<?
include "header.php";

if(isset($_POST['task'])) { $task = $_POST['task']; } else { $task = "renameimg"; }
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 == "renameimg_do") {
$newtitle = str_replace(">", "&gt;", str_replace("<", "&lt;", str_replace("'", "&#39;", $_POST[newtitle])));
$newdescr = str_replace(">", "&gt;", str_replace("<", "&lt;", str_replace("'", "&#39;", $_POST[newdescr])));

mysql_query("UPDATE ims_image SET title='$newtitle', description='$newdescr' 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 == "renameimg") {

echo $header;
echo "
<table width='520' cellpadding='0' cellspacing='0'>
<tr>
<td>
<b>Modify Image</b><br>
Please enter a new title or description for this image below.<br>
</td>
</tr>
</table>

<br>

<table width='520' cellpadding='0' cellspacing='0'>
<form action='modify_images.php' method='post'> 
<tr>
<input type='hidden' name='i_id' value='$i_id'>
<input type='hidden' name='f_id' value='$f_id'>
<td style='padding-bottom: 5px;'>
<font class='small'>Image Title</font><br>
<input class='text' type='text' name='newtitle' value='$image_info[title]' size='25' maxlength='40' style='margin-bottom: 5px;'><br>
<font class='small'>Image Description</font><br>
<input class='text' type='text' name='newdescr' value='$image_info[description]' size='75' maxlength='250' style='margin-bottom: 5px;'><br>
<input type='hidden' name='page' value='$page'>
<input type='hidden' name='task' value='renameimg_do'>
<input type='submit' class='button' value='Modify Image'>
<input type='button' class='button' value='Cancel' onClick=\"gofolder('$f_id&page=$page')\">
</td>
</tr>
</form>
</table>";
echo $footer;
}


?>