users.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. * @author Bart Visscher <bartv@thisnet.nl>
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Clark Tomlinson <fallen013@gmail.com>
  7. * @author Daniel Molkentin <daniel@molkentin.de>
  8. * @author Georg Ehrke <georg@owncloud.com>
  9. * @author Jakob Sack <mail@jakobsack.de>
  10. * @author Joas Schilling <nickvergessen@owncloud.com>
  11. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  12. * @author Lukas Reschke <lukas@statuscode.ch>
  13. * @author Morris Jobke <hey@morrisjobke.de>
  14. * @author Robin Appelman <icewind@owncloud.com>
  15. * @author Robin McCorkell <robin@mccorkell.me.uk>
  16. * @author Roeland Jago Douma <rullzer@owncloud.com>
  17. * @author Stephan Peijnik <speijnik@anexia-it.com>
  18. * @author Thomas Müller <thomas.mueller@tmit.eu>
  19. *
  20. * @copyright Copyright (c) 2016, ownCloud, Inc.
  21. * @license AGPL-3.0
  22. *
  23. * This code is free software: you can redistribute it and/or modify
  24. * it under the terms of the GNU Affero General Public License, version 3,
  25. * as published by the Free Software Foundation.
  26. *
  27. * This program is distributed in the hope that it will be useful,
  28. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30. * GNU Affero General Public License for more details.
  31. *
  32. * You should have received a copy of the GNU Affero General Public License, version 3,
  33. * along with this program. If not, see <http://www.gnu.org/licenses/>
  34. *
  35. */
  36. OC_Util::checkSubAdminUser();
  37. \OC::$server->getNavigationManager()->setActiveEntry('core_users');
  38. $userManager = \OC::$server->getUserManager();
  39. $groupManager = \OC_Group::getManager();
  40. // Set the sort option: SORT_USERCOUNT or SORT_GROUPNAME
  41. $sortGroupsBy = \OC\Group\MetaData::SORT_USERCOUNT;
  42. if (\OC_App::isEnabled('user_ldap')) {
  43. $isLDAPUsed =
  44. $groupManager->isBackendUsed('\OCA\User_LDAP\Group_LDAP')
  45. || $groupManager->isBackendUsed('\OCA\User_LDAP\Group_Proxy');
  46. if ($isLDAPUsed) {
  47. // LDAP user count can be slow, so we sort by group name here
  48. $sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME;
  49. }
  50. }
  51. $config = \OC::$server->getConfig();
  52. $isAdmin = OC_User::isAdminUser(OC_User::getUser());
  53. $groupsInfo = new \OC\Group\MetaData(
  54. OC_User::getUser(),
  55. $isAdmin,
  56. $groupManager,
  57. \OC::$server->getUserSession()
  58. );
  59. $groupsInfo->setSorting($sortGroupsBy);
  60. list($adminGroup, $groups) = $groupsInfo->get();
  61. $recoveryAdminEnabled = OC_App::isEnabled('encryption') &&
  62. $config->getAppValue( 'encryption', 'recoveryAdminEnabled', null );
  63. if($isAdmin) {
  64. $subAdmins = \OC::$server->getGroupManager()->getSubAdmin()->getAllSubAdmins();
  65. // New class returns IUser[] so convert back
  66. $result = [];
  67. foreach ($subAdmins as $subAdmin) {
  68. $result[] = [
  69. 'gid' => $subAdmin['group']->getGID(),
  70. 'uid' => $subAdmin['user']->getUID(),
  71. ];
  72. }
  73. $subAdmins = $result;
  74. }else{
  75. /* Retrieve group IDs from $groups array, so we can pass that information into OC_Group::displayNamesInGroups() */
  76. $gids = array();
  77. foreach($groups as $group) {
  78. if (isset($group['id'])) {
  79. $gids[] = $group['id'];
  80. }
  81. }
  82. $subAdmins = false;
  83. }
  84. // load preset quotas
  85. $quotaPreset=$config->getAppValue('files', 'quota_preset', '1 GB, 5 GB, 10 GB');
  86. $quotaPreset=explode(',', $quotaPreset);
  87. foreach($quotaPreset as &$preset) {
  88. $preset=trim($preset);
  89. }
  90. $quotaPreset=array_diff($quotaPreset, array('default', 'none'));
  91. $defaultQuota=$config->getAppValue('files', 'default_quota', 'none');
  92. $defaultQuotaIsUserDefined=array_search($defaultQuota, $quotaPreset)===false
  93. && array_search($defaultQuota, array('none', 'default'))===false;
  94. \OC::$server->getEventDispatcher()->dispatch('OC\Settings\Users::loadAdditionalScripts');
  95. $tmpl = new OC_Template("settings", "users/main", "user");
  96. $tmpl->assign('groups', $groups);
  97. $tmpl->assign('sortGroups', $sortGroupsBy);
  98. $tmpl->assign('adminGroup', $adminGroup);
  99. $tmpl->assign('isAdmin', (int)$isAdmin);
  100. $tmpl->assign('subadmins', $subAdmins);
  101. $tmpl->assign('numofgroups', count($groups) + count($adminGroup));
  102. $tmpl->assign('quota_preset', $quotaPreset);
  103. $tmpl->assign('default_quota', $defaultQuota);
  104. $tmpl->assign('defaultQuotaIsUserDefined', $defaultQuotaIsUserDefined);
  105. $tmpl->assign('recoveryAdminEnabled', $recoveryAdminEnabled);
  106. $tmpl->assign('enableAvatars', \OC::$server->getConfig()->getSystemValue('enable_avatars', true) === true);
  107. $tmpl->assign('show_storage_location', $config->getAppValue('core', 'umgmt_show_storage_location', 'false'));
  108. $tmpl->assign('show_last_login', $config->getAppValue('core', 'umgmt_show_last_login', 'false'));
  109. $tmpl->assign('show_email', $config->getAppValue('core', 'umgmt_show_email', 'false'));
  110. $tmpl->assign('show_backend', $config->getAppValue('core', 'umgmt_show_backend', 'false'));
  111. $tmpl->assign('send_email', $config->getAppValue('core', 'umgmt_send_email', 'false'));
  112. $tmpl->printPage();