Location: PHPKode > projects > EmploiNet : a timetable web manager > EmploiNet/v0.8.0/Administration/diviser.php3
<?

	
	include("../BarreDeMenu.php3");
    
    include("../Session/security.php");

// Entete
    buildHeader("Volume horaire des enseignements");
// 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,"diviser.php3",false);
// Ouverture de la connexion avec la base de donnees
    $connection = openConnection($databaseName);
// Variables globales
	// matiere
	$G_id_matiere;
	$G_nom_matiere;
	$G_nb_matieres;
	// type de seance
	$G_id_type_seance;
	$G_libelle_type_seance;
	$G_nb_types_seance;
	$G_duree_type_seance; // duree associee a un type de seance pour une matiere (tableau a 2 entrees)
	$n = count($id_promotion); // nombre de promotions selectionnees

// Traitement des evenements Promotion et Groupe
	switch ($choice)
	{
		case -1: // changement de promotion
		{
			$id_groupe = -1;
			break;
		}
		case -2: // changement de groupe
		{
			if ($id_groupe != -1)
			{
				$result2 = mysql_query("SELECT * FROM associer WHERE id_groupe=$id_groupe[0]");
    	      	$n = mysql_num_rows($result2); 
        	  	for ($i=0;$i<$n;$i++)
          		{
            		$une_promotion = mysql_fetch_array($result2);
		   	    	$id_promotion[$i] = $une_promotion["id_promotion"];
				}
     	  	}	 
			break; 
		}
	}
	// Si une promotion ou un groupe est selectionne
	if ($n > 0)
	{	
		// Chargement des types de seance			
		$result = mysql_query("SELECT * FROM typeseance ORDER BY id_type_seance");
		$G_nb_types_seance = mysql_num_rows($result);
		for ($i = 0;$i < $G_nb_types_seance;$i++)
		{
			$a_record = mysql_fetch_array($result);
			$G_id_type_seance[$i] = $a_record["id_type_seance"];
			$G_libelle_type_seance[$i] = $a_record["type"];
		}
		// Si un groupe est selectionne
		if ($id_groupe != -1) $result = mysql_query("SELECT matiere.id_matiere,matiere.nom FROM matiere,suivipargroupe WHERE suivipargroupe.id_groupe = $id_groupe AND suivipargroupe.id_matiere = matiere.id_matiere"); 		
		// Sinon une promotion est selectionnee
		else $result = mysql_query("SELECT matiere.id_matiere,matiere.nom FROM matiere,suiviparpromotion WHERE suiviparpromotion.id_promotion = $id_promotion[0] AND suiviparpromotion.id_matiere = matiere.id_matiere"); 
		// Chargement des matieres dans les variables globales G_id_matiere et G_nom
		// Chargement de la duree de chaque matiere en fonction du type de seance
        $G_nb_matieres = mysql_num_rows($result); 
        for ($i = 0;$i < $G_nb_matieres;$i++)
		{
			$une_matiere = mysql_fetch_array($result);
			$G_id_matiere[$i] = $une_matiere["id_matiere"];
			$G_nom[$i] = $une_matiere["nom"];
			for ($j = 0;$j < $G_nb_types_seance;$j++)
			{
				$result2 = mysql_query("SELECT nb_heures FROM diviser WHERE id_matiere=$G_id_matiere[$i] AND id_type_seance=$G_id_type_seance[$j]"); 
				if ($result2 != 0 && mysql_num_rows($result2) > 0) 
				{
  					$a_record = mysql_fetch_array($result2);
				  	$G_duree_type_seance[$j][$i] = $a_record["nb_heures"];
				}
				else $G_duree_type_seance[$j][$i] = 0;
			}
		}
/*******************************************************************************/	
/************************ Traitement des modifications *************************/
/*******************************************************************************/	
		if ($choice >= 0)
		{
			// determination de la cellule modifiee	
			$i = floor($choice / $G_nb_types_seance); // indice matiere
		  	$j = $choice - ($i * $G_nb_types_seance); // indice type seance
			// destruction de l'ancienne duree
			mysql_query("DELETE FROM diviser WHERE id_matiere=$G_id_matiere[$i] AND id_type_seance=$G_id_type_seance[$j]"); 
			// si la duree saisie est non nulle et positive
			if ($duree[$choice] > 0)
			{
				// mise a jour de la table diviser
				mysql_query("INSERT INTO diviser VALUES (".$G_id_matiere[$i].",".$G_id_type_seance[$j].",".$duree[$choice].")"); 
				$G_duree_type_seance[$j][$i] = $duree[$choice]; 
			}
			else $G_duree_type_seance[$j][$i] = 0;
		}
	}
/*******************************************************************************/	
/****************************** Formulaire *************************************/
/*******************************************************************************/	
	print("<form name=\"form1\"action=\"diviser.php3\" method=post>\n");
	print("  <table align=center border=0 cellspacing=0 cellpading=0 width=700 bgcolor=\"#C0C000\">\n");
    print("  <tr>\n");
	print("    <td>\n");
    print("      <input type=\"hidden\" name=\"login\" value=\"$login\">\n");
	print("      <input type=\"hidden\" name=\"choice\" value=\"-1\">\n");
    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");
// Liste des promotions	
	print("        <tr>\n");
	print("          <td valign=top width=100 nowrap><font size=3><i>Promotion :</i></font></td>\n");
	print("          <td width=250>\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 tabindex=-1 multiple name=\"id_promotion[]\" size=5 width=200 OnChange=\"choice.value=-1; submit();\">\n");
	for ($i=0;$i<$index_max;$i++)
	{
		$a_record = mysql_fetch_array($result);
	  	$found = false;
		$j = 0;
		while (!$found && $j<$n)
		{		
			if ($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>\n");
	print("          </td>\n");
// Liste des groupes associes a la promotion selectionnee
	print("          <td valign=top width=100 nowrap><font size=3><i>Groupe :</i></font></td>\n");
	print("          <td valign=top width=250>\n");
	print("          <select tabindex=-1 name=\"id_groupe\" size=1 width=200 OnChange=\"choice.value = -2; submit();\">\n");
	if ($n > 0)
	{
		$from = "groupe,associer as t0";
		$where = "t0.id_promotion = ".$id_promotion[0]." ";
		for ($i=1;$i<$n;$i++)
    	{
	   		$where = $where."AND t$i.id_promotion = ".$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 nom";
		$result = mysql_query($request);
    	$index_max = mysql_num_rows($result); 
		$found = false;
		for ($i=0;$i<$index_max;$i++)
		{
	  		$a_record = mysql_fetch_array($result);
			if ($id_groupe == $a_record["id_groupe"])
			{
				print("          <option selected value=".$a_record["id_groupe"]." >");
				$found = true;
			}
			else
				print("          <option value=".$a_record["id_groupe"].">");
			print($a_record["nom"]);
			print("</option>\n");
	  	}
  		if (!$found) print("<option selected value=\"-1\"></option>\n");
  		else print("<option value=\"-1\"></option>\n");
	}
	print("          </select>\n");
	print("          </td>\n");
	print("        </tr>\n");
	print("       </table><BR>\n");
/*******************************************************************************/	
/******************************** Grille ***************************************/
/*******************************************************************************/	
	if ($n > 0 && $G_nb_matieres > 0)
	{
    	print("  <table align=center border=0 cellspacing=0 cellpading=0 width=700 bgcolor=\"#C0C000\">\n");
		print("        <tr>\n");
		print("          <td colspan=4>\n");
    	print("            <table border=1 align=center width=100%>\n");
	    print("              <tr valign=BOTTOM>\n");
	    print("                <td><font size=3><i>Mati&egrave;re</i></font></td>\n");
		for ($i = 0;$i < $G_nb_types_seance;$i++)
			print("                <td><font size=3><i>".$G_libelle_type_seance[$i]."</i></font></td>\n");
	    print("              </tr>\n");
	    for ($i = 0;$i < $G_nb_matieres;$i++)
    	{
	    	print("              <tr valign=BOTTOM>\n");
      		print("                <td><i>$G_nom[$i]</i></td>\n");
			for ($j = 0;$j < $G_nb_types_seance;$j++)
      			print("                <td><input tabindex=".($i*$G_nb_types_seance+$j)." name=\"duree[".($i*$G_nb_types_seance+$j)."]\" size=8 OnChange=\"choice.value=".($i*$G_nb_types_seance+$j)."; submit();\" value=".$G_duree_type_seance[$j][$i]."></td>\n");
      		print("              </tr>\n");
    	}
    	print("             </table>\n");
		print("          </td>\n");
		print("        </tr>\n");
	}
   	print("  </table>\n");
   	print("</form>\n");
/******/	
/******/	
/*******************************************************************************/	
/*******************************************************************************/	
/*	if ($n > 0 && $G_nb_matieres > 0)
	{
	  print("<script language=JavaScript>\n");
	  if (!isset($choice))
	  {
	    $L = 0;
	    $R = 0;
	  }
	  else
	  {
	    $L=floor($choice/4);
	    $R=$choice-$L*4; 
	    if ($R == 3) 
	    {
		  $R = 0;
		  $L++;
	    }
	    if ($L > $G_nb_matieres) 
		{
	      $L = 0;
		}
	  }
	  print("var choix=$choice;\n");
	  print("var R=$R;\n");
	  print("var L=$L;\n");
      print("  document.form1.elements[".(5+4*$L+$R)."].focus();\n");
	  print("</script>\n");

	} */

	  buildEndOfPage();

	}
?>    



 
Return current item: EmploiNet : a timetable web manager