PageRenderTime 67ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/phpBB/includes/acp/auth.php

http://github.com/phpbb/phpbb
PHP | 1316 lines | 943 code | 210 blank | 163 comment | 172 complexity | 9bbcfe9d11525ec7bb59c14630e8b85a MD5 | raw file
Possible License(s): GPL-3.0, AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * This file is part of the phpBB Forum Software package.
  5. *
  6. * @copyright (c) phpBB Limited <https://www.phpbb.com>
  7. * @license GNU General Public License, version 2 (GPL-2.0)
  8. *
  9. * For full copyright and license information, please see
  10. * the docs/CREDITS.txt file.
  11. *
  12. */
  13. /**
  14. * @ignore
  15. */
  16. if (!defined('IN_PHPBB'))
  17. {
  18. exit;
  19. }
  20. /**
  21. * ACP Permission/Auth class
  22. */
  23. class auth_admin extends \phpbb\auth\auth
  24. {
  25. /**
  26. * Init auth settings
  27. */
  28. function __construct()
  29. {
  30. global $db, $cache;
  31. if (($this->acl_options = $cache->get('_acl_options')) === false)
  32. {
  33. $sql = 'SELECT auth_option_id, auth_option, is_global, is_local
  34. FROM ' . ACL_OPTIONS_TABLE . '
  35. ORDER BY auth_option_id';
  36. $result = $db->sql_query($sql);
  37. $global = $local = 0;
  38. $this->acl_options = array();
  39. while ($row = $db->sql_fetchrow($result))
  40. {
  41. if ($row['is_global'])
  42. {
  43. $this->acl_options['global'][$row['auth_option']] = $global++;
  44. }
  45. if ($row['is_local'])
  46. {
  47. $this->acl_options['local'][$row['auth_option']] = $local++;
  48. }
  49. $this->acl_options['id'][$row['auth_option']] = (int) $row['auth_option_id'];
  50. $this->acl_options['option'][(int) $row['auth_option_id']] = $row['auth_option'];
  51. }
  52. $db->sql_freeresult($result);
  53. $cache->put('_acl_options', $this->acl_options);
  54. }
  55. }
  56. /**
  57. * Get permission mask
  58. * This function only supports getting permissions of one type (for example a_)
  59. *
  60. * @param set|view $mode defines the permissions we get, view gets effective permissions (checking user AND group permissions), set only gets the user or group permission set alone
  61. * @param mixed $user_id user ids to search for (a user_id or a group_id has to be specified at least)
  62. * @param mixed $group_id group ids to search for, return group related settings (a user_id or a group_id has to be specified at least)
  63. * @param mixed $forum_id forum_ids to search for. Defining a forum id also means getting local settings
  64. * @param string $auth_option the auth_option defines the permission setting to look for (a_ for example)
  65. * @param local|global $scope the scope defines the permission scope. If local, a forum_id is additionally required
  66. * @param ACL_NEVER|ACL_NO|ACL_YES $acl_fill defines the mode those permissions not set are getting filled with
  67. */
  68. function get_mask($mode, $user_id = false, $group_id = false, $forum_id = false, $auth_option = false, $scope = false, $acl_fill = ACL_NEVER)
  69. {
  70. global $db, $user;
  71. $hold_ary = array();
  72. $view_user_mask = ($mode == 'view' && $group_id === false) ? true : false;
  73. if ($auth_option === false || $scope === false)
  74. {
  75. return array();
  76. }
  77. $acl_user_function = ($mode == 'set') ? 'acl_user_raw_data' : 'acl_raw_data';
  78. if (!$view_user_mask)
  79. {
  80. if ($forum_id !== false)
  81. {
  82. $hold_ary = ($group_id !== false) ? $this->acl_group_raw_data($group_id, $auth_option . '%', $forum_id) : $this->$acl_user_function($user_id, $auth_option . '%', $forum_id);
  83. }
  84. else
  85. {
  86. $hold_ary = ($group_id !== false) ? $this->acl_group_raw_data($group_id, $auth_option . '%', ($scope == 'global') ? 0 : false) : $this->$acl_user_function($user_id, $auth_option . '%', ($scope == 'global') ? 0 : false);
  87. }
  88. }
  89. // Make sure hold_ary is filled with every setting (prevents missing forums/users/groups)
  90. $ug_id = ($group_id !== false) ? ((!is_array($group_id)) ? array($group_id) : $group_id) : ((!is_array($user_id)) ? array($user_id) : $user_id);
  91. $forum_ids = ($forum_id !== false) ? ((!is_array($forum_id)) ? array($forum_id) : $forum_id) : (($scope == 'global') ? array(0) : array());
  92. // Only those options we need
  93. $compare_options = array_diff(preg_replace('/^((?!' . $auth_option . ').+)|(' . $auth_option . ')$/', '', array_keys($this->acl_options[$scope])), array(''));
  94. // If forum_ids is false and the scope is local we actually want to have all forums within the array
  95. if ($scope == 'local' && !count($forum_ids))
  96. {
  97. $sql = 'SELECT forum_id
  98. FROM ' . FORUMS_TABLE;
  99. $result = $db->sql_query($sql, 120);
  100. while ($row = $db->sql_fetchrow($result))
  101. {
  102. $forum_ids[] = (int) $row['forum_id'];
  103. }
  104. $db->sql_freeresult($result);
  105. }
  106. if ($view_user_mask)
  107. {
  108. $auth2 = null;
  109. $sql = 'SELECT user_id, user_permissions, user_type
  110. FROM ' . USERS_TABLE . '
  111. WHERE ' . $db->sql_in_set('user_id', $ug_id);
  112. $result = $db->sql_query($sql);
  113. while ($userdata = $db->sql_fetchrow($result))
  114. {
  115. if ($user->data['user_id'] != $userdata['user_id'])
  116. {
  117. $auth2 = new \phpbb\auth\auth();
  118. $auth2->acl($userdata);
  119. }
  120. else
  121. {
  122. global $auth;
  123. $auth2 = &$auth;
  124. }
  125. $hold_ary[$userdata['user_id']] = array();
  126. foreach ($forum_ids as $f_id)
  127. {
  128. $hold_ary[$userdata['user_id']][$f_id] = array();
  129. foreach ($compare_options as $option)
  130. {
  131. $hold_ary[$userdata['user_id']][$f_id][$option] = $auth2->acl_get($option, $f_id);
  132. }
  133. }
  134. }
  135. $db->sql_freeresult($result);
  136. unset($userdata);
  137. unset($auth2);
  138. }
  139. foreach ($ug_id as $_id)
  140. {
  141. if (!isset($hold_ary[$_id]))
  142. {
  143. $hold_ary[$_id] = array();
  144. }
  145. foreach ($forum_ids as $f_id)
  146. {
  147. if (!isset($hold_ary[$_id][$f_id]))
  148. {
  149. $hold_ary[$_id][$f_id] = array();
  150. }
  151. }
  152. }
  153. // Now, we need to fill the gaps with $acl_fill. ;)
  154. // Now switch back to keys
  155. if (count($compare_options))
  156. {
  157. $compare_options = array_combine($compare_options, array_fill(1, count($compare_options), $acl_fill));
  158. }
  159. // Defining the user-function here to save some memory
  160. $return_acl_fill = function () use ($acl_fill)
  161. {
  162. return $acl_fill;
  163. };
  164. // Actually fill the gaps
  165. if (count($hold_ary))
  166. {
  167. foreach ($hold_ary as $ug_id => $row)
  168. {
  169. foreach ($row as $id => $options)
  170. {
  171. // Do not include the global auth_option
  172. unset($options[$auth_option]);
  173. // Not a "fine" solution, but at all it's a 1-dimensional
  174. // array_diff_key function filling the resulting array values with zeros
  175. // The differences get merged into $hold_ary (all permissions having $acl_fill set)
  176. $hold_ary[$ug_id][$id] = array_merge($options,
  177. array_map($return_acl_fill,
  178. array_flip(
  179. array_diff(
  180. array_keys($compare_options), array_keys($options)
  181. )
  182. )
  183. )
  184. );
  185. }
  186. }
  187. }
  188. else
  189. {
  190. $hold_ary[($group_id !== false) ? $group_id : $user_id][(int) $forum_id] = $compare_options;
  191. }
  192. return $hold_ary;
  193. }
  194. /**
  195. * Get permission mask for roles
  196. * This function only supports getting masks for one role
  197. */
  198. function get_role_mask($role_id)
  199. {
  200. global $db;
  201. $hold_ary = array();
  202. // Get users having this role set...
  203. $sql = 'SELECT user_id, forum_id
  204. FROM ' . ACL_USERS_TABLE . '
  205. WHERE auth_role_id = ' . $role_id . '
  206. ORDER BY forum_id';
  207. $result = $db->sql_query($sql);
  208. while ($row = $db->sql_fetchrow($result))
  209. {
  210. $hold_ary[$row['forum_id']]['users'][] = $row['user_id'];
  211. }
  212. $db->sql_freeresult($result);
  213. // Now grab groups...
  214. $sql = 'SELECT group_id, forum_id
  215. FROM ' . ACL_GROUPS_TABLE . '
  216. WHERE auth_role_id = ' . $role_id . '
  217. ORDER BY forum_id';
  218. $result = $db->sql_query($sql);
  219. while ($row = $db->sql_fetchrow($result))
  220. {
  221. $hold_ary[$row['forum_id']]['groups'][] = $row['group_id'];
  222. }
  223. $db->sql_freeresult($result);
  224. return $hold_ary;
  225. }
  226. /**
  227. * Display permission mask (assign to template)
  228. */
  229. function display_mask($mode, $permission_type, &$hold_ary, $user_mode = 'user', $local = false, $group_display = true)
  230. {
  231. global $template, $user, $db, $phpbb_container;
  232. /* @var $phpbb_permissions \phpbb\permissions */
  233. $phpbb_permissions = $phpbb_container->get('acl.permissions');
  234. /** @var \phpbb\group\helper $group_helper */
  235. $group_helper = $phpbb_container->get('group_helper');
  236. // Define names for template loops, might be able to be set
  237. $tpl_pmask = 'p_mask';
  238. $tpl_fmask = 'f_mask';
  239. $tpl_category = 'category';
  240. $tpl_mask = 'mask';
  241. $l_acl_type = $phpbb_permissions->get_type_lang($permission_type, (($local) ? 'local' : 'global'));
  242. // Allow trace for viewing permissions and in user mode
  243. $show_trace = ($mode == 'view' && $user_mode == 'user') ? true : false;
  244. // Get names
  245. if ($user_mode == 'user')
  246. {
  247. $sql = 'SELECT user_id as ug_id, username as ug_name
  248. FROM ' . USERS_TABLE . '
  249. WHERE ' . $db->sql_in_set('user_id', array_keys($hold_ary)) . '
  250. ORDER BY username_clean ASC';
  251. }
  252. else
  253. {
  254. $sql = 'SELECT group_id as ug_id, group_name as ug_name, group_type
  255. FROM ' . GROUPS_TABLE . '
  256. WHERE ' . $db->sql_in_set('group_id', array_keys($hold_ary)) . '
  257. ORDER BY group_type DESC, group_name ASC';
  258. }
  259. $result = $db->sql_query($sql);
  260. $ug_names_ary = array();
  261. while ($row = $db->sql_fetchrow($result))
  262. {
  263. $ug_names_ary[$row['ug_id']] = ($user_mode == 'user') ? $row['ug_name'] : $group_helper->get_name($row['ug_name']);
  264. }
  265. $db->sql_freeresult($result);
  266. // Get used forums
  267. $forum_ids = array();
  268. foreach ($hold_ary as $ug_id => $row)
  269. {
  270. $forum_ids = array_merge($forum_ids, array_keys($row));
  271. }
  272. $forum_ids = array_unique($forum_ids);
  273. $forum_names_ary = array();
  274. if ($local)
  275. {
  276. $forum_names_ary = make_forum_select(false, false, true, false, false, false, true);
  277. // Remove the disabled ones, since we do not create an option field here...
  278. foreach ($forum_names_ary as $key => $value)
  279. {
  280. if (!$value['disabled'])
  281. {
  282. continue;
  283. }
  284. unset($forum_names_ary[$key]);
  285. }
  286. }
  287. else
  288. {
  289. $forum_names_ary[0] = $l_acl_type;
  290. }
  291. // Get available roles
  292. $sql = 'SELECT *
  293. FROM ' . ACL_ROLES_TABLE . "
  294. WHERE role_type = '" . $db->sql_escape($permission_type) . "'
  295. ORDER BY role_order ASC";
  296. $result = $db->sql_query($sql);
  297. $roles = array();
  298. while ($row = $db->sql_fetchrow($result))
  299. {
  300. $roles[$row['role_id']] = $row;
  301. }
  302. $db->sql_freeresult($result);
  303. $cur_roles = $this->acl_role_data($user_mode, $permission_type, array_keys($hold_ary));
  304. // Build js roles array (role data assignments)
  305. $s_role_js_array = '';
  306. if (count($roles))
  307. {
  308. $s_role_js_array = array();
  309. // Make sure every role (even if empty) has its array defined
  310. foreach ($roles as $_role_id => $null)
  311. {
  312. $s_role_js_array[$_role_id] = "\n" . 'role_options[' . $_role_id . '] = new Array();' . "\n";
  313. }
  314. $sql = 'SELECT r.role_id, o.auth_option, r.auth_setting
  315. FROM ' . ACL_ROLES_DATA_TABLE . ' r, ' . ACL_OPTIONS_TABLE . ' o
  316. WHERE o.auth_option_id = r.auth_option_id
  317. AND ' . $db->sql_in_set('r.role_id', array_keys($roles));
  318. $result = $db->sql_query($sql);
  319. while ($row = $db->sql_fetchrow($result))
  320. {
  321. $flag = substr($row['auth_option'], 0, strpos($row['auth_option'], '_') + 1);
  322. if ($flag == $row['auth_option'])
  323. {
  324. continue;
  325. }
  326. $s_role_js_array[$row['role_id']] .= 'role_options[' . $row['role_id'] . '][\'' . addslashes($row['auth_option']) . '\'] = ' . $row['auth_setting'] . '; ';
  327. }
  328. $db->sql_freeresult($result);
  329. $s_role_js_array = implode('', $s_role_js_array);
  330. }
  331. $template->assign_var('S_ROLE_JS_ARRAY', $s_role_js_array);
  332. unset($s_role_js_array);
  333. // Now obtain memberships
  334. $user_groups_default = $user_groups_custom = array();
  335. if ($user_mode == 'user' && $group_display)
  336. {
  337. $sql = 'SELECT group_id, group_name, group_type
  338. FROM ' . GROUPS_TABLE . '
  339. ORDER BY group_type DESC, group_name ASC';
  340. $result = $db->sql_query($sql);
  341. $groups = array();
  342. while ($row = $db->sql_fetchrow($result))
  343. {
  344. $groups[$row['group_id']] = $row;
  345. }
  346. $db->sql_freeresult($result);
  347. $memberships = group_memberships(false, array_keys($hold_ary), false);
  348. // User is not a member of any group? Bad admin, bad bad admin...
  349. if ($memberships)
  350. {
  351. foreach ($memberships as $row)
  352. {
  353. $user_groups_default[$row['user_id']][] = $group_helper->get_name($groups[$row['group_id']]['group_name']);
  354. }
  355. }
  356. unset($memberships, $groups);
  357. }
  358. // If we only have one forum id to display or being in local mode and more than one user/group to display,
  359. // we switch the complete interface to group by user/usergroup instead of grouping by forum
  360. // To achieve this, we need to switch the array a bit
  361. if (count($forum_ids) == 1 || ($local && count($ug_names_ary) > 1))
  362. {
  363. $hold_ary_temp = $hold_ary;
  364. $hold_ary = array();
  365. foreach ($hold_ary_temp as $ug_id => $row)
  366. {
  367. foreach ($forum_names_ary as $forum_id => $forum_row)
  368. {
  369. if (isset($row[$forum_id]))
  370. {
  371. $hold_ary[$forum_id][$ug_id] = $row[$forum_id];
  372. }
  373. }
  374. }
  375. unset($hold_ary_temp);
  376. foreach ($hold_ary as $forum_id => $forum_array)
  377. {
  378. $content_array = $categories = array();
  379. $this->build_permission_array($hold_ary[$forum_id], $content_array, $categories, array_keys($ug_names_ary));
  380. $template->assign_block_vars($tpl_pmask, array(
  381. 'NAME' => ($forum_id == 0) ? $forum_names_ary[0] : $forum_names_ary[$forum_id]['forum_name'],
  382. 'PADDING' => ($forum_id == 0) ? '' : $forum_names_ary[$forum_id]['padding'],
  383. 'CATEGORIES' => implode('</th><th>', $categories),
  384. 'L_ACL_TYPE' => $l_acl_type,
  385. 'S_LOCAL' => ($local) ? true : false,
  386. 'S_GLOBAL' => (!$local) ? true : false,
  387. 'S_NUM_CATS' => count($categories),
  388. 'S_VIEW' => ($mode == 'view') ? true : false,
  389. 'S_NUM_OBJECTS' => count($content_array),
  390. 'S_USER_MODE' => ($user_mode == 'user') ? true : false,
  391. 'S_GROUP_MODE' => ($user_mode == 'group') ? true : false)
  392. );
  393. foreach ($content_array as $ug_id => $ug_array)
  394. {
  395. // Build role dropdown options
  396. $current_role_id = (isset($cur_roles[$ug_id][$forum_id])) ? $cur_roles[$ug_id][$forum_id] : 0;
  397. $role_options = array();
  398. $s_role_options = '';
  399. $current_role_id = (isset($cur_roles[$ug_id][$forum_id])) ? $cur_roles[$ug_id][$forum_id] : 0;
  400. foreach ($roles as $role_id => $role_row)
  401. {
  402. $role_description = (!empty($user->lang[$role_row['role_description']])) ? $user->lang[$role_row['role_description']] : nl2br($role_row['role_description']);
  403. $role_name = (!empty($user->lang[$role_row['role_name']])) ? $user->lang[$role_row['role_name']] : $role_row['role_name'];
  404. $title = ($role_description) ? ' title="' . $role_description . '"' : '';
  405. $s_role_options .= '<option value="' . $role_id . '"' . (($role_id == $current_role_id) ? ' selected="selected"' : '') . $title . '>' . $role_name . '</option>';
  406. $role_options[] = array(
  407. 'ID' => $role_id,
  408. 'ROLE_NAME' => $role_name,
  409. 'TITLE' => $role_description,
  410. 'SELECTED' => $role_id == $current_role_id,
  411. );
  412. }
  413. if ($s_role_options)
  414. {
  415. $s_role_options = '<option value="0"' . ((!$current_role_id) ? ' selected="selected"' : '') . ' title="' . htmlspecialchars($user->lang['NO_ROLE_ASSIGNED_EXPLAIN']) . '">' . $user->lang['NO_ROLE_ASSIGNED'] . '</option>' . $s_role_options;
  416. }
  417. if (!$current_role_id && $mode != 'view')
  418. {
  419. $s_custom_permissions = false;
  420. foreach ($ug_array as $key => $value)
  421. {
  422. if ($value['S_NEVER'] || $value['S_YES'])
  423. {
  424. $s_custom_permissions = true;
  425. break;
  426. }
  427. }
  428. }
  429. else
  430. {
  431. $s_custom_permissions = false;
  432. }
  433. $template->assign_block_vars($tpl_pmask . '.' . $tpl_fmask, array(
  434. 'NAME' => $ug_names_ary[$ug_id],
  435. 'UG_ID' => $ug_id,
  436. 'S_ROLE_OPTIONS' => $s_role_options,
  437. 'S_CUSTOM' => $s_custom_permissions,
  438. 'FORUM_ID' => $forum_id,
  439. 'S_ROLE_ID' => $current_role_id,
  440. ));
  441. $template->assign_block_vars_array($tpl_pmask . '.' . $tpl_fmask . '.role_options', $role_options);
  442. $this->assign_cat_array($ug_array, $tpl_pmask . '.' . $tpl_fmask . '.' . $tpl_category, $tpl_mask, $ug_id, $forum_id, ($mode == 'view'), $show_trace);
  443. unset($content_array[$ug_id]);
  444. }
  445. unset($hold_ary[$forum_id]);
  446. }
  447. }
  448. else
  449. {
  450. foreach ($ug_names_ary as $ug_id => $ug_name)
  451. {
  452. if (!isset($hold_ary[$ug_id]))
  453. {
  454. continue;
  455. }
  456. $content_array = $categories = array();
  457. $this->build_permission_array($hold_ary[$ug_id], $content_array, $categories, array_keys($forum_names_ary));
  458. $template->assign_block_vars($tpl_pmask, array(
  459. 'NAME' => $ug_name,
  460. 'CATEGORIES' => implode('</th><th>', $categories),
  461. 'USER_GROUPS_DEFAULT' => ($user_mode == 'user' && isset($user_groups_default[$ug_id]) && count($user_groups_default[$ug_id])) ? implode($user->lang['COMMA_SEPARATOR'], $user_groups_default[$ug_id]) : '',
  462. 'USER_GROUPS_CUSTOM' => ($user_mode == 'user' && isset($user_groups_custom[$ug_id]) && count($user_groups_custom[$ug_id])) ? implode($user->lang['COMMA_SEPARATOR'], $user_groups_custom[$ug_id]) : '',
  463. 'L_ACL_TYPE' => $l_acl_type,
  464. 'S_LOCAL' => ($local) ? true : false,
  465. 'S_GLOBAL' => (!$local) ? true : false,
  466. 'S_NUM_CATS' => count($categories),
  467. 'S_VIEW' => ($mode == 'view') ? true : false,
  468. 'S_NUM_OBJECTS' => count($content_array),
  469. 'S_USER_MODE' => ($user_mode == 'user') ? true : false,
  470. 'S_GROUP_MODE' => ($user_mode == 'group') ? true : false)
  471. );
  472. foreach ($content_array as $forum_id => $forum_array)
  473. {
  474. // Build role dropdown options
  475. $current_role_id = (isset($cur_roles[$ug_id][$forum_id])) ? $cur_roles[$ug_id][$forum_id] : 0;
  476. $role_options = array();
  477. $current_role_id = (isset($cur_roles[$ug_id][$forum_id])) ? $cur_roles[$ug_id][$forum_id] : 0;
  478. $s_role_options = '';
  479. foreach ($roles as $role_id => $role_row)
  480. {
  481. $role_description = (!empty($user->lang[$role_row['role_description']])) ? $user->lang[$role_row['role_description']] : nl2br($role_row['role_description']);
  482. $role_name = (!empty($user->lang[$role_row['role_name']])) ? $user->lang[$role_row['role_name']] : $role_row['role_name'];
  483. $title = ($role_description) ? ' title="' . $role_description . '"' : '';
  484. $s_role_options .= '<option value="' . $role_id . '"' . (($role_id == $current_role_id) ? ' selected="selected"' : '') . $title . '>' . $role_name . '</option>';
  485. $role_options[] = array(
  486. 'ID' => $role_id,
  487. 'ROLE_NAME' => $role_name,
  488. 'TITLE' => $role_description,
  489. 'SELECTED' => $role_id == $current_role_id,
  490. );
  491. }
  492. if ($s_role_options)
  493. {
  494. $s_role_options = '<option value="0"' . ((!$current_role_id) ? ' selected="selected"' : '') . ' title="' . htmlspecialchars($user->lang['NO_ROLE_ASSIGNED_EXPLAIN']) . '">' . $user->lang['NO_ROLE_ASSIGNED'] . '</option>' . $s_role_options;
  495. }
  496. if (!$current_role_id && $mode != 'view')
  497. {
  498. $s_custom_permissions = false;
  499. foreach ($forum_array as $key => $value)
  500. {
  501. if ($value['S_NEVER'] || $value['S_YES'])
  502. {
  503. $s_custom_permissions = true;
  504. break;
  505. }
  506. }
  507. }
  508. else
  509. {
  510. $s_custom_permissions = false;
  511. }
  512. $template->assign_block_vars($tpl_pmask . '.' . $tpl_fmask, array(
  513. 'NAME' => ($forum_id == 0) ? $forum_names_ary[0] : $forum_names_ary[$forum_id]['forum_name'],
  514. 'PADDING' => ($forum_id == 0) ? '' : $forum_names_ary[$forum_id]['padding'],
  515. 'S_CUSTOM' => $s_custom_permissions,
  516. 'UG_ID' => $ug_id,
  517. 'S_ROLE_OPTIONS' => $s_role_options,
  518. 'FORUM_ID' => $forum_id)
  519. );
  520. $template->assign_block_vars_array($tpl_pmask . '.' . $tpl_fmask . '.role_options', $role_options);
  521. $this->assign_cat_array($forum_array, $tpl_pmask . '.' . $tpl_fmask . '.' . $tpl_category, $tpl_mask, $ug_id, $forum_id, ($mode == 'view'), $show_trace);
  522. }
  523. unset($hold_ary[$ug_id], $ug_names_ary[$ug_id]);
  524. }
  525. }
  526. }
  527. /**
  528. * Display permission mask for roles
  529. */
  530. function display_role_mask(&$hold_ary)
  531. {
  532. global $db, $template, $user, $phpbb_root_path, $phpEx;
  533. global $phpbb_container;
  534. if (!count($hold_ary))
  535. {
  536. return;
  537. }
  538. /** @var \phpbb\group\helper $group_helper */
  539. $group_helper = $phpbb_container->get('group_helper');
  540. // Get forum names
  541. $sql = 'SELECT forum_id, forum_name
  542. FROM ' . FORUMS_TABLE . '
  543. WHERE ' . $db->sql_in_set('forum_id', array_keys($hold_ary)) . '
  544. ORDER BY left_id';
  545. $result = $db->sql_query($sql);
  546. // If the role is used globally, then reflect that
  547. $forum_names = (isset($hold_ary[0])) ? array(0 => '') : array();
  548. while ($row = $db->sql_fetchrow($result))
  549. {
  550. $forum_names[$row['forum_id']] = $row['forum_name'];
  551. }
  552. $db->sql_freeresult($result);
  553. foreach ($forum_names as $forum_id => $forum_name)
  554. {
  555. $auth_ary = $hold_ary[$forum_id];
  556. $template->assign_block_vars('role_mask', array(
  557. 'NAME' => ($forum_id == 0) ? $user->lang['GLOBAL_MASK'] : $forum_name,
  558. 'FORUM_ID' => $forum_id)
  559. );
  560. if (isset($auth_ary['users']) && count($auth_ary['users']))
  561. {
  562. $sql = 'SELECT user_id, username
  563. FROM ' . USERS_TABLE . '
  564. WHERE ' . $db->sql_in_set('user_id', $auth_ary['users']) . '
  565. ORDER BY username_clean ASC';
  566. $result = $db->sql_query($sql);
  567. while ($row = $db->sql_fetchrow($result))
  568. {
  569. $template->assign_block_vars('role_mask.users', array(
  570. 'USER_ID' => $row['user_id'],
  571. 'USERNAME' => get_username_string('username', $row['user_id'], $row['username']),
  572. 'U_PROFILE' => get_username_string('profile', $row['user_id'], $row['username']),
  573. ));
  574. }
  575. $db->sql_freeresult($result);
  576. }
  577. if (isset($auth_ary['groups']) && count($auth_ary['groups']))
  578. {
  579. $sql = 'SELECT group_id, group_name, group_type
  580. FROM ' . GROUPS_TABLE . '
  581. WHERE ' . $db->sql_in_set('group_id', $auth_ary['groups']) . '
  582. ORDER BY group_type ASC, group_name';
  583. $result = $db->sql_query($sql);
  584. while ($row = $db->sql_fetchrow($result))
  585. {
  586. $template->assign_block_vars('role_mask.groups', array(
  587. 'GROUP_ID' => $row['group_id'],
  588. 'GROUP_NAME' => $group_helper->get_name($row['group_name']),
  589. 'U_PROFILE' => append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=group&amp;g={$row['group_id']}"))
  590. );
  591. }
  592. $db->sql_freeresult($result);
  593. }
  594. }
  595. }
  596. /**
  597. * NOTE: this function is not in use atm
  598. * Add a new option to the list ... $options is a hash of form ->
  599. * $options = array(
  600. * 'local' => array('option1', 'option2', ...),
  601. * 'global' => array('optionA', 'optionB', ...)
  602. * );
  603. */
  604. function acl_add_option($options)
  605. {
  606. global $db, $cache;
  607. if (!is_array($options))
  608. {
  609. return false;
  610. }
  611. $cur_options = array();
  612. // Determine current options
  613. $sql = 'SELECT auth_option, is_global, is_local
  614. FROM ' . ACL_OPTIONS_TABLE . '
  615. ORDER BY auth_option_id';
  616. $result = $db->sql_query($sql);
  617. while ($row = $db->sql_fetchrow($result))
  618. {
  619. $cur_options[$row['auth_option']] = ($row['is_global'] && $row['is_local']) ? 'both' : (($row['is_global']) ? 'global' : 'local');
  620. }
  621. $db->sql_freeresult($result);
  622. // Here we need to insert new options ... this requires discovering whether
  623. // an options is global, local or both and whether we need to add an permission
  624. // set flag (x_)
  625. $new_options = array('local' => array(), 'global' => array());
  626. foreach ($options as $type => $option_ary)
  627. {
  628. $option_ary = array_unique($option_ary);
  629. foreach ($option_ary as $option_value)
  630. {
  631. $new_options[$type][] = $option_value;
  632. $flag = substr($option_value, 0, strpos($option_value, '_') + 1);
  633. if (!in_array($flag, $new_options[$type]))
  634. {
  635. $new_options[$type][] = $flag;
  636. }
  637. }
  638. }
  639. unset($options);
  640. $options = array();
  641. $options['local'] = array_diff($new_options['local'], $new_options['global']);
  642. $options['global'] = array_diff($new_options['global'], $new_options['local']);
  643. $options['both'] = array_intersect($new_options['local'], $new_options['global']);
  644. // Now check which options to add/update
  645. $add_options = $update_options = array();
  646. // First local ones...
  647. foreach ($options as $type => $option_ary)
  648. {
  649. foreach ($option_ary as $option)
  650. {
  651. if (!isset($cur_options[$option]))
  652. {
  653. $add_options[] = array(
  654. 'auth_option' => (string) $option,
  655. 'is_global' => ($type == 'global' || $type == 'both') ? 1 : 0,
  656. 'is_local' => ($type == 'local' || $type == 'both') ? 1 : 0
  657. );
  658. continue;
  659. }
  660. // Else, update existing entry if it is changed...
  661. if ($type === $cur_options[$option])
  662. {
  663. continue;
  664. }
  665. // New type is always both:
  666. // If is now both, we set both.
  667. // If it was global the new one is local and we need to set it to both
  668. // If it was local the new one is global and we need to set it to both
  669. $update_options[] = $option;
  670. }
  671. }
  672. if (!empty($add_options))
  673. {
  674. $db->sql_multi_insert(ACL_OPTIONS_TABLE, $add_options);
  675. }
  676. if (!empty($update_options))
  677. {
  678. $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . '
  679. SET is_global = 1, is_local = 1
  680. WHERE ' . $db->sql_in_set('auth_option', $update_options);
  681. $db->sql_query($sql);
  682. }
  683. $cache->destroy('_acl_options');
  684. $this->acl_clear_prefetch();
  685. // Because we just changed the options and also purged the options cache, we instantly update/regenerate it for later calls to succeed.
  686. $this->acl_options = array();
  687. $this->__construct();
  688. return true;
  689. }
  690. /**
  691. * Set a user or group ACL record
  692. */
  693. function acl_set($ug_type, $forum_id, $ug_id, $auth, $role_id = 0, $clear_prefetch = true)
  694. {
  695. global $db;
  696. // One or more forums
  697. if (!is_array($forum_id))
  698. {
  699. $forum_id = array($forum_id);
  700. }
  701. // One or more users
  702. if (!is_array($ug_id))
  703. {
  704. $ug_id = array($ug_id);
  705. }
  706. $ug_id_sql = $db->sql_in_set($ug_type . '_id', array_map('intval', $ug_id));
  707. $forum_sql = $db->sql_in_set('forum_id', array_map('intval', $forum_id));
  708. // Instead of updating, inserting, removing we just remove all current settings and re-set everything...
  709. $table = ($ug_type == 'user') ? ACL_USERS_TABLE : ACL_GROUPS_TABLE;
  710. $id_field = $ug_type . '_id';
  711. // Get any flags as required
  712. reset($auth);
  713. $flag = key($auth);
  714. $flag = substr($flag, 0, strpos($flag, '_') + 1);
  715. // This ID (the any-flag) is set if one or more permissions are true...
  716. $any_option_id = (int) $this->acl_options['id'][$flag];
  717. // Remove any-flag from auth ary
  718. if (isset($auth[$flag]))
  719. {
  720. unset($auth[$flag]);
  721. }
  722. // Remove current auth options...
  723. $auth_option_ids = array((int) $any_option_id);
  724. foreach ($auth as $auth_option => $auth_setting)
  725. {
  726. $auth_option_ids[] = (int) $this->acl_options['id'][$auth_option];
  727. }
  728. $sql = "DELETE FROM $table
  729. WHERE $forum_sql
  730. AND $ug_id_sql
  731. AND " . $db->sql_in_set('auth_option_id', $auth_option_ids);
  732. $db->sql_query($sql);
  733. // Remove those having a role assigned... the correct type of course...
  734. $sql = 'SELECT role_id
  735. FROM ' . ACL_ROLES_TABLE . "
  736. WHERE role_type = '" . $db->sql_escape($flag) . "'";
  737. $result = $db->sql_query($sql);
  738. $role_ids = array();
  739. while ($row = $db->sql_fetchrow($result))
  740. {
  741. $role_ids[] = $row['role_id'];
  742. }
  743. $db->sql_freeresult($result);
  744. if (count($role_ids))
  745. {
  746. $sql = "DELETE FROM $table
  747. WHERE $forum_sql
  748. AND $ug_id_sql
  749. AND auth_option_id = 0
  750. AND " . $db->sql_in_set('auth_role_id', $role_ids);
  751. $db->sql_query($sql);
  752. }
  753. // Ok, include the any-flag if one or more auth options are set to yes...
  754. foreach ($auth as $auth_option => $setting)
  755. {
  756. if ($setting == ACL_YES && (!isset($auth[$flag]) || $auth[$flag] == ACL_NEVER))
  757. {
  758. $auth[$flag] = ACL_YES;
  759. }
  760. }
  761. $sql_ary = array();
  762. foreach ($forum_id as $forum)
  763. {
  764. $forum = (int) $forum;
  765. if ($role_id)
  766. {
  767. foreach ($ug_id as $id)
  768. {
  769. $sql_ary[] = array(
  770. $id_field => (int) $id,
  771. 'forum_id' => (int) $forum,
  772. 'auth_option_id' => 0,
  773. 'auth_setting' => 0,
  774. 'auth_role_id' => (int) $role_id,
  775. );
  776. }
  777. }
  778. else
  779. {
  780. foreach ($auth as $auth_option => $setting)
  781. {
  782. $auth_option_id = (int) $this->acl_options['id'][$auth_option];
  783. if ($setting != ACL_NO)
  784. {
  785. foreach ($ug_id as $id)
  786. {
  787. $sql_ary[] = array(
  788. $id_field => (int) $id,
  789. 'forum_id' => (int) $forum,
  790. 'auth_option_id' => (int) $auth_option_id,
  791. 'auth_setting' => (int) $setting
  792. );
  793. }
  794. }
  795. }
  796. }
  797. }
  798. $db->sql_multi_insert($table, $sql_ary);
  799. if ($clear_prefetch)
  800. {
  801. $this->acl_clear_prefetch();
  802. }
  803. }
  804. /**
  805. * Set a role-specific ACL record
  806. */
  807. function acl_set_role($role_id, $auth)
  808. {
  809. global $db;
  810. // Get any-flag as required
  811. reset($auth);
  812. $flag = key($auth);
  813. $flag = substr($flag, 0, strpos($flag, '_') + 1);
  814. // Remove any-flag from auth ary
  815. if (isset($auth[$flag]))
  816. {
  817. unset($auth[$flag]);
  818. }
  819. // Re-set any flag...
  820. foreach ($auth as $auth_option => $setting)
  821. {
  822. if ($setting == ACL_YES && (!isset($auth[$flag]) || $auth[$flag] == ACL_NEVER))
  823. {
  824. $auth[$flag] = ACL_YES;
  825. }
  826. }
  827. $sql_ary = array();
  828. foreach ($auth as $auth_option => $setting)
  829. {
  830. $auth_option_id = (int) $this->acl_options['id'][$auth_option];
  831. if ($setting != ACL_NO)
  832. {
  833. $sql_ary[] = array(
  834. 'role_id' => (int) $role_id,
  835. 'auth_option_id' => (int) $auth_option_id,
  836. 'auth_setting' => (int) $setting
  837. );
  838. }
  839. }
  840. // If no data is there, we set the any-flag to ACL_NEVER...
  841. if (!count($sql_ary))
  842. {
  843. $sql_ary[] = array(
  844. 'role_id' => (int) $role_id,
  845. 'auth_option_id' => (int) $this->acl_options['id'][$flag],
  846. 'auth_setting' => ACL_NEVER
  847. );
  848. }
  849. // Remove current auth options...
  850. $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . '
  851. WHERE role_id = ' . $role_id;
  852. $db->sql_query($sql);
  853. // Now insert the new values
  854. $db->sql_multi_insert(ACL_ROLES_DATA_TABLE, $sql_ary);
  855. $this->acl_clear_prefetch();
  856. }
  857. /**
  858. * Remove local permission
  859. */
  860. function acl_delete($mode, $ug_id = false, $forum_id = false, $permission_type = false)
  861. {
  862. global $db;
  863. if ($ug_id === false && $forum_id === false)
  864. {
  865. return;
  866. }
  867. $option_id_ary = array();
  868. $table = ($mode == 'user') ? ACL_USERS_TABLE : ACL_GROUPS_TABLE;
  869. $id_field = $mode . '_id';
  870. $where_sql = array();
  871. if ($forum_id !== false)
  872. {
  873. $where_sql[] = (!is_array($forum_id)) ? 'forum_id = ' . (int) $forum_id : $db->sql_in_set('forum_id', array_map('intval', $forum_id));
  874. }
  875. if ($ug_id !== false)
  876. {
  877. $where_sql[] = (!is_array($ug_id)) ? $id_field . ' = ' . (int) $ug_id : $db->sql_in_set($id_field, array_map('intval', $ug_id));
  878. }
  879. // There seem to be auth options involved, therefore we need to go through the list and make sure we capture roles correctly
  880. if ($permission_type !== false)
  881. {
  882. // Get permission type
  883. $sql = 'SELECT auth_option, auth_option_id
  884. FROM ' . ACL_OPTIONS_TABLE . "
  885. WHERE auth_option " . $db->sql_like_expression($permission_type . $db->get_any_char());
  886. $result = $db->sql_query($sql);
  887. $auth_id_ary = array();
  888. while ($row = $db->sql_fetchrow($result))
  889. {
  890. $option_id_ary[] = $row['auth_option_id'];
  891. $auth_id_ary[$row['auth_option']] = ACL_NO;
  892. }
  893. $db->sql_freeresult($result);
  894. // First of all, lets grab the items having roles with the specified auth options assigned
  895. $sql = "SELECT auth_role_id, $id_field, forum_id
  896. FROM $table, " . ACL_ROLES_TABLE . " r
  897. WHERE auth_role_id <> 0
  898. AND auth_role_id = r.role_id
  899. AND r.role_type = '{$permission_type}'
  900. AND " . implode(' AND ', $where_sql) . '
  901. ORDER BY auth_role_id';
  902. $result = $db->sql_query($sql);
  903. $cur_role_auth = array();
  904. while ($row = $db->sql_fetchrow($result))
  905. {
  906. $cur_role_auth[$row['auth_role_id']][$row['forum_id']][] = $row[$id_field];
  907. }
  908. $db->sql_freeresult($result);
  909. // Get role data for resetting data
  910. if (count($cur_role_auth))
  911. {
  912. $sql = 'SELECT ao.auth_option, rd.role_id, rd.auth_setting
  913. FROM ' . ACL_OPTIONS_TABLE . ' ao, ' . ACL_ROLES_DATA_TABLE . ' rd
  914. WHERE ao.auth_option_id = rd.auth_option_id
  915. AND ' . $db->sql_in_set('rd.role_id', array_keys($cur_role_auth));
  916. $result = $db->sql_query($sql);
  917. $auth_settings = array();
  918. while ($row = $db->sql_fetchrow($result))
  919. {
  920. // We need to fill all auth_options, else setting it will fail...
  921. if (!isset($auth_settings[$row['role_id']]))
  922. {
  923. $auth_settings[$row['role_id']] = $auth_id_ary;
  924. }
  925. $auth_settings[$row['role_id']][$row['auth_option']] = $row['auth_setting'];
  926. }
  927. $db->sql_freeresult($result);
  928. // Set the options
  929. foreach ($cur_role_auth as $role_id => $auth_row)
  930. {
  931. foreach ($auth_row as $f_id => $ug_row)
  932. {
  933. $this->acl_set($mode, $f_id, $ug_row, $auth_settings[$role_id], 0, false);
  934. }
  935. }
  936. }
  937. }
  938. // Now, normally remove permissions...
  939. if ($permission_type !== false)
  940. {
  941. $where_sql[] = $db->sql_in_set('auth_option_id', array_map('intval', $option_id_ary));
  942. }
  943. $sql = "DELETE FROM $table
  944. WHERE " . implode(' AND ', $where_sql);
  945. $db->sql_query($sql);
  946. $this->acl_clear_prefetch();
  947. }
  948. /**
  949. * Assign category to template
  950. * used by display_mask()
  951. */
  952. function assign_cat_array(&$category_array, $tpl_cat, $tpl_mask, $ug_id, $forum_id, $s_view, $show_trace = false)
  953. {
  954. global $template, $phpbb_admin_path, $phpEx, $phpbb_container;
  955. /* @var $phpbb_permissions \phpbb\permissions */
  956. $phpbb_permissions = $phpbb_container->get('acl.permissions');
  957. foreach ($category_array as $cat => $cat_array)
  958. {
  959. if (!$phpbb_permissions->category_defined($cat))
  960. {
  961. continue;
  962. }
  963. $template->assign_block_vars($tpl_cat, array(
  964. 'S_YES' => ($cat_array['S_YES'] && !$cat_array['S_NEVER'] && !$cat_array['S_NO']) ? true : false,
  965. 'S_NEVER' => ($cat_array['S_NEVER'] && !$cat_array['S_YES'] && !$cat_array['S_NO']) ? true : false,
  966. 'S_NO' => ($cat_array['S_NO'] && !$cat_array['S_NEVER'] && !$cat_array['S_YES']) ? true : false,
  967. 'CAT_NAME' => $phpbb_permissions->get_category_lang($cat),
  968. ));
  969. /* Sort permissions by name (more naturaly and user friendly than sorting by a primary key)
  970. * Commented out due to it's memory consumption and time needed
  971. *
  972. $key_array = array_intersect(array_keys($user->lang), array_map(create_function('$a', 'return "acl_" . $a;'), array_keys($cat_array['permissions'])));
  973. $values_array = $cat_array['permissions'];
  974. $cat_array['permissions'] = array();
  975. foreach ($key_array as $key)
  976. {
  977. $key = str_replace('acl_', '', $key);
  978. $cat_array['permissions'][$key] = $values_array[$key];
  979. }
  980. unset($key_array, $values_array);
  981. */
  982. foreach ($cat_array['permissions'] as $permission => $allowed)
  983. {
  984. if (!$phpbb_permissions->permission_defined($permission))
  985. {
  986. continue;
  987. }
  988. if ($s_view)
  989. {
  990. $template->assign_block_vars($tpl_cat . '.' . $tpl_mask, array(
  991. 'S_YES' => ($allowed == ACL_YES) ? true : false,
  992. 'S_NEVER' => ($allowed == ACL_NEVER) ? true : false,
  993. 'UG_ID' => $ug_id,
  994. 'FORUM_ID' => $forum_id,
  995. 'FIELD_NAME' => $permission,
  996. 'S_FIELD_NAME' => 'setting[' . $ug_id . '][' . $forum_id . '][' . $permission . ']',
  997. 'U_TRACE' => ($show_trace) ? append_sid("{$phpbb_admin_path}index.$phpEx", "i=permissions&amp;mode=trace&amp;u=$ug_id&amp;f=$forum_id&amp;auth=$permission") : '',
  998. 'UA_TRACE' => ($show_trace) ? append_sid("{$phpbb_admin_path}index.$phpEx", "i=permissions&mode=trace&u=$ug_id&f=$forum_id&auth=$permission", false) : '',
  999. 'PERMISSION' => $phpbb_permissions->get_permission_lang($permission),
  1000. ));
  1001. }
  1002. else
  1003. {
  1004. $template->assign_block_vars($tpl_cat . '.' . $tpl_mask, array(
  1005. 'S_YES' => ($allowed == ACL_YES) ? true : false,
  1006. 'S_NEVER' => ($allowed == ACL_NEVER) ? true : false,
  1007. 'S_NO' => ($allowed == ACL_NO) ? true : false,
  1008. 'UG_ID' => $ug_id,
  1009. 'FORUM_ID' => $forum_id,
  1010. 'FIELD_NAME' => $permission,
  1011. 'S_FIELD_NAME' => 'setting[' . $ug_id . '][' . $forum_id . '][' . $permission . ']',
  1012. 'U_TRACE' => ($show_trace) ? append_sid("{$phpbb_admin_path}index.$phpEx", "i=permissions&amp;mode=trace&amp;u=$ug_id&amp;f=$forum_id&amp;auth=$permission") : '',
  1013. 'UA_TRACE' => ($show_trace) ? append_sid("{$phpbb_admin_path}index.$phpEx", "i=permissions&mode=trace&u=$ug_id&f=$forum_id&auth=$permission", false) : '',
  1014. 'PERMISSION' => $phpbb_permissions->get_permission_lang($permission),
  1015. ));
  1016. }
  1017. }
  1018. }
  1019. }
  1020. /**
  1021. * Building content array from permission rows with explicit key ordering
  1022. * used by display_mask()
  1023. */
  1024. function build_permission_array(&$permission_row, &$content_array, &$categories, $key_sort_array)
  1025. {
  1026. global $phpbb_container;
  1027. /* @var $phpbb_permissions \phpbb\permissions */
  1028. $phpbb_permissions = $phpbb_container->get('acl.permissions');
  1029. foreach ($key_sort_array as $forum_id)
  1030. {
  1031. if (!isset($permission_row[$forum_id]))
  1032. {
  1033. continue;
  1034. }
  1035. $permissions = $permission_row[$forum_id];
  1036. ksort($permissions);
  1037. foreach ($permissions as $permission => $auth_setting)
  1038. {
  1039. $cat = $phpbb_permissions->get_permission_category($permission);
  1040. // Build our categories array
  1041. if (!isset($categories[$cat]))
  1042. {
  1043. $categories[$cat] = $phpbb_permissions->get_category_lang($cat);
  1044. }
  1045. // Build our content array
  1046. if (!isset($content_array[$forum_id]))
  1047. {
  1048. $content_array[$forum_id] = array();
  1049. }
  1050. if (!isset($content_array[$forum_id][$cat]))
  1051. {
  1052. $content_array[$forum_id][$cat] = array(
  1053. 'S_YES' => false,
  1054. 'S_NEVER' => false,
  1055. 'S_NO' => false,
  1056. 'permissions' => array(),
  1057. );
  1058. }
  1059. $content_array[$forum_id][$cat]['S_YES'] |= ($auth_setting == ACL_YES) ? true : false;
  1060. $content_array[$forum_id][$cat]['S_NEVER'] |= ($auth_setting == ACL_NEVER) ? true : false;
  1061. $content_array[$forum_id][$cat]['S_NO'] |= ($auth_setting == ACL_NO) ? true : false;
  1062. $content_array[$forum_id][$cat]['permissions'][$permission] = $auth_setting;
  1063. }
  1064. }
  1065. }
  1066. /**
  1067. * Use permissions from another user. This transferes a permission set from one user to another.
  1068. * The other user is always able to revert back to his permission set.
  1069. * This function does not check for lower/higher permissions, it is possible for the user to gain
  1070. * "more" permissions by this.
  1071. * Admin permissions will not be copied.
  1072. */
  1073. function ghost_permissions($from_user_id, $to_user_id)
  1074. {
  1075. global $db;
  1076. if ($to_user_id == ANONYMOUS)
  1077. {
  1078. return false;
  1079. }
  1080. $hold_ary = $this->acl_raw_data_single_user($from_user_id);
  1081. // Key 0 in $hold_ary are global options, all others are forum_ids
  1082. // We disallow copying admin permissions
  1083. foreach ($this->acl_options['global'] as $opt => $id)
  1084. {
  1085. if (strpos($opt, 'a_') === 0)
  1086. {
  1087. $hold_ary[0][$this->acl_options['id'][$opt]] = ACL_NEVER;
  1088. }
  1089. }
  1090. // Force a_switchperm to be allowed
  1091. $hold_ary[0][$this->acl_options['id']['a_switchperm']] = ACL_YES;
  1092. $user_permissions = $this->build_bitstring($hold_ary);
  1093. if (!$user_permissions)
  1094. {
  1095. return false;
  1096. }
  1097. $sql = 'UPDATE ' . USERS_TABLE . "
  1098. SET user_permissions = '" . $db->sql_escape($user_permissions) . "',
  1099. user_perm_from = $from_user_id
  1100. WHERE user_id = " . $to_user_id;
  1101. $db->sql_query($sql);
  1102. return true;
  1103. }
  1104. }