<?php
session_start();
include('../includes/config.php'); 

if(!is_numeric($_GET['id'])){
	exit();
} else {
	$id=$_GET['id'];
}

if($_SESSION["zalogowany"]!==1) {
	header("Location: $basehttp/admin/"); 
}

function DeleteDir($dir)
{
 
	$fd = opendir($dir);
	if(!$fd) return false;
	while (($file = readdir($fd))!== false)
	{
		if($file =="." || $file== "..") continue;
		if(is_dir($dir."/".$file))
		{
			  DeleteDir($dir."/".$file);
		}
		else
		{
			unlink("$dir/$file");
		}
	}
	closedir($fd);
	rmdir($dir);
}
	
	
$type=$_GET['type'];

switch ($type):
	case 'news':
		mysql_query("UPDATE `$type` SET `photo` = '' WHERE `id` = $id"); 		
		DeleteDir('../../media/photos/'.$type.'/'.$id);		
	break;
	case 'pytania':
		mysql_query("UPDATE `$type` SET `photo` = '' WHERE `id` = $id"); 		
		DeleteDir('../../media/photos/'.$type.'/'.$id);		
	break;
	case 'lang':
		mysql_query("UPDATE `$type` SET `photo` = '' WHERE `id` = $id"); 		
		DeleteDir('../../media/photos/'.$type.'/'.$id);		
	break;	
endswitch;		

?>
