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 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
|
<?php
echo("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n");
/* Variables de connexion : ajustez ces paramètres selon votre propre environnement */
$serveur = "localhost";
$admin = "root";
$mdp = "";
$base = "movedb";
/* On récupère si elle existe la valeur de la région envoyée par le formulaire */
$id_type = isset($_POST['type'])?$_POST['type']:null;
$id_block = isset($_POST['block'])?$_POST['block']:null;
$id_ref = isset($_POST['ref'])?$_POST['ref']:null;
$id_name = isset($_POST['name'])?$_POST['name']:null;
$id_descr = isset($_POST['descr'])?$_POST['descr']:null;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<link href="styles.css" rel="stylesheet" type="text/css"><title>Commande d achat</title>
</head>
<body class="tableaux">
<?php
if(isset($_POST['ok']) && isset($_POST['block']) && $_POST['block'] != ""
&& isset($_POST['ref']) && $_POST['ref'] != ""
&& isset($_POST['name']) && $_POST['name'] != ""
&& isset($_POST['descr']) && $_POST['descr'] != "")
{
$type_selectionne = $_POST['type'];
$block_selectionne = $_POST['block'];
$ref_selectionne = $_POST['ref'];
$name_selectionne = $_POST['name'];
$descr_selectionne = $_POST['descr'];
}
?>
<?php
/* On établit la connexion à MySQL avec mysql_pconnect() plutôt qu'avec mysql_connect()
* car on aura besoin de la connexion un peu plus loin dans le script */
$connexion = mysql_connect($serveur, $admin, $mdp)
or die("Impossible de se connecter : " . mysql_error());
$choixbase = mysql_select_db($base);
$sql1 = "SELECT type".
" FROM table_item".
" GROUP BY type";
$rech_types = mysql_query($sql1);
if($rech_types != false)
{
$type = array();
/* On active un compteur pour les types */
$nb_types = 0;
while($ligne = mysql_fetch_assoc($rech_types))
{
array_push($type, $ligne["type"]);
/* On incrémente de compteur */
$nb_types++;
}
}
?>
<form action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post" id="chgblock">
<legend>Sélectionnez un type</legend>
<select name="type" id="type" onchange="document.forms['chgblock'].submit();">
<option value="-1">- - - Choisissez un type - - -</option>
<?php
for($i = 0; $i < $nb_types; $i++)
{
?>
<option value="<?php echo($type[$i]); ?>"<?php echo((isset($id_type) && $id_type == $type[$i])?" selected=\"selected\"":null); ?>><?php echo($type[$i]); ?></option>
<?php
}
?>
</select>
<p>
<?php
mysql_free_result($rech_types);
mysql_close($connexion);
/* On commence par vérifier si on a envoyé un numéro de type et le cas échéant s'il est différent de -1 */
if(isset($id_type) && $id_type != -1)
{
/* Création de la requête pour avoir les blocks de ce type */
$sql2 = "SELECT block".
" FROM table_item".
" WHERE type = '". $id_type ."'".
" GROUP BY block;";
$connexion = mysql_connect($serveur, $admin, $mdp)
or die("Impossible de se connecter : " . mysql_error());
$choixbase = mysql_select_db($base);
$rech_blocks = mysql_query($sql2);
/* Un petit compteur pour les blocks */
$nb_blocks = 0;
/* On crée deux tableaux pour les numéros et les noms des départements */
$block = array();
/* On va mettre les numéros et noms des départements dans les deux tableaux */
while($ligne = mysql_fetch_assoc($rech_blocks))
{
array_push($block, $ligne["block"]);
$nb_blocks++;
}
/* Maintenant on peut construire la liste déroulante */
?>
<select name="block" id="block" onchange="document.forms['chgblock'].submit();">
<option value="-1">- - - Choisissez un block - - -</option>
<?php
for($j = 0; $j<$nb_blocks; $j++)
{
?>
<option value="<?php echo($block[$j]); ?>"<?php echo((isset($id_block) && $id_block == $block[$j])?" selected=\"selected\"":null); ?>><?php echo($block[$j]); ?></option>
<?php
}
}
?>
</select>
<p>
<?php
if((isset($id_block) && $id_block != -1) && (isset($id_type) && $id_type != -1))
{
$sql3 = "SELECT ref".
" FROM table_item".
" WHERE block = '". $id_block ."' AND type = '". $id_type ."'".
" ORDER BY ref;";
$connexion = mysql_connect($serveur, $admin, $mdp) or die("Impossible de se connecter : " . mysql_error());
$choixbase = mysql_select_db($base);
$rech_refs = mysql_query($sql3);
$nb_refs = 0;
$ref = array();
while($ligne = mysql_fetch_assoc($rech_refs))
{
array_push($ref, $ligne["ref"]);
$nb_refs++;
}
?>
<select name="ref" id="ref" onchange="document.forms['chgblock'].submit();">
<option value="-1">- - - Choisissez une ref - - -</option>
<?php
for($k = 0; $k<$nb_refs; $k++)
{
?>
<option value="<?php echo($ref[$k]); ?>"<?php echo((isset($id_ref) && $id_ref == $ref[$k])?" selected=\"selected\"":null); ?>><?php echo($ref[$k]); ?></option>
<?php
}}
?>
</select>
<p>
<?php
if((isset($id_block) && $id_block != -1) && (isset($id_type) && $id_type != -1)&& (isset($id_ref) && $id_ref != -1))
{
$sql4 = "SELECT name".
" FROM table_item".
" WHERE block = '". $id_block ."' AND type = '". $id_type ."'AND ref = '". $id_ref ."'".
" ORDER BY name;";
$connexion = mysql_connect($serveur, $admin, $mdp) or die("Impossible de se connecter : " . mysql_error());
$choixbase = mysql_select_db($base);
$rech_names = mysql_query($sql4);
$nb_names = 0;
$name = array();
while($ligne = mysql_fetch_assoc($rech_names))
{
array_push($name, $ligne["name"]);
$nb_names++;
}
?>
<textarea name="name" id="name">
<?php
for($l = 0; $l<$nb_names; $l++)
{
echo $name[$l];
echo isset($id_name) && $id_name == $name[$l];
}}
?>
</textarea>
<p>
<?php
if((isset($id_block) && $id_block != -1) && (isset($id_type) && $id_type != -1)&& (isset($id_ref) && $id_ref != -1))
{
$sql5 = "SELECT descr".
" FROM table_item".
" WHERE block = '". $id_block ."' AND type = '". $id_type ."'AND ref = '". $id_ref ."'".
" ORDER BY descr;";
$connexion = mysql_connect($serveur, $admin, $mdp) or die("Impossible de se connecter : " . mysql_error());
$choixbase = mysql_select_db($base);
$rech_descrs = mysql_query($sql5);
$nb_descrs = 0;
$descr = array();
while($ligne = mysql_fetch_assoc($rech_descrs))
{
array_push($descr, $ligne["descr"]);
$nb_descrs++;
}
?>
<textarea name="descr" id="descr">
<?php
for($m = 0; $m<$nb_descrs; $m++)
{
echo $descr[$m];
echo (isset($id_descr) && $id_descr == $descr[$m]);
}
?>
</textarea>
<?php
mysql_free_result($rech_descrs);
?>
<input type="submit" name="ok" id="ok" value="Envoyer" >
<a href="add_det_order2.php?id_cmde=26&ref=<?php echo $id_ref ; ?>&block=<?php echo $id_block ; ?>
&type=<?php echo $id_type ; ?>
&descr=<?php echo $descr ; ?>&name=<?php
for($l = 0; $l<$nb_names; $l++)
{
echo $name[$l];
echo isset($id_name) && $id_name == $name[$l];
}}
?>">Valider</a>
</form>
<?php
mysql_close($connexion);
?>
</body>
</html> |
Partager