<?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=\'#7c860e\'>$nick</font>";
	$nicksup = "<img src=\'img/barinfo.png\' alt=\'.\' /><font color=\'#ffbf00\'>$nick</font>";
	$nickgon = "$nick";
	$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">$2</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'];
	$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`) VALUES('$nicksoz','$msg','$datemsg','$avatar','$data_user_id')") or die(mysql_error());
		header("Location: bar.php?");
		exit();
	}elseif($data_user['status'] == "Админ"){
		mysql_query("INSERT INTO bar(`nick`,`msg`,`date`,`avatar`,`id_user`) VALUES('$nickadmin','$msg','$datemsg','$avatar','$data_user_id')") or die(mysql_error());
		header("Location: bar.php?");
		exit();
	}elseif($data_user['status'] == "Модератор"){
		mysql_query("INSERT INTO bar(`nick`,`msg`,`date`,`avatar`,`id_user`) VALUES('$nickmoder','$msg','$datemsg','$avatar','$data_user_id')") 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`) VALUES('$nickvip','$msg','$datemsg','$avatar','$data_user_id')") or die(mysql_error());
		header("Location: bar.php?");
		exit();
	}elseif($data_user['status'] == "Помощник"){
		mysql_query("INSERT INTO bar(`nick`,`msg`,`date`,`avatar`,`id_user`) VALUES('$nicksup','$msg','$datemsg','$avatar','$data_user_id')") or die(mysql_error());
		header("Location: bar.php?");
		exit();
	}else{
		mysql_query("INSERT INTO bar(`nick`,`msg`,`date`,`avatar`,`id_user`) VALUES('$nickgon','$msg','$datemsg','$avatar','$data_user_id')") or die(mysql_error());
		header("Location: bar.php?");
		exit();
		}
	}
	}
}
if(isset($_GET['money1'])){
	$resm_obmen1 = abs($data_user['money'])+1000;
	$resm_obm1 = abs($data_user['money2'])-1;
	if(abs($data_user['money2'])< 1){
		$err = "Парень,меня не обманешь!";
	}else{
	$obmenka1 = mysql_query("UPDATE users SET money='".$resm_obmen1."', money2='".$resm_obm1."' WHERE nick='".$_SESSION['user']."'") or die(mysql_error());
	if($obmenka1 == true){
		$obmenka1 = "<center>С тобой приятно иметь дело,Паренек!</center>";
	}
	}
}

if(isset($_GET['money2'])){
	$resm_obmen2 = abs($data_user['money'])+6000;
	$resm_obm2 = abs($data_user['money2'])-5;
	if(abs($data_user['money2'])< 5){
		$err = "Парень,меня не обманешь!";
	}else{
	$obmenka2 = mysql_query("UPDATE users SET money='".$resm_obmen2."', money2='".$resm_obm2."' WHERE nick='".$_SESSION['user']."'") or die(mysql_error());
	if($obmenka2 == true){
		$obmenka2 = "<center>С тобой приятно иметь дело,Паренек!</center>";
	}
	}
}

if(isset($_GET['money3'])){
	$resm_obmen3 = abs($data_user['money'])+14000;
	$resm_obm3 = abs($data_user['money2'])-10;
	if(abs($data_user['money2'])< 10){
		$err = "Парень,меня не обманешь!";
	}else{
	$obmenka3 = mysql_query("UPDATE users SET money='".$resm_obmen3."', money2='".$resm_obm3."' WHERE nick='".$_SESSION['user']."'") or die(mysql_error());
	if($obmenka3 == true){
		$obmenka3 = "<center>С тобой приятно иметь дело,Паренек!</center>";
	}
	}
}
if(isset($_GET['money4'])){
	$resm_obmen4 = abs($data_user['money'])-18000;
	$resm_obm4 = abs($data_user['money2'])+10;
	if(abs($data_user['money'])< 18000){
		$err = "Парень,меня не обманешь!";
	}else{
	$obmenka4 = mysql_query("UPDATE users SET money='".$resm_obmen4."', money2='".$resm_obm4."' WHERE nick='".$_SESSION['user']."'") or die(mysql_error());
	if($obmenka4 == true){
		$obmenka4 = "<center>С тобой приятно иметь дело,Паренек!</center>";
	}
	}
}
if(isset($_GET['money5'])){
	$resm_obmen5 = abs($data_user['money'])-170000;
	$resm_obm5 = abs($data_user['money2'])+100;
	if(abs($data_user['money'])< 170000){
		$err = "Парень,меня не обманешь!";
	}else{
	$obmenka5 = mysql_query("UPDATE users SET money='".$resm_obmen5."', money2='".$resm_obm5."' WHERE nick='".$_SESSION['user']."'") or die(mysql_error());
	if($obmenka5 == true){
		$obmenka5 = "<center>С тобой приятно иметь дело,Паренек!</center>";
	}
	}
}
include 'head.php';
?>
<div class="title">Барыга</div>
<?php
if($obmenka1){
	echo "<table class='wdt msg'>
<tr>
	<td><img src='style/$data_user[theme]/icon/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> $obmenka1 </b>
	</td>
</tr>
</table>";
}
elseif($obmenka2){
	echo "<table class='wdt msg'>
<tr>
	<td><img src='style/$data_user[theme]/icon/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> $obmenka2 </b>
	</td>
</tr>
</table>";
}
elseif($obmenka3){
	echo "<table class='wdt msg'>
<tr>
	<td><img src='style/$data_user[theme]/icon/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> $obmenka3 </b>
	</td>
</tr>
</table>";
}
elseif($obmenka4){
	echo "<table class='wdt msg'>
<tr>
	<td><img src='style/$data_user[theme]/icon/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> $obmenka4 </b>
	</td>
</tr>
</table>";
}
elseif($obmenka5){
	echo "<table class='wdt msg'>
<tr>
	<td><img src='style/$data_user[theme]/icon/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> $obmenka5 </b>
	</td>
</tr>
</table>";
}elseif($err){
echo "<table class='wdt msg'>
<tr>
	<td><img src='style/$data_user[theme]/icon/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;'><center><b>Эй,Парень! Я тут проездом.<br>Валютку обменять?</b></center>
	</td>
</tr>
</table>";
}
?>
<div class="karo"><center><b>Золото на серебро</b></center></div>
<div class="mono"><center>1 золотой на 1.000 серебра.<br>
<a href="obmen.php?money1"><input type="submit" value="Обменять" class="btn2" /></a></center>
</div>
<div class="mono"><center>5 золотых на 6.000 серебра.<br>
<a href="obmen.php?money2"><input type="submit" value="Обменять" class="btn2" /></a></center>
</div>
<div class="mono"><center>10 золотых на 14.000 серебра.<br>
<a href="obmen.php?money3"><input type="submit" value="Обменять" class="btn2" /></a></center>
</div>
<div class="karo"><center><b>Серебро на золото</b></center></div>
<div class="mono"><center>18.000 серебра на 10 золота.<br>
<a href="obmen.php?money4"><input type="submit" value="Обменять" class="btn2" /></a></center>
</div>
<div class="mono"><center>170.000 серебра на 100 золота.<br>
<a href="obmen.php?money5"><input type="submit" value="Обменять" class="btn2" /></a></center>
</div>
<?
include 'foot.php';
?>