Browse Source

[svn r9915] Files update for My Space

Eric Marguin 18 years ago
parent
commit
0c7aa7f762
5 changed files with 897 additions and 181 deletions
  1. 37 13
      main/mySpace/coaches.php
  2. 188 72
      main/mySpace/cours.php
  3. 274 48
      main/mySpace/index.php
  4. 136 11
      main/mySpace/session.php
  5. 262 37
      main/mySpace/student.php

+ 37 - 13
main/mySpace/coaches.php

@@ -21,6 +21,7 @@ Display :: display_header($nameTools);
 api_display_tool_title($nameTools);
 
 $tbl_course = Database :: get_main_table(MAIN_COURSE_TABLE);
+$tbl_course_user = Database :: get_main_table(MAIN_COURSE_USER_TABLE);
 $tbl_user = Database :: get_main_table(MAIN_USER_TABLE);
 $tbl_session = Database :: get_main_table(MAIN_SESSION_TABLE);
 $tbl_session_rel_course = Database :: get_main_table(MAIN_SESSION_COURSE_TABLE);
@@ -98,33 +99,56 @@ $tbl_track_login = Database :: get_statistic_table(STATISTIC_TRACK_E_LOGIN_TABLE
 	
 	}
 
+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);
+	  
+	if(mysql_num_rows($result)>0){
+	    return true;	    
+	}
+	else{
+		return false;
+	}
+  
+}
+
 
 /**
  * MAIN PART
  */
 
-/*
- * liste nominative avec coordonnées et lien vers les cours et
-les stagiaires dont il est le
-responsable. 
- */
-
 if(isset($_GET["id_student"])){
 	
 	$i_id_student=$_GET["id_student"];
 	$sqlCoachs = "SELECT DISTINCT src.id_coach " .
-					"FROM $tbl_session_rel_course as src, $tbl_session_rel_course_rel_user as srcru, $tbl_user as user " .
-					"WHERE src.id_coach<>'0' AND src.course_code=srcru.course_code AND srcru.id_user='$i_id_student' AND srcru.id_user=user.user_id
+					"FROM $tbl_session_rel_course as src, $tbl_session_rel_course_rel_user as srcru " .
+					"WHERE src.id_coach<>'0' AND src.course_code=srcru.course_code AND srcru.id_user='$i_id_student' AND srcru.id_session=src.id_session 
 				  ";
 
 }
 
 else{
-$sqlCoachs = "	SELECT DISTINCT id_coach, user_id, lastname, firstname
-					FROM $tbl_user, $tbl_session_rel_course
-					WHERE id_coach=user_id
-					ORDER BY lastname ASC
-				  ";
+	if(api_is_platform_admin()){
+		$sqlCoachs = "	SELECT DISTINCT id_coach, user_id, lastname, firstname
+						FROM $tbl_user, $tbl_session_rel_course
+						WHERE id_coach=user_id
+						ORDER BY lastname ASC
+					  ";
+	}
+	else{
+		
+		$sqlCoachs = "	SELECT DISTINCT id_coach, $tbl_user.user_id, lastname, firstname
+						FROM $tbl_user as user, $tbl_session_rel_course as session_rel_course, $tbl_course_user as course_rel_user  
+						WHERE course_rel_user.course_code=session_rel_course.course_code AND course_rel_user.status='1' AND course_rel_user.user_id='".$_SESSION["_uid"]."' 
+						AND session_rel_course.id_coach=user.user_id 
+						ORDER BY lastname ASC
+					  ";
+	
+	}
 }
 $resultCoachs = api_sql_query($sqlCoachs);
 

+ 188 - 72
main/mySpace/cours.php

@@ -2,7 +2,7 @@
 /*
  * Created on 28 juil. 2006 by Elixir Interactive http://www.elixir-interactive.com
  */
- 
+ ob_start();
  $nameTools= 'Cours';
  $langFile = array ('registration', 'index','trad4all', 'tracking');
  $cidReset=true;
@@ -11,7 +11,20 @@
  $this_section = "session_my_space";
  
  api_block_anonymous_users();
-  $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
+ $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"])){
+ 	 $interbreadcrumb[] = array ("url" => "cours.php", "name" => get_lang('Teachers'));
+ }
+ 
  Display :: display_header($nameTools);
  
  
@@ -20,6 +33,7 @@
  $tbl_user = Database :: get_main_table(MAIN_USER_TABLE);
  $tbl_session_course = Database :: get_main_table(MAIN_SESSION_COURSE_TABLE);
  $tbl_session = Database :: get_main_table(MAIN_SESSION_TABLE);
+ $tbl_session_course_user = Database :: get_main_table(MAIN_SESSION_COURSE_USER_TABLE);
  
 /*
  ===============================================================================
@@ -68,13 +82,56 @@
 	
 	return $message;
  }
+ 
+ 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);
+	  
+	if(mysql_num_rows($result)>0){
+	    return true;	    
+	}
+	else{
+		return false;
+	}
+  }
+  
+  function isDisplayed($s_code, $a_courses){
+  	
+  	if(array_key_exists($s_code,$a_courses)){
+  		return true;
+  	}
+  	else{
+  		return false;
+  	}
+  	
+  }
+  
 
 /*
  ===============================================================================
  	MAIN CODE
  ===============================================================================  
  */
+	
+	
+	if(isset($_GET["id_session"]) && $_GET["id_session"]!=""){
+		
+		$i_id_session=intval($_GET["id_session"]);
+		
+		$sqlCourse="SELECT DISTINCT code, title " .
+ 					"FROM $tbl_course as course, $tbl_session_course as src " .
+ 					"WHERE course.code=src.course_code AND src.id_session='$i_id_session'";
 
+		$resultCourses = api_sql_query($sqlCourse);
+		
+		$a_courses = api_store_result($resultCourses);
+		
+	}
+	
 	if(isset($_GET["user_id"]) && $_GET["user_id"]!=""){
  		
  		$i_user_id=$_GET["user_id"];
@@ -88,6 +145,14 @@
  			
  		}
  		
+ 		elseif(isset($_GET["type"]) && $_GET["type"]=="student"){
+ 			
+ 			$sqlCourse="SELECT title,code " .
+	 					"FROM $tbl_course as course, $tbl_session_course_user as srcu " .
+	 					"WHERE course.code=srcu.course_code AND srcu.id_user='$i_user_id'";
+
+ 		}
+ 		
  		//It's a teacher
  		else{
 	 		$sqlCourse = "	SELECT 	title,code
@@ -96,14 +161,59 @@
 							ORDER BY title ASC
 						  ";
  		}
+ 		
+ 		$resultCourses = api_sql_query($sqlCourse);
+		
+		$a_courses = api_store_result($resultCourses);
+ 		
  	}
- 	else{
- 		$sqlCourse = "	SELECT 	title,code
-						FROM $tbl_course as course
-						ORDER BY title ASC
-					  ";
+ 	if(!isset($_GET["user_id"]) && !isset($_GET["id_session"])){
+ 		
+ 		//La personne est admin
+		if(api_is_platform_admin()){
+ 		
+	 		$sqlCourse = "	SELECT 	title,code
+							FROM $tbl_course as course
+							ORDER BY title ASC
+						  ";
+			$resultCourses = api_sql_query($sqlCourse);
+		
+			$a_courses = api_store_result($resultCourses);
+
+		}
+		else{
+			
+			if($is_allowedCreateCourse){
+				
+				$sqlCourse = "	SELECT title,code
+								FROM $tbl_course as course, $tbl_user_course as course_rel_user 
+								WHERE course_rel_user.course_code=course.code AND course_rel_user.user_id='$_uid' AND course_rel_user.status='1'
+								ORDER BY title ASC
+							  ";
+
+			}
+			
+			$resultCoursesTeacher = api_sql_query($sqlCourse);
+		
+			$a_courses_teacher = api_store_result($resultCoursesTeacher);
+			
+			if(is_coach()){
+				
+				$sqlCourse = "	SELECT DISTINCT code, title 
+								FROM $tbl_course as course, $tbl_session_course as session_rel_course 
+							  	WHERE session_rel_course.course_code=course.code AND id_coach='$_uid' 
+							  ";
+
+				$resultCoursesCoach = api_sql_query($sqlCourse);
+				$a_courses = array_merge($a_courses_teacher,api_store_result($resultCoursesCoach));
+				
+			}
+			
+		}
  	}
 	
+	
+	
 	$resultCourse = api_sql_query($sqlCourse);
 	
 	$a_header[]=get_lang('Title');
@@ -125,76 +235,82 @@
 					</th>
 				</tr>
           	 ';
-
-		while($a_course= mysql_fetch_array($resultCourse))
-		{
-			$sqlCoach = "SELECT CONCAT(user.firstname,' ',user.lastname) as tutor_name
-						 FROM $tbl_user
-						 INNER JOIN $tbl_session_course as sessionCourse
-							ON sessionCourse.course_code = '".$a_course['code']."'
-							AND sessionCourse.id_coach = user.user_id
-						";
-			$resultCoach = api_sql_query($sqlCoach);
-			$a_coach = mysql_fetch_array($resultCoach);
+		
+		$a_alreadydisplay=array();
+		
+		foreach($a_courses as $a_course){
 			
-			/*$sqlFormateur = "	SELECT CONCAT(user.firstname,' ',user.lastname) as formateur_name
-						 		FROM $tbl_user
-								INNER JOIN $tbl_session_course as sessionCourse
-									ON sessionCourse.course_code = '".$a_course['code']."'
-								INNER JOIN $tbl_session AS session
-									ON session.id = sessionCourse.id_session
-									AND session.id_coach = user.user_id
-							";*/
-			$sqlFormateur = "	SELECT CONCAT(user.firstname,' ',user.lastname) as formateur_name
-						 		FROM $tbl_user as user, $tbl_user_course as cru
-								WHERE user.user_id=cru.user_id AND cru.status='1' AND cru.course_code='".$a_course['code']."'
+			if(!isDisplayed($a_course["code"],$a_alreadydisplay)){
+				
+				$a_alreadydisplay[$a_course["code"]]=1;
+				
+				$sqlCoach = "SELECT CONCAT(user.firstname,' ',user.lastname) as tutor_name
+							 FROM $tbl_user
+							 INNER JOIN $tbl_session_course as sessionCourse
+								ON sessionCourse.course_code = '".$a_course['code']."'
+								AND sessionCourse.id_coach = user.user_id
 							";
-
-			$resultFormateur = api_sql_query($sqlFormateur);
-			$a_formateur = mysql_fetch_array($resultFormateur);
-			
-			if($i%2==0){
-				$s_css_class="row_odd";
+				$resultCoach = api_sql_query($sqlCoach);
+				$a_coach = mysql_fetch_array($resultCoach);
+				
+				/*$sqlFormateur = "	SELECT CONCAT(user.firstname,' ',user.lastname) as formateur_name
+							 		FROM $tbl_user
+									INNER JOIN $tbl_session_course as sessionCourse
+										ON sessionCourse.course_code = '".$a_course['code']."'
+									INNER JOIN $tbl_session AS session
+										ON session.id = sessionCourse.id_session
+										AND session.id_coach = user.user_id
+								";*/
+				$sqlFormateur = "	SELECT CONCAT(user.firstname,' ',user.lastname) as formateur_name
+							 		FROM $tbl_user as user, $tbl_user_course as cru
+									WHERE user.user_id=cru.user_id AND cru.status='1' AND cru.course_code='".$a_course['code']."'
+								";
+	
+				$resultFormateur = api_sql_query($sqlFormateur);
+				$a_formateur = mysql_fetch_array($resultFormateur);
 				
-				if($i%20==0 && $i!=0){
-						echo '<tr>
-						<th>
-							'.get_lang('Title').'
-						</th>
-						<th>
-							'.get_lang('Tutor').'
-						</th>
-						<th>
-							'.get_lang('Teachers').'
-						</th>
-					</tr>';
-					}
+				if($i%2==0){
+					$s_css_class="row_odd";
+					
+					if($i%20==0 && $i!=0){
+							echo '<tr>
+							<th>
+								'.get_lang('Title').'
+							</th>
+							<th>
+								'.get_lang('Tutor').'
+							</th>
+							<th>
+								'.get_lang('Teachers').'
+							</th>
+						</tr>';
+						}
+					
+				}
+				else{
+					$s_css_class="row_even";
+				}
 				
+				$i++;
+	
+				echo '<tr class="'.$s_css_class.'">
+						<td>
+					 		<a href="'.api_get_path(REL_CLARO_PATH).'tracking/courseLog.php?cidReq='.$a_course['code'].'">'.$a_course['title'].'</a></td>
+						<td>
+							'.$a_coach['tutor_name'].'
+						</td>
+					 	<td>
+							'.$a_formateur['formateur_name'].'
+						</td>
+					  </tr>
+					 ';
+	
+				$a_data[$index]["title"]=$a_course['title'];
+				$a_data[$index]["tutor_name"]=$a_coach['tutor_name'];
+				$a_data[$index]["formateur_name"]=$a_formateur['formateur_name'];
+				
+				$index++;			
 			}
-			else{
-				$s_css_class="row_even";
-			}
-			
-			$i++;
-
-			echo '<tr class="'.$s_css_class.'">
-					<td>
-				 		'.$a_course['title'].'</td>
-					<td>
-						'.$a_coach['tutor_name'].'
-					</td>
-				 	<td>
-						'.$a_formateur['formateur_name'].'
-					</td>
-				  </tr>
-				 ';
-
-			$a_data[$index]["title"]=$a_course['title'];
-			$a_data[$index]["tutor_name"]=$a_coach['tutor_name'];
-			$a_data[$index]["formateur_name"]=$a_formateur['formateur_name'];
-			
-			$index++;			
-
 		}
 		echo '</table>';
 	}

+ 274 - 48
main/mySpace/index.php

@@ -2,11 +2,11 @@
 /*
  * Created on 27 juil. 2006 by Elixir Interactive http://www.elixir-interactive.com
  */
- $nameTools= 'Mon espace';
+ 
  $langFile = array ('registration', 'index','trad4all','tracking');
  $cidReset=true;
  require ('../inc/global.inc.php');
- 
+ $nameTools= get_lang("MySpace");
  $this_section = "session_my_space";
  
  api_block_anonymous_users();
@@ -14,72 +14,297 @@
  
   $tbl_user = Database :: get_main_table(MAIN_USER_TABLE);
   $tbl_course = Database :: get_main_table(MAIN_COURSE_TABLE);
+  $tbl_course_user = Database :: get_main_table(MAIN_COURSE_USER_TABLE);
   $tbl_class = Database :: get_main_table(MAIN_CLASS_TABLE);
   $tbl_sessions = Database :: get_main_table(MAIN_SESSION_TABLE);
   $tbl_session_course = Database :: get_main_table(MAIN_SESSION_COURSE_TABLE);
+  $tbl_session_user = Database :: get_main_table(MAIN_SESSION_USER_TABLE);
+  $tbl_session_course_user = Database :: get_main_table(MAIN_SESSION_COURSE_USER_TABLE);
   $tbl_admin= Database :: get_main_table(MAIN_ADMIN_TABLE);
+  
+  
+    
+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);
+	  
+	if(mysql_num_rows($result)>0){
+	    return true;	    
+	}
+	else{
+		return false;
+	}
+  
+}
+  
+  
+  
  /*
  ===============================================================================
  	MAIN CODE
  ===============================================================================  
  */
-    
-	$sqlNbFormateurs = "SELECT COUNT(user_id)
-				  		FROM $tbl_user
-				  		WHERE status = 1 
-				 	  ";
-	$resultNbFormateurs = api_sql_query($sqlNbFormateurs);
-	$a_nbFormateurs = mysql_fetch_array($resultNbFormateurs);
-	$nbFormateurs = $a_nbFormateurs[0];
-  	
+ 	
+ 	//Trainers
+    if(api_is_platform_admin()){
+		$sqlNbFormateurs = "SELECT COUNT(user_id)
+					  		FROM $tbl_user
+					  		WHERE status = 1 
+					 	  ";
+		$resultNbFormateurs = api_sql_query($sqlNbFormateurs);
+		$a_nbFormateurs = mysql_fetch_array($resultNbFormateurs);
+		$nbFormateurs = $a_nbFormateurs[0];
+    }
   	
   	
+  	//Coachs
+  	$nbCoachs=0;
+  	if(api_is_platform_admin()){
+	  	$sqlNbCoachs = "SELECT COUNT(DISTINCT id_coach)
+					  		FROM $tbl_session_course
+					  		WHERE id_coach<>'0'	 
+					 	  ";
+		$resultNbCoachs = api_sql_query($sqlNbCoachs);
+		$a_nbCoachs = mysql_fetch_array($resultNbCoachs);
+		$nbCoachs = $a_nbCoachs[0];
+  	}
   	
-  	$sqlNbCoachs = "SELECT COUNT(DISTINCT id_coach)
-				  		FROM $tbl_session_course
-				  		WHERE id_coach<>'0'	 
-				 	  ";
-	$resultNbCoachs = api_sql_query($sqlNbCoachs);
-	$a_nbCoachs = mysql_fetch_array($resultNbCoachs);
-	$nbCoachs = $a_nbCoachs[0];
-
-	$sqlNbStagiaire = "	SELECT COUNT(user_id)
-				  		FROM $tbl_user
-				  		WHERE status = 5 
-				 	  ";
-	$resultNbStagiaire = api_sql_query($sqlNbStagiaire);
-	$a_nbStagiaire = mysql_fetch_array($resultNbStagiaire);
-	$nbStagiaire = $a_nbStagiaire[0];
+  	elseif($is_allowedCreateCourse){
+  		
+  		$a_coach=array();
+  		
+  		$sqlNbCours = "	SELECT course_code
+						FROM $tbl_course_user
+					  	WHERE user_id='$_uid' AND status='1'
+					  ";
+		$resultNbCours = api_sql_query($sqlNbCours);
+		
+		while($a_courses=mysql_fetch_array($resultNbCours)){
+			
+			$sql="SELECT DISTINCT id_coach FROM $tbl_session_course WHERE course_code='".$a_courses["course_code"]."'";
+			
+			$resultCoach = api_sql_query($sql);
+			
+			if(mysql_num_rows($resultCoach)>0){
+				while($a_temp=mysql_fetch_array($resultCoach)){
+					$a_coach[]=$a_temp["id_coach"];
+				}
+			}
+			
+		}
+		
+		$a_coach=array_unique($a_coach);
+		$nbCoachs=count($a_coach);
+  		
+  	}
+
+
+	
+	//Nombre de stagiaires (cours dans lesquels il est coach ou formateurs)
 	
-	$sqlNbCours = "	SELECT COUNT(code)
-					FROM $tbl_course
-				  ";
-	$resultNbCours = api_sql_query($sqlNbCours);
-	$a_nbCours = mysql_fetch_array($resultNbCours);
-	$nbCours = $a_nbCours[0];
+	$nbStagiaire=0;
+	$a_stagiaire_teacher=array();
 	
-	$sqlNbSessions = "	SELECT COUNT(id)
-					FROM $tbl_sessions
-				  ";
-	$resultNbSessions = api_sql_query($sqlNbSessions);
-	$a_nbSessions= mysql_fetch_array($resultNbSessions);
-	$nbSessions = $a_nbSessions[0];
+	//La personne est admin
+	if(api_is_platform_admin()){
+
+		$sqlNbStagiaire = "	SELECT COUNT(user_id)
+					  		FROM $tbl_user
+					  		WHERE status = 5 
+					 	  ";
+		$resultNbStagiaire = api_sql_query($sqlNbStagiaire);
+		$a_nbStagiaire = mysql_fetch_array($resultNbStagiaire);
+		$nbStagiaire = $a_nbStagiaire[0];
+	}
+	
+	else{
+		
+		//La personne a le statut de professeur
+		if($is_allowedCreateCourse){
+
+			$sqlNbStagiaire="SELECT DISTINCT srcru.id_user FROM $tbl_course_user as course_rel_user, $tbl_session_course_user as srcru " .
+							"WHERE course_rel_user.user_id='$_uid' AND course_rel_user.status='1' AND course_rel_user.course_code=srcru.course_code";
+
+			$resultNbStagiaire = api_sql_query($sqlNbStagiaire);
+			
+			while($a_temp = mysql_fetch_array($resultNbStagiaire)){
+				$a_stagiaire_teacher[]=$a_temp[0];
+			}
+
+		}
+		
+		if(is_coach()){
+
+			$a_stagiaire_coach=array();
+			
+			$sql="SELECT id_session, course_code FROM $tbl_session_course WHERE id_coach='$_uid'";
+
+			$result=api_sql_query($sql);
+			
+			while($a_courses=mysql_fetch_array($result)){
+				
+		    	$course_code=$a_courses["course_code"];
+		    	$id_session=$a_courses["id_session"];
+		    	
+		    	$sqlStudents = "SELECT distinct	srcru.id_user  
+								FROM $tbl_session_course_user AS srcru 
+								INNER JOIN $tbl_user as user 
+									ON srcru.id_user = user.user_id 
+									AND user.status = 5 
+								WHERE course_code='$course_code' AND id_session='$id_session'";
+
+				$q_students=api_sql_query($sqlStudents);
+				
+				while($a_temp=mysql_fetch_array($q_students)){
+					$a_stagiaire_coach[]=$a_temp[0];
+				}
+				
+		    }
+		    $a_stagiaires=array_merge($a_stagiaire_teacher,$a_stagiaire_coach);
+				
+			$a_stagiaires=array_unique($a_stagiaires);
+			
+			$nbStagiaire=count($a_stagiaires);
+		    
+		}
+		else{
+			$nbStagiaire=count($a_stagiaire_teacher);
+		}
+		
+	}
+	
+	//Nombre de cours
+	
+	//La personne est admin donc on compte le nombre total de cours
+	if(api_is_platform_admin()){
+	
+		$sqlNbCours = "	SELECT COUNT(code)
+						FROM $tbl_course
+					  ";
+		$resultNbCours = api_sql_query($sqlNbCours);
+		$a_nbCours = mysql_fetch_array($resultNbCours);
+		$nbCours = $a_nbCours[0];
+		
+	}
+	
+	else{
+		
+		$a_cours=array();
+		
+		//La personne a le statut de professeur	
+		if($is_allowedCreateCourse){
+			
+			$sqlNbCours = "	SELECT DISTINCT course_code
+							FROM $tbl_course_user
+						  	WHERE user_id='$_uid' AND status='1'
+						  ";
+			$resultCours = api_sql_query($sqlNbCours);
+			
+			while($a_cours_teacher = mysql_fetch_array($resultCours)){
+				$a_cours[]=$a_cours_teacher["course_code"];
+			}
+			
+		}
+		
+		//La personne est coach
+		if(is_coach()){
+			
+			$sqlNbCours = "	SELECT DISTINCT course_code 
+							FROM $tbl_session_course 
+						  	WHERE id_coach='$_uid' 
+						  ";
+			$resultCours = api_sql_query($sqlNbCours);
+			
+			while($a_cours_coach = mysql_fetch_array($resultCours)){
+				$a_cours[]=$a_cours_coach["course_code"];
+			}
+			
+		}
+		$a_cours=array_unique($a_cours);
+		$nbCours=count($a_cours);
+		
+	}
+	
+	
+	//Nombre de sessions
+	
+	//La personne est admin donc on compte le nombre total de sessions
+	if(api_is_platform_admin()){
+	
+		$sqlNbSessions = "	SELECT COUNT(id)
+							FROM $tbl_sessions
+						 ";
+		$resultNbSessions = api_sql_query($sqlNbSessions);
+		$a_nbSessions= mysql_fetch_array($resultNbSessions);
+		$nbSessions = $a_nbSessions[0];
+		
+	}
+	
+	else{
+		
+		$a_sessions=array();
+		
+		if($is_allowedCreateCourse){
+			
+			$sqlNbSessions = "	SELECT DISTINCT id_session 
+								FROM $tbl_session_course as session_course, $tbl_course_user as course_rel_user  
+							  	WHERE session_course.course_code=course_rel_user.course_code AND course_rel_user.status='1' AND course_rel_user.user_id='$_uid' 
+							  ";
+
+			$resultNbSessions = api_sql_query($sqlNbSessions);
+			
+			while($a_temp = mysql_fetch_array($resultNbSessions)){
+				$a_sessions[]=$a_temp["id_session"];
+			}
+			
+		}
+		
+		if(is_coach()){
+			$sqlNbSessions = "	SELECT DISTINCT id_session 
+								FROM $tbl_session_course 
+							  	WHERE id_coach='$_uid' 
+							  ";
+
+			$resultNbSessions = api_sql_query($sqlNbSessions);
+			
+			while($a_temp = mysql_fetch_array($resultNbSessions)){
+				$a_sessions[]=$a_temp["id_session"];
+			}
+		
+		}
+		
+		$a_sessions=array_unique($a_sessions);
+		$nbSessions = count($a_sessions);
+		
+	}
 
 	$sql_nb_admin="SELECT count(user_id) FROM $tbl_admin";
 	$resultNbAdmin = api_sql_query($sql_nb_admin);
 	$i_nb_admin=mysql_result($resultNbAdmin,0,0);
+	
  ?>
  
- <div class="admin_section">
-	<h4>
-		<?php echo "<a href='teachers.php'>".get_lang('Trainers')." (".$nbFormateurs.")</a>"; ?>
-	</h4>
- </div>
- <div class="admin_section">
-	<h4>
-		<?php echo "<a href='coaches.php'>".get_lang('Tutor')." (".$nbCoachs.")</a>"; ?>
-	</h4>
- </div>
+ <?php
+ if(api_is_platform_admin()){
+	 echo '<div class="admin_section">
+		<h4>
+			<a href="teachers.php">'.get_lang('Trainers').' ('.$nbFormateurs.')</a>
+		</h4>
+	 </div>';
+ }
+ 
+ if(api_is_platform_admin() || $is_allowedCreateCourse){
+	 echo '<div class="admin_section">
+		<h4>
+			<a href="coaches.php">'.get_lang("Tutor").' ('.$nbCoachs.')</a>
+		</h4>
+	 </div>';
+ }
+ ?>
  <div class="admin_section">
 	<h4>
 		<?php 
@@ -102,6 +327,7 @@
 		<?php echo "<a href='session.php'>".get_lang('Sessions').' ('.$nbSessions.')'."</a>"; ?>
 	</h4>
  </div>
+
  <div class="admin_section">
 	<h4>
 		<?php echo get_lang('Tracks'); ?>

+ 136 - 11
main/mySpace/session.php

@@ -2,7 +2,7 @@
 /*
  * Created on 28 juil. 2006 by Elixir Interactive http://www.elixir-interactive.com
  */
-
+ob_start();
  $nameTools= 'Sessions';
  $langFile = array ('registration', 'index','trad4all','tracking');
  $cidReset=true;
@@ -15,38 +15,144 @@
  Display :: display_header($nameTools);
 
  
+ $tbl_course_user = Database :: get_main_table(MAIN_COURSE_USER_TABLE);
+ $tbl_sessions = Database :: get_main_table(MAIN_SESSION_TABLE);
+ $tbl_session_course = Database :: get_main_table(MAIN_SESSION_COURSE_TABLE);
+ $tbl_course = Database :: get_main_table(MAIN_COURSE_TABLE);
+ 
+ 
+ /*
+ ===============================================================================
+ 	FUNCTION
+ ===============================================================================  
+ */
+ 
+ function exportCsv($a_header,$a_data)
+ {
+ 	global $archiveDirName;
+
+	$fileName = 'sessions.csv';
+	$archivePath = api_get_path(SYS_PATH).$archiveDirName.'/';
+	$archiveURL = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive=';
+	
+	if(!$open = fopen($archivePath.$fileName,'w+'))
+	{
+		$message = get_lang('noOpen');
+	}
+	else
+	{
+		$info = '';
+		
+		foreach($a_header as $header)
+		{
+			$info .= $header.';';
+		}
+		$info .= "\r\n";
+		
+		
+		foreach($a_data as $data)
+		{
+			foreach($data as $infos)
+			{
+				$info .= $infos.';';
+			}
+			$info .= "\r\n";
+		}
+		
+		fwrite($open,$info);
+		fclose($open);
+		chmod($fileName,0777);
+		
+		header("Location:".$archiveURL.$fileName);
+	}
+	
+	return $message;
+ }
+ 
+ 
  
- $tbl_session = Database :: get_main_table(MAIN_SESSION_TABLE);
  /*
  ===============================================================================
  	MAIN CODE
  ===============================================================================  
  */
+	
+	
+	//Nombre de sessions
+	
+	//La personne est admin donc on récupère toutes les sessions
+	if(api_is_platform_admin()){
+	
+		$sqlSessions = "	SELECT id, name
+							FROM $tbl_sessions
+						 ";
+		
+	}
+	
+	else{
+		
+		$a_sessions=array();
+		
+		if($is_allowedCreateCourse){
+			
+			$sqlSessions = "	SELECT DISTINCT id_session, name 
+								FROM $tbl_session_course as session_course, $tbl_course_user as course_rel_user, $tbl_sessions as session  
+							  	WHERE session.id=session_course.id_session AND session_course.course_code=course_rel_user.course_code AND course_rel_user.status='1' AND (course_rel_user.user_id='$_uid' OR session_course.id_coach='$_uid') 
+							  ";
 
-	$sqlSession = "	SELECT name
-					FROM $tbl_session
-					ORDER BY name ASC
-				  ";
-	$resultSession = api_sql_query($sqlSession);
+			$resultSessions = api_sql_query($sqlSessions);
+			
+			while($a_temp = mysql_fetch_array($resultSessions)){
+				$a_sessions[]=$a_temp["id_session"];
+			}
+			
+		}
+		
+		$a_sessions=array_unique($a_sessions);
+		$nbSessions = count($a_sessions);
+		
+	}
+	
+	$a_header[]=get_lang('Title');
 	
-	if(mysql_num_rows($resultSession)>0)
+	$resultSessions = api_sql_query($sqlSessions);
+	
+	if(mysql_num_rows($resultSessions)>0)
 	{
 		echo '<table class="data_table">
 			 	<tr>
 					<th>
 						'.get_lang('Title').'
 					</th>
+					<th>
+						'.get_lang('Courses').'
+					</th>
 				</tr>
           	 ';
-		while($a_session = mysql_fetch_array($resultSession))
+		while($a_sessions = mysql_fetch_array($resultSessions))
 		{
+			
+			$i_id_session=$a_sessions['id_session'];
+			/*
+			//On récupère tous les cours de la session courante
+			$sql="SELECT course.title FROM $tbl_course as course, $tbl_session_course as session_rel_course " .
+					"WHERE session_rel_course.id_session='$i_id_session' AND session_rel_course.course_code=course.code";
+			
+			$resultCourses = api_sql_query($sql);*/
+			
 			echo '<tr>
 					<td>
 				 ';
-			echo		$a_session['name'];
+			echo		$a_sessions['name'];
 			echo '	</td>
+					<td>
+						<a href="cours.php?id_session='.$i_id_session.'">-></a>
+					</td>
 				  </tr>
 				 ';
+				 
+			$a_data[$i_user_id]["name"]=$a_sessions['name'];		
+			
 		}
 		echo '</table>';
 	}
@@ -54,5 +160,24 @@
 	{
 		echo get_lang('NoSession');
 	}
- 
+
+if(isset($_POST['export'])){
+	
+	exportCsv($a_header,$a_data);
+	
+}
+
+echo "<br /><br />";
+echo "<form method='post' action='session.php'>
+		<input type='submit' name='export' value='".get_lang('exportExcel')."'/>
+	  <form>";
+
+/*
+==============================================================================
+	FOOTER
+==============================================================================
+*/
+
+Display::display_footer();
+
 ?>

+ 262 - 37
main/mySpace/student.php

@@ -2,6 +2,7 @@
 /*
  * Created on 28 juil. 2006 by Elixir Interactive http://www.elixir-interactive.com
  */
+ 
 ob_start();
  $nameTools= 'Students';
  $langFile = array ('registration', 'index','trad4all', 'tracking');
@@ -17,8 +18,10 @@ ob_start();
  
  $tbl_course = Database :: get_main_table(MAIN_COURSE_TABLE);
  $tbl_user = Database :: get_main_table(MAIN_USER_TABLE);
+ $tbl_course_user = Database :: get_main_table(MAIN_COURSE_USER_TABLE);
  $tbl_session = Database :: get_main_table(MAIN_SESSION_TABLE);
  $tbl_session_course = Database :: get_main_table(MAIN_SESSION_COURSE_TABLE);
+ $tbl_session_course_user = Database :: get_main_table(MAIN_SESSION_COURSE_USER_TABLE);
  $tbl_session_rel_user = Database :: get_main_table(MAIN_SESSION_USER_TABLE);
  
 /*
@@ -68,28 +71,232 @@ ob_start();
 	
 	return $message;
  }
+ 
+ /**
+  * Returns an array of students of courses (who belong to no sessions) which in the given user is a teacher
+  * @param int teacher_id The id of the teacher
+  */
+ function getStudentsFromCoursesNoSession($i_teacher_id, $a_students){
+ 	
+ 	$tbl_session_course_user = Database :: get_main_table(MAIN_SESSION_COURSE_USER_TABLE);
+ 	$tbl_course_user = Database :: get_main_table(MAIN_COURSE_USER_TABLE);
+ 	$tbl_user = Database :: get_main_table(MAIN_USER_TABLE);
+ 	$tbl_session_course = Database :: get_main_table(MAIN_SESSION_COURSE_TABLE);
+ 	
+ 	
+ 	$sql_select_courses="SELECT course_rel_user.course_code FROM $tbl_course_user as course_rel_user LEFT OUTER JOIN $tbl_session_course as src ON course_rel_user.course_code=src.course_code WHERE user_id='$i_teacher_id' AND status='1' AND src.course_code IS NULL";
+
+ 	$result_courses=api_sql_query($sql_select_courses);
+ 	
+ 	while($a_courses=mysql_fetch_array($result_courses)){
+ 		
+ 		$s_course_code=$a_courses["course_code"];
+ 		$sqlStudents = "SELECT user.user_id,lastname,firstname,email FROM $tbl_course_user as course_rel_user, $tbl_user as user WHERE course_rel_user.user_id=user.user_id AND course_rel_user.status='5' AND course_rel_user.course_code='$s_course_code'";
+ 		$result_students=api_sql_query($sqlStudents);
+
+ 		if(mysql_num_rows($result_students)>0){
+ 		
+	 		while($a_students_temp=mysql_fetch_array($result_students)){
+	 			
+	 			$a_current_student=array();
+	 			
+	 			//If the user has already been added to the table
+	 			if(!array_key_exists($a_students,$a_students_temp["user_id"])){
+	 			
+		 			$a_current_student[]=$a_students_temp["user_id"];
+		 			$a_current_student[]=$a_students_temp["lastname"];
+		 			$a_current_student[]=$a_students_temp["firstname"];
+		 			$a_current_student[]=$a_students_temp["email"];
+		 			
+		 			$a_students[$a_students_temp["user_id"]]=$a_current_student;
+		 			$a_students[$a_students_temp["user_id"]]["teacher"]=true;
+		 			
+	 			}
+	 			
+	 		}
+	 		
+ 		}
+ 		 
+ 	}
+ 	
+ 	return $a_students;
+ 	
+ }
+ 
+ 
+ /**
+  * Returns an array of students of courses (who belong to at least one session) which in the given user is a teacher
+  * @param int teacher_id The id of the teacher
+  */
+ function getStudentsFromCoursesFromSessions($i_teacher_id, $a_students){
+ 	
+ 	$tbl_session_course_user = Database :: get_main_table(MAIN_SESSION_COURSE_USER_TABLE);
+ 	$tbl_course_user = Database :: get_main_table(MAIN_COURSE_USER_TABLE);
+ 	$tbl_user = Database :: get_main_table(MAIN_USER_TABLE);
+ 	$tbl_session_course = Database :: get_main_table(MAIN_SESSION_COURSE_TABLE);
+ 	
+ 	$sql_select_courses="SELECT course_rel_user.course_code FROM $tbl_course_user as course_rel_user, $tbl_session_course as session_rel_course WHERE user_id='$i_teacher_id' AND status='1' AND session_rel_course.course_code=course_rel_user.course_code";
+ 	$result_courses=api_sql_query($sql_select_courses);
+
+ 	while($a_courses=mysql_fetch_array($result_courses)){
+ 		
+ 		$s_course_code=$a_courses["course_code"];
+ 		$sqlStudents = "SELECT DISTINCT user.user_id,lastname,firstname,email FROM $tbl_session_course_user as srcru, $tbl_user as user WHERE srcru.id_user=user.user_id AND srcru.course_code='$s_course_code'";
+ 		$result_students=api_sql_query($sqlStudents);
+ 		echo $sqlStudents;
+ 		if(mysql_num_rows($result_students)>0){
+ 		
+	 		while($a_students_temp=mysql_fetch_array($result_students)){
+	 			
+	 			$a_current_student=array();
+	 			
+	 			//If the user has already been added to the table
+	 			if(!array_key_exists($a_students,$a_students_temp["user_id"])){
+	 				
+		 			$a_current_student[]=$a_students_temp["user_id"];
+		 			$a_current_student[]=$a_students_temp["lastname"];
+		 			$a_current_student[]=$a_students_temp["firstname"];
+		 			$a_current_student[]=$a_students_temp["email"];
+		 			
+		 			$a_students[$a_students_temp["user_id"]]=$a_current_student;
+		 			$a_students[$a_students_temp["user_id"]]["teacher"]=true;
+		 			
+	 			}
+	 			
+	 		}
+	 		
+ 		}
+ 		 
+ 	}
+ 	
+ 	return $a_students;
+ 	
+ }
+ 
+ 
+ /**
+  * Returns an array of students of courses which in the given user is a coach
+  * @param int coach_id The id of the coach
+  */
+ function getStudentsFromCoursesFromSessionsCoach($i_coach_id, $a_students){
+ 	
+ 	$tbl_session_course_user = Database :: get_main_table(MAIN_SESSION_COURSE_USER_TABLE);
+ 	$tbl_course_user = Database :: get_main_table(MAIN_COURSE_USER_TABLE);
+ 	$tbl_user = Database :: get_main_table(MAIN_USER_TABLE);
+ 	$tbl_session_course = Database :: get_main_table(MAIN_SESSION_COURSE_TABLE);
+ 	
+ 	$sql_select_courses="SELECT course_code, id_session FROM $tbl_session_course as session_rel_course WHERE session_rel_course.id_coach='$i_coach_id'";
+ 	$result_courses=api_sql_query($sql_select_courses);
+
+ 	while($a_courses=mysql_fetch_array($result_courses)){
+ 		
+ 		$s_course_code=$a_courses["course_code"];
+ 		$i_id_session=$a_courses["id_session"];
+ 		
+ 		$sqlStudents="SELECT user.user_id,lastname,firstname,email 
+						FROM $tbl_session_course_user as srcru, $tbl_user as user 
+						WHERE srcru.course_code='$s_course_code' AND srcru.id_session='$i_id_session' AND srcru.id_user=user.user_id 
+						";
+ 		$result_students=api_sql_query($sqlStudents);
+
+ 		if(mysql_num_rows($result_students)>0){
+ 		
+	 		while($a_students_temp=mysql_fetch_array($result_students)){
+	 			
+	 			$a_current_student=array();
+	 			
+	 			//If the user has already been added to the table
+	 			if(!array_key_exists($a_students,$a_students_temp["user_id"])){
+	 			
+		 			$a_current_student[]=$a_students_temp["user_id"];
+		 			$a_current_student[]=$a_students_temp["lastname"];
+		 			$a_current_student[]=$a_students_temp["firstname"];
+		 			$a_current_student[]=$a_students_temp["email"];
+		 			
+		 			$a_students[$a_students_temp["user_id"]]=$a_current_student;
+		 			$a_students[$a_students_temp["user_id"]]["teacher"]=false;
+		 			
+	 			}
+	 			
+	 		}
+	 		
+ 		}
+ 		 
+ 	}
+ 	
+ 	return $a_students;
+ 	
+ }
+ 
+ 
+ function mysort($a , $b){
+	if($a[1]>$b[1]){
+		return 1;
+	}
+	else if($b[1]>$a[1]){
+		return -1;
+	}
+	else {
+		return 0;
+	}
+	
+}
+ 
 
 /*
  ===============================================================================
  	MAIN CODE
  ===============================================================================  
  */
+	$a_students=array();
+	
+	//La personne est admin
+	if(api_is_platform_admin()){
+	
+		$sqlStudent = "	SELECT user_id,lastname,firstname,email
+						FROM $tbl_user
+						WHERE status = '5'
+						ORDER BY lastname ASC
+					  ";
+		$resultStudent = api_sql_query($sqlStudent);
+		
+		while($a_students_temp=mysql_fetch_array($resultStudent)){
+			
+			$a_current_student=array();
+	 			
+ 			//If the user has already been added to the table
+ 			
+ 			$a_current_student[]=$a_students_temp["user_id"];
+ 			$a_current_student[]=$a_students_temp["lastname"];
+ 			$a_current_student[]=$a_students_temp["firstname"];
+ 			$a_current_student[]=$a_students_temp["email"];
+ 			
+ 			$a_students[$a_students_temp["user_id"]]=$a_current_student;
+ 			$a_students[$a_students_temp["user_id"]]["teacher"]=true;
+	 		
+		}
+	}
+	
+	else{
+		
+		$a_students=getStudentsFromCoursesNoSession($_uid, $a_students);
+
+		$a_students=getStudentsFromCoursesFromSessions($_uid, $a_students);
+
+		$a_students=getStudentsFromCoursesFromSessionsCoach($_uid, $a_students);
 
-	$sqlStudent = "	SELECT user_id,lastname,firstname,email
-					FROM $tbl_user
-					WHERE status = 5
-					ORDER BY lastname ASC
-				  ";
-	$resultStudent = api_sql_query($sqlStudent);
+		
+	}	  
+	
+	usort($a_students,"mysort");
 	
 	$a_header[]=get_lang('Lastname');
 	$a_header[]=get_lang('Firstname');
 	$a_header[]=get_lang('Email');
-	$a_header[]=get_lang('Tutor');
 	
 	$a_data=array();
 
-	if(mysql_num_rows($resultStudent)>0)
+	if(count($a_students)>0)
 	{
 		echo '<table class="data_table">
 			 	<tr>
@@ -105,12 +312,16 @@ ob_start();
 					<th>
 						'.get_lang('Tutor').'
 					</th>
+					<th>
+						'.get_lang('Courses').'
+					</th>
 					<th>
 						'.get_lang('TakenSessions').'
 					</th>
 				</tr>
           	 ';
-		while($a_student= mysql_fetch_array($resultStudent))
+          	 
+		foreach($a_students as $a_current_student)
 		{
 			
 			if($i%2==0){
@@ -118,24 +329,27 @@ ob_start();
 				
 				if($i%20==0 && $i!=0){
 					echo '<tr>
-					<th>
-						'.get_lang('Lastname').'
-					</th>
-					<th>
-						'.get_lang('Firstname').'
-					</th>
-					<th>
-						'.get_lang('Email').'
-					</th>
-					<th>
-						'.get_lang('Tutor').'
-					</th>
-					<th>
-						'.get_lang('TakenSessions').'
-					</th>
-				</tr>';
+							<th>
+								'.get_lang('Lastname').'
+							</th>
+							<th>
+								'.get_lang('Firstname').'
+							</th>
+							<th>
+								'.get_lang('Email').'
+							</th>
+							<th>
+								'.get_lang('Tutor').'
+							</th>
+							<th>
+								'.get_lang('Courses').'
+							</th>
+							<th>
+								'.get_lang('TakenSessions').'
+							</th>
+						</tr>
+		          	 ';
 				}
-				
 			}
 			else{
 				$s_css_class="row_even";
@@ -146,34 +360,45 @@ ob_start();
 			echo '<tr class="'.$s_css_class.'">
 					<td>
 				 ';
-			echo		$a_student['lastname'];
+			echo		$a_current_student[1];
 			echo '	</td>
 					<td>
-						'.$a_student['firstname'].'
+						'.$a_current_student[2].'
 					</td>
 					<td>
 				 ';
-			if(!empty($a_student['email']))
+			if(!empty($a_current_student[3]))
 			{	
-				echo	'<a href="mailto:'.$s_email.'">'.$a_student['email'].'</a>';
+				echo	'<a href="mailto:'.$s_email.'">'.$a_current_student[3].'</a>';
 			}
 			else
 			{
 				//echo get_lang('NoEmail');
 			}
-			echo '	</td>
+			echo '	</td>';
+			
+			if($a_current_student["teacher"]==true){
+			
+				echo '<td>
+						<a href="coaches.php?id_student='.$a_current_student[0].'">-></a>
+					</td>
 					<td>
-						<a href="coaches.php?id_student='.$a_student['user_id'].'">-></a>
+						<a href="cours.php?type=student&user_id='.$a_current_student[0].'">-></a>
 					</td>
 					<td align="center">
-						<a href="'.$_SERVER['PHP_SELF'].'?student='.$a_student['user_id'].'#sessionSuivie"> -> </a>
-					</td>
-				  </tr>
-				 ';
+						<a href="'.$_SERVER['PHP_SELF'].'?student='.$a_current_student[0].'#sessionSuivie"> -> </a>
+					</td>';
+			}
+			else{
+				echo '<td colspan="3"></td>';
+			}
+			  echo '</tr>';
+
+				 
 			$a_data[$a_student['user_id']]["lastname"]=$a_student['lastname'];
 			$a_data[$a_student['user_id']]["firstname"]=$a_student['firstname'];
 			$a_data[$a_student['user_id']]["email"]=$a_student['email'];
-			$a_data[$a_student['user_id']]["coach"]="";
+
 		}
 		echo '</table>';
 	}