<?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>' .
    "\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 href="' . $set['homeurl'] . '/bootstrap/css/bootstrap.min.css" rel="stylesheet">' .
"\n" . '<script src="/bootstrap/js/jquery-3.2.1.slim.min.js"></script>' .
"\n" . '<script src="/bootstrap/js/popper.min.js"></script>
<script type="text/javascript" src="'.$home.'/js/jquery.js"></script>' .
    "\n" . '<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script>' .
    "\n" . '<link rel="stylesheet" type="text/css" href="'.$home.'/responsive/style_menu.css" />' .
    "\n" . '<link rel="stylesheet" type="text/css" href="'.$home.'/responsive/css.css"/>' .
    "\n" . '<script type="text/javascript" src="'.$home.'/responsive/js_show.js"></script>' .
"\n" . '<script src="/bootstrap/js/bootstrap.min.js"></script><script src="https://use.fontawesome.com/80530f0ccf.js"></script>' .
    "\n" . '' .
    "\n" . '<link rel="stylesheet" href="' . $set['homeurl'] . '/theme/' . $set_user['skin'] . '/style.css">' .
     "\n" . '<link rel="stylesheet" href="' . $set['homeurl'] . '/theme/' . $set_user['skin'] . '/css.css"><link rel="stylesheet" href="' . $set['homeurl'] . '/theme/' . $set_user['skin'] . '/stylem.css">' .
     "\n" . '<link rel="stylesheet" href="' . $set['homeurl'] . '/theme/' . $set_user['skin'] . '/styles.css">' .
      "\n" . '<link rel="stylesheet" href="' . $set['homeurl'] . '/theme/' . $set_user['skin'] . '/engine.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();

 if ($user_id) {
    $xemnotification = 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);
    $xemmessage = 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);
    $xemfriend = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_contact` WHERE `from_id`='$user_id' AND `type`='2' AND `friends`='0';"), 0);
    $xemalbum = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_album_files` WHERE `user_id` = '" . core::$user_id . "' AND `unread_comments` = 1"), 0);
    $tongthongbao = ($xemnotification + $xemfriend + $xemalbum + $xemmessage);
    $xemthongbao = ($xemnotification + $xemfriend + $xemalbum);
echo "<script>
loged=1,step=0,title=document.title;
$(document).ready(function(){
var refreshTitle = setInterval(function() {
    $(\"#loadtitle\").load('/auto/autotitle.php');
    $(\"#loadtitle\").slideDown(\"slow\");
    }, 6000);
});
</script>";


    echo '<div id="loadtitle">';
    echo "<script type=\"text/javascript\">
    function flash_title() {
        if($tongthongbao > 0){
            step++;
            if(step==3){step=1};
            if(step==1){document.title=title};
            if(step==2){document.title='Bạn có ".($xemthongbao > 0 && $xemmessage > 0 ? $xemmessage.' tin nhắn và '.$xemthongbao.' thông báo' : ($xemthongbao > 0 ? $xemthongbao.' thông báo' : ($xemmessage > 0 ? $xemmessage.' tin nhắn' : '')))." mới .!!'};
            setTimeout(\"flash_title()\",1500);
        };
    };
    flash_title();
    </script>";
    echo '</div>';
   }
/*
-----------------------------------------------------------------
Рекламный модуль
-----------------------------------------------------------------
*/
$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 '<nav class="mobile-menu">
';
echo '<div class="menu"><br><a href="/"><b>Главная</b></a>
<div style="float: right;"><i class="fa fa-users" aria-hidden="true"></i>' . counters::online() . '</div></div>';
echo '<div class="topmenu"><a href="/download/dir_1.html">Узбекская Музыка</a></div>
                        <div class="topmenu"><a href="/download/dir_2.html">Русская Музыка</a></div>
                        <div class="topmenu"><a href="/download/dir_3.html">Зарубежная Музыка</a></div>
                        <div class="topmenu"><a href="/download/dir_4.html">Турецкая Музыка</a></div>
                        <div class="topmenu"><a href="/download/dir_8.html">Клубная Музыка</a></div>
<div class="topmenu"><a href="/download/dir_9.html">Минуссовка</a></div>';

echo '</nav><div id="container-outer">
<div class="main-menu" style="position: fixed;top: 0px;width:100%;">
<div class="mobile-header">
<div class="clearfloat">
<div class="wrap-icon-left m-menu">
<div class="icon-menu">
<a href="#"><span class="menu-open"><i class="fa fa-bars fa-2x"></i></span>
<span class="menu-close"><i class="fa fa-times fa-2x" aria-hidden="true"></i>
</a></span>
</div>
</div>
<a href="'.$home.'"><img src="/images/lolo.png" alt="SALOMLAR.UZ" /></a>';

echo '<script type="text/javascript"> function toggle(){var ele=document.getElementById("dropdown-toggleg");if(ele.style.display=="block"){ele.style.display = "none";}else{ele.style.display = "block";}} </script>';
             
  if($user_id){
echo '<div class="wrap-icon-right">
<div class="icon-cart">
<div class="list-cart-home">
<a style="color: #eee;margin-right: 6px;" href="javascript:toggle();"><a style="color: #eee;margin-right: 6px;" href="javascript:toggle();">
<img style="border: 2px #6c6666 solid;
   border-radius: 50%;
   box-shadow:
   0 1px 4px rgba(0, 0, 0, .3),
   -23px 0 20px -23px rgba(0, 0, 0, .8),
   23px 0 20px -23px rgba(0, 0, 0, .8),
   0 0 40px rgba(0, 0, 0, .1) inset;"
   src="/images/cower.png" width="40" hueght="40"> <i class="fa fa-sort-desc" aria-hidden="true"></i> </a>
</div>
</div>
</div>';
echo '<div id="relative"><div class="dropdown-toggleg" id="dropdown-toggleg">
<a href="' . $home . '/users/profile.php"><li><table style="padding: 0; border-spacing: 0;"><tr><td style="vertical-align: baseline; padding: 0 5px 0 5px"><img src="/images/user/info.png" /></td><td>Анкета</td></tr></table></li></a>
<a href="/users/index.php?act=online"><li><table style="padding: 0; border-spacing: 0;"><tr><td style="vertical-align: baseline; padding: 0 5px 0 5px"><img src="/images/user/partner.png" /></td><td>Онлайн</td></tr></table></li></a>';
echo '<li><center><table cellpadding="0" cellspacing="0"><tr><td valign="baseline" style="padding: 0 5px 0 5px"><a href="/download/top.php"><img src="/images/user/helpdesk.png" /></a></td><td valign="baseline" style="padding: 0 5px 0 5px"><a href="/pages/faq.php"><img src="/images/user/settings.png" /></a></td><td valign="baseline" style="padding: 0 5px 0 5px"><a href="/exit.php"><img src="/images/user/exit.png" /></a></td></tr></table></center></li>
<li style="text-align:center" class="lobster">
'.$thoiganhientai.'
</li>
</div></div>';
 }else{ 
echo '<div class="wrap-icon-right">
<div class="icon-cart">
<div class="list-cart-home"><a href="/login.php"><i class="fa fa-user-circle-o fa-2x" aria-hidden="true"></i></a></div></div></div>'; }
echo '</div>
</div>
</div><section id="container"><div class="containered">';

echo '<div class="smenu"><br></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['1'])) {
$bnsd = mysql_query("SELECT * FROM `cms_ban_users` WHERE `user_id` = '" . $user_id . "' ORDER BY `ban_time`, `ban_reason`, `ban_who` DESC LIMIT $start, $kmess");
$bns = mysql_fetch_array($bnsd);
$remain = $bns['ban_time'] - time();
$period = $bns['ban_time'] - $bns['ban_while'];
echo '<div style="text-align: center;" class="menu"><br/><img src="/images/stop.png" alt="STOP !!!"/><br/><br/>
<b>Sayt qoidalariga rioya qilmaganligingiz uchun sayt ma\'muriyati a\'zosi '.$bns['ban_who'].' tamonidan banlangansiz!</b><br/>
<b>Sababi:</b> '.$bns['ban_reason'].'<br/><b>Jazo muddati:</b> ' . functions::timecount($period).'<br/>
<b>Tugash vaqti:</b> ' . functions::timecount($remain) . '</div>';
include ('pages/end.php');
exit;
}
if (!empty($ban)) echo '<div class="menu">' . $lng['ban'] . '&#160;<a href="' . $set['homeurl'] . '/users/profile.php?act=ban">' . $lng['in_detail'] . '</a></div>';

/*
-----------------------------------------------------------------
Ссылки на непрочитанное
-----------------------------------------------------------------
*/
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[] = '<a href="' . $home . '/mail/index.php?act=systems">Система</a> (+' . $new_sys_mail . ')';
	$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[] = '<a href="' . $home . '/mail/index.php?act=new">' . $lng['mail'] . '</a> (+' . $new_mail . ')';
    if ($datauser['comm_count'] > $datauser['comm_old']) $list[] = '<a href="' . core::$system_set['homeurl'] . '/users/profile.php?act=guestbook&amp;user=' . $user_id . '">' . $lng['guestbook'] . '</a> (' . ($datauser['comm_count'] - $datauser['comm_old']) . ')';
    $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[] = '<a href="' . core::$system_set['homeurl'] . '/users/album.php?act=top&amp;mod=my_new_comm">' . $lng['albums_comments'] . '</a>';

    if (!empty($list)) echo '<div class="rmenu">' . $lng['unread'] . ': ' . functions::display_menu($list, ', ') . '</div>';
}
