| 1 |
3670 |
psotfx |
<?php
|
| 2 |
5276 |
bartvb |
/**
|
| 3 |
5114 |
acydburn |
*
|
| 4 |
5114 |
acydburn |
* @package phpBB3
|
| 5 |
5114 |
acydburn |
* @version $Id$
|
| 6 |
5276 |
bartvb |
* @copyright (c) 2005 phpBB Group
|
| 7 |
5276 |
bartvb |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
| 8 |
5114 |
acydburn |
*
|
| 9 |
5114 |
acydburn |
*/
|
| 10 |
3670 |
psotfx |
|
| 11 |
5114 |
acydburn |
/**
|
| 12 |
8146 |
acydburn |
* @ignore
|
| 13 |
8146 |
acydburn |
*/
|
| 14 |
8146 |
acydburn |
if (!defined('IN_PHPBB'))
|
| 15 |
8146 |
acydburn |
{
|
| 16 |
8146 |
acydburn |
exit;
|
| 17 |
8146 |
acydburn |
}
|
| 18 |
8146 |
acydburn |
|
| 19 |
8146 |
acydburn |
/**
|
| 20 |
5114 |
acydburn |
* Obtain user_ids from usernames or vice versa. Returns false on
|
| 21 |
5114 |
acydburn |
* success else the error string
|
| 22 |
7150 |
acydburn |
*
|
| 23 |
7150 |
acydburn |
* @param array &$user_id_ary The user ids to check or empty if usernames used
|
| 24 |
7150 |
acydburn |
* @param array &$username_ary The usernames to check or empty if user ids used
|
| 25 |
7150 |
acydburn |
* @param mixed $user_type Array of user types to check, false if not restricting by user type
|
| 26 |
5114 |
acydburn |
*/
|
| 27 |
7150 |
acydburn |
function user_get_id_name(&$user_id_ary, &$username_ary, $user_type = false)
|
| 28 |
4780 |
psotfx |
{
|
| 29 |
4780 |
psotfx |
global $db;
|
| 30 |
4780 |
psotfx |
|
| 31 |
4780 |
psotfx |
// Are both arrays already filled? Yep, return else
|
| 32 |
5276 |
bartvb |
// are neither array filled?
|
| 33 |
4780 |
psotfx |
if ($user_id_ary && $username_ary)
|
| 34 |
4780 |
psotfx |
{
|
| 35 |
5967 |
acydburn |
return false;
|
| 36 |
4780 |
psotfx |
}
|
| 37 |
4780 |
psotfx |
else if (!$user_id_ary && !$username_ary)
|
| 38 |
4780 |
psotfx |
{
|
| 39 |
4780 |
psotfx |
return 'NO_USERS';
|
| 40 |
4780 |
psotfx |
}
|
| 41 |
4780 |
psotfx |
|
| 42 |
4780 |
psotfx |
$which_ary = ($user_id_ary) ? 'user_id_ary' : 'username_ary';
|
| 43 |
4780 |
psotfx |
|
| 44 |
5824 |
acydburn |
if ($$which_ary && !is_array($$which_ary))
|
| 45 |
4780 |
psotfx |
{
|
| 46 |
4780 |
psotfx |
$$which_ary = array($$which_ary);
|
| 47 |
4780 |
psotfx |
}
|
| 48 |
4780 |
psotfx |
|
| 49 |
6494 |
naderman |
$sql_in = ($which_ary == 'user_id_ary') ? array_map('intval', $$which_ary) : array_map('utf8_clean_string', $$which_ary);
|
| 50 |
4780 |
psotfx |
unset($$which_ary);
|
| 51 |
4780 |
psotfx |
|
| 52 |
6114 |
acydburn |
$user_id_ary = $username_ary = array();
|
| 53 |
6114 |
acydburn |
|
| 54 |
4780 |
psotfx |
// Grab the user id/username records
|
| 55 |
6494 |
naderman |
$sql_where = ($which_ary == 'user_id_ary') ? 'user_id' : 'username_clean';
|
| 56 |
5276 |
bartvb |
$sql = 'SELECT user_id, username
|
| 57 |
6271 |
acydburn |
FROM ' . USERS_TABLE . '
|
| 58 |
6271 |
acydburn |
WHERE ' . $db->sql_in_set($sql_where, $sql_in);
|
| 59 |
6544 |
acydburn |
|
| 60 |
7150 |
acydburn |
if ($user_type !== false && !empty($user_type))
|
| 61 |
6544 |
acydburn |
{
|
| 62 |
7150 |
acydburn |
$sql .= ' AND ' . $db->sql_in_set('user_type', $user_type);
|
| 63 |
6544 |
acydburn |
}
|
| 64 |
6544 |
acydburn |
|
| 65 |
4780 |
psotfx |
$result = $db->sql_query($sql);
|
| 66 |
4780 |
psotfx |
|
| 67 |
4780 |
psotfx |
if (!($row = $db->sql_fetchrow($result)))
|
| 68 |
4780 |
psotfx |
{
|
| 69 |
6015 |
acydburn |
$db->sql_freeresult($result);
|
| 70 |
4780 |
psotfx |
return 'NO_USERS';
|
| 71 |
4780 |
psotfx |
}
|
| 72 |
4780 |
psotfx |
|
| 73 |
4780 |
psotfx |
do
|
| 74 |
4780 |
psotfx |
{
|
| 75 |
4780 |
psotfx |
$username_ary[$row['user_id']] = $row['username'];
|
| 76 |
4780 |
psotfx |
$user_id_ary[] = $row['user_id'];
|
| 77 |
4780 |
psotfx |
}
|
| 78 |
4780 |
psotfx |
while ($row = $db->sql_fetchrow($result));
|
| 79 |
4780 |
psotfx |
$db->sql_freeresult($result);
|
| 80 |
4780 |
psotfx |
|
| 81 |
4780 |
psotfx |
return false;
|
| 82 |
4780 |
psotfx |
}
|
| 83 |
4780 |
psotfx |
|
| 84 |
5114 |
acydburn |
/**
|
| 85 |
6048 |
acydburn |
* Get latest registered username and update database to reflect it
|
| 86 |
6048 |
acydburn |
*/
|
| 87 |
6048 |
acydburn |
function update_last_username()
|
| 88 |
6048 |
acydburn |
{
|
| 89 |
6048 |
acydburn |
global $db;
|
| 90 |
6048 |
acydburn |
|
| 91 |
6048 |
acydburn |
// Get latest username
|
| 92 |
6742 |
davidmj |
$sql = 'SELECT user_id, username, user_colour
|
| 93 |
6048 |
acydburn |
FROM ' . USERS_TABLE . '
|
| 94 |
9233 |
acydburn |
WHERE user_type IN (' . phpbb::USER_NORMAL . ', ' . phpbb::USER_FOUNDER . ')
|
| 95 |
6048 |
acydburn |
ORDER BY user_id DESC';
|
| 96 |
6048 |
acydburn |
$result = $db->sql_query_limit($sql, 1);
|
| 97 |
6048 |
acydburn |
$row = $db->sql_fetchrow($result);
|
| 98 |
6048 |
acydburn |
$db->sql_freeresult($result);
|
| 99 |
6048 |
acydburn |
|
| 100 |
6048 |
acydburn |
if ($row)
|
| 101 |
6048 |
acydburn |
{
|
| 102 |
6048 |
acydburn |
set_config('newest_user_id', $row['user_id'], true);
|
| 103 |
6048 |
acydburn |
set_config('newest_username', $row['username'], true);
|
| 104 |
6742 |
davidmj |
set_config('newest_user_colour', $row['user_colour'], true);
|
| 105 |
6048 |
acydburn |
}
|
| 106 |
6048 |
acydburn |
}
|
| 107 |
6048 |
acydburn |
|
| 108 |
6048 |
acydburn |
/**
|
| 109 |
5114 |
acydburn |
* Updates a username across all relevant tables/fields
|
| 110 |
6015 |
acydburn |
*
|
| 111 |
6015 |
acydburn |
* @param string $old_name the old/current username
|
| 112 |
6015 |
acydburn |
* @param string $new_name the new username
|
| 113 |
5114 |
acydburn |
*/
|
| 114 |
4780 |
psotfx |
function user_update_name($old_name, $new_name)
|
| 115 |
4780 |
psotfx |
{
|
| 116 |
9242 |
acydburn |
global $db;
|
| 117 |
4780 |
psotfx |
|
| 118 |
4780 |
psotfx |
$update_ary = array(
|
| 119 |
6021 |
acydburn |
FORUMS_TABLE => array('forum_last_poster_name'),
|
| 120 |
6021 |
acydburn |
MODERATOR_CACHE_TABLE => array('username'),
|
| 121 |
6021 |
acydburn |
POSTS_TABLE => array('post_username'),
|
| 122 |
6021 |
acydburn |
TOPICS_TABLE => array('topic_first_poster_name', 'topic_last_poster_name'),
|
| 123 |
4780 |
psotfx |
);
|
| 124 |
4780 |
psotfx |
|
| 125 |
4780 |
psotfx |
foreach ($update_ary as $table => $field_ary)
|
| 126 |
4780 |
psotfx |
{
|
| 127 |
4780 |
psotfx |
foreach ($field_ary as $field)
|
| 128 |
4780 |
psotfx |
{
|
| 129 |
5276 |
bartvb |
$sql = "UPDATE $table
|
| 130 |
5357 |
acydburn |
SET $field = '" . $db->sql_escape($new_name) . "'
|
| 131 |
5357 |
acydburn |
WHERE $field = '" . $db->sql_escape($old_name) . "'";
|
| 132 |
4780 |
psotfx |
$db->sql_query($sql);
|
| 133 |
4780 |
psotfx |
}
|
| 134 |
4780 |
psotfx |
}
|
| 135 |
4780 |
psotfx |
|
| 136 |
9242 |
acydburn |
if (phpbb::$config['newest_username'] == $old_name)
|
| 137 |
4807 |
psotfx |
{
|
| 138 |
6117 |
acydburn |
set_config('newest_username', $new_name, true);
|
| 139 |
4807 |
psotfx |
}
|
| 140 |
8306 |
acydburn |
|
| 141 |
8306 |
acydburn |
// Because some tables/caches use username-specific data we need to purge this here.
|
| 142 |
9240 |
acydburn |
phpbb::$acm->destroy_sql(MODERATOR_CACHE_TABLE);
|
| 143 |
4807 |
psotfx |
}
|
| 144 |
4807 |
psotfx |
|
| 145 |
5114 |
acydburn |
/**
|
| 146 |
8729 |
Kellanved |
* Adds a user
|
| 147 |
8383 |
Kellanved |
*
|
| 148 |
8383 |
Kellanved |
* @param mixed $user_row An array containing the following keys (and the appropriate values): username, group_id (the group to place the user in), user_email and the user_type(usually 0). Additional entries not overridden by defaults will be forwarded.
|
| 149 |
8383 |
Kellanved |
* @param string $cp_data custom profile fields, see custom_profile::build_insert_sql_array
|
| 150 |
8786 |
acydburn |
* @return the new user's ID.
|
| 151 |
6048 |
acydburn |
*/
|
| 152 |
6048 |
acydburn |
function user_add($user_row, $cp_data = false)
|
| 153 |
6048 |
acydburn |
{
|
| 154 |
9242 |
acydburn |
global $db, $user, $auth;
|
| 155 |
6048 |
acydburn |
|
| 156 |
6056 |
acydburn |
if (empty($user_row['username']) || !isset($user_row['group_id']) || !isset($user_row['user_email']) || !isset($user_row['user_type']))
|
| 157 |
6048 |
acydburn |
{
|
| 158 |
6048 |
acydburn |
return false;
|
| 159 |
6048 |
acydburn |
}
|
| 160 |
6048 |
acydburn |
|
| 161 |
7748 |
acydburn |
$username_clean = utf8_clean_string($user_row['username']);
|
| 162 |
7748 |
acydburn |
|
| 163 |
7748 |
acydburn |
if (empty($username_clean))
|
| 164 |
7748 |
acydburn |
{
|
| 165 |
7748 |
acydburn |
return false;
|
| 166 |
7748 |
acydburn |
}
|
| 167 |
7748 |
acydburn |
|
| 168 |
6048 |
acydburn |
$sql_ary = array(
|
| 169 |
6048 |
acydburn |
'username' => $user_row['username'],
|
| 170 |
7748 |
acydburn |
'username_clean' => $username_clean,
|
| 171 |
6048 |
acydburn |
'user_password' => (isset($user_row['user_password'])) ? $user_row['user_password'] : '',
|
| 172 |
6743 |
davidmj |
'user_pass_convert' => 0,
|
| 173 |
6628 |
acydburn |
'user_email' => strtolower($user_row['user_email']),
|
| 174 |
8308 |
davidmj |
'user_email_hash' => hexdec(crc32(strtolower($user_row['user_email'])) . strlen($user_row['user_email'])),
|
| 175 |
6048 |
acydburn |
'group_id' => $user_row['group_id'],
|
| 176 |
6048 |
acydburn |
'user_type' => $user_row['user_type'],
|
| 177 |
6048 |
acydburn |
);
|
| 178 |
6048 |
acydburn |
|
| 179 |
6048 |
acydburn |
// These are the additional vars able to be specified
|
| 180 |
6048 |
acydburn |
$additional_vars = array(
|
| 181 |
6048 |
acydburn |
'user_permissions' => '',
|
| 182 |
9242 |
acydburn |
'user_timezone' => phpbb::$config['board_timezone'],
|
| 183 |
9242 |
acydburn |
'user_dateformat' => phpbb::$config['default_dateformat'],
|
| 184 |
9242 |
acydburn |
'user_lang' => phpbb::$config['default_lang'],
|
| 185 |
9242 |
acydburn |
'user_style' => phpbb::$config['default_style'],
|
| 186 |
6048 |
acydburn |
'user_actkey' => '',
|
| 187 |
6048 |
acydburn |
'user_ip' => '',
|
| 188 |
6048 |
acydburn |
'user_regdate' => time(),
|
| 189 |
6383 |
acydburn |
'user_passchg' => time(),
|
| 190 |
8033 |
acydburn |
'user_options' => 895,
|
| 191 |
6048 |
acydburn |
|
| 192 |
6394 |
grahamje |
'user_inactive_reason' => 0,
|
| 193 |
6394 |
grahamje |
'user_inactive_time' => 0,
|
| 194 |
6048 |
acydburn |
'user_lastmark' => time(),
|
| 195 |
6048 |
acydburn |
'user_lastvisit' => 0,
|
| 196 |
6048 |
acydburn |
'user_lastpost_time' => 0,
|
| 197 |
6048 |
acydburn |
'user_lastpage' => '',
|
| 198 |
6048 |
acydburn |
'user_posts' => 0,
|
| 199 |
9242 |
acydburn |
'user_dst' => (int) phpbb::$config['board_dst'],
|
| 200 |
6048 |
acydburn |
'user_colour' => '',
|
| 201 |
6663 |
acydburn |
'user_occ' => '',
|
| 202 |
6524 |
davidmj |
'user_interests' => '',
|
| 203 |
6048 |
acydburn |
'user_avatar' => '',
|
| 204 |
6048 |
acydburn |
'user_avatar_type' => 0,
|
| 205 |
6048 |
acydburn |
'user_avatar_width' => 0,
|
| 206 |
6048 |
acydburn |
'user_avatar_height' => 0,
|
| 207 |
6048 |
acydburn |
'user_new_privmsg' => 0,
|
| 208 |
6048 |
acydburn |
'user_unread_privmsg' => 0,
|
| 209 |
6048 |
acydburn |
'user_last_privmsg' => 0,
|
| 210 |
6048 |
acydburn |
'user_message_rules' => 0,
|
| 211 |
6048 |
acydburn |
'user_full_folder' => PRIVMSGS_NO_BOX,
|
| 212 |
6048 |
acydburn |
'user_emailtime' => 0,
|
| 213 |
6048 |
acydburn |
|
| 214 |
6048 |
acydburn |
'user_notify' => 0,
|
| 215 |
6048 |
acydburn |
'user_notify_pm' => 1,
|
| 216 |
6048 |
acydburn |
'user_notify_type' => NOTIFY_EMAIL,
|
| 217 |
6048 |
acydburn |
'user_allow_pm' => 1,
|
| 218 |
6048 |
acydburn |
'user_allow_viewonline' => 1,
|
| 219 |
6048 |
acydburn |
'user_allow_viewemail' => 1,
|
| 220 |
6048 |
acydburn |
'user_allow_massemail' => 1,
|
| 221 |
6048 |
acydburn |
|
| 222 |
6048 |
acydburn |
'user_sig' => '',
|
| 223 |
6048 |
acydburn |
'user_sig_bbcode_uid' => '',
|
| 224 |
6209 |
davidmj |
'user_sig_bbcode_bitfield' => '',
|
| 225 |
8351 |
acydburn |
|
| 226 |
8121 |
kellanved |
'user_form_salt' => unique_id(),
|
| 227 |
6048 |
acydburn |
);
|
| 228 |
6048 |
acydburn |
|
| 229 |
6048 |
acydburn |
// Now fill the sql array with not required variables
|
| 230 |
6048 |
acydburn |
foreach ($additional_vars as $key => $default_value)
|
| 231 |
6048 |
acydburn |
{
|
| 232 |
6048 |
acydburn |
$sql_ary[$key] = (isset($user_row[$key])) ? $user_row[$key] : $default_value;
|
| 233 |
6048 |
acydburn |
}
|
| 234 |
6048 |
acydburn |
|
| 235 |
6058 |
acydburn |
// Any additional variables in $user_row not covered above?
|
| 236 |
6058 |
acydburn |
$remaining_vars = array_diff(array_keys($user_row), array_keys($sql_ary));
|
| 237 |
6058 |
acydburn |
|
| 238 |
6058 |
acydburn |
// Now fill our sql array with the remaining vars
|
| 239 |
6058 |
acydburn |
if (sizeof($remaining_vars))
|
| 240 |
6058 |
acydburn |
{
|
| 241 |
6058 |
acydburn |
foreach ($remaining_vars as $key)
|
| 242 |
6058 |
acydburn |
{
|
| 243 |
6058 |
acydburn |
$sql_ary[$key] = $user_row[$key];
|
| 244 |
6058 |
acydburn |
}
|
| 245 |
6058 |
acydburn |
}
|
| 246 |
6058 |
acydburn |
|
| 247 |
6238 |
davidmj |
$sql = 'INSERT INTO ' . USERS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
|
| 248 |
6048 |
acydburn |
$db->sql_query($sql);
|
| 249 |
6048 |
acydburn |
|
| 250 |
6048 |
acydburn |
$user_id = $db->sql_nextid();
|
| 251 |
6048 |
acydburn |
|
| 252 |
6048 |
acydburn |
// Insert Custom Profile Fields
|
| 253 |
6048 |
acydburn |
if ($cp_data !== false && sizeof($cp_data))
|
| 254 |
6048 |
acydburn |
{
|
| 255 |
6048 |
acydburn |
$cp_data['user_id'] = (int) $user_id;
|
| 256 |
6058 |
acydburn |
|
| 257 |
6058 |
acydburn |
if (!class_exists('custom_profile'))
|
| 258 |
6058 |
acydburn |
{
|
| 259 |
8572 |
acydburn |
include_once(PHPBB_ROOT_PATH . 'includes/functions_profile_fields.' . PHP_EXT);
|
| 260 |
6058 |
acydburn |
}
|
| 261 |
6058 |
acydburn |
|
| 262 |
8146 |
acydburn |
$sql = 'INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' ' .
|
| 263 |
6058 |
acydburn |
$db->sql_build_array('INSERT', custom_profile::build_insert_sql_array($cp_data));
|
| 264 |
6048 |
acydburn |
$db->sql_query($sql);
|
| 265 |
6048 |
acydburn |
}
|
| 266 |
6048 |
acydburn |
|
| 267 |
6048 |
acydburn |
// Place into appropriate group...
|
| 268 |
6048 |
acydburn |
$sql = 'INSERT INTO ' . USER_GROUP_TABLE . ' ' . $db->sql_build_array('INSERT', array(
|
| 269 |
6048 |
acydburn |
'user_id' => (int) $user_id,
|
| 270 |
6048 |
acydburn |
'group_id' => (int) $user_row['group_id'],
|
| 271 |
6048 |
acydburn |
'user_pending' => 0)
|
| 272 |
6048 |
acydburn |
);
|
| 273 |
6048 |
acydburn |
$db->sql_query($sql);
|
| 274 |
6048 |
acydburn |
|
| 275 |
6114 |
acydburn |
// Now make it the users default group...
|
| 276 |
6782 |
davidmj |
group_set_user_default($user_row['group_id'], array($user_id), false);
|
| 277 |
6114 |
acydburn |
|
| 278 |
6151 |
naderman |
// set the newest user and adjust the user count if the user is a normal user and no activation mail is sent
|
| 279 |
9233 |
acydburn |
if ($user_row['user_type'] == phpbb::USER_NORMAL)
|
| 280 |
6151 |
naderman |
{
|
| 281 |
6151 |
naderman |
set_config('newest_user_id', $user_id, true);
|
| 282 |
6151 |
naderman |
set_config('newest_username', $user_row['username'], true);
|
| 283 |
9242 |
acydburn |
set_config('num_users', phpbb::$config['num_users'] + 1, true);
|
| 284 |
6782 |
davidmj |
|
| 285 |
6782 |
davidmj |
$sql = 'SELECT group_colour
|
| 286 |
6782 |
davidmj |
FROM ' . GROUPS_TABLE . '
|
| 287 |
8383 |
Kellanved |
WHERE group_id = ' . (int) $user_row['group_id'];
|
| 288 |
6782 |
davidmj |
$result = $db->sql_query_limit($sql, 1);
|
| 289 |
6782 |
davidmj |
$row = $db->sql_fetchrow($result);
|
| 290 |
6782 |
davidmj |
$db->sql_freeresult($result);
|
| 291 |
6782 |
davidmj |
|
| 292 |
6782 |
davidmj |
set_config('newest_user_colour', $row['group_colour'], true);
|
| 293 |
6151 |
naderman |
}
|
| 294 |
6151 |
naderman |
|
| 295 |
6048 |
acydburn |
return $user_id;
|
| 296 |
6048 |
acydburn |
}
|
| 297 |
6048 |
acydburn |
|
| 298 |
6048 |
acydburn |
/**
|
| 299 |
5114 |
acydburn |
* Remove User
|
| 300 |
5114 |
acydburn |
*/
|
| 301 |
5700 |
acydburn |
function user_delete($mode, $user_id, $post_username = false)
|
| 302 |
4811 |
psotfx |
{
|
| 303 |
9242 |
acydburn |
global $db, $user, $auth;
|
| 304 |
4811 |
psotfx |
|
| 305 |
6803 |
acydburn |
$sql = 'SELECT *
|
| 306 |
6803 |
acydburn |
FROM ' . USERS_TABLE . '
|
| 307 |
6803 |
acydburn |
WHERE user_id = ' . $user_id;
|
| 308 |
6803 |
acydburn |
$result = $db->sql_query($sql);
|
| 309 |
6803 |
acydburn |
$user_row = $db->sql_fetchrow($result);
|
| 310 |
6803 |
acydburn |
$db->sql_freeresult($result);
|
| 311 |
6803 |
acydburn |
|
| 312 |
6803 |
acydburn |
if (!$user_row)
|
| 313 |
6803 |
acydburn |
{
|
| 314 |
6803 |
acydburn |
return false;
|
| 315 |
6803 |
acydburn |
}
|
| 316 |
6803 |
acydburn |
|
| 317 |
7527 |
acydburn |
// Before we begin, we will remove the reports the user issued.
|
| 318 |
7527 |
acydburn |
$sql = 'SELECT r.post_id, p.topic_id
|
| 319 |
7527 |
acydburn |
FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . ' p
|
| 320 |
7527 |
acydburn |
WHERE r.user_id = ' . $user_id . '
|
| 321 |
7527 |
acydburn |
AND p.post_id = r.post_id';
|
| 322 |
7527 |
acydburn |
$result = $db->sql_query($sql);
|
| 323 |
7527 |
acydburn |
|
| 324 |
7527 |
acydburn |
$report_posts = $report_topics = array();
|
| 325 |
7527 |
acydburn |
while ($row = $db->sql_fetchrow($result))
|
| 326 |
7527 |
acydburn |
{
|
| 327 |
7527 |
acydburn |
$report_posts[] = $row['post_id'];
|
| 328 |
7527 |
acydburn |
$report_topics[] = $row['topic_id'];
|
| 329 |
7527 |
acydburn |
}
|
| 330 |
7527 |
acydburn |
$db->sql_freeresult($result);
|
| 331 |
7527 |
acydburn |
|
| 332 |
7527 |
acydburn |
if (sizeof($report_posts))
|
| 333 |
7527 |
acydburn |
{
|
| 334 |
7527 |
acydburn |
$report_posts = array_unique($report_posts);
|
| 335 |
7527 |
acydburn |
$report_topics = array_unique($report_topics);
|
| 336 |
7527 |
acydburn |
|
| 337 |
7527 |
acydburn |
// Get a list of topics that still contain reported posts
|
| 338 |
7527 |
acydburn |
$sql = 'SELECT DISTINCT topic_id
|
| 339 |
7527 |
acydburn |
FROM ' . POSTS_TABLE . '
|
| 340 |
7527 |
acydburn |
WHERE ' . $db->sql_in_set('topic_id', $report_topics) . '
|
| 341 |
7527 |
acydburn |
AND post_reported = 1
|
| 342 |
7527 |
acydburn |
AND ' . $db->sql_in_set('post_id', $report_posts, true);
|
| 343 |
7527 |
acydburn |
$result = $db->sql_query($sql);
|
| 344 |
7527 |
acydburn |
|
| 345 |
7527 |
acydburn |
$keep_report_topics = array();
|
| 346 |
7527 |
acydburn |
while ($row = $db->sql_fetchrow($result))
|
| 347 |
7527 |
acydburn |
{
|
| 348 |
7527 |
acydburn |
$keep_report_topics[] = $row['topic_id'];
|
| 349 |
7527 |
acydburn |
}
|
| 350 |
7527 |
acydburn |
$db->sql_freeresult($result);
|
| 351 |
7527 |
acydburn |
|
| 352 |
7527 |
acydburn |
if (sizeof($keep_report_topics))
|
| 353 |
7527 |
acydburn |
{
|
| 354 |
7527 |
acydburn |
$report_topics = array_diff($report_topics, $keep_report_topics);
|
| 355 |
7527 |
acydburn |
}
|
| 356 |
7527 |
acydburn |
unset($keep_report_topics);
|
| 357 |
7527 |
acydburn |
|
| 358 |
7527 |
acydburn |
// Now set the flags back
|
| 359 |
7527 |
acydburn |
$sql = 'UPDATE ' . POSTS_TABLE . '
|
| 360 |
7527 |
acydburn |
SET post_reported = 0
|
| 361 |
7527 |
acydburn |
WHERE ' . $db->sql_in_set('post_id', $report_posts);
|
| 362 |
7527 |
acydburn |
$db->sql_query($sql);
|
| 363 |
7527 |
acydburn |
|
| 364 |
7527 |
acydburn |
if (sizeof($report_topics))
|
| 365 |
7527 |
acydburn |
{
|
| 366 |
7527 |
acydburn |
$sql = 'UPDATE ' . TOPICS_TABLE . '
|
| 367 |
7527 |
acydburn |
SET topic_reported = 0
|
| 368 |
7527 |
acydburn |
WHERE ' . $db->sql_in_set('topic_id', $report_topics);
|
| 369 |
7527 |
acydburn |
$db->sql_query($sql);
|
| 370 |
7527 |
acydburn |
}
|
| 371 |
7527 |
acydburn |
}
|
| 372 |
7527 |
acydburn |
|
| 373 |
7527 |
acydburn |
// Remove reports
|
| 374 |
7527 |
acydburn |
$db->sql_query('DELETE FROM ' . REPORTS_TABLE . ' WHERE user_id = ' . $user_id);
|
| 375 |
7527 |
acydburn |
|
| 376 |
8233 |
kellanved |
if ($user_row['user_avatar'] && $user_row['user_avatar_type'] == AVATAR_UPLOAD)
|
| 377 |
8233 |
kellanved |
{
|
| 378 |
8233 |
kellanved |
avatar_delete('user', $user_row);
|
| 379 |
8233 |
kellanved |
}
|
| 380 |
8351 |
acydburn |
|
| 381 |
4811 |
psotfx |
switch ($mode)
|
| 382 |
4811 |
psotfx |
{
|
| 383 |
4811 |
psotfx |
case 'retain':
|
| 384 |
6436 |
acydburn |
|
| 385 |
8914 |
acydburn |
$db->sql_transaction('begin');
|
| 386 |
8914 |
acydburn |
|
| 387 |
6436 |
acydburn |
if ($post_username === false)
|
| 388 |
6436 |
acydburn |
{
|
| 389 |
6436 |
acydburn |
$post_username = $user->lang['GUEST'];
|
| 390 |
6436 |
acydburn |
}
|
| 391 |
6436 |
acydburn |
|
| 392 |
7881 |
acydburn |
// If the user is inactive and newly registered we assume no posts from this user being there...
|
| 393 |
9233 |
acydburn |
if ($user_row['user_type'] == phpbb::USER_INACTIVE && $user_row['user_inactive_reason'] == INACTIVE_REGISTER && !$user_row['user_posts'])
|
| 394 |
7881 |
acydburn |
{
|
| 395 |
7881 |
acydburn |
}
|
| 396 |
7881 |
acydburn |
else
|
| 397 |
7881 |
acydburn |
{
|
| 398 |
7881 |
acydburn |
$sql = 'UPDATE ' . FORUMS_TABLE . '
|
| 399 |
7881 |
acydburn |
SET forum_last_poster_id = ' . ANONYMOUS . ", forum_last_poster_name = '" . $db->sql_escape($post_username) . "', forum_last_poster_colour = ''
|
| 400 |
7881 |
acydburn |
WHERE forum_last_poster_id = $user_id";
|
| 401 |
7881 |
acydburn |
$db->sql_query($sql);
|
| 402 |
4811 |
psotfx |
|
| 403 |
7881 |
acydburn |
$sql = 'UPDATE ' . POSTS_TABLE . '
|
| 404 |
7881 |
acydburn |
SET poster_id = ' . ANONYMOUS . ", post_username = '" . $db->sql_escape($post_username) . "'
|
| 405 |
7881 |
acydburn |
WHERE poster_id = $user_id";
|
| 406 |
7881 |
acydburn |
$db->sql_query($sql);
|
| 407 |
4811 |
psotfx |
|
| 408 |
7881 |
acydburn |
$sql = 'UPDATE ' . POSTS_TABLE . '
|
| 409 |
7881 |
acydburn |
SET post_edit_user = ' . ANONYMOUS . "
|
| 410 |
7881 |
acydburn |
WHERE post_edit_user = $user_id";
|
| 411 |
7881 |
acydburn |
$db->sql_query($sql);
|
| 412 |
6436 |
acydburn |
|
| 413 |
7881 |
acydburn |
$sql = 'UPDATE ' . TOPICS_TABLE . '
|
| 414 |
7881 |
acydburn |
SET topic_poster = ' . ANONYMOUS . ", topic_first_poster_name = '" . $db->sql_escape($post_username) . "', topic_first_poster_colour = ''
|
| 415 |
7881 |
acydburn |
WHERE topic_poster = $user_id";
|
| 416 |
7881 |
acydburn |
$db->sql_query($sql);
|
| 417 |
4811 |
psotfx |
|
| 418 |
7881 |
acydburn |
$sql = 'UPDATE ' . TOPICS_TABLE . '
|
| 419 |
7881 |
acydburn |
SET topic_last_poster_id = ' . ANONYMOUS . ", topic_last_poster_name = '" . $db->sql_escape($post_username) . "', topic_last_poster_colour = ''
|
| 420 |
7881 |
acydburn |
WHERE topic_last_poster_id = $user_id";
|
| 421 |
7881 |
acydburn |
$db->sql_query($sql);
|
| 422 |
6513 |
acydburn |
|
| 423 |
7881 |
acydburn |
// Since we change every post by this author, we need to count this amount towards the anonymous user
|
| 424 |
6513 |
acydburn |
|
| 425 |
7881 |
acydburn |
// Update the post count for the anonymous user
|
| 426 |
7881 |
acydburn |
if ($user_row['user_posts'])
|
| 427 |
7881 |
acydburn |
{
|
| 428 |
7881 |
acydburn |
$sql = 'UPDATE ' . USERS_TABLE . '
|
| 429 |
7881 |
acydburn |
SET user_posts = user_posts + ' . $user_row['user_posts'] . '
|
| 430 |
7881 |
acydburn |
WHERE user_id = ' . ANONYMOUS;
|
| 431 |
7881 |
acydburn |
$db->sql_query($sql);
|
| 432 |
7881 |
acydburn |
}
|
| 433 |
6513 |
acydburn |
}
|
| 434 |
8914 |
acydburn |
|
| 435 |
8914 |
acydburn |
$db->sql_transaction('commit');
|
| 436 |
8914 |
acydburn |
|
| 437 |
5700 |
acydburn |
break;
|
| 438 |
4811 |
psotfx |
|
| 439 |
4811 |
psotfx |
case 'remove':
|
| 440 |
|