<?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');

/*
-----------------------------------------------------------------
Hacklord Main menu
-----------------------------------------------------------------
*/
if (!$systemUser->isValid() || ($systemUser->isValid() && $config['mod_comz'] != 0)) {
echo '<div class="mainblok"><div class="phdr"><img src="/images/logox.png" width="16" height="15" class="left"/>&nbsp;<b>Web Options</b></div><div class="none"><table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td width="55px" align="center">
<img src="/images/logox.png" width="70px" height="auto"/></td><td align="center" width="5px"><img src="/images/divi.gif" repeat="y"/></td><td align="left" width="auto"><font  style="color:#3399ff">&bull;</font> <a href="guestbook/index.php">' . _t('Guestbook') . '</a> [' . $counters->guestbook() . ']<br/><font  style="color:#3399ff">&bull;</font> <a href="forum/index.php">' . $_t('Forum') . '</a> [' . $counters->forum() . ']<br/><font  style="color:#3399ff">&bull;</font> <a href="users/index.php">Members</a> [' . $counters->users() . ']<br/><font  style="color:#3399ff">&bull;</font> <a href="download/">' . _t('Downloads') . '</a> [' . $counters->downloads() . ']<br/><font  style="color:#3399ff">&bull;</font> <a href="../card">ID CARD MAKER</a><br/><font
style="color:#3399ff">&bull;</font> <a href="pages/community.php">Community</a></td></tr></table></div>';
echo '</div>';
}

/*
-----------------------------------------------------------------
Hacklord Apply for staff
-----------------------------------------------------------------
*/

if ($headmod == 'mainpage') {
if ($systemUser->isValid() && !isset($systemUser->ban['1']) && !isset($systemUser->ban['11']) && $config['mod_staff'] != 0) {
echo '<div class="mainblok"><div class="phdr"><b>Apply As Administrator Now!!!</b></div>';
echo '<div class="gmenu" style="text-align:left">We are looking some talented members to manage this site forum..<br>If you think you are available,you can Click the button below..</div>';
echo '<div class="phdr"><a href="' .$config['homeurl'] . '/floxymods/apply_staff.php?act=add_staff"><font color="red"><b>Apply For Staff Now.</b></font></a></div></div>';
}
}

/*
-----------------------------------------------------------------
Hacklord Newest topic
-----------------------------------------------------------------
*/
$set_forum = unserialize($systemUser->set_forum); 
$setts = $config->newThemes;
if($setts['botalThemes'] > 0 && !$set_forum['seeThemes']) {
$totaled = $db->query("SELECT COUNT(*) FROM `forum` WHERE `type`='t' and kedit='0' AND `close`!='1'")->fetchColumn();
echo '<div class="mainblok"><div class="phdr"><table width="100%" cellpadding="0" cellspacing="0"><tr><td align="left" valign=""><img src="/images/subfldr.png" width="16" height="16" class="left"/>&nbsp;<b>Newest Threads</b></td><td width="auto" align="right" valign="">';
if ($systemUser->isValid() && !isset($systemUser->ban['1']) && !isset($systemUser->ban['11'])) {
echo '<a href="floxymods/fthread.php"><img src="/images/addmore.png" width="16" height="16" class="right"/></a>';
} else {
#FOR MEMBERS ONLY
}
echo '</td></tr></table></div>';
if ($totaled) {
$kreq = $db->query("SELECT * FROM `forum` WHERE `type`='t'" . ($systemUser->rights >= 7 ? '' : " AND `close`!='1'") . " ORDER BY `id` DESC LIMIT $start, " . $setts['botalThemes']);
$i = 0;
while (($kres = $kreq->fetch()) !== false) {
echo $i % 2 ? '<div class="menu">' : '<div class="menu">';
$qq3 = $db->query("SELECT `id`, `refid`, `text` FROM `forum` WHERE `type` = 'r' AND `id` = '" . $kres['refid'] . "' LIMIT 1");
$razdd = $qq3->fetch();
$qq4 = $db->query("SELECT `id`, `text` FROM `forum` WHERE `type`='f' AND `id` = '" . $razdd['refid'] . "' LIMIT 1");
$frmm = $qq4->fetch();
$nikuserr = $db->query("SELECT `from` FROM `forum` WHERE `type` = 'm' AND `close` != '1' AND `refid` = '" . $kres['id'] . "' ORDER BY `time` DESC LIMIT 1");
$namm = $nikuserr->fetch();
$botalPosts = $db->query("SELECT COUNT(*) FROM `forum` WHERE `type`='m' AND `refid`='" . $kres['id'] . "'" . ($systemUser->rights >= 7 ? '' : " AND `close` != '1'"));
$colmess1 = $botalPosts->fetchColumn();
$cpgg = ceil($colmess1 / $kmess);
$npp = $db->query("SELECT COUNT(*) FROM `cms_forum_rdm` WHERE `time` >= '" . $kres['time'] . "' AND `topic_id` = '" . $kres['id'] . "' AND `user_id`='$systemUser->id'")->fetchColumn();
// Icons for topic
$icons = array(
($npp ? (!$kres['vip'] ? '<img src="../images/op.gif" alt=""/>' : '') : '<img src="../images/np.gif" alt=""/>'),
($kres['vip'] ? '<img src="../images/pt.gif" alt=""/>' : ''),
($kres['nospam'] ? '<img src="../images/nospam.png" alt=""/>' : ''),
($kres['min_post'] ? '<img src="../images/priv.png" alt=""/>' : ''),
($kres['realid'] ? '<img src="../images/rate.gif" alt=""/>' : ''),
($kres['edit'] ? '<img src="../images/tz.gif" alt=""/>' : '')
);
echo implode('', array_filter($icons));
echo '<a href="'.$config->homeurl.'/forum/' . $tools->rewriteUrl($kres['text']) . '_' . $kres['id'] . '.html">' . $kres['text'] . '</a>&#160;[<span class="red">' . $colmess1 . '</span>]';
if ($cpg > 1) {
echo '<a href="/forum/' . $tools->rewriteUrl($kres['text']) . '_' . $kres['id'] . '_p' . $cpgg . '.html' . ($_SESSION['uppost']) . '">&#160;<img src="/images/viewpost.gif" width="12" height="10"/></a>';
}
echo '<div class="sub">';
echo 'Thread starter:&#160;' . $kres['from'];
if (!empty($namm['from'])) {
echo '<br/>Last post:&#160;<font color="orange">' . $namm['from'] . '</font>';
}
echo '<br/>Time:&#160;<span class="gray">' . $tools->updateTime($kres['time']) . '</span></div>';
echo '</div>';
++$i;
}
unset($_SESSION['fsort_id']);
unset($_SESSION['fsort_users']);
} else {
echo '<div class="rmenu"><p>New Threads Not Available..!!</p></div>';
}
if ($totaled > $setts['botalThemes']) {
echo '<div class="gmenu" align="right"><a href="' . $config['homeurl'] . '/forum/index.php?act=new&amp;do=select" class="pagenav" title="Forum list"/>Show more <img src="/images/viewpost.gif" width="12" height="10"/></a></div>';
}
echo '</div>';
}

/*
-----------------------------------------------------------------
Hacklord Latest topic
-----------------------------------------------------------------
*/

$set_forum = unserialize($systemUser->set_forum);
$settings = $config->lastThemes;
if($settings['totalThemes'] > 0 && !$set_forum['viewThemes']) {
$total = $db->query("SELECT COUNT(*) FROM `forum` WHERE `type`='t' and kedit='0' AND `close`!='1'")->fetchColumn();
echo '<div class="mainblok"><div class="phdr"><table width="100%" cellpadding="0" cellspacing="0"><tr><td align="left" valign=""><img src="/images/subfldr.png" width="16" height="16" class="left"/>&nbsp;<b>Recent Threads</b></td><td width="auto" align="right" valign="">';
if ($systemUser->isValid() && !isset($systemUser->ban['1']) && !isset($systemUser->ban['11'])) {
echo '<a href="floxymods/fthread.php"><img src="/images/addmore.png" width="16" height="16" class="right"/></a>';
} else {
#FOR MEMBERS ONLY
}
echo '</td></tr></table></div>';
if ($total) {
$req = $db->query("SELECT * FROM `forum` WHERE `type`='t'" . ($systemUser->rights >= 7 ? '' : " AND `close`!='1'") . " ORDER BY `time` DESC LIMIT $start, " . $settings['totalThemes']);
$i = 0;
while (($res = $req->fetch()) !== false) {
echo $i % 2 ? '<div class="menu">' : '<div class="menu">';
$q3 = $db->query("SELECT `id`, `refid`, `text` FROM `forum` WHERE `type` = 'r' AND `id` = '" . $res['refid'] . "' LIMIT 1");
$razd = $q3->fetch();
$q4 = $db->query("SELECT `id`, `text` FROM `forum` WHERE `type`='f' AND `id` = '" . $razd['refid'] . "' LIMIT 1");
$frm = $q4->fetch();
$nikuser = $db->query("SELECT `from` FROM `forum` WHERE `type` = 'm' AND `close` != '1' AND `refid` = '" . $res['id'] . "' ORDER BY `time` DESC LIMIT 1");
$nam = $nikuser->fetch();
$colmes = $db->query("SELECT COUNT(*) FROM `forum` WHERE `type`='m' AND `refid`='" . $res['id'] . "'" . ($systemUser->rights >= 7 ? '' : " AND `close` != '1'"));
$colmes1 = $colmes->fetchColumn();
$cpg = ceil($colmes1 / $kmess);
$np = $db->query("SELECT COUNT(*) FROM `cms_forum_rdm` WHERE `time` >= '" . $res['time'] . "' AND `topic_id` = '" . $res['id'] . "' AND `user_id`='$systemUser->id'")->fetchColumn();
// Icons for topic
$icons = array(
($np ? (!$res['vip'] ? '<img src="../images/op.gif" alt=""/>' : '') : '<img src="../images/np.gif" alt=""/>'),
($res['vip'] ? '<img src="../images/pt.gif" alt=""/>' : ''),
($res['nospam'] ? '<img src="../images/nospam.png" alt=""/>' : ''),
($res['min_post'] ? '<img src="../images/priv.png" alt=""/>' : ''),
($res['realid'] ? '<img src="../images/rate.gif" alt=""/>' : ''),
($res['edit'] ? '<img src="../images/tz.gif" alt=""/>' : '')
);
echo implode('', array_filter($icons));

echo '<a href="'.$config->homeurl.'/forum/' . $tools->rewriteUrl($res['text']) . '_' . $res['id'] . '.html">' . (empty($res['text']) ? '-----' : $res['text']) . '</a> [' . $colmes1 . ']';
if ($cpg > 1) {
echo '<a href="/forum/' . $tools->rewriteUrl($res['text']) . '_' . $res['id'] . '_p' . $cpg . '.html' . ($_SESSION['uppost']) . ' ">&#160;<img src="/images/viewpost.gif" width="12" height="10"/></a>';
}
echo '<div class="sub">';
echo 'Thread starter:&#160;' . $res['from'];
if (!empty($nam['from'])) {
echo '<br/>Last post:&#160;<font color="orange">' . $nam['from'] . '</font>';
}
echo '<br/>Time:&#160;<span class="gray">' . $tools->updateTime($res['time']) . '</span></div>';
echo '</div>';
++$i;
}
unset($_SESSION['fsort_id']);
unset($_SESSION['fsort_users']);
} else {
echo '<div class="rmenu"><p>Recent Topic List Is Empty!!</p></div>';
}
if ($total > $kmess) {
echo '<div class="gmenu" align="right">' . $tools->displayPagination('index.php?', $start, $total, $kmess) . '</div>';
}
echo '</div>';
}
