<?php
require '../core/system.php';
echo admin();
if (isset($_POST['message'])) {
$ticket_id = $_SESSION['ticket_id'];
$msg = check($_POST['message']);
if(mb_strlen($msg) < 1 or mb_strlen($msg) > 6000) $err =  'Длина сообщения должна быть в пределах 1 - 6000 символов';
if(!isset($err)) {
$time = time();
mysql_query("INSERT INTO `support_messages` (`message`, `post_time`, `user_id`, `ticket_id`, `admin_msg`) values('$msg', '$time', '$user[id]', '$ticket_id', '1')");
mysql_query("UPDATE `support_tickets` SET `new` = '1', `last_msg_time` = '$time', `status` = '1', `footer_new` = '1' WHERE `id` = '$ticket_id'");
header("Location: /view_ticket_admin?id=$ticket_id");
$_SESSION['message'] = 'Сообщение добавлено!';
exit();
}else{
header("Location: /view_ticket_admin?id=$ticket_id");
$_SESSION['err'] = $err;
exit();
} 
}else{
header("Location: /support");
exit();
}
?>