/** * function getQuizUserListHtml: * Generates the User list with their total, section specific marks */ function getQuizUserListHtml($quizId) { // Evaluate the quiz, // retrieve list of users and their total marks, and display $quizRow = getQuizRow($quizId); $weights = getWeights($quizId); if (count($weights) > 0) { displayerror("Marks for questions with weight " . join(", ", $weights) . " is not set. Correct the quiz after setting marks for all weigh. You can set that in <a href='./+edit#quizWeightMarks'>Edit</a>."); return ''; } if (isset($_POST['btnCalculateMarks'])) { evaluateQuiz($quizId); updateSectionMarks($quizId); } $tableJqueryStuff = ""; $numSecColumns = 0; $userTable = MYSQL_DATABASE_PREFIX . 'users'; $markQuery = "SELECT `{$userTable}`.`user_email` AS `email`, `{$userTable}`.`user_id` AS `user_id`, SUM(`quiz_marksallotted`) AS `total`, MIN(`quiz_attemptstarttime`) AS `starttime`, MAX(`quiz_submissiontime`) AS `finishtime`, TIMEDIFF(MAX(`quiz_submissiontime`), MIN(`quiz_attemptstarttime`)) AS `timetaken` FROM `{$userTable}`, `quiz_userattempts` WHERE " . "`{$userTable}`.`user_id` = `quiz_userattempts`.`user_id` AND " . "`quiz_userattempts`.`page_modulecomponentid` = '{$quizId}' " . "GROUP BY `quiz_userattempts`.`user_id` ORDER BY `total` DESC, `timetaken`, `starttime`, `finishtime`, `email`"; $profileQuery = 'SELECT `form_elementname` FROM `form_elementdesc` WHERE `page_modulecomponentid` = 0 ORDER BY `form_elementrank`'; $profileResult = mysql_query($profileQuery); $profilecolumns = array(); while ($profileRow = mysql_fetch_row($profileResult)) { $profilecolumns['form0_' . $profileRow[0]] = $profileRow[0]; } $markResult = mysql_query($markQuery); if (!$markResult) { displayerror($markQuery . ' ' . mysql_error()); } $query = mysql_fetch_array(mysql_query("SELECT `quiz_title` FROM `quiz_descriptions` WHERE `page_modulecomponentid` = '{$quizId}'")); $result = mysql_query("SELECT `quiz_sectiontitle` FROM `quiz_sections` WHERE `page_modulecomponentid` = '{$quizId}' ORDER BY `quiz_sectionid`"); $sectionHead = ""; $secCols = ""; $toggleColumns = "<tr><td><input type='checkbox' onclick='fnShowHide(0);' checked />User Full Name<br/></td>"; $toggleColumns .= "<td><input type='checkbox' onclick='fnShowHide(1);' />User Email<br/></td>"; $toggleColumns .= "<td><input type='checkbox' onclick='fnShowHide(2);' checked />Marks<br/></td>"; $toggleColumns .= "<td><input type='checkbox' onclick='fnShowHide(3);' checked />Time Taken<br/></td>"; $toggleColumns .= "<td><input type='checkbox' onclick='fnShowHide(4);' />Started<br/></td>"; $toggleColumns .= "<td><input type='checkbox' onclick='fnShowHide(5);' />Finished<br/></td>"; $c = 6; while ($row = mysql_fetch_array($result)) { $sectionHead .= "<th>Section : {$row['quiz_sectiontitle']}</th>"; $tableJqueryStuff .= "null,"; if ($c % 6 == 0) { $secCols .= "</tr><tr>"; } $secCols .= "<td><input type='checkbox' onclick='fnShowHide({$c});' checked />Section : {$row['quiz_sectiontitle']}<br/></td>"; $numSecColumns++; $c++; } $toggleColumns .= $secCols; $columnNames = array(); foreach ($profilecolumns as $columnName => $columnTitle) { $sectionHead .= "<th>{$columnTitle}</th>\n"; $columnNames[] = $columnName; $checked = "checked"; if (!($columnName == "useremail" || $columnName == "registrationdate" || $columnName == "lastupdated")) { $tableJqueryStuff .= "/* {$columnTitle} */ { \"bVisible\": false },"; $checked = ""; } else { $tableJqueryStuff .= "null,"; } if ($c % 6 == 0) { $toggleColumns .= "</tr><tr>"; } $toggleColumns .= "<td><input type='checkbox' onclick='fnShowHide({$c});' {$checked} />{$columnTitle} <br/></td>"; $c = $c + 1; } $toggleColumns .= "</tr>"; global $urlRequestRoot, $cmsFolder, $STARTSCRIPTS; $tableJqueryStuff = <<<STUFF \t\t\t\t\t\t\tnull, \t\t\t\t\t\t\t{ "bVisible": false }, \t\t\t\t\t\t\tnull, \t\t\t\t\t\t\tnull, \t\t\t\t\t\t\t{ "bVisible": false }, \t\t\t\t\t\t\t{ "bVisible": false }, \t\t\t\t\t\t\t{$tableJqueryStuff} \t\t\t\t\t\t\tnull STUFF; $smarttable = smarttable::render(array('userstable'), array('userstable' => array('aoColumns' => "{$tableJqueryStuff}"))); $STARTSCRIPTS .= "initSmartTable();"; $userListHtml = <<<HEAD \t{$smarttable} \t<script type="text/javascript" charset="utf-8"> \t\t\tfunction fnShowHide( iCol ) \t\t\t{ \t\t\t\tvar bVis = oTable.fnSettings().aoColumns[iCol].bVisible; \t\t\t\toTable.fnSetColumnVis( iCol, bVis ? false : true ); \t\t\t} \t</script> HEAD; global $ICONS_SRC, $ICONS; $quizName = $query[0]; $userListHtml .= "<h3>User Submissions for Quiz: {$query[0]}</h3>\n\t\t<fieldset><legend>Select Columns</legend><table>{$toggleColumns}</table></fieldset>" . "<form action='./+correct' method=POST><input type='submit' value='Calculate Marks' name='btnCalculateMarks' />\n\t\t<form action='./+correct' method=POST><input type='submit' value='Save As Excel' name='save_as_excel' /></form>"; $userListTable = "\n\t\t<table class=\"userlisttable display\" border=\"1\" id='userstable'>" . "<thead><tr><th>User Full Name</th><th>User Email</th><th>Total Marks</th><th>Time Taken</th><th>Started</th><th>Finished</th>{$sectionHead}<th>Action</th></tr></thead><tbody>"; while ($markRow = mysql_fetch_assoc($markResult)) { $userMarks = ""; $marksResult = mysql_query("SELECT `quiz_marksallotted`,`quiz_sectionid` FROM `quiz_userattempts` WHERE `user_id` = '{$markRow['user_id']}' AND `page_modulecomponentid` = '{$quizId}' ORDER BY `quiz_sectionid`"); $cc = 1; while ($row = mysql_fetch_array($marksResult)) { if ($row['quiz_sectionid'] != $cc) { while ($row['quiz_sectionid'] > $cc) { $userMarks .= "<td>-0</td>"; $cc++; } } $userMarks .= "<td>{$row['quiz_marksallotted']}</td>"; $cc++; } while ($cc <= $numSecColumns) { $userMarks .= "<td>-0</td>"; $cc++; } if (is_null($markRow['finishtime'])) { $markRow['finished'] = 0; $markRow['finishtime'] = 'NULL'; } $userfullname = getUserFullNameFromEmail($markRow['email']); $elementDataQuery = 'SELECT `form_elementdata`, `form_elementdesc`.`form_elementid`, `form_elementdesc`.`form_elementname`, `form_elementdesc`.`form_elementtype` FROM `form_elementdesc`, `form_elementdata` WHERE ' . "`form_elementdata`.`page_modulecomponentid` = 0 AND `user_id` = '{$markRow['user_id']}' AND " . "`form_elementdata`.`page_modulecomponentid` = `form_elementdesc`.`page_modulecomponentid` AND " . "`form_elementdata`.`form_elementid` = `form_elementdesc`.`form_elementid` ORDER BY `form_elementrank`"; $elementDataResult = mysql_query($elementDataQuery) or die($elementDataQuery . '<br />' . mysql_error()); $elementRow = array(); while ($elementDataRow = mysql_fetch_assoc($elementDataResult)) { $elementRow['form0_' . $elementDataRow['form_elementname']] = $elementDataRow['form_elementdata']; if ($elementDataRow['form_elementtype'] == 'file') { $elementRow['form0_' . $elementDataRow['form_elementname']] = '<a href="./' . $elementDataRow['form_elementdata'] . '">' . $elementDataRow['form_elementdata'] . '</a>'; } } $display = array(); $columnCount = count($columnNames); for ($i = 0; $i < count($columnNames); $i++) { if (isset($elementRow[$columnNames[$i]])) { $display[] = $elementRow[$columnNames[$i]]; } // else { // $display[] = ' '; // } } $profileStuff = ''; if (count($display)) { $profileStuff = '<td>' . join($display, '</td><td>') . '</td>'; } if ($userfullname == "") { $userfullname = "Anonymous"; } $userListTable .= "<tr><td>{$userfullname}</td><td>{$markRow['email']}</td><td>{$markRow['total']}</td><td>{$markRow['timetaken']}</td><td>{$markRow['starttime']}</td><td>{$markRow['finishtime']}</td>{$userMarks} {$profileStuff}"; $userListTable .= '<td><form name="userclearform" method="POST" action=""><input type="hidden" name="hdnUserId" id="hdnUserId" value="' . $markRow['user_id'] . "\" /><a href=\"./+correct&useremail={$markRow['email']}\">" . $ICONS['Correct']['small'] . '</a><input type="image" src="' . $ICONS_SRC["Delete"]["small"] . '" name="btnDeleteUser" id="btnDeleteUser" value="Reject Submission" title="Reject Submission"/></form></td>'; $userListTable .= "</tr>\n"; } $userListTable .= "</tbody></table>\n"; if (isset($_POST['save_as_excel'])) { header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false); header("Content-Type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=\"{$quizName}.xls\";"); header("Content-Transfer-Encoding: binary"); echo $userListTable; exit(1); } return $userListHtml . $userListTable; }
/** * 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; }
/** * function getNewQuizObject: * returns a object of this quiztype */ private function getNewQuizObject() { $quizRow = getQuizRow($this->moduleComponentId); $quizType = $quizRow['quiz_quiztype']; $quizObjectType = ucfirst($quizType) . 'Quiz'; if (!class_exists($quizObjectType)) { displayerror('Error. This type of quiz has not been implemented yet.'); return false; } $quizObject = new $quizObjectType($this->moduleComponentId); return $quizObject; }
public function __construct($quizId) { $this->quizId = $quizId; $this->quizRow = getQuizRow($quizId); }