<?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="container-fluid page_header"><div class="container"><div class="row"><div class="col-xs-12 col-sm-8 col-md-9 col-lg-9"><h1>Журнал оповещения </h1><ol class="breadcrumb" xmlns:v="http://'.homeurl.'/#"><li typeof="v:Breadcrumb"><a href="/" rel="v:url" property="v:title">'.homeurl.'</a></li><li typeof="v:Breadcrumb"><a href="/office" rel="v:url" property="v:title">Кабинет</a></li><li class="active" typeof="v:Breadcrumb"><span property="v:title">Уведомления</span></li></ol></div></div></div></div>';
echo'<div class="container page_body"><div class="row"><div class="col-xs-12 page_content col-lg-9"><div class="navbar page_content_navbar collapse hidden-lg"><div class="container-fluid"><div class="navbar-collapse"></div></div></div><div class="text_box hidden-lg pr_block_small hidden"></div><div class="container-fluid cols_table">';

echo '<div class="catSides"><a href="/"><i class="md-format-list-bulleted"></i> Главная </a> -<a href="/office"> Кабинет</a> - Журнал оповещения</div>';
$sort = isset($_GET['sort']) ? check($_GET['sort']) : false;
$sorts = (empty($sort) ? '1' : $sort);
echo '<ul class="nav nav-pills nav-stacked"><li> <a href="?clean='.$sorts.'"><i class="md md-swap-calls"></i> Очистить ленту</a></ul>';
$arr = [1=>'Все', 2=>'Форум', 3=>'Комментарии', 4=>'Рейтинг', 5=>'Прочее', 6=>'Биллинг'];
echo '<div class="catSides"><i class="md-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="row text_box"><div class="pull-right text-muted top_right_box"></div> ' . ($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();
?>
