#!/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 = "feedbk2.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/feedbk2.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" style="width: 600px">
  <tr style="height: 0">
    <td style="width: 110px"></td>
    <td style="width:  30px"></td>
    <td style="width: 170px"></td>
    <td style="width: 290px"></td>
  </tr>
  <tr style="height: 1.5em">
    <td colspan="4" class="masthead1">Ridged Band</td>
  </tr>
  <tr style="height: 1.2em">
    <td colspan="4" class="masthead2">SPECIALIZED TISSUE OF THE PENIS</td>
  </tr>
  <tr style="height: 1.2em">
    <td colspan="4"></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-e.html">Home</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/abstr1.html">Abstract</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/anat1.html">Anatomy</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/func1.html">Function</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/pix1.html">Pictures</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/faq1.html">FAQ</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/news1.html">Newsletter</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left-selected">Questionnaire</td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/cgi-bin/feedbk1.cgi">Feedback</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/links1.html">Links</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/feedbk2-f.html">Fran&ccedil;ais</a></td>
        </tr>
      </table>
    </td>
    <td></td>
    <td colspan="2" class="bodytext" valign="top">

<p class="heading1">QUESTIONNAIRE</p>

<p style="margin-top: 1em">Previous scientific papers published in the <a href="http://www.cirp.org/library/anatomy/taylor/">British Journal of Urology</a> and <a href="http://www.cirp.org/library/anatomy/cold-taylor/">BJU International</a> dealt with the anatomy of the foreskin and its ridged band. However, there is still a great deal to be learned about the anatomy and function of the penis.</p> 

<img src="http://research.cirp.org/images/male1.gif" style="margin: 0 0 1em 0" alt="Diagram showing bulbocavernosus muscle" />

<p style="font-weight: bold">Instructions:</p>

<p>Repeat these tests until you think you have reliable answers. Don&#8217;t rush. Do the tests with penis flaccid (soft).</p>

<ol style="margin: 0 0 0 2em; padding: 0 0 0 0">
<li style="margin: 0 0 0 0;   padding: 0 0 0 0">Try to relax. Contract your <span style="font-weight: bold">bulb muscles</span> as quickly and firmly as you can. (The bulb muscles are the ones that squeeze the back end of the penis after urination.) Repeat the squeeze 5 -10 times so that you remember how hard or how easy it is to finish urination in the usual way. Can you feel the contraction?
    <p style="margin-top: 0.5em"><input type="radio" name="Q1" value="YES" />Yes&nbsp;&nbsp; &nbsp;&nbsp;<input type="radio" name="Q1" value="NO" />No</p></li>

<li style="margin: 2em 0 0 0; padding: 0 0 0 0">Repeat the above test, this time gently squeezing the urethra between thumb and forefinger at a point midway along the penis. 


<p style="margin-top: 0.5em">What effect does compression of the urethra have on bulb muscle contraction?</p>
<p style="margin-top: 0.5em"><input type="radio" name="Q2" value="NO DIFFERENCE" />It makes no difference.</p>
<p style="margin-top: 0.5em"><input type="radio" name="Q2" value="EASIER" />It makes it EASIER (less difficult, shorter time to full contraction).</p>
<p style="margin-top: 0.5em"><input type="radio" name="Q2" value="MORE DIFFICULT" />It makes it MORE DIFFICULT (longer time to full contraction).</p>


</li>

<li style="margin: 2em 0 0 0; padding: 0 0 0 0">Your age:
    <p style="margin-top: 0.5em"><input type="radio" name="Q3" value="18-29" />18-29&nbsp;&nbsp; &nbsp;&nbsp;<input type="radio" name="Q3" value="30-39" />30-39&nbsp;&nbsp; &nbsp;&nbsp;<input type="radio" name="Q3" value="40-49" />40-49&nbsp;&nbsp; &nbsp;&nbsp;<input type="radio" name="Q3" value="50-59" />50-59&nbsp;&nbsp; &nbsp;&nbsp;<input type="radio" name="Q3" value="60+" />60+</p></li>

<li style="margin: 2em 0 0 0;   padding: 0 0 0 0">Were the instructions easy to understand?
    <p style="margin-top: 0.5em"><input type="radio" name="Q4" value="YES" />Yes&nbsp;&nbsp; &nbsp;&nbsp;<input type="radio" name="Q4" value="NO" />No</p></li>
</ol>

    </td> 
  </tr>





  <tr>
    <td></td>
    <td></td>
    <td class="bodytext" valign="top" style="padding: 1em 0 0 0">
Your email address:<br /><input type="text" name="users_email" value="" />
    </td>
    <td class="bodytext" valign="top" style="padding: 1em 0 0 0">
Your name (optional):<br /><input type="text" name="users_name" />
    </td> 
  </tr>


  <tr>
    <td></td>
    <td></td>
    <td colspan="2" class="bodytext" valign="top" style="padding: 1em 0 0 0">

Additional comments:<br /><textarea name="message" rows="6" cols="40"></textarea>
<br /><input type="submit" value="   Send it   " style="margin: 0.5em 0 0 0" /><input type="hidden" name="mail" value="1" />
<p style="margin: 1em 0 1em 0">Thank you for your assistance!</p>

    </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>

</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"     =>    "Email address is blank.",
                "2"     =>    "Email address must contain @.",
                "3"     =>    "Referring Web page is blank.",
                "4"     =>    "Unknown referring Web page.",
                "5"     =>    "Comments must not contain urls.");


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

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="3" class="masthead1">Ridged Band</td>
  </tr>
  <tr style="height: 1.2em">
    <td colspan="3" class="masthead2">SPECIALIZED TISSUE OF THE 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">The form you submitted contained the following error:</p><p style="font-weight: bold; color: #ff0000; margin-left: 2em">$error_codes{$error}</p><p style="margin-left: 1em">Please click on your browser&#8217;s <span class="i">Back</span> button to correct your input.</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: RB survey result
Cc: harrisond\@telus.net

__END_OF_MESSAGE__
print MESSAGE ("Respondent: $FORM_DATA{'users_email'}\n");
print MESSAGE ("Name: $FORM_DATA{'users_name'}\n\n");

print MESSAGE ("Can you feel the bulb muscle contraction? $FORM_DATA{'Q1'}\n\n");

print MESSAGE ("With compression of urethra:\ $FORM_DATA{'Q2'}\n");

print MESSAGE ("Age: $FORM_DATA{'Q3'}\n");

print MESSAGE ("Questions easy to understand? $FORM_DATA{'Q4'}\n\n");

print MESSAGE ("Additional comments:\n");
print MESSAGE ("$FORM_DATA{'message'}");
print MESSAGE ("\n###\n");

print MESSAGE ("SYSTEM INFORMATION\n");
print MESSAGE ("Browser: $FORM_DATA{'browserName'}\n");
print MESSAGE ("Version: $FORM_DATA{'browserVersion'}\n");
print MESSAGE ("Screen Resolution: $FORM_DATA{'screenSize'}\n");
print MESSAGE ("Operating System: $FORM_DATA{'platform'}\n");
print MESSAGE ("System Language: $FORM_DATA{'systemLanguage'}\n");
print MESSAGE ("referrer: $FORM_DATA{'referrer'}\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="3" class="masthead1">Ridged Band</td>
  </tr>
  <tr style="height: 1.2em">
    <td colspan="3" class="masthead2">SPECIALIZED TISSUE OF THE 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-e.html">Home</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/abstr1.html">Abstract</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/anat1.html">Anatomy</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/func1.html">Function</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/pix1.html">Pictures</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/faq1.html">FAQ</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/news1.html">Newsletter</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left-selected">Questionnaire</td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/cgi-bin/feedbk1.cgi">Feedback</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/links1.html">Links</a></td>
        </tr>
        <tr style="height: 1em"> 
          <td class="nav-left"><a class="nav-left" href="http://research.cirp.org/feedbk2-f.html">Français</a></td>
        </tr>
      </table>
    </td>
    <td></td>
    <td colspan="2" class="bodytext" valign="middle"><p class="b">Thank you...</p><p class="b">...your reply has been sent.</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

