Location: PHPKode > projects > EmploiNet : a timetable web manager > EmploiNet/v0.8.0/Administration/Functions.php3
<?
$G_nb_colonnes = 0;
$G_nb_max=0;

function buildField($label,$type,$name,$value,$keyName,$request,$fields,$length,$newline)
{
    global $G_nb_colonnes;
    global $G_nb_max;

    if ($type != 4) print("          <td valign=top nowrap><font size=3><i>$label :</i></font></td>\n");
    else print("          <td valign=top>&nbsp;</td>\n");
    switch ($type)
	{
	case 1: print("          <td valign=top><input size=$length name=\"$name\" value=\"$value\"></td>\n");
	    break;
	case 2: print("          <td>\n");
	    $result = mysql_query($request);
	    $index_max = mysql_num_rows($result);
	    print("          <select multiple name=\"".$keyName."[]\" size=$length>\n");

	    $m = count($value);

	    for ($i=0;$i<$index_max;$i++)
		{
		    $a_record = mysql_fetch_array($result);

		    $found = false;
		    $j = 0;
		    while (!$found && $j<$m)
		        {		
			    if ($value[$j] == $a_record[0])
			        $found = true;
			    else
				$j++;
		        }
		    if ($found)
			print("          <option selected value=\"".$a_record[0]."\">");
		    else
			print("          <option value=\"".$a_record[0]."\">");
		    $n = count($fields);
		    for ($j=0;$j<$n;$j++)
			print($a_record[$fields[$j]]." ");
		    print("</option>\n");
		}
	    print("          </select>\n");
	    print("          </td>\n");
	    break;
	case 3: print("          <td><textarea name=\"$name\" cols=$length rows=3>$value</textarea></td>\n");
	    break;
	case 4: if ($value=="O") print("          <td><input type=checkbox value=\"O\" name=\"$name\" checked>");
	else print("          <td><input type=checkbox value=\"O\" name=\"$name\">");
	    print("&nbsp;<font size=3><i>$label</i></font></td>\n");
	    break;
	case 5: print("          <td>\n");
	    $result = mysql_query($request);
	    $index_max = mysql_num_rows($result); 
	    print("          <select name=\"".$keyName."\" size=$length>\n");
	    print("          <option value=\"-1\">&nbsp;</option>\n");
	    for ($i=0;$i<$index_max;$i++)
		{
		    $a_record = mysql_fetch_array($result);
		    $found = false;
		    if ($value == $a_record[$keyName])
			print("          <option selected value=\"".$a_record[$keyName]."\" >");
		    else
			print("          <option value=".$a_record[$keyName].">");
		    $n = count($fields);
		    for ($j=0;$j<$n;$j++)
			print($a_record[$fields[$j]]." ");
		    print("</option>\n");
		}
	    print("          </select>\n");
	    print("          </td>\n");
	    break;
	}
    $G_nb_colonnes+=2;
    if ($newline)
	{
	    if ($G_nb_colonnes < $G_nb_max)
		for ($i = $G_nb_colonnes; $i < $G_nb_max; $i++)
		    print("          <td valign=top>&nbsp;</td>\n");
	    $G_nb_colonnes = 0;
	    print("        </tr>\n");
	    print("        <tr>\n");
	}
}

function buildForm($fileName,$form,$id_session,$choix)   // $choix sert à choisir pour quelle catégorie
{						   // cette fonction est utilisée :
    global $login;		   //                    0 : promotion, groupe, gestionnaire, département, enseignant, salle, matière.
    global $index;		   //				     1 : étudiant
    global $G_nb_max;
    global $id_promotion;
    global $lettre;

    print("<script language=\"JavaScript\">\n");
    print("function open1(v)\n");
    print("{\n");
    print("  document.form1.choice.value = v;\n");
    print("  document.form1.submit();\n");
    print("}\n");
    print("</script>\n");
    print("<form name=\"form1\" action=\"$fileName\" method=post>\n");
    print("  <input type=\"hidden\" name=\"login\" value=\"$login\">\n");
    print("  <input type=\"hidden\" name=\"choice\" value=\"-1\">\n");
    print("  <input type=\"hidden\" name=\"index\" value=$index>\n");
    print("  <input type=\"hidden\" name=\"id_session\" value=\"$id_session\">\n");
    print("  <input type=\"hidden\" name=\"".($form["FieldName"][0])."\" value=\"".($form["Value"][0])."\">\n");
    
    print("  <table align=center border=0 cellspacing=0 cellpading=0 bordercolor=\"#C0C000\" bgcolor=\"#C0C000\">\n");

    if($choix==1){              ////seulement pour etudiant
	echo "<tr>\n";
	echo "<td align='center'>\n";
    
	$lettres=array(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z);
    
	for($i=0;$i<=25;$i++)
	    {
		$query="SELECT distinct(etudiant.id_etudiant),nom,prenom FROM etudiant,inscrit WHERE inscrit.id_promotion=$id_promotion AND etudiant.id_etudiant=inscrit.id_etudiant AND etudiant.nom LIKE '".$lettres[$i]."%' ORDER BY nom";
		$result=mysql_query($query);
		$nbEtudiants=mysql_num_rows($result);
		if($nbEtudiants!=0)
		    {
			echo "<a href='$filename?lettre=$lettres[$i]&id_session=$id_session&id_promotion=$id_promotion'>$lettres[$i]</a>&nbsp;&nbsp;&nbsp;&nbsp;";
		    }
		else
		    {
			echo "$lettres[$i]&nbsp;&nbsp;&nbsp;&nbsp;";
		    }
	    }
    
	echo "</td>\n";
	echo "</tr>\n";
	buildCustomFields();
	if(isset($lettre))
	    {
		echo "<tr>\n";
		echo "<td align='center'>\n";
		$query="SELECT distinct(etudiant.id_etudiant),nom,prenom FROM etudiant,inscrit WHERE inscrit.id_promotion=$id_promotion AND etudiant.id_etudiant=inscrit.id_etudiant AND etudiant.nom LIKE '".$lettre."%' ORDER BY nom";
		$result=mysql_query($query);
		$nbEtudiants=mysql_num_rows($result);
		echo "<select name='id_Etudiant' onChange='open1(8)'>\n";
		for($i=0;$i<$nbEtudiants;$i++)
		    {
			$etudiant=mysql_fetch_array($result);
			echo "<option value='$etudiant[0]'>$etudiant[1]&nbsp;$etudiant[2]</option>\n";
		    }
		echo "<option selected value=\"-1\" >&nbsp;&nbsp;&nbsp;&nbsp;-- CHOISIR $lettre --</option>\n";
		echo "</select>\n";
		echo "</td>\n";
		echo "</tr>\n";
	    }
    } 
    // Champs de saisie
    if(!isset($lettre)){
	print("  <tr>\n");
	print("    <td>\n");
	print("      <table align=center border=0 cellspacing=2 cellpading=0 bordercolor=\"#C0C000\" bgcolor=\"#C0C000\">\n");
	print("      <tr>\n");
	
	$n = count($form["Name"]);
	for ($i = 1;$i < $n;$i++)
	    buildField($form["Name"][$i],$form["Type"][$i],$form["FieldName"][$i],$form["Value"][$i],$form["KeyName"][$i],$form["Request"][$i],$form["Fields"][$i],$form["Length"][$i],$form["NewLine"][$i]);
	
	if($choix==0){
	    buildCustomFields();        //seulement pour promo et groupe
	}  
	print("      </tr>\n");
	print("      </table>\n");
	print("    </td>\n");
	print("  </tr>\n");

	//***********************************************************************************************
	    //* Boutons de navigation
	    //***********************************************************************************************

	    include("BoutonNavigation.php3");
	    if($choix==1){
		boutonNav(1);
	    }
	    else{
		boutonNav(0);
	    }

	    //***********************************************************************************************
			     //* Fin des boutons de navigation
			     //***********************************************************************************************
			     }
    print("  </table>\n");
    print("</form>\n");
    print("<br><br>\n");
  
}
function rechercheId($keyValue,$result,$keyName)
{
    $found = false;
    $index = 0;
    while (!$found && $a_record = mysql_fetch_array($result))
	if ($a_record[$keyName] != $keyValue)
	    $index++;
	else
	    $found = true;
    if ($found)
	return $index;	
    else
	return -1;
}
//******************************************************************
 
function getKeyValue($keyName)
{
    $result = mysql_query("SELECT * FROM id");
    $id = mysql_fetch_array($result);
    mysql_query("UPDATE id SET $keyName=".($id[$keyName]+1));
    return $id[$keyName]+1;
}

function nouveau($keyName)
{
    global $index;
    global $databaseName;
	
    $keyValue = newRecord();
    if ($keyValue != -1)
	{
	    openConnection($databaseName);
	    $result = selectRecords();
	    $index = rechercheId($keyValue,$result,$keyName);
	    remplir_formulaire($index,$result);
	}
}
	  
function modifier($keyValue,$keyName)
{
    global $index;
    global $index_max;

    if ($index_max >= 0)
	{
	    modifyRecord($keyValue,0);
	    $result = selectRecords();
	    $index = rechercheId($keyValue,$result,$keyName);
	    remplir_formulaire($index,$result);
	}
}
  
//*************Changement de promotion**********************  
function changementPromo($keyValue,$keyName)
{
    global $index;
    global $index_max;

    if ($index_max >= 0)
	{
	    modifyRecord($keyValue,1);
	    $result = selectRecords();

	    if ($index_max > 0)
		{
		    if ($index > 0) 
			$index--;
		    remplir_formulaire($index,$result);
		}
	    else
	  	$index = -1;
	}
}
  
//***********************************************************

function supprimer($keyValue,$keyName)
{
    global $index;
    global $index_max;

    if ($index_max >= 0)
	{
	    deleteRecord($keyValue);
	    openConnection($databaseName);
	    $result = selectRecords();
	    if (($index_max >= 0) && ($index > 0)) {
		$index--;
		remplir_formulaire($index,$result);
	    }
	}
    else
	$index = -1;
}
?>
Return current item: EmploiNet : a timetable web manager