<?php
require_once('classes/body.class.php');
require_once('classes/db.class.php');
require_once('classes/system.class.php');
$title= new Body;
$title->SetTitle(homeurl.' - Журнал оповещения!');
///Подключаем шапку
$title->GetHeader();

if ($b == false) {
header('location: /');
die();
}
echo'<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-widgets"></i><a href="/"style="text-decoration:none; color:white;"> Главная</a> :: Журнал оповещения </div></div></div>';

$sort = isset($_GET['sort']) ? check($_GET['sort']) : false;
$sorts = (empty($sort) ? '1' : $sort);
echo '<div class="list-group-item media"><a href="?clean='.$sorts.'"><i class="zmdi zmdi-swap-calls"></i> Очистить ленту</a></div>';
$arr = [1=>'Все', 2=>'Форум', 3=>'Комментарии', 4=>'Рейтинг', 5=>'Прочее', 6=>'Биллинг'];
echo '<div class="list-group-item media"><i class="zmdi zmdi-format-list-bulleted"></i> ';
foreach($arr as $v => $value) {
$t = ($v == 1 || $v == 2 || $v == 3 || $v == 4) ? ' :: ' : '::';
$new = DB::$dbs->querySingle("SELECT COUNT(id) FROM jurnal WHERE user_id = ? AND act = ? AND type = ?", [$b['id'],$v,1]);
echo ($sort != $v ? '<a href="?sort='.$v.'">'.$value.'</a> '.(!empty($new) ? '<font color="red"><b>+'.$new.'</b></font>':'').' '.$t.' ':' <b>'.$value.'</b> '.(!empty($new) ? '<font color="red"><b>+'.$new.'</b></font>':'').'  '.$t.' ');
}
echo '</div>';
$ord = (empty($sort) ? '1' : $sort);
if (isset($_GET['clean'])) {
$clean = isset($_GET['clean']) ? abs((int)$_GET['clean']) : false;
if ($clean != 1) {
DB::$dbs->query("DELETE FROM jurnal WHERE act = ? AND user_id = ?", [$clean,$b['id']]);
} else {
DB::$dbs->query("DELETE FROM jurnal WHERE user_id = ?", [$b['id']]);
}
header('Location: ?sort='.$clean);
die();
}
if ($ord != 1) {
$k_mess = DB::$dbs->querySingle("SELECT count(id) FROM jurnal WHERE user_id = ? AND act = ?",[$b['id'],$ord]);
} else {
$k_mess = DB::$dbs->querySingle("SELECT count(id) FROM jurnal WHERE user_id = ?",[$b['id']]);
}
if ($k_mess == 0) {
err('Ничего нет!');
}
$num = 10;
$k_page = k_page($k_mess, $num);
$page = page($k_page);
$start = $num*$page-$num;
if ($ord != 1) {
$sql = DB::$dbs->query("SELECT * FROM jurnal WHERE user_id = ? AND act = ? ORDER BY time DESC LIMIT $start,$num", [$b['id'],$ord]);
} else {
$sql = DB::$dbs->query("SELECT * FROM jurnal WHERE user_id = ? ORDER BY time DESC LIMIT $start,$num", [$b['id']]);
}
while($a = $sql->fetch()){
if ($a['type']==1) {
DB::$dbs->query("UPDATE jurnal SET type = ? WHERE `id` = ? LIMIT 1", [0,$a['id']]);
}
echo '<div class="list-group-item media"> ' . ($a['type']==1 ? ' <font color="red"><b>[new]</b></font>':NULL).' '.text($a['text']).' ('.vr($a['time']).')</div>';
}
if ($k_page>1) {
str('?sort='.$ord.'&', $k_page,$page);
}

///Подключаем меню
$title->GetMenu();

///Подключаем футер
$title->GetFooter();
?>
