<?php 
/**
 * Система управления сайтом HostCMS v. 5.xx
 * Copyright © 2005-2010 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
 *
 * Форма добаления/редактирования скидок конкретного товара.
 * 
 * Файл: /admin/shop/action/form_edit_add_item_discount.php
 * 
 * @author Hostmake LLC
 * @version 5.x
 */
if (isset($id))
{
	$edit_item_discount = $id;
}
else
{
	$edit_item_discount = 0;
}
$datetime = & singleton('DateClass');

$form_params = array();
$form_params['title'] = $edit_item_discount==0?$GLOBALS['MSG_shops']['item_discount_add_form_title']:$GLOBALS['MSG_shops']['item_discount_edit_form_title'];
$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/shop/shop.php';

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

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

$shop_items_catalog_item_id = to_int($_REQUEST['shop_items_catalog_item_id']);
$DataBase = & singleton('DataBase');
$shop = & singleton('shop');

// Получаем имя товара
$res = mysql_fetch_assoc($shop->GetItem($shop_items_catalog_item_id));

$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/shop/shop.php";
$new_path_array[1]['name'] = $row['shop_shops_name'];
$new_path_array[1]['link'] = "/admin/shop/shop.php?action=show_groups&shop_groups_parent_id=0&shop_shops_id=$shop_shops_id";


if ($path_array)
{
	foreach ($path_array as $key => $value)
	{

		$new_path_array[] = array (
		'link' => "/admin/shop/shop.php?action=show_groups&shop_groups_parent_id=$key&shop_shops_id=$shop_shops_id",
		'name' => $value);
	}
}
// Если мы пришли сюда из формы списка модификаций
if (isset($_REQUEST['shop_items_catalog_modification_id']))
{
	$shop_items_catalog_modification_id = to_int($_REQUEST['shop_items_catalog_modification_id']);

	// Получаепм имя товара от которого пришли
	$row = mysql_fetch_assoc($shop->GetItem($shop_items_catalog_modification_id));

	$new_path_array[] = array("name" => $GLOBALS['MSG_shops']['item_modification_title'].'"'.$row['shop_items_catalog_name'].'"', "link" => "/admin/shop/shop.php?action=show_groups&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id&shop_items_catalog_modification_id=$shop_items_catalog_modification_id");
}
$new_path_array[] = array("name" => $GLOBALS['MSG_shops']['show_item_discount_title'].' "'.$res['shop_items_catalog_name'].'"', "link" => "/admin/shop/shop.php?action=show_item_discount&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id&shop_items_catalog_item_id=$shop_items_catalog_item_id");
$form_params['path_array'] = $new_path_array;

$admin_forms_fields = new admin_forms_fields($form_params);

$DataBase = & singleton('DataBase');

// Редактировние производителя
if ($edit_item_discount)
{
	$type = 1;

	$result = $shop->GetItemDiscount($edit_item_discount);

	$shop_discount_id = to_int($result['shop_discount_id']);
}
// Добавление производителя
else
{
	$shop_discount_id = 0;
}

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


// Заполняем поле "Список скидок"
$arr = array();

$arr[0] = ' ... ';

$res = $shop->GetAllDiscounts($shop_shops_id);

while ($row = mysql_fetch_assoc($res))
{
	$arr[$row['shop_discount_id']] = $row['shop_discount_name'];
}

// Список скидок
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'shop_discount_id';
$params['caption'] = $GLOBALS['MSG_shops']['item_discount_name'];
$params['type'] = 2; // Выпадающий список.
$params['items'] = $arr;
$params['value'] = $shop_discount_id;
$params['attributes']['class'] = 'large';

$admin_forms_fields->AddField($params);

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

// передеам скрытое поле с идентификатором адреса если он есть
if ($edit_item_discount)
{
	$params = array();
	$params['tab_id'] = $tab_id;
	$params['name'] = 'edit_item_discount';
	$params['caption'] = '';
	$params['type'] = 4; // hidden.
	$params['value'] = $edit_item_discount;
	$admin_forms_fields->AddField($params);
}
// Если пришли из формы модификаций
if (isset($shop_items_catalog_modification_id))
{
	$param = array();
	$param['tab_id'] = $tab_id;
	$param['name'] = 'shop_items_catalog_modification_id';
	$param['caption'] = '';
	$param['type'] = 4; // hidden.
	$param['value'] = $shop_items_catalog_modification_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_item_discount';
$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);

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

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

// Кнопка "Применить".
$params = array();
$params['name'] = 'add_item_discount';
$params['caption'] = $GLOBALS['MSG_shops']['add_city_area_form_button'];
$params['image'] = '/admin/images/add.gif';
$admin_forms_fields->AddButton($params);

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

?>