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

$form_params['title'] = $information_propertys_groups_dir_id==0
? $GLOBALS['MSG_information_systems']['add_property_dir']
: $GLOBALS['MSG_information_systems']['edit_property_dir'];

$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/InformationSystems/InformationSystems.php';
$form_params['form_attribs']['name'] = 'EditAddISDirPropertyGroup';

$InformationSystem = new InformationSystem();

$admin_forms_fields = new admin_forms_fields();

$DataBase = & singleton('DataBase');

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

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

$parray = array();

// Строим "хлебные крошки"
$parray[0] = 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']);

// Идентификатор текущей группы (раздела) информационных систем
$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)
	{
		$parray[] = 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']);
	}
}	

$parray[] = 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}", 12, '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}", 12, 'load_data'),
'name' => htmlspecialchars($row_information_system['information_systems_name']));

$parray[] = 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=0", 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=0", 51, 'load_data'),
'name' => sprintf($GLOBALS['MSG_information_systems']['bread_crumbs_property_groups_list'], $row_information_system['information_systems_name']));

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;
}

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

if (count($path_array) > 0)
{
	foreach ($path_array as $key => $value)
	{
		$parray[] = 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);
	}
}

$param['path_array'] = $parray;

$form_params['path_array'] = $parray;

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

$admin_forms_fields->admin_forms_fields($form_params);

if ($information_propertys_groups_dir_id)
{
	$data_row = $InformationSystem->GetPropertyGroupsDir($information_propertys_groups_dir_id);

	$information_systems_res = $data_row['information_systems_id'];

	$information_propertys_groups_dir_parent_id = $data_row['information_propertys_groups_dir_parent_id'];

	$information_propertys_groups_dir_name = $data_row['information_propertys_groups_dir_name'];

	$information_propertys_groups_dir_description = $data_row['information_propertys_groups_dir_description'];

	$information_propertys_groups_dir_order = $data_row['information_propertys_groups_dir_order'];
}
else
{
	$information_systems_res = $real_information_systems_id;

	$information_propertys_groups_dir_parent_id = $ext_is_groups_parent_id;

	$information_propertys_groups_dir_name = '';

	$information_propertys_groups_dir_description = '';

	$information_propertys_groups_dir_order = '';
}

// Параметры.
$tab_id = $admin_forms_fields->AddTab($GLOBALS['MSG_information_systems']['information_systems_form_tab_1']);

// Название директории дополнительных свойств инфоэлементов
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'information_propertys_groups_dir_name';
$param['caption'] = $GLOBALS['MSG_information_systems']['information_propertys_items_dir_name'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $information_propertys_groups_dir_name;
$param['attributes']['class'] = 'large';
$param['format']['minlen']['value'] = 1;
$param['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($param);
// Разделитель.
$admin_forms_fields->AddSeparator($tab_id);

// Описание группы
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'information_propertys_groups_dir_description';
$param['caption'] = $GLOBALS['MSG_information_systems']['information_propertys_items_dir_description'];
$param['type'] = 5; // Поле ввода.
$param['attributes']['rows'] = 10;
$param['value'] = $information_propertys_groups_dir_description;
$admin_forms_fields->AddField($param);
// Разделитель.
$admin_forms_fields->AddSeparator($tab_id);

// Получаем список всех информационных систем
$is_array = $InformationSystem->GetAllInformationSystems(CURRENT_SITE);

$infosys_array = array(0 => ' ... ');

if ($is_array)
{
	while ($is_row = mysql_fetch_assoc($is_array))
	{
		$infosys_array[$is_row['information_systems_id']] = $is_row['information_systems_name'];
	}
}

// Информационная система
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'information_systems_res';
$param['caption'] = $GLOBALS['MSG_information_systems']['information_systems_id'];
$param['type'] = 2; // Поле ввода.
$param['value'] = $information_systems_res;
$param['items'] = $infosys_array;
$admin_forms_fields->AddField($param);
// Разделитель.
$admin_forms_fields->AddSeparator($tab_id);

// Получаем список всех групп дополнительных свойств
//$groups_dir_res = $InformationSystem->GetAllPropertyGroupsDirForInformationSystem($real_information_systems_id);
$groups_dir_res = $InformationSystem->GetDelimitedGroups(0, $real_information_systems_id, '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');

$count = count($groups_dir_res);

$array = array(0 => ' ... ');

for ($i = 0; $i < $count; $i++)
{
	if (isset($information_propertys_groups_dir_id) && ($information_propertys_groups_dir_id == to_int($groups_dir_res[$i]['information_propertys_groups_dir_id'])))
	{
		continue;
	}
	$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_parent_id';
$param['caption'] = $GLOBALS['MSG_information_systems']['information_propertys_items_dir_parent_id'];
$param['type'] = 2; // Выпадающий список.
$param['value'] = $information_propertys_groups_dir_parent_id;
$param['items'] = $array;
$admin_forms_fields->AddField($param);
// Разделитель.
$admin_forms_fields->AddSeparator($tab_id);

// Порядок сортировки
$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'information_propertys_groups_dir_order';
$param['caption'] = $GLOBALS['MSG_information_systems']['information_propertys_items_dir_order'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $information_propertys_groups_dir_order;
$admin_forms_fields->AddField($param);
// Разделитель.
$admin_forms_fields->AddSeparator($tab_id);



if ($information_propertys_groups_dir_id)
{
	$params = array();
	$params['tab_id'] = $tab_id;
	$params['name'] = 'information_propertys_groups_dir_id';
	$params['caption'] = '';
	$params['type'] = 4; // hidden.
	$params['value'] = $information_propertys_groups_dir_id;
	$admin_forms_fields->AddField($params);
}

$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'ext_is_groups_parent_id';
$params['caption'] = '';
$params['type'] = 4; // hidden.
$params['value'] = $ext_is_groups_parent_id;
$admin_forms_fields->AddField($params);

$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'information_systems_dir_parent_id';
$params['caption'] = '';
$params['type'] = 4; // hidden.
$params['value'] = $information_systems_dir_parent_id;
$admin_forms_fields->AddField($params);

// Кнопка "Сохранить".
$param = array();
$param['name'] = 'save_is_group_dir_property';
$param['caption'] = $GLOBALS['MSG_information_systems']['information_items_save_form_button_name'];
$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_is_group_dir_property';
$param['caption'] = $GLOBALS['MSG_information_systems']['information_items_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);

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