Exemplo n.º 1
0
/**
 * 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;
}
Exemplo n.º 2
0
 /**
  * function actionCorrect:
  * handles all actions in Correct
  * Corrects user submission and displays userList with their Marks
  */
 public function actionCorrect()
 {
     if (isset($_POST['btnSetMark'])) {
         $quizid = escape($_POST['quizid']);
         $sectionid = escape($_POST['sectionid']);
         $questionid = escape($_POST['questionid']);
         $userid = escape($_POST['userid']);
         $mark = escape($_POST['mark']);
         $condition = "`page_modulecomponentid` = '{$quizid}' AND `quiz_sectionid` = '{$sectionid}' AND `quiz_questionid` = '{$questionid}' AND `user_id` = '{$userid}'";
         $result = mysql_query("SELECT `quiz_submittedanswer` FROM `quiz_answersubmissions` WHERE {$condition}");
         if ($row = mysql_fetch_array($result)) {
             $result = mysql_fetch_array(mysql_query("SELECT `question_positivemarks`, `question_negativemarks` FROM `quiz_weightmarks` WHERE `page_modulecomponentid` = '{$quizid}' AND `question_weight` = (SELECT `quiz_questionweight` FROM `quiz_questions` WHERE `page_modulecomponentid` = '{$quizid}' AND `quiz_sectionid` = '{$sectionid}' AND `quiz_questionid` = '{$questionid}')"));
             if ($_POST['mark'] > $result['question_positivemarks'] || $_POST['mark'] < -1 * $result['question_negativemarks']) {
                 displaywarning('Mark out of range for this question, so mark not set');
             } else {
                 mysql_query("UPDATE `quiz_answersubmissions` SET `quiz_marksallotted` = {$mark} WHERE {$condition}");
                 updateSectionMarks($quizid);
                 displayinfo('Mark set');
             }
         } else {
             displayerror('Unable to set value');
         }
     }
     if (isset($_GET['useremail'])) {
         $userId = getUserIdFromEmail($_GET['useremail']);
         if ($userId) {
             return getQuizCorrectForm($this->moduleComponentId, $userId);
         } else {
             displayerror('Error. Could not find user.');
         }
     } elseif (isset($_POST['btnDeleteUser']) && isset($_POST['hdnUserId']) && is_numeric($_POST['hdnUserId'])) {
         $quizObject = $this->getNewQuizObject();
         if ($quizObject !== false) {
             $quizObject->deleteEntries(intval($_POST['hdnUserId']));
         }
     }
     return getQuizUserListHtml($this->moduleComponentId);
 }