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

// Проверяем существует ли идентификатор
if (isset($_REQUEST['shop_comment_id']))
{
	$param['shop_comment_id'] = to_int($_REQUEST['shop_comment_id']);
}

// Устанавливаем параметры
$param['shop_items_catalog_item_id'] = to_int($_REQUEST['shop_items_catalog_item_id']);
$param['shop_comment_user_name'] = to_str($_REQUEST['shop_comment_user_name']);
$param['shop_comment_subject'] = to_str($_REQUEST['shop_comment_subject']);
$param['shop_comment_text'] = to_str($_REQUEST['shop_comment_text']);
$param['shop_comment_user_ip'] = to_str($_REQUEST['shop_comment_user_ip']);
$param['shop_comment_grade'] = to_int($_REQUEST['shop_comment_grade']);
$param['site_users_id'] = to_int($_REQUEST['site_users_id']);
$param['shop_comment_user_email'] = to_str($_REQUEST['shop_comment_user_email']);

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

$date = & singleton('DateClass');
$param['shop_comment_date_time'] = $date->datetime_format_sql(to_str($_REQUEST['shop_comment_date_time']));

if (to_int($param['shop_items_catalog_item_id']) == 0) 
{
	show_error_message($GLOBALS['MSG_shops']['add_comment_error_empty_item_field']);
}
elseif ($comment = $shop->InsertComment($param))
{
	$admin_forms = new admin_forms();
	$window_id = $admin_forms->GetWindowId();
	?><script type="text/javascript">
	$.appendInput('<?php echo $window_id?>', 'EditAddComment', 'shop_comment_id', '<?php echo $comment?>');
	</script><?php

	if (isset($_REQUEST['shop_comment_id'])) 
	{
		show_message($GLOBALS['MSG_shops']['comment_edit_success']);
	}
	else 
	{
		show_message($GLOBALS['MSG_shops']['comment_insert_success']);
	}
	
}
else
{
	if (isset($_REQUEST['shop_comment_id'])) 
	{
		show_error_message($GLOBALS['MSG_shops']['comment_edit_error']);
	}
	else 
	{
		show_error_message($GLOBALS['MSG_shops']['comment_insert_error']);
	}
}
?>