<?

header('Cache-Control: no-store, no-cache, must-revalidate');

// Определение версии
if (isset($_GET['ver']))$_SESSION['ver'] = check($_GET['ver']);

if (isset($user))$ver = check($user['ver']);
else if (isset($_SESSION['ver'])) $ver = check($_SESSION['ver']);
else $ver = check($_GET['ver']);

if (empty($ver)) $ver = 'xhtml';

// Шрифт :)
if($user['fsize'] == 'small') {$fs1 = '<small>';$fs2 = '</small>';}
else if($user['fsize'] == 'big') {$fs1 = '<big>';$fs2 = '</big>';}
else {$fs1 = '';$fs2 = '';}

// Стиль
if (isset($user['style'])) $them = $user['style'];
else if (isset($set['style'])) $them = $set['style'];
else $them = 'go-wap';


ob_start();
// Основные дивы, для удобства :)
if ($ver!='wml'){
define('hdrs','<div class="hdrs">');
define('gb','<div class="gb">');
define('gbinroom','<div class="gbinroom">');
define('links','<div class="links">');
define('menu','<div class="menu">');
define('main','<div class="main">');
define('footer','<div class="footer">');
define('citata','<div class="citata">');
define('copyr','<div class="copy">');
define('aut','<div class="aut">');
define('razdel','<div class="razdel">');
define('razdel1','<div class="razdel1">');
define('div','</div>');
}else{
define('copyr','');
define('citata','');
define('footer','');
define('hdrs','');
define('gb','');
define('gbinroom','');
define('links','');
define('menu','');
define('main','');
define('aut','');
define('razde','');
define('razdel','');
define('div','<br/>');
}


// Собственно верх
function head ()
{
global $db,$them, $title, $set, $align, $ver, $user, $_GET, $head, $fs1, $fs2;
if (empty($head)) $head = $title;
$title = $set['name'].'|'.$title;
if ($ver!='wml'){
// Если стиль не WEB
if(!isset($set['Reply_to'])) $set['Reply_to'] = NULL;
if (!isset($user)||$them != 'WEB'){
header("Expires: Mon, 6 Jul 2012 12:00:00 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");

header("Content-type:text/html; charset=utf-8");
echo '<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" lang="ru">
<head><meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8"/>
<link rel="shortcut icon" href="/favicon.ico" />
<meta name="yandex-verification" content="686ade4c98a4eb7c" />
<meta name="google-site-verification" content="EHizmI2bQt5A3TUG9LrKZgCpTN9R8SULPMx5Qo7GaSs" />
<meta name="copyright" content="'.$set['copyright'].'" />
<Meta name="author" Content="'.$set['author'].'">
<Meta name="Reply-to" Content="'.$set['Reply_to'].'">
<Meta name="description" Content="'.$set['description'].'">
<Meta name="keywords" Content="'.$set['keywords'].'">';
echo '<link rel="stylesheet" type="text/css" href="/style/'.$them.'.css"/>
<title>'.$title.'</title>';

if (isset($user)){
if (isset($_GET['rm']) && $_GET['rm'] != ''){
$rm = intval($_GET['rm']);
if ($user['avr']==0){ echo "<meta http-equiv=\"Pragma\" content=\"no-cache\"/><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>";
}else{ echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"".$user['avr']."; URL=".H."room?rm=$rm&amp;".SID."\">";}
}else{
echo '<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/>';
}
}else{
echo '<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/>';
}
echo '</head><body>';
if (isset($user)){
$pr_n = $db->sql_fetchfield($db->sql_query("select count(*) as num from privat where to_id = '".$user['id']."' and `readin` = '0'"),0);
if ($pr_n>0)echo menu.'<center><img src="/img/new.gif" alt="*"/> <b><a href="/my/privat?mod=in">Вам письмо('.$pr_n.')</a></b></center>'.div;
if($user['level']>=5)
{
$spam = $db->sql_fetchfield($db->sql_query("select count(*) as num from spamus where `read` = '0'"),0);
if ($spam>0)echo menu.'<img src="/img/new.gif" alt="*"/> <b><a href="/admin/spamer.php">Спам(+'.$spam.')</a></b>'.div;
}
}
echo '<div class="hdrs">'.$fs1.$head.$fs2.'</div><div class="main" align="'.$align.'">';

}else{
require_once'web.php'; // Подключаем верх WEB стиля
}


echo $fs1;
}else{

header("Content-type: text/vnd.wap.wml; charset=utf-8");
echo '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml12.dtd"><wml>';
if (isset($user)){
$pr_n = $db->sql_fetchfield($db->sql_query("select count(*) as num from privat where to_id = '".$user['id']."' and `readin` = '0'"),0);
if ($pr_n>0)echo menu.'<img src="/img/new.gif" alt="*"/> <b><a href="/my/privat?mod=in">Вам письмо('.$pr_n.')</a></b>'.div;
}
echo "<card id=\"chat\" title=\"".$title."\">";
echo "<p align=\"".$align."\">";
echo $fs1;

}

}


// Низ
function foot()
{
global $db,$them,$title,$set,$align,$ver,$user,$_GET,$Content_Encoding,$theme,$ip,$ua,$starttime,$pagesize,$fs2,$copy,$copir,$debag;

mysql_query("UPDATE `users` SET `location` = '$title', `location_ref` = 'http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]."' WHERE `id` = '$user[id]'");


$pagesize=round((ob_get_length())/1024,1);




if (isset($user))$db->sql_query ("Update users set alltraf='".($user["alltraf"]+$pagesize)."', lasttraf='".$pagesize."' where id='".$user['id']."'");

// Подключаем низ WEB стиля
if (isset($user) && $ver!='wml' && $them == 'WEB')
{
require_once'webf.php';

echo $fs2;
if ($ver!='wml')echo '</div></body></html>';
else echo '</p></card></wml>';

}else{

//echo copyr.'['.$pagesize.' Кб|'.$debag->endTimer().' сек]'.div;

#############################################################
if ($ver=='xhtml'){ 
echo '</div>';
echo copyr.'<center>[<a href="?'.$inv_url.'&amp;ver=wml">wml </a> | xhtml]</center>'.div;

}else{
echo '<center>[<a href="?'.$inv_url.'&amp;ver=xhtml">xhtml</a> | wml]</center><br/>';
}

if (isset($_GET['ver']))
{
$ver=check($_GET['ver']);
$db->sql_query ("Update users set ver='".$ver."' where id='".$user['id']."'");
header ('Location: ?'.SID);
exit;
}
#############################################################

///echo "Кликни>>><a href='http://v7traf.ru/3528.rub'>Раздел 18+</a><<<Кликни<br/>";
echo $fs2;
if ($ver!='wml')echo '</body></html>';
else echo '</p></card></wml>';
}
exit;
ob_end_flush();
}



/*
if($ver != 'wml')
{
	if(!isset($_SESSION['scr']))
	{
		//размер экрана
		// проверяем существование переменных $width и $height
		if (isset($_GET['width']) AND isset($_GET['height']))
		// если переменные существуют, выполняем код между фигурными скобками
		{
			// выводим полученные значения на экран
			$_SESSION['scr'] = check($_GET['width']).'X'.check($_GET['height']);
		} // если переменные не существуют, выполняем следующее
		else 
		{
		// PHP сгенерирует код JavaScript, который обработает браузер 
		// пользователя и передаст значения обратно PHP-скрипту через протокол HTTP
		 echo "<script language='javascript'>\n"; 
		 echo " location.href=\"${_SERVER['SCRIPT_NAME']}?${_SERVER['QUERY_STRING']}" 
			  . "&width=\" + screen.width + \"&height=\" + screen.height;\n"; 
		 echo "</script>\n"; 
		 exit(); 
		} 
	}
}
/*


if($ver != 'wml'){

$size = (isset($_SESSION['size']))?$_SESSION['size']:'не знаю';
echo 'Разрешение экрана - '. $size;?>
<script language=JavaScript>
document.write("<img style='visibility:hidden' src='get-screen.php?"+screen.width+"x"+screen.height+"'/>");
</script>
<?php

	if (!isset($_POST['screen']) and $_SESSION['scr'] == '') { 
		?> 
		<form action="" method="post"> 
		<script language="javascript"> 
		document.write ('<input name="screen" type="hidden" value="'+ screen.width +'x'+screen.height + '"></form>'); 
		document.forms[0].submit(); 
		</script>
		<?php 
		} 
	if (isset($_POST['screen'])) 
	{
		$_SESSION['scr'] = check($_POST['screen']);
	}
}else{$_SESSION['scr'] = '0x0';} */


?>