<?php 
/**
 * Система управления сайтом HostCMS v. 5.xx
 * Copyright © 2005-2010 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
 *
 * Форма добаления/редактирования дополнительных свойств узлов структуры.
 * 
 * Файл: /admin/structure/action/edit_structure_propertys.php
 * 
 * @author Hostmake LLC
 * @version 5.x
 */
if (!isset($structure_propertys_id))
{
	$structure_propertys_id = $_REQUEST['structure_propertys_id'];
}

$datetime = new DateClass();

if (isset($structure_parent_id))
{
	$structure_parent_id = $structure_parent_id;
}
else
{
	$structure_parent_id = 0;
}

$admin_forms_fields = new admin_forms_fields();

$form_params = array();
$form_params['title'] = $structure_propertys_id == 0 ? $GLOBALS['MSG_structure']['structure_propertys_add_form_title'] : $GLOBALS['MSG_structure']['structure_propertys_edit_form_title'];
$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/structure/structure.php';
$form_params['form_attribs']['name'] = 'EditAddNodeProp';

$DataBase = & singleton('DataBase');

$struct = & singleton('Structure');

$path_array = $struct->GetStructurePathArray($structure_parent_id, false);

$new_path_array = array();

$new_path_array[0]['name'] = $GLOBALS['MSG_structure']['parent_dir'];
$new_path_array[0]['link'] = $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/structure/structure.php', "&action=show&structure_parent_id=0", 82, 'load_data');
$new_path_array[0]['onclick'] = $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/structure/structure.php', "&action=show&structure_parent_id=0", 82, 'load_data');

if ($path_array)
{
	foreach ($path_array as $keys => $values)
	{
		foreach ($values as $key => $value)
		{
			if (is_numeric($key))
			{
				$new_path_array[] = array (
				'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/structure/structure.php', "&action=show&structure_parent_id={$key}", 82, 'load_data', 0, 0, 0, 0),
				'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/structure/structure.php', "&action=show&structure_parent_id={$key}", 82, 'load_data', 0, 0, 0, 0),
				'name' => $value);
			}
		}
	}
}

$new_path_array[] = array(
"link" => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/structure/structure.php', "&action=show_structure_propertys&structure_parent_id={$structure_parent_id}", 86, 'load_data'),
"onclick" => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/structure/structure.php', "&action=show_structure_propertys&structure_parent_id={$structure_parent_id}", 86, 'load_data'),
"name" => $GLOBALS['MSG_structure']['structure_propertys_show_title']);

$form_params['path_array'] = $new_path_array;

$admin_forms_fields->admin_forms_fields($form_params);

// Редактирование дополнительного свойства
if ($structure_propertys_id)
{
	$type = 1;
	$res = $struct->SelectStructurePropertys(CURRENT_SITE, $structure_propertys_id);
	$res = mysql_fetch_assoc($res);
	$site_id = to_int($res['site_id']);
	$structure_propertys_name = to_str($res['structure_propertys_name']);
	$structure_propertys_type = to_str($res['structure_propertys_type']);
	$structure_propertys_order = to_int($res['structure_propertys_order']);
	$structure_propertys_define_value = to_str($res['structure_propertys_define_value']);
	$structure_propertys_date_default_value = $structure_propertys_define_value;
	$structure_propertys_datetime_default_value = $structure_propertys_define_value;
	$structure_propertys_define_checked_value = to_int($structure_propertys_date_default_value);
	$structure_propertys_xml_name = to_str($res['structure_propertys_xml_name']);
	$structure_propertys_lists_id = to_int($res['structure_propertys_lists_id']);
	$structure_propertys_information_systems_id = to_int($res['structure_propertys_information_systems_id']);
	$users_id = to_int($res['users_id']);
}
else
{
	$site_id = CURRENT_SITE;
	$structure_propertys_name = '';
	$structure_propertys_type = 0;
	$structure_propertys_order = 0;
	$structure_propertys_define_value = '';
	$structure_propertys_date_default_value = ''; // Дата
	$structure_propertys_datetime_default_value = ''; // ДатаВремя
	$structure_propertys_define_checked_value = 0;
	$structure_propertys_xml_name = '';
	$structure_propertys_lists_id = 0;
	$structure_propertys_information_systems_id = 0;
}

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

// Название
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'structure_propertys_name';
$params['caption'] = $GLOBALS['MSG_structure']['structure_propertys_add_form_name'];
$params['type'] = 0; // Текстовое поле
$params['value'] = $structure_propertys_name;
$params['attributes']['class'] = 'large';
$params['format']['minlen']['value'] = 1;
$params['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($params);

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

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

// Заполняем поля элемента "Тип"
$arr = array(0 => $GLOBALS['MSG_structure']['structure_propertys_add_form_type_name1'],
1 => $GLOBALS['MSG_structure']['structure_propertys_add_form_type_name2'],
2 => $GLOBALS['MSG_structure']['structure_propertys_add_form_type_name3'],
4 => $GLOBALS['MSG_structure']['structure_propertys_add_form_type_name5'],
5 => $GLOBALS['MSG_structure']['structure_propertys_add_form_type_name6'],
6 => $GLOBALS['MSG_structure']['structure_propertys_add_form_type_name7'],
7 => $GLOBALS['MSG_structure']['structure_propertys_add_form_type_name8'],
8 => $GLOBALS['MSG_structure']['structure_propertys_add_form_type_name9'],
9 => $GLOBALS['MSG_structure']['structure_propertys_add_form_type_name10']);

if (class_exists('lists'))
{
	$arr[3] = $GLOBALS['MSG_structure']['structure_propertys_add_form_type_name4'];
}

// Тип
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'structure_propertys_type';
$params['caption'] = $GLOBALS['MSG_structure']['structure_propertys_add_form_type'];
$params['type'] = 2; // Выпадающий список
$params['value'] = $structure_propertys_type;
$params['attributes']['onchange'] = "ShowRows('{$window_id}', this.value)";
$items = array();
foreach ($arr as $key => $value)
{
	$items[$key] = $value;
}
$params['items'] = $items;
$params['attributes']['style'] = 'width: 210px;';
$params['div_attributes']['style'] = 'float: left;';
$admin_forms_fields->AddField($params);

// Имя XML тэга
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'structure_propertys_xml_name';
$params['caption'] = $GLOBALS['MSG_structure']['structure_add_form_xml_name'];
$params['type'] = 0; // Текстовое поле
$params['value'] = $structure_propertys_xml_name;
$params['format']['lib']['value'] = 'latinBase';
$params['format']['lib']['message'] = $GLOBALS['MSG_structure']['structure_propertys_add_form_xml_name_error'];
$params['format']['minlen']['value'] = 1;
$params['format']['maxlen']['value'] = 255;
$params['attributes']['style'] = 'width: 210px;';
$params['div_attributes']['style'] = 'float: left;';
$admin_forms_fields->AddField($params);

// Порядковый номер
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'structure_propertys_order';
$params['caption'] = $GLOBALS['MSG_structure']['structure_propertys_add_form_order'];
$params['type'] = 0; // Текстовое поле
$params['value'] = $structure_propertys_order;
$params['format']['lib']['value'] = 'integer';
$params['format']['minlen']['value'] = 1;
$params['format']['maxlen']['value'] = 6;
$params['attributes']['style'] = 'width: 210px;';
$params['div_attributes']['style'] = 'float: left;';
$admin_forms_fields->AddField($params);

// Разделитель.
$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_items_define_checked_value';
$param['html_id'] = 'id_define_checked_value';
$param['caption'] = $GLOBALS['MSG_structure']['structure_add_form_default_checked'];
$param['value'] = $structure_propertys_define_checked_value;

$admin_forms_fields->AddField($param);

// Значение по умолчанию (Число, Строка, Большое текстовое поле)
$params = array();
$params['tab_id'] = $tab_id;
$params['div_id'] = 'structure_propertys_define_value';
$params['name'] = 'structure_propertys_define_value';
$params['caption'] = $GLOBALS['MSG_structure']['structure_propertys_add_form_default_value'];
$params['type'] = 0; // Текстовое поле
$params['value'] = $structure_propertys_define_value;
$params['format']['maxlen']['value'] = 255;
$admin_forms_fields->AddField($params);

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

// Значение по умолчанию для поля типа "Дата"
$param = array();

$param['tab_id'] = $tab_id;
$param['div_id'] = 'default_date_value_id';
$param['name'] = 'structure_propertys_date_default_value';
$param['caption'] = $GLOBALS['MSG_structure']['structure_propertys_add_form_default_value'];
$param['type'] = 10; // Поле ввода даты.
$param['value'] = $structure_propertys_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'] = 'structure_propertys_datetime_default_value';
$param['caption'] = $GLOBALS['MSG_structure']['structure_propertys_add_form_default_value'];
$param['type'] = 11; // Поле ввода датывремени.
$param['value'] = $structure_propertys_datetime_default_value;
$param['attributes'] = array();
$param['attributes']['size'] = 22;

$admin_forms_fields->AddField($param);

if (class_exists('lists'))
{
	// Заполняем поля элемента "Списки"
	$arr = array();
	$list = new lists();
	$res = $list->GetAllListsForSite(CURRENT_SITE);

	while ($row = mysql_fetch_assoc($res))
	{
		$arr[$row['lists_id']] = $row['lists_name'];
	}

	// Списки (Список)
	$params = array();
	$params['tab_id'] = $tab_id;
	$params['div_id'] = 'structure_propertys_lists_id';
	$params['name'] = 'structure_propertys_lists_id';
	$params['caption'] = $GLOBALS['MSG_structure']['structure_add_form_lists'];
	$params['type'] = 2; // Выпадающий список
	$params['items'] = $arr;
	$params['value'] = $structure_propertys_lists_id;
	$admin_forms_fields->AddField($params);

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

// Заполняем поля элемента "Информационная система"
$arr = array();
$is = & singleton('InformationSystem');
$res = $is->GetAllInformationSystems(false);
while ($row = mysql_fetch_assoc($res))
{
	$arr[$row['information_systems_id']] = $row['information_systems_name'];
}

// Информационная система
$params = array();
$params['tab_id'] = $tab_id;
$params['div_id'] = 'structure_propertys_information_systems_id';
$params['name'] = 'structure_propertys_information_systems_id';
$params['caption'] = $GLOBALS['MSG_structure']['structure_propertys_add_form_inf_system'];
$params['type'] = 2; // Выпадающий список
$params['items'] = $arr;
$params['value'] = $structure_propertys_information_systems_id;
$admin_forms_fields->AddField($params);

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

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

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

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

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

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

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

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

$admin_forms_fields->SetExternalHtml($external_html);

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