Просмотр файла mc-2.7.0/modules/forum/controllers/forum_admin.php

Размер файла: 14.76Kb
  1. <?php
  2.  
  3. /**
  4. * MobileCMS
  5. *
  6. * Open source content management system for mobile sites
  7. *
  8. * @author MobileCMS Team <support@mobilecms.pro>
  9. * @copyright Copyright (c) 2011-2019, MobileCMS Team
  10. * @link https://mobilecms.pro Official site
  11. * @license MIT license
  12. */
  13. defined('IN_SYSTEM') or die('<b>403<br />Запрет доступа!</b>');
  14.  
  15. /**
  16. * Контроллер админки форума
  17. */
  18. class Forum_Admin_Controller extends Controller {
  19.  
  20. /**
  21. * Уровень пользовательского доступа
  22. */
  23. public $access_level = 10;
  24.  
  25. /**
  26. * Тема
  27. */
  28. public $template_theme = 'admin';
  29.  
  30. /**
  31. * Метод по умолчанию
  32. */
  33. public function action_index() {
  34. $this->action_sections();
  35. }
  36.  
  37. /**
  38. * Конфигурация модуля
  39. */
  40. public function action_config() {
  41. $_config = $this->config['forum'];
  42.  
  43. if (isset($_POST['submit'])) {
  44. main::is_demo();
  45. $_config = $_POST;
  46.  
  47. main::config($_config, 'forum', $this->db);
  48.  
  49. a_notice('Данные успешно изменены!', a_url('forum/admin/config'));
  50. }
  51.  
  52. if (!isset($_POST['submit']) || $error) {
  53. $this->tpl->assign(array(
  54. '_config' => $_config
  55. ));
  56.  
  57. $this->tpl->display('config');
  58. }
  59. }
  60.  
  61. /**
  62. * Управление разделами форума
  63. */
  64. public function action_sections() {
  65. switch ($_GET['a']) {
  66. # Создание раздела
  67. case 'create':
  68. main::is_demo();
  69. if (!empty($_POST['new_section'])) {
  70. $position = $this->db->get_one("SELECT MAX(position) FROM #__forum_sections") + 1;
  71. $this->db->query("INSERT INTO #__forum_sections SET
  72. name = '" . a_safe($_POST['new_section']) . "',
  73. position = '" . $position . "'
  74. ");
  75.  
  76. a_notice('Раздел успешно создан!', a_url('forum/admin'));
  77. } else {
  78. a_error('Укажите название раздела!');
  79. }
  80. break;
  81.  
  82. # Удаление раздела
  83. case 'delete':
  84. main::is_demo();
  85. $section = $this->db->get_row("SELECT * FROM #__forum_sections WHERE section_id = " . intval($_GET['section_id']));
  86. $this->db->query("DELETE FROM #__forum_sections WHERE section_id = " . intval($_GET['section_id']));
  87.  
  88. # Меняем позиции
  89. $this->db->query("UPDATE #__forum_sections SET position = position - 1 WHERE position > " . $section['position']);
  90.  
  91. a_notice('Раздел успешно удален!', a_url('forum/admin'));
  92. break;
  93.  
  94. # Редактирование раздела
  95. case 'edit':
  96. if (is_numeric($_GET['section_id'])) {
  97. if (!$section = $this->db->get_row("SELECT * FROM #__forum_sections WHERE section_id = '" . intval($_GET['section_id']) . "'"))
  98. a_error('Раздел не найден!');
  99. $action = 'edit';
  100. } else {
  101. $section = array();
  102. $action = 'add';
  103. }
  104.  
  105. if (isset($_POST['submit'])) {
  106. main::is_demo();
  107. if (empty($_POST['name'])) {
  108. $this->error .= 'Укажите название категории<br />';
  109. }
  110.  
  111. if (!$this->error) {
  112. if ($action == 'add') {
  113. $position = $this->db->get_one("SELECT MAX(position) FROM #__forum_sections") + 1;
  114. $this->db->query("INSERT INTO #__forum_sections SET
  115. name = '" . a_safe($_POST['name']) . "',
  116. position = '" . $position . "'
  117. ");
  118. $message = 'Раздел успешно создан!';
  119. }
  120. if ($action == 'edit') {
  121. $this->db->query("UPDATE #__forum_sections SET name = '" . a_safe($_POST['name']) . "' WHERE section_id='" . intval($_GET['section_id']) . "'");
  122. $message = 'Раздел успешно переименован!';
  123. }
  124.  
  125. a_notice($message, a_url('forum/admin'));
  126. }
  127. }
  128. if (!isset($_POST['submit']) || $this->error) {
  129. $this->tpl->assign(array(
  130. 'error' => $this->error,
  131. 'section' => $section,
  132. 'action' => $action
  133. ));
  134. $this->tpl->display('sections_edit');
  135. }
  136. break;
  137.  
  138. # Увеличение позиции
  139. case 'up':
  140. if (!$section = $this->db->get_row("SELECT * FROM #__forum_sections WHERE section_id = " . intval($_GET['section_id']))) {
  141. a_error('Раздел не найден!');
  142. }
  143.  
  144. # Меняем позиции
  145. $this->db->query("UPDATE #__forum_sections SET position = " . $section['position'] . " WHERE position = " . ($section['position'] - 1));
  146. $this->db->query("UPDATE #__forum_sections SET position = " . ($section['position'] - 1) . " WHERE section_id = " . intval($_GET['section_id']));
  147.  
  148. header("Location: " . a_url('forum/admin'));
  149. exit;
  150. break;
  151.  
  152. # Уменьшение позиции
  153. case 'down':
  154. if (!$section = $this->db->get_row("SELECT * FROM #__forum_sections WHERE section_id = " . intval($_GET['section_id'])))
  155. a_error('Раздел не найден!');
  156.  
  157. # Меняем позиции
  158. $this->db->query("UPDATE #__forum_sections SET position = " . $section['position'] . " WHERE position = " . ($section['position'] + 1));
  159. $this->db->query("UPDATE #__forum_sections SET position = " . ($section['position'] + 1) . " WHERE section_id = " . intval($_GET['section_id']));
  160.  
  161. header("Location: " . a_url('forum/admin'));
  162. exit;
  163. break;
  164.  
  165. # Список разделов
  166. default:
  167. $sql = "SELECT SQL_CALC_FOUND_ROWS f_s.*
  168. FROM #__forum_sections AS f_s";
  169.  
  170. $sql .= " ORDER BY f_s.position ASC";
  171.  
  172. $result = $this->db->query($sql);
  173.  
  174. $min_p = $this->db->get_one("SELECT MIN(position) FROM #__forum_sections");
  175. $max_p = $this->db->get_one("SELECT MAX(position) FROM #__forum_sections");
  176.  
  177. while ($section = $this->db->fetch_array($result)) {
  178. if ($section['position'] != $min_p)
  179. $section['up'] = '<a href="' . a_url('forum/admin/sections', 'a=up&amp;section_id=' . $section['section_id']) . '">up</a>';
  180. else
  181. $section['up'] = 'up';
  182.  
  183. if ($section['position'] != $max_p)
  184. $section['down'] = '<a href="' . a_url('forum/admin/sections', 'a=down&amp;section_id=' . $section['section_id']) . '">down</a>';
  185. else
  186. $section['down'] = 'down';
  187.  
  188. $sections[] = $section;
  189. }
  190.  
  191. $this->tpl->assign(array(
  192. 'sections' => $sections
  193. ));
  194.  
  195. $this->tpl->display('sections_list');
  196. break;
  197. }
  198. }
  199.  
  200. /**
  201. * Управление форумами
  202. */
  203. public function action_forums() {
  204. switch ($_GET['a']) {
  205. # Редактирование форума
  206. case 'edit':
  207. if (is_numeric($_GET['forum_id'])) {
  208. if (!$forum = $this->db->get_row("SELECT * FROM #__forum_forums WHERE forum_id = '" . intval($_GET['forum_id']) . "'"))
  209. a_error('Форум не найден!');
  210. $action = 'edit';
  211. } else {
  212. $forum = array();
  213. $action = 'add';
  214. }
  215.  
  216. if (isset($_POST['submit'])) {
  217. main::is_demo();
  218. if (empty($_POST['name'])) {
  219. $this->error .= 'Укажите название Форума<br />';
  220. }
  221. if (!$this->db->get_one("SELECT section_id FROM #__forum_sections WHERE section_id = '" . intval($_POST['section_id']) . "'")) {
  222. $this->error .= 'Раздел не найден!<br />';
  223. }
  224.  
  225. if (!$this->error) {
  226. if ($action == 'add') {
  227. $position = $this->db->get_one("SELECT MAX(position) FROM #__forum_forums WHERE section_id = '" . intval($_POST['section_id']) . "'") + 1;
  228. $this->db->query("INSERT INTO #__forum_forums SET
  229. section_id = '" . intval($_POST['section_id']) . "',
  230. name = '" . a_safe($_POST['name']) . "',
  231. position = '$position'
  232. ");
  233. $message = 'Форум успешно создан!';
  234. }
  235. if ($action == 'edit') {
  236. $this->db->query("UPDATE #__forum_forums SET
  237. section_id = '" . intval($_POST['section_id']) . "',
  238. name = '" . a_safe($_POST['name']) . "'
  239. WHERE forum_id='" . intval($_GET['forum_id']) . "'
  240. ");
  241. $message = 'Форум успешно изменён!';
  242. }
  243. a_notice($message, a_url('forum/admin/forums', 'a=list_forums&amp;section_id=' . $_POST['section_id']));
  244. }
  245. }
  246. if (!isset($_POST['submit']) || $this->error) {
  247. $sections = $this->db->get_array("SELECT * FROM #__forum_sections ORDER BY position");
  248. $this->tpl->assign(array(
  249. 'error' => $this->error,
  250. 'sections' => $sections,
  251. 'forum' => $forum,
  252. 'action' => $action
  253. ));
  254. $this->tpl->display('forums_edit');
  255. }
  256. break;
  257.  
  258. # Удаление форума
  259. case 'delete':
  260. main::is_demo();
  261. if (!$forum = $this->db->get_row("SELECT * FROM #__forum_forums WHERE forum_id = '" . intval($_GET['forum_id']) . "'")) {
  262. a_error('Форум не найден!');
  263. }
  264.  
  265. $this->db->query("DELETE FROM #__forum_forums WHERE forum_id = " . intval($_GET['forum_id']));
  266.  
  267. # Меняем позиции
  268. $this->db->query("UPDATE #__forum_forums SET position = position - 1 WHERE section_id = '" . $forum['section_id'] . "' AND position > " . $forum['position']);
  269.  
  270. a_notice('Форум успешно удален!', a_url('forum/admin/forums', 'a=list_forums&amp;section_id=' . $forum['section_id']));
  271. break;
  272.  
  273. # Увеличение позиции
  274. case 'up':
  275. if (!$forum = $this->db->get_row("SELECT * FROM #__forum_forums WHERE forum_id = " . intval($_GET['forum_id'])))
  276. a_error('Форум не найден!');
  277.  
  278. # Меняем позиции
  279. $this->db->query("UPDATE #__forum_forums SET position = " . $forum['position'] . " WHERE section_id = '" . $forum['section_id'] . "' AND position = " . ($forum['position'] - 1));
  280. $this->db->query("UPDATE #__forum_forums SET position = " . ($forum['position'] - 1) . " WHERE section_id = '" . $forum['section_id'] . "' AND forum_id = " . intval($_GET['forum_id']));
  281.  
  282. header("Location: " . a_url('forum/admin/forums', 'section_id=' . $forum['section_id'], TRUE));
  283. exit;
  284. break;
  285.  
  286. # Уменьшение позиции
  287. case 'down':
  288. if (!$forum = $this->db->get_row("SELECT * FROM #__forum_forums WHERE forum_id = " . intval($_GET['forum_id'])))
  289. a_error('Форум не найден!');
  290.  
  291. # Меняем позиции
  292. $this->db->query("UPDATE #__forum_forums SET position = " . $forum['position'] . " WHERE section_id = '" . $forum['section_id'] . "' AND position = " . ($forum['position'] + 1));
  293. $this->db->query("UPDATE #__forum_forums SET position = " . ($forum['position'] + 1) . " WHERE section_id = '" . $forum['section_id'] . "' AND forum_id = " . intval($_GET['forum_id']));
  294.  
  295. header("Location: " . a_url('forum/admin/forums', 'section_id=' . $forum['section_id'], TRUE));
  296. exit;
  297. break;
  298.  
  299. # Список форумов
  300. case 'forums_list':
  301. case 'list_forums':
  302. default:
  303. if (!$section = $this->db->get_row("SELECT * FROM #__forum_sections WHERE section_id = " . intval($_GET['section_id'])))
  304. a_error('Раздел не найден!');
  305.  
  306. $sql = "SELECT SQL_CALC_FOUND_ROWS ff.*
  307. FROM #__forum_forums AS ff";
  308. $sql .= " WHERE ff.section_id = '" . intval($_GET['section_id']) . "'";
  309. $sql .= " ORDER BY ff.position ASC LIMIT $this->start, $this->per_page";
  310.  
  311. $result = $this->db->query($sql);
  312.  
  313. $min_p = $this->db->get_one("SELECT MIN(position) FROM #__forum_forums WHERE section_id = '" . intval($_GET['section_id']) . "'");
  314. $max_p = $this->db->get_one("SELECT MAX(position) FROM #__forum_forums WHERE section_id = '" . intval($_GET['section_id']) . "'");
  315.  
  316. while ($forum = $this->db->fetch_array($result)) {
  317. if ($forum['position'] != $min_p) {
  318. $forum['up'] = '<a href="' . a_url('forum/admin/forums', 'a=up&amp;forum_id=' . $forum['forum_id']) . '">up</a>';
  319. } else {
  320. $forum['up'] = 'up';
  321. }
  322.  
  323. if ($forum['position'] != $max_p) {
  324. $forum['down'] = '<a href="' . a_url('forum/admin/forums', 'a=down&amp;forum_id=' . $forum['forum_id']) . '">down</a>';
  325. } else {
  326. $forum['down'] = 'down';
  327. }
  328.  
  329. $forums[] = $forum;
  330. }
  331.  
  332. $this->tpl->assign(array(
  333. 'section' => $section,
  334. 'forums' => $forums
  335. ));
  336.  
  337. $this->tpl->display('forums_list');
  338. break;
  339. }
  340. }
  341.  
  342. }
  343.  
  344. ?>