From 460f8234f8631e459affbb9d1db91eb75734c74c Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Mon, 21 Dec 2009 09:41:31 +0000 Subject: [PATCH] Fixed the HTML display in the export webservice page. (Trac #58) SVN:trunk[199] --- application/itopwebpage.class.inc.php | 1 + application/webpage.class.inc.php | 31 +++++++++++++++++++++++++++ webservices/export.php | 15 +++++++++++++ 3 files changed, 47 insertions(+) diff --git a/application/itopwebpage.class.inc.php b/application/itopwebpage.class.inc.php index c183fae54..1b1bca3d8 100644 --- a/application/itopwebpage.class.inc.php +++ b/application/itopwebpage.class.inc.php @@ -214,6 +214,7 @@ EOF echo "\n"; echo "\n"; echo "{$this->s_title}\n"; + echo $this->get_base_tag(); // Stylesheets MUST be loaded before any scripts otherwise // jQuery scripts may face some spurious problems (like failing on a 'reload') foreach($this->a_linked_stylesheets as $a_stylesheet) diff --git a/application/webpage.class.inc.php b/application/webpage.class.inc.php index 077586983..e33e7235c 100644 --- a/application/webpage.class.inc.php +++ b/application/webpage.class.inc.php @@ -19,6 +19,7 @@ class web_page protected $a_include_scripts; protected $a_include_stylesheets; protected $a_headers; + protected $a_base; public function __construct($s_title) { @@ -29,6 +30,7 @@ class web_page $this->a_linked_scripts = array(); $this->a_linked_stylesheets = array(); $this->a_headers = array(); + $this->a_base = array( 'href' => '', 'target' => ''); ob_start(); // Start capturing the output } @@ -40,6 +42,15 @@ class web_page $this->s_title = $s_title; } + /** + * Specify a default URL and a default target for all links on a page + */ + public function set_base($s_href = '', $s_target = '') + { + $this->a_base['href'] = $s_href; + $this->a_base['target'] = $s_target; + } + /** * Add any text or HTML fragment to the body of the page */ @@ -227,6 +238,7 @@ class web_page echo "\n"; echo "\n"; echo "{$this->s_title}\n"; + echo $this->get_base_tag(); foreach($this->a_linked_scripts as $s_script) { echo "\n"; @@ -285,5 +297,24 @@ class web_page $this->add(""); } } + + protected function get_base_tag() + { + $sTag = ''; + if (($this->a_base['href'] != '') || ($this->a_base['target'] != '')) + { + $sTag = 'a_base['href'] != '')) + { + $sTag .= "href =\"{$this->a_base['href']}\" "; + } + if (($this->a_base['target'] != '')) + { + $sTag .= "target =\"{$this->a_base['target']}\" "; + } + $sTag .= " />\n"; + } + return $sTag; + } } ?> diff --git a/webservices/export.php b/webservices/export.php index b7c7ad2e7..912ddebfa 100644 --- a/webservices/export.php +++ b/webservices/export.php @@ -32,6 +32,21 @@ if (!empty($sExpression)) { case 'html': $oP = new nice_web_page("iTop - Export"); + // The HTML output is made for pages located in the /pages/ folder + // since this page is in a different folder, let's adjust the HTML 'base' attribute + // to make the relative hyperlinks in the page work + $sServerName = $_SERVER['SERVER_NAME']; + $sProtocol = isset($_SERVER['HTTPS']) ? 'https' : 'http'; + if ($sProtocol == 'http') + { + $sPort = ($_SERVER['SERVER_PORT'] == 80) ? '' : ':'.$_SERVER['SERVER_PORT']; + } + else + { + $sPort = ($_SERVER['SERVER_PORT'] == 443) ? '' : ':'.$_SERVER['SERVER_PORT']; + } + $sUrl = "$sProtocol://{$sServerName}{$sPort}/pages/"; + $oP->set_base($sUrl); cmdbAbstractObject::DisplaySet($oP, $oSet, array('menu' => false)); break;