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

// Entete
    buildHeader("<font color=red> ATTENTION:</font><BR> Suppression d&eacute;finitive <br>d'&eacute;tudiants <br> ");

// 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);

//*****************************************

//**********Validation de la suppression********
            
            if((isset($test))&&($test=='Valider la suppression définitive')){
           
            	foreach($tab_etudiant as $etudiant){
	        	    // on enleve la photo de l'étudiant
		        	$result=mysql_query("select photo as p from etudiant WHERE (id_etudiant='$etudiant')");
		        	$img=mysql_fetch_array($result);
		        	if($img["p"]!=''){
	    				unlink("tromb/Photos/$etudiant.jpg");  
		 			}    
	    	        mysql_query("DELETE FROM etudiant WHERE (id_etudiant='$etudiant')");
	                mysql_query("DELETE FROM inscrit WHERE (id_etudiant='$etudiant')");
	                mysql_query("DELETE FROM appartient WHERE (id_etudiant='$etudiant')");
				}
              
	            //enlever l'étudiant de la base session
	            openConnection("session");
	            foreach($tab_etudiant as $etudiant){
		            $result=mysql_query("select login from appartient where id_type_user=2 and id=$etudiant");
		            $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'"); 
        	    }
		        $connection = openConnection($databaseName);	//  on se reconnecte à la base emploi du temps 
															//  car on était connecté à la base session
            }
//************************************************

// Choisir la promotion
		print("<FORM METHOD=POST ACTION=\"SupprimerEtudiant_promo.php\">\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)){
                    
                  print("<script language=\"JavaScript\">\n");
		  print("function openOne(v)\n");
		  print("{\n");
		  
	 	  print("  document.form1.submit();\n");
		  print("}\n");
		  print("function openTwo(v)\n");
		  print("{\n");
		  print("  document.form2.choice.value = v;\n");
		  print("  document.form2.submit();\n");
		  print("}\n");
		  
		  print("</script>\n");

                  echo "<form name='form1' method='post' action='ListeEtudiant_aSupprimer.php'>\n";
                  echo "<input type='hidden' name='id_promotion' value='$id_promotion'>\n";
                  echo "<input type='hidden' name='id_session' value='$id_session'>\n";
                  
                  //**********sélection des étudiants de la promotion sélectionnée**********
                  $result1=mysql_query("select e.id_etudiant as id,nom,prenom from etudiant e,inscrit i where e.id_etudiant=i.id_etudiant and id_promotion=$id_promotion order by nom");
                  $result2=mysql_query("SELECT id_promotion as id,diplome.libelle as L1,promotion.libelle as L2 FROM promotion,diplome WHERE promotion.id_diplome=diplome.id_diplome and id_promotion<>$id_promotion ORDER BY diplome.libelle");
                  echo "<table align=center border=0 cellspacing=10 cellpading=0 width=700 bgcolor=\"#C0C000\">\n";
                  echo "<tr>\n";
                  $nbEtudiant=mysql_num_rows($result1);     // pour voir si la promotion sélectionnée possède des étudiants
                  if($nbEtudiant==0) {
                    echo "<td align='center'><i>Il n'y a pas d'étudiants<br>dans la promotion sélectionnée</i></td>\n";
                  }
                  else {
                    echo "<td><i>&eacute;tudiants de la promotion : </i></td>\n";
                    echo "<td align='left'><select multiple name='tab_etudiant[]' size=8>\n";
                  
                    $etudiant=mysql_fetch_array($result1);
                    if((isset ($choice)) && ($choice==1)){
                      while($etudiant){
                        echo "<option selected value='".$etudiant["id"]."' >".$etudiant["nom"]." ".$etudiant["prenom"]."</option>\n";
                        $etudiant=mysql_fetch_array($result1);   
             	      }
                    }
                    else {
                      while($etudiant){
                        echo "<option value='".$etudiant["id"]."'>".$etudiant["nom"]." ".$etudiant["prenom"]."</option>\n";
                        $etudiant=mysql_fetch_array($result1);
                      }
                    }

                    echo "</td>\n";
                    echo "</tr>\n";
                    echo "<tr bgcolor=\"#FFFFD0\">\n";
                    echo "<td colspan=4 align='center'>\n";
		    print("	 <table border=1 cellpading=0 cellspacing=0 width=700><tr><td>\n");
    		    print("      <table border=0 cellspacing=1 cellpading=5 align=center bgcolor=\"#FFFFD0\">\n");
    		    print("        <tr valign=middle align=center>\n");
    		    print("          <td width=40><a href=\"javascript:openTwo(1);\"><img border=0 src=\"../img/selectAll.gif\" alt=\"Sélectionner tous les étudiants\"></td>\n");
    		    print("          <td width=40><a href=\"javascript:openOne(2);\"><img border=0 src=\"../img/DeleteButton.gif\" alt=\"Supprimer\"></td>\n");
 	            print("          <td width=40><a href=\"javascript:openTwo(3);\"><img border=0 src=\"../img/EraseButton.gif\" alt=\"Annuler\"></td>\n");
 	            print("        </tr>\n");
  	            print("      </table>\n");
  	            print("    </td></tr></table>\n");
  	            echo "</td>\n";
  	          }
  	          echo "</tr>\n";
                  echo "</table>\n";
                  echo "</form>\n";
                  echo "<form name='form2' method='post' action='SupprimerEtudiant_promo.php'>\n";
                  echo "<input type='hidden' name='id_promotion' value='$id_promotion'>\n";
                  echo "<input type='hidden' name='id_session' value='$id_session'>\n";
                  echo "<input type='hidden' name='choice'>\n";
                  
                  echo "</form>\n";
                } 
                     
    }
buildEndOfPage();
?>
Return current item: EmploiNet : a timetable web manager