notice.ctrl.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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', 'comment_status', 'comments', 'reply_comment');
  9. $do = in_array($do, $dos) ? $do : 'list';
  10. permission_check_account_user('system_article_notice');
  11. if ($do == 'category_post') {
  12. if (checksubmit('submit')) {
  13. $i = 0;
  14. if (!empty($_GPC['title'])) {
  15. foreach ($_GPC['title'] as $k => $v) {
  16. $title = safe_gpc_string($v);
  17. if (empty($title)) {
  18. continue;
  19. }
  20. $data = array(
  21. 'title' => $title,
  22. 'displayorder' => intval($_GPC['displayorder'][$k]),
  23. 'type' => 'notice',
  24. );
  25. pdo_insert('article_category', $data);
  26. $i++;
  27. }
  28. }
  29. itoast('添加公告分类成功', url('article/notice/category'), 'success');
  30. }
  31. template('article/notice-category-post');
  32. }
  33. if ($do == 'category') {
  34. $category_table = table('article_category');
  35. if (checksubmit('submit')) {
  36. $id = intval($_GPC['id']);
  37. if (empty($id)) {
  38. iajax(1, '参数有误');
  39. }
  40. if (empty($_GPC['title'])) {
  41. iajax(1, '分类名称不能为空');
  42. }
  43. $update = array(
  44. 'title' => safe_gpc_string($_GPC['title']),
  45. 'displayorder' => max(0,intval($_GPC['displayorder']))
  46. );
  47. $category_table->fill($update)->where('id', $id)->save();
  48. iajax(0, '修改分类成功');
  49. }
  50. $data = $category_table->getNoticeCategoryLists();
  51. template('article/notice-category');
  52. }
  53. if ($do == 'category_del') {
  54. $id = intval($_GPC['id']);
  55. pdo_delete('article_category', array('id' => $id,'type' => 'notice'));
  56. pdo_delete('article_notice', array('cateid' => $id));
  57. itoast('删除公告分类成功', referer(), 'success');
  58. }
  59. if ($do == 'post') {
  60. $id = intval($_GPC['id']);
  61. $notice = table('article_notice')->searchWithId($id)->get();
  62. if (empty($notice)) {
  63. $notice = array(
  64. 'is_display' => 1,
  65. 'is_show_home' => 1,
  66. 'group' => array('vice_founder' => array(), 'normal' => array())
  67. );
  68. } else {
  69. $notice['style'] = iunserializer($notice['style']);
  70. $notice['group'] = empty($notice['group']) ? array('vice_founder' => array(), 'normal' => array()) : iunserializer($notice['group']);
  71. }
  72. $user_groups = table('users_group')->getall();
  73. $user_vice_founder_groups = table('users_founder_group')->getall();
  74. if (checksubmit()) {
  75. $title = safe_gpc_string($_GPC['title']) ? safe_gpc_string($_GPC['title']) : itoast('公告标题不能为空', '', 'error');
  76. $cateid = intval($_GPC['cateid']) ? intval($_GPC['cateid']) : itoast('公告分类不能为空', '', 'error');
  77. $content = safe_gpc_string($_GPC['content']) ? safe_gpc_string($_GPC['content']) : itoast('公告内容不能为空', '', 'error');
  78. $style = array('color' => safe_gpc_string($_GPC['style']['color']), 'bold' => intval($_GPC['style']['bold']));
  79. $group = $vice_group = array();
  80. if (!empty($_GPC['group']) && is_array($_GPC['group'])) {
  81. foreach ($_GPC['group'] as $value) {
  82. if (!is_numeric($value)) {
  83. itoast('参数错误!');
  84. }
  85. $group[] = intval($value);
  86. }
  87. }
  88. if (!empty($_GPC['vice_founder_group']) && is_array($_GPC['vice_founder_group'])) {
  89. foreach ($_GPC['vice_founder_group'] as $vice_founder_value) {
  90. if (!is_numeric($vice_founder_value)) {
  91. itoast('参数错误!');
  92. }
  93. $vice_group[] = intval($vice_founder_value);
  94. }
  95. }
  96. if (empty($group) && empty($vice_group)) {
  97. $group = '';
  98. } else {
  99. $group = iserializer(array('normal' => $group, 'vice_founder' => $vice_group));
  100. }
  101. $data = array(
  102. 'title' => $title,
  103. 'cateid' => $cateid,
  104. 'content' => safe_gpc_html(htmlspecialchars_decode($content)),
  105. 'displayorder' => intval($_GPC['displayorder']),
  106. 'click' => intval($_GPC['click']),
  107. 'is_display' => intval($_GPC['is_display']),
  108. 'is_show_home' => intval($_GPC['is_show_home']),
  109. 'createtime' => TIMESTAMP,
  110. 'style' => iserializer($style),
  111. 'group' => $group,
  112. );
  113. if (!empty($notice['id'])) {
  114. pdo_update('article_notice', $data, array('id' => $id));
  115. } else {
  116. pdo_insert('article_notice', $data);
  117. }
  118. itoast('编辑公告成功', url('article/notice/list'), 'success');
  119. }
  120. $categorys = table('article_category')->getNoticeCategoryLists();
  121. template('article/notice-post');
  122. }
  123. if ($do == 'list') {
  124. $pindex = max(1, intval($_GPC['page']));
  125. $psize = 20;
  126. $article_table = table('article_notice');
  127. $cateid = intval($_GPC['cateid']);
  128. $createtime = intval($_GPC['createtime']);
  129. $title = safe_gpc_string($_GPC['title']);
  130. if (!empty($cateid)) {
  131. $article_table->searchWithCateid($cateid);
  132. }
  133. if (!empty($createtime)) {
  134. $article_table->searchWithCreatetimeRange($createtime);
  135. }
  136. if (!empty($title)) {
  137. $article_table->searchWithTitle($title);
  138. }
  139. $order = !empty($_W['setting']['news_display']) ? $_W['setting']['news_display'] : 'displayorder';
  140. $article_table->searchWithPage($pindex, $psize);
  141. $article_table->orderby($order, 'DESC');
  142. $notices = $article_table->getList();
  143. $total = $article_table->getLastQueryTotal();
  144. $pager = pagination($total, $pindex, $psize);
  145. $categorys = table('article_category')->getNoticeCategoryLists();
  146. $comment_status = setting_load('notice_comment_status');
  147. $comment_status = empty($comment_status['notice_comment_status']) ? 0 : 1;
  148. template('article/notice');
  149. }
  150. if ($do == 'batch_post') {
  151. if (checksubmit()) {
  152. if (!empty($_GPC['ids'])) {
  153. foreach ($_GPC['ids'] as $k => $v) {
  154. $data = array(
  155. 'title' => trim($_GPC['title'][$k]),
  156. 'displayorder' => intval($_GPC['displayorder'][$k]),
  157. 'click' => intval($_GPC['click'][$k]),
  158. );
  159. pdo_update('article_notice', $data, array('id' => intval($v)));
  160. }
  161. itoast('编辑公告列表成功', referer(), 'success');
  162. }
  163. }
  164. }
  165. if ($do == 'del') {
  166. $id = intval($_GPC['id']);
  167. pdo_delete('article_notice', array('id' => $id));
  168. pdo_delete('article_unread_notice', array('notice_id' => $id));
  169. itoast('删除公告成功', referer(), 'success');
  170. }
  171. if ($do == 'displaysetting') {
  172. $setting = safe_gpc_string($_GPC['setting']);
  173. $data = $setting == 'createtime' ? 'createtime' : 'displayorder';
  174. setting_save($data, 'notice_display');
  175. itoast('更改成功!', referer(), 'success');
  176. }
  177. if ($do == 'comment_status') {
  178. $status = setting_load('notice_comment_status');
  179. setting_save(empty($status['notice_comment_status']) ? 1 : 0, 'notice_comment_status');
  180. itoast('更改成功!', referer(), 'success');
  181. }
  182. if ($do == 'comments') {
  183. $id = intval($_GPC['id']);
  184. $order = empty($_GPC['order']) || $_GPC['order'] == 'id' ? 'id' : 'like_num';
  185. template('article/comment-list');
  186. }
  187. if ($do == 'reply_comment') {
  188. $id = intval($_GPC['id']);
  189. $comment_table = table('article_comment');
  190. $comment = $comment_table->where('id', $id)->get();
  191. if (empty($comment)) {
  192. iajax(1, '评论不存在');
  193. }
  194. $data = array(
  195. 'parentid' => $comment['id'],
  196. 'articleid' => $comment['articleid'],
  197. 'uid' => $_W['uid'],
  198. 'content' => safe_gpc_string($_GPC['replycontent']),
  199. );
  200. $comment_table->addComment($data);
  201. $data = array_merge($data, $_W['user']);
  202. iajax(0, $data);
  203. }