コード例 #1
0
ファイル: Bans.subs.php プロジェクト: KeiroD/Elkarte
/**
 * This function removes a batch of triggers based on ids
 *
 * What it does:
 * - Doesn't clean the inputs, expects valid input
 * - Removes the ban triggers by id or group
 *
 * @package Bans
 * @param int[]|int $items_ids
 * @param int|boolean $group_id
 * @return bool
 */
function removeBanTriggers($items_ids = array(), $group_id = false)
{
    $db = database();
    if ($group_id !== false) {
        $group_id = (int) $group_id;
    }
    if (empty($group_id) && empty($items_ids)) {
        return false;
    }
    if (!is_array($items_ids)) {
        $items_ids = array($items_ids);
    }
    // Log the ban removals so others know
    $log_info = banLogItems(banDetails($items_ids, $group_id));
    logTriggersUpdates($log_info, 'remove');
    // Remove the ban triggers by id's or groups
    if ($group_id !== false) {
        $db->query('', '
			DELETE FROM {db_prefix}ban_items
			WHERE id_ban IN ({array_int:ban_list})
				AND id_ban_group = {int:ban_group}', array('ban_list' => $items_ids, 'ban_group' => $group_id));
    } elseif (!empty($items_ids)) {
        $db->query('', '
			DELETE FROM {db_prefix}ban_items
			WHERE id_ban IN ({array_int:ban_list})', array('ban_list' => $items_ids));
    }
    return true;
}
コード例 #2
0
 /**
  * This function handles the ins and outs of the screen for adding new ban
  * triggers or modifying existing ones.
  *
  * - Adding new ban triggers:
  *   - is accessed by ?action=admin;area=ban;sa=edittrigger;bg=x
  *   - uses the ban_edit_trigger sub template of ManageBans.
  *
  * - Editing existing ban triggers:
  *   - is accessed by ?action=admin;area=ban;sa=edittrigger;bg=x;bi=y
  *   - uses the ban_edit_trigger sub template of ManageBans.
  *
  * @uses sub template ban_edit_trigger
  */
 public function action_edittrigger()
 {
     global $context, $scripturl;
     require_once SUBSDIR . '/Bans.subs.php';
     $ban_group = isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0;
     $ban_id = isset($_REQUEST['bi']) ? (int) $_REQUEST['bi'] : 0;
     if (empty($ban_group)) {
         fatal_lang_error('ban_not_found', false);
     }
     // Adding a new trigger
     if (isset($_POST['add_new_trigger']) && !empty($_POST['ban_suggestions'])) {
         saveTriggers($_POST['ban_suggestions'], $ban_group, 0, $ban_id);
         redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : ''));
     } elseif (isset($_POST['edit_trigger']) && !empty($_POST['ban_suggestions'])) {
         // The first replaces the old one, the others are added new
         // (simplification, otherwise it would require another query and some work...)
         saveTriggers(array_shift($_POST['ban_suggestions']), $ban_group, 0, $ban_id);
         if (!empty($_POST['ban_suggestions'])) {
             saveTriggers($_POST['ban_suggestions'], $ban_group);
         }
         redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : ''));
     } elseif (isset($_POST['edit_trigger'])) {
         removeBanTriggers($ban_id);
         redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : ''));
     }
     // No id supplied, this must be a new trigger being added
     if (empty($ban_id)) {
         $context['ban_trigger'] = array('id' => 0, 'group' => $ban_group, 'ip' => array('value' => '', 'selected' => true), 'hostname' => array('selected' => false, 'value' => ''), 'email' => array('value' => '', 'selected' => false), 'banneduser' => array('value' => '', 'selected' => false), 'is_new' => true);
     } else {
         $ban_row = banDetails($ban_id, $ban_group);
         if (empty($ban_row)) {
             fatal_lang_error('ban_not_found', false);
         }
         $row = $ban_row[$ban_id];
         // Load it up for the template
         $context['ban_trigger'] = array('id' => $row['id_ban'], 'group' => $row['id_ban_group'], 'ip' => array('value' => empty($row['ip_low1']) ? '' : range2ip(array($row['ip_low1'], $row['ip_low2'], $row['ip_low3'], $row['ip_low4'], $row['ip_low5'], $row['ip_low6'], $row['ip_low7'], $row['ip_low8']), array($row['ip_high1'], $row['ip_high2'], $row['ip_high3'], $row['ip_high4'], $row['ip_high5'], $row['ip_high6'], $row['ip_high7'], $row['ip_high8'])), 'selected' => !empty($row['ip_low1'])), 'hostname' => array('value' => str_replace('%', '*', $row['hostname']), 'selected' => !empty($row['hostname'])), 'email' => array('value' => str_replace('%', '*', $row['email_address']), 'selected' => !empty($row['email_address'])), 'banneduser' => array('value' => $row['member_name'], 'selected' => !empty($row['member_name'])), 'is_new' => false);
     }
     // The template uses the autosuggest functions
     loadJavascriptFile('suggest.js');
     // Template we will use
     $context['sub_template'] = 'ban_edit_trigger';
     $context['form_url'] = $scripturl . '?action=admin;area=ban;sa=edittrigger';
     createToken('admin-bet');
 }