Example #1
0
/**
 * function getQuestionOptionListHtml:
 * returns HTML format list of options with check boxes to check right answer
 */
function getQuestionOptionListHtml($quizId, $sectionId, $questionId, $questionType, $rightAnswer, $editable = false)
{
    $optionList = getQuestionOptionList($quizId, $sectionId, $questionId);
    if ($optionList === false) {
        return false;
    }
    if ($questionType == 'mso') {
        $rightAnswer = explode('|', $rightAnswer);
    } else {
        $rightAnswer = array($rightAnswer);
    }
    $inputTypePrefix = $questionType == 'sso' ? 'opt' : 'chk';
    $html = '<table id="optionsTable" border="0" width="100%">';
    for ($i = 0; $i < count($optionList); ++$i) {
        $elementName = "{$inputTypePrefix}Option";
        if ($questionType == 'mso') {
            $elementName .= $i;
        }
        $elementId = "{$inputTypePrefix}Option{$i}";
        $html .= '<tr><td style="width:32px"><input type="' . ($questionType == 'sso' ? 'radio' : 'checkbox') . '" id="' . $elementId . '" name="' . $elementName . '" value="' . $i . '"';
        if ($editable && in_array($optionList[$i]['quiz_optionid'], $rightAnswer)) {
            $html .= ' checked="checked"';
        }
        $html .= ' /></td><td>';
        if ($editable) {
            $html .= '<input type="text" name="txtOptionText' . $i . '" id="txtOptionText' . $i . '" value="' . $optionList[$i]['quiz_optiontext'] . '" />';
        } else {
            $html .= $optionList[$i]['quiz_optiontext'];
        }
        $html .= "</td></tr>\n";
    }
    $html .= '</table> <input type="button" name="btnAddOption" onclick="addOption()" value="Add Option" />';
    return $html;
}
Example #2
0
/**
 * fuction getQuizCorrectForm:
 * returns form where user answers submissions will be displayed, marks can be alloted for subjective answers
 */
function getQuizCorrectForm($quizId, $userId)
{
    $marks = mysql_fetch_array(mysql_query("SELECT 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 `quiz_userattempts` WHERE `user_id` = '{$userId}' AND `page_modulecomponentid` = '{$quizId}'"));
    $title = mysql_fetch_array(mysql_query("SELECT `quiz_title` FROM `quiz_descriptions` WHERE `page_modulecomponentid` = '{$quizId}'"));
    $correctFormHtml = "";
    $sectionHead = "";
    $sections = mysql_query("SELECT `quiz_sections`.`quiz_sectiontitle` AS `quiz_sectiontitle`, `quiz_sections`.`quiz_sectionid` AS `quiz_sectionid`, `quiz_marksallotted` FROM `quiz_userattempts` JOIN `quiz_sections` ON `quiz_userattempts`.`quiz_sectionid` = `quiz_sections`.`quiz_sectionid` WHERE `user_id` = '{$userId}' AND `quiz_userattempts`.`page_modulecomponentid` = '{$quizId}' AND `quiz_sections`.`page_modulecomponentid` = '{$quizId}'");
    while ($sectionsRow = mysql_fetch_array($sections)) {
        $correctFormHtml .= "<h4>{$sectionsRow['quiz_sectiontitle']}(Marks: {$sectionsRow['quiz_marksallotted']})</h4>";
        $sectionHead .= "<td><b>{$sectionsRow['quiz_sectiontitle']}</b> section marks: {$sectionsRow['quiz_marksallotted']}</td>";
        $questionQuery = "SELECT `quiz_questions`.`quiz_questionid` AS `quiz_questionid`, " . "`quiz_questions`.`quiz_question` AS `quiz_question`, `quiz_questiontype`, " . "`quiz_rightanswer`, `quiz_submittedanswer`, `quiz_marksallotted`,`quiz_questions`.`quiz_sectionid` " . "FROM `quiz_questions`, `quiz_answersubmissions` WHERE " . "`quiz_questions`.`page_modulecomponentid` = '{$quizId}' AND " . "`quiz_questions`.`page_modulecomponentid` = `quiz_answersubmissions`.`page_modulecomponentid` AND " . "`quiz_questions`.`quiz_sectionid` = `quiz_answersubmissions`.`quiz_sectionid` AND " . "`quiz_questions`.`quiz_questionid` = `quiz_answersubmissions`.`quiz_questionid` AND " . "`quiz_questions`.`quiz_sectionid` = '{$sectionsRow['quiz_sectionid']}' AND " . "`user_id` = '{$userId}' ORDER BY `quiz_answersubmissions`.`quiz_questionrank`";
        $questionResult = mysql_query($questionQuery);
        if (!$questionResult) {
            displayerror($questionQuery . '<br />' . mysql_error());
        }
        while ($questionRow = mysql_fetch_assoc($questionResult)) {
            $correctFormHtml .= '<table class="quiz_' . (is_null($questionRow['quiz_marksallotted']) || floatval($questionRow['quiz_marksallotted']) <= 0 ? 'wrong' : 'right') . "answer\"><tr><td colspan=\"2\">{$questionRow['quiz_question']}</td></tr>\n";
            if ($questionRow['quiz_questiontype'] == 'subjective') {
                $submittedAnswers = array();
                $submittedAnswers[] = $questionRow['quiz_submittedanswer'];
                $correctAnswers = array();
                $correctAnswers[] = $questionRow['quiz_rightanswer'];
                $correctFormHtml .= '<tr><td nowrap="nowrap" width="10%">Submitted Answer:</td><td>' . implode("<br />\n", $submittedAnswers) . "</td></tr>\n";
                $correctFormHtml .= '<tr><td nowrap="nowrap" width="10%">Correct Answer:</td><td>' . implode("<br />\n", $correctAnswers) . "</td></tr>\n";
                $correctFormHtml .= "<tr><td>Mark:</td><td><form method=POST action='./+correct&useremail=" . safe_html($_GET['useremail']) . "'><input type=hidden name=quizid value='{$quizId}'><input type=hidden name=sectionid value={$questionRow['quiz_sectionid']}><input type=hidden name=questionid value={$questionRow['quiz_questionid']}><input type=hidden name=userid value={$userId}><input type=text name=mark size=5 value='{$questionRow['quiz_marksallotted']}'><input type=submit value='Submit' name=btnSetMark></form></td></tr>";
            } elseif ($questionRow['quiz_questiontype'] == 'sso' || $questionRow['quiz_questiontype'] == 'mso') {
                $optionList = getQuestionOptionList($quizId, $sectionsRow['quiz_sectionid'], $questionRow['quiz_questionid']);
                $options = array();
                for ($i = 0; $i < count($optionList); ++$i) {
                    $options[$optionList[$i]['quiz_optionid']] = $optionList[$i];
                }
                $correctAnswers = array();
                $rightAnswerIds = explode('|', $questionRow['quiz_rightanswer']);
                for ($i = 0; $i < count($rightAnswerIds); ++$i) {
                    $correctAnswers[] = $options[$rightAnswerIds[$i]]['quiz_optiontext'];
                }
                $submittedAnswers = array();
                $submittedAnswerIds = explode('|', $questionRow['quiz_submittedanswer']);
                for ($i = 0; $i < count($submittedAnswerIds); ++$i) {
                    $submittedAnswers[] = $options[$submittedAnswerIds[$i]]['quiz_optiontext'];
                }
                $correctFormHtml .= '<tr><td nowrap="nowrap" width="10%">Submitted Answer:</td><td>' . implode("<br />\n", $submittedAnswers) . "</td></tr>\n";
                $correctFormHtml .= "<tr><td nowrap=\"nowrap\" width=\"10%\">Correct Answer:</td><td>" . implode("<br />\n", $correctAnswers) . "</td></tr>\n";
                $correctFormHtml .= "<tr><td>Mark:</td><td>{$questionRow['quiz_marksallotted']}</td></tr>";
            }
            $correctFormHtml .= "</table>\n";
        }
    }
    $quizcorrectinfo = "<h3>{$title['quiz_title']} - Quiz Answers Correct form for user: " . safe_html($_GET['useremail']) . "</h3><form name='userclearform' method='POST' action='./+correct'><a href='./+correct'>&lt;&lt;Back</a> &nbsp;&nbsp;&nbsp;<input type='hidden' name='hdnUserId' id='hdnUserId' value='{$userId}' /><input type='submit' name='btnDeleteUser' id='btnDeleteUser' value='Reject Submission' /></form><table width=100%><tr><td>Total marks: {$marks['total']}</td>{$sectionHead}<td>Start time: {$marks['starttime']}</td><td>Finish time: {$marks['finishtime']}</td><td>Time taken: {$marks['timetaken']}</td></tr></table>";
    $correctFormHtml .= "<a href='./+correct'>&lt;&lt;Back</a>";
    return $quizcorrectinfo . $correctFormHtml;
}
Example #3
0
    /**
     * function formatQuestion:
     * Given a question row, return HTML for the question.
     * @param $questionRow
     * @return string Question in HTML.
     */
    private function formatQuestion($questionRow, $questionNumber = -1)
    {
        $questionType = $questionRow['quiz_questiontype'];
        if ($questionType == 'subjective') {
            $fieldName = 'txtAnswer' . $questionRow['quiz_sectionid'] . '_' . $questionRow['quiz_questionid'];
            $answer = '<textarea 
style="width:95%;height:100px;" name="' . $fieldName . '" id="' . $fieldName . '"></textarea>';
        } else {
            $optionList = getQuestionOptionList($this->quizId, $questionRow['quiz_sectionid'], $questionRow['quiz_questionid']);
            $answer = '<table class="objectivecontainer" width="100%">';
            for ($i = 0; $i < count($optionList); ++$i) {
                $fieldType = $questionType == 'sso' ? 'radio' : 'checkbox';
                $fieldName = '';
                $fieldId = '';
                if ($questionType == 'sso') {
                    $fieldName = 'optAnswer' . $questionRow['quiz_sectionid'] . '_' . $questionRow['quiz_questionid'];
                    $fieldId = $fieldName . '_' . $optionList[$i]['quiz_optionid'];
                } elseif ($questionType == 'mso') {
                    $fieldName = 'chkAnswer' . $questionRow['quiz_sectionid'] . '_' . $questionRow['quiz_questionid'] . '_' . $optionList[$i]['quiz_optionid'];
                    $fieldId = $fieldName;
                }
                $answer .= "<tr><td width=\"24\"><input type=\"{$fieldType}\" name=\"{$fieldName}\" id=\"{$fieldId}\" value=\"{$optionList[$i]['quiz_optionid']}\" /> </td><td><label for=\"{$fieldId}\"> {$optionList[$i]['quiz_optiontext']}</label></td></tr>\n";
            }
            $answer .= '</table>';
        }
        $hiddenFieldName = "hdnQuestion{$questionRow['quiz_sectionid']}_{$questionRow['quiz_questionid']}";
        $questionDesc = $questionRow['quiz_question'];
        if ($questionNumber > 0) {
            $questionDesc = $questionNumber . ') ' . $questionDesc;
        }
        global $sourceFolder, $moduleFolder;
        require_once $sourceFolder . "/pngRender.class.php";
        $render = new pngrender();
        $questionDesc = $render->transform($questionDesc);
        $answer = $render->transform($answer);
        return <<<QUESTIONFORM
\t\t\t<input type="hidden" name="{$hiddenFieldName}" id="{$hiddenFieldName}" value="" />
\t\t\t<div class="quiz_questioncontainer">
\t\t\t\t<br /><b>{$questionDesc}</b><br /><br />
\t\t\t</div>
\t\t\t<div class="quiz_answercontainer">
\t\t\t\t{$answer}
\t\t\t</div>
QUESTIONFORM;
    }