<?php
/**
* FILE_NAME : cache.php
*
* @copyright Copyright (c) 2009 - 2010 www.dali.edu.cn
* @author DaLi University 2009 Graduation Design
* @package 基本缓存文件
* @subpackage
* @version Thu Sep 15 10:34:56 GMT 2009
*/

if(!defined('IN_WEB')) {
	exit('Access Denied');
}

// 更新设置选项
function recache()	{
	global $DB, $dbprefix;
	$settings = $DB->query("SELECT variable, value FROM {$dbprefix}settings");
	$contents = "\$_CFG = array(\r\n";
        while ($setting = $DB->fetch_array($settings)) {
			$contents.="\t'".addslashes($setting['variable'])."' => '".addslashes($setting['value'])."',\r\n";	}
			$contents .= ');';
			writecache('settings',$contents);
	}

// 写入缓存文件
function writecache($cachename, $cachedata = '') {
	$cachedir = WEB_ROOT.'cache/';
	$cachefile = $cachedir.$cachename.'.php';
	if(!is_dir($cachedir)) {
		mkdir($cachedir, 0777);
	}
	if($fp = fopen($cachefile, 'wb')) {
		fwrite($fp, "<?php\r\nif(!defined('IN_WEB')) exit('Access Denied');\r\n\r\n".$cachedata."\r\n\r\n?>");
		fclose($fp);
		chmod($cachefile, 0777);
	} else {
		echo 'Can not write to cache files, please check directory ./cache/ .';
		exit;
	}
}

?>