export.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. require_once('../application/application.inc.php');
  3. require_once('../application/nicewebpage.class.inc.php');
  4. require_once('../application/csvpage.class.inc.php');
  5. require_once('../application/xmlpage.class.inc.php');
  6. require_once('../application/startup.inc.php');
  7. require_once('../application/loginwebpage.class.inc.php');
  8. LoginWebPage::DoLogin(); // Check user rights and prompt if needed
  9. $sOperation = utils::ReadParam('operation', 'menu');
  10. $oContext = new UserContext();
  11. $oAppContext = new ApplicationContext();
  12. $iActiveNodeId = utils::ReadParam('menu', -1);
  13. $currentOrganization = utils::ReadParam('org_id', '');
  14. // Main program
  15. $sExpression = utils::ReadParam('expression', '');
  16. $sFormat = strtolower(utils::ReadParam('format', 'html'));
  17. $oP = null;
  18. if (!empty($sExpression))
  19. {
  20. try
  21. {
  22. $oFilter = DBObjectSearch::FromOQL($sExpression);
  23. if ($oFilter)
  24. {
  25. $oSet = new CMDBObjectSet($oFilter);
  26. switch($sFormat)
  27. {
  28. case 'html':
  29. $oP = new NiceWebPage("iTop - Export");
  30. // The HTML output is made for pages located in the /pages/ folder
  31. // since this page is in a different folder, let's adjust the HTML 'base' attribute
  32. // to make the relative hyperlinks in the page work
  33. $sServerName = $_SERVER['SERVER_NAME'];
  34. $sProtocol = isset($_SERVER['HTTPS']) ? 'https' : 'http';
  35. if ($sProtocol == 'http')
  36. {
  37. $sPort = ($_SERVER['SERVER_PORT'] == 80) ? '' : ':'.$_SERVER['SERVER_PORT'];
  38. }
  39. else
  40. {
  41. $sPort = ($_SERVER['SERVER_PORT'] == 443) ? '' : ':'.$_SERVER['SERVER_PORT'];
  42. }
  43. $sUrl = "$sProtocol://{$sServerName}{$sPort}/pages/";
  44. $oP->set_base($sUrl);
  45. cmdbAbstractObject::DisplaySet($oP, $oSet, array('menu' => false, 'display_limit' => false)); // no menu, no truncated list
  46. break;
  47. case 'csv':
  48. $oP = new CSVPage("iTop - Export");
  49. cmdbAbstractObject::DisplaySetAsCSV($oP, $oSet);
  50. break;
  51. case 'xml':
  52. $oP = new XMLPage("iTop - Export");
  53. cmdbAbstractObject::DisplaySetAsXML($oP, $oSet);
  54. break;
  55. default:
  56. $oP = new WebPage("iTop - Export");
  57. $oP->add("Unsupported format '$sFormat'. Possible values are: html, csv or xml.");
  58. }
  59. }
  60. }
  61. catch(Exception $e)
  62. {
  63. $oP = new WebPage("iTop - Export");
  64. $oP->p("Error the query can not be executed.");
  65. $oP->p($e->GetHtmlDesc());
  66. }
  67. }
  68. if (!$oP)
  69. {
  70. // Display a short message about how to use this page
  71. $oP = new WebPage("iTop - Export");
  72. $oP->p("<strong>General purpose export page.</strong>");
  73. $oP->p("<strong>Parameters:</strong>");
  74. $oP->p("<ul><li>expression: an OQL expression (URL encoded if needed)</li>
  75. <li>format: (optional, default is html) the desired output format. Can be one of 'html', 'csv' or 'xml'</li>
  76. </ul>");
  77. }
  78. $oP->output();
  79. ?>