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

$affiliate = & singleton('affiliate');

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

$param['affiliate_plans_name'] = to_str($_REQUEST['affiliate_plans_name']);

$param['affiliate_plans_description'] = to_str($_REQUEST['affiliate_plans_description']);

if (isset($_REQUEST['affiliate_plans_activity']))
{
	$param['affiliate_plans_activity'] = 1;
}
else
{
	$param['affiliate_plans_activity'] = 0;
}

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

$param['affiliate_plans_last_change_datetime'] = to_str($_REQUEST['affiliate_plans_last_change_datetime']);

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

$param['affiliate_plans_min_sum_of_items'] = to_float($_REQUEST['affiliate_plans_min_sum_of_items']);

if (isset($_REQUEST['affiliate_plans_delivery_on']))
{
	$param['affiliate_plans_delivery_on'] = 1;
}
else
{
	$param['affiliate_plans_delivery_on'] = 0;
}

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

	if (isset($_REQUEST['affiliate_plans_id']))
	{
		show_message($GLOBALS['MSG_shops']['edit_success_message']);
	}
	else
	{
		show_message($GLOBALS['MSG_shops']['add_success_message']);
	}
}
else
{
	if (isset($_REQUEST['affiliate_plans_id']))
	{
		show_error_message($GLOBALS['MSG_shops']['edit_error_message']);
	}
	else
	{
		show_error_message($GLOBALS['MSG_shops']['add_error_message']);
	}
}
?>