/** * Deletes a user */ function DeleteUser() { // Check the token if (!Kit::CheckToken()) { trigger_error(__('Sorry the form has expired. Please refresh.'), E_USER_ERROR); } $response = new ResponseManager(); $deleteAllItems = Kit::GetParam('deleteAllItems', _POST, _CHECKBOX) == 1; $userId = Kit::GetParam('userid', _POST, _INT, 0); $groupId = $this->user->getGroupFromID($userId, true); $user = new Userdata(); $user->userId = $userId; $userGroup = new UserGroup(); if (!$deleteAllItems) { // Can we delete this user? Don't even try if we cant. $children = $user->getChildTypes(); if (count($children) > 0) { trigger_error(sprintf(__('Cannot delete user, they own %s'), implode(', ', $children)), E_USER_ERROR); } // Can we delete this group? $children = $userGroup->getChildTypes($groupId); if (count($children) > 0) { trigger_error(sprintf(__('Cannot delete user, they own %s'), implode(', ', $children)), E_USER_ERROR); } } // Delete all items has been selected, so call delete on the group, then the user $userGroup->UnlinkAllGroups($userId); // Delete the user specific group if (!$userGroup->Delete($groupId)) { trigger_error($userGroup->GetErrorMessage(), E_USER_ERROR); } // Delete the user if (!$user->Delete()) { trigger_error($user->GetErrorMessage(), E_USER_ERROR); } $response->SetFormSubmitResponse(__('User Deleted.')); $response->Respond(); }