#! /usr/bin/perl

use CGI qw(:all *table *p);

print header();
print start_html(-title=>"SALSA Corpus Request");

if (param('Cancel')) {Delete_all()};

if (! (param('step') && param('name') && param('institution') && param('email'))) {
#  Delete_all();
  print
    h3("Step 1/2: Please Fill In Request Form."),
     start_form(),
     start_table,
#     Tr(td("Name"),td(textfield(-name=>'name',-value=>'Der Stephan'))),
#     Tr(td("Institution"),td(textfield(-name=>'institution',-value=>'UdS'))),
#     Tr(td("Email"),td(textfield(-name=>'email',-value=>'whgsb@sms.at'))),
     Tr(td("Name"),td(textfield(-name=>'name'))),
     Tr(td("Institution"),td(textfield(-name=>'institution'))),
     Tr(td("Email"),td(textfield(-name=>'email'))),
     Tr(td("Purpose*"),td(textarea(-rows=>'3',-cols=>"50",-name=>'purpose'))),
     end_table,
      p('*Optional field; we would be interested to learn what you want to use the SALSA corpus for.'),
     hidden(-name=>'step',-value=>'2'),
     p(submit(-name=>'Go')),
     end_form
     } elsif (param('step') == 2) {
       Delete('step');
       print h3("Step 2/2: Please Read the License Agreement below."),br,hr;
       
       open(FH, "/web/www.coli.uni-saarland.de/html/projects/salsa/corpus/doc/license.html");
       { local $/;  $allfile = <FH>; }
       close(FH);
       $allfile =~ s/<body>(.*)<\/body>/$1/si;
       print p("$allfile"),hr;

       print start_form();
       foreach my $p (param()) {	
	 print hidden(-name=>$p,-value=>param($p));
       };
       print 
	 hidden(-name=>'step',-value=>'3'),
	 p(submit(-name=>'Yes'), "... I have read and accepted the license agreement."),
  	 end_form();
     } elsif (param('step') == 3) {
       my $name = param('name');
       my $inst = param('institution');
       my $email = param('email');
       my $purpose = param('purpose');
       
       foreach my $string ($name,$inst,$email,$purpose) {
	   $string =~ s/[^a-zA-Z0-9_@\-\. ]/*/g;
       };

       
       system("echo \"SALSA corpus Request from\n\n$name\n$inst\n$email\n$purpose\" |mail -s 'SALSA corpus request' salsa-mit\@coli.uni-sb.de");
       print h3("Thank you! You will receive your access data by email.");
       system("echo 'You can download the SALSA corpus from http://www.coli.uni-saarland.de/projects/salsa/corpus/download/.	
Login: salsa-corpus	
Password: tocaro40	
	 '  | mail -s 'Your SALSA corpus request' $email");

       open(LOG,'>>/web/www.coli.uni-saarland.de/html/projects/salsa/corpus/request.log');
       my $today = `date +%D`;
       chomp $today;
       print LOG "$today\t$name\t$inst\t$email\t$purpose\n";
       close(LOG);
     };
	

  if (param('step') != 3) {
      print start_form(),p(submit(-name=>'Cancel')),end_form();
  };
print br(),hr,
  p(span({-style=>'font-style:italic'},a({-href=>'http://www.coli.uni-saarland.de/cl/projects/salsa/'},"The SALSA Project"))),
  end_html();
