<?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('2_2');
$ac=CS_Request("ac");
?>
<!doctype html>
<html>
<head>
<meta charset="gbk">
<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(){
	$("#adddh").click(function(){
		var CS_Name=$("#CS_Name").val();
		var CS_XID=$("#CS_XID").val();
		var CS_AliasName=$("#CS_AliasName").val();
		var CS_Template=$("#CS_Template").val();
		var re = /^[a-z0-9]*$/gi
	$("#CS_Name").css("border-color","#666 #ccc #ccc #666");
	$("#CS_XID").css("border-color","#666 #ccc #ccc #666");
	$("#CS_AliasName").css("border-color","#666 #ccc #ccc #666");
	$("#CS_Template").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_AliasName==""){
		$("#CS_AliasName").css("border","1px solid red");
		$("#Msg").text("请填写英文别名！").css("color","red");
		return false;
		}
	else if(re.test(CS_AliasName)==false){
		$("#CS_AliasName").css("border","1px solid red");
		$("#Msg").text("英文别名必须是数字或字母组成！").css("color","red");
		return false;
		}
	else if(CS_XID==""){
		$("#CS_XID").css("border","1px solid red");
		$("#Msg").text("请填写排序号！").css("color","red");
		return false;
		}
	else if(CS_Template==""){
		$("#CS_Template").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>
<?php
   $id=CS_Request("id");
   if($id){
	   $row=$db->getrow("SELECT * FROM ".Getdbname('class')." Where CS_ID='".$id."'");
	   if($row){
		$Arr=array($row['CS_Name'],$row['CS_FID'],$row['CS_XID'],$row['CS_YID'],$row['CS_Template'],$row['CS_AliasName'],$row['CS_Title'],$row['CS_Keywords'],$row['CS_Description']);
	   }
   }else{
		$Arr=array('','0','0','0','dance-list.html','','','','');
   }
?>
<!-- mod start -->
<form method="post" class="J_ajaxForm" action="?ac=edit" data-role="edit">
<div class="pop_cont pop_table">
	<table width="100%" style="table-layout:fixed;">
		<col width="90" />
		<col /><input name="id" type="hidden" value="<?php echo $id?>" />
		<tr>
			<th>上级分类</th>
			<td>
				<span class="must_red">*</span>
				<select name="CS_FID" class="select_5"><option value="0">顶级分类</option>
                               <?php
                                   $sqlc="select * from ".Getdbname('class')." where CS_SID=1 and CS_FID=0";
                                   $results=$db->query($sqlc);
	                             if($results){
	                                while ($row1=$db->fetch_array($results)){
                                             if($Arr[1]==$row1['CS_ID']){
                                                  echo '<option value="'.$row1['CS_ID'].'" selected="selected">'.$row1['CS_Name'].'</option>';
                                             }else{
                                                  echo '<option value="'.$row1['CS_ID'].'">'.$row1['CS_Name'].'</option>';
                                             }
                                        }
                                     }
                               ?>
				</select>
			</td>
		</tr>
		<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="<?php echo $Arr[0]?>">
			</td>
		</tr>
		<tr>
			<th>英文别名</th>
			<td>
				<span class="must_red">*</span>
				<div class="mb5"><input type="text" id="CS_AliasName" name="CS_AliasName" class="input length_5" value="<?php echo $Arr[5]?>"></div>
				<div class="gray">英文字母组合</div>
			</td>
		</tr>
		<tr>
			<th>模版文件</th>
			<td>
				<span class="must_red">*</span>
				<div class="mb5"><input type="text" id="CS_Template" name="CS_Template" class="input length_5" value="<?php echo $Arr[4]?>"></div>
				<div class="gray">该分类使用模版</div>
			</td>
		</tr>
		<tr>
			<th>顺序</th>
			<td>
				<span class="must_red">*</span>
				<input type="text" id="CS_XID" name="CS_XID" class="input length_5" value="<?php echo $Arr[2]?>" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
			</td>
		</tr>
 		<tr>
			<th>SEO标题</th>
			<td>
				<div class="mb5"><input type="text" id="CS_Title" name="CS_Title" class="input length_5" value="<?php echo $Arr[6]?>"></div>
				<div class="gray">SEO标题-title</div>
			</td>
		</tr>
 		<tr>
			<th>SEO关键词</th>
			<td>
				<div class="mb5"><input type="text" id="CS_Keywords" name="CS_Keywords" class="input length_5" value="<?php echo $Arr[7]?>"></div>
				<div class="gray">SEO关键词-Keywords</div>
			</td>
		</tr>
 		<tr>
			<th>SEO介绍</th>
			<td>
				<div class="mb5"><input type="text" id="CS_Description" name="CS_Description" class="input length_5" value="<?php echo $Arr[8]?>"></div>
				<div class="gray">SEO介绍-Description</div>
			</td>
		</tr>
		<tr>
			<th>是否启用</th>
			<td>
				<ul class="three_list cc">
					<li><label><input name="CS_YID" type="checkbox" value="ok" <?php if($Arr[3]=='0') echo 'checked';?> >启用</label></li>
				</ul>
			</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="adddh" type="submit">提交</button>
</div>
</form>
<!-- end -->
</div>
<?php
if($ac=='edit'){
    $id=CS_Request("id");
    $CS_FID=CS_Request("CS_FID");
    $CS_Name=CS_Request("CS_Name");
    $CS_AliasName=CS_Request("CS_AliasName");
    $CS_Template=CS_Request("CS_Template");
    $CS_XID=CS_Request("CS_XID");
    $CS_Title=CS_Request("CS_Title");
    $CS_Keywords=CS_Request("CS_Keywords");
    $CS_Description=CS_Request("CS_Description");
    $CS_YID=CS_Request("CS_YID");
    if($CS_YID!='ok'){
           $CS_YID=1;
    }else{
           $CS_YID=0;
    }
    if(empty($CS_XID)) $CS_XID=0;

    if(empty($CS_Name)||empty($CS_AliasName)||empty($CS_Template)) exit("<script>document.getElementById('Msg').innerHTML='请把资料填写完整!';</script>");

    if(!empty($id)){  //修改
           $title="修改";
           $sql="update ".Getdbname('class')." set CS_Name='".$CS_Name."',CS_AliasName='".$CS_AliasName."',CS_Template='".$CS_Template."',CS_FID=".$CS_FID.",CS_YID=".$CS_YID.",CS_XID=".$CS_XID.",CS_Title='".$CS_Title."',CS_Keywords='".$CS_Keywords."',CS_Description='".$CS_Description."' where CS_ID=".$id;
    }else{   //新增
           $title="添加";
           $sql="Insert ".Getdbname('class')."  (CS_Name,CS_AliasName,CS_Template,CS_FID,CS_YID,CS_XID,CS_Title,CS_Keywords,CS_Description) values ('".$CS_Name."','".$CS_AliasName."','".$CS_Template."',".$CS_FID.",".$CS_YID.",".$CS_XID.",'".$CS_Title."','".$CS_Keywords."','".$CS_Description."')";
    }

    if($db->query($sql)){
        echo '<script>document.getElementById("Msg").className="tips_success";$("#Msg").text("恭喜,'.$title.'成功!").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("抱歉,'.$title.'失败!").css("color","red");</script>';
        echo "<script>setTimeout(\"window.location='javascript:history.go(-1);'\",2000);</script>";
    }
}
?>
</body>
</html>