<?
include "header.php";

// CHECK FOR URL VARIABLE MANIPUPLATION
if(isset($_GET['f_id'])) { $f_id = $_GET['f_id']; } elseif(isset($_POST['f_id'])) { $f_id = $_POST['f_id']; } else { exit(); }


$images_inside = mysql_num_rows(mysql_query("SELECT * FROM ims_image WHERE u_id='$user_info[u_id]' AND f_id='$f_id'"));
echo $header;

// CHECK FOR URL MANIPULATION (MATCH WITH CORRECT USER)
$folder = mysql_num_rows(mysql_query("SELECT * FROM ims_folders WHERE f_id='$f_id' AND u_id='$user_info[u_id]'"));
if($folder == 0) {
echo "You are trying to access an invalid folder.<br>Please use your browser's back button to return.";
echo $footer;
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($page == "") { $page = "1"; }

echo "<table width='520' cellpadding='0' cellspacing='0'>
<tr>
<form action='upload_images.php?f_id=$f_id&page=$page' method='POST'>
<td valign='top'><b>$folder_info[name]</b> ($images_inside image"; if($images_inside != 1) { echo "s"; } echo ")<br>Images that exist within this folder are listed below.<br>The address (URL) to each image is provided.
</td>
<td align='center'>
<br><input type='submit' class='button' value='Upload New Images' style='margin-bottom: 3px;'>";

$images_inside = mysql_num_rows(mysql_query("SELECT * FROM ims_image WHERE u_id='$user_info[u_id]' AND f_id='$f_id'"));

if(!isset($_GET['page'])) { $page = 1; } else { $page = $_GET['page']; }
if(($images_inside % $user_info[prefs_images_per_page]) != 0) {
$maxpage = ($images_inside) / $user_info[prefs_images_per_page] + 1;
} else {
$maxpage = ($images_inside) / $user_info[prefs_images_per_page];
}
$maxpage = (int) $maxpage;

if($page > $maxpage) { $page = $maxpage; }
if($page < 1) { $page = 1; }

$start = ($page - 1) * $user_info[prefs_images_per_page];

echo "<br>";
if($page - 1 > 0) {  
$prev = $page - 1;  
$np = "<a href='view_folder.php?f_id=$f_id&page=$prev'>&#171; Previous</a>";  
} else {
$np = "<font color='#444444'>&#171; Previous</font>"; 
}
if($page + 1 <= $maxpage) {  
$next = $page + 1;  
$pp = "<a href='view_folder.php?f_id=$f_id&page=$next'>Next &#187;</a>";  
} else {
$pp = "<font color='#444444'>Next &#187;</font>"; 
}

if($maxpage != 1 & $maxpage != 0) {
echo "$np &nbsp;<font color='#777777'>|</font>&nbsp; <b>Page $page</b> &nbsp;<font color='#777777'>|</font>&nbsp; $pp";
}

echo "
</td>
<input type='hidden' name='task' value='upload'>
</form></tr></table><br>
";


if($images_inside == 0) { echo "<b>There are currently no images in this folder.</b>"; }
if($user_info[prefs_listby] == "alpha") {
$listby = "title";
} elseif($user_info[prefs_listby] == "newest") {
$listby = "i_id DESC";
} elseif($user_info[prefs_listby] == "oldest") {
$listby = "i_id";
} else {
$listby = "title";
}
// SHOW IMAGES IN THIS FOLDER
$result = mysql_query("SELECT * FROM ims_image WHERE u_id='$user_info[u_id]' AND f_id='$f_id' ORDER BY $listby LIMIT $start, $user_info[prefs_images_per_page]");
$count = 0;
while($image_info = mysql_fetch_assoc($result)) {
$count = $count + 1;
$filesize = round($image_info[size]/1024);
$imageurl = "pic.php?u=$user_info[u_id]$user_info[code]&i=$image_info[i_id]";
$thumburl = "thumbs.php?u=$user_info[u_id]$user_info[code]&i=$image_info[i_id]";

$server_array = explode("/", $_SERVER['PHP_SELF']);
$server_array_mod = array_pop($server_array);
$server_info = implode("/", $server_array);
$server = "http://".$_SERVER['HTTP_HOST'].$server_info;

if($image_info[views] != "1") { $p = "s"; } else { $p = ""; }

$imagename = $image_info[title];
$middle = "<input type='text' name='url$image_info[i_id]' size='80' value='$server/$imageurl' style='font-size: 8pt; padding-left: 2px; margin-top: 2px; margin-bottom: 1px;'>";

echo "
<table width='518' cellpadding='0' cellspacing='0' style='margin-bottom: 1px; border: 1px solid #888888; background: #FFFFFF;"; if($count > 1) { echo " margin-top: 5px;"; } echo "'>
<tr><td width='10' style='padding: 5px;'>
<div style='margin: 0px;'><a "; if($user_info[prefs_newwin] == "yes") { echo "target='_blank' "; } echo "title='View Image' href='$imageurl'><img src='$thumburl' width='60' height='60' border='0' style='border: 1px solid #666666;'></a></div>
</td>
<td style='padding: 5px;' valign='top'>
  <table cellpadding='0' cellspacing='0'>
  <tr><td colspan='2' style='padding-bottom: 3px;'><a "; if($user_info[prefs_newwin] == "yes") { echo "target='_blank' "; } echo "title='View Image' href='$imageurl'><b>$imagename</b></a> - <b>$filesize KB</b>&nbsp; "; if($image_info[views] != "") { echo "($image_info[views] view$p)"; } else { echo "(0 views)"; } echo "</td>
  <tr><td colspan='2'>$middle</td></tr>
  <tr><td align='left' style='padding-top: 2px;'>";
        if($admin_info[rotate_feature] == "yes" & $image_info[ext] != "gif" & $image_info[ext] != "pdf") { echo "<a href='rotate_images.php?r=1&i_id=$image_info[i_id]&page=$page'><img src='./icons/button_rotate1.gif' border='0' alt='Rotate image 90 degrees counter-clockwise.'></a>&nbsp;<a href='rotate_images.php?r=2&i_id=$image_info[i_id]&page=$page'><img src='./icons/button_rotate2.gif' border='0' alt='Rotate image 90 degrees clockwise.'></a>&nbsp;"; }
        if($admin_info[resize_feature] == "yes" & $image_info[ext] != "gif" & $image_info[ext] != "pdf") { echo "<a href='resize_images.php?i_id=$image_info[i_id]&page=$page'><img src='./icons/button_scale.gif' border='0' alt='Resize this image.'></a>"; }
echo "
      </td>
      <td align='right'>
";

echo "  <a href='#' onclick='getcode($user_info[u_id],$image_info[i_id])'>Get Code</a> <font class='gray'>&nbsp;|&nbsp; </font>";

echo "
  <a href='move_images.php?i_id=$image_info[i_id]&f_id=$f_id&page=$page'>Move</a> <font class='gray'>&nbsp;|&nbsp; </font>
  <a href='modify_images.php?i_id=$image_info[i_id]&f_id=$f_id&page=$page'>Modify</a> <font class='gray'>&nbsp;|&nbsp; </font>
  <a href='delete_images.php?i_id=$image_info[i_id]&f_id=$f_id&page=$page'>Delete</a>
  </td></tr></table>
</td></tr>
</table>
";
}

echo $footer;

?>