diff --git a/phpBB/adm/style/acp_ban.html b/phpBB/adm/style/acp_ban.html index 35e2028618..147eae106b 100644 --- a/phpBB/adm/style/acp_ban.html +++ b/phpBB/adm/style/acp_ban.html @@ -11,11 +11,11 @@ @@ -85,44 +98,41 @@
{L_UNBAN_EXPLAIN}
- diff --git a/phpBB/adm/style/admin.css b/phpBB/adm/style/admin.css index 6924f6d890..f6598331eb 100644 --- a/phpBB/adm/style/admin.css +++ b/phpBB/adm/style/admin.css @@ -288,6 +288,10 @@ li { padding-right: 10px; } +.w-50 { + width: 50%; +} + @media only screen and (max-width: 700px), only screen and (max-device-width: 700px) { #wrap, #page-body, diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 8e784ef576..48bb7be21c 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -3156,33 +3156,37 @@ function display_ban_end_options() */ function display_ban_options($mode) { - global $user, $template, $phpbb_container; + global $language, $user, $template, $phpbb_container; /** @var \phpbb\ban\manager $ban_manager */ $ban_manager = $phpbb_container->get('ban.manager'); $ban_rows = $ban_manager->get_bans($mode); - $banned_options = array(); + $banned_options = []; + foreach ($ban_rows as $ban_row) { - $banned_options[] = ''; + $banned_options[] = [ + 'value' => $ban_row['ban_id'], + 'label' => $ban_row['ban_item'], + ]; $time_length = ($ban_row['ban_end']) ? ($ban_row['ban_end'] - $ban_row['ban_start']) / 60 : 0; if ($time_length == 0) { // Banned permanently - $ban_length = $user->lang['PERMANENT']; + $ban_length = $language->lang('PERMANENT'); } else if (isset($ban_end_text[$time_length])) { // Banned for a given duration - $ban_length = $user->lang('BANNED_UNTIL_DURATION', $ban_end_text[$time_length], $user->format_date($ban_row['ban_end'], false, true)); + $ban_length = $language->lang('BANNED_UNTIL_DURATION', $ban_end_text[$time_length], $user->format_date($ban_row['ban_end'], false, true)); } else { // Banned until given date - $ban_length = $user->lang('BANNED_UNTIL_DATE', $user->format_date($ban_row['ban_end'], false, true)); + $ban_length = $language->lang('BANNED_UNTIL_DATE', $user->format_date($ban_row['ban_end'], false, true)); } $template->assign_block_vars('bans', array( @@ -3196,16 +3200,24 @@ function display_ban_options($mode) )); } - $options = ''; - if ($banned_options) + if (count($banned_options)) { - $options .= ''; - } + $banned_select = [ + 'tag' => 'select', + 'name' => 'unban[]', + 'id' => 'unban', + 'class' => 'w-50', + 'multiple' => true, + 'size' => 10, + 'data' => [ + 'onchange' => 'display_details', + ], + 'options' => [[ + 'label' => $language->lang('OPTIONS_BANNED'), + 'options' => $banned_options, + ]], + ]; - $template->assign_vars(array( - 'S_BANNED_OPTIONS' => (bool) $banned_options, - 'BANNED_OPTIONS' => $options, - )); + $template->assign_vars(['BANNED_SELECT' => $banned_select]); + } } diff --git a/phpBB/phpbb/ban/manager.php b/phpBB/phpbb/ban/manager.php index 8ce469b5fb..52cae3670a 100644 --- a/phpBB/phpbb/ban/manager.php +++ b/phpBB/phpbb/ban/manager.php @@ -263,23 +263,15 @@ class manager */ public function get_bans(string $mode) { - /** @var type_interface $ban_mode */ - $ban_mode = $this->find_type($mode); - if ($ban_mode === false) + /** @var type_interface $ban_type */ + $ban_type = $this->find_type($mode); + if ($ban_type === false) { - throw new type_not_found_exception(); // TODO + throw new type_not_found_exception(); } $this->tidy(); - $sql = 'SELECT ban_id, ban_item, ban_start, ban_end, ban_reason, ban_reason_display - FROM ' . $this->bans_table . " - WHERE ban_mode = '" . $this->db->sql_escape($mode) . "' - AND (ban_end = 0 OR ban_end >= " . time() . ')'; - $result = $this->db->sql_query($sql); - $rowset = $this->db->sql_fetchrowset($result); - $this->db->sql_freeresult($result); - - return $rowset; + return $ban_type->get_ban_options(); } /** diff --git a/phpBB/phpbb/ban/type/base.php b/phpBB/phpbb/ban/type/base.php index f404e1bdeb..d82be47af7 100644 --- a/phpBB/phpbb/ban/type/base.php +++ b/phpBB/phpbb/ban/type/base.php @@ -100,6 +100,25 @@ abstract class base implements type_interface return []; } + /** + * {@inheritDoc} + */ + public function get_ban_options(): array + { + // @todo replace table constant by string + $sql = 'SELECT * + FROM ' . BANS_TABLE . ' + WHERE (ban_end >= ' . time() . " + OR ban_end = 0) + AND ban_mode = '{$this->get_type()}' + ORDER BY ban_item"; + $result = $this->db->sql_query($sql); + $rowset = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); + + return $rowset; + } + /** * Queries users that are excluded from banning (like founders) * from the database and saves them in $this->excluded array. diff --git a/phpBB/phpbb/ban/type/type_interface.php b/phpBB/phpbb/ban/type/type_interface.php index b807b3e018..0c16a24319 100644 --- a/phpBB/phpbb/ban/type/type_interface.php +++ b/phpBB/phpbb/ban/type/type_interface.php @@ -100,6 +100,13 @@ interface type_interface */ public function get_banned_users(): array; + /** + * Get ban options mapping ban ID to an option to display to admins + * + * @return array + */ + public function get_ban_options(): array; + /** * Prepares the given ban items before saving them in the database * diff --git a/phpBB/phpbb/ban/type/user.php b/phpBB/phpbb/ban/type/user.php index 1b8592e354..cb5de0f8dd 100644 --- a/phpBB/phpbb/ban/type/user.php +++ b/phpBB/phpbb/ban/type/user.php @@ -68,6 +68,32 @@ class user extends base return $unbanned_users; } + /** + * {@inheritDoc} + */ + public function get_ban_options(): array + { + $ban_options = []; + + // @todo replace table constant by string + $sql = 'SELECT b.*, u.user_id, u.username, u.username_clean + FROM ' . BANS_TABLE . ' b, ' . $this->users_table . ' u + WHERE (b.ban_end >= ' . time() . " + OR b.ban_end = 0) + AND b.ban_mode = '{$this->get_type()}' + AND u.user_id = b.ban_item + ORDER BY u.username_clean ASC"; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $row['ban_item'] = $row['username']; + $ban_options[] = $row; + } + $this->db->sql_freeresult($result); + + return $ban_options; + } + /** * {@inheritDoc} */