PageRenderTime 66ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/forum/includes/acp/acp_users.php

https://github.com/GreyTeardrop/socionicasys-forum
PHP | 2421 lines | 1872 code | 441 blank | 108 comment | 319 complexity | d5feda09cf819783a4077b564e72b513 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-3.0, MPL-2.0-no-copyleft-exception

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. //-- mod: Prime Trash Bin (Posts) -------------------------------------------//
  387. // Intercept the post deletion (deleting all posts by a specific user).
  388. include($phpbb_root_path . 'includes/prime_trash_bin_b.' . $phpEx);
  389. stifle_users_posts($user_id, $user_row['username'], adm_back_link($this->u_action . '&amp;u=' . $user_id));
  390. //-- end: Prime Trash Bin (Posts) -------------------------------------------//
  391. // Delete posts, attachments, etc.
  392. delete_posts('poster_id', $user_id);
  393. add_log('admin', 'LOG_USER_DEL_POSTS', $user_row['username']);
  394. trigger_error($user->lang['USER_POSTS_DELETED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  395. }
  396. else
  397. {
  398. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  399. //-- mod: Prime Trash Bin (Posts) -------------------------------------------//
  400. // Pass on our variables through the confirmation page.
  401. 'delete_reason' => request_var('delete_reason', '', true),
  402. 'delete_forever' => request_var('delete_forever', false),
  403. //-- end: Prime Trash Bin (Posts) -------------------------------------------//
  404. 'u' => $user_id,
  405. 'i' => $id,
  406. 'mode' => $mode,
  407. 'action' => $action,
  408. 'update' => true))
  409. );
  410. }
  411. break;
  412. case 'delattach':
  413. if (confirm_box(true))
  414. {
  415. delete_attachments('user', $user_id);
  416. add_log('admin', 'LOG_USER_DEL_ATTACH', $user_row['username']);
  417. trigger_error($user->lang['USER_ATTACHMENTS_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  418. }
  419. else
  420. {
  421. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  422. 'u' => $user_id,
  423. 'i' => $id,
  424. 'mode' => $mode,
  425. 'action' => $action,
  426. 'update' => true))
  427. );
  428. }
  429. break;
  430. case 'deloutbox':
  431. if (confirm_box(true))
  432. {
  433. $msg_ids = array();
  434. $lang = 'EMPTY';
  435. $sql = 'SELECT msg_id
  436. FROM ' . PRIVMSGS_TO_TABLE . "
  437. WHERE author_id = $user_id
  438. AND folder_id = " . PRIVMSGS_OUTBOX;
  439. $result = $db->sql_query($sql);
  440. if ($row = $db->sql_fetchrow($result))
  441. {
  442. if (!function_exists('delete_pm'))
  443. {
  444. include($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
  445. }
  446. do
  447. {
  448. $msg_ids[] = (int) $row['msg_id'];
  449. }
  450. while ($row = $db->sql_fetchrow($result));
  451. $db->sql_freeresult($result);
  452. delete_pm($user_id, $msg_ids, PRIVMSGS_OUTBOX);
  453. add_log('admin', 'LOG_USER_DEL_OUTBOX', $user_row['username']);
  454. $lang = 'EMPTIED';
  455. }
  456. $db->sql_freeresult($result);
  457. trigger_error($user->lang['USER_OUTBOX_' . $lang] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  458. }
  459. else
  460. {
  461. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  462. 'u' => $user_id,
  463. 'i' => $id,
  464. 'mode' => $mode,
  465. 'action' => $action,
  466. 'update' => true))
  467. );
  468. }
  469. break;
  470. case 'moveposts':
  471. if (!check_form_key($form_name))
  472. {
  473. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  474. }
  475. $user->add_lang('acp/forums');
  476. $new_forum_id = request_var('new_f', 0);
  477. if (!$new_forum_id)
  478. {
  479. $this->page_title = 'USER_ADMIN_MOVE_POSTS';
  480. $template->assign_vars(array(
  481. 'S_SELECT_FORUM' => true,
  482. 'U_ACTION' => $this->u_action . "&amp;action=$action&amp;u=$user_id",
  483. 'U_BACK' => $this->u_action . "&amp;u=$user_id",
  484. 'S_FORUM_OPTIONS' => make_forum_select(false, false, false, true))
  485. );
  486. return;
  487. }
  488. // Is the new forum postable to?
  489. $sql = 'SELECT forum_name, forum_type
  490. FROM ' . FORUMS_TABLE . "
  491. WHERE forum_id = $new_forum_id";
  492. $result = $db->sql_query($sql);
  493. $forum_info = $db->sql_fetchrow($result);
  494. $db->sql_freeresult($result);
  495. if (!$forum_info)
  496. {
  497. trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  498. }
  499. if ($forum_info['forum_type'] != FORUM_POST)
  500. {
  501. trigger_error($user->lang['MOVE_POSTS_NO_POSTABLE_FORUM'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  502. }
  503. // Two stage?
  504. // Move topics comprising only posts from this user
  505. $topic_id_ary = $move_topic_ary = $move_post_ary = $new_topic_id_ary = array();
  506. $forum_id_ary = array($new_forum_id);
  507. $sql = 'SELECT topic_id, COUNT(post_id) AS total_posts
  508. FROM ' . POSTS_TABLE . "
  509. WHERE poster_id = $user_id
  510. AND forum_id <> $new_forum_id
  511. GROUP BY topic_id";
  512. $result = $db->sql_query($sql);
  513. while ($row = $db->sql_fetchrow($result))
  514. {
  515. $topic_id_ary[$row['topic_id']] = $row['total_posts'];
  516. }
  517. $db->sql_freeresult($result);
  518. if (sizeof($topic_id_ary))
  519. {
  520. $sql = 'SELECT topic_id, forum_id, topic_title, topic_replies, topic_replies_real, topic_attachment
  521. FROM ' . TOPICS_TABLE . '
  522. WHERE ' . $db->sql_in_set('topic_id', array_keys($topic_id_ary));
  523. $result = $db->sql_query($sql);
  524. while ($row = $db->sql_fetchrow($result))
  525. {
  526. if (max($row['topic_replies'], $row['topic_replies_real']) + 1 == $topic_id_ary[$row['topic_id']])
  527. {
  528. $move_topic_ary[] = $row['topic_id'];
  529. }
  530. else
  531. {
  532. $move_post_ary[$row['topic_id']]['title'] = $row['topic_title'];
  533. $move_post_ary[$row['topic_id']]['attach'] = ($row['topic_attachment']) ? 1 : 0;
  534. }
  535. $forum_id_ary[] = $row['forum_id'];
  536. }
  537. $db->sql_freeresult($result);
  538. }
  539. // Entire topic comprises posts by this user, move these topics
  540. if (sizeof($move_topic_ary))
  541. {
  542. move_topics($move_topic_ary, $new_forum_id, false);
  543. }
  544. if (sizeof($move_post_ary))
  545. {
  546. // Create new topic
  547. // Update post_ids, report_ids, attachment_ids
  548. foreach ($move_post_ary as $topic_id => $post_ary)
  549. {
  550. // Create new topic
  551. $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
  552. 'topic_poster' => $user_id,
  553. 'topic_time' => time(),
  554. 'forum_id' => $new_forum_id,
  555. 'icon_id' => 0,
  556. 'topic_approved' => 1,
  557. 'topic_title' => $post_ary['title'],
  558. 'topic_first_poster_name' => $user_row['username'],
  559. 'topic_type' => POST_NORMAL,
  560. 'topic_time_limit' => 0,
  561. 'topic_attachment' => $post_ary['attach'])
  562. );
  563. $db->sql_query($sql);
  564. $new_topic_id = $db->sql_nextid();
  565. // Move posts
  566. $sql = 'UPDATE ' . POSTS_TABLE . "
  567. SET forum_id = $new_forum_id, topic_id = $new_topic_id
  568. WHERE topic_id = $topic_id
  569. AND poster_id = $user_id";
  570. $db->sql_query($sql);
  571. if ($post_ary['attach'])
  572. {
  573. $sql = 'UPDATE ' . ATTACHMENTS_TABLE . "
  574. SET topic_id = $new_topic_id
  575. WHERE topic_id = $topic_id
  576. AND poster_id = $user_id";
  577. $db->sql_query($sql);
  578. }
  579. $new_topic_id_ary[] = $new_topic_id;
  580. }
  581. }
  582. $forum_id_ary = array_unique($forum_id_ary);
  583. $topic_id_ary = array_unique(array_merge(array_keys($topic_id_ary), $new_topic_id_ary));
  584. if (sizeof($topic_id_ary))
  585. {
  586. sync('topic_reported', 'topic_id', $topic_id_ary);
  587. sync('topic', 'topic_id', $topic_id_ary);
  588. }
  589. if (sizeof($forum_id_ary))
  590. {
  591. sync('forum', 'forum_id', $forum_id_ary, false, true);
  592. }
  593. add_log('admin', 'LOG_USER_MOVE_POSTS', $user_row['username'], $forum_info['forum_name']);
  594. add_log('user', $user_id, 'LOG_USER_MOVE_POSTS_USER', $forum_info['forum_name']);
  595. trigger_error($user->lang['USER_POSTS_MOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  596. break;
  597. case 'leave_nr':
  598. if (confirm_box(true))
  599. {
  600. remove_newly_registered($user_id, $user_row);
  601. add_log('admin', 'LOG_USER_REMOVED_NR', $user_row['username']);
  602. trigger_error($user->lang['USER_LIFTED_NR'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  603. }
  604. else
  605. {
  606. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  607. 'u' => $user_id,
  608. 'i' => $id,
  609. 'mode' => $mode,
  610. 'action' => $action,
  611. 'update' => true))
  612. );
  613. }
  614. break;
  615. }
  616. // Handle registration info updates
  617. $data = array(
  618. 'username' => utf8_normalize_nfc(request_var('user', $user_row['username'], true)),
  619. 'user_founder' => request_var('user_founder', ($user_row['user_type'] == USER_FOUNDER) ? 1 : 0),
  620. 'email' => strtolower(request_var('user_email', $user_row['user_email'])),
  621. 'email_confirm' => strtolower(request_var('email_confirm', '')),
  622. 'new_password' => request_var('new_password', '', true),
  623. 'password_confirm' => request_var('password_confirm', '', true),
  624. );
  625. // Validation data - we do not check the password complexity setting here
  626. $check_ary = array(
  627. 'new_password' => array(
  628. array('string', true, $config['min_pass_chars'], $config['max_pass_chars']),
  629. array('password')),
  630. 'password_confirm' => array('string', true, $config['min_pass_chars'], $config['max_pass_chars']),
  631. );
  632. // Check username if altered
  633. if ($data['username'] != $user_row['username'])
  634. {
  635. $check_ary += array(
  636. 'username' => array(
  637. array('string', false, $config['min_name_chars'], $config['max_name_chars']),
  638. array('username', $user_row['username'])
  639. ),
  640. );
  641. }
  642. // Check email if altered
  643. if ($data['email'] != $user_row['user_email'])
  644. {
  645. $check_ary += array(
  646. 'email' => array(
  647. array('string', false, 6, 60),
  648. array('email', $user_row['user_email'])
  649. ),
  650. 'email_confirm' => array('string', true, 6, 60)
  651. );
  652. }
  653. $error = validate_data($data, $check_ary);
  654. if ($data['new_password'] && $data['password_confirm'] != $data['new_password'])
  655. {
  656. $error[] = 'NEW_PASSWORD_ERROR';
  657. }
  658. if ($data['email'] != $user_row['user_email'] && $data['email_confirm'] != $data['email'])
  659. {
  660. $error[] = 'NEW_EMAIL_ERROR';
  661. }
  662. if (!check_form_key($form_name))
  663. {
  664. $error[] = 'FORM_INVALID';
  665. }
  666. // Which updates do we need to do?
  667. $update_username = ($user_row['username'] != $data['username']) ? $data['username'] : false;
  668. $update_password = ($data['new_password'] && !phpbb_check_hash($user_row['user_password'], $data['new_password'])) ? true : false;
  669. $update_email = ($data['email'] != $user_row['user_email']) ? $data['email'] : false;
  670. if (!sizeof($error))
  671. {
  672. $sql_ary = array();
  673. if ($user_row['user_type'] != USER_FOUNDER || $user->data['user_type'] == USER_FOUNDER)
  674. {
  675. // Only allow founders updating the founder status...
  676. if ($user->data['user_type'] == USER_FOUNDER)
  677. {
  678. // Setting a normal member to be a founder
  679. if ($data['user_founder'] && $user_row['user_type'] != USER_FOUNDER)
  680. {
  681. // Make sure the user is not setting an Inactive or ignored user to be a founder
  682. if ($user_row['user_type'] == USER_IGNORE)
  683. {
  684. trigger_error($user->lang['CANNOT_SET_FOUNDER_IGNORED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  685. }
  686. if ($user_row['user_type'] == USER_INACTIVE)
  687. {
  688. trigger_error($user->lang['CANNOT_SET_FOUNDER_INACTIVE'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  689. }
  690. $sql_ary['user_type'] = USER_FOUNDER;
  691. }
  692. else if (!$data['user_founder'] && $user_row['user_type'] == USER_FOUNDER)
  693. {
  694. // Check if at least one founder is present
  695. $sql = 'SELECT user_id
  696. FROM ' . USERS_TABLE . '
  697. WHERE user_type = ' . USER_FOUNDER . '
  698. AND user_id <> ' . $user_id;
  699. $result = $db->sql_query_limit($sql, 1);
  700. $row = $db->sql_fetchrow($result);
  701. $db->sql_freeresult($result);
  702. if ($row)
  703. {
  704. $sql_ary['user_type'] = USER_NORMAL;
  705. }
  706. else
  707. {
  708. trigger_error($user->lang['AT_LEAST_ONE_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  709. }
  710. }
  711. }
  712. }
  713. if ($update_username !== false)
  714. {
  715. $sql_ary['username'] = $update_username;
  716. $sql_ary['username_clean'] = utf8_clean_string($update_username);
  717. add_log('user', $user_id, 'LOG_USER_UPDATE_NAME', $user_row['username'], $update_username);
  718. }
  719. if ($update_email !== false)
  720. {
  721. $sql_ary += array(
  722. 'user_email' => $update_email,
  723. 'user_email_hash' => phpbb_email_hash($update_email),
  724. );
  725. add_log('user', $user_id, 'LOG_USER_UPDATE_EMAIL', $user_row['username'], $user_row['user_email'], $update_email);
  726. }
  727. if ($update_password)
  728. {
  729. $sql_ary += array(
  730. 'user_password' => phpbb_hash($data['new_password']),
  731. 'user_passchg' => time(),
  732. 'user_pass_convert' => 0,
  733. );
  734. $user->reset_login_keys($user_id);
  735. add_log('user', $user_id, 'LOG_USER_NEW_PASSWORD', $user_row['username']);
  736. }
  737. if (sizeof($sql_ary))
  738. {
  739. $sql = 'UPDATE ' . USERS_TABLE . '
  740. SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
  741. WHERE user_id = ' . $user_id;
  742. $db->sql_query($sql);
  743. }
  744. if ($update_username)
  745. {
  746. user_update_name($user_row['username'], $update_username);
  747. }
  748. // Let the users permissions being updated
  749. $auth->acl_clear_prefetch($user_id);
  750. add_log('admin', 'LOG_USER_USER_UPDATE', $data['username']);
  751. trigger_error($user->lang['USER_OVERVIEW_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  752. }
  753. // Replace "error" strings with their real, localised form
  754. $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
  755. }
  756. if ($user_id == $user->data['user_id'])
  757. {
  758. $quick_tool_ary = array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH', 'deloutbox' => 'DEL_OUTBOX');
  759. if ($user_row['user_new'])
  760. {
  761. $quick_tool_ary['leave_nr'] = 'LEAVE_NR';
  762. }
  763. }
  764. else
  765. {
  766. $quick_tool_ary = array();
  767. if ($user_row['user_type'] != USER_FOUNDER)
  768. {
  769. $quick_tool_ary += array('banuser' => 'BAN_USER', 'banemail' => 'BAN_EMAIL', 'banip' => 'BAN_IP');
  770. }
  771. if ($user_row['user_type'] != USER_FOUNDER && $user_row['user_type'] != USER_IGNORE)
  772. {
  773. $quick_tool_ary += array('active' => (($user_row['user_type'] == USER_INACTIVE) ? 'ACTIVATE' : 'DEACTIVATE'));
  774. }
  775. $quick_tool_ary += array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH', 'deloutbox' => 'DEL_OUTBOX');
  776. if ($config['email_enable'] && ($user_row['user_type'] == USER_NORMAL || $user_row['user_type'] == USER_INACTIVE))
  777. {
  778. $quick_tool_ary['reactivate'] = 'FORCE';
  779. }
  780. if ($user_row['user_new'])
  781. {
  782. $quick_tool_ary['leave_nr'] = 'LEAVE_NR';
  783. }
  784. }
  785. $s_action_options = '<option class="sep" value="">' . $user->lang['SELECT_OPTION'] . '</option>';
  786. foreach ($quick_tool_ary as $value => $lang)
  787. {
  788. $s_action_options .= '<option value="' . $value . '">' . $user->lang['USER_ADMIN_' . $lang] . '</option>';
  789. }
  790. if ($config['load_onlinetrack'])
  791. {
  792. $sql = 'SELECT MAX(session_time) AS session_time, MIN(session_viewonline) AS session_viewonline
  793. FROM ' . SESSIONS_TABLE . "
  794. WHERE session_user_id = $user_id";
  795. $result = $db->sql_query($sql);
  796. $row = $db->sql_fetchrow($result);
  797. $db->sql_freeresult($result);
  798. $user_row['session_time'] = (isset($row['session_time'])) ? $row['session_time'] : 0;
  799. $user_row['session_viewonline'] = (isset($row['session_viewonline'])) ? $row['session_viewonline'] : 0;
  800. unset($row);
  801. }
  802. $last_visit = (!empty($user_row['session_time'])) ? $user_row['session_time'] : $user_row['user_lastvisit'];
  803. $inactive_reason = '';
  804. if ($user_row['user_type'] == USER_INACTIVE)
  805. {
  806. $inactive_reason = $user->lang['INACTIVE_REASON_UNKNOWN'];
  807. switch ($user_row['user_inactive_reason'])
  808. {
  809. case INACTIVE_REGISTER:
  810. $inactive_reason = $user->lang['INACTIVE_REASON_REGISTER'];
  811. break;
  812. case INACTIVE_PROFILE:
  813. $inactive_reason = $user->lang['INACTIVE_REASON_PROFILE'];
  814. break;
  815. case INACTIVE_MANUAL:
  816. $inactive_reason = $user->lang['INACTIVE_REASON_MANUAL'];
  817. break;
  818. case INACTIVE_REMIND:
  819. $inactive_reason = $user->lang['INACTIVE_REASON_REMIND'];
  820. break;
  821. }
  822. }
  823. // Posts in Queue
  824. $sql = 'SELECT COUNT(post_id) as posts_in_queue
  825. FROM ' . POSTS_TABLE . '
  826. WHERE poster_id = ' . $user_id . '
  827. AND post_approved = 0';
  828. $result = $db->sql_query($sql);
  829. $user_row['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue');
  830. $db->sql_freeresult($result);
  831. $template->assign_vars(array(
  832. 'L_NAME_CHARS_EXPLAIN' => sprintf($user->lang[$config['allow_name_chars'] . '_EXPLAIN'], $config['min_name_chars'], $config['max_name_chars']),
  833. 'L_CHANGE_PASSWORD_EXPLAIN' => sprintf($user->lang[$config['pass_complex'] . '_EXPLAIN'], $config['min_pass_chars'], $config['max_pass_chars']),
  834. 'L_POSTS_IN_QUEUE' => $user->lang('NUM_POSTS_IN_QUEUE', $user_row['posts_in_queue']),
  835. 'S_FOUNDER' => ($user->data['user_type'] == USER_FOUNDER) ? true : false,
  836. 'S_OVERVIEW' => true,
  837. 'S_USER_IP' => ($user_row['user_ip']) ? true : false,
  838. 'S_USER_FOUNDER' => ($user_row['user_type'] == USER_FOUNDER) ? true : false,
  839. 'S_ACTION_OPTIONS' => $s_action_options,
  840. 'S_OWN_ACCOUNT' => ($user_id == $user->data['user_id']) ? true : false,
  841. 'S_USER_INACTIVE' => ($user_row['user_type'] == USER_INACTIVE) ? true : false,
  842. 'U_SHOW_IP' => $this->u_action . "&amp;u=$user_id&amp;ip=" . (($ip == 'ip') ? 'hostname' : 'ip'),
  843. 'U_WHOIS' => $this->u_action . "&amp;action=whois&amp;user_ip={$user_row['user_ip']}",
  844. 'U_MCP_QUEUE' => ($auth->acl_getf_global('m_approve')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue', true, $user->session_id) : '',
  845. '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')) : '',
  846. 'POSTS_IN_QUEUE' => $user_row['posts_in_queue'],
  847. 'USER' => $user_row['username'],
  848. 'USER_REGISTERED' => $user->format_date($user_row['user_regdate']),
  849. 'REGISTERED_IP' => ($ip == 'hostname') ? gethostbyaddr($user_row['user_ip']) : $user_row['user_ip'],
  850. 'USER_LASTACTIVE' => ($last_visit) ? $user->format_date($last_visit) : ' - ',
  851. 'USER_EMAIL' => $user_row['user_email'],
  852. 'USER_WARNINGS' => $user_row['user_warnings'],
  853. 'USER_POSTS' => $user_row['user_posts'],
  854. 'USER_INACTIVE_REASON' => $inactive_reason,
  855. ));
  856. //-- mod: Prime Trash Bin (Posts) -------------------------------------------//
  857. // Add a flag to the template so our Permanent Delete option will appear.
  858. include($phpbb_root_path . 'includes/prime_trash_bin_b.' . $phpEx);
  859. if (stifle_posts_enabled())
  860. {
  861. $user->add_lang('mods/prime_trash_bin_a');
  862. $template->assign_var('S_CAN_DELETE_FOREVER', auth_fake_delete('delete'));
  863. }
  864. //-- end: Prime Trash Bin (Posts) -------------------------------------------//
  865. break;
  866. case 'feedback':
  867. $user->add_lang('mcp');
  868. // Set up general vars
  869. $start = request_var('start', 0);
  870. $deletemark = (isset($_POST['delmarked'])) ? true : false;
  871. $deleteall = (isset($_POST['delall'])) ? true : false;
  872. $marked = request_var('mark', array(0));
  873. $message = utf8_normalize_nfc(request_var('message', '', true));
  874. // Sort keys
  875. $sort_days = request_var('st', 0);
  876. $sort_key = request_var('sk', 't');
  877. $sort_dir = request_var('sd', 'd');
  878. // Delete entries if requested and able
  879. if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs'))
  880. {
  881. if (!check_form_key($form_name))
  882. {
  883. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  884. }
  885. $where_sql = '';
  886. if ($deletemark && $marked)
  887. {
  888. $sql_in = array();
  889. foreach ($marked as $mark)
  890. {
  891. $sql_in[] = $mark;
  892. }
  893. $where_sql = ' AND ' . $db->sql_in_set('log_id', $sql_in);
  894. unset($sql_in);
  895. }
  896. if ($where_sql || $deleteall)
  897. {
  898. $sql = 'DELETE FROM ' . LOG_TABLE . '
  899. WHERE log_type = ' . LOG_USERS . "
  900. AND reportee_id = $user_id
  901. $where_sql";
  902. $db->sql_query($sql);
  903. add_log('admin', 'LOG_CLEAR_USER', $user_row['username']);
  904. }
  905. }
  906. if ($submit && $message)
  907. {
  908. if (!check_form_key($form_name))
  909. {
  910. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  911. }
  912. add_log('admin', 'LOG_USER_FEEDBACK', $user_row['username']);
  913. add_log('mod', 0, 0, 'LOG_USER_FEEDBACK', $user_row['username']);
  914. add_log('user', $user_id, 'LOG_USER_GENERAL', $message);
  915. trigger_error($user->lang['USER_FEEDBACK_ADDED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  916. }
  917. // Sorting
  918. $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']);
  919. $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
  920. $sort_by_sql = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
  921. $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
  922. 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);
  923. // Define where and sort sql for use in displaying logs
  924. $sql_where = ($sort_days) ? (time() - ($sort_days * 86400)) : 0;
  925. $sql_sort = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
  926. // Grab log data
  927. $log_data = array();
  928. $log_count = 0;
  929. view_log('user', $log_data, $log_count, $config['topics_per_page'], $start, 0, 0, $user_id, $sql_where, $sql_sort);
  930. $template->assign_vars(array(
  931. 'S_FEEDBACK' => true,
  932. 'S_ON_PAGE' => on_page($log_count, $config['topics_per_page'], $start),
  933. 'PAGINATION' => generate_pagination($this->u_action . "&amp;u=$user_id&amp;$u_sort_param", $log_count, $config['topics_per_page'], $start, true),
  934. 'S_LIMIT_DAYS' => $s_limit_days,
  935. 'S_SORT_KEY' => $s_sort_key,
  936. 'S_SORT_DIR' => $s_sort_dir,
  937. 'S_CLEARLOGS' => $auth->acl_get('a_clearlogs'))
  938. );
  939. foreach ($log_data as $row)
  940. {
  941. $template->assign_block_vars('log', array(
  942. 'USERNAME' => $row['username_full'],
  943. 'IP' => $row['ip'],
  944. 'DATE' => $user->format_date($row['time']),
  945. 'ACTION' => nl2br($row['action']),
  946. 'ID' => $row['id'])
  947. );
  948. }
  949. break;
  950. case 'warnings':
  951. $user->add_lang('mcp');
  952. // Set up general vars
  953. $start = request_var('start', 0);
  954. $deletemark = (isset($_POST['delmarked'])) ? true : false;
  955. $deleteall = (isset($_POST['delall'])) ? true : false;
  956. $confirm = (isset($_POST['confirm'])) ? true : false;
  957. $marked = request_var('mark', array(0));
  958. $message = utf8_normalize_nfc(request_var('message', '', true));
  959. // Sort keys
  960. $sort_days = request_var('st', 0);
  961. $sort_key = request_var('sk', 't');
  962. $sort_dir = request_var('sd', 'd');
  963. // Delete entries if requested and able
  964. if ($deletemark || $deleteall || $confirm)
  965. {
  966. if (confirm_box(true))
  967. {
  968. $where_sql = '';
  969. $deletemark = request_var('delmarked', 0);
  970. $deleteall = request_var('delall', 0);
  971. if ($deletemark && $marked)
  972. {
  973. $where_sql = ' AND ' . $db->sql_in_set('warning_id', array_values($marked));
  974. }
  975. if ($where_sql || $deleteall)
  976. {
  977. $sql = 'DELETE FROM ' . WARNINGS_TABLE . "
  978. WHERE user_id = $user_id
  979. $where_sql";
  980. $db->sql_query($sql);
  981. if ($deleteall)
  982. {
  983. $log_warnings = $deleted_warnings = 0;
  984. }
  985. else
  986. {
  987. $num_warnings = (int) $db->sql_affectedrows();
  988. $deleted_warnings = ' user_warnings - ' . $num_warnings;
  989. $log_warnings = ($num_warnings > 2) ? 2 : $num_warnings;
  990. }
  991. $sql = 'UPDATE ' . USERS_TABLE . "
  992. SET user_warnings = $deleted_warnings
  993. WHERE user_id = $user_id";
  994. $db->sql_query($sql);
  995. switch ($log_warnings)
  996. {
  997. case 2:
  998. add_log('admin', 'LOG_WARNINGS_DELETED', $user_row['username'], $num_warnings);
  999. break;
  1000. case 1:
  1001. add_log('admin', 'LOG_WARNING_DELETED', $user_row['username']);
  1002. break;
  1003. default:
  1004. add_log('admin', 'LOG_WARNINGS_DELETED_ALL', $user_row['username']);
  1005. break;
  1006. }
  1007. }
  1008. }
  1009. else
  1010. {
  1011. $s_hidden_fields = array(
  1012. 'i' => $id,
  1013. 'mode' => $mode,
  1014. 'u' => $user_id,
  1015. 'mark' => $marked,
  1016. );
  1017. if (isset($_POST['delmarked']))
  1018. {
  1019. $s_hidden_fields['delmarked'] = 1;
  1020. }
  1021. if (isset($_POST['delall']))
  1022. {
  1023. $s_hidden_fields['delall'] = 1;
  1024. }
  1025. if (isset($_POST['delall']) || (isset($_POST['delmarked']) && sizeof($marked)))
  1026. {
  1027. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields));
  1028. }
  1029. }
  1030. }
  1031. $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
  1032. FROM ' . WARNINGS_TABLE . ' w
  1033. LEFT JOIN ' . LOG_TABLE . ' l
  1034. ON (w.log_id = l.log_id)
  1035. LEFT JOIN ' . USERS_TABLE . ' m
  1036. ON (l.user_id = m.user_id)
  1037. WHERE w.user_id = ' . $user_id . '
  1038. ORDER BY w.warning_time DESC';
  1039. $result = $db->sql_query($sql);
  1040. while ($row = $db->sql_fetchrow($result))
  1041. {
  1042. if (!$row['log_operation'])
  1043. {
  1044. // We do not have a log-entry anymore, so there is no data available
  1045. $row['action'] = $user->lang['USER_WARNING_LOG_DELETED'];
  1046. }
  1047. else
  1048. {
  1049. $row['action'] = (isset($user->lang[$row['log_operation']])) ? $user->lang[$row['log_operation']] : '{' . ucfirst(str_replace('_', ' ', $row['log_operation'])) . '}';
  1050. if (!empty($row['log_data']))
  1051. {
  1052. $log_data_ary = @unserialize($row['log_data']);
  1053. $log_data_ary = ($log_data_ary === false) ? array() : $log_data_ary;
  1054. if (isset($user->lang[$row['log_operation']]))
  1055. {
  1056. // Check if there are more occurrences of % than arguments, if there are we fill out the arguments array
  1057. // It doesn't matter if we add more arguments than placeholders
  1058. if ((substr_count($row['action'], '%') - sizeof($log_data_ary)) > 0)
  1059. {
  1060. $log_data_ary = array_merge($log_data_ary, array_fill(0, substr_count($row['action'], '%') - sizeof($log_data_ary), ''));
  1061. }
  1062. $row['action'] = vsprintf($row['action'], $log_data_ary);
  1063. $row['action'] = bbcode_nl2br(censor_text($row['action']));
  1064. }
  1065. else if (!empty($log_data_ary))
  1066. {
  1067. $row['action'] .= '<br />' . implode('', $log_data_ary);
  1068. }
  1069. }
  1070. }
  1071. $template->assign_block_vars('warn', array(
  1072. 'ID' => $row['warning_id'],
  1073. 'USERNAME' => ($row['log_operation']) ? get_username_string('full', $row['mod_user_id'], $row['mod_username'], $row['mod_user_colour']) : '-',
  1074. 'ACTION' => make_clickable($row['action']),
  1075. 'DATE' => $user->format_date($row['warning_time']),
  1076. ));
  1077. }
  1078. $db->sql_freeresult($result);
  1079. $template->assign_vars(array(
  1080. 'S_WARNINGS' => true,
  1081. ));
  1082. break;
  1083. case 'profile':
  1084. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  1085. include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
  1086. $cp = new custom_profile();
  1087. $cp_data = $cp_error = array();
  1088. $sql = 'SELECT lang_id
  1089. FROM ' . LANG_TABLE . "
  1090. WHERE lang_iso = '" . $db->sql_escape($user->data['user_lang']) . "'";
  1091. $result = $db->sql_query($sql);
  1092. $row = $db->sql_fetchrow($result);
  1093. $db->sql_freeresult($result);
  1094. $user_row['iso_lang_id'] = $row['lang_id'];
  1095. $data = array(
  1096. 'icq' => request_var('icq', $user_row['user_icq']),
  1097. 'aim' => request_var('aim', $user_row['user_aim']),
  1098. 'msn' => request_var('msn', $user_row['user_msnm']),
  1099. 'yim' => request_var('yim', $user_row['user_yim']),
  1100. 'jabber' => utf8_normalize_nfc(request_var('jabber', $user_row['user_jabber'], true)),
  1101. 'website' => request_var('website', $user_row['user_website']),
  1102. 'location' => utf8_normalize_nfc(request_var('location', $user_row['user_from'], true)),
  1103. 'occupation' => utf8_normalize_nfc(request_var('occupation', $user_row['user_occ'], true)),
  1104. 'interests' => utf8_normalize_nfc(request_var('interests', $user_row['user_interests'], true)),
  1105. 'bday_day' => 0,
  1106. 'bday_month' => 0,
  1107. 'bday_year' => 0,
  1108. );
  1109. if ($user_row['user_birthday'])
  1110. {
  1111. list($data['bday_day'], $data['bday_month'], $data['bday_year']) = explode('-', $user_row['user_birthday']);
  1112. }
  1113. $data['bday_day'] = request_var('bday_day', $data['bday_day']);
  1114. $data['bday_month'] = request_var('bday_month', $data['bday_month']);
  1115. $data['bday_year'] = request_var('bday_year', $data['bday_year']);
  1116. $data['user_birthday'] = sprintf('%2d-%2d-%4d', $data['bday_day'], $data['bday_month'], $data['bday_year']);
  1117. //-- mod: Prime Birthdate ---------------------------------------------------//
  1118. include($phpbb_root_path . 'includes/prime_birthdate.' . $phpEx);
  1119. $prime_birthdate->acp_users_get_vars($data, $user_row);
  1120. //-- end: Prime Birthdate ---------------------------------------------------//
  1121. if ($submit)
  1122. {
  1123. $error = validate_data($data, array(
  1124. 'icq' => array(
  1125. array('string', true, 3, 15),
  1126. array('match', true, '#^[0-9]+$#i')),
  1127. 'aim' => array('string', true, 3, 255),
  1128. 'msn' => array('string', true, 5, 255),
  1129. 'jabber' => array(
  1130. array('string', true, 5, 255),
  1131. array('jabber')),
  1132. 'yim' => array('string', true, 5, 255),
  1133. 'website' => array(
  1134. array('string', true, 12, 255),
  1135. array('match', true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i')),
  1136. 'location' => array('string', true, 2, 100),
  1137. 'occupation' => array('string', true, 2, 500),
  1138. 'interests' => array('string', true, 2, 500),
  1139. 'bday_day' => array('num', true, 1, 31),
  1140. 'bday_month' => array('num', true, 1, 12),
  1141. 'bday_year' => array('num', true, 1901, gmdate('Y', time())),
  1142. 'user_birthday' => array('date', true),
  1143. ));
  1144. // validate custom profile fields
  1145. $cp->submit_cp_field('profile', $user_row['iso_lang_id'], $cp_data, $cp_error);
  1146. if (sizeof($cp_error))
  1147. {
  1148. $error = array_merge($error, $cp_error);
  1149. }
  1150. if (!check_form_key($form_name))
  1151. {
  1152. $error[] = 'FORM_INVALID';
  1153. }
  1154. if (!sizeof($error))
  1155. {
  1156. $sql_ary = array(
  1157. 'user_icq' => $data['icq'],
  1158. 'user_aim' => $data['aim'],
  1159. 'user_msnm' => $data['msn'],
  1160. 'user_yim' => $data['yim'],
  1161. 'user_jabber' => $data['jabber'],
  1162. 'user_website' => $data['website'],
  1163. 'user_from' => $data['location'],
  1164. 'user_occ' => $data['occupation'],
  1165. 'user_interests'=> $data['interests'],
  1166. 'user_birthday' => $data['user_birthday'],
  1167. );
  1168. //-- mod: Prime Birthdate ---------------------------------------------------//
  1169. $prime_birthdate->acp_users_inject_sql($sql_ary, $data);
  1170. //-- end: Prime Birthdate ---------------------------------------------------//
  1171. $sql = 'UPDATE ' . USERS_TABLE . '
  1172. SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
  1173. WHERE user_id = $user_id";
  1174. $db->sql_query($sql);
  1175. // Update Custom Fields
  1176. $cp->update_profile_field_data($user_id, $cp_data);
  1177. trigger_error($user->lang['USER_PROFILE_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  1178. }
  1179. // Replace "error" strings with their real, localised form
  1180. $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
  1181. }
  1182. $s_birthday_day_options = '<option value="0"' . ((!$data['bday_day']) ? ' selected="selected"' : '') . '>--</option>';
  1183. for ($i = 1; $i < 32; $i++)
  1184. {
  1185. $selected = ($i == $data['bday_day']) ? ' selected="selected"' : '';
  1186. $s_birthday_day_options .= "<option value=\"$i\"$selected>$i</option>";
  1187. }
  1188. $s_birthday_month_options = '<option value="0"' . ((!$data['bday_month']) ? ' selected="selected"' : '') . '>--</option>';
  1189. for ($i = 1; $i < 13; $i++)
  1190. {
  1191. $selected = ($i == $data['bday_month']) ? ' selected="selected"' : '';
  1192. $s_birthday_month_options .= "<option value=\"$i\"$selected>$i</option>";
  1193. }

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