#!/usr/bin/perl5 # !/usr/bin/perl # # CGI program to navigate within the magazine. It takes 3 arguments: # the issue name (i.e., "issue2.9") # the name of the current file # the command (Next, Prev, TOC, Rant, Arch, Us) # # If the command is Rant, Archive, or Staff, then it hands back the # requested file (rant page, archive page, masthead). If the command # is TOC, then it uses the issue name to hand back the TOC for that # issue. Otherwise, It uses the issue name to retrieve the issue_list # file from the issue directory, then scans that file for a name matching # the name passed in. When it finds one, it then applies the command # (next, previous) to determine the correct file to hand back. # # Sample invocation: # "../bin/nav_mag.cgi?iname=issue2.9&this=skippy.shtml&cmd=Next" # # this requires cgi-lib.pl push (@INC, '/cgi-bin'); require ('cgi-lib.pl'); #============================================================================ # grab values passed in #============================================================================ &ReadParse(*in); # make the variables a little easier to read... $current_issue = $in{'iname'}; $command = $in{'cmd'}; $this_file = $in{'this'}; # # Simple cases first - if we have Rant, Archive, or Staff, then # just hand back the appropriate file... if ($command eq "Rant") { $location = "../rant/rantrant.shtml"; } elsif ($command eq "Arch") { $location = "../Archives.shtml"; } elsif ($command eq "Us") { $location = "../staff/Masthead.shtml"; } elsif ($command eq "TOC") { $location = "../".$current_issue."/TOC.html"; } else { # # Now, we either have next or previous. We'll need to open the # issue_list file of the issue we're in, and scan it for the # current filename. When we find it, either take the previous # one, or the next one... # $issue_list_file = "../".$current_issue."/issue_list"; #print "Issue list is[", $issue_list_file, "]\n"; if (open(ILIST_FILE, $issue_list_file)) { $last_filename = ""; # save the last filename seen here $first_filename = ""; # save the first file here $in_loop = 1; while (chop($current_filename = ) && ($in_loop == 1)) { # Save the name of the first file, in case we have to # go "next" on the last file... if ($first_filename eq "") { $first_filename = $current_filename; } # Now, if this one matches what we have, then we need # to do some checking. If this file is the one we # currently "have", then we need to apply the # command to it... #print "Current[", $current_filename, "], and this[", $this_file, "]\n"; if ($current_filename eq $this_file) { if ($command eq "Next") { #print "Next! ", eof(), "\n\n"; # If this is the end of the issue_list file, then # what we really want is the first file (wrap # around). Otherwise, read the next one in. if (eof() == 1) { $location = "../".$current_issue."/".$first_filename; } else { $tempbuf = ; $location = "../".$current_issue."/".$tempbuf; } } elsif ($command eq "Prev") { # If we are at the first file (i.e., $last_filename # hasn't yet been set), then we will cheat, since # we know that the backpage is the last one... if ($last_filename eq "") { $location = "../".$current_issue."/backpage.shtml"; } else { $location = "../".$current_issue."/".$last_filename; } } # end elsif $in_loop = 0; } # end if we found a matching filename # Save this as the new 'previous' file $last_filename = $current_filename; } wend; # get it - the end of the while loop close(ILIST_FILE); } else { # # Error! Let's default to the TOC... # $location = "../".$current_issue."/TOC.html"; # # We should also write out an error somehow... # #print "ERROR!!!", "\n\n"; } } # end else we have prev or next.. # # Now that we have a location, print that bad boy... print "Location: ", $location, "\n\n"; exit;