/** * Class WebPage * * @copyright Copyright (C) 2010-2015 Combodo SARL * @license http://opensource.org/licenses/AGPL-3.0 */ /** * Generic interface common to CLI and Web pages */ Interface Page { public function output(); public function add($sText); public function p($sText); public function pre($sText); public function add_comment($sText); public function table($aConfig, $aData, $aParams = array()); } /** * Simple helper class to ease the production of HTML pages * * This class provide methods to add content, scripts, includes... to a web page * and renders the full web page by putting the elements in the proper place & order * when the output() method is called. * Usage: * $oPage = new WebPage("Title of my page"); * $oPage->p("Hello World !"); * $oPage->output(); */ class WebPage implements Page { protected $s_title; protected $s_content; protected $s_deferred_content; protected $a_scripts; protected $a_dict_entries; protected $a_styles; protected $a_include_scripts; protected $a_include_stylesheets; protected $a_headers; protected $a_base; protected $iNextId; protected $iTransactionId; protected $sContentType; protected $sContentDisposition; protected $sContentFileName; protected $bTrashUnexpectedOutput; protected $s_sOutputFormat; protected $a_OutputOptions; protected $bPrintable; public function __construct($s_title, $bPrintable = false) { $this->s_title = $s_title; $this->s_content = ""; $this->s_deferred_content = ''; $this->a_scripts = array(); $this->a_dict_entries = array(); $this->a_styles = array(); $this->a_linked_scripts = array(); $this->a_linked_stylesheets = array(); $this->a_headers = array(); $this->a_base = array( 'href' => '', 'target' => ''); $this->iNextId = 0; $this->iTransactionId = 0; $this->sContentType = ''; $this->sContentDisposition = ''; $this->sContentFileName = ''; $this->bTrashUnexpectedOutput = false; $this->s_OutputFormat = utils::ReadParam('output_format', 'html'); $this->a_OutputOptions = array(); $this->bPrintable = $bPrintable; ob_start(); // Start capturing the output } /** * Change the title of the page after its creation */ public function set_title($s_title) { $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 */ public function add($s_html) { $this->s_content .= $s_html; } /** * Add any text or HTML fragment (identified by an ID) at the end of the body of the page * This is useful to add hidden content, DIVs or FORMs that should not * be embedded into each other. */ public function add_at_the_end($s_html, $sId = '') { $this->s_deferred_content .= $s_html; } /** * Add a paragraph to the body of the page */ public function p($s_html) { $this->add($this->GetP($s_html)); } /** * Add a pre-formatted text to the body of the page */ public function pre($s_html) { $this->add('
'.$s_html.''); } /** * Add a comment */ public function add_comment($sText) { $this->add(''); } /** * Add a paragraph to the body of the page */ public function GetP($s_html) { return "
$s_html
\n"; } /** * Adds a tabular content to the web page * @param Hash $aConfig Configuration of the table: hash array of 'column_id' => 'Column Label' * @param Hash $aData Hash array. Data to display in the table: each row is made of 'column_id' => Data. A column 'pkey' is expected for each row * @param Hash $aParams Hash array. Extra parameters for the table. * @return void */ public function table($aConfig, $aData, $aParams = array()) { $this->add($this->GetTable($aConfig, $aData, $aParams)); } public function GetTable($aConfig, $aData, $aParams = array()) { $oAppContext = new ApplicationContext(); static $iNbTables = 0; $iNbTables++; $sHtml = ""; $sHtml .= "".$aDef['label']." | \n"; } $sHtml .= "
---|
".$aAttrib['label']." | ".implode(" | ", $aAttrib['value'])." | \n"; } else { $sHtml .= "".$aAttrib['label']." | ".$aAttrib['value']." | \n"; } $sComment = (isset($aAttrib['comments'])) ? $aAttrib['comments'] : ' '; $sInfo = (isset($aAttrib['infos'])) ? $aAttrib['infos'] : ' '; $sHtml .= "$sComment | $sInfo | \n"; $sHtml .= "