<?php
    $cachedIndex = "/home/breser/public_html/ben.reser.org/wow/sws/index.cached";
    $historyFile = "/home/breser/public_html/ben.reser.org/wow/sws/wws-history/data.xml";

    if ( !(is_readable($cachedIndex) && is_writeable($cachedIndex)) ) {
        if ( !($cachedIndexHandle = fopen($cachedIndex, 'w')) ) {
            die("Couldnt read/write/create the cached index file.");
        } else { fclose($cachedIndexHandle); }
    }
            
    if ( !($mtime = filemtime($historyFile)) )
        die("Couldnt fetch last uploaded raid time.");

    if ( !($indexmtime = filemtime($cachedIndex)) )
        die("Couldnt fetch last generated index time.");

    //File checking done
    //time to see if the history file was updated after the current index
    if ($indexmtime < $mtime)
    {
        // History file updated
        // Write new index
        $aoeu123 = true;
        require('parser.php');
        ob_start(); // Start buffer so we can just print() everything instead of having to use file handles and fwrite
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Contempt - StasisCL</title>
<!-- YUI: http://developer.yahoo.com/yui/articles/hosting/?connection&container&event&json&menu&MIN -->
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/combo?2.6.0/build/container/assets/skins/sam/container.css&amp;2.6.0/build/menu/assets/skins/sam/menu.css" />
<script type="text/javascript" src="http://yui.yahooapis.com/combo?2.6.0/build/yahoo-dom-event/yahoo-dom-event.js&amp;2.6.0/build/connection/connection-min.js&amp;2.6.0/build/container/container-min.js&amp;2.6.0/build/json/json-min.js&amp;2.6.0/build/menu/menu-min.js"></script>
<!-- SWS -->
<link rel="stylesheet" type="text/css" href="/extras/sws2.css" />
<script type="text/javascript" src="/extras/sws.js"></script>
<!-- Contempt -->
<link rel="stylesheet" type="text/css" href="/extras/contempt.css" />
</head>
<body>
<div class="swsmaster">
<div class="top">
<h2>Contempt - StasisCL</h2>
<div id="swsmenu" class="yuimenubar yuimenubarnav">
<div class="bd">
<ul class="first-of-type">
<li class="yuimenubaritem first-of-type"><a class="yuimenubaritemlabel" href="#raids" onclick="toggleTab('raids');">Raids</a></li>
<li class="yuimenubaritem"><a class="yuimenubaritemlabel" href="#zones" onclick="toggleTab('zones');">Zones</a></li>
<li class="yuimenubaritem"><a class="yuimenubaritemlabel" href="http://www.contemptgaming.com/">ContemptGaming.com</a></li>
</ul>
</div> <!-- bd -->
</div> <!-- swsmenu -->
</div> <!-- top -->
<div class="tabContainer">
<div class="tab" id="tab_raids">
<?php if ( !((include('tab_raid.php')) == 'OK') ) { print("<p>Couldnt generate raid tab.</p>"); } ?>
</div>
<div class="tab" id="tab_zones">
<?php if ( !((include('tab_zone.php')) == 'OK') ) { print("<p>Couldnt generate zone tab.</p>"); } ?>
</div>
</div>
<p class="footer">stasiscl available at <a href="http://code.google.com/p/stasiscl/">http://code.google.com/p/stasiscl/</a></p>
</div>
<script type="text/javascript">toggleTab('raids');</script>
</body>
</html>
<?php
// Still in the if check to see if the index needed to be rewritten.
//  if ($indexmtime < $mtime)
//  {
        $handle = fopen($cachedIndex, 'w');
        fwrite($handle, ob_get_contents());
        fclose($handle);
        ob_end_clean();
    }
    header('Content-Type: text/html; charset=utf-8');
    print(file_get_contents($cachedIndex));
?>
