admin_announce.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. defined('IN_PHPCMS') or exit('No permission resources.');
  3. pc_base::load_app_class('admin','admin',0);
  4. class admin_announce extends admin {
  5. private $db; public $username;
  6. public function __construct() {
  7. parent::__construct();
  8. //if (!module_exists(ROUTE_M)) showmessage(L('module_not_exists'));
  9. $this->username = param::get_cookie('admin_username');
  10. $this->db = pc_base::load_model('announce_model');
  11. }
  12. public function init() {
  13. //公告列表
  14. $sql = '';
  15. $_GET['status'] = $_GET['status'] ? intval($_GET['status']) : 1;
  16. $sql = '`siteid`=\''.$this->get_siteid().'\'';
  17. switch($_GET['s']) {
  18. case '1': $sql .= ' AND `passed`=\'1\' AND (`endtime` >= \''.date('Y-m-d').'\' or `endtime`=\'0000-00-00\')'; break;
  19. case '2': $sql .= ' AND `passed`=\'0\''; break;
  20. case '3': $sql .= ' AND `passed`=\'1\' AND `endtime`!=\'0000-00-00\' AND `endtime` <\''.date('Y-m-d').'\' '; break;
  21. }
  22. $page = max(intval($_GET['page']), 1);
  23. $data = $this->db->listinfo($sql, '`aid` DESC', $page);
  24. $big_menu = array('javascript:window.top.art.dialog({id:\'add\',iframe:\'?m=announce&c=admin_announce&a=add\', title:\''.L('announce_add').'\', width:\'700\', height:\'500\', lock:true}, function(){var d = window.top.art.dialog({id:\'add\'}).data.iframe;var form = d.document.getElementById(\'dosubmit\');form.click();return false;}, function(){window.top.art.dialog({id:\'add\'}).close()});void(0);', L('announce_add'));
  25. include $this->admin_tpl('announce_list');
  26. }
  27. /**
  28. * 添加公告
  29. */
  30. public function add() {
  31. if(isset($_POST['dosubmit'])) {
  32. $_POST['announce'] = $this->check($_POST['announce']);
  33. if($this->db->insert($_POST['announce'])) showmessage(L('announcement_successful_added'), HTTP_REFERER, '', 'add');
  34. } else {
  35. //获取站点模板信息
  36. pc_base::load_app_func('global', 'admin');
  37. $siteid = $this->get_siteid();
  38. $template_list = template_list($siteid, 0);
  39. $site = pc_base::load_app_class('sites','admin');
  40. $info = $site->get_by_id($siteid);
  41. foreach ($template_list as $k=>$v) {
  42. $template_list[$v['dirname']] = $v['name'] ? $v['name'] : $v['dirname'];
  43. unset($template_list[$k]);
  44. }
  45. $show_header = $show_validator = $show_scroll = 1;
  46. pc_base::load_sys_class('form', '', 0);
  47. include $this->admin_tpl('announce_add');
  48. }
  49. }
  50. /**
  51. * 修改公告
  52. */
  53. public function edit() {
  54. $_GET['aid'] = intval($_GET['aid']);
  55. if(!$_GET['aid']) showmessage(L('illegal_operation'));
  56. if(isset($_POST['dosubmit'])) {
  57. $_POST['announce'] = $this->check($_POST['announce'], 'edit');
  58. if($this->db->update($_POST['announce'], array('aid' => $_GET['aid']))) showmessage(L('announced_a'), HTTP_REFERER, '', 'edit');
  59. } else {
  60. $where = array('aid' => $_GET['aid']);
  61. $an_info = $this->db->get_one($where);
  62. pc_base::load_sys_class('form', '', 0);
  63. //获取站点模板信息
  64. pc_base::load_app_func('global', 'admin');
  65. $template_list = template_list($this->siteid, 0);
  66. foreach ($template_list as $k=>$v) {
  67. $template_list[$v['dirname']] = $v['name'] ? $v['name'] : $v['dirname'];
  68. unset($template_list[$k]);
  69. }
  70. $show_header = $show_validator = $show_scroll = 1;
  71. include $this->admin_tpl('announce_edit');
  72. }
  73. }
  74. /**
  75. * ajax检测公告标题是否重复
  76. */
  77. public function public_check_title() {
  78. if (!$_GET['title']) exit(0);
  79. if (CHARSET=='gbk') {
  80. $_GET['title'] = iconv('UTF-8', 'GBK', $_GET['title']);
  81. }
  82. $title = $_GET['title'];
  83. if ($_GET['aid']) {
  84. $r = $this->db->get_one(array('aid' => $_GET['aid']));
  85. if ($r['title'] == $title) {
  86. exit('1');
  87. }
  88. }
  89. $r = $this->db->get_one(array('siteid' => $this->get_siteid(), 'title' => $title), 'aid');
  90. if($r['aid']) {
  91. exit('0');
  92. } else {
  93. exit('1');
  94. }
  95. }
  96. /**
  97. * 批量修改公告状态 使其成为审核、未审核状态
  98. */
  99. public function public_approval($aid = 0) {
  100. if((!isset($_POST['aid']) || empty($_POST['aid'])) && !$aid) {
  101. showmessage(L('illegal_operation'));
  102. } else {
  103. if(is_array($_POST['aid']) && !$aid) {
  104. array_map(array($this, 'public_approval'), $_POST['aid']);
  105. showmessage(L('announce_passed'), HTTP_REFERER);
  106. } elseif($aid) {
  107. $aid = intval($aid);
  108. $this->db->update(array('passed' => $_GET['passed']), array('aid' => $aid));
  109. return true;
  110. }
  111. }
  112. }
  113. /**
  114. * 批量删除公告
  115. */
  116. public function delete($aid = 0) {
  117. if((!isset($_POST['aid']) || empty($_POST['aid'])) && !$aid) {
  118. showmessage(L('illegal_operation'));
  119. } else {
  120. if(is_array($_POST['aid']) && !$aid) {
  121. array_map(array($this, 'delete'), $_POST['aid']);
  122. showmessage(L('announce_deleted'), HTTP_REFERER);
  123. } elseif($aid) {
  124. $aid = intval($aid);
  125. $this->db->delete(array('aid' => $aid));
  126. }
  127. }
  128. }
  129. /**
  130. * 验证表单数据
  131. * @param array $data 表单数组数据
  132. * @param string $a 当表单为添加数据时,自动补上缺失的数据。
  133. * @return array 验证后的数据
  134. */
  135. private function check($data = array(), $a = 'add') {
  136. if($data['title']=='') showmessage(L('title_cannot_empty'));
  137. if($data['content']=='') showmessage(L('announcements_cannot_be_empty'));
  138. $r = $this->db->get_one(array('title' => $data['title']));
  139. if (strtotime($data['endtime'])<strtotime($data['starttime'])) {
  140. $data['endtime'] = '';
  141. }
  142. if ($a=='add') {
  143. if (is_array($r) && !empty($r)) {
  144. showmessage(L('announce_exist'), HTTP_REFERER);
  145. }
  146. $data['siteid'] = $this->get_siteid();
  147. $data['addtime'] = SYS_TIME;
  148. $data['username'] = $this->username;
  149. if ($data['starttime'] == '') $announce['starttime'] = date('Y-m-d');
  150. } else {
  151. if ($r['aid'] && ($r['aid']!=$_GET['aid'])) {
  152. showmessage(L('announce_exist'), HTTP_REFERER);
  153. }
  154. }
  155. return $data;
  156. }
  157. }
  158. ?>