* @author Romain Quetiez * @author Denis Flaven * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL */ require_once('../approot.inc.php'); require_once(APPROOT."/application/webpage.class.inc.php"); class ajax_page extends WebPage { /** * Jquery style ready script * @var Hash */ protected $m_sReadyScript; protected $m_sCurrentTab; protected $m_sCurrentTabContainer; protected $m_aTabs; /** * constructor for the web page * @param string $s_title Not used */ function __construct($s_title) { parent::__construct($s_title); $this->m_sReadyScript = ""; $this->add_header("Content-type: text/html; charset=utf-8"); $this->add_header("Cache-control: no-cache"); $this->m_sCurrentTabContainer = ''; $this->m_sCurrentTab = ''; $this->m_aTabs = array(); } public function AddTabContainer($sTabContainer, $sPrefix = '') { $this->m_aTabs[$sTabContainer] = array('content' =>'', 'prefix' => $sPrefix); $this->add("\$Tabs:$sTabContainer\$"); } public function AddToTab($sTabContainer, $sTabLabel, $sHtml) { if (!isset($this->m_aTabs[$sTabContainer]['content'][$sTabLabel])) { // Set the content of the tab $this->m_aTabs[$sTabContainer]['content'][$sTabLabel] = $sHtml; } else { // Append to the content of the tab $this->m_aTabs[$sTabContainer]['content'][$sTabLabel] .= $sHtml; } } public function SetCurrentTabContainer($sTabContainer = '') { $sPreviousTabContainer = $this->m_sCurrentTabContainer; $this->m_sCurrentTabContainer = $sTabContainer; return $sPreviousTabContainer; } public function SetCurrentTab($sTabLabel = '') { $sPreviousTab = $this->m_sCurrentTab; $this->m_sCurrentTab = $sTabLabel; return $sPreviousTab; } /** * Echoes the content of the whole page * @return void */ public function output() { foreach($this->a_headers as $s_header) { header($s_header); } if (count($this->m_aTabs) > 0) { $this->add_ready_script( <<m_aTabs as $sTabContainerName => $aTabContainer) { $sTabs = ''; $m_aTabs = $aTabContainer['content']; $sPrefix = $aTabContainer['prefix']; $container_index = 0; if (count($m_aTabs) > 0) { $sTabs = "\n
\n"; $sTabs .= "\n"; // Now add the content of the tabs themselves $i = 0; foreach($m_aTabs as $sTabName => $sTabContent) { $sTabs .= "
".$sTabContent."
\n"; $i++; } $sTabs .= "
\n\n"; } $this->s_content = str_replace("\$Tabs:$sTabContainerName\$", $sTabs, $this->s_content); $container_index++; } $s_captured_output = ob_get_contents(); ob_end_clean(); echo $this->s_content; echo $this->s_deferred_content; if (count($this->a_scripts) > 0) { echo "\n"; } if (!empty($this->m_sReadyScript)) { echo "\n"; } if (trim($s_captured_output) != "") { echo $s_captured_output; } } /** * Adds a paragraph with a smaller font into the page * NOT implemented (i.e does nothing) * @param string $sText Content of the (small) paragraph * @return void */ public function small_p($sText) { } public function add($sHtml) { if (!empty($this->m_sCurrentTabContainer) && !empty($this->m_sCurrentTab)) { $this->AddToTab($this->m_sCurrentTabContainer, $this->m_sCurrentTab, $sHtml); } else { parent::add($sHtml); } } /** * Adds a script to be executed when the DOM is ready (typical JQuery use) * NOT implemented in this version of the class. * @return void */ public function add_ready_script($sScript) { // Does nothing in ajax rendered content.. for now... // Maybe we should add this as a simple