Файл: duels.php
Строк: 279
<?
require_once("core/core.php");
$location = 'В дуэлях';
if (!$u['id']) {
header("Location: reg.php?err=1");
exit;
}
//--------------------------------------------------------------------------------------------------------//
$duels_end = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_list` WHERE `time_end` < '" . time() . "'"), 0);
if ($duels_end > 0) {
$result = mysql_query("SELECT * FROM `duels_list` WHERE `time_end` < '" . time() . "'");
while ($duel = mysql_fetch_assoc($result)) {
$count1 = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_votes` WHERE `vote` = '1' AND `duel` = '" . $duel['id'] . "'"), 0);
$count2 = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_votes` WHERE `vote` = '2' AND `duel` = '" . $duel['id'] . "'"), 0);
if ($count1 == $count2)
$victory = 0;
else if ($count1 > $count2)
$victory = $duel['user1'];
else
$victory = $duel['user2'];
mysql_query("UPDATE `duels_list` SET `victory` = '$victory' WHERE `id` = '" . $duel['id'] . "'");
}
}
//--------------------------------------------------------------------------------------------------------//
$da = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_add` WHERE `user2` = '" . $u['id'] . "'"), 0);
switch (@$_GET['act']) {
//~~~~~~~~~~~~~~~~Вызов на дуэль~~~~~~~~~~~~~~~~~~//
case 'add':
if (isset($_GET['id'])) {
$id = num($_GET['id']);
$req = mysql_query("SELECT * FROM `users` WHERE `id` = '$id' LIMIT 1");
if (mysql_num_rows($req) and $id != $u['id']) {
$user = mysql_fetch_assoc($req);
}
}
if (isset($user['id'])) {
if (ban($user['id']) || ($user['delete'] == 1)) {
require('head.php');
error(' Пользователь заблокирован!');
require('foot.php');
exit;
}
require('head.php');
echo '<div class="title"><center>Дуэли :: <b>Вызов</b> <a href="page.php?id=' . $user['id'] . '"><b>' . $user['login'] . '</b></a></center></div>';
echo '<div class="title">';
echo '<a href = "duels.php?act=view">Мои дуэли</a> | <a href = "duels.php?act=add_list">Вызовы</a> (' . $da . ')';
echo '</div>';
//Проверим не на дуэли ли тот кто пытается вызвать
$req = mysql_query("SELECT * FROM `duels_list` WHERE (`user1` = '" . $u['id'] . "' or `user2` = '" . $u['id'] . "') and `time_end` > '" . time() . "' LIMIT 1");
if (mysql_num_rows($req)) {
error(' Вы на дуэли!');
} else {
//Проверяем не на дуэли ли
$req = mysql_query("SELECT * FROM `duels_list` WHERE (`user1` = '" . $user['id'] . "' or `user2` = '" . $user['id'] . "') and `time_end` > '" . time() . "' LIMIT 1");
if (mysql_num_rows($req)) {
error(' Пользователь ' . ico($user['sex'], $user['admin'], $user['online']) . ' <a href = "/id' . $user['id'] . '"><b><font color="#79358c">' . $user['login'] . '</font></b></a> уже на дуэли!');
} else {
//Не встречная ли заявка
$req = mysql_query("SELECT * FROM `duels_add` WHERE `user1` = '" . $user['id'] . "' and `user2` = '" . $u['id'] . "' LIMIT 1");
if (mysql_num_rows($req)) {
//Если заявка встречная направляем сразу в принятие заявки
header("Location: friends.php?act=add_list&add='" . $user['id'] . "'");
} else {
//Не повторная ли заявка
$req = mysql_query("SELECT * FROM `duels_add` WHERE `user1` = '" . $u['id'] . "' and `user2` = '" . $user['id'] . "' LIMIT 1");
if (mysql_num_rows($req)) {
error('Вызов пользователю ' . ico($user['sex'], $user['admin'], $user['online']) . ' <a href = "/id' . $user['id'] . '"><b><font color="#79358c">' . $user['login'] . '</font></b></a> уже был отправлен ранее!');
} else {
if (isset($_POST['submit'])) {
//удаляем заявки если есть
mysql_query("DELETE FROM `duels_add` WHERE `user1` = '" . $u['id'] . "'");
mysql_query("INSERT INTO `duels_add` SET
`user1` = '" . $u['id'] . "',
`user2` = '" . $user['id'] . "',
`time` = '" . time() . "'
");
//Записываем в журнал
if ($u['sex'] == 'm') {
$action[0] = 'Вызвал';
} else {
$action[0] = 'Вызвала';
}
$text = $action[0] . ' Вас на <a href = "duels.php?act=add_list">дуэль</a>.';
mysql_query("INSERT INTO `jurnal` SET
`user` = '" . $user['id'] . "',
`outuser` = '" . $u['id'] . "',
`text` = '$text',
`time` = '" . time() . "',
`new` = '1'
");
ok('Вызов пользователю ' . ico($user['sex'], $user['admin'], $user['online']) . ' <a href = "/id' . $user['id'] . '"><b><font color="#79358c">' . $user['login'] . '</font></b></a> отправлен!');
} else {
$req = mysql_query("SELECT * FROM `duels_add` WHERE `user1` = '" . $u['id'] . "' LIMIT 1");
if (mysql_num_rows($req)) {
echo '<div class = "title">Предыдущий Ваш вызов будет отменен!</div>';
}
echo '<div class="div">';
echo 'Вызываем пользователя ';
echo '' . ico($user['sex'], $user['admin'], $user['online']) . '';
echo ' <a href="/id'.$user['id'].'"><b><font color="#79358c">' . $user['login'] . '</font></b></a>';
echo '' . medal($user['rating']) . '';
echo ' на дуэль?<br/>';
echo '<form action="duels.php?act=add&id=' . $user['id'] . '" method="post">';
echo '<input type="submit" name="submit" value="Да, вызываем">';
echo '</form></div>';
}
}
}
}
}
echo '</div>';
require('foot.php');
//Если никто не выбрался
} else {
require('head.php');
echo '<div class="title"><center><a href = "duels.php">Дуэли</a> :: <b>Ошибка</b></center></div>';
error(' Такого пользователя нет!');
require('foot.php');
}
break;
//~~~~~~~~~~~~~~~~~~~~~~~~Вызовы, обработка~~~~~~~~~~~~~~~~~~~~~~~~~~//
case 'add_list':
require('head.php');
echo '<div class="title"><center><a href = "duels.php">Дуэли</a> :: Вызовы</center></div>';
echo '<div class="nav">';
echo '<a href = "duels.php?act=view">Мои дуэли</a> | <a href = "duels.php?act=add_list">Вызовы</a> (<font color="green">' . $da . '</font>)';
if (@$fa) {
echo ' | <a href = "friends.php?act=adding_list">Заявки</a> (<font color="red">' . @$fa . '</font>)';
}
echo '</div>';
//Принять
if (@$_GET['add']) {
$add = num(@$_GET['add']);
$req = mysql_query("SELECT * FROM `duels_add` WHERE `user1` = '" . $add . "' and `user2` = '" . $u['id'] . "' LIMIT 1");
if (mysql_num_rows($req)) {
$user = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '" . $add . "' LIMIT 1"));
mysql_query("INSERT INTO `duels_list` SET
`user1` = '" . $user['id'] . "',
`user2` = '" . $u['id'] . "',
`time` = '" . time() . "',
`time_end` = '" . (time() + (60 * 60 * 24 * 3)) . "'
");
//Записываем в журнал
if ($u['sex'] == 'm') {
$action[0] = 'Принял';
} else {
$action[0] = 'Приняла';
}
$text = $action[0] . ' Ваш вызов на <a href = "duels.php?act=view">дуэль</a>!';
mysql_query("INSERT INTO `jurnal` SET
`user` = '" . $user['id'] . "',
`outuser` = '" . $u['id'] . "',
`text` = '$text',
`time` = '" . time() . "',
`new` = '1'
");
mysql_query("DELETE FROM `duels_add` WHERE `user1` = '$add' and `user2` = '" . $u['id'] . "'");
ok(' Вызов от пользователя ' . ico($user['sex'], $user['admin'], $user['online']) . ' <a href = "/id' . $user['id'] . '"><b><font color="#79358c">' . $user['login'] . '</font></b></a> принят!');
} else {
}
}
//Отклонить
if (@$_GET['notadd']) {
$notadd = num($_GET['notadd']);
$req = mysql_query("SELECT * FROM `friends_adding` WHERE `user` = '$notadd' and `friend` = '" . $u['id'] . "' LIMIT 1");
if (mysql_num_rows($req)) {
$user = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '$notadd' LIMIT 1"));
mysql_query("DELETE FROM friends_adding WHERE user = '" . $user['id'] . "' and `friend` = '" . $u['id'] . "'");
ok(' Заявка от пользователя ' . ico($user['sex'], $user['admin'], $user['online']) . ' <a href = "/id' . $user['id'] . '"><b><font color="#79358c">' . $user['login'] . '</font></b></a> отклонена!');
} else {
}
}
$all = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_add` WHERE `user2` = '" . $u['id'] . "'"), 0);
if ($all > 0) {
$total = num(($all - 1) / 10) + 1;
$page = isset($_GET['page']) ? num($_GET['page']) : '';
if (empty($page) or $page < 0)
$page = 1;
if ($page > $total)
$page = $total;
$start = $page * 10 - 10;
$result = mysql_query("SELECT * FROM `duels_add` WHERE `user2` = '" . $u['id'] . "' ORDER BY `time` DESC LIMIT $start, 10");
while ($duel = mysql_fetch_assoc($result)) {
echo '<div class="div">';
$user = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '" . $duel["user1"] . "'"));
//Вывод
echo '' . ico($user['sex'], $user['admin'], $user['online']) . '';
echo ' <b><font color="#79358c">' . $user['login'] . '</font></b>';
echo '' . medal($user['rating']) . '';
echo '<br/>';
echo '<a href = "duels.php?act=add_list&add=' . $user['id'] . '"><font color="green">Принять</font></a> | <a href = "duels.php?act=add_list¬add=' . $user['id'] . '"><font color="darkred">Отклонить</font></a>';
echo '</div>';
}
echo '</div>';
navigation($page, $total, 'duels.php?act=add_list&');
} else {
echo '<div class="div"> У Вас еще нет вызовов на дуэль! </div>';
}
require('foot.php');
break;
//~~~~~~~~~~~~~~~~~Дуэли пользователей~~~~~~~~~~~~~~~~~~~//
case 'view':
$id = num(@$_GET['id']);
if (!$id)
$id = $u['id'];
$req = mysql_query("SELECT * FROM `users` WHERE `id` = '$id' LIMIT 1");
if (mysql_num_rows($req)) {
$user = mysql_fetch_assoc($req);
}
if (!$user['id']) {
require('head.php');
echo '<div class="title"><center><a href = "duels.php">Дуэли</a> :: <b>Ошибка</b></center></div>';
error(' Такой дуэли нет!');
require('foot.php');
exit;
}
if ($user['delete'] == 1) {
require('head.php');
error(' Пользователь заблокирован!');
require('foot.php');
exit;
}
if ($id == $u['id']) {
$zag = '<a href = "duels.php?act=view">Мои дуэли</a>';
} else {
$zag = 'Дуэли <a href = "page.php?id=' . $user['id'] . '">' . $user['login'] . '</a>';
}
$title = $title . ' :: Дуэли';
require('head.php');
require('core/duel_ava.php');
echo '<div class="title"><center><a href = "duels.php">Дуэли</a> :: ' . $zag . '</center></div>';
$d = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_list` WHERE `user1` = '" . $u['id'] . "' OR `user2` = '" . $u['id'] . "'"), 0);
$da = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_add` WHERE `user2` = '" . $u['id'] . "'"), 0);
echo '</div>';
$all = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_list` WHERE `user1` = '" . $user['id'] . "' OR `user2` = '" . $user['id'] . "'"), 0);
$duels_victory = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_list` WHERE (`user1` = '" . $user['id'] . "' OR `user2` = '" . $user['id'] . "') AND `time_end` < '" . time() . "' AND `victory` = '" . $user['id'] . "'"), 0);
$duels_victory2 = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_list` WHERE (`user1` = '" . $user['id'] . "' OR `user2` = '" . $user['id'] . "') AND (`time_end` < '" . time() . "' AND `victory` > 0 AND `victory` <> '" . $user['id'] . "')"), 0);
$duels_victory3 = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_list` WHERE (`user1` = '" . $user['id'] . "' OR `user2` = '" . $user['id'] . "') AND `time_end` < '" . time() . "' AND `victory` = '0'"), 0);
echo '<div class="div">';
echo 'Побед: <font color="green">' . $duels_victory . '</font>';
echo '</div><div class="div">';
echo 'Поражений: <font color="red">' . $duels_victory2 . '</font>';
echo '</div><div class="div">';
echo 'Ничьих: ' . $duels_victory3 . '';
echo '</div>';
if (isset($_GET['duel']) and isset($_GET['vote'])) {
$duel = num($_GET['duel']);
$vote = num($_GET['vote']);
if ($vote == 1 or $vote = 2) {
$req = mysql_query("SELECT * FROM `duels_list` WHERE `id` = '$duel' AND `time_end` > '" . time() . "' LIMIT 1");
if (mysql_num_rows($req)) {
$duel = mysql_fetch_assoc($req);
$req = mysql_query("SELECT * FROM `duels_votes` WHERE `user` = '" . $u['id'] . "' AND `duel` = '" . $duel['id'] . "' LIMIT 1");
if (mysql_num_rows($req) == 0) {
mysql_query("INSERT INTO `duels_votes` SET
`user` = '" . $u['id'] . "',
`vote` = '$vote',
`time` = '" . time() . "',
`duel` = '" . $duel['id'] . "'
");
}
}
}
}
if ($all > 0) {
$total = num(($all - 1) / 10) + 1;
$page = num(@$_GET['page']);
if (empty($page) or $page < 0)
$page = 1;
if ($page > $total)
$page = $total;
$start = $page * 10 - 10;
$result = mysql_query("SELECT * FROM `duels_list` WHERE `user1` = '" . $user['id'] . "' OR `user2` = '" . $user['id'] . "' ORDER BY `time` DESC LIMIT $start, 10");
while ($duel = mysql_fetch_assoc($result)) {
echo '<div class="div">';
if ($duel['time_end'] < time()) {
$user1 = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '" . $duel["user1"] . "'"));
$user2 = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '" . $duel["user2"] . "'"));
echo ' (' . vremya($duel['time_end']) . ')<br/>';
$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_votes` WHERE `vote` = '1' AND `duel` = '" . $duel['id'] . "'"), 0);
echo ' ' . ico($user['sex'], $user1['admin'], $user1['online']) . ' <a href = "/id' . $user1['id'] . '"><b><font color="#79358c">' . $user1['login'] . '</font></b></a> (<font color="green">' . $count . '</font>) ';
echo ' <b>vs</b> ';
$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_votes` WHERE `vote` = '2' AND `duel` = '" . $duel['id'] . "'"), 0);
echo ' ' . ico($user2['sex'], $user2['admin'], $user2['online']) . ' <a href = "/id' . $user2['id'] . '"><b><font color="#79358c">' . $user2['login'] . '</font></b></a> (<font color="green">' . $count . '</font>)';
echo '</div>';
} else {
$req = mysql_query("SELECT * FROM `duels_votes` WHERE `user` = '" . $u['id'] . "' AND `duel` = '" . $duel['id'] . "' LIMIT 1");
if (mysql_num_rows($req) == 0)
$vote_acces = true; else
$vote_acces = false;
$user1 = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '" . $duel["user1"] . "'"));
$user2 = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '" . $duel["user2"] . "'"));
$time = $duel['time_end'] - time();
$chas = intval($time / 3600);
if ($chas > 0) {
$chas = $chas . ' ч.';
$time = $time - ($chas * 3600);
} else {
$chas = '';
}
$min = intval($time / 60);
if ($min > 0) {
$min = $min . ' м.';
$time = $time - ($min * 60);
} else {
$min = '';
}
$sek = $time . ' с.';
echo '<center> Осталось: <font color="green">' . $chas . ' ' . $min . '</font><br/>';
echo '<table>
<tr>
<td VALIGN=top width = 100>';
duel_ava($user1['id']);
$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_votes` WHERE `vote` = '1' AND `duel` = '" . $duel['id'] . "'"), 0);
echo '<br/>' . ico($user1['sex'], $user1['admin'], $user1['online']) . ' <a href = "/id' . $user1['id'] . '"><b><font color="#79358c">' . $user1['login'] . '</font></b></a> (<font color="red">' . $count . ' голосов</font>)<br/>';
if ($vote_acces)
echo '<a href = "duels.php?act=view&id=' . $id . '&duel=' . $duel['id'] . '&vote=1">Голосовать</a>';
echo '</td>
<td VALIGN=top>';
echo '<br/> <b><font color="red">vs</font></b> ';
echo '</td>
<td VALIGN=top width = 100>';
duel_ava($user2['id']);
$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_votes` WHERE `vote` = '2' AND `duel` = '" . $duel['id'] . "'"), 0);
echo '<br/>' . ico($user2['sex'], $user2['admin'], $user2['online']) . ' <a href = "/id' . $user2['id'] . '"><b><font color="#79358c">' . $user2['login'] . '</font></b></a> (<font color="red">' . $count . ' голосов</font>)<br/>';
if ($vote_acces)
echo '<a href = "duels.php?act=view&id=' . $id . '&duel=' . $duel['id'] . '&vote=2">Голосовать</a>';
echo '</td>
</tr>
</table></center>';
echo '</div>';
}
}
echo '</div>';
navigation($page, $total, 'duels.php?act=view&id=' . $id . '&');
}else {
echo '<div class="div"> Дуэлей пока нет!</div>';
}
echo '</div>';
require('foot.php');
break;
//~~~~~~~~~~~~~~~~~~~~~Список всех дуэлей~~~~~~~~~~~~~~~~~~~~~~//
default:
$title = $title . ' :: Дуэли';
require('head.php');
require('core/duel_ava.php');
echo '<div class="title"><center>Дуэли</center></div>';
$d = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_list` WHERE `user1` = '" . $u['id'] . "' OR `user2` = '" . $u['id'] . "'"), 0);
$da = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_add` WHERE `user2` = '" . $u['id'] . "'"), 0);
echo '<div class="nav">';
echo '<a href = "duels.php?act=view">Мои дуэли</a> (<font color="green">' . $d . '</font>) | <a href = "duels.php?act=add_list">Мои вызовы</a> (<font color="green">' . $da . '</font>)';
echo '</div>';
if (isset($_GET['id']) and isset($_GET['vote'])) {
$id = num($_GET['id']);
$vote = num($_GET['vote']);
if ($vote == 1 or $vote = 2) {
$req = mysql_query("SELECT * FROM `duels_list` WHERE `id` = '$id' AND `time_end` > '" . time() . "' LIMIT 1");
if (mysql_num_rows($req)) {
$duel = mysql_fetch_assoc($req);
$req = mysql_query("SELECT * FROM `duels_votes` WHERE `user` = '" . $u['id'] . "' AND `duel` = '" . $duel['id'] . "' LIMIT 1");
if (mysql_num_rows($req) == 0) {
mysql_query("INSERT INTO `duels_votes` SET
`user` = '" . $u['id'] . "',
`vote` = '$vote',
`time` = '" . time() . "',
`duel` = '" . $duel['id'] . "'
");
}
}
}
}
$all = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_list` WHERE `time_end` > '" . time() . "'"), 0);
if ($all > 0) {
$total = num(($all - 1) / 10) + 1;
$page = num(@$_GET['page']);
if (empty($page) or $page < 0)
$page = 1;
if ($page > $total)
$page = $total;
$start = $page * 10 - 10;
$result = mysql_query("SELECT * FROM `duels_list` WHERE `time_end` > '" . time() . "' ORDER BY `time` DESC LIMIT $start, 10");
while ($duel = mysql_fetch_assoc($result)) {
echo '<div class="div">';
$req = mysql_query("SELECT * FROM `duels_votes` WHERE `user` = '" . $u['id'] . "' AND `duel` = '" . $duel['id'] . "' LIMIT 1");
if (mysql_num_rows($req) == 0)
$vote_acces = true; else
$vote_acces = false;
$user1 = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '" . $duel["user1"] . "'"));
$user2 = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '" . $duel["user2"] . "'"));
$time = $duel['time_end'] - time();
$chas = intval($time / 3600);
if ($chas > 0) {
$chas = $chas . ' ч.';
$time = $time - ($chas * 3600);
} else {
$chas = '';
}
$min = intval($time / 60);
if ($min > 0) {
$min = $min . ' м.';
$time = $time - ($min * 60);
} else {
$min = '';
}
$sek = $time . ' с.';
echo '<center>Осталось: <font color="green">' . $chas . ' ' . $min . '</font><br/>';
echo '<table>
<tr>
<td VALIGN=top width = 100>';
echo "" . duel_ava(@$user1['id']) . "";
$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_votes` WHERE `vote` = '1' AND `duel` = '" . $duel['id'] . "'"), 0);
echo '</br>' . ico($user1['sex'], $user1['admin'], $user1['online']) . ' <a href = "/id' . $user1['id'] . '"><b><font color="#79358c">' . $user1['login'] . '</font></b></a> (<font color="red">' . $count . ' голосов</font>)</br>';
if ($vote_acces)
echo '<a href = "duels.php?id=' . $duel['id'] . '&vote=1">Голосовать</a>';
echo '</td>
<td VALIGN=top>';
echo '</br> <b><font color="red">vs</font></b> ';
echo '</td>
<td VALIGN=top width = 100>';
echo "" . duel_ava(@$user2['id']) . "";
$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_votes` WHERE `vote` = '2' AND `duel` = '" . $duel['id'] . "'"), 0);
echo '</br>' . ico($user2['sex'], $user2['admin'], $user2['online']) . ' <a href = "/id' . $user2['id'] . '"><b><font color="#79358c">' . $user2['login'] . '</font></b></a> (<font color="red">' . $count . ' голосов</font>)</br>';
if ($vote_acces)
echo '<a href = "duels.php?id=' . $duel['id'] . '&vote=2">Голосовать</a>';
echo '</td>
</tr>
</table></centre>';
echo '</div>';
}
echo '</div>';
navigation($page, $total, 'duels.php?');
}else {
error(' Дуэлей пока нет!');
}
echo '</div>';
require('foot.php');
break;
}
?>