forum_group.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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: forum_group.php 33695 2013-08-03 04:39:22Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. require_once libfile('function/group');
  12. $_G['action']['action'] = 3;
  13. $_G['action']['fid'] = $_G['fid'];
  14. $_G['basescript'] = 'group';
  15. $actionarray = array('join', 'out', 'create', 'viewmember', 'manage', 'index', 'memberlist', 'recommend');
  16. $action = getgpc('action') && in_array($_GET['action'], $actionarray) ? $_GET['action'] : 'index';
  17. if(in_array($action, array('join', 'out', 'create', 'manage', 'recommend'))) {
  18. if(empty($_G['uid'])) {
  19. showmessage('not_loggedin', '', '', array('login' => 1));
  20. }
  21. }
  22. if(empty($_G['fid']) && $action != 'create') {
  23. showmessage('group_rediret_now', 'group.php');
  24. }
  25. $first = &$_G['cache']['grouptype']['first'];
  26. $second = &$_G['cache']['grouptype']['second'];
  27. $rssauth = $_G['rssauth'];
  28. $rsshead = $_G['setting']['rssstatus'] ? ('<link rel="alternate" type="application/rss+xml" title="'.$_G['setting']['bbname'].' - '.$navtitle.'" href="'.$_G['siteurl'].'forum.php?mod=rss&fid='.$_G['fid'].'&amp;auth='.$rssauth."\" />\n") : '';
  29. if($_G['fid']) {
  30. if($_G['forum']['status'] != 3) {
  31. showmessage('forum_not_group', 'group.php');
  32. } elseif($_G['forum']['level'] == -1) {
  33. showmessage('group_verify', '', array(), array('alert' => 'info'));
  34. } elseif($_G['forum']['jointype'] < 0 && !$_G['forum']['ismoderator']) {
  35. showmessage('forum_group_status_off', 'group.php');
  36. }
  37. $groupcache = getgroupcache($_G['fid'], array('replies', 'views', 'digest', 'lastpost', 'ranking', 'activityuser', 'newuserlist'), 604800);
  38. $_G['forum']['icon'] = get_groupimg($_G['forum']['icon'], 'icon');
  39. $_G['forum']['banner'] = get_groupimg($_G['forum']['banner']);
  40. $_G['forum']['dateline'] = dgmdate($_G['forum']['dateline'], 'd');
  41. $_G['forum']['posts'] = intval($_G['forum']['posts']);
  42. $_G['grouptypeid'] = $_G['forum']['fup'];
  43. $groupuser = C::t('forum_groupuser')->fetch_userinfo($_G['uid'], $_G['fid']);
  44. $onlinemember = grouponline($_G['fid'], 1);
  45. $groupmanagers = $_G['forum']['moderators'];
  46. $nav = get_groupnav($_G['forum']);
  47. $groupnav = $nav['nav'];
  48. $seodata = array('forum' => $_G['forum']['name'], 'first' => $nav['first']['name'], 'second' => $nav['second']['name'], 'gdes' => $_G['forum']['description']);
  49. list($navtitle, $metadescription, $metakeywords) = get_seosetting('grouppage', $seodata);
  50. if(!$navtitle) {
  51. $navtitle = helper_seo::get_title_page($_G['forum']['name'], $_G['page']).' - '.$_G['setting']['navs'][3]['navname'];
  52. $nobbname = false;
  53. } else {
  54. $nobbname = true;
  55. }
  56. if(!$metakeywords) {
  57. $metakeywords = $_G['forum']['name'];
  58. }
  59. if(!$metadescription) {
  60. $metadescription = $_G['forum']['name'];
  61. }
  62. $_G['seokeywords'] = $_G['setting']['seokeywords']['group'];
  63. $_G['seodescription'] = $_G['setting']['seodescription']['group'];
  64. }
  65. if(in_array($action, array('out', 'viewmember', 'manage', 'index', 'memberlist'))) {
  66. $status = groupperm($_G['forum'], $_G['uid'], $action, $groupuser);
  67. if($status == -1) {
  68. showmessage('forum_not_group', 'group.php');
  69. } elseif($status == 1) {
  70. showmessage('forum_group_status_off');
  71. }
  72. if($action != 'index') {
  73. if($status == 2) {
  74. showmessage('forum_group_noallowed', "forum.php?mod=group&fid=$_G[fid]");
  75. } elseif($status == 3) {
  76. showmessage('forum_group_moderated', "forum.php?mod=group&fid=$_G[fid]");
  77. }
  78. }
  79. }
  80. if(in_array($action, array('index')) && $status != 2) {
  81. $newuserlist = $activityuserlist = array();
  82. foreach($groupcache['newuserlist']['data'] as $user) {
  83. $newuserlist[$user['uid']] = $user;
  84. $newuserlist[$user['uid']]['online'] = !empty($onlinemember['list']) && is_array($onlinemember['list']) && !empty($onlinemember['list'][$user['uid']]) ? 1 : 0;
  85. }
  86. $activityuser = array_slice($groupcache['activityuser']['data'], 0, 8);
  87. foreach($activityuser as $user) {
  88. $activityuserlist[$user['uid']] = $user;
  89. $activityuserlist[$user['uid']]['online'] = !empty($onlinemember['list']) && is_array($onlinemember['list']) && !empty($onlinemember['list'][$user['uid']]) ? 1 : 0;
  90. }
  91. $groupviewed_list = get_viewedgroup();
  92. }
  93. $showpoll = $showtrade = $showreward = $showactivity = $showdebate = 0;
  94. if($_G['forum']['allowpostspecial']) {
  95. $showpoll = $_G['forum']['allowpostspecial'] & 1;
  96. $showtrade = $_G['forum']['allowpostspecial'] & 2;
  97. $showreward = isset($_G['setting']['extcredits'][$_G['setting']['creditstransextra'][2]]) && ($_G['forum']['allowpostspecial'] & 4);
  98. $showactivity = $_G['forum']['allowpostspecial'] & 8;
  99. $showdebate = $_G['forum']['allowpostspecial'] & 16;
  100. }
  101. if($_G['group']['allowpost']) {
  102. $_G['group']['allowpostpoll'] = $_G['group']['allowpostpoll'] && $showpoll;
  103. $_G['group']['allowposttrade'] = $_G['group']['allowposttrade'] && $showtrade;
  104. $_G['group']['allowpostreward'] = $_G['group']['allowpostreward'] && $showreward;
  105. $_G['group']['allowpostactivity'] = $_G['group']['allowpostactivity'] && $showactivity;
  106. $_G['group']['allowpostdebate'] = $_G['group']['allowpostdebate'] && $showdebate;
  107. }
  108. if($action == 'index') {
  109. $newthreadlist = $livethread = array();
  110. if($status != 2) {
  111. loadcache('forumstick');
  112. $forumstickytids = '';
  113. if(isset($_G['cache']['forumstick'][$_G['forum']['fup']])) {
  114. $forumstickytids = $_G['cache']['forumstick'][$_G['forum']['fup']];
  115. }
  116. require_once libfile('function/feed');
  117. if($forumstickytids) {
  118. foreach(C::t('forum_thread')->fetch_all_by_tid_or_fid($_G['fid'], $forumstickytids) as $row) {
  119. $row['dateline'] = dgmdate($row['dateline'], 'd');
  120. $row['lastpost'] = dgmdate($row['lastpost'], 'u');
  121. $row['allreplies'] = $row['replies'] + $row['comments'];
  122. $row['lastposterenc'] = rawurlencode($row['lastposter']);
  123. $stickythread[$row['tid']] = $row;
  124. }
  125. }
  126. $newthreadlist = getgroupcache($_G['fid'], array('dateline'), 0, 10, 0, 1);
  127. foreach($newthreadlist['dateline']['data'] as $key => $thread) {
  128. if(!empty($stickythread) && $stickythread[$thread[tid]]) {
  129. unset($newthreadlist['dateline']['data'][$key]);
  130. continue;
  131. }
  132. $newthreadlist['dateline']['data'][$key]['allreplies'] = $newthreadlist['dateline']['data'][$key]['replies'] + $newthreadlist['dateline']['data'][$key]['comments'];
  133. if($thread['closed'] == 1) {
  134. $newthreadlist['dateline']['data'][$key]['folder'] = 'lock';
  135. } elseif(empty($_G['cookie']['oldtopics']) || strpos($_G['cookie']['oldtopics'], 'D'.$thread['tid'].'D') === FALSE) {
  136. $newthreadlist['dateline']['data'][$key]['folder'] = 'new';
  137. } else {
  138. $newthreadlist['dateline']['data'][$key]['folder'] = 'common';
  139. }
  140. }
  141. if($stickythread) {
  142. $newthreadlist['dateline']['data'] = array_merge($stickythread, $newthreadlist['dateline']['data']);
  143. }
  144. $groupfeedlist = array();
  145. if(!IS_ROBOT) {
  146. $activityuser = array_keys($groupcache['activityuser']['data']);
  147. if($activityuser) {
  148. $query = C::t('home_feed')->fetch_all_by_uid_dateline($activityuser);
  149. foreach($query as $feed) {
  150. if($feed['friend'] == 0) {
  151. $groupfeedlist[] = mkfeed($feed);
  152. }
  153. }
  154. }
  155. }
  156. if($_G['forum']['livetid']) {
  157. include_once libfile('function/post');
  158. $livethread = C::t('forum_thread')->fetch($_G['forum']['livetid']);
  159. $livepost = C::t('forum_post')->fetch_threadpost_by_tid_invisible($_G['forum']['livetid']);
  160. $livemessage = messagecutstr($livepost['message'], 200);
  161. $liveallowpostreply = $groupuser['uid'] && $groupuser['level'] ? true : false;
  162. list($seccodecheck, $secqaacheck) = seccheck('post', 'newthread');
  163. }
  164. } else {
  165. $newuserlist = $activityuserlist = array();
  166. $newuserlist = array_slice($groupcache['newuserlist']['data'], 0, 4);
  167. foreach($newuserlist as $user) {
  168. $newuserlist[$user['uid']] = $user;
  169. $newuserlist[$user['uid']]['online'] = !empty($onlinemember['list']) && is_array($onlinemember['list']) && !empty($onlinemember['list'][$user['uid']]) ? 1 : 0;
  170. }
  171. }
  172. write_groupviewed($_G['fid']);
  173. include template('diy:group/group:'.$_G['fid']);
  174. } elseif($action == 'memberlist') {
  175. $oparray = array('card', 'address', 'alluser');
  176. $op = getgpc('op') && in_array($_GET['op'], $oparray) ? $_GET['op'] : 'alluser';
  177. $page = intval(getgpc('page')) ? intval($_GET['page']) : 1;
  178. $perpage = 50;
  179. $start = ($page - 1) * $perpage;
  180. $alluserlist = $adminuserlist = array();
  181. $staruserlist = $page < 2 ? C::t('forum_groupuser')->groupuserlist($_G['fid'], 'lastupdate', 0, 0, array('level' => '3'), array('uid', 'username', 'level', 'joindateline', 'lastupdate')) : '';
  182. $adminlist = $groupmanagers && $page < 2 ? $groupmanagers : array();
  183. if($op == 'alluser') {
  184. $alluserlist = C::t('forum_groupuser')->groupuserlist($_G['fid'], 'lastupdate', $perpage, $start, "AND level='4'", '', $onlinemember['list']);
  185. $multipage = multi($_G['forum']['membernum'], $perpage, $page, 'forum.php?mod=group&action=memberlist&op=alluser&fid='.$_G['fid']);
  186. if($adminlist) {
  187. foreach($adminlist as $user) {
  188. $adminuserlist[$user['uid']] = $user;
  189. $adminuserlist[$user['uid']]['online'] = $onlinemember['list'] && is_array($onlinemember['list']) && $onlinemember['list'][$user['uid']] ? 1 : 0;
  190. }
  191. }
  192. }
  193. include template('diy:group/group:'.$_G['fid']);
  194. } elseif($action == 'join') {
  195. $inviteuid = 0;
  196. $membermaximum = $_G['current_grouplevel']['specialswitch']['membermaximum'];
  197. if(!empty($membermaximum)) {
  198. $curnum = C::t('forum_groupuser')->fetch_count_by_fid($_G['fid']);
  199. if($curnum >= $membermaximum) {
  200. showmessage('group_member_maximum', '', array('membermaximum' => $membermaximum));
  201. }
  202. }
  203. if($groupuser['uid']) {
  204. showmessage('group_has_joined', "forum.php?mod=group&fid=$_G[fid]");
  205. } else {
  206. $modmember = 4;
  207. $showmessage = 'group_join_succeed';
  208. $confirmjoin = TRUE;
  209. $inviteuid = C::t('forum_groupinvite')->fetch_uid_by_inviteuid($_G['fid'], $_G['uid']);
  210. if($_G['forum']['jointype'] == 1) {
  211. if(!$inviteuid) {
  212. $confirmjoin = FALSE;
  213. $showmessage = 'group_join_need_invite';
  214. }
  215. } elseif($_G['forum']['jointype'] == 2) {
  216. $modmember = !empty($groupmanagers[$inviteuid]) || $_G['adminid'] == 1 ? 4 : 0;
  217. !empty($groupmanagers[$inviteuid]) && $showmessage = 'group_join_apply_succeed';
  218. }
  219. if($confirmjoin) {
  220. C::t('forum_groupuser')->insert($_G['fid'], $_G['uid'], $_G['username'], $modmember, TIMESTAMP, TIMESTAMP);
  221. if($_G['forum']['jointype'] == 2 && (empty($inviteuid) || empty($groupmanagers[$inviteuid]))) {
  222. foreach($groupmanagers as $manage) {
  223. notification_add($manage['uid'], 'group', 'group_member_join', array('fid' => $_G['fid'], 'groupname' => $_G['forum']['name'], 'url' => $_G['siteurl'].'forum.php?mod=group&action=manage&op=checkuser&fid='.$_G['fid']), 1);
  224. }
  225. } else {
  226. }
  227. if($inviteuid) {
  228. C::t('forum_groupinvite')->delete_by_inviteuid($_G['fid'], $_G['uid']);
  229. }
  230. if($modmember == 4) {
  231. C::t('forum_forumfield')->update_membernum($_G['fid']);
  232. }
  233. C::t('forum_forumfield')->update($_G['fid'], array('lastupdate' => TIMESTAMP));
  234. }
  235. include_once libfile('function/stat');
  236. updatestat('groupjoin');
  237. delgroupcache($_G['fid'], array('activityuser', 'newuserlist'));
  238. showmessage($showmessage, "forum.php?mod=group&fid=$_G[fid]");
  239. }
  240. } elseif($action == 'out') {
  241. if($_G['uid'] == $_G['forum']['founderuid']) {
  242. showmessage('group_exit_founder');
  243. }
  244. $showmessage = 'group_exit_succeed';
  245. C::t('forum_groupuser')->delete_by_fid($_G['fid'], $_G['uid']);
  246. C::t('forum_forumfield')->update_membernum($_G['fid'], -1);
  247. update_groupmoderators($_G['fid']);
  248. delgroupcache($_G['fid'], array('activityuser', 'newuserlist'));
  249. showmessage($showmessage, "forum.php?mod=forumdisplay&fid=$_G[fid]");
  250. } elseif($action == 'create') {
  251. if(!$_G['group']['allowbuildgroup']) {
  252. showmessage('group_create_usergroup_failed', "group.php");
  253. }
  254. $creditstransextra = $_G['setting']['creditstransextra']['12'] ? $_G['setting']['creditstransextra']['12'] : $_G['setting']['creditstrans'];
  255. if($_G['group']['buildgroupcredits']) {
  256. if(empty($creditstransextra)) {
  257. $_G['group']['buildgroupcredits'] = 0;
  258. } else {
  259. getuserprofile('extcredits'.$creditstransextra);
  260. if($_G['member']['extcredits'.$creditstransextra] < $_G['group']['buildgroupcredits']) {
  261. showmessage('group_create_usergroup_credits_failed', '', array('buildgroupcredits' => $_G['group']['buildgroupcredits']. $_G['setting']['extcredits'][$creditstransextra]['unit'].$_G['setting']['extcredits'][$creditstransextra]['title']));
  262. }
  263. }
  264. }
  265. $groupnum = C::t('forum_forumfield')->fetch_groupnum_by_founderuid($_G['uid']);
  266. $allowbuildgroup = $_G['group']['allowbuildgroup'] - $groupnum;
  267. if($allowbuildgroup < 1) {
  268. showmessage('group_create_max_failed');
  269. }
  270. $_GET['fupid'] = intval($_GET['fupid']);
  271. $_GET['groupid'] = intval($_GET['groupid']);
  272. if(!submitcheck('createsubmit')) {
  273. $groupselect = get_groupselect(getgpc('fupid'), getgpc('groupid'));
  274. } else {
  275. $parentid = intval($_GET['parentid']);
  276. $fup = intval($_GET['fup']);
  277. $name = censor(dhtmlspecialchars(cutstr(trim($_GET['name']), 20, '')));
  278. $censormod = censormod($name);
  279. if(empty($name)) {
  280. showmessage('group_name_empty');
  281. } elseif($censormod) {
  282. showmessage('group_name_failed');
  283. } elseif(empty($parentid) && empty($fup)) {
  284. showmessage('group_category_empty');
  285. }
  286. if(empty($_G['cache']['grouptype']['first'][$parentid]) && empty($_G['cache']['grouptype']['second'][$fup])
  287. || $_G['cache']['grouptype']['first'][$parentid]['secondlist'] && !in_array($_G['cache']['grouptype']['second'][$fup]['fid'], $_G['cache']['grouptype']['first'][$parentid]['secondlist'])) {
  288. showmessage('group_category_error');
  289. }
  290. if(empty($fup)) {
  291. $fup = $parentid;
  292. }
  293. if(C::t('forum_forum')->fetch_fid_by_name($name)) {
  294. showmessage('group_name_exist');
  295. }
  296. require_once libfile('function/discuzcode');
  297. $descriptionnew = discuzcode(dhtmlspecialchars(censor(trim($_GET['descriptionnew']))), 0, 0, 0, 0, 1, 1, 0, 0, 1);
  298. $censormod = censormod($descriptionnew);
  299. if($censormod) {
  300. showmessage('group_description_failed');
  301. }
  302. if(empty($_G['setting']['groupmod']) || $_G['adminid'] == 1) {
  303. $levelinfo = C::t('forum_grouplevel')->fetch_by_credits();
  304. $levelid = $levelinfo['levelid'];
  305. } else {
  306. $levelid = -1;
  307. }
  308. $newfid = C::t('forum_forum')->insert_group($fup, 'sub', $name, '3', $levelid);
  309. if($newfid) {
  310. $jointype = intval($_GET['jointype']);
  311. $gviewperm = intval($_GET['gviewperm']);
  312. $fieldarray = array('fid' => $newfid, 'description' => $descriptionnew, 'jointype' => $jointype, 'gviewperm' => $gviewperm, 'dateline' => TIMESTAMP, 'founderuid' => $_G['uid'], 'foundername' => $_G['username'], 'membernum' => 1);
  313. C::t('forum_forumfield')->insert($fieldarray);
  314. C::t('forum_forumfield')->update_groupnum($fup, 1);
  315. C::t('forum_groupuser')->insert($newfid, $_G['uid'], $_G['username'], 1, TIMESTAMP);
  316. require_once libfile('function/cache');
  317. updatecache('grouptype');
  318. }
  319. if($creditstransextra && $_G['group']['buildgroupcredits']) {
  320. updatemembercount($_G['uid'], array($creditstransextra => -$_G['group']['buildgroupcredits']), 1, 'BGR', $newfid);
  321. }
  322. include_once libfile('function/stat');
  323. updatestat('group');
  324. if($levelid == -1) {
  325. showmessage('group_create_mod_succeed', "group.php?mod=my&view=manager", array(), array('alert' => 'right', 'showdialog' => 1, 'showmsg' => true, 'locationtime' => true));
  326. }
  327. showmessage('group_create_succeed', "forum.php?mod=group&action=manage&fid=$newfid", array(), array('showdialog' => 1, 'showmsg' => true, 'locationtime' => true));
  328. }
  329. $_G['setting']['navs']['3']['navname'] = '俱乐部';
  330. include template('diy:group/group:'.$_G['fid']);
  331. } elseif($action == 'manage'){
  332. if(!$_G['forum']['ismoderator']) {
  333. showmessage('group_admin_noallowed');
  334. }
  335. $specialswitch = $_G['current_grouplevel']['specialswitch'];
  336. $oparray = array('group', 'checkuser', 'manageuser', 'threadtype', 'demise');
  337. $_GET['op'] = getgpc('op') && in_array($_GET['op'], $oparray) ? $_GET['op'] : 'group';
  338. if(empty($groupmanagers[$_G[uid]]) && !in_array($_GET['op'], array('group', 'threadtype', 'demise')) && $_G['adminid'] != 1) {
  339. showmessage('group_admin_noallowed');
  340. }
  341. $page = intval(getgpc('page')) ? intval($_GET['page']) : 1;
  342. $perpage = 50;
  343. $start = ($page - 1) * $perpage;
  344. $url = 'forum.php?mod=group&action=manage&op='.$_GET['op'].'&fid='.$_G['fid'];
  345. if($_GET['op'] == 'group') {
  346. $domainlength = checkperm('domainlength');
  347. if(submitcheck('groupmanage')) {
  348. $forumarr = array();
  349. if(isset($_GET['domain']) && $_G['forum']['domain'] != $_GET['domain']) {
  350. $domain = strtolower(trim($_GET['domain']));
  351. if($_G['setting']['allowgroupdomain'] && !empty($_G['setting']['domain']['root']['group']) && $domainlength) {
  352. checklowerlimit('modifydomain');
  353. }
  354. require_once libfile('function/delete');
  355. if(empty($domainlength) || empty($domain)) {
  356. $domain = '';
  357. deletedomain($_G['fid'], 'group');
  358. } else {
  359. require_once libfile('function/domain');
  360. if(domaincheck($domain, $_G['setting']['domain']['root']['group'], $domainlength)) {
  361. deletedomain($_G['fid'], 'group');
  362. C::t('common_domain')->insert(array('domain' => $domain, 'domainroot' => $_G['setting']['domain']['root']['group'], 'id' => $_G['fid'], 'idtype' => 'group'));
  363. }
  364. }
  365. $forumarr['domain'] = $domain;
  366. updatecreditbyaction('modifydomain');
  367. }
  368. if(($_GET['name'] && !empty($specialswitch['allowchangename'])) || ($_GET['fup'] && !empty($specialswitch['allowchangetype']))) {
  369. if($_G['uid'] != $_G['forum']['founderuid'] && $_G['adminid'] != 1) {
  370. showmessage('group_edit_only_founder');
  371. }
  372. $fup = intval($_GET['fup']);
  373. $parentid = intval($_GET['parentid']);
  374. if(isset($_GET['name'])) {
  375. $_GET['name'] = censor(dhtmlspecialchars(cutstr(trim($_GET['name']), 20, '')));
  376. if(empty($_GET['name'])) {
  377. showmessage('group_name_empty');
  378. }
  379. $censormod = censormod($_GET['name']);
  380. if($censormod) {
  381. showmessage('group_name_failed');
  382. }
  383. } elseif(isset($_GET['parentid']) && empty($parentid) && empty($fup)) {
  384. showmessage('group_category_empty');
  385. }
  386. if(!empty($_GET['name']) && $_GET['name'] != $_G['forum']['name']) {
  387. if(C::t('forum_forum')->fetch_fid_by_name($_GET['name'])) {
  388. showmessage('group_name_exist', $url);
  389. }
  390. $forumarr['name'] = $_GET['name'];
  391. }
  392. if(empty($fup)) {
  393. $fup = $parentid;
  394. }
  395. if(isset($_GET['parentid']) && $fup != $_G['forum']['fup']) {
  396. $forumarr['fup'] = $fup;
  397. }
  398. }
  399. if($forumarr) {
  400. C::t('forum_forum')->update($_G['fid'], $forumarr);
  401. if($forumarr['fup']) {
  402. C::t('forum_forumfield')->update_groupnum($forumarr['fup'], 1);
  403. C::t('forum_forumfield')->update_groupnum($_G['forum']['fup'], -1);
  404. require_once libfile('function/cache');
  405. updatecache('grouptype');
  406. }
  407. }
  408. $setarr = array();
  409. $deletebanner = $_GET['deletebanner'];
  410. $iconnew = upload_icon_banner($_G['forum'], $_FILES['iconnew'], 'icon');
  411. $bannernew = upload_icon_banner($_G['forum'], $_FILES['bannernew'], 'banner');
  412. if($iconnew) {
  413. $setarr['icon'] = $iconnew;
  414. $group_recommend = dunserialize($_G['setting']['group_recommend']);
  415. if($group_recommend[$_G['fid']]) {
  416. $group_recommend[$_G['fid']]['icon'] = get_groupimg($iconnew);
  417. C::t('common_setting')->update('group_recommend', $group_recommend);
  418. include libfile('function/cache');
  419. updatecache('setting');
  420. }
  421. }
  422. if($bannernew && empty($deletebanner)) {
  423. $setarr['banner'] = $bannernew;
  424. } elseif($deletebanner) {
  425. $setarr['banner'] = '';
  426. @unlink($_G['forum']['banner']);
  427. }
  428. require_once libfile('function/discuzcode');
  429. $_GET['descriptionnew'] = discuzcode(censor(trim($_GET['descriptionnew'])), 0, 0, 0, 0, 1, 1, 0, 0, 1);
  430. $censormod = censormod($_GET['descriptionnew']);
  431. if($censormod) {
  432. showmessage('group_description_failed');
  433. }
  434. $_GET['jointypenew'] = intval($_GET['jointypenew']);
  435. if($_GET['jointypenew'] == '-1' && $_G['uid'] != $_G['forum']['founderuid']) {
  436. showmessage('group_close_only_founder');
  437. }
  438. $_GET['gviewpermnew'] = intval($_GET['gviewpermnew']);
  439. $setarr['description'] = $_GET['descriptionnew'];
  440. $setarr['jointype'] = $_GET['jointypenew'];
  441. $setarr['gviewperm'] = $_GET['gviewpermnew'];
  442. C::t('forum_forumfield')->update($_G['fid'], $setarr);
  443. showmessage('group_setup_succeed', $url);
  444. } else {
  445. $firstgid = $_G['cache']['grouptype']['second'][$_G['forum']['fup']]['fup'];
  446. $groupselect = get_groupselect($firstgid, $_G['forum']['fup']);
  447. $gviewpermselect = $jointypeselect = array('','','');
  448. require_once libfile('function/editor');
  449. $_G['forum']['descriptionnew'] = html2bbcode($_G['forum']['description']);
  450. $jointypeselect[$_G['forum']['jointype']] = 'checked="checked"';
  451. $gviewpermselect[$_G['forum']['gviewperm']] = 'checked="checked"';
  452. if($_G['setting']['allowgroupdomain'] && !empty($_G['setting']['domain']['root']['group']) && $domainlength) {
  453. loadcache('creditrule');
  454. getuserprofile('extcredits1');
  455. $rule = $_G['cache']['creditrule']['modifydomain'];
  456. $credits = $consume = $common = '';
  457. for($i = 1; $i <= 8; $i++) {
  458. if($_G['setting']['extcredits'][$i] && $rule['extcredits'.$i]) {
  459. $consume .= $common.$_G['setting']['extcredits'][$i]['title'].$rule['extcredits'.$i].$_G['setting']['extcredits'][$i]['unit'];
  460. $credits .= $common.$_G['setting']['extcredits'][$i]['title'].$_G['member']['extcredits'.$i].$_G['setting']['extcredits'][$i]['unit'];
  461. $common = ',';
  462. }
  463. }
  464. }
  465. }
  466. } elseif($_GET['op'] == 'checkuser') {
  467. $checktype = 0;
  468. $checkusers = array();
  469. if(!empty($_GET['uid'])) {
  470. $checkusers = array($_GET['uid']);
  471. $checktype = intval($_GET['checktype']);
  472. } elseif(getgpc('checkall') == 1 || getgpc('checkall') == 2) {
  473. $checktype = $_GET['checkall'];
  474. $query = C::t('forum_groupuser')->fetch_all_by_fid($_G['fid'], 1);
  475. foreach($query as $row) {
  476. $checkusers[] = $row['uid'];
  477. }
  478. }
  479. if($checkusers) {
  480. foreach($checkusers as $uid) {
  481. $notification = $checktype == 1 ? 'group_member_check' : 'group_member_check_failed';
  482. notification_add($uid, 'group', $notification, array('fid' => $_G['fid'], 'groupname' => $_G['forum']['name'], 'url' => $_G['siteurl'].'forum.php?mod=group&fid='.$_G['fid']), 1);
  483. }
  484. if($checktype == 1) {
  485. C::t('forum_groupuser')->update_for_user($checkusers, $_G['fid'], null, null, 4);
  486. C::t('forum_forumfield')->update_membernum($_G['fid'], count($checkusers));
  487. } elseif($checktype == 2) {
  488. C::t('forum_groupuser')->delete_by_fid($_G['fid'], $checkusers);
  489. }
  490. if($checktype == 1) {
  491. showmessage('group_moderate_succeed', $url);
  492. } else {
  493. showmessage('group_moderate_failed', $url);
  494. }
  495. } else {
  496. $checkusers = array();
  497. $userlist = C::t('forum_groupuser')->groupuserlist($_G['fid'], 'joindateline', $perpage, $start, array('level' => 0));
  498. $checknum = C::t('forum_groupuser')->fetch_count_by_fid($_G['fid'], 1);
  499. $multipage = multi($checknum, $perpage, $page, $url);
  500. foreach($userlist as $user) {
  501. $user['joindateline'] = date('Y-m-d H:i', $user['joindateline']);
  502. $checkusers[$user['uid']] = $user;
  503. }
  504. }
  505. } elseif($_GET['op'] == 'manageuser') {
  506. $mtype = array(1 => lang('group/template', 'group_moderator'), 2 => lang('group/template', 'group_moderator_vice'), 3 => lang('group/template', 'group_star_member_title'), 4 => lang('group/misc', 'group_normal_member'), 5 => lang('group/misc', 'group_goaway'));
  507. if(!submitcheck('manageuser')) {
  508. $userlist = array();
  509. if(empty($_GET['srchuser'])) {
  510. $staruserlist = $page < 2 ? C::t('forum_groupuser')->groupuserlist($_G['fid'], '', 0, 0, array('level' => '3'), array('uid', 'username', 'level', 'joindateline', 'lastupdate')) : '';
  511. $adminuserlist = $groupmanagers && $page < 2 ? $groupmanagers : array();
  512. $multipage = multi($_G['forum']['membernum'], $perpage, $page, $url);
  513. } else {
  514. $start = 0;
  515. }
  516. $userlist = C::t('forum_groupuser')->groupuserlist($_G['fid'], '', $perpage, $start, $_GET['srchuser'] ? "AND username like '".addslashes($_GET[srchuser])."%'" : "AND level='4'");
  517. } else {
  518. $muser = getgpc('muid');
  519. $targetlevel = $_GET['targetlevel'];
  520. if($muser && is_array($muser)) {
  521. foreach($muser as $muid => $mlevel) {
  522. if($_G['adminid'] != 1 && $_G['forum']['founderuid'] != $_G['uid'] && $groupmanagers[$muid] && $groupmanagers[$muid]['level'] <= $groupuser['level']) {
  523. showmessage('group_member_level_admin_noallowed.', $url);
  524. }
  525. if($_G['adminid'] == 1 || ($muid != $_G['uid'] && ($_G['forum']['founderuid'] == $_G['uid'] || !$groupmanagers[$muid] || $groupmanagers[$muid]['level'] > $groupuser['level']))) {
  526. if($targetlevel != 5) {
  527. C::t('forum_groupuser')->update_for_user($muid, $_G['fid'], null, null, $targetlevel);
  528. } else {
  529. if(!$groupmanagers[$muid] || count($groupmanagers) > 1) {
  530. C::t('forum_groupuser')->delete_by_fid($_G['fid'], $muid);
  531. C::t('forum_forumfield')->update_membernum($_G['fid'], -1);
  532. } else {
  533. showmessage('group_only_one_moderator', $url);
  534. }
  535. }
  536. }
  537. }
  538. update_groupmoderators($_G['fid']);
  539. showmessage('group_setup_succeed', $url.'&page='.$page);
  540. } else {
  541. showmessage('group_choose_member', $url);
  542. }
  543. }
  544. } elseif($_GET['op'] == 'threadtype') {
  545. if(empty($specialswitch['allowthreadtype'])) {
  546. showmessage('group_level_cannot_do');
  547. }
  548. if($_G['uid'] != $_G['forum']['founderuid'] && $_G['adminid'] != 1) {
  549. showmessage('group_threadtype_only_founder');
  550. }
  551. $typenumlimit = 20;
  552. if(!submitcheck('groupthreadtype')) {
  553. $threadtypes = $checkeds = array();
  554. if(empty($_G['forum']['threadtypes'])) {
  555. $checkeds['status'][0] = 'checked';
  556. $display = 'none';
  557. } else {
  558. $display = '';
  559. $_G['forum']['threadtypes']['status'] = 1;
  560. foreach($_G['forum']['threadtypes'] as $key => $val) {
  561. $val = intval($val);
  562. $checkeds[$key][$val] = 'checked';
  563. }
  564. }
  565. foreach(C::t('forum_threadclass')->fetch_all_by_fid($_G['fid']) as $type) {
  566. $type['enablechecked'] = isset($_G['forum']['threadtypes']['types'][$type['typeid']]) ? ' checked="checked"' : '';
  567. $type['name'] = dhtmlspecialchars($type['name']);
  568. $threadtypes[] = $type;
  569. }
  570. } else {
  571. $threadtypesnew = $_GET['threadtypesnew'];
  572. $threadtypesnew['types'] = $threadtypes['special'] = $threadtypes['show'] = array();
  573. if(is_array($_GET['newname']) && $_GET['newname']) {
  574. $newname = array_unique($_GET['newname']);
  575. if($newname) {
  576. foreach($newname as $key => $val) {
  577. $val = dhtmlspecialchars(censor(cutstr(trim($val), 16, '')));
  578. if($_GET['newenable'][$key] && $val) {
  579. $newtype = C::t('forum_threadclass')->fetch_by_fid_name($_G['fid'], $val);
  580. $newtypeid = $newtype['typeid'];
  581. if(!$newtypeid) {
  582. $typenum = C::t('forum_threadclass')->count_by_fid($_G['fid']);
  583. if($typenum < $typenumlimit) {
  584. $threadtypes_newdisplayorder = intval($_GET['newdisplayorder'][$key]);
  585. $newtypeid = C::t('forum_threadclass')->insert(array('fid' => $_G['fid'], 'name' => $val, 'displayorder' => $threadtypes_newdisplayorder), true);
  586. }
  587. }
  588. if($newtypeid) {
  589. $threadtypesnew['options']['name'][$newtypeid] = $val;
  590. $threadtypesnew['options']['displayorder'][$newtypeid] = $threadtypes_newdisplayorder;
  591. $threadtypesnew['options']['enable'][$newtypeid] = 1;
  592. }
  593. }
  594. }
  595. }
  596. $threadtypesnew['status'] = 1;
  597. } else {
  598. $newname = array();
  599. }
  600. if($threadtypesnew['status']) {
  601. if(is_array($threadtypesnew['options']) && $threadtypesnew['options']) {
  602. if(!empty($threadtypesnew['options']['enable'])) {
  603. $typeids = array_keys($threadtypesnew['options']['enable']);
  604. } else {
  605. $typeids = array(0);
  606. }
  607. if(!empty($threadtypesnew['options']['delete'])) {
  608. C::t('forum_threadclass')->delete_by_typeid_fid($threadtypesnew['options']['delete'], $_G['fid']);
  609. }
  610. foreach(C::t('forum_threadclass')->fetch_all_by_typeid_fid($typeids, $_G['fid']) as $type) {
  611. if($threadtypesnew['options']['name'][$type['typeid']] != $type['name'] || $threadtypesnew['options']['displayorder'][$type['typeid']] != $type['displayorder']) {
  612. $threadtypesnew['options']['name'][$type['typeid']] = dhtmlspecialchars(censor(cutstr(trim($threadtypesnew['options']['name'][$type['typeid']]), 16, '')));
  613. $threadtypesnew['options']['displayorder'][$type['typeid']] = intval($threadtypesnew['options']['displayorder'][$type['typeid']]);
  614. C::t('forum_threadclass')->update_by_typeid_fid($type['typeid'], $_G['fid'], array(
  615. 'name' => $threadtypesnew['options']['name'][$type['typeid']],
  616. 'displayorder' => $threadtypesnew['options']['displayorder'][$type['typeid']],
  617. ));
  618. }
  619. }
  620. }
  621. if($threadtypesnew && $typeids) {
  622. foreach(C::t('forum_threadclass')->fetch_all_by_typeid($typeids) as $type) {
  623. if($threadtypesnew['options']['enable'][$type['typeid']]) {
  624. $threadtypesnew['types'][$type['typeid']] = $threadtypesnew['options']['name'][$type['typeid']];
  625. }
  626. }
  627. }
  628. $threadtypesnew = !empty($threadtypesnew) ? serialize($threadtypesnew) : '';
  629. } else {
  630. $threadtypesnew = '';
  631. }
  632. C::t('forum_forumfield')->update($_G['fid'], array('threadtypes' => $threadtypesnew));
  633. showmessage('group_threadtype_edit_succeed', $url);
  634. }
  635. } elseif($_GET['op'] == 'demise') {
  636. if((!empty($_G['forum']['founderuid']) && $_G['forum']['founderuid'] == $_G['uid']) || $_G['adminid'] == 1) {
  637. $ucresult = $allowbuildgroup = $groupnum = 0;
  638. if(count($groupmanagers) <= 1) {
  639. showmessage('group_cannot_demise');
  640. }
  641. if(submitcheck('groupdemise')) {
  642. $suid = intval($_GET['suid']);
  643. if(empty($suid)) {
  644. showmessage('group_demise_choose_receiver');
  645. }
  646. if(empty($_GET['grouppwd'])) {
  647. showmessage('group_demise_password');
  648. }
  649. loaducenter();
  650. $ucresult = uc_user_login($_G['uid'], $_GET['grouppwd'], 1);
  651. if(!is_array($ucresult) || $ucresult[0] < 1) {
  652. showmessage('group_demise_password_error');
  653. }
  654. $user = getuserbyuid($suid);
  655. loadcache('usergroup_'.$user['groupid']);
  656. $allowbuildgroup = $_G['cache']['usergroup_'.$user['groupid']]['allowbuildgroup'];
  657. if($allowbuildgroup > 0) {
  658. $groupnum = C::t('forum_forumfield')->fetch_groupnum_by_founderuid($suid);
  659. }
  660. if(empty($allowbuildgroup) || $allowbuildgroup - $groupnum < 1) {
  661. showmessage('group_demise_receiver_cannot_do');
  662. }
  663. C::t('forum_forumfield')->update($_G['fid'], array('founderuid' => $suid, 'foundername' => $user['username']));
  664. C::t('forum_groupuser')->update_for_user($suid, $_G['fid'], NULL, NULL, 1);
  665. update_groupmoderators($_G['fid']);
  666. sendpm($suid, lang('group/misc', 'group_demise_message_title', array('forum' => $_G['forum']['name'])), lang('group/misc', 'group_demise_message_body', array('forum' => $_G['forum']['name'], 'siteurl' => $_G['siteurl'], 'fid' => $_G['fid'])), $_G['uid']);
  667. showmessage('group_demise_succeed', 'forum.php?mod=group&action=manage&fid='.$_G['fid']);
  668. }
  669. } else {
  670. showmessage('group_demise_founder_only');
  671. }
  672. } else {
  673. showmessage('undefined_action');
  674. }
  675. include template('diy:group/group:'.$_G['fid']);
  676. } elseif($action == 'recommend') {
  677. if(!$_G['forum']['ismoderator'] || !in_array($_G['adminid'], array(1,2))) {
  678. showmessage('group_admin_noallowed');
  679. }
  680. if(submitcheck('grouprecommend')) {
  681. if($_GET['recommend'] != $_G['forum']['recommend']) {
  682. C::t('forum_forum')->update($_G['fid'], array('recommend' => intval($_GET['recommend'])));
  683. require_once libfile('function/cache');
  684. updatecache('forumrecommend');
  685. }
  686. showmessage('grouprecommend_succeed', '', array(), array('alert' => 'right', 'closetime' => true, 'showdialog' => 1));
  687. } else {
  688. require_once libfile('function/forumlist');
  689. $forumselect = forumselect(FALSE, 0, $_G['forum']['recommend']);
  690. }
  691. include template('group/group_recommend');
  692. }
  693. ?>