/**
  * Delete Moderator
  *
  * @param mixed $userID
  * @return bool
  */
 public static function deleteModerator($userID)
 {
     global $db;
     //Getting Old Moderator
     $query = $db->prepare("SELECT moderatorID, userID FROM " . TABLE_MODERATOR . " WHERE userID=%d", $userID);
     $oldModerator = $db->getRow($query);
     if (!$oldModerator) {
         buckys_add_message(MSG_INVALID_REQUEST, MSG_TYPE_ERROR);
         return false;
     }
     //Remove Candidate
     $db->query("DELETE FROM " . TABLE_MODERATOR . " WHERE userID=" . $oldModerator['userID']);
     //Update User ACL
     //$db->query("UPDATE " . TABLE_USERS . " SET user_acl_id='" . USER_ACL_REGISTERED . "' WHERE userID=" . $oldModerator['userID']);
     $db->update("UPDATE " . TABLE_USERS . " SET user_type='Registered', user_acl_id='" . BuckysUserAcl::getIdFromName('Registered') . "' WHERE userID='" . $userID . "' AND user_acl_id != '" . BuckysUserAcl::getIdFromName('Administrator') . "'");
     buckys_add_message(MSG_MODERATOR_REMOVED);
     return true;
 }
 /**
  * Choose Moderator
  * 
  * @param int $candidateID
  * 
  * @return Error Message or True
  */
 public function chooseModerator($candidateID)
 {
     global $db, $BUCKYS_GLOBALS;
     //Check user acl again
     if (!buckys_check_user_acl(USER_ACL_ADMINISTRATOR)) {
         return MSG_PERMISSION_DENIED;
     }
     //Check Candidate ID
     $query = $db->prepare("SELECT candidateID, userID, candidateType FROM " . TABLE_MODERATOR_CANDIDATES . " WHERE candidateID=%d", $candidateID);
     $candidate = $db->getRow($query);
     if (!$candidate) {
         return MSG_INVALID_REQUEST;
     }
     //Getting Old Moderator
     $query = $db->prepare("SELECT moderatorID, userID FROM " . TABLE_MODERATOR . " WHERE moderatorType=%d AND moderatorStatus=1", $candidate['candidateType']);
     $oldModerator = $db->getRow($query);
     if ($oldModerator) {
         //Update the status to 0 on the Moderator Table
         $db->query("UPDATE " . TABLE_MODERATOR . " SET moderatorStatus=0 WHERE moderatorID=" . $oldModerator['moderatorID']);
         //Change the user type and acl id on the users table
         $db->update("UPDATE " . TABLE_USERS . " SET user_type='Registered', user_acl_id='" . BuckysUserAcl::getIdFromName('Registered') . "' WHERE userID='" . $oldModerator['userID'] . "' AND user_acl_id='" . BuckysUserAcl::getIdFromName('Moderator') . "'");
     }
     //Create New Moderator
     $mId = $db->insertFromArray(TABLE_MODERATOR, array('moderatorType' => $candidate['candidateType'], 'userID' => $candidate['userID'], 'moderatorStatus' => 1, 'electedDate' => date('Y-m-d H:i:s')));
     //Update user table
     $db->update("UPDATE " . TABLE_USERS . " SET user_type='Moderator', user_acl_id='" . BuckysUserAcl::getIdFromName('Moderator') . "' WHERE userID='" . $candidate['userID'] . "' AND user_acl_id != '" . BuckysUserAcl::getIdFromName('Administrator') . "'");
     //Remove Candidates
     $db->query("DELETE FROM " . TABLE_MODERATOR_CANDIDATES . " WHERE candidateType='" . $candidate['candidateType'] . "'");
     return;
 }