Minor - code style changes

skala
Julio Montoya 12 years ago
parent 4bc0525d3e
commit ea660a2eb2
  1. 142
      index.php
  2. 5
      news_list.php
  3. 347
      user_portal.php

@ -3,8 +3,7 @@
/** /**
* @package chamilo.main * @package chamilo.main
*/ */
define('CHAMILO_HOMEPAGE', true); define('CHAMILO_HOMEPAGE', true);
$language_file = array('courses', 'index'); $language_file = array('courses', 'index');
@ -20,7 +19,7 @@ require_once 'main/chat/chat_functions.lib.php';
$this_section = SECTION_CAMPUS; $this_section = SECTION_CAMPUS;
$htmlHeadXtra[] = api_get_jquery_libraries_js(array('bxslider')); $htmlHeadXtra[] = api_get_jquery_libraries_js(array('bxslider'));
$htmlHeadXtra[] =' $htmlHeadXtra[] = '
<script> <script>
$(document).ready(function(){ $(document).ready(function(){
$("#slider").bxSlider({ $("#slider").bxSlider({
@ -44,7 +43,9 @@ use Symfony\Component\HttpFoundation\Response;
class IndexController class IndexController
{ {
public function indexAction(Application $app) {
public function indexAction(Application $app)
{
$request = $app['request']; $request = $app['request'];
//Actions //Actions
@ -56,28 +57,22 @@ class IndexController
//$article = $app['orm.em']->getRepository('Entity\EntityCourse'); //$article = $app['orm.em']->getRepository('Entity\EntityCourse');
//$courses_query = $app['orm.em']->createQuery('SELECT a FROM Entity\EntityCourse a'); //$courses_query = $app['orm.em']->createQuery('SELECT a FROM Entity\EntityCourse a');
//$a = new EntityCourse(); //$a = new EntityCourse();
//require_once '/var/www/chamilo11/main/inc/Entity/EntityCourse.php';
//$article = $app['orm.em']->getRepository('EntityCourse'); //$article = $app['orm.em']->getRepository('EntityCourse');
//var_dump($article); //var_dump($article);
//$courses_query = $app['orm.em']->createQuery('SELECT a FROM Entity\EntityCourse a'); //$courses_query = $app['orm.em']->createQuery('SELECT a FROM Entity\EntityCourse a');
/* /*
$paginator = new Doctrine\ORM\Tools\Pagination\Paginator($courses_query, $fetchJoinCollection = true); $paginator = new Doctrine\ORM\Tools\Pagination\Paginator($courses_query, $fetchJoinCollection = true);
$c = count($paginator); $c = count($paginator);
foreach ($paginator as $course) { foreach ($paginator as $course) {
echo $course->getCode() . "\n"; echo $course->getCode() . "\n";
} }
exit;*/ exit; */
//$app['orm.em']->find('EntityCourse', 1); //$app['orm.em']->find('EntityCourse', 1);
//var_dump($app['orm.ems']['mysql']); //var_dump($app['orm.ems']['mysql']);
// Defines wether or not anonymous visitors can see a list of the courses on the Chamilo homepage that are open to the world. // 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'; //$_setting['display_courses_to_anonymous_users'] = 'true';
// Delete session neccesary for legal terms // Delete session neccesary for legal terms
if (api_get_setting('allow_terms_conditions') == 'true') { if (api_get_setting('allow_terms_conditions') == 'true') {
unset($_SESSION['term_and_condition']); unset($_SESSION['term_and_condition']);
@ -130,17 +125,17 @@ class IndexController
$announcements_block = PageController::return_announcements(); $announcements_block = PageController::return_announcements();
} }
$app['template']->assign('hot_courses', $hot_courses); $app['template']->assign('hot_courses', $hot_courses);
$app['template']->assign('announcements_block', $announcements_block); $app['template']->assign('announcements_block', $announcements_block);
//Homepage //Homepage
$app['template']->assign('home_page_block', PageController::return_home_page()); $app['template']->assign('home_page_block', PageController::return_home_page());
//Navigation links //Navigation links
$nav_links = $app['template']->return_navigation_links(); $nav_links = $app['template']->return_navigation_links();
$app['template']->assign('navigation_course_links', $nav_links); $app['template']->assign('navigation_course_links', $nav_links);
$app['template']->assign('main_navigation_block', $nav_links); $app['template']->assign('main_navigation_block', $nav_links);
PageController::return_notice(); PageController::return_notice();
PageController::return_help(); PageController::return_help();
@ -156,17 +151,18 @@ class IndexController
/** /**
* *
* @todo This piece of code should probably move to local.inc.php where the actual login procedure is handled. * @todo This piece of code should probably move to local.inc.php where the actual login procedure is handled.
* @todo Check if this code is used. I think this code is never executed because after clicking the submit button * @todo Check if this code is used. I think this code is never executed because after clicking the submit button
* the code does the stuff in local.inc.php and then redirects to index.php or user_portal.php depending * the code does the stuff in local.inc.php and then redirects to index.php or user_portal.php depending
* on api_get_setting('page_after_login'). * on api_get_setting('page_after_login').
* @deprecated seems not to be used * @deprecated seems not to be used
*/ */
function check_last_login() { function check_last_login()
{
if (!empty($_POST['submitAuth'])) { if (!empty($_POST['submitAuth'])) {
// The user has been already authenticated, we are now to find the last login of the user. // The user has been already authenticated, we are now to find the last login of the user.
if (!empty($this->user_id)) { if (!empty($this->user_id)) {
$track_login_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN); $track_login_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$sql_last_login = "SELECT login_date $sql_last_login = "SELECT login_date
FROM $track_login_table FROM $track_login_table
WHERE login_user_id = '".$this->user_id."' WHERE login_user_id = '".$this->user_id."'
@ -194,62 +190,64 @@ class IndexController
} }
} }
function set_login_form(Application $app) { function set_login_form(Application $app)
{
$user_id = api_get_user_id(); $user_id = api_get_user_id();
$login_form = null; $login_form = null;
if (!$user_id || api_is_anonymous($user_id)) { if (!$user_id || api_is_anonymous($user_id)) {
// Only display if the user isn't logged in. // Only display if the user isn't logged in.
$app['template']->assign('login_language_form', api_display_language_form(true)); $app['template']->assign('login_language_form', api_display_language_form(true));
//self::display_login_form($app); //self::display_login_form($app);
$app['template']->assign('login_form', self::display_login_form($app)); $app['template']->assign('login_form', self::display_login_form($app));
if (api_get_setting('allow_lostpassword') == 'true' || api_get_setting('allow_registration') == 'true') { if (api_get_setting('allow_lostpassword') == 'true' || api_get_setting('allow_registration') == 'true') {
$login_form .= '<ul class="nav nav-list">'; $login_form .= '<ul class="nav nav-list">';
if (api_get_setting('allow_registration') != 'false') { if (api_get_setting('allow_registration') != 'false') {
$login_form .= '<li><a href="main/auth/inscription.php">'.get_lang('Reg').'</a></li>'; $login_form .= '<li><a href="main/auth/inscription.php">'.get_lang('Reg').'</a></li>';
} }
if (api_get_setting('allow_lostpassword') == 'true') { if (api_get_setting('allow_lostpassword') == 'true') {
$login_form .= '<li><a href="main/auth/lostPassword.php">'.get_lang('LostPassword').'</a></li>'; $login_form .= '<li><a href="main/auth/lostPassword.php">'.get_lang('LostPassword').'</a></li>';
} }
$login_form .= '</ul>'; $login_form .= '</ul>';
} }
$app['template']->assign('login_options', $login_form); $app['template']->assign('login_options', $login_form);
} }
} }
function logout() { function logout()
{
$user_id = api_get_user_id(); $user_id = api_get_user_id();
online_logout($user_id, true); online_logout($user_id, true);
} }
function display_login_form(Application $app) { function display_login_form(Application $app)
/*{{ form_widget(form) }} {
$form = $app['form.factory']->createBuilder('form') /* {{ form_widget(form) }}
->add('name') $form = $app['form.factory']->createBuilder('form')
->add('email') ->add('name')
->add('gender', 'choice', array( ->add('email')
'choices' => array(1 => 'male', 2 => 'female'), ->add('gender', 'choice', array(
'expanded' => true, 'choices' => array(1 => 'male', 2 => 'female'),
)) 'expanded' => true,
->getForm(); ))
return $app['template']->assign('form', $form->createView()); ->getForm();
*/ return $app['template']->assign('form', $form->createView());
*/
$form = new FormValidator('formLogin', 'POST', null, null, array('class'=>'form-vertical'));
$form = new FormValidator('formLogin', 'POST', null, null, array('class' => 'form-vertical'));
$form->addElement('text', 'login', get_lang('UserName'), array('class' => 'span2 autocapitalize_off', 'autofocus' => 'autofocus')); $form->addElement('text', 'login', get_lang('UserName'), array('class' => 'span2 autocapitalize_off', 'autofocus' => 'autofocus'));
$form->addElement('password', 'password', get_lang('Pass'), array('class' => 'span2')); $form->addElement('password', 'password', get_lang('Pass'), array('class' => 'span2'));
$form->addElement('style_submit_button','submitAuth', get_lang('LoginEnter'), array('class' => 'btn')); $form->addElement('style_submit_button', 'submitAuth', get_lang('LoginEnter'), array('class' => 'btn'));
$html = $form->return_form(); $html = $form->return_form();
if (api_get_setting('openid_authentication') == 'true') { if (api_get_setting('openid_authentication') == 'true') {
include_once 'main/auth/openid/login.php'; include_once 'main/auth/openid/login.php';
$html .= '<div>'.openid_form().'</div>'; $html .= '<div>'.openid_form().'</div>';
} }
return $html; return $html;
} }
} }
$app->match('/', 'IndexController::indexAction', 'POST|GET'); $app->match('/', 'IndexController::indexAction', 'POST|GET');
$app->run(); $app->run();
//$app['http_cache']->run(); //$app['http_cache']->run();

@ -9,8 +9,8 @@ require_once 'main/inc/global.inc.php';
$tool_name = get_lang('SystemAnnouncements'); $tool_name = get_lang('SystemAnnouncements');
$actions = ''; $actions = '';
if (api_is_platform_admin()) { if (api_is_platform_admin()) {
$actions = '<a href="'.api_get_path(WEB_PATH).'main/admin/system_announcements.php">'.Display::return_icon('edit.png', get_lang('EditSystemAnnouncement'), array(), 32).'</a>'; $actions = '<a href="'.api_get_path(WEB_PATH).'main/admin/system_announcements.php">'.Display::return_icon('edit.png', get_lang('EditSystemAnnouncement'), array(), 32).'</a>';
} }
if (api_is_anonymous()) { if (api_is_anonymous()) {
@ -22,6 +22,5 @@ $content = SystemAnnouncementManager ::display_announcements_slider($visibility
$tpl = new Template($tool_name); $tpl = new Template($tool_name);
$tpl->assign('actions', $actions); $tpl->assign('actions', $actions);
//$tpl->assign('message', $message);
$tpl->assign('content', $content); $tpl->assign('content', $content);
$tpl->display_one_col_template(); $tpl->display_one_col_template();

@ -18,15 +18,14 @@
/** /**
* INIT SECTION * INIT SECTION
*/ */
// Language files that should be included. // Language files that should be included.
use \ChamiloSession as Session; use \ChamiloSession as Session;
$language_file = array('courses', 'index','admin'); $language_file = array('courses', 'index', 'admin');
$cidReset = true; /* Flag forcing the 'current course' reset, $cidReset = true; /* Flag forcing the 'current course' reset,
as we're not inside a course anymore */ as we're not inside a course anymore */
if (isset($_SESSION['this_section'])) if (isset($_SESSION['this_section']))
unset($_SESSION['this_section']); // For HTML editor repository. unset($_SESSION['this_section']); // For HTML editor repository.
@ -43,11 +42,11 @@ $this_section = SECTION_COURSES;
$load_dirs = api_get_setting('show_documents_preview'); $load_dirs = api_get_setting('show_documents_preview');
if ($load_dirs) { if ($load_dirs) {
$url = api_get_path(WEB_AJAX_PATH).'document.ajax.php?a=document_preview'; $url = api_get_path(WEB_AJAX_PATH).'document.ajax.php?a=document_preview';
$folder_icon = api_get_path(WEB_IMG_PATH).'icons/22/folder.png'; $folder_icon = api_get_path(WEB_IMG_PATH).'icons/22/folder.png';
$close_icon = api_get_path(WEB_IMG_PATH).'loading1.gif'; $close_icon = api_get_path(WEB_IMG_PATH).'loading1.gif';
$htmlHeadXtra[] = '<script> $htmlHeadXtra[] = '<script>
$(document).ready(function() { $(document).ready(function() {
$(".document_preview_container").hide(); $(".document_preview_container").hide();
@ -85,13 +84,14 @@ use Symfony\Component\HttpFoundation\Response;
class UserPortalController class UserPortalController
{ {
function indexAction(Application $app) function indexAction(Application $app)
{ {
// Check if a user is enrolled only in one course for going directly to the course after the login. // Check if a user is enrolled only in one course for going directly to the course after the login.
if (api_get_setting('go_to_course_after_login') == 'true') { if (api_get_setting('go_to_course_after_login') == 'true') {
// Get the courses list // Get the courses list
$personal_course_list = UserManager::get_personal_session_course_list(api_get_user_id()); $personal_course_list = UserManager::get_personal_session_course_list(api_get_user_id());
$my_session_list = array(); $my_session_list = array();
$count_of_courses_no_sessions = 0; $count_of_courses_no_sessions = 0;
@ -109,10 +109,10 @@ class UserPortalController
if ($count_of_sessions == 1 && $count_of_courses_no_sessions == 0) { if ($count_of_sessions == 1 && $count_of_courses_no_sessions == 0) {
$key = array_keys($personal_course_list); $key = array_keys($personal_course_list);
$course_info = $personal_course_list[$key[0]]; $course_info = $personal_course_list[$key[0]];
$course_directory = $course_info['course_info']['path']; $course_directory = $course_info['course_info']['path'];
$id_session = isset($course_info['id_session']) ? $course_info['id_session'] : 0; $id_session = isset($course_info['id_session']) ? $course_info['id_session'] : 0;
$url = api_get_path(WEB_CODE_PATH).'session/?session_id='.$id_session; $url = api_get_path(WEB_CODE_PATH).'session/?session_id='.$id_session;
@ -121,10 +121,10 @@ class UserPortalController
} }
if (!isset($_SESSION['coursesAlreadyVisited']) && $count_of_sessions == 0 && $count_of_courses_no_sessions == 1) { if (!isset($_SESSION['coursesAlreadyVisited']) && $count_of_sessions == 0 && $count_of_courses_no_sessions == 1) {
$key = array_keys($personal_course_list); $key = array_keys($personal_course_list);
$course_info = $personal_course_list[$key[0]]; $course_info = $personal_course_list[$key[0]];
$course_directory = $course_info['course_info']['path']; $course_directory = $course_info['course_info']['path'];
$id_session = isset($course_info['id_session']) ? $course_info['id_session'] : 0; $id_session = isset($course_info['id_session']) ? $course_info['id_session'] : 0;
$url = api_get_path(WEB_COURSE_PATH).$course_directory.'/?id_session='.$id_session; $url = api_get_path(WEB_COURSE_PATH).$course_directory.'/?id_session='.$id_session;
header('location:'.$url); header('location:'.$url);
@ -133,20 +133,20 @@ class UserPortalController
} }
/* Sniffing system */ /* Sniffing system */
/* /*
//store posts to sessions //store posts to sessions
if ($_SESSION['sniff_navigator']!="checked") { if ($_SESSION['sniff_navigator']!="checked") {
$_SESSION['sniff_navigator']=Security::remove_XSS($_POST['sniff_navigator']); $_SESSION['sniff_navigator']=Security::remove_XSS($_POST['sniff_navigator']);
$_SESSION['sniff_screen_size_w']=Security::remove_XSS($_POST['sniff_navigator_screen_size_w']); $_SESSION['sniff_screen_size_w']=Security::remove_XSS($_POST['sniff_navigator_screen_size_w']);
$_SESSION['sniff__screen_size_h']=Security::remove_XSS($_POST['sniff_navigator_screen_size_h']); $_SESSION['sniff__screen_size_h']=Security::remove_XSS($_POST['sniff_navigator_screen_size_h']);
$_SESSION['sniff_type_mimetypes']=Security::remove_XSS($_POST['sniff_navigator_type_mimetypes']); $_SESSION['sniff_type_mimetypes']=Security::remove_XSS($_POST['sniff_navigator_type_mimetypes']);
$_SESSION['sniff_suffixes_mimetypes']=Security::remove_XSS($_POST['sniff_navigator_suffixes_mimetypes']); $_SESSION['sniff_suffixes_mimetypes']=Security::remove_XSS($_POST['sniff_navigator_suffixes_mimetypes']);
$_SESSION['sniff_list_plugins']=Security::remove_XSS($_POST['sniff_navigator_list_plugins']); $_SESSION['sniff_list_plugins']=Security::remove_XSS($_POST['sniff_navigator_list_plugins']);
$_SESSION['sniff_check_some_activex']=Security::remove_XSS($_POST['sniff_navigator_check_some_activex']); $_SESSION['sniff_check_some_activex']=Security::remove_XSS($_POST['sniff_navigator_check_some_activex']);
$_SESSION['sniff_check_some_plugins']=Security::remove_XSS($_POST['sniff_navigator_check_some_plugins']); $_SESSION['sniff_check_some_plugins']=Security::remove_XSS($_POST['sniff_navigator_check_some_plugins']);
$_SESSION['sniff_java']=Security::remove_XSS($_POST['sniff_navigator_java']); $_SESSION['sniff_java']=Security::remove_XSS($_POST['sniff_navigator_java']);
$_SESSION['sniff_java_sun_ver']=Security::remove_XSS($_POST['sniff_navigator_java_sun_ver']); $_SESSION['sniff_java_sun_ver']=Security::remove_XSS($_POST['sniff_navigator_java_sun_ver']);
}*/ } */
@ -161,36 +161,36 @@ class UserPortalController
$app['template']->assign('content', $courses_and_sessions); $app['template']->assign('content', $courses_and_sessions);
/* /*
if (api_get_setting('allow_browser_sniffer') == 'true') { if (api_get_setting('allow_browser_sniffer') == 'true') {
if ($_SESSION['sniff_navigator']!="checked") { if ($_SESSION['sniff_navigator']!="checked") {
$app['template']->assign('show_sniff', 1); $app['template']->assign('show_sniff', 1);
} else { } else {
$app['template']->assign('show_sniff', 0); $app['template']->assign('show_sniff', 0);
} }
} }
//check for flash and message //check for flash and message
$sniff_notification = ''; $sniff_notification = '';
$some_activex=$_SESSION['sniff_check_some_activex']; $some_activex=$_SESSION['sniff_check_some_activex'];
$some_plugins=$_SESSION['sniff_check_some_plugins']; $some_plugins=$_SESSION['sniff_check_some_plugins'];
if(!empty($some_activex) || !empty($some_plugins)){ if(!empty($some_activex) || !empty($some_plugins)){
if (! preg_match("/flash_yes/", $some_activex) && ! preg_match("/flash_yes/", $some_plugins)) { if (! preg_match("/flash_yes/", $some_activex) && ! preg_match("/flash_yes/", $some_plugins)) {
$sniff_notification = Display::return_message(get_lang('NoFlash'), 'warning', true); $sniff_notification = Display::return_message(get_lang('NoFlash'), 'warning', true);
//js verification - To annoying of redirecting every time the page //js verification - To annoying of redirecting every time the page
$app['template']->assign('sniff_notification', $sniff_notification); $app['template']->assign('sniff_notification', $sniff_notification);
} }
}*/ } */
PageController::return_profile_block(); PageController::return_profile_block();
PageController::return_user_image_block(); PageController::return_user_image_block();
PageController::return_course_block(); PageController::return_course_block();
$app['template']->assign('navigation_course_links', $app['template']->return_navigation_links()); $app['template']->assign('navigation_course_links', $app['template']->return_navigation_links());
PageController::return_reservation_block(); PageController::return_reservation_block();
$app['template']->assign('search_block', PageController::return_search_block()); $app['template']->assign('search_block', PageController::return_search_block());
$app['template']->assign('classes_block', PageController::return_classes_block()); $app['template']->assign('classes_block', PageController::return_classes_block());
PageController::return_skills_links(); PageController::return_skills_links();
// Deleting the session_id. // Deleting the session_id.
@ -202,19 +202,18 @@ class UserPortalController
return new Response($response, 200, array()); return new Response($response, 200, array());
} }
function check_last_login()
function check_last_login() { {
/** /**
* @todo This piece of code should probably move to local.inc.php where the actual login procedure is handled. * @todo This piece of code should probably move to local.inc.php where the actual login procedure is handled.
* @todo Check if this code is used. I think this code is never executed because after clicking the submit button * @todo Check if this code is used. I think this code is never executed because after clicking the submit button
* the code does the stuff in local.inc.php and then redirects to index.php or user_portal.php depending * the code does the stuff in local.inc.php and then redirects to index.php or user_portal.php depending
* on api_get_setting('page_after_login'). * on api_get_setting('page_after_login').
*/ */
if (!empty($_POST['submitAuth'])) { if (!empty($_POST['submitAuth'])) {
// The user has been already authenticated, we are now to find the last login of the user. // The user has been already authenticated, we are now to find the last login of the user.
if (!empty($this->user_id)) { if (!empty($this->user_id)) {
$track_login_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN); $track_login_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$sql_last_login = "SELECT login_date $sql_last_login = "SELECT login_date
FROM $track_login_table FROM $track_login_table
WHERE login_user_id = '".$this->user_id."' WHERE login_user_id = '".$this->user_id."'
@ -242,120 +241,125 @@ class UserPortalController
} }
} }
function set_login_form() { function set_login_form()
global $loginFailed; {
global $loginFailed;
$login_form = ''; $login_form = '';
if (!($this->user_id) || api_is_anonymous($this->user_id)) { if (!($this->user_id) || api_is_anonymous($this->user_id)) {
// Only display if the user isn't logged in. // Only display if the user isn't logged in.
$this->page->assign('login_language_form', api_display_language_form(true)); $this->page->assign('login_language_form', api_display_language_form(true));
$this->page->assign('login_form', self::display_login_form()); $this->page->assign('login_form', self::display_login_form());
if ($loginFailed) { if ($loginFailed) {
$this->page->assign('login_failed', self::handle_login_failed()); $this->page->assign('login_failed', self::handle_login_failed());
} }
if (api_get_setting('allow_lostpassword') == 'true' || api_get_setting('allow_registration') == 'true') { if (api_get_setting('allow_lostpassword') == 'true' || api_get_setting('allow_registration') == 'true') {
$login_form .= '<ul class="nav nav-list">'; $login_form .= '<ul class="nav nav-list">';
if (api_get_setting('allow_registration') != 'false') { if (api_get_setting('allow_registration') != 'false') {
$login_form .= '<li><a href="main/auth/inscription.php">'.get_lang('Reg').'</a></li>'; $login_form .= '<li><a href="main/auth/inscription.php">'.get_lang('Reg').'</a></li>';
} }
if (api_get_setting('allow_lostpassword') == 'true') { if (api_get_setting('allow_lostpassword') == 'true') {
$login_form .= '<li><a href="main/auth/lostPassword.php">'.get_lang('LostPassword').'</a></li>'; $login_form .= '<li><a href="main/auth/lostPassword.php">'.get_lang('LostPassword').'</a></li>';
} }
$login_form .= '</ul>'; $login_form .= '</ul>';
} }
$this->page->assign('login_options', $login_form); $this->page->assign('login_options', $login_form);
} }
} }
/** /**
* Alias for the online_logout() function * Alias for the online_logout() function
*/ */
function logout() { function logout()
{
online_logout($this->user_id, true); online_logout($this->user_id, true);
} }
/** /**
* This function checks if there are courses that are open to the world in the platform course categories (=faculties) * This function checks if there are courses that are open to the world in the platform course categories (=faculties)
* *
* @param string $category * @param string $category
* @return boolean * @return boolean
*/ */
function category_has_open_courses($category) { function category_has_open_courses($category)
$setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true'; {
$main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE); $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
$main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
$category = Database::escape_string($category); $category = Database::escape_string($category);
$sql_query = "SELECT * FROM $main_course_table WHERE category_code='$category'"; $sql_query = "SELECT * FROM $main_course_table WHERE category_code='$category'";
$sql_result = Database::query($sql_query); $sql_result = Database::query($sql_query);
while ($course = Database::fetch_array($sql_result)) { while ($course = Database::fetch_array($sql_result)) {
if (!$setting_show_also_closed_courses) { if (!$setting_show_also_closed_courses) {
if ((api_get_user_id() > 0 && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) { if ((api_get_user_id() > 0 && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
return true; //at least one open course return true; //at least one open course
} }
} else { } else {
if (isset($course['visibility'])) { if (isset($course['visibility'])) {
return true; // At least one course (it does not matter weither it's open or not because $setting_show_also_closed_courses = true). return true; // At least one course (it does not matter weither it's open or not because $setting_show_also_closed_courses = true).
} }
} }
} }
return false; return false;
} }
/** /**
* Reacts on a failed login: * Reacts on a failed login:
* Displays an explanation with a link to the registration form. * Displays an explanation with a link to the registration form.
* *
* @version 1.0.1 * @version 1.0.1
*/ */
function handle_login_failed() { function handle_login_failed()
{
$message = get_lang('InvalidId'); $message = get_lang('InvalidId');
if (!isset($_GET['error'])) { if (!isset($_GET['error'])) {
if (api_is_self_registration_allowed()) { if (api_is_self_registration_allowed()) {
$message = get_lang('InvalidForSelfRegistration'); $message = get_lang('InvalidForSelfRegistration');
} }
} else { } else {
switch ($_GET['error']) { switch ($_GET['error']) {
case '': case '':
if (api_is_self_registration_allowed()) { if (api_is_self_registration_allowed()) {
$message = get_lang('InvalidForSelfRegistration'); $message = get_lang('InvalidForSelfRegistration');
} }
break; break;
case 'account_expired': case 'account_expired':
$message = get_lang('AccountExpired'); $message = get_lang('AccountExpired');
break; break;
case 'account_inactive': case 'account_inactive':
$message = get_lang('AccountInactive'); $message = get_lang('AccountInactive');
break; break;
case 'user_password_incorrect': case 'user_password_incorrect':
$message = get_lang('InvalidId'); $message = get_lang('InvalidId');
break; break;
case 'access_url_inactive': case 'access_url_inactive':
$message = get_lang('AccountURLInactive'); $message = get_lang('AccountURLInactive');
break; break;
case 'unrecognize_sso_origin': case 'unrecognize_sso_origin':
//$message = get_lang('SSOError'); //$message = get_lang('SSOError');
break; break;
} }
} }
return Display::return_message($message, 'error'); return Display::return_message($message, 'error');
} }
/** /**
* retrieves all the courses that the user has already subscribed to * retrieves all the courses that the user has already subscribed to
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
* @param int $user_id: the id of the user * @param int $user_id: the id of the user
* @return array an array containing all the information of the courses of the given user * @return array an array containing all the information of the courses of the given user
*/ */
function get_courses_of_user($user_id) { function get_courses_of_user($user_id)
$table_course = Database::get_main_table(TABLE_MAIN_COURSE); {
$table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
// Secondly we select the courses that are in a category (user_course_cat <> 0) and sort these according to the sort of the category $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$user_id = intval($user_id); // Secondly we select the courses that are in a category (user_course_cat <> 0) and sort these according to the sort of the category
$sql_select_courses = "SELECT course.code k, course.visual_code vc, course.subscribe subscr, course.unsubscribe unsubscr, $user_id = intval($user_id);
$sql_select_courses = "SELECT course.code k, course.visual_code vc, course.subscribe subscr, course.unsubscribe unsubscr,
course.title i, course.tutor_name t, course.db_name db, course.directory dir, course_rel_user.status status, course.title i, course.tutor_name t, course.db_name db, course.directory dir, course_rel_user.status status,
course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat
FROM $table_course course, FROM $table_course course,
@ -364,16 +368,27 @@ class UserPortalController
AND course_rel_user.user_id = '".$user_id."' AND course_rel_user.user_id = '".$user_id."'
AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH." AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."
ORDER BY course_rel_user.sort ASC"; ORDER BY course_rel_user.sort ASC";
$result = Database::query($sql_select_courses); $result = Database::query($sql_select_courses);
$courses = array(); $courses = array();
while ($row = Database::fetch_array($result)) { while ($row = Database::fetch_array($result)) {
// We only need the database name of the course. // We only need the database name of the course.
$courses[$row['k']] = array('db' => $row['db'], 'code' => $row['k'], 'visual_code' => $row['vc'], 'title' => $row['i'], 'directory' => $row['dir'], 'status' => $row['status'], 'tutor' => $row['t'], 'subscribe' => $row['subscr'], 'unsubscribe' => $row['unsubscr'], 'sort' => $row['sort'], 'user_course_category' => $row['user_course_cat']); $courses[$row['k']] = array(
} 'db' => $row['db'],
return $courses; 'code' => $row['k'],
} 'visual_code' => $row['vc'],
'title' => $row['i'],
'directory' => $row['dir'],
'status' => $row['status'],
'tutor' => $row['t'],
'subscribe' => $row['subscr'],
'unsubscribe' => $row['unsubscr'],
'sort' => $row['sort'],
'user_course_category' => $row['user_course_cat']
);
}
return $courses;
}
} }
$app->get('/', 'UserPortalController::indexAction'); $app->get('/', 'UserPortalController::indexAction');
$app->run(); $app->run();
//$app['http_cache']->run(); //$app['http_cache']->run();
Loading…
Cancel
Save