notice.ctrl.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. load()->model('article');
  8. $dos = array('category_post', 'category', 'category_del', 'list', 'post', 'batch_post', 'del', 'displaysetting');
  9. $do = in_array($do, $dos) ? $do : 'list';
  10. permission_check_account_user('system_article_notice');
  11. if ($do == 'category_post') {
  12. $_W['page']['title'] = '公告分类-公告管理-文章-系统管理';
  13. if (checksubmit('submit')) {
  14. $i = 0;
  15. if (!empty($_GPC['title'])) {
  16. foreach ($_GPC['title'] as $k => $v) {
  17. $title = trim($v);
  18. if (empty($title)) {
  19. continue;
  20. }
  21. $data = array(
  22. 'title' => $title,
  23. 'displayorder' => intval($_GPC['displayorder'][$k]),
  24. 'type' => 'notice',
  25. );
  26. pdo_insert('article_category', $data);
  27. $i++;
  28. }
  29. }
  30. itoast('添加公告分类成功', url('article/notice/category'), 'success');
  31. }
  32. template('article/notice-category-post');
  33. }
  34. if ($do == 'category') {
  35. $_W['page']['title'] = '分类列表-公告分类-公告管理-文章-系统管理';
  36. if (checksubmit('submit')) {
  37. if (!empty($_GPC['ids'])) {
  38. foreach ($_GPC['ids'] as $k => $v) {
  39. $data = array(
  40. 'title' => trim($_GPC['title'][$k]),
  41. 'displayorder' => intval($_GPC['displayorder'][$k])
  42. );
  43. pdo_update('article_category', $data, array('id' => intval($v)));
  44. }
  45. itoast('修改公告分类成功', referer(), 'success');
  46. }
  47. }
  48. $data = pdo_fetchall('SELECT * FROM ' . tablename('article_category') . ' WHERE type = :type ORDER BY displayorder DESC', array(':type' => 'notice'));
  49. template('article/notice-category');
  50. }
  51. if ($do == 'category_del') {
  52. $id = intval($_GPC['id']);
  53. pdo_delete('article_category', array('id' => $id,'type' => 'notice'));
  54. pdo_delete('article_notice', array('cateid' => $id));
  55. itoast('删除公告分类成功', referer(), 'success');
  56. }
  57. if ($do == 'post') {
  58. $_W['page']['title'] = '编辑公告-公告管理-文章-系统管理';
  59. $id = intval($_GPC['id']);
  60. $notice = pdo_fetch('SELECT * FROM ' . tablename('article_notice') . ' WHERE id = :id', array(':id' => $id));
  61. if (empty($notice)) {
  62. $notice = array(
  63. 'is_display' => 1,
  64. 'is_show_home' => 1,
  65. 'group' => array('vice_founder' => array(), 'normal' => array())
  66. );
  67. } else {
  68. $notice['style'] = iunserializer($notice['style']);
  69. $notice['group'] = empty($notice['group']) ? array('vice_founder' => array(), 'normal' => array()) : iunserializer($notice['group']);
  70. }
  71. $user_groups = table('group')->groupList();
  72. $user_vice_founder_groups = table('group')->groupList(true);
  73. if (checksubmit()) {
  74. $title = trim($_GPC['title']) ? safe_gpc_string($_GPC['title']) : itoast('公告标题不能为空', '', 'error');
  75. $cateid = intval($_GPC['cateid']) ? intval($_GPC['cateid']) : itoast('公告分类不能为空', '', 'error');
  76. $content = trim($_GPC['content']) ? safe_gpc_string($_GPC['content']) : itoast('公告内容不能为空', '', 'error');
  77. $style = array('color' => safe_gpc_string($_GPC['style']['color']), 'bold' => intval($_GPC['style']['bold']));
  78. $group = $vice_group = array();
  79. if (!empty($_GPC['group']) && is_array($_GPC['group'])) {
  80. foreach ($_GPC['group'] as $value) {
  81. if (!is_numeric($value)) {
  82. itoast('参数错误!');
  83. }
  84. $group[] = intval($value);
  85. }
  86. }
  87. if (!empty($_GPC['vice_founder_group']) && is_array($_GPC['vice_founder_group'])) {
  88. foreach ($_GPC['vice_founder_group'] as $vice_founder_value) {
  89. if (!is_numeric($vice_founder_value)) {
  90. itoast('参数错误!');
  91. }
  92. $vice_group[] = intval($vice_founder_value);
  93. }
  94. }
  95. if (empty($group) && empty($vice_group)) {
  96. $group = '';
  97. } else {
  98. $group = iserializer(array('normal' => $group, 'vice_founder' => $vice_group));
  99. }
  100. $data = array(
  101. 'title' => $title,
  102. 'cateid' => $cateid,
  103. 'content' => safe_gpc_html(htmlspecialchars_decode($content)),
  104. 'displayorder' => intval($_GPC['displayorder']),
  105. 'click' => intval($_GPC['click']),
  106. 'is_display' => intval($_GPC['is_display']),
  107. 'is_show_home' => intval($_GPC['is_show_home']),
  108. 'createtime' => TIMESTAMP,
  109. 'style' => iserializer($style),
  110. 'group' => $group,
  111. );
  112. if (!empty($notice['id'])) {
  113. pdo_update('article_notice', $data, array('id' => $id));
  114. } else {
  115. pdo_insert('article_notice', $data);
  116. }
  117. itoast('编辑公告成功', url('article/notice/list'), 'success');
  118. }
  119. $categorys = pdo_fetchall('SELECT * FROM ' . tablename('article_category') . ' WHERE type = :type ORDER BY displayorder DESC', array(':type' => 'notice'));
  120. template('article/notice-post');
  121. }
  122. if ($do == 'list') {
  123. $_W['page']['title'] = '公告列表-公告管理-文章-系统管理';
  124. $condition = ' WHERE 1';
  125. $cateid = intval($_GPC['cateid']);
  126. $createtime = intval($_GPC['createtime']);
  127. $search_title = trim($_GPC['title']);
  128. $params = array();
  129. if ($cateid > 0) {
  130. $condition .= ' AND cateid = :cateid';
  131. $params[':cateid'] = $cateid;
  132. }
  133. if ($createtime > 0) {
  134. $condition .= ' AND createtime >= :createtime';
  135. $params[':createtime'] = strtotime("-{$createtime} days");
  136. }
  137. if (!empty($search_title)) {
  138. $condition .= " AND title LIKE :title";
  139. $params[':title'] = "%{$search_title}%";
  140. }
  141. $order = !empty($_W['setting']['notice_display']) ? $_W['setting']['notice_display'] : 'displayorder';
  142. $pindex = max(1, intval($_GPC['page']));
  143. $psize = 20;
  144. $sql = 'SELECT * FROM ' . tablename('article_notice') . $condition . " ORDER BY " . $order . " DESC LIMIT " . ($pindex - 1) * $psize .',' .$psize;
  145. $notices = pdo_fetchall($sql, $params);
  146. foreach ($notices as &$notice_value) {
  147. if (!empty($notice_value)) {
  148. $notice_value['style'] = iunserializer($notice_value['style']);
  149. }
  150. }
  151. unset($notice_value);
  152. $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('article_notice') . $condition, $params);
  153. $pager = pagination($total, $pindex, $psize);
  154. $categorys = pdo_fetchall('SELECT * FROM ' . tablename('article_category') . ' WHERE type = :type ORDER BY displayorder DESC', array(':type' => 'notice'), 'id');
  155. template('article/notice');
  156. }
  157. if ($do == 'batch_post') {
  158. if (checksubmit()) {
  159. if (!empty($_GPC['ids'])) {
  160. foreach ($_GPC['ids'] as $k => $v) {
  161. $data = array(
  162. 'title' => trim($_GPC['title'][$k]),
  163. 'displayorder' => intval($_GPC['displayorder'][$k]),
  164. 'click' => intval($_GPC['click'][$k]),
  165. );
  166. pdo_update('article_notice', $data, array('id' => intval($v)));
  167. }
  168. itoast('编辑公告列表成功', referer(), 'success');
  169. }
  170. }
  171. }
  172. if ($do == 'del') {
  173. $id = intval($_GPC['id']);
  174. pdo_delete('article_notice', array('id' => $id));
  175. pdo_delete('article_unread_notice', array('notice_id' => $id));
  176. itoast('删除公告成功', referer(), 'success');
  177. }
  178. if ($do == 'displaysetting') {
  179. $setting = trim($_GPC['setting']);
  180. $data = $setting == 'createtime' ? 'createtime' : 'displayorder';
  181. setting_save($data, 'notice_display');
  182. itoast('更改成功!', referer(), 'success');
  183. }