PageRenderTime 74ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/phpBB/includes/acp/acp_groups.php

https://github.com/erikfrerejean/phpbb3
PHP | 836 lines | 653 code | 130 blank | 53 comment | 147 complexity | 22c6ef9c30ef6c308809b0a6132d6c46 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package acp
  5. * @version $Id$
  6. * @copyright (c) 2005 phpBB Group
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. * @ignore
  12. */
  13. if (!defined('IN_PHPBB'))
  14. {
  15. exit;
  16. }
  17. /**
  18. * @package acp
  19. */
  20. class acp_groups
  21. {
  22. var $u_action;
  23. function main($id, $mode)
  24. {
  25. global $config, $db, $user, $auth, $template, $cache;
  26. global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads;
  27. $user->add_lang('acp/groups');
  28. $this->tpl_name = 'acp_groups';
  29. $this->page_title = 'ACP_GROUPS_MANAGE';
  30. $form_key = 'acp_groups';
  31. add_form_key($form_key);
  32. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  33. // Check and set some common vars
  34. $action = (isset($_POST['add'])) ? 'add' : ((isset($_POST['addusers'])) ? 'addusers' : request_var('action', ''));
  35. $group_id = request_var('g', 0);
  36. $mark_ary = request_var('mark', array(0));
  37. $name_ary = request_var('usernames', '', true);
  38. $leader = request_var('leader', 0);
  39. $default = request_var('default', 0);
  40. $start = request_var('start', 0);
  41. $update = (isset($_POST['update'])) ? true : false;
  42. // Clear some vars
  43. $can_upload = (file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads) ? true : false;
  44. $group_row = array();
  45. // Grab basic data for group, if group_id is set and exists
  46. if ($group_id)
  47. {
  48. $sql = 'SELECT *
  49. FROM ' . GROUPS_TABLE . "
  50. WHERE group_id = $group_id";
  51. $result = $db->sql_query($sql);
  52. $group_row = $db->sql_fetchrow($result);
  53. $db->sql_freeresult($result);
  54. if (!$group_row)
  55. {
  56. trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
  57. }
  58. // Check if the user is allowed to manage this group if set to founder only.
  59. if ($user->data['user_type'] != USER_FOUNDER && $group_row['group_founder_manage'])
  60. {
  61. trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
  62. }
  63. }
  64. // Which page?
  65. switch ($action)
  66. {
  67. case 'approve':
  68. case 'demote':
  69. case 'promote':
  70. if (!check_form_key($form_key))
  71. {
  72. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
  73. }
  74. if (!$group_id)
  75. {
  76. trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
  77. }
  78. // Approve, demote or promote
  79. $group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
  80. $error = group_user_attributes($action, $group_id, $mark_ary, false, $group_name);
  81. if (!$error)
  82. {
  83. switch ($action)
  84. {
  85. case 'demote':
  86. $message = 'GROUP_MODS_DEMOTED';
  87. break;
  88. case 'promote':
  89. $message = 'GROUP_MODS_PROMOTED';
  90. break;
  91. case 'approve':
  92. $message = 'USERS_APPROVED';
  93. break;
  94. }
  95. trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&amp;action=list&amp;g=' . $group_id));
  96. }
  97. else
  98. {
  99. trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;action=list&amp;g=' . $group_id), E_USER_WARNING);
  100. }
  101. break;
  102. case 'default':
  103. if (!$group_id)
  104. {
  105. trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
  106. }
  107. else if (empty($mark_ary))
  108. {
  109. trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&amp;action=list&amp;g=' . $group_id), E_USER_WARNING);
  110. }
  111. if (confirm_box(true))
  112. {
  113. $group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
  114. group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row);
  115. trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action . '&amp;action=list&amp;g=' . $group_id));
  116. }
  117. else
  118. {
  119. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  120. 'mark' => $mark_ary,
  121. 'g' => $group_id,
  122. 'i' => $id,
  123. 'mode' => $mode,
  124. 'action' => $action))
  125. );
  126. }
  127. break;
  128. case 'set_default_on_all':
  129. if (confirm_box(true))
  130. {
  131. $group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
  132. $start = 0;
  133. do
  134. {
  135. $sql = 'SELECT user_id
  136. FROM ' . USER_GROUP_TABLE . "
  137. WHERE group_id = $group_id
  138. ORDER BY user_id";
  139. $result = $db->sql_query_limit($sql, 200, $start);
  140. $mark_ary = array();
  141. if ($row = $db->sql_fetchrow($result))
  142. {
  143. do
  144. {
  145. $mark_ary[] = $row['user_id'];
  146. }
  147. while ($row = $db->sql_fetchrow($result));
  148. group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row);
  149. $start = (sizeof($mark_ary) < 200) ? 0 : $start + 200;
  150. }
  151. else
  152. {
  153. $start = 0;
  154. }
  155. $db->sql_freeresult($result);
  156. }
  157. while ($start);
  158. trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action . '&amp;action=list&amp;g=' . $group_id));
  159. }
  160. else
  161. {
  162. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  163. 'mark' => $mark_ary,
  164. 'g' => $group_id,
  165. 'i' => $id,
  166. 'mode' => $mode,
  167. 'action' => $action))
  168. );
  169. }
  170. break;
  171. case 'deleteusers':
  172. if (empty($mark_ary))
  173. {
  174. trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&amp;action=list&amp;g=' . $group_id), E_USER_WARNING);
  175. }
  176. case 'delete':
  177. if (!$group_id)
  178. {
  179. trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
  180. }
  181. else if ($action === 'delete' && $group_row['group_type'] == GROUP_SPECIAL)
  182. {
  183. trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
  184. }
  185. if (confirm_box(true))
  186. {
  187. $error = '';
  188. switch ($action)
  189. {
  190. case 'delete':
  191. if (!$auth->acl_get('a_groupdel'))
  192. {
  193. trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
  194. }
  195. $error = group_delete($group_id, $group_row['group_name']);
  196. break;
  197. case 'deleteusers':
  198. $group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
  199. $error = group_user_del($group_id, $mark_ary, false, $group_name);
  200. break;
  201. }
  202. $back_link = ($action == 'delete') ? $this->u_action : $this->u_action . '&amp;action=list&amp;g=' . $group_id;
  203. if ($error)
  204. {
  205. trigger_error($user->lang[$error] . adm_back_link($back_link), E_USER_WARNING);
  206. }
  207. $message = ($action == 'delete') ? 'GROUP_DELETED' : 'GROUP_USERS_REMOVE';
  208. trigger_error($user->lang[$message] . adm_back_link($back_link));
  209. }
  210. else
  211. {
  212. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  213. 'mark' => $mark_ary,
  214. 'g' => $group_id,
  215. 'i' => $id,
  216. 'mode' => $mode,
  217. 'action' => $action))
  218. );
  219. }
  220. break;
  221. case 'addusers':
  222. if (!check_form_key($form_key))
  223. {
  224. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
  225. }
  226. if (!$group_id)
  227. {
  228. trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
  229. }
  230. if (!$name_ary)
  231. {
  232. trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&amp;action=list&amp;g=' . $group_id), E_USER_WARNING);
  233. }
  234. $name_ary = array_unique(explode("\n", $name_ary));
  235. $group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
  236. // Add user/s to group
  237. if ($error = group_user_add($group_id, false, $name_ary, $group_name, $default, $leader, 0, $group_row))
  238. {
  239. trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;action=list&amp;g=' . $group_id), E_USER_WARNING);
  240. }
  241. $message = ($leader) ? 'GROUP_MODS_ADDED' : 'GROUP_USERS_ADDED';
  242. trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&amp;action=list&amp;g=' . $group_id));
  243. break;
  244. case 'edit':
  245. case 'add':
  246. include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  247. $data = $submit_ary = array();
  248. if ($action == 'edit' && !$group_id)
  249. {
  250. trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
  251. }
  252. if ($action == 'add' && !$auth->acl_get('a_groupadd'))
  253. {
  254. trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
  255. }
  256. $error = array();
  257. $user->add_lang('ucp');
  258. $avatar_select = basename(request_var('avatar_select', ''));
  259. $category = basename(request_var('category', ''));
  260. // Did we submit?
  261. if ($update)
  262. {
  263. if (!check_form_key($form_key))
  264. {
  265. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
  266. }
  267. $group_name = utf8_normalize_nfc(request_var('group_name', '', true));
  268. $group_desc = utf8_normalize_nfc(request_var('group_desc', '', true));
  269. $group_type = request_var('group_type', GROUP_FREE);
  270. $allow_desc_bbcode = request_var('desc_parse_bbcode', false);
  271. $allow_desc_urls = request_var('desc_parse_urls', false);
  272. $allow_desc_smilies = request_var('desc_parse_smilies', false);
  273. $data['uploadurl'] = request_var('uploadurl', '');
  274. $data['remotelink'] = request_var('remotelink', '');
  275. $data['width'] = request_var('width', '');
  276. $data['height'] = request_var('height', '');
  277. $delete = request_var('delete', '');
  278. $submit_ary = array(
  279. 'colour' => request_var('group_colour', ''),
  280. 'rank' => request_var('group_rank', 0),
  281. 'receive_pm' => isset($_REQUEST['group_receive_pm']) ? 1 : 0,
  282. 'legend' => isset($_REQUEST['group_legend']) ? 1 : 0,
  283. 'message_limit' => request_var('group_message_limit', 0),
  284. 'max_recipients' => request_var('group_max_recipients', 0),
  285. 'founder_manage' => 0,
  286. 'skip_auth' => request_var('group_skip_auth', 0),
  287. );
  288. if ($user->data['user_type'] == USER_FOUNDER)
  289. {
  290. $submit_ary['founder_manage'] = isset($_REQUEST['group_founder_manage']) ? 1 : 0;
  291. }
  292. if (!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl'] || $data['remotelink'])
  293. {
  294. // Avatar stuff
  295. $var_ary = array(
  296. 'uploadurl' => array('string', true, 5, 255),
  297. 'remotelink' => array('string', true, 5, 255),
  298. 'width' => array('string', true, 1, 3),
  299. 'height' => array('string', true, 1, 3),
  300. );
  301. if (!($error = validate_data($data, $var_ary)))
  302. {
  303. $data['user_id'] = "g$group_id";
  304. if ((!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl']) && $can_upload)
  305. {
  306. list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_upload($data, $error);
  307. }
  308. else if ($data['remotelink'])
  309. {
  310. list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_remote($data, $error);
  311. }
  312. }
  313. }
  314. else if ($avatar_select && $config['allow_avatar_local'])
  315. {
  316. // check avatar gallery
  317. if (is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category))
  318. {
  319. $submit_ary['avatar_type'] = AVATAR_GALLERY;
  320. list($submit_ary['avatar_width'], $submit_ary['avatar_height']) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . $avatar_select);
  321. $submit_ary['avatar'] = $category . '/' . $avatar_select;
  322. }
  323. }
  324. else if ($delete)
  325. {
  326. $submit_ary['avatar'] = '';
  327. $submit_ary['avatar_type'] = $submit_ary['avatar_width'] = $submit_ary['avatar_height'] = 0;
  328. }
  329. else if ($data['width'] && $data['height'])
  330. {
  331. // Only update the dimensions?
  332. if ($config['avatar_max_width'] || $config['avatar_max_height'])
  333. {
  334. if ($data['width'] > $config['avatar_max_width'] || $data['height'] > $config['avatar_max_height'])
  335. {
  336. $error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], $data['width'], $data['height']);
  337. }
  338. }
  339. if (!sizeof($error))
  340. {
  341. if ($config['avatar_min_width'] || $config['avatar_min_height'])
  342. {
  343. if ($data['width'] < $config['avatar_min_width'] || $data['height'] < $config['avatar_min_height'])
  344. {
  345. $error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], $data['width'], $data['height']);
  346. }
  347. }
  348. }
  349. if (!sizeof($error))
  350. {
  351. $submit_ary['avatar_width'] = $data['width'];
  352. $submit_ary['avatar_height'] = $data['height'];
  353. }
  354. }
  355. if ((isset($submit_ary['avatar']) && $submit_ary['avatar'] && (!isset($group_row['group_avatar']))) || $delete)
  356. {
  357. if (isset($group_row['group_avatar']) && $group_row['group_avatar'])
  358. {
  359. avatar_delete('group', $group_row, true);
  360. }
  361. }
  362. /*
  363. * Validate the length of "Maximum number of allowed recipients per
  364. * private message" setting. We use 16777215 as a maximum because it matches
  365. * MySQL unsigned mediumint maximum value which is the lowest amongst DBMSes
  366. * supported by phpBB3. Also validate the submitted colour value.
  367. */
  368. $validation_checks = array(
  369. 'max_recipients' => array('num', false, 0, 16777215),
  370. 'colour' => array('hex_colour', true),
  371. );
  372. if ($validation_error = validate_data($submit_ary, $validation_checks))
  373. {
  374. // Replace "error" string with its real, localised form
  375. $error = array_merge($error, $validation_error);
  376. }
  377. if (!sizeof($error))
  378. {
  379. // Only set the rank, colour, etc. if it's changed or if we're adding a new
  380. // group. This prevents existing group members being updated if no changes
  381. // were made.
  382. $group_attributes = array();
  383. $test_variables = array(
  384. 'rank' => 'int',
  385. 'colour' => 'string',
  386. 'avatar' => 'string',
  387. 'avatar_type' => 'int',
  388. 'avatar_width' => 'int',
  389. 'avatar_height' => 'int',
  390. 'receive_pm' => 'int',
  391. 'legend' => 'int',
  392. 'message_limit' => 'int',
  393. 'max_recipients'=> 'int',
  394. 'founder_manage'=> 'int',
  395. 'skip_auth' => 'int',
  396. );
  397. foreach ($test_variables as $test => $type)
  398. {
  399. if (isset($submit_ary[$test]) && ($action == 'add' || $group_row['group_' . $test] != $submit_ary[$test]))
  400. {
  401. settype($submit_ary[$test], $type);
  402. $group_attributes['group_' . $test] = $group_row['group_' . $test] = $submit_ary[$test];
  403. }
  404. }
  405. if (!($error = group_create($group_id, $group_type, $group_name, $group_desc, $group_attributes, $allow_desc_bbcode, $allow_desc_urls, $allow_desc_smilies)))
  406. {
  407. $group_perm_from = request_var('group_perm_from', 0);
  408. // Copy permissions?
  409. // If the user has the a_authgroups permission and at least one additional permission ability set the permissions are fully transferred.
  410. // We do not limit on one auth category because this can lead to incomplete permissions being tricky to fix for the admin, roles being assigned or added non-default permissions.
  411. // Since the user only has the option to copy permissions from non leader managed groups this seems to be a good compromise.
  412. if ($group_perm_from && $action == 'add' && $auth->acl_get('a_authgroups') && $auth->acl_gets('a_aauth', 'a_fauth', 'a_mauth', 'a_uauth'))
  413. {
  414. $sql = 'SELECT group_founder_manage
  415. FROM ' . GROUPS_TABLE . '
  416. WHERE group_id = ' . $group_perm_from;
  417. $result = $db->sql_query($sql);
  418. $check_row = $db->sql_fetchrow($result);
  419. $db->sql_freeresult($result);
  420. // Check the group if non-founder
  421. if ($check_row && ($user->data['user_type'] == USER_FOUNDER || $check_row['group_founder_manage'] == 0))
  422. {
  423. // From the mysql documentation:
  424. // Prior to MySQL 4.0.14, the target table of the INSERT statement cannot appear in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14.
  425. // Due to this we stay on the safe side if we do the insertion "the manual way"
  426. // Copy permisisons from/to the acl groups table (only group_id gets changed)
  427. $sql = 'SELECT forum_id, auth_option_id, auth_role_id, auth_setting
  428. FROM ' . ACL_GROUPS_TABLE . '
  429. WHERE group_id = ' . $group_perm_from;
  430. $result = $db->sql_query($sql);
  431. $groups_sql_ary = array();
  432. while ($row = $db->sql_fetchrow($result))
  433. {
  434. $groups_sql_ary[] = array(
  435. 'group_id' => (int) $group_id,
  436. 'forum_id' => (int) $row['forum_id'],
  437. 'auth_option_id' => (int) $row['auth_option_id'],
  438. 'auth_role_id' => (int) $row['auth_role_id'],
  439. 'auth_setting' => (int) $row['auth_setting']
  440. );
  441. }
  442. $db->sql_freeresult($result);
  443. // Now insert the data
  444. $db->sql_multi_insert(ACL_GROUPS_TABLE, $groups_sql_ary);
  445. $auth->acl_clear_prefetch();
  446. }
  447. }
  448. $cache->destroy('sql', GROUPS_TABLE);
  449. $message = ($action == 'edit') ? 'GROUP_UPDATED' : 'GROUP_CREATED';
  450. trigger_error($user->lang[$message] . adm_back_link($this->u_action));
  451. }
  452. }
  453. if (sizeof($error))
  454. {
  455. $error = array_map(array(&$user, 'lang'), $error);
  456. $group_rank = $submit_ary['rank'];
  457. $group_desc_data = array(
  458. 'text' => $group_desc,
  459. 'allow_bbcode' => $allow_desc_bbcode,
  460. 'allow_smilies' => $allow_desc_smilies,
  461. 'allow_urls' => $allow_desc_urls
  462. );
  463. }
  464. }
  465. else if (!$group_id)
  466. {
  467. $group_name = utf8_normalize_nfc(request_var('group_name', '', true));
  468. $group_desc_data = array(
  469. 'text' => '',
  470. 'allow_bbcode' => true,
  471. 'allow_smilies' => true,
  472. 'allow_urls' => true
  473. );
  474. $group_rank = 0;
  475. $group_type = GROUP_OPEN;
  476. }
  477. else
  478. {
  479. $group_name = $group_row['group_name'];
  480. $group_desc_data = generate_text_for_edit($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_options']);
  481. $group_type = $group_row['group_type'];
  482. $group_rank = $group_row['group_rank'];
  483. }
  484. $sql = 'SELECT *
  485. FROM ' . RANKS_TABLE . '
  486. WHERE rank_special = 1
  487. ORDER BY rank_title';
  488. $result = $db->sql_query($sql);
  489. $rank_options = '<option value="0"' . ((!$group_rank) ? ' selected="selected"' : '') . '>' . $user->lang['USER_DEFAULT'] . '</option>';
  490. while ($row = $db->sql_fetchrow($result))
  491. {
  492. $selected = ($group_rank && $row['rank_id'] == $group_rank) ? ' selected="selected"' : '';
  493. $rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>';
  494. }
  495. $db->sql_freeresult($result);
  496. $type_free = ($group_type == GROUP_FREE) ? ' checked="checked"' : '';
  497. $type_open = ($group_type == GROUP_OPEN) ? ' checked="checked"' : '';
  498. $type_closed = ($group_type == GROUP_CLOSED) ? ' checked="checked"' : '';
  499. $type_hidden = ($group_type == GROUP_HIDDEN) ? ' checked="checked"' : '';
  500. $avatar_img = (!empty($group_row['group_avatar'])) ? get_user_avatar($group_row['group_avatar'], $group_row['group_avatar_type'], $group_row['group_avatar_width'], $group_row['group_avatar_height'], 'GROUP_AVATAR') : '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />';
  501. $display_gallery = (isset($_POST['display_gallery'])) ? true : false;
  502. if ($config['allow_avatar_local'] && $display_gallery)
  503. {
  504. avatar_gallery($category, $avatar_select, 4);
  505. }
  506. $back_link = request_var('back_link', '');
  507. switch ($back_link)
  508. {
  509. case 'acp_users_groups':
  510. $u_back = append_sid("{$phpbb_admin_path}index.$phpEx", 'i=users&amp;mode=groups&amp;u=' . request_var('u', 0));
  511. break;
  512. default:
  513. $u_back = $this->u_action;
  514. break;
  515. }
  516. $template->assign_vars(array(
  517. 'S_EDIT' => true,
  518. 'S_ADD_GROUP' => ($action == 'add') ? true : false,
  519. 'S_GROUP_PERM' => ($action == 'add' && $auth->acl_get('a_authgroups') && $auth->acl_gets('a_aauth', 'a_fauth', 'a_mauth', 'a_uauth')) ? true : false,
  520. 'S_INCLUDE_SWATCH' => true,
  521. 'S_CAN_UPLOAD' => $can_upload,
  522. 'S_ERROR' => (sizeof($error)) ? true : false,
  523. 'S_SPECIAL_GROUP' => ($group_type == GROUP_SPECIAL) ? true : false,
  524. 'S_DISPLAY_GALLERY' => ($config['allow_avatar_local'] && !$display_gallery) ? true : false,
  525. 'S_IN_GALLERY' => ($config['allow_avatar_local'] && $display_gallery) ? true : false,
  526. 'S_USER_FOUNDER' => ($user->data['user_type'] == USER_FOUNDER) ? true : false,
  527. 'ERROR_MSG' => (sizeof($error)) ? implode('<br />', $error) : '',
  528. 'GROUP_NAME' => ($group_type == GROUP_SPECIAL) ? $user->lang['G_' . $group_name] : $group_name,
  529. 'GROUP_INTERNAL_NAME' => $group_name,
  530. 'GROUP_DESC' => $group_desc_data['text'],
  531. 'GROUP_RECEIVE_PM' => (isset($group_row['group_receive_pm']) && $group_row['group_receive_pm']) ? ' checked="checked"' : '',
  532. 'GROUP_FOUNDER_MANAGE' => (isset($group_row['group_founder_manage']) && $group_row['group_founder_manage']) ? ' checked="checked"' : '',
  533. 'GROUP_LEGEND' => (isset($group_row['group_legend']) && $group_row['group_legend']) ? ' checked="checked"' : '',
  534. 'GROUP_MESSAGE_LIMIT' => (isset($group_row['group_message_limit'])) ? $group_row['group_message_limit'] : 0,
  535. 'GROUP_MAX_RECIPIENTS' => (isset($group_row['group_max_recipients'])) ? $group_row['group_max_recipients'] : 0,
  536. 'GROUP_COLOUR' => (isset($group_row['group_colour'])) ? $group_row['group_colour'] : '',
  537. 'GROUP_SKIP_AUTH' => (!empty($group_row['group_skip_auth'])) ? ' checked="checked"' : '',
  538. 'S_DESC_BBCODE_CHECKED' => $group_desc_data['allow_bbcode'],
  539. 'S_DESC_URLS_CHECKED' => $group_desc_data['allow_urls'],
  540. 'S_DESC_SMILIES_CHECKED'=> $group_desc_data['allow_smilies'],
  541. 'S_RANK_OPTIONS' => $rank_options,
  542. 'S_GROUP_OPTIONS' => group_select_options(false, false, (($user->data['user_type'] == USER_FOUNDER) ? false : 0)),
  543. 'AVATAR' => $avatar_img,
  544. 'AVATAR_IMAGE' => $avatar_img,
  545. 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'],
  546. 'AVATAR_WIDTH' => (isset($group_row['group_avatar_width'])) ? $group_row['group_avatar_width'] : '',
  547. 'AVATAR_HEIGHT' => (isset($group_row['group_avatar_height'])) ? $group_row['group_avatar_height'] : '',
  548. 'GROUP_TYPE_FREE' => GROUP_FREE,
  549. 'GROUP_TYPE_OPEN' => GROUP_OPEN,
  550. 'GROUP_TYPE_CLOSED' => GROUP_CLOSED,
  551. 'GROUP_TYPE_HIDDEN' => GROUP_HIDDEN,
  552. 'GROUP_TYPE_SPECIAL' => GROUP_SPECIAL,
  553. 'GROUP_FREE' => $type_free,
  554. 'GROUP_OPEN' => $type_open,
  555. 'GROUP_CLOSED' => $type_closed,
  556. 'GROUP_HIDDEN' => $type_hidden,
  557. 'U_BACK' => $u_back,
  558. 'U_SWATCH' => append_sid("{$phpbb_admin_path}swatch.$phpEx", 'form=settings&amp;name=group_colour'),
  559. 'U_ACTION' => "{$this->u_action}&amp;action=$action&amp;g=$group_id",
  560. 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024)),
  561. ));
  562. return;
  563. break;
  564. case 'list':
  565. if (!$group_id)
  566. {
  567. trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
  568. }
  569. $this->page_title = 'GROUP_MEMBERS';
  570. // Grab the leaders - always, on every page...
  571. $sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_regdate, u.user_colour, u.user_posts, u.group_id, ug.group_leader, ug.user_pending
  572. FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug
  573. WHERE ug.group_id = $group_id
  574. AND u.user_id = ug.user_id
  575. AND ug.group_leader = 1
  576. ORDER BY ug.group_leader DESC, ug.user_pending ASC, u.username_clean";
  577. $result = $db->sql_query($sql);
  578. while ($row = $db->sql_fetchrow($result))
  579. {
  580. $template->assign_block_vars('leader', array(
  581. 'U_USER_EDIT' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&amp;action=edit&amp;u={$row['user_id']}"),
  582. 'USERNAME' => $row['username'],
  583. 'USERNAME_COLOUR' => $row['user_colour'],
  584. 'S_GROUP_DEFAULT' => ($row['group_id'] == $group_id) ? true : false,
  585. 'JOINED' => ($row['user_regdate']) ? $user->format_date($row['user_regdate']) : ' - ',
  586. 'USER_POSTS' => $row['user_posts'],
  587. 'USER_ID' => $row['user_id'],
  588. ));
  589. }
  590. $db->sql_freeresult($result);
  591. // Total number of group members (non-leaders)
  592. $sql = 'SELECT COUNT(user_id) AS total_members
  593. FROM ' . USER_GROUP_TABLE . "
  594. WHERE group_id = $group_id
  595. AND group_leader = 0";
  596. $result = $db->sql_query($sql);
  597. $total_members = (int) $db->sql_fetchfield('total_members');
  598. $db->sql_freeresult($result);
  599. $s_action_options = '';
  600. $options = array('default' => 'DEFAULT', 'approve' => 'APPROVE', 'demote' => 'DEMOTE', 'promote' => 'PROMOTE', 'deleteusers' => 'DELETE');
  601. foreach ($options as $option => $lang)
  602. {
  603. $s_action_options .= '<option value="' . $option . '">' . $user->lang['GROUP_' . $lang] . '</option>';
  604. }
  605. $template->assign_vars(array(
  606. 'S_LIST' => true,
  607. 'S_GROUP_SPECIAL' => ($group_row['group_type'] == GROUP_SPECIAL) ? true : false,
  608. 'S_ACTION_OPTIONS' => $s_action_options,
  609. 'S_ON_PAGE' => on_page($total_members, $config['topics_per_page'], $start),
  610. 'PAGINATION' => generate_pagination($this->u_action . "&amp;action=$action&amp;g=$group_id", $total_members, $config['topics_per_page'], $start, true),
  611. 'GROUP_NAME' => ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'],
  612. 'U_ACTION' => $this->u_action . "&amp;g=$group_id",
  613. 'U_BACK' => $this->u_action,
  614. 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=list&amp;field=usernames'),
  615. 'U_DEFAULT_ALL' => "{$this->u_action}&amp;action=set_default_on_all&amp;g=$group_id",
  616. ));
  617. // Grab the members
  618. $sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_colour, u.user_regdate, u.user_posts, u.group_id, ug.group_leader, ug.user_pending
  619. FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug
  620. WHERE ug.group_id = $group_id
  621. AND u.user_id = ug.user_id
  622. AND ug.group_leader = 0
  623. ORDER BY ug.group_leader DESC, ug.user_pending ASC, u.username_clean";
  624. $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
  625. $pending = false;
  626. while ($row = $db->sql_fetchrow($result))
  627. {
  628. if ($row['user_pending'] && !$pending)
  629. {
  630. $template->assign_block_vars('member', array(
  631. 'S_PENDING' => true)
  632. );
  633. $pending = true;
  634. }
  635. $template->assign_block_vars('member', array(
  636. 'U_USER_EDIT' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&amp;action=edit&amp;u={$row['user_id']}"),
  637. 'USERNAME' => $row['username'],
  638. 'USERNAME_COLOUR' => $row['user_colour'],
  639. 'S_GROUP_DEFAULT' => ($row['group_id'] == $group_id) ? true : false,
  640. 'JOINED' => ($row['user_regdate']) ? $user->format_date($row['user_regdate']) : ' - ',
  641. 'USER_POSTS' => $row['user_posts'],
  642. 'USER_ID' => $row['user_id'])
  643. );
  644. }
  645. $db->sql_freeresult($result);
  646. return;
  647. break;
  648. }
  649. $template->assign_vars(array(
  650. 'U_ACTION' => $this->u_action,
  651. 'S_GROUP_ADD' => ($auth->acl_get('a_groupadd')) ? true : false)
  652. );
  653. // Get us all the groups
  654. $sql = 'SELECT g.group_id, g.group_name, g.group_type
  655. FROM ' . GROUPS_TABLE . ' g
  656. ORDER BY g.group_type ASC, g.group_name';
  657. $result = $db->sql_query($sql);
  658. $lookup = $cached_group_data = array();
  659. while ($row = $db->sql_fetchrow($result))
  660. {
  661. $type = ($row['group_type'] == GROUP_SPECIAL) ? 'special' : 'normal';
  662. // used to determine what type a group is
  663. $lookup[$row['group_id']] = $type;
  664. // used for easy access to the data within a group
  665. $cached_group_data[$type][$row['group_id']] = $row;
  666. $cached_group_data[$type][$row['group_id']]['total_members'] = 0;
  667. }
  668. $db->sql_freeresult($result);
  669. // How many people are in which group?
  670. $sql = 'SELECT COUNT(ug.user_id) AS total_members, ug.group_id
  671. FROM ' . USER_GROUP_TABLE . ' ug
  672. WHERE ' . $db->sql_in_set('ug.group_id', array_keys($lookup)) . '
  673. GROUP BY ug.group_id';
  674. $result = $db->sql_query($sql);
  675. while ($row = $db->sql_fetchrow($result))
  676. {
  677. $type = $lookup[$row['group_id']];
  678. $cached_group_data[$type][$row['group_id']]['total_members'] = $row['total_members'];
  679. }
  680. $db->sql_freeresult($result);
  681. // The order is... normal, then special
  682. ksort($cached_group_data);
  683. foreach ($cached_group_data as $type => $row_ary)
  684. {
  685. if ($type == 'special')
  686. {
  687. $template->assign_block_vars('groups', array(
  688. 'S_SPECIAL' => true)
  689. );
  690. }
  691. foreach ($row_ary as $group_id => $row)
  692. {
  693. $group_name = (!empty($user->lang['G_' . $row['group_name']]))? $user->lang['G_' . $row['group_name']] : $row['group_name'];
  694. $template->assign_block_vars('groups', array(
  695. 'U_LIST' => "{$this->u_action}&amp;action=list&amp;g=$group_id",
  696. 'U_EDIT' => "{$this->u_action}&amp;action=edit&amp;g=$group_id",
  697. 'U_DELETE' => ($auth->acl_get('a_groupdel')) ? "{$this->u_action}&amp;action=delete&amp;g=$group_id" : '',
  698. 'S_GROUP_SPECIAL' => ($row['group_type'] == GROUP_SPECIAL) ? true : false,
  699. 'GROUP_NAME' => $group_name,
  700. 'TOTAL_MEMBERS' => $row['total_members'],
  701. ));
  702. }
  703. }
  704. }
  705. }
  706. ?>