Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / Footer.class.php
bloba0d14ad525bdc279a9eed6b84669972486655062
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 object
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 * @return new PMA_Footer object
58 public function __construct()
60 $this->_isEnabled = true;
61 $this->_scripts = new PMA_Scripts();
62 $this->_isMinimal = false;
65 /**
66 * Renders the debug messages
68 * @return string
70 private function _getDebugMessage()
72 $retval = '';
73 if (! empty($_SESSION['debug'])) {
74 $sum_time = 0;
75 $sum_exec = 0;
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';
84 $retval .= '<pre>';
86 ob_start();
87 print_r($_SESSION['debug']);
88 $retval .= ob_get_contents();
89 ob_end_clean();
91 $retval .= '</pre>';
92 $retval .= '</div>';
93 $_SESSION['debug'] = array();
95 return $retval;
98 /**
99 * Returns the url of the current page
101 * @param mixed $encoding See PMA_generate_common_url()
103 * @return string
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(
111 array(
112 'db' => $db,
113 'table' => $table,
114 'server' => $GLOBALS['server'],
115 'target' => $target
117 $encoding
122 * Renders the link to open a new page
124 * @param string $url The url of the page
126 * @return string
128 private function _getSelfLink($url)
130 $retval = '';
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(
136 'window-new.png',
137 __('Open new phpMyAdmin window')
139 } else {
140 $retval .= __('Open new phpMyAdmin window');
142 $retval .= '</a>';
143 $retval .= '</div>';
144 return $retval;
148 * Renders the link to open a new page
150 * @return string
152 public function getErrorMessages()
154 $retval = '';
155 if ($GLOBALS['error_handler']->hasDisplayErrors()) {
156 $retval .= '<div class="clearfloat" id="pma_errors">';
157 $retval .= $GLOBALS['error_handler']->getDispErrors();
158 $retval .= '</div>';
160 return $retval;
164 * Saves query in history
166 * @return void
168 private function _setHistory()
170 if (! PMA_isValid($_REQUEST['no_history'])
171 && empty($GLOBALS['error_message'])
172 && ! empty($GLOBALS['sql_query'])
174 PMA_setHistory(
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
186 * @return void
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
199 * @return void
201 public function setAjax($isAjax)
203 $this->_isAjax = ($isAjax == true);
207 * Turn on minimal display mode
209 * @return void
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;
227 * Renders the footer
229 * @return string
231 public function getDisplay()
233 $retval = '';
234 $this->_setHistory();
235 if ($this->_isEnabled) {
236 if (! $this->_isAjax) {
237 $retval .= "</div>";
239 if (! $this->_isAjax && ! $this->_isMinimal) {
240 if (PMA_getenv('SCRIPT_NAME')
241 && empty($_POST)
242 && empty($GLOBALS['checked_special'])
243 && ! $this->_isAjax
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(
251 sprintf(
252 'AJAX.cache.primer = {'
253 . ' url: "%s",'
254 . ' scripts: %s,'
255 . ' menuHash: "%s"'
256 . '};',
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)) {
270 ob_start();
271 include CUSTOM_FOOTER_FILE;
272 $retval .= ob_get_contents();
273 ob_end_clean();
276 if (! $this->_isAjax) {
277 $retval .= "</body></html>";
281 return $retval;