6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 if (!defined('IN_PHPBB'))
28 function main($id, $mode)
30 global $config, $phpbb_root_path, $phpEx;
31 global $db, $user, $auth, $template;
33 $user_id = request_var('u', 0);
34 $key = request_var('k', '');
36 $sql = 'SELECT user_id, username, user_type, user_email, user_newpasswd, user_lang, user_notify_type, user_actkey, user_inactive_reason
37 FROM ' . USERS_TABLE . "
38 WHERE user_id = $user_id";
39 $result = $db->sql_query($sql);
40 $user_row = $db->sql_fetchrow($result);
41 $db->sql_freeresult($result);
45 trigger_error('NO_USER');
48 if ($user_row['user_type'] <> USER_INACTIVE && !$user_row['user_newpasswd'])
50 meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
51 trigger_error('ALREADY_ACTIVATED');
54 if (($user_row['user_inactive_reason'] == INACTIVE_MANUAL) || $user_row['user_actkey'] != $key)
56 trigger_error('WRONG_ACTIVATION');
59 // Do not allow activating by non administrators when admin activation is on
60 // Only activation type the user should be able to do is INACTIVE_REMIND
61 // or activate a new password which is not an activation state :@
62 if (!$user_row['user_newpasswd'] && $user_row['user_inactive_reason'] != INACTIVE_REMIND && $config['require_activation'] == USER_ACTIVATION_ADMIN && !$auth->acl_get('a_user'))
64 if (!$user->data['is_registered'])
66 login_box('', $user->lang['NO_AUTH_OPERATION']);
68 trigger_error('NO_AUTH_OPERATION');
71 $update_password = ($user_row['user_newpasswd']) ? true : false;
77 'user_password' => $user_row['user_newpasswd'],
78 'user_newpasswd' => '',
79 'user_pass_convert' => 0,
80 'user_login_attempts' => 0,
83 $sql = 'UPDATE ' . USERS_TABLE . '
84 SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
85 WHERE user_id = ' . $user_row['user_id'];
88 add_log('user', $user_row['user_id'], 'LOG_USER_NEW_PASSWORD', $user_row['username']);
91 if (!$update_password)
93 include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
95 user_active_flip('activate', $user_row['user_id']);
97 $sql = 'UPDATE ' . USERS_TABLE . "
99 WHERE user_id = {$user_row['user_id']}";
100 $db->sql_query($sql);
102 // Create the correct logs
103 add_log('user', $user_row['user_id'], 'LOG_USER_ACTIVE_USER');
104 if ($auth->acl_get('a_user'))
106 add_log('admin', 'LOG_USER_ACTIVE', $user_row['username']);
110 if ($config['require_activation'] == USER_ACTIVATION_ADMIN && !$update_password)
112 include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
114 $messenger = new messenger(false);
116 $messenger->template('admin_welcome_activated', $user_row['user_lang']);
118 $messenger->to($user_row['user_email'], $user_row['username']);
120 $messenger->anti_abuse_headers($config, $user);
122 $messenger->assign_vars(array(
123 'USERNAME' => htmlspecialchars_decode($user_row['username']))
126 $messenger->send($user_row['user_notify_type']);
128 $message = 'ACCOUNT_ACTIVE_ADMIN';
132 if (!$update_password)
134 $message = ($user_row['user_inactive_reason'] == INACTIVE_PROFILE) ? 'ACCOUNT_ACTIVE_PROFILE' : 'ACCOUNT_ACTIVE';
138 $message = 'PASSWORD_ACTIVATED';
142 meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
143 trigger_error($user->lang[$message]);