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) { switch ($mode) {
case 'load': case 'load':
case 'save': case 'save':
case 'remove':
if (!$tpl_id = (int)$this->request['tpl_id']) { if (!$tpl_id = (int)$this->request['tpl_id']) {
$this->ajax_die('Выбранный шаблон не найден, создайте новый (empty tpl_id)'); $this->ajax_die('Выбранный шаблон не найден, создайте новый (empty tpl_id)');
} }
@ -144,6 +145,22 @@ switch ($mode) {
} }
break; 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 // ошибочный $mode
default: default:
$this->ajax_die("invalid mode: $mode"); $this->ajax_die("invalid mode: $mode");

View file

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