<?php
$admin = 2;
$file = __FILE__;
include ("../inc/inc_common.php");
include ("../inc/inc_connect.php");
include ("../inc/inc_admincheck.php");
include ("../inc/inc_getdate.php");
include ("../inc/inc_forumname.php");
$page = "Admin - Configure Moderators";
$pagelink = $file;
include("../inc/inc_setonline.php");
$title = "$name1 Admin - $gfcookie[1] - Configure Moderators";
include ("../inc/inc_head.php");
include ("../inc/inc_body.php");
$title = "Configure Moderators";
include ("../inc/inc_title.php");

if ($action == "remove")
{
    $forums = "0";
    $result=mysql_query("SELECT * FROM $userstable WHERE strName = '$name'");
    $num_rows = mysql_num_rows( $result );
    while ( $a_row = mysql_fetch_object( $result ) )
    {
        $fmod = explode(",", $a_row->strForumsModerated);
        $count = 0;
        while ($count < 100)
        {
            if ($fmod[$count] != "$id" AND $fmod[$count] != "0" )
            {
                $forums = $forums.",".$fmod[$count];
            }
            if ($fmod[$count] == "")
            {
                break;
            }
            $count ++;
        }

        $query = "UPDATE $userstable SET strForumsModerated = '$forums' WHERE strName = '$name'";
        mysql_query( $query, $link ) or die ( "Error! : ".mysql_error() );
    }
}

print "<br><br><table border=1 cellpadding=3 cellspacing=0 style=\"border-collapse: collapse\" bordercolor=\"$bordercolor\" width=60% style=\"font-family: $font; font-size: $fontpoint\" bgcolor=\"$fgcolour\"><tr><td width=\"100%\" align=\"center\"><br><b>Choose the forum on which you wish to add / remove moderators</b><br><br>
<table border=0 cellpadding=3 cellspacing=0 width=\"50%\" style=\"font-family: $font; font-size: $fontpoint\">";

$result=mysql_query("SELECT * FROM $grouptable WHERE ynGroupMaster != '2' ORDER BY intGroupId, ynGroupMaster DESC"); //I know that's not the right order - but it is much simpler to do things this way...
$num_rows = mysql_num_rows( $result );
while ( $a_row = mysql_fetch_object( $result ) )
{
    print "<tr><td>";

    if ($a_row->ynGroupMaster == 1)
    {
        print "<br><b>$a_row->strName</td><td>&nbsp;</td></tr>";
        continue;
    }

    print "<a href=\"admin_moderatorsadd.php?id=$a_row->intId\">$a_row->strName</a></td><td>&nbsp;Moderated by: ";

    $resultb=mysql_query("SELECT * FROM $userstable WHERE strForumsModerated != '' ORDER BY strName");
    $num_rowsb = mysql_num_rows( $resultb );
    while ( $b_row = mysql_fetch_object( $resultb ) )
    {
        $fmod = explode(",", $b_row->strForumsModerated);
        $count = 0;
        while ($count < 100) // if you have more that 100 sub-forum, change the number accordingly :oP
        {
            if ($a_row->intId == $fmod[$count])
            {
                $counter ++;
                print "<a href=\"admin_moderators.php?action=remove&name=$b_row->strName&id=$a_row->intId\">$b_row->strName</a>&nbsp;";
                break;
            }

            if ($fmod[$count] == "")
            {
                break;
            }
            $count ++;
        }
    }
    if ($counter == 0)
    {
        print "Nobody";
    }
    $counter = 0;
    print "</td></tr>";
}
print "<table><br>Click on a forum name to add moderators to that forum.<br>
Click on a moderators name to <i>remove</i> their moderator status for a forum.<br><br></td></tr></table>";

include ("../inc/inc_footer.php");