setquota.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * Copyright (c) 2012, 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_JSON::checkSubAdminUser();
  8. OCP\JSON::callCheck();
  9. $username = isset($_POST["username"])?$_POST["username"]:'';
  10. if(($username == '' && !OC_Group::inGroup(OC_User::getUser(), 'admin')) || (!OC_Group::inGroup(OC_User::getUser(), 'admin') && !OC_SubAdmin::isUserAccessible(OC_User::getUser(), $username))) {
  11. $l = OC_L10N::get('core');
  12. OC_JSON::error(array( 'data' => array( 'message' => $l->t('Authentication error') )));
  13. exit();
  14. }
  15. //make sure the quota is in the expected format
  16. $quota=$_POST["quota"];
  17. if($quota!='none' and $quota!='default') {
  18. $quota= OC_Helper::computerFileSize($quota);
  19. if($quota==0) {
  20. $quota='default';
  21. }else{
  22. $quota=OC_Helper::humanFileSize($quota);
  23. }
  24. }
  25. // Return Success story
  26. if($username) {
  27. OC_Preferences::setValue($username, 'files', 'quota', $quota);
  28. }else{//set the default quota when no username is specified
  29. if($quota=='default') {//'default' as default quota makes no sense
  30. $quota='none';
  31. }
  32. OC_Appconfig::setValue('files', 'default_quota', $quota);
  33. }
  34. OC_JSON::success(array("data" => array( "username" => $username , 'quota' => $quota)));