<?php
##########################################
# ~ Разработка отдельных модулей ~~~~~~~ #
# ~ и написание скриптов на php (c)KoT ~ #
# ~ ICQ: 7675072 ~~~~~~~~~~~~~~~~~~~~~~~ #
# ~ Site: 4atlove.ru ~~~~~~~~~~~~~~~~~~~ #
# ~ E-mail: notefree@bk.ru ~~~~~~~~~~~~~ #
##########################################

require'config.php';
aut();
$title='Меню бара';
head();
$rm = isset($_GET['rm']) ? (int)$_GET['rm'] : 0;
$rooms = $db->sql_fetchrow($db->sql_query("SELECT * FROM `rooms` WHERE `rm` = '$rm'"));
if($rooms['bot_bartender']!=1) header('Location: enter?').exit;
$toUrl = '&amp;rm='.$rm.'&amp;';

switch($_GET['mod']) {
	//Список разделов
	default:
	$sql = mysql_query("SELECT *,(SELECT COUNT(*) FROM bot_bartender_product WHERE bot_bartender_product.cat_id = bot_bartender_cat.id ) AS count FROM bot_bartender_cat");
	while(false != ($res = mysql_fetch_assoc($sql))){
		echo '&raquo; <a href="list_drink.php?mod=show&amp;cat_id='.$res['id'].$toUrl.'">'.$res['name'].'</a> ('.$res['count'].') <br/>';
	}
	echo 'Для заказа стриптиза используйте любую из команд:<br /><b>!стрип, !стриптиз, !strip или !striptiz</b><br /> Цена заказа 100руб.';
    break;

    //Список  товаров
    case 'show':
    if(!isset($_GET['cat_id'])) header('Location: list_drink.php?');
    $cat_id = (int)$_GET['cat_id'];
    $cat = mysql_fetch_assoc(mysql_query("SELECT name FROM bot_bartender_cat WHERE id = '$cat_id'"));
    if(!isset($cat['name'])) header('Location: list_drink.php?');
    echo '<div align="center"><b>'.$cat['name'].'</b></div>';
	//Список  напитков
	$count = mysql_result(mysql_query("SELECT COUNT(*) FROM bot_bartender_product WHERE cat_id = '$cat_id'"), 0);
	if($count){
		include 'class/navigator.php';
		$n = new navigator($count, 5, 'list_drink.php?mod=show&amp;cat_id='.$cat_id.$toUrl.'&amp;');
		$sql = mysql_query("SELECT * FROM bot_bartender_product WHERE cat_id = '$cat_id' {$n->limit}");
		while(false != ($res = mysql_fetch_assoc($sql))){
			if(is_file('upload/bot_bartender/'.$res['id'].'.img')){
				echo '<img src="utils/resize.php?img=upload/bot_bartender/'.$res['id'].'.img&width=100&height=0" alt="" /><br />';
			}
			echo '
			<b>!'.$res['name'].'</b><br />
			Цена: '.$res['price'].'$<br />
			'.($res['alcohol']>0 ? '+ '.$res['alcohol'] : '- '.abs($res['alcohol'])).'%<hr />';
		}
		echo $n->navi();
	} else echo 'Раздел пуст...<br />';
	echo '&raquo; <a href="list_drink.php?'.$toUrl.'&amp;">Назад</a>';
    break;

    //Угощение
    case 'for_friend':
    if (!isset($_GET['friend_id'])) header('Location: list_drink.php?').exit;
    $friend_id = (int)$_GET['friend_id'];
    if (isset($_GET['ok'])) {

    	$us = mysql_fetch_assoc(mysql_query("SELECT * FROM users WHERE id = '$friend_id'"));
		$alk = mysql_fetch_assoc(mysql_query("SELECT * FROM bot_bartender_product WHERE id = '".(int)$_GET['ok']."'"));

		$us['alcohol'] += $alk['alcohol'];
    	if (!$us['id']) {
    		echo 'Такого юзера нет';
    	} elseif (!$alk['id']) {
    		echo 'Такого напитка нет';
    	} elseif ($alk['price'] > $user['rur']) {
    		echo 'У вас не хватает денег';
    	} elseif ($us['alcohol'] > 100) {
    		echo '<font color="#FF0000">Он слишком пьян для этого напитка!</font>';
    	} else {
			mysql_query("UPDATE users SET rur = rur-'" .$alk['price'] . "' WHERE id = '" . $user['id'] . "'");
			mysql_query("UPDATE users SET alcohol = '".$us['alcohol']."' WHERE id = '" . $us['id'] . "'");
			include 'class/bot_bartender.php';
			$botB = new bot_bartender($user['alcohol'], $user['rur'], $user['id']);
            $botRow = mysql_fetch_assoc(mysql_query("SELECT * FROM users WHERE id = '" . $botB->config['id_bot'] . "'"));
			$img = is_file('upload/bot_bartender/'.$alk['id'].'.img') ? ' <img src="utils/resize.php?img=upload/bot_bartender/'.$alk['id'].'.img&width=100&height=0" alt="" />' : '';
            $msg = '<b>'.$user['user'].'</b> заказал для <b>'.$us['user'].'</b> '.$alk['name'].$img.', заказ выполнен! <b>Тост</b> '.$botB->toast();
			mysql_query("
				INSERT INTO message SET
					user = 'Бармен',
					user_id = '0',
					time = '".(time()+1)."',
					msg = '$msg',
					rm = '$rm',
					emo = '0',
					bb = '0',
					color = '0'
			");
			$botB = new bot_bartender($us['alcohol'], $us['money'], $us['id']);
			$botB->team = '<b>'.$user['user'].'</b> угостил: '.$alk['name'];
            $botB->setLog();
			header('Location: room.php?&rm='.$rm);
    	}
    }

    echo '<div class="c4">Чем будешь угощать?</div><br/>';
	//Список  напитков
	$count = mysql_result(mysql_query("SELECT COUNT(*) FROM bot_bartender_product WHERE  alcohol > 0"), 0);
	if ($count) {
		include 'class/navigator.php';
		$n = new navigator($count, 5, 'list_drink.php?mod=for_friend&amp;'.$toUrl.'&amp;friend_id='.$friend_id.'&amp;');
		$sql = mysql_query("SELECT * FROM bot_bartender_product WHERE alcohol > 0 {$n->limit}");
		while(false != ($res = mysql_fetch_assoc($sql))) {
			if (is_file('upload/bot_bartender/'.$res['id'].'.img')) {
				echo '<img src="utils/resize.php?img=upload/bot_bartender/'.$res['id'].'.img&width=100&height=0" alt="" /><br />';
			}
			echo '
			<b>!'.$res['name'].'</b><br />
			Цена: '.$res['price'].'$ '.($res['price'] > $user['rur'] ? '<small>[Недостаточно денег]</small>' : '<a href="list_drink.php?mod=for_friend&amp;'.$toUrl.'&amp;friend_id='.$friend_id.'&amp;ok='.$res['id'].'">Купить</a>').'<br />
			'.($res['alcohol']>0 ? '+ '.$res['alcohol'] : '- '.abs($res['alcohol'])).'%<hr />';
		}
		echo $n->navi();
	} else echo 'Пусто...<br />';
	echo '&raquo; <a href="list_drink.php?'.$toUrl.'&amp;">Назад</a>';
    break;
}
echo gbinroom.'
 <a href="room?'.$toUrl.'">В чат</a><br/>
 <a href="enter">Прихожая</a>
 '.div;
foot();
?>