<?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("DELETE FROM $type WHERE id = '$id'"); 	
		if($enabledLang) mysql_query("DELETE FROM news_lang WHERE content = '$id'"); 	
	break;
	case 'faq':
		mysql_query("DELETE FROM $type WHERE id = '$id'"); 	
		if($enabledLang) mysql_query("DELETE FROM news_lang WHERE content = '$id'"); 	
	break;	
	case 'oferty':
		mysql_query("DELETE FROM $type WHERE id = '$id'"); 	
	break;	
	case 'cv':
		mysql_query("DELETE FROM $type WHERE id = '$id'"); 	
	break;	
	case 'pytania':
		mysql_query("DELETE FROM $type WHERE id = '$id'"); 	
	break;		
	case 'menu_tygodnia':
		mysql_query("DELETE FROM $type WHERE id = '$id'"); 	
	break;
	case 'szkolenia':
		mysql_query("DELETE FROM $type WHERE id = '$id'"); 	
		if($enabledLang) mysql_query("DELETE FROM szkolenia_lang WHERE content = '$id'"); 	
	break;	
	case 'links':
		mysql_query("DELETE FROM $type WHERE id = '$id'"); 	
	break;	
	case 'lang':
		$row = mysql_fetch_array(mysql_query("SELECT * FROM lang WHERE `id`='$id'"));   
		mysql_query("DELETE FROM $type WHERE id = '$id'"); 	
		mysql_query("DELETE FROM translate_text WHERE lang='$row[lang]'");
	break;	
	case 'slider':
		DeleteDir('../../media/photos/slider/'.$id);	
		mysql_query("DELETE FROM $type WHERE id = '$id'"); 	
		@mysql_query("DELETE FROM slider_lang WHERE content = '$id'");
	break;	
	case 'partners':
		DeleteDir('../../media/photos/partners/'.$id);	
		mysql_query("DELETE FROM $type WHERE id = '$id'"); 	
	break;		
	case 'lang_translate':
		$row = mysql_fetch_array(mysql_query("SELECT * FROM translate_name WHERE `id`='$id'"));   
		mysql_query("DELETE FROM translate_text WHERE word='$row[id]'"); 
		mysql_query("DELETE FROM translate_name WHERE id='$id'");
	break;	
	case 'pages_gallery':
		$row = mysql_fetch_array(mysql_query("SELECT * FROM $type WHERE `id`='$id'")); 
		unlink('../../media/photos/'.$type.'/'.$row['category'].'/medium/'.$row['photo']);
		unlink('../../media/photos/'.$type.'/'.$row['category'].'/min/'.$row['photo']);
		mysql_query("DELETE FROM $type WHERE id = '$id'"); 	
	break;	
	case 'pages':	
		DeleteDir('../../media/photos/'.$type.'_gallery/'.$id);	
		DeleteDir('../../media/files/pages/'.$id);	
		mysql_query("DELETE FROM $type WHERE id = '$id'"); 	
		@mysql_query("DELETE FROM pages_lang WHERE content = '$id'"); 	
		@mysql_query("DELETE FROM files WHERE `parent` = 'pages' AND parent_id = '$id'"); 	
	break;	
	case 'files':
		$row = mysql_fetch_array(mysql_query("SELECT * FROM $type WHERE `id`='$id'")); 
		unlink('../../media/files/'.$row['parent'].'/'.$row['parent_id'].'/'.$row['file']);
		mysql_query("DELETE FROM $type WHERE id = '$id'"); 	
	break;	
	case 'gallery':
		DeleteDir('../../media/photos/'.$type.'/'.$id);
		DeleteDir('../../media/photos/images/'.$id);
		mysql_query("DELETE FROM $type WHERE id = '$id'"); 	
	break;		
	case 'images':
		$row = mysql_fetch_array(mysql_query("SELECT * FROM $type WHERE `id`='$id'")); 
		unlink('../../media/photos/images/'.$row['category'].'/min/'.$row['photo']);
		unlink('../../media/photos/images/'.$row['category'].'/medium/'.$row['photo']);
		mysql_query("DELETE FROM $type WHERE id = '$id'"); 	
	break;	
	default:
		mysql_query("DELETE FROM $type WHERE id = '$id'"); 	
	break;		
			
endswitch;		

?>
