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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
| <?php
include 'config.php';
// SOUMISSION DU FORMULAIRE POUR MISE A JOUR
if ($_GET['action'] === 'confirm') {
$set = array();
/**
* Fragment sql de mise à jour d'un champ
* @param string $post_key Valeur de la clé du tableau $_POST
* @param bool $is_int entier attendu, si faux => string
* @param bool $empty_allowed Indique si la valeur (null|'') est autorisée
* @param string field Nom du champ de la table, si null => égal à $post_key
*/
$setField =
function($post_key, $is_int = false, $empty_allowed = false, $field = null) use (&$set)
{
if (array_key_exists($key, $_POST)) {
$value = $_POST[$key];
if (strlen($value) === 0) {
if ($empty_allowed) {
$set[] = $field.' = NULL';
}
}
else
if ($is_int) {
if (ctype_digit("$value")) {
$set[] = $field.' = '.$value;
}
}
else {
$set[] = $field.' = '.mysql_real_escape_string($value);
}
}
};
// champs à mettre à jour
$setField('n_federation', true);
$setField('n_lang', true);
$setField('name');
$setField('fname');
$setField('company');
$setField('n_category', true);
$setField('sector');
$setField('address');
$setField('city');
$setField('cp');
$setField('n_country', true);
$setField('mobile');
$setField('phone');
$setField('fax');
$setField('email');
$setField('website');
if ( ! empty($set) && ctype_digit($_POST['id'])) {
$sql = 'UPDATE u_member SET '.implode(', ', $set).' WHERE id = '.$_POST['id'];
echo (mysql_query($sql))
? 'Félicitations, la fiche du produit a bien été modifée<br>'
: 'Erreur, veuillez recommencer !';
}
// on s'arrête une fois la mise à jour effectuée
exit;
}
// PAS DE SOUMISSION -> AFFICHAGE SIMPLE DES DONNEES
if (isset($_GET['id']) && ctype_digit($_GET['id'])) {
$id_membre = $_GET['id'];
}
else {
echo 'Identifiant du membre erroné';
exit;
}
$sql = "SELECT * FROM u_member WHERE id = $id_membre";
$qry = mysql_query($sql) or die('Err : '.mysql_error());
$membre = mysql_fetch_assoc($qry);
$sql = 'SELECT id, n_federation FROM u_federation';
$federations = mysql_query($sql) or die('Err : '.mysql_error());
$sql = 'SELECT id, n_lang FROM u_lang';
$langues = mysql_query($sql) or die('Err : '.mysql_error());
$sql = 'SELECT id, n_category FROM u_category';
$categories = mysql_query($sql) or die('Err : '.mysql_error());
$sql = 'SELECT id, n_country FROM u_country';
$pays = mysql_query($sql) or die('Err : '.mysql_error());
// item de liste sélectionné
$selected = function($current, $target) { return ($current == $target) ? ' selected="selected"' : null; };
// sécurisation de l'affichage
$hes = function($p) { return htmlentities($p, ENT_QUOTES); };
?>
<script language="JavaScript">
<!--
/***********************************************
* Required field(s) validation v1.10- By NavSurf
* Visit Nav Surf at http://navsurf.com
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
function formCheck(formobj){
// Enter name of mandatory fields
var fieldRequired = Array("name_prod", "name_cat", "ref", "prix", "descp");
// Enter field description to appear in the dialog box
var fieldDescription = Array("Nom du Produit", "Catégorie", "Référence", "Prix", "Description");
// dialog message
var alertMsg = "Please complete the following fields:\n";
var l_Msg = alertMsg.length;
for (var i = 0; i < fieldRequired.length; i++){
var obj = formobj.elements[fieldRequired[i]];
if (obj){
switch(obj.type){
case "select-one":
if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "select-multiple":
if (obj.selectedIndex == -1){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "text":
case "textarea":
case "file":
if (obj.value == "" || obj.value == null){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
default:
}
if (obj.type == undefined){
var blnchecked = false;
for (var j = 0; j < obj.length; j++){
if (obj[j].checked){
blnchecked = true;
}
}
if (!blnchecked){
alertMsg += " - " + fieldDescription[i] + "\n";
}
}
}
}
if (alertMsg.length == l_Msg){
return true;
}else{
alert(alertMsg);
return false;
}
}
// -->
</script>
<form action="?action=confirm" method="post" onsubmit="return formCheck(this);" enctype="multipart/form-data">
<input type="hidden" name="id" value="<?php echo $id_membre; ?>">
<table width="546">
<tr><td>Federation : </td>
<td>
<select name="n_federation">
<?php while($row = mysql_fetch_assoc($federations)): ?>
<option value="<?php echo $row['id']; ?>"<?php echo $selected($row['id'], $membre['n_federation']); ?>><?php echo $hes($row['n_federation']); ?></option>
<?php endwhile; ?>
</select>
</td>
</tr>
<tr>
<td>Lang : </td>
<td>
<select name="n_lang">
<?php while($row = mysql_fetch_assoc($langues)): ?>
<option value="<?php echo $row['id']; ?>"<?php echo $selected($row['id'], $membre['n_lang']); ?>><?php echo $hes($row['n_lang']); ?></option>
<?php endwhile; ?>
</select>
</td>
</tr>
<tr><td>Name : </td><td><input type="text" name="name" value="<?php echo $hes($membre['name']); ?>"></td></tr>
<tr><td>First Name : </td><td><input type="text" name="fname" value="<?php echo $hes($membre['fname']); ?>"></td></tr>
<tr><td>Company : </td><td><input type="text" name="company" value="<?php echo $hes($membre['company']);; ?>"></td></tr>
<tr>
<td>Category : </td>
<td>
<select name="n_category">
<?php while($row = mysql_fetch_assoc($categories)): ?>
<option value="<?php echo $row['id']; ?>"<?php echo $selected($row['id'], $membre['n_category']); ?>><?php echo $hes($row['n_category']); ?></option>
<?php endwhile; ?>
</select>
</td>
</tr>
<tr><td>Sector : </td><td><input type="text" name="sector" value="<?php echo $hes($membre['sector']); ?>"></td></tr>
<tr><td>Address : </td><td><input type="text" name="address" value="<?php echo $hes($membre['address']); ?>"></td></tr>
<tr><td>City : </td><td><input type="text" name="city" value="<?php echo $hes($membre['city']); ?>"></td></tr>
<tr><td>CP : </td><td><input type="text" name="cp" value="<?php echo $hes($membre['cp']); ?>"></td></tr>
<tr>
<td>Country : </td>
<td>
<select name="n_country">
<?php while($row = mysql_fetch_assoc($pays)): ?>
<option value="<?php echo $row['id']; ?>"<?php echo $selected($row['id'], $membre['n_country']); ?>><?php echo $hes($row['n_country']); ?></option>
<?php endwhile; ?>
</select>
</td>
</tr>
<tr><td>Mobile : </td><td><input type="text" name="mobile" value="<?php echo $hes($membre['mobile']); ?>"></td></tr>
<tr><td>Phone : </td><td><input type="text" name="phone" value="<?php echo $hes($membre['phone']); ?>"></td></tr>
<tr><td>Fax : </td><td><input type="text" name="fax" value="<?php echo $hes($membre['fax']); ?>"></td></tr>
<tr><td>Email : </td><td><input type="text" name="email" value="<?php echo $hes($membre['email']); ?>"></td></tr>
<tr><td>Website : </td><td><input type="text" name="website" value="<?php echo $hes($membre['website']); ?>"></td></tr>
<tr><td><input type="submit" name="submit" value="Envoyer"></td></tr>
</table>
</form>
<font color="red"> * = Champs falcutatifs</font> |