admincp_credits.php
9.04 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
213
214
215
216
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: admincp_credits.php 32527 2013-02-05 09:56:25Z monkey $
*/
if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
exit('Access Denied');
}
cpheader();
$operation = $operation ? $operation : 'list';
if($operation == 'list') {
$rules = array();
foreach(C::t('common_credit_rule')->fetch_all_rule() as $value) {
$rules[$value['rid']] = $value;
}
if(!submitcheck('rulesubmit')) {
$anchor = in_array($_GET['anchor'], array('base', 'policytable', 'edit')) ? $_GET['anchor'] : 'base';
$current = array($anchor => 1);
showsubmenu('setting_credits', array(
array('setting_credits_base', 'setting&operation=credits&anchor=base', $current['base']),
array('setting_credits_policy', 'credits&operation=list&anchor=policytable', $current['policytable']),
));
showformheader("credits&operation=list");
showtableheader('setting_credits_policy', 'nobottom', 'id="policytable"'.($anchor != 'policytable' ? ' style="display: none"' : ''));
echo '<tr class="header"><th class="td28 nowrap">'.$lang['setting_credits_policy_name'].'</th><th class="td28 nowrap">'.$lang['setting_credits_policy_cycletype'].'</th><th class="td28 nowrap">'.$lang['setting_credits_policy_rewardnum'].'</th>';
for($i = 1; $i <= 8; $i++) {
if($_G['setting']['extcredits'][$i]) {
echo "<th class=\"td25\" id=\"policy$i\" ".($_G['setting']['extcredits'][$i] ? '' : 'disabled')." valign=\"top\">".$_G['setting']['extcredits'][$i]['title']."</th>";
}
}
echo '<th class="td25"> </th></tr>';
foreach($rules as $rid => $rule) {
$tdarr = array($rule['rulename'], $rule['rid'] ? $lang['setting_credits_policy_cycletype_'.$rule['cycletype']] : 'N/A', $rule['rid'] && $rule['cycletype'] ? $rule['rewardnum'] : 'N/A');
for($i = 1; $i <= 8; $i++) {
if($_G['setting']['extcredits'][$i]) {
array_push($tdarr, '<input name="credit['.$rule['rid'].']['.$i.']" class="txt" value="'.$rule['extcredits'.$i].'" />');
}
}
$opstr = '<a href="'.ADMINSCRIPT.'?action=credits&operation=edit&rid='.$rule['rid'].'" title="" class="act">'.$lang['edit'].'</a>';
array_push($tdarr, $opstr);
showtablerow('', array_fill(0, count($_G['setting']['extcredits']) + 4, 'class="td25"'), $tdarr);
}
showtablerow('', 'class="lineheight" colspan="9"', $lang['setting_credits_policy_comment']);
showtablefooter();
showtableheader('', 'nobottom', '');
showsetting('setting_credits_policy_mobile', 'settingnew[creditspolicymobile]', $_G['setting']['creditspolicymobile'], 'text');
showsubmit('rulesubmit');
showtablefooter();
showformfooter();
} else {
foreach($_GET['credit'] as $rid => $credits) {
$rule = array();
for($i = 1; $i <= 8; $i++) {
if($_G['setting']['extcredits'][$i]) {
$rule['extcredits'.$i] = $credits[$i];
}
}
C::t('common_credit_rule')->update($rid, $rule);
}
$settings = array(
'creditspolicymobile' => $_GET['settingnew']['creditspolicymobile'],
);
C::t('common_setting')->update_batch($settings);
updatecache(array('setting', 'creditrule'));
cpmsg('credits_update_succeed', 'action=credits&operation=list&anchor=policytable', 'succeed');
}
} elseif($operation == 'edit') {
$rid = intval($_GET['rid']);
$fid = intval($_GET['fid']);
if($rid) {
$globalrule = $ruleinfo = C::t('common_credit_rule')->fetch($rid);
if($fid) {
$query = C::t('forum_forum')->fetch_info_by_fid($fid);
$forumname = $query['name'];
$policy = $query['creditspolicy'] ? dunserialize($query['creditspolicy']) : array();
if(isset($policy[$ruleinfo['action']])) {
$ruleinfo = $policy[$ruleinfo['action']];
}
}
}
if(!submitcheck('rulesubmit')) {
if(!$rid) {
$ruleinfo['rulename'] = $lang['credits_edit_lowerlimit'];
}
if(!$fid) {
shownav('global', 'credits_edit');
showsubmenu("$lang[credits_edit] - $ruleinfo[rulename]");
} else {
if(!in_array($fid, explode(',', $globalrule['fids']))) {
for($i = 1; $i <= 8; $i++) {
$ruleinfo['extcredits'.$i] = '';
}
}
shownav('forum', 'forums_edit');
showsubmenu("$forumname - $lang[credits_edit] - $ruleinfo[rulename]");
showtips('forums_edit_tips');
}
showformheader("credits&operation=edit&rid=$rid&".($fid ? "fid=$fid" : ''));
$extra = '';
if($fid) {
$actives = $checkarr = array();
$usecustom = in_array($fid, explode(',', $globalrule['fids'])) ? 1 : 0;
$actives[$usecustom] = ' class="checked"';
$checkarr[$usecustom] = ' checked';
showtableheader('', 'nobottom');
$str = <<<EOF
<ul onmouseover="altStyle(this);">
<li$actives[1]><input type="radio" onclick="$('edit').style.display = '';" $checkarr[1] value="1" name="rule[usecustom]" class="radio"> $lang[yes]</li>
<li$actives[0]><input type="radio" onclick="$('edit').style.display = 'none';" $checkarr[0] value="0" name="rule[usecustom]" class="radio"> $lang[no]</li>
</ul>
EOF;
showsetting('setting_credits_use_custom_credit', 'usecustom', $usecustom, $str);
showtablefooter();
$extra = !$usecustom ? ' style="display:none;" ' : '';
}
showtips('setting_credits_policy_comment');
showtableheader('credits_edit', 'nobottom', 'id="edit"'.$extra);
if($rid) {
showsetting('setting_credits_policy_cycletype', array('rule[cycletype]', array(
array(0, $lang['setting_credits_policy_cycletype_0'], array('cycletimetd' => 'none', 'rewardnumtd' => 'none')),
array(1, $lang['setting_credits_policy_cycletype_1'], array('cycletimetd' => 'none', 'rewardnumtd' => '')),
array(2, $lang['setting_credits_policy_cycletype_2'], array('cycletimetd' => '', 'rewardnumtd' => '')),
array(3, $lang['setting_credits_policy_cycletype_3'], array('cycletimetd' => '', 'rewardnumtd' => '')),
array(4, $lang['setting_credits_policy_cycletype_4'], array('cycletimetd' => 'none', 'rewardnumtd' => '')),
)), $ruleinfo['cycletype'], 'mradio');
showtagheader('tbody', 'cycletimetd', in_array($ruleinfo['cycletype'], array(2, 3)), 'sub');
showsetting('credits_edit_cycletime', 'rule[cycletime]', $ruleinfo['cycletime'], 'text');
showtagfooter('tbody');
showtagheader('tbody', 'rewardnumtd', in_array($ruleinfo['cycletype'], array(1, 2, 3, 4)), 'sub');
showsetting('credits_edit_rewardnum', 'rule[rewardnum]', $ruleinfo['rewardnum'], 'text');
showtagfooter('tbody');
}
for($i = 1; $i <= 8; $i++) {
if($_G['setting']['extcredits'][$i]) {
if($rid) {
showsetting("extcredits{$i}(".$_G['setting']['extcredits'][$i]['title'].')', "rule[extcredits{$i}]", $ruleinfo['extcredits'.$i], 'text', '', 0, $fid ? '('.$lang['credits_edit_globalrule'].':'.$globalrule['extcredits'.$i].')' : '');
} else {
showsetting("extcredits{$i}(".$_G['setting']['extcredits'][$i]['title'].')', "rule[extcredits{$i}]", $_G['setting']['creditspolicy']['lowerlimit'][$i], 'text');
}
}
}
showtablefooter();
showtableheader('', 'nobottom');
showsubmit('rulesubmit');
showtablefooter();
showformfooter();
} else {
$rid = $_GET['rid'];
$rule = $_GET['rule'];
if($rid) {
if(!$rule['cycletype']) {
$rule['cycletime'] = 0;
$rule['rewardnum'] = 1;
}
$havecredit = $rule['usecustom'] ? true : false;
for($i = 1; $i <= 8; $i++) {
if(!$_G['setting']['extcredits'][$i]) {
$rule['extcredits'.$i] = 0;
}
}
foreach($rule as $key => $val) {
$rule[$key] = intval($val);
}
if($fid) {
$fids = $globalrule['fids'] ? explode(',', $globalrule['fids']) : array();
if($havecredit) {
$rule['rid'] = $rid;
$rule['fid'] = $fid;
$rule['rulename'] = $ruleinfo['rulename'];
$rule['action'] = $ruleinfo['action'];
$policy[$ruleinfo['action']] = $rule;
if(!in_array($fid, $fids)) {
$fids[] = $fid;
}
} else {
if($rule['cycletype'] != 0 && ($rule['cycletype'] == 4 && !$rule['rewardnum'])) {
require_once DISCUZ_ROOT.'./source/class/class_credit.php';
credit::deletelogbyfid($rid, $fid);
}
unset($policy[$ruleinfo['action']]);
if(in_array($fid, $fids)) {
unset($fids[array_search($fid, $fids)]);
}
}
C::t('forum_forumfield')->update($fid, array('creditspolicy' => serialize($policy)));
C::t('common_credit_rule')->update($rid, array('fids' => implode(',', $fids)));
updatecache('creditrule');
cpmsg('credits_update_succeed', 'action=forums&operation=edit&anchor=credits&fid='.$fid, 'succeed');
} else {
C::t('common_credit_rule')->update($rid, $rule);
}
updatecache('creditrule');
} else {
$lowerlimit['creditspolicy']['lowerlimit'] = array();
for($i = 1; $i <= 8; $i++) {
if($_G['setting']['extcredits'][$i]) {
$lowerlimit['creditspolicy']['lowerlimit'][$i] = (float)$rule['extcredits'.$i];
}
}
C::t('common_setting')->update('creditspolicy', $lowerlimit['creditspolicy']);
updatecache(array('setting', 'creditrule'));
}
cpmsg('credits_update_succeed', 'action=credits&operation=list&anchor=policytable', 'succeed');
}
}
?>