<?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=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>
<script language="javascript" type="text/javascript" src="../../public/datepicker/wdatepicker.js"></script>
<style> 
body{width:440px;}
</style>
<script language="javascript">
$(document).ready(function(){
	$("#addgo").click(function(){
		var CS_Name=$("#CS_Name").val();
		var CS_Pass=$("#CS_Pass").val();
		var CS_Email=$("#CS_Email").val();
	$("#CS_Name").css("border-color","#666 #ccc #ccc #666");
	$("#CS_Pass").css("border-color","#666 #ccc #ccc #666");
	$("#CS_Email").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_Pass==""){
		$("#CS_Pass").css("border","1px solid red");
		$("#Msg").text("请填写会员密码！").css("color","red");
		return false;
		}
	else if(CS_Email==""){
		$("#CS_Email").css("border","1px solid red");
		$("#Msg").text("请填写会员EMAIL！").css("color","red");
		return false;
		}
	else if(isEmail(CS_Email)==false){
		$("#CS_Email").css("border","1px solid red");
		$("#Msg").text("邮箱格式错误！");
		return false;}
	});
});
function isEmail(str){
 res = /^[0-9a-zA-Z_\-\.]+@[0-9a-zA-Z_\-]+(\.[0-9a-zA-Z_\-]+)*$/;
 var re = new RegExp(res);
 return !(str.match(re) == null);
};
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('user')." Where CS_ID='".$id."'");
	   if($row){
		$Arr=array($row['CS_Name'],$row['CS_SID'],$row['CS_TID'],$row['CS_QQ'],$row['CS_Sex'],$row['CS_City'],$row['CS_Email'],$row['CS_Qqid'],$row['CS_Nichen'],$row['CS_Cion'],$row['CS_Vip'],$row['CS_VipTime'],$row['CS_EndTime'],$row['CS_Qianm'],$row['CS_Pass']);
	   }
   }else{
		$Arr=array('','0','0','','','','','','','0','0','','','','');
   }
?>
<!-- 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?>" /><input name="CS_VipTime" type="hidden" value="<?php echo $Arr[11]?>" />
		<tr><input name="Pass" type="hidden" value="<?php echo $Arr[14]?>" /><input name="QQid" type="hidden" value="<?php echo $Arr[7]?>" />
			<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>
				<input type="password" id="CS_Pass" name="CS_Pass" class="input input_hd length_5" value="<?php echo $Arr[14]?>">
			</td>
		</tr>
		<tr>
			<th>会员昵称</th>
			<td>
				<div class="mb5"><input type="text" id="CS_Nichen" name="CS_Nichen" class="input length_3" value="<?php echo $Arr[8]?>">
                             &nbsp;&nbsp;性别：<select class="select_1" name="CS_Sex">
            					<option value='0' <?php if($Arr[4]==0) echo 'selected="selected"';?>>男</option>   
            					<option value='1' <?php if($Arr[4]==1) echo 'selected="selected"';?>>女</option>            
                                         </select>
                                </div>
			</td>
		</tr>
		<tr>
			<th>会员QQ</th>
			<td>
				<div class="mb5"><input type="text" name="CS_QQ" class="input length_5" value="<?php echo $Arr[3]?>"></div>
			</td>
		</tr>
		<tr>
			<th>会员EMAIL</th>
			<td>
				<span class="must_red">*</span>
				<input type="text" id="CS_Email" name="CS_Email" class="input length_5" value="<?php echo $Arr[6]?>">
			</td>
		</tr>
 		<tr>
			<th>会员地区</th>
			<td>
				<div class="mb5"><input type="text" name="CS_City" class="input length_5" value="<?php echo $Arr[5]?>"></div>
			</td>
		</tr>
 		<tr>
			<th>会员金币</th>
			<td>
				<div class="mb5"><input type="text" name="CS_Cion" class="input length_2" value="<?php echo $Arr[9]?>" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"></div>
			</td>
		</tr>
 		<tr>
			<th>会员级别</th>
			<td>
				<div class="mb5"><label><input name="CS_Vip" type="radio" value="0" <?php if($Arr[10]==0){echo "checked";}?> onClick="javascript:document.getElementById('opss').style.display='none'" /><span>普通会员</span></label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                               <label><input name="CS_Vip" type="radio" value="1" <?php if($Arr[10]==1){echo "checked";}?> onClick="javascript:document.getElementById('opss').style.display=''" /><span>VIP会员</span></label>
                                </div>
			</td>
		</tr>
 		<tr id="opss" <?php if($Arr[10]==0){echo "style=\"display:none\"";} ?>>
			<th>VIP到期时间</th>
			<td>
				<div class="mb5"><input type="text" id="CS_EndTime" name="CS_EndTime" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="input length_5" value="<?php echo $Arr[12]?>">
                                </div>
			</td>
		</tr>
		<tr <?php if(empty($Arr[7])){echo "style=\"display:none\"";} ?>>
			<th>取消QQ登入</th>
			<td>
				<ul class="three_list cc">
					<li><label><input name="CS_Qqid" type="checkbox" value="ok">取消</label></li>
				</ul>
			</td>
		</tr>
 		<tr>
			<th>会员签名</th>
			<td>
				<div class="mb5"><textarea class="length_5" name="CS_WebCount"><?php echo html_entity_decode(stripslashes($Arr[13]))?></textarea></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="addgo" type="submit">提交</button>
</div>
</form>
<!-- end -->
</div>
<?php
if($ac=='edit'){
    $id=CS_Request("id");
    $CS_Vip=CS_Request("CS_Vip");
    $CS_Name=CS_Request("CS_Name");
    $CS_Nichen=CS_Request("CS_Nichen");
    $CS_Pass=CS_Request("CS_Pass");
    $CS_Sex=CS_Request("CS_Sex");
    $CS_QQ=CS_Request("CS_QQ");
    $CS_Email=CS_Request("CS_Email");
    $CS_City=CS_Request("CS_City");
    $CS_Qqid=CS_Request("CS_Qqid");
    $CS_Cion=CS_Request("CS_Cion");
    $Pass=CS_Request("Pass");

    if($CS_Qqid=='ok'){
           $CS_Qqid='';
    }else{
           $CS_Qqid=CS_Request("QQid");
    }

    if(empty($CS_Cion)) $CS_Cion=0;

    if($CS_Vip==1){
         $CS_VipTime=CS_Request("CS_VipTime");
         if(empty($CS_VipTime)) $CS_VipTime=date('Y-m-d H:i:s');
         $CS_EndTime=CS_Request("CS_EndTime");
    }

    if($CS_Pass!=$Pass) $CS_Pass=md5($CS_Pass);

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

    if(!empty($id)){  //修改
           $title="修改";
        if($CS_Vip==1){
           $sql="update ".Getdbname('user')." set CS_Name='".$CS_Name."',CS_Pass='".$CS_Pass."',CS_Nichen='".$CS_Nichen."',CS_Vip=".$CS_Vip.",CS_Sex=".$CS_Sex.",CS_Cion=".$CS_Cion.",CS_QQ='".$CS_QQ."',CS_Email='".$CS_Email."',CS_City='".$CS_City."',CS_Qqid='".$CS_Qqid."',CS_VipTime='".$CS_VipTime."',CS_EndTime='".$CS_EndTime."' where CS_ID=".$id;
        }else{
           $sql="update ".Getdbname('user')." set CS_Name='".$CS_Name."',CS_Pass='".$CS_Pass."',CS_Nichen='".$CS_Nichen."',CS_Vip=".$CS_Vip.",CS_Sex=".$CS_Sex.",CS_Cion=".$CS_Cion.",CS_QQ='".$CS_QQ."',CS_Email='".$CS_Email."',CS_City='".$CS_City."',CS_Qqid='".$CS_Qqid."' where CS_ID=".$id;
        }
    }else{   //新增
           $title="添加";
        if($CS_Vip==1){
           $sql="Insert ".Getdbname('user')."  (CS_Name,CS_Pass,CS_Nichen,CS_Vip,CS_Sex,CS_Cion,CS_QQ,CS_Email,CS_City,CS_Qqid,CS_VipTime,CS_EndTime) values ('".$CS_Name."','".$CS_Pass."','".$CS_Nichen."',".$CS_Vip.",".$CS_Sex.",".$CS_Cion.",'".$CS_QQ."','".$CS_Email."','".$CS_City."','".$CS_Qqid."','".$CS_VipTime."','".$CS_EndTime."')";
        }else{
           $sql="Insert ".Getdbname('user')."  (CS_Name,CS_Pass,CS_Nichen,CS_Vip,CS_Sex,CS_Cion,CS_QQ,CS_Email,CS_City,CS_Qqid) values ('".$CS_Name."','".$CS_Pass."','".$CS_Nichen."',".$CS_Vip.",".$CS_Sex.",".$CS_Cion.",'".$CS_QQ."','".$CS_Email."','".$CS_City."','".$CS_Qqid."')";
        }
    }
    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>
