Рефакторинг, очистка, работа над ошибками, связанными с базой, отказ от глобальной переменной $user во многих файлах.
Singleton в некоторых местах вместо решения #42. Новые шаги для решения #16 и #52. Closes #42. Closes #32. Closes #31.
This commit is contained in:
+22
-31
@@ -4,8 +4,7 @@ use Battles\Template;
|
||||
use Battles\User;
|
||||
|
||||
require_once 'config.php';
|
||||
$user = User::$current;
|
||||
$hostel = mysql_fetch_array(mysql_query('SELECT `id`, `uid`, `type`, `time` FROM `hostel` WHERE `uid` = "' . $user['id'] . '" LIMIT 1'));
|
||||
$hostel = mysql_fetch_array(mysql_query('SELECT `id`, `uid`, `type`, `time` FROM `hostel` WHERE `uid` = "' . User::getInstance()->getId() . '" LIMIT 1'));
|
||||
$error = '';
|
||||
$rs = '';
|
||||
$base = [1 => ['type' => 'Сумка'], 2 => ['type' => 'Сундук'], 3 => ['type' => 'Комната'], 4 => ['type' => 'Амбар']];
|
||||
@@ -52,7 +51,7 @@ function select_arenda($u, $type, $redirect = false)
|
||||
|
||||
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'] . '"');
|
||||
mysql_query('UPDATE `users`,`online` SET `users`.`room` = 26, `online`.`room` = 26 WHERE `users`.`id` = "' . User::getInstance()->getId() . '" AND `online`.`id` = "' . User::getInstance()->getId() . '"');
|
||||
header('Location: city.php');
|
||||
} else {
|
||||
$error = 'Вы спите ...';
|
||||
@@ -62,7 +61,7 @@ if ($_GET['exit'] == 1) {
|
||||
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'] . '"');
|
||||
mysql_query('UPDATE `users`,`online` SET `users`.`room` = 661, `online`.`room` = 661 WHERE `users`.`id` = "' . User::getInstance()->getId() . '" AND `online`.`id` = "' . User::getInstance()->getId() . '"');
|
||||
header('Location: hostel_room.php');
|
||||
} else {
|
||||
$error = 'У Вас просрочена аренда. Оплатите что-бы продолжить пользоваться нашими услугами ...';
|
||||
@@ -74,12 +73,12 @@ if ($_GET['to_room'] == 1) {
|
||||
|
||||
if ($_GET['pays'] && (int)$_GET['pays'] >= 1 && (int)$_GET['pays'] <= 4) {
|
||||
if (isset($hostel['id'])) {
|
||||
if ($user['money'] >= $cost[$hostel['type']][(int)$_GET['pays']]) {
|
||||
if (User::getInstance()->getMoney() >= $cost[$hostel['type']][(int)$_GET['pays']]) {
|
||||
$time = $hostel['time'] + 60 * 60 * 24 * $times[(int)$_GET['pays']];
|
||||
$user['money'] -= $cost[$hostel['type']][(int)$_GET['pays']];
|
||||
User::getInstance()->setMoney(User::getInstance()->getMoney() -= $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');
|
||||
mysql_query('UPDATE `users` SET `money` = "' . User::getInstance()->getMoney() . '" WHERE `id` = "' . User::getInstance()->getId() . '" LIMIT 1');
|
||||
mysql_query('UPDATE `hostel` SET `time` = "' . $time . '" WHERE `uid` = "' . User::getInstance()->getId() . '" AND `id` = "' . $hostel['id'] . '" LIMIT 1');
|
||||
$error = 'Всё прошло успешно ...';
|
||||
} else {
|
||||
$error = 'Недостаточно денег ...';
|
||||
@@ -93,14 +92,14 @@ if (isset($_POST['select']) && isset($_POST['tariff'])) {
|
||||
if ($_POST['tariff'] == 0) {
|
||||
$error = 'Выберите тариф ...';
|
||||
} else {
|
||||
$error = select_arenda($user, (int)$_POST['tariff']);
|
||||
$error = select_arenda(User::getInstance(), (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']);
|
||||
mysql_query('DELETE FROM `hostel` WHERE `uid` = "' . User::getInstance()->getId() . '" AND `id` = "' . $hostel['id'] . '" LIMIT 1');
|
||||
remove_hostel_items(User::getInstance()->getId());
|
||||
$error = 'Вы успешно отказались от аренды ...';
|
||||
unset($hostel);
|
||||
} elseif (isset($hostel['id']) && $hostel['time'] < time()) {
|
||||
@@ -110,9 +109,9 @@ if ($_GET['del'] == 1) {
|
||||
|
||||
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);
|
||||
mysql_query('DELETE FROM `hostel` WHERE `uid` = "' . User::getInstance()->getId() . '" AND `id` = "' . $hostel['id'] . '" LIMIT 1');
|
||||
remove_hostel_items(User::getInstance()->getId());
|
||||
select_arenda(User::getInstance(), (int)$_POST['retariff'], true);
|
||||
} elseif (isset($hostel['id']) && $hostel['time'] < time()) {
|
||||
$error = 'Нельзя сменить услугу если имеется задолежнность ...';
|
||||
}
|
||||
@@ -120,21 +119,13 @@ if (isset($_POST['deselect']) && isset($_POST['retariff'])) {
|
||||
|
||||
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');
|
||||
$sl = 2;
|
||||
mysql_query('UPDATE `users` SET `sleep` = "' . (time() + 60 * 60 * $sl) . '", `sleep_time` = "' . (time() + 60 * 60 * 8) . '" WHERE `id` = "' . User::getInstance()->getId() . '" LIMIT 1');
|
||||
mysql_query('INSERT INTO `effects` (`type`, `name`, `time`, `owner`) VALUES ("8", "Сон", "' . (time() + 60 * 60 * $sl) . '", "' . User::getInstance()->getId() . '")');
|
||||
$ef = mysql_query('SELECT `id`, `time`, `type` FROM `effects` WHERE `owner` = "' . User::getInstance()->getId() . '" 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'] . '"');
|
||||
mysql_query('UPDATE `effects` SET `sleep` = "' . $tm . '" WHERE `id` = "' . $pl['id'] . '" AND `owner` = "' . User::getInstance()->getId() . '"');
|
||||
}
|
||||
header('Location: hostel.php');
|
||||
} else {
|
||||
@@ -143,12 +134,12 @@ if ($_GET['sleep'] && $user['sleep'] == 0) {
|
||||
}
|
||||
|
||||
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');
|
||||
mysql_query('UPDATE `users` SET `sleep` = "0" WHERE `id` = "' . User::getInstance()->getId() . '" LIMIT 1');
|
||||
mysql_query('DELETE FROM `effects` WHERE `owner` = "' . User::getInstance()->getId() . '" AND `type` = "8" LIMIT 1');
|
||||
$ef = mysql_query('SELECT `id`, `time`, `sleep` FROM `effects` WHERE `owner` = "' . User::getInstance()->getId() . '" 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'] . '"');
|
||||
mysql_query('UPDATE `effects` SET `time` = "' . $tm . '", `sleep` = "0" WHERE `id` = "' . $pl['id'] . '" AND `owner` = "' . User::getInstance()->getId() . '"');
|
||||
}
|
||||
header('Location: hostel.php');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user