PageRenderTime 59ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/ajax/searchrow.php

https://gitlab.com/OnBlox/OnBlox-Template
PHP | 198 lines | 129 code | 26 blank | 43 comment | 33 complexity | efd228a4ebc1edf01b0247cb98b924b8 MD5 | raw file
  1. <?php
  2. /*
  3. * @version $Id$
  4. -------------------------------------------------------------------------
  5. GLPI - Gestionnaire Libre de Parc Informatique
  6. Copyright (C) 2015 Teclib'.
  7. http://glpi-project.org
  8. based on GLPI - Gestionnaire Libre de Parc Informatique
  9. Copyright (C) 2003-2014 by the INDEPNET Development Team.
  10. -------------------------------------------------------------------------
  11. LICENSE
  12. This file is part of GLPI.
  13. GLPI is free software; you can redistribute it and/or modify
  14. it under the terms of the GNU General Public License as published by
  15. the Free Software Foundation; either version 2 of the License, or
  16. (at your option) any later version.
  17. GLPI is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. GNU General Public License for more details.
  21. You should have received a copy of the GNU General Public License
  22. along with GLPI. If not, see <http://www.gnu.org/licenses/>.
  23. --------------------------------------------------------------------------
  24. */
  25. /** @file
  26. * @brief
  27. * @since version 0.85
  28. */
  29. // Direct access to file
  30. if (strpos($_SERVER['PHP_SELF'],"searchrow.php")) {
  31. include ('../inc/includes.php');
  32. header("Content-Type: text/html; charset=UTF-8");
  33. Html::header_nocache();
  34. }
  35. Session::checkLoginUser();
  36. // Non define case
  37. if (isset($_POST["itemtype"])
  38. && isset($_POST["num"]) ) {
  39. $options = Search::getCleanedOptions($_POST["itemtype"]);
  40. $randrow = mt_rand();
  41. $rowid = 'searchrow'.$_POST['itemtype'].$randrow;
  42. $addclass = '';
  43. if ($_POST["num"] == 0) {
  44. $addclass = ' headerRow';
  45. }
  46. echo "<tr class='normalcriteria$addclass' id='$rowid'><td class='left' width='45%'>";
  47. // First line display add / delete images for normal and meta search items
  48. if ($_POST["num"] == 0) {
  49. $linked = Search::getMetaItemtypeAvailable($_POST["itemtype"]);
  50. echo "<img class='pointer' src=\"".$CFG_GLPI["root_doc"]."/pics/plus.png\" alt='+' title=\"".
  51. __s('Add a search criterion')."\" id='addsearchcriteria$randrow'>";
  52. $js = Html::jsGetElementbyID("addsearchcriteria$randrow").".on('click', function(e) {
  53. $.post( '".$CFG_GLPI['root_doc']."/ajax/searchrow.php',
  54. { itemtype: '".$_POST["itemtype"]."', num: $nbsearchcountvar })
  55. .done(function( data ) {
  56. $('#".$searchcriteriatableid." .normalcriteria:last').after(data);
  57. });
  58. $nbsearchcountvar = $nbsearchcountvar +1;});";
  59. echo Html::scriptBlock($js);
  60. echo "&nbsp;&nbsp;&nbsp;&nbsp;";
  61. if (is_array($linked) && (count($linked) > 0)) {
  62. echo "<img class='pointer' src=\"".$CFG_GLPI["root_doc"]."/pics/meta_plus.png\"
  63. alt='+' title=\"". __s('Add a global search criterion').
  64. "\" id='addmetasearchcriteria$randrow'>";
  65. $js = Html::jsGetElementbyID("addmetasearchcriteria$randrow").".on('click', function(e) {
  66. $.post( '".$CFG_GLPI['root_doc']."/ajax/searchmetarow.php',
  67. { itemtype: '".$_POST["itemtype"]."', num: $nbmetasearchcountvar })
  68. .done(function( data ) {
  69. $('#".$searchcriteriatableid."').append(data);
  70. });
  71. $nbmetasearchcountvar = $nbmetasearchcountvar +1;});";
  72. echo Html::scriptBlock($js);
  73. echo "&nbsp;&nbsp;&nbsp;&nbsp;";
  74. }
  75. // Instanciate an object to access method
  76. $item = NULL;
  77. if ($_POST["itemtype"] != 'AllAssets') {
  78. $item = getItemForItemtype($_POST["itemtype"]);
  79. }
  80. if ($item && $item->maybeDeleted()) {
  81. echo "<input type='hidden' id='is_deleted' name='is_deleted' value='".$p['is_deleted']."'>";
  82. }
  83. } else {
  84. echo "<img class='pointer' src=\"".$CFG_GLPI["root_doc"]."/pics/moins.png\" alt='-' title=\"".
  85. __s('Delete a search criterion')."\" onclick=\"".
  86. Html::jsGetElementbyID($rowid).".remove();\">&nbsp;&nbsp;";
  87. }
  88. $criteria = array();
  89. if (isset($_SESSION['glpisearch'][$_POST["itemtype"]]['criteria'][$_POST["num"]])
  90. && is_array($_SESSION['glpisearch'][$_POST["itemtype"]]['criteria'][$_POST["num"]])) {
  91. $criteria = $_SESSION['glpisearch'][$_POST["itemtype"]]['criteria'][$_POST["num"]];
  92. } else {
  93. foreach ($options as $key => $val) {
  94. if (is_array($val)) {
  95. $criteria['field'] = $key;
  96. break;
  97. }
  98. }
  99. }
  100. // Display link item
  101. if ($_POST["num"] > 0) {
  102. $value = '';
  103. if (isset($criteria["link"])) {
  104. $value = $criteria["link"];
  105. }
  106. Dropdown::showFromArray("criteria[".$_POST["num"]."][link]",
  107. Search::getLogicalOperators(),
  108. array('value' => $value));
  109. }
  110. $selected = $first = '';
  111. $values = array();
  112. // display select box to define search item
  113. if ($CFG_GLPI['allow_search_view'] == 2) {
  114. $values['view'] = __('Items seen');
  115. }
  116. reset($options);
  117. $group = '';
  118. foreach ($options as $key => $val) {
  119. // print groups
  120. if (!is_array($val)) {
  121. $group = $val;
  122. } else {
  123. if (!isset($val['nosearch']) || ($val['nosearch'] == false)) {
  124. $values[$group][$key] = $val["name"];
  125. }
  126. }
  127. }
  128. if ($CFG_GLPI['allow_search_view'] == 1) {
  129. $values['view'] = __('Items seen');
  130. }
  131. if ($CFG_GLPI['allow_search_all']) {
  132. $values['all'] = __('All');
  133. }
  134. $value = '';
  135. if (isset($criteria['field'])) {
  136. $value = $criteria['field'];
  137. }
  138. $rand = Dropdown::showFromArray("criteria[".$_POST["num"]."][field]", $values,
  139. array('value' => $value));
  140. $field_id = Html::cleanId("dropdown_criteria[".$_POST["num"]."][field]$rand");
  141. echo "</td><td class='left'>";
  142. $spanid= 'SearchSpan'.$_POST["itemtype"].$_POST["num"];
  143. echo "<div id='$spanid'>\n";
  144. $used_itemtype = $_POST["itemtype"];
  145. // Force Computer itemtype for AllAssets to permit to show specific items
  146. if ($_POST["itemtype"] == 'AllAssets') {
  147. $used_itemtype = 'Computer';
  148. }
  149. $_POST['itemtype'] = $used_itemtype;
  150. $_POST['field'] = $value;
  151. $_POST['searchtype'] = (isset($criteria['searchtype'])?$criteria['searchtype']:"" );
  152. $_POST['value'] = (isset($criteria['value'])?stripslashes($criteria['value']):"" );
  153. include (GLPI_ROOT."/ajax/searchoption.php");
  154. echo "</div>\n";
  155. $params = array('field' => '__VALUE__',
  156. 'itemtype' => $used_itemtype,
  157. 'num' => $_POST["num"],
  158. 'value' => $_POST["value"],
  159. 'searchtype' => $_POST["searchtype"]);
  160. Ajax::updateItemOnSelectEvent($field_id, $spanid,
  161. $CFG_GLPI["root_doc"]."/ajax/searchoption.php", $params);
  162. echo "</td></tr>\n";
  163. }
  164. ?>