diff --git a/e107_admin/footer.php b/e107_admin/footer.php
index 0926fe1dc..17855f135 100644
--- a/e107_admin/footer.php
+++ b/e107_admin/footer.php
@@ -11,16 +11,51 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_admin/footer.php,v $
-| $Revision: 1.1.1.1 $
-| $Date: 2006-12-02 04:33:22 $
-| $Author: mcfly_e107 $
+| $Revision: 1.2 $
+| $Date: 2006-12-05 09:28:02 $
+| $Author: mrpete $
+----------------------------------------------------------------------------+
*/
-
if (!defined('e107_INIT')) { exit; }
+$In_e107_Footer = TRUE; // For registered shutdown function
+global $eTraffic, $error_handler, $db_time, $sql, $mySQLserver, $mySQLuser, $mySQLpassword, $mySQLdefaultdb, $ADMIN_FOOTER, $e107;
-global $ADMIN_FOOTER, $footer_js, $sql;
+//
+// SHUTDOWN SEQUENCE
+//
+// The following items have been carefully designed so page processing will finish properly
+// Please DO NOT re-order these items without asking first! You WILL break something ;)
+// These letters match the USER footer (that's why there is B.1,B.2)
+//
+// A Ensure sql and traffic objects exist
+// B.1 Clear cache if over a week old
+// B.2 Send the footer templated data
+// C Dump any/all traffic and debug information
+// [end of regular-page-only items]
+// D Close the database connection
+// E Themed footer code
+// F Configured footer scripts
+// G Browser-Server time sync script (must be the last one generated/sent)
+// H Final HTML (/body, /html)
+// I collect and send buffered page, along with needed headers
+//
+//
+// A Ensure sql and traffic objects exist
+//
+
+if(!is_object($sql)){
+ // reinstigate db connection if another connection from third-party script closed it ...
+ $sql = new db;
+ $sql -> db_Connect($mySQLserver, $mySQLuser, $mySQLpassword, $mySQLdefaultdb);
+}
+if (!is_object($eTraffic)) {
+ $eTraffic = new e107_traffic;
+ $eTraffic->Bump('Lost Traffic Counters');
+}
+//
+// B.1 Clear cache if over a week old
+//
if (ADMIN == TRUE) {
if ($pref['cachestatus']) {
if (!$sql->db_Select('generic', '*', "gen_type='empty_cache'"))
@@ -38,50 +73,117 @@ if (ADMIN == TRUE) {
}
}
}
+
+
+//
+// B.2 Send footer template
+//
if (strpos(e_SELF.'?'.e_QUERY, 'menus.php?configure') === FALSE) {
parse_admin($ADMIN_FOOTER);
}
+
+
+//
+// C Dump all debug and traffic information
+//
$eTimingStop = microtime();
-global $eTimingStart, $eTraffic;
+global $eTimingStart;
$rendertime = number_format($eTraffic->TimeDelta( $eTimingStart, $eTimingStop ), 4);
$db_time = number_format($db_time,4);
$rinfo = '';
-if($pref['displayrendertime']){ $rinfo .= "Render time: {$rendertime} second(s); {$db_time} of that for queries. "; }
-if($pref['displaysql']){ $rinfo .= "DB queries: ".$sql -> db_QueryCount().". "; }
-if(isset($pref['displaycacheinfo']) && $pref['displaycacheinfo']){ $rinfo .= $cachestring."."; }
-echo ($rinfo ? "\n
{$rinfo}
\n" : "");
+ if($pref['displayrendertime']){ $rinfo .= "Render time: {$rendertime} second(s); {$db_time} of that for queries. "; }
+ if($pref['displaysql']){ $rinfo .= "DB queries: ".$sql -> db_QueryCount().". "; }
+ if(isset($pref['display_memory_usage']) && $pref['display_memory_usage']){ $rinfo .= "Memory Usage: ".$e107->get_memory_usage(); }
+ if(isset($pref['displaycacheinfo']) && $pref['displaycacheinfo']){ $rinfo .= $cachestring."."; }
+ echo ($rinfo ? "\n{$rinfo}
\n" : "");
-if($error_handler->debug == true) {
- echo "
-
";
+ if ((ADMIN || $pref['developer']) && E107_DEBUG_LEVEL) {
+ global $db_debug;
+ echo "\n\n";
+ $db_debug->Show_All();
+ }
+
+ /*
+ changes by jalist 24/01/2005:
+ show sql queries
+ usage: add ?showsql to query string, must be admin
+ */
+
+ if(ADMIN && isset($queryinfo) && is_array($queryinfo))
+ {
+ $c=1;
+ $mySQLInfo = $sql->mySQLinfo;
+ echo "
+
+ ID | SQL Queries | \n
\n";
+ foreach ($queryinfo as $infovalue)
+ {
+ echo "\n\n
\n";
+ $c++;
+ }
+ echo "
";
+ }
+
+//
+// D Close DB connection. We're done talking to underlying MySQL
+//
+ $sql -> db_Close(); // Only one is needed; the db is only connected once even with several $sql objects
+
+ //
+ // Just before we quit: dump quick timer if there is any
+ // Works any time we get this far. Not calibrated, but it is quick and simple to use.
+ // To use: eQTimeOn(); eQTimeOff();
+ //
+ $tmp = eQTimeElapsed();
+ if (strlen($tmp)) {
+ global $ns;
+ $ns->tablerender('Quick Admin Timer',"Results: {$tmp} microseconds");
+ }
+
+if ($pref['developer']) {
+ global $oblev_at_start,$oblev_before_start;
+ if (ob_get_level() != $oblev_at_start) {
+ $oblev = ob_get_level();
+ $obdbg = "Software defect detected; ob_*() level {$oblev} at end instead of ($oblev_at_start). POPPING EXTRA BUFFERS!
";
+ while (ob_get_level() > $oblev_at_start) {
+ ob_end_flush();
+ }
+ echo $obdbg;
+ }
+ // 061109 PHP 5 has a bug such that the starting level might be zero or one.
+ // Until they work that out, we'll disable this message.
+ // Devs can re-enable for testing as needed.
+ //
+ if (0 && $oblev_before_start != 0) {
+ $obdbg = "Software warning; ob_*() level {$oblev_before_start} at start; this page not properly integrated into its wrapper.
";
+ echo $obdbg;
+ }
+}
+
+if((ADMIN == true || $pref['developer']) && $error_handler->debug == true) {
echo "
+
PHP Errors:
".$error_handler->return_errors()."
";
- $tmp = $eTraffic->Display();
- if (strlen($tmp)) {
- $ns->tablerender('Traffic Counters', $tmp);
- }
-
- $tmp = $db_debug->Show_Performance();
- if (strlen($tmp)) {
- $ns->tablerender('Time Analysis', $tmp);
- }
- $tmp = $db_debug->Show_SQL_Details();
- if (strlen($tmp)) {
- $ns->tablerender('SQL Analysis', $tmp);
- }
}
+//
+// E Last themed footer code, usually JS
+//
if (function_exists('theme_foot'))
{
echo theme_foot();
}
+//
+// F any included JS footer scripts
+//
+global $footer_js;
if(isset($footer_js) && is_array($footer_js))
{
$footer_js = array_unique($footer_js);
@@ -92,8 +194,57 @@ if(isset($footer_js) && is_array($footer_js))
}
}
+//
+// G final JS script keeps user and server time in sync.
+// It must be the last thing created before sending the page to the user.
+//
+// see e107.js and class2.php
+// This must be done as late as possible in page processing.
+$_serverTime=time();
+$lastSet = isset($_COOKIE['e107_tdSetTime']) ? $_COOKIE['e107_tdSetTime'] : 0;
+if (abs($_serverTime - $lastSet) > 120) {
+ /* update time delay every couple of minutes.
+ * Benefit: account for user time corrections and changes in internet delays
+ * Drawback: each update may cause all server times to display a bit different
+ */
+ echo "\n";
+}
+
+//
+// H Final HTML
+//
echo "