<?
include("../BarreDeMenu.php3");
include("fonctions_moyenne.php3");
include("../security.php");
// Entete
buildHeader("Relevé de notes");
// Verification de la session
$autorisation_list[0]=1; // Professeur
$user_type = validateSession($id_session);
if ($user_type == -1 || !security($id_session,$autorisation_list)) print("Accès refusé");
else
{
// Barre de menu
buildMenuBar($id_session,$user_type,"gdn/moyenne.php3",false);
// Determination du id_user a l'aide du id_session
$user_id = getUserID($id_session);
// Ouverture de la connexion
$connection = openConnection($databaseName);
//***********************************************************************************************
//* Debut du formulaire
//***********************************************************************************************
print("<form name=\"form1\" action=\"moyenne.php3\" method=post>\n");
print(" <input type=\"hidden\" name=\"login\" value=\"$login\">\n");
print(" <input type=\"hidden\" name=\"index\" value=\"$index\">\n");
// index=1 => on affiche les notes & les moyennes si il y en a deja
// index=2 => on (re)calcule les moyennes et on remplit la colonne moyennes
// index=3 => on insere les nouvelles moyennes dans la table moyenne
print(" <input type=\"hidden\" name=\"id_session\" value=\"$id_session\">\n");
print(" <input type=\"hidden\" name=\"user_type\" value=\"$user_type\">\n");
print(" <input type=\"hidden\" name=\"user_id\" value=\"$user_id\">\n");
print(" <input type=\"hidden\" name=\"display\" value=\"$display\">\n");
print(" <input type=\"hidden\" name=\"mat\" value=\"$mat\">\n");
print(" <input type=\"hidden\" name=\"promo\" value=\"$promo\">\n");
// les 3 champs suivants sont utilisés quand on veut visualiser le detail des notes d'une epreuve
// en cliquant sur son libelle (entete de colonne)
print(" <input type=\"hidden\" name=\"id_note\" value=\"\">\n");
print(" <input type=\"hidden\" name=\"id_typenote\" value=\"\">\n");
print(" <input type=\"hidden\" name=\"id_groupe\" value=\"$id_groupe\">\n");
if($index==1 || $index==2){
$res = mysql_query("SELECT moyenne.id_etudiant, moyenne.moyenne FROM moyenne, appartient, associer WHERE moyenne.id_matiere=$mat AND moyenne.id_etudiant=appartient.id_etudiant AND appartient.id_groupe=associer.id_groupe AND associer.id_promotion=$promo");
if(mysql_num_rows($res)==0) $moyennes = -1;
if($id_groupe!=-1){
$result = mysql_query("SELECT nom FROM groupe WHERE id_groupe=$id_groupe ");
$info_groupe = mysql_fetch_row($result);
}
// affichage du nom de la matiere et de la promotion :
$result_b = mysql_query("SELECT matiere.nom, promotion.libelle FROM promotion, matiere WHERE promotion.id_promotion=$promo AND matiere.id_matiere=$mat");
$infos = mysql_fetch_row($result_b);
print(" <DIV ALIGN=left><B><I><U>Matière :</U> $infos[0]<br><U>Promotion :</U> $infos[1]<br> \n");
if($id_groupe!=-1) print(" <U>Groupe :</U> $info_groupe[0] <br> \n");
print(" </I></B></DIV><br> \n");
// liste des notes se rapportant a la promotion (ou au groupe) :
if($id_groupe!=-1)
$result = mysql_query("SELECT DISTINCT note.id_note, note.libelle, note.coefficient, note.rapport, DATE_FORMAT(note.date,'%d/%m/%Y'), note.id_typenote FROM note, suivipargroupe ANAG WHERE note.id_matiere=$mat AND ANAG.id_matiere=$mat AND ANAG.id_groupe=$id_groupe ORDER BY id_typenote, date");
else
$result = mysql_query("SELECT DISTINCT note.id_note, note.libelle, note.coefficient, note.rapport, DATE_FORMAT(note.date,'%d/%m/%Y'), note.id_typenote FROM note, suiviparpromotion ANAG WHERE note.id_matiere=$mat AND ANAG.id_matiere=$mat AND ANAG.id_promotion=$promo ORDER BY id_typenote, date");
print(" <table align=center border=1 cellspacing=0 cellpading=0 width=100%> \n");
print(" <tr> \n");
print(" <td> </td> \n");
$nb_notes = mysql_num_rows($result);
for($i=0;$i<$nb_notes;$i++){
$note = mysql_fetch_row($result);
$id_notes[$i] = $note[0];
$coefficient[$i] = $note[2];
$rapport[$i] = $note[3];
print(" <td align=center width=70> <a href=\"Javascript:document.form1.action='page1.php3';document.form1.index.value=3;document.form1.id_note.value=$note[0];document.form1.id_typenote.value=$note[5];document.form1.id_groupe.value=$id_groupe;document.form1.submit();\"><font size=2 face=arial><b> $note[1] </b></font></a> <br> <font size=1 face=arial>($note[4])</font> </td> \n");
}
// si pas bcp de notes (- de 5) on rajoute des colonnes vides
for($i=$nb_notes;$i<=5;$i++) print(" <td align=center width=70> </td> \n");
if($moyennes!=-1 || $index==2)
print(" <td align=center width=70> <font size=2 face=arial><b>Moyenne</b></font> </td> \n");
print(" </tr> \n");
// liste des etudiants de la promotion (ou du groupe) :
if($id_groupe!=-1)
$result = mysql_query("SELECT E.id_etudiant, UPPER(E.nom), E.prenom FROM etudiant E, appartient AP, associer ASS WHERE E.id_etudiant=AP.id_etudiant AND AP.id_groupe=$id_groupe AND AP.id_groupe=ASS.id_groupe AND ASS.id_promotion=$promo ORDER BY E.nom, E.prenom");
else
$result = mysql_query("SELECT E.id_etudiant, UPPER(E.nom), E.prenom FROM etudiant E, inscrit I WHERE E.id_etudiant=I.id_etudiant AND I.id_promotion=$promo ORDER BY E.nom, E.prenom");
$nb_etu = mysql_num_rows($result);
for($k=0;$k<$nb_notes;$k++){
// initialisations des tableaux qui serviront à calculer la moyenne de la classe pour chaque epreuve :
$sommes_notes[$k] = 0.0;
$sommes_etudiants[$k] = 0.0;
}
$somme_moy = 0.0;
$nb_moyennes = 0;
for($i=0;$i<mysql_num_rows($result);$i++){
$etudiant = mysql_fetch_row($result);
// génération de la requete qui va trouver les notes de l'etudiant :
$requete = "SELECT id_note, note FROM avoirUneNote WHERE id_etudiant=$etudiant[0]";
for($j=0;$j<$nb_notes;$j++){
if($j==0) $requete .= " AND ( ";
else $requete .= " or " ;
$requete .= " id_note=$id_notes[$j] " ;
if($j==$nb_notes-1) $requete .= " ) ORDER BY id_note";
}
$result2 = mysql_query($requete);
for($k=0;$k<$nb_notes;$k++) $notes_etudiant[$k]=""; // initialisation du tableau de notes
for($k=0;$k<mysql_num_rows($result2);$k++){
$note = mysql_fetch_row($result2);
// on met toutes les notes de l'etudiant dans le tableau $notes_etudiant
for($t=0;$t<$nb_notes;$t++){
if($note[0]==$id_notes[$t]) $notes_etudiant[$t]=$note[1];
}
}
// maintenant :
// le tableau $id_notes[] contient la liste des 'id_notes'
// le tableau $coefficient[] contient les coefficients des notes correspondantes
// le tableau $rapport[] contient le rapport de chacune des notes
// et le tableau $notes_etudiant[] contient les notes de l'etudiant en cours pour chacune des notes du tableau $id_notes[]
print(" <tr> \n");
print(" <td align=left> $etudiant[1] $etudiant[2] </td> \n");
for($k=0;$k<$nb_notes;$k++){
print(" <td align=center><font size=2 face=arial> ");
if($notes_etudiant[$k]==-1) print(" abs ");
else{
if($notes_etudiant[$k]==-2) print(" <font color=red>def</font> ");
else{
print(" $notes_etudiant[$k] ");
if($notes_etudiant[$k]!=""){
$sommes_notes[$k] += $notes_etudiant[$k];
$sommes_etudiants[$k]+= 1.0;
}
}
}
print(" </font></td> \n");
}
// si pas bcp de notes (- de 5) on rajoute des colonnes vides
for($k=$nb_notes;$k<=5;$k++) print(" <td > </td> \n");
$moy = "";
if($index==2){
$moy = moyenne_classique($nb_notes,$notes_etudiant,$rapport,$coefficient);
$moy = sprintf ("%01.2f", $moy);
if($moy<0) $moy = "def";
else{
$somme_moy+=$moy;
$nb_moyennes++;
}
}else{
if($moyenne!=-1){
$tmp = mysql_query("SELECT moyenne FROM moyenne WHERE id_etudiant=$etudiant[0] AND id_matiere=$mat");
$res_tmp = mysql_fetch_row($tmp);
$moy = $res_tmp[0];
if($moy<0) $moy = "def";
else{
$somme_moy+=$moy;
$nb_moyennes++;
}
}
}
if($moyennes!=-1 || $index==2)
print(" <td align=center> <INPUT type=hidden name=\"id_etudiant_$i\" value=\"$etudiant[0]\"><input type=text name=\"moyenne_$i\" value=\"$moy\" size=5> </td> \n");
print(" </tr> \n");
}
// derniere ligne du tableau : les moyennes de chaque epreuve
print(" <tr> \n");
print(" <td align=left><font size=2 face=arial> <b>Moyennes des épreuves</b> </font></td> \n");
for($k=0;$k<$nb_notes;$k++){
print(" <td align=center><font size=2 face=arial> ");
if($sommes_etudiants[$k]==0) print(" - ");
else{
$moy_epreuve = $sommes_notes[$k] / $sommes_etudiants[$k];
$moy_epreuve = sprintf ("%01.2f", $moy_epreuve);
print(" <b>$moy_epreuve</b> ");
}
print(" </font></td> \n");
}
// si pas bcp de notes (- de 5) on rajoute des colonnes vides
for($k=$nb_notes;$k<=5;$k++) print(" <td > </td> \n");
if($nb_moyennes!=0) {
$moy_gene = $somme_moy/$nb_moyennes;
$moy_gene = sprintf ("%01.2f", $moy_gene);
}
if($moyennes!=-1 || $index==2)
print(" <td align=center><INPUT type=hidden name=\"moyenne_promo\" value=\"$moy_gene\"><font size=2 face=arial><b> $moy_gene </b></font></td> \n");
print(" </table> \n");
print(" <br> \n");
print(" <table align=center border=0 cellspacing=0 cellpading=0> \n");
print(" <tr> \n");
print(" <td align=center><INPUT type=button value=\"Calculer les moyennes\" onClick=\"index.value=2;submit();\"> </td> \n");
if($moyennes!=-1 || $index==2)
print(" <td align=center><INPUT type=button value=\" Valider \" onClick=\"index.value=3;action='moyenne.php3';submit();\"> </td> \n");
print(" </tr> \n");
print(" </table> \n");
print(" <input type=hidden name=\"nb_etu\" value=\"$nb_etu\" > \n");
}
//***********************************************************************************************
//* $index=3 ==>> on insere les moyennes dans la table
//***********************************************************************************************
if($index==3){
for($i=0;$i<$nb_etu;$i++){
$id_etudiant = "$" . "id_etudiant_" . $i ;
$moyenne_etudiant = "$" . "moyenne_" . $i ;
eval( "\$id_etudiant = \"$id_etudiant\";" );
eval( "\$moyenne_etudiant = \"$moyenne_etudiant\";" );
if($moyenne_etudiant=="def") $moyenne_etudiant=-2;
mysql_query("DELETE FROM moyenne WHERE id_etudiant=$id_etudiant AND id_matiere=$mat");
//if($moyenne_etudiant!="")
mysql_query("INSERT INTO moyenne VALUES ('$id_etudiant', '$mat', '$moyenne_etudiant')");
mysql_query("DELETE FROM moyennepromotion WHERE id_matiere=$mat AND id_promotion=$promo AND id_groupe=$id_groupe ");
mysql_query("INSERT INTO moyennepromotion VALUES ('$mat','$promo','$id_groupe','$moyenne_promo')");
}
print(" <SCRIPT LANGUAGE=javascript> \n");
print(" document.form1.index.value=\"1\"; \n"); // IL FAUT RECHARGER LE FORMULAIRE
print(" document.form1.submit(); \n");
print(" </SCRIPT> \n");
print(" \n");
}// fin index=3
//***********************************************************************************************
//* Fin du formulaire
//***********************************************************************************************
print("</form> \n");
//***********************************************************************************************
//***********************************************************************************************
//***********************************************************************************************
}
buildEndOfPage();
?>