#!/usr/bin/perl
#
# Part of the Escher Database
#
# Pass as the query string the ID of the picture from the database which
# is to be displayed. A page will be displayed with the picture and info
# about it from the database. Html files are supported to be displayed
# instead of pictures.
BEGIN { push (@INC,'../include/') }
use Db;
require 'mce.conf';
require 'cgi-lib.pl';
print &PrintHeader;
# id of item to display is...
$id=$ENV{QUERY_STRING};
# Find the image or html file for a picture in the passed subdirectory,
# and return the extention of the file. Return undef if it isn't found.
sub FindPicture { my ($dir,$id)=@_;
if (-e "$dir/$id.gif") { return '.gif' }
elsif (-e "$dir/$id.jpg") { return '.jpg' }
elsif (-e "$dir/$id.jpeg") { return '.jpeg' }
elsif (-e "./$id.html") { return '.html' }
}
# Look up the item in the database:
Db::load($dbloc);
if (!$Db::db{$id}{name}) { # bad database/can't find.
print "
Error!
Unable to find item $id in database.\b";
}
else { #pretty-print item.
$ext=FindPicture($dir,$id);
print "
$Db::db{$id}{name}
";
if ($ext && $ext ne ".html") {
print "$Db::db{$id}{name} ";
}
else {
print $Db::db{$id}{name}." ";
}
print ", also known as $Db::db{$id}{othernames}, " if $Db::db{$id}{othernames};
print "was created in $Db::db{$id}{date} " if $Db::db{$id}{date};
print "
$Db::db{$id}{comments}" if $Db::db{$id}{comments};
if ($ext && $ext ne '.html') { # display the picture.
print "
";
}
elsif ($ext eq 'html') { # display a html file.
print "
";
open (IN,"<./$id.html") || print $!;
while () { print $_ }
close IN;
print "";
}
print "- Medium: $Db::db{$id}{medium}" if $Db::db{$id}{medium};
print "
- Dimensions: $Db::db{$id}{dimensions} millimeters" if $Db::db{$id}{dimensions};
if ($Db::db{$id}{group}) { # gix up groups into search links.
if ($Db::db{$id}{group}=~m/,/ ne undef) {
print '
- Groups: ';
}
else {
print '
- Group: ';
}
foreach $group (split(/,/,$Db::db{$id}{group})) {
$group2=$group;
$group2=~tr/ /+/;
$group2=lc($group2);
$g_string.="$group, ";
}
$g_string=~s/, $/\n/;
print $g_string;
}
if ($Db::db{$id}{xref}) { # Fix up xrefs into links.
print "
- Cross references: ";
foreach $a (split(/[ |,]/,$Db::db{$id}{xref})) {
print "$Db::db{$a}{name} ";
}
}
print '
';
}
&PrintFooter;
print '';