1. Check existence of mb_string, mysql and xml extensions before installation.
[openemr.git] / phpmyadmin / libraries / Footer.class.php
blob3bcc06d73b4348cef7650afa2669d7e185615efd
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Used to render the footer of PMA's pages
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 require_once 'libraries/Scripts.class.php';
14 /**
15 * Class used to output the footer
17 * @package PhpMyAdmin
19 class PMA_Footer
21 /**
22 * PMA_Scripts instance
24 * @access private
25 * @var PMA_Scripts
27 private $_scripts;
28 /**
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.
33 * @access private
34 * @var bool
36 private $_isAjax;
37 /**
38 * Whether to only close the BODY and HTML tags
39 * or also include scripts, errors and links
41 * @access private
42 * @var bool
44 private $_isMinimal;
45 /**
46 * Whether to display anything
48 * @access private
49 * @var bool
51 private $_isEnabled;
53 /**
54 * Creates a new class instance
56 public function __construct()
58 $this->_isEnabled = true;
59 $this->_scripts = new PMA_Scripts();
60 $this->_isMinimal = false;
63 /**
64 * Returns the message for demo server to error messages
66 * @return string
68 private function _getDemoMessage()
70 $message = '<a href="/">' . __('phpMyAdmin Demo Server') . '</a>: ';
71 if (file_exists('./revision-info.php')) {
72 include './revision-info.php';
73 $message .= sprintf(
74 __('Currently running Git revision %1$s from the %2$s branch.'),
75 '<a target="_blank" href="' . $repobase . $fullrevision . '">'
76 . $revision . '</a>',
77 '<a target="_blank" href="' . $repobranchbase . $branch . '">'
78 . $branch . '</a>'
80 } else {
81 $message .= __('Git information missing!');
84 return PMA_Message::notice($message)->getDisplay();
87 /**
88 * Remove recursions and iterator objects from an object
90 * @param object|array &$object Object to clean
91 * @param array $stack Stack used to keep track of recursion,
92 * need not be passed for the first time
94 * @return object Reference passed object
96 private static function _removeRecursion(&$object, $stack = array())
98 if ((is_object($object) || is_array($object)) && $object) {
99 if ($object instanceof Traversable) {
100 $object = "***ITERATOR***";
101 } else if (!in_array($object, $stack, true)) {
102 $stack[] = $object;
103 foreach ($object as &$subobject) {
104 self::_removeRecursion($subobject, $stack);
106 } else {
107 $object = "***RECURSION***";
110 return $object;
114 * Renders the debug messages
116 * @return string
118 public function getDebugMessage()
120 $retval = '\'null\'';
121 if ($GLOBALS['cfg']['DBG']['sql']
122 && empty($_REQUEST['no_debug'])
123 && !empty($_SESSION['debug'])
125 // Remove recursions and iterators from $_SESSION['debug']
126 self::_removeRecursion($_SESSION['debug']);
128 $retval = JSON_encode($_SESSION['debug']);
129 $_SESSION['debug'] = array();
130 return json_last_error() ? '\'false\'' : $retval;
132 $_SESSION['debug'] = array();
133 return $retval;
137 * Returns the url of the current page
139 * @param string|null $encode See PMA_URL_getCommon()
141 * @return string
143 public function getSelfUrl($encode = 'html')
145 $db = ! empty($GLOBALS['db']) ? $GLOBALS['db'] : '';
146 $table = ! empty($GLOBALS['table']) ? $GLOBALS['table'] : '';
147 $target = ! empty($_REQUEST['target']) ? $_REQUEST['target'] : '';
148 $params = array(
149 'db' => $db,
150 'table' => $table,
151 'server' => $GLOBALS['server'],
152 'target' => $target
154 // needed for server privileges tabs
155 if (isset($_REQUEST['viewing_mode'])
156 && in_array($_REQUEST['viewing_mode'], array('server', 'db', 'table'))
158 $params['viewing_mode'] = $_REQUEST['viewing_mode'];
161 * @todo coming from server_privileges.php, here $db is not set,
162 * add the following condition below when that is fixed
163 * && $_REQUEST['checkprivsdb'] == $db
165 if (isset($_REQUEST['checkprivsdb'])
167 $params['checkprivsdb'] = $_REQUEST['checkprivsdb'];
170 * @todo coming from server_privileges.php, here $table is not set,
171 * add the following condition below when that is fixed
172 * && $_REQUEST['checkprivstable'] == $table
174 if (isset($_REQUEST['checkprivstable'])
176 $params['checkprivstable'] = $_REQUEST['checkprivstable'];
178 if (isset($_REQUEST['single_table'])
179 && in_array($_REQUEST['single_table'], array(true, false))
181 $params['single_table'] = $_REQUEST['single_table'];
183 return basename(PMA_getenv('SCRIPT_NAME')) . PMA_URL_getCommon(
184 $params,
185 $encode
190 * Renders the link to open a new page
192 * @param string $url The url of the page
194 * @return string
196 private function _getSelfLink($url)
198 $retval = '';
199 $retval .= '<div id="selflink" class="print_ignore">';
200 $retval .= '<a href="' . $url . '"'
201 . ' title="' . __('Open new phpMyAdmin window') . '" target="_blank">';
202 if (PMA_Util::showIcons('TabsMode')) {
203 $retval .= PMA_Util::getImage(
204 'window-new.png',
205 __('Open new phpMyAdmin window')
207 } else {
208 $retval .= __('Open new phpMyAdmin window');
210 $retval .= '</a>';
211 $retval .= '</div>';
212 return $retval;
216 * Renders the link to open a new page
218 * @return string
220 public function getErrorMessages()
222 $retval = '<div class="clearfloat" id="pma_errors">';
223 if ($GLOBALS['error_handler']->hasDisplayErrors()) {
224 $retval .= $GLOBALS['error_handler']->getDispErrors();
226 $retval .= '</div>';
229 * Report php errors
231 $GLOBALS['error_handler']->reportErrors();
233 return $retval;
237 * Saves query in history
239 * @return void
241 private function _setHistory()
243 if (! PMA_isValid($_REQUEST['no_history'])
244 && empty($GLOBALS['error_message'])
245 && ! empty($GLOBALS['sql_query'])
247 PMA_setHistory(
248 PMA_ifSetOr($GLOBALS['db'], ''),
249 PMA_ifSetOr($GLOBALS['table'], ''),
250 $GLOBALS['cfg']['Server']['user'],
251 $GLOBALS['sql_query']
257 * Disables the rendering of the footer
259 * @return void
261 public function disable()
263 $this->_isEnabled = false;
267 * Set the ajax flag to indicate whether
268 * we are servicing an ajax request
270 * @param bool $isAjax Whether we are servicing an ajax request
272 * @return void
274 public function setAjax($isAjax)
276 $this->_isAjax = !!$isAjax;
280 * Turn on minimal display mode
282 * @return void
284 public function setMinimal()
286 $this->_isMinimal = true;
290 * Returns the PMA_Scripts object
292 * @return PMA_Scripts object
294 public function getScripts()
296 return $this->_scripts;
300 * Renders the footer
302 * @return string
304 public function getDisplay()
306 $retval = '';
307 $this->_setHistory();
308 if ($this->_isEnabled) {
309 if (! $this->_isAjax) {
310 $retval .= "</div>";
312 if (! $this->_isAjax && ! $this->_isMinimal) {
313 if (PMA_getenv('SCRIPT_NAME')
314 && empty($_POST)
315 && empty($GLOBALS['checked_special'])
316 && ! $this->_isAjax
318 $url = $this->getSelfUrl('unencoded');
319 $header = PMA_Response::getInstance()->getHeader();
320 $scripts = $header->getScripts()->getFiles();
321 $menuHash = $header->getMenu()->getHash();
322 // prime the client-side cache
323 $this->_scripts->addCode(
324 sprintf(
325 'if (! (history && history.pushState)) '
326 . 'PMA_MicroHistory.primer = {'
327 . ' url: "%s",'
328 . ' scripts: %s,'
329 . ' menuHash: "%s"'
330 . '};',
331 PMA_escapeJsString($url),
332 json_encode($scripts),
333 PMA_escapeJsString($menuHash)
337 if (PMA_getenv('SCRIPT_NAME')
338 && ! $this->_isAjax
340 $url = $this->getSelfUrl();
341 $retval .= $this->_getSelfLink($url);
343 $this->_scripts->addCode(
344 'var debugSQLInfo = ' . $this->getDebugMessage() . ';'
346 $retval .= $this->getErrorMessages();
347 $retval .= $this->_scripts->getDisplay();
348 if ($GLOBALS['cfg']['DBG']['demo']) {
349 $retval .= '<div id="pma_demo">';
350 $retval .= $this->_getDemoMessage();
351 $retval .= '</div>';
353 // Include possible custom footers
354 if (file_exists(CUSTOM_FOOTER_FILE)) {
355 $retval .= '<div id="pma_footer">';
356 ob_start();
357 include CUSTOM_FOOTER_FILE;
358 $retval .= ob_get_contents();
359 ob_end_clean();
360 $retval .= '</div>';
363 if (! $this->_isAjax) {
364 $retval .= "</body></html>";
368 return $retval;