1
+ <?php
2
+ /*=========================================================================
3
+ MIDAS Server
4
+ Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5
+ All rights reserved.
6
+ More information http://www.kitware.com
7
+
8
+ Licensed under the Apache License, Version 2.0 (the "License");
9
+ you may not use this file except in compliance with the License.
10
+ You may obtain a copy of the License at
11
+
12
+ http://www.apache.org/licenses/LICENSE-2.0.txt
13
+
14
+ Unless required by applicable law or agreed to in writing, software
15
+ distributed under the License is distributed on an "AS IS" BASIS,
16
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ See the License for the specific language governing permissions and
18
+ limitations under the License.
19
+ =========================================================================*/
20
+
21
+ /** sizequota main config controller */
22
+ class Sizequota_ConfigController extends Sizequota_AppController
23
+ {
24
+ public $ _moduleForms = array ('Config ' );
25
+
26
+ /** index action*/
27
+ function indexAction ()
28
+ {
29
+ $ this ->requireAdminPrivileges ();
30
+
31
+ $ modelLoader = new MIDAS_ModelLoader ();
32
+ $ settingModel = $ modelLoader ->loadModel ('Setting ' );
33
+ $ defaultUserQuota = $ settingModel ->getValueByName ('defaultuserquota ' , $ this ->moduleName );
34
+ $ defaultCommunityQuota = $ settingModel ->getValueByName ('defaultcommunityquota ' , $ this ->moduleName );
35
+
36
+ $ configForm = $ this ->ModuleForm ->Config ->createConfigForm ();
37
+ $ formArray = $ this ->getFormAsArray ($ configForm );
38
+ if ($ defaultUserQuota !== null )
39
+ {
40
+ $ formArray ['defaultuserquota ' ]->setValue ($ defaultUserQuota );
41
+ }
42
+ if ($ defaultCommunityQuota !== null )
43
+ {
44
+ $ formArray ['defaultcommunityquota ' ]->setValue ($ defaultCommunityQuota );
45
+ }
46
+ $ this ->view ->configForm = $ formArray ;
47
+
48
+ if ($ this ->_request ->isPost ())
49
+ {
50
+ $ this ->disableLayout ();
51
+ $ this ->_helper ->viewRenderer ->setNoRender ();
52
+ $ submitConfig = $ this ->_getParam ('submitConfig ' );
53
+ if (isset ($ submitConfig ))
54
+ {
55
+ $ defaultUserQuota = $ this ->_getParam ('defaultuserquota ' );
56
+ $ defaultCommunityQuota = $ this ->_getParam ('defaultcommunityquota ' );
57
+ if (!$ this ->_isValidQuota (array ($ defaultUserQuota , $ defaultCommunityQuota )))
58
+ {
59
+ echo JsonComponent::encode (array (false , 'Invalid quota value. Please enter a positive integer. ' ));
60
+ return ;
61
+ }
62
+ $ settingModel ->setConfig ('defaultuserquota ' , $ defaultUserQuota , $ this ->moduleName );
63
+ $ settingModel ->setConfig ('defaultcommunityquota ' , $ defaultCommunityQuota , $ this ->moduleName );
64
+ echo JsonComponent::encode (array (true , 'Changes saved ' ));
65
+ }
66
+ }
67
+ }
68
+
69
+ /** Test whether the provided quota value is legal */
70
+ private function _isValidQuota ($ quotas )
71
+ {
72
+ foreach ($ quotas as $ quota )
73
+ {
74
+ if (!preg_match ('/^[0-9]*$/ ' , $ quota ))
75
+ {
76
+ return false ;
77
+ }
78
+ }
79
+ return true ;
80
+ }
81
+
82
+ }//end class
0 commit comments