From c4944b6ccb5d739f9f103bc6398dad2d9c5f58e9 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 5 Sep 2011 11:56:31 +0200 Subject: [PATCH] Now, index.php and userportal.php are using the smarty template --- index-smarty.php | 57 ------ index.php | 193 ++++++++---------- main/inc/lib/template.lib.php | 12 +- main/inc/lib/userportal.lib.php | 47 ++--- main/template/default/layout/layout_2_col.tpl | 8 +- main/template/default/layout/login_form.tpl | 12 ++ user_portal.php | 59 +++--- userportal-smarty.php | 53 ----- 8 files changed, 154 insertions(+), 287 deletions(-) delete mode 100644 index-smarty.php create mode 100644 main/template/default/layout/login_form.tpl delete mode 100644 userportal-smarty.php diff --git a/index-smarty.php b/index-smarty.php deleted file mode 100644 index b7f76d90a1..0000000000 --- a/index-smarty.php +++ /dev/null @@ -1,57 +0,0 @@ - -$(document).ready(function(){ - $("#slider").bxSlider({ - infiniteLoop : true, - auto : true, - pager : true, - autoHover : true, - pause : 10000 - }); -}); -'; - - -$index = new IndexManager($header_title); -$tpl = $index->tpl->get_template('layout/layout_2_col.tpl'); - - - -//@todo move this inside the IndexManager -$index->tpl->assign('login_block', $index->set_login_form()); -$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()); -$index->tpl->assign('plugin_campushomepage', $index->return_plugin_campushomepage()); - -$index->tpl->display($tpl); \ No newline at end of file diff --git a/index.php b/index.php index a15e62a124..0a30f4cb8a 100755 --- a/index.php +++ b/index.php @@ -3,14 +3,8 @@ /** * @package chamilo.main - * @author Patrick Cool , Ghent University, Refactoring - * @todo check the different @todos in this page and really do them - * @todo check if the news management works as expected */ -// Only this script should have this constant defined. This is used to activate the javascript that -// gives the login name automatic focus in header.inc.html. -/** @todo Couldn't this be done using the $HtmlHeadXtra array? */ define('CHAMILO_HOMEPAGE', true); $language_file = array('courses', 'index'); @@ -19,46 +13,61 @@ $language_file = array('courses', 'index'); // Maybe we should change this into an api function? an example: Coursemanager::unset(); $cidReset = true; -/* Included libraries */ - -/** @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).'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); -$setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true'; // The section (for the tabs). $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); +$htmlHeadXtra[] = api_get_jquery_libraries_js(array('bxslider')); +$htmlHeadXtra[] =' +'; + +//@todo add this in the template -/* Action Handling */ +//check if javascript is enabled +echo ''; -/** @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? - * by doing this you could logout from any page instead of only from index.php. From the moment there is a logout=true in the url you will be logged out - * this can be usefull when you are on an open course and you need to log in to edit something and you immediately want to check how anonymous users - * will see it. - */ -$my_user_id = api_get_user_id(); +//check if cookies are enabled +?> + +logout(); + $index->logout(); } /* Table definitions */ - /* Constants and CONFIGURATION parameters */ /** @todo these configuration settings should move to the Chamilo config settings. */ @@ -72,16 +81,16 @@ $_setting['display_courses_to_anonymous_users'] = 'true'; * @todo Consider removing this piece of code because does nothing. */ if (isset($_GET['submitAuth']) && $_GET['submitAuth'] == 1) { - // nice lie!!! - echo 'Attempted breakin - sysadmins notified.'; - session_destroy(); - die(); + // nice lie!!! + echo 'Attempted breakin - sysadmins notified.'; + session_destroy(); + die(); } // Delete session neccesary for legal terms if (api_get_setting('allow_terms_conditions') == 'true') { - unset($_SESSION['update_term_and_condition']); - unset($_SESSION['info_current_user']); + unset($_SESSION['update_term_and_condition']); + unset($_SESSION['info_current_user']); } /** @@ -92,101 +101,65 @@ 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) + // 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']."' ORDER BY login_date DESC LIMIT 1"; - $result_last_login = Database::query($sql_last_login); - if (!$result_last_login) { - if (Database::num_rows($result_last_login) > 0) { - $user_last_login_datetime = Database::fetch_array($result_last_login); - $user_last_login_datetime = $user_last_login_datetime[0]; - api_session_register('user_last_login_datetime'); - } - } - Database::free_result($result_last_login); - - //event_login(); - if (api_is_platform_admin()) { - // decode all open event informations and fill the track_c_* tables - include api_get_path(LIBRARY_PATH).'stats.lib.inc.php'; - decodeOpenInfos(); - } - } - // End login -- if ($_POST['submitAuth']) + $result_last_login = Database::query($sql_last_login); + if (!$result_last_login) { + if (Database::num_rows($result_last_login) > 0) { + $user_last_login_datetime = Database::fetch_array($result_last_login); + $user_last_login_datetime = $user_last_login_datetime[0]; + api_session_register('user_last_login_datetime'); + } + } + Database::free_result($result_last_login); + + //event_login(); + if (api_is_platform_admin()) { + // decode all open event informations and fill the track_c_* tables + include api_get_path(LIBRARY_PATH).'stats.lib.inc.php'; + decodeOpenInfos(); + } + } + // End login -- if ($_POST['submitAuth']) } else { - // Only if login form was not sent because if the form is sent the user was already on the page. - event_open(); + // Only if login form was not sent because if the form is sent the user was already on the page. + event_open(); } -$htmlHeadXtra[] = api_get_jquery_libraries_js(array('bxslider')); -$htmlHeadXtra[] =' -'; - -Display::display_header($header_title); - -/* MAIN CODE */ - -echo '
'; - -//check if javascript is enabled -echo ''; - -//check if cookies are enabled -?> - -return_home_page(); +//@todo add this in the template +if (api_get_setting('display_categories_on_homepage') == 'true') { + echo '
'; + $index->display_anonymous_course_list(); + echo '
'; +} -// Display courses and category list. -//if (!$page_included) { - echo $index->return_announcements(); - - if (api_get_setting('display_categories_on_homepage') == 'true') { - echo '
'; - $index->display_anonymous_course_list(); - echo '
'; - } -//} -echo '
'; +$tpl = $index->tpl->get_template('layout/layout_2_col.tpl'); +$index->set_login_form(); -echo ''; +$index->tpl->assign('profile_block', $index->return_profile_block()); +$index->tpl->assign('notice_block', $index->return_notice()); +$index->tpl->assign('plugin_campushomepage', $index->return_plugin_campushomepage()); -/* Footer */ -Display :: display_footer(); \ No newline at end of file +$index->tpl->display($tpl); \ No newline at end of file diff --git a/main/inc/lib/template.lib.php b/main/inc/lib/template.lib.php index 13e1f20cbe..aee7902738 100644 --- a/main/inc/lib/template.lib.php +++ b/main/inc/lib/template.lib.php @@ -6,7 +6,7 @@ require_once api_get_path(LIBRARY_PATH).'smarty/Smarty.class.php'; class Template extends Smarty { - var $style = 'experimental'; //see the template folder + var $style = 'default'; //see the template folder function __construct($title = '') { $this->title = $title; @@ -44,12 +44,14 @@ class Template extends Smarty { return $this->style.'/'.$name; } - private function set_user_parameters() { - if (api_get_user_id()) { + private function set_user_parameters() { + $user_info = array(); + $user_info['logged'] = 0; + if (api_get_user_id() && !api_is_anonymous()) { $user_info = api_get_user_info(); - //$this->assign('user_info', $user_info); - $this->assign('_u', $user_info); + $user_info['logged'] = 1; } + $this->assign('_u', $user_info); } private function set_system_parameters() { diff --git a/main/inc/lib/userportal.lib.php b/main/inc/lib/userportal.lib.php index e7057a271e..2f4c103d8f 100644 --- a/main/inc/lib/userportal.lib.php +++ b/main/inc/lib/userportal.lib.php @@ -33,10 +33,11 @@ class IndexManager { } $this->home = $home; $this->user_id = api_get_user_id(); + $this->load_directories_preview = true; } - function set_login_form($use_template = true) { + function set_login_form() { global $loginFailed; $login_form = ''; @@ -44,41 +45,35 @@ class IndexManager { 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(); + $this->tpl->assign('login_language_form', api_display_language_form(true)); + $this->tpl->assign('login_form', self::display_login_form()); + + if ($loginFailed) { + $this->tpl->assign('login_failed', self::handle_login_failed()); } if (api_get_setting('allow_lostpassword') == 'true' || api_get_setting('allow_registration') == 'true') { - $login_form .= ''; + $login_form .= ''; } + $this->tpl->assign('login_options', $login_form); if (api_number_of_plugins('loginpage_menu') > 0) { - $login_form .= '
'; + $login_form = '
'; ob_start(); api_plugin('loginpage_menu'); $plugin_login = ob_get_contents(); $login_form .= $plugin_login; $login_form .= '
'; - } - if (!empty($login_form)) { - $login_form = ''; + $this->tpl->assign('login_plugin_menu', $login_form); } - } - $login_form_tmp = $login_form; - if ($use_template) - $this->tpl->assign('login_block', $login_form); - //@todo remove this return - - return $login_form; + } } @@ -775,7 +770,7 @@ class IndexManager {
'; - $html .= show_right_block(get_lang('Search'), $search_content); + $html .= self::show_right_block(get_lang('Search'), $search_content); } return $html; } @@ -799,7 +794,7 @@ class IndexManager { } if (!empty($classes)) { $classes = Display::tag('ul', $classes, array('class'=>'menulist')); - $html .= show_right_block(get_lang('Classes'), $classes); + $html .= self::show_right_block(get_lang('Classes'), $classes); } } return $html; @@ -811,7 +806,7 @@ class IndexManager { $booking_content .=''; - $html .= show_right_block(get_lang('Booking'), $booking_content); + $html .= self::show_right_block(get_lang('Booking'), $booking_content); } return $html; } @@ -824,7 +819,7 @@ class IndexManager { api_plugin('mycourses_menu'); $plugin_content = ob_get_contents(); ob_end_clean(); - echo show_right_block('', $plugin_content); + echo self::show_right_block('', $plugin_content); } } @@ -1192,8 +1187,8 @@ class IndexManager { // Sessions and courses that are not in a session category. if (!isset($_GET['history'])) { // If we're not in the history view... - CourseManager :: display_special_courses(api_get_user_id(), $load_dirs); - CourseManager :: display_courses(api_get_user_id(), $load_dirs); + CourseManager :: display_special_courses(api_get_user_id(), $this->load_directories_preview); + CourseManager :: display_courses(api_get_user_id(), $this->load_directories_preview); } // Independent sessions. foreach ($category['sessions'] as $session) { @@ -1223,7 +1218,7 @@ class IndexManager { if ($session_now > $allowed_time) { //read only and accesible if (api_get_setting('hide_courses_in_sessions') == 'false') { - $c = CourseManager :: get_logged_user_course_html($course, $session['details']['id'], 'session_course_item', true, $load_dirs); + $c = CourseManager :: get_logged_user_course_html($course, $session['details']['id'], 'session_course_item', true, $this->load_directories_preview); //$c = CourseManager :: get_logged_user_course_html($course, $session['details']['id'], 'session_course_item',($session['details']['visibility']==3?false:true)); $html_courses_session .= $c[1]; } diff --git a/main/template/default/layout/layout_2_col.tpl b/main/template/default/layout/layout_2_col.tpl index 8e141b80e6..1c6c89cc8c 100644 --- a/main/template/default/layout/layout_2_col.tpl +++ b/main/template/default/layout/layout_2_col.tpl @@ -1,7 +1,7 @@ {extends file="default/layout/main.tpl"} {block name=header} - {include file="default/layout/header.tpl"} + {include file="default/layout/header.tpl"} {/block} {block name=body} @@ -12,8 +12,10 @@ {$announcements_block} -