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