users.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * Copyright (c) 2011, Robin Appelman <icewind1991@gmail.com>
  4. * This file is licensed under the Affero General Public License version 3 or later.
  5. * See the COPYING-README file.
  6. */
  7. OC_Util::checkSubAdminUser();
  8. // We have some javascript foo!
  9. OC_Util::addScript('settings', 'users/deleteHandler');
  10. OC_Util::addScript('settings', 'users/filter');
  11. OC_Util::addScript( 'settings', 'users/users' );
  12. OC_Util::addScript( 'settings', 'users/groups' );
  13. OC_Util::addScript( 'core', 'multiselect' );
  14. OC_Util::addScript( 'core', 'singleselect' );
  15. OC_Util::addStyle( 'settings', 'settings' );
  16. OC_App::setActiveNavigationEntry( 'core_users' );
  17. $users = array();
  18. $userManager = \OC_User::getManager();
  19. $groupManager = \OC_Group::getManager();
  20. $isAdmin = OC_User::isAdminUser(OC_User::getUser());
  21. $groupsInfo = new \OC\Group\MetaData(OC_User::getUser(), $isAdmin, $groupManager);
  22. $groupsInfo->setSorting($groupsInfo::SORT_USERCOUNT);
  23. list($adminGroup, $groups) = $groupsInfo->get();
  24. $recoveryAdminEnabled = OC_App::isEnabled('files_encryption') &&
  25. OC_Appconfig::getValue( 'files_encryption', 'recoveryAdminEnabled' );
  26. if($isAdmin) {
  27. $accessibleUsers = OC_User::getDisplayNames('', 30);
  28. $subadmins = OC_SubAdmin::getAllSubAdmins();
  29. }else{
  30. /* Retrieve group IDs from $groups array, so we can pass that information into OC_Group::displayNamesInGroups() */
  31. $gids = array();
  32. foreach($groups as $group) {
  33. if (isset($group['id'])) {
  34. $gids[] = $group['id'];
  35. }
  36. }
  37. $accessibleUsers = OC_Group::displayNamesInGroups($gids, '', 30);
  38. $subadmins = false;
  39. }
  40. // load preset quotas
  41. $quotaPreset=OC_Appconfig::getValue('files', 'quota_preset', '1 GB, 5 GB, 10 GB');
  42. $quotaPreset=explode(',', $quotaPreset);
  43. foreach($quotaPreset as &$preset) {
  44. $preset=trim($preset);
  45. }
  46. $quotaPreset=array_diff($quotaPreset, array('default', 'none'));
  47. $defaultQuota=OC_Appconfig::getValue('files', 'default_quota', 'none');
  48. $defaultQuotaIsUserDefined=array_search($defaultQuota, $quotaPreset)===false
  49. && array_search($defaultQuota, array('none', 'default'))===false;
  50. // load users and quota
  51. foreach($accessibleUsers as $uid => $displayName) {
  52. $quota = OC_Preferences::getValue($uid, 'files', 'quota', 'default');
  53. $isQuotaUserDefined = array_search($quota, $quotaPreset) === false
  54. && array_search($quota, array('none', 'default')) === false;
  55. $name = $displayName;
  56. if ($displayName !== $uid) {
  57. $name = $name . ' (' . $uid . ')';
  58. }
  59. $user = $userManager->get($uid);
  60. $users[] = array(
  61. "name" => $uid,
  62. "displayName" => $displayName,
  63. "groups" => OC_Group::getUserGroups($uid),
  64. 'quota' => $quota,
  65. 'isQuotaUserDefined' => $isQuotaUserDefined,
  66. 'subadmin' => OC_SubAdmin::getSubAdminsGroups($uid),
  67. 'storageLocation' => $user->getHome(),
  68. 'lastLogin' => $user->getLastLogin(),
  69. );
  70. }
  71. $tmpl = new OC_Template("settings", "users/main", "user");
  72. $tmpl->assign('users', $users);
  73. $tmpl->assign('groups', $groups);
  74. $tmpl->assign('adminGroup', $adminGroup);
  75. $tmpl->assign('isAdmin', (int)$isAdmin);
  76. $tmpl->assign('subadmins', $subadmins);
  77. $tmpl->assign('numofgroups', count($groups) + count($adminGroup));
  78. $tmpl->assign('quota_preset', $quotaPreset);
  79. $tmpl->assign('default_quota', $defaultQuota);
  80. $tmpl->assign('defaultQuotaIsUserDefined', $defaultQuotaIsUserDefined);
  81. $tmpl->assign('recoveryAdminEnabled', $recoveryAdminEnabled);
  82. $tmpl->assign('enableAvatars', \OC::$server->getConfig()->getSystemValue('enable_avatars', true));
  83. $tmpl->printPage();