• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

cms/modules/quiz/quizview.php

Go to the documentation of this file.
00001 <?php
00002 if(!defined('__PRAGYAN_CMS'))
00003 { 
00004         header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
00005         echo "<h1>403 Forbidden<h1><h4>You are not authorized to access the page.</h4>";
00006         echo '<hr/>'.$_SERVER['SERVER_SIGNATURE'];
00007         exit(1);
00008 }
00009 /*
00010  * Created on Jan 17, 2009
00011  */
00012 
00019 function getQuestionTypeCounts($quizId, $sectionId) {
00020         $countQuery = "SELECT `quiz_questiontype`, COUNT(*) FROM `quiz_questions` WHERE `page_modulecomponentid` = $quizId AND `quiz_sectionid` = $sectionId GROUP BY `quiz_questiontype`";
00021         $countResult = mysql_query($countQuery);
00022         $result = array();
00023         while ($countRow = mysql_fetch_row($countResult))
00024                 $result[$countRow[0]] = $countRow[1];
00025         $questionTypes = array_keys(getQuestionTypes());
00026         for ($i = 0; $i < count($questionTypes); ++$i)
00027                 if (!array_key_exists($questionTypes[$i], $result))
00028                         $result[$questionTypes[$i]] = 0;
00029         return $result;
00030 }
00031 
00037 function checkQuizSetup($quizId) {
00038         $sectionList = getSectionList($quizId);
00039         if (count($sectionList) == 0)
00040                 return false;
00041 
00042         $questionTypes = array_keys(getQuestionTypes());
00043         for ($i = 0; $i < count($sectionList); ++$i) {
00044                 $questionCounts = getQuestionTypeCounts($quizId, $sectionList[$i]['quiz_sectionid']);
00045                 for ($j = 0; $j < count($questionTypes); ++$j)
00046                         if ($questionCounts[$questionTypes[$j]] < $sectionList[$i]['quiz_section' . $questionTypes[$j] . 'count'])
00047                                 return false;
00048         }
00049         return true;
00050 }
00051 
00056 function checkQuizOpen($quizId) {
00057         $quizQuery = "SELECT IF(NOW() < `quiz_startdatetime`, -1, IF(NOW() > `quiz_enddatetime`, 1, 0)) FROM `quiz_descriptions` WHERE `page_modulecomponentid` = $quizId";
00058         $quizResult = mysql_query($quizQuery);
00059         $quizRow = mysql_fetch_row($quizResult);
00060         if (!$quizRow) {
00061                 displayerror('Error. Could not find information about the given quiz.');
00062                 return 1;
00063         }
00064         return $quizRow[0];
00065 }
00066 
00071 function checkUserFirstAttempt($quizId, $userId) {
00072         $attemptQuery = "SELECT COUNT(*) FROM `quiz_userattempts` WHERE `page_modulecomponentid` = $quizId AND `user_id` = $userId";
00073         $attemptResult = mysql_query($attemptQuery);
00074         $attemptRow = mysql_fetch_row($attemptResult);
00075         return $attemptRow[0] == 0;
00076 }
00077 
00082 function sectionBelongsToQuiz($quizId, $sectionId) {
00083         $sectionQuery = "SELECT COUNT(*) FROM `quiz_sections` WHERE `page_modulecomponentid` = $quizId AND `quiz_sectionid` = $sectionId";
00084         $sectionResult = mysql_query($sectionQuery);
00085         $sectionRow = mysql_fetch_row($sectionResult);
00086         return $sectionRow[0] == 1;
00087 }
00088 
00093 function startSection($quizId, $sectionId, $userId) {
00094         $attemptQuery = "INSERT INTO `quiz_userattempts`(`page_modulecomponentid`, `quiz_sectionid`, `user_id`, `quiz_attemptstarttime`) VALUES " .
00095                         "($quizId, $sectionId, $userId, NOW())";
00096         if (!mysql_query($attemptQuery)) {
00097                 displayerror('Database Error. Could not mark section as started.');
00098                 return false;
00099         }
00100         return true;
00101 }
00102 
00107 function getFirstSectionId($quizId) {
00108         $sectionQuery = "SELECT MIN(`quiz_sectionid`) FROM `quiz_sections` WHERE `page_modulecomponentid` = $quizId";
00109         $sectionResult = mysql_query($sectionQuery);
00110         if (!$sectionResult)
00111                 return -1;
00112         $sectionRow = mysql_fetch_row($sectionResult);
00113         return $sectionRow[0];
00114 }
00115 
00120 function getAttemptRow($quizId, $sectionId, $userId) {
00121         $attemptQuery = "SELECT * FROM `quiz_userattempts` WHERE `page_modulecomponentid` = $quizId AND `quiz_sectionid` = $sectionId AND `user_id` = $userId";
00122         $attemptResult = mysql_query($attemptQuery);
00123         return mysql_fetch_assoc($attemptResult);
00124 }

Generated on Mon Mar 14 2011 05:35:30 for Pragyan CMS by  doxygen 1.7.1