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

if (isset($_POST["information_property_groups_id"]))
{
	$type = 1;
	$information_propertys_groups_id = to_int($_POST["information_property_groups_id"]);
}
else
{
	$type = 0;
	$information_propertys_groups_id = 0;
}

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

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

	if (trim($_POST['information_propertys_groups_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']);
	}
}
else
{
	switch (to_int($_POST['information_propertys_groups_type']))
	{
		case 0: // Число
		{
			$information_propertys_groups_default_value = to_int($_POST['information_propertys_groups_default_value']);
			break;
		}

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

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

	$param['information_propertys_groups_id'] = $information_propertys_groups_id;
	$param['information_system_id'] = to_int($_POST['information_system_id']);
	$param['information_propertys_groups_name'] = to_str($_POST['information_propertys_groups_name']);
	$param['information_propertys_groups_type'] = to_int($_POST['information_propertys_groups_type']);
	$param['information_propertys_groups_order'] = to_int($_POST['information_propertys_groups_order']);
	$param['information_propertys_groups_default_value'] = $information_propertys_groups_default_value;
	$param['information_propertys_groups_xml_name'] = to_str($_POST['information_propertys_groups_xml_name']);
	$param['information_propertys_groups_lists_id'] =  $information_propertys_groups_lists_id;
	$param['information_propertys_groups_information_system_id'] = to_int($_POST['information_propertys_groups_information_system_id']);
	$param['users_id'] = false;
	$param['information_propertys_groups_dir_id'] = $_POST['information_propertys_groups_dir_id'];
	
	$param['information_propertys_groups_big_width'] = $_POST['information_propertys_groups_big_width'];
	$param['information_propertys_groups_big_height'] = $_POST['information_propertys_groups_big_height'];
	$param['information_propertys_groups_small_width'] = $_POST['information_propertys_groups_small_width'];
	$param['information_propertys_groups_small_height'] = $_POST['information_propertys_groups_small_height'];
	
	if ($insert_property_groups_id = $information_system->InsertInformationPropertysGroups($param))
	{
		$admin_forms = new admin_forms();
		$window_id = $admin_forms->GetWindowId();
		?><script type="text/javascript">
		$.appendInput('<?php echo $window_id?>', 'EditAddPropertyGroups', 'information_property_groups_id', '<?php echo $insert_property_groups_id?>');
		</script><?php

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