<!DOCTYPE html>
<html>
 <head lang="en"> 
  <meta charset="GB2312" /> 
  <title></title> 
  <link href="css/style.css" title="style" rel="stylesheet" type="text/css" /> 
  <script src="js/jquery-1.6.3.min.js"></script> 
 </head> 
 <body style="background: #F3F3F3"> 
  <div> 
   <div class="list2" style="margin: 10px;"> 
    <a id="anote" class="you_p" href="#" style="color: #fff">用户资料编辑</a> 
   </div> 
   <div class="setbase" style="border: #B0B7BF 1px solid"> 
    <table width="100%"> 
     <tbody>
	  <tr>
       <th><span>编 号:</span></th>
       <th style="text-align: left"><input id="tuid"  style="width:150px" /></th>
       <th style="text-align: left">系统自动分类</th>
      </tr> 
      <tr>
       <th width="15%"><span>登录名:</span></th>
       <th style="text-align: left"><input id="tcode"  style="width:150px" /></th>
       <th style="text-align: left">用户登录名</th>
      </tr> 
	   <tr>
       <th width="15%"><span>用户名称:</span></th>
       <th style="text-align: left"><input id="tname"  style="width:150px" /></th>
       <th style="text-align: left">用户昵称</th>
      </tr> 
      <tr>
       <th><span>用户状态:</span></th>
       <th style="text-align: left">
		<input type="radio" checked="checked" id="tstate0" name="tstate" value="0" /> 不停用
		<input type="radio" id="tstate1" name="tstate" value="1" /> 停用
		
	   </th>
       <th style="text-align: left">是否停用账户</th>
      </tr> 
      <tr>
       <th><span>是否管理:</span> </th>
       <th style="text-align: left">

		<input type="radio" checked="checked" id="tkind0" name="tkind" value="0" /> 不是
		<input type="radio" id="tkind1" name="tkind" value="1" /> 是
		
	   </th>
       <th style="text-align: left">是否是管理员</th>
      </tr> 
      <tr>
       <th><span>接收编码:</span></th>
       <th style="text-align: left">
		<select id="trecv1" style="width:150px" > 
			   <option value="1">1</option>
			   <option value="2">2</option>
			   <option value="3">3</option>
			   <option value="4">4</option>
			   <option value="5">5</option>
			   <option value="6">6</option>
			   <option value="7">7</option>
			   <option value="8">8</option>
			   <option value="9">9</option>
			   <option value="10">10</option>
			   <option value="11">11</option>
			   <option value="12">12</option>
			   <option value="13">13</option>
			   <option value="14">14</option>
			   <option value="15">15</option>
			   <option value="16">16</option>
		</select>
	   </th>
       <th style="text-align: left">限制1-16</th>
      </tr> 
      
      <tr>
       <th><span>NOTE:</span></th>
       <th style="text-align: left"><input id="tnote"  style="width:150px" /></th>
       <th style="text-align: left">note</th>
      </tr> 
      <tr>
       <th><span>手机号码:</span></th>
       <th style="text-align: left"><input id="tsmsnum" style="width:150px" /></th>
       <th style="text-align: left">手机号码接收短信</th>
      </tr> 
	  <tr>
       <th><span>电话号码:</span></th>
       <th style="text-align: left"><input id="ttelnum" style="width:150px" /></th>
       <th style="text-align: left">电话号码接听电话</th>
      </tr> 
	   <tr>
       <th><span>用户邮箱:</span></th>
       <th style="text-align: left"><input id="temail" style="width:250px" /></th>
       <th style="text-align: left">邮箱接收邮件</th>
      </tr> 
     </tbody>
    </table> 
   </div> 


  </div> 
  <div> 
   <table width="100%">
    <tbody>
     <tr> 
      <th><a id="abtn" href="javascript:saveclick()" class="back" style="color: #fff;background: #ffa225">保存</a></th> 
      <th><a href="javascript:history.back()" class="back" style="color: #fff">返回</a></th> 
     </tr>
    </tbody>
   </table> 
  </div> 
  <script>
<% db_Open("/NandFlash/dbCfg.db3"); %>
var jUser=<% db_QryAdv("select * from tbUser where UID="+type); %>;
var jUserRecv=<% db_QryAdv("select Recv from tbUser"); %>;
<% db_Close(); %>

var itype=<% write(type); %>;
var iextx=0;

$(function(){
	$("#tuid").attr("disabled","disabled");
	if(itype != 0)
	{	
		$("#tcode").attr("disabled","disabled");
		if(jUser.recs[0].UID == 1)
		{
			document.getElementById("tstate0").disabled=true;
			document.getElementById("tstate1").disabled=true;
			document.getElementById("tkind0").disabled=true;
			document.getElementById("tkind1").disabled=true;
		}
		
		if(jUser.recs[0].State == 0)
		{
			document.getElementById("tstate0").checked=true;
		}
		else
		{
			document.getElementById("tstate1").checked=true;
		}
		if(jUser.recs[0].Kind == 0)
		{
			document.getElementById("tkind0").checked=true;
		}
		else
		{
			document.getElementById("tkind1").checked=true;
			
		}
		for(var i in jUserRecv.recs)
		{
			if(jUserRecv.recs[i].Recv != jUser.recs[0].Recv)
				$("#trecv1 option[value='"+jUserRecv.recs[i].Recv+"']").remove(); //删除Select中Value的Option 
			
		}

		
		$("#tcode").val(jUser.recs[0].Code);
		$("#tname").val(jUser.recs[0].Name);
		$("#trecv1").val(jUser.recs[0].Recv);
		$("#tuid").val(jUser.recs[0].UID);
		$("#tnote").val(jUser.recs[0].Note);
		$("#tsmsnum").val(jUser.recs[0].SmsNum);
		$("#ttelnum").val(jUser.recs[0].TelNum);
		$("#temail").val(jUser.recs[0].Email);
	}
	else
	{
		$("#abtn").text("增加");
		for(var i in jUserRecv.recs)
		{
				$("#trecv1 option[value='"+jUserRecv.recs[i].Recv+"']").remove(); //删除Select中Value的Option 
			
		}
	}
});

function onport(obj){
  var iv=$("#tport").val();
  if(iv==4)
    $(".setaddr").show();
  else
    $(".setaddr").hide();
  if(iv==6){
    if($("#ttype").val()>=3584)
      $(".setext").show();
    else
      $(".setext").hide();
  }
}

function saveclick(){
  var spost=""; 
  if(itype==0){
  if($("#tcode").attr("value").length <= 0 || $("#tname").attr("value") <=0)
  {
		alert("失败!(至少填写登录名和用户名称！)");
		return;
  }
 
  spost+="&code="+$("#tcode").attr("value");
  spost+="&name="+$("#tname").attr("value");
  spost+="&state="+$("input[name='tstate']:checked").val(); 
  spost+="&kind="+ $("input[name='tkind']:checked").val();  
  spost+="&recv1="+$("#trecv1").attr("value");
  spost+="&note="+$("#tnote").attr("value");
  spost+="&smsnum="+$("#tsmsnum").attr("value");
  spost+="&telnum="+$("#ttelnum").attr("value");
  spost+="&email="+$("#temail").attr("value");
  
    $.ajax({
      type: "POST",
      url: "omdev/usertype.asp",
      data: "op=ins"+spost,
      dataType:"json",
      success: function(msg){
        if(msg.op=="ok")
          history.back();
        else
          alert("增加 "+$("#tname").attr("value")+" 失败!(用户名称或者登录名已经存在！)");
      }
    });
    return;
  }

  spost+="&uid="+itype;
  spost+="&code="+$("#tcode").attr("value");
  spost+="&name="+$("#tname").attr("value");
  spost+="&state="+$("input[name='tstate']:checked").val(); 
  spost+="&kind="+ $("input[name='tkind']:checked").val();  
  spost+="&recv1="+$("#trecv1").attr("value");
  spost+="&note="+$("#tnote").attr("value");
  spost+="&smsnum="+$("#tsmsnum").attr("value");
  spost+="&telnum="+$("#ttelnum").attr("value");
  spost+="&email="+$("#temail").attr("value");

  $.ajax({
    type: "POST",
    url: "omdev/usertype.asp",
    data: "op=upd"+spost,
    dataType:"json",
    success: function(msg){
      if(msg.op=="ok") {
        //location.href=document.referrer;
        history.back();
      }
      else
        alert("保存数据 编号"+itype+" 失败!");
    }
  });
}
</script>  
 </body>
</html>