users.php 4.7 KB

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