Location: PHPKode > projects > E2Exam: LAMP for the Education > question1a.php
<?
if(!isset($examcode)){
?><script language="javascript">
<!--
	alert("There seems to be an error. Please try again.\n   The system will now close the exam window and prompt you to login.\n If problem reoccur, inform the proctor.\n Thank very much.");
	self.close();
//-->
</script>
<?
} else {
require("db.php");
if(isset($answer)){
	if($answer=="Save"){
		$sql = "select * from ExamAnswers where QID=".$question." and EID='".$examcode."'";
		$res = mysql_query($sql);
		$num = mysql_num_rows($res);
		if($num<=0){
			$sql = "insert into ExamAnswers(EID,QID,ANS) values('".$examcode."',".$question.",'".$ans."')";
			$res = mysql_query($sql);
		} else {
			$sql = "update ExamAnswers set(ANS='".$ans."') where QID=".$question." and EID='".$examcode."' ";
			$res = mysql_query($sql);
		}
		$lastnum=$question;
	}else{
		$sql = "update ExamAnswers set(ANS='".$ans."') where QID=".$question." and EID='".$examcode."' ";
		$res = mysql_query($sql);
	}
	unset($quesid);
}
$sql = mysql_query("select max(QID) as mib from Questions");
$res = mysql_fetch_array($sql);
$mib = $res['mib'];

if(isset($quesid) && !isset($action)){
	$action="Update";
} else {
	$action="Save";
	$x=0;
	do{
		$x++;
		$quesid=mt_rand(1,$mib);
		$sql = "select * from ExamAnswers where QID=".$quesid." and EID='".$examcode."'";
		$res = mysql_query($sql);
		$num = mysql_num_rows($res);
	}while(($num>=1) && ($x<$mib));
	if($x==$mib){
		header("location: question.php?eidmo=".$examcode);
		exit;
	}
}

echo "<html>";

echo "<head>";
echo "<title>Questionnaire</title>";
echo '<script language="javascript">
<!--
function verifyme(t){
	if (confirm("Final Answer?")) {
        return true;
       }
	return false;
}
function mouseDown(e) {
 if (parseInt(navigator.appVersion)>3) {
  var clickType=1;
  if (navigator.appName=="Netscape") clickType=e.which;
  else clickType=event.button;
  if (clickType!=1) {
alert("     Lorma Colleges English Proficiency Exam\n\n\n\n\n                      aoc");
}
 }
 return true;
}
if (parseInt(navigator.appVersion)>3) {
 document.onmousedown = mouseDown;
 if (navigator.appName=="Netscape") 
  document.captureEvents(Event.MOUSEDOWN);
}
//-->
</script>';
echo '<style>
<!--
a.dn:active     { color: #FFFFFF; font-family: Tahoma; font-size: 8pt; background-color: #ff0000; text-decoration: none; }
a.dn:hover     { color: #FFFFFF; font-family: Tahoma; font-size: 8pt; background-color: #ff0000; text-decoration: none; }
a.dn:visited     { color: #008080; font-family: Tahoma; font-size: 8pt; background-color: #ffff00; text-decoration: none; }
a.dn:link     { color: #008080; font-family: Tahoma; font-size: 8pt; background-color: #ffff00; text-decoration: none; }

a:active     { color: #FFFFFF; font-family: Tahoma; font-size: 8pt; background-color: #ff0000; text-decoration: none; }
a:hover     { color: #FFFFFF; font-family: Tahoma; font-size: 8pt; background-color: #ff0000; text-decoration: none; }
a:visited     { color: #FFFF00; font-family: Tahoma; font-size: 8pt; background-color: #008080; text-decoration: none; }
a:link     { color: #FFFF00; font-family: Tahoma; font-size: 8pt; background-color: #008080; text-decoration: none; }

-->
</style>';
echo '</head><body><div align="center"><center>';

if($res = mysql_query("select * from ExamAnswers where EID='".$examcode."'")){
	$itemno = mysql_num_rows($res)+1;
} else {
	$itemno = 1;
}
$sq = "select q.*,d.Directions from Questions q,Directions d where q.DIRID=d.DIRID and QID=".$quesid;
$res = mysql_query($sq) or die("1-".mysql_error());
$r = mysql_fetch_array($res);
#echo '<table cellpadding="0" cellspacing="0" border="0" bordercolor="#008080" width="100%" height="100%">';
#echo '<tr><td width="100%" height="95%" align="center">';
echo '<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">';
echo '<tr>';
echo '<td align="right" style="border-style:solid; border-width:1px; padding:0; color:#FFFFFF; font-family:Tahoma; font-size:10pt; font-weight:bold; background-color:#336699" height="21">';
$img = mt_rand(1,14);
$image = "images/g".$img.".jpg";
echo 'Item#:'.$itemno.' of '.$mib.'&nbsp;       Q#:'.$quesid.'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
echo '<img src="'.$image.'" align="middle" width="375" height="100"></td>';
echo '</tr><tr>';
echo '<td style="border-style:solid; border-width:1px; padding:0; color:#FFFFFF; font-family:Tahoma; font-size:10pt; font-weight:bold; background-color:#008080" height="53">';
echo '<font color="#FFFF00">Direction:</font> '.$r["Directions"].'</td>';
echo '</tr><tr>';
echo '<td valign="top" style="border-style:solid; border-width:1px; padding:0; font-family:Tahoma; font-size:12pt; font-weight:bold" height="67">Q: '.$r["Question"].'</td>';
echo '</tr>';
echo '<form method="post" action="'.$PHP_SELF.'"';
if($action=="Update" || $action=="Previous"){
	$action="Update"; 
	echo 'onsubmit="verifyme(this);"';
}
echo ' name="a">';
echo '<input type="hidden" name="question" value="'.$quesid.'">';
echo '<input type="hidden" name="examcode" value="'.$examcode.'">';
echo '<tr>';

  $a = mt_rand(1,2);
  if($a % 2 == 0){
  	$bb="2"; 
  	$aa="3";
  } else { 
  	$bb="3";
  	$aa="2"; 
  }
  $ac = " ";
  $bc = " ";
  $ad = " background-color: #ffffff; ";
  $bd = " background-color: #ffffff; ";
if($res = mysql_query("select QID from ExamAnswers where QID=".$quesid." and EID='".$examcode."' and ANS='".$r[$aa]."'")){
	$num = mysql_num_rows($res);
	if($num==1){	
		$ac = " checked ";
		$ad = " background-color: #33aa33; ";
	}
}  
echo '<td style="border: 1px solid #008080; padding: 0" height="23" align="center">';
echo '<input type="radio" '.$ac.' value="'.$r[$aa].'" name="ans" id="ans1" onclick="a.answer.disabled=false;document.a.ansa.style.backgroundColor=\'#33aa33\';document.a.ansb.style.backgroundColor=\'#ffffff\';" style="width: 30; height: 30; color:#FFFF00; background-color:#ffffff">';
echo '<input type="button" value="'.$r[$aa].'" name="ansa" onclick="a.answer.disabled=false;a.ans1.checked=true;document.a.ansa.style.backgroundColor=\'#33aa33\';document.a.ansb.style.backgroundColor=\'#ffffff\';" style="color: #000000; font-family: Tahoma; font-size: 10pt; font-weight: bold; border: 1px solid #ffffff; '.$ad.' height:30; width=';
if(strlen($r[$aa])>35){
	echo strlen($r[$aa])*7;
}else{
	echo '350';
}
echo '"></td></tr>';
if($res = mysql_query("select QID from ExamAnswers where QID=".$quesid." and EID='".$examcode."' and ANS='".$r[$bb]."'")){
	$num = mysql_num_rows($res);
	if($num==1){	
		$bc = " checked ";
		$bd = " background-color: #33aa33; ";
	}
} 
echo '<tr><td style="border: 1px solid #008080; padding: 0" height="23" align="center">';
echo '<input type="radio" '.$bc.' value="'.$r[$bb].'" name="ans" id="ans2" onclick="a.answer.disabled=false;document.a.ansb.style.backgroundColor=\'#33aa33\';document.a.ansa.style.backgroundColor=\'#ffffff\';" style="width: 30; height: 30; color:#FFFF00; background-color:#ffffff">';
echo '<input type="button" value="'.$r[$bb].'" name="ansb" onclick="a.answer.disabled=false;a.ans2.checked=true;document.a.ansb.style.backgroundColor=\'#33aa33\';document.a.ansa.style.backgroundColor=\'#ffffff\';" style="color: #000000; font-family: Tahoma; font-size: 10pt; font-weight: bold; border: 1px solid #ffffff; '.$bd.' height:30; width=';
if(strlen($r[$bb])>35){
	echo strlen($r[$bb])*7;
}else{
	echo '350';
}
echo '"></td>';
echo '</tr><tr>';
echo '<td align="center" height="26">
<input type="submit" value="'.$action.'" onlick="this.submit();this.disabled=true;" name="answer" disabled style="width: 300; height: 40; font-family: Tahoma; font-size: 14pt; font-weight: bold"></td>';
echo '</tr></form>';
if(isset($lastnum)){
	echo '<tr><form method="post" action="'.$PHP_SELF.'">';
	echo '<input type="hidden" name="quesid" value="'.$lastnum.'"><input type="hidden" name="examcode" value="'.$examcode.'">';
	echo '<td align="center">';
	echo '<input type="submit" name="acttion" value="Previous"></td>';
	echo '</form>';
	echo '</tr>';
}
echo '<tr>';
echo '<td align="center" valign="top">';
echo '<p align="center" style="font-family: Tahoma; font-size: 2mm; font-weight: normal">';
$r=0;
for($i=1;$i<=$mib;$i++){
if($res = mysql_query("select QID from ExamAnswers where QID=".$i." and EID='".$examcode."'")){
	$num = mysql_num_rows($res);
	if($num==1){	
		echo '<a href="'.$PHP_SELF.'?quesid='.$i.'&examcode='.$examcode.'" class="dn">&nbsp;'.$i.'&nbsp;</a>';
	}else{
		echo '<a href="'.$PHP_SELF.'?quesid='.$i.'&examcode='.$examcode.'&action=Save" class="ud">&nbsp;'.$i.'&nbsp;</a>';
	}
} else {
	echo '<a href="'.$PHP_SELF.'?quesid='.$i.'&examcode='.$examcode.'&action=Save" class="ud">&nbsp;'.$i.'&nbsp;</a>';
}
$h=strlen($i)+4;
$r+=$h;
	if($r>=160){
		echo '<br>';
		$r=0;
	}
} 
echo '</p><p align="center" style="font-family: Tahoma; font-size: 8pt; font-weight: normal">Legend: <a href="#" class="dn">&nbsp;&nbsp;&nbsp;&nbsp;</a>Answered&nbsp&nbsp;<a href="#" class="ud">&nbsp;&nbsp;&nbsp;&nbsp;</a>UnAnswered</p></td></tr></table>';
#echo '</td><tr><td align="center" style="font-family: Tahoma; size=1; color=#336699; font-size:2mm; font-weight:bold">aoc</td></tr></table>';
echo '</center></div>';
echo '</body></html>';
}
?>
Return current item: E2Exam: LAMP for the Education