<?php
!function_exists('html') && exit('ERR');

if($job=="addstyle"&&$Apower[style_editstyle])
{
	$style_select=select_style('keywords');
	$CssCode="/******以下是默认的设置,你可以随便修改********/\r\n\r\n\r\n";
	$CssCode.=read_file(PHP168_PATH."images/default/style.css");
	require(dirname(__FILE__)."/"."head.php");
	require(dirname(__FILE__)."/"."template/style/menu.htm");
	require(dirname(__FILE__)."/"."template/style/style.htm");
	require(dirname(__FILE__)."/"."foot.php");
}
elseif($action=="addstyle"&&$Apower[style_editstyle])
{
	if(!$postdb[keywords]){
		showmsg("关键字不能为空");
	}elseif(!$postdb[name]){
		showmsg("风格名称不能为空");
	}
	if( file_exists(PHP168_PATH."php168/style/$postdb[keywords].php") )
	{
		showmsg("关键字已经存在了,请换一个关键字吧");
	}elseif( file_exists(PHP168_PATH."images/$postdb[keywords]/css.css") ){
		showmsg("关键字的样式表已经存在了,请换一个关键字吧");
	}
	$show="<?php	";
	foreach($postdb AS $key=>$value){
		$show.="
		\$styledb['$key']='$value';";
	}
	write_file(PHP168_PATH."php168/style/$postdb[keywords].php",$show);
	makepath(PHP168_PATH."images/$postdb[keywords]");
	write_file(PHP168_PATH."images/$postdb[keywords]/css.css",stripslashes("$CssCode\r\n"));
	jump("添加成功","index.php?lfj=style&job=editstyle&keywords=$postdb[keywords]");
}
elseif($job=="editstyle"&&$Apower[style_editstyle])
{
	$style_select=select_style('keywords',$keywords,"index.php?lfj=style&job=editstyle");
	@include(PHP168_PATH."php168/style/$keywords.php");
	$rsdb=$styledb;
	$keywords_check=" readonly ";
	$CssCode=read_file(PHP168_PATH."images/$styledb[keywords]/css.css");
	require(dirname(__FILE__)."/"."head.php");
	require(dirname(__FILE__)."/"."template/style/menu.htm");
	require(dirname(__FILE__)."/"."template/style/style.htm");
	require(dirname(__FILE__)."/"."foot.php");
}
elseif($action=="editstyle"&&$Apower[style_editstyle])
{
	//此处的目的是相当于替换数组差不多
	include(PHP168_PATH."php168/style/$postdb[keywords].php");
	foreach($postdb AS $key=>$value){
		if($value!=$styledb[$key]){
			$chang_style.=chang_style($key,$value);
		}
		$styledb[$key]=$value;
	}

	$show="<?php	";
	foreach($styledb AS $key=>$value){
		$show.="
		\$styledb['$key']='$value';";
	}
	if($chang_style){
		$chang_style="\r\n\r\n\r\n/********\r\n*最后修改于:".date("Y-m-d H:i",$timestamp)."\r\n*********/$chang_style";
	}
	write_file(PHP168_PATH."php168/style/$postdb[keywords].php",$show);
	write_file(PHP168_PATH."images/$postdb[keywords]/css.css",stripslashes("$CssCode$chang_style"));
	jump("修改成功","index.php?lfj=style&job=editstyle&keywords=$postdb[keywords]");
}
elseif($action=="deletestyle"&&$Apower[style_editstyle])
{
	/*只删除配置文件.其他不删除了.防止误删除可以恢复*/
	if( unlink(PHP168_PATH."php168/style/$keywords.php") ){
		jump("删除成功","index.php?lfj=style&job=deletestyle");
	}else{
		showmsg("删除失败,请确认文件属性可写".PHP168_PATH."php168/style/$keywords.php");
	}
	
}
elseif($job=="deletestyle"&&$Apower[style_editstyle])
{
	$style_select=select_style('keywords');
	require(dirname(__FILE__)."/"."head.php");
	require(dirname(__FILE__)."/"."template/style/menu.htm");
	require(dirname(__FILE__)."/"."template/style/deletestyle.htm");
	require(dirname(__FILE__)."/"."foot.php");
}
elseif($job=='getpic'&&$Apower[style_editstyle])
{
	$dir=opendir(PHP168_PATH."images/diy.style/$type/");
	while( $file=readdir($dir) ){
		if(eregi("jpg$",$file)||eregi("gif$",$file)||eregi("png$",$file)){
			$_listdb[]="$webdb[www_url]/images/diy.style/$type/$file";
		}
	}
	$listdb=array_chunk($_listdb,4);
	require(dirname(__FILE__)."/"."head.php");
	require(dirname(__FILE__)."/"."template/style/pic.htm");
	require(dirname(__FILE__)."/"."foot.php");
}

function chang_style($key,$value){
	if($key=="bodybgcolor"){
		$show="\r\nbody{\r\n\tbackground:$value;\r\n}";
	}elseif($key=="bodyBgImg"){
		$show="\r\nbody{\r\n\tbackground:url($value) center 50%;\r\n}";
	}elseif($key=="wrapWidth"){
		$show="\r\n.wrap{\r\n\twidth:$value;\r\n}";
	}elseif($key=="fontColor"){
		$show="\r\nTD,a,a:visited,a:hover{\r\n\tcolor:$value;\r\n}";
	}elseif($key=="tableBorderColor"){
		$show="\r\n.dragTable{\r\n\tborder:1px $value solid;\r\n}";
	}elseif($key=="tableBgcolor"){
		$show="\r\n.dragTable{\r\n\tbackground:$value;\r\n}";
	}elseif($key=="tableHeadBgColor"){
		$show="\r\n.dragTable .head{\r\n\tbackground:$value;\r\n}";
	}elseif($key=="tableHeadFontColor"){
		$show="\r\n.dragTable .head,.dragTable .head a{\r\n\tcolor:$value;\r\n}";
	}elseif($key=="tableHeadBgImg"){
		$show="\r\n.dragTable .head{\r\n\tbackground:url($value);\r\n}";
	}
	return $show;
}
?>