<?php
# Name: PHP版程氏音乐CMS管理系统 v3.0
# Author: 程氏<web@chshcms.com> [QQ:848769359]
# Homepage:http://www.chshcms.cn/
include_once("../../lib/cs_label.php");
include_once("../loginstate.php");
SystemPer('7_1');
$ac=CS_Request("ac");
?>
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>csdjcms management</title>
<link href="../res/css/admin_style.css" rel="stylesheet" />
<script language="javascript" src="../res/js/jquery.js"></script>
<style> 
body{width:440px;}
</style>
<script language="javascript">
$(document).ready(function(){
	$("#addip").click(function(){
		var CS_Name=$("#CS_Name").val();
		var CS_TempPath=$("#CS_TempPath").val();
	$("#CS_Name").css("border-color","#666 #ccc #ccc #666");
	$("#CS_TempPath").css("border-color","#666 #ccc #ccc #666");
	if(CS_Name==""){
		$("#CS_Name").css("border","1px solid red");
		$("#Msg").text("请填写模版名称！").css("color","red");
		return false;
		}
	else if(CS_TempPath==""){
		$("#CS_TempPath").css("border","1px solid red");
		$("#Msg").text("请填写模版路径！").css("color","red");
		return false;
		}
	});
});

function dhcolok(){
    this.parent.$('.webox').css({display:'none'});
    this.parent.$('.background').css({display:'none'});
}
</script>
</head>
<body class="body_none">
<div>
<!-- mod start -->
<form method="post" class="J_ajaxForm" action="?ac=edit" data-role="edit">
<div class="pop_cont pop_table2">
	<table width="100%" style="table-layout:fixed;">
		<col width="90" />
		<col />
		<tr>
			<th>模版名称</th>
			<td>
				<span class="must_red">*</span>
				<input type="text" id="CS_Name" name="CS_Name" class="input input_hd length_5" value="">
			</td>
		</tr>
		<tr>
			<th>模版路径</th>
			<td>
				<span class="must_red">*</span>
				<div class="mb5"><input type="text" id="CS_TempPath" name="CS_TempPath" class="input length_5" value=""></div>
			</td>
		</tr>
	</table>
</div>
<!-- mod end -->
<div class="pop_bottom">
    <div class="tips_error" id="Msg"></div>
	<button class="btn fr" onclick="dhcolok();" type="button">取消</button>
	<button class="btn btn_submit J_ajax_submit_btn mr10 fr" id="addip" type="submit">提交</button>
</div>
</form>
<!-- end -->
</div>
<?php
if($ac=='edit'){
    $CS_Name=CS_Request("CS_Name");
    $CS_TempPath=CS_Request("CS_TempPath");
    if(substr($CS_TempPath,0,5)!="skins") exit("<script>document.getElementById('Msg').innerHTML='模版路径开头文件夹必须为skins';</script>");
    if(substr($CS_TempPath,-1)!="/") $CS_TempPath=$CS_TempPath."/";
    if(empty($CS_Name)||empty($CS_TempPath)) exit("<script>document.getElementById('Msg').innerHTML='请把资料填写完整!';</script>");

    if(!file_exists(_CSDJ_ROOT_.$CS_TempPath."cs-index.html")) exit("<script>document.getElementById('Msg').innerHTML='没有找到模版首页文件!';</script>");

    $sql="Insert ".Getdbname('skins')."  (CS_Name,CS_TempPath) values ('".$CS_Name."','".$CS_TempPath."')";

    if($db->query($sql)){
        echo '<script>document.getElementById("Msg").className="tips_success";$("#Msg").text("恭喜,添加成功!").css("color","#026E12");</script>';
	echo "<script>setTimeout(\"this.parent.$('.webox').css({display:'none'});this.parent.$('.background').css({display:'none'});window.parent.location.reload();\",2000);</script>";
    }else{
        echo '<script>$("#Msg").text("抱歉,添加失败!").css("color","red");</script>';
        echo "<script>setTimeout(\"window.location='javascript:history.go(-1);'\",2000);</script>";
    }
}
?>
</body>
</html>
