<?
require_once ('../system/func.php');
if(date("l", time()) == 'Monday')$date = (time()+60*60*24*5); // Понедельник, записываем на 5 дней
elseif(date("l", time()) == 'Saturday')$date = (time()+60*60*24*2); // Суббота, записываем на 2 день
$t = mysql_query("SELECT * FROM `turnir_chereps` ORDER BY `id` DESC LIMIT 1");
$t = mysql_fetch_array($t);
if(!$t){
mysql_query("INSERT INTO `turnir_chereps` SET `date` = '".$date."'");
exit();
}
if($t['start'] == 1 and $t['date']-60*5 <= time()){
$q = mysql_query("SELECT * FROM `users` WHERE `chereps` >= '1' ORDER BY `chereps` DESC");
while($post = mysql_fetch_assoc($q)) {
$i++;
$ank = $post;
$crystals = num($post['chereps']*9);
if($i == 1){
mysql_query("UPDATE `users` SET `gold` = '".($post['gold']+150)."', `crystals` = '".($post['crystals']+$crystals)."' WHERE `id` = '".$post['id']."' LIMIT 1");
$text = "Турнир по черепам на ".date("j.n.Y")." окончен![br]Вы заработали [img]/images/icons/gold.png[/img] 150 золота и [img]/images/icons/crystal.png[/img] ".$crystals." кристаллов";
mysql_query("INSERT INTO `mail` SET `in` = '0', `out` = '".$ank['id']."', `text` = '$text' , `time` = '".time()."'");
$kont = mysql_fetch_assoc(mysql_query("SELECT * FROM `kont` WHERE `id_user` = '".$ank['id']."' && `id_kont` = '0' LIMIT 1"));
if(!$kont){
mysql_query("INSERT INTO `kont` SET `id_user` = '".$ank['id']."', `id_kont` = '0', `time` = '".time()."'");
}else{
mysql_query("update `kont` set `time` = '".time()."' WHERE `id_user` = '".$ank['id']."' AND `id_kont` = '0'");
}
}elseif($i == 2){
mysql_query("UPDATE `users` SET `gold` = '".($post['gold']+125)."', `crystals` = '".($post['crystals']+$crystals)."' WHERE `id` = '".$post['id']."' LIMIT 1");
$text = "Турнир по черепам на ".date("j.n.Y")." окончен![br]Вы заработали [img]/images/icons/gold.png[/img] 125 золота и [img]/images/icons/crystal.png[/img] ".$crystals." кристаллов";
mysql_query("INSERT INTO `mail` SET `in` = '0', `out` = '".$ank['id']."', `text` = '$text' , `time` = '".time()."'");
$kont = mysql_fetch_assoc(mysql_query("SELECT * FROM `kont` WHERE `id_user` = '".$ank['id']."' && `id_kont` = '0' LIMIT 1"));
if(!$kont){
mysql_query("INSERT INTO `kont` SET `id_user` = '".$ank['id']."', `id_kont` = '0', `time` = '".time()."'");
}else{
mysql_query("update `kont` set `time` = '".time()."' WHERE `id_user` = '".$ank['id']."' AND `id_kont` = '0'");
}
}elseif($i == 3){
mysql_query("UPDATE `users` SET `gold` = '".($post['gold']+100)."', `crystals` = '".($post['crystals']+$crystals)."' WHERE `id` = '".$post['id']."' LIMIT 1");
$text = "Турнир по черепам на ".date("j.n.Y")." окончен![br]Вы заработали [img]/images/icons/gold.png[/img] 100 золота и [img]/images/icons/crystal.png[/img] ".$crystals." кристаллов";
mysql_query("INSERT INTO `mail` SET `in` = '0', `out` = '".$ank['id']."', `text` = '$text' , `time` = '".time()."'");
$kont = mysql_fetch_assoc(mysql_query("SELECT * FROM `kont` WHERE `id_user` = '".$ank['id']."' && `id_kont` = '0' LIMIT 1"));
if(!$kont){
mysql_query("INSERT INTO `kont` SET `id_user` = '".$ank['id']."', `id_kont` = '0', `time` = '".time()."'");
}else{
mysql_query("update `kont` set `time` = '".time()."' WHERE `id_user` = '".$ank['id']."' AND `id_kont` = '0'");
}
}elseif($i == 4){
mysql_query("UPDATE `users` SET `gold` = '".($post['gold']+75)."', `crystals` = '".($post['crystals']+$crystals)."' WHERE `id` = '".$post['id']."' LIMIT 1");
$text = "Турнир по черепам на ".date("j.n.Y")." окончен![br]Вы заработали [img]/images/icons/gold.png[/img] 75 золота и [img]/images/icons/crystal.png[/img] ".$crystals." кристаллов";
mysql_query("INSERT INTO `mail` SET `in` = '0', `out` = '".$ank['id']."', `text` = '$text' , `time` = '".time()."'");
$kont = mysql_fetch_assoc(mysql_query("SELECT * FROM `kont` WHERE `id_user` = '".$ank['id']."' && `id_kont` = '0' LIMIT 1"));
if(!$kont){
mysql_query("INSERT INTO `kont` SET `id_user` = '".$ank['id']."', `id_kont` = '0', `time` = '".time()."'");
}else{
mysql_query("update `kont` set `time` = '".time()."' WHERE `id_user` = '".$ank['id']."' AND `id_kont` = '0'");
}
}elseif($i == 5){
mysql_query("UPDATE `users` SET `gold` = '".($post['gold']+50)."', `crystals` = '".($post['crystals']+$crystals)."' WHERE `id` = '".$post['id']."' LIMIT 1");
$text = "Турнир по черепам на ".date("j.n.Y")." окончен![br]Вы заработали [img]/images/icons/gold.png[/img] 50 золота и [img]/images/icons/crystal.png[/img] ".$crystals." кристаллов";
mysql_query("INSERT INTO `mail` SET `in` = '0', `out` = '".$ank['id']."', `text` = '$text' , `time` = '".time()."'");
$kont = mysql_fetch_assoc(mysql_query("SELECT * FROM `kont` WHERE `id_user` = '".$ank['id']."' && `id_kont` = '0' LIMIT 1"));
if(!$kont){
mysql_query("INSERT INTO `kont` SET `id_user` = '".$ank['id']."', `id_kont` = '0', `time` = '".time()."'");
}else{
mysql_query("update `kont` set `time` = '".time()."' WHERE `id_user` = '".$ank['id']."' AND `id_kont` = '0'");
}
}else{
mysql_query("UPDATE `users` SET `crystals` = '".($post['crystals']+$crystals)."' WHERE `id` = '".$post['id']."' LIMIT 1");
$text = "Турнир по черепам на ".date("j.n.Y")." окончен![br]Вы заработали [img]/images/icons/crystal.png.png[/img] ".$crystals." кристаллов";
mysql_query("INSERT INTO `mail` SET `in` = '0', `out` = '".$ank['id']."', `text` = '$text' , `time` = '".time()."'");
$kont = mysql_fetch_assoc(mysql_query("SELECT * FROM `kont` WHERE `id_user` = '".$ank['id']."' && `id_kont` = '0' LIMIT 1"));
if(!$kont){
mysql_query("INSERT INTO `kont` SET `id_user` = '".$ank['id']."', `id_kont` = '0', `time` = '".time()."'");
}else{
mysql_query("update `kont` set `time` = '".time()."' WHERE `id_user` = '".$ank['id']."' AND `id_kont` = '0'");
}
}
}
$m1 = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `chereps` >= '1' ORDER BY `chereps` DESC LIMIT 1"));
$m2 = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `chereps` <= '$m1[chereps]' AND `id` != '$m1[id]' ORDER BY `chereps` DESC LIMIT 1"));
$m3 = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `chereps` <= '$m2[chereps]' AND `id` != '$m1[id]' AND `id` != '$m2[id]' ORDER BY `chereps` DESC LIMIT 1"));
$m4 = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `chereps` <= '$m3[chereps]' AND `id` != '$m1[id]' AND `id` != '$m2[id]' AND `id` != '$m3[id]' ORDER BY `chereps` DESC LIMIT 1"));
$m5 = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `chereps` <= '$m4[chereps]' AND `id` != '$m1[id]' AND `id` != '$m2[id]' AND `id` != '$m3[id]' AND `id` != '$m4[id]' ORDER BY `chereps` DESC LIMIT 1"));
$text = "[center]Турнир по черепам на ".date("j.n.Y")." окончен![br][br]
[b]Победители:[/b][br][br]
".($m1 ? "1. $m1[login] - 150 золота" : "")."
".($m2 ? "[br]2. $m2[login] - 125 золота" : "")."
".($m3 ? "[br]3. $m3[login] - 100 золота" : "")."
".($m4 ? "[br]3. $m4[login] - 75 золота" : "")."
".($m5 ? "[br]3. $m5[login] - 50 золота" : "")."
[/center]";
$name = "Турнир по черепам на ".date("j.n.Y")."";
mysql_query("UPDATE users SET news_read = '1'");
mysql_query("INSERT INTO `topic` SET `id_forum` = '1', `id_user` = '1', `name` = '$name', `text` = '$text', `time` = '".time()."', `onlick` = '".time()."'");
mysql_query("UPDATE `users` SET `chereps` = '0'");
mysql_query("UPDATE `turnir_chereps` SET `start` = '2' WHERE `id` = '".$t['id']."' LIMIT 1");
mysql_query("INSERT INTO `turnir_chereps` SET `date` = '".$date."'");
}elseif($t['start'] == 0 and $t['date']-60*5 <= time()){
mysql_query("UPDATE `turnir_chereps` SET `start` = '1', `date` = '".$date."' WHERE `id` = '".$t['id']."' LIMIT 1");
}
?>