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

$warehouse = & singleton('warehouse');

// Проверяем существует ли идентификатор
if (isset($_REQUEST['shop_warehouse_id']))
{
	$param['shop_warehouse_id'] = to_int($_REQUEST['shop_warehouse_id']);
}

// Устанавливаем параметры
$param['shop_shops_id'] = to_str($_REQUEST['shop_shops_id']);
$param['shop_warehouse_name'] = to_str($_REQUEST['shop_warehouse_name']);

if(isset($_REQUEST['shop_warehouse_activity']))
{
	$param['shop_warehouse_activity'] = 1;
}
else
{
	$param['shop_warehouse_activity'] = 0;
}

if(isset($_REQUEST['shop_warehouse_default']))
{
	$param['shop_warehouse_default'] = 1;
}
else
{
	$param['shop_warehouse_default'] = 0;
}

$param['shop_country_id'] = to_str($_REQUEST['country_id']);
$param['shop_location_id'] = to_str($_REQUEST['location_id']);
$param['shop_city_id'] = to_str($_REQUEST['city_id']);
$param['shop_city_area_id'] = to_str($_REQUEST['city_area_id']);
$param['shop_warehouse_address'] = to_str($_REQUEST['shop_warehouse_address']);
$param['shop_warehouse_order'] = to_str($_REQUEST['shop_warehouse_order']);

if ($warehouse_id = $warehouse->InsertWarehouse($param))
{
	$admin_forms = new admin_forms();
	$window_id = $admin_forms->GetWindowId();
	?><script type="text/javascript">
	$.appendInput('<?php echo $window_id?>', 'EditAddWarehouse', 'shop_warehouse_id', '<?php echo $warehouse_id?>');
	</script><?php

	if (to_int($_REQUEST['shop_warehouse_id'])) 
	{
		show_message($GLOBALS['MSG_shops']['warehouse_edit_success']);
	}
	else 
	{
		show_message($GLOBALS['MSG_shops']['warehouse_add_success']);
	}
}
else
{
	if (to_int($_REQUEST['shop_warehouse_id'])) 
	{
		show_error_message($GLOBALS['MSG_shops']['warehouse_edit_error']);
	}
	else 
	{
		show_error_message($GLOBALS['MSG_shops']['warehouse_add_error']);
	}
}
?>