#!/usr/bin/perl

require 'cgi-lib.pl';
require 'html-sheets.pl';

$base_url="/concentrators";

$source_path  = "/homes/nber/cuthbert/web/concentrators/concen_source";
$current_url   = "$base_url/concen.cgi";

$small_image  = "$base_url/images/8060/conc.jpg";
$banner_image = "$base_url/images/head_conc.jpg";

$doc_title    = "concentrators";
$banner_alt   = "[$doc_title]";

$header_information =<<EO_TEXT;
EO_TEXT

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

if (&ReadParse()) {
  if ($in{'add'} =~ /true/) {
    &displayInputForm();
    exit 0;
  }
  if (!$in{'comments'}) {
    &displaySource;
    exit 1;
  }
  $in{'subject'} =~ s|[\<\>(\&lt)(\&gt)\;]| |g;
  $in{'name'}    =~ s|[\<\>(\&lt)(\&gt)\;]| |g;
  $in{'comments'} =~ s|\n|\<br\>|g;
  open (SR,">>$source_path");
  print SR "$in{'subject'}.,.$in{'name'}.,.$in{'comments'}\n";
  close SR;
  &displaySource;
}
else {
  &displaySource;
  exit 1;
}

sub displaySource {
  open (SR,"$source_path");
  @chunk_source=<SR>;
  close SR;

  $read_source='';
  $source_entry='';
  foreach $source_entry (@chunk_source) {
    ($subject,$name,$comments)=split(/\.,\./,$source_entry);
    if ($subject)  {$read_source=$read_source."<b>$subject</b><br>\n";}
    if ($name)     {$read_source=$read_source."<i>$name</i><br>\n";}
    if ($comments) {$read_source=$read_source."<font color=\"#307030\">$comments</font><p>\n";}
  }
  &music_headers;
  print <<EOF;
<tr><td colspan=2>
<font face="helvetica, arial" size=-1>
<br>
$header_information<br>
<a href="$current_url?add=true">add comments</a>
<p>

$read_source

</font></td></tr></table>
<p>
EOF

  &text_navbar;
  &html_footer;
}

sub displayInputForm {
  &music_headers;
  &submit_new;
  &text_navbar;
  &html_footer;
}
