You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

users.php 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. $config = \OC::$server->getConfig();
  44. if ($config->getSystemValue('sort_groups_by_name', false)) {
  45. $sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME;
  46. } else {
  47. $isLDAPUsed = false;
  48. if (\OC_App::isEnabled('user_ldap')) {
  49. $isLDAPUsed =
  50. $groupManager->isBackendUsed('\OCA\User_LDAP\Group_LDAP')
  51. || $groupManager->isBackendUsed('\OCA\User_LDAP\Group_Proxy');
  52. if ($isLDAPUsed) {
  53. // LDAP user count can be slow, so we sort by group name here
  54. $sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME;
  55. }
  56. }
  57. }
  58. $isAdmin = OC_User::isAdminUser(OC_User::getUser());
  59. $isDisabled = !OC_User::isEnabled(OC_User::getUser());
  60. $groupsInfo = new \OC\Group\MetaData(
  61. OC_User::getUser(),
  62. $isAdmin,
  63. $groupManager,
  64. \OC::$server->getUserSession()
  65. );
  66. $groupsInfo->setSorting($sortGroupsBy);
  67. list($adminGroup, $groups) = $groupsInfo->get();
  68. $recoveryAdminEnabled = OC_App::isEnabled('encryption') &&
  69. $config->getAppValue( 'encryption', 'recoveryAdminEnabled', '0');
  70. if($isAdmin) {
  71. $subAdmins = \OC::$server->getGroupManager()->getSubAdmin()->getAllSubAdmins();
  72. // New class returns IUser[] so convert back
  73. $result = [];
  74. foreach ($subAdmins as $subAdmin) {
  75. $result[] = [
  76. 'gid' => $subAdmin['group']->getGID(),
  77. 'uid' => $subAdmin['user']->getUID(),
  78. ];
  79. }
  80. $subAdmins = $result;
  81. }else{
  82. /* Retrieve group IDs from $groups array, so we can pass that information into OC_Group::displayNamesInGroups() */
  83. $gids = array();
  84. foreach($groups as $group) {
  85. if (isset($group['id'])) {
  86. $gids[] = $group['id'];
  87. }
  88. }
  89. $subAdmins = false;
  90. }
  91. $disabledUsers = $isLDAPUsed ? 0 : $userManager->countDisabledUsers();
  92. $disabledUsersGroup = [
  93. 'id' => '_disabledUsers',
  94. 'name' => '_disabledUsers',
  95. 'usercount' => $disabledUsers
  96. ];
  97. // load preset quotas
  98. $quotaPreset=$config->getAppValue('files', 'quota_preset', '1 GB, 5 GB, 10 GB');
  99. $quotaPreset=explode(',', $quotaPreset);
  100. foreach($quotaPreset as &$preset) {
  101. $preset=trim($preset);
  102. }
  103. $quotaPreset=array_diff($quotaPreset, array('default', 'none'));
  104. $defaultQuota=$config->getAppValue('files', 'default_quota', 'none');
  105. $defaultQuotaIsUserDefined=array_search($defaultQuota, $quotaPreset)===false
  106. && array_search($defaultQuota, array('none', 'default'))===false;
  107. \OC::$server->getEventDispatcher()->dispatch('OC\Settings\Users::loadAdditionalScripts');
  108. $tmpl = new OC_Template("settings", "users/main", "user");
  109. $tmpl->assign('groups', $groups);
  110. $tmpl->assign('sortGroups', $sortGroupsBy);
  111. $tmpl->assign('adminGroup', $adminGroup);
  112. $tmpl->assign('disabledUsersGroup', $disabledUsersGroup);
  113. $tmpl->assign('isAdmin', (int)$isAdmin);
  114. $tmpl->assign('subadmins', $subAdmins);
  115. $tmpl->assign('numofgroups', count($groups) + count($adminGroup));
  116. $tmpl->assign('quota_preset', $quotaPreset);
  117. $tmpl->assign('default_quota', $defaultQuota);
  118. $tmpl->assign('defaultQuotaIsUserDefined', $defaultQuotaIsUserDefined);
  119. $tmpl->assign('recoveryAdminEnabled', $recoveryAdminEnabled);
  120. $tmpl->assign('show_storage_location', $config->getAppValue('core', 'umgmt_show_storage_location', 'false'));
  121. $tmpl->assign('show_last_login', $config->getAppValue('core', 'umgmt_show_last_login', 'false'));
  122. $tmpl->assign('show_email', $config->getAppValue('core', 'umgmt_show_email', 'false'));
  123. $tmpl->assign('show_backend', $config->getAppValue('core', 'umgmt_show_backend', 'false'));
  124. $tmpl->assign('send_email', $config->getAppValue('core', 'umgmt_send_email', 'false'));
  125. $tmpl->printPage();