UniversalSearch.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  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; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * Analytical search
  18. *
  19. * @author Erwan Taloc <erwan.taloc@combodo.com>
  20. * @author Romain Quetiez <romain.quetiez@combodo.com>
  21. * @author Denis Flaven <denis.flaven@combodo.com>
  22. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  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. // First part: select the class to search for
  48. $oP->add("<form>");
  49. $oP->add(Dict::S('UI:UniversalSearch:LabelSelectTheClass')."<select style=\"width: 150px;\" id=\"select_class\" name=\"baseClass\" onChange=\"this.form.submit();\">");
  50. $aClassLabels = array();
  51. foreach(MetaModel::GetClasses('bizmodel') as $sCurrentClass)
  52. {
  53. $aClassLabels[$sCurrentClass] = MetaModel::GetName($sCurrentClass);
  54. }
  55. asort($aClassLabels);
  56. foreach($aClassLabels as $sCurrentClass => $sLabel)
  57. {
  58. $sDescription = MetaModel::GetClassDescription($sCurrentClass);
  59. $sSelected = ($sCurrentClass == $sBaseClass) ? " SELECTED" : "";
  60. $oP->add("<option value=\"$sCurrentClass\" title=\"$sDescription\"$sSelected>$sLabel</option>");
  61. }
  62. $oP->add("</select>\n");
  63. $oP->add($oAppContext->GetForForm());
  64. $oP->add("</form>\n");
  65. try
  66. {
  67. if ($sOperation == 'search_form')
  68. {
  69. $sOQL = "SELECT $sClass $sOQLClause";
  70. $oFilter = DBObjectSearch::FromOQL($sOQL);
  71. }
  72. else
  73. {
  74. // Second part: advanced search form:
  75. if (!empty($sFilter))
  76. {
  77. $oFilter = CMDBSearchFilter::unserialize($sFilter);
  78. }
  79. else if (!empty($sClass))
  80. {
  81. $oFilter = new CMDBSearchFilter($sClass);
  82. }
  83. }
  84. }
  85. catch (CoreException $e)
  86. {
  87. $oFilter = new CMDBSearchFilter($sClass);
  88. $oP->P("<b>".Dict::Format('UI:UniversalSearch:Error', $e->getHtmlDesc())."</b>");
  89. }
  90. if ($oFilter != null)
  91. {
  92. $oSet = new CMDBObjectSet($oFilter);
  93. $oBlock = new DisplayBlock($oFilter, 'search', false);
  94. $aExtraParams = $oAppContext->GetAsHash();
  95. $aExtraParams['open'] = true;
  96. $aExtraParams['baseClass'] = $sBaseClass;
  97. $aExtraParams['action'] = utils::GetAbsoluteUrlAppRoot().'pages/UniversalSearch.php';
  98. //$aExtraParams['class'] = $sClassName;
  99. $oBlock->Display($oP, 0, $aExtraParams);
  100. // Search results
  101. $oResultBlock = new DisplayBlock($oFilter, 'list', false);
  102. $oResultBlock->Display($oP, 1);
  103. // Menu node
  104. $sFilter = $oFilter->ToOQL();
  105. $oP->add("\n<!-- $sFilter -->\n");
  106. }
  107. $oP->add("</div>\n");
  108. $oP->output();
  109. ?>