<?php
    // admin.php
    
    if (isInGroup($CURRENTUSER, 'admin'))
    {
        switch ($action):
        case "g_default":
        drawMainTop();
        print "TODO: Create a snazzy report page showing various metrics of the site's status";
        drawMainBottom();
        break;
         
         
        case "g_viewReferers":
         
        $referers = mysql_query("SELECT referer FROM hittracker ORDER BY ID DESC LIMIT 0,100");
         
        drawMainTop();
        while ($refs = mysql_fetch_array($referers ) )
        {
             
            print("<a href='". $refs['referer']. "'>" . $refs['referer'] . "</a><br />" );
        }
        drawMainBottom();
        break;
         
         
        case "g_viewAccessLog":
         
        $hits = mysql_query("select * from hittracker order by ID desc limit 0,100") or die (mysql_error());
         
        drawMainTop();
        while ($row = mysql_fetch_array($hits))
        {
             
            print "<b>Hit</b>: $row[ID] <br /> ";
            print "<b>Time</b>: ". date("r", $row['date']) ." <br /> ";
            print "<b>User</b>: $row[user] <br /> ";
            print "<b>Shard</b>: $row[shard]<br />";
            print "<b>Action</b>: $row[action]<br />";
            print "<b>ObjectID</b>: $row[objectID]<br />";
            print "<b>User IP</b>: $row[userIP]<br />";
            print "<b>Ref</b>: <a href='" . $row['referer'] . "'>". $row['referer'] . "</a><br /><br />";
             
             
        }
        drawMainBottom();
         
        break;
        case "g_manageForum":
         
        // Display forums
        $forumList = mysql_query("select * from forumList where parentForumID=0") or die(mysql_error());
        drawMainTop();
        print "<font class='headC1'><u>Forum Listing:</u></font><br /><br />";
        print "<table width=\"90%\" cellspacing=0>";
         
        while ($row = mysql_fetch_array($forumList))
        {
             
            print "<tr><td class='forumDisplayTableHead'><a href='index.php?shard=admin&amp;action=g_editForum&amp;ID=$row[ID]'>$row[forumName]</a><br />";
            print "<font class='fineC2'>$row[forumDescription]</font></td></tr>";
             
             
            $subForums = mysql_query("select * from forumList where parentForumID=$row[ID]") or die(mysql_error());
            while ($row2 = mysql_fetch_array($subForums))
            {
                print "<tr><td class='forumDisplayTableBody'>";
                print "<a href='index.php?shard=admin&amp;action=g_editForum&amp;ID=$row2[ID]'>$row2[forumName]</a><br />";
                print "<font class='fineC2'>$row2[forumDescription]</font></td></tr>";
            }
             
            print "<tr><td class='forumDisplayTableBody'><font class='fineC2'>[ <a href='index.php?shard=admin&amp;action=g_addForum&amp;parentForumID=$row[ID]'>Create New Forum</a> ]</font></td></tr>";
        }
         
        print "</table><br />[ <a href='index.php?shard=admin&amp;action=g_addForumCatagory'>Create New Forum Catagory</a> ]";
        drawMainBottom();
        break;
        case "g_addForumCatagory":
         
        // Add a new forum Catagory
        drawMainTop();
        print "<font class='headC1'><u>Create New Forum Catagory Definition:</u></font><br /><br />";
        print "<form action='index.php?shard=admin&amp;action=submitForum' method=POST>";
        print "<table width='100%'><tr><td width=200>Catagory Title:</td><td><input name=forumName size=55 class='text'></td></tr>";
        print "<tr><td valign=top>Catagory Description:</td><td><textarea class='text' name='forumDescription' rows=10 cols=60></textarea></td></tr>";
        print "<tr><td valign=top><font class='fineC2'>Click submit to enter catagory</font></td>";
        print "<td><input type=hidden name=parentForumID value=0><input type=submit class=submit value=Submit></td></tr></table></form>";
        drawMainBottom();
         
        break;
        case "g_addForum":
        // Add a new forum
        drawMainTop();
        print "<font class='headC1'><u>Create New Forum:</u></font><br /><br />";
        print "<form action='index.php?shard=admin&amp;action=submitForum' method=POST>";
        print "<table width='100%'><tr><td width=200>Forum Title:</td><td><input name=forumName size=55 class='text'></td></tr>";
        print "<tr><td valign=top>Forum Description:</td><td><textarea class='text' name='forumDescription' rows=10 cols=60></textarea></td></tr>";
        print "<tr><td valign=top><font class='fineC2'>Click submit to enter catagory</font></td>";
        print "<input type=hidden name=parentForumID value=$_REQUEST[parentForumID]>";
        print "<td><input type=submit class=submit value=Submit></td></tr></table></form>";
        drawMainBottom();
        break;
        case "g_editForum":
         
        $f = mysql_query("select * from forumList where ID=$_REQUEST[ID]") or die(mysql_error());
        $row = mysql_fetch_array($f);
         
        // Edit a forum / catagory
        drawMainTop();
        print "<font class='headC1'><u>Edit Forum:</u></font><br /><br />";
        print "<form action='index.php?shard=admin&amp;action=submitForum' method=POST>";
        print "<table width='100%'><tr><td width=200>Forum Title:</td><td><input name=forumName size=55 class='text'></td></tr>";
        print "<tr><td valign=top>Forum Description:</td><td><textarea class='text' name='forumDescription' rows=10 cols=60></textarea></td></tr>";
        print "<tr><td valign=top><font class='fineC2'>Click submit to enter catagory</font></td>";
        print "<input type=hidden name=parentForumID value=$_REQUEST[parentForumID]>";
        print "<td><input type=submit class=submit value=Submit></td></tr></table></form>";
        drawMainBottom();
        break;
        case "submitForum":
        $result = mysql_query("insert into forumList (forumName, parentForumID, forumDescription)
            values
            ('$_REQUEST[forumName]', $_REQUEST[parentForumID], '$_REQUEST[forumDescription]')") or die(mysql_error());
        header("Location: index.php?shard=admin&action=g_manageForum");
        break;
        endswitch;
    }
   
     
?>
