ManageMembergroups.php 40 KB

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