<?

if(isset($_POST["tb_ads_optimize"])){
$variant=$_POST["tb_ads_optimize"];
if(isset($_POST["tb_ads1_optimize"])){
$variant=$_POST["tb_ads1_optimize"];


if($variant==4){
require('config.php');
$sql="SELECT * FROM tb_ads1 WHERE tipo='visit'";
$result=mysql_query($sql);
$den=(24*60*60);
$timeNow=time();
$numCleared=0;
WHILE($row=mysql_fetch_array($result)){
$timeChek=($row["visitime"]+$den);
    if($timeChek<$timeNow){
    $numCleared++;
     $delId=$row["id"];
     $query="DELETE FROM tb_ads1 WHERE id='$delId'";
     mysql_query($query)or die(mysql_error());
 }
}
 echo 'Успешно! удалено: <b>'.$numCleared.'</b>устаревших записей!';
 mysql_close($con);}
}


//история пустых входов
if($variant==3){
require('config.php');
$sql="SELECT * FROM regmonitor WHERE registered=''";
$result=mysql_query($sql);
$numCleared=0;
	WHILE($row=mysql_fetch_array($result)){
	$numCleared++;
	$delId=$row["id"];
	$query="DELETE FROM regmonitor WHERE id='$delId'";
	mysql_query($query) or die(mysql_error());
	}
echo 'Сделано! удалено: <b>'.$numCleared.'</b> ненужных записей!';
mysql_close($con);
}


//история пустых рефералов
if($variant==2){
require('config.php');
$sql="SELECT * FROM tb_history WHERE user=''";
$result=mysql_query($sql);
$numCleared=0;
	WHILE($row=mysql_fetch_array($result)){
	$numCleared++;
	$delId=$row["id"];
	$query="DELETE FROM tb_history WHERE id='$delId'";
	mysql_query($query) or die(mysql_error());
	}
echo 'Сделано! удалено: <b>'.$numCleared.'</b> ненужных записей!';
mysql_close($con);
}

if($variant==1){
require('config.php');
$sql="SELECT * FROM tb_ads WHERE tipo='visit'";
$result=mysql_query($sql);
$den=(24*60*60);
$timeNow=time();
$numCleared=0;
WHILE($row=mysql_fetch_array($result)){
$timeChek=($row["visitime"]+$den);
    if($timeChek<$timeNow){
    $numCleared++;
     $delId=$row["id"];
     $query="DELETE FROM tb_ads WHERE id='$delId'";
     mysql_query($query)or die(mysql_error());
 }
}
 echo 'Успешно! удалено: <b>'.$numCleared.'</b>устаревших записей!';
 mysql_close($con);}
}

?>
<table>
<th>Удаление истории кликов</th>
<th>Удаление истории пустых пополнений</th>
<th>Удаление истории пустых входов</th>
<th>Удаление истории кликов2</th>
<tr>
<td><form action="adminmain.php?p=optimize_bd" method="post">
<input type="hidden" name="tb_ads_optimize" value="1">
<input type="submit" value="Очистить">
</form>
</td>
<td><form action="adminmain.php?p=optimize_bd" method="post">
<input type="hidden" name="tb_ads_optimize" value="2">
<input type="submit" value="Очистить">
</form>
</td>
<td><form action="adminmain.php?p=optimize_bd" method="post">
<input type="hidden" name="tb_ads_optimize" value="3">
<input type="submit" value="Очистить">
</form>
</td>
<td><form action="adminmain.php?p=optimize_bd" method="post">
<input type="hidden" name="tb_ads_optimize" value="3">
<input type="submit" value="Очистить">
</form>
</td>

</table>
