<?php
header('Content-Type: text/html; charset=utf-8');
set_time_limit(0);
ini_set ('max_execution_time', "0");
include("config.php");
$lnk = mysql_connect($hostname,$username,$password);
mysql_select_db($dbname, $lnk);
mysql_query("SET NAMES utf8");
// получение списка логинов
$logins=array();
$ids=array();
$res=mysql_query("SELECT * FROM zn_anket");
while ($a=mysql_fetch_array($res)) {
$logins[]=$a['login'];
$ids[]=$a['id'];
}
$inf=date("d.m.Y H:i:s")."\n";
// отчистка старых анкет и постов
#mysql_query("DELETE FROM zn_anket WHERE lastdate < CURRENT_TIMESTAMP()- INTERVAL 3 MONTH");
mysql_query("DELETE FROM zn_messages WHERE date < CURRENT_TIMESTAMP()- INTERVAL 3 MONTH");
mysql_query("DELETE FROM zn_chat WHERE date < CURRENT_TIMESTAMP()- INTERVAL 15 DAY");
// разбаниваем ip и ники
mysql_query("DELETE FROM zn_ban WHERE bandate < CURRENT_TIMESTAMP()");
mysql_query("UPDATE zn_anket SET banned=0, bandate=NULL WHERE bandate < CURRENT_TIMESTAMP()");
// удаляем незаполненные анкеты
mysql_query("DELETE FROM zn_anket WHERE sex IS NULL AND lastdate < CURRENT_TIMESTAMP()- INTERVAL 1 HOUR");
// если есть не старые лучшие анкеты, то старые удаляем
//if (mysql_num_rows(mysql_query("SELECT * FROM zn_anket WHERE sex='m' AND best='1' AND bestdate > NOW()-INTERVAL $bestlong DAY"))) {
mysql_query("UPDATE zn_anket SET best='0' WHERE sex='m' AND best='1' AND bestdate < NOW()-INTERVAL $bestlong DAY");
//}
//if (mysql_num_rows(mysql_query("SELECT * FROM zn_anket WHERE sex='w' AND best='1' AND bestdate > NOW()-INTERVAL $bestlong DAY"))) {
mysql_query("UPDATE zn_anket SET best='0' WHERE sex='w' AND best='1' AND bestdate < NOW()-INTERVAL $bestlong DAY");
//}
$inf.="Clean messages\n";
$res=mysql_query("SELECT * FROM zn_messages");
while ($a=mysql_fetch_array($res)) {
if (!in_array($a['ot'], $logins)) {
mysql_query("DELETE FROM zn_messages WHERE ot='$a[ot]'");
$inf.="Deleted mes from $a[ot]\n";
}
if (!in_array($a['komu'], $logins)) {
mysql_query("DELETE FROM zn_messages WHERE komu='$a[komu]'");
$inf.="Deleted mes to $a[komu]\n";
}
}
$inf.="Clean friends\n";
$res=mysql_query("SELECT * FROM zn_friends");
while ($a=mysql_fetch_array($res)) {
if (!in_array($a['alogin'], $logins)) {
mysql_query("DELETE FROM zn_friends WHERE alogin='$a[alogin]'");
$inf.="Deleted $a[alogin]\n";
}
if (!in_array($a['flogin'], $logins)) {
mysql_query("DELETE FROM zn_friends WHERE flogin='$a[flogin]'");
$inf.="Deleted $a[flogin]\n";
}
}
$inf.="Clean ignor\n";
$res=mysql_query("SELECT * FROM zn_ignor");
while ($a=mysql_fetch_array($res)) {
if (!in_array($a['alogin'], $logins)) {
mysql_query("DELETE FROM zn_ignor WHERE alogin='$a[alogin]'");
$inf.="Deleted $a[alogin]\n";
}
if (!in_array($a['ignlogin'], $logins)) {
mysql_query("DELETE FROM zn_ignor WHERE ignlogin='$a[ignlogin]'");
$inf.="Deleted $a[ignlogin]\n";
}
}
$inf.="Clean fototop\n";
$res=mysql_query("SELECT * FROM zn_fototop");
while ($a=mysql_fetch_array($res)) {
if (!in_array($a['aid'], $ids)) {
mysql_query("DELETE FROM zn_fototop WHERE aid='$a[aid]'");
$inf.="Deleted $a[aid]\n";
}
if (!in_array($a['fid'], $ids)) {
mysql_query("DELETE FROM zn_fototop WHERE fid='$a[fid]'");
$inf.="Deleted $a[fid]\n";
}
}
/*mysql_query("UPDATE zn_anket SET photo='0'");
$totalphoto=0;
$deleted=0;
$dh=opendir("images/");
while (($file=readdir($dh))!==false) {
preg_match("/(\w*)\.(\w*)$/", $file, $m);
$id=trim(@$m[1]);
$act=@strtolower($m[2]);
if (($act!='gif') && ($act!='jpg') && ($act!='png')) {continue;}
$res=mysql_query("SELECT * FROM zn_anket WHERE id='$id'");
if (mysql_num_rows($res)==0) {
unlink("images/$file");
$deleted++;
continue;
}
if (!@getimagesize("images/$file")) {
unlink("images/$file");
$inf.="File $file is bad\n";
$deleted++;
} else {
mysql_query("UPDATE zn_anket SET photo='1' WHERE id='$id'");
$totalphoto++;
}
}
closedir($dh);
$inf.="\nUser whith photo: $totalphoto, deleted: $deleted\n\n\n";*/
$inf.="\n";
$fp=fopen('dellog.txt', 'a+');
fwrite($fp, $inf);
fclose($fp);
echo str_replace("\n", "<br/>\n", $inf);
echo "<big>End</big><br/>";
?>