#!/usr/local/bin/perl 
# review - allow vistors to review, and view reviews of, bob ostertag's albums
# steev hise, steev@cyboganic.com, june 97

$| = 1;
open(STDERR, ">&STDOUT");
use CGI;
$self = "review";
$mailprog = "/usr/sbin/sendmail";
@cd = ('Like a Melody',
	'Twins!',
	'Verbatim',
	'Fear No Love',
	'Say No More',
	'Say No More in Person',
	'All the Rage',
	'Burns Like Fire',
	'Sooner or Later',
	'Attention Span',
	'Voice of America',
	'Getting a Head',
	'Fall Mountain',
	'Live Show',
	'Bob\'s work in general',
       );

$q = new CGI;
print $q->header;
print $q->start_html(-title=>'Bob Ostertag Visitor Reviews');
print "<body bgcolor=\"#999933\" text=\"#000000\" link=\"#ff0000\" vlink=\"#5555
00\" alink=\"#ff00ff\">\n";
print $q->startform('post', $self);
print "<font size=6>Visitor Reviews<br></font>\n";

$q->import_names('Q');
# print $q->dump();

# lessee, error checking first - must have a  To, a Body...

if($Q::submit) {  # if they pushed the button...
   $error .= "Error: Your message is blank.  You must have <b>something</b> to say!<br>\n" unless ($Q::body);

   $error .= "Error: Who are you?  From field is required!<br>\n" unless ($Q::from);

print $error, "<hr>" if($error);

# no errors, send it off!
  if(!$error) {
    if($Q::url) {
      if($Q::url =~ /\@/) {
        $href="mailto:"; 
	$url = $Q::url;
      } else {
        $Q::url =~ s/^http:\/\/(.*)/$1/i;
	$url = $Q::url;
	$href = "http://";
      }
    $from = "<a href=\"$href$url\">$Q::from</a>";
    } else {
      $from = $Q::from;
    }
    # now save (append) the stuff to the old reviews file
    open(OLD, ">>/www/Detritus/ostertag/reviews/reviews.html") || die 
    	"can't open old reviews: $!\n<br>";
    print OLD <<"EOT";
<!--another review -->
    <hr>
    <font size=5>Review of <b>$Q::album</b> written by $from.</h2>
    <blockquote>
      $Q::body
    </blockquote>
EOT
    
    close OLD;
    $q->delete_all();   # get rid of old submission
  }  # end of no errors
}    # end of submit block

# now open to read
open(OLD, "/www/Detritus/ostertag/reviews/reviews.html");
@old_reviews = <OLD>;
close OLD;
print @old_reviews unless($error);

# print the form!  

open(OLD, "/www/Detritus/ostertag/reviews/reviews.html");
@old_reviews = <OLD>;
close OLD;

# the actual form
print
	$q->hr,
	"Write your own:",
	$q->br,
	"Review of: ",
	$q->popup_menu(-name=>'album', 'values'=>\@cd),
	" By: ", 
	$q->textfield(-name=>'from', -size=>25),
	$q->br,
	"email or url (optional): ",
	$q->textfield(-name=>'url', -size=>25),
	$q->br,
	"Review:",
	$q->br,
	$q->textarea(-name=>'body', -wrap=>'physical', -rows=>15, -columns=>50),	$q->br,
	$q->submit(-name=>'submit', 'value'=>'send message'),
	$q->reset('Undo'),
	$q->endform;

print <<"EOT";
<hr>
<i>a script by steev hise</i>
EOT
print $q->end_html;
exit;

