Location: PHPKode > projects > EmploiNet : a timetable web manager > EmploiNet/v0.8.0/Administration/appartient.php3
<?
    
    include("../BarreDeMenu.php3");
    
    include("../Session/security.php");

// Entete
    buildHeader("Constitution des groupes");

// 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,"appartient.php3",false);
// Ouverture de la connexion avec la base de donnees
	    $connection = openConnection($databaseName);

    $G_nb_etudiants;
	$G_id_etudiant;
	$G_nom;
	$G_prenom;
    $G_nb_etudiants_groupe;
	$G_id_etudiant_groupe;
	$G_nom_etudiant_groupe;
	$G_prenom_etudiant_groupe;

	$n = count($id_promotion);
	$m = count($id_groupe);
	if ($m > 0 && $choice != 4)
	{
		$result = mysql_query("SELECT id_etudiant FROM appartient WHERE id_groupe=$id_groupe[0]");
		$G_nb_etudiants_groupe = mysql_num_rows($result);
		for($i = 0;$i < $G_nb_etudiants_groupe;$i++)
	    {
	    	$un_etudiant = mysql_fetch_array($result);
			$G_id_etudiant_groupe[$i] = $un_etudiant["id_etudiant"];
			$result2 = mysql_query("SELECT distinct(nom),prenom FROM etudiant WHERE id_etudiant=$G_id_etudiant_groupe[$i]");
			$un_etudiant = mysql_fetch_array($result2);
			$G_nom_etudiant_groupe[$i] = $un_etudiant["nom"];
			$G_prenom_etudiant_groupe[$i] = $un_etudiant["prenom"];
		}	  			
	}

	switch ($choice)
	{
	  	case 1: $id_groupe = "";
			    $m = 0;
				break;
		case 2: $result = mysql_query("SELECT * FROM associer WHERE id_groupe=$id_groupe[0]");
          		$n = mysql_num_rows($result); 
		        for ($i=0;$i<$n;$i++)
          		{
            		$une_promotion = mysql_fetch_array($result);
	   	    		$id_promotion[$i] = $une_promotion["id_promotion"];
     	  		}	  
				break;
		case 3: $k = $G_nb_etudiants_groupe;
				$G_nb_etudiants_groupe += count($id_etudiant);
				$j = 0;
				for($i = $k;$i < $G_nb_etudiants_groupe;$i++)
				{
					$G_id_etudiant_groupe[$i] = $id_etudiant[$j];
					$result = mysql_query("SELECT nom,prenom FROM etudiant WHERE id_etudiant=$G_id_etudiant_groupe[$i]");
					$un_etudiant = mysql_fetch_array($result);
					$G_nom_etudiant_groupe[$i] = $un_etudiant["nom"];
					$G_prenom_etudiant_groupe[$i] = $un_etudiant["prenom"];
					$result = mysql_query("INSERT INTO appartient VALUES ($G_id_etudiant_groupe[$i],$id_groupe[0])");
					$j++;
				}
				break;
		case 4: $k = count($id_etudiant_groupe);
				for ($i=0;$i<$k;$i++)
				  mysql_query("DELETE FROM appartient WHERE id_groupe=$id_groupe[0] AND id_etudiant=$id_etudiant_groupe[$i]");
				break;
	}
	

	if ($n > 0)
	{	
		$where = "WHERE inscrit.id_promotion = $id_promotion[0] ";
		for ($i = 1;$i < $n;$i++)
			$where .= "OR inscrit.id_promotion = $id_promotion[$i] ";
		$result = mysql_query("SELECT distinct(etudiant.id_etudiant),nom,prenom FROM etudiant,inscrit $where AND etudiant.id_etudiant = inscrit.id_etudiant ORDER BY nom"); 
        $G_nb_etudiants = mysql_num_rows($result); 
        for ($i = 0;$i < $G_nb_etudiants;$i++)
		{
			$a_record = mysql_fetch_array($result);
			$G_id_etudiant[$i] = $a_record["id_etudiant"];
			$G_nom[$i] = $a_record["nom"];
			$G_prenom[$i] = $a_record["prenom"];
		}
	}
    print("<form action=\"appartient.php3\" method=post>\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");

    print("  <table align=center border=0 cellspacing=0 cellpading=0 width=700 bgcolor=\"#C0C000\">\n");
	print("  <tr>\n");
    print("    <td valign=middletop width=100><font size=3><i>Promotion :</i></font></td>\n");
	if ($n > 0) print("    <td width=250 align=left>\n");
	else print("    <td width=600 align=left>\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 multiple name=\"id_promotion[]\" size=8 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 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");
	if ($n > 0)
	{
	  print("    <td valign=middletop width=100><font size=3><i>Groupe :</i></font></td>\n");
	  print("    <td width=250>\n");
	  print("          <select name=\"id_groupe[]\" size=8 width=200 OnChange=\"choice.value = 2; submit();\">\n");
      $where="(";
      for ($i=0;$i<$n-1;$i++){
        $where.="id_promotion=".$id_promotion[$i]." or "; 
      }
      $where.="id_promotion=".$id_promotion[$n-1].")";
      $request="select distinct g.id_groupe,g.nom from associer a,groupe g where a.id_groupe=g.id_groupe and ".$where;
      
      $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 ($id_groupe[$j] == $a_record["id_groupe"])
		    $found = true;
	      else
	      	$j++;
	    }
		if ($found)
		  print("          <option value=".$a_record["id_groupe"]." selected>");
		else
		  print("          <option value=".$a_record["id_groupe"].">");
		print($a_record["nom"]);
		print("\n");
	  }
	  print("          </select>\n");
	  print("    </td>\n");
	}
	print("    </tr>\n");
	if ($n > 0)
	{
		print("  <tr><td colspan=4>\n");
	    print("        <table align=center border=1 cellspacing=0 cellpading=0 bgcolor=\"#C0C000\" width=650>\n");
		print("        <tr>\n");
		if ($n == 1) print("          <td valign=top width=150><font size=3><i>Etudiants de la promotion :</i></font></td>\n");
		else print("          <td valign=top width=150><font size=3><i>Etudiants des promotions :</i></font></td>\n");
		if ($m > 0) print("          <td width=150>\n");
		else print("          <td colspan = 4 width=500 align=left>\n");
		print("          <select name=\"id_etudiant[]\" multiple size=8 width=200>\n");
		for ($i=0;$i<$G_nb_etudiants;$i++)
			{
    		$found = false;
			$j = 0;
	    	while (!$found && $j<$G_nb_etudiants_groupe)
    		{		
	  			if ($G_id_etudiant[$i] == $G_id_etudiant_groupe[$j])
		        	$found = true;
	       		else
	      			$j++;
	    	}
			if (!$found) 
			{
				print("          <option value=".$G_id_etudiant[$i].">");
				print($G_nom[$i]." ".$G_prenom[$i]);
			}
		}
		print("          </select>\n");
		print("          </td>\n");
		if ($m > 0)
		{
			print("          <td valign = middle align = middle width = 50>\n");
			print("				<input type=button name=\"Ajouter\"  value=\" > \" OnClick=\"choice.value=3; submit();\"><BR><BR>\n");
			print("				<input type=button name=\"Supprimer\" value=\" < \" OnClick=\"choice.value=4; submit();\">\n");
			print("          </td>\n");
			print("          <td valign=top width=150><font size=3><i>Etudiants du groupe :</i></font></td>\n");
			print("          <td width=150>\n");
			print("          <select name=\"id_etudiant_groupe[]\" multiple size=8 width=200>\n");
			for ($i=0;$i<$G_nb_etudiants_groupe;$i++)
			{
				print("          <option value=".$G_id_etudiant_groupe[$i].">");
				print($G_nom_etudiant_groupe[$i]." ".$G_prenom_etudiant_groupe[$i]);
			} 
			print("          </select>\n");
			print("          </td>\n");
		}
		print("        </tr>\n");
		print("        </table>\n");
		print("  </TD></tr>\n");
	}	
	
    print("  </table>\n");
    print("</form>\n");
    print("<br><br>\n");
  }
  buildEndOfPage();
?>    

 
Return current item: EmploiNet : a timetable web manager