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

$shop = & singleton('shop');

if (isset($_REQUEST['edit_cond_of_delivery']))
{
	$param['id'] = to_int($_REQUEST['edit_cond_of_delivery']);
}

$param['name'] = to_str($_REQUEST['cond_of_delivery_name']);
$param['type_of_delivery'] = to_int($_REQUEST['type_of_delivery_id']);

// Обрабатываем данные об идентификаторах стран, местоположений и т.д

/*// Получаем идентификатор страны
$param['country'] = to_int($_REQUEST['country_id']);

$temp = $_REQUEST['location_id'];

$array_of_delimited_strings = explode('_', $temp);

// Получаем идентификатор местоположения
$param['location'] = to_int($array_of_delimited_strings[1]);


$temp = $_REQUEST['city_id'];

$array_of_delimited_strings = explode('_', $temp);

// Получаем идентификатор города
$param['city'] = to_int($array_of_delimited_strings[1]);


$temp = $_REQUEST['city_area_id'];

$array_of_delimited_strings = explode('_', $temp);

// Получаем идентификатор района города
$param['city_area'] = to_int($array_of_delimited_strings[1]);*/




$param['country'] = to_int($_REQUEST['country_id']);
$param['location'] = to_int($_REQUEST['location_id']);
$param['city'] = to_int($_REQUEST['city_id']);
$param['city_area'] = to_int($_REQUEST['city_area_id']);


$param['weight_from'] = to_float($_REQUEST['cond_of_delivery_weight_from']);
$param['weight_to'] = to_float($_REQUEST['cond_of_delivery_weight_to']);
$param['price_from'] = to_float($_REQUEST['cond_of_delivery_price_from']);
$param['price_to'] = to_float($_REQUEST['cond_of_delivery_price_to']);
$param['description'] = to_str($_REQUEST['cond_of_delivery_description']);
$param['price'] = to_float($_REQUEST['cond_of_delivery_price']);
$param['currency'] = to_int($_REQUEST['currency_id']);
$param['shop_tax_id'] = to_int($_REQUEST['shop_tax_id']);

if ($condofdelivery = $shop->InsertCondOfDelivery($param))
{
	$admin_forms = new admin_forms();
	$window_id = $admin_forms->GetWindowId();
	?><script type="text/javascript">
	$.appendInput('<?php echo $window_id?>', 'EditAddCondOfDelivery', 'edit_cond_of_delivery', '<?php echo $condofdelivery?>');
	</script><?php

	if (isset($_REQUEST['edit_cond_of_delivery']))
	{
		show_message($GLOBALS['MSG_shops']['success_edit_cond_of_delivery']);
	}
	else 
	{
		show_message($GLOBALS['MSG_shops']['success_add_cond_of_delivery']);
	}
}
else
{
	if (isset($_REQUEST['edit_cond_of_delivery']))
	{
		show_error_message($GLOBALS['MSG_shops']['error_edit_cond_of_delivery']);
	}
	else 
	{
		show_error_message($GLOBALS['MSG_shops']['error_add_cond_of_delivery']);
	}
}
?>