modcp_announcement.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: modcp_announcement.php 29236 2012-03-30 05:34:47Z chenmengshu $
  7. */
  8. if(!defined('IN_DISCUZ') || !defined('IN_MODCP')) {
  9. exit('Access Denied');
  10. }
  11. $annlist = null;
  12. $add_successed = $edit_successed = false;
  13. $op = empty($_GET['op']) ? 'add' : $_GET['op'];
  14. $announce = array('subject' => '', 'message' => '', 'starttime' => '', 'endtime' => '');
  15. $announce['checked'] = array('selected="selected"', '');
  16. switch($op) {
  17. case 'add':
  18. $announce['starttime'] = dgmdate(TIMESTAMP, 'd');
  19. $announce['endtime'] = dgmdate(TIMESTAMP + 86400 * 30, 'd');
  20. if(submitcheck('submit')) {
  21. $message = is_array($_GET['message']) ? $_GET['message'][$_GET['type']] : '';
  22. save_announce(0, $_GET['starttime'], $_GET['endtime'], $_GET['subject'], $_GET['type'], $message, 0);
  23. $add_successed = true;
  24. }
  25. break;
  26. case 'manage':
  27. $annlist = get_annlist();
  28. if(submitcheck('submit')) {
  29. $delids = array();
  30. if(!empty($_GET['delete']) && is_array($_GET['delete'])) {
  31. foreach($_GET['delete'] as $id) {
  32. $id = intval($id);
  33. if(isset($annlist[$id])) {
  34. unset($annlist[$id]);
  35. $delids[] = $id;
  36. }
  37. }
  38. if($delids) {
  39. C::t('forum_announcement')->delete_by_id_username($delids, $_G['username']);
  40. }
  41. }
  42. $updateorder = false;
  43. if(!empty($_GET['order']) && is_array($_GET['order'])) {
  44. foreach ($_GET['order'] as $id => $val) {
  45. $val = intval($val);
  46. if(isset($annlist[$id]) && $annlist[$id]['displayorder'] != $val) {
  47. $annlist[$id]['displayorder'] = $val;
  48. C::t('forum_announcement')->update_displayorder_by_id_username($id, $val, $_G['username']);
  49. $updateorder = true;
  50. }
  51. }
  52. }
  53. if($delids || $updateorder) {
  54. update_announcecache();
  55. }
  56. }
  57. break;
  58. case 'edit':
  59. $id = intval($_GET['id']);
  60. $announce = C::t('forum_announcement')->fetch_by_id_username($id, $_G['username']);
  61. if(!count($announce)) {
  62. showmessage('modcp_ann_nofound');
  63. }
  64. if(!submitcheck('submit')) {
  65. $announce['starttime'] = $announce['starttime'] ? dgmdate($announce['starttime'], 'd') : '';
  66. $announce['endtime'] = $announce['endtime'] ? dgmdate($announce['endtime'], 'd') : '';
  67. $announce['message'] = $announce['type'] != 1 ? dhtmlspecialchars($announce['message']) : $announce['message'];
  68. $announce['checked'] = $announce['type'] != 1 ? array('selected="selected"', '') : array('', 'selected="selected"');
  69. } else {
  70. $announce['starttime'] = $_GET['starttime'];
  71. $announce['endtime'] = $_GET['endtime'];
  72. $announce['checked'] = $_GET['type'] != 1 ? array('selected="selected"', '') : array('', 'selected="selected"');
  73. $message = $_GET['message'][$_GET['type']];
  74. save_announce($id, $_GET['starttime'], $_GET['endtime'], $_GET['subject'], $_GET['type'], $message, $_GET['displayorder']);
  75. $edit_successed = true;
  76. }
  77. break;
  78. }
  79. $annlist = get_annlist();
  80. function get_annlist() {
  81. global $_G;
  82. $annlist = C::t('forum_announcement')->fetch_all_by_displayorder();
  83. foreach ($annlist as $announce) {
  84. $announce['disabled'] = $announce['author'] != $_G['member']['username'] ? 'disabled' : '';
  85. $announce['starttime'] = $announce['starttime'] ? dgmdate($announce['starttime'], 'd') : '-';
  86. $announce['endtime'] = $announce['endtime'] ? dgmdate($announce['endtime'], 'd') : '-';
  87. $annlist[$announce['id']] = $announce;
  88. }
  89. return $annlist;
  90. }
  91. function update_announcecache() {
  92. require_once libfile('function/cache');
  93. updatecache(array('announcements', 'announcements_forum'));
  94. }
  95. function save_announce($id = 0, $starttime, $endtime, $subject, $type, $message, $displayorder = 0) {
  96. global $_G;
  97. $displayorder = intval($displayorder);
  98. $type = intval($type);
  99. $starttime = empty($starttime) || strtotime($starttime) < TIMESTAMP ? TIMESTAMP : strtotime($starttime);
  100. $endtime = empty($endtime) ? 0 : (strtotime($endtime) < $starttime ? ($starttime + 86400 * 30) : strtotime($endtime));
  101. $subject = dhtmlspecialchars(trim($subject));
  102. if($type == 1) {
  103. list($message) = explode("\n", trim($message));
  104. $message = dhtmlspecialchars($message);
  105. } else {
  106. $type = 0;
  107. $message = trim($message);
  108. }
  109. if(empty($subject) || empty($message)) {
  110. acpmsg('modcp_ann_empty');
  111. } elseif($type == 1 && substr(strtolower($message), 0, 7) != 'http://') {
  112. acpmsg('modcp_ann_urlerror');
  113. } else {
  114. $data = array('author'=>$_G['username'], 'subject'=>$subject, 'type'=>$type, 'starttime'=>$starttime, 'endtime'=>$endtime,
  115. 'message'=>$message, 'displayorder'=>$displayorder);
  116. if(empty($id)) {
  117. C::t('forum_announcement')->insert($data);
  118. } else {
  119. C::t('forum_announcement')->update($id, $data, true);
  120. }
  121. update_announcecache();
  122. return true;
  123. }
  124. }
  125. ?>