<?
//
//
require_once($_SERVER['DOCUMENT_ROOT']."/jquery/inc/system.php");
//
//
$m1 = DB::$dbs->queryFetch("SELECT * FROM `users` WHERE `tour` >= ? ORDER BY `tour` DESC LIMIT 1", array(1)); 
//
//
if($m1['tour'] >= 1){
//
//
$coll1 = intval($m1['tour']*10/300);
$s1 = intval($m1['liga_type']*25000);
//
//
if($m1){
DB::$dbs->query("UPDATE `users` SET `gold` = `gold` + ?, `silver` = `silver` + ? WHERE `id` = ? LIMIT 1", array($coll1,$s1,$m1['id'])); 
}
//
//
$m2 = DB::$dbs->queryFetch("SELECT * FROM `users` WHERE `tour` <= ? AND `id` != ? ORDER BY `tour` DESC LIMIT 1", array($m1['tour'],$m1['id'])); 
//
//
$coll2 = intval($m2['tour']*10/300);
$s2 = intval($m2['liga_type']*25000);
//
//
if($m2){
DB::$dbs->query("UPDATE `users` SET `gold` = `gold` + ?, `silver` = `silver` + ? WHERE `id` = ? LIMIT 1", array($coll2,$s2,$m2['id'])); 
}
//
//
$m3 = DB::$dbs->queryFetch("SELECT * FROM `users` WHERE `tour` <= ? AND `id` != ? AND `id` != ? ORDER BY `tour` DESC LIMIT 1", array($m2['tour'],$m1['id'],$m2['id']));
//
//
$coll3 = intval($m3['tour']*10/300);
$s3 = intval($m3['liga_type']*25000);
//
//
if($m3){
DB::$dbs->query("UPDATE `users` SET `gold` = `gold` + ?, `silver` = `silver` + ? WHERE `id` = ? LIMIT 1", array($coll3,$s3,$m3['id'])); 
} 
//
//
$m4 = DB::$dbs->queryFetch("SELECT * FROM `users` WHERE `tour` <= ? AND `id` != ? AND `id` != ? AND `id` != ? ORDER BY `tour` DESC LIMIT 1", array($m3['tour'],$m1['id'],$m2['id'],$m3['id'])); 
//
//
$coll4 = intval($m4['tour']*10/300);
$s4 = intval($m4['liga_type']*25000);
//
//
if($m4){
DB::$dbs->query("UPDATE `users` SET `gold` = `gold` + ?, `silver` = `silver` + ? WHERE `id` = ? LIMIT 1", array($coll4,$s4,$m4['id'])); 
}
//
//
$m5 = DB::$dbs->queryFetch("SELECT * FROM `users` WHERE `tour` <= ? AND `id` != ? AND `id` != ? AND `id` != ? AND `id` != ? ORDER BY `tour` DESC LIMIT 1", array($m4['tour'],$m1['id'],$m2['id'],$m3['id'],$m4['id'])); 
//
//
$coll5 = intval($m5['tour']*10/300);
$s5 = intval($m5['liga_type']*25000);
//
//
if($m5){
DB::$dbs->query("UPDATE `users` SET `gold` = `gold` + ?, `silver` = `silver` + ? WHERE `id` = ? LIMIT 1", array($coll5,$s5,$m5['id'])); 
}
//
//
$m6 = DB::$dbs->queryFetch("SELECT * FROM `users` WHERE `tour` <= ? AND `id` != ? AND `id` != ? AND `id` != ? AND `id` != ? AND `id` != ? ORDER BY `tour` DESC LIMIT 1", array($m5['tour'],$m1['id'],$m2['id'],$m3['id'],$m4['id'],$m5['id'])); 
//
//
$coll6 = intval($m6['tour']*10/300);
$s6 = intval($m6['liga_type']*25000);
//
//
if($m6){
DB::$dbs->query("UPDATE `users` SET `gold` = `gold` + ?, `silver` = `silver` + ? WHERE `id` = ? LIMIT 1", array($coll6,$s6,$m6['id'])); 
}
//
//
$m7 = DB::$dbs->queryFetch("SELECT * FROM `users` WHERE `tour` <= ? AND `id` != ? AND `id` != ? AND `id` != ? AND `id` != ? AND `id` != ? AND `id` != ? ORDER BY `tour` DESC LIMIT 1", array($m6['tour'],$m1['id'],$m2['id'],$m3['id'],$m4['id'],$m5['id'],$m6['id'])); 
//
//
$coll7 = intval($m7['tour']*10/300);
$s7 = intval($m7['liga_type']*25000);
//
//
if($m7){
DB::$dbs->query("UPDATE `users` SET `gold` = `gold` + ?, `silver` = `silver` + ? WHERE `id` = ? LIMIT 1", array($coll7,$s7,$m7['id'])); 
}
//
//
$m8 = DB::$dbs->queryFetch("SELECT * FROM `users` WHERE `tour` <= ? AND `id` != ? AND `id` != ? AND `id` != ? AND `id` != ? AND `id` != ? AND `id` != ? AND `id` != ? ORDER BY `tour` DESC LIMIT 1", array($m7['tour'],$m1['id'],$m2['id'],$m3['id'],$m4['id'],$m5['id'],$m6['id'],$m7['id'])); 
//
//
$coll8 = intval($m8['tour']*10/300);
$s8 = intval($m8['liga_type']*25000);
//
//
if($m8){
DB::$dbs->query("UPDATE `users` SET `gold` = `gold` + ?, `silver` = `silver` + ? WHERE `id` = ? LIMIT 1", array($coll8,$s8,$m8['id'])); 
}
//
//
$m9 = DB::$dbs->queryFetch("SELECT * FROM `users` WHERE `tour` <= ? AND `id` != ? AND `id` != ? AND `id` != ? AND `id` != ? AND `id` != ? AND `id` != ? AND `id` != ? AND `id` != ? ORDER BY `tour` DESC LIMIT 1", array($m8['tour'],$m1['id'],$m2['id'],$m3['id'],$m4['id'],$m5['id'],$m6['id'],$m7['id'],$m8['id'])); 
//
//
$coll9 = intval($m8['tour']*10/300);
$s9 = intval($m9['liga_type']*25000);
//
//
if($m9){
DB::$dbs->query("UPDATE `users` SET `gold` = `gold` + ?, `silver` = `silver` + ? WHERE `id` = ? LIMIT 1", array($coll9,$s9,$m9['id'])); 
}
//
//
$m10 = DB::$dbs->queryFetch("SELECT * FROM `users` WHERE `tour` <= ? AND `id` != ? AND `id` != ? AND `id` != ? AND `id` != ? AND `id` != ? AND `id` != ? AND `id` != ? AND `id` != ? AND `id` != ? ORDER BY `tour` DESC LIMIT 1", array($m9['tour'],$m1['id'],$m2['id'],$m3['id'],$m4['id'],$m5['id'],$m6['id'],$m7['id'],$m8['id'],$m9['id'])); 
//
//
$coll10 = intval($m10['tour']*10/300);
$s10 = intval($m10['liga_type']*25000);
//
//
if($m10){
DB::$dbs->query("UPDATE `users` SET `gold` = `gold` + ?, `silver` = `silver` + ? WHERE `id` = ? LIMIT 1", array($coll10,$s10,$m10['id'])); 
}
//
//
$text = "Подведены итоги турнира:[br][br]

".($m1 ? "1. [img=https://mters.ru/css/img/gender_".$m1['gender'].".png]16[/img] ".$m1['name']." - [img=https://mters.ru/css/img/gold.png]16[/img] [color=#F2C234]".intval($m1['tour']*15/300)." [/color] [img=https://mters.ru/css/img/silver.png]16[/img] [color=silver]".intval($m1['liga_type']*25000)." [/color]" : "")."
".($m2 ? "[br]2. [img=https://mters.ru/css/img/gender_".$m2['gender'].".png]16[/img] ".$m2['name']." - [img=https://mters.ru/css/img/gold.png]16[/img] [color=#F2C234]".intval($m2['tour']*15/300)." [/color] [img=https://mters.ru/css/img/silver.png]16[/img] [color=silver]".intval($m2['liga_type']*25000)." [/color]" : "")."
".($m3 ? "[br]3. [img=https://mters.ru/css/img/gender_".$m3['gender'].".png]16[/img] ".$m3['name']." - [img=https://mters.ru/css/img/gold.png]16[/img] [color=#F2C234]".intval($m3['tour']*15/300)." [/color] [img=https://mters.ru/css/img/silver.png]16[/img] [color=silver]".intval($m3['liga_type']*25000)." [/color]" : "")."
".($m4 ? "[br]4. [img=https://mters.ru/css/img/gender_".$m4['gender'].".png]16[/img] ".$m4['name']." - [img=https://mters.ru/css/img/gold.png]16[/img] [color=#F2C234]".intval($m4['tour']*15/300)." [/color] [img=https://mters.ru/css/img/silver.png]16[/img] [color=silver]".intval($m4['liga_type']*25000)." [/color]" : "")."
".($m5 ? "[br]5. [img=https://mters.ru/css/img/gender_".$m5['gender'].".png]16[/img] ".$m5['name']." - [img=https://mters.ru/css/img/gold.png]16[/img] [color=#F2C234]".intval($m5['tour']*15/300)." [/color] [img=https://mters.ru/css/img/silver.png]16[/img] [color=silver]".intval($m5['liga_type']*25000)." [/color]" : "")."
".($m6 ? "[br]6. [img=https://mters.ru/css/img/gender_".$m6['gender'].".png]16[/img] ".$m6['name']." - [img=https://mters.ru/css/img/gold.png]16[/img] [color=#F2C234]".intval($m6['tour']*15/300)." [/color] [img=https://mters.ru/css/img/silver.png]16[/img] [color=silver]".intval($m6['liga_type']*25000)." [/color]" : "")."
".($m7 ? "[br]7. [img=https://mters.ru/css/img/gender_".$m7['gender'].".png]16[/img] ".$m7['name']." - [img=https://mters.ru/css/img/gold.png]16[/img] [color=#F2C234]".intval($m7['tour']*15/300)." [/color] [img=https://mters.ru/css/img/silver.png]16[/img] [color=silver]".intval($m7['liga_type']*25000)." [/color]" : "")."
".($m8 ? "[br]8. [img=https://mters.ru/css/img/gender_".$m8['gender'].".png]16[/img] ".$m8['name']." - [img=https://mters.ru/css/img/gold.png]16[/img] [color=#F2C234]".intval($m8['tour']*15/300)." [/color] [img=https://mters.ru/css/img/silver.png]16[/img] [color=silver]".intval($m8['liga_type']*25000)." [/color]" : "")."
".($m9 ? "[br]9. [img=https://mters.ru/css/img/gender_".$m9['gender'].".png]16[/img] ".$m9['name']." - [img=https://mters.ru/css/img/gold.png]16[/img] [color=#F2C234]".intval($m9['tour']*15/300)." [/color] [img=https://mters.ru/css/img/silver.png]16[/img] [color=silver]".intval($m9['liga_type']*25000)." [/color]" : "")."
".($m10 ? "[br]10. [img=https://mters.ru/css/img/gender_".$m10['gender'].".png]16[/img] ".$m10['name']." - [img=https://mters.ru/css/img/gold.png]16[/img] [color=#F2C234]".intval($m10['tour']*15/300)." [/color] [img=https://mters.ru/css/img/silver.png]16[/img] [color=silver]".intval($m10['liga_type']*25000)." [/color]" : "")."
[br][br]
Поздравляем всех победителей! 
";
//
//
$name = "Турнир арены";
//
//
DB::$dbs->query("INSERT INTO `news` SET `time` = ?, `name` = ?, `text` = ?", array(time(),$name,$text));
//
//
DB::$dbs->query("UPDATE `users` SET `tour_time` = ?, `tour` = ?, `news` = ?, `liga_type` = ?, `liga_coll` = ?", array(time()+86400*7,0,1,1,0)); 
//
//
}
//
//
?>