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

if($_GET['id']) $id=intval($_GET['id']);
if($_GET['pass']) $pass=_pre($_GET['pass']);

$r=mysql_query("SELECT * FROM board WHERE id='".$id."' AND pass='".$pass."'");
$nr=mysql_num_rows($r);

if($nr)
	{
	$rr=mysql_fetch_array($r);
	$vip=$rr['vip'];

	if($_GET['del']) 
		{
		$_GET['del']=intval($_GET['del']);
		$r=mysql_query("SELECT * FROM foto WHERE id_foto='".$_GET['del']."'");
		$nk=mysql_num_rows($r);
		if($nk)
			{
			$rr=mysql_fetch_array($r);

			$small = '../foto/'.$rr['papka'].'/'.$_GET['del'].'s.jpg';
			$big = '../foto/'.$rr['papka'].'/'.$_GET['del'].'b.jpg';
			if(file_exists($small) && is_file($small)) unlink($small);
			if(file_exists($big) && is_file($big)) unlink($big);
		
			mysql_query("DELETE FROM foto WHERE id_foto='".$_GET['del']."'");
			
			$r=mysql_query("SELECT * FROM foto WHERE id='".$id."' ORDER BY id_foto");
			$nh=mysql_num_rows($r);
			if($nh)
				{
				$rr=mysql_fetch_array($r);
				mysql_query("UPDATE board SET kol_foto='".$nh."', small='foto/".$rr['papka']."/".$rr['id_foto']."s.jpg' WHERE id='".$id."'"); 
				}
			else
			mysql_query("UPDATE board SET kol_foto='0', small='' WHERE id='".$id."'"); 
			}
		}

	$r=mysql_query("SELECT * FROM foto WHERE id='".$id."' ORDER BY id_foto");
	$nk=mysql_num_rows($r);
	if($nk)
		{
		echo '<table cellpadding="3" cellspacing="3" >';
		$i=0;
		$j=0;
		while($rr=mysql_fetch_array($r))
			{
			if(!$j && $vip==3)
				{
				$middle_a = "../foto/".$rr['papka']."/".$rr['id_foto']."b.jpg";
				$middle_b = "../foto_vip/".$id."m.jpg";
				@smalling ($middle_a, $middle_b, 200, 4, ".jpg");
				} 
			
			if(!$i) 
			echo '<tr>';
			echo '<td valign="top" align=center>';
			echo '<img src="../foto/'.$rr['papka'].'/'.$rr['id_foto'].'s.jpg" border=0 height=80> ';
			echo '<br><a href="javascript:dels('.$rr['id_foto'].')"><font color=red>X</font></a>';
			$j++;
			$i++;
			if($i==4) $i=0;
			}
		echo '</table>';
		}
	} 
	
if($nk < $rru['limit_foto'])
	{
	?>
	<script type="text/javascript">
	document.getElementById('foto').disabled=0;
	</script>
	<?
	}
else
	{
	?>
	<script type="text/javascript">
	document.getElementById('foto').disabled=1;
	</script>
	<?
	}

?>