<?php
session_start();
require_once "../init.php";
require_once "../../common/Config.inc.php";

require_once "../authority.inc.php";
$Skin=$_POST['Skin'];
$edit = $_POST['edit'];

?>


<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<LINK rel="Bookmark" href="/favicon.ico" >
<LINK rel="Shortcut Icon" href="/favicon.ico" />


<!--[if lt IE 9]>
<script type="text/javascript" src="../lib/html5.js"></script>
<script type="text/javascript" src="../lib/respond.min.js"></script>
<script type="text/javascript" src="../lib/PIE_IE678.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.7/iconfont.css" />
<link rel="stylesheet" type="text/css" href="../lib/icheck/icheck.css" />
<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="../static/h-ui.admin/js/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<!--/meta 作为公共模版分离出去-->


 

<!--[if lte IE 8]>

<style>

.check_box label,.radio_box label{display:none;}

</style>

<![endif]-->



<title>模板管理</title>
</head>
<body>

<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 模板管理 <span class="c-gray en">&gt;</span> 模板设置 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<article class="page-container">

<div class="cl pd-5 bg-1 bk-gray mt-10"> <span class="l"><a href="/admin/settings/tpl_select.php"   class="btn  btn-danger radius"><i class="Hui-iconfont">1.</i> 选择模板</a>  <a onclick="window.parent.location.href='/admin/edittpl/'"  class="btn  btn-primary radius"   target="_blank"><i class="Hui-iconfont" >2.</i> 可视化编辑</a> <a   id="hot"  onclick="Hui_admin_tab(this)"  class="btn btn-primary radius" data-title="自定义html" _href="/admin/edittpl/themeedit.php"  href="/admin/edittpl/themeedit.php"><i class="Hui-iconfont">3.</i> 自定义html</a> <a   id="hot"  onclick="Hui_admin_tab(this)"  class="btn btn-primary radius" data-title="更多官方模板" _href="http://www.yinxi.net/design/"  href="http://www.yinxi.net/design/" target="_blank"> <i class="Hui-iconfont">4.</i> 更多官方模板</a> 
<a   id="hot"  onclick="Hui_admin_tab(this)"  class="btn btn-primary radius" data-title="更多官方模板" _href="http://www.yinxi.net/design/"  href="http://wpa.qq.com/msgrd?v=3&uin=2522407257&site=qq&menu=yes" target="_blank"> <i class="Hui-iconfont">5.</i> 300元去除版权</a> 
<a   id="hot"  onclick="Hui_admin_tab(this)"  class="btn btn-primary radius" data-title="多用户商业版" _href="http://www.yinxi.net/design/"  href="http://www.yinxi.net/design/" target="_blank"> <i class="Hui-iconfont">5.</i> 多用户商业版</a> 
</span>  </div>
						<?

if($edit==1){

//更新数据库
	
	if($Skin=="")
	{
	 echo "<script>alert('你没有选中模板！');window.location ='/admin/settings/tpl_select.php';</script>";
	exit();
	}



	
        $sql = "truncate table menu";
        $db->query($sql);
		
		   $sql = "truncate table notes";
        $db->query($sql);


$db1=mysql_connect(DB_SERVER,DB_LOGIN,DB_PW);
	if(!$db1) $error="数据库主机、用户名、密码中一个或多个有误：".mysql_error();
	if(!$error){
		if(!mysql_select_db(DB_LOGIN,$db1)){
			$error="数据库名有错或您没有访问该数据库的权限";
		}
	}
	mysql_query('SET NAMES utf8');
	if(!$error){
	$filename = "../../skin/$Skin/data/sql.sql";
		$fp = fopen($filename, "r");
		$content = fread($fp, filesize($filename));
		
		$content = str_replace("\r", '', $content);
		$contents = explode(";\n", $content);
		$c_count = count($contents);
		for($i = 0; $i < $c_count-1; $i ++)
		{
			$contents[$i] = trim($contents[$i]);
			if(!$contents[$i]) continue;
			mysql_query($contents[$i],$db1);
			if (mysql_error()) {
				$error="初始化数据出错:".$contents[$i].mysql_error();
				break;
			}
		}
		fclose($fp);


}

	echo $error;





        $sql = "UPDATE config SET value = '$Skin' WHERE code = 'Skin'";
        $db->query($sql);
  
	clear_tpl_files();
	
	$mess .= "<font color='red'><b> GOOD！成功选择模板，系统设定已被更新 </b></font>";
	echo $mess;
	
}

$AgentInfo = load_config(1);

?>		
					<div style="text-align:center;">
				
				<?
				$handel = opendir("../../skin");
				while($dirname = readdir($handel)){
					if($dirname=='.' || $dirname=='..') continue;
					if(!is_dir("../../skin/$dirname")) continue;
					if(strpos($dirname,"_bak")>0) continue;//2011-3-21
					$sel = $dirname == $AgentInfo['Skin']?"checked":"";
					

echo "<div style='width:250px;height:363px;border:1px solid #ccc;float:left;margin:12px;margin-top:30px;text-align:center'><img src='../../skin/$dirname/preview.jpg?id=2d2' style='margin-bottom:8px;' width=250px height=300px>";
echo "   <form action='tpl_select.php' method='post'> <input name='Skin' value='$dirname' $sel   type='radio' id='check_2'>

                   <label for='check_2'>$dirname</label>
  <br><button  class='btn btn-default' style='width:250px;margin-bottom:0px;' type='submit'><i class='Hui-iconfont'>&#xe68f;</i> 切换模板</button>
<input name='edit' type='hidden' value='1'></form></div>";
				}
				?>
			
					</div>


</article>


</body></html>