<?
require_once '../core/system.php';
echo only_reg();
$header = 'Осада';
require_once '../core/head.php';
if((strtotime("11:30")-60<=time() AND strtotime("11:30")+60>=time()) OR (strtotime("15:30")-60<=time() AND strtotime("15:30")+60>=time()) OR (strtotime("20:30")-60<=time() AND strtotime("20:30")+60>=time())){
$spis = mysql_query("SELECT * FROM `zamki` order by `id` asc");
while($s = mysql_fetch_assoc($spis)){
$uscc = mysql_query("SELECT * FROM `zamki_user` WHERE zid='$s[id]'");
if(mysql_num_rows($uscc)){
	echo'z';
mysql_query("UPDATE `zamki` SET status='1',starazh1s='1',starazh2s='1',kings='1',starazh1h='".$s[strazhhp]."',starazh2h='".$s[strazhhp]."',kingh='".$s[kinghp]."',start='".time()."',timeatack='".time()."' WHERE id = '$s[id]'");
}
}
}
if((strtotime("11:40")-60<=time() AND strtotime("11:40")+60>=time()) OR (strtotime("15:40")-60<=time() AND strtotime("15:40")+60>=time()) OR (strtotime("20:40")-60<=time() AND strtotime("20:40")+60>=time())){
	$spis = mysql_query("SELECT * FROM `zamki` order by `id` asc");
	while($s = mysql_fetch_assoc($spis)){
	if($s[status]==1){
		mysql_query("UPDATE `zamki` SET `status`='0' WHERE id='$s[id]'");
		$opponents = mysql_query("SELECT * FROM `zamki_user`");
		while($opp = mysql_fetch_array($opponents))
		{
			$time = time();
			$msgs='К сожелению, никто не выиграл, но может вам повезёт в следующем бою';
			mysql_query("INSERT INTO `mail` (`id_user`, `id_kont`, `msg`, `time`, `read`) values('1', '".abs(intval($opp[uid]))."', '$msgs', '$time', '1')");
			mysql_query("INSERT INTO `users_konts` (`id_user`, `id_kont`, `time`) VALUES ('".abs(intval($opp[uid]))."', '1', '$time')");
			mysql_query("UPDATE `users_konts` SET `new_msg` = '1' WHERE `id_kont` = '1' AND `id_user` = '".abs(intval($opp[uid]))."'");
		}
		mysql_query("DELETE FROM zamki_user");
		mysql_query("DELETE FROM zamki_clan");
	}
	}
}

require_once '../core/foot.php';
?>