<?php
require_once '../core/system.php';

if(isset($_GET['id']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `support_tickets` WHERE `id` = '".intval($_GET['id'])."'"),0) == true) {
$ticket = mysql_fetch_assoc(mysql_query("SELECT * FROM `support_tickets` WHERE `id` = $_GET[id] LIMIT 1"));
mysql_query("UPDATE `support_tickets` SET `new` = '0' WHERE `id` = $_GET[id] LIMIT 1");
$_SESSION['ticket_id'] = $ticket['id'];
}else{
$_SESSION['err'] = "Запрос не найден!";
header('Location: /support');
exit();
}
if ($user[prava] <=5 ) {
if ($ticket[user_id] != $user[id]) {
header('Location: /support');
exit();
}
}
$header = 'Запрос';
include_once '../core/head.php';
// Будет добавлено позже
/*if ($ticket[user_id] == $user[id]) {
echo '<div class="player menuList">
<li><a href="close_ticket?id='.$ticket[id].'"><img src="/images/icon/arrow.png" />Закрыть запрос</a></li>
</div>';
}*/
include 'ticket_status.php';
echo '<div class="mini-line"></div>
<div class="block_zero center"><form action="send_ticket_message" method="post"><div>Сообщение:<br/><textarea name="message" class = "text large" rows="4" cols="55"></textarea><br/><div class="center"><span class="btn"><span class="end"><input class="label" type="submit" value="Отправить">Отправить</span></span></div></div></form></div>';
echo '<div class="mini-line"></div>
<div class="center"><b><font color="white">Статус:</font></b> '.$ticket_status.'</div> 
';
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `support_messages` WHERE `user_id` = '$user[id]'"),0);
$k_page = k_page($k_post,$set['p_str']);
$page = page($k_page);
$start = $set['p_str']*$page-$set['p_str'];
$q=mysql_query("SELECT * FROM `support_messages` WHERE `ticket_id` = '$ticket[id]' ORDER BY id DESC LIMIT $start, $set[p_str]");
echo "<div class='mini-line'></div>";

while($post = mysql_fetch_assoc($q)) {
$ank2 = mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id` = '$post[user_id]' LIMIT 1"));

echo '<div class="player">';
if ($post[admin_msg] == 1){
echo " Администратор ";
if ($user[prava] >= 5) {
echo '(<a href="/user/'.$ank2[id].'/"><span style="color:red;">'.$ank2[nick].'</span></a>)';
}
}elseif ($post[admin_msg] == 0) {
if ($ank2['storona'] == '0') {echo '<img src="/images/icon/0.png" height="11" alt="a"/> '; }
    if ($ank2['storona'] == '1') {echo '<img src="/images/icon/1.png" height="11" alt="d"/> '; }
echo online($ank2[id]);
echo ' <a href="/user/'.$ank2[id].'/">'.$ank2[nick].'</a>';
}
echo '<span class="float-right grey">'.vremja($post[post_time]).'</span>
<br><span style="orange">'.$post[message].'</span><br>
</div><div class="dot-line"></div>';
}
echo '<div class="mini-line"></div>
<div class="player menuList">
<li><a href="/support">Назад к запросам</a></li>
</div>';
include_once '../core/foot.php';
?>