PageRenderTime 70ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/phpBB/includes/acp/acp_users.php

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

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