Location: PHPKode > projects > Nukequiz > html/modules/Nukequiz/public/NQPQuestions.php
<?php
/*****************************************************************/
/* Nukequiz (tm)    v 3.1.0                                		 */
/* By: Kissoftware (hide@address.com)      		     */
/* http://www.kissoftware.org.uk                           		 */
/* http://www.kissoftware.co.uk                       		     */
/* Copyright © 2003-2008 by Kissoftware         				 */
/* See Docs For Information & Credits                 			 */
/* For More information Visit Forums Or The Online Help Manual	 */
/*****************************************************************/
$pagetitle = _NQ_NUKEQUIZ.' - '.$nquiztitle;
include('header.php');
logoheader();
if($submitted == '1'){
set_time_limit(0);
setcookie("time_online_TT", '', time() -120);
setcookie("time_online_TO", '', time() -120);
setcookie("time_online_ST", '', time() -120);
}
else {
include ("NQPQuizTime.php");
$test = new time_online;
OpenTable();
echo "<center><font class='Time'>";
$test -> display_time("total_time");
echo "</center></font>";
echo "<Script>window.history.forward(2);</Script>";
CloseTable();
}
$qset = $db->sql_query("SELECT * FROM ".$prefix."_nquiz_quiz WHERE qid='$qid'");
$qset = mysql_fetch_array($qset);
$euser = $qset['emailuser'];
$eadmin = $qset['emailadmin'];
echo "<form name='qs' action='modules.php?name=$module_name&amp;id=$qid' method='post'>";
echo "<input type='hidden' name='submitted' value='1'>";
echo "<input type='hidden' name='op' value='id'>";
echo "<input type='hidden' name='sid' value='$sid'>";
echo "<input type='hidden' name='qid' value='$qid'>";
echo "<input type='hidden' name='sbid' value='$sbid'>";
echo "<input type='hidden' name='logname' value='$logname'>";
echo "<input type='hidden' name='adrs' value='$adrs'>";
echo "<input type='hidden' name='email' value='$email'>";
echo "<input type='hidden' name='starttime' value='$starttime'>";
if($qset['random']=='0') $ordering = "ORDER BY quesid ASC";
if($qset['random']=='1') $ordering = "ORDER BY question ASC";
if($qset['random']=='2') $ordering = "ORDER BY rand()";
$question = $db->sql_query("SELECT * FROM ".$prefix."_nquiz_questions WHERE qid='$qid' $ordering");
if($submitted == '1'){
$submitvalue = "disabled='disabled'";
}
$i = 0;
$j = 1;
while($thequestion = mysql_fetch_array($question) ){
if($qset['maxqnum'] != 0 && $j-1 == $qset['maxqnum']){
break;
}
$i = $thequestion['quesid'];
$db->sql_query("UPDATE ".$prefix."_nquiz_questions SET hit_count=hit_count+1 WHERE quesid='$i'");
$type = "N/A";
if( $thequestion['ismcq'] == 1 ){
if( $thequestion['ismultiple'] == 1 ){$type = ""._NQMULANS."";
}else{$type = ""._NQ_SINGANS.""; }
}else{$type = ""._NQ_SANS.""; }
OpenTable();
echo "<center><table width='100%' cellpadding='2' cellspacing='2' border='0' align='center'>";
$o_question = nl2br($thequestion['question']);
$quesfile = $thequestion['file'];
$qexplain = $thequestion['qexplain'];
$points = $thequestion['points'];
$dir = $qset['dir'];
$imagesdir = $nq_config['images_directory'];
if (substr($quesfile,-4) == ".mid" || substr($quesfile,-4) == ".mp3" || substr($quesfile,-4) == ".wav"){
soundwin();
$myquizimage = myquizimage("playsound.png");
echo "<td colspan='2' align='center'><a href=\"modules.php?name=$module_name&amp;op=soundbar&amp;ftitle=$dir&amp;quesfile=$quesfile\" Onclick=\"sounddisp(this.href,'','400','350','yes');return false;\"><img src=\"$myquizimage\" title=\""._NQ_PLAYSOUNDWIN."\" onMouseOver=\"self.status='"._NQ_PLAYSOUNDWIN." ';return true\" onmouseout=\"self.status='';return true\"alt=\""._NQ_PLAYSOUNDWIN."\"></a></td></tr><tr>";
}
elseif ($quesfile != ""._NQ_NONE."")
{
imagewin();
echo "<td colspan='2' align='center'><a href=\"modules.php?name=$module_name&amp;op=viewimage&amp;ftitle=$dir&amp;quesfile=$quesfile\" Onclick=\"imagedisp(this.href,'','400','350','yes');return false;\"><img src=\"modules/$module_name/$imagesdir/$dir/thumbs/th_$quesfile\" title=\""._NQ_ENLARGEIMGWIN."\" onMouseOver=\"self.status='"._NQ_ENLARGEIMGWIN." ';return true\" onmouseout=\"self.status='';return true\"alt=\""._NQ_ENLARGEIMGWIN."\"></a></td></tr><tr>";
}
else{
}
if ($nq_config['user_help'] == '1') {echo "<tr><td align='center' colspan='2'>(&nbsp;$type&nbsp;)<br></td></tr>";}
echo "<tr><td align='left' colspan='2'><b>"._NQ_QUESTION."&nbsp;$j.</b>&nbsp;&nbsp;";
$quespoints = $thequestion['points'];
if ($quespoints =='1'){
echo "(&nbsp;$quespoints&nbsp;"._NQ_PT."&nbsp;)</td></tr>";
}
else {
echo "(&nbsp;$quespoints&nbsp;"._NQ_PTS."&nbsp;)</td></tr>";
}
echo "<tr><td align='left' colspan='2'>$o_question</td></tr><tr>";
if($thequestion['ismcq'] == 1 ){
if($thequestion['ismultiple'] == 1 ){
$theFormat = 'checked="checked"';
$mcq1 = ""; $mcq2 = ""; $mcq3 = ""; $mcq4 = "";
if($_POST["qns1$i"] == 1){$mcq1 = $theFormat;}
if($_POST["qns2$i"] == 2){$mcq2 = $theFormat;}
if($_POST["qns3$i"] == 3){$mcq3 = $theFormat;}
if($_POST["qns4$i"] == 4){$mcq4 = $theFormat;}
for ($z=1; $z <= 4; $z++) {																				
echo "<td align='center' width='32'><input type='checkbox' name='qns$z$i' value='$z' $mcq.$z $submitvalue></td><td align='left' width='100%'>".$thequestion['sol'.$z]."</td></tr><tr>";
}
if($submitted == 1){$mcqAns = "";
if($_POST["qns1$i"] == 1){$mcqAns = $mcqAns."1";}
if($_POST["qns2$i"] == 2){$mcqAns = $mcqAns."2";}
if($_POST["qns3$i"] == 3){$mcqAns = $mcqAns."3";}
if($_POST["qns4$i"] == 4){$mcqAns = $mcqAns."4";}
if($mcqAns == $thequestion['answer']){
if($qset['view_answers'] == '1'){
$report .= "<b>"._NQ_QUESTIONNO."&nbsp;$j</b>&nbsp;&radic;&nbsp;<br><br>";
q_right();
}
$score= $score + $points;
$qcorrect .= " $j";
}
else{
if($qset['view_answers'] == '1'){
$therightquestions = preg_split('//', $thequestion['answer'], -1, PREG_SPLIT_NO_EMPTY);
$r = 0;
q_wrong();
echo "<td align='left' colspan='2'><b>"._NQ_RANSWER."&nbsp;:&nbsp;</b>";
while($r < count($therightquestions)){
$z = $therightquestions[$r]." ";
$result = $db->sql_query("SELECT sol$z FROM ".$prefix."_nquiz_questions WHERE quesid='$i'");
list($sol) = $db->sql_fetchrow($result);
$r++;
echo " $sol ";
}
echo "</td></tr><td align='left' colspan='2'><b>"._NQ_EXPLAINED.":</b>&nbsp;$qexplain</td></tr><tr>";
$report .= "<b>"._NQ_QUESTIONNO."&nbsp;$j</b>&nbsp;&times;&nbsp;<br>".$thequestion['question']."<br>"._NQ_RANSWER.":&nbsp;$sol<br>"._NQ_EXPLAINED.":&nbsp;".$thequestion['qexplain']."<br><br>";
$qwrong .= " $j";
	}
}
}
}
else{
$theFormat = 'checked="checked"';
$mcq1 = ""; $mcq2 = ""; $mcq3 = ""; $mcq4 = "";
if( isset($_POST["qn$i"])){
switch ($_POST["qn$i"]){
case 1:
$mcq1 = $theFormat;
break;
case 2:
$mcq2 = $theFormat;
break;
case 3:
$mcq3 = $theFormat;
break;
case 4:
$mcq4 = $theFormat;
break;
}
}
for ($z=1; $z <= 4; $z++) {
echo "<td align='center' width='32'><input type='radio' name='qn$i' value='$z' $mcq.$z $submitvalue></td><td align='left' width='100%'>".$thequestion['sol'.$z]."</td></tr><tr>";
}
if($submitted == 1){
$mcqAns = substr($thequestion['answer'],0,1);
if($_POST["qn$i"] == $mcqAns){
if($qset['view_answers'] == '1'){
$report .= "<b>"._NQ_QUESTIONNO."&nbsp;$j</b>&nbsp;&radic;&nbsp;<br><br>";
q_right();
}
$score= $score + $points;
$qcorrect .= " $j";
}
else{
if($qset['view_answers'] == 1){
q_wrong();
$c=$thequestion['answer'];
$result = $db->sql_query("SELECT sol$c FROM ".$prefix."_nquiz_questions WHERE quesid='$i'");
list($sol) = $db->sql_fetchrow($result);
echo "<td align='left' colspan='2'><b>"._NQ_RANSWER."&nbsp;:&nbsp;</b>$sol</td></tr><td align='left' colspan='2'><b>"._NQ_EXPLAINED.":</b>&nbsp;$qexplain</td></tr><tr>";
$report .= "<b>"._NQ_QUESTIONNO."&nbsp;$j</b>&nbsp;&times;&nbsp;<br>".$thequestion['question']."<br>"._NQ_RANSWER.":&nbsp;$sol<br>"._NQ_EXPLAINED.":&nbsp;".$thequestion['qexplain']."<br><br>";
$qwrong .=  " $j";
			}
		}
	}
}
}
else{
$sa = "";
if($_POST["qn$i"] != ""){$sa = $_POST["qn$i"];}
echo "<td align='left' colspan='2'><input type='text' name='qn$i' value='$sa' size='60' maxlength='60' $submitvalue></td></tr><tr>";
if($submitted == 1){$saAns = strtolower($_POST["qn$i"]);
$saAns = ucwords($saAns);        
$saAns = ucwords(strtolower($saAns));
$check1 = 0;
$check2 = 0;
$check3 = 0;
$check4 = 0;
if($thequestion['sol1'] != "" && substr_count($saAns,$thequestion['sol1']) >= 1){$check1 = 1;}
if($thequestion['sol2'] != "" && substr_count($saAns,$thequestion['sol2']) >= 1){$check2 = 1;}
if($thequestion['sol3'] != "" && substr_count($saAns,$thequestion['sol3']) >= 1){$check3 = 1;}
if($thequestion['sol4'] != "" && substr_count($saAns,$thequestion['sol4']) >= 1){$check4 = 1;}
if($thequestion['isoe'] == 1){
if($check1==1||$check2==1||$check3==1||$check4==1){
if($qset['view_answers'] == '1'){
$report .= "<b>"._NQ_QUESTIONNO."&nbsp;$j</b>&nbsp;&radic;&nbsp;<br><br>";
q_right();
}
$score= $score + $points;
$qcorrect .= " $j";
}
else if(intval($qset['view_answers']) == '1'){
$qwrong .= " $j";
q_wrong();
echo "<td align='left' colspan='2'><b>"._NQ_RANSWER."&nbsp;:&nbsp;</b>".$thequestion['sol1']."</td></tr><td align='left' colspan='2'><b>"._NQ_EXPLAINED.":</b>&nbsp;$qexplain</td></tr><tr>";
$report .= "<b>"._NQ_QUESTIONNO."&nbsp;$j</b>&nbsp;&times;&nbsp;<br>".$thequestion['question']."<br>"._NQ_RANSWER.":&nbsp;".$thequestion['sol1']."<br>"._NQ_EXPLAINED.":&nbsp;".$thequestion['qexplain']."<br><br>";
}
}
else{
$varChk = 1;
if($thequestion['sol1'] != "" && $check1 != 1){$varChk = 0;}
if($thequestion['sol2'] != "" && $check2 != 1){$varChk = 0;}
if($thequestion['sol3'] != "" && $check3 != 1){$varChk = 0;}
if($thequestion['sol4'] != "" && $check4 != 1){$varChk = 0;}
if( $varChk == 1 ){
if($qset['view_answers'] == 1){
$report .= "<b>"._NQ_QUESTIONNO."&nbsp;$j</b>&nbsp;&radic;&nbsp;<br><br>";
q_right();
}
$score= $score + $points;
$qcorrect .= " $j";
}
else if($qset['view_answers'] == 1){
q_wrong();
$qwrong .= " $j";
echo "<b>"._NQ_RANSWER."&nbsp;:&nbsp;</b>$j<br><b>"._NQ_EXPLAINED.":</b>&nbsp;$qexplain<br>";
$report .= "<b>"._NQ_QUESTIONNO."&nbsp;$j</b>&nbsp;&times;&nbsp;<br>".$thequestion['question']."<br>"._NQ_RANSWER.":&nbsp;".$thequestion['answer']."<br>"._NQ_EXPLAINED.":&nbsp;".$thequestion['qexplain']."<br><br>";
		}
	}
}
}
echo "</tr></table></center>";
CloseTable();
$j++;
}
if($submitted == 1){
$db->sql_query("UPDATE ".$prefix."_nquiz_quiz SET hit_count=hit_count+1 WHERE qid='$qid'");
if (!$score > '0'){$score ='0';}
$resultx = $db->sql_query("SELECT points_total FROM ".$prefix."_nquiz_quiz WHERE qid='$qid'");
list($totpoints) = $db->sql_fetchrow($resultx);
$cal = ($score/$totpoints);
$perc  =  round($cal*100,2 );
OpenTable();
echo "<br><center><b>"._NQ_URSCORE."</b><br><br>$score&nbsp;/&nbsp;$totpoints&nbsp;<b>"._NQ_PTS."</b>&nbsp;(&nbsp;$perc%&nbsp;)<br>";
$endtime=time();
$seconds=$endtime-$starttime;
if ($seconds > 0) {
$mins = floor( $seconds / ( int )60 );
$secs = $seconds - ($mins *60);
$hrs = floor( $mins / ( int )60 );
}
if ($secs <=9){
$secs="0$secs";
}
if ($mins <=9){
$mins="0$mins";
}
if ($hrs <=9){
$hrs="0$hrs";
}
$ttime="$hrs:$mins:$secs";
$reported .= "<b>"._NQ_TTAKEN."<br></b>$hrs&nbsp;:&nbsp;$mins&nbsp;:&nbsp;$secs<br><br>(&nbsp;"._NQ_HRS."&nbsp;:&nbsp;"._NQ_MINS."&nbsp;:&nbsp;"._NQ_SECS."&nbsp;)<br>";
echo "<br><center>"._NQ_UCOMPLETEDQT."<br><br>$hrs&nbsp;<b>"._NQ_HRS."</b>&nbsp;$mins&nbsp;<b>"._NQ_MINS."</b>&nbsp;$secs&nbsp;<b>"._NQ_SECS."</b><br><br>";
$db->sql_query("UPDATE ".$prefix."_nquiz_scoreboard SET  endtime='$endtime',  score='$score', perc='$perc', qcorrect='$qcorrect', qwrong='$qwrong', ttime='$ttime' WHERE sbid='$sbid' AND username='$logname'");
$add = $nq_config['userpoints'];
$nukepoints = intval($nq_config['nukepoints']);
if ($nukepoints == '1'){
$db->sql_query("UPDATE ".$prefix."_users SET points=points+$add WHERE username='$logname'");
}
$nukepoints = $nq_config['points'];
if ($nukepoints == '2'){
$db->sql_query("UPDATE ".$prefix."_users SET points=points+$score WHERE username='$logname'");
}
$title = $qset['title'];
$emailtemplate = $nq_config['templates'];
$reply = $nq_config['reply_email'];
if (intval($eadmin) == '1'){
$admin_addmail = $qset['admin_email'];
$subject = ""._NQ_USERRESULTS." : $title";
$from  = "FROM:$sitename<$reply>\nContent-Type: text/html; charset=iso-8859-1\r\n";
include_once("modules/$module_name/templates/$emailtemplate/t_2.php");
mail($admin_addmail, $subject, $emailbody, $from);
}
if (intval($euser) == '1'){
$subject = ""._NQ_SUBMITTEDQUIZ.": $title";
$from  = "FROM:$sitename<$reply>\nContent-Type: text/html; charset=iso-8859-1\r\n";
include_once("modules/$module_name/templates/$emailtemplate/t_1.php");
mail($adrs, $subject, $emailbody, $from);
echo "<br><center><b>"._NQ_YOURRESULTSEMAIL."</b><br>$adrs<br>";
}
echo "<br>[&nbsp;<a href='modules.php?name=$module_name'>"._NQ_QUIZINDEX."</a>&nbsp;]<br><br></center>";
CloseTable();
}
else {
OpenTable();
echo "<center><br><table cellpadding='2' cellspacing='2' border='0'><tr><td align='center'>";
echo "<input type='submit' onClick=\"this.disabled=true;submit()\" value='&raquo;&nbsp;"._NQ_FINISH."&nbsp;&laquo;'></td></tr></table><br>";
CloseTable();
echo "</form>";
}
include('footer.php');
?>
Return current item: Nukequiz