Location: PHPKode > projects > DarkCodex Forum System > darkcodex/admin/dorevokemod.php
<?php
include ("config.inc");
include ("forum.inc");

$dbh = db_connect();

$user = authenticate();
if ($user[Status] != 'Administrator') {
    not_right ("You must be logged in, and be a valid administrator to access this.");
}  

$FORM = get_input();

# --------------------
# Assign the variables
$Username = $FORM[Username];
$Username_q = db_quote($Username);


# -----------------------------------------------------
# Check to see if this User is a moderator of any board
$query = <<<END_SQL
    SELECT *
    FROM Boards
    WHERE Moderator = $Username_q
END_SQL;
$sth = mysql_query($query) or die ("Query syntax error. $query. Reason: " . mysql_error() . "");
$rows = mysql_num_rows($sth);
$Status  = '';
$newstat = '';
if ($rows > 0) {
    $Status = "Moderator";
    $newstat = db_quote("Moderator");
} else {
    $Status = "User";
    $newstat = db_quote("User");
}

# --------------------------------------------------
# Update this user's status
$Username_q = db_quote($Username);
$query = <<<END_SQL
    UPDATE Users 
    SET Status = $newstat
    WHERE Username = $Username_q     
END_SQL;
mysql_query($query, $dbh) or die ("Can't execute query: $query. Reason: " . mysql_error() . "");

# ---------------------------------------------------------------
# Send the user a message letting them know they have been demoted 
$Sender  = $user[Username];
$To      = $Username;
$Subject = "Your privileges";
$mess    = '';
if ($Status == "User"){
    $mess    = "Your Moderator privileges have been revoked.  You have been returned to user status.";
}
send_message($Sender,$To,$Subject,$mess);

# ------------------------------------
# Now inform all other Admins and mods
$Sender  = $user[Username];
$To      = "A_M_GROUP";
$Subject = "Moderator demoted";
$mess    = "$Sender has revoked Moderator privileges from $Username";
send_message($Sender,$To,$Subject,$mess);

# ------------------------
# Send them a confirmation
send_header ("Moderator privileges revoked.","<META HTTP-EQUIV=\"Refresh\" content=\"5;url=$config[cgiurl]/admin/login.php\">");
table_header("Moderator privileges revoked.");
print "Moderator privileges have been removed from $Username.  You will now be returned to the main Administration page.";

mysql_free_result($sth);
send_footer();
?>
Return current item: DarkCodex Forum System