Added ability to remove topic templates (#862)

This commit is contained in:
Roman Kelesidis 2023-08-23 01:37:34 +07:00 committed by GitHub
commit 3da70d5c5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View file

@ -26,6 +26,7 @@ $sql_error = false;
switch ($mode) {
case 'load':
case 'save':
case 'remove':
if (!$tpl_id = (int)$this->request['tpl_id']) {
$this->ajax_die('Выбранный шаблон не найден, создайте новый (empty tpl_id)');
}
@ -144,6 +145,22 @@ switch ($mode) {
}
break;
// удаление шаблона
case 'remove':
if (!$forum_id = (int)$this->request['forum_id']) {
$this->ajax_die('empty forum_id');
}
if (!forum_exists($forum_id)) {
$this->ajax_die("нет такого форума [id: $forum_id]");
}
$sql = "DELETE FROM " . BB_TOPIC_TPL . " WHERE tpl_id = $tpl_id LIMIT 1";
if (!@DB()->query($sql)) {
$sql_error = DB()->sql_error();
}
DB()->query("UPDATE " . BB_FORUMS . " SET forum_tpl_id = 0 WHERE forum_id = $forum_id LIMIT 1");
$this->response['msg'] = "Шаблон {$tpl_data['tpl_name']} успешно удалён";
break;
// ошибочный $mode
default:
$this->ajax_die("invalid mode: $mode");

View file

@ -4407,10 +4407,12 @@ ajax.topic_tpl = function(mode, params) {
$('#tpl-new-block').toggle();
break;
case 'remove':
case 'load':
ajax.exec({
action : 'topic_tpl',
mode : 'load',
mode : mode,
forum_id : {FORUM_ID},
tpl_id : $('#forum_tpl_select').val()
});
break;
@ -4480,6 +4482,7 @@ ajax.callback.topic_tpl = function(data) {
$('#tpl-rules-link').attr({href: data.tpl_rules_href});
break;
case 'remove':
case 'assign':
alert(data.msg);
window.location.reload();
@ -4496,7 +4499,8 @@ ajax.callback.topic_tpl = function(data) {
break;
case 'new':
$('#tpl-new-resp').html('новый шаблон создан (в списке выбора он появится после перезагрузки страницы)');
$('#tpl-new-resp').html('новый шаблон создан');
window.location.reload();
break;
}
};
@ -4717,6 +4721,7 @@ $(function(){
<!-- IF TPL_SELECT -->{TPL_SELECT} &nbsp;
<input type="button" value="Включить в этом форуме" class="bold" onclick="ajax.topic_tpl('assign', {tpl_id: $('#forum_tpl_select').val()})" /> &nbsp;
<input type="button" value="Загрузить" onclick="ajax.topic_tpl('load')" /> &nbsp;
<input type="button" value="{L_REMOVE}" onclick="ajax.topic_tpl('remove')" /> &nbsp;
<!-- ELSE -->Нет щаблонов для релизов<!-- ENDIF -->
<br /><br />
<span class="gen">