@@ -7,12 +7,51 @@ class AdminController extends AppController
7
7
{
8
8
public $ _models =array ();
9
9
public $ _daos =array ();
10
- public $ _components =array ('Upgrade ' );
10
+ public $ _components =array ('Upgrade ' ,'Utility ' );
11
+ public $ _forms =array ('Admin ' );
11
12
12
13
/** index*/
13
14
function indexAction ()
14
15
{
16
+ if (!$ this ->logged ||!$ this ->userSession ->Dao ->getAdmin ()==1 )
17
+ {
18
+ throw new Zend_Exception ("You should be an administrator " );
19
+ }
20
+ $ this ->view ->header ="Administration " ;
21
+ $ configForm =$ this ->Form ->Admin ->createConfigForm ();
22
+
23
+ $ applicationConfig =parse_ini_file (BASE_PATH .'/core/configs/application.local.ini ' ,true );
24
+ $ formArray =$ this ->getFormAsArray ($ configForm );
15
25
26
+ $ formArray ['name ' ]->setValue ($ applicationConfig ['global ' ]['application.name ' ]);
27
+ $ formArray ['environment ' ]->setValue ($ applicationConfig ['global ' ]['environment ' ]);
28
+ $ formArray ['lang ' ]->setValue ($ applicationConfig ['global ' ]['application.lang ' ]);
29
+ $ formArray ['smartoptimizer ' ]->setValue ($ applicationConfig ['global ' ]['smartoptimizer ' ]);
30
+ $ formArray ['timezone ' ]->setValue ($ applicationConfig ['global ' ]['default.timezone ' ]);
31
+ $ this ->view ->configForm =$ formArray ;
32
+
33
+ if ($ this ->_request ->isPost ())
34
+ {
35
+ $ this ->_helper ->layout ->disableLayout ();
36
+ $ this ->_helper ->viewRenderer ->setNoRender ();
37
+ $ submitConfig =$ this ->_getParam ('submitConfig ' );
38
+ if (isset ($ submitConfig ))
39
+ {
40
+ $ applicationConfig =parse_ini_file (BASE_PATH .'/core/configs/application.local.ini ' ,true );
41
+ if (file_exists ( BASE_PATH .'/core/configs/application.local.ini.old ' ))
42
+ {
43
+ unlink ( BASE_PATH .'/core/configs/application.local.ini.old ' );
44
+ }
45
+ rename (BASE_PATH .'/core/configs/application.local.ini ' , BASE_PATH .'/core/configs/application.local.ini.old ' );
46
+ $ applicationConfig ['global ' ]['application.name ' ]=$ this ->_getParam ('name ' );
47
+ $ applicationConfig ['global ' ]['application.lang ' ]=$ this ->_getParam ('lang ' );
48
+ $ applicationConfig ['global ' ]['environment ' ]=$ this ->_getParam ('environment ' );
49
+ $ applicationConfig ['global ' ]['smartoptimizer ' ]=$ this ->_getParam ('smartoptimizer ' );
50
+ $ applicationConfig ['global ' ]['default.timezone ' ]=$ this ->_getParam ('timezone ' );
51
+ $ this ->Component ->Utility ->createInitFile (BASE_PATH .'/core/configs/application.local.ini ' , $ applicationConfig );
52
+ echo JsonComponent::encode (array (true ,'Changed saved ' ));
53
+ }
54
+ }
16
55
}//end indexAction
17
56
18
57
@@ -23,13 +62,19 @@ function upgradeAction()
23
62
{
24
63
throw new Zend_Exception ("You should be an administrator " );
25
64
}
65
+ if (!$ this ->getRequest ()->isXmlHttpRequest ())
66
+ {
67
+ throw new Zend_Exception ("Why are you here ? Should be ajax. " );
68
+ }
69
+ $ this ->_helper ->layout ->disableLayout ();
26
70
27
71
$ db =Zend_Registry::get ('dbAdapter ' );
28
72
$ dbtype =Zend_Registry::get ('configDatabase ' )->database ->adapter ;
29
73
$ modulesConfig =Zend_Registry::get ('configsModules ' );
30
74
31
75
if ($ this ->_request ->isPost ())
32
76
{
77
+ $ this ->_helper ->viewRenderer ->setNoRender ();
33
78
$ upgraded =false ;
34
79
$ modulesConfig =Zend_Registry::get ('configsModules ' );
35
80
$ modules =array ();
@@ -44,6 +89,15 @@ function upgradeAction()
44
89
45
90
$ dbtype =Zend_Registry::get ('configDatabase ' )->database ->adapter ;
46
91
$ modulesConfig =Zend_Registry::get ('configsModules ' );
92
+ if ($ upgraded )
93
+ {
94
+ echo JsonComponent::encode (array (true ,'Upgraded ' ));
95
+ }
96
+ else
97
+ {
98
+ echo JsonComponent::encode (array (true ,'Nothing to upgrade ' ));
99
+ }
100
+ return ;
47
101
}
48
102
49
103
$ modules =array ();
0 commit comments