<?php 
/**
 * Система управления сайтом HostCMS v. 5.xx
 * Copyright © 2005-2008 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
 *
 * Ajax загрузчик формы списка информационных групп и элементов.
 * 
 * Файл: /admin/InformationSystems/action/load_information_groups.php
 * 
 * @author Hostmake LLC
 * @version 5.2
 */
function LoadAjaxData(&$admin_forms)
{
	$on_page = $admin_forms->GetOnPageCount();
	$page = to_int($_REQUEST['limit']);
	$begin = ($page == 0) ? 0 : ($page - 1) * $on_page;

	$param = array();

	/*
	$param['limit'][0] = array();
	$param['limit'][1] = array('begin' => $begin, 'count' => $on_page);
	*/

	$param['limit']['all'] = array('begin' => $begin, 'count' => $on_page);

	$information_system_id = to_int($_REQUEST['information_system_id']);
	$information_groups_parent_id = to_int($_REQUEST['information_groups_parent_id']);

	$InformationSystem = & singleton('InformationSystem');

	// Строим "хлебные крошки"
	$path_array = $InformationSystem->GetInformationGroupsPathArray($information_groups_parent_id, $information_system_id);

	$new_path_array = array();

	$new_path_array[] = array(
	'link' => $admin_forms->GetHtmlCallDoLoadAjax('/admin/InformationSystems/InformationSystems.php', '', 11, 'load_data'),
	'onclick' => $admin_forms->GetOnClickCallDoLoadAjax('/admin/InformationSystems/InformationSystems.php', '', 11, 'load_data'),
	'name' => $GLOBALS['MSG_information_systems']['show_information_systems_title']);

	// Меняем порядок следования элементов в массиве на обратный
	$path_array = array_reverse($path_array, true);

	// Преобразуем идентификаторы групп в ссылки на группы.
	if ($path_array)
	{
		foreach ($path_array as $information_groups_parent_id => $value)
		{
			$new_path_array[] = array (
			'link' => $admin_forms->GetHtmlCallDoLoadAjax('/admin/InformationSystems/InformationSystems.php', "&action=show_information_groups&information_groups_parent_id={$information_groups_parent_id}&information_system_id={$information_system_id}", 12, 'load_data'),
			'onclick' => $admin_forms->GetOnClickCallDoLoadAjax('/admin/InformationSystems/InformationSystems.php', "&action=show_information_groups&information_groups_parent_id={$information_groups_parent_id}&information_system_id={$information_system_id}", 12, 'load_data'),
			'name' => $value['information_groups_name']);
		}
	}

	$param['path_array'] = $new_path_array;

	// Запрос для выборки информационных групп инфосистемы.
	$param['data'][] = "SELECT information_groups_id AS key_field, information_groups_name AS name,
	information_groups_allow_indexation AS indexation_field,
	information_systems_id AS information_systems_id,
	information_groups_parent_id,
	information_groups_name AS date
	FROM `information_groups_table`
	WHERE `information_systems_id`= '$information_system_id'
	AND `information_groups_parent_id` = '$information_groups_parent_id' 
	{FILTER_STRING} {ORDER_STRING} {LIMIT}";

	// Количество информационных групп
	$count_groups = "SELECT count(information_groups_id) as count
	FROM `information_groups_table`
	WHERE `information_systems_id`= '$information_system_id'
	AND `information_groups_parent_id` = '$information_groups_parent_id'
	{FILTER_STRING}";	

	// Запрос для выборки информационных элементов.
	$param['data'][] = "SELECT information_items_table.*,
	information_items_table.information_systems_id AS information_systems_id,
	information_items_table.information_items_id AS key_field,
	information_items_table.information_groups_id AS information_groups_parent_id, 
	information_items_table.information_items_name AS name, 
	information_items_table.information_items_status AS status_field, 
	information_items_table.information_items_allow_indexation AS indexation_field, 
	count( comment_table.comment_id ) AS comment_field,
	information_items_date AS date,
	information_items_table.information_items_putend_date AS date_end
	
	FROM `information_items_table` LEFT JOIN `comment_table` 
	ON information_items_table.information_items_id = comment_table.information_items_id
	WHERE information_items_table.information_systems_id = $information_system_id
	AND `information_groups_id` = $information_groups_parent_id  {FILTER_STRING} 
	GROUP BY information_items_table.information_items_id {ORDER_STRING} {LIMIT}";

	// Посчитаем общее число информационных элементов.
	$count = "SELECT count(information_items_id) as count
	FROM `information_items_table`
	WHERE `information_systems_id`= '$information_system_id'
	AND `information_groups_id` = '$information_groups_parent_id'
	{FILTER_STRING}";

	// Формируем верхнее меню.
	$k = 0;

	$menu = array();
	$menu[$k]['name'] = $GLOBALS['MSG_information_systems']['information_system_top_menu_items'];
	$menu[$k]['link'] = '';
	$menu[$k]['icon'] = '';

	$sub_menu = array();
	$sub_menu[$p = 0]['name'] = $GLOBALS['MSG_information_systems']['show_information_groups_link2'];
	$sub_menu[$p]['link'] = $admin_forms->GetHtmlCallTrigerSingleAction('edit_group_item', 'check_1_0', 12, 0, 0);
	$sub_menu[$p]['onclick'] = $admin_forms->GetOnClickCallTrigerSingleAction('edit_group_item', 'check_1_0', 12, 0, 0);
	$sub_menu[$p]['icon'] = '/admin/images/page_add.gif';

	$sub_menu[++$p]['name'] = $GLOBALS['MSG_information_systems']['show_information_groups_link3'];
	$sub_menu[$p]['link'] = $admin_forms->GetHtmlCallDoLoadAjax('/admin/InformationSystems/InformationSystems.php', "&action=show_information_propertys_items&information_system_id={$information_system_id}", 50, 'load_data');
	$sub_menu[$p]['onclick'] = $admin_forms->GetOnClickCallDoLoadAjax('/admin/InformationSystems/InformationSystems.php', "&action=show_information_propertys_items&information_system_id={$information_system_id}", 50, 'load_data');
	$sub_menu[$p]['icon'] = '/admin/images/page_gear.gif';

	// Добавляем подэлементы.
	$menu[$k]['sub_items'] = $sub_menu;

	$menu[++$k]['name'] = $GLOBALS['MSG_information_systems']['information_system_top_menu_groups'];
	$menu[$k]['link'] = '';
	$menu[$k]['icon'] = '';

	$p = 0;

	// Добавление группы
	$sub_menu = array();

	$sub_menu[$p]['name'] = $GLOBALS['MSG_information_systems']['show_information_groups_link1'];
	$sub_menu[$p]['link'] = $admin_forms->GetHtmlCallTrigerSingleAction('edit_group_item', 'check_0_0', 12, 0, 0);
	$sub_menu[$p]['onclick'] = $admin_forms->GetOnClickCallTrigerSingleAction('edit_group_item', 'check_0_0', 12, 0, 0);
	$sub_menu[$p]['icon'] = '/admin/images/folder_add.gif';

	// Свойства групп
	$sub_menu[++$p]['name'] = $GLOBALS['MSG_information_systems']['show_information_groups_link4'];
	$sub_menu[$p]['link'] = $admin_forms->GetHtmlCallDoLoadAjax('/admin/InformationSystems/InformationSystems.php', "&action=show_information_propertys_groups&information_system_id={$information_system_id}", 51, 'load_data');
	$sub_menu[$p]['onclick'] = $admin_forms->GetOnClickCallDoLoadAjax('/admin/InformationSystems/InformationSystems.php', "&action=show_information_propertys_groups&information_system_id={$information_system_id}", 51, 'load_data');
	$sub_menu[$p]['icon'] = '/admin/images/folder_gear.gif';

	// Добавляем подэлементы.
	$menu[$k]['sub_items'] = $sub_menu;

	$p = 0;

	$menu[++$k]['name'] = $GLOBALS['MSG_information_systems']['show_all_comments_top_menu'];
	$menu[$k]['link'] = '';
	$menu[$k]['icon'] = '';

	$sub_menu = array();

	$sub_menu[$p]['name'] = $GLOBALS['MSG_information_systems']['show_comments_link_show_all_comments'];
	$sub_menu[$p]['link'] = $admin_forms->GetHtmlCallDoLoadAjax('/admin/InformationSystems/InformationSystems.php', "&action=show_comments&all_comments_system=1&information_system_id={$information_system_id}", 52, 'load_data');
	$sub_menu[$p]['onclick'] = $admin_forms->GetOnClickCallDoLoadAjax('/admin/InformationSystems/InformationSystems.php', "&action=show_comments&all_comments_system=1&information_system_id={$information_system_id}", 52, 'load_data');
	$sub_menu[$p]['icon'] = '/admin/images/comments.gif';

	// Добавляем подэлементы.
	$menu[$k]['sub_items'] = $sub_menu;

	// Формируем массив меню.
	$menu_array = array();
	$menu_array[] = $menu;

	// Для первого набора данных общее количство не указываем, т.к. передаем все элементы,
	// для второго набора данных указываем в виде запроса.
	$param['total_count'][0] = $count_groups;
	$param['total_count'][1] = $count;

	// В поле с картинкой отображаем значек папки. Т.к. изображение для поля задается в
	// формате <Значение поля>=<Путь к изображению> и поле не имеет значения, поэтому
	//  присваиваемое значение имеет данный вид
	$param['field_params'][0][46]['admin_forms_field_image'] = "=/admin/images/folder.gif";
	$param['field_params'][0][47]['admin_forms_field_image'] = "=/admin/images/folder.gif";
	$param['field_params'][0][47]['admin_forms_field_type'] = 4;

	$param['field_params'][1][49]['admin_forms_field_alt'] = "0=".$GLOBALS['MSG_information_systems']['information_item_is_active']
	. "\n1=".$GLOBALS['MSG_information_systems']['information_item_is_active'];
	$param['field_params'][1][49]['admin_forms_field_title'] = "0=".$GLOBALS['MSG_information_systems']['information_item_is_active']
	. "\n1=".$GLOBALS['MSG_information_systems']['information_item_is_active'];

	// В поле Активность для информационных групп не отображаем индикатор активности
	$param['field_params'][0][49]['admin_forms_field_type'] = 1;



	$param['field_params'][0][50]['admin_forms_field_alt'] = "0=".$GLOBALS['MSG_information_systems']['information_group_is_indexation']
	. "\n1=".$GLOBALS['MSG_information_systems']['information_group_is_indexation'];
	$param['field_params'][0][50]['admin_forms_field_title'] = "0=".$GLOBALS['MSG_information_systems']['information_group_is_indexation']
	. "\n1=".$GLOBALS['MSG_information_systems']['information_group_is_indexation'];


	$param['field_params'][1][50]['admin_forms_field_alt'] = "0=".$GLOBALS['MSG_information_systems']['information_item_is_indexation']
	. "\n1=".$GLOBALS['MSG_information_systems']['information_item_is_indexation'];
	$param['field_params'][1][50]['admin_forms_field_title'] = "0=".$GLOBALS['MSG_information_systems']['information_item_is_indexation']
	. "\n1=".$GLOBALS['MSG_information_systems']['information_item_is_indexation'];


	$param['current_page'] = $page;
	$param['on_page'] = $on_page;
	$param['menus'] = $menu_array;

	$row_information_system = $InformationSystem->GetInformationSystem($information_system_id);

	// Заголовок формы
	$param['title'] = sprintf($GLOBALS['MSG_information_systems']['show_information_groups_title'], $row_information_system['information_systems_name']);
	
	$param['field_params'][1]['name']['admin_forms_field_type'] = 10;// вычисляемое поле
	$param['field_params'][1]['name']['callback_function'] = 'callback_function_name';
		
	// Функция обратного вызова для названия
	function callback_function_name($field_value, $value, $row)
	{
		if ($row['date_end'] != "0000-00-00 00:00:00" && $row['date_end'] < date("Y-m-d H:i:s"))
		{
			?><div style="text-decoration: line-through"><?php echo $row['name']?></div><?php
		}
		else 
		{
			echo $row['name'];
		}		
	}

	return $param;
}

// Необязательная функция для определения реального имени столбца по псевдониму.
function ResolveFieldName(&$field_name, $dataset_id)
{

	switch ($dataset_id)
	{
		case 0: // Список информационных групп.
		{
			if ($field_name == 'name')
			{
				$field_name = 'information_groups_name';
			}
			elseif ($field_name == 'key_field')
			{
				$field_name = 'information_groups_id';
			}
			elseif ($field_name == 'indexation_field')
			{
				$field_name = 'information_groups_allow_indexation';
			}
			elseif ($field_name == 'date')
			{
				$field_name = 'information_groups_name';
			}
			elseif ($field_name == 'comment_field')
			{
				$field_name = 'information_groups_name';
			}

			break;
		}
		case 1: // Список информационных элементов.
		{
			if ($field_name == 'name')
			{
				$field_name = 'information_items_name';
			}
			elseif ($field_name == 'key_field')
			{
				$field_name = 'information_items_table.information_items_id';
			}
			elseif ($field_name == 'status')
			{
				$field_name = 'information_items_status';
			}
			elseif ($field_name == 'indexation_field')
			{
				$field_name = 'information_items_allow_indexation';
			}
			elseif ($field_name == 'date')
			{
				$field_name = 'information_items_date';
			}
			elseif ($field_name == 'date_end')
			{
				$field_name = 'information_items_table.information_items_putend_date';
			}
			break;
		}
	}
	return true;
}

// Обработчик события "Редактировать" информационную группы или элемента.
function edit_group_item(&$param)
{
	ob_start();

	$information_system_id=to_int($_REQUEST['information_system_id']);
	$information_group_parent_id = to_int($_REQUEST['information_groups_parent_id']);

	$InformationSystem = & singleton('InformationSystem');

	if (isset($param['data']))
	{
		// Редактирование информационной группы.
		if (isset($param['data'][0]))
		{
			foreach ($param['data'][0] as $information_group_id => $value)
			{
				// Определяем режим доступа пользователя и принадлежит ли объект пользователю
				$user_access = new user_access();

				// Определяем информацию об объекте
				$object_res = $InformationSystem->SelectInformationGroups($information_group_id);

				if ($object_res)
				{
					$object_row = mysql_fetch_assoc($object_res);
				}

				if ($object_row)
				{
					$object_user_id = $object_row['users_id'];
				}
				else
				{
					$object_user_id = 0;
				}

				if ($user_access->IssetUserAccessForObject($object_user_id))
				{
					include(CMS_FOLDER . 'admin/InformationSystems/action/form_edit_add_information_groups.php');

					$param['title'] = ($information_group_id == 0) ? $GLOBALS['MSG_information_systems']['information_groups_add_form_title'] : $GLOBALS['MSG_information_systems']['information_groups_edit_form_title'];
				}
				else
				{
					$user_access->MessageOnlyOwn();
					$param['error'] = ob_get_clean();
					return ;
				}
			}
		}

		// Редактирование информационного элемента.
		if (isset($param['data'][1]))
		{
			foreach ($param['data'][1] as $key => $value)
			{
				// Определяем режим доступа пользователя и принадлежит ли объект пользователю
				$user_access = new user_access();

				// Определяем информацию об объекте
				$object_row = $InformationSystem->GetInformationSystemItem($key);

				if ($object_row)
				{
					$object_user_id = $object_row['users_id'];
				}
				else
				{
					$object_user_id = 0;
				}

				if ($user_access->IssetUserAccessForObject($object_user_id))
				{
					$information_item_id = intval($key);

					include(CMS_FOLDER . 'admin/InformationSystems/action/form_edit_add_information_items.php');

					$param['title'] =  $information_item_id == 0 ? $GLOBALS['MSG_information_systems']['information_items_add_form_title'] : $GLOBALS['MSG_information_systems']['information_items_edit_form_title'];

				}
				else
				{
					$user_access->MessageOnlyOwn();
					$param['error'] = ob_get_clean();
					return ;
				}
			}
		}
	}

	$param['result'] = ob_get_clean();
	return true;
}

// Обработчик события "Копировать" информационного элемента
function copy_item(&$param)
{
	ob_start();

	if (defined('READ_ONLY') && READ_ONLY)
	{
		$kernel = & singleton('kernel');

		$kernel->ReadMode();
	}
	else
	{
		$InformationSystem = & singleton('InformationSystem');

		if (isset($param['data']))
		{
			if (isset($param['data'][1]))
			{
				foreach ($param['data'][1] as $key => $value)
				{
					// Определяем режим доступа пользователя и принадлежит ли объект пользователю
					$user_access = new user_access();

					// Определяем информацию об объекте
					$object_row = $InformationSystem->GetInformationSystemItem($key);

					if ($object_row)
					{
						$object_user_id = $object_row['users_id'];
					}
					else
					{
						$object_user_id = 0;
					}

					if ($user_access->IssetUserAccessForObject($object_user_id))
					{
						$InformationSystem->CopyInformationItem($key);
					}
					else
					{
						$user_access->MessageOnlyOwn();
						$param['error'] = ob_get_clean();
						return ;
					}
				}
			}
		}
	}
	$param['error'] = ob_get_clean();

}

// Изменение статуса активности информационного элемента
function change_item_active(&$param)
{
	ob_start();

	if (defined('READ_ONLY') && READ_ONLY)
	{
		$kernel = & singleton('kernel');

		$kernel->ReadMode();
	}
	else
	{
		$InformationSystem = & singleton('InformationSystem');

		if (isset($param['data']) && is_array($param['data']))
		{
			if (isset($param['data'][1]))
			{
				foreach ($param['data'][1] as $key => $row)
				{					
					// Определяем режим доступа пользователя и принадлежит ли объект пользователю
					$user_access = new user_access();

					// Определяем информацию об объекте
					$object_row = $InformationSystem->GetInformationSystemItem($key);

					if ($object_row)
					{
						$object_user_id = $object_row['users_id'];
					}
					else
					{
						$object_user_id = 0;
					}

					if ($user_access->IssetUserAccessForObject($object_user_id))
					{
						// Выбираем данные об инфоэлементе
						$res = $InformationSystem->GetInformationSystemItem($key);
						
						$param_item = array();
						$param_item['information_items_id'] = $key;
						$param_item['information_items_status'] = 1 - $res['information_items_status'];
						
						$InformationSystem->InsertInformationItem($param_item);												
					}
					else
					{
						$user_access->MessageOnlyOwn();
						$param['error'] = ob_get_clean();
						return ;
					}
				}
			}
		}
	}
	$error = ob_get_clean();

	$param['error'] = $error;
}

// Изменение статуса индексированности информационного элемента
function change_item_indexation(&$param)
{
	ob_start();

	if (defined('READ_ONLY') && READ_ONLY)
	{
		$kernel = & singleton('kernel');

		$kernel->ReadMode();
	}
	else
	{
		$InformationSystem = & singleton('InformationSystem');

		if (isset($param['data']) && is_array($param['data']))
		{
			if (isset($param['data'][0]))
			{
				foreach ($param['data'][0] as $key => $row)
				{
					// Определяем режим доступа пользователя и принадлежит ли объект пользователю
					$user_access = new user_access();

					// Определяем информацию об объекте
					$object_res = $InformationSystem->SelectInformationGroups($key);

					if ($object_res)
					{
						$object_row = mysql_fetch_assoc($object_res);
					}

					if ($object_row)
					{
						$object_user_id = $object_row['users_id'];
					}
					else
					{
						$object_user_id = 0;
					}

					if ($user_access->IssetUserAccessForObject($object_user_id))
					{
						// Выбираем данные об инфоэлементе
						$res = $InformationSystem->GetInformationGroup(intval($key));

						$InformationSystem_id = $res['information_systems_id'];
						$information_group_id = intval($key);
						$information_group_parent_id = $res['information_groups_parent_id'];
						$information_group_name = $res['information_groups_name'];
						$information_group_description = $res["information_groups_description"];
						$information_group_order = $res['information_groups_order'];
						$information_group_path = $res['information_groups_path'];
						$information_group_small_image = $res['information_groups_small_image'];
						$information_group_allow_indexation = 1- $res['information_groups_allow_indexation'];
						$information_group_seo_title = $res['information_groups_seo_title'];
						$information_group_seo_description = $res['information_groups_seo_description'];
						$information_group_seo_keywords = $res['information_groups_seo_keywords'];
						$information_group_access = $res['information_groups_access'];
						$user_id = $res['users_id'];

						$InformationSystem->InsertInformationGroups(1, $information_group_id, $InformationSystem_id, $information_group_parent_id, $information_group_name, $information_group_description, $information_group_order, $information_group_path, '', $information_group_allow_indexation, $information_group_seo_title, $information_group_seo_description, $information_group_seo_keywords, $information_group_access, $user_id);
					}
					else
					{
						$user_access->MessageOnlyOwn();
						$param['error'] = ob_get_clean();
						return ;
					}
				}
			}

			if (isset($param['data'][1]))
			{
				foreach ($param['data'][1] as $key => $row)
				{

					// Определяем режим доступа пользователя и принадлежит ли объект пользователю
					$user_access = new user_access();

					// Определяем информацию об объекте
					$object_row = $InformationSystem->GetInformationSystemItem($key, array('cache_off' => true));

					if ($object_row)
					{
						$object_user_id = $object_row['users_id'];
					}
					else
					{
						$object_user_id = 0;
					}

					if ($user_access->IssetUserAccessForObject($object_user_id))
					{
						// Выбираем данные об инфоэлементе
						$res = $InformationSystem->GetInformationSystemItem($key);

						$param_item = array();						
						$param_item['information_items_id'] = $key;
						$param_item['information_items_allow_indexation'] = 1 - $res['information_items_allow_indexation'];
						
						$InformationSystem->InsertInformationItem($param_item);												
					}
					else
					{
						$user_access->MessageOnlyOwn();
						$param['error'] = ob_get_clean();
						return ;
					}
				}
			}
		}
	}
	$error = ob_get_clean();

	$param['error'] = $error;
}


// Удаление информационной группы и элемента.
function delete_group_item(&$param)
{
	ob_start();

	if (defined('READ_ONLY') && READ_ONLY)
	{
		$kernel = & singleton('kernel');

		$kernel->ReadMode();
	}
	else
	{
		$information_system = & singleton('InformationSystem');

		$information_system_id = to_int($_REQUEST['information_system_id']);

		$count_deleted_items = 0;

		$count_deleted_groups = 0;

		if (isset($param['data']))
		{
			if (isset($param['data'][0]))
			{
				foreach ($param['data'][0] as $key => $value)
				{
					// Определяем режим доступа пользователя и принадлежит ли объект пользователю
					$user_access = new user_access();

					// Определяем информацию об объекте
					$object_res = $information_system->SelectInformationGroups($key);

					if ($object_res)
					{
						$object_row = mysql_fetch_assoc($object_res);
					}

					if ($object_row)
					{
						$object_user_id = $object_row['users_id'];
					}
					else
					{
						$object_user_id = 0;
					}

					if ($user_access->IssetUserAccessForObject($object_user_id))
					{
						if (!$information_system->del_information_groups($key, $information_system_id))
						{
							$flag_success_delete_group = false;
						}
						else
						{
							++$count_deleted_groups;

							$flag_success_delete_group = true;
						}
					}
					else
					{
						$user_access->MessageOnlyOwn();

						$flag_success_delete_group = false;
					}
				}

				if ($flag_success_delete_group)
				{
					if ($count_deleted_groups == 1)
					{
						show_message($GLOBALS['MSG_information_systems']['delete_information_group_success']);
					}
					else
					{
						show_message($GLOBALS['MSG_information_systems']['delete_information_groups_success']);
					}
				}
				/*else
				{
				show_error_message($GLOBALS['MSG_information_systems']['delete_information_group_error']);
				}*/
			}

			if (isset($param['data'][1]))
			{
				foreach ($param['data'][1] as $key => $value)
				{
					// Определяем режим доступа пользователя и принадлежит ли объект пользователю
					$user_access = new user_access();

					// Определяем информацию об объекте
					$object_row = $information_system->GetInformationSystemItem($key, array('cache_off' => true));

					if ($object_row)
					{
						$object_user_id = $object_row['users_id'];
					}
					else
					{
						$object_user_id = 0;
					}

					if ($user_access->IssetUserAccessForObject($object_user_id))
					{
						if (!$information_system->del_information_items($key))
						{
							$flag_success_delete_item = false;
						}
						else
						{
							++$count_deleted_items;

							$flag_success_delete_item = true;
						}
					}
					else
					{
						$user_access->MessageOnlyOwn();

						$flag_success_delete_item = false;
					}
				}
				if ($flag_success_delete_item)
				{
					if ($count_deleted_items == 1)
					{
						show_message($GLOBALS['MSG_information_systems']['delete_information_item_success']);
					}
					else
					{
						show_message($GLOBALS['MSG_information_systems']['delete_information_items_success']);
					}
				}
				/*else
				{
				show_error_message($GLOBALS['MSG_information_systems']['delete_information_items_error']);
				}*/
			}
		}
	}
	$param['error'] = ob_get_clean();

}


// Удаление файла большого изображения информационного элемента.
function delete_big_image_item(&$param)
{
	ob_start();

	if (defined('READ_ONLY') && READ_ONLY)
	{
		$kernel = & singleton('kernel');

		$kernel->ReadMode();
	}
	else
	{
		$information_system = & singleton('InformationSystem');

		$information_system_id = to_int($_REQUEST['information_system_id']);

		if (isset($param['data']))
		{
			if (isset($param['data'][1]))
			{
				$DataBase = & singleton(DataBase);

				foreach ($param['data'][1] as $key => $value)
				{
					$information_item_id = intval($key);

					$row = $information_system->GetInformationSystemItem($information_item_id);

					if ($row)
					{
						if (is_dir(CMS_FOLDER.UPLOADDIR))
						{
							$fname = CMS_FOLDER.UPLOADDIR.$row['information_items_image'];#путь к большой картинке
							$field_name = "`information_items_image`";

							if (is_file($fname))
							{
								// удаляем файл
								if (@unlink($fname))
								{
									// Удаляем файл из таблицы
									$query = "UPDATE `information_items_table` SET  $field_name = ''  WHERE information_items_id=$information_item_id";
									$DataBase->query($query);
								}
							}
						}
						else
						{
							show_error_message($GLOBALS['MSG_information_systems']['error_information_dir'].CMS_FOLDER.UPLOADDIR);
						}
					}
				}
			}
		}
	}

	$param['error'] = ob_get_clean();
}

?>