<?php
/*--------------------------------------------*/
/*--- Copyright 2011 © JohnCMS AND Ezhyk.ru ---*/
/*--- Web Module for JohnCMS 4.4.0 by -Kip-OK- & Modification -tillad- ---*/
/*--- Web theme "Double Game" by Copy-Paste Гг ---*/
/*--- Регистрируемся на http://ezhyk.ru ---*/
/*--------------------------------------------*/
defined('_IN_JOHNCMS') or die('Error: restricted access');

$headmod = isset($headmod) ? mysql_real_escape_string($headmod) : '';
$textl = isset($textl) ? $textl : $set['copyright'];

/*
-----------------------------------------------------------------
Выводим HTML заголовки страницы, подключаем CSS файл
-----------------------------------------------------------------
*/
if(stristr(core::$user_agent, "msie") && stristr(core::$user_agent, "windows")){
    // Выдаем заголовки для Internet Explorer
    header("Cache-Control: no-store, no-cache, must-revalidate");
  
} else {
    // Выдаем заголовки для остальных браузеров
    header("Cache-Control: public");
   
}
header("Expires: " . date("r",  time() + 60));
echo '<?xml version="1.0" encoding="utf-8"?>' . "\n" .
     "\n" . '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">' .
     "\n" . '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">' .
     "\n" . '<head>' .
     "\n" . '<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8"/>' .
     "\n" . '<meta http-equiv="Content-Style-Type" content="text/css" />' .
     "\n" . '<meta name="Generator" content="JohnCMS, http://johncms.com" />' . // ВНИМАНИЕ!!! Данный копирайт удалять нельзя
     (!empty($set['meta_key']) ? "\n" . '<meta name="keywords" content="' . $set['meta_key'] . '" />' : '') .
     (!empty($set['meta_desc']) ? "\n" . '<meta name="description" content="' . $set['meta_desc'] . '" />' : '') .
     "\n" . '<link rel="stylesheet" href="' . $set['homeurl'] . '/theme/web/style.css" type="text/css" />' .
     "\n" . '<script type="text/javascript" src="/theme/web/js/jquery.js"></script>' .
     "\n" . '<script type="text/javascript" src="/theme/web/js/ddaccordion.js"></script>' .
     "\n" . '<script type="text/javascript" src="/theme/web/js/alibs.js"></script>' .
     "\n" . '<script type="text/javascript" src="/theme/web/js/timers.js"></script>' .
     "\n" . '<script type="text/javascript" src="/theme/web/js/jquery.galleryview-1.0.1-pack.js"></script>' .
	 "\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();


/*
-----------------------------------------------------------------
Фиксация местоположений посетителей
-----------------------------------------------------------------
*/
$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` = '$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 = 0;
            $sql .= "`sestime` = '" . time() . "', `movings` = '0'";
        }
        if ($res['place'] != $headmod) {
            ++$movings;
            $sql .= "`place` = '$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` = '$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>';
$mp = new mainpage();
$lng_profile = core::load_lng('profile');

$total_photo = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_album_files` WHERE `user_id` = '$user_id'"), 0);
$total_guest = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_users_guestbook` WHERE `user_id` = '$user_id'"), 0);

$count_mail = mysql_result(mysql_query("SELECT COUNT(*) FROM `privat` WHERE `user` = '$login' AND `type` = 'in'"), 0);
$count_newmail = mysql_result(mysql_query("SELECT COUNT(*) FROM `privat` WHERE `user` = '" . $login . "' AND `type` = 'in' AND `chit` = 'no'"), 0);

echo '<div id="wrapper">
	<div id="header">
    <div id="header_h" align="center">
    <div class="header_h"><div class="header_h"><div class="header_h">
	<ul class="reset">
<li><a href="/"><span>Главная</a></li>
<li><div class="menu_end"><a href="/style.php?style=wap"><span>Wap версия</span></a></div></li>
</ul>
    </div></div></div>
    </div><!-- /header_h -->
    <div id="header_c">
    <div class="header_c"><div class="header_c"><div class="header_c">
    <div class="header_c_l">
    <div class="header_c_l_h">
    <div class="header_logo"><a href="/" ><img src="/theme/web/images/spacer.gif" alt=""/></a></div>
    <div class="header_social">
    <ul id="social_btn">
	<li><a href="/rss/rss.php" class="rss" title="rss"/></a></li>
	<li><a href="http://twitter.com/home/?status='.$home.'" class="tw" title="tw"/></a></li>
	<li><a href="http://vkontakte.ru/share.php?url='.$home.'" class="vk" title="vk"/></a></li>
	</ul>
    </div>
    </div>
    <div class="header_c_l_b">';
if (!$user_id)
{
	echo '<div class="reg_form">
<form method="post" action="/login.php">
<div class="lfield">
<div><input type="text" name="login_name" /></div>
<div><input type="password" name="login_password" /></div>
</div>
<div class="popsubmit">
<input name="login" type="hidden" id="login" value="submit" />
<div class="log_btn">
<button type="submit" title=""><img src="/theme/web/images/spacer.gif" alt=""/></button></div>
</div>
</form>
</div>
<div class="reg_link"><a href="/registration.php">Регистрация</a>
 | <a href="/users/skl.php?continue">Забыли пароль?</a></div>';
} else {	

echo '<div class="log_form">';

 if (file_exists(($_SERVER['DOCUMENT_ROOT'].'/files/users/photo/' . $user_id . '.jpg')))
      {
    echo '<div class="log_form_ava"><img src="'.$_SERVER['DOCUMENT_ROOT'].'/files/users/photo/' . $user_id . '.jpg" style="width: 106px; height: 106px;" alt="' . $user_name . '" /></div>';
	} else {
	echo '<div class="log_form_ava"><img src="/theme/web/images/noavatar.png" alt="' . $user_name . '" /></div>';
	}
	
  echo '<ul class="reset">
    <li>Привет, '.$login.'</li>
    <li><a href="/users/profile.php">' . $lng_profile['my_profile'] . '</a>(' . $count_mail . ($count_newmail ? '&#160;/&#160;<span class="red"><a href="pradd.php?act=in&amp;new">+' . $count_newmail . '</a></span>' : '') . ')</li>
    </ul>
    <ul class="reset">
    <li><a href="/users/album.php?act=list">' . $lng['photo_album'] . '</a> (' . $total_photo . ')</li>
    <li><a href="/users/profile.php?act=guestbook">' . $lng['guestbook'] . ' (' . $total_guest . ')</a></li>
    </ul>
    <ul class="reset">
	<li><a href="/users/profile.php?act=stat">' . $lng['statistics'] . '</a></li>
    <li><a href="/exit.php">Выход</a></li>
    </ul>
</div>';
}

echo '</div>
    </div>
    <div class="header_c_r">
    <div class="header_banner"><div><img src="/theme/web/images/468x60.png" alt="" /></div></div>
    <div class="header_search">
    <div class="search_block">
	
	<form action="/forum/search.php" method="post">
	<div class="search_btn"><input class="sbtn" value="Поиск" alt="Поиск" type="image" src="/theme/web/images/spacer.gif" /></div>
	<div class="search_bg"><input class="sfield" id="story" name="search" value="Введите текст для поиска..." onblur="if(this.value==\'\') this.value=\'Введите текст для поиска...\';" onfocus="if(this.value==\'Введите текст для поиска...\') this.value=\'\';" type="text" maxlength="60" /></div>
	</form>
	
	</div>
    </div>
    </div>
    </div></div></div>
    </div>
	<!-- /header_c -->

    <div id="header_b">
    <div class="speedbar"><span id="dle-speedbar">Добро пожаловать</span></div>
    </div><!-- /header_b -->
    </div><!-- /header -->';
	
include_once $_SERVER['DOCUMENT_ROOT'].'/theme/web/right.php';
include_once $_SERVER['DOCUMENT_ROOT'].'/theme/web/left.php';

if ($headmod != "mainpage" || ($headmod == 'mainpage' && $act))
      { 
	   echo '<div id="side_center">

        <div id="dle-content">        <div class="story">
        <div class="story_h">
        <div class="story_h_t">
        <div class="story_moder">
        <ul class="reset">
		
		</ul>
        </div>
        <div class="story_title"></div>
        </div>
        <div class="story_h_inf">
        
        </div>
        </div>
        <div class="story_c story_text">
        <div id="news-id-5" style="display:inline;">';
	  }
?>
