PageRenderTime 73ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/forum/includes/acp/acp_users.php

https://bitbucket.org/itoxable/chiron-gaming
PHP | 2392 lines | 1859 code | 440 blank | 93 comment | 318 complexity | bd0d21dc4f16bb5a5b4e38a292dcb591 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.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_users
  21. {
  22. var $u_action;
  23. var $p_master;
  24. function acp_users(&$p_master)
  25. {
  26. $this->p_master = &$p_master;
  27. }
  28. function main($id, $mode)
  29. {
  30. global $config, $db, $user, $auth, $template, $cache;
  31. global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads;
  32. $user->add_lang(array('posting', 'ucp', 'acp/users'));
  33. $this->tpl_name = 'acp_users';
  34. $this->page_title = 'ACP_USER_' . strtoupper($mode);
  35. $error = array();
  36. $username = utf8_normalize_nfc(request_var('username', '', true));
  37. $user_id = request_var('u', 0);
  38. $action = request_var('action', '');
  39. $submit = (isset($_POST['update']) && !isset($_POST['cancel'])) ? true : false;
  40. $form_name = 'acp_users';
  41. add_form_key($form_name);
  42. // Whois (special case)
  43. if ($action == 'whois')
  44. {
  45. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  46. $this->page_title = 'WHOIS';
  47. $this->tpl_name = 'simple_body';
  48. $user_ip = request_var('user_ip', '');
  49. $domain = gethostbyaddr($user_ip);
  50. $ipwhois = user_ipwhois($user_ip);
  51. $template->assign_vars(array(
  52. 'MESSAGE_TITLE' => sprintf($user->lang['IP_WHOIS_FOR'], $domain),
  53. 'MESSAGE_TEXT' => nl2br($ipwhois))
  54. );
  55. return;
  56. }
  57. // Show user selection mask
  58. if (!$username && !$user_id)
  59. {
  60. $this->page_title = 'SELECT_USER';
  61. $template->assign_vars(array(
  62. 'U_ACTION' => $this->u_action,
  63. 'ANONYMOUS_USER_ID' => ANONYMOUS,
  64. 'S_SELECT_USER' => true,
  65. 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=select_user&amp;field=username&amp;select_single=true'),
  66. ));
  67. return;
  68. }
  69. if (!$user_id)
  70. {
  71. $sql = 'SELECT user_id
  72. FROM ' . USERS_TABLE . "
  73. WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
  74. $result = $db->sql_query($sql);
  75. $user_id = (int) $db->sql_fetchfield('user_id');
  76. $db->sql_freeresult($result);
  77. if (!$user_id)
  78. {
  79. trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING);
  80. }
  81. }
  82. // Generate content for all modes
  83. $sql = 'SELECT u.*, s.*
  84. FROM ' . USERS_TABLE . ' u
  85. LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id)
  86. WHERE u.user_id = ' . $user_id . '
  87. ORDER BY s.session_time DESC';
  88. $result = $db->sql_query_limit($sql, 1);
  89. $user_row = $db->sql_fetchrow($result);
  90. $db->sql_freeresult($result);
  91. if (!$user_row)
  92. {
  93. trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING);
  94. }
  95. // Generate overall "header" for user admin
  96. $s_form_options = '';
  97. // Build modes dropdown list
  98. $sql = 'SELECT module_mode, module_auth
  99. FROM ' . MODULES_TABLE . "
  100. WHERE module_basename = 'users'
  101. AND module_enabled = 1
  102. AND module_class = 'acp'
  103. ORDER BY left_id, module_mode";
  104. $result = $db->sql_query($sql);
  105. $dropdown_modes = array();
  106. while ($row = $db->sql_fetchrow($result))
  107. {
  108. if (!$this->p_master->module_auth($row['module_auth']))
  109. {
  110. continue;
  111. }
  112. $dropdown_modes[$row['module_mode']] = true;
  113. }
  114. $db->sql_freeresult($result);
  115. foreach ($dropdown_modes as $module_mode => $null)
  116. {
  117. $selected = ($mode == $module_mode) ? ' selected="selected"' : '';
  118. $s_form_options .= '<option value="' . $module_mode . '"' . $selected . '>' . $user->lang['ACP_USER_' . strtoupper($module_mode)] . '</option>';
  119. }
  120. $template->assign_vars(array(
  121. 'U_BACK' => $this->u_action,
  122. 'U_MODE_SELECT' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&amp;u=$user_id"),
  123. 'U_ACTION' => $this->u_action . '&amp;u=' . $user_id,
  124. 'S_FORM_OPTIONS' => $s_form_options,
  125. 'MANAGED_USERNAME' => $user_row['username'])
  126. );
  127. // Prevent normal users/admins change/view founders if they are not a founder by themselves
  128. if ($user->data['user_type'] != USER_FOUNDER && $user_row['user_type'] == USER_FOUNDER)
  129. {
  130. trigger_error($user->lang['NOT_MANAGE_FOUNDER'] . adm_back_link($this->u_action), E_USER_WARNING);
  131. }
  132. switch ($mode)
  133. {
  134. case 'overview':
  135. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  136. $user->add_lang('acp/ban');
  137. $delete = request_var('delete', 0);
  138. $delete_type = request_var('delete_type', '');
  139. $ip = request_var('ip', 'ip');
  140. if ($submit)
  141. {
  142. // You can't delete the founder
  143. if ($delete && $user_row['user_type'] != USER_FOUNDER)
  144. {
  145. if (!$auth->acl_get('a_userdel'))
  146. {
  147. trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  148. }
  149. // Check if the user wants to remove himself or the guest user account
  150. if ($user_id == ANONYMOUS)
  151. {
  152. trigger_error($user->lang['CANNOT_REMOVE_ANONYMOUS'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  153. }
  154. if ($user_id == $user->data['user_id'])
  155. {
  156. trigger_error($user->lang['CANNOT_REMOVE_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  157. }
  158. if ($delete_type)
  159. {
  160. if (confirm_box(true))
  161. {
  162. user_delete($delete_type, $user_id, $user_row['username']);
  163. add_log('admin', 'LOG_USER_DELETED', $user_row['username']);
  164. trigger_error($user->lang['USER_DELETED'] . adm_back_link($this->u_action));
  165. }
  166. else
  167. {
  168. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  169. 'u' => $user_id,
  170. 'i' => $id,
  171. 'mode' => $mode,
  172. 'action' => $action,
  173. 'update' => true,
  174. 'delete' => 1,
  175. 'delete_type' => $delete_type))
  176. );
  177. }
  178. }
  179. else
  180. {
  181. trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  182. }
  183. }
  184. // Handle quicktool actions
  185. switch ($action)
  186. {
  187. case 'banuser':
  188. case 'banemail':
  189. case 'banip':
  190. if ($user_id == $user->data['user_id'])
  191. {
  192. trigger_error($user->lang['CANNOT_BAN_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  193. }
  194. if ($user_id == ANONYMOUS)
  195. {
  196. trigger_error($user->lang['CANNOT_BAN_ANONYMOUS'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  197. }
  198. if ($user_row['user_type'] == USER_FOUNDER)
  199. {
  200. trigger_error($user->lang['CANNOT_BAN_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  201. }
  202. if (!check_form_key($form_name))
  203. {
  204. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  205. }
  206. $ban = array();
  207. switch ($action)
  208. {
  209. case 'banuser':
  210. $ban[] = $user_row['username'];
  211. $reason = 'USER_ADMIN_BAN_NAME_REASON';
  212. $log = 'LOG_USER_BAN_USER';
  213. break;
  214. case 'banemail':
  215. $ban[] = $user_row['user_email'];
  216. $reason = 'USER_ADMIN_BAN_EMAIL_REASON';
  217. $log = 'LOG_USER_BAN_EMAIL';
  218. break;
  219. case 'banip':
  220. $ban[] = $user_row['user_ip'];
  221. $sql = 'SELECT DISTINCT poster_ip
  222. FROM ' . POSTS_TABLE . "
  223. WHERE poster_id = $user_id";
  224. $result = $db->sql_query($sql);
  225. while ($row = $db->sql_fetchrow($result))
  226. {
  227. $ban[] = $row['poster_ip'];
  228. }
  229. $db->sql_freeresult($result);
  230. $reason = 'USER_ADMIN_BAN_IP_REASON';
  231. $log = 'LOG_USER_BAN_IP';
  232. break;
  233. }
  234. $ban_reason = utf8_normalize_nfc(request_var('ban_reason', $user->lang[$reason], true));
  235. $ban_give_reason = utf8_normalize_nfc(request_var('ban_give_reason', '', true));
  236. // Log not used at the moment, we simply utilize the ban function.
  237. $result = user_ban(substr($action, 3), $ban, 0, 0, 0, $ban_reason, $ban_give_reason);
  238. trigger_error((($result === false) ? $user->lang['BAN_ALREADY_ENTERED'] : $user->lang['BAN_SUCCESSFUL']) . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  239. break;
  240. case 'reactivate':
  241. if ($user_id == $user->data['user_id'])
  242. {
  243. trigger_error($user->lang['CANNOT_FORCE_REACT_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  244. }
  245. if (!check_form_key($form_name))
  246. {
  247. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  248. }
  249. if ($user_row['user_type'] == USER_FOUNDER)
  250. {
  251. trigger_error($user->lang['CANNOT_FORCE_REACT_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  252. }
  253. if ($user_row['user_type'] == USER_IGNORE)
  254. {
  255. trigger_error($user->lang['CANNOT_FORCE_REACT_BOT'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  256. }
  257. if ($config['email_enable'])
  258. {
  259. include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
  260. $server_url = generate_board_url();
  261. $user_actkey = gen_rand_string(mt_rand(6, 10));
  262. $email_template = ($user_row['user_type'] == USER_NORMAL) ? 'user_reactivate_account' : 'user_resend_inactive';
  263. if ($user_row['user_type'] == USER_NORMAL)
  264. {
  265. user_active_flip('deactivate', $user_id, INACTIVE_REMIND);
  266. $sql = 'UPDATE ' . USERS_TABLE . "
  267. SET user_actkey = '" . $db->sql_escape($user_actkey) . "'
  268. WHERE user_id = $user_id";
  269. $db->sql_query($sql);
  270. }
  271. else
  272. {
  273. // Grabbing the last confirm key - we only send a reminder
  274. $sql = 'SELECT user_actkey
  275. FROM ' . USERS_TABLE . '
  276. WHERE user_id = ' . $user_id;
  277. $result = $db->sql_query($sql);
  278. $user_actkey = (string) $db->sql_fetchfield('user_actkey');
  279. $db->sql_freeresult($result);
  280. }
  281. $messenger = new messenger(false);
  282. $messenger->template($email_template, $user_row['user_lang']);
  283. $messenger->to($user_row['user_email'], $user_row['username']);
  284. $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
  285. $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
  286. $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
  287. $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
  288. $messenger->assign_vars(array(
  289. 'WELCOME_MSG' => htmlspecialchars_decode(sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename'])),
  290. 'USERNAME' => htmlspecialchars_decode($user_row['username']),
  291. 'U_ACTIVATE' => "$server_url/ucp.$phpEx?mode=activate&u={$user_row['user_id']}&k=$user_actkey")
  292. );
  293. $messenger->send(NOTIFY_EMAIL);
  294. add_log('admin', 'LOG_USER_REACTIVATE', $user_row['username']);
  295. add_log('user', $user_id, 'LOG_USER_REACTIVATE_USER');
  296. trigger_error($user->lang['FORCE_REACTIVATION_SUCCESS'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  297. }
  298. break;
  299. case 'active':
  300. if ($user_id == $user->data['user_id'])
  301. {
  302. // It is only deactivation since the user is already activated (else he would not have reached this page)
  303. trigger_error($user->lang['CANNOT_DEACTIVATE_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  304. }
  305. if (!check_form_key($form_name))
  306. {
  307. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  308. }
  309. if ($user_row['user_type'] == USER_FOUNDER)
  310. {
  311. trigger_error($user->lang['CANNOT_DEACTIVATE_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  312. }
  313. if ($user_row['user_type'] == USER_IGNORE)
  314. {
  315. trigger_error($user->lang['CANNOT_DEACTIVATE_BOT'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  316. }
  317. user_active_flip('flip', $user_id);
  318. if ($user_row['user_type'] == USER_INACTIVE)
  319. {
  320. if ($config['require_activation'] == USER_ACTIVATION_ADMIN)
  321. {
  322. include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
  323. $messenger = new messenger(false);
  324. $messenger->template('admin_welcome_activated', $user_row['user_lang']);
  325. $messenger->to($user_row['user_email'], $user_row['username']);
  326. $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
  327. $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
  328. $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
  329. $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
  330. $messenger->assign_vars(array(
  331. 'USERNAME' => htmlspecialchars_decode($user_row['username']))
  332. );
  333. $messenger->send(NOTIFY_EMAIL);
  334. }
  335. }
  336. $message = ($user_row['user_type'] == USER_INACTIVE) ? 'USER_ADMIN_ACTIVATED' : 'USER_ADMIN_DEACTIVED';
  337. $log = ($user_row['user_type'] == USER_INACTIVE) ? 'LOG_USER_ACTIVE' : 'LOG_USER_INACTIVE';
  338. add_log('admin', $log, $user_row['username']);
  339. add_log('user', $user_id, $log . '_USER');
  340. trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  341. break;
  342. case 'delsig':
  343. if (!check_form_key($form_name))
  344. {
  345. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  346. }
  347. $sql_ary = array(
  348. 'user_sig' => '',
  349. 'user_sig_bbcode_uid' => '',
  350. 'user_sig_bbcode_bitfield' => ''
  351. );
  352. $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
  353. WHERE user_id = $user_id";
  354. $db->sql_query($sql);
  355. add_log('admin', 'LOG_USER_DEL_SIG', $user_row['username']);
  356. add_log('user', $user_id, 'LOG_USER_DEL_SIG_USER');
  357. trigger_error($user->lang['USER_ADMIN_SIG_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  358. break;
  359. case 'delavatar':
  360. if (!check_form_key($form_name))
  361. {
  362. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  363. }
  364. $sql_ary = array(
  365. 'user_avatar' => '',
  366. 'user_avatar_type' => 0,
  367. 'user_avatar_width' => 0,
  368. 'user_avatar_height' => 0,
  369. );
  370. $sql = 'UPDATE ' . USERS_TABLE . '
  371. SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
  372. WHERE user_id = $user_id";
  373. $db->sql_query($sql);
  374. // Delete old avatar if present
  375. if ($user_row['user_avatar'] && $user_row['user_avatar_type'] != AVATAR_GALLERY)
  376. {
  377. avatar_delete('user', $user_row);
  378. }
  379. add_log('admin', 'LOG_USER_DEL_AVATAR', $user_row['username']);
  380. add_log('user', $user_id, 'LOG_USER_DEL_AVATAR_USER');
  381. trigger_error($user->lang['USER_ADMIN_AVATAR_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  382. break;
  383. case 'delposts':
  384. if (confirm_box(true))
  385. {
  386. // Delete posts, attachments, etc.
  387. delete_posts('poster_id', $user_id);
  388. add_log('admin', 'LOG_USER_DEL_POSTS', $user_row['username']);
  389. trigger_error($user->lang['USER_POSTS_DELETED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  390. }
  391. else
  392. {
  393. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  394. 'u' => $user_id,
  395. 'i' => $id,
  396. 'mode' => $mode,
  397. 'action' => $action,
  398. 'update' => true))
  399. );
  400. }
  401. break;
  402. case 'delattach':
  403. if (confirm_box(true))
  404. {
  405. delete_attachments('user', $user_id);
  406. add_log('admin', 'LOG_USER_DEL_ATTACH', $user_row['username']);
  407. trigger_error($user->lang['USER_ATTACHMENTS_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  408. }
  409. else
  410. {
  411. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  412. 'u' => $user_id,
  413. 'i' => $id,
  414. 'mode' => $mode,
  415. 'action' => $action,
  416. 'update' => true))
  417. );
  418. }
  419. break;
  420. case 'deloutbox':
  421. if (confirm_box(true))
  422. {
  423. $msg_ids = array();
  424. $lang = 'EMPTY';
  425. $sql = 'SELECT msg_id
  426. FROM ' . PRIVMSGS_TO_TABLE . "
  427. WHERE author_id = $user_id
  428. AND folder_id = " . PRIVMSGS_OUTBOX;
  429. $result = $db->sql_query($sql);
  430. if ($row = $db->sql_fetchrow($result))
  431. {
  432. if (!function_exists('delete_pm'))
  433. {
  434. include($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
  435. }
  436. do
  437. {
  438. $msg_ids[] = (int) $row['msg_id'];
  439. }
  440. while ($row = $db->sql_fetchrow($result));
  441. $db->sql_freeresult($result);
  442. delete_pm($user_id, $msg_ids, PRIVMSGS_OUTBOX);
  443. add_log('admin', 'LOG_USER_DEL_OUTBOX', $user_row['username']);
  444. $lang = 'EMPTIED';
  445. }
  446. $db->sql_freeresult($result);
  447. trigger_error($user->lang['USER_OUTBOX_' . $lang] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  448. }
  449. else
  450. {
  451. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  452. 'u' => $user_id,
  453. 'i' => $id,
  454. 'mode' => $mode,
  455. 'action' => $action,
  456. 'update' => true))
  457. );
  458. }
  459. break;
  460. case 'moveposts':
  461. if (!check_form_key($form_name))
  462. {
  463. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  464. }
  465. $user->add_lang('acp/forums');
  466. $new_forum_id = request_var('new_f', 0);
  467. if (!$new_forum_id)
  468. {
  469. $this->page_title = 'USER_ADMIN_MOVE_POSTS';
  470. $template->assign_vars(array(
  471. 'S_SELECT_FORUM' => true,
  472. 'U_ACTION' => $this->u_action . "&amp;action=$action&amp;u=$user_id",
  473. 'U_BACK' => $this->u_action . "&amp;u=$user_id",
  474. 'S_FORUM_OPTIONS' => make_forum_select(false, false, false, true))
  475. );
  476. return;
  477. }
  478. // Is the new forum postable to?
  479. $sql = 'SELECT forum_name, forum_type
  480. FROM ' . FORUMS_TABLE . "
  481. WHERE forum_id = $new_forum_id";
  482. $result = $db->sql_query($sql);
  483. $forum_info = $db->sql_fetchrow($result);
  484. $db->sql_freeresult($result);
  485. if (!$forum_info)
  486. {
  487. trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  488. }
  489. if ($forum_info['forum_type'] != FORUM_POST)
  490. {
  491. trigger_error($user->lang['MOVE_POSTS_NO_POSTABLE_FORUM'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  492. }
  493. // Two stage?
  494. // Move topics comprising only posts from this user
  495. $topic_id_ary = $move_topic_ary = $move_post_ary = $new_topic_id_ary = array();
  496. $forum_id_ary = array($new_forum_id);
  497. $sql = 'SELECT topic_id, COUNT(post_id) AS total_posts
  498. FROM ' . POSTS_TABLE . "
  499. WHERE poster_id = $user_id
  500. AND forum_id <> $new_forum_id
  501. GROUP BY topic_id";
  502. $result = $db->sql_query($sql);
  503. while ($row = $db->sql_fetchrow($result))
  504. {
  505. $topic_id_ary[$row['topic_id']] = $row['total_posts'];
  506. }
  507. $db->sql_freeresult($result);
  508. if (sizeof($topic_id_ary))
  509. {
  510. $sql = 'SELECT topic_id, forum_id, topic_title, topic_replies, topic_replies_real, topic_attachment
  511. FROM ' . TOPICS_TABLE . '
  512. WHERE ' . $db->sql_in_set('topic_id', array_keys($topic_id_ary));
  513. $result = $db->sql_query($sql);
  514. while ($row = $db->sql_fetchrow($result))
  515. {
  516. if (max($row['topic_replies'], $row['topic_replies_real']) + 1 == $topic_id_ary[$row['topic_id']])
  517. {
  518. $move_topic_ary[] = $row['topic_id'];
  519. }
  520. else
  521. {
  522. $move_post_ary[$row['topic_id']]['title'] = $row['topic_title'];
  523. $move_post_ary[$row['topic_id']]['attach'] = ($row['topic_attachment']) ? 1 : 0;
  524. }
  525. $forum_id_ary[] = $row['forum_id'];
  526. }
  527. $db->sql_freeresult($result);
  528. }
  529. // Entire topic comprises posts by this user, move these topics
  530. if (sizeof($move_topic_ary))
  531. {
  532. move_topics($move_topic_ary, $new_forum_id, false);
  533. }
  534. if (sizeof($move_post_ary))
  535. {
  536. // Create new topic
  537. // Update post_ids, report_ids, attachment_ids
  538. foreach ($move_post_ary as $topic_id => $post_ary)
  539. {
  540. // Create new topic
  541. $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
  542. 'topic_poster' => $user_id,
  543. 'topic_time' => time(),
  544. 'forum_id' => $new_forum_id,
  545. 'icon_id' => 0,
  546. 'topic_approved' => 1,
  547. 'topic_title' => $post_ary['title'],
  548. 'topic_first_poster_name' => $user_row['username'],
  549. 'topic_type' => POST_NORMAL,
  550. 'topic_time_limit' => 0,
  551. 'topic_attachment' => $post_ary['attach'])
  552. );
  553. $db->sql_query($sql);
  554. $new_topic_id = $db->sql_nextid();
  555. // Move posts
  556. $sql = 'UPDATE ' . POSTS_TABLE . "
  557. SET forum_id = $new_forum_id, topic_id = $new_topic_id
  558. WHERE topic_id = $topic_id
  559. AND poster_id = $user_id";
  560. $db->sql_query($sql);
  561. if ($post_ary['attach'])
  562. {
  563. $sql = 'UPDATE ' . ATTACHMENTS_TABLE . "
  564. SET topic_id = $new_topic_id
  565. WHERE topic_id = $topic_id
  566. AND poster_id = $user_id";
  567. $db->sql_query($sql);
  568. }
  569. $new_topic_id_ary[] = $new_topic_id;
  570. }
  571. }
  572. $forum_id_ary = array_unique($forum_id_ary);
  573. $topic_id_ary = array_unique(array_merge(array_keys($topic_id_ary), $new_topic_id_ary));
  574. if (sizeof($topic_id_ary))
  575. {
  576. sync('topic_reported', 'topic_id', $topic_id_ary);
  577. sync('topic', 'topic_id', $topic_id_ary);
  578. }
  579. if (sizeof($forum_id_ary))
  580. {
  581. sync('forum', 'forum_id', $forum_id_ary, false, true);
  582. }
  583. add_log('admin', 'LOG_USER_MOVE_POSTS', $user_row['username'], $forum_info['forum_name']);
  584. add_log('user', $user_id, 'LOG_USER_MOVE_POSTS_USER', $forum_info['forum_name']);
  585. trigger_error($user->lang['USER_POSTS_MOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  586. break;
  587. case 'leave_nr':
  588. if (confirm_box(true))
  589. {
  590. remove_newly_registered($user_id, $user_row);
  591. add_log('admin', 'LOG_USER_REMOVED_NR', $user_row['username']);
  592. trigger_error($user->lang['USER_LIFTED_NR'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  593. }
  594. else
  595. {
  596. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  597. 'u' => $user_id,
  598. 'i' => $id,
  599. 'mode' => $mode,
  600. 'action' => $action,
  601. 'update' => true))
  602. );
  603. }
  604. break;
  605. }
  606. // Handle registration info updates
  607. $data = array(
  608. 'username' => utf8_normalize_nfc(request_var('user', $user_row['username'], true)),
  609. 'user_founder' => request_var('user_founder', ($user_row['user_type'] == USER_FOUNDER) ? 1 : 0),
  610. 'email' => strtolower(request_var('user_email', $user_row['user_email'])),
  611. 'email_confirm' => strtolower(request_var('email_confirm', '')),
  612. 'new_password' => request_var('new_password', '', true),
  613. 'password_confirm' => request_var('password_confirm', '', true),
  614. );
  615. // Validation data - we do not check the password complexity setting here
  616. $check_ary = array(
  617. 'new_password' => array(
  618. array('string', true, $config['min_pass_chars'], $config['max_pass_chars']),
  619. array('password')),
  620. 'password_confirm' => array('string', true, $config['min_pass_chars'], $config['max_pass_chars']),
  621. );
  622. // Check username if altered
  623. if ($data['username'] != $user_row['username'])
  624. {
  625. $check_ary += array(
  626. 'username' => array(
  627. array('string', false, $config['min_name_chars'], $config['max_name_chars']),
  628. array('username', $user_row['username'])
  629. ),
  630. );
  631. }
  632. // Check email if altered
  633. if ($data['email'] != $user_row['user_email'])
  634. {
  635. $check_ary += array(
  636. 'email' => array(
  637. array('string', false, 6, 60),
  638. array('email', $user_row['user_email'])
  639. ),
  640. 'email_confirm' => array('string', true, 6, 60)
  641. );
  642. }
  643. $error = validate_data($data, $check_ary);
  644. if ($data['new_password'] && $data['password_confirm'] != $data['new_password'])
  645. {
  646. $error[] = 'NEW_PASSWORD_ERROR';
  647. }
  648. if ($data['email'] != $user_row['user_email'] && $data['email_confirm'] != $data['email'])
  649. {
  650. $error[] = 'NEW_EMAIL_ERROR';
  651. }
  652. if (!check_form_key($form_name))
  653. {
  654. $error[] = 'FORM_INVALID';
  655. }
  656. // Which updates do we need to do?
  657. $update_username = ($user_row['username'] != $data['username']) ? $data['username'] : false;
  658. $update_password = ($data['new_password'] && !phpbb_check_hash($user_row['user_password'], $data['new_password'])) ? true : false;
  659. $update_email = ($data['email'] != $user_row['user_email']) ? $data['email'] : false;
  660. if (!sizeof($error))
  661. {
  662. $sql_ary = array();
  663. if ($user_row['user_type'] != USER_FOUNDER || $user->data['user_type'] == USER_FOUNDER)
  664. {
  665. // Only allow founders updating the founder status...
  666. if ($user->data['user_type'] == USER_FOUNDER)
  667. {
  668. // Setting a normal member to be a founder
  669. if ($data['user_founder'] && $user_row['user_type'] != USER_FOUNDER)
  670. {
  671. // Make sure the user is not setting an Inactive or ignored user to be a founder
  672. if ($user_row['user_type'] == USER_IGNORE)
  673. {
  674. trigger_error($user->lang['CANNOT_SET_FOUNDER_IGNORED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  675. }
  676. if ($user_row['user_type'] == USER_INACTIVE)
  677. {
  678. trigger_error($user->lang['CANNOT_SET_FOUNDER_INACTIVE'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  679. }
  680. $sql_ary['user_type'] = USER_FOUNDER;
  681. }
  682. else if (!$data['user_founder'] && $user_row['user_type'] == USER_FOUNDER)
  683. {
  684. // Check if at least one founder is present
  685. $sql = 'SELECT user_id
  686. FROM ' . USERS_TABLE . '
  687. WHERE user_type = ' . USER_FOUNDER . '
  688. AND user_id <> ' . $user_id;
  689. $result = $db->sql_query_limit($sql, 1);
  690. $row = $db->sql_fetchrow($result);
  691. $db->sql_freeresult($result);
  692. if ($row)
  693. {
  694. $sql_ary['user_type'] = USER_NORMAL;
  695. }
  696. else
  697. {
  698. trigger_error($user->lang['AT_LEAST_ONE_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  699. }
  700. }
  701. }
  702. }
  703. if ($update_username !== false)
  704. {
  705. $sql_ary['username'] = $update_username;
  706. $sql_ary['username_clean'] = utf8_clean_string($update_username);
  707. add_log('user', $user_id, 'LOG_USER_UPDATE_NAME', $user_row['username'], $update_username);
  708. }
  709. if ($update_email !== false)
  710. {
  711. $sql_ary += array(
  712. 'user_email' => $update_email,
  713. 'user_email_hash' => phpbb_email_hash($update_email),
  714. );
  715. add_log('user', $user_id, 'LOG_USER_UPDATE_EMAIL', $user_row['username'], $user_row['user_email'], $update_email);
  716. }
  717. if ($update_password)
  718. {
  719. $sql_ary += array(
  720. 'user_password' => phpbb_hash($data['new_password']),
  721. 'user_passchg' => time(),
  722. 'user_pass_convert' => 0,
  723. );
  724. $user->reset_login_keys($user_id);
  725. add_log('user', $user_id, 'LOG_USER_NEW_PASSWORD', $user_row['username']);
  726. }
  727. if (sizeof($sql_ary))
  728. {
  729. $sql = 'UPDATE ' . USERS_TABLE . '
  730. SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
  731. WHERE user_id = ' . $user_id;
  732. $db->sql_query($sql);
  733. }
  734. if ($update_username)
  735. {
  736. user_update_name($user_row['username'], $update_username);
  737. }
  738. // Let the users permissions being updated
  739. $auth->acl_clear_prefetch($user_id);
  740. add_log('admin', 'LOG_USER_USER_UPDATE', $data['username']);
  741. trigger_error($user->lang['USER_OVERVIEW_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  742. }
  743. // Replace "error" strings with their real, localised form
  744. $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
  745. }
  746. if ($user_id == $user->data['user_id'])
  747. {
  748. $quick_tool_ary = array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH', 'deloutbox' => 'DEL_OUTBOX');
  749. if ($user_row['user_new'])
  750. {
  751. $quick_tool_ary['leave_nr'] = 'LEAVE_NR';
  752. }
  753. }
  754. else
  755. {
  756. $quick_tool_ary = array();
  757. if ($user_row['user_type'] != USER_FOUNDER)
  758. {
  759. $quick_tool_ary += array('banuser' => 'BAN_USER', 'banemail' => 'BAN_EMAIL', 'banip' => 'BAN_IP');
  760. }
  761. if ($user_row['user_type'] != USER_FOUNDER && $user_row['user_type'] != USER_IGNORE)
  762. {
  763. $quick_tool_ary += array('active' => (($user_row['user_type'] == USER_INACTIVE) ? 'ACTIVATE' : 'DEACTIVATE'));
  764. }
  765. $quick_tool_ary += array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH', 'deloutbox' => 'DEL_OUTBOX');
  766. if ($config['email_enable'] && ($user_row['user_type'] == USER_NORMAL || $user_row['user_type'] == USER_INACTIVE))
  767. {
  768. $quick_tool_ary['reactivate'] = 'FORCE';
  769. }
  770. if ($user_row['user_new'])
  771. {
  772. $quick_tool_ary['leave_nr'] = 'LEAVE_NR';
  773. }
  774. }
  775. $s_action_options = '<option class="sep" value="">' . $user->lang['SELECT_OPTION'] . '</option>';
  776. foreach ($quick_tool_ary as $value => $lang)
  777. {
  778. $s_action_options .= '<option value="' . $value . '">' . $user->lang['USER_ADMIN_' . $lang] . '</option>';
  779. }
  780. if ($config['load_onlinetrack'])
  781. {
  782. $sql = 'SELECT MAX(session_time) AS session_time, MIN(session_viewonline) AS session_viewonline
  783. FROM ' . SESSIONS_TABLE . "
  784. WHERE session_user_id = $user_id";
  785. $result = $db->sql_query($sql);
  786. $row = $db->sql_fetchrow($result);
  787. $db->sql_freeresult($result);
  788. $user_row['session_time'] = (isset($row['session_time'])) ? $row['session_time'] : 0;
  789. $user_row['session_viewonline'] = (isset($row['session_viewonline'])) ? $row['session_viewonline'] : 0;
  790. unset($row);
  791. }
  792. $last_visit = (!empty($user_row['session_time'])) ? $user_row['session_time'] : $user_row['user_lastvisit'];
  793. $inactive_reason = '';
  794. if ($user_row['user_type'] == USER_INACTIVE)
  795. {
  796. $inactive_reason = $user->lang['INACTIVE_REASON_UNKNOWN'];
  797. switch ($user_row['user_inactive_reason'])
  798. {
  799. case INACTIVE_REGISTER:
  800. $inactive_reason = $user->lang['INACTIVE_REASON_REGISTER'];
  801. break;
  802. case INACTIVE_PROFILE:
  803. $inactive_reason = $user->lang['INACTIVE_REASON_PROFILE'];
  804. break;
  805. case INACTIVE_MANUAL:
  806. $inactive_reason = $user->lang['INACTIVE_REASON_MANUAL'];
  807. break;
  808. case INACTIVE_REMIND:
  809. $inactive_reason = $user->lang['INACTIVE_REASON_REMIND'];
  810. break;
  811. }
  812. }
  813. // Posts in Queue
  814. $sql = 'SELECT COUNT(post_id) as posts_in_queue
  815. FROM ' . POSTS_TABLE . '
  816. WHERE poster_id = ' . $user_id . '
  817. AND post_approved = 0';
  818. $result = $db->sql_query($sql);
  819. $user_row['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue');
  820. $db->sql_freeresult($result);
  821. $template->assign_vars(array(
  822. 'L_NAME_CHARS_EXPLAIN' => sprintf($user->lang[$config['allow_name_chars'] . '_EXPLAIN'], $config['min_name_chars'], $config['max_name_chars']),
  823. 'L_CHANGE_PASSWORD_EXPLAIN' => sprintf($user->lang[$config['pass_complex'] . '_EXPLAIN'], $config['min_pass_chars'], $config['max_pass_chars']),
  824. 'L_POSTS_IN_QUEUE' => $user->lang('NUM_POSTS_IN_QUEUE', $user_row['posts_in_queue']),
  825. 'S_FOUNDER' => ($user->data['user_type'] == USER_FOUNDER) ? true : false,
  826. 'S_OVERVIEW' => true,
  827. 'S_USER_IP' => ($user_row['user_ip']) ? true : false,
  828. 'S_USER_FOUNDER' => ($user_row['user_type'] == USER_FOUNDER) ? true : false,
  829. 'S_ACTION_OPTIONS' => $s_action_options,
  830. 'S_OWN_ACCOUNT' => ($user_id == $user->data['user_id']) ? true : false,
  831. 'S_USER_INACTIVE' => ($user_row['user_type'] == USER_INACTIVE) ? true : false,
  832. 'U_SHOW_IP' => $this->u_action . "&amp;u=$user_id&amp;ip=" . (($ip == 'ip') ? 'hostname' : 'ip'),
  833. 'U_WHOIS' => $this->u_action . "&amp;action=whois&amp;user_ip={$user_row['user_ip']}",
  834. 'U_MCP_QUEUE' => ($auth->acl_getf_global('m_approve')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue', true, $user->session_id) : '',
  835. 'U_SWITCH_PERMISSIONS' => ($auth->acl_get('a_switchperm') && $user->data['user_id'] != $user_row['user_id']) ? append_sid("{$phpbb_root_path}ucp.$phpEx", "mode=switch_perm&amp;u={$user_row['user_id']}&amp;hash=" . generate_link_hash('switchperm')) : '',
  836. 'POSTS_IN_QUEUE' => $user_row['posts_in_queue'],
  837. 'USER' => $user_row['username'],
  838. 'USER_REGISTERED' => $user->format_date($user_row['user_regdate']),
  839. 'REGISTERED_IP' => ($ip == 'hostname') ? gethostbyaddr($user_row['user_ip']) : $user_row['user_ip'],
  840. 'USER_LASTACTIVE' => ($last_visit) ? $user->format_date($last_visit) : ' - ',
  841. 'USER_EMAIL' => $user_row['user_email'],
  842. 'USER_WARNINGS' => $user_row['user_warnings'],
  843. 'USER_POSTS' => $user_row['user_posts'],
  844. 'USER_INACTIVE_REASON' => $inactive_reason,
  845. ));
  846. break;
  847. case 'feedback':
  848. $user->add_lang('mcp');
  849. // Set up general vars
  850. $start = request_var('start', 0);
  851. $deletemark = (isset($_POST['delmarked'])) ? true : false;
  852. $deleteall = (isset($_POST['delall'])) ? true : false;
  853. $marked = request_var('mark', array(0));
  854. $message = utf8_normalize_nfc(request_var('message', '', true));
  855. // Sort keys
  856. $sort_days = request_var('st', 0);
  857. $sort_key = request_var('sk', 't');
  858. $sort_dir = request_var('sd', 'd');
  859. // Delete entries if requested and able
  860. if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs'))
  861. {
  862. if (!check_form_key($form_name))
  863. {
  864. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  865. }
  866. $where_sql = '';
  867. if ($deletemark && $marked)
  868. {
  869. $sql_in = array();
  870. foreach ($marked as $mark)
  871. {
  872. $sql_in[] = $mark;
  873. }
  874. $where_sql = ' AND ' . $db->sql_in_set('log_id', $sql_in);
  875. unset($sql_in);
  876. }
  877. if ($where_sql || $deleteall)
  878. {
  879. $sql = 'DELETE FROM ' . LOG_TABLE . '
  880. WHERE log_type = ' . LOG_USERS . "
  881. AND reportee_id = $user_id
  882. $where_sql";
  883. $db->sql_query($sql);
  884. add_log('admin', 'LOG_CLEAR_USER', $user_row['username']);
  885. }
  886. }
  887. if ($submit && $message)
  888. {
  889. if (!check_form_key($form_name))
  890. {
  891. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  892. }
  893. add_log('admin', 'LOG_USER_FEEDBACK', $user_row['username']);
  894. add_log('mod', 0, 0, 'LOG_USER_FEEDBACK', $user_row['username']);
  895. add_log('user', $user_id, 'LOG_USER_GENERAL', $message);
  896. trigger_error($user->lang['USER_FEEDBACK_ADDED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  897. }
  898. // Sorting
  899. $limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
  900. $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
  901. $sort_by_sql = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
  902. $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
  903. gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
  904. // Define where and sort sql for use in displaying logs
  905. $sql_where = ($sort_days) ? (time() - ($sort_days * 86400)) : 0;
  906. $sql_sort = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
  907. // Grab log data
  908. $log_data = array();
  909. $log_count = 0;
  910. view_log('user', $log_data, $log_count, $config['topics_per_page'], $start, 0, 0, $user_id, $sql_where, $sql_sort);
  911. $template->assign_vars(array(
  912. 'S_FEEDBACK' => true,
  913. 'S_ON_PAGE' => on_page($log_count, $config['topics_per_page'], $start),
  914. 'PAGINATION' => generate_pagination($this->u_action . "&amp;u=$user_id&amp;$u_sort_param", $log_count, $config['topics_per_page'], $start, true),
  915. 'S_LIMIT_DAYS' => $s_limit_days,
  916. 'S_SORT_KEY' => $s_sort_key,
  917. 'S_SORT_DIR' => $s_sort_dir,
  918. 'S_CLEARLOGS' => $auth->acl_get('a_clearlogs'))
  919. );
  920. foreach ($log_data as $row)
  921. {
  922. $template->assign_block_vars('log', array(
  923. 'USERNAME' => $row['username_full'],
  924. 'IP' => $row['ip'],
  925. 'DATE' => $user->format_date($row['time']),
  926. 'ACTION' => nl2br($row['action']),
  927. 'ID' => $row['id'])
  928. );
  929. }
  930. break;
  931. case 'warnings':
  932. $user->add_lang('mcp');
  933. // Set up general vars
  934. $start = request_var('start', 0);
  935. $deletemark = (isset($_POST['delmarked'])) ? true : false;
  936. $deleteall = (isset($_POST['delall'])) ? true : false;
  937. $confirm = (isset($_POST['confirm'])) ? true : false;
  938. $marked = request_var('mark', array(0));
  939. $message = utf8_normalize_nfc(request_var('message', '', true));
  940. // Sort keys
  941. $sort_days = request_var('st', 0);
  942. $sort_key = request_var('sk', 't');
  943. $sort_dir = request_var('sd', 'd');
  944. // Delete entries if requested and able
  945. if ($deletemark || $deleteall || $confirm)
  946. {
  947. if (confirm_box(true))
  948. {
  949. $where_sql = '';
  950. $deletemark = request_var('delmarked', 0);
  951. $deleteall = request_var('delall', 0);
  952. if ($deletemark && $marked)
  953. {
  954. $where_sql = ' AND ' . $db->sql_in_set('warning_id', array_values($marked));
  955. }
  956. if ($where_sql || $deleteall)
  957. {
  958. $sql = 'DELETE FROM ' . WARNINGS_TABLE . "
  959. WHERE user_id = $user_id
  960. $where_sql";
  961. $db->sql_query($sql);
  962. if ($deleteall)
  963. {
  964. $log_warnings = $deleted_warnings = 0;
  965. }
  966. else
  967. {
  968. $num_warnings = (int) $db->sql_affectedrows();
  969. $deleted_warnings = ' user_warnings - ' . $num_warnings;
  970. $log_warnings = ($num_warnings > 2) ? 2 : $num_warnings;
  971. }
  972. $sql = 'UPDATE ' . USERS_TABLE . "
  973. SET user_warnings = $deleted_warnings
  974. WHERE user_id = $user_id";
  975. $db->sql_query($sql);
  976. switch ($log_warnings)
  977. {
  978. case 2:
  979. add_log('admin', 'LOG_WARNINGS_DELETED', $user_row['username'], $num_warnings);
  980. break;
  981. case 1:
  982. add_log('admin', 'LOG_WARNING_DELETED', $user_row['username']);
  983. break;
  984. default:
  985. add_log('admin', 'LOG_WARNINGS_DELETED_ALL', $user_row['username']);
  986. break;
  987. }
  988. }
  989. }
  990. else
  991. {
  992. $s_hidden_fields = array(
  993. 'i' => $id,
  994. 'mode' => $mode,
  995. 'u' => $user_id,
  996. 'mark' => $marked,
  997. );
  998. if (isset($_POST['delmarked']))
  999. {
  1000. $s_hidden_fields['delmarked'] = 1;
  1001. }
  1002. if (isset($_POST['delall']))
  1003. {
  1004. $s_hidden_fields['delall'] = 1;
  1005. }
  1006. if (isset($_POST['delall']) || (isset($_POST['delmarked']) && sizeof($marked)))
  1007. {
  1008. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields));
  1009. }
  1010. }
  1011. }
  1012. $sql = 'SELECT w.warning_id, w.warning_time, w.post_id, l.log_operation, l.log_data, l.user_id AS mod_user_id, m.username AS mod_username, m.user_colour AS mod_user_colour
  1013. FROM ' . WARNINGS_TABLE . ' w
  1014. LEFT JOIN ' . LOG_TABLE . ' l
  1015. ON (w.log_id = l.log_id)
  1016. LEFT JOIN ' . USERS_TABLE . ' m
  1017. ON (l.user_id = m.user_id)
  1018. WHERE w.user_id = ' . $user_id . '
  1019. ORDER BY w.warning_time DESC';
  1020. $result = $db->sql_query($sql);
  1021. while ($row = $db->sql_fetchrow($result))
  1022. {
  1023. if (!$row['log_operation'])
  1024. {
  1025. // We do not have a log-entry anymore, so there is no data available
  1026. $row['action'] = $user->lang['USER_WARNING_LOG_DELETED'];
  1027. }
  1028. else
  1029. {
  1030. $row['action'] = (isset($user->lang[$row['log_operation']])) ? $user->lang[$row['log_operation']] : '{' . ucfirst(str_replace('_', ' ', $row['log_operation'])) . '}';
  1031. if (!empty($row['log_data']))
  1032. {
  1033. $log_data_ary = @unserialize($row['log_data']);
  1034. $log_data_ary = ($log_data_ary === false) ? array() : $log_data_ary;
  1035. if (isset($user->lang[$row['log_operation']]))
  1036. {
  1037. // Check if there are more occurrences of % than arguments, if there are we fill out the arguments array
  1038. // It doesn't matter if we add more arguments than placeholders
  1039. if ((substr_count($row['action'], '%') - sizeof($log_data_ary)) > 0)
  1040. {
  1041. $log_data_ary = array_merge($log_data_ary, array_fill(0, substr_count($row['action'], '%') - sizeof($log_data_ary), ''));
  1042. }
  1043. $row['action'] = vsprintf($row['action'], $log_data_ary);
  1044. $row['action'] = bbcode_nl2br(censor_text($row['action']));
  1045. }
  1046. else if (!empty($log_data_ary))
  1047. {
  1048. $row['action'] .= '<br />' . implode('', $log_data_ary);
  1049. }
  1050. }
  1051. }
  1052. $template->assign_block_vars('warn', array(
  1053. 'ID' => $row['warning_id'],
  1054. 'USERNAME' => ($row['log_operation']) ? get_username_string('full', $row['mod_user_id'], $row['mod_username'], $row['mod_user_colour']) : '-',
  1055. 'ACTION' => make_clickable($row['action']),
  1056. 'DATE' => $user->format_date($row['warning_time']),
  1057. ));
  1058. }
  1059. $db->sql_freeresult($result);
  1060. $template->assign_vars(array(
  1061. 'S_WARNINGS' => true,
  1062. ));
  1063. break;
  1064. case 'profile':
  1065. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  1066. include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
  1067. $cp = new custom_profile();
  1068. $cp_data = $cp_error = array();
  1069. $sql = 'SELECT lang_id
  1070. FROM ' . LANG_TABLE . "
  1071. WHERE lang_iso = '" . $db->sql_escape($user->data['user_lang']) . "'";
  1072. $result = $db->sql_query($sql);
  1073. $row = $db->sql_fetchrow($result);
  1074. $db->sql_freeresult($result);
  1075. $user_row['iso_lang_id'] = $row['lang_id'];
  1076. $data = array(
  1077. 'icq' => request_var('icq', $user_row['user_icq']),
  1078. 'aim' => request_var('aim', $user_row['user_aim']),
  1079. 'msn' => request_var('msn', $user_row['user_msnm']),
  1080. 'yim' => request_var('yim', $user_row['user_yim']),
  1081. 'jabber' => utf8_normalize_nfc(request_var('jabber', $user_row['user_jabber'], true)),
  1082. 'website' => request_var('website', $user_row['user_website']),
  1083. 'location' => utf8_normalize_nfc(request_var('location', $user_row['user_from'], true)),
  1084. 'occupation' => utf8_normalize_nfc(request_var('occupation', $user_row['user_occ'], true)),
  1085. 'interests' => utf8_normalize_nfc(request_var('interests', $user_row['user_interests'], true)),
  1086. 'bday_day' => 0,
  1087. 'bday_month' => 0,
  1088. 'bday_year' => 0,
  1089. );
  1090. if ($user_row['user_birthday'])
  1091. {
  1092. list($data['bday_day'], $data['bday_month'], $data['bday_year']) = explode('-', $user_row['user_birthday']);
  1093. }
  1094. $data['bday_day'] = request_var('bday_day', $data['bday_day']);
  1095. $data['bday_month'] = request_var('bday_month', $data['bday_month']);
  1096. $data['bday_year'] = request_var('bday_year', $data['bday_year']);
  1097. $data['user_birthday'] = sprintf('%2d-%2d-%4d', $data['bday_day'], $data['bday_month'], $data['bday_year']);
  1098. if ($submit)
  1099. {
  1100. $error = validate_data($data, array(
  1101. 'icq' => array(
  1102. array('string', true, 3, 15),
  1103. array('match', true, '#^[0-9]+$#i')),
  1104. 'aim' => array('string', true, 3, 255),
  1105. 'msn' => array('string', true, 5, 255),
  1106. 'jabber' => array(
  1107. array('string', true, 5, 255),
  1108. array('jabber')),
  1109. 'yim' => array('string', true, 5, 255),
  1110. 'website' => array(
  1111. array('string', true, 12, 255),
  1112. array('match', true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i')),
  1113. 'location' => array('string', true, 2, 100),
  1114. 'occupation' => array('string', true, 2, 500),
  1115. 'interests' => array('string', true, 2, 500),
  1116. 'bday_day' => array('num', true, 1, 31),
  1117. 'bday_month' => array('num', true, 1, 12),
  1118. 'bday_year' => array('num', true, 1901, gmdate('Y', time())),
  1119. 'user_birthday' => array('date', true),
  1120. ));
  1121. // validate custom profile fields
  1122. $cp->submit_cp_field('profile', $user_row['iso_lang_id'], $cp_data, $cp_error);
  1123. if (sizeof($cp_error))
  1124. {
  1125. $error = array_merge($error, $cp_error);
  1126. }
  1127. if (!check_form_key($form_name))
  1128. {
  1129. $error[] = 'FORM_INVALID';
  1130. }
  1131. if (!sizeof($error))
  1132. {
  1133. $sql_ary = array(
  1134. 'user_icq' => $data['icq'],
  1135. 'user_aim' => $data['aim'],
  1136. 'user_msnm' => $data['msn'],
  1137. 'user_yim' => $data['yim'],
  1138. 'user_jabber' => $data['jabber'],
  1139. 'user_website' => $data['website'],
  1140. 'user_from' => $data['location'],
  1141. 'user_occ' => $data['occupation'],
  1142. 'user_interests'=> $data['interests'],
  1143. 'user_birthday' => $data['user_birthday'],
  1144. );
  1145. $sql = 'UPDATE ' . USERS_TABLE . '
  1146. SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
  1147. WHERE user_id = $user_id";
  1148. $db->sql_query($sql);
  1149. // Update Custom Fields
  1150. $cp->update_profile_field_data($user_id, $cp_data);
  1151. trigger_error($user->lang['USER_PROFILE_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  1152. }
  1153. // Replace "error" strings with their real, localised form
  1154. $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
  1155. }
  1156. $s_birthday_day_options = '<option value="0"' . ((!$data['bday_day']) ? ' selected="selected"' : '') . '>--</option>';
  1157. for ($i = 1; $i < 32; $i++)
  1158. {
  1159. $selected = ($i == $data['bday_day']) ? ' selected="selected"' : '';
  1160. $s_birthday_day_options .= "<option value=\"$i\"$selected>$i</option>";
  1161. }
  1162. $s_birthday_month_options = '<option value="0"' . ((!$data['bday_month']) ? ' selected="selected"' : '') . '>--</option>';
  1163. for ($i = 1; $i < 13; $i++)
  1164. {
  1165. $selected = ($i == $data['bday_month']) ? ' selected="selected"' : '';
  1166. $s_birthday_month_options .= "<option value=\"$i\"$selected>$i</option>";
  1167. }
  1168. $s_birthday_year_options = '';
  1169. $now = getdate();
  1170. $s_birthday_year_options = '<option value="0"' . ((!$data['bday_year']) ? ' selected="selected"' : '') . '>--</option>';
  1171. for ($i = $now['year'] - 100; $i <= $now['year']; $i++)
  1172. {
  1173. $selected = ($i == $data['bday_year']) ? ' selected="selected"' : '';
  1174. $s_birthday_year_options .= "<option value=\"$i\"$selected>$i</option>";
  1175. }
  1176. unset($now);
  1177. $template->assign_vars(array(
  1178. 'ICQ' => $data['icq'],
  1179. 'YIM' => $data['yim'],
  1180. 'AIM' => $data['aim'],
  1181. 'MSN' => $data['msn'],
  1182. 'JABBER' => $data['jabber'],
  1183. 'WEBSITE' => $data['website'],
  1184. 'LOCATION' => $data['location'],
  1185. 'OCCUPATION' => $data['occupation'],
  1186. 'INTERESTS' => $data['interests'],
  1187. 'S_BIRTHDAY_DAY_OPTIONS' => $s_birthday_day_options,
  1188. 'S_BIRTHDAY_MONTH_OPTIONS' => $s_birthday_month_options,
  1189. 'S_BIRTHDAY_YEAR_OPTIONS' => $s_birthday_year_options,
  1190. 'S_PROFILE' => true)
  1191. );
  1192. // Get additional profile fields and assign them to the template block var 'profile_fields'
  1193. $user->get_profile_fields($user_id);
  1194. $cp->generate_profile_fields('profile', $user_row['iso_lang_id']);
  1195. break;
  1196. case 'prefs':
  1197. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  1198. $data = array(
  1199. 'dateformat' => utf8_normalize_nfc(request_var('dateformat', $user_row['user_dateformat'], true)),
  1200. 'lang' => basename(request_var('lang', $user_row['user_lang'])),
  1201. 'tz' => request_var('tz', (float) $user_row['user_timezone']),
  1202. 'style' => request_var('style', $user_row['user_style']),
  1203. 'dst' => request_var('dst', $user_row['user_dst']),
  1204. 'viewemail' => request_var('viewemail', $user_row['user_allow_viewemail']),
  1205. 'massemail' => request_var('massemail', $user_row['user_allow_massemail']),
  1206. 'hideonline' => request_var('hideonline', !$user_row['user_allow_viewonline']),
  1207. 'notifymethod' => request_var('notifymethod', $user_row['user_notify_type']),
  1208. 'notifypm' => request_var('notifypm', $user_row['user_notify_pm']),
  1209. 'popuppm' => request_var('popuppm', $this->optionget($user_row, 'popuppm')),
  1210. 'allowpm' => request_var('allowpm', $user_row['user_allow_pm']),
  1211. 'topic_sk' => request_var('topic_sk', ($user_row['user_topic_sortby_type']) ? $user_row['user_topic_sortby_type'] : 't'),
  1212. 'topic_sd' => request_var('topic_sd', ($user_row['user_topic_sortby_dir']) ? $user_row['user_topic_sortby_dir'] : 'd'),
  1213. 'topic_st' => request_var('topic_st', ($user_row['user_topic_show_days']) ? $user_row['user_topic_show_days'] : 0),
  1214. 'post_sk' => request_var('post_sk', ($user_row['user_post_sortby_type']) ? $user_row['user_post_sortby_type'] : 't'),
  1215. 'post_sd' => request_var('post_sd', ($user_row['user_post_sortby_dir']) ? $user_row['user_post_sortby_dir'] : 'a'),
  1216. 'post_st' => request_var('post_st', ($user_row['user_post_show_days']) ? $user_row['user_post_show_days'] : 0),
  1217. 'view_images' => request_var('view_images', $this->optionget($user_row, 'viewimg')),
  1218. 'view_flash' => request_var('view_flash', $this->optionget($user_row, 'viewflash')),
  1219. 'view_smilies' => request_var('view_smilies', $this->optionget($user_row, 'viewsmilies')),
  1220. 'view_sigs' => request_var('view_sigs', $this->optionget($user_row, 'viewsigs')),
  1221. 'view_avatars' => request_var('view_avatars', $this->optionget($user_row, 'viewavatars')),
  1222. 'view_wordcensor' => request_var('view_wordcensor', $this->optionget($user_row, 'viewcensors')),
  1223. 'bbcode' => request_var('bbcode', $this->optionget($user_row, 'bbcode')),
  1224. 'smilies' => request_var('smilies', $this->optionget($user_row, 'smilies')),
  1225. 'sig' => request_var('sig', $this->optionget($user_row, 'attachsig')),
  1226. 'notify' => request_var('notify', $user_row['user_notify']),
  1227. );
  1228. if ($submit)
  1229. {
  1230. $error = validate_data($data, array(
  1231. 'dateformat' => array('string', false, 1, 30),
  1232. 'lang' => array('match', false, '#^[a-z_\-]{2,}$#i'),
  1233. 'tz' => array('num', false, -14, 14),
  1234. 'topic_sk' => array('string', false, 1, 1),
  1235. 'topic_sd' => array('string', false, 1, 1),
  1236. 'post_sk' => array('string', false, 1, 1),
  1237. 'post_sd' => array('string', false, 1, 1),
  1238. ));
  1239. if (!check_form_key($form_name))
  1240. {
  1241. $error[] = 'FORM_INVALID';
  1242. }
  1243. if (!sizeof($error))
  1244. {
  1245. $this->optionset($user_row, 'popuppm', $data['popuppm']);
  1246. $this->optionset($user_row, 'viewimg', $data['view_images']);
  1247. $this->optionset($user_row, 'viewflash', $data['view_flash']);
  1248. $this->optionset($user_row, 'viewsmilies', $data['view_smilies']);
  1249. $this->optionset($user_row, 'viewsigs', $data['view_sigs']);
  1250. $this->optionset($user_row, 'viewavatars', $data['view_avatars']);
  1251. $this->optionset($user_row, 'viewcensors', $data['view_wordcensor']);
  1252. $this->optionset($user_row, 'bbcode', $data['bbcode']);
  1253. $this->optionset($user_row, 'smilies', $data['smilies']);
  1254. $this->optionset($user_row, 'attachsig', $data['sig']);
  1255. $sql_ary = array(
  1256. 'user_options' => $user_row['user_options'],
  1257. 'user_allow_pm' => $data['allowpm'],
  1258. 'user_allow_viewemail' => $data['viewemail'],
  1259. 'user_allow_massemail' => $data['massemail'],
  1260. 'user_allow_viewonline' => !$data['hideonline'],
  1261. 'user_notify_type' => $data['notifymethod'],
  1262. 'user_notify_pm' => $data['notifypm'],
  1263. 'user_dst' => $data['dst'],
  1264. 'user_dateformat' => $data['dateformat'],
  1265. 'user_lang' => $data['lang'],
  1266. 'user_timezone' => $data['tz'],
  1267. 'user_style' => $data['style'],
  1268. 'user_topic_sortby_type' => $data['topic_sk'],
  1269. 'user_post_sortby_type' => $data['post_sk'],
  1270. 'user_topic_sortby_dir' => $data['topic_sd'],
  1271. 'user_post_sortby_dir' => $data['post_sd'],
  1272. 'user_topic_show_days' => $data['topic_st'],
  1273. 'user_post_show_days' => $data['post_st'],
  1274. 'user_notify' => $data['notify'],
  1275. );
  1276. $sql = 'UPDATE ' . USERS_TABLE . '
  1277. SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
  1278. WHERE user_id = $user_id";
  1279. $db->sql_query($sql);
  1280. // Check if user has an active session
  1281. if ($user_row['session_id'])
  1282. {
  1283. // We'll update the session if user_allow_viewonline has changed and the user is a bot
  1284. // Or if it's a regular user and the admin set it to hide the session
  1285. if ($user_row['user_allow_viewonline'] != $sql_ary['user_allow_viewonline'] && $user_row['user_type'] == USER_IGNORE
  1286. || $user_row['user_allow_viewonline'] && !$sql_ary['user_allow_viewonline'])
  1287. {
  1288. // We also need to check if the user has the permission to cloak.
  1289. $user_auth = new auth();
  1290. $user_auth->acl($user_row);
  1291. $session_sql_ary = array(
  1292. 'session_viewonline' => ($user_auth->acl_get('u_hideonline')) ? $sql_ary['user_allow_viewonline'] : true,
  1293. );
  1294. $sql = 'UPDATE ' . SESSIONS_TABLE . '
  1295. SET ' . $db->sql_build_array('UPDATE', $session_sql_ary) . "
  1296. WHERE session_user_id = $user_id";
  1297. $db->sql_query($sql);
  1298. unset($user_auth);
  1299. }
  1300. }
  1301. trigger_error($user->lang['USER_PREFS_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  1302. }
  1303. // Replace "error" strings with their real, localised form
  1304. $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
  1305. }
  1306. $dateformat_options = '';
  1307. foreach ($user->lang['dateformats'] as $format => $null)
  1308. {
  1309. $dateformat_options .= '<option value="' . $format . '"' . (($format == $data['dateformat']) ? ' selected="selected"' : '') . '>';
  1310. $dateformat_options .= $user->format_date(time(), $format, false) . ((strpos($format, '|') !== false) ? $user->lang['VARIANT_DATE_SEPARATOR'] . $user->format_date(time(), $format, true) : '');
  1311. $dateformat_options .= '</option>';
  1312. }
  1313. $s_custom = false;
  1314. $dateformat_options .= '<option value="custom"';
  1315. if (!isset($user->lang['dateformats'][$data['dateformat']]))
  1316. {
  1317. $dateformat_options .= ' selected="selected"';
  1318. $s_custom = true;
  1319. }
  1320. $dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>';
  1321. $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
  1322. // Topic ordering options
  1323. $limit_topic_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
  1324. $sort_by_topic_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']);
  1325. // Post ordering options
  1326. $limit_post_days = array(0 => $user->lang['ALL_POSTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
  1327. $sort_by_post_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
  1328. $_options = array('topic', 'post');
  1329. foreach ($_options as $sort_option)
  1330. {
  1331. ${'s_limit_' . $sort_option . '_days'} = '<select name="' . $sort_option . '_st">';
  1332. foreach (${'limit_' . $sort_option . '_days'} as $day => $text)
  1333. {
  1334. $selected = ($data[$sort_option . '_st'] == $day) ? ' selected="selected"' : '';
  1335. ${'s_limit_' . $sort_option . '_days'} .= '<option value="' . $day . '"' . $selected . '>' . $text . '</option>';
  1336. }
  1337. ${'s_limit_' . $sort_option . '_days'} .= '</select>';
  1338. ${'s_sort_' . $sort_option . '_key'} = '<select name="' . $sort_option . '_sk">';
  1339. foreach (${'sort_by_' . $sort_option . '_text'} as $key => $text)
  1340. {
  1341. $selected = ($data[$sort_option . '_sk'] == $key) ? ' selected="selected"' : '';
  1342. ${'s_sort_' . $sort_option . '_key'} .= '<option value="' . $key . '"' . $selected . '>' . $text . '</option>';
  1343. }
  1344. ${'s_sort_' . $sort_option . '_key'} .= '</select>';
  1345. ${'s_sort_' . $sort_option . '_dir'} = '<select name="' . $sort_option . '_sd">';
  1346. foreach ($sort_dir_text as $key => $value)
  1347. {
  1348. $selected = ($data[$sort_option . '_sd'] == $key) ? ' selected="selected"' : '';
  1349. ${'s_sort_' . $sort_option . '_dir'} .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  1350. }
  1351. ${'s_sort_' . $sort_option . '_dir'} .= '</select>';
  1352. }
  1353. $template->assign_vars(array(
  1354. 'S_PREFS' => true,
  1355. 'S_JABBER_DISABLED' => ($config['jab_enable'] && $user_row['user_jabber'] && @extension_loaded('xml')) ? false : true,
  1356. 'VIEW_EMAIL' => $data['viewemail'],
  1357. 'MASS_EMAIL' => $data['massemail'],
  1358. 'ALLOW_PM' => $data['allowpm'],
  1359. 'HIDE_ONLINE' => $data['hideonline'],
  1360. 'NOTIFY_EMAIL' => ($data['notifymethod'] == NOTIFY_EMAIL) ? true : false,
  1361. 'NOTIFY_IM' => ($data['notifymethod'] == NOTIFY_IM) ? true : false,
  1362. 'NOTIFY_BOTH' => ($data['notifymethod'] == NOTIFY_BOTH) ? true : false,
  1363. 'NOTIFY_PM' => $data['notifypm'],
  1364. 'POPUP_PM' => $data['popuppm'],
  1365. 'DST' => $data['dst'],
  1366. 'BBCODE' => $data['bbcode'],
  1367. 'SMILIES' => $data['smilies'],
  1368. 'ATTACH_SIG' => $data['sig'],
  1369. 'NOTIFY' => $data['notify'],
  1370. 'VIEW_IMAGES' => $data['view_images'],
  1371. 'VIEW_FLASH' => $data['view_flash'],
  1372. 'VIEW_SMILIES' => $data['view_smilies'],
  1373. 'VIEW_SIGS' => $data['view_sigs'],
  1374. 'VIEW_AVATARS' => $data['view_avatars'],
  1375. 'VIEW_WORDCENSOR' => $data['view_wordcensor'],
  1376. 'S_TOPIC_SORT_DAYS' => $s_limit_topic_days,
  1377. 'S_TOPIC_SORT_KEY' => $s_sort_topic_key,
  1378. 'S_TOPIC_SORT_DIR' => $s_sort_topic_dir,
  1379. 'S_POST_SORT_DAYS' => $s_limit_post_days,
  1380. 'S_POST_SORT_KEY' => $s_sort_post_key,
  1381. 'S_POST_SORT_DIR' => $s_sort_post_dir,
  1382. 'DATE_FORMAT' => $data['dateformat'],
  1383. 'S_DATEFORMAT_OPTIONS' => $dateformat_options,
  1384. 'S_CUSTOM_DATEFORMAT' => $s_custom,
  1385. 'DEFAULT_DATEFORMAT' => $config['default_dateformat'],
  1386. 'A_DEFAULT_DATEFORMAT' => addslashes($config['default_dateformat']),
  1387. 'S_LANG_OPTIONS' => language_select($data['lang']),
  1388. 'S_STYLE_OPTIONS' => style_select($data['style']),
  1389. 'S_TZ_OPTIONS' => tz_select($data['tz'], true),
  1390. )
  1391. );
  1392. break;
  1393. case 'avatar':
  1394. include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  1395. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  1396. $can_upload = (file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads) ? true : false;
  1397. if ($submit)
  1398. {
  1399. if (!check_form_key($form_name))
  1400. {
  1401. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  1402. }
  1403. if (avatar_process_user($error, $user_row, $can_upload))
  1404. {
  1405. trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_row['user_id']));
  1406. }
  1407. // Replace "error" strings with their real, localised form
  1408. $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
  1409. }
  1410. if (!$config['allow_avatar'] && $user_row['user_avatar_type'])
  1411. {
  1412. $error[] = $user->lang['USER_AVATAR_NOT_ALLOWED'];
  1413. }
  1414. else if ((($user_row['user_avatar_type'] == AVATAR_UPLOAD) && !$config['allow_avatar_upload']) ||
  1415. (($user_row['user_avatar_type'] == AVATAR_REMOTE) && !$config['allow_avatar_remote']) ||
  1416. (($user_row['user_avatar_type'] == AVATAR_GALLERY) && !$config['allow_avatar_local']))
  1417. {
  1418. $error[] = $user->lang['USER_AVATAR_TYPE_NOT_ALLOWED'];
  1419. }
  1420. // Generate users avatar
  1421. $avatar_img = ($user_row['user_avatar']) ? get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height'], 'USER_AVATAR', true) : '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />';
  1422. $display_gallery = (isset($_POST['display_gallery'])) ? true : false;
  1423. $avatar_select = basename(request_var('avatar_select', ''));
  1424. $category = basename(request_var('category', ''));
  1425. if ($config['allow_avatar_local'] && $display_gallery)
  1426. {
  1427. avatar_gallery($category, $avatar_select, 4);
  1428. }
  1429. $template->assign_vars(array(
  1430. 'S_AVATAR' => true,
  1431. 'S_CAN_UPLOAD' => $can_upload,
  1432. 'S_UPLOAD_FILE' => ($config['allow_avatar'] && $can_upload && $config['allow_avatar_upload']) ? true : false,
  1433. 'S_REMOTE_UPLOAD' => ($config['allow_avatar'] && $can_upload && $config['allow_avatar_remote_upload']) ? true : false,
  1434. 'S_ALLOW_REMOTE' => ($config['allow_avatar'] && $config['allow_avatar_remote']) ? true : false,
  1435. 'S_DISPLAY_GALLERY' => ($config['allow_avatar'] && $config['allow_avatar_local'] && !$display_gallery) ? true : false,
  1436. 'S_IN_GALLERY' => ($config['allow_avatar'] && $config['allow_avatar_local'] && $display_gallery) ? true : false,
  1437. 'AVATAR_IMAGE' => $avatar_img,
  1438. 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'],
  1439. 'USER_AVATAR_WIDTH' => $user_row['user_avatar_width'],
  1440. 'USER_AVATAR_HEIGHT' => $user_row['user_avatar_height'],
  1441. 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024)))
  1442. );
  1443. break;
  1444. case 'rank':
  1445. if ($submit)
  1446. {
  1447. if (!check_form_key($form_name))
  1448. {
  1449. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  1450. }
  1451. $rank_id = request_var('user_rank', 0);
  1452. $sql = 'UPDATE ' . USERS_TABLE . "
  1453. SET user_rank = $rank_id
  1454. WHERE user_id = $user_id";
  1455. $db->sql_query($sql);
  1456. trigger_error($user->lang['USER_RANK_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  1457. }
  1458. $sql = 'SELECT *
  1459. FROM ' . RANKS_TABLE . '
  1460. WHERE rank_special = 1
  1461. ORDER BY rank_title';
  1462. $result = $db->sql_query($sql);
  1463. $s_rank_options = '<option value="0"' . ((!$user_row['user_rank']) ? ' selected="selected"' : '') . '>' . $user->lang['NO_SPECIAL_RANK'] . '</option>';
  1464. while ($row = $db->sql_fetchrow($result))
  1465. {
  1466. $selected = ($user_row['user_rank'] && $row['rank_id'] == $user_row['user_rank']) ? ' selected="selected"' : '';
  1467. $s_rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>';
  1468. }
  1469. $db->sql_freeresult($result);
  1470. $template->assign_vars(array(
  1471. 'S_RANK' => true,
  1472. 'S_RANK_OPTIONS' => $s_rank_options)
  1473. );
  1474. break;
  1475. case 'sig':
  1476. include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
  1477. include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  1478. $enable_bbcode = ($config['allow_sig_bbcode']) ? (bool) $this->optionget($user_row, 'sig_bbcode') : false;
  1479. $enable_smilies = ($config['allow_sig_smilies']) ? (bool) $this->optionget($user_row, 'sig_smilies') : false;
  1480. $enable_urls = ($config['allow_sig_links']) ? (bool) $this->optionget($user_row, 'sig_links') : false;
  1481. $signature = utf8_normalize_nfc(request_var('signature', (string) $user_row['user_sig'], true));
  1482. $preview = (isset($_POST['preview'])) ? true : false;
  1483. if ($submit || $preview)
  1484. {
  1485. include_once($phpbb_root_path . 'includes/message_parser.' . $phpEx);
  1486. $enable_bbcode = ($config['allow_sig_bbcode']) ? ((request_var('disable_bbcode', false)) ? false : true) : false;
  1487. $enable_smilies = ($config['allow_sig_smilies']) ? ((request_var('disable_smilies', false)) ? false : true) : false;
  1488. $enable_urls = ($config['allow_sig_links']) ? ((request_var('disable_magic_url', false)) ? false : true) : false;
  1489. $message_parser = new parse_message($signature);
  1490. // Allowing Quote BBCode
  1491. $message_parser->parse($enable_bbcode, $enable_urls, $enable_smilies, $config['allow_sig_img'], $config['allow_sig_flash'], true, $config['allow_sig_links'], true, 'sig');
  1492. if (sizeof($message_parser->warn_msg))
  1493. {
  1494. $error[] = implode('<br />', $message_parser->warn_msg);
  1495. }
  1496. if (!check_form_key($form_name))
  1497. {
  1498. $error = 'FORM_INVALID';
  1499. }
  1500. if (!sizeof($error) && $submit)
  1501. {
  1502. $this->optionset($user_row, 'sig_bbcode', $enable_bbcode);
  1503. $this->optionset($user_row, 'sig_smilies', $enable_smilies);
  1504. $this->optionset($user_row, 'sig_links', $enable_urls);
  1505. $sql_ary = array(
  1506. 'user_sig' => (string) $message_parser->message,
  1507. 'user_options' => $user_row['user_options'],
  1508. 'user_sig_bbcode_uid' => (string) $message_parser->bbcode_uid,
  1509. 'user_sig_bbcode_bitfield' => (string) $message_parser->bbcode_bitfield
  1510. );
  1511. $sql = 'UPDATE ' . USERS_TABLE . '
  1512. SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
  1513. WHERE user_id = ' . $user_id;
  1514. $db->sql_query($sql);
  1515. trigger_error($user->lang['USER_SIG_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  1516. }
  1517. // Replace "error" strings with their real, localised form
  1518. $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
  1519. }
  1520. $signature_preview = '';
  1521. if ($preview)
  1522. {
  1523. // Now parse it for displaying
  1524. $signature_preview = $message_parser->format_display($enable_bbcode, $enable_urls, $enable_smilies, false);
  1525. unset($message_parser);
  1526. }
  1527. decode_message($signature, $user_row['user_sig_bbcode_uid']);
  1528. $template->assign_vars(array(
  1529. 'S_SIGNATURE' => true,
  1530. 'SIGNATURE' => $signature,
  1531. 'SIGNATURE_PREVIEW' => $signature_preview,
  1532. 'S_BBCODE_CHECKED' => (!$enable_bbcode) ? ' checked="checked"' : '',
  1533. 'S_SMILIES_CHECKED' => (!$enable_smilies) ? ' checked="checked"' : '',
  1534. 'S_MAGIC_URL_CHECKED' => (!$enable_urls) ? ' checked="checked"' : '',
  1535. 'BBCODE_STATUS' => ($config['allow_sig_bbcode']) ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . append_sid("{$phpbb_root_path}faq.$phpEx", 'mode=bbcode') . '">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$phpbb_root_path}faq.$phpEx", 'mode=bbcode') . '">', '</a>'),
  1536. 'SMILIES_STATUS' => ($config['allow_sig_smilies']) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'],
  1537. 'IMG_STATUS' => ($config['allow_sig_img']) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'],
  1538. 'FLASH_STATUS' => ($config['allow_sig_flash']) ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'],
  1539. 'URL_STATUS' => ($config['allow_sig_links']) ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'],
  1540. 'L_SIGNATURE_EXPLAIN' => sprintf($user->lang['SIGNATURE_EXPLAIN'], $config['max_sig_chars']),
  1541. 'S_BBCODE_ALLOWED' => $config['allow_sig_bbcode'],
  1542. 'S_SMILIES_ALLOWED' => $config['allow_sig_smilies'],
  1543. 'S_BBCODE_IMG' => ($config['allow_sig_img']) ? true : false,
  1544. 'S_BBCODE_FLASH' => ($config['allow_sig_flash']) ? true : false,
  1545. 'S_LINKS_ALLOWED' => ($config['allow_sig_links']) ? true : false)
  1546. );
  1547. // Assigning custom bbcodes
  1548. display_custom_bbcodes();
  1549. break;
  1550. case 'attach':
  1551. $start = request_var('start', 0);
  1552. $deletemark = (isset($_POST['delmarked'])) ? true : false;
  1553. $marked = request_var('mark', array(0));
  1554. // Sort keys
  1555. $sort_key = request_var('sk', 'a');
  1556. $sort_dir = request_var('sd', 'd');
  1557. if ($deletemark && sizeof($marked))
  1558. {
  1559. $sql = 'SELECT attach_id
  1560. FROM ' . ATTACHMENTS_TABLE . '
  1561. WHERE poster_id = ' . $user_id . '
  1562. AND is_orphan = 0
  1563. AND ' . $db->sql_in_set('attach_id', $marked);
  1564. $result = $db->sql_query($sql);
  1565. $marked = array();
  1566. while ($row = $db->sql_fetchrow($result))
  1567. {
  1568. $marked[] = $row['attach_id'];
  1569. }
  1570. $db->sql_freeresult($result);
  1571. }
  1572. if ($deletemark && sizeof($marked))
  1573. {
  1574. if (confirm_box(true))
  1575. {
  1576. $sql = 'SELECT real_filename
  1577. FROM ' . ATTACHMENTS_TABLE . '
  1578. WHERE ' . $db->sql_in_set('attach_id', $marked);
  1579. $result = $db->sql_query($sql);
  1580. $log_attachments = array();
  1581. while ($row = $db->sql_fetchrow($result))
  1582. {
  1583. $log_attachments[] = $row['real_filename'];
  1584. }
  1585. $db->sql_freeresult($result);
  1586. delete_attachments('attach', $marked);
  1587. $message = (sizeof($log_attachments) == 1) ? $user->lang['ATTACHMENT_DELETED'] : $user->lang['ATTACHMENTS_DELETED'];
  1588. add_log('admin', 'LOG_ATTACHMENTS_DELETED', implode(', ', $log_attachments));
  1589. trigger_error($message . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  1590. }
  1591. else
  1592. {
  1593. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  1594. 'u' => $user_id,
  1595. 'i' => $id,
  1596. 'mode' => $mode,
  1597. 'action' => $action,
  1598. 'delmarked' => true,
  1599. 'mark' => $marked))
  1600. );
  1601. }
  1602. }
  1603. $sk_text = array('a' => $user->lang['SORT_FILENAME'], 'c' => $user->lang['SORT_EXTENSION'], 'd' => $user->lang['SORT_SIZE'], 'e' => $user->lang['SORT_DOWNLOADS'], 'f' => $user->lang['SORT_POST_TIME'], 'g' => $user->lang['SORT_TOPIC_TITLE']);
  1604. $sk_sql = array('a' => 'a.real_filename', 'c' => 'a.extension', 'd' => 'a.filesize', 'e' => 'a.download_count', 'f' => 'a.filetime', 'g' => 't.topic_title');
  1605. $sd_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
  1606. $s_sort_key = '';
  1607. foreach ($sk_text as $key => $value)
  1608. {
  1609. $selected = ($sort_key == $key) ? ' selected="selected"' : '';
  1610. $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  1611. }
  1612. $s_sort_dir = '';
  1613. foreach ($sd_text as $key => $value)
  1614. {
  1615. $selected = ($sort_dir == $key) ? ' selected="selected"' : '';
  1616. $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  1617. }
  1618. if (!isset($sk_sql[$sort_key]))
  1619. {
  1620. $sort_key = 'a';
  1621. }
  1622. $order_by = $sk_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC');
  1623. $sql = 'SELECT COUNT(attach_id) as num_attachments
  1624. FROM ' . ATTACHMENTS_TABLE . "
  1625. WHERE poster_id = $user_id
  1626. AND is_orphan = 0";
  1627. $result = $db->sql_query_limit($sql, 1);
  1628. $num_attachments = (int) $db->sql_fetchfield('num_attachments');
  1629. $db->sql_freeresult($result);
  1630. $sql = 'SELECT a.*, t.topic_title, p.message_subject as message_title
  1631. FROM ' . ATTACHMENTS_TABLE . ' a
  1632. LEFT JOIN ' . TOPICS_TABLE . ' t ON (a.topic_id = t.topic_id
  1633. AND a.in_message = 0)
  1634. LEFT JOIN ' . PRIVMSGS_TABLE . ' p ON (a.post_msg_id = p.msg_id
  1635. AND a.in_message = 1)
  1636. WHERE a.poster_id = ' . $user_id . "
  1637. AND a.is_orphan = 0
  1638. ORDER BY $order_by";
  1639. $result = $db->sql_query_limit($sql, $config['posts_per_page'], $start);
  1640. while ($row = $db->sql_fetchrow($result))
  1641. {
  1642. if ($row['in_message'])
  1643. {
  1644. $view_topic = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&amp;p={$row['post_msg_id']}");
  1645. }
  1646. else
  1647. {
  1648. $view_topic = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t={$row['topic_id']}&amp;p={$row['post_msg_id']}") . '#p' . $row['post_msg_id'];
  1649. }
  1650. $template->assign_block_vars('attach', array(
  1651. 'REAL_FILENAME' => $row['real_filename'],
  1652. 'COMMENT' => nl2br($row['attach_comment']),
  1653. 'EXTENSION' => $row['extension'],
  1654. 'SIZE' => get_formatted_filesize($row['filesize']),
  1655. 'DOWNLOAD_COUNT' => $row['download_count'],
  1656. 'POST_TIME' => $user->format_date($row['filetime']),
  1657. 'TOPIC_TITLE' => ($row['in_message']) ? $row['message_title'] : $row['topic_title'],
  1658. 'ATTACH_ID' => $row['attach_id'],
  1659. 'POST_ID' => $row['post_msg_id'],
  1660. 'TOPIC_ID' => $row['topic_id'],
  1661. 'S_IN_MESSAGE' => $row['in_message'],
  1662. 'U_DOWNLOAD' => append_sid("{$phpbb_root_path}download/file.$phpEx", 'mode=view&amp;id=' . $row['attach_id']),
  1663. 'U_VIEW_TOPIC' => $view_topic)
  1664. );
  1665. }
  1666. $db->sql_freeresult($result);
  1667. $template->assign_vars(array(
  1668. 'S_ATTACHMENTS' => true,
  1669. 'S_ON_PAGE' => on_page($num_attachments, $config['topics_per_page'], $start),
  1670. 'S_SORT_KEY' => $s_sort_key,
  1671. 'S_SORT_DIR' => $s_sort_dir,
  1672. 'PAGINATION' => generate_pagination($this->u_action . "&amp;u=$user_id&amp;sk=$sort_key&amp;sd=$sort_dir", $num_attachments, $config['topics_per_page'], $start, true))
  1673. );
  1674. break;
  1675. case 'groups':
  1676. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  1677. $user->add_lang(array('groups', 'acp/groups'));
  1678. $group_id = request_var('g', 0);
  1679. if ($group_id)
  1680. {
  1681. // Check the founder only entry for this group to make sure everything is well
  1682. $sql = 'SELECT group_founder_manage
  1683. FROM ' . GROUPS_TABLE . '
  1684. WHERE group_id = ' . $group_id;
  1685. $result = $db->sql_query($sql);
  1686. $founder_manage = (int) $db->sql_fetchfield('group_founder_manage');
  1687. $db->sql_freeresult($result);
  1688. if ($user->data['user_type'] != USER_FOUNDER && $founder_manage)
  1689. {
  1690. trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  1691. }
  1692. }
  1693. else
  1694. {
  1695. $founder_manage = 0;
  1696. }
  1697. switch ($action)
  1698. {
  1699. case 'demote':
  1700. case 'promote':
  1701. case 'default':
  1702. if (!$group_id)
  1703. {
  1704. trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  1705. }
  1706. group_user_attributes($action, $group_id, $user_id);
  1707. if ($action == 'default')
  1708. {
  1709. $user_row['group_id'] = $group_id;
  1710. }
  1711. break;
  1712. case 'delete':
  1713. if (confirm_box(true))
  1714. {
  1715. if (!$group_id)
  1716. {
  1717. trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  1718. }
  1719. if ($error = group_user_del($group_id, $user_id))
  1720. {
  1721. trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  1722. }
  1723. $error = array();
  1724. // The delete action was successful - therefore update the user row...
  1725. $sql = 'SELECT u.*, s.*
  1726. FROM ' . USERS_TABLE . ' u
  1727. LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id)
  1728. WHERE u.user_id = ' . $user_id . '
  1729. ORDER BY s.session_time DESC';
  1730. $result = $db->sql_query_limit($sql, 1);
  1731. $user_row = $db->sql_fetchrow($result);
  1732. $db->sql_freeresult($result);
  1733. }
  1734. else
  1735. {
  1736. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  1737. 'u' => $user_id,
  1738. 'i' => $id,
  1739. 'mode' => $mode,
  1740. 'action' => $action,
  1741. 'g' => $group_id))
  1742. );
  1743. }
  1744. break;
  1745. case 'approve':
  1746. if (confirm_box(true))
  1747. {
  1748. if (!$group_id)
  1749. {
  1750. trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  1751. }
  1752. group_user_attributes($action, $group_id, $user_id);
  1753. }
  1754. else
  1755. {
  1756. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  1757. 'u' => $user_id,
  1758. 'i' => $id,
  1759. 'mode' => $mode,
  1760. 'action' => $action,
  1761. 'g' => $group_id))
  1762. );
  1763. }
  1764. break;
  1765. }
  1766. // Add user to group?
  1767. if ($submit)
  1768. {
  1769. if (!check_form_key($form_name))
  1770. {
  1771. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  1772. }
  1773. if (!$group_id)
  1774. {
  1775. trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  1776. }
  1777. // Add user/s to group
  1778. if ($error = group_user_add($group_id, $user_id))
  1779. {
  1780. trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  1781. }
  1782. $error = array();
  1783. }
  1784. $sql = 'SELECT ug.*, g.*
  1785. FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . " ug
  1786. WHERE ug.user_id = $user_id
  1787. AND g.group_id = ug.group_id
  1788. ORDER BY g.group_type DESC, ug.user_pending ASC, g.group_name";
  1789. $result = $db->sql_query($sql);
  1790. $i = 0;
  1791. $group_data = $id_ary = array();
  1792. while ($row = $db->sql_fetchrow($result))
  1793. {
  1794. $type = ($row['group_type'] == GROUP_SPECIAL) ? 'special' : (($row['user_pending']) ? 'pending' : 'normal');
  1795. $group_data[$type][$i]['group_id'] = $row['group_id'];
  1796. $group_data[$type][$i]['group_name'] = $row['group_name'];
  1797. $group_data[$type][$i]['group_leader'] = ($row['group_leader']) ? 1 : 0;
  1798. $id_ary[] = $row['group_id'];
  1799. $i++;
  1800. }
  1801. $db->sql_freeresult($result);
  1802. // Select box for other groups
  1803. $sql = 'SELECT group_id, group_name, group_type, group_founder_manage
  1804. FROM ' . GROUPS_TABLE . '
  1805. ' . ((sizeof($id_ary)) ? 'WHERE ' . $db->sql_in_set('group_id', $id_ary, true) : '') . '
  1806. ORDER BY group_type DESC, group_name ASC';
  1807. $result = $db->sql_query($sql);
  1808. $s_group_options = '';
  1809. while ($row = $db->sql_fetchrow($result))
  1810. {
  1811. if (!$config['coppa_enable'] && $row['group_name'] == 'REGISTERED_COPPA')
  1812. {
  1813. continue;
  1814. }
  1815. // Do not display those groups not allowed to be managed
  1816. if ($user->data['user_type'] != USER_FOUNDER && $row['group_founder_manage'])
  1817. {
  1818. continue;
  1819. }
  1820. $s_group_options .= '<option' . (($row['group_type'] == GROUP_SPECIAL) ? ' class="sep"' : '') . ' value="' . $row['group_id'] . '">' . (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</option>';
  1821. }
  1822. $db->sql_freeresult($result);
  1823. $current_type = '';
  1824. foreach ($group_data as $group_type => $data_ary)
  1825. {
  1826. if ($current_type != $group_type)
  1827. {
  1828. $template->assign_block_vars('group', array(
  1829. 'S_NEW_GROUP_TYPE' => true,
  1830. 'GROUP_TYPE' => $user->lang['USER_GROUP_' . strtoupper($group_type)])
  1831. );
  1832. }
  1833. foreach ($data_ary as $data)
  1834. {
  1835. $template->assign_block_vars('group', array(
  1836. 'U_EDIT_GROUP' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=groups&amp;mode=manage&amp;action=edit&amp;u=$user_id&amp;g={$data['group_id']}&amp;back_link=acp_users_groups"),
  1837. 'U_DEFAULT' => $this->u_action . "&amp;action=default&amp;u=$user_id&amp;g=" . $data['group_id'],
  1838. 'U_DEMOTE_PROMOTE' => $this->u_action . '&amp;action=' . (($data['group_leader']) ? 'demote' : 'promote') . "&amp;u=$user_id&amp;g=" . $data['group_id'],
  1839. 'U_DELETE' => $this->u_action . "&amp;action=delete&amp;u=$user_id&amp;g=" . $data['group_id'],
  1840. 'U_APPROVE' => ($group_type == 'pending') ? $this->u_action . "&amp;action=approve&amp;u=$user_id&amp;g=" . $data['group_id'] : '',
  1841. 'GROUP_NAME' => ($group_type == 'special') ? $user->lang['G_' . $data['group_name']] : $data['group_name'],
  1842. 'L_DEMOTE_PROMOTE' => ($data['group_leader']) ? $user->lang['GROUP_DEMOTE'] : $user->lang['GROUP_PROMOTE'],
  1843. 'S_IS_MEMBER' => ($group_type != 'pending') ? true : false,
  1844. 'S_NO_DEFAULT' => ($user_row['group_id'] != $data['group_id']) ? true : false,
  1845. 'S_SPECIAL_GROUP' => ($group_type == 'special') ? true : false,
  1846. )
  1847. );
  1848. }
  1849. }
  1850. $template->assign_vars(array(
  1851. 'S_GROUPS' => true,
  1852. 'S_GROUP_OPTIONS' => $s_group_options)
  1853. );
  1854. break;
  1855. case 'perm':
  1856. include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
  1857. $auth_admin = new auth_admin();
  1858. $user->add_lang('acp/permissions');
  1859. add_permission_language();
  1860. $forum_id = request_var('f', 0);
  1861. // Global Permissions
  1862. if (!$forum_id)
  1863. {
  1864. // Select auth options
  1865. $sql = 'SELECT auth_option, is_local, is_global
  1866. FROM ' . ACL_OPTIONS_TABLE . '
  1867. WHERE auth_option ' . $db->sql_like_expression($db->any_char . '_') . '
  1868. AND is_global = 1
  1869. ORDER BY auth_option';
  1870. $result = $db->sql_query($sql);
  1871. $hold_ary = array();
  1872. while ($row = $db->sql_fetchrow($result))
  1873. {
  1874. $hold_ary = $auth_admin->get_mask('view', $user_id, false, false, $row['auth_option'], 'global', ACL_NEVER);
  1875. $auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', false, false);
  1876. }
  1877. $db->sql_freeresult($result);
  1878. unset($hold_ary);
  1879. }
  1880. else
  1881. {
  1882. $sql = 'SELECT auth_option, is_local, is_global
  1883. FROM ' . ACL_OPTIONS_TABLE . "
  1884. WHERE auth_option " . $db->sql_like_expression($db->any_char . '_') . "
  1885. AND is_local = 1
  1886. ORDER BY is_global DESC, auth_option";
  1887. $result = $db->sql_query($sql);
  1888. while ($row = $db->sql_fetchrow($result))
  1889. {
  1890. $hold_ary = $auth_admin->get_mask('view', $user_id, false, $forum_id, $row['auth_option'], 'local', ACL_NEVER);
  1891. $auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', true, false);
  1892. }
  1893. $db->sql_freeresult($result);
  1894. }
  1895. $s_forum_options = '<option value="0"' . ((!$forum_id) ? ' selected="selected"' : '') . '>' . $user->lang['VIEW_GLOBAL_PERMS'] . '</option>';
  1896. $s_forum_options .= make_forum_select($forum_id, false, true, false, false, false);
  1897. $template->assign_vars(array(
  1898. 'S_PERMISSIONS' => true,
  1899. 'S_GLOBAL' => (!$forum_id) ? true : false,
  1900. 'S_FORUM_OPTIONS' => $s_forum_options,
  1901. 'U_ACTION' => $this->u_action . '&amp;u=' . $user_id,
  1902. 'U_USER_PERMISSIONS' => append_sid("{$phpbb_admin_path}index.$phpEx" ,'i=permissions&amp;mode=setting_user_global&amp;user_id[]=' . $user_id),
  1903. 'U_USER_FORUM_PERMISSIONS' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions&amp;mode=setting_user_local&amp;user_id[]=' . $user_id))
  1904. );
  1905. break;
  1906. }
  1907. // Assign general variables
  1908. $template->assign_vars(array(
  1909. 'S_ERROR' => (sizeof($error)) ? true : false,
  1910. 'ERROR_MSG' => (sizeof($error)) ? implode('<br />', $error) : '')
  1911. );
  1912. }
  1913. /**
  1914. * Optionset replacement for this module based on $user->optionset
  1915. */
  1916. function optionset(&$user_row, $key, $value, $data = false)
  1917. {
  1918. global $user;
  1919. $var = ($data) ? $data : $user_row['user_options'];
  1920. if ($value && !($var & 1 << $user->keyoptions[$key]))
  1921. {
  1922. $var += 1 << $user->keyoptions[$key];
  1923. }
  1924. else if (!$value && ($var & 1 << $user->keyoptions[$key]))
  1925. {
  1926. $var -= 1 << $user->keyoptions[$key];
  1927. }
  1928. else
  1929. {
  1930. return ($data) ? $var : false;
  1931. }
  1932. if (!$data)
  1933. {
  1934. $user_row['user_options'] = $var;
  1935. return true;
  1936. }
  1937. else
  1938. {
  1939. return $var;
  1940. }
  1941. }
  1942. /**
  1943. * Optionget replacement for this module based on $user->optionget
  1944. */
  1945. function optionget(&$user_row, $key, $data = false)
  1946. {
  1947. global $user;
  1948. $var = ($data) ? $data : $user_row['user_options'];
  1949. return ($var & 1 << $user->keyoptions[$key]) ? true : false;
  1950. }
  1951. }
  1952. ?>