#!/usr/bin/perl5

my $TITLE = "Send message";
my $BGCOLOR = "#FFFFFF";
my $TEXT_COLOR_NORMAL = "#000000";
my $REQUIRED_TEXT_COLOR = "#000000";
my $BACKGROUND_URL = "";
my $CGI_DIR = "/cgi-bin";
my $SENDMAIL = "/usr/sbin/sendmail";
## my $SENDMAIL = "/usr/lib/sendmail";
my $IMAGE_DIR = "http://research.cirp.org/images";
## my $CC_EMAIL = "harrisond\@telus.net";
my $CC_EMAIL = "";
my $MODULE = "feedbk1-f.cgi";

&get_form_data;
if (!$FORM_DATA{'mail'}) {
        &print_header;
        &print_html_form;
} else {
        $error = 0;
        &print_header;        
        &check_form_data;
        if (!$error) {
                &send_mail;
                &reply_to_user;
        }       
}
exit(0);

######## THE SUBROUTINES ########

########
#
#sub get_form_data
#
#       Gets the information submitted, decodes it, and puts it
#       into the $FORM_DATA associative array.
#
#########
sub get_form_data {
        
$request_method = $ENV{'REQUEST_METHOD'};
if ($request_method eq "GET") {
        $form_info = $ENV{'QUERY_STRING'};
} else {
        $size_of_form_information = $ENV{'CONTENT_LENGTH'};
        read (STDIN, $form_info, $size_of_form_information);
}
@key_value_pairs = split (/&/, $form_info);
foreach $key_value (@key_value_pairs) {
        ($key, $value) = split (/=/, $key_value);
        $value =~ tr/+/ /;
        $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg;
        if (defined($FORM_DATA{$key})) {
                $FORM_DATA{$key} = join (", ", $FORM_DATA{$key}, $value);
        } else {
                $FORM_DATA{$key} = $value;
        }
}

} #get_form_data

########
#
#sub print_header
#
#       Prints out HTML page headers. 
#
########
sub print_header {

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

print <<__END_OF_HTML_CODE__;

\<?xml version=\"1.0\" encoding=\"iso-8859-1\"?\>

\<\!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
    \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"\>
\<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\"\>

\n<head>\n<title>$TITLE</title>

<link rel=\"StyleSheet\" href=\"http://research.cirp.org/style1.css\" type=\"text/css\" />

<SCRIPT LANGUAGE="JavaScript">
<!-- 

function getSysteminfo() {
var x = navigator;
document.mailForm.browserName.value = x.appName;
document.mailForm.browserVersion.value = x.appVersion;
document.mailForm.systemLanguage.value = x.systemLanguage;
document.mailForm.platform.value = navigator.platform;
document.mailForm.referrer.value = document.referrer;

var h = screen.height;
var w = screen.width;
var s = w + "x" + h;
document.mailForm.screenSize.value = s;
}


//-->
</SCRIPT>


</head>
<body onLoad="getSysteminfo();">
__END_OF_HTML_CODE__

}#print_header

########
#
#sub print_html_form
#
#       This subroutine prints out the HTML form the user fills in to
#       send an email message.
#
#########
sub print_html_form {


print <<__END_OF_HTML_CODE__;

<div class="container-main">

<form name="mailForm" action="/cgi-bin/feedbk1-f.cgi" method="post">
<INPUT TYPE="hidden" NAME="browserName" value="Unknown">
<INPUT TYPE="hidden" NAME="browserVersion" value="Unknown">
<INPUT TYPE="hidden" NAME="systemLanguage" value="Unknown">
<INPUT TYPE="hidden" NAME="screenSize" value="Unknown">
<INPUT TYPE="hidden" NAME="platform" value="Unknown">
<INPUT TYPE="hidden" NAME="referrer" value="Unknown">

<table border="0" cellpadding="0" cellspacing="0" class="table-main">
  <tr style="height: 0">
    <td style="width: 110px"></td>
    <td style="width:  30px"></td>
    <td style="width: 190px"></td>
    <td style="width: 170px"></td>
  </tr>
  <tr style="height: 1.5em">
    <td colspan="4" class="masthead1">Bande striée</td>
  </tr>
  <tr style="height: 1.2em">
    <td colspan="4" class="masthead2">TISSU SPECIALISE DU PENIS</td>
  </tr>
  <tr style="height: 1.2em">
    <td colspan="4"></td>
  </tr>
  <tr>
    <td rowspan="3" valign="top">
      <table border="0" cellpadding="0" cellspacing="2" class="table-nav-left">
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/index-f.html">Page d&#8217;accueil</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/abstr1-f.html">Résumé</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/anat1-f.html">Anatomie</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/func1-f.html">Fonction</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/pix1-f.html">Images</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/faq1-f.html">FAQ</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/news1-f.html">Bulletins</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/feedbk2-f.html">Questionnaire</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left-selected">Nous écrire</td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/links1-f.html">Liens</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/cgi-bin/feedbk1.cgi">English</a></td>
        </tr>
      </table>
    </td>
    <td></td>
    <td colspan="2" class="bodytext" valign="top">

<p style="font-weight: bold; margin: 0 0 1.5em 0">Vos commentaires ou questions sont les bienvenus.</p> 

    </td> 
  </tr>

  <tr>
    <td></td>
    <td class="bodytext">
Votre adresse email&nbsp;:<br /><input type="text" name="users_email" id="users_email" value="" />
    </td>
    <td class="bodytext">
Votre nom (facultatif)&nbsp;:<br /><input type="text" name="users_name" />
    </td> 
  </tr>

  <tr>
    <td></td>
    <td colspan="2" class="bodytext">

<p style="margin: 1em 0 0 0">Votre message&nbsp;:</p>
<textarea name="message" rows="6" cols="40"></textarea>
<br /><input type="submit" value="   Envoyer   " style="margin: 0.5em 0 1em 0" /><input type="hidden" name="mail" value="1" />


    </td> 
  </tr>

  <tr style="height: 0.5em">
    <td colspan="4"></td>
  </tr>
  <tr class="hr-bottom">
    <td colspan="4"></td>
  </tr>
  <tr style="height: 0.5em">
    <td colspan="4"></td>
  </tr>
  <tr>
    <td colspan="4" style="text-align: left; padding-left: 0.5em"><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" style="height: 31px; width: 88px; border: none" /></a></td>
  </tr>
</table>
</form>
</div>

<script type="text/javascript">
<!--- Hide
document.form["mailform"].users_email.focus();
// -->
</script>

</body>
</html>



__END_OF_HTML_CODE__

} #print_html_form

########
#
#sub check_form_data
#
#       This subroutine checks the information submitted via the
#       html form to make sure it has all the required information.
#
########
sub check_form_data {

$FORM_DATA{"users_email"} = &escape_input($FORM_DATA{"users_email"}) ;
$FORM_DATA{"users_name"} = &escape_input($FORM_DATA{"users_name"}) ;
$FORM_DATA{"message"} = &escape_input($FORM_DATA{"message"}) ;


#The array which holds all the error code numbers, and the error message
#associated with that code number.
my      %error_codes = (
                "1"     =>    "Une adresse email est obligatoire.",
                "2"     =>    "Une adresse légale doit contenir un et un seul «&nbsp;@&nbsp;».",
                "3"     =>    "Vous avez laissé votre message en blanc.",
                "4"     =>    "Message must not contain urls.",
                "5"     =>    "Referring Web page is blank.",
                "6"     =>    "Unknown referring Web page.");

if ($FORM_DATA{'users_email'} !~ /\w/) {
        $error = 1;
} elsif ($FORM_DATA{'users_email'} !~ /@/) {
        $error = 2;
} elsif ($FORM_DATA{'message'} !~ /\w/) {
        $error = 3;
} elsif ($FORM_DATA{'message'} =~ /href/) {
        $error = 4;
} elsif ($FORM_DATA{'referrer'} !~ /\w/) {
        $error = 5;
} elsif ($FORM_DATA{'referrer'} =~ /Unknown/) {
        $error = 6;
}

if ($error) {

print <<__END_OF_HTML_CODE__;


<div class="container-main">
<table border="0" cellpadding="0" cellspacing="0" class="table-main">
  <tr style="height: 1.5em">
    <td colspan="4" class="masthead1">Bande striée</td>
  </tr>
  <tr style="height: 1.2em">
    <td colspan="4" class="masthead2">TISSU SPECIALISE DU PENIS</td>
  </tr>
  <tr style="height: 2.5em">
    <td colspan="3"></td>
  </tr>
  <tr style="height: 1.2em">
    <td colspan="3" class="bodytext"><p style="margin-left: 1em">Erreur sur le formulaire&nbsp;:</p><p style="font-weight: bold; color: #ff0000; margin-left: 2em">$error_codes{$error}</p><p style="margin-left: 1em">SVP cliquer sur le bouton «&nbsp;Retour&nbsp;» de votre navigateur pour corriger l&#8217;erreur.</p></td>
  </tr>
  <tr style="height: 2em">
    <td colspan="3"></td>
  </tr>
  <tr class="hr-bottom">
    <td colspan="3"></td>
  </tr>
  <tr style="height: 0.5em">
    <td colspan="3"></td>
  </tr>
  <tr>
    <td colspan="3" style="text-align: left; padding-left: 0.5em"><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" style="height: 31px; width: 88px; border: none" /></a></td>
  </tr>
</table>

</div>

</body>
</html>

__END_OF_HTML_CODE__

}

if ($FORM_DATA{'cc'} ne "") {
        $CC_EMAIL = $FORM_DATA{'cc'};
}

} #check_form_data

########
#
#sub send_mail
#
#       This subroutine writes and sends the email message.
#
########
sub send_mail {

open (MESSAGE, "| $SENDMAIL -t -oi ");
print MESSAGE <<__END_OF_MESSAGE__;
To: no_circ\@sbcglobal.net 
From: research\@cirp.org
Subject: commentaires bande striée
Cc: harrisond\@telus.net

__END_OF_MESSAGE__
print MESSAGE ("Répondant : $FORM_DATA{'users_email'}\n");
print MESSAGE ("Nom : $FORM_DATA{'users_name'}\n\n");
print MESSAGE ("Message :\n");
print MESSAGE ("$FORM_DATA{'message'}\n\n");
print MESSAGE ("###\n");
print MESSAGE ("SYSTEM INFORMATION\n");
print MESSAGE ("Navigateur : $FORM_DATA{'browserName'}\n");
print MESSAGE ("Version : $FORM_DATA{'browserVersion'}\n");
print MESSAGE ("Dimensions de l\'écran : $FORM_DATA{'screenSize'}\n");
print MESSAGE ("Système d\'exploitation : $FORM_DATA{'platform'}\n");
print MESSAGE ("Referrer : $FORM_DATA{'referrer'}\n");
print MESSAGE ("Langue du système : $FORM_DATA{'systemLanguage'}\n");
close (MESSAGE);


} #send_mail

########
#
#sub reply_to_user
#
#       Provided everything submitted from the form checks out ok,
#       this subroutine returns an acknowledgement to the user.
#
########
sub reply_to_user {

print <<__END_OF_HTML_CODE__;

<div class="container-main">
<table border="0" cellpadding="0" cellspacing="0" class="table-main">
  <tr style="height: 0">
    <td width="110px"></td>
    <td width=" 50px"></td>
    <td width="440px"></td>
  </tr>
  <tr style="height: 1.5em">
    <td colspan="4" class="masthead1">Bande striée</td>
  </tr>
  <tr style="height: 1.2em">
    <td colspan="4" class="masthead2">TISSU SPECIALISE DU PENIS</td>
  </tr>
  <tr style="height: 1.2em">
    <td colspan="3"></td>
  </tr>
  <tr>
    <td valign="top">
      <table border="0" cellpadding="0" cellspacing="2" class="table-nav-left">
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/index-f.html">Page d&#8217;accueil</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/abstr1-f.html">Résumé</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/anat1-f.html">Anatomie</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/func1-f.html">Fonction</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/pix1-f.html">Images</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/faq1-f.html">FAQ</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/news1-f.html">Bulletins</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/feedbk2-f.html">Questionnaire</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left-selected">Nous écrire</td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/links1-f.html">Liens</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/cgi-bin/feedbk1.cgi">English</a></td>
        </tr>
      </table>
    </td>
    <td></td>
    <td colspan="2" class="bodytext" valign="middle"><p class="b">Merci...</p><p class="b">...votre message a bien été envoyé.</p></td>
  </tr>
  <tr style="height: 0.5em">
    <td colspan="3"></td>
  </tr>
  <tr class="hr-bottom">
    <td colspan="3"></td>
  </tr>
  <tr style="height: 0.5em">
    <td colspan="3"></td>
  </tr>
  <tr>
    <td colspan="3" style="text-align: left; padding-left: 0.5em"><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" style="height: 31px; width: 88px; border: none" /></a></td>
  </tr>
</table>


__END_OF_HTML_CODE__


print ("</BODY>\n</HTML>\n");

} #reply_to_user


sub escape_input { 

local ($stringin) = @_;
$_ = $stringin;
s/&/&amp;/g;
s/</\&#60;/g;
s/>/\&#62;/g;
s/"/&#34;/g;
s/\\\\/&#92;/g;
s/\\\{/&#123;/g;
s/\\\}/&#125;/g;
s/\\,/&#44;/g;
s/\(/&#40;/g;
s/\)/&#41;/g;
s/\[/&#91;/g;
s/\]/&#93;/g;
s/\*/&#42;/g;
s/\+/&#43;/g;
s/\|/&#124;/g;
s/'/&#39;/g;
s/\r\n/\n/g;
s/\r/\n/g;
s/\n/ <BR>/g;

return $_; }


#FILE: $MODULE

