UniversalSearch.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. // Copyright (C) 2010-2016 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero 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. // iTop 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 Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * Analytical search
  20. *
  21. * @copyright Copyright (C) 2010-2016 Combodo SARL
  22. * @license http://opensource.org/licenses/AGPL-3.0
  23. */
  24. require_once('../approot.inc.php');
  25. require_once(APPROOT.'/application/application.inc.php');
  26. require_once(APPROOT.'/application/itopwebpage.class.inc.php');
  27. require_once(APPROOT.'/application/applicationcontext.class.inc.php');
  28. require_once(APPROOT.'/application/startup.inc.php');
  29. require_once(APPROOT.'/application/loginwebpage.class.inc.php');
  30. LoginWebPage::DoLogin(true); // Check user rights and prompt if needed (must be admin)
  31. $oAppContext = new ApplicationContext();
  32. $oP = new iTopWebPage(Dict::S('UI:UniversalSearchTitle'));
  33. $oP->add_linked_script("../js/json.js");
  34. $oP->add_linked_script("../js/forms-json-utils.js");
  35. $oP->add_linked_script("../js/wizardhelper.js");
  36. $oP->add_linked_script("../js/wizard.utils.js");
  37. $oP->add_linked_script("../js/linkswidget.js");
  38. $oP->add_linked_script("../js/extkeywidget.js");
  39. $oP->add_linked_script("../js/jquery.blockUI.js");
  40. // From now on the context is limited to the the selected organization ??
  41. // Now render the content of the page
  42. $sBaseClass = utils::ReadParam('baseClass', 'Organization', false, 'class');
  43. $sClass = utils::ReadParam('class', $sBaseClass, false, 'class');
  44. $sOQLClause = utils::ReadParam('oql_clause', '', false, 'raw_data');
  45. $sFilter = utils::ReadParam('filter', '', false, 'raw_data');
  46. $sOperation = utils::ReadParam('operation', '');
  47. $oP->SetBreadCrumbEntry('ui-tool-universalsearch', Dict::S('Menu:UniversalSearchMenu'), Dict::S('Menu:UniversalSearchMenu+'), '', utils::GetAbsoluteUrlAppRoot().'images/wrench.png');
  48. // First part: select the class to search for
  49. $oP->add("<form>");
  50. $oP->add(Dict::S('UI:UniversalSearch:LabelSelectTheClass')."<select style=\"width: 150px;\" id=\"select_class\" name=\"baseClass\" onChange=\"this.form.submit();\">");
  51. $aClassLabels = array();
  52. foreach(MetaModel::GetClasses('bizmodel') as $sCurrentClass)
  53. {
  54. $aClassLabels[$sCurrentClass] = MetaModel::GetName($sCurrentClass);
  55. }
  56. asort($aClassLabels);
  57. foreach($aClassLabels as $sCurrentClass => $sLabel)
  58. {
  59. $sDescription = MetaModel::GetClassDescription($sCurrentClass);
  60. $sSelected = ($sCurrentClass == $sBaseClass) ? " SELECTED" : "";
  61. $oP->add("<option value=\"$sCurrentClass\" title=\"$sDescription\"$sSelected>$sLabel</option>");
  62. }
  63. $oP->add("</select>\n");
  64. $oP->add($oAppContext->GetForForm());
  65. $oP->add("</form>\n");
  66. try
  67. {
  68. if ($sOperation == 'search_form')
  69. {
  70. $sOQL = "SELECT $sClass $sOQLClause";
  71. $oFilter = DBObjectSearch::FromOQL($sOQL);
  72. }
  73. else
  74. {
  75. // Second part: advanced search form:
  76. if (!empty($sFilter))
  77. {
  78. $oFilter = DBSearch::unserialize($sFilter);
  79. }
  80. else if (!empty($sClass))
  81. {
  82. $oFilter = new DBObjectSearch($sClass);
  83. }
  84. }
  85. }
  86. catch (CoreException $e)
  87. {
  88. $oFilter = new DBObjectSearch($sClass);
  89. $oP->P("<b>".Dict::Format('UI:UniversalSearch:Error', $e->getHtmlDesc())."</b>");
  90. }
  91. if ($oFilter != null)
  92. {
  93. $oSet = new CMDBObjectSet($oFilter);
  94. $oBlock = new DisplayBlock($oFilter, 'search', false);
  95. $aExtraParams = $oAppContext->GetAsHash();
  96. $aExtraParams['open'] = true;
  97. $aExtraParams['baseClass'] = $sBaseClass;
  98. $aExtraParams['action'] = utils::GetAbsoluteUrlAppRoot().'pages/UniversalSearch.php';
  99. //$aExtraParams['class'] = $sClassName;
  100. $oBlock->Display($oP, 0, $aExtraParams);
  101. // Search results
  102. $oResultBlock = new DisplayBlock($oFilter, 'list', false);
  103. $oResultBlock->Display($oP, 1);
  104. // Breadcrumb
  105. //$iCount = $oBlock->GetDisplayedCount();
  106. $sPageId = "ui-search-".$oFilter->GetClass();
  107. $sLabel = MetaModel::GetName($oFilter->GetClass());
  108. $oP->SetBreadCrumbEntry($sPageId, $sLabel, '', '', '../images/breadcrumb-search.png');
  109. // Menu node
  110. $sFilter = $oFilter->ToOQL();
  111. $oP->add("\n<!-- $sFilter -->\n");
  112. }
  113. $oP->add("</div>\n");
  114. $oP->output();
  115. ?>