<?php 
/**
 * Система управления сайтом HostCMS v. 5.xx
 * Copyright © 2005-2010 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
 *
 * Форма добаления/редактирования дополнительных свойств групп товаров.
 * 
 * Файл: /admin/shop/action/form_edit_add_property_for_group_dir.php
 * 
 * @author Hostmake LLC
 * @version 5.x
 */
$admin_forms_fields = new admin_forms_fields();
$form_params = array();
$form_params['title'] = $shop_properties_groups_dir_id==0?$GLOBALS['MSG_shops']['add_group_dir']:$GLOBALS['MSG_shops']['edit_group_dir'];
$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/shop/shop.php';
$form_params['form_attribs']['name'] = 'EditAddGroupDir';

$shop = & singleton('shop');

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

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

if (isset($_REQUEST['ext_shop_groups_parent_id']))
{
	$ext_shop_groups_parent_id = to_int($_REQUEST['ext_shop_groups_parent_id']);
}
else
{
	$ext_shop_groups_parent_id = 0;
}

$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->GetHtmlCallDoLoadAjax('/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_property_for_group'],
"link" => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 135, '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", 135, 'load_data')
);

// Генерируем дополнительные хлебные крошки
$path_array = $shop->GetAdditionalPropertyDirPathArray($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", 135, '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", 135, 'load_data'),
		'name' => $value);
	}
}

$form_params['path_array'] = $new_path_array;

$admin_forms_fields = new admin_forms_fields($form_params);

// Редактирование
if ($shop_properties_groups_dir_id)
{
	$row = $shop->GetPropertiesGroupsDir($shop_properties_groups_dir_id);

	$shop_properties_groups_dir_parent_id = $row['shop_properties_groups_dir_parent_id'];

	$shop_properties_groups_dir_name = $row['shop_properties_groups_dir_name'];

	$shop_properties_groups_dir_description = $row['shop_properties_groups_dir_description'];

	$shop_properties_groups_dir_order = $row['shop_properties_groups_dir_order'];
}
// Добавление
else
{
	$shop_properties_groups_dir_parent_id = $ext_shop_groups_parent_id;

	$shop_properties_groups_dir_name = '';

	$shop_properties_groups_dir_description = '';

	$shop_properties_groups_dir_order = '';
}

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

// Название
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'shop_properties_groups_dir_name';
$params['caption'] = $GLOBALS['MSG_shops']['shop_properties_groups_dir_name'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $shop_properties_groups_dir_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);

$groups_dir_arr = $shop->GetDelimitedGroupsDirExtProperty(0, $shop_shops_id, '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');

$count = count($groups_dir_arr);

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

for ($i = 0; $i < $count; $i++)
{
	if (isset($shop_properties_groups_dir_id) && ($shop_properties_groups_dir_id == to_int($groups_dir_arr[$i]['shop_properties_groups_dir_id'])))
	{
		continue;
	}
	$array[$groups_dir_arr[$i]['shop_properties_groups_dir_id']] = $groups_dir_arr[$i]['separator'].$groups_dir_arr[$i]['shop_properties_groups_dir_name'];
}

// Родительский раздел
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'shop_properties_groups_dir_parent_id';
$params['caption'] = $GLOBALS['MSG_shops']['shop_properties_groups_dir_parent_id'];
$params['type'] = 2; // Выпадающий список.
$params['value'] = $shop_properties_groups_dir_parent_id;
$params['items'] = $array;
$admin_forms_fields->AddField($params);
// Разделитель.
$admin_forms_fields->AddSeparator($tab_id);

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

// Порядок сортировки раздела
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'shop_properties_groups_dir_order';
$params['caption'] = $GLOBALS['MSG_shops']['shop_properties_groups_dir_order'];
$params['type'] = 0; // Поле ввода.
$params['value'] = $shop_properties_groups_dir_order;
$params['attributes']['rows'] = 10;
$admin_forms_fields->AddField($params);
// Разделитель.
$admin_forms_fields->AddSeparator($tab_id);

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

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

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

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

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