/** * 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; }
} require_once DIR_FS_INCLUDES . "messages.php"; require_once DIR_FS_INCLUDES . "tables.php"; $db = new Database_Mysqli(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME); require_once DIR_FS_FUNCTIONS . "session.php"; require_once DIR_FS_FUNCTIONS . "general.php"; require_once DIR_FS_FUNCTIONS . "view.php"; //Session Start buckys_session_start(); //Init Global Values buckys_enqueue_javascript('jquery-1.9.0.js', false, false); buckys_enqueue_javascript('site.js'); buckys_enqueue_stylesheet('main.css'); $BUCKYS_GLOBALS['template'] = DEFAULT_THEME; $BUCKYS_GLOBALS['layout'] = 'layout'; $BUCKYS_GLOBALS['headerType'] = 'default'; //Define User Acl Constants BuckysUserAcl::defineAclConstants(); //Set User Data into Global Variable if (!($userID = buckys_is_logged_in())) { $BUCKYS_GLOBALS['user'] = array('userID' => 0, 'user_type' => 'Public', 'aclLevel' => 0, 'aclName' => 'Public'); } else { $BUCKYS_GLOBALS['user'] = BuckysUser::getUserBasicInfo($userID); } if (buckys_is_logged_in()) { buckys_enqueue_stylesheet('footer.css'); buckys_enqueue_stylesheet('jquery-ui/jquery-ui.css'); buckys_enqueue_javascript('jquery-ui.min.js'); buckys_enqueue_javascript('jquery.contextMenu.js'); buckys_enqueue_javascript('private_messenger.js'); }
/** * Get name from level * * @param $level * @return * @internal param Int $acl */ public function getNameFromLevel($level) { global $db; if (BuckysUserAcl::$USER_ACL == null) { BuckysUserAcl::loadAcl(); } foreach (BuckysUserAcl::$USER_ACL as $row) { if ($row['Level'] == $level) { return $row['Name']; } } }
/** * 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; }