function processRecords($docs) { global $fields; $N = $docs->response->numFound; foreach ($docs->response->docs as $doc) { // echo $doc->id, "\n"; foreach ($fields as $field) { if (isset($doc->{$field})) { foreach ($doc->{$field} as $value) { $terms = getTerms($field, $value); $total = getWeights($field, $terms, $N); // printf("\t%s: %s ==> %s\n", $field, $value, $total); printf("%s ==> %s\n", (int) ($total * 100), $value); } } } } }
/** * 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; }