#!/usr/local/bin/perl

# This is hacked about from the script by Lincoln Stein at
# http://stein.cshl.org/WWW/software/CGI/examples/monty.txt
     
use CGI qw(all);
use CGI::Carp qw/fatalsToBrowser/;

use strict; # provides for STRICT syntax checking
no strict "subs";

 
sub print_prompt {
   my($query) = @_;
 
   print $query->start_form;
   print "<EM>What's your name?</EM><BR>";
   print $query->textfield('name');
    
   
   print "<P><EM>What's your e-mail address?</EM><BR>";
   print $query->textfield('email');
 
   print "<P><EM>Do you want a box number</EM><BR>",
   $query->radio_group(
                       -name=>'box',
                       -Values=>['yes','no'],
                       -default=>'yes');   
   
   print "<P><EM>What category should your ad go into?</EM>  ";
   print $query->popup_menu(-name=>'Category',
                            -Values=>['Contacts','Services Offered','Moots','Services Wanted'],
                            -default=>'Contacts');

   print "<P><EM>Where are you?</EM>  ";
   print $query->popup_menu(-name=>'Country',
                            -Values=>['England','Scotland','Wales','Northern Ireland', 'Republic of Ireland', 'Channel Islands', 'Other Europe', 'Other'],
                            -default=>'England');

# Note: If 'Other' is selected, the ad should be rejected as this is a European
# Sevice. If 'Other Europe' is selected, we need to ask where.

   print "<P><EM>Ad headline?</EM><BR>";
   print $query->textfield('headline');

   print "<P><EM>Ad Text</EM><BR>";
   print $query->textarea(-name=>'body',
                          -rows=>10,
                          -columns=>50);
   
   print "<P>",$query->reset;
   print $query->submit('Action','Submit');
   print $query->endform;
   print "<HR>\n";
        }
 
sub do_work {
    my($query) = @_;
    my(@values,$key);

    print "<H2>Here are the current settings in this form</H2>";

    foreach $key ($query->param) {
        print "<STRONG>$key</STRONG> -> ";
        @values = $query->param($key);
        print join(", ",@values),"<BR>\n";
    }
}
 
sub print_tail {
    print <<END;
<HR>
<p>Hacked from something by:<br>
<ADDRESS>Lincoln D. Stein</ADDRESS><BR>
</p>
END
    ;
}

# main program begins here

my $query = new CGI; # always introduce new variables with "my"

print $query->header;
print $query->start_html(-title=>'Advertise with Us!',
     -meta=>{'keywords'=>'pagan classified contact'},
     -head=> <<END_OF_HEADER,
<link href="http://www.paganlink.org/paganlink.css" rel="stylesheet" type="text/css" title="Paganlink Style Sheet">

<link href="../help.html" rel="help">
<link href="../culprits.html" rel="author">
END_OF_HEADER

-lang=>'en-GB');

# open the file containing the top table (chrome!)
open(TOP_BIT,"top_table.html");

# add error checking later

# reads each line in in turn, printing it. if line exists is true. When line
# runs out, is false, so exits while.
while(<TOP_BIT>) {
    print $_;
}
close TOP_BIT;

print_prompt($query);
do_work($query);
print_tail;
print $query->end_html;
exit;

