<?
include "mysqlcon.php";

if(isset($_POST['task'])) { $task = $_POST['task']; } else { $task = "nothing"; }
if(!isset($_GET['u_id']) OR $_GET['u_id'] == "") { exit(); } else { $u_id = $_GET['u_id']; }

$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(); }

$album = mysql_fetch_assoc(mysql_query("SELECT * FROM ims WHERE u_id='$u_id'"));
if($album[photo_album] != "yes") { exit; }
$result = "";

$width = $album[albumprefs_width];
str_replace(" ", "", $width);
if(!is_numeric($width) OR $width == "" OR $width == "0") { $width = "500"; }

if($task == "set_cookie") {
$password = $_POST['password'];
if($password == $album[albumprefs_password]) {
setcookie("album_pass", $password, 0, "/");
header("Location: album.php?u_id=$u_id$code");
exit;
} else {
$result = "<br><font color='#FF0000'><b>The password you provided was incorrect.</b></font>";
}
}

echo "
<html>
<head>
<META HTTP-EQUIV='Pragma' CONTENT='no-cache'>
<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-family: verdana, arial, tahoma; font-size: 8pt; font-weight: bold; }
</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 ALBUM IS DISABLED
if($album[albumprefs_on] == "no") {

echo "

<table cellpadding='0' cellspacing='0' width='400' style='background: #F7F7F7; border: 1px solid #777777;'>
<tr>
<td valign='middle' style='padding: 10px;'>

<table cellpadding='0' cellspacing='0'>
<tr>
<td style='padding-right: 10px;'>
<img src='./icons/error.gif' border='0'>
</td>
<td>
<b>You cannot access this photo album because it has been disabled.
Please try again at a later time.
</b>
</td></tr></table>

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










// IF ALBUM IS PRIVATE
} elseif(($album[albumprefs_privacy] == "private" AND !isset($_COOKIE['album_pass'])) | $_COOKIE['album_pass'] != $album[albumprefs_password]) {

echo "

<table cellpadding='0' cellspacing='0' width='400' style='background: #F7F7F7; border: 1px solid #777777;'>
<form action='album.php?u_id=$u_id$code' method='POST'>
<tr>
<td valign='middle' style='padding: 10px;'>

<table cellpadding='0' cellspacing='0'>
<tr>
<td valign='top' style='padding-right: 10px;'>
<img src='./icons/key.gif' border='0'>
</td>
<td style='padding-top: 3px;'>
<b>This photo album is private.<br>To enter, please provide the password:</b><br><br>

<input type='hidden' name='task' value='set_cookie'>
<input type='password' size='25' class='text' name='password'>
<input type='submit' class='button' value='Submit' style='margin-bottom: 2px;'>
$result
</td></tr></table>
</td>
</tr>
</form>
</table>
";











// IF ALBUM IS ENABLED AND PUBLIC
} else {

$count = 0;
$folders = mysql_query("SELECT * FROM ims_folders WHERE u_id='$u_id' AND in_album='yes' ORDER BY name");

// IF THERE ARE NO FOLDERS
if(mysql_num_rows($folders) == 0) {
echo "
<table cellpadding='0' cellspacing='0' width='400' style='background: #F7F7F7; border: 1px solid #777777;'>
<tr>
<td style='padding: 10px;'>
<table cellpadding='0' cellspacing='0'>
<tr>
<td valign='middle' style='padding-right: 10px;'><img src='./icons/error.gif' border='0'></td>
<td><b>This photo album contains no image folders.<br>Please check back at a later time.</b></td>
</tr>
</table>
</td>
</tr>
</table>
";
} else {












echo "

<table width='$width' cellpadding='0' cellspacing='0' style='border-bottom: 1px solid #777777;'>
";

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";
}

while($folder = mysql_fetch_assoc($folders)) {
$count = $count + 1;
$getimages = mysql_query("SELECT i_id FROM ims_image WHERE f_id='$folder[f_id]'");
$firstimage = mysql_fetch_assoc(mysql_query("SELECT i_id FROM ims_image WHERE f_id='$folder[f_id]' ORDER BY $listby LIMIT 0,1"));
$images_inside = mysql_num_rows($getimages);
if($count % 2) { $bg = "#F7F7F7"; } else { $bg = "#FFFFFF"; }

if($images_inside == 0) { 
$thumb = "<a href='album_folder.php?u_id=$u_id$code&f_id=$folder[f_id]'><img src='./icons/emptyfolder.gif' border='0' style='border: 1px solid #666666;'></a>";
} else {
	if($album[albumprefs_thumbs] == "no") {
	$thumb = "<a href='album_folder.php?u_id=$u_id$code&f_id=$folder[f_id]'><img src='./icons/emptyfolder.gif' border='0' style='border: 1px solid #666666;'></a>";
	} else {
	$thisthumb = "thumbs.php?u=$u_id$code&i=$firstimage[i_id]";
	$thumb = "<a href='album_folder.php?u_id=$u_id$code&f_id=$folder[f_id]'><img src='$thisthumb' width='60' height='60' border='0' style='border: 1px solid #666666;'></a>";
	}
}


echo "
<tr>
<td style='border: 1px solid #777777; background: $bg; border-bottom: none;'>
";

if($count % 2) { $counttype = "odd"; } else { $counttype = "even"; }

// ALIGNED LEFT
if($album[albumprefs_align] == "left" OR ($album[albumprefs_align] == "alt" AND $counttype == "odd")) {
echo "
<table cellpadding='0' cellspacing='0'>
<tr>
<td width='20' style='padding: 5px;'>$thumb</td>
<td valign='top' style='padding: 5px; padding-left: 2px;'>
  <table cellpadding='0' cellspacing='0' width='100%'>
  <tr><td style='padding-bottom: 3px;'><b><a href='album_folder.php?u_id=$u_id$code&f_id=$folder[f_id]'>$folder[name]</a></b> ($images_inside images)</td></tr>
  <tr><td>$folder[description]</td></tr>
  </table>
</td>
</tr>
</table>
";
}

// ALIGNED RIGHT
if($album[albumprefs_align] == "right" OR ($album[albumprefs_align] == "alt" AND $counttype == "even")) {
echo "
<table cellpadding='0' cellspacing='0' align='right'>
<tr>
<td valign='top' style='padding: 5px; padding-right: 2px;'>
  <table cellpadding='0' cellspacing='0' width='100%'>
  <tr><td align='right' style='padding-bottom: 3px;'><b><a href='album_folder.php?u_id=$u_id$code&f_id=$folder[f_id]'>$folder[name]</a></b> ($images_inside images)</td></tr>
  <tr><td align='right'>$folder[description]</td></tr>
  </table>
</td>
<td width='20' style='padding: 5px; padding-left: 3px;'>$thumb</td>
</tr>
</table>
";
}


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

echo "</table>";

}
}












echo "
<table cellpadding='0' cellspacing='0' style='margin-top: 3px;'>
<tr>
<td align='center' style='color: #444444; padding-left: 1px;'>
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>
";

?>