Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit d2af82c

Browse files
author
Charles Marion
committed
ENH: Added administration page (only config and upgrade tabs)
1 parent 9a9034e commit d2af82c

File tree

9 files changed

+259
-27
lines changed

9 files changed

+259
-27
lines changed

core/controllers/AdminController.php

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,51 @@ class AdminController extends AppController
77
{
88
public $_models=array();
99
public $_daos=array();
10-
public $_components=array('Upgrade');
10+
public $_components=array('Upgrade','Utility');
11+
public $_forms=array('Admin');
1112

1213
/** index*/
1314
function indexAction()
1415
{
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);
1525

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+
}
1655
}//end indexAction
1756

1857

@@ -23,13 +62,19 @@ function upgradeAction()
2362
{
2463
throw new Zend_Exception("You should be an administrator");
2564
}
65+
if(!$this->getRequest()->isXmlHttpRequest())
66+
{
67+
throw new Zend_Exception("Why are you here ? Should be ajax.");
68+
}
69+
$this->_helper->layout->disableLayout();
2670

2771
$db=Zend_Registry::get('dbAdapter');
2872
$dbtype=Zend_Registry::get('configDatabase')->database->adapter;
2973
$modulesConfig=Zend_Registry::get('configsModules');
3074

3175
if($this->_request->isPost())
3276
{
77+
$this->_helper->viewRenderer->setNoRender();
3378
$upgraded=false;
3479
$modulesConfig=Zend_Registry::get('configsModules');
3580
$modules=array();
@@ -44,6 +89,15 @@ function upgradeAction()
4489

4590
$dbtype=Zend_Registry::get('configDatabase')->database->adapter;
4691
$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;
47101
}
48102

49103
$modules=array();

core/controllers/components/UpgradeComponent.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ public function transformVersionToNumeric($text)
108108
/** upgrade*/
109109
public function upgrade($currentVersion)
110110
{
111+
if(!isset($currentVersion))
112+
{
113+
throw new Zend_Exception("Please set the current version");
114+
}
111115
if(!is_numeric($currentVersion))
112116
{
113117
$currentVersion=$this->transformVersionToNumeric($currentVersion);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
class AdminForm extends AppForm
3+
{
4+
5+
/** create form */
6+
public function createConfigForm()
7+
{
8+
$form = new Zend_Form;
9+
10+
$form->setAction($this->webroot.'/admin/index')
11+
->setMethod('post');
12+
13+
$lang = new Zend_Form_Element_Select('lang');
14+
$lang ->addMultiOptions(array(
15+
'en' => 'English',
16+
'fr' => 'French'
17+
));
18+
19+
$timezone = new Zend_Form_Element_Select('timezone');
20+
$timezone ->addMultiOptions(array(
21+
'America/New_York' => 'America/New_York',
22+
'Europe/Paris' => 'Europe/Paris'
23+
));
24+
25+
$environment = new Zend_Form_Element_Select('environment');
26+
$environment ->addMultiOptions(array(
27+
'production' => 'Production' ,
28+
'development' => 'Development'
29+
));
30+
31+
$name = new Zend_Form_Element_Text('name');
32+
$name ->setRequired(true)
33+
->addValidator('NotEmpty', true);
34+
35+
$smartoptimizer = new Zend_Form_Element_Checkbox("smartoptimizer");
36+
37+
38+
$submit = new Zend_Form_Element_Submit('submitConfig');
39+
$submit ->setLabel('Save configuration');
40+
41+
$form->addElements(array($timezone,$environment,$lang,$name,$smartoptimizer,$submit));
42+
return $form;
43+
}
44+
} // end class
45+
?>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
div.viewSideBar input.globalButton{
2+
margin-left: 0px!important;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
div.viewSideBar input.globalButton{
2+
margin-left: 0px!important;
3+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
$(document).ready(function() {
2+
3+
tabs=$( "#tabsGeneric" ).tabs({
4+
});
5+
$("#tabsGeneric").show();
6+
$('img.tabsLoading').hide()
7+
8+
9+
$('#configForm').ajaxForm( {beforeSubmit: validateConfig, success: successConfig} );
10+
});
11+
12+
var tabs;
13+
14+
15+
16+
17+
18+
function validateConfig(formData, jqForm, options) {
19+
20+
}
21+
22+
function successConfig(responseText, statusText, xhr, form)
23+
{
24+
try {
25+
jsonResponse = jQuery.parseJSON(responseText);
26+
} catch (e) {
27+
alert("An error occured. Please check the logs.");
28+
return false;
29+
}
30+
if(jsonResponse==null)
31+
{
32+
createNotive('Error',4000);
33+
return;
34+
}
35+
if(jsonResponse[0])
36+
{
37+
createNotive(jsonResponse[1],4000);
38+
}
39+
else
40+
{
41+
createNotive(jsonResponse[1],4000);
42+
}
43+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
$('#upgradeMIDAS').ajaxForm( {beforeSubmit: validateUpgrade, success: successUpgrade} );
2+
3+
4+
5+
function validateUpgrade(formData, jqForm, options) {
6+
7+
}
8+
9+
function successUpgrade(responseText, statusText, xhr, form)
10+
{
11+
try {
12+
jsonResponse = jQuery.parseJSON(responseText);
13+
} catch (e) {
14+
alert("An error occured. Please check the logs.");
15+
return false;
16+
}
17+
if(jsonResponse==null)
18+
{
19+
createNotive('Error',4000);
20+
return;
21+
}
22+
if(jsonResponse[0])
23+
{
24+
tabs.tabs( "load" , 1);
25+
createNotive(jsonResponse[1],4000);
26+
}
27+
else
28+
{
29+
createNotive(jsonResponse[1],4000);
30+
}
31+
}

core/views/admin/index.phtml

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,66 @@
1-
admin
1+
<?php
2+
$this->headScript()->appendFile($this->coreWebroot . '/public/js/jquery/jquery.form.js');
3+
$this->headScript()->appendFile($this->coreWebroot . '/public/js/admin/admin.index.js');
4+
?>
5+
<link type="text/css" rel="stylesheet" href="<?php echo $this->coreWebroot?>/public/css/admin/admin.index.css" />
6+
<link type="text/css" rel="stylesheet" href="<?php echo $this->coreWebroot?>/public/css/common/common.genericPage.css" />
7+
<div class="viewMain">
8+
9+
<img class="tabsLoading" alt="" src="<?php echo $this->coreWebroot?>/public/images/icons/loading.gif" />
10+
<div class="tabs" id='tabsGeneric'>
11+
<ul>
12+
<li><a href="#tabs-configuration">Configuration</a></li>
13+
<li><a href="#tabs-assetstore">Assetstores</a></li>
14+
<li><a href="<?php echo $this->webroot?>/admin/upgrade">Upgrade</a></li>
15+
<li><a href="#tabs-modules">Modules</a></li>
16+
</ul>
17+
<div id="tabs-configuration">
18+
<?php
19+
echo "
20+
<form class='genericForm' id='configForm' method='{$this->configForm['method']}' action='{$this->configForm['action']}'>
21+
<h3>Configuration:</h3>
22+
<div class='installName'>
23+
<label for='name'>Application name</label>
24+
{$this->configForm['name']}
25+
</div>
26+
<div class='installLang'>
27+
<label for='lang'>Language</label>
28+
{$this->configForm['lang']}
29+
</div>
30+
<div class='installEnvironment'>
31+
<label for='environment'>Environment</label>
32+
{$this->configForm['environment']}
33+
</div>
34+
<div class='installTimezone'>
35+
<label for='environment'>Timezone</label>
36+
{$this->configForm['timezone']}
37+
</div>
38+
<div class='installSmartoptimizer'>
39+
<label for='smartoptimizer'>CSS and Javascript optimizer</label>
40+
{$this->configForm['smartoptimizer']}
41+
</div>
42+
<div>
43+
{$this->configForm['submitConfig']}
44+
</div>
45+
</form>";
46+
?>
47+
</div>
48+
<div id="tabs-assetstore">
49+
50+
</div>
51+
<div id="tabs-modules">
52+
53+
</div>
54+
</div>
55+
56+
</div>
57+
<div class="viewSideBar">
58+
59+
60+
</div>
61+
62+
63+
64+
65+
66+

core/views/admin/upgrade.phtml

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,16 @@
1-
<?php
2-
if(isset($this->upgraded))
3-
{
4-
if($this->upgraded)
5-
{
6-
echo "Upgraded";
7-
}
8-
else
9-
{
10-
echo "Nothing to upgrade";
11-
}
12-
}
13-
?>
1+
<link type="text/css" rel="stylesheet" href="<?php echo $this->coreWebroot?>/public/css/admin/admin.upgrade.css" />
2+
<script type="text/javascript" src="<?php echo $this->coreWebroot?>/public/js/admin/admin.upgrade.js"></script>
143

15-
<h4>Core :</h4>
4+
<h3>Core :</h3>
165
Current version: <?php echo $this->core['currentText']?> <br/>
176
<?php
187
if($this->core['current']<$this->core['target'])
198
{
209
echo "Need to upgrade to version: ".$this->core['targetText'];
21-
}
22-
else
23-
{
24-
2510
}
2611
?>
2712

28-
<h4>Modules:</h4>
13+
<h3>Modules:</h3>
2914
<?php
3015
foreach($this->modules as $name=>$module)
3116
{
@@ -35,12 +20,11 @@ foreach($this->modules as $name=>$module)
3520
{
3621
echo "Need to upgrade to version: ".$module['targetText'];
3722
}
38-
else
39-
{
40-
41-
}
23+
4224
}
4325
?>
44-
<form action="" method="post">
45-
<input type='submit' value="Upgrade"/>
26+
<br/>
27+
<br/>
28+
<form id='upgradeMIDAS' action="<?php echo $this->webroot?>/admin/upgrade" method="post">
29+
<input type='submit' class="globalButton" value="Upgrade"/>
4630
</form>

0 commit comments

Comments
 (0)