<?php
ini_set("display_errors", "on");
error_reporting(E_ALL ^ E_NOTICE);
require('commonFunctions.php');

$action = $_GET['action'];
$textListing = $_POST['textListing'];
$important = array();
$important['ROM/118/106.DAT'] = 'General Items';
$important['ROM/118/107.DAT'] = 'Usable Items';
$important['ROM/118/108.DAT'] = 'Armor';
$important['ROM/286/73.DAT'] = 'Armor 2';
$important['ROM/118/109.DAT'] = 'Weapons';
$important['ROM/217/21.DAT'] = 'Vouchers and Slips';
$important['ROM/175/35.DAT'] = 'Key Items';
$important['ROM/118/114.DAT'] = 'Magic/Abilities';
$important['ROM/181/72.DAT'] = 'Ability Names';
$important['ROM/181/73.DAT'] = 'Spell Names';
$important['ROM/181/74.DAT'] = 'Abilitiy Descriptions';
$important['ROM/181/75.DAT'] = 'Spell Descriptions';
$important['ROM/176/60.DAT'] = "San d'Orian Quests";
$important['ROM/176/61.DAT'] = 'Bastok Quests';
$important['ROM/176/62.DAT'] = 'Windurst Quests';
$important['ROM/176/63.DAT'] = 'Jeuno Quests';
$important['ROM/176/64.DAT'] = 'Other Quests';
$important['ROM/176/65.DAT'] = 'RoTZ Quests';
$important['ROM/176/66.DAT'] = 'ToAU Quests';
$important['ROM/196/6.DAT'] = 'WotG Quests';
$important['ROM/242/64.DAT'] = 'Abyssea Quests';
$important['ROM/176/67.DAT'] = "San d'Orian Missions";
$important['ROM/176/68.DAT'] = 'Bastok Missions';
$important['ROM/176/69.DAT'] = 'Windurst Missions';
$important['ROM/176/70.DAT'] = 'RoTZ Missions';
$important['ROM/176/71.DAT'] = 'CoP Missions';
$important['ROM/176/72.DAT'] = 'Assault Missions';
$important['ROM/176/73.DAT'] = 'ToAU Missions';
$important['ROM/196/7.DAT'] = 'WotG Missions';
$important['ROM/196/8.DAT'] = 'Campaign Ops';
$important['ROM/222/18.DAT'] = 'ACP Missions';
$important['ROM/223/12.DAT'] = 'AKE Missios';
$important['ROM/223/13.DAT'] = 'ASA Missios';
$important['ROM/180/78.DAT'] = 'Titles';
$important['ROM/180/102.DAT'] = 'Status Names';
$important['ROM/119/57.DAT'] = 'Status Descriptions';
$important['ROM/165/84.DAT'] = 'Area Names';

$mainpath = "C:\Program Files\PlayOnline\SquareEnix\FINAL FANTASY XI";
$testpath = "C:\Program Files\PlayOnline\SquareEnix\FINAL FANTASY XI Test Client";
$mainpath = "C:\Program Files (x86)\Steam\steamapps\common\\ffxi\SquareEnix\FINAL FANTASY XI";
$testpath = "D:\Program Files (x86)\PlayOnline\SquareEnix\FINAL FANTASY XI Test Client";

$lastmonth = strtotime("-1 month");
$lastweek = strtotime("-1 week");

$count = 0;
$output = '';

if (strlen($action) == 0) {
    print "<a href=\"Patch Checker.php?action=live\">Check temp files during patch download.</a><br />
    <a href=\"Patch Checker.php?action=1-a\">Show all important FFXI Dates.</a><br />
    <a href=\"Patch Checker.php?action=1-b\">Show important FFXI Dates in the last month.</a><br />
    <a href=\"Patch Checker.php?action=1-c\">Show important FFXI Dates in the last week.</a><br />
    <a href=\"Patch Checker.php?action=2-a\">Show all important FFXI Test Server Dates.</a><br />
    <a href=\"Patch Checker.php?action=2-b\">Show important FFXI Test Server Dates in the last month.</a><br />
    <a href=\"Patch Checker.php?action=2-c\">Show important FFXI Test Server Dates in the last week.</a><br />";
} else {
    $getpath = (strpos($action, "1-") !== false || $action == 'live') ? $mainpath : $testpath;
    $lastWeek = (strpos($action, "-c") !== false) ? true : false;
    $lastMonth = (strpos($action, "-b") !== false) ? true : false;
    foreach ($important as $path => $name) {
        if ($action == 'live') {
            $count =  (file_exists("$getpath//$path.tmp2") == true) ? $count+1 : $count;
            $output .= (file_exists("$getpath//$path.tmp2") == true) ? "<b>*</b> Temporary file for <b>$name</b> exists at $getpath//$path.tmp2!!\r\n<br />" : "No result fie $name at $getpath//$path.tmp2!!\r\n<br />";
        } else {
            $lastmod = filemtime("$getpath//$path");
            if (($lastmod > $lastweek && $lastWeek == true) || ($lastmod > $lastmonth && $lastMonth == true) || ($lastMonth == false && $lastWeek == false)) {
                $output .= "$name was last modified: " . date ("F d, Y H:i:s.", $lastmod) . "\r\n<br />";
                $count ++;
            }
        }
    }
    $result = ($count == 1) ? "result" : "results";
    print "<b>$count $result.</b>\r\n<br /><br />$output";
}

?>
