Преглед на файлове

Fixed the HTML display in the export webservice page. (Trac #58)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@199 a333f486-631f-4898-b8df-5754b55c2be0
dflaven преди 15 години
родител
ревизия
7b4b62270a
променени са 3 файла, в които са добавени 47 реда и са изтрити 0 реда
  1. 1 0
      application/itopwebpage.class.inc.php
  2. 31 0
      application/webpage.class.inc.php
  3. 15 0
      webservices/export.php

+ 1 - 0
application/itopwebpage.class.inc.php

@@ -214,6 +214,7 @@ EOF
         echo "<html>\n";
         echo "<head>\n";
         echo "<title>{$this->s_title}</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)

+ 31 - 0
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
     }
 	
@@ -41,6 +43,15 @@ class web_page
     }
     
 	/**
+	 * 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
 	 */
     public function add($s_html)
@@ -227,6 +238,7 @@ class web_page
         echo "<html>\n";
         echo "<head>\n";
         echo "<title>{$this->s_title}</title>\n";
+        echo $this->get_base_tag();
         foreach($this->a_linked_scripts as $s_script)
         {
             echo "<script type=\"text/javascript\" src=\"$s_script\"></script>\n";
@@ -285,5 +297,24 @@ class web_page
 			$this->add("<input type=\"hidden\" name=\"".$sLabel."[$sKey]\" value=\"$sValue\">");
 		}
 	}
+
+	protected function get_base_tag()
+	{
+		$sTag = '';
+        if (($this->a_base['href'] != '') || ($this->a_base['target'] != ''))
+        {
+        	$sTag = '<base ';
+        	if (($this->a_base['href'] != ''))
+        	{
+        		$sTag .= "href =\"{$this->a_base['href']}\" ";
+			}
+        	if (($this->a_base['target'] != ''))
+        	{
+        		$sTag .= "target =\"{$this->a_base['target']}\" ";
+			}
+			$sTag .= " />\n";
+		}
+		return $sTag;
+	}
 }
 ?>

+ 15 - 0
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;