Location: PHPKode > projects > EmploiNet : a timetable web manager > EmploiNet/v0.8.0/projet/choixProjet.php
<?

include("../BarreDeMenu.php3");

include("../Session/security.php");

print("<HTML><HEAD>\n
<TITLE>Projet</TITLE>\n
</HEAD>\n
<BODY>\n");
// Verification de la session
$autorisation_list[0]=2; // étudiant
$user_type = validateSession($id_session);
if ($user_type == -1 || !security($id_session,$autorisation_list)) print("Accès refusé");
else {
  // Entete
  buildHeader("Choix du projet");

  // Barre de menu
 print("<FONT SIZE=2><I>\n");
 print("<A HREF='../index.php?id_session=$id_session'>Menu</A><BR>\n");
 print("</I></FONT>\n");

  /********recherche de l'id_etudiant de celui connecté*******************/
  /*$resultats=mysql_query("select a.id from appartient a,session s where a.login=s.login and a.id_type_user=2 and s.id_session='$id_session'");
  $idE=mysql_fetch_array($resultats);
  $id_etudiant=$idE["id"]; */

  $id_etudiant=getUserID($id_session);

    /**************************************************************************/
  
   // connection à la table emploi_du_temps
  openConnection($databaseName);
 
  
  //  vérification si le projet a ete validé ou non
  $requeteVerif=mysql_query("select id_groupeetudiant as id from etudiant where id_etudiant=$id_etudiant");
  if((mysql_num_rows($requeteVerif))) {
    $idGr=mysql_fetch_array($requeteVerif);
    $requeteTest=mysql_query("select * from validerprojet where id_groupeetudiant=".$idGr["id"]);
    if(mysql_num_rows($requeteTest)) {
      $dejaChoisi=1; 
    }
    else {
      $dejaChoisi=0; 
    }
  }
  else {
    $dejaChoisi=0;
  }
  if(!$dejaChoisi) {
    
    // Choisir la promotion
    print("<FORM METHOD=POST ACTION='choixProjet.php'>\n");
    print("<INPUT TYPE=HIDDEN NAME='id_session' VALUE='$id_session'>\n");
    print("  <table align=center border=0 cellspacing=0 cellpadding=0 width=600 bgcolor=\"#B1D0F3\">\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");
    
    //*******************on liste les promotions dans lesquelles l'etudiant connecté est inscrit******************/
    
    $resultat=mysql_query("select id_promotion as idP from inscrit where id_etudiant=$id_etudiant");
    $nbPromo=mysql_num_rows($resultat);
    $where="";
    if($nbPromo>=2){
      $id_promo=mysql_fetch_array($resultat);
      $where.="(id_promotion=".$id_promo["idP"]." or ";
      
      if($nbPromo==2){
        $id_promo=mysql_fetch_array($resultat);
        $where.="id_promotion=".$id_promo["idP"].")";
      }
      else{
        for($i=1;$i<$nbPromo-1;$i++){
          $id_promo=mysql_fetch_array($resultat);
          $where.="id_promotion=".$id_promo["idP"]." or ";
        }
      }
      if($nbPromo>2){
        $id_promo=mysql_fetch_array($resultat);
        $where.="id_promotion=".$id_promo["idP"].")";
      }
    }
    else{
      $id_promo=mysql_fetch_array($resultat);
      $where.="id_promotion=".$id_promo["idP"];
    }
    
    /************************************************************************************************************/
    
    $result = mysql_query("SELECT id_promotion,diplome.libelle as L1,promotion.libelle as L2 FROM promotion,diplome WHERE"." ".$where." "."and promotion.id_diplome=diplome.id_diplome ORDER BY diplome.libelle");
    $index_max = mysql_num_rows($result); 
		if ($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)){
   
   if(isset($envoie)||isset($remodifier)) {
     $resultProj=mysql_query("select * from projet where id_promotion=$id_promotion order by descriptif");
     $nbProj=mysql_num_rows($resultProj);
     for($i=0;$i<$nbProj;$i++) {
       $proj=mysql_fetch_array($resultProj);
       if(isset($choice[$proj["num_proj"]])) {
         if(isset($envoie)) {
           $r1=mysql_query("insert into associerchoixprojet (id_groupeetudiant,preferenceChoix,num_proj) values ('$id_groupeetudiant','".$choice[$proj["num_proj"]]."','".$proj["num_proj"]."')");
           if(!$r1) {
             print("
             <script language='javascript'>
               alert('Il faut appuyer sur modifier pour changer votre choix sur le projet n°".($i+1)."');
             </script>");
           }
         }
         else {
            mysql_query("update associerchoixprojet set preferenceChoix=".$choice[$proj["num_proj"]]." where id_groupeetudiant=$id_groupeetudiant and num_proj=".$proj["num_proj"]);
         }
       }
     }
   }
   
   
   if(isset($annuler)||isset($effacer)) {
     $requeteID=mysql_query("select id_groupeetudiant from etudiant where id_etudiant=$id_etudiant");
     $IdGroupeE=mysql_fetch_array($requeteID);
     $id=$IdGroupeE["id_groupeetudiant"];
     if(!isset($effacer)) {
       mysql_query("delete from groupeetudiant where id_groupeetudiant=$id");
       mysql_query("update etudiant set id_groupeetudiant=0 where id_groupeetudiant=$id");
     }
     mysql_query("delete from associerchoixprojet where id_groupeetudiant=$id");
   }
   
   if(isset($valider)) {
     
     
     if(!isset($modif)) {
       $requeteG=mysql_query("select id_groupeetudiant as idG from id");
       $numG=mysql_fetch_array($requeteG);
       $ancien=$numG["idG"];
       $nouveau=($ancien+1);
       mysql_query("insert into groupeetudiant (id_groupeetudiant) values ('$nouveau')");
       mysql_query("update id set id_groupeetudiant='$nouveau' where id_groupeetudiant='$ancien'");
       mysql_query("update etudiant set id_groupeetudiant='$nouveau' where id_etudiant='$id_etudiant'");
     }
     $nbE=(count($tab_etudiant));
     if($nbE>0) {
       if($nbE<10) {
         $requeteID=mysql_query("select id_groupeetudiant from etudiant where id_etudiant=$id_etudiant");
         $IdGroupeE=mysql_fetch_array($requeteID);
         $nouveau=$IdGroupeE["id_groupeetudiant"];
         foreach($tab_etudiant as $etudiant) {
           $requeteSecurite=mysql_query("select id_groupeetudiant as id,nom,prenom from etudiant where id_etudiant=$etudiant");
           $test=mysql_fetch_array($requeteSecurite);
           if ($test["id"]!=0) {
             print("
             <script language='javascript'>
               alert('L\'étudiant(e) ".$test["nom"]." ".$test["prenom"]." est déjà dans un groupe');
             </script>");
           }
           else {
             mysql_query("update etudiant set id_groupeetudiant='$nouveau' where id_etudiant='$etudiant'");   
           }
         }
       }
       else {
         print("
         <script language='javascript'>
           alert('Les groupes à plus de 10 étudiants \\n ne sont pas autorisés');
         </script>");
         $modifier=0;
       }
     }
   }
      
   $requete=mysql_query("select * from etudiant where id_etudiant=$id_etudiant");
   $Letudiant=mysql_fetch_array($requete);
   if($Letudiant["id_groupeetudiant"]>0) {
     $id_groupeetudiant=$Letudiant["id_groupeetudiant"];
   }   
   if(!isset($id_groupeetudiant)||(isset($modifier))) {
     if(isset($tab_modif_groupe)) {
       if(($n=count($tab_modif_groupe))>0) {
         foreach($tab_modif_groupe as $elt) {
           mysql_query("update etudiant set id_groupeetudiant='0' where id_etudiant=$elt and id_groupeetudiant=$id_groupeetudiant");
         }
       }
     }
     $requete1=mysql_query("select e.id_etudiant as id,nom,prenom from etudiant e,inscrit i where e.id_etudiant=i.id_etudiant and i.id_promotion=$id_promotion and e.id_etudiant<>$id_etudiant and e.id_groupeetudiant='0' order by nom");
     echo "<form method='POST' name='form1' action='choixProjet.php'>\n";
     if(isset($modifier)) {
       echo "<INPUT TYPE=HIDDEN NAME='modif' VALUE='1'>\n";
     }
     echo "<INPUT TYPE=HIDDEN NAME='id_session' VALUE='$id_session'>\n";
     echo "<INPUT TYPE=HIDDEN NAME='id_promotion' VALUE='$id_promotion'>\n";
     echo "<table align='center' border=0 cellpadding=5 cellspacing=5 bgcolor='#C0C000' width=600>\n";
     echo "<col span=3 align=center>\n";
     echo "<tr><td colspan=3>".$Letudiant["nom"]." ".$Letudiant["prenom"]."<br><br><b>Constituez votre groupe <br>(avec au maximum 2 autres personnes)<br>ou<br>valider pour être seul(e)</b></td>\n";
     echo "<td>";
     $nbE=mysql_num_rows($requete1);
     echo "<select size=10 multiple name='tab_etudiant[]'>\n";
     for($i=0;$i<$nbE;$i++) {
       $unEtudiant=mysql_fetch_array($requete1);
       echo "<option value='".$unEtudiant["id"]."'>".$unEtudiant["nom"]." ".$unEtudiant["prenom"]."\n";
     }
     echo "</select></td>\n";
     echo "<td colspan=2><input type=submit name=valider value=Valider>&nbsp;&nbsp;&nbsp;";
     echo "<input type=reset value=Annuler></td></tr>\n";
     echo "</table></form>\n";  
   }
   else {
     $request=mysql_query("select id_etudiant as id,nom,prenom from etudiant where id_groupeetudiant=$id_groupeetudiant and id_etudiant<>$id_etudiant order by nom");
     echo "<form method='POST' name='form2' action='choixProjet.php'>\n";
     echo "<INPUT TYPE=HIDDEN NAME='id_session' VALUE='$id_session'>\n";
     echo "<INPUT TYPE=HIDDEN NAME='id_promotion' VALUE='$id_promotion'>\n";
     echo "<table align='center' border=0 cellpadding=5 cellspacing=5 bgcolor='#C0C000' width=600>\n";
     echo "<col span=2 align=center>\n";
     echo "<tr><td>";
     echo $Letudiant["nom"]." ".$Letudiant["prenom"]."<br>\n";
     $nbGE=mysql_num_rows($request);
     for($i=0;$i<$nbGE;$i++) {
       $un_etudiant=mysql_fetch_array($request);
       echo "<INPUT TYPE=HIDDEN NAME='tab_modif_groupe[$i]' VALUE='".$un_etudiant["id"]."'>\n";
       echo $un_etudiant["nom"]." ".$un_etudiant["prenom"]."<br>\n";
     }
     echo "</td>\n";
     echo "<td><input type=submit name=modifier value=Modifier>&nbsp;";
     echo "<input type=submit name=annuler value=Annuler></td>\n";
     echo "</tr></table>\n";
     echo "</form>\n";
   
     $resultp=mysql_query("select * from projet where id_promotion=$id_promotion order by descriptif");
     
     echo "<table align='center' border=0 cellpadding=5 cellspacing=5 bgcolor='#C0C000' width=600>\n";
     echo "<tr><td align=center><b>Choisissez votre projet en effectuant 5 choix parmi les projets proposés <br>( par ordre de préférence )</b></td></tr>\n";
     echo "</table>\n";
     
     print("
     <form method='POST' name='form3' action='choixProjet.php'>  
     <INPUT TYPE=HIDDEN NAME='id_session' VALUE='$id_session'>
     <INPUT TYPE=HIDDEN NAME='id_promotion' VALUE='$id_promotion'>
     <INPUT TYPE=HIDDEN NAME='id_groupeetudiant' VALUE='$id_groupeetudiant'>
     
     <table align='center' border=2 cellpadding=5 cellspacing=5 bgcolor='#C0C000' bordercolor='black'>
     <col span=8 align=center>
     <tr>
     <td>&nbsp;</td>\n");
     print("
     <th>Enseignant<br>responsable</th>
     <th>Nombre d'étudiants<br>par projet</th>\n");
     for ($i=1;$i<6;$i++){
     if ($i==1) {echo "<th width='10%' height='19' align='center'>".$i."er choix</th>\n";}
     else  {echo "<th width='10%' height='19' align='center'>".$i."&egrave;me choix</th>\n";}
     }
     printf("</tr>");
     $j=0;
     while( $enr = mysql_fetch_array( $resultp )){
       $j++;
       echo "<tr>\n<td align=left><A HREF=\"".$enr["url"]."\" TARGET=\"projet\">Projet n° $j : ";
       echo $enr["descriptif"]."</A></td>\n";
       $req=mysql_query("select nom,prenom,nb_etudiant from projet p,professeur pr where p.id_professeur=pr.id_professeur and num_proj=".$enr["num_proj"]);
       $res=mysql_fetch_array($req);
       echo "<td>".$res["nom"]." ".$res["prenom"]."</td>\n";
       echo "<td>".$res["nb_etudiant"]."</td>\n";
       for ($i=1;$i<6;$i++) {
         $request1=mysql_query("select preferenceChoix as pc from associerchoixprojet where id_groupeetudiant=$id_groupeetudiant and num_proj=".$enr["num_proj"]);
         $Pchoix=mysql_fetch_array($request1);
         if(((isset($choice[$enr["num_proj"]])&&($choice[$enr["num_proj"]]==$i))||($Pchoix["pc"]==$i))&&(!isset($effacer))) {
	   echo "<td width='10%' height='1' align='center'><input type='radio' value=$i name='choice[".$enr["num_proj"]."]' checked>$i</td>\n";
	 }
	 else {
	   echo "<td width='10%' height='1' align='center'><input type='radio' value=$i name='choice[".$enr["num_proj"]."]'>$i</td>\n"; 
	 }
       }
       print("</tr>\n");
     }
     print("</table>
     <BR>
     <center><input type='submit' value='Envoyer' name='envoie'>&nbsp;&nbsp;&nbsp;\n");
     print("
     <input type='submit' value='Effacer' name='effacer'>&nbsp;&nbsp;&nbsp;
     <input type='submit' value='Modifier' name='remodifier'></center>
     </form>\n");
   }
 }
}
else {
  echo "<table align='center' border=0 cellpadding=20 cellspacing=5 bgcolor='#C0C000' width=600>\n";
  echo "<tr><th align=center>Vous ne pouvez plus accéder à cette page car vous avez maintenant un projet !!</th></tr>\n";
  echo "</table>\n";
}
}
buildEndOfPage();
print("
</body>
</BODY>
</HTML>");


?>
Return current item: EmploiNet : a timetable web manager