#!/usr/local/bin/perl
# rotator.pl
# Author:  Ian Graham
#          Information Commons, University of Toronto
#          <igraham@hprc.utoronto.ca>
# Version: 0.1b.    Date:    July 13 1995

$include_path="/svc/www/InsTest";           # Directory containing include files
print "Content-type: text/html\n\n";        # print content-type header

# Get listing for the directory that contains the inserts:
if( !opendir(DIR, $include_path)) {
    &f_error("Unable to open notices directory\n", __LINE__, __FILE__); }
@tmp = readdir(DIR);
foreach (@tmp) {
   push(@filenames, $include_path."/".$_) if -T $include_path."/".$_;
}
close(DIR);

$last_index = $#filenames;   # Get index of last entry in filenames array
$last_index += 1;
if($last_index < 0) { 
   print " no files to insert ....\n"; die; # no stuff, so don't do nuthin'
}
else {
   srand(time);              # Randomly select insertion: print it to stdout.
   $rand_index = int(rand($last_index));
   open(TEMP, $filenames[$rand_index]) ||
      &f_error("Unable to open insertion file.\n", __LINE__,__FILE__);
   @insertion = <TEMP>;
   print @insertion;
}      # --------------- FINISHED --------------

# Error Handling Subroutine

sub f_error {           
  print "Content-type text/html\n\n";
  print "Fatal error  at line $_[1] in file $_[2].\n";
  print "Please send mail to: <BR>\n";
  print "<A HREF=\"mailto:webmaster@commons.utoronto.ca\">webmaster@commons.utoronto.ca</A><BR>\n";
  print "to inform us of this error. If you can please, quote the URL\n";
  print "of the page that gave this error.\n<HR>\n";
   die "Fatal Error: $_[0] at line $_[1] in file $_[2] \n";
}

