company.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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
  22. */
  23. if (!defined('NOTOKENRENEWAL')) {
  24. define('NOTOKENRENEWAL', 1); // Disables token renewal
  25. }
  26. if (!defined('NOREQUIREMENU')) {
  27. define('NOREQUIREMENU', '1');
  28. }
  29. if (!defined('NOREQUIREHTML')) {
  30. define('NOREQUIREHTML', '1');
  31. }
  32. if (!defined('NOREQUIREAJAX')) {
  33. define('NOREQUIREAJAX', '1');
  34. }
  35. if (!defined('NOREQUIRESOC')) {
  36. define('NOREQUIRESOC', '1');
  37. }
  38. if (!defined('NOCSRFCHECK')) {
  39. define('NOCSRFCHECK', '1');
  40. }
  41. require '../../main.inc.php';
  42. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  43. $htmlname = GETPOST('htmlname', 'aZ09');
  44. $filter = GETPOST('filter', 'alpha');
  45. $outjson = (GETPOST('outjson', 'int') ? GETPOST('outjson', 'int') : 0);
  46. $action = GETPOST('action', 'aZ09');
  47. $id = GETPOST('id', 'int');
  48. $excludeids = GETPOST('excludeids', 'intcomma');
  49. $showtype = GETPOST('showtype', 'int');
  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. //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
  65. //print_r($_GET);
  66. if (!empty($action) && $action == 'fetch' && !empty($id)) {
  67. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  68. $outjson = array();
  69. if ($object->id > 0) {
  70. $outref = $object->ref;
  71. $outname = $object->name;
  72. $outdesc = '';
  73. $outtype = $object->type;
  74. $outjson = array('ref' => $outref, 'name' => $outname, 'desc' => $outdesc, 'type' => $outtype);
  75. }
  76. echo json_encode($outjson);
  77. } else {
  78. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  79. $langs->load("companies");
  80. top_httphead();
  81. if (empty($htmlname)) {
  82. return;
  83. }
  84. // Filter on the company to search can be:
  85. // Into an array with key $htmlname123 (we take first one found). Which page use this ?
  86. // Into a var with name $htmlname can be 'prodid', 'productid', ...
  87. $match = preg_grep('/('.preg_quote($htmlname, '/').'[0-9]+)/', array_keys($_GET));
  88. sort($match);
  89. $id = (!empty($match[0]) ? $match[0] : ''); // Take first key found into GET array with matching $htmlname123
  90. // When used from jQuery, the search term is added as GET param "term".
  91. $searchkey = (($id && GETPOST($id, 'alpha')) ? GETPOST($id, 'alpha') : (($htmlname && GETPOST($htmlname, 'alpha')) ?GETPOST($htmlname, 'alpha') : ''));
  92. if (!$searchkey) {
  93. return;
  94. }
  95. if (empty($form) || !is_object($form)) {
  96. $form = new Form($db);
  97. }
  98. if (!empty($excludeids)) {
  99. $excludeids = explode(',', $excludeids);
  100. } else {
  101. $excludeids = array();
  102. }
  103. $arrayresult = $form->select_thirdparty_list(0, $htmlname, $filter, 1, $showtype, 0, null, $searchkey, $outjson, 0, 'minwidth100', '', false, $excludeids);
  104. $db->close();
  105. if ($outjson) {
  106. print json_encode($arrayresult);
  107. }
  108. }