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

$fileNum = $_GET['fileNum'];
$action = $_GET['action'];
$category = $_GET['category'];
$icons = $_GET['icons'];
$type = $_GET['type'];
$icons = $_GET['icons'];
$id = $_GET['id'];
$ind = $_GET['ind'];

$fileList = array('', 'item1Data.txt', 'item2Data.txt', 'vouchersData.txt', 'armorData.txt', 'weaponsData.txt');

$flagListIn = array('None', 'CanUse', 'CanTradeNPC', 'NoAuction', 'CanEquip', 'NoSale', 'NoDelivery', 'Ex');
$flagListOut = array('', 'Can Use', 'NPC tradable', 'Not auctionable', 'Equippable', 'Not vendorable', 'Not sendable', 'Not sendable, Exclusive');

$typeListIn = array('UsableItem', 'QuestItem');
$typeListOut = array('Usable Item', 'Quest Item');

$targetListIn = array('PartyMember', 'Ally');
$targetListOut = array('Party Member', 'Alliance Member');

//Weapon and armor replacement variables

$statIn = array("STR", "INT", "VIT", "MND", "DEX", "AGI", "CHR", "HP", "MP");
$statOut = array("[[STR]]", "[[INT]]", "[[VIT]]", "[[MND]]", "[[DEX]]", "[[AGI]]", "[[CHR]]", "[[HP]]", "[[MP]]");
$elementIn = array("?Element: Fire?", "?Element: Ice?", "?Element: Wind?", "?Element: Earth?", "?Element: Thunder?", "?Element: Water?", "?Element: Light?", "?Element: Dark?", "?Element: Air?");
$elementOut = array("{{Fire}}", "{{Ice}}", "{{Wind}}", "{{Earth}}", "{{Thunder}}", "{{Water}}", "{{Light}}", "{{Dark}}", "{{Wind}}");
$otherIn = array("HP, MP, or TP Drain", "HP drain", "MP Drain", "TP Drain", "Breath damage taken", "Magic damage taken", "Physical damage taken", "Damage taken", "HP and MP recovered while healing", "MP recovered while healing", "HP recovered while healing", "Absorbs HP", "Absorbs MP", "Accuracy Bonus", "Evasion Bonus", "Kick Attacks", "Triple Attack", "Double Attack", "Quadruple Attack", "Sneak Attack", "Trick Attack", "Impairs evasion", "Weapon Skill Accuracy", "Magic Accuracy", "Ranged Accuracy", "Ranged Attack", "Accuracy", "Delay", "Evasion skill", "Evasion", "DEF", "DMG", "Enchantment", "Additional effect", "Critical hit rate", "Magic Attack Bonus", "Magic Atk. Bonus", "Magic Defense Bonus", "Magic Def. Bonus", "Attack Bonus", "Attack", "Magic critical hit rate", "Increases magic critical hit damage", "Magic critical hit");
$otherOut = array("[[H*P|H*P drain]], [[M*P|M*P Drain]], or [[T*P Drain]]", "[[H*P drain]]", "[[M*P Drain]]", "[[T*P Drain]]", "[[Breath d**age taken]]", "[[Magic d**age taken]]", "[[Physical d**age taken]]", "[[Damage taken]]", "[[H*P recovered while healing|H*P]] and [[M*P recovered while healing]]", "[[M*P recovered while healing]]", "[[H*P recovered while healing]]", "[[H*P Drain|Absorbs H*P]]", "[[M*P Drainracy Bonus]]", "[[A**uracy Bonus]]", "[[E**sion Bonus]]", "[[Kick A**acks]]", "[[Triple A**ack]]", "[[Double A**ack]]", "[[Quadruple A**ack]]", "[[Sneak A**ack]]", "[[Trick A**ack]]", "[[Impairs e**sion]]", "[[Weapon Skill A**uracy]]", "[[Magic A**uracy]]", "[[Ranged A**uracy]]", "[[Ranged A**ack]]", "[[A**uracy]]", "[[Delay]]", "[[E**sion skill]]", "[[E**sion]]", "[[Defense|DEF]]", "[[Damage|DMG]]", "[[Enchantment]]", "[[Additional effect]]", "[[Critical Hit|Critical hit rate]]", "[[Magic A**ack Bonus]]", "[[Magic A**ack Bonus|Magic Atk. Bonus]]"
             , "[[Magic D**ense Bonus]]", "[[Magic D**ense Bonus|Magic Def. Bonus]]", "[[A**ack Bonus]]", "[[A**ack]]", "[[Ma**c Cr**ical Hit|Ma**c cr**ical hit rate]]", "[[Ma**c Cr**ical Hit|Increases ma**c cr**ical hit damage]]", "[[Ma**c Cr**ical Hit|Ma**c cr**ical hit]]");
$otherIn0 = array("Activated", "In Dynamis", "Besieged", "Assault", "Latent effect", "In areas outside own nation's control", "In areas under own nation's control", "TP Bonus", "Enmity", "Haste", "Spell interruption rate", "Weakens defense", "\"Cure\" potency", "Potency of \"Cure\" and \"Waltz\" effects received", "\"Cure\" spellcasting time", "Potency of \"Cure\" effect received", "Reduces \"Reward\" recast time", "Enhances effect of \"Absorb\" spells", "\"Waltz\" potency", "Potency of \"Waltz\" effect received", "Improves \"Tame\" success rate", "Increases \"Samba\" duration");
$otherOut0 = array("Ac*iva*ed", "[[:Category:Dynamis|In Dynamis]]", "[[:Category:Besieged|Besieged]]", "[[:Category:A**ault|A**ault]]", "[[Latent effect]]", "[[In areas outside own nation's control]]", "[[In areas under own nation's control]]", "[[TP Bonus]]", "[[Enmity]]", "[[Haste (Status)|Haste]]", "[[Spell interruption rate]]", "[[Weakens defense]]", "[[Cure Potency|\"Cure\" potency]]", "[[Cure Potency|Potency of \"Cure\"]] and [[Waltz|\"Waltz\" effects received]]", "[[Cure Spellcasting Time|\"Cure\" spellcasting time]]", "[[Cure Potency|Potency of \"Cure\" effect received]]", "[[R**ard|Reduces \"R**ard\" recast time]]", "[[:Category:Absorb_Spell#Equipment|Enhances effect of \"Absorb\" spells]]", "[[Waltz|\"Waltz\" potency]]", "[[Waltz|Potency of \"Waltz\" effect received]]", "[[T**e|Improves \"T**e\" success rate]]", "[[Samba|Increases \"Samba\" duration]]");
$otherIn1 = array("Synthesis image support", "Experience point bonus", "Sword enhancement spell duration", "Sword enhancement spell damage", "Salvage", "Garrison", "Slow", "Reduces clamming \"incidents\"", "Wyvern", "wyvern", "Fellow", "Movement speed", "Increases movement speed", "Automaton", "Daytime", "Nighttime", "Dispense", "Adds \"Refresh\" effect", "Adds \"Regen\" effect", "Set:", "Song spellcasting time", "Increases rate of critical hits", "Decreases movement speed", "Avatar perpetuation cost", "perpetuation cost", "\"Blood Pact\" ability delay", "Blood Pact: Rage", "Blood Pact: Ward", "Blood Pact", "Regain", "Campaign", "Aftermath", "Afterglow", "March", "Mambo", "Madrigal", "Ballad", "Minne", "Finale", "Etude", "Paeon", "Lullaby", "Threnody", "Hymnus", "Virelai", "Mazurka", "Requiem", "Minuet", "Carol", "Elegy", "Prelude");
$otherOut1 = array("[[Synthesis image support]]", "[[Experience point bonus]]", "[[Enspell|Sword enhancement spell duration]]", "[[Enspell|Sword enhancement spell damage]]", "[[:Category:Salvage|Salvage]]", "[[:Category:Garrison|Garrison]]", "[[Slow (Status)|Slow]]", "[[Clamming|Reduces clamming \"incidents\"]]", "[[W**ern]]", "[[W**ern|w**ern]]", "[[Adventuring Fellow|Fellow]]", "[[Movement speed]]", "[[Movement speed|Increases movement speed]]", "[[Automaton]]", "[[Daytime]]", "[[Nighttime]]", "[[Dispense]]", "[[Refresh (Status)|Adds \"Refresh\" effect]]", "[[Regen (Status)|Adds \"Regen\" effect]]", "[[:Category:Armor Set|Set]]:", "[[Song spellcasting time]]", "[[Critical hit|Increases rate of critical hits]]", "[[Decreases movement speed]]", "[[Avatar p**petuation cost]]", "[[perpetuation cost]]", "[[\"Bl00d Pact\" ability delay]]", "[[Bl00d Pact: Rage]]", "[[Bl00d Pact: Ward]]", "[[Bl00d Pact]]", "[[Regain (Status)|Regain]]", "[[:Category:Campaign|Capmaign]]", "[[Aftermath]]", "[[Afterglow]]",
                   "[[March]]", "[[Mambo]]", "[[Madrigal]]", "[[Ballad]]", "[[Minne]]", "[[Finale]]", "[[Etude]]", "[[Paeon]]", "[[Lullaby]]", "[[Threnody]]", "[[Hymnus]]", "[[Virelai]]", "[[Mazurka]]", "[[Requiem]]", "[[Minuet]]", "[[Carol]]", "[[Elegy]]", "[[Prelude]]");
$otherIn2 = array("Ac*iva*ed", "K**ana", "A*$", "Sw**d", "S**w", "W**ern", "w**ern", "B**st", "E**sion", "e**sion", "A**uracy", "A**ack", "H*P", "M*P", "T*P", "St**l", "D**ense", "A**ault", "d**age", "D**age", "p**petuation", "Bl00d Pact", "Ma**c", "Cr**ical", "cr**ical", "R**ard", "T**e", "ma**c");
$otherOut2 = array("Activated", "Katana", "Axe", "Sword", "Slow", "Wyvern", "wyvern", "Boost", "Evasion", "evasion", "Accuracy", "Attack", "HP", "MP", "TP", "Steal", "Defense", "Assault", "damage", "Damage", "perpetuation", "Blood Pact", "Magic", "Critical", "critical", "Reward", "Tame", "magic");
$monsterListIn = array("beasts", "lizards", "vermin", "plantoids", "aquans", "amorphs", "birds", "undead", "arcana", "dragons", "demons", "elementals", "Quadov", "gigas", "Orcs", "Yagudo");
$abilityListIn = array("Accomplice", "Activate", "Addendum: Black", "Addendum: White", "Afflatus Solace", "Aggressor", "Alacrity", "Allies' Roll", "Ancient Circle", "Angon", "Arcane Circle", "Assassin's Charge", "Assault", "Astral Flow", "Avatar's Favor", "Azure Lore", "Barrage", "Beast Roll", "Benediction", "Berserk", "Blade Bash", "Blitzer's Roll", "Blood Rage", "Blood Weapon", "Boost", "Bounty Shot", "Burst Affinity", "Call Beast", "Call Wyvern", "Camouflage", "Caster's Roll", "Celerity", "Chain Affinity", "Chainspell", "Chakra", "Chaos Roll", "Charm", "Chi Blast", "Chivalry", "Choral Roll", "Climactic Flourish", "Collaborator", "Composure", "Conspirator", "Convergence", "Corsair's Roll", "Counterstance", "Courser's Roll", "Cover", "Dark Arts", "Dark Maneuver", "Dark Seal", "Dark Shot", "Deactivate", "Deep Breathing", "Defender", "Deploy", "Despoil", "Devotion", "Diabolic Eye", "Diffusion", "Dismiss", "Divine Caress", "Divine Emblem",
"Divine Seal", "Dodge", "Double Shot", "Double-Up", "Drachen Roll", "Eagle Eye Shot", "Earth Maneuver", "Earth Shot", "Ebullience", "Efflux", "Elemental Seal", "Elemental Siphon", "Enmity Douse", "Enrage", "Evoker's Roll", "Familiar", "Fealty", "Feather Step", "Feint", "Feral Howl", "Fight", "Fighter's Roll", "Fire Maneuver", "Fire Shot", "Flashy Shot", "Flee", "Focus", "Fold", "Footwork", "Formless Strikes", "Futae", "Gallant's Roll", "Gauge", "Hasso", "Healer's Roll", "Heel", "Hide", "High Jump", "Holy Circle", "Hundred Fists", "Hunter's Roll", "Ice Maneuver", "Ice Shot", "Immanence", "Impetus", "Innin", "Invincible", "Jump", "Killer Instinct", "Last Resort", "Leave", "Light Arts", "Light Maneuver", "Light Shot", "Magus's Roll", "Mana Cede", "Mana Wall", "Manafont", "Mantra", "Martyr", "Meditate", "Meikyo Shisui", "Mighty Strikes", "Mijin Gakure", "Monk's Roll", "Mug", "Nether Void", "Nightingale", "Ninja Roll", "Overdrive", "Parsimony", "Penury", "Perfect Counter",
"Perfect Dodge", "Perpetuance", "Pet commands", "Phantom Roll", "Provoke", "Puppet Roll", "Quick Draw", "Rampart", "Random Deal", "Rapture", "Ready", "Release", "Repair", "Restraint", "Retaliation", "Retreat", "Retrieve", "Reverse Flourish", "Reward", "Rogue's Roll", "Role Reversal", "Saboteur", "Samurai Roll", "Sange", "Scavenge", "Seigan", "Sekkanoki", "Sengikori", "Sentinel", "Shadowbind", "Sharpshot", "Shield Bash", "Shikikoyo", "Sic", "Snake Eye", "Snapshot", "Sneak Attack", "Soul Jump", "Soul Voice", "Souleater", "Spirit Jump", "Spirit Link", "Spirit Surge", "Spur", "Stay", "Steal", "Stealth Shot", "Striking Flourish", "Sublimation", "Super Jump", "Tactical Guard", "Tactical Parry", "Tactical Switch", "Tactician's Roll", "Tame", "Third Eye", "Thunder Maneuver", "Thunder Shot", "Tomahawk", "Trick Attack", "Triple Shot", "Troubadour", "Unlimited Shot", "Velocity Shot", "Ventriloquy", "Violent Flourish", "Warcry", "Warding Circle", "Warlock's Roll", "Warrior's Charge", "Water Maneuver",
"Water Shot"," Weapon Bash", "Wild Card", "Wind Maneuver", "Wind Shot", "Wizard's Roll", "Yonin");
$killerListIn = array("Amorph Killer", "Aquan Killer", "Arcana Killer", "Beast Killer", "Bird Killer", "Demon Killer", "Dragon Killer", "Elemental Killer", "Empty Killer", "Lizard Killer", "Plantoid Killer", "Undead Killer", "Vermin Killer");
$resistListIn = array("Resist Amnesia", "Resist Bind", "Resist Blind", "Resist Charm", "Resist Curse", "Resist Gravity", "Resist Paralyze", "Resist Petrify", "Resist Poison", "Resist Silence", "Resist Sleep", "Resist Slow", "Resist Stun", "Resist Virus");
$relicWSListIn = array("Ascetic's Fury", "Atonement", "Blade: Hi", "Blade: Kamu", "Blade: Metsu", "Camlann's Torment", "Catastrophe", "Chant du Cygne", "Cloudsplitter", "Coronach", "Dagan", "Death Blossom", "Drakesbane", "Expiacion", "Final Heaven", "Garland of Bliss", "Gate of Tartarus", "Geirskogul", "Glory Slash", "Insurgency", "Jishnu's Radiance", "King's Justice", "Knights of Round", "Leaden Salute", "Mandalic Stab", "Mercy Stroke", "Metatron Torment", "Mordant Rime", "Myrkr", "Mystic Boon", "Namas Arrow", "Omniscience", "Onslaught", "Primal Rend", "Pyrrhic Kleos", "Quietus", "Randgrith", "Rudra's Storm", "Scourge", "Stringing Pummel", "Tachi: Fudo", "Tachi: Kaiten", "Tachi: Rana", "Tartarus Torpor", "Torcleaver", "Trueflight", "Ukko's Fury", "Uriel Blade", "Victory Smite", "Vidohunir", "Wildfire");
$traitListIn = array("Aggressive Aim", "Alertness", "Ambush", "Assassin", "Assimilation", "Aura Steal", "Auto Refresh", "Auto Regen", "Beast Affinity ", "Beast Healer", "Blood Boon", "Clear Mind", "Conserve MP", "Conserve TP", "Counter", "Courtly Measure", "Defense Bonus", "Desperate Blows", "Divine Benison", "Divine Veil", "Dual Wield", "Empathy", "Enchainment", "Fast Cast", "Fencer", "Fine-Tuning", "Gilfinder", "Guardian", "Ikishoten", "Invigorate", "Iron Will", "Loaded Deck", "Martial Arts", "Max HP Boost", "Max MP Boost", "Military Parade", "Muted Soul", "Ninja tool expertise", "Occult Acumen", "Optimization", "Overwhelm", "Penance", "Rapid Shot", "Recycle", "Savagery", "Shield Def. Bonus", "Shield Mastery", "Skillchain Bonus", "Stealth", "Store TP", "Stout Servant", "Strafe", "Subtle Blow", "Treasure Hunter", "True Shot", "Winning Streak", "Zanshin");
$spellSkill = array("Blue", "Dark", "Divine", "Elemental", "Enfeebling", "Enhancing", "Healing", "Summoning", "Blue");
$spellSkillIn = array();
$spellSkillOut = array();
$magicSkill = array("Ninjutsu", "Singing", "String instrument", "Wind instrument");
$magicSkillIn = array();
$magicSkillOut = array();
$combatSkill = array("Hand-to-Hand", "Dagger", "Great Sword", "Sword", "Great Axe", "Axe", "Scythe", "Polearm", "Great Katana", "Katana", "Staff", "Club", "Archery", "Marksmanship", "Throwing", "Shield", "Parrying", "Guarding", "Evasion");
$craftSkill = array("Fishing", "Woodworking", "Smithing", "Goldsmithing", "Clothcraft", "Leathercraft", "Bonecraft", "Alchemy", "Cooking");
$combatSkillIn = array();
$combatSkillOut = array();
$craftSkillIn = array();
$craftSkillOut = array();
$dayList = array("Firesday", "Earthsday", "Watersday", "Windsday", "Iceday", "Lightningday", "Lightsday", "Darksday");
$dayListIn = array();
$dayListOut = array();
foreach ($spellSkill as $spell) {
    array_push($spellSkillIn, "$spell magic skill");
    array_push($spellSkillOut, "[[:Category:$spell Magic|$spell magic skill]]");
}
foreach ($magicSkill as $magic) {
    array_push($magicSkillIn, "$magic skill");
    array_push($magicSkillOut, "[[:Category:$magic|$magic skill]]");
}
foreach ($combatSkill as $combat) {
    array_push($combatSkillIn, "$combat skill");
    $combat = str_replace($otherOut2, $otherIn2, $combat);
    array_push($combatSkillOut, "[[$combat|$combat skill]]");
}
foreach ($craftSkill as $craft) {
    array_push($craftSkillIn, "$craft skill");
    array_push($craftSkillOut, "[[$craft|$craft skill]]");
}
foreach ($dayList as $day) {
    array_push($dayListIn, $day."s");
    array_push($dayListOut, "[[$day|".$day."s]]");
}
$monsterListOut = array();
foreach ($monsterListIn as $monster) {
    array_push($monsterListOut, "[[:Category:".ucwords($monster)."|$monster]]");
}
$abilityListOut = array();
$traitListOut = array();
$killerListOut = array();
$resistListOut = array();
$relicWSListOut = array();
$propertyListIn = array($abilityListIn, $traitListIn, $killerListIn, $resistListIn, $relicWSListIn);
$propertyListOut = array();

for ($i=0; $i<count($propertyListIn); $i++) {
    $propertyListOut[$i] = array();
    for ($j=0; $j<count($propertyListIn[$i]); $j++) {
        $propertyListIn[$i][$j] = str_replace($otherOut2, $otherIn2, $propertyListIn[$i][$j]);
        $propertyListOut[$i][$j] = '[['.$propertyListIn[$i][$j].']]';
   }
   //print_r ($propertyListOut[$i]);
   //print "\r\n<br />";
}

$abilityListOut = $propertyListOut[0];
$traitListOut = $propertyListOut[1];
$killerListOut = $propertyListOut[2];
$resistListOut = $propertyListOut[3];
$relicWSListOut = $propertyListOut[4];

$jobListIn = array('WAR', 'MNK', 'WHM', 'BLM', 'RDM', 'THF', 'PLD', 'DRK', 'BST', 'BRD', 'RNG', 'SAM', 'NIN', 'DRG', 'SMN', 'BLU', 'COR', 'PUP', 'DNC', 'SCH');
$jobListOut = array('Warrior', 'Monk', 'White Mage', 'Black Mage', 'Red Mage', 'Thief', 'Paladin', 'Dark Knight', 'Beastmaster', 'Bard', 'Ranger', 'Samurai', 'Ninja', 'Dragoon', 'Summoner', 'Blue Mage', 'Corsair', 'Puppetmaster', 'Dancer', 'Scholar');


$raceListIn = array('HumeMale', 'HumeFemale', 'EvlaanMale', 'ElvaanFemale', 'TarutaruMale', 'TarutaruFemale');
$raceListOut = array('Hume Male', 'Hume Female', 'Evlaan Male', 'Elvaan Female', 'Tarutaru Male', 'Tarutaru Female');

$skillListIn = array('GreatAxe', 'GreatKatana', 'GreatSword', 'HandToHand', 'PoleArm', 'StringInstrument', 'Thrown', 'WindInstrument');
$skillListOut = array('Great Axe', 'Great Katana', 'Great Sword', 'Hand-to-Hand', 'Polearm', 'String Instrument', 'Throwing', 'Wind Instrument');

$safeListIn = array("San D'Oria", " Of ", " A ", " The ");
$safeListOut = array("San d'Oria", " of ", " a ", " the ");


$roman = array(" IV", " III", " II", " I",);

$magianLow = array("Simian Fists", "Mantis", "Wargfangs", "Cat's Claws", "Renegade", "Kartika", "Athame", "Dakini", "Schiavona", "Nobilis", "Soulsaber", "Sunblade", "Albion", "Salamand Sword", "Brand d'Arcon", "Splinter", "Bonebiter", "Punisher", "Skeggiold", "Sagaris", "Bonesplitter", "Luchtaine", "Hephaestus", "Stigma", "Ultimatum", "Vengeance", "Severance", "Copperhead", "Oathkeeper", "Bradamante", "Stribog", "Koruri", "Mozu", "Isatu", "Kuina", "Shirodachi", "Radennotachi", "Kurodachi", "Efunotachi", "Rageblow", "Culacula", "Goedendag", "Ingrimm", "Shillelagh", "Slaine", "Danda", "Teiwaz", "Kestrel", "Astrild", "Goshawk", "Gyrfalcon", "Blue Steel", "Magnatus", "Dragonmaw", "Huracan");
$magianWeapon = array("Revenant Fists", "Ursine Claws", "Taipan Fangs", "Barracudas", "Daka", "Parazonium", "Kila", "Fusetto", "Badelaire", "Khanda", "Shamshir", "Machaera", "Espafut", "Prestelame", "Sombrelame", "Kalavejs", "Alard's Axe", "Richardet's Axe", "Guichard's Axe", "Renaud's Axe", "Maschu", "Kunlun", "Atlas", "Sumeru", "Penitence", "Maleficence", "Absolution", "Reckoning", "Cerastes", "Corsesca", "Langdebeve", "Stingray", "Tobi", "Enchu", "Sekka", "Uzura", "Hiradennotachi", "Kokushitsunotachi", "Hyogugusarinotachi", "Keitonotachi", "Canne de Combat", "Naboot", "Hoeroa", "Makhila", "Taiaha", "Yantok", "Shareeravadi", "Agni's Staff", "Varuna's Staff", "Vayu's Staff", "Kubera's Staff", "Indra's Staff", "Soma's Staff", "Surya's Staff", "Yama's Staff", "Sedikutchi", "Harrier", "Condor", "Bateleur", "Sparrowhawk",
    "Bedlam", "Spitfire", "Mayhem", "Anarchy", "Dumuzis", "Ursa Majors", "Oxyuranis", "Sphyras", "Khandroma", "Praxidikai", "Thokcha", "Centovente", "Brunello", "Khadga", "Shikargar", "Thibron", "Xiphias", "Fulgurante", "Tenebreuse", "Kauriraris", "Sacripante", "Ganelon", "Astolfo", "Fernagu", "Shamash", "Liushi Shan", "Telamon", "Tavatimsa", "Umiliati", "Ogresse", "Cloacina", "Basanizo", "Daboya", "Chauve-Souris", "Nahvalr", "Sixgill", "Kasasagi", "Majimun", "Arisui", "Hitaki", "Torigashiranotachi", "Kawatsutsuminotachi", "Kabutsuchinotachi", "Kantonotachi", "Rose Couverte", "Tahtib", "Tutunui", "Ukaldi", "Paikea", "Urduja", "Tuahjebat", "Atar", "Vourukasha", "Vayuvata", "Vishrava", "Apamajas", "Haoma", "Arka", "Xsaeta", "Muruga", "Circinae", "Gymnogyps", "Terathopus", "Accipiter", "Mollfrith", "Aithon", "Erra", "Ataktos");
$woeWeapon = array("Revenant Fists", "Daka", "Badelaire", "Espafut", "Alard's Axe", "Maschu", "Penitence", "Cerastes", "Tobi", "Hiradennotachi", "Canne de Combat", "Taiaha", "Harrier", "Bedlam", "Dumuzis", "Khandroma", "Brunello", "Xiphias", "Sacripante", "Shamash", "Umiliati", "Daboya", "Kasasagi", "Torigashiranotachi", "Rose Couverte", "Paikea", "Circinae", "Mollfrith");
$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");

$relicArmorIn = array("Warrior's Mask", "Warrior's Lorica", "Warrior's Mufflers", "Warrior's Cuisses", "Warrior's Calligae", 'Melee Crown', 'Melee Cyclas', 'Melee Gloves', 'Melee Hose', 'Melee Gaiters', "Cleric's Cap", "Cleric's Briault", "Cleric's Mitts", "Cleric's Pantaloons", "Cleric's Duckbills", "Sorcerer's Petasos", "Sorcerer's Coat", "Sorcerer's Gloves", "Sorcerer's Tonban", "Sorcerer's Sabots", "Duelist's Chapeau", "Duelist's Tabard", "Duelist's Gloves", "Duelist's Tights", "Duelist's Boots", "Assassin's Bonnet", "Assassin's Vest", "Assassin's Armlets", "Assassin's Culottes", "Assassin's Poulaines", 'Valor Coronet', 'Valor Surcoat', 'Valor Gauntlets', 'Valor Breeches', 'Valor Leggings', 'Abyss Burgeonet', 'Abyss Cuirass', 'Abyss Gauntlets', 'Abyss Flanchard', 'Abyss Sollerets', 'Monster Helm', 'Monster Jackcoat', 'Monster Gloves', 'Monster Trousers', 'Monster Gaiters', "Bard's Roundlet", "Bard's Justaucorps", "Bard's Cuffs", "Bard's Cannions", "Bard's Slippers", "Scout's Beret", "Scout's Jerkin",
    "Scout's Bracers", "Scout's Braccae", "Scout's Socks", 'Saotome Kabuto', 'Saotome Domaru', 'Saotome Kote', 'Saotome Haidate', 'Saotome Sune-Ate', 'Koga Hatsuburi', 'Koga Chainmail', 'Koga Tekko', 'Koga Hakama', 'Koga Kyahan', 'Wyrm Armet', 'Wyrm Mail', 'Wyrm Finger Gauntlets', 'Wyrm Brais', 'Wyrm Greaves', "Summoner's Horn", "Summoner's Doublet", "Summoner's Bracers", "Summoner's Spats", "Summoner's Pigaches", 'Mirage Keffiyeh', 'Mirage Jubbah', 'Mirage Bazubands', 'Mirage Shalwar', 'Mirage Charuqs', "Commodore's Tricorne", 'Commodore Frac', 'Commodore Gants', 'Commodore Culottes', 'Commodore Bottes', 'Pantin Taj', 'Pantin Tobe', 'Pantin Dastanas', 'Pantin Churidars', 'Pantin Babouches', 'Etoile Tiara', 'Etoile Casaque', 'Etoile Bangles', 'Etoile Tights', 'Etoile Toe Shoes', 'Argute Mortarboard', 'Argute Gown', 'Argute Bracers', 'Argute Pants', 'Argute Loafers');
$empyreanArmorIn = array("Ravager's Mask", "Ravager's Lorica", "Ravager's Mufflers", "Ravager's Cuisses", "Ravager's Calligae", "Tantra Crown", "Tantra Cyclas", "Tantra Gloves", "Tantra Hose", "Tantra Gaiters", "Orison Cap", "Orison Bliaud", "Orison Mitts", "Orison Pantaloons", "Orison Duckbills", "Goetia Petasos", "Goetia Coat", "Goetia Gloves", "Goetia Chausses", "Goetia Sabots", "Estoqueur's Chappel", "Estoqueur's Sayon", "Estoqueur's Gantherots", "Estoqueur's Fuseau", "Estoqueur's Houseaux", "Raider's Bonnet", "Raider's Vest", "Raider's Armlets", "Raider's Culottes", "Raider's Poulaines", "Creed Armet", "Creed Cuirass", "Creed Gauntlets", "Creed Cuisses", "Creed Sabatons", "Bale Burgeonet", "Bale Cuirass", "Bale Gauntlets", "Bale Flanchard", "Bale Sollerets", "Ferine Cabasset", "Ferine Gausape", "Ferine Manoplas", "Ferine Quijotes", "Ferine Ocreae", "Aoidos' Calot", "Aoidos' Hongreline", "Aoidos' Manchettes", "Aoidos' Rhingrave", "Aoidos' Cothurnes", "Sylvan Gapette", "Sylvan Caban",
    "Sylvan Glovelettes", "Sylvan Bragues", "Sylvan Bottillons", "Unkai Kabuto", "Unkai Domaru", "Unkai Kote", "Unkai Haidate", "Unkai Sune-Ate", "Iga Zukin", "Iga Ningi", "Iga Tekko", "Iga Hakama", "Iga Kyahan", "Lancer's Mezail", "Lancer's Plackart", "Lancer's Vambraces", "Lancer's Cuissots", "Lancer's Schynbalds", "Caller's Horn", "Caller's Doublet", "Caller's Bracers", "Caller's Spats", "Caller's Pigaches", "Mavi Kavuk", "Mavi Mintan", "Mavi Bazuband", "Mavi Tayt", "Mavi Basmak", "Navarch's Tricorne", "Navarch's Frac", "Navarch's Gants", "Navarch's Culottes", "Navarch's Bottes", "Cirque Capello", "Cirque Farsetto", "Cirque Guanti", "Cirque Pantaloni", "Cirque Scarpe", "Charis Tiara", "Charis Casaque", "Charis Bangles", "Charis Tights", "Charis Toeshoes", "Savant's Bonnet", "Savant's Gown", "Savant's Bracers", "Savant's Pants", "Savant's Loafers");
$artifactTorqueIn = array("Fighter's Torque", "Temple Torque", "Healer's Torque", "Wizard's Torque", "Warlock's Torque", "Rogue's Torque", "Gallant Torque", "Chaos Torque", "Beast Torque", "Choral Torque", "Hunter's Torque", "Myochin Shusa", "Ninja Shusa", "Drachen Torque", "Evoker's Torque", "Magus Torque", "Corsair's Torque", "Puppetry Torque", "Dancer's Torque", "Scholar's Torque");


$magianCategories = array();
$magianCategories['Hand-to-Hand'] = 'Hand-to-Hand';
$magianCategories['Dagger'] = 'Dagger';
$magianCategories['Sword'] = 'Sword';
$magianCategories['Great Sword'] = 'Great Sword';
$magianCategories['Axe'] = 'Axe';
$magianCategories['Great Axe'] = 'Great Axe';
$magianCategories['Scythe'] = 'Scythe';
$magianCategories['Polearm'] = 'Polearm';
$magianCategories['Katana'] = 'Katana';
$magianCategories['Great Katana'] = 'Great Katana';
$magianCategories['Club'] = 'Club';
$magianCategories['Staff'] = 'Staff';
$magianCategories['Ranged'] = 'Archery';
$magianCategories['Archery'] = 'Archery';
$magianCategories['Marksmanship'] = 'Marksmanship';
$magianCategories['Wind Instrument'] = 'Instrument';
$magianCategories['String Instrument'] = 'Instrument';
$magianCategories['Shields'] = 'Shields';
$magianCategories['Head'] = 'Head';
$magianCategories['Neck'] = 'Neck';
$magianCategories['Body'] = 'Body';
$magianCategories['Hands'] = 'Hand';
$magianCategories['Waist'] = 'Waist';
$magianCategories['Back'] = 'Back';
$magianCategories['Rings'] = 'Ring';
$magianCategories['Earrings'] = 'Earring';
$magianCategories['Ears'] = 'Earring';
$magianCategories['Legs'] = 'Leg';
$magianCategories['Feet'] = 'Feet';

//Not actual magians, but useful for reassigning items to wiki categories
$magianCategories['Grips'] = 'Grips';
$magianCategories['Fishing'] = 'Fishing Gear';
$magianCategories['Fishing Gear'] = 'Fishing Gear';
$magianCategories['PetItems'] = 'Pet Items';
$magianCategories['Shield'] = 'Shields';


$primativeIn = array('"', ':', '?');
$primativeOut = array('_', '_', '_');
$imageIn = array('"', ':');
$imageOut = array('', '-');
$colors = array("ffffff", "e3eafd");
$counter = 0;


/*  If new item tables are added to the game in the future, make sure to update
$itemHandlesIn with the approprate start numbers of those files and
$itemHandlesOut with the link to $fileList.  The new numbers for itemHandlesIn
should always be added in before 999999999999.  Also, make sure to put them
in numerical order!
-Septy
*/

$itemHandlesIn = array(0, 4096, 10240, 16384, 27648, 28672, 999999999999);
$itemHandlesOut = array(1, 2, 4, 5, 4, 3);

if ($category == "ALL") {
    $category = '';
} elseif (strlen($category) > 0) {
    $category = urldecode($category);
    $subCat = '';
    if (strrpos($category, '#') > 0) {
       $categoryExplode = explode('#', $category);
       $category = $categoryExplode[0];
       $subCat = $categoryExplode[1];
    }
}

if (strlen($ind) > 0 && strlen($fileNum) == 0) {
    foreach($itemHandlesOut as $k => $n) {
        $fileNum = ($ind >= $itemHandlesIn[$k] && $ind < $itemHandlesIn[$k+1]) ? $n : $fileNum;
        //print "$ind | " . $itemHandlesIn[$k] . " | " . $itemHandlesIn[$k+1] . " | $k | $n | $fileNum\r\n<br />";
    }
}

if (strlen($fileNum) == 0 && $action == null) {
    print "<table width=\"1000\" border=\"0\" cellspacing=\"1\" cellpadding=\"2\">
  <tr>
    <td colspan=\"4\" align=\"left\">
    <font size=\"+2\"><b>Items</b></font>
    </td></tr>
    <tr>
    <td valign=\"top\" width=\"25%\">
<b>Simple Listings</b><br />
* <a href=\"Neo-Item-O-Matic.php?fileNum=1&action=List\">General Items</a><br />
* <a href=\"Neo-Item-O-Matic.php?fileNum=2&action=List\">Usable Items</a><br />
* <a href=\"Neo-Item-O-Matic.php?fileNum=3&action=List\">Vouchers and Slips</a><br />
* <a href=\"Neo-Item-O-Matic.php?action=AlphaS\">Alphabetical Listing</a>
    </td>
    <td valign=\"top\" width=\"25%\">
<b>Update Formatted Listings</b><br />
* <a href=\"Neo-Item-O-Matic.php?fileNum=1&action=uList\">General Items</a><br />
* <a href=\"Neo-Item-O-Matic.php?fileNum=2&action=uList\">Usable Items</a><br />
* <a href=\"Neo-Item-O-Matic.php?fileNum=3&action=uList\">Vouchers and Slips</a><br />
* <a href=\"Neo-Item-O-Matic.php?&action=furnishings\">Furnishings</a><br />
    </td>
    <td valign=\"top\" width=\"25%\">

    </td>
    <td valign=\"top\" width=\"25%\">
    
    </td>
  </tr>
</table>";

    $array = @file('weaponsData.txt');
    $catList = array();
    foreach ($array as $row) {

        $newRow = explode("|", $row);

        $curCat = ($newRow[11] != 'Main, Sub' && $newRow[11] != 'Main') ? urlencode($newRow[17].'#'.$newRow[11]) : $curCat = urlencode($newRow[17]);

        if ($catList[$curCat] > 0) {
            $catList[$curCat]++;
        } else {
            $catList[$curCat] = 1;
        }
    }
    print "<table width=\"1000\" border=\"0\" cellspacing=\"1\" cellpadding=\"2\">
  <tr>
    <td colspan=\"4\" align=\"left\">
    <font size=\"+2\"><b>Weapons</b></font>
    </td></tr>
    <tr>
    <td valign=\"top\" width=\"25%\"> <b>Category formatted listing</b><br />";
    foreach($catList as $key => $thisRow) {
        $cat = urldecode($key);
        print "<a href=\"Neo-Item-O-Matic.php?&fileNum=5&category=$key&action=index\">$cat</a>- ($thisRow)<br />\r\n";
    }
    print "</td>
    <td valign=\"top\" width=\"25%\"><b>Singular listing</b><br />";
    $listTot = 0;
    foreach($catList as $key => $thisRow) {
        $cat = urldecode($key);
        $listTot += $thisRow;
        print "<a href=\"Neo-Item-O-Matic.php?&fileNum=5&category=$key&action=List\">$cat</a>- ($thisRow)<br />\r\n";
    }
    print "<a href=\"Neo-Item-O-Matic.php?&fileNum=5&category=All&action=List\">All armor</a>- ($listTot)<br />\r\n";

    print "</td>
    <td valign=\"top\" width=\"25%\"><b>Update formatted listing</b><br />";
    foreach($catList as $key => $thisRow) {
        $cat = urldecode($key);
        print "<a href=\"Neo-Item-O-Matic.php?&fileNum=5&category=$key&action=update\">$cat</a>- ($thisRow)<br />\r\n";
    }
    print "</td>
    <td valign=\"top\" width=\"25%\"><b>Singular resource listing</b><br />";
    $listTot = 0;
    foreach($catList as $key => $thisRow) {
        $listTot += $thisRow;
        $cat = urldecode($key);
        print "<a href=\"Item-O-Matic.php?&fileNum=5&category=$key&action=List&icons=1\">$cat</a>- ($thisRow)<br />\r\n";
    }
    print "<a href=\"Item-O-Matic.php?&fileNum=5&category=All&action=List&icons=1\">All armor</a>- ($listTot)<br />\r\n";
    print "</td>
  </tr>
</table>";

    $array = @file('armorData.txt');
    $catList = array();
    foreach ($array as $row) {

        $newRow = explode("|", $row);
        if ($catList[$newRow[11]] > 0) {
            $catList[$newRow[11]]++;
        } else {
            $catList[$newRow[11]] = 1;
        }
    }
    print "<table width=\"1000\" border=\"0\" cellspacing=\"1\" cellpadding=\"2\">
  <tr>
    <td colspan=\"4\" align=\"left\">
    <font size=\"+2\"><b>Armor</b></font>
    </td></tr>
    <tr>
    <td valign=\"top\" width=\"25\"%> <b>Category formatted listing</b><br />";
    foreach($catList as $key => $thisRow) {
        print "<a href=\"Item-O-Matic.php?&fileNum=4&category=$key&action=index\">$key</a>- ($thisRow)<br />\r\n";
    }
    print "</td>
    <td valign=\"top\" width=\"25\"%><b>Singular listing</b><br />";
    $listTot = 0;
    foreach($catList as $key => $thisRow) {
        $listTot += $thisRow;
        print "<a href=\"Item-O-Matic.php?&fileNum=4&category=$key&action=List\">$key</a>- ($thisRow)<br />\r\n";
    }
    print "<a href=\"Item-O-Matic.php?&fileNum=4&category=All&action=List\">All armor</a>- ($listTot)<br />\r\n";

    print "</td>
    <td valign=\"top\" width=\"25\"%><b>Update formatted listing</b><br />";
    foreach($catList as $key => $thisRow) {
        print "<a href=\"Item-O-Matic.php?&fileNum=4&category=$key&action=update\">$key</a>- ($thisRow)<br />\r\n";
    }
    print "</td>
    <td valign=\"top\" width=\"25\"%><b>Singular resource listing</b><br />";
    $listTot = 0;
    foreach($catList as $key => $thisRow) {
        $listTot += $thisRow;
        print "<a href=\"Item-O-Matic.php?&fileNum=4&category=$key&action=List&icons=1\">$key</a>- ($thisRow)<br />\r\n";
    }
    print "<a href=\"Item-O-Matic.php?&fileNum=4&category=All&action=List&icons=1\">All armor</a>- ($listTot)<br />\r\n";
    print "</td>
  </tr>
</table>";

}elseif ($action == "List") {
    $array = @file($fileList[$fileNum]);
    $checkCat = (strlen($category) > 0) ? true : false;
    $doIcon = ($icons == 1) ? '&icons=1' : '';
    foreach ($array as $num => $row) {
        $newRow = explode("|", $row);
        //print "$checkCat | $fileNum | $category | " . $newRow[17] . " | $subCat | " . $newRow[11] . "\r\n<br />";
        if ($checkCat == false || ($fileNum == 5 && $newRow[17] == $category && ($newRow[11] == $subCat || $subCat==null)) || ($fileNum == 4 && $newRow[11] == $category)) {
            $name = $newRow[3];
            $wikiName = $newRow[2];
            $longName = ucitem($newRow[4]);
            $ind = $newRow[1];
            $link = ($wikiName != $longName) ? $wikiName."|".$longName : $wikiName;
            print "* [[<a href=\"Item-O-Matic.php?ind=$ind$doIcon\">$link</a>]]<br />\r\n";
        }
    }
} elseif ($action == "index") {
    $array = @file($fileList[$fileNum]);
    if ($fileNum == 5) {
        print "==Weapon List==
<br />
<br />{| class=sortable style=\"text-align:center; background-color:#799bfb\" width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\"
<br />|- BGCOLOR=\"#b7cbfe\"
<br />! width=\"15%\" | Weapon Name
<br />! width=\"1%\" class=\"unsortable\" | R
<br />! width=\"1%\" class=\"unsortable\" | E
<br />! width=\"1%\" class=\"unsortable\" | M
<br />! width=\"5%\" | Level
<br />! width=\"5%\" | Damage
<br />! width=\"5%\" | Delay
<br />! width=\"5%\" | DPS
<br />! width=\"45%\" class=\"unsortable\"|Additional Effects
<br />! width=\"15%\"|Jobs\r\n<br />";
    } else {
        print "[[Category:Item]] [[Category:Armor]]\r\n<br />== Equipment List ==
<br />
<br />{| class=sortable style=\"text-align:center; background-color:#799bfb\" width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\"
<br />|- BGCOLOR=\"#ADBDCC\"
<br />! width=\"15%\" | Equipment Name
<br />! width=\"1%\" class=\"unsortable\" | R
<br />! width=\"1%\" class=\"unsortable\" | E
<br />! width=\"1%\" class=\"unsortable\" | M
<br />! width=\"5%\"| Level
<br />! width=\"5%\"| Defense
<br />! width=\"45%\" class=\"unsortable\"| Additional Effects
<br />! width=\"15%\"| Jobs\r\n<br />";
    }
    $enchantList = ($fileNum == 5) ? array(18, 19, 20, 21) : array(16, 17, 18, 19);
    foreach ($array as $num => $row) {
        $newRow = explode("|", $row);
        //print $newRow[7]." || ".$newRow[18]." || $category || ".$newRow[12]." || $subCat\r\n<br />";
        if (($fileNum == 5 && $newRow[17] == $category && ($newRow[11] == $subCat || $subCat==null)) || ($fileNum == 4 && $newRow[11] == $category)) {
            if ($newRow[3] != "." && $newRow[3] != null) {
                $col = $colors[$counter%2];
                $counter++;
                $rare = '';
                $ex = '';
                $tags = '';
                $spText = '';
                $name = $newRow[3];
                $wikiName = $newRow[2];
                $longName = ucitem($newRow[4]);
                $link = ($wikiName != $longName) ? $wikiName."|".$longName : $wikiName;
                $level = $newRow[10];
                //$tags = "&lt;br /&gt;";
                if (strrpos($newRow[6], "Rare") !== false) {
                   $rare = "{{Icon|Rare}}";
                   $tags = " ";
                }
                if (strstr($newRow[6], "Ex") !== false) {
                   $ex = "{{Icon|Ex}}";
                   $tags = " ";
                }
                $strip = explode('+', ucitem($newRow[4]));
                $hq = trim($strip[1]);
                $strip[0] = str_replace($roman, '', $strip[0]);
                $baseName = trim($strip[0]);
                $link = "'''[[<a href=\"Weapon-O-Matic.php?&type=singular&id=$num\">$link</a>]]'''";
                $jobs = str_replace('"', '', $newRow[13]);
                $description = str_replace('[br]', ' ', $newRow[7]);
                if ($jobs != "All") {
                    $jobs = "[[". str_replace(', ', ']] / [[', $jobs)."]]";
                }
                if ($fileNum == 5) {
                    $specialCheck = str_replace($specialWeaponIn, $specialWeaponOut, $baseName);
                    $specialCheck = str_replace($magianWeapon, "Magian", $specialCheck);
                    $specialCheck = str_replace($magianLow, "Magian", $specialCheck);
                    $magCat = $magianCategories[$category];
                    if ((($specialCheck == "Relic" || $specialCheck == 'Empyrean' || $specialCheck == 'Mythic') && $level > 75) || $specialCheck == 'Magian') {
                       $tags = " ";
                       $spText = " {{Magian Icon|$magCat}}";
                    }
                    //$link = "'''[[<a href=\"Weapon-O-Matic.php?&type=singular&id=$num\">$link</a>]]'''$tags$rare$ex$spText";
                    $dps = " - ";
                    $delay = " ";
                    $delayExplode = explode("(", $newRow[16]);
                    $damage = "-";
                    $delayExplode[1] = str_replace(')', '', $delayExplode[1]);
                    if ($category != "Hand-to-Hand" && $category !="Fishing" && $category != "Pet Items" && $category != "None" && $category != "Wind Instrument" && $category != "String Instrument" && $category != '-' && $category != 'Grips') {
                       $dps = ($category != "Thrown") ? $newRow[16] : '-';
                       $delay = $newRow[15];
                       $damage = $newRow[14];
                       $descExplode = explode(" ", $description);
                       $descExplode = array_slice($descExplode, 2);
                       $description = implode(" ", $descExplode);
                    } elseif ($category == "Hand-to-Hand") {
                        $delay = $newRow[15];
                        $damage = $newRow[14];
                        $damageExplode = explode(" ", $damage);
                        $descExplode = explode(" ", $description);
                        $descExplode = array_slice($descExplode, 2);
                        $description = implode(" ", $descExplode);
                    }
                } else {
                    $specialCheck = str_replace($specialWeaponIn, $specialWeaponOut, $baseName);
                    $specialCheck = str_replace($relicArmorIn, "Relic", $specialCheck);
                    $specialCheck = str_replace($empyreanArmorIn, "Empyrean", $specialCheck);
                    $specialCheck = str_replace($artifactTorqueIn, "Artifact Torque", $specialCheck);
                    $spText = '';
                    $magCat = $magianCategories[$category];
                    if (($specialCheck == "Relic" && $hq == 2) || ($specialCheck == 'Empyrean' && $hq >= 1) || ($category == 'Shields' && $level > 75)) {
                        $spText = " {{Magian Icon|$magCat}}";
                    } elseif ($specialCheck == 'Artifact Torque') {
                        $spText = " {{Magian Icon|Job Emote}}";
                    }
                    $descExplode = explode(" ", $description);
                    $defense = ($newRow[14] != null) ? $newRow[14] : 0;
                    $defense = str_replace('"', '', $defense);
                    $defense = str_replace('~', '', $defense);
                    if (strstr($descExplode[0], "DEF:") === false ) {
                        $description = implode(" ", $descExplode);
                    } else {
                        if (strstr($defense, "~") === false) {
                            $descExplode = array_slice($descExplode, 1);
                            $description = implode(" ", $descExplode);
                        } else {
                            $description = implode(" ", $descExplode);
                        }
                    }
                }

                $description = str_replace($otherIn0, $otherOut0, $description);
                $description = str_replace($otherIn, $otherOut, $description);
                $description = str_replace($elementIn, $elementOut, $description);
                $description = str_replace($monsterListIn, $monsterListOut, $description);
                $description = str_replace($traitListIn, $traitListOut, $description);
                $description = str_replace($abilityListIn, $abilityListOut, $description);
                $description = str_replace($killerListIn, $killerListOut, $description);
                $description = str_replace($resistListIn, $resistListOut, $description);
                $description = str_replace($relicWSListIn, $relicWSListOut, $description);
                $description = str_replace($spellSkillIn, $spellSkillOut, $description);
                $description = str_replace($magicSkillIn, $magicSkillOut, $description);
                $description = str_replace($combatSkillIn, $combatSkillOut, $description);
                $description = str_replace($craftSkillIn, $craftSkillOut, $description);
                $description = str_replace($dayListIn, $dayListOut, $description);
                $description = str_replace($otherIn1, $otherOut1, $description);
                $description = str_replace($statIn, $statOut, $description);
                $description = str_replace($otherIn2, $otherOut2, $description);
                
                $enchant0 = $newRow[$enchantList[0]];
                if ($enchant0 > 0) {
                    $enchant1 = getEnchantment($newRow[$enchantList[2]], 'l');
                    $enchant2 = getEnchantment($newRow[$enchantList[3]], 'l');
                    $description .= "<br />&lt;$enchant0/$enchant0 $enchant1/[$enchant2, $enchant1]&gt;";
                }
                if ($fileNum == 5) {
                    print "|- BGCOLOR=\"#$col\"<br />\r\n";
                    print "| BGCOLOR=\"#ccccff\" | $link<br />\r\n";
                    print "| $rare<br />\r\n";
                    print "| $ex<br />\r\n";
                    print "| $spText<br />\r\n";
                    print "| $level<br />\r\n";
                    print "| $damage<br />\r\n";
                    print "| $delay<br />\r\n";
                    print "| $dps<br />\r\n";
                    print "| $description<br />\r\n";
                    print "| $jobs<br />\r\n";
                } else {
                    print "|- BGCOLOR=\"#$col\"<br />\r\n";
                    print "| BGCOLOR=\"#CEE0F2\" | $link<br />\r\n";
                    print "| $rare<br />\r\n";
                    print "| $ex<br />\r\n";
                    print "| $spText<br />\r\n";
                    print "| $level<br />\r\n";
                    print "| $defense<br />\r\n";
                    print "| $description<br />\r\n";
                    print "| $jobs<br />\r\n";
                }
            }
        }
    }
    print "|-\r\n<br />|}";
} elseif ($action == "update" ) {
    $array = @file($fileList[$fileNum]);
    print "{| border=1\r\n<br />";
    $enchantList = ($fileNum == 5) ? array(18, 19, 20, 21) : array(16, 17, 18, 19);
    foreach ($array as $num => $row) {
        $newRow = explode("|", $row);
        //print $newRow[7]." || ".$newRow[18]." || $category || ".$newRow[12]." || $subCat\r\n<br />";
        if (($fileNum == 5 && $newRow[17] == $category && ($newRow[11] == $subCat || $subCat == '')) || ($fileNum == 4 && $newRow[11] == $category)) {

            if ($newRow[3] != "." && $newRow[3] != null) {
                $rare = '';
                $ex = '';
                $tags = '';
                $name = $newRow[3];
                $wikiName = $newRow[2];
                $imageRename = str_replace($imageIn, $imageOut, $wikiName);
                $longName = ucitem($newRow[4]);
                $link = ($wikiName != $longName) ? $wikiName."|".$longName : $wikiName;
                if (strrpos($newRow[6], "Rare") !== false) {
                   $rare = "{{Rare}}";
                   $tags = ' ';
                }
                if (strstr($newRow[6], "Ex") !== false) {
                   $ex = "{{Ex}}";
                   $tags = ' ';
                }
                $link = "[[<a href=\"Weapon-O-Matic.php?&type=singular&id=$num&icons=1\">$link</a>]]$tags$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);
                $description = str_replace($elementIn, $elementOut, $description);

                $skill = ($fileNum == 5) ? $magianCategories[$newRow[17]] : $magianCategories[$newRow[11]];
                //$skill = ($skill == 'Shield') ? 'Shields' : $skill;
                $catType = (strlen($skill) > 0) ? "[[:Category:$skill|$skill]]" : '-';

                $enchant0 = $newRow[$enchantList[0]];
                if ($enchant0 > 0) {
                    $enchant1 = getEnchantment($newRow[$enchantList[2]], 'l');
                    $enchant2 = getEnchantment($newRow[$enchantList[3]], 'l');
                    $description .= "<br />&lt;$enchant0/$enchant0 $enchant1/[$enchant2, $enchant1]&gt;";
                }
                print "|-<br />
| $link<br />
| [[Image:$imageRename icon.png]]<br />
| ".$newRow[10]."<br />
| $catType<br />
| $description<br />
| $jobs<br />";

            }
        }
    }
    print "|-\r\n<br />|}";
} elseif ($action == "uList") {
    $array = @file($fileList[$fileNum]);
    foreach ($array as $num => $row) {
        $newRow = explode("|", $row);
        $name = $newRow[3];
        $wikiName = $newRow[2];
        $longName = ucitem($newRow[4]);
        $link = ($wikiName != $longName) ? "$wikiName|$longName" : $wikiName;
        $fancyImageName = str_replace($imageIn, $imageOut, $wikiName);
        $flags = str_replace($flagListIn, $flagListOut, $mewRow[6]);
        $description = str_replace('<br />', ' ', $newRow[7]);
        $description = str_replace('[br]', ' ', $description);
        $ind = $newRow[1];
        $stack = $newRow[8];
        $rare = '';
        $ex = '';
        if (strrpos($newRow[6], "Rare") !== false) {
            $rare = "{{Rare}}";
        }
        if (strstr($newRow[6], "Ex") !== false) {
            $ex = "{{Ex}}";
        }
        print "|-<br />
| [[<a href=\"Item-O-Matic.php?&ind=$ind&icons=1\">$link</a>]]$rare$ex<br />
| [[Image:$fancyImageName icon.png]]<br />
| $stack<br />
| $description<br />";
    }
} elseif ($action == "AlphaS") {

    $nameList = array();
    for($n = 1; $n<4; $n++) {
        $array = @file($fileList[$n]);
        foreach ($array as $num => $row) {
            $newRow = explode("|", $row);
            $primative = $newRow[3];
            $ind = $newRow[1];
            $name = $newRow[3];
            $wikiName = $newRow[2];
            $longName = ucitem($newRow[4]);
            $link = ($wikiName != $longName) ? $wikiName."|".$longName : $wikiName;
            $primative = str_replace($primativeIn, $primativeOut, $wikiName);
            $imNum = "[".substr('00000000', 0, (8-strlen($newRow[1]))).$newRow[1]."] $primative.png";
            $fancyImageName = str_replace($imageIn, $imageOut, $wikiName);
            $nameList[$primative] = "* [[<a href=\"Item-O-Matic.php?&ind=$ind\">$link</a>]]<br />\r\n";
        }
    }
    ksort($nameList);
    foreach ($nameList as $key => $row) {
        print $row;
    }
} elseif ($action == 'furnishings') {
    $array = @file('item1Data.txt');
    print "== Furniture List ==
<br />{| style=\"background:#eef3f7; text-align: center;\" class=\"wikitable sortable\" cellpadding=\"2\" width=\"100%\"
<br />! style=\"background:#ccebfe; border-color: #59c1ff;\" colspan=\"1\" width=\"20%\"| Name
<br />! style=\"background:#ccebfe; border-color: #59c1ff;\" colspan=\"1\" width=\"20%\"| Effect
<br />! style=\"background:#ccebfe; border-color: #59c1ff;\" colspan=\"1\" width=\"12%\"| Element
<br />! style=\"background:#ccebfe; border-color: #59c1ff;\" colspan=\"1\" width=\"12%\"| Storage
<br />! style=\"background:#ccebfe; border-color: #59c1ff;\" colspan=\"1\" width=\"8%\"| Aura
<br />|-";
    foreach ($array as $n => $row) {
        $currow = explode('|', $row);
        if ($currow[0] == 'FFXI Furnishing' || $currow[0] == 'FFXI Flowerpot' || $currow[0] == 'FFXI Mannequin') {
            $wikiName = trim($currow[2]);
            $longName = ucItem(trim($currow[4]));
            if ($currow[0] == 'FFXI Mannequin') {
                $rep = (strpos($wikiName, 'F Mannequin') === true) ? "&#9792;" : "&#9794;";
                $longName = str_replace('?', $rep, $longName);
            }
            $link = ($wikiName != $longName) ? "[[$wikiName|$longName]]" : "[[$wikiName]]";
            $element = $currow[10];
            $storage = $currow[11];
            print "\r\n<br />| style=\"border-color: #59c1ff;\"| $link
<br />| style=\"border-color: #59c1ff;\"|
<br />| style=\"border-color: #59c1ff;\"| $element
<br />| style=\"border-color: #59c1ff;\"| $storage
<br />| style=\"border-color: #59c1ff;\"|
<br />|-";
        }
    }
    print "\r\n\r\n<br />|}";
} elseif ((strlen($id) > 0 || strlen($ind) > 0)) {
    $array = @file($fileList[$fileNum]);
    if (strlen($ind) > 0) {
        foreach ($array as $key => $row) {
            $row = explode('|', $row);
            if ($row[1] == $ind) {
                $id = $key;
                break 1;
            }
        }
    }
    //print "$ind | $id | $fileList[$fileNum]";
    $useIcon = ($icons == 1) ? true : false;
    if ($id !== null) {
        $row = $array[$id];
        writeTemplate($row, $useIcon, false);
    }
}

?>
