UniversalSearch.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. // From now on the context is limited to the the selected organization ??
  34. // Now render the content of the page
  35. $sBaseClass = utils::ReadParam('baseClass', 'Organization');
  36. $sClass = utils::ReadParam('class', $sBaseClass);
  37. $sOQLClause = utils::ReadParam('oql_clause', '');
  38. $sFilter = utils::ReadParam('filter', '');
  39. $sOperation = utils::ReadParam('operation', '');
  40. // First part: select the class to search for
  41. $oP->add("<form>");
  42. $oP->add(Dict::S('UI:UniversalSearch:LabelSelectTheClass')."<select style=\"width: 150px;\" id=\"select_class\" name=\"baseClass\" onChange=\"this.form.submit();\">");
  43. $aClassLabels = array();
  44. foreach(MetaModel::GetClasses('bizmodel') as $sCurrentClass)
  45. {
  46. $aClassLabels[$sCurrentClass] = MetaModel::GetName($sCurrentClass);
  47. }
  48. asort($aClassLabels);
  49. foreach($aClassLabels as $sCurrentClass => $sLabel)
  50. {
  51. $sDescription = MetaModel::GetClassDescription($sCurrentClass);
  52. $sSelected = ($sCurrentClass == $sBaseClass) ? " SELECTED" : "";
  53. $oP->add("<option value=\"$sCurrentClass\" title=\"$sDescription\"$sSelected>$sLabel</option>");
  54. }
  55. $oP->add("</select>\n");
  56. $oP->add($oAppContext->GetForForm());
  57. $oP->add("</form>\n");
  58. try
  59. {
  60. if ($sOperation == 'search_form')
  61. {
  62. $sOQL = "SELECT $sClass $sOQLClause";
  63. $oFilter = DBObjectSearch::FromOQL($sOQL);
  64. }
  65. else
  66. {
  67. // Second part: advanced search form:
  68. if (!empty($sFilter))
  69. {
  70. $oFilter = CMDBSearchFilter::unserialize($sFilter);
  71. }
  72. else if (!empty($sClass))
  73. {
  74. $oFilter = new CMDBSearchFilter($sClass);
  75. }
  76. }
  77. }
  78. catch (CoreException $e)
  79. {
  80. $oFilter = new CMDBSearchFilter($sClass);
  81. $oP->P("<b>".Dict::Format('UI:UniversalSearch:Error', $e->getHtmlDesc())."</b>");
  82. }
  83. if ($oFilter != null)
  84. {
  85. $oSet = new CMDBObjectSet($oFilter);
  86. $oBlock = new DisplayBlock($oFilter, 'search', false);
  87. $aExtraParams = $oAppContext->GetAsHash();
  88. $aExtraParams['open'] = true;
  89. $aExtraParams['baseClass'] = $sBaseClass;
  90. //$aExtraParams['class'] = $sClassName;
  91. $oBlock->Display($oP, 0, $aExtraParams);
  92. // Search results
  93. $oResultBlock = new DisplayBlock($oFilter, 'list', false);
  94. $oResultBlock->Display($oP, 1);
  95. // Menu node
  96. $sFilter = $oFilter->ToOQL();
  97. $oP->add("\n<!-- $sFilter -->\n");
  98. }
  99. $oP->add("</div>\n");
  100. $oP->output();
  101. ?>