diff --git a/main/inc/lib/urlmanager.lib.php b/main/inc/lib/urlmanager.lib.php index e94a67afc1..7ac88a43ca 100755 --- a/main/inc/lib/urlmanager.lib.php +++ b/main/inc/lib/urlmanager.lib.php @@ -757,6 +757,26 @@ class UrlManager return $result; } + /** + * Deletes user from all portals + * @author Julio Montoya + * @param int user id + * + * @return boolean true if success + * */ + public static function deleteUserFromAllUrls($userId) + { + $table_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + $result = true; + if (!empty($userId)) { + $sql= "DELETE FROM $table_url_rel_user + WHERE user_id = ".intval($userId); + Database::query($sql); + } + + return $result; + } + /** * Deletes an url and course relationship * @author Julio Montoya diff --git a/main/inc/lib/usermanager.lib.php b/main/inc/lib/usermanager.lib.php index 964aeeb4a5..31600933bb 100755 --- a/main/inc/lib/usermanager.lib.php +++ b/main/inc/lib/usermanager.lib.php @@ -475,12 +475,12 @@ class UserManager */ public static function can_delete_user($user_id) { - global $_configuration; - if (isset($_configuration['deny_delete_users']) && - $_configuration['deny_delete_users'] == true - ) { + $deny = api_get_configuration_value('deny_delete_users'); + + if ($deny) { return false; } + $table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); if ($user_id != strval(intval($user_id))) { return false; @@ -493,12 +493,14 @@ class UserManager $res = Database::query($sql); while ($course = Database::fetch_object($res)) { $sql = "SELECT id FROM $table_course_user - WHERE status=1 AND c_id = " . Database::escape_string($course->c_id); + WHERE status=1 AND c_id = " . intval($course->c_id); $res2 = Database::query($sql); if (Database::num_rows($res2) == 1) { + return false; } } + return true; } @@ -612,8 +614,7 @@ class UserManager $extraFieldValue = new ExtraFieldValue('user'); $extraFieldValue->deleteValuesByItem($user_id); - $url_id = api_get_current_access_url_id(); - UrlManager::delete_url_rel_user($user_id, $url_id); + UrlManager::deleteUserFromAllUrls($user_id); if (api_get_setting('allow_social_tool') == 'true') { $userGroup = new UserGroup(); @@ -648,12 +649,13 @@ class UserManager WHERE lastedit_user_id = '".$user_id."'"; Database::query($sql); + + + // Delete user from database $sql = "DELETE FROM $table_user WHERE id = '".$user_id."'"; Database::query($sql); - - // Add event to system log $user_id_manager = api_get_user_id();