function user_delete($p_user_id) { $c_user_id = db_prepare_int($p_user_id); $t_user_table = config_get('mantis_user_table'); user_ensure_unprotected($p_user_id); # Remove associated profiles user_delete_profiles($p_user_id); # Remove associated preferences user_pref_delete_all($p_user_id); # Remove project specific access levels user_delete_project_specific_access_levels($p_user_id); #unset non-unique realname flags if necessary if (config_get('differentiate_duplicates')) { $c_realname = db_prepare_string(user_get_field($p_user_id, 'realname')); $query = "SELECT id\n\t\t\t\t\tFROM {$t_user_table}\n\t\t\t\t\tWHERE realname='{$c_realname}'"; $result = db_query($query); $t_count = db_num_rows($result); if ($t_count == 2) { # unset flags if there are now only 2 unique names for ($i = 0; $i < $t_count; $i++) { $t_user_id = db_result($result, $i); user_set_field($t_user_id, 'duplicate_realname', OFF); } } } user_clear_cache($p_user_id); # Remove account $query = "DELETE FROM {$t_user_table}\n\t\t\t\t WHERE id='{$c_user_id}'"; db_query($query); return true; }
/** * delete a user account (account, profiles, preferences, project-specific access levels) * returns true when the account was successfully deleted * * @param integer $p_user_id A valid user identifier. * @return boolean Always true */ function user_delete($p_user_id) { $c_user_id = (int) $p_user_id; user_ensure_unprotected($p_user_id); # Remove associated profiles user_delete_profiles($p_user_id); # Remove associated preferences user_pref_delete_all($p_user_id); # Remove project specific access levels user_delete_project_specific_access_levels($p_user_id); # unset non-unique realname flags if necessary if (config_get('differentiate_duplicates')) { $c_realname = user_get_field($p_user_id, 'realname'); $t_query = 'SELECT id FROM {user} WHERE realname=' . db_param(); $t_result = db_query($t_query, array($c_realname)); $t_users = array(); while ($t_row = db_fetch_array($t_result)) { $t_users[] = $t_row; } $t_user_count = count($t_users); if ($t_user_count == 2) { # unset flags if there are now only 2 unique names for ($i = 0; $i < $t_user_count; $i++) { $t_user_id = $t_users[$i]['id']; user_set_field($t_user_id, 'duplicate_realname', OFF); } } } user_clear_cache($p_user_id); # Remove account $t_query = 'DELETE FROM {user} WHERE id=' . db_param(); db_query($t_query, array($c_user_id)); return true; }
$c_realname = db_prepare_string($f_realname); $c_protected = db_prepare_bool($f_protected); $c_enabled = db_prepare_bool($f_enabled); $c_user_id = db_prepare_int($f_user_id); $c_access_level = db_prepare_int($f_access_level); $t_user_table = config_get('mantis_user_table'); $t_old_protected = user_get_field($f_user_id, 'protected'); # check that we are not downgrading the last administrator $t_old_access = user_get_field($f_user_id, 'access_level'); if (ADMINISTRATOR == $t_old_access && $t_old_access != $f_access_level && 1 >= user_count_level(ADMINISTRATOR)) { trigger_error(ERROR_USER_CHANGE_LAST_ADMIN, ERROR); } # Project specific access rights override global levels, hence, for users who are changed # to be administrators, we have to remove project specific rights. if ($c_access_level >= ADMINISTRATOR && !user_is_administrator($c_user_id)) { user_delete_project_specific_access_levels($c_user_id); } # if the user is already protected and the admin is not removing the # protected flag then don't update the access level and enabled flag. # If the user was unprotected or the protected flag is being turned off # then proceed with a full update. if ($f_protected && $t_old_protected) { $query = "UPDATE {$t_user_table}\n\t \t\tSET username='******', email='{$c_email}',\n\t \t\t\tprotected='{$c_protected}', realname='{$c_realname}'\n\t \t\tWHERE id='{$c_user_id}'"; } else { $query = "UPDATE {$t_user_table}\n\t \t\tSET username='******', email='{$c_email}',\n\t \t\t\taccess_level='{$c_access_level}', enabled='{$c_enabled}',\n\t \t\t\tprotected='{$c_protected}', realname='{$c_realname}'\n\t \t\tWHERE id='{$c_user_id}'"; } $result = db_query($query); $t_redirect_url = 'manage_user_page.php'; html_page_top1(); if ($result) { html_meta_redirect($t_redirect_url);