/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

  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. }
  1194. $s_birthday_year_options = '';
  1195. $now = getdate();
  1196. $s_birthday_year_options = '<option value="0"' . ((!$data['bday_year']) ? ' selected="selected"' : '') . '>--</option>';
  1197. for ($i = $now['year'] - 100; $i <= $now['year']; $i++)
  1198. {
  1199. $selected = ($i == $data['bday_year']) ? ' selected="selected"' : '';
  1200. $s_birthday_year_options .= "<option value=\"$i\"$selected>$i</option>";
  1201. }
  1202. unset($now);
  1203. //-- mod: Prime Birthdate ---------------------------------------------------//
  1204. $prime_birthdate->acp_users_format_fields($data, $s_birthday_day_options, $s_birthday_month_options, $s_birthday_year_options);
  1205. //-- end: Prime Birthdate ---------------------------------------------------//
  1206. $template->assign_vars(array(
  1207. 'ICQ' => $data['icq'],
  1208. 'YIM' => $data['yim'],
  1209. 'AIM' => $data['aim'],
  1210. 'MSN' => $data['msn'],
  1211. 'JABBER' => $data['jabber'],
  1212. 'WEBSITE' => $data['website'],
  1213. 'LOCATION' => $data['location'],
  1214. 'OCCUPATION' => $data['occupation'],
  1215. 'INTERESTS' => $data['interests'],
  1216. 'S_BIRTHDAY_DAY_OPTIONS' => $s_birthday_day_options,
  1217. 'S_BIRTHDAY_MONTH_OPTIONS' => $s_birthday_month_options,
  1218. 'S_BIRTHDAY_YEAR_OPTIONS' => $s_birthday_year_options,
  1219. 'S_PROFILE' => true)
  1220. );
  1221. // Get additional profile fields and assign them to the template block var 'profile_fields'
  1222. $user->get_profile_fields($user_id);
  1223. $cp->generate_profile_fields('profile', $user_row['iso_lang_id']);
  1224. break;
  1225. case 'prefs':
  1226. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  1227. $data = array(
  1228. 'dateformat' => utf8_normalize_nfc(request_var('dateformat', $user_row['user_dateformat'], true)),
  1229. 'lang' => basename(request_var('lang', $user_row['user_lang'])),
  1230. 'tz' => request_var('tz', $user_row['user_timezone']),
  1231. 'style' => request_var('style', $user_row['user_style']),
  1232. 'dst' => request_var('dst', $user_row['user_dst']),
  1233. 'viewemail' => request_var('viewemail', $user_row['user_allow_viewemail']),
  1234. 'massemail' => request_var('massemail', $user_row['user_allow_massemail']),
  1235. 'hideonline' => request_var('hideonline', !$user_row['user_allow_viewonline']),
  1236. 'notifymethod' => request_var('notifymethod', $user_row['user_notify_type']),
  1237. 'notifypm' => request_var('notifypm', $user_row['user_notify_pm']),
  1238. 'popuppm' => request_var('popuppm', $this->optionget($user_row, 'popuppm')),
  1239. 'allowpm' => request_var('allowpm', $user_row['user_allow_pm']),
  1240. 'topic_sk' => request_var('topic_sk', ($user_row['user_topic_sortby_type']) ? $user_row['user_topic_sortby_type'] : 't'),
  1241. 'topic_sd' => request_var('topic_sd', ($user_row['user_topic_sortby_dir']) ? $user_row['user_topic_sortby_dir'] : 'd'),
  1242. 'topic_st' => request_var('topic_st', ($user_row['user_topic_show_days']) ? $user_row['user_topic_show_days'] : 0),
  1243. 'post_sk' => request_var('post_sk', ($user_row['user_post_sortby_type']) ? $user_row['user_post_sortby_type'] : 't'),
  1244. 'post_sd' => request_var('post_sd', ($user_row['user_post_sortby_dir']) ? $user_row['user_post_sortby_dir'] : 'a'),
  1245. 'post_st' => request_var('post_st', ($user_row['user_post_show_days']) ? $user_row['user_post_show_days'] : 0),
  1246. 'view_images' => request_var('view_images', $this->optionget($user_row, 'viewimg')),
  1247. 'view_flash' => request_var('view_flash', $this->optionget($user_row, 'viewflash')),
  1248. 'view_smilies' => request_var('view_smilies', $this->optionget($user_row, 'viewsmilies')),
  1249. 'view_sigs' => request_var('view_sigs', $this->optionget($user_row, 'viewsigs')),
  1250. 'view_avatars' => request_var('view_avatars', $this->optionget($user_row, 'viewavatars')),
  1251. 'view_wordcensor' => request_var('view_wordcensor', $this->optionget($user_row, 'viewcensors')),
  1252. 'bbcode' => request_var('bbcode', $this->optionget($user_row, 'bbcode')),
  1253. 'smilies' => request_var('smilies', $this->optionget($user_row, 'smilies')),
  1254. 'sig' => request_var('sig', $this->optionget($user_row, 'attachsig')),
  1255. 'notify' => request_var('notify', $user_row['user_notify']),
  1256. );
  1257. if ($submit)
  1258. {
  1259. $error = validate_data($data, array(
  1260. 'dateformat' => array('string', false, 1, 30),
  1261. 'lang' => array('match', false, '#^[a-z_\-]{2,}$#i'),
  1262. 'topic_sk' => array('string', false, 1, 1),
  1263. 'topic_sd' => array('string', false, 1, 1),
  1264. 'post_sk' => array('string', false, 1, 1),
  1265. 'post_sd' => array('string', false, 1, 1),
  1266. ));
  1267. if (!check_form_key($form_name))
  1268. {
  1269. $error[] = 'FORM_INVALID';
  1270. }
  1271. if (!sizeof($error))
  1272. {
  1273. $this->optionset($user_row, 'popuppm', $data['popuppm']);
  1274. $this->optionset($user_row, 'viewimg', $data['view_images']);
  1275. $this->optionset($user_row, 'viewflash', $data['view_flash']);
  1276. $this->optionset($user_row, 'viewsmilies', $data['view_smilies']);
  1277. $this->optionset($user_row, 'viewsigs', $data['view_sigs']);
  1278. $this->optionset($user_row, 'viewavatars', $data['view_avatars']);
  1279. $this->optionset($user_row, 'viewcensors', $data['view_wordcensor']);
  1280. $this->optionset($user_row, 'bbcode', $data['bbcode']);
  1281. $this->optionset($user_row, 'smilies', $data['smilies']);
  1282. $this->optionset($user_row, 'attachsig', $data['sig']);
  1283. $sql_ary = array(
  1284. 'user_options' => $user_row['user_options'],
  1285. 'user_allow_pm' => $data['allowpm'],
  1286. 'user_allow_viewemail' => $data['viewemail'],
  1287. 'user_allow_massemail' => $data['massemail'],
  1288. 'user_allow_viewonline' => !$data['hideonline'],
  1289. 'user_notify_type' => $data['notifymethod'],
  1290. 'user_notify_pm' => $data['notifypm'],
  1291. 'user_dst' => $data['dst'],
  1292. 'user_dateformat' => $data['dateformat'],
  1293. 'user_lang' => $data['lang'],
  1294. 'user_timezone' => $data['tz'],
  1295. 'user_style' => $data['style'],
  1296. 'user_topic_sortby_type' => $data['topic_sk'],
  1297. 'user_post_sortby_type' => $data['post_sk'],
  1298. 'user_topic_sortby_dir' => $data['topic_sd'],
  1299. 'user_post_sortby_dir' => $data['post_sd'],
  1300. 'user_topic_show_days' => $data['topic_st'],
  1301. 'user_post_show_days' => $data['post_st'],
  1302. 'user_notify' => $data['notify'],
  1303. );
  1304. $sql = 'UPDATE ' . USERS_TABLE . '
  1305. SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
  1306. WHERE user_id = $user_id";
  1307. $db->sql_query($sql);
  1308. // Check if user has an active session
  1309. if ($user_row['session_id'])
  1310. {
  1311. // We'll update the session if user_allow_viewonline has changed and the user is a bot
  1312. // Or if it's a regular user and the admin set it to hide the session
  1313. if ($user_row['user_allow_viewonline'] != $sql_ary['user_allow_viewonline'] && $user_row['user_type'] == USER_IGNORE
  1314. || $user_row['user_allow_viewonline'] && !$sql_ary['user_allow_viewonline'])
  1315. {
  1316. // We also need to check if the user has the permission to cloak.
  1317. $user_auth = new auth();
  1318. $user_auth->acl($user_row);
  1319. $session_sql_ary = array(
  1320. 'session_viewonline' => ($user_auth->acl_get('u_hideonline')) ? $sql_ary['user_allow_viewonline'] : true,
  1321. );
  1322. $sql = 'UPDATE ' . SESSIONS_TABLE . '
  1323. SET ' . $db->sql_build_array('UPDATE', $session_sql_ary) . "
  1324. WHERE session_user_id = $user_id";
  1325. $db->sql_query($sql);
  1326. unset($user_auth);
  1327. }
  1328. }
  1329. trigger_error($user->lang['USER_PREFS_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  1330. }
  1331. // Replace "error" strings with their real, localised form
  1332. $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
  1333. }
  1334. $dateformat_options = '';
  1335. foreach ($user->lang['dateformats'] as $format => $null)
  1336. {
  1337. $dateformat_options .= '<option value="' . $format . '"' . (($format == $data['dateformat']) ? ' selected="selected"' : '') . '>';
  1338. $dateformat_options .= $user->format_date(time(), $format, false) . ((strpos($format, '|') !== false) ? $user->lang['VARIANT_DATE_SEPARATOR'] . $user->format_date(time(), $format, true) : '');
  1339. $dateformat_options .= '</option>';
  1340. }
  1341. $s_custom = false;
  1342. $dateformat_options .= '<option value="custom"';
  1343. if (!isset($user->lang['dateformats'][$data['dateformat']]))
  1344. {
  1345. $dateformat_options .= ' selected="selected"';
  1346. $s_custom = true;
  1347. }
  1348. $dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>';
  1349. $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
  1350. // Topic ordering options
  1351. $limit_topic_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
  1352. $sort_by_topic_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']);
  1353. // Post ordering options
  1354. $limit_post_days = array(0 => $user->lang['ALL_POSTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
  1355. $sort_by_post_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
  1356. $_options = array('topic', 'post');
  1357. foreach ($_options as $sort_option)
  1358. {
  1359. ${'s_limit_' . $sort_option . '_days'} = '<select name="' . $sort_option . '_st">';
  1360. foreach (${'limit_' . $sort_option . '_days'} as $day => $text)
  1361. {
  1362. $selected = ($data[$sort_option . '_st'] == $day) ? ' selected="selected"' : '';
  1363. ${'s_limit_' . $sort_option . '_days'} .= '<option value="' . $day . '"' . $selected . '>' . $text . '</option>';
  1364. }
  1365. ${'s_limit_' . $sort_option . '_days'} .= '</select>';
  1366. ${'s_sort_' . $sort_option . '_key'} = '<select name="' . $sort_option . '_sk">';
  1367. foreach (${'sort_by_' . $sort_option . '_text'} as $key => $text)
  1368. {
  1369. $selected = ($data[$sort_option . '_sk'] == $key) ? ' selected="selected"' : '';
  1370. ${'s_sort_' . $sort_option . '_key'} .= '<option value="' . $key . '"' . $selected . '>' . $text . '</option>';
  1371. }
  1372. ${'s_sort_' . $sort_option . '_key'} .= '</select>';
  1373. ${'s_sort_' . $sort_option . '_dir'} = '<select name="' . $sort_option . '_sd">';
  1374. foreach ($sort_dir_text as $key => $value)
  1375. {
  1376. $selected = ($data[$sort_option . '_sd'] == $key) ? ' selected="selected"' : '';
  1377. ${'s_sort_' . $sort_option . '_dir'} .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  1378. }
  1379. ${'s_sort_' . $sort_option . '_dir'} .= '</select>';
  1380. }
  1381. $template->assign_vars(array(
  1382. 'S_PREFS' => true,
  1383. 'S_JABBER_DISABLED' => ($config['jab_enable'] && $user_row['user_jabber'] && @extension_loaded('xml')) ? false : true,
  1384. 'VIEW_EMAIL' => $data['viewemail'],
  1385. 'MASS_EMAIL' => $data['massemail'],
  1386. 'ALLOW_PM' => $data['allowpm'],
  1387. 'HIDE_ONLINE' => $data['hideonline'],
  1388. 'NOTIFY_EMAIL' => ($data['notifymethod'] == NOTIFY_EMAIL) ? true : false,
  1389. 'NOTIFY_IM' => ($data['notifymethod'] == NOTIFY_IM) ? true : false,
  1390. 'NOTIFY_BOTH' => ($data['notifymethod'] == NOTIFY_BOTH) ? true : false,
  1391. 'NOTIFY_PM' => $data['notifypm'],
  1392. 'POPUP_PM' => $data['popuppm'],
  1393. 'DST' => $data['dst'],
  1394. 'BBCODE' => $data['bbcode'],
  1395. 'SMILIES' => $data['smilies'],
  1396. 'ATTACH_SIG' => $data['sig'],
  1397. 'NOTIFY' => $data['notify'],
  1398. 'VIEW_IMAGES' => $data['view_images'],
  1399. 'VIEW_FLASH' => $data['view_flash'],
  1400. 'VIEW_SMILIES' => $data['view_smilies'],
  1401. 'VIEW_SIGS' => $data['view_sigs'],
  1402. 'VIEW_AVATARS' => $data['view_avatars'],
  1403. 'VIEW_WORDCENSOR' => $data['view_wordcensor'],
  1404. 'S_TOPIC_SORT_DAYS' => $s_limit_topic_days,
  1405. 'S_TOPIC_SORT_KEY' => $s_sort_topic_key,
  1406. 'S_TOPIC_SORT_DIR' => $s_sort_topic_dir,
  1407. 'S_POST_SORT_DAYS' => $s_limit_post_days,
  1408. 'S_POST_SORT_KEY' => $s_sort_post_key,
  1409. 'S_POST_SORT_DIR' => $s_sort_post_dir,
  1410. 'DATE_FORMAT' => $data['dateformat'],
  1411. 'S_DATEFORMAT_OPTIONS' => $dateformat_options,
  1412. 'S_CUSTOM_DATEFORMAT' => $s_custom,
  1413. 'DEFAULT_DATEFORMAT' => $config['default_dateformat'],
  1414. 'A_DEFAULT_DATEFORMAT' => addslashes($config['default_dateformat']),
  1415. 'S_LANG_OPTIONS' => language_select($data['lang']),
  1416. 'S_STYLE_OPTIONS' => style_select($data['style']),
  1417. 'S_TZ_OPTIONS' => tz_select($data['tz'], true),
  1418. )
  1419. );
  1420. break;
  1421. case 'avatar':
  1422. include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  1423. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  1424. $can_upload = (file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads) ? true : false;
  1425. if ($submit)
  1426. {
  1427. if (!check_form_key($form_name))
  1428. {
  1429. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  1430. }
  1431. if (avatar_process_user($error, $user_row, $can_upload))
  1432. {
  1433. trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_row['user_id']));
  1434. }
  1435. // Replace "error" strings with their real, localised form
  1436. $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
  1437. }
  1438. if (!$config['allow_avatar'] && $user_row['user_avatar_type'])
  1439. {
  1440. $error[] = $user->lang['USER_AVATAR_NOT_ALLOWED'];
  1441. }
  1442. else if ((($user_row['user_avatar_type'] == AVATAR_UPLOAD) && !$config['allow_avatar_upload']) ||
  1443. (($user_row['user_avatar_type'] == AVATAR_REMOTE) && !$config['allow_avatar_remote']) ||
  1444. (($user_row['user_avatar_type'] == AVATAR_GALLERY) && !$config['allow_avatar_local']))
  1445. {
  1446. $error[] = $user->lang['USER_AVATAR_TYPE_NOT_ALLOWED'];
  1447. }
  1448. // Generate users avatar
  1449. $avatar_img = ($user_row['user_avatar']) ? get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height'], 'USER_AVATAR', true) : '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />';
  1450. $display_gallery = (isset($_POST['display_gallery'])) ? true : false;
  1451. $avatar_select = basename(request_var('avatar_select', ''));
  1452. $category = basename(request_var('category', ''));
  1453. if ($config['allow_avatar_local'] && $display_gallery)
  1454. {
  1455. avatar_gallery($category, $avatar_select, 4);
  1456. }
  1457. $template->assign_vars(array(
  1458. 'S_AVATAR' => true,
  1459. 'S_CAN_UPLOAD' => $can_upload,
  1460. 'S_UPLOAD_FILE' => ($config['allow_avatar'] && $can_upload && $config['allow_avatar_upload']) ? true : false,
  1461. 'S_REMOTE_UPLOAD' => ($config['allow_avatar'] && $can_upload && $config['allow_avatar_remote_upload']) ? true : false,
  1462. 'S_ALLOW_REMOTE' => ($config['allow_avatar'] && $config['allow_avatar_remote']) ? true : false,
  1463. 'S_DISPLAY_GALLERY' => ($config['allow_avatar'] && $config['allow_avatar_local'] && !$display_gallery) ? true : false,
  1464. 'S_IN_GALLERY' => ($config['allow_avatar'] && $config['allow_avatar_local'] && $display_gallery) ? true : false,
  1465. 'AVATAR_IMAGE' => $avatar_img,
  1466. 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'],
  1467. 'USER_AVATAR_WIDTH' => $user_row['user_avatar_width'],
  1468. 'USER_AVATAR_HEIGHT' => $user_row['user_avatar_height'],
  1469. 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024)))
  1470. );
  1471. break;
  1472. case 'rank':
  1473. if ($submit)
  1474. {
  1475. if (!check_form_key($form_name))
  1476. {
  1477. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  1478. }
  1479. $rank_id = request_var('user_rank', 0);
  1480. $sql = 'UPDATE ' . USERS_TABLE . "
  1481. SET user_rank = $rank_id
  1482. WHERE user_id = $user_id";
  1483. $db->sql_query($sql);
  1484. trigger_error($user->lang['USER_RANK_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  1485. }
  1486. $sql = 'SELECT *
  1487. FROM ' . RANKS_TABLE . '
  1488. WHERE rank_special = 1
  1489. ORDER BY rank_title';
  1490. $result = $db->sql_query($sql);
  1491. $s_rank_options = '<option value="0"' . ((!$user_row['user_rank']) ? ' selected="selected"' : '') . '>' . $user->lang['NO_SPECIAL_RANK'] . '</option>';
  1492. while ($row = $db->sql_fetchrow($result))
  1493. {
  1494. $selected = ($user_row['user_rank'] && $row['rank_id'] == $user_row['user_rank']) ? ' selected="selected"' : '';
  1495. $s_rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>';
  1496. }
  1497. $db->sql_freeresult($result);
  1498. $template->assign_vars(array(
  1499. 'S_RANK' => true,
  1500. 'S_RANK_OPTIONS' => $s_rank_options)
  1501. );
  1502. break;
  1503. case 'sig':
  1504. include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
  1505. include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  1506. $enable_bbcode = ($config['allow_sig_bbcode']) ? (bool) $this->optionget($user_row, 'sig_bbcode') : false;
  1507. $enable_smilies = ($config['allow_sig_smilies']) ? (bool) $this->optionget($user_row, 'sig_smilies') : false;
  1508. $enable_urls = ($config['allow_sig_links']) ? (bool) $this->optionget($user_row, 'sig_links') : false;
  1509. $signature = utf8_normalize_nfc(request_var('signature', (string) $user_row['user_sig'], true));
  1510. $preview = (isset($_POST['preview'])) ? true : false;
  1511. if ($submit || $preview)
  1512. {
  1513. include_once($phpbb_root_path . 'includes/message_parser.' . $phpEx);
  1514. $enable_bbcode = ($config['allow_sig_bbcode']) ? ((request_var('disable_bbcode', false)) ? false : true) : false;
  1515. $enable_smilies = ($config['allow_sig_smilies']) ? ((request_var('disable_smilies', false)) ? false : true) : false;
  1516. $enable_urls = ($config['allow_sig_links']) ? ((request_var('disable_magic_url', false)) ? false : true) : false;
  1517. $message_parser = new parse_message($signature);
  1518. // Allowing Quote BBCode
  1519. $message_parser->parse($enable_bbcode, $enable_urls, $enable_smilies, $config['allow_sig_img'], $config['allow_sig_flash'], true, $config['allow_sig_links'], true, 'sig');
  1520. if (sizeof($message_parser->warn_msg))
  1521. {
  1522. $error[] = implode('<br />', $message_parser->warn_msg);
  1523. }
  1524. if (!check_form_key($form_name))
  1525. {
  1526. $error = 'FORM_INVALID';
  1527. }
  1528. if (!sizeof($error) && $submit)
  1529. {
  1530. $this->optionset($user_row, 'sig_bbcode', $enable_bbcode);
  1531. $this->optionset($user_row, 'sig_smilies', $enable_smilies);
  1532. $this->optionset($user_row, 'sig_links', $enable_urls);
  1533. $sql_ary = array(
  1534. 'user_sig' => (string) $message_parser->message,
  1535. 'user_options' => $user_row['user_options'],
  1536. 'user_sig_bbcode_uid' => (string) $message_parser->bbcode_uid,
  1537. 'user_sig_bbcode_bitfield' => (string) $message_parser->bbcode_bitfield
  1538. );
  1539. $sql = 'UPDATE ' . USERS_TABLE . '
  1540. SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
  1541. WHERE user_id = ' . $user_id;
  1542. $db->sql_query($sql);
  1543. trigger_error($user->lang['USER_SIG_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  1544. }
  1545. // Replace "error" strings with their real, localised form
  1546. $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
  1547. }
  1548. $signature_preview = '';
  1549. if ($preview)
  1550. {
  1551. // Now parse it for displaying
  1552. $signature_preview = $message_parser->format_display($enable_bbcode, $enable_urls, $enable_smilies, false);
  1553. unset($message_parser);
  1554. }
  1555. decode_message($signature, $user_row['user_sig_bbcode_uid']);
  1556. $template->assign_vars(array(
  1557. 'S_SIGNATURE' => true,
  1558. 'SIGNATURE' => $signature,
  1559. 'SIGNATURE_PREVIEW' => $signature_preview,
  1560. 'S_BBCODE_CHECKED' => (!$enable_bbcode) ? ' checked="checked"' : '',
  1561. 'S_SMILIES_CHECKED' => (!$enable_smilies) ? ' checked="checked"' : '',
  1562. 'S_MAGIC_URL_CHECKED' => (!$enable_urls) ? ' checked="checked"' : '',
  1563. 'BBCODE_STATUS' => ($config['allow_sig_bbcode']) ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . append_sid("{$phpbb_root_path}faq.$phpEx", 'mode=bbcode') . '">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$phpbb_root_path}faq.$phpEx", 'mode=bbcode') . '">', '</a>'),
  1564. 'SMILIES_STATUS' => ($config['allow_sig_smilies']) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'],
  1565. 'IMG_STATUS' => ($config['allow_sig_img']) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'],
  1566. 'FLASH_STATUS' => ($config['allow_sig_flash']) ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'],
  1567. 'URL_STATUS' => ($config['allow_sig_links']) ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'],
  1568. 'L_SIGNATURE_EXPLAIN' => sprintf($user->lang['SIGNATURE_EXPLAIN'], $config['max_sig_chars']),
  1569. 'S_BBCODE_ALLOWED' => $config['allow_sig_bbcode'],
  1570. 'S_SMILIES_ALLOWED' => $config['allow_sig_smilies'],
  1571. 'S_BBCODE_IMG' => ($config['allow_sig_img']) ? true : false,
  1572. 'S_BBCODE_FLASH' => ($config['allow_sig_flash']) ? true : false,
  1573. 'S_LINKS_ALLOWED' => ($config['allow_sig_links']) ? true : false)
  1574. );
  1575. // Assigning custom bbcodes
  1576. display_custom_bbcodes();
  1577. break;
  1578. case 'attach':
  1579. $start = request_var('start', 0);
  1580. $deletemark = (isset($_POST['delmarked'])) ? true : false;
  1581. $marked = request_var('mark', array(0));
  1582. // Sort keys
  1583. $sort_key = request_var('sk', 'a');
  1584. $sort_dir = request_var('sd', 'd');
  1585. if ($deletemark && sizeof($marked))
  1586. {
  1587. $sql = 'SELECT attach_id
  1588. FROM ' . ATTACHMENTS_TABLE . '
  1589. WHERE poster_id = ' . $user_id . '
  1590. AND is_orphan = 0
  1591. AND ' . $db->sql_in_set('attach_id', $marked);
  1592. $result = $db->sql_query($sql);
  1593. $marked = array();
  1594. while ($row = $db->sql_fetchrow($result))
  1595. {
  1596. $marked[] = $row['attach_id'];
  1597. }
  1598. $db->sql_freeresult($result);
  1599. }
  1600. if ($deletemark && sizeof($marked))
  1601. {
  1602. if (confirm_box(true))
  1603. {
  1604. $sql = 'SELECT real_filename
  1605. FROM ' . ATTACHMENTS_TABLE . '
  1606. WHERE ' . $db->sql_in_set('attach_id', $marked);
  1607. $result = $db->sql_query($sql);
  1608. $log_attachments = array();
  1609. while ($row = $db->sql_fetchrow($result))
  1610. {
  1611. $log_attachments[] = $row['real_filename'];
  1612. }
  1613. $db->sql_freeresult($result);
  1614. delete_attachments('attach', $marked);
  1615. $message = (sizeof($log_attachments) == 1) ? $user->lang['ATTACHMENT_DELETED'] : $user->lang['ATTACHMENTS_DELETED'];
  1616. add_log('admin', 'LOG_ATTACHMENTS_DELETED', implode(', ', $log_attachments));
  1617. trigger_error($message . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  1618. }
  1619. else
  1620. {
  1621. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  1622. 'u' => $user_id,
  1623. 'i' => $id,
  1624. 'mode' => $mode,
  1625. 'action' => $action,
  1626. 'delmarked' => true,
  1627. 'mark' => $marked))
  1628. );
  1629. }
  1630. }
  1631. $sk_text = array('a' => $user->lang['SORT_FILENAME'], 'c' => $user->lang['SORT_EXTENSION'], 'd' => $user->lang['SORT_SIZE'], 'e' => $user->lang['SORT_DOWNLOADS'], 'f' => $user->lang['SORT_POST_TIME'], 'g' => $user->lang['SORT_TOPIC_TITLE']);
  1632. $sk_sql = array('a' => 'a.real_filename', 'c' => 'a.extension', 'd' => 'a.filesize', 'e' => 'a.download_count', 'f' => 'a.filetime', 'g' => 't.topic_title');
  1633. $sd_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
  1634. $s_sort_key = '';
  1635. foreach ($sk_text as $key => $value)
  1636. {
  1637. $selected = ($sort_key == $key) ? ' selected="selected"' : '';
  1638. $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  1639. }
  1640. $s_sort_dir = '';
  1641. foreach ($sd_text as $key => $value)
  1642. {
  1643. $selected = ($sort_dir == $key) ? ' selected="selected"' : '';
  1644. $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  1645. }
  1646. if (!isset($sk_sql[$sort_key]))
  1647. {
  1648. $sort_key = 'a';
  1649. }
  1650. $order_by = $sk_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC');
  1651. $sql = 'SELECT COUNT(attach_id) as num_attachments
  1652. FROM ' . ATTACHMENTS_TABLE . "
  1653. WHERE poster_id = $user_id
  1654. AND is_orphan = 0";
  1655. $result = $db->sql_query_limit($sql, 1);
  1656. $num_attachments = (int) $db->sql_fetchfield('num_attachments');
  1657. $db->sql_freeresult($result);
  1658. $sql = 'SELECT a.*, t.topic_title, p.message_subject as message_title
  1659. FROM ' . ATTACHMENTS_TABLE . ' a
  1660. LEFT JOIN ' . TOPICS_TABLE . ' t ON (a.topic_id = t.topic_id
  1661. AND a.in_message = 0)
  1662. LEFT JOIN ' . PRIVMSGS_TABLE . ' p ON (a.post_msg_id = p.msg_id
  1663. AND a.in_message = 1)
  1664. WHERE a.poster_id = ' . $user_id . "
  1665. AND a.is_orphan = 0
  1666. ORDER BY $order_by";
  1667. $result = $db->sql_query_limit($sql, $config['posts_per_page'], $start);
  1668. while ($row = $db->sql_fetchrow($result))
  1669. {
  1670. if ($row['in_message'])
  1671. {
  1672. $view_topic = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&amp;p={$row['post_msg_id']}");
  1673. }
  1674. else
  1675. {
  1676. $view_topic = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t={$row['topic_id']}&amp;p={$row['post_msg_id']}") . '#p' . $row['post_msg_id'];
  1677. }
  1678. $template->assign_block_vars('attach', array(
  1679. 'REAL_FILENAME' => $row['real_filename'],
  1680. 'COMMENT' => nl2br($row['attach_comment']),
  1681. 'EXTENSION' => $row['extension'],
  1682. 'SIZE' => get_formatted_filesize($row['filesize']),
  1683. 'DOWNLOAD_COUNT' => $row['download_count'],
  1684. 'POST_TIME' => $user->format_date($row['filetime']),
  1685. 'TOPIC_TITLE' => ($row['in_message']) ? $row['message_title'] : $row['topic_title'],
  1686. 'ATTACH_ID' => $row['attach_id'],
  1687. 'POST_ID' => $row['post_msg_id'],
  1688. 'TOPIC_ID' => $row['topic_id'],
  1689. 'S_IN_MESSAGE' => $row['in_message'],
  1690. 'U_DOWNLOAD' => append_sid("{$phpbb_root_path}download/file.$phpEx", 'mode=view&amp;id=' . $row['attach_id']),
  1691. 'U_VIEW_TOPIC' => $view_topic)
  1692. );
  1693. }
  1694. $db->sql_freeresult($result);
  1695. $template->assign_vars(array(
  1696. 'S_ATTACHMENTS' => true,
  1697. 'S_ON_PAGE' => on_page($num_attachments, $config['topics_per_page'], $start),
  1698. 'S_SORT_KEY' => $s_sort_key,
  1699. 'S_SORT_DIR' => $s_sort_dir,
  1700. 'PAGINATION' => generate_pagination($this->u_action . "&amp;u=$user_id&amp;sk=$sort_key&amp;sd=$sort_dir", $num_attachments, $config['topics_per_page'], $start, true))
  1701. );
  1702. break;
  1703. case 'groups':
  1704. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  1705. $user->add_lang(array('groups', 'acp/groups'));
  1706. $group_id = request_var('g', 0);
  1707. if ($group_id)
  1708. {
  1709. // Check the founder only entry for this group to make sure everything is well
  1710. $sql = 'SELECT group_founder_manage
  1711. FROM ' . GROUPS_TABLE . '
  1712. WHERE group_id = ' . $group_id;
  1713. $result = $db->sql_query($sql);
  1714. $founder_manage = (int) $db->sql_fetchfield('group_founder_manage');
  1715. $db->sql_freeresult($result);
  1716. if ($user->data['user_type'] != USER_FOUNDER && $founder_manage)
  1717. {
  1718. trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  1719. }
  1720. }
  1721. else
  1722. {
  1723. $founder_manage = 0;
  1724. }
  1725. switch ($action)
  1726. {
  1727. case 'demote':
  1728. case 'promote':
  1729. case 'default':
  1730. if (!$group_id)
  1731. {
  1732. trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  1733. }
  1734. group_user_attributes($action, $group_id, $user_id);
  1735. if ($action == 'default')
  1736. {
  1737. $user_row['group_id'] = $group_id;
  1738. }
  1739. break;
  1740. case 'delete':
  1741. if (confirm_box(true))
  1742. {
  1743. if (!$group_id)
  1744. {
  1745. trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  1746. }
  1747. if ($error = group_user_del($group_id, $user_id))
  1748. {
  1749. trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  1750. }
  1751. $error = array();
  1752. // The delete action was successful - therefore update the user row...
  1753. $sql = 'SELECT u.*, s.*
  1754. FROM ' . USERS_TABLE . ' u
  1755. LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id)
  1756. WHERE u.user_id = ' . $user_id . '
  1757. ORDER BY s.session_time DESC';
  1758. $result = $db->sql_query_limit($sql, 1);
  1759. $user_row = $db->sql_fetchrow($result);
  1760. $db->sql_freeresult($result);
  1761. }
  1762. else
  1763. {
  1764. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  1765. 'u' => $user_id,
  1766. 'i' => $id,
  1767. 'mode' => $mode,
  1768. 'action' => $action,
  1769. 'g' => $group_id))
  1770. );
  1771. }
  1772. break;
  1773. case 'approve':
  1774. if (confirm_box(true))
  1775. {
  1776. if (!$group_id)
  1777. {
  1778. trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  1779. }
  1780. group_user_attributes($action, $group_id, $user_id);
  1781. }
  1782. else
  1783. {
  1784. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  1785. 'u' => $user_id,
  1786. 'i' => $id,
  1787. 'mode' => $mode,
  1788. 'action' => $action,
  1789. 'g' => $group_id))
  1790. );
  1791. }
  1792. break;
  1793. }
  1794. // Add user to group?
  1795. if ($submit)
  1796. {
  1797. if (!check_form_key($form_name))
  1798. {
  1799. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  1800. }
  1801. if (!$group_id)
  1802. {
  1803. trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  1804. }
  1805. // Add user/s to group
  1806. if ($error = group_user_add($group_id, $user_id))
  1807. {
  1808. trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  1809. }
  1810. $error = array();
  1811. }
  1812. $sql = 'SELECT ug.*, g.*
  1813. FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . " ug
  1814. WHERE ug.user_id = $user_id
  1815. AND g.group_id = ug.group_id
  1816. ORDER BY g.group_type DESC, ug.user_pending ASC, g.group_name";
  1817. $result = $db->sql_query($sql);
  1818. $i = 0;
  1819. $group_data = $id_ary = array();
  1820. while ($row = $db->sql_fetchrow($result))
  1821. {
  1822. $type = ($row['group_type'] == GROUP_SPECIAL) ? 'special' : (($row['user_pending']) ? 'pending' : 'normal');
  1823. $group_data[$type][$i]['group_id'] = $row['group_id'];
  1824. $group_data[$type][$i]['group_name'] = $row['group_name'];
  1825. $group_data[$type][$i]['group_leader'] = ($row['group_leader']) ? 1 : 0;
  1826. $id_ary[] = $row['group_id'];
  1827. $i++;
  1828. }
  1829. $db->sql_freeresult($result);
  1830. // Select box for other groups
  1831. $sql = 'SELECT group_id, group_name, group_type, group_founder_manage
  1832. FROM ' . GROUPS_TABLE . '
  1833. ' . ((sizeof($id_ary)) ? 'WHERE ' . $db->sql_in_set('group_id', $id_ary, true) : '') . '
  1834. ORDER BY group_type DESC, group_name ASC';
  1835. $result = $db->sql_query($sql);
  1836. $s_group_options = '';
  1837. while ($row = $db->sql_fetchrow($result))
  1838. {
  1839. if (!$config['coppa_enable'] && $row['group_name'] == 'REGISTERED_COPPA')
  1840. {
  1841. continue;
  1842. }
  1843. // Do not display those groups not allowed to be managed
  1844. if ($user->data['user_type'] != USER_FOUNDER && $row['group_founder_manage'])
  1845. {
  1846. continue;
  1847. }
  1848. $s_group_options .= '<option' . (($row['group_type'] == GROUP_SPECIAL) ? ' class="sep"' : '') . ' value="' . $row['group_id'] . '">' . (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</option>';
  1849. }
  1850. $db->sql_freeresult($result);
  1851. $current_type = '';
  1852. foreach ($group_data as $group_type => $data_ary)
  1853. {
  1854. if ($current_type != $group_type)
  1855. {
  1856. $template->assign_block_vars('group', array(
  1857. 'S_NEW_GROUP_TYPE' => true,
  1858. 'GROUP_TYPE' => $user->lang['USER_GROUP_' . strtoupper($group_type)])
  1859. );
  1860. }
  1861. foreach ($data_ary as $data)
  1862. {
  1863. $template->assign_block_vars('group', array(
  1864. 'U_EDIT_GROUP' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=groups&amp;mode=manage&amp;action=edit&amp;u=$user_id&amp;g={$data['group_id']}&amp;back_link=acp_users_groups"),
  1865. 'U_DEFAULT' => $this->u_action . "&amp;action=default&amp;u=$user_id&amp;g=" . $data['group_id'],
  1866. 'U_DEMOTE_PROMOTE' => $this->u_action . '&amp;action=' . (($data['group_leader']) ? 'demote' : 'promote') . "&amp;u=$user_id&amp;g=" . $data['group_id'],
  1867. 'U_DELETE' => $this->u_action . "&amp;action=delete&amp;u=$user_id&amp;g=" . $data['group_id'],
  1868. 'U_APPROVE' => ($group_type == 'pending') ? $this->u_action . "&amp;action=approve&amp;u=$user_id&amp;g=" . $data['group_id'] : '',
  1869. 'GROUP_NAME' => ($group_type == 'special') ? $user->lang['G_' . $data['group_name']] : $data['group_name'],
  1870. 'L_DEMOTE_PROMOTE' => ($data['group_leader']) ? $user->lang['GROUP_DEMOTE'] : $user->lang['GROUP_PROMOTE'],
  1871. 'S_IS_MEMBER' => ($group_type != 'pending') ? true : false,
  1872. 'S_NO_DEFAULT' => ($user_row['group_id'] != $data['group_id']) ? true : false,
  1873. 'S_SPECIAL_GROUP' => ($group_type == 'special') ? true : false,
  1874. )
  1875. );
  1876. }
  1877. }
  1878. $template->assign_vars(array(
  1879. 'S_GROUPS' => true,
  1880. 'S_GROUP_OPTIONS' => $s_group_options)
  1881. );
  1882. break;
  1883. case 'perm':
  1884. include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
  1885. $auth_admin = new auth_admin();
  1886. $user->add_lang('acp/permissions');
  1887. add_permission_language();
  1888. $forum_id = request_var('f', 0);
  1889. // Global Permissions
  1890. if (!$forum_id)
  1891. {
  1892. // Select auth options
  1893. $sql = 'SELECT auth_option, is_local, is_global
  1894. FROM ' . ACL_OPTIONS_TABLE . '
  1895. WHERE auth_option ' . $db->sql_like_expression($db->any_char . '_') . '
  1896. AND is_global = 1
  1897. ORDER BY auth_option';
  1898. $result = $db->sql_query($sql);
  1899. $hold_ary = array();
  1900. while ($row = $db->sql_fetchrow($result))
  1901. {
  1902. $hold_ary = $auth_admin->get_mask('view', $user_id, false, false, $row['auth_option'], 'global', ACL_NEVER);
  1903. $auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', false, false);
  1904. }
  1905. $db->sql_freeresult($result);
  1906. unset($hold_ary);
  1907. }
  1908. else
  1909. {
  1910. $sql = 'SELECT auth_option, is_local, is_global
  1911. FROM ' . ACL_OPTIONS_TABLE . "
  1912. WHERE auth_option " . $db->sql_like_expression($db->any_char . '_') . "
  1913. AND is_local = 1
  1914. ORDER BY is_global DESC, auth_option";
  1915. $result = $db->sql_query($sql);
  1916. while ($row = $db->sql_fetchrow($result))
  1917. {
  1918. $hold_ary = $auth_admin->get_mask('view', $user_id, false, $forum_id, $row['auth_option'], 'local', ACL_NEVER);
  1919. $auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', true, false);
  1920. }
  1921. $db->sql_freeresult($result);
  1922. }
  1923. $s_forum_options = '<option value="0"' . ((!$forum_id) ? ' selected="selected"' : '') . '>' . $user->lang['VIEW_GLOBAL_PERMS'] . '</option>';
  1924. $s_forum_options .= make_forum_select($forum_id, false, true, false, false, false);
  1925. $template->assign_vars(array(
  1926. 'S_PERMISSIONS' => true,
  1927. 'S_GLOBAL' => (!$forum_id) ? true : false,
  1928. 'S_FORUM_OPTIONS' => $s_forum_options,
  1929. 'U_ACTION' => $this->u_action . '&amp;u=' . $user_id,
  1930. 'U_USER_PERMISSIONS' => append_sid("{$phpbb_admin_path}index.$phpEx" ,'i=permissions&amp;mode=setting_user_global&amp;user_id[]=' . $user_id),
  1931. 'U_USER_FORUM_PERMISSIONS' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions&amp;mode=setting_user_local&amp;user_id[]=' . $user_id))
  1932. );
  1933. break;
  1934. }
  1935. // Assign general variables
  1936. $template->assign_vars(array(
  1937. 'S_ERROR' => (sizeof($error)) ? true : false,
  1938. 'ERROR_MSG' => (sizeof($error)) ? implode('<br />', $error) : '')
  1939. );
  1940. }
  1941. /**
  1942. * Optionset replacement for this module based on $user->optionset
  1943. */
  1944. function optionset(&$user_row, $key, $value, $data = false)
  1945. {
  1946. global $user;
  1947. $var = ($data) ? $data : $user_row['user_options'];
  1948. if ($value && !($var & 1 << $user->keyoptions[$key]))
  1949. {
  1950. $var += 1 << $user->keyoptions[$key];
  1951. }
  1952. else if (!$value && ($var & 1 << $user->keyoptions[$key]))
  1953. {
  1954. $var -= 1 << $user->keyoptions[$key];
  1955. }
  1956. else
  1957. {
  1958. return ($data) ? $var : false;
  1959. }
  1960. if (!$data)
  1961. {
  1962. $user_row['user_options'] = $var;
  1963. return true;
  1964. }
  1965. else
  1966. {
  1967. return $var;
  1968. }
  1969. }
  1970. /**
  1971. * Optionget replacement for this module based on $user->optionget
  1972. */
  1973. function optionget(&$user_row, $key, $data = false)
  1974. {
  1975. global $user;
  1976. $var = ($data) ? $data : $user_row['user_options'];
  1977. return ($var & 1 << $user->keyoptions[$key]) ? true : false;
  1978. }
  1979. }
  1980. ?>