<?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 == "Zone Adversary") {
        foreach($itemList as $key => $thisRow) {
            print "";
        }
    } elseif ($listType == "Zone NM") {
        foreach($itemList as $key => $thisRow) {
            print "{{Zone NM Row<br />
|NM.Name=$key<br />
|NM.Family=<br />
|NM.Main=<br />
|NM.Sub=<br />
|NM.Links=<br />
|NM.Aggressive=<br />
|NM.Detects=<br />
|NM.Minimum_Level=<br />
|NM.Maximum_Level=<br />
|NM.Spawns=<br />
|NM.Spawn_Condition=<br />
|NM.Treasure=<br />
|NM.Steal=<br />
|NM.Position=<br />
|NM.Map=1<br />
}}";
        }
    } elseif ($listType == "Adversary") {
        foreach($itemList as $key => $thisRow) {
            print "&nbsp;&lt;page&gt;<br />
    &nbsp;&nbsp;&lt;title&gt;$key&lt;/title&gt;<br />
		&nbsp;&nbsp;&lt;revision&gt;<br />
			&nbsp;&nbsp;&nbsp;&lt;text xml:space=&quot;preserve&quot; bytes=&quot;398&quot;&gt;{{Adversary Table<br />
			}}&lt;/text&gt;<br />
		&nbsp;&nbsp;&lt;/revision&gt;<br />
  &nbsp;&lt;/page&gt;<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=\"Zone Adversary\" checked=\"checked\" />
    Zone Adversary</label>
    <label>
    <input type=\"radio\" name=\"listType\" id=\"listType\" value=\"Zone NM\" />
    Zone NM</label>
    <label>
    <input type=\"radio\" name=\"listType\" id=\"listType\" value=\"Zone NPC\" />
    Zone NPC</label>
    <label>
    <input type=\"radio\" name=\"listType\" id=\"listType\" value=\"Adversary\" />
    Adversary</label>
    <label>
    <input type=\"radio\" name=\"listType\" id=\"listType\" value=\"NPC\" />
    NPC</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>";

}




?>
