示例#1
0
                 exit;
             } catch (Exception $e) {
                 handleAjaxExceptions($e);
             }
         } elseif (isset($_GET['ajax']) && $_GET['ajax'] == 'cancel') {
             try {
                 if (eF_checkParameter($_GET['course_id'], 'id')) {
                     $course = new EfrontCourse($_GET['course_id']);
                     $course->removeUsers($_GET['users_login']);
                     $event = array("type" => EfrontEvent::COURSE_USER_REFUSAL, "users_LOGIN" => $_GET['users_login'], "lessons_ID" => $course->course['id'], "lessons_name" => $course->course['name']);
                     EfrontEvent::triggerEvent($event);
                     echo json_encode(array('status' => 1));
                     exit;
                 }
             } catch (Exception $e) {
                 handleAjaxExceptions($e);
             }
         }
     }
 }
 #cpp#endif
 if ($currentUser->coreAccess['dashboard'] != 'hidden') {
     $myCoursesOptions[] = array('text' => _DASHBOARD, 'image' => "32x32/user.png", 'href' => basename($_SERVER['PHP_SELF']) . "?ctg=personal");
 }
 $constraints = array('archive' => false, 'active' => true, 'sort' => 'name');
 $userCourses = $currentUser->getUserCourses($constraints);
 foreach ($userCourses as $key => $course) {
     if ($course->course['start_date'] && $course->course['start_date'] > time()) {
         $course->course['remaining'] = null;
     } elseif ($course->course['end_date'] && $course->course['end_date'] < time()) {
         $course->course['remaining'] = 0;
示例#2
0
 public function getSmartyTpl()
 {
     $smarty = $this->getSmartyVar();
     $smarty->assign("T_RSS_MODULE_BASEURL", $this->moduleBaseUrl);
     $smarty->assign("T_RSS_MODULE_BASELINK", $this->moduleBaseLink);
     $smarty->assign("T_RSS_PROVIDED_FEEDS_MODES", $this->feedProviderModes);
     $smarty->assign("T_RSS_PROVIDED_FEEDS_TYPES", $this->providedFeeds);
     $smarty->assign("T_RSS_PROVIDED_FEEDS_LESSON_TYPES", $this->lessonProvidedFeeds);
     if (isset($_GET['delete_feed']) && eF_checkParameter($_GET['delete_feed'], 'id')) {
         try {
             if ($_GET['type'] == 'provider') {
                 eF_deleteTableData("module_rss_provider", "id=" . $_GET['delete_feed']);
             } else {
                 eF_deleteTableData("module_rss_feeds", "id=" . $_GET['delete_feed']);
             }
         } catch (Exception $e) {
             handleAjaxExceptions($e);
         }
         exit;
     } elseif (isset($_GET['deactivate_feed']) && eF_checkParameter($_GET['deactivate_feed'], 'id')) {
         try {
             if ($_GET['type'] == 'provider') {
                 eF_updateTableData("module_rss_provider", array("active" => 0), "id=" . $_GET['deactivate_feed']);
             } else {
                 eF_updateTableData("module_rss_feeds", array("active" => 0), "id=" . $_GET['deactivate_feed']);
             }
             echo 0;
         } catch (Exception $e) {
             handleAjaxExceptions($e);
         }
         exit;
     } elseif (isset($_GET['activate_feed']) && eF_checkParameter($_GET['activate_feed'], 'file')) {
         //Although db operations do not support exceptions (yet), we leave this here for future support
         try {
             if ($_GET['type'] == 'provider') {
                 eF_updateTableData("module_rss_provider", array("active" => 1), "id=" . $_GET['activate_feed']);
             } else {
                 eF_updateTableData("module_rss_feeds", array("active" => 1), "id=" . $_GET['activate_feed']);
             }
             echo 1;
         } catch (Exception $e) {
             handleAjaxExceptions($e);
         }
         exit;
     } else {
         if (isset($_GET['add_feed']) || isset($_GET['edit_feed']) && eF_checkParameter($_GET['edit_feed'], 'id')) {
             if ($_SESSION['s_lesson_user_type']) {
                 $type = $_SESSION['s_lesson_user_type'];
             } else {
                 $type = $this->getCurrentUser()->getType();
             }
             $smarty->assign("T_RSS_USERTYPE", $type);
             $feeds = $this->getFeeds();
             $lessons = array(-1 => _RSS_NONE, 0 => _ALLLESSONS);
             $result = EfrontLesson::getLessons();
             foreach ($result as $key => $lesson) {
                 $lessons[$key] = $lesson['name'];
             }
             isset($_GET['add_feed']) ? $postTarget = "&add_feed=1" : ($postTarget = "&edit_feed=" . $_GET['edit_feed']);
             $form = new HTML_QuickForm("add_feed_form", "post", $this->moduleBaseUrl . $postTarget, "", null, true);
             $form->registerRule('checkParameter', 'callback', 'eF_checkParameter');
             $form->addElement('text', 'title', _RSS_FEEDTITLE, 'class = "inputText"');
             $form->addElement('text', 'url', _RSS_FEEDURL, 'class = "inputText"');
             $form->addElement('select', 'lessons_ID', _LESSON, $lessons);
             if ($type != 'administrator' && $_SESSION['s_lessons_ID']) {
                 $form->setDefaults(array('lessons_ID' => $_SESSION['s_lessons_ID']));
                 $form->freeze(array('lessons_ID'));
             }
             $form->addElement("advcheckbox", "active", _RSS_ACTIVE, null, 'class = "inputCheckBox"', array(0, 1));
             $form->setDefaults(array('active' => 1));
             $form->addElement("advcheckbox", "only_summary", _RSS_ONLYSUMMARY, null, 'class = "inputCheckBox"', array(0, 1));
             $form->addRule('title', _THEFIELD . ' "' . _RSS_FEEDTITLE . '" ' . _ISMANDATORY, 'required', null, 'client');
             $form->addRule('url', _THEFIELD . ' "' . _RSS_FEEDURL . '" ' . _ISMANDATORY, 'required', null, 'client');
             $form->addRule('title', _INVALIDFIELDDATA, 'checkParameter', 'text');
             $form->addElement('submit', 'submit', _SUBMIT, 'class = "flatButton"');
             if (isset($_GET['edit_feed'])) {
                 $editFeed = $feeds[$_GET['edit_feed']];
                 $form->setDefaults($editFeed);
             }
             if ($form->isSubmitted() && $form->validate()) {
                 //If the form is submitted and validated
                 $values = $form->exportValues();
                 $fields = array("title" => $values['title'], "url" => $values['url'], "active" => $values['active'], "only_summary" => $values['only_summary'], "lessons_ID" => $values['lessons_ID']);
                 if (isset($_GET['add_feed'])) {
                     eF_insertTableData("module_rss_feeds", $fields);
                     $smarty->assign("T_RSS_RSS_MESSAGE", _RSS_SUCCESSFULLYADDEDFEED);
                 } else {
                     eF_updateTableData("module_rss_feeds", $fields, "id=" . $_GET['edit_feed']);
                     $smarty->assign("T_RSS_RSS_MESSAGE", _RSS_SUCCESSFULLYEDITEDFEED);
                     EfrontCache::getInstance()->deleteCache('rss_cache:' . $_GET['edit_feed']);
                 }
             }
             $smarty->assign("T_RSS_ADD_RSS_FORM", $form->toArray());
         } else {
             if (isset($_GET['add_feed_provider']) || isset($_GET['edit_feed_provider']) && eF_checkParameter($_GET['edit_feed_provider'], 'id')) {
                 if ($_SESSION['s_lesson_user_type']) {
                     $type = $_SESSION['s_lesson_user_type'];
                 } else {
                     $type = $this->getCurrentUser()->getType();
                 }
                 $smarty->assign("T_RSS_USERTYPE", $type);
                 $feeds = $this->getProvidedFeeds();
                 isset($_GET['add_feed_provider']) ? $postTarget = "&add_feed_provider=1" : ($postTarget = "&edit_feed_provider=" . $_GET['edit_feed_provider']);
                 !isset($_GET['lesson']) or $postTarget .= '&lesson=1';
                 $form = new HTML_QuickForm("add_feed_provider_form", "post", $this->moduleBaseUrl . $postTarget . '&tab=rss_provider', "", null, true);
                 $form->registerRule('checkParameter', 'callback', 'eF_checkParameter');
                 if ($_GET['lesson']) {
                     $lessons = array(0 => _ALLLESSONS);
                     $result = EfrontLesson::getLessons();
                     foreach ($result as $key => $lesson) {
                         $lessons[$key] = $lesson['name'];
                     }
                     $form->addElement('select', 'feeds_provided', _RSS_PROVIDEDFEEDS, $this->lessonProvidedFeeds);
                     $form->addElement('select', 'lessons_ID', _LESSON, $lessons);
                     if ($type != 'administrator' && $_SESSION['s_lessons_ID']) {
                         $form->setDefaults(array('lessons_ID' => $_SESSION['s_lessons_ID']));
                         $form->freeze(array('lessons_ID'));
                     }
                 } else {
                     $form->addElement('select', 'feeds_provided', _RSS_PROVIDEDFEEDS, $this->providedFeeds);
                 }
                 $form->addElement("advcheckbox", "active", _RSS_ACTIVE, null, 'class = "inputCheckBox"', array(0, 1));
                 $form->setDefaults(array('active' => 1));
                 $form->addElement('submit', 'submit', _SUBMIT, 'class = "flatButton"');
                 if (isset($_GET['edit_feed_provider'])) {
                     $editFeed = $feeds[$_GET['edit_feed_provider']];
                     $form->setDefaults($editFeed);
                 }
                 try {
                     if ($form->isSubmitted() && $form->validate()) {
                         //If the form is submitted and validated
                         $values = $form->exportValues();
                         $fields = array("mode" => $_GET['lesson'] ? 'lesson' : 'system', "type" => $values['feeds_provided'], "active" => $values['active'], "lessons_ID" => $values['lessons_ID']);
                         foreach ($feeds as $feed) {
                             if ($feed['type'] == $fields['type'] && $feed['mode'] == $fields['mode'] && $feed['lessons_ID'] == $fields['lessons_ID']) {
                                 throw new Exception(_FEEDALREADYEXISTS);
                             }
                         }
                         if (isset($_GET['add_feed_provider'])) {
                             eF_insertTableData("module_rss_provider", $fields);
                             $smarty->assign("T_RSS_RSS_MESSAGE", _RSS_SUCCESSFULLYADDEDFEED);
                         } else {
                             eF_updateTableData("module_rss_provider", $fields, "id=" . $_GET['edit_feed_provider']);
                             $smarty->assign("T_RSS_RSS_MESSAGE", _RSS_SUCCESSFULLYEDITEDFEED);
                         }
                     }
                 } 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>';
                     $message_type = 'failure';
                 }
                 $smarty->assign("T_RSS_PROVIDE_RSS_FORM", $form->toArray());
             } else {
                 if (isset($_GET['ajax'])) {
                     echo $this->getRssFeeds($_GET['refresh']);
                     //echo $this -> getRssFeeds(true);
                     exit;
                 } else {
                     $lessons = array(0 => _ALLLESSONS);
                     $result = EfrontLesson::getLessons();
                     foreach ($result as $key => $lesson) {
                         $lessons[$key] = $lesson['name'];
                     }
                     $smarty->assign("T_LESSON_NAMES", $lessons);
                     if ($_SESSION['s_lesson_user_type']) {
                         $type = $_SESSION['s_lesson_user_type'];
                         $smarty->assign("T_RSS_PROVIDED_FEEDS", $this->getProvidedFeeds($_SESSION['s_lessons_ID']));
                         $smarty->assign("T_RSS_FEEDS", $this->getFeeds(false, $_SESSION['s_lessons_ID']));
                     } else {
                         $type = $this->getCurrentUser()->getType();
                         $smarty->assign("T_RSS_PROVIDED_FEEDS", $this->getProvidedFeeds());
                         $smarty->assign("T_RSS_FEEDS", $this->getFeeds());
                     }
                     $smarty->assign("T_RSS_USERTYPE", $type);
                 }
             }
         }
     }
     if ($message) {
         $this->setMessageVar($message, $message_type);
     }
     return $this->moduleBaseDir . "module_rss.tpl";
 }
 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);
     }
 }
示例#4
0
文件: ask.php 项目: bqq1986/efront
function askInformation()
{
    try {
        if (isset($_GET['lessons_ID']) && eF_checkParameter($_GET['lessons_ID'], 'id')) {
            $lesson = new EfrontLesson($_GET['lessons_ID']);
            $lessonInformation = $lesson->getInformation();
            $languages = EfrontSystem::getLanguages(true);
            //$lessonInformation['language'] = $languages[$lesson -> lesson['languages_NAME']];
            if ($lessonInformation['professors']) {
                foreach ($lessonInformation['professors'] as $value) {
                    $professorsString[] = $value['name'] . ' ' . $value['surname'];
                }
                $lessonInformation['professors'] = implode(", ", $professorsString);
            }
            $lesson->lesson['price'] ? $priceString = formatPrice($lesson->lesson['price'], array($lesson->options['recurring'], $lesson->options['recurring_duration']), true) : ($priceString = false);
            $lessonInformation['price_string'] = $priceString;
            //    if (!$lessonInformation['price']) {
            //        unset($lessonInformation['price_string']);
            //    }
            try {
                if ($_GET['from_course']) {
                    $course = new EfrontCourse($_GET['from_course']);
                    $schedule = $course->getLessonScheduleInCourse($lesson);
                    if ($schedule['start_date'] || $schedule['end_date']) {
                        $lessonInformation['from_timestamp'] = $schedule['start_date'];
                        $lessonInformation['to_timestamp'] = $schedule['end_date'];
                    } else {
                        $lessonInformation['from_timestamp'] = $schedule['active_in_lesson'] + 24 * 60 * 60 * $schedule['start_period'];
                        $lessonInformation['to_timestamp'] = $lessonInformation['from_timestamp'] + 24 * 60 * 60 * $schedule['end_period'];
                    }
                }
            } catch (Exception $e) {
            }
            foreach ($lessonInformation as $key => $value) {
                if ($value) {
                    switch ($key) {
                        case 'language':
                            $GLOBALS['configuration']['onelanguage'] or $tooltipInfo[] = '<div class = "infoEntry"><span>' . _LANGUAGE . "</span><span>: {$languages[$value]}</span></div>";
                            break;
                        case 'professors':
                            $tooltipInfo[] = '<div class = "infoEntry"><span>' . _PROFESSORS . "</span><span>: {$value}</span></div>";
                            break;
                        case 'content':
                            $tooltipInfo[] = '<div class = "infoEntry"><span>' . _CONTENTUNITS . "</span><span>: {$value}</span></div>";
                            break;
                        case 'tests':
                            EfrontUser::isOptionVisible('tests') ? $tooltipInfo[] = '<div class = "infoEntry"><span>' . _TESTS . "</span><span>: {$value}</span></div>" : null;
                            break;
                        case 'projects':
                            EfrontUser::isOptionVisible('projects') ? $tooltipInfo[] = '<div class = "infoEntry"><span>' . _PROJECTS . "</span><span>: {$value}</span></div>" : null;
                            break;
                        case 'course_dependency':
                            $tooltipInfo[] = '<div class = "infoEntry"><span>' . _DEPENDSON . "</span><span>: {$value}</span></div>";
                            break;
                        case 'from_timestamp':
                            $tooltipInfo[] = '<div class = "infoEntry"><span>' . _AVAILABLEFROM . "</span><span>: " . formatTimestamp($value, 'time_nosec') . "</span></div>";
                            break;
                        case 'to_timestamp':
                            $tooltipInfo[] = '<div class = "infoEntry"><span>' . _AVAILABLEUNTIL . "</span><span>: " . formatTimestamp($value, 'time_nosec') . "</span></div>";
                            break;
                        case 'general_description':
                            $tooltipInfo[] = '<div class = "infoEntry"><span>' . _DESCRIPTION . "</span><span>: {$value}</span></div>";
                            break;
                        case 'assessment':
                            $tooltipInfo[] = '<div class = "infoEntry"><span>' . _ASSESSMENT . "</span><span>: {$value}</span></div>";
                            break;
                        case 'objectives':
                            $tooltipInfo[] = '<div class = "infoEntry"><span>' . _OBJECTIVES . "</span><span>: {$value}</span></div>";
                            break;
                        case 'lesson_topics':
                            $tooltipInfo[] = '<div class = "infoEntry"><span>' . _LESSONTOPICS . "</span><span>: {$value}</span></div>";
                            break;
                        case 'resources':
                            $tooltipInfo[] = '<div class = "infoEntry"><span>' . _RESOURCES . "</span><span>: {$value}</span></div>";
                            break;
                        case 'other_info':
                            $tooltipInfo[] = '<div class = "infoEntry"><span>' . _OTHERINFO . "</span><span>: {$value}</span></div>";
                            break;
                        case 'price_string':
                            !$lesson->lesson['course_only'] ? $tooltipInfo[] = '<div class = "infoEntry"><span>' . _PRICE . "</span><span>: {$value}</span></div>" : null;
                            break;
                        default:
                            break;
                    }
                }
            }
            if ($string = implode("", $tooltipInfo)) {
                echo $string;
            } else {
                echo _NODATAFOUND;
            }
        }
        if (isset($_GET['courses_ID']) && eF_checkParameter($_GET['courses_ID'], 'id')) {
            $course = new EfrontCourse($_GET['courses_ID']);
            $courseInformation = $course->getInformation();
            $languages = EfrontSystem::getLanguages(true);
            if ($courseInformation['professors']) {
                foreach ($courseInformation['professors'] as $value) {
                    $professorsString[] = $value['name'] . ' ' . $value['surname'];
                }
                $courseInformation['professors'] = implode(", ", $professorsString);
            }
            $course->course['price'] ? $priceString = formatPrice($course->course['price'], array($course->options['recurring'], $course->options['recurring_duration']), true) : ($priceString = false);
            $courseInformation['price_string'] = $priceString;
            foreach ($courseInformation as $key => $value) {
                if ($value) {
                    switch ($key) {
                        case 'language':
                            $tooltipInfo[] = '<div class = "infoEntry"><span>' . _LANGUAGE . "</span><span>: {$languages[$value]}</span></div>";
                            break;
                        case 'professors':
                            $tooltipInfo[] = '<div class = "infoEntry"><span>' . _PROFESSORS . "</span><span>: {$value}</span></div>";
                            break;
                        case 'lessons_number':
                            $tooltipInfo[] = '<div class = "infoEntry"><span>' . _LESSONS . "</span><span>: {$value}</span></div>";
                            break;
                        case 'instances':
                            $tooltipInfo[] = '<div class = "infoEntry"><span>' . _COURSEINSTANCES . "</span><span>: {$value}</span></div>";
                            break;
                        case 'general_description':
                            $tooltipInfo[] = '<div class = "infoEntry"><span>' . _DESCRIPTION . "</span><span>: {$value}</span></div>";
                            break;
                        case 'assessment':
                            $tooltipInfo[] = '<div class = "infoEntry"><span>' . _ASSESSMENT . "</span><span>: {$value}</span></div>";
                            break;
                        case 'objectives':
                            $tooltipInfo[] = '<div class = "infoEntry"><span>' . _OBJECTIVES . "</span><span>: {$value}</span></div>";
                            break;
                        case 'lesson_topics':
                            $tooltipInfo[] = '<div class = "infoEntry"><span>' . _COURSETOPICS . "</span><span>: {$value}</span></div>";
                            break;
                        case 'resources':
                            $tooltipInfo[] = '<div class = "infoEntry"><span>' . _RESOURCES . "</span><span>: {$value}</span></div>";
                            break;
                        case 'other_info':
                            $tooltipInfo[] = '<div class = "infoEntry"><span>' . _OTHERINFO . "</span><span>: {$value}</span></div>";
                            break;
                        case 'price_string':
                            $tooltipInfo[] = '<div class = "infoEntry"><span>' . _PRICE . "</span><span>: {$value}</span></div>";
                            break;
                        default:
                            break;
                    }
                }
            }
            if ($string = implode("", $tooltipInfo)) {
                echo $string;
            } else {
                echo _NODATAFOUND;
            }
        }
        // For eFront social
        if (isset($_GET['common_lessons']) && isset($_GET['user1']) && isset($_GET['user2'])) {
            $user1 = EfrontUserFactory::factory($_GET['user1']);
            if ($user1->getType() != "administrator") {
                $common_lessons = $user1->getCommonLessons($_GET['user2']);
                // pr($common_lessons);
                foreach ($common_lessons as $id => $lesson) {
                    if (strlen($lesson['name']) > 25) {
                        $lesson['name'] = substr($lesson['name'], 0, 22) . "...";
                    }
                    $tooltipInfo[] = '<div class = "infoEntry"><span>' . $lesson['name'] . "</span><span></span></div>";
                }
                if ($string = implode("", $tooltipInfo)) {
                    echo $string;
                } else {
                    echo _NODATAFOUND;
                }
            } else {
                echo _NODATAFOUND;
            }
        }
    } catch (Exception $e) {
        handleAjaxExceptions($e);
    }
}
 /**
  * (non-PHPdoc)
  * @see libraries/EfrontModule#getDashboardModule()
  */
 public function getDashboardModule()
 {
     $smarty = $this->getSmartyVar();
     $smarty->assign("T_MODULE_BASEURL", $_SERVER['PHP_SELF'] . '?ctg=personal');
     try {
         if (isset($_GET['ajax']) && $_GET['ajax'] == 'vLabTable') {
             $this->getAjaxResults();
             $smarty->display($this->moduleBaseDir . "module_vLab_dashboard.tpl");
             exit;
         }
     } catch (Exception $e) {
         handleAjaxExceptions($e);
     }
     return true;
 }
示例#6
0
 /**
  * Handle AJAX actions
  *
  * This function is used to perform the necessary ajax actions,
  * that may be used in tests
  * <br/>Example:
  * <code>
  * $result     = eF_getTableData("completed_tests", "*", "id=".$_GET['show_solved_test']);
  * $showTest   = unserialize($result[0]['test']);
  * $status     = $showTest -> getStatus($result[0]['users_LOGIN']);
  * $testString = $showTest -> toHTMLQuickForm(new HTML_Quickform(), false, true, true);
  * $testString = $showTest -> toHTMLSolved($testString, true);
  * if (isset($_GET['ajax'])) {
  *     $showTest -> handleAjaxActions();
  * }
  * </code>
  *
  * @since 3.5.2
  * @access public
  */
 public function handleAjaxActions()
 {
     try {
         if (isset($_GET['test_score'])) {
             if (mb_strpos($_GET['test_score'], ",") !== false) {
                 $_GET['test_score'] = str_replace(",", ".", $_GET['test_score']);
             }
             if (is_numeric($_GET['test_score']) && $_GET['test_score'] <= 100 && $_GET['test_score'] >= 0) {
                 $this->completedTest['score'] = $_GET['test_score'];
                 foreach ($this->questions as $id => $question) {
                     if ($question->pending) {
                         $this->questions[$id]->pending = 0;
                         $this->questions[$id]->score = $this->completedTest['score'];
                     }
                 }
                 if ($this->test['mastery_score'] && $this->test['mastery_score'] > $this->completedTest['score']) {
                     $this->completedTest['status'] = 'failed';
                 } else {
                     if ($this->test['mastery_score'] && $this->test['mastery_score'] <= $this->completedTest['score']) {
                         $this->completedTest['status'] = 'passed';
                     }
                 }
                 $this->completedTest['pending'] = 0;
                 $this->save();
                 $result = eF_getTableData("completed_tests", "archive", "id=" . $this->completedTest['id']);
                 if (!$result[0]['archive']) {
                     $testUser = EfrontUserFactory::factory($this->completedTest['login']);
                     if ($this->completedTest['status'] == 'failed') {
                         $testUser->setSeenUnit($this->test['content_ID'], $this->test['lessons_ID'], 0);
                     } else {
                         $testUser->setSeenUnit($this->test['content_ID'], $this->test['lessons_ID'], 1);
                     }
                 }
                 echo $this->completedTest['status'];
             } else {
                 throw new EfrontTestException(_INVALIDSCORE . ': ' . $_GET['test_score'], EfrontTestException::INVALID_SCORE);
             }
             exit;
         } else {
             if (isset($_GET['test_feedback'])) {
                 $this->completedTest['feedback'] = $_GET['test_feedback'];
                 $this->save();
                 echo $_GET['test_feedback'];
                 exit;
             } else {
                 if (isset($_GET['redo_test']) && eF_checkParameter($_GET['redo_test'], 'id')) {
                     $result = eF_getTableData("completed_tests", "tests_ID, users_LOGIN", "id=" . $_GET['redo_test']);
                     $test = new EfrontTest($result[0]['tests_ID']);
                     $test->redo($result[0]['users_LOGIN']);
                     exit;
                 } else {
                     if (isset($_GET['redo_wrong_test']) && eF_checkParameter($_GET['redo_wrong_test'], 'id')) {
                         $result = eF_getTableData("completed_tests", "tests_ID, users_LOGIN", "id=" . $_GET['redo_wrong_test']);
                         $test = new EfrontTest($result[0]['tests_ID']);
                         $test->redoOnlyWrong($result[0]['users_LOGIN']);
                         exit;
                     } else {
                         if (isset($_GET['delete_done_test'])) {
                             if (isset($_GET['all'])) {
                                 $this->undo($this->completedTest['login']);
                                 //eF_deleteTableData("completed_tests", "users_LOGIN='******'login']."' and tests_ID=".$this -> completedTest['testsId']);
                             } else {
                                 $this->undo($this->completedTest['login'], $this->completedTest['id']);
                                 //eF_deleteTableData("completed_tests", "id=".$this -> completedTest['id']);
                             }
                             exit;
                         } else {
                             if (isset($_GET['question_score'])) {
                                 if (mb_strpos($_GET['question_score'], ",") !== false) {
                                     $_GET['question_score'] = str_replace(",", ".", $_GET['question_score']);
                                 }
                                 if (in_array($_GET['question'], array_keys($this->questions))) {
                                     if (is_numeric($_GET['question_score']) && $_GET['question_score'] <= 100 && $_GET['question_score'] >= 0) {
                                         $this->questions[$_GET['question']]->score = $_GET['question_score'];
                                         $this->questions[$_GET['question']]->scoreInTest = round($_GET['question_score'] * $this->getQuestionWeight($_GET['question']), 3);
                                         $this->questions[$_GET['question']]->pending = 0;
                                         $score = 0;
                                         foreach ($this->questions as $question) {
                                             $this->completedTest['scoreInTest'][$question->question['id']] = $question->scoreInTest;
                                             $score += $question->scoreInTest;
                                         }
                                         $this->completedTest['score'] = round($score, 2);
                                         $testUser = EfrontUserFactory::factory($this->completedTest['login']);
                                         if ($this->test['mastery_score'] && $this->test['mastery_score'] > $this->completedTest['score']) {
                                             if ($this->getPotentialScore() < $this->test['mastery_score']) {
                                                 $this->completedTest['status'] = 'failed';
                                                 $flag = 0;
                                                 //$testUser -> setSeenUnit($this -> test['content_ID'], $this -> test['lessons_ID'], 0);
                                             }
                                         } else {
                                             if ($this->test['mastery_score'] && $this->test['mastery_score'] <= $this->completedTest['score']) {
                                                 $this->completedTest['status'] = 'passed';
                                                 $flag = 1;
                                                 //$testUser -> setSeenUnit($this -> test['content_ID'], $this -> test['lessons_ID'], 1);
                                             }
                                         }
                                         $this->completedTest['pending'] = 0;
                                         foreach ($this->getQuestions(true) as $question) {
                                             if ($question->pending) {
                                                 $this->completedTest['pending'] = 1;
                                             }
                                         }
                                         try {
                                             $lesson = new EfrontLesson($this->test['lessons_ID']);
                                             $lesson_name = $lesson->lesson['name'];
                                         } catch (EfrontLessonException $e) {
                                             $lesson_name = _SKILLGAPTESTS;
                                         }
                                         if (!$this->completedTest['pending']) {
                                             EfrontEvent::triggerEvent(array("type" => EfrontEvent::TEST_MARKED, "users_LOGIN" => $this->completedTest['login'], "lessons_ID" => $this->test['lessons_ID'], "lessons_name" => $lesson_name, "entity_ID" => $this->test['id'], "entity_name" => $this->test['name']));
                                         }
                                         if ($this->completedTest['status'] == 'failed' && $this->completedTest['pending'] != 1) {
                                             EfrontEvent::triggerEvent(array("type" => EfrontEvent::TEST_FAILURE, "users_LOGIN" => $this->completedTest['login'], "lessons_ID" => $this->test['lessons_ID'], "lessons_name" => $lesson_name, "entity_ID" => $this->test['id'], "entity_name" => $this->test['name']));
                                         }
                                         $this->save();
                                         $testUser->setSeenUnit($this->test['content_ID'], $this->test['lessons_ID'], $flag);
                                         echo json_encode($this->completedTest);
                                     } else {
                                         throw new EfrontTestException(_INVALIDSCORE . ': ' . $_GET['test_score'], EfrontTestException::INVALID_SCORE);
                                     }
                                 } else {
                                     throw new EfrontTestException(_INVALIDID . ': ' . $_GET['question'], EfrontTestException::QUESTION_NOT_EXISTS);
                                 }
                                 exit;
                             } else {
                                 if (isset($_GET['question_feedback'])) {
                                     if (in_array($_GET['question'], array_keys($this->questions))) {
                                         $this->questions[$_GET['question']]->feedback = $_GET['question_feedback'];
                                         $this->save();
                                         echo $_GET['question_feedback'];
                                     } else {
                                         throw new EfrontTestException(_INVALIDID . ': ' . $_GET['question'], EfrontTestException::QUESTION_NOT_EXISTS);
                                     }
                                     exit;
                                 } else {
                                     if (isset($_GET['delete_file'])) {
                                         $file = new EfrontFile($_GET['delete_file']);
                                         $testDirectory = $this->getDirectory();
                                         if (strpos($file['path'], $testDirectory['path']) !== false) {
                                             $file->delete();
                                         }
                                         exit;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     } catch (Exception $e) {
         handleAjaxExceptions($e);
     }
 }
 /**
  * Handle AJAX actions
  *
  * This function is used to perform the necessary ajax actions,
  * that may be fired by the file manager
  * <br/>Example:
  * <code>
  * $basedir    = $currentLesson -> getDirectory();
  * $filesystem = new FileSystemTree($basedir);
  * $filesystem -> handleAjaxActions();
  * </code>
  *
  * @param EfrontUser $currentUser The current user
  * @since 3.5.0
  * @access public
  */
 public function handleAjaxActions($currentUser)
 {
     if (isset($_GET['delete_file']) && (eF_checkParameter($_GET['delete_file'], 'id') || strpos(urldecode($_GET['delete_file']), $this->dir['path']) !== false)) {
         try {
             $file = new EfrontFile(urldecode($_GET['delete_file']));
             if (strpos($file['path'], $this->dir['path']) === false) {
                 throw new EfrontFileException(_YOUCANNOTACCESSTHEREQUESTEDRESOURCE, EfrontFileException::UNAUTHORIZED_ACTION);
             }
             $file->delete();
         } catch (Exception $e) {
             handleAjaxExceptions($e);
         }
         exit;
     } else {
         if (isset($_GET['share']) && (eF_checkParameter($_GET['share'], 'id') || strpos(urldecode($_GET['share']), $this->dir['path']) !== false)) {
             try {
                 $file = new EfrontFile(urldecode($_GET['share']));
                 if (strpos($file['path'], $this->dir['path']) === false) {
                     throw new EfrontFileException(_YOUCANNOTACCESSTHEREQUESTEDRESOURCE, EfrontFileException::UNAUTHORIZED_ACTION);
                 }
                 $file->share();
             } catch (Exception $e) {
                 handleAjaxExceptions($e);
             }
             exit;
         } else {
             if (isset($_GET['unshare']) && (eF_checkParameter($_GET['unshare'], 'id') || strpos(urldecode($_GET['unshare']), $this->dir['path']) !== false)) {
                 try {
                     $file = new EfrontFile(urldecode($_GET['unshare']));
                     if (strpos($file['path'], $this->dir['path']) === false) {
                         throw new EfrontFileException(_YOUCANNOTACCESSTHEREQUESTEDRESOURCE, EfrontFileException::UNAUTHORIZED_ACTION);
                     }
                     $file->unshare();
                 } catch (Exception $e) {
                     handleAjaxExceptions($e);
                 }
                 exit;
             } else {
                 if (isset($_GET['uncompress']) && (eF_checkParameter($_GET['uncompress'], 'id') || strpos(urldecode($_GET['uncompress']), $this->dir['path']) !== false)) {
                     try {
                         $file = new EfrontFile(urldecode($_GET['uncompress']));
                         if (strpos($file['path'], $this->dir['path']) === false) {
                             throw new EfrontFileException(_YOUCANNOTACCESSTHEREQUESTEDRESOURCE, EfrontFileException::UNAUTHORIZED_ACTION);
                         }
                         $file->uncompress();
                     } catch (Exception $e) {
                         handleAjaxExceptions($e);
                     }
                     exit;
                 } elseif (isset($_GET['delete_folder']) && (eF_checkParameter($_GET['delete_folder'], 'id') || strpos(urldecode($_GET['delete_folder']), $this->dir['path']) !== false)) {
                     try {
                         $directory = new EfrontDirectory(urldecode($_GET['delete_folder']));
                         if (strpos($directory['path'], $this->dir['path']) === false) {
                             throw new EfrontFileException(_YOUCANNOTACCESSTHEREQUESTEDRESOURCE, EfrontFileException::UNAUTHORIZED_ACTION);
                         }
                         $directory->delete();
                     } catch (Exception $e) {
                         handleAjaxExceptions($e);
                     }
                     exit;
                 } elseif (isset($_GET['download']) && (eF_checkParameter($_GET['download'], 'id') || strpos(urldecode($_GET['download']), $this->dir['path']) !== false)) {
                     try {
                         $file = new EfrontFile(urldecode($_GET['download']));
                         if (strpos($file['path'], $this->dir['path']) === false) {
                             throw new EfrontFileException(_YOUCANNOTACCESSTHEREQUESTEDRESOURCE, EfrontFileException::UNAUTHORIZED_ACTION);
                         }
                         $file->sendFile(true);
                     } catch (Exception $e) {
                         handleAjaxExceptions($e);
                     }
                     exit;
                 } elseif (isset($_GET['view']) && (eF_checkParameter($_GET['view'], 'id') || strpos(urldecode($_GET['view']), $this->dir['path']) !== false)) {
                     try {
                         $file = new EfrontFile(urldecode($_GET['view']));
                         if (strpos($file['path'], $this->dir['path']) === false) {
                             throw new EfrontFileException(_YOUCANNOTACCESSTHEREQUESTEDRESOURCE, EfrontFileException::UNAUTHORIZED_ACTION);
                         }
                         $file->sendFile(false);
                     } catch (Exception $e) {
                         handleAjaxExceptions($e);
                     }
                     exit;
                 } elseif (isset($_GET['update']) && (eF_checkParameter($_GET['update'], 'id') || strpos(urldecode($_GET['update']), $this->dir['path']) !== false)) {
                     try {
                         $_GET['type'] == 'file' ? $file = new EfrontFile(urldecode($_GET['update'])) : ($file = new EfrontDirectory(urldecode($_GET['update'])));
                         if (strpos($file['path'], $this->dir['path']) === false) {
                             throw new EfrontFileException(_YOUCANNOTACCESSTHEREQUESTEDRESOURCE, EfrontFileException::UNAUTHORIZED_ACTION);
                         }
                         $previousName = $file['name'];
                         if ($file['name'] != $_GET['name']) {
                             $file->rename(dirname($file['path']) . '/' . EfrontFile::encode(urldecode($_GET['name'])));
                         }
                         echo json_encode(array('previousName' => $previousName, 'name' => $file['name']));
                     } catch (Exception $e) {
                         handleAjaxExceptions($e);
                     }
                     exit;
                 }
             }
         }
     }
 }
 /**
  * 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;
 }
示例#9
0
 public function getSmartyTpl()
 {
     $currentUser = $this->getCurrentUser();
     $rules = $this->getRules();
     $smarty = $this->getSmartyVar();
     if ($currentUser->getRole($this->getCurrentLesson()) == 'professor' || $currentUser->getRole($this->getCurrentLesson()) == 'student') {
         $currentLesson = $this->getCurrentLesson();
         $currentLessonID = $currentLesson->lesson['id'];
         if (!isset($_SESSION['module_journal_dimension']) || count($_GET) == 2 && $_GET['ctg'] == 'module' && $_GET['op'] == 'module_journal' || count($_GET) == 3 && $_GET['ctg'] == 'module' && $_GET['op'] == 'module_journal' && $_GET['new_lesson_id'] == $currentLessonID) {
             $_SESSION['module_journal_dimension'] = 'small';
         }
         if (!isset($_SESSION['module_journal_entries_from']) || count($_GET) == 2 && $_GET['ctg'] == 'module' && $_GET['op'] == 'module_journal' || count($_GET) == 3 && $_GET['ctg'] == 'module' && $_GET['op'] == 'module_journal' && $_GET['new_lesson_id'] == $currentLessonID) {
             $_SESSION['module_journal_entries_from'] = '-1';
         }
         if (isset($_SESSION['module_journal_scroll_position'])) {
             $smarty->assign("T_JOURNAL_SCROLL_POSITION", $_SESSION['module_journal_scroll_position']);
         }
         $smarty->assign("T_JOURNAL_DIMENSIONS", $_SESSION['module_journal_dimension']);
         $smarty->assign("T_JOURNAL_ENTRIES_FROM", $_SESSION['module_journal_entries_from']);
         $entries = $this->getEntries($currentUser->user['login'], $_SESSION['module_journal_entries_from']);
         global $popup;
         isset($popup) && $popup == 1 ? $popup_ = '&popup=1' : ($popup_ = '');
     }
     $smarty->assign("T_JOURNAL_BASEURL", $this->moduleBaseUrl);
     $smarty->assign("T_JOURNAL_BASELINK", $this->moduleBaseLink);
     if (isset($_GET['edit_allow_export']) && $_GET['edit_allow_export'] == '1' && isset($_GET['allow'])) {
         try {
             $object = eF_getTableData("module_journal_settings", "id", "name='export'");
             eF_updateTableData("module_journal_settings", array("value" => $_GET['allow']), "id=" . $object[0]['id']);
         } catch (Exception $e) {
             handleAjaxExceptions($e);
         }
         exit;
     }
     if (isset($_GET['edit_professor_preview']) && $_GET['edit_professor_preview'] == '1' && isset($_GET['preview'])) {
         try {
             $object = eF_getTableData("module_journal_settings", "id", "name='preview'");
             eF_updateTableData("module_journal_settings", array("value" => $_GET['preview']), "id=" . $object[0]['id']);
         } catch (Exception $e) {
             handleAjaxExceptions($e);
         }
         exit;
     }
     if (isset($_GET['dimension']) && eF_checkParameter($_GET['dimension'], 'string')) {
         $smarty->assign("T_JOURNAL_DIMENSIONS", $_GET['dimension']);
         $_SESSION['module_journal_dimension'] = $_GET['dimension'];
     }
     if (isset($_GET['entries_from'])) {
         $smarty->assign("T_JOURNAL_ENTRIES_FROM", $_GET['entries_from']);
         $_SESSION['module_journal_entries_from'] = $_GET['entries_from'];
     }
     if (isset($_GET['delete_rule']) && eF_checkParameter($_GET['delete_rule'], 'id') && in_array($_GET['delete_rule'], array_keys($rules))) {
         try {
             eF_deleteTableData("module_journal_rules", "id=" . $_GET['delete_rule']);
         } catch (Exception $e) {
             handleAjaxExceptions($e);
         }
         exit;
     }
     if (isset($_GET['deactivate_rule']) && eF_checkParameter($_GET['deactivate_rule'], 'id') && in_array($_GET['deactivate_rule'], array_keys($rules))) {
         eF_updateTableData("module_journal_rules", array('active' => 0), "id=" . $_GET['deactivate_rule']);
     }
     if (isset($_GET['activate_rule']) && eF_checkParameter($_GET['activate_rule'], 'id') && in_array($_GET['activate_rule'], array_keys($rules))) {
         eF_updateTableData("module_journal_rules", array('active' => 1), "id=" . $_GET['activate_rule']);
     }
     if (isset($_GET['delete_entry']) && eF_checkParameter($_GET['delete_entry'], 'id') && in_array($_GET['delete_entry'], array_keys($entries))) {
         $object = eF_getTableData("module_journal_entries", "users_LOGIN", "id=" . $_GET['delete_entry']);
         if ($object[0]['users_LOGIN'] != $_SESSION['s_login']) {
             eF_redirect($this->moduleBaseUrl . "&message=" . urlencode(_JOURNAL_NOACCESS) . $popup_);
             exit;
         }
         eF_deleteTableData("module_journal_entries", "id=" . $_GET['delete_entry']);
     }
     if (isset($_GET['saveas']) && $_GET['saveas'] == 'pdf') {
         $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true);
         $pdf->SetCreator(PDF_CREATOR);
         $pdf->SetAuthor(PDF_AUTHOR);
         $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
         $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
         $pdf->setFontSubsetting(false);
         $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
         $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
         $pdf->setHeaderFont(array('Freeserif', 'I', 11));
         $pdf->setFooterFont(array('Freeserif', '', 8));
         $pdf->setHeaderData('', '', '', _JOURNAL_NAME);
         $pdf->AliasNbPages();
         $pdf->AddPage();
         $pdf->SetFont('Freeserif', '', 10);
         $pdf->SetTextColor(0, 0, 0);
         foreach ($entries as $entry) {
             $pdf->Cell(0, 0, $entry['entry_date_formatted'], 0, 1, L, 0);
             $pdf->writeHTML('<br/>', true, false, true, false, '');
             $pdf->writeHTML($entry['entry_body'], true, false, true, false, '');
             $pdf->writeHTML('<div style="height: 5px;"></div>', true, false, true, false, '');
             $pdf->writeHTML('<hr>', true, false, true, false, '');
         }
         $fileNamePdf = "journal.pdf";
         header("Content-type: application/pdf");
         header("Content-disposition: attachment; filename=" . $fileNamePdf);
         echo $pdf->Output('', 'S');
         exit(0);
     }
     if (isset($_GET['saveas']) && $_GET['saveas'] == 'doc') {
         include dirname(__FILE__) . "/classes/html_to_doc.inc.php";
         $entriesHTML = '';
         foreach ($entries as $entry) {
             $entriesHTML .= $entry['entry_date_formatted'];
             $entriesHTML .= $entry['entry_body'];
             $entriesHTML .= '<hr><br/>';
         }
         $htmltodoc = new HTML_TO_DOC();
         $htmltodoc->createDoc($entriesHTML, "journal", true);
         exit(0);
     }
     if (isset($_GET['saveas']) && $_GET['saveas'] == 'txt') {
         include dirname(__FILE__) . "/classes/html2text.inc";
         header('Content-Type: text/plain');
         header('Content-Disposition: attachment; filename="journal.txt"');
         $entriesHTML = '';
         foreach ($entries as $entry) {
             $entriesHTML .= $entry['entry_date_formatted'];
             $entriesHTML .= $entry['entry_body'];
             $entriesHTML .= '<p></p>';
             $entriesHTML .= '_______________________________________________________';
             $entriesHTML .= '<p></p>';
         }
         $htmlToText = new Html2Text($entriesHTML, 100);
         $entriesHTMLtext = $htmlToText->convert();
         echo $entriesHTMLtext;
         exit(0);
     }
     if (isset($_GET['check_students_journals']) && $_GET['check_students_journals'] == '1') {
         $professorJournalLessons = $this->getProfessorJournalLessons($currentUser);
         $journalLessonsStudents = $this->getJournalLessonsStudents($professorJournalLessons);
         $smarty->assign("T_JOURNAL_STUDENTS", $journalLessonsStudents);
     }
     if (isset($_GET['preview_journal']) && $_GET['preview_journal'] == '1' && isset($_GET['student']) && eF_checkParameter($_GET['student'], 'login')) {
         $userLogin = $_GET['student'];
         $professorJournalLessons = $this->getProfessorJournalLessons($currentUser);
         $studentEntries = $this->getStudentEntries($userLogin, $professorJournalLessons);
         $smarty->assign("T_JOURNAL_STUDENT_ENTRIES", $studentEntries);
     }
     if (isset($_REQUEST['autosave']) && $_REQUEST['autosave'] == "1" && isset($_REQUEST['entry_body']) && isset($_REQUEST['edit_entry'])) {
         if ($_REQUEST['edit_entry'] != "-1") {
             if (eF_checkParameter($_GET['edit_entry'], 'id')) {
                 $object = eF_getTableData("module_journal_entries", "lessons_ID", "id=" . $_GET['edit_entry']);
                 $fields = array("entry_body" => $_REQUEST['entry_body'], "entry_date" => date('Y') . '-' . date('m') . '-' . date('d') . ' ' . date('H') . ':' . date('i') . ':' . date('s'), "lessons_ID" => $object[0]['lessons_ID'], "users_LOGIN" => $currentUser->user['login']);
                 eF_updateTableData("module_journal_entries", $fields, "id=" . $_REQUEST['edit_entry']);
             }
         } else {
             $fields = array("entry_body" => $_REQUEST['entry_body'], "entry_date" => date('Y') . '-' . date('m') . '-' . date('d') . ' ' . date('H') . ':' . date('i') . ':' . date('s'), "lessons_ID" => $currentLessonID, "users_LOGIN" => $currentUser->user['login']);
             $id = eF_insertTableData("module_journal_entries", $fields);
             if ($id) {
                 if (isset($_SESSION['module_journal_autosave_entry'])) {
                     $this->deleteAutoSaveEntry();
                     $_SESSION['module_journal_autosave_entry'] = $id;
                 } else {
                     $_SESSION['module_journal_autosave_entry'] = $id;
                 }
             }
         }
         exit(0);
     }
     if (isset($_REQUEST['show_right']) && $_REQUEST['show_right'] == "1" && isset($_REQUEST['entry_body']) && $_REQUEST['entry_body'] != "" && isset($_REQUEST['edit']) && isset($_REQUEST['edit_entry'])) {
         if (isset($_SESSION['module_journal_show_right_entry'])) {
             unset($_SESSION['module_journal_show_right_entry']);
         }
         $_SESSION['module_journal_show_right_entry'] = $_REQUEST['entry_body'];
     }
     if (isset($_REQUEST['hide_right']) && $_REQUEST['hide_right'] == "1" && isset($_REQUEST['entry_body']) && $_REQUEST['entry_body'] != "" && isset($_REQUEST['edit']) && isset($_REQUEST['edit_entry'])) {
         if (isset($_SESSION['module_journal_hide_right_entry'])) {
             unset($_SESSION['module_journal_hide_right_entry']);
         }
         $_SESSION['module_journal_hide_right_entry'] = $_REQUEST['entry_body'];
     }
     if (isset($_REQUEST['hide_left']) && $_REQUEST['hide_left'] == "1" && isset($_REQUEST['entry_body']) && $_REQUEST['entry_body'] != "" && isset($_REQUEST['edit']) && isset($_REQUEST['edit_entry'])) {
         if (isset($_SESSION['module_journal_hide_left_entry'])) {
             unset($_SESSION['module_journal_hide_left_entry']);
         }
         $_SESSION['module_journal_hide_left_entry'] = $_REQUEST['entry_body'];
     }
     if (isset($_REQUEST['scroll_position']) && eF_checkParameter($_REQUEST['scroll_position'], 'id')) {
         $_SESSION['module_journal_scroll_position'] = $_REQUEST['scroll_position'];
     }
     if (isset($_GET['add_rule']) || isset($_GET['edit_rule']) && eF_checkParameter($_GET['edit_rule'], 'id') && in_array($_GET['edit_rule'], array_keys($rules))) {
         if ($_SESSION['s_type'] != "administrator") {
             eF_redirect($this->moduleBaseUrl . "&message=" . urlencode(_JOURNAL_NOACCESS));
         }
         isset($_GET['add_rule']) ? $postTarget = "&add_rule=1" : ($postTarget = "&edit_rule=" . $_GET['edit_rule']);
         global $load_editor;
         $load_editor = true;
         $form = new HTML_QuickForm("add_edit_rule_form", "post", $this->moduleBaseUrl . $postTarget, "", null, true);
         $form->addElement('text', 'title', _TITLE, 'class="inputText" style="width:498px;"');
         $form->addRule('title', _THEFIELD . ' "' . _TITLE . '" ' . _ISMANDATORY, 'required', null, 'client');
         $form->addElement('textarea', 'description', _DESCRIPTION, 'class="inputContentTextarea simpleEditor" style="width:500px;height:20em;"');
         $form->addElement('submit', 'submit', _SUBMIT, 'class="flatButton"');
         if (isset($_GET['edit_rule'])) {
             $editRule = $rules[$_GET['edit_rule']];
             $form->setDefaults($editRule);
         }
         if ($form->isSubmitted() && $form->validate()) {
             $values = $form->exportValues();
             $fields = array("title" => $values['title'], "description" => $values['description']);
             if ($values['description'] == '') {
                 $message = _JOURNAL_EMPTY_RULE_DESCRIPTION;
                 if (isset($_GET['add_rule'])) {
                     eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=failure&add_rule=1");
                 } else {
                     eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=failure&edit_rule=" . $_GET['edit_rule']);
                 }
             }
             if (isset($_GET['add_rule'])) {
                 if (eF_insertTableData("module_journal_rules", $fields)) {
                     $message = _JOURNAL_RULE_SUCCESSFULLY_ADDED;
                     eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=success");
                 } else {
                     $message = _JOURNAL_RULE_ADD_PROBLEM;
                     eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=failure");
                 }
             } else {
                 if (eF_updateTableData("module_journal_rules", $fields, "id=" . $_GET['edit_rule'])) {
                     $message = _JOURNAL_RULE_SUCCESSFULLY_EDITED;
                     eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=success");
                 } else {
                     $message = _JOURNAL_RULE_EDIT_PROBLEM;
                     eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=failure");
                 }
             }
         }
         $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
         $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
         $form->setRequiredNote(_REQUIREDNOTE);
         $form->accept($renderer);
         $smarty->assign('T_JOURNAL_ADD_EDIT_RULE_FORM', $renderer->toArray());
     } else {
         $rules = $this->getRules();
         $smarty->assign("T_JOURNAL_RULES", $rules);
         $object = eF_getTableData("module_journal_settings", "value", "name='export'");
         $smarty->assign("T_JOURNAL_ALLOW_EXPORT", $object[0]['value']);
         $object = eF_getTableData("module_journal_settings", "value", "name='preview'");
         $smarty->assign("T_JOURNAL_ALLOW_PROFESSOR_PREVIEW", $object[0]['value']);
         if ($currentUser->getRole($this->getCurrentLesson()) == 'professor' || $currentUser->getRole($this->getCurrentLesson()) == 'student') {
             $activeRules = $this->getRules(true);
             $smarty->assign("T_JOURNAL_ACTIVE_RULES", $activeRules);
             $entries = $this->getEntries($currentUser->user['login'], $_SESSION['module_journal_entries_from']);
             $smarty->assign("T_JOURNAL_ENTRIES", $entries);
             $journalLessons = $this->getJournalLessons($currentUser->user['login']);
             $smarty->assign("T_JOURNAL_LESSONS", $journalLessons);
             /*					*/
             global $load_editor;
             $load_editor = true;
             if (isset($_GET['edit_entry']) && $_GET['edit_entry'] != '-1') {
                 $postTarget = "&edit_entry=" . $_GET['edit_entry'];
             } else {
                 $postTarget = "&add_entry=1";
             }
             if (isset($_GET['hide_right']) && $_GET['hide_right'] == '1') {
                 $editorStyle = array('small' => 'width:588px; height:320px;', 'medium' => 'width:673px; height:375px;', 'large' => 'width:759px; height:430px;');
             } else {
                 $editorStyle = array('small' => 'width:300px; height:320px;', 'medium' => 'width:344px; height:375px;', 'large' => 'width:388px; height:430px;');
             }
             $form = new HTML_QuickForm("add_edit_entry_form", "post", $this->moduleBaseUrl . $postTarget, "", null, true);
             $form->addElement('textarea', 'entry_body', _DESCRIPTION, 'class="inputContentTextarea simpleEditor" style="' . $editorStyle[$_SESSION['module_journal_dimension']] . '"');
             if (isset($_GET['edit_entry']) && $_GET['edit_entry'] != '-1') {
                 $form->addElement('submit', 'submit', _UPDATE . ' ' . _JOURNAL_ENTRY, 'class="flatButton"');
             } else {
                 $form->addElement('submit', 'submit', _SAVE . ' ' . _JOURNAL_ENTRY, 'class="flatButton"');
             }
             if (isset($_GET['edit_entry']) && $_GET['edit_entry'] != '-1') {
                 $editEntry = $entries[$_GET['edit_entry']];
                 $form->setDefaults($editEntry);
                 if (!in_array($_GET['edit_entry'], array_keys($entries))) {
                     eF_redirect($this->moduleBaseUrl . "&message=" . urlencode(_JOURNAL_NOACCESS) . $popup_);
                 }
                 $object = eF_getTableData("module_journal_entries", "lessons_ID, users_LOGIN, entry_date", "id=" . $_GET['edit_entry']);
                 if ($object[0]['users_LOGIN'] != $_SESSION['s_login']) {
                     eF_redirect($this->moduleBaseUrl . "&message=" . urlencode(_JOURNAL_NOACCESS) . $popup_);
                 }
             }
             if (isset($_GET['show_left']) && $_GET['show_left'] == '1' && isset($_GET['edit']) && isset($_GET['edit_entry'])) {
                 if (isset($_SESSION['module_journal_hide_left_entry'])) {
                     $form->setDefaults(array("entry_body" => $_SESSION['module_journal_hide_left_entry']));
                     unset($_SESSION['module_journal_hide_left_entry']);
                 }
             }
             if (isset($_GET['show_right']) && $_GET['show_right'] == '1' && isset($_GET['edit']) && isset($_GET['edit_entry'])) {
                 if (isset($_SESSION['module_journal_show_right_entry'])) {
                     $form->setDefaults(array("entry_body" => $_SESSION['module_journal_show_right_entry']));
                     unset($_SESSION['module_journal_show_right_entry']);
                 }
             }
             if (isset($_GET['hide_right']) && $_GET['hide_right'] == '1' && isset($_GET['edit']) && isset($_GET['edit_entry'])) {
                 if (isset($_SESSION['module_journal_hide_right_entry'])) {
                     $form->setDefaults(array("entry_body" => $_SESSION['module_journal_hide_right_entry']));
                     unset($_SESSION['module_journal_hide_right_entry']);
                 }
             }
             if ($form->isSubmitted() && $form->validate()) {
                 $values = $form->exportValues();
                 isset($_GET['add_entry']) ? $lessonID = $currentLessonID : ($lessonID = $object[0]['lessons_ID']);
                 if (isset($_GET['add_entry'])) {
                     $date = date('Y') . '-' . date('m') . '-' . date('d') . ' ' . date('H') . ':' . date('i') . ':' . date('s');
                 } else {
                     $date = $object[0]['entry_date'];
                 }
                 $fields = array("entry_body" => $values['entry_body'], "entry_date" => $date, "lessons_ID" => $lessonID, "users_LOGIN" => $currentUser->user['login']);
                 if ($values['entry_body'] == '') {
                     $message = _JOURNAL_EMPTY_ENTRY_BODY;
                     eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=failure" . $popup_);
                 }
                 if (isset($_GET['add_entry'])) {
                     if (eF_insertTableData("module_journal_entries", $fields)) {
                         if (isset($_SESSION['module_journal_autosave_entry'])) {
                             $this->deleteAutoSaveEntry();
                         }
                         $message = _JOURNAL_ENTRY_SUCCESSFULLY_ADDED;
                         eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=success" . $popup_);
                     } else {
                         $message = _JOURNAL_ENTRY_ADD_PROBLEM;
                         eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=failure" . $popup_);
                     }
                 } else {
                     if (eF_updateTableData("module_journal_entries", $fields, "id=" . $_GET['edit_entry'])) {
                         $message = _JOURNAL_ENTRY_SUCCESSFULLY_EDITED;
                         eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=success" . $popup_);
                     } else {
                         $message = _JOURNAL_ENTRY_EDIT_PROBLEM;
                         eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=failure" . $popup_);
                     }
                 }
             }
             $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
             $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
             $form->setRequiredNote(_REQUIREDNOTE);
             $form->accept($renderer);
             $smarty->assign('T_JOURNAL_ADD_ENTRY_FORM', $renderer->toArray());
             if ($currentUser->getRole($this->getCurrentLesson()) == 'professor') {
                 $popupInfo[] = array('text' => _JOURNAL_POPUP_INFO, 'image' => $this->moduleBaseLink . 'images/info.png', 'href' => $this->moduleBaseUrl . '&popup_info=1&popup=1', 'onClick' => "eF_js_showDivPopup(event, '" . _JOURNAL_POPUP_INFO . "', 2)", 'target' => 'POPUP_FRAME', 'id' => 'popup_info');
                 $smarty->assign("T_JOURNAL_POPUP_INFO", $popupInfo);
             }
         }
     }
     if ($currentUser->getType() == 'administrator') {
         return $this->moduleBaseDir . "module_journal_admin.tpl";
     } else {
         if ($currentUser->getRole($this->getCurrentLesson()) == 'professor' || $currentUser->getRole($this->getCurrentLesson()) == 'student') {
             if (isset($_GET['hide_left']) && $_GET['hide_left'] == '1') {
                 return $this->moduleBaseDir . "module_journal_user_right.tpl";
             }
             if (isset($_GET['hide_right']) && $_GET['hide_right'] == '1') {
                 return $this->moduleBaseDir . "module_journal_user_left.tpl";
             }
             return $this->moduleBaseDir . "module_journal_user.tpl";
         }
     }
 }
 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()
 {
     $currentLesson = $this->getCurrentLesson();
     $smarty = $this->getSmartyVar();
     $smarty->assign("T_MODULE_BASEDIR", $this->moduleBaseDir);
     $smarty->assign("T_MODULE_BASELINK", $this->moduleBaseLink);
     $smarty->assign("T_MODULE_BASEURL", $this->moduleBaseUrl);
     if ($currentLesson && !$currentLesson->options['digital_library']) {
         $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) {
             $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 (in_array($key, $lessonSharedFiles)) {
                 $value['module_shared_files_status'] = 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);
         list($tableSize, $dataSource) = filterSortPage($dataSource);
         $smarty->assign("T_TABLE_SIZE", $tableSize);
         if (!empty($dataSource)) {
             $smarty->assign("T_DATA_SOURCE", $dataSource);
         }
         try {
             if (isset($_GET['ajax']) && isset($_GET['share_file'])) {
                 try {
                     $entity = new EfrontFile(urldecode($_GET['share_file']));
                 } catch (Exception $e) {
                     $entity = new EfrontDirectory(urldecode($_GET['share_file']));
                 }
                 if (in_array($entity['path'], $lessonSharedFiles)) {
                     eF_deleteTableData("module_shared_files", "path='" . $entity['path'] . "' and lessons_ID=" . $currentLesson->lesson['id']);
                     $added = false;
                     if ($entity instanceof EfrontDirectory) {
                         $subTree = new FileSystemTree($entity, true);
                         $insertValues = array();
                         foreach ($subTree->tree as $value) {
                             eF_deleteTableData("module_shared_files", "path='" . $value['path'] . "' and lessons_ID=" . $currentLesson->lesson['id']);
                         }
                     }
                 } else {
                     eF_insertTableData("module_shared_files", array("path" => $entity['path'], 'lessons_ID' => $currentLesson->lesson['id']));
                     $added = true;
                     if ($entity instanceof EfrontDirectory) {
                         $subTree = new FileSystemTree($entity, true);
                         $insertValues = array();
                         foreach ($subTree->tree as $value) {
                             $insertValues[] = array("path" => $value['path'], 'lessons_ID' => $currentLesson->lesson['id']);
                         }
                         if (!empty($insertValues)) {
                             eF_insertTableDataMultiple("module_shared_files", $insertValues);
                         }
                     }
                 }
                 echo json_encode(array('status' => 1, 'added' => $added));
                 exit;
             }
         } catch (Exception $e) {
             handleAjaxExceptions($e);
         }
         return true;
     } else {
         if ($currentLesson) {
             $currentLesson->options['digital_library'] = 0;
             $currentLesson->persist();
             eF_redirect($this->moduleBaseUrl . '&message=' . urlencode(_MODULE_SHARED_FILES_SHAREDFILESENABLED));
             //$this->setMessageVar(_MODULE_SHARED_FILES_SHAREDFILESENABLED);
             //$smarty -> assign("T_SHARED_FILES_ENABLED", true);
         }
     }
 }
示例#12
0
 public static function handleInstallationExceptions($e)
 {
     if ($_GET['unattended']) {
         handleAjaxExceptions($e);
     } else {
         handleNormalFlowExceptions($e);
     }
 }