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 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
| <?php
// Au démarrage, aucune sélection : on extrait toutes les données individuellement pour chaque liste
// Tu as 4 listes : Raison sociale | ROS | Code postal | Produit
mysql_connect('localhost', 'root', '');
mysql_select_db('xls_db');
// raison sociale
$sql = 'SELECT DISTINCT client FROM histo ORDER BY client';
$qry = mysql_query($sql);
while($row = mysql_fetch_assoc($qry)) {
$dataClient[] = $row['client'];
}
// ROS
$sql = 'SELECT DISTINCT ros FROM histo ORDER BY ros';
$qry = mysql_query($sql);
while($row = mysql_fetch_assoc($qry)) {
$dataRos[] = $row['ros'];
}
// code postal
$sql = 'SELECT DISTINCT codepostal FROM histo ORDER BY codepostal';
$qry = mysql_query($sql);
while($row = mysql_fetch_assoc($qry)) {
$dataCp[] = $row['codepostal'];
}
// produit
$sql = 'SELECT DISTINCT id_produit FROM histo ORDER BY id_produit';
$qry = mysql_query($sql);
while($row = mysql_fetch_assoc($qry)) {
$dataProduit[] = $row['id_produit'];
}
// historique non filtré
// produit
$sql = 'SELECT * FROM histo';
$qry = mysql_query($sql);
while($row = mysql_fetch_assoc($qry)) {
$dataHisto[] = $row;
}
$hsc = function($p) { return htmlspecialchars($p, ENT_QUOTES); }
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<!-- Titre
************************************************************-->
<title>PROJET AFFECTATION ROS</title>
<!-- Feuille de style
************************************************************-->
<style type="text/css" media="screen">
@import url(styles/style.css);
</style>
<script type="application/javascript" charset="ISO-8859-1" src="jquery-1.6.3.min.js"></script>
<script type="application/javascript">
function filterLists() {
// ici on récupère les valeurs sélectionnées pour chaque liste avec les sélecteurs de jQuery
var client = $('#clients option:selected').val();
var ros = $('#ros option:selected').val();
var cp = $('#cps option:selected').val();
var produit = $('#produits option:selected').val();
// on fait notre appel ajax paramétré (pas besoin de s'occuper de l'implémentation du XMLHttpRequest, jQuery le fait pour toi)
$.ajax({
type: 'POST', // méthode de transmission des données
url: 'filterLists.php', // script à exécuter sur le serveur
data: 'client='+encodeURIComponent(client)+'&ros='+encodeURIComponent(ros)+'&cp='+encodeURIComponent(cp)+'&produit='+encodeURIComponent(produit), // données à passer au script via le tableau $_POST
dataType: 'xml', // type des données attendues en retour : ici xml
cache: false,
success: function(response) { // traitement du résultat (= données reçues du serveur) une fois l'appel ajax réussi
var code;
// vu que la réponse est au format xml, on demande à jquery de trouver des noeuds spécifiques
// et si ces noeuds contiennent des données alors on remplace les données des listes liées par celles renvoyées par le serveur
// en clair : on remplace si nécessaire l'ensemble des lignes <option value=""></option> pour chaque liste qui n'a pas encore de sélection
if ((code = $(response).find('clients').text()).length) $('#clients').html(code);
if ((code = $(response).find('ros').text()).length) $('#ros').html(code);
if ((code = $(response).find('cps').text()).length) $('#cps').html(code);
if ((code = $(response).find('produits').text()).length) $('#produits').html(code);
if ((code = $(response).find('table').text()).length) $('#table').html(code);
}
});
}
</script>
</head>
<body id="principal">
<?php
// ICI MODIFIEZ LE PARAMETRAGE
// Connexion à la base de données
$server = 'localhost';
$user = 'root';
$pwd = '';
$dbName = 'xls_db';
$cnx = mysql_connect($server, $user, $pwd);
$db = mysql_select_db($dbName);
// Au démarrage, aucune sélection : on extrait toutes les données individuellement pour chaque liste
// DONNES DE LA TABLE
$sql = <<<SQL
SELECT histo.id_produit, histo.type_produit, histo.ros, histo.client, histo.adresse, histo.ville, histo.codepostal
FROM histo
ORDER BY
histo.codepostal ASC,
histo.id_produit ASC,
histo.type_produit ASC,
histo.ros ASC,
histo.client ASC,
histo.adresse ASC,
histo.ville ASC
SQL;
$qry = mysql_query($sql);
while($row = mysql_fetch_assoc($qry)) {
$data[] = $row;
}
// pour chaque liste il faut prévoir leur retrait du filtre
// en insérant une ligne vide en début de liste : <option value=""></option>
?>
<!-- Conteneur
************************************************************-->
<div id="conteneur">
<!-- En-tete
************************************************************-->
<h1 id="header">
<a href="./" title="PROJET AFFECTATION ROS"><span>PROJET AFFECTATION ROS</span></a>
</h1>
<!-- Barre verticale
************************************************************-->
<div id="navigation">
<div id="styles">
<h2>Menu</h2>
<ul>
<li><a href="index.php">Historique Prod</a></li>
<li><a href="ajout.php">Nouvelle Prod</a></li>
<li><a href="#">Pré-études</a></li>
</ul>
</div>
<div id="informations">
<h2>Informations</h2>
<p>Mise à jour de la base 03 Fevrier 2011</p>
<p></p>
</div>
</div>
<!-- Contenu
************************************************************-->
<div id="contenu">
<div id="main">
<div id="projet">
<h2><span>Historique Production</span></h2>
<p></p>
</div>
<div id="base">
<h3><span>Base de Données</span></h3>
<p>Sélectionnez de un à plusieurs critères de recherche.</p><br>
<p>
<form id="frmRecherche">
<table>
<tbody id="table2">
<tr>
<!-- Liste des clients -->
<td>
<label for="clients">Clients</label>
</td>
<td>
<select id="clients" onchange="filterLists();">
<option value=""></option>
<?php foreach($dataClient as $client): ?>
<option value="<?php echo $hsc($client); ?>"><?php echo $hsc($client); ?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
<tr>
<!-- Liste des ROS-->
<td>
<label for="ros">ROS</label>
</td>
<td>
<select id="ros" onchange="filterLists();">
<option value=""></option>
<?php foreach($dataRos as $ros): ?>
<option value="<?php echo $hsc($ros); ?>"><?php echo $hsc($ros); ?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
<tr>
<!-- Liste des codes postaux-->
<td>
<label for="cp">Code Postal</label>
</td>
<td>
<select id="cp" onchange="filterLists();">
<option value=""></option>
<?php foreach($dataCp as $cp): ?>
<option value="<?php echo $hsc($cp); ?>"><?php echo $hsc($cp); ?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
<tr>
<!-- Liste des produits-->
<td>
<label for="produit">Produits</label>
</td>
<td>
<select id="produit" onchange="filterLists();">
<option value=""></option>
<?php foreach($dataProduit as $produit): ?>
<option value="<?php echo $hsc($produit); ?>"><?php echo $hsc($produit); ?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
</tbody>
</table>
</form>
</p>
<br>
<p>
<!-- Données de la table -->
<table>
<thead>
<tr>
<th>Produit</th>
<th>Type</th>
<th>Client</th>
<th>Adresse</th>
<th>CP</th>
<th>Ville</th>
<th>ROS</th>
</tr>
</thead>
<tbody id="table">
<?php foreach($dataHisto as $row): ?>
<tr id="table">
<td><?php echo $hsc($row['id_produit']); ?></td>
<td><?php echo $hsc($row['type_produit']); ?></td>
<td><?php echo $hsc($row['client']); ?></td>
<td><?php echo $hsc($row['adresse']); ?></td>
<td><?php echo $hsc($row['codepostal']); ?></td>
<td><?php echo $hsc($row['ville']); ?></td>
<td><?php echo $hsc($row['ros']); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</p>
</div>
<!-- Bloc pour mettre des informations sur le design
************************************************************-->
<div id="infostyle"><span></span></div>
<!-- /Contenu
************************************************************-->
</div>
</div>
<!-- Pied de page
************************************************************-->
<p id="footer"><span>
2011-2011, Steven Pawlak
<p class="flotte">
<img src="styles/logo_indexed.gif" alt="Orange !" />
</p>
</span></p>
<!-- /Conteneur
************************************************************-->
</div>
<!-- Blocs supplémentaires pour ajouter des images
************************************************************-->
<div id="imgbloc1"><span></span></div>
<div id="imgbloc2"><span></span></div>
<div id="imgbloc3"><span></span></div>
<div id="imgbloc4"><span></span></div>
<div id="imgbloc5"><span></span></div>
<!-- Balises de fermeture
************************************************************-->
</body>
</html> |
Partager