<?php
include('action.abs.php');
class setting extends action{
	function setting() {
		parent :: action();
	}
	/*
	function clean() {
		$config = APP::N('sysConfig');	
		$data = array(
			'rewrite_enable' => 0
			);
		$config->set($data);
		$config->save(true);
		var_dump($config->get());
	}
	 */
	function upload() {
		if ($this->_isPost()) {
			$file = V('f:logo');
			$state = 200;
			while ($file && $file['tmp_name']) {
				if ($file['size'] > 500 * 1024) {
					$state = '上传LOGO的大小不能超过500K';
					break;
				}
				$info = getimagesize($file['tmp_name']);
				if ($info[2] != 3) {
					$state = '上传的图片文件不为PNG格式，请重新选择';
					break;
				}
				if (!move_uploaded_file($file['tmp_name'], P_VAR . WB_LOGO_PREVIEW_FILE_NAME)) {
					$state = '复制文件时出错,上传失败';
					break;
				}
				$logo = W_BASE_URL . P_VAR_NAME .WB_LOGO_PREVIEW_FILE_NAME;
				break;
			}
			echo '<script>parent.uploadFinished("' . $state. '","' . $logo . '");</script>';
		}
	}
	function edit() {
		$config = APP::N('sysConfig');
		if ($this->_isPost()) {
			$file = V('p:logo');
			if ($file && is_file(P_VAR . WB_LOGO_PREVIEW_FILE_NAME)) {
				copy(P_VAR . WB_LOGO_PREVIEW_FILE_NAME, P_VAR . WB_LOGO_FILE_NAME);
				$logo = W_BASE_URL . P_VAR_NAME .WB_LOGO_FILE_NAME;
			}
			$data = array(
				'rewrite_enable' => V('p:rewrite_enable', '0'),
				'logo' => $logo,
				'bind_enable' => V('p:bind_enable', 0),
				'each_page_wb' => V('p:each_page_wb', 20),
				'each_page_comment' => V('p:each_page_comment', 20),
				'display_head' => V('p:display_head', '0'),
				'header_html' => V('p:header',''),
				'footer_html' => V('p:footer','')
				);
			$config->set($data);
			$config->save(true);
			$this->_succ('已经成功保存你的配置', array('edit'));
			exit;
		}
		$d = $config->get();
		if ($d) {
			TPL::assign('config', $d);
		}
		$this->_display('setting');
	}
}
