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

$curFile = $_GET['curFile'];
$action = $_GET['action'];
$spName = $_GET['spName'];
$batchList = $_POST['batchList'];
$rawList = array();
$nameList = array();
$linkList = array();
$rawList[0] = array('', 'weaponsData', 'armorData', 'item1Data', 'item2Data', 'vouchersData', 'keyItemParse', 'BastokQuestsParse', 'SanDorianQuestsParse', 'WindurstQuestsParse', 'JeunoQuestsParse', 'OtherQuestsParse', 'ZilartQuestsParse', 'AhtUrhganQuestsParse', 'GoddessQuestsParse', 'campaignOpParse', 'GoddessMissionsParse', 'AbysseaQuestsParse');
$nameList[0] = array('', '=== New Weapons ===', '=== New Armors ===', '=== New Items ===', '=== New Items ===', '== New Vouchers and Slips ==', '== Key Items ==', '=== Bastok Quests ===', "=== San d'Oria Quests ===", '=== Windusrst Quests ===', '=== Jeuno Quests ===', '=== Other Quests ===', '=== Outland Quests ===', '=== Aht Urghan Quests ===', '=== Wings of the Goddess Quests ===', '== Campaign Ops ==', '== Wings of the Goddess Missions ==', '==Abyssea Quests==');
$linkList[0] = array('', 'Item-O-Matic.php?', 'Item-O-Matic.php?', 'Item-O-Matic.php?&', 'Item-O-Matic.php?', 'Item-O-Matic.php?', 'Key-O-Matic.php?&action=seek', 'Quest-O-Matic.php?&curFile=1', 'Quest-O-Matic.php?&curFile=2', 'Quest-O-Matic.php?&curFile=3', 'Quest-O-Matic.php?&curFile=4', 'Quest-O-Matic.php?&curFile=5', 'Quest-O-Matic.php?&curFile=6', 'Quest-O-Matic.php?&curFile=7', 'Quest-O-Matic.php?&curFile=8', '', '', 'Quest-O-Matic.php?curFile=9');
$rawList[1] = array('', 'weaponsData', 'armorData', 'item1Data', 'item2Data', 'vouchersData', 'keyItemParse');
$nameList[1] = array('', '=== New Weapons ===', '=== New Armors ===', '=== New Items ===', '=== New Items ===', '=== New Vouchers and Slips ===', "=== New Key Items ===");
$linkList[1] = array('', 'Item-O-Matic.php?', 'Item-O-Matic.php?', 'Item-O-Matic.php?', 'Item-O-Matic.php?', 'Key-O-Matic.php?&action=seek', '', '');
$rawList[2] = array('', 'weaponsData', 'armorData', 'item1Data', 'item2Data', 'vouchersData');
$nameList[2] = array('', '=== New Weapons ===', '=== New Armors ===', '=== New Items ===', '=== New Items ===', '=== New Vouchers and Slips ===');
$linkList[2] = array('', 'Item-O-Matic.php?', 'Item-O-Matic.php?', 'Item-O-Matic.php?', 'Item-O-Matic.php?', 'Item-O-Matic.php?');
$checkList = array();
$checkList[1] = array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21);
$checkList[2] = array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19);
$checkList[3] = array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
$checkList[4] = array(2, 3, 4, 5, 6, 7, 8, 9, 10);

$properties = array();
$properties[1] = array("Datum Type", "ID Number", "Wiki Name", 'Game Name', 'Singluar Long Name', 'Plural Long Name', 'Flags', 'Description', 'Stack', 'Target', 'Level', 'Slot', 'Race', 'Job', 'Damage', 'Delay', 'DPS', 'Weapon Type', "Number of Charges", "Cast Time", "Charge Time", "Recharge Time");
$properties[2] = array("Datum Type", "ID Number", "Wiki Name", 'Game Name', 'Singluar Long Name', 'Plural Long Name', 'Flags', 'Description', 'Stack', 'Target', 'Level', 'Slot', 'Race', 'Job', 'Def', 'Shield Size', "Number of Charges", "Cast Time", "Charge Time", "Recharge Time");
$properties[3] = array("Datum Type", "ID Number", "Wiki Name", 'Game Name', 'Singluar Long Name', 'Plural Long Name', 'Flags', 'Description', 'Stack', 'Target', "Moghancement Element", "Storage");
$properties[4] = array("Datum Type", "ID Number", "Wiki Name", 'Game Name', 'Singluar Long Name', 'Plural Long Name', 'Flags', 'Description', 'Stack', 'Target', 'Use Time');

$pageRenameIn = array('#', '&');
$pageRenameOut = array('', 'and');

$keyRenameIn = array(':', '#');
$keyRenameOut = array('_', '');

$specialWeaponIn = array("Ochain", "Daurdabla", "Verethragna", "Twashtar", "Almace", "Caladbolg", "Farsha", "Ukonvasara", "Redemption", "Rhongomiant", "Kannagi", "Masamune", "Gambanteinn", "Hvergelmir", "Gandiva", "Armageddon", "Aegis", "Gjallarhorn", "Spharai", "Mandau", "Excalibur", "Ragnarok", "Guttler", "Bravura", "Gungnir", "Apocalypse", "Kikoku", "Amanomurakumo", "Mjollnir", "Claustrum", "Annihilator", "Yoichinoyumi", "Conqueror", "Glanzfaust", "Yagrush", "Laevateinn", "Murgleis", "Vajra", "Burtgang", "Liberator", "Aymur", "Carnwenhan", "Gastraphetes", "Kogarasumaru", "Nagi", "Ryunohige", "Nirvana", "Tizona", "Death Penalty", "Kenkonken", "Terpsichore", "Tupsimati");
$specialWeaponOut = array("Empyrean", "Empyrean", "Empyrean", "Empyrean", "Empyrean", "Empyrean", "Empyrean", "Empyrean", "Empyrean", "Empyrean", "Empyrean", "Empyrean", "Empyrean", "Empyrean", "Empyrean", "Empyrean", "Relic", "Relic", "Relic", "Relic", "Relic", "Relic", "Relic", "Relic", "Relic", "Relic", "Relic", "Relic", "Relic", "Relic", "Relic", "Relic", "Mythic", "Mythic", "Mythic", "Mythic", "Mythic", "Mythic", "Mythic", "Mythic", "Mythic", "Mythic", "Mythic", "Mythic", "Mythic", "Mythic", "Mythic", "Mythic", "Mythic", "Mythic", "Mythic", "Mythic");

$cutList = array('Square of', 'Jug of', 'Vial of', 'Piece of', 'Jar of', 'Pot of', 'Vase of', 'Sprig of', 'Bag of', 'Clump of', 'Set of', 'Ingot of', 'Handful of', 'Spool of', 'Ponze of', 'Bowl of', 'Bundle of', 'Flask of', 'Flasque of', 'Lump of', 'Chunk of', 'Slice of', 'Serving of', 'Bunch of', 'Plate of', 'Bottle of', 'Sprig of', 'Dish of', 'Can of', 'Pair of', 'Loaf of', 'Cone of', 'Pitcher of', 'Pair of', 'Dose of');
$cutListPl = array('Squares of', 'Jugs of', 'Vials of', 'Pieces of', 'Jars of', 'Pots of', 'Vases of', 'Sprigs of', 'Bags of', 'Clumps of', 'Sets of', 'Ingots of', 'Handfuls of', 'Spools of', 'Ponzes of', 'Bowls of', 'Bundles of', 'Flasks of', 'Flasques of', 'Lumps of', 'Chunks of', 'Slices of', 'Servings of', 'Bunches of', 'Plates of', 'Bottles of', 'Sprigs of', 'Dishes of', 'Cans of', 'Pairs of', 'Loaves of', 'Cones of', 'Pitchers of', 'Pairs of', 'Doses of');
$repList = array('Square', 'Jug', 'Vial', 'Piece', 'Jar', 'Pot', 'Vase', 'Sprig', 'Bag', 'Clump', 'Set', 'Ingot', 'Handful', 'Spool', 'Ponze', 'Bowl', 'Bundle', 'Flask', 'Flasque', 'Lump', 'Chunk', 'Slice', 'Serving', 'Bunch', 'Plate', 'Bottle', 'Sprig', 'Dish', 'Can', 'Pair', 'Loaf', 'Cone', 'Pitcher', 'Pair', 'Dose');
$repListPl = array('Squares', 'Jugs', 'Vials', 'Pieces', 'Jars', 'Pots', 'Vases', 'Sprigs', 'Bags', 'Clumps', 'Sets', 'Ingots', 'Handfuls', 'Spools', 'Ponzes', 'Bowls', 'Bundles', 'Flasks', 'Flasques', 'Lumps', 'Chunks', 'Slices', 'Servings', 'Bunches', 'Plates', 'Bottles', 'Sprigs', 'Dishes', 'Cans', 'Pairs', 'Loaves', 'Cones', 'Pitchers', 'Pairs', 'Doses');

$fIndex = 0;
$day = date('Y-m-d');
$time = date('H:i:s');
$now = $day."T".$time."Z";
$removeWiki = array("*", "#");
$colors = array("ffffff", "dfe4ff");
$counter = 0;

function getPageContents($n) {
    $n = str_replace(' ', '_', $n);
    $o = @file_get_contents("http://wiki.bluegartr.com/bg/".$n);
    if (strlen($o) == 0) {
        return "No page";
    } elseif (strpos($o, 'Category:Item Info') !== false) {
        return "Item Info";
    } else {
        return "No flags";
    }
}

function writeSpecial($n, $ty) {
    global $array;
    $desc = array();
    $level = array();
    $output = array();
    foreach ($array as $curarr) {
        $currow = explode('|', $curarr);
        if ($currow[3] == $n) {
            array_push($output, $currow[2]);
            array_push($level, $currow[10]);
            array_push($desc, strlen($currow[7]));
        }

    }
    array_multisort($level, SORT_ASC, $desc, SORT_ASC, $output);
    $count = count($output);
    $article = (substr($specialCheck, 0, 1) == "E") ? "an" : "a";
    $ret = "{{Disambiguation|".implode('|', $output)."}}<br />
[[File:".$output[count($output)-1]." description.png|right|link=" . $output[count($output)-1] . "]]<br />
'''$n''' is $article [[:Category:$ty Weapons|$ty weapon]].&lt;br /&gt;<br />
There are $count items that share this name:<br /><br />";
    foreach ($output as $op) {
        $ret .= "* [[$op]]\r\n<br />";
    }
    $ret .= "\r\n<br /> Please follow the above links for more information
        about the item.  $n can be upgraded through the [[Trial of the Magians]].<br />
[[Category:$ty Weapons]]";
    return ($ret);
}


if ($curFile == null && $spName == null && $action === null) {
    print "<table width=\"1000\" border=\"0\" cellspacing=\"1\" cellpadding=\"2\">
  <tr>
    <td valign=\"top\" width=\"33%\">
<b>Update table formatted</b><br />\r\n";
    foreach ($rawList[0] as $key => $curName) {
        if ($key > 0) {
            print "<a href=\"Compare-O-Matic.php?curFile=".$key."\">".$curName."</a><br />\r\n";
        }
    }
    print "
    </td>
    <td valign=\"top\" width=\"33%\">
<b>Update XML formatted</b><br />\r\n";
    foreach ($rawList[1] as $key => $curName) {
        if ($key > 0) {
            print "<a href=\"Compare-O-Matic.php?curFile=".$key."&action=1\">".$curName."</a><br />\r\n";
        }
    }
    print "Quest and Mission batches are accessed from their respective listings.
    </td>
    <td valign=\"top\" width=\"33%\">
<b>Redirects XML formatted</b><br />\r\n";
    foreach ($rawList[2] as $key => $curName) {
        if ($key > 0) {
            print "<a href=\"Compare-O-Matic.php?curFile=".$key."&action=2\">".$curName."</a><br />\r\n";
        }
    }
    print "Quest and Mission batches are accessed from their respective listings.
    </td>
  </tr>
</table>";
    $curSp = '';
    print "<table width=\"1000\" border=\"0\" cellspacing=\"1\" cellpadding=\"2\">
  <tr>
  <td valign=\"top\">";
  print "<a href=\"Compare-O-Matic.php?spName=All\">$All Relics, Empyreans, and Mythics</a><br />\r\n";
    foreach ($specialWeaponIn as $k => $sp) {
        if ($specialWeaponOut[$k] != $curSp) {
            if ($curSp != '') {
                print "  </td>
                <td valign=\"top\">";
           }
           $curSp = $specialWeaponOut[$k];
           print "<b>$curSp</b>\r\n<br />";
       }
       print "<a href=\"Compare-O-Matic.php?spName=$sp\">$sp</a><br />\r\n";
    }
    print "</td>
      </tr>
</table>
Create your own XML batch!<br /><br />
    <form id=\"form1\" name=\"form1\" method=\"post\" action=\"Compare-O-Matic.php?action=custom\">
  <label>Item List<br />
  <textarea name=\"batchList\" id=\"batchList\" cols=\"45\" rows=\"5\"></textarea>
  </label>
  <p>
    <label>
    <input type=\"submit\" name=\"Submit\" id=\"Submit\" value=\"Submit\" />
    </label>
    <label>
    <input type=\"reset\" name=\"Reset\" id=\"Reset\" value=\"Reset\" />
    </label>
  </p>
</form>";
} elseif (strlen($spName) > 0) {
    $array = @file('ultimateParse.txt');
    $spCheck = str_replace($specialWeaponIn, 'SpCheck', $spName);
    if ($spCheck == 'SpCheck') {
        $specialCheck = str_replace($specialWeaponIn, $specialWeaponOut, $spName);
        $op = writeSpecial($spName, $specialCheck);
        print $op;
    } elseif ($spName == 'All') {
        $op = '';
        foreach($specialWeaponIn as $w) {
            $specialCheck = str_replace($specialWeaponIn, $specialWeaponOut, $w);
            $op .= xmlWrapper($w, writeSpecial($w, $specialCheck));
        }
        xmlStart();
        print $op;
        xmlEnd();
    }
} elseif ($action == "custom") {
    $array = @file('ultimateParse.txt');
    if (strlen($batchList) > 0) {
        $batchArr = explode("\r\n", $batchList);
        $batchList = implode(",", $batchArr);
        $batchArr = explode(",", $batchList);
        $searchArr = array();
        foreach ($array as $curArr) {
            $curData = explode('|', $curArr);
            $curData[2] = trim($curData[2]);
            $searchArr[$curData[2]] = $curData;
        }
        foreach ($batchArr as $currow) {
            $currow = str_replace($removeWiki, '', $currow);
            $currow = trim($currow);
            if (count($searchArr[$currow]) > 0) {
                $thisrow = implode('|', $searchArr[$currow]);
                print xmlWrapper($currow, writeTemplate($thisrow, false, true));
            }
        }
    }
} elseif ($action == 1) {
    $action = 1;
    $array = @file($rawList[$action][$curFile].'.txt');
    $array1 = @file("oldList/".$rawList[$action][$curFile].'.txt');
    $fileSystem = $rawList[$action][$curFile];
    $fileSystem = str_replace('Parse', '', $fileSystem);
    $imTarg = 'Image-O-Matic2.php';
    $newIndList = array();
    $changeList = array();

    if ($curFile == 6) {
        $goodString = "String Table Entry";
        $goodNum = 6;
    } elseif ($curFile > 6) {
        $goodString = "String Table Entry";
        $goodNum = 3;
    } else {
        $goodString = "FFXI Item";
        $goodNum = 3;
        $imTarg = 'Image-O-Matic.php';
    }

    if (!$array || !$array1) {
        if (!$array && !$array1) {
            print "Unable to open files: \"$array\" and \"$array1\"";
        } elseif (!$array) {
            print "Unable to open file: \"$array\": ".$rawList[$action][$curFile];
        } else {
            print "Unable to open file: \"oldList/".$rawList[$action][$curFile];
        }
    } else {
        $newArray = array();
        $newArray1 = array();
        $keyList = array();
        foreach ($array as $row) {
            $row = explode('|', $row);
             if ($curFile == 6) {
                $ind = $row[6];
            } elseif ($curFile <= 6) {
                $ind = $row[1];
                $ind = number_format($ind, 0, '', '');
            } else {
                $ind = $row[3];
            }
            //print_r ($row);
            //print "<br />ind- $ind <br />\r\n<br />";
            $newArray[$ind] = $row;
            $keyList[$ind] = 1;
        }
        foreach ($array1 as $row) {
            $row = explode('|', $row);
            if ($curFile == 6) {
                $ind = $row[6];
            } elseif ($curFile <= 5) {
                $ind = $row[1];
                $ind = number_format($ind, 0, '', '');
            } else {
                $ind = $row[3];
            }
            //print_r ($row);
            //print "<br />ind- $ind <br />\r\n<br />";
            $newArray1[$ind] = $row;
            $keyList[$ind] = 1;
        }

        $newStuff = array();
        $renamedStuff = array();
        $changedStuff = array();
        $changedNumber = array();
        $changedSet = array();
        foreach ($keyList as $key => $num) {
            if (is_string($newArray[$key][$goodNum]) == true) {
                $test = trim(strtolower($newArray[$key][$goodNum]));
            }  else {
                $test = $newArray[$key][$goodNum];
            }
            if (is_string($newArray1[$key][$goodNum]) == true) {
                $test1 = trim(strtolower($newArray1[$key][$goodNum]));
            } else {
                $test1 =  $newArray1[$key][$goodNum];
            }
            if ($test != $test1 && $test1 == null) {
                $newStuff[$key] = $newArray[$key];
            } elseif ($test != $test1) {
                $renamedStuff[$key] = $newArray[$key];
            } elseif ($curFile <= 5) {
                 foreach ($checkList[$curFile] as $num) {
                     if ($newArray[$key][$num] != $newArray1[$key][$num]) {
                         $changedStuff[$key] = $newArray[$key];
                         $changedNumber[$key][$num] = true;
                     }
                 }
            }
        }

        if ($curFile < 6) {
            foreach ($newStuff as $num => $newRow) {
                $thisRow = implode('|', $newRow);
                print xmlWrapper($newRow[2], writeTemplate($thisRow, false, true));
            }
        } elseif ($curFile == 6) {
            $title = '';
            foreach ($newStuff as $num => $currow) {
                print writeKeyItem($currow, true);
           }
        } else {
            print $nameList[$curFile]."\r\n<br />";
            foreach ($newStuff as $row) {
                print "* [[".$row[$goodNum]."]] \r\n<br />";
                array_push($newIndList, $row[1]);
            }
        }
    }
} elseif ($action == 2) {
    $action = 2;
    $array = @file($rawList[$action][$curFile].'.txt');
    $array1 = @file("oldList/".$rawList[$action][$curFile].'.txt');
    $fileSystem = $rawList[$action][$curFile];
    $fileSystem = str_replace('Parse', '', $fileSystem);
    $imTarg = 'Image-O-Matic2.php';
    $newIndList = array();
    $changeList = array();

    $goodString = "String Table Entry";
    $goodNum = 3;


    if (!$array || !$array1) {
        if (!$array && !$array1) {
            print "Unable to open files: \"$array\" and \"$array1\"";
        } elseif (!$array) {
            print "Unable to open file: \"$array\": ".$rawList[$action][$curFile];
        } else {
            print "Unable to open file: \"oldList/$array1\"";
        }
    } else {
        $newArray = array();
        $newArray1 = array();
        $keyList = array();
        foreach ($array as $row) {
            $row = explode('|', $row);
             if ($curFile == 5) {
                $ind = $row[6];
            } elseif ($curFile <= 4) {
                $ind = $row[1];
                $ind = number_format($ind, 0, '', '');
            } else {
                $ind = $row[3];
            }
            //print_r ($row);
            //print "<br />ind- $ind <br />\r\n<br />";
            $newArray[$ind] = $row;
            $keyList[$ind] = 1;
        }
        foreach ($array1 as $row) {
            $row = explode('|', $row);
            if ($curFile == 5) {
                $ind = $row[6];
            } elseif ($curFile <= 4) {
                $ind = $row[1];
                $ind = number_format($ind, 0, '', '');
            } else {
                $ind = $row[3];
            }
            //print_r ($row);
            //print "<br />ind- $ind <br />\r\n<br />";
            $newArray1[$ind] = $row;
            $keyList[$ind] = 1;
        }

        $newStuff = array();
        $renamedStuff = array();
        $changedStuff = array();
        $changedNumber = array();
        $changedSet = array();
        foreach ($keyList as $key => $num) {
            if (is_string($newArray[$key][$goodNum]) == true) {
                $test = trim(strtolower($newArray[$key][$goodNum]));
            }  else {
                $test = $newArray[$key][$goodNum];
            }
            if (is_string($newArray1[$key][$goodNum]) == true) {
                $test1 = trim(strtolower($newArray1[$key][$goodNum]));
            } else {
                $test1 =  $newArray1[$key][$goodNum];
            }
            if ($test != $test1 && $test1 == null) {
                $newStuff[$key] = $newArray[$key];
            } elseif ($test != $test1) {
                $renamedStuff[$key] = $newArray[$key];
            } elseif ($curFile <= 4) {
                 foreach ($checkList[$curFile] as $num) {
                     if ($newArray[$key][$num] != $newArray1[$key][$num]) {
                         $changedStuff[$key] = $newArray[$key];
                         $changedNumber[$key][$num] = true;
                     }
                 }
            }
        }
        foreach ($newStuff as $num => $row) {
            $row[2] = trim($row[2]);
            $row[3] = trim($row[3]);
            $row[4] = trim($row[4]);
            $row[2] = str_replace('  ', ' ', $row[2]);
            $row[3] = str_replace('  ', ' ', $row[3]);
            $row[4] = str_replace('  ', ' ', $row[4]);
            $testname = ucitem($row[4]);
            $testname = str_replace($ampIn, $ampOut, $testname);
            $spcheck = str_replace($specialWeaponIn, "Special Weapon", $row[3]);
            $cutPhrase = str_replace($cutList, "", $testname);
            $cutPhrase = trim($cutPhrase);
            $checkPhrase = "False";
            $doCheck = false;
            $doLink = false;
            $testshort = str_replace($ampIn, $ampOut, $row[3]);
            if ($cutPhrase != $testshort && $cutPhrase != $testname) {
                $checkPhrase = "True";
            }
            if ($row[2] != $testname) {
                if (strpos($row[2], 'Mannequin') !== false) {
                    if (strpos($row[7], 'female') !== false) {
                        $testname = str_replace('?', 'F', $testname);
                    } else {
                        $testname = str_replace('?', 'M', $testname);
                    }
                    $doLink = true;
                } elseif (strpos($testname, 'Scroll of') !== false) {
                    $doLink = true;
                } elseif ($spcheck == "Special Weapon" || ($testshort != $row[2] && strpos($row[2], '(Level ') !== false )) {
                    $doLink = false;
                    if ($checkPhrase == "True") {
                        //$doCheck = true;
                    }
                } elseif (strpos($row[3], 'Bonanza Kupon') !== false) {
                } elseif ($testshort != $testname) {
                    $doLink = true;
                    if ($checkPhrase == "True") {
                        $doCheck = true;
                    }
                }
            }
            //print $row[4] . " | $testshort | $testname | $cutPhrase | $testshort | $doLink | $doCheck \r\n<br />";
            if ($doLink == true) {
                if ($linkList[$testname] != true) {
                    print "[[$testname]]|[[".$row[2]."]]&lt;br /&gt;<br />\r\n";
                    $linkList[$testname] = true;
                }
            }
            if ($doCheck == true) {
                if ($linkList[$cutPhrase] != true) {
                    print "[[$cutPhrase]]|[[".$row[2]."]]&lt;br /&gt;<br />\r\n";
                    $linkList[$cutPhrase] = true;
                }
            }
        }
    }
} else {
    $action = 0;
    $array = @file($rawList[$action][$curFile].'.txt');
    $array1 = @file("oldList/".$rawList[$action][$curFile].'.txt');
    $fileSystem = $rawList[$action][$curFile];
    $fileSystem = str_replace('Parse', '', $fileSystem);
    $imTarg = 'Image-O-Matic2.php';
    $newIndList = array();

    if ($curFile == 6) {
        $goodString = "String Table Entry";
        $goodNum = 6;
    } elseif ($curFile > 6) {
        $goodString = "String Table Entry";
        $goodNum = 3;
    } else {
        $goodString = "FFXI Item";
        $goodNum = 3;
        $imTarg = 'Image-O-Matic.php';
    }

    if (!$array || !$array1) {
        if (!$array && !$array1) {
            print "Unable to open files: \"$array\" and \"$array1\"";
        } elseif (!$array) {
            print "Unable to open file: \"$array\": ".$rawList[$action][$curFile];
        } else {
            print "Unable to open file: \"oldList/$array1\"";
        }
    } else {
        $newArray = array();
        $newArray1 = array();
        $keyList = array();
        foreach ($array as $row) {
            $row = explode('|', $row);
             if ($curFile == 6) {
                $ind = $row[6];
            } elseif ($curFile <= 4) {
                $ind = $row[1];
                $ind = number_format($ind, 0, '', '');
            } else {
                $ind = $row[3];
            }
            //print_r ($row);
            //print "<br />ind- $ind <br />\r\n<br />";
            $newArray[$ind] = $row;
            $keyList[$ind] = 1;
        }
        foreach ($array1 as $row) {
            $row = explode('|', $row);
            if ($curFile == 6) {
                $ind = $row[6];
            } elseif ($curFile <= 4) {
                $ind = $row[1];
                $ind = number_format($ind, 0, '', '');
            } else {
                $ind = $row[3];
            }
            //print_r ($row);
            //print "<br />ind- $ind <br />\r\n<br />";
            $newArray1[$ind] = $row;
            $keyList[$ind] = 1;
        }

        $newStuff = array();
        $renamedStuff = array();
        $changedStuff = array();
        $changedNumber = array();
        $changedSet = array();
        foreach ($keyList as $key => $num) {
            if (is_string($newArray[$key][$goodNum]) == true) {
                $test = trim(strtolower($newArray[$key][$goodNum]));
            }  else {
                $test = $newArray[$key][$goodNum];
            }
            if (is_string($newArray1[$key][$goodNum]) == true) {
                $test1 = trim(strtolower($newArray1[$key][$goodNum]));
            } else {
                $test1 =  $newArray1[$key][$goodNum];
            }
            if ($test != $test1 && $test1 == null) {
                $newStuff[$key] = $newArray[$key];
            } elseif ($test != $test1) {
                 $renamedStuff[$key] = $newArray[$key];
            } elseif ($curFile <= 4) {
                 foreach ($checkList[$curFile] as $num) {
                     if ($newArray[$key][$num] != $newArray1[$key][$num]) {
                         $changedStuff[$key] = $newArray[$key];
                         $changedNumber[$key][$num] = true;
                     }
                 }
            }
        }
        print "<font size=\"+2\">New Stuff: </font>\r\n<br />";
        if ($curFile == 2) {
            print "=== Armor ===\r\n<br />{| style=\"background-color:#000878\" width=\"800px\" border=\"0\"\r\n<br />
|-BGCOLOR=\"#ADBDCC\"\r\n<br />
! width=150 | Name\r\n<br />
! width=35 | Icon\r\n<br />
! Level\r\n<br />
! width=100 | Slot\r\n<br />
! width=275 | Description\r\n<br />
! width=225 | Jobs\r\n<br />";

            print "\r\n<br \>";
            foreach ($newStuff as $num => $newRow) {
                $primative = $newRow[3];
                $fancyName = $newRow[2];
                $link = $fancyName;
                $col = $colors[$counter%2];
                $counter++;
                $rare = '';
                $ex = '';
                $spacer = '';
                $longName = ucitem($newRow[4]);
                if ($longName != $fancyName) {
                    $link = "$fancyName|$longName";
                }
                if (strrpos($newRow[6], "Rare") !== false) {
                    $spacer = ' ';
                    $rare = "{{Icon|Rare}}";
                }
                if (strstr($newRow[6], "Ex") !== false) {
                    $spacer = ' ';
                    $ex = "{{Icon|Ex}}";
                }
                $iconName = str_replace(':', '-', $fancyName);
                $link = "'''[[<a href=\"".$linkList[$action][$curFile]."&ind=".$newRow[1]."\">$link</a>]]'''";
                array_push($newIndList, $newRow[1]);
                $link .= $spacer.$rare.$ex;
                $jobs = str_replace('"', '', $newRow[13]);
                $damage = "-";
                if ($jobs != "All") {
                    $jobs = "[[".str_replace(', ', ']] / [[', $jobs)."]]";
                }

                $description = str_replace('<br />', ' ', $newRow[7]);
                $description = str_replace('[br]', ' ', $description);

                if ($newRow[16] > 0) {
                    $enchant1 = getEnchantment($newRow[18], 'l');
                    $enchant2 = getEnchantment($newRow[19], 'l');
                    $description .= "<br />&lt;".$newRow[16]."/".$newRow[16]." $enchant1/[$enchant2, $enchant1]&gt;";
                }
                $catLink = "[[:Category:".$newRow[11]."|".$newRow[11]."]]";
                if ($newRow[11] == '-') {
                    $catLink = '-';
                } elseif ($newRow[11] == 'Wind Instrument' || $newRow[11] == 'String Instrument') {
                    $catLink = "[[:Category:Instruments|".$newRow[11]."]]";
                } elseif ($newRow[11] == 'Fishing Gear') {
                    $catLink = "[[:Category:Fishing|Fishing Gear]]";
                }
                print "|- BGCOLOR=\"#$col\"<br />
| BGCOLOR=\"#CEE0F2\" | $link<br />
| [[Image:$iconName icon.png]]<br />
| ".$newRow[10]."<br />
| $catLink<br />
| $description<br />
| $jobs<br />";
            

        }
        print "|-\r\n<br />|}\r\n<br />";
        $indList = implode(',', $newIndList);
        print "\r\n<br /><br /><a href=\"$imTarg?&action=batch&fileSystem=$fileSystem&ind=$indList\">New Armor batch image processing</a><br /><br />";
        } elseif ($curFile == 1) {
            print "== New Equipment ==\r\n<br />=== Weapons ===\r\n<br />{| style=\"background-color:#000878\" width=\"800px\" border=\"0\"\r\n<br />
|-BGCOLOR=\"#ADBDCC\"\r\n<br />
! width=150 | Name\r\n<br />
! width=35 | Icon\r\n<br />
! Level\r\n<br />
! width=100 | Slot\r\n<br />
! width=275 | Description\r\n<br />
! width=225 | Jobs\r\n<br />";

            foreach ($newStuff as $num => $newRow) {
                $primative = $newRow[3];
                $fancyName = $newRow[2];
                $link = $fancyName;
                $col = $colors[$counter%2];
                $counter++;
                $rare = '';
                $ex = '';
                $spacer = '';
                $longName = ucitem($newRow[4]);
                if ($longName != $fancyName) {
                    $link = "$fancyName|$longName";
                }
                if (strrpos($newRow[6], "Rare") !== false) {
                    $spacer = ' ';
                    $rare = "{{Icon|Rare}}";
                }
                if (strstr($newRow[6], "Ex") !== false) {
                    $spacer = ' ';
                    $ex = "{{Icon|Ex}}";
                }
                $iconName = str_replace(':', '-', $fancyName);
                $link = "'''[[<a href=\"".$linkList[$action][$curFile]."&ind=".$newRow[1]."\">$link</a>]]'''";
                array_push($newIndList, $newRow[1]);
                $link .= $spacer.$rare.$ex;
                $jobs = str_replace('"', '', $newRow[13]);
                if ($jobs != "All") {
                    $jobs = "[[".str_replace(', ', ']] / [[', $jobs)."]]";
                }

                $description = str_replace('[br]', ' ', $newRow[7]);
                $description = str_replace('<br />', ' ', $description);
                $level = $newRow[10];

                $skill = $newRow[17];
                if ($skill == '-') {
                    $wepType = '-';
                } elseif ($skill == 'String Instrument' || $skill == 'Wind Instrument') {
                    $wepType = "[[:Category:Instrument|$skill]]";
                } else {
                    $wepType = "[[:Category:$skill|$skill]]";
                }

                if ($newRow[18] > 0) {
                    $enchant1 = getEnchantment($newRow[20], 'l');
                    $enchant2 = getEnchantment($newRow[21], 'l');
                    $description .= "<br />&lt;".$newRow[18]."/".$newRow[18]." $enchant1/[$enchant2, $enchant1]&gt;";
                }

                print "|- BGCOLOR=\"#$col\"<br />
| BGCOLOR=\"#CEE0F2\" | $link<br />
| [[Image:$iconName icon.png]]<br />
| ".$newRow[10]."<br />
| $wepType<br />
| $description<br />
| $jobs<br />";
            }
            print "|-\r\n<br />|}\r\n<br />";
            $indList = implode(',', $newIndList);
            print "\r\n<br /><br /><a href=\"$imTarg?&action=batch&fileSystem=$fileSystem&ind=$indList\">New Weapon batch image processing</a><br /><br />";
            } elseif ($curFile == 3 || $curFile == 4) {
                $fileNum = $curFile -2;
                $itemPrint = "\r\n<br />{| style=\"background-color:#000878\" width=\"800px\" border=\"0\"\r\n<br />
|-BGCOLOR=\"#ADBDCC\"\r\n<br />
! width=100 | Name\r\n<br />
! width=35 | Icon\r\n<br />
! Stack\r\n<br />
! width=600 | Description\r\n<br />";
                print "== New Items == ".$itemPrint;
                $newCat = '';
                foreach ($newStuff as $num => $newRow) {
                    $name = trim($newRow[2]);
                    $primative = $newRow[3];
                    $fancyName = $newRow[2];
                    $link = $fancyName;
                    $col = $colors[$counter%2];
                    $counter++;
                    $rare = '';
                    $ex = '';
                    $spacer = '';
                    $longName = ucitem($newRow[4]);
                    if ($longName != $fancyName) {
                        $link = "$fancyName|$longName";
                    }
                    if (strrpos($newRow[6], "Rare") !== false) {
                        $spacer = ' ';
                        $rare = "{{Icon|Rare}}";
                    }
                    if (strstr($newRow[6], "Ex") !== false) {
                        $spacer = ' ';
                        $ex = "{{Icon|Ex}}";
                    }
                    $iconName = str_replace(':', '-', $fancyName);
                    $link = "'''[[<a href=\"".$linkList[$action][$curFile]."&ind=".$newRow[1]."\">$link</a>]]'''";
                    $link .= $spacer.$rare.$ex;
                    
                    if (strstr($newRow[6], "Scroll") !== false && (stristr($newRow[4], "scroll of") !== false || strstr($newRow[2], " (Scroll)") !== false)) {
                        if ($newCat != 'Scrolls') {
                            $newCat = 'Scrolls';
                            print "|-\r\n<br />|}\r\n<br />=== Scrolls === ".$itemPrint;
                        }
                    }  elseif ($newCat == 'Scrolls') {
                        $newCat = '';
                        print "|-\r\n<br />|}\r\n<br />=== Food === ".$itemPrint;
                    }
                    $flags = str_replace($flagListIn, $flagListOut, $flags);
                    if ($newRow[0] == 'FFXI Furnishing' || $newRow[0] == 'FFXI Mannequin' || $newRow[0] == 'FFXI Flowerpot') {
                        if ($newCat != 'Furnishing') {
                            $newCat = 'Furnishing';
                            print "|-\r\n<br />|}\r\n<br />=== Furnishings === ".$itemPrint;
                        }
                        $category .= ' [[Category:Furnishings]]';
                        $doFurninshing = true;
                    } elseif ($newCat == 'Furnishing') {
                        $newCat = '';
                        print "|-\r\n<br />|}\r\n<br />=== General Items === ".$itemPrint;
                    }
                    $description = str_replace('<br />', ' ', $newRow[7]);
                    $description = str_replace('[br]', ' ', $description);


                    array_push($newIndList, $newRow[1]);
                    $stack = $newRow[8];
                    print "|- BGCOLOR=\"#$col\"<br />
| BGCOLOR=\"#CEE0F2\" | $link<br />
| [[Image:$iconName icon.png]]<br />
| $stack<br />
| $description<br />";
                }
                print "|-\r\n<br />|}\r\n<br />";
                $indList = implode(',', $newIndList);
                print "\r\n<br /><br /><a href=\"$imTarg?&action=batch&fileSystem=$fileSystem&ind=$indList\">New Item batch image processing</a><br /><br />";
        } elseif ($curFile == 6) {
            $title = '';
            print $nameList[$action][$curFile]."\r\n<br />";
            foreach ($newStuff as $row) {
                if ($row[9] != $title) {
                    $title = $row[9];
                    print "=== $title === \r\n<br />";
                }
                $name = ucfirst($row[$goodNum]);
                print "* [[<a href=\"".$linkList[$action][$curFile]."&ind=".$row[1]."\">$name</a>]] \r\n<br />";
                array_push($newIndList, $row[1]);
            }
        } else {
            print $nameList[$action][$curFile]."\r\n<br />";
            foreach ($newStuff as $row) {
                $thisRow = str_replace('**', '', $row[$goodNum]);
                $wikiName = str_replace($pageRenameIn, $pageRenameOut, $thisRow);
                if ($wikiName != $thisRow) {
                    $thisRow = $wikiName.'|'.$thisRow;
                }
                print "* [[$thisRow]] \r\n<br />";
                array_push($newIndList, $row[1]);
            }
        }
        $indList = implode(',', $newIndList);
        print "\r\n<br /><br /><a href=\"$imTarg?&action=batch&fileSystem=$fileSystem&ind=$indList\">New batch image processing</a><br /><br />";
        if (strpos($rawList[$action][$curFile], 'Quest') !== false) {
            print "\r\n<br /><br /><a href=\"".$linkList[$action][$curFile]."&action=XML&ind=$indList\">New batch XML file</a><br /><br />";

        }
        print "<font size=\"+2\">Renamed Stuff: </font>\r\n<br />";
        foreach ($renamedStuff as $key => $row) {
            print "* ".$newArray1[$key][$goodNum]." renamed to [[".$row[$goodNum]."]] \r\n<br />";
        }
        print "<font size=\"+2\">Changed Stuff: </font>\r\n<br />";
        $newIndList = array();
        foreach ($changedStuff as $key => $row) {
            $fancyName = $row[$goodNum];
            $link = $row[$goodNum];
            if ($fancyName != $row[2]) {
                $link = "$fancyName|".$row[2];
            }
            print " *[[<a href=\"".$linkList[$action][$curFile]."$action=list&ind=".$row[1]."\">$link</a>]]";
            array_push($newIndList, $row[1]);
            foreach ($row as $nKey => $item) {
                if ($changedNumber[$key][$nKey] == true) {
                    $d = str_replace('[br]', ' ', $row[$nKey]);
                    $d1 = str_replace('[br]', ' ', $newArray1[$key][$nKey]);
                    print "\r\n<br />: Changed Attribute ".$properties[$curFile][$nKey]."- \"<b>".$d1."</b>\" changed to \"<b>".$d."</b>\"";
                }
            }
             print "\r\n<br /><br />";
        }
        $indList = implode(',', $newIndList);
        print "\r\n<br /><br /><a href=\"$imTarg?&action=batch&fileSystem=$fileSystem&ind=$indList\">New Item batch image processing</a><br /><br />";
    }
    
}

?>

