summaryrefslogtreecommitdiff
path: root/demos/blog/protected/Pages/Admin/ConfigMan.php
blob: be5e3983555f358e40e6b285c375953fa62d2abb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
 * ConfigMan class file
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @link http://www.pradosoft.com/
 * @copyright Copyright &copy; 2006 PradoSoft
 * @license http://www.pradosoft.com/license/
 * @version $Id: ConfigMan.php 3189 2012-07-12 12:16:21Z ctrlaltca $
 */

/**
 * ConfigMan class
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @link http://www.pradosoft.com/
 * @copyright Copyright &copy; 2006 PradoSoft
 * @license http://www.pradosoft.com/license/
 */
class ConfigMan extends BlogPage
{
	const CONFIG_FILE='Application.Data.Settings';

	public function onLoad($param)
	{
		parent::onLoad($param);
		if(!$this->IsPostBack)
		{
			$parameters=$this->Application->Parameters;
			$this->SiteTitle->Text=$parameters['SiteTitle'];
			$this->SiteSubtitle->Text=$parameters['SiteSubtitle'];
			$this->SiteOwner->Text=$parameters['SiteOwner'];
			$this->AdminEmail->Text=$parameters['AdminEmail'];
			$this->MultipleUser->Checked=TPropertyValue::ensureBoolean($parameters['MultipleUser']);
			$this->AccountApproval->Checked=TPropertyValue::ensureBoolean($parameters['AccountApproval']);
			$this->PostPerPage->Text=$parameters['PostPerPage'];
			$this->RecentComments->Text=$parameters['RecentComments'];
			$this->PostApproval->Checked=TPropertyValue::ensureBoolean($parameters['PostApproval']);
			$themes=$this->Service->ThemeManager->AvailableThemes;
			$this->ThemeName->DataSource=$themes;
			$this->ThemeName->dataBind();
			$this->ThemeName->SelectedValue=array_search($parameters['ThemeName'],$themes);
		}
	}

	public function saveButtonClicked($sender,$param)
	{
		$dom=new TXmlDocument;
		$dom->Encoding='utf-8';
		$dom->TagName='parameters';
		$elements=$dom->Elements;
		$elements[]=$this->createParameter('SiteTitle',$this->SiteTitle->Text);
		$elements[]=$this->createParameter('SiteSubtitle',$this->SiteSubtitle->Text);
		$elements[]=$this->createParameter('SiteOwner',$this->SiteOwner->Text);
		$elements[]=$this->createParameter('AdminEmail',$this->AdminEmail->Text);
		$elements[]=$this->createParameter('MultipleUser',$this->MultipleUser->Checked);
		$elements[]=$this->createParameter('AccountApproval',$this->AccountApproval->Checked);
		$elements[]=$this->createParameter('PostPerPage',$this->PostPerPage->Text);
		$elements[]=$this->createParameter('RecentComments',$this->RecentComments->Text);
		$elements[]=$this->createParameter('PostApproval',$this->PostApproval->Checked);
		$themeName=$this->ThemeName->SelectedItem->Text;
		$elements[]=$this->createParameter('ThemeName',$themeName);
		$dom->saveToFile(Prado::getPathOfNamespace(self::CONFIG_FILE,'.xml'));
		if($themeName!==$this->Theme->Name)
			$this->Response->reload();
	}

	private function createParameter($id,$value)
	{
		$element=new TXmlElement('parameter');
		$element->Attributes['id']=$id;
		$element->Attributes['value']=TPropertyValue::ensureString($value);
		return $element;
	}
}