<?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('1_4');
$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_Url=$("#CS_Url").val();
	$("#CS_Name").css("border-color","#666 #ccc #ccc #666");
	$("#CS_Playip").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_Url==""){
		$("#CS_Url").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('link')." Where CS_ID='".$id."'");
	   if($row){
		$Arr=array($row['CS_Name'],$row['CS_Url'],$row['CS_Pic'],$row['CS_CID'],$row['CS_YID']);
	   }
   }else{
		$Arr=array('','','','0','0');
   }
?>
<!-- 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 /><input name="CS_ID" type="hidden" value="<?php echo $id?>" />
		<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_Url" name="CS_Url" class="input length_5" value="<?php echo $Arr[1]?>"></div>
			</td>
		</tr>
		<tr id="opps" <?php if($Arr[3]==0){echo "style=\"display:none\"";} ?>>
			<th>LOGO地址</th>
			<td>
				<span class="must_red">*</span>
				<div class="mb5"><input type="text" id="CS_Pic" name="CS_Pic" class="input length_5" value="<?php echo $Arr[2]?>"></div>
			</td>
		</tr>
		<tr>
			<th>链接类型</th>
			<td>
				<div class="mb5">
                                        <label><input name="CS_CID" type="radio" value="1" <?php if($Arr[3]==1){echo "checked";}?> onClick="javascript:document.getElementById('opps').style.display='none';"/><span>文字链接</span></label>&nbsp;&nbsp;&nbsp;&nbsp;
                                        <label><input name="CS_CID" type="radio" value="2" <?php if($Arr[3]==2){echo "checked";}?> onClick="javascript:document.getElementById('opps').style.display='';"/><span>图片链接</span></label>
                                </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[4]=='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="addip" type="submit">提交</button>
</div>
</form>
<!-- end -->
</div>
<?php
if($ac=='edit'){
    $CS_ID=CS_Request("CS_ID");
    $CS_Name=CS_Request("CS_Name");
    $CS_Url=CS_Request("CS_Url");
    $CS_Pic=CS_Request("CS_Pic");
    $CS_CID=CS_Request("CS_CID");
    $CS_YID=CS_Request("CS_YID");

    if($CS_YID!='ok'){
           $CS_YID=1;
    }else{
           $CS_YID=0;
    }
    if(empty($CS_CID)) $CS_CID=0;

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

    if(!empty($CS_ID)){  //修改
           $title="修改";
           $sql="update ".Getdbname('link')." set CS_Name='".$CS_Name."',CS_Url='".$CS_Url."',CS_Pic='".$CS_Pic."',CS_CID=".$CS_CID.",CS_YID=".$CS_YID." where CS_ID=".$CS_ID;
    }else{   //新增
           $title="添加";
           $sql="Insert ".Getdbname('link')."  (CS_Name,CS_Url,CS_Pic,CS_CID,CS_YID) values ('".$CS_Name."','".$CS_Url."','".$CS_Pic."',".$CS_CID.",".$CS_YID.")";
    }

    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>
