// COPYRIGHT : © 2003, 2004 Project Minerva Team and © 2001, 2003 The phpBB Group
// WWW       : http://www.project-minerva.org/
// LICENCE   : GPL v2.0 [ see /docs/COPYING ]
//
//--------------------------------------------------------------------------------------------------
if (!defined('IN_PHPBB')) {
    die('Hacking attempt');
}
global $cache, $db, $template, $userdata, $board_config;
global $do_gzip_compress, $gen_simple_header, $mvModuleCopyright, $starttime;
//
// Show the overall footer.
//
// Jnr. Admin
include_once $phpbb_root_path . 'includes/functions_jr_admin.' . $phpEx;
$admin_link = jr_admin_make_admin_link();
$page_gen = '';
$legal = '';
$tpl_name = 'overall_footer.tpl';
if (isset($gen_simple_header) && !empty($gen_simple_header)) {
    $tpl_name = 'simple_footer.tpl';
} else {
    if ($userdata['session_logged_in'] && $userdata['user_level'] == ADMIN) {
        $gzip_text = $board_config['gzip_compress'] ? 'GZIP : On' : 'GZIP : Off';
        $debug_text = DEBUG == 1 ? 'Debug : On' : 'Debug : Off';
        $excuted_queries = $db->num_queries;
        $endtime = explode(' ', microtime());
        $gentime = round($endtime[1] + $endtime[0] - $starttime, 4);
        $sql_time = round($db->sql_time, 4);
        $sql_part = round($sql_time / $gentime * 100);
        $php_part = 100 - $sql_part;
/**
* Page Footer
*/
function page_footer($exit = true, $template_to_parse = 'body', $parse_template = false)
{
    global $db, $cache, $config, $user, $template, $images, $theme, $lang, $tree;
    global $table_prefix, $SID, $_SID;
    global $ip_cms, $cms_config_vars, $cms_config_global_blocks, $cms_config_layouts, $cms_page;
    global $starttime, $base_memory_usage, $do_gzip_compress, $start;
    global $gen_simple_header, $meta_content, $nav_separator, $nav_links, $nav_pgm, $nav_add_page_title, $skip_nav_cat;
    global $breadcrumbs;
    global $cms_acp_url;
    $config['gzip_compress_runtime'] = isset($config['gzip_compress_runtime']) ? $config['gzip_compress_runtime'] : $config['gzip_compress'];
    $config['url_rw_runtime'] = isset($config['url_rw_runtime']) ? $config['url_rw_runtime'] : ($config['url_rw'] || $config['url_rw_guests'] && $user->data['user_id'] == ANONYMOUS ? true : false);
    if (!defined('IN_CMS')) {
        $cms_page['global_blocks'] = empty($cms_page['global_blocks']) ? false : true;
        //$cms_page['global_blocks'] = ((!isset($cms_page['page_id']) || !$cms_page['global_blocks']) ? false : true);
        $cms_page_blocks = empty($cms_page['page_id']) || empty($cms_config_layouts[$cms_page['page_id']]) ? false : true;
        if (empty($gen_simple_header) && !defined('HAS_DIED') && !defined('IN_LOGIN') && ($cms_page['global_blocks'] || $cms_page_blocks) && (!$config['board_disable'] || $user->data['user_level'] == ADMIN)) {
            $template->assign_var('SWITCH_CMS_GLOBAL_BLOCKS', true);
            if ($ip_cms->cms_parse_blocks($cms_page['page_id'], !empty($cms_page['page_id']), $cms_page['global_blocks'], 'tailcenter')) {
                $template->assign_var('TC_BLOCK', true);
            }
            if ($ip_cms->cms_parse_blocks($cms_page['page_id'], !empty($cms_page['page_id']), $cms_page['global_blocks'], 'tailright')) {
                $template->assign_vars(array('FOOTER_WIDTH' => $cms_config_vars['footer_width'], 'TR_BLOCK' => true));
            }
            $ip_cms->cms_parse_blocks($cms_page['page_id'], !empty($cms_page['page_id']), $cms_page['global_blocks'], 'tail');
            /*
             */
        }
        if (empty($gen_simple_header)) {
            if ($ip_cms->cms_parse_blocks(0, true, true, 'gfooter')) {
                $template->assign_var('GF_BLOCK', true);
            }
        }
        $bottom_html_block_text = get_ad('glb');
        $footer_banner_text = get_ad('glf');
        // CrackerTracker v5.x
        /*
        include_once(IP_ROOT_PATH . 'includes/ctracker/engines/ct_footer.' . PHP_EXT);
        $output_login_status = ($user->data['ct_enable_ip_warn'] ? $lang['ctracker_ma_on'] : $lang['ctracker_ma_off']);
        
        $template->assign_vars(array(
        	'CRACKER_TRACKER_FOOTER' => create_footer_layout($config['ctracker_footer_layout']),
        	'L_STATUS_LOGIN' => ($config['ctracker_login_ip_check'] ? sprintf($lang['ctracker_ipwarn_info'], $output_login_status) : ''),
        	)
        );
        */
        // CrackerTracker v5.x
    }
    include_once IP_ROOT_PATH . 'includes/functions_jr_admin.' . PHP_EXT;
    $admin_link = jr_admin_make_admin_link();
    //Begin Lo-Fi Mod
    $path_parts = pathinfo($_SERVER['SCRIPT_NAME']);
    $lofi = '<a href="' . append_sid(IP_ROOT_PATH . $path_parts['basename'] . '?' . htmlspecialchars(str_replace(array('&lofi=0', '&lofi=1', 'lofi=0', 'lofi=1'), array('', '', '', ''), $_SERVER['QUERY_STRING'])) . '&amp;lofi=' . (empty($_COOKIE[$config['cookie_name'] . '_lofi']) ? '1' : '0')) . '">' . (empty($_COOKIE[$config['cookie_name'] . '_lofi']) ? $lang['Lofi'] : $lang['Full_Version']) . '</a>';
    $mobile_style = '<a href="' . append_sid(IP_ROOT_PATH . $path_parts['basename'] . '?' . htmlspecialchars(str_replace(array('&mob=0', '&mob=1', 'mob=0', 'mob=1'), array('', '', '', ''), $_SERVER['QUERY_STRING'])) . '&amp;mob=' . (!empty($_COOKIE[$config['cookie_name'] . '_mob']) ? '0' : '1')) . '">' . (!empty($_COOKIE[$config['cookie_name'] . '_mob']) ? $lang['MOBILE_STYLE_DISABLE'] : $lang['MOBILE_STYLE_ENABLE']) . '</a>';
    $template->assign_vars(array('L_LOFI' => $lang['Lofi'], 'L_FULL_VERSION' => $lang['Full_Version'], 'LOFI' => $lofi . ($user->data['is_mobile'] ? '&nbsp;&bull;&nbsp;' . $mobile_style : ''), 'MOBILE_STYLE' => $mobile_style));
    //End Lo-Fi Mod
    $template->assign_vars(array('TRANSLATION_INFO' => isset($lang['TRANSLATION_INFO']) && $lang['TRANSLATION_INFO'] != '' ? '<br />&nbsp;' . $lang['TRANSLATION_INFO'] : (isset($lang['TRANSLATION']) && $lang['TRANSLATION'] != '' ? '<br />&nbsp;' . $lang['TRANSLATION'] : ''), 'BOTTOM_HTML_BLOCK' => $bottom_html_block_text, 'FOOTER_BANNER_BLOCK' => $footer_banner_text, 'GOOGLE_ANALYTICS' => $config['google_analytics'], 'CMS_ACP' => !empty($cms_acp_url) ? $cms_acp_url : '', 'ADMIN_LINK' => $admin_link));
    // Mighty Gorgon - CRON - BEGIN
    if ($config['cron_global_switch'] && !defined('IN_CRON') && !defined('IN_ADMIN') && !defined('IN_CMS') && empty($config['board_disable'])) {
        $cron_time = time();
        $cron_append = '';
        $cron_types = array('files', 'database', 'cache', 'sql', 'users', 'topics', 'sessions');
        for ($i = 0; $i < sizeof($cron_types); $i++) {
            $cron_trigger = $cron_time - $config['cron_' . $cron_types[$i] . '_interval'];
            if ($config['cron_' . $cron_types[$i] . '_interval'] > 0 && $cron_trigger > $config['cron_' . $cron_types[$i] . '_last_run']) {
                $cron_append .= (empty($cron_append) ? '?' : '&amp;') . $cron_types[$i] . '=1';
            }
        }
        // We can force hours crons as all checks are performed by the function
        $hour_cron_types = array('digests', 'birthdays');
        $cur_time = @getdate();
        foreach ($hour_cron_types as $hour_cron_type) {
            $config['cron_' . $hour_cron_type . '_last_run'] = !empty($config['cron_' . $hour_cron_type . '_last_run']) ? $config['cron_' . $hour_cron_type . '_last_run'] : time() - 3600;
            $last_send_time = @getdate($config['cron_' . $hour_cron_type . '_last_run']);
            if (!empty($config['cron_' . $hour_cron_type . '_interval']) && $config['cron_' . $hour_cron_type . '_interval'] > 0 && $cur_time['hours'] != $last_send_time['hours']) {
                $cron_append .= (empty($cron_append) ? '?' : '&amp;') . $hour_cron_type . '=1';
            }
        }
        if (!empty($cron_append)) {
            $template->assign_var('RUN_CRON_TASK', '<img src="' . append_sid(IP_ROOT_PATH . 'cron.' . PHP_EXT . $cron_append) . '" width="1" height="1" alt="cron" />');
        }
    }
    // Mighty Gorgon - CRON - END
    if ($config['page_gen']) {
        // Page generation time - BEGIN
        /* Set $page_gen_allowed to FALSE if you want only Admins to view page generation info */
        $page_gen_allowed = true;
        if ($user->data['user_level'] == ADMIN || $page_gen_allowed) {
            $gzip_text = $config['gzip_compress_runtime'] ? 'GZIP ' . $lang['Enabled'] : 'GZIP ' . $lang['Disabled'];
            $debug_text = DEBUG == true ? $lang['Debug_On'] : $lang['Debug_Off'];
            $memory_usage_text = '';
            //$excuted_queries = $db->num_queries['total'];
            $excuted_queries = $db->num_queries['normal'];
            $endtime = explode(' ', microtime());
            $endtime = $endtime[1] + $endtime[0];
            $gentime = round($endtime - $starttime, 4);
            // You can adjust the number 6
            $sql_time = round($db->sql_time, 4);
            $sql_part = round($sql_time / $gentime * 100);
            $php_part = 100 - $sql_part;
            // Mighty Gorgon - Extra Debug - BEGIN
            if (defined('DEBUG_EXTRA') && $user->data['user_level'] == ADMIN) {
                if (function_exists('memory_get_usage')) {
                    if ($memory_usage = memory_get_usage()) {
                        global $base_memory_usage;
                        $memory_usage -= $base_memory_usage;
                        $memory_usage = $memory_usage >= 1048576 ? round(round($memory_usage / 1048576 * 100) / 100, 2) . ' ' . 'MB' : ($memory_usage >= 1024 ? round(round($memory_usage / 1024 * 100) / 100, 2) . ' ' . 'KB' : $memory_usage . ' ' . 'BYTES');
                        $memory_usage_text = ' - ' . $lang['Memory_Usage'] . ': ' . $memory_usage;
                    }
                }
                if (defined('DEBUG_EXTRA')) {
                    $tmp_query_string = htmlspecialchars(str_replace(array('&explain=1', 'explain=1'), array('', ''), $_SERVER['QUERY_STRING']));
                    $gzip_text .= ' - <a href="' . append_sid(IP_ROOT_PATH . $path_parts['basename'] . (!empty($tmp_query_string) ? '?' . $tmp_query_string . '&amp;explain=1' : '?explain=1')) . '">Extra ' . $lang['Debug_On'] . '</a>';
                }
            }
            //if (defined('DEBUG_EXTRA') && ($user->data['user_level'] == ADMIN))
            if (defined('DEBUG_EXTRA') && !empty($_REQUEST['explain']) && $user->data['user_level'] == ADMIN && method_exists($db, 'sql_report')) {
                $db->sql_report('display');
            }
            // Mighty Gorgon - Extra Debug - END
            $template->assign_vars(array('SPACER' => $images['spacer'], 'S_GENERATION_TIME' => true, 'PAGE_GEN_TIME' => $lang['Page_Generation_Time'] . ':', 'GENERATION_TIME' => $gentime, 'NUMBER_QUERIES' => $excuted_queries, 'MEMORY_USAGE' => $memory_usage_text, 'GZIP_TEXT' => $gzip_text, 'SQL_QUERIES' => $lang['SQL_Queries'], 'SQL_PART' => $sql_part, 'PHP_PART' => $php_part, 'DEBUG_TEXT' => $debug_text));
            /*
            $gen_log_file = IP_ROOT_PATH . MAIN_CACHE_FOLDER . '/gen_log.txt';
            $fp = fopen ($gen_log_file, "a+");
            fwrite($fp, (!empty($gentime) ? $gentime : '0') . "\t" . (!empty($memory_usage) ? $memory_usage : '0') . "\t" . $user->page['page'] . "\n");
            fclose($fp);
            */
        }
        // Page generation time - END
    }
    // Check for some switches here, in case we have changed/reset these swiches somewhere through the code or CMS blocks!
    $template->assign_vars(array('S_PRINT_SIZE' => !empty($config['display_print_size']) ? true : false, 'S_JQUERY_UI' => !empty($config['jquery_ui']) ? true : false, 'S_JQUERY_UI_TP' => !empty($config['jquery_ui_tp']) ? true : false, 'S_JQUERY_UI_BA' => !empty($config['jquery_ui_ba']) ? true : false, 'S_JQUERY_UI_STYLE' => !empty($config['jquery_ui_style']) ? $config['jquery_ui_style'] : 'cupertino', 'S_JQUERY_TAGS' => !empty($config['jquery_tags']) ? true : false));
    if ($parse_template || empty($template_to_parse)) {
        $footer_tpl = empty($gen_simple_header) ? 'overall_footer.tpl' : 'simple_footer.tpl';
        $template->set_filenames(array('overall_footer' => $footer_tpl));
        $template->pparse('overall_footer');
    } else {
        //$template_to_parse = empty($template_to_parse) ? 'body' : $template_to_parse;
        $template->pparse($template_to_parse);
    }
    if ($exit) {
        garbage_collection();
        exit_handler();
        exit;
    }
    return;
}