1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
| <?php
$NoCours = $_REQUEST['NoCours'];
// connect to database
include 'DataBaseSettings.php';
$connection = mysql_connect($server, $username, $password) or die("Error connecting to database");
mysql_select_db($database, $connection);
$query = 'SELECT Periode FROM periodecourante WHERE Rec=999';
$rs = mysql_query($query);
$row = mysql_fetch_assoc($rs);
$semestre = '1s';
if ($row ['Periode'] == 2) $table = '2s';
// on compte le nombre d'élèves
$Result = mysql_query('SELECT count(*) FROM elevespoints'.$semestre.' WHERE NoCours='.$NoCours);
$NbEleves = mysql_result($Result,0,0);
$query = 'SELECT (@ROW := @ROW + 1) AS NoLigne, nom, prenom, gr, sex, dob,
PT1, PT2, PT3, PT4, PT5, PT6, PT7, PT8,
CN1, CN2, CN3, CN4, CN5, CN6, CN7, CN8,
PX1, PX2, PX3, PX4, PX5, PX6, PX7, PX8
FROM elevespoints'.$semestre.'
JOIN elevespointsdesc'.$semestre.' ON elevespointsdesc'.$semestre.'.NoCours = elevespoints'.$semestre.'.NoCours
JOIN (SELECT @ROW := 0) r
WHERE elevespoints'.$semestre.'.NoCours='.$NoCours.' ORDER BY nom';
$rs = mysql_query($query);
$i = 1;
$NbNotesV = array();
$TableauNotes = array();
$JSon = '{"Notes":[';
while($row = mysql_fetch_assoc($rs)) {
$JSon .= '{';
$JSon .= '"NoLigne'.'":"'.$i.'", ';
$JSon .= '"nom'.'":"'.$row['nom'].'", ';
$JSon .= '"prenom'.'":"'.$row['prenom'].'", ';
$JSon .= '"gr'.'":"'.$row['gr'].'", ';
$JSon .= '"sex'.'":"'.$row['sex'].'", ';
$JSon .= '"dob'.'":"'.$row['dob'].'", ';
$Somme = 0;
$Total = 0;
for ($j=1;$j<9;$j++) {
$NbPt = $row ['PT'.$j];
$PMax = $row ['PX'.$j];
if (floatval($NbPt) != 0 and floatval($PMax) != 0) {
$Note = number_format((float)round((floatval($NbPt) / floatval($PMax) * 5) + 1,1), 1, '.', '');
$Note = round($Note * 2) / 2;
// on compte la compte dans le tableau du nombre de notes verticales
$NbNotesV [$j] ++;
// on rempli le tableau de toutes les notes (ligne, colonne)
$TableauNotes[$i][$j] = $Note;
}
else $Note = '';
// calcul de la moyenne
$MoyH = '';
if ($Note != '') {
$Somme = $Somme + $Note * floatval($row['CN'.$j]);
$Total = $Total + floatval($row['CN'.$j]);
}
// on rempli le JSon
if ($Note != '') $JSon .= '"NT'.$j.'":"'.number_format($Note, 1, '.', '').'", ';
else $JSon .= '"NT'.$j.'":"'.$Note.'", ';
if ($Somme != 0) {
$MoyH = round($Somme / $Total,1);
}
} // fin de la boucle sur les colonnes (1 à 9)
$JSon .= '"MoyH'.'":"'.$MoyH.'", ';
$JSon = substr($JSon,0,-2);
$JSon .= '},';
$i++;
} // fin de la boucle sur le recordSet (les 17 élèves)
// calcul des moyennes verticales
// on fait d'abord une boucle de 1 à 9 horizontalement
// ce qui fait que la boucle intérieure parcourt la colonne 1 pour les 17 élèves, puis la colonne 2 pour les 17 ..
$MoyV=array();
$Somme = 0;
for ($j=1;$j<9;$j++){
for ($k=1;$k<=$NbEleves;$k++){
$Somme = $Somme + $TableauNotes[$k][$j];
//echo 'j='.$j.' k='.$k.' S='.$Somme.' Note'.$TableauNotes[$k][$j];
}
if ($Somme != 0) $MoyV[$j]=round($Somme/$NbNotesV[$j],1);
else $MoyV[$j] = '-.-';
// echo 'MoyV='.$MoyV[$j].' NbNV='.$NbNotesV[$j].'<br><br>';
$Somme = 0;
}
// on formate les moyennes verticales (qui sont dans un tableau à une dimension) et on calcule la moyenne horizontale des moyennes verticales
$Somme = 0;
$NbMoyV = 0;
for ($j=1;$j<9;$j++){
if ($MoyV[$j] != '-.-') {
$MoyV[$j] = number_format($MoyV[$j], 1, '.', '');
$Somme = $Somme + $MoyV[$j];
$NbMoyV ++;
}
}
// on ajoute la dernière ligne au JSon, celle des moyennes
$JSon .='{"NoLigne":"", "nom":"MOYENNE TRAVAIL", "prenom":"", "gr":"", "sex":"", "dob":"",
"NT1":"'.$MoyV[1].'", "NT2":"'.$MoyV[2].'", "NT3":"'.$MoyV[3].'", "NT4":"'.$MoyV[4].'",
"NT5":"'.$MoyV[5].'", "NT6":"'.$MoyV[6].'", "NT7":"'.$MoyV[7].'", "NT8":"'.$MoyV[8].'",
"MoyH":"'.number_format(round($Somme/$NbMoyV,1), 1, '.', '').'"}';
$JSon .= ']}';
// return response to client
echo $JSon;
?> |