/gespac/gestion_inventaire/form_marques.php

http://gespac.googlecode.com/ · PHP · 592 lines · 469 code · 79 blank · 44 comment · 5 complexity · 9c06c41d9cc77cf22a7e48e96f647398 MD5 · raw file

  1. <?PHP
  2. #formulaire d'ajout et de modification
  3. #des marques
  4. // lib
  5. require_once ('../fonctions.php');
  6. include_once ('../config/databases.php');
  7. include_once ('../../class/Log.class.php');
  8. include_once ('../../class/Sql.class.php');
  9. $id = $_GET['id'];
  10. // cnx ŕ la base de données GESPAC
  11. $con_gespac = new Sql ($host, $user, $pass, $gespac);
  12. // *********************************************************************************
  13. //
  14. // Formulaire vierge de création
  15. //
  16. // *********************************************************************************
  17. if ( $id == '-1' ) {
  18. echo "<h2>Formulaire de création d'une marque</h2><br>";
  19. ?>
  20. <script>
  21. // Donne le focus au premier champ du formulaire
  22. $('filt').focus();
  23. </script>
  24. <!--
  25. GESTION PAR CORRESPONDANCE DE L'INSERTION D'UNE MARQUE
  26. -->
  27. <div id='creer_modele_par_corr'>
  28. <form>
  29. <center>
  30. <p>Choisir un modčle : <input name="filt" id="filt" onKeyPress="return disableEnterKey(event)" onkeyup="filter(this, 'corr_table');" type="text"></p>
  31. <?PHP
  32. // ici il faut récupérer les lignes DISTINCTES histoire de ne pas surcharger le tableau
  33. $liste_correspondances = $con_gespac->QueryAll ( "SELECT corr_id, corr_marque_ocs, corr_type, corr_stype, corr_marque, corr_modele FROM correspondances GROUP BY corr_modele ORDER BY corr_modele" );
  34. ?>
  35. <table id="corr_table">
  36. <?PHP
  37. foreach ( $liste_correspondances as $corr ) {
  38. $corr_id = $corr['corr_id'];
  39. $corr_marque_ocs = $corr['corr_marque_ocs'];
  40. $corr_type = $corr['corr_type'];
  41. $corr_stype = $corr['corr_stype'];
  42. $corr_marque = $corr['corr_marque'];
  43. $corr_modele = $corr['corr_modele'];
  44. echo "<tr style='display:none' class='tr_filter'>";
  45. echo "<td width=200>&nbsp $corr_type</td>";
  46. echo "<td width=200>&nbsp $corr_stype</td>";
  47. echo "<td width=200>&nbsp $corr_marque</td>";
  48. echo "<td width=200>&nbsp $corr_modele</td>";
  49. echo "<td><a href='#' onclick=\"validation_ajout_marque($corr_id, '$corr_marque $corr_modele');\"><img src='img/add.png'> </a></td>";
  50. echo "</tr>";
  51. }
  52. ?>
  53. </table>
  54. <br>
  55. <span id='creer_modele' style='display:none;'><a href='#' onclick="affiche_creer_modele();">Créer un nouveau modčle</a></span>
  56. </center>
  57. </FORM>
  58. </div>
  59. <!--
  60. GESTION MANUELLE DE L'INSERTION D'UNE MARQUE
  61. -->
  62. <div id='creer_nouveau_modele' style='display:none'>
  63. <form action="gestion_inventaire/post_marques.php?action=add" method="post" name="post_form" id="post_form">
  64. <center>
  65. <table width=500>
  66. <tr>
  67. <TD>Famille</TD>
  68. <TD>
  69. <div id="combo_type">
  70. <div id="listbox_type" style='display:inline;'>
  71. <select name=select_type id=select_type>
  72. <option value=''> >>> Selectionnez une valeur <<< </option>
  73. <?PHP
  74. $liste_des_types = $con_gespac->queryAll ( "SELECT DISTINCT marque_type FROM marques ORDER BY marque_type" );
  75. foreach ( $liste_des_types as $record ) { // on remplit la liste des types
  76. $type = $record['marque_type'];
  77. echo "<option value='$type'>$type</option>";
  78. }
  79. ?>
  80. </select>
  81. </div>
  82. <div id="textbox_type" style='display:none;'><input name=text_type id=text_type type="text"></div>
  83. <td><a href="#" onclick="change_combo('listbox_type', 'textbox_type', 'select_type', 'text_type');"> <img src='./img/add.png'> </a> </td>
  84. </div>
  85. </TD>
  86. </tr>
  87. <tr>
  88. <TD>Sous-famille</TD>
  89. <TD>
  90. <div id="combo_stype">
  91. <div id="listbox_stype" style='display:inline;'>
  92. <select name=select_stype id=select_stype>
  93. <option value=''> >>> Selectionnez une valeur <<< </option>
  94. <?PHP
  95. $liste_des_stypes = $con_gespac->queryAll ( "SELECT DISTINCT marque_stype FROM marques ORDER BY marque_stype" );
  96. foreach ( $liste_des_stypes as $record ) { // on remplit la liste des types
  97. $stype = $record['marque_stype'];
  98. echo "<option value='$stype'>$stype</option>";
  99. }
  100. ?>
  101. </select>
  102. </div>
  103. <div id="textbox_stype" style='display:none;'><input name=text_stype id=text_stype type="text"></div>
  104. <td><a href="#" onclick="change_combo('listbox_stype', 'textbox_stype', 'select_stype', 'text_stype');"> <img src='./img/add.png'> </a> </td>
  105. </div>
  106. </TD>
  107. </tr>
  108. <tr>
  109. <TD>Marque</TD>
  110. <TD>
  111. <div id="combo_marque">
  112. <div id="listbox_marque" style='display:inline;'>
  113. <select name=select_marque id=select_marque>
  114. <option value=''> >>> Selectionnez une valeur <<< </option>
  115. <?PHP
  116. $liste_des_marques = $con_gespac->queryAll ( "SELECT DISTINCT marque_marque FROM marques ORDER BY marque_marque" );
  117. foreach ( $liste_des_marques as $record ) { // on remplit la liste des types
  118. $marque = $record['marque_marque'];
  119. echo "<option value='$marque'>$marque</option>";
  120. }
  121. ?>
  122. </select>
  123. </div>
  124. <div id="textbox_marque" style='display:none;'><input name=text_marque id=text_marque type="text"></div>
  125. <td><a href="#" onclick="change_combo('listbox_marque', 'textbox_marque', 'select_marque', 'text_marque');"> <img src='./img/add.png'> </a> </td>
  126. </div>
  127. </TD>
  128. </tr>
  129. <tr>
  130. <TD>Modčle</TD>
  131. <TD>
  132. <div id="combo_modele">
  133. <div id="listbox_modele" style='display:inline;'>
  134. <select name=select_modele id=select_modele>
  135. <option value=''> >>> Selectionnez une valeur <<< </option>
  136. <?PHP
  137. $liste_des_modeles = $con_gespac->queryAll ( "SELECT DISTINCT marque_model FROM marques ORDER BY marque_model" );
  138. foreach ( $liste_des_modeles as $record ) { // on remplit la liste des types
  139. $modele = $record['marque_model'];
  140. echo "<option value='$modele'>$modele</option>";
  141. }
  142. ?>
  143. </select>
  144. </div>
  145. <div id="textbox_modele" style='display:none;'><input name=text_modele id=text_modele type="text"></div>
  146. <td><a href="#" onclick="change_combo('listbox_modele', 'textbox_modele', 'select_modele', 'text_modele');"> <img src='./img/add.png'> </a> </td>
  147. </div>
  148. </TD>
  149. </tr>
  150. </table>
  151. <br>
  152. <input type=submit value='Ajouter une marque'>
  153. <br><br>
  154. <a href='#' onclick="affiche_liste_modele();">Liste des modčles</a>
  155. </center>
  156. </FORM>
  157. <div>
  158. <?PHP
  159. }
  160. // *********************************************************************************
  161. //
  162. // formulaire de modification prérempli
  163. //
  164. // *********************************************************************************
  165. else {
  166. echo "<h2>Formulaire de modification d'une marque</h2><br>";
  167. // Requete pour récupérer les données des champs pour la marque ŕ modifier
  168. // stockage des lignes retournées par sql dans un tableau nommé avec originalité "array" (mais "tableau" peut aussi marcher)
  169. $marque_a_modifier = $con_gespac->queryRow ( "SELECT marque_id, marque_type, marque_stype, marque_marque, marque_model FROM marques WHERE marque_id=$id" );
  170. // valeur ŕ affecter aux champs
  171. $marque_id = $marque_a_modifier[0];
  172. $marque_type = $marque_a_modifier[1];
  173. $marque_stype = $marque_a_modifier[2];
  174. $marque_marque = $marque_a_modifier[3];
  175. $marque_modele = $marque_a_modifier[4];
  176. ?>
  177. <script>
  178. // Donne le focus au premier champ du formulaire
  179. $('select_type').focus();
  180. </script>
  181. <!--
  182. GESTION PAR CORRESPONDANCE DE LA MODIFICATION D'UNE MARQUE
  183. -->
  184. <DIV id='modif_modele_par_corr' >
  185. <form>
  186. <center>
  187. <p>Choisir un modčle : <input name="filt" id="filt" onKeyPress="return disableEnterKey(event)" onkeyup="filter(this, 'corr_table');" type="text"></p>
  188. <?PHP
  189. // ici il faut récupérer les lignes DISTINCTES histoire de ne pas surcharger le tableau
  190. $liste_correspondances = $con_gespac->queryAll ( "SELECT corr_id, corr_marque_ocs, corr_type, corr_stype, corr_marque, corr_modele FROM correspondances GROUP BY corr_modele ORDER BY corr_modele" );
  191. ?>
  192. <table id="corr_table">
  193. <?PHP
  194. foreach ( $liste_correspondances as $corr ) {
  195. $corr_id = $corr['corr_id'];
  196. $corr_marque_ocs = $corr['corr_marque_ocs'];
  197. $corr_type = $corr['corr_type'];
  198. $corr_stype = $corr['corr_stype'];
  199. $corr_marque = $corr['corr_marque'];
  200. $corr_modele = $corr['corr_modele'];
  201. echo "<tr style='display:none' class='tr_filter'>";
  202. echo "<td width=200>$corr_type</td>";
  203. echo "<td width=200>$corr_stype</td>";
  204. echo "<td width=200>$corr_marque</td>";
  205. echo "<td width=200>$corr_modele</td>";
  206. echo "<td><a href='#' onclick=\"validation_modif_marque($corr_id, '$corr_marque $corr_modele', '$marque_marque $marque_modele', $marque_id);\"><img src='img/write.png'> </a></td>";
  207. echo "</tr>";
  208. }
  209. ?>
  210. </table>
  211. <br>
  212. <span id='modif_modele' style='display:none;'><a href='#' onclick="affiche_modif_modele();">Modification manuelle du modčle</a></span>
  213. </center>
  214. </FORM>
  215. </DIV>
  216. <!--
  217. GESTION MANUELLE DE LA MODIFICATION D'UNE MARQUE
  218. -->
  219. <DIV id='modif_manuelle_modele' style='display:none'>
  220. <form action="gestion_inventaire/post_marques.php?action=mod" method="post" name="post_form" id="post_form">
  221. <input type=hidden name=marqueid value=<?PHP echo $id;?> >
  222. <center>
  223. <table width=500>
  224. <tr>
  225. <TD>Famille</TD>
  226. <TD>
  227. <div id="combo_type">
  228. <div id="listbox_type" style='display:inline;'>
  229. <select name=select_type id=select_type>
  230. <?PHP
  231. $liste_des_types = $con_gespac->queryAll ( "SELECT DISTINCT marque_type FROM marques" );
  232. foreach ( $liste_des_types as $record ) { // on remplit la liste des types
  233. $type = $record['marque_type'];
  234. $selected = $marque_type == $type ? "selected" : "";
  235. echo "<option $selected value='$type'>$type</option>";
  236. }
  237. ?>
  238. </select>
  239. </div>
  240. <div id="textbox_type" style='display:none;'><input name=text_type id=text_type type="text"></div>
  241. <td><a href="#" onclick="change_combo('listbox_type', 'textbox_type', 'select_type', 'text_type');"> <img src='./img/add.png'> </a> </td>
  242. </div>
  243. </TD>
  244. </tr>
  245. <tr>
  246. <TD>Sous-famille</TD>
  247. <TD>
  248. <div id="combo_stype">
  249. <div id="listbox_stype" style='display:inline;'>
  250. <select name=select_stype id=select_stype>
  251. <?PHP
  252. $liste_des_stypes = $con_gespac->queryAll ( "SELECT DISTINCT marque_stype FROM marques" );
  253. foreach ( $liste_des_stypes as $record ) { // on remplit la liste des types
  254. $stype = $record['marque_stype'];
  255. $selected = $marque_stype == $stype ? "selected" : "";
  256. echo "<option $selected value='$stype'>$stype</option>";
  257. }
  258. ?>
  259. </select>
  260. </div>
  261. <div id="textbox_stype" style='display:none;'><input name=text_stype id=text_stype type="text"></div>
  262. <td><a href="#" onclick="change_combo('listbox_stype', 'textbox_stype', 'select_stype', 'text_stype');"> <img src='./img/add.png'> </a> </td>
  263. </div>
  264. </TD>
  265. </tr>
  266. <tr>
  267. <TD>Marque</TD>
  268. <TD>
  269. <div id="combo_marque">
  270. <div id="listbox_marque" style='display:inline;'>
  271. <select name=select_marque id=select_marque>
  272. <?PHP
  273. $liste_des_marques = $con_gespac->queryAll ( "SELECT DISTINCT marque_marque FROM marques" );
  274. foreach ( $liste_des_marques as $record ) { // on remplit la liste des types
  275. $marque = $record['marque_marque'];
  276. $selected = $marque_marque == $marque ? "selected" : "";
  277. echo "<option $selected value='$marque'>$marque</option>";
  278. }
  279. ?>
  280. </select>
  281. </div>
  282. <div id="textbox_marque" style='display:none;'><input name=text_marque id=text_marque type="text"></div>
  283. <td><a href="#" onclick="change_combo('listbox_marque', 'textbox_marque', 'select_marque', 'text_marque');"> <img src='./img/add.png'> </a> </td>
  284. </div>
  285. </TD>
  286. </tr>
  287. <tr>
  288. <TD>Modčle</TD>
  289. <TD>
  290. <div id="combo_modele">
  291. <div id="listbox_modele" style='display:inline;'>
  292. <select name=select_modele id=select_modele>
  293. <?PHP
  294. $liste_des_modeles = $con_gespac->queryAll ( "SELECT DISTINCT marque_model FROM marques" );
  295. foreach ( $liste_des_modeles as $record ) { // on remplit la liste des types
  296. $modele = $record['marque_model'];
  297. $selected = $marque_modele == $modele ? "selected" : "";
  298. echo "<option $selected value='$modele'>$modele</option>";
  299. }
  300. ?>
  301. </select>
  302. </div>
  303. <div id="textbox_modele" style='display:none;'><input name=text_modele id=text_modele type="text"></div>
  304. <td><a href="#" onclick="change_combo('listbox_modele', 'textbox_modele', 'select_modele', 'text_modele');"> <img src='./img/add.png'> </a> </td>
  305. </div>
  306. </TD>
  307. </tr>
  308. </table>
  309. <br>
  310. <input type=submit value='Modifier cette marque' >
  311. </center>
  312. </FORM>
  313. <DIV>
  314. <?PHP
  315. }
  316. ?>
  317. <script type="text/javascript">
  318. // masque le combo pour afficher le input et vis-versa
  319. function change_combo(select_tr_id, input_tr_id, select_id, input_id) {
  320. var inputbox = document.getElementById (input_tr_id);
  321. var list = document.getElementById (select_tr_id);
  322. var inputvalue = document.getElementById (input_id);
  323. var selectvalue = document.getElementById (select_id);
  324. if (inputbox.style.display == "inline") {
  325. inputvalue.value = "";
  326. inputbox.style.display = 'none';
  327. list.style.display = 'inline';
  328. } else {
  329. selectvalue.value = '';
  330. inputbox.style.display = 'inline';
  331. list.style.display = 'none';
  332. }
  333. }
  334. // *********************************************************************************
  335. //
  336. // Fonction de filtrage des tables
  337. //
  338. // *********************************************************************************
  339. function filter (phrase, _id){
  340. var words = phrase.value.toLowerCase().split(" ");
  341. var table = document.getElementById(_id);
  342. var ele;
  343. var compte = 0;
  344. if (phrase.value == "") { // Si la phrase est nulle, on masque toutes les lignes
  345. for (var r = 1; r < table.rows.length; r++) table.rows[r].style.display = "none";
  346. }
  347. else {
  348. for (var r = 1; r < table.rows.length; r++){
  349. ele = table.rows[r].innerHTML.replace(/<[^>]+>/g,"");
  350. var displayStyle = 'none';
  351. for (var i = 0; i < words.length; i++) {
  352. if (ele.toLowerCase().indexOf(words[i])>=0) { // la phrase de recherche est reconnue
  353. displayStyle = '';
  354. compte++;
  355. }
  356. else { // on masque les rows qui ne correspondent pas
  357. displayStyle = 'none';
  358. break;
  359. }
  360. }
  361. // Affichage on / off en fonction de displayStyle
  362. table.rows[r].style.display = displayStyle;
  363. if ($("creer_modele")) {
  364. if (compte > 0) {$("creer_modele").setStyle("display", "none");}
  365. else {$("creer_modele").setStyle("display", "block");}
  366. }
  367. if ($("modif_modele")) {
  368. if (compte > 0) {$("modif_modele").setStyle("display", "none");}
  369. else {$("modif_modele").setStyle("display", "block");}
  370. }
  371. }
  372. }
  373. }
  374. // *********************************************************************************
  375. //
  376. // PERMET DE PASSER A LA CREATION MANUELLE D'une MARQUE
  377. //
  378. // *********************************************************************************
  379. function affiche_creer_modele() {
  380. $('creer_nouveau_modele').style.display = "";
  381. $('creer_modele_par_corr').style.display = "none";
  382. $('creer_modele').style.display = "none";
  383. }
  384. // *********************************************************************************
  385. //
  386. // PERMET DE PASSER A LA LISTE des MODčLES
  387. //
  388. // *********************************************************************************
  389. function affiche_liste_modele() {
  390. $('creer_nouveau_modele').style.display = "none";
  391. $('creer_modele_par_corr').style.display = "";
  392. }
  393. // *********************************************************************************
  394. //
  395. // AJOUT d'un MARQUE par sa CORRESPONDANCE
  396. //
  397. // *********************************************************************************
  398. function validation_ajout_marque (corr_id, marque) {
  399. var valida = confirm('Voulez-vous vraiment ajouter la marque ' + marque + ' ?');
  400. // si la réponse est TRUE ==> on lance la page post_marques.php
  401. if (valida) {
  402. $('targetback').setStyle("display","block"); $('target').setStyle("display","block");
  403. $('target').load("gestion_inventaire/post_marques.php?action=add_corr&corr_id=" + corr_id);
  404. SexyLightbox.close();
  405. window.setTimeout("document.location.href='index.php?page=marques&filter=" + $('filt').value + "'", 1500);
  406. }
  407. }
  408. // *********************************************************************************
  409. //
  410. // MODIF d'une MARQUE par sa CORRESPONDANCE
  411. //
  412. // *********************************************************************************
  413. function validation_modif_marque (corr_id, marque, oldmarque, marque_id) {
  414. var valida = confirm('Voulez-vous vraiment modifier la marque ' + oldmarque + ' par la marque ' + marque + ' ?');
  415. // si la réponse est TRUE ==> on lance la page post_marques.php
  416. if (valida) {
  417. $('targetback').setStyle("display","block"); $('target').setStyle("display","block");
  418. $('target').load("gestion_inventaire/post_marques.php?action=modif_corr&corr_id=" + corr_id + "&marque_id=" + marque_id);
  419. SexyLightbox.close();
  420. window.setTimeout("document.location.href='index.php?page=marques&filter=" + $('filt').value + "'", 1500);
  421. }
  422. }
  423. // *********************************************************************************
  424. //
  425. // PERMET DE PASSER A LA MODIFICATION MANUELLE D'une MARQUE
  426. //
  427. // *********************************************************************************
  428. function affiche_modif_modele() {
  429. $('modif_manuelle_modele').style.display = "";
  430. $('modif_modele_par_corr').style.display = "none";
  431. $('modif_modele').style.display = "none";
  432. }
  433. /******************************************
  434. *
  435. * AJAX
  436. *
  437. *******************************************/
  438. window.addEvent('domready', function(){
  439. $('post_form').addEvent('submit', function(e) { // Pour poster un formulaire
  440. new Event(e).stop();
  441. new Request({
  442. method: this.method,
  443. url: this.action,
  444. onSuccess: function(responseText, responseXML, filt) {
  445. $('targetback').setStyle("display","block"); $('target').setStyle("display","block");
  446. $('target').set('html', responseText);
  447. SexyLightbox.close();
  448. window.setTimeout("document.location.href='index.php?page=marques&filter=" + $('filt').value + "'", 1500);
  449. }
  450. }).send(this.toQueryString());
  451. });
  452. });
  453. </script>