protected $_head; # Settings for this application protected $_app; # Default values array. protected $_default; public function __construct($index=null) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); # If we done have a configuration, then our IMGDIR and CSS are not defined if (! defined('IMGDIR')) define('IMGDIR','images/default'); if (! defined('CSSDIR')) define('CSSDIR','css/default'); $this->index = $index; # To be defined in a configuration file. $this->_app['title'] = app_name(); $this->_app['logo'] = IMGDIR.'/logo-small.png'; if (! is_null($index)) $this->_app['urlcss'] = sprintf('%s/%s',CSSDIR,$_SESSION[APPCONFIG]->getValue('appearance','stylesheet')); else $this->_app['urlcss'] = sprintf('%s/%s',CSSDIR,'style.css'); # Default Values for configurable items. $this->_default['sysmsg']['error'] = IMGDIR.'/error-big.png'; $this->_default['sysmsg']['warn'] = IMGDIR.'/warn-big.png'; $this->_default['sysmsg']['info'] = IMGDIR.'/info-big.png'; # Capture any output so far (in case we send some headers below) - there shouldnt be any output anyway. $preOutput = ''; # Try and work around if php compression is on, or the user has set compression in the config. # type = 1 for user gzip, 0 for php.ini gzip. $obStatus = ob_get_status(); if (isset($obStatus['type']) && $obStatus['type'] && $obStatus['status']) { $preOutput = ob_get_contents(); ob_end_clean(); } header('Content-type: text/html; charset="UTF-8"'); if (isCompress()) { header('Content-Encoding: gzip'); if (defined('DEBUG_ENABLED') && DEBUG_ENABLED) debug_log('Sent COMPRESSED header to browser and discarded (%s)',129,0,__FILE__,__LINE__,__METHOD__,$preOutput); } if (isset($_SESSION[APPCONFIG]) && $_SESSION[APPCONFIG]->getValue('appearance','compress') && ini_get('zlib.output_compression')) $this->setsysmsg(array('title'=>_('Warning'),'body'=>_('WARNING: You cannot have PHP compression and application compression enabled at the same time. Please unset zlib.output_compression or set $config->custom->appearance[\'compress\']=false'),'type'=>'warn')); # Turn back on output buffering. ob_start(); # Initial Values $this->_pageheader[] = ''; $this->_pageheader[] .= ''."\n"; } /* Add to the HTML Header */ public function head_add($html) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); $this->_head[] .= $html; } /* Print out the HTML header */ private function pageheader_print() { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); # HTML prepage requirements. foreach ($this->_pageheader as $line) echo $line."\n"; # Page Title echo ''; printf(''); $DNs = get_request('dn','REQUEST'); if (is_array($DNs)) $DNs = ''; if (isset($_SESSION[APPCONFIG])) printf('%s (%s) - %s%s', $this->_app['title'], app_version(), $DNs ? htmlspecialchars($DNs).' ' : '', $_SESSION[APPCONFIG]->getValue('appearance','page_title')); else printf('%s - %s',$this->_app['title'],app_version()); echo ''; # Style sheet. printf('',$this->_app['urlcss']); if (defined('JSDIR')) { printf('',JSDIR); echo "\n"; printf('',JSDIR); printf('',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 && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); if (isset($_SESSION[APPCONFIG])) $pagetitle = $_SESSION[APPCONFIG]->getValue('appearance','page_title') ? ' - '.$_SESSION[APPCONFIG]->getValue('appearance','page_title') : ''; else $pagetitle = ''; echo ''; echo '
'; printf('',get_href('sf'),$this->_app['logo']); echo ''; echo '
'; $empty = true; if (function_exists('cmd_control_pane')) foreach (cmd_control_pane('top') as $cmddetails) if ((isset($cmddetails['enable']) && $cmddetails['enable']) || ! isset($cmddetails['enable'])) { if (! $empty) echo ' '; printf('%s',$cmddetails['link'],$cmddetails['image']); $empty = false; } if ($empty) echo ' '; echo '
'; echo ''; echo "\n"; } private function control_print() { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); echo ''; echo ''; if ($empty) echo ''; echo ''; echo '
'; $empty = true; if (function_exists('cmd_control_pane')) foreach (cmd_control_pane('main') as $cmddetails) if ((isset($cmddetails['enable']) && trim($cmddetails['enable'])) || ! isset($cmddetails['enable'])) { if (! $empty) echo ' | '; printf('%s',$cmddetails['link'], (isset($_SESSION[APPCONFIG]) && $_SESSION[APPCONFIG]->getValue('appearance','control_icons')) ? $cmddetails['image'] : $cmddetails['title']); $empty = false; } echo ' 
'; } protected function tree() { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); if (! isset($_SESSION[APPCONFIG])) return; if (is_null($this->index)) $this->index = min(array_keys($_SESSION[APPCONFIG]->getServerList())); if (count($_SESSION[APPCONFIG]->getServerList()) > 1) { echo '
'; echo '
'; printf('%s:
%s',('Server Select'), server_select_list($this->index,false,'index',true,sprintf("onchange=\"tree_unhide('index',%s)\"",$this->index))); echo '
'; echo '
'; echo "\n\n"; } foreach ($_SESSION[APPCONFIG]->getServerList() as $index => $server) { printf('
',$server->getIndex(),($server->getIndex() == $this->index) ? 'block' : 'none'); $tree = Tree::getInstance($server->getIndex()); $tree->draw(); echo '
'; echo "\n\n"; } } public function block_add($side,$object) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); if (! is_object($object)) error(sprintf('block_add called with [%s], but it is not an object',serialize($object))); $this->_block[$side][] = $object; } private function block_print($side) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); 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 && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); 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']); } } } private function body($raw=false) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); # Add the Session System Messages if (isset($_SESSION['sysmsg']) && is_array($_SESSION['sysmsg'])) { foreach ($_SESSION['sysmsg'] as $msg) $this->setsysmsg($msg); 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',$raw); } private function footer_print() { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); printf('%s
%s
%s', isCompress() ? '[C]' : ' ', app_version(), get_href('logo') ? sprintf('SourceForge.net Logo',get_href('sf'),get_href('logo')) : ' '); } /** * Only show a particular page frame - used by an AJAX call */ public function show($frame,$compress=false,$raw=false) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); # If the body is called via AJAX, and compression is enable, we need to compress the output if ($compress && ob_get_level() && isCompress()) { ob_end_clean(); ob_start(); } switch ($frame) { case 'BODY': $this->body($raw); break; case 'TREE': $this->tree(); break; default: error(sprintf('show called with unknown frame [%s]',$frame),'error','index.php'); } if ($compress && ob_get_level() && isCompress()) { $output = ob_get_contents(); ob_end_clean(); if (defined('DEBUG_ENABLED') && DEBUG_ENABLED) debug_log('Sending COMPRESSED output to browser[(%s),%s]',129,0,__FILE__,__LINE__,__METHOD__, strlen($output),$output); print gzencode($output); } } public function display($filter=array()) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); # Control what is displayed. $display = array( 'HEAD'=>false, 'CONTROL'=>false, 'TREE'=>true, 'FOOT'=>false ); $display = array_merge($display,$filter); # HTML Header $this->pageheader_print(); # Start of body # Page Header echo ''; echo "\n"; echo ''; if ($display['HEAD']) $this->head_print(); # Control Line if ($display['CONTROL']) { echo ''; echo "\n"; } # Left Block echo ''; if ($display['TREE']) { echo ''; } echo ''; echo ''; echo "\n"; # Page Footer if ($display['FOOT']) $this->footer_print(); # Finish HTML echo '
'; echo '
'; $this->control_print(); echo '
'; printf('',_('Hide/Unhide the tree'),IMGDIR); echo '
'; $this->tree(); echo '
'; echo '
'; echo '
'; echo "\n"; $this->body(); echo '
'; echo '
'; echo ''; echo ''; # compress output if (ob_get_level() && isCompress()) { $output = ob_get_contents(); ob_end_clean(); if (defined('DEBUG_ENABLED') && DEBUG_ENABLED) debug_log('Sending COMPRESSED output to browser[(%s),%s]',129,0,__FILE__,__LINE__,__METHOD__, strlen($output),$output); print gzencode($output); } } public function setsysmsg($data) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); if (! is_array($data)) return; if (isset($this->sysmsg)) $msgnum = count($this->sysmsg) + 1; else $msgnum = 1; foreach (array('title','body','type') as $index) if (isset($data[$index])) $this->sysmsg[$msgnum][$index] = $data[$index]; } } /** * This class draws a block. * * @package phpLDAPadmin * @subpackage Page */ class block { private $title; private $body; private $foot; 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,$raw=false) { $output = ''; if ($raw) $output .= $this->body; else { $output .= sprintf('',$side); if (isset($this->title)) $output .= sprintf('',$this->title); if (isset($this->body)) $output .= sprintf('',$this->body); if (isset($this->footer)) $output .= sprintf('',$this->foot); $output .= '
%s
%s
%s
'; } return $output; } } ?>