<?php
session_start();
ob_start();

require("../includes/config.php");
require("../includes/dbcon.php");
if($_SESSION['uid']==""){	
	header("location:index.php");
	exit();
}
$eId=$_REQUEST['eId'];
$enrolleeQuery = mysql_query("select * from enrollee where enrollee_id=".$eId);
$enrolleeValue = mysql_fetch_array($enrolleeQuery);

$enrolleeName=$enrolleeValue['fisrt_name']." ".$enrolleeValue['middle_name']." ".$enrolleeValue['last_name'];
if( !empty($_POST) )
{
	$qsn="";
	$ans="";
	$insert_ans_sql="";
	$insertId="";
	$insert_enrollee_security_sql="";

	$q1=$_REQUEST['q1'];
	$q2=$_REQUEST['q2'];
	$q3=$_REQUEST['q3'];
	$q4=$_REQUEST['q4'];
	$q5=$_REQUEST['q5'];

	$a1=trim($_REQUEST['a1']);	
	$a2=trim($_REQUEST['a2']);
	$a3=trim($_REQUEST['a3']);
	$a4=trim($_REQUEST['a4']);
	$a5=trim($_REQUEST['a5']);
	/*for($i=1;$i<=5;$i++)
	{
		print $ans=$a.$i;
		print "<br>";
		print $qsn=$q."".$i;
		exit;*/
		if(!empty($a1))
		{
			$qsn=$q1;
			$ans=$a1;
			$insert_ans_sql="insert into security_answer set security_q_id=".$qsn.", answer='".$ans."'";			
			mysql_query($insert_ans_sql);
			$insertId= mysql_insert_id();

			if($insertId)
			{				
				$insert_enrollee_security_sql="insert into enrollee_security set enrollee_id=".$eId.", answer_id=".$insertId;
				mysql_query($insert_enrollee_security_sql);
			}
		}

		if(!empty($a2))
		{
			$qsn=$q2;
			$ans=$a2;
			$insert_ans_sql="insert into security_answer set security_q_id=".$qsn.", answer='".$ans."'";			
			mysql_query($insert_ans_sql);
			$insertId= mysql_insert_id();

			if($insertId)
			{				
				$insert_enrollee_security_sql="insert into enrollee_security set enrollee_id=".$eId.", answer_id=".$insertId;
				mysql_query($insert_enrollee_security_sql);
			}
		}

		if(!empty($a3))
		{
			$qsn=$q3;
			$ans=$a3;
			$insert_ans_sql="insert into security_answer set security_q_id=".$qsn.", answer='".$ans."'";			
			mysql_query($insert_ans_sql);
			$insertId= mysql_insert_id();

			if($insertId)
			{				
				$insert_enrollee_security_sql="insert into enrollee_security set enrollee_id=".$eId.", answer_id=".$insertId;
				mysql_query($insert_enrollee_security_sql);
			}
		}

		if(!empty($a4))
		{
			$qsn=$q4;
			$ans=$a4;
			$insert_ans_sql="insert into security_answer set security_q_id=".$qsn.", answer='".$ans."'";			
			mysql_query($insert_ans_sql);
			$insertId= mysql_insert_id();

			if($insertId)
			{				
				$insert_enrollee_security_sql="insert into enrollee_security set enrollee_id=".$eId.", answer_id=".$insertId;
				mysql_query($insert_enrollee_security_sql);
			}
		}

		if(!empty($a5))
		{
			$qsn=$q5;
			$ans=$a5;
			$insert_ans_sql="insert into security_answer set security_q_id=".$qsn.", answer='".$ans."'";			
			mysql_query($insert_ans_sql);
			$insertId= mysql_insert_id();

			if($insertId)
			{				
				$insert_enrollee_security_sql="insert into enrollee_security set enrollee_id=".$eId.", answer_id=".$insertId;
				mysql_query($insert_enrollee_security_sql);
			}
		}
	//}
	header("location:aprove.php?eId=".$eId);
}
ob_end_flush();
?>
<!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>:::   User Questionaries Page   :::</title>
<script language="JavaScript" src="../includes/js/common.js"></script>
<script language="JavaScript">
function validate()
{
	var is_valid=true
			
	is_valid = blank_check( document.frm.a1.value, "PLEASE INPUT ANSWER 1" )
		if( is_valid == false ) { document.frm.a1.focus(); return is_valid }

	is_valid = blank_check( document.frm.a2.value, "PLEASE INPUT ANSWER 2" )
		if( is_valid == false ) { document.frm.a2.focus(); return is_valid }

	is_valid = blank_check( document.frm.a3.value, "PLEASE INPUT ANSWER 3" )
		if( is_valid == false ) { document.frm.a3.focus(); return is_valid }

	is_valid = blank_check( document.frm.a4.value, "PLEASE INPUT ANSWER 4" )
		if( is_valid == false ) { document.frm.a4.focus(); return is_valid }

	is_valid = blank_check( document.frm.a5.value, "PLEASE INPUT ANSWER 5" )
		if( is_valid == false ) { document.frm.a5.focus(); return is_valid }
	
	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">Questionaries for <?=$enrolleeName?> </span> </div></td>
				</tr>
			</table>
			<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0" class="DarkLightBox">	
		<?php
		if($err_msg)
		{
		?>
			 <tr>
			   <td height="30" align="center" valign="top" colspan="5"><strong><?=$err_msg?></strong></td>	   
			 </tr>
		<?php
		}
		?>
		<?php
			$questionQuery = mysql_query("select * from security_question order by security_q_id asc");
			$j=1;
			while($questionValue = mysql_fetch_array($questionQuery))
			{
		?>
			 <tr>
			   <td width="10%" height="30" align="left" valign="top" class="browseEventContents"><b>Question <?=$j?>:</b></td>	   
			   <td width="35%" height="30" align="left" valign="top"><?=$questionValue['question']?></td>
			   <td height="30" align="left" valign="top" width="1%">&nbsp;<input name="q<?=$j?>" type="hidden" value="<?=$questionValue['security_q_id']?>"></td>
			   <td width="10%" height="30" align="left" valign="top" class="browseEventContents"><b>Answer <?=$j?>:</b></td>
			   <td width="44%" height="30" align="left" valign="top"><input name="a<?=$j?>" type="text" class="textField" size="50" /></td>   
			 </tr> 	 
			 <tr>
			   <td height="30" align="left" valign="top" colspan="5">&nbsp;</td> 
			 </tr>	     	     	     	     	     	  
		<?
			$j++;
			}
		?>
			 <tr>
			   <td height="30" align="right" valign="top" class="browseEventContents" colspan="5"><input name="Submit" type="submit" value="Next" /></td>
			 </tr>
		</table>
	</form>
<?php
include_once("../includes/footer.php");
?>
		</td>
	</tr>
</table>
</body>
</html>