<?php
//
error_reporting(0);
//
date_default_timezone_set('Europe/Kiev');
//
$time1 = date('d.m.y');
$time2 = date('H:i:s');
//
function time_left($tl){
$d=3600*24;
$day=floor($tl/$d);
$tl=$tl-($d*$day);
$hour=floor($tl/3600);
$tl=$tl-(3600*$hour);
$minute=floor($tl/60);
$tl=$tl-(60*$minute);
$second=floor($tl);
$dayt="".($day>0?"$day д. ":null)."";
$hourt="".($hour>0?"$hour ч. ":null)."";
$minutet="".($minute>0?"$minute м. ":null)."";
$secondt="".($second>0?"$second с. ":null)."";
if($day>0){
$minutet=NULL;
$secondt=NULL;
}
if($hour>0 && $day==0){
$secondt=NULL;
$dayt=NULL;
}
return "$dayt$hourt$minutet$secondt";
}

if($user['premium_time']<time()){
    mysql_query("UPDATE `users` SET `premium`='0' WHERE `id`='$uid'");
}
//
$ch = mysql_num_rows(mysql_query("SELECT * FROM `users` WHERE `color_chat`=''"));
if($ch>='1'){
    mysql_query("UPDATE `users` SET `color_chat`='white' WHERE `color_chat`=''");
}
//
$q = mysql_num_rows(mysql_query("SELECT * FROM `mobs` WHERE `user`!='' and `time`='0' or `time`<'".time()."'"));
if($q>='1'){
    mysql_query("UPDATE `mobs` SET `hp`=`hpall`,`user`='',`time`='0' WHERE `user`!='' and `time`='0' or `time`<'".time()."'");
}
//
if($user['pred']>='3'){
    $tb=time()+86400;
    mysql_query("INSERT INTO `ban` SET `user`='$uid',`who`='Система',`time`='$tb',`text`='Вы были забанены на 24 часа, так как получили 3 предупреждения'") or die(mysql_error());
    mysql_query("UPDATE `users` SET `pred`='0' WHERE `id`='$uid'");
}

$ban2 = mysql_query("SELECT * FROM `ban` WHERE `time`<'".time()."' and `time`!='perm'");
$b2 = mysql_num_rows($ban2);
if($b2>='1'){
    $bn2 = mysql_fetch_assoc($ban2);
    mysql_query("DELETE FROM `ban` WHERE `user`='$bn2[user]' and `time`<='".time()."'");
}
//
function isMobile() {
    return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]);
}

if(isMobile()){
    mysql_query("UPDATE `users` SET `user_agent`='mobile' WHERE `id`='$uid'");
}else{
    mysql_query("UPDATE `users` SET `user_agent`='pc' WHERE `id`='$uid'");
}
//
mysql_query("UPDATE `users` SET `ip`='".mysql_real_escape_string($_SERVER['REMOTE_ADDR'])."' WHERE `id`='$uid'");
//
$sea = mysql_query("SELECT * FROM `users` WHERE `sea`='1'");
$sea1 = mysql_num_rows($sea);
if($sea1>='1'){
	$sea2 = mysql_fetch_assoc($sea);
	if($sea2['online']<time()){
		mysql_query("UPDATE `users` SET `sea`='0' WHERE `id`='$sea2[id]'");
	}
}
//
/** Ресурсы **/
$q = mysql_num_rows(mysql_query("SELECT * FROM `res` WHERE `user`='$uid' and `res`='iskra1'"));
if($q == '0'){
    mysql_query("INSERT INTO `res` SET 
    `user`='$uid',
    `name`='Искра Зарождения',
    `img`='iskra.png',
    `kol`='0',
    `res`='iskra1'");
}
$q = mysql_num_rows(mysql_query("SELECT * FROM `res` WHERE `user`='$uid' and `res`='iskra2'"));
if($q == '0'){
    mysql_query("INSERT INTO `res` SET 
    `user`='$uid',
    `name`='Искра Безмолвия',
    `img`='iskra2.png',
    `kol`='0',
    `res`='iskra2'");
}
$q = mysql_num_rows(mysql_query("SELECT * FROM `res` WHERE `user`='$uid' and `res`='iskra3'"));
if($q == '0'){
    mysql_query("INSERT INTO `res` SET 
    `user`='$uid',
    `name`='Искра Умиротворения',
    `img`='iskra3.png',
    `kol`='0',
    `res`='iskra3'");
}
$q = mysql_num_rows(mysql_query("SELECT * FROM `res` WHERE `user`='$uid' and `res`='iskra4'"));
if($q == '0'){
    mysql_query("INSERT INTO `res` SET 
    `user`='$uid',
    `name`='Искра Грёз',
    `img`='iskra4.png',
    `kol`='0',
    `res`='iskra4'");
}
$q = mysql_num_rows(mysql_query("SELECT * FROM `res` WHERE `user`='$uid' and `res`='iskra5'"));
if($q == '0'){
    mysql_query("INSERT INTO `res` SET 
    `user`='$uid',
    `name`='Искра Разума',
    `img`='iskra5.png',
    `kol`='0',
    `res`='iskra5'");
}
/** магия **/
$q = mysql_num_rows(mysql_query("SELECT * FROM `us_mag` WHERE `user`='$uid' and `mag`='ogshar'"));
if($q == '0'){
    mysql_query("INSERT INTO `us_mag` SET 
    `user`='$uid',
    `mag`='ogshar',
    `name`='Огненный шар',
    `img`='ogshar1.png',
    `level`='1',
    `tip`='fire',
    `mp`='71',
    `hp`='0',
    `min_u`='37',
    `max_u`='51'");
}
$q = mysql_num_rows(mysql_query("SELECT * FROM `us_mag` WHERE `user`='$uid' and `mag`='haos'"));
if($q == '0'){
    mysql_query("INSERT INTO `us_mag` SET 
    `user`='$uid',
    `mag`='haos',
    `name`='Хлыст хаоса',
    `img`='haos1.png',
    `level`='1',
    `tip`='haos',
    `mp`='68',
    `hp`='100',
    `min_u`='25',
    `max_u`='35'");
}
$q = mysql_num_rows(mysql_query("SELECT * FROM `us_mag` WHERE `user`='$uid' and `mag`='volna'"));
if($q == '0'){
    mysql_query("INSERT INTO `us_mag` SET 
    `user`='$uid',
    `mag`='volna',
    `name`='Волна',
    `img`='volna1.png',
    `level`='1',
    `tip`='volna',
    `mp`='71',
    `hp`='18',
    `min_u`='25',
    `max_u`='35'");
}
/** **/

?>