private function doCategoryReports() { $smarty = $this->getSmartyVar(); $currentUser = $this->getCurrentUser(); $directionsTree = new EfrontDirectionsTree(); $directionPaths = $directionsTree->toPathString(); $form = new HTML_QuickForm("category_form", "post", basename($_SERVER['PHP_SELF']) . "?ctg=module&op=module_administrator_tools&tab=category_reports&do=enterprise", "", null, true); $form->addElement('select', 'category', _CATEGORY, $directionPaths); $form->addElement('checkbox', 'incomplete', _MODULE_ADMINISTRATOR_TOOLS_SHOWINCOMPLETE); $form->addElement('checkbox', 'inactive', _MODULE_ADMINISTRATOR_TOOLS_SHOWINACTIVECOURSES); $form->addElement('date', 'from_timestamp', _MODULE_ADMINISTRATOR_TOOLS_COMPLETEDFROM, array('minYear' => 1970, 'maxYear' => date("Y"))); $form->addElement('date', 'to_timestamp', _MODULE_ADMINISTRATOR_TOOLS_COMPLETEDTO, array('minYear' => 1970, 'maxYear' => date("Y"))); $form->addElement("submit", "submit", _SUBMIT, 'class = "flatButton"'); $form->setDefaults(array("from_timestamp" => mktime(0, 0, 0, date("m") - 1, date("d"), date("Y")), "to_timestamp" => time())); if ($form->isSubmitted() && $form->validate()) { $values = $form->exportValues(); $_SESSION['from_timestamp'] = mktime(0, 0, 0, $_POST['from_timestamp']['M'], $_POST['from_timestamp']['d'], $_POST['from_timestamp']['Y']); $_SESSION['to_timestamp'] = mktime(23, 59, 59, $_POST['to_timestamp']['M'], $_POST['to_timestamp']['d'], $_POST['to_timestamp']['Y']); $_SESSION['category'] = $values['category']; $_SESSION['incomplete'] = $values['incomplete']; $_SESSION['inactive'] = $values['inactive']; $smarty->assign("T_SHOW_TABLE", true); } if (isset($_GET['ajax']) && $_GET['ajax'] == 'categoryUsersTable' || $_GET['ajax'] == 'xls' || $_GET['ajax'] == 'show_xls') { $smarty->assign("T_SHOW_TABLE", true); $smarty->assign("T_DIRECTIONS_TREE", $directionPaths); $branchesTree = new EfrontBranchesTree(); $branchesPaths = $branchesTree->toPathString(); $category = new EfrontDirection($_SESSION['category']); $directionsTree = new EfrontDirectionsTree(); $children = $directionsTree->getNodeChildren($_SESSION['category']); foreach (new EfrontAttributeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($children)), array('id')) as $value) { $siblings[] = $value; } $result = eF_getTableDataFlat("courses", "id", "archive = 0 && directions_ID in (" . implode(",", $siblings) . ")"); $categoryCourses = $result['id']; $resultCourses = eF_getTableDataFlat("users_to_courses uc, courses c", "distinct c.id", 'c.id=uc.courses_ID ' . (!$_SESSION['inactive'] ? 'and c.active=1' : '') . ' and uc.archive=0 and uc.completed=1 and uc.to_timestamp >= ' . $_SESSION['from_timestamp'] . ' and uc.to_timestamp <= ' . $_SESSION['to_timestamp']); $resultEvents = eF_getTableDataFlat("events e, courses c", "distinct c.id", 'c.id=e.lessons_ID ' . (!$_SESSION['inactive'] ? 'and c.active=1' : '') . ' and e.type=54 and e.timestamp >= ' . $_SESSION['from_timestamp'] . ' and e.timestamp <= ' . $_SESSION['to_timestamp']); if (empty($resultEvents)) { $resultEvents['id'] = array(); } $result = array_unique(array_merge($resultCourses['id'], $resultEvents['id'])); $categoryCourses = array_intersect(array_unique($categoryCourses), $result); //count only courses that have users completed them if ($_SESSION['incomplete']) { $constraints = array('archive' => false, 'condition' => '(to_timestamp is null OR to_timestamp = 0 OR (to_timestamp >= ' . $_SESSION['from_timestamp'] . ' and to_timestamp <= ' . $_SESSION['to_timestamp'] . '))'); } else { $constraints = array('archive' => false, 'condition' => 'completed=1 and to_timestamp >= ' . $_SESSION['from_timestamp'] . ' and to_timestamp <= ' . $_SESSION['to_timestamp']); } foreach ($categoryCourses as $courseId) { $course = new EfrontCourse($courseId); foreach ($course->getCourseUsers($constraints) as $value) { $userBranches = $value->aspects['hcd']->getBranches(); $userSupervisors = $value->aspects['hcd']->getSupervisors(); $userSupervisor = end($userSupervisors); $value->user['course_active'] = $course->course['active']; $value->user['course_id'] = $course->course['id']; $value->user['category'] = $directionPaths[$course->course['directions_ID']]; $value->user['course'] = $course->course['name']; $value->user['directions_ID'] = $course->course['directions_ID']; $value->user['branch'] = $branchesPaths[current($userBranches['employee'])]; $value->user['branch_ID'] = current($userBranches['employee']); $value->user['supervisor'] = $userSupervisor; $value->user['historic'] = false; $unique = md5($value->user['to_timestamp'] . $value->user['course_id'] . $value->user['login']); $courseUsers[$unique] = $value->user; } $result = eF_getTableData("events", "*", 'type=54 and lessons_ID=' . $courseId . ' and timestamp >= ' . $_SESSION['from_timestamp'] . ' and timestamp <= ' . $_SESSION['to_timestamp']); //exit; foreach ($result as $entry) { try { $value = EfrontUserFactory::factory($entry['users_LOGIN']); if (!$value->user['archive']) { $userBranches = $value->aspects['hcd']->getBranches(); $userSupervisors = $value->aspects['hcd']->getSupervisors(); //pr($entry['users_LOGIN']);pr($userSupervisors);pr(current($userSupervisors)); $userSupervisor = current($userSupervisors); $value->user['course_active'] = $course->course['active']; $value->user['course_id'] = $course->course['id']; $value->user['category'] = $directionPaths[$course->course['directions_ID']]; $value->user['course'] = $course->course['name']; $value->user['directions_ID'] = $course->course['directions_ID']; $value->user['branch'] = $branchesPaths[current($userBranches['employee'])]; $value->user['branch_ID'] = current($userBranches['employee']); $value->user['supervisor'] = $userSupervisor; $value->user['to_timestamp'] = $entry['timestamp']; $value->user['completed'] = 1; $value->user['score'] = ''; $value->user['historic'] = true; $unique = md5($value->user['to_timestamp'] . $value->user['course_id'] . $value->user['login']); if (!isset($courseUsers[$unique])) { $courseUsers[$unique] = $value->user; } } } catch (Exception $e) { /*Bypass non-existing users*/ } } } if ($_GET['ajax'] == 'xls') { $xlsFilePath = $currentUser->getDirectory() . 'category_report.xls'; unlink($xlsFilePath); $_GET['limit'] = sizeof($courseUsers); $_GET['sort'] = 'category'; list($tableSize, $courseUsers) = filterSortPage($courseUsers); $header = array('category' => _CATEGORY, 'course' => _NAME, 'login' => _USER, 'to_timestamp' => _COMPLETED, 'score' => _SCORE, 'supervisor' => _SUPERVISOR, 'branch' => _BRANCH, 'historic' => _MODULE_ADMINISTRATOR_TOOLS_HISTORICENTRY); foreach ($courseUsers as $value) { $rows[] = array(_CATEGORY => str_replace(" → ", " -> ", $value['category']), _COURSE => $value['course'], _USER => formatLogin($value['login']), _COMPLETED => formatTimestamp($value['to_timestamp']), _SCORE => $value['historic'] ? '' : formatScore($value['score']) . '%', _SUPERVISOR => formatLogin($value['supervisor']), _BRANCH => str_replace(" → ", " -> ", $value['branch']), _MODULE_ADMINISTRATOR_TOOLS_HISTORICENTRY => $value['historic'] ? _YES : _NO); } EfrontSystem::exportToXls($rows, $xlsFilePath); exit; } else { if ($_GET['ajax'] == 'show_xls') { $xlsFilePath = $currentUser->getDirectory() . 'category_report.xls'; $file = new EfrontFile($xlsFilePath); $file->sendFile(true); exit; } else { list($tableSize, $courseUsers) = filterSortPage($courseUsers); $smarty->assign("T_SORTED_TABLE", $_GET['ajax']); $smarty->assign("T_TABLE_SIZE", $tableSize); $smarty->assign("T_DATA_SOURCE", $courseUsers); } } } $smarty->assign("T_CATEGORY_FORM", $form->toArray()); }
$value = $value->lesson; //$lessonsAvgScore += $value['score']; if ($value['completed']) { $completedScores[] = $value['score']; } $dataL[$lessonId] = array(_NAME => $value['name'], _CATEGORY => str_replace(" → ", " -> ", $directionsTreePaths[$value['directions_ID']]), _REGISTRATIONDATE => formatTimestamp($value['active_in_lesson']), _COMPLETED => $value['completed'] ? _YES . ($value['timestamp_completed'] ? ', ' . _ON . ' ' . formatTimestamp($value['timestamp_completed']) : '') : '-', _SCORE => formatScore($value['score']) . '%'); if ($GLOBALS['configuration']['time_reports']) { $dataL[$lessonId][_ACTIVETIMEINLESSON] = $value['active_time_in_lesson']['time_string']; } else { $dataL[$lessonId][_TIME] = $value['time_in_lesson']['time_string']; } if (isset($userDoneTests[$value['id']])) { $subsectionFormatting = array(_TESTNAME => array('width' => '78%', 'fill' => true), _STATUS => array('width' => '13%', 'fill' => true, 'align' => 'C'), _SCORE => array('width' => '9%', 'fill' => true, 'align' => 'R')); $subSectionData = array(); foreach ($userDoneTests[$value['id']] as $test) { $subSectionData[] = array(_TESTNAME => $test['name'], _STATUS => $test['status'], _SCORE => formatScore($test['active_score']) . '%'); } $subSections[$lessonId] = array('data' => $subSectionData, 'formatting' => $subsectionFormatting, 'title' => _TESTSFORLESSON . ': ' . $value['name']); } } $pdf->printDataSection(_TRAINING . ': ' . _LESSONS, $dataL, $formatting, $subSections); if (sizeof($completedScores) > 0) { $lessonsAvgScore = round(array_sum($completedScores) / sizeof($completedScores), 2); } /* $testsAvgScoreNum = 0; $testsAvgScore = 0; foreach ($userDoneTests as $lessonId => $tests) { foreach ($tests as $test) { $testsAvgScore += $test['active_score']; $testsAvgScoreNum++;
foreach ($userDoneTests[$value['id']] as $test) { $testsSubSectionData[] = array(_TESTNAME => $test['name'], _STATUS => $test['status'], _SCORE => formatScore($test['score']).'%'); } $testSubSections[$lessonId] = array('data' => $testsSubSectionData, 'formatting' => $testSubsectionFormatting, 'title' => _TESTSFORLESSON.': '.$courseLesson['name']); } */ } $subSections[$courseId] = array('data' => $subSectionData, 'formatting' => $subsectionFormatting, 'title' => _LESSONSFORCOURSE . ': ' . $value['name'], 'subSections' => $testSubSections); } } $pdf->printDataSection(_TRAINING . ': ' . _COURSES, $data, $formatting, $subSections); $data = $subSections = array(); foreach ($userLessons as $lessonId => $value) { $data[$lessonId] = array(_NAME => $value['name'], _CATEGORY => str_replace(" → ", " -> ", $directionsPathStrings[$value['directions_ID']]), _REGISTRATIONDATE => formatTimestamp($value['active_in_lesson']), _COMPLETED => $value['completed'] ? _YES . ($value['timestamp_completed'] ? ', ' . _ON . ' ' . formatTimestamp($value['timestamp_completed']) : '') : '-', _SCORE => formatScore($value['score']) . '%'); /* if (isset($userDoneTests[$value['id']])) { $subsectionFormatting = array(_TESTNAME => array('width' => '78%', 'fill' => true), _STATUS => array('width' => '13%', 'fill' => true, 'align' => 'C'), _SCORE => array('width' => '9%', 'fill' => true, 'align' => 'R')); $subSectionData = array(); foreach ($userDoneTests[$value['id']] as $test) { $subSectionData[] = array(_TESTNAME => $test['name'], _STATUS => $test['status'], _SCORE => formatScore($test['score']).'%'); } $subSections[$lessonId] = array('data' => $subSectionData, 'formatting' => $subsectionFormatting, 'title' => _TESTSFORLESSON.': '.$value['name']); } */ }
$data = array(); foreach ($professors as $user) { $data[] = array(_USER => formatLogin($user['login']), _REGISTRATIONDATE => formatTimestamp($user['timestamp'])); } $pdf->printDataSection(_PROFESSORSINFO, $data, $formatting); if (EfrontUser::isOptionVisible('tests')) { $formatting = array(_USER => array('width' => '25%', 'fill' => false), _SCORE => array('width' => '15%', 'fill' => false)); foreach ($testsInfo as $id => $info) { $data = array(); foreach ($info['done'] as $results) { $avgScore[] = $results['active_score'] ? $results['active_score'] : $results['score']; $data[] = array(_USER => formatLogin($results['users_LOGIN']), _SCORE => formatScore(round($results['active_score'] ? $results['active_score'] : $results['score'], 2)) . "%"); } if (!empty($data)) { $data[] = array(_USER => _AVERAGESCORE, _SCORE => formatScore(round(array_sum($avgScore) / sizeof($avgScore), 2)) . "%"); } $pdf->printDataSection(_TESTSINFORMATION . ': ' . $info['general']['name'], $data, $formatting); } if (sizeof($lessonQuestions) > 0) { $formatting = array(_QUESTION => array('width' => '50%', 'fill' => false), _QUESTIONTYPE => array('width' => '20%', 'fill' => false), _DIFFICULTY => array('width' => '10%', 'fill' => false, 'align' => 'C'), _TIMESDONE => array('width' => '10%', 'fill' => false, 'align' => 'C'), _AVERAGESCORE => array('width' => '10%', 'fill' => false, 'align' => 'C')); $data = array(); foreach ($questionsInfo as $id => $questionInfo) { $data[] = array(_QUESTION => $questionInfo['text'], _QUESTIONTYPE => Question::$questionTypes[$questionInfo['type']], _DIFFICULTY => Question::$questionDifficulties[$questionInfo['difficulty']], _TIMESDONE => $questionInfo['times_done'], _AVERAGESCORE => formatScore($questionInfo['avg_score']) . "%"); } $pdf->printDataSection(_QUESTIONSINFORMATION, $data, $formatting); } } $pdf->OutputPdf('lesson_form_' . $infoLesson->lesson['name'] . '.pdf'); exit; } }
</div> '; } $supervisors = array(); foreach ($user->aspects['hcd']->getSupervisors() as $value) { $supervisors[] = formatLogin($value); } if (!empty($supervisors)) { $tooltipInfo[] = '<div class = "infoEntry"><span>' . _SUPERVISORS . "</span><span>: " . implode(", ", $supervisors) . "</span></div>"; } $skills = $user->aspects['hcd']->getSkills(); foreach ($skills as $value) { $tooltipInfo[] = ' <div class = "infoEntry"> <span>' . _SKILL . '</span><span>: ' . $value['description'] . ($value['specification'] ? ' <b>(' . $value['specification'] . ')</b>' : '') . '</span> <span> ' . _WITHSCORE . ': </span><span style = "font-weight:bold">' . formatScore($value['score']) . '%</span> </div> '; } } #cpp#endif echo implode("", $tooltipInfo); } } } #cpp#endif } #cpp#endif } catch (Exception $e) { echo $e->getMessage() . ' (' . $e->getCode() . ')'; //No ajax error handling here, since we want the info to appear in the popup
/** * Display question with correct answer * * This function is used to display the question, together * with its correct answer. * <br/>Example: * <code> * $question = new MultipleOneQuestion(3); //Instantiate question * $form = new HTML_QuickForm("questionForm", "post", "", "", null, true); //Create a form * echo $question -> preview($form); //Output solved question HTML code * </code> * * @param HTML_QuickForm $form The form to add fields to and display * @param boolean $questionStats * @return string The HTML code of the solved question * @since 3.6.0 * @access public */ public function preview(&$form, $questionStats = false, $hideAnswerStatus = false) { $this->toHTMLQuickForm($form); //Assign proper elements to the form $results = $this->correct(); //Correct question for ($k = 0; $k < sizeof($this->options); $k++) { $form->setDefaults(array("question[" . $this->question['id'] . "][{$k}]" => '')); } $form->freeze(); //Freeze the form elements $renderer = new HTML_QuickForm_Renderer_ArraySmarty($foo); //Get a smarty renderer, only because it reforms the form in a very convenient way for printing html $form->accept($renderer); //Render the form $formArray = $renderer->toArray(); //Get the rendered form fields $innerQuestionString = ''; for ($k = 0; $k < sizeof($this->options); $k++) { //Display properly each option. The group can't be used, since we will display each option differently, depending on whether it is correct or not $index = $this->order[$k]; //$index is used to recreate the answers order, for a done test, or to apply the answers shuffle, for an unsolved test if ($this->answer[$index]) { if (!$hideAnswerStatus) { $innerQuestionString .= '<span class = "correctAnswer">' . $formArray['question'][$this->question['id']][$index]['label']; } else { $innerQuestionString .= '<span>' . $formArray['question'][$this->question['id']][$index]['label']; } if ($questionStats[$this->question['id']]['percent_per_option'][$index]) { if (!$hideAnswerStatus) { $innerQuestionString .= " (" . $questionStats[$this->question['id']]['percent_per_option'][$index] . "%)"; } else { //means it is feeback temporary fix $innerQuestionString .= " (" . formatScore($questionStats[$this->question['id']]['answers_per_option'][$index] / $questionStats[$this->question['id']]['times_done']) . "%)"; } } elseif ($questionStats !== false) { if (!$hideAnswerStatus) { $innerQuestionString .= " (0%)"; } else { //means it is feeback temporary fix $innerQuestionString .= " (100%)"; } } } else { if (!$hideAnswerStatus) { $innerQuestionString .= '<span class = "wrongAnswer">' . $formArray['question'][$this->question['id']][$index]['label']; } else { $innerQuestionString .= '<span>' . $formArray['question'][$this->question['id']][$index]['label']; } if ($questionStats[$this->question['id']]['percent_per_option'][$index]) { if (!$hideAnswerStatus) { $innerQuestionString .= " (" . $questionStats[$this->question['id']]['percent_per_option'][$index] . "%)"; } else { $innerQuestionString .= " (" . formatScore($questionStats[$this->question['id']]['answers_per_option'][$index] / $questionStats[$this->question['id']]['times_done']) . "%)"; } } elseif ($questionStats !== false) { if (!$hideAnswerStatus) { $innerQuestionString .= " (0%)"; } else { $innerQuestionString .= " (100%)"; } } } $innerQuestionString .= '</span><br>'; } $questionString = ' <table width = "100%"> <tr><td>' . $this->question['text'] . '</td></tr> <tr><td style = "vertical-align:middle;padding-bottom:10px"> ' . $innerQuestionString . ' </td></tr> </table>'; return $questionString; }
/** * Generate the HTML for this event's score. * * @param array $buffer * @param string $code * @param string $name * @param string $stylesheet relative url to css style sheet * @param array $scores scores for each competitor given in order of placement * @return array */ function getEventHtml(&$buffer, $code, $name, $stylesheet, $scores) { $buffer[] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'; $buffer[] = <<<EOD <html> <head> <title>{$code} : {$name}</title> <link rel="stylesheet" type="text/css" media="screen" href="{$stylesheet}" /> </head> <body> <h1>{$code} : {$name}</h1> <table> <thead> <th scope="col">Placement</th> <th scope="col">Name</th> <th scope="col">Score 1</th> <th scope="col">Score 2</th> <th scope="col">Score 3</th> <th scope="col">Score 4</th> <th scope="col">Score 5</th> <th scope="col">Score 6</th> <th scope="col">Time Deduction</th> <th scope="col">Other Deduction</th> <th scope="col">Final Score</th> </thead> <tbody> EOD; $isOdd = true; foreach ($scores as $s) { // Scoring $buffer[] = sprintf('<tr class="%s"><td class="placement">%d</td><td class="name">%s</td><td class="score">%s</td><td class="score">%s</td><td class="score">%s</td><td class="score">%s</td><td class="score">%s</td><td class="score">%s</td><td class="score">%s</td><td class="score">%s</td><td class="score">%s</td></tr>', $isOdd ? 'oddRow' : 'evenRow', $s['placement'], $s['name'], formatScore($s['score1']), formatScore($s['score2']), formatScore($s['score3']), formatScore($s['score4']), formatScore($s['score5']), formatScore($s['score6']), formatScore($s['timeDeduction']), formatScore($s['otherDeduction']), formatScore($s['finalScore'])); $isOdd = !$isOdd; } $buffer[] = <<<EOD </tbody> </table> </body> </html> EOD; // asdf return $buffer; }
foreach ($result as $value) { $userBranches[$value['users_login']][] = $value['name']; } foreach ($userBranches as $login => $value) { $userBranches[$login] = implode(",", $value); } $formatting = array(_USER => array('width' => '16%', 'fill' => false), _COURSEROLE => array('width' => '16%', 'fill' => false), _BRANCH => array('width' => '16%', 'fill' => false), _PERCENTAGE => array('width' => '16%', 'fill' => false), _ENROLLEDON => array('width' => '10%', 'fill' => false), _COMPLETED => array('width' => '11%', 'fill' => false), _SCORE => array('width' => '11%', 'fill' => false, 'align' => 'R')); } #cpp#endif foreach ($users as $login => $info) { if ($info['completed'] && $info['to_timestamp']) { $completedString = _YES . ', ' . _ON . ' ' . formatTimestamp($info['to_timestamp']); } elseif ($info['completed']) { $completedString = _YES; } else { $completedString = _NO; } if (G_VERSIONTYPE == 'enterprise') { #cpp#ifdef ENTERPRISE $data[] = array(_USER => formatLogin($info['login']), _COURSEROLE => $roles[$info['role']], _BRANCH => $userBranches[$login], _PERCENTAGE => $rolesBasic[$info['user_type']] == 'student' ? $info['lesson_percentage'] . "%" : "", _ENROLLEDON => formatTimestamp($info['enrolled_on']), _COMPLETED => $completedString, _SCORE => formatScore($info['score']) . "%"); } else { #cpp#else $data[] = array(_USER => formatLogin($info['login']), _COURSEROLE => $roles[$info['role']], _PERCENTAGE => $rolesBasic[$info['user_type']] == 'student' ? $info['lesson_percentage'] . "%" : "", _ENROLLEDON => formatTimestamp($info['enrolled_on']), _COMPLETED => $completedString, _SCORE => formatScore($info['score']) . "%"); } #cpp#endif } $pdf->printDataSection(_USERSINFO, $data, $formatting); $pdf->OutputPdf('course_form_' . $infoCourse->course['name'] . '.pdf'); exit; } }