<?php
#This is where we get PII from the subject and go to ncms with it. 
#and ask embarrassing questions.
require("includes/.htconfig.php");

$snoopyfile=NCMSSTORAGE."/$enrollee_id.xml";
if (!file_exists($snoopyfile))
{
  include ("./includes/.htxmlparse.inc.php");
}             ##End of NCMS processing, we now have the file and its contents, Q/A are in the database.

if( !empty($_POST) )
{
  if ($_REQUEST["command"] == "Final Answer")
  {
    $question_id=$_REQUEST["question_id"];
    $answernumber=$_REQUEST["answernumber"];
    $query="update questions set subjectanswer=$answernumber where question_id=$question_id";
    if (!mysql_query($query))
    {
      reporterror("recording an answer to a question",$query);
    }
  }
}

$query="select count(subjectanswer) from questions where enrollee_id=$enrollee_id and subjectanswer is NOT NULL";
$nAnswers=mysql_getOne($query);
$query="select * from questions where enrollee_id=$enrollee_id and subjectanswer is NULL";
if (!($questions=mysql_query($query)))
{
  reporterror("getting unanswered questions for $enrollee_id",$query);
  $errmsgs.="<BR>We had trouble finding questions for you.";
}
else if (($nToGo=mysql_num_rows($questions)) == 0)    ##Finished all the questions
{
  $msgs.="That's all folks.";
  require("includes/.htdecide.inc.php");
  if ($decide)
  {
    $key=openssl_pkey_get_private("file:/var/www/sites/www.reliableid.com/ValID/cert.pem","mad3mad3mad");
    if ($key) $msgs.="<BR>We opened the key.";
    else $errmsgs.="<BR>We did not open the key.";
    advancePage($enrollee_id,$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 him up with the information available at ".REJECTURL."?id=$enrollee_id.";
    mail(REJECTTO,REJECTSUBJECT,$body,$headers);
  }
}

?>
<!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>
<link href="./style/design.css" rel="stylesheet" type="text/css" />

<style type="text/css">
<!--
.style1 {font-size: 0.8em}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Identity Authentication</title>
<script language="JavaScript" src="includes/js/common.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="cal/calendar-win2k-cold-1.css" title="win2k-cold-1"><!-- main calendar program -->  
  <script type="text/javascript" src="cal/calendar.js"></script><!-- language for the calendar -->  
  <script type="text/javascript" src="cal/calendar-en.js"></script><!-- the following script defines the Calendar.setup helper function, which makes
       adding a calendar a matter of 1 or 2 lines of code. -->  
  <script type="text/javascript" src="cal/calendar-setup.js"></script>
<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 ($nAnswers > 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
        }
        echo "<BR>Question number ".$nAnswers."-";
        $question=mysql_fetch_array($questions);
        echo $question["question"];
        echo "<BR><INPUT type=hidden name=question_id value=".$question["question_id"].">";
        $query="select * from answers where question_id=".$question["question_id"];
        echo "<SELECT name=answernumber>";
        echo spew_options($link,$query,"answernumber","answer");
        echo "</SELECT>";
        echo "<BR><INPUT type=submit name =command value='Final Answer'>";
        ?>
        <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>