private $_head; # Settings for this application private $_app; # Default values array. private $_default; public function __construct($server_id=null) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED) debug_log('Entered with [%s]',129,__FILE__,__LINE__,__METHOD__,$server_id); # To be defined in a configuration file. $this->_app['title'] = 'phpLDAPadmin'; # Default Values for configurable items. $this->_default['stylecss'] = CSSDIR.'style.css'; $this->_default['logo'] = 'images/logo_small.jpg'; $this->_default['sysmsg']['error'] = 'images/warning.png'; $this->_default['sysmsg']['warn'] = 'images/notice.png'; $this->_default['sysmsg']['info'] = 'images/light-big.png'; # Capture any output so far (in case we send some headers below) - there shouldnt be any output anyway. $preOutput = ''; if (ob_get_level()) { $preOutput = ob_get_contents(); ob_end_clean(); } //header('Content-type: text/html; charset="UTF-8"'); @todo: Something is sending output to the browser. if (isset($_SESSION['plaConfig']) && $_SESSION['plaConfig']->GetValue('appearance','compress') && eregi('gzip',$_SERVER['HTTP_ACCEPT_ENCODING'])) { header('Content-Encoding: gzip'); if (DEBUG_ENABLED) debug_log('Sent COMPRESSED header to browser and discarded (%s)',129,__FILE__,__LINE__,__METHOD__,$preOutput); } # Turn back on output buffering. ob_start(); # Initial Values $this->_pageheader[] .= ''."\n"; $this->_pageheader[] .= '_pageheader[] .= '"http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">'."\n"; $this->_pageheader[] .= "\n"; $this->_pageheader[] .= ''."\n"; $this->_pageheader[] .= "\n"; $this->_app['logo'] = $this->_default['logo']; if (! is_null($server_id)) $this->_app['urlcss'] = sprintf('%s%s',CSSDIR,$_SESSION['plaConfig']->GetValue('appearance','stylesheet')); else $this->_app['urlcss'] = sprintf('%s%s',CSSDIR,'style.css'); $this->server_id = $server_id; } /* Add to the HTML Header */ public function head_add($html) { $this->_head[] .= $html; } /* Print out the HTML header */ private function pageheader_print() { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED) debug_log('Entered with ()',129,__FILE__,__LINE__,__METHOD__); # HTML prepage requirements. foreach ($this->_pageheader as $line) echo $line."\n"; # Page Title echo ''; if (isset($_SESSION['plaConfig'])) printf('%s (%s) - %s', $this->_app['title'],pla_version(),$_SESSION['plaConfig']->GetValue('appearance','page_title')); else printf('%s - %s',$this->_app['title'],pla_version()); # Style sheet. printf('',$this->_app['urlcss']); printf('',JSDIR); printf('','../htdocs/'.JSDIR); printf('','../htdocs/'); echo "\n"; printf('',JSDIR); printf('',JSDIR); printf('',JSDIR); printf('','../htdocs/'.JSDIR); printf('','../htdocs/'.JSDIR); echo "\n"; # HTML head requirements. if (is_array($this->_head) && count ($this->_head)) foreach ($this->_head as $line) echo $line."\n"; echo ''; echo "\n"; } private function head_print() { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED) debug_log('Entered with ()',129,__FILE__,__LINE__,__METHOD__); if (isset($_SESSION['plaConfig'])) $pagetitle = $_SESSION['plaConfig']->GetValue('appearance','page_title') ? ' - '.$_SESSION['plaConfig']->GetValue('appearance','page_title') : ''; else $pagetitle = ''; echo ''; if (is_null($this->server_id)) printf('%s',' '); else printf('%s %s',$this->_app['title'],$pagetitle); echo ''; } private function control_print() { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED) debug_log('Entered with ()',129,__FILE__,__LINE__,__METHOD__); if (! isset($this->server_id) || is_null($this->server_id)) { echo ' '; return; } echo ''; echo ''; $empty = true; if ($_SESSION['plaConfig']->isCommandAvailable('home')) { printf('', _('Home'),_('Home'),_('Home')); $empty = false; } if ($_SESSION['plaConfig']->isCommandAvailable('purge')) { printf('', _('Purge caches'),_('Purge all cached data in phpLDAPadmin, including server schemas.'),_('Purge caches')); $empty = false; } if ($_SESSION['plaConfig']->isCommandAvailable('external_links', 'feature')) { printf('', get_href('add_rfe'),_('Request feature'),_('light'),_('Request feature')); $empty = false; } if ($_SESSION['plaConfig']->isCommandAvailable('external_links', 'bug')) { printf('', get_href('add_bug'),_('Report a bug'),_('bug'),_('Report a bug')); $empty = false; } if ($_SESSION['plaConfig']->isCommandAvailable('external_links', 'donation')) { printf('', get_href('donate'),_('Donate'),_('Donate'),_('Donate')); $empty = false; } if (! $_SESSION['plaConfig']->GetValue('appearance','hide_debug_info')) { printf('', _('Show Cache'),_('Show Cache'),_('Show Cache')); $empty = false; } if ($_SESSION['plaConfig']->isCommandAvailable('external_links', 'help')) { printf('', get_href('documentation'),_('Help'),_('Help'),_('Help')); $empty = false; } if ($empty) { echo ''; } printf('',$this->_app['logo']); echo ''; echo '
%s
%s
%s
%s
%s
%s
%s
%s
%s
%s
%s
%s
%s
%s
 
'; } protected function tree() { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED) debug_log('Entered with ()',129,__FILE__,__LINE__,__METHOD__); if (! isset($_SESSION['plaConfig'])) return; $server_id = is_null($this->server_id) ? min($_SESSION['plaConfig']->ldapservers->GetServerList()) : $this->server_id; echo ''; if (count(server_info_list(true)) > 1) { echo '
'; echo '
'; printf('%s%s
%s',_('Server Select'),_(':'), server_select_list($server_id,false,'server_id',sprintf("onchange=\"tree_unhide('server_id',%s)\"",$server_id))); echo '
'; echo '
'; echo "\n\n"; } foreach ($_SESSION['plaConfig']->ldapservers->GetServerList() as $server_id) { printf('
',$server_id,($server_id == $this->server_id) ? 'block': 'none'); $ldapserver = $_SESSION['plaConfig']->ldapservers->Instance($server_id); $tree = Tree::getInstance($ldapserver->server_id); $tree->draw(); echo '
'; } echo ''; } public function block_add($side,$object) { if (! is_object($object)) error('not an object'); $this->_block[$side][] = $object; } private function block_print($side) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED) debug_log('Entered with ()',129,__FILE__,__LINE__,__METHOD__); if (! isset($this->_block[$side])) return; printf('',$side); foreach ($this->_block[$side] as $object) echo $object->draw($side); echo ''; } private function sysmsg() { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED) debug_log('Entered with ()',129,__FILE__,__LINE__,__METHOD__); if (isset($this->sysmsg)) { foreach ($this->sysmsg as $index => $details) { switch ($details['type']) { case 'error': $icon = $this->_default['sysmsg']['error']; break; case 'warn': $icon = $this->_default['sysmsg']['warn']; break; case 'info': default: $icon = $this->_default['sysmsg']['info']; break; } if (isset($details['title'])) printf('%s%s', $icon,$details['type'],$details['title']); if (isset($details['body'])) if (is_array($details['body'])) { echo ''; foreach ($details['body'] as $line) printf('%s
',$line); echo ''; } else printf('%s',$details['body']); } } } public function body($compress=false) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED) debug_log('Entered with (%s)',129,__FILE__,__LINE__,__METHOD__,$compress); # If the body is called via AJAX, and compression is enable, we need to compress the output if ($compress && ob_get_level()) { ob_end_clean(); ob_start(); } # System Message if (isset($_SESSION['sysmsg']) && $_SESSION['sysmsg']) { $this->setsysmsg($_SESSION['sysmsg']); unset($_SESSION['sysmsg']); } if (isset($this->sysmsg)) { echo ''; $this->sysmsg(); echo '
'; echo "\n"; } if (isset($this->_block['body'])) { foreach ($this->_block['body'] as $object) echo $object->draw('body'); } if ($compress && ob_get_level() && isset($_SESSION['plaConfig']) && $_SESSION['plaConfig']->GetValue('appearance','compress') && eregi('gzip',$_SERVER['HTTP_ACCEPT_ENCODING'])) { $output = ob_get_contents(); ob_end_clean(); if (DEBUG_ENABLED) debug_log('Sending COMPRESSED output to browser[(%s),%s]',129,__FILE__,__LINE__,__METHOD__, strlen($output),$output); print gzencode($output); } } private function footer_print() { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED) debug_log('Entered with ()',129,__FILE__,__LINE__,__METHOD__); printf('%s',pla_version()); } public function display($filter=array()) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED) debug_log('Entered with [%s]',129,__FILE__,__LINE__,__METHOD__,$filter); # Control what is displayed. $display = array( 'tree'=>true ); $display = array_merge($display,$filter); # HTML Header $this->pageheader_print(); echo "\n"; # Start of body # Page Header echo ''; echo "\n"; echo ''; $this->head_print(); echo "\n"; # Control Line echo ''; echo "\n"; # Left Block echo ''; if ($display['tree']) { # $this->block_print('tree'); $this->tree(); echo "\n"; } echo ''; echo ''; echo "\n"; # Page Footer $this->footer_print(); # Finish HTML echo '
'; $this->control_print(); echo '
'; echo '
'; echo "\n"; $this->body(); echo '
'; echo '
'; echo ''; echo ''; # compress output if (ob_get_level() && isset($_SESSION['plaConfig']) && $_SESSION['plaConfig']->GetValue('appearance','compress') && eregi('gzip',$_SERVER['HTTP_ACCEPT_ENCODING'])) { $output = ob_get_contents(); ob_end_clean(); if (DEBUG_ENABLED) debug_log('Sending COMPRESSED output to browser[(%s),%s]',129,__FILE__,__LINE__,__METHOD__, strlen($output),$output); print gzencode($output); } } public function setsysmsg($data) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED) debug_log('Entered with [%s]',129,__FILE__,__LINE__,__METHOD__,$data); if (! is_array($data)) return; if (isset($this->sysmsg)) $nummsg = count($this->sysmsg); else $nummsg = 1; foreach ($data as $msgno => $msgarray) { $msgindex = $msgno + $nummsg; foreach (array('title','body','type') as $index) if (isset($msgarray[$index])) $this->sysmsg[$msgindex][$index] = $msgarray[$index]; } } } class block { private $title; private $body; private $foot; public function __construct() { } public function setTitle($html) { $this->title = $html; } public function setBody($html) { $this->body = $html; } public function setFooter($html) { $this->foot = $html; } public function draw($side) { $output = ''; $output .= sprintf('',$side); if (isset($this->body['title'])) $output .= sprintf('',$this->title); if (isset($this->body['body'])) $output .= sprintf('',$this->body); if (isset($this->body['footer'])) $output .= sprintf('',$this->foot); $output .= '
%s
%s
%s
'; return $output; } } ?>