sibusql.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. require_once('../application/application.inc.php');
  3. require_once('../application/itopwebpage.class.inc.php');
  4. require_once('../application/startup.inc.php');
  5. require_once('../application/loginwebpage.class.inc.php');
  6. login_web_page::DoLogin(); // Check user rights and prompt if needed
  7. $sOperation = utils::ReadParam('operation', 'menu');
  8. $oContext = new UserContext();
  9. $oAppContext = new ApplicationContext();
  10. $iActiveNodeId = utils::ReadParam('menu', -1);
  11. $currentOrganization = utils::ReadParam('org_id', '');
  12. $oP = new iTopWebPage("iTop - Expression Evaluation", $currentOrganization);
  13. // Main program
  14. $sExpression = utils::ReadParam('expression', '');
  15. $sEncoding = utils::ReadParam('encoding', 'oql');
  16. try
  17. {
  18. if ($sEncoding == 'crypted')
  19. {
  20. // Translate $sExpression into a oql expression
  21. $sClearText = base64_decode($sExpression);
  22. echo "<strong>FYI: '$sClearText'</strong><br/>\n";
  23. $oFilter = DBObjectSearch::unserialize($sExpression);
  24. $sExpression = $oFilter->ToOQL();
  25. exit;
  26. }
  27. else
  28. {
  29. // leave $sExpression as is
  30. }
  31. $oP->add('<form method="get">'."\n");
  32. $oP->add('Expression to evaluate:<br/>'."\n");
  33. $oP->add('<textarea cols="50" rows="20" name="expression">'.$sExpression.'</textarea>'."<p> Example:<br/>SELECT bizPerson AS B WHERE B.name LIKE '%A%'</p>\n");
  34. $oP->add('<input type="submit" value=" Evaluate ">'."\n");
  35. $oP->add('</form>'."\n");
  36. if (!empty($sExpression))
  37. {
  38. $oFilter = DBObjectSearch::FromOQL($sExpression);
  39. if ($oFilter)
  40. {
  41. $oP->p('Query expression: '.$oFilter->ToOQL());
  42. $oP->p('Serialized filter: '.$oFilter->serialize());
  43. $oSet = new CMDBObjectSet($oFilter);
  44. $oP->p('The query returned '.$oSet->count().' results(s)');
  45. cmdbAbstractObject::DisplaySet($oP, $oSet);
  46. }
  47. }
  48. }
  49. catch(CoreException $e)
  50. {
  51. $oP->p('<b>An error occured while running the query:</b>');
  52. $oP->p($e->getHtmlDesc());
  53. }
  54. catch(Exception $e)
  55. {
  56. $oP->p('<b>An error occured while running the query:</b>');
  57. $oP->p($e->getMessage());
  58. }
  59. $oP->output();
  60. ?>