<?php
/*
秀影EasyFramework框架
qq:24498936
msn:jdzcn_net@hotmail.com
website:http://www.vodcms.com
*/
class ConfigController extends Easy_Controller_Action {
	public function  init(){
		$this->_IO = new Easy_Filesystem();
		$this->_View->config = $this->config;
	}
	public function IndexAction(){
		$filename = ROOT.'Config/config.inc.php';
		@chmod($filename, 0777);
		$Group = new GroupModel();
		$this->_View->vipoption = $Group->CreateOption((int)$this->config['vip']);
		if ($this->_Request->isPost()){
			$POST = $this->_Request->getPost();
			$str = str_replace('index.php/', '', substr($_SERVER['REQUEST_URI'],0,strpos($_SERVER['REQUEST_URI'], 'config')));
			$POST['basedir'] = $str;
			foreach ($POST as $key=>$value){
				if (is_numeric($value)){
					$data.= "\$config['$key'] = ".intval($value).";\n";
				}else{
					$data.= "\$config['$key'] = '".addslashes($value)."';\n";
				}
			}
			$data= "<?php \n".$data."\n?>";
			if ($this->_IO->wfile($filename, $data)===false){
				$this->_View->message = $IO->error;
			}else{
				$this->_View->message = _('保存配置成功!');
			}
			$Vodcms = new VodcmsModel();
			$Vodcms->clean();
			exit($this->_View->render('message'));
		}
	}
	public function SeoAction(){
		
	}
	public function userAction(){
		$filename = ROOT.'Config/user.xml';
		$this->_User = new UsersModel();
		$this->_View->xml = new Easy_Config();
		$this->_View->xml->set($filename);
		$this->_View->groupOption = $this->_User->groupOption($this->_View->xml->usergroup);
		$this->_View->vipOption = $this->_User->groupOption($this->_View->xml->vipgroup);
		if ($this->_Request->isPost()){
			$data = '';
			foreach ($this->_Request->getPost() as $key=>$value){
				$data.= "<$key>$value</$key>\n";
			}
			$data= '<?xml version="1.0" encoding="gb2312"?>
			<userconfig>
			'.$data;
			$data.= '</userconfig>';
			$this->_IO->wfile($filename, $data);
			$contents = file_get_contents(ROOT.'Config/config.inc.php');
			$ucenter = intval($this->_Request->getPost('ucenter'));
			echo $ucenter;
			$contents = preg_replace('/\$config[\'ucenter\']+\s+\=+\s+(\d+);/is', '$config[\'ucenter\'] = '.$ucenter, $contents);
			echo $contents; 
			$this->_View->message = _('保存成功!');
			exit($this->_View->render('message'));
		}
	}
}?>