session_start(); if(!isset($_SESSION['uid'])) { header('Location: index.php'); die(); } include('config.php'); $user = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `id` = "'.$_SESSION['uid'].'" LIMIT 1')); $hostel = mysql_fetch_array(mysql_query('SELECT `id`, `uid`, `type`, `time` FROM `hostel` WHERE `uid` = "'.$user['id'].'" LIMIT 1')); #include('functions.php'); $error = ''; $rs = ''; $base = array(1 => array('type' => 'Сумка'), 2 => array('type' => 'Сундук'), 3 => array('type' => 'Комната'), 4 => array('type' => 'Амбар')); $times = array(1 => 7, 2 => 14, 3 => 21, 4 => 28); $cost = array(1 => array(8, 16, 24, 32), 2 => array(15, 30, 45, 60), 3 => array(25, 50, 75, 100), 4 => array(40, 80, 120, 160)); function remove_hostel_items($u) { $itms = mysql_query('SELECT `id`, `owner` FROM `inventory` WHERE `owner` = "-101' . $u . '"'); while ($pl = mysql_fetch_array($itms)) { mysql_query('UPDATE `inventory` SET `owner` = "' . $u . '" WHERE `id` = "' . $pl['id'] . '" AND `owner` = "-101' . $u . '"'); } } function select_arenda($u, $type, $redirect = false) { $hostel = mysql_fetch_array(mysql_query('SELECT `id` FROM `hostel` WHERE `uid` = "' . $u['id'] . '" LIMIT 1')); $price = array(1 => 8, 2 => 15, 3 => 25, 4 => 40); if (!isset($u['id'])) { $r = 'Персонаж не найден ...'; } else { if ($type > 0 && $type <= 4) { if (isset($hostel['id'])) { $r = 'Не более 1 арендованного места ...'; } else { if ($u['money'] >= $price[$type]) { $u['money'] -= $price[$type]; mysql_query('UPDATE `users` SET `money` = "' . $u['money'] . '" WHERE `id` = "' . $u['id'] . '" LIMIT 1'); mysql_query('INSERT INTO `hostel` (`uid`, `type`, `time`) VALUES ("' . $u['id'] . '", "' . $type . '", "' . (time() + 60 * 60 * 24 * 7) . '")'); $r = 'Поздравляем с успешной арендой ...'; } else { $r = 'Недостаточно денег ...'; } } } else { $r = 'Неверный тип аренды ...'; } } if ($redirect == true) { header('Location: main.php'); } return $r; } if($_GET['exit'] == 1) { if($user['sleep'] == 0) { mysql_query('UPDATE `users`,`online` SET `users`.`room` = 26, `online`.`room` = 26 WHERE `users`.`id` = "'.$user['id'].'" AND `online`.`id` = "'.$user['id'].'"'); header('Location: city.php'); } else { $error = 'Вы спите ...'; } } if($_GET['to_room'] == 1) { if(isset($hostel['id'])) { if($hostel['time'] > time()) { mysql_query('UPDATE `users`,`online` SET `users`.`room` = 661, `online`.`room` = 661 WHERE `users`.`id` = "'.$user['id'].'" AND `online`.`id` = "'.$user['id'].'"'); header('Location: hostel_room.php'); } else { $error = 'У Вас просрочена аренда. Оплатите что-бы продолжить пользоваться нашими услугами ...'; } } else { $error = 'У Вас, нету комнаты ...'; } } if($_GET['pays']) { if((int)$_GET['pays'] >= 1 && (int)$_GET['pays'] <= 4) { if(isset($hostel['id'])) { if($user['money'] >= $cost[$hostel['type']][(int)$_GET['pays']]) { $time = $hostel['time']+60*60*24*$times[(int)$_GET['pays']]; $user['money'] -= $cost[$hostel['type']][(int)$_GET['pays']]; $hostel['time'] = $time; mysql_query('UPDATE `users` SET `money` = "'.$user['money'].'" WHERE `id` = "'.$user['id'].'" LIMIT 1'); mysql_query('UPDATE `hostel` SET `time` = "'.$time.'" WHERE `uid` = "'.$user['id'].'" AND `id` = "'.$hostel['id'].'" LIMIT 1'); $error = 'Всё прошло успешно ...'; } else { $error = 'Недостаточно денег ...'; } } else { $error = 'Ошибка #1'; } } } if(isset($_POST['select']) && isset($_POST['tariff'])) { if($_POST['tariff'] == 0) { $error = 'Выберите тариф ...'; } else { $error = select_arenda($user, (int)$_POST['tariff']); } } if($_GET['del'] == 1) { if(isset($hostel['id']) && $hostel['time'] > time()) { mysql_query('DELETE FROM `hostel` WHERE `uid` = "'.$user['id'].'" AND `id` = "'.$hostel['id'].'" LIMIT 1'); remove_hostel_items($user['id']); $error = 'Вы успешно отказались от аренды ...'; unset($hostel); } elseif(isset($hostel['id']) && $hostel['time'] < time()) { $error = 'Нельзя отказаться от услуг если имеется задолежнность ...'; } } if(isset($_POST['deselect']) && isset($_POST['retariff'])) { if(isset($hostel['id']) && $hostel['time'] > time()) { mysql_query('DELETE FROM `hostel` WHERE `uid` = "'.$user['id'].'" AND `id` = "'.$hostel['id'].'" LIMIT 1'); remove_hostel_items($user['id']); select_arenda($user, (int)$_POST['retariff'], true); } elseif(isset($hostel['id']) && $hostel['time'] < time()) { $error = 'Нельзя сменить услугу если имеется задолежнность ...'; } } if($_GET['sleep'] && $user['sleep'] == 0) { if($user['sleep_time'] <= time()) { if($user['vip'] == 1) { $sl = 8; } elseif($user['vip'] == 2) { $sl = 12; } elseif($user['vip'] == 3) { $sl = 18; } else { $sl = 2; } mysql_query('UPDATE `users` SET `sleep` = "'.(time()+60*60*$sl).'", `sleep_time` = "'.(time()+60*60*8).'" WHERE `id` = "'.$user['id'].'" LIMIT 1'); mysql_query('INSERT INTO `effects` (`type`, `name`, `time`, `owner`) VALUES ("8", "Сон", "'.(time()+60*60*$sl).'", "'.$user['id'].'")'); $ef = mysql_query('SELECT `id`, `time`, `type` FROM `effects` WHERE `owner` = "'.$user['id'].'" AND `type` != 11 AND `type` != 12 AND `type` != 13 AND `type` != 14 AND `type` != 5 AND `type` != 4 AND `type` != 2 AND `type` != 3 AND `type` != 8'); while($pl = mysql_fetch_array($ef)) { $tm = $pl['time']-time(); mysql_query('UPDATE `effects` SET `sleep` = "'.$tm.'" WHERE `id` = "'.$pl['id'].'" AND `owner` = "'.$user['id'].'"'); } header('Location: hostel.php'); } else { $error = 'Нельзя спать ... Приходите через : '.timeOut($user['sleep_time']-time()); } } if($_GET['unsleep'] && $user['sleep'] > 0) { mysql_query('UPDATE `users` SET `sleep` = "0" WHERE `id` = "'.$user['id'].'" LIMIT 1'); mysql_query('DELETE FROM `effects` WHERE `owner` = "'.$user['id'].'" AND `type` = "8" LIMIT 1'); $ef = mysql_query('SELECT `id`, `time`, `sleep` FROM `effects` WHERE `owner` = "'.$user['id'].'" AND `sleep` != 0'); while($pl = mysql_fetch_array($ef)) { $tm = time()+$pl['sleep']; mysql_query('UPDATE `effects` SET `time` = "'.$tm.'", `sleep` = "0" WHERE `id` = "'.$pl['id'].'" AND `owner` = "'.$user['id'].'"'); } header('Location: hostel.php'); } ?>