<?
include "header.php";
if($user_info[photo_album] != "yes") { exit; }

if(isset($_POST['task'])) {
  if($_POST['task'] == "unset_cookie") {
    setcookie("album_pass", "", 0, "/");
    header("Location: album.php?u_id=$user_info[u_id]$user_info[code]");
    exit();
  }
}



echo $header;




if(isset($_POST['submit'])) {
$albumprefs_on = $_POST['albumprefs_on'];
$albumprefs_privacy = $_POST['albumprefs_privacy'];
$albumprefs_password = $_POST['albumprefs_password'];
$albumprefs_logo = str_replace("'", "&#39;", $_POST['albumprefs_logo']);
$albumprefs_thumbs = $_POST['albumprefs_thumbs'];
$albumprefs_align = $_POST['albumprefs_align'];
$albumprefs_width = $_POST['albumprefs_width'];
$albumprefs_head = str_replace("</textarea>", "&lt;/textarea>", $_POST['albumprefs_head']);
$albumprefs_foot = str_replace("</textarea>", "&lt;/textarea>", $_POST['albumprefs_foot']);

// BE SURE THAT RADIOS ARE FILLED IN
if($albumprefs_on == "") { $albumprefs_on = "no"; }
if($albumprefs_privacy == "") { $albumprefs_privacy = "public"; }

// MAKE SURE A PASSWORD IS ASSIGNED IF SET TO PRIVATE
if($albumprefs_privacy == "private" AND $albumprefs_password == "") {
echo "
<table width='520' cellpadding='0' cellspacing='0'>
<tr><td>
<b>An Error Has Occurred</b><br>Because you have set your Photo Album to \"private\", you must provide a password.
<br><br>
<table cellpadding='0' cellspacing='0'>
<tr>
<form action='view_album.php' method='POST'>
<td><input type='submit' class='button' value='Try Again'></td>
</form>
</tr>
</table>
</td></tr></table>
";
echo $footer;
exit;
}


if(preg_match("/[^a-z,A-Z,0-9]/", $albumprefs_password)) {
echo "
<table width='520' cellpadding='0' cellspacing='0'>
<tr><td>
<b>An Error Has Occurred</b><br>Your photo album password may only contain alpha-numeric characters.
<br><br>
<table cellpadding='0' cellspacing='0'>
<tr>
<form action='view_album.php' method='POST'>
<td><input type='submit' class='button' value='Try Again'></td>
</form>
</tr>
</table>
</td></tr></table>
";
echo $footer;
exit;
}



$folders = mysql_query("SELECT * FROM ims_folders WHERE u_id='$user_info[u_id]'");
while($folder_info = mysql_fetch_assoc($folders)) {
  $var = "album_on".$folder_info[f_id];
  if($_POST[$var] == "yes") { $in_album = "yes"; } else { $in_album = "no"; }
  mysql_query("UPDATE ims_folders SET in_album='$in_album' WHERE f_id='$folder_info[f_id]' AND u_id='$user_info[u_id]'"); 
}


// SAVE SETTINGS
mysql_query("UPDATE ims SET albumprefs_on='$albumprefs_on', albumprefs_privacy='$albumprefs_privacy', albumprefs_password='$albumprefs_password', albumprefs_thumbs='$albumprefs_thumbs', albumprefs_align='$albumprefs_align', albumprefs_width='$albumprefs_width', albumprefs_logo='$albumprefs_logo', albumprefs_head='$albumprefs_head', albumprefs_foot='$albumprefs_foot' WHERE u_id='$user_info[u_id]'");
echo "
<table width='520' cellpadding='0' cellspacing='0'>
<tr><td>
<b>Settings Saved</b><br>
Your Photo Album settings have been saved. 
<br><br>

<table cellpadding='0' cellspacing='0'>
<tr>
<form action='view_album.php' method='POST'><td><input type='submit' class='button' value='Return To Settings'>&nbsp;</td></form>
</tr>
</table>
</td></tr></table>
";
echo $footer;
exit;
}





$album = mysql_fetch_assoc(mysql_query("SELECT * FROM ims WHERE u_id='$user_info[u_id]'"));
echo "
<table width='520' cellpadding='0' cellspacing='0'>
<tr><td valign='top'>
<b>Photo Album Settings</b><br>
Use this page to configure your online Photo Album.
</td>
<form action='view_album.php' target='_blank' method='POST'>
<td style='padding-top: 8px;'>
<input type='hidden' name='task' value='unset_cookie'>
<input type='submit' class='button' value='View My Photo Album'>
</td>
</form>
</tr>
</table>
<br>

<table width='520' cellpadding='0' cellspacing='0' style='border: 1px solid #AAAAAA; background: #FFFFFF;' style='margin-bottom: 8px;'>
<form name='prefs' action='view_album.php' method='POST'>
<tr><td style='padding: 5px; padding-bottom: 0px;'>Would you like to turn your Photo Album on or off?</td></tr>
<tr>
<td style='padding: 3px; padding-top: 2px;'>
  <table cellpadding='0' cellspacing='0'>
  <td><input type='radio' name='albumprefs_on' value='yes'"; if($album[albumprefs_on] == "yes") { echo " CHECKED"; } echo "></td><td valign='top'><b>On</b>&nbsp;&nbsp;&nbsp;</td>
  <td><input type='radio' name='albumprefs_on' value='no'"; if($album[albumprefs_on] == "no") { echo " CHECKED"; } echo "></td><td valign='top'><b>Off</b></td>
  </tr></table>
</td>
</tr></table>

<script language='JavaScript'>
<!--
function enable(field) {
document.prefs.albumprefs_password.disabled = false;
document.prefs.albumprefs_password.style.background = '#FFFFFF'
}
function disable(field) {
document.prefs.albumprefs_password.value = '';
document.prefs.albumprefs_password.disabled = true;
document.prefs.albumprefs_password.style.background = '#EEEEEE'
}
// -->
</script>

<table width='520' cellpadding='0' cellspacing='0' style='border: 1px solid #AAAAAA; background: #FFFFFF;' style='margin-bottom: 8px;'>
<tr>
<td width='275' style='padding: 5px; padding-bottom: 0px;'>Do you want your Photo Album to be public or private?</td>
<td style='padding: 5px; padding-bottom: 0px;'>If private, enter password:</td>
</tr>
<tr>
<td style='padding: 3px; padding-top: 2px;'>
  <table cellpadding='0' cellspacing='0'>
  <td><input type='radio' name='albumprefs_privacy' value='public' onClick=\"disable('albumprefs_password')\""; if($album[albumprefs_privacy] == "public") { echo " CHECKED"; } echo "></td><td valign='top'><b>Public</b>&nbsp;&nbsp;&nbsp;</td>
  <td><input type='radio' name='albumprefs_privacy' value='private' onClick=\"enable('albumprefs_password')\""; if($album[albumprefs_privacy] == "private") { echo " CHECKED"; } echo "></td><td valign='top'><b>Private</b></td>
  </tr></table>
</td>
<td style='padding: 3px; padding-top: 2px;'>
  <table cellpadding='0' cellspacing='0'>
  <td><input type='text' class='text' name='albumprefs_password' maxlength='20' value='$album[albumprefs_password]' style='margin-left: 2px;'"; if($album[albumprefs_privacy] == "public") { echo " DISABLED style='background: #EEEEEE;'"; } echo "></td>
  </tr></table>
</td>
</tr></table>
";



$folders = mysql_query("SELECT * FROM ims_folders WHERE u_id='$user_info[u_id]' ORDER BY name");
$folder_count = mysql_num_rows($folders);

if($folder_count == 0) {
$blurb = "
<font color='#FF0000'>
<b>There are no existing folders in your account.</b><br> You must create an image
folder and upload at least one image before your photo album
will be viewable.
</font>
";
} else {
$blurb = "
Select which image folders you would like to include in your Photo Album.
";
}

echo "
<table width='520' cellpadding='0' cellspacing='0' style='border: 1px solid #AAAAAA; background: #FFFFFF;' style='margin-bottom: 8px;'>
<tr><td style='padding: 5px; padding-bottom: 0px;'>$blurb</td></tr>
<tr>
<td style='padding: 3px; padding-top: 2px;'>
  <table cellpadding='0' cellspacing='0'>
";

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

echo "
<tr>
<td><input type='checkbox' name='album_on$folder_info[f_id]' value='yes' style='margin-top: 2px;'"; if($folder_info[in_album] == "yes") { echo " CHECKED"; } echo ">&nbsp;<img src='./icons/sfolder.gif' border='0'>&nbsp;</td>
<td><b>$folder_info[name]</b> ($images_inside images)</td>
</tr>
";
}

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




echo "
<table width='520' cellpadding='0' cellspacing='0' style='border: 1px solid #AAAAAA; background: #FFFFFF;' style='margin-bottom: 8px;'>
<tr><td style='padding: 5px; padding-bottom: 0px;'>Do you want to display thumbnails or folder icons on your Photo Album homepage?</td></tr>
<tr>
<td style='padding: 3px; padding-top: 2px;'>
  <table cellpadding='0' cellspacing='0'>
  <td><input type='radio' name='albumprefs_thumbs' value='yes'"; if($album[albumprefs_thumbs] == "yes") { echo " CHECKED"; } echo "></td><td valign='top'><b>Thumbnails</b>&nbsp;&nbsp;&nbsp;</td>
  <td><input type='radio' name='albumprefs_thumbs' value='no'"; if($album[albumprefs_thumbs] == "no") { echo " CHECKED"; } echo "></td><td valign='top'><b>Folder Icons</b></td>
  </tr></table>
</td>
</tr>
<tr><td style='padding: 5px; padding-bottom: 0px;'>How do you want your image folders to be aligned on your Photo Album homepage?</td></tr>
<tr>
<td style='padding: 3px; padding-top: 2px;'>
  <table cellpadding='0' cellspacing='0'>
  <td><input type='radio' name='albumprefs_align' value='left'"; if($album[albumprefs_align] == "left") { echo " CHECKED"; } echo "></td><td valign='top'><b>Aligned Left</b>&nbsp;&nbsp;&nbsp;</td>
  <td><input type='radio' name='albumprefs_align' value='alt'"; if($album[albumprefs_align] == "alt") { echo " CHECKED"; } echo "></td><td valign='top'><b>Alternating</b>&nbsp;&nbsp;&nbsp;</td>
  <td><input type='radio' name='albumprefs_align' value='right'"; if($album[albumprefs_align] == "right") { echo " CHECKED"; } echo "></td><td valign='top'><b>Aligned Right</b></td>
  </tr></table>
</td>
</tr>
</table>

<table width='520' cellpadding='0' cellspacing='0' style='border: 1px solid #AAAAAA; background: #FFFFFF;' style='margin-bottom: 8px;'>
<tr><td style='padding: 5px; padding-bottom: 0px;'>If you would like to use a custom logo, enter the URL below (optional):</td></tr>
<tr>
<td style='padding: 3px; padding-top: 2px;'>
  <table cellpadding='0' cellspacing='0'>
  <td><input type='text' class='text' name='albumprefs_logo' value='$album[albumprefs_logo]' size='70' maxlength='200' style='margin-left: 2px;'></td>
  </tr></table>
</td>
</tr>
<tr><td style='padding: 5px; padding-bottom: 0px;'>How many pixels wide should your Photo Album be?</td></tr>
<tr>
<td style='padding: 3px; padding-top: 2px;'>
  <table cellpadding='0' cellspacing='0'>
<td>
<select name='albumprefs_width' style='margin-left: 2px;'>
<option value='300'"; if($album[albumprefs_width] == "300") { echo " SELECTED"; } echo ">300</option>
<option value='400'"; if($album[albumprefs_width] == "400") { echo " SELECTED"; } echo ">400</option>
<option value='500'"; if($album[albumprefs_width] == "500") { echo " SELECTED"; } echo ">500</option>
<option value='600'"; if($album[albumprefs_width] == "600") { echo " SELECTED"; } echo ">600</option>
<option value='700'"; if($album[albumprefs_width] == "700") { echo " SELECTED"; } echo ">700</option>
</select>
</td>
  </tr></table>
</td>
</tr>
<tr><td style='padding: 5px; padding-bottom: 0px;'>If you would like to include any header/footer text or HTML, provide it below:</td></tr>
<tr>
<td style='padding: 3px; padding-top: 2px; padding-left: 5px;'>
  <table cellpadding='0' cellspacing='0'>
  <td><b>Header</b> (optional)<br><textarea rows='5' name='albumprefs_head' cols='45' style='font-size: 9pt;'>$album[albumprefs_head]</textarea>&nbsp;</td>
  <td><b>Footer</b> (optional)<br><textarea rows='5' name='albumprefs_foot' cols='45' style='font-size: 9pt;'>$album[albumprefs_foot]</textarea></td>
  </tr></table>
</td>
</tr></table>
";




echo "
<table cellpadding='0' cellspacing='0'>
<tr><td colspan='2' style='padding-top: 10px;'><input class='button' name='submit' type='submit' value='Save Changes'"; if($admin_info[demo_feature] == "on" & $user_info[email] == "$admin_info[demo_email]") { echo " DISABLED"; } echo "></td></tr>
</form>
</table>
";



echo $footer;
?>