<?php
DEFINE("ROOT_DIR", realpath(dirname(__FILE__).'/../') );
require(ROOT_DIR."/config.php");
$t = time();

// Обнуление рекламной статистики
$time_del = (time()-86400);
mysql_query("DELETE FROM `nano_rek_ip` WHERE `time`<'$time_del'") or die(mysql_error());

// Очистка корзины
$sql = mysql_query("SELECT `id` FROM `nano_korzina` WHERE `time`<='".(time()-86400)."' AND `rek_asoc`!='8'");
if(mysql_num_rows($sql) > 0){
while($row = mysql_fetch_assoc($sql)){
$id_korz = $row["id"];
mysql_query("DELETE FROM `nano_korzina` WHERE `id`='$id_korz'");
}
}

// Очистка корзины с рефералом
$sql = mysql_query("SELECT `id`, `id_rek` FROM `nano_korzina` WHERE `time`<='".(time()-3600)."' AND `rek_asoc`='8'");
if(mysql_num_rows($sql) > 0){
while($row = mysql_fetch_assoc($sql)){
$id_korz_r = $row["id"];
$id_us_r = $row["id_rek"];
mysql_query("DELETE FROM `nano_korzina` WHERE `id`='$id_korz_r'");
mysql_query("UPDATE `nano_jarmorka` SET `status`='1' WHERE `id`='$id_us_r'");
}
}

// Чистка просрочек выполнения
$sql=mysql_query("SELECT * FROM `nano_rek_taskwait` WHERE `status`='1'");
while ($row = mysql_fetch_array($sql)) {
$id_task = $row["id_task"];
$end = $row["end"];
if($end < $t){
mysql_query("UPDATE `nano_rek_task` SET `work`=`work`-'1' WHERE `id`='$id_task'");
mysql_query("DELETE FROM `nano_rek_taskwait` WHERE `status`='1' AND `end`<'$t'");
}
}

// Остановка рекламы
mysql_query("UPDATE `nano_rek_banner` SET `activ`='0',`summ`='0' WHERE `summ`<=`cena`");
mysql_query("UPDATE `nano_rek_dinamika` SET `activ`='0',`summ`='0' WHERE `summ`<=`cena`");
mysql_query("UPDATE `nano_rek_kontext` SET `activ`='0',`summ`='0' WHERE `summ`<=`cena`");
mysql_query("UPDATE `nano_rek_psmenu` SET `activ`='0',`summ`='0' WHERE `summ`<=`cena`");
mysql_query("UPDATE `nano_rek_task` SET `work`='0' WHERE `work`<'0'");

// Поправка сейфа
mysql_query("UPDATE `nano_user` SET `save_ball`='0' WHERE `save_ball`<'0.000000'");
?> 