<?
include("../BarreDeMenu.php3");
include("../Session/security.php");
//*******fonction pour l'affichage des minutes dans le tableau par la suite******
function mettreMinute($str){
$i=0;
while($str[$i]!='.') $i++;
if($str[$i++]=='0'){
return 0;
}
else{
$min=(int)$str[$i]*6;
return $min;
}
}
//******************************************************************************
// Verification de la session
$autorisation_list[0]=2; // Etudiant
$user_type = validateSession($id_session);
if ($user_type == -1 || !security($id_session,$autorisation_list)) print("Accès refusé");
else {
// Entete
buildHeader("Matières suivies");
// Barre de menu
print("<FONT SIZE=2><I>\n");
print("<A HREF=\"../index.php?id_session=$id_session\">Menu</A><BR>\n");
print("</I></FONT>\n");
/********recherche de l'id_etudiant de celui connecté*******************/
$resultats=mysql_query("select a.id from appartient a,session s where a.login=s.login and a.id_type_user=2 and s.id_session='$id_session'");
$idE=mysql_fetch_array($resultats);
$id_etudiant=$idE["id"];
/**************************************************************************/
$link=openConnection($databaseName);
// Choisir la promotion
print("<FORM METHOD=POST ACTION='matiereEtudiant.php'>\n");
print("<INPUT TYPE=HIDDEN NAME='id_session' VALUE='$id_session'>\n");
print(" <table align=center border=0 cellspacing=0 cellpadding=0 width=700 bgcolor=\"#B1D0F3\">\n");
// Liste des promotions
print(" <tr>\n");
print(" <td valign=top width=100 nowrap rowspan=3><font size=3><i>Promotion :</i></font></td>\n");
print(" <td width=250 rowspan=3 valign=top>\n");
//*******************on liste les promotions dans lesquelles l'etudiant connecté est inscrit******************/
$resultat=mysql_query("select id_promotion as idP from inscrit where id_etudiant=$id_etudiant");
$nbPromo=mysql_num_rows($resultat);
$where="";
if($nbPromo>=2){
$id_promo=mysql_fetch_array($resultat);
$where.="(id_promotion=".$id_promo["idP"]." or ";
if($nbPromo==2){
$id_promo=mysql_fetch_array($resultat);
$where.="id_promotion=".$id_promo["idP"].")";
}
else{
for($i=1;$i<$nbPromo-1;$i++){
$id_promo=mysql_fetch_array($resultat);
$where.="id_promotion=".$id_promo["idP"]." or ";
}
}
if($nbPromo>2){
$id_promo=mysql_fetch_array($resultat);
$where.="id_promotion=".$id_promo["idP"].")";
}
}
else{
$id_promo=mysql_fetch_array($resultat);
$where.="id_promotion=".$id_promo["idP"];
}
/************************************************************************************************************/
$result = mysql_query("SELECT id_promotion,diplome.libelle as L1,promotion.libelle as L2 FROM promotion,diplome WHERE"." ".$where." "."and promotion.id_diplome=diplome.id_diplome ORDER BY diplome.libelle");
$index_max = mysql_num_rows($result);
if ($index_max == 1)
{
$a_record = mysql_fetch_array($result);
$id_promotion=$a_record["id_promotion"];
print($a_record["L1"]." ".$a_record["L2"]);
print("\n");
}
else
{
print(" <select name=\"id_promotion\" size=1 width=200 OnChange=\"submit();\">\n");
if (!isset($id_promotion)) print(" <option selected>");
for ($i=0;$i<$index_max;$i++)
{
$a_record = mysql_fetch_array($result);
if ($id_promotion==$a_record["id_promotion"]) print(" <option value=".$a_record["id_promotion"]." selected>");
else print(" <option value=".$a_record["id_promotion"].">");
print($a_record["L1"]." ".$a_record["L2"]);
print("\n");
}
print(" </select>\n");
}
print(" </td>\n");
print(" </tr>\n");
print(" </table>\n");
print(" </FORM>\n");
//**
if(isset($id_promotion)){
//******on regarde si l'étudiant est inscrit dans une promotion où il existe des groupes***********
$result=mysql_query("SELECT id_groupe as id from associer where id_promotion=$id_promotion");
$nbgroupe=mysql_num_rows($result);
if ($nbgroupe==0){
$groupes=0;
}
else{
$result1=mysql_query("select ap.id_groupe as id from promotion p, associer ass, appartient ap where p.id_promotion=ass.id_promotion and ap.id_groupe=ass.id_groupe and ap.id_etudiant=$id_etudiant and p.id_promotion=$id_promotion");
/* F. Nolot : si l'etudiant est inscrit dans aucun groupe */
$groupe_E=mysql_fetch_array($result1);
$id_groupe_E=$groupe_E["id"];
$groupes=1;
}
//****************Creation d'un tableau contenant les matieres*******************************
if($groupes==0){
$result=mysql_query("SELECT id_matiere as id from suiviparpromotion where id_promotion=$id_promotion");
$nbmatCOMMUN=mysql_num_rows($result);
for ($i=0;$i<$nbmat;$i++) {
$mat=mysql_fetch_array($result);
$tab_matCOMMUN[$i]=$mat["id"];
}
}
else{
$resultCOMMUN=mysql_query("SELECT id_matiere as id from suiviparpromotion where id_promotion=$id_promotion");
$resultGROUPE=mysql_query("SELECT id_matiere as id from suivipargroupe where id_groupe=$id_groupe_E");
$nbmatCOMMUN=mysql_num_rows($resultCOMMUN);
if ($resultGROUPE != false) $nbmatGROUPE=mysql_num_rows($resultGROUPE);
else $nbmatGROUPE=0;
for ($i=0;$i<$nbmatCOMMUN;$i++){
$matCOMMUN=mysql_fetch_array($resultCOMMUN);
$tab_matCOMMUN[$i]=$matCOMMUN["id"];
}
for ($i=0;$i<$nbmatGROUPE;$i++){
$matGROUPE=mysql_fetch_array($resultGROUPE);
$tab_matGROUPE[$i]=$matGROUPE["id"];
}
}
/*******************************************************************************************************/
echo "<table align='center' border='2' bordercolor='black' cellspacing=1 cellpadding=5 width='85%'>\n";
echo "<col span='4' align='center'>\n";
//***********Affichage du titre personnalisé de l'étudiant connecté***************
$resultat2 = mysql_query("SELECT diplome.libelle as L1,promotion.libelle as L2 FROM promotion,diplome WHERE promotion.id_diplome=diplome.id_diplome and id_promotion=$id_promotion");
$unePromo=mysql_fetch_array($resultat2);
$query=mysql_query("select nom,prenom from etudiant where id_etudiant=$id_etudiant");
$etudiant=mysql_fetch_array($query);
echo "<tr>\n<td colspan='4'><font face='Baskerville Old Face' color='#000000' size='5'><i><u>Fiche de l'étudiant</u></i> : ".$etudiant["nom"]." ".$etudiant["prenom"]."<br>".$unePromo["L1"]." ".$unePromo["L2"];
if($groupes==1){
$query1=mysql_query("select nom from groupe where id_groupe=$id_groupe_E");
if ($query1 != false )$nom=mysql_fetch_array($query1);
$nomGroupe=$nom["nom"];
echo "<br><i><u>Groupe</u></i> : $nomGroupe";
}
echo "</font></td>\n</tr>\n";
//**********************************************************************************
echo "<tr>\n<td><u><font face='Baskerville Old Face' color='#000000' size='4'>MATIERE</font></u></td>\n";
echo "<td><u><font face='Baskerville Old Face' color='#000000' size='4'>ENSEIGNANTS</font></u></td>\n";
echo "<td><u><font face='Baskerville Old Face' color='#000000' size='4'>TYPES<br>DE<br>SEANCE</font></u></td>\n";
echo "<td><u><font face='Baskerville Old Face' color='#000000' size='4'>NOMBRE<br>D' HEURES</font></u></td>\n</tr>\n";
echo "<tr>\n";
for($i=0;$i<$nbmatCOMMUN;$i++){ //Pour une matière
$resultat=mysql_query("SELECT libelle as lib from matiere where id_matiere=$tab_matCOMMUN[$i]");
$matiere=mysql_fetch_array($resultat);
echo "<tr>\n";
//*****on retourne les types de seances pour une matière pour connaitre le nombre de lignes necessaires a la case matiere***
$result=mysql_query("select id_type_seance from assurer where id_matiere=$tab_matCOMMUN[$i] and id_groupe=-1");
$nbLignes=mysql_num_rows($result);
echo "<th rowspan='$nbLignes'>".$matiere["lib"]." ";
//********dans le cas d'une promo à groupes : matière à tronc commun****
if($groupes==1){
echo "( Tronc commun )";
}
//*******************************************************************************
echo "</th>\n";
//*******on recherche le nombre de prof enseignant la matiere*******************
$res=mysql_query("select distinct id_professeur as id from assurer where id_matiere=$tab_matCOMMUN[$i] and id_groupe=-1");
$id_professeur=mysql_fetch_array($res);
while($id_professeur){ // pour un prof
$resultats=mysql_query("select id_type_seance as id,nb_heures as nbH from assurer where id_groupe=-1 and id_matiere=$tab_matCOMMUN[$i] and id_professeur=".$id_professeur["id"]);
$nbTypeSeance=mysql_num_rows($resultats);
$resultats1=mysql_query("select nom,prenom,email from professeur where id_professeur=".$id_professeur["id"]);
$unProf=mysql_fetch_array($resultats1);
echo "<td rowspan='$nbTypeSeance'><a href='mailto:".$unProf["email"]."'>".$unProf["nom"]." ".$unProf["prenom"]."</a></td>\n";
for($j=0;$j<$nbTypeSeance;$j++){ // un type séance
$unTypeSeance=mysql_fetch_array($resultats);
$res1=mysql_query("select type from typeseance where id_type_seance=".$unTypeSeance["id"]);
$nomTypeSeance=mysql_fetch_array($res1);
echo "<td>".$nomTypeSeance["type"]."</td>\n";
echo "<td>".(int)$unTypeSeance["nbH"]." H ";
$heure=$unTypeSeance["nbH"];
if($minutes=mettreMinute($heure)){
echo $minutes;
}
echo "</td>\n";
echo "</tr>\n<tr>\n";
}
$id_professeur=mysql_fetch_array($res);
}
}
if ($groupes==1) {
echo "</tr>\n<tr>\n";
for($i=0;$i<$nbmatGROUPE;$i++) { //Pour une matière
$resultat=mysql_query("SELECT libelle as lib from matiere where id_matiere=$tab_matGROUPE[$i]");
$matiere=mysql_fetch_array($resultat);
echo "<tr>\n";
//*****on retourne les types de seances pour une matière pour connaitre le nombre de lignes necessaires a la case matiere***
$result=mysql_query("select id_type_seance from assurer where id_matiere=$tab_matGROUPE[$i] and id_groupe=$id_groupe_E");
$nbLignes=mysql_num_rows($result);
echo "<th rowspan='$nbLignes'>".$matiere["lib"]." ( Groupe )";
echo "</th>\n";
//*******on recherche le nombre de prof enseignant la matiere*******************
$res=mysql_query("select distinct id_professeur as id from assurer where id_matiere=$tab_matGROUPE[$i] and id_groupe=$id_groupe_E");
$id_professeur=mysql_fetch_array($res);
while($id_professeur){ // pour un prof
$resultats=mysql_query("select id_type_seance as id,nb_heures as nbH from assurer where id_groupe=$id_groupe_E and id_matiere=$tab_matGROUPE[$i] and id_professeur=".$id_professeur["id"]);
$nbTypeSeance=mysql_num_rows($resultats);
$resultats1=mysql_query("select nom,prenom,email from professeur where id_professeur=".$id_professeur["id"]);
$unProf=mysql_fetch_array($resultats1);
echo "<td rowspan='$nbTypeSeance'><a href='mailto:".$unProf["email"]."'>".$unProf["nom"]." ".$unProf["prenom"]."</a></td>\n";
for($j=0;$j<$nbTypeSeance;$j++){ // un type séance
$unTypeSeance=mysql_fetch_array($resultats);
$res1=mysql_query("select type from typeseance where id_type_seance=".$unTypeSeance["id"]);
$nomTypeSeance=mysql_fetch_array($res1);
echo "<td>".$nomTypeSeance["type"]."</td>\n";
echo "<td>".(int)$unTypeSeance["nbH"]." H ";
$heure=$unTypeSeance["nbH"];
if($minutes=mettreMinute($heure)){
echo $minutes;
}
echo "</td>\n";
echo "</tr>\n<tr>\n";
}
$id_professeur=mysql_fetch_array($res);
}
}
}
echo "</tr>\n</table>\n";
}
}
buildEndOfPage();
?>
</body>
</html>