<?php

/**
 * @package     JohnCMS
 * @link        http://johncms.com
 * @copyright   Copyright (C) 2008-2011 JohnCMS Community
 * @license     LICENSE.txt (see attached file)
 * @version     VERSION.txt (see attached file)
 * @author      http://johncms.com/about
 */

defined('_IN_JOHNCMS') or die('Error: restricted access');
//Реферальская система
require_once ($rootpath . 'incfiles/referals.php');
//Реферальская система 

$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>' .
    "\n" . '<html lang="' . core::$lng_iso . '">' .
    "\n" . '<head>' .
    "\n" . '<meta charset="utf-8">' .
    "\n" . '<meta http-equiv="X-UA-Compatible" content="IE=edge">' .
    "\n" . '<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0, user-scalable=yes">' .
    "\n" . '<meta name="HandheldFriendly" content="true">' .
    "\n" . '<meta name="MobileOptimized" content="width">' .
    "\n" . '<meta content="yes" name="apple-mobile-web-app-capable">' .
    "\n" . '<meta name="Generator" content="JohnCMS, http://johncms.com">' .
    "\n" . '<meta name="keywords" content="' . $keywords . '">'.
    "\n" . '<meta name="description" content="' . $description . '">'.
	"\n" . '<link rel="stylesheet" href="' . $set['homeurl'] . '/css/bootstrap.min.css" />' .
    "\n" . '<link rel="stylesheet" href="' . $set['homeurl'] . '/theme/' . $set_user['skin'] . '/style.css">' .
    "\n" . '<script src="' . $set['homeurl'] . '/js/jquery-1.11.3.min.js"></script>' .
    "\n" . '<script src="' . $set['homeurl'] . '/js/bootstrap.min.js"></script>' .
    "\n" . '<link rel="stylesheet" href="' . $set['homeurl'] . '/animate.css" />' .
    "\n" . '<link rel="stylesheet" href="' . $set['homeurl'] . '/font-awesome.css">' .
    "\n" . '<link rel="shortcut icon" href="' . $set['homeurl'] . '/favicon.ico">' .
    "\n" . '<link rel="alternate" type="application/rss+xml" title="RSS | ' . $lng['site_news'] . '" href="' . $set['homeurl'] . '/rss/rss.php">' .
    "\n" . '<title>' . $textl . '</title>' .
    "\n" . '</head><body>' . core::display_core_errors();

/*
-----------------------------------------------------------------
Рекламный модуль
-----------------------------------------------------------------
*/
$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];

/*
-----------------------------------------------------------------
Выводим логотип и переключатель языков
-----------------------------------------------------------------
*/
?>

<header class="header">
    <div class="container">
        <h1 class="logo pull-left"><a href="/"><?=$set['copyright']?></a></h1>
        
        </form>
    </div>
</header>

<div class="container"><div class="row">
    <nav class="main-nav">
        <ul>
            <li class="hidden-lg hidden-md hidden-sm"><a href="/" class="main-nav-a"><i class="fa fa-home" aria-hidden="true"></i></a></li>

            <li class="hidden-lg hidden-md hidden-sm"><a href="/forum/index.php?act=new&do=period" class="main-nav-a"><i class="fa fa-clock-o" aria-hidden="true"></i></a></li>
            

            <li class="hidden-xs"><a href="/" class="main-nav-a"><i class="fa fa-home" aria-hidden="true"></i> Главная</a></li>

            <li class="hidden-xs"><a href="/forum/index.php?act=new&do=period" class="main-nav-a"><i class="fa fa-clock-o" aria-hidden="true"></i> Новые посты</a></li>
            
          
                     
               <? echo forum_counte(); ?>
     
    <? if ($user_id) {
    $list = array();
    $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[] = '<li><a class="main-nav-a" href="' . $home . '/mail/index.php?act=systems"><i class="fa fa-spinner" aria-hidden="true"></i> <span class="badge">' . $new_sys_mail . '</span></a></li>';
	$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[] = '<li><a class="main-nav-a" href="' . $home . '/mail/index.php?act=new"><i class="fa fa-paper-plane" aria-hidden="true"></i> <span class="badge">' . $new_mail . '</span></a></li>';
    if ($datauser['comm_count'] > $datauser['comm_old']) $list[] = '<li><a class="main-nav-a" href="' . core::$system_set['homeurl'] . '/users/profile.php?act=guestbook&amp;user=' . $user_id . '"><i class="fa fa-address-book-o" aria-hidden="true"></i> <span class="badge">' . ($datauser['comm_count'] - $datauser['comm_old']) . '</span></a></li>';
    $new_album_comm = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_album_files` WHERE `user_id` = '" . core::$user_id . "' AND `unread_comments` = 1"), 0);
	if ($new_album_comm) $list[] = '<li><a class="main-nav-a" href="' . core::$system_set['homeurl'] . '/users/album.php?act=top&amp;mod=my_new_comm"><i class="fa fa-picture-o" aria-hidden="true"></i> <span class="badge">' . $new_album_comm . '</span></a></li>';

    if (!empty($list)) echo functions::display_menu($list, ' ');
}
?>       
                      
                      <? if (!$user_id) { ?>    <li class="dropdown pull-right">

              <button class="btn btn-default dropdown-toggle nav-btn hidden-xs" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
                <i class="fa fa-lock" aria-hidden="true"></i> Гость                <span class="caret"></span>
              </button>
              <button class="btn btn-default dropdown-toggle nav-btn visible-xs" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
                <i class="fa fa-lock" aria-hidden="true"></i>                <span class="caret"></span>
              </button>
          <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
                 
              <li><a href="/login.php">Авторизация</a></li>
              <li><a href="/registration.php">Регистрация</a></li>
              <li><a href="/users/skl.php">Восстановить пароль</a></li>
                   <? } else {?>
                   <li class="dropdown pull-right">

              <button class="btn btn-default dropdown-toggle nav-btn hidden-xs" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
               <i class="fa fa-user" aria-hidden="true"></i> <?= $login?>                <span class="caret"></span>
              </button>
              <button class="btn btn-default dropdown-toggle nav-btn visible-xs" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
               <i class="fa fa-user" aria-hidden="true"></i>               <span class="caret"></span>
              </button>
         <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
              
              <li><a href="/users/profile.php">Мой профиль</a></li>
              <li><a href="/users/profile.php?act=office">Личный кабинет</a></li>
              <li><a href="/users/index.php">Пользователи</a></li>
              <li><a href="/users/referals.php">Рефералы</a></li>
              <li><a href="/guestbook/index.php">Гостевая книга</a></li>
              <li><a href="/users/album.php">Фотоальбом</a></li>
              <li><a href="/forum/index.php">Форум</a></li>
              <li><a href="/blogs">Блог</a></li>
              <li><a href="/pages/faq.php">FAQ</a></li>
              <li><a href="/ads.php">Реклама</a></li>
              <li><a href="/exit.php">Выход</a></li>
                              
              </ul>
                    <? } ?>           
              </ul>
            </li>
        </ul>
    </nav></div>
</div>

 <? function forum_counte($num = 0){
  if (core::$user_id){
    $total = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_topics` LEFT JOIN `forum_readed` ON `forum_topics`.`topic` = `forum_readed`.`topic` AND `forum_readed`.`user_id` = '".core::$user_id."' WHERE (`forum_readed`.`topic` Is Null OR `forum_topics`.`time` > `forum_readed`.`time`) "), 0);
    if ($num == 1){
      return $total;
    }elseif($num == 2){
      if ($total)
        return ' <li><span class="badge"><a class="main-nav-a" href="index.php?act=last&amp;unread">+'.$total.'</a></span></li>';
      else
        return false;
    }else{
      return '<li><a class="main-nav-a" href="/forum/index.php?act=last&amp;unread"><i class="fa fa-check" aria-hidden="true"></i> <span class="hidden-xs">Непрочитанные</span>'.($total ? ' <span class="badge">'.$total.'</span>' : '').'
</a></li>
<li><a class="main-nav-a" href="/forum/index.php?act=my&amp;journal"><i class="fa fa-bell" aria-hidden="true"></i>'.(journal::displayNew() ? journal::displayNew() : '').'</a></li>';
    }
  }
}
?> 
<!--
<li><a href="/forum/index.php?act=my&amp;favourites">Избранное</a>
<div class="container"><div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="topnavi">

</div></div></div></div>-->

<div class="container"><div class="row">
<div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">


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

/*
-----------------------------------------------------------------
Главное меню пользователя
-----------------------------------------------------------------
*/
/*echo '<div class="tmn">' .
    (isset($_GET['err']) || $headmod != "mainpage" || ($headmod == 'mainpage' && $act) ? '<a href=\'' . $set['homeurl'] . '\'>' . functions::image('menu_home.png') . $lng['homepage'] . '</a><br/>' : '') .
    ($user_id && $headmod != 'office' ? '<a href="' . $set['homeurl'] . '/users/profile.php?act=office">' . functions::image('menu_cabinet.png') . $lng['personal'] . '</a><br/>' : '') .
    (!$user_id && $headmod != 'login' ? functions::image('menu_login.png') . '<a href="' . $set['homeurl'] . '/login.php">' . $lng['login'] . '</a>' : '') .
    '</div><div class="maintxt">';*/

/*
-----------------------------------------------------------------
Рекламный блок сайта
-----------------------------------------------------------------
*/
echo '

<div class="phdr">Реклама</a></div>';
if (!empty($cms_ads[1])) echo '<div class="gmenu">' . $cms_ads[1] . '</div>';
echo '
<br>';

/*
-----------------------------------------------------------------
Фиксация местоположений посетителей
-----------------------------------------------------------------
*/
$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)) echo '<div class="alarm">' . $lng['ban'] . '&#160;<a href="' . $set['homeurl'] . '/users/profile.php?act=ban">' . $lng['in_detail'] . '</a></div>';

/*
-----------------------------------------------------------------
Ссылки на непрочитанное
-----------------------------------------------------------------
*/
