selectobject.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/core/ajax/selectobject.php
  19. * \brief File to return Ajax response on a selection list request
  20. */
  21. if (!defined('NOTOKENRENEWAL')) {
  22. define('NOTOKENRENEWAL', 1); // Disables token renewal
  23. }
  24. if (!defined('NOREQUIREMENU')) {
  25. define('NOREQUIREMENU', '1');
  26. }
  27. if (!defined('NOREQUIREHTML')) {
  28. define('NOREQUIREHTML', '1');
  29. }
  30. if (!defined('NOREQUIREAJAX')) {
  31. define('NOREQUIREAJAX', '1');
  32. }
  33. if (!defined('NOREQUIRESOC')) {
  34. define('NOREQUIRESOC', '1');
  35. }
  36. // Load Dolibarr environment
  37. require '../../main.inc.php';
  38. $objectdesc = GETPOST('objectdesc', 'alpha');
  39. $htmlname = GETPOST('htmlname', 'aZ09');
  40. $outjson = (GETPOST('outjson', 'int') ? GETPOST('outjson', 'int') : 0);
  41. $id = GETPOST('id', 'int');
  42. $filter = GETPOST('filter', 'alphanohtml');
  43. /*
  44. * View
  45. */
  46. //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
  47. //print_r($_GET);
  48. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  49. $form = new Form($db);
  50. //$langs->load("companies");
  51. top_httphead();
  52. if (empty($htmlname)) {
  53. return;
  54. }
  55. $InfoFieldList = explode(":", $objectdesc);
  56. $classname = $InfoFieldList[0];
  57. $classpath = $InfoFieldList[1];
  58. if (!empty($classpath)) {
  59. dol_include_once($classpath);
  60. if ($classname && class_exists($classname)) {
  61. $objecttmp = new $classname($db);
  62. }
  63. }
  64. if (!is_object($objecttmp)) {
  65. dol_syslog('Error bad param objectdesc', LOG_WARNING);
  66. print 'Error bad param objectdesc';
  67. }
  68. // When used from jQuery, the search term is added as GET param "term".
  69. $searchkey = (($id && GETPOST($id, 'alpha')) ? GETPOST($id, 'alpha') : (($htmlname && GETPOST($htmlname, 'alpha')) ? GETPOST($htmlname, 'alpha') : ''));
  70. // Add a security test to avoid to get content of all tables
  71. restrictedArea($user, $objecttmp->element, $id);
  72. $arrayresult = $form->selectForFormsList($objecttmp, $htmlname, '', 0, $searchkey, '', '', '', 0, 1, 0, '', $filter);
  73. $db->close();
  74. if ($outjson) {
  75. print json_encode($arrayresult);
  76. }