<?php

define('_IN_JOHNCMS', 1);
require('../system/bootstrap.php');
/** @var Psr\Container\ContainerInterface $container */
$container = App::getContainer();

/** @var PDO $db */
$db = $container->get(PDO::class);

/** @var Johncms\Tools $tools */
$tools = $container->get('tools');

/** @var Johncms\Environment $env */
            $env = App::getContainer()->get('env');

/** @var Johncms\User $systemUser */
$systemUser = $container->get(Johncms\User::class);

/** @var Johncms\Config $config */
$config = $container->get(Johncms\Config::class);

$headmod = 'notif';
$textl = 'Forum Notifikasi';
require ('../system/head.php');



echo '<div class="mainblok"><div class="phdr"><b>Forum Notification</b></div>';

if($systemUser->notif_forum) {	
  echo '<div class="topmenu">New Notification : ' . $systemUser->notif_forum . '</div></div>';
  $db->exec("UPDATE `users` SET `notif_forum`='0' WHERE `id` = '$systemUser->id'");
}

$total = $db->query("SELECT COUNT(*) FROM `forum` WHERE `id_user`='$systemUser->id'" .
    ($systemUser->rights >= 7 ? "" : " AND `close` != '1'"))->fetchColumn();
if ($total) {
    $req = $db->query("SELECT `forum`.*, `users`.`sex`, `users`.`rights`, `users`.`lastdate`, `users`.`status`, `users`.`datereg`
     	FROM `forum` LEFT JOIN `users` ON `forum`.`user_id` = `users`.`id`
      	WHERE `forum`.`type` = 'm' AND `forum`.`id_user`='$systemUser->id'" . ($systemUser->rights >=
        7 ? "" : " AND `forum`.`close` != '1'") . " ORDER BY `forum`.`id` DESC LIMIT $start, $kmess");
    while (($res = $req->fetch()) !== false) {
    	if ($res['close'])
        	echo '<div class="rmenu">';
        else
    		echo $i % 2 ? '<div class="mainblok"><div class="phdr">Notif Forum</div><div class="list2">' : '<div class="mainblok"><div class="phdr">Notif Forum</div><div class="list1">';
        $theme = $db->query("SELECT `text` FROM `forum` WHERE `id` = '" . $res['refid'] . "' ORDER BY `id` ASC LIMIT 1")->fetch();
       ###
        echo '<b>From: <a href="profile.php?user=' . $res['user_id'] . '">' . $res['from'] . '</a></b><br/>';
        echo '<span name="title"><b>Topic: <a href="../forum/index.php?id=' . $res['refid'] . '">' . $theme['text'] . '</a></b></title>';
        echo '<script type="text/javascript" src="/thumbnail/th_forum3.js"></script><script type="text/javascript" src="/thumbnail/th_forum2.js"></script><script type="text/javascript" src="/thumbnail/th_forum1.js"></script><script type="text/javascript" src="/thumbnail/th_forum4.js"></script>';
        echo '<br/><b>Time:</b><small>' . date("d.m.Y / H:i", $res['time'] + $config['timeshift'] * 3600) . '</small>';
         echo '<br/><font color="red">Your Post Answered:</font><br/>';
        //echo '<span class="button-tag">';
        $text = $tools->checkout($res['text'], 1, 1);
        if(mb_strlen($res['text']) > 50)
           $text .= ' ...';
        if ($res['kedit'])
            $text .= '<br /><small>Edited <b>' . $res['edit'] . '</b> (' . date("d.m /H:i", $res['tedit'] + $config['timeshift'] * 3600) . ') <b>[' . $res['kedit'] . ']</b></small>';
    	      echo $text;
             //echo '</span>';
            echo '<br/><span class="button-tag"><a href="../forum/index.php?act=post&amp;id=' . $res['id'] . '">Read More</a></span>';
        echo '</div></div>';
        ++$i;
    }
} else
	echo '<div class="menu"><p>Not found!</p></div>';
echo '<div class="phdr">Total: ' . $total . '</div>';


if ($total > $kmess) {
	echo '<p>' . $tools->displayPagination('notif.php?', $start, $total, $kmess) . '</p>' .
	'<p><form action="notif.php?" method="post"><input type="text" name="page" size="2"/><input type="submit" value="To page &gt;&gt;"/></form></p>';
}

echo '<p><a href="index.php?act=office">Back</a></p>';

require_once ('../system/end.php');
?>