ManageMembergroups.php 40 KB

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