Advertisement
Guest User

Untitled

a guest
Sep 12th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 77.51 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4. //error_reporting(0);
  5. include("constantes.php");
  6.  
  7. function connexion(){
  8. try {
  9. $user = DBUSER;
  10. $passwd = DBPWD;
  11. $dbname = DBNAME;
  12. $host = SERVERNAME;
  13. $db = new PDO("pgsql:dbname=$dbname;host=$host", $user, $passwd);
  14. }
  15. catch ( PDOException $e ) {
  16. return false;
  17. }
  18. return $db;
  19. }
  20.  
  21. function CoUtilisateur($db,$user,$pass){
  22. $exec = false;
  23. $result = false;
  24. try {
  25. $req = "SELECT * from utilisateur WHERE (utilisateur = ?) AND (pass = ?) AND (inactif = '0');";
  26. $sql = $db->prepare($req);
  27. $sql->bindParam(1, $user, PDO::PARAM_STR,500);
  28. $sql->bindParam(2, $pass, PDO::PARAM_STR,500);
  29. $exec = $sql->execute();
  30. $result = $sql->fetch(PDO::FETCH_ASSOC);
  31. }
  32. catch (PDOException $e) {
  33. return false;
  34. }
  35. if (!$exec) {
  36. return false;
  37. }
  38. return $result;
  39. }
  40.  
  41.  
  42. function Visualisation($db,$table, $data){
  43. try {
  44. $req = null;
  45. $exec = false;
  46. $result = false;
  47. switch ($table) {
  48. case 'reference-bl':
  49. $req = " SELECT coalesce(COUNT(*)+1,1) as id, coalesce(configuration.code_atelier,'56') as code_atelier FROM bon_de_livraison as bl,configuration WHERE (configuration.id = ?) AND (EXTRACT(YEAR from bl.date_expedition) = ?) GROUP BY configuration.code_atelier;";
  50. $sql = $db->prepare($req);
  51. $id = $_SESSION['id'];
  52. $sql->bindParam(1, $id, PDO::PARAM_INT);
  53. $year = date("Y");
  54. $sql->bindParam(2, $year, PDO::PARAM_INT);
  55. break;
  56. case 'reference-facture':
  57. $req = " SELECT coalesce(max(factures.id)+1,1) as id, coalesce(configuration.code_atelier,'56') as code_atelier FROM bon_de_livraison as bl,factures WHERE configuration.id = ? GROUP BY configuration.code_atelier;";
  58. $sql = $db->prepare($req);
  59. $id = $_SESSION['id'];
  60. $sql->bindParam(1, $id, PDO::PARAM_INT);
  61. break;
  62. case 'stock':
  63. $req = "SELECT id as N°, designation as Designation, quantite as Quantité, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 'N°,Designation,Quantité' as colonnes, 'stock' as type FROM stock WHERE id > ? ";
  64. $sql= $db->prepare($req);
  65. $sql->bindParam(1, $data[0], PDO::PARAM_INT);
  66. break;
  67. case 'stock-all':
  68. $req = "SELECT id,designation FROM stock WHERE quantite > 0";
  69. $sql = $db->prepare($req);
  70. break;
  71. case 'aide':
  72. $req = "SELECT id as N°, titre as Titre, tag as Tag, contenu as Contenu, 'N°,Titre,Tag,Contenu' as colonnes,1 as Modifier, 1 as Supprimer,'aide' as type FROM aide WHERE id > ?";
  73. $sql= $db->prepare($req);
  74. $sql->bindParam(1, $data[0], PDO::PARAM_INT);
  75. break;
  76. case 'intervention':
  77. if($data[1] == 0){
  78. $req = "SELECT i1.id as N°, i1.reference as Référence, i1.date_intervention as Date_Intervention, i1.lieu as Lieu, c1.nom as Client, i1.intervenant as Intervenant, b1.reference as Reference_BL,type_intervention AS Type_intervention, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 1 as Archiver, 0 as Desarchiver , 'N°,Référence,Date_Intervention,Lieu,Client,Intervenant,Reference_BL,Type_intervention' as colonnes, 'intervention' as type FROM interventions i1, clients c1, bon_de_livraison b1 WHERE (i1.id > ?) AND (i1.client = c1.id) AND (b1.id = i1.bon_de_livraison) AND (i1.archive = ?) ORDER BY i1.id ASC ";
  79. }else{
  80. $req = "SELECT i1.id as N°, i1.reference as Référence, i1.date_intervention as Date_Intervention, i1.lieu as Lieu, c1.nom as Client, i1.intervenant as Intervenant, b1.reference as Reference_BL,type_intervention AS Type_intervention,0 as Visualiser, 0 as Modifier, 0 as Supprimer, 0 as Dissocier, 0 as Archiver, 1 as Desarchiver , 'N°,Référence,Date_Intervention,Lieu,Client,Intervenant,Reference_BL,Type_intervention' as colonnes, 'intervention' as type FROM interventions i1, clients c1, bon_de_livraison b1 WHERE (i1.id > ?) AND (i1.client = c1.id) AND (b1.id = i1.bon_de_livraison) AND (i1.archive = ?) ORDER BY i1.id ASC ";
  81. }
  82. $sql= $db->prepare($req);
  83. $sql->bindParam(1, $data[0], PDO::PARAM_INT);
  84. $sql->bindParam(2, $data[1], PDO::PARAM_INT);
  85. break;
  86. case 'client':
  87. $req = "SELECT id as N°, nom as Nom, complement as Complément, responsable as Responsable, adresse as Adresse, code_postale as Code_Postale, ville as Ville, telephone as Telephone, fax as Fax, mail as Mail, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 'N°,Nom,Complément,Responsable,Adresse,Code_Postale,Ville,Telephone,Fax,Mail' as colonnes, 'client' as type FROM clients WHERE id > ? ";
  88. $sql= $db->prepare($req);
  89. $sql->bindParam(1, $data[0], PDO::PARAM_INT);
  90. break;
  91. case 'all-client':
  92. $req = "SELECT id, nom from clients";
  93. $sql = $db->prepare($req);
  94. break;
  95. case 'bl':
  96. if($data[1] == 0){
  97. $req = "SELECT bon.id as N°, bon.reference as Référence,cli.nom as Client,bon.date_expedition as Date_expedition,bon.date_facturation as Date_de_facturation,bon.adresse_facturation as Adresse_Facturation, bon.redacteur as Redacteur,type_bl as Type_de_BL, 1 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 1 as Archiver, 0 as Desarchiver , 1 as PDF, 'N°,Référence,Client,Date_expedition,Date_de_facturation,Adresse_Facturation,Redacteur,Type_de_BL' as colonnes, 'bl' as type FROM bon_de_livraison bon, clients cli WHERE (bon.client = cli.id) AND (bon.id > ?) AND (bon.archive = ?) ORDER BY bon.id ASC ";
  98. }else{
  99. $req = "SELECT bon.id as N°, bon.reference as Référence,cli.nom as Client,bon.date_expedition as Date_expedition,bon.date_facturation as Date_de_facturation,bon.adresse_facturation as Adresse_Facturation, bon.redacteur as Redacteur,type_bl as Type_de_BL, 1 as Visualiser, 0 as Modifier, 0 as Supprimer, 0 as Dissocier, 0 as Archiver, 1 as Desarchiver , 1 as PDF, 'N°,Référence,Client,Date_expedition,Date_de_facturation,Adresse_Facturation,Redacteur,Type_de_BL' as colonnes, 'bl' as type FROM bon_de_livraison bon, clients cli WHERE (bon.client = cli.id) AND (bon.id > ?) AND (bon.archive = ?) ORDER BY bon.id ASC ";
  100. }
  101. $sql= $db->prepare($req);
  102. $sql->bindParam(1, $data[0], PDO::PARAM_INT);
  103. $sql->bindParam(2, $data[1], PDO::PARAM_INT);
  104. break;
  105. case 'prix-bl':
  106. $req = "SELECT coalesce(ROUND(SUM(produit.quantite*articles.prix),2),0) as PrixTotal from articles_tarification_laposte articles, produit_et_travaux produit WHERE (articles.id = produit.designation) AND (produit.reference_bon_de_livraison = ?);";
  107. $sql= $db->prepare($req);
  108. $sql->bindParam(1, $data, PDO::PARAM_STR);
  109. break;
  110. case 'bl-possible-intervention':
  111. $req = "SELECT * FROM bon_de_livraison WHERE reference = ? OR id = (SELECT id FROM bon_de_livraison WHERE bon_de_livraison.id NOT IN (SELECT bon_de_livraison FROM interventions))";
  112. $sql= $db->prepare($req);
  113. $sql->bindParam(1, $data, PDO::PARAM_STR);
  114. break;
  115. case 'info-bl':
  116. $req = "SELECT * FROM bon_de_livraison WHERE reference = ?";
  117. $sql= $db->prepare($req);
  118. $sql->bindParam(1, $data, PDO::PARAM_STR);
  119. break;
  120. case 'prestation-bl':
  121. $req = "SELECT articles.id,produit.id as produit_et_travaux_id,articles.denomination,categorie_tarification_laposte.denomination as categorie, articles.prix,produit.quantite, ROUND(produit.quantite*articles.prix,2) as PrixTotalHT,produit.stock from articles_tarification_laposte articles, produit_et_travaux produit,categorie_tarification_laposte WHERE (categorie_tarification_laposte.id = articles.categorie_tarification) AND (articles.id = produit.designation) AND (produit.reference_bon_de_livraison = ?);";
  122. $sql= $db->prepare($req);
  123. $sql->bindParam(1, $data, PDO::PARAM_STR);
  124. break;
  125. case 'prestation-possible-bl':
  126. $req = "SELECT produit.id as id, produit.denomination as denomination, categorie.denomination as categorie, produit.prix as prix FROM articles_tarification_laposte produit, categorie_tarification_laposte categorie WHERE produit.categorie_tarification = categorie.id ORDER BY categorie;";
  127. $sql= $db->query($req);
  128. break;
  129. case 'bl-facture':
  130. $req = "SELECT b.reference as Désignation, b.lieu_intervention as Lieu_intervention, ROUND(SUM(p.quantite*a.prix),2) as \"P.U_brut\", '' as \"%\", ROUND(SUM(p.quantite*a.prix),2) as \"P.U_net\", 1 as Quantité,ROUND(SUM(p.quantite*a.prix),2) as \"Montant_H.T\",5 as \"*\", 0 as Visualiser, 0 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 0 as Desarchiver ,'Désignation,Lieu_intervention,P.U_brut,%,P.U_net,Quantité,Montant_H.T,*' as colonnes, 'bl-facture' as type FROM bon_de_livraison as b, articles_tarification_laposte as a, produit_et_travaux as p, factures as f WHERE (b.reference = p.reference_bon_de_livraison) AND (p.designation = a.id) AND (b.facture = f.id) AND (f.reference = ?) AND (b.archive = 1) GROUP BY b.reference,b.lieu_intervention;";
  131. $sql = $db->prepare( $req );
  132. $sql->bindParam(1,$data[0],PDO::PARAM_STR);
  133. break;
  134. case 'bl-possible-facture':
  135. $req = "SELECT bon.id, bon.reference FROM bon_de_livraison bon WHERE (facture = 0) AND (archive = 1)";
  136. $sql= $db->prepare($req);
  137. break;
  138. case 'info-facture':
  139. $req = "SELECT * FROM factures WHERE reference = ?";
  140. $sql = $db->prepare( $req );
  141. $sql->bindParam(1,$data[0],PDO::PARAM_STR);
  142. break;
  143. case 'facture':
  144. if($data[1] == 0){
  145. $req = "SELECT factures.id as N°, factures.reference as Référence, clients.nom as Client, factures.date_debut as Debut_Facturation,factures.date_fin as Fin_Facturation, factures.date_echeance as Date_Echeance, 1 as Visualiser, 1 as Modifier, 1 as Supprimer, 1 as Dissocier, 1 as Archiver, 0 as Desarchiver, 1 as PDF ,'N°,Référence,Client,Debut_Facturation,Fin_Facturation,Date_Echeance' as colonnes, 'facture' as type from factures, clients WHERE (factures.paye = 0) AND (clients.id = factures.client) AND (factures.id > ?) AND (factures.archive = ?) ORDER BY factures.id ASC ";
  146. }else{
  147. $req = "SELECT factures.id as N°, factures.reference as Référence, clients.nom as Client, factures.date_debut as Debut_Facturation,factures.date_fin as Fin_Facturation, factures.date_echeance as Date_Echeance, 1 as Visualiser, 0 as Modifier, 0 as Supprimer, 1 as Dissocier, 0 as Archiver, 1 as Desarchiver, 1 as PDF,'N°,Référence,Client,Debut_Facturation,Fin_Facturation,Date_Echeance' as colonnes, 'facture' as type from factures, clients WHERE (factures.paye = 0) AND (clients.id = factures.client) AND (factures.id > ?) AND (factures.archive = ?) ORDER BY factures.id ASC ";
  148. }
  149. $sql= $db->prepare($req);
  150. $sql->bindParam(1, $data[0], PDO::PARAM_INT);
  151. $sql->bindParam(2, $data[1], PDO::PARAM_INT);
  152. break;
  153. case 'prix-facture':
  154. $req = "SELECT coalesce(ROUND(SUM(p.quantite*a.prix),2),0) as prix_avant_tva, 20 as tva, coalesce(ROUND(SUM(p.quantite*a.prix)*0.2,2),0) as prix_tva, coalesce(ROUND(SUM(p.quantite*a.prix)*1.2,2),0) as prix_total FROM bon_de_livraison as b, articles_tarification_laposte as a, produit_et_travaux as p, factures as f WHERE (b.reference = p.reference_bon_de_livraison) AND (p.designation = a.id) AND (b.facture = f.id) AND (f.reference = ?);";
  155. $sql = $db->prepare( $req );
  156. $sql->bindParam(1,$data,PDO::PARAM_STR);
  157. break;
  158. case 'facture-dernier-id':
  159. $req = "SELECT COUNT(*) FROM factures";
  160. $sql = $db->query( $req );
  161. break;
  162. case 'bl-facture-dissocier':
  163. $req = "SELECT bl.type_bl as Type_intervention,
  164. bl.reference as reference,
  165. bl.lieu_intervention,
  166. SUM(articles_tarification_laposte.prix*produit_et_travaux.quantite) as \"P.U_brut\",
  167. '' as \"%\" ,
  168. SUM(articles_tarification_laposte.prix*produit_et_travaux.quantite) as \"P.U_net\",
  169. 1 as Quantité,
  170. SUM(articles_tarification_laposte.prix*produit_et_travaux.quantite) as \"Montant_H.T\",
  171. 5 as \"*\",
  172. 0 as Visualiser,
  173. 0 as Modifier,
  174. 0 as Supprimer,
  175. 0 as Dissocier,
  176. 0 as Archiver,
  177. 0 as Desarchiver,
  178. 'Type_intervention,Reference,Lieu_intervention,P.U_brut,%,P.U_net,Quantité,Montant_H.T,*' as colonnes FROM
  179. public.articles_tarification_laposte,
  180. public.bon_de_livraison as bl,
  181. public.categorie_tarification_laposte,
  182. public.clients,
  183. public.produit_et_travaux
  184. WHERE
  185. produit_et_travaux.reference_bon_de_livraison = bl.reference AND
  186. produit_et_travaux.designation = articles_tarification_laposte.id AND
  187. bl.client = clients.id AND
  188. bl.reference IN (SELECT b.reference FROM bon_de_livraison as b,factures as f WHERE (b.facture = f.id) AND (f.reference = ?))
  189. GROUP BY bl.date_expedition, bl.reference,bl.lieu_intervention,bl.type_bl";
  190. //$req = "SEELCT ";
  191. $sql = $db->prepare( $req );
  192. $sql->bindParam(1,$data[0],PDO::PARAM_STR);
  193. break;
  194. case 'sauvegarde':
  195. $req = "SELECT id as N°, date_sauvegarde as Date_de_la_sauvegarde, save_struct as Sauvegarde_structurelle, save_data as Sauvegarde_des_données, save_full as Sauvegarde_complète, mise_a_jour as \"Mise_à_jour\", 0 as Visualiser, 0 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 'N°,Date_de_la_sauvegarde,Sauvegarde_structurelle,Sauvegarde_des_données,Sauvegarde_complète,Mise_à_jour' as colonnes, 'sauvegarde' as type FROM sauvegarde WHERE id > ? ";
  196. $sql= $db->prepare($req);
  197. $sql->bindParam(1, $data[0], PDO::PARAM_INT);
  198. break;
  199. case 'categorie':
  200. $req = "SELECT id as N°, denomination as denomination, categorie_tarification_laposte.type as Classification, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 'N°,Denomination,Classification' as colonnes, 'categorie' as type FROM categorie_tarification_laposte WHERE id > ? ";
  201. $sql= $db->prepare($req);
  202. $sql->bindParam(1, $data[0], PDO::PARAM_INT);
  203. break;
  204. case 'all-categorie':
  205. $req = "SELECT id,denomination FROM categorie_tarification_laposte";
  206. $sql= $db->prepare($req);
  207. break;
  208. case 'config-redaction':
  209. $req = "SELECT * FROM configuration WHERE id = ?";
  210. $sql= $db->prepare($req);
  211. if(isset($_SESSION['id'])){
  212. $id = $_SESSION['id'];
  213. }else{
  214. $id = 1;
  215. }
  216. $sql->bindParam(1, $id,PDO::PARAM_INT);
  217. break;
  218. case 'info-user':
  219. $req = "SELECT utilisateur,nom,prenom FROM utilisateur WHERE id = ?";
  220. $sql= $db->prepare($req);
  221. $id = $_SESSION['id'];
  222. $sql->bindParam(1, $id, PDO::PARAM_INT);
  223. break;
  224. case 'utilisateur':
  225. $req = "SELECT utilisateur,visualisation_des_stocks as \"Visualisation des stocks\", interventions as \"Interventions\", clients as \"Clients\", modification_client as \"Modifier les clients\", bon_de_livraison as \"Bon de livraison\", modification_bon_de_livraison as \"Modification des bons de livraison\", visualisation_bon_de_livraison as \"Visualisation des bons de livraisons\",factures as Factures,visualisation_facture as \"Visualisation des factures\",modification_facture as \"Modification des factures\", analyses as \"Visualisation des analyses\", configuration_stock as \"Configuration du stock\", configuration_prestations as \"Configuration des prestations\", configuration_categories as \"Configuration des Catégories\", option_redaction as \"Option de rédactions\", administration_des_comptes as \"Administration des comptes\", configuration_du_compte as \"Configuration du compte\",archives as \"Visualisation des archives\", sauvegarde as \"Administration des sauvegardes\",inactif as \"inactif\" FROM utilisateur WHERE (utilisateur != 'admin') AND (id > ?) ORDER BY utilisateur";
  226. $sql= $db->prepare($req);
  227. $sql->bindParam(1, $data, PDO::PARAM_INT);
  228. break;
  229. case 'prestation':
  230. $req = "SELECT produit.id as N°, produit.denomination as denomination, categorie.denomination as categorie, produit.prix as prix, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 'N°,Denomination,Categorie,Prix' as colonnes, 'prestation' as type FROM articles_tarification_laposte produit, categorie_tarification_laposte categorie WHERE (produit.categorie_tarification = categorie.id) AND (produit.id > ?) ";
  231. $sql= $db->prepare($req);
  232. $sql->bindParam(1, $data[0], PDO::PARAM_INT);
  233. default:
  234. # code...
  235. break;
  236. }
  237.  
  238. if($req != null){
  239. $exec = $sql->execute();
  240. //print_r($sql->errorInfo());
  241. //echo $table;
  242. //if($table != "prestation-bl"){
  243. $result = $sql->fetchAll(PDO::FETCH_ASSOC);
  244. /*}else{
  245. $result = $sql->fetchAll(PDO::FETCH_NUM);
  246. }*/
  247.  
  248. }
  249. }
  250. catch (PDOException $e) {
  251. return false;
  252. }
  253. if (!$exec) {
  254. return false;
  255. }
  256. return $result;
  257. }
  258.  
  259. function Modification($db, $table, $data){
  260. try {
  261. $req = null;
  262. $exec = false;
  263. switch ($table) {
  264. case 'stock':
  265. $req = "UPDATE stock SET designation = ?,quantite = ? WHERE id = ?";
  266. $sql= $db->prepare($req);
  267. $sql->bindParam(1, $data[1], PDO::PARAM_STR);
  268. $sql->bindParam(2, $data[2], PDO::PARAM_INT);
  269. $sql->bindParam(3, $data[0], PDO::PARAM_INT);
  270. break;
  271. case 'facture-information':
  272. $req = "UPDATE factures SET information = ? WHERE reference = ?";
  273. $sql= $db->prepare($req);
  274. $sql->bindParam(1, $data[0], PDO::PARAM_STR);
  275. $sql->bindParam(2, $data[1], PDO::PARAM_STR);
  276. break;
  277. case 'intervention':
  278. $req = "UPDATE bon_de_livraison SET type_bl = ? WHERE id = (SELECT bl.id FROM bon_de_livraison bl, interventions i1 WHERE (? = i1.id) AND (bl.id = i1.bon_de_livraison))";
  279. $sql= $db->prepare($req);
  280. $sql->bindParam(1, $data[7], PDO::PARAM_STR);
  281. $sql->bindParam(2, $data[0], PDO::PARAM_INT);
  282. $sql->execute();
  283.  
  284. $req = "UPDATE interventions SET reference = ?,date_intervention = ?,lieu = ?,client = ?,Intervenant = ?,bon_de_livraison = ?,type_intervention = ? WHERE (id = ?)";
  285. $sql= $db->prepare($req);
  286. $sql->bindParam(1, $data[1], PDO::PARAM_STR);
  287. $sql->bindParam(2, $data[2], PDO::PARAM_STR);
  288. $sql->bindParam(3, $data[3], PDO::PARAM_STR);
  289. $sql->bindParam(4, $data[4], PDO::PARAM_INT);
  290. $sql->bindParam(5, $data[5], PDO::PARAM_STR);
  291. $sql->bindParam(6, $data[6], PDO::PARAM_INT);
  292. $sql->bindParam(7, $data[7], PDO::PARAM_STR);
  293. $sql->bindParam(8, $data[0], PDO::PARAM_INT);
  294. break;
  295. case 'client':
  296. $req = "UPDATE clients SET nom = ?, complement = ?,responsable = ?,adresse = ?,code_postale = ?,ville = ?,telephone = ?, fax = ?,mail = ? WHERE (id = ?)";
  297. $sql= $db->prepare($req);
  298. //var_dump($data);
  299. $sql->bindParam(1, $data[1], PDO::PARAM_STR);
  300. $sql->bindParam(2, $data[2], PDO::PARAM_STR);
  301. $sql->bindParam(3, $data[3], PDO::PARAM_STR);
  302. $sql->bindParam(4, $data[4], PDO::PARAM_INT);
  303. $sql->bindParam(5, $data[5], PDO::PARAM_STR);
  304. $sql->bindParam(6, $data[6], PDO::PARAM_INT);
  305. $sql->bindParam(7, $data[7], PDO::PARAM_STR);
  306. $sql->bindParam(8, $data[8], PDO::PARAM_STR);
  307. $sql->bindParam(9, $data[9], PDO::PARAM_STR);
  308. $sql->bindParam(10, $data[0], PDO::PARAM_INT);
  309. break;
  310. case 'bl':
  311. $req = "UPDATE interventions SET type_intervention = ? WHERE id = (SELECT i1.id FROM bon_de_livraison bl, interventions i1 WHERE (? = bl.id) AND (bl.id = i1.bon_de_livraison))";
  312. $sql= $db->prepare($req);
  313. $sql->bindParam(1, $data[9], PDO::PARAM_STR);
  314. $sql->bindParam(2, $data[8], PDO::PARAM_INT);
  315. $sql->execute();
  316.  
  317. $req = "UPDATE bon_de_livraison SET reference = ?,redacteur = ?,date_expedition = ?,date_facturation = ?, adresse_facturation = ?, lieu_intervention = ?, observation = ?, code_atelier = ?,type_bl = ? WHERE bon_de_livraison.id = ?";
  318. $sql= $db->prepare($req);
  319. $sql->bindParam(1, $data[0], PDO::PARAM_STR);
  320. $sql->bindParam(2, $data[1], PDO::PARAM_STR);
  321. $sql->bindParam(3, $data[2], PDO::PARAM_STR);
  322. $sql->bindParam(4, $data[3], PDO::PARAM_STR);
  323. $sql->bindParam(5, $data[4], PDO::PARAM_STR);
  324. $sql->bindParam(6, $data[5], PDO::PARAM_STR);
  325. $sql->bindParam(7, $data[6], PDO::PARAM_STR);
  326. $sql->bindParam(8, $data[7], PDO::PARAM_STR);
  327. $sql->bindParam(9, $data[9], PDO::PARAM_STR);
  328. $sql->bindParam(10, $data[8], PDO::PARAM_INT);
  329. break;
  330. case 'categorie':
  331. $req = "UPDATE categorie_tarification_laposte SET denomination = ?, type = ? WHERE id = ? ";
  332. $sql= $db->prepare($req);
  333. $sql->bindParam(1, $data[1], PDO::PARAM_STR);
  334. $sql->bindParam(2, $data[2], PDO::PARAM_STR);
  335. $sql->bindParam(3, $data[0], PDO::PARAM_INT);
  336. break;
  337. case 'prestation':
  338. $req = "UPDATE articles_tarification_laposte SET denomination = ?,categorie_tarification = ?,prix = ? WHERE (id = ?)";
  339. $sql= $db->prepare($req);
  340. $sql->bindParam(1, $data[1], PDO::PARAM_STR);
  341. $sql->bindParam(2, $data[2], PDO::PARAM_INT);
  342. $sql->bindParam(3, $data[3], PDO::PARAM_STR);
  343. $sql->bindParam(4, $data[0], PDO::PARAM_INT);
  344. break;
  345. case 'config-redaction':
  346. $req = "UPDATE configuration SET nom = ?, code_atelier = ?,rue = ?, bp = ?, code_postale = ?, ville = ?, cedex = ?, telephone = ?, fax = ?, email = ?, site_web = ?, code_ape = ?, code_urssaf = ?, num_intercommunautaire = ?, num_tva = ?, num_siret = ?, ordre_cheque = ?, IBAN = ?, BIC = ?, pied_de_page = ? WHERE id = ? ";
  347. $sql= $db->prepare($req);
  348. $id = $_SESSION['id'];
  349. $sql->bindParam(1, $data[0], PDO::PARAM_STR);
  350. $sql->bindParam(2, $data[1], PDO::PARAM_STR);
  351. $sql->bindParam(3, $data[2], PDO::PARAM_STR);
  352. $sql->bindParam(4, $data[3], PDO::PARAM_STR);
  353. $sql->bindParam(5, $data[4], PDO::PARAM_STR);
  354. $sql->bindParam(6, $data[5], PDO::PARAM_STR);
  355. $sql->bindParam(7, $data[6], PDO::PARAM_STR);
  356. $sql->bindParam(8, $data[7], PDO::PARAM_STR);
  357. $sql->bindParam(9, $data[8], PDO::PARAM_STR);
  358. $sql->bindParam(10, $data[9], PDO::PARAM_STR);
  359. $sql->bindParam(11, $data[10], PDO::PARAM_STR);
  360. $sql->bindParam(12, $data[11], PDO::PARAM_STR);
  361. $sql->bindParam(13, $data[12], PDO::PARAM_STR);
  362. $sql->bindParam(14, $data[13], PDO::PARAM_STR);
  363. $sql->bindParam(15, $data[14], PDO::PARAM_STR);
  364. $sql->bindParam(16, $data[15], PDO::PARAM_STR);
  365. $sql->bindParam(17, $data[16], PDO::PARAM_STR);
  366. $sql->bindParam(18, $data[17], PDO::PARAM_STR);
  367. $sql->bindParam(19, $data[18], PDO::PARAM_INT);
  368. $sql->bindParam(20, $data[19], PDO::PARAM_INT);
  369. $sql->bindParam(21, $id, PDO::PARAM_INT);
  370. break;
  371. case 'config-permission':
  372. $req = "UPDATE utilisateur SET visualisation_des_stocks = ?, interventions = ?, clients = ?, modification_client = ?, bon_de_livraison = ?, modification_bon_de_livraison = ?, visualisation_bon_de_livraison = ?, factures = ?, visualisation_facture = ?, modification_facture = ?, analyses = ?, configuration_stock = ?,configuration_prestations = ?, configuration_categories = ?, option_redaction = ?, administration_des_comptes = ?, configuration_du_compte = ?,archives = ?,sauvegarde = ? ,inactif = ?,aide = 1 WHERE utilisateur = ?";
  373. $sql= $db->prepare($req);
  374. $sql->bindParam(1, $data[0], PDO::PARAM_STR);
  375. $sql->bindParam(2, $data[1], PDO::PARAM_STR);
  376. $sql->bindParam(3, $data[2], PDO::PARAM_STR);
  377. $sql->bindParam(4, $data[3], PDO::PARAM_STR);
  378. $sql->bindParam(5, $data[4], PDO::PARAM_STR);
  379. $sql->bindParam(6, $data[5], PDO::PARAM_STR);
  380. $sql->bindParam(7, $data[6], PDO::PARAM_STR);
  381. $sql->bindParam(8, $data[7], PDO::PARAM_STR);
  382. $sql->bindParam(9, $data[8], PDO::PARAM_STR);
  383. $sql->bindParam(10, $data[9], PDO::PARAM_STR);
  384. $sql->bindParam(11, $data[10], PDO::PARAM_STR);
  385. $sql->bindParam(12, $data[11], PDO::PARAM_STR);
  386. $sql->bindParam(13, $data[12], PDO::PARAM_STR);
  387. $sql->bindParam(14, $data[13], PDO::PARAM_STR);
  388. $sql->bindParam(15, $data[14], PDO::PARAM_STR);
  389. $sql->bindParam(16, $data[15], PDO::PARAM_STR);
  390. $sql->bindParam(17, $data[16], PDO::PARAM_STR);
  391. $sql->bindParam(18, $data[17], PDO::PARAM_STR);
  392. $sql->bindParam(19, $data[18], PDO::PARAM_STR);
  393. $sql->bindParam(20, $data[19], PDO::PARAM_STR);
  394. $sql->bindParam(21, $data[20], PDO::PARAM_STR);
  395. break;
  396. case 'bl-possible-facture':
  397. $req = "UPDATE bon_de_livraison SET facture = (SELECT id FROM factures WHERE reference = ?) WHERE id = ?";
  398. $sql= $db->prepare($req);
  399. $sql->bindParam(1, $data[0], PDO::PARAM_STR);
  400. $sql->bindParam(2, $data[1], PDO::PARAM_STR);
  401. break;
  402. case 'mdp':
  403. $req = "UPDATE utilisateur SET pass = ? WHERE utilisateur = ?";
  404. $sql= $db->prepare($req);
  405. $sql->bindParam(1, $data[0], PDO::PARAM_STR);
  406. $sql->bindParam(2, $data[1], PDO::PARAM_STR);
  407. break;
  408. case 'quantite-produit-bl':
  409. // 0 - ID PRODUIT ET TRAVAUX
  410. // 1 - QUANTITE PRESTATION
  411. // 2 - QUANTITE PRECEDENTE PRESTATION
  412. // 3 - ID STOCK
  413. //var_dump($data);
  414. $req = "UPDATE stock SET quantite = ((SELECT quantite FROM stock WHERE id = (SELECT stock FROM produit_et_travaux WHERE id = ?))+?) WHERE id = (SELECT stock FROM produit_et_travaux WHERE id = ?)";
  415. $sql1 = $db->prepare($req);
  416. $sql1->bindParam(1,$data[0],PDO::PARAM_INT);
  417. $sql1->bindParam(2,$data[2],PDO::PARAM_INT);
  418. $sql1->bindParam(3,$data[0],PDO::PARAM_INT);
  419. $sql1->execute();
  420. //print_r($sql1->errorInfo());
  421. //echo "</br>";
  422. $req = "UPDATE stock SET quantite = (SELECT quantite FROM stock WHERE id = ?)-? WHERE id = ?";
  423. $sql2= $db->prepare($req);
  424. $sql2->bindParam(1,$data[3],PDO::PARAM_INT);
  425. $sql2->bindParam(2,$data[1],PDO::PARAM_INT);
  426. $sql2->bindParam(3,$data[3],PDO::PARAM_INT);
  427. $sql2->execute();
  428. //print_r($sql2->errorInfo());
  429.  
  430.  
  431. $req = "UPDATE produit_et_travaux SET quantite = ?,stock = ? WHERE produit_et_travaux.id = ?";
  432. $sql= $db->prepare($req);
  433. $sql->bindParam(1, $data[1], PDO::PARAM_INT);
  434. $sql->bindParam(2, $data[3], PDO::PARAM_INT);
  435. $sql->bindParam(3, $data[0], PDO::PARAM_INT);
  436.  
  437. break;
  438. case 'statut-utilisateur':
  439. $req = "UPDATE utilisateur SET inactif = ? WHERE utilisateur = ? ";
  440. $sql= $db->prepare($req);
  441. $sql->bindParam(1, $data[0], PDO::PARAM_STR);
  442. $sql->bindParam(2, $data[1], PDO::PARAM_STR);
  443. break;
  444. case 'bl-facture':
  445. $req = "UPDATE bon_de_livraison SET facture = 0 WHERE reference = ?";
  446. $sql= $db->prepare($req);
  447. $sql->bindParam(1, $data, PDO::PARAM_STR);
  448. break;
  449. case 'aide':
  450. $req = "UPDATE aide SET titre = ?,tag = ?, contenu = ? WHERE id = ?";
  451. $sql= $db->prepare($req);
  452. $sql->bindParam(4, $data[0], PDO::PARAM_STR);
  453. $sql->bindParam(1, $data[1], PDO::PARAM_STR);
  454. $sql->bindParam(2, $data[2], PDO::PARAM_STR);
  455. $sql->bindParam(3, $data[3], PDO::PARAM_STR);
  456. break;
  457. default:
  458. # code...
  459. break;
  460. }
  461.  
  462. if($req != null){
  463. $exec = $sql->execute();
  464. /* var_dump($data);
  465. */// print_r($sql->errorInfo());
  466.  
  467. }
  468. }
  469. catch (PDOException $e) {
  470. return false;
  471. }
  472. if (!$exec) {
  473. return false;
  474. }
  475. return $exec;
  476. }
  477.  
  478. function Suppresion($db,$table, $data){
  479. try {
  480. $req = null;
  481. $exec = false;
  482. switch ($table) {
  483. case 'stock':
  484. $req = "DELETE FROM stock WHERE id = :id";
  485. $sql = $db->prepare( $req );
  486. $sql->bindParam(':id', $data, PDO::PARAM_INT);
  487. break;
  488. case 'intervention':
  489. $req = "UPDATE stock set quantite = stock.quantite+p.quantite FROM (SELECT quantite,stock FROM produit_et_travaux WHERE reference_bon_de_livraison = (SELECT bon_de_livraison.reference FROM interventions,bon_de_livraison WHERE interventions.id = ? AND interventions.bon_de_livraison = bon_de_livraison.id) ) AS p WHERE id = p.stock;";
  490. $sql = $db->prepare( $req );
  491. $sql->bindParam(1, $data, PDO::PARAM_INT);
  492. $sql->execute();
  493.  
  494. $req = "DELETE FROM bon_de_livraison WHERE bon_de_livraison.id = (SELECT interventions.bon_de_livraison FROM interventions WHERE interventions.id = ?)";
  495. $sql = $db->prepare( $req );
  496. $sql->bindParam(1, $data, PDO::PARAM_INT);
  497. $exec = $sql->execute();
  498. if($exec){
  499. $req = "DELETE FROM interventions WHERE interventions.id = :id";
  500. $sql = $db->prepare( $req );
  501. $sql->bindParam(':id', $data, PDO::PARAM_INT);
  502. }
  503. break;
  504. case 'client':
  505. $req = "DELETE FROM clients WHERE id = :id";
  506. $sql = $db->prepare( $req );
  507. $sql->bindParam(':id', $data, PDO::PARAM_INT);
  508. break;
  509. case 'bl':
  510. $req = "UPDATE stock set quantite = stock.quantite+p.quantite FROM (SELECT quantite,stock FROM produit_et_travaux WHERE reference_bon_de_livraison = (SELECT reference FROM bon_de_livraison WHERE id = ?)) AS p WHERE id = p.stock;";
  511. $sql = $db->prepare( $req );
  512. $sql->bindParam(1, $data, PDO::PARAM_INT);
  513. $sql->execute();
  514.  
  515. $req = "DELETE FROM bon_de_livraison WHERE id = :id";
  516. $sql = $db->prepare( $req );
  517. $sql->bindParam(':id', $data, PDO::PARAM_INT);
  518. break;
  519. case 'facture':
  520. $req = "UPDATE bon_de_livraison SET facture = 0 WHERE facture = ?";
  521. $sql = $db->prepare( $req );
  522. $sql->bindParam(1, $data, PDO::PARAM_INT);
  523. $sql->execute();
  524. $req = "DELETE FROM factures WHERE id = :id";
  525. $sql = $db->prepare( $req );
  526. $sql->bindParam(':id', $data, PDO::PARAM_INT);
  527. break;
  528. case 'categorie':
  529. $req = "DELETE FROM categorie_tarification_laposte WHERE id = :id";
  530. $sql = $db->prepare( $req );
  531. $sql->bindParam(':id', $data, PDO::PARAM_INT);
  532. break;
  533. case 'prestation':
  534. $req = "DELETE FROM articles_tarification_laposte WHERE id = :id";
  535. $sql = $db->prepare( $req );
  536. $sql->bindParam(':id', $data, PDO::PARAM_INT);
  537. break;
  538. case 'aide':
  539. $req = "DELETE FROM aide WHERE id = :id";
  540. $sql = $db->prepare( $req );
  541. $sql->bindParam(':id', $data, PDO::PARAM_INT);
  542. break;
  543. case 'produit-bl':
  544. $req = "UPDATE stock SET quantite = ((SELECT quantite FROM stock WHERE id = (SELECT stock FROM produit_et_travaux WHERE id = ?))+?) WHERE id = (SELECT stock FROM produit_et_travaux WHERE id = ?)";
  545. $sql1 = $db->prepare($req);
  546. $sql1->bindParam(1,$data[2],PDO::PARAM_INT);
  547. $sql1->bindParam(2,$data[3],PDO::PARAM_INT);
  548. $sql1->bindParam(3,$data[2],PDO::PARAM_INT);
  549. $sql1->execute();
  550.  
  551. $req = "DELETE FROM produit_et_travaux WHERE (reference_bon_de_livraison = ?) AND (designation= ?)";
  552. $sql = $db->prepare($req);
  553. $sql->bindParam(1, $data[0], PDO::PARAM_STR);
  554. $sql->bindParam(2, $data[1], PDO::PARAM_INT);
  555. break;
  556. case 'sauvegarde':
  557. $req ="SELECT * FROM sauvegarde WHERE id = :id";
  558. $sql = $db->prepare( $req );
  559. $sql->bindParam(':id', $data, PDO::PARAM_INT);
  560. $res = $sql->execute();
  561. if($res){
  562. $infos = $sql->fetch(PDO::FETCH_NUM);
  563. $file_struct = $infos[2];
  564. $file_data = $infos[3];
  565. $file_full = $infos[4];
  566. $file_mise_a_jour = $infos[5];
  567. unlink ("/var/www/html/sauvegarde/file/".$file_struct);
  568. unlink ("/var/www/html/sauvegarde/file/".$file_data);
  569. unlink ("/var/www/html/sauvegarde/file/".$file_full);
  570. unlink ("/var/www/html/sauvegarde/file/".$file_mise_a_jour);
  571. $req = "DELETE FROM sauvegarde WHERE id = :id";
  572. $sql = $db->prepare( $req );
  573. $sql->bindParam(':id', $data, PDO::PARAM_INT);
  574. }else{
  575. $result = FALSE;
  576. }
  577. break;
  578. default:
  579. # code...
  580. break;
  581. }
  582.  
  583. if($req != null){
  584. $exec = $sql->execute();
  585. $result = $sql->fetchAll(PDO::FETCH_ASSOC);
  586. }
  587. }
  588. catch (PDOException $e) {
  589. return false;
  590. }
  591. if (!$exec) {
  592. return false;
  593. }
  594. return $exec;
  595. }
  596.  
  597. function Ajouter($db, $table, $data){
  598. try {
  599. $req = null;
  600. $exec = false;
  601. switch ($table) {
  602. case 'stock':
  603. $req = "INSERT INTO stock (designation, quantite) VALUES (?,?)";
  604. $sql= $db->prepare($req);
  605. $sql->bindParam(1, $data[0], PDO::PARAM_STR);
  606. $sql->bindParam(2, $data[1], PDO::PARAM_INT);
  607. break;
  608. case 'intervention':
  609.  
  610. $req = "INSERT INTO interventions (reference,date_intervention, lieu, client, intervenant, bon_de_livraison,type_intervention) VALUES (?,?, ?, ?, ?,nextval('bon_de_livraison_id_seq')+1,?)";
  611. $sql= $db->prepare($req);
  612. $sql->bindParam(1, $data[0], PDO::PARAM_STR);
  613. $sql->bindParam(2, $data[1], PDO::PARAM_STR);
  614. $sql->bindParam(3, $data[2], PDO::PARAM_STR);
  615. $sql->bindParam(4, $data[3], PDO::PARAM_INT);
  616. $sql->bindParam(5, $data[4], PDO::PARAM_STR);
  617. $sql->bindParam(6, $data[5], PDO::PARAM_STR);
  618.  
  619. $exec = $sql->execute();
  620.  
  621. if($exec){
  622. $req = "INSERT INTO bon_de_livraison (reference, date_expedition, date_facturation, redacteur,client,lieu_intervention,adresse_facturation,code_atelier,type_bl) VALUES (?, ?,?, ?,?,?,(SELECT adresse FROM clients WHERE id = ?),(SELECT code_atelier FROM configuration WHERE id = ?),?)";
  623. $sql= $db->prepare($req);
  624. $redacteur = $_SESSION['nom']."-".$_SESSION['prenom'];
  625. $ReferenceBL = Visualisation($db,'reference-bl', null);
  626.  
  627. $date = date('Y');
  628. $Ref = '0000'.$ReferenceBL[0]['id'];
  629. $len = strlen($Ref);
  630. $Ref = $Ref[$len-4].$Ref[$len-3].$Ref[$len-2].$Ref[$len-1];
  631. $Ref = $ReferenceBL[0]['code_atelier'].$date[2].$date[3].$Ref;
  632.  
  633. $sql->bindParam(1, $Ref, PDO::PARAM_STR);
  634. $sql->bindParam(2,$data[1], PDO::PARAM_STR);
  635. $sql->bindParam(3, $data[1], PDO::PARAM_STR);
  636. $sql->bindParam(4, $redacteur, PDO::PARAM_STR);
  637. $sql->bindParam(5, $data[3], PDO::PARAM_INT);
  638. $sql->bindParam(6, $data[2], PDO::PARAM_STR);
  639. $sql->bindParam(7, $data[3], PDO::PARAM_INT);
  640. $sql->bindParam(8, $_SESSION['id'], PDO::PARAM_INT);
  641. $sql->bindParam(9, $data[5], PDO::PARAM_STR);
  642. $exec = $sql->execute();
  643. $req = null;
  644. if(!$exec){
  645. $req = "DELETE FROM interventions WHERE id = currval('interventions_id_seq')";
  646. $sql = $db->prepare($req);
  647. $exec = $sql->execute();
  648. if($exec){
  649. $req = null;
  650. $exec = false;
  651. }
  652. }
  653. }
  654.  
  655. break;
  656. case 'client':
  657. $req = "INSERT INTO clients (nom, complement, responsable, adresse, code_postale, ville,telephone,fax,mail) VALUES (?, ?, ?, ?, ?,?,?,?,?)";
  658. $sql= $db->prepare($req);
  659. $sql->bindParam(1, $data[0], PDO::PARAM_STR);
  660. $sql->bindParam(2, $data[1], PDO::PARAM_STR);
  661. $sql->bindParam(3, $data[2], PDO::PARAM_STR);
  662. $sql->bindParam(4, $data[3], PDO::PARAM_STR);
  663. $sql->bindParam(5, $data[4], PDO::PARAM_STR);
  664. $sql->bindParam(6, $data[5], PDO::PARAM_STR);
  665. $sql->bindParam(7, $data[6], PDO::PARAM_STR);
  666. $sql->bindParam(8, $data[7], PDO::PARAM_STR);
  667. $sql->bindParam(9, $data[8], PDO::PARAM_STR);
  668.  
  669. break;
  670. case 'bl':
  671. $req = "INSERT INTO bon_de_livraison (reference, client,adresse_facturation,code_atelier,redacteur,type_bl) VALUES (?,?,(SELECT adresse FROM clients WHERE id = ?),(SELECT code_atelier FROM configuration WHERE id = ?),?,?)";
  672. $sql= $db->prepare($req);
  673. $sql->bindParam(1, $data[0], PDO::PARAM_STR);
  674. $sql->bindParam(2, $data[1], PDO::PARAM_INT);
  675. $sql->bindParam(3, $data[1], PDO::PARAM_INT);
  676. $sql->bindParam(4, $_SESSION['id'], PDO::PARAM_INT);
  677. $redacteur = $_SESSION['nom']."-".$_SESSION['prenom'];
  678. $sql->bindParam(5, $redacteur, PDO::PARAM_STR);
  679. $sql->bindParam(6, $data[2], PDO::PARAM_STR);
  680.  
  681. break;
  682. case 'facture':
  683. $req = "INSERT INTO factures (reference, client,date_debut, date_fin,date_creation,date_echeance,dissocier) VALUES (?, ?, ?, ?, ?,?,0)";
  684. $sql = $db->prepare($req);
  685. $date = date('Y-m-d');
  686. $date_echance = new DateTime();
  687. $interval = new DateInterval('P1M');
  688. $date_echance->add($interval);
  689. $date_eche = $date_echance->format('Y-m-d');
  690.  
  691. $sql->bindParam(1, $data[0], PDO::PARAM_INT);
  692. $sql->bindParam(2, $data[1], PDO::PARAM_STR);
  693. $sql->bindParam(3, $data[2], PDO::PARAM_STR);
  694. $sql->bindParam(4, $data[3], PDO::PARAM_STR);
  695. $sql->bindParam(5, $date, PDO::PARAM_STR);
  696. $sql->bindParam(6, $date_eche, PDO::PARAM_STR);
  697. $result = $sql->execute();
  698.  
  699. $req = "UPDATE bon_de_livraison SET facture = (SELECT id FROM factures WHERE reference = ?) WHERE reference = (SELECT reference WHERE (date_expedition BETWEEN ? AND ?) AND (client = ?) AND (archive = 1) AND (facture = 0) AND (type_bl = ?) )";
  700. $sql= $db->prepare($req);
  701. $sql->bindParam(1, $data[0], PDO::PARAM_STR);
  702. $sql->bindParam(4, $data[1], PDO::PARAM_STR);
  703. $sql->bindParam(2, $data[2], PDO::PARAM_STR);
  704. $sql->bindParam(3, $data[3], PDO::PARAM_INT);
  705. $sql->bindParam(5, $data[4], PDO::PARAM_STR);
  706. break;
  707. case 'categorie':
  708. $req = "INSERT INTO categorie_tarification_laposte (denomination, type) VALUES (?, ?)";
  709. $sql= $db->prepare($req);
  710. $sql->bindParam(1, $data[0], PDO::PARAM_STR);
  711. $sql->bindParam(2, $data[1], PDO::PARAM_STR);
  712. break;
  713. case 'prestation':
  714. $req = "INSERT INTO articles_tarification_laposte (denomination, categorie_tarification, prix) VALUES (?, ?, ?)";
  715. $sql= $db->prepare($req);
  716. $sql->bindParam(1, $data[0], PDO::PARAM_STR);
  717. $sql->bindParam(2, $data[1], PDO::PARAM_STR);
  718. $sql->bindParam(3, $data[2], PDO::PARAM_STR);
  719. break;
  720. case 'aide':
  721. $req = "INSERT INTO aide (titre, tag, contenu) VALUES (?, ?, ?)";
  722. $sql= $db->prepare($req);
  723. $sql->bindParam(1, $data[0], PDO::PARAM_STR);
  724. $sql->bindParam(2, $data[1], PDO::PARAM_STR);
  725. $sql->bindParam(3, $data[2], PDO::PARAM_STR);
  726. break;
  727. case 'utilisateur':
  728. $req = "INSERT INTO utilisateur (utilisateur, pass,nom,prenom) VALUES (?,?,?,?)";
  729. $sql= $db->prepare($req);
  730. $sql->bindParam(1, $data[0], PDO::PARAM_STR);
  731. $sql->bindParam(2, $data[1], PDO::PARAM_STR);
  732. $sql->bindParam(3, $data[2], PDO::PARAM_STR);
  733. $sql->bindParam(4, $data[3], PDO::PARAM_STR);
  734.  
  735. $exec = $sql->execute();
  736.  
  737. if($exec){
  738. $req = "SELECT * FROM (SELECT (SELECT utilisateur.id FROM utilisateur WHERE utilisateur.utilisateur = ?),configuration.nom,configuration.rue,configuration.bp,configuration.code_postale,configuration.ville,configuration.cedex,configuration.telephone,configuration.fax,configuration.email,configuration.site_web,configuration.code_ape,configuration.code_urssaf, configuration.num_intercommunautaire, configuration.num_tva,configuration.num_siret, configuration.ordre_cheque, configuration.iban,configuration.bic,configuration.pied_de_page FROM configuration,utilisateur WHERE utilisateur.utilisateur = 'admin') AS INFO;";
  739. $sql= $db->prepare($req);
  740. $sql->bindParam(1, $data[0], PDO::PARAM_STR);
  741. $exec = $sql->execute();
  742. $result = $sql->fetch(PDO::FETCH_NUM);
  743. $req = "INSERT INTO configuration (id,nom,rue,bp,code_postale,ville,cedex,telephone, fax,email,site_web,code_ape,code_urssaf, num_intercommunautaire, num_tva,num_siret, ordre_cheque, iban, bic, pied_de_page) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
  744. $sql= $db->prepare($req);
  745. $sql->bindParam(1, $result[0], PDO::PARAM_STR);
  746. $sql->bindParam(2, $result[1], PDO::PARAM_STR);
  747. $sql->bindParam(3, $result[2], PDO::PARAM_STR);
  748. $sql->bindParam(4, $result[3], PDO::PARAM_STR);
  749. $sql->bindParam(5, $result[4], PDO::PARAM_STR);
  750. $sql->bindParam(6, $result[5], PDO::PARAM_STR);
  751. $sql->bindParam(7, $result[6], PDO::PARAM_STR);
  752. $sql->bindParam(8, $result[7], PDO::PARAM_STR);
  753. $sql->bindParam(9, $result[8], PDO::PARAM_STR);
  754. $sql->bindParam(10, $result[9], PDO::PARAM_STR);
  755. $sql->bindParam(11, $result[10], PDO::PARAM_STR);
  756. $sql->bindParam(12, $result[11], PDO::PARAM_STR);
  757. $sql->bindParam(13, $result[12], PDO::PARAM_STR);
  758. $sql->bindParam(14, $result[13], PDO::PARAM_STR);
  759. $sql->bindParam(15, $result[14], PDO::PARAM_STR);
  760. $sql->bindParam(16, $result[15], PDO::PARAM_STR);
  761. $sql->bindParam(17, $result[16], PDO::PARAM_STR);
  762. $sql->bindParam(18, $result[17], PDO::PARAM_STR);
  763. $sql->bindParam(19, $result[18], PDO::PARAM_STR);
  764. $sql->bindParam(20, $result[19], PDO::PARAM_INT);
  765. }
  766. break;
  767. case 'produit-bl':
  768. $req = "INSERT INTO produit_et_travaux (reference_bon_de_livraison, designation) VALUES (?, ?);";
  769. $sql = $db->prepare($req);
  770. $sql->bindParam(1, $data[0], PDO::PARAM_STR);
  771. $sql->bindParam(2, $data[1], PDO::PARAM_INT);
  772. break;
  773. case 'bl-facture':
  774. $req = "UPDATE bon_de_livraison SET facture = (SELECT id FROM factures WHERE reference = ?) WHERE id = ?;";
  775. $sql= $db->prepare($req);
  776. $sql->bindParam(1, $data[0], PDO::PARAM_STR);
  777. $sql->bindParam(2, $data[1], PDO::PARAM_INT);
  778. break;
  779. case 'sauvegarde':
  780. $date = date('Y-m-d');
  781. $date_file = date('Y_m_d_H_i_s');
  782. $file_struct = "SAUVEGARDE_STRUCTURE_".$date_file.'.sql';
  783. $file_data = "SAUVEGARDE_DATA_".$date_file.'.sql';
  784. $file_full = "SAUVEGARDE_COMPLETE_".$date_file.'.sql';
  785. $file_update = "MISE_A_JOUR_".$date_file.".sql";
  786. $req = "INSERT INTO sauvegarde (date_sauvegarde,save_struct,save_data,save_full,mise_a_jour) VALUES (?,?,?,?,?)";
  787. $sql = $db->prepare( $req );
  788. $sql->bindParam(1, $date,PDO::PARAM_STR);
  789. $sql->bindParam(2, $file_struct,PDO::PARAM_STR);
  790. $sql->bindParam(3, $file_data,PDO::PARAM_STR);
  791. $sql->bindParam(4, $file_full,PDO::PARAM_STR);
  792. $sql->bindParam(5, $file_update,PDO::PARAM_STR);
  793. $result = $sql->execute();
  794. $connection = ssh2_connect($_SERVER['SERVER_ADDR'], 22);
  795. if($connection && $result){
  796. $user = ssh2_auth_password($connection, 'root', 'esat2017');
  797. if($user){
  798. FichierMiseAJour();
  799. $output1 = ssh2_exec($connection,'pg_dump -U root --schema-only facture > /var/www/html/sauvegarde/file/SAUVEGARDE_STRUCTURE_'.$date_file.'.sql');
  800. $output2 = ssh2_exec($connection,'pg_dump -U root facture > /var/www/html/sauvegarde/file/SAUVEGARDE_COMPLETE_'.$date_file.'.sql');
  801. $output3 = ssh2_exec($connection,'pg_dump -U root --column-inserts --attribute-inserts --data-only --exclude-schema=schema facture > /var/www/html/sauvegarde/file/SAUVEGARDE_DATA_'.$date_file.'.sql');
  802. $output4 = ssh2_exec($connection,'exit');
  803. if($output1 && $output2 && $output3 && $output4){
  804. $req = null;
  805. $exec = true;
  806. }
  807. }
  808. }
  809. break;
  810. default:
  811. # code...
  812. break;
  813. }
  814.  
  815. if($req != null){
  816. $exec = $sql->execute();
  817. //print_r($sql->errorInfo());
  818. }
  819. }
  820. catch (PDOException $e) {
  821. return false;
  822. }
  823. if (!$exec) {
  824. return false;
  825. }
  826. return $exec;
  827. }
  828.  
  829. function Archiver($db,$table, $data){
  830. try {
  831. $req = null;
  832. $exec = false;
  833. $id = $data;
  834. switch ($table) {
  835. case 'intervention':
  836. $req = "UPDATE bon_de_livraison SET archive = 1 WHERE id = (SELECT bl.id FROM bon_de_livraison bl, interventions i1 WHERE (? = i1.id) AND (bl.id = i1.bon_de_livraison))";
  837. $sql= $db->prepare($req);
  838. $sql->bindParam(1, $id, PDO::PARAM_INT);
  839. $sql->execute();
  840. $req = "UPDATE interventions SET archive = 1 WHERE id = ?";
  841. $sql= $db->prepare($req);
  842. $sql->bindParam(1, $id, PDO::PARAM_INT);
  843. break;
  844. case 'bl':
  845. $req = "UPDATE interventions SET archive = 1 WHERE id = (SELECT i1.id FROM bon_de_livraison bl, interventions i1 WHERE (? = bl.id) AND (bl.id = i1.bon_de_livraison))";
  846. $sql= $db->prepare($req);
  847. $sql->bindParam(1, $id, PDO::PARAM_INT);
  848. $sql->execute();
  849.  
  850. $req = "UPDATE bon_de_livraison SET archive = 1 WHERE id = ?";
  851. $sql= $db->prepare($req);
  852. $sql->bindParam(1, $id, PDO::PARAM_INT);
  853. break;
  854. case 'facture':
  855. $req = "UPDATE factures SET archive = 1 WHERE id = ?";
  856. $sql= $db->prepare($req);
  857. $sql->bindParam(1, $id, PDO::PARAM_INT);
  858. break;
  859.  
  860.  
  861. default:
  862. # code...
  863. break;
  864. }
  865.  
  866. if($req != null){
  867. $exec = $sql->execute();
  868. }
  869. }
  870. catch (PDOException $e) {
  871. return false;
  872. }
  873. if (!$exec) {
  874. return false;
  875. }
  876. return $exec;
  877. }
  878.  
  879. function Desarchiver($db,$type,$data){
  880. try {
  881. $req = null;
  882. $exec = false;
  883. switch ($type) {
  884. case 'intervention':
  885. $req = "UPDATE interventions SET archive = 0 WHERE id = ?";
  886. break;
  887. case 'bl':
  888. $req = "UPDATE bon_de_livraison SET archive = 0 WHERE id = ?";
  889. break;
  890. case 'facture':
  891. $req = "UPDATE factures SET archive = 0 WHERE id = ?";
  892. break;
  893. default:
  894. break;
  895. }
  896.  
  897. if($req != null){
  898. $sql= $db->prepare($req);
  899. $sql->bindParam(1, $data, PDO::PARAM_INT);
  900. $exec = $sql->execute();
  901. $result = $sql->fetchAll(PDO::FETCH_NUM);
  902. }
  903.  
  904. }
  905. catch ( PDOException $e ) {
  906. return false;
  907. }
  908. if ( !$exec ) {
  909. return false;
  910. }
  911. return $exec;
  912. }
  913.  
  914. function Rechercher($db, $type, $data,$archive){
  915. try{
  916. $req = null;
  917. $select = $data[0];
  918. $value = $data[1];
  919. switch ($type) {
  920.  
  921. case 'stock':
  922. switch ($select) {
  923. case 'N°':
  924. $req = "SELECT id as N°, designation as Designation, quantite as Quantité, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 'N°,Designation,Quantité' as colonnes, 'stock' as type FROM stock WHERE id = ?;";
  925. break;
  926. case 'Designation':
  927. $req = "SELECT id as N°, designation as Designation, quantite as Quantité, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 'N°,Designation,Quantité' as colonnes, 'stock' as type FROM stock WHERE (REPLACE(UPPER(designation),' ','') LIKE ?) ";
  928. break;
  929. case 'Quantité':
  930. $req = "SELECT id as N°, designation as Designation, quantite as Quantité, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 'N°,Designation,Quantité' as colonnes, 'stock' as type FROM stock WHERE quantite = ?;";
  931. break;
  932. }
  933. break;
  934. case 'intervention':
  935. switch($select){
  936. case 'N°':
  937. $req = "SELECT i1.id as N°, i1.reference as Référence, i1.date_intervention as Date_Intervention, i1.lieu as Lieu, c1.nom as Client, i1.intervenant as Intervenant, b1.reference as Reference_BL,type_intervention as Type_Intervention, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 1 as Archiver, 0 as Desarchiver , 'N°,Référence,Date_Intervention,Lieu,Client,Intervenant,Reference_BL,Type_Intervention' as colonnes, 'intervention' as type FROM interventions i1,clients c1,bon_de_livraison b1 WHERE (i1.id = ?) AND (i1.archive = ?) AND (i1.client = c1.id) AND (i1.bon_de_livraison = b1.id);";
  938. break;
  939. case 'Référence':
  940. $req = "SELECT i1.id as N°, i1.reference as Référence, i1.date_intervention as Date_Intervention, i1.lieu as Lieu, c1.nom as Client, i1.intervenant as Intervenant, b1.reference as Reference_BL,type_intervention as Type_Intervention, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 1 as Archiver, 0 as Desarchiver , 'N°,Référence,Date_Intervention,Lieu,Client,Intervenant,Reference_BL,Type_Intervention' as colonnes, 'intervention' as type FROM interventions i1,clients c1,bon_de_livraison b1 WHERE (REPLACE(UPPER(i1.reference),' ','') LIKE ?) AND (i1.archive = ?) AND (i1.client = c1.id) AND (b1.id = i1.bon_de_livraison);";
  941. break;
  942. case 'Date_Intervention':
  943. $req = "SELECT i1.id as N°, i1.reference as Référence, i1.date_intervention as Date_Intervention, i1.lieu as Lieu, c1.nom as Client, i1.intervenant as Intervenant, b1.reference as Reference_BL,type_intervention as Type_Intervention, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 1 as Archiver, 0 as Desarchiver , 'N°,Référence,Date_Intervention,Lieu,Client,Intervenant,Reference_BL,Type_Intervention' as colonnes, 'intervention' as type FROM interventions i1,clients c1,bon_de_livraison b1 WHERE (i1.date_intervention = ?) AND (i1.archive = ?) AND (i1.client = c1.id) AND (b1.id = i1.bon_de_livraison);";
  944. # code...
  945. break;
  946. case 'Client':
  947. $req = "SELECT i1.id as N°, i1.reference as Référence, i1.date_intervention as Date_Intervention, i1.lieu as Lieu, c1.nom as Client, i1.intervenant as Intervenant, b1.reference as Reference_BL,type_intervention as Type_Intervention, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 1 as Archiver, 0 as Desarchiver , 'N°,Référence,Date_Intervention,Lieu,Client,Intervenant,Reference_BL,Type_Intervention' as colonnes, 'intervention' as type FROM interventions i1,clients c1,bon_de_livraison b1 WHERE (REPLACE(UPPER(c1.nom),' ','') LIKE ?) AND (i1.archive = ?) AND (i1.client = c1.id) AND (b1.id = i1.bon_de_livraison);";
  948. # code...
  949. break;
  950. case 'Lieu':
  951. $req = "SELECT i1.id as N°, i1.reference as Référence, i1.date_intervention as Date_Intervention, i1.lieu as Lieu, c1.nom as Client, i1.intervenant as Intervenant, b1.reference as Reference_BL,type_intervention as Type_Intervention, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 1 as Archiver, 0 as Desarchiver , 'N°,Référence,Date_Intervention,Lieu,Client,Intervenant,Reference_BL,Type_Intervention' as colonnes, 'intervention' as type FROM interventions i1,clients c1,bon_de_livraison b1 WHERE (REPLACE(UPPER(i1.lieu),' ','') LIKE ?) AND (i1.archive = ?) AND (i1.client = c1.id) AND (b1.id = i1.bon_de_livraison);";
  952. # code...
  953. break;
  954. case 'Reference_BL':
  955. $req = "SELECT i1.id as N°, i1.reference as Référence, i1.date_intervention as Date_Intervention, i1.lieu as Lieu, c1.nom as Client, i1.intervenant as Intervenant, b1.reference as Reference_BL,type_intervention as Type_Intervention, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 1 as Archiver, 0 as Desarchiver , 'N°,Référence,Date_Intervention,Lieu,Client,Intervenant,Reference_BL,Type_Intervention' as colonnes, 'intervention' as type FROM interventions i1,clients c1,bon_de_livraison b1 WHERE (REPLACE(UPPER(b1.reference),' ','') LIKE ?) AND (i1.archive = ?) AND (i1.client = c1.id) AND (b1.id = i1.bon_de_livraison);";
  956. break;
  957. case 'Intervenant':
  958. $req = "SELECT i1.id as N°, i1.reference as Référence, i1.date_intervention as Date_Intervention, i1.lieu as Lieu, c1.nom as Client, i1.intervenant as Intervenant, b1.reference as Reference_BL,type_intervention as Type_Intervention, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 1 as Archiver, 0 as Desarchiver , 'N°,Référence,Date_Intervention,Lieu,Client,Intervenant,Reference_BL,Type_Intervention' as colonnes, 'intervention' as type FROM interventions i1,clients c1,bon_de_livraison b1 WHERE (REPLACE(UPPER(i1.intervenant),' ','') LIKE ?) AND (i1.archive = ?) AND (i1.client = c1.id) AND (b1.id = i1.bon_de_livraison);";
  959. # code...
  960. case 'Type_intervention':
  961. $req = "SELECT i1.id as N°, i1.reference as Référence, i1.date_intervention as Date_Intervention, i1.lieu as Lieu, c1.nom as Client, i1.intervenant as Intervenant, b1.reference as Reference_BL,type_intervention as Type_Intervention, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 1 as Archiver, 0 as Desarchiver , 'N°,Référence,Date_Intervention,Lieu,Client,Intervenant,Reference_BL,Type_Intervention' as colonnes, 'intervention' as type FROM interventions i1,clients c1,bon_de_livraison b1 WHERE (REPLACE(UPPER(i1.type_intervention),' ','') LIKE ?) AND (i1.archive = ?) AND (i1.client = c1.id) AND (b1.id = i1.bon_de_livraison);";
  962. break;
  963. }
  964. break;
  965. case 'client':
  966. switch ($select) {
  967. case 'N°':
  968. $req = "SELECT id as N°, nom as Nom, complement as Complément, responsable as Responsable, adresse as Adresse, code_postale as Code_Postale, ville as Ville, telephone as Telephone, fax as Fax, mail as Mail, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 'N°,Nom,Complément,Responsable,Adresse,Code_Postale,Ville,Telephone,Fax,Mail' as colonnes, 'client' as type FROM clients WHERE id = ?";
  969. # code...
  970. break;
  971. case 'Nom':
  972. $req = "SELECT id as N°, nom as Nom, complement as Complément, responsable as Responsable, adresse as Adresse, code_postale as Code_Postale, ville as Ville, telephone as Telephone, fax as Fax, mail as Mail, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 'N°,Nom,Complément,Responsable,Adresse,Code_Postale,Ville,Telephone,Fax,Mail' as colonnes, 'client' as type FROM clients WHERE (REPLACE(UPPER(nom),' ','') LIKE ?)";
  973. # code...
  974. break;
  975. case 'Complément':
  976. $req = "SELECT id as N°, nom as Nom, complement as Complément, responsable as Responsable, adresse as Adresse, code_postale as Code_Postale, ville as Ville, telephone as Telephone, fax as Fax, mail as Mail, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 'N°,Nom,Complément,Responsable,Adresse,Code_Postale,Ville,Telephone,Fax,Mail' as colonnes, 'client' as type FROM clients WHERE (REPLACE(UPPER(complement),' ','') LIKE ?)";
  977. # code...
  978. break;
  979. case 'Responsable':
  980. $req = "SELECT id as N°, nom as Nom, complement as Complément, responsable as Responsable, adresse as Adresse, code_postale as Code_Postale, ville as Ville, telephone as Telephone, fax as Fax, mail as Mail, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 'N°,Nom,Complément,Responsable,Adresse,Code_Postale,Ville,Telephone,Fax,Mail' as colonnes, 'client' as type FROM clients WHERE (REPLACE(UPPER(responsable),' ','') LIKE ?)";
  981. # code...
  982. break;
  983. case 'Adresse':
  984. $req = "SELECT id as N°, nom as Nom, complement as Complément, responsable as Responsable, adresse as Adresse, code_postale as Code_Postale, ville as Ville, telephone as Telephone, fax as Fax, mail as Mail, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 'N°,Nom,Complément,Responsable,Adresse,Code_Postale,Ville,Telephone,Fax,Mail' as colonnes, 'client' as type FROM clients WHERE (REPLACE(UPPER(adresse),' ','') LIKE ?)";
  985. # code...
  986. break;
  987. case 'Code_Postale':
  988. $req = "SELECT id as N°, nom as Nom, complement as Complément, responsable as Responsable, adresse as Adresse, code_postale as Code_Postale, ville as Ville, telephone as Telephone, fax as Fax, mail as Mail, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 'N°,Nom,Complément,Responsable,Adresse,Code_Postale,Ville,Telephone,Fax,Mail' as colonnes, 'client' as type FROM clients WHERE (REPLACE(UPPER(code_postale),' ','') LIKE ?)";
  989. # code...
  990. break;
  991. case 'Ville':
  992. $req = "SELECT id as N°, nom as Nom, complement as Complément, responsable as Responsable, adresse as Adresse, code_postale as Code_Postale, ville as Ville, telephone as Telephone, fax as Fax, mail as Mail, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 'N°,Nom,Complément,Responsable,Adresse,Code_Postale,Ville,Telephone,Fax,Mail' as colonnes, 'client' as type FROM clients WHERE (REPLACE(UPPER(ville),' ','') LIKE ?)";
  993. # code...
  994. break;
  995. case 'Telephone':
  996. $req = "SELECT id as N°, nom as Nom, complement as Complément, responsable as Responsable, adresse as Adresse, code_postale as Code_Postale, ville as Ville, telephone as Telephone, fax as Fax, mail as Mail, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 'N°,Nom,Complément,Responsable,Adresse,Code_Postale,Ville,Telephone,Fax,Mail' as colonnes, 'client' as type FROM clients WHERE (REPLACE(UPPER(telephone),' ','') LIKE ?)";
  997. # code...
  998. break;
  999. case 'Fax':
  1000. $req = "SELECT id as N°, nom as Nom, complement as Complément, responsable as Responsable, adresse as Adresse, code_postale as Code_Postale, ville as Ville, telephone as Telephone, fax as Fax, mail as Mail, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 'N°,Nom,Complément,Responsable,Adresse,Code_Postale,Ville,Telephone,Fax,Mail' as colonnes, 'client' as type FROM clients WHERE (REPLACE(UPPER(fax),' ','') LIKE ?)";
  1001. # code...
  1002. break;
  1003. case 'Mail':
  1004. $req = "SELECT id as N°, nom as Nom, complement as Complément, responsable as Responsable, adresse as Adresse, code_postale as Code_Postale, ville as Ville, telephone as Telephone, fax as Fax, mail as Mail, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 'N°,Nom,Complément,Responsable,Adresse,Code_Postale,Ville,Telephone,Fax,Mail' as colonnes, 'client' as type FROM clients WHERE (REPLACE(UPPER(mail),' ','') LIKE ?)";
  1005. # code...
  1006. break;
  1007. default:
  1008. # code...
  1009. break;
  1010. }
  1011. break;
  1012. case 'bl':
  1013. switch($select){
  1014. case 'N°':
  1015. $req = "SELECT bon.id as N°, bon.reference as Référence,cli.nom as Client,bon.date_expedition as Date_expedition,bon.date_facturation as Date_de_facturation,bon.adresse_facturation as Adresse_Facturation, bon.redacteur as Redacteur,type_bl AS Type_de_BL, 1 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 1 as Archiver, 0 as Desarchiver ,1 as PDF, 'N°,Référence,Client,Date_expedition,Date_de_facturation,Adresse_Facturation,Redacteur,Type_de_BL' as colonnes, 'bl' as type FROM bon_de_livraison bon, clients cli WHERE (bon.client = cli.id) AND (bon.id = ?) AND (bon.archive = ?)";
  1016. break;
  1017. case 'Référence':
  1018. $req = "SELECT bon.id as N°, bon.reference as Référence,cli.nom as Client,bon.date_expedition as Date_expedition,bon.date_facturation as Date_de_facturation,bon.adresse_facturation as Adresse_Facturation, bon.redacteur as Redacteur, type_bl AS Type_de_BL,1 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 1 as Archiver, 0 as Desarchiver ,1 as PDF, 'N°,Référence,Client,Date_expedition,Date_de_facturation,Adresse_Facturation,Redacteur,Type_de_BL' as colonnes, 'bl' as type FROM bon_de_livraison bon, clients cli WHERE (bon.client = cli.id) AND (REPLACE(UPPER(bon.reference),' ','') LIKE ?) AND (bon.archive = ?)";
  1019. break;
  1020. case 'Client':
  1021. $req = "SELECT bon.id as N°, bon.reference as Référence,cli.nom as Client,bon.date_expedition as Date_expedition,bon.date_facturation as Date_de_facturation,bon.adresse_facturation as Adresse_Facturation, bon.redacteur as Redacteur,type_bl AS Type_de_BL, 1 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 1 as Archiver, 0 as Desarchiver ,1 as PDF, 'N°,Référence,Client,Date_expedition,Date_de_facturation,Adresse_Facturation,Redacteur,Type_de_BL' as colonnes, 'bl' as type FROM bon_de_livraison bon, clients cli WHERE (bon.client = cli.id) AND (REPLACE(UPPER(cli.nom),' ','') LIKE ?) AND (bon.archive = ?)";
  1022. break;
  1023. case 'Date_expedition':
  1024. $req = "SELECT bon.id as N°, bon.reference as Référence,cli.nom as Client,bon.date_expedition as Date_expedition,bon.date_facturation as Date_de_facturation,bon.adresse_facturation as Adresse_Facturation, bon.redacteur as Redacteur,type_bl AS Type_de_BL, 1 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 1 as Archiver, 0 as Desarchiver ,1 as PDF, 'N°,Référence,Client,Date_expedition,Date_de_facturation,Adresse_Facturation,Redacteur,Type_de_BL' as colonnes, 'bl' as type FROM bon_de_livraison bon, clients cli WHERE (bon.client = cli.id) AND (bon.date_expedition = ?) AND (bon.archive = ?)";
  1025. break;
  1026. case 'Date_de_facturation':
  1027. $req = "SELECT bon.id as N°, bon.reference as Référence,cli.nom as Client,bon.date_expedition as Date_expedition,bon.date_facturation as Date_de_facturation,bon.adresse_facturation as Adresse_Facturation, bon.redacteur as Redacteur,type_bl AS Type_de_BL, 1 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 1 as Archiver, 0 as Desarchiver ,1 as PDF, 'N°,Référence,Client,Date_expedition,Date_de_facturation,Adresse_Facturation,Redacteur,Type_de_BL' as colonnes, 'bl' as type FROM bon_de_livraison bon, clients cli WHERE (bon.client = cli.id) AND (bon.date_facturation = ?) AND (bon.archive = ?)";
  1028. break;
  1029. case 'adresse_Facturation':
  1030. $req = "SELECT bon.id as N°, bon.reference as Référence,cli.nom as Client,bon.date_expedition as Date_expedition,bon.date_facturation as Date_de_facturation,bon.adresse_facturation as Adresse_Facturation, bon.redacteur as Redacteur,type_bl AS Type_de_BL, 1 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 1 as Archiver, 0 as Desarchiver ,1 as PDF, 'N°,Référence,Client,Date_expedition,Date_de_facturation,Adresse_Facturation,Redacteur,Type_de_BL' as colonnes, 'bl' as type FROM bon_de_livraison bon, clients cli WHERE (bon.client = cli.id) AND (REPLACE(UPPER(bon.adresse_facturation),' ','') = ?) AND (bon.archive = ?)";
  1031. break;
  1032. case 'Redacteur':
  1033. $req = "SELECT bon.id as N°, bon.reference as Référence,cli.nom as Client,bon.date_expedition as Date_expedition,bon.date_facturation as Date_de_facturation,bon.adresse_facturation as Adresse_Facturation, bon.redacteur as Redacteur,type_bl AS Type_de_BL, 1 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 1 as Archiver, 0 as Desarchiver ,1 as PDF, 'N°,Référence,Client,Date_expedition,Date_de_facturation,Adresse_Facturation,Redacteur,Type_de_BL' as colonnes, 'bl' as type FROM bon_de_livraison bon, clients cli WHERE (bon.client = cli.id) AND (REPLACE(UPPER(bon.redacteur),' ','') LIKE ?) AND (bon.archive = ?)";
  1034. break;
  1035. case 'Lieu Intervention':
  1036. $req = "SELECT bon.id as N°, bon.reference as Référence,cli.nom as Client,bon.date_expedition as Date_expedition,bon.date_facturation as Date_de_facturation,bon.adresse_facturation as Adresse_Facturation, bon.redacteur as Redacteur,type_bl AS Type_de_BL, 1 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 1 as Archiver, 0 as Desarchiver ,1 as PDF, 'N°,Référence,Client,Date_expedition,Date_de_facturation,Adresse_Facturation,Redacteur,Type_de_BL' as colonnes, 'bl' as type FROM bon_de_livraison bon, clients cli WHERE (bon.client = cli.id) AND (REPLACE(UPPER(bon.lieu_intervention),' ','') LIKE ?) AND (bon.archive = ?)";
  1037. # code...
  1038. break;
  1039. case 'Type_de_BL':
  1040. $req = "SELECT bon.id as N°, bon.reference as Référence,cli.nom as Client,bon.date_expedition as Date_expedition,bon.date_facturation as Date_de_facturation,bon.adresse_facturation as Adresse_Facturation, bon.redacteur as Redacteur,type_bl AS Type_de_BL, 1 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 1 as Archiver, 0 as Desarchiver , 'N°,Référence,Client,Date_expedition,Date_de_facturation,Adresse_Facturation,Redacteur,Type_de_BL' as colonnes, 'bl' as type FROM bon_de_livraison bon, clients cli WHERE (bon.client = cli.id) AND (REPLACE(UPPER(bon.type_bl),' ','') LIKE ?) AND (bon.archive = ?)";
  1041. #code...
  1042. break;
  1043. }
  1044. break;
  1045. case 'facture':
  1046. switch($select){
  1047. case 'N°':
  1048. $req = "SELECT factures.id as N°, factures.reference as Référence, clients.nom as Client, factures.date_debut as Debut_Facturation,factures.date_fin as Fin_Facturation, factures.date_echeance as Date_Echeance, 1 as Visualiser, 1 as Modifier, 1 as Supprimer, 1 as Dissocier, 1 as Archiver, 0 as Desarchiver, 1 as PDF ,'N°,Référence,Client,Debut_Facturation,Fin_Facturation,Date_Echeance' as colonnes, 'facture' as type from factures, clients WHERE (factures.paye = 0) AND (clients.id = factures.client) AND (factures.id = ?) AND (factures.archive = ?)";
  1049. break;
  1050. case 'Référence':
  1051. $req = "SELECT factures.id as N°, factures.reference as Référence, clients.nom as Client, factures.date_debut as Debut_Facturation,factures.date_fin as Fin_Facturation, factures.date_echeance as Date_Echeance, 1 as Visualiser, 1 as Modifier, 1 as Supprimer, 1 as Dissocier, 1 as Archiver, 0 as Desarchiver, 1 as PDF ,'N°,Référence,Client,Debut_Facturation,Fin_Facturation,Date_Echeance' as colonnes, 'facture' as type from factures, clients WHERE (factures.paye = 0) AND (clients.id = factures.client) AND ((REPLACE(UPPER(factures.reference),' ','')) LIKE ?) AND (factures.archive = ?)";
  1052. break;
  1053. case 'Client':
  1054. $req = "SELECT factures.id as N°, factures.reference as Référence, clients.nom as Client, factures.date_debut as Debut_Facturation,factures.date_fin as Fin_Facturation, factures.date_echeance as Date_Echeance, 1 as Visualiser, 1 as Modifier, 1 as Supprimer, 1 as Dissocier, 1 as Archiver, 0 as Desarchiver, 1 as PDF ,'N°,Référence,Client,Debut_Facturation,Fin_Facturation,Date_Echeance' as colonnes, 'facture' as type from factures, clients WHERE (factures.paye = 0) AND (clients.id = factures.client) AND ((REPLACE(UPPER(clients.nom),' ','')) LIKE ?) AND (factures.archive = ?)";
  1055. break;
  1056. case 'Debut_Facturation':
  1057. $req = "SELECT factures.id as N°, factures.reference as Référence, clients.nom as Client, factures.date_debut as Debut_Facturation,factures.date_fin as Fin_Facturation, factures.date_echeance as Date_Echeance, 1 as Visualiser, 1 as Modifier, 1 as Supprimer, 1 as Dissocier, 1 as Archiver, 0 as Desarchiver, 1 as PDF ,'N°,Référence,Client,Debut_Facturation,Fin_Facturation,Date_Echeance' as colonnes, 'facture' as type from factures, clients WHERE (factures.paye = 0) AND (clients.id = factures.client) AND (factures.date_debut = ?) AND (factures.archive = ?)";
  1058. # code...
  1059. break;
  1060. case 'Fin_Facturation':
  1061. $req = "SELECT factures.id as N°, factures.reference as Référence, clients.nom as Client, factures.date_debut as Debut_Facturation,factures.date_fin as Fin_Facturation, factures.date_echeance as Date_Echeance, 1 as Visualiser, 1 as Modifier, 1 as Supprimer, 1 as Dissocier, 1 as Archiver, 0 as Desarchiver, 1 as PDF ,'N°,Référence,Client,Debut_Facturation,Fin_Facturation,Date_Echeance' as colonnes, 'facture' as type from factures, clients WHERE (factures.paye = 0) AND (clients.id = factures.client) AND (factures.date_fin = ?) AND (factures.archive = ?)";
  1062. # code...
  1063. break;
  1064. case 'Date_Echeance':
  1065. $req = "SELECT factures.id as N°, factures.reference as Référence, clients.nom as Client, factures.date_debut as Debut_Facturation,factures.date_fin as Fin_Facturation, factures.date_echeance as Date_Echeance, 1 as Visualiser, 1 as Modifier, 1 as Supprimer, 1 as Dissocier, 1 as Archiver, 0 as Desarchiver , 1 as PDF ,'N°,Référence,Client,Debut_Facturation,Fin_Facturation,Date_Echeance' as colonnes, 'facture' as type from factures, clients WHERE (factures.paye = 0) AND (clients.id = factures.client) AND (factures.date_echeance = ?) AND (factures.archive = ?)";
  1066. break;
  1067. }
  1068. break;
  1069. case 'prestation':
  1070. switch ($select) {
  1071. case 'N°':
  1072. $req = "SELECT produit.id as N°, produit.denomination as denomination, categorie.denomination as categorie, produit.prix as prix, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 'N°,Denomination,Categorie,Prix' as colonnes, 'prestation' as type FROM articles_tarification_laposte produit, categorie_tarification_laposte categorie WHERE (produit.categorie_tarification = categorie.id) AND (produit.id = ?)";
  1073. # code...
  1074. break;
  1075. case 'Denomination':
  1076. $req = "SELECT produit.id as N°, produit.denomination as denomination, categorie.denomination as categorie, produit.prix as prix, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 'N°,Denomination,Categorie,Prix' as colonnes, 'prestation' as type FROM articles_tarification_laposte produit, categorie_tarification_laposte categorie WHERE (produit.categorie_tarification = categorie.id) AND ((REPLACE(UPPER(produit.denomination),' ','')) LIKE ?)";
  1077. # code...
  1078. break;
  1079. case 'Categorie':
  1080. $req = "SELECT produit.id as N°, produit.denomination as denomination, categorie.denomination as categorie, produit.prix as prix, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 'N°,Denomination,Categorie,Prix' as colonnes, 'prestation' as type FROM articles_tarification_laposte produit, categorie_tarification_laposte categorie WHERE (produit.categorie_tarification = categorie.id) AND ((REPLACE(UPPER(categorie.denomination),' ','')) LIKE ?)";
  1081. # code...
  1082. break;
  1083. case 'Prix':
  1084. $req = "SELECT produit.id as N°, produit.denomination as denomination, categorie.denomination as categorie, produit.prix as prix, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 'N°,Denomination,Categorie,Prix' as colonnes, 'prestation' as type FROM articles_tarification_laposte produit, categorie_tarification_laposte categorie WHERE (produit.categorie_tarification = categorie.id) AND (produit.prix = ?)";
  1085. # code...
  1086. break;
  1087. default:
  1088. # code...
  1089. break;
  1090. }
  1091. # code...
  1092. break;
  1093. case 'categorie':
  1094. switch ($select) {
  1095. case 'N°':
  1096. $req = "SELECT id as N°, denomination as denomination, categorie_tarification_laposte.type as Classification, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 'categorie' as type,'N°,Denomination,Classification' as colonnes FROM categorie_tarification_laposte WHERE id = ?";
  1097. # code...
  1098. break;
  1099. case 'Denomination':
  1100. $req = "SELECT id as N°, denomination as denomination, categorie_tarification_laposte.type as Classification, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 'categorie' as type, 'N°,Denomination,Classification' as colonnes FROM categorie_tarification_laposte WHERE ((REPLACE(UPPER(denomination),' ','')) LIKE ?)";
  1101. # code...
  1102. break;
  1103. case 'Type':
  1104. $req = "SELECT id as N°, denomination as denomination, categorie_tarification_laposte.type as Classification, 0 as Visualiser, 1 as Modifier, 1 as Supprimer, 0 as Dissocier, 0 as Archiver, 'categorie' as type, 'N°,Denomination,Classification' as colonnes FROM categorie_tarification_laposte WHERE ((REPLACE(UPPER(type),' ','')) LIKE ?)";
  1105. # code...
  1106. break;
  1107. default:
  1108. # code...
  1109. break;
  1110. }
  1111. # code...
  1112. break;
  1113. case 'aide':
  1114. switch ($select) {
  1115. case 'N°':
  1116. $req = "SELECT id as N°, titre as Titre, tag as Tag, contenu as Contenu, 'N°,Titre,Tag,Contenu' as colonnes,1 as Modifier,1 as Supprimer,'aide' as type FROM aide WHERE id = ?";
  1117. break;
  1118. case 'Titre':
  1119. $req = "SELECT id as N°, titre as Titre, tag as Tag, contenu as Contenu, 'N°,Titre,Tag,Contenu' as colonnes,1 as Modifier,1 as Supprimer,'aide' as type FROM aide WHERE ((REPLACE(UPPER(titre),' ','')) LIKE ?)";
  1120. break;
  1121. case 'Tag':
  1122. $req = "SELECT id as N°, titre as Titre, tag as Tag, contenu as Contenu, 'N°,Titre,Tag,Contenu' as colonnes,1 as Modifier,1 as Supprimer,'aide' as type FROM aide WHERE ((REPLACE(UPPER(tag),' ','')) LIKE ?)";
  1123. break;
  1124. case 'Contenu':
  1125. $req = "SELECT id as N°, titre as Titre, tag as Tag, contenu as Contenu, 'N°,Titre,Tag,Contenu' as colonnes,1 as Modifier,1 as Supprimer,'aide' as type FROM aide WHERE ((REPLACE(UPPER(contenu),' ','')) LIKE ?)";
  1126. break;
  1127. }
  1128. break;
  1129. default:
  1130. # code...
  1131. break;
  1132. }
  1133. if($req != null){
  1134. $sql = $db->prepare($req);
  1135. if( ($select != "N°") && ($select != "Quantité") && ($select != "Prix") ){
  1136. $value = str_replace(" ","",mb_strtoupper('%'.$value.'%'));
  1137. $sql->bindParam(1, $value, PDO::PARAM_STR);
  1138. }else{
  1139. $sql->bindParam(1, $value, PDO::PARAM_INT);
  1140. }
  1141. if( ($type == "bl") || ($type == "facture") || ($type == "intervention") ){
  1142. $sql->bindParam(2, $archive, PDO::PARAM_INT);
  1143. }
  1144. $exec = $sql->execute();
  1145. $result = $sql->fetchAll(PDO::FETCH_ASSOC);
  1146. }else{
  1147. $exec = false;
  1148. }
  1149. }catch ( PDOException $e ) {
  1150. return false;
  1151. }
  1152. if ( !$exec ) {
  1153. return false;
  1154. }
  1155. return $result;
  1156. }
  1157.  
  1158. function Analyse($db,$table,$data){
  1159. try {
  1160. $req = null;
  1161. $exec = false;
  1162. switch ($table) {
  1163. case 'Excel1':
  1164. $req = "SELECT b.date_expedition as Date, b.reference as Reference, b.lieu_intervention as lieu_intervention, ROUND(SUM(p.quantite*a.prix),2) as prix, type_bl FROM bon_de_livraison as b, articles_tarification_laposte as a, produit_et_travaux as p WHERE (b.reference = p.reference_bon_de_livraison) AND (p.designation = a.id) AND (b.archive = 1) AND (b.date_expedition BETWEEN ? AND ?) AND ( (b.type_bl = 'HORS_CIDEX') OR (b.type_bl = 'CIDEX'))GROUP BY b.reference,b.lieu_intervention,b.date_expedition,b.type_bl ORDER BY b.date_expedition;";
  1165. $sql = $db->prepare($req);
  1166. $sql->bindParam(1,$data[0],PDO::PARAM_STR);
  1167. $sql->bindParam(2,$data[1],PDO::PARAM_STR);
  1168. break;
  1169. case 'Excel2':
  1170. $req = "(SELECT EXTRACT(year from bl.date_expedition) as year, EXTRACT(month from bl.date_expedition) as month, 'POSTE' as client, SUM(tarif.prix*pt.quantite) as Prix, type_bl as type FROM articles_tarification_laposte as tarif, bon_de_livraison as bl,clients, produit_et_travaux as pt WHERE (pt.reference_bon_de_livraison = bl.reference) AND (pt.designation = tarif.id) AND (bl.client = clients.id) AND (bl.archive = 1) AND ((REPLACE(UPPER(clients.nom),' ','')) LIKE '%POSTE%') GROUP BY month,type,year) UNION (SELECT EXTRACT(year from bl.date_expedition) as year, EXTRACT(month from bl.date_expedition) as month, 'AUTRES_CLIENTS' as client, SUM(tarif.prix*pt.quantite) as Prix, type_bl as type FROM articles_tarification_laposte as tarif, bon_de_livraison as bl,clients, produit_et_travaux as pt WHERE (pt.reference_bon_de_livraison = bl.reference) AND (pt.designation = tarif.id) AND (bl.client = clients.id) AND (bl.archive = 1) AND ((REPLACE(UPPER(clients.nom),' ','')) NOT LIKE '%POSTE%') GROUP BY month,type,year);";
  1171. $sql = $db->prepare($req);
  1172.  
  1173. break;
  1174. default:
  1175. # code...
  1176. break;
  1177. }
  1178.  
  1179. if($req != null){
  1180. $exec = $sql->execute();
  1181. // print_r($sql->errorInfo());
  1182. $result = $sql->fetchAll(PDO::FETCH_ASSOC);
  1183. }
  1184. }
  1185. catch (PDOException $e) {
  1186. return false;
  1187. }
  1188. if (!$exec) {
  1189. return false;
  1190. }
  1191. return $result;
  1192. }
  1193.  
  1194. function FichierMiseAJour(){
  1195. $db = connexion();
  1196. //$req = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'";
  1197. //$sql = $db->prepare($req);
  1198. //$exec = $sql->execute();
  1199. //$table = $sql->fetchAll(PDO::FETCH_ASSOC);
  1200.  
  1201. $table = array(0 => 'clients',1 => 'interventions',2 => 'bon_de_livraison',3 => 'categorie_tarification_laposte',4 => 'utilisateur',5 => 'configuration',6 => 'articles_tarification_laposte',7 => 'produit_et_travaux',8 => 'stock',9 => 'sauvegarde',10 => 'facture');
  1202.  
  1203. //var_dump($table);
  1204. $date_file = date('Y_m_d_H_i_s');
  1205. $myfile = fopen("../sauvegarde/file/MISE_A_JOUR_".$date_file.".sql", "w") or die(json_encode(false));
  1206.  
  1207. $ref = "";
  1208. $update = "";
  1209. $insert = "";
  1210. for($i = 0; $i < sizeof($table) ; $i++){
  1211. $req = "SELECT column_name FROM information_schema.columns WHERE table_schema = 'public' AND table_name= '".$table[$i]."'";
  1212. $sql = $db->prepare($req);
  1213. $exec = $sql->execute();
  1214. $column = $sql->fetchAll(PDO::FETCH_ASSOC);
  1215. //var_dump($column);
  1216. $req = "SELECT * FROM ".$table[$i]." ORDER BY id";
  1217. $sql = $db->prepare($req);
  1218. $exec = $sql->execute();
  1219. $result = $sql->fetchAll(PDO::FETCH_ASSOC);
  1220. //var_dump($result);
  1221. // INSERT INTO articles_tarification_laposte (id, denomination, categorie_tarification, prix) VALUES (1, 'CIDEX B1', 1, 8.49);
  1222.  
  1223. /* INSERT */
  1224. for($k = 0; $k < sizeof($result) ; $k++){
  1225. if(sizeof($result[$k]) > 0){
  1226. $ref = "INSERT INTO ".$table[$i]." ( ";
  1227. $pre = "INSERT INTO ".$table[$i]." ( ";
  1228. $post = "(";
  1229. for($j = 0; $j < sizeof($column); $j++){
  1230. $pre .= $column[$j]['column_name'].",";
  1231. $type = gettype($result[$k][$column[$j]['column_name']]);
  1232. if($type = 'string'){
  1233. $post .= "'".str_replace("'","'' ",$result[$k][$column[$j]['column_name']])."' ,";
  1234. }else{
  1235. $post .= $result[$k][$column[$j]['column_name']]." ,";
  1236. }
  1237. }
  1238. $pre = rtrim($pre,", ");
  1239. $post = rtrim($post,", ");
  1240. $pre .= ")";
  1241. $post .= ");";
  1242.  
  1243. if($insert != $ref){
  1244. $insert .= $pre." VALUES ".$post."\n";
  1245. }
  1246. }
  1247. }
  1248. /* UPDATE */
  1249. for($k = 0; $k < sizeof($result) ; $k++){
  1250. if(sizeof($result[$k]) > 0){
  1251. $ref = "UPDATE ".$table[$i]." SET ";
  1252. $update .= "UPDATE ".$table[$i]." SET ";
  1253. for($j = 0; $j < sizeof($column); $j++){
  1254. if(($column[$j]['column_name'] != 'id') && ($column[$j]['column_name'] != 'facture')){
  1255. $type = gettype($result[$k][$column[$j]['column_name']]);
  1256. if($type = 'string'){
  1257. $update .= $column[$j]['column_name']." = '".str_replace("'","'' ",$result[$k][$column[$j]['column_name']])."' ,";
  1258. }else{
  1259. $update .= $column[$j]['column_name']." = ".$result[$k][$column[$j]['column_name']]." ,";
  1260. }
  1261. }
  1262. }
  1263. $update = rtrim($update,", ");
  1264. if($update != $ref){
  1265. $update .= " WHERE id = ".$result[$k]['id'].";\n";
  1266. }
  1267. }
  1268. }
  1269.  
  1270.  
  1271. }
  1272.  
  1273. if($update != $ref){
  1274. fwrite($myfile, $insert);
  1275. fwrite($myfile, $update);
  1276. }
  1277. fclose($myfile);
  1278. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement