<?php
session_start();
include_once "inc/db_connect.php";
include_once "inc/fnc.php";
header('Content-Type: text/html;charset=utf8');
$err = "";
if(isset($_POST['regok'])){unset($_SESSION['reg_ok']);}
if(!isset($_SESSION['user'])){
header("Location: index.php?");
exit();
}else{
$data_user = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE nick='".$_SESSION['user']."'")) or die(mysql_error());
if(isset($_POST['msgok'])){
$nick = $data_user['nick'];
$nicksoz = "<img src=\'img/soz.png\' alt=\'.\' /><font color=\'#FF0000\'>$nick</font>";
$nickadmin = "<img src=\'img/admin.png\' alt=\'.\' /><font color=\'#3f3f3f\'>$nick</font>";
$nickmoder = "<img src=\'img/moder.png\' alt=\'.\' /><font color=\'#2e7dc7\'>$nick</font>";
$nickvip = "<img src=\'img/vip.png\' alt=\'.\' /><font color=\'#000000\'>$nick</font>";
$nicksup = "<img src=\'img/barinfo.png\' alt=\'.\' /><font color=\'#003399\'>$nick</font>";
$nicktur = "<img src=\'img/tur.png\' alt=\'.\' /><font color=\'ORANGE\'>$nick</font>";
$nickgon = "<font color=\'#0769ad\'>$nick</font>";
$msg = mysql_real_escape_string(strip_tags(stripslashes(htmlspecialchars($_POST['msg']))));
$msg = preg_replace("#\[b\](.*)\[\/b\]#isU", '<b>\\1</b>', $msg);
$msg = preg_replace("#\[i\](.*)\[\/i\]#isU", '<i>\\1</i>', $msg);
$msg = preg_replace("#\[u\](.*)\[\/u\]#isU", '<u>\\1</u>', $msg);
$msg = preg_replace("#\[img\](.*)\[\/img\]#isU", '<img src="\\1" width="100" height="100">', $msg);
$msg = preg_replace("/\[url=([^\]]+?)\](.+?)\[\/url\]/uis", "<a href=\"$1\" rel=\"nofollow\">$2</a>", $msg);
$msg = preg_replace("/\[color=(.*)\](.+?)\[\/color\]/uis", '<span style="color:$1">$20</span>', $msg);
$msg = str_replace(':D','<img src="smiles/d.gif" />',$msg);
$msg = str_replace(':-D','<img src="smiles/d.gif" />',$msg);
$msg = str_replace(':)','<img src="smiles/smile.gif" />',$msg);
$msg = str_replace(':-)','<img src="smiles/smile.gif" />',$msg);
$msg = str_replace(':-(','<img src="smiles/bad.gif" />',$msg);
$msg = str_replace(':(','<img src="smiles/bad.gif" />',$msg);
$msg = str_replace(':poh','<img src="smiles/poh.gif" />',$msg);
$msg = str_replace(':bravo','<img src="smiles/bravo.gif" />',$msg);
$msg = str_replace(':drink','<img src="smiles/drink.gif" />',$msg);
$msg = str_replace('lol','<img src="smiles/lol.gif" />',$msg);
$datemsg = date("H:i:s");
$data_user_id = $data_user['id'];
$mystatus = $data_user['mystatus'];
$avatar = $data_user['avatar'];
if($msg == "") {
header("Location: bar.php?");
exit();
}else{
if($data_user['status'] == "Создатель"){
mysql_query("INSERT INTO bar(`nick`,`msg`,`date`,`avatar`,`id_user`,`mystatus`) VALUES('$nicksoz','$msg','$datemsg','$avatar','$data_user_id','$mystatus')") or die(mysql_error());
header("Location: bar.php?");
exit();
}elseif($data_user['status'] == "Админ"){
mysql_query("INSERT INTO bar(`nick`,`msg`,`date`,`avatar`,`id_user`,`mystatus`) VALUES('$nickadmin','$msg','$datemsg','$avatar','$data_user_id','$mystatus')") or die(mysql_error());
header("Location: bar.php?");
exit();
}elseif($data_user['status'] == "Модератор"){
mysql_query("INSERT INTO bar(`nick`,`msg`,`date`,`avatar`,`id_user`,`mystatus`) VALUES('$nickmoder','$msg','$datemsg','$avatar','$data_user_id','$mystatus')") or die(mysql_error());
header("Location: bar.php?");
exit();
}elseif($data_user['status'] == "VIP"){
mysql_query("INSERT INTO bar(`nick`,`msg`,`date`,`avatar`,`id_user`,`mystatus`) VALUES('$nickvip','$msg','$datemsg','$avatar','$data_user_id','$mystatus')") or die(mysql_error());
header("Location: bar.php?");
exit();
}elseif($data_user['status'] == "Помощник"){
mysql_query("INSERT INTO bar(`nick`,`msg`,`date`,`avatar`,`id_user`,`mystatus`) VALUES('$nicksup','$msg','$datemsg','$avatar','$data_user_id','$mystatus')") or die(mysql_error());
header("Location: bar.php?");
exit();
}
elseif($data_user['status'] == "Турнирщик"){
mysql_query("INSERT INTO bar(`nick`,`msg`,`date`,`avatar`,`id_user`,`mystatus`) VALUES('$nicktur','$msg','$datemsg','$avatar','$data_user_id','$mystatus')") or die(mysql_error());
header("Location: /bar?");
exit();
}else{
mysql_query("INSERT INTO bar(`nick`,`msg`,`date`,`avatar`,`id_user`,`mystatus`) VALUES('$nickgon','$msg','$datemsg','$avatar','$data_user_id','$mystatus')") or die(mysql_error());
header("Location: bar.php?");
exit();
}
}
}
}
if(isset($_GET['coffee'])){
$resm_piv = abs($data_user['money'])-500;
$resm_eng = abs($data_user['fuel'])+10;
if(abs($data_user['money'])< 500){
$err = "Извини,но у тебя не хватает <img style='padding:0;margin:0;float:none;' src='img/money.png' alt='.' />";
}else{
$coffee = mysql_query("UPDATE users SET money='".$resm_piv."', fuel='".$resm_eng."' WHERE nick='".$_SESSION['user']."'") or die(mysql_error());
if($coffee == true){
$coffee = "<center><img src='img/coffee.png'>Держи свой напиток.<br>С тебя <font color='#23b900'>500</font> монет</center>";
}
}
}

if(isset($_GET['milk'])){
$resm_coc = abs($data_user['money2'])-2;
$resm_en = abs($data_user['fuel'])+100;
if(abs($data_user['money2'])< 2){
$err = "Извини,но у тебя не хватает <img style='padding:0;margin:0;float:none;' src='img/money2.png' alt='.' /> или ты набрал MAX число бензина.";
}else{
$energy = mysql_query("UPDATE users SET money2='".$resm_coc."', fuel='".$resm_en."' WHERE nick='".$_SESSION['user']."'") or die(mysql_error());
if($energy == true){
$energy = "<center><img src='img/milk.png'>Держи свой напиток.<br>С тебя <font color='#23b900'>2</font> золота</center>";
}
}
}
?>
<?
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
echo '<html>';
echo '<head>';
echo '<title>Лига скорости</title>';
echo '<meta http-equiv="Content-Type" content="text/html" charset="windows-1251" />';
echo '<meta name="description" content="Мобильные онлайн гонки">';
if(empty($data_user['theme']) or $data_user['theme'] == 'default')
{
$style="/style/default/mobile.css";
}
if($data_user['theme'] == "twotheme")
{
$style="style/twotheme/mobile.css";
}
echo '<link rel="stylesheet" href="'.$style.'" type="text/css" />';
?>
<div class="inform">
<div class="block"><img src="img/benz.png" alt="Бензин"/> <?=$data_user['fuel']?></div>
<div class="block"><img src="img/speed.png" alt="Скорость" /> <?=$data_user['speed']?> л.с</div>
<div class="block"><img src="img/money2.png" alt="Золото" /> <?=$data_user['money2']?></div>
<div class="block"><img src="img/money.png" alt="Баксы" /> <?=$data_user['money']?></div><br><br>
<div class="progress">
<div class="progress2" style="width:<?=$levelimg?>%">
</div></div>
</div>
<?
echo '<div class="inform"><center>';
        echo '<div class="block"><a href="index.php"><b>Гараж</b></a></div>';
        echo '<div class="block"><a href="/race.php"><b>Гонки</b></a></div>';
echo '<div class="block"><a href="/taxi.php"><b>Такси</b></a></div>';
echo '<div class="block"><a href="/city.php"><b>Город</b></a></div>';
echo '</center></div>';
?>
<div class="title">Бар</div>
<?php
if($energy){
echo "<table class='wdt msg'>
<tr>
<td><img src='img/info.png' alt='info' height='60'/></td>
<td style='vertical-align:top;padding:10px;border:2px dotted indigo;border-radius: 5px 5px 5px 5px;'><b> $energy </b>
</td>
</tr>
</table>";
}
elseif($coffee){
echo "<table class='wdt msg'>
<tr>
<td><img src='img/info.png' alt='info' height='60'/></td>
<td style='vertical-align:top;padding:10px;border:2px dotted indigo;-moz-border-radius:5px;
-webkit-border-radius:5px;'><b> $coffee </b>
</td>
</tr>
</table>";
}elseif($err){
echo "<table class='wdt msg'>
<tr>
<td><img src='img/info.png' alt='info' height='60'/></td>
<td style='vertical-align:top;padding:8px;border:2px dotted indigo;-moz-border-radius:5px;
-webkit-border-radius:5px;'><b> $err </b>
</td>
</tr>
</table>";
}else{
echo "<table class='wdt msg'>
<tr>
<td><img src='style/$data_user[theme]/icon/info.png' alt='info' height='50' width='50' /></td>
<td style='vertical-align:top;padding:10px;border:2px dotted indigo;-moz-border-radius:5px;
-webkit-border-radius:5px;'><b>Добро пожаловать в бар! Здесь ты можешь выпить напитки, а также пообщаться с другими гонщиками! Удачи.</b>
</td>
</tr>
</table>";
}
?>
<div class="title"><center><b>Сообщества в соц.сетях:<br>
<a href="http://m.vk.com/lowraceclub"><img src="img/vk.png" width="32" height="32"></a>
<a href="http://m.odnoklassniki.ru/dk?st.cmd=altGroupMain&st.groupId=52041674784959&_prevCmd=userAltGroups&tkn=899"><img src="img/ok.png" width="32" height="32"></a>
</b></center></div>
<table class="menu1 wdt">
<tr>
<td><a href="/rules.php" title="правила"><font color="#0769ad">Прочти правила игры</font></a></td>
</tr>
</table>
<div class="mono"><center><b>Чего брать будешь?</b></center></div>
<table width="100%" class="mono">
<tr>
<td>
<center>
<span style="float:left">
<b>Кофе</b><br><br>
<a href="bar.php?coffee">
<img src="img/coffee.png"/></a><br>
<img src="img/money.png"><font color='#0769ad'> 500 монет</font><br>
Добавляет<br>
<img src="img/benz.png"> 10
</span>
<span style="float:right">
<b>Кефир</b><br><br>
<a href="/bar.php?milk">
<img src="img/milk.png"/></a><br>
<img src="img/money2.png"><font color='#0769ad'> 2 золото</font><br>
Добавляет<br>
<img src="img/benz.png"> 100
</span>
</center>
</td></tr> 
</table>
<div class="menu"><center><b>Писать в чат можно только с 2 уровня</b></center></div>
<?
if($data_user['banned']!=0)
{
echo "<div class='menu'>";
echo' <center>Вы забанены.<br></center>';
echo' <center>ПРИЧИНА: <b>'.$data_user['prich'].'</b></center>';
echo "</div>";
echo "<div class='menu'>";
echo' <center>Теперь чат недоступен.<br></center>';
echo "</div>";
include 'foot.php';
exit;
}
if($data_user['level']>=2)
{
?>
<script language="javascript" type="text/javascript">
<!--
var ie=document.all?1:0;
var ns=document.getElementById&&!document.all?1:0;

function InsertSmile(SmileId)
{
if(ie)
{
document.all.message.focus();
document.all.message.value+=" "+SmileId+" ";
}

else if(ns)
{
document.forms['sms'].elements['msg'].focus();
document.forms['sms'].elements['msg'].value+=" "+SmileId+" ";
}

else
alert("Ваш браузер не поддерживается!");
}
//-->
</script>
<div class="title">
<a style="cursor: pointer;" onclick='InsertSmile(":D")'><img src='smiles/d.gif' alt='' / ></a>
<a style="cursor: pointer;" onclick='InsertSmile(":)")'><img src='smiles/smile.gif' alt='' /></a>
<a style="cursor: pointer;" onclick='InsertSmile(":(")'><img src='smiles/bad.gif' alt='' /></a>
<a style="cursor: pointer;" onclick='InsertSmile(":poh")'><img src='smiles/poh.gif' alt='' /></a>
<a style="cursor: pointer;" onclick='InsertSmile(":bravo")'><img src='smiles/bravo.gif' alt='' /></a>
<a style="cursor: pointer;" onclick='InsertSmile(":drink")'><img src='smiles/drink.gif' alt='' /></a>
<a style="cursor: pointer;" onclick='InsertSmile("lol")'><img src='smiles/lol.gif' alt='' /></a>
</div>
<div class="mono">
<center>
<form action="bar.php" method="post" name="sms">
Сообщение: <br/>
<script charset="utf-8" src="/js/bbcode.js" type="text/javascript"></script>  
<a href="javascript:bb_b('Site');" title="Жирный"><img src="img/b.gif" alt="b" /></a>  
<a href="javascript:bb_i('Site');" title="Курсив"><img src="img/i.gif" alt="i" /></a>  
<a href="javascript:bb_u('Site');" title="Подчеркивание"><img src="img/u.gif" alt="u" /></a><br/>
<textarea name='msg' id='Site' maxlength='180'></textarea><br/>
<center><input type="submit" name="msgok" value="Отправить" class="btn"> 
<input type="submit" name="" value="Обновить" class="btn"></center><br/>
<br />
</form>
</center></div>
<?
}

?>
<?php
include 'inc/nav.php';
nav::start( mysql_query("SELECT * FROM `bar`"));
$msg_user = mysql_query("SELECT * FROM `bar` ORDER BY `id` DESC ".nav::l()) or die(mysql_error());
$msg_row_user = mysql_fetch_array($msg_user);
$countmsgbar = mysql_num_rows($msg_user);
if($countmsgbar == 0){
echo "<div class='menu'><center><b>Чат пуст или был недавно очищен.</b></center></div>";
}else{
do{
?>
<table class="wdt msgbar">
<tr>
<td style='width:*;'>
<a href='/info.php?id=<?=$msg_row_user['id_user']?>'><font color='indigo'> 
<b>     
<?=$msg_row_user['nick']?>
</b>
</font></a><font color="blue">(<?=$msg_row_user['date']?>)</font> <a href='/cars.php?id=<?=$msg_row_user['id_user']?>'><img src="img/car.png"></a><br/>
<?=$msg_row_user['msg'];?><br /><br>
<font size="1"><i><?=$msg_row_user['mystatus'];?></i></font><br />

</td>
</tr>
</td>
</tr>
</table>
</div>
<?
}while($msg_row_user = mysql_fetch_array($msg_user));
}
nav::end();
include 'foot.php';
?>