<?
include "header.php";

if(isset($_POST['task'])) { $task = $_POST['task']; } else { $task = "deletefolder"; }
if(isset($_POST['f_id'])) { $f_id = $_POST['f_id']; } elseif(isset($_GET['f_id'])) { $f_id = $_GET['f_id']; } else { exit(); }
if(mysql_num_rows(mysql_query("SELECT * FROM ims_folders WHERE f_id='$f_id' AND u_id='$user_info[u_id]'")) != 1) { exit(); }
$folder_info = mysql_fetch_assoc(mysql_query("SELECT * FROM ims_folders WHERE f_id='$f_id' AND u_id='$user_info[u_id]'"));

if($task == "deletefolder_do") {
// DELETE ALL FILES WITHIN FOLDER
$path = "./u/$user_info[u_id]/$folder_info[f_id]";
$dir_handle = @opendir($path) or die("Unable to open $path");
while ($file = readdir($dir_handle)) {
if($file != "." & $file != "..") {
if(is_dir("$path/$file")) {
$dir_handle2 = @opendir("$path/$file");
  while ($file2 = readdir($dir_handle2)) {
  if($file2 != "." & $file2 != "..") {
  unlink("$path/$file/$file2");
  }}
rmdir("$path/$file");
} else {
unlink("$path/$file");
}}}

// DELETE FOLDER ITSELF

chmod($path, 0777);
rmdir($path);
mysql_query("DELETE FROM ims_image WHERE u_id='$user_info[u_id]' AND f_id='$f_id'");
mysql_query("DELETE FROM ims_folders WHERE u_id='$user_info[u_id]' AND f_id='$f_id'");
header("Location: index.php");
exit;
}




if($task == "deletefolder") {
echo $header;
echo "
<table width='520' cellpadding='0' cellspacing='0'>
<form action='delete_folder.php' method='POST'>
<tr>
<td>
<b>Deletion Confirmation</b><br><font class='csmall'>
Are you sure you want to delete the folder <b>\"$folder_info[name]\"</b>?<br>
All images within will be erased!<br></font>
<br>
<input type='submit' class='button' value='Delete Folder'>
<input type='button' class='button' value='Cancel' onClick='goview()'>
<input type='hidden' name='task' value='deletefolder_do'>
<input type='hidden' name='f_id' value='$f_id'>
</td>
</form>
</tr>
</table>
$footer
";
}

?>