<?
/* --- F. Nolot
Des commentaires dans ce fichier correspondent à des fonctionnalitées non finalisées
Require MySQL4 minimum pour pouvoir faire une requete UNION */
include("Functions.php3");
include("Navigation.php3");
include("../BarreDeMenu.php3");
include("class_matiere.php3");
include("../Session/security.php");
function remplir_formulaire($index, $result) {
global $G_matiere;
global $G_nb_promotions;
global $G_id_promotion;
global $G_nb_groupes;
global $G_id_groupe;
if ( ($index != -1) && mysql_data_seek($result,$index))
{
$une_matiere = mysql_fetch_array($result);
$G_matiere->id_matiere = $une_matiere["id_matiere"];
$G_matiere->nom = $une_matiere["nom"];
$G_matiere->id_periode = $une_matiere["id_periode"];
$G_matiere->libelle = $une_matiere["libelle"];
$G_matiere->id_departement = $une_matiere["id_departement"];
$result3 = mysql_query("SELECT * FROM suivipargroupe WHERE id_matiere=$G_matiere->id_matiere");
$G_nb_groupes = mysql_num_rows($result3);
for ($i=0;$i<$G_nb_groupes;$i++)
{
$un_groupe = mysql_fetch_array($result3);
$G_id_groupe[$i] = $un_groupe["id_groupe"];
}
if ($G_nb_groupes > 0) $result2 = mysql_query("SELECT * FROM associer WHERE id_groupe=$G_id_groupe[0]");
else $result2 = mysql_query("SELECT * FROM suiviparpromotion WHERE id_matiere=$G_matiere->id_matiere");
$G_nb_promotions = mysql_num_rows($result2);
for ($i=0;$i<$G_nb_promotions;$i++)
{
$une_promotion = mysql_fetch_array($result2);
$G_id_promotion[$i] = $une_promotion["id_promotion"];
}
}
else
{ print(mysql_error());
}
}
function selectRecords()
{
global $id_promotion2;
$request = mysql_query("SELECT distinct(matiere.id_matiere),nom,id_periode,libelle,id_departement
FROM matiere,suiviparpromotion
WHERE
(suiviparpromotion.id_promotion=$id_promotion2
AND matiere.id_matiere=suiviparpromotion.id_matiere)
UNION
SELECT distinct(matiere.id_matiere),nom,id_periode,libelle,id_departement
FROM matiere,suivipargroupe,associer
WHERE
(associer.id_promotion=$id_promotion2
AND suivipargroupe.id_groupe=associer.id_groupe
AND matiere.id_matiere=suivipargroupe.id_matiere)
ORDER BY nom");
return $request;
}
function deleteRecord($keyValue)
{
mysql_query("DELETE FROM matiere WHERE (id_matiere='$keyValue')");
mysql_query("DELETE FROM suiviparpromotion WHERE (id_matiere='$keyValue')");
mysql_query("DELETE FROM suivipargroupe WHERE (id_matiere='$keyValue')");
}
function modifyRecord($keyValue)
{
global $nom;
global $id_periode;
global $libelle;
global $id_departement;
global $id_promotion;
global $id_promotion2;
global $id_groupe;
/* global $TousP,$CMP,$TDP,$TDmP,$TPP,$ExamenP;
global $TousG,$CMG,$TDG,$TDmG,$TPG,$ExamenG; */
mysql_query("UPDATE matiere SET nom='$nom',id_periode='$id_periode',libelle='$libelle',id_departement='$id_departement' WHERE id_matiere=$keyValue");
mysql_query("DELETE FROM suiviparpromotion WHERE (id_matiere='$keyValue')");
mysql_query("DELETE FROM suivipargroupe WHERE (id_matiere='$keyValue')");
$m = count($id_groupe);
if ($m == 0)
{
// Une matiere est suivie par une et une seule promotion
// dans la table suiviparpromotion
mysql_query("INSERT INTO suiviparpromotion VALUES ($id_promotion2,$keyValue,-1)");
/* if ($TousP=="o") mysql_query("INSERT INTO suiviparpromotion VALUES ($id_promotion2,$keyValue,-1)");
if ($CMP=="o") mysql_query("INSERT INTO suiviparpromotion VALUES ($id_promotion2,$keyValue,1)");
if ($TDP=="o") mysql_query("INSERT INTO suiviparpromotion VALUES ($id_promotion2,$keyValue,2)");
if ($TDmP=="o") mysql_query("INSERT INTO suiviparpromotion VALUES ($id_promotion2,$keyValue,3)");
if ($TPP=="o") mysql_query("INSERT INTO suiviparpromotion VALUES ($id_promotion2,$keyValue,4)");
if ($ExamenP=="o") mysql_query("INSERT INTO suiviparpromotion VALUES ($id_promotion2,$keyValue,5)");*/
}
else
{
// Une matiere peut etre suivie par plusieurs groupes non simultanement
for ($i=0;$i<$m;$i++)
{
mysql_query("INSERT INTO suivipargroupe VALUES (".($id_groupe[$i]).",$keyValue,-1)");
/* if ($TousG=="o") mysql_query("INSERT INTO suivipargroupe VALUES (".($id_groupe[$i]).",$keyValue,-1)");
if ($CMG=="o") mysql_query("INSERT INTO suivipargroupe VALUES (".($id_groupe[$i]).",$keyValue,1)");
if ($TDG=="o") mysql_query("INSERT INTO suivipargroupe VALUES (".($id_groupe[$i]).",$keyValue,2)");
if ($TDmG=="o") mysql_query("INSERT INTO suivipargroupe VALUES (".($id_groupe[$i]).",$keyValue,3)");
if ($TPG=="o") mysql_query("INSERT INTO suivipargroupen VALUES (".($id_groupe[$i]).",$keyValue,4)");
if ($ExamenG=="o") mysql_query("INSERT INTO suivipargroupe VALUES (".($id_groupe[$i]).",$keyValue,5)");*/
}
}
}
function newRecord()
{
global $id_matiere;
global $nom;
global $id_periode;
global $libelle;
global $id_departement;
global $id_promotion;
global $id_groupe;
global $G_matiere;
/* global $TousP,$CMP,$TDP,$TDmP,$TPP,$ExamenP;
global $TousG,$CMG,$TDG,$TDmG,$TPG,$ExamenG;*/
if ($nom != "" && $nom != "- Obligatoire -" ) {
$id_matiere = getKeyValue("id_matiere");
$request = "INSERT INTO matiere VALUES('$id_matiere','$nom','$id_periode','$libelle','$id_departement')";
mysql_query($request);
$m = count($id_groupe);
if ($m == 0)
{
// Une matiere est suivie par plusieurs promotions
// dans la table suiviparpromotion
$n = count($id_promotion);
for ($i=0;$i<$n;$i++)
{
mysql_query("INSERT INTO suiviparpromotion VALUES (".($id_promotion[$i]).",$id_matiere,-1)");
/* if ($TousP=="o") mysql_query("INSERT INTO suiviparpromotion VALUES (".($id_promotion[$i]).",$id_matiere,-1)");
if ($CMP=="o") mysql_query("INSERT INTO suiviparpromotion VALUES (".($id_promotion[$i]).",$id_matiere,1)");
if ($TDP=="o") mysql_query("INSERT INTO suiviparpromotion VALUES (".($id_promotion[$i]).",$id_matiere,2)");
if ($TDmP=="o") mysql_query("INSERT INTO suiviparpromotion VALUES (".($id_promotion[$i]).",$id_matiere,3)");
if ($TPP=="o") mysql_query("INSERT INTO suiviparpromotion VALUES (".($id_promotion[$i]).",$id_matiere,4)");
if ($ExamenP=="o") mysql_query("INSERT INTO suiviparpromotion VALUES (".($id_promotion[$i]).",$id_matiere,5)");*/
}
}
else
{
for ($i=0;$i<$m;$i++)
{
mysql_query("INSERT INTO suivipargroupe VALUES (".($id_groupe[$i]).",$id_matiere,-1)");
/* if ($TousG=="o") mysql_query("INSERT INTO suivipargroupe VALUES (".($id_groupe[$i]).",$id_matiere,-1)");
if ($CMG=="o") mysql_query("INSERT INTO suivipargroupe VALUES (".($id_groupe[$i]).",$id_matiere,1)");
if ($TDG=="o") mysql_query("INSERT INTO suivipargroupe VALUES (".($id_groupe[$i]).",$id_matiere,2)");
if ($TDmG=="o") mysql_query("INSERT INTO suivipargroupe VALUES (".($id_groupe[$i]).",$id_matiere,3)");
if ($TPG=="o") mysql_query("INSERT INTO suivipargroupen VALUES (".($id_groupe[$i]).",$id_matiere,4)");
if ($ExamenG=="o") mysql_query("INSERT INTO suivipargroupe VALUES (".($id_groupe[$i]).",$id_matiere,5)");*/
}
}
echo "<script language='javascript'>\n";
echo "alert(\"La matière $nom est ajouté\");\n";
echo "</script>\n";
// ---
return -1; // F. Nolot pour effacer le formulaire une fois l'insertion terminée
// return $id_matiere;
}
else
{
$G_matiere->nom = "- Obligatoire -";
return -1;
}
}
// Formulaire de saisie
function buildCustomFields()
{
global $choice;
global $G_matiere;
global $id_promotion;
global $id_groupe;
global $G_nb_promotions;
global $G_id_promotion;
global $G_nb_groupes;
global $G_id_groupe;
global $id_type_seance;
global $id_promotion2;
print("<INPUT TYPE=HIDDEN NAME=\"id_promotion2\" VALUE=\"$id_promotion2\">\n");
if ($choice == 8) $n = count($id_promotion);
else $n = $G_nb_promotions;
if ($choice >= 8) $m = count($id_groupe);
else $m = $G_nb_groupes;
// Champ "suivie par promotion"
print(" <tr>\n");
print(" <td valign=top nowrap><i>Suivie par la promotion :</i></td>\n");
print(" <td nowrap>\n");
$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);
print(" <table><tr><td>\n");
print(" <select multiple name=\"id_promotion[]\" size=6 OnChange=\"choice.value=8; submit();\">\n");
for ($i=0;$i<$index_max;$i++)
{
$a_record = mysql_fetch_array($result);
$found = false;
$j = 0;
while (!$found && $j<$n)
{
if (($choice != 8 && $G_id_promotion[$j] == $a_record["id_promotion"]) || ($choice == 8 && $id_promotion[$j] == $a_record["id_promotion"]))
$found = true;
else
$j++;
}
if ($found)
print(" <option selected value=".$a_record["id_promotion"]." >");
else
print(" <option value=".$a_record["id_promotion"].">");
print($a_record["L1"]." ".$a_record["L2"]);
print("</option>\n");
}
print(" </select></td>\n");
/* Correspond au choix avec TD, TP, TDm
if (isset($G_matiere->id_matiere) && ($G_matiere->id_matiere!=-1) && ($G_matiere->id_matiere!=""))
{
$result = mysql_query("SELECT id_type_seance FROM suiviparpromotion WHERE id_matiere=".$G_matiere->id_matiere);
$a_record = mysql_fetch_array($result);
}
else $a_record["id_type_seance"]=0;
print(" <td align=center valign=top><i>Tous</i><br><input type=checkbox name=\"TousP\" value=\"o\"");
if ($a_record["id_type_seance"]==-1) print(" checked");
print(" ></td>\n");
print(" <td align=center valign=top><i>CM</i><br><input type=checkbox name=\"CMP\" value=\"o\"");
if ($a_record["id_type_seance"]==1) print(" checked");
print(" ></td>\n");
print(" <td align=center valign=top><i>TD</i><br><input type=checkbox name=\"TDP\" value=\"o\"");
if ($a_record["id_type_seance"]==2) print(" checked");
print(" ></td>\n");
print(" <td align=center valign=top><i>TDm</i><br><input type=checkbox name=\"TDmP\" value=\"o\"");
if ($a_record["id_type_seance"]==3) print(" checked");
print(" ></td>\n");
print(" <td align=center valign=top><i>TP</i><br><input type=checkbox name=\"TPP\" value=\"o\"");
if ($a_record["id_type_seance"]==4) print(" checked");
print(" ></td>\n");
print(" <td align=center valign=top><i>Examen</i><br><input type=checkbox name=\"ExamenP\" value=\"o\"");
if ($a_record["id_type_seance"]==5) print(" checked");
print(" ></td>\n");*/
print(" </tr>\n");
print(" </table>\n");
print(" </td></tr>\n");
// Champ "suivie par groupe"
print(" <tr><td valign=middletop nowrap><i>Suivie par le groupe :</i></td>\n");
print(" <td>\n");
print(" <table><tr><td>\n");
print(" <select multiple name=\"id_groupe[]\" size=3 OnChange=\"choice.value = 9; submit();\">\n");
if ($n > 0)
{
$from = "groupe,associer as t0";
if ($choice == 8) $where = "t0.id_promotion = ".$id_promotion[0]." ";
else $where = "t0.id_promotion = ".$G_id_promotion[0]." ";
for ($i=1;$i<$n;$i++)
{
if ($choice == 8) $where = $where."AND t$i.id_promotion = ".$id_promotion[$i]." ";
else $where = $where."AND t$i.id_promotion = ".$G_id_promotion[$i]." ";
$from = $from.",associer as t$i";
}
for ($i=1;$i<$n;$i++)
$where = $where."AND t".($i-1).".id_groupe = t".$i.".id_groupe ";
$request = "SELECT groupe.id_groupe,groupe.nom,groupe.id_type_groupe FROM ".$from." WHERE ".$where." AND groupe.id_groupe = t0.id_groupe ORDER BY groupe.nom";
$result = mysql_query($request);
$index_max = mysql_num_rows($result);
for ($i=0;$i<$index_max;$i++)
{
$a_record = mysql_fetch_array($result);
$found = false;
$j = 0;
while (!$found && $j<$m)
{
if (($choice < 8 && $G_id_groupe[$j] == $a_record["id_groupe"]) || ($choice >= 8 && $id_groupe[$j] == $a_record["id_groupe"]))
$found = true;
else
$j++;
}
if ($found)
print(" <option selected value=".$a_record["id_groupe"]." >");
else
print(" <option value=".$a_record["id_groupe"].">");
print($a_record["nom"]);
print("</option>\n");
}
}
print(" </select></td>\n");
/* if ( isset($G_matiere->id_matiere) && ($G_matiere->id_matiere!=-1) && ($G_matiere->id_matiere!="") )
{
$result = mysql_query("SELECT id_type_seance FROM suivipargroupe WHERE id_matiere=".$G_matiere->id_matiere);
$a_record = mysql_fetch_array($result);
}
else $a_record["id_type_seance"]=0;
print(" <td align=center valign=top><i>Tous</i><br><input type=checkbox name=\"TousG\" value=\"o\"");
if ($a_record["id_type_seance"]==-1) print(" checked");
print(" ></td>\n");
print(" <td align=center valign=top><i>CM</i><br><input type=checkbox name=\"CMG\" value=\"o\"");
if ($a_record["id_type_seance"]==1) print(" checked");
print(" ></td>\n");
print(" <td align=center valign=top><i>TD</i><br><input type=checkbox name=\"TDG\" value=\"o\"");
if ($a_record["id_type_seance"]==2) print(" checked");
print(" ></td>\n");
print(" <td align=center valign=top><i>TDm</i><br><input type=checkbox name=\"TDmG\" value=\"o\"");
if ($a_record["id_type_seance"]==3) print(" checked");
print(" ></td>\n");
print(" <td align=center valign=top><i>TP</i><br><input type=checkbox name=\"TPG\" value=\"o\"");
if ($a_record["id_type_seance"]==4) print(" checked");
print(" ></td>\n");
print(" <td align=center valign=top><i>Examen</i><br><input type=checkbox name=\"ExamenG\" value=\"o\"");
if ($a_record["id_type_seance"]==5) print(" checked");
print(" ></td>\n");*/
print(" </tr>\n");
print(" </table>\n");
print(" </td>\n");
print(" <tr>\n");
}
// Entete
buildHeader("Matière");
// Verification de la session
$autorisation_list[0]=0; // Administrateur
$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,"matiere.php3",false);
// Ouverture de la connexion avec la base de donnees
$connection = openConnection($databaseName);
//*****************************************
// Choisir la promotion
print("<FORM METHOD=POST ACTION=\"matiere.php3\">\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");
$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);
print(" <select name=\"id_promotion2\" size=1 width=200 OnChange=\"submit();\">\n");
if (!isset($id_promotion2)) print(" <option selected> </option>\n");
for ($i=0;$i<$index_max;$i++) {
$a_record = mysql_fetch_array($result);
if ($id_promotion2==$a_record["id_promotion"]) print(" <option selected value=".$a_record["id_promotion"].">");
else print(" <option value=".$a_record["id_promotion"].">");
print($a_record["L1"]." ".$a_record["L2"]);
print("</option>\n");
}
print(" </select>\n");
print(" </td>\n");
print(" </tr>\n");
print(" </table>\n");
print(" </FORM>\n");
//**
//*****************************************
if (isset($id_promotion2)) {
$G_matiere = new Matiere(-1,"","","",-1);
$G_id_promotion;
$G_nb_promotions = 0;
$G_id_groupe;
$G_nb_groupes = 0;
//***********************************************************************************************
//* Navigation et rechercheId
//***********************************************************************************************
perform($id_matiere,"id_matiere");
if ($choice == 8)
{
if ($id_matiere != -1) $G_matiere->id_matiere = $id_matiere;
$G_matiere->nom = $nom;
$G_matiere->id_periode = $id_periode;
$G_matiere->libelle = $libelle;
$id_groupe = "";
}
if ($choice == 9)
{
$G_matiere->id_matiere = $id_matiere;
$G_matiere->nom = $nom;
$G_matiere->id_periode = $id_periode;
$G_matiere->libelle = $libelle;
$result2 = mysql_query("SELECT * FROM associer WHERE id_groupe=$id_groupe[0]");
$G_nb_promotions = mysql_num_rows($result2);
for ($i=0;$i<$G_nb_promotions;$i++)
{
$une_promotion = mysql_fetch_array($result2);
$G_id_promotion[$i] = $une_promotion["id_promotion"];
}
}
//***********************************************************************************************
//* Fin de la navigation
//***********************************************************************************************
$form["Name"]=array("","Nom","Periode","Libellé","Département de rattachement");
$form["Type"]=array(0,1,5,1,5);
$form["FieldName"]=array("id_matiere","nom","id_periode","libelle","id_departement");
$form["Value"]=array($G_matiere->id_matiere,$G_matiere->nom,$G_matiere->id_periode,$G_matiere->libelle,$G_matiere->id_departement);
$form["KeyName"]=array("","","id_periode","","id_departement");
if (isset($G_id_groupe[0]))
$request = "SELECT id_periode,numero FROM periode,associer WHERE associer.id_groupe=$G_id_groupe[0] AND periode.id_promotion=associer.id_promotion ORDER BY numero";
else
{
if (isset($id_groupe[0]))
$request = "SELECT id_periode,numero FROM periode,associer WHERE associer.id_groupe=$id_groupe[0] AND periode.id_promotion=associer.id_promotion ORDER BY numero";
else
{
if (isset($id_promotion2))
$request = "SELECT id_periode,numero FROM periode WHERE id_promotion=$id_promotion2 ORDER BY numero";
else
$request = "SELECT id_periode,numero FROM periode WHERE id_promotion=$G_id_promotion[0] ORDER BY numero";
}
}
$form["Request"]=array("","",$request,"","SELECT * FROM departement ORDER BY libelle");
$form["Fields"]=array("","",array("numero"),"",array("libelle"));
$form["Length"]=array(0,32,3,32,1);
$form["NewLine"]=array(false,true,true,true,false);
buildForm("matiere.php3",$form,$id_session,0,$user_type,$user_id,$display);
}
}
buildEndOfPage();
?>