Advertisement
Guest User

acp_user.php

a guest
Feb 27th, 2015
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 88.84 KB | None | 0 0
  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. /**
  12. * @ignore
  13. */
  14. if (!defined('IN_PHPBB'))
  15. {
  16. exit;
  17. }
  18.  
  19. /**
  20. * @package acp
  21. */
  22. class acp_users
  23. {
  24. var $u_action;
  25. var $p_master;
  26.  
  27. function acp_users(&$p_master)
  28. {
  29. $this->p_master = &$p_master;
  30. }
  31.  
  32. function main($id, $mode)
  33. {
  34. global $config, $db, $user, $auth, $template, $cache;
  35. global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads;
  36.  
  37. $user->add_lang(array('posting', 'ucp', 'acp/users'));
  38. $this->tpl_name = 'acp_users';
  39. $this->page_title = 'ACP_USER_' . strtoupper($mode);
  40.  
  41. $error = array();
  42. $username = utf8_normalize_nfc(request_var('username', '', true));
  43. $user_id = request_var('u', 0);
  44. $action = request_var('action', '');
  45.  
  46. $submit = (isset($_POST['update']) && !isset($_POST['cancel'])) ? true : false;
  47.  
  48. $form_name = 'acp_users';
  49. add_form_key($form_name);
  50.  
  51. // Whois (special case)
  52. if ($action == 'whois')
  53. {
  54. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  55.  
  56. $this->page_title = 'WHOIS';
  57. $this->tpl_name = 'simple_body';
  58.  
  59. $user_ip = request_var('user_ip', '');
  60. $domain = gethostbyaddr($user_ip);
  61. $ipwhois = user_ipwhois($user_ip);
  62.  
  63. $template->assign_vars(array(
  64. 'MESSAGE_TITLE' => sprintf($user->lang['IP_WHOIS_FOR'], $domain),
  65. 'MESSAGE_TEXT' => nl2br($ipwhois))
  66. );
  67.  
  68. return;
  69. }
  70.  
  71. // Show user selection mask
  72. if (!$username && !$user_id)
  73. {
  74. $this->page_title = 'SELECT_USER';
  75.  
  76. $template->assign_vars(array(
  77. 'U_ACTION' => $this->u_action,
  78. 'ANONYMOUS_USER_ID' => ANONYMOUS,
  79.  
  80. 'S_SELECT_USER' => true,
  81. 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=select_user&amp;field=username&amp;select_single=true'),
  82. ));
  83.  
  84. return;
  85. }
  86.  
  87. if (!$user_id)
  88. {
  89. $sql = 'SELECT user_id
  90. FROM ' . USERS_TABLE . "
  91. WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
  92. $result = $db->sql_query($sql);
  93. $user_id = (int) $db->sql_fetchfield('user_id');
  94. $db->sql_freeresult($result);
  95.  
  96. if (!$user_id)
  97. {
  98. trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING);
  99. }
  100. }
  101.  
  102. // Generate content for all modes
  103. $sql = 'SELECT u.*, s.*
  104. FROM ' . USERS_TABLE . ' u
  105. LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id)
  106. WHERE u.user_id = ' . $user_id . '
  107. ORDER BY s.session_time DESC';
  108. $result = $db->sql_query_limit($sql, 1);
  109. $user_row = $db->sql_fetchrow($result);
  110. $db->sql_freeresult($result);
  111.  
  112. if (!$user_row)
  113. {
  114. trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING);
  115. }
  116.  
  117. // Generate overall "header" for user admin
  118. $s_form_options = '';
  119.  
  120. // Build modes dropdown list
  121. $sql = 'SELECT module_mode, module_auth
  122. FROM ' . MODULES_TABLE . "
  123. WHERE module_basename = 'users'
  124. AND module_enabled = 1
  125. AND module_class = 'acp'
  126. ORDER BY left_id, module_mode";
  127. $result = $db->sql_query($sql);
  128.  
  129. $dropdown_modes = array();
  130. while ($row = $db->sql_fetchrow($result))
  131. {
  132. if (!$this->p_master->module_auth($row['module_auth']))
  133. {
  134. continue;
  135. }
  136.  
  137. $dropdown_modes[$row['module_mode']] = true;
  138. }
  139. $db->sql_freeresult($result);
  140.  
  141. foreach ($dropdown_modes as $module_mode => $null)
  142. {
  143. $selected = ($mode == $module_mode) ? ' selected="selected"' : '';
  144. $s_form_options .= '<option value="' . $module_mode . '"' . $selected . '>' . $user->lang['ACP_USER_' . strtoupper($module_mode)] . '</option>';
  145. }
  146.  
  147. $template->assign_vars(array(
  148. 'U_BACK' => $this->u_action,
  149. 'U_MODE_SELECT' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&amp;u=$user_id"),
  150. 'U_ACTION' => $this->u_action . '&amp;u=' . $user_id,
  151. 'S_FORM_OPTIONS' => $s_form_options,
  152. 'MANAGED_USERNAME' => $user_row['username'])
  153. );
  154.  
  155. // Prevent normal users/admins change/view founders if they are not a founder by themselves
  156. if ($user->data['user_type'] != USER_FOUNDER && $user_row['user_type'] == USER_FOUNDER)
  157. {
  158. trigger_error($user->lang['NOT_MANAGE_FOUNDER'] . adm_back_link($this->u_action), E_USER_WARNING);
  159. }
  160.  
  161. switch ($mode)
  162. {
  163. case 'overview':
  164.  
  165. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  166.  
  167. $user->add_lang('acp/ban');
  168.  
  169. $delete = request_var('delete', 0);
  170. $delete_type = request_var('delete_type', '');
  171. $ip = request_var('ip', 'ip');
  172.  
  173. if ($submit)
  174. {
  175. // You can't delete the founder
  176. if ($delete && $user_row['user_type'] != USER_FOUNDER)
  177. {
  178. if (!$auth->acl_get('a_userdel'))
  179. {
  180. trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  181. }
  182.  
  183. // Check if the user wants to remove himself or the guest user account
  184. if ($user_id == ANONYMOUS)
  185. {
  186. trigger_error($user->lang['CANNOT_REMOVE_ANONYMOUS'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  187. }
  188.  
  189. if ($user_id == $user->data['user_id'])
  190. {
  191. trigger_error($user->lang['CANNOT_REMOVE_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  192. }
  193.  
  194. if ($delete_type)
  195. {
  196. if (confirm_box(true))
  197. {
  198. user_delete($delete_type, $user_id, $user_row['username']);
  199.  
  200. add_log('admin', 'LOG_USER_DELETED', $user_row['username']);
  201. trigger_error($user->lang['USER_DELETED'] . adm_back_link($this->u_action));
  202. }
  203. else
  204. {
  205. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  206. 'u' => $user_id,
  207. 'i' => $id,
  208. 'mode' => $mode,
  209. 'action' => $action,
  210. 'update' => true,
  211. 'delete' => 1,
  212. 'delete_type' => $delete_type))
  213. );
  214. }
  215. }
  216. else
  217. {
  218. trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  219. }
  220. }
  221.  
  222. // Handle quicktool actions
  223. switch ($action)
  224. {
  225. case 'banuser':
  226. case 'banemail':
  227. case 'banip':
  228.  
  229. if ($user_id == $user->data['user_id'])
  230. {
  231. trigger_error($user->lang['CANNOT_BAN_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  232. }
  233.  
  234. if ($user_id == ANONYMOUS)
  235. {
  236. trigger_error($user->lang['CANNOT_BAN_ANONYMOUS'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  237. }
  238.  
  239. if ($user_row['user_type'] == USER_FOUNDER)
  240. {
  241. trigger_error($user->lang['CANNOT_BAN_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  242. }
  243.  
  244. if (!check_form_key($form_name))
  245. {
  246. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  247. }
  248.  
  249. $ban = array();
  250.  
  251. switch ($action)
  252. {
  253. case 'banuser':
  254. $ban[] = $user_row['username'];
  255. $reason = 'USER_ADMIN_BAN_NAME_REASON';
  256. $log = 'LOG_USER_BAN_USER';
  257. break;
  258.  
  259. case 'banemail':
  260. $ban[] = $user_row['user_email'];
  261. $reason = 'USER_ADMIN_BAN_EMAIL_REASON';
  262. $log = 'LOG_USER_BAN_EMAIL';
  263. break;
  264.  
  265. case 'banip':
  266. $ban[] = $user_row['user_ip'];
  267.  
  268. $sql = 'SELECT DISTINCT poster_ip
  269. FROM ' . POSTS_TABLE . "
  270. WHERE poster_id = $user_id";
  271. $result = $db->sql_query($sql);
  272.  
  273. while ($row = $db->sql_fetchrow($result))
  274. {
  275. $ban[] = $row['poster_ip'];
  276. }
  277. $db->sql_freeresult($result);
  278.  
  279. $reason = 'USER_ADMIN_BAN_IP_REASON';
  280. $log = 'LOG_USER_BAN_IP';
  281. break;
  282. }
  283.  
  284. $ban_reason = utf8_normalize_nfc(request_var('ban_reason', $user->lang[$reason], true));
  285. $ban_give_reason = utf8_normalize_nfc(request_var('ban_give_reason', '', true));
  286.  
  287. // Log not used at the moment, we simply utilize the ban function.
  288. $result = user_ban(substr($action, 3), $ban, 0, 0, 0, $ban_reason, $ban_give_reason);
  289.  
  290. trigger_error((($result === false) ? $user->lang['BAN_ALREADY_ENTERED'] : $user->lang['BAN_SUCCESSFUL']) . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  291.  
  292. break;
  293.  
  294. case 'reactivate':
  295.  
  296. if ($user_id == $user->data['user_id'])
  297. {
  298. trigger_error($user->lang['CANNOT_FORCE_REACT_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  299. }
  300.  
  301. if (!check_form_key($form_name))
  302. {
  303. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  304. }
  305.  
  306. if ($user_row['user_type'] == USER_FOUNDER)
  307. {
  308. trigger_error($user->lang['CANNOT_FORCE_REACT_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  309. }
  310.  
  311. if ($user_row['user_type'] == USER_IGNORE)
  312. {
  313. trigger_error($user->lang['CANNOT_FORCE_REACT_BOT'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  314. }
  315.  
  316. if ($config['email_enable'])
  317. {
  318. include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
  319.  
  320. $server_url = generate_board_url();
  321.  
  322. $user_actkey = gen_rand_string(mt_rand(6, 10));
  323. $email_template = ($user_row['user_type'] == USER_NORMAL) ? 'user_reactivate_account' : 'user_resend_inactive';
  324.  
  325. if ($user_row['user_type'] == USER_NORMAL)
  326. {
  327. user_active_flip('deactivate', $user_id, INACTIVE_REMIND);
  328.  
  329. $sql = 'UPDATE ' . USERS_TABLE . "
  330. SET user_actkey = '" . $db->sql_escape($user_actkey) . "'
  331. WHERE user_id = $user_id";
  332. $db->sql_query($sql);
  333. }
  334. else
  335. {
  336. // Grabbing the last confirm key - we only send a reminder
  337. $sql = 'SELECT user_actkey
  338. FROM ' . USERS_TABLE . '
  339. WHERE user_id = ' . $user_id;
  340. $result = $db->sql_query($sql);
  341. $user_actkey = (string) $db->sql_fetchfield('user_actkey');
  342. $db->sql_freeresult($result);
  343. }
  344.  
  345. $messenger = new messenger(false);
  346.  
  347. $messenger->template($email_template, $user_row['user_lang']);
  348.  
  349. $messenger->to($user_row['user_email'], $user_row['username']);
  350.  
  351. $messenger->anti_abuse_headers($config, $user);
  352.  
  353. $messenger->assign_vars(array(
  354. 'WELCOME_MSG' => htmlspecialchars_decode(sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename'])),
  355. 'USERNAME' => htmlspecialchars_decode($user_row['username']),
  356. 'U_ACTIVATE' => "$server_url/ucp.$phpEx?mode=activate&u={$user_row['user_id']}&k=$user_actkey")
  357. );
  358.  
  359. $messenger->send(NOTIFY_EMAIL);
  360.  
  361. add_log('admin', 'LOG_USER_REACTIVATE', $user_row['username']);
  362. add_log('user', $user_id, 'LOG_USER_REACTIVATE_USER');
  363.  
  364. trigger_error($user->lang['FORCE_REACTIVATION_SUCCESS'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  365. }
  366.  
  367. break;
  368.  
  369. case 'active':
  370.  
  371. if ($user_id == $user->data['user_id'])
  372. {
  373. // It is only deactivation since the user is already activated (else he would not have reached this page)
  374. trigger_error($user->lang['CANNOT_DEACTIVATE_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  375. }
  376.  
  377. if (!check_form_key($form_name))
  378. {
  379. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  380. }
  381.  
  382. if ($user_row['user_type'] == USER_FOUNDER)
  383. {
  384. trigger_error($user->lang['CANNOT_DEACTIVATE_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  385. }
  386.  
  387. if ($user_row['user_type'] == USER_IGNORE)
  388. {
  389. trigger_error($user->lang['CANNOT_DEACTIVATE_BOT'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  390. }
  391.  
  392. user_active_flip('flip', $user_id);
  393.  
  394. if ($user_row['user_type'] == USER_INACTIVE)
  395. {
  396. if ($config['require_activation'] == USER_ACTIVATION_ADMIN)
  397. {
  398. include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
  399.  
  400. $messenger = new messenger(false);
  401.  
  402. $messenger->template('admin_welcome_activated', $user_row['user_lang']);
  403.  
  404. $messenger->to($user_row['user_email'], $user_row['username']);
  405.  
  406. $messenger->anti_abuse_headers($config, $user);
  407.  
  408. $messenger->assign_vars(array(
  409. 'USERNAME' => htmlspecialchars_decode($user_row['username']))
  410. );
  411.  
  412. $messenger->send(NOTIFY_EMAIL);
  413. }
  414. }
  415.  
  416. $message = ($user_row['user_type'] == USER_INACTIVE) ? 'USER_ADMIN_ACTIVATED' : 'USER_ADMIN_DEACTIVED';
  417. $log = ($user_row['user_type'] == USER_INACTIVE) ? 'LOG_USER_ACTIVE' : 'LOG_USER_INACTIVE';
  418.  
  419. add_log('admin', $log, $user_row['username']);
  420. add_log('user', $user_id, $log . '_USER');
  421.  
  422. trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  423.  
  424. break;
  425.  
  426. case 'delsig':
  427.  
  428. if (!check_form_key($form_name))
  429. {
  430. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  431. }
  432.  
  433. $sql_ary = array(
  434. 'user_sig' => '',
  435. 'user_sig_bbcode_uid' => '',
  436. 'user_sig_bbcode_bitfield' => ''
  437. );
  438.  
  439. $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
  440. WHERE user_id = $user_id";
  441. $db->sql_query($sql);
  442.  
  443. add_log('admin', 'LOG_USER_DEL_SIG', $user_row['username']);
  444. add_log('user', $user_id, 'LOG_USER_DEL_SIG_USER');
  445.  
  446. trigger_error($user->lang['USER_ADMIN_SIG_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  447.  
  448. break;
  449.  
  450. case 'delavatar':
  451.  
  452. if (!check_form_key($form_name))
  453. {
  454. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  455. }
  456.  
  457. $sql_ary = array(
  458. 'user_avatar' => '',
  459. 'user_avatar_type' => 0,
  460. 'user_avatar_width' => 0,
  461. 'user_avatar_height' => 0,
  462. );
  463.  
  464. $sql = 'UPDATE ' . USERS_TABLE . '
  465. SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
  466. WHERE user_id = $user_id";
  467. $db->sql_query($sql);
  468.  
  469. // Delete old avatar if present
  470. if ($user_row['user_avatar'] && $user_row['user_avatar_type'] != AVATAR_GALLERY)
  471. {
  472. avatar_delete('user', $user_row);
  473. }
  474.  
  475. add_log('admin', 'LOG_USER_DEL_AVATAR', $user_row['username']);
  476. add_log('user', $user_id, 'LOG_USER_DEL_AVATAR_USER');
  477.  
  478. trigger_error($user->lang['USER_ADMIN_AVATAR_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  479. break;
  480.  
  481. case 'delposts':
  482.  
  483. if (confirm_box(true))
  484. {
  485. // Delete posts, attachments, etc.
  486. delete_posts('poster_id', $user_id);
  487.  
  488. add_log('admin', 'LOG_USER_DEL_POSTS', $user_row['username']);
  489. trigger_error($user->lang['USER_POSTS_DELETED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  490. }
  491. else
  492. {
  493. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  494. 'u' => $user_id,
  495. 'i' => $id,
  496. 'mode' => $mode,
  497. 'action' => $action,
  498. 'update' => true))
  499. );
  500. }
  501.  
  502. break;
  503.  
  504. case 'delattach':
  505.  
  506. if (confirm_box(true))
  507. {
  508. delete_attachments('user', $user_id);
  509.  
  510. add_log('admin', 'LOG_USER_DEL_ATTACH', $user_row['username']);
  511. trigger_error($user->lang['USER_ATTACHMENTS_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  512. }
  513. else
  514. {
  515. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  516. 'u' => $user_id,
  517. 'i' => $id,
  518. 'mode' => $mode,
  519. 'action' => $action,
  520. 'update' => true))
  521. );
  522. }
  523.  
  524. break;
  525.  
  526. case 'deloutbox':
  527.  
  528. if (confirm_box(true))
  529. {
  530. $msg_ids = array();
  531. $lang = 'EMPTY';
  532.  
  533. $sql = 'SELECT msg_id
  534. FROM ' . PRIVMSGS_TO_TABLE . "
  535. WHERE author_id = $user_id
  536. AND folder_id = " . PRIVMSGS_OUTBOX;
  537. $result = $db->sql_query($sql);
  538.  
  539. if ($row = $db->sql_fetchrow($result))
  540. {
  541. if (!function_exists('delete_pm'))
  542. {
  543. include($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
  544. }
  545.  
  546. do
  547. {
  548. $msg_ids[] = (int) $row['msg_id'];
  549. }
  550. while ($row = $db->sql_fetchrow($result));
  551.  
  552. $db->sql_freeresult($result);
  553.  
  554. delete_pm($user_id, $msg_ids, PRIVMSGS_OUTBOX);
  555.  
  556. add_log('admin', 'LOG_USER_DEL_OUTBOX', $user_row['username']);
  557.  
  558. $lang = 'EMPTIED';
  559. }
  560. $db->sql_freeresult($result);
  561.  
  562. trigger_error($user->lang['USER_OUTBOX_' . $lang] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  563. }
  564. else
  565. {
  566. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  567. 'u' => $user_id,
  568. 'i' => $id,
  569. 'mode' => $mode,
  570. 'action' => $action,
  571. 'update' => true))
  572. );
  573. }
  574. break;
  575.  
  576. case 'moveposts':
  577.  
  578. if (!check_form_key($form_name))
  579. {
  580. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  581. }
  582.  
  583. $user->add_lang('acp/forums');
  584.  
  585. $new_forum_id = request_var('new_f', 0);
  586.  
  587. if (!$new_forum_id)
  588. {
  589. $this->page_title = 'USER_ADMIN_MOVE_POSTS';
  590.  
  591. $template->assign_vars(array(
  592. 'S_SELECT_FORUM' => true,
  593. 'U_ACTION' => $this->u_action . "&amp;action=$action&amp;u=$user_id",
  594. 'U_BACK' => $this->u_action . "&amp;u=$user_id",
  595. 'S_FORUM_OPTIONS' => make_forum_select(false, false, false, true))
  596. );
  597.  
  598. return;
  599. }
  600.  
  601. // Is the new forum postable to?
  602. $sql = 'SELECT forum_name, forum_type
  603. FROM ' . FORUMS_TABLE . "
  604. WHERE forum_id = $new_forum_id";
  605. $result = $db->sql_query($sql);
  606. $forum_info = $db->sql_fetchrow($result);
  607. $db->sql_freeresult($result);
  608.  
  609. if (!$forum_info)
  610. {
  611. trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  612. }
  613.  
  614. if ($forum_info['forum_type'] != FORUM_POST)
  615. {
  616. trigger_error($user->lang['MOVE_POSTS_NO_POSTABLE_FORUM'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  617. }
  618.  
  619. // Two stage?
  620. // Move topics comprising only posts from this user
  621. $topic_id_ary = $move_topic_ary = $move_post_ary = $new_topic_id_ary = array();
  622. $forum_id_ary = array($new_forum_id);
  623.  
  624. $sql = 'SELECT topic_id, COUNT(post_id) AS total_posts
  625. FROM ' . POSTS_TABLE . "
  626. WHERE poster_id = $user_id
  627. AND forum_id <> $new_forum_id
  628. GROUP BY topic_id";
  629. $result = $db->sql_query($sql);
  630.  
  631. while ($row = $db->sql_fetchrow($result))
  632. {
  633. $topic_id_ary[$row['topic_id']] = $row['total_posts'];
  634. }
  635. $db->sql_freeresult($result);
  636.  
  637. if (sizeof($topic_id_ary))
  638. {
  639. $sql = 'SELECT topic_id, forum_id, topic_title, topic_replies, topic_replies_real, topic_attachment
  640. FROM ' . TOPICS_TABLE . '
  641. WHERE ' . $db->sql_in_set('topic_id', array_keys($topic_id_ary));
  642. $result = $db->sql_query($sql);
  643.  
  644. while ($row = $db->sql_fetchrow($result))
  645. {
  646. if (max($row['topic_replies'], $row['topic_replies_real']) + 1 == $topic_id_ary[$row['topic_id']])
  647. {
  648. $move_topic_ary[] = $row['topic_id'];
  649. }
  650. else
  651. {
  652. $move_post_ary[$row['topic_id']]['title'] = $row['topic_title'];
  653. $move_post_ary[$row['topic_id']]['attach'] = ($row['topic_attachment']) ? 1 : 0;
  654. }
  655.  
  656. $forum_id_ary[] = $row['forum_id'];
  657. }
  658. $db->sql_freeresult($result);
  659. }
  660.  
  661. // Entire topic comprises posts by this user, move these topics
  662. if (sizeof($move_topic_ary))
  663. {
  664. move_topics($move_topic_ary, $new_forum_id, false);
  665. }
  666.  
  667. if (sizeof($move_post_ary))
  668. {
  669. // Create new topic
  670. // Update post_ids, report_ids, attachment_ids
  671. foreach ($move_post_ary as $topic_id => $post_ary)
  672. {
  673. // Create new topic
  674. $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
  675. 'topic_poster' => $user_id,
  676. 'topic_time' => time(),
  677. 'forum_id' => $new_forum_id,
  678. 'icon_id' => 0,
  679. 'topic_approved' => 1,
  680. 'topic_title' => $post_ary['title'],
  681. 'topic_first_poster_name' => $user_row['username'],
  682. 'topic_type' => POST_NORMAL,
  683. 'topic_time_limit' => 0,
  684. 'topic_attachment' => $post_ary['attach'])
  685. );
  686. $db->sql_query($sql);
  687.  
  688. $new_topic_id = $db->sql_nextid();
  689.  
  690. // Move posts
  691. $sql = 'UPDATE ' . POSTS_TABLE . "
  692. SET forum_id = $new_forum_id, topic_id = $new_topic_id
  693. WHERE topic_id = $topic_id
  694. AND poster_id = $user_id";
  695. $db->sql_query($sql);
  696.  
  697. if ($post_ary['attach'])
  698. {
  699. $sql = 'UPDATE ' . ATTACHMENTS_TABLE . "
  700. SET topic_id = $new_topic_id
  701. WHERE topic_id = $topic_id
  702. AND poster_id = $user_id";
  703. $db->sql_query($sql);
  704. }
  705.  
  706. $new_topic_id_ary[] = $new_topic_id;
  707. }
  708. }
  709.  
  710. $forum_id_ary = array_unique($forum_id_ary);
  711. $topic_id_ary = array_unique(array_merge(array_keys($topic_id_ary), $new_topic_id_ary));
  712.  
  713. if (sizeof($topic_id_ary))
  714. {
  715. sync('topic_reported', 'topic_id', $topic_id_ary);
  716. sync('topic', 'topic_id', $topic_id_ary);
  717. }
  718.  
  719. if (sizeof($forum_id_ary))
  720. {
  721. sync('forum', 'forum_id', $forum_id_ary, false, true);
  722. }
  723.  
  724.  
  725. add_log('admin', 'LOG_USER_MOVE_POSTS', $user_row['username'], $forum_info['forum_name']);
  726. add_log('user', $user_id, 'LOG_USER_MOVE_POSTS_USER', $forum_info['forum_name']);
  727.  
  728. trigger_error($user->lang['USER_POSTS_MOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  729.  
  730. break;
  731.  
  732. case 'leave_nr':
  733.  
  734. if (confirm_box(true))
  735. {
  736. remove_newly_registered($user_id, $user_row);
  737.  
  738. add_log('admin', 'LOG_USER_REMOVED_NR', $user_row['username']);
  739. trigger_error($user->lang['USER_LIFTED_NR'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  740. }
  741. else
  742. {
  743. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  744. 'u' => $user_id,
  745. 'i' => $id,
  746. 'mode' => $mode,
  747. 'action' => $action,
  748. 'update' => true))
  749. );
  750. }
  751.  
  752. break;
  753. }
  754.  
  755. // Handle registration info updates
  756. $data = array(
  757. 'username' => utf8_normalize_nfc(request_var('user', $user_row['username'], true)),
  758. 'user_founder' => request_var('user_founder', ($user_row['user_type'] == USER_FOUNDER) ? 1 : 0),
  759. 'email' => strtolower(request_var('user_email', $user_row['user_email'])),
  760. 'email_confirm' => strtolower(request_var('email_confirm', '')),
  761. 'new_password' => request_var('new_password', '', true),
  762. 'password_confirm' => request_var('password_confirm', '', true),
  763. );
  764.  
  765. // Validation data - we do not check the password complexity setting here
  766. $check_ary = array(
  767. 'new_password' => array(
  768. array('string', true, $config['min_pass_chars'], $config['max_pass_chars']),
  769. array('password')),
  770. 'password_confirm' => array('string', true, $config['min_pass_chars'], $config['max_pass_chars']),
  771. );
  772.  
  773. // Check username if altered
  774. if ($data['username'] != $user_row['username'])
  775. {
  776. $check_ary += array(
  777. 'username' => array(
  778. array('string', false, $config['min_name_chars'], $config['max_name_chars']),
  779. array('username', $user_row['username'])
  780. ),
  781. );
  782. }
  783.  
  784. // Check email if altered
  785. if ($data['email'] != $user_row['user_email'])
  786. {
  787. $check_ary += array(
  788. 'email' => array(
  789. array('string', false, 6, 60),
  790. array('email', $user_row['user_email'])
  791. ),
  792. 'email_confirm' => array('string', true, 6, 60)
  793. );
  794. }
  795.  
  796. $error = validate_data($data, $check_ary);
  797.  
  798. if ($data['new_password'] && $data['password_confirm'] != $data['new_password'])
  799. {
  800. $error[] = 'NEW_PASSWORD_ERROR';
  801. }
  802.  
  803. if ($data['email'] != $user_row['user_email'] && $data['email_confirm'] != $data['email'])
  804. {
  805. $error[] = 'NEW_EMAIL_ERROR';
  806. }
  807.  
  808. if (!check_form_key($form_name))
  809. {
  810. $error[] = 'FORM_INVALID';
  811. }
  812.  
  813. // Which updates do we need to do?
  814. $update_username = ($user_row['username'] != $data['username']) ? $data['username'] : false;
  815. $update_password = ($data['new_password'] && !phpbb_check_hash($data['new_password'], $user_row['user_password'])) ? true : false;
  816. $update_email = ($data['email'] != $user_row['user_email']) ? $data['email'] : false;
  817.  
  818. if (!sizeof($error))
  819. {
  820. $sql_ary = array();
  821.  
  822. if ($user_row['user_type'] != USER_FOUNDER || $user->data['user_type'] == USER_FOUNDER)
  823. {
  824. // Only allow founders updating the founder status...
  825. if ($user->data['user_type'] == USER_FOUNDER)
  826. {
  827. // Setting a normal member to be a founder
  828. if ($data['user_founder'] && $user_row['user_type'] != USER_FOUNDER)
  829. {
  830. // Make sure the user is not setting an Inactive or ignored user to be a founder
  831. if ($user_row['user_type'] == USER_IGNORE)
  832. {
  833. trigger_error($user->lang['CANNOT_SET_FOUNDER_IGNORED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  834. }
  835.  
  836. if ($user_row['user_type'] == USER_INACTIVE)
  837. {
  838. trigger_error($user->lang['CANNOT_SET_FOUNDER_INACTIVE'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  839. }
  840.  
  841. $sql_ary['user_type'] = USER_FOUNDER;
  842. }
  843. else if (!$data['user_founder'] && $user_row['user_type'] == USER_FOUNDER)
  844. {
  845. // Check if at least one founder is present
  846. $sql = 'SELECT user_id
  847. FROM ' . USERS_TABLE . '
  848. WHERE user_type = ' . USER_FOUNDER . '
  849. AND user_id <> ' . $user_id;
  850. $result = $db->sql_query_limit($sql, 1);
  851. $row = $db->sql_fetchrow($result);
  852. $db->sql_freeresult($result);
  853.  
  854. if ($row)
  855. {
  856. $sql_ary['user_type'] = USER_NORMAL;
  857. }
  858. else
  859. {
  860. trigger_error($user->lang['AT_LEAST_ONE_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  861. }
  862. }
  863. }
  864. }
  865.  
  866. if ($update_username !== false)
  867. {
  868. $sql_ary['username'] = $update_username;
  869. $sql_ary['username_clean'] = utf8_clean_string($update_username);
  870.  
  871. add_log('user', $user_id, 'LOG_USER_UPDATE_NAME', $user_row['username'], $update_username);
  872. }
  873.  
  874. if ($update_email !== false)
  875. {
  876. $sql_ary += array(
  877. 'user_email' => $update_email,
  878. 'user_email_hash' => phpbb_email_hash($update_email),
  879. );
  880.  
  881. add_log('user', $user_id, 'LOG_USER_UPDATE_EMAIL', $user_row['username'], $user_row['user_email'], $update_email);
  882. }
  883.  
  884. if ($update_password)
  885. {
  886. $sql_ary += array(
  887. 'user_password' => phpbb_hash($data['new_password']),
  888. 'user_passchg' => time(),
  889. 'user_pass_convert' => 0,
  890. );
  891.  
  892. $user->reset_login_keys($user_id);
  893. add_log('user', $user_id, 'LOG_USER_NEW_PASSWORD', $user_row['username']);
  894. }
  895.  
  896. if (sizeof($sql_ary))
  897. {
  898. $sql = 'UPDATE ' . USERS_TABLE . '
  899. SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
  900. WHERE user_id = ' . $user_id;
  901. $db->sql_query($sql);
  902. }
  903.  
  904. if ($update_username)
  905. {
  906. user_update_name($user_row['username'], $update_username);
  907. }
  908.  
  909. // Let the users permissions being updated
  910. $auth->acl_clear_prefetch($user_id);
  911.  
  912. add_log('admin', 'LOG_USER_USER_UPDATE', $data['username']);
  913.  
  914. trigger_error($user->lang['USER_OVERVIEW_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  915. }
  916.  
  917. // Replace "error" strings with their real, localised form
  918. $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
  919. }
  920.  
  921. if ($user_id == $user->data['user_id'])
  922. {
  923. $quick_tool_ary = array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH', 'deloutbox' => 'DEL_OUTBOX');
  924. if ($user_row['user_new'])
  925. {
  926. $quick_tool_ary['leave_nr'] = 'LEAVE_NR';
  927. }
  928. }
  929. else
  930. {
  931. $quick_tool_ary = array();
  932.  
  933. if ($user_row['user_type'] != USER_FOUNDER)
  934. {
  935. $quick_tool_ary += array('banuser' => 'BAN_USER', 'banemail' => 'BAN_EMAIL', 'banip' => 'BAN_IP');
  936. }
  937.  
  938. if ($user_row['user_type'] != USER_FOUNDER && $user_row['user_type'] != USER_IGNORE)
  939. {
  940. $quick_tool_ary += array('active' => (($user_row['user_type'] == USER_INACTIVE) ? 'ACTIVATE' : 'DEACTIVATE'));
  941. }
  942.  
  943. $quick_tool_ary += array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH', 'deloutbox' => 'DEL_OUTBOX');
  944.  
  945. if ($config['email_enable'] && ($user_row['user_type'] == USER_NORMAL || $user_row['user_type'] == USER_INACTIVE))
  946. {
  947. $quick_tool_ary['reactivate'] = 'FORCE';
  948. }
  949.  
  950. if ($user_row['user_new'])
  951. {
  952. $quick_tool_ary['leave_nr'] = 'LEAVE_NR';
  953. }
  954. }
  955.  
  956. $s_action_options = '<option class="sep" value="">' . $user->lang['SELECT_OPTION'] . '</option>';
  957. foreach ($quick_tool_ary as $value => $lang)
  958. {
  959. $s_action_options .= '<option value="' . $value . '">' . $user->lang['USER_ADMIN_' . $lang] . '</option>';
  960. }
  961.  
  962. if ($config['load_onlinetrack'])
  963. {
  964. $sql = 'SELECT MAX(session_time) AS session_time, MIN(session_viewonline) AS session_viewonline
  965. FROM ' . SESSIONS_TABLE . "
  966. WHERE session_user_id = $user_id";
  967. $result = $db->sql_query($sql);
  968. $row = $db->sql_fetchrow($result);
  969. $db->sql_freeresult($result);
  970.  
  971. $user_row['session_time'] = (isset($row['session_time'])) ? $row['session_time'] : 0;
  972. $user_row['session_viewonline'] = (isset($row['session_viewonline'])) ? $row['session_viewonline'] : 0;
  973. unset($row);
  974. }
  975.  
  976. $last_visit = (!empty($user_row['session_time'])) ? $user_row['session_time'] : $user_row['user_lastvisit'];
  977.  
  978. $inactive_reason = '';
  979. if ($user_row['user_type'] == USER_INACTIVE)
  980. {
  981. $inactive_reason = $user->lang['INACTIVE_REASON_UNKNOWN'];
  982.  
  983. switch ($user_row['user_inactive_reason'])
  984. {
  985. case INACTIVE_REGISTER:
  986. $inactive_reason = $user->lang['INACTIVE_REASON_REGISTER'];
  987. break;
  988.  
  989. case INACTIVE_PROFILE:
  990. $inactive_reason = $user->lang['INACTIVE_REASON_PROFILE'];
  991. break;
  992.  
  993. case INACTIVE_MANUAL:
  994. $inactive_reason = $user->lang['INACTIVE_REASON_MANUAL'];
  995. break;
  996.  
  997. case INACTIVE_REMIND:
  998. $inactive_reason = $user->lang['INACTIVE_REASON_REMIND'];
  999. break;
  1000. }
  1001. }
  1002.  
  1003. // Posts in Queue
  1004. $sql = 'SELECT COUNT(post_id) as posts_in_queue
  1005. FROM ' . POSTS_TABLE . '
  1006. WHERE poster_id = ' . $user_id . '
  1007. AND post_approved = 0';
  1008. $result = $db->sql_query($sql);
  1009. $user_row['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue');
  1010. $db->sql_freeresult($result);
  1011.  
  1012. $sql = 'SELECT post_id
  1013. FROM ' . POSTS_TABLE . '
  1014. WHERE poster_id = '. $user_id;
  1015. $result = $db->sql_query_limit($sql, 1);
  1016. $user_row['user_has_posts'] = (bool) $db->sql_fetchfield('post_id');
  1017. $db->sql_freeresult($result);
  1018.  
  1019. $template->assign_vars(array(
  1020. 'L_NAME_CHARS_EXPLAIN' => sprintf($user->lang[$config['allow_name_chars'] . '_EXPLAIN'], $config['min_name_chars'], $config['max_name_chars']),
  1021. 'L_CHANGE_PASSWORD_EXPLAIN' => sprintf($user->lang[$config['pass_complex'] . '_EXPLAIN'], $config['min_pass_chars'], $config['max_pass_chars']),
  1022. 'L_POSTS_IN_QUEUE' => $user->lang('NUM_POSTS_IN_QUEUE', $user_row['posts_in_queue']),
  1023. 'S_FOUNDER' => ($user->data['user_type'] == USER_FOUNDER) ? true : false,
  1024.  
  1025. 'S_OVERVIEW' => true,
  1026. 'S_USER_IP' => ($user_row['user_ip']) ? true : false,
  1027. 'S_USER_FOUNDER' => ($user_row['user_type'] == USER_FOUNDER) ? true : false,
  1028. 'S_ACTION_OPTIONS' => $s_action_options,
  1029. 'S_OWN_ACCOUNT' => ($user_id == $user->data['user_id']) ? true : false,
  1030. 'S_USER_INACTIVE' => ($user_row['user_type'] == USER_INACTIVE) ? true : false,
  1031.  
  1032. 'U_SHOW_IP' => $this->u_action . "&amp;u=$user_id&amp;ip=" . (($ip == 'ip') ? 'hostname' : 'ip'),
  1033. 'U_WHOIS' => $this->u_action . "&amp;action=whois&amp;user_ip={$user_row['user_ip']}",
  1034. 'U_MCP_QUEUE' => ($auth->acl_getf_global('m_approve')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue', true, $user->session_id) : '',
  1035.  
  1036. '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')) : '',
  1037.  
  1038. 'POSTS_IN_QUEUE' => $user_row['posts_in_queue'],
  1039. 'USER' => $user_row['username'],
  1040. 'USER_REGISTERED' => $user->format_date($user_row['user_regdate']),
  1041. 'REGISTERED_IP' => ($ip == 'hostname') ? gethostbyaddr($user_row['user_ip']) : $user_row['user_ip'],
  1042. 'USER_LASTACTIVE' => ($last_visit) ? $user->format_date($last_visit) : ' - ',
  1043. 'USER_EMAIL' => $user_row['user_email'],
  1044. 'USER_WARNINGS' => $user_row['user_warnings'],
  1045. 'USER_POSTS' => $user_row['user_posts'],
  1046. 'USER_HAS_POSTS' => $user_row['user_has_posts'],
  1047. 'USER_INACTIVE_REASON' => $inactive_reason,
  1048. ));
  1049.  
  1050. break;
  1051.  
  1052. case 'feedback':
  1053.  
  1054. $user->add_lang('mcp');
  1055.  
  1056. // Set up general vars
  1057. $start = request_var('start', 0);
  1058. $deletemark = (isset($_POST['delmarked'])) ? true : false;
  1059. $deleteall = (isset($_POST['delall'])) ? true : false;
  1060. $marked = request_var('mark', array(0));
  1061. $message = utf8_normalize_nfc(request_var('message', '', true));
  1062.  
  1063. // Sort keys
  1064. $sort_days = request_var('st', 0);
  1065. $sort_key = request_var('sk', 't');
  1066. $sort_dir = request_var('sd', 'd');
  1067.  
  1068. // Delete entries if requested and able
  1069. if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs'))
  1070. {
  1071. if (!check_form_key($form_name))
  1072. {
  1073. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  1074. }
  1075.  
  1076. $where_sql = '';
  1077. if ($deletemark && $marked)
  1078. {
  1079. $sql_in = array();
  1080. foreach ($marked as $mark)
  1081. {
  1082. $sql_in[] = $mark;
  1083. }
  1084. $where_sql = ' AND ' . $db->sql_in_set('log_id', $sql_in);
  1085. unset($sql_in);
  1086. }
  1087.  
  1088. if ($where_sql || $deleteall)
  1089. {
  1090. $sql = 'DELETE FROM ' . LOG_TABLE . '
  1091. WHERE log_type = ' . LOG_USERS . "
  1092. AND reportee_id = $user_id
  1093. $where_sql";
  1094. $db->sql_query($sql);
  1095.  
  1096. add_log('admin', 'LOG_CLEAR_USER', $user_row['username']);
  1097. }
  1098. }
  1099.  
  1100. if ($submit && $message)
  1101. {
  1102. if (!check_form_key($form_name))
  1103. {
  1104. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  1105. }
  1106.  
  1107. add_log('admin', 'LOG_USER_FEEDBACK', $user_row['username']);
  1108. add_log('mod', 0, 0, 'LOG_USER_FEEDBACK', $user_row['username']);
  1109. add_log('user', $user_id, 'LOG_USER_GENERAL', $message);
  1110.  
  1111. trigger_error($user->lang['USER_FEEDBACK_ADDED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  1112. }
  1113.  
  1114. // Sorting
  1115. $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']);
  1116. $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
  1117. $sort_by_sql = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
  1118.  
  1119. $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
  1120. 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);
  1121.  
  1122. // Define where and sort sql for use in displaying logs
  1123. $sql_where = ($sort_days) ? (time() - ($sort_days * 86400)) : 0;
  1124. $sql_sort = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
  1125.  
  1126. // Grab log data
  1127. $log_data = array();
  1128. $log_count = 0;
  1129. $start = view_log('user', $log_data, $log_count, $config['topics_per_page'], $start, 0, 0, $user_id, $sql_where, $sql_sort);
  1130.  
  1131. $template->assign_vars(array(
  1132. 'S_FEEDBACK' => true,
  1133. 'S_ON_PAGE' => on_page($log_count, $config['topics_per_page'], $start),
  1134. 'PAGINATION' => generate_pagination($this->u_action . "&amp;u=$user_id&amp;$u_sort_param", $log_count, $config['topics_per_page'], $start, true),
  1135.  
  1136. 'S_LIMIT_DAYS' => $s_limit_days,
  1137. 'S_SORT_KEY' => $s_sort_key,
  1138. 'S_SORT_DIR' => $s_sort_dir,
  1139. 'S_CLEARLOGS' => $auth->acl_get('a_clearlogs'))
  1140. );
  1141.  
  1142. foreach ($log_data as $row)
  1143. {
  1144. $template->assign_block_vars('log', array(
  1145. 'USERNAME' => $row['username_full'],
  1146. 'IP' => $row['ip'],
  1147. 'DATE' => $user->format_date($row['time']),
  1148. 'ACTION' => nl2br($row['action']),
  1149. 'ID' => $row['id'])
  1150. );
  1151. }
  1152.  
  1153. break;
  1154.  
  1155. case 'warnings':
  1156. $user->add_lang('mcp');
  1157.  
  1158. // Set up general vars
  1159. $start = request_var('start', 0);
  1160. $deletemark = (isset($_POST['delmarked'])) ? true : false;
  1161. $deleteall = (isset($_POST['delall'])) ? true : false;
  1162. $confirm = (isset($_POST['confirm'])) ? true : false;
  1163. $marked = request_var('mark', array(0));
  1164. $message = utf8_normalize_nfc(request_var('message', '', true));
  1165.  
  1166. // Sort keys
  1167. $sort_days = request_var('st', 0);
  1168. $sort_key = request_var('sk', 't');
  1169. $sort_dir = request_var('sd', 'd');
  1170.  
  1171. // Delete entries if requested and able
  1172. if ($deletemark || $deleteall || $confirm)
  1173. {
  1174. if (confirm_box(true))
  1175. {
  1176. $where_sql = '';
  1177. $deletemark = request_var('delmarked', 0);
  1178. $deleteall = request_var('delall', 0);
  1179. if ($deletemark && $marked)
  1180. {
  1181. $where_sql = ' AND ' . $db->sql_in_set('warning_id', array_values($marked));
  1182. }
  1183.  
  1184. if ($where_sql || $deleteall)
  1185. {
  1186. $sql = 'DELETE FROM ' . WARNINGS_TABLE . "
  1187. WHERE user_id = $user_id
  1188. $where_sql";
  1189. $db->sql_query($sql);
  1190.  
  1191. if ($deleteall)
  1192. {
  1193. $log_warnings = $deleted_warnings = 0;
  1194. }
  1195. else
  1196. {
  1197. $num_warnings = (int) $db->sql_affectedrows();
  1198. $deleted_warnings = ' user_warnings - ' . $num_warnings;
  1199. $log_warnings = ($num_warnings > 2) ? 2 : $num_warnings;
  1200. }
  1201.  
  1202. $sql = 'UPDATE ' . USERS_TABLE . "
  1203. SET user_warnings = $deleted_warnings
  1204. WHERE user_id = $user_id";
  1205. $db->sql_query($sql);
  1206.  
  1207. switch ($log_warnings)
  1208. {
  1209. case 2:
  1210. add_log('admin', 'LOG_WARNINGS_DELETED', $user_row['username'], $num_warnings);
  1211. break;
  1212. case 1:
  1213. add_log('admin', 'LOG_WARNING_DELETED', $user_row['username']);
  1214. break;
  1215. default:
  1216. add_log('admin', 'LOG_WARNINGS_DELETED_ALL', $user_row['username']);
  1217. break;
  1218. }
  1219. }
  1220. }
  1221. else
  1222. {
  1223. $s_hidden_fields = array(
  1224. 'i' => $id,
  1225. 'mode' => $mode,
  1226. 'u' => $user_id,
  1227. 'mark' => $marked,
  1228. );
  1229. if (isset($_POST['delmarked']))
  1230. {
  1231. $s_hidden_fields['delmarked'] = 1;
  1232. }
  1233. if (isset($_POST['delall']))
  1234. {
  1235. $s_hidden_fields['delall'] = 1;
  1236. }
  1237. if (isset($_POST['delall']) || (isset($_POST['delmarked']) && sizeof($marked)))
  1238. {
  1239. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields));
  1240. }
  1241. }
  1242. }
  1243.  
  1244. $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
  1245. FROM ' . WARNINGS_TABLE . ' w
  1246. LEFT JOIN ' . LOG_TABLE . ' l
  1247. ON (w.log_id = l.log_id)
  1248. LEFT JOIN ' . USERS_TABLE . ' m
  1249. ON (l.user_id = m.user_id)
  1250. WHERE w.user_id = ' . $user_id . '
  1251. ORDER BY w.warning_time DESC';
  1252. $result = $db->sql_query($sql);
  1253.  
  1254. while ($row = $db->sql_fetchrow($result))
  1255. {
  1256. if (!$row['log_operation'])
  1257. {
  1258. // We do not have a log-entry anymore, so there is no data available
  1259. $row['action'] = $user->lang['USER_WARNING_LOG_DELETED'];
  1260. }
  1261. else
  1262. {
  1263. $row['action'] = (isset($user->lang[$row['log_operation']])) ? $user->lang[$row['log_operation']] : '{' . ucfirst(str_replace('_', ' ', $row['log_operation'])) . '}';
  1264. if (!empty($row['log_data']))
  1265. {
  1266. $log_data_ary = @unserialize($row['log_data']);
  1267. $log_data_ary = ($log_data_ary === false) ? array() : $log_data_ary;
  1268.  
  1269. if (isset($user->lang[$row['log_operation']]))
  1270. {
  1271. // Check if there are more occurrences of % than arguments, if there are we fill out the arguments array
  1272. // It doesn't matter if we add more arguments than placeholders
  1273. if ((substr_count($row['action'], '%') - sizeof($log_data_ary)) > 0)
  1274. {
  1275. $log_data_ary = array_merge($log_data_ary, array_fill(0, substr_count($row['action'], '%') - sizeof($log_data_ary), ''));
  1276. }
  1277. $row['action'] = vsprintf($row['action'], $log_data_ary);
  1278. $row['action'] = bbcode_nl2br(censor_text($row['action']));
  1279. }
  1280. else if (!empty($log_data_ary))
  1281. {
  1282. $row['action'] .= '<br />' . implode('', $log_data_ary);
  1283. }
  1284. }
  1285. }
  1286.  
  1287.  
  1288. $template->assign_block_vars('warn', array(
  1289. 'ID' => $row['warning_id'],
  1290. 'USERNAME' => ($row['log_operation']) ? get_username_string('full', $row['mod_user_id'], $row['mod_username'], $row['mod_user_colour']) : '-',
  1291. 'ACTION' => make_clickable($row['action']),
  1292. 'DATE' => $user->format_date($row['warning_time']),
  1293. ));
  1294. }
  1295. $db->sql_freeresult($result);
  1296.  
  1297. $template->assign_vars(array(
  1298. 'S_WARNINGS' => true,
  1299. ));
  1300.  
  1301. break;
  1302.  
  1303. case 'profile':
  1304.  
  1305. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  1306. include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
  1307.  
  1308. $cp = new custom_profile();
  1309.  
  1310. $cp_data = $cp_error = array();
  1311.  
  1312. $sql = 'SELECT lang_id
  1313. FROM ' . LANG_TABLE . "
  1314. WHERE lang_iso = '" . $db->sql_escape($user->data['user_lang']) . "'";
  1315. $result = $db->sql_query($sql);
  1316. $row = $db->sql_fetchrow($result);
  1317. $db->sql_freeresult($result);
  1318.  
  1319. $user_row['iso_lang_id'] = $row['lang_id'];
  1320.  
  1321. $data = array(
  1322. 'icq' => request_var('icq', $user_row['user_icq']),
  1323. 'aim' => request_var('aim', $user_row['user_aim']),
  1324. 'msn' => request_var('msn', $user_row['user_msnm']),
  1325. 'yim' => request_var('yim', $user_row['user_yim']),
  1326. 'jabber' => utf8_normalize_nfc(request_var('jabber', $user_row['user_jabber'], true)),
  1327. 'website' => request_var('website', $user_row['user_website']),
  1328. 'location' => utf8_normalize_nfc(request_var('location', $user_row['user_from'], true)),
  1329. 'occupation' => utf8_normalize_nfc(request_var('occupation', $user_row['user_occ'], true)),
  1330. 'interests' => utf8_normalize_nfc(request_var('interests', $user_row['user_interests'], true)),
  1331. 'bday_day' => 0,
  1332. 'bday_month' => 0,
  1333. 'bday_year' => 0,
  1334. );
  1335.  
  1336. if ($user_row['user_birthday'])
  1337. {
  1338. list($data['bday_day'], $data['bday_month'], $data['bday_year']) = explode('-', $user_row['user_birthday']);
  1339. }
  1340.  
  1341. $data['bday_day'] = request_var('bday_day', $data['bday_day']);
  1342. $data['bday_month'] = request_var('bday_month', $data['bday_month']);
  1343. $data['bday_year'] = request_var('bday_year', $data['bday_year']);
  1344. $data['user_birthday'] = sprintf('%2d-%2d-%4d', $data['bday_day'], $data['bday_month'], $data['bday_year']);
  1345.  
  1346.  
  1347. if ($submit)
  1348. {
  1349. $error = validate_data($data, array(
  1350. 'icq' => array(
  1351. array('string', true, 3, 15),
  1352. array('match', true, '#^[0-9]+$#i')),
  1353. 'aim' => array('string', true, 3, 255),
  1354. 'msn' => array('string', true, 5, 255),
  1355. 'jabber' => array(
  1356. array('string', true, 5, 255),
  1357. array('jabber')),
  1358. 'yim' => array('string', true, 5, 255),
  1359. 'website' => array(
  1360. array('string', true, 12, 255),
  1361. array('match', true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i')),
  1362. 'location' => array('string', true, 2, 100),
  1363. 'occupation' => array('string', true, 2, 500),
  1364. 'interests' => array('string', true, 2, 500),
  1365. 'bday_day' => array('num', true, 1, 31),
  1366. 'bday_month' => array('num', true, 1, 12),
  1367. 'bday_year' => array('num', true, 1901, gmdate('Y', time())),
  1368. 'user_birthday' => array('date', true),
  1369. ));
  1370.  
  1371. // validate custom profile fields
  1372. $cp->submit_cp_field('profile', $user_row['iso_lang_id'], $cp_data, $cp_error);
  1373.  
  1374. if (sizeof($cp_error))
  1375. {
  1376. $error = array_merge($error, $cp_error);
  1377. }
  1378. if (!check_form_key($form_name))
  1379. {
  1380. $error[] = 'FORM_INVALID';
  1381. }
  1382.  
  1383. if (!sizeof($error))
  1384. {
  1385. $sql_ary = array(
  1386. 'user_icq' => $data['icq'],
  1387. 'user_aim' => $data['aim'],
  1388. 'user_msnm' => $data['msn'],
  1389. 'user_yim' => $data['yim'],
  1390. 'user_jabber' => $data['jabber'],
  1391. 'user_website' => $data['website'],
  1392. 'user_from' => $data['location'],
  1393. 'user_occ' => $data['occupation'],
  1394. 'user_interests'=> $data['interests'],
  1395. 'user_birthday' => $data['user_birthday'],
  1396. );
  1397.  
  1398. $sql = 'UPDATE ' . USERS_TABLE . '
  1399. SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
  1400. WHERE user_id = $user_id";
  1401. $db->sql_query($sql);
  1402.  
  1403. // Update Custom Fields
  1404. $cp->update_profile_field_data($user_id, $cp_data);
  1405.  
  1406. trigger_error($user->lang['USER_PROFILE_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  1407. }
  1408.  
  1409. // Replace "error" strings with their real, localised form
  1410. $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
  1411. }
  1412.  
  1413. $s_birthday_day_options = '<option value="0"' . ((!$data['bday_day']) ? ' selected="selected"' : '') . '>--</option>';
  1414. for ($i = 1; $i < 32; $i++)
  1415. {
  1416. $selected = ($i == $data['bday_day']) ? ' selected="selected"' : '';
  1417. $s_birthday_day_options .= "<option value=\"$i\"$selected>$i</option>";
  1418. }
  1419.  
  1420. $s_birthday_month_options = '<option value="0"' . ((!$data['bday_month']) ? ' selected="selected"' : '') . '>--</option>';
  1421. for ($i = 1; $i < 13; $i++)
  1422. {
  1423. $selected = ($i == $data['bday_month']) ? ' selected="selected"' : '';
  1424. $s_birthday_month_options .= "<option value=\"$i\"$selected>$i</option>";
  1425. }
  1426. $s_birthday_year_options = '';
  1427.  
  1428. $now = getdate();
  1429. $s_birthday_year_options = '<option value="0"' . ((!$data['bday_year']) ? ' selected="selected"' : '') . '>--</option>';
  1430. for ($i = $now['year'] - 100; $i <= $now['year']; $i++)
  1431. {
  1432. $selected = ($i == $data['bday_year']) ? ' selected="selected"' : '';
  1433. $s_birthday_year_options .= "<option value=\"$i\"$selected>$i</option>";
  1434. }
  1435. unset($now);
  1436.  
  1437. $template->assign_vars(array(
  1438. 'ICQ' => $data['icq'],
  1439. 'YIM' => $data['yim'],
  1440. 'AIM' => $data['aim'],
  1441. 'MSN' => $data['msn'],
  1442. 'JABBER' => $data['jabber'],
  1443. 'WEBSITE' => $data['website'],
  1444. 'LOCATION' => $data['location'],
  1445. 'OCCUPATION' => $data['occupation'],
  1446. 'INTERESTS' => $data['interests'],
  1447.  
  1448. 'S_BIRTHDAY_DAY_OPTIONS' => $s_birthday_day_options,
  1449. 'S_BIRTHDAY_MONTH_OPTIONS' => $s_birthday_month_options,
  1450. 'S_BIRTHDAY_YEAR_OPTIONS' => $s_birthday_year_options,
  1451.  
  1452. 'S_PROFILE' => true)
  1453. );
  1454.  
  1455. // Get additional profile fields and assign them to the template block var 'profile_fields'
  1456. $user->get_profile_fields($user_id);
  1457.  
  1458. $cp->generate_profile_fields('profile', $user_row['iso_lang_id']);
  1459.  
  1460. break;
  1461.  
  1462. case 'prefs':
  1463.  
  1464. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  1465.  
  1466. $data = array(
  1467. 'dateformat' => utf8_normalize_nfc(request_var('dateformat', $user_row['user_dateformat'], true)),
  1468. 'lang' => basename(request_var('lang', $user_row['user_lang'])),
  1469. 'tz' => request_var('tz', (float) $user_row['user_timezone']),
  1470. 'style' => request_var('style', $user_row['user_style']),
  1471. 'dst' => request_var('dst', $user_row['user_dst']),
  1472. 'viewemail' => request_var('viewemail', $user_row['user_allow_viewemail']),
  1473. 'massemail' => request_var('massemail', $user_row['user_allow_massemail']),
  1474. 'hideonline' => request_var('hideonline', !$user_row['user_allow_viewonline']),
  1475. 'notifymethod' => request_var('notifymethod', $user_row['user_notify_type']),
  1476. 'notifypm' => request_var('notifypm', $user_row['user_notify_pm']),
  1477. 'popuppm' => request_var('popuppm', $this->optionget($user_row, 'popuppm')),
  1478. 'allowpm' => request_var('allowpm', $user_row['user_allow_pm']),
  1479.  
  1480. 'topic_sk' => request_var('topic_sk', ($user_row['user_topic_sortby_type']) ? $user_row['user_topic_sortby_type'] : 't'),
  1481. 'topic_sd' => request_var('topic_sd', ($user_row['user_topic_sortby_dir']) ? $user_row['user_topic_sortby_dir'] : 'd'),
  1482. 'topic_st' => request_var('topic_st', ($user_row['user_topic_show_days']) ? $user_row['user_topic_show_days'] : 0),
  1483.  
  1484. 'post_sk' => request_var('post_sk', ($user_row['user_post_sortby_type']) ? $user_row['user_post_sortby_type'] : 't'),
  1485. 'post_sd' => request_var('post_sd', ($user_row['user_post_sortby_dir']) ? $user_row['user_post_sortby_dir'] : 'a'),
  1486. 'post_st' => request_var('post_st', ($user_row['user_post_show_days']) ? $user_row['user_post_show_days'] : 0),
  1487.  
  1488. 'view_images' => request_var('view_images', $this->optionget($user_row, 'viewimg')),
  1489. 'view_flash' => request_var('view_flash', $this->optionget($user_row, 'viewflash')),
  1490. 'view_smilies' => request_var('view_smilies', $this->optionget($user_row, 'viewsmilies')),
  1491. 'view_sigs' => request_var('view_sigs', $this->optionget($user_row, 'viewsigs')),
  1492. 'view_avatars' => request_var('view_avatars', $this->optionget($user_row, 'viewavatars')),
  1493. 'view_wordcensor' => request_var('view_wordcensor', $this->optionget($user_row, 'viewcensors')),
  1494.  
  1495. 'bbcode' => request_var('bbcode', $this->optionget($user_row, 'bbcode')),
  1496. 'smilies' => request_var('smilies', $this->optionget($user_row, 'smilies')),
  1497. 'sig' => request_var('sig', $this->optionget($user_row, 'attachsig')),
  1498. 'notify' => request_var('notify', $user_row['user_notify']),
  1499. );
  1500.  
  1501. if ($submit)
  1502. {
  1503. $error = validate_data($data, array(
  1504. 'dateformat' => array('string', false, 1, 30),
  1505. 'lang' => array('match', false, '#^[a-z_\-]{2,}$#i'),
  1506. 'tz' => array('num', false, -14, 14),
  1507.  
  1508. 'topic_sk' => array('string', false, 1, 1),
  1509. 'topic_sd' => array('string', false, 1, 1),
  1510. 'post_sk' => array('string', false, 1, 1),
  1511. 'post_sd' => array('string', false, 1, 1),
  1512. ));
  1513.  
  1514. if (!check_form_key($form_name))
  1515. {
  1516. $error[] = 'FORM_INVALID';
  1517. }
  1518.  
  1519. if (!sizeof($error))
  1520. {
  1521. $this->optionset($user_row, 'popuppm', $data['popuppm']);
  1522. $this->optionset($user_row, 'viewimg', $data['view_images']);
  1523. $this->optionset($user_row, 'viewflash', $data['view_flash']);
  1524. $this->optionset($user_row, 'viewsmilies', $data['view_smilies']);
  1525. $this->optionset($user_row, 'viewsigs', $data['view_sigs']);
  1526. $this->optionset($user_row, 'viewavatars', $data['view_avatars']);
  1527. $this->optionset($user_row, 'viewcensors', $data['view_wordcensor']);
  1528. $this->optionset($user_row, 'bbcode', $data['bbcode']);
  1529. $this->optionset($user_row, 'smilies', $data['smilies']);
  1530. $this->optionset($user_row, 'attachsig', $data['sig']);
  1531.  
  1532. $sql_ary = array(
  1533. 'user_options' => $user_row['user_options'],
  1534.  
  1535. 'user_allow_pm' => $data['allowpm'],
  1536. 'user_allow_viewemail' => $data['viewemail'],
  1537. 'user_allow_massemail' => $data['massemail'],
  1538. 'user_allow_viewonline' => !$data['hideonline'],
  1539. 'user_notify_type' => $data['notifymethod'],
  1540. 'user_notify_pm' => $data['notifypm'],
  1541.  
  1542. 'user_dst' => $data['dst'],
  1543. 'user_dateformat' => $data['dateformat'],
  1544. 'user_lang' => $data['lang'],
  1545. 'user_timezone' => $data['tz'],
  1546. 'user_style' => $data['style'],
  1547.  
  1548. 'user_topic_sortby_type' => $data['topic_sk'],
  1549. 'user_post_sortby_type' => $data['post_sk'],
  1550. 'user_topic_sortby_dir' => $data['topic_sd'],
  1551. 'user_post_sortby_dir' => $data['post_sd'],
  1552.  
  1553. 'user_topic_show_days' => $data['topic_st'],
  1554. 'user_post_show_days' => $data['post_st'],
  1555.  
  1556. 'user_notify' => $data['notify'],
  1557. );
  1558.  
  1559. $sql = 'UPDATE ' . USERS_TABLE . '
  1560. SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
  1561. WHERE user_id = $user_id";
  1562. $db->sql_query($sql);
  1563.  
  1564. // Check if user has an active session
  1565. if ($user_row['session_id'])
  1566. {
  1567. // We'll update the session if user_allow_viewonline has changed and the user is a bot
  1568. // Or if it's a regular user and the admin set it to hide the session
  1569. if ($user_row['user_allow_viewonline'] != $sql_ary['user_allow_viewonline'] && $user_row['user_type'] == USER_IGNORE
  1570. || $user_row['user_allow_viewonline'] && !$sql_ary['user_allow_viewonline'])
  1571. {
  1572. // We also need to check if the user has the permission to cloak.
  1573. $user_auth = new auth();
  1574. $user_auth->acl($user_row);
  1575.  
  1576. $session_sql_ary = array(
  1577. 'session_viewonline' => ($user_auth->acl_get('u_hideonline')) ? $sql_ary['user_allow_viewonline'] : true,
  1578. );
  1579.  
  1580. $sql = 'UPDATE ' . SESSIONS_TABLE . '
  1581. SET ' . $db->sql_build_array('UPDATE', $session_sql_ary) . "
  1582. WHERE session_user_id = $user_id";
  1583. $db->sql_query($sql);
  1584.  
  1585. unset($user_auth);
  1586. }
  1587. }
  1588.  
  1589. trigger_error($user->lang['USER_PREFS_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  1590. }
  1591.  
  1592. // Replace "error" strings with their real, localised form
  1593. $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
  1594. }
  1595.  
  1596. $dateformat_options = '';
  1597. foreach ($user->lang['dateformats'] as $format => $null)
  1598. {
  1599. $dateformat_options .= '<option value="' . $format . '"' . (($format == $data['dateformat']) ? ' selected="selected"' : '') . '>';
  1600. $dateformat_options .= $user->format_date(time(), $format, false) . ((strpos($format, '|') !== false) ? $user->lang['VARIANT_DATE_SEPARATOR'] . $user->format_date(time(), $format, true) : '');
  1601. $dateformat_options .= '</option>';
  1602. }
  1603.  
  1604. $s_custom = false;
  1605.  
  1606. $dateformat_options .= '<option value="custom"';
  1607. if (!isset($user->lang['dateformats'][$data['dateformat']]))
  1608. {
  1609. $dateformat_options .= ' selected="selected"';
  1610. $s_custom = true;
  1611. }
  1612. $dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>';
  1613.  
  1614. $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
  1615.  
  1616. // Topic ordering options
  1617. $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']);
  1618. $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']);
  1619.  
  1620. // Post ordering options
  1621. $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']);
  1622. $sort_by_post_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
  1623.  
  1624. $_options = array('topic', 'post');
  1625. foreach ($_options as $sort_option)
  1626. {
  1627. ${'s_limit_' . $sort_option . '_days'} = '<select name="' . $sort_option . '_st">';
  1628. foreach (${'limit_' . $sort_option . '_days'} as $day => $text)
  1629. {
  1630. $selected = ($data[$sort_option . '_st'] == $day) ? ' selected="selected"' : '';
  1631. ${'s_limit_' . $sort_option . '_days'} .= '<option value="' . $day . '"' . $selected . '>' . $text . '</option>';
  1632. }
  1633. ${'s_limit_' . $sort_option . '_days'} .= '</select>';
  1634.  
  1635. ${'s_sort_' . $sort_option . '_key'} = '<select name="' . $sort_option . '_sk">';
  1636. foreach (${'sort_by_' . $sort_option . '_text'} as $key => $text)
  1637. {
  1638. $selected = ($data[$sort_option . '_sk'] == $key) ? ' selected="selected"' : '';
  1639. ${'s_sort_' . $sort_option . '_key'} .= '<option value="' . $key . '"' . $selected . '>' . $text . '</option>';
  1640. }
  1641. ${'s_sort_' . $sort_option . '_key'} .= '</select>';
  1642.  
  1643. ${'s_sort_' . $sort_option . '_dir'} = '<select name="' . $sort_option . '_sd">';
  1644. foreach ($sort_dir_text as $key => $value)
  1645. {
  1646. $selected = ($data[$sort_option . '_sd'] == $key) ? ' selected="selected"' : '';
  1647. ${'s_sort_' . $sort_option . '_dir'} .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  1648. }
  1649. ${'s_sort_' . $sort_option . '_dir'} .= '</select>';
  1650. }
  1651.  
  1652. $template->assign_vars(array(
  1653. 'S_PREFS' => true,
  1654. 'S_JABBER_DISABLED' => ($config['jab_enable'] && $user_row['user_jabber'] && @extension_loaded('xml')) ? false : true,
  1655.  
  1656. 'VIEW_EMAIL' => $data['viewemail'],
  1657. 'MASS_EMAIL' => $data['massemail'],
  1658. 'ALLOW_PM' => $data['allowpm'],
  1659. 'HIDE_ONLINE' => $data['hideonline'],
  1660. 'NOTIFY_EMAIL' => ($data['notifymethod'] == NOTIFY_EMAIL) ? true : false,
  1661. 'NOTIFY_IM' => ($data['notifymethod'] == NOTIFY_IM) ? true : false,
  1662. 'NOTIFY_BOTH' => ($data['notifymethod'] == NOTIFY_BOTH) ? true : false,
  1663. 'NOTIFY_PM' => $data['notifypm'],
  1664. 'POPUP_PM' => $data['popuppm'],
  1665. 'DST' => $data['dst'],
  1666. 'BBCODE' => $data['bbcode'],
  1667. 'SMILIES' => $data['smilies'],
  1668. 'ATTACH_SIG' => $data['sig'],
  1669. 'NOTIFY' => $data['notify'],
  1670. 'VIEW_IMAGES' => $data['view_images'],
  1671. 'VIEW_FLASH' => $data['view_flash'],
  1672. 'VIEW_SMILIES' => $data['view_smilies'],
  1673. 'VIEW_SIGS' => $data['view_sigs'],
  1674. 'VIEW_AVATARS' => $data['view_avatars'],
  1675. 'VIEW_WORDCENSOR' => $data['view_wordcensor'],
  1676.  
  1677. 'S_TOPIC_SORT_DAYS' => $s_limit_topic_days,
  1678. 'S_TOPIC_SORT_KEY' => $s_sort_topic_key,
  1679. 'S_TOPIC_SORT_DIR' => $s_sort_topic_dir,
  1680. 'S_POST_SORT_DAYS' => $s_limit_post_days,
  1681. 'S_POST_SORT_KEY' => $s_sort_post_key,
  1682. 'S_POST_SORT_DIR' => $s_sort_post_dir,
  1683.  
  1684. 'DATE_FORMAT' => $data['dateformat'],
  1685. 'S_DATEFORMAT_OPTIONS' => $dateformat_options,
  1686. 'S_CUSTOM_DATEFORMAT' => $s_custom,
  1687. 'DEFAULT_DATEFORMAT' => $config['default_dateformat'],
  1688. 'A_DEFAULT_DATEFORMAT' => addslashes($config['default_dateformat']),
  1689.  
  1690. 'S_LANG_OPTIONS' => language_select($data['lang']),
  1691. 'S_STYLE_OPTIONS' => style_select($data['style']),
  1692. 'S_TZ_OPTIONS' => tz_select($data['tz'], true),
  1693. )
  1694. );
  1695.  
  1696. break;
  1697.  
  1698. case 'avatar':
  1699.  
  1700. include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  1701. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  1702.  
  1703. $can_upload = (file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads) ? true : false;
  1704.  
  1705. if ($submit)
  1706. {
  1707.  
  1708. if (!check_form_key($form_name))
  1709. {
  1710. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  1711. }
  1712.  
  1713. if (avatar_process_user($error, $user_row, $can_upload))
  1714. {
  1715. trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_row['user_id']));
  1716. }
  1717.  
  1718. // Replace "error" strings with their real, localised form
  1719. $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
  1720. }
  1721.  
  1722. if (!$config['allow_avatar'] && $user_row['user_avatar_type'])
  1723. {
  1724. $error[] = $user->lang['USER_AVATAR_NOT_ALLOWED'];
  1725. }
  1726. else if ((($user_row['user_avatar_type'] == AVATAR_UPLOAD) && !$config['allow_avatar_upload']) ||
  1727. (($user_row['user_avatar_type'] == AVATAR_REMOTE) && !$config['allow_avatar_remote']) ||
  1728. (($user_row['user_avatar_type'] == AVATAR_GALLERY) && !$config['allow_avatar_local']))
  1729. {
  1730. $error[] = $user->lang['USER_AVATAR_TYPE_NOT_ALLOWED'];
  1731. }
  1732.  
  1733. // Generate users avatar
  1734. $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="" />';
  1735.  
  1736. $display_gallery = (isset($_POST['display_gallery'])) ? true : false;
  1737. $avatar_select = basename(request_var('avatar_select', ''));
  1738. $category = basename(request_var('category', ''));
  1739.  
  1740. if ($config['allow_avatar_local'] && $display_gallery)
  1741. {
  1742. avatar_gallery($category, $avatar_select, 4);
  1743. }
  1744.  
  1745. $template->assign_vars(array(
  1746. 'S_AVATAR' => true,
  1747. 'S_CAN_UPLOAD' => $can_upload,
  1748. 'S_UPLOAD_FILE' => ($config['allow_avatar'] && $can_upload && $config['allow_avatar_upload']) ? true : false,
  1749. 'S_REMOTE_UPLOAD' => ($config['allow_avatar'] && $can_upload && $config['allow_avatar_remote_upload']) ? true : false,
  1750. 'S_ALLOW_REMOTE' => ($config['allow_avatar'] && $config['allow_avatar_remote']) ? true : false,
  1751. 'S_DISPLAY_GALLERY' => ($config['allow_avatar'] && $config['allow_avatar_local'] && !$display_gallery) ? true : false,
  1752. 'S_IN_GALLERY' => ($config['allow_avatar'] && $config['allow_avatar_local'] && $display_gallery) ? true : false,
  1753.  
  1754. 'AVATAR_IMAGE' => $avatar_img,
  1755. 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'],
  1756. 'USER_AVATAR_WIDTH' => $user_row['user_avatar_width'],
  1757. 'USER_AVATAR_HEIGHT' => $user_row['user_avatar_height'],
  1758.  
  1759. 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024)))
  1760. );
  1761.  
  1762. break;
  1763.  
  1764. case 'rank':
  1765.  
  1766. if ($submit)
  1767. {
  1768. if (!check_form_key($form_name))
  1769. {
  1770. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  1771. }
  1772.  
  1773. $rank_id = request_var('user_rank', 0);
  1774.  
  1775. $sql = 'UPDATE ' . USERS_TABLE . "
  1776. SET user_rank = $rank_id
  1777. WHERE user_id = $user_id";
  1778. $db->sql_query($sql);
  1779.  
  1780. trigger_error($user->lang['USER_RANK_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  1781. }
  1782.  
  1783. $sql = 'SELECT *
  1784. FROM ' . RANKS_TABLE . '
  1785. WHERE rank_special = 1
  1786. ORDER BY rank_title';
  1787. $result = $db->sql_query($sql);
  1788.  
  1789. $s_rank_options = '<option value="0"' . ((!$user_row['user_rank']) ? ' selected="selected"' : '') . '>' . $user->lang['NO_SPECIAL_RANK'] . '</option>';
  1790.  
  1791. while ($row = $db->sql_fetchrow($result))
  1792. {
  1793. $selected = ($user_row['user_rank'] && $row['rank_id'] == $user_row['user_rank']) ? ' selected="selected"' : '';
  1794. $s_rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>';
  1795. }
  1796. $db->sql_freeresult($result);
  1797.  
  1798. $template->assign_vars(array(
  1799. 'S_RANK' => true,
  1800. 'S_RANK_OPTIONS' => $s_rank_options)
  1801. );
  1802.  
  1803. break;
  1804.  
  1805. case 'sig':
  1806.  
  1807. include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
  1808. include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  1809.  
  1810. $enable_bbcode = ($config['allow_sig_bbcode']) ? (bool) $this->optionget($user_row, 'sig_bbcode') : false;
  1811. $enable_smilies = ($config['allow_sig_smilies']) ? (bool) $this->optionget($user_row, 'sig_smilies') : false;
  1812. $enable_urls = ($config['allow_sig_links']) ? (bool) $this->optionget($user_row, 'sig_links') : false;
  1813. $signature = utf8_normalize_nfc(request_var('signature', (string) $user_row['user_sig'], true));
  1814.  
  1815. $preview = (isset($_POST['preview'])) ? true : false;
  1816.  
  1817. if ($submit || $preview)
  1818. {
  1819. include_once($phpbb_root_path . 'includes/message_parser.' . $phpEx);
  1820.  
  1821. $enable_bbcode = ($config['allow_sig_bbcode']) ? ((request_var('disable_bbcode', false)) ? false : true) : false;
  1822. $enable_smilies = ($config['allow_sig_smilies']) ? ((request_var('disable_smilies', false)) ? false : true) : false;
  1823. $enable_urls = ($config['allow_sig_links']) ? ((request_var('disable_magic_url', false)) ? false : true) : false;
  1824.  
  1825. $message_parser = new parse_message($signature);
  1826.  
  1827. // Allowing Quote BBCode
  1828. $message_parser->parse($enable_bbcode, $enable_urls, $enable_smilies, $config['allow_sig_img'], $config['allow_sig_flash'], true, $config['allow_sig_links'], true, 'sig');
  1829.  
  1830. if (sizeof($message_parser->warn_msg))
  1831. {
  1832. $error[] = implode('<br />', $message_parser->warn_msg);
  1833. }
  1834.  
  1835. if (!check_form_key($form_name))
  1836. {
  1837. $error = 'FORM_INVALID';
  1838. }
  1839.  
  1840. if (!sizeof($error) && $submit)
  1841. {
  1842. $this->optionset($user_row, 'sig_bbcode', $enable_bbcode);
  1843. $this->optionset($user_row, 'sig_smilies', $enable_smilies);
  1844. $this->optionset($user_row, 'sig_links', $enable_urls);
  1845.  
  1846. $sql_ary = array(
  1847. 'user_sig' => (string) $message_parser->message,
  1848. 'user_options' => $user_row['user_options'],
  1849. 'user_sig_bbcode_uid' => (string) $message_parser->bbcode_uid,
  1850. 'user_sig_bbcode_bitfield' => (string) $message_parser->bbcode_bitfield
  1851. );
  1852.  
  1853. $sql = 'UPDATE ' . USERS_TABLE . '
  1854. SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
  1855. WHERE user_id = ' . $user_id;
  1856. $db->sql_query($sql);
  1857.  
  1858. trigger_error($user->lang['USER_SIG_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  1859. }
  1860.  
  1861. // Replace "error" strings with their real, localised form
  1862. $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
  1863. }
  1864.  
  1865. $signature_preview = '';
  1866.  
  1867. if ($preview)
  1868. {
  1869. // Now parse it for displaying
  1870. $signature_preview = $message_parser->format_display($enable_bbcode, $enable_urls, $enable_smilies, false);
  1871. unset($message_parser);
  1872. }
  1873.  
  1874. decode_message($signature, $user_row['user_sig_bbcode_uid']);
  1875.  
  1876. $template->assign_vars(array(
  1877. 'S_SIGNATURE' => true,
  1878.  
  1879. 'SIGNATURE' => $signature,
  1880. 'SIGNATURE_PREVIEW' => $signature_preview,
  1881.  
  1882. 'S_BBCODE_CHECKED' => (!$enable_bbcode) ? ' checked="checked"' : '',
  1883. 'S_SMILIES_CHECKED' => (!$enable_smilies) ? ' checked="checked"' : '',
  1884. 'S_MAGIC_URL_CHECKED' => (!$enable_urls) ? ' checked="checked"' : '',
  1885.  
  1886. '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>'),
  1887. 'SMILIES_STATUS' => ($config['allow_sig_smilies']) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'],
  1888. 'IMG_STATUS' => ($config['allow_sig_img']) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'],
  1889. 'FLASH_STATUS' => ($config['allow_sig_flash']) ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'],
  1890. 'URL_STATUS' => ($config['allow_sig_links']) ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'],
  1891.  
  1892. 'L_SIGNATURE_EXPLAIN' => sprintf($user->lang['SIGNATURE_EXPLAIN'], $config['max_sig_chars']),
  1893.  
  1894. 'S_BBCODE_ALLOWED' => $config['allow_sig_bbcode'],
  1895. 'S_SMILIES_ALLOWED' => $config['allow_sig_smilies'],
  1896. 'S_BBCODE_IMG' => ($config['allow_sig_img']) ? true : false,
  1897. 'S_BBCODE_FLASH' => ($config['allow_sig_flash']) ? true : false,
  1898. 'S_LINKS_ALLOWED' => ($config['allow_sig_links']) ? true : false)
  1899. );
  1900.  
  1901. // Assigning custom bbcodes
  1902. display_custom_bbcodes();
  1903.  
  1904. break;
  1905.  
  1906. case 'attach':
  1907.  
  1908. $start = request_var('start', 0);
  1909. $deletemark = (isset($_POST['delmarked'])) ? true : false;
  1910. $marked = request_var('mark', array(0));
  1911.  
  1912. // Sort keys
  1913. $sort_key = request_var('sk', 'a');
  1914. $sort_dir = request_var('sd', 'd');
  1915.  
  1916. if ($deletemark && sizeof($marked))
  1917. {
  1918. $sql = 'SELECT attach_id
  1919. FROM ' . ATTACHMENTS_TABLE . '
  1920. WHERE poster_id = ' . $user_id . '
  1921. AND is_orphan = 0
  1922. AND ' . $db->sql_in_set('attach_id', $marked);
  1923. $result = $db->sql_query($sql);
  1924.  
  1925. $marked = array();
  1926. while ($row = $db->sql_fetchrow($result))
  1927. {
  1928. $marked[] = $row['attach_id'];
  1929. }
  1930. $db->sql_freeresult($result);
  1931. }
  1932.  
  1933. if ($deletemark && sizeof($marked))
  1934. {
  1935. if (confirm_box(true))
  1936. {
  1937. $sql = 'SELECT real_filename
  1938. FROM ' . ATTACHMENTS_TABLE . '
  1939. WHERE ' . $db->sql_in_set('attach_id', $marked);
  1940. $result = $db->sql_query($sql);
  1941.  
  1942. $log_attachments = array();
  1943. while ($row = $db->sql_fetchrow($result))
  1944. {
  1945. $log_attachments[] = $row['real_filename'];
  1946. }
  1947. $db->sql_freeresult($result);
  1948.  
  1949. delete_attachments('attach', $marked);
  1950.  
  1951. $message = (sizeof($log_attachments) == 1) ? $user->lang['ATTACHMENT_DELETED'] : $user->lang['ATTACHMENTS_DELETED'];
  1952.  
  1953. add_log('admin', 'LOG_ATTACHMENTS_DELETED', implode(', ', $log_attachments));
  1954. trigger_error($message . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  1955. }
  1956. else
  1957. {
  1958. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  1959. 'u' => $user_id,
  1960. 'i' => $id,
  1961. 'mode' => $mode,
  1962. 'action' => $action,
  1963. 'delmarked' => true,
  1964. 'mark' => $marked))
  1965. );
  1966. }
  1967. }
  1968.  
  1969. $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']);
  1970. $sk_sql = array('a' => 'a.real_filename', 'c' => 'a.extension', 'd' => 'a.filesize', 'e' => 'a.download_count', 'f' => 'a.filetime', 'g' => 't.topic_title');
  1971.  
  1972. $sd_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
  1973.  
  1974. $s_sort_key = '';
  1975. foreach ($sk_text as $key => $value)
  1976. {
  1977. $selected = ($sort_key == $key) ? ' selected="selected"' : '';
  1978. $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  1979. }
  1980.  
  1981. $s_sort_dir = '';
  1982. foreach ($sd_text as $key => $value)
  1983. {
  1984. $selected = ($sort_dir == $key) ? ' selected="selected"' : '';
  1985. $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  1986. }
  1987.  
  1988. if (!isset($sk_sql[$sort_key]))
  1989. {
  1990. $sort_key = 'a';
  1991. }
  1992.  
  1993. $order_by = $sk_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC');
  1994.  
  1995. $sql = 'SELECT COUNT(attach_id) as num_attachments
  1996. FROM ' . ATTACHMENTS_TABLE . "
  1997. WHERE poster_id = $user_id
  1998. AND is_orphan = 0";
  1999. $result = $db->sql_query_limit($sql, 1);
  2000. $num_attachments = (int) $db->sql_fetchfield('num_attachments');
  2001. $db->sql_freeresult($result);
  2002.  
  2003. $sql = 'SELECT a.*, t.topic_title, p.message_subject as message_title
  2004. FROM ' . ATTACHMENTS_TABLE . ' a
  2005. LEFT JOIN ' . TOPICS_TABLE . ' t ON (a.topic_id = t.topic_id
  2006. AND a.in_message = 0)
  2007. LEFT JOIN ' . PRIVMSGS_TABLE . ' p ON (a.post_msg_id = p.msg_id
  2008. AND a.in_message = 1)
  2009. WHERE a.poster_id = ' . $user_id . "
  2010. AND a.is_orphan = 0
  2011. ORDER BY $order_by";
  2012. $result = $db->sql_query_limit($sql, $config['posts_per_page'], $start);
  2013.  
  2014. while ($row = $db->sql_fetchrow($result))
  2015. {
  2016. if ($row['in_message'])
  2017. {
  2018. $view_topic = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&amp;p={$row['post_msg_id']}");
  2019. }
  2020. else
  2021. {
  2022. $view_topic = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t={$row['topic_id']}&amp;p={$row['post_msg_id']}") . '#p' . $row['post_msg_id'];
  2023. }
  2024.  
  2025. $template->assign_block_vars('attach', array(
  2026. 'REAL_FILENAME' => $row['real_filename'],
  2027. 'COMMENT' => nl2br($row['attach_comment']),
  2028. 'EXTENSION' => $row['extension'],
  2029. 'SIZE' => get_formatted_filesize($row['filesize']),
  2030. 'DOWNLOAD_COUNT' => $row['download_count'],
  2031. 'POST_TIME' => $user->format_date($row['filetime']),
  2032. 'TOPIC_TITLE' => ($row['in_message']) ? $row['message_title'] : $row['topic_title'],
  2033.  
  2034. 'ATTACH_ID' => $row['attach_id'],
  2035. 'POST_ID' => $row['post_msg_id'],
  2036. 'TOPIC_ID' => $row['topic_id'],
  2037.  
  2038. 'S_IN_MESSAGE' => $row['in_message'],
  2039.  
  2040. 'U_DOWNLOAD' => append_sid("{$phpbb_root_path}download/file.$phpEx", 'mode=view&amp;id=' . $row['attach_id']),
  2041. 'U_VIEW_TOPIC' => $view_topic)
  2042. );
  2043. }
  2044. $db->sql_freeresult($result);
  2045.  
  2046. $template->assign_vars(array(
  2047. 'S_ATTACHMENTS' => true,
  2048. 'S_ON_PAGE' => on_page($num_attachments, $config['topics_per_page'], $start),
  2049. 'S_SORT_KEY' => $s_sort_key,
  2050. 'S_SORT_DIR' => $s_sort_dir,
  2051.  
  2052. '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))
  2053. );
  2054.  
  2055. break;
  2056.  
  2057. case 'groups':
  2058.  
  2059. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  2060.  
  2061. $user->add_lang(array('groups', 'acp/groups'));
  2062. $group_id = request_var('g', 0);
  2063.  
  2064. if ($group_id)
  2065. {
  2066. // Check the founder only entry for this group to make sure everything is well
  2067. $sql = 'SELECT group_founder_manage
  2068. FROM ' . GROUPS_TABLE . '
  2069. WHERE group_id = ' . $group_id;
  2070. $result = $db->sql_query($sql);
  2071. $founder_manage = (int) $db->sql_fetchfield('group_founder_manage');
  2072. $db->sql_freeresult($result);
  2073.  
  2074. if ($user->data['user_type'] != USER_FOUNDER && $founder_manage)
  2075. {
  2076. trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  2077. }
  2078. }
  2079. else
  2080. {
  2081. $founder_manage = 0;
  2082. }
  2083.  
  2084. switch ($action)
  2085. {
  2086. case 'demote':
  2087. case 'promote':
  2088. case 'default':
  2089. if (!$group_id)
  2090. {
  2091. trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  2092. }
  2093. group_user_attributes($action, $group_id, $user_id);
  2094.  
  2095. if ($action == 'default')
  2096. {
  2097. $user_row['group_id'] = $group_id;
  2098. }
  2099. break;
  2100.  
  2101. case 'delete':
  2102.  
  2103. if (confirm_box(true))
  2104. {
  2105. if (!$group_id)
  2106. {
  2107. trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  2108. }
  2109.  
  2110. if ($error = group_user_del($group_id, $user_id))
  2111. {
  2112. trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  2113. }
  2114.  
  2115. $error = array();
  2116.  
  2117. // The delete action was successful - therefore update the user row...
  2118. $sql = 'SELECT u.*, s.*
  2119. FROM ' . USERS_TABLE . ' u
  2120. LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id)
  2121. WHERE u.user_id = ' . $user_id . '
  2122. ORDER BY s.session_time DESC';
  2123. $result = $db->sql_query_limit($sql, 1);
  2124. $user_row = $db->sql_fetchrow($result);
  2125. $db->sql_freeresult($result);
  2126. }
  2127. else
  2128. {
  2129. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  2130. 'u' => $user_id,
  2131. 'i' => $id,
  2132. 'mode' => $mode,
  2133. 'action' => $action,
  2134. 'g' => $group_id))
  2135. );
  2136. }
  2137.  
  2138. break;
  2139.  
  2140. case 'approve':
  2141.  
  2142. if (confirm_box(true))
  2143. {
  2144. if (!$group_id)
  2145. {
  2146. trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  2147. }
  2148. group_user_attributes($action, $group_id, $user_id);
  2149. }
  2150. else
  2151. {
  2152. confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  2153. 'u' => $user_id,
  2154. 'i' => $id,
  2155. 'mode' => $mode,
  2156. 'action' => $action,
  2157. 'g' => $group_id))
  2158. );
  2159. }
  2160.  
  2161. break;
  2162. }
  2163.  
  2164. // Add user to group?
  2165. if ($submit)
  2166. {
  2167.  
  2168. if (!check_form_key($form_name))
  2169. {
  2170. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  2171. }
  2172.  
  2173. if (!$group_id)
  2174. {
  2175. trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  2176. }
  2177.  
  2178. // Add user/s to group
  2179. if ($error = group_user_add($group_id, $user_id))
  2180. {
  2181. trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
  2182. }
  2183.  
  2184. $error = array();
  2185. }
  2186.  
  2187.  
  2188. $sql = 'SELECT ug.*, g.*
  2189. FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . " ug
  2190. WHERE ug.user_id = $user_id
  2191. AND g.group_id = ug.group_id
  2192. ORDER BY g.group_type DESC, ug.user_pending ASC, g.group_name";
  2193. $result = $db->sql_query($sql);
  2194.  
  2195. $i = 0;
  2196. $group_data = $id_ary = array();
  2197. while ($row = $db->sql_fetchrow($result))
  2198. {
  2199. $type = ($row['group_type'] == GROUP_SPECIAL) ? 'special' : (($row['user_pending']) ? 'pending' : 'normal');
  2200.  
  2201. $group_data[$type][$i]['group_id'] = $row['group_id'];
  2202. $group_data[$type][$i]['group_name'] = $row['group_name'];
  2203. $group_data[$type][$i]['group_leader'] = ($row['group_leader']) ? 1 : 0;
  2204.  
  2205. $id_ary[] = $row['group_id'];
  2206.  
  2207. $i++;
  2208. }
  2209. $db->sql_freeresult($result);
  2210.  
  2211. // Select box for other groups
  2212. $sql = 'SELECT group_id, group_name, group_type, group_founder_manage
  2213. FROM ' . GROUPS_TABLE . '
  2214. ' . ((sizeof($id_ary)) ? 'WHERE ' . $db->sql_in_set('group_id', $id_ary, true) : '') . '
  2215. ORDER BY group_type DESC, group_name ASC';
  2216. $result = $db->sql_query($sql);
  2217.  
  2218. $s_group_options = '';
  2219. while ($row = $db->sql_fetchrow($result))
  2220. {
  2221. if (!$config['coppa_enable'] && $row['group_name'] == 'REGISTERED_COPPA')
  2222. {
  2223. continue;
  2224. }
  2225.  
  2226. // Do not display those groups not allowed to be managed
  2227. if ($user->data['user_type'] != USER_FOUNDER && $row['group_founder_manage'])
  2228. {
  2229. continue;
  2230. }
  2231.  
  2232. $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>';
  2233. }
  2234. $db->sql_freeresult($result);
  2235.  
  2236. $current_type = '';
  2237. foreach ($group_data as $group_type => $data_ary)
  2238. {
  2239. if ($current_type != $group_type)
  2240. {
  2241. $template->assign_block_vars('group', array(
  2242. 'S_NEW_GROUP_TYPE' => true,
  2243. 'GROUP_TYPE' => $user->lang['USER_GROUP_' . strtoupper($group_type)])
  2244. );
  2245. }
  2246.  
  2247. foreach ($data_ary as $data)
  2248. {
  2249. $template->assign_block_vars('group', array(
  2250. '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"),
  2251. 'U_DEFAULT' => $this->u_action . "&amp;action=default&amp;u=$user_id&amp;g=" . $data['group_id'],
  2252. 'U_DEMOTE_PROMOTE' => $this->u_action . '&amp;action=' . (($data['group_leader']) ? 'demote' : 'promote') . "&amp;u=$user_id&amp;g=" . $data['group_id'],
  2253. 'U_DELETE' => $this->u_action . "&amp;action=delete&amp;u=$user_id&amp;g=" . $data['group_id'],
  2254. 'U_APPROVE' => ($group_type == 'pending') ? $this->u_action . "&amp;action=approve&amp;u=$user_id&amp;g=" . $data['group_id'] : '',
  2255.  
  2256. 'GROUP_NAME' => ($group_type == 'special') ? $user->lang['G_' . $data['group_name']] : $data['group_name'],
  2257. 'L_DEMOTE_PROMOTE' => ($data['group_leader']) ? $user->lang['GROUP_DEMOTE'] : $user->lang['GROUP_PROMOTE'],
  2258.  
  2259. 'S_IS_MEMBER' => ($group_type != 'pending') ? true : false,
  2260. 'S_NO_DEFAULT' => ($user_row['group_id'] != $data['group_id']) ? true : false,
  2261. 'S_SPECIAL_GROUP' => ($group_type == 'special') ? true : false,
  2262. )
  2263. );
  2264. }
  2265. }
  2266.  
  2267. $template->assign_vars(array(
  2268. 'S_GROUPS' => true,
  2269. 'S_GROUP_OPTIONS' => $s_group_options)
  2270. );
  2271.  
  2272. break;
  2273.  
  2274. case 'perm':
  2275.  
  2276. include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
  2277.  
  2278. $auth_admin = new auth_admin();
  2279.  
  2280. $user->add_lang('acp/permissions');
  2281. add_permission_language();
  2282.  
  2283. $forum_id = request_var('f', 0);
  2284.  
  2285. // Global Permissions
  2286. if (!$forum_id)
  2287. {
  2288. // Select auth options
  2289. $sql = 'SELECT auth_option, is_local, is_global
  2290. FROM ' . ACL_OPTIONS_TABLE . '
  2291. WHERE auth_option ' . $db->sql_like_expression($db->any_char . '_') . '
  2292. AND is_global = 1
  2293. ORDER BY auth_option';
  2294. $result = $db->sql_query($sql);
  2295.  
  2296. $hold_ary = array();
  2297.  
  2298. while ($row = $db->sql_fetchrow($result))
  2299. {
  2300. $hold_ary = $auth_admin->get_mask('view', $user_id, false, false, $row['auth_option'], 'global', ACL_NEVER);
  2301. $auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', false, false);
  2302. }
  2303. $db->sql_freeresult($result);
  2304.  
  2305. unset($hold_ary);
  2306. }
  2307. else
  2308. {
  2309. $sql = 'SELECT auth_option, is_local, is_global
  2310. FROM ' . ACL_OPTIONS_TABLE . "
  2311. WHERE auth_option " . $db->sql_like_expression($db->any_char . '_') . "
  2312. AND is_local = 1
  2313. ORDER BY is_global DESC, auth_option";
  2314. $result = $db->sql_query($sql);
  2315.  
  2316. while ($row = $db->sql_fetchrow($result))
  2317. {
  2318. $hold_ary = $auth_admin->get_mask('view', $user_id, false, $forum_id, $row['auth_option'], 'local', ACL_NEVER);
  2319. $auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', true, false);
  2320. }
  2321. $db->sql_freeresult($result);
  2322. }
  2323.  
  2324. $s_forum_options = '<option value="0"' . ((!$forum_id) ? ' selected="selected"' : '') . '>' . $user->lang['VIEW_GLOBAL_PERMS'] . '</option>';
  2325. $s_forum_options .= make_forum_select($forum_id, false, true, false, false, false);
  2326.  
  2327. $template->assign_vars(array(
  2328. 'S_PERMISSIONS' => true,
  2329.  
  2330. 'S_GLOBAL' => (!$forum_id) ? true : false,
  2331. 'S_FORUM_OPTIONS' => $s_forum_options,
  2332.  
  2333. 'U_ACTION' => $this->u_action . '&amp;u=' . $user_id,
  2334. 'U_USER_PERMISSIONS' => append_sid("{$phpbb_admin_path}index.$phpEx" ,'i=permissions&amp;mode=setting_user_global&amp;user_id[]=' . $user_id),
  2335. 'U_USER_FORUM_PERMISSIONS' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions&amp;mode=setting_user_local&amp;user_id[]=' . $user_id))
  2336. );
  2337.  
  2338. break;
  2339.  
  2340. }
  2341. //BEGIN mChat Mod
  2342. case 'mchat':
  2343.  
  2344. $user->add_lang('mods/mchat_lang');
  2345.  
  2346. $data = array(
  2347. 'user_mchat_index' => request_var('user_mchat_index',(bool) $user_row['user_mchat_index']),
  2348. 'user_mchat_sound' => request_var('user_mchat_sound', (bool) $user_row['user_mchat_sound']),
  2349. 'user_mchat_stats_index' => request_var('user_mchat_stats_index', (bool) $user_row['user_mchat_stats_index']),
  2350. 'user_mchat_topics' => request_var('user_mchat_topics', (bool) $user_row['user_mchat_topics']),
  2351. 'user_mchat_avatars' => request_var('user_mchat_avatars', (bool) $user_row['user_mchat_avatars']),
  2352. 'user_mchat_input_area' => request_var('user_mchat_input_area', (bool) $user_row['user_mchat_input_area']),
  2353. );
  2354.  
  2355. if ($submit)
  2356. {
  2357. $error = array();
  2358.  
  2359. if (!check_form_key($form_name))
  2360. {
  2361. $error[] = 'FORM_INVALID';
  2362. }
  2363.  
  2364. if (!sizeof($error))
  2365. {
  2366.  
  2367. $sql_ary = array(
  2368. 'user_mchat_index' => $data['user_mchat_index'],
  2369. 'user_mchat_sound' => $data['user_mchat_sound'],
  2370. 'user_mchat_stats_index' => $data['user_mchat_stats_index'],
  2371. 'user_mchat_topics' => $data['user_mchat_topics'],
  2372. 'user_mchat_avatars' => $data['user_mchat_avatars'],
  2373. 'user_mchat_input_area' => $data['user_mchat_input_area'],
  2374. );
  2375.  
  2376. $sql = 'UPDATE ' . USERS_TABLE . '
  2377. SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
  2378. WHERE user_id = $user_id";
  2379. $db->sql_query($sql);
  2380.  
  2381. trigger_error($user->lang['USER_MCHAT_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
  2382. }
  2383.  
  2384. // Replace "error" strings with their real, localised form
  2385. $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
  2386. }
  2387.  
  2388. $template->assign_vars(array(
  2389. 'S_MCHAT' => true,
  2390. 'DISPLAY_MCHAT' => $data['user_mchat_index'],
  2391. 'SOUND_MCHAT' => $data['user_mchat_sound'],
  2392. 'STATS_MCHAT' => $data['user_mchat_stats_index'],
  2393. 'TOPICS_MCHAT' => $data['user_mchat_topics'],
  2394. 'AVATARS_MCHAT' => $data['user_mchat_avatars'],
  2395. 'INPUT_AREA' => $data['user_mchat_input_area'],
  2396. ));
  2397. break;
  2398. // END mChat Mod
  2399.  
  2400. // Assign general variables
  2401. $template->assign_vars(array(
  2402. 'S_ERROR' => (sizeof($error)) ? true : false,
  2403. 'ERROR_MSG' => (sizeof($error)) ? implode('<br />', $error) : '')
  2404. );
  2405. }
  2406.  
  2407. /**
  2408. * Set option bit field for user options in a user row array.
  2409. *
  2410. * Optionset replacement for this module based on $user->optionset.
  2411. *
  2412. * @param array $user_row Row from the users table.
  2413. * @param int $key Option key, as defined in $user->keyoptions property.
  2414. * @param bool $value True to set the option, false to clear the option.
  2415. * @param int $data Current bit field value, or false to use $user_row['user_options']
  2416. * @return int|bool If $data is false, the bit field is modified and
  2417. * written back to $user_row['user_options'], and
  2418. * return value is true if the bit field changed and
  2419. * false otherwise. If $data is not false, the new
  2420. * bitfield value is returned.
  2421. */
  2422. function optionset(&$user_row, $key, $value, $data = false)
  2423. {
  2424. global $user;
  2425.  
  2426. $var = ($data !== false) ? $data : $user_row['user_options'];
  2427.  
  2428. $new_var = phpbb_optionset($user->keyoptions[$key], $value, $var);
  2429.  
  2430. if ($data === false)
  2431. {
  2432. if ($new_var != $var)
  2433. {
  2434. $user_row['user_options'] = $new_var;
  2435. return true;
  2436. }
  2437. else
  2438. {
  2439. return false;
  2440. }
  2441. }
  2442. else
  2443. {
  2444. return $new_var;
  2445. }
  2446. }
  2447.  
  2448. /**
  2449. * Get option bit field from user options in a user row array.
  2450. *
  2451. * Optionget replacement for this module based on $user->optionget.
  2452. *
  2453. * @param array $user_row Row from the users table.
  2454. * @param int $key option key, as defined in $user->keyoptions property.
  2455. * @param int $data bit field value to use, or false to use $user_row['user_options']
  2456. * @return bool true if the option is set in the bit field, false otherwise
  2457. */
  2458. function optionget(&$user_row, $key, $data = false)
  2459. {
  2460. global $user;
  2461.  
  2462. $var = ($data !== false) ? $data : $user_row['user_options'];
  2463. return phpbb_optionget($user->keyoptions[$key], $var);
  2464. }
  2465. }
  2466.  
  2467. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement