<?php
//Neil 20171107 - turned cache to false, was true
$cache = false; // Turn On -> true OR Turn Off -> false

//20180413 - Set Page Variables - Rachel
$PageTemplate    = '/krugerrand/buy/baraka-overview.php';
$PageScripts     = '/krugerrand/buy/scripts/overview-scripts.php';
$PageTitle       = 'Buy/Sell Krugerrand';
$PageContent         = '/buy-krugerrand-overview.txt';
$pageID                = 'baraka-overview';
$bodyClass       = 'bullion-overview-main  krugerrand-main';
// $subPage_one     = '';
// $subPage_two     = 'price-and-features';
// $subPage_three   = 'calculator';
// $subPage_four    = '#modal-02';
// $sub_title_one   = 'Overview';
// $sub_title_two   = 'Pricing & Features';
// $sub_title_three = 'Investment Calculator';
// $subPage_class_1 = 'active';
// $subPage_class_2 = '';
// $subPage_class_3 = '';



$subPage_one     = '';
$subPage_two     = '';
$subPage_three   = '';
$subPage_four    = '';
$sub_title_one   = '';
$sub_title_two   = '';
$sub_title_three = '';
$subPage_class_1 = '';
$subPage_class_2 = '';
$subPage_class_3 = '';
?>

<?php
// Cache PHP Pages to reduce API loads due to the JS scripts loading on each page when they should not be.
// You can Thank me later
// Regards, Roy
if($cache == true){
    //settings
    $cache_ext  = '.html'; // file extension
    $cache_time     = 3600;  // Cache file expires afere these seconds (1 hour = 3600 sec)
    $cache_folder   = 'cached-files/'; // folder to store Cache files
    $ignore_pages   = array('', '');

    $dynamic_url    = 'http://'.$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . $_SERVER['QUERY_STRING']; // Requested dynamic page (full url)
    $cache_file     = $cache_folder.md5($dynamic_url).$cache_ext; // Construct a cache file
    $ignore = (in_array($dynamic_url,$ignore_pages))?true:false; // Check if url is in ignore list

    if (!$ignore && file_exists($cache_file) && time() - $cache_time < filemtime($cache_file)) { // Check Cache exist and it's not expired.
        ob_start('ob_gzhandler'); // Turn on output buffering, "ob_gzhandler" for the compressed page with gzip.
        readfile($cache_file); // Read Cache file
        echo '<!-- cached page - '.date('l jS \of F Y h:i:s A', filemtime($cache_file)).', Page : '.$dynamic_url.' -->';
        ob_end_flush(); // Flush and turn off output buffering
        exit(); // No need to proceed further, exit the flow.
    }
    //Turn on output buffering with gzip compression.
    ob_start('ob_gzhandler');
}
######## Your Website Content Starts Below #########
?>

<?php
// START BY LOADING SITE CONFIG
require ('../../config/site.php');
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
?>

<?php
// LOAD HELPER Requests -- > This will load Client Information and Templates
require (HELPERS.'/requests.php');
require (HELPERS.'/functions.php');

?>

<?php
// LOAD includes/begin --> Contains: DocType CSS and JS
require (INCLUDES.'/begin.php');
?>

<?php
// LOAD includes/header --> Contains: Closing </head> AND Top Navigation
require (INCLUDES.'/header.php');
?>

<?php
// Made this a little Neater calling the Template File Directly
require (TEMPLATES.$PageTemplate);
// <!-- END PAGE BASE CONTENT -->
echo "</div>"; // YOU MAY NOT NEED THIS
?>

<?php
// LOAD includes/footer --> Contains: FOOTER and JS scripts
require (INCLUDES.'/footer.php');
?>

<?php
// Check if template has scripts file
if(isset($PageScripts)){
    require (TEMPLATES.$PageScripts);
}
?>

<?php
// LOAD includes/end --> Contains: Contains: Closing </body> AND </html> TAGS
//require (INCLUDES.'/end.php');
include_once("../../analyticstracking.php");
echo'
</body>
</html>
';
?>

<?php
######## Your Website Content Ends here #########
if($cache == true){
    if (!is_dir($cache_folder)) { // Create a new folder if we need to
        mkdir($cache_folder);
    }
    if(!$ignore){
        $fp = fopen($cache_file, 'w');  // Open file for writing
        fwrite($fp, ob_get_contents()); // Write contents of the output buffer in Cache file
        fclose($fp); //Close file pointer
    }
    ob_end_flush(); //Flush and turn off output buffering
}
?>
