#!/usr/bin/perl
# mvl.cgi - file filtering script that parses HTML  - dev
# files (dadabase documents) and inserts hidden fields and appends forms.
# written by Gerry Smith <sfguu4658@agt.net>

require 'FormData.pl';
require 'MailForm.pl';
require 'user.pl';   # members only comments
require 'lev1.pl';   # members only comments


$filelist    = "doclist.txt";
$passwd_file = "ul.txt";

$sitetitle   = "Global Dialog";

$homelink        = "http://www.global-dialog.org/";
$homelinkstring  = "Global Dialog Home";

$mvdhomelink     = "http://www.global-dialog.org/mvd/";   # must end with /
$mvdhomelinkstring = "MVD Home ";

$listlink        = "mvl.cgi?NextName=List";
$listlinkstring  = "List";

$bgcolor     = "#99CCCC";
$background  = "../graphics/web3.jpg";
$commentbackground = "../graphics/web3.jpg";

$mailprog    = '/usr/sbin/sendmail';
$owner       = 'valor@global-dialog.org';
$sysop       = 'PeopleComments@global-dialog.org';
$backup      = 'MVDSAVES@global-dialog.org';
$Script      = $ENV{'SCRIPT_NAME'};

$date_command = '/bin/date';

open(FILE,$filelist) || die("$0: couldn't open $filelist for
reading($!)\n");  @array = <FILE>;
close(FILE);

foreach $line (@array){
chop($line);
($key,$value) = split(',',$line);
$Files2Names{$key} = $value;
}


$nextcomment = 0;
$doneonce = 0;
$addedcom = 0;
$commetsadded = 0;
$Tot = 0;
$FileNum = 0;
foreach (sort(keys(%Files2Names))) {
 $ValidFiles[ $FileNum ] = $_;
 $ValidNames[ $FileNum ] = $NextName = $Files2Names{$_};
 $Names2Numbs{$NextName} = $FileNum++; # Used to validate names.
 $Tot++;
}

unless ($Script) {              # Must be testing in the shell...
 $ENV{'SCRIPT_NAME'}    = $0;
 $ENV{'REQUEST_METHOD'} = 'GET';
 $ENV{'QUERY_STRING'}   = 'NextName=0';
 $ENV{'CONTENT_LENGTH'} = length($ENV{'QUERY_STRING'});
}

if (&getFormData(*Form) && ($NextName = $Form{'NextName'})) {
 $NextName  =  &Addcomment(*Form) if ($NextName eq 'Submit');
 $NextName  =  &Prevuecomment(*Form) if ($NextName eq 'Prevue');
 $NextName  =  &Addinput(*Form) if ($NextName eq 'Input');
 $NextName  =  &Preview(*Form) if ($NextName eq 'Preview');
 $NextName  =  &ListAll(*Form) if ($NextName eq "List");
 $NextName  =  $Form{'ThisFile'} if ($NextName eq "Update");
 $NextName  =  $Files2Names{$NextName} if ($NextName =~ /\.s*html*$/);
 #   Now simultaneously get $NextName's number and validate it:
 $FileNum   =  $Names2Numbs{$NextName} || 0;

}
else {
 $FileNum   = 0;
}

&sendParsedFile( *Form, $FileNum );
exit;

############### Local Subroutines: ###########################

sub  sendParsedFile {
 local ( *Form, $FileNum ) = @_;
 my    ( $line, $File, $NextName, $PrevName );
 $insdir = 0;
 $canshoaddc = 0;

 $File   = $ValidFiles[ $FileNum ];

 $ThisFile = $ValidFiles[ $FileNum];
 $FileN = $FileNum + 1;
 if($FileN >= $Tot){ $FileN = 0;}
 $NextName = $ValidFiles[$FileN];
 $FileB = $FileNum-1;
 if($FileB <  0 ) { $FileB = $Tot-1;}
 $PrevName = $ValidFiles[$FileB];

 open(File, $File) || die("$0: sendParsedFile died on $File ($!)\n");
 while ($lin = <File> ) {
    if ( $lin =~ /<!--commentsadded-->/i ) {
      $commentsadded = 1;
      break;
      #$doneonce = 1;
    }
    elsif ( $lin =~ /<!--NoCommentForm-->/i ) {
      $Form{'noaddc'} = 1;
    }
 }
 close (File);

 print "Content-type: text/html\n\n";
 open(File, $File) || die("$0: sendParsedFile died on $File ($!)\n");
 while ($line = <File>) {

   if ( $line =~ /<!--Description-->/i ) {
     print "<!--Description-->";
        if( $commentsadded eq 1 ) {
          print "\n<!--commentsadded-->";
        }
     print "\n<center><a name=top><hr><font size=-1>";
       if($Form{'shonav'}){
          print "<a href=\"mvl.cgi?ThisFile=$ThisFile&shonav=1&NextName=$NextName\"> [ Next ] </a>&nbsp\;&nbsp\;";
          print "<a href=\"mvl.cgi?ThisFile=$ThisFile&shonav=1&NextName=$PrevName\"> [ Back ] </a>&nbsp\;&nbsp\;";
          print "<a href=\"mvl.cgi?ThisFile=$ThisFile&shonav=1&NextName=List\"> [ List ] </a>&nbsp\;&nbsp\;";
       }
       if( $commentsadded eq 1 ) {
           print "<a href=#additions> [ Goto Comments ] </a>&nbsp\;&nbsp\;";
       }
       if(!$Form{'noaddc'}){
           print "<a href=#Comment> [ Add Comment ] </a>&nbsp\;&nbsp\;";
       }
     print "<a href=\"searchmvl.cgi\"> [ Search ]</a>&nbsp\;&nbsp\;<a href=$homelink> [ $homelinkstring ]
</a></font></center><hr><p>";
   }
   elsif ( $line =~ /<!--EndDescription-->/i ) {
     $canshoaddc = 1;
     print $line;
   }
   elsif ( $line =~ /Participant Comments follow below/i ) {
     $addedcom = 1;
     print $line;
   }
   elsif ( $line =~ /\*\</i ) {
     $line =~ s/\*\</\*\&lt\;/g;
     print $line;
   }
   elsif ( $line =~ /^<!--insert\s+(\w+)\s*-->/i) {
     if ($1 eq 'Next') {
       $insdir = 1;
       &insertNames(*Form, $FileNum);
     }
   }
   elsif ( $line =~ /(.*)<\/body>(.*)/i && !$insdir ) {
     &insertNames(*Form, $FileNum, $1, $2, 1);
   }
   else { print $line; }
 }
 close (File);
}

sub Addcomment {
 local (*Form) = @_;
 my    ($line, $File, $message);


if (&CheckUser($Form{'uname'},$Form{'pword'},0)){  # members only comments

# Get the Date for timestamp on comment entry
$date = `$date_command +"%A, %B %d, %Y at %T (%Z)"`; chop($date);
$shortdate = `$date_command +"%D %T %Z"`; chop($shortdate);

 $File   = $Form{'ThisFile'};

 $Form{'add'} =~ s/~!/ ~!/g;
 $Form{'add'} =~ s/<!--(.|\n)*-->//g;

 $Form{'add'} =~ s/(http:\/\/\S+)(\s|$)/<a href=$1>$1\040<\/a>/g;

 $Form{'addname'} =~ s/~!/ ~!/g;
 $Form{'addname'} =~ s/<!--(.|\n)*-->//g;
 $Form{'addemail'} =~ s/~!/ ~!/g;
 $Form{'addemail'} =~ s/<!--(.|\n)*-->//g;

 $Form{'mailto'} =~ s/~!/ ~!/g;
 $Form{'mailto'} =~ s/<!--(.|\n)*-->//g;

 $add = $Form{'add'};

 $Form{'add'} =~ s/\n/\n<br>/g;

 $message = $Form{'addname'} . " added the following to this page: " . $Form{'ThisFile'} . "\n\n" . $Form{'add'};

 open(FILE, $File) || die("$0: Addcomment couldn't open $File for reading($!)\n");
 @lines = <FILE>;
 close(FILE);

 &mailForm($backup, $backup, "[MVD back-up] ".$Files2Names{$File}." : ".$date, "$ENV{'HTTP_REFERER'}\n\n@lines\n");

 &mailForm($owner, $owner, "[MVD back-up] ".$Files2Names{$File}." : ".$date, "$ENV{'HTTP_REFERER'}\n\n@lines\n");

 open(FILE, ">$File") || die("$0: Addcomment couldn't open $File for writing($!)\n");
 flock(FILE, 2);

 foreach $line (@lines) {

   if ( $line =~ /<!--Description-->/i && $Form{'addedcom'} ne 1) {
     print FILE "<!--Description-->\n<!--commentsadded-->\n";
   }
   elsif ( $line =~ /<a name=additions>/i) {

     $nextcomment=1;
     print FILE "<a name=additions><hr><center><font size=+1><b><i>Participant Comments follow below</i></b></font></center>\n";

     print FILE "\n<center><table border=4 cellpadding=5 width=87% background=$commentbackground>\n<td><font
color=black>$Form{'add'}</font>\n";
     if($Form{'addname'}){
       if ($Form{'addemail'}) {
         print FILE "\n<p><a href=mailto:$Form{'addemail'}>$Form{'addname'}</a>\n";
       }
       else{
         print FILE "\n<p><font color=green>$Form{'addname'}</font>";
       }
     }
     print FILE "<br><font size=1>$shortdate</font></td></table></center>\n";
    }
   elsif ( $line =~ /<!--EndDescription-->/i && $nextcomment ne 1) {

     if ($Form{'addedcom'} ne 1) {
       print FILE "<a name=additions><hr><center><font size=+1><b><i>Participant Comments follow
below</i></b></font></center>\n";
     }
     print FILE "\n<center><table border=4 cellpadding=5 width=87% background=$commentbackground>\n<td><font
color=black>$Form{'add'}</font>\n";
       if($Form{'addname'}){
       print FILE "\n<br><small><font color=green>$Form{'addname'}</font></small>";
       if ($Form{'addemail'}) {
         print FILE "&nbsp\;&nbsp\;&nbsp\;<a href=mailto:$Form{'addemail'}><small> $Form{'addemail'}</a></small>\n";
       }
     }
     print FILE "<br><font size=1>$shortdate</font></td></table></center>\n<p><\!--EndDescription-->\n";
    }
    else {
       print FILE $line;
   }
 }

   flock(FILE, 8);
   close (FILE);
   &mailForm($owner, $owner, "[ MVD Comment ] ".$Files2Names{$File}." : ".$shortdate, "$ENV{'HTTP_REFERER'}\n\n$message\n");
   &mailForm($sysop, $sysop, "[ MVD Comment ] ".$Files2Names{$File}." : ".$shortdate, "$ENV{'HTTP_REFERER'}\n\n$message\n");

 if ($Form{'mailto'} ne "" ) {

$commentpage = $mvdhomelink."mvl.cgi?NextName=".$Files2Names{$File};

   if ( $Form{'addname'} eq "" ) {
     $Form{'addname'} = "anonymous";
   }
   if ( $Form{'addemail'} eq "" ) {
     $Form{'addemail'} = "no email address supplied";
   }

   $message = $Form{'addname'}." ( ".$Form{'addemail'}." ) has requested that the submission he or she posted to the
global-dialog.org site be emailed to you. Do not reply to this email. The submission was made to this page: $commentpage\n\nThe
submission follows immediately below:\n\n".$add;
   &mailForm($Form{'mailto'}, $Form{'mailto'}, "[ MVD Comment Mail-To ]", "\n$message\n\n\n");
 }

   $NextName  =  $Files2Names{$File};
   $FileNum   =  $Names2Numbs{$NextName};

   &sendParsedFile( *Form, $FileNum );
   exit;

}                                                                       # members only comments
else {                                                                  # members only comments
 &BadCombo("registered member with priviledges to add comments");      # members only comments
 exit;}                                                                # members only comments

}

sub Prevuecomment {
 local (*Form) = @_;
 my    ($line, $File, $message);


# Get the Date for timestamp on comment entry
$date = `$date_command +"%A, %B %d, %Y at %T (%Z)"`; chop($date);
$shortdate = `$date_command +"%D %T %Z"`; chop($shortdate);

 $File   = $Form{'ThisFile'};

 $Form{'add'} =~ s/~!/ ~!/g;
 $Form{'add'} =~ s/<!--(.|\n)*-->//g;

 $Form{'add'} =~ s/(http:\/\/\S+)(\s|$)/<a href=$1>$1\040<\/a>/g;

 $Form{'addname'} =~ s/~!/ ~!/g;
 $Form{'addname'} =~ s/<!--(.|\n)*-->//g;
 $Form{'addemail'} =~ s/~!/ ~!/g;
 $Form{'addemail'} =~ s/<!--(.|\n)*-->//g;

 $Form{'mailto'} =~ s/~!/ ~!/g;
 $Form{'mailto'} =~ s/<!--(.|\n)*-->//g;

 $add = $Form{'add'};

 $Form{'add'} =~ s/\n/\n<br>/g;

 print "Content-type: text/html\n\n";

 print "<HTML><HEAD><TITLE>Comment Prevue</TITLE></HEAD><BODY BGCOLOR=$bgcolor background=$background>";

 print "<a name=additions><hr><center><font size=+1><i><b>My Comments</b></i></font></center><p>\n";

 print "\n<center><table border=4 cellpadding=5 width=87% background=$commentbackground>\n<td>";
 print "<font color=black>$Form{'add'}</font>\n";
 if($Form{'addname'}){
   if ($Form{'addemail'}) {
     print "\n<p><a href=mailto:$Form{'addemail'}>$Form{'addname'}</a>\n";
   }
   else{
     print "\n<p><font color=green>$Form{'addname'}</font>";
   }
 }
 print "<br><font size=1>$shortdate</font></td></table></center><p><hr>\n</body></html>";

 exit;
}

sub Preview {
 local (*Form) = @_;
 my    ($line, $File, $message);

# Get the Date for timestamp on comment entry
$date = `$date_command +"%A, %B %d, %Y at %T (%Z)"`; chop($date);
$shortdate = `$date_command +"%D %T %Z"`; chop($shortdate);

 $File  = $Form{'AddFile'};

 $Form{'URL'} =~ s/~!/ ~!/g;
 $Form{'URL'} =~ s/<!--(.|\n)*-->//g;
 $Form{'URL'} =~ s/http:\/\///g;

 if($Form{'URL'} ne '') {
   $Form{'URL'} = "http://" . $Form{'URL'};
 }

 $Form{'URLTitle'} =~ s/~!/ ~!/g;
 $Form{'URLTitle'} =~ s/<!--(.|\n)*-->//g;

 $Form{'blurb'} =~ s/~!/ ~!/g;
 $Form{'blurb'} =~ s/<!--(.|\n)*-->//g;

 $Form{'blurb'} =~ s/(http:\/\/\S+)(\s|$)/<a href=$1>$1\040<\/a>/g;

 $Form{'inputcomment'} =~ s/~!/ ~!/g;
 $Form{'inputcomment'} =~ s/<!--(.|\n)*-->//g;

 $Form{'inputcomment'} =~ s/(http:\/\/\S+)(\s|$)/<a href=$1>$1\040<\/a>/g;

 $Form{'inputname'} =~ s/~!/ ~!/g;
 $Form{'inputname'} =~ s/<!--(.|\n)*-->//g;

 $Form{'inputemail'} =~ s/~!/ ~!/g;
 $Form{'inputemail'} =~ s/<!--(.|\n)*-->//g;

 $Form{'mailto'} =~ s/~!/ ~!/g;
 $Form{'mailto'} =~ s/<!--(.|\n)*-->//g;

 $add = $Form{'URLTitle'} . "\n" . $Form{'URL'} . "\n\n" . $Form{'blurb'} . "\n\n" . $Form{'inputcomment'};

 $Form{'blurb'} =~ s/\n/\n<br>/g;
 $Form{'inputcomment'} =~ s/\n/\n<br>/g;

 $message = $Form{'inputname'} . " added the following to this page: " . $Form{'ThisFile'} . "\n\n" . $add;

 print "Content-type: text/html\n\n";
 open(File, $File) || die("$0: Preview died on $File ($!)\n");
 while ($line = <File>) {
   print $line;
 }

 print "<center>My personal comments follow below<p><hr width=80%>\n";
 print "\n<center><table width=75%>\n<td>\n";

       if($Form{'URL'}){
         if($Form{'URLTitle'}){
           print "<a href=$Form{'URL'}><b>$Form{'URLTitle'}</b></a><br>\n";
         }
         else {
           print "<a href=$Form{'URL'}><b>$Form{'URL'}</b></a><br>\n";
         }
       }

       if($Form{'blurb'}){
         print "$Form{'blurb'}<p>\n";
       }
       if($Form{'inputcomment'}){
         print "$Form{'inputcomment'}<p>\n";
       }

       if($Form{'inputname'})
       {
         if ($Form{'inputemail'})
         {
           print "<a href=mailto:$Form{'inputemail'}><b>$Form{'inputname'}</b></a>\n";
         }
         else
         {
            print "\n<b><font color=green>$Form{'inputname'}</font></b>";
         }
       }
       print "<br><font size=1>$shortdate</font></td></table><hr width=80%></center><br><br><br>\n";

 print "</body></html>";

 exit;
}

sub Addinput {
 local (*Form) = @_;
 my    ($line, $File, $AddFile, $TestFile, $message);


# Get the Date for timestamp on comment entry
$date = `$date_command +"%A, %B %d, %Y at %T (%Z)"`; chop($date);
$shortdate = `$date_command +"%D %T %Z"`; chop($shortdate);

 $File   = $Form{'ThisFile'};
 $AddFile  = $Form{'AddFile'};

 $Form{'URL'} =~ s/~!/ ~!/g;
 $Form{'URL'} =~ s/<!--(.|\n)*-->//g;
 $Form{'URL'} =~ s/http:\/\///g;

 if($Form{'URL'} ne '') {
   $Form{'URL'} = "http://" . $Form{'URL'};
 }

 $Form{'URLTitle'} =~ s/~!/ ~!/g;
 $Form{'URLTitle'} =~ s/<!--(.|\n)*-->//g;

 $Form{'blurb'} =~ s/~!/ ~!/g;
 $Form{'blurb'} =~ s/<!--(.|\n)*-->//g;

 $Form{'blurb'} =~ s/(http:\/\/\S+)(\s|$)/<a href=$1>$1\040<\/a>/g;

 $Form{'inputcomment'} =~ s/~!/ ~!/g;
 $Form{'inputcomment'} =~ s/<!--(.|\n)*-->//g;

 $Form{'inputcomment'} =~ s/(http:\/\/\S+)(\s|$)/<a href=$1>$1\040<\/a>/g;

 $Form{'inputname'} =~ s/~!/ ~!/g;
 $Form{'inputname'} =~ s/<!--(.|\n)*-->//g;

 $Form{'inputemail'} =~ s/~!/ ~!/g;
 $Form{'inputemail'} =~ s/<!--(.|\n)*-->//g;

 $Form{'mailto'} =~ s/~!/ ~!/g;
 $Form{'mailto'} =~ s/<!--(.|\n)*-->//g;

 $add = $Form{'URLTitle'} . "\n" . $Form{'URL'} . "\n\n" . $Form{'blurb'} . "\n\n" . $Form{'inputcomment'};

 $Form{'blurb'} =~ s/\n/\n<br>/g;
 $Form{'inputcomment'} =~ s/\n/\n<br>/g;

 $message = $Form{'inputname'} . " added the following to this page: " . $Form{'ThisFile'} . "\n\n" . $add;

 open(FILE, $File) || die("$0: Addinput couldn't open $File for reading($!)\n");
 @lines = <FILE>;
 close(FILE);

 &mailForm($backup, $backup, "[MVD back-up] ".$Files2Names{$File}." : ".$date, "$ENV{'HTTP_REFERER'}\n\n@lines\n");

 &mailForm($owner, $owner, "[MVD back-up] ".$Files2Names{$File}." : ".$date, "$ENV{'HTTP_REFERER'}\n\n@lines\n");

 open(FILE, ">$File") || die("$0: Addinput couldn't open $File for writing($!)\n");
 flock(FILE, 2);

 foreach $line (@lines) {

   if ( $line =~ /<a name=$Form{'inputnum'}>/i) {

#      $nextcomment=1;
     print FILE "<a name=$Form{'inputnum'}>\n";

     print FILE "\n<center><table width=81% background=$commentbackground>\n<td>\n";

       if($Form{'URL'}){
         if($Form{'URLTitle'}){
           print FILE "<a href=$Form{'URL'}><b>$Form{'URLTitle'}</b></a><br>\n";
         }
         else {
           print FILE "<a href=$Form{'URL'}><b>$Form{'URL'}</b></a><br>\n";
         }
       }

       if($Form{'blurb'}){
         print FILE "$Form{'blurb'}<p>\n";
       }
       if($Form{'inputcomment'}){
         print FILE "$Form{'inputcomment'}<p>\n";
       }


       if($Form{'inputname'})
       {
         if ($Form{'inputemail'})
         {
           print FILE "<a href=mailto:$Form{'inputemail'}><b>$Form{'inputname'}</b></a>\n";
         }
         else
         {
            print FILE "\n<b><font color=green>$Form{'inputname'}</font></b>";
         }
       }
       print FILE "<br><font size=1>$shortdate</font></td></table><hr width=85%></center>\n";
    }
    else {
       print FILE $line;
    }
 }

   flock(FILE, 8);
   close (FILE);
   &mailForm($owner, $owner, "[ MVD Input ] ".$Files2Names{$File}." : ".$shortdate, "$ENV{'HTTP_REFERER'}\n\n$message\n");
   &mailForm($sysop, $sysop, "[ MVD Input ] ".$Files2Names{$File}." : ".$shortdate, "$ENV{'HTTP_REFERER'}\n\n$message\n");

 if ($Form{'mailto'} ne "" ) {

$commentpage = $mvdhomelink."mvl.cgi?NextName=".$Files2Names{$File};

   if ( $Form{'inputname'} eq "" ) {
     $Form{'inputname'} = "anonymous";
   }
   if ( $Form{'inputemail'} eq "" ) {
     $Form{'inputemail'} = "no email address supplied";
   }

   if($AddFile ne '')
   {
        $add = '';
        open(FILE, $AddFile) || die("$0: Addinput couldn't open $AddFile for reading($!)\n");
        @lines = <FILE>;
        foreach $line (@lines)
        {
            $add .= $line;
        }
        close(FILE);
        $add .= "<center>My personal comments follow below<p><hr width=80%></center>\n";
        $add .= "\n<center><table width=75%>\n<td>\n";

        if($Form{'URL'}){
          if($Form{'URLTitle'}){
            $add .= "<a href=$Form{'URL'}><b>$Form{'URLTitle'}</b></a><br>\n";
          }
          else {
            $add .= "<a href=$Form{'URL'}><b>$Form{'URL'}</b></a><br>\n";
          }
        }

        if($Form{'blurb'}){
          $add .= "$Form{'blurb'}<p>\n";
        }
        if($Form{'inputcomment'}){
          $add .= "$Form{'inputcomment'}<p>\n";
        }

        if($Form{'inputname'}){
          $add .= "\n<b><font color=green>$Form{'inputname'}</font></b>";
          if ($Form{'inputemail'}) {
          $add .= "&nbsp\;&nbsp\;&nbsp\;<a href=mailto:$Form{'inputemail'}><small> $Form{'inputemail'}</a></small>\n";
          }
        }
        $add .= "<br><font size=1>$shortdate</font></td></table><hr width=80%></center><br><br><br>\n";
        $add .= "</body></html>";

        #&mailForm($Form{'mailto'}, $Form{'mailto'}, "[ Global-Dialog Mail ]", $add, 1);
         &htmlmailForm($Form{'mailto'}, $Form{'mailto'}, "[ Global-Dialog Mail ]", $add);
        #$TestFile = "testmail.html";
        #open(FILE, ">$TestFile") || die("$0: Addinput couldn't open $File for writing($!)\n");
        #flock(FILE, 2);
        #print FILE $add;
        #flock(FILE, 8);
        #close (FILE);
   }
   else
   {
        $message = $Form{'inputname'}." ( ".$Form{'inputemail'}." ) has requested that the submission he or she posted to the
global-dialog.org site be emailed to you. Do not reply to this email. The submission was made to this page: $commentpage\n\nThe
submission follows immediately below:\n\n".$add;
        &mailForm($Form{'mailto'}, $Form{'mailto'}, "[ MVD Input Mail-To ]", "\n$message\n\n\n");
    }
 }

   $NextName  =  $Files2Names{$File};
   $FileNum   =  $Names2Numbs{$NextName};

   &sendParsedFile( *Form, $FileNum );
   exit;
}

sub ListAll {
 local ( *Form ) = @_;

 print <<EOF;
Content-type: text/html

<HTML>
<HEAD><TITLE> $sitetitle MVD Document List </TITLE></HEAD>
<BODY BGCOLOR=$bgcolor background=$background>
<FORM METHOD=POST ACTION=$Script><CENTER>
<p><hr size=2><p>
<H1>Mariposa's Variorum Dadabase: $sitetitle </H1>
<H3>Alphabetical list of all documents</h3>
Click on the name to open<p><hr size=2></CENTER><p>
EOF

 $FileNumb = $FileNum;
 print "<center>There are currently $FileNumb documents.<p>\n";
 print "<table border=2 cellpadding=5 bgcolor=#99CCCC>\n";
 print "<tr valign=middle><td align=center valign=middle>Title</td></tr>\n";
 $c1=1;
for($c=0;$c<$FileNumb;$c++){
 print "<tr valign=middle><td valign=middle>$c1: <A HREF=\"$Script\?shonav=1&NextName=$ValidFiles[$c]\">
$ValidNames[$c]</A></td></tr>\n";
 $c1++;
}
print "</table></center></form><p><hr>\n";

print <<EOF;
<p>
<center>
<table width=700 cellpadding=0 border=0><td>
<FORM METHOD=POST ACTION="searchmvl.cgi">
<center>
<H3>Search MVD</H3>
<INPUT TYPE=TEXT SIZE=55 MAXLENGTH=255 NAME="Query" VALUE="$Query"><br>
Regular Expressions:&nbsp;
<INPUT TYPE=CHECKBOX NAME=RegExp    VALUE=CHECKED $RegExp>&nbsp;&nbsp;
Match Case:
<INPUT TYPE=CHECKBOX NAME=MatchCase VALUE=CHECKED $MatchCase><br>
<INPUT TYPE=SUBMIT  VALUE=Submit>
<INPUT TYPE=RESET   VALUE=Reset><BR>
</FORM>
<BR><a href="regex.html"><font size=-1><i>How to use regular expressions.</i></font></a><p>
</center>
</td></table>
<p><hr>
</center>
EOF

 print "<center><a href=$homelink target=_top> [ $homelinkstring ] </a>&nbsp\;&nbsp\;<a href=$mvdhomelink> [ $mvdhomelinkstring
] </a>\n";
 print "</center><hr><p></BODY></HTML>\n";
 exit;
}

sub  insertNames {
 local ( *Form, $FileNum, $textb4bod, $textaftbod, $notmvdfile ) = @_;
 my    ( $ThisFile, $NextName, $PrevName,$sho );

 $sho = 0;

 #ThisFile = $ValidFiles[ $FileNum ];
 #NextName = $ValidNames[($FileNum + 1) % $#ValidFiles];
 #PrevName = $ValidNames[($FileNum - 1) % $#ValidFiles];

 $ThisFile = $ValidFiles[ $FileNum];
 $FileN = $FileNum + 1;
 if($FileN >= $Tot){ $FileN = 0;}
 $NextName = $ValidNames[$FileN];
 $FileB = $FileNum-1;
 if($FileB <  0 ) { $FileB = $Tot-1;}
 $PrevName = $ValidNames[$FileB];

 if($notmvdfile && $textb4bod){
   print "$textb4bod<br>\n";
 }

 if( $addedcom eq 1 ) {
   print "<center><font size=-1>Any added comments do not necessarily reflect the views of the editors or other writers at this

site.</font></center>";
 }

 if($Form{'shonav'}){
   print "<a name=Nav><hr><p><font size=-1><FORM METHOD=POST ACTION=\"mvl.cgi\">\n";
   print "<center><INPUT TYPE=HIDDEN NAME=ThisFile VALUE=\"$ThisFile\">\n<INPUT TYPE=HIDDEN NAME=shonav VALUE=1>\n",
   "<table border=0><td><INPUT TYPE=SUBMIT NAME=NextName VALUE=\"List\"></td>\n",
   "<td>Next: <INPUT TYPE=SUBMIT NAME=NextName VALUE=\"$NextName\"><p>\n",
   "Back: <INPUT TYPE=SUBMIT NAME=NextName VALUE=\"$PrevName\">\n";
   print "</td></table><\/FORM></font></center>\n<p>";
   $sho = 1;
 }

if(!$Form{'noaddc'} && $canshoaddc){
print <<EOF;
<a name=Comment><hr><p>
<center><Font size=+2>Add your own comments.</font><br>
See guidelines below.
<font size=-1>
<Form METHOD=POST ACTION="mvl.cgi">
<br><TEXTAREA NAME='add' ROWS=8 COLS=70 WRAP></TEXTAREA><p>
 <INPUT TYPE=HIDDEN NAME=ThisFile VALUE='$ThisFile'>
 <INPUT TYPE=HIDDEN NAME=shonav VALUE='$Form{'shonav'}'>
 <INPUT TYPE=HIDDEN NAME=addedcom VALUE='$addedcom'>
 Name  : <INPUT TYPE=TEXT NAME='addname' size=40><br>
 Email : <INPUT TYPE=TEXT NAME='addemail' size=40><p>
Member Username: <INPUT TYPE=TEXT SIZE=23 NAME="uname"><br>
Member Password: <INPUT TYPE=password SIZE=23 NAME="pword"><p>
<font color=red><b>*</b></font>Mail-To : <INPUT TYPE=TEXT NAME='mailto' size=40><p>
 <INPUT TYPE=SUBMIT NAME=NextName VALUE=Submit> <INPUT TYPE=RESET VALUE=Reset> <INPUT TYPE=SUBMIT NAME=NextName
VALUE=Prevue></form></font><p><table
width=700><td><small><center><b>Entry Guidelines</b></center>
<p>
This form is to allow you to add any comments which are relevant to the current topic.
A Comment submitted with this form will be immediately appended to the document you see above.
It will be inserted just underneath the main document text and will be put into its own table
separated from the document text and other comments in their own tables. Comments are stacked
with the most recent appearing nearer the top of the page.
<p>
Your name will be included if you fill out that field and if you supply an email address
it will *not* be displayed but your name will become a "mailto" link, which others can
click on to send you email. Suppling your name and email address is optional but it is
nice to let others know who is the one submitting these comments.
<p>
Please use the *Prevue* button to check your submission and check for typos and broken
links before you submit it. Use your browsers *Back* button to return to the input
form. URLs of the form http://examplesite ( e.g. http://www.global-dialog.org ) will
be automatically turned into clickable links so you don't have to add the HTML tags for
that yourself but you can use other HTML tags to make your comments more colorful or unique
if you choose.
<p>
Input an email address into the *Mail-To* field to have the comment you are submitting
emailed to you or to any other address you specify. Please fill out the *Name* and *Email*
fields so they can be sent along with your submission to let the recipient know who is
sending this to them.  Please use this feature with respect.
<p>
Flames and any other kinds of disrespectful or frivolous entries will be deleted.
<b>Thank you for your particpation.</b>
<p></small></td></table><p></center>
EOF
}

print <<END;
<center><p><hr>
<a href=#top> [ Goto Top ] </a>&nbsp\;&nbsp\;
<a href=$homelink target=_top>[ $homelinkstring ]</a></center><hr><p>
END

 if($notmvdfile){
   print "</body>$textaftbod<br>\n";
 }
}
