/** * function getSectionEditForm: * this function returns HTML edit form for a section, where section specific properties can be edited */ function getSectionEditForm($quizId, $sectionId, $dataSource) { $fieldMap = getSectionEditFormFieldMap(); 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') { $sectionRow = getSectionRow($quizId, $sectionId); if (!$sectionRow) { displayerror('Error. Could not load information about the specified section. Section not found.'); return ''; } for ($i = 0; $i < count($fieldMap); ++$i) { if ($fieldMap[$i][3] == 'checkbox') { ${$fieldMap}[$i][2] = isset($sectionRow[$fieldMap[$i][1]]) && $sectionRow[$fieldMap[$i][1]] != 0 ? 'checked="checked"' : ''; } else { ${$fieldMap}[$i][2] = isset($sectionRow[$fieldMap[$i][1]]) ? htmlentities($sectionRow[$fieldMap[$i][1]]) : ''; } } } $sectionEditForm = <<<SECTIONEDITFORM \t\t<form name="sectioneditform" action="" method="POST"> \t\t\t<fieldset style="padding:8px"> \t\t\t\t<legend>Edit Section Properties</legend> \t\t\t\t<table border="0"> \t\t\t\t\t<tr><td><label for="txtSectionTitle">Section Title:</label></td><td><input type="text" name="txtSectionTitle" id="txtSectionTitle" value="{$section_sectiontitle}" /></td></tr> \t\t\t\t\t<tr><td><label for="txtSSOCount">Number of Single Select Objective Questions:</label></td><td><input type="text" name="txtSSOCount" id="txtSSOCount" value="{$section_ssocount}" /></td></tr> \t\t\t\t\t<tr><td><label for="txtMSOCount">Number of Multi-select Objective Questions:</label></td><td><input type="text" name="txtMSOCount" id="txtMSOCount" value="{$section_msocount}" /></td></tr> \t\t\t\t\t<tr><td><label for="txtSubjectiveCount">Number of Subjective Questions:</label></td><td><input type="text" name="txtSubjectiveCount" id="txtSubjectiveCount" value="{$section_subjectivecount}" /></td></tr> \t\t\t\t\t<tr><td><label for="txtSessionTimeLimit">Time Limit:</label></td><td><input type="text" name="txtSessionTimeLimit" id="txtSessionTimeLimit" value="{$section_timelimit}" /></td></tr> \t\t\t\t\t<tr><td><label>Show Limit?</label></td><td><label><input type="checkbox" name="chkShowLimit" id="chkShowLimit" value="yes" {$section_showlimit} /> Yes</label></td></tr> \t\t\t\t\t<tr><td><label>Shuffle Questions?</label></td><td><label><input type="checkbox" name="chkShuffle" id="chkShuffle" value="yes" {$section_shuffle} /> Yes</label></td></tr> \t\t\t\t</table> \t\t\t</fieldset> \t\t\t<input type="submit" name="btnSubmit" id="btnSubmit" value="Submit" /> \t\t</form> \t\t<p><a href="./+edit">« Back to Quiz Properties</a></p> SECTIONEDITFORM; return $sectionEditForm; }
/** * function checkUserTimedOut: * Returns a string denoting the amount of time the user has to complete the section or quiz. * @param Integer $userId User ID of the user. * @param Integer $sectionId Section ID. If omitted, the time remaining for the entire quiz is shown. * @param String $offset Amount of time to add as grace period for the user. To be used only to check if a page can be submitted. * @return Boolean indicating whether the user has run out of time or not. -1 indicating errors. */ private function checkUserTimedOut($userId, $sectionId = -1, $offset = '0 SECOND') { if ($sectionId < 0) { // Check if the quiz has timed out: // Find the earliest attempt start time, add quiz duration to it // add offset to now, and compare $timeoutQuery = "SELECT IF(DATE_SUB(NOW(), INTERVAL {$offset}) > ADDTIME(MIN(`quiz_attemptstarttime`), '{$this->quizRow['quiz_testduration']}'), 1, 0) AS `quiz_expired` FROM " . "`quiz_userattempts` WHERE `page_modulecomponentid` = {$this->quizId} AND `user_id` = {$userId}"; } else { $sectionRow = getSectionRow($this->quizId, $sectionId); if ($sectionRow['quiz_sectiontimelimit'] == '00:00:00') { return false; } $timeoutQuery = "SELECT IF(DATE_SUB(NOW(), INTERVAL {$offset}) > ADDTIME(`quiz_attemptstarttime`, '{$sectionRow['quiz_sectiontimelimit']}'), 1, 0) AS `quiz_expired` FROM " . "`quiz_userattempts` WHERE `page_modulecomponentid` = '{$this->quizId}' AND `quiz_sectionid` = '{$sectionId}' AND `user_id` = '{$userId}'"; } $timeoutResult = mysql_query($timeoutQuery); if (!$timeoutResult) { displayerror('Database Error. Could not retrieve time information.'); return -1; } $timeoutRow = mysql_fetch_row($timeoutResult); if (is_null($timeoutRow[0])) { // An invalid Section ID was passed => we could not find a row for the user for that // Section ID. assume he timed out return true; } return $timeoutRow[0]; }