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

if (isset($_REQUEST['constants_id']))
{
	$type = 1;
	$constants_id = to_int($_REQUEST['constants_id']);
}
else
{
	$constants_id = 0;
	$type = 0;
}

$constants_name = trim(to_str($_REQUEST['constants_name']));
$constants_value = trim(to_str($_REQUEST['constants_value']));
$constants_description = to_str($_REQUEST['constants_description']);
$constants_activity = to_str($_REQUEST['constants_activity']);

if ($constants_activity == 'on')
{
	$constants_activity = 1;
}
else
{
	$constants_activity = 0;
}

if ($insert_constant_id = $constant->AddEditConstants($type, $constants_id, $constants_name, $constants_value, $constants_description, $constants_activity))
{
	$admin_forms = new admin_forms();
	$window_id = $admin_forms->GetWindowId();
	?><script type="text/javascript">
	$.appendInput('<?php echo $window_id?>', 'EditAddConstant', 'constants_id', '<?php echo $insert_constant_id?>');
	</script><?php

	if ($type)
	{
		show_message($GLOBALS['MSG_constants']['constants_edit_success_message']);
	}
	else
	{
		show_message($GLOBALS['MSG_constants']['constants_add_success_message']);
	}
}
else
{
	if ($type)
	{
		show_error_message($GLOBALS['MSG_constants']['constants_edit_error_message']);
	}
	else
	{
		show_error_message($GLOBALS['MSG_constants']['constants_add_error_message']);
	}
}

?>