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

// Entete
    buildHeader("Etudiant");

// 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,"etudiant.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=\"etudiant.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("</option>\n");
			}
			print("          </select>\n");
		}
		print("          </td>\n");
		print("        </tr>\n");
		print("      </table>\n");
		print("  </FORM>\n");
//**
//*****************************************
	  
		if (isset($id_promotion))
		{		
	  		$G_etudiant = new Etudiant(-1,-1,"","","","","","","");
  			$G_id_promotion;
  			$G_nb_inscriptions = 0; 
            if(!isset($choice)){$choice=0;}
                        
                         
			function remplir_formulaire($index, $result)
			{
				global $G_etudiant;
				global $G_nb_inscriptions; 
				global $G_id_promotion;

				if (mysql_data_seek($result,$index))
				{
					$un_etudiant = mysql_fetch_array($result);   
					$G_etudiant->id_etudiant = $un_etudiant["id_etudiant"];
					$G_etudiant->ine = $un_etudiant["ine"];
					$G_etudiant->nom = $un_etudiant["nom"];
					$G_etudiant->prenom = $un_etudiant["prenom"];
					$G_etudiant->adresse = $un_etudiant["adresse"];
					$G_etudiant->code_postal = $un_etudiant["code_postal"];
					$G_etudiant->ville = $un_etudiant["ville"];
					$G_etudiant->email = $un_etudiant["email"];
					$G_etudiant->tel = $un_etudiant["tel"];

					$result2 = mysql_query("SELECT * FROM inscrit WHERE id_etudiant=$G_etudiant->id_etudiant");
					$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"];
					}
				}
			}

			function selectRecords()
			{
				global $id_promotion;
				return mysql_query("SELECT distinct(etudiant.id_etudiant),ine,nom,prenom,adresse,code_postal,ville,email,tel FROM etudiant,inscrit WHERE inscrit.id_promotion=$id_promotion AND etudiant.id_etudiant=inscrit.id_etudiant ORDER BY nom");
			}
  
      function deleteRecord($keyValue)
      {
        global $databaseName;
        
        // on enleve la photo de l'étudiant
        $result=mysql_query("select photo as p from etudiant WHERE (id_etudiant='$keyValue')");
        $img=mysql_fetch_array($result);
        if($img["p"]!=''){
          unlink("tromb/Photos/$keyValue.jpg");  
 		}
        //on enleve l'étudiant de la base emploi_du_temps
        mysql_query("DELETE FROM etudiant WHERE (id_etudiant='$keyValue')");
        mysql_query("DELETE FROM inscrit WHERE (id_etudiant='$keyValue')");
        mysql_query("DELETE FROM appartient WHERE (id_etudiant='$keyValue')");

        //on enleve l'étudiant de la base session
        openConnection("session");
        $result=mysql_query("select login from appartient where id_type_user=2 and id=$keyValue");
        $loginRES=mysql_fetch_array($result);
        $login=$loginRES["login"];
        mysql_query("delete from appartient where login='$login'");
        mysql_query("delete from session where login='$login'");
        mysql_query("delete from user where login='$login'");
        openConnection($databaseName);
      }

      function modifyRecord($keyValue,$int)      //$int=0 : pour modifier uniquement           
      { 					 //    =1 : pour changer de promotion
      
        global $ine;
        global $nom;
		global $prenom;
		global $adresse;
		global $code_postal;
		global $ville;
		global $email;
		global $tel;
		global $tab_promotion;
		global $id_promotion;
                
                $found=0;
                $ind=0;
                $cpt=count($tab_promotion);
                while((!$found)&&($ind<$cpt)) {
                  if ($tab_promotion[$ind]==$id_promotion) {
                    $found=1;
                  }
                  $ind++;
                }
                if(!($found)&&($int==0)) {
                  echo "<script language='javascript'>\n";
                  echo "alert(\"La promotion initiale n'apparait pas\\ndans les promotions sélectionnées \");\n";
                  echo "</script>\n";
                }
                else {
        	  mysql_query("UPDATE etudiant SET ine='$ine',nom='$nom',prenom='$prenom',adresse='$adresse',code_postal='$code_postal',ville='$ville',email='$email',tel='$tel' WHERE id_etudiant=$keyValue");
		  mysql_query("DELETE FROM inscrit WHERE id_etudiant=$keyValue");

		
		  for ($i=0;$i<$cpt;$i++) {                                                    
		    mysql_query("INSERT INTO inscrit VALUES ($keyValue,".$tab_promotion[$i].")");
		  }

		  if($int==1) {
		  //************on s'occupe de la purge dans la table appartient******************
                                           
                      $resultat=mysql_query("select id_groupe as id from associer where id_promotion=$id_promotion");
                      $nbG=mysql_num_rows($resultat);
                      if($nbG!=0){
                        //*****************on met dans le tableau tab_idGroupe les groupes associés à ma promotion sélectionnée**** 
                        $ind=0;
                        $groupe_id=mysql_fetch_array($resultat);
                        while($groupe_id){
                          $tab_idGroupe[$ind]=$groupe_id["id"];
                          $ind++;
                          $groupe_id=mysql_fetch_array($resultat);
                        }
                        //*********************************************************************************************************
                        
                        //************on compare les groupes dans lesquels est inscrit l'étudiant avec les groupes correspondants à la promotion*
                       
                          $resultat=mysql_query("select id_groupe as id from appartient where id_etudiant=$keyValue");
                          $nbGr=mysql_num_rows($resultat);
                          if($nbGr!=0){
                            $id1_groupe=mysql_fetch_array($resultat);
                            while($id1_groupe){
                              foreach($tab_idGroupe as $id2_groupe){
                                if($id1_groupe["id"]==$id2_groupe){
                                  mysql_query("delete from appartient where id_groupe=".$id1_groupe["id"]." and id_etudiant=$keyValue");
                                }
                              }
                              $id1_groupe=mysql_fetch_array($resultat);
                            }
                          } 
		        
		      } 
		      
		      //***********************************fin de la purge d'appartient*******************************
		    }

	     }     

              
      }

      function newRecord()
     {
		global $databaseName;

		global $id_etudiant;
	    global $ine;
    	global $nom;
	    global $prenom;
		global $adresse;
		global $code_postal;
		global $ville;
		global $email;
		global $tel;
		global $id_promotion;
		global $tab_promotion;
		global $G_etudiant;

        if ($nom != "" && $prenom != "" && $nom != "- Obligatoire -" && $prenom != "- Obligatoire -")
		{
		       $n = count($tab_promotion);
	       
		       if($n==0){
		         echo "<script language='javascript'>\n";
				 echo "  window.alert('Aucune promotion sélectionnée!!');\n";
                 echo "</script>\n";
                 $G_etudiant->ine = $ine;
                 $G_etudiant->nom = $nom;
				 $G_etudiant->prenom = $prenom;
				 $G_etudiant->adresse = $adresse;
				 $G_etudiant->code_postal = $code_postal;
				 $G_etudiant->ville = $ville;
				 $G_etudiant->email = $email;
				 $G_etudiant->tel = $tel;
		         return(-1);
		       } 
		       else {
		         
		         $found=0;
                 $ind=0;
               
				while((!$found)&&($ind<$n)) {
                if ($tab_promotion[$ind]==$id_promotion) {
                $found=1;
                }
                $ind++;
                }
                         if(!($found)) {
                           echo "<script language='javascript'>\n";
                           echo "alert(\"il faut au moins inscrire l'étudiant\\ndans la promotion initiale\");\n";
                           echo "</script>\n";
                           $G_etudiant->ine = $ine;
                           $G_etudiant->nom = $nom;
			   $G_etudiant->prenom = $prenom;
			   $G_etudiant->adresse = $adresse;
			   $G_etudiant->code_postal = $code_postal;
			   $G_etudiant->ville = $ville;
			   $G_etudiant->email = $email;
			   $G_etudiant->tel = $tel;
                           return(-1);
                         }
                         else {
	        $id_etudiant = getKeyValue("id_etudiant");
			mysql_query("INSERT INTO etudiant VALUES('$id_etudiant','$ine','$nom','$prenom','$adresse','$code_postal','$ville','$email','$tel','','')");
	        for ($i=0;$i<$n;$i++) mysql_query("INSERT INTO inscrit VALUES ($id_etudiant,".($tab_promotion[$i]).")");
		  
// Creation d'un compte d'acces avec mot de passe
			   mysql_select_db("session");
			   $login = strtolower(substr($prenom,0,1).$nom);
			   $password = strtolower($prenom."00");
	           mysql_query("INSERT INTO user VALUES ('$login','$password',2,$id_etudiant)");
	           mysql_query("INSERT INTO appartient VALUES ('$login',2,$id_etudiant)");
			  mysql_select_db($databaseName);
			  //--- F. Nolot : Pour prévenir que l'inscription s'est bien passée.
			         echo "<script language='javascript'>\n";
                     echo "alert(\"$prenom $nom est inscrit\");\n";
                     echo "</script>\n";
			// ---
//		   return $id_etudiant;
		return -1; // F. Nolot pour effacer le formulaire une fois l'insertion terminée

		        }
		     }
		       
		}
		else
		{
			$G_etudiant->nom = "- Obligatoire -";
			$G_etudiant->prenom = "- Obligatoire -"; 		  
			return -1;
		}
      }

//***********************************************************************************************
//* Navigation et rechercheId
//***********************************************************************************************
      if((isset($id_Etudiant))&&($id_Etudiant!=-1)){$id_etudiant=$id_Etudiant;}
      perform($id_etudiant,"id_etudiant");

//***********************************************************************************************
//* 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("","INE","Nom","Pr&eacute;nom","Adresse","Code postal","Ville","E-mail","T&eacute;l","Inscrit en");
			$form["Type"]=array(0,1,1,1,3,1,1,1,1,2,2);
			$form["FieldName"]=array("id_etudiant","ine","nom","prenom","adresse","code_postal","ville","email","tel","id_promotion");
			$form["Value"]=array($G_etudiant->id_etudiant,$G_etudiant->ine,$G_etudiant->nom,$G_etudiant->prenom,$G_etudiant->adresse,$G_etudiant->code_postal,$G_etudiant->ville,$G_etudiant->email,$G_etudiant->tel,$G_id_promotion);
			$form["KeyName"]=array("","","","","","","","","","tab_promotion");
			$form["Request"]=array("","","","","","","","","","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("L1","L2"));
	        $form["Length"]=array(0,15,32,32,32,5,32,40,16,5);
	  		$form["NewLine"]=array(false,true,false,true,true,false,true,false,true,false);
 			buildForm("etudiant.php3",$form,$id_session,1,$user_type);
	  	}
	}
  	buildEndOfPage();
?>    
Return current item: EmploiNet : a timetable web manager