Forráskód Böngészése

Feature #306 - Cleaning the top-directory php source files.

Ivan Tcholakov 15 éve
szülő
commit
9f7498f692
6 módosított fájl, 466 hozzáadás és 501 törlés
  1. 185 180
      index.php
  2. 6 17
      newsList.php
  3. 117 128
      user_portal.php
  4. 6 7
      webchatdeny.php
  5. 112 120
      whoisonline.php
  6. 40 49
      whoisonlinesession.php

+ 185 - 180
index.php

@@ -25,23 +25,22 @@
 */
 
 /**
-*	@package dokeos.main
-* 	@author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Refactoring
-* 	@version $Id: index.php 22368 2009-07-24 23:25:57Z iflorespaz $
-*   @todo check the different @todos in this page and really do them
-* 	@todo check if the news management works as expected
-*/
-
+ *	@package dokeos.main
+ *	@author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Refactoring
+ *	@version $Id: index.php 22368 2009-07-24 23:25:57Z iflorespaz $
+ *	@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? */
+/** @todo Couldn't this be done using the $HtmlHeadXtra array? */
 define('DOKEOS_HOMEPAGE', true);
 
 // the language file
 $language_file = array ('courses', 'index');
 
-/* Flag forcing the 'current course' reset, as we're not inside a course anymore  */
+/* 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;
 
@@ -51,35 +50,40 @@ $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');
-include_once (api_get_path(LIBRARY_PATH).'course.lib.php');
-include_once (api_get_path(LIBRARY_PATH).'debug.lib.inc.php');
-include_once (api_get_path(LIBRARY_PATH).'events.lib.inc.php');
-include_once (api_get_path(LIBRARY_PATH).'system_announcements.lib.php');
-include_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
-include_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
+require_once 'main/inc/global.inc.php';
+include_once api_get_path(LIBRARY_PATH).'course.lib.php';
+include_once api_get_path(LIBRARY_PATH).'debug.lib.inc.php';
+include_once api_get_path(LIBRARY_PATH).'events.lib.inc.php';
+include_once api_get_path(LIBRARY_PATH).'system_announcements.lib.php';
+include_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
+include_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.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') ? true : false;
+$setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
 
 // the section (for the tabs)
 $this_section = SECTION_CAMPUS;
+
 /*
 -----------------------------------------------------------
 	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?
+
+/** @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();
+$my_user_id = api_get_user_id();
 
 if (!empty($_GET['logout'])) {
 	logout();
 }
+
 /*
 -----------------------------------------------------------
 	Table definitions
@@ -103,12 +107,12 @@ if (isset($_user['user_id'])) {
 	$nameTools = api_get_setting('siteName');
 }
 
-
 /*
 ==============================================================================
 		LOGIN
 ==============================================================================
 */
+
 /**
  * @todo This piece of code should probably move to local.inc.php where the actual login / logout procedure is handled.
  * @todo consider removing this piece of code because does nothing.
@@ -119,11 +123,13 @@ if (isset($_GET['submitAuth']) && $_GET['submitAuth'] == 1) {
 	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']);
 }
+
 /**
  * @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
@@ -131,31 +137,32 @@ if (api_get_setting('allow_terms_conditions')=='true') {
  * 		 on api_get_setting('page_after_login')
  */
 
-if (!empty($_POST["submitAuth"])) {
+if (!empty($_POST['submitAuth'])) {
 	// the user is already authenticated, we now find the last login of the user.
 	if (isset ($_user['user_id'])) {
 		$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 = api_sql_query($sql_last_login, __FILE__, __LINE__);
-		if (!$result_last_login)
+		$result_last_login = Database::query($sql_last_login, __FILE__, __LINE__);
+		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');
 			}
+		}
 		mysql_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");
+			include api_get_path(LIBRARY_PATH).'stats.lib.inc.php';
 			decodeOpenInfos();
 		}
 	}
 
-} // end login -- if($_POST["submitAuth"])
+} // 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.
 
@@ -170,6 +177,7 @@ Display :: display_header('', 'dokeos');
 		MAIN CODE
 ==============================================================================
 */
+
 echo '<div class="maincontent" id="content">';
 
 // Plugins for loginpage_main AND campushomepage_main
@@ -179,17 +187,17 @@ if (!api_get_user_id()) {
 	api_plugin('campushomepage_main');
 }
 
-$home= 'home/';
-if ($_configuration['multiple_access_urls']==true) {
+$home = 'home/';
+if ($_configuration['multiple_access_urls']) {
 	$access_url_id = api_get_current_access_url_id();
 	if ($access_url_id != -1){
 		$url_info = api_get_access_url($access_url_id);
 		// "http://" and the final "/" replaced
-		$url = substr($url_info['url'],7,strlen($url_info['url'])-8);
+		$url = substr($url_info['url'], 7, strlen($url_info['url']) - 8);
 		$clean_url = replace_dangerous_char($url);
-		$clean_url = str_replace('/','-',$clean_url);
+		$clean_url = str_replace('/', '-', $clean_url);
 		$clean_url = $clean_url.'/';
-		$home_old  = 'home/';
+		$home_old = 'home/';
 		$home= 'home/'.$clean_url;
 	}
 }
@@ -197,35 +205,35 @@ if ($_configuration['multiple_access_urls']==true) {
 // Including the page for the news
 $page_included = false;
 
-if (!empty ($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/',$_GET['include'])) {
-	include ('./'.$home.$_GET['include']);
+if (!empty($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/', $_GET['include'])) {
+	include './'.$home.$_GET['include'];
 	$page_included = true;
 } else {
 
 	if (!empty($_SESSION['user_language_choice'])) {
-		$user_selected_language=$_SESSION['user_language_choice'];
-	} elseif(!empty($_SESSION['_user']['language'])) {
-		$user_selected_language=$_SESSION['_user']['language'];
+		$user_selected_language = $_SESSION['user_language_choice'];
+	} elseif (!empty($_SESSION['_user']['language'])) {
+		$user_selected_language = $_SESSION['_user']['language'];
 	} else {
-		$user_selected_language=api_get_setting('platformLanguage');
+		$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');
-		else {
-			$home_top_temp=file($home_old.'home_top.html');
+	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');
+		} else {
+			$home_top_temp = file($home_old.'home_top.html');
 		}
-		$home_top_temp=implode('',$home_top_temp);
-		$open=str_replace('{rel_path}',api_get_path(REL_PATH),$home_top_temp);
+		$home_top_temp = implode('', $home_top_temp);
+		$open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
 		echo $open;
 	} else {
-		if(file_exists($home.'home_top_'.$user_selected_language.'.html')) {
+		if (file_exists($home.'home_top_'.$user_selected_language.'.html')) {
 			$home_top_temp = file_get_contents($home.'home_top_'.$user_selected_language.'.html');
 		} else {
 			$home_top_temp = file_get_contents($home.'home_top.html');
 		}
-		$open=str_replace('{rel_path}',api_get_path(REL_PATH),$home_top_temp);
+		$open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
 		echo $open;
 	}
 }
@@ -272,10 +280,10 @@ function logout()
 {
 	global $_configuration, $extAuthSource;
 	// variable initialisation
-	$query_string='';
+	$query_string = '';
 
 	if (!empty($_SESSION['user_language_choice'])) {
-		$query_string='?language='.$_SESSION['user_language_choice'];
+		$query_string = '?language='.$_SESSION['user_language_choice'];
 	}
 
 	// Database table definition
@@ -283,16 +291,16 @@ function logout()
 
 	// selecting the last login of the user
 	$uid = intval($_GET['uid']);
-	$sql_last_connection="SELECT login_id, login_date FROM $tbl_track_login WHERE login_user_id='$uid' ORDER BY login_date DESC LIMIT 0,1";
-	$q_last_connection=api_sql_query($sql_last_connection);
-	if (Database::num_rows($q_last_connection)>0) {
-		$i_id_last_connection=Database::result($q_last_connection,0,"login_id");
+	$sql_last_connection = "SELECT login_id, login_date FROM $tbl_track_login WHERE login_user_id='$uid' ORDER BY login_date DESC LIMIT 0,1";
+	$q_last_connection = Database::query($sql_last_connection, __FILE__, __LINE__);
+	if (Database::num_rows($q_last_connection) > 0) {
+		$i_id_last_connection = Database::result($q_last_connection, 0, 'login_id');
 	}
 
 	if (!isset($_SESSION['login_as'])) {
-		$current_date=date('Y-m-d H:i:s',time());
-		$s_sql_update_logout_date="UPDATE $tbl_track_login SET logout_date='".$current_date."' WHERE login_id='$i_id_last_connection'";
-		api_sql_query($s_sql_update_logout_date);
+		$current_date = date('Y-m-d H:i:s', time());
+		$s_sql_update_logout_date = "UPDATE $tbl_track_login SET logout_date='".$current_date."' WHERE login_id='$i_id_last_connection'";
+		Database::query($s_sql_update_logout_date, __FILE__, __LINE__);
 	}
 	LoginDelete($uid, $_configuration['statistics_database']); //from inc/lib/online.inc.php - removes the "online" status
 
@@ -306,7 +314,7 @@ function logout()
 		if (is_array($extAuthSource[$uinfo['auth_source']])) {
 			$subarray = $extAuthSource[$uinfo['auth_source']];
 			if (!empty($subarray['logout']) && file_exists($subarray['logout'])) {
-				include_once($subarray['logout']);
+				include_once ($subarray['logout']);
 				$logout_function = $uinfo['auth_source'].'_logout';
 				if (function_exists($logout_function)) {
 					$logout_function($uinfo);
@@ -329,19 +337,19 @@ function logout()
 function category_has_open_courses($category) {
 	global $setting_show_also_closed_courses;
 
-	$user_identified = (api_get_user_id()>0 && !api_is_anonymous());
+	$user_identified = (api_get_user_id() > 0 && !api_is_anonymous());
 	$main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
 	$sql_query = "SELECT * FROM $main_course_table WHERE category_code='$category'";
-	$sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
+	$sql_result = Database::query($sql_query, __FILE__, __LINE__);
 	while ($course = Database::fetch_array($sql_result)) {
-		if ($setting_show_also_closed_courses == false) {
-			if ((api_get_user_id()>0
-				and $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
-				or ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
+		if (!$setting_show_also_closed_courses) {
+			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
 			}
-		} else  {
-			if(isset($course['visibility'])){
+		} else {
+			if (isset($course['visibility'])){
 				return true; //at least one course (does not matter weither it's open or not because $setting_show_also_closed_courses = true
 			}
 		}
@@ -369,7 +377,7 @@ function display_anonymous_right_menu() {
 
 	$platformLanguage = api_get_setting('platformLanguage');
 
-	if ( !($_user['user_id']) or api_is_anonymous($_user['user_id']) ) {  // only display if the user isn't logged in
+	if (!($_user['user_id']) || api_is_anonymous($_user['user_id']) ) { // only display if the user isn't logged in
 		api_display_language_form(true);
 		echo '<br />';
 		display_login_form();
@@ -378,7 +386,7 @@ function display_anonymous_right_menu() {
 			echo '<br />';
 			handle_login_failed();
 		}
-		if (api_get_setting('allow_lostpassword') == 'true' OR api_get_setting('allow_registration') == 'true') {
+		if (api_get_setting('allow_lostpassword') == 'true' || api_get_setting('allow_registration') == 'true') {
 			echo '<div class="menusection"><span class="menusectioncaption">'.get_lang('MenuUser').'</span><ul class="menulist">';
 			if (api_get_setting('allow_registration') <> 'false') {
 				echo '<li><a href="main/auth/inscription.php">'.get_lang('Reg').'</a></li>';
@@ -397,29 +405,28 @@ function display_anonymous_right_menu() {
 
 
 	// My Account section
-	if (isset($_SESSION['_user']['user_id']) && $_SESSION['_user']['user_id']!=0) {
+	if (isset($_SESSION['_user']['user_id']) && $_SESSION['_user']['user_id'] != 0) {
 		// tabs that are deactivated are added here
 
-
-		$show_menu=false;
-		$show_create_link=false;
-		$show_course_link=false;
+		$show_menu = false;
+		$show_create_link = false;
+		$show_course_link = false;
 
 		$display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION["studentview"] != "studentenview");
 
 		if ($display_add_course_link) {
 			//display_create_course_link();
-			$show_menu=true;
-			$show_create_link=true;
+			$show_menu = true;
+			$show_create_link = true;
 		}
 
 		if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
-				$show_menu=true;
-				$show_course_link=true;
+				$show_menu = true;
+				$show_course_link = true;
 		} else {
-			if (api_get_setting('allow_students_to_browse_courses')=='true') {
-				$show_menu=true;
-				$show_course_link=true;
+			if (api_get_setting('allow_students_to_browse_courses') == 'true') {
+				$show_menu = true;
+				$show_course_link = true;
 			}
 		}
 
@@ -427,10 +434,12 @@ function display_anonymous_right_menu() {
 			echo "<div class=\"menusection\">";
 			echo "<span class=\"menusectioncaption\">".get_lang("MenuUser")."</span>";
 			echo "<ul class=\"menulist\">";
-			if ($show_create_link)
+			if ($show_create_link) {
 				display_create_course_link();
-			if ($show_course_link)
+			}
+			if ($show_course_link) {
 				display_edit_course_list_links();
+			}
 			echo "</ul>";
 			echo "</div>";
 		}
@@ -439,8 +448,8 @@ function display_anonymous_right_menu() {
 			echo "<div class=\"menusection\">";
 			echo "<span class=\"menusectioncaption\">".get_lang("MainNavigation")."</span>";
 			echo "<ul class=\"menulist\">";
-			foreach($menu_navigation as $section => $navigation_info) {
-				$current = ($section == $GLOBALS['this_section'] ? ' id="current"' : '');
+			foreach ($menu_navigation as $section => $navigation_info) {
+				$current = $section == $GLOBALS['this_section'] ? ' id="current"' : '';
 				echo '<li'.$current.'>';
 				echo '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
 				echo '</li>';
@@ -452,33 +461,29 @@ function display_anonymous_right_menu() {
 	}
 
 	// help section
-	/*** hide right menu "general" and other parts on anonymous right menu  *****/
+	/*** hide right menu "general" and other parts on anonymous right menu *****/
 
 	$user_selected_language = api_get_interface_language();
 	global $home, $home_old;
-	if (!isset ($user_selected_language))
-	{
+	if (!isset($user_selected_language)) {
 		$user_selected_language = $platformLanguage;
 	}
 
-	if (!file_exists($home.'home_menu_'.$user_selected_language.'.html') && file_exists($home.'home_menu.html') && file_get_contents($home.'home_menu.html')!='')
-	{
+	if (!file_exists($home.'home_menu_'.$user_selected_language.'.html') && file_exists($home.'home_menu.html') && file_get_contents($home.'home_menu.html') != '') {
 		echo "<div class=\"menusection\">", "<span class=\"menusectioncaption\">".get_lang("MenuGeneral")."</span>";
 	 	echo "<ul class=\"menulist\">";
-		if (file_exists($home.'home_menu.html'))
+		if (file_exists($home.'home_menu.html')) {
 			include ($home.'home_menu.html');
-		else {
+		} else {
 			include ($home_old.'home_menu.html');
 		}
 		echo '</ul>';
 		echo '</div>';
 	}
-
-	elseif(file_exists($home.'home_menu_'.$user_selected_language.'.html') && file_get_contents($home.'home_menu_'.$user_selected_language.'.html')!='')
-	{
+	elseif(file_exists($home.'home_menu_'.$user_selected_language.'.html') && file_get_contents($home.'home_menu_'.$user_selected_language.'.html') != '') {
 		echo "<div class=\"menusection\">", "<span class=\"menusectioncaption\">".get_lang("MenuGeneral")."</span>";
 	 	echo "<ul class=\"menulist\">";
-		include($home.'home_menu_'.$user_selected_language.'.html');
+		include ($home.'home_menu_'.$user_selected_language.'.html');
 		echo '</ul>';
 		echo '</div>';
 	}
@@ -491,15 +496,16 @@ function display_anonymous_right_menu() {
 
 	// includes for any files to be displayed below anonymous right menu
 
-	if (!file_exists($home.'home_notice_'.$user_selected_language.'.html') && file_exists($home.'home_notice.html') && file_get_contents($home.'home_notice.html')!='') {
+	if (!file_exists($home.'home_notice_'.$user_selected_language.'.html') && file_exists($home.'home_notice.html') && file_get_contents($home.'home_notice.html') != '') {
 		echo '<div class="note">';
-		if (file_exists($home.'home_notice.html'))
+		if (file_exists($home.'home_notice.html')) {
 			include ($home.'home_notice.html');
-		else {
+		} else {
 			include ($home_old.'home_notice.html');
 		}
 		echo '</div>';
-	} elseif(file_exists($home.'home_notice_'.$user_selected_language.'.html') && file_get_contents($home.'home_notice_'.$user_selected_language.'.html')!='') {
+	}
+	elseif(file_exists($home.'home_notice_'.$user_selected_language.'.html') && file_get_contents($home.'home_notice_'.$user_selected_language.'.html') != '') {
 		echo '<div class="note">';
 		include($home.'home_notice_'.$user_selected_language.'.html');
 		echo '</div>';
@@ -528,16 +534,16 @@ function handle_login_failed() {
 				}
 				break;
 			case 'account_expired':
-				$message=get_lang('AccountExpired');
+				$message = get_lang('AccountExpired');
 				break;
 			case 'account_inactive':
-				$message=get_lang('AccountInactive');
+				$message = get_lang('AccountInactive');
 				break;
 			case 'user_password_incorrect':
-				$message=get_lang('InvalidId');
+				$message = get_lang('InvalidId');
 				break;
 			case 'access_url_inactive':
-				$message=get_lang('AccountURLInactive');
+				$message = get_lang('AccountURLInactive');
 				break;
 		}
 	}
@@ -548,20 +554,20 @@ function handle_login_failed() {
 *	Adds a form to let users login
 *	@version 1.1
 */
-function display_login_form()
-{
+function display_login_form() {
 	$form = new FormValidator('formLogin');
-	$form->addElement('text','login',get_lang('UserName'),array('size'=>17));
-	$form->addElement('password','password',get_lang('Pass'),array('size'=>17));
-	$form->addElement('style_submit_button','submitAuth',get_lang('langEnter'), array('class'=>'login'));
+	$form->addElement('text', 'login', get_lang('UserName'), array('size' => 17));
+	$form->addElement('password', 'password', get_lang('Pass'), array('size' => 17));
+	$form->addElement('style_submit_button','submitAuth', get_lang('langEnter'), array('class' => 'login'));
 	$renderer =& $form->defaultRenderer();
 	$renderer->setElementTemplate('<div><label>{label}</label></div><div>{element}</div>');
 	$form->display();
-	if (api_get_setting('openid_authentication')=='true') {
-		include_once('main/auth/openid/login.php');
+	if (api_get_setting('openid_authentication') == 'true') {
+		include_once 'main/auth/openid/login.php';
 		echo '<div>'.openid_form().'</div>';
 	}
 }
+
 /**
  * Displays a link to the lost password section
  */
@@ -581,7 +587,7 @@ function display_anonymous_course_list() {
 	$stok = Security::get_token();
 
 	//init
-	$user_identified = (api_get_user_id()>0 && !api_is_anonymous());
+	$user_identified = (api_get_user_id() > 0 && !api_is_anonymous());
 	$web_course_path = api_get_path(WEB_COURSE_PATH);
 	$category = Database::escape_string($_GET['category']);
 	global $setting_show_also_closed_courses;
@@ -599,18 +605,18 @@ function display_anonymous_course_list() {
 
 	//showing only the courses of the current access_url_id
 	global $_configuration;
-	if ($_configuration['multiple_access_urls']==true) {
+	if ($_configuration['multiple_access_urls'] == true) {
 		$url_access_id = api_get_current_access_url_id();
 		if ($url_access_id !=-1) {
 			$tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
-			$sql_get_course_list="SELECT * FROM $main_course_table as course INNER JOIN $tbl_url_rel_course as url_rel_course
+			$sql_get_course_list = "SELECT * FROM $main_course_table as course INNER JOIN $tbl_url_rel_course as url_rel_course
 					ON (url_rel_course.course_code=course.code)
 					WHERE access_url_id = $url_access_id AND category_code = '".Database::escape_string($_GET["category"])."' ORDER BY title, UPPER(visual_code)";
 		}
 	}
 
 	//removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."'
-	$sql_result_courses = api_sql_query($sql_get_course_list, __FILE__, __LINE__);
+	$sql_result_courses = Database::query($sql_get_course_list, __FILE__, __LINE__);
 
 	while ($course_result = Database::fetch_array($sql_result_courses)) {
 		$course_list[] = $course_result;
@@ -621,13 +627,13 @@ function display_anonymous_course_list() {
 	if($user_identified) {
 		if ($setting_show_also_closed_courses) {
 			$platform_visible_courses = '';
-		} else  {
+		} else {
 			$platform_visible_courses = "  AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' OR t3.visibility='".COURSE_VISIBILITY_OPEN_PLATFORM."' )";
 		}
 	} else {
 		if ($setting_show_also_closed_courses) {
 			$platform_visible_courses = '';
-		} else  {
+		} else {
 			$platform_visible_courses = "  AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' )";
 		}
 	}
@@ -642,9 +648,9 @@ function display_anonymous_course_list() {
 
 	//showing only the category of courses of the current access_url_id
 	global $_configuration;
-	if ($_configuration['multiple_access_urls']==true) {
+	if ($_configuration['multiple_access_urls'] == true) {
 		$url_access_id = api_get_current_access_url_id();
-		if ($url_access_id !=-1) {
+		if ($url_access_id != -1) {
 			$tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
 			$sqlGetSubCatList = "
 				SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
@@ -653,12 +659,12 @@ function display_anonymous_course_list() {
 				LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code $platform_visible_courses)
 				INNER JOIN $tbl_url_rel_course as url_rel_course
 					ON (url_rel_course.course_code=t3.code)
-				WHERE access_url_id = $url_access_id AND t1.parent_id ". (empty ($category) ? "IS NULL" : "='$category'")."
+				WHERE access_url_id = $url_access_id AND t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")."
 				GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
 		}
 	}
 
-	$resCats = api_sql_query($sqlGetSubCatList, __FILE__, __LINE__);
+	$resCats = Database::query($sqlGetSubCatList, __FILE__, __LINE__);
 	$thereIsSubCat = false;
 	if (Database::num_rows($resCats) > 0) {
 		$htmlListCat = "<h4 style=\"margin-top: 0px;\">".get_lang("CatList")."</h4>"."<ul>";
@@ -690,14 +696,14 @@ function display_anonymous_course_list() {
 					$htmlListCat .= $catLine['name'];
 					$htmlListCat .= "</li>\n";
 					$thereIsSubCat = true;
-				}//else don't set thereIsSubCat to true to avoid printing things if not requested
+				} //else don't set thereIsSubCat to true to avoid printing things if not requested
 			} else {
 				$htmlTitre = "<p>";
 				if (api_get_setting('show_back_link_on_top_of_tree') == 'true') {
 					$htmlTitre .= "<a href=\"".api_get_self()."\">"."&lt;&lt; ".get_lang("BackToHomePage")."</a>";
 				}
 				if (!is_null($catLine['parent_id']) || (api_get_setting('show_back_link_on_top_of_tree') <> 'true' && !is_null($catLine['code']))) {
-					$htmlTitre .= "<a href=\"".api_get_self()."?category=".$catLine['parent_id']."\">"."&lt;&lt; ".get_lang("Up")."</a>";
+					$htmlTitre .= "<a href=\"".api_get_self()."?category=".$catLine['parent_id']."\">"."&lt;&lt; ".get_lang('Up')."</a>";
 				}
 				$htmlTitre .= "</p>\n";
 				if ($category != "" && !is_null($catLine['code'])) {
@@ -729,27 +735,27 @@ function display_anonymous_course_list() {
 			$courses_of_user = get_courses_of_user(api_get_user_id());
 		}
 
-		foreach ($course_list AS $course) {
+		foreach ($course_list as $course) {
 			// $setting_show_also_closed_courses
 
-			if ($setting_show_also_closed_courses==false) {
+			if ($setting_show_also_closed_courses == false) {
 				// if we do not show the closed courses
 				// we only show the courses that are open to the world (to everybody)
 				// and the courses that are open to the platform (if the current user is a registered user
-				if( ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) OR ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
+				if( ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
 					$courses_shown++;
 					$courses_list_string .= "<li>\n";
 				$courses_list_string .= "<a href=\"".$web_course_path.$course['directory']."/\">".$course['title']."</a><br />";
-				if (api_get_setting("display_coursecode_in_courselist") == "true") {
+				if (api_get_setting('display_coursecode_in_courselist') == 'true') {
 					$courses_list_string .= $course['visual_code'];
 				}
-				if (api_get_setting("display_coursecode_in_courselist") == "true" AND api_get_setting("display_teacher_in_courselist") == "true") {
-					$courses_list_string .= " - ";
+				if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') {
+					$courses_list_string .= ' - ';
 				}
-				if (api_get_setting("display_teacher_in_courselist") == "true") {
+				if (api_get_setting('display_teacher_in_courselist') == 'true') {
 					$courses_list_string .= $course['tutor_name'];
 				}
-					if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] <> api_get_setting('platformLanguage')) {
+					if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
 						$courses_list_string .= ' - '.$course['course_language'];
 					}
 					$courses_list_string .= "</li>\n";
@@ -766,50 +772,49 @@ function display_anonymous_course_list() {
 			else {
 				$courses_shown++;
 				$courses_list_string .= "<li>\n";
-					if ( $course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
-							OR ($user_identified AND $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
-							OR ($user_identified AND key_exists($course['code'],$courses_of_user) AND $course['visibility'] <> COURSE_VISIBILITY_CLOSED)
-							OR $courses_of_user[$course['code']]['status'] == '1'
-							OR api_is_platform_admin()) {
-						$courses_list_string .= "<a href=\"".$web_course_path.$course['directory']."/\">";
-					}
-					$courses_list_string .= $course['title'];
-					if ( $course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
-							OR ($user_identified AND $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
-							OR ($user_identified AND key_exists($course['code'],$courses_of_user) AND $course['visibility'] <> COURSE_VISIBILITY_CLOSED)
-							OR $courses_of_user[$course['code']]['status'] == '1'
-							OR api_is_platform_admin()) {
-						$courses_list_string .="</a><br />";
-					}
-					if (api_get_setting("display_coursecode_in_courselist") == "true") {
-						$courses_list_string .= $course['visual_code'];
-					}
-					if (api_get_setting("display_coursecode_in_courselist") == "true" AND api_get_setting("display_teacher_in_courselist") == "true") {
-						$courses_list_string .= " - ";
-					}
-					if (api_get_setting("display_teacher_in_courselist") == "true")
-					{
-						$courses_list_string .= $course['tutor_name'];
-					}
-				if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] <> api_get_setting('platformLanguage')) {
+				if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
+						|| ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
+						|| ($user_identified && key_exists($course['code'], $courses_of_user) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
+						|| $courses_of_user[$course['code']]['status'] == '1'
+						|| api_is_platform_admin()) {
+					$courses_list_string .= "<a href=\"".$web_course_path.$course['directory']."/\">";
+				}
+				$courses_list_string .= $course['title'];
+				if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
+						|| ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
+						|| ($user_identified && key_exists($course['code'], $courses_of_user) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
+						|| $courses_of_user[$course['code']]['status'] == '1'
+						|| api_is_platform_admin()) {
+					$courses_list_string .= "</a><br />";
+				}
+				if (api_get_setting('display_coursecode_in_courselist') == 'true') {
+					$courses_list_string .= $course['visual_code'];
+				}
+				if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') {
+					$courses_list_string .= ' - ';
+				}
+				if (api_get_setting('display_teacher_in_courselist') == 'true') {
+					$courses_list_string .= $course['tutor_name'];
+				}
+				if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
 					$courses_list_string .= ' - '.$course['course_language'];
 				}
-					if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] <> api_get_setting('platformLanguage')) {
-						$courses_list_string .= ' - '.$course['course_language'];
-					}
-					// We display a subscription link if
-					// 1. it is allowed to register for the course and if the course is not already in the courselist of the user and if the user is identiefied
-					// 2
-					if ($user_identified AND !key_exists($course['code'],$courses_of_user)) {
-						if ($course['subscribe'] == '1') {
-							$courses_list_string .= "<form action=\"main/auth/courses.php?action=subscribe&category=".$_GET['category']."\" method=\"post\">";
-							$courses_list_string .= '<input type="hidden" name="sec_token" value="'.$stok.'">';
-							$courses_list_string .= "<input type=\"hidden\" name=\"subscribe\" value=\"".$course['code']."\" />";
-							$courses_list_string .= "<input type=\"image\" name=\"unsub\" src=\"main/img/enroll.gif\" alt=\"".get_lang("Subscribe")."\" />".get_lang("Subscribe")."</form>";
-						} else {
-							$courses_list_string .= '<br />'.get_lang("SubscribingNotAllowed");
-						}
+				if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
+					$courses_list_string .= ' - '.$course['course_language'];
+				}
+				// We display a subscription link if
+				// 1. it is allowed to register for the course and if the course is not already in the courselist of the user and if the user is identiefied
+				// 2
+				if ($user_identified && !key_exists($course['code'], $courses_of_user)) {
+					if ($course['subscribe'] == '1') {
+						$courses_list_string .= "<form action=\"main/auth/courses.php?action=subscribe&category=".$_GET['category']."\" method=\"post\">";
+						$courses_list_string .= '<input type="hidden" name="sec_token" value="'.$stok.'">';
+						$courses_list_string .= "<input type=\"hidden\" name=\"subscribe\" value=\"".$course['code']."\" />";
+						$courses_list_string .= "<input type=\"image\" name=\"unsub\" src=\"main/img/enroll.gif\" alt=\"".get_lang("Subscribe")."\" />".get_lang("Subscribe")."</form>";
+					} else {
+						$courses_list_string .= '<br />'.get_lang("SubscribingNotAllowed");
 					}
+				}
 				$courses_list_string .= "</li>\n";
 			}
 		}
@@ -818,11 +823,11 @@ function display_anonymous_course_list() {
 		// echo "<blockquote>",get_lang('_No_course_publicly_available'),"</blockquote>\n";
 	}
 	if ($courses_shown > 0) { //only display the list of courses and categories if there was more than
-	  // 0 courses visible to the world (we're in the anonymous list here)
+		// 0 courses visible to the world (we're in the anonymous list here)
 		echo $courses_list_string;
 	}
-	if ($category != "") {
-		echo "<p>", "<a href=\"".api_get_self()."\"><b></b> ", Display :: return_icon('back.png', get_lang('BackToHomePage')),get_lang("BackToHomePage"), "</a>", "</p>\n";
+	if ($category != '') {
+		echo "<p>", "<a href=\"".api_get_self()."\"> ", Display :: return_icon('back.png', get_lang('BackToHomePage')), get_lang("BackToHomePage"), "</a>", "</p>\n";
 	}
 }
 
@@ -836,20 +841,20 @@ 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);
 
-	// Secondly we select the courses that are in a category (user_course_cat<>0) and sort these according to the sort of the category
+	// Secondly we select the courses that are in a category (user_course_cat <> 0) and sort these according to the sort of the category
 	$user_id = intval($user_id);
-	$sql_select_courses="SELECT course.code k, course.visual_code  vc, course.subscribe subscr, course.unsubscribe unsubscr,
+	$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_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat
-		                        FROM    $table_course       course,
+								FROM    $table_course       course,
 										$table_course_user  course_rel_user
-		                        WHERE course.code = course_rel_user.course_code
-		                        AND   course_rel_user.user_id = '".$user_id."'
-		                        ORDER BY course_rel_user.sort ASC";
-	$result = api_sql_query($sql_select_courses,__FILE__,__LINE__);
-	while ($row=Database::fetch_array($result)) {
+								WHERE course.code = course_rel_user.course_code
+								AND   course_rel_user.user_id = '".$user_id."'
+								ORDER BY course_rel_user.sort ASC";
+	$result = Database::query($sql_select_courses, __FILE__, __LINE__);
+	while ($row = Database::fetch_array($result)) {
 		// 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'], '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;
 }

+ 6 - 17
newsList.php

@@ -4,34 +4,23 @@
  * Created on 30 mai 2006 by Elixir Interactive http://www.elixir-interactive.com
  */
 
-
 // name of the language file that needs to be included
 $language_file = array ('courses', 'index');
 
 // including necessary files
-include_once('main/inc/global.inc.php');
-include_once (api_get_path(LIBRARY_PATH).'/system_announcements.lib.php');
+include_once 'main/inc/global.inc.php';
+include_once api_get_path(LIBRARY_PATH).'system_announcements.lib.php';
 
 $tool_name = get_lang("SystemAnnouncements");
 Display::display_header($tool_name);
 
-if(isset($_GET['start']))
-{
-	$start = (int)$_GET['start'];
-}
-else
-{
-	$start = 0;
-}
+$start = isset($_GET['start']) ? (int)$_GET['start'] : $start = 0;
 
-if (isset($_user['user_id']))
-{
+if (isset($_user['user_id'])) {
 	$visibility = api_is_allowed_to_create_course() ? VISIBLE_TEACHER : VISIBLE_STUDENT;
 	SystemAnnouncementManager :: display_all_announcements($visibility, $announcement, $start, $_user['user_id']);
-}
-else
-{
+} else {
 	SystemAnnouncementManager :: display_all_announcements(VISIBLE_GUEST, $announcement, $start);
 }
+
 Display::display_footer();
-?>

+ 117 - 128
user_portal.php

@@ -31,7 +31,7 @@
 
 /*
 ==============================================================================
-	   INIT SECTION
+		INIT SECTION
 ==============================================================================
 */
 // Don't change these settings
@@ -44,23 +44,22 @@ define('SCRIPTVAL_NewEntriesOfTheDayOfLastLogin', 5);
 define('SCRIPTVAL_NoTimeLimit', 6);
 // End 'don't change' section
 
-
-// name of the language file that needs to be included
+// Language files that should be included
 $language_file = array ('courses', 'index');
 
 $cidReset = true; /* Flag forcing the 'current course' reset,
-                   as we're not inside a course anymore  */
+					as we're not inside a course anymore  */
 /*
 -----------------------------------------------------------
 	Included libraries
 -----------------------------------------------------------
 */
-include_once ('./main/inc/global.inc.php');
-include_once (api_get_path(LIBRARY_PATH).'course.lib.php');
-include_once (api_get_path(LIBRARY_PATH).'debug.lib.inc.php');
-include_once (api_get_path(LIBRARY_PATH).'system_announcements.lib.php');
-include_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
-include_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php');
+include_once './main/inc/global.inc.php';
+include_once api_get_path(LIBRARY_PATH).'course.lib.php';
+include_once api_get_path(LIBRARY_PATH).'debug.lib.inc.php';
+include_once api_get_path(LIBRARY_PATH).'system_announcements.lib.php';
+include_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
+include_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
 
 api_block_anonymous_users(); // only users who are logged in can proceed
 
@@ -82,13 +81,13 @@ $main_category_table 	= Database :: get_main_table(TABLE_MAIN_CATEGORY);
 -----------------------------------------------------------
 */
 // ---- Course list options ----
-define('CONFVAL_showCourseLangIfNotSameThatPlatform', TRUE);
+define('CONFVAL_showCourseLangIfNotSameThatPlatform', true);
 // Preview of course content
 // to disable all: set CONFVAL_maxTotalByCourse = 0
 // to enable all: set e.g. CONFVAL_maxTotalByCourse = 5
 // by default disabled since what's new icons are better (see function display_digest() )
 define('CONFVAL_maxValvasByCourse', 2); // Maximum number of entries
-define('CONFVAL_maxAgendaByCourse', 2); //  collected from each course
+define('CONFVAL_maxAgendaByCourse', 2); // collected from each course
 define('CONFVAL_maxTotalByCourse', 0); //  and displayed in summary.
 define('CONFVAL_NB_CHAR_FROM_CONTENT', 80);
 // Order to sort data
@@ -97,8 +96,8 @@ $orderKey = array('keyTools', 'keyTime', 'keyCourse'); // default "best" Choice
 //$orderKey = array('keyCourse', 'keyTime', 'keyTools');
 //$orderKey = array('keyCourse', 'keyTools', 'keyTime');
 define('CONFVAL_showExtractInfo', SCRIPTVAL_UnderCourseList);
-// SCRIPTVAL_InCourseList    // best choice if $orderKey[0] == 'keyCourse'
-// SCRIPTVAL_UnderCourseList // best choice
+// SCRIPTVAL_InCourseList		// best choice if $orderKey[0] == 'keyCourse'
+// SCRIPTVAL_UnderCourseList	// best choice
 // SCRIPTVAL_Both // probably only for debug
 //define('CONFVAL_dateFormatForInfosFromCourses', get_lang('dateFormatShort'));
 define('CONFVAL_dateFormatForInfosFromCourses', get_lang('dateFormatLong'));
@@ -109,20 +108,16 @@ define("CONFVAL_limitPreviewTo", SCRIPTVAL_NewEntriesOfTheDayOfLastLogin);
 
 /*if(api_is_allowed_to_create_course() && !isset($_GET['sessionview'])){
 	$nosession = true;
-}
-else {
+} else {
 	$nosession = false;
 }*/
 
-$nosession=false;
+$nosession = false;
 
-if(api_get_setting('use_session_mode')=='true' && !$nosession) {
-	if (isset($_GET['inactives'])){
-		$display_actives = false;
-	} else {
-		$display_actives = true;
-	}
+if (api_get_setting('use_session_mode') == 'true' && !$nosession) {
+	$display_actives = !isset($_GET['inactives']);
 }
+
 $nameTools = get_lang('MyCourses');
 $this_section = SECTION_COURSES;
 
@@ -226,7 +221,7 @@ function get_personal_course_list($user_id) {
 
 	$personal_course_list_sql = "SELECT DISTINCT course.code k, course.directory d, course.visual_code c, course.db_name db, course.title i, course.tutor_name t, course.course_language l, 5 as s
 								FROM $main_course_table as course, $tbl_session_course_user as srcru
-							  	WHERE srcru.course_code=course.code AND srcru.id_user='$user_id'";
+								WHERE srcru.course_code=course.code AND srcru.id_user='$user_id'";
 
 	$course_list_sql_result = api_sql_query($personal_course_list_sql, __FILE__, __LINE__);
 
@@ -238,7 +233,7 @@ function get_personal_course_list($user_id) {
 
 	$personal_course_list_sql = "SELECT DISTINCT course.code k, course.directory d, course.visual_code c, course.db_name db, course.title i, course.tutor_name t, course.course_language l, 2 as s
 								FROM $main_course_table as course, $tbl_session_course as src, $tbl_session as session
-							  	WHERE session.id_coach='$user_id' AND session.id=src.id_session AND src.course_code=course.code";
+								WHERE session.id_coach='$user_id' AND session.id=src.id_session AND src.course_code=course.code";
 
 	$course_list_sql_result = api_sql_query($personal_course_list_sql, __FILE__, __LINE__);
 
@@ -251,12 +246,12 @@ function get_personal_course_list($user_id) {
 }
 
 
-
 /*
 -----------------------------------------------------------
 	Display functions
 -----------------------------------------------------------
 */
+
 /**
  * Warning: this function defines a global.
  * @todo use the correct get_path function
@@ -265,6 +260,7 @@ function display_admin_links() {
 	global $rootAdminWeb;
 	echo "<li><a href=\"".$rootAdminWeb."\">".get_lang('PlatformAdmin')."</a></li>";
 }
+
 /**
  * Enter description here...
  *
@@ -272,6 +268,7 @@ function display_admin_links() {
 function display_create_course_link() {
 	echo "<li><a href=\"main/create_course/add_course.php\">".get_lang('CourseCreate')."</a></li>";
 }
+
 /**
  * Enter description here...
  *
@@ -293,10 +290,10 @@ function display_digest($toolsList, $digest, $orderKey, $courses) {
 		// // // LEVEL 1 // // //
 		reset($digest);
 		echo "<br /><br />\n";
-		while (list ($key1) = each($digest)) {
+		while (list($key1) = each($digest)) {
 			if (is_array($digest[$key1])) {
 				// // // Title of LEVEL 1 // // //
-				echo "<b>\n";
+				echo "<strong>\n";
 				if ($orderKey[0] == 'keyTools') {
 					$tools = $key1;
 					echo $toolsList[$key1]['name'];
@@ -306,7 +303,7 @@ function display_digest($toolsList, $digest, $orderKey, $courses) {
 				} elseif ($orderKey[0] == 'keyTime') {
 					echo format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($digest[$key1]));
 				}
-				echo "</b>\n";
+				echo "</strong>\n";
 				// // // End Of Title of LEVEL 1 // // //
 				// // // LEVEL 2 // // //
 				reset($digest[$key1]);
@@ -361,8 +358,8 @@ function display_digest($toolsList, $digest, $orderKey, $courses) {
  * $my_course['d'] - course directory
  * $my_course['i'] - course title
  * $my_course['c'] - visual course code
- * $my_course['k']   - system course code
- * $my_course['db']  - course database
+ * $my_course['k']  - system course code
+ * $my_course['db'] - course database
  *
  * @version 1.0.3
  * @todo refactor into different functions for database calls | logic | display
@@ -428,56 +425,55 @@ function get_logged_user_course_html($my_course) {
 
 	$s_course_status=$my_course['s'];
 
-	$s_htlm_status_icon="";
+	$s_htlm_status_icon = '';
 
-	if ($s_course_status==1) {
+	if ($s_course_status == 1) {
 		$s_htlm_status_icon=Display::return_icon('teachers.gif', get_lang('Teacher'));
 	}
-	if ($s_course_status==2) {
+	if ($s_course_status == 2) {
 		$s_htlm_status_icon=Display::return_icon('coachs.gif', get_lang('GeneralCoach'));
 	}
-	if ($s_course_status==5) {
-		$s_htlm_status_icon=Display::return_icon('students.gif', get_lang('Student'));
+	if ($s_course_status == 5) {
+		$s_htlm_status_icon = Display::return_icon('students.gif', get_lang('Student'));
 	}
 
 	//display course entry
-	$result.="\n\t";
+	$result .= "\n\t";
 	$result .= '<li class="courses"><div class="coursestatusicons">'.$s_htlm_status_icon.'</div>';
 	//show a hyperlink to the course, unless the course is closed and user is not course admin
 	if ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) {
-		if(api_get_setting('use_session_mode')=='true' && !$nosession) {
-			if(empty($my_course['id_session'])) {
+		if (api_get_setting('use_session_mode') == 'true' && !$nosession) {
+			if (empty($my_course['id_session'])) {
 				$my_course['id_session'] = 0;
 			}
-			if($user_in_course_status == COURSEMANAGER || ($date_start <= $now && $date_end >= $now) || $date_start=='0000-00-00') {
+			if($user_in_course_status == COURSEMANAGER || ($date_start <= $now && $date_end >= $now) || $date_start == '0000-00-00') {
 				$result .= '<a href="'.api_get_path(WEB_COURSE_PATH).$course_directory.'/?id_session='.$my_course['id_session'].'">'.$course_display_title.'</a>';
 			}
 		} else {
 			$result .= '<a href="'.api_get_path(WEB_COURSE_PATH).$course_directory.'/">'.$course_display_title.'</a>';
 		}
 	} else {
-		$result .= $course_display_title." "." ".get_lang('CourseClosed')."";
+		$result .= $course_display_title.'  '.get_lang('CourseClosed');
 	}
 	// show the course_code and teacher if chosen to display this
-	if (api_get_setting('display_coursecode_in_courselist') == 'true' OR api_get_setting('display_teacher_in_courselist') == 'true') {
+	if (api_get_setting('display_coursecode_in_courselist') == 'true' || api_get_setting('display_teacher_in_courselist') == 'true') {
 		$result .= '<br />';
 	}
 	if (api_get_setting('display_coursecode_in_courselist') == 'true') {
 		$result .= $course_display_code;
 	}
-	if (api_get_setting('display_coursecode_in_courselist') == 'true' AND api_get_setting('display_teacher_in_courselist') == 'true') {
+	if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') {
 		$result .= ' &ndash; ';
 	}
 	if (api_get_setting('display_teacher_in_courselist') == 'true') {
 		$result .= $course_teacher;
-		if(!empty($course_teacher_email)) {
+		if (!empty($course_teacher_email)) {
 			$result .= ' ('.$course_teacher_email.')';
 		}
 	}
 
 	$current_course_settings = CourseManager :: get_access_settings($my_course['k']);
 
-
 	// display the what's new icons
 	$result .= show_notification($my_course);
 
@@ -495,7 +491,7 @@ function get_logged_user_course_html($my_course) {
 			}
 			$result .= '</li>';
 			$result .= '<ul>';
-			reset($digest[$thisCourseSysCode][$key2]);
+			reset ($digest[$thisCourseSysCode][$key2]);
 			while (list ($key3, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2])) {
 				$result .= '<li>';
 				if ($orderKey[2] == 'keyTools') {
@@ -522,7 +518,7 @@ function get_logged_user_course_html($my_course) {
 	$result .= '</li>';
 
 
-	if (api_get_setting('use_session_mode')=='true' && !$nosession) {
+	if (api_get_setting('use_session_mode') == 'true' && !$nosession) {
 		$session = '';
 		$active = false;
 		if (!empty($my_course['session_name'])) {
@@ -542,19 +538,19 @@ function get_logged_user_course_html($my_course) {
 			$session['title'] = $my_course['session_name'];
 			if ( $my_course['date_start']=='0000-00-00' ) {
 				$session['dates'] = get_lang('WithoutTimeLimits');
-				if ( api_get_setting('show_session_coach') === 'true' ) {
+				if (api_get_setting('show_session_coach') === 'true') {
 					$session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
 				}
 				$active = true;
 			} else {
 				$session ['dates'] = ' - '.get_lang('From').' '.$my_course['date_start'].' '.get_lang('To').' '.$my_course['date_end'];
-				if ( api_get_setting('show_session_coach') === 'true' ) {
+				if (api_get_setting('show_session_coach') === 'true') {
 					$session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
 				}
-				$active = ($date_start <= $now && $date_end >= $now)?true:false;
+				$active = $date_start <= $now && $date_end >= $now;
 			}
 		}
-		$output = array ($my_course['user_course_cat'], $result, $my_course['id_session'], $session, 'active'=>$active);
+		$output = array ($my_course['user_course_cat'], $result, $my_course['id_session'], $session, 'active' => $active);
 	} else {
 		$output = array ($my_course['user_course_cat'], $result);
 	}
@@ -584,8 +580,9 @@ function show_notification($my_course) {
 	$oldestTrackDate = "3000-01-01 00:00:00";
 	while ($lastTrackInCourse = Database::fetch_array($resLastTrackInCourse)) {
 		$lastTrackInCourseDate[$lastTrackInCourse['access_tool']] = $lastTrackInCourse['access_date'];
-		if ($oldestTrackDate > $lastTrackInCourse['access_date'])
+		if ($oldestTrackDate > $lastTrackInCourse['access_date']) {
 			$oldestTrackDate = $lastTrackInCourse['access_date'];
+		}
 	}
 	// get the last edits of all tools of this course
 	$sql = "SELECT tet.*, tet.lastedit_date last_date, tet.tool tool, tet.ref ref,
@@ -605,13 +602,12 @@ function show_notification($my_course) {
 	//filter all selected items
 	while ($res && ($item_property = Database::fetch_array($res))) {
 		if ((!isset ($lastTrackInCourseDate[$item_property['tool']])
-                || $lastTrackInCourseDate[$item_property['tool']] < $item_property['lastedit_date'])
-            && ((in_array($item_property['to_group_id'], $group_ids) && $item_property['tool'] != TOOL_DROPBOX)
-                || $item_property['to_user_id'] == $user_id)
-            && ($item_property['visibility'] == '1'
-                || ($my_course['s'] == '1' && $item_property['visibility'] == '0')
-                || !isset ($item_property['visibility'])))
-        {
+				|| $lastTrackInCourseDate[$item_property['tool']] < $item_property['lastedit_date'])
+			&& ((in_array($item_property['to_group_id'], $group_ids) && $item_property['tool'] != TOOL_DROPBOX)
+				|| $item_property['to_user_id'] == $user_id)
+			&& ($item_property['visibility'] == '1'
+				|| ($my_course['s'] == '1' && $item_property['visibility'] == '0')
+				|| !isset ($item_property['visibility']))) {
 			$notifications[$item_property['tool']] = $item_property;
 		}
 	}
@@ -636,7 +632,6 @@ function show_notification($my_course) {
 */
 function get_user_course_categories() {
 	global $_user;
-
 	$output = array();
 	$table_category = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY);
 	$sql = "SELECT * FROM ".$table_category." WHERE user_id='".Database::escape_string($_user['user_id'])."'";
@@ -661,10 +656,10 @@ if (!isset ($maxValvas)) {
 	$maxValvas = CONFVAL_maxValvasByCourse; // Maximum number of entries
 }
 if (!isset ($maxAgenda)) {
-	$maxAgenda = CONFVAL_maxAgendaByCourse; //  collected from each course
+	$maxAgenda = CONFVAL_maxAgendaByCourse; // collected from each course
 }
 if (!isset ($maxCourse)) {
-	$maxCourse = CONFVAL_maxTotalByCourse; //  and displayed in summary.
+	$maxCourse = CONFVAL_maxTotalByCourse; // and displayed in summary.
 }
 $maxValvas = (int) $maxValvas;
 $maxAgenda = (int) $maxAgenda;
@@ -680,6 +675,7 @@ if ($maxCourse > 0) {
 echo '	<div class="maincontent" id="maincontent">'; // start of content for logged in users
 // Plugins for the my courses main area
 api_plugin('mycourses_main');
+
 /*
 -----------------------------------------------------------------------------
 	System Announcements
@@ -694,8 +690,8 @@ if (!empty ($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/',$_GET['in
 	$pageIncluded = true;
 } else {
 	/*--------------------------------------
-	              DISPLAY COURSES
-	   --------------------------------------*/
+				DISPLAY COURSES
+	  --------------------------------------*/
 
 	$list = '';
 	// this is the main function to get the course list
@@ -733,7 +729,7 @@ if (!empty ($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/',$_GET['in
 			//Take the entries listed at the top of advalvas/announcements tool
 			$course_announcement_table = Database::get_course_table(TABLE_ANNOUNCEMENT);
 			$sqlGetLastAnnouncements = "SELECT end_date publicationDate, content
-									                            FROM ".$course_announcement_table;
+											FROM ".$course_announcement_table;
 			switch (CONFVAL_limitPreviewTo) {
 				case SCRIPTVAL_NewEntriesOfTheDay :
 					$sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date("Y m d")."'";
@@ -744,12 +740,11 @@ if (!empty ($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/',$_GET['in
 					// take care mysql -> DATE_FORMAT(time,format) php -> date(format,date)
 					$sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date("Y m d", $_user["lastLogin"])."'";
 			}
-			$sqlGetLastAnnouncements .= "ORDER BY end_date DESC
-									                             LIMIT ".$maxValvas;
+			$sqlGetLastAnnouncements .= "ORDER BY end_date DESC LIMIT ".$maxValvas;
 			$resGetLastAnnouncements = api_sql_query($sqlGetLastAnnouncements, __FILE__, __LINE__);
 			if ($resGetLastAnnouncements) {
 				while ($annoncement = Database::fetch_array($resGetLastAnnouncements)) {
-					$keyTools = "valvas";
+					$keyTools = 'valvas';
 					$keyTime = $annoncement['publicationDate'];
 					$keyCourse = $thisCourseSysCode;
 					$digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = htmlspecialchars(api_substr(strip_tags($annoncement["content"]), 0, CONFVAL_NB_CHAR_FROM_CONTENT), ENT_QUOTES, $charset);
@@ -773,11 +768,11 @@ if (!empty ($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/',$_GET['in
 		// collect from agenda, but only if tool is visible for the course
 		if ($result && $thisAgenda > 0 && Database::num_rows($result) > 0) {
 			$tableCal = $courseTablePrefix.$thisCourseDbName.$_configuration['db_glue']."calendar_event";
-			$sqlGetNextAgendaEvent = "SELECT  start_date , title content, start_time
-									                          FROM $tableCal
-									                          WHERE start_date >= CURDATE()
-									                          ORDER BY start_date, start_time
-									                          LIMIT $maxAgenda";
+			$sqlGetNextAgendaEvent = "SELECT start_date, title content, start_time
+											FROM $tableCal
+											WHERE start_date >= CURDATE()
+											ORDER BY start_date, start_time
+											LIMIT $maxAgenda";
 			$resGetNextAgendaEvent = api_sql_query($sqlGetNextAgendaEvent, __FILE__, __LINE__);
 			if ($resGetNextAgendaEvent) {
 				while ($agendaEvent = Database::fetch_array($resGetNextAgendaEvent)) {
@@ -799,24 +794,24 @@ if (!empty ($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/',$_GET['in
 	} //end while mycourse...
 }
 
-if ( is_array($list) ) {
+if (is_array($list)) {
 	//Courses whithout sessions
 	$old_user_category = 0;
-	foreach($list as $key=>$value) {
-		if ( empty($value[2]) ) { //if out of any session
+	foreach ($list as $key => $value) {
+		if (empty($value[2])) { //if out of any session
 
 			$userdefined_categories = get_user_course_categories();
 			echo '<ul class="courseslist">';
 
 			if ($old_user_category<>$value[0]) {
-				if ($key<>0 OR $value[0]<>0) {// there are courses in the previous category
+				if ($key <> 0 || $value[0] <> 0) {// there are courses in the previous category
 					echo "\n</ul>";
 				}
 				echo "\n\n\t<ul class=\"user_course_category\"><li>".$userdefined_categories[$value[0]]."</li></ul>\n";
 				if ($key<>0 OR $value[0]<>0){ // there are courses in the previous category
 					echo "<ul class=\"courseslist\">";
 				}
-				$old_user_category=$value[0];
+				$old_user_category = $value[0];
 
 			}
 			echo $value[1];
@@ -824,21 +819,19 @@ if ( is_array($list) ) {
 		}
 	}
 
-
 	$listActives = $listInactives = $listCourses = array();
-	foreach ( $list as $key=>$value ) {
-		if ( $value['active'] ) { //if the session is still active (as told by get_logged_user_course_html())
+	foreach ($list as $key => $value) {
+		if ($value['active']) { //if the session is still active (as told by get_logged_user_course_html())
 			$listActives[] = $value;
-		} else if ( !empty($value[2]) ) { //if there is a session but it is not active
+		} else if (!empty($value[2])) { //if there is a session but it is not active
 			$listInactives[] = $value;
 		}
 	}
 	$old_user_category = 0;
 	$userdefined_categories = get_user_course_categories();
 
-	if(count($listActives)>0 && $display_actives){
+	if (count($listActives) > 0 && $display_actives) {
 		echo "<ul class=\"courseslist\">\n";
-
 		foreach ($listActives as $key => $value) {
 			if (!empty($value[2])) {
 				if ((isset($old_session) && $old_session != $value[2]) or ((!isset($old_session)) && isset($value[2]))) {
@@ -848,25 +841,20 @@ if ( is_array($list) ) {
 					}
 					echo '<ul class="session_box">' .
 							'<li class="session_box_title">'.$value[3]['title'].' '.$value[3]['dates'].'</li>';
-					if ( !empty($value[3]['coach']) ) {
+					if (!empty($value[3]['coach'])) {
 						echo '<li class="session_box_coach">'.$value[3]['coach'].'</li>';
 					}
 					echo "</ul>\n";
-
 					echo '<ul class="session_course_item">';
 				}
 			}
 			echo $value[1];
-
 		}
-
 		echo "\n</ul><br /><br />\n";
-
 	}
 
-	if (count($listInactives)>0 && !$display_actives) {
+	if (count($listInactives) > 0 && !$display_actives) {
 		echo '<ul class="sessions_list_inactive">';
-
 		foreach ($listInactives as $key => $value) {
 			if (!empty($value[2])) {
 				if ($old_session != $value[2]) {
@@ -876,23 +864,21 @@ if ( is_array($list) ) {
 					}
 					echo '<ul class="session_box">' .
 							'<li class="session_box_title">'.$value[3]['title'].' '.$value[3]['dates'].'</li>';
-					if ( !empty($value[3]['coach']) ) {
+					if (!empty($value[3]['coach'])) {
 						echo '<li class="session_box_coach">'.$value[3]['coach'].'</li>';
 					}
 					echo "</ul>\n";
-
-				echo '<ul>';
-
+					echo '<ul>';
 				}
 			}
 			echo $value[1];
-
 		}
-
 		echo "\n</ul><br /><br />\n";
 	}
 }
+
 echo '</div>'; // end of content section
+
 // Register whether full admin or null admin course
 // by course through an array dbname x user status
 api_session_register('status');
@@ -906,43 +892,46 @@ echo '	<div class="menu">';
 
 // api_display_language_form(); // moved to the profile page.
 
-$show_menu=false;
-$show_create_link=false;
-$show_course_link=false;
-$show_digest_link=false;
+$show_menu = false;
+$show_create_link = false;
+$show_course_link = false;
+$show_digest_link = false;
 
-$display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION["studentview"] != "studentenview");
+$display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION['studentview'] != 'studentenview');
 if ($display_add_course_link) {
-	$show_menu=true;
-	$show_create_link=true;
+	$show_menu = true;
+	$show_create_link = true;
 }
 
 if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
-	$show_menu=true;
-	$show_course_link=true;
+	$show_menu = true;
+	$show_course_link = true;
 } else {
 	if (api_get_setting('allow_students_to_browse_courses')=='true') {
-		$show_menu=true;
-		$show_course_link=true;
+		$show_menu = true;
+		$show_course_link = true;
 	}
 }
 
-if(isset($toolsList) and is_array($toolsList) and isset($digest)) {
-	$show_digest_link=true;
-	$show_menu=true;
+if (isset($toolsList) and is_array($toolsList) and isset($digest)) {
+	$show_digest_link = true;
+	$show_menu = true;
 }
 
 // My account section
-if ($show_menu){
+if ($show_menu) {
 	echo '<div class="menusection">';
 	echo '<span class="menusectioncaption">'.get_lang('MenuUser').'</span>';
 	echo '<ul class="menulist">';
-	if ($show_create_link)
+	if ($show_create_link) {
 		display_create_course_link();
-	if ($show_course_link)
+	}
+	if ($show_course_link) {
 		display_edit_course_list_links();
-	if ($show_digest_link)
+	}
+	if ($show_digest_link) {
 		display_digest($toolsList, $digest, $orderKey, $courses);
+	}
 	echo '</ul>';
 	echo '</div>';
 }
@@ -954,7 +943,7 @@ if (!empty($menu_navigation)) {
 	echo '<span class="menusectioncaption">'.get_lang('MainNavigation').'</span>';
 	echo '<ul class="menulist">';
 	foreach ($menu_navigation as $section => $navigation_info) {
-		$current = ($section == $GLOBALS['this_section'] ? ' id="current"' : '');
+		$current = $section == $GLOBALS['this_section'] ? ' id="current"' : '';
 		echo '<li'.$current.'>';
 		echo '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
 		echo '</li>';
@@ -964,7 +953,6 @@ if (!empty($menu_navigation)) {
 	echo '</div>';
 }
 
-
 // plugins for the my courses menu
 if (isset($_plugins['mycourses_menu']) && is_array($_plugins['mycourses_menu'])) {
 	echo '<div class="note">';
@@ -972,18 +960,18 @@ if (isset($_plugins['mycourses_menu']) && is_array($_plugins['mycourses_menu']))
 	echo '</div>';
 }
 
-if (api_get_setting('allow_reservation')=='true' && api_is_allowed_to_create_course() ){
+if (api_get_setting('allow_reservation') == 'true' && api_is_allowed_to_create_course() ){
 	//include_once('main/reservation/rsys.php');
 	echo '<div class="menusection">';
 	echo '<span class="menusectioncaption">'.get_lang('Booking').'</span>';
 	echo '<ul class="menulist">';
-	echo '<a href="main/reservation/reservation.php">'.get_lang('ManageReservations').'</a><br/>';
-	//echo '<a href="main/reservation/reservation.php">'.get_lang('ManageReservations').'</a><br/>';
+	echo '<a href="main/reservation/reservation.php">'.get_lang('ManageReservations').'</a><br />';
+	//echo '<a href="main/reservation/reservation.php">'.get_lang('ManageReservations').'</a><br />';
 
 	/*require_once('main/reservation/rsys.php');
 	if(api_is_platform_admin() || Rsys :: check_user_status() == 1) { // Only for admins & teachers...
-	    echo '<a href="main/reservation/m_item.php">'.get_lang('ManageItems').'</a><br/>';
-	    echo '<a href="main/reservation/m_reservation.php">'.get_lang('ManageReservationPeriods').'</a><br/>';
+		echo '<a href="main/reservation/m_item.php">'.get_lang('ManageItems').'</a><br />';
+		echo '<a href="main/reservation/m_reservation.php">'.get_lang('ManageReservationPeriods').'</a><br />';
 	}
 	*/
 	echo '</ul>';
@@ -992,19 +980,20 @@ if (api_get_setting('allow_reservation')=='true' && api_is_allowed_to_create_cou
 
 // search textbox
 if (api_get_setting('search_enabled') == 'true') {
-    echo '<div class="searchbox">';
-    $search_btn = get_lang('Search');
-    $search_text_default = get_lang('YourTextHere');
+	echo '<div class="searchbox">';
+	$search_btn = get_lang('Search');
+	$search_text_default = get_lang('YourTextHere');
 echo <<<EOD
-<br/>
+<br />
 <form action="main/search/" method="post">
-&nbsp;&nbsp;<input type="text" id="query"  size="15" name="query" value="" />
+&nbsp;&nbsp;<input type="text" id="query" size="15" name="query" value="" />
 &nbsp;&nbsp;<button class="save" type="submit" name="submit" value="$search_btn"/>$search_btn </button>
 </form>
 EOD;
-    echo '</div>';
+	echo '</div>';
 }
 
 echo '</div>'; // end of menu
+
 //footer
 Display :: display_footer();

+ 6 - 7
webchatdeny.php

@@ -12,22 +12,22 @@
 */
 
 // name of the language file that needs to be included
-$language_file = "index";
+$language_file = 'index';
 
 // including necessary files
-include_once('./main/inc/global.inc.php');
+include_once './main/inc/global.inc.php';
 
 // table definitions
 $track_user_table = Database::get_main_table(TABLE_MAIN_USER);
-if (isset($_user['user_id']) && $_user['user_id']!='') {
+if (isset($_user['user_id']) && $_user['user_id'] != '') {
 	$_user['user_id'] = intval($_user['user_id']);
-	$sql="update $track_user_table set chatcall_user_id = '', chatcall_date = '', chatcall_text='DENIED' where (user_id = ".$_user['user_id'].")";
-	$result=api_sql_query($sql,__FILE__,__LINE__);
+	$sql = "update $track_user_table set chatcall_user_id = '', chatcall_date = '', chatcall_text='DENIED' where (user_id = ".$_user['user_id'].")";
+	$result = Database::query($sql, __FILE__, __LINE__);
 }
 
 Display::display_header();
 
-$message=get_lang("RequestDenied")."<br><br><a href='javascript:history.back()'>".get_lang("Back")."</a>";
+$message = get_lang('RequestDenied').'<br /><br /><a href="javascript: history.back();">'.get_lang('Back').'</a>';
 Display::display_normal_message($message);
 
 /*
@@ -37,4 +37,3 @@ Display::display_normal_message($message);
 */
 
 Display::display_footer();
-?>

+ 112 - 120
whoisonline.php

@@ -6,26 +6,30 @@
 * Who is online list
 ==============================================================================
 */
-// name of the language file that needs to be included
-$language_file = array('index','registration','messages','userInfo');
+
+// language files that should be included
+$language_file = array('index', 'registration', 'messages', 'userInfo');
+
 if (!isset($_GET['cidReq'])) {
-	$cidReset = true;
+	$cidReset = true;
 }
+
 // including necessary files
 require_once './main/inc/global.inc.php';
 require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
 require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
 require_once api_get_path(LIBRARY_PATH).'social.lib.php';
+
 // table definitions
 $track_user_table = Database::get_main_table(TABLE_MAIN_USER);
 
-$htmlHeadXtra[] = '<script type="text/javascript">
+$htmlHeadXtra[] = '<script type="text/javascript">
 	function show_image(image,width,height) {
 		width = parseInt(width) + 20;
-		height = parseInt(height) + 20;
-		window_x = window.open(image,\'windowX\',\'width=\'+ width + \', height=\'+ height + \'\');
+		height = parseInt(height) + 20;
+		window_x = window.open(image,\'windowX\',\'width=\'+ width + \', height=\'+ height + \'\');
 	}
-
+
 </script>';
 $htmlHeadXtra[] = '<script type="text/javascript" src="./main/inc/lib/javascript/jquery.js"></script>';
 $htmlHeadXtra[] = '<script type="text/javascript" src="./main/inc/lib/javascript/thickbox.js"></script>';
@@ -36,7 +40,7 @@ $(document).ready(function (){
 		if (confirm("'.get_lang('SendMessageInvitation', '').'")) {
 			$("#form_register_friend").submit();
 		}
-	});
+	});
 });
 function change_panel (mypanel_id,myuser_id) {
 		$.ajax({
@@ -50,10 +54,10 @@ function change_panel (mypanel_id,myuser_id) {
 			 $("div#id_content_panel_init").html(datos);
 			 $("div#display_response_id").html("");
 			}
-		});
+		});
 }
 function action_database_panel(option_id,myuser_id) {
-
+
 	if (option_id==5) {
 		my_txt_subject=$("#txt_subject_id").val();
 	} else {
@@ -75,8 +79,8 @@ function action_database_panel(option_id,myuser_id) {
 		success: function(datos) {
 		 $("#display_response_id").html(datos);
 		}
-	});
-}
+	});
+}
 function display_hide () {
 		setTimeout("hide_display_message()",3000);
 }
@@ -91,93 +95,92 @@ function hide_display_message () {
 	}catch(e) {
 		$("#txt_area_invite").val("");
 	}
-}
+}
 </script>';
+
 if ($_GET['chatid'] != '') {
 	//send out call request
 	$time = time();
 	$time = date("Y-m-d H:i:s", $time);
 	$chatid = addslashes($_GET['chatid']);
-	if ($_GET['chatid']==strval(intval($_GET['chatid']))) {
-		$sql="update $track_user_table set chatcall_user_id = '".Database::escape_string($_user['user_id'])."', chatcall_date = '".Database::escape_string($time)."', chatcall_text = '' where (user_id = ".(int)Database::escape_string($chatid).")";
-		$result=api_sql_query($sql,__FILE__,__LINE__);
+	if ($_GET['chatid'] == strval(intval($_GET['chatid']))) {
+		$sql = "update $track_user_table set chatcall_user_id = '".Database::escape_string($_user['user_id'])."', chatcall_date = '".Database::escape_string($time)."', chatcall_text = '' where (user_id = ".(int)Database::escape_string($chatid).")";
+		$result = Database::query($sql, __FILE__, __LINE__);
 		//redirect caller to chat
 		header("Location: ".$_configuration['code_append']."chat/chat.php?".api_get_cidreq()."&origin=whoisonline&target=".Security::remove_XSS($chatid));
-		exit;
+		exit;
 	}
 }
 
-
 /**
  * Displays a sortable table with the list of online users.
  * @param array $user_list
  */
-function display_user_list($user_list, $_plugins)
-{
+function display_user_list($user_list, $_plugins) {
 	global $charset;
-	if ($_GET["id"]=='') {
+	if ($_GET['id'] == '') {
 		$extra_params = array();
 		$course_url = '';
-		if(strlen($_GET['cidReq']) > 0) {
+		if (strlen($_GET['cidReq']) > 0) {
 			$extra_params['cidReq'] = Security::remove_XSS($_GET['cidReq']);
 			$course_url = '&amp;cidReq='.Security::remove_XSS($_GET['cidReq']);
-		}
+		}
 		foreach ($user_list as $user) {
-			$uid=$user[0];
+			$uid = $user[0];
 			$user_info = api_get_user_info($uid);
 			$table_row = array();
 			$url = '?id='.$uid.$course_url;
-            $image_array=UserManager::get_user_picture_path_by_id($uid,'system',false,true);
-
-            $friends_profile = UserFriend::get_picture_user($uid, $image_array['file'], 92, 'medium_', ' width="90" height="90" ');
-            //reduce image
-            $table_row[] = '<center><a href="'.$url.'"><img src="'.$friends_profile['file'].'" '.$friends_profile['style'].' border="1"></a></center>';
+			$image_array = UserManager::get_user_picture_path_by_id($uid, 'system', false, true);
+
+			$friends_profile = UserFriend::get_picture_user($uid, $image_array['file'], 92, 'medium_', ' width="90" height="90" ');
+			// reduce image
+			$table_row[] = '<center><a href="'.$url.'"><img src="'.$friends_profile['file'].'" '.$friends_profile['style'].' border="1"></a></center>';
 			$table_row[] = '<a href="'.$url.'">'.api_get_person_name($user_info['firstName'], $user_info['lastName']).'</a>';
-
+
 			//$table_row[] = '<a href="'.$url.'">'.$user_info['lastName'].'</a>';
-
+
 			if (api_get_setting('show_email_addresses') == 'true') {
 				$table_row[] = Display::encrypted_mailto_link($user_info['mail']);
 			}
-			$user_anonymous=api_get_anonymous_id();
-			if (api_get_setting('allow_social_tool')=='true' && api_get_user_id()<>$user_anonymous && api_get_user_id()<>0) {
+			$user_anonymous = api_get_anonymous_id();
+			if (api_get_setting('allow_social_tool') == 'true' && api_get_user_id() <> $user_anonymous && api_get_user_id() <> 0) {
 				if ($user_info['user_id'] != api_get_user_id() && !api_is_anonymous($user_info['user_id'])) {
-					$user_relation=UserFriend::get_relation_between_contacts(api_get_user_id(),$user_info['user_id']);
-					if ($user_relation==0 || $user_relation==6) {
+					$user_relation = UserFriend::get_relation_between_contacts(api_get_user_id(), $user_info['user_id']);
+					if ($user_relation == 0 || $user_relation == 6) {
 						$table_row[] = '<a href="main/messages/send_message_to_userfriend.inc.php?view_panel=2&height=365&width=610&user_friend='.$user_info['user_id'].'" class="thickbox" title="'.get_lang('SendInvitation').'">'.Display :: return_icon('add_multiple_users.gif', get_lang('SocialInvitationToFriends')).'&nbsp;'.get_lang('SendInvitation').'</a><br />
 										<a href="main/messages/send_message_to_userfriend.inc.php?view_panel=1&height=365&width=610&user_friend='.$user_info['user_id'].'" class="thickbox" title="'.get_lang('SendAMessage').'">'.Display :: return_icon('mail_send.png', get_lang('SendAMessage')).'&nbsp;'.get_lang('SendAMessage').'</a>';
 					} else {
 						$table_row[] = '<a href="main/messages/send_message_to_userfriend.inc.php?view_panel=1&height=365&width=610&user_friend='.$user_info['user_id'].'" class="thickbox" title="'.get_lang('SendAMessage').'">'.Display :: return_icon('mail_send.png', get_lang('SendAMessage')).'&nbsp;'.get_lang('SendAMessage').'</a>';
-					}
+					}
 				}
 			}
 			$table_data[] = $table_row;
 		}
-		$table_header[] = array(get_lang('UserPicture'),false,'width="90"');
-		$table_header[] = array(get_lang('Name'),true);
-		//$table_header[] = array(get_lang('LastName'),true);
-
+		$table_header[] = array(get_lang('UserPicture'), false, 'width="90"');
+		$table_header[] = array(get_lang('Name'), true);
+		//$table_header[] = array(get_lang('LastName'), true);
+
 		if (api_get_setting('show_email_addresses') == 'true') {
-			$table_header[] = array(get_lang('Email'),true);
-		}
-		$user_anonymous=api_get_anonymous_id();
-		if (api_get_setting('allow_social_tool')=='true' && api_get_user_id()<>$user_anonymous && api_get_user_id()<>0) {
-			$table_header[] = array(get_lang('Friends'),false,'width="200"');
+			$table_header[] = array(get_lang('Email'), true);
 		}
+		$user_anonymous = api_get_anonymous_id();
+		if (api_get_setting('allow_social_tool') == 'true' && api_get_user_id() <> $user_anonymous && api_get_user_id() <> 0) {
+			$table_header[] = array(get_lang('Friends'), false, 'width="200"');
+		}
 		/*this feature is deprecated
-		if ( api_get_setting('allow_message_tool')=='true' && isset($_SESSION['_user'])) {
-			$table_header[] = array(get_lang('SendMessage'),true);
+		if (api_get_setting('allow_message_tool') == 'true' && isset($_SESSION['_user'])) {
+			$table_header[] = array(get_lang('SendMessage'), true);
 		}
 		*/
-		$sorting_options['column'] = (isset ($_GET['column']) ? (int)$_GET['column'] : 2);
-		/*if (api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool')=='true' ) {
+		$sorting_options['column'] = (isset($_GET['column']) ? (int)$_GET['column'] : 2);
+		/*if (api_get_setting('allow_social_tool') == 'true' && api_get_setting('allow_message_tool') == 'true') {
 			//send_invitation_friend_user();
-			echo '<div align="right"><input type="button" name="id_btn_send_invitation" id="id_btn_send_invitation" value="'.get_lang('SendInviteMessage').'"/></div>';
+			echo '<div align="right"><input type="button" name="id_btn_send_invitation" id="id_btn_send_invitation" value="'.get_lang('SendInviteMessage').'"/></div>';
 			echo '<form action="whoisonline.php" name="form_register_friend" id="form_register_friend" method="post">';
 		}*/
-
-		Display::display_sortable_table($table_header,$table_data,$sorting_options,array('per_page_default'=>count($table_data)),$extra_params);
-		/*if (api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool')=='true' ) {
+
+		Display::display_sortable_table($table_header, $table_data, $sorting_options, array('per_page_default' => count($table_data)), $extra_params);
+		/*if (api_get_setting('allow_social_tool') == 'true' && api_get_setting('allow_message_tool') == 'true' ) {
 			echo '</form>';
 		}*/
 	}
@@ -186,58 +189,56 @@ function display_user_list($user_list, $_plugins)
  * Displays the information of an individual user
  * @param int $user_id
  */
-function display_individual_user($user_id)
-{
+function display_individual_user($user_id) {
 	global $interbreadcrumb;
 	$safe_user_id = Database::escape_string($user_id);
-
+
 	// to prevent a hacking attempt: http://www.dokeos.com/forum/viewtopic.php?t=5363
-	$user_table=Database::get_main_table(TABLE_MAIN_USER);
+	$user_table = Database::get_main_table(TABLE_MAIN_USER);
 	$sql = "SELECT * FROM $user_table WHERE user_id='".$safe_user_id."'";
-	$result=api_sql_query($sql,__FILE__,__LINE__);
-	if (Database::num_rows($result)==1) {
+	$result = Database::query($sql, __FILE__, __LINE__);
+	if (Database::num_rows($result) == 1) {
 		$user_object = Database::fetch_object($result);
-		$name = GetFullUserName($user_id).($_SESSION['_uid'] == $user_id ? '&nbsp;<b>('.get_lang('Me').')</b>' : '' );
+		$name = GetFullUserName($user_id).($_SESSION['_uid'] == $user_id ? '&nbsp;<strong>('.get_lang('Me').')</strong>' : '' );
 		$alt = GetFullUserName($user_id).($_SESSION['_uid'] == $user_id ? '&nbsp;('.get_lang('Me').')' : '');
 		$status = ($user_object->status == COURSEMANAGER ? get_lang('Teacher') : get_lang('Student'));
-		$interbreadcrumb[]=array("url" => "whoisonline.php","name" => get_lang('UsersOnLineList'));
+		$interbreadcrumb[] = array('url' => 'whoisonline.php', 'name' => get_lang('UsersOnLineList'));
 		Display::display_header($alt);
 		echo '<div class="actions-title">';
 		echo $alt;
-		echo '</div><br/>';
+		echo '</div><br />';
 		echo '<div style="text-align: center">';
 		if (strlen(trim($user_object->picture_uri)) > 0) {
-			$sysdir_array = UserManager::get_user_picture_path_by_id($safe_user_id,'system');
+			$sysdir_array = UserManager::get_user_picture_path_by_id($safe_user_id, 'system');
 			$sysdir = $sysdir_array['dir'];
-			$webdir_array = UserManager::get_user_picture_path_by_id($safe_user_id,'web');
+			$webdir_array = UserManager::get_user_picture_path_by_id($safe_user_id, 'web');
 			$webdir = $webdir_array['dir'];
-			$fullurl=$webdir.$user_object->picture_uri;
-			$system_image_path=$sysdir.$user_object->picture_uri;
-			list($width, $height, $type, $attr) = getimagesize($system_image_path);
+			$fullurl = $webdir.$user_object->picture_uri;
+			$system_image_path = $sysdir.$user_object->picture_uri;
+			list($width, $height, $type, $attr) = @getimagesize($system_image_path);
 			$resizing = (($height > 200) ? 'height="200"' : '');
 			$height += 30;
 			$width += 30;
-			$window_name = 'window'.uniqid('');
-			// get the path,width and height from original picture
+			$window_name = 'window'.uniqid('');
+			// get the path,width and height from original picture
 			$big_image = $webdir.'big_'.$user_object->picture_uri;
 			$big_image_size = api_getimagesize($big_image);
-			$big_image_width= $big_image_size[0];
-			$big_image_height= $big_image_size[1];
-			$url_big_image = $big_image.'?rnd='.time();
-			echo '<input type="image" src="'.$fullurl.'" alt="'.$alt.'" onclick="return show_image(\''.$url_big_image.'\',\''.$big_image_width.'\',\''.$big_image_height.'\');"/><br />';
+			$big_image_width = $big_image_size[0];
+			$big_image_height = $big_image_size[1];
+			$url_big_image = $big_image.'?rnd='.time();
+			echo '<input type="image" src="'.$fullurl.'" alt="'.$alt.'" onclick="javascript: return show_image(\''.$url_big_image.'\',\''.$big_image_width.'\',\''.$big_image_height.'\');"/><br />';
 			global $user_anonymous;
-			if (api_get_setting('allow_social_tool')=='true' && api_get_user_id()<>$user_anonymous && api_get_user_id()<>0) {
+			if (api_get_setting('allow_social_tool') == 'true' && api_get_user_id() <> $user_anonymous && api_get_user_id() <> 0) {
 				echo '<br />';
-				echo '<a href="'.api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$safe_user_id.'">'.get_lang('ViewSharedProfile').'</a>';
+				echo '<a href="'.api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$safe_user_id.'">'.get_lang('ViewSharedProfile').'</a>';
 				echo '<br />';
-			}
-		} else {
-			echo Display::return_icon('unknown.jpg',get_lang('Unknown'));
+			}
+		} else {
+			echo Display::return_icon('unknown.jpg', get_lang('Unknown'));
 			echo '<br />';
 		}
-
-		if (api_get_setting("show_email_addresses") == "true")
-		{
+
+		if (api_get_setting('show_email_addresses') == 'true') {
 			echo Display::encrypted_mailto_link($user_object->email,$user_object->email).'<br />';
 		}
 		echo $status.'<br />';
@@ -274,12 +275,12 @@ function display_individual_user($user_id)
  * @todo use the correct api_get_path instead of $clarolineRepositoryWeb
  */
 function display_productions($user_id)
-{
-	$sysdir_array = UserManager::get_user_picture_path_by_id($user_id,'system');
+{
+	$sysdir_array = UserManager::get_user_picture_path_by_id($user_id, 'system');
 	$sysdir = $sysdir_array['dir'].$user_id.'/';
-	$webdir_array = UserManager::get_user_picture_path_by_id($user_id,'web');
+	$webdir_array = UserManager::get_user_picture_path_by_id($user_id, 'web');
 	$webdir = $webdir_array['dir'].$user_id.'/';
-	if( !is_dir($sysdir)) {
+	if (!is_dir($sysdir)) {
 		mkpath($sysdir);
 	}
 	$handle = opendir($sysdir);
@@ -290,21 +291,20 @@ function display_productions($user_id)
 		}
 		$productions[] = $file;
 	}
-	if(count($productions) > 0)	{
+	if (count($productions) > 0)	{
 		echo '<dt><strong>'.get_lang('Productions').'</strong></dt>';
 		echo '<dd><ul>';
-		foreach($productions as $index => $file) {
+		foreach ($productions as $index => $file) {
 			// Only display direct file links to avoid browsing an empty directory
-			if(is_file($sysdir.$file) && $file != $webdir_array['file']){
+			if (is_file($sysdir.$file) && $file != $webdir_array['file']) {
 				echo '<li><a href="'.$webdir.urlencode($file).'" target=_blank>'.$file.'</a></li>';
 			}
 			// Real productions are under a subdirectory by the User's id
-			if(is_dir($sysdir.$file)) {
+			if (is_dir($sysdir.$file)) {
 				$subs = scandir($sysdir.$file);
-				foreach($subs as $my => $sub) {
-					if(substr($sub,0,1) != '.' && is_file($sysdir.$file.'/'.$sub))
-					{
-						echo '<li><a href="'.$webdir.urlencode($file).'/'.urlencode($sub).'" target=_blank>'.$sub.'</a></li>';
+				foreach ($subs as $my => $sub) {
+					if (substr($sub, 0, 1) != '.' && is_file($sysdir.$file.'/'.$sub)) {
+						echo '<li><a href="'.$webdir.urlencode($file).'/'.urlencode($sub).'" target=_blank>'.$sub.'</a></li>';
 					}
 				}
 			}
@@ -314,63 +314,56 @@ function display_productions($user_id)
 }
 
 // This if statement prevents users accessing the who's online feature when it has been disabled.
-if ((api_get_setting('showonline','world') == 'true' AND !$_user['user_id']) OR ((api_get_setting('showonline','users') == 'true' OR api_get_setting('showonline','course') == 'true') AND $_user['user_id'])) {
+if ((api_get_setting('showonline', 'world') == 'true' && !$_user['user_id']) || ((api_get_setting('showonline', 'users') == 'true' || api_get_setting('showonline', 'course') == 'true') && $_user['user_id'])) {
 	if(isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) {
-		$user_list = Who_is_online_in_this_course($_user['user_id'],api_get_setting('time_limit_whosonline'),$_GET['cidReq']);
+		$user_list = Who_is_online_in_this_course($_user['user_id'], api_get_setting('time_limit_whosonline'), $_GET['cidReq']);
 	} else {
-		$user_list = WhoIsOnline($_user['user_id'],$_configuration['statistics_database'],api_get_setting('time_limit_whosonline'));
+		$user_list = WhoIsOnline($_user['user_id'], $_configuration['statistics_database'], api_get_setting('time_limit_whosonline'));
 	}
 
-
-	$total=count($user_list);
-	if (!isset($_GET['id']))
-	{
+	$total = count($user_list);
+	if (!isset($_GET['id'])) {
 		Display::display_header(get_lang('UsersOnLineList'));
 		echo '<div class="actions-title">';
 		echo get_lang('UsersOnLineList');
 		echo '</div>';
 		echo '<div class="actions-message">'.get_lang('TotalOnLine').' : '.$total.'</div>';
-		if ($_GET['id']=='') {
+		if ($_GET['id'] == '') {
 			echo '<p><a class="refresh" href="javascript:window.location.reload()">'.get_lang('Refresh').'</a></p>';
 		} else {
-			if(0) // if ($_user['user_id'] && $_GET["id"] != $_user['user_id'])
-			{
+			if (0) {
+			// if ($_user['user_id'] && $_GET["id"] != $_user['user_id']) {
 				echo '<a href="'.api_get_self().'?chatid='.Security::remove_XSS($_GET['id']).'">'.get_lang('SendChatRequest').'</a>';
 			}
 		}
 	}
 
-	if ($user_list!=false)
-	{
-		if (!isset($_GET['id']))
-		{
+	if ($user_list) {
+		if (!isset($_GET['id'])) {
 			display_user_list($user_list, $_plugins);
-		}
-		else   //individual user information - also displays header info
-		{
+		} else {
+			//individual user information - also displays header info
 			display_individual_user(Security::remove_XSS($_GET['id']));
 		}
 	}
-	elseif(isset($_GET['id']))
-	{
+	elseif (isset($_GET['id'])) {
 		Display::display_header(get_lang('UsersOnLineList'));
 		echo '<div class="actions-title">';
 		echo get_lang('UsersOnLineList');
 		echo '</div>';
 	}
-}
-else
-{
+} else {
 	Display::display_header(get_lang('UsersOnLineList'));
 	Display::display_error_message(get_lang('AccessNotAllowed'));
 }
-$referer = empty($_GET['referer'])?'index.php':api_htmlentities(strip_tags($_GET['referer']),ENT_QUOTES,$charset);
+
+$referer = empty($_GET['referer']) ? 'index.php' : api_htmlentities(strip_tags($_GET['referer']), ENT_QUOTES);
 
 if (isset($_GET['id'])) {
-	echo '<a href="whoisonline.php" class="fake_button_back">'.get_lang('Back').'</a>';
+	echo '<a href="whoisonline.php" class="fake_button_back">'.get_lang('Back').'</a>';
 } else {
-	echo '<a href="'.$referer.'" class="fake_button_back">'.get_lang('BackHome').'</a>';
-}
+	echo '<a href="'.$referer.'" class="fake_button_back">'.get_lang('BackHome').'</a>';
+}
 
 /*
 ==============================================================================
@@ -379,4 +372,3 @@ if (isset($_GET['id'])) {
 */
 /*echo '<div align="center"><a href="http://main.svndokeos.net/main/upload/users/4/4_49aeb3bb8bba5.jpg" class="thickbox">hola</a></div>';*/
 Display::display_footer();
-?>

+ 40 - 49
whoisonlinesession.php

@@ -1,18 +1,12 @@
 <?php
 /* For licensing terms, see /dokeos_license.txt */
-
-/**
- * @todo variables are sometimes in cammelcase, or even worse a mixture of CammelCase and udnerscoring: $a_userList
- *
- */
-
-// name of the language file that needs to be included
+
+// name of the language file that needs to be included
 $language_file = array ('index', 'chat', 'tracking');
 
-include_once("./main/inc/global.inc.php");
+include_once './main/inc/global.inc.php';
 api_block_anonymous_users();
 
-
 $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
 $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
 
@@ -25,7 +19,7 @@ $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
 
 Display::display_header(get_lang('UserOnlineListSession'));
 ?>
-<br/><br/>
+<br /><br />
 <table class="data_table" width="60%">
 	<tr class="tableName">
 		<td colspan="4">
@@ -47,37 +41,38 @@ Display::display_header(get_lang('UserOnlineListSession'));
 		</th>
 	</tr>
 <?php
-	$sessionIsCoach = array();
-	if (isset($_user['user_id']) && $_user['user_id']!='') {
+	$session_is_coach = array();
+	if (isset($_user['user_id']) && $_user['user_id'] != '') {
 		$_user['user_id'] = intval($_user['user_id']);
-		$result = api_sql_query("SELECT DISTINCT id,
-										name,
-										date_start,
-										date_end
-									FROM $tbl_session as session
+		$result = Database::query("SELECT DISTINCT id,
+										name,
+										date_start,
+										date_end
+									FROM $tbl_session as session
 									INNER JOIN $tbl_session_course as session_rel_course
 										ON session_rel_course.id_coach = ".$_user['user_id']."
 										AND session.id = session_rel_course.id_session
 									ORDER BY date_start, date_end, name",__FILE__,__LINE__);
-
+
 		while ($session = Database:: fetch_array($result)) {
-			$sessionIsCoach[$session['id']] = $session;
+			$session_is_coach[$session['id']] = $session;
 		}
-
-		$result = api_sql_query("SELECT DISTINCT id,
-										name,
-										date_start,
-										date_end
-								FROM $tbl_session as session
+
+		$result = Database::query("SELECT DISTINCT id,
+										name,
+										date_start,
+										date_end
+								FROM $tbl_session as session
 								WHERE session.id_coach = ".$_user['user_id']."
 								ORDER BY date_start, date_end, name",__FILE__,__LINE__);
 		while ($session = Database:: fetch_array($result)) {
-			$sessionIsCoach[$session['id']] = $session;
+			$session_is_coach[$session['id']] = $session;
 		}
 
-		foreach($sessionIsCoach as $session) {
-			$sql = "SELECT 	DISTINCT last_access.access_user_id,
-							last_access.access_date,
+		$students_online = array();
+		foreach ($session_is_coach as $session) {
+			$sql = "SELECT 	DISTINCT last_access.access_user_id,
+							last_access.access_date,
 							last_access.access_cours_code,
 							last_access.access_session_id,
 							".(api_is_western_name_order() ? "CONCAT(user.firstname,' ',user.lastname)" : "CONCAT(user.lastname,' ',user.firstname)")." as name,
@@ -85,41 +80,38 @@ Display::display_header(get_lang('UserOnlineListSession'));
 					FROM ".Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS)." AS last_access
 					INNER JOIN ".Database::get_main_table(TABLE_MAIN_USER)." AS user
 						ON user.user_id = last_access.access_user_id
-					WHERE access_session_id='".$session['id']."'
+					WHERE access_session_id='".$session['id']."'
 					AND NOW()-access_date<1000 GROUP BY access_user_id";
 
-			$result = api_sql_query($sql,__FILE__,__LINE__);
-
-			while($a_userList = mysql_fetch_array($result)) {
-				$a_onlineStudent[$a_userList['access_user_id']] = $a_userList;
+			$result = Database::query($sql, __FILE__, __LINE__);
+
+			while($user_list = Database::fetch_array($result)) {
+				$students_online[$user_list['access_user_id']] = $user_list;
 			}
 		}
-
-		if(count($a_onlineStudent)>0) {
-			foreach($a_onlineStudent as $onlineStudent) {
+
+		if (count($students_online) > 0) {
+			foreach ($students_online as $student_online) {
 				echo "<tr>
 						<td>
 					";
-				echo		$onlineStudent['name'];
+				echo $student_online['name'];
 				echo "	</td>
 						<td align='center'>
 					 ";
-				echo		$onlineStudent['access_cours_code'];
+				echo $student_online['access_cours_code'];
 				echo "	</td>
 						<td align='center'>
 					 ";
-							 if(!empty($onlineStudent['email']))
-							 {
-								echo $onlineStudent['email'];
-							 }
-							 else
-							 {
+							 if (!empty($student_online['email'])) {
+								echo $student_online['email'];
+							 } else {
 							 	echo get_lang('NoEmail');
-							 }
+							 }
 				echo "	</td>
 						<td align='center'>
 					 ";
-				echo '<a href="main/chat/chat.php?cidReq='.$onlineStudent['access_cours_code'].'&id_session='.$onlineStudent['access_session_id'].'"> -> </a>';
+				echo '<a href="main/chat/chat.php?cidReq='.$student_online['access_cours_code'].'&id_session='.$student_online['access_session_id'].'"> -> </a>';
 				echo "	</td>
 					</tr>
 					 ";
@@ -136,11 +128,10 @@ Display::display_header(get_lang('UserOnlineListSession'));
 ?>
 </table>
 <?php
+
 /*
 ==============================================================================
 		FOOTER
 ==============================================================================
 */
-
 Display::display_footer();
-?>