Файл: archive/www/musimka.ru/duels.php
Строк: 177
<?
require('connect.php');
if(!$u['id']){
header ("Location: registration.php?err=1");
exit;
}
$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"> <img src= "ico/duels.gif"> <b>Дуэли</b></div>';
echo '<div class="nav">';
echo '<a href = "duels.php?act=view">Мои дуэли</a> | <a href = "duels.php?act=add_list">Вызовы</a> ('.$da.')<br/><b>Вызов на дуэль</b>';
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(' Пользователь <a href = "/'.$user['id'].'">'.$user['login'].'</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('Вызов пользователю <a href = "/'.$user['id'].'">'.$user['login'].'</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('Вызов пользователю <a href = "/'.$user['id'].'">'.$user['login'].'</a> отправлен !');
} else {
$req = mysql_query("SELECT * FROM `duels_add` WHERE `user1` = '".$u['id']."' LIMIT 1");
if(mysql_num_rows($req)){
echo '<div class = "app">Предыдущий Ваш вызов будет отменен !</div>';
}
echo '<div class="div">';
echo 'Вызываем пользователя <a href = "/'.$user['id'].'">'.$user['login'].'</a> на дуэль?<br/>';
echo '<form action="duels.php?act=add&id='.$user['id'].'" method="post">';
echo '<input type="submit" name="submit" value="Да, вызываем" class="submit white"/>';
echo '</form></div>';
}
}
}
}
}
echo '</div>';
require('foot.php');
//Если никто не выбрался
} else {
require('head.php');
echo '<div class="title"><img src= "ico/duels.gif"> <a href = "duels.php">Дуэли</a> <b>Ошибка</b></div>';
error(' Такого пользователя нет !');
require('foot.php');
}
break;
//~~~~~~~~~~~~~~~~~~~~~~~~Вызовы, обработка~~~~~~~~~~~~~~~~~~~~~~~~~~//
case 'add_list':
require('head.php');
echo '<div class="title"><img src= "ico/duels.gif"> <a href = "duels.php">Дуэли</a> <a href = "duels.php?act=add_list">Вызовы </a> <b>Просмотр</b></div>';
echo '<div class="nav">';
echo '<a href = "duels.php?act=view">Мои дуэли</a> | <a href = "duels.php?act=add_list">Вызовы</a> ('.$da.')';
if(@$fa){ echo ' | <a href = "friends.php?act=adding_list">Заявки</a> ('.@$fa.')';}
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(' Вызов от пользователя <a href = "/'.$user['id'].'">'.$user['login'].'</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']."'");
error(' Заявка от пользователя <a href = "/'.$user['id'].'">'.$user['login'].'</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 = 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 $i % 2 ? '<div class="div">' : '<div class="div">';
$user = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '".$duel["user1"]."'"));
//Вывод
if(ban($user['id']) || ($user['delete'] == 1)){
echo ''.ico($user['sex'],$user['admin']).' <a href = "/'.$user['id'].'"><del>'.$user['login'].'</del></a> '.online($user['online']).'';
} else {
echo ''.ico($user['sex'],$user['admin']).' <a href = "/'.$user['id'].'">'.$user['login'].'</a> '.online($user['online']).'';
}
echo '<br/>';
echo '<a href = "duels.php?act=add_list&add='.$user['id'].'">Принять</a> | <a href = "duels.php?act=add_list¬add='.$user['id'].'">Отклонить</a>';
echo '</div>';
$i++;
}
echo '</div>';
navigation($page, $total,'duels.php?act=add_list&');
}else{
error(' У Вас еще нет вызовов на дуэль !');
}
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"><img src= "ico/duels.gif"> <a href = "duels.php">Дуэли</a> <b>Ошибка</b></div>';
error(' Такого дуэли нет !');
require('foot.php');
exit;
}
if(ban($user['id']) || ($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 = "/'.$user['id'].'">'.$user['login'].'</a>'; }
$title = $title.' | Дуэли';
require('head.php');
require('core/duel_ava.php');
echo '<div class="title"><img src= "ico/duels.gif"> <a href = "duels.php">Дуэли</a> '.$zag.' <b>Просмотр</b></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> ('.$d.') | <a href = "duels.php?act=add_list">Мои вызовы</a> ('.$da.')';
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 'Побед: '.$duels_victory.'<br/>';
echo 'Поражений: '.$duels_victory2.'<br/>';
echo 'Ничьих: '.$duels_victory3.'<br/>';
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 @$i % 2 ? '<div class="div">' : '<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 '<img src = "ico/clock.png"> '.vremya($duel['time_end']).'<br/>';
$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_votes` WHERE `vote` = '1' AND `duel` = '".$duel['id']."'"), 0);
if(ban($user1['id']) || ($user1['delete'] == 1)){
echo '<a href = "/'.$user1['id'].'"><del>'.$user1['login'].'</del></a> ('.$count.') ';
} else {
echo '<a href = "/'.$user1['id'].'">'.$user1['login'].'</a> ('.$count.') ';
}
echo ' <b>vs</b> ';
$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_votes` WHERE `vote` = '2' AND `duel` = '".$duel['id']."'"), 0);
if(ban($user2['id']) || ($user2['delete'] == 1)){
echo ' <a href = "/'.$user2['id'].'"><del>'.$user2['login'].'</del></a> ('.$count.')';
} else {
echo ' <a href = "/'.$user2['id'].'">'.$user2['login'].'</a> ('.$count.')';
}
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 '<img src = "ico/clock.png"> Осталось: '.$chas.' '.$min.'<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);
if(ban($user1['id']) || ($user1['delete'] == 1)){
echo '<br/><a href = "/'.$user1['id'].'"><del>'.$user1['login'].'</del></a> ('.$count.')<br/>';
} else {
echo '<br/><a href = "/'.$user1['id'].'">'.$user1['login'].'</a> ('.$count.')<br/>';
}
if($vote_acces == true) echo '<a href = "duels.php?act=view&id='.$id.'&duel='.$duel['id'].'&vote=1">Голосовать</a>';
echo '</td>
<td VALIGN=top>';
echo '<br/>vs ';
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);
if(ban($user2['id']) || ($user2['delete'] == 1)){
echo '<br/><a href = "/'.$user2['id'].'"><del>'.$user2['login'].'</del></a> ('.$count.')<br/>';
} else {
echo '<br/><a href = "/'.$user2['id'].'">'.$user2['login'].'</a> ('.$count.')<br/>';
}
if($vote_acces == true) echo '<a href = "duels.php?act=view&id='.$id.'&duel='.$duel['id'].'&vote=2">Голосовать</a>';
echo '</td>
</tr>
</table>';
echo '</div>';
@$i++;
}
}
echo '</div>';
navigation($page, $total,'duels.php?act=view&id='.$id.'&');
}else{
error(' Дуэлей нет !');
}
echo '</div>';
require('foot.php');
break;
//~~~~~~~~~~~~~~~~~~~~~Список всех дуэлей~~~~~~~~~~~~~~~~~~~~~~//
default:
$title = $title.' | Дуэли';
require('head.php');
require('core/duel_ava.php');
echo '<div class="title"><img src= "ico/duels.gif"> <a href = "duels.php">Дуэли</a> <b>Просмотр</b></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> ('.$d.') | <a href = "duels.php?act=add_list">Мои вызовы</a> ('.$da.')';
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 @$i % 2 ? '<div class="div">' : '<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 '<img src = "ico/clock.png"> Осталось: '.$chas.' '.$min.'<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);
if(ban($user1['id']) || ($user1['delete'] == 1)){
echo '</br><a href = "/'.$user1['id'].'"><del>'.$user1['login'].'</del></a> ('.$count.')</br>';
} else {
echo '</br><a href = "/'.$user1['id'].'">'.$user1['login'].'</a> ('.$count.')</br>';
}
if($vote_acces == true) echo '<a href = "duels.php?id='.$duel['id'].'&vote=1">Голосовать</a>';
echo '</td>
<td VALIGN=top>';
echo '</br><b>vs</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);
if(ban($user2['id']) || ($user2['delete'] == 1)){
echo '</br><a href = "/'.$user2['id'].'"><del>'.$user2['login'].'</del></a> ('.$count.')</br>';
} else {
echo '</br><a href = "/'.$user2['id'].'">'.$user2['login'].'</a> ('.$count.')</br>';
}
if($vote_acces == true) echo '<a href = "duels.php?id='.$duel['id'].'&vote=2">Голосовать</a>';
echo '</td>
</tr>
</table>';
echo '</div>';
@$i++;
}
echo '</div>';
navigation($page, $total,'duels.php?');
}else{
error(' Дуэлей нет !');
}
echo '</div>';
require('foot.php');
break;
}
?>