<?

// Now process the form
   if ($_SERVER['REQUEST_METHOD']=="POST"){
      // In testing, if you get an Bad referer error
      // comment out or remove the next three lines
      if (strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'])>7 ||
         !strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']))
         die("Bad referer");
      $msg="User Study Questionnaire form version 1.0:\n\n";
      foreach($_POST as $key => $val){
         if (is_array($val)){
            $msg.="Item: $key\n";
            foreach($val as $v){
               $v = stripslashes($v);
               $msg.="   $v\n";
            }
         } else {
            $val = stripslashes($val);
			if( $val == "on" ) {
				$msg.="$key\n";
			}
			else {
            	$msg.="$key: \"$val\"\n";
			}
         }
      }
      $recipient="stewart@csail.mit.edu";
      $subject="User Study Questionnaire";
      error_reporting(0);
      if (mail($recipient, $subject, $msg)){
         $res = "<h1>Thank you!</h1><p>Successfully submitted.</p>\n";
         //$res .= nl2br($input);
      } else
         $res = "An error occurred and the message could not be sent.";
   }/* else
      $res = "Bad request method";*/
	  
	  
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>User Study Questionnaire</title>
</head>

<body>
<?
if( $res != "" ) {
echo $res;
}
else {

?>
<h3>Questionnaire</h3>
<form id="questionnaire" name="questionnaire" method="post" action="<? echo $PHP_SELF; ?>">
  <p>List three things you liked about Idea Navigator:<br />
    <textarea name="liked" cols="70" rows="10" wrap="virtual" id="liked"></textarea>
  </p>
  <p>List three things you disliked about Idea Navigator:<br />
    <textarea name="disliked" cols="70" rows="10" wrap="virtual" id="disliked"></textarea>
  </p>
  <p>How old are you? 
    <input name="age" type="text" id="age" size="5" />
  </p>
  <p>Gender: 
     <input type="radio" name="gender" id="gender" value="female" />
     Female &nbsp; 
  <input type="radio" name="gender" id="gender" value="male" />
  Male
</p>
  <p>Primary language: 
    <input name="language" type="text" id="language" size="40" />
  </p>
  <p>Are you fluent in English? 
    <input type="radio" name="fluent" id="fluent" value="yes" />
Yes &nbsp;
<input type="radio" name="fluent" id="fluent" value="no" />
No </p>
  <p>Are you a student? 
    <input type="radio" name="student" id="student" value="yes" />
Yes &nbsp;
<input type="radio" name="student" id="student" value="no" />
No </p>
  <p>What is your occupation or primary field(s) of study? 
    <input name="field" type="text" id="field" size="40" />
  </p>
  <p>When finished: 
    <input type="submit" name="Submit" id="Submit" value="Submit" />
  </p>
</form>
<?
}
?>
</body>
</html>
