Bladeren bron

Bug #3646 and Issue #306 - Training reports (part3 ): Cleaning and minor reworks for all the code in this tool. This is needed for code readability and understanding, before further efforts for implementing person name related logic.

Ivan Tcholakov 15 jaren geleden
bovenliggende
commit
3fc6b57c73

+ 151 - 159
main/mySpace/access_details.php

@@ -38,139 +38,137 @@
 $language_file = array ('registration', 'index', 'tracking');
 
 // including the global Dokeos file
-require_once('../inc/global.inc.php');
+require_once '../inc/global.inc.php';
 
 // including additional libraries
-include_once(api_get_path(LIBRARY_PATH).'pchart/pData.class.php');
-include_once(api_get_path(LIBRARY_PATH).'pchart/pChart.class.php');
-include_once(api_get_path(LIBRARY_PATH).'pchart/pCache.class.php');
+include_once api_get_path(LIBRARY_PATH).'pchart/pData.class.php';
+include_once api_get_path(LIBRARY_PATH).'pchart/pChart.class.php';
+include_once api_get_path(LIBRARY_PATH).'pchart/pCache.class.php';
 
 // the section (for the tabs)
 $this_section = "session_my_space";
 
 
-
 /* MAIN */
 $user_id = Security::remove_XSS($_REQUEST['student']);
 $course_code=Security::remove_XSS($_REQUEST['course']);
 
-
-$connections = get_connections_to_course($user_id, $course_code);	
+$connections = get_connections_to_course($user_id, $course_code);
 if (api_is_xml_http_request()) {
 	$type  = Security::remove_XSS($_GET['type']);	
-	$main_year = $main_month_year = $main_day = array();	
+	$main_year = $main_month_year = $main_day = array();
 	// get last 8 days/months
 	$last_days = 8;	
 	$last_months = 5;	
-	for ($i=$last_days; $i>=0; $i--) {
-		$main_day[date ('d-m-Y', mktime () - $i * 3600 * 24)]=0;			
+	for ($i = $last_days; $i >= 0; $i--) {
+		$main_day[date ('d-m-Y', mktime () - $i * 3600 * 24)] = 0;			
 	}	
-	for ($i=$last_months; $i>=0; $i--) {
-		$main_month_year[date ('m-Y', mktime () - $i*30 * 3600 * 24)]=0;	
+	for ($i = $last_months; $i >= 0; $i--) {
+		$main_month_year[date ('m-Y', mktime () - $i*30 * 3600 * 24)] = 0;	
 	} 
-	
-	$i = 0;		
-	if (is_array($connections) && count($connections)>0 ){
-		foreach ($connections as $key=>$data) {				
-			//creating the main array		
-			//$main_year[date('Y',$data['login'])]+=calculHours($data['logout']-$data['login'])*60;
-			//$main_month_year[date('m-Y',$data['login'])]+=calculHours($data['logout']-$data['login'])*60;
-			$main_month_year[date('m-Y',$data['login'])]+=float_format(($data['logout']-$data['login'])/60, 0);
-			//$main_day[date('d-m-Y',$data['login'])]+=calculHours($data['logout']-$data['login'])*60;
-			$main_day[date('d-m-Y',$data['login'])]+=float_format(($data['logout']-$data['login'])/60, 0);
-			if ($i > 500) {
-				break;
-			}
-			$i++;
+
+	$i = 0;
+	if (is_array($connections) && count($connections) > 0) {
+	foreach ($connections as $key => $data) {
+		//creating the main array		
+		//$main_year[date('Y', $data['login'])] += calculHours($data['logout'] - $data['login']) * 60;	
+			//$main_month_year[date('m-Y', $data['login'])] += calculHours($data['logout'] - $data['login']) * 60;
+			$main_month_year[date('m-Y', $data['login'])] += float_format(($data['logout'] - $data['login'])/60, 0);
+			//$main_day[date('d-m-Y', $data['login'])] += calculHours($data['logout'] - $data['login']) * 60;
+			$main_day[date('d-m-Y', $data['login'])] += float_format(($data['logout'] - $data['login']) / 60, 0);
+		if ($i > 500) {
+			break;
 		}
-		//var_dump($main_month_year);				
-		switch ($type) {
-			case 'day':
+		$i++;
+	}
+	//var_dump($main_month_year);
+	switch ($type) {
+		case 'day':
 			$main_date = $main_day;
 			break;
-			case 'month':
+		case 'month':
 			$main_date = $main_month_year ;						
 			break;
-			case 'year':
+		case 'year':
 			$main_date = $main_year;
 			break;
-		}		
-		//echo '<pre>'; print_r($main_date);
-		
-		// the nice graphics :D
-		$labels = array_keys($main_date);	
-		if (count($main_date)==1) {
-			$labels = $labels[0];
-			$main_date = $main_date[$labels];
-		}
-		
-		$DataSet = new pData;	
-		$DataSet->AddPoint($main_date,'Q');
-		if (count($main_date)!=1) {
-			$DataSet->AddPoint($labels,'Date');
-		}
-		$DataSet->AddAllSeries();  
-		$DataSet->RemoveSerie('Date');  
-		$DataSet->SetAbsciseLabelSerie('Date');
-		$DataSet->SetYAxisName(get_lang('Minutes'));
-		$graph_id = api_get_user_id().'AccessDetails'.api_get_course_id();
-		$DataSet->AddAllSeries();
+	}
+	//echo '<pre>'; print_r($main_date);
+
+	// the nice graphics :D
+	$labels = array_keys($main_date);
+	if (count($main_date) == 1) {
+		$labels = $labels[0];
+		$main_date = $main_date[$labels];
+	}
+
+	$DataSet = new pData;	
+	$DataSet->AddPoint($main_date, 'Q');
+	if (count($main_date)!= 1) {
+		$DataSet->AddPoint($labels, 'Date');
+	}
+	$DataSet->AddAllSeries();  
+	$DataSet->RemoveSerie('Date');  
+	$DataSet->SetAbsciseLabelSerie('Date');
+	$DataSet->SetYAxisName(get_lang('Minutes'));
+	$graph_id = api_get_user_id().'AccessDetails'.api_get_course_id();
+	$DataSet->AddAllSeries();
+
+	$Cache = new pCache();
+	// the graph id
+	$data = $DataSet->GetData();
+
+	if ($Cache->IsInCache($graph_id, $DataSet->GetData())) {
+	//if (0) {
+		//if we already created the img
+		//	echo 'in cache';
+		$img_file = $Cache->GetHash($graph_id, $DataSet->GetData());
+	} else  {
+		// if the image does not exist in the archive/ folder
+		// Initialise the graph  
+		$Test = new pChart(760, 230);
+
+		//which schema of color will be used
+		$quant_resources = count($data[0]) - 1;					
+		// Adding the color schemma
+		$Test->loadColorPalette(api_get_path(LIBRARY_PATH)."pchart/palette/default.txt");
+
+	  	$Test->setFontProperties(api_get_path(LIBRARY_PATH)."pchart/fonts/tahoma.ttf", 8);
+	  	$Test->setGraphArea(70, 30, 680, 200);
+	  	$Test->drawFilledRoundedRectangle(7, 7, 693, 223, 5, 240, 240, 240);
+	  	$Test->drawRoundedRectangle(5, 5, 695, 225, 5, 230, 230, 230);
+	  	$Test->drawGraphArea(255, 255, 255, TRUE);
+	  	$Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_START0, 150, 150, 150, TRUE, 0, 0);
+	  	$Test->drawGrid(4, TRUE, 230, 230, 230, 50);
+	    $Test->setLineStyle(2);
+		// Draw the 0 line
+		$Test->setFontProperties(api_get_path(LIBRARY_PATH)."pchart/fonts/tahoma.ttf", 6);
+		$Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
 		
-		$Cache = new pCache();
-		// the graph id
-		$data = $DataSet->GetData();
+	  	if (count($main_date) == 1) {
+			//Draw a graph 
+			echo '<strong>'.$labels.'</strong><br/>';			
+  			$Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), TRUE);
+	  	} else {
+			//Draw the line graph  
+			$Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());     
+			$Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, 255, 255, 255);
+ 		}
+	  
+		// Finish the graph     
+		$Test->setFontProperties(api_get_path(LIBRARY_PATH)."pchart/fonts/tahoma.ttf", 8);     
+		       
+		$Test->setFontProperties(api_get_path(LIBRARY_PATH)."pchart/fonts/tahoma.ttf", 10);     
+		$Test->drawTitle(60, 22, get_lang('AccessDetails'), 50, 50, 50, 585);    
 		
-		if ($Cache->IsInCache($graph_id, $DataSet->GetData())) {
-		//if (0) {
-			//if we already created the img
-			//	echo 'in cache';
-			$img_file = $Cache->GetHash($graph_id,$DataSet->GetData());			
-		} else  {		  
-		// if the image does not exist in the archive/ folder		
-			// Initialise the graph  
-			$Test = new pChart(760,230);
-			 
-			//which schema of color will be used
-			$quant_resources = count($data[0])-1;					
-			// Adding the color schemma
-			$Test->loadColorPalette(api_get_path(LIBRARY_PATH)."pchart/palette/default.txt");
-									
-		  	$Test->setFontProperties(api_get_path(LIBRARY_PATH)."pchart/fonts/tahoma.ttf",8);     
-		  	$Test->setGraphArea(70,30,680,200);     
-		  	$Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);     
-		  	$Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);     
-		  	$Test->drawGraphArea(255,255,255,TRUE);  
-		  	$Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_START0,150,150,150,TRUE,0,0);     
-		  	$Test->drawGrid(4,TRUE,230,230,230,50);  
-		    $Test->setLineStyle(2); 
-			// Draw the 0 line     
-			$Test->setFontProperties(api_get_path(LIBRARY_PATH)."pchart/fonts/tahoma.ttf",6);     
-			$Test->drawTreshold(0,143,55,72,TRUE,TRUE);
-			
-		  	if (count($main_date)==1) {
-				//Draw a graph 
-				echo '<strong>'.$labels.'</strong><br/>';			
-	  			$Test->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);
-		  	} else {
-				//Draw the line graph  
-				$Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());     
-				$Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);
-	 		}
-		  
-			// Finish the graph     
-			$Test->setFontProperties(api_get_path(LIBRARY_PATH)."pchart/fonts/tahoma.ttf",8);     
-			       
-			$Test->setFontProperties(api_get_path(LIBRARY_PATH)."pchart/fonts/tahoma.ttf",10);     
-			$Test->drawTitle(60,22,get_lang('AccessDetails'),50,50,50,585);    
-			
-			//------------------						
-			//echo 'not in cache';			
-			$Cache->WriteToCache($graph_id,$DataSet->GetData(),$Test);						
-			ob_start();
-			$Test->Stroke();
-			ob_end_clean();				
-			$img_file = $Cache->GetHash($graph_id,$DataSet->GetData());		
-		}
+		//------------------						
+		//echo 'not in cache';			
+		$Cache->WriteToCache($graph_id,$DataSet->GetData(),$Test);						
+		ob_start();
+		$Test->Stroke();
+		ob_end_clean();				
+		$img_file = $Cache->GetHash($graph_id,$DataSet->GetData());		
+	}	
 		echo '<img src="'.api_get_path(WEB_ARCHIVE_PATH).$img_file.'">';
 	} else {
 		Display::display_warning_message (get_lang('GraphicNotAvailable'));
@@ -181,14 +179,14 @@ if (api_is_xml_http_request()) {
 $nameTools= get_lang('AccessDetails');
 
 //StudentDetails
-if (isset($_GET['origin']) && strcmp($_GET['origin'],'tracking_course')===0) {
+if (isset($_GET['origin']) && strcmp($_GET['origin'], 'tracking_course') === 0) {
 	$interbreadcrumb[] = array ("url" => "../tracking/courseLog.php?cidReq=".Security::remove_XSS($_GET['course'])."&amp;studentlist=true&id_session=".api_get_session_id(), "name" => get_lang("Tracking"));
 	$interbreadcrumb[] = array ("url" => "myStudents.php?student=".Security::remove_XSS($_GET['student'])."&details=true&origin=".Security::remove_XSS($_GET['origin'])."&amp;course=".Security::remove_XSS($_GET['course']).'&amp;cidReq='.Security::remove_XSS($_GET['course']), "name" => get_lang('DetailsStudentInCourse'));
-	$interbreadcrumb[] = array ("url" => "#", "name" => get_lang("Details"));
-} elseif (isset($_GET['origin']) && strcmp($_GET['origin'],'user_course')===0) {
+	$interbreadcrumb[] = array ("url" => "javascript: void(0);", "name" => get_lang("Details"));
+} elseif (isset($_GET['origin']) && strcmp($_GET['origin'], 'user_course') === 0) {
 	$interbreadcrumb[] = array ("url" => "../user/user.php?cidReq=".Security::remove_XSS($_GET['course']), "name" => get_lang("Users"));
 	$interbreadcrumb[] = array ("url" => "myStudents.php?student=".Security::remove_XSS($_GET['student'])."&details=true&origin=".Security::remove_XSS($_GET['origin'])."&amp;course=".Security::remove_XSS($_GET['course']).'&amp;cidReq='.Security::remove_XSS($_GET['course']), "name" => get_lang('DetailsStudentInCourse'));
-	$interbreadcrumb[] = array ("url" => "#", "name" => get_lang("Details"));
+	$interbreadcrumb[] = array ("url" => "javascript: void(0);", "name" => get_lang("Details"));
 }
 
 $htmlHeadXtra[] = '<script src="../inc/lib/javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
@@ -205,14 +203,14 @@ $(function() {
 </script>'  ;
 
 Display :: display_header('');
-$TBL_USERINFO_DEF 	= Database :: get_course_table(TABLE_USER_INFO);
+$TBL_USERINFO_DEF 		= Database :: get_course_table(TABLE_USER_INFO);
 $mainUserInfo 		= api_get_user_info($user_id);
 
 $result_to_print = '';
 $main_date_array = array();
 
-foreach ($connections as $key=>$data) { 
-	$result_to_print .= '&nbsp;&nbsp;'.date('d-m-Y (H:i:s)',$data['login']).' - '.calculHours($data['logout']-$data['login']).'<br />'."\n";	
+foreach ($connections as $key => $data) { 
+	$result_to_print .= '&nbsp;&nbsp;'.date('d-m-Y (H:i:s)', $data['login']).' - '.calculHours($data['logout'] - $data['login']).'<br />'."\n";	
 }
 api_display_tool_title(get_lang('DetailsStudentInCourse'));
 echo '<div class="actions">';
@@ -229,18 +227,16 @@ echo '<strong>'.get_lang('User').': '.api_get_person_name($mainUserInfo['firstNa
 <?php
 
 echo '<div id="graph"></div><br />';
-echo '<div class="actions"><strong>',get_lang('DateAndTimeOfAccess'),' - ',get_lang('Duration'),'</strong></div><br />';
+echo '<div class="actions"><strong>', get_lang('DateAndTimeOfAccess'), ' - ', get_lang('Duration'), '</strong></div><br />';
 echo $result_to_print;
 
 /* Login time against logout time
-foreach ($connections as $key=>$data)
-{
+foreach ($connections as $key => $data) {
     echo ("<tr><td>".date("d-m-Y (H:i:s)",$data['login'])."</td><td>".date("d-m-Y (H:i:s)",$data['logout'])."</td></tr>"); 
 }
 */
 /*
-foreach ($connections as $key=>$data)
-{
+foreach ($connections as $key => $data) {
     echo ("<tr><td>".date("d-m-Y (H:i:s)",$data['login'])."</td><td>".calculHours($data['logout']-$data['login'])."</td></tr>"); 
 }
 echo ("</table>");
@@ -266,30 +262,28 @@ function get_connections_to_course($user_id, $course_code) {
     $tbl_track_course 	= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
     $tbl_main			= Database :: get_main_table(TABLE_MAIN_COURSE);
     
-    $sql_query='SELECT visual_code as course_code FROM '.$tbl_main.' c WHERE code="'.Database::escape_string($course_code).'";';
-    $result=api_sql_query($sql_query,__FILE__,__LINE__);
-    $row_query=Database::fetch_array($result,'ASSOC');
-    $course_true=isset($row_query['course_code']) ? $row_query['course_code']: $course_code;
+    $sql_query = 'SELECT visual_code as course_code FROM '.$tbl_main.' c WHERE code="'.Database::escape_string($course_code).'";';
+    $result = Database::query($sql_query, __FILE__, __LINE__);
+    $row_query = Database::fetch_array($result,'ASSOC');
+    $course_true = isset($row_query['course_code']) ? $row_query['course_code']: $course_code;
 
     $sql = 'SELECT login_course_date, logout_course_date FROM ' . $tbl_track_course . ' 
-    				WHERE user_id = ' . intval($user_id) . '
-    				AND course_code="' . Database::escape_string($course_true) . '" ORDER BY login_course_date ASC';
+    	WHERE user_id = ' . intval($user_id) . '
+    	AND course_code="' . Database::escape_string($course_true) . '" ORDER BY login_course_date ASC';
+
+    $rs = Database::query($sql, __FILE__, __LINE__);
+    $connections = array();
 
-    $rs = api_sql_query($sql);
-    $connections  = array();
-    
     while ($a_connections = Database::fetch_array($rs)) {
-    
+
         $s_login_date = $a_connections['login_course_date'];
         $s_logout_date = $a_connections['logout_course_date'];
-        
+
         $i_timestamp_login_date = strtotime($s_login_date);
         $i_timestamp_logout_date = strtotime($s_logout_date);
-        
-        $connections[] = array('login'=>$i_timestamp_login_date, 'logout'=>$i_timestamp_logout_date);
-        
+
+        $connections[] = array('login' => $i_timestamp_login_date, 'logout' => $i_timestamp_logout_date);
     }
-    
     return $connections;
 }
 
@@ -303,56 +297,54 @@ function get_connections_to_course($user_id, $course_code) {
  * @param unknown_type $day
  * @return unknown
  */
-function get_connections_to_course_by_time($user_id, $course_code, $year='', $month='', $day='') {
+function get_connections_to_course_by_time($user_id, $course_code, $year = '', $month = '', $day = '') {
 	// Database table definitions
     $tbl_track_course 		= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
     $tbl_main				= Database :: get_main_table(TABLE_MAIN_COURSE);
-    
-    $sql_query='SELECT visual_code as course_code FROM '.$tbl_main.' c WHERE code="'.Database :: escape_string($course_code).'";';
-    $result=api_sql_query($sql_query,__FILE__,__LINE__);
-    $row_query=Database::fetch_array($result,'ASSOC');
-    $course_true=isset($row_query['course_code']) ? $row_query['course_code']: $course_code;
+
+    $sql_query = 'SELECT visual_code as course_code FROM '.$tbl_main.' c WHERE code="'.Database :: escape_string($course_code).'";';
+    $result = Database::query($sql_query, __FILE__, __LINE__);
+    $row_query = Database::fetch_array($result,'ASSOC');
+    $course_true = isset($row_query['course_code']) ? $row_query['course_code']: $course_code;
 
     $sql = 'SELECT login_course_date, logout_course_date FROM ' . $tbl_track_course . ' 
     				WHERE user_id = ' . intval($user_id) . '
     				AND course_code="' . Database::escape_string($course_true) . '"    				 
     				ORDER BY login_course_date DESC';
-    
-    $rs = api_sql_query($sql);
+
+    $rs = Database::query($sql, __FILE__, __LINE__);
     $connections  = array();    
     while ($a_connections = Database::fetch_array($rs)) {    
         $s_login_date 				= $a_connections['login_course_date'];
         $s_logout_date 				= $a_connections['logout_course_date'];        
         $i_timestamp_login_date 	= strtotime($s_login_date);
         $i_timestamp_logout_date 	= strtotime($s_logout_date);        
-        $connections[] = array('login'=>$i_timestamp_login_date, 'logout'=>$i_timestamp_logout_date);        
+        $connections[] = array('login' => $i_timestamp_login_date, 'logout' => $i_timestamp_logout_date);        
     }    
     return $connections;
 }
 
-	
 /**
  * Transforms seconds into a time format
  *
  * @param unknown_type $seconds
  * @return unknown
  */
-function calculHours($seconds)
-{	
-  //How many hours ?
-  $hours = floor($seconds / 3600);
-
-  //How many minutes ?
-  $min = floor(($seconds - ($hours * 3600)) / 60);
-  if ($min < 10)
-    $min = '0'.$min;
-
-  //How many seconds
-  $sec = $seconds - ($hours * 3600) - ($min * 60);
-  if ($sec < 10)
-    $sec = '0'.$sec;
+function calculHours($seconds) {	
+	//How many hours ?
+	$hours = floor($seconds / 3600);
+
+	//How many minutes ?
+	$min = floor(($seconds - ($hours * 3600)) / 60);
+	if ($min < 10) {
+		$min = '0'.$min;
+	}
 
-  return $hours.get_lang('HourShort').' '.$min.':'.$sec;
+	//How many seconds
+	$sec = $seconds - ($hours * 3600) - ($min * 60);
+	if ($sec < 10) {
+    	$sec = '0'.$sec;
+	}
 
+	return $hours.get_lang('HourShort').' '.$min.':'.$sec;
 }
-?>

+ 3 - 3
main/mySpace/admin.php

@@ -90,7 +90,7 @@ if (isset($_POST['export'])) {
 $sqlAdmins = "SELECT user.user_id,lastname,firstname,email
 				FROM $tbl_user as user, $tbl_admin as admin
 				WHERE admin.user_id=user.user_id".$order_clause;
-$resultAdmins = api_sql_query($sqlAdmins, __FILE__, __LINE__);
+$resultAdmins = Database::query($sqlAdmins, __FILE__, __LINE__);
 
 if (api_is_western_name_order()) {
 	echo '<table class="data_table"><tr><th>'.get_lang('FirstName').'</th><th>'.get_lang('LastName').'</th><th>'.get_lang('Email').'</th></tr>';
@@ -108,8 +108,8 @@ if (api_is_western_name_order(PERSON_NAME_DATA_EXPORT)) {
 	$a_header[] = get_lang('Email');
 }
 
-if (mysql_num_rows($resultAdmins) > 0 ) {
-	while($a_admins = mysql_fetch_array($resultAdmins)){
+if (Database::num_rows($resultAdmins) > 0 ) {
+	while ($a_admins = Database::fetch_array($resultAdmins)) {
 
 		$i_user_id = $a_admins["user_id"];
 		$s_lastname = $a_admins["lastname"];

+ 12 - 12
main/mySpace/coaches.php

@@ -101,8 +101,8 @@ function calculHours($seconds) {
 function is_coach() {
   	global $tbl_session_course;
 	$sql = "SELECT course_code FROM $tbl_session_course WHERE id_coach='".$_SESSION["_uid"]."'";
-	$result = api_sql_query($sql, __FILE__, __LINE__);
-	if (mysql_num_rows($result) > 0) {
+	$result = Database::query($sql, __FILE__, __LINE__);
+	if (Database::num_rows($result) > 0) {
 		return true;	    
 	}	else {
 		return false;
@@ -136,7 +136,7 @@ if (isset($_GET["id_student"])) {
 			AND session_rel_course.id_coach=user.user_id".$order_clause;
 	}
 }
-$resultCoachs = api_sql_query($sqlCoachs, __FILE__, __LINE__);
+$resultCoachs = Database::query($sqlCoachs, __FILE__, __LINE__);
 
 if (api_is_western_name_order()) {
 	echo '<table class="data_table"><tr><th>'.get_lang('FirstName').'</th><th>'.get_lang('LastName').'</th><th>'.get_lang('ConnectionTime').'</th><th>'.get_lang('AdminCourses').'</th><th>'.get_lang('Students').'</th></tr>';
@@ -154,25 +154,25 @@ if (api_is_western_name_order(PERSON_NAME_DATA_EXPORT)) {
 	$a_header[] = get_lang('ConnectionTime');
 }
 
-if (mysql_num_rows($resultCoachs) > 0) {
-	while ($a_coachs = mysql_fetch_array($resultCoachs)) {
+if (Database::num_rows($resultCoachs) > 0) {
+	while ($a_coachs = Database::fetch_array($resultCoachs)) {
 		$i_id_coach=$a_coachs["id_coach"];
 
-		if(isset($_GET["id_student"])){
+		if (isset($_GET["id_student"])) {
 			$sql_infos_coach = "SELECT lastname, firstname FROM $tbl_user WHERE user_id='$i_id_coach'";
-			$resultCoachsInfos = api_sql_query($sql_infos_coach);
-			$s_lastname = mysql_result($resultCoachsInfos,0,"lastname");
-			$s_firstname = mysql_result($resultCoachsInfos,0,"firstname");
+			$resultCoachsInfos = Database::query($sql_infos_coach, __FILE__, __LINE__);
+			$s_lastname = Database::result($resultCoachsInfos, 0, "lastname");
+			$s_firstname = Database::result($resultCoachsInfos, 0, "firstname");
 		} else {
 			$s_lastname = $a_coachs["lastname"];
 			$s_firstname = $a_coachs["firstname"];
 		}
 
 		$s_sql_connection_time = "SELECT login_date, logout_date FROM $tbl_track_login WHERE login_user_id ='$i_id_coach' AND logout_date <> 'null'";
-		$q_result_connection_time = api_sql_query($s_sql_connection_time);
+		$q_result_connection_time = Database::query($s_sql_connection_time, __FILE__, __LINE__);
 
-		$i_nb_seconds=0;
-		while($a_connections = mysql_fetch_array($q_result_connection_time)) {
+		$i_nb_seconds = 0;
+		while($a_connections = Database::fetch_array($q_result_connection_time)) {
 			$s_login_date = $a_connections["login_date"];
 			$s_logout_date = $a_connections["logout_date"];
 			$i_timestamp_login_date = strtotime($s_login_date);

+ 64 - 81
main/mySpace/course.php

@@ -2,59 +2,53 @@
 /*
  * Created on 28 juil. 2006 by Elixir Interactive http://www.elixir-interactive.com
  */
- ob_start();
- $nameTools= 'Cours';
- // name of the language file that needs to be included 
-$language_file = array ('admin','registration', 'index','trad4all', 'tracking');
- $cidReset=true;
- require ('../inc/global.inc.php');
- require_once (api_get_path(LIBRARY_PATH).'tracking.lib.php');
- require_once (api_get_path(LIBRARY_PATH).'export.lib.inc.php');
- require_once (api_get_path(LIBRARY_PATH).'course.lib.php');
- 
- $this_section = "session_my_space";
- $id_session = intval($_GET['id_session']);
+ob_start();
+$nameTools = 'Cours';
+// name of the language file that needs to be included 
+$language_file = array ('admin', 'registration', 'index', 'trad4all', 'tracking');
+$cidReset = true;
+require '../inc/global.inc.php';
+require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
+require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
+require_once api_get_path(LIBRARY_PATH).'course.lib.php';
+
+$this_section = "session_my_space";
+$id_session = intval($_GET['id_session']);
 
- api_block_anonymous_users();
- $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
- 
- if(isset($_GET["id_session"]) && $_GET["id_session"]!=""){
+api_block_anonymous_users();
+$interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
+
+if(isset($_GET["id_session"]) && $_GET["id_session"]!=""){
 	$interbreadcrumb[] = array ("url" => "session.php", "name" => get_lang('Sessions'));
- }
- 
- if(isset($_GET["user_id"]) && $_GET["user_id"]!="" && isset($_GET["type"]) && $_GET["type"]=="coach"){
- 	 $interbreadcrumb[] = array ("url" => "coaches.php", "name" => get_lang('Tutors'));
- }
- 
- if(isset($_GET["user_id"]) && $_GET["user_id"]!="" && isset($_GET["type"]) && $_GET["type"]=="student"){
- 	 $interbreadcrumb[] = array ("url" => "student.php", "name" => get_lang('Students'));
- }
- 
- if(isset($_GET["user_id"]) && $_GET["user_id"]!="" && !isset($_GET["type"])){
- 	 $interbreadcrumb[] = array ("url" => "teachers.php", "name" => get_lang('Teachers'));
- }
- 
+}
+
+if(isset($_GET["user_id"]) && $_GET["user_id"]!="" && isset($_GET["type"]) && $_GET["type"]=="coach"){
+	 $interbreadcrumb[] = array ("url" => "coaches.php", "name" => get_lang('Tutors'));
+}
 
-function count_courses()
-{
+if(isset($_GET["user_id"]) && $_GET["user_id"]!="" && isset($_GET["type"]) && $_GET["type"]=="student"){
+	 $interbreadcrumb[] = array ("url" => "student.php", "name" => get_lang('Students'));
+}
+
+if(isset($_GET["user_id"]) && $_GET["user_id"]!="" && !isset($_GET["type"])){
+	 $interbreadcrumb[] = array ("url" => "teachers.php", "name" => get_lang('Teachers'));
+}
+
+function count_courses() {
 	global $nb_courses;
 	return $nb_courses;
 }
- //checking if the current coach is the admin coach
-$show_import_icon=false;
+
+//checking if the current coach is the admin coach
+$show_import_icon = false;
 
-if (api_get_setting('add_users_by_coach')=='true')
-{
-	if(!api_is_platform_admin())
-	{
+if (api_get_setting('add_users_by_coach') == 'true') {
+	if (!api_is_platform_admin()) {
 		$sql = 'SELECT id_coach FROM '.Database :: get_main_table(TABLE_MAIN_SESSION).' WHERE id='.$id_session;
-		$rs = api_sql_query($sql,__FILE__,__LINE__);
-		if(Database::result($rs,0,0)!=$_user['user_id'])	
-		{
+		$rs = Database::query($sql,__FILE__,__LINE__);
+		if (Database::result($rs, 0, 0) != $_user['user_id']) {
 			api_not_allowed(true);  
-		}
-		else
-		{
+		} else {
 			$show_import_icon=true;	
 		}
 	}
@@ -62,7 +56,6 @@ if (api_get_setting('add_users_by_coach')=='true')
 
 Display :: display_header($nameTools);
 
-
 // Database Table Definitions 
 $tbl_course 				= Database :: get_main_table(TABLE_MAIN_COURSE);
 $tbl_user_course 			= Database :: get_main_table(TABLE_MAIN_COURSE_USER);
@@ -71,21 +64,17 @@ $tbl_session_course 		= Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
 $tbl_session 				= Database :: get_main_table(TABLE_MAIN_SESSION);
 $tbl_session_course_user 	= Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  
-if (isset($_GET['action']))
-{
-	if ($_GET['action']=='show_message') 
-	{
+if (isset($_GET['action'])) {
+	if ($_GET['action'] == 'show_message') {
 		Display :: display_normal_message(stripslashes($_GET['message']),false);
 	}
-	
-	if ($_GET['action']=='error_message') 
-	{
+
+	if ($_GET['action'] == 'error_message') {
 		Display :: display_error_message(stripslashes($_GET['message']),false);
 	}
 }			
 
-if ($show_import_icon)
-{
+if ($show_import_icon) {
 	echo "<div align=\"right\">";
 	echo '<a href="user_import.php?id_session='.$id_session.'&action=export&amp;type=xml">'.Display::return_icon('excel.gif', get_lang('ImportUserListXMLCSV')).'&nbsp;'.get_lang('ImportUserListXMLCSV').'</a>';
 	echo "</div><br />";
@@ -114,29 +103,26 @@ $csv_content[] = array(
 				//get_lang('AvgExercisesScore'),
 				get_lang('AvgMessages'),
 				get_lang('AvgAssignments')
-				);
+			);
 if (is_array($a_courses)) {
-	foreach($a_courses as $course_code) {
+	foreach ($a_courses as $course_code) {
 		$nb_students_in_course = 0;
 		$a_students = array();
 		$course = CourseManager :: get_course_information($course_code);
 		$avg_assignments_in_course = $avg_messages_in_course = $avg_progress_in_course = $avg_score_in_course = $avg_time_spent_in_course = 0;
-		
+
 		// students subscribed to the course throw a session
-		if(api_get_setting('use_session_mode') == 'true')
-		{
+		if (api_get_setting('use_session_mode') == 'true') {
 			$sql = 'SELECT id_user as user_id
 					FROM '.$tbl_session_course_user.'
 					WHERE course_code="'.Database :: escape_string($course_code).'"
 					AND id_session='.$id_session;
-			$rs = api_sql_query($sql, __FILE__, __LINE__);
+			$rs = Database::query($sql, __FILE__, __LINE__);
 			
-			while($row = mysql_fetch_array($rs))
-			{
-				if(!in_array($row['user_id'], $a_students))
-				{
+			while ($row = Database::fetch_array($rs)) {
+				if (!in_array($row['user_id'], $a_students)) {
 					$nb_students_in_course++;
-					
+
 					// tracking datas
 					$avg_progress_in_course += Tracking :: get_avg_student_progress ($row['user_id'], $course_code);
 					$avg_score_in_course += Tracking :: get_avg_student_score ($row['user_id'], $course_code);
@@ -147,15 +133,14 @@ if (is_array($a_courses)) {
 				}
 			}
 		}
-		if($nb_students_in_course>0)
-		{
+		if ($nb_students_in_course > 0) {
 			$avg_time_spent_in_course = api_time_to_hms($avg_time_spent_in_course / $nb_students_in_course);
-			$avg_progress_in_course = round($avg_progress_in_course / $nb_students_in_course,2).' %';
-			$avg_score_in_course = round($avg_score_in_course / $nb_students_in_course,2).' %';
-			$avg_messages_in_course = round($avg_messages_in_course / $nb_students_in_course,2);
-			$avg_assignments_in_course = round($avg_assignments_in_course / $nb_students_in_course,2);
+			$avg_progress_in_course = round($avg_progress_in_course / $nb_students_in_course, 2).' %';
+			$avg_score_in_course = round($avg_score_in_course / $nb_students_in_course, 2).' %';
+			$avg_messages_in_course = round($avg_messages_in_course / $nb_students_in_course, 2);
+			$avg_assignments_in_course = round($avg_assignments_in_course / $nb_students_in_course, 2);
 		}
-		
+
 		$table_row = array();
 		$table_row[] = $course['title'];
 		$table_row[] = $nb_students_in_course;
@@ -165,7 +150,7 @@ if (is_array($a_courses)) {
 		$table_row[] = $avg_messages_in_course;
 		$table_row[] = $avg_assignments_in_course;
 		$table_row[] = '<a href="../tracking/courseLog.php?cidReq='.$course_code.'&studentlist=true&id_session='.$id_session.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
-		
+
 		$csv_content[] = array(
 							$course['title'],
 							$nb_students_in_course,
@@ -174,21 +159,19 @@ if (is_array($a_courses)) {
 							$avg_score_in_course,
 							$avg_messages_in_course,
 							$avg_assignments_in_course,
-							);
-		
+						);
+
 		$table -> addRow($table_row, 'align="right"');	
 	}
 }
-$table -> setColAttributes(0,array('align'=>'left'));
-$table -> setColAttributes(7,array('align'=>'center'));
+$table -> setColAttributes(0, array('align'=>'left'));
+$table -> setColAttributes(7, array('align'=>'center'));
 $table -> display();
-	
- 
+
 /*
  ==============================================================================
 		FOOTER
  ==============================================================================
  */
 
- Display :: display_footer();
-?>
+Display :: display_footer();

File diff suppressed because it is too large
+ 253 - 351
main/mySpace/index.php


+ 50 - 58
main/mySpace/lp_tracking.php

@@ -9,7 +9,7 @@
 $language_file = array ('registration', 'index', 'tracking', 'exercice', 'scorm', 'learnpath');
 //$cidReset = true;
 
-include ('../inc/global.inc.php');
+include '../inc/global.inc.php';
 
 $from_myspace = false;
 $from_link = '';
@@ -19,16 +19,16 @@ if (isset($_GET['from']) && $_GET['from'] == 'myspace') {
 } else {
 	$this_section = SECTION_COURSES;
 }
-include_once(api_get_path(LIBRARY_PATH).'tracking.lib.php');
-include_once(api_get_path(LIBRARY_PATH).'export.lib.inc.php');
-include_once(api_get_path(LIBRARY_PATH).'course.lib.php');
-include_once(api_get_path(LIBRARY_PATH).'usermanager.lib.php');
-include_once('../newscorm/learnpath.class.php');
-include_once('../newscorm/learnpathItem.class.php');
-require_once (api_get_path(LIBRARY_PATH).'export.lib.inc.php');
+include_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
+include_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
+include_once api_get_path(LIBRARY_PATH).'course.lib.php';
+include_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
+include_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
+include_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathItem.class.php';
+require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
 
 $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
-if($export_csv) {
+if ($export_csv) {
 	ob_start();
 }
 $csv_content = array();
@@ -41,7 +41,7 @@ if (isset($_GET['course'])) {
 $user_infos = UserManager :: get_user_info_by_id($user_id);
 $name = $user_infos['firstname'].' '.$user_infos['lastname'];
 
-if(!api_is_platform_admin(true) && !CourseManager :: is_course_teacher($_user['user_id'], $cidReq) && !Tracking :: is_allowed_to_coach_student($_user['user_id'],$_GET['student_id']) && $user_infos['hr_dept_id']!==$_user['user_id']) {
+if (!api_is_platform_admin(true) && !CourseManager :: is_course_teacher($_user['user_id'], $cidReq) && !Tracking :: is_allowed_to_coach_student($_user['user_id'],$_GET['student_id']) && $user_infos['hr_dept_id']!==$_user['user_id']) {
 	Display::display_header('');
 	api_not_allowed();
 	Display::display_footer();
@@ -57,7 +57,7 @@ if (!empty($course_exits)) {
 
 $_course['dbNameGlu'] = $_configuration['table_prefix'] . $_course['db_name'] . $_configuration['db_glue'];
 
-if(!empty($_GET['origin']) && $_GET['origin'] == 'user_course') {
+if (!empty($_GET['origin']) && $_GET['origin'] == 'user_course') {
 	$interbreadcrumb[] = array ("url" => api_get_path(WEB_COURSE_PATH).$_course['directory'], 'name' => $_course['title']);
 	$interbreadcrumb[] = array ("url" => "../user/user.php?cidReq=".$cidReq, "name" => get_lang("Users"));
 } else if(!empty($_GET['origin']) && $_GET['origin'] == 'tracking_course') {
@@ -88,49 +88,42 @@ div.description {
 	font-size: 10px;
 	color: Silver;
 }
- .data_table
-  {
-  	border-collapse: collapse;
-  }
- .data_table th{
+
+.data_table {
+	border-collapse: collapse;
+}
+.data_table th {
 	padding-right: 0px;
-  	border: 1px  solid gray;
-  	background-color: #eef;
-  }
-  .data_table tr.row_odd
-  {
-  	background-color: #fafafa;
-  }
-  .data_table tr.row_odd:hover, .data_table tr.row_even:hover
-  {
-  	background-color: #f0f0f0;
-  }
-  .data_table tr.row_even
-  {
-  	background-color: #fff;
-  }
- .data_table td
-  {
-  	padding: 5px;
+	border: 1px  solid gray;
+	background-color: #eef;
+}
+.data_table tr.row_odd {
+	background-color: #fafafa;
+}
+.data_table tr.row_odd:hover, .data_table tr.row_even:hover {
+	background-color: #f0f0f0;
+}
+.data_table tr.row_even {
+	background-color: #fff;
+}
+.data_table td {
+	padding: 5px;
 	vertical-align: top;
-  	border-bottom: 1px solid #b1b1b1;
-  	border-right: 1px dotted #e1e1e1; 
-  	border-left: 1px dotted #e1e1e1;
- }
+	border-bottom: 1px solid #b1b1b1;
+	border-right: 1px dotted #e1e1e1; 
+	border-left: 1px dotted #e1e1e1;
+}
 
- .margin_table
- {
+.margin_table {
 	margin-left : 3px;
-        width: 80%;
- }
- .margin_table td.title
- {
-    background-color: #ffff99;
- }
- .margin_table td.content
- {
-    background-color: #ddddff;
- }
+	width: 80%;
+}
+.margin_table td.title {
+	background-color: #ffff99;
+}
+.margin_table td.content {
+	background-color: #ddddff;
+}
 </style>';
 
 Display :: display_header($nameTools);
@@ -138,29 +131,28 @@ Display :: display_header($nameTools);
 $lp_id = intval($_GET['lp_id']);
 
 $sql = 'SELECT name 
-		FROM '.Database::get_course_table(TABLE_LP_MAIN, $_course['db_name']).'
-		WHERE id='.Database::escape_string($lp_id);
-$rs = api_sql_query($sql, __FILE__, __LINE__);
+	FROM '.Database::get_course_table(TABLE_LP_MAIN, $_course['db_name']).'
+	WHERE id='.Database::escape_string($lp_id);
+$rs = Database::query($sql, __FILE__, __LINE__);
 $lp_title = Database::result($rs, 0, 0);	
 
 echo '<div class ="actions"><div align="left" style="float:left;margin-top:2px;" ><strong>'.$_course['title'].' - '.$lp_title.' - '.$name.'</strong></div>
 	  <div  align="right">
-			<a href="#" onclick="window.print()"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a>
+			<a href="javascript: void(0);" onclick="javascript: window.print();"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a>
 			<a href="'.api_get_self().'?export=csv&'.Security::remove_XSS($_SERVER['QUERY_STRING']).'"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsCSV').'</a>
 		 </div></div>
 	<div class="clear"></div>';
 
 $list = learnpath :: get_flat_ordered_items_list($lp_id);
 $origin = 'tracking';
-if($export_csv) {	
-	include_once('../newscorm/lp_stats.php');	
+if ($export_csv) {	
+	include_once api_get_path(SYS_CODE_PATH).'newscorm/lp_stats.php';	
 	//Export :: export_table_csv($csv_content, 'reporting_student');
 } else {
 	ob_start();
-	include_once('../newscorm/lp_stats.php');
+	include_once  api_get_path(SYS_CODE_PATH).'newscorm/lp_stats.php';
 	$tracking_content = ob_get_contents();
 	ob_end_clean();
 	echo api_utf8_decode($tracking_content, $charset);
 }
 Display :: display_footer();
-?>

+ 28 - 31
main/mySpace/myStudents.php

@@ -7,29 +7,23 @@
  */
 
 // name of the language file that needs to be included 
-$language_file = array (
-	'registration',
-	'index',
-	'tracking',
-	'exercice',
-	'admin'
-);
+$language_file = array('registration', 'index', 'tracking', 'exercice', 'admin');
 //$cidReset=true;
 require '../inc/global.inc.php';
 require_once api_get_path(LIBRARY_PATH) . 'tracking.lib.php';
 require_once api_get_path(LIBRARY_PATH) . 'export.lib.inc.php';
 require_once api_get_path(LIBRARY_PATH) . 'usermanager.lib.php';
 require_once api_get_path(LIBRARY_PATH) . 'course.lib.php';
-require_once '../newscorm/learnpath.class.php';
+require_once  api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
 
 $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 + \'\');		
 }
-				
+
 </script>';
 
 $export_csv = isset ($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
@@ -175,23 +169,24 @@ function calculHours($seconds) {
 
 	//How many minutes ?
 	$min = floor(($seconds - ($hours * 3600)) / 60);
-	if ($min < 10)
+	if ($min < 10) {
 		$min = "0" . $min;
+	}
 
 	//How many seconds
 	$sec = $seconds - ($hours * 3600) - ($min * 60);
-	if ($sec < 10)
+	if ($sec < 10) {
 		$sec = "0" . $sec;
+	}
 
 	return $hours . "h" . $min . "m" . $sec . "s";
-
 }
 
 function is_teacher($course_code) {
 	global $_user;
 	$tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
 	$sql = "SELECT 1 FROM $tbl_course_user WHERE user_id='" . $_user["user_id"] . "' AND course_code='" . Database :: escape_string($course_code) . "' AND status='1'";
-	$result = api_sql_query($sql, __FILE__, __LINE__);
+	$result = Database::query($sql, __FILE__, __LINE__);
 	if (Database :: result($result) != 1) {
 		return true;
 	} else {
@@ -276,7 +271,7 @@ if (!empty ($_GET['student'])) {
 
 	$avg_student_progress = $avg_student_score = $nb_courses = 0;
 	$sql = 'SELECT course_code FROM ' . $tbl_course_user . ' WHERE user_id=' . Database :: escape_string($a_infosUser['user_id']);
-	$rs = api_sql_query($sql, __FILE__, __LINE__);
+	$rs = Database::query($sql, __FILE__, __LINE__);
 	$a_courses = array ();
 	while ($row = Database :: fetch_array($rs)) {
 		$a_courses[$row['course_code']] = $row['course_code'];
@@ -284,7 +279,7 @@ if (!empty ($_GET['student'])) {
 
 	// get the list of sessions where the user is subscribed as student
 	$sql = 'SELECT DISTINCT course_code FROM ' . Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER) . ' WHERE id_user=' . intval($a_infosUser['user_id']);
-	$rs = api_sql_query($sql, __FILE__, __LINE__);
+	$rs = Database::query($sql, __FILE__, __LINE__);
 	while ($row = Database :: fetch_array($rs)) {
 		$a_courses[$row['course_code']] = $row['course_code'];
 	}
@@ -536,7 +531,7 @@ if (!empty ($_GET['student'])) {
 										WHERE session_course_user.id_user = ' . intval($a_infosUser['user_id']) . '
 										AND session_course_user.course_code = "' . Database :: escape_string($course_code_info) . '"
 										ORDER BY id_session DESC';
-			$rs = api_sql_query($sql, __FILE__, __LINE__);
+			$rs = Database::query($sql, __FILE__, __LINE__);
 			$num_row = Database :: num_rows($rs);
 			if ($num_row > 0) {
 				$le_session_id = intval(Database :: result($rs, 0, 0));
@@ -544,7 +539,7 @@ if (!empty ($_GET['student'])) {
 					// get session name and coach of the session
 					$sql = 'SELECT name, id_coach FROM ' . $tbl_session . ' 
 														WHERE id=' . $le_session_id;
-					$rs = api_sql_query($sql, __FILE__, __LINE__);
+					$rs = Database::query($sql, __FILE__, __LINE__);
 					$session_name = Database :: result($rs, 0, 'name');
 					$session_coach_id = intval(Database :: result($rs, 0, 'id_coach'));
 
@@ -552,7 +547,7 @@ if (!empty ($_GET['student'])) {
 					$sql = 'SELECT id_coach FROM ' . $tbl_session_course . ' 
 														WHERE id_session=' . $le_session_id . '
 														AND course_code = "' . Database :: escape_string($_GET['course']) . '"';
-					$rs = api_sql_query($sql, __FILE__, __LINE__);
+					$rs = Database::query($sql, __FILE__, __LINE__);
 					$session_course_coach_id = intval(Database :: result($rs, 0, 0));
 
 					if ($session_course_coach_id != 0) {
@@ -665,7 +660,7 @@ if (!empty ($_GET['student'])) {
 										FROM $t_lp AS lp ORDER BY lp.name ASC
 									";
 
-		$resultLearnpath = api_sql_query($sqlLearnpath, __FILE__, __LINE__);
+		$resultLearnpath = Database::query($sqlLearnpath, __FILE__, __LINE__);
 
 		$csv_content[] = array ();
 		$csv_content[] = array (
@@ -694,7 +689,7 @@ if (!empty ($_GET['student'])) {
 													ON item_view.lp_view_id = view.id
 													AND view.lp_id = ' . $a_learnpath['id'] . '
 													AND view.user_id = ' . intval($_GET['student']);
-				$rs = api_sql_query($sql, __FILE__, __LINE__);
+				$rs = Database::query($sql, __FILE__, __LINE__);
 				$total_time = 0;
 				if (Database :: num_rows($rs) > 0) {
 					$total_time = Database :: result($rs, 0, 0);
@@ -709,7 +704,7 @@ if (!empty ($_GET['student'])) {
 													ON item_view.lp_view_id = view.id
 													AND view.lp_id = ' . $a_learnpath['id'] . '
 													AND view.user_id = ' . intval($_GET['student']);
-				$rs = api_sql_query($sql, __FILE__, __LINE__);
+				$rs = Database::query($sql, __FILE__, __LINE__);
 				$start_time = null;
 				if (Database :: num_rows($rs) > 0) {
 					$start_time = Database :: result($rs, 0, 0);
@@ -837,7 +832,7 @@ if (!empty ($_GET['student'])) {
 		$t_tool = Database :: get_course_table(TABLE_TOOL_LIST, $a_infosCours['db_name']);
 		$sql = 'SELECT visibility FROM ' . $t_tool . ' WHERE name="quiz"';
 
-		$resultVisibilityQuizz = api_sql_query($sql, __FILE__, __LINE__);
+		$resultVisibilityQuizz = Database::query($sql, __FILE__, __LINE__);
 		$t_quiz = Database :: get_course_table(TABLE_QUIZ_TEST, $a_infosCours['db_name']);
 
 		if (Database :: result($resultVisibilityQuizz, 0, 'visibility') == 1) {
@@ -847,7 +842,7 @@ if (!empty ($_GET['student'])) {
 												WHERE active='1' ORDER BY quiz.title ASC
 												";
 
-			$resultExercices = api_sql_query($sqlExercices, __FILE__, __LINE__);
+			$resultExercices = Database::query($sqlExercices, __FILE__, __LINE__);
 			$i = 0;
 			$is_student = Security :: remove_XSS($_GET['student']);
 			if (Database :: num_rows($resultExercices) > 0) {
@@ -859,7 +854,7 @@ if (!empty ($_GET['student'])) {
 															AND orig_lp_id = 0
 															AND orig_lp_item_id = 0				
 															AND exe_user_id='" . Database :: escape_string($is_student) . "'";
-					$resultEssais = api_sql_query($sqlEssais, __FILE__, __LINE__);
+					$resultEssais = Database::query($sqlEssais, __FILE__, __LINE__);
 					$a_essais = Database :: fetch_array($resultEssais);
 
 					$sqlScore = "SELECT exe_id, exe_result,exe_weighting
@@ -871,7 +866,7 @@ if (!empty ($_GET['student'])) {
 														 AND orig_lp_item_id = 0
 														 ORDER BY exe_date DESC LIMIT 1";
 
-					$resultScore = api_sql_query($sqlScore, __FILE__, __LINE__);
+					$resultScore = Database::query($sqlScore, __FILE__, __LINE__);
 					$score = 0;
 					while ($a_score = Database :: fetch_array($resultScore)) {
 						$score = $score + $a_score['exe_result'];
@@ -882,6 +877,8 @@ if (!empty ($_GET['student'])) {
 					if ($weighting != 0) {
 						//i.e 10.50 
 						$pourcentageScore = round(($score * 100) / $weighting, 2);
+					} else {
+						$pourcentageScore = null;
 					}
 
 					$weighting = 0;
@@ -924,7 +921,7 @@ if (!empty ($_GET['student'])) {
 												 ";
 
 					$sql_last_attempt = 'SELECT exe_id FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $a_exercices['id'] . '" AND exe_user_id="' . Security :: remove_XSS($_GET['student']) . '" AND exe_cours_id="' . $a_infosCours['code'] . '" AND orig_lp_id = 0 AND orig_lp_item_id = 0 ORDER BY exe_date DESC LIMIT 1';
-					$resultLastAttempt = api_sql_query($sql_last_attempt, __FILE__, __LINE__);
+					$resultLastAttempt = Database::query($sql_last_attempt, __FILE__, __LINE__);
 					if (Database :: num_rows($resultLastAttempt) > 0) {
 						$id_last_attempt = Database :: result($resultLastAttempt, 0, 0);
 
@@ -1154,14 +1151,14 @@ if (!empty ($_GET['student'])) {
 											ON qrq.question_id = qq.id
 											AND qrq.exercice_id = " . intval($_GET['exe_id']);
 
-		$resultExerciceDetails = api_sql_query($sqlExerciceDetails, __FILE__, __LINE__);
+		$resultExerciceDetails = Database::query($sqlExerciceDetails, __FILE__, __LINE__);
 
 		$sqlExName = "	SELECT quiz.title
 								FROM " . $t_q . " AS quiz
 							 	WHERE quiz.id = " . intval($_GET['exe_id']);
 		;
 
-		$resultExName = api_sql_query($sqlExName, __FILE__, __LINE__);
+		$resultExName = Database::query($sqlExName, __FILE__, __LINE__);
 		$a_exName = Database :: fetch_array($resultExName);
 
 		echo "<table class='data_table'>
@@ -1177,7 +1174,7 @@ if (!empty ($_GET['student'])) {
 										FROM  " . $t_qa . " as qa
 										WHERE qa.question_id = " . $a_exerciceDetails['id'];
 
-			$resultAnswer = api_sql_query($sqlAnswer, __FILE__, __LINE__);
+			$resultAnswer = Database::query($sqlAnswer, __FILE__, __LINE__);
 
 			echo "<a name='infosExe'></a>";
 
@@ -1220,4 +1217,4 @@ if ($export_csv) {
 		FOOTER
 ==============================================================================
 */
-Display :: display_footer();
+Display :: display_footer();

+ 75 - 123
main/mySpace/progression.php

@@ -2,27 +2,25 @@
 /*
  * Created on 28 juil. 2006 by Elixir Interactive http://www.elixir-interactive.com
  */
-$language_file = array ('registration', 'index','tracking');
-require ('../inc/global.inc.php');
+$language_file = array ('registration', 'index', 'tracking');
+require '../inc/global.inc.php';
  
- $nameTools= get_lang('Progression');
- // name of the language file that needs to be included 
+$nameTools = get_lang('Progression');
 
- $cidReset=true;
+$cidReset = true;
 
- 
- $this_section = "session_my_space";
- 
- api_block_anonymous_users();
-  $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
- Display :: display_header($nameTools);
- 
-// Database Table Definitions 
+$this_section = "session_my_space";
+
+api_block_anonymous_users();
+$interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
+Display :: display_header($nameTools);
+
+// Database Table Definitions
 $tbl_course 		= Database :: get_main_table(TABLE_MAIN_COURSE);
 $tbl_user 			= Database :: get_main_table(TABLE_MAIN_USER);
 $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
 $tbl_session 		= Database :: get_main_table(TABLE_MAIN_SESSION);
-$tbl_track_exercice = Database :: get_statistic_table(STATISTIC_TRACK_E_EXERCICES_TABLE);
+$tbl_track_exercice = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  
  /*
  ===============================================================================
@@ -30,135 +28,89 @@ $tbl_track_exercice = Database :: get_statistic_table(STATISTIC_TRACK_E_EXERCICE
  ===============================================================================  
  */
  
- function exportCsv($a_header,$a_data)
- {
- 	global $archiveDirName;
-	
+function exportCsv($a_header, $a_data) {
+	global $archiveDirName;
+
 	$fileName = 'test.csv';
-	$archivePath = api_get_path(SYS_PATH).$archiveDirName.'/';
+	$archivePath = api_get_path(SYS_ARCHIVE_PATH);
 	$archiveURL = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive=';
-	
-	if(!$open = fopen($archivePath.$fileName,'w+'))
-	{
+
+	if (!$open = fopen($archivePath.$fileName, 'w+')) {
 		$message = get_lang('noOpen');
-	}
-	else
-	{
+	} else {
 		$info = '';
-		
-		foreach($a_header as $header)
-		{
+
+		foreach ($a_header as $header) {
 			$info .= $header.';';
 		}
 		$info .= "\r\n";
-		
-		
-		foreach($a_data as $data)
-		{
-			foreach($data as $infos)
-			{
+
+		foreach ($a_data as $data) {
+			foreach($data as $infos) {
 				$info .= $infos.';';
 			}
 			$info .= "\r\n";
 		}
-		
-		fwrite($open,$info);
+
+		fwrite($open, $info);
 		fclose($open);
 		$perm = api_get_setting('permissions_for_new_files');
-		$perm = octdec(!empty($perm)?$perm:'0660');
-		chmod($fileName,$perm);
+		$perm = octdec(!empty($perm) ? $perm : '0660');
+		chmod($fileName, $perm);
 		$message = get_lang('UsageDatacreated');
-		
+
 		header("Location:".$archiveURL.$fileName);
 	}
-	
 	return $message;
- }
- 
- /*
- ===============================================================================
+}
+
+/*
+===============================================================================
  	MAIN CODE
- ===============================================================================  
- */
- $sqlCourse = "	SELECT 	title,code
-					FROM $tbl_course as course
-					ORDER BY title ASC
-				  ";
-	
-	$resultCourse = api_sql_query($sqlCourse);
+===============================================================================  
+*/
+$sqlCourse = "SELECT 	title,code
+	FROM $tbl_course as course
+	ORDER BY title ASC";
 
-	if(mysql_num_rows($resultCourse)>0)
-	{
-		if(isset($_POST['export']))
-		{
-			$exportResult = exportCsv($header,$data);
-			Display :: display_error_message($exportResult);
+$resultCourse = Database::query($sqlCourse, __FILE__, __LINE__);
+
+if (Database::num_rows($resultCourse) > 0) {
+	if (isset($_POST['export'])) {
+		$exportResult = exportCsv($header,$data);
+		Display :: display_error_message($exportResult);
+	}
+	echo '<table class="data_table"><tr><th>'.get_lang('Course').'</th><th>'.get_lang('TempsFrequentation').'</th><th>'.get_lang('Progression').'</th><th>'.get_lang('MoyenneTest').'</th></tr>';
+	$header = array(get_lang('Course'),get_lang('TempsFrequentation'),get_lang('Progression'),get_lang('MoyenneTest'));
+	while ($a_course = Database::fetch_array($resultCourse)) {
+		$sqlMoyTest = "SELECT exe_result,exe_weighting
+			FROM $tbl_track_exercice
+			WHERE exe_cours_id = '".$a_course['code']."'";
+		$resultMoyTest = Database::query($sqlMoyTest, __FILE__, __LINE__);
+		$result = 0;
+		$weighting = 0;
+		while ($a_moyTest = Database::fetch_array($resultMoyTest)) {
+			$result = $result + $a_moyTest['exe_result'];
+			$weighting = $weighting + $a_moyTest['exe_weighting'];
 		}
-		echo '<table class="data_table">
-			 	<tr>
-					<th>
-						'.get_lang('Course').'
-					</th>
-					<th>
-						'.get_lang('TempsFrequentation').'
-					</th>
-					<th>
-						'.get_lang('Progression').'
-					</th>
-					<th>
-						'.get_lang('MoyenneTest').'
-					</th>
-				</tr>
-          	 ';
-        $header = array(get_lang('Course'),get_lang('TempsFrequentation'),get_lang('Progression'),get_lang('MoyenneTest'));
-		while($a_course= mysql_fetch_array($resultCourse))
-		{
-			$sqlMoyTest = "	SELECT exe_result,exe_weighting
-							FROM $tbl_track_exercice
-							WHERE exe_cours_id = '".$a_course['code']."'
-						  ";
-			$resultMoyTest = api_sql_query($sqlMoyTest);
-			$result = 0;
-			$weighting = 0;
-			while($a_moyTest = mysql_fetch_array($resultMoyTest))
-			{
-				$result = $result + $a_moyTest['exe_result'];
-				$weighting = $weighting + $a_moyTest['exe_weighting'];
-			}
-			$moyenneTest = round(($result*100)/$weighting);
-			echo '<tr>
-					<td>
-				 		'.$a_course['title'].'
-					</td>
-					<td>
-						
-					</td>
-					<td>
-						
-					</td>
-					<td align="center">
-						'.$moyenneTest.'%
-					</td>
-				  </tr>
-				 ';
+		if ($weighting != 0) {
+			$moyenneTest = round(($result * 100) / $weighting);
+		} else {
+			$moyenneTest = null;
 		}
-		echo '</table>';
-		
-		echo "<br /><br />";
-		echo "<form method='post'>
-				<input type='submit' name='export' value='".get_lang('exportExcel')."'/>
-			  <form>";
+		echo '<tr><td>'.$a_course['title'].'</td><td> </td><td> </td><td align="center">'.$moyenneTest.'%</td> </tr>';
 	}
-	else
-	{
-		echo get_lang('NoCourse');
-	}
- 
- /*
- ==============================================================================
+	echo '</table>';
+	echo "<br /><br />";
+	echo "<form method='post'><input type='submit' name='export' value='".get_lang('exportExcel')."'/><form>";
+} else {
+	echo get_lang('NoCourse');
+}
+
+/*
+==============================================================================
 		FOOTER
- ==============================================================================
- */
-	
-	Display :: display_footer();
-?>
+==============================================================================
+*/
+
+Display :: display_footer();

+ 80 - 145
main/mySpace/reussite.php

@@ -2,182 +2,117 @@
 /*
  * Created on 28 juil. 2006 by Elixir Interactive http://www.elixir-interactive.com
  */
- 
- $nameTools= 'Réussite';
- // name of the language file that needs to be included 
-$language_file = array ('registration', 'index','trad4all','tracking');
- $cidReset=true;
- require ('../inc/global.inc.php');
- 
- $this_section = "session_my_space";
- 
- api_block_anonymous_users();
-  $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
- Display :: display_header($nameTools);
 
- 
+$nameTools = 'Reussite';
+// name of the language file that needs to be included 
+$language_file = array ('registration', 'index', 'trad4all', 'tracking');
+$cidReset = true;
+require '../inc/global.inc.php';
+
+$this_section = "session_my_space";
+
+api_block_anonymous_users();
+$interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
+Display :: display_header($nameTools);
+
 // Database Table Definitions 
 $tbl_course 		= Database :: get_main_table(TABLE_MAIN_COURSE);
 $tbl_user 			= Database :: get_main_table(TABLE_MAIN_USER);
 $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
 $tbl_session 		= Database :: get_main_table(TABLE_MAIN_SESSION);
-$tbl_track_exercice = Database :: get_statistic_table(STATISTIC_TRACK_E_EXERCICES_TABLE);
- 
- /*
- ===============================================================================
- 	MAIN CODE
- ===============================================================================  
- */
- if(!empty($_GET['session']))
- {
- 	
- 	$sqlSession = "	SELECT name,id
-					FROM $tbl_session
-					ORDER BY name ASC
-				  ";
-	$resultSession = api_sql_query($sqlSession);
-	
+$tbl_track_exercice = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
+
+/*
+===============================================================================
+	MAIN CODE
+===============================================================================  
+*/
+if (!empty($_GET['session'])) {
+	$sqlSession = "SELECT name,id
+		FROM $tbl_session
+		ORDER BY name ASC";
+	$resultSession = Database::query($sqlSession, __FILE__, __LINE__);
+
 	echo "<a href='".api_get_self()."'>".get_lang('MoyCourse')."</a>";
 	echo "<br /><br />";
-	
-	if(mysql_num_rows($resultSession)>0)
-	{
-		
-		
-		echo '<table class="data_table">
-			 	<tr>
-					<th>
-						'.get_lang('Session').'
-					</th>
-					<th>
-						'.get_lang('MoyenneTest').'
-					</th>
-					<th>
-						'.get_lang('MoyenneExamen').'
-					</th>
-				</tr>
-          	 ';
-		
-		while($a_session = mysql_fetch_array($resultSession))
-		{
-			$sqlCourse = "	SELECT 	title,code
-							FROM $tbl_course as course
-							INNER JOIN $tbl_session_course AS rel_course
-								ON course.code = rel_course.course_code
-								AND rel_course.id_session = ".$a_session['id']."
-							ORDER BY title ASC
-				  		 ";
-	
-			$resultCourse = api_sql_query($sqlCourse);
+
+	if (Database::num_rows($resultSession) > 0) {
+		echo '<table class="data_table"><tr><th>'.get_lang('Session').'</th><th>'.get_lang('MoyenneTest').'</th><th>'.get_lang('MoyenneExamen').'</th></tr>';
+		while ($a_session = Database::fetch_array($resultSession)) {
+			$sqlCourse = "SELECT title,code
+				FROM $tbl_course as course
+				INNER JOIN $tbl_session_course AS rel_course
+				ON course.code = rel_course.course_code
+				AND rel_course.id_session = ".$a_session['id']."
+				ORDER BY title ASC";
+
+			$resultCourse = Database::query($sqlCourse, __FILE__, __LINE__);
 			$totalResult = 0;
 			$totalWeighting = 0;
-			while($a_course = mysql_fetch_array($resultCourse))
-			{
-				$sqlMoyTest = "	SELECT exe_result,exe_weighting
-							FROM $tbl_track_exercice
-							WHERE exe_cours_id = '".$a_course['code']."'
-						  ";
-				$resultMoyTest = api_sql_query($sqlMoyTest);
+			while ($a_course = Database::fetch_array($resultCourse)) {
+				$sqlMoyTest = "SELECT exe_result,exe_weighting
+					FROM $tbl_track_exercice
+					WHERE exe_cours_id = '".$a_course['code']."'";
+				$resultMoyTest = Database::query($sqlMoyTest);
 				$result = 0;
 				$weighting = 0;
-				while($a_moyTest = mysql_fetch_array($resultMoyTest))
-				{
+				while ($a_moyTest = Database::fetch_array($resultMoyTest)) {
 					$result = $result + $a_moyTest['exe_result'];
 					$weighting = $weighting + $a_moyTest['exe_weighting'];
 				}
 				$totalResult = $totalResult + $result;
 				$totalWeighting = $totalWeighting + $weighting;
 			}
-			$moyenneTest = round(($totalResult*100) / $totalWeighting);
-			
-			
-			echo '<tr>
-					<td>
-				 		'.$a_session['name'].'
-					</td>
-					<td align="center">
-						'.$moyenneTest.'%
-					</td>
-				 	<td>
-						
-					</td>
-				  </tr>
-				 ';
-			
+			if ($totalWeighting != 0) {
+				$moyenneTest = round(($totalResult * 100) / $totalWeighting);
+			} else {
+				$moyenneTest = 0;
+			}
+
+			echo '<tr><td>'.$a_session['name'].'</td><td align="center">'.$moyenneTest.'%</td><td> </td></tr>';
 		}
 		echo '</table>';
-	}
-	else
-	{
+	} else {
 		echo get_lang('NoSession');
 	}
- }
- else
- {
- 	$sqlCourse = "	SELECT 	title,code
-					FROM $tbl_course as course
-					ORDER BY title ASC
-				  ";
-	
-	$resultCourse = api_sql_query($sqlCourse);
-	
+} else {
+	$sqlCourse = "SELECT 	title,code
+		FROM $tbl_course as course
+		ORDER BY title ASC";
+
+	$resultCourse = Database::query($sqlCourse, __FILE__, __LINE__);
+
 	echo "<a href='".api_get_self()."?session=true'>".get_lang('MoySession')."</a>";
 	echo "<br /><br />";
-	if(mysql_num_rows($resultCourse)>0)
-	{
-		echo '<table class="data_table">
-			 	<tr>
-					<th>
-						'.get_lang('Course').'
-					</th>
-					<th>
-						'.get_lang('MoyenneTest').'
-					</th>
-					<th>
-						'.get_lang('MoyenneExamen').'
-					</th>
-				</tr>
-          	 ';
-		while($a_course= mysql_fetch_array($resultCourse))
-		{
-			$sqlMoyTest = "	SELECT exe_result,exe_weighting
-							FROM $tbl_track_exercice
-							WHERE exe_cours_id = '".$a_course['code']."'
-						  ";
-			$resultMoyTest = api_sql_query($sqlMoyTest);
+	if (Database::num_rows($resultCourse) > 0) {
+		echo '<table class="data_table"><tr><th>'.get_lang('Course').'</th><th>'.get_lang('MoyenneTest').'</th><th>'.get_lang('MoyenneExamen').'</th></tr>';
+		while ($a_course= Database::fetch_array($resultCourse)) {
+			$sqlMoyTest = "SELECT exe_result,exe_weighting
+				FROM $tbl_track_exercice
+				WHERE exe_cours_id = '".$a_course['code']."'";
+			$resultMoyTest = Database::query($sqlMoyTest, __FILE__, __LINE__);
 			$result = 0;
 			$weighting = 0;
-			while($a_moyTest = mysql_fetch_array($resultMoyTest))
-			{
+			while ($a_moyTest = Database::fetch_array($resultMoyTest)) {
 				$result = $result + $a_moyTest['exe_result'];
 				$weighting = $weighting + $a_moyTest['exe_weighting'];
 			}
-			$moyenneTest = round(($result*100)/$weighting);
-			echo '<tr>
-					<td>
-				 		'.$a_course['title'].'
-					</td>
-					<td align="center">
-						'.$moyenneTest.'%
-					</td>
-				 	<td>
-						
-					</td>
-				  </tr>
-				 ';
+			if ($weighting != 0) {
+				$moyenneTest = round(($result * 100) / $weighting);
+			} else {
+				$moyenneTest = null;
+			}
+			echo '<tr><td>'.$a_course['title'].'</td><td align="center">'.$moyenneTest.'%</td><td> </td></tr>';
 		}
 		echo '</table>';
-	}
-	else
-	{
+	} else {
 		echo get_lang('NoCourse');
 	}
- }
- /*
- ==============================================================================
+}
+/*
+==============================================================================
 		FOOTER
- ==============================================================================
- */
-	
-	Display :: display_footer();
-?>
+==============================================================================
+*/
+
+Display :: display_footer();

+ 62 - 86
main/mySpace/session.php

@@ -26,18 +26,18 @@
  * Somes fixes by Julio Montoya
  */
 ob_start();
- $nameTools= 'Sessions';
- // name of the language file that needs to be included 
-$language_file = array ('registration', 'index','trad4all','tracking');
-$cidReset=true;
-require ('../inc/global.inc.php');
-require_once (api_get_path(LIBRARY_PATH).'tracking.lib.php');
-require_once (api_get_path(LIBRARY_PATH).'export.lib.inc.php');
+$nameTools= 'Sessions';
+// name of the language file that needs to be included 
+$language_file = array ('registration', 'index', 'trad4all', 'tracking');
+$cidReset = true;
+require '../inc/global.inc.php';
+require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
+require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
 
 api_block_anonymous_users();
 
 $this_section = "session_my_space";
- 
+
 api_block_anonymous_users();
 $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
 Display :: display_header($nameTools);
@@ -47,148 +47,124 @@ $tbl_course_user 		= Database :: get_main_table(TABLE_MAIN_COURSE_USER);
 $tbl_sessions 			= Database :: get_main_table(TABLE_MAIN_SESSION);
 $tbl_session_course 	= Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
 $tbl_course 			= Database :: get_main_table(TABLE_MAIN_COURSE);
- 
+
 $export_csv = false;
 
-if (isset($_GET['export']) && $_GET['export'] == 'csv')
-{
-	$export_csv=true; 
+if (isset($_GET['export']) && $_GET['export'] == 'csv') {
+	$export_csv = true; 
 }
 
 
- /*
- ===============================================================================
- 	FUNCTION
- ===============================================================================  
- */
+/*
+===============================================================================
+	FUNCTION
+===============================================================================  
+*/
  
-function count_sessions_coached()
-{
+function count_sessions_coached() {
 	global $nb_sessions;
 	return $nb_sessions;
 }
 
-function sort_sessions($a, $b)
-{
+function sort_sessions($a, $b) {
 	global $tracking_column;
-	if ($a[$tracking_column] > $b[$tracking_column])
+	if ($a[$tracking_column] > $b[$tracking_column]) {
 		return 1;
-	else 
+	} else {
 		return -1;
+	}
 }
 
-function rsort_sessions($a, $b)
-{
+function rsort_sessions($a, $b) {
 	global $tracking_column;
-	if ($b[$tracking_column] > $a[$tracking_column])
+	if ($b[$tracking_column] > $a[$tracking_column]) {
 		return 1;
-	else 
+	} else {
 		return -1;
+	}
 }
 
 
- /*
- ===============================================================================
- 	MAIN CODE
- ===============================================================================  
- */
+/*
+===============================================================================
+	MAIN CODE
+===============================================================================  
+*/
 
-if(isset($_GET['id_coach']) && $_GET['id_coach']!='')
-{
+if (isset($_GET['id_coach']) && $_GET['id_coach'] != '') {
 	$id_coach=$_GET['id_coach'];
-}
-else
-{
+} else {
 	$id_coach=$_user['user_id'];
 }
 
 $a_sessions = Tracking :: get_sessions_coached_by_user($id_coach);
 $nb_sessions = count($a_sessions);
 
-if($export_csv)
-{
+if ($export_csv) {
 	$csv_content=array();
 }
 
-if($nb_sessions > 0)
-{
+if ($nb_sessions > 0) {
 	echo '<div align="right">
-			<a href="#" onclick="window.print()"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a>
+			<a href="javascript: void(0);" onclick="javascript: window.print();"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a>
 			<a href="'.api_get_self().'?export=csv"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsCSV').'</a>
 		  </div>';
 	$table = new SortableTable('tracking', 'count_sessions_coached');
 	$table -> set_header(0, get_lang('Title'));
 	$table -> set_header(1, get_lang('Status'));
 	$table -> set_header(2, get_lang('Date'));
-	$table -> set_header(3, get_lang('Details'),false);
-	
+	$table -> set_header(3, get_lang('Details'), false);
+
 	$all_datas = array();	
-	foreach ($a_sessions as $session)
-	{	
+	foreach ($a_sessions as $session) {
 		$row = array();
 		$row[] = $session['name'];
 		$row[] = $session['status'];
-		
-		if($session['date_start']!='0000-00-00' && $session['date_end']!='0000-00-00')
-		{
+
+		if ($session['date_start']!='0000-00-00' && $session['date_end']!='0000-00-00') {
 			$row[] = get_lang('From').' '.format_locale_date(get_lang('DateFormatLongWithoutDay'),strtotime($session['date_start'])).' '.get_lang('To').' '.format_locale_date(get_lang('DateFormatLongWithoutDay'),strtotime($session['date_end']));
-		}
-		else
-		{
+		} else {
 			$row[] = ' - ';
 		}
-		
-		if($export_csv)
-		{
+
+		if ($export_csv) {
 			$csv_content[]=$row;
 		}
-		
-		if(isset($_GET['id_coach']) && $_GET['id_coach']!='')
-		{
+
+		if (isset($_GET['id_coach']) && $_GET['id_coach'] != '') {
 			$row[] = '<a href="student.php?id_session='.$session['id'].'&id_coach='.$_GET['id_coach'].'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
-		}
-		else
-		{
+		} else {
 			$row[] = '<a href="course.php?id_session='.$session['id'].'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
-		}		 
+		}
 		$all_datas[] = $row;
 	}
-	
-	if(!isset($tracking_column))
-	{
+
+	if (!isset($tracking_column)) {
 		$tracking_column = 0;
 	}
-		
-	if($_GET['tracking_direction'] == 'DESC')
-	{
+
+	if ($_GET['tracking_direction'] == 'DESC') {
 		usort($all_datas, 'rsort_sessions');
-	}
-	else
-	{
+	} else {
 		usort($all_datas, 'sort_sessions');
 	}
-	
-	if($export_csv)
-	{
+
+	if ($export_csv) {
 		usort($csv_content, 'sort_sessions');
 	}
-	
-	foreach($all_datas as $row)
-	{
-		$table -> addRow($row);	
+
+	foreach ($all_datas as $row) {
+		$table -> addRow($row);
 	}
-	
+
 	$table -> setColAttributes(3,array('align'=>'center'));
 	$table -> display();	
-	
-	if($export_csv)
-	{
+
+	if ($export_csv) {
 		ob_end_clean();		
 		Export :: export_table_csv($csv_content, 'reporting_student_list');
 	}
-}
-else
-{
+} else {
 	get_lang('NoSession');
 }
 
@@ -197,5 +173,5 @@ else
 	FOOTER
 ==============================================================================
 */
+
 Display::display_footer();
-?>

+ 86 - 107
main/mySpace/student.php

@@ -1,52 +1,52 @@
 <?php
+
 /*
  * Created on 28 juil. 2006 by Elixir Interactive http://www.elixir-interactive.com
  */
+
  // name of the language file that needs to be included 
 $language_file = array ('registration', 'index', 'tracking');
 $cidReset=true;
-require ('../inc/global.inc.php');
-require_once (api_get_path(LIBRARY_PATH).'tracking.lib.php');
-require_once (api_get_path(LIBRARY_PATH).'export.lib.inc.php');
-require_once (api_get_path(LIBRARY_PATH).'course.lib.php');
-require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php');
- 
+require '../inc/global.inc.php';
+require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
+require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
+require_once api_get_path(LIBRARY_PATH).'course.lib.php';
+require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
 
 
 $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
-if($export_csv)
-{
+if ($export_csv) {
 	ob_start();
 }
 $csv_content = array();
 
-if(isset($_GET['id_coach']) && intval($_GET['id_coach'])!=0){
-	$nameTools= get_lang("CoachStudents");
+if(isset($_GET['id_coach']) && intval($_GET['id_coach'])!=0) {
+	$nameTools = get_lang("CoachStudents");
 	$sql = 'SELECT lastname, firstname FROM '.Database::get_main_table(TABLE_MAIN_USER).' WHERE user_id='.intval($_GET['id_coach']);
-	$rs = api_sql_query($sql, __FILE__, __LINE__);
+	$rs = Database::query($sql, __FILE__, __LINE__);
+
 	$coach_name = mysql_result($rs, 0, 0).' '.mysql_result($rs, 0, 1);
 	$title = get_lang('Probationers').' - '.$coach_name;
-}
-else{
+} else {
 	$nameTools= get_lang("Students");
 	$title = get_lang('Probationers');
 }
- 
+
 $this_section = "session_my_space";
- 
+
 api_block_anonymous_users();
- 
+
 $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
- 
-if(isset($_GET["user_id"]) && $_GET["user_id"]!="" && !isset($_GET["type"])){
+
+if (isset($_GET["user_id"]) && $_GET["user_id"]!="" && !isset($_GET["type"])) {
 	$interbreadcrumb[] = array ("url" => "teachers.php", "name" => get_lang('Teachers'));
 }
- 
-if(isset($_GET["user_id"]) && $_GET["user_id"]!="" && isset($_GET["type"]) && $_GET["type"]=="coach"){
+
+if (isset($_GET["user_id"]) && $_GET["user_id"]!="" && isset($_GET["type"]) && $_GET["type"]=="coach") {
  	$interbreadcrumb[] = array ("url" => "coaches.php", "name" => get_lang('Tutors'));
 }
 
-$isCoach = api_is_coach(); 
+$isCoach = api_is_coach();
 
 Display :: display_header($nameTools);
 
@@ -65,28 +65,28 @@ $tbl_session_rel_user 		= Database :: get_main_table(TABLE_MAIN_SESSION_USER);
  ===============================================================================  
  */
 
-function count_student_coached()
-{
+function count_student_coached() {
 	global $a_students;
 	return count($a_students);
 }
 
-function sort_users($a, $b)
-{
+function sort_users($a, $b) {
 	global $tracking_column;
-	if($a[$tracking_column] > $b[$tracking_column])
+	if ($a[$tracking_column] > $b[$tracking_column]) {
 		return 1;
-	else 
+	} else {
 		return -1;
+	}
 }
 
 function rsort_users($a, $b)
 {
 	global $tracking_column;
-	if($b[$tracking_column] > $a[$tracking_column])
+	if($b[$tracking_column] > $a[$tracking_column]) {
 		return 1;
-	else 
+	} else {
 		return -1;
+	}
 }
 
 /*
@@ -95,46 +95,42 @@ function rsort_users($a, $b)
  ===============================================================================  
  */ 
 
-if($isCoach || api_is_platform_admin() || $_user['status']==DRH)
-{
+if ($isCoach || api_is_platform_admin() || $_user['status'] == DRH) {
 
 	echo '<div align="left" style="float:left"><h4>'.$title.'</h4></div>
 		  <div align="right">
-			<a href="#" onclick="window.print()"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a>
+			<a href="javascript: void(0);" onclick="javascript: window.print();"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a>
 			<a href="'.api_get_self().'?export=csv"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsCSV').'</a>
 		  </div><div class="clear"></div>';
-	
-	if(isset($_GET['id_coach'])){
+
+	if (isset($_GET['id_coach'])) {
 		$coach_id=intval($_GET['id_coach']);
-	}
-	else{
+	} else {
 		$coach_id=$_user['user_id'];
 	}
-	
-	if(!isset($_GET['id_session'])){
-		if($isCoach)
-		{
+
+	if (!isset($_GET['id_session'])) {
+		if ($isCoach) {
 			$a_courses = Tracking :: get_courses_followed_by_coach($coach_id);
 			$a_students = Tracking :: get_student_followed_by_coach($coach_id);
 		}
-		else if($_user['status']==DRH)
-		{
+		elseif ($_user['status'] == DRH) {
 			$a_students = Tracking :: get_student_followed_by_drh($_user['user_id']);
 			$courses_of_the_platform = CourseManager :: get_real_course_list();
-			foreach($courses_of_the_platform as $course)
+			foreach ($courses_of_the_platform as $course) {
 				$a_courses[$course['code']] = $course['code'];
+			}
 		}
-	}
-	else{
+	} else {
 		$a_students = Tracking :: get_student_followed_by_coach_in_a_session($_GET['id_session'], $coach_id);
 	}
-	
+
 	$tracking_column = isset($_GET['tracking_column']) ? $_GET['tracking_column'] : 0;
 	$tracking_direction = isset($_GET['tracking_direction']) ? $_GET['tracking_direction'] : DESC;
-	
-	if(count($a_students)>0)
-	{
+
+	if (count($a_students) > 0) {
 		$table = new SortableTable('tracking', 'count_student_coached');
+
 		$table -> set_header(0, get_lang('LastName'), true, 'align="center');
 		$table -> set_header(1, get_lang('FirstName'), true, 'align="center');
 		$table -> set_header(2, get_lang('Time'),false);
@@ -145,9 +141,8 @@ if($isCoach || api_is_platform_admin() || $_user['status']==DRH)
 		$table -> set_header(7, get_lang('FirstLogin'), false);
 		$table -> set_header(8, get_lang('LatestLogin'), false);
 		$table -> set_header(9, get_lang('Details'),false);
-	     
-	    if($export_csv)
-		{
+
+	    if ($export_csv) {
 			$csv_content[] = array ( 
 									get_lang('LastName'),
 									get_lang('FirstName'),
@@ -158,23 +153,20 @@ if($isCoach || api_is_platform_admin() || $_user['status']==DRH)
 									get_lang('Messages'),
 									get_lang('FirstLogin'),
 									get_lang('LatestLogin')
-								   );
+								);
 		}
-	    
+
 	    $all_datas = array();
-		foreach($a_students as $student_id)
-		{
+		foreach ($a_students as $student_id) {
 			$student_datas = UserManager :: get_user_info_by_id($student_id);
-			if(isset($_GET['id_session'])){
+			if(isset($_GET['id_session'])) {
 				$a_courses = Tracking :: get_course_list_in_session_from_student($student_id,$_GET['id_session']);
 			}
-			
-			$avg_time_spent = $avg_student_score = $avg_student_progress = $total_assignments = $total_messages = 0 ;
+
+			$avg_time_spent = $avg_student_score = $avg_student_progress = $total_assignments = $total_messages = 0;
 			$nb_courses_student = 0;
-			foreach($a_courses as $course_code)
-			{
-				if(CourseManager :: is_user_subscribed_in_course($student_id,$course_code, true))
-				{
+			foreach ($a_courses as $course_code) {
+				if (CourseManager :: is_user_subscribed_in_course($student_id, $course_code, true)) {
 					$avg_time_spent += Tracking :: get_time_spent_on_the_platform($student_id, $course_code);
 					$avg_student_score += Tracking :: get_avg_student_score($student_id, $course_code);
 					$avg_student_progress += Tracking :: get_avg_student_progress($student_id, $course_code);
@@ -186,82 +178,69 @@ if($isCoach || api_is_platform_admin() || $_user['status']==DRH)
 			$avg_time_spent = $avg_time_spent / $nb_courses_student;
 			$avg_student_score = $avg_student_score / $nb_courses_student;
 			$avg_student_progress = $avg_student_progress / $nb_courses_student;
-			
+
 			$row = array();
+
 			$row[] = $student_datas['lastname'];
-			$row[] = 	$student_datas['firstname'];
+			$row[] = $student_datas['firstname'];
 			$row[] = api_time_to_hms($avg_time_spent);
-			$row[] = round($avg_student_progress,2).' %';
-			$row[] = round($avg_student_score,2).' %';		
+			$row[] = round($avg_student_progress, 2).' %';
+			$row[] = round($avg_student_score, 2).' %';		
 			$row[] = $total_assignments;
 			$row[] = $total_messages;
-			
+
 			$string_date=Tracking :: get_last_connection_date($student_id,true);
 			$first_date=Tracking :: get_first_connection_date($student_id);
 			$row[] = $first_date;
 			$row[] = $string_date;
-			
-			
-			if($export_csv)
-			{
+
+			if ($export_csv) {
 				$csv_content[] = $row;
 			}
-			
-			if(isset($_GET['id_coach']) && intval($_GET['id_coach'])!=0){
+
+			if (isset($_GET['id_coach']) && intval($_GET['id_coach']) !=0 ) {
 				$row[] = '<a href="myStudents.php?student='.$student_id.'&id_coach='.$coach_id.'&id_session='.$_GET['id_session'].'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
-			}
-			else{
+			} else {
 				$row[] = '<a href="myStudents.php?student='.$student_id.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
 			}
-			
-			$all_datas[] = $row;		
-	
+
+			$all_datas[] = $row;
 		}
-		
-		if($tracking_direction == 'ASC')
-		{
+
+		if ($tracking_direction == 'ASC') {
 			usort($all_datas, 'rsort_users');
-		}
-		else
-		{
+		} else {
 			usort($all_datas, 'sort_users');
 		}
-		
-		if($export_csv)
-		{
+
+		if ($export_csv) {
 			usort($csv_content, 'sort_users');
 		}
-		
-		foreach($all_datas as $row)
-		{
+
+		foreach ($all_datas as $row) {
 			$table -> addRow($row,'align="right"');	
 		}
-		$table -> updateColAttributes(0,array('align'=>'left'));
-		$table -> updateColAttributes(1,array('align'=>'left'));
-		$table -> updateColAttributes(7,array('align'=>'left'));
-		$table -> updateColAttributes(8,array('align'=>'left'));
-		$table -> setColAttributes(9,array('align'=>'center'));
+		$table -> updateColAttributes(0, array('align'=>'left'));
+		$table -> updateColAttributes(1, array('align'=>'left'));
+		$table -> updateColAttributes(7, array('align'=>'left'));
+		$table -> updateColAttributes(8, array('align'=>'left'));
+		$table -> setColAttributes(9, array('align'=>'center'));
 		$table -> display();
-		
-	}
-	else
-	{
+	} else {
 		echo get_lang('NoStudent');
 	}
-	
+
 	// send the csv file if asked
-	if($export_csv)
-	{
+	if ($export_csv) {
 		ob_end_clean();
 		Export :: export_table_csv($csv_content, 'reporting_student_list');
 	}
 }
 
 /*
- ==============================================================================
+==============================================================================
 		FOOTER
- ==============================================================================
- */
+==============================================================================
+*/
 	
 Display :: display_footer();
-?>

+ 63 - 124
main/mySpace/teachers.php

@@ -8,8 +8,8 @@ ob_start();
 
 // names of the language file that needs to be included 
 $language_file = array ('registration', 'index','trad4all', 'tracking', 'admin');
-$cidReset=true;
-require ('../inc/global.inc.php');
+$cidReset = true;
+require '../inc/global.inc.php';
 
 $this_section = "session_my_space";
 
@@ -29,55 +29,46 @@ $tbl_session_course 	= Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
 $tbl_session_rel_user 	= Database :: get_main_table(TABLE_MAIN_SESSION_USER);
 
 
- /*
- ===============================================================================
- 	FUNCTION
- ===============================================================================  
- */
+/*
+===============================================================================
+	FUNCTION
+===============================================================================  
+*/
 
-function exportCsv($a_header,$a_data)
- {
+function exportCsv($a_header, $a_data) {
  	global $archiveDirName;
 
 	$fileName = 'teachers.csv';
-	$archivePath = api_get_path(SYS_PATH).$archiveDirName.'/';
+	$archivePath = api_get_path(SYS_ARCHIVE_PATH);
 	$archiveURL = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive=';
-	
-	if(!$open = fopen($archivePath.$fileName,'w+'))
-	{
+
+	if (!$open = fopen($archivePath.$fileName, 'w+')) {
 		$message = get_lang('noOpen');
-	}
-	else
-	{
+	} else {
 		$info = '';
-		
-		foreach($a_header as $header)
-		{
+
+		foreach ($a_header as $header) {
 			$info .= $header.';';
 		}
 		$info .= "\r\n";
-		
-		
-		foreach($a_data as $data)
-		{
-			foreach($data as $infos)
-			{
+
+		foreach ($a_data as $data) {
+			foreach ($data as $infos) {
 				$info .= $infos.';';
 			}
 			$info .= "\r\n";
 		}
-		
+
 		fwrite($open,$info);
 		fclose($open);
 		$perm = api_get_setting('permissions_for_new_files');
 		$perm = octdec(!empty($perm)?$perm:'0660');
 		chmod($fileName,$perm);
-		
+
 		header("Location:".$archiveURL.$fileName);
 	}
-	
 	return $message;
- }
+}
 
 
 /**
@@ -85,121 +76,71 @@ function exportCsv($a_header,$a_data)
  */
 
 
-if(isset($_GET["teacher_id"]) && $_GET["teacher_id"]!=0){
+if (isset($_GET["teacher_id"]) && $_GET["teacher_id"] != 0) {
 	$i_teacher_id=$_GET["teacher_id"];
-	$sqlFormateurs = "	SELECT user_id,lastname,firstname,email
-						FROM $tbl_user
-						WHERE user_id='$i_teacher_id' 
-						ORDER BY lastname ASC
-					  ";
-}
-else{
-	$sqlFormateurs = "	SELECT user_id,lastname,firstname,email
-						FROM $tbl_user
-						WHERE status = 1
-						ORDER BY lastname ASC
-					  ";
+	$sqlFormateurs = "SELECT user_id,lastname,firstname,email
+		FROM $tbl_user
+		WHERE user_id='$i_teacher_id' 
+		ORDER BY lastname ASC";
+} else {
+	$sqlFormateurs = "SELECT user_id,lastname,firstname,email
+		FROM $tbl_user
+		WHERE status = 1
+		ORDER BY lastname ASC";
 }
 
-$resultFormateurs = api_sql_query($sqlFormateurs);
-
-echo '<table class="data_table">
-	 	<tr>
-			<th>
-				'.get_lang('FirstName').'
-			</th>
-			<th>
-				'.get_lang('LastName').'
-			</th>
-			<th>
-				'.get_lang('Email').'
-			</th>
-			<th>
-				'.get_lang('AdminCourses').'
-			</th>
-			<th>
-				'.get_lang('Students').'
-			</th>
-		</tr>
-  	 ';
-
-$a_header[]=get_lang('FirstName');
-$a_header[]=get_lang('LastName');
-$a_header[]=get_lang('Email');
-
-$a_data=array();
-
-if(mysql_num_rows($resultFormateurs)>0){
-	
-	$i=1;
-	
-	while($a_formateurs=mysql_fetch_array($resultFormateurs)){
-		
-		$i_user_id=$a_formateurs["user_id"];
-		$s_lastname=$a_formateurs["lastname"];
-		$s_firstname=$a_formateurs["firstname"];
-		$s_email=$a_formateurs["email"];
-		
-		if($i%2==0){
-			$s_css_class="row_odd";
+$resultFormateurs = Database::query($sqlFormateurs, __FILE__, __LINE__);
+
+echo '<table class="data_table"><tr><th>'.get_lang('FirstName').'</th><th>'.get_lang('LastName').'</th><th>'.get_lang('Email').'</th><th>'.get_lang('AdminCourses').'</th><th>'.get_lang('Students').'</th></tr>';
+
+$a_header[] = get_lang('FirstName');
+$a_header[] = get_lang('LastName');
+$a_header[] = get_lang('Email');
+
+$a_data = array();
+
+if (Database::num_rows($resultFormateurs) > 0) {
+
+	$i = 1;
+	while ($a_formateurs = Database::fetch_array($resultFormateurs)) {
+
+		$i_user_id = $a_formateurs["user_id"];
+		$s_lastname = $a_formateurs["lastname"];
+		$s_firstname = $a_formateurs["firstname"];
+		$s_email = $a_formateurs["email"];
+
+		if ($i%2 == 0) {
+			$s_css_class = "row_odd";
 			
-			if($i%20==0 && $i!=0){
-				echo '<tr>
-				<th>
-					'.get_lang('FirstName').'
-				</th>
-				<th>
-					'.get_lang('LastName').'
-				</th>
-				<th>
-					'.get_lang('Email').'
-				</th>
-				<th>
-					'.get_lang('AdminCourses').'
-				</th>
-				<th>
-					'.get_lang('Students').'
-				</th>
-			</tr>';
+			if ($i%20 == 0 && $i != 0){
+				echo '<tr><th>'.get_lang('FirstName').'</th><th>'.get_lang('LastName').'</th><th>'.get_lang('Email').'</th><th>'.get_lang('AdminCourses').'</th><th>'.get_lang('Students').'</th></tr>';
 			}
-			
-		}
-		else{
-			$s_css_class="row_even";
+		} else {
+			$s_css_class = "row_even";
 		}
-		
+
 		$i++;
-		
+
 		$a_data[$i_user_id]["firstname"]=$s_firstname;
 		$a_data[$i_user_id]["lastname"]=$s_lastname;
 		$a_data[$i_user_id]["email"]=$s_email;
-		
-		echo '<tr class="'.$s_css_class.'"><td>'.$s_firstname.'</td><td>'.$s_lastname.'</td><td><a href="mailto:'.$s_email.'">'.$s_email.'</a></td><td><a href="course.php?user_id='.$i_user_id.'">-></a></td><td><a href="student.php?user_id='.$i_user_id.'">-></a></td></tr>';
-		
+
+		echo '<tr class="'.$s_css_class.'"><td>'.$s_firstname.'</td><td>'.$s_lastname.'</td><td><a href="mailto:'.$s_email.'">'.$s_email.'</a></td><td><a href="course.php?user_id='.$i_user_id.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a></td><td><a href="student.php?user_id='.$i_user_id.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a></td></tr>';
 	}
-	
 }
 
 //No results
-else{
-	
+else {
 	echo '<tr><td colspan="5" "align=center">'.get_lang("NoResults").'</td></tr>';
-	
 }
-
 echo '</table>';
 
-
-if(isset($_POST['export'])){
-	
+if (isset($_POST['export'])) {
 	exportCsv($a_header,$a_data);
-	
 }
 
 echo "<br /><br />";
-echo "<form method='post' action='teachers.php'>
-		<input type='submit' name='export' value='".get_lang('exportExcel')."'/>
-	  <form>";
+echo "<form method='post' action='teachers.php'><input type='submit' name='export' value='".get_lang('exportExcel')."'/><form>";
 
 /*
 ==============================================================================
@@ -208,5 +149,3 @@ echo "<form method='post' action='teachers.php'>
 */
 
 Display::display_footer();
-
-?>

+ 100 - 128
main/mySpace/user_add.php

@@ -21,15 +21,15 @@
 */
 
 // name of the language file that needs to be included
-$language_file = array('admin','registration');
-$cidReset=true;
+$language_file = array('admin', 'registration');
+$cidReset = true;
 // including necessary libraries
-require ('../inc/global.inc.php');
+require '../inc/global.inc.php';
 $libpath = api_get_path(LIBRARY_PATH);
-include_once ($libpath.'fileManage.lib.php');
-include_once ($libpath.'fileUpload.lib.php');
-include_once ($libpath.'usermanager.lib.php');
-require_once ($libpath.'formvalidator/FormValidator.class.php');
+include_once $libpath.'fileManage.lib.php';
+include_once $libpath.'fileUpload.lib.php';
+include_once $libpath.'usermanager.lib.php';
+require_once $libpath.'formvalidator/FormValidator.class.php';
 
 // user permissions
 api_protect_admin_script(true);
@@ -40,7 +40,7 @@ $table_admin 	= Database :: get_main_table(TABLE_MAIN_ADMIN);
 $table_user 	= Database :: get_main_table(TABLE_MAIN_USER);
 
 $htmlHeadXtra[] = '
-<script language="JavaScript" type="text/JavaScript">
+<script type="text/javascript">
 <!--
 function enable_expiration_date() { //v2.0
 	document.user_add.radio_expiration_date[0].checked=false;
@@ -71,13 +71,12 @@ function display_drh_list(){
 //-->
 </script>';
 
-if(!empty($_GET['message'])) {
+if (!empty($_GET['message'])) {
 	$message = urldecode($_GET['message']);
 }
 
 $id_session='';
-if(isset($_GET["id_session"]) && $_GET["id_session"]!="")
-{
+if (isset($_GET["id_session"]) && $_GET["id_session"] != "") {
  	$id_session = Security::remove_XSS($_GET["id_session"]); 	
 	//$interbreadcrumb[] = array ("url" => "session.php", "name" => get_lang('Sessions')); 
 	//$interbreadcrumb[] = array ("url" => "course.php?id_session=".$_GET["id_session"]."", "name" => get_lang('Cours'));
@@ -89,84 +88,82 @@ $tool_name = get_lang('AddUser');
 // Create the form
 $form = new FormValidator('user_add');
 // Lastname
-$form->addElement('text','lastname',get_lang('LastName'));
-$form->applyFilter('lastname','html_filter');
-$form->applyFilter('lastname','trim');
+$form->addElement('text','lastname', get_lang('LastName'));
+$form->applyFilter('lastname', 'html_filter');
+$form->applyFilter('lastname', 'trim');
 $form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
 // Firstname
-$form->addElement('text','firstname',get_lang('FirstName'));
-$form->applyFilter('firstname','html_filter');
-$form->applyFilter('firstname','trim');
+$form->addElement('text','firstname', get_lang('FirstName'));
+$form->applyFilter('firstname', 'html_filter');
+$form->applyFilter('firstname', 'trim');
 $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
 // Official code
-$form->addElement('text', 'official_code', get_lang('OfficialCode'),array('size' => '40'));
-$form->applyFilter('official_code','html_filter');
-$form->applyFilter('official_code','trim');
+$form->addElement('text', 'official_code', get_lang('OfficialCode'), array('size' => '40'));
+$form->applyFilter('official_code', 'html_filter');
+$form->applyFilter('official_code', 'trim');
 // Email
-$form->addElement('text', 'email', get_lang('Email'),array('size' => '40'));
+$form->addElement('text', 'email', get_lang('Email'), array('size' => '40'));
 $form->addRule('email', get_lang('EmailWrong'), 'email');
 $form->addRule('email', get_lang('EmailWrong'), 'required');
 // Phone
-$form->addElement('text','phone',get_lang('PhoneNumber'));
+$form->addElement('text', 'phone', get_lang('PhoneNumber'));
 // Picture
 $form->addElement('file', 'picture', get_lang('AddPicture'));
 $allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif');
 $form->addRule('picture', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types);
 // Username
-$form->addElement('text', 'username', get_lang('LoginName'),array('maxlength'=>20));
+$form->addElement('text', 'username', get_lang('LoginName'), array('maxlength' => 20));
 $form->addRule('username', get_lang('ThisFieldIsRequired'), 'required');
 $form->addRule('username', get_lang('OnlyLettersAndNumbersAllowed'), 'username');
-$form->addRule('username', '', 'maxlength',20);
+$form->addRule('username', '', 'maxlength', 20);
 $form->addRule('username', get_lang('UserTaken'), 'username_available', $user_data['username']);
 // Password
 $group = array();
 $auth_sources = 0; //make available wider as we need it in case of form reset (see below)
-if(count($extAuthSource) > 0)
-{
-	$group[] =& HTML_QuickForm::createElement('radio','password_auto',null,get_lang('ExternalAuthentication').' ',2);
+if (count($extAuthSource) > 0) {
+	$group[] =& HTML_QuickForm::createElement('radio','password_auto', null, get_lang('ExternalAuthentication').' ', 2);
 	$auth_sources = array();
-	foreach($extAuthSource as $key => $info)
-	{
+	foreach ($extAuthSource as $key => $info) {
 		$auth_sources[$key] = $key;
 	}
-	$group[] =& HTML_QuickForm::createElement('select','auth_source',null,$auth_sources);
-	$group[] =& HTML_QuickForm::createElement('static','','','<br />');
+	$group[] =& HTML_QuickForm::createElement('select', 'auth_source', null, $auth_sources);
+	$group[] =& HTML_QuickForm::createElement('static', '', '', '<br />');
 }
-$group[] =& HTML_QuickForm::createElement('radio','password_auto',get_lang('Password'),get_lang('AutoGeneratePassword').'<br />',1);
-$group[] =& HTML_QuickForm::createElement('radio', 'password_auto','id="radio_user_password"',null,0);
-$group[] =& HTML_QuickForm::createElement('password', 'password',null,'onkeydown=password_switch_radio_button(document.user_add,"password[password_auto]")');
+$group[] =& HTML_QuickForm::createElement('radio', 'password_auto', get_lang('Password'), get_lang('AutoGeneratePassword').'<br />', 1);
+$group[] =& HTML_QuickForm::createElement('radio', 'password_auto', 'id="radio_user_password"', null, 0);
+$group[] =& HTML_QuickForm::createElement('password', 'password', null, array('onkeydown' => 'javascript: password_switch_radio_button(document.user_add,"password[password_auto]");'));
 $form->addGroup($group, 'password', get_lang('Password'), '');
 
 
 
 // Send email
 $group = array();
-$group[] =& HTML_QuickForm::createElement('radio', 'send_mail',null,get_lang('Yes'),1);
-$group[] =& HTML_QuickForm::createElement('radio', 'send_mail',null,get_lang('No'),0);
+$group[] =& HTML_QuickForm::createElement('radio', 'send_mail',null,get_lang('Yes'), 1);
+$group[] =& HTML_QuickForm::createElement('radio', 'send_mail',null,get_lang('No'), 0);
 $form->addGroup($group, 'mail', get_lang('SendMailToNewUser'), '&nbsp;');
 // Expiration Date
 $form->addElement('radio', 'radio_expiration_date', get_lang('ExpirationDate'), get_lang('NeverExpires'), 0);
 $group = array ();
 $group[] = & $form->createElement('radio', 'radio_expiration_date', null, get_lang('On'), 1);
-$group[] = & $form->createElement('datepicker','expiration_date', null, array ('form_name' => $form->getAttribute('name'), 'onChange'=>'enable_expiration_date()'));
+$group[] = & $form->createElement('datepicker', 'expiration_date', null, array('form_name' => $form->getAttribute('name'), 'onChange'=>'enable_expiration_date()'));
 $form->addGroup($group, 'max_member_group', null, '', false);
 // Active account or inactive account
-$form->addElement('radio','active',get_lang('ActiveAccount'),get_lang('Active'),1);
-$form->addElement('radio','active','',get_lang('Inactive'),0);
+$form->addElement('radio', 'active', get_lang('ActiveAccount'), get_lang('Active'), 1);
+$form->addElement('radio', 'active', '', get_lang('Inactive'), 0);
 
 
 //session list
 if (api_is_session_admin()) {
 	$where = 'WHERE session_admin_id='.intval(api_get_user_id());
 	$where .= ' AND ( (session.date_start <= CURDATE() AND session.date_end >= CURDATE()) OR session.date_start="0000-00-00" ) ';
-	$tbl_session=Database::get_main_table(TABLE_MAIN_SESSION);
-	$result=api_sql_query("SELECT id,name,nbr_courses,date_start,date_end 
-							FROM $tbl_session 					
-							$where
-							ORDER BY name",__FILE__,__LINE__);	
-	$a_sessions=api_store_result($result);		
+	$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
+	$result = Database::query("SELECT id,name,nbr_courses,date_start,date_end 
+		FROM $tbl_session 					
+		$where
+		ORDER BY name",__FILE__,__LINE__);
+	$a_sessions = api_store_result($result);		
 	$session_list = array();	
-	$session_list[0]=get_lang('SelectSession');
+	$session_list[0] = get_lang('SelectSession');
 	if (is_array($a_sessions)) {	
 		foreach ($a_sessions as $session) {
 			$session_list[$session['id']]=$session['name'];
@@ -177,16 +174,14 @@ if (api_is_session_admin()) {
 	//api_asort($session_list, SORT_STRING);
 	api_natsort($session_list);
 
-	$form->addElement('select','session_id',get_lang('Session'),$session_list);
+	$form->addElement('select', 'session_id', get_lang('Session'), $session_list);
 }		
 
 
 // EXTRA FIELDS
-$extra = UserManager::get_extra_fields(0,50,5,'ASC');
-foreach($extra as $id => $field_details)
-{
-	switch($field_details[2])
-	{
+$extra = UserManager::get_extra_fields(0, 50, 5, 'ASC');
+foreach ($extra as $id => $field_details) {
+	switch ($field_details[2]) {
 		case USER_FIELD_TYPE_TEXT:
 			$form->addElement('text', 'extra_'.$field_details[1], $field_details[3], array('size' => 40));
 			$form->applyFilter('extra_'.$field_details[1], 'stripslashes');
@@ -200,8 +195,7 @@ foreach($extra as $id => $field_details)
 			break;
 		case USER_FIELD_TYPE_RADIO:
 			$group = array();
-			foreach($field_details[9] as $option_id => $option_details)
-			{
+			foreach ($field_details[9] as $option_id => $option_details) {
 				$options[$option_details[1]] = $option_details[2];
 				$group[] =& HTML_QuickForm::createElement('radio', 'extra_'.$field_details[1], $option_details[1],$option_details[2].'<br />',$option_details[1]);
 			}
@@ -209,30 +203,28 @@ foreach($extra as $id => $field_details)
 			break;
 		case USER_FIELD_TYPE_SELECT:
 			$options = array();
-			foreach($field_details[9] as $option_id => $option_details)
-			{
+			foreach ($field_details[9] as $option_id => $option_details) {
 				$options[$option_details[1]] = $option_details[2];
 			}
 			$form->addElement('select','extra_'.$field_details[1],$field_details[3],$options,'');			
 			break;
 		case USER_FIELD_TYPE_SELECT_MULTIPLE:
 			$options = array();
-			foreach($field_details[9] as $option_id => $option_details)
-			{
+			foreach ($field_details[9] as $option_id => $option_details) {
 				$options[$option_details[1]] = $option_details[2];
 			}
 			$form->addElement('select','extra_'.$field_details[1],$field_details[3],$options,array('multiple' => 'multiple'));
 			break;
 		case USER_FIELD_TYPE_DATE:
 			$form->addElement('datepickerdate', 'extra_'.$field_details[1], $field_details[3]);
-			$form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear',1900);
+			$form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear', 1900);
 			$defaults['extra_'.$field_details[1]] = date('Y-m-d 12:00:00');
 			$form -> setDefaults($defaults);
 			$form->applyFilter('theme', 'trim');
 			break;
 		case USER_FIELD_TYPE_DATETIME:
 			$form->addElement('datepicker', 'extra_'.$field_details[1], $field_details[3]);
-			$form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear',1900);
+			$form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear', 1900);
 			$defaults['extra_'.$field_details[1]] = date('Y-m-d 12:00:00');
 			$form -> setDefaults($defaults);
 			$form->applyFilter('theme', 'trim');
@@ -249,9 +241,9 @@ $defaults['active'] = 1;
 $defaults['expiration_date']=array();
 $days = api_get_setting('account_valid_duration');
 $time = strtotime('+'.$days.' day');
-$defaults['expiration_date']['d']=date('d',$time);
-$defaults['expiration_date']['F']=date('m',$time);
-$defaults['expiration_date']['Y']=date('Y',$time);
+$defaults['expiration_date']['d'] = date('d',$time);
+$defaults['expiration_date']['F'] = date('m',$time);
+$defaults['expiration_date']['Y'] = date('Y',$time);
 $defaults['radio_expiration_date'] = 0;
 $defaults['status'] = STUDENT;
 $defaults['session_id'] = api_get_session_id();
@@ -262,22 +254,18 @@ $form->setDefaults($defaults);
 $form->addElement('submit', 'submit', get_lang('Add'));
 $form->addElement('submit', 'submit_plus', get_lang('Add').'+');
 // Validate form
-if( $form->validate())
-{
+if ($form->validate()) {
 	$check = Security::check_token('post');
-	if($check)
-	{
+	if ($check) {
 		$user = $form->exportValues();
 		$picture_element = & $form->getElement('picture');
 		$picture = $picture_element->getValue();
 		$picture_uri = '';
-		if (strlen($picture['name']) > 0)
-		{
-			if(!is_dir(api_get_path(SYS_CODE_PATH).'upload/users/')){
-				if(mkdir(api_get_path(SYS_CODE_PATH).'upload/users/'))
-				{
+		if (strlen($picture['name']) > 0) {
+			if (!is_dir(api_get_path(SYS_CODE_PATH).'upload/users/')) {
+				if (mkdir(api_get_path(SYS_CODE_PATH).'upload/users/')) {
 					$perm = api_get_setting('permissions_for_new_directories');
-					$perm = octdec(!empty($perm)?$perm:'0770');
+					$perm = octdec(!empty($perm) ? $perm : '0770');
 					chmod(api_get_path(SYS_CODE_PATH).'upload/users/');
 				}
 			}
@@ -296,95 +284,82 @@ if( $form->validate())
 		$platform_admin = intval($user['admin']['platform_admin']);
 		$send_mail = intval($user['mail']['send_mail']);
 		$hr_dept_id = intval($user['hr_dept_id']);
-		if(count($extAuthSource) > 0 && $user['password']['password_auto'] == '2')
-		{
+		if (count($extAuthSource) > 0 && $user['password']['password_auto'] == '2') {
 			$auth_source = $user['password']['auth_source'];
 			$password = 'PLACEHOLDER';
-		}
-		else
-		{
+		} else {
 			$auth_source = PLATFORM_AUTH_SOURCE;
 			$password = $user['password']['password_auto'] == '1' ? api_generate_password() : $user['password']['password'];
 		}
-		if ($user['radio_expiration_date']=='1' )
-		{
+		if ($user['radio_expiration_date']=='1') {
 			$expiration_date=$user['expiration_date'];
-		}
-		else
-		{
+		} else {
 			$expiration_date='0000-00-00 00:00:00';
 		}
 		$active = intval($user['active']);
 		// default status = student
 		$status =5;
 		//create user
-		$user_id = UserManager::create_user($firstname,$lastname,$status,$email,$username,$password,$official_code,api_get_setting('platformLanguage'),$phone,$picture_uri,$auth_source,$expiration_date,$active, $hr_dept_id);
-		
+		$user_id = UserManager::create_user($firstname, $lastname, $status, $email, $username, $password, $official_code, api_get_setting('platformLanguage'), $phone, $picture_uri, $auth_source, $expiration_date, $active, $hr_dept_id);
+
 		//adding to the session		
-		if (api_is_session_admin()) {			
+		if (api_is_session_admin()) {
 			$tbl_session_rel_course				= Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
 			$tbl_session_rel_course_rel_user	= Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
 			$tbl_session						= Database::get_main_table(TABLE_MAIN_SESSION);
 			$tbl_session_rel_user				= Database::get_main_table(TABLE_MAIN_SESSION_USER);
-			
+
 			$id_session = $user['session_id'];
-			if ($id_session!=0)
-			{
-				$result=api_sql_query("SELECT course_code FROM $tbl_session_rel_course WHERE id_session='$id_session'",__FILE__,__LINE__);
-		
+			if ($id_session != 0) {
+				$result = Database::query("SELECT course_code FROM $tbl_session_rel_course WHERE id_session='$id_session'",__FILE__,__LINE__);
+
 				$CourseList=array();	
-				while($row=Database::fetch_array($result)) {
-					$CourseList[]=$row['course_code'];
+				while ($row=Database::fetch_array($result)) {
+					$CourseList[] = $row['course_code'];
 				}
-		
-				foreach($CourseList as $enreg_course) {
-					api_sql_query("INSERT INTO $tbl_session_rel_course_rel_user(id_session,course_code,id_user) VALUES('$id_session','$enreg_course','$user_id')",__FILE__,__LINE__);
+
+				foreach ($CourseList as $enreg_course) {
+					Database::query("INSERT INTO $tbl_session_rel_course_rel_user(id_session,course_code,id_user) VALUES('$id_session','$enreg_course','$user_id')",__FILE__,__LINE__);
 					// updating the total				
 					$sql = "SELECT COUNT(id_user) as nbUsers FROM $tbl_session_rel_course_rel_user WHERE id_session='$id_session' AND course_code='$enreg_course'";
-					$rs = api_sql_query($sql, __FILE__, __LINE__);
+					$rs = Database::query($sql, __FILE__, __LINE__);
 					list($nbr_users) = Database::fetch_array($rs);
-					api_sql_query("UPDATE $tbl_session_rel_course SET nbr_users=$nbr_users WHERE id_session='$id_session' AND course_code='$enreg_course'",__FILE__,__LINE__);				
+					Database::query("UPDATE $tbl_session_rel_course SET nbr_users=$nbr_users WHERE id_session='$id_session' AND course_code='$enreg_course'",__FILE__,__LINE__);				
 				}		
-				
-				
-				api_sql_query("INSERT INTO $tbl_session_rel_user(id_session, id_user) VALUES('$id_session','$user_id')",__FILE__,__LINE__);
-				
-				
+
+				Database::query("INSERT INTO $tbl_session_rel_user(id_session, id_user) VALUES('$id_session','$user_id')", __FILE__, __LINE__);
+
 				$sql = "SELECT COUNT(nbr_users) as nbUsers FROM $tbl_session WHERE id='$id_session' ";
-				$rs = api_sql_query($sql, __FILE__, __LINE__);
+				$rs = Database::query($sql, __FILE__, __LINE__);
 				list($nbr_users) = Database::fetch_array($rs);
-				
-				api_sql_query("UPDATE $tbl_session SET nbr_users= $nbr_users WHERE id='$id_session' ",__FILE__,__LINE__);
-						
+
+				Database::query("UPDATE $tbl_session SET nbr_users= $nbr_users WHERE id='$id_session' ", __FILE__, __LINE__);
 			}
 		}		
 			
 		
 		$extras = array();
-		foreach($user as $key => $value)
-		{
-			if(substr($key,0,6)=='extra_') //an extra field
-			{
-				$myres = UserManager::update_extra_field_value($user_id,substr($key,6),$value);
+		foreach ($user as $key => $value) {
+			if (substr($key, 0, 6) == 'extra_') {
+				//an extra field
+				$myres = UserManager::update_extra_field_value($user_id, substr($key, 6), $value);
 			}
 		}
-		
-		if ($platform_admin)
-		{
+
+		if ($platform_admin) {
 			$sql = "INSERT INTO $table_admin SET user_id = '".$user_id."'";
-			api_sql_query($sql,__FILE__,__LINE__);
+			Database::query($sql, __FILE__, __LINE__);
 		}
-		if (!empty ($email) && $send_mail)
-		{
+		if (!empty ($email) && $send_mail) {
 			$emailto = '"'.$firstname.' '.$lastname.'" <'.$email.'>';
 			$emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName');
 			$emailheaders = 'From: '.api_get_setting('administratorName').' '.api_get_setting('administratorSurname').' <'.api_get_setting('emailAdministrator').">\n";
 			$emailheaders .= 'Reply-To: '.api_get_setting('emailAdministrator');
-			
+
 			$portal_url = $_configuration['root_web'];
 			if ($_configuration['multiple_access_urls']==true) {
 				$access_url_id = api_get_current_access_url_id();				
-				if ($access_url_id != -1 ){
+				if ($access_url_id != -1) {
 					$url = api_get_access_url($access_url_id);
 					$portal_url = $url['url'];
 				}
@@ -393,22 +368,19 @@ if( $form->validate())
 			@api_send_mail($emailto, $emailsubject, $emailbody, $emailheaders);
 		}
 		Security::clear_token();
-		if(isset($user['submit_plus']))
-		{
+		if (isset($user['submit_plus'])) {
 			//we want to add more. Prepare report message and redirect to the same page (to clean the form)
 			$tok = Security::get_token();
 			header('Location: user_add.php?message='.urlencode(get_lang('UserAdded')).'&sec_token='.$tok);
 			exit ();
-		}
-		else
-		{
+		} else {
 			$tok = Security::get_token();
 			header('Location: ../admin/user_list.php?action=show_message&message='.urlencode(get_lang('UserAdded')).'&sec_token='.$tok);
 			exit ();
 		}
 	}
 } else {
-	if(isset($_POST['submit'])) {
+	if (isset($_POST['submit'])) {
 		Security::clear_token();
 	}
 	$token = Security::get_token();
@@ -418,14 +390,14 @@ if( $form->validate())
 // Display form
 Display::display_header($tool_name);
 //api_display_tool_title($tool_name);
-if(!empty($message)) {
+if (!empty($message)) {
 	Display::display_normal_message(stripslashes($message));
 }
 $form->display();
+
 /*
 ==============================================================================
 		FOOTER
 ==============================================================================
 */
 Display::display_footer();
-?>

+ 237 - 349
main/mySpace/user_import.php

@@ -19,6 +19,7 @@
 	Contact: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium, info@dokeos.com
 ==============================================================================
 */
+
 /**
 ==============================================================================
 *   This tool allows platform admins to add users by uploading a CSV or XML file
@@ -26,6 +27,7 @@
 *   Created on 26 julio 2008  by Julio Montoya gugli100@gmail.com 
 ==============================================================================
 */
+
 /**
 Makes a username i.e Julio Montoya into jmontoya
 we check if the lastname have < 17 characteres 
@@ -34,22 +36,16 @@ we give 2 variables to a possible sufix. Sufix means the last numbers of the use
 @param string lastname
 @author Julio Montoya Armas
 */
-function make_login($firstname,$lastname)
-{
-	$desired_username='';	
-	if (api_strlen($lastname)<17)
-	{
-		$desired_username = api_substr($firstname,0,1).$lastname;
-	}
-	else
-	{
-		$desired_username = api_substr($firstname,0,1).api_substr($lastname,0,16);
+function make_login($firstname, $lastname) {
+	$desired_username = '';	
+	if (api_strlen($lastname) < 17) {
+		$desired_username = api_substr($firstname, 0, 1).$lastname;
+	} else {
+		$desired_username = api_substr($firstname, 0, 1).api_substr($lastname, 0, 16);
 	}	
 	return api_strtolower($desired_username);
 }
 
-
-		
 /**
 Checks if a username exist in the DB otherwise it create a "double" 
 ie. if we look into for jmontoya but the user's name already exist we create the user jmontoya2
@@ -60,43 +56,33 @@ the return array will be array(username=>'jmontoya', sufix='2')
 @return array with the username, the sufix 
 @author Julio Montoya Armas
 */
-function make_username($firstname, $lastname, $username)
-{
+function make_username($firstname, $lastname, $username) {
 	$table_user = Database::get_main_table(TABLE_MAIN_USER);
-	$tbl_session_rel_course_rel_user=Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);		
-	// if username exist 
-	if ( ! UserManager :: is_username_available($username) || empty($username) )  
-	{
-		$i=0;		
-		while (1)
-		{
-			if ($i==0)
-			{	
-				$sufix = '';						
+	$tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
+	// if username exist
+	if (!UserManager::is_username_available($username) || empty($username)) {
+		$i = 0;
+		while (1) {
+			if ($i == 0) {
+				$sufix = '';
+			} else {
+				$sufix = $i;
 			}
-			else
-			{
-				$sufix= $i;
-			}
-			$desired_username=make_login($firstname,$lastname);						
-			if (UserManager :: is_username_available($desired_username.$sufix)) 
-			{
+			$desired_username = make_login($firstname, $lastname);
+			if (UserManager::is_username_available($desired_username.$sufix)) {
 				break;
-			}
-			else
-			{
+			} else {
 				$i++;
-			}	
+			}
 		}
-		$username_array=array('username'=>$desired_username , 'sufix'=>$sufix);
-		return $username_array; 
-	}
-	else 
-	{
-		$username_array=array('username'=>$username , 'sufix'=>'');
+		$username_array = array('username' => $desired_username , 'sufix' => $sufix);
+		return $username_array;
+	} else {
+		$username_array = array('username' => $username, 'sufix' => '');
 		return $username_array;
 	}
 }
+
 /**
 Checks if there are repeted users in a given array
 
@@ -105,21 +91,17 @@ Checks if there are repeted users in a given array
 @return array with the $usernames array and the $user_array array
 @author Julio Montoya Armas
 */
-function check_user_in_array($usernames,$user_array)
-{
-	$user_list=array_keys($usernames);	
-	$username=$user_array['username'].$user_array['sufix'];
-	
-	if (in_array($username,$user_list))
-	{		
-		$user_array['sufix']+= $usernames[$username];
+function check_user_in_array($usernames, $user_array) {
+	$user_list = array_keys($usernames);
+	$username = $user_array['username'].$user_array['sufix'];
+
+	if (in_array($username, $user_list)) {
+		$user_array['sufix'] += $usernames[$username];
 		$usernames[$username]++;
+	} else {
+		$usernames[$username] = 1;
 	}
-	else
-	{
-		$usernames[$username]=1;
-	}
-	$result_array=array($usernames,$user_array);
+	$result_array = array($usernames, $user_array);
 	return $result_array;
 }
 
@@ -130,86 +112,71 @@ function check_user_in_array($usernames,$user_array)
  * @return 0 if the user is not subscribed  otherwise it returns the user_id of the given username 
  * @author Julio Montoya Armas
  */
-function user_available_in_session($username, $CourseList,$id_session)
-{
+function user_available_in_session($username, $CourseList, $id_session) {
 	$table_user = Database::get_main_table(TABLE_MAIN_USER);
-	$tbl_session_rel_course_rel_user=Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);		
-	
-	foreach($CourseList as $enreg_course)
-	{				
+	$tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);		
+
+	foreach($CourseList as $enreg_course) {
 		$sql_select = "SELECT u.user_id FROM $tbl_session_rel_course_rel_user rel INNER JOIN $table_user u
 		on (rel.id_user=u.user_id)
 		WHERE rel.id_session='$id_session' AND u.status='5' AND u.username ='$username' AND rel.course_code='$enreg_course'";	
 		//echo "<br>";
-		$rs = api_sql_query($sql_select, __FILE__, __LINE__);	
-		if (Database::num_rows($rs) > 0)
-		{
-			return Database::result($rs,0,0); 
+		$rs = Database::query($sql_select, __FILE__, __LINE__);
+		if (Database::num_rows($rs) > 0) {
+			return Database::result($rs, 0, 0); 
+		} else {
+			return 0;
 		}
-		else		
-			return 0; 
 	}
-
 }
 
 /**
 This function checks if the users in the uploaded file are not repeted and creates the username if necesary
-i.e if in the file there are an user repeted twice (Julio Montoya / Julio Montoya) and the username fields are empty. IN this case, 
+i.e if in the file there are an user repeted twice (Julio Montoya / Julio Montoya) and the username fields are empty. IN this case,
 this function will create the usernames based in the first and last name. The users will be jmontoya and jmontoya2
 but if in the database there is a user with a name jmontoya the users registered will be jmontoya2 and jmontoya3.
 @param $users list of users
 @author Julio Montoya Armas
 */
-function check_all_usernames($users,$CourseList, $id_session)
-{
-	$table_user = Database::get_main_table(TABLE_MAIN_USER);	
-	$usernames = array ();
-	$new_users=array();	
-	foreach ($users as $index => $user)
-	{	
-		$user['UserName']=str_replace(' ', '',trim($user['UserName'])); 
-		$desired_username=array();		
-		if (empty($user['UserName']))
-		{			
-			$desired_username =make_username($user['FirstName'],$user['LastName'],'');
-			$pre_username= $desired_username['username'].$desired_username['sufix'];
+function check_all_usernames($users, $CourseList, $id_session) {
+	$table_user = Database::get_main_table(TABLE_MAIN_USER);
+	$usernames = array();
+	$new_users = array();
+	foreach ($users as $index => $user) {
+		$user['UserName'] = str_replace(' ', '', trim($user['UserName']));
+		$desired_username = array();
+		if (empty($user['UserName'])) {
+			$desired_username = make_username($user['FirstName'], $user['LastName'], '');
+			$pre_username = $desired_username['username'].$desired_username['sufix'];
 			$user['UserName'] = $pre_username;
 			$user['create'] = '1';
-		}
-		else
-		{	
-			if (UserManager :: is_username_available($user['UserName']))
-			{	
-				$desired_username = make_username($user['FirstName'],$user['LastName'],$user['UserName']);									
-				$user['UserName'] = $desired_username['username'].$desired_username['sufix'];	
-				$user['create'] = '1';											
-			}
-			else
-			{
-				$is_session_avail= user_available_in_session($user['UserName'], $CourseList, $id_session);			
-				if ($is_session_avail==0)
-				{
-					//$desired_username = make_username($user['FirstName'],$user['LastName'],$user['UserName']);									
-					//$user['UserName'] = $desired_username['username'].$desired_username['sufix'];	
+		} else {
+			if (UserManager::is_username_available($user['UserName'])) {
+				$desired_username = make_username($user['FirstName'], $user['LastName'], $user['UserName']);
+				$user['UserName'] = $desired_username['username'].$desired_username['sufix'];
+				$user['create'] = '1';
+			} else {
+				$is_session_avail = user_available_in_session($user['UserName'], $CourseList, $id_session);
+				if ($is_session_avail == 0) {
+					//$desired_username = make_username($user['FirstName'],$user['LastName'],$user['UserName']);
+					//$user['UserName'] = $desired_username['username'].$desired_username['sufix'];
 					$user_name = $user['UserName'];
 					//echo "<br>";
-					$sql_select = "SELECT user_id FROM $table_user WHERE username ='$user_name' ";	
-					$rs = api_sql_query($sql_select, __FILE__, __LINE__);	
-					$user['create'] =Database::result($rs,0,0); // this should be the ID because the user exist
+					$sql_select = "SELECT user_id FROM $table_user WHERE username ='$user_name' ";
+					$rs = Database::query($sql_select, __FILE__, __LINE__);
+					$user['create'] = Database::result($rs, 0, 0); // this should be the ID because the user exist
 					//echo '<br>';
+				} else {
+					$user['create'] = $is_session_avail;
 				}
-				else
-				{	
-					$user['create'] = $is_session_avail;	
-				}						
 			}
-		}	
+		}
 		// usernames is the current list of users in the file
-		$result_array=check_user_in_array($usernames,$desired_username);
-		$usernames=$result_array[0];
-		$desired_username=$result_array[1];	
-		$user['UserName']=$desired_username['username'].$desired_username['sufix'];		
-		$new_users[]=$user;		
+		$result_array = check_user_in_array($usernames, $desired_username);
+		$usernames = $result_array[0];
+		$desired_username = $result_array[1];
+		$user['UserName'] = $desired_username['username'].$desired_username['sufix'];
+		$new_users[] = $user;
 	}
 	return $new_users;
 }
@@ -220,29 +187,25 @@ function check_all_usernames($users,$CourseList, $id_session)
  * @param the session id 
  * @author Julio Montoya Armas
  */
-function get_user_creator($users,$CourseList, $id_session)
-{ 
-	$errors=array();	
-	foreach ($users as $index => $user)
-	{	
+function get_user_creator($users,$CourseList, $id_session) {
+	$errors = array();
+	foreach ($users as $index => $user) {
 		// database table definition
 		$table_user = Database::get_main_table(TABLE_MAIN_USER);
-		$tbl_session_rel_course_rel_user=Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);		
-		$username=$user['UserName'];	
-		//echo "<br>";	
-		$sql ="SELECT creator_id FROM $table_user WHERE username='$username' ";
-	
-		$rs=api_sql_query($sql,__FILE__,__LINE__);
-		$creator_id=Database::result($rs,0,0);
+		$tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
+		$username = $user['UserName'];
+		//echo "<br>";
+		$sql = "SELECT creator_id FROM $table_user WHERE username='$username' ";
+
+		$rs = Database::query($sql, __FILE__, __LINE__);
+		$creator_id = Database::result($rs, 0, 0);
 		// check if we are the creators or not
-		if ($creator_id!='')
-		{	
-			if ($creator_id != api_get_user_id())
-			{
+		if ($creator_id != '') {	
+			if ($creator_id != api_get_user_id()) {
 				$user['error'] = get_lang('UserAlreadyRegisteredByOtherCreator');
 				$errors[] = $user;
 			}
-		}	
+		}
 	}
 	return $errors;
 }
@@ -252,55 +215,46 @@ function get_user_creator($users,$CourseList, $id_session)
  * validate the imported data
  * @param list of users 
  */
-function validate_data($users,$id_session)
-{
-	$errors = array ();
-	$usernames = array ();
-	$new_users=array();
-	foreach ($users as $index => $user)
-	{
-		//1. check if mandatory fields are set	
-		$mandatory_fields = array ('LastName', 'FirstName');
-		if (api_get_setting('registration', 'email') == 'true')
-		{
-			$mandatory_fields[] = 'Email';	
+function validate_data($users, $id_session) {
+	$errors = array();
+	$usernames = array();
+	$new_users = array();
+	foreach ($users as $index => $user) {
+		//1. check if mandatory fields are set
+		$mandatory_fields = array('LastName', 'FirstName');
+		if (api_get_setting('registration', 'email') == 'true') {
+			$mandatory_fields[] = 'Email';
 		}
-			
-		foreach ($mandatory_fields as $key => $field)
-		{
-			if (!isset ($user[$field]) || strlen($user[$field]) == 0)
-			{
+
+		foreach ($mandatory_fields as $key => $field) {
+			if (!isset ($user[$field]) || strlen($user[$field]) == 0) {
 				$user['error'] = get_lang($field.'Mandatory');
 				$errors[] = $user;
 			}
 		}
 		// 2. check if the username is too long
-		if (api_strlen($user['UserName']) > 20)
-		{
+		if (api_strlen($user['UserName']) > 20) {
 			$user['error'] = get_lang('UserNameTooLong');
 			$errors[] = $user;
 		}
-		
-		$user['UserName']=trim($user['UserName']);
-			
-		if (strlen($user['UserName']) == 0 || $user['UserName']=='' )
-		{
-			 $user['UserName'] =make_login($user['FirstName'],$user['LastName']);		
+
+		$user['UserName'] = trim($user['UserName']);
+
+		if (strlen($user['UserName']) == 0 || $user['UserName'] == '') {
+			 $user['UserName'] = make_login($user['FirstName'], $user['LastName']);
 		}
-		$new_users[]=$user;
+		$new_users[] = $user;
 	}
-	$results=array('errors'=>$errors,'users'=>$new_users);
+	$results = array('errors' => $errors, 'users' => $new_users);
 	return $results;
 }
 
 /**
  * Add missing user-information (which isn't required, like password, etc)
  */
-function complete_missing_data($user)
-{
+function complete_missing_data($user) {
 	//1. generate a password if necessary
-	if (!isset ($user['Password']) || strlen($user['Password']) == 0)
-	{
+	if (!isset ($user['Password']) || strlen($user['Password']) == 0) {
 		$user['Password'] = api_generate_password();
 	}
 	return $user;
@@ -308,158 +262,129 @@ function complete_missing_data($user)
 /**
  * Save the imported data
  */
-function save_data($users, $CourseList,$id_session)
-{
+function save_data($users, $CourseList, $id_session) {
 	$tbl_session						= Database::get_main_table(TABLE_MAIN_SESSION);
 	$tbl_session_rel_course				= Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
 	$tbl_session_rel_course_rel_user	= Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
 	$tbl_session_rel_user				= Database::get_main_table(TABLE_MAIN_SESSION_USER);
-	
+
 	$sendMail = $_POST['sendMail'] ? 1 : 0;
-	
+
 	// adding users to the platform	
-	$new_users=array();
-	foreach ($users as $index => $user)
-	{
+	$new_users = array();
+	foreach ($users as $index => $user) {
 		$user = complete_missing_data($user);		
 		// coach only will registered users
-		$default_status = '5';		
-		if ($user['create']=='1')
-		{
-			$user['id']=UserManager :: create_user($user['FirstName'], $user['LastName'], $default_status , $user['Email'], $user['UserName'], $user['Password'], $user['OfficialCode'], api_get_setting('PlatformLanguage'), $user['PhoneNumber'], '');
-			$user['added_at_platform']=1;		
+		$default_status = '5';
+		if ($user['create'] == '1') {
+			$user['id'] = UserManager :: create_user($user['FirstName'], $user['LastName'], $default_status , $user['Email'], $user['UserName'], $user['Password'], $user['OfficialCode'], api_get_setting('PlatformLanguage'), $user['PhoneNumber'], '');
+			$user['added_at_platform'] = 1;
+		} else {
+			$user['id'] = $user['create'];
+			$user['added_at_platform'] = 0;
 		}
-		else
-		{
-			$user['id']=$user['create'];
-			$user['added_at_platform']=0;			
-		}
-		$new_users[]=$user;		
+		$new_users[] = $user;
 	}
 	//update users list 
 	$users = $new_users;
 	
 	// inserting users
-	$super_list =array();		
-	foreach($CourseList as $enreg_course)
-	{
-		$nbr_users=0;	
-		$new_users =array();	
-		foreach ($users as $index => $user)
-		{
+	$super_list = array();
+	foreach ($CourseList as $enreg_course) {
+		$nbr_users = 0;	
+		$new_users = array();	
+		foreach ($users as $index => $user) {
 			$userid = $user['id'];		
-			$sql= "INSERT IGNORE INTO $tbl_session_rel_course_rel_user(id_session,course_code,id_user) VALUES('$id_session','$enreg_course','$userid')";
+			$sql = "INSERT IGNORE INTO $tbl_session_rel_course_rel_user(id_session,course_code,id_user) VALUES('$id_session','$enreg_course','$userid')";
 			//echo "<br>";
-			$course_session=array('course'=>$enreg_course,'added'=>1);
-			//$user['added_at_session']=$course_session;
-			api_sql_query($sql,__FILE__,__LINE__);
-			if(mysql_affected_rows())
-			{
+			$course_session=array('course' => $enreg_course, 'added' => 1);
+			//$user['added_at_session'] = $course_session;
+			Database::query($sql, __FILE__, __LINE__);
+			if (Database::affected_rows()) {
 				$nbr_users++;
 			}
-			$new_users[]=$user;	
+			$new_users[] = $user;	
 		}		
-		$super_list[]=$new_users;
-		
+		$super_list[] = $new_users;
+
 		//update the nbr_users field
 		$sql_select = "SELECT COUNT(id_user) as nbUsers FROM $tbl_session_rel_course_rel_user WHERE id_session='$id_session' AND course_code='$enreg_course'";
-		$rs = api_sql_query($sql_select, __FILE__, __LINE__);
+		$rs = Database::query($sql_select, __FILE__, __LINE__);
 		list($nbr_users) = Database::fetch_array($rs);
 		$sql_update = "UPDATE $tbl_session_rel_course SET nbr_users=$nbr_users WHERE id_session='$id_session' AND course_code='$enreg_course'";		
-		api_sql_query($sql_update ,__FILE__,__LINE__);
-					
+		Database::query($sql_update , __FILE__, __LINE__);
+
 		$sql_update = "UPDATE $tbl_session SET nbr_users= '$nbr_users' WHERE id='$id_session'";
-		api_sql_query($sql_update,__FILE__,__LINE__);		
+		Database::query($sql_update, __FILE__, __LINE__);		
 	}	
 	// we dont delete the users (thoughts while dreaming) 
 	//$sql_delete = "DELETE FROM $tbl_session_rel_user WHERE id_session = '$id_session'";
-	//api_sql_query($sql_delete,__FILE__, __LINE__);
-		
-	$new_users=array();		
-	foreach ($users as $index => $user)
-	{	
-		$userid = $user['id'];	
+	//Database::query($sql_delete,__FILE__, __LINE__);
+
+	$new_users = array();		
+	foreach ($users as $index => $user) {
+		$userid = $user['id'];
 		$sql_insert = "INSERT IGNORE INTO $tbl_session_rel_user(id_session, id_user) VALUES('$id_session','$userid')";
-		api_sql_query($sql_insert,__FILE__,__LINE__);		
-		$user['added_at_session']=1;
-		$new_users[]=$user;
+		Database::query($sql_insert, __FILE__, __LINE__);
+		$user['added_at_session'] = 1;
+		$new_users[] = $user;
 	}
-	
-	$users=$new_users;	
-	$registered_users=get_lang('FileImported').'<br /> Import file results : <br />';
+
+	$users = $new_users;	
+	$registered_users = get_lang('FileImported').'<br /> Import file results : <br />';
 	// sending the email
-	$addedto='';
-	if ($sendMail)
-	{					
-		$i=0;			
-		foreach ($users as $index => $user)
-		{				
-			$emailto =$user['FirstName'].' '.$user['LastName'].' <'.$user['Email'].'>';
+	$addedto = '';
+	if ($sendMail) {					
+		$i = 0;			
+		foreach ($users as $index => $user) {				
+			$emailto = $user['FirstName'].' '.$user['LastName'].' <'.$user['Email'].'>';
 			$emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName');
 			$emailbody = get_lang('Dear').' '.$user['FirstName'].' '.$user['LastName'].",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName')." ".get_lang('Settings')." $user[UserName]\n".get_lang('Pass')." : $user[Password]\n\n".get_lang('Address')." ".api_get_setting('siteName')." ".get_lang('Is')." : ".api_get_path('WEB_PATH')." \n\n".get_lang('Problem')."\n\n".get_lang('Formula').",\n\n".api_get_setting('administratorName')." ".api_get_setting('administratorSurname')."\n".get_lang('Manager')." ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n".get_lang('Email')." : ".api_get_setting('emailAdministrator')."";
 			$emailheaders = 'From: '.api_get_setting('administratorName').' '.api_get_setting('administratorSurname').' <'.api_get_setting('emailAdministrator').">\n";
 			$emailheaders .= 'Reply-To: '.api_get_setting('emailAdministrator');		
-			@ api_send_mail($emailto, $emailsubject, $emailbody, $emailheaders);
-			
-			if ( ($user['added_at_platform']== 1  && $user['added_at_session']==1) || $user['added_at_session']==1)
-			{				
-				if ($user['added_at_platform']==1)
-				{
-					$addedto=get_lang('UserCreatedPlatform');
-				}
-				else 
-				{
-					$addedto='          ';
+			@api_send_mail($emailto, $emailsubject, $emailbody, $emailheaders);
+
+			if (($user['added_at_platform'] == 1  && $user['added_at_session'] == 1) || $user['added_at_session'] == 1) {				
+				if ($user['added_at_platform'] == 1) {
+					$addedto = get_lang('UserCreatedPlatform');
+				} else  {
+					$addedto = '          ';
 				}
-				
-				if ($user['added_at_session']==1)
-				{
-					$addedto.=get_lang('UserInSession');
+
+				if ($user['added_at_session'] == 1) {
+					$addedto .= get_lang('UserInSession');
 				}			
-				$registered_users.= "<a href=\"../user/userInfo.php?uInfo=".$user['id']."\">".$user['FirstName']." ".$user['LastName']."</a> - ".$addedto.'<br />';
-			}
-			else
-			{
-				$addedto= get_lang('UserNotAdded');				
-				$registered_users.= "<a href=\"../user/userInfo.php?uInfo=".$user['id']."\">".$user['FirstName']." ".$user['LastName']."</a> - ".$addedto.'<br />';				
+				$registered_users .= "<a href=\"../user/userInfo.php?uInfo=".$user['id']."\">".$user['FirstName']." ".$user['LastName']."</a> - ".$addedto.'<br />';
+			} else {
+				$addedto = get_lang('UserNotAdded');				
+				$registered_users .= "<a href=\"../user/userInfo.php?uInfo=".$user['id']."\">".$user['FirstName']." ".$user['LastName']."</a> - ".$addedto.'<br />';				
 			}
 		}
-	}
-	else
-	{	
-		$i=0;			
-		foreach ($users as $index => $user)
-		{				
-			if ( ($user['added_at_platform']== 1  && $user['added_at_session']==1) || $user['added_at_session']==1)
-			{				
-				if ($user['added_at_platform']==1)
-				{
-					$addedto=get_lang('UserCreatedPlatform');
-				}
-				else
-				{
-					$addedto='          ';
+	} else {	
+		$i = 0;			
+		foreach ($users as $index => $user) {				
+			if (($user['added_at_platform'] == 1 && $user['added_at_session'] == 1) || $user['added_at_session'] == 1) {				
+				if ($user['added_at_platform'] == 1) {
+					$addedto = get_lang('UserCreatedPlatform');
+				} else {
+					$addedto = '          ';
 				}
-				
-				if ($user['added_at_session']==1)
-				{
-					$addedto.=' '.get_lang('UserInSession');
+
+				if ($user['added_at_session'] == 1) {
+					$addedto .= ' '.get_lang('UserInSession');
 				}
-			
-				$registered_users.= "<a href=\"../user/userInfo.php?uInfo=".$user['id']."\">".$user['FirstName']." ".$user['LastName']."</a> - ".$addedto.'<br />';
-			}
-			else
-			{
-				$addedto= get_lang('UserNotAdded');				
-				$registered_users.= "<a href=\"../user/userInfo.php?uInfo=".$user['id']."\">".$user['FirstName']." ".$user['LastName']."</a> - ".$addedto.'<br />';				
+
+				$registered_users .= "<a href=\"../user/userInfo.php?uInfo=".$user['id']."\">".$user['FirstName']." ".$user['LastName']."</a> - ".$addedto.'<br />';
+			} else {
+				$addedto = get_lang('UserNotAdded');				
+				$registered_users .= "<a href=\"../user/userInfo.php?uInfo=".$user['id']."\">".$user['FirstName']." ".$user['LastName']."</a> - ".$addedto.'<br />';				
 			}								
-		
 		}		
 	}
-		
+
 	header('Location: course.php?id_session='.$id_session.'&action=show_message&message='.urlencode($registered_users));
 	exit ();
-	
+
 	//header('Location: resume_session.php?id_session='.$id_session);
 }
 /**
@@ -467,13 +392,10 @@ function save_data($users, $CourseList,$id_session)
  * @param string $file Path to the CSV-file
  * @return array All userinformation read from the file
  */
-function parse_csv_data($file)
-{
+function parse_csv_data($file) {
 	$users = Import :: csv_to_array($file);
-	foreach ($users as $index => $user)
-	{
-		if (isset ($user['Courses']))
-		{
+	foreach ($users as $index => $user) {
+		if (isset ($user['Courses'])) {
 			$user['Courses'] = explode('|', trim($user['Courses']));
 		}
 		$users[$index] = $user;
@@ -483,12 +405,10 @@ function parse_csv_data($file)
 /**
  * XML-parser: handle start of element
  */
-function element_start($parser, $data)
-{
+function element_start($parser, $data) {
 	global $user;
 	global $current_tag;
-	switch ($data)
-	{
+	switch ($data) {
 		case 'Contact' :
 			$user = array ();
 			break;
@@ -499,14 +419,12 @@ function element_start($parser, $data)
 /**
  * XML-parser: handle end of element
  */
-function element_end($parser, $data)
-{
+function element_end($parser, $data) {
 	global $user;
 	global $users;
 	global $current_value;
 	$user[$data] = $current_value;
-	switch ($data)
-	{
+	switch ($data) {
 		case 'Contact' :			
 			$users[] = $user;
 			break;
@@ -518,8 +436,7 @@ function element_end($parser, $data)
 /**
  * XML-parser: handle character data
  */
-function character_data($parser, $data)
-{
+function character_data($parser, $data) {
 	global $current_value;
 	$current_value = $data;
 }
@@ -528,8 +445,7 @@ function character_data($parser, $data)
  * @param string $file Path to the XML-file
  * @return array All userinformation read from the file
  */
-function parse_xml_data($file)
-{
+function parse_xml_data($file) {
 	global $current_tag;
 	global $current_value;
 	global $user;
@@ -544,10 +460,10 @@ function parse_xml_data($file)
 	return $users;
 }
 // name of the language file that needs to be included
-$language_file = array ('admin','registration', 'index','trad4all', 'tracking');
+$language_file = array ('admin', 'registration', 'index', 'trad4all', 'tracking');
 
 $cidReset = true;
-include ('../inc/global.inc.php');
+include '../inc/global.inc.php';
 $this_section = SECTION_PLATFORM_ADMIN;
 
 require_once (api_get_path(LIBRARY_PATH).'fileManage.lib.php');
@@ -562,112 +478,85 @@ $tool_name = get_lang('ImportUserListXMLCSV');
 api_block_anonymous_users();
 
 $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
-$id_session='';
-if(isset($_GET["id_session"]) && $_GET["id_session"]!="")
-{
+$id_session = '';
+if (isset($_GET["id_session"]) && $_GET["id_session"] != "") {
  	$id_session = Security::remove_XSS($_GET["id_session"]); 	
 	$interbreadcrumb[] = array ("url" => "session.php", "name" => get_lang('Sessions')); 
 	$interbreadcrumb[] = array ("url" => "course.php?id_session=".$_GET["id_session"]."", "name" => get_lang('Course'));
 }
 
- //checking if the current coach is the admin coach
+//checking if the current coach is the admin coach
 /*
-if (!api_is_coach()) 
-{
-	api_not_allowed(true); 
+if (!api_is_coach()) {
+	api_not_allowed(true);
 }
 */
 //checking if the current coach is the admin coach
-if (api_get_setting('add_users_by_coach')=='true')
-{
-	if(!api_is_platform_admin())
-	{
-		if (isset($_REQUEST['id_session']))
-		{
-			$id_session=$_REQUEST['id_session'];
+if (api_get_setting('add_users_by_coach') == 'true') {
+	if (!api_is_platform_admin()) {
+		if (isset($_REQUEST['id_session'])) {
+			$id_session = $_REQUEST['id_session'];
 			$sql = 'SELECT id_coach FROM '.Database :: get_main_table(TABLE_MAIN_SESSION).' WHERE id='.$id_session;
-			$rs = api_sql_query($sql,__FILE__,__LINE__);
-			if(mysql_result($rs,0,0)!=$_user['user_id'])	
-			{
+			$rs = Database::query($sql, __FILE__, __LINE__);
+			if (Database::result($rs, 0, 0) != $_user['user_id']) {
 				api_not_allowed(true);  
 			}
-		}
-		else
-		{
-				api_not_allowed(true);  
+		} else {
+			api_not_allowed(true);  
 		}	
 	}
-}
-else
-{
+} else {
 	api_not_allowed(true);  
 }
 
 set_time_limit(0);
 
-if ($_POST['formSent'] AND $_FILES['import_file']['size'] !== 0)
-{		
+if ($_POST['formSent'] && $_FILES['import_file']['size'] !== 0) {		
 	$file_type = $_POST['file_type'];
 	$id_session = $_POST['id_session'];
-	if ($file_type == 'csv')
-	{
+	if ($file_type == 'csv') {
 		$users = parse_csv_data($_FILES['import_file']['tmp_name']);
-	}
-	else
-	{		
+	} else {
 		$users = parse_xml_data($_FILES['import_file']['tmp_name']);		
 	}
-	if (count($users) >0 )
-	{
+	if (count($users) >0) {
 		$results = validate_data($users);		
 		$errors = $results['errors'];
 		$users = $results['users'];
-		
-		if (count($errors) == 0)
-		{			
-			if (!empty($id_session))
-			{		
+
+		if (count($errors) == 0) {
+			if (!empty($id_session)) {
 				$tbl_session_rel_course	= Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
 				//selecting all the courses from the session id requested
-				$sql ="SELECT course_code FROM $tbl_session_rel_course WHERE id_session='$id_session'";
-				$result=api_sql_query($sql,__FILE__,__LINE__);
-				$CourseList=array();
-				while($row=Database::fetch_array($result)) 
-				{
-					$CourseList[]=$row['course_code'];
+				$sql = "SELECT course_code FROM $tbl_session_rel_course WHERE id_session='$id_session'";
+				$result = Database::query($sql, __FILE__, __LINE__);
+				$CourseList = array();
+				while ($row = Database::fetch_array($result)) {
+					$CourseList[] = $row['course_code'];
 				}
-				$errors=get_user_creator($users,$CourseList, $id_session);
-				$users=check_all_usernames($users,$CourseList, $id_session);
-				if (count($errors) == 0)
-				{				
-					save_data($users,$CourseList,$id_session);
-				}		
-			}
-			else
-			{
+				$errors = get_user_creator($users, $CourseList, $id_session);
+				$users = check_all_usernames($users, $CourseList, $id_session);
+				if (count($errors) == 0) {
+					save_data($users, $CourseList, $id_session);
+				}
+			} else {
 				header('Location: course.php?id_session='.$id_session.'&action=error_message&message='.urlencode(get_lang('NoSessionId')));
 			}
 		}
-	}
-	else
-	{
+	} else {
 		header('Location: course.php?id_session='.$id_session.'&action=error_message&message='.urlencode(get_lang('NoUsersRead')));
 	}
 }
 
 Display :: display_header($tool_name);
 
-if($_FILES['import_file']['size'] == 0 AND $_POST)
-{
+if ($_FILES['import_file']['size'] == 0 AND $_POST) {
 	Display::display_error_message(get_lang('ThisFieldIsRequired'));
 }
 
-				
-if (count($errors) != 0)
-{
+if (count($errors) != 0) {
 	$error_message = '<ul>';
-	foreach ($errors as $index => $error_user)
-	{
+	foreach ($errors as $index => $error_user) {
 		$error_message .= '<li><b>'.$error_user['error'].'</b>: ';
 		$error_message .= $error_user['FirstName'].' '.$error_user['LastName'];
 		$error_message .= '</li>';
@@ -731,4 +620,3 @@ $form->display();
 ==============================================================================
 */
 Display :: display_footer();
-?>

Some files were not shown because too many files changed in this diff