Exemplo n.º 1
0
         if ($form->isSubmitted() && $form->validate()) {
             $cloneTemplate = eF_getTableData("certificate_templates", "certificate_xml", "id=" . $tid);
             $formValues = $form->exportValues();
             $dbFields = array("certificate_name" => $formValues['certificate_name'], "certificate_xml" => $cloneTemplate[0]['certificate_xml'], "certificate_type" => "course", "users_LOGIN" => $GLOBALS['currentUser']->user['login']);
             if ($cloned = eF_insertTableData("certificate_templates", $dbFields)) {
                 $message = _SUCCESSFULLYCLONECERTIFICATETEMPLATE;
                 $message_type = 'success';
             } else {
                 $message = _PROBLEMCLONECERTIFICATETEMPLATE;
                 $message_type = 'failure';
             }
             $redirectUrl = "" . basename($_SERVER['PHP_SELF']) . "?" . $baseUrl . "&op=format_certificate&message=" . urlencode($message);
             $redirectUrl .= "&message_type=" . $message_type . "&reset_popup=1&tid=" . $cloned;
             $smarty->assign('T_CLONE_CERTIFICATE_TEMPLATE_REDIRECT', $redirectUrl);
         }
         $renderer = prepareFormRenderer($form);
         $smarty->assign('T_CLONE_CERTIFICATE_TEMPLATE_FORM', $renderer->toArray());
     }
     #cpp#endif
 } else {
     if ($_GET['op'] == 'delete_certificate_template') {
         if (G_VERSIONTYPE != 'community') {
             #cpp#ifndef COMMUNITY
             if ($_SESSION['s_type'] != 'administrator') {
                 $templates = eF_getTableData("certificate_templates", "id, certificate_name, certificate_type", "certificate_type='main' OR id='" . $currentCourse->options['certificate_tpl_id'] . "' OR users_LOGIN='******'currentUser']->user['login'] . "'", "certificate_name");
             } else {
                 $templates = eF_getTableData("certificate_templates", "id, certificate_name, certificate_type", "", "certificate_name");
             }
             foreach ($templates as $key => $value) {
                 $userTemplates[$value['id']] = $value['id'];
             }
 /**
  * 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);
     $smarty->assign("T_TABLE_OPTIONS", array(array('image' => $this->moduleBaseLink . 'img/order.png', 'text' => _MODULE_SECURITY_RECHECKLOCALFILES, 'href' => $this->moduleBaseUrl . '&delete_local_list=1'), array('image' => $this->moduleBaseLink . 'img/refresh.png', 'text' => _MODULE_SECURITY_RECHECKSERVERFILES, 'href' => $this->moduleBaseUrl . '&delete_remote_list=1'), array('image' => $this->moduleBaseLink . 'img/rules.png', 'text' => _MODULE_SECURITY_RESETIGNORELIST, 'href' => $this->moduleBaseUrl . '&delete_ignore_list=1')));
     if (isset($_GET['download_ignore_list'])) {
         try {
             $file = new EfrontFile($this->getIgnoreListName());
             $file->sendFile(true);
         } catch (Exception $e) {
             $this->setMessageVar('The list is empty', 'failure');
         }
     } else {
         if ($_GET['delete_remote_list']) {
             $file = new EfrontFile($this->getCachedRemoteListName());
             $file->delete();
         } else {
             if ($_GET['delete_local_list']) {
                 $file = new EfrontFile($this->getLocalListName());
                 $file->delete();
             } else {
                 if ($_GET['delete_ignore_list']) {
                     try {
                         $file = new EfrontFile($this->getIgnoreListName());
                         $file->delete();
                     } catch (Exception $e) {
                     }
                 }
             }
         }
     }
     if (isset($_GET['download'])) {
         $_GET['download'] = base64_decode($_GET['download']);
     }
     $form = new HTML_QuickForm("demo_form", "post", $this->moduleBaseUrl . "&type=" . $_GET['type'], "", null, true);
     switch ($_GET['type']) {
         case 'install':
             $form->addElement('submit', 'submit_delete_install', _MODULE_SECURITY_DELETEINSTALLDIRECTORY, 'class = "flatButton"');
             break;
         case 'magic_quotes_gpc':
             break;
         case 'default_accounts':
             $form->addElement('submit', 'submit_deactivate', _MODULE_SECURITY_DEACTIVATEDEFAULTACCOUNTS, 'class = "flatButton"  title = "Click this to deactivate these accounts"');
             break;
         case 'changed_files':
             list($changed_files, $new_files) = $this->checksumCheck();
             $smarty->assign("T_CHANGED_FILES", $changed_files);
             if (isset($_GET['download']) && in_array($_GET['download'], array_keys($changed_files)) && $_GET['download'] != 'libraries/configuration.php') {
                 try {
                     $file = new EfrontFile(G_ROOTPATH . $_GET['download']);
                     $file->sendFile(true);
                     exit;
                 } catch (Exception $e) {
                     $this->setMessageVar(_MODULE_SECURITY_FILECOULDNOTBEDELETED, 'failure');
                 }
             } else {
                 if (isset($_GET['ignore']) && in_array($_GET['ignore'], array_keys($changed_files))) {
                     $this->addToIgnoreList($_GET['ignore']);
                     echo json_encode(array('success' => true));
                     exit;
                 }
             }
             $form->addElement('submit', 'submit_recheck', _MODULE_SECURITY_RECHECKFILES, 'class = "flatButton" ');
             $form->addElement('submit', 'reset_ignore_list', _MODULE_SECURITY_RESETIGNORELIST, 'class = "flatButton" ');
             $form->addElement('submit', 'ignore_changed_all', _MODULE_SECURITY_IGNOREALL, 'class = "flatButton" ');
             break;
         case 'new_files':
             list($changed_files, $new_files) = $this->checksumCheck();
             if (isset($_GET['download']) && in_array($_GET['download'], array_keys($new_files)) && $_GET['download'] != 'libraries/configuration.php') {
                 try {
                     $file = new EfrontFile(G_ROOTPATH . $_GET['download']);
                     $file->sendFile(true);
                     exit;
                 } catch (Exception $e) {
                     $this->setMessageVar(_MODULE_SECURITY_FILECOULDNOTBEDELETED, 'failure');
                 }
             } else {
                 if (isset($_GET['ignore']) && in_array($_GET['ignore'], array_keys($new_files))) {
                     $this->addToIgnoreList($_GET['ignore']);
                 } else {
                     if (isset($_GET['delete']) && in_array($_GET['delete'], array_keys($new_files))) {
                         try {
                             $file = new EfrontFile(G_ROOTPATH . $_GET['delete']);
                             $file->delete();
                         } catch (Exception $e) {
                         }
                         $file = new EfrontFile($this->getLocalListName());
                         $file->delete();
                         list($changed_files, $new_files) = $this->checksumCheck();
                     }
                 }
             }
             $smarty->assign("T_NEW_FILES", $new_files);
             $form->addElement('submit', 'submit_recheck', _MODULE_SECURITY_RECHECKFILES, 'class = "flatButton" ');
             $form->addElement('submit', 'reset_ignore_list', _MODULE_SECURITY_RESETIGNORELIST, 'class = "flatButton" ');
             $form->addElement('submit', 'ignore_new_all', _MODULE_SECURITY_IGNOREALL, 'class = "flatButton" ');
             break;
         default:
             $smarty->assign("T_SECURITY_FEEDS", $this->getRssFeeds());
             try {
                 $smarty->assign("T_LOCAL_ISSUES", $this->checkLocalIssues());
             } catch (Exception $e) {
                 $this->setMessageVar($e->getMessage(), 'failure');
             }
             break;
     }
     if ($form->isSubmitted() && $form->validate()) {
         try {
             $values = $form->exportValues();
             if ($values['submit_recheck']) {
                 $file = new EfrontFile($this->getLocalListName());
                 $file->delete();
                 eF_redirect($this->moduleBaseUrl . '&type=' . $_GET['type'] . '&message=' . urlencode(_OPERATIONCOMPLETEDSUCCESSFULLY) . '&message_type=success');
             } else {
                 if ($values['submit_delete_install']) {
                     file_get_contents(G_SERVERNAME . 'index.php?delete_install=1');
                     eF_redirect($this->moduleBaseUrl . '&type=' . $_GET['type'] . '&message=' . urlencode(_OPERATIONCOMPLETEDSUCCESSFULLY) . '&message_type=success');
                 } else {
                     if ($values['submit_deactivate']) {
                         $result = eF_updateTableData("users", array('active' => 0), "(login = '******' and password = '******') or (login = '******' and password = '******')");
                         eF_redirect($this->moduleBaseUrl . '&message=' . urlencode(_OPERATIONCOMPLETEDSUCCESSFULLY) . '&message_type=success');
                     } else {
                         if ($values['reset_ignore_list']) {
                             try {
                                 $file = new EfrontFile($this->getIgnoreListName());
                                 $file->delete();
                                 eF_redirect($this->moduleBaseUrl . '&type=' . $_GET['type'] . '&message=' . urlencode(_OPERATIONCOMPLETEDSUCCESSFULLY) . '&message_type=success');
                             } catch (Exception $e) {
                                 $this->setMessageVar(_MODULE_SECURITY_THELISTISEMTPY, 'failure');
                             }
                         } else {
                             if ($values['ignore_new_all']) {
                                 list($changed_files, $new_files) = $this->checksumCheck();
                                 foreach ($new_files as $key => $value) {
                                     $this->addToIgnoreList($key);
                                 }
                                 eF_redirect($this->moduleBaseUrl . '&type=new_files&message=' . urlencode(_OPERATIONCOMPLETEDSUCCESSFULLY) . '&message_type=success');
                             } else {
                                 if ($values['ignore_changed_all']) {
                                     list($changed_files, $new_files) = $this->checksumCheck();
                                     foreach ($changed_files as $key => $value) {
                                         $this->addToIgnoreList($key);
                                     }
                                     eF_redirect($this->moduleBaseUrl . '&type=changed_files&message=' . urlencode(_OPERATIONCOMPLETEDSUCCESSFULLY) . '&message_type=success');
                                 }
                             }
                         }
                     }
                 }
             }
         } catch (Exception $e) {
             $smarty->assign("T_EXCEPTION_TRACE", $e->getTraceAsString());
             $message = $e->getMessage() . ' (' . $e->getCode() . ') &nbsp;<a href = "javascript:void(0)" onclick = "eF_js_showDivPopup(event, \'' . _ERRORDETAILS . '\', 2, \'error_details\')">' . _MOREINFO . '</a>';
             $this->setMessageVar($message, 'failure');
         }
     }
     $renderer = prepareFormRenderer($form);
     $smarty->assign('T_SECURITY_FORM', $renderer->toArray());
     //$feeds = $this->getRssFeeds(true, false);
     //$smarty->assign("T_SECURITY_FEEDS", $feeds);
     return true;
 }
 public function getSmartyTpl()
 {
     $smarty = $this->getSmartyVar();
     ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     // Module rates
     $heartbeatForm = new HTML_QuickForm('module_chat_heartbeat_form', "post", $this->moduleBaseUrl, "", null, true);
     $heartbeatForm->addElement('text', 'engine_rate', _CHAT_ENGINE_RATE, 'class="inputText" style="width:100px;"');
     $heartbeatForm->addRule('engine_rate', _THEFIELD . ' ' . _CHAT_ENGINE_RATE . ' ' . _ISMANDATORY, 'required', null, 'client');
     $heartbeatForm->addRule('engine_rate', _THEFIELD . ' ' . _CHAT_ENGINE_RATE . ' ' . _CHAT_MUST_BE_NUMERIC_VALUE, 'numeric', null, 'client');
     $heartbeatForm->addRule('engine_rate', _THEFIELD . ' ' . _CHAT_ENGINE_RATE . ' ' . _CHAT_MUST_BE_GREATER_THAN_ONE, 'callback', create_function('$a', '$res = ($a >= 1) ? true : false; return $res;'));
     $heartbeatForm->addElement('text', 'refresh_rate', _CHAT_USERLIST_REFRESH_RATE, 'class="inputText" style="width:100px;"');
     $heartbeatForm->addRule('refresh_rate', _THEFIELD . ' ' . _CHAT_USERLIST_REFRESH_RATE . ' ' . _ISMANDATORY, 'required', null, 'client');
     $heartbeatForm->addRule('refresh_rate', _THEFIELD . ' ' . _CHAT_USERLIST_REFRESH_RATE . ' ' . _CHAT_MUST_BE_NUMERIC_VALUE, 'numeric', null, 'client');
     $heartbeatForm->addRule('refresh_rate', _THEFIELD . ' ' . _CHAT_ENGINE_RATE . ' ' . _CHAT_MUST_BE_GREATER_THAN_ONE, 'callback', create_function('$a', '$res = ($a >= 1) ? true : false; return $res;'));
     $heartbeatForm->addElement('submit', 'submit', _SUBMIT, 'class="flatButton"');
     $heartbeatForm->setDefaults(array('engine_rate' => $this->getChatHeartbeat() / 1000, 'refresh_rate' => $this->getRefreshRate() / 1000));
     $renderer = prepareFormRenderer($heartbeatForm);
     $smarty->assign("T_CHAT_CHATHEARTBEAT_FORM", $renderer->toArray());
     if ($heartbeatForm->isSubmitted() && $heartbeatForm->validate()) {
         $values = $heartbeatForm->exportValues();
         $this->setChatHeartbeat($values['engine_rate'] * 1000);
         $this->setRefreshRate($values['refresh_rate'] * 1000);
         eF_redirect($this->moduleBaseUrl . '&message_type=success&message=' . urlencode(_CHAT_VALUES_UPDATED_SUCCESSFULLY));
     }
     ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     // Create Log file
     $logForm = new HTML_QuickForm("module_chat_createlog_form", "post", $this->moduleBaseUrl . "&createLog=1", "", null, true);
     $logForm->addElement('hidden', 'hidden_lesson_id', '', 'id = "hidden_lesson_id"');
     $logForm->addElement('text', 'lesson_title', _CHAT_LESSON_TITLE, 'maxlength="100" size="100" class="autoCompleteTextBox" id="autocomplete"');
     $logForm->addRule('lesson_title', _THEFIELD . ' ' . _CHAT_LESSON_TITLE . ' ' . _ISMANDATORY, 'required', null, 'client');
     $logForm->addElement('date', 'from', _CHAT_FROM_DATE, array('format' => 'dMY', 'minYear' => 2010, 'maxYear' => date('Y')));
     $logForm->addElement('date', 'until', _CHAT_UNTIL_DATE, array('format' => 'dMY', 'minYear' => 2010, 'maxYear' => date('Y')));
     $logForm->addElement('submit', 'submit', _SUBMIT, 'class="flatButton"');
     $week_ago = $this->subtractDaysFromToday(7);
     $logForm->setDefaults(array('until' => array('d' => date('d'), 'M' => date('m'), 'Y' => date('Y')), 'from' => $week_ago));
     $renderer = prepareFormRenderer($logForm);
     $smarty->assign("T_CHAT_CREATE_LOG_FORM", $renderer->toArray());
     if (isset($_GET['createLog'])) {
         $log = $this->createLessonHistory($_POST['hidden_lesson_id'], $_POST['from']['Y'] . '-' . $_POST['from']['M'] . '-' . $_POST['from']['d'] . ' ' . "00:00:00", $_POST['until']['Y'] . '-' . $_POST['until']['M'] . '-' . $_POST['until']['d'] . ' ' . "23:59:59");
         $smarty->assign('T_LOG', $log);
         $smarty->assign('T_CHAT_LESSON_TITLE', $l2);
     }
     if ($_POST['exportAdminChat']) {
         $this->adminLogsExportToExcel($_POST['logTitle'], $_POST['data']);
         exit;
     }
     ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     // Clear chat logs
     return $this->moduleBaseDir . "control_panel.tpl";
 }
Exemplo n.º 4
0
                    //Get the form from the entity itself
                    $entityForm = $entity->getForm($entityForm);
                    //try/catch here in order to keep displaying the form in case of an error
                    try {
                        //Assign the form to the entity to handle it accordingly
                        if ($entityForm->isSubmitted() && $entityForm->validate()) {
                            //if $values is set, then the parent file may have done some processing itself
                            if (isset($values) && $values) {
                                $entity->handleForm($entityForm, array_merge($entityForm->exportValues(), $values));
                            } else {
                                $entity->handleForm($entityForm);
                            }
                            $message = _OPERATIONCOMPLETEDSUCCESSFULLY;
                            $message_type = 'success';
                            $processedForm = true;
                            //This can be used outside to signify that the form processing is complete (to allow, for example, for redirecting)
                        }
                    } catch (Exception $e) {
                        handleNormalFlowExceptions($e);
                    }
                    $renderer = prepareFormRenderer($entityForm);
                    $entityForm->accept($renderer);
                    $smarty->assign('T_ENTITY_FORM', $renderer->toArray());
                    $smarty->assign('T_ENTITY_FORM_ARRAY', $entityForm->toArray());
                } catch (Exception $e) {
                    handleNormalFlowExceptions($e);
                }
            }
        }
    }
}
 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";
             }
         }
     }
 }