<?php
#This is where we get PII from the subject and go to ncms with it. 
#and ask embarrassing questions.
#As of 7 May 2009, the PII is already in the $_SESSION array and the questions will be stored there, too.
require("includes/.htconfig.php");
if (!isset($subjectid) || is_null($subjectid))
{
  reportError("Lost subjectid before going to NCMS.");
  die("We are sorry but we have lost track of your identity and can't go further.  Can you <A href=start.php>start all over</A>?");
}
$snoopyfile=NCMSSTORAGE."/$subjectid.xml";
if (!file_exists($snoopyfile))
{
  include ("./includes/.htNCMSsend.inc.php");
}             ##End of NCMS processing, we now have the file and its contents, Q/A are in the database.
if (!array_key_exists("questions",$_SESSION))
  require("./includes/.htNCMSparse.inc.php");
$questions=$_SESSION['questions'];
if (!array_key_exists("questions",$_SESSION) || $questions['general']['numquestions'] == 0)
{
  reportError("No questions returned from NCMS for $subjectid");
  $errmsgs.="<BR>We are sorry but there seems to be a problem with the response to your data.  We shall send your information to aone of our notaries for resolution.";
  $stopthis=1;
}
else
  $stopthis=0;

if( !empty($_POST) )
{
  if ($_REQUEST["command"] == "Final Answer")
  {
    $question_id=$_REQUEST["question_id"];
    $answernumber=$_REQUEST["answernumber"];
    $_SESSION['questions']['questions'][$question_id]['answer']=$answernumber;
    $_SESSION['questions']['general']['lastquestion']=$question_id;
  }
  else
    $question_id=0;
}
else
  $question_id=0;

$nToGo = intval($questions['general']['numquestions'])-intval($question_id);

if ($questions['general']['numquestions'] == $question_id)     ##Finished all the questions
{
  $msgs.="That's all folks.";
  require("includes/.htdecide.inc.php");
  if ($decide)
  {
    advancePage($newby);
    exit();
  }
  else
  {
    $errmsgs.="<BR>I'm sorry but we don't think you've proven yourself to be who you say you are.  "
      ."We shall inform our staff notary who should contact you soon.";
    $errmsgs.="<BR>You got $nright questions right out of $nq, leaving $nwrong wrong, not good.";
    $headers="From: ".EMAILFROM;
    $body="We have just rejected ".makeName($enrollee)."."
      ."Perhaps, you can cheer ".(($_SESSION['gender'] == "m")?("him"):("her"))." up with the information available at ".REJECTURL."?id=$enrollee_id.";
      $body.="\n\nActually, the information he gave us is in\n$url\nand the questions from NCMS were\n";
      $body.=file_get_contents($snoopyfile);
    mail(REJECTTO,REJECTSUBJECT,$body,$headers);
  }
}
require("includes/headstart.php");
?>
  <title>Identity Authentication</title>
<script language="JavaScript">
function validate()
{
	var is_valid=true

	return is_valid
}
</script>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr>
		<td align="center" valign="top">

<?php
include_once("includes/header.php");

?>
<form name="frm" method="post" action="" enctype="multipart/form-data" onSubmit="return validate()">	
	<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">	 
	 <tr>
	   <td width="30%" valign="top">
		<div class="bodySubHeader">
		<span class="bsht03">Authentication of Your Claims</span>		
		</div>
		</td>
	 </tr>
    <?PHP
    if ($nToGo > 0)
    {
    ?>
    <tr>
      <td colspan="4">
        <?PHP
        if ($stopthis == 0)
        {
          if ($question_id > 0)
          {
            echo "Doing well so far, $nToGo to go.  Here's the next one.";
          }
          else
          {
          ?>
          We shall now embark on the touchy subject of the veracity of your claims.
          We are about to ask you <?=$nToGo?> questions which other people are unlikely to know.
          Please answer them correctly.
          <?PHP
          }
          $question_id++;
          echo "\n<BR>Question number ".$question_id."-";
          echo $questions['questions'][$question_id]['question'];
          echo "<BR><INPUT type=hidden name=question_id value=$question_id>";
          echo "<SELECT name=answernumber>";
          foreach ($questions['questions'][$question_id]['answers'] as $n=>$answer)echo "\n<OPTION value=$n> $answer";
          echo "</SELECT>";
          echo "<BR><INPUT type=submit name =command value='Final Answer'>";
        }   ##  $stopthis == 0
        ?>
        <br/>
      </td>
    </tr>
    <?PHP
    }
    ?>
	</table>		
	<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0" class="DarkLightBox">
	 <tr>
	   <td height="30" align="left" valign="top" colspan="8">&nbsp;</td> 
	 </tr>		 
	</table>
</form>
<?php
include_once("includes/footer.php");
?>
	   </td>
	 </tr> 	 
</table>
</body>
</html>