admincp_magics.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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: admincp_magics.php 34093 2013-10-09 05:41:18Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
  9. exit('Access Denied');
  10. }
  11. cpheader();
  12. $operation = $operation ? $operation : 'admin';
  13. if($operation == 'admin') {
  14. if(!submitcheck('magicsubmit')) {
  15. shownav('extended', 'magics', 'admin');
  16. showsubmenu('nav_magics', array(
  17. array('admin', 'magics&operation=admin', 1),
  18. array('nav_magics_confer', 'members&operation=confermagic', 0)
  19. ));
  20. showtips('magics_tips');
  21. $settings = C::t('common_setting')->fetch_all(array('magicstatus', 'magicdiscount'));
  22. showformheader('magics&operation=admin');
  23. showtableheader();
  24. showsetting('magics_config_open', 'settingsnew[magicstatus]', $settings['magicstatus'], 'radio');
  25. showsetting('magics_config_discount', 'settingsnew[magicdiscount]', $settings['magicdiscount'], 'text');
  26. showtablefooter();
  27. showtableheader('magics_list', 'fixpadding');
  28. $newmagics = getmagics();
  29. 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'));
  30. foreach(C::t('common_magic')->fetch_all_data() as $magic) {
  31. $magic['credit'] = $magic['credit'] ? $magic['credit'] : $_G['setting']['creditstransextra'][3];
  32. $credits = '<select name="credit['.$magic['magicid'].']">';
  33. foreach($_G['setting']['extcredits'] as $i => $extcredit) {
  34. $credits .= '<option value="'.$i.'" '.($i == $magic['credit'] ? 'selected' : '').'>'.$extcredit['title'].'</option>';
  35. }
  36. $credits .= '</select>';
  37. $magictype = $lang['magics_type_'.$magic['type']];
  38. $eidentifier = explode(':', $magic['identifier']);
  39. showtablerow('', array('class="td25"', 'class="td25"', 'class="td25"', 'class="td28"', 'class="td28"', 'class="td28"', 'class="td28"', '', ''), array(
  40. "<input type=\"checkbox\" class=\"checkbox\" name=\"delete[]\" value=\"$magic[magicid]\">",
  41. "<input type=\"text\" class=\"txt\" name=\"displayorder[$magic[magicid]]\" value=\"$magic[displayorder]\">",
  42. "<input type=\"checkbox\" class=\"checkbox\" name=\"available[$magic[magicid]]\" value=\"1\" ".($magic['available'] ? 'checked' : '').">",
  43. "<input type=\"text\" class=\"txt\" style=\"width:80px\" name=\"name[$magic[magicid]]\" value=\"$magic[name]\">".
  44. (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" />' : '')
  45. : (file_exists(DISCUZ_ROOT.'./static/image/magic/'.$magic['identifier'].'.small.gif') ? '<img class="vmiddle" src="static/image/magic/'.$magic['identifier'].'.small.gif" />' : '')),
  46. "<input type=\"text\" class=\"txt\" name=\"price[$magic[magicid]]\" value=\"$magic[price]\">".$credits,
  47. "<input type=\"text\" class=\"txt\" name=\"num[$magic[magicid]]\" value=\"$magic[num]\">".
  48. ($magic['supplytype'] ? '/ '.$magic['supplynum'].' / '.$lang['magic_suppytype_'.$magic['supplytype']] : ''),
  49. "<input type=\"text\" class=\"txt\" name=\"weight[$magic[magicid]]\" value=\"$magic[weight]\"><input type=\"hidden\" name=\"identifier[$magic[magicid]]\" value=\"$magic[identifier]\">",
  50. "<a href=\"".ADMINSCRIPT."?action=magics&operation=edit&magicid=$magic[magicid]\" class=\"act\">$lang[detail]</a>"
  51. ));
  52. unset($newmagics[$magic[identifier]]);
  53. }
  54. foreach($newmagics as $newmagic) {
  55. $credits = '<select name="newcredit['.$newmagic['class'].']">';
  56. foreach($_G['setting']['extcredits'] as $i => $extcredit) {
  57. $credits .= '<option value="'.$i.'">'.$extcredit['title'].'</option>';
  58. }
  59. $credits .= '</select>';
  60. $eclass = explode(':', $newmagic['class']);
  61. showtablerow('', array('class="td25"', 'class="td25"', 'class="td25"', 'class="td28"', 'class="td28"', 'class="td28"', 'class="td28"', '', ''), array(
  62. '',
  63. "<input type=\"text\" class=\"txt\" name=\"newdisplayorder[$newmagic[class]]\" value=\"0\">",
  64. "<input type=\"checkbox\" class=\"checkbox\" name=\"newavailable[$newmagic[class]]\" value=\"1\">",
  65. "<input type=\"text\" class=\"txt\" style=\"width:80px\" name=\"newname[$newmagic[class]]\" value=\"$newmagic[name]\">".
  66. (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" />' : '')
  67. : (file_exists(DISCUZ_ROOT.'./static/image/magic/'.$newmagic['class'].'.small.gif') ? '<img class="vmiddle" src="static/image/magic/'.$newmagic['class'].'.small.gif" />' : '')).
  68. "<input type=\"hidden\" name=\"newdesc[$newmagic[class]]\" value=\"$newmagic[desc]\" />".
  69. "<input type=\"hidden\" name=\"newuseevent[$newmagic[class]]\" value=\"$newmagic[useevent]\" />",
  70. "<input type=\"text\" class=\"txt\" name=\"newprice[$newmagic[class]]\" value=\"$newmagic[price]\">".$credits,
  71. "<input type=\"text\" class=\"txt\" name=\"newnum[$newmagic[class]]\" value=\"0\">",
  72. "<input type=\"text\" class=\"txt\" name=\"newweight[$newmagic[class]]\" value=\"$newmagic[weight]\">",
  73. '<font color="#F00">New!</font>'
  74. ));
  75. }
  76. showsubmit('magicsubmit', 'submit', 'del', '&nbsp;&nbsp;<input type="checkbox" onclick="checkAll(\'prefix\', this.form, \'available\', \'availablechk1\')" class="checkbox" id="availablechk1" name="availablechk1">'.cplang('available'));
  77. showtablefooter();
  78. showformfooter();
  79. } else {
  80. if(is_array($_GET['settingsnew'])) {
  81. C::t('common_setting')->update_batch(array('magicstatus'=> $_GET['settingsnew']['magicstatus'], 'magicdiscount' => $_GET['settingsnew']['magicdiscount']));
  82. }
  83. if($ids = dimplode($_GET['delete'])) {
  84. C::t('common_magic')->delete($_GET['delete']);
  85. C::t('common_member_magic')->delete('', $_GET['delete']);
  86. C::t('common_magiclog')->delete_by_magicid($_GET['delete']);
  87. }
  88. if(is_array($_GET['name'])) {
  89. foreach($_GET['name'] as $id => $val) {
  90. if(!is_array($_GET['identifier']) ||
  91. !is_array($_GET['displayorder']) || !is_array($_GET['credit']) ||
  92. !is_array($_GET['price']) || !is_array($_GET['num']) ||
  93. !is_array($_GET['weight']) || !preg_match('/^[\w:]+$/', $_GET['identifier'][$id])) {
  94. continue;
  95. }
  96. C::t('common_magic')->update($id, array(
  97. 'available' => $_GET['available'][$id],
  98. 'name' => $val,
  99. 'identifier' => $_GET['identifier'][$id],
  100. 'displayorder' => $_GET['displayorder'][$id],
  101. 'credit' => $_GET['credit'][$id],
  102. 'price' => $_GET['price'][$id],
  103. 'num' => $_GET['num'][$id],
  104. 'weight' => $_GET['weight'][$id]
  105. ));
  106. }
  107. }
  108. if(is_array($_GET['newname'])) {
  109. foreach($_GET['newname'] as $identifier => $name) {
  110. $data = array(
  111. 'name' => $name,
  112. 'useevent' => $_GET['newuseevent'][$identifier],
  113. 'identifier' => $identifier,
  114. 'available' => $_GET['newavailable'][$identifier],
  115. 'description' => $_GET['newdesc'][$identifier],
  116. 'displayorder' => $_GET['newdisplayorder'][$identifier],
  117. 'credit' => $_GET['newcredit'][$identifier],
  118. 'price' => $_GET['newprice'][$identifier],
  119. 'num' => $_GET['newnum'][$identifier],
  120. 'weight' => $_GET['newweight'][$identifier],
  121. );
  122. C::t('common_magic')->insert($data);
  123. }
  124. }
  125. updatecache(array('setting', 'magics'));
  126. cpmsg('magics_data_succeed', 'action=magics&operation=admin', 'succeed');
  127. }
  128. } elseif($operation == 'edit') {
  129. $magicid = intval($_GET['magicid']);
  130. $magic = C::t('common_magic')->fetch($magicid);
  131. if(!submitcheck('magiceditsubmit')) {
  132. $magicperm = dunserialize($magic['magicperm']);
  133. $groups = $forums = array();
  134. foreach(C::t('common_usergroup')->range() as $group) {
  135. $groups[$group['groupid']] = $group['grouptitle'];
  136. }
  137. $typeselect = array($magic['type'] => 'selected');
  138. shownav('extended', 'magics', 'admin');
  139. showsubmenu('nav_magics', array(
  140. array('admin', 'magics&operation=admin', 0),
  141. array('nav_magics_confer', 'members&operation=confermagic', 0)
  142. ));
  143. echo '<br />';
  144. $eidentifier = explode(':', $magic['identifier']);
  145. if(count($eidentifier) > 1 && preg_match('/^[\w\_:]+$/', $magic['identifier'])) {
  146. include_once DISCUZ_ROOT.'./source/plugin/'.$eidentifier[0].'/magic/magic_'.$eidentifier[1].'.php';
  147. $magicclass = 'magic_'.$eidentifier[1];
  148. } else {
  149. require_once libfile('magic/'.$magic['identifier'], 'class');
  150. $magicclass = 'magic_'.$magic['identifier'];
  151. }
  152. $magicclass = new $magicclass;
  153. $magicsetting = $magicclass->getsetting($magicperm);
  154. echo '<div class="colorbox"><h4>'.lang('magic/'.$magic['identifier'], $magicclass->name).'</h4>'.
  155. '<table cellspacing="0" cellpadding="3"><tr><td>'.
  156. (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" />' : '')
  157. : (file_exists(DISCUZ_ROOT.'./static/image/magic/'.$magic['identifier'].'.gif') ? '<img src="static/image/magic/'.$magic['identifier'].'.gif" />' : '')).
  158. '</td><td valign="top">'.lang('magic/'.$magic['identifier'], $magicclass->description).'</td></tr></table>'.
  159. '<div style="width:95%" align="right">'.lang('magic/'.$magic['identifier'], $magicclass->copyright).'</div></div>';
  160. $credits = array();
  161. foreach($_G['setting']['extcredits'] as $i => $extcredit) {
  162. $credits[] = array($i, $extcredit['title']);
  163. }
  164. showformheader('magics&operation=edit&magicid='.$magicid);
  165. showtableheader();
  166. showtitle($lang['magics_edit'].' - '.$magic['name'].'('.$magic['identifier'].')');
  167. showsetting('magics_edit_name', 'namenew', $magic['name'], 'text');
  168. showsetting('magics_edit_credit', array('creditnew', $credits), $magic['credit'], 'select');
  169. showsetting('magics_edit_price', 'pricenew', $magic['price'], 'text');
  170. showsetting('magics_edit_num', 'numnew', $magic['num'], 'text');
  171. showsetting('magics_edit_supplynum', 'supplynumnew', $magic['supplynum'], 'text');
  172. showsetting('magics_edit_weight', 'weightnew', $magic['weight'], 'text');
  173. showsetting('magics_edit_supplytype', array('supplytypenew', array(
  174. array(0, $lang['magics_goods_stack_none']),
  175. array(1, $lang['magics_goods_stack_day']),
  176. array(2, $lang['magics_goods_stack_week']),
  177. array(3, $lang['magics_goods_stack_month']),
  178. )), $magic['supplytype'], 'mradio');
  179. showsetting('magics_edit_useperoid', array('useperoidnew', array(
  180. array(0, $lang['magics_edit_useperoid_none']),
  181. array(1, $lang['magics_edit_useperoid_day']),
  182. array(4, $lang['magics_edit_useperoid_24hr']),
  183. array(2, $lang['magics_edit_useperoid_week']),
  184. array(3, $lang['magics_edit_useperoid_month']),
  185. )), $magic['useperoid'], 'mradio');
  186. showsetting('magics_edit_usenum', 'usenumnew', $magic['usenum'], 'text');
  187. showsetting('magics_edit_description', 'descriptionnew', $magic['description'], 'textarea');
  188. if(is_array($magicsetting)) {
  189. foreach($magicsetting as $settingvar => $setting) {
  190. if(!empty($setting['value']) && is_array($setting['value'])) {
  191. foreach($setting['value'] as $k => $v) {
  192. $setting['value'][$k][1] = lang('magic/'.$magic['identifier'], $setting['value'][$k][1]);
  193. }
  194. }
  195. $varname = in_array($setting['type'], array('mradio', 'mcheckbox', 'select', 'mselect')) ?
  196. ($setting['type'] == 'mselect' ? array('perm['.$settingvar.'][]', $setting['value']) : array('perm['.$settingvar.']', $setting['value']))
  197. : 'perm['.$settingvar.']';
  198. $value = $magicperm[$settingvar] != '' ? $magicperm[$settingvar] : $setting['default'];
  199. $comment = lang('magic/'.$magic['identifier'], $setting['title'].'_comment');
  200. $comment = $comment != $setting['title'].'_comment' ? $comment : '';
  201. showsetting(lang('magic/'.$magic['identifier'], $setting['title']).':', $varname, $value, $setting['type'], '', 0, $comment);
  202. }
  203. }
  204. showtitle('magics_edit_perm');
  205. 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>');
  206. showtablerow('', 'colspan="2"', mcheckbox('usergroupsperm', $groups, explode("\t", $magicperm['usergroups'])));
  207. if(!empty($magicclass->targetgroupperm)) {
  208. 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>');
  209. showtablerow('', 'colspan="2"', mcheckbox('targetgroupsperm', $groups, explode("\t", $magicperm['targetgroups'])));
  210. }
  211. showsubmit('magiceditsubmit');
  212. showtablefooter();
  213. showformfooter();
  214. } else {
  215. $namenew = dhtmlspecialchars(trim($_GET['namenew']));
  216. $identifiernew = dhtmlspecialchars(trim(strtoupper($_GET['identifiernew'])));
  217. $descriptionnew = dhtmlspecialchars($_GET['descriptionnew']);
  218. $availablenew = !$identifiernew ? 0 : 1;
  219. $magicperm['usergroups'] = is_array($_GET['usergroupsperm']) && !empty($_GET['usergroupsperm']) ? "\t".implode("\t",$_GET['usergroupsperm'])."\t" : '';
  220. $magicperm['targetgroups'] = is_array($_GET['targetgroupsperm']) && !empty($_GET['targetgroupsperm']) ? "\t".implode("\t",$_GET['targetgroupsperm'])."\t" : '';
  221. $eidentifier = explode(':', $magic['identifier']);
  222. if(count($eidentifier) > 1 && preg_match('/^[\w\_:]+$/', $magic['identifier'])) {
  223. include_once DISCUZ_ROOT.'./source/plugin/'.$eidentifier[0].'/magic/magic_'.$eidentifier[1].'.php';
  224. $magicclass = 'magic_'.$eidentifier[1];
  225. } else {
  226. require_once libfile('magic/'.$magic['identifier'], 'class');
  227. $magicclass = 'magic_'.$magic['identifier'];
  228. }
  229. $magicclass = new $magicclass;
  230. $magicclass->setsetting($magicperm, $_GET['perm']);
  231. $magicpermnew = addslashes(serialize($magicperm));
  232. $supplytypenew = intval($_GET['supplytypenew']);
  233. $supplynumnew = $_GET['supplytypenew'] ? intval($_GET['supplynumnew']) : 0;
  234. $usenumnew = intval($_GET['usenumnew']);
  235. $useperoidnew = $_GET['useperoidnew'] ? intval($_GET['useperoidnew']) : 0;
  236. $creditnew = intval($_GET['creditnew']);
  237. if(!$namenew) {
  238. cpmsg('magics_parameter_invalid', '', 'error');
  239. }
  240. if(C::t('common_magic')->check_identifier($identifiernew, $magicid)) {
  241. cpmsg('magics_identifier_invalid', '', 'error');
  242. }
  243. C::t('common_magic')->update($magicid, array(
  244. 'name' => $namenew,
  245. 'description' => $descriptionnew,
  246. 'price' => $_GET['pricenew'],
  247. 'num' => $_GET['numnew'],
  248. 'supplytype' => $supplytypenew,
  249. 'supplynum' => $supplynumnew,
  250. 'useperoid' => $useperoidnew,
  251. 'usenum' => $usenumnew,
  252. 'weight' => $_GET['weightnew'],
  253. 'magicperm' => $magicpermnew,
  254. 'credit' => $creditnew
  255. ));
  256. updatecache(array('setting', 'magics'));
  257. cpmsg('magics_data_succeed', 'action=magics&operation=admin', 'succeed');
  258. }
  259. }
  260. function getmagics() {
  261. global $_G;
  262. $checkdirs = array_merge(array(''), $_G['setting']['plugins']['available']);
  263. $magics = array();
  264. foreach($checkdirs as $key) {
  265. if($key) {
  266. $dir = DISCUZ_ROOT.'./source/plugin/'.$key.'/magic';
  267. } else {
  268. $dir = DISCUZ_ROOT.'./source/class/magic';
  269. }
  270. if(!file_exists($dir)) {
  271. continue;
  272. }
  273. $magicdir = dir($dir);
  274. while($entry = $magicdir->read()) {
  275. if(!in_array($entry, array('.', '..')) && preg_match("/^magic\_[\w\.]+$/", $entry) && substr($entry, -4) == '.php' && strlen($entry) < 30 && is_file($dir.'/'.$entry)) {
  276. @include_once $dir.'/'.$entry;
  277. $magicclass = substr($entry, 0, -4);
  278. if(class_exists($magicclass)) {
  279. $magic = new $magicclass();
  280. $script = substr($magicclass, 6);
  281. $script = ($key ? $key.':' : '').$script;
  282. $magics[$script] = array(
  283. 'class' => $script,
  284. 'name' => lang('magic/'.$script, $magic->name),
  285. 'desc' => lang('magic/'.$script, $magic->description),
  286. 'price' => $magic->price,
  287. 'weight' => $magic->weight,
  288. 'useevent' => !empty($magic->useevent) ? $magic->useevent : 0,
  289. 'version' => $magic->version,
  290. 'copyright' => lang('magic/'.$script, $magic->copyright),
  291. 'filemtime' => @filemtime($dir.'/'.$entry)
  292. );
  293. }
  294. }
  295. }
  296. }
  297. uasort($magics, 'filemtimesort');
  298. return $magics;
  299. }
  300. ?>