<?php
/****************************************************************************
* DRBImageGallery
* http://www.dbscripts.net/imagegallery/
*
* Copyright (c) 2007-2009 Don Barnes
****************************************************************************/
$ORDER_BY_PARAM_NAME = "_orderBy";
$OFFSET_PARAM_NAME = "_offset";
$DESCRIPTION_PARAM_NAME = "_description";
$NAME_PARAM_NAME = "_name";
$ATTRIBUTE_PARAM_NAME_PREFIX = "_q";
$MAX_SEARCH_VALUE_LENGTH = 64;
function find_images($where = NULL, $orderby = NULL, $offset = 0, $count = NULL) {
global $TABLE_IMAGE;
return db_find($TABLE_IMAGE, $where, $orderby, $offset, $count);
}
function count_images($where = NULL) {
global $TABLE_IMAGE;
return db_count($TABLE_IMAGE, $where);
}
function find_image($where) {
global $TABLE_IMAGE;
return db_find_fetch($TABLE_IMAGE, $where);
}
function find_image_by_filename($filename) {
return find_image("filename = '" . mysql_real_escape_string($filename) . "'");
}
function find_image_by_id($imageId) {
if(!is_numeric($imageId)) {
die("Invalid image.");
}
return find_image("imageId = " . mysql_real_escape_string($imageId));
}
function delete_image($where) {
global $TABLE_IMAGE;
$tablename = full_table_name($TABLE_IMAGE);
return db_execute("delete from " . $tablename . " where " . $where);
}
function delete_image_by_filename($filename) {
$res = find_image_by_filename($filename);
delete_image_by_id($res["imageId"]);
}
function delete_image_by_id($imageId) {
// Delete child records
delete_image_attribute_values_by_imageId($imageId);
// Delete image
return delete_image("imageId = " . mysql_real_escape_string($imageId));
}
function validate_image($assoc) {
global $MAX_IMAGE_FILENAME_LENGTH;
global $MAX_IMAGE_NAME_LENGTH;
global $MAX_IMAGE_DESCRIPTION_LENGTH;
if(validate_length($assoc, 'filename', $MAX_IMAGE_FILENAME_LENGTH) === FALSE) return FALSE;
if(validate_length($assoc, 'name', $MAX_IMAGE_NAME_LENGTH) === FALSE) return FALSE;
if(validate_length($assoc, 'description', $MAX_IMAGE_DESCRIPTION_LENGTH) === FALSE) return FALSE;
if(validate_notempty($assoc, 'filename') === FALSE) return FALSE;
return TRUE;
}
function insert_image($assoc) {
global $TABLE_IMAGE;
if(!validate_image($assoc)) return FALSE;
$literalValues = Array("addedDt" => "now()");
return db_insert($TABLE_IMAGE, $assoc, $literalValues);
}
function delete_thumbnail($thumbdirname, $filename) {
global $dbs_error;
$thumbpath = replace_file_extension($thumbdirname . '/' . $filename, "jpg");
if(!file_exists($thumbpath)) {
return TRUE;
}
if(@unlink($thumbpath) === FALSE) {
$dbs_error = "Delete failed: " . htmlspecialchars_default($thumbpath);
return FALSE;
}
return TRUE;
}
function delete_image_file($dirname, $filename) {
global $dbs_error;
$filepath = replace_file_extension($dirname . '/' . $filename, "jpg");
if(!file_exists($filepath)) {
return TRUE;
}
if(unlink($filepath) === FALSE) {
$dbs_error = "Delete failed: " . htmlspecialchars_default($filepath);
return FALSE;
}
return TRUE;
}
function add_new_image($filename, $dirname, $thumbdirname) {
global $CREATE_THUMBS;
// Insert image
$values = Array("filename" => $filename);
if(insert_image($values) === FALSE) {
return FALSE;
}
// Create thumbnail
if($CREATE_THUMBS === TRUE) {
if(create_thumbnail($dirname, $thumbdirname, $filename) === FALSE) {
global $dbs_error;
$dbs_error = "Error creating thumbnail for " . htmlspecialchars_default($filename) . ": " . htmlspecialchars_default($dbs_error);
return FALSE;
}
}
return TRUE;
}
function remove_image($image) {
global $IMAGE_FOLDER;
global $THUMB_FOLDER;
$image_path = dirname(__FILE__) . '/../' . $IMAGE_FOLDER;
$thumb_path = dirname(__FILE__) . '/../' . $THUMB_FOLDER;
if(delete_thumbnail($thumb_path, $image['filename']) === FALSE) return FALSE;
if(delete_image_file($image_path, $image['filename']) === FALSE) return FALSE;
if(delete_image_by_id($image['imageId']) === FALSE) return FALSE;
return TRUE;
}
function is_image_file($filepath) {
$filetype = get_file_extension($filepath);
if($filetype === FALSE) {
$dbs_error = "Cannot determine file type: " . htmlspecialchars_default($filepath);
return FALSE;
}
if($filetype == "png" || $filetype == "gif" || $filetype == "jpeg" || $filetype == "jpg") {
return TRUE;
} else {
return FALSE;
}
}
function image_create($filepath) {
global $dbs_error;
$filetype = get_file_extension($filepath);
if($filetype === FALSE) {
$dbs_error = "Cannot determine file type: " . htmlspecialchars_default($filepath);
return FALSE;
}
switch($filetype) {
case "png":
$image = imagecreatefrompng($filepath);
break;
case "gif":
$image = imagecreatefromgif($filepath);
break;
case "jpg":
case "jpeg":
$image = imagecreatefromjpeg($filepath);
break;
default:
$dbs_error = "Unsupported image file type: " . htmlspecialchars_default($filetype);
return FALSE;
}
if($image === FALSE) {
$dbs_error = "image_create failed.";
return FALSE;
}
return $image;
}
function create_thumbnail($dirname, $thumbdirname, $filename) {
global $dbs_error;
$filepath = rtrim($dirname, "/") . '/' . $filename;
$thumbpath = replace_file_extension(rtrim($thumbdirname, "/") . "/" . $filename, "jpg");
// Confirm that directory exists
if(!file_exists($thumbdirname)) {
mkdir($thumbdirname);
}
// Get thumbnail size
$size = get_thumbnail_size($filepath);
if($size === FALSE) return FALSE;
// Create thumbnail
$thumbWidth = $size[2];
$thumbHeight = $size[3];
$imageOut = imagecreatetruecolor($thumbWidth, $thumbHeight);
if($imageOut === FALSE) {
$dbs_error = "imagecreatetruecolor failed.";
return FALSE;
}
$imageIn = image_create($filepath);
if($imageIn === FALSE) return FALSE;
if(imagecopyresampled($imageOut, $imageIn, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $size[0], $size[1]) === FALSE) {
$dbs_error = "imagecopyresampled failed.";
return FALSE;
}
if(imagejpeg($imageOut, $thumbpath, 100) === FALSE) {
$dbs_error = "imagejpeg failed.";
return FALSE;
}
return TRUE;
}
function get_thumbnail_size($filepath) {
global $MAX_THUMB_WIDTH;
global $MAX_THUMB_HEIGHT;
global $dbs_error;
// Get initial width and height
$size = getimagesize($filepath);
if($size === FALSE) {
$dbs_error = "getimagesize failed.";
return FALSE;
}
$origWidth = $thumbWidth = $size[0];
$origHeight = $thumbHeight = $size[1];
// Change width and height to fit maximums
if($thumbWidth > $MAX_THUMB_WIDTH) {
$aspect = $MAX_THUMB_WIDTH / $thumbWidth;
$thumbWidth = round($aspect * $thumbWidth);
$thumbHeight = round($aspect * $thumbHeight);
}
if($thumbHeight > $MAX_THUMB_HEIGHT) {
$aspect = $MAX_THUMB_HEIGHT / $thumbHeight;
$thumbWidth = round($aspect * $thumbWidth);
$thumbHeight = round($aspect * $thumbHeight);
}
return array($origWidth, $origHeight, $thumbWidth, $thumbHeight);
}
function update_image($assoc, $imageId) {
global $TABLE_IMAGE;
if(!validate_image($assoc)) return FALSE;
if(empty($imageId)) {
global $dbs_error;
$dbs_error = "An image ID was not provided.";
return FALSE;
}
return db_update($TABLE_IMAGE, $assoc, "imageId = " . mysql_real_escape_string($imageId));
}
function is_an_attribute_param($name) {
global $ATTRIBUTE_PARAM_NAME_PREFIX;
return (substr($name, 0 , strlen($ATTRIBUTE_PARAM_NAME_PREFIX)) == $ATTRIBUTE_PARAM_NAME_PREFIX);
}
function is_a_query_param($name) {
global $ORDER_BY_PARAM_NAME;
global $OFFSET_PARAM_NAME;
global $DESCRIPTION_PARAM_NAME;
global $NAME_PARAM_NAME;
return (is_an_attribute_param($name) ||
$name == $ORDER_BY_PARAM_NAME ||
$name == $OFFSET_PARAM_NAME ||
$name == $DESCRIPTION_PARAM_NAME ||
$name == $NAME_PARAM_NAME);
}
function query_to_where() {
global $TABLE_IMAGE_ATTRIBUTE_VALUE;
global $ATTRIBUTE_PARAM_NAME_PREFIX;
$tableImgAttrValName = full_table_name($TABLE_IMAGE_ATTRIBUTE_VALUE);
$where = "";
foreach($_REQUEST as $name => $value) {
if(is_an_attribute_param($name)) {
$attributeId = mysql_real_escape_string(substr($name, strlen($ATTRIBUTE_PARAM_NAME_PREFIX)));
if(!is_numeric($attributeId)) {
die("Invalid parameter: " . htmlspecialchars_default($name));
}
$queryValue = mysql_real_escape_string($value);
if(!empty($queryValue)) {
if(!is_numeric($queryValue)) {
die("Invalid value: " . htmlspecialchars_default($queryValue));
}
if(strlen($where) > 0) $where .= " and";
$where .= " exists (select 1 from {$tableImgAttrValName} iav where iav.attributeId = {$attributeId}"
. " and iav.valueId = $queryValue and iav.imageId = a.imageId)";
}
}
}
global $MAX_SEARCH_VALUE_LENGTH;
// Handle name
global $NAME_PARAM_NAME;
if(isset($_REQUEST[$NAME_PARAM_NAME]) && !empty($_REQUEST[$NAME_PARAM_NAME])) {
if(strlen($_REQUEST[$NAME_PARAM_NAME]) > $MAX_SEARCH_VALUE_LENGTH) {
die("The specified search value for name is too long.");
}
$nameValue = mysql_real_escape_string($_REQUEST[$NAME_PARAM_NAME]);
if(strlen($where) > 0) $where .= " and";
$where .= " a.name like '%" . $nameValue . "%'";
}
// Handle description
global $DESCRIPTION_PARAM_NAME;
if(isset($_REQUEST[$DESCRIPTION_PARAM_NAME]) && !empty($_REQUEST[$DESCRIPTION_PARAM_NAME])) {
if(strlen($_REQUEST[$DESCRIPTION_PARAM_NAME]) > $MAX_SEARCH_VALUE_LENGTH) {
die("The specified search value for description is too long.");
}
$descriptionValue = mysql_real_escape_string($_REQUEST[$DESCRIPTION_PARAM_NAME]);
if(strlen($where) > 0) $where .= " and";
$where .= " a.description like '%" . $descriptionValue . "%'";
}
if($where === "") $where = NULL;
return $where;
}
function query_to_order_by() {
global $ORDER_BY_PARAM_NAME;
$orderByValue = (isset($_REQUEST[$ORDER_BY_PARAM_NAME])?$_REQUEST[$ORDER_BY_PARAM_NAME]:NULL);
if(empty($orderByValue)) {
$orderByValue = "addedDt";
}
if($orderByValue !== "name" && $orderByValue !== "addedDt") {
die("Invalid order by value.");
}
if($orderByValue == "addedDt") $orderByValue = "addedDt desc";
return $orderByValue;
}
function query_to_offset() {
global $OFFSET_PARAM_NAME;
if(isset($_REQUEST[$OFFSET_PARAM_NAME])) {
$paramValue = $_REQUEST[$OFFSET_PARAM_NAME];
if(!is_numeric($paramValue) || $paramValue < 0) {
die("Invalid offset.");
}
return $paramValue;
} else {
return 0;
}
}
function image_details_table_from_query($queryAction) {
image_details_table(query_to_where(), query_to_order_by(), query_to_offset(), NULL, $queryAction);
}
function image_thumbs_table_from_query() {
image_thumbs_table(query_to_where(), query_to_order_by(), query_to_offset());
}
function image_count($where, $offset, $count) {
$imageCount = count_images($where);
if($offset >= $imageCount && $offset !== 0) die("Invalid offset.");
$firstImageCount = $offset + 1;
$lastImageCount = $offset + $count;
if($lastImageCount > $imageCount) $lastImageCount = $imageCount;
if($imageCount > 0) {
global $RESULTS_TEXT;
$resultsText = sprintf($RESULTS_TEXT, $firstImageCount, $lastImageCount, $imageCount);
echo("<p>" . htmlspecialchars_default($resultsText) . "</p>\n");
} else {
global $ERROR_MSG_NO_RESULTS;
echo("<p>" . htmlspecialchars_default($ERROR_MSG_NO_RESULTS) . "</p>\n");
}
return $imageCount;
}
function getImageURL($filename) {
global $base_url;
global $IMAGE_FOLDER;
$encodedFilename = implode("/", array_map("rawurlencode", explode("/", $filename)));
return $base_url . rawurlencode($IMAGE_FOLDER) . '/' . $encodedFilename;
}
function getThumbURL($filename) {
global $CREATE_THUMBS;
$folder = "";
if($CREATE_THUMBS === TRUE) {
global $THUMB_FOLDER;
$folder = $THUMB_FOLDER;
} else {
global $IMAGE_FOLDER;
$folder = $IMAGE_FOLDER;
}
$encodedFilename = implode("/", array_map("rawurlencode", explode("/", replace_file_extension($filename, "jpg"))));
global $base_url;
return $base_url . rawurlencode($folder) . '/' . $encodedFilename;
}
function getImagePageURL($imageId) {
// Get query string for results
$queryString = image_nav_get();
// Append image ID to query string
if(strlen($queryString) > 0) $queryString .= "&";
$queryString .= "imageId=" . urlencode($imageId);
return ".?" . $queryString;
}
function image_nav_get() {
$queryString = "";
foreach($_REQUEST as $name => $value) {
if(is_a_query_param($name) && !empty($value)) {
if(strlen($queryString) > 0) $queryString .= "&";
$queryString .= urlencode($name) . "=" . urlencode($value);
}
}
return $queryString;
}
function image_details_table($where = NULL, $orderby = NULL, $offset = 0, $count = NULL, $queryAction = NULL) {
global $IMAGE_FOLDER;
global $MAX_RESULTS_PER_PAGE;
if(!isset($count)) $count = $MAX_RESULTS_PER_PAGE;
$imageCount = image_count($where, $offset, $count);
$res = find_images($where, $orderby, $offset, $count);
if($res === FALSE) {
global $dbs_error;
die('Could not find images: ' . htmlspecialchars_default($dbs_error));
}
echo("<div class=\"thumbnailContainer\">\n");
echo("<table>\n");
echo("<tr>\n");
if($_SESSION['admin'] == "TRUE") {
echo("<th colspan=\"2\">Options</th>\n");
}
echo("<th>Image</th>\n");
echo("<th>Name and Description</th>\n");
echo("<th>Attributes</th>\n");
echo("</tr>\n");
while( ($assoc = db_fetch($res)) !== FALSE ) {
$thumb_url = getThumbURL($assoc['filename']);
$img_url = getImageURL($assoc['filename']);
echo("<tr>\n");
if($_SESSION['admin'] == "TRUE") {
?>
<td class="buttonCol">
<form method="post" action="index.php">
<p>
<input type="hidden" name="action" value="showimage" />
<input type="hidden" name="imageId" value="<?php echo(htmlspecialchars_default($assoc['imageId'])) ?>" />
<?php
// Post the query with the edit request, so that user can return to results
foreach($_REQUEST as $name => $value) {
if(is_a_query_param($name) && !empty($value)) {
?>
<input type="hidden" name="<?php echo( htmlspecialchars_default($name) ); ?>" value="<?php echo( htmlspecialchars_default($value) ); ?>" />
<?php
}
}
?>
<input type="submit" value="Edit" class="submit" />
</p>
</form>
</td>
<td class="buttonCol">
<form method="post" action="index.php" onsubmit="return confirm('Are you sure you want to delete this image? The image file and all assignments associated with this image will be permanently deleted!')">
<p>
<input type="hidden" name="action" value="deleteimage" />
<input type="hidden" name="imageId" value="<?php echo(htmlspecialchars_default($assoc['imageId'])) ?>" />
<?php
// Post the query with the edit request, so that user can return to results
foreach($_REQUEST as $name => $value) {
if(is_a_query_param($name) && !empty($value)) {
?>
<input type="hidden" name="<?php echo( htmlspecialchars_default($name) ); ?>" value="<?php echo( htmlspecialchars_default($value) ); ?>" />
<?php
}
}
?>
<input type="submit" value="Delete" class="submit" />
</p>
</form>
</td>
<?php
}
echo("<td><a href=\"{$img_url}\"><img src=\"{$thumb_url}\" alt=\"" . htmlspecialchars_default($assoc['name']) . "\" class=\"thumbnail\" /></a><br />\n" . htmlspecialchars_default($assoc['filename']) . "</td>\n");
echo("<td>\n<strong>" . htmlspecialchars_default($assoc['name']) . "</strong>\n<br /><br />" . htmlspecialchars_default($assoc['description']) . "\n</td>\n");
echo("<td>\n");
image_attribute_value_list_by_imageId($assoc['imageId']);
echo("</td>\n");
echo("</tr>\n");
}
echo("</table>\n");
nav_buttons($offset, $count, $imageCount, $queryAction);
echo("</div>\n");
}
function image_thumbs_table($where = NULL, $orderby = NULL, $offset = 0, $count = NULL) {
global $IMAGE_FOLDER;
global $MAX_RESULTS_PER_PAGE;
if(!isset($count)) $count = $MAX_RESULTS_PER_PAGE;
$imageCount = image_count($where, $offset, $count);
$res = find_images($where, $orderby, $offset, $count);
if($res === FALSE) {
global $dbs_error;
die('Could not find images: ' . htmlspecialchars_default($dbs_error));
}
echo("<div class=\"thumbnailContainer\">\n");
while( ($assoc = db_fetch($res)) !== FALSE ) {
$thumb_url = getThumbURL($assoc['filename']);
global $LINK_RESULTS_TO_PAGE;
$img_url = "";
if($LINK_RESULTS_TO_PAGE === TRUE) {
$img_url = getImagePageURL($assoc['imageId']);
} else {
$img_url = getImageURL($assoc['filename']);
}
echo("<div class=\"thumbnail\">\n");
$alt = "";
if(!empty($assoc['description'])) {
$alt = " alt=\"" . htmlspecialchars_default($assoc['description']) . "\"";
} else {
$alt = " alt=\"no description available\"";
}
echo("<a href=\"{$img_url}\"><img src=\"{$thumb_url}\"{$alt} /></a><br />\n");
if(!empty($assoc['name'])) echo(htmlspecialchars_default($assoc['name']) . "<br />\n");
echo("</div>\n");
}
nav_buttons($offset, $count, $imageCount);
echo("</div>\n");
}
function nav_buttons($offset, $count, $imageCount, $queryAction = NULL) {
global $SHOW_FIRST_AND_LAST_BUTTONS;
global $NAV_FIRST_BUTTON_TEXT;
global $NAV_PREVIOUS_BUTTON_TEXT;
global $NAV_NEXT_BUTTON_TEXT;
global $NAV_LAST_BUTTON_TEXT;
echo("<div class=\"tableNav\">\n");
global $MAX_RESULTS_PER_PAGE;
if($offset > 0) {
$nextOffset = $offset - $count;
if($nextOffset < 0) $nextOffset = 0;
if($SHOW_FIRST_AND_LAST_BUTTONS == TRUE) image_nav_form($NAV_FIRST_BUTTON_TEXT, 0, "tableNavBack", $queryAction);
image_nav_form($NAV_PREVIOUS_BUTTON_TEXT, $nextOffset, "tableNavBack", $queryAction);
}
if($offset + $count < $imageCount) {
if($SHOW_FIRST_AND_LAST_BUTTONS == TRUE) image_nav_form($NAV_LAST_BUTTON_TEXT, ($imageCount - 1) - (($imageCount - 1) % $MAX_RESULTS_PER_PAGE), "tableNavForward", $queryAction);
image_nav_form($NAV_NEXT_BUTTON_TEXT, $offset + $count, "tableNavForward", $queryAction);
}
echo("</div>\n");
}
function image_nav_form($buttonName, $offset, $class, $action = NULL) {
?>
<form method="get" action="index.php" class="<?php echo( htmlspecialchars_default($class) ); ?>">
<div>
<?php
image_nav_input($offset, $action);
?>
<input type="submit" value="<?php echo( htmlspecialchars_default($buttonName) ); ?>" class="submit" />
</div>
</form>
<?php
}
function image_nav_input($offset, $action = NULL) {
global $OFFSET_PARAM_NAME;
if(!empty($action)) {
?>
<input type="hidden" name="action" value="<?php echo( htmlspecialchars_default($action) ); ?>" />
<?php
}
foreach($_REQUEST as $name => $value) {
if(is_a_query_param($name) && $name !== $OFFSET_PARAM_NAME && !empty($value)) {
?>
<input type="hidden" name="<?php echo( htmlspecialchars_default($name) ); ?>" value="<?php echo( htmlspecialchars_default($value) ); ?>" />
<?php
}
}
if(!isset($offset) && isset($_REQUEST[$OFFSET_PARAM_NAME])) $offset = $_REQUEST[$OFFSET_PARAM_NAME];
if(!empty($offset)) {
?>
<input type="hidden" name="<?php echo($OFFSET_PARAM_NAME); ?>" value="<?php echo( htmlspecialchars_default($offset) ); ?>" />
<?php
}
}
function image_query_form($legend = NULL, $action = NULL) {
if(empty($legend)) {
// Get default legend from strings configuration
global $SEARCH_FORM_LEGEND;
$legend = $SEARCH_FORM_LEGEND;
}
?>
<form method="get" action="index.php">
<fieldset>
<legend><?php echo($legend); ?></legend>
<?php
if(isset($action)) {
echo("<input type=\"hidden\" name=\"action\" value=\"" . htmlspecialchars_default($action) . "\" />\n");
}
echo("<p>\n");
global $MAX_SEARCH_VALUE_LENGTH;
// Add name field
global $ALLOW_SEARCH_BY_NAME;
if($ALLOW_SEARCH_BY_NAME === TRUE) {
global $NAME_PARAM_NAME;
echo("<label for=\"{$NAME_PARAM_NAME}\">Name:</label>\n");
$paramValue = (isset($_REQUEST[$NAME_PARAM_NAME])?$_REQUEST[$NAME_PARAM_NAME]:NULL);
$value = (empty($paramValue)?"":"value=\"" . htmlspecialchars_default($paramValue) . "\" ");
echo("<input type=\"text\" name=\"{$NAME_PARAM_NAME}\" id=\"{$NAME_PARAM_NAME}\" maxlength=\"{$MAX_SEARCH_VALUE_LENGTH}\" {$value}class=\"inputText\" />\n<br />\n");
}
// Add description field
global $ALLOW_SEARCH_BY_DESCRIPTION;
if($ALLOW_SEARCH_BY_DESCRIPTION === TRUE) {
global $DESCRIPTION_PARAM_NAME;
echo("<label for=\"{$DESCRIPTION_PARAM_NAME}\">Description:</label>\n");
$paramValue = (isset($_REQUEST[$DESCRIPTION_PARAM_NAME])?$_REQUEST[$DESCRIPTION_PARAM_NAME]:NULL);
$value = (empty($paramValue)?"":"value=\"" . htmlspecialchars_default($paramValue) . "\" ");
echo("<input type=\"text\" name=\"{$DESCRIPTION_PARAM_NAME}\" id=\"{$DESCRIPTION_PARAM_NAME}\" maxlength=\"{$MAX_SEARCH_VALUE_LENGTH}\" {$value}class=\"inputText\" />\n<br />\n");
}
// Add attribute field
image_query_fields();
// Add order by field
global $ORDER_BY_PARAM_NAME;
global $SORT_FIELD_NAME;
$paramValue = (isset($_REQUEST[$ORDER_BY_PARAM_NAME])?$_REQUEST[$ORDER_BY_PARAM_NAME]:NULL);
echo("<label for=\"{$ORDER_BY_PARAM_NAME}\">" . htmlspecialchars_default($SORT_FIELD_NAME) . ":</label>\n");
echo("<select name=\"{$ORDER_BY_PARAM_NAME}\" id=\"{$ORDER_BY_PARAM_NAME}\">\n");
echo("<option value=\"name\"" . ($paramValue==="name"?" selected=\"selected\"":"") . ">Name</option>\n");
echo("<option value=\"addedDt\"" . ($paramValue==="addedDt"?" selected=\"selected\"":"") . ">Date Added</option>\n");
echo("</select>\n");
echo("</p>\n");
global $SEARCH_FORM_BUTTON_TEXT;
?>
<input type="submit" value="<?php echo(htmlspecialchars_default($SEARCH_FORM_BUTTON_TEXT)); ?>" class="submit" />
</fieldset>
</form>
<?php
}
function image_query_fields() {
global $ATTRIBUTE_PARAM_NAME_PREFIX;
// Get list of attributes
$attributes = find_attributes(NULL, "sequenceNum");
if($attributes === FALSE) {
global $dbs_error;
die('Could not find attributes: ' . htmlspecialchars_default($dbs_error));
}
while( ($attribute = db_fetch($attributes)) !== FALSE ) {
$paramName = $ATTRIBUTE_PARAM_NAME_PREFIX . htmlspecialchars_default($attribute['attributeId']);
$paramValue = htmlspecialchars_default( isset($_REQUEST[$paramName])?$_REQUEST[$paramName]:NULL );
$attributeName = htmlspecialchars_default($attribute['name']);
echo("<label for=\"{$paramName}\">{$attributeName}:</label>\n");
echo("<select name=\"{$paramName}\" id=\"{$paramName}\">\n");
echo("<option value=\"\"></option>\n");
$values = find_values_by_attributeId($attribute['attributeId']);
if($values === FALSE) {
global $dbs_error;
die('Could not find values: ' . htmlspecialchars_default($dbs_error));
}
while( ($value = db_fetch($values)) !== FALSE ) {
$optionValue = htmlspecialchars_default($value['valueId']);
$optionName = htmlspecialchars_default($value['value']);
$selected = "";
if($optionValue == $paramValue) $selected = " selected=\"selected\"";
echo("<option value=\"{$optionValue}\"$selected>{$optionName}</option>\n");
}
echo("</select>\n");
echo("<br />\n");
}
}
function load_image($imageId) {
global $the_image;
$the_image = find_image_by_id($imageId);
return $the_image;
}
function image_url() {
global $the_image;
echo getImageURL($the_image['filename']);
}
function image_name() {
global $the_image;
echo htmlspecialchars_default($the_image['name']);
}
function image_description() {
global $the_image;
echo htmlspecialchars_default($the_image['description']);
}
function image_attribute_values() {
global $the_image;
image_attribute_value_list_by_imageId($the_image['imageId']);
}
function back_to_search_results() {
global $OFFSET_PARAM_NAME;
global $BACK_TO_RESULTS_BUTTON_TEXT;
image_nav_form($BACK_TO_RESULTS_BUTTON_TEXT, (isset($_REQUEST[$OFFSET_PARAM_NAME])?$_REQUEST[$OFFSET_PARAM_NAME]:NULL), "bottomPageNav");
}
?>