ajax.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Copyright (C) 2020 Laurent Destailleur <eldy@users.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 3 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 <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/bom/ajax/ajax.php
  20. * \brief Ajax component for BOM.
  21. */
  22. if (!defined('NOTOKENRENEWAL')) {
  23. define('NOTOKENRENEWAL', '1'); // Disables token renewal
  24. }
  25. if (!defined('NOREQUIREHTML')) {
  26. define('NOREQUIREHTML', '1');
  27. }
  28. if (!defined('NOREQUIREAJAX')) {
  29. define('NOREQUIREAJAX', '1');
  30. }
  31. if (!defined('NOREQUIRESOC')) {
  32. define('NOREQUIRESOC', '1');
  33. }
  34. if (!defined('NOREQUIREMENU')) {
  35. define('NOREQUIREMENU', '1');
  36. }
  37. if (!defined('NOBROWSERNOTIF')) {
  38. define('NOBROWSERNOTIF', '1');
  39. }
  40. include_once '../../main.inc.php'; // Load $user and permissions
  41. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
  43. $action = GETPOST('action', 'aZ09');
  44. $idproduct = GETPOST('idproduct', 'int');
  45. /*
  46. * View
  47. */
  48. top_httphead();
  49. if ($action == 'getDurationUnitByProduct' && $user->hasRight('product', 'lire')) {
  50. $product = new Product($db);
  51. $res = $product->fetch($idproduct);
  52. $cUnit = new CUnits($db);
  53. $fk_unit = $cUnit->getUnitFromCode($product->duration_unit, 'short_label', 'time');
  54. echo json_encode($fk_unit);
  55. exit();
  56. }