PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/source/include/spacecp/spacecp_usergroup.php

https://github.com/jinbo51/DiscuzX
PHP | 368 lines | 320 code | 42 blank | 6 comment | 120 complexity | 793ffdec40bc2d1e551216308620a24c MD5 | raw file
Possible License(s): BSD-3-Clause
  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: spacecp_usergroup.php 32739 2013-03-05 08:16:30Z monkey $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. if($_G['inajax'] && $_GET['showextgroups']) {
  12. require_once libfile('function/forumlist');
  13. loadcache('usergroups');
  14. $extgroupids = $_G['member']['extgroupids'] ? explode("\t", $_G['member']['extgroupids']) : array();
  15. $group = array();
  16. if($_G['uid'] && $_G['group']['grouptype'] == 'member' && $_G['group']['groupcreditslower'] != 999999999) {
  17. $group['upgradecredit'] = $_G['group']['groupcreditslower'] - $_G['member']['credits'];
  18. $group['upgradeprogress'] = 100 - ceil($group['upgradecredit'] / ($_G['group']['groupcreditslower'] - $_G['group']['groupcreditshigher']) * 100);
  19. $group['upgradeprogress'] = max($group['upgradeprogress'], 2);
  20. }
  21. include template('forum/viewthread_profile_node');
  22. include template('common/extgroups');
  23. exit;
  24. }
  25. $do = in_array($_GET['do'], array('buy', 'exit', 'switch', 'list', 'forum', 'expiry')) ? trim($_GET['do']) : 'usergroup';
  26. $extgroupids = $_G['member']['extgroupids'] ? explode("\t", $_G['member']['extgroupids']) : array();
  27. space_merge($space, 'count');
  28. $credits = $space['credits'];
  29. $forumselect = '';
  30. $activeus = array();
  31. $activeus[$do] = ' class="a"';
  32. if(in_array($do, array('buy', 'exit'))) {
  33. $groupid = intval($_GET['groupid']);
  34. $group = C::t('common_usergroup')->fetch($groupid);
  35. if($group['type'] != 'special' || $group['system'] == 'private' || $group['radminid'] != 0) {
  36. $group = null;
  37. }
  38. if(empty($group)) {
  39. showmessage('usergroup_not_found');
  40. }
  41. $join = $do == 'buy' ? 1 : 0;
  42. $group['dailyprice'] = $group['minspan'] = 0;
  43. if($group['system'] != 'private') {
  44. list($group['dailyprice'], $group['minspan']) = explode("\t", $group['system']);
  45. if($group['dailyprice'] > -1 && $group['minspan'] == 0) {
  46. $group['minspan'] = 1;
  47. }
  48. }
  49. $creditstrans = $_G['setting']['creditstrans'];
  50. if(!isset($_G['setting']['creditstrans'])) {
  51. showmessage('credits_transaction_disabled');
  52. }
  53. if(!submitcheck('buysubmit')) {
  54. $usermoney = $space['extcredits'.$creditstrans];
  55. $usermaxdays = $group['dailyprice'] > 0 ? intval($usermoney / $group['dailyprice']) : 0;
  56. $group['minamount'] = $group['dailyprice'] * $group['minspan'];
  57. } else {
  58. $memberfieldforum = C::t('common_member_field_forum')->fetch($_G['uid']);
  59. $groupterms = dunserialize($memberfieldforum['groupterms']);
  60. unset($memberfieldforum);
  61. require_once libfile('function/forum');
  62. if($join) {
  63. $extgroupidsarray = array();
  64. foreach(array_unique(array_merge($extgroupids, array($groupid))) as $extgroupid) {
  65. if($extgroupid) {
  66. $extgroupidsarray[] = $extgroupid;
  67. }
  68. }
  69. $extgroupidsnew = implode("\t", $extgroupidsarray);
  70. if($group['dailyprice']) {
  71. if(($days = intval($_GET['days'])) < $group['minspan']) {
  72. showmessage('usergroups_span_invalid', '', array('minspan' => $group['minspan']));
  73. }
  74. if($space['extcredits'.$creditstrans] - ($amount = $days * $group['dailyprice']) < ($minbalance = 0)) {
  75. showmessage('credits_balance_insufficient', '', array('title'=> $_G['setting']['extcredits'][$creditstrans]['title'],'minbalance' => ($minbalance + $amount)));
  76. }
  77. $groupterms['ext'][$groupid] = ($groupterms['ext'][$groupid] > TIMESTAMP ? $groupterms['ext'][$groupid] : TIMESTAMP) + $days * 86400;
  78. $groupexpirynew = groupexpiry($groupterms);
  79. C::t('common_member')->update($_G['uid'], array('groupexpiry' => $groupexpirynew, 'extgroupids' => $extgroupidsnew));
  80. updatemembercount($_G['uid'], array($creditstrans => "-$amount"), true, 'UGP', $extgroupidsnew);
  81. C::t('common_member_field_forum')->update($_G['uid'], array('groupterms' => serialize($groupterms)));
  82. } else {
  83. C::t('common_member')->update($_G['uid'], array('extgroupids' => $extgroupidsnew));
  84. }
  85. showmessage('usergroups_join_succeed', "home.php?mod=spacecp&ac=usergroup".($_GET['gid'] ? "&gid=$_GET[gid]" : '&do=list'), array('group' => $group['grouptitle']), array('showdialog' => 3, 'showmsg' => true, 'locationtime' => true));
  86. } else {
  87. if($groupid != $_G['groupid']) {
  88. if(isset($groupterms['ext'][$groupid])) {
  89. unset($groupterms['ext'][$groupid]);
  90. }
  91. $groupexpirynew = groupexpiry($groupterms);
  92. C::t('common_member_field_forum')->update($_G['uid'], array('groupterms' => serialize($groupterms)));
  93. } else {
  94. $groupexpirynew = 'groupexpiry';
  95. }
  96. $extgroupidsarray = array();
  97. foreach($extgroupids as $extgroupid) {
  98. if($extgroupid && $extgroupid != $groupid) {
  99. $extgroupidsarray[] = $extgroupid;
  100. }
  101. }
  102. $extgroupidsnew = implode("\t", array_unique($extgroupidsarray));
  103. C::t('common_member')->update($_G['uid'], array('groupexpiry' => $groupexpirynew, 'extgroupids' => $extgroupidsnew));
  104. showmessage('usergroups_exit_succeed', "home.php?mod=spacecp&ac=usergroup".($_GET['gid'] ? "&gid=$_GET[gid]" : '&do=list'), array('group' => $group['grouptitle']), array('showdialog' => 3, 'showmsg' => true, 'locationtime' => true));
  105. }
  106. }
  107. } elseif($do == 'switch') {
  108. $groupid = intval($_GET['groupid']);
  109. if(!in_array($groupid, $extgroupids)) {
  110. showmessage('usergroup_not_found');
  111. }
  112. if($_G['groupid'] == 4 && $_G['member']['groupexpiry'] > 0 && $_G['member']['groupexpiry'] > TIMESTAMP) {
  113. showmessage('usergroup_switch_not_allow');
  114. }
  115. $group = C::t('common_usergroup')->fetch($groupid);
  116. if(submitcheck('groupsubmit')) {
  117. $memberfieldforum = C::t('common_member_field_forum')->fetch($_G['uid']);
  118. $groupterms = dunserialize($memberfieldforum['groupterms']);
  119. unset($memberfieldforum);
  120. $extgroupidsnew = $_G['groupid'];
  121. $groupexpirynew = $groupterms['ext'][$groupid];
  122. foreach($extgroupids as $extgroupid) {
  123. if($extgroupid && $extgroupid != $groupid) {
  124. $extgroupidsnew .= "\t".$extgroupid;
  125. }
  126. }
  127. if($_G['adminid'] > 0 && $group['radminid'] > 0) {
  128. $newadminid = $_G['adminid'] < $group['radminid'] ? $_G['adminid'] : $group['radminid'];
  129. } elseif($_G['adminid'] > 0) {
  130. $newadminid = $_G['adminid'];
  131. } else {
  132. $newadminid = $group['radminid'];
  133. }
  134. C::t('common_member')->update($_G['uid'], array('groupid' => $groupid, 'adminid' => $newadminid, 'groupexpiry' => $groupexpirynew, 'extgroupids' => $extgroupidsnew));
  135. showmessage('usergroups_switch_succeed', "home.php?mod=spacecp&ac=usergroup".($_GET['gid'] ? "&gid=$_GET[gid]" : '&do=list'), array('group' => $group['grouptitle']), array('showdialog' => 3, 'showmsg' => true, 'locationtime' => true));
  136. }
  137. } elseif($do == 'forum') {
  138. if($_G['setting']['verify']['enabled']) {
  139. $myverify= array();
  140. getuserprofile('verify1');
  141. for($i = 1; $i < 6; $i++) {
  142. if($_G['member']['verify'.$i] == 1) {
  143. $myverify[] = $i;
  144. }
  145. }
  146. $ar = array(1, 2, 3, 4, 5);
  147. }
  148. $language = lang('forum/misc');
  149. $permlang = $language;
  150. loadcache('forums');
  151. $fids = array_keys($_G['cache']['forums']);
  152. $perms = array('viewperm', 'postperm', 'replyperm', 'getattachperm', 'postattachperm', 'postimageperm');
  153. $defaultperm = array(
  154. array('viewperm' => 1, 'postperm' => 0, 'replyperm' => 0, 'getattachperm' => 1, 'postattachperm' => 0, 'postimageperm' => 0),
  155. array('viewperm' => 1, 'postperm' => 1, 'replyperm' => 1, 'getattachperm' => 1, 'postattachperm' => 1, 'postimageperm' => 1),
  156. );
  157. if($_G['setting']['verify']['enabled']) {
  158. for($i = 1; $i < 6; $i++) {
  159. if($_G['setting']['verify'][$i]['available']) {
  160. $verifyicon[$i] = !empty($_G['setting']['verify'][$i]['icon']) ? '<img src="'.$_G['setting']['verify'][$i]['icon'].'" alt="'.$_G['setting']['verify'][$i]['title'].'" class="vm" title="'.$_G['setting']['verify'][$i]['title'].'" />' : $_G['setting']['verify'][$i]['title'];
  161. }
  162. }
  163. }
  164. $forumperm = $verifyperm = $myverifyperm = array();
  165. $query = C::t('forum_forum')->fetch_all_info_by_fids($fids);
  166. foreach($query as $forum) {
  167. foreach($perms as $perm) {
  168. if($forum[$perm]) {
  169. if($_G['setting']['verify']['enabled']) {
  170. for($i = 1; $i < 6; $i++) {
  171. $verifyperm[$forum['fid']][$perm] .= preg_match("/(^|\t)(v".$i.")(\t|$)/", $forum[$perm]) ? $verifyicon[$i] : '';
  172. if(in_array($i, $myverify)) {
  173. $myverifyperm[$forum['fid']][$perm] = 1;
  174. }
  175. }
  176. }
  177. $forumperm[$forum['fid']][$perm] = preg_match("/(^|\t)(".$_G['groupid'].")(\t|$)/", $forum[$perm]) ? 1 : 0;
  178. } else {
  179. $forumperm[$forum['fid']][$perm] = $defaultperm[$_G['groupid'] != 7 ? 1 : 0][$perm];
  180. }
  181. }
  182. }
  183. } elseif($do == 'list' || $do == 'expiry') {
  184. $memberfieldforum = C::t('common_member_field_forum')->fetch($_G['uid']);
  185. $groupterms = dunserialize($memberfieldforum['groupterms']);
  186. unset($memberfieldforum);
  187. $expgrouparray = $expirylist = $termsarray = array();
  188. if(!empty($groupterms['ext']) && is_array($groupterms['ext'])) {
  189. $termsarray = $groupterms['ext'];
  190. }
  191. if(!empty($groupterms['main']['time']) && (empty($termsarray[$_G['groupid']]) || $termsarray[$_G['groupid']] > $groupterm['main']['time'])) {
  192. $termsarray[$_G['groupid']] = $groupterms['main']['time'];
  193. }
  194. foreach($termsarray as $expgroupid => $expiry) {
  195. if($expiry <= TIMESTAMP) {
  196. $expgrouparray[] = $expgroupid;
  197. }
  198. }
  199. if(!empty($groupterms['ext'])) {
  200. foreach($groupterms['ext'] as $extgroupid => $time) {
  201. $expirylist[$extgroupid] = array('time' => dgmdate($time, 'd'), 'type' => 'ext', 'noswitch' => $time < TIMESTAMP);
  202. }
  203. }
  204. if(!empty($groupterms['main'])) {
  205. $expirylist[$_G['groupid']] = array('time' => dgmdate($groupterms['main']['time'], 'd'), 'type' => 'main');
  206. }
  207. $groupids = array();
  208. foreach($_G['cache']['usergroups'] as $groupid => $usergroup) {
  209. if(!empty($usergroup['pubtype'])) {
  210. $groupids[] = $groupid;
  211. }
  212. }
  213. $expiryids = array_keys($expirylist);
  214. if(!$expiryids && $_G['member']['groupexpiry']) {
  215. C::t('common_member')->update($_G['uid'], array('groupexpiry' => 0));
  216. }
  217. $groupids = array_merge($extgroupids, $expiryids, $groupids);
  218. $usermoney = $space['extcredits'.$_G['setting']['creditstrans']];
  219. if($groupids) {
  220. foreach(C::t('common_usergroup')->fetch_all($groupids) as $group) {
  221. $isexp = in_array($group['groupid'], $expgrouparray);
  222. if($_G['cache']['usergroups'][$group['groupid']]['pubtype'] == 'buy') {
  223. list($dailyprice) = explode("\t", $group['system']);
  224. $expirylist[$group['groupid']]['dailyprice'] = $dailyprice;
  225. $expirylist[$group['groupid']]['usermaxdays'] = $dailyprice > 0 ? round($usermoney / $dailyprice) : 0;
  226. } else {
  227. $expirylist[$group['groupid']]['usermaxdays'] = 0;
  228. }
  229. $expirylist[$group['groupid']]['maingroup'] = $group['type'] != 'special' || $group['system'] == 'private' || $group['radminid'] > 0;
  230. $expirylist[$group['groupid']]['grouptitle'] = $isexp ? '<s>'.$group['grouptitle'].'</s>' : $group['grouptitle'];
  231. }
  232. }
  233. } else {
  234. $language = lang('forum/misc');
  235. require_once libfile('function/forumlist');
  236. $permlang = $language;
  237. unset($language);
  238. $maingroup = $_G['group'];
  239. $ptype = in_array($_GET['ptype'], array(0, 1, 2)) ? intval($_GET['ptype']) : 0;
  240. foreach($_G['cache']['usergroups'] as $gid => $value) {
  241. $cachekey[] = 'usergroup_'.$gid;
  242. }
  243. loadcache($cachekey);
  244. $_G['group'] = $maingroup;
  245. $sidegroup = $usergroups = $activegs = array();
  246. $nextupgradeid = $nextexist = 0;
  247. $memberfieldforum = C::t('common_member_field_forum')->fetch($_G['uid']);
  248. $groupterms = dunserialize($memberfieldforum['groupterms']);
  249. unset($memberfieldforum);
  250. $switchmaingroup = $_G['group']['grouppublic'] || isset($groupterms['ext']) ? 1 : 0;
  251. foreach($_G['cache']['usergroups'] as $gid => $group) {
  252. $group['grouptitle'] = strip_tags($group['grouptitle']);
  253. if($group['type'] == 'special') {
  254. $type = $_G['cache']['usergroup_'.$gid]['radminid'] ? 'admin' : 'user';
  255. } elseif($group['type'] == 'system') {
  256. $type = $_G['cache']['usergroup_'.$gid]['radminid'] ? 'admin' : 'user';
  257. } elseif($group['type'] == 'member') {
  258. $type = 'upgrade';
  259. }
  260. if($nextupgradeid && $group['type'] == 'member') {
  261. $_GET['gid'] = $gid;
  262. $nextupgradeid = 0;
  263. }
  264. $g = '<a href="home.php?mod=spacecp&ac=usergroup&gid='.$gid.'"'.(!empty($_GET['gid']) && $_GET['gid'] == $gid ? ' class="xi1"' : '').'>'.$group['grouptitle'].'</a>';
  265. if(in_array($gid, $extgroupids)) {
  266. $usergroups['my'] .= $g;
  267. }
  268. $usergroups[$type] .= $g;
  269. if(!empty($_GET['gid']) && $_GET['gid'] == $gid) {
  270. $switchtype = $type;
  271. if(!empty($_GET['gid'])) {
  272. $activegs[$switchtype] = ' a';
  273. }
  274. $currentgrouptitle = $group['grouptitle'];
  275. $sidegroup = $_G['cache']['usergroup_'.$gid];
  276. if($_G['cache']['usergroup_'.$gid]['radminid']) {
  277. $admingids[] = $gid;
  278. }
  279. } elseif(empty($_GET['gid']) && $_G['groupid'] == $gid && $group['type'] == 'member') {
  280. $nextupgradeid = 1;
  281. }
  282. }
  283. $usergroups['my'] = '<a href="home.php?mod=spacecp&ac=usergroup">'.$maingroup['grouptitle'].'</a>'.$usergroups['my'];
  284. if($activegs == array()) {
  285. $activegs['my'] = ' a';
  286. }
  287. $bperms = array('allowvisit','readaccess','allowinvisible','allowsearch','allowcstatus','disablepostctrl', 'allowsendpm', 'allowfriend', 'allowstatdata', 'allowmyop');
  288. if($_G['setting']['portalstatus']) {
  289. $bperms[] = 'allowpostarticle';
  290. }
  291. $pperms = array('allowpost','allowreply','allowpostpoll','allowvote','allowpostreward','allowpostactivity','allowpostdebate','allowposttrade','allowat', 'allowreplycredit', 'allowposttag', 'allowcreatecollection','maxsigsize','allowsigbbcode','allowsigimgcode','allowrecommend','raterange','allowcommentpost','allowmediacode');
  292. $aperms = array('allowgetattach', 'allowgetimage', 'allowpostattach', 'allowpostimage', 'allowsetattachperm', 'maxattachsize', 'maxsizeperday', 'maxattachnum', 'attachextensions');
  293. $sperms = array('allowpoke', 'allowclick', 'allowcomment', 'maxspacesize', 'maximagesize');
  294. if(helper_access::check_module('blog')) {$sperms[] = 'allowblog';}
  295. if(helper_access::check_module('album')) {$sperms[] = 'allowupload';}
  296. if(helper_access::check_module('share')) {$sperms[] = 'allowshare';}
  297. if(helper_access::check_module('doing')) {$sperms[] = 'allowdoing';}
  298. $allperms = array();
  299. $allkey = array_merge($bperms, $pperms, $aperms, $sperms);
  300. if($sidegroup) {
  301. foreach($allkey as $pkey) {
  302. if(in_array($pkey, array('maxattachsize', 'maxsizeperday', 'maxspacesize', 'maximagesize'))) {
  303. $sidegroup[$pkey] = $sidegroup[$pkey] ? sizecount($sidegroup[$pkey]) : 0;
  304. }
  305. $allperms[$pkey][$sidegroup['groupid']] = $sidegroup[$pkey];
  306. }
  307. }
  308. foreach($maingroup as $pkey => $v) {
  309. if(in_array($pkey, array('maxattachsize', 'maxsizeperday', 'maxspacesize', 'maximagesize'))) {
  310. $maingroup[$pkey] = $maingroup[$pkey] ? sizecount($maingroup[$pkey]) : 0;
  311. }
  312. }
  313. $publicgroup = array();
  314. $extgroupids[] = $_G['groupid'];
  315. foreach(C::t('common_usergroup')->fetch_all_switchable(array_unique($extgroupids)) as $group) {
  316. $group['allowsetmain'] = in_array($group['groupid'], $extgroupids);
  317. $publicgroup[$group['groupid']] = $group;
  318. }
  319. $group = $group[count($group)];
  320. $_GET['perms'] = 'member';
  321. if($sidegroup) {
  322. $group = $sidegroup;
  323. }
  324. }
  325. include_once template("home/spacecp_usergroup");
  326. ?>