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

$headmod = isset($headmod) ? mysql_real_escape_string($headmod) : '';
$textl = isset($textl) ? $textl : $set['copyright'];
$imgurl = isset($imgurl) ? $imgurl : ''.$set['homeurl'].'/dist/img/favicon.png';
$siteurl = isset($siteurl) ? $siteurl : '';
$keywords = isset($keywords) ? $keywords : $set['meta_key'];
$description = isset($description) ? $description : $set['meta_desc'];

$csrf_token = md5(uniqid(rand(), true));
$_SESSION['csrf'] = $csrf_token;

echo '<!-- Saýt skripti Pälwan Akmyradow(AkmyradoffSoft) tarapyndan 2020-nji ýylda döredildi -->
<!DOCTYPE html>
<html lang="tk-TK">
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- CSRF Token -->
    <meta name="csrf-token" content="'.$csrf_token.'">

    <!-- Meta Keys -->
    <meta name="google-site-verification" content="" />
    <meta name="yandex-verification" content="" />
    <meta name="mailru-verification" content=""/>
    
    <meta name="generator" content="AkmyradoffSoft">
    <meta name="keywords" content="' . $keywords . '">
    <meta name="description" content="' . $description . '">';
if($headmod == 'music' || $headmod == 'video' || $headmod == 'singer'){
echo '
    <meta property="og:image" content="' . $imgurl . '">
    <meta property="og:title" content="' . $textl . '">
    <meta property="og:description" content="' . $description . '">
    <meta property="og:keywords" content="' . $keywords . '">';
}
echo '
    
    <script type="application/ld+json">
        {
          "@context": "http://schema.org",
          "@type": "Course",
          "name": "' . $keywords . '",
          "description": "' . $description . '",
          "provider": {
            "@type": "Organization",
            "name": "' . $description . '",
            "sameAs": "'.$set['homeurl'].'/'.$siteurl.'"
          }
        }
    </script>

    <title>' . $textl . '</title>


    <!-- Styles -->
    <link href="'.$set['homeurl'].'/dist/css/app.css" rel="stylesheet">
    <link href="'.$set['homeurl'].'/dist/css/styles.css" rel="stylesheet">
    <link href="'.$set['homeurl'].'/dist/css/bootstrap.css" rel="stylesheet">
</head>
<body>
' . core::display_core_errors();



echo'
    <nav class="header-navbar d-flex justify-content-between align-items-center">';

if ($headmod == "mainpage"){
echo '
        <a href="'.$set['homeurl'].'"><img style="width:120px;margin-left:30px;" src="'.$set['homeurl'].'/dist/img/logo.svg" alt="logo"> </a>
';
}else{
echo '
        <a class="nav-logo" href="'.$set['homeurl'].'"><img src="'.$set['homeurl'].'/dist/img/logo.svg" alt="logo"> </a>
        <a class="previous" href="'.$set['homeurl'].'"><svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 16 16" size="30" class="previous" height="30" width="30" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M16 9l-3-3V2h-2v2L8 1 0 9h2l1 5c0 .55.45 1 1 1h8c.55 0 1-.45 1-1l1-5h2zm-4 5H9v-4H7v4H4L2.81 7.69 8 2.5l5.19 5.19L12 14z"></path></svg></a>
';
}
echo '
    </nav>
    <a class="btn-upload" href="'.$set['homeurl'].'/upload">
        <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 16 16" color="#fff" size="24" height="24" width="24" xmlns="http://www.w3.org/2000/svg" style="color: rgb(255, 255, 255);"><path d="M4.887 6.2l-.964-.165A2.5 2.5 0 103.5 11H6v1H3.5a3.5 3.5 0 11.59-6.95 5.002 5.002 0 119.804 1.98A2.501 2.501 0 0113.5 12H10v-1h3.5a1.5 1.5 0 00.237-2.981L12.7 7.854l.216-1.028a4 4 0 10-7.843-1.587l-.185.96z"></path><path fill-rule="evenodd" d="M5 8.854a.5.5 0 00.707 0L8 6.56l2.293 2.293A.5.5 0 1011 8.146L8.354 5.5a.5.5 0 00-.708 0L5 8.146a.5.5 0 000 .708z" clip-rule="evenodd"></path><path fill-rule="evenodd" d="M8 6a.5.5 0 01.5.5v8a.5.5 0 01-1 0v-8A.5.5 0 018 6z" clip-rule="evenodd"></path></svg>
    </a>

        <main class="py-4">

';



/*
-----------------------------------------------------------------
Фиксация местоположений посетителей
-----------------------------------------------------------------
*/
$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) . "'
        ");
    }
}