Fixing fatal error when loging out + index.php and index-smarty.php are the same now

skala
Julio Montoya 14 years ago
parent e7480f7be7
commit e9c19fc99a
  1. 32
      index-smarty.php
  2. 59
      index.php
  3. 15
      main/inc/lib/system_announcements.lib.php
  4. 203
      main/inc/lib/userportal.lib.php
  5. 7
      main/template/default/layout/header.tpl
  6. 4
      main/template/default/layout/layout_two_col.tpl
  7. 3
      main/template/experimental/layout/layout_two_col.tpl

@ -13,31 +13,45 @@ $language_file = array('courses', 'index');
// Maybe we should change this into an api function? an example: Coursemanager::unset();
$cidReset = true;
/* Included libraries */
// The section (for the tabs).
$this_section = SECTION_CAMPUS;
require_once 'main/inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'userportal.lib.php';
// The section (for the tabs).
$this_section = SECTION_CAMPUS;
$header_title = null;
if (!api_is_anonymous()) {
$header_title = " ";
}
$htmlHeadXtra[] = api_get_jquery_libraries_js(array('bxslider'));
$htmlHeadXtra[] ='
<script type="text/javascript">
$(document).ready(function(){
$("#slider").bxSlider({
infiniteLoop : true,
auto : true,
pager : true,
autoHover : true,
pause : 10000
});
});
</script>';
$index = new IndexManager($header_title);
$tpl = $index->tpl->get_template('layout/layout_two_col.tpl');
$user_id = api_get_user_id();
//@todo move this inside the IndexManager
$index->tpl->assign('login_block', $index->show_login_form($user_id));
$index->tpl->assign('teacher_block', $index->display_teacher_link($user_id));
$index->tpl->assign('home_page', $index->return_home_page());
$index->tpl->assign('announcements_block', $index->return_announcements());
$index->tpl->assign('teacher_block', $index->return_teacher_link());
$index->tpl->assign('home_page_block', $index->return_home_page());
$index->tpl->assign('profile_block', $index->return_profile_block());
$index->tpl->assign('notice_block', $index->return_notice($home));
$index->tpl->assign('notice_block', $index->return_notice());
$index->tpl->assign('plugin_campushomepage', $index->return_plugin_campushomepage());
$index->tpl->display($tpl);

@ -24,11 +24,9 @@ $cidReset = true;
/** @todo Make all the library files consistent, use filename.lib.php and not filename.lib.inc.php. */
require_once 'main/inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'system_announcements.lib.php';
require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
require_once api_get_path(LIBRARY_PATH).'userportal.lib.php';
require_once 'main/chat/chat_functions.lib.php';
$loginFailed = isset($_GET['loginFailed']) ? true : isset($loginFailed);
@ -38,6 +36,13 @@ $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 't
$this_section = SECTION_CAMPUS;
unset($_SESSION['this_section']);//for hmtl editor repository
$header_title = null;
if (!api_is_anonymous()) {
$header_title = " ";
}
$index = new IndexManager($header_title, false);
/* Action Handling */
/** @todo Wouldn't it make more sense if this would be done in local.inc.php so that local.inc.php become the only place where authentication is done?
@ -48,13 +53,11 @@ unset($_SESSION['this_section']);//for hmtl editor repository
$my_user_id = api_get_user_id();
if (!empty($_GET['logout'])) {
logout();
$index->logout();
}
/* Table definitions */
$main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
$main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
$track_login_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
/* Constants and CONFIGURATION parameters */
/** @todo these configuration settings should move to the Chamilo config settings. */
@ -62,11 +65,6 @@ $track_login_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_
/** Defines wether or not anonymous visitors can see a list of the courses on the Chamilo homepage that are open to the world. */
$_setting['display_courses_to_anonymous_users'] = 'true';
/** @todo Remove this piece of code because this is not used. */
if (isset($_user['user_id'])) {
$nameTools = api_get_setting('siteName');
}
/* LOGIN */
/**
@ -96,6 +94,7 @@ if (api_get_setting('allow_terms_conditions') == 'true') {
if (!empty($_POST['submitAuth'])) {
// The user has been already authenticated, we are now to find the last login of the user.
if (isset ($_user['user_id'])) {
$track_login_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$sql_last_login = "SELECT UNIX_TIMESTAMP(login_date)
FROM $track_login_table
WHERE login_user_id = '".$_user['user_id']."'
@ -123,17 +122,6 @@ if (!empty($_POST['submitAuth'])) {
event_open();
}
// The header.
/*$header_title = get_lang('Homepage');
//$sitename = api_get_setting('siteName');
if (!api_get_user_id()) {
$header_title = null;
}*/
$header_title = null;
if (!api_is_anonymous()) {
$header_title = " ";
}
$htmlHeadXtra[] = api_get_jquery_libraries_js(array('bxslider'));
$htmlHeadXtra[] ='
<script type="text/javascript">
@ -150,10 +138,6 @@ $(document).ready(function(){
Display::display_header($header_title);
$index = new IndexManager($header_title, false);
/* MAIN CODE */
echo '<div id="content" class="maincontent">';
@ -185,17 +169,7 @@ echo $index->return_home_page();
// Display courses and category list.
//if (!$page_included) {
// Display System announcements
$announcement = isset($_GET['announcement']) ? $_GET['announcement'] : -1;
$announcement = intval($announcement);
if (isset($_user['user_id'])) {
$visibility = api_is_allowed_to_create_course() ? VISIBLE_TEACHER : VISIBLE_STUDENT;
SystemAnnouncementManager :: display_announcements_slider($visibility, $announcement);
} else {
SystemAnnouncementManager :: display_announcements_slider(VISIBLE_GUEST, $announcement);
}
echo $index->return_announcements();
if (api_get_setting('display_categories_on_homepage') == 'true') {
echo '<div class="home_cats">';
@ -206,16 +180,13 @@ echo $index->return_home_page();
echo '</div>';
echo '<div id="menu-wrapper">';
echo $index->return_profile_block();
echo $index->return_profile_block();
// Display right menu: language form, login section + useful weblinks.
$index->display_anonymous_right_menu();
// Display right menu: language form, login section + useful weblinks.
$index->display_anonymous_right_menu();
echo '</div>';
/* Footer */
Display :: display_footer();

@ -489,27 +489,28 @@ class SystemAnnouncementManager {
$sql .= " ORDER BY date_start DESC LIMIT 0,7";
$announcements = Database::query($sql);
$html = '';
if (Database::num_rows($announcements) > 0) {
$query_string = ereg_replace('announcement=[1-9]+', '', $_SERVER['QUERY_STRING']);
$query_string = ereg_replace('&$', '', $query_string);
$url = api_get_self();
echo '<div class="system_announcements">';
echo '<h3>'.get_lang('SystemAnnouncements').'</h3>';
$html .= '<div class="system_announcements">';
$html .= '<h3>'.get_lang('SystemAnnouncements').'</h3>';
//echo '<div style="margin:10px;text-align:right;"><a href="news_list.php">'.get_lang('More').'</a></div>';
echo '<div id="container-slider">
$html .= '<div id="container-slider">
<ul id="slider">';
while ($announcement = Database::fetch_object($announcements)) {
if ($id != $announcement->id) {
echo '<li><h1>'.$announcement->title.'</h1>'.$announcement->content.'</li>';
$html .= '<li><h1>'.$announcement->title.'</h1>'.$announcement->content.'</li>';
} else {
echo '<li><h1>'.$announcement->title.'</h1>'.$announcement->content.'</li>';
$html .= '<li><h1>'.$announcement->title.'</h1>'.$announcement->content.'</li>';
}
}
echo '</ul></div></div>';
$html .= '</ul></div></div>';
}
return;
return $html;
}
}

@ -1,22 +1,101 @@
<?php
require_once api_get_path(LIBRARY_PATH).'system_announcements.lib.php';
require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
require_once api_get_path(SYS_CODE_PATH).'survey/survey.lib.php';
class IndexManager {
var $tpl = false;
var $name = '';
var $tpl = false; //An instance of the template engine
var $name = '';
var $home = '';
var $default_home = 'home/';
function __construct($title, $load_template = true) {
if ($load_template) {
$this->tpl = new Template($title);
}
$home = 'home/';
if (api_get_multiple_access_url()) {
$access_url_id = api_get_current_access_url_id();
$url_info = api_get_access_url($access_url_id);
$url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
$clean_url = replace_dangerous_char($url);
$clean_url = str_replace('/', '-', $clean_url);
$clean_url .= '/';
// if $clean_url == "localhost/" means that the multiple URL was not well configured we don't rename the $home variable
if ($clean_url != 'localhost/')
$home = 'home/'.$clean_url;
}
$this->home = $home;
$this->user_id = api_get_user_id();
}
function set_login_form($use_template = true) {
global $loginFailed;
$login_form = '';
if (!($this->user_id) || api_is_anonymous($this->user_id)) {
// Only display if the user isn't logged in.
$login_form = api_display_language_form(true);
$login_form .= self::display_login_form();
if ($loginFailed) {
$login_form .= self::handle_login_failed();
}
if (api_get_setting('allow_lostpassword') == 'true' || api_get_setting('allow_registration') == 'true') {
$login_form .= '<div class="menusection"><span class="menusectioncaption">'.get_lang('MenuUser').'</span><ul class="menulist">';
if (api_get_setting('allow_registration') != 'false') {
$login_form .= '<li><a href="main/auth/inscription.php">'.get_lang('Reg').'</a></li>';
}
if (api_get_setting('allow_lostpassword') == 'true') {
$login_form .= '<li><a href="main/auth/lostPassword.php">'.get_lang('LostPassword').'</a></li>';
}
$login_form .= '</ul></div>';
}
if (api_number_of_plugins('loginpage_menu') > 0) {
$login_form .= '<div class="note" style="background: none">';
ob_start();
api_plugin('loginpage_menu');
$plugin_login = ob_get_contents();
$login_form .= $plugin_login;
$login_form .= '</div>';
}
if (!empty($login_form)) {
$login_form = '<div class="menu" id="menu">'.$login_form.'</div>';
}
}
$login_form_tmp = $login_form;
if ($use_template)
$this->tpl->assign('login_block', $login_form);
//@todo remove this return
return $login_form;
}
function return_announcements() {
// Display System announcements
$announcement = isset($_GET['announcement']) ? $_GET['announcement'] : -1;
$announcement = intval($announcement);
if (isset($_user['user_id'])) {
$visibility = api_is_allowed_to_create_course() ? VISIBLE_TEACHER : VISIBLE_STUDENT;
$announcements = SystemAnnouncementManager :: display_announcements_slider($visibility, $announcement);
} else {
$announcements = SystemAnnouncementManager :: display_announcements_slider(VISIBLE_GUEST, $announcement);
}
return $announcements;
}
/* Functions */
/**
* This function handles the logout and is called whenever there is a $_GET['logout']
@ -112,24 +191,17 @@ class IndexManager {
* @todo does $_plugins need to be global?
*/
function display_anonymous_right_menu() {
global $loginFailed, $_plugins, $_user, $menu_navigation, $home, $home_old;
global $loginFailed, $_plugins, $_user, $menu_navigation;
$platformLanguage = api_get_setting('platformLanguage');
$platformLanguage = api_get_setting('platformLanguage');
$display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION['studentview'] != 'studentenview');
$current_user_id = api_get_user_id();
$display_add_course_link= api_is_allowed_to_create_course() && ($_SESSION['studentview'] != 'studentenview');
echo self::set_login_form(false);
$current_user_id = api_get_user_id();
echo self::return_teacher_link();
$login_form = self::show_login_form($current_user_id);
if (!empty($login_form)) {
echo '<div class="menu" id="menu">';
echo $login_form;
echo '</div>';
}
echo self::display_teacher_link($current_user_id);
echo self::return_notice($home);
echo self::return_notice();
//Plugin
echo self::return_plugin_campushomepage();
@ -137,9 +209,9 @@ class IndexManager {
function display_teacher_link($current_user_id) {
function return_teacher_link() {
$html = '';
if (!empty($current_user_id)) {
if (!empty($this->user_id)) {
// tabs that are deactivated are added here
$show_menu = false;
@ -194,29 +266,14 @@ class IndexManager {
function return_home_page() {
$home = 'home/';
if (api_get_multiple_access_url()) {
$access_url_id = api_get_current_access_url_id();
$url_info = api_get_access_url($access_url_id);
$url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
$clean_url = replace_dangerous_char($url);
$clean_url = str_replace('/', '-', $clean_url);
$clean_url .= '/';
$home_old = 'home/';
// if $clean_url == "localhost/" means that the multiple URL was not well configured we don't rename the $home variable
if ($clean_url != 'localhost/')
$home = 'home/'.$clean_url;
}
// Including the page for the news
$html = '';
if (!empty($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/', $_GET['include'])) {
$open = @(string)file_get_contents(api_get_path(SYS_PATH).$home.$_GET['include']);
$open = @(string)file_get_contents(api_get_path(SYS_PATH).$this->home.$_GET['include']);
$html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
} else {
if (!empty($_SESSION['user_language_choice'])) {
$user_selected_language = $_SESSION['user_language_choice'];
} elseif (!empty($_SESSION['_user']['language'])) {
@ -224,19 +281,18 @@ class IndexManager {
} else {
$user_selected_language = api_get_setting('platformLanguage');
}
if (!file_exists($home.'home_news_'.$user_selected_language.'.html')) {
if (file_exists($home.'home_top.html')) {
$home_top_temp = file($home.'home_top.html');
if (!file_exists($this->home.'home_news_'.$user_selected_language.'.html')) {
if (file_exists($this->home.'home_top.html')) {
$home_top_temp = file($this->home.'home_top.html');
} else {
$home_top_temp = file($home_old.'home_top.html');
$home_top_temp = file($this->default_home.'home_top.html');
}
$home_top_temp = implode('', $home_top_temp);
} else {
if (file_exists($home.'home_top_'.$user_selected_language.'.html')) {
$home_top_temp = file_get_contents($home.'home_top_'.$user_selected_language.'.html');
if (file_exists($this->home.'home_top_'.$user_selected_language.'.html')) {
$home_top_temp = file_get_contents($this->home.'home_top_'.$user_selected_language.'.html');
} else {
$home_top_temp = file_get_contents($home.'home_top.html');
$home_top_temp = file_get_contents($this->home.'home_top.html');
}
}
if (trim($home_top_temp) == '' && api_is_platform_admin()) {
@ -246,23 +302,22 @@ class IndexManager {
$html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
}
return $html;
}
function return_notice($home) {
function return_notice() {
$sys_path = api_get_path(SYS_PATH);
$user_selected_language = api_get_interface_language();
$html = '';
// Notice
$home_notice = @(string)file_get_contents($sys_path.$home.'home_notice_'.$user_selected_language.'.html');
$home_notice = @(string)file_get_contents($sys_path.$this->home.'home_notice_'.$user_selected_language.'.html');
if (empty($home_notice)) {
$home_notice = @(string)file_get_contents($sys_path.$home.'home_notice.html');
$home_notice = @(string)file_get_contents($sys_path.$this->home.'home_notice.html');
}
if (!empty($home_notice)) {
$home_notice = api_to_system_encoding($home_notice, api_detect_encoding(strip_tags($home_notice)));
echo show_right_block('', $home_notice, 'note');
echo self::show_right_block('', $home_notice, 'note');
}
if (isset($_SESSION['_user']['user_id']) && $_SESSION['_user']['user_id'] != 0) {
@ -278,7 +333,7 @@ class IndexManager {
$content .='<li'.$current.'><a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a></li>';
}
$content .= '</ul>';
$html .= show_right_block(get_lang('MainNavigation'), $content);
$html .= self::show_right_block(get_lang('MainNavigation'), $content);
}
}
@ -289,12 +344,12 @@ class IndexManager {
$user_selected_language = $platformLanguage;
}
$home_menu = @(string)file_get_contents($sys_path.$home.'home_menu_'.$user_selected_language.'.html');
$home_menu = @(string)file_get_contents($sys_path.$this->home.'home_menu_'.$user_selected_language.'.html');
if (!empty($home_menu)) {
$home_menu_content .= '<ul class="menulist">';
$home_menu_content .= api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
$home_menu_content .= '</ul>';
$html .= show_right_block(get_lang('MenuGeneral'), $home_menu_content);
$html .= self::show_right_block(get_lang('MenuGeneral'), $home_menu_content);
}
return $html;
@ -351,12 +406,6 @@ class IndexManager {
/**
* Displays a link to the lost password section
*/
function display_lost_password_info() {
return '<li><a href="main/auth/lostPassword.php">'.get_lang('LostPassword').'</a></li>';
}
/**
* Display list of courses in a category.
@ -674,41 +723,7 @@ class IndexManager {
return $html;
}
function show_login_form($current_user_id) {
$login_form = '';
if (!($current_user_id) || api_is_anonymous($current_user_id) ) {
// Only display if the user isn't logged in.
$login_form = api_display_language_form(true);
$login_form .= self::display_login_form();
if ($loginFailed) {
$login_form .= self::handle_login_failed();
}
if (api_get_setting('allow_lostpassword') == 'true' || api_get_setting('allow_registration') == 'true') {
$login_form .= '<div class="menusection"><span class="menusectioncaption">'.get_lang('MenuUser').'</span><ul class="menulist">';
if (api_get_setting('allow_registration') != 'false') {
$login_form .= '<li><a href="main/auth/inscription.php">'.get_lang('Reg').'</a></li>';
}
if (api_get_setting('allow_lostpassword') == 'true') {
$login_form .= self::display_lost_password_info();
}
$login_form .= '</ul></div>';
}
if (api_number_of_plugins('loginpage_menu') > 0) {
$login_form .= '<div class="note" style="background: none">';
ob_start();
api_plugin('loginpage_menu');
$plugin_login = ob_get_contents();
$login_form .= $plugin_login;
$login_form .= '</div>';
}
}
return $login_form;
}
function return_search_block() {
$html = '';
@ -948,8 +963,10 @@ class IndexManager {
return $plugin_content;
}
/**
* The most important function here, prints the session and course list
*
* */
function return_courses_and_sessions($personal_course_list) {
// Don't change these settings

@ -1,6 +1,13 @@
<div id="header">
{* header *}
{$header1}
{* header right *}
{$header2}
{* menu *}
{$header3}
{* breadcrumb *}
{$header4}
</div>

@ -7,13 +7,17 @@
{block name=body}
<div id="maincontent" class="maincontent">
{$plugin_courses_block}
{$home_page_block}
{$content}
{$announcements_block}
</div>
<div id="menu-wrapper">
{$login_block}
{$profile_block}
{$account_block}
{$teacher_block}
{$notice_block}
{$navigation_course_links}
{$plugin_courses_right_block}
{$reservation_block}

@ -7,11 +7,14 @@
{block name=body}
<h1>My experimental Template!!</h1>
<div id="maincontent" class="maincontent">
{$home_page_block}
{$plugin_courses_block}
{$content}
{$announcements_block}
</div>
<div id="menu-wrapper">
{$login_block}
{$profile_block}
{$account_block}
{$teacher_block}

Loading…
Cancel
Save