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

$shop = & singleton('shop');

$date = new DateClass();

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

if (isset($_REQUEST['edit_list_of_properties']))
{
	$param['shop_properties_group_id'] = to_int($_REQUEST['edit_list_of_properties']);
}

/* Формируем массив с параметрами для дополнительного свойства товара */
$param['shop_properties_group_name'] = to_str($_REQUEST['list_of_properties_name']);
$param['shop_properties_group_xml_name'] = to_str($_REQUEST['list_of_properties_xml_name']);
$param['shop_properties_group_order'] = to_str($_REQUEST['list_of_properties_order']);
$param['shop_properties_group_type'] = to_int($_REQUEST['list_of_properties_type']);
$param['shop_properties_groups_dir_id'] = to_int($_REQUEST['shop_properties_groups_dir_id']);

// checkbox
if ($param['shop_properties_group_type'] == 7)
{
	$param['shop_properties_group_default_value'] = isset($_REQUEST['checkbox']) ? 1 : 0;
}
// тип данных - дата
elseif ($param['shop_properties_group_type'] == 5)
{
	$param['shop_properties_group_default_value'] = $date->date_format_sql($_REQUEST['date_without_time']);
}
// тип данных - датавремя
elseif ($param['shop_properties_group_type'] == 6)
{
	$param['shop_properties_group_default_value'] = $date->datetime_format_sql($_REQUEST['date_with_time']);
}
else 
{
	$param['shop_properties_group_default_value'] = to_str($_REQUEST['list_of_properties_default_value']);
}

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

$param['shop_mesures_id'] = to_int($_REQUEST['list_of_properties_mesures']);

$param['lists_id'] = to_int($_REQUEST['list_of_properties_lists_id']);

/* Осуществляем вставку дополнительного свойства */
if ($prop = $shop->InsertPropretyOfGroup($param))
{
		?>
	<script>
	var ElementInput = document.createElement("input");
	ElementInput.setAttribute("type", "hidden");
	ElementInput.setAttribute("name", "edit_list_of_properties");
	ElementInput.setAttribute("value", "<?php echo $prop?>");

	document.getElementById('EditAddGroupProperty').appendChild(ElementInput);
	</script>
	<?php 
	if (isset($_REQUEST['edit_list_of_properties']))
	{
		show_message($GLOBALS['MSG_shops']['success_edit_group_properties']);
	}
	else
	{
		show_message($GLOBALS['MSG_shops']['success_add_group_properties']);
	}
}
else
{
	if (isset($_REQUEST['edit_list_of_properties']))
	{
		show_error_message($GLOBALS['MSG_shops']['error_edit_group_properties']);
	}
	else
	{
		show_error_message($GLOBALS['MSG_shops']['error_add_group_properties']);
	}
}

?>