<?php


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

$headmod = isset($headmod) ? mysql_real_escape_string($headmod) : '';
$textl = isset($textl) ? $textl : $set['copyright'];
$keywords = isset($keywords) ? htmlspecialchars($keywords) : $set['meta_key'];
$description = isset($description) ? htmlspecialchars($description) : $set['meta_desc'];

echo'<!DOCTYPE html>' .
    '<html lang="' . core::$lng_iso . '">' .
    '<head>' .
    '<meta charset="utf-8">' .
    '<meta http-equiv="X-UA-Compatible" content="IE=edge">' .
    '<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0, user-scalable=yes">' .
    '<meta name="HandheldFriendly" content="true">' .
    '<meta name="MobileOptimized" content="width">' .
    '<meta content="yes" name="apple-mobile-web-app-capable">' .
'<meta name="Generator" content="Menejer.CF">' .
    '<meta name="keywords" content="' . $keywords . '">'.
    '<meta name="description" content="' . $description . '">'.
    '<meta name="author" content="Abatbaev Ilham">' .
    '<meta name="robots" content="all" />'.
  '<meta name="revisit-after" content="1 days" />'.
	'<link rel="stylesheet" href="' . $set['homeurl'] . '/theme/' . $set_user['skin'] . '/css/style.css" type="text/css">' .
	'<link rel="stylesheet" href="' . $set['homeurl'] . '/theme/' . $set_user['skin'] . '/foundation/foundation-icons.css" type="text/css">' .
	'<link rel="stylesheet" href="' . $set['homeurl'] . '/theme/' . $set_user['skin'] . '/css/all.css" integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous">'.
'<link rel="canonical" href="http://menejer.cf" />'.
	'<link rel="stylesheet" href="' . $set['homeurl'] . '/theme/' . $set_user['skin'] . '/css/all1.css" integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous">'.
    '<link rel="shortcut icon" href="' . $set['homeurl'] . '/favicon.ico">' .
    '<link rel="alternate" type="application/rss+xml" title="RSS | ' . $lng['site_news'] . '" href="' . $set['homeurl'] . '/rss/rss.php">' .
    '<title>'.$set['copyright'].'</title>' .
    '</head><body>' . core::display_core_errors();

/*
-----------------------------------------------------------------
Рекламный модуль
-----------------------------------------------------------------
*/
$lng_news = core::load_lng('news');

$cms_ads = array();
if (!isset($_GET['err']) && $act != '404' && $headmod != 'admin') {
    $view = $user_id ? 2 : 1;
    $layout = ($headmod == 'mainpage' && !$act) ? 1 : 2;
    $req = mysql_query("SELECT * FROM `cms_ads` WHERE `to` = '0' AND (`layout` = '$layout' or `layout` = '0') AND (`view` = '$view' or `view` = '0') ORDER BY  `mesto` ASC");
    if (mysql_num_rows($req)) {
        while (($res = mysql_fetch_assoc($req)) !== FALSE) {
            $name = explode("|", $res['name']);
            $name = htmlentities($name[mt_rand(0, (count($name) - 1))], ENT_QUOTES, 'UTF-8');
            if (!empty($res['color'])) $name = '<span style="color:#' . $res['color'] . '">' . $name . '</span>';
            // Если было задано начертание шрифта, то применяем
            $font = $res['bold'] ? 'font-weight: bold;' : FALSE;
            $font .= $res['italic'] ? ' font-style:italic;' : FALSE;
            $font .= $res['underline'] ? ' text-decoration:underline;' : FALSE;
            if ($font) $name = '<span style="' . $font . '">' . $name . '</span>';
            @$cms_ads[$res['type']] .= '<a href="' . ($res['show'] ? functions::checkout($res['link']) : $set['homeurl'] . '/go.php?id=' . $res['id']) . '">' . $name . '</a><br/>';
            if (($res['day'] != 0 && time() >= ($res['time'] + $res['day'] * 3600 * 24)) || ($res['count_link'] != 0 && $res['count'] >= $res['count_link']))
                mysql_query("UPDATE `cms_ads` SET `to` = '1'  WHERE `id` = '" . $res['id'] . "'");
        }
    }
}

/*
-----------------------------------------------------------------
Рекламный блок сайта
-----------------------------------------------------------------
*/
if (isset($cms_ads[0])) echo $cms_ads[0];

/*
-----------------------------------------------------------------
Выводим логотип и переключатель языков
-----------------------------------------------------------------
*/
echo '<table style="width: 100%; background: #fff;"><tr>' .
    '<td valign="bottom"><a href="' . $set['homeurl'] . '">' . functions::image('logo.png', array('class' => '')) . '</a></td>' .
    '</tr></table>';

/*
-----------------------------------------------------------------
Выводим верхний блок с приветствием
-----------------------------------------------------------------
*/
echo '<div class="header"> ' . $lng['hi'] . ', ' . ($user_id ? '<b>' . $login . '</b>!' : $lng['guest'] . '!') . ' '.$lng['hour'].' ' . date("H:i", time() + $set['timeshift'] * 3600) . '</div>';

/*
-----------------------------------------------------------------
Главное меню пользователя
-----------------------------------------------------------------
*/
echo '<div class="menu" style="text-align:center;">';
if($user_id) echo'<a href="' . $set['homeurl'] . '/users/profile.php">' . $lng['profile'] . '</a>&nbsp;|&nbsp;<a href="' . $set['homeurl'] . '/users/profile.php?act=office">' . $lng['personal'] . '</a>&nbsp;|&nbsp;<a href="'.$home.'/man/index.php" style="font-weight: bold; color:red;">'.$lng['fm2018'].'</a>';   else  echo'<a href="' . $set['homeurl'] . '/login.php">' . $lng['login'] . '</a>&nbsp;|&nbsp;<a href="' . $set['homeurl'] . '/reg.php">' . $lng['registration'] . '</a>';

echo'</div>';

/*
-----------------------------------------------------------------
Рекламный блок сайта
-----------------------------------------------------------------
*/
if (!empty($cms_ads[1])) echo '<div class="menu">' . $cms_ads[1] . '</div>';

/*
-----------------------------------------------------------------
Фиксация местоположений посетителей
-----------------------------------------------------------------
*/
$sql = '';
$set_karma = unserialize($set['karma']);
if ($user_id) {
    // Фиксируем местоположение авторизованных
    if (!$datauser['karma_off'] && $set_karma['on'] && $datauser['karma_time'] <= (time() - 86400)) {
        $sql .= " `karma_time` = '" . time() . "', ";
    }
    $movings = $datauser['movings'];
    if ($datauser['lastdate'] < (time() - 300)) {
        $movings = 0;
        $sql .= " `sestime` = '" . time() . "', ";
    }
    if ($datauser['place'] != $headmod) {
        ++$movings;
        $sql .= " `place` = '" . mysql_real_escape_string($headmod) . "', ";
    }
    if ($datauser['browser'] != $agn)
        $sql .= " `browser` = '" . mysql_real_escape_string($agn) . "', ";
    $totalonsite = $datauser['total_on_site'];
    if ($datauser['lastdate'] > (time() - 300))
        $totalonsite = $totalonsite + time() - $datauser['lastdate'];
    mysql_query("UPDATE `users` SET $sql
        `movings` = '$movings',
        `total_on_site` = '$totalonsite',
        `lastdate` = '" . time() . "'
        WHERE `id` = '$user_id'
    ");
} else {
    // Фиксируем местоположение гостей
    $movings = 0;
    $session = md5(core::$ip . core::$ip_via_proxy . core::$user_agent);
    $req = mysql_query("SELECT * FROM `cms_sessions` WHERE `session_id` = '$session' LIMIT 1");
    if (mysql_num_rows($req)) {
        // Если есть в базе, то обновляем данные
        $res = mysql_fetch_assoc($req);
        $movings = ++$res['movings'];
        if ($res['sestime'] < (time() - 300)) {
            $movings = 1;
            $sql .= " `sestime` = '" . time() . "', ";
        }
        if ($res['place'] != $headmod) {
            $sql .= " `place` = '" . mysql_real_escape_string($headmod) . "', ";
        }
        mysql_query("UPDATE `cms_sessions` SET $sql
            `movings` = '$movings',
            `lastdate` = '" . time() . "'
            WHERE `session_id` = '$session'
        ");
    } else {
        // Если еще небыло в базе, то добавляем запись
        mysql_query("INSERT INTO `cms_sessions` SET
            `session_id` = '" . $session . "',
            `ip` = '" . core::$ip . "',
            `ip_via_proxy` = '" . core::$ip_via_proxy . "',
            `browser` = '" . mysql_real_escape_string($agn) . "',
            `lastdate` = '" . time() . "',
            `sestime` = '" . time() . "',
            `place` = '" . mysql_real_escape_string($headmod) . "'
        ");
    }
}

/*
-----------------------------------------------------------------
Выводим сообщение о Бане
-----------------------------------------------------------------
*/
if (!empty($ban)) {
header('Location: /users/profile.php?act=ban');
    exit;
}

/*
-----------------------------------------------------------------
Ссылки на непрочитанное
-----------------------------------------------------------------
*/
if ($user_id) { 
echo'<div class="topclassd"><table width="100%" cellpadding="0" cellspacing="0"><tr>';
if ($headmod != "mainpage") {
echo'<td align="center" style="width: 1%;  border-right: 1px #8ee384 solid; color: #fff;"><a class="topa" style="color:#fff;" href="'.$home.'"><img src="'.$home.'/images/head/homes.png" style="margin-bottom: -3px;width:18px; height:18px;" alt="'.$lng['home'].'" title="'.$lng['home'].'"></a></td>';
}

$users = mysql_result(mysql_query("SELECT COUNT(*) FROM `users` WHERE `lastdate` > '" . (time() - 300) . "'"), 0);
echo'<td style="width: 1%;  border-right: 1px #8ee384 solid; color: #fff;" align="center"><a class="topa" style="color:#fff;" href="'.$home.'/users/index.php?act=online"><img src="'.$home.'/images/head/online.png" style="margin-bottom: -3px;width:18px; height:18px;" alt="'.$lng['online'].'" title="'.$lng['online'].'">&#160;'.$users.'</a></td>';	
$list = array();
   

	
if ($headmod != "pradd") {
$new_pm = mysql_result(mysql_query("SELECT COUNT(*) FROM `privat` WHERE `user` = '$login' AND `type` = 'in' AND `chit` = 'no'"), 0);
    if ($new_pm) $list[] = '<td align="center" style="width: 1%;  border-right: 1px #8ee384 solid; color: #fff;"><a class="topa" style="color:#fff;" href="' . core::$system_set['homeurl'] . '/users/pradd.php?act=in&amp;new"><img src="'.$home.'/images/head/pradd.png" style="margin-bottom: -3px;width:18px; height:18px;"  alt="'.$lng['manager'].'">+' . $new_pm . '</a></td>';
}
	
    $new_sys_mail = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_mail` WHERE `from_id`='$user_id' AND `read`='0' AND `sys`='1' AND `delete`!='$user_id';"), 0);
	if ($new_sys_mail) $list[] = '<td align="center" style="width: 1%;  border-right: 1px #8ee384 solid; color: #fff;"><a class="topa" style="color:#fff;" href="' . $home . '/mail/index.php?act=systems"><img src="'.$home.'/images/head/system.png" style="margin-bottom: -3px;width:18px; height:18px;" alt="'.$lng['system'].'" align="top"> +' . $new_sys_mail . '</a></td>';

	if ($new)
	$total .= '&#160;/&#160;<span class="red">+'.$new.'</span>';	
$chat_mess = mysql_result(mysql_query("SELECT COUNT(*) FROM `m_chat` WHERE `time` > '" . (time() - 3600*24) . "'"), 0);
	echo'<td align="center" style="width: 1%;  border-right: 1px #8ee384 solid; color: #fff;"><a class="topa" style="color:#fff;" href="'.$home.'/mchat/index.php"><img src="'.$home.'/images/head/mchat.png" style="margin-bottom: -3px;width:18px; height:18px;" alt="'.$lng['mchat'].'" title="'.$lng['mchat'].'">&#160;'.$chat_mess.'</a></td>';
$new_mail = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_mail` LEFT JOIN `cms_contact` ON `cms_mail`.`user_id`=`cms_contact`.`from_id` AND `cms_contact`.`user_id`='$user_id' WHERE `cms_mail`.`from_id`='$user_id' AND `cms_mail`.`sys`='0' AND `cms_mail`.`read`='0' AND `cms_mail`.`delete`!='$user_id' AND `cms_contact`.`ban`!='1' AND `cms_mail`.`spam`='0'"), 0);
	if ($new_mail) $list[] = '<td align="center" style="width: 1%;  border-right: 1px #8ee384 solid; color: #fff;"><a class="topa" style="color:#fff;" href="' . $home . '/mail/index.php?act=new"><img src="'.$home.'/images/head/mail.png" alt="'.$lng['mail'].'" style="margin-bottom: -3px;width:18px; height:18px;"> +' . $new_mail . '</a></td>';
    if ($datauser['comm_count'] > $datauser['comm_old']) $list[] = '<td align="center" style="width: 1%;  border-right: 1px #8ee384 solid; color: #fff;"><a class="topa" style="color:#fff;" href="' . core::$system_set['homeurl'] . '/users/profile.php?act=guestbook&amp;user=' . $user_id . '"><img src="'.$home.'/images/head/book.png" alt="'.$lng['guestbook'].'" style="margin-bottom: -3px;width:18px; height:18px;">' . ($datauser['comm_count'] - $datauser['comm_old']) . '</a></td>';
if(time() > $datauser['money_time'] + 3600 * 10){
    $bonus = mysql_fetch_assoc(mysql_query("SELECT * FROM `shop` WHERE `id`=5"));
    $mon = $datauser['balans'] + $bonus['price'];
    mysql_query("UPDATE `users` SET `balans` = '$mon', `money_time` = '".time()."' WHERE `id` = '$user_id'");
    $list[] = '<td align="center" style="width: 1%;  border-right: 1px #8ee384 solid; color: #fff;"><a class="topa" style="color:#fff;" href="http://webwmr.ru/100.go" target="_blank"><img src="'.$home.'/images/head/money.png" alt="'.$lng['mail'].'" style="margin-bottom: -3px;width:18px; height:18px;">+'.$bonus['price'].'</a>';
    }

    echo '' . functions::display_menu($list, ' ') . '';
	echo'</tr></table></div>';
}