users.php 5.0 KB

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