diff --git a/zayavka.php b/zayavka.php
index 82369a2..220b65c 100644
--- a/zayavka.php
+++ b/zayavka.php
@@ -41,10 +41,11 @@ class Zayavka
* @var string
*/
private $errorMessage;
+ private $user;
function __construct($user_id)
{
-
+ $this->user = $user_id;
}
function fteam($team)
@@ -97,10 +98,8 @@ class Zayavka
public function addteam($team, $r)
{
- global $user;
$id = $_SESSION['uid'];
$zay = $_REQUEST['gocombat'];
- $error = null;
$owntravma = db::c()->query('SELECT `id`, `type` FROM `effects` WHERE (`type` = 12 OR `type` = 13) AND `owner` = ?i', $id)->fetch_assoc();
$z = $this->getlist($r, null, $zay);
if ($owntravma['type'] == 12 && ($z[$zay]['type'] != 4 && $z[$zay]['type'] != 5)) {
@@ -108,10 +107,10 @@ class Zayavka
} elseif ($owntravma['type'] == 13) {
$this->errorMessage = "У Вас тяжелая травма, Вы не сможете драться...";
}
- if (!empty($user['zayavka'])) {
+ if ($this->user->zayavka) {
$this->errorMessage = "Вы находитесь в заявке";
}
- if ($user['hp'] < $user['maxhp'] * 0.33) {
+ if ($this->user->health < $this->user->maxHealth * 0.33) {
$this->errorMessage = "Вы слишком ослаблены для боя, восстановитесь.";
}
if (!$z || !empty($this->user_status($id))) {
@@ -126,7 +125,7 @@ class Zayavka
foreach ($z[$zay]['team' . $teamz] as $v) {
$enemy = db::c()->query('SELECT `klan` FROM `users` WHERE `id` = ?i', $v)->fetch_assoc();
- if ($user['klan'] == $enemy['klan']) {
+ if ($this->user->clan == $enemy['klan']) {
$this->errorMessage = "Нельзя драться против сокланов!";
}
}
@@ -134,11 +133,11 @@ class Zayavka
if ($z[$zay]['t' . $team . 'min'] == 99) {
$toper = db::c()->query('SELECT `klan` FROM `users` WHERE `id` = ?i', $z[$zay]['team' . $team][0])->fetch_assoc();
- if ($user['klan'] != $toper['klan']) {
+ if ($this->user->clan != $toper['klan']) {
$this->errorMessage = "Эта заявка не может быть принята Вами.";
}
} else {
- if ($user['level'] > 0 && !($z[$zay]['t' . $team . 'min'] <= $user['level'] && $z[$zay]['t' . $team . 'max'] >= $user['level'])) {
+ if ($this->user->level > 0 && !($z[$zay]['t' . $team . 'min'] <= $this->user->level && $z[$zay]['t' . $team . 'max'] >= $this->user->level)) {
$this->errorMessage = "Эта заявка не может быть принята Вами. - " . $z[$zay]['t' . $team . 'min'];
}
}
@@ -177,8 +176,6 @@ class Zayavka
public function addzayavka($start, $timeout, $t1c, $t2c, $type, $t1min, $t2min, $t1max, $t2max, $coment, $level, $blood = 0)
{
- global $user;
-
if (!in_array($level, [2, 4, 5])) {
$level = 4;
} /*2-физ, 4-группа, 5-хаос*/
@@ -198,13 +195,13 @@ class Zayavka
if (!in_array($timeout, [1, 3, 5, 10])) {
$timeout = 1;
}
- if ($this->user_status($user['id']) != 0) {
+ if ($this->user_status($this->user->id) != 0) {
exit();
}
- if (!$user['klan'] && $t1min == 99) {
+ if (!$this->user->clan && $t1min == 99) {
$this->errorMessage = "Вы не состоите в клане.";
}
- if ($user['hp'] < $user['maxhp'] * 0.33) {
+ if ($this->user->health < $this->user->maxHealth * 0.33) {
$this->errorMessage = "Вы слишком ослаблены для боя, восстановитесь.";
}
if ($this->errorMessage) {
@@ -218,8 +215,8 @@ class Zayavka
db::c()->query('INSERT INTO `zayavka`
(`start`, `timeout`, `t1c`, `t2c`, `type`, `level`, `coment`, `team1`, `t1min`, `t2min`, `t1max`, `t2max`,`podan`,`blood`)
VALUES (?i,?i,?i,?i,?i,?i,"?s","?s",?d,?i,?i,?i,?i,"?s",?i)',
- $start, $timeout, $t1c, $t2c, $type, $level, $coment, $user['id'], $t1min, $t2min, $t1max, $t2max, date('H:i'), $blood);
- db::c()->query('UPDATE `users` SET `zayavka` = ?i WHERE `id` = ?i', db::c()->getLastInsertId(), $user['id']);
+ $start, $timeout, $t1c, $t2c, $type, $level, $coment, $this->user->id, $t1min, $t2min, $t1max, $t2max, date('H:i'), $blood);
+ db::c()->query('UPDATE `users` SET `zayavka` = ?i WHERE `id` = ?i', db::c()->getLastInsertId(), $this->user->id);
return 'Заявка подана!';
}
}
@@ -247,8 +244,7 @@ class Zayavka
public function showfiz($row)
{
- global $user;
- $rr = "{$row['podan']} ";
+ $rr = "user->id, $row['team1']) || in_array($this->user->id, $row['team2']) || $row['team2']) ? "disabled " : "") . " name=\"gocombat\" value=\"{$row['id']}\" />{$row['podan']} ";
foreach ($row['team1'] as $k => $v) {
$rr .= Nick::id($v)->full(1);
@@ -287,7 +283,7 @@ class Zayavka
$range2 = "{$row['t2min']}-{$row['t2max']}";
}
- $rr = "{$row['podan']} {$row['t1c']}({$range1}) (";
+ $rr = "user->id, $row['team1']) || in_array($this->user->id, $row['team2'])) ? "disabled " : "") . " name=\"gocombat\" value=\"{$row['id']}\">{$row['podan']} {$row['t1c']}({$range1}) (";
foreach ($row['team1'] as $k => $v) {
if ($k != 0) {
$rr .= ", ";
@@ -312,7 +308,7 @@ class Zayavka
$rr .= "";
}
- $a = db::c()->query('SELECT `admin` FROM `users` WHERE `id` = ?i', $user['id'])->fetch_assoc();
+ $a = db::c()->query('SELECT `admin` FROM `users` WHERE `id` = ?i', $this->user->id)->fetch_assoc();
$rr .= ") тип боя: ";
if ($row['blood'] && $row['type'] == 4) {
@@ -338,7 +334,7 @@ class Zayavka
public function showhaos($row)
{
global $user;
- $rr = "{$row['podan']} (";
+ $rr = "user->id, $row['team1']) || in_array($this->user->id, $row['team2'])) ? "disabled " : "") . " name=\"gocombat\" value=\"{$row['id']}\" />{$row['podan']} (";
if ($row['bots'] == '7') {
$rr .= Nick::id(10962)->full(1);
@@ -380,14 +376,8 @@ class Zayavka
$rr .= "(таймаут {$row['timeout']} мин.) бой начнется через " . round(($row['start'] - time()) / 60, 1) . " мин. " . (($row['coment']) ? "(" . $row['coment'] . ")" : "") . "";
- if ($user['admin'] === 1) {
- $rsr = ' | Удалить заявку';
- } else {
- $rsr = '';
- }
-
- if ($user['admin'] == 1) {
- $rr .= "Удалить коммнтарий$rsr
";
+ if ($this->user->admin == 1) {
+ $rr .= "Удалить комментарий | Удалить заявку
";
} else {
$rr .= "
";
}
@@ -599,7 +589,7 @@ VALUES ("?s","?s",?i,?i,?i,"?s","?s",?i,?i,?i,?i)',
db::c()->query('UPDATE `bots` SET `battle` = ?i WHERE `id` = ?i', $id, $bot['id']);
}
}
- if ($user['zayavka'] == $zay) {
+ if ($this->user->zayavka == $zay) {
die("");
}
}
@@ -608,7 +598,7 @@ VALUES ("?s","?s",?i,?i,?i,"?s","?s",?i,?i,?i,?i)',
$zay = new Zayavka;
header("Cache-Control: no-cache");
if (!empty($_POST['open'])) {
- $f = fopen("/tmp/zayavka/" . $user['id'] . ".txt", "w+");
+ $f = fopen("/tmp/zayavka/" . $user->id . ".txt", "w+");
fputs($f, time());
fclose($f);
}
@@ -630,11 +620,7 @@ if (!empty($_POST['open'])) {
@@ -675,38 +661,38 @@ if (!empty($_POST['open'])) {
} else {
$blood = 0;
}
- echo $zay->addzayavka(0, $_POST['timeout'], 1, 1, $_POST['k'], $user['level'], 1, $user['level'], 21, '', 2, $blood);
+ echo $zay->addzayavka(0, $_POST['timeout'], 1, 1, $_POST['k'], $user->level, 1, $user->level, 21, '', 2, $blood);
die("");
}
if (!empty($_POST['back'])) {
- unlink("/tmp/zayavka/" . $user['id'] . ".txt");
- echo $zay->delzayavka($user['id'], $user['zayavka'], 2, 0);
+ unlink("/tmp/zayavka/" . $user->id . ".txt");
+ echo $zay->delzayavka($user->id, $user->zayavka, 2, 0);
}
if (!empty($_POST['back2'])) {
- $z = $zay->getlist(2, null, $user['zayavka']);
- AddChatSystem('Внимание!' . Nick::id($user['id'])->short() . ' отозвал заявку.');
- echo $zay->delteam($user['id'], $user['zayavka'], 2);
+ $z = $zay->getlist(2, null, $user->zayavka);
+ AddChatSystem('Внимание!' . Nick::id($user->id)->short() . ' отозвал заявку.');
+ echo $zay->delteam($user->id, $user->zayavka, 2);
}
if (!empty($_POST['cansel'])) {
- $z = $zay->getlist(2, null, $user['zayavka']);
- echo $zay->delteam($z[$user['zayavka']]['team2'][0], $user['zayavka'], 2);
- AddChatSystem('Внимание!' . Nick::id($user['id'])->short() . ' отказался от поединка.');
+ $z = $zay->getlist(2, null, $user->zayavka);
+ echo $zay->delteam($z[$user->zayavka]['team2'][0], $user->zayavka, 2);
+ AddChatSystem('Внимание!' . Nick::id($user->id)->short() . ' отказался от поединка.');
}
- if (!empty($_POST['confirm2']) && empty($user['zayavka'])) {
+ if (!empty($_POST['confirm2']) && empty($user->zayavka)) {
$z = $zay->getlist(2, null, $_REQUEST['gocombat']);
$toper = db::c()->query('SELECT `klan` FROM `users` WHERE `id` = ?i', $z[$_REQUEST['gocombat']]['team1'][0])->fetch_assoc();
- if ($user['klan'] != $toper['klan'] || $user['klan'] == '') {
- AddChatSystem('Внимание!' . Nick::id($user['id'])->short() . ' принял заявку, нужно принять вызов или отказать.');
+ if ($user->clan != $toper['klan'] || !$user->clan) {
+ AddChatSystem('Внимание!' . Nick::id($user->id)->short() . ' принял заявку, нужно принять вызов или отказать.');
}
echo $zay->addteam(2, 2);
echo " Ожидаем подтверждения боя. "; } if (!empty($_POST['gofi'])) { - $zay->battlestart($user['id'], $user['zayavka'], 2); + $zay->battlestart($user->id, $user->zayavka, 2); } echo ""; echo '
| '; + echo ' |
';
$z = $zay->getlist(4, null, $_POST['gocombat']);
echo "Ожидаем начала группового боя... Бой начнется через: " . round(($z[$_POST['gocombat']]['start'] - time()) / 60, 1) . " мин."; @@ -905,14 +891,14 @@ if (!empty($_POST['goconfirm']) && empty($user['zayavka'])) { echo ""; -if (!empty($_POST['confirm1']) && !empty($_POST['gocombat']) && empty($user['zayavka'])) { +if (!empty($_POST['confirm1']) && !empty($_POST['gocombat']) && empty($user->zayavka)) { echo $zay->addteam(1, 4); } -if (!empty($_POST['confirm2']) && $_POST['gocombat'] && empty($user['zayavka'])) { +if (!empty($_POST['confirm2']) && $_POST['gocombat'] && empty($user->zayavka)) { echo $zay->addteam(2, 4); } -if (!empty($_POST['open']) && empty($user['zayavka'])) { +if (!empty($_POST['open']) && empty($user->zayavka)) { switch ($_POST['levellogin1']) { default: case 0 : //любой @@ -921,27 +907,27 @@ if (!empty($_POST['open']) && empty($user['zayavka'])) { break; case 1 : //только моего и ниже $min1 = 0; - $max1 = $user['level']; + $max1 = $user->level; break; case 2 : //только ниже моего уровня $min1 = 0; - $max1 = $user['level'] - 1; + $max1 = $user->level - 1; break; case 3 : //только моего уровня - $min1 = $user['level']; - $max1 = $user['level']; + $min1 = $user->level; + $max1 = $user->level; break; case 4 : //не старше меня более чем на уровень - $min1 = $user['level']; - $max1 = $user['level'] + 1; + $min1 = $user->level; + $max1 = $user->level + 1; break; case 5 : //не младше меня более чем на уровень - $min1 = $user['level'] - 1; - $max1 = $user['level']; + $min1 = $user->level - 1; + $max1 = $user->level; break; case 6 : //мой уровень +/- 1 - $min1 = (int)$user['level'] - 1; - $max1 = (int)$user['level'] + 1; + $min1 = (int)$user->level - 1; + $max1 = (int)$user->level + 1; break; case 99 : // кланы $min1 = 99; @@ -956,27 +942,27 @@ if (!empty($_POST['open']) && empty($user['zayavka'])) { break; case 1 : //только моего и ниже $min1 = 0; - $max1 = $user['level']; + $max1 = $user->level; break; case 2 : //только ниже моего уровня $min1 = 0; - $max1 = $user['level'] - 1; + $max1 = $user->level - 1; break; case 3 : //только моего уровня - $min1 = $user['level']; - $max1 = $user['level']; + $min1 = $user->level; + $max1 = $user->level; break; case 4 : //не старше меня более чем на уровень - $min1 = $user['level']; - $max1 = $user['level'] + 1; + $min1 = $user->level; + $max1 = $user->level + 1; break; case 5 : //не младше меня более чем на уровень - $min1 = $user['level'] - 1; - $max1 = $user['level']; + $min1 = $user->level - 1; + $max1 = $user->level; break; case 6 : //мой уровень +/- 1 - $min1 = (int)$user['level'] - 1; - $max1 = (int)$user['level'] + 1; + $min1 = (int)$user->level - 1; + $max1 = (int)$user->level + 1; break; case 99 : // кланы $min1 = 99; @@ -1006,7 +992,7 @@ if (!empty($_POST['open']) && empty($user['zayavka'])) { echo ""; -echo ' | '; +echo ' | '; echo ' |
';
echo ' '; @@ -1023,7 +1009,7 @@ echo ' if ($get == 'haos') { - if (!empty($_POST['open']) && empty($user['zayavka'])) { + if (!empty($_POST['open']) && empty($user->zayavka)) { switch ($_POST['levellogin1']) { default: case 0 : @@ -1031,12 +1017,12 @@ if ($get == 'haos') { $max1 = 21; break; case 3 : - $min1 = $user['level']; - $max1 = $user['level']; + $min1 = $user->level; + $max1 = $user->level; break; case 6 : - $min1 = (int)$user['level'] - 1; - $max1 = (int)$user['level'] + 1; + $min1 = (int)$user->level - 1; + $max1 = (int)$user->level + 1; break; } @@ -1051,16 +1037,16 @@ if ($get == 'haos') { } echo '
| '; + echo ' |