<?php


/**
 * Система управления сайтом HostCMS v. 5.xx
 * Copyright © 2005-2010 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
 *
 * Форма создания модификаций товара.
 *
 * Файл: /admin/shop/action/form_create_modification.php
 *
 * @author Hostmake LLC
 * @version 5.x
 */

$form_params = array ();
$form_params['title'] = $GLOBALS['MSG_shops']['create_modification_title'];
$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/shop/shop.php';

$shop = & singleton('shop');
$DataBase = & singleton('DataBase');
$admin_forms_fields = new admin_forms_fields();

$shop_id = to_int($_REQUEST['shop_shops_id']);
$shop_groups_parent_id = to_int($_REQUEST['shop_groups_parent_id']);
$shop_items_catalog_id = to_int($_REQUEST['shop_items_catalog_modification_id']);

$shop_row = $shop->GetShop($shop_id, array (
	'cache_off' => true
));
$item_row = $shop->GetItem($shop_items_catalog_id, array (
	'cache_off' => true
));

$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'] = $shop_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_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_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_id", 65, 'load_data'),
			'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_groups_parent_id=$key&shop_shops_id=$shop_id", 65, 'load_data'),
			'name' => $value
		);
	}
}

$new_path_array[] = array (
	'name' => sprintf($GLOBALS['MSG_shops']['item_modification_title'], $item_row['shop_items_catalog_name']),
	'link' => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_id&shop_groups_parent_id=$shop_groups_parent_id&shop_items_catalog_modification_id=$shop_items_catalog_id", 81, 'load_data'),
	'onclick' => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&shop_shops_id=$shop_id&shop_groups_parent_id=$shop_groups_parent_id&shop_items_catalog_modification_id=$shop_items_catalog_id", 81, 'load_data')
);

// Массив хлебных крошек
$form_params['path_array'] = $new_path_array;
$admin_forms_fields->admin_forms_fields($form_params);

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

$property_name_array = array ();

// Модуль "списки" включен
if (class_exists('lists'))
{
	$lists = & singleton('lists');

	// Получаем все доступные доп. свойства товаров
	$properties_for_group_res = $shop->GetPropertiesOfGroupForXml($shop_id, $shop_groups_parent_id);

	if ($properties_for_group_res)
	{
		while ($properties_for_group_row = mysql_fetch_assoc($properties_for_group_res))
		{
			// Списки
			if ($properties_for_group_row['shop_list_of_properties_type'] == 2)
			{
				// Получаем информацию о списке
				$list_values = $lists->GetListItemsById(to_int($properties_for_group_row['lists_id']));

				if (count($list_values))
				{
					$property_name_array[] = sprintf($GLOBALS['MSG_shops']['create_modification_property_name_template'], $properties_for_group_row['shop_list_of_properties_name'], $properties_for_group_row['shop_list_of_properties_id']);

					// Доступность свойства
					$param = array ();
					$param['tab_id'] = $tab_id;
					$param['name'] = "property_{$properties_for_group_row['shop_list_of_properties_id']}";
					$param['caption'] = '&nbsp;';
					$param['lable'] = sprintf($GLOBALS['MSG_shops']['create_modification_property_enable'], $properties_for_group_row['shop_list_of_properties_name'], $properties_for_group_row['shop_list_of_properties_id']);
					$param['type'] = 1; // Флажок
					$param['value'] = 1;
					$admin_forms_fields->AddField($param);

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

// Цена
$param = array ();
$param['tab_id'] = $tab_id;
$param['name'] = 'price';
$param['caption'] = $GLOBALS['MSG_shops']['create_modification_price'];
$param['type'] = 0; // Поле ввода.
$param['value'] = $item_row['shop_items_catalog_price'];
$param['format']['lib']['value'] = 'decimal';
$param['div_attributes']['style'] = 'float: left; margin-right: 10px; width: 75px;';
$admin_forms_fields->AddField($param);

// Получаем список валют
$items_arr = array ();

$currency_res = $shop->GetAllCurrency();

while ($currency_row = mysql_fetch_assoc($currency_res))
{
	$items_arr[$currency_row['shop_currency_id']] = $currency_row['shop_currency_name'];
}

// Валюты
$param = array ();
$param['tab_id'] = $tab_id;
$param['name'] = 'items_catalog_currency';
$param['caption'] = '&nbsp;';
$param['type'] = 2; // список
$param['items'] = $items_arr;
$param['value'] = $item_row['shop_currency_id'];
$param['attributes']['style'] = 'width: 100px;';
$param['div_attributes']['style'] = 'float: left;';
$admin_forms_fields->AddField($param);

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

// Единицы измерения
// Получаем список единиц измерения
$items_arr = array (
0 => '...'
);

$mesures_res = $shop->GetAllMesures();

while ($mesures_row = mysql_fetch_assoc($mesures_res))
{
	$items_arr[$mesures_row['shop_mesures_id']] = $mesures_row['shop_mesures_name'];
}

$param = array ();
$param['tab_id'] = $tab_id;
$param['name'] = 'items_catalog_mesures';
$param['caption'] = '&nbsp;';
$param['type'] = 2; // список
$param['items'] = $items_arr;
$param['value'] = $item_row['shop_mesures_id'];
$param['attributes']['style'] = 'width: 100px;';
$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['name'] = 'items_catalog_marking';
$param['caption'] = $GLOBALS['MSG_shops']['create_modification_mark'];
$param['type'] = 0; // поле ввода
$param['value'] = sprintf($GLOBALS['MSG_shops']['create_modification_mark_template'], $item_row['shop_items_catalog_marking']);
$param['format']['maxlen']['value'] = 50;
$admin_forms_fields->AddField($param);

// Справка
$param = array ();
$param['tab_id'] = $tab_id;
$param['name'] = 'info_mark';
$param['caption'] = '&nbsp;';
$param['type'] = 8; // Текст
$param['value'] = $GLOBALS['MSG_shops']['create_modification_mark_template_info'];
$param['attributes']['style'] = 'width: 100px;';
$param['div_attributes']['style'] = 'float: left; margin-top: -20px';
$admin_forms_fields->AddField($param);

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

if (count($property_name_array) > 0)
{
	// Название
	$param = array ();
	$param['tab_id'] = $tab_id;
	$param['name'] = 'items_catalog_name';
	$param['caption'] = $GLOBALS['MSG_shops']['create_modification_name'];
	$param['type'] = 0; // поле ввода
	$param['value'] = $item_row['shop_items_catalog_name'] . " " . implode(", ", $property_name_array);
	$param['format']['maxlen']['value'] = 255;
	$admin_forms_fields->AddField($param);
}

// Справка
$param = array ();
$param['tab_id'] = $tab_id;
$param['name'] = 'info';
$param['caption'] = '&nbsp;';
$param['type'] = 8; // Текст
$param['value'] = sprintf($GLOBALS['MSG_shops']['create_modification_name_template_info'], $item_row['shop_items_catalog_name'], $item_row['shop_items_catalog_name']);
$param['attributes']['style'] = 'width: 100px;';
$param['div_attributes']['style'] = 'float: left; margin-top: -20px';
$admin_forms_fields->AddField($param);

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

// Скопировать основные атрибуты товара
$param = array ();
$param['tab_id'] = $tab_id;
$param['name'] = "copy_main_properties";
$param['caption'] = '&nbsp;';
$param['lable'] = $GLOBALS['MSG_shops']['create_modification_copy_main_properties'];
$param['type'] = 1; // Флажок
$param['value'] = 0;
$param['div_attributes']['style'] = 'margin-left: -8px;';
$admin_forms_fields->AddField($param);

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

// Скопировать seo-поля
$param = array ();
$param['tab_id'] = $tab_id;
$param['name'] = "copy_seo";
$param['caption'] = '&nbsp;';
$param['lable'] = $GLOBALS['MSG_shops']['create_modification_copy_seo'];
$param['type'] = 1; // Флажок
$param['value'] = 0;
$param['div_attributes']['style'] = 'margin-left: -8px;';
$admin_forms_fields->AddField($param);

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

// Скопировать параметры экспорта/импорта
$param = array ();
$param['tab_id'] = $tab_id;
$param['name'] = "copy_export_import";
$param['caption'] = '&nbsp;';
$param['lable'] = $GLOBALS['MSG_shops']['create_modification_copy_export_import'];
$param['type'] = 1; // Флажок
$param['value'] = 0;
$param['div_attributes']['style'] = 'margin-left: -8px;';
$admin_forms_fields->AddField($param);

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

// Скопировать дополнительные цены товара
$param = array ();
$param['tab_id'] = $tab_id;
$param['name'] = "copy_prices_to_item";
$param['caption'] = '&nbsp;';
$param['lable'] = $GLOBALS['MSG_shops']['create_modification_copy_prices_to_item'];
$param['type'] = 1; // Флажок
$param['value'] = 0;
$param['div_attributes']['style'] = 'margin-left: -8px;';
$admin_forms_fields->AddField($param);

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

// Скопировать специальные цены товара
$param = array ();
$param['tab_id'] = $tab_id;
$param['name'] = "copy_specials_prices_to_item";
$param['caption'] = '&nbsp;';
$param['lable'] = $GLOBALS['MSG_shops']['create_modification_copy_specials_prices_to_item'];
$param['type'] = 1; // Флажок
$param['value'] = 0;
$param['div_attributes']['style'] = 'margin-left: -8px;';
$admin_forms_fields->AddField($param);

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

// Скопировать сопутствующие товары
$param = array ();
$param['tab_id'] = $tab_id;
$param['name'] = "copy_tying_products";
$param['caption'] = '&nbsp;';
$param['lable'] = $GLOBALS['MSG_shops']['create_modification_copy_tying_products'];
$param['type'] = 1; // Флажок
$param['value'] = 0;
$param['div_attributes']['style'] = 'margin-left: -8px;';
$admin_forms_fields->AddField($param);

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

// Скопировать доп. свойства
$param = array ();
$param['tab_id'] = $tab_id;
$param['name'] = "copy_external_property";
$param['caption'] = '&nbsp;';
$param['lable'] = $GLOBALS['MSG_shops']['create_modification_copy_external_property'];
$param['type'] = 1; // Флажок
$param['value'] = 0;
$param['div_attributes']['style'] = 'margin-left: -8px;';
$admin_forms_fields->AddField($param);

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

// Скопировать доп. свойства
$param = array ();
$param['tab_id'] = $tab_id;
$param['name'] = "copy_tags";
$param['caption'] = '&nbsp;';
$param['lable'] = $GLOBALS['MSG_shops']['create_modification_copy_tags'];
$param['type'] = 1; // Флажок
$param['value'] = 0;
$param['div_attributes']['style'] = 'margin-left: -8px;';
$admin_forms_fields->AddField($param);

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

/*// Тип основного товара - обычный
 if ($item_row['shop_items_catalog_type'] == 0)
 {
 $eitems_res = $shop->GetEitemsForItem($shop_items_catalog_id);

 // У основного товара есть электронные товары
 if (mysql_num_rows($eitems_res))
 {
 // Скопировать электронные товары
 $param = array ();
 $param['tab_id'] = $tab_id;
 $param['name'] = "copy_eitems";
 $param['caption'] = '&nbsp;';
 $param['lable'] = $GLOBALS['MSG_shops']['create_modification_copy_eitems'];
 $param['type'] = 1; // Флажок
 $param['value'] = 0;
 $param['div_attributes']['style'] = 'margin-left: -8px;';
 $admin_forms_fields->AddField($param);

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

// Передаем идентификатор группы, из которой пришли
$param = array ();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_group_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'] = 'shop_shops_id';
$param['caption'] = '';
$param['type'] = 4; // hidden.
$param['value'] = $shop_id;
$admin_forms_fields->AddField($param);

// Передаем идентификатор основного товара
$param = array ();
$param['tab_id'] = $tab_id;
$param['name'] = 'shop_items_catalog_id';
$param['caption'] = '';
$param['type'] = 4; // hidden.
$param['value'] = $shop_items_catalog_id;
$admin_forms_fields->AddField($param);

// Передаем идентификатор магазина
/*$param = array ();
 $param['tab_id'] = $tab_id;
 $param['name'] = 'hostcmsAAdditionalParams';
 $param['caption'] = '';
 $param['type'] = 4; // hidden.
 $param['value'] = "&shop_shops_id=$shop_id";
 $admin_forms_fields->AddField($param);*/

$param = array ();
$param['name'] = 'create_modifications';
$param['caption'] = $GLOBALS['MSG_shops']['create_modification_button'];
//$param['attributes']['onclick'] = "return SendForm('{$admin_forms_fields->GetWindowId()}', '/admin/shop/shop.php', '&action=create_modifications', this, 0)";
$param['attributes']['onclick'] = $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']) . " )";

$admin_forms_fields->AddButton($param);

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