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

$affiliate = & singleton('affiliate');

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

$param['affiliate_plans_id'] = to_int($_REQUEST['affiliate_plans_id']);
$param['affiliate_values_inner_level'] = to_int($_REQUEST['affiliate_values_inner_level']);
$param['affiliate_values_type'] = to_int($_REQUEST['affiliate_values_type']);

if (!$param['affiliate_values_type'])
{
	$param['affiliate_values_value'] = 0;
	$param['affiliate_values_percent'] = to_float($_REQUEST['affiliate_values_percent']);
	
	if ($param['affiliate_values_percent'] > 2147483647)
	{
		$param['affiliate_values_percent'] = 2147483647;
		show_message($GLOBALS['MSG_shops']['error_affiliate_percent_over_range']);
	}
}
else 
{
	$param['affiliate_values_percent'] = 0;
	$param['affiliate_values_value'] = to_float($_REQUEST['affiliate_values_value']);
	
	if ($param['affiliate_values_value'] > 2147483647)
	{
		$param['affiliate_values_value'] = 2147483647;
		show_message($GLOBALS['MSG_shops']['error_affiliate_value_over_range']);		
	}
}

if ($affiliate_values_id = $affiliate->InsertAffiliateValues($param))
{
	$admin_forms = new admin_forms();
	$window_id = $admin_forms->GetWindowId();
	?><script type="text/javascript">
	$.appendInput('<?php echo $window_id?>', 'AddAffiliateValue', 'affiliate_values_id', '<?php echo $affiliate_values_id?>');
	</script><?php

	if (isset($_REQUEST['affiliate_values_id']))
	{
		show_message($GLOBALS['MSG_shops']['edit_success_affiliate_values']);
	}
	else
	{
		show_message($GLOBALS['MSG_shops']['add_success_affiliate_values']);
	}
}
else
{
	if (isset($_REQUEST['affiliate_values_id']))
	{
		show_error_message($GLOBALS['MSG_shops']['edit_error_affiliate_values']);
	}
	else
	{
		show_error_message($GLOBALS['MSG_shops']['add_error_affiliate_values']);
	}
}
?>