<?php 
/**
 * Система управления сайтом HostCMS v. 5.xx
 * Copyright © 2005-2010 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
 *
 * Форма добаления/редактирования дополнительного свойства информационных групп
 * 
 * Файл: /admin/InformationSystems/action/form_edit_add_information_propertys_groups.php
 * 
 * @author Hostmake LLC
 * @version 5.x
 */
$information_system = & singleton('InformationSystem');

if (isset($_REQUEST['ext_is_groups_parent_id']))
{
	$ext_is_groups_parent_id = intval($_REQUEST['ext_is_groups_parent_id']);
}
else
{
	$ext_is_groups_parent_id = 0;
}

// Получаем данные об информационной системе
$information_system_row = $information_system->GetInformationSystem($information_system_id);

// Не возникало ошибок при добавлении/редактировании дополнительного свойства информационной группы
if (!isset($error_information_propertys_groups))
{
	// Редактирование дополнительного свойства информационной группы
	if ($information_property_groups_id != 0)
	{

		if ($row = $information_system->GetInformationGroupsPropertys($information_property_groups_id))
		{
			$information_propertys_groups_name = $row["information_propertys_groups_name"];
			$information_propertys_groups_type = $row["information_propertys_groups_type"];
			$information_propertys_groups_order = $row["information_propertys_groups_order"];
			$information_propertys_groups_default_value = $row["information_propertys_groups_default_value"];

			// Дата
			$information_propertys_groups_date_default_value = $information_propertys_groups_default_value;
			// Дата-время
			$information_propertys_groups_datetime_default_value = $information_propertys_groups_default_value;

			$information_propertys_groups_define_checked_value = to_int($information_propertys_groups_date_default_value);
			$information_propertys_groups_xml_name = $row["information_propertys_groups_xml_name"];
			$information_propertys_groups_lists_id = $row['information_propertys_groups_lists_id'];
			$information_propertys_groups_information_system_id = $row['information_propertys_groups_information_systems_id'];
			
			$information_propertys_groups_dir_id = $row['information_propertys_groups_dir_id'];
			
			$information_propertys_groups_big_width = $row['information_propertys_groups_big_width'];
			
			$information_propertys_groups_big_height = $row['information_propertys_groups_big_height'];
			
			$information_propertys_groups_small_width = $row['information_propertys_groups_small_width'];
			
			$information_propertys_groups_small_height = $row['information_propertys_groups_small_height'];
		}
		else
		{
			show_error_message($GLOBALS['MSG_information_systems']['not_exists_information_propertys_groups']);
			return;
		}
	}
	else // Добавление дополнительного свойства информационной группы
	{

		$information_propertys_groups_name = '';
		$information_propertys_groups_type = 0;
		$information_propertys_groups_order = 0;
		$information_propertys_groups_default_value = '';

		// Дата
		$information_propertys_groups_date_default_value = '';
		// Дата-время
		$information_propertys_groups_datetime_default_value = '';

		$information_propertys_groups_define_checked_value = 0;
		$information_propertys_groups_xml_name = '';
		$information_propertys_groups_lists_id = 0;
		$information_propertys_groups_information_system_id = 0;
		$information_propertys_groups_dir_id = $ext_is_groups_parent_id;
		
		$information_propertys_groups_big_width = $information_system_row['information_systems_image_big_max_width_group'];
		
		$information_propertys_groups_big_height = $information_system_row['information_systems_image_big_max_height_group'];
		
		$information_propertys_groups_small_width = $information_system_row['information_systems_image_small_max_width_group'];
		
		$information_propertys_groups_small_height = $information_system_row['information_systems_image_small_max_height_group'];
	}
}
else // Произошла ошибка при добавлении/редактировании дополнительного свойства информационной группы
{

	$information_propertys_groups_name = to_str($_POST["information_propertys_groups_name"]);
	$information_propertys_groups_type = to_str($_POST["information_propertys_groups_type"]);
	$information_propertys_groups_order = to_str($_POST["information_propertys_groups_order"]);
	$information_propertys_groups_default_value = to_str($_POST["information_propertys_groups_default_value"]);

	$information_propertys_groups_dir_id = to_int($_POST['information_propertys_groups_dir_id']);
	
	// Дата
	$information_propertys_groups_date_default_value =  to_str($_POST["information_propertys_groups_date_default_value"]);

	// Дата-время
	$information_propertys_groups_datetime_default_value =  to_str($_POST["information_propertys_groups_datetime_default_value"]);

	if (isset($_POST['information_propertys_groups_define_checked_value']))
	{
		$information_propertys_groups_define_checked_value = 1;
	}
	else
	{
		$information_propertys_groups_define_checked_value = 0;
	}

	$information_propertys_groups_xml_name = to_str($_POST["information_propertys_groups_xml_name"]);
	$information_propertys_lists_id = to_int($_POST['information_propertys_groups_lists_id']);
	$information_propertys_groups_information_system_id = to_int($_POST['information_propertys_groups_information_system_id']);

	$information_propertys_groups_big_width = $information_system_row['information_systems_image_big_max_width_group'];
		
	$information_propertys_groups_big_height = $information_system_row['information_systems_image_big_max_height_group'];
	
	$information_propertys_groups_small_width = $information_system_row['information_systems_image_small_max_width_group'];
	
	$information_propertys_groups_small_height = $information_system_row['information_systems_image_small_max_height_group'];
}

$info_information_system = $information_system->GetInformationSystem($information_system_id);

$form_params = array();

$form_params['title'] = $information_property_groups_id == 0
? $GLOBALS['MSG_information_systems']['information_propertys_groups_add_form_title']
: $GLOBALS['MSG_information_systems']['information_propertys_groups_edit_form_title'];

$form_params['title'] .= ' "' . $info_information_system['information_systems_name'] . '"';

$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/InformationSystems/InformationSystems.php';
$form_params['form_attribs']['ENCTYPE'] = 'multipart/form-data';
$form_params['form_attribs']['name'] = 'EditAddPropertyGroups';

$admin_forms_fields = new admin_forms_fields();

// Формируем "хлебные крошки"
$new_path_array = array();

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

$InformationSystem = & singleton('InformationSystem');

// Идентификатор текущей группы (раздела) информационных систем
$information_systems_dir_parent_id = to_int($_REQUEST['information_systems_dir_parent_id']);
	
// Путь по группам инфосистем
if ($information_systems_dir_parent_id)
{
	$information_systems_dir_path_array = $InformationSystem->GetInformationSystemsDirPathArray($information_systems_dir_parent_id);
	
	// Меняем порядок следования элементов в массиве на обратный
	$information_systems_dir_path_array = array_reverse($information_systems_dir_path_array, true);
	
	foreach ($information_systems_dir_path_array as $key => $value)
	{
		$new_path_array[] = array (
		'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/InformationSystems/InformationSystems.php', "&information_systems_dir_parent_id={$key}", 11, 'load_data'),
		'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/InformationSystems/InformationSystems.php', "&information_systems_dir_parent_id={$key}", 11, 'load_data'),
		'name' => $value['information_systems_dir_name']);
	}
}	

$path_array = $InformationSystem->GetInformationGroupsPathArray(0, $information_system_id);

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

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

$new_path_array[] = array (
'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/InformationSystems/InformationSystems.php', "&information_systems_dir_parent_id={$information_systems_dir_parent_id}&information_system_id={$information_system_id}", 51, 'load_data'),
'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/InformationSystems/InformationSystems.php', "&information_systems_dir_parent_id={$information_systems_dir_parent_id}&information_system_id={$information_system_id}", 51, 'load_data'),
'name' => sprintf($GLOBALS['MSG_information_systems']['show_information_propertys_groups_title'], $info_information_system['information_systems_name']));

// Дополнительные хлебные крошки для хождения по группам дополнительных свойств информационных групп
$path_array = $InformationSystem->GetAdditionalPropertyPathArrayGroup($ext_is_groups_parent_id);

if (count($path_array) > 0)
{
	foreach ($path_array as $key => $value)
	{
		$new_path_array[] = array (
		'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/InformationSystems/InformationSystems.php', "&information_systems_dir_parent_id={$information_systems_dir_parent_id}&information_system_id={$information_system_id}&ext_is_groups_parent_id={$key}", 51, 'load_data'),
		'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/InformationSystems/InformationSystems.php', "&information_systems_dir_parent_id={$information_systems_dir_parent_id}&information_system_id={$information_system_id}&ext_is_groups_parent_id={$key}", 51, 'load_data'),
		'name' => $value);
	}
}

// Передаем в массив для констурктора "хлебные крошки"
$form_params['path_array'] = $new_path_array;

$admin_forms_fields->admin_forms_fields($form_params);

$DataBase = & singleton('DataBase');

$tab_id = $admin_forms_fields->AddTab($GLOBALS['MSG_information_systems']['additional_propertys_information_groups_form_tab_1']);

// Название дополнительного свойства информационной группы.
$param = array();

$param['tab_id'] = $tab_id;
$param['name'] = 'information_propertys_groups_name';
$param['caption'] = $GLOBALS['MSG_information_systems']['information_group_propertys_add_form_name'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $information_propertys_groups_name;
$param['attributes'] = array();
$param['attributes']['class'] = 'large';
$param['format']['minlen']['value'] = 1;
$param['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($param);

$admin_forms = new admin_forms();
$window_id = $admin_forms->GetWindowId();

// Формируем массив типов дополнительных свойств информационной группы
$items = array(0=>$GLOBALS['MSG_information_systems']['information_propertys_add_form_type_name1'],
1=>$GLOBALS['MSG_information_systems']['information_propertys_add_form_type_name2'],
2=>$GLOBALS['MSG_information_systems']['information_propertys_add_form_type_name3'],
4=>$GLOBALS['MSG_information_systems']['information_big_text'],
6=>$GLOBALS['MSG_information_systems']['information_system'],
5=>$GLOBALS['MSG_information_systems']['information_visual_edit'],
7=>$GLOBALS['MSG_information_systems']['information_checkbox'],
8=>$GLOBALS['MSG_information_systems']['information_date'],
9=>$GLOBALS['MSG_information_systems']['information_date_time']);

if (class_exists('lists'))
{
	$items[3] = $GLOBALS['MSG_information_systems']['information_propertys_add_form_type_name4'];
}

// Список типов дополнительных свойств
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'information_propertys_groups_type';
$param['caption'] = $GLOBALS['MSG_information_systems']['lib_property_form_type'];
$param['type'] = 2; // Выпадающий список.
$param['attributes']['onchange'] = "ShowRowsGroupPropertys('{$window_id}', this.value)";
$param['value'] = $information_propertys_groups_type;
$param['items'] = $items;
$param['attributes']['style'] = 'width: 210px;';
$param['div_attributes']['style'] = 'float: left;';
$admin_forms_fields->AddField($param);

// Родительская группа 
$groups_dir_res = $InformationSystem->GetDelimitedGroups(0, $information_system_id, '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
$count = count($groups_dir_res);
$array = array(0 => ' ... ');
for ($i = 0; $i < $count; $i++)
{
	$array[$groups_dir_res[$i]['information_propertys_groups_dir_id']] = $groups_dir_res[$i]['separator'].$groups_dir_res[$i]['information_propertys_groups_dir_name'];
}
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'information_propertys_groups_dir_id';
$param['caption'] = $GLOBALS['MSG_information_systems']['information_propertys_items_dir_parent_id'];
$param['type'] = 2; // Выпадающий список.
$param['value'] = $information_propertys_groups_dir_id;
$param['items'] = $array;
$param['attributes']['style'] = 'width: 210px;';
$param['div_attributes']['style'] = 'float: left;';
$admin_forms_fields->AddField($param);

// Порядковый номер дополнительного свойства
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'information_propertys_groups_order';
$param['caption'] = $GLOBALS['MSG_information_systems']['information_propertys_groups_add_form_order'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $information_propertys_groups_order;
$param['attributes']['style'] = 'width: 210px;';
$param['div_attributes']['style'] = 'float: left;';
$admin_forms_fields->AddField($param);

$admin_forms_fields->AddSeparator($tab_id);

// Список информационных систем
$param = array();
$param['tab_id'] = $tab_id;
$param['div_id'] = 'information_system_id';
$param['name'] = 'information_propertys_groups_information_system_id';
$param['caption'] = $GLOBALS['MSG_information_systems']['information_propertys_groups_add_form_inf_system'];
$param['type'] = 2; // Выпадающий список.
$param['value'] = $information_propertys_groups_information_system_id;
$items = array();
$result_information_systems = $information_system->GetAllInformationSystems(CURRENT_SITE);
$count_information_systems = mysql_num_rows($result_information_systems);
for ($i = 0; $i <  $count_information_systems; $i++)
{
	$row_information_systems = mysql_fetch_assoc($result_information_systems);
	$items[$row_information_systems['information_systems_id']] = $row_information_systems['information_systems_name'];
}
$param['items'] = $items;
$param['attributes']['style'] = 'width: 320px;';
$param['div_attributes']['style'] = 'float: left;';
$admin_forms_fields->AddField($param);


// Формируем список доступных списков
// Проверяем существование модуля Списки

// Модуль Списки существует
if (class_exists('lists'))
{
	$param = array();
	$param['tab_id'] = $tab_id;
	$param['div_id'] = 'list_id';
	$param['name'] = 'information_propertys_groups_lists_id';
	$param['caption'] = $GLOBALS['MSG_information_systems']['information_propertys_group_add_form_lists'];
	$param['type'] = 2; // Выпадающий список.
	$param['value'] = $information_propertys_groups_lists_id;
	$items = array();
	$lists = & singleton('lists');

	// Получаем информацию о всех доступных списках
	$result_list = $lists->GetAllListsForSite(CURRENT_SITE);

	$count_lists =mysql_num_rows($result_list);

	for ($i = 0; $i < $count_lists; $i++)
	{
		$row_list = mysql_fetch_assoc($result_list);
		$items[$row_list['lists_id']] = $row_list['lists_name'];
	}

	$param['items'] = $items;
	$param['attributes']['style'] = 'width: 320px;';
	$param['div_attributes']['style'] = 'float: left;';
	$admin_forms_fields->AddField($param);
}


// Значение по умолчанию
$param = array();
$param['tab_id'] = $tab_id;
$param['div_id'] = 'default_value_id';
$param['name'] = 'information_propertys_groups_default_value';
$param['caption'] = $GLOBALS['MSG_information_systems']['information_propertys_add_form_group_default_value'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $information_propertys_groups_default_value;
$param['attributes'] = array();
$param['attributes']['style'] = 'width: 660px;';
$param['div_attributes']['style'] = 'float: left;';
$admin_forms_fields->AddField($param);

// Значение по умолчанию для поля типа "Дата"
$param = array();
$param['tab_id'] = $tab_id;
$param['div_id'] = 'default_date_value_id';
$param['name'] = 'information_propertys_groups_date_default_value';
$param['caption'] = $GLOBALS['MSG_information_systems']['information_propertys_add_form_group_default_value'];
$param['type'] = 10; // Поле ввода.
$param['value'] = $information_propertys_groups_date_default_value;
$param['attributes'] = array();
$param['attributes']['size'] = 10;
$admin_forms_fields->AddField($param);

// Значение по умолчанию для поля типа "Дата-время"
$param = array();
$param['tab_id'] = $tab_id;
$param['div_id'] = 'default_datetime_value_id';
$param['name'] = 'information_propertys_groups_datetime_default_value';
$param['caption'] = $GLOBALS['MSG_information_systems']['information_propertys_add_form_group_default_value'];
$param['type'] = 11; // Поле ввода.
$param['value'] = $information_propertys_groups_datetime_default_value;
$param['attributes'] = array();
$param['attributes']['size'] = 22;
$admin_forms_fields->AddField($param);

// ширина большого изображения по умолчанию (Тип: строка)
$param = array();
$param['tab_id'] = $tab_id;
$param['div_id'] = 'information_propertys_groups_big_width';
$param['name'] = 'information_propertys_groups_big_width';
$param['caption'] = $GLOBALS['MSG_information_systems']['form_edit_add_group_big_max_width'];
$param['type'] = 0; // Поле ввода
$param['value'] = $information_propertys_groups_big_width;
$param['attributes']['style'] = 'width: 320px;';
$param['div_attributes']['style'] = 'float: left;';
$admin_forms_fields->AddField($param);

// высота большого изображения по умолчанию (Тип: строка)
$param = array();
$param['tab_id'] = $tab_id;
$param['div_id'] = 'information_propertys_groups_big_height';
$param['name'] = 'information_propertys_groups_big_height';
$param['caption'] = $GLOBALS['MSG_information_systems']['form_edit_add_group_big_max_height'];
$param['type'] = 0; // Поле ввода
$param['value'] = $information_propertys_groups_big_height;
$param['attributes']['style'] = 'width: 320px;';
$param['div_attributes']['style'] = 'float: left;';
$admin_forms_fields->AddField($param);

// Разделитель.
$admin_forms_fields->AddSeparator($tab_id);

// ширина малого изображения по умолчанию (Тип: строка)
$param = array();
$param['tab_id'] = $tab_id;
$param['div_id'] = 'information_propertys_groups_small_width';
$param['name'] = 'information_propertys_groups_small_width';
$param['caption'] = $GLOBALS['MSG_information_systems']['form_edit_add_group_small_max_width'];
$param['type'] = 0; // Поле ввода
$param['value'] = $information_propertys_groups_small_width;
$param['attributes']['style'] = 'width: 320px;';
$param['div_attributes']['style'] = 'float: left;';
$admin_forms_fields->AddField($param);

// высота малого изображения по умолчанию (Тип: строка)
$param = array();
$param['tab_id'] = $tab_id;
$param['div_id'] = 'information_propertys_groups_small_height';
$param['name'] = 'information_propertys_groups_small_height';
$param['caption'] = $GLOBALS['MSG_information_systems']['form_edit_add_group_small_max_height'];
$param['type'] = 0; // Поле ввода
$param['value'] = $information_propertys_groups_small_height;
$param['attributes']['style'] = 'width: 320px;';
$param['div_attributes']['style'] = 'float: left;';
$admin_forms_fields->AddField($param);

// Разделитель.
$admin_forms_fields->AddSeparator($tab_id);

// Флажок
$param = array();
$param['tab_id'] = $tab_id;
$param['div_id'] = 'default_checked_value_id';
$param['type'] = 1;
$param['name'] = 'information_propertys_groups_define_checked_value';
$param['html_id'] = 'id_define_checked_value';
$param['caption'] = $GLOBALS['MSG_information_systems']['information_propertys_groups_add_form_default_checked'];
$param['value'] = $information_propertys_groups_define_checked_value;
$admin_forms_fields->AddField($param);

// Имя XML-тэга
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'information_propertys_groups_xml_name';
$param['caption'] = $GLOBALS['MSG_information_systems']['information_propertys_groups_add_form_xml_name'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $information_propertys_groups_xml_name;
$param['format']['lib']['value'] = 'latinBase';
$param['format']['minlen']['value'] = 1;
$param['format']['maxlen']['value'] = 255;
$param['attributes']['style'] = 'width: 320px;';
$param['div_attributes']['style'] = 'float: left;';
$admin_forms_fields->AddField($param);

$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'action';
$param['type'] = 4; // Поле ввода.
$param['value'] = 'show_information_propertys_groups';

$admin_forms_fields->AddField($param);

$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'information_system_id';
$param['type'] = 4; // Поле ввода.
$param['value'] = $information_system_id;

$admin_forms_fields->AddField($param);

// Редактирование дополнительного свойства информационной группы
if ($information_property_groups_id != 0)
{
	// Идентификатор дополнительного свойства информационной группы
	$param = array();
	$param['tab_id'] = $tab_id;
	$param['name'] = 'information_property_groups_id';
	$param['type'] = 4; // Поле ввода.
	$param['value'] = $information_property_groups_id;

	$admin_forms_fields->AddField($param);
}

// Идентификатор группы дополнительных свойств информационной группы
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'information_systems_dir_parent_id';
$param['type'] = 4; // Поле ввода.
$param['value'] = $information_systems_dir_parent_id;
$admin_forms_fields->AddField($param);

// Кнопка "Сохранить".
$param = array();
$param['name'] = 'save_information_groups_property';
$param['caption'] = $GLOBALS['MSG_information_systems']['information_groups_save_form_button_name'];
$param['image'] = '/admin/images/add.gif';
$param['attributes']['onclick'] = "return SendForm('{$admin_forms_fields->GetWindowId()}', '{$admin_forms_fields->AAction}', '{$admin_forms_fields->AAdditionalParams}', this, ".to_int($_REQUEST['admin_forms_id']).", 'load_data', " . to_int($admin_forms_fields->form_params['current_page']) . ", " . to_int($admin_forms_fields->form_params['on_page']) . " )";
$param['attributes']['type'] = 'button';
$admin_forms_fields->AddButton($param);

// Кнопка "Применить".
$param = array();
$param['name'] = 'add_information_groups_property';
$param['caption'] = $GLOBALS['MSG_information_systems']['information_groups_add_form_button_name'];
$param['image'] = '/admin/images/add.gif';
$param['attributes']['onclick'] = "return SendForm('{$admin_forms_fields->GetWindowId()}', '{$admin_forms_fields->AAction}', '{$admin_forms_fields->AAdditionalParams}', this, ".to_int($_REQUEST['admin_forms_id']).", 'load_data', " . to_int($admin_forms_fields->form_params['current_page']) . ", " . to_int($admin_forms_fields->form_params['on_page']) . " )";
$param['attributes']['type'] = 'submit';
$admin_forms_fields->AddButton($param);

ob_start();
?><script language="JavaScript">
ShowRowsGroupPropertys('<?php echo $window_id?>', <?php echo $information_propertys_groups_type?>)
</script><?php
$external_html = ob_get_clean();

$admin_forms_fields->SetExternalHtml($external_html);
// Отображение формы.
$admin_forms_fields->ShowForm();
?>