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

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

// Entete
    buildHeader("Promotion");

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

		$G_promotion = new Promotion(-1,-1,"","",-1,-1,-1);
  
		function remplir_formulaire($index, $result)
      	{
			global $G_promotion;
      
        	if (mysql_data_seek($result,$index))
        	{
          		$une_promotion = mysql_fetch_array($result);   
          		$G_promotion->id_promotion = $une_promotion["id_promotion"];
          		$G_promotion->id_diplome = $une_promotion["id_diplome"];
          		$G_promotion->libelle = $une_promotion["libelle"];
				$G_promotion->sigle = $une_promotion["sigle"];
				$G_promotion->id_cgu = $une_promotion["id_cgu"];
				$G_promotion->id_departement = $une_promotion["id_departement"];
				$G_promotion->id_professeur = $une_promotion["id_professeur"];
        	}
        	else print("Error: mysql_data_seek"); 
      	}

      	function selectRecords()
      	{
        	return mysql_query("SELECT * FROM promotion ORDER BY id_diplome");
      	}

      	function deleteRecord($keyValue)
      	{
        	mysql_query("DELETE FROM promotion WHERE (id_promotion='$keyValue')");
			mysql_query("DELETE FROM periode WHERE (id_promotion='$keyValue')");
     	}

      	function modifyRecord($keyValue)
      	{
 	    	global $id_diplome;
			global $libelle;
			global $sigle;
			global $id_cgu;
			global $id_departement;
			global $id_professeur;
			global $id_periode;
			global $numero_semaine_debut;
			global $nb_semaines;

        	mysql_query("UPDATE promotion SET id_diplome='$id_diplome',libelle='$libelle',sigle='$sigle',id_cgu='$id_cgu',id_departement='$id_departement',id_professeur='$id_professeur' WHERE id_promotion=$keyValue");
			for ($i=0;$i<4;$i++)
			{
				if ($numero_semaine_debut[$i]!="" && $nb_semaines[$i]!="")
				{
					if ($id_periode[$i]!=-1)
					{
						mysql_query("UPDATE periode SET numero_semaine_debut='".$numero_semaine_debut[$i]."',nb_semaines='".$nb_semaines[$i]."' WHERE id_periode=".$id_periode[$i]);
					}
					else // nouvelle periode
					{
			  			$id_periode2 = getKeyValue("id_periode");
					  	mysql_query("INSERT INTO periode VALUES('$id_periode2','$keyValue','".($i+1)."','".$numero_semaine_debut[$i]."','".$nb_semaines[$i]."')");
					}
				}
				else
				{
					if ($id_periode[$i]!=-1)
						mysql_query("DELETE FROM periode WHERE (id_periode='".$id_periode[$i]."')");
				}
			}
      	}

      	function newRecord()
      	{
			global $id_promotion;
	    	global $id_diplome;
	    	global $libelle;
			global $sigle;
			global $id_cgu;
			global $id_departement;
			global $id_professeur;
			global $numero_semaine_debut;
			global $nb_semaines;
			global $G_promotion;

        	if ($libelle != "" && $libelle != "- Obligatoire -" && $sigle != "" && $sigle != "- Obligatoire -")
			{
		  		$id_promotion = getKeyValue("id_promotion");
			  	mysql_query("INSERT INTO promotion VALUES('$id_promotion','$id_diplome','$libelle','$sigle','$id_cgu','$id_departement','$id_professeur')");
				for ($i=0;$i<4;$i++)
				{
					if ($numero_semaine_debut[$i]!="" && $nb_semaines[$i]!="")
					{
			  			$id_periode2 = getKeyValue("id_periode");
					  	mysql_query("INSERT INTO periode VALUES('$id_periode2','$id_promotion','".($i+1)."','".$numero_semaine_debut[$i]."','".$nb_semaines[$i]."')");
					}
				}
//		  		return $id_promotion;
				echo "<script language='javascript'>\n";
				 echo "  window.alert('Promotion ajoutée');\n";
                 echo "</script>\n";
				return -1; // F. Nolot pour effacer le formaulaire une fois l'insertion terminée
			}
			else
			{
		  		$G_promotion->libelle = "- Obligatoire -"; 		  
		  		$G_promotion->sigle = "- Obligatoire -"; 		  
		  		return -1;
			}
      	}

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

		perform($id_promotion,"id_promotion");

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

// Formulaire de saisie

      	function buildCustomFields()
	  	{
			global $G_promotion;
			
			print("        <tr>\n");
    	  	print("          <td valign=top nowrap><i>P&eacute;riodes :</i></td>\n");
		  	print("          <td>&nbsp;</td>\n");
			print("        </tr>\n");
			print("        <tr>\n");
			print("        <td colspan=2><table border=1 width=100% bgcolor=\"#C0C000\"><tr>\n");
		  	print("          <td align=center><i>Num&eacute;ro de la p&eacute;riode</i></td>\n");
		  	print("          <td align=center><i>Num&eacute;ro de la premi&egrave;re semaine</i></td>\n");
		  	print("          <td align=center><i>Nombre de semaines</i></td>\n");
			print("        </tr>\n");
			$request = "SELECT * FROM periode WHERE id_promotion = ".$G_promotion->id_promotion." ORDER BY numero";
	
			$result = mysql_query($request);
			if ($result!=0) $nb_periodes = mysql_num_rows($result);
			else $nb_periodes = 0;
			for ($i=0;$i<$nb_periodes;$i++)
			{
				$une_periode = mysql_fetch_row($result);
				print("        <tr>\n");
			  	print("          <td align=center>".($i+1)."\n");
				print("          <input type=hidden name=id_periode[$i] value=$une_periode[0]>\n");
			    print("          </td>\n");
			  	print("          <td align=center><input name=numero_semaine_debut[$i] value=\"$une_periode[3]\"></td>\n");
			  	print("          <td align=center><input name=nb_semaines[$i] value=\"$une_periode[4]\"></td>\n");
				print("        </tr>\n");
			}
			for ($i=$nb_periodes;$i<4;$i++)
			{
				
				print("        <tr>\n");
			  	print("          <td align=center>".($i+1)."\n");
				print("          <input type=hidden name=id_periode[$i] value=-1>\n");
			    print("          </td>\n");
			  	print("          <td align=center><input name=numero_semaine_debut[$i]></td>\n");
			  	print("          <td align=center><input name=nb_semaines[$i]></td>\n");
				print("        </tr>\n");
			}
			print("       </table><td>\n");
			print("       </tr>\n");
	  	}

	  	$form["Name"]=array("","Dipl&ocirc;me","Libell&eacute;","Sigle","Site","D&eacute;partement de rattachement","Pr&eacute;sident de jury");
	  	$form["Type"]=array(0,5,1,1,5,5,5);
	  	$form["FieldName"]=array("id_promotion","id_diplome","libelle","sigle","id_cgu","id_departement","id_professeur");
	  	$form["Value"]=array($G_promotion->id_promotion,$G_promotion->id_diplome,$G_promotion->libelle,$G_promotion->sigle,$G_promotion->id_cgu,$G_promotion->id_departement,$G_promotion->id_professeur);
	  	$form["KeyName"]=array("","id_diplome","","","id_cgu","id_departement","id_professeur");
	  	$form["Request"]=array("","SELECT * FROM diplome ORDER BY libelle","","","SELECT * FROM cgu ORDER BY libelle","SELECT * FROM departement ORDER BY libelle","SELECT * FROM professeur ORDER BY nom,prenom");
	  	$form["Fields"]=array("",array("libelle"),"","",array("libelle"),array("libelle"),array("nom","prenom"));
	  	$form["Length"]=array(0,1,50,32,1,1,1);
	  	$form["NewLine"]=array(false,true,true,true,true,true,true);

	  	buildForm("promotion.php3",$form,$id_session,0,$user_type,$user_id,$display);
  	}
  	buildEndOfPage();
?>
Return current item: EmploiNet : a timetable web manager