<?
$base_path="../";
$bp="../";
require_once($base_path.'connect/connect.php'); 
include_once($base_path.'lib/lib.php');

$id=intval($_REQUEST['id']);
$pass=anti($_REQUEST['pass']);

$r1 = mysql_query ("SELECT * FROM board WHERE id = '".$id."' AND pass='".$pass."'") or die(mysql_error());
$nr=mysql_num_rows($r1);
if($nr<1) 
	{
	$err = "Такого объявления не существует";
	$title = $err;
	}
else
	{
	$rr1=mysql_fetch_array($r1);

	if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) 
		{
		$r=mysql_query("SELECT * FROM foto WHERE id='".$id."'");
		while($rr=mysql_fetch_array($r))
			{
			$big = $base_path.'foto/'.$rr['papka'].'/'.$rr['id_foto'].'b.jpg';
			$small = $base_path.'foto/'.$rr['papka'].'/'.$rr['id_foto'].'s.jpg';
			if (file_exists($big) && is_file($big)) unlink($big);
			if (file_exists($small) && is_file($small)) unlink($small);
			}
		
		$mid = $base_path.'foto_vip/'.$id.'m.jpg';
		if (file_exists($mid) && is_file($mid)) unlink($mid);

		mysql_query("DELETE FROM board WHERE id='".$id."'");
		mysql_query("DELETE FROM foto WHERE id='".$id."'");

		$ud=1;
		}
	$title='Удаление объявления N '.$id.': '.$rr1['zag'];
	}

?>
<HTML><HEAD><TITLE><? echo $title; ?></TITLE>
<META http-equiv=content-type content="text/html; charset=utf-8">
<meta name="robots" content="nofollow" />
<link rel="stylesheet" href="../style/style.css" type="text/css"/>
</HEAD>
<BODY 
style="MARGIN: 0px auto; POSITION: inherit; width: 1000px">
<?
include_once($base_path."blok/top_form.php"); 
if($err)
echo '<br><font color=red>'.$err.'</font>';
else
	{
	if($ud)
	echo "<br><font color=green>Объявление N ".$id." успешно удалено</font>";
	else
		{
		?>
		<br>
		<form action="del.php" method="post" name="form" >
		<input class="submit" type="submit" name="Submit" value="Удалить объявление N <?=$id?>">
		<input name="id" type="hidden" value="<?=$id?>">
		<input name="pass" type="hidden" value="<?=$pass?>">
		<input type="hidden" name="MM_insert" value="form">
		</form>
		<?
		}
	} 
include('bottom.php');
?>
</body>
</html>