<?php
define('PROTECTOR', 1);

$headmod = 'otchet';//фикс. места

$textl='Отчеты';
include('files/path.php');
include($path.'files/db.php');
include($path.'files/auth.php');
include($path.'files/func.php');
include($path.'files/core.php');
include($path.'files/head.php');
include($path.'files/zag.php');

switch($_GET[mod]){

default:
$q = mysql_query("SELECT COUNT(*) FROM `otchet` WHERE `user_to` = '$log' AND `read` = '1';");
$new_mail = mysql_result($q, 0);
$w = mysql_query("SELECT COUNT(*) FROM `otchet` WHERE `user_to` = '$log'");
$old_mail = mysql_result($w, 0);


echo "<a href=\"otchet.php?mod=read\">Боевые отчеты</a>[$new_mail/$old_mail]<br/>";
echo "<a href=\"otchet.php?mod=delete_all\">Очистить отчеты</a><br/>";
echo"<a href=\"index.php?\">Назад</a>";
break;

case 'read':

$result = mysql_result(mysql_query("SELECT COUNT(*) FROM `otchet` WHERE user_to = '$log'"),0);
if ($result == 0)
{
echo "<b>Отчетов нет!</b><br/>";
}
else {
if ($_GET[page] == "" || $_GET[page] < 0 || $_GET[page] == "0")
{
$_GET[page] = 0;
}
$next = $_GET[page] + 1;
$back = $_GET[page] - 1;
$num = $_GET[page] * 5;
if($_GET[page] == "0")
{$i = 0;}
else{$i = ($_GET[page]*5)+1;}
$viso = mysql_num_rows(mysql_query("SELECT komentaras FROM komentarai"));
$puslap = floor($viso/5);
$message = mysql_query("SELECT * FROM otchet WHERE user_to = '$log'  ORDER BY id DESC LIMIT $num,5");
while($msg = mysql_fetch_array($message))
{
if ($msg[read] == 1)
{
mysql_query("UPDATE `otchet` SET `read` = 0 WHERE `user_to` = '$log'");
}
if ($msg[read] == 1)
{
$read = "Не прочитано";
} else
{
$read = "Прочитано";
}
$text = $msg[mail_msg];
$text = strip_tags($text);
$from = strip_tags($msg['user_from']);
echo "<div class='event'><b>Нападавший:</b><b><a href='search.php?nick=".$from."&amp;go=go'>$from</a> [$read] </b><br/><b>Дата нападения</b>: <small>$msg[time]</small><br/><b>Отчет</b>: $text
<br/><a href=\"otchet.php?iden=$msg[id]&amp;mod=delete_mess\">Удалить</a>
</div>";
}

if ($_GET[page] > 0)
{
echo "<a href=\"otchet.php?mod=read&amp;page=$back\">&lt; Назад</a>";
}


if($_GET[page] < $puslap || $_GET[page] == "" || $_GET[page] == 0)
{echo "<a href=\"otchet.php?mod=read&amp;page=$next\"> Далее &gt;</a><br/>";}

echo "</div>";
}
break;

case 'delete_all':

mysql_query("DELETE FROM `otchet` WHERE `user_to` = '$log'");
echo"Все отчеты успешно удалены!<br/>";
echo"<a href=\"otchet.php?mod=read\">В отчеты</a><br/>";
break;



case 'delete_mess':

if (isset($_GET[iden]))
{
mysql_query("DELETE FROM `otchet` WHERE `id` = '".intval($_GET['iden'])."' LIMIT 1");
mysql_query("OPTIMIZE TABLE `otchet`");

echo "Вы успешно удалили отчет!<br/>";
} else
{
echo "Ошибка!<br/>";
}
echo "<a href=\"otchet.php?mod=read\">Назад</a><br/>";
break;


}

include($path.'files/down.php');
?>
