<?
include("../BarreDeMenu.php3");
include("../Session/security.php");
// Entete
buildHeader("Changement de promotion<br>d'un ensemble d'étudiants");
// Verification de la session
$autorisation_list[0]=0; // Administrateur
$autorisation_list[1]=3; // Gestionnaire
$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,"etudiant.php3",false);
// Determination du user_id
$user_id = getUserID($id_session);
// Ouverture de la connexion avec la base de donnees
$connection = openConnection($databaseName);
//*****************************************
// Choisir la promotion
print("<FORM METHOD=POST ACTION=\"changement_promo.php\">\n");
print("<INPUT TYPE=HIDDEN NAME=\"id_session\" VALUE=$id_session>\n");
print(" <table align=center border=0 cellspacing=0 cellpading=0 width=700 bgcolor=\"#C0C000\">\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");
if ($user_type==3)
$result = mysql_query("SELECT distinct(promotion.id_promotion),diplome.libelle as L1,promotion.libelle as L2
FROM promotion,diplome,gerer WHERE gerer.id_gestionnaire=$user_id
AND promotion.id_promotion=gerer.id_promotion
AND diplome.id_diplome=promotion.id_diplome
ORDER BY diplome.libelle");
else $result = mysql_query("SELECT id_promotion,diplome.libelle as L1,promotion.libelle as L2
FROM promotion,diplome
WHERE promotion.id_diplome=diplome.id_diplome
ORDER BY diplome.libelle");
$index_max = mysql_num_rows($result);
if ($user_type==3 && $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)){
if((isset($choice))&&($choice==1)){
$nbE=count($tab_etudiant);
$nbP=count($tab_promotion);
if(($nbE!=0)&&($nbP!=0)){
//************on s'occupe d'abord de la purge dans la table appartient******************
$resultat=mysql_query("select id_groupe as id from associer where id_promotion=$id_promotion");
$nbG=mysql_num_rows($resultat);
if($nbG!=0){
//*****************on met dans le tableau tab_idGroupe les groupes associés à ma promotion sélectionnée****
$ind=0;
$groupe_id=mysql_fetch_array($resultat);
while($groupe_id){
$tab_idGroupe[$ind]=$groupe_id["id"];
$ind++;
$groupe_id=mysql_fetch_array($resultat);
}
//*********************************************************************************************************
//************on compare les groupes dans lesquels sont inscrits chaque etudiant avec les groupes correspondants à la promotion*
foreach($tab_etudiant as $etudiant){
$resultat=mysql_query("select id_groupe as id from appartient where id_etudiant=$etudiant");
$nbGr=mysql_num_rows($resultat);
if($nbGr!=0){
$id1_groupe=mysql_fetch_array($resultat);
while($id1_groupe){
foreach($tab_idGroupe as $id2_groupe){
if($id1_groupe["id"]==$id2_groupe){
mysql_query("delete from appartient where id_groupe=".$id1_groupe["id"]." and id_etudiant=$etudiant");
}
}
$id1_groupe=mysql_fetch_array($resultat);
}
}
}
}
//***********************************fin de la purge d'appartient*******************************
//**************************debut purge de la table inscrit**********************
foreach($tab_etudiant as $etudiant){
mysql_query("DELETE FROM inscrit WHERE id_etudiant=$etudiant and id_promotion=$id_promotion");
foreach($tab_promotion as $promotion){
mysql_query("INSERT INTO inscrit VALUES ($etudiant,$promotion)");
}
}
//***********************************fin de la purge d'inscrit*******************************
}
else{
echo "<script language='javascript'>\n";
if ($nbE==0){
echo "window.alert('il faut sélectionner\\nau moins un étudiant !!');\n";
}
else{
echo "window.alert('il faut sélectionner\\nau moins une promotion !!');\n";
}
echo "</script>\n";
}
}
print("<script language=\"JavaScript\">\n");
print("function open(v)\n");
print("{\n");
print(" document.form1.choice.value = v;\n");
print(" document.form1.submit();\n");
print("}\n");
print("</script>\n");
echo "<form name='form1' method='post' action='changement_promo.php'>\n";
echo "<input type='hidden' name='id_promotion' value='$id_promotion'>\n";
echo "<input type='hidden' name='id_session' value='$id_session'>\n";
echo "<input type='hidden' name='choice'>\n";
//**********sélection des étudiants de la promotion sélectionnée**********
$result1=mysql_query("select e.id_etudiant as id,nom,prenom from etudiant e,inscrit i where e.id_etudiant=i.id_etudiant and id_promotion=$id_promotion order by nom");
$result2=mysql_query("SELECT id_promotion as id,diplome.libelle as L1,promotion.libelle as L2 FROM promotion,diplome WHERE promotion.id_diplome=diplome.id_diplome and id_promotion<>$id_promotion ORDER BY diplome.libelle");
echo "<table align=center border=0 cellspacing=10 cellpading=0 width=700 bgcolor=\"#C0C000\">\n";
echo "<tr>\n";
$nbEtudiant=mysql_num_rows($result1); // pour voir si la promotion sélectionnée possède des étudiants
if($nbEtudiant==0) {
echo "<td align='center'><i>Il n'y a pas d'étudiants<br>dans la promotion sélectionnée</i></td>\n";
}
else {
echo "<td><i>étudiants de la promotion : </i></td>\n";
echo "<td align='left'>";
echo "<select multiple name='tab_etudiant[]' size=8>\n";
$etudiant=mysql_fetch_array($result1);
while($etudiant){
if((isset($choice))&&($choice==3)){
echo "<option value='".$etudiant["id"]."' selected>".$etudiant["nom"]." ".$etudiant["prenom"]."\n";
}
else{
echo "<option value='".$etudiant["id"]."'>".$etudiant["nom"]." ".$etudiant["prenom"]."\n";
}
$etudiant=mysql_fetch_array($result1);
}
echo "</td>\n";
echo "<td><i>promotion(s) de destination : </i></td>\n";
echo "<td align='left'><select multiple name='tab_promotion[]' size=4>\n";
$promotion=mysql_fetch_array($result2);
while($promotion){
echo "<option value='".$promotion["id"]."'>".$promotion["L1"]." ".$promotion["L2"]."\n";
$promotion=mysql_fetch_array($result2);
}
echo "</select>\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr bgcolor=\"#FFFFD0\">\n";
echo "<td colspan=4 align='center'>\n";
print(" <table border=1 cellpading=0 cellspacing=0 width=700><tr><td>\n");
print(" <table border=0 cellspacing=1 cellpading=5 align=center bgcolor=\"#FFFFD0\">\n");
print(" <tr valign=middle align=center>\n");
print(" <td width=40><a href=\"javascript:open(3);\"><img border=0 src=\"../img/selectAll.gif\" alt=\"Sélectionner tous les étudiants\"></a></td>\n");
print(" <td width=40><a href=\"javascript:open(1);\"><img border=0 src=\"../img/changement.gif\" alt=\"Valider\"></a></td>\n");
print(" <td width=40><a href=\"javascript:open(2);\"><img border=0 src=\"../img/EraseButton.gif\" alt=\"Annuler\"></a></td>\n");
}
print(" </tr>\n");
print(" </table>\n");
print(" </td></tr></table>\n");
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</form>\n";
}
}
buildEndOfPage();
?>