#!/usr/server/gnu/bin/perl $DEFAULT_SHOW = "4,2"; $THISCGIURL = "http://www.stecf.org/bin/heic_images3.pl"; $HOMEURL = "http://www.spacetelescope.org/gallery/"; $IMAGEDIRURL = "http://www.spacetelescope.org/HSTarchive"; print "Content-type: text/html\n\n"; $file = "/home/web/ecf/docs/bin/heic_images.dat"; open(I,"<$file") || die "Cannot read input file\n"; $numlines = `wc -l $file`; # # Save the UNESCAPED QUERY_STRING # { my ($k, $v, @save ); ( @save ) = split(/\&/,$ENV{'QUERY_STRING'}); foreach $save ( @save ) { ( $k, $v ) = split(/=/, $save); $QS{ $k } = $v; } } # # Get input parameters # use CGI; $query = new CGI; $fullsearch = $query->param("fullsearch"); $fullsearch = "ImPoSsIbLeEnTrY" unless $fullsearch; $search = $query->param("search"); $search = "ImPoSsIbLeEnTrY" unless $search; $from = $query->param("from"); $goto = $query->param("goto"); # possible values: "next" | "previous" $show = $query->param("show"); $show = $DEFAULT_SHOW unless $show; # # Define the search creterion (bit see also the while loop afterword) # if ( $search ne "ImPoSsIbLeEnTrY" ) { $searchfor = $search; } elsif ( $fullsearch ne "ImPoSsIbLeEnTrY" ) { $searchfor = $fullsearch; } # # Table aspect # ( $TABLECOLS , $TABLEROWS ) = split(/,/,$show); # # Number of cells to show # $nshow = $TABLECOLS * $TABLEROWS; # # Collect the FROM hash, which is structered in this way: # # UptoRecord => NumMatchingRecordsFound, etc. # # that is, 65=>8,127=>23 means # from record 1 to record 65 8 matching records were found # from record 1 to record 123 23 matching records were found # %from = eval "($from)"; # # Build the @form array ( ordered list of the keys of %form ) # ( @from ) = sort { $a <=> $b } keys ( %from ); # # Build the @found array ( list of the values of %form [ordered according to @from] ) # foreach $k ( @from ) { push ( @found, $from{$k} ); } # # Define "uptonow" # # It is the number of matching records from record 1 to the record after which # the new search will start. # $uptonow = $found[ $#found ]; # DEBUG: print " # Search starts at line ",$from[$#from]+1,"

\n"; # # Skip the first $from[$#from] lines # (until which we know that we found $uptonow matches # $row = 1; while( $row < $from[$#from] ) { $row++; ; } # DEBUG print "

FIRST FOUND AT ROW: $row

\n"; # # SEARCH! # while() { $row++; ( $thumbnail, $category, $opo_heic, $title, $description, $number, $original_file, $medium_jpeg, $large_jpeg, $object_name, $object_type, $year, $scientists, $credit, $instrument, $caption_link, $press_release_link ) = split(/\|/); if ( $object_type =~ /$search/i || /$fullsearch/i ) { $found++; # # Is this a query for a single selected record ? show="0,0" in that case. # if ( $show eq "0,0" ) { # # In this case the search must be conducted onto the "number" # if ( $number eq $fullsearch ) { # # Searched record found. Let's print it directly. # &PrintOne; last; } else { next; } } # # if it is not a query for a single selected record then ... # else { # # If there is still room, let's save also this matching record # otherwise, save the point where this is happening for the first time (lastrow) # but do not exit the loop, since we NEED to know how many other matching records there are. # if ( $found <= $nshow ) { &StoreTableCell( $found - 1 ); } else { if ( ! $lastrow ) { $lastrow = $row -1; } } } } } close(I); if ( ! $lastrow ) { # # it reached the end of file before finding any other matching entry. # $lastrow = $row-1; } # DEBUG print "

LAST FOUND AT ROW: $row

\n"; # # totalfound is the number of matching records # from the first given record ($from[$#from]) to the end of the file. # $totalfound = $found; $row--; # # How many records were here displayed ? # (Let's re-use $found for this purpose) # if ( $found < 1) { $found = "0"; } if ( $found > $nshow ) { $found = $nshow; } # # Hence up to now (lastrow) we have seen $uptonow + $found records # $uptonow += $found; # # Update @from and @found with this new values # push ( @from, $lastrow ); push ( @found, $uptonow ); # # If it was not a query for a single specific record # then print: # 1.- the table. # 2.- the howmany-records found/left section # 3.- the navigation (PREV/NEXT) buttons. # if ( $show ne "0,0" ) { &ESA_Header ( "Hubble Gallery Search Term: $searchfor" ); &PrintTable ( $found, $uptonow, $totalfound ); } &ESA_Footer; # # *** END OF MAIN ***************************************************** # sub PrintButtons { my ( $nextfrom, $previousfrom ); for ( $i=0; $i <= $#from; $i++) { if ($i > $#from-2) { $nextfrom .= $from[$i]."%3d%3e".$found[$i].","; } else { $nextfrom .= $from[$i]."%3d%3e".$found[$i].","; $previousfrom .= $from[$i]."%3d%3e".$found[$i].","; } } chop( $nextfrom ); # drop the comma chop( $previousfrom ); # drop the comma $search =~ s/\s/+/g; print "


\n\n"; if ( $from > 0 ) { print "\n\n"; } if ( $lastrow <= $numlines ) { print "\n\n"; } print "


\n\n"; print "Back to: \n"; print " \n"; #XXX print " \n"; } sub StoreTableCell { my ( $cellnum ) = @_; $cellrow = ( $cellnum - $cellnum % $TABLECOLS ) / $TABLECOLS; $cellcol = ( $cellnum % $TABLECOLS ); $Table[ $cellrow ][ $cellcol ] = ""; # WIDTH=140>"; $Title[ $cellrow ][ $cellcol ] = "$title"; $TableID[ $cellrow ][ $cellcol ] = "$number"; } sub PrintTable { my ( $ncells, $uptonow, $totalfound ) = @_; my $found = $ncells; my $cellrows = 0; my $cellcols = 0; my $row = 0; my $rows = 0; my $titleCellOpen = "

"; my $titleCellClose= "
"; my $imageCellOpen = "
"; my $imageCellClose= "
"; for ($cellnum=0; $cellnum<$ncells; $cellnum++) { $cellrow = ( $cellnum - $cellnum % $TABLECOLS ) / $TABLECOLS; $cellcol = ( $cellnum % $TABLECOLS ); $ImageRow[ $cellrow ] .= $imageCellOpen; $TitleRow[ $cellrow ] .= $titleCellOpen.$Title[ $cellrow ][ $cellcol ].$titleCellClose; if ( $TableID[ $cellrow ][ $cellcol ] ) { $ImageRow[ $cellrow ] .= ""; $ImageRow[ $cellrow ] .= $Table[ $cellrow ][ $cellcol ]; $ImageRow[ $cellrow ] .= ""; } else { $ImageRow[ $cellrow ] .= $Table[ $cellrow ][ $cellcol ]; } $ImageRow[ $cellrow ] .= $imageCellClose; } print "\n\n\n"; for( $row=0; $row < ( $ncells / $TABLECOLS ) ; $row++) { print "\n"; print " $ImageRow[ $row ]\n"; print "\n\n"; print "\n"; print " $TitleRow[ $row ]\n"; print "\n\n"; } print "\n\n"; print "
"; print "\n"; print ". "x80, "\n

\n"; print " Shown records: ", $uptonow - $found + 1 , " - ", $uptonow; print "         "; print " Remaining records: ", $totalfound - $found ,"\n"; print "\n
\n", ". "x80, "\n"; print "
\n"; &PrintButtons; print "

\n\n\n"; } sub PrintOne { &ESA_Header( $title ); print "
"; print " "; print " \n"; } else { print " $credit\n"; } print "


$description


"; print "

"; if ( $caption_link ) { print " Caption"; print "

\n"; } if ( $press_release_link ) { print " Release: $number"; } else { print " Release: $number"; } print "

Object: $object_name

Type: $object_type

Credits:"; if ( $scientists ) { print " $scientists
$credit

"; } sub ESA_Header { my ( $title ) = @_; if ( ! $title ) { $title = "Image archive query result"; } print ' ESA SCIENCE: Hubble
 

'. $title .'

 

 

'; #

 

} sub ESA_Footer { print '
 
'; } # thumbnail varchar(25) null, # category varchar(25) null, # opo_heic varchar(4) null, # title varchar(255) null, # description varchar(255) null, # number varchar(15) null, # original_file varchar(25) null, # medium_jpeg varchar(25) null, # large_jpeg varchar(25) null, # object_name varchar(75) null, # object_type varchar(35) null, # year varchar(4) null, # scientists varchar(255) null, # credit text(16) null, # instrument varchar(10) null, # caption_link varchar(100) null, # press_release_link varchar(100) null