人人商城

notice.ctrl.php 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. $_W['page']['title'] = '公告分类-公告管理-文章-系统管理';
  13. if (checksubmit('submit')) {
  14. $i = 0;
  15. if (!empty($_GPC['title'])) {
  16. foreach ($_GPC['title'] as $k => $v) {
  17. $title = safe_gpc_string($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' => safe_gpc_string($_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 = table('articlecategory')->getNoticeCategoryLists();
  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 = table('articlenotice')->searchWithId($id)->get();
  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 = safe_gpc_string($_GPC['title']) ? safe_gpc_string($_GPC['title']) : itoast('公告标题不能为空', '', 'error');
  75. $cateid = intval($_GPC['cateid']) ? intval($_GPC['cateid']) : itoast('公告分类不能为空', '', 'error');
  76. $content = safe_gpc_string($_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 = table('articlecategory')->getNoticeCategoryLists();
  120. template('article/notice-post');
  121. }
  122. if ($do == 'list') {
  123. $_W['page']['title'] = '公告列表-公告管理-文章-系统管理';
  124. $pindex = max(1, intval($_GPC['page']));
  125. $psize = 20;
  126. $article_table = table('articlenotice');
  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. $notices = $article_table->getArticleNoticeLists($order);
  142. if (!empty($notices)) {
  143. foreach ($notices as &$notice_value) {
  144. if (!empty($notice_value)) {
  145. $notice_value['style'] = iunserializer($notice_value['style']);
  146. }
  147. }
  148. }
  149. $total = $article_table->getLastQueryTotal();
  150. $pager = pagination($total, $pindex, $psize);
  151. $categorys = table('articlecategory')->getNoticeCategoryLists($order);
  152. $comment_status = setting_load('notice_comment_status');
  153. $comment_status = empty($comment_status['notice_comment_status']) ? 0 : 1;
  154. template('article/notice');
  155. }
  156. if ($do == 'batch_post') {
  157. if (checksubmit()) {
  158. if (!empty($_GPC['ids'])) {
  159. foreach ($_GPC['ids'] as $k => $v) {
  160. $data = array(
  161. 'title' => trim($_GPC['title'][$k]),
  162. 'displayorder' => intval($_GPC['displayorder'][$k]),
  163. 'click' => intval($_GPC['click'][$k]),
  164. );
  165. pdo_update('article_notice', $data, array('id' => intval($v)));
  166. }
  167. itoast('编辑公告列表成功', referer(), 'success');
  168. }
  169. }
  170. }
  171. if ($do == 'del') {
  172. $id = intval($_GPC['id']);
  173. pdo_delete('article_notice', array('id' => $id));
  174. pdo_delete('article_unread_notice', array('notice_id' => $id));
  175. itoast('删除公告成功', referer(), 'success');
  176. }
  177. if ($do == 'displaysetting') {
  178. $setting = safe_gpc_string($_GPC['setting']);
  179. $data = $setting == 'createtime' ? 'createtime' : 'displayorder';
  180. setting_save($data, 'notice_display');
  181. itoast('更改成功!', referer(), 'success');
  182. }
  183. if ($do == 'comment_status') {
  184. $status = setting_load('notice_comment_status');
  185. setting_save(empty($status['notice_comment_status']) ? 1 : 0, 'notice_comment_status');
  186. itoast('更改成功!', referer(), 'success');
  187. }
  188. if ($do == 'comments') {
  189. $id = intval($_GPC['id']);
  190. $order = empty($_GPC['order']) || $_GPC['order'] == 'id' ? 'id' : 'like_num';
  191. template('article/comment-list');
  192. }
  193. if ($do == 'reply_comment') {
  194. $id = intval($_GPC['id']);
  195. $comment_table = table('article_comment');
  196. $comment = $comment_table->where('id', $id)->get();
  197. if (empty($comment)) {
  198. iajax(1, '评论不存在');
  199. }
  200. $data = array(
  201. 'parentid' => $comment['id'],
  202. 'articleid' => $comment['articleid'],
  203. 'uid' => $_W['uid'],
  204. 'content' => safe_gpc_string($_GPC['replycontent']),
  205. );
  206. $comment_table->addComment($data);
  207. $data = array_merge($data, $_W['user']);
  208. iajax(0, $data);
  209. }