ManageMembergroups.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161
  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 reqWin(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 reqWin(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. 'stars' => array(
  113. 'header' => array(
  114. 'value' => $txt['membergroups_stars'],
  115. ),
  116. 'data' => array(
  117. 'function' => create_function('$rowData', '
  118. global $settings;
  119. $stars = explode(\'#\', $rowData[\'stars\']);
  120. // In case no stars are setup, return with nothing
  121. if (empty($stars[0]) || empty($stars[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\'], $stars[1]);
  127. return str_repeat($image, $stars[0]);
  128. }
  129. '),
  130. ),
  131. 'sort' => array(
  132. 'default' => 'stars',
  133. 'reverse' => 'stars 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. 'stars' => array(
  213. 'header' => array(
  214. 'value' => $txt['membergroups_stars'],
  215. ),
  216. 'data' => array(
  217. 'function' => create_function('$rowData', '
  218. global $settings;
  219. $stars = explode(\'#\', $rowData[\'stars\']);
  220. if (empty($stars[0]) || empty($stars[1]))
  221. return \'\';
  222. else
  223. {
  224. $star_image = sprintf(\'<img src="%1$s/%2$s" alt="*" />\', $settings[\'images_url\'], $stars[1]);
  225. return str_repeat($star_image, $stars[0]);
  226. }
  227. '),
  228. ),
  229. 'sort' => array(
  230. 'default' => 'CASE WHEN id_group < 4 THEN id_group ELSE 4 END, stars',
  231. 'reverse' => 'CASE WHEN id_group < 4 THEN id_group ELSE 4 END, stars 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. 'stars' => '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, stars
  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. stars = {string:stars}
  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. 'stars' => $group_info['stars'],
  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. $_POST['boardaccess'] = empty($_POST['boardaccess']) || !is_array($_POST['boardaccess']) ? array() : $_POST['boardaccess'];
  452. foreach ($_POST['boardaccess'] as $key => $value)
  453. $_POST['boardaccess'][$key] = (int) $value;
  454. // Only do this if they have special access requirements.
  455. if (!empty($_POST['boardaccess']))
  456. $smcFunc['db_query']('', '
  457. UPDATE {db_prefix}boards
  458. SET member_groups = CASE WHEN member_groups = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT(member_groups, {string:comma_group}) END
  459. WHERE id_board IN ({array_int:board_list})',
  460. array(
  461. 'board_list' => $_POST['boardaccess'],
  462. 'blank_string' => '',
  463. 'group_id_string' => (string) $id_group,
  464. 'comma_group' => ',' . $id_group,
  465. )
  466. );
  467. // If this is joinable then set it to show group membership in people's profiles.
  468. if (empty($modSettings['show_group_membership']) && $_POST['group_type'] > 1)
  469. updateSettings(array('show_group_membership' => 1));
  470. // Rebuild the group cache.
  471. updateSettings(array(
  472. 'settings_updated' => time(),
  473. ));
  474. // We did it.
  475. logAction('add_group', array('group' => $_POST['group_name']), 'admin');
  476. // Go change some more settings.
  477. redirectexit('action=admin;area=membergroups;sa=edit;group=' . $id_group);
  478. }
  479. // Just show the 'add membergroup' screen.
  480. $context['page_title'] = $txt['membergroups_new_group'];
  481. $context['sub_template'] = 'new_group';
  482. $context['post_group'] = isset($_REQUEST['postgroup']);
  483. $context['undefined_group'] = !isset($_REQUEST['postgroup']) && !isset($_REQUEST['generalgroup']);
  484. $context['allow_protected'] = allowedTo('admin_forum');
  485. $result = $smcFunc['db_query']('', '
  486. SELECT id_group, group_name
  487. FROM {db_prefix}membergroups
  488. WHERE (id_group > {int:moderator_group} OR id_group = {int:global_mod_group})' . (empty($modSettings['permission_enable_postgroups']) ? '
  489. AND min_posts = {int:min_posts}' : '') . (allowedTo('admin_forum') ? '' : '
  490. AND group_type != {int:is_protected}') . '
  491. ORDER BY min_posts, id_group != {int:global_mod_group}, group_name',
  492. array(
  493. 'moderator_group' => 3,
  494. 'global_mod_group' => 2,
  495. 'min_posts' => -1,
  496. 'is_protected' => 1,
  497. )
  498. );
  499. $context['groups'] = array();
  500. while ($row = $smcFunc['db_fetch_assoc']($result))
  501. $context['groups'][] = array(
  502. 'id' => $row['id_group'],
  503. 'name' => $row['group_name']
  504. );
  505. $smcFunc['db_free_result']($result);
  506. $request = $smcFunc['db_query']('', '
  507. SELECT b.id_cat, c.name AS cat_name, b.id_board, b.name, b.child_level
  508. FROM {db_prefix}boards AS b
  509. LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
  510. ORDER BY board_order',
  511. array(
  512. )
  513. );
  514. $context['num_boards'] = $smcFunc['db_num_rows']($request);
  515. $context['categories'] = array();
  516. while ($row = $smcFunc['db_fetch_assoc']($request))
  517. {
  518. // This category hasn't been set up yet..
  519. if (!isset($context['categories'][$row['id_cat']]))
  520. $context['categories'][$row['id_cat']] = array(
  521. 'id' => $row['id_cat'],
  522. 'name' => $row['cat_name'],
  523. 'boards' => array()
  524. );
  525. // Set this board up, and let the template know when it's a child. (indent them..)
  526. $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
  527. 'id' => $row['id_board'],
  528. 'name' => $row['name'],
  529. 'child_level' => $row['child_level'],
  530. 'selected' => false
  531. );
  532. }
  533. $smcFunc['db_free_result']($request);
  534. // Now, let's sort the list of categories into the boards for templates that like that.
  535. $temp_boards = array();
  536. foreach ($context['categories'] as $category)
  537. {
  538. $temp_boards[] = array(
  539. 'name' => $category['name'],
  540. 'child_ids' => array_keys($category['boards'])
  541. );
  542. $temp_boards = array_merge($temp_boards, array_values($category['boards']));
  543. // Include a list of boards per category for easy toggling.
  544. $context['categories'][$category['id']]['child_ids'] = array_keys($category['boards']);
  545. }
  546. createToken('admin-mmg');
  547. }
  548. /**
  549. * Deleting a membergroup by URL (not implemented).
  550. * Called by ?action=admin;area=membergroups;sa=delete;group=x;session_var=y.
  551. * Requires the manage_membergroups permission.
  552. * Redirects to ?action=admin;area=membergroups.
  553. *
  554. * @todo look at this
  555. */
  556. function DeleteMembergroup()
  557. {
  558. global $sourcedir;
  559. checkSession('get');
  560. require_once($sourcedir . '/Subs-Membergroups.php');
  561. deleteMembergroups((int) $_REQUEST['group']);
  562. // Go back to the membergroup index.
  563. redirectexit('action=admin;area=membergroups;');
  564. }
  565. /**
  566. * Editing a membergroup.
  567. * Screen to edit a specific membergroup.
  568. * Called by ?action=admin;area=membergroups;sa=edit;group=x.
  569. * It requires the manage_membergroups permission.
  570. * Also handles the delete button of the edit form.
  571. * Redirects to ?action=admin;area=membergroups.
  572. *
  573. * @uses the edit_group sub template of ManageMembergroups.
  574. */
  575. function EditMembergroup()
  576. {
  577. global $context, $txt, $sourcedir, $modSettings, $smcFunc;
  578. $_REQUEST['group'] = isset($_REQUEST['group']) && $_REQUEST['group'] > 0 ? (int) $_REQUEST['group'] : 0;
  579. // Make sure this group is editable.
  580. if (!empty($_REQUEST['group']))
  581. {
  582. $request = $smcFunc['db_query']('', '
  583. SELECT id_group
  584. FROM {db_prefix}membergroups
  585. WHERE id_group = {int:current_group}' . (allowedTo('admin_forum') ? '' : '
  586. AND group_type != {int:is_protected}') . '
  587. LIMIT {int:limit}',
  588. array(
  589. 'current_group' => $_REQUEST['group'],
  590. 'is_protected' => 1,
  591. 'limit' => 1,
  592. )
  593. );
  594. list ($_REQUEST['group']) = $smcFunc['db_fetch_row']($request);
  595. $smcFunc['db_free_result']($request);
  596. }
  597. // Now, do we have a valid id?
  598. if (empty($_REQUEST['group']))
  599. fatal_lang_error('membergroup_does_not_exist', false);
  600. // The delete this membergroup button was pressed.
  601. if (isset($_POST['delete']))
  602. {
  603. checkSession();
  604. validateToken('admin-mmg');
  605. require_once($sourcedir . '/Subs-Membergroups.php');
  606. deleteMembergroups($_REQUEST['group']);
  607. redirectexit('action=admin;area=membergroups;');
  608. }
  609. // A form was submitted with the new membergroup settings.
  610. elseif (isset($_POST['save']))
  611. {
  612. // Validate the session.
  613. checkSession();
  614. validateToken('admin-mmg');
  615. // Can they really inherit from this group?
  616. if (isset($_POST['group_inherit']) && $_POST['group_inherit'] != -2 && !allowedTo('admin_forum'))
  617. {
  618. $request = $smcFunc['db_query']('', '
  619. SELECT group_type
  620. FROM {db_prefix}membergroups
  621. WHERE id_group = {int:inherit_from}
  622. LIMIT {int:limit}',
  623. array(
  624. 'inherit_from' => $_POST['group_inherit'],
  625. 'limit' => 1,
  626. )
  627. );
  628. list ($inherit_type) = $smcFunc['db_fetch_row']($request);
  629. $smcFunc['db_free_result']($request);
  630. }
  631. // Set variables to their proper value.
  632. $_POST['max_messages'] = isset($_POST['max_messages']) ? (int) $_POST['max_messages'] : 0;
  633. $_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);
  634. $_POST['stars'] = (empty($_POST['star_count']) || $_POST['star_count'] < 0) ? '' : min((int) $_POST['star_count'], 99) . '#' . $_POST['star_image'];
  635. $_POST['group_desc'] = isset($_POST['group_desc']) && ($_REQUEST['group'] == 1 || (isset($_POST['group_type']) && $_POST['group_type'] != -1)) ? trim($_POST['group_desc']) : '';
  636. $_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'];
  637. $_POST['group_hidden'] = empty($_POST['group_hidden']) || $_POST['min_posts'] != -1 || $_REQUEST['group'] == 3 ? 0 : (int) $_POST['group_hidden'];
  638. $_POST['group_inherit'] = $_REQUEST['group'] > 1 && $_REQUEST['group'] != 3 && (empty($inherit_type) || $inherit_type != 1) ? (int) $_POST['group_inherit'] : -2;
  639. //@todo Don't set online_color for the Moderators group?
  640. // Do the update of the membergroup settings.
  641. $smcFunc['db_query']('', '
  642. UPDATE {db_prefix}membergroups
  643. SET group_name = {string:group_name}, online_color = {string:online_color},
  644. max_messages = {int:max_messages}, min_posts = {int:min_posts}, stars = {string:stars},
  645. description = {string:group_desc}, group_type = {int:group_type}, hidden = {int:group_hidden},
  646. id_parent = {int:group_inherit}
  647. WHERE id_group = {int:current_group}',
  648. array(
  649. 'max_messages' => $_POST['max_messages'],
  650. 'min_posts' => $_POST['min_posts'],
  651. 'group_type' => $_POST['group_type'],
  652. 'group_hidden' => $_POST['group_hidden'],
  653. 'group_inherit' => $_POST['group_inherit'],
  654. 'current_group' => (int) $_REQUEST['group'],
  655. 'group_name' => $smcFunc['htmlspecialchars']($_POST['group_name']),
  656. 'online_color' => $_POST['online_color'],
  657. 'stars' => $_POST['stars'],
  658. 'group_desc' => $_POST['group_desc'],
  659. )
  660. );
  661. call_integration_hook('integrate_save_membergroup', array((int) $_REQUEST['group']));
  662. // Time to update the boards this membergroup has access to.
  663. if ($_REQUEST['group'] == 2 || $_REQUEST['group'] > 3)
  664. {
  665. $_POST['boardaccess'] = empty($_POST['boardaccess']) || !is_array($_POST['boardaccess']) ? array() : $_POST['boardaccess'];
  666. foreach ($_POST['boardaccess'] as $key => $value)
  667. $_POST['boardaccess'][$key] = (int) $value;
  668. // Find all board this group is in, but shouldn't be in.
  669. $request = $smcFunc['db_query']('', '
  670. SELECT id_board, member_groups
  671. FROM {db_prefix}boards
  672. WHERE FIND_IN_SET({string:current_group}, member_groups) != 0' . (empty($_POST['boardaccess']) ? '' : '
  673. AND id_board NOT IN ({array_int:board_access_list})'),
  674. array(
  675. 'current_group' => (int) $_REQUEST['group'],
  676. 'board_access_list' => $_POST['boardaccess'],
  677. )
  678. );
  679. while ($row = $smcFunc['db_fetch_assoc']($request))
  680. $smcFunc['db_query']('', '
  681. UPDATE {db_prefix}boards
  682. SET member_groups = {string:member_group_access}
  683. WHERE id_board = {int:current_board}',
  684. array(
  685. 'current_board' => $row['id_board'],
  686. 'member_group_access' => implode(',', array_diff(explode(',', $row['member_groups']), array($_REQUEST['group']))),
  687. )
  688. );
  689. $smcFunc['db_free_result']($request);
  690. // Add the membergroup to all boards that hadn't been set yet.
  691. if (!empty($_POST['boardaccess']))
  692. $smcFunc['db_query']('', '
  693. UPDATE {db_prefix}boards
  694. SET member_groups = CASE WHEN member_groups = {string:blank_string} THEN {string:group_id_string} ELSE CONCAT(member_groups, {string:comma_group}) END
  695. WHERE id_board IN ({array_int:board_list})
  696. AND FIND_IN_SET({int:current_group}, member_groups) = 0',
  697. array(
  698. 'board_list' => $_POST['boardaccess'],
  699. 'blank_string' => '',
  700. 'current_group' => (int) $_REQUEST['group'],
  701. 'group_id_string' => (string) (int) $_REQUEST['group'],
  702. 'comma_group' => ',' . $_REQUEST['group'],
  703. )
  704. );
  705. }
  706. // Remove everyone from this group!
  707. if ($_POST['min_posts'] != -1)
  708. {
  709. $smcFunc['db_query']('', '
  710. UPDATE {db_prefix}members
  711. SET id_group = {int:regular_member}
  712. WHERE id_group = {int:current_group}',
  713. array(
  714. 'regular_member' => 0,
  715. 'current_group' => (int) $_REQUEST['group'],
  716. )
  717. );
  718. $request = $smcFunc['db_query']('', '
  719. SELECT id_member, additional_groups
  720. FROM {db_prefix}members
  721. WHERE FIND_IN_SET({string:current_group}, additional_groups) != 0',
  722. array(
  723. 'current_group' => (int) $_REQUEST['group'],
  724. )
  725. );
  726. $updates = array();
  727. while ($row = $smcFunc['db_fetch_assoc']($request))
  728. $updates[$row['additional_groups']][] = $row['id_member'];
  729. $smcFunc['db_free_result']($request);
  730. foreach ($updates as $additional_groups => $memberArray)
  731. updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), array((int) $_REQUEST['group'])))));
  732. }
  733. elseif ($_REQUEST['group'] != 3)
  734. {
  735. // Making it a hidden group? If so remove everyone with it as primary group (Actually, just make them additional).
  736. if ($_POST['group_hidden'] == 2)
  737. {
  738. $request = $smcFunc['db_query']('', '
  739. SELECT id_member, additional_groups
  740. FROM {db_prefix}members
  741. WHERE id_group = {int:current_group}
  742. AND FIND_IN_SET({int: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_merge(explode(',', $additional_groups), array((int) $_REQUEST['group'])))));
  753. $smcFunc['db_query']('', '
  754. UPDATE {db_prefix}members
  755. SET id_group = {int:regular_member}
  756. WHERE id_group = {int:current_group}',
  757. array(
  758. 'regular_member' => 0,
  759. 'current_group' => $_REQUEST['group'],
  760. )
  761. );
  762. }
  763. // Either way, let's check our "show group membership" setting is correct.
  764. $request = $smcFunc['db_query']('', '
  765. SELECT COUNT(*)
  766. FROM {db_prefix}membergroups
  767. WHERE group_type > {int:non_joinable}',
  768. array(
  769. 'non_joinable' => 1,
  770. )
  771. );
  772. list ($have_joinable) = $smcFunc['db_fetch_row']($request);
  773. $smcFunc['db_free_result']($request);
  774. // Do we need to update the setting?
  775. if ((empty($modSettings['show_group_membership']) && $have_joinable) || (!empty($modSettings['show_group_membership']) && !$have_joinable))
  776. updateSettings(array('show_group_membership' => $have_joinable ? 1 : 0));
  777. }
  778. // Do we need to set inherited permissions?
  779. if ($_POST['group_inherit'] != -2 && $_POST['group_inherit'] != $_POST['old_inherit'])
  780. {
  781. require_once($sourcedir . '/ManagePermissions.php');
  782. updateChildPermissions($_POST['group_inherit']);
  783. }
  784. // Finally, moderators!
  785. $moderator_string = isset($_POST['group_moderators']) ? trim($_POST['group_moderators']) : '';
  786. $smcFunc['db_query']('', '
  787. DELETE FROM {db_prefix}group_moderators
  788. WHERE id_group = {int:current_group}',
  789. array(
  790. 'current_group' => $_REQUEST['group'],
  791. )
  792. );
  793. if ((!empty($moderator_string) || !empty($_POST['moderator_list'])) && $_POST['min_posts'] == -1 && $_REQUEST['group'] != 3)
  794. {
  795. // Get all the usernames from the string
  796. if (!empty($moderator_string))
  797. {
  798. $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;' => '"'));
  799. preg_match_all('~"([^"]+)"~', $moderator_string, $matches);
  800. $moderators = array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $moderator_string)));
  801. for ($k = 0, $n = count($moderators); $k < $n; $k++)
  802. {
  803. $moderators[$k] = trim($moderators[$k]);
  804. if (strlen($moderators[$k]) == 0)
  805. unset($moderators[$k]);
  806. }
  807. // Find all the id_member's for the member_name's in the list.
  808. $group_moderators = array();
  809. if (!empty($moderators))
  810. {
  811. $request = $smcFunc['db_query']('', '
  812. SELECT id_member
  813. FROM {db_prefix}members
  814. WHERE member_name IN ({array_string:moderators}) OR real_name IN ({array_string:moderators})
  815. LIMIT ' . count($moderators),
  816. array(
  817. 'moderators' => $moderators,
  818. )
  819. );
  820. while ($row = $smcFunc['db_fetch_assoc']($request))
  821. $group_moderators[] = $row['id_member'];
  822. $smcFunc['db_free_result']($request);
  823. }
  824. }
  825. else
  826. {
  827. $moderators = array();
  828. foreach ($_POST['moderator_list'] as $moderator)
  829. $moderators[] = (int) $moderator;
  830. $group_moderators = array();
  831. if (!empty($moderators))
  832. {
  833. $request = $smcFunc['db_query']('', '
  834. SELECT id_member
  835. FROM {db_prefix}members
  836. WHERE id_member IN ({array_int:moderators})
  837. LIMIT {int:num_moderators}',
  838. array(
  839. 'moderators' => $moderators,
  840. 'num_moderators' => count($moderators),
  841. )
  842. );
  843. while ($row = $smcFunc['db_fetch_assoc']($request))
  844. $group_moderators[] = $row['id_member'];
  845. $smcFunc['db_free_result']($request);
  846. }
  847. }
  848. // Found some?
  849. if (!empty($group_moderators))
  850. {
  851. $mod_insert = array();
  852. foreach ($group_moderators as $moderator)
  853. $mod_insert[] = array($_REQUEST['group'], $moderator);
  854. $smcFunc['db_insert']('insert',
  855. '{db_prefix}group_moderators',
  856. array('id_group' => 'int', 'id_member' => 'int'),
  857. $mod_insert,
  858. array('id_group', 'id_member')
  859. );
  860. }
  861. }
  862. // There might have been some post group changes.
  863. updateStats('postgroups');
  864. // We've definitely changed some group stuff.
  865. updateSettings(array(
  866. 'settings_updated' => time(),
  867. ));
  868. // Log the edit.
  869. logAction('edited_group', array('group' => $_POST['group_name']), 'admin');
  870. redirectexit('action=admin;area=membergroups');
  871. }
  872. // Fetch the current group information.
  873. $request = $smcFunc['db_query']('', '
  874. SELECT group_name, description, min_posts, online_color, max_messages, stars, group_type, hidden, id_parent
  875. FROM {db_prefix}membergroups
  876. WHERE id_group = {int:current_group}
  877. LIMIT 1',
  878. array(
  879. 'current_group' => (int) $_REQUEST['group'],
  880. )
  881. );
  882. if ($smcFunc['db_num_rows']($request) == 0)
  883. fatal_lang_error('membergroup_does_not_exist', false);
  884. $row = $smcFunc['db_fetch_assoc']($request);
  885. $smcFunc['db_free_result']($request);
  886. $row['stars'] = explode('#', $row['stars']);
  887. $context['group'] = array(
  888. 'id' => $_REQUEST['group'],
  889. 'name' => $row['group_name'],
  890. 'description' => htmlspecialchars($row['description']),
  891. 'editable_name' => $row['group_name'],
  892. 'color' => $row['online_color'],
  893. 'min_posts' => $row['min_posts'],
  894. 'max_messages' => $row['max_messages'],
  895. 'star_count' => (int) $row['stars'][0],
  896. 'star_image' => isset($row['stars'][1]) ? $row['stars'][1] : '',
  897. 'is_post_group' => $row['min_posts'] != -1,
  898. 'type' => $row['min_posts'] != -1 ? 0 : $row['group_type'],
  899. 'hidden' => $row['min_posts'] == -1 ? $row['hidden'] : 0,
  900. 'inherited_from' => $row['id_parent'],
  901. 'allow_post_group' => $_REQUEST['group'] == 2 || $_REQUEST['group'] > 4,
  902. 'allow_delete' => $_REQUEST['group'] == 2 || $_REQUEST['group'] > 4,
  903. 'allow_protected' => allowedTo('admin_forum'),
  904. );
  905. // Get any moderators for this group
  906. $request = $smcFunc['db_query']('', '
  907. SELECT mem.id_member, mem.real_name
  908. FROM {db_prefix}group_moderators AS mods
  909. INNER JOIN {db_prefix}members AS mem ON (mem.id_member = mods.id_member)
  910. WHERE mods.id_group = {int:current_group}',
  911. array(
  912. 'current_group' => $_REQUEST['group'],
  913. )
  914. );
  915. $context['group']['moderators'] = array();
  916. while ($row = $smcFunc['db_fetch_assoc']($request))
  917. $context['group']['moderators'][$row['id_member']] = $row['real_name'];
  918. $smcFunc['db_free_result']($request);
  919. $context['group']['moderator_list'] = empty($context['group']['moderators']) ? '' : '&quot;' . implode('&quot;, &quot;', $context['group']['moderators']) . '&quot;';
  920. if (!empty($context['group']['moderators']))
  921. list ($context['group']['last_moderator_id']) = array_slice(array_keys($context['group']['moderators']), -1);
  922. // Get a list of boards this membergroup is allowed to see.
  923. $context['boards'] = array();
  924. if ($_REQUEST['group'] == 2 || $_REQUEST['group'] > 3)
  925. {
  926. $request = $smcFunc['db_query']('', '
  927. SELECT b.id_cat, c.name as cat_name, b.id_board, b.name, b.child_level, FIND_IN_SET({string:current_group}, b.member_groups) != 0 AS can_access
  928. FROM {db_prefix}boards AS b
  929. LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
  930. ORDER BY board_order',
  931. array(
  932. 'current_group' => (int) $_REQUEST['group'],
  933. )
  934. );
  935. $context['categories'] = array();
  936. while ($row = $smcFunc['db_fetch_assoc']($request))
  937. {
  938. // This category hasn't been set up yet..
  939. if (!isset($context['categories'][$row['id_cat']]))
  940. $context['categories'][$row['id_cat']] = array(
  941. 'id' => $row['id_cat'],
  942. 'name' => $row['cat_name'],
  943. 'boards' => array()
  944. );
  945. // Set this board up, and let the template know when it's a child. (indent them..)
  946. $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
  947. 'id' => $row['id_board'],
  948. 'name' => $row['name'],
  949. 'child_level' => $row['child_level'],
  950. 'selected' => !(empty($row['can_access']) || $row['can_access'] == 'f'),
  951. );
  952. }
  953. $smcFunc['db_free_result']($request);
  954. // Now, let's sort the list of categories into the boards for templates that like that.
  955. $temp_boards = array();
  956. foreach ($context['categories'] as $category)
  957. {
  958. $temp_boards[] = array(
  959. 'name' => $category['name'],
  960. 'child_ids' => array_keys($category['boards'])
  961. );
  962. $temp_boards = array_merge($temp_boards, array_values($category['boards']));
  963. // Include a list of boards per category for easy toggling.
  964. $context['categories'][$category['id']]['child_ids'] = array_keys($category['boards']);
  965. }
  966. $max_boards = ceil(count($temp_boards) / 2);
  967. if ($max_boards == 1)
  968. $max_boards = 2;
  969. }
  970. // Finally, get all the groups this could be inherited off.
  971. $request = $smcFunc['db_query']('', '
  972. SELECT id_group, group_name
  973. FROM {db_prefix}membergroups
  974. WHERE id_group != {int:current_group}' .
  975. (empty($modSettings['permission_enable_postgroups']) ? '
  976. AND min_posts = {int:min_posts}' : '') . (allowedTo('admin_forum') ? '' : '
  977. AND group_type != {int:is_protected}') . '
  978. AND id_group NOT IN (1, 3)
  979. AND id_parent = {int:not_inherited}',
  980. array(
  981. 'current_group' => (int) $_REQUEST['group'],
  982. 'min_posts' => -1,
  983. 'not_inherited' => -2,
  984. 'is_protected' => 1,
  985. )
  986. );
  987. $context['inheritable_groups'] = array();
  988. while ($row = $smcFunc['db_fetch_assoc']($request))
  989. $context['inheritable_groups'][$row['id_group']] = $row['group_name'];
  990. $smcFunc['db_free_result']($request);
  991. call_integration_hook('integrate_view_membergroup');
  992. $context['sub_template'] = 'edit_group';
  993. $context['page_title'] = $txt['membergroups_edit_group'];
  994. createToken('admin-mmg');
  995. }
  996. /**
  997. * Set some general membergroup settings and permissions.
  998. * Called by ?action=admin;area=membergroups;sa=settings
  999. * Requires the admin_forum permission (and manage_permissions for changing permissions)
  1000. * Redirects to itself.
  1001. *
  1002. * @uses membergroup_settings sub template of ManageMembergroups.
  1003. */
  1004. function ModifyMembergroupsettings()
  1005. {
  1006. global $context, $sourcedir, $scripturl, $modSettings, $txt;
  1007. $context['sub_template'] = 'show_settings';
  1008. $context['page_title'] = $txt['membergroups_settings'];
  1009. // Needed for the settings functions.
  1010. require_once($sourcedir . '/ManageServer.php');
  1011. // Don't allow assignment of guests.
  1012. $context['permissions_excluded'] = array(-1);
  1013. // Only one thing here!
  1014. $config_vars = array(
  1015. array('permissions', 'manage_membergroups'),
  1016. );
  1017. call_integration_hook('integrate_modify_membergroup_settings', array(&$config_vars));
  1018. if (isset($_REQUEST['save']))
  1019. {
  1020. checkSession();
  1021. call_integration_hook('integrate_save_membergroup_settings');
  1022. // Yeppers, saving this...
  1023. saveDBSettings($config_vars);
  1024. redirectexit('action=admin;area=membergroups;sa=settings');
  1025. }
  1026. // Some simple context.
  1027. $context['post_url'] = $scripturl . '?action=admin;area=membergroups;save;sa=settings';
  1028. $context['settings_title'] = $txt['membergroups_settings'];
  1029. // We need this for the in-line permissions
  1030. createToken('admin-mp');
  1031. prepareDBSettingContext($config_vars);
  1032. }
  1033. ?>