UniversalSearch.php 3.9 KB

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