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

// Entete
    buildHeader("Groupe");

// 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,"groupe.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=\"groupe.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");
		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))
		{		
			$G_groupe = new Groupe(-1,"","");
			$G_id_promotion;
			$G_nb_inscriptions = 0; 

      function remplir_formulaire($index, $result)
      {
        global $G_groupe;
  	    global $G_nb_inscriptions; 
		global $G_id_promotion;
      
        if (mysql_data_seek($result,$index))
        {
          $un_groupe = mysql_fetch_array($result);   
          $G_groupe->id_groupe = $un_groupe["id_groupe"];
          $G_groupe->nom = $un_groupe["nom"];
          $G_groupe->id_type_groupe = $un_groupe["id_type_groupe"];
          $result2 = mysql_query("SELECT * FROM associer WHERE id_groupe=$G_groupe->id_groupe");
          $G_nb_inscriptions = mysql_num_rows($result2); 
          for ($i=0;$i<$G_nb_inscriptions;$i++)
          {
            $une_inscription = mysql_fetch_array($result2);
			$G_id_promotion[$i] = $une_inscription["id_promotion"];
     	  }

        }
        else
          print("Error: mysql_data_seek"); 
      }

      function selectRecords()
      {
	  	global $id_promotion;
		
        return mysql_query("SELECT distinct(groupe.id_groupe),nom,id_type_groupe FROM groupe,associer WHERE associer.id_promotion=$id_promotion AND groupe.id_groupe=associer.id_groupe ORDER BY nom");
      }
    
      function deleteRecord($keyValue)
      {
        mysql_query("DELETE FROM groupe WHERE (id_groupe='$keyValue')");
        mysql_query("DELETE FROM associer WHERE (id_groupe='$keyValue')");
      }

      function modifyRecord($keyValue)
      {
 	    global $nom;
		global $id_type_groupe;
		global $id_promotion;

        mysql_query("UPDATE groupe SET nom='$nom',id_type_groupe='$id_type_groupe' WHERE id_groupe=$keyValue");
		mysql_query("DELETE FROM associer WHERE id_groupe=$keyValue");
		$n = count($id_promotion);
		for ($i=0;$i<$n;$i++)
		{
		  mysql_query("INSERT INTO associer VALUES ($keyValue,".($id_promotion[$i]).")");
		} 
      }

      function newRecord()
      {
		global $id_groupe;
	    global $nom;
	    global $id_type_groupe;
		global $id_promotion;
		global $G_groupe;

        if ($nom != "" && $nom != "- Obligatoire -")
		{
		  $id_groupe = getKeyValue("id_groupe");
		  mysql_query("INSERT INTO groupe VALUES('$id_groupe','$nom','$id_type_groupe')");
		  $n = count($id_promotion);
		  for ($i=0;$i<$n;$i++)
		  {
		    mysql_query("INSERT INTO associer VALUES ($id_groupe,".($id_promotion[$i]).")");
		  } 
//		  return $id_groupe;
			echo "<script language='javascript'>\n";
            echo "alert(\"Le groupe $nom est crée\");\n";
            echo "</script>\n";
			// ---
//		   return $id_etudiant;
		return -1; // F. Nolot pour effacer le formulaire une fois l'insertion terminée
		}
		else
		{
		  $G_groupe->nom = "- Obligatoire -";
		  return -1;
		}
      }

//***********************************************************************************************
//* Navigation et rechercheId
//***********************************************************************************************

	  function customPerform()
	  {
	  }

      perform($id_groupe,"id_groupe");

//***********************************************************************************************
//* Fin de la navigation
//***********************************************************************************************

// Formulaire de saisie
			function buildCustomFields()
		  	{
				global $id_promotion;
				
		  		print("<INPUT TYPE=HIDDEN NAME=\"id_promotion\" VALUE=$id_promotion>\n");
		  	}

	  $form["Name"]=array("","Nom","Type","Associ&eacute; &agrave;");
	  $form["Type"]=array(0,1,5,2);
	  $form["FieldName"]=array("id_groupe","nom","id_type_groupe","id_promotion");
	  $form["Value"]=array($G_groupe->id_groupe,$G_groupe->nom,$G_groupe->id_type_groupe,$id_promotion);
	  $form["KeyName"]=array("","","id_type_groupe","id_promotion");
	  $form["Request"]=array("","","SELECT * FROM typegroupe","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");
	  $form["Fields"]=array("","",array("libelle"),array("L1","L2"));
	  $form["Length"]=array(0,32,1,10);
	  $form["NewLine"]=array(false,true,true,false);

			buildForm("groupe.php3",$form,$id_session,0,$user_type,$user_id,$display);
		}
	}
	buildEndOfPage();
?>    

Return current item: EmploiNet : a timetable web manager