diff --git a/phpBB/includes/acp/acp_ban.php b/phpBB/includes/acp/acp_ban.php
index 22ae9d4e7b..9335e40ff9 100644
--- a/phpBB/includes/acp/acp_ban.php
+++ b/phpBB/includes/acp/acp_ban.php
@@ -25,9 +25,12 @@ class acp_ban
function main($id, $mode)
{
- global $user, $template, $request, $phpbb_dispatcher;
+ global $user, $template, $request, $phpbb_dispatcher, $phpbb_container;
global $phpbb_root_path, $phpEx;
+ /** @var \phpbb\ban\manager $ban_manager */
+ $ban_manager = $phpbb_container->get('ban.manager');
+
if (!function_exists('user_ban'))
{
include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
diff --git a/phpBB/includes/acp/acp_email.php b/phpBB/includes/acp/acp_email.php
index 3fba4917ec..cddf7b3324 100644
--- a/phpBB/includes/acp/acp_email.php
+++ b/phpBB/includes/acp/acp_email.php
@@ -26,7 +26,7 @@ class acp_email
function main($id, $mode)
{
global $config, $db, $user, $template, $phpbb_log, $request;
- global $phpbb_root_path, $phpbb_admin_path, $phpEx, $phpbb_dispatcher;
+ global $phpbb_root_path, $phpbb_admin_path, $phpEx, $phpbb_dispatcher, $phpbb_container;
$user->add_lang('acp/email');
$this->tpl_name = 'acp_email';
@@ -74,7 +74,7 @@ class acp_email
{
// If giving usernames the admin is able to email inactive users too...
$sql_ary = array(
- 'SELECT' => 'username, user_email, user_jabber, user_notify_type, user_lang',
+ 'SELECT' => 'user_id, username, user_email, user_jabber, user_notify_type, user_lang',
'FROM' => array(
USERS_TABLE => '',
),
@@ -88,7 +88,7 @@ class acp_email
if ($group_id)
{
$sql_ary = array(
- 'SELECT' => 'u.user_email, u.username, u.username_clean, u.user_lang, u.user_jabber, u.user_notify_type',
+ 'SELECT' => 'u.user_id, u.user_email, u.username, u.username_clean, u.user_lang, u.user_jabber, u.user_notify_type',
'FROM' => array(
USERS_TABLE => 'u',
USER_GROUP_TABLE => 'ug',
@@ -104,7 +104,7 @@ class acp_email
else
{
$sql_ary = array(
- 'SELECT' => 'u.username, u.username_clean, u.user_email, u.user_jabber, u.user_lang, u.user_notify_type',
+ 'SELECT' => 'u.user_id, u.username, u.username_clean, u.user_email, u.user_jabber, u.user_lang, u.user_notify_type',
'FROM' => array(
USERS_TABLE => 'u',
),
@@ -113,21 +113,6 @@ class acp_email
'ORDER_BY' => 'u.user_lang, u.user_notify_type',
);
}
-
- // Mail banned or not
- if (!isset($_REQUEST['mail_banned_flag']))
- {
- $sql_ary['WHERE'] .= ' AND (b.ban_id IS NULL
- OR b.ban_exclude = 1)';
- $sql_ary['LEFT_JOIN'] = array(
- array(
- 'FROM' => array(
- BANLIST_TABLE => 'b',
- ),
- 'ON' => 'u.user_id = b.ban_userid',
- ),
- );
- }
}
/**
* Modify sql query to change the list of users the email is sent to
@@ -141,11 +126,22 @@ class acp_email
$sql = $db->sql_build_query('SELECT', $sql_ary);
$result = $db->sql_query($sql);
- $row = $db->sql_fetchrow($result);
+ $rows = $db->sql_fetchrowset($result);
+ $db->sql_freeresult($result);
- if (!$row)
+ if (!empty($rows) && !$request->is_set('mail_banned_flag'))
+ {
+ /** @var \phpbb\ban\manager $ban_manager */
+ $ban_manager = $phpbb_container->get('ban.manager');
+ $banned_users = $ban_manager->get_banned_users();
+
+ $rows = array_filter($rows, function ($row) use ($banned_users) {
+ return !isset($banned_users[(int) $row['user_id']]);
+ });
+ }
+
+ if (empty($rows))
{
- $db->sql_freeresult($result);
trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING);
}
@@ -155,10 +151,10 @@ class acp_email
// Maximum number of bcc recipients
$max_chunk_size = (int) $config['email_max_chunk_size'];
$email_list = array();
- $old_lang = $row['user_lang'];
- $old_notify_type = $row['user_notify_type'];
+ $old_lang = $rows[0]['user_lang'];
+ $old_notify_type = $rows[0]['user_notify_type'];
- do
+ foreach ($rows as $row)
{
if (($row['user_notify_type'] == NOTIFY_EMAIL && $row['user_email']) ||
($row['user_notify_type'] == NOTIFY_IM && $row['user_jabber']) ||
@@ -185,8 +181,6 @@ class acp_email
$i++;
}
}
- while ($row = $db->sql_fetchrow($result));
- $db->sql_freeresult($result);
// Send the messages
if (!class_exists('messenger'))
diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php
index a56a583307..f560dbfbcb 100644
--- a/phpBB/includes/constants.php
+++ b/phpBB/includes/constants.php
@@ -239,7 +239,7 @@ define('ACL_ROLES_TABLE', $table_prefix . 'acl_roles');
define('ACL_USERS_TABLE', $table_prefix . 'acl_users');
define('ATTACHMENTS_TABLE', $table_prefix . 'attachments');
define('BACKUPS_TABLE', $table_prefix . 'backups');
-define('BANLIST_TABLE', $table_prefix . 'banlist');
+define('BANS_TABLE', $table_prefix . 'bans');
define('BBCODES_TABLE', $table_prefix . 'bbcodes');
define('BOOKMARKS_TABLE', $table_prefix . 'bookmarks');
define('BOTS_TABLE', $table_prefix . 'bots');
diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php
index 11a672a2ed..04eb7d8df6 100644
--- a/phpBB/includes/functions_admin.php
+++ b/phpBB/includes/functions_admin.php
@@ -3156,63 +3156,18 @@ function display_ban_end_options()
*/
function display_ban_options($mode)
{
- global $user, $db, $template;
+ global $user, $template, $phpbb_container;
- switch ($mode)
+ /** @var \phpbb\ban\manager $ban_manager */
+ $ban_manager = $phpbb_container->get('ban.manager');
+ $ban_rows = $ban_manager->get_bans($mode);
+
+ $banned_options = array();
+ foreach ($ban_rows as $row)
{
- case 'user':
+ $banned_options[] = '';
- $field = 'username';
-
- $sql = 'SELECT b.*, u.user_id, u.username, u.username_clean
- FROM ' . BANLIST_TABLE . ' b, ' . USERS_TABLE . ' u
- WHERE (b.ban_end >= ' . time() . '
- OR b.ban_end = 0)
- AND u.user_id = b.ban_userid
- ORDER BY u.username_clean ASC';
- break;
-
- case 'ip':
-
- $field = 'ban_ip';
-
- $sql = 'SELECT *
- FROM ' . BANLIST_TABLE . '
- WHERE (ban_end >= ' . time() . "
- OR ban_end = 0)
- AND ban_ip <> ''
- ORDER BY ban_ip";
- break;
-
- case 'email':
-
- $field = 'ban_email';
-
- $sql = 'SELECT *
- FROM ' . BANLIST_TABLE . '
- WHERE (ban_end >= ' . time() . "
- OR ban_end = 0)
- AND ban_email <> ''
- ORDER BY ban_email";
- break;
- }
- $result = $db->sql_query($sql);
-
- $banned_options = $excluded_options = array();
- while ($row = $db->sql_fetchrow($result))
- {
- $option = '';
-
- if ($row['ban_exclude'])
- {
- $excluded_options[] = $option;
- }
- else
- {
- $banned_options[] = $option;
- }
-
- $time_length = ($row['ban_end']) ? ($row['ban_end'] - $row['ban_start']) / 60 : 0;
+ $time_length = ($ban_row['ban_end']) ? ($ban_row['ban_end'] - $ban_row['ban_start']) / 60 : 0;
if ($time_length == 0)
{
@@ -3222,34 +3177,26 @@ function display_ban_options($mode)
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($row['ban_end'], false, true));
+ $ban_length = $user->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($row['ban_end'], false, true));
+ $ban_length = $user->lang('BANNED_UNTIL_DATE', $user->format_date($ban_row['ban_end'], false, true));
}
$template->assign_block_vars('bans', array(
- 'BAN_ID' => (int) $row['ban_id'],
+ 'BAN_ID' => (int) $ban_row['ban_id'],
'LENGTH' => $ban_length,
'A_LENGTH' => addslashes($ban_length),
- 'REASON' => $row['ban_reason'],
- 'A_REASON' => addslashes($row['ban_reason']),
- 'GIVE_REASON' => $row['ban_give_reason'],
- 'A_GIVE_REASON' => addslashes($row['ban_give_reason']),
+ 'REASON' => $ban_row['ban_reason'],
+ 'A_REASON' => addslashes($ban_row['ban_reason']),
+ 'GIVE_REASON' => $ban_row['ban_reason_display'],
+ 'A_GIVE_REASON' => addslashes($ban_row['ban_reason_display']),
));
}
- $db->sql_freeresult($result);
$options = '';
- if ($excluded_options)
- {
- $options .= '';
- }
-
if ($banned_options)
{
$options .= '