<?
include "header.php";

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



if($task == "deleteimg_do") {

unlink("./u/$user_info[u_id]/$folder_info[f_id]/".$image_info[i_id].".".$image_info[ext]);
if($image_info[thumb] != "none") { unlink("./u/$user_info[u_id]/$folder_info[f_id]/thumbs/$image_info[thumb]"); }
mysql_query("DELETE FROM ims_image WHERE u_id='$user_info[u_id]' AND f_id='$f_id' AND i_id='$i_id'");
header("Location: view_folder.php?f_id=$f_id&page=$page");
exit;
}



if($task == "deleteimg") {

echo $header;
echo "
<table width='520' cellpadding='0' cellspacing='0'>
<form action='delete_images.php' method='POST'>
<tr>
<td style='padding-bottom: 5px;'>
<b>Delete Image?</b><br>
Are you sure you want to delete the image <b>\"$image_info[title]\"</b>?<br>
<br>
<input type='hidden' name='f_id' value='$f_id'>
<input type='hidden' name='i_id' value='$i_id'>
<input type='hidden' name='page' value='$page'>
<input type='hidden' name='task' value='deleteimg_do'>
<input type='submit' class='button' value='Delete Image'>
<input type='button' class='button' value='Cancel' onClick=\"gofolder('$f_id&page=$page')\">
</td>
</tr>
</form>
</table>";
echo $footer;
}


?>