PageRenderTime 47ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/phpBB/includes/acp/acp_users.php

https://github.com/Jipem/phpbb
PHP | 2503 lines | 1879 code | 457 blank | 167 comment | 302 complexity | 52a955bb5af3b12ef4925b4c12bdcf74 MD5 | raw file
Possible License(s): AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  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. 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. global $phpbb_dispatcher, $request;
  33. global $phpbb_container;
  34. $user->add_lang(array('posting', 'ucp', 'acp/users'));
  35. $this->tpl_name = 'acp_users';
  36. $error = array();
  37. $username = utf8_normalize_nfc(request_var('username', '', true));
  38. $user_id = request_var('u', 0);
  39. $action = request_var('action', '');
  40. $submit = (isset($_POST['update']) && !isset($_POST['cancel'])) ? true : false;
  41. $form_name = 'acp_users';
  42. add_form_key($form_name);
  43. // Whois (special case)
  44. if ($action == 'whois')
  45. {
  46. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  47. $this->page_title = 'WHOIS';
  48. $this->tpl_name = 'simple_body';
  49. $user_ip = phpbb_ip_normalise(request_var('user_ip', ''));
  50. $domain = gethostbyaddr($user_ip);
  51. $ipwhois = user_ipwhois($user_ip);
  52. $template->assign_vars(array(
  53. 'MESSAGE_TITLE' => sprintf($user->lang['IP_WHOIS_FOR'], $domain),
  54. 'MESSAGE_TEXT' => nl2br($ipwhois))
  55. );
  56. return;
  57. }
  58. // Show user selection mask
  59. if (!$username && !$user_id)
  60. {
  61. $this->page_title = 'SELECT_USER';
  62. $template->assign_vars(array(
  63. 'U_ACTION' => $this->u_action,
  64. 'ANONYMOUS_USER_ID' => ANONYMOUS,
  65. 'S_SELECT_USER' => true,
  66. 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=select_user&amp;field=username&amp;select_single=true'),
  67. ));
  68. return;
  69. }
  70. if (!$user_id)
  71. {
  72. $sql = 'SELECT user_id
  73. FROM ' . USERS_TABLE . "
  74. WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
  75. $result = $db->sql_query($sql);
  76. $user_id = (int) $db->sql_fetchfield('user_id');
  77. $db->sql_freeresult($result);
  78. if (!$user_id)
  79. {
  80. trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING);
  81. }
  82. }
  83. // Generate content for all modes
  84. $sql = 'SELECT u.*, s.*
  85. FROM ' . USERS_TABLE . ' u
  86. LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id)
  87. WHERE u.user_id = ' . $user_id . '
  88. ORDER BY s.session_time DESC';
  89. $result = $db->sql_query_limit($sql, 1);
  90. $user_row = $db->sql_fetchrow($result);
  91. $db->sql_freeresult($result);
  92. if (!$user_row)
  93. {
  94. trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING);
  95. }
  96. // Generate overall "header" for user admin
  97. $s_form_options = '';
  98. // Build modes dropdown list
  99. $sql = 'SELECT module_mode, module_auth
  100. FROM ' . MODULES_TABLE . "
  101. WHERE module_basename = 'acp_users'
  102. AND module_enabled = 1
  103. AND module_class = 'acp'
  104. ORDER BY left_id, module_mode";
  105. $result = $db->sql_query($sql);
  106. $dropdown_modes = array();
  107. while ($row = $db->sql_fetchrow($result))
  108. {
  109. if (!$this->p_master->module_auth_self($row['module_auth']))
  110. {
  111. continue;
  112. }
  113. $dropdown_modes[$row['module_mode']] = true;
  114. }
  115. $db->sql_freeresult($result);
  116. foreach ($dropdown_modes as $module_mode => $null)
  117. {
  118. $selected = ($mode == $module_mode) ? ' selected="selected"' : '';
  119. $s_form_options .= '<option value="' . $module_mode . '"' . $selected . '>' . $user->lang['ACP_USER_' . strtoupper($module_mode)] . '</option>';
  120. }
  121. $template->assign_vars(array(
  122. 'U_BACK' => $this->u_action,
  123. 'U_MODE_SELECT' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&amp;u=$user_id"),
  124. 'U_ACTION' => $this->u_action . '&amp;u=' . $user_id,
  125. 'S_FORM_OPTIONS' => $s_form_options,
  126. 'MANAGED_USERNAME' => $user_row['username'])
  127. );
  128. // Prevent normal users/admins change/view founders if they are not a founder by themselves
  129. if ($user->data['user_type'] != USER_FOUNDER && $user_row['user_type'] == USER_FOUNDER)
  130. {
  131. trigger_error($user->lang['NOT_MANAGE_FOUNDER'] . adm_back_link($this->u_action), E_USER_WARNING);
  132. }
  133. $this->page_title = $user_row['username'] . ' :: ' . $user->lang('ACP_USER_' . strtoupper($mode));
  134. switch ($mode)
  135. {
  136. case 'overview':
  137. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  138. $user->add_lang('acp/ban');
  139. $delete = request_var('delete', 0);
  140. $delete_type = request_var('delete_type', '');
  141. $ip = request_var('ip', 'ip');
  142. if ($submit)
  143. {
  144. if ($delete)
  145. {
  146. if (!$auth->acl_get('a_userdel'))
  147. {
  148. trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  149. }
  150. // Check if the user wants to remove himself or the guest user account
  151. if ($user_id == ANONYMOUS)
  152. {
  153. trigger_error($user->lang['CANNOT_REMOVE_ANONYMOUS'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  154. }
  155. // Founders can not be deleted.
  156. if ($user_row['user_type'] == USER_FOUNDER)
  157. {
  158. trigger_error($user->lang['CANNOT_REMOVE_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  159. }
  160. if ($user_id == $user->data['user_id'])
  161. {
  162. trigger_error($user->lang['CANNOT_REMOVE_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  163. }
  164. if ($delete_type)
  165. {
  166. if (confirm_box(true))
  167. {
  168. user_delete($delete_type, $user_id, $user_row['username']);
  169. add_log('admin', 'LOG_USER_DELETED', $user_row['username']);
  170. trigger_error($user->lang['USER_DELETED'] . adm_back_link($this->u_action));
  171. }
  172. else
  173. {
  174. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  175. 'u' => $user_id,
  176. 'i' => $id,
  177. 'mode' => $mode,
  178. 'action' => $action,
  179. 'update' => true,
  180. 'delete' => 1,
  181. 'delete_type' => $delete_type))
  182. );
  183. }
  184. }
  185. else
  186. {
  187. trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  188. }
  189. }
  190. // Handle quicktool actions
  191. switch ($action)
  192. {
  193. case 'banuser':
  194. case 'banemail':
  195. case 'banip':
  196. if ($user_id == $user->data['user_id'])
  197. {
  198. trigger_error($user->lang['CANNOT_BAN_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  199. }
  200. if ($user_id == ANONYMOUS)
  201. {
  202. trigger_error($user->lang['CANNOT_BAN_ANONYMOUS'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  203. }
  204. if ($user_row['user_type'] == USER_FOUNDER)
  205. {
  206. trigger_error($user->lang['CANNOT_BAN_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  207. }
  208. if (!check_form_key($form_name))
  209. {
  210. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  211. }
  212. $ban = array();
  213. switch ($action)
  214. {
  215. case 'banuser':
  216. $ban[] = $user_row['username'];
  217. $reason = 'USER_ADMIN_BAN_NAME_REASON';
  218. $log = 'LOG_USER_BAN_USER';
  219. break;
  220. case 'banemail':
  221. $ban[] = $user_row['user_email'];
  222. $reason = 'USER_ADMIN_BAN_EMAIL_REASON';
  223. $log = 'LOG_USER_BAN_EMAIL';
  224. break;
  225. case 'banip':
  226. $ban[] = $user_row['user_ip'];
  227. $sql = 'SELECT DISTINCT poster_ip
  228. FROM ' . POSTS_TABLE . "
  229. WHERE poster_id = $user_id";
  230. $result = $db->sql_query($sql);
  231. while ($row = $db->sql_fetchrow($result))
  232. {
  233. $ban[] = $row['poster_ip'];
  234. }
  235. $db->sql_freeresult($result);
  236. $reason = 'USER_ADMIN_BAN_IP_REASON';
  237. $log = 'LOG_USER_BAN_IP';
  238. break;
  239. }
  240. $ban_reason = utf8_normalize_nfc(request_var('ban_reason', $user->lang[$reason], true));
  241. $ban_give_reason = utf8_normalize_nfc(request_var('ban_give_reason', '', true));
  242. // Log not used at the moment, we simply utilize the ban function.
  243. $result = user_ban(substr($action, 3), $ban, 0, 0, 0, $ban_reason, $ban_give_reason);
  244. trigger_error((($result === false) ? $user->lang['BAN_ALREADY_ENTERED'] : $user->lang['BAN_SUCCESSFUL']) . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  245. break;
  246. case 'reactivate':
  247. if ($user_id == $user->data['user_id'])
  248. {
  249. trigger_error($user->lang['CANNOT_FORCE_REACT_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  250. }
  251. if (!check_form_key($form_name))
  252. {
  253. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  254. }
  255. if ($user_row['user_type'] == USER_FOUNDER)
  256. {
  257. trigger_error($user->lang['CANNOT_FORCE_REACT_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  258. }
  259. if ($user_row['user_type'] == USER_IGNORE)
  260. {
  261. trigger_error($user->lang['CANNOT_FORCE_REACT_BOT'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  262. }
  263. if ($config['email_enable'])
  264. {
  265. include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
  266. $server_url = generate_board_url();
  267. $user_actkey = gen_rand_string(mt_rand(6, 10));
  268. $email_template = ($user_row['user_type'] == USER_NORMAL) ? 'user_reactivate_account' : 'user_resend_inactive';
  269. if ($user_row['user_type'] == USER_NORMAL)
  270. {
  271. user_active_flip('deactivate', $user_id, INACTIVE_REMIND);
  272. $sql = 'UPDATE ' . USERS_TABLE . "
  273. SET user_actkey = '" . $db->sql_escape($user_actkey) . "'
  274. WHERE user_id = $user_id";
  275. $db->sql_query($sql);
  276. }
  277. else
  278. {
  279. // Grabbing the last confirm key - we only send a reminder
  280. $sql = 'SELECT user_actkey
  281. FROM ' . USERS_TABLE . '
  282. WHERE user_id = ' . $user_id;
  283. $result = $db->sql_query($sql);
  284. $user_actkey = (string) $db->sql_fetchfield('user_actkey');
  285. $db->sql_freeresult($result);
  286. }
  287. $messenger = new messenger(false);
  288. $messenger->template($email_template, $user_row['user_lang']);
  289. $messenger->set_addresses($user_row);
  290. $messenger->anti_abuse_headers($config, $user);
  291. $messenger->assign_vars(array(
  292. 'WELCOME_MSG' => htmlspecialchars_decode(sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename'])),
  293. 'USERNAME' => htmlspecialchars_decode($user_row['username']),
  294. 'U_ACTIVATE' => "$server_url/ucp.$phpEx?mode=activate&u={$user_row['user_id']}&k=$user_actkey")
  295. );
  296. $messenger->send(NOTIFY_EMAIL);
  297. add_log('admin', 'LOG_USER_REACTIVATE', $user_row['username']);
  298. add_log('user', $user_id, 'LOG_USER_REACTIVATE_USER');
  299. trigger_error($user->lang['FORCE_REACTIVATION_SUCCESS'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  300. }
  301. break;
  302. case 'active':
  303. if ($user_id == $user->data['user_id'])
  304. {
  305. // It is only deactivation since the user is already activated (else he would not have reached this page)
  306. trigger_error($user->lang['CANNOT_DEACTIVATE_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  307. }
  308. if (!check_form_key($form_name))
  309. {
  310. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  311. }
  312. if ($user_row['user_type'] == USER_FOUNDER)
  313. {
  314. trigger_error($user->lang['CANNOT_DEACTIVATE_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  315. }
  316. if ($user_row['user_type'] == USER_IGNORE)
  317. {
  318. trigger_error($user->lang['CANNOT_DEACTIVATE_BOT'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  319. }
  320. user_active_flip('flip', $user_id);
  321. if ($user_row['user_type'] == USER_INACTIVE)
  322. {
  323. if ($config['require_activation'] == USER_ACTIVATION_ADMIN)
  324. {
  325. $phpbb_notifications = $phpbb_container->get('notification_manager');
  326. $phpbb_notifications->delete_notifications('admin_activate_user', $user_row['user_id']);
  327. include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
  328. $messenger = new messenger(false);
  329. $messenger->template('admin_welcome_activated', $user_row['user_lang']);
  330. $messenger->set_addresses($user_row);
  331. $messenger->anti_abuse_headers($config, $user);
  332. $messenger->assign_vars(array(
  333. 'USERNAME' => htmlspecialchars_decode($user_row['username']))
  334. );
  335. $messenger->send(NOTIFY_EMAIL);
  336. }
  337. }
  338. $message = ($user_row['user_type'] == USER_INACTIVE) ? 'USER_ADMIN_ACTIVATED' : 'USER_ADMIN_DEACTIVED';
  339. $log = ($user_row['user_type'] == USER_INACTIVE) ? 'LOG_USER_ACTIVE' : 'LOG_USER_INACTIVE';
  340. add_log('admin', $log, $user_row['username']);
  341. add_log('user', $user_id, $log . '_USER');
  342. trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  343. break;
  344. case 'delsig':
  345. if (!check_form_key($form_name))
  346. {
  347. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  348. }
  349. $sql_ary = array(
  350. 'user_sig' => '',
  351. 'user_sig_bbcode_uid' => '',
  352. 'user_sig_bbcode_bitfield' => ''
  353. );
  354. $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
  355. WHERE user_id = $user_id";
  356. $db->sql_query($sql);
  357. add_log('admin', 'LOG_USER_DEL_SIG', $user_row['username']);
  358. add_log('user', $user_id, 'LOG_USER_DEL_SIG_USER');
  359. trigger_error($user->lang['USER_ADMIN_SIG_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  360. break;
  361. case 'delavatar':
  362. if (!check_form_key($form_name))
  363. {
  364. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  365. }
  366. $sql_ary = array(
  367. 'user_avatar' => '',
  368. 'user_avatar_type' => '',
  369. 'user_avatar_width' => 0,
  370. 'user_avatar_height' => 0,
  371. );
  372. $sql = 'UPDATE ' . USERS_TABLE . '
  373. SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
  374. WHERE user_id = $user_id";
  375. $db->sql_query($sql);
  376. // Delete old avatar if present
  377. $phpbb_avatar_manager = $phpbb_container->get('avatar.manager');
  378. $driver = $phpbb_avatar_manager->get_driver($user_row['user_avatar_type']);
  379. if ($driver)
  380. {
  381. $driver->delete($user_row);
  382. }
  383. add_log('admin', 'LOG_USER_DEL_AVATAR', $user_row['username']);
  384. add_log('user', $user_id, 'LOG_USER_DEL_AVATAR_USER');
  385. trigger_error($user->lang['USER_ADMIN_AVATAR_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  386. break;
  387. case 'delposts':
  388. if (confirm_box(true))
  389. {
  390. // Delete posts, attachments, etc.
  391. delete_posts('poster_id', $user_id);
  392. add_log('admin', 'LOG_USER_DEL_POSTS', $user_row['username']);
  393. trigger_error($user->lang['USER_POSTS_DELETED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  394. }
  395. else
  396. {
  397. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  398. 'u' => $user_id,
  399. 'i' => $id,
  400. 'mode' => $mode,
  401. 'action' => $action,
  402. 'update' => true))
  403. );
  404. }
  405. break;
  406. case 'delattach':
  407. if (confirm_box(true))
  408. {
  409. delete_attachments('user', $user_id);
  410. add_log('admin', 'LOG_USER_DEL_ATTACH', $user_row['username']);
  411. trigger_error($user->lang['USER_ATTACHMENTS_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  412. }
  413. else
  414. {
  415. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  416. 'u' => $user_id,
  417. 'i' => $id,
  418. 'mode' => $mode,
  419. 'action' => $action,
  420. 'update' => true))
  421. );
  422. }
  423. break;
  424. case 'deloutbox':
  425. if (confirm_box(true))
  426. {
  427. $msg_ids = array();
  428. $lang = 'EMPTY';
  429. $sql = 'SELECT msg_id
  430. FROM ' . PRIVMSGS_TO_TABLE . "
  431. WHERE author_id = $user_id
  432. AND folder_id = " . PRIVMSGS_OUTBOX;
  433. $result = $db->sql_query($sql);
  434. if ($row = $db->sql_fetchrow($result))
  435. {
  436. if (!function_exists('delete_pm'))
  437. {
  438. include($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
  439. }
  440. do
  441. {
  442. $msg_ids[] = (int) $row['msg_id'];
  443. }
  444. while ($row = $db->sql_fetchrow($result));
  445. $db->sql_freeresult($result);
  446. delete_pm($user_id, $msg_ids, PRIVMSGS_OUTBOX);
  447. add_log('admin', 'LOG_USER_DEL_OUTBOX', $user_row['username']);
  448. $lang = 'EMPTIED';
  449. }
  450. $db->sql_freeresult($result);
  451. trigger_error($user->lang['USER_OUTBOX_' . $lang] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  452. }
  453. else
  454. {
  455. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  456. 'u' => $user_id,
  457. 'i' => $id,
  458. 'mode' => $mode,
  459. 'action' => $action,
  460. 'update' => true))
  461. );
  462. }
  463. break;
  464. case 'moveposts':
  465. if (!check_form_key($form_name))
  466. {
  467. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  468. }
  469. $user->add_lang('acp/forums');
  470. $new_forum_id = request_var('new_f', 0);
  471. if (!$new_forum_id)
  472. {
  473. $this->page_title = 'USER_ADMIN_MOVE_POSTS';
  474. $template->assign_vars(array(
  475. 'S_SELECT_FORUM' => true,
  476. 'U_ACTION' => $this->u_action . "&amp;action=$action&amp;u=$user_id",
  477. 'U_BACK' => $this->u_action . "&amp;u=$user_id",
  478. 'S_FORUM_OPTIONS' => make_forum_select(false, false, false, true))
  479. );
  480. return;
  481. }
  482. // Is the new forum postable to?
  483. $sql = 'SELECT forum_name, forum_type
  484. FROM ' . FORUMS_TABLE . "
  485. WHERE forum_id = $new_forum_id";
  486. $result = $db->sql_query($sql);
  487. $forum_info = $db->sql_fetchrow($result);
  488. $db->sql_freeresult($result);
  489. if (!$forum_info)
  490. {
  491. trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  492. }
  493. if ($forum_info['forum_type'] != FORUM_POST)
  494. {
  495. trigger_error($user->lang['MOVE_POSTS_NO_POSTABLE_FORUM'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  496. }
  497. // Two stage?
  498. // Move topics comprising only posts from this user
  499. $topic_id_ary = $move_topic_ary = $move_post_ary = $new_topic_id_ary = array();
  500. $forum_id_ary = array($new_forum_id);
  501. $sql = 'SELECT topic_id, post_visibility, COUNT(post_id) AS total_posts
  502. FROM ' . POSTS_TABLE . "
  503. WHERE poster_id = $user_id
  504. AND forum_id <> $new_forum_id
  505. GROUP BY topic_id, post_visibility";
  506. $result = $db->sql_query($sql);
  507. while ($row = $db->sql_fetchrow($result))
  508. {
  509. $topic_id_ary[$row['topic_id']][$row['post_visibility']] = $row['total_posts'];
  510. }
  511. $db->sql_freeresult($result);
  512. if (sizeof($topic_id_ary))
  513. {
  514. $sql = 'SELECT topic_id, forum_id, topic_title, topic_posts_approved, topic_posts_unapproved, topic_posts_softdeleted, topic_attachment
  515. FROM ' . TOPICS_TABLE . '
  516. WHERE ' . $db->sql_in_set('topic_id', array_keys($topic_id_ary));
  517. $result = $db->sql_query($sql);
  518. while ($row = $db->sql_fetchrow($result))
  519. {
  520. if ($topic_id_ary[$row['topic_id']][ITEM_APPROVED] == $row['topic_posts_approved']
  521. && $topic_id_ary[$row['topic_id']][ITEM_UNAPPROVED] == $row['topic_posts_unapproved']
  522. && $topic_id_ary[$row['topic_id']][ITEM_REAPPROVE] == $row['topic_posts_unapproved']
  523. && $topic_id_ary[$row['topic_id']][ITEM_DELETED] == $row['topic_posts_softdeleted'])
  524. {
  525. $move_topic_ary[] = $row['topic_id'];
  526. }
  527. else
  528. {
  529. $move_post_ary[$row['topic_id']]['title'] = $row['topic_title'];
  530. $move_post_ary[$row['topic_id']]['attach'] = ($row['topic_attachment']) ? 1 : 0;
  531. }
  532. $forum_id_ary[] = $row['forum_id'];
  533. }
  534. $db->sql_freeresult($result);
  535. }
  536. // Entire topic comprises posts by this user, move these topics
  537. if (sizeof($move_topic_ary))
  538. {
  539. move_topics($move_topic_ary, $new_forum_id, false);
  540. }
  541. if (sizeof($move_post_ary))
  542. {
  543. // Create new topic
  544. // Update post_ids, report_ids, attachment_ids
  545. foreach ($move_post_ary as $topic_id => $post_ary)
  546. {
  547. // Create new topic
  548. $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
  549. 'topic_poster' => $user_id,
  550. 'topic_time' => time(),
  551. 'forum_id' => $new_forum_id,
  552. 'icon_id' => 0,
  553. 'topic_visibility' => ITEM_APPROVED,
  554. 'topic_title' => $post_ary['title'],
  555. 'topic_first_poster_name' => $user_row['username'],
  556. 'topic_type' => POST_NORMAL,
  557. 'topic_time_limit' => 0,
  558. 'topic_attachment' => $post_ary['attach'])
  559. );
  560. $db->sql_query($sql);
  561. $new_topic_id = $db->sql_nextid();
  562. // Move posts
  563. $sql = 'UPDATE ' . POSTS_TABLE . "
  564. SET forum_id = $new_forum_id, topic_id = $new_topic_id
  565. WHERE topic_id = $topic_id
  566. AND poster_id = $user_id";
  567. $db->sql_query($sql);
  568. if ($post_ary['attach'])
  569. {
  570. $sql = 'UPDATE ' . ATTACHMENTS_TABLE . "
  571. SET topic_id = $new_topic_id
  572. WHERE topic_id = $topic_id
  573. AND poster_id = $user_id";
  574. $db->sql_query($sql);
  575. }
  576. $new_topic_id_ary[] = $new_topic_id;
  577. }
  578. }
  579. $forum_id_ary = array_unique($forum_id_ary);
  580. $topic_id_ary = array_unique(array_merge(array_keys($topic_id_ary), $new_topic_id_ary));
  581. if (sizeof($topic_id_ary))
  582. {
  583. sync('topic_reported', 'topic_id', $topic_id_ary);
  584. sync('topic', 'topic_id', $topic_id_ary);
  585. }
  586. if (sizeof($forum_id_ary))
  587. {
  588. sync('forum', 'forum_id', $forum_id_ary, false, true);
  589. }
  590. add_log('admin', 'LOG_USER_MOVE_POSTS', $user_row['username'], $forum_info['forum_name']);
  591. add_log('user', $user_id, 'LOG_USER_MOVE_POSTS_USER', $forum_info['forum_name']);
  592. trigger_error($user->lang['USER_POSTS_MOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  593. break;
  594. case 'leave_nr':
  595. if (confirm_box(true))
  596. {
  597. remove_newly_registered($user_id, $user_row);
  598. add_log('admin', 'LOG_USER_REMOVED_NR', $user_row['username']);
  599. trigger_error($user->lang['USER_LIFTED_NR'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  600. }
  601. else
  602. {
  603. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  604. 'u' => $user_id,
  605. 'i' => $id,
  606. 'mode' => $mode,
  607. 'action' => $action,
  608. 'update' => true))
  609. );
  610. }
  611. break;
  612. default:
  613. /**
  614. * Run custom quicktool code
  615. *
  616. * @event core.acp_users_overview_run_quicktool
  617. * @var array user_row Current user data
  618. * @var string action Quick tool that should be run
  619. * @since 3.1.0-a1
  620. */
  621. $vars = array('action', 'user_row');
  622. extract($phpbb_dispatcher->trigger_event('core.acp_users_overview_run_quicktool', compact($vars)));
  623. break;
  624. }
  625. // Handle registration info updates
  626. $data = array(
  627. 'username' => utf8_normalize_nfc(request_var('user', $user_row['username'], true)),
  628. 'user_founder' => request_var('user_founder', ($user_row['user_type'] == USER_FOUNDER) ? 1 : 0),
  629. 'email' => strtolower(request_var('user_email', $user_row['user_email'])),
  630. 'new_password' => $request->variable('new_password', '', true),
  631. 'password_confirm' => $request->variable('password_confirm', '', true),
  632. );
  633. // Validation data - we do not check the password complexity setting here
  634. $check_ary = array(
  635. 'new_password' => array(
  636. array('string', true, $config['min_pass_chars'], $config['max_pass_chars']),
  637. array('password')),
  638. 'password_confirm' => array('string', true, $config['min_pass_chars'], $config['max_pass_chars']),
  639. );
  640. // Check username if altered
  641. if ($data['username'] != $user_row['username'])
  642. {
  643. $check_ary += array(
  644. 'username' => array(
  645. array('string', false, $config['min_name_chars'], $config['max_name_chars']),
  646. array('username', $user_row['username'])
  647. ),
  648. );
  649. }
  650. // Check email if altered
  651. if ($data['email'] != $user_row['user_email'])
  652. {
  653. $check_ary += array(
  654. 'email' => array(
  655. array('string', false, 6, 60),
  656. array('user_email', $user_row['user_email']),
  657. ),
  658. );
  659. }
  660. $error = validate_data($data, $check_ary);
  661. if ($data['new_password'] && $data['password_confirm'] != $data['new_password'])
  662. {
  663. $error[] = 'NEW_PASSWORD_ERROR';
  664. }
  665. if (!check_form_key($form_name))
  666. {
  667. $error[] = 'FORM_INVALID';
  668. }
  669. // Instantiate passwords manager
  670. $passwords_manager = $phpbb_container->get('passwords.manager');
  671. // Which updates do we need to do?
  672. $update_username = ($user_row['username'] != $data['username']) ? $data['username'] : false;
  673. $update_password = $data['new_password'] && !$passwords_manager->check($data['new_password'], $user_row['user_password']);
  674. $update_email = ($data['email'] != $user_row['user_email']) ? $data['email'] : false;
  675. if (!sizeof($error))
  676. {
  677. $sql_ary = array();
  678. if ($user_row['user_type'] != USER_FOUNDER || $user->data['user_type'] == USER_FOUNDER)
  679. {
  680. // Only allow founders updating the founder status...
  681. if ($user->data['user_type'] == USER_FOUNDER)
  682. {
  683. // Setting a normal member to be a founder
  684. if ($data['user_founder'] && $user_row['user_type'] != USER_FOUNDER)
  685. {
  686. // Make sure the user is not setting an Inactive or ignored user to be a founder
  687. if ($user_row['user_type'] == USER_IGNORE)
  688. {
  689. trigger_error($user->lang['CANNOT_SET_FOUNDER_IGNORED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  690. }
  691. if ($user_row['user_type'] == USER_INACTIVE)
  692. {
  693. trigger_error($user->lang['CANNOT_SET_FOUNDER_INACTIVE'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  694. }
  695. $sql_ary['user_type'] = USER_FOUNDER;
  696. }
  697. else if (!$data['user_founder'] && $user_row['user_type'] == USER_FOUNDER)
  698. {
  699. // Check if at least one founder is present
  700. $sql = 'SELECT user_id
  701. FROM ' . USERS_TABLE . '
  702. WHERE user_type = ' . USER_FOUNDER . '
  703. AND user_id <> ' . $user_id;
  704. $result = $db->sql_query_limit($sql, 1);
  705. $row = $db->sql_fetchrow($result);
  706. $db->sql_freeresult($result);
  707. if ($row)
  708. {
  709. $sql_ary['user_type'] = USER_NORMAL;
  710. }
  711. else
  712. {
  713. trigger_error($user->lang['AT_LEAST_ONE_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  714. }
  715. }
  716. }
  717. }
  718. /**
  719. * Modify user data before we update it
  720. *
  721. * @event core.acp_users_overview_modify_data
  722. * @var array user_row Current user data
  723. * @var array data Submitted user data
  724. * @var array sql_ary User data we udpate
  725. * @since 3.1.0-a1
  726. */
  727. $vars = array('user_row', 'data', 'sql_ary');
  728. extract($phpbb_dispatcher->trigger_event('core.acp_users_overview_modify_data', compact($vars)));
  729. if ($update_username !== false)
  730. {
  731. $sql_ary['username'] = $update_username;
  732. $sql_ary['username_clean'] = utf8_clean_string($update_username);
  733. add_log('user', $user_id, 'LOG_USER_UPDATE_NAME', $user_row['username'], $update_username);
  734. }
  735. if ($update_email !== false)
  736. {
  737. $sql_ary += array(
  738. 'user_email' => $update_email,
  739. 'user_email_hash' => phpbb_email_hash($update_email),
  740. );
  741. add_log('user', $user_id, 'LOG_USER_UPDATE_EMAIL', $user_row['username'], $user_row['user_email'], $update_email);
  742. }
  743. if ($update_password)
  744. {
  745. $sql_ary += array(
  746. 'user_password' => $passwords_manager->hash($data['new_password']),
  747. 'user_passchg' => time(),
  748. );
  749. $user->reset_login_keys($user_id);
  750. add_log('user', $user_id, 'LOG_USER_NEW_PASSWORD', $user_row['username']);
  751. }
  752. if (sizeof($sql_ary))
  753. {
  754. $sql = 'UPDATE ' . USERS_TABLE . '
  755. SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
  756. WHERE user_id = ' . $user_id;
  757. $db->sql_query($sql);
  758. }
  759. if ($update_username)
  760. {
  761. user_update_name($user_row['username'], $update_username);
  762. }
  763. // Let the users permissions being updated
  764. $auth->acl_clear_prefetch($user_id);
  765. add_log('admin', 'LOG_USER_USER_UPDATE', $data['username']);
  766. trigger_error($user->lang['USER_OVERVIEW_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  767. }
  768. // Replace "error" strings with their real, localised form
  769. $error = array_map(array($user, 'lang'), $error);
  770. }
  771. if ($user_id == $user->data['user_id'])
  772. {
  773. $quick_tool_ary = array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH', 'deloutbox' => 'DEL_OUTBOX');
  774. if ($user_row['user_new'])
  775. {
  776. $quick_tool_ary['leave_nr'] = 'LEAVE_NR';
  777. }
  778. }
  779. else
  780. {
  781. $quick_tool_ary = array();
  782. if ($user_row['user_type'] != USER_FOUNDER)
  783. {
  784. $quick_tool_ary += array('banuser' => 'BAN_USER', 'banemail' => 'BAN_EMAIL', 'banip' => 'BAN_IP');
  785. }
  786. if ($user_row['user_type'] != USER_FOUNDER && $user_row['user_type'] != USER_IGNORE)
  787. {
  788. $quick_tool_ary += array('active' => (($user_row['user_type'] == USER_INACTIVE) ? 'ACTIVATE' : 'DEACTIVATE'));
  789. }
  790. $quick_tool_ary += array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH', 'deloutbox' => 'DEL_OUTBOX');
  791. if ($config['email_enable'] && ($user_row['user_type'] == USER_NORMAL || $user_row['user_type'] == USER_INACTIVE))
  792. {
  793. $quick_tool_ary['reactivate'] = 'FORCE';
  794. }
  795. if ($user_row['user_new'])
  796. {
  797. $quick_tool_ary['leave_nr'] = 'LEAVE_NR';
  798. }
  799. }
  800. if ($config['load_onlinetrack'])
  801. {
  802. $sql = 'SELECT MAX(session_time) AS session_time, MIN(session_viewonline) AS session_viewonline
  803. FROM ' . SESSIONS_TABLE . "
  804. WHERE session_user_id = $user_id";
  805. $result = $db->sql_query($sql);
  806. $row = $db->sql_fetchrow($result);
  807. $db->sql_freeresult($result);
  808. $user_row['session_time'] = (isset($row['session_time'])) ? $row['session_time'] : 0;
  809. $user_row['session_viewonline'] = (isset($row['session_viewonline'])) ? $row['session_viewonline'] : 0;
  810. unset($row);
  811. }
  812. /**
  813. * Add additional quick tool options and overwrite user data
  814. *
  815. * @event core.acp_users_display_overview
  816. * @var array user_row Array with user data
  817. * @var array quick_tool_ary Ouick tool options
  818. * @since 3.1.0-a1
  819. */
  820. $vars = array('user_row', 'quick_tool_ary');
  821. extract($phpbb_dispatcher->trigger_event('core.acp_users_display_overview', compact($vars)));
  822. $s_action_options = '<option class="sep" value="">' . $user->lang['SELECT_OPTION'] . '</option>';
  823. foreach ($quick_tool_ary as $value => $lang)
  824. {
  825. $s_action_options .= '<option value="' . $value . '">' . $user->lang['USER_ADMIN_' . $lang] . '</option>';
  826. }
  827. $last_active = (!empty($user_row['session_time'])) ? $user_row['session_time'] : $user_row['user_lastvisit'];
  828. $inactive_reason = '';
  829. if ($user_row['user_type'] == USER_INACTIVE)
  830. {
  831. $inactive_reason = $user->lang['INACTIVE_REASON_UNKNOWN'];
  832. switch ($user_row['user_inactive_reason'])
  833. {
  834. case INACTIVE_REGISTER:
  835. $inactive_reason = $user->lang['INACTIVE_REASON_REGISTER'];
  836. break;
  837. case INACTIVE_PROFILE:
  838. $inactive_reason = $user->lang['INACTIVE_REASON_PROFILE'];
  839. break;
  840. case INACTIVE_MANUAL:
  841. $inactive_reason = $user->lang['INACTIVE_REASON_MANUAL'];
  842. break;
  843. case INACTIVE_REMIND:
  844. $inactive_reason = $user->lang['INACTIVE_REASON_REMIND'];
  845. break;
  846. }
  847. }
  848. // Posts in Queue
  849. $sql = 'SELECT COUNT(post_id) as posts_in_queue
  850. FROM ' . POSTS_TABLE . '
  851. WHERE poster_id = ' . $user_id . '
  852. AND ' . $db->sql_in_set('post_visibility', array(ITEM_UNAPPROVED, ITEM_REAPPROVE));
  853. $result = $db->sql_query($sql);
  854. $user_row['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue');
  855. $db->sql_freeresult($result);
  856. $sql = 'SELECT post_id
  857. FROM ' . POSTS_TABLE . '
  858. WHERE poster_id = '. $user_id;
  859. $result = $db->sql_query_limit($sql, 1);
  860. $user_row['user_has_posts'] = (bool) $db->sql_fetchfield('post_id');
  861. $db->sql_freeresult($result);
  862. $template->assign_vars(array(
  863. 'L_NAME_CHARS_EXPLAIN' => $user->lang($config['allow_name_chars'] . '_EXPLAIN', $user->lang('CHARACTERS', (int) $config['min_name_chars']), $user->lang('CHARACTERS', (int) $config['max_name_chars'])),
  864. 'L_CHANGE_PASSWORD_EXPLAIN' => $user->lang($config['pass_complex'] . '_EXPLAIN', $user->lang('CHARACTERS', (int) $config['min_pass_chars']), $user->lang('CHARACTERS', (int) $config['max_pass_chars'])),
  865. 'L_POSTS_IN_QUEUE' => $user->lang('NUM_POSTS_IN_QUEUE', $user_row['posts_in_queue']),
  866. 'S_FOUNDER' => ($user->data['user_type'] == USER_FOUNDER) ? true : false,
  867. 'S_OVERVIEW' => true,
  868. 'S_USER_IP' => ($user_row['user_ip']) ? true : false,
  869. 'S_USER_FOUNDER' => ($user_row['user_type'] == USER_FOUNDER) ? true : false,
  870. 'S_ACTION_OPTIONS' => $s_action_options,
  871. 'S_OWN_ACCOUNT' => ($user_id == $user->data['user_id']) ? true : false,
  872. 'S_USER_INACTIVE' => ($user_row['user_type'] == USER_INACTIVE) ? true : false,
  873. 'U_SHOW_IP' => $this->u_action . "&amp;u=$user_id&amp;ip=" . (($ip == 'ip') ? 'hostname' : 'ip'),
  874. 'U_WHOIS' => $this->u_action . "&amp;action=whois&amp;user_ip={$user_row['user_ip']}",
  875. 'U_MCP_QUEUE' => ($auth->acl_getf_global('m_approve')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue', true, $user->session_id) : '',
  876. 'U_SEARCH_USER' => ($config['load_search'] && $auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id={$user_row['user_id']}&amp;sr=posts") : '',
  877. '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')) : '',
  878. 'POSTS_IN_QUEUE' => $user_row['posts_in_queue'],
  879. 'USER' => $user_row['username'],
  880. 'USER_REGISTERED' => $user->format_date($user_row['user_regdate']),
  881. 'REGISTERED_IP' => ($ip == 'hostname') ? gethostbyaddr($user_row['user_ip']) : $user_row['user_ip'],
  882. 'USER_LASTACTIVE' => ($last_active) ? $user->format_date($last_active) : ' - ',
  883. 'USER_EMAIL' => $user_row['user_email'],
  884. 'USER_WARNINGS' => $user_row['user_warnings'],
  885. 'USER_POSTS' => $user_row['user_posts'],
  886. 'USER_HAS_POSTS' => $user_row['user_has_posts'],
  887. 'USER_INACTIVE_REASON' => $inactive_reason,
  888. ));
  889. break;
  890. case 'feedback':
  891. $user->add_lang('mcp');
  892. // Set up general vars
  893. $start = request_var('start', 0);
  894. $deletemark = (isset($_POST['delmarked'])) ? true : false;
  895. $deleteall = (isset($_POST['delall'])) ? true : false;
  896. $marked = request_var('mark', array(0));
  897. $message = utf8_normalize_nfc(request_var('message', '', true));
  898. $pagination = $phpbb_container->get('pagination');
  899. // Sort keys
  900. $sort_days = request_var('st', 0);
  901. $sort_key = request_var('sk', 't');
  902. $sort_dir = request_var('sd', 'd');
  903. // Delete entries if requested and able
  904. if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs'))
  905. {
  906. if (!check_form_key($form_name))
  907. {
  908. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  909. }
  910. $where_sql = '';
  911. if ($deletemark && $marked)
  912. {
  913. $sql_in = array();
  914. foreach ($marked as $mark)
  915. {
  916. $sql_in[] = $mark;
  917. }
  918. $where_sql = ' AND ' . $db->sql_in_set('log_id', $sql_in);
  919. unset($sql_in);
  920. }
  921. if ($where_sql || $deleteall)
  922. {
  923. $sql = 'DELETE FROM ' . LOG_TABLE . '
  924. WHERE log_type = ' . LOG_USERS . "
  925. AND reportee_id = $user_id
  926. $where_sql";
  927. $db->sql_query($sql);
  928. add_log('admin', 'LOG_CLEAR_USER', $user_row['username']);
  929. }
  930. }
  931. if ($submit && $message)
  932. {
  933. if (!check_form_key($form_name))
  934. {
  935. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  936. }
  937. add_log('admin', 'LOG_USER_FEEDBACK', $user_row['username']);
  938. add_log('mod', 0, 0, 'LOG_USER_FEEDBACK', $user_row['username']);
  939. add_log('user', $user_id, 'LOG_USER_GENERAL', $message);
  940. trigger_error($user->lang['USER_FEEDBACK_ADDED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  941. }
  942. // Sorting
  943. $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']);
  944. $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
  945. $sort_by_sql = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
  946. $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
  947. 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);
  948. // Define where and sort sql for use in displaying logs
  949. $sql_where = ($sort_days) ? (time() - ($sort_days * 86400)) : 0;
  950. $sql_sort = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
  951. // Grab log data
  952. $log_data = array();
  953. $log_count = 0;
  954. $start = view_log('user', $log_data, $log_count, $config['topics_per_page'], $start, 0, 0, $user_id, $sql_where, $sql_sort);
  955. $base_url = $this->u_action . "&amp;u=$user_id&amp;$u_sort_param";
  956. $pagination->generate_template_pagination($base_url, 'pagination', 'start', $log_count, $config['topics_per_page'], $start);
  957. $template->assign_vars(array(
  958. 'S_FEEDBACK' => true,
  959. 'S_LIMIT_DAYS' => $s_limit_days,
  960. 'S_SORT_KEY' => $s_sort_key,
  961. 'S_SORT_DIR' => $s_sort_dir,
  962. 'S_CLEARLOGS' => $auth->acl_get('a_clearlogs'))
  963. );
  964. foreach ($log_data as $row)
  965. {
  966. $template->assign_block_vars('log', array(
  967. 'USERNAME' => $row['username_full'],
  968. 'IP' => $row['ip'],
  969. 'DATE' => $user->format_date($row['time']),
  970. 'ACTION' => nl2br($row['action']),
  971. 'ID' => $row['id'])
  972. );
  973. }
  974. break;
  975. case 'warnings':
  976. $user->add_lang('mcp');
  977. // Set up general vars
  978. $start = request_var('start', 0);
  979. $deletemark = (isset($_POST['delmarked'])) ? true : false;
  980. $deleteall = (isset($_POST['delall'])) ? true : false;
  981. $confirm = (isset($_POST['confirm'])) ? true : false;
  982. $marked = request_var('mark', array(0));
  983. $message = utf8_normalize_nfc(request_var('message', '', true));
  984. // Sort keys
  985. $sort_days = request_var('st', 0);
  986. $sort_key = request_var('sk', 't');
  987. $sort_dir = request_var('sd', 'd');
  988. // Delete entries if requested and able
  989. if ($deletemark || $deleteall || $confirm)
  990. {
  991. if (confirm_box(true))
  992. {
  993. $where_sql = '';
  994. $deletemark = request_var('delmarked', 0);
  995. $deleteall = request_var('delall', 0);
  996. if ($deletemark && $marked)
  997. {
  998. $where_sql = ' AND ' . $db->sql_in_set('warning_id', array_values($marked));
  999. }
  1000. if ($where_sql || $deleteall)
  1001. {
  1002. $sql = 'DELETE FROM ' . WARNINGS_TABLE . "
  1003. WHERE user_id = $user_id
  1004. $where_sql";
  1005. $db->sql_query($sql);
  1006. if ($deleteall)
  1007. {
  1008. $log_warnings = $deleted_warnings = 0;
  1009. }
  1010. else
  1011. {
  1012. $num_warnings = (int) $db->sql_affectedrows();
  1013. $deleted_warnings = ' user_warnings - ' . $num_warnings;
  1014. $log_warnings = ($num_warnings > 2) ? 2 : $num_warnings;
  1015. }
  1016. $sql = 'UPDATE ' . USERS_TABLE . "
  1017. SET user_warnings = $deleted_warnings
  1018. WHERE user_id = $user_id";
  1019. $db->sql_query($sql);
  1020. if ($log_warnings)
  1021. {
  1022. add_log('admin', 'LOG_WARNINGS_DELETED', $user_row['username'], $num_warnings);
  1023. }
  1024. else
  1025. {
  1026. add_log('admin', 'LOG_WARNINGS_DELETED_ALL', $user_row['username']);
  1027. }
  1028. }
  1029. }
  1030. else
  1031. {
  1032. $s_hidden_fields = array(
  1033. 'i' => $id,
  1034. 'mode' => $mode,
  1035. 'u' => $user_id,
  1036. 'mark' => $marked,
  1037. );
  1038. if (isset($_POST['delmarked']))
  1039. {
  1040. $s_hidden_fields['delmarked'] = 1;
  1041. }
  1042. if (isset($_POST['delall']))
  1043. {
  1044. $s_hidden_fields['delall'] = 1;
  1045. }
  1046. if (isset($_POST['delall']) || (isset($_POST['delmarked']) && sizeof($marked)))
  1047. {
  1048. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields));
  1049. }
  1050. }
  1051. }
  1052. $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
  1053. FROM ' . WARNINGS_TABLE . ' w
  1054. LEFT JOIN ' . LOG_TABLE . ' l
  1055. ON (w.log_id = l.log_id)
  1056. LEFT JOIN ' . USERS_TABLE . ' m
  1057. ON (l.user_id = m.user_id)
  1058. WHERE w.user_id = ' . $user_id . '
  1059. ORDER BY w.warning_time DESC';
  1060. $result = $db->sql_query($sql);
  1061. while ($row = $db->sql_fetchrow($result))
  1062. {
  1063. if (!$row['log_operation'])
  1064. {
  1065. // We do not have a log-entry anymore, so there is no data available
  1066. $row['action'] = $user->lang['USER_WARNING_LOG_DELETED'];
  1067. }
  1068. else
  1069. {
  1070. $row['action'] = (isset($user->lang[$row['log_operation']])) ? $user->lang[$row['log_operation']] : '{' . ucfirst(str_replace('_', ' ', $row['log_operation'])) . '}';
  1071. if (!empty($row['log_data']))
  1072. {
  1073. $log_data_ary = @unserialize($row['log_data']);
  1074. $log_data_ary = ($log_data_ary === false) ? array() : $log_data_ary;
  1075. if (isset($user->lang[$row['log_operation']]))
  1076. {
  1077. // Check if there are more occurrences of % than arguments, if there are we fill out the arguments array
  1078. // It doesn't matter if we add more arguments than placeholders
  1079. if ((substr_count($row['action'], '%') - sizeof($log_data_ary)) > 0)
  1080. {
  1081. $log_data_ary = array_merge($log_data_ary, array_fill(0, substr_count($row['action'], '%') - sizeof($log_data_ary), ''));
  1082. }
  1083. $row['action'] = vsprintf($row['action'], $log_data_ary);
  1084. $row['action'] = bbcode_nl2br(censor_text($row['action']));
  1085. }
  1086. else if (!empty($log_data_ary))
  1087. {
  1088. $row['action'] .= '<br />' . implode('', $log_data_ary);
  1089. }
  1090. }
  1091. }
  1092. $template->assign_block_vars('warn', array(
  1093. 'ID' => $row['warning_id'],
  1094. 'USERNAME' => ($row['log_operation']) ? get_username_string('full', $row['mod_user_id'], $row['mod_username'], $row['mod_user_colour']) : '-',
  1095. 'ACTION' => make_clickable($row['action']),
  1096. 'DATE' => $user->format_date($row['warning_time']),
  1097. ));
  1098. }
  1099. $db->sql_freeresult($result);
  1100. $template->assign_vars(array(
  1101. 'S_WARNINGS' => true,
  1102. ));
  1103. break;
  1104. case 'profile':
  1105. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  1106. $cp = $phpbb_container->get('profilefields.manager');
  1107. $cp_data = $cp_error = array();
  1108. $sql = 'SELECT lang_id
  1109. FROM ' . LANG_TABLE . "
  1110. WHERE lang_iso = '" . $db->sql_escape($user->data['user_lang']) . "'";
  1111. $result = $db->sql_query($sql);
  1112. $row = $db->sql_fetchrow($result);
  1113. $db->sql_freeresult($result);
  1114. $user_row['iso_lang_id'] = $row['lang_id'];
  1115. $data = array(
  1116. 'jabber' => utf8_normalize_nfc(request_var('jabber', $user_row['user_jabber'], true)),
  1117. 'bday_day' => 0,
  1118. 'bday_month' => 0,
  1119. 'bday_year' => 0,
  1120. );
  1121. if ($user_row['user_birthday'])
  1122. {
  1123. list($data['bday_day'], $data['bday_month'], $data['bday_year']) = explode('-', $user_row['user_birthday']);
  1124. }
  1125. $data['bday_day'] = request_var('bday_day', $data['bday_day']);
  1126. $data['bday_month'] = request_var('bday_month', $data['bday_month']);
  1127. $data['bday_year'] = request_var('bday_year', $data['bday_year']);
  1128. $data['user_birthday'] = sprintf('%2d-%2d-%4d', $data['bday_day'], $data['bday_month'], $data['bday_year']);
  1129. if ($submit)
  1130. {
  1131. $error = validate_data($data, array(
  1132. 'jabber' => array(
  1133. array('string', true, 5, 255),
  1134. array('jabber')),
  1135. 'bday_day' => array('num', true, 1, 31),
  1136. 'bday_month' => array('num', true, 1, 12),
  1137. 'bday_year' => array('num', true, 1901, gmdate('Y', time())),
  1138. 'user_birthday' => array('date', true),
  1139. ));
  1140. // validate custom profile fields
  1141. $cp->submit_cp_field('profile', $user_row['iso_lang_id'], $cp_data, $cp_error);
  1142. if (sizeof($cp_error))
  1143. {
  1144. $error = array_merge($error, $cp_error);
  1145. }
  1146. if (!check_form_key($form_name))
  1147. {
  1148. $error[] = 'FORM_INVALID';
  1149. }
  1150. if (!sizeof($error))
  1151. {
  1152. $sql_ary = array(
  1153. 'user_jabber' => $data['jabber'],
  1154. 'user_birthday' => $data['user_birthday'],
  1155. );
  1156. $sql = 'UPDATE ' . USERS_TABLE . '
  1157. SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
  1158. WHERE user_id = $user_id";
  1159. $db->sql_query($sql);
  1160. // Update Custom Fields
  1161. $cp->update_profile_field_data($user_id, $cp_data);
  1162. trigger_error($user->lang['USER_PROFILE_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  1163. }
  1164. // Replace "error" strings with their real, localised form
  1165. $error = array_map(array($user, 'lang'), $error);
  1166. }
  1167. $s_birthday_day_options = '<option value="0"' . ((!$data['bday_day']) ? ' selected="selected"' : '') . '>--</option>';
  1168. for ($i = 1; $i < 32; $i++)
  1169. {
  1170. $selected = ($i == $data['bday_day']) ? ' selected="selected"' : '';
  1171. $s_birthday_day_options .= "<option value=\"$i\"$selected>$i</option>";
  1172. }
  1173. $s_birthday_month_options = '<option value="0"' . ((!$data['bday_month']) ? ' selected="selected"' : '') . '>--</option>';
  1174. for ($i = 1; $i < 13; $i++)
  1175. {
  1176. $selected = ($i == $data['bday_month']) ? ' selected="selected"' : '';
  1177. $s_birthday_month_options .= "<option value=\"$i\"$selected>$i</option>";
  1178. }
  1179. $s_birthday_year_options = '';
  1180. $now = getdate();
  1181. $s_birthday_year_options = '<option value="0"' . ((!$data['bday_year']) ? ' selected="selected"' : '') . '>--</option>';
  1182. for ($i = $now['year'] - 100; $i <= $now['year']; $i++)
  1183. {
  1184. $selected = ($i == $data['bday_year']) ? ' selected="selected"' : '';
  1185. $s_birthday_year_options .= "<option value=\"$i\"$selected>$i</option>";
  1186. }
  1187. unset($now);
  1188. $template->assign_vars(array(
  1189. 'JABBER' => $data['jabber'],
  1190. 'S_BIRTHDAY_DAY_OPTIONS' => $s_birthday_day_options,
  1191. 'S_BIRTHDAY_MONTH_OPTIONS' => $s_birthday_month_options,
  1192. 'S_BIRTHDAY_YEAR_OPTIONS' => $s_birthday_year_options,
  1193. 'S_PROFILE' => true)
  1194. );
  1195. // Get additional profile fields and assign them to the template block var 'profile_fields'
  1196. $user->get_profile_fields($user_id);
  1197. $cp->generate_profile_fields('profile', $user_row['iso_lang_id']);
  1198. break;
  1199. case 'prefs':
  1200. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  1201. $data = array(
  1202. 'dateformat' => utf8_normalize_nfc(request_var('dateformat', $user_row['user_dateformat'], true)),
  1203. 'lang' => basename(request_var('lang', $user_row['user_lang'])),
  1204. 'tz' => request_var('tz', $user_row['user_timezone']),
  1205. 'style' => request

Large files files are truncated, but you can click here to view the full file