userautocomplete.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. OCP\JSON::checkLoggedIn();
  3. OCP\JSON::checkAppEnabled('files_sharing');
  4. $users = array();
  5. $groups = array();
  6. $self = OCP\USER::getUser();
  7. $users[] = "<optgroup label='Users'>";
  8. $groups[] = "<optgroup label='Groups'>";
  9. if(OCP\Config::getAppValue('files_sharing', 'allowSharingWithEveryone', 'no') == 'yes') {
  10. $allGroups = OC_Group::getGroups();
  11. foreach($allGroups as $group) {
  12. $groups[] = "<option value='".$group."(group)'>".$group." (group) </option>";
  13. }
  14. $allUsers = OC_User::getUsers();
  15. foreach($allUsers as $user) {
  16. if($user != $self) {
  17. $users[] = "<option value='".$user."'>".$user."</option>";
  18. }
  19. }
  20. } else {
  21. $userGroups = OC_Group::getUserGroups($self);
  22. foreach ($userGroups as $group) {
  23. $groupUsers = OC_Group::usersInGroup($group);
  24. $userCount = 0;
  25. foreach ($groupUsers as $user) {
  26. if ($user != $self) {
  27. $users[] = "<option value='".$user."'>".$user."</option>";
  28. $userCount++;
  29. }
  30. }
  31. // Don't include the group if only the current user is a member of it
  32. if ($userCount > 0) {
  33. $groups[] = "<option value='".$group."(group)'>".$group." (group) </option>";
  34. }
  35. }
  36. $users = array_unique($users);
  37. }
  38. $users[] = "</optgroup>";
  39. $groups[] = "</optgroup>";
  40. $users = array_merge($users, $groups);
  41. OCP\JSON::encodedPrint($users);
  42. ?>