* (page_modulecomponentid, quiz_sectionid, quiz_userid) * page_modulecomponentid, quiz_sectionid, user_id, quiz_attemptstarttime, quiz_submissiontime, quiz_marksallotted * * quiz_answersubmissions: A Record of each question submitted for each quiz for each user, identified by * (page_modulecomponentid, quiz_section, quiz_questionid, quiz_userid) * page_modulecomponentid, quiz_sectionid, quiz_questionid, user_id, quiz_questionrank, quiz_submittedanswer, * quiz_questionviewtime, quiz_answersubmittime, quiz_marksallotted */ /** * Including parts of quiz module */ require_once 'quiz/quizedit.php'; require_once 'quiz/quizview.php'; require_once 'quiz/quizcorrect.php'; require_once 'quiz/iquiz.php'; $quizTypes = getQuizTypes(); for ($i = 0; $i < count($quizTypes); ++$i) { require_once 'quiz/' . $quizTypes[$i] . 'quiz.php'; } class quiz implements module { private $moduleComponentId; private $userId; private $action; /** * function getHtml: * Gateway through which CMS interacts with module * This function will be called from getContent function of cms/content.lib.php */ public function getHtml($userId, $moduleComponentId, $action) {
/** * function getQuizEditForm: * returns the HTML interface to edit the quiz, * which includes editing quiz properties, setting weight marks, editing sections, and adding questions to sections * and gives link to editing questions */ function getQuizEditForm($quizId, $dataSource) { $fieldMap = getQuizEditFormFieldMap(); if ($dataSource == 'POST') { for ($i = 0; $i < count($fieldMap); ++$i) { if ($fieldMap[$i][3] == 'chk') { ${$fieldMap}[$i][2] = isset($_POST[$fieldMap[$i][0]]) ? 'checked="checked"' : ''; } else { ${$fieldMap}[$i][2] = isset($_POST[$fieldMap[$i][0]]) ? htmlentities(safe_html($_POST[$fieldMap[$i][0]])) : ''; } } } elseif ($dataSource == 'db') { $quizRow = getQuizRow($quizId); if (!$quizRow) { displayerror('Could not retrieve information about the specified quiz. Quiz not found.'); return ''; } for ($i = 0; $i < count($fieldMap); ++$i) { if ($fieldMap[$i][3] == 'checkbox') { ${$fieldMap}[$i][2] = isset($quizRow[$fieldMap[$i][1]]) && $quizRow[$fieldMap[$i][1]] != 0 ? 'checked="checked"' : ''; } else { ${$fieldMap}[$i][2] = isset($quizRow[$fieldMap[$i][1]]) ? htmlentities($quizRow[$fieldMap[$i][1]]) : ''; } } } $quizTypeBox = getQuizTypeBox($quiz_quiztype); $setWeightMarks = weightMarksForm($quizId); global $moduleFolder, $cmsFolder, $urlRequestRoot; $calpath = "{$urlRequestRoot}/{$cmsFolder}/{$moduleFolder}"; $quizEditForm = <<<QUIZEDITFORM \t<link rel="stylesheet" type="text/css" media="all" href="{$calpath}/form/calendar/calendar.css" title="Aqua" /> \t<script type="text/javascript" src="{$calpath}/form/calendar/calendar.js"></script> \t<form name="quizpropertiesform" action="./+edit" method="POST"> \t\t<h3>Quiz Properties</h3> \t\t<fieldset style="padding:8px"> \t\t\t<legend>General Properties</legend> \t\t\t<table border="0"> \t\t\t\t<tr><td><label for="txtTitle">Quiz Title:</label></td><td><input type="text" name="txtTitle" id="txtTitle" value="{$quiz_quiztitle}" /></td></tr> \t\t\t\t<tr><td><label for="txtHeaderText">Header Text:</label></td><td><textarea rows="5" cols="30" id="txtHeaderText" name="txtHeaderText">{$quiz_headertext}</textarea></td></tr> \t\t\t\t<tr><td><label for="txtSubmitText">Submit Text:</label></td><td><textarea rows="5" cols="30" id="txtSubmitText" name="txtSubmitText">{$quiz_submittext}</textarea></td></tr> \t\t\t\t<tr><td><label for="selQuizType">Quiz Type:</label></td><td>{$quizTypeBox}</td></tr> \t\t\t\t<tr><td><label for="txtDuration">Quiz Duration (HH:MM):</label></td><td><input type="text" name="txtDuration" id="txtDuration" value="{$quiz_testduration}" /></td></tr> \t\t\t\t<tr><td><label for="txtQuestionCount">Questions Per Test:</label></td><td><input type="text" name="txtQuestionCount" id="txtQuestionCount" value="{$quiz_questionspertest}" /></td></tr> \t\t\t\t<tr><td><label for="txtQuestionsPerPage">Questions Per Page:</label></td><td><input type="text" name="txtQuestionsPerPage" id="txtQuestionsPerPage" value="{$quiz_questionsperpage}" /></td></tr> \t\t\t\t<tr><td>Show Timers:</td><td><label><input type="checkbox" name="chkShowTimerPerTest" id="chkShowTimerPerTest" value="pertest" {$quiz_showtesttimer} /> Per Test</label> <label><input type="checkbox" name="chkShowTimerPerPage" id="chkShowTimerPerPage" value="perpage" {$quiz_showpagetimer} /> Per Page</label></td></tr> \t\t\t\t<tr><td><label>Allow Random Access to Sections?</label></td><td><label><input type="checkbox" id="chkSectionRandomAccess" name="chkSectionRandomAccess" {$quiz_sectionrandomaccess} /> Yes</label></td></tr> \t\t\t\t<tr><td><label>Mix Sections?</label></td><td><label><input type="checkbox" name="chkMixSections" id="chkMixSections" value="mixsections" {$quiz_mixsections} /> Yes</label></td></tr> \t\t\t\t<tr><td><label for="txtOpenTime">Opening Time:</label></td><td><input type="text" name="txtOpenTime" id="txtOpenTime" value="{$quiz_startdatetime}" /><input name="calc" type="reset" value=" ... " onclick="return showCalendar('txtOpenTime', '%Y-%m-%d %H:%M:%S', '24', true);" /></td></tr> \t\t\t\t<tr><td><label for="txtCloseTime">Closing Time:</label></td><td><input type="text" name="txtCloseTime" id="txtCloseTime" value="{$quiz_closedatetime}" /><input name="calc" type="reset" value=" ... " onclick="return showCalendar('txtCloseTime', '%Y-%m-%d %H:%M:%S', '24', true);" /></td></tr> \t\t\t</table> \t\t</fieldset> \t\t \t\t<fieldset id="quizWeightMarks"> \t\t<legend>Weight - Marks</legend> \t\t{$setWeightMarks} \t\t</fieldset> \t\t \t\t<fieldset style="padding:8px" id="quizTypeSpecificProperties"> \t\t\t<legend>Quiz Type Specific Properties</legend> QUIZEDITFORM; $quizTypes = getQuizTypes(); for ($i = 0; $i < count($quizTypes); ++$i) { $quizObjectClassName = ucfirst($quizTypes[$i]) . 'Quiz'; $quizObject = new $quizObjectClassName($quizId); $quizEditForm .= "<div id=\"{$quizTypes[$i]}QuizProperties\">" . $quizObject->getPropertiesForm($dataSource) . "</div>\n"; } $quizEditForm .= <<<QUIZEDITFORM \t\t</fieldset> \t\t<script type="text/javascript"> \t\t\tfunction quizTypeChanged(e) { \t\t\t\tvar selQuizType = document.getElementById('selQuizType'); \t\t\t\tvar showId = selQuizType.value + 'QuizProperties'; \t\t\t\tvar options = selQuizType.getElementsByTagName('option'); \t\t\t\tfor (var i = 0; i < options.length; ++i) { \t\t\t\t\tvar curId = options[i].value + 'QuizProperties'; \t\t\t\t\tdocument.getElementById(curId).style.display = (curId == showId ? '' : 'none'); \t\t\t\t} \t\t\t} \t\t\tfunction validateAddQuestions(form) { \t\t\t\tvar questionCount = form.txtQuestionCount.value; \t\t\t\tif (!/^\\d+\$/.test(questionCount)) { \t\t\t\t\talert('Please enter the number of questions to add.'); \t\t\t\t\treturn false; \t\t\t\t} \t\t\t\tquestionCount = parseInt(sectionCount); \t\t\t\tif (questionCount <= 0) { \t\t\t\t\talert('Please enter a positive number of questions to add.'); \t\t\t\t\treturn false; \t\t\t\t} \t\t\t\tif (questionCount > 100) \t\t\t\t\tif (!confirm('You are about to add ' + questionCount + ' questions. Are you sure you wish to do this?')) \t\t\t\t\t\treturn false; \t\t\t\treturn true; \t\t\t} \t\t\tfunction validateAddSections() { \t\t\t\tvar sectionCount = document.getElementById('txtSectionCount').value; \t\t\t\tif (!/^\\d+\$/.test(sectionCount)) { \t\t\t\t\talert('Please enter the number of sections to add.'); \t\t\t\t\treturn false; \t\t\t\t} \t\t\t\tsectionCount = parseInt(sectionCount); \t\t\t\tif (sectionCount <= 0) { \t\t\t\t\talert('Please enter a positive number of sections to add.'); \t\t\t\t\treturn false; \t\t\t\t} \t\t\t\tif (sectionCount > 100) \t\t\t\t\tif (!confirm('You are about to add ' + sectionCount + ' sections. Are you sure you wish to do this?')) \t\t\t\t\t\treturn false; \t\t\t\treturn true; \t\t\t} \t\t\tdocument.getElementById('selQuizType').onchange = quizTypeChanged; \t\t\tquizTypeChanged(null); \t\t</script> \t\t<br /> \t\t<input type="submit" name="btnSubmit" value="Submit" /> \t</form> \t<hr /> \t<fieldset style="padding:8px"> \t\t<legend>Sections</legend> QUIZEDITFORM; global $urlRequestRoot, $sourceFolder, $templateFolder, $cmsFolder; $editImage = "<img style=\"padding:0px\" src=\"{$urlRequestRoot}/{$cmsFolder}/{$templateFolder}/common/icons/16x16/apps/accessories-text-editor.png\" alt=\"Edit\" />"; $deleteImage = "{$urlRequestRoot}/{$cmsFolder}/{$templateFolder}/common/icons/16x16/actions/edit-delete.png"; $moveUpImage = "<img src=\"{$urlRequestRoot}/{$cmsFolder}/{$templateFolder}/common/icons/16x16/actions/go-up.png\" alt=\"Move Section Up\" />"; $moveDownImage = "<img src=\"{$urlRequestRoot}/{$cmsFolder}/{$templateFolder}/common/icons/16x16/actions/go-down.png\" alt=\"Move Section Down\" />"; $quizSections = getSectionList($quizId); $questionTypes = getQuestionTypes(); $sectionCount = count($quizSections); for ($i = 0; $i < $sectionCount; ++$i) { $moveUp = $i == 0 ? '' : "<a href=\"./+edit&subaction=movesection&direction=up§ionid={$quizSections[$i]['quiz_sectionid']}\" />{$moveUpImage}</a>"; $moveDown = $i == $sectionCount - 1 ? '' : "<a href=\"./+edit&subaction=movesection&direction=down§ionid={$quizSections[$i]['quiz_sectionid']}\" />{$moveDownImage}</a>"; $stats = array(); foreach ($questionTypes as $questionTypeName => $questionTypeTitle) { $stats[] = $quizSections[$i]['quiz_section' . $questionTypeName . 'count'] . ' ' . $questionTypeTitle . ' question(s)'; } $stats = implode(', ', $stats) . ' to be chosen from this section.'; $timeLimit = $quizSections[$i]['quiz_sectiontimelimit'] == '00:00:00' ? 'No Time Limit' : $quizSections[$i]['quiz_sectiontimelimit']; $questionTable = getQuestionTableHtml($quizId, $quizSections[$i]['quiz_sectionid']); $quizEditForm .= <<<SECTIONTEXT \t\t\t<h3>Section: {$quizSections[$i]['quiz_sectiontitle']}</h3> \t\t\tOptions: \t\t\t\t<a href="./+edit&subaction=editsection§ionid={$quizSections[$i]['quiz_sectionid']}">{$editImage}</a> \t\t\t\t<form style="display:inline;" name="deletesectionform" method="POST" action="./+edit&subaction=deletesection" onsubmit="return confirm('You are about to delete a complete section. This will delete all questions that belong to that section. Are you sure you wish to proceed?')"> \t\t\t\t\t<input type="hidden" name="hdnSectionId" value="{$quizSections[$i]['quiz_sectionid']}" /> \t\t\t\t\t<input type="image" name="btnDelete" id="btnDelete" src="{$deleteImage}" /> \t\t\t\t</form> \t\t\t\t{$moveUp} \t\t\t\t{$moveDown} \t\t\t<p>{$stats}</p> \t\t\t<p>Time limit: {$timeLimit}</p> \t\t\t{$questionTable} \t\t\t<form name="questionaddform" action="./+edit&subaction=addquestions§ionid={$quizSections[$i]['quiz_sectionid']}" method="POST" onsubmit="return validateAddQuestions(this)"> \t\t\t\t<p>Add <input type="text" name="txtQuestionCount" value="1" size="3" /> Questions \t\t\t\t<input type="submit" name="btnAddQuestions" value="Go" /> \t\t\t</form> \t\t\t<p></p> \t\t\t<hr /> \t\t\t<br /> SECTIONTEXT; } $quizEditForm .= <<<QUIZEDITFORM \t<form name="sectionaddform" action="./+edit&subaction=addsections" method="POST" onsubmit="return validateAddSections()"> \t\t<p> \t\t\tAdd <input type="text" size="3" name="txtSectionCount" id="txtSectionCount" value="1" /> Section(s) \t\t\t<input type="submit" name="btnAddSections" id="btnAddSections" value="Go" /> \t\t</p> \t</fieldset> QUIZEDITFORM; return $quizEditForm; }