<?php
ini_set("display_errors", "on");
error_reporting(E_ALL ^ E_NOTICE);

$textListing = $_POST['textListing'];
$listType = $_POST['listType'];

if ($textListing != null) {
    $textArray = explode("\r", $textListing);
    sort($textArray);
    $itemList = array();
    foreach ($textArray as $row) {
        $row = trim($row);
        if ($itemList[$row] > 0) {
            $itemList[$row]++;
        } else {
            $itemList[$row] = 1;
        }
    }
    if ($listType == "NPC") {
        foreach($itemList as $key => $thisRow) {
            print "{{Zone NPC<br />
|NPC Name=$key<br />
|Position (pos)=<br />
|Function/Role=<br />
}}<br />";
        }
    } elseif ($listType == "NM") {
        foreach($itemList as $key => $thisRow) {
            print "{{Zone Bestiary<br />
|Monster Name=$key<br />
|Level Range=<br />
|Pop Position (pos)=<br />
|Notable Drops=<br />
*[[Place Name of Drop Here]]<br />
|Aggros To=<br />
|Monster Family Type=<br />
|Spawn Condition=<br />
}}
<br />";
        }
    } elseif ($listType == "Monster") {
        foreach($itemList as $key => $thisRow) {
            print "{{Zone Monster Instance |$key | | | | | | | |$thisRow | | }}\r\n<br />";
        }
    } else {
       foreach($itemList as $key => $thisRow) {
            print "$key ($thisRow)\r\n<br />";
        }
    }

} else {
    print "<form id=\"form1\" name=\"form1\" method=\"post\" action=\"Sort-O-Matic.php\">
  <label>Text Listing<br />
  <textarea name=\"textListing\" id=\"textListing\" cols=\"45\" rows=\"5\"></textarea>
  </label>
  <p>
    <label>
    <input type=\"radio\" name=\"listType\" id=\"listType\" value=\"Monster\" checked=\"checked\" />
    Monster Listing</label>
    <label>
    <input type=\"radio\" name=\"listType\" id=\"listType\" value=\"NM\" />
    Notorious Monsters Listing</label>
    <label>
    <input type=\"radio\" name=\"listType\" id=\"listType\" value=\"NPC\" />
    NPC Listing</label>
    <label>
    <input type=\"radio\" name=\"listType\" id=\"listType\" value=\"None\" checked=\"checked\" />
    None</label>
  </p>
  <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>";

}




?>
