1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| //Formulaire ajout : Objet connexion base de données, objet déclarartion de variable, id de la table, $type d'utilisateur (facultatif), données de la table
function Ajout($mysql, $variable, $n, $type='null', $value=''){
//Libellé de la table concernée
$lib_n=$variable->table[$n];
$formulaire="";
//Pour chaque champs de la bdd
foreach ($variable->lib_champs[$lib_n] as $lib){
//Value activée ou désactivée en fonction des paramètres : $value[$variable->champs[nom_table][libellé_champs]]
$valeur='';
if (isset($value[$variable->champs[$lib_n][$lib]]))
$valeur=$value[$variable->champs[$lib_n][$lib]];
//Afficher en caché le champs de l'identifiant
if (ereg("Identifiant", $lib))
$formulaire.='<input type="hidden" name="'.$variable->champs[$lib_n][$lib].'" value="'.$valeur.'">';
//Construire les combos si c'est une clée étrangère
elseif (ereg("Clé_", $lib)){
$lib_type=$lib;
//Supression du paramètre type_
if (ereg($type, $lib))
$lib_type=ereg_replace($type."_", "", $lib_type);
//Suppression du paramètre clé_
$lib_type=ereg_replace("Clé_", "", $lib_type);
//Construction de la combo en fonction du résultat
if (!ereg('_', $lib_type)){
//Construction de la requete combo selon la table personne ou autre
if (ereg('Personne', $lib_type))
$select=" select ".$variable->champs[$lib_type]['Login Utilisateur'].", ".$variable->champs[$lib_type]['Nom'];
else
$select=" select ".$variable->champs[$lib_type]['Identifiant'].", ".$variable->champs[$lib_type]['Libellé'];
$from= " from ".$lib_type;
$formulaire.='<tr><td>'.$lib_type.': </td><td>'.ComboTable($mysql, $variable, $select, $from, $variable->champs[$lib_n][$lib], $valeur).'</td></tr>';
}
}
//Afficher en caché le champs ayant pour intituté caché
elseif (ereg("Cacher_Type", $lib) )
$formulaire.='<input type="hidden" name="'.$variable->champs[$lib_n][$lib].'" value="'.$type.'">';
elseif (ereg("Cacher", $lib) )
$formulaire.='<input type="hidden" name="'.$variable->champs[$lib_n][$lib].'" value="'.$valeur.'">';
//Initialisation basique
else
$formulaire.='<tr><td>'.$lib.': </td><td><input type="text" name="'.$variable->champs[$lib_n][$lib].'" value="'.$valeur.'"></td></tr>';
}
$formulaire.='<input type="hidden" name="n" value="'.$n.'">';
return($formulaire);
} |
Partager