ManageMembergroups.php 42 KB

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