showactivity_setting.inc.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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: showactivity_setting.inc.php 35147 2014-12-11 06:21:50Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
  9. exit('Access Denied');
  10. }
  11. $setting = C::t('common_setting')->fetch_all(array('mobilewechat'));
  12. $setting = (array)unserialize($setting['mobilewechat']);
  13. $ac = !empty($_GET['ac']) ? $_GET['ac'] : '';
  14. require_once libfile('function/forumlist');
  15. loadcache('forums');
  16. require_once DISCUZ_ROOT.'./source/plugin/wechat/setting.class.php';
  17. WeChatSetting::menu();
  18. if(!$ac) {
  19. $ppp = 20;
  20. arsort($setting['showactivity']['tids']);
  21. $page = max(1, $_GET['page']);
  22. $tids = array_slice($setting['showactivity']['tids'], ($page - 1) * $ppp, $ppp);
  23. $multipage = multi(count($setting['showactivity']['tids']), $ppp, $page, ADMINSCRIPT.'?action=plugins&operation=config&do='.$pluginid.'&identifier=wechat&pmod=showactivity_setting', 0, 3, TRUE, TRUE);
  24. $showthreads = C::t('forum_thread')->fetch_all($tids);
  25. $activities = C::t('forum_activity')->fetch_all(array_keys($showthreads));
  26. arsort($showthreads);
  27. showformheader('plugins&operation=config&do='.$pluginid.'&identifier=wechat&pmod=showactivity_setting&ac=del', 'enctype');
  28. showtableheader();
  29. echo '<tr class="header"><th></th><th>'.lang('plugin/wechat', 'show_title').'</th><th>'.
  30. lang('plugin/wechat', 'show_starttime').' - '.lang('plugin/wechat', 'show_endtime').'</th><th>'.
  31. lang('plugin/wechat', 'show_expiration').'</th><th>'.
  32. lang('plugin/wechat', 'show_applynumber').'</th><th>'.
  33. lang('plugin/wechat', 'show_forum').'</th><th></th></tr>';
  34. foreach($showthreads as $tid => $thread) {
  35. $settingsnew[$tid] = $tid;
  36. echo '<tr class="hover"><th class="td25"><input class="checkbox" type="checkbox" name="delete['.$thread['tid'].']" value="'.$thread['tid'].'"></th><th><a href="forum.php?mod=viewthread&tid='.$thread['tid'].'" target="_blank">'.$thread['subject'].'</a></th><th>'.
  37. dgmdate($activities[$thread['tid']]['starttimefrom']).($activities[$thread['tid']]['starttimeto'] ? ' - '.dgmdate($activities[$thread['tid']]['starttimeto']) : '').'</th><th>'.
  38. dgmdate($activities[$thread['tid']]['expiration']).'</th><th>'.
  39. $activities[$thread['tid']]['applynumber'].'</th><th>'.
  40. $_G['cache']['forums'][$thread['fid']]['name'].'</th><th>'.
  41. '<a href="'.ADMINSCRIPT.'?action=plugins&operation=config&do='.$pluginid.'&identifier=wechat&pmod=showactivity_setting&ac=export&tid='.$thread['tid'].'">'.lang('plugin/wechat', 'show_export').'</a></th></tr>';
  42. }
  43. $add = '<input type="button" class="btn" onclick="location.href=\''.ADMINSCRIPT.'?action=plugins&operation=config&do='.$pluginid.'&identifier=wechat&pmod=showactivity_setting&ac=add\'" value="'.lang('plugin/wechat', 'show_addthread').'" />';
  44. if($showthreads) {
  45. showsubmit('submit', lang('plugin/wechat', 'show_delthread'), $add, '', $multipage);
  46. } else {
  47. showsubmit('', '', 'td', $add);
  48. }
  49. showtablefooter();
  50. showformfooter();
  51. } elseif($ac == 'del') {
  52. if(submitcheck('submit')) {
  53. foreach($_GET['delete'] as $delete) {
  54. unset($setting['showactivity']['tids'][$delete]);
  55. C::t('forum_thread')->delete($delete);
  56. }
  57. $settings = array('mobilewechat' => serialize($setting));
  58. C::t('common_setting')->update_batch($settings);
  59. updatecache(array('plugin', 'setting'));
  60. cpmsg(lang('plugin/wechat', 'show_delthread_succeed'), 'action=plugins&operation=config&do='.$pluginid.'&identifier=wechat&pmod=showactivity_setting', 'succeed');
  61. }
  62. } elseif($ac == 'add') {
  63. if(!submitcheck('submit')) {
  64. echo '<script type="text/javascript" src="static/js/calendar.js"></script>';
  65. $forumselect = "<select name=\"fid\">\n<option value=\"\">&nbsp;&nbsp;> ".cplang('select')."</option><option value=\"\">&nbsp;</option>".str_replace('%', '%%', forumselect(FALSE, 0, 0, TRUE)).'</select>';
  66. showformheader('plugins&operation=config&do='.$pluginid.'&identifier=wechat&pmod=showactivity_setting&ac=add', 'enctype');
  67. showtableheader();
  68. showsetting(lang('plugin/wechat', 'show_title'), 'subject', '', 'text');
  69. showsetting(lang('plugin/wechat', 'show_starttime'), 'starttimefrom', '', 'calendar', '', 0, '', 1);
  70. showsetting(lang('plugin/wechat', 'show_expiration'), 'activityexpiration', '', 'calendar', '', 0, '', 1);
  71. showsetting(lang('plugin/wechat', 'show_endtime'), 'starttimeto', '', 'calendar', '', 0, '', 1);
  72. showsetting(lang('plugin/wechat', 'show_memo'), 'message', '', 'textarea');
  73. showsetting(lang('plugin/wechat', 'show_forum'), '', '', $forumselect);
  74. showsubmit('submit');
  75. showtablefooter();
  76. showformfooter();
  77. } else {
  78. $_GET['activityclass'] = lang('plugin/wechat', 'show_thread_class');
  79. $_GET['activityplace'] = lang('plugin/wechat', 'show_thread_place');
  80. if(!$_GET['subject'] || !$_GET['starttimefrom'] || !$_GET['activityexpiration'] || !$_GET['message'] || !$_GET['fid']) {
  81. cpmsg(lang('plugin/wechat', 'show_input_error'), '', 'error');
  82. }
  83. if(@strtotime($_GET['starttimefrom']) === -1 || @strtotime($_GET['starttimefrom']) === FALSE) {
  84. cpmsg(lang('message', 'activity_fromtime_error'), '', 'error');
  85. } elseif(trim($_GET['activityexpiration']) && (@strtotime($_GET['activityexpiration']) === -1 || @strtotime($_GET['activityexpiration']) === FALSE)) {
  86. cpmsg(lang('message', 'activity_totime_error'), '', 'error');
  87. }
  88. $activity = array();
  89. $activity['class'] = $_GET['activityclass'];
  90. $activity['starttimefrom'] = @strtotime($_GET['starttimefrom']);
  91. $activity['starttimeto'] = $_GET['starttimeto'] ? @strtotime($_GET['starttimeto']) : 0;
  92. $activity['place'] = $_GET['activityplace'];
  93. $activity['expiration'] = @strtotime($_GET['activityexpiration']);
  94. $newthread = array(
  95. 'fid' => $_GET['fid'],
  96. 'posttableid' => 0,
  97. 'readperm' => 0,
  98. 'price' => 0,
  99. 'typeid' => 0,
  100. 'sortid' => 0,
  101. 'author' => $_G['username'],
  102. 'authorid' => $_G['uid'],
  103. 'subject' => $_GET['subject'],
  104. 'dateline' => TIMESTAMP,
  105. 'lastpost' => TIMESTAMP,
  106. 'lastposter' => $_G['username'],
  107. 'displayorder' => 1,
  108. 'digest' => 0,
  109. 'special' => 4,
  110. 'attachment' => 0,
  111. 'moderated' => 0,
  112. 'status' => 0,
  113. 'isgroup' => 0,
  114. 'replycredit' => 0,
  115. 'closed' => 0,
  116. );
  117. $tid = C::t('forum_thread')->insert($newthread, true);
  118. $pid = insertpost(array(
  119. 'fid' => $_GET['fid'],
  120. 'tid' => $tid,
  121. 'first' => '1',
  122. 'author' => $_G['username'],
  123. 'authorid' => $_G['uid'],
  124. 'subject' => $_GET['subject'],
  125. 'dateline' => TIMESTAMP,
  126. 'message' => $_GET['message'],
  127. 'useip' => '',
  128. 'invisible' => 0,
  129. 'anonymous' => 0,
  130. 'usesig' => 0,
  131. 'htmlon' => 0,
  132. 'bbcodeoff' => 0,
  133. 'smileyoff' => 0,
  134. 'parseurloff' => 0,
  135. 'attachment' => '0',
  136. 'tags' => '',
  137. 'replycredit' => 0,
  138. 'status' => 0
  139. ));
  140. $data = array(
  141. 'tid' => $tid,
  142. 'uid' => $_G['uid'],
  143. 'cost' => 0,
  144. 'starttimefrom' => $activity['starttimefrom'],
  145. 'starttimeto' => $activity['starttimeto'],
  146. 'place' => $activity['place'],
  147. 'class' => $activity['class'],
  148. 'expiration' => $activity['expiration']
  149. );
  150. C::t('forum_activity')->insert($data);
  151. $setting['showactivity']['tids'][$tid] = $tid;
  152. $settings = array('mobilewechat' => serialize($setting));
  153. C::t('common_setting')->update_batch($settings);
  154. updatecache(array('plugin', 'setting'));
  155. require_once DISCUZ_ROOT . './source/plugin/wechat/wsq.class.php';
  156. wsq::report('pubshowactivity');
  157. cpmsg(lang('plugin/wechat', 'show_addthread_succeed'), 'action=plugins&operation=config&do='.$pluginid.'&identifier=wechat&pmod=showactivity_setting', 'succeed');
  158. }
  159. } elseif($ac == 'export') {
  160. if(!isset($setting['showactivity']['tids'][$_GET['tid']])) {
  161. cpmsg(lang('plugin/wechat', 'show_thread_not_found'));
  162. }
  163. $thread = get_thread_by_tid($_GET['tid']);
  164. if(!$thread) {
  165. cpmsg(lang('plugin/wechat', 'show_thread_not_found'));
  166. }
  167. $posttableid = $thread['posttableid'];
  168. $posts = DB::fetch_all("SELECT * FROM %t WHERE tid=%d", array('forum_debatepost', $_GET['tid']), 'pid');
  169. foreach(C::t('forum_post')->fetch_all($posttableid, array_keys($posts), false) as $post) {
  170. $array[$posts[$post['pid']]['voters'].'.'.$post['position']] = $post['author'].','.$posts[$post['pid']]['voters'].','.$post['position'];
  171. }
  172. ob_end_clean();
  173. header('Content-Encoding: none');
  174. header('Content-Type: application/octet-stream');
  175. header('Content-Disposition: attachment; filename=showactivity_'.$_GET['tid'].'.csv');
  176. header('Pragma: no-cache');
  177. header('Expires: 0');
  178. krsort($array);
  179. $detail = lang('plugin/wechat', 'show_export_title')."\r\n".implode("\r\n", $array);
  180. if($_G['charset'] != 'gbk') {
  181. $detail = diconv($detail, $_G['charset'], 'GBK');
  182. }
  183. define('FOOTERDISABLED', true);
  184. echo $detail;
  185. exit();
  186. }
  187. ?>