PageRenderTime 50ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/forum/includes/acp/acp_users.php

https://bitbucket.org/itoxable/chiron-gaming
PHP | 2392 lines | 1859 code | 440 blank | 93 comment | 318 complexity | bd0d21dc4f16bb5a5b4e38a292dcb591 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0

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

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