PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/product/ajax/products.php

https://bitbucket.org/speedealing/speedealing
PHP | 151 lines | 89 code | 27 blank | 35 comment | 26 complexity | 41e935b9feff4994f0866f0e6fec8483 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  3. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  4. * Copyright (C) 2007-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/product/ajax/products.php
  21. * \brief File to return Ajax response on product list request
  22. */
  23. if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal
  24. if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
  25. if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
  26. if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
  27. if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
  28. if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1');
  29. if (empty($_GET['keysearch']) && ! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
  30. require '../../main.inc.php';
  31. $htmlname=GETPOST('htmlname','alpha');
  32. $socid=GETPOST('socid','alpha');
  33. $type=GETPOST('type','alpha');
  34. $mode=GETPOST('mode','int');
  35. $status=((GETPOST('status','alpha') >= 0) ? GETPOST('status','alpha') : -1);
  36. $outjson=(GETPOST('outjson','int') ? GETPOST('outjson','int') : 0);
  37. $pricelevel=GETPOST('price_level','int');
  38. $action=GETPOST('action', 'alpha');
  39. $id=GETPOST('id', 'alpha');
  40. //require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  41. //$form = new Form($db);
  42. //$arrayresult=$form->select_products("",$htmlname,$type,"",$pricelevel,$searchkey,$status,2,$outjson);
  43. ////echo '<pre>' . print_r($arrayresult, true) . '</pre>';
  44. //echo json_encode($arrayresult);
  45. //exit;
  46. /*
  47. * View
  48. */
  49. //print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n";
  50. dol_syslog(join(',',$_GET));
  51. //print_r($_GET);
  52. if (! empty($action) && $action == 'fetch' && ! empty($id))
  53. {
  54. require DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
  55. $outjson=array();
  56. $object = new Product($db);
  57. $ret=$object->fetch($id);
  58. if ($ret > 0)
  59. {
  60. $outref=$object->ref;
  61. $outlabel=$object->label;
  62. $outdesc=$object->description;
  63. $outtype=$object->type;
  64. $found=false;
  65. // Multiprice
  66. if (isset($price_level) && $price_level >= 1) // If we need a particular price level (from 1 to 6)
  67. {
  68. $sql = "SELECT price, price_ttc, price_base_type, tva_tx";
  69. $sql.= " FROM ".MAIN_DB_PREFIX."product_price ";
  70. $sql.= " WHERE fk_product='".$id."'";
  71. $sql.= " AND price_level=".$price_level;
  72. $sql.= " ORDER BY date_price";
  73. $sql.= " DESC LIMIT 1";
  74. $result = $this->db->query($sql);
  75. if ($result)
  76. {
  77. $objp = $this->db->fetch_object($result);
  78. if ($objp)
  79. {
  80. $found=true;
  81. $outprice_ht=price($objp->price);
  82. $outprice_ttc=price($objp->price_ttc);
  83. $outpricebasetype=$objp->price_base_type;
  84. $outtva_tx=$objp->tva_tx;
  85. }
  86. }
  87. }
  88. if (! $found)
  89. {
  90. $outprice_ht=price($object->price);
  91. $outprice_ttc=price($object->price_ttc);
  92. $outpricebasetype=$object->price_base_type;
  93. $outtva_tx=$object->tva_tx;
  94. }
  95. $outjson = array('ref'=>$outref, 'label'=>$outlabel, 'desc'=>$outdesc, 'type'=>$outtype, 'price_ht'=>$outprice_ht, 'price_ttc'=>$outprice_ttc, 'pricebasetype'=>$outpricebasetype, 'tva_tx'=>$outtva_tx);
  96. }
  97. echo json_encode($outjson);
  98. }
  99. else
  100. {
  101. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  102. $langs->load("products");
  103. $langs->load("main");
  104. top_httphead();
  105. if (empty($htmlname)) return;
  106. $match = preg_grep('/('.$htmlname.'[0-9]+)/',array_keys($_GET));
  107. sort($match);
  108. $idprod = (! empty($match[0]) ? $match[0] : '');
  109. if (! GETPOST($htmlname) && ! GETPOST($idprod)) return;
  110. // When used from jQuery, the search term is added as GET param "term".
  111. $searchkey=(GETPOST($idprod)?GETPOST($idprod):(GETPOST($htmlname)?GETPOST($htmlname):''));
  112. $form = new Form($db);
  113. if (empty($mode) || $mode == 1)
  114. {
  115. $arrayresult=$form->select_products("",$htmlname,$type,"",$pricelevel,$searchkey,$status,2,$outjson);
  116. }
  117. elseif ($mode == 2)
  118. {
  119. $arrayresult=$form->select_produits_fournisseurs_do($socid,"",$htmlname,$type,"",$searchkey,$status,$outjson);
  120. }
  121. // $db->close();
  122. if ($outjson) print json_encode($arrayresult);
  123. }
  124. ?>