<?php
##This is where we gather the credentials in batches of up to three.  So far, we do not ask for scans of them.
##For the first goround, we try to steer the subject toward a birth certificate.
##The process continues to collect credentials until No more is selected as a credential type
##or the subject clicks the That's all button.
$newby=9;
require("includes/.htconfig.php");
$msg="";

if( !empty($_POST) )
{
  $ended=FALSE;         ##Stops asking for more credentials
  for ($j=0;$j<3;$j++)
  {
    $credtype=trim($_REQUEST["credential_type_code$j"]);
    if ($credtype == "nm"){$ended=TRUE;continue;}         ##We go to the next page after processing all of this page.
    if ($credtype == "") continue;
    if ($credtype == "  ") continue;
    $credential_name=trim($_REQUEST["credential_name$j"]);
    $prior_name=trim($_REQUEST["prior_name$j"]);
    $issuing_agency=trim($_REQUEST["issuing_agency$j"]);
    $issue_date=trim($_REQUEST["issue_date$j"]);
    $valid_until=trim($_REQUEST["valid_until$j"]);
    $query="insert into credential set
      enrollee_id=$enrollee_id,
      issuing_agency='".mysql_escape_string($issuing_agency)."',
      credential_type_code='$credtype',
      credential_name='".mysql_escape_string($credential_name)."',
      issue_date='".mysql_escape_string($issue_date)."'";
    if (strlen($prior_name)>0) $query.=",prior_name='".mysql_escape_string($prior_name)."'";
    if (strlen($valid_until)>0) $query.=",valid_until='".mysql_escape_string($valid_until)."'";
    if (!mysql_query($query,$link))
    {
      reporterror("adding credential $j",$query);
      $errmsgs.="<BR>We failed to record your ".getOne("select credential_type from credential_type_code where credential_type_code = '$credtype'").".";
    }
  }
  if ($ended  || ($_REQUEST["command"] == "That's all I have"))
  {
    advancePage($enrollee_id,$newby);
  }
}

######################################################################################################

?>
<!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>Your Credentials</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");
          $typequery="select * from credential_type_code";
          $credsquery="select c.*,ct.credential_type from credential c,credential_type_code ct where ct.credential_type_code=c.credential_type_code and enrollee_id=$enrollee_id order by issue_date";
          $creds=mysql_query($credsquery);
          $nCreds=mysql_num_rows($creds);
        ?>
        <?php
        if( 1 )
        {
        ?>
          <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td width="30%" valign="top">
                <div class="bodySubHeader">
                  <span class="bsht03">Step 3: Identity Documentation</span>
                </div>
              </td>
            </tr>
            <tr>
              <td colspan="4">
                <?PHP
                if ($nCreds >0)
                {
                  echo "So far, you have submitted these $nCreds documents:";
                  for ($j=0;$j<$nCreds;$j++)
                  {
                    $cred=mysql_fetch_array($creds);
                    echo "<BR>".$cred["issue_date"]."-".$cred["credential_type"]." issued by ".$cred["issuing_agency"]
                      ." gives your name as ".$cred["credential_name"].".";
                    if (!is_null($cred["prior_name"]) && strlen($cred["prior_name"]) > 0)
                      echo "  This was a change from ".$cred["prior_name"].".";
                  }
                  echo "<BR><FORM action=$script method=post><INPUT type=submit name=command value=\"That's all I have\"></FORM>";
                  echo "<BR>Now you can add more for a complete record.";
                }
                else
                {
                ?>
                We now need to know what documents you have to verify your claim of identity.
                We would like to have at least your birth certificate and one government-issued photo ID.
                You should also tell us about any documents which change your name (court order, marriage license, adoption record).
                You don't have to get them in order, we can do that.
                Just record them for us now as well as you can.
                <?PHP
                }
                ?>
                <br/>
              </td>
            </tr>
          </table>
        <form name="frm" method="post" action="<?=$script?>" enctype="multipart/form-data" onSubmit="return validate()">

          <table>
            <tr>
              <?PHP
              for ($i=0;$i<3;$i++)
              {
                $j=$nCreds+$i;
                echo "<th>Document $j</th>";
              }
              ?>
            </tr>
            <tr>
              <?PHP
              for ($j=0;$j<3;$j++)
              {
              ?>
              <td>
                <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0" class="DarkLightBox">
                  <tr>
                    <td height="30" align="left" valign="top" class="browseEventContents">Document type:</td>
                    <td height="30" align="left" valign="top" colspan="7">
                      <select name='credential_type_code<?=$j?>' id='type_code<?=$j?>'>
                        <?php
                          echo "<option value=\"  \"></option>";
                          if ($nCreds == 0 and $j == 0)
		                        echo spew_options($link,$typequery,"credential_type_code","credential_type","bc");
                          else
		                        echo spew_options($link,$typequery,"credential_type_code","credential_type");
                          echo "<option value=\"nm\">No more</option>";
                        ?>
                      </select>
                    </td>
                  </tr>

                  <tr>
                    <?PHP
                    echo inputCells("Name on the credential$redstar","credential_name$j");
                    echo "</tr><tr>".inputCells("Previous name (if changed)","prior_name$j");
                    echo "</tr><tr>".inputCells("Identifier or number","number$j");
                    echo "</tr><tr>".inputCells("Issuing Agency$redstar","issuing_agency$j");
                    ##echo "</tr><tr>".inputCells("Date of issue$redstar","issue_date$j");
                    ##echo "</tr><tr>".inputCells("Expiration date","valid_until$j");
                    ?>
                  </tr>
                  <tr>
                    <td height="30" align="left" valign="top" class="browseEventContents">
                      Date of issue:<?$redstar?>
                    </td>
                    <td height="30" align="left" valign="top">
                      <input name="issue_date<?=$j?>" id="issue_date<?=$j?>" type="text" class="textField"/>&nbsp;<img src="cal/img.gif" id="f_trigger_<?=$j?>" style="border: 1px solid red; cursor: pointer;" title="Date selector" onMouseOver="this.style.background='red';" onMouseOut="this.style.background=''">
                    </td>
                  </tr>
                  <tr>
                    <td height="30" align="left" valign="top" class="browseEventContents">Expiration date<BR>(if any):</td>
                    <td height="30" align="left" valign="top">
                      <input name="valid_until<?=$j?>" id="valid_until<?=$j?>" type="text" class="textField"/>&nbsp;<img src="cal/img.gif" id="f_trigger_e<?=$j?>" style="border: 1px solid red; cursor: pointer;" title="Date selector" onMouseOver="this.style.background='red';" onMouseOut="this.style.background=''">
                    </td>
                  </tr>
                </table>
              </td>
              <?PHP
              }
              ?>
            </tr>
            <tr>
              <td height="35" align="left" valign="bottom" colspan="2">&nbsp;</td>
              <td height="35" align="left" valign="bottom">
                <input name="Submit" type="submit" value="Next" />
              </td>
            </tr>
          </table>
        </td>
    </tr>
  </table>
</form>
<?PHP
for($j=0;$j<3;$j++)
{
?>
<script type="text/javascript">
  Calendar.setup({
  inputField     :    "issue_date<?=$j?>",     // id of the input field
  ifFormat       :    "%Y-%m-%e",      // format of the input field
  button         :    "f_trigger_<?=$j?>",  // trigger for the calendar (button ID)
  align          :    "Tl",           // alignment (defaults to "Bl")
  singleClick    :    true
  });
  Calendar.setup({
  inputField     :    "valid_until<?=$j?>",     // id of the input field
  ifFormat       :    "%Y-%m-%e",      // format of the input field
  button         :    "f_trigger_e<?=$j?>",  // trigger for the calendar (button ID)
  align          :    "Tl",           // alignment (defaults to "Bl")
  singleClick    :    true
  });
</script>
<?PHP
}
?>
<?php
}
else
{
	$msg="You are already activated";
?>
	<table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">		 
	 <tr>
	   <td height="30" align="center" valign="top"><strong><?=$msg?></strong></td>	   
	 </tr>
	</table>
<?php
}
?>
<?php
include_once("includes/footer.php");
?>
	   </td>
	 </tr> 	 
</table>
</body>
</html>