<?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 PDO $db */
$db = $container->get(PDO::class);

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

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

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


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>Link Advertisement</b></td><td width="auto" align="right" valign="">';
if ($systemUser->isValid() && !isset($systemUser->ban['1']) && !isset($systemUser->ban['11'])) {
echo '<a href="../floxymods/friendssite.php?act=add_site"><img src="/images/addmore.png" width="16" height="16" class="right"/></a>';
} else {
#FOR MEMBERS ONLY
}
echo '</td></tr></table></div>';
$total = $db->query("SELECT COUNT(*) FROM `friendssite`")->fetchColumn();
if($total) {
$req = $db->query("SELECT COUNT(*) FROM `friendssite` WHERE `type`='1'");
$colmes = $req->fetchColumn();
$req = $db->query("SELECT * FROM `friendssite` WHERE `type`='1' ORDER BY RAND() LIMIT 1 ;");
$i = 0;
while ($res = $req->fetch()) {
echo ($i % 2) ? '<div class="list1">' : '<div class="list1">';
$q = mysql_query("SELECT `name`,`id` FROM `users` WHERE `id`='" . $res['iduser'] . "'");
$arr = $q->fetch();
echo '<a href="' .$config->homeurl. '/floxymods/friendssite.php?act=redirect&amp;id=' . $res['id'] . '"><b>' . $tools->checkout($res['name']) . '</b></a> [<span class="red">' . $res['count'] . '</span>]<br/>' . $tools->checkout($res['opis'], 1, 1);
echo '</div>';
++$i;
}
} else {
echo '<div class="list1">Link advertisement is empty..!!</div>';
}
echo '</div>';

// Рекламный блок сайта
if (!empty($cms_ads[2])) {
    echo '<div class="mainblok"><div class="phdr">Sponsored by:</div><center>' . $cms_ads[2] . '</center></div>';
}

// MASTERSCLIQ Navigation 
if ($headmod != "mainpage" || ($headmod == 'mainpage' && $act))
if ($systemUser->getConfig()->quickGo) {
echo '<div class="mainblok"><div class="phdr"><img src="/images/home.png" width="14" height="14" class="left"/>&nbsp;<a href="' . $config['homeurl'] . '">' . _t('Homepage') . '</a><br/>';
echo '<form action="' . $config['homeurl'] . '/go.php" method="post">';
echo '<select name="adres" style="font-size:x-small">
<option selected="selected">' . _t('Quick Navigation') . '</option>
<option value="guest">' . _t('Guestbook') . '</option>
<option value="forum">' . _t('Forum') . '</option>
<option value="news">' . _t('News Archive') . '</option>
<option value="profile">' . _t('Profile') . '</option>
<option value="down">' . _t('Downloads') . '</option>
<option value="johncms">' . _t('Johncms') . '</option>
<option value="foxwap">Foxwap Social Community</option>
</select><input type="submit" value="Go" style="font-size:x-small"/>';
echo '</form></div></div>';
}

// Floxywap Online
function showOnline($user = [], $status = 0, $ip = 0, $str = '', $text = '', $sub = '') {
global $systemUser, $config;
$out = false;
if ($user['rights'] == 0) {
$colornick['colornick'] = 'FF9900';
}
if ($user['rights'] == 1) {
$colornick['colornick'] = '3399FF';
}
if ($user['rights'] == 2) {
$colornick['colornick'] = '3399FF';
}
if ($user['rights'] == 3) {
$colornick['colornick'] = '3399FF';
}
if ($user['rights'] == 4) {
$colornick['colornick'] = '3399FF';
}
if ($user['rights'] == 5) {
$colornick['colornick'] = '3399FF';
}
if ($user['rights'] == 6) {
$colornick['colornick'] = '3399FF';
}
if ($user['rights'] == 7) {
$colornick['colornick'] = '339900';
}
if ($user['rights'] == 8) {
$colornick['colornick'] = 'EE2C2C';
}
if ($user['rights'] == 9) {
$colornick['colornick'] = 'CC0000';
}
if ($user['rights'] == 10) {
$colornick['colornick'] = '7192A8';
}
$out .= !$systemUser->isValid() || $systemUser->id == $user['id'] ? '<span style = "color:#' . $colornick['colornick'] . '">' . $user['name'] . '</span>' : '<a href="../users/profile.php?user=' . $user['id'] . '"><span style="color:#' . $colornick['colornick'] . '">' . $user['name'] . '</span></a>';
return $out;
}
function timecount($var) {
global $config;
if ($var < 0)
$var = 0;
$day = ceil($var/86400);
if ($var > 345600) {
$str = $day . ' ' . _t('Day');
}
elseif ($var >= 172800) {
$str = $day . ' ' . _t('Days');
}
elseif ($var >= 86400) {
$str = '1 ' . $_('Day');
} else {
$str = date("G:i:s", mktime(0, 0, $var));
}
return $str;
}
$users_boys = $db->query("SELECT COUNT(*) FROM `users` WHERE `sex` = 'm';")->fetchColumn();
$users_girls = $db->query("SELECT COUNT(*) FROM `users` WHERE `sex` = 'zh';")->fetchColumn();
$users = $db->query("SELECT COUNT(*) FROM `users` WHERE `lastdate` > '" . (time() - 300) . "'")->fetchColumn();
$guests = $db->query("SELECT COUNT(*) FROM `cms_sessions` WHERE `lastdate` > '" . (time() - 300) . "'")->fetchColumn();
echo '<div class="mainblok"><div class="phdr"><img src="/images/memb.png" width="16" height="16" class="left"/>&#160;<b>Whats going on..</b></a></div>';
$online = $_GET['online'];
echo '<div class="bmenu" id="online" name="online">'.($online ? '<a href="' . $_SERVER['HTTP_REFERER'] . '#online">Online</a>' : '<b>Online</b>').' <font  style="color:#3399ff">&bull;</font> '.($online == '24h' ? '<b>History</b>' : '<a href="index.php?online=24h#online">History</a>').' <font  style="color:#3399ff">&bull;</font> <b>Guest on</b>&#160;';
if ($guests >= 1)
echo '<a href="' . $config['homeurl'] . '/users/index.php?act=online&amp;mod=guest"><span class="red">' . $guests . '</a></span>';
else
echo '<span class="red">0..</a></span>';
echo '</div>';
echo '<div class="list1">Members:&#160;<a href="../users/index.php">' . $counters->users() . ' </a><br/><span class="red">' . $users_boys . '</span> Boys and <span class="red">' . $users_girls . '</span> Girls<br/>';
echo '<a href="index.php?online=freaks#online">View the online records..</a><br/>';
if ($users >= 1)
echo 'Currently:&#160;<span class="green">' . $users . '</span>&#160;member online<br/>';
switch($online) {
default:
$onltime = time() - 600;
$total = $db->query("SELECT COUNT(*) FROM `" . ($act == 'guest' ? 'cms_guests' : 'users') . "` WHERE `lastdate` > '$onltime'")->fetchColumn();
$gbot = 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)';
$yanbot = 'Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)';
$bing = 'Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)';
$bd = 'Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)';
$googlebot = $db->query("SELECT COUNT(*) FROM `cms_sessions` WHERE `lastdate` > '$onltime' AND `browser`='$gbot'")->fetchColumn();
$yandexbot = $db->query("SELECT COUNT(*) FROM `cms_sessions` WHERE `lastdate` > '$onltime' AND `browser`='$yanbot'")->fetchColumn();
$bingbot = $db->query("SELECT COUNT(*) FROM `cms_sessions` WHERE `lastdate` > '$onltime' AND `browser`='$bing'")->fetchColumn();
$baidu = $db->query("SELECT COUNT(*) FROM `cms_sessions` WHERE `lastdate` > '$onltime' AND `browser`='$bd'")->fetchColumn();
$total = $total+$googlebot+$yandexbot+$bingbot+$baidu;
echo 'Active Member:&#160;';
if ($total) {
echo ''.($googlebot ? '<font color="#7192a8">Google[bot]</font>, ' : '').''.($yandexbot ? '<font color="#7192a8">Yandex[bot]</font>, ' : '').''.($bingbot ? '<font color="#7192a8">Bing[bot]</font>, ' : '').''.($baidu ? '<font color="#7192a8">Baidu[bot]</font>, ' : '').'';
$req = $db->query("SELECT * FROM `" . ($act == 'guest' ? 'cms_guests' : 'users') . "` WHERE `preg`='1' and `lastdate` > '" . (time() - 300) . "' ORDER BY " . ($act == 'guest' ? "`movings` DESC" : "`name` ASC") . " LIMIT 1000");
while ($res = $req->fetch()) {
echo showOnline($res, 0, ($act == 'guest' || ($systemUser->rights >= 1 && $systemUser->rights >= $res['rights']) ? ($systemUser->rights >= 6 ? 2 : 1) : 0), ' (' . $res['movings'] . ' - ' . timecount($realtime - $res['sestime']) . ') ' . $place);
echo ', ';
++$l;
}
echo'<br/>';
} else {
echo 'No members online..!!<br/>';
}
break;
case '24h':
$total = $db->query("SELECT COUNT(*) FROM `" . ($act == 'guest' ? 'cms_guests' : 'users') . "` WHERE `lastdate` > '" . (time() - 96000) . "'")->fetchColumn();
echo 'Last 24 hours:&#160;';
if ($total > 0) {
$req = $db->query("SELECT * FROM `" . ($act == 'guest' ? 'cms_guests' : 'users') . "` WHERE `preg`='1' and `lastdate` > '" . (time() - 96000) . "' ORDER BY " . ($act == 'guest' ? "`movings` DESC" : "`name` ASC") . " LIMIT 1000");
while ($res = $req->fetch()) {
echo showOnline($res, 0, ($act == 'guest' || ($systemUser->rights >= 1 && $systemUser->rights >= $res['rights']) ? ($systemUser->rights >= 6 ? 2 : 1) : 0), ' (' . $res['movings'] . ' - ' . timecount($realtime - $res['sestime']) . ') ' . $place);
echo ', ';
++$l;
}
echo '<br/>';
} else {
echo 'No members online..!!<br/>';
}
break;
case 'freaks':
$rea = $db->query("SELECT COUNT(*) FROM `users` WHERE `lastdate` > '" . (time() - 172800) . "'")->fetchColumn();
$reb = $db->query("SELECT COUNT(*) FROM `cms_sessions` WHERE `lastdate` > '" . (time() - 172800) . "'")->fetchColumn();
$vr = date("d F Y g:i:s a",time()+(7*3600));
echo 'Record at online <span class="red">'.$vr.'</span> are <span class="red">'.$rea.'</span> Members and <span class="red">'.$reb.'</span> Guest, results show the
largest number of people online at the same time at <font color="green">' . $config['copyright'] . '</font><br/>';
break;
}
$total = $db->query("SELECT COUNT(*) FROM `users` WHERE `dayb` = '" . date('j', time()) . "' AND `monthb` = '" . date('n', time()) . "' AND `preg` = '1'")->fetchColumn();
if ($total) {
echo 'Birthday members:&#160;';
$req = $db->query("SELECT * FROM `users` WHERE `dayb` = '" . date('j', time()) . "' AND `monthb` = '" . date('n', time()) . "' AND `preg` = '1' ORDER BY `name` DESC LIMIT 100");
while($res = $req->fetch()) {
echo '<a href="' . $config['homeurl'] . '/users/profile.php?user='.$res['id'].'">'.$res['name'].'</a>, ';
}
}
if ($total) {
echo '<br/>';
} else {
#NO DATA
}
$cox = @$db->query("SELECT * FROM `users` WHERE `lastdate` >= '" . intval(time() - 300) . "' ORDER BY RAND() LIMIT 1;");
$count = $cox->rowCount();
while ($arr = $cox->fetch()) {
echo 'New Joined Member:&#160;';
$req = $db->query("SELECT `id`, `name`, `datereg` FROM `users` WHERE (preg='1') ORDER BY `datereg` DESC LIMIT 1;");
$arr = $req->fetch();
echo '<a href="' . $config['homeurl'] . '/users/profile.php?user=' . $arr['id'] . '"><font color="blue">'.$arr['name'] .'</font></a>';
}
if ($systemUser->isValid() || $config['active']) {
echo '<form action="' . $config['homeurl'] . '/users/?act=setskin" method="post" >' .
'Theme options:<br><select name="skin">';
foreach (glob(ROOT_PATH . 'theme/*/*.css') as $val) {
$dir = explode('/', dirname($val));
$theme = array_pop($dir);
echo '<option' . ($systemUser->getConfig()->skin == $theme ? ' selected="selected">' : '>') . $theme . '</option>';
}
echo '</select>' .
'<input type="submit" name="submit" value="Change Design"/></form></div>';
}

echo '</div><div class="mainblok"><div class="phdr">';
echo '<table width="100%" cellpadding="0" cellspacing="0"><tr><td align="left" valign="">';
echo '<a href="' . $config['homeurl'] . '"><font color="purple">' . $config['copyright'] . '</font></a>&nbsp;';
echo '</td><td width="auto" align="right" valign="">';
list($msec,$sec)=explode(chr(3),microtime());
echo '<font color="red">&nbsp;Load:</font>&nbsp;<font color="red">'.round(($sec + $msec) - $conf['headtime'], 3).'</font>&nbsp;sec&nbsp;';
echo '</td></tr></table></div></div>';


echo '</div><div class="fmenu">';

if (isset($_GET['err']) || $headmod != "mainpage" || ($headmod == 'mainpage' && isset($_GET['act']))) {
    echo '<div><a href=\'' . $config->homeurl . '\'>' . $tools->image('menu_home.png') . _t('Home', 'system') . '</a></div>';
}

echo '<div>' . $container->get('counters')->online() . '</div>' .
    '</div>' .
    '<div style="text-align:center">' .
    '<p><b>' . $config->copyright . '</b></p>';

// Счетчики каталогов
$req = $db->query('SELECT * FROM `cms_counters` WHERE `switch` = 1 ORDER BY `sort` ASC');

if ($req->rowCount()) {
    while ($res = $req->fetch()) {
        $link1 = ($res['mode'] == 1 || $res['mode'] == 2) ? $res['link1'] : $res['link2'];
        $link2 = $res['mode'] == 2 ? $res['link1'] : $res['link2'];
        $count = ($headmod == 'mainpage') ? $link1 : $link2;

        if (!empty($count)) {
            echo $count;
        }
    }
}

// Рекламный блок сайта
if (!empty($cms_ads[3])) {
    echo '<br />' . $cms_ads[3];
}

/*
-----------------------------------------------------------------
ВНИМАНИЕ!!!
Данный копирайт нельзя убирать в течение 90 дней с момента установки скриптов
-----------------------------------------------------------------
ATTENTION!!!
The copyright could not be removed within 90 days of installation scripts
-----------------------------------------------------------------
*/
echo '<div><small>&copy; <a href="http://johncms.com">JohnCMS</a></small></div>' .
    '</div></body></html>';
