[ticket/9687] Use Forms for template display and fix display for users

PHPBB3-9687
This commit is contained in:
Marc Alexander 2023-07-29 23:09:42 +02:00
parent 6048458a12
commit 1a4e6fe3e8
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
7 changed files with 122 additions and 52 deletions

View file

@ -11,11 +11,11 @@
<script>
// <![CDATA[
var ban_length = new Array();
ban_length[-1] = '';
var ban_reason = new Array();
const ban_length = [];
ban_length[-1] = '';
const ban_reason = [];
ban_reason[-1] = '';
var ban_give_reason = new Array();
const ban_give_reason = [];
ban_give_reason[-1] = '';
<!-- BEGIN bans -->
@ -43,6 +43,19 @@
}
}
document.addEventListener("DOMContentLoaded", () => {
const $unbanSelect = document.getElementById('unban');
if ($unbanSelect) {
$unbanSelect.addEventListener('change', function () {
if (this.selectedIndex > -1) {
display_details(this.options[this.selectedIndex].value);
} else {
display_details(-1);
}
});
}
});
// ]]>
</script>
@ -85,44 +98,41 @@
<p>{L_UNBAN_EXPLAIN}</p>
<form id="acp_unban" method="post" action="{U_ACTION}">
<form id="acp_unban" method="post" action="{{ U_ACTION }}">
<fieldset>
<legend>{L_UNBAN_TITLE}</legend>
<legend>{{ lang('UNBAN_TITLE') }}</legend>
<!-- IF S_BANNED_OPTIONS -->
{% if BANNED_SELECT %}
<dl>
<dt><label for="unban">{L_BAN_CELL}{L_COLON}</label></dt>
<dd><select id="unban" name="unban[]" multiple="multiple" size="10" style="width: 50%" onchange="if (this.selectedIndex > -1) display_details(this.options[this.selectedIndex].value); else display_details(-1);">{BANNED_OPTIONS}</select></dd>
<dt><label for="unban">{{ lang('BAN_CELL') ~ lang('COLON') }}</label></dt>
<dd>
{{ FormsSelect(BANNED_SELECT) }}
</dd>
</dl>
<dl>
<dt><label for="unbanlength">{L_BAN_LENGTH}{L_COLON}</label></dt>
<dt><label for="unbanlength">{{ lang('BAN_LENGTH') ~ lang('COLON') }}</label></dt>
<dd><input style="border: 0;" type="text" class="text full" readonly="readonly" name="unbanlength" id="unbanlength" /></dd>
</dl>
<dl>
<dt><label for="unbanreason">{L_BAN_REASON}{L_COLON}</label></dt>
<dt><label for="unbanreason">{{ lang('BAN_REASON') ~ lang('COLON') }}</label></dt>
<dd><textarea style="border: 0;" class="text full" readonly="readonly" name="unbanreason" id="unbanreason" rows="5" cols="80">&nbsp;</textarea></dd>
</dl>
<dl>
<dt><label for="unbangivereason">{L_BAN_GIVE_REASON}{L_COLON}</label></dt>
<dt><label for="unbangivereason">{{ lang('BAN_GIVE_REASON') ~ lang('COLON') }}</label></dt>
<dd><textarea style="border: 0;" class="text full" readonly="readonly" name="unbangivereason" id="unbangivereason" rows="5" cols="80">&nbsp;</textarea></dd>
</dl>
<p class="submit-buttons">
<input class="button1" type="submit" id="unbansubmit" name="unbansubmit" value="{L_SUBMIT}" />&nbsp;
<input class="button2" type="reset" id="unbanreset" name="unbanreset" value="{L_RESET}" />
<input class="button1" type="submit" id="unbansubmit" name="unbansubmit" value="{{ lang('SUBMIT') }}" />&nbsp;
<input class="button2" type="reset" id="unbanreset" name="unbanreset" value="{{ lang('RESET') }}" />
</p>
{S_FORM_TOKEN}
</fieldset>
<!-- ELSE -->
<p>{L_NO_BAN_CELL}</p>
{S_FORM_TOKEN}
{% else %}
<p>{{ lang('NO_BAN_CELL') }}</p>
{% endif %}
{{ S_FORM_TOKEN }}
</fieldset>
<!-- ENDIF -->
</form>
<!-- INCLUDE overall_footer.html -->

View file

@ -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,

View file

@ -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[] = '<option value="' . $ban_row['ban_id'] . '">' . $ban_row['ban_item'] . '</option>';
$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 .= '<optgroup label="' . $user->lang['OPTIONS_BANNED'] . '">';
$options .= implode('', $banned_options);
$options .= '</optgroup>';
}
$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]);
}
}

View file

@ -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();
}
/**

View file

@ -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.

View file

@ -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
*

View file

@ -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}
*/