private function doMultiplePlacements()
 {
     $smarty = $this->getSmartyVar();
     $currentUser = $this->getCurrentUser();
     try {
         if ($_GET['ajax'] == 'multiplePlacementsTable') {
             $users = eF_getTableData("module_hcd_employee_works_at_branch wb, users u", "wb.users_login, sum(assigned) as placements, u.active", "wb.users_login=u.login and wb.assigned = 1 and u.archive=0", "", "users_login");
             foreach ($users as $key => $value) {
                 if ($value['placements'] <= 1) {
                     unset($users[$key]);
                 }
             }
             list($tableSize, $users) = filterSortPage($users);
             $smarty->assign("T_SORTED_TABLE", $_GET['ajax']);
             $smarty->assign("T_TABLE_SIZE", $tableSize);
             $smarty->assign("T_DATA_SOURCE", $users);
         }
     } catch (Exception $e) {
         handleAjaxExceptions($e);
     }
 }
<?php

if (str_replace(DIRECTORY_SEPARATOR, "/", __FILE__) == $_SERVER['SCRIPT_FILENAME']) {
    exit;
}
if (isset($_GET['ajax']) && $_GET['ajax'] == $tableName) {
    //isset($_GET['limit']) && eF_checkParameter($_GET['limit'], 'uint') ? null : $_GET['limit'] = G_DEFAULT_TABLE_SIZE;
    if (!$alreadySorted) {
        list($tableSize, $dataSource) = filterSortPage($dataSource);
        $smarty->assign("T_TABLE_SIZE", $tableSize);
    }
    if (!empty($dataSource)) {
        $smarty->assign("T_DATA_SOURCE", $dataSource);
    }
    $smarty->assign("T_SORTED_TABLE", $tableName);
    if ($benchmark) {
        $benchmark->set('script');
    }
    $smarty->display($_SESSION['s_type'] . '.tpl');
    if ($benchmark) {
        $benchmark->set('smarty');
        $benchmark->stop();
        $output = $benchmark->display();
        if (G_DEBUG) {
            echo $output;
        }
    }
    exit;
}
 public function getSmartyTpl()
 {
     $currentUser = $this->getCurrentUser();
     $smarty = $this->getSmartyVar();
     $ranges = $this->getRanges();
     $smarty->assign("T_GRADEBOOK_BASEURL", $this->moduleBaseUrl);
     $smarty->assign("T_GRADEBOOK_BASELINK", $this->moduleBaseLink);
     if ($currentUser->getRole($this->getCurrentLesson()) == 'professor') {
         $currentLesson = $this->getCurrentLesson();
         $currentLessonID = $currentLesson->lesson['id'];
         $lessonUsers = $currentLesson->getUsers('student');
         // get all students that have this lesson
         $lessonColumns = $this->getLessonColumns($currentLessonID);
         $allUsers = $this->getLessonUsers($currentLessonID, $lessonColumns);
         $gradeBookLessons = $this->getGradebookLessons($currentUser->getLessons(false, 'professor'), $currentLessonID);
     } else {
         if ($currentUser->getRole($this->getCurrentLesson()) == 'student') {
             $currentLesson = $this->getCurrentLesson();
             $currentLessonID = $currentLesson->lesson['id'];
         }
     }
     if (isset($_GET['import_grades']) && eF_checkParameter($_GET['import_grades'], 'id') && in_array($_GET['import_grades'], array_keys($lessonColumns))) {
         $object = eF_getTableData("module_gradebook_objects", "creator", "id=" . $_GET['import_grades']);
         //if($object[0]['creator'] != $_SESSION['s_login']){
         if ($currentUser->getRole($this->getCurrentLesson()) != 'professor') {
             eF_redirect($this->moduleBaseUrl . "&message=" . urlencode(_GRADEBOOK_NOACCESS));
             exit;
         }
         $result = eF_getTableData("module_gradebook_objects", "refers_to_type, refers_to_id", "id=" . $_GET['import_grades']);
         $type = $result[0]['refers_to_type'];
         $id = $result[0]['refers_to_id'];
         $oid = $_GET['import_grades'];
         foreach ($lessonUsers as $userLogin => $value) {
             $this->importGrades($type, $id, $oid, $userLogin);
         }
     } else {
         if (isset($_GET['delete_column']) && eF_checkParameter($_GET['delete_column'], 'id') && in_array($_GET['delete_column'], array_keys($lessonColumns))) {
             $object = eF_getTableData("module_gradebook_objects", "creator", "id=" . $_GET['delete_column']);
             //if($object[0]['creator'] != $_SESSION['s_login']){
             if ($currentUser->getRole($this->getCurrentLesson()) != 'professor') {
                 eF_redirect($this->moduleBaseUrl . "&message=" . urlencode(_GRADEBOOK_NOACCESS));
                 exit;
             }
             eF_deleteTableData("module_gradebook_objects", "id=" . $_GET['delete_column']);
             eF_deleteTableData("module_gradebook_grades", "oid=" . $_GET['delete_column']);
         } else {
             if (isset($_GET['compute_score_grade']) && $_GET['compute_score_grade'] == '1') {
                 foreach ($allUsers as $uid => $student) {
                     $this->computeScoreGrade($lessonColumns, $ranges, $student['users_LOGIN'], $uid);
                 }
             } else {
                 if (isset($_GET['export_excel']) && ($_GET['export_excel'] == 'one' || $_GET['export_excel'] == 'all')) {
                     require_once 'Spreadsheet/Excel/Writer.php';
                     $workBook = new Spreadsheet_Excel_Writer();
                     $workBook->setTempDir(G_UPLOADPATH);
                     $workBook->setVersion(8);
                     $workBook->send('GradeBook.xls');
                     if ($_GET['export_excel'] == 'one') {
                         $workSheet =& $workBook->addWorksheet($currentLesson->lesson['name']);
                         $this->professorLessonToExcel($currentLessonID, $currentLesson->lesson['name'], $workBook, $workSheet);
                     } else {
                         if ($_GET['export_excel'] == 'all') {
                             $professorLessons = $currentUser->getLessons(false, 'professor');
                             foreach ($professorLessons as $key => $value) {
                                 $subLesson = new EfrontLesson($key);
                                 $subLessonUsers = $subLesson->getUsers('student');
                                 // get all students that have this lesson
                                 $result = eF_getTableData("module_gradebook_users", "count(uid) as total_users", "lessons_ID=" . $key);
                                 if ($result[0]['total_users'] != 0) {
                                     // module installed for this lesson
                                     $workSheet =& $workBook->addWorksheet($subLesson->lesson['name']);
                                     $this->professorLessonToExcel($key, $subLesson->lesson['name'], $workBook, $workSheet);
                                 }
                             }
                         }
                     }
                     $workBook->close();
                     exit;
                 } else {
                     if (isset($_GET['export_student_excel']) && ($_GET['export_student_excel'] == 'current' || $_GET['export_student_excel'] == 'all')) {
                         require_once 'Spreadsheet/Excel/Writer.php';
                         $workBook = new Spreadsheet_Excel_Writer();
                         $workBook->setTempDir(G_UPLOADPATH);
                         $workBook->setVersion(8);
                         $workBook->send('GradeBook.xls');
                         if ($_GET['export_student_excel'] == 'current') {
                             $workSheet =& $workBook->addWorksheet($currentLesson->lesson['name']);
                             $this->studentLessonToExcel($currentLessonID, $currentLesson->lesson['name'], $currentUser, $workBook, $workSheet);
                         } else {
                             if ($_GET['export_student_excel'] == 'all') {
                                 $studentLessons = $currentUser->getLessons(false, 'student');
                                 foreach ($studentLessons as $key => $value) {
                                     // Is GradeBook installed for this lesson ?
                                     $installed = eF_getTableData("module_gradebook_users", "*", "lessons_ID=" . $key . " and users_LOGIN='******'login'] . "'");
                                     if (sizeof($installed) != 0) {
                                         $subLesson = new EfrontLesson($key);
                                         $workSheet =& $workBook->addWorksheet($subLesson->lesson['name']);
                                         $this->studentLessonToExcel($key, $subLesson->lesson['name'], $currentUser, $workBook, $workSheet);
                                     }
                                 }
                             }
                         }
                         $workBook->close();
                         exit;
                     } else {
                         if (isset($_GET['switch_lesson']) && eF_checkParameter($_GET['switch_lesson'], 'id') && in_array($_GET['switch_lesson'], array_keys($gradeBookLessons))) {
                             $lessonID = $_GET['switch_lesson'];
                             eF_redirect("location:" . $this->moduleBaseUrl . "&lessons_ID=" . $lessonID);
                         }
                     }
                 }
             }
         }
     }
     if (isset($_GET['delete_range']) && eF_checkParameter($_GET['delete_range'], 'id') && in_array($_GET['delete_range'], array_keys($ranges))) {
         try {
             eF_deleteTableData("module_gradebook_ranges", "id=" . $_GET['delete_range']);
         } catch (Exception $e) {
             handleAjaxExceptions($e);
         }
         exit;
     } else {
         if (isset($_GET['add_range']) || isset($_GET['edit_range']) && eF_checkParameter($_GET['edit_range'], 'id') && in_array($_GET['edit_range'], array_keys($ranges))) {
             $grades = array();
             for ($i = 0; $i <= 100; $i++) {
                 $grades[$i] = $i;
             }
             isset($_GET['add_range']) ? $postTarget = "&add_range=1" : ($postTarget = "&edit_range=" . $_GET['edit_range']);
             $form = new HTML_QuickForm("add_range_form", "post", $this->moduleBaseUrl . $postTarget, "", null, true);
             $form->registerRule('checkParameter', 'callback', 'eF_checkParameter');
             // XXX
             $form->addElement('select', 'range_from', _GRADEBOOK_RANGE_FROM, $grades);
             $form->addElement('select', 'range_to', _GRADEBOOK_RANGE_TO, $grades);
             $form->addElement('text', 'grade', _GRADEBOOK_GRADE, 'class = "inputText"');
             $form->addRule('grade', _THEFIELD . ' "' . _GRADEBOOK_GRADE . '" ' . _ISMANDATORY, 'required', null, 'client');
             $form->addRule('grade', _INVALIDFIELDDATA, 'checkParameter', 'text');
             // XXX
             $form->addElement('submit', 'submit', _SUBMIT, 'class = "flatButton"');
             if (isset($_GET['edit_range'])) {
                 $editRange = $ranges[$_GET['edit_range']];
                 $form->setDefaults($editRange);
             }
             if ($form->isSubmitted() && $form->validate()) {
                 $error = $invalid_range = false;
                 $values = $form->exportValues();
                 $fields = array("range_from" => $values['range_from'], "range_to" => $values['range_to'], "grade" => $values['grade']);
                 if (isset($_GET['edit_range'])) {
                     // do not check it below ...
                     unset($ranges[$_GET['edit_range']]);
                 }
                 foreach ($ranges as $range) {
                     if ($range['grade'] == $fields['grade']) {
                         $message = _GRADEBOOK_GRADE . " '" . $fields['grade'] . "' " . _GRADEBOOK_ALREADY_EXISTS;
                         $message_type = 'failure';
                         $error = true;
                         break;
                     }
                     if ($fields['range_from'] >= $range['range_from'] && $fields['range_to'] <= $range['range_to']) {
                         $invalid_range = true;
                     }
                     if ($fields['range_from'] >= $range['range_from'] && $fields['range_from'] < $range['range_to'] && $fields['range_to'] >= $range['range_to']) {
                         $invalid_range = true;
                     }
                     if ($fields['range_to'] > $range['range_from'] && $fields['range_to'] <= $range['range_to']) {
                         $invalid_range = true;
                     }
                     if ($fields['range_from'] <= $range['range_from'] && $fields['range_to'] >= $range['range_to']) {
                         $invalid_range = true;
                     }
                     if ($invalid_range) {
                         $message = _GRADEBOOK_INVALID_RANGE . ". " . _GRADEBOOK_RANGE;
                         $message .= " [" . $range['range_from'] . ", " . $range['range_to'] . "]" . " " . _GRADEBOOK_ALREADY_EXISTS;
                         $message_type = 'failure';
                         $error = true;
                         break;
                     }
                 }
                 if ($fields['range_from'] > $fields['range_to']) {
                     $message = _GRADEBOOK_RANGE_FROM . ' ' . _GRADEBOOK_GRATER_THAN . ' ' . _GRADEBOOK_RANGE_TO;
                     $message_type = 'failure';
                     $error = true;
                 }
                 if ($error == false) {
                     if (isset($_GET['add_range'])) {
                         if (eF_insertTableData("module_gradebook_ranges", $fields)) {
                             $smarty->assign("T_GRADEBOOK_MESSAGE", _GRADEBOOK_RANGE_SUCCESSFULLY_ADDED);
                         } else {
                             $message = _GRADEBOOK_RANGE_ADD_PROBLEM;
                             $message_type = 'failure';
                         }
                     } else {
                         if (eF_updateTableData("module_gradebook_ranges", $fields, "id=" . $_GET['edit_range'])) {
                             $smarty->assign("T_GRADEBOOK_MESSAGE", _GRADEBOOK_RANGE_SUCCESSFULLY_EDITED);
                         } else {
                             $message = _GRADEBOOK_RANGE_EDIT_PROBLEM;
                             $message_type = 'failure';
                         }
                     }
                 }
             }
             $renderer = prepareFormRenderer($form);
             $form->accept($renderer);
             $smarty->assign('T_GRADEBOOK_ADD_EDIT_RANGE_FORM', $renderer->toArray());
         } else {
             if (isset($_GET['add_column'])) {
                 $tests = $currentLesson->getTests(true, true);
                 $scormTests = $currentLesson->getScormTests();
                 $projects = $currentLesson->getProjects(false);
                 $weights = array();
                 $refersTo = array("real_world" => _GRADEBOOK_REAL_WORLD_OBJECT, "progress" => _LESSONPROGRESS);
                 for ($i = 1; $i <= 10; $i++) {
                     $weights[$i] = $i;
                 }
                 if ($currentLesson->options['tests'] == 1) {
                     foreach ($tests as $key => $test) {
                         $refersTo['test_' . $key] = _TEST . ': ' . $test->test['name'];
                     }
                 }
                 if ($currentLesson->options['scorm'] == 1) {
                     foreach ($scormTests as $key => $scormTest) {
                         $scorm = eF_getTableData("content", "name", "id=" . $scormTest);
                         $refersTo['scormtest_' . $scormTest] = _SCORM . ' ' . _TEST . ': ' . $scorm[0]['name'];
                     }
                 }
                 if ($currentLesson->options['projects'] == 1) {
                     foreach ($projects as $key => $project) {
                         $refersTo['project_' . $key] = _PROJECT . ': ' . $project['title'];
                     }
                 }
                 $form = new HTML_QuickForm("add_column_form", "post", $this->moduleBaseUrl . "&add_column=1", "", null, true);
                 $form->addElement('text', 'column_name', _GRADEBOOK_COLUMN_NAME, 'class = "inputText"');
                 $form->addElement('select', 'column_weight', _GRADEBOOK_COLUMN_WEIGHT, $weights);
                 $form->addElement('select', 'column_refers_to', _GRADEBOOK_COLUMN_REFERS_TO, $refersTo);
                 $form->addRule('column_name', _THEFIELD . ' "' . _GRADEBOOK_COLUMN_NAME . '" ' . _ISMANDATORY, 'required', null, 'client');
                 $form->addElement('submit', 'submit', _SUBMIT, 'class = "flatButton"');
                 if ($form->isSubmitted() && $form->validate()) {
                     $values = $form->exportValues();
                     $fields = array("name" => $values['column_name'], "weight" => $values['column_weight'], "lessons_ID" => $currentLessonID, "creator" => $_SESSION['s_login']);
                     if ($values['column_refers_to'] == "real_world") {
                         $fields['refers_to_type'] = 'real_world';
                         $fields['refers_to_id'] = -1;
                     } else {
                         if ($values['column_refers_to'] == "progress") {
                             $fields['refers_to_type'] = 'progress';
                             $fields['refers_to_id'] = $currentLessonID;
                         } else {
                             $type = explode('_', $values['column_refers_to']);
                             $fields['refers_to_type'] = $type[0];
                             $fields['refers_to_id'] = $type[1];
                         }
                     }
                     if ($objectID = eF_insertTableData("module_gradebook_objects", $fields)) {
                         $smarty->assign("T_GRADEBOOK_MESSAGE", _GRADEBOOK_COLUMN_SUCCESSFULLY_ADDED);
                         foreach ($lessonUsers as $userLogin => $value) {
                             $fieldsGrades = array("oid" => $objectID, "grade" => -1, "users_LOGIN" => $userLogin);
                             if (eF_insertTableData("module_gradebook_grades", $fieldsGrades)) {
                                 $smarty->assign("T_GRADEBOOK_MESSAGE", _GRADEBOOK_COLUMN_SUCCESSFULLY_ADDED);
                             } else {
                                 $message = _GRADEBOOK_COLUMN_ADD_PROBLEM;
                                 $message_type = 'failure';
                             }
                         }
                     } else {
                         $message = _GRADEBOOK_COLUMN_ADD_PROBLEM;
                         $message_type = 'failure';
                     }
                 }
                 $renderer = prepareFormRenderer($form);
                 $form->accept($renderer);
                 $smarty->assign('T_GRADEBOOK_ADD_COLUMN_FORM', $renderer->toArray());
             } else {
                 if (isset($_GET['edit_publish']) && isset($_GET['uid']) && isset($_GET['publish']) && eF_checkParameter($_GET['uid'], 'id') && in_array($_GET['uid'], array_keys($allUsers))) {
                     try {
                         $publish = !$allUsers[$_GET['uid']]['publish'];
                         eF_updateTableData("module_gradebook_users", array("publish" => $publish), "uid=" . $_GET['uid']);
                         echo json_encode(array('publish' => $publish));
                     } catch (Exception $e) {
                         handleAjaxExceptions($e);
                     }
                     exit;
                 } else {
                     if (isset($_GET['complete_lesson']) && isset($_GET['uid']) && eF_checkParameter($_GET['uid'], 'id') && in_array($_GET['uid'], array_keys($allUsers))) {
                         try {
                             $user = $allUsers[$_GET['uid']];
                             eF_updateTableData("users_to_lessons", array("completed" => 1, 'score' => $user['score']), "lessons_ID= " . $user['lessons_ID'] . " and users_LOGIN='******'users_LOGIN'] . "'");
                             echo json_encode(array('completed' => 1));
                         } catch (Exception $e) {
                             handleAjaxExceptions($e);
                         }
                         exit;
                     } else {
                         if (isset($_GET['change_grade']) && isset($_GET['grade']) && eF_checkParameter($_GET['change_grade'], 'id')) {
                             $newGrade = $_GET['grade'];
                             try {
                                 if ($newGrade != '') {
                                     if (!is_numeric($newGrade) || $newGrade > 100) {
                                         throw new EfrontContentException(_GRADEBOOK_INVALID_GRADE . ': "' . $newGrade . '". ' . _GRADEBOOK_VALID_GRADE_SPECS, EfrontContentException::INVALID_SCORE);
                                     }
                                 } else {
                                     $newGrade = -1;
                                 }
                                 $newGrade = str_replace(',', '.', $newGrade);
                                 eF_updateTableData("module_gradebook_grades", array("grade" => $newGrade), "gid=" . $_GET['change_grade']);
                             } catch (Exception $e) {
                                 header("HTTP/1.0 500");
                                 echo rawurlencode($e->getMessage());
                             }
                             exit;
                         } else {
                             $smarty->assign("T_GRADEBOOK_RANGES", $ranges);
                             if ($currentUser->getRole($this->getCurrentLesson()) == 'professor') {
                                 /* Add new students to GradeBook related tables */
                                 $result = eF_getTableData("module_gradebook_users", "users_LOGIN", "lessons_ID=" . $currentLessonID);
                                 $allLogins = array();
                                 foreach ($result as $user) {
                                     array_push($allLogins, $user['users_LOGIN']);
                                 }
                                 if (sizeof($result) != sizeof($lessonUsers)) {
                                     // FIXME
                                     $lessonColumns = $this->getLessonColumns($currentLessonID);
                                     foreach ($lessonUsers as $userLogin => $value) {
                                         if (!in_array($userLogin, $allLogins)) {
                                             $userFields = array("users_LOGIN" => $userLogin, "lessons_ID" => $currentLessonID, "score" => -1, "grade" => '-1');
                                             $uid = eF_insertTableData("module_gradebook_users", $userFields);
                                             foreach ($lessonColumns as $key => $column) {
                                                 $fieldsGrades = array("oid" => $key, "grade" => -1, "users_LOGIN" => $userLogin);
                                                 $type = $column['refers_to_type'];
                                                 $id = $column['refers_to_id'];
                                                 eF_insertTableData("module_gradebook_grades", $fieldsGrades);
                                                 if ($type != 'real_world') {
                                                     $this->importGrades($type, $id, $key, $userLogin);
                                                 }
                                             }
                                             $this->computeScoreGrade($lessonColumns, $ranges, $userLogin, $uid);
                                         }
                                     }
                                 }
                                 /* End */
                                 $lessonColumns = $this->getLessonColumns($currentLessonID);
                                 //$allUsers = $this->getLessonUsers($currentLessonID, $lessonColumns);	//we got this earlier
                                 $gradeBookLessons = $this->getGradebookLessons($currentUser->getLessons(false, 'professor'), $currentLessonID);
                                 $smarty->assign("T_GRADEBOOK_LESSON_COLUMNS", $lessonColumns);
                                 $smarty->assign("T_GRADEBOOK_GRADEBOOK_LESSONS", $gradeBookLessons);
                                 //Added by makriria because of #4613
                                 foreach ($allUsers as $key => $value) {
                                     if (!isset($lessonUsers[$value['users_LOGIN']])) {
                                         unset($allUsers[$key]);
                                     }
                                 }
                                 if ($_GET['ajax'] == 'usersTable') {
                                     list($tableSize, $allUsers) = filterSortPage($allUsers);
                                     $smarty->assign("T_SORTED_TABLE", $_GET['ajax']);
                                     $smarty->assign("T_TABLE_SIZE", $tableSize);
                                     $smarty->assign("T_DATA_SOURCE", $allUsers);
                                 }
                                 //$smarty->assign("T_DATA_SOURCE", $allUsers);
                             } else {
                                 if ($currentUser->getRole($this->getCurrentLesson()) == 'student') {
                                     $lessonColumns = $this->getLessonColumns($currentLessonID);
                                     $studentGrades = $this->getStudentGrades($currentUser, $currentLessonID, $lessonColumns);
                                     $smarty->assign("T_GRADEBOOK_LESSON_COLUMNS", $lessonColumns);
                                     $smarty->assign("T_GRADEBOOK_STUDENT_GRADES", $studentGrades);
                                     $smarty->assign("T_GRADEBOOK_CURRENT_LESSON_NAME", $currentLesson->lesson['name']);
                                     // Show all my lessons
                                     $studentLessons = $currentUser->getLessons(false, 'student');
                                     $studentLessonsNames = array();
                                     $studentLessonsColumns = array();
                                     $studentLessonsGrades = array();
                                     foreach ($studentLessons as $key => $value) {
                                         // Is GradeBook installed for this lesson ?
                                         $installed = eF_getTableData("module_gradebook_users", "*", "lessons_ID=" . $key . " and users_LOGIN='******'login'] . "'");
                                         if (sizeof($installed) != 0) {
                                             $lesson = new EfrontLesson($key);
                                             $columns = $this->getLessonColumns($key);
                                             $grades = $this->getStudentGrades($currentUser, $key, $columns);
                                             array_push($studentLessonsNames, $lesson->lesson['name']);
                                             $studentLessonsColumns[$lesson->lesson['name']] = $columns;
                                             $studentLessonsGrades[$lesson->lesson['name']] = $grades;
                                         }
                                     }
                                     $smarty->assign("T_GRADEBOOK_STUDENT_LESSON_NAMES", $studentLessonsNames);
                                     $smarty->assign("T_GRADEBOOK_STUDENT_LESSON_COLUMNS", $studentLessonsColumns);
                                     $smarty->assign("T_GRADEBOOK_STUDENT_LESSON_GRADES", $studentLessonsGrades);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($message) {
         $this->setMessageVar($message, $message_type);
     }
     if ($currentUser->getType() == 'administrator') {
         return $this->moduleBaseDir . "module_gradebook_admin.tpl";
     } else {
         if ($currentUser->getRole($this->getCurrentLesson()) == 'professor') {
             return $this->moduleBaseDir . "module_gradebook_professor.tpl";
         } else {
             if ($currentUser->getRole($this->getCurrentLesson()) == 'student') {
                 return $this->moduleBaseDir . "module_gradebook_student.tpl";
             }
         }
     }
 }
 /**
  * The main functionality
  *
  * (non-PHPdoc)
  * @see libraries/EfrontModule#getModule()
  */
 public function getModule()
 {
     $smarty = $this->getSmartyVar();
     $smarty->assign("T_MODULE_BASEDIR", $this->moduleBaseDir);
     $smarty->assign("T_MODULE_BASELINK", $this->moduleBaseLink);
     $smarty->assign("T_MODULE_BASEURL", $this->moduleBaseUrl);
     $currentUser = $this->getCurrentUser();
     if ($currentUser->user['user_type'] != 'administrator') {
         $currentEmployee = $this->getCurrentUser()->aspects['hcd'];
         if (!$currentEmployee || !$currentEmployee->isSupervisor()) {
             throw new Exception("You cannot access this module");
         }
     }
     $form = new HTML_QuickForm("user_activity_form", "post", basename($_SERVER['PHP_SELF']) . "?ctg=module&op=module_idle_users&tab=user_activity", "", null, true);
     $form->addElement('date', 'idle_from_timestamp', _MODULE_IDLE_USERS_SHOWINACTIVEUSERSSINCE, array('minYear' => 2005, 'maxYear' => date("Y")));
     $form->addElement("static", "", '<a href = "javascript:void(0)" onclick = "setFormDate(' . date("Y") . ',' . date("m") . ',' . (date("d") - 7) . ')">' . _LASTWEEK . '</a> - <a href = "javascript:void(0)" onclick = "setFormDate(' . date("Y") . ',' . (date("m") - 1) . ',' . date("d") . ')">' . _LASTMONTH . '</a> - <a href = "javascript:void(0)" onclick = "setFormDate(' . date("Y") . ',' . (date("m") - 3) . ',' . date("d") . ')">' . _MODULE_IDLE_USERS_LAST3MONTHS . '</a>');
     $form->addElement("submit", "submit", _SUBMIT, 'class = "flatButton"');
     if (!isset($_SESSION['timestamp_from'])) {
         $_SESSION['timestamp_from'] = time() - 86400 * 30;
     }
     $form->setDefaults(array("idle_from_timestamp" => $_SESSION['timestamp_from']));
     if ($form->isSubmitted() && $form->validate()) {
         $values = $form->exportValues();
         $_SESSION['timestamp_from'] = mktime(0, 0, 0, $values['idle_from_timestamp']['M'], $values['idle_from_timestamp']['d'], $values['idle_from_timestamp']['Y']);
     }
     $smarty->assign("T_IDLE_USER_FORM", $form->toArray());
     try {
         if ($currentEmployee) {
             if ($_SESSION['s_current_branch'] && in_array($_SESSION['s_current_branch'], $currentEmployee->supervisesBranches)) {
                 $currentBranch = new EfrontBranch($_SESSION['s_current_branch']);
                 $subbranches = $currentBranch->getSubbranches();
                 foreach ($subbranches as $subbranch) {
                     $branches[$subbranch['branch_ID']] = $subbranch['branch_ID'];
                 }
                 $branches[$_SESSION['s_current_branch']] = $_SESSION['s_current_branch'];
                 $result = eF_getTableData("users u JOIN module_hcd_employee_works_at_branch ewb on ewb.users_login=u.login", "u.login,u.name,u.surname,u.active,u.last_login as last_action", "ewb.branch_ID in (" . implode(',', $branches) . ") and u.last_login is null or u.last_login <= " . $_SESSION['timestamp_from']);
                 //$result = eF_getTableData("(select login,name,surname,active,max(l.timestamp) as last_action from users u left outer join logs l on u.login=l.users_LOGIN where u.archive=0 group by login) r join module_hcd_employee_works_at_branch ewb on ewb.users_login=r.login", "*", "ewb.branch_ID in (".implode(',', $branches) .") and (r.last_action is null or r.last_action <= ".$_SESSION['timestamp_from'].")");
             } else {
                 $result = eF_getTableData("users u JOIN module_hcd_employee_works_at_branch ewb on ewb.users_login=u.login", "u.login,u.name,u.surname,u.active,u.last_login as last_action", "ewb.branch_ID in (" . implode(',', $currentEmployee->supervisesBranches) . ") and u.last_login is null or u.last_login <= " . $_SESSION['timestamp_from']);
                 //$result = eF_getTableData("(select login,name,surname,active,max(l.timestamp) as last_action from users u left outer join logs l on u.login=l.users_LOGIN where u.archive=0 group by login) r join module_hcd_employee_works_at_branch ewb on ewb.users_login=r.login", "*", "ewb.branch_ID in (".implode(',', $currentEmployee->supervisesBranches).") and (r.last_action is null or r.last_action <= ".$_SESSION['timestamp_from'].")");
             }
         } else {
             $result = eF_getTableData("users", "login,name,surname,active,last_login as last_action", "last_login is null or last_login <= " . $_SESSION['timestamp_from']);
         }
         $users = array();
         foreach ($result as $value) {
             if ($value['last_action']) {
                 $value['last_action_since'] = eF_convertIntervalToTime(time() - $value['last_action'], true);
             } else {
                 $value['last_action_since'] = null;
             }
             $users[$value['login']] = $value;
         }
         foreach ($users as $key => $value) {
             if (isset($_COOKIE['toggle_active'])) {
                 if ($_COOKIE['toggle_active'] == 1 && !$value['active'] || $_COOKIE['toggle_active'] == -1 && $value['active']) {
                     unset($users[$key]);
                 }
             }
         }
         if (isset($_GET['excel'])) {
             $export_users[] = array(_USER, _MODULE_IDLE_USERS_LASTACTION, _STATUS);
             foreach ($users as $key => $value) {
                 $value['last_action'] ? $last_action = formatTimestamp($value['last_action']) : ($last_action = _NEVER);
                 $value['active'] ? $status = _ACTIVE : ($status = _INACTIVE);
                 $export_users[] = array(formatLogin($value['login']), $last_action, $status);
             }
             EfrontSystem::exportToCsv($export_users, true);
             exit;
         }
         if ($_GET['ajax'] == 'idleUsersTable') {
             list($tableSize, $users) = filterSortPage($users);
             $smarty->assign("T_SORTED_TABLE", $_GET['ajax']);
             $smarty->assign("T_TABLE_SIZE", $tableSize);
             $smarty->assign("T_DATA_SOURCE", $users);
         }
         if (isset($_GET['ajax']) && isset($_GET['archive_user'])) {
             if (isset($users[$_GET['archive_user']])) {
                 $user = EfrontUserFactory::factory($_GET['archive_user']);
                 $user->archive();
             }
             exit;
         } else {
             if (isset($_GET['ajax']) && isset($_GET['archive_all_users'])) {
                 //eF_updateTableData("users", array("archive" => 1, "active" => 0), "login in (select login from (select login,max(l.timestamp) as last_action from users u left outer join logs l on u.login=l.users_LOGIN where u.archive=0 and u.login != '".$_SESSION['s_login']."' group by login) r where r.last_action <= ".$_SESSION['timestamp_from']." or r.last_action is null)");
                 foreach ($users as $value) {
                     eF_updateTableData("users", array("archive" => 1, "active" => 0), "login='******'login'] . "'");
                 }
                 exit;
             } else {
                 if (isset($_GET['ajax']) && isset($_GET['toggle_user'])) {
                     if (isset($users[$_GET['toggle_user']])) {
                         $user = EfrontUserFactory::factory($_GET['toggle_user']);
                         if ($user->user['active']) {
                             $user->deactivate();
                         } else {
                             $user->activate();
                         }
                         echo json_encode(array('status' => 1, 'active' => $user->user['active']));
                     }
                     exit;
                 } else {
                     if (isset($_GET['ajax']) && isset($_GET['deactivate_all_users'])) {
                         //eF_updateTableData("users", array("active" => 0), "login in (select login from (select login,max(l.timestamp) as last_action from users u left outer join logs l on u.login=l.users_LOGIN where u.archive=0 and u.login != '".$_SESSION['s_login']."' group by login) r where r.last_action <= ".$_SESSION['timestamp_from']." or r.last_action is null)");
                         foreach ($users as $value) {
                             eF_updateTableData("users", array("active" => 0), "login='******'login'] . "'");
                         }
                         exit;
                     }
                 }
             }
         }
     } catch (Exception $e) {
         handleAjaxExceptions($e);
     }
     return true;
 }
 /**
  * Code to execute on the lesson page
  *
  * (non-PHPdoc)
  * @see libraries/EfrontModule#getLessonModule()
  */
 public function getLessonModule()
 {
     $currentLesson = $this->getCurrentLesson();
     if ($currentLesson && !$currentLesson->options['digital_library']) {
         $smarty = $this->getSmartyVar();
         $smarty->assign("T_MODULE_BASEDIR", $this->moduleBaseDir);
         $smarty->assign("T_MODULE_BASELINK", $this->moduleBaseLink);
         $smarty->assign("T_MODULE_BASEURL", $this->moduleBaseUrl);
         $result = eF_getTableDataFlat("module_shared_files", "path", "lessons_ID=" . $currentLesson->lesson['id']);
         $lessonSharedFiles = $result['path'];
         $basedir = new EfrontDirectory($currentLesson->getDirectory());
         if ($_GET['other']) {
             $directory = new EfrontDirectory($_GET['other']);
             if (strpos($directory['path'], $basedir['path']) !== false && strcmp($directory['path'], $basedir['path'])) {
                 $basedir = $directory;
                 $smarty->assign("T_PARENT_DIR", dirname($basedir['path']));
             }
         }
         $smarty->assign("T_CURRENT_DIR", str_replace($currentLesson->getDirectory(), "", $basedir['path']));
         $filesystem = new FileSystemTree($basedir, true);
         $files = $directories = array();
         foreach ($filesystem->tree as $key => $value) {
             if (in_array($key, $lessonSharedFiles)) {
                 $value['image'] = $value->getTypeImage();
                 if (strpos($value['mime_type'], "image") !== false || strpos($value['mime_type'], "text") !== false || strpos($value['mime_type'], "pdf") !== false || strpos($value['mime_type'], "html") !== false || strpos($value['mime_type'], "flash") !== false) {
                     $value['preview'] = true;
                 }
                 if ($value instanceof EfrontFile) {
                     $files[$key] = (array) $value;
                 } elseif ($value instanceof EfrontDirectory) {
                     $value['size'] = 0;
                     $directories[$key] = (array) $value;
                 }
             }
         }
         $tableName = "sharedFilesTable";
         $dataSource = array_merge($directories, $files);
         if (isset($_GET['ajax']) && $_GET['ajax'] == "sharedFilesTable") {
             list($tableSize, $dataSource) = filterSortPage($dataSource);
             $smarty->assign("T_TABLE_SIZE", $tableSize);
             if (!empty($dataSource)) {
                 $smarty->assign("T_DATA_SOURCE", $dataSource);
             }
         }
         return true;
     }
 }