PageRenderTime 54ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/cashdesk/facturation_dhtml.php

https://github.com/asterix14/dolibarr
PHP | 109 lines | 67 code | 14 blank | 28 comment | 16 complexity | 010a9eafdf34c1a006fce4c8c34eacf0 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2007-2008 Jeremie Ollivier <jeremie.o@laposte.net>
  3. * Copyright (C) 2008-2009 Laurent Destailleur <eldy@uers.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * This page is called each time we press a key in the code
  20. * search form to show product combo list.
  21. */
  22. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1');
  23. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1');
  24. if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
  25. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
  26. if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1');
  27. if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1');
  28. if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
  29. if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
  30. if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
  31. //if (! defined("NOLOGIN")) define("NOLOGIN",'1');
  32. // Change this following line to use the correct relative path (../, ../../, etc)
  33. require("../main.inc.php");
  34. require_once(DOL_DOCUMENT_ROOT.'/cashdesk/include/environnement.php');
  35. //header("Content-type: text/html; charset=UTF-8");
  36. header("Content-type: text/html; charset=".$conf->file->character_set_client);
  37. // Search from criteria
  38. if (dol_strlen($_GET["code"]) >= 0) // If search criteria is on char length at least
  39. {
  40. $sql = "SELECT p.rowid, p.ref, p.label, p.tva_tx";
  41. if ($conf->stock->enabled && !empty($conf_fkentrepot)) $sql.= ", ps.reel";
  42. $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
  43. if ($conf->stock->enabled && !empty($conf_fkentrepot)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON p.rowid = ps.fk_product AND ps.fk_entrepot = '".$conf_fkentrepot."'";
  44. $sql.= " WHERE p.tosell = 1";
  45. $sql.= " AND p.fk_product_type = 0";
  46. // Add criteria on ref/label
  47. if (! empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE))
  48. {
  49. $sql.= " AND (p.ref LIKE '".$_GET['code']."%' OR p.label LIKE '".$_GET['code']."%')";
  50. }
  51. else
  52. {
  53. $sql.= " AND (p.ref LIKE '%".$_GET['code']."%' OR p.label LIKE '%".$_GET['code']."%')";
  54. }
  55. $sql.= " ORDER BY label";
  56. dol_syslog("facturation_dhtml.php sql=".$sql);
  57. $result = $db->query($sql);
  58. if ($result)
  59. {
  60. if ( $nbr = $db->num_rows($result) )
  61. {
  62. $resultat = '<ul class="dhtml_bloc">';
  63. $ret=array(); $i=0;
  64. while ( $tab = $db->fetch_array($result) )
  65. {
  66. foreach ( $tab as $cle => $valeur )
  67. {
  68. $ret[$i][$cle] = $valeur;
  69. }
  70. $i++;
  71. }
  72. $tab=$ret;
  73. $tab_size=count($tab);
  74. for($i=0;$i < $tab_size;$i++)
  75. {
  76. $resultat .= '
  77. <li class="dhtml_defaut" title="'.$tab[$i]['ref'].'"
  78. onMouseOver="javascript: this.className = \'dhtml_selection\';"
  79. onMouseOut="javascript: this.className = \'dhtml_defaut\';"
  80. >'.$tab[$i]['ref'].' - '.$tab[$i]['label'].'</li>
  81. ';
  82. }
  83. $resultat .= '</ul>';
  84. print $resultat;
  85. }
  86. else
  87. {
  88. $langs->load("cashdesk");
  89. print '<ul class="dhtml_bloc">';
  90. print '<li class="dhtml_defaut">'.$langs->trans("NoResults").'</li>';
  91. print '</ul>';
  92. }
  93. }
  94. }
  95. ?>