forum_group.php 34 KB

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