<?php 
if (core::$user_rights == 9) {
  ini_set('display_errors', 1);
  ini_set('display_startup_errors', 1);
  error_reporting(E_ALL);
} ?>
<?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'];
/*
Реклама модули
*/
$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']) : $home . '/go.'.$akb_for.'?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'] . "'");
    }
  }
}
// Mehmonlani qaydan kirganini aniiqlaymiz 
$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) . "'
      "); } } ?>
      <!DOCTYPE html>
      <html>
      <head>
       <meta charset="utf-8">
       <html lang="uz">
       <meta http-equiv="X-UA-Compatible" content="IE=edge">
       <meta name="viewport" content="width=device-width, initial-scale=1">
       <link rel="alternate" type="application/rss+xml" title="RSS | <?php echo $lng['site_news']; ?>" href="<?php echo $home; ?>/rss/rss.<?php echo$akb_for;?>">
       <link rel="shortcut icon" href="<?php echo  $home; ?>/favicon.ico">
       <link rel="stylesheet" href="<?php echo $home;?>/theme/<?php echo $set_user['skin'];?>/css/w3.css">
       <link rel="stylesheet" href="<?php echo $home;?>/theme/<?php echo $set_user['skin'];?>/css/style.css">
       <link rel="stylesheet" href="<?php echo $home;?>/theme/<?php echo $set_user['skin'];?>/css/w3-theme-blue-grey.css">
       <link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Open+Sans'>
       <link rel="stylesheet" href="<?php echo $home;?>/theme/<?php echo $set_user['skin'];?>/css/akbar.css" type="text/css" />
       <script defer src="<?php echo $home;?>/theme/<?php echo $set_user['skin'];?>/js/all.js"></script>
       <?php if (($user_id == true) && !($user_id == false)) { ?>
       <script src="<?php echo $home;?>/theme/<?php echo $set_user['skin'];?>/js/jquery.js"></script>
       <script src="<?php echo $home;?>/ajax/ajax.js"></script>
            
        <?php } ?>
       <!--   <script src="//unpkg.com/vue"> </script>
         <script src="//cdnjs.cloudflare.com/ajax/libs/axios/0.15.3/axios.min.js"> </script> -->
         <!-- Keraksiz Ajax chat kodlari boshlanvotti -->
         <!-- tugadi ajax chat -->
       </head>
       <title><?php echo $textl;?></title>
       <style>
         html, body, h1, h2, h3, h4, h5 {font-family: "Open Sans", sans-serif}
       </style>
       <noscript>Akasi iltimos yangiro brovzer ishlating</noscript>
       <body class="w3-theme-l5 w3-content" style="max-width:1600px">
         <?php core::display_core_errors(); ?>
         <!-- Foydalanuvchilar uchun ko`rinadi -->
         <?php 
         if (($user_id == true) && !($user_id == false)) { 
          include_once $_SERVER['DOCUMENT_ROOT'].'/theme/'.$set_user['skin'].'/php/users.php';
        } ?>
        <!-- Mehmonlar uchun ko`rinadi -->
        <?php 
        if ((!$user_id == true) && !(!$user_id == false)) {
          include_once $_SERVER['DOCUMENT_ROOT'].'/theme/'.$set_user['skin'].'/php/mehmon.php';
        } ?>
        <div class="w3-card w3-round w3-white w3-hide-small">
          <div class="w3-container"> 
           <p><a href="<?php echo $home; ?>/users/index.<?php echo$akb_for;?>?act=online">Hozir saytda</a></p><hr><p>
            <?php 
            $akb_total = "SELECT COUNT(*) FROM `users` WHERE `lastdate` > " . (time() - 300);
            $akb_list = "SELECT * FROM `users` WHERE `lastdate` > " . (time() - 300) . " ORDER BY rand() ASC LIMIT 300";
            if ($akb_total) {
              $kbar_o = mysql_query($akb_list);
              while (($akbar_onl = mysql_fetch_assoc($kbar_o)) !== false) {
                echo '<a href="/users/profile.'.$akb_for.'?user='.$akbar_onl['id'].'">'.$akbar_onl['name'].'</a>, ';
              } }  
              ?>
            </p></div></div><br>
            <!-- Alert Box -->
            <div class="w3-container w3-display-container w3-round w3-theme-l4 w3-border w3-theme-border w3-margin-bottom w3-hide-small">
             <p><a href="http://socpublic.com/?i=3397782" target="_blank"><img src="<?php echo $home; ?>/images/s400.gif" width="99%" height="400" border="0" alt="SOCPUBLIC.COM - заработок в интернете!"><br></a> <br><a href="https://socpublic.com/?i=3397782&slide=1">SOCPUBLIC.COM - Заработок в интернете, платные задания, платные письма, платные просмотры.</a> </p>
           </div>
         </div> 
         <div class="w3-col m7">
           <div class="w3-row-padding">
            <div class="w3-col m12">
             <div class="w3-card w3-round w3-white">
              <div class="w3-container w3-padding">
                <p><a href="http://socpublic.com/?i=3397782" target="_blank"><img src="<?php echo $home; ?>/images/s728.gif" width="99%" height="10%" border="0" alt="SOCPUBLIC.COM - заработок в интернете!"></a></p> </div></div></div></div><br></div>
                <div class="w3-col m7">
                 <div class="w3-row-padding">
                  <div class="w3-col m12">
                   <div class="w3-card w3-round w3-white">
                    <div class="w3-container w3-padding">
                     <?php !$user_id ?: include 'bonus.php'; ?>