Exemplo n.º 1
0
/**
 * Updates an existing ban group
 *
 * - If the name doesn't exists a new one is created
 *
 * @package Bans
 * @param mixed[] $ban_info
 * @return nothing
 */
function updateBanGroup($ban_info = array())
{
    $db = database();
    // Lets check for errors first
    $ban_errors = Error_Context::context('ban', 1);
    if (empty($ban_info['name'])) {
        $ban_errors->addError('ban_name_empty');
    }
    if (empty($ban_info['id'])) {
        $ban_errors->addError('ban_id_empty');
    }
    if ($ban_errors->hasErrors()) {
        return false;
    }
    // No problems found, so lets add this to the ban list
    $request = $db->query('', '
		SELECT id_ban_group
		FROM {db_prefix}ban_groups
		WHERE name = {string:new_ban_name}
			AND id_ban_group = {int:ban_group}
		LIMIT 1', array('ban_group' => $ban_info['id'], 'new_ban_name' => $ban_info['name']));
    if ($db->num_rows($request) == 0) {
        return insertBanGroup($ban_info);
    }
    $db->free_result($request);
    $db->query('', '
		UPDATE {db_prefix}ban_groups
		SET
			name = {string:ban_name},
			reason = {string:reason},
			notes = {string:notes},
			expire_time = {raw:expiration},
			cannot_access = {int:cannot_access},
			cannot_post = {int:cannot_post},
			cannot_register = {int:cannot_register},
			cannot_login = {int:cannot_login}
		WHERE id_ban_group = {int:id_ban_group}', array('expiration' => $ban_info['db_expiration'], 'cannot_access' => $ban_info['cannot']['access'], 'cannot_post' => $ban_info['cannot']['post'], 'cannot_register' => $ban_info['cannot']['register'], 'cannot_login' => $ban_info['cannot']['login'], 'id_ban_group' => $ban_info['id'], 'ban_name' => $ban_info['name'], 'reason' => $ban_info['reason'], 'notes' => $ban_info['notes']));
    return $ban_info['id'];
}
Exemplo n.º 2
0
 /**
  * This function handles submitted forms that add, modify or remove ban triggers.
  */
 public function action_edit2()
 {
     global $context;
     require_once SUBSDIR . '/Bans.subs.php';
     // Check with security first
     checkSession();
     validateToken('admin-bet');
     $ban_errors = Error_Context::context('ban', 1);
     // Adding or editing a ban group
     if (isset($_POST['add_ban']) || isset($_POST['modify_ban'])) {
         $ban_info = array();
         // Let's collect all the information we need
         $ban_info['id'] = isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0;
         $ban_info['is_new'] = empty($ban_info['id']);
         $ban_info['expire_date'] = !empty($_POST['expire_date']) ? (int) $_POST['expire_date'] : 0;
         $ban_info['expiration'] = array('status' => isset($_POST['expiration']) && in_array($_POST['expiration'], array('never', 'one_day', 'expired')) ? $_POST['expiration'] : 'never', 'days' => $ban_info['expire_date']);
         $ban_info['db_expiration'] = $ban_info['expiration']['status'] == 'never' ? 'NULL' : ($ban_info['expiration']['status'] == 'one_day' ? time() + 24 * 60 * 60 * $ban_info['expire_date'] : 0);
         $ban_info['full_ban'] = empty($_POST['full_ban']) ? 0 : 1;
         $ban_info['reason'] = !empty($_POST['reason']) ? Util::htmlspecialchars($_POST['reason'], ENT_QUOTES) : '';
         $ban_info['name'] = !empty($_POST['ban_name']) ? Util::htmlspecialchars($_POST['ban_name'], ENT_QUOTES) : '';
         $ban_info['notes'] = isset($_POST['notes']) ? Util::htmlspecialchars($_POST['notes'], ENT_QUOTES) : '';
         $ban_info['notes'] = str_replace(array("\r", "\n", '  '), array('', '<br />', '&nbsp; '), $ban_info['notes']);
         $ban_info['cannot']['access'] = empty($ban_info['full_ban']) ? 0 : 1;
         $ban_info['cannot']['post'] = !empty($ban_info['full_ban']) || empty($_POST['cannot_post']) ? 0 : 1;
         $ban_info['cannot']['register'] = !empty($ban_info['full_ban']) || empty($_POST['cannot_register']) ? 0 : 1;
         $ban_info['cannot']['login'] = !empty($ban_info['full_ban']) || empty($_POST['cannot_login']) ? 0 : 1;
         // Adding a new ban group
         if (empty($ban_info['id'])) {
             $ban_group_id = insertBanGroup($ban_info);
         } else {
             $ban_group_id = updateBanGroup($ban_info);
         }
         if ($ban_group_id !== false) {
             $ban_info['id'] = $ban_group_id;
             $ban_info['is_new'] = false;
         }
         $context['ban'] = $ban_info;
     }
     // Update the triggers associated with this ban
     if (isset($_POST['ban_suggestions'])) {
         $saved_triggers = saveTriggers($_POST['ban_suggestions'], $ban_info['id'], isset($_REQUEST['u']) ? (int) $_REQUEST['u'] : 0, isset($_REQUEST['bi']) ? (int) $_REQUEST['bi'] : 0);
         $context['ban_suggestions']['saved_triggers'] = $saved_triggers;
     }
     // Something went wrong somewhere, ban info or triggers, ... Oh well, let's go back.
     if ($ban_errors->hasErrors()) {
         $context['ban_suggestions'] = $saved_triggers;
         $context['ban']['from_user'] = true;
         // They may have entered a name not using the member select box
         if (isset($_REQUEST['u'])) {
             $context['ban_suggestions'] = array_merge($context['ban_suggestions'], getMemberData((int) $_REQUEST['u']));
         } elseif (isset($_REQUEST['user'])) {
             $context['ban']['from_user'] = false;
             $context['use_autosuggest'] = true;
             $context['ban_suggestions']['member']['name'] = $_REQUEST['user'];
         }
         // Not strictly necessary, but it's nice
         if (!empty($context['ban_suggestions']['member']['id'])) {
             $context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']);
         }
         return $this->action_edit();
     }
     if (isset($_POST['ban_items'])) {
         $ban_group_id = isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0;
         $ban_items = array_map('intval', $_POST['ban_items']);
         removeBanTriggers($ban_items, $ban_group_id);
     }
     // Register the last modified date.
     updateSettings(array('banLastUpdated' => time()));
     // Update the member table to represent the new ban situation.
     updateBanMembers();
     // Go back to an appropriate spot
     redirectexit('action=admin;area=ban;sa=' . (isset($_POST['add_ban']) ? 'list' : 'edit;bg=' . $ban_group_id));
 }