UniversalSearch.php 3.9 KB

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