<?
include "mysqlcon.php";

$u_id = $_GET['u_id'];
$f_id = $_GET['f_id'];
if($u_id == "" OR $f_id == "") { exit(); }

$code = strrev(substr(strrev($u_id), 0, 5));
$u_id = strrev(substr(strrev($u_id), 5));

if(mysql_num_rows(mysql_query("SELECT * FROM ims WHERE u_id='$u_id' AND code='$code'")) != 1) { exit(); }

$folders = mysql_query("SELECT * FROM ims_folders WHERE f_id='$f_id' AND u_id='$u_id'");
$folder = mysql_fetch_assoc($folders);
$album = mysql_fetch_assoc(mysql_query("SELECT * FROM ims WHERE u_id='$u_id'"));
$images = mysql_query("SELECT * FROM ims_image WHERE u_id='$u_id' AND f_id='$f_id'");
$images_inside = mysql_num_rows($images);

$width = $album[albumprefs_width];

if(mysql_num_rows($folders) == 0) { exit(); }

if(($album[albumprefs_privacy] == "private" AND !isset($_COOKIE['album_pass'])) | $_COOKIE['album_pass'] != $album[albumprefs_password]) {
header("Location: album.php?u_id=$u_id$code");
exit;
}

if($album[photo_album] != "yes") { exit; }

echo "
<html>
<head>
<title>$album[fname] $album[lname]'s Online Photo Album - $admin_info[site_name]</title>
<style type='text/css'>
body { font-family: tahoma, verdana, arial; font-size: 8pt; }
td { font-family: tahoma, verdana, arial; font-size: 8pt; }
a:link { color: #000066; }
a:visited { color: #000066; }
a:hover { color: #000066; }
input.button { background: #DDDDDD; font-weight: bold; font-size: 8pt; font-family: verdana, arial, tahoma; }
</style>
</head>
<body>
";

// SHOW LOGO IMAGE
if($album[albumprefs_logo] != "" AND $album[albumprefs_logo] != "http://") {
echo "<img src='$album[albumprefs_logo]' border='0'>";
}

if($album[albumprefs_logo] == "") {
echo "<h3 style='margin-bottom: 5px; margin-top: 0px;'>$album[fname]'s Photo Album</h3>";
}

// SHOW HEADER HTML
if($album[albumprefs_head] != "" AND $album[albumprefs_on] != "no") {
echo "
<table cellpadding='0' cellspacing='0'>
<tr><td>".str_replace("&lt;/textarea>", "</textarea>", $album[albumprefs_head])."</td></tr>
</table><br>
";
}




if(mysql_num_rows($images) != 0) {
if(mysql_num_rows($images) != 1) { $plural = "s"; }
echo "
<table width='$width' cellpadding='0' cellspacing='0' style='margin-bottom: 7px;'>
<tr>
<td style='border: 1px solid #888888; background: #F7F7F7; padding: 5px;'>
  <table cellpadding='0' cellspacing='0' width='100%'>
  <tr><td><b><a href='album.php?u_id=$u_id$code'>Photo Album</a> &#187; $folder[name]</b> ($images_inside image$plural)</td></tr>
";  

if($folder[description] != "" AND $folder[description] != " ") {
echo "<tr><td style='padding-top: 3px;'>$folder[description]</td></tr>";
}

echo "
  </table>
</td>
</tr>
</table>
";
}


echo "
<table cellpadding='0' cellspacing='0' width='$width'>
<tr>
<td align='center' style='padding-bottom: 9px;'>
";

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

if($maxpage != 1) {  
if($page - 1 > 0) {  
$prev = $page - 1;  
$np = "<a href='album_folder.php?u_id=$u_id$code&f_id=$f_id&page=$prev'>&#171; Last Page</a>";  
}  
if($page + 1 <= $maxpage) {  
$next = $page + 1;  
$pp = "<a href='album_folder.php?u_id=$u_id$code&f_id=$f_id&page=$next'>Next Page &#187;</a>";  
}}

if($pp != "" OR $np != "") {

if($pp == "") { $pp = "<font color='#666666'>Next Page &#187;</font>"; }
if($np == "") { $np = "<font color='#666666'>&#171; Last Page</font>"; }
if($np != "" OR $pp != "") { echo "$np &nbsp;|&nbsp; <b>Page $page</b> &nbsp;|&nbsp; $pp"; }

}

if($album[prefs_listby] == "alpha") {
$listby = "title";
} elseif($album[prefs_listby] == "newest") {
$listby = "i_id DESC";
} elseif($album[prefs_listby] == "oldest") {
$listby = "i_id";
} else {
$listby = "title";
}

echo "</td></tr></table>";



$count = 0;
$images = mysql_query("SELECT * FROM ims_image WHERE u_id='$u_id' AND f_id='$f_id' ORDER BY $listby LIMIT $start, $album[prefs_images_per_page]");
while($image = mysql_fetch_assoc($images)) {
$count = $count + 1;
$desc = $image[description];
if($desc == "") { $desc = "No Description"; }
echo "
<table width='$width' cellpadding='0' cellspacing='0' style='"; if($count != 1) { echo "margin-top: 7px; "; } echo "border: 1px solid #888888; background: #F7F7F7;'>
<tr><td width='10' style='padding: 5px;'>
<div style='margin: 0px;'><a "; if($album[prefs_newwin] == "yes") { echo "target='_blank' "; } echo "title='View Image' href='pic.php?u=$u_id$album[code]&i=$image[i_id]'><img src='thumbs.php?u=$u_id$album[code]&i=$image[i_id]' 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 style='padding-bottom: 3px;'><a "; if($album[prefs_newwin] == "yes") { echo "target='_blank' "; } echo "title='View Image' href='pic.php?u=$u_id$album[code]&i=$image[i_id]'><b>$image[title]</b></a> "; if($image[views] != "") { echo "($image[views] view"; if($image[views] != 1) { echo "s"; } echo ")"; } else { echo "(0 views)"; } echo "</td>
  <tr><td>$desc</td></tr>
</table>
</td></tr>
</table>
";
}

if(mysql_num_rows($images) == 0) {
echo "
<table cellpadding='0' cellspacing='0' width='400' style='background: #F7F7F7; border: 1px solid #777777;'>
<tr>
<td align='center' valign='middle' style='padding: 20px;'>
<b>There are no images inside this folder.</b>
<form action='album.php?u_id=$u_id$code' method='POST'>
<input type='submit' class='button' value='Go Back'>
</td>
</form>
</tr>
</table>
";
}

echo "
<table cellpadding='0' cellspacing='0' style='margin-top: 3px;'>
<tr>
<td align='center' style='padding-left: 1px; color: #444444;'>
Driven by Webligo IMS Software
</td>
</tr>
</table>
";


// SHOW FOOTER HTML
if($album[albumprefs_foot] != "" AND $album[albumprefs_on] != "no") {
echo "<br>".str_replace("&lt;/textarea>", "</textarea>", $album[albumprefs_foot])."<br>";
}




echo "
</body>
</html>
";

?>