Файл: tjersy.worldbyte.net/turnir.php
Строк: 236
<?php
require_once 'inc/system.php';
require_once 'inc/head.php';
no_auth();
##################################
$tsettings = mysql_fetch_array(mysql_query("SELECT * FROM `turnir_settings`"));
$lider = mysql_fetch_array(mysql_query("SELECT * FROM turnir ORDER BY `win` DESC"));
##################################
if($tsettings['status'] == 0){
echo '<div class="register_title"> ПОБЕДИТЕЛЬ </div>';
$t = mysql_query("SELECT * FROM `turnir` WHERE `win` != '0' ORDER BY `win` DESC LIMIT 1");
$twin = mysql_query("SELECT * FROM `turnir` ORDER BY `win` DESC LIMIT 1");
##########################################################################
$twi = mysql_query("SELECT * FROM `turnir` ORDER BY `win` DESC LIMIT 1");
$twin = mysql_fetch_array($twi);
##########################################################################
$cnt_win = mysql_num_rows($t);
if($cnt_win == '0') echo '<div class="register_form">В данном турнире нет победителя.</div>';
while($tw = mysql_fetch_array($t)){
echo '<div class="tur_form">';
echo '<img src="'.$tw['car'].'" alt="'.$tw['carname'].'" width="270" alt=" "/> <br/>';
echo '<img src="/system/img/crown_gold.png"> '.giu($tw['id_user']).' <br/>';
echo 'Побед в турнире: <b>'.$tw['win'].'</b><br/>';
echo '<a href="/guest/'.$tw['id_user'].'"><input style="width: 80%;" type="button" value="ГАРАЖ ИГРОКА" class="button" /></a>';
echo '</div>';
}
echo '<div class="register_info"> ТОП '.$tsettings['top'].' УЧАСТНИКОВ </div>';
$tt = mysql_query("SELECT * FROM `turnir` WHERE `id_user` != '$twin[id_user]' AND `win` != '0' ORDER BY `win` DESC LIMIT $tsettings[top]");
$cnt_top = mysql_num_rows($tt);
if($cnt_top == '0') echo '<div class="register_form">В данном турнире нет участников.</div>';
while($top = mysql_fetch_array($tt)){
echo '<div class="tur_form">';
echo '<img src="'.$top['car'].'" alt="'.$top['carname'].'" width="270" alt=" "/><br>';
echo '<img src="/system/img/crown_silver.png"> '.giu($top['id_user']).'<br>';
echo 'Побед в турнире: <b>'.$top['win'].'</b><br/>';
echo '<a href="/guest/'.$top['id_user'].'"><input style="width: 80%;" type="button" value="ГАРАЖ ИГРОКА" class="button" /></font></a><br/>';
echo '</div>';
}
echo '<div class="foots_link">'.$tsettings['car'].'</div>';
##################################
} else {
##################################
if(isset($_POST['start'])){
if($US['carname'] != $tsettings['car']){
okay('Ваш автомобиль не подходит для этого турнира ');
include_once 'system/inc/foot.php';
exit();
}
$query = mysql_query("SELECT COUNT(id_user) FROM turnir WHERE `id_user` = '".$US['id']."'") or die(mysql_error());
if(mysql_result($query22, 0) > 0){
header('Location: /turnir');
exit();
}else{
mysql_query("INSERT INTO `turnir` (id_user, car, win, vilet) VALUES('$data_user[id]', '$data_user[car]', '0', '0')") or die(mysql_error());
}
}
##################################
$iquery = mysql_result(mysql_query("SELECT COUNT(*) FROM `turnir` WHERE `id_user` = '".$US['id']."'"), 0);
if($iquery > '0'){
$DT = mysql_fetch_assoc(mysql_query("SELECT * FROM `turnir` WHERE `id_user` = '".$US['id']."'"));
if($DT['vilet'] == 1){
if(isset($_POST['pop'])){
if($US['money2'] < '2'){
header("location: /donate");
} else {
$result = $US['money2'] - 2;
mysql_query("UPDATE `turnir` SET `vilet` = '0', `win` = '0' WHERE `id_user` = '".$US['id']."'");
mysql_query("UPDATE `users` SET `money2` = '$result', `wintur` = '0' WHERE `id` = '".$US['id']."'") or die(mysql_query());
header("location: /turnir");
}
}
echo '<div class="register_title"> ВЫЛЕТ </div>';
echo '<div class="register_txt">';
echo ''.$US['nick'].', Вы покидаете турнир.<br/> Вы можете взять еще попытку за 2 <img width="14px" src="/system/img/money2.png" alt="Золото" />, но все Ваши заезды аннулируются.';
echo '</div>';
echo '<form action="" method="post">';
echo '<input type="submit" name="pop" class="register_btn" value="ВЗЯТЬ ПОПЫТКУ" />';
echo '</form>';
##############################
} else {
##############################
$DV_query = mysql_query("SELECT * FROM `turnir` WHERE `id_user` != '".$US['id']."' AND `vilet` = '0' AND `win` >= '".$US['wintop']."' ORDER BY RAND() LIMIT 1");
$DV = mysql_fetch_array($DV_query);
$V = mysql_query("SELECT * FROM `users` WHERE `id` = '".$DV['id_user']."' AND `carname` = '".$tsettings['car']."' LIMIT 1");
$VS = mysql_fetch_array($V);
$cnt = mysql_num_rows($V);
if($cnt < '1'){
echo '<div class="register_title"> ТУРНИР </div>';
echo '<div class="register_text" style="border-radius: 0px 0px 7px 7px;"><center> Нет соперника.<br/> Требуется немного подождать.<br/> Ваши победы: '.$US['wintur'].' <br/><a href="/turnir"><input style="width: 80%;" type="button" value="ОБНОВИТЬ" class="button" /></a></center></div>';
include_once 'system/inc/foot.php';
exit();
}
$lid = mysql_fetch_array(mysql_query("SELECT * FROM `turnir` WHERE `win` != '0' ORDER BY `win` DESC LIMIT 1"));
if($lid['id_user'] == $US['id']){
echo '<div class="register_title"> ТУРНИР </div>';
echo '<div style="border-radius: 0px 0px 7px 7px;" class="register_text"><center>
Вы лидируете в турнире.<br/> Ваши победы: <b>'.$US['wintur'].'</b> <br/><a href="/turnir"><input style="width: 80%;" type="button" value="ОБНОВИТЬ" class="button" /></a></center></div>';
include_once 'system/inc/foot.php';
exit();
}
##############################
if(isset($_POST['prin'])){
if($US['carname'] != $tsettings['car']){
okay('Ваш автомобиль не подходит для этого турнира ');
include_once 'system/inc/foot.php';
exit();
}
$random = rand(1,2);
if($US['id'] == $VS['id']){
header("location: /turnir");
exit();
}
if($US['fuel'] < $tsettings['fuel'])
{
header("location: /filling");
} else {
if(speed($US['id']) >= speed($VS['id'])){
mysql_query("UPDATE `turnir` SET `win` = `win` + '1' WHERE `id_user` = '".$US['id']."'") or die(mysql_error());
mysql_query("UPDATE `users` SET `wintur` = `wintur` + '1' WHERE `id` = '".$US['id']."'") or die(mysql_error());
mysql_query("UPDATE `users` SET `fuel` = `fuel` - '".$tsettings['fuel']."' WHERE `id` = '".$US['id']."'") or die(mysql_error());
if($US['nitro_50'] > '0'){
mysql_query("UPDATE `users` SET `nitro_50` = `nitro_50` - '1' WHERE `id` = '".$US['id']."'") or die(mysql_error());
}
if($US['nitro_100'] > '0'){
mysql_query("UPDATE `users` SET `nitro_100` = `nitro_100` - '1' WHERE `id` = '".$US['id']."'") or die(mysql_error());
}
header("location: /turnir");
}
elseif(speed($US['id']) < speed($VS['id']) && $random == '1'){
mysql_query("UPDATE `turnir` SET `win` = `win` + '1' WHERE `id_user` = '".$US['id']."'") or die(mysql_error());
mysql_query("UPDATE `users` SET `wintur` = `wintur` + '1' WHERE `id` = '".$US['id']."'") or die(mysql_error());
mysql_query("UPDATE `users` SET `fuel` = `fuel` - '".$tsettings['fuel']."' WHERE `id` = '".$US['id']."'") or die(mysql_error());
if($US['nitro_50'] > '0'){
mysql_query("UPDATE `users` SET `nitro_50` = `nitro_50` - '1' WHERE `id` = '".$US['id']."'") or die(mysql_error());
}
if($US['nitro_100'] > '0'){
mysql_query("UPDATE `users` SET `nitro_100` = `nitro_100` - '1' WHERE `id` = '".$US['id']."'") or die(mysql_error());
}
header("location: /turnir");
}
elseif(speed($US['id']) < speed($VS['id']) && $random == '2'){
mysql_query("UPDATE `turnir` SET `vilet` = '1' WHERE `id_user` = '".$US['id']."'") or die(mysql_error());
mysql_query("UPDATE `users` SET `fuel` = `fuel` - '".$tsettings['fuel']."' WHERE `id` = '".$US['id']."'") or die(mysql_error());
if($US['nitro_50'] > '0'){
mysql_query("UPDATE `users` SET `nitro_50` = `nitro_50` - '1' WHERE `id` = '".$US['id']."'") or die(mysql_error());
}
if($US['nitro_100'] > '0'){
mysql_query("UPDATE `users` SET `nitro_100` = `nitro_100` - '1' WHERE `id` = '".$US['id']."'") or die(mysql_error());
}
header("location: /turnir");
}
}
}
##############################
$count = mysql_query("SELECT * FROM `turnir` WHERE `id_user` != '".$US['id']."' AND `vilet` = '0' AND `win` >= '".$US['wintop']."'");
$cnt_tur = mysql_num_rows($count);
okey('Количество Ваших побед: '.$US['wintur'].'<br/>Всего участников: '.$cnt_tur.'');
echo '<div class="register_title"> Соперник: '.$VS['nick'].' </div>';
echo '<div class="register_txt" style="border-radius: 0px 0px 7px 7px;text-align: center;">';
echo '<br/><br/><img src="'.$VS['car'].'" alt="'.$VS['carname'].'" width="270" alt=" "/> <br/><br/>';
echo '<hr/>';
echo '<form method="post">';
echo '<input type="submit" name="prin" class="button" value="ПРИНЯТЬ" /> <a href="/turnir"><input type="button" class="button" value="ОБНОВИТЬ" /></a>';
echo '</form>';
echo '</div>';
echo '</div>';
}
##############################
} else {
##############################
$imgcar = mysql_fetch_array(mysql_query("SELECT * FROM `auto` WHERE `carname` = '".$tsettings['car']."'"));
$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `turnir`"), 0);
echo '<div class="register_title"> ТУРНИР </div>';
echo '<div class="register_form">';
echo '<img src="'.$imgcar['car'].'" alt="'.$imgcar['carname'].'" width="270" alt=" "/> <br/>';
echo 'Турнирный автомобиль: '.$imgcar['carname'].' <br/>';
echo 'В турнире участвуют <b>'.$count.'</b> чел. <br/>';
echo '</div>';
echo '<div class="register_info"> ОПИСАНИЕ </div>';
echo '<div class="register_txt">';
echo 'На каждый заезд в турнире Вы тратите '.$tsettings['fuel'].' литров бензина. <br/>';
echo 'Побеждает тот, кто к концу турнира одержит больше всего побед!<br/>
В случае поражения Вы покидаете турнир.
Побежденный Вами гонщик не покидает турнир, пока сам не проиграет.<br>';
echo '</div>';
echo '<div class="register_info"> ПОБЕДИТЕЛЬ ПОЛУЧИТ </div>';
echo '<div class="register_txt">';
echo '<img width="14px" src="/system/img/money.png" alt="Серебро" /> '.$tsettings['money_win'].' <br/>';
echo '<img width="14px" src="/system/img/money2.png" alt="Золото" /> '.$tsettings['zoloto_win'].' <br/>';
echo '<img width="14px" src="/system/img/star.png" alt="Авторитет" /> '.$tsettings['raiting_win'].' <br/>';
echo '<img width="14px" src="/system/img/settings.png" alt="Гайки" /> '.$tsettings['coins'].' <br/>';
echo '</div>';
echo '<div class="register_info"> ТОП '.$tsettings['top'].' ПОЛУЧАТ </div>';
echo '<div class="register_txt">';
echo '<img width="14px" src="/system/img/money.png" alt="Серебро" /> '.$tsettings['money_top'].' <br/>';
echo '<img width="14px" src="/system/img/money2.png" alt="Золото" /> '.$tsettings['zoloto_top'].' <br/>';
echo '<img width="14px" src="/system/img/star.png" alt="Авторитет" /> '.$tsettings['raiting_top'].' <br/>';
echo '</div>';
if($US['carname'] != $tsettings['car']){
echo '<input type="submit" class="register_btn" value="СМЕНИТЕ АВТОМОБИЛЬ" />';
} else {
echo '<form method="post"><input type="submit" name="start" class="register_btn" value="НАЧАТЬ ТУРНИР" /></form>';
}
}
}
##################################
include_once 'system/inc/foot.php';
?>