Code clean. Твою ж мать, проще переписать чем ковыряться...

This commit is contained in:
Igor Barkov (iwork) 2020-09-28 18:59:12 +03:00
parent 716dd93a91
commit 7fef811dbf

View File

@ -1,13 +1,14 @@
<?php <?php
session_start(); session_start();
if (!isset($_SESSION['uid'])) { if (empty($_SESSION['uid'])) {
header("Location: index.php"); header("Location: index.php");
exit;
} }
include("config.php");
include("functions.php"); include("functions.php");
if ($user['battle'] != 0) { $user = $user ?? [];
if ($user->battle != 0) {
header('Location: fbattle.php'); header('Location: fbattle.php');
die(); exit;
} }
db::c()->query('LOCK TABLES `bots` WRITE, `battle` WRITE, `logs` WRITE, `users` WRITE, `inventory` WRITE, `zayavka` WRITE, `effects` WRITE, `online` WRITE, `clans` WRITE'); db::c()->query('LOCK TABLES `bots` WRITE, `battle` WRITE, `logs` WRITE, `users` WRITE, `inventory` WRITE, `zayavka` WRITE, `effects` WRITE, `online` WRITE, `clans` WRITE');
@ -16,7 +17,7 @@ if ($do == "clear" && $user->admin == 1) {
db::c()->query('UPDATE `zayavka` SET `coment` = "?s" WHERE `id` = ?i', '<em>Вырезано цензурой!</em>', $_GET['zid']); db::c()->query('UPDATE `zayavka` SET `coment` = "?s" WHERE `id` = ?i', '<em>Вырезано цензурой!</em>', $_GET['zid']);
} }
if (!empty($_GET['del']) && $user['admin'] == 1) { //удаление заявки на бой. if (!empty($_GET['del']) && $user->admin == 1) { //удаление заявки на бой.
$zayavka = db::c()->query('SELECT `id` FROM `zayavka` WHERE `id` = ?i', $_GET['zid'])->fetch_assoc(); $zayavka = db::c()->query('SELECT `id` FROM `zayavka` WHERE `id` = ?i', $_GET['zid'])->fetch_assoc();
if (isset($zayavka['id'])) { if (isset($zayavka['id'])) {
db::c()->query('UPDATE `users` SET `zayavka` = 0 WHERE `zayavka` = ?i', $zayavka['id']); db::c()->query('UPDATE `users` SET `zayavka` = 0 WHERE `zayavka` = ?i', $zayavka['id']);
@ -26,16 +27,20 @@ if (!empty($_GET['del']) && $user['admin'] == 1) { //удаление заявк
} }
} }
$_SESSION['view'] = false; $_SESSION['view'] = false;
if (isset($_REQUEST['view'])) $_SESSION['view'] = $_REQUEST['view']; if (isset($_REQUEST['view'])) {
$_SESSION['view'] = $_REQUEST['view'];
}
class zayavka class Zayavka
{ {
var $mysql; /**
* @var string
*/
private $errorMessage;
function __construct() function __construct($user_id)
{ {
global $mysql;
$this->mysql = $mysql;
} }
function fteam($team) function fteam($team)
@ -53,7 +58,7 @@ class zayavka
* @return mixed * @return mixed
* @throws \Krugozor\Database\Mysql\Exception * @throws \Krugozor\Database\Mysql\Exception
*/ */
function getlist($razdel = 4, $level = null, $id = null) public function getlist($razdel = 4, $level = null, $id = null)
{ {
$sql = db::c()->prepare('SELECT * FROM `zayavka` WHERE `level` = ?i', $razdel); $sql = db::c()->prepare('SELECT * FROM `zayavka` WHERE `level` = ?i', $razdel);
if (!is_null($level)) { if (!is_null($level)) {
@ -86,65 +91,71 @@ class zayavka
return $zay; return $zay;
} }
function addteam($team, $r) public function addteam($team, $r)
{ {
global $user; global $user;
$id = $_SESSION['uid']; $id = $_SESSION['uid'];
$zay = $_REQUEST['gocombat']; $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(); $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); $z = $this->getlist($r, null, $zay);
if ($owntravma) { if ($owntravma['type'] == 12 && ($z[$zay]['type'] != 4 && $z[$zay]['type'] != 5)) {
switch ($owntravma['type']) { $this->errorMessage = "У Вас средняя травма, поединки с оружием слишком тяжелы для Вас...";
case ($owntravma['type'] == 12 && ($z[$zay]['type'] != 4 && $z[$zay]['type'] != 5)): } elseif ($owntravma['type'] == 13) {
return "У Вас средняя травма, поединки с оружием слишком тяжелы для Вас..."; $this->errorMessage = "У Вас тяжелая травма, Вы не сможете драться...";
break;
case 13:
return "У Вас тяжелая травма, Вы не сможете драться...";
break;
} }
if (!empty($user['zayavka'])) {
$this->errorMessage = "Вы находитесь в заявке";
}
if ($user['hp'] < $user['maxhp'] * 0.33) {
$this->errorMessage = "Вы слишком ослаблены для боя, восстановитесь.";
}
if (!$z || !empty($this->user_status($id))) {
$this->errorMessage = "Эта заявка не может быть принята Вами.";
}
if ($z[$zay]['type'] != 3 || $z[$zay]['type'] != 5) {
if ($team == 1) {
$teamz = 2;
} else {
$teamz = 1;
} }
if (!empty($user['zayavka'])) return "Вы находитесь в заявке";
if ($user['hp'] < $user['maxhp'] * 0.33) return "Вы слишком ослаблены для боя, восстановитесь.";
if (!$z) return "Эта заявка не может быть принята Вами.";
if ($this->user_status($id) != 0) return "Эта заявка не может быть принята Вами.";
if ($z[$zay]['type'] != 3 OR $z[$zay]['type'] != 5) {
if ($team == 1) $teamz = 2;
else $teamz = 1;
foreach ($z[$zay]['team' . $teamz] as $v) { foreach ($z[$zay]['team' . $teamz] as $v) {
$enemy = db::c()->query('SELECT `klan` FROM `users` WHERE `id` = ?i', $v)->fetch_assoc(); $enemy = db::c()->query('SELECT `klan` FROM `users` WHERE `id` = ?i', $v)->fetch_assoc();
if ($user['klan'] == $enemy['klan']) return "Нельзя драться против сокланов!"; if ($user['klan'] == $enemy['klan']) {
$this->errorMessage = "Нельзя драться против сокланов!";
}
} }
} }
if ($z[$zay]['t' . $team . 'min'] == 99) { 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(); $toper = db::c()->query('SELECT `klan` FROM `users` WHERE `id` = ?i', $z[$zay]['team' . $team][0])->fetch_assoc();
if ($user['klan'] != $toper['klan']) return "Эта заявка не может быть принята Вами."; if ($user['klan'] != $toper['klan']) {
$this->errorMessage = "Эта заявка не может быть принята Вами.";
}
} else { } else {
if ($user['level'] > 0 && !($z[$zay]['t' . $team . 'min'] <= $user['level'] && $z[$zay]['t' . $team . 'max'] >= $user['level'])) { if ($user['level'] > 0 && !($z[$zay]['t' . $team . 'min'] <= $user['level'] && $z[$zay]['t' . $team . 'max'] >= $user['level'])) {
return "Эта заявка не может быть принята Вами. - " . $z[$zay]['t' . $team . 'min']; $this->errorMessage = "Эта заявка не может быть принята Вами. - " . $z[$zay]['t' . $team . 'min'];
} }
} }
if (count($z[$zay]['team' . $team]) >= $z[$zay]['t' . $team . 'c']) { if (count($z[$zay]['team' . $team]) >= $z[$zay]['t' . $team . 'c']) {
return "Группа уже набрана."; $this->errorMessage = "Группа уже набрана.";
} }
$z[$zay]['team' . $team][] = ''; $z[$zay]['team' . $team][] = '';
if (mysql_query("UPDATE `users`, `zayavka` SET `users`.`zayavka` = {$zay}, `zayavka`.`team{$team}` = '" . implode(";", $z[$zay]['team' . $team]) . "" . $id . ";' WHERE `users`.`id` = {$id} AND `users`.`zayavka` = 0 AND `zayavka`.`id` = {$zay}")) { if ($this->errorMessage) {
return $this->errorMessage;
} else {
mysql_query("UPDATE `users`, `zayavka` SET `users`.`zayavka` = {$zay}, `zayavka`.`team{$team}` = '" . implode(";", $z[$zay]['team' . $team]) . "" . $id . ";' WHERE `users`.`id` = {$id} AND `users`.`zayavka` = 0 AND `zayavka`.`id` = {$zay}");
return "Вы приняли заявку на бой."; return "Вы приняли заявку на бой.";
} else return 'addteam(): database error!'; }
} }
function delteam($id, $zay, $r) public function delteam($id, $zay, $r)
{ {
$z = $this->getlist($r, null, $zay); $z = $this->getlist($r, null, $zay);
if ($z[$zay]['level'] > 3 || $z[$zay]['level'] == null) { if ($z[$zay]['level'] > 3 || $z[$zay]['level'] == null) {
return "Ай-ай-ай!"; $this->errorMessage = 'Неизвестная ошибка.';
} }
foreach ($z[$zay]['team2'] as $v) { foreach ($z[$zay]['team2'] as $v) {
@ -152,38 +163,52 @@ class zayavka
$teams[] = $v; $teams[] = $v;
} }
} }
if ($this->errorMessage) {
if (mysql_query("UPDATE `users`, `zayavka` SET `users`.`zayavka` = '0', `zayavka`.`team{$team}` = '{$teams}' WHERE `users`.`id` = {$id} AND `zayavka`.`id` = {$zay};")) { return $this->errorMessage;
} else {
mysql_query("UPDATE `users`, `zayavka` SET `users`.`zayavka` = '0', `zayavka`.`team{$team}` = '{$teams}' WHERE `users`.`id` = {$id} AND `zayavka`.`id` = {$zay};");
return "Вы отозвали запрос"; return "Вы отозвали запрос";
} else return 'delteam(): database error!'; }
} }
function addzayavka($start, $timeout, $t1c, $t2c, $type, $t1min, $t2min, $t1max, $t2max, $coment, $level, $blood = 0) public function addzayavka($start, $timeout, $t1c, $t2c, $type, $t1min, $t2min, $t1max, $t2max, $coment, $level, $blood = 0)
{ {
global $user; global $user;
if (!in_array($level, [2, 4, 5])) $level = 4; /*2-физ, 4-группа, 5-хаос*/ if (!in_array($level, [2, 4, 5])) {
$level = 4;
if ($level == 2 AND $type != 1 AND $type != 4 AND $type != 6) $type = 1; } /*2-физ, 4-группа, 5-хаос*/
if ($level == 4 AND $type != 2 AND $type != 4) $type = 2;
if ($level == 5 AND $type != 3 AND $type != 5) $type = 3;
if (!in_array($start, [1, 3, 5, 10, 15, 30, 60])) $start = 1;
if (!in_array($timeout, [1, 3, 5, 10])) $timeout = 1;
if ($this->user_status($user['id']) != 0) exit();
if ($level == 2 && $type != 1 && $type != 4 && $type != 6) {
$type = 1;
}
if ($level == 4 && $type != 2 && $type != 4) {
$type = 2;
}
if ($level == 5 && $type != 3 && $type != 5) {
$type = 3;
}
if (!in_array($start, [1, 3, 5, 10, 15, 30, 60])) {
$start = 1;
}
if (!in_array($timeout, [1, 3, 5, 10])) {
$timeout = 1;
}
if ($this->user_status($user['id']) != 0) {
exit();
}
if (!$user['klan'] && $t1min == 99) { if (!$user['klan'] && $t1min == 99) {
return "Вы не состоите в клане."; $this->errorMessage = "Вы не состоите в клане.";
} }
if ($user['hp'] < $user['maxhp'] * 0.33) { if ($user['hp'] < $user['maxhp'] * 0.33) {
return "Вы слишком ослаблены для боя, восстановитесь."; $this->errorMessage = "Вы слишком ослаблены для боя, восстановитесь.";
} }
if ($this->errorMessage) {
return $this->errorMessage;
} else {
if ($type == 3) { if ($type == 3) {
AddChatSystem('Внимание! Подана заявка на хаотический поединок ({$t1min} - {$t1max}), который начнется через {$start} минут.'); AddChatSystem('Внимание! Подана заявка на хаотический поединок ({$t1min} - {$t1max}), который начнется через {$start} минут.');
} }
$start = time() + $start * 60; $start = time() + $start * 60;
db::c()->query('INSERT INTO `zayavka` db::c()->query('INSERT INTO `zayavka`
@ -191,34 +216,32 @@ class zayavka
VALUES (?i,?i,?i,?i,?i,?i,"?s","?s",?d,?i,?i,?i,?i,"?s",?i)', 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); $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']); db::c()->query('UPDATE `users` SET `zayavka` = ?i WHERE `id` = ?i', db::c()->getLastInsertId(), $user['id']);
return 'Заявка подана!';
return null; }
} }
function delzayavka($id, $zay, $r, $f = 1) public function delzayavka($id, $zay, $r, $f = 1)
{ {
$z = $this->getlist($r, null, $zay); $z = $this->getlist($r, null, $zay);
if ($f != 1) { if ($f != 1 && $z[$zay]['level'] > 3) {
if ($z[$zay]['level'] > 3) { return 'Неизвестная ошибка.';
return 'Ай-ай-ай!'; } else {
} mysql_query("DELETE FROM `zayavka` WHERE `id` = {$zay} AND (`team1` LIKE '{$id};%' OR `team2` LIKE '{$id};%') LIMIT 1");
}
if (mysql_query("DELETE FROM `zayavka` WHERE `id` = {$zay} AND (`team1` LIKE '{$id};%' OR `team2` LIKE '{$id};%') LIMIT 1")) {
if (count($z[$zay]['team1']) > 0) { if (count($z[$zay]['team1']) > 0) {
foreach ($z[$zay]['team1'] as $k => $v) foreach ($z[$zay]['team1'] as $k => $v) {
db::c()->query('UPDATE `users` SET `zayavka` = 0 WHERE `id` = ?i', $v); db::c()->query('UPDATE `users` SET `zayavka` = 0 WHERE `id` = ?i', $v);
} }
}
if (count($z[$zay]['team2']) > 0) { if (count($z[$zay]['team2']) > 0) {
foreach ($z[$zay]['team2'] as $k => $v) foreach ($z[$zay]['team2'] as $k => $v) {
db::c()->query('UPDATE `users` SET `zayavka` = 0 WHERE `id` = ?i', $v); db::c()->query('UPDATE `users` SET `zayavka` = 0 WHERE `id` = ?i', $v);
} }
}
return 'Вы отозвали заявку.'; return 'Вы отозвали заявку.';
} else return 'delzayavka(): database error!'; }
} }
function showfiz($row) public function showfiz($row)
{ {
global $user; global $user;
$rr = "<input type=\"radio\" " . ((in_array($user['id'], $row['team1']) || in_array($user['id'], $row['team2']) || $row['team2']) ? "disabled " : "") . " name=\"gocombat\" value=\"{$row['id']}\" /><font class=date>{$row['podan']}</font> "; $rr = "<input type=\"radio\" " . ((in_array($user['id'], $row['team1']) || in_array($user['id'], $row['team2']) || $row['team2']) ? "disabled " : "") . " name=\"gocombat\" value=\"{$row['id']}\" /><font class=date>{$row['podan']}</font> ";
@ -246,7 +269,7 @@ class zayavka
return $rr; return $rr;
} }
function showgroup($row) public function showgroup($row)
{ {
if ($row['t1min'] == 99) { if ($row['t1min'] == 99) {
$range1 = "<i>клан</i>"; $range1 = "<i>клан</i>";
@ -308,7 +331,7 @@ class zayavka
return $rr; return $rr;
} }
function showhaos($row) public function showhaos($row)
{ {
global $user; global $user;
$rr = "<input type=\"radio\" " . ((in_array($user['id'], $row['team1']) || in_array($user['id'], $row['team2'])) ? "disabled " : "") . " name=\"gocombat\" value=\"{$row['id']}\" /><font class=\"date\">{$row['podan']}</font> ("; $rr = "<input type=\"radio\" " . ((in_array($user['id'], $row['team1']) || in_array($user['id'], $row['team2'])) ? "disabled " : "") . " name=\"gocombat\" value=\"{$row['id']}\" /><font class=\"date\">{$row['podan']}</font> (";
@ -367,7 +390,7 @@ class zayavka
return $rr; return $rr;
} }
function user_status($id) public function user_status($id)
{ {
$r = db::c()->query('SELECT `team1`,`team2` FROM `zayavka`, `users` WHERE `users`.`id` = ?i AND `zayavka`.`id` = `users`.`zayavka`', $id)->fetch_assoc(); $r = db::c()->query('SELECT `team1`,`team2` FROM `zayavka`, `users` WHERE `users`.`id` = ?i AND `zayavka`.`id` = `users`.`zayavka`', $id)->fetch_assoc();
$t1 = $this->fteam($r['team1']); $t1 = $this->fteam($r['team1']);
@ -381,7 +404,7 @@ class zayavka
} }
} }
function battlestart($id, $zay, $r) public function battlestart($id, $zay, $r)
{ {
global $user; global $user;
$z = $this->getlist($r, null, $zay); $z = $this->getlist($r, null, $zay);
@ -470,7 +493,7 @@ class zayavka
} }
} }
while (count($cost) > 0) { while (!empty($cost)) {
if ($power1 <= $power2) { if ($power1 <= $power2) {
$tmp = array_shift($cost); $tmp = array_shift($cost);
$power1 += $tmp[1]; $power1 += $tmp[1];
@ -509,7 +532,9 @@ class zayavka
die(); die();
} }
if (!in_array($z['timeout'], [3, 4, 5, 7, 10])) $z['timeout'] = 3; if (!in_array($z['timeout'], [3, 4, 5, 7, 10])) {
$z['timeout'] = 3;
}
if (count($teams) > 1) { if (count($teams) > 1) {
if ($z['type'] == 1 || $z['type'] == 4) { if ($z['type'] == 1 || $z['type'] == 4) {
@ -576,7 +601,7 @@ VALUES ("?s","?s",?i,?i,?i,"?s","?s",?i,?i,?i,?i)',
} }
} }
$zay = new zayavka; $zay = new Zayavka;
header("Cache-Control: no-cache"); header("Cache-Control: no-cache");
if (!empty($_POST['open'])) { if (!empty($_POST['open'])) {
$f = fopen("/tmp/zayavka/" . $user['id'] . ".txt", "w+"); $f = fopen("/tmp/zayavka/" . $user['id'] . ".txt", "w+");
@ -609,7 +634,9 @@ if (!empty($_POST['open'])) {
<TABLE width=100% cellspacing=1 cellpadding=1> <TABLE width=100% cellspacing=1 cellpadding=1>
<TR> <TR>
<TD colspan=5> <TD colspan=5>
<?php if (!empty($level)) {echo Nick::id($user)->battle();} ?> <?php if (!empty($level)) {
echo Nick::id($user)->battle();
} ?>
</TD> </TD>
<TD colspan=4 align=right> <TD colspan=4 align=right>
<INPUT TYPE=button value="Вернуться" onclick="location.href='main.php?top=<?= mt_rand() ?>';"> <INPUT TYPE=button value="Вернуться" onclick="location.href='main.php?top=<?= mt_rand() ?>';">
@ -629,8 +656,12 @@ if (!empty($_POST['open'])) {
<TD> <TD>
<?php <?php
$get = urldecode(filter_input(INPUT_SERVER, 'QUERY_STRING')); $get = urldecode(filter_input(INPUT_SERVER, 'QUERY_STRING'));
if ($user['room'] != 1 AND $get != 'current') die(err('В этой комнате невозможно подавать заявки!')); if ($user->room != 1 && $get != 'current') {
if (!$get) echo '<p style="text-align: center; font-weight: bold; margin-top: 16px;">Выберите раздел</p>'; exit('В этой комнате невозможно подавать заявки!');
}
if (!$get) {
echo '<p style="text-align: center; font-weight: bold; margin-top: 16px;">Выберите раздел</p>';
}
if ($get == 'fiz') { if ($get == 'fiz') {
echo "<b style='color: #f80000;'>"; echo "<b style='color: #f80000;'>";
@ -657,7 +688,7 @@ if (!empty($_POST['open'])) {
echo $zay->delteam($z[$user['zayavka']]['team2'][0], $user['zayavka'], 2); echo $zay->delteam($z[$user['zayavka']]['team2'][0], $user['zayavka'], 2);
AddChatSystem('Внимание!' . Nick::id($user['id'])->short() . ' отказался от поединка.'); AddChatSystem('Внимание!' . Nick::id($user['id'])->short() . ' отказался от поединка.');
} }
if (!empty($_POST['confirm2']) AND empty($user['zayavka'])) { if (!empty($_POST['confirm2']) && empty($user['zayavka'])) {
$z = $zay->getlist(2, null, $_REQUEST['gocombat']); $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(); $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'] == '') { if ($user['klan'] != $toper['klan'] || $user['klan'] == '') {
@ -740,16 +771,16 @@ if (!empty($_POST['open'])) {
} }
} }
} }
if ($zay->user_status($user['id']) == 2) { if ($zay->user_status($user['id']) == 2 && $z[$user['zayavka']]['level'] == 2) {
if ($z[$user['zayavka']]['level'] == 2)
echo "Ожидаем подтверждения боя. <input type=submit name=back2 value='Отозвать заявку'>"; echo "Ожидаем подтверждения боя. <input type=submit name=back2 value='Отозвать заявку'>";
} }
echo '</td></tr></table></TD><TD align=right valign=top rowspan=2><INPUT TYPE=submit name=tmp value="Обновить"><BR><FIELDSET style="width:150px;"><LEGEND>Показывать заявки</LEGEND><table cellspacing=0 cellpadding=0 ><tr><td width=1%><input type=radio name=view value="' . $user['level'] . '" ' . (($_SESSION['view'] != null) ? "checked" : "") . '></td><td>моего уровня</td></tr><tr><td><input type=radio name=view value="" ' . (($_SESSION['view'] == null) ? "checked" : "") . '></td><td>все</td></tr></table></FIELDSET>'; echo '</td></tr></table></TD><TD align=right valign=top rowspan=2><INPUT TYPE=submit name=tmp value="Обновить"><BR><FIELDSET style="width:150px;"><LEGEND>Показывать заявки</LEGEND><table cellspacing=0 cellpadding=0 ><tr><td width=1%><input type=radio name=view value="' . $user['level'] . '" ' . (($_SESSION['view'] != null) ? "checked" : "") . '></td><td>моего уровня</td></tr><tr><td><input type=radio name=view value="" ' . (($_SESSION['view'] == null) ? "checked" : "") . '></td><td>все</td></tr></table></FIELDSET>';
echo '<tr><td><INPUT TYPE=hidden name=level value=fiz><INPUT TYPE=submit value="Принять вызов" NAME=confirm2><BR>'; echo '<tr><td><INPUT TYPE=hidden name=level value=fiz><INPUT TYPE=submit value="Принять вызов" NAME=confirm2><BR>';
if ($z = $zay->getlist(2, $_SESSION['view'])) if ($z = $zay->getlist(2, $_SESSION['view'])) {
foreach ($z as $k => $v) { foreach ($z as $k => $v) {
echo $zay->showfiz($v); echo $zay->showfiz($v);
} }
}
echo '<INPUT TYPE=submit value="Принять вызов" NAME=confirm2></TD></TR></TABLE>'; echo '<INPUT TYPE=submit value="Принять вызов" NAME=confirm2></TD></TR></TABLE>';
} }
@ -782,7 +813,8 @@ if (!empty($_POST['open'])) {
<option value=10>10 мин.</option> <option value=10>10 мин.</option>
</select> </select>
<BR><BR> <BR><BR>
Ваша команда <INPUT TYPE=text NAME=nlogin1 size=3 maxlength=2 placeholder="Количество союзников"> бойцов<BR> Ваша команда <INPUT TYPE=text NAME=nlogin1 size=3 maxlength=2
placeholder="Количество союзников"> бойцов<BR>
Уровни союзников &nbsp;&nbsp;<SELECT NAME=levellogin1> Уровни союзников &nbsp;&nbsp;<SELECT NAME=levellogin1>
<option value=0>любой <option value=0>любой
<option value=1>только моего и ниже <option value=1>только моего и ниже
@ -829,7 +861,7 @@ if (!empty($_POST['open'])) {
<?php } <?php }
if (!empty($_POST['goconfirm']) AND empty($user['zayavka'])) { if (!empty($_POST['goconfirm']) && empty($user['zayavka'])) {
echo '<TABLE width=100%><TR><TD>'; echo '<TABLE width=100%><TR><TD>';
$z = $zay->getlist(4, null, $_POST['gocombat']); $z = $zay->getlist(4, null, $_POST['gocombat']);
echo "<B>Ожидаем начала группового боя...</B><BR>Бой начнется через: " . round(($z[$_POST['gocombat']]['start'] - time()) / 60, 1) . " мин."; echo "<B>Ожидаем начала группового боя...</B><BR>Бой начнется через: " . round(($z[$_POST['gocombat']]['start'] - time()) / 60, 1) . " мин.";
@ -843,19 +875,25 @@ if (!empty($_POST['goconfirm']) AND empty($user['zayavka'])) {
</TD></TR><TR> </TD></TR><TR>
<TD align=center>'; <TD align=center>';
foreach ($z[$_POST['gocombat']]['team1'] as $k => $v) { foreach ($z[$_POST['gocombat']]['team1'] as $k => $v) {
if ($k != 0) $rr .= "<BR>"; if ($k != 0) {
$rr .= "<BR>";
}
echo Nick::id($v)->full(1); echo Nick::id($v)->full(1);
} }
echo '</TD><TD align=center>'; echo '</TD><TD align=center>';
foreach ($z[$_POST['gocombat']]['team2'] as $k => $v) { foreach ($z[$_POST['gocombat']]['team2'] as $k => $v) {
if ($k != 0) $rr .= "<BR>"; if ($k != 0) {
$rr .= "<BR>";
}
echo Nick::id($v)->full(1); echo Nick::id($v)->full(1);
} }
echo '</TD></TR><TR>'; echo '</TD></TR><TR>';
if ($z[$_POST['gocombat']]['team1'][0] != 1000 && $z[$_POST['gocombat']]['team1'][0] != 1001) if ($z[$_POST['gocombat']]['team1'][0] != 1000 && $z[$_POST['gocombat']]['team1'][0] != 1001) {
echo '<TD align=center><INPUT TYPE=submit name=confirm1 value="Я за этих!"></TD>'; echo '<TD align=center><INPUT TYPE=submit name=confirm1 value="Я за этих!"></TD>';
else echo '<TD align=center>Силы Хаоса</TD>'; } else {
echo '<TD align=center>Силы Хаоса</TD>';
}
echo '<TD align=center><INPUT TYPE=submit name=confirm2 value="Я за этих!"></TD></TR></TABLE><INPUT TYPE=hidden name=gocombat value="' . $_POST['gocombat'] . '"><INPUT TYPE=hidden name=level value=group>'; echo '<TD align=center><INPUT TYPE=submit name=confirm2 value="Я за этих!"></TD></TR></TABLE><INPUT TYPE=hidden name=gocombat value="' . $_POST['gocombat'] . '"><INPUT TYPE=hidden name=level value=group>';
die(); die();
@ -863,16 +901,16 @@ if (!empty($_POST['goconfirm']) AND empty($user['zayavka'])) {
echo "<b style='color: #f80000;'>"; echo "<b style='color: #f80000;'>";
if (!empty($_POST['confirm1']) AND !empty($_POST['gocombat']) AND empty($user['zayavka'])) { if (!empty($_POST['confirm1']) && !empty($_POST['gocombat']) && empty($user['zayavka'])) {
echo $zay->addteam(1, 4); echo $zay->addteam(1, 4);
} }
if (!empty($_POST['confirm2']) AND $_POST['gocombat'] AND empty($user['zayavka'])) { if (!empty($_POST['confirm2']) && $_POST['gocombat'] && empty($user['zayavka'])) {
echo $zay->addteam(2, 4); echo $zay->addteam(2, 4);
} }
if (!empty($_POST['open']) AND empty($user['zayavka'])) { if (!empty($_POST['open']) && empty($user['zayavka'])) {
//print_r($_REQUEST);
switch ($_POST['levellogin1']) { switch ($_POST['levellogin1']) {
default:
case 0 : //любой case 0 : //любой
$min1 = 0; $min1 = 0;
$max1 = 21; $max1 = 21;
@ -907,6 +945,7 @@ if (!empty($_POST['open']) AND empty($user['zayavka'])) {
break; break;
} }
switch ($_POST['levellogin2']) { switch ($_POST['levellogin2']) {
default:
case 0 : //любой case 0 : //любой
$min1 = 0; $min1 = 0;
$max1 = 21; $max1 = 21;
@ -940,8 +979,12 @@ if (!empty($_POST['open']) AND empty($user['zayavka'])) {
$max1 = 99; $max1 = 99;
break; break;
} }
if ($min1 < 0) $min1 = 0; if ($min1 < 0) {
if ($max1 < 0) $max1 = 0; $min1 = 0;
}
if ($max1 < 0) {
$max1 = 0;
}
if ($_POST['k']) { if ($_POST['k']) {
$_POST['k'] = 4; $_POST['k'] = 4;
} else { } else {
@ -952,37 +995,33 @@ if (!empty($_POST['open']) AND empty($user['zayavka'])) {
} else { } else {
$blood = 0; $blood = 0;
} }
if ($_POST['nlogin1'] == 1 && $_POST['nlogin2'] == 1) {
echo "Не надо превращать групповой бой в физический поединок";
} else {
echo $zay->addzayavka($_POST['startime'] / 60, $_POST['timeout'], $_POST['nlogin1'], $_POST['nlogin2'], $_POST['k'], $min1, $min2, $max1, $max2, $_POST['cmt'], 4, $blood); echo $zay->addzayavka($_POST['startime'] / 60, $_POST['timeout'], $_POST['nlogin1'], $_POST['nlogin2'], $_POST['k'], $min1, $min2, $max1, $max2, $_POST['cmt'], 4, $blood);
} }
}
/////////////////////////////////
echo "</b><INPUT TYPE=hidden name=level value=group>"; echo "</b><INPUT TYPE=hidden name=level value=group>";
echo '</TD><TD align=right valign=top rowspan=2><INPUT TYPE=submit name=tmp value="Обновить"><BR><FIELDSET style="width:150px;"><LEGEND>Показывать заявки</LEGEND><table cellspacing=0 cellpadding=0 ><tr><td width=1%><input type=radio name=view value="' . $user['level'] . '" ' . (($_SESSION['view'] != null) ? "checked" : "") . '></td><td>моего уровня</td></tr><tr><td><input type=radio name=view value="" ' . (($_SESSION['view'] == null) ? "checked" : "") . '></td><td>все</td></tr></table></FIELDSET>'; echo '</TD><TD align=right valign=top rowspan=2><INPUT TYPE=submit name=tmp value="Обновить"><BR><FIELDSET style="width:150px;"><LEGEND>Показывать заявки</LEGEND><table cellspacing=0 cellpadding=0 ><tr><td width=1%><input type=radio name=view value="' . $user['level'] . '" ' . (($_SESSION['view'] != null) ? "checked" : "") . '></td><td>моего уровня</td></tr><tr><td><input type=radio name=view value="" ' . (($_SESSION['view'] == null) ? "checked" : "") . '></td><td>все</td></tr></table></FIELDSET>';
echo '<tr><td width=85%>'; echo '<tr><td width=85%>';
echo '<BR><INPUT TYPE=submit value="Принять участие" NAME=goconfirm><BR>'; echo '<BR><INPUT TYPE=submit value="Принять участие" NAME=goconfirm><BR>';
if ($z = $zay->getlist(4, $_SESSION['view'])) if ($z = $zay->getlist(4, $_SESSION['view'])) {
foreach ($z as $k => $v) { foreach ($z as $k => $v) {
if ((($z[$k]['start'] - time()) < 0) || (($z[$k]['t1c'] == count($z[$k]['team1'])) && ($z[$k]['t2c'] == count($z[$k]['team2'])))) { if ((($z[$k]['start'] - time()) < 0) || (($z[$k]['t1c'] == count($z[$k]['team1'])) && ($z[$k]['t2c'] == count($z[$k]['team2'])))) {
$zay->battlestart("CHAOS", $k, 4); $zay->battlestart("CHAOS", $k, 4);
} }
echo $zay->showgroup($v); echo $zay->showgroup($v);
} }
}
echo '<INPUT TYPE=submit value="Принять участие" NAME=goconfirm></td></tr></table>'; echo '<INPUT TYPE=submit value="Принять участие" NAME=goconfirm></td></tr></table>';
} }
if ($get == 'haos') { if ($get == 'haos') {
if ($user['level'] < 2) { if (!empty($_POST['open']) && empty($user['zayavka'])) {
die("<BR><BR><BR><CENTER><B>Хаотичные бои доступны с 2 уровня.</b></CENTER>");
}
if (!empty($_POST['open']) AND empty($user['zayavka'])) {
switch ($_POST['levellogin1']) { switch ($_POST['levellogin1']) {
default:
case 0 : case 0 :
$min1 = 1; $min1 = 1;
$max1 = 21; $max1 = 21;
@ -996,7 +1035,6 @@ if ($get == 'haos') {
$max1 = (int)$user['level'] + 1; $max1 = (int)$user['level'] + 1;
break; break;
} }
//$_POST['k'] = 3;
$blood = 0; $blood = 0;
if ($_POST['travma']) { if ($_POST['travma']) {
@ -1014,27 +1052,31 @@ if ($get == 'haos') {
} }
if ($zay->user_status($user['id']) != 0) { if ($zay->user_status($user['id']) != 0) {
$z = $zay->getlist(5, null, $user['zayavka']); $z = $zay->getlist(5, null, $user['zayavka']);
if ($z[$user['zayavka']]['level'] == 5) if ($z[$user['zayavka']]['level'] == 5) {
echo "<B>Ожидаем начала группового боя...</B><BR>Бой начнется через: " . round(($z[$user['zayavka']]['start'] - time()) / 60, 1) . " мин."; echo "<B>Ожидаем начала группового боя...</B><BR>Бой начнется через: " . round(($z[$user['zayavka']]['start'] - time()) / 60, 1) . " мин.";
} }
}
echo '</td></tr></table></TD><TD align=right valign=top rowspan=2><INPUT TYPE=submit name=tmp value="Обновить"><BR><FIELDSET style="width:150px;"><LEGEND>Показывать заявки</LEGEND><table cellspacing=0 cellpadding=0 ><tr><td width=1%><input type=radio name=view value="' . $user['level'] . '" ' . (($_SESSION['view'] != null) ? "checked" : "") . '></td><td>моего уровня</td></tr><tr><td><input type=radio name=view value="" ' . (($_SESSION['view'] == null) ? "checked" : "") . '></td><td>все</td></tr></table></FIELDSET>'; echo '</td></tr></table></TD><TD align=right valign=top rowspan=2><INPUT TYPE=submit name=tmp value="Обновить"><BR><FIELDSET style="width:150px;"><LEGEND>Показывать заявки</LEGEND><table cellspacing=0 cellpadding=0 ><tr><td width=1%><input type=radio name=view value="' . $user['level'] . '" ' . (($_SESSION['view'] != null) ? "checked" : "") . '></td><td>моего уровня</td></tr><tr><td><input type=radio name=view value="" ' . (($_SESSION['view'] == null) ? "checked" : "") . '></td><td>все</td></tr></table></FIELDSET>';
echo '<tr><td width=85%><INPUT TYPE=hidden name=level value=haos><INPUT TYPE=submit value="Принять участие" NAME=confirm2><BR>'; echo '<tr><td width=85%><INPUT TYPE=hidden name=level value=haos><INPUT TYPE=submit value="Принять участие" NAME=confirm2><BR>';
if ($z = $zay->getlist(5, $_SESSION['view'])) if ($z = $zay->getlist(5, $_SESSION['view'])) {
foreach ($z as $k => $v) { foreach ($z as $k => $v) {
if (($z[$k]['start'] - time()) < 0) { if (($z[$k]['start'] - time()) < 0) {
$zay->battlestart("CHAOS", $k, 5); $zay->battlestart("CHAOS", $k, 5);
} }
echo $zay->showhaos($v); echo $zay->showhaos($v);
} }
}
echo '<INPUT TYPE=submit value="Принять участие" NAME=confirm2></TD></TR></TABLE>'; echo '<INPUT TYPE=submit value="Принять участие" NAME=confirm2></TD></TR></TABLE>';
//print_r($_POST);
} }
if ($get == 'current') { if ($get == 'current') {
$t1 = floor(time() - 900); $t1 = floor(time() - 900);
$data = db::c()->query('SELECT * FROM `battle` WHERE `win` = 3 AND `to1` > ?i AND `to2` > ?i ORDER BY `id` ASC', $t1, $t1); $data = db::c()->query('SELECT * FROM `battle` WHERE `win` = 3 AND `to1` > ?i AND `to2` > ?i ORDER BY `id` ASC', $t1, $t1);
if (empty($data->getNumRows())) echo 'Надо же! Ни одного поединка!'; if (empty($data->getNumRows())) {
else while ($row = $data->fetch_assoc()) { echo 'Надо же! Ни одного поединка!';
}
else {
while ($row = $data->fetch_assoc()) {
echo "<span class=date>{$row['date']}</span>"; echo "<span class=date>{$row['date']}</span>";
$z = explode(";", $row['t1']); $z = explode(";", $row['t1']);
foreach ($z as $k => $v) { foreach ($z as $k => $v) {
@ -1054,6 +1096,7 @@ if ($get == 'current') {
echo "<img src='i/fighttype{$row['type']}.gif'> <a href='logs.php?log={$row['id']}' target=_blank>»»</a><br />"; echo "<img src='i/fighttype{$row['type']}.gif'> <a href='logs.php?log={$row['id']}' target=_blank>»»</a><br />";
} }
} }
}
db::c()->query('UNLOCK TABLES'); db::c()->query('UNLOCK TABLES');