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

$form_params = array();
$form_params['title'] = $shop_properties_items_dir_id==0?$GLOBALS['MSG_shops']['form_edit_add_title_add']:$GLOBALS['MSG_shops']['form_edit_add_title_edit'];
$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/shop/shop.php';
$form_params['form_attribs']['name'] = 'EditAddDirProperty';

$shop = & singleton('shop');

$admin_forms_fields = new admin_forms_fields();

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

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

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

$shop = & singleton('shop');

$data = new DateClass();

$DataBase = & singleton('DataBase');

$row = $shop->GetShop($shop_shops_id);

$path_array = $shop->GetShopPathArray($shop_groups_parent_id, false);

// Преобразуем идентификаторы групп в ссылки на группы.
$new_path_array = array();
$new_path_array[0]['name'] = $GLOBALS['MSG_shops']['header_admin__list_forms'];
$new_path_array[0]['link'] = $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', '', 54, 'load_data');
$new_path_array[0]['onclick'] = $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', '', 54, 'load_data');

$new_path_array[1]['name'] = $row['shop_shops_name'];
$new_path_array[1]['link'] = $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_groups_parent_id=0&shop_shops_id=$shop_shops_id", 65, 'load_data');
$new_path_array[1]['onclick'] = $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_groups_parent_id=0&shop_shops_id=$shop_shops_id", 65, 'load_data');


if ($path_array)
{
	foreach ($path_array as $key => $value)
	{
		$new_path_array[] = array (
		'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_groups_parent_id=$key&shop_shops_id=$shop_shops_id", 65, 'load_data'),
		'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_groups_parent_id=$key&shop_shops_id=$shop_shops_id", 65, 'load_data'),
		'name' => $value);
	}
}
$new_path_array[] = array("name" => $GLOBALS['MSG_shops']['list_of_properties_add_form_link'],
"link" => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 67, 'load_data'),
"onclick" => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 67, 'load_data')
);

// Генерируем дополнительные хлебные крошки
$path_array = $shop->GetAdditionalPropertyPathArray($ext_shop_groups_parent_id);

if (count($path_array) > 0)
{
	foreach ($path_array as $key => $value)
	{
		$new_path_array[] = array (
		'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_groups_parent_id=$shop_groups_parent_id&shop_shops_id=$shop_shops_id&ext_shop_groups_parent_id=$key", 67, 'load_data'),
		'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_groups_parent_id=$shop_groups_parent_id&shop_shops_id=$shop_shops_id&ext_shop_groups_parent_id=$key", 67, 'load_data'),
		'name' => $value);
	}
}

$form_params['path_array'] = $new_path_array;

$admin_forms_fields->admin_forms_fields($form_params);

if ($shop_properties_items_dir_id)
{
	$shop_properties_items_dir_row = $shop->GetPropertiesItemsDir($shop_properties_items_dir_id);
	$shop_properties_items_dir_parent_id = $shop_properties_items_dir_row['shop_properties_items_dir_parent_id'];
	$shop_properties_items_dir_name = $shop_properties_items_dir_row['shop_properties_items_dir_name'];
	$shop_properties_items_dir_description = $shop_properties_items_dir_row['shop_properties_items_dir_description'];
	$shop_properties_items_dir_order = $shop_properties_items_dir_row['shop_properties_items_dir_order'];
}
else
{
	// Пока 0, затем нужно заменить на идентификатор полученной группы из запроса $_REQUEST
	$shop_properties_items_dir_parent_id = $ext_shop_groups_parent_id;
	$shop_properties_items_dir_name = '';
	$shop_properties_items_dir_description = '';
	$shop_properties_items_dir_order = 0;
}

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

$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_properties_items_dir_name';
$param['caption'] = $GLOBALS['MSG_shops']['form_edit_add_shop_properties_items_dir_name'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $shop_properties_items_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);

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

$mas = $shop->GetDelimitedGroupsExtProperty(0, $shop_shops_id, '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');

$mas_count = count($mas);

for ($i = 0; $i < $mas_count; $i++)
{
	if (isset($shop_properties_items_dir_id) && ($shop_properties_items_dir_id == to_int($mas[$i]['shop_properties_items_dir_id'])))
	{
		continue;
	}
	$array[$mas[$i]['shop_properties_items_dir_id']] = $mas[$i]['separator'].$mas[$i]['shop_properties_items_dir_name'];
}

$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_properties_items_dir_parent_id';
$param['caption'] = $GLOBALS['MSG_shops']['form_edit_add_shop_properties_items_dir_parent_id'];
$param['type'] = 2; // Выпадающий список.
$param['value'] = $shop_properties_items_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'] = 'shop_properties_items_dir_description';
$param['caption'] = $GLOBALS['MSG_shops']['form_edit_add_shop_properties_items_dir_description'];
$param['type'] = 5; // Текстовое поле.
$param['value'] = $shop_properties_items_dir_description;
$param['attributes']['rows'] = 10;
$admin_forms_fields->AddField($param);
// Разделитель.
$admin_forms_fields->AddSeparator($tab_id);

$param = array();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_properties_items_dir_order';
$param['caption'] = $GLOBALS['MSG_shops']['form_edit_add_shop_properties_items_dir_order'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $shop_properties_items_dir_order;
$admin_forms_fields->AddField($param);
// Разделитель.
$admin_forms_fields->AddSeparator($tab_id);

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

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

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

// передеам скрытое поле с идентификатором адреса если он есть
if ($shop_properties_items_dir_id)
{
	$param = array();
	$param['tab_id'] = $tab_id;
	$param['name'] = 'shop_properties_items_dir_id';
	$param['caption'] = '';
	$param['type'] = 4; // hidden.
	$param['value'] = $shop_properties_items_dir_id;
	$admin_forms_fields->AddField($param);
}

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

// Кнопка "Применить".
$param = array();
$param['name'] = 'add_dir_property';
$param['caption'] = $GLOBALS['MSG_shops']['apply'];
$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();
?>