<?php
include_once '../sys/inc/start.php';
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/user.php';
$set['title']='Бармен онлайн';
include_once '../sys/inc/thead.php';
title();
aut();

if(!isset($user)){
  echo "Вы не зарегистрированы";
  include_once '../sys/inc/tfoot.php';
  break;
}

include_once 'inc/start.php';

if(isset($_GET['id'])){
	
	$id=abs(intval($_GET['id']));
	
	if(mysql_result(mysql_query("SELECT COUNT(*) FROM `bar_ingridient` WHERE `id`='".$id."'"),0)!=0){
		if($bar_user['money']>=mysql_result(mysql_query("SELECT `cost` FROM `bar_ingridient` WHERE `id`='".$id."'"),0)){
		
			mysql_query("UPDATE `bar_user` SET `money`=`money`-".mysql_result(mysql_query("SELECT `cost` FROM `bar_ingridient` WHERE `id`='".$id."'"),0)." WHERE `id_u`='".$user_id."'");
			
			if(mysql_result(mysql_query("SELECT COUNT(*) FROM `bar_my_ingridient` WHERE `id_u`='".$user_id."' AND `id_i`='".$id."'"),0)==0)
			mysql_query("INSERT INTO `bar_my_ingridient`(`id_u`,`id_i`,`col`) VALUES('".$user_id."','".$id."','5')");
			else
			mysql_query("UPDATE `bar_my_ingridient` SET `col`=`col`+5 WHERE `id_u`='".$user_id."' AND `id_i`='".$id."'");
		
			bar_msg($diz['msg'],'Покупка успешно осуществлена');
		}
		else
		bar_msg($diz['msg'],'У вас не хватает денег');
	}
	else
		bar_msg($diz['msg'],'Ошибка');
}
			
echo "
<div class='".$diz['main']."'>

<img src='i/4.png' /> ".$bar_user['level']."
<img src='i/exp.png' /> ".$bar_user['exp']."
<img src='i/d.png' /> ".$bar_user['money']."
<br/><img src='i/bottle.png' />".$bar_user['alc']." ".nap($bar_user['alc'])."
<div class='".$diz['title2']."'>Магазин</div>
<center><img src='i/shop.gif' /></center>


<div class='".$diz['title2']."'>Товары</div>";
$total=mysql_result(mysql_query("SELECT COUNT(*) FROM `bar_ingridient`"),0);
$quert=mysql_query("SELECT * FROM `bar_ingridient` ORDER BY `id` ASC LIMIT ".$start.",5");

while($array=mysql_fetch_array($quert)){

echo '<table cellpadding="0">
<tr>
<td style="border: 2px solid #0090C4;
background-color: #fff;
height:48px;
width:48px;" align="center">
<img src="i/i_'.$array['id'].'.png" alt="." />
</td>
<td>

 '.$array['name'].'(5 шт.)
<br/>
 В баре: '.intval(mysql_result(mysql_query("SELECT `col` FROM `bar_my_ingridient` WHERE `id_u`='".$user_id."' AND `id_i`='".$array['id']."'"),0)).'<br/>
 <a href="shop.php?id='.$array['id'].'&amp;start='.$start.'">Купить за
 <img src="i/mmoney.png" alt="." />
 '.$array['cost'].'</a>
</td></tr></table>';
}



if ($total > 5) {
    echo bar_pagenav('shop.php?', $start, $total, 5);
   }
   
echo "</div>";
ret($diz['ret'],'Мой бар','index.php');
 include_once '../sys/inc/tfoot.php';
?>
