/ajax/dropdownAllItems.php

https://github.com/glpi-project/glpi · PHP · 96 lines · 52 code · 12 blank · 32 comment · 13 complexity · 26dcd8502ce31d70d6d1404f41ed394f MD5 · raw file

  1. <?php
  2. /**
  3. * ---------------------------------------------------------------------
  4. * GLPI - Gestionnaire Libre de Parc Informatique
  5. * Copyright (C) 2015-2020 Teclib' and contributors.
  6. *
  7. * http://glpi-project.org
  8. *
  9. * based on GLPI - Gestionnaire Libre de Parc Informatique
  10. * Copyright (C) 2003-2014 by the INDEPNET Development Team.
  11. *
  12. * ---------------------------------------------------------------------
  13. *
  14. * LICENSE
  15. *
  16. * This file is part of GLPI.
  17. *
  18. * GLPI is free software; you can redistribute it and/or modify
  19. * it under the terms of the GNU General Public License as published by
  20. * the Free Software Foundation; either version 2 of the License, or
  21. * (at your option) any later version.
  22. *
  23. * GLPI is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU General Public License
  29. * along with GLPI. If not, see <http://www.gnu.org/licenses/>.
  30. * ---------------------------------------------------------------------
  31. */
  32. include ('../inc/includes.php');
  33. header("Content-Type: text/html; charset=UTF-8");
  34. Html::header_nocache();
  35. Session::checkCentralAccess();
  36. // Make a select box
  37. if ($_POST["idtable"] && class_exists($_POST["idtable"])) {
  38. // Link to user for search only > normal users
  39. $link = "getDropdownValue.php";
  40. if ($_POST["idtable"] == 'User') {
  41. $link = "getDropdownUsers.php";
  42. }
  43. $rand = mt_rand();
  44. if (isset($_POST['rand'])) {
  45. $rand = $_POST['rand'];
  46. }
  47. $field_id = Html::cleanId("dropdown_".$_POST["name"].$rand);
  48. $p = ['value' => 0,
  49. 'valuename' => Dropdown::EMPTY_VALUE,
  50. 'itemtype' => $_POST["idtable"],
  51. 'display_emptychoice' => true,
  52. 'displaywith' => ['otherserial', 'serial']];
  53. if (isset($_POST['value'])) {
  54. $p['value'] = $_POST['value'];
  55. }
  56. if (isset($_POST['entity_restrict'])) {
  57. $p['entity_restrict'] = $_POST['entity_restrict'];
  58. }
  59. if (isset($_POST['condition'])) {
  60. $p['condition'] = $_POST['condition'];
  61. }
  62. if (isset($_POST['used'])) {
  63. $_POST['used'] = Toolbox::jsonDecode($_POST['used'], true);
  64. }
  65. if (isset($_POST['used'][$_POST['idtable']])) {
  66. $p['used'] = $_POST['used'][$_POST['idtable']];
  67. }
  68. if (isset($_POST['width'])) {
  69. $p['width'] = $_POST['width'];
  70. }
  71. echo Html::jsAjaxDropdown($_POST["name"], $field_id,
  72. $CFG_GLPI['root_doc']."/ajax/".$link,
  73. $p);
  74. if (!empty($_POST['showItemSpecificity'])) {
  75. $params = ['items_id' => '__VALUE__',
  76. 'itemtype' => $_POST["idtable"]];
  77. if (isset($_POST['entity_restrict'])) {
  78. $params['entity_restrict'] = $_POST['entity_restrict'];
  79. }
  80. Ajax::updateItemOnSelectEvent($field_id, "showItemSpecificity_".$_POST["name"]."$rand",
  81. $_POST['showItemSpecificity'], $params);
  82. echo "<br><span id='showItemSpecificity_".$_POST["name"]."$rand'>&nbsp;</span>\n";
  83. }
  84. }