Example #1
0
/**
 * Checks whether a quiz has been set up properly with sufficient number of questions.
 * @param integer $quizId Quiz Id.
 * @return boolean True indicating that the quiz is set up properly, false indicating otherwise.
 */
function checkQuizSetup($quizId)
{
    $sectionList = getSectionList($quizId);
    if (count($sectionList) == 0) {
        return false;
    }
    $questionTypes = array_keys(getQuestionTypes());
    for ($i = 0; $i < count($sectionList); ++$i) {
        $questionCounts = getQuestionTypeCounts($quizId, $sectionList[$i]['quiz_sectionid']);
        for ($j = 0; $j < count($questionTypes); ++$j) {
            if ($questionCounts[$questionTypes[$j]] < $sectionList[$i]['quiz_section' . $questionTypes[$j] . 'count']) {
                return false;
            }
        }
    }
    return true;
}
Example #2
0
function getNodePanel($divId)
{
    global $vbulletin;
    global $vbphrase;
    global $phrasegroups;
    global $sect_js_varname;
    fetch_phrase_group('cpcms');
    $result = "\n<div id=\"{$divId}\" style=\"position: absolute;\n\tdisplay: none;\twidth:600px;height:380px;background-color:white; text-align:" . vB_Template_Runtime::fetchStyleVar('left') . ";\n\toverflow: auto;" . vB_Template_Runtime::fetchStyleVar('left') . ":100px;top:100px; border:1px solid #000;clear:both;padding:0px 0px 0px 0px;\">\n\t<div class=\"tcat\" style=\"border:0;height:12px;top:0px;" . vB_Template_Runtime::fetchStyleVar('left') . ":0px;width:580px;position:relative;\" >\n\t\t<span style=\"" . vB_Template_Runtime::fetchStyleVar('left') . ":0px;top:0px;position:relative;text-align:" . vB_Template_Runtime::fetchStyleVar('left') . ";font-size:120%;width:50%;float:" . vB_Template_Runtime::fetchStyleVar('left') . ";\"><strong>" . $vbphrase['section_navigator'] . "</strong>\n\t\t</span>\n\t\t<div style=\"" . vB_Template_Runtime::fetchStyleVar('left') . ":400px;border:0;top:-20px;text-align:" . vB_Template_Runtime::fetchStyleVar('right') . ";padding:0px 10px 0px 0px;\">\n\t\t\t<input type=\"button\" id=\"button_selectsection_close\" value=\"" . $vbphrase['close'] . "\"\n\t\t\tonclick=\"document.getElementById('{$divId}').style.display='none'\" />\n\t\t</div>\n\t</div>\n\t<div class=\"picker_overlay\" style=\"border:0;height:343px;width:100%;top:0px;padding:0;\n\t\toverflow:auto;position:relative;display:block;\">\n\t\t<div class=\"tcat\" style=\"border:0;position:relative;" . vB_Template_Runtime::fetchStyleVar('left') . ":0px;width:561px;padding:0;\n\t\t\tfont-size:14px;font-weight:bold;padding:2px;color:black;float:" . vB_Template_Runtime::fetchStyleVar('left') . ";padding:10px;\n\t\t\tborder-style:solid;border-width:1px 1px 0 1px;border-color:#000000;\">" . $vbphrase['choose_a_section'] . "\n\t\t</div>\n\t\t<div style=\"border:0;padding-" . vB_Template_Runtime::fetchStyleVar('left') . ":5px\">\n\t";
    $result .= getSectionList();
    $result .= "\n\t</div>\n\t</div>\n</div>\n";
    return $result;
}
Example #3
0
/**
 * 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&sectionid={$quizSections[$i]['quiz_sectionid']}\" />{$moveUpImage}</a>";
        $moveDown = $i == $sectionCount - 1 ? '' : "<a href=\"./+edit&subaction=movesection&direction=down&sectionid={$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&sectionid={$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&sectionid={$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;
}
Example #4
0
 /**
  * function markSectionCompleted:
  * Marks a section as completed.
  * @return Boolean True if the section is (or was) completed. False if the section is not complete.
  */
 private function markSectionCompleted($userId, $sectionId = -1)
 {
     if ($sectionId == -1) {
         $sections = getSectionList($this->quizId);
         $allOk = true;
         for ($i = 0; $i < count($sections); ++$i) {
             $allOk = $this->markSectionCompleted($userId, $sections[$i]['quiz_sectionid']) && $allOk;
         }
         return $allOk;
     }
     $attemptRow = getAttemptRow($this->quizId, $sectionId, $userId);
     if (is_null($attemptRow['quiz_submissiontime'])) {
         // Check if all questions for this section have been completed, if yes, set quiz_submissiontime and return true
         $questionQuery = "SELECT COUNT(*) FROM `quiz_answersubmissions` WHERE " . "`page_modulecomponentid` = '{$this->quizId}' AND `quiz_sectionid` = '{$sectionId}' AND `user_id` = '{$userId}' AND `quiz_answersubmittime` IS NULL";
         $questionResult = mysql_query($questionQuery);
         $questionRow = mysql_fetch_row($questionResult);
         if ($questionRow[0] != 0) {
             return false;
         }
         $updateQuery = "UPDATE `quiz_userattempts` SET `quiz_submissiontime` = NOW() WHERE `page_modulecomponentid` = '{$this->quizId}' AND `quiz_sectionid` = '{$sectionId}' AND `user_id` = '{$userId}'";
         if (mysql_query($updateQuery)) {
             return true;
         } else {
             displayerror('Database Error. Could not mark section as completed.');
             return -1;
         }
     } else {
         return true;
     }
 }