<?php
if (! defined ( 'APP_PATH' ) || ! defined ( 'I_PATH' )) {
	exit ( 'Access Denied' );
}

class ld_setting_template extends controllerBase {
	function __construct() {
		parent::__construct ();
		$this->a = $this->sysParams ( 'a', 1 );
	}
	function index() {
		$this->toptxt = '选择模板';
		$tpl_list = array ();
		if($this->sysParams("go"))
		{
			$view_themes = $_REQUEST['view_themes'];// $this-> sysParams("view_themes");
			$configfile='config.php';
			$fp_tp=@fopen($configfile,"r");
			$fp_txt=@fread($fp_tp,filesize($configfile));
			@fclose($fp_tp);
			$fp_txt=preg_replace("/'view_themes' => '.*?',/","'view_themes' => '".$view_themes."',",$fp_txt);
			$fpt_tpl=@fopen($configfile,"w");
			
			@fwrite($fpt_tpl,$fp_txt);
			@fclose($fpt_tpl);
			message_a("模板设置成功",'?c=ld_setting_template');
		}
		$default_tpl_pic="/uploads/tpl_pic.jpg";
		$dir = APP_PATH . "/template";
		$fso = opendir ( $dir );
		while ( $flist = readdir ( $fso ) ) {
			$t=$dir."/".$flist;
			if(file_exists($t."/default.jpg"))
			{
				$tpl_list[$flist]="/template/".$flist."/default.jpg";
			}
			else 
			{
				$tpl_list[$flist]=$default_tpl_pic;
			}
		}
		closedir ( $fso );
		$this->molds="setting_template";	
		$this->tpl_list = $tpl_list;
		$this->view_themes = $GLOBALS ['LD_I'] ['ext'] ['view_themes'];
		$this->display ( "setting_template.html" );
	}
}	