admincp_magics.php
16.5 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: admincp_magics.php 34093 2013-10-09 05:41:18Z nemohou $
*/
if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
exit('Access Denied');
}
cpheader();
$operation = $operation ? $operation : 'admin';
if($operation == 'admin') {
if(!submitcheck('magicsubmit')) {
shownav('extended', 'magics', 'admin');
showsubmenu('nav_magics', array(
array('admin', 'magics&operation=admin', 1),
array('nav_magics_confer', 'members&operation=confermagic', 0)
));
showtips('magics_tips');
$settings = C::t('common_setting')->fetch_all(array('magicstatus', 'magicdiscount'));
showformheader('magics&operation=admin');
showtableheader();
showsetting('magics_config_open', 'settingsnew[magicstatus]', $settings['magicstatus'], 'radio');
showsetting('magics_config_discount', 'settingsnew[magicdiscount]', $settings['magicdiscount'], 'text');
showtablefooter();
showtableheader('magics_list', 'fixpadding');
$newmagics = getmagics();
showsubtitle(array('', 'display_order', '<input type="checkbox" onclick="checkAll(\'prefix\', this.form, \'available\', \'availablechk\')" class="checkbox" id="availablechk" name="availablechk">'.cplang('available'), 'name', $lang['price'], $lang['magics_num'], 'weight'));
foreach(C::t('common_magic')->fetch_all_data() as $magic) {
$magic['credit'] = $magic['credit'] ? $magic['credit'] : $_G['setting']['creditstransextra'][3];
$credits = '<select name="credit['.$magic['magicid'].']">';
foreach($_G['setting']['extcredits'] as $i => $extcredit) {
$credits .= '<option value="'.$i.'" '.($i == $magic['credit'] ? 'selected' : '').'>'.$extcredit['title'].'</option>';
}
$credits .= '</select>';
$magictype = $lang['magics_type_'.$magic['type']];
$eidentifier = explode(':', $magic['identifier']);
showtablerow('', array('class="td25"', 'class="td25"', 'class="td25"', 'class="td28"', 'class="td28"', 'class="td28"', 'class="td28"', '', ''), array(
"<input type=\"checkbox\" class=\"checkbox\" name=\"delete[]\" value=\"$magic[magicid]\">",
"<input type=\"text\" class=\"txt\" name=\"displayorder[$magic[magicid]]\" value=\"$magic[displayorder]\">",
"<input type=\"checkbox\" class=\"checkbox\" name=\"available[$magic[magicid]]\" value=\"1\" ".($magic['available'] ? 'checked' : '').">",
"<input type=\"text\" class=\"txt\" style=\"width:80px\" name=\"name[$magic[magicid]]\" value=\"$magic[name]\">".
(count($eidentifier) > 1 ? (file_exists(DISCUZ_ROOT.'./source/plugin/'.$eidentifier[0].'/magic/magic_'.$eidentifier[1].'.small.gif') ? '<img class="vmiddle" src="source/plugin/'.$eidentifier[0].'/magic/magic_'.$eidentifier[1].'.small.gif" />' : '')
: (file_exists(DISCUZ_ROOT.'./static/image/magic/'.$magic['identifier'].'.small.gif') ? '<img class="vmiddle" src="static/image/magic/'.$magic['identifier'].'.small.gif" />' : '')),
"<input type=\"text\" class=\"txt\" name=\"price[$magic[magicid]]\" value=\"$magic[price]\">".$credits,
"<input type=\"text\" class=\"txt\" name=\"num[$magic[magicid]]\" value=\"$magic[num]\">".
($magic['supplytype'] ? '/ '.$magic['supplynum'].' / '.$lang['magic_suppytype_'.$magic['supplytype']] : ''),
"<input type=\"text\" class=\"txt\" name=\"weight[$magic[magicid]]\" value=\"$magic[weight]\"><input type=\"hidden\" name=\"identifier[$magic[magicid]]\" value=\"$magic[identifier]\">",
"<a href=\"".ADMINSCRIPT."?action=magics&operation=edit&magicid=$magic[magicid]\" class=\"act\">$lang[detail]</a>"
));
unset($newmagics[$magic[identifier]]);
}
foreach($newmagics as $newmagic) {
$credits = '<select name="newcredit['.$newmagic['class'].']">';
foreach($_G['setting']['extcredits'] as $i => $extcredit) {
$credits .= '<option value="'.$i.'">'.$extcredit['title'].'</option>';
}
$credits .= '</select>';
$eclass = explode(':', $newmagic['class']);
showtablerow('', array('class="td25"', 'class="td25"', 'class="td25"', 'class="td28"', 'class="td28"', 'class="td28"', 'class="td28"', '', ''), array(
'',
"<input type=\"text\" class=\"txt\" name=\"newdisplayorder[$newmagic[class]]\" value=\"0\">",
"<input type=\"checkbox\" class=\"checkbox\" name=\"newavailable[$newmagic[class]]\" value=\"1\">",
"<input type=\"text\" class=\"txt\" style=\"width:80px\" name=\"newname[$newmagic[class]]\" value=\"$newmagic[name]\">".
(count($eclass) > 1 ? (file_exists(DISCUZ_ROOT.'./source/plugin/'.$eclass[0].'/magic/magic_'.$eclass[1].'.small.gif') ? '<img class="vmiddle" src="source/plugin/'.$eclass[0].'/magic/magic_'.$eclass[1].'.small.gif" />' : '')
: (file_exists(DISCUZ_ROOT.'./static/image/magic/'.$newmagic['class'].'.small.gif') ? '<img class="vmiddle" src="static/image/magic/'.$newmagic['class'].'.small.gif" />' : '')).
"<input type=\"hidden\" name=\"newdesc[$newmagic[class]]\" value=\"$newmagic[desc]\" />".
"<input type=\"hidden\" name=\"newuseevent[$newmagic[class]]\" value=\"$newmagic[useevent]\" />",
"<input type=\"text\" class=\"txt\" name=\"newprice[$newmagic[class]]\" value=\"$newmagic[price]\">".$credits,
"<input type=\"text\" class=\"txt\" name=\"newnum[$newmagic[class]]\" value=\"0\">",
"<input type=\"text\" class=\"txt\" name=\"newweight[$newmagic[class]]\" value=\"$newmagic[weight]\">",
'<font color="#F00">New!</font>'
));
}
showsubmit('magicsubmit', 'submit', 'del', ' <input type="checkbox" onclick="checkAll(\'prefix\', this.form, \'available\', \'availablechk1\')" class="checkbox" id="availablechk1" name="availablechk1">'.cplang('available'));
showtablefooter();
showformfooter();
} else {
if(is_array($_GET['settingsnew'])) {
C::t('common_setting')->update_batch(array('magicstatus'=> $_GET['settingsnew']['magicstatus'], 'magicdiscount' => $_GET['settingsnew']['magicdiscount']));
}
if($ids = dimplode($_GET['delete'])) {
C::t('common_magic')->delete($_GET['delete']);
C::t('common_member_magic')->delete('', $_GET['delete']);
C::t('common_magiclog')->delete_by_magicid($_GET['delete']);
}
if(is_array($_GET['name'])) {
foreach($_GET['name'] as $id => $val) {
if(!is_array($_GET['identifier']) ||
!is_array($_GET['displayorder']) || !is_array($_GET['credit']) ||
!is_array($_GET['price']) || !is_array($_GET['num']) ||
!is_array($_GET['weight']) || !preg_match('/^[\w:]+$/', $_GET['identifier'][$id])) {
continue;
}
C::t('common_magic')->update($id, array(
'available' => $_GET['available'][$id],
'name' => $val,
'identifier' => $_GET['identifier'][$id],
'displayorder' => $_GET['displayorder'][$id],
'credit' => $_GET['credit'][$id],
'price' => $_GET['price'][$id],
'num' => $_GET['num'][$id],
'weight' => $_GET['weight'][$id]
));
}
}
if(is_array($_GET['newname'])) {
foreach($_GET['newname'] as $identifier => $name) {
$data = array(
'name' => $name,
'useevent' => $_GET['newuseevent'][$identifier],
'identifier' => $identifier,
'available' => $_GET['newavailable'][$identifier],
'description' => $_GET['newdesc'][$identifier],
'displayorder' => $_GET['newdisplayorder'][$identifier],
'credit' => $_GET['newcredit'][$identifier],
'price' => $_GET['newprice'][$identifier],
'num' => $_GET['newnum'][$identifier],
'weight' => $_GET['newweight'][$identifier],
);
C::t('common_magic')->insert($data);
}
}
updatecache(array('setting', 'magics'));
cpmsg('magics_data_succeed', 'action=magics&operation=admin', 'succeed');
}
} elseif($operation == 'edit') {
$magicid = intval($_GET['magicid']);
$magic = C::t('common_magic')->fetch($magicid);
if(!submitcheck('magiceditsubmit')) {
$magicperm = dunserialize($magic['magicperm']);
$groups = $forums = array();
foreach(C::t('common_usergroup')->range() as $group) {
$groups[$group['groupid']] = $group['grouptitle'];
}
$typeselect = array($magic['type'] => 'selected');
shownav('extended', 'magics', 'admin');
showsubmenu('nav_magics', array(
array('admin', 'magics&operation=admin', 0),
array('nav_magics_confer', 'members&operation=confermagic', 0)
));
echo '<br />';
$eidentifier = explode(':', $magic['identifier']);
if(count($eidentifier) > 1 && preg_match('/^[\w\_:]+$/', $magic['identifier'])) {
include_once DISCUZ_ROOT.'./source/plugin/'.$eidentifier[0].'/magic/magic_'.$eidentifier[1].'.php';
$magicclass = 'magic_'.$eidentifier[1];
} else {
require_once libfile('magic/'.$magic['identifier'], 'class');
$magicclass = 'magic_'.$magic['identifier'];
}
$magicclass = new $magicclass;
$magicsetting = $magicclass->getsetting($magicperm);
echo '<div class="colorbox"><h4>'.lang('magic/'.$magic['identifier'], $magicclass->name).'</h4>'.
'<table cellspacing="0" cellpadding="3"><tr><td>'.
(count($eidentifier) > 1 ? (file_exists(DISCUZ_ROOT.'./source/plugin/'.$eidentifier[0].'/magic/magic_'.$eidentifier[1].'.gif') ? '<img src="source/plugin/'.$eidentifier[0].'/magic/magic_'.$eidentifier[1].'.gif" />' : '')
: (file_exists(DISCUZ_ROOT.'./static/image/magic/'.$magic['identifier'].'.gif') ? '<img src="static/image/magic/'.$magic['identifier'].'.gif" />' : '')).
'</td><td valign="top">'.lang('magic/'.$magic['identifier'], $magicclass->description).'</td></tr></table>'.
'<div style="width:95%" align="right">'.lang('magic/'.$magic['identifier'], $magicclass->copyright).'</div></div>';
$credits = array();
foreach($_G['setting']['extcredits'] as $i => $extcredit) {
$credits[] = array($i, $extcredit['title']);
}
showformheader('magics&operation=edit&magicid='.$magicid);
showtableheader();
showtitle($lang['magics_edit'].' - '.$magic['name'].'('.$magic['identifier'].')');
showsetting('magics_edit_name', 'namenew', $magic['name'], 'text');
showsetting('magics_edit_credit', array('creditnew', $credits), $magic['credit'], 'select');
showsetting('magics_edit_price', 'pricenew', $magic['price'], 'text');
showsetting('magics_edit_num', 'numnew', $magic['num'], 'text');
showsetting('magics_edit_supplynum', 'supplynumnew', $magic['supplynum'], 'text');
showsetting('magics_edit_weight', 'weightnew', $magic['weight'], 'text');
showsetting('magics_edit_supplytype', array('supplytypenew', array(
array(0, $lang['magics_goods_stack_none']),
array(1, $lang['magics_goods_stack_day']),
array(2, $lang['magics_goods_stack_week']),
array(3, $lang['magics_goods_stack_month']),
)), $magic['supplytype'], 'mradio');
showsetting('magics_edit_useperoid', array('useperoidnew', array(
array(0, $lang['magics_edit_useperoid_none']),
array(1, $lang['magics_edit_useperoid_day']),
array(4, $lang['magics_edit_useperoid_24hr']),
array(2, $lang['magics_edit_useperoid_week']),
array(3, $lang['magics_edit_useperoid_month']),
)), $magic['useperoid'], 'mradio');
showsetting('magics_edit_usenum', 'usenumnew', $magic['usenum'], 'text');
showsetting('magics_edit_description', 'descriptionnew', $magic['description'], 'textarea');
if(is_array($magicsetting)) {
foreach($magicsetting as $settingvar => $setting) {
if(!empty($setting['value']) && is_array($setting['value'])) {
foreach($setting['value'] as $k => $v) {
$setting['value'][$k][1] = lang('magic/'.$magic['identifier'], $setting['value'][$k][1]);
}
}
$varname = in_array($setting['type'], array('mradio', 'mcheckbox', 'select', 'mselect')) ?
($setting['type'] == 'mselect' ? array('perm['.$settingvar.'][]', $setting['value']) : array('perm['.$settingvar.']', $setting['value']))
: 'perm['.$settingvar.']';
$value = $magicperm[$settingvar] != '' ? $magicperm[$settingvar] : $setting['default'];
$comment = lang('magic/'.$magic['identifier'], $setting['title'].'_comment');
$comment = $comment != $setting['title'].'_comment' ? $comment : '';
showsetting(lang('magic/'.$magic['identifier'], $setting['title']).':', $varname, $value, $setting['type'], '', 0, $comment);
}
}
showtitle('magics_edit_perm');
showtablerow('', 'colspan="2" class="td27"', $lang['magics_edit_usergroupperm'].':<input class="checkbox" type="checkbox" name="chkall1" onclick="checkAll(\'prefix\', this.form, \'usergroupsperm\', \'chkall1\', true)" id="chkall1" /><label for="chkall1"> '.cplang('select_all').'</label>');
showtablerow('', 'colspan="2"', mcheckbox('usergroupsperm', $groups, explode("\t", $magicperm['usergroups'])));
if(!empty($magicclass->targetgroupperm)) {
showtablerow('', 'colspan="2" class="td27"', $lang['magics_edit_targetgroupperm'].':<input class="checkbox" type="checkbox" name="chkall2" onclick="checkAll(\'prefix\', this.form, \'targetgroupsperm\', \'chkall2\', true)" id="chkall2" /><label for="chkall2"> '.cplang('select_all').'</label>');
showtablerow('', 'colspan="2"', mcheckbox('targetgroupsperm', $groups, explode("\t", $magicperm['targetgroups'])));
}
showsubmit('magiceditsubmit');
showtablefooter();
showformfooter();
} else {
$namenew = dhtmlspecialchars(trim($_GET['namenew']));
$identifiernew = dhtmlspecialchars(trim(strtoupper($_GET['identifiernew'])));
$descriptionnew = dhtmlspecialchars($_GET['descriptionnew']);
$availablenew = !$identifiernew ? 0 : 1;
$magicperm['usergroups'] = is_array($_GET['usergroupsperm']) && !empty($_GET['usergroupsperm']) ? "\t".implode("\t",$_GET['usergroupsperm'])."\t" : '';
$magicperm['targetgroups'] = is_array($_GET['targetgroupsperm']) && !empty($_GET['targetgroupsperm']) ? "\t".implode("\t",$_GET['targetgroupsperm'])."\t" : '';
$eidentifier = explode(':', $magic['identifier']);
if(count($eidentifier) > 1 && preg_match('/^[\w\_:]+$/', $magic['identifier'])) {
include_once DISCUZ_ROOT.'./source/plugin/'.$eidentifier[0].'/magic/magic_'.$eidentifier[1].'.php';
$magicclass = 'magic_'.$eidentifier[1];
} else {
require_once libfile('magic/'.$magic['identifier'], 'class');
$magicclass = 'magic_'.$magic['identifier'];
}
$magicclass = new $magicclass;
$magicclass->setsetting($magicperm, $_GET['perm']);
$magicpermnew = addslashes(serialize($magicperm));
$supplytypenew = intval($_GET['supplytypenew']);
$supplynumnew = $_GET['supplytypenew'] ? intval($_GET['supplynumnew']) : 0;
$usenumnew = intval($_GET['usenumnew']);
$useperoidnew = $_GET['useperoidnew'] ? intval($_GET['useperoidnew']) : 0;
$creditnew = intval($_GET['creditnew']);
if(!$namenew) {
cpmsg('magics_parameter_invalid', '', 'error');
}
if(C::t('common_magic')->check_identifier($identifiernew, $magicid)) {
cpmsg('magics_identifier_invalid', '', 'error');
}
C::t('common_magic')->update($magicid, array(
'name' => $namenew,
'description' => $descriptionnew,
'price' => $_GET['pricenew'],
'num' => $_GET['numnew'],
'supplytype' => $supplytypenew,
'supplynum' => $supplynumnew,
'useperoid' => $useperoidnew,
'usenum' => $usenumnew,
'weight' => $_GET['weightnew'],
'magicperm' => $magicpermnew,
'credit' => $creditnew
));
updatecache(array('setting', 'magics'));
cpmsg('magics_data_succeed', 'action=magics&operation=admin', 'succeed');
}
}
function getmagics() {
global $_G;
$checkdirs = array_merge(array(''), $_G['setting']['plugins']['available']);
$magics = array();
foreach($checkdirs as $key) {
if($key) {
$dir = DISCUZ_ROOT.'./source/plugin/'.$key.'/magic';
} else {
$dir = DISCUZ_ROOT.'./source/class/magic';
}
if(!file_exists($dir)) {
continue;
}
$magicdir = dir($dir);
while($entry = $magicdir->read()) {
if(!in_array($entry, array('.', '..')) && preg_match("/^magic\_[\w\.]+$/", $entry) && substr($entry, -4) == '.php' && strlen($entry) < 30 && is_file($dir.'/'.$entry)) {
@include_once $dir.'/'.$entry;
$magicclass = substr($entry, 0, -4);
if(class_exists($magicclass)) {
$magic = new $magicclass();
$script = substr($magicclass, 6);
$script = ($key ? $key.':' : '').$script;
$magics[$script] = array(
'class' => $script,
'name' => lang('magic/'.$script, $magic->name),
'desc' => lang('magic/'.$script, $magic->description),
'price' => $magic->price,
'weight' => $magic->weight,
'useevent' => !empty($magic->useevent) ? $magic->useevent : 0,
'version' => $magic->version,
'copyright' => lang('magic/'.$script, $magic->copyright),
'filemtime' => @filemtime($dir.'/'.$entry)
);
}
}
}
}
uasort($magics, 'filemtimesort');
return $magics;
}
?>