#!/usr/bin/perl # ########################################################################### # # Basic script for displaying results. It's called in two ways, # either to display a single record, or to display multiple # records. # Name: display.cgi ########################################################################### # Basic script setup. push(@INC,"/var/lib/httpd/cgi-bin"); use DBI; require "cgi-lib.pl"; require "cookie.lib"; # Get variables from the post and from the cookies ready to go &ReadParse(*input); $startno = $input{'startnumber'}; # Start counting at $endno = $input{'endnumber'}; # End counting at $single = $input{'single'}; # We just displaying 1 record? $id = $input{'id'}; # if so, which one? &GetCookies; $username = $Cookies{'userted'}; # Obvious $password = $Cookies{'passwordted'}; # Obvious $prepare = $Cookies{'prepared'}; # This is the SELECT clause # Check to see if the username and password are okay by actually # connecting to the database. If it fails we know they were # invalid. $dbh = DBI->connect("DBI:mysql:filmlib",$username,$password) or die &ErrSpoiledCookie; # Header starts print "Content-type:text/html\n"; # Find out how we were called... if ($single ne "True") { # We weren't called to display a single record...so it's multiple # records we're looking for. Send it to Execute. &Execute($prepare,$startno,$endno); print &HtmlBot; } else { # We're just displaying one record...set it up and display it if ($username eq "read") { # No filemods for user 'read'. $filemod_menu = ""; } else { # It isn't the only read-only user...so let them see # the filemod menu (it won't work if they don't # have permissions anyway.) $filemod_menu = "
"; } # Prepare in the SQL clause to get all the fields of that one # record. $cursor = $dbh->prepare("SELECT ID, Title ,CATALOGNO,RUNTIME,ANNOTATION,LANGUAGE FROM Result3 WHERE ID=$id"); # And now execute it. $cursor->execute; # Gimme an array... my @smatch; # Now we'll stick our stuff in it (might not need this while loop.) while ( @smatch = $cursor->fetchrow_array ) { # Make sure the output looks nice. if ($smatch[5] eq "") { $langee = "(Not given)" } else { $langee = $smatch[5] } $title = $smatch[1]; $title =~ s/"/"\;/g; $annote = $smatch[4]; $annote =~ s/"/"\;/g; # And then print out the whole mess in an HTML table. print "Content-type:text/html\n\n"; print "Results For This Record"; print <
  Information on This Film/Video
Title:
Catalog Number: Runtime (in minutes): Language:
Information:

[Back to search results]

PS: If your browser is not JavaScript capable then please click the Back button on your browser window once to take you to the the search results

$filemod_menu [ Back To Main Page ]

ENDOFTABLE } # Okay...clean up our mess. Disconnect and drop the ending HTML. $cursor->finish; $dbh->disconnect; &HtmlBot; } # -----SubRoutines---- # sub Execute { # These variables were passed from the function call. local($pprepare) = @_[0]; # The SELECT statement local($start_num) = @_[1]; # Start counting at. local($end_num) = @_[2]; # ...and end counting at. # If either of the start or end numbers wasn't passed...die. # (Probably should come up with an error message for this.) if (($start_num eq "") || ($end_num eq "")) { print "\nERROR: Execute passed without parameters"; } # Prepare the SELECT clause and then execute it. $cursor = $dbh->prepare("$pprepare"); $cursor->execute; # I'll need an array to stick these into... my @field; # End the header (pass a cookie first.) &SetCookies('prepared',$prepare); print "\n"; # Start the HTML table for output. print "Database Results"; print ""; print "
"; print "
"; print ""; print "
Database Results\n"; print "
ID NumberTitleCatalog Number Runtime Language\n"; # Initialize our counter. $i=0; # Filter out the results. while ( @field = $cursor->fetchrow_array ) { # Only print the ones we want on this page. if (($i >= $start_num) && ($i <= $end_num)) { print "
$field[0] $field[1] $field[2] $field[3] $field[5]\n"; } # Increment the counter until it's all over. $i++; } # So how many records were there anyway? $count=$i-1; # End the table. print "
"; # Do we print the 'previous 20' button? PREVIOUS: { if ($start_num >= 20) { $start_no = $start_num - 20; $end_no = $end_num - 20; print " <- [ Previous 20 Records ] "; } } # Do we print the 'next 20' button? NEXT: { if ($start_num <= ($count-20)) { $start_no = $start_num + 20; $end_no = $end_num + 20; print " [ Next 20 Records ] ->"; } } # Clean up our mess...disconnect from the database and # send the ending html stuff. $cursor->finish; $dbh->disconnect; print < [ Back to Main Page ] TTT print "
"; &HtmlBot; exit (1); } sub ErrSpoiledCookie { print "Content-type:text/html\n\n"; print <Film/Video Library - Security Error 2:ErrSpoiledCookie
Security Error

There has been a security-related error. The information passed from your browser as an identification Cookie was not valid. Possible reasons for this could be that a Cookie was not set properly or has expired since last login. Please keep the following in mind:
  1. Our Cookies expire at the end of every session. This means that if you disconnect from your browser and reconnect at a later time, the Cookie information held by your browser will no longer be valid.
  2. Starting from the initial interface of this database will help insure that a fresh Cookie is set in your browser.

Please go back and try again.

END_ERRSPOILEDCOOKIE &HtmlBot; } sub HtmlBot { print "\n"; }