ManageMembergroups.php 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187
  1. <?php
  2. /**
  3. * This file is concerned with anything in the Manage Membergroups admin screen.
  4. *
  5. * Simple Machines Forum (SMF)
  6. *
  7. * @package SMF
  8. * @author Simple Machines http://www.simplemachines.org
  9. * @copyright 2011 Simple Machines
  10. * @license http://www.simplemachines.org/about/smf/license.php BSD
  11. *
  12. * @version 2.1 Alpha 1
  13. */
  14. if (!defined('SMF'))
  15. die('Hacking attempt...');
  16. /**
  17. * Main dispatcher, the entrance point for all 'Manage Membergroup' actions.
  18. * It forwards to a function based on the given subaction, default being subaction 'index', or, without manage_membergroup
  19. * permissions, then 'settings'.
  20. * Called by ?action=admin;area=membergroups.
  21. * Requires the manage_membergroups or the admin_forum permission.
  22. *
  23. * @uses ManageMembergroups template.
  24. * @uses ManageMembers language file.
  25. */
  26. function ModifyMembergroups()
  27. {
  28. global $context, $txt, $scripturl, $sourcedir;
  29. $subActions = array(
  30. 'add' => array('AddMembergroup', 'manage_membergroups'),
  31. 'delete' => array('DeleteMembergroup', 'manage_membergroups'),
  32. 'edit' => array('EditMembergroup', 'manage_membergroups'),
  33. 'index' => array('MembergroupIndex', 'manage_membergroups'),
  34. 'members' => array('MembergroupMembers', 'manage_membergroups', 'Groups.php'),
  35. 'settings' => array('ModifyMembergroupsettings', 'admin_forum'),
  36. );
  37. call_integration_hook('integrate_manage_membergroups', array(&$subActions));
  38. // Default to sub action 'index' or 'settings' depending on permissions.
  39. $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (allowedTo('manage_membergroups') ? 'index' : 'settings');
  40. // Is it elsewhere?
  41. if (isset($subActions[$_REQUEST['sa']][2]))
  42. require_once($sourcedir . '/' . $subActions[$_REQUEST['sa']][2]);
  43. // Do the permission check, you might not be allowed her.
  44. isAllowedTo($subActions[$_REQUEST['sa']][1]);
  45. // Language and template stuff, the usual.
  46. loadLanguage('ManageMembers');
  47. loadTemplate('ManageMembergroups');
  48. // Setup the admin tabs.
  49. $context[$context['admin_menu_name']]['tab_data'] = array(
  50. 'title' => $txt['membergroups_title'],
  51. 'help' => 'membergroups',
  52. 'description' => $txt['membergroups_description'],
  53. );
  54. // Call the right function.
  55. $subActions[$_REQUEST['sa']][0]();
  56. }
  57. /**
  58. * Shows an overview of the current membergroups.
  59. * Called by ?action=admin;area=membergroups.
  60. * Requires the manage_membergroups permission.
  61. * Splits the membergroups in regular ones and post count based groups.
  62. * It also counts the number of members part of each membergroup.
  63. *
  64. * @uses ManageMembergroups template, main.
  65. */
  66. function MembergroupIndex()
  67. {
  68. global $txt, $scripturl, $context, $settings, $smcFunc, $sourcedir;
  69. $context['page_title'] = $txt['membergroups_title'];
  70. // The first list shows the regular membergroups.
  71. $listOptions = array(
  72. 'id' => 'regular_membergroups_list',
  73. 'title' => $txt['membergroups_regular'],
  74. 'base_href' => $scripturl . '?action=admin;area=membergroups' . (isset($_REQUEST['sort2']) ? ';sort2=' . urlencode($_REQUEST['sort2']) : ''),
  75. 'default_sort_col' => 'name',
  76. 'get_items' => array(
  77. 'file' => $sourcedir . '/Subs-Membergroups.php',
  78. 'function' => 'list_getMembergroups',
  79. 'params' => array(
  80. 'regular',
  81. ),
  82. ),
  83. 'columns' => array(
  84. 'name' => array(
  85. 'header' => array(
  86. 'value' => $txt['membergroups_name'],
  87. ),
  88. 'data' => array(
  89. 'function' => create_function('$rowData', '
  90. global $scripturl;
  91. // Since the moderator group has no explicit members, no link is needed.
  92. if ($rowData[\'id_group\'] == 3)
  93. $group_name = $rowData[\'group_name\'];
  94. else
  95. {
  96. $color_style = empty($rowData[\'online_color\']) ? \'\' : sprintf(\' style="color: %1$s;"\', $rowData[\'online_color\']);
  97. $group_name = sprintf(\'<a href="%1$s?action=admin;area=membergroups;sa=members;group=%2$d"%3$s>%4$s</a>\', $scripturl, $rowData[\'id_group\'], $color_style, $rowData[\'group_name\']);
  98. }
  99. // Add a help option for moderator and administrator.
  100. if ($rowData[\'id_group\'] == 1)
  101. $group_name .= sprintf(\' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)\', $scripturl);
  102. elseif ($rowData[\'id_group\'] == 3)
  103. $group_name .= sprintf(\' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)\', $scripturl);
  104. return $group_name;
  105. '),
  106. ),
  107. 'sort' => array(
  108. 'default' => 'CASE WHEN id_group < 4 THEN id_group ELSE 4 END, group_name',
  109. 'reverse' => 'CASE WHEN id_group < 4 THEN id_group ELSE 4 END, group_name DESC',
  110. ),
  111. ),
  112. 'icons' => array(
  113. 'header' => array(
  114. 'value' => $txt['membergroups_icons'],
  115. ),
  116. 'data' => array(
  117. 'function' => create_function('$rowData', '
  118. global $settings;
  119. $icons = explode(\'#\', $rowData[\'icons\']);
  120. // In case no icons are setup, return with nothing
  121. if (empty($icons[0]) || empty($icons[1]))
  122. return \'\';
  123. // Otherwise repeat the image a given number of times.
  124. else
  125. {
  126. $image = sprintf(\'<img src="%1$s/%2$s" alt="*" />\', $settings[\'images_url\'], $icons[1]);
  127. return str_repeat($image, $icons[0]);
  128. }
  129. '),
  130. ),
  131. 'sort' => array(
  132. 'default' => 'icons',
  133. 'reverse' => 'icons DESC',
  134. )
  135. ),
  136. 'members' => array(
  137. 'header' => array(
  138. 'value' => $txt['membergroups_members_top'],
  139. ),
  140. 'data' => array(
  141. 'function' => create_function('$rowData', '
  142. global $txt;
  143. // No explicit members for the moderator group.
  144. return $rowData[\'id_group\'] == 3 ? $txt[\'membergroups_guests_na\'] : $rowData[\'num_members\'];
  145. '),
  146. 'style' => 'text-align: center',
  147. ),
  148. 'sort' => array(
  149. 'default' => 'CASE WHEN id_group < 4 THEN id_group ELSE 4 END, 1',
  150. 'reverse' => 'CASE WHEN id_group < 4 THEN id_group ELSE 4 END, 1 DESC',
  151. ),
  152. ),
  153. 'modify' => array(
  154. 'header' => array(
  155. 'value' => $txt['modify'],
  156. ),
  157. 'data' => array(
  158. 'sprintf' => array(
  159. 'format' => '<a href="' . $scripturl . '?action=admin;area=membergroups;sa=edit;group=%1$d">' . $txt['membergroups_modify'] . '</a>',
  160. 'params' => array(
  161. 'id_group' => false,
  162. ),
  163. ),
  164. 'style' => 'text-align: center',
  165. ),
  166. ),
  167. ),
  168. 'additional_rows' => array(
  169. array(
  170. 'position' => 'below_table_data',
  171. 'value' => '<a class="button_link" href="' . $scripturl . '?action=admin;area=membergroups;sa=add;generalgroup">' . $txt['membergroups_add_group'] . '</a>',
  172. ),
  173. ),
  174. );
  175. call_integration_hook('integrate_modify_regular_groups', array(&$listOptions));
  176. require_once($sourcedir . '/Subs-List.php');
  177. createList($listOptions);
  178. // The second list shows the post count based groups.
  179. $listOptions = array(
  180. 'id' => 'post_count_membergroups_list',
  181. 'title' => $txt['membergroups_post'],
  182. 'base_href' => $scripturl . '?action=admin;area=membergroups' . (isset($_REQUEST['sort']) ? ';sort=' . urlencode($_REQUEST['sort']) : ''),
  183. 'default_sort_col' => 'required_posts',
  184. 'request_vars' => array(
  185. 'sort' => 'sort2',
  186. 'desc' => 'desc2',
  187. ),
  188. 'get_items' => array(
  189. 'file' => $sourcedir . '/Subs-Membergroups.php',
  190. 'function' => 'list_getMembergroups',
  191. 'params' => array(
  192. 'post_count',
  193. ),
  194. ),
  195. 'columns' => array(
  196. 'name' => array(
  197. 'header' => array(
  198. 'value' => $txt['membergroups_name'],
  199. ),
  200. 'data' => array(
  201. 'function' => create_function('$rowData', '
  202. global $scripturl;
  203. $colorStyle = empty($rowData[\'online_color\']) ? \'\' : sprintf(\' style="color: %1$s;"\', $rowData[\'online_color\']);
  204. return sprintf(\'<a href="%1$s?action=moderate;area=viewgroups;sa=members;group=%2$d"%3$s>%4$s</a>\', $scripturl, $rowData[\'id_group\'], $colorStyle, $rowData[\'group_name\']);
  205. '),
  206. ),
  207. 'sort' => array(
  208. 'default' => 'group_name',
  209. 'reverse' => 'group_name DESC',
  210. ),
  211. ),
  212. 'icons' => array(
  213. 'header' => array(
  214. 'value' => $txt['membergroups_icons'],
  215. ),
  216. 'data' => array(
  217. 'function' => create_function('$rowData', '
  218. global $settings;
  219. $icons = explode(\'#\', $rowData[\'icons\']);
  220. if (empty($icons[0]) || empty($icons[1]))
  221. return \'\';
  222. else
  223. {
  224. $icon_image = sprintf(\'<img src="%1$s/%2$s" alt="*" />\', $settings[\'images_url\'], $icons[1]);
  225. return str_repeat($icon_image, $icons[0]);
  226. }
  227. '),
  228. ),
  229. 'sort' => array(
  230. 'default' => 'CASE WHEN id_group < 4 THEN id_group ELSE 4 END, icons',
  231. 'reverse' => 'CASE WHEN id_group < 4 THEN id_group ELSE 4 END, icons DESC',
  232. )
  233. ),
  234. 'members' => array(
  235. 'header' => array(
  236. 'value' => $txt['membergroups_members_top'],
  237. ),
  238. 'data' => array(
  239. 'db' => 'num_members',
  240. 'style' => 'text-align: center',
  241. ),
  242. 'sort' => array(
  243. 'default' => '1 DESC',
  244. 'reverse' => '1',
  245. ),
  246. ),
  247. 'required_posts' => array(
  248. 'header' => array(
  249. 'value' => $txt['membergroups_min_posts'],
  250. ),
  251. 'data' => array(
  252. 'db' => 'min_posts',
  253. 'style' => 'text-align: center',
  254. ),
  255. 'sort' => array(
  256. 'default' => 'min_posts',
  257. 'reverse' => 'min_posts DESC',
  258. ),
  259. ),
  260. 'modify' => array(
  261. 'header' => array(
  262. 'value' => $txt['modify'],
  263. ),
  264. 'data' => array(
  265. 'sprintf' => array(
  266. 'format' => '<a href="' . $scripturl . '?action=admin;area=membergroups;sa=edit;group=%1$d">' . $txt['membergroups_modify'] . '</a>',
  267. 'params' => array(
  268. 'id_group' => false,
  269. ),
  270. ),
  271. 'style' => 'text-align: center',
  272. ),
  273. ),
  274. ),
  275. 'additional_rows' => array(
  276. array(
  277. 'position' => 'below_table_data',
  278. 'value' => '<a class="button_link" href="' . $scripturl . '?action=admin;area=membergroups;sa=add;postgroup">' . $txt['membergroups_add_group'] . '</a>',
  279. ),
  280. ),
  281. );
  282. call_integration_hook('integrate_modify_post_groups', array(&$listOptions));
  283. createList($listOptions);
  284. }
  285. /**
  286. * This function handles adding a membergroup and setting some initial properties.
  287. * Called by ?action=admin;area=membergroups;sa=add.
  288. * It requires the manage_membergroups permission.
  289. * Allows to use a predefined permission profile or copy one from another group.
  290. * Redirects to action=admin;area=membergroups;sa=edit;group=x.
  291. *
  292. * @uses the new_group sub template of ManageMembergroups.
  293. */
  294. function AddMembergroup()
  295. {
  296. global $context, $txt, $sourcedir, $modSettings, $smcFunc;
  297. // A form was submitted, we can start adding.
  298. if (isset($_POST['group_name']) && trim($_POST['group_name']) != '')
  299. {
  300. checkSession();
  301. validateToken('admin-mmg');
  302. $postCountBasedGroup = isset($_POST['min_posts']) && (!isset($_POST['postgroup_based']) || !empty($_POST['postgroup_based']));
  303. $_POST['group_type'] = !isset($_POST['group_type']) || $_POST['group_type'] < 0 || $_POST['group_type'] > 3 || ($_POST['group_type'] == 1 && !allowedTo('admin_forum')) ? 0 : (int) $_POST['group_type'];
  304. // @todo Check for members with same name too?
  305. $request = $smcFunc['db_query']('', '
  306. SELECT MAX(id_group)
  307. FROM {db_prefix}membergroups',
  308. array(
  309. )
  310. );
  311. list ($id_group) = $smcFunc['db_fetch_row']($request);
  312. $smcFunc['db_free_result']($request);
  313. $id_group++;
  314. $smcFunc['db_insert']('',
  315. '{db_prefix}membergroups',
  316. array(
  317. 'id_group' => 'int', 'description' => 'string', 'group_name' => 'string-80', 'min_posts' => 'int',
  318. 'icons' => 'string', 'online_color' => 'string', 'group_type' => 'int',
  319. ),
  320. array(
  321. $id_group, '', $smcFunc['htmlspecialchars']($_POST['group_name'], ENT_QUOTES), ($postCountBasedGroup ? (int) $_POST['min_posts'] : '-1'),
  322. '1#star.png', '', $_POST['group_type'],
  323. ),
  324. array('id_group')
  325. );
  326. call_integration_hook('integrate_add_membergroup', array($id_group, $postCountBasedGroup));
  327. // Update the post groups now, if this is a post group!
  328. if (isset($_POST['min_posts']))
  329. updateStats('postgroups');
  330. // You cannot set permissions for post groups if they are disabled.
  331. if ($postCountBasedGroup && empty($modSettings['permission_enable_postgroups']))
  332. $_POST['perm_type'] = '';
  333. if ($_POST['perm_type'] == 'predefined')
  334. {
  335. // Set default permission level.
  336. require_once($sourcedir . '/ManagePermissions.php');
  337. setPermissionLevel($_POST['level'], $id_group, 'null');
  338. }
  339. // Copy or inherit the permissions!
  340. elseif ($_POST['perm_type'] == 'copy' || $_POST['perm_type'] == 'inherit')
  341. {
  342. $copy_id = $_POST['perm_type'] == 'copy' ? (int) $_POST['copyperm'] : (int) $_POST['inheritperm'];
  343. // Are you a powerful admin?
  344. if (!allowedTo('admin_forum'))
  345. {
  346. $request = $smcFunc['db_query']('', '
  347. SELECT group_type
  348. FROM {db_prefix}membergroups
  349. WHERE id_group = {int:copy_from}
  350. LIMIT {int:limit}',
  351. array(
  352. 'copy_from' => $copy_id,
  353. 'limit' => 1,
  354. )
  355. );
  356. list ($copy_type) = $smcFunc['db_fetch_row']($request);
  357. $smcFunc['db_free_result']($request);
  358. // Protected groups are... well, protected!
  359. if ($copy_type == 1)
  360. fatal_lang_error('membergroup_does_not_exist');
  361. }
  362. // Don't allow copying of a real priviledged person!
  363. require_once($sourcedir . '/ManagePermissions.php');
  364. loadIllegalPermissions();
  365. $request = $smcFunc['db_query']('', '
  366. SELECT permission, add_deny
  367. FROM {db_prefix}permissions
  368. WHERE id_group = {int:copy_from}',
  369. array(
  370. 'copy_from' => $copy_id,
  371. )
  372. );
  373. $inserts = array();
  374. while ($row = $smcFunc['db_fetch_assoc']($request))
  375. {
  376. if (empty($context['illegal_permissions']) || !in_array($row['permission'], $context['illegal_permissions']))
  377. $inserts[] = array($id_group, $row['permission'], $row['add_deny']);
  378. }
  379. $smcFunc['db_free_result']($request);
  380. if (!empty($inserts))
  381. $smcFunc['db_insert']('insert',
  382. '{db_prefix}permissions',
  383. array('id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int'),
  384. $inserts,
  385. array('id_group', 'permission')
  386. );
  387. $request = $smcFunc['db_query']('', '
  388. SELECT id_profile, permission, add_deny
  389. FROM {db_prefix}board_permissions
  390. WHERE id_group = {int:copy_from}',
  391. array(
  392. 'copy_from' => $copy_id,
  393. )
  394. );
  395. $inserts = array();
  396. while ($row = $smcFunc['db_fetch_assoc']($request))
  397. $inserts[] = array($id_group, $row['id_profile'], $row['permission'], $row['add_deny']);
  398. $smcFunc['db_free_result']($request);
  399. if (!empty($inserts))
  400. $smcFunc['db_insert']('insert',
  401. '{db_prefix}board_permissions',
  402. array('id_group' => 'int', 'id_profile' => 'int', 'permission' => 'string', 'add_deny' => 'int'),
  403. $inserts,
  404. array('id_group', 'id_profile', 'permission')
  405. );
  406. // Also get some membergroup information if we're copying and not copying from guests...
  407. if ($copy_id > 0 && $_POST['perm_type'] == 'copy')
  408. {
  409. $request = $smcFunc['db_query']('', '
  410. SELECT online_color, max_messages, icons
  411. FROM {db_prefix}membergroups
  412. WHERE id_group = {int:copy_from}
  413. LIMIT 1',
  414. array(
  415. 'copy_from' => $copy_id,
  416. )
  417. );
  418. $group_info = $smcFunc['db_fetch_assoc']($request);
  419. $smcFunc['db_free_result']($request);
  420. // ...and update the new membergroup with it.
  421. $smcFunc['db_query']('', '
  422. UPDATE {db_prefix}membergroups
  423. SET
  424. online_color = {string:online_color},
  425. max_messages = {int:max_messages},
  426. icons = {string:icons}
  427. WHERE id_group = {int:current_group}',
  428. array(
  429. 'max_messages' => $group_info['max_messages'],
  430. 'current_group' => $id_group,
  431. 'online_color' => $group_info['online_color'],
  432. 'icons' => $group_info['icons'],
  433. )
  434. );
  435. }
  436. // If inheriting say so...
  437. elseif ($_POST['perm_type'] == 'inherit')
  438. {
  439. $smcFunc['db_query']('', '
  440. UPDATE {db_prefix}membergroups
  441. SET id_parent = {int:copy_from}
  442. WHERE id_group = {int:current_group}',
  443. array(
  444. 'copy_from' => $copy_id,
  445. 'current_group' => $id_group,
  446. )
  447. );
  448. }
  449. }
  450. // Make sure all boards selected are stored in a proper array.
  451. $accesses = empty($_POST['boardaccess']) || !is_array($_POST['boardaccess']) ? array() : $_POST['boardaccess'];
  452. $changed_boards['allow'] = array();
  453. $changed_boards['deny'] = array();
  454. $changed_boards['ignore'] = array();
  455. foreach ($accesses as $group_id => $action)
  456. $changed_boards[$action][] = (int) $group_id;
  457. foreach (array('allow', 'deny') as $board_action)
  458. {
  459. // Only do this if they have special access requirements.
  460. if (!empty($changed_boards[$board_action]))
  461. $smcFunc['db_query']('', '
  462. UPDATE {db_prefix}boards
  463. SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END
  464. WHERE id_board IN ({array_int:board_list})',
  465. array(
  466. 'board_list' => $changed_boards[$board_action],
  467. 'blank_string' => '',
  468. 'group_id_string' => (string) $id_group,
  469. 'comma_group' => ',' . $id_group,
  470. 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
  471. )
  472. );
  473. }
  474. // If this is joinable then set it to show group membership in people's profiles.
  475. if (empty($modSettings['show_group_membership']) && $_POST['group_type'] > 1)
  476. updateSettings(array('show_group_membership' => 1));
  477. // Rebuild the group cache.
  478. updateSettings(array(
  479. 'settings_updated' => time(),
  480. ));
  481. // We did it.
  482. logAction('add_group', array('group' => $_POST['group_name']), 'admin');
  483. // Go change some more settings.
  484. redirectexit('action=admin;area=membergroups;sa=edit;group=' . $id_group);
  485. }
  486. // Just show the 'add membergroup' screen.
  487. $context['page_title'] = $txt['membergroups_new_group'];
  488. $context['sub_template'] = 'new_group';
  489. $context['post_group'] = isset($_REQUEST['postgroup']);
  490. $context['undefined_group'] = !isset($_REQUEST['postgroup']) && !isset($_REQUEST['generalgroup']);
  491. $context['allow_protected'] = allowedTo('admin_forum');
  492. if (!empty($modSettings['deny_boards_access']))
  493. loadLanguage('ManagePermissions');
  494. $result = $smcFunc['db_query']('', '
  495. SELECT id_group, group_name
  496. FROM {db_prefix}membergroups
  497. WHERE (id_group > {int:moderator_group} OR id_group = {int:global_mod_group})' . (empty($modSettings['permission_enable_postgroups']) ? '
  498. AND min_posts = {int:min_posts}' : '') . (allowedTo('admin_forum') ? '' : '
  499. AND group_type != {int:is_protected}') . '
  500. ORDER BY min_posts, id_group != {int:global_mod_group}, group_name',
  501. array(
  502. 'moderator_group' => 3,
  503. 'global_mod_group' => 2,
  504. 'min_posts' => -1,
  505. 'is_protected' => 1,
  506. )
  507. );
  508. $context['groups'] = array();
  509. while ($row = $smcFunc['db_fetch_assoc']($result))
  510. $context['groups'][] = array(
  511. 'id' => $row['id_group'],
  512. 'name' => $row['group_name']
  513. );
  514. $smcFunc['db_free_result']($result);
  515. $request = $smcFunc['db_query']('', '
  516. SELECT b.id_cat, c.name AS cat_name, b.id_board, b.name, b.child_level
  517. FROM {db_prefix}boards AS b
  518. LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
  519. ORDER BY board_order',
  520. array(
  521. )
  522. );
  523. $context['num_boards'] = $smcFunc['db_num_rows']($request);
  524. $context['categories'] = array();
  525. while ($row = $smcFunc['db_fetch_assoc']($request))
  526. {
  527. // This category hasn't been set up yet..
  528. if (!isset($context['categories'][$row['id_cat']]))
  529. $context['categories'][$row['id_cat']] = array(
  530. 'id' => $row['id_cat'],
  531. 'name' => $row['cat_name'],
  532. 'boards' => array()
  533. );
  534. // Set this board up, and let the template know when it's a child. (indent them..)
  535. $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
  536. 'id' => $row['id_board'],
  537. 'name' => $row['name'],
  538. 'child_level' => $row['child_level'],
  539. 'allow' => false,
  540. 'deny' => false
  541. );
  542. }
  543. $smcFunc['db_free_result']($request);
  544. // Now, let's sort the list of categories into the boards for templates that like that.
  545. $temp_boards = array();
  546. foreach ($context['categories'] as $category)
  547. {
  548. $temp_boards[] = array(
  549. 'name' => $category['name'],
  550. 'child_ids' => array_keys($category['boards'])
  551. );
  552. $temp_boards = array_merge($temp_boards, array_values($category['boards']));
  553. // Include a list of boards per category for easy toggling.
  554. $context['categories'][$category['id']]['child_ids'] = array_keys($category['boards']);
  555. }
  556. createToken('admin-mmg');
  557. }
  558. /**
  559. * Deleting a membergroup by URL (not implemented).
  560. * Called by ?action=admin;area=membergroups;sa=delete;group=x;session_var=y.
  561. * Requires the manage_membergroups permission.
  562. * Redirects to ?action=admin;area=membergroups.
  563. *
  564. * @todo look at this
  565. */
  566. function DeleteMembergroup()
  567. {
  568. global $sourcedir;
  569. checkSession('get');
  570. require_once($sourcedir . '/Subs-Membergroups.php');
  571. deleteMembergroups((int) $_REQUEST['group']);
  572. // Go back to the membergroup index.
  573. redirectexit('action=admin;area=membergroups;');
  574. }
  575. /**
  576. * Editing a membergroup.
  577. * Screen to edit a specific membergroup.
  578. * Called by ?action=admin;area=membergroups;sa=edit;group=x.
  579. * It requires the manage_membergroups permission.
  580. * Also handles the delete button of the edit form.
  581. * Redirects to ?action=admin;area=membergroups.
  582. *
  583. * @uses the edit_group sub template of ManageMembergroups.
  584. */
  585. function EditMembergroup()
  586. {
  587. global $context, $txt, $sourcedir, $modSettings, $smcFunc;
  588. $_REQUEST['group'] = isset($_REQUEST['group']) && $_REQUEST['group'] > 0 ? (int) $_REQUEST['group'] : 0;
  589. if (!empty($modSettings['deny_boards_access']))
  590. loadLanguage('ManagePermissions');
  591. // Make sure this group is editable.
  592. if (!empty($_REQUEST['group']))
  593. {
  594. $request = $smcFunc['db_query']('', '
  595. SELECT id_group
  596. FROM {db_prefix}membergroups
  597. WHERE id_group = {int:current_group}' . (allowedTo('admin_forum') ? '' : '
  598. AND group_type != {int:is_protected}') . '
  599. LIMIT {int:limit}',
  600. array(
  601. 'current_group' => $_REQUEST['group'],
  602. 'is_protected' => 1,
  603. 'limit' => 1,
  604. )
  605. );
  606. list ($_REQUEST['group']) = $smcFunc['db_fetch_row']($request);
  607. $smcFunc['db_free_result']($request);
  608. }
  609. // Now, do we have a valid id?
  610. if (empty($_REQUEST['group']))
  611. fatal_lang_error('membergroup_does_not_exist', false);
  612. // The delete this membergroup button was pressed.
  613. if (isset($_POST['delete']))
  614. {
  615. checkSession();
  616. validateToken('admin-mmg');
  617. require_once($sourcedir . '/Subs-Membergroups.php');
  618. deleteMembergroups($_REQUEST['group']);
  619. redirectexit('action=admin;area=membergroups;');
  620. }
  621. // A form was submitted with the new membergroup settings.
  622. elseif (isset($_POST['save']))
  623. {
  624. // Validate the session.
  625. checkSession();
  626. validateToken('admin-mmg');
  627. // Can they really inherit from this group?
  628. if (isset($_POST['group_inherit']) && $_POST['group_inherit'] != -2 && !allowedTo('admin_forum'))
  629. {
  630. $request = $smcFunc['db_query']('', '
  631. SELECT group_type
  632. FROM {db_prefix}membergroups
  633. WHERE id_group = {int:inherit_from}
  634. LIMIT {int:limit}',
  635. array(
  636. 'inherit_from' => $_POST['group_inherit'],
  637. 'limit' => 1,
  638. )
  639. );
  640. list ($inherit_type) = $smcFunc['db_fetch_row']($request);
  641. $smcFunc['db_free_result']($request);
  642. }
  643. // Set variables to their proper value.
  644. $_POST['max_messages'] = isset($_POST['max_messages']) ? (int) $_POST['max_messages'] : 0;
  645. $_POST['min_posts'] = isset($_POST['min_posts']) && isset($_POST['group_type']) && $_POST['group_type'] == -1 && $_REQUEST['group'] > 3 ? abs($_POST['min_posts']) : ($_REQUEST['group'] == 4 ? 0 : -1);
  646. $_POST['icons'] = (empty($_POST['icon_count']) || $_POST['icon_count'] < 0) ? '' : min((int) $_POST['icon_count'], 99) . '#' . $_POST['icon_image'];
  647. $_POST['group_desc'] = isset($_POST['group_desc']) && ($_REQUEST['group'] == 1 || (isset($_POST['group_type']) && $_POST['group_type'] != -1)) ? trim($_POST['group_desc']) : '';
  648. $_POST['group_type'] = !isset($_POST['group_type']) || $_POST['group_type'] < 0 || $_POST['group_type'] > 3 || ($_POST['group_type'] == 1 && !allowedTo('admin_forum')) ? 0 : (int) $_POST['group_type'];
  649. $_POST['group_hidden'] = empty($_POST['group_hidden']) || $_POST['min_posts'] != -1 || $_REQUEST['group'] == 3 ? 0 : (int) $_POST['group_hidden'];
  650. $_POST['group_inherit'] = $_REQUEST['group'] > 1 && $_REQUEST['group'] != 3 && (empty($inherit_type) || $inherit_type != 1) ? (int) $_POST['group_inherit'] : -2;
  651. //@todo Don't set online_color for the Moderators group?
  652. // Do the update of the membergroup settings.
  653. $smcFunc['db_query']('', '
  654. UPDATE {db_prefix}membergroups
  655. SET group_name = {string:group_name}, online_color = {string:online_color},
  656. max_messages = {int:max_messages}, min_posts = {int:min_posts}, icons = {string:icons},
  657. description = {string:group_desc}, group_type = {int:group_type}, hidden = {int:group_hidden},
  658. id_parent = {int:group_inherit}
  659. WHERE id_group = {int:current_group}',
  660. array(
  661. 'max_messages' => $_POST['max_messages'],
  662. 'min_posts' => $_POST['min_posts'],
  663. 'group_type' => $_POST['group_type'],
  664. 'group_hidden' => $_POST['group_hidden'],
  665. 'group_inherit' => $_POST['group_inherit'],
  666. 'current_group' => (int) $_REQUEST['group'],
  667. 'group_name' => $smcFunc['htmlspecialchars']($_POST['group_name']),
  668. 'online_color' => $_POST['online_color'],
  669. 'icons' => $_POST['icons'],
  670. 'group_desc' => $_POST['group_desc'],
  671. )
  672. );
  673. call_integration_hook('integrate_save_membergroup', array((int) $_REQUEST['group']));
  674. // Time to update the boards this membergroup has access to.
  675. if ($_REQUEST['group'] == 2 || $_REQUEST['group'] > 3)
  676. {
  677. $accesses = empty($_POST['boardaccess']) || !is_array($_POST['boardaccess']) ? array() : $_POST['boardaccess'];
  678. $changed_boards['allow'] = array();
  679. $changed_boards['deny'] = array();
  680. $changed_boards['ignore'] = array();
  681. foreach ($accesses as $group_id => $action)
  682. $changed_boards[$action][] = (int) $group_id;
  683. foreach (array('allow', 'deny') as $board_action)
  684. {
  685. // Find all board this group is in, but shouldn't be in.
  686. $request = $smcFunc['db_query']('', '
  687. SELECT id_board, {raw:column}
  688. FROM {db_prefix}boards
  689. WHERE FIND_IN_SET({string:current_group}, {raw:column}) != 0' . (empty($changed_boards[$board_action]) ? '' : '
  690. AND id_board NOT IN ({array_int:board_access_list})'),
  691. array(
  692. 'current_group' => (int) $_REQUEST['group'],
  693. 'board_access_list' => $changed_boards[$board_action],
  694. 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
  695. )
  696. );
  697. while ($row = $smcFunc['db_fetch_assoc']($request))
  698. $smcFunc['db_query']('', '
  699. UPDATE {db_prefix}boards
  700. SET {raw:column} = {string:member_group_access}
  701. WHERE id_board = {int:current_board}',
  702. array(
  703. 'current_board' => $row['id_board'],
  704. 'member_group_access' => implode(',', array_diff(explode(',', $row['member_groups']), array($_REQUEST['group']))),
  705. 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
  706. )
  707. );
  708. $smcFunc['db_free_result']($request);
  709. // Add the membergroup to all boards that hadn't been set yet.
  710. if (!empty($changed_boards[$board_action]))
  711. $smcFunc['db_query']('', '
  712. UPDATE {db_prefix}boards
  713. SET {raw:column} = CASE WHEN {raw:column} = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT({raw:column}, {string:comma_group}) END
  714. WHERE id_board IN ({array_int:board_list})
  715. AND FIND_IN_SET({int:current_group}, {raw:column}) = 0',
  716. array(
  717. 'board_list' => $changed_boards[$board_action],
  718. 'blank_string' => '',
  719. 'current_group' => (int) $_REQUEST['group'],
  720. 'group_id_string' => (string) (int) $_REQUEST['group'],
  721. 'comma_group' => ',' . $_REQUEST['group'],
  722. 'column' => $board_action == 'allow' ? 'member_groups' : 'deny_member_groups',
  723. )
  724. );
  725. }
  726. }
  727. // Remove everyone from this group!
  728. if ($_POST['min_posts'] != -1)
  729. {
  730. $smcFunc['db_query']('', '
  731. UPDATE {db_prefix}members
  732. SET id_group = {int:regular_member}
  733. WHERE id_group = {int:current_group}',
  734. array(
  735. 'regular_member' => 0,
  736. 'current_group' => (int) $_REQUEST['group'],
  737. )
  738. );
  739. $request = $smcFunc['db_query']('', '
  740. SELECT id_member, additional_groups
  741. FROM {db_prefix}members
  742. WHERE FIND_IN_SET({string:current_group}, additional_groups) != 0',
  743. array(
  744. 'current_group' => (int) $_REQUEST['group'],
  745. )
  746. );
  747. $updates = array();
  748. while ($row = $smcFunc['db_fetch_assoc']($request))
  749. $updates[$row['additional_groups']][] = $row['id_member'];
  750. $smcFunc['db_free_result']($request);
  751. foreach ($updates as $additional_groups => $memberArray)
  752. updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group'])))));
  753. }
  754. elseif ($_REQUEST['group'] != 3)
  755. {
  756. // Making it a hidden group? If so remove everyone with it as primary group (Actually, just make them additional).
  757. if ($_POST['group_hidden'] == 2)
  758. {
  759. $request = $smcFunc['db_query']('', '
  760. SELECT id_member, additional_groups
  761. FROM {db_prefix}members
  762. WHERE id_group = {int:current_group}
  763. AND FIND_IN_SET({int:current_group}, additional_groups) = 0',
  764. array(
  765. 'current_group' => (int) $_REQUEST['group'],
  766. )
  767. );
  768. $updates = array();
  769. while ($row = $smcFunc['db_fetch_assoc']($request))
  770. $updates[$row['additional_groups']][] = $row['id_member'];
  771. $smcFunc['db_free_result']($request);
  772. foreach ($updates as $additional_groups => $memberArray)
  773. updateMemberData($memberArray, array('additional_groups' => implode(',', array_merge(explode(',', $additional_groups), array((int) $_REQUEST['group'])))));
  774. $smcFunc['db_query']('', '
  775. UPDATE {db_prefix}members
  776. SET id_group = {int:regular_member}
  777. WHERE id_group = {int:current_group}',
  778. array(
  779. 'regular_member' => 0,
  780. 'current_group' => $_REQUEST['group'],
  781. )
  782. );
  783. }
  784. // Either way, let's check our "show group membership" setting is correct.
  785. $request = $smcFunc['db_query']('', '
  786. SELECT COUNT(*)
  787. FROM {db_prefix}membergroups
  788. WHERE group_type > {int:non_joinable}',
  789. array(
  790. 'non_joinable' => 1,
  791. )
  792. );
  793. list ($have_joinable) = $smcFunc['db_fetch_row']($request);
  794. $smcFunc['db_free_result']($request);
  795. // Do we need to update the setting?
  796. if ((empty($modSettings['show_group_membership']) && $have_joinable) || (!empty($modSettings['show_group_membership']) && !$have_joinable))
  797. updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0));
  798. }
  799. // Do we need to set inherited permissions?
  800. if ($_POST['group_inherit'] != -2 && $_POST['group_inherit'] != $_POST['old_inherit'])
  801. {
  802. require_once($sourcedir . '/ManagePermissions.php');
  803. updateChildPermissions($_POST['group_inherit']);
  804. }
  805. // Finally, moderators!
  806. $moderator_string = isset($_POST['group_moderators']) ? trim($_POST['group_moderators']) : '';
  807. $smcFunc['db_query']('', '
  808. DELETE FROM {db_prefix}group_moderators
  809. WHERE id_group = {int:current_group}',
  810. array(
  811. 'current_group' => $_REQUEST['group'],
  812. )
  813. );
  814. if ((!empty($moderator_string) || !empty($_POST['moderator_list'])) && $_POST['min_posts'] == -1 && $_REQUEST['group'] != 3)
  815. {
  816. // Get all the usernames from the string
  817. if (!empty($moderator_string))
  818. {
  819. $moderator_string = strtr(preg_replace('~&amp;#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', htmlspecialchars($moderator_string), ENT_QUOTES), array('&quot;' => '"'));
  820. preg_match_all('~"([^"]+)"~', $moderator_string, $matches);
  821. $moderators = array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $moderator_string)));
  822. for ($k = 0, $n = count($moderators); $k < $n; $k++)
  823. {
  824. $moderators[$k] = trim($moderators[$k]);
  825. if (strlen($moderators[$k]) == 0)
  826. unset($moderators[$k]);
  827. }
  828. // Find all the id_member's for the member_name's in the list.
  829. $group_moderators = array();
  830. if (!empty($moderators))
  831. {
  832. $request = $smcFunc['db_query']('', '
  833. SELECT id_member
  834. FROM {db_prefix}members
  835. WHERE member_name IN ({array_string:moderators}) OR real_name IN ({array_string:moderators})
  836. LIMIT ' . count($moderators),
  837. array(
  838. 'moderators' => $moderators,
  839. )
  840. );
  841. while ($row = $smcFunc['db_fetch_assoc']($request))
  842. $group_moderators[] = $row['id_member'];
  843. $smcFunc['db_free_result']($request);
  844. }
  845. }
  846. else
  847. {
  848. $moderators = array();
  849. foreach ($_POST['moderator_list'] as $moderator)
  850. $moderators[] = (int) $moderator;
  851. $group_moderators = array();
  852. if (!empty($moderators))
  853. {
  854. $request = $smcFunc['db_query']('', '
  855. SELECT id_member
  856. FROM {db_prefix}members
  857. WHERE id_member IN ({array_int:moderators})
  858. LIMIT {int:num_moderators}',
  859. array(
  860. 'moderators' => $moderators,
  861. 'num_moderators' => count($moderators),
  862. )
  863. );
  864. while ($row = $smcFunc['db_fetch_assoc']($request))
  865. $group_moderators[] = $row['id_member'];
  866. $smcFunc['db_free_result']($request);
  867. }
  868. }
  869. // Found some?
  870. if (!empty($group_moderators))
  871. {
  872. $mod_insert = array();
  873. foreach ($group_moderators as $moderator)
  874. $mod_insert[] = array($_REQUEST['group'], $moderator);
  875. $smcFunc['db_insert']('insert',
  876. '{db_prefix}group_moderators',
  877. array('id_group' => 'int', 'id_member' => 'int'),
  878. $mod_insert,
  879. array('id_group', 'id_member')
  880. );
  881. }
  882. }
  883. // There might have been some post group changes.
  884. updateStats('postgroups');
  885. // We've definitely changed some group stuff.
  886. updateSettings(array(
  887. 'settings_updated' => time(),
  888. ));
  889. // Log the edit.
  890. logAction('edited_group', array('group' => $_POST['group_name']), 'admin');
  891. redirectexit('action=admin;area=membergroups');
  892. }
  893. // Fetch the current group information.
  894. $request = $smcFunc['db_query']('', '
  895. SELECT group_name, description, min_posts, online_color, max_messages, icons, group_type, hidden, id_parent
  896. FROM {db_prefix}membergroups
  897. WHERE id_group = {int:current_group}
  898. LIMIT 1',
  899. array(
  900. 'current_group' => (int) $_REQUEST['group'],
  901. )
  902. );
  903. if ($smcFunc['db_num_rows']($request) == 0)
  904. fatal_lang_error('membergroup_does_not_exist', false);
  905. $row = $smcFunc['db_fetch_assoc']($request);
  906. $smcFunc['db_free_result']($request);
  907. $row['icons'] = explode('#', $row['icons']);
  908. $context['group'] = array(
  909. 'id' => $_REQUEST['group'],
  910. 'name' => $row['group_name'],
  911. 'description' => htmlspecialchars($row['description']),
  912. 'editable_name' => $row['group_name'],
  913. 'color' => $row['online_color'],
  914. 'min_posts' => $row['min_posts'],
  915. 'max_messages' => $row['max_messages'],
  916. 'icon_count' => (int) $row['icons'][0],
  917. 'icon_image' => isset($row['icons'][1]) ? $row['icons'][1] : '',
  918. 'is_post_group' => $row['min_posts'] != -1,
  919. 'type' => $row['min_posts'] != -1 ? 0 : $row['group_type'],
  920. 'hidden' => $row['min_posts'] == -1 ? $row['hidden'] : 0,
  921. 'inherited_from' => $row['id_parent'],
  922. 'allow_post_group' => $_REQUEST['group'] == 2 || $_REQUEST['group'] > 4,
  923. 'allow_delete' => $_REQUEST['group'] == 2 || $_REQUEST['group'] > 4,
  924. 'allow_protected' => allowedTo('admin_forum'),
  925. );
  926. // Get any moderators for this group
  927. $request = $smcFunc['db_query']('', '
  928. SELECT mem.id_member, mem.real_name
  929. FROM {db_prefix}group_moderators AS mods
  930. INNER JOIN {db_prefix}members AS mem ON (mem.id_member = mods.id_member)
  931. WHERE mods.id_group = {int:current_group}',
  932. array(
  933. 'current_group' => $_REQUEST['group'],
  934. )
  935. );
  936. $context['group']['moderators'] = array();
  937. while ($row = $smcFunc['db_fetch_assoc']($request))
  938. $context['group']['moderators'][$row['id_member']] = $row['real_name'];
  939. $smcFunc['db_free_result']($request);
  940. $context['group']['moderator_list'] = empty($context['group']['moderators']) ? '' : '&quot;' . implode('&quot;, &quot;', $context['group']['moderators']) . '&quot;';
  941. if (!empty($context['group']['moderators']))
  942. list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1);
  943. // Get a list of boards this membergroup is allowed to see.
  944. $context['boards'] = array();
  945. if ($_REQUEST['group'] == 2 || $_REQUEST['group'] > 3)
  946. {
  947. $request = $smcFunc['db_query']('', '
  948. SELECT b.id_cat, c.name as cat_name, b.id_board, b.name, b.child_level,
  949. FIND_IN_SET({string:current_group}, b.member_groups) != 0 AS can_access, FIND_IN_SET({string:current_group}, b.deny_member_groups) != 0 AS cannot_access
  950. FROM {db_prefix}boards AS b
  951. LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
  952. ORDER BY board_order',
  953. array(
  954. 'current_group' => (int) $_REQUEST['group'],
  955. )
  956. );
  957. $context['categories'] = array();
  958. while ($row = $smcFunc['db_fetch_assoc']($request))
  959. {
  960. // This category hasn't been set up yet..
  961. if (!isset($context['categories'][$row['id_cat']]))
  962. $context['categories'][$row['id_cat']] = array(
  963. 'id' => $row['id_cat'],
  964. 'name' => $row['cat_name'],
  965. 'boards' => array()
  966. );
  967. // Set this board up, and let the template know when it's a child. (indent them..)
  968. $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
  969. 'id' => $row['id_board'],
  970. 'name' => $row['name'],
  971. 'child_level' => $row['child_level'],
  972. 'allow' => !(empty($row['can_access']) || $row['can_access'] == 'f'),
  973. 'deny' => !(empty($row['cannot_access']) || $row['cannot_access'] == 'f'),
  974. );
  975. }
  976. $smcFunc['db_free_result']($request);
  977. // Now, let's sort the list of categories into the boards for templates that like that.
  978. $temp_boards = array();
  979. foreach ($context['categories'] as $category)
  980. {
  981. $temp_boards[] = array(
  982. 'name' => $category['name'],
  983. 'child_ids' => array_keys($category['boards'])
  984. );
  985. $temp_boards = array_merge($temp_boards, array_values($category['boards']));
  986. // Include a list of boards per category for easy toggling.
  987. $context['categories'][$category['id']]['child_ids'] = array_keys($category['boards']);
  988. }
  989. $max_boards = ceil(count($temp_boards) / 2);
  990. if ($max_boards == 1)
  991. $max_boards = 2;
  992. }
  993. // Finally, get all the groups this could be inherited off.
  994. $request = $smcFunc['db_query']('', '
  995. SELECT id_group, group_name
  996. FROM {db_prefix}membergroups
  997. WHERE id_group != {int:current_group}' .
  998. (empty($modSettings['permission_enable_postgroups']) ? '
  999. AND min_posts = {int:min_posts}' : '') . (allowedTo('admin_forum') ? '' : '
  1000. AND group_type != {int:is_protected}') . '
  1001. AND id_group NOT IN (1, 3)
  1002. AND id_parent = {int:not_inherited}',
  1003. array(
  1004. 'current_group' => (int) $_REQUEST['group'],
  1005. 'min_posts' => -1,
  1006. 'not_inherited' => -2,
  1007. 'is_protected' => 1,
  1008. )
  1009. );
  1010. $context['inheritable_groups'] = array();
  1011. while ($row = $smcFunc['db_fetch_assoc']($request))
  1012. $context['inheritable_groups'][$row['id_group']] = $row['group_name'];
  1013. $smcFunc['db_free_result']($request);
  1014. call_integration_hook('integrate_view_membergroup');
  1015. $context['sub_template'] = 'edit_group';
  1016. $context['page_title'] = $txt['membergroups_edit_group'];
  1017. createToken('admin-mmg');
  1018. }
  1019. /**
  1020. * Set some general membergroup settings and permissions.
  1021. * Called by ?action=admin;area=membergroups;sa=settings
  1022. * Requires the admin_forum permission (and manage_permissions for changing permissions)
  1023. * Redirects to itself.
  1024. *
  1025. * @uses membergroup_settings sub template of ManageMembergroups.
  1026. */
  1027. function ModifyMembergroupsettings()
  1028. {
  1029. global $context, $sourcedir, $scripturl, $modSettings, $txt;
  1030. $context['sub_template'] = 'show_settings';
  1031. $context['page_title'] = $txt['membergroups_settings'];
  1032. // Needed for the settings functions.
  1033. require_once($sourcedir . '/ManageServer.php');
  1034. // Don't allow assignment of guests.
  1035. $context['permissions_excluded'] = array(-1);
  1036. // Only one thing here!
  1037. $config_vars = array(
  1038. array('permissions', 'manage_membergroups'),
  1039. );
  1040. call_integration_hook('integrate_modify_membergroup_settings', array(&$config_vars));
  1041. if (isset($_REQUEST['save']))
  1042. {
  1043. checkSession();
  1044. call_integration_hook('integrate_save_membergroup_settings');
  1045. // Yeppers, saving this...
  1046. saveDBSettings($config_vars);
  1047. redirectexit('action=admin;area=membergroups;sa=settings');
  1048. }
  1049. // Some simple context.
  1050. $context['post_url'] = $scripturl . '?action=admin;area=membergroups;save;sa=settings';
  1051. $context['settings_title'] = $txt['membergroups_settings'];
  1052. // We need this for the in-line permissions
  1053. createToken('admin-mp');
  1054. prepareDBSettingContext($config_vars);
  1055. }
  1056. ?>