<?
require_once('../connect/connect.php');
require_once('../lib/lib.php');

	$r = mysql_query("SELECT id FROM board WHERE vip=0 AND ( 
	(data1 < NOW() AND id_akk = 0) 
	OR 
	(id_akk > 0 AND data1 + INTERVAL ".$rru['max_flash']." DAY < NOW())
	)");
	while($rr=mysql_fetch_array($r))	
		{
		$del_ttmp[] = $rr['id'];
		$mid = '../foto_vip/'.$d_t.'m.jpg';
		if (file_exists($mid) && is_file($mid)) unlink($mid);
		}

	if($del_ttmp)
		{
		$arr = implode(',', $del_ttmp);
		$r1 = mysql_query ("SELECT * FROM foto WHERE id IN (".$arr.")") or die(mysql_error());
		if($r1)
			{
			while($rr1 = mysql_fetch_array($r1))
				{
				$small = '../foto/'.$rr1['papka'].'/'.$rr1['id_foto'].'s.jpg';
				$big   = '../foto/'.$rr1['papka'].'/'.$rr1['id_foto'].'b.jpg';
				if(file_exists($small) && is_file($small)) unlink($small);
				if(file_exists($big) && is_file($big)) unlink($big);
				}
			}
	
		$q = "DELETE FROM foto WHERE id IN (".$arr.")";
		$q2 = "DELETE FROM board WHERE id IN (".$arr.")";
		$q3 = "DELETE FROM comment WHERE id IN (".$arr.")";
	
		mysql_query($q);
		mysql_query($q2);
		mysql_query($q3);
		}
		
	mysql_query("UPDATE board SET activ = '1' WHERE vip=0 AND id_akk > 0 AND activ = 0 AND data1 < NOW()");
?> 
