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

$DateClass = new DateClass();

// Редактирование комментария
if (isset($_POST['comment_id']))
{
	$comment_id = to_int($_POST['comment_id']);
}
else
{
	$comment_id = 0;
}

$comment_text = to_str($_POST['comment_text']);

if (class_exists("typograph"))
{
	// Модуль типографики подключен, проверяем, нужно ли применять типографику описания.
	if (isset($_POST['use_typograph_for_comment_text']))
	{
		// Создаем объект типографа и типографируем текст.
		$typograph = new typograph();
		$comment_text = $typograph->ProcessTypographic($comment_text, isset($_POST['trailing_punctuation_for_comment_text']));
	}
}

$param_comment = array();
$param_comment['comment_id'] = $comment_id;
$param_comment['comment_parent_id'] = to_int($_POST['comment_parent_id']);
$param_comment['information_items_id'] = to_int($_POST['information_item_id']);
$param_comment['comment_fio'] = to_str($_POST['comment_fio']);
$param_comment['comment_email'] = to_str($_POST['comment_email']);
$param_comment['comment_phone'] = to_str($_POST['comment_phone']);
$param_comment['comment_text'] = $comment_text;
$param_comment['comment_status'] = to_int($_POST['comment_status']);
$param_comment['comment_subject'] = trim(to_str($_POST['comment_subject']));
$param_comment['comment_ip'] = to_str($_POST['comment_ip']);
$param_comment['comment_date'] = $DateClass->datetime_format_sql($_POST['comment_date']);
$param_comment['comment_grade'] = to_int($_POST['comment_grade']);
$param_comment['site_users_id'] = to_int($_POST['site_users_id']);

if ($insert_item_comment_id = $inforrmation_system->AddCommentWithoutStriptags($param_comment))
{
	$admin_forms = new admin_forms();
	$window_id = $admin_forms->GetWindowId();
	?><script type="text/javascript">
	$.appendInput('<?php echo $window_id?>', 'EditAddItemComment', 'comment_id', '<?php echo $insert_item_comment_id?>');
	</script><?php

	if ($comment_id > 0)
	{
		show_message($GLOBALS['MSG_information_systems']['edit_comment_success']);
	}
	else
	{
		show_message($GLOBALS['MSG_information_systems']['add_comment_success']);
	}
}
else // Ошибка добавления/редактирования комментария
{
	if ($comment_id > 0)
	{
		show_error_message($GLOBALS['MSG_information_systems']['edit_comment_error']);
	}
	else
	{
		show_error_message($GLOBALS['MSG_information_systems']['add_comment_error']);
	}
}
?>