<?php
/*
 * JohnCMS NEXT Mobile Content Management System (http://johncms.com)
 *
 * For copyright and license information, please see the LICENSE.md
 * Installing the system or redistributions of files must retain the above copyright notice.
 *
 * @link        http://johncms.com JohnCMS Project
 * @copyright   Copyright (C) JohnCMS Community
 * @license     GPL-3
 */

defined('_IN_JOHNCMS') or die('Error: restricted access');

/** @var Psr\Container\ContainerInterface $container */
$container = App::getContainer();

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

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

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

$forum = $db->query("SELECT * FROM `forum` WHERE `type`='t' ORDER BY `time` DESC LIMIT 5");
	$i = 0;
?>
	<div class="menu"><b>GootyCMS</b> - Это мод движка JohnCMS, который будет переделан под адаптивную верстку. Так же будут добавлены некоторые модули. А пока, регистрируйтесь, общаейтесь, предлагайте свои идеи.</div><br />
<?
echo '<div class="phdr">Новое на форуме</div>';
while ($f = $forum->fetch()) {
	$user = $db->query("SELECT * FROM `forum` WHERE `type`='m' AND `refid`='".$f['id']."' ORDER BY `time` DESC LIMIT 1")->fetch();
	$us = $db->query("SELECT * FROM `users` WHERE `id`='".$user['user_id']."'")->fetch();
	$total = $db->query("SELECT COUNT(*) FROM `forum` WHERE `type`='m' AND `refid`='".$f['id']."'" . ($systemUser->rights >= 7 ? '' : " AND `close`!='1'"))->fetchColumn();
	$pcat = $db->query("SELECT * FROM `forum` WHERE `id`='".$f['refid']."'")->fetch();
	$cat = $db->query("SELECT * FROM `forum` WHERE `id`='".$pcat['refid']."'")->fetch();
	echo $i % 2 ? '<div class="list2">' : '<div class="list1">';
	// Значки
	$np = $db->query("SELECT COUNT(*) FROM `cms_forum_rdm` WHERE `time` >= '" . $f['time'] . "' AND `topic_id` = '" . $f['id'] . "' AND `user_id` = " . $systemUser->id)->fetchColumn();
    $icons = [
        ($np ? (!$res['vip'] ? '<i class="fas fa-file" style="color:#72ce72"></i>' : '') : '<i class="fas fa-file" style="color:#72ce72"></i>'),
        ($f['vip'] ? ' <i class="fas fa-thumbtack" style="color:#c03bc1"></i>' : ''),
        ($f['realid'] ? ' <i class="far fa-chart-bar" style="color:#3bc197"></i>' : ''),
        ($f['edit'] ? ' <i class="fas fa-lock" style="color:#f54343"></i>' : ''),
    ];
    echo implode('', array_filter($icons));
?>  <a href="/forum/?id=<?php echo $f['id']; ?>"><?php echo $f['text']; ?></a><br>
	<div class="div">
		<small>
			
			<span class="float-left">
				<i class="fas fa-user"></i> <?php echo $f['from']; ?> 
				<i class="fas fa-user"></i> <?php echo $us['name']; ?> 
				<i class="fas fa-comment-alt"></i> <?php echo $total; ?><br>
				<i class="fas fa-th-list"></i> <a href="/forum/?id=<?php echo $cat['id']; ?>"><?php echo $cat['text']; ?></a> / <a href="/forum/?id=<?php echo $pcat['id']; ?>"><?php echo $pcat['text']; ?></a>
			</span>
			<span class="float-right" style="position: relative;bottom: -20px;">
				<i class="far fa-calendar-alt"></i> <?php echo $tools->displayDate($f['time']); ?>
			</span>
			<div class="clearfix"></div>
		</small>
	</div>
	

</div>
<?php ++$i; ?>
<?php } ?>