company.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  3. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2007-2019 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 <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/societe/ajax/company.php
  21. * \brief File to return Ajax response on thirdparty list request. Used by the combo list of thirdparties.
  22. * Search done on name, name_alias, barcode, tva_intra, ...
  23. */
  24. if (!defined('NOTOKENRENEWAL')) {
  25. define('NOTOKENRENEWAL', 1); // Disables token renewal
  26. }
  27. if (!defined('NOREQUIREMENU')) {
  28. define('NOREQUIREMENU', '1');
  29. }
  30. if (!defined('NOREQUIREHTML')) {
  31. define('NOREQUIREHTML', '1');
  32. }
  33. if (!defined('NOREQUIREAJAX')) {
  34. define('NOREQUIREAJAX', '1');
  35. }
  36. if (!defined('NOREQUIRESOC')) {
  37. define('NOREQUIRESOC', '1');
  38. }
  39. // Load Dolibarr environment
  40. require '../../main.inc.php';
  41. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  42. $htmlname = GETPOST('htmlname', 'aZ09');
  43. $filter = GETPOST('filter', 'alpha');
  44. $outjson = (GETPOST('outjson', 'int') ? GETPOST('outjson', 'int') : 0);
  45. $action = GETPOST('action', 'aZ09');
  46. $id = GETPOST('id', 'int');
  47. $excludeids = GETPOST('excludeids', 'intcomma');
  48. $showtype = GETPOSTINT('showtype', 'alpha');
  49. $showcode = GETPOSTINT('showcode', 'alpha');
  50. $object = new Societe($db);
  51. if ($id > 0) {
  52. $object->fetch($id);
  53. }
  54. // Security check
  55. if ($user->socid > 0) {
  56. unset($action);
  57. $socid = $user->socid;
  58. $object->id = $socid;
  59. }
  60. restrictedArea($user, 'societe', $object->id, '&societe');
  61. /*
  62. * View
  63. */
  64. top_httphead('application/json');
  65. //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
  66. //print_r($_GET);
  67. if (!empty($action) && $action == 'fetch' && !empty($id)) {
  68. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  69. $outjson = array();
  70. if ($object->id > 0) {
  71. $outref = $object->ref;
  72. $outname = $object->name;
  73. $outdesc = '';
  74. $outtype = $object->type;
  75. $outjson = array('ref' => $outref, 'name' => $outname, 'desc' => $outdesc, 'type' => $outtype);
  76. }
  77. echo json_encode($outjson);
  78. } else {
  79. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  80. if (empty($htmlname)) {
  81. return;
  82. }
  83. // Filter on the company to search can be:
  84. // Into an array with key $htmlname123 (we take first one found). Which page use this ?
  85. // Into a var with name $htmlname can be 'prodid', 'productid', ...
  86. $match = preg_grep('/('.preg_quote($htmlname, '/').'[0-9]+)/', array_keys($_GET));
  87. sort($match);
  88. $id = (!empty($match[0]) ? $match[0] : ''); // Take first key found into GET array with matching $htmlname123
  89. // When used from jQuery, the search term is added as GET param "term".
  90. $searchkey = (($id && GETPOST($id, 'alpha')) ? GETPOST($id, 'alpha') : (($htmlname && GETPOST($htmlname, 'alpha')) ? GETPOST($htmlname, 'alpha') : ''));
  91. if (!$searchkey) {
  92. return;
  93. }
  94. if (empty($form) || !is_object($form)) {
  95. $form = new Form($db);
  96. }
  97. if (!empty($excludeids)) {
  98. $excludeids = explode(',', $excludeids);
  99. } else {
  100. $excludeids = array();
  101. }
  102. $arrayresult = $form->select_thirdparty_list(0, $htmlname, $filter, 1, $showtype, 0, null, $searchkey, $outjson, 0, 'minwidth100', '', false, $excludeids, $showcode);
  103. if ($outjson) {
  104. print json_encode($arrayresult);
  105. }
  106. }
  107. $db->close();