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

$DateClass = new DateClass();

// Обновление свойства информационных элементов
if (isset($_POST["information_property_items_id"]))
{
	$type = 1;
	$information_propertys_items_id = to_int($_POST["information_property_items_id"]);
}
else
{
	$type = 0;
	$information_propertys_items_id = 0;
}

// На случай, если нет списков
if (isset($_POST['information_propertys_items_lists_id']))
{
	$information_propertys_items_lists_id = to_int($_POST['information_propertys_items_lists_id']);
}
else
{
	$information_propertys_items_lists_id = '';
}


if (trim($_POST['information_propertys_items_xml_name']) == '' || !ereg("^[а-яА-Яa-zA-Z]", trim($_POST['information_propertys_items_xml_name'])))
{

	$error_information_propertys_items = 1;

	if (trim($_POST['information_propertys_items_xml_name']) == '')
	{
		show_error_message($GLOBALS['MSG_information_systems']['error_information_name_tag_XML']);
	}
	else
	{
		show_error_message($GLOBALS['MSG_information_systems']['error_information_name_tag_XML_liter']);
	}

	$information_system_id = to_int($_POST['information_system_id']);
	$information_propertys_items_name = to_str($_POST["information_propertys_name"]);
	$information_propertys_items_type = to_str($_POST["information_propertys_type"]);
	$information_propertys_items_order = to_str($_POST["information_propertys_order"]);
	$information_propertys_items_define_value = to_str($_POST["information_propertys_define_value"]);
	$information_propertys_items_xml_name = to_str($_POST["information_propertys_xml_name"]);
	$property_information_systems_id = to_int($_POST['information_propertys_information_system_id']);

	if (isset($_POST['information_propertys_items_lists_id']))
	{
		$information_propertys_items_lists_id = to_int($_POST['information_propertys_items_lists_id']);
	}
	else
	{
		$information_propertys_items_lists_id = 0;
	}
}
else
{
	switch (to_int($_POST['information_propertys_items_type']))
	{
		case 0: // Число
		{
			$information_propertys_items_default_value = to_int($_POST['information_propertys_items_default_value']);
			break;
		}

		case 7: // Флажок
		{
			if (isset($_POST['information_propertys_items_define_checked_value']))
			{
				$information_propertys_items_default_value = 1;
			}
			else
			{
				$information_propertys_items_default_value = 0;
			}
			break;
		}
		
		case 8: // Дата
		{
			$information_propertys_items_default_value = to_str($_POST['information_propertys_items_date_default_value']);
			break;
		}
		
		case 9: // Дата-время
		{
			$information_propertys_items_default_value = to_str($_POST['information_propertys_items_datetime_default_value']);
			break;
		}

		default:
			{
				$information_propertys_items_default_value = to_str($_POST['information_propertys_items_default_value']);
			}
	}

	$param['information_propertys_id'] = $information_propertys_items_id;
	$param['information_system_id'] = to_int($_POST['information_system_id']);
	$param['information_propertys_name'] = to_str($_POST['information_propertys_items_name']);
	$param['information_propertys_type'] = to_int($_POST['information_propertys_items_type']);
	$param['information_propertys_order'] = to_int($_POST['information_propertys_items_order']);
	$param['information_propertys_define_value'] = $information_propertys_items_default_value;
	$param['information_propertys_xml_name'] = to_str($_POST['information_propertys_items_xml_name']);
	$param['information_propertys_lists_id'] = $information_propertys_items_lists_id;
	$param['information_propertys_information_systems_id'] = to_int($_POST['information_propertys_items_information_system_id']);
	
	$param['information_propertys_items_dir_id'] = to_int($_POST['information_propertys_items_dir_id']);
	
	
	$param['information_propertys_default_big_width'] = to_int($_POST['information_propertys_default_big_width']);
	$param['information_propertys_default_small_width'] = to_int($_POST['information_propertys_default_small_width']);
	$param['information_propertys_default_big_height'] = to_int($_POST['information_propertys_default_big_height']);
	$param['information_propertys_default_small_height'] = to_int($_POST['information_propertys_default_small_height']);
	$param['users_id'] = false;

	if ($insert_property_items_id = $information_system->InsertInformationPropertys($param))
	{
		$admin_forms = new admin_forms();
		$window_id = $admin_forms->GetWindowId();
		?><script type="text/javascript">
		$.appendInput('<?php echo $window_id?>', 'EditAddPropertyItems', 'information_property_items_id', '<?php echo $insert_property_items_id?>');
		</script><?php

		if ($type)
		{
			show_message($GLOBALS['MSG_information_systems']['edit_information_propertys']);
		}
		else
		{
			show_message($GLOBALS['MSG_information_systems']['add_information_propertys']);
		}
	}
	else // Ошибка добавления/редактирования дополнительного свойства информационных элементов
	{
		if ($type)
		{
			show_message($GLOBALS['MSG_information_systems']['edit_information_propertys_error']);
		}
		else
		{
			show_message($GLOBALS['MSG_information_systems']['add_information_propertys_error']);
		}
	}
}
?>