<?php

/* DCMS Special
 * Дата последнего редактирования 16.12.2015
 * Модифицировал densnet
 */

foreach (array('start', 'compress', 'sess', 'settings', 'db_connect', 'ipua', 'fnc', 'user') as $inc) {
    require_once "../../sys/inc/{$inc}.php";
}

$set['title'] = lang('Журнал форума');

require_once H . 'sys/inc/thead.php';

aut() . only_reg();

if (!isset($_GET['all']) && !isset($_GET['new'])) {
    header('Location: journal.php?new');
    exit;
}

define('DIR_FORUM', '/modules/forum/');

$isset = (isset($_GET['type'])) ? '?type=' . $db->safesql($_GET['type']) . '&' : '?';
$type = (isset($_GET['all'])) ? 'all' : 'new';
$read = (isset($_GET['all'])) ? NULL : 'AND `read` = "0"';

$k = $db->super_query("SELECT COUNT(*) as count FROM `f_journal` WHERE `read` = '0' AND `id_user` = '$user[id]'");
$new_j = (($k['count'] == 0) ? null : "+ $k[count]");
$k = $db->super_query("SELECT COUNT(*) as count FROM `notification` WHERE `id_kont` = '$user[id]' AND `read` = '0'");
$new_n = (($k['count'] == 0) ? null : "+ $k[count]");
$k = $db->super_query("SELECT COUNT(*) as count FROM `notifications` WHERE `id_kont` = '$user[id]' AND `read` = '0'");
$new_ns = (($k['count'] == 0) ? null : "+ $k[count]");
$k = $db->super_query("SELECT COUNT(*) as count FROM `events` WHERE `id_kont` = '$user[id]' AND `read` = '0'");
$new_ev = (($k['count'] == 0) ? null : "+ $k[count]");

#Навигация
echo "<div class='list-group-item-null list-group-item-grey'><small>";
echo "<a href='/' class='hint--right' data-hint='" . lang('На главную') . "'><i class='fa fa-home fa-lg'></i></a> <i class='fa fa-angle-right fa-fw'></i> ";
echo "<a href='" . DIR_FORUM . "'>" . lang('Форум') . "</a> <i class='fa fa-angle-right fa-fw'></i> ";
echo lang('Уведомления');
echo "</small></div><br />";

echo "<div class='list-group-item-null list-group-item-grey'>";
echo "<ul class='nav nav-tabs' style='margin-bottom: -11px;'>";
echo "<li class='nav-item'><a class='nav-link' href='/user/notification/'>" . lang('Ответы') . " $new_n</a></li>";
echo "<li class='nav-item'><a class='nav-link' href='/user/notification/index.php?act=feed'>" . lang('Новости') . " $new_ns</a></li>";
echo "<li class='nav-item'><a class='nav-link active'>" . lang('Форум') . " $new_j</a></li>";
echo "<li class='nav-item'><a class='nav-link' href='/user/notification/index.php?act=events'>" . lang('События') . " $new_ev</a></li>";
echo "</ul>";
echo '</div>';

echo '<div class="list-group-item-null">';
if (isset($_GET['all'])) {
    echo "<ul class='nav nav-pills'>";
    echo "<li class='nav-item'><a class='nav-link active' href='journal.php{$isset}all'>" . lang('Все') . "</a></li>";
    echo "<li class='nav-item'><a class='nav-link' href='journal.php{$isset}new'>" . lang('Новые') . "</a></li>";
    echo "</ul>";
}
if (isset($_GET['new'])) {
    echo "<ul class='nav nav-pills'>";
    echo "<li class='nav-item'><a class='nav-link' href='journal.php{$isset}all'>" . lang('Все') . "</a></li>";
    echo "<li class='nav-item'><a class='nav-link active' href='journal.php{$isset}new'>" . lang('Новые') . "</a></li>";
    echo "</ul>";
}
echo '</div>';

$type_j = (isset($_GET['type'])) ? '`type` = "' . $db->safesql($_GET['type']) . '" AND' : NULL;
$k_post = $db->super_query("SELECT COUNT(*) as count FROM `f_journal` WHERE $type_j `id_user` = '$user[id]' $read");
$k_post = $k_post['count'];
$k_page = k_page($k_post, $set['p_str']);
$page = page($k_page);
$start = $set['p_str'] * $page - $set['p_str'];
if ($k_post == 0) {
    $doc->NoResult();
} else {
    $js = $db->query('SELECT * FROM `f_journal` WHERE ' . $type_j . ' `id_user` = ' . $user['id'] . ' ' . $read . ' ORDER BY `id` DESC LIMIT ' . $start . ', ' . $set['p_str']);
    while ($j = mysqli_fetch_object($js)) {
        echo "<div class='list-group-item-null list-group-item-grey dop'>";
        echo toOutput($j->text) . "<br />";
        echo date::times($j->time);
        echo "</div>";
    }
    if ($k_page > 1) {
        str('journal.php' . $isset . $type, $k_page, $page);
    }
    if (isset($_GET['new'])) {
        $db->query('UPDATE `f_journal` SET `read` = "1" WHERE `id_user` = ' . $user['id']);
    }
}

require_once H . 'sys/inc/tfoot.php';
