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

$form_params = array();
$form_params['title'] = $GLOBALS['MSG_shops']['change_prices_for_shop_group'];
$form_params['form_attribs']['method'] = 'post';
$form_params['form_attribs']['action'] = '/admin/shop/shop.php';
$form_params['form_attribs']['ENCTYPE'] = 'multipart/form-data';

$admin_forms_fields = new admin_forms_fields();

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

$shop = & singleton('shop');

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

$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']['change_prices_for_shop_group'],
"link" => $admin_forms_fields->GetHtmlCallDoLoadAjax('/admin/shop/shop.php', "&action=change_prices&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 0, 'load_data'),
"onclick" => $admin_forms_fields->GetOnClickCallDoLoadAjax('/admin/shop/shop.php', "&action=change_prices&shop_shops_id=$shop_shops_id&shop_groups_parent_id=$shop_groups_parent_id", 0, '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']);

// Выбор типа изменения (умножить или прибавить)
$arr = array(1=>$GLOBALS['MSG_shops']['multiply_price_to_digit'], 0=>$GLOBALS['MSG_shops']['add_price_to_digit']);
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'type_of_change';
$params['caption'] = $GLOBALS['MSG_shops']['select_price_form'];
$params['type'] = 13; // радиокнопки
$params['value'] = 1;
$params['options']['count'] = 2;
$params['options']['labels'] = $arr;
$params['options']['input_text'] = array(1 => 0, 0 => 1);
$params['options']['index'] = array(1 => 0, 0 => 1);
$params['options']['values'] = array(1 => '1.00', 0 => '0.00');
$params['options']['ext_name'] = array(1 => 0, 0 => 1);
$params['options']['onclick'] = 'SetActiveForTextBox(%ext_name%)';
$params['attributes']['style'] = 'width: 75px;';
$params['div_attributes']['style'] = 'float: left;';
$admin_forms_fields->AddField($params);

// Получаем данные о магазине
$shop_row = $shop->GetShop($shop_shops_id, array('cache_off' => true));

$shop_currency_id = $shop_row['shop_currency_id'];

// Получаем информацию о валюте
$currency_row = $shop->GetCurrency($shop_currency_id, array('cache_off' => true));

// Имя валюты магазина
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'shop_currency_name';
$params['caption'] = '&nbsp;';
$params['type'] = 8; // Текст
$params['value'] = $currency_row['shop_currency_name'];
$param['attributes']['style'] = 'width: 100px;';
$param['div_attributes']['style'] = 'float: left; margin-top: 5px';
$admin_forms_fields->AddField($params);

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

// Получаем список всех скидок
$discount_res = $shop->GetAllDiscounts($shop_shops_id);

$arr = array();
$arr[0] = ' ... ';

while ($discount_row = mysql_fetch_assoc($discount_res)) 
{
	$arr[$discount_row['shop_discount_id']] = $discount_row['shop_discount_name'];
}

// Поле "Установить скидку"
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'shop_discount_id';
$params['caption'] = $GLOBALS['MSG_shops']['select_discount_type'];
$params['type'] = 2; // Выпадающий список
$params['value'] = 0;
$params['items'] = $arr;
$params['attributes']['style'] = 'width: 320px; float: left;';
$params['apply_filter'] = true;
$admin_forms_fields->AddField($params);

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

// Флаг "Удалить скидку"
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'flag_delete_discount';
$params['caption'] = $GLOBALS['MSG_shops']['flag_delete_discount'];
$params['type'] = 1; // Флажок
$params['value'] = 0;
$admin_forms_fields->AddField($params);

// Заполнение формы "Родительская группа для загрузки товаров"
$arr = array($GLOBALS['MSG_shops']['select_parent_group_name']);

$shop_current_group_id = 0;

$aCache = GetShopGroups($shop_shops_id);
$arr = GetShopGroupsCreateOption($arr, $aCache, $shop_current_group_id);
unset($aCache);

// Родительская группа для загрузки товаров
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'shop_groups_parent_id';
$params['caption'] = $GLOBALS['MSG_shops']['select_parent_group'];
$params['type'] = 2; // Выпадающий список
$params['items'] = $arr;
$params['value'] = to_int($_REQUEST['shop_groups_parent_id']);
$params['attributes']['style'] = 'width: 320px; float: left;';
$params['apply_filter'] = true;
$admin_forms_fields->AddField($params);

$arr = array();
$shop->CacheGoupsIdTree[$shop_shops_id] = array();

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

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

// Получаем список производителей для данного магазина
$producers_res = $shop->GetAllProducers(array('shop_id' => $shop_shops_id));

if($producers_res)
{
	while($producers_row = mysql_fetch_assoc($producers_res))
	{
		$array_of_producers[$producers_row['shop_producers_list_id']] = $producers_row['shop_producers_list_name'];
	}
}

// Идентификатор производителя
$params = array();
$params['tab_id'] = $tab_id;
$params['name'] = 'shop_producers_list_id';
$params['caption'] = $GLOBALS['MSG_shops']['show_producer_id_filter_change_price_for'];
$params['type'] = 2; // Выпадающий список
$params['items'] = $array_of_producers;
$params['value'] = 0;
$params['attributes']['style'] = 'width: 320px; float: left;';
$params['apply_filter'] = true;
$admin_forms_fields->AddField($params);

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

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

$params = array();
$params['name'] = 'do_accept_new_price';
$params['caption'] = $GLOBALS['MSG_shops']['comment_form_add'];
$params['attributes']['onclick'] = "return SendForm('{$admin_forms_fields->GetWindowId()}', '/admin/shop/shop.php', '&action=do_accept_new_price', this, 0)";
$admin_forms_fields->AddButton($params);

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

<script language="JavaScript">
function SetActiveForTextBox(param)
{
	if(param == 0)
	{
		// Заблокировать второй TextBox
		document.getElementById("text_1").disabled = true;
		document.getElementById("text_0").disabled = false;
	}
	else
	{
		// Заблокировать первый TextBox
		document.getElementById("text_0").disabled = true;
		document.getElementById("text_1").disabled = false;
	}
}
SetActiveForTextBox(1);
</script>