Now, index.php and userportal.php are using the smarty template

skala
Julio Montoya 14 years ago
parent 13317a6d98
commit c4944b6ccb
  1. 57
      index-smarty.php
  2. 193
      index.php
  3. 10
      main/inc/lib/template.lib.php
  4. 41
      main/inc/lib/userportal.lib.php
  5. 4
      main/template/default/layout/layout_2_col.tpl
  6. 12
      main/template/default/layout/login_form.tpl
  7. 57
      user_portal.php
  8. 53
      userportal-smarty.php

@ -1,57 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @package chamilo.main
*/
define('CHAMILO_HOMEPAGE', true);
$language_file = array('courses', 'index');
/* Flag forcing the 'current course' reset, as we're not inside a course anymore. */
// Maybe we should change this into an api function? an example: Coursemanager::unset();
$cidReset = true;
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_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);

@ -3,14 +3,8 @@
/**
* @package chamilo.main
* @author Patrick Cool <patrick.cool@UGent.be>, 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[] ='
<script type="text/javascript">
$(document).ready(function(){
$("#slider").bxSlider({
infiniteLoop : true,
auto : true,
pager : true,
autoHover : true,
pause : 10000
});
});
</script>';
/* Action Handling */
//@todo add this in the template
/** @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 javascript is enabled
echo '<noscript>';
echo Display::display_error_message(get_lang("NoJavascript"));
echo '</noscript>';
//check if cookies are enabled
?>
<script language="JavaScript">
if(navigator.cookieEnabled==false){
document.writeln('<?php Display::display_error_message(get_lang("NoCookies")); ?>');
}
</script>
<?php
$index = new IndexManager($header_title);
//Actions
$loginFailed = isset($_GET['loginFailed']) ? true : isset($loginFailed);
$setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
if (!empty($_GET['logout'])) {
$index->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[] ='
<script type="text/javascript">
$(document).ready(function(){
$("#slider").bxSlider({
infiniteLoop : true,
auto : true,
pager : true,
autoHover : true,
pause : 10000
});
});
</script>';
Display::display_header($header_title);
/* MAIN CODE */
echo '<div id="content" class="maincontent">';
//check if javascript is enabled
echo '<noscript>';
echo Display::display_error_message(get_lang("NoJavascript"));
echo '</noscript>';
//check if cookies are enabled
?>
<script language="JavaScript">
if(navigator.cookieEnabled==false){
document.writeln('<?php Display::display_error_message(get_lang("NoCookies")); ?>');
}
</script>
<?php
//@todo add this in the template
// Plugins for loginpage_main AND campushomepage_main.
if (!api_get_user_id()) {
api_plugin('loginpage_main');
api_plugin('loginpage_main');
} else {
api_plugin('campushomepage_main');
api_plugin('campushomepage_main');
}
echo $index->return_home_page();
// Display courses and category list.
//if (!$page_included) {
echo $index->return_announcements();
if (api_get_setting('display_categories_on_homepage') == 'true') {
echo '<div class="home_cats">';
$index->display_anonymous_course_list();
echo '</div>';
}
//}
//@todo add this in the template
if (api_get_setting('display_categories_on_homepage') == 'true') {
echo '<div class="home_cats">';
$index->display_anonymous_course_list();
echo '</div>';
}
echo '</div>';
echo '<div id="menu-wrapper">';
echo $index->return_profile_block();
$tpl = $index->tpl->get_template('layout/layout_2_col.tpl');
$index->set_login_form();
// Display right menu: language form, login section + useful weblinks.
$index->display_anonymous_right_menu();
//@todo move this inside the IndexManager
$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());
echo '</div>';
$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();
$index->tpl->display($tpl);

@ -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;
@ -45,11 +45,13 @@ class Template extends Smarty {
}
private function set_user_parameters() {
if (api_get_user_id()) {
$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() {

@ -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();
$this->tpl->assign('login_language_form', api_display_language_form(true));
$this->tpl->assign('login_form', self::display_login_form());
if ($loginFailed) {
$login_form .= self::handle_login_failed();
$this->tpl->assign('login_failed', 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">';
$login_form .= '<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>';
$login_form .= '</ul>';
}
$this->tpl->assign('login_options', $login_form);
if (api_number_of_plugins('loginpage_menu') > 0) {
$login_form .= '<div class="note" style="background: none">';
$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>';
$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 {
<input type="text" id="query" size="15" name="query" value="" />
<button class="save" type="submit" name="submit" value="'.$search_btn.'" />'.$search_btn.' </button>
</form></div>';
$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 .='<ul class="menulist">';
$booking_content .='<a href="main/reservation/reservation.php">'.get_lang('ManageReservations').'</a><br />';
$booking_content .='</ul>';
$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];
}

@ -13,7 +13,9 @@
</div>
<div id="menu-wrapper">
{$login_block}
{if $_u.logged == 0}
{include file="default/layout/login_form.tpl"}
{/if}
{$profile_block}
{$account_block}
{$teacher_block}

@ -0,0 +1,12 @@
<div id="menu" class="menu">
<div class="menusection">
<span class="menusectioncaption">
{"Login"|get_lang}
</span>
</div>
{$login_language_form}
{$login_form}
{$login_failed}
{$login_options}
{$login_plugin_menu}
</div>

@ -21,6 +21,7 @@
/**
* INIT SECTION
*/
// Language files that should be included.
$language_file = array('courses', 'index','admin');
@ -35,7 +36,6 @@ if (isset($_SESSION['this_section']))
require_once './main/inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'userportal.lib.php';
api_block_anonymous_users(); // Only users who are logged in can proceed.
/* Constants and CONFIGURATION parameters */
@ -183,8 +183,6 @@ if ($load_dirs) {
</script>';
}
Display :: display_header($nameTools);
/* Sniffing system */
//by Juan Carlos Raña Trabado
?>
@ -348,45 +346,40 @@ if (stripos("flash_yes", $_SESSION['sniff_check_some_activex'])===0 || stripos("
/* MAIN CODE */
$index = new IndexManager($nameTools, false);
echo '<div class="maincontent" id="maincontent">'; // Start of content for logged in users.
// Plugins for the my courses main area.
echo $index->return_courses_main_plugin();
// Main courses and session list
echo $index->return_courses_and_sessions($personal_course_list);
$userportal = new IndexManager(get_lang('MyCourses'));
echo '</div>'; // End of content main-section
$tpl = $userportal->tpl->get_template('layout/layout_2_col.tpl');
// Register whether full admin or null admin course by course through an array dbname x user status.
api_session_register('status');
//if (!$userportal->tpl->isCached($tpl, api_get_user_id())) {
/* RIGHT MENU */
//@todo all this could be moved in the IndexManager
echo '<div id="menu-wrapper">';
$courses_list = $userportal->return_courses_main_plugin();
$personal_course_list = UserManager::get_personal_session_course_list(api_get_user_id());
//Profile content
echo $index->return_profile_block();
echo $index->return_account_block();
// Main courses and session list
ob_start();
$userportal->return_courses_and_sessions($personal_course_list);
$courses_and_sessions = ob_get_contents();
ob_get_clean();
echo $index->return_navigation_course_links($menu_navigation);
//
$userportal->tpl->assign('content', $courses_and_sessions);
echo $index->return_plugin_courses_block();
echo $index->return_reservation_block();
echo $index->return_search_block();
echo $index->return_classes_block();
echo '</div>'; // End of menu wrapper
$userportal->tpl->assign('plugin_courses_block', $userportal->return_courses_main_plugin());
$userportal->tpl->assign('profile_block', $userportal->return_profile_block());
$userportal->tpl->assign('account_block', $userportal->return_account_block());
$userportal->tpl->assign('navigation_course_links', $userportal->return_navigation_course_links($menu_navigation));
$userportal->tpl->assign('plugin_courses_right_block', $userportal->return_plugin_courses_block());
$userportal->tpl->assign('reservation_block', $userportal->return_reservation_block());
$userportal->tpl->assign('search_block', $userportal->return_search_block());
$userportal->tpl->assign('classes_block', $userportal->return_classes_block());
/*} else {
}*/
$userportal->tpl->display($tpl);
// Deleting the session_id.
api_session_unregister('session_id');
// Footer
Display :: display_footer();

@ -1,53 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @package chamilo.main
*/
define('CHAMILO_HOMEPAGE', true);
$language_file = array('courses', 'index');
/* Flag forcing the 'current course' reset, as we're not inside a course anymore. */
// Maybe we should change this into an api function? an example: Coursemanager::unset();
$cidReset = true;
/* Included libraries */
require_once 'main/inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'userportal.lib.php';
$this_section = SECTION_COURSES;
api_block_anonymous_users(); // Only users who are logged in can proceed.
$userportal = new IndexManager(get_lang('MyCourses'));
$tpl = $userportal->tpl->get_template('layout/layout_2_col.tpl');
//if (!$userportal->tpl->isCached($tpl, api_get_user_id())) {
//@todo all this could be moved in the IndexManager
$courses_list = $userportal->return_courses_main_plugin();
$personal_course_list = UserManager::get_personal_session_course_list(api_get_user_id());
// Main courses and session list
ob_start();
$userportal->return_courses_and_sessions($personal_course_list);
$courses_and_sessions = ob_get_contents();
ob_get_clean();
//
$userportal->tpl->assign('content', $courses_and_sessions);
$userportal->tpl->assign('plugin_courses_block', $userportal->return_courses_main_plugin());
$userportal->tpl->assign('profile_block', $userportal->return_profile_block());
$userportal->tpl->assign('account_block', $userportal->return_account_block());
$userportal->tpl->assign('navigation_course_links', $userportal->return_navigation_course_links($menu_navigation));
$userportal->tpl->assign('plugin_courses_right_block', $userportal->return_plugin_courses_block());
$userportal->tpl->assign('reservation_block', $userportal->return_reservation_block());
$userportal->tpl->assign('search_block', $userportal->return_search_block());
$userportal->tpl->assign('classes_block', $userportal->return_classes_block());
/*} else {
}*/
$userportal->tpl->display($tpl);
Loading…
Cancel
Save