2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Used to render the footer of PMA's pages
8 if (! defined('PHPMYADMIN')) {
12 require_once 'libraries/Scripts.class.php';
15 * Class used to output the footer
22 * PMA_Scripts instance
29 * Whether we are servicing an ajax request.
30 * We can't simply use $GLOBALS['is_ajax_request']
31 * here since it may have not been initialised yet.
38 * Whether to only close the BODY and HTML tags
39 * or also include scripts, errors and links
46 * Whether to display anything
54 * Creates a new class instance
56 * @return new PMA_Footer object
58 public function __construct()
60 $this->_isEnabled
= true;
61 $this->_scripts
= new PMA_Scripts();
62 $this->_isMinimal
= false;
66 * Renders the debug messages
70 private function _getDebugMessage()
73 if (! empty($_SESSION['debug'])) {
76 foreach ($_SESSION['debug']['queries'] as $query) {
77 $sum_time +
= $query['count'] * $query['time'];
78 $sum_exec +
= $query['count'];
81 $retval .= '<div id="session_debug">';
82 $retval .= count($_SESSION['debug']['queries']) . ' queries executed ';
83 $retval .= $sum_exec . ' times in ' . $sum_time . ' seconds';
87 print_r($_SESSION['debug']);
88 $retval .= ob_get_contents();
93 $_SESSION['debug'] = array();
99 * Returns the url of the current page
101 * @param mixed $encoding See PMA_generate_common_url()
105 public function getSelfUrl($encoding = null)
107 $db = ! empty($GLOBALS['db']) ?
$GLOBALS['db'] : '';
108 $table = ! empty($GLOBALS['table']) ?
$GLOBALS['table'] : '';
109 $target = ! empty($_REQUEST['target']) ?
$_REQUEST['target'] : '';
110 return basename(PMA_getenv('SCRIPT_NAME')) . PMA_generate_common_url(
114 'server' => $GLOBALS['server'],
122 * Renders the link to open a new page
124 * @param string $url The url of the page
128 private function _getSelfLink($url)
131 $retval .= '<div id="selflink" class="print_ignore">';
132 $retval .= '<a href="' . $url . '"'
133 . ' title="' . __('Open new phpMyAdmin window') . '" target="_blank">';
134 if ($GLOBALS['cfg']['NavigationBarIconic']) {
135 $retval .= PMA_Util
::getImage(
137 __('Open new phpMyAdmin window')
140 $retval .= __('Open new phpMyAdmin window');
148 * Renders the link to open a new page
152 public function getErrorMessages()
155 if ($GLOBALS['error_handler']->hasDisplayErrors()) {
156 $retval .= '<div class="clearfloat" id="pma_errors">';
157 $retval .= $GLOBALS['error_handler']->getDispErrors();
164 * Saves query in history
168 private function _setHistory()
170 if (! PMA_isValid($_REQUEST['no_history'])
171 && empty($GLOBALS['error_message'])
172 && ! empty($GLOBALS['sql_query'])
175 PMA_ifSetOr($GLOBALS['db'], ''),
176 PMA_ifSetOr($GLOBALS['table'], ''),
177 $GLOBALS['cfg']['Server']['user'],
178 $GLOBALS['sql_query']
184 * Disables the rendering of the footer
188 public function disable()
190 $this->_isEnabled
= false;
194 * Set the ajax flag to indicate whether
195 * we are sevicing an ajax request
197 * @param bool $isAjax Whether we are sevicing an ajax request
201 public function setAjax($isAjax)
203 $this->_isAjax
= ($isAjax == true);
207 * Turn on minimal display mode
211 public function setMinimal()
213 $this->_isMinimal
= true;
217 * Returns the PMA_Scripts object
219 * @return PMA_Scripts object
221 public function getScripts()
223 return $this->_scripts
;
231 public function getDisplay()
234 $this->_setHistory();
235 if ($this->_isEnabled
) {
236 if (! $this->_isAjax
) {
239 if (! $this->_isAjax
&& ! $this->_isMinimal
) {
240 if (PMA_getenv('SCRIPT_NAME')
242 && empty($GLOBALS['checked_special'])
245 $url = $this->getSelfUrl('unencoded');
246 $header = PMA_Response
::getInstance()->getHeader();
247 $scripts = $header->getScripts()->getFiles();
248 $menuHash = $header->getMenu()->getHash();
249 // prime the client-side cache
250 $this->_scripts
->addCode(
252 'AJAX.cache.primer = {'
257 PMA_escapeJsString($url),
258 json_encode($scripts),
259 PMA_escapeJsString($menuHash)
262 $url = $this->getSelfUrl();
263 $retval .= $this->_getSelfLink($url);
265 $retval .= $this->_getDebugMessage();
266 $retval .= $this->getErrorMessages();
267 $retval .= $this->_scripts
->getDisplay();
268 // Include possible custom footers
269 if (file_exists(CUSTOM_FOOTER_FILE
)) {
271 include CUSTOM_FOOTER_FILE
;
272 $retval .= ob_get_contents();
276 if (! $this->_isAjax
) {
277 $retval .= "</body></html>";