From 3da70d5c5c352121ed1fcc643ae028b76358a233 Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Wed, 23 Aug 2023 01:37:34 +0700 Subject: [PATCH] Added ability to remove topic templates (#862) --- library/ajax/topic_tpl.php | 17 +++++++++++++++++ styles/templates/posting_tpl.tpl | 9 +++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/library/ajax/topic_tpl.php b/library/ajax/topic_tpl.php index 5f683781e..cbdfc535a 100644 --- a/library/ajax/topic_tpl.php +++ b/library/ajax/topic_tpl.php @@ -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"); diff --git a/styles/templates/posting_tpl.tpl b/styles/templates/posting_tpl.tpl index b12b06b9f..5aba82b0d 100644 --- a/styles/templates/posting_tpl.tpl +++ b/styles/templates/posting_tpl.tpl @@ -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(){ {TPL_SELECT}       +   Нет щаблонов для релизов