Location: PHPKode > projects > @1 File Store > control/folders/delete.php
<?
if(!isset($_GET["id"]) || $_GET["id"]=="") {
	exit("Bad request");
}
require_once("const.php");
$smarty->assign("action", $lang['delete_folder_2']);
$form["submit"]=$lang['delete'];
$form["readonly"]=1;
$form["hidden_fields"]=array("id"=>$_GET["id"]);

if($_SERVER["REQUEST_METHOD"]==$form["method"]) {	
	$SQL="SELECT * FROM `".DB_PREFIX."file_list` WHERE `folder_id`='".$_POST["id"]."'";
	if(!$mysql->query($SQL)) {
		exit($mysql->error);
	}
	while(!$mysql->EOF) {
		unlink("../../".UPLOAD_DIR.$mysql->field("download"));
		$mysql->movenext();
	}

	$q1="SELECT parent FROM `".DB_PREFIX."folders` WHERE `id`='".$_POST["id"]."'";
	if(!$mysql->query($q1)) { exit($mysql->error); }
	$f1=$mysql->field('parent');



	$q2="SELECT id FROM `".DB_PREFIX."folders` WHERE `parent`='".$_POST["id"]."'";
	if(!$mysql->query($q2)) { exit($mysql->error); }
	$f2=array();
	while(!$mysql->EOF) {
		$f2[]=$mysql->field('id');
		$mysql->movenext();
	}
	foreach ($f2 as $kf2 => $vf2) {
		$q3="UPDATE `".DB_PREFIX."folders` SET `parent`='".$f1."' WHERE `id`='".$vf2."'";
		if(!$mysql->query($q3)) { exit($mysql->error); }
	}




	$SQL="DELETE FROM `".DB_PREFIX."file_list` WHERE `folder_id`='".$_POST["id"]."'";
	if(!$mysql->query($SQL)) {
		exit($mysql->error);
	}
	
	$SQL="DELETE FROM `".DB_PREFIX."folders`  WHERE `id`='".$_POST["id"]."'";
	if(!$mysql->query($SQL)) {
		exit($mysql->error);
	}

	$SQL="DELETE FROM `".DB_PREFIX."access_list`  WHERE `folder_id`='".$_POST["id"]."'";
	if(!$mysql->query($SQL)) {
		exit($mysql->error);
	}






	Header("Location:index.php");
	exit();
} else {
	$SQL="SELECT * FROM `".DB_PREFIX."folders` WHERE `id`='".$_GET["id"]."'";
	if(!$mysql->query($SQL)) {
		exit($mysql->error);
	} else {
		$userform->load($form["fields"], $mysql->arr);
	}
}

$smarty->assign("form", $form);
$smarty->display("control/form.tpl");
?>
Return current item: @1 File Store