<!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: 5px;'>
    <a class='you_p' href='#' style='color: #fff'>定时简报设置</a>
  </div>
  <div id='setalm' style='border: #B0B7BF 1px solid'>
    <table  width='100%'>
      <tr><th width="15%"><span>简报方式(mode):</span></th><th style='text-align: left'><input id="atimeon" value="5" style="width:100px"></input></th><th width='25%' style='text-align: left'>&nbsp;数值范围:0~9999</th></tr>
      <tr><th><span>简报时间(hhmm):</span></th><th style='text-align: left'><input id="atimeredo" value="900" style="width:100px"></input></th><th style='text-align: left'>&nbsp;数值范围:0~9999</th></tr>
      <tr><th><span>简报发送方式:</span></th><th id="almonMode" style='text-align: left'>
        <input type="checkbox" name="almmask" value="1">声光</input>&nbsp;&nbsp;
        <input type="checkbox" name="almmask" value="2">语音</input>&nbsp;&nbsp;
        <input type="checkbox" name="almmask" value="4">短信</input>&nbsp;&nbsp;
        <input type="checkbox" name="almmask" value="8">彩信</input>&nbsp;&nbsp;
        <input type="checkbox" name="almmask" value="16">电话</input>&nbsp;&nbsp;
        <input type="checkbox" name="almmask" value="32">邮件</input>&nbsp;&nbsp;
		<input type="checkbox" name="almmask" value="256">联动1</input>&nbsp;&nbsp;
        <input type="checkbox" name="almmask" value="512">联动2</input>&nbsp;&nbsp;</th></tr>
      <tr><th><span>简报短信内容:</span></th><th style='text-align: left'>
        <textarea id="almsms" style='width: 400px'>短信内容</textarea></th><th>&nbsp;</th></tr>
      <tr><th><span>简报电话内容:</span></th><th style='text-align: left'>
        <textarea id="almtel" style='width: 400px'>电话内容</textarea></th><th>&nbsp;</th></tr>
      <tr><th><span>信息接收人:</span></th><th id="lsRecv" style='text-align: left'>
        <input type="checkbox" name="arecv">管理员</input>&nbsp;&nbsp
        <input type="checkbox" name="arecv">用户1</input>&nbsp;&nbsp;
    </table>
  </div>

</div>
<div>
  <table width='100%'><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></table>
</div>

<script>

var aidType=0;
var aidSIDx=0;

<% db_Open("/NandFlash/dbCfg.db3"); %>
var jalm=<% db_QryAdv("select * from tbAlm where AID=-1",0); %>;
var jrecv=<% db_QryAdv("select Name,Recv from tbUser where State=0 and Recv>0",0); %>;
var jDOInfo = <% db_QryAdv("select * from tbPort where Type=2",0); %>
<% db_Close(); %>



listAlmOnMode(jDOInfo);
function listAlmOnMode(data){
  var s="";
  var valtmp=256;
   s+="  <input type=\"checkbox\" name=\"almmask\" value=\"1\">声光</input>&nbsp;&nbsp;\n";
   s+="  <input type=\"checkbox\" name=\"almmask\" value=\"2\">语音</input>&nbsp;&nbsp;\n";
   s+="  <input type=\"checkbox\" name=\"almmask\" value=\"4\">短信</input>&nbsp;&nbsp;\n";
   s+="  <input type=\"checkbox\" name=\"almmask\" value=\"8\">彩信</input>&nbsp;&nbsp;\n";
   s+="  <input type=\"checkbox\" name=\"almmask\" value=\"16\">电话</input>&nbsp;&nbsp;\n";
   s+="  <input type=\"checkbox\" name=\"almmask\" value=\"32\">邮件</input>&nbsp;&nbsp;\n";
   
   for(var i=1;i < data.reccnt;i++)
   {
   	if(i>1)
   		valtmp = valtmp * 2;
   	s+="  <input type=\"checkbox\" name=\"almmask\" value=\"";
   	s+=valtmp;
   	s+="\">联动";
   	s+=i;
   	s+="</input>&nbsp;&nbsp;\n";
   }
   s+="</th></tr>\n";
  
  $("#almonMode").html(s);
  console.log("almonMode="+s);
}


listRecv();
function listRecv(){
  if(jrecv.reccnt==0) return;
  var s="";
  $.each(jrecv.recs, function(i,n){
    s+="<input type='checkbox' name='arecv' value='"+n.Recv+"'>"+n.Name+"</input>&nbsp;&nbsp;";
  });
  $("#lsRecv").html(s);
}

$(function(){
  showAlm(jalm.recs[0]);
});

function isNumber(obj) {
    return typeof obj === 'number' && !isNaN(obj)
}

function showAlm(alm){
  $("#atimeon").val(alm.TimeOn);
  $("#atimeredo").val(alm.TimeRedo);
  showAlmMask(alm.AlmMask);
  $("#almsms").val(alm.AlmSms);
  $("#almtel").val(alm.AlmTel);
  showRecv(alm.AlmRecv);
}
function showAlmMask(imask){
  $("input[name='almmask']").each(function(){
    var iv=parseInt(this.value);
    if(iv & imask)
      $(this).attr("checked",true);
    else
      $(this).attr("checked",false);
  });
}
function showRecv(irecv){
  $("input[name='arecv']").each(function(){
    var iv=parseInt(this.value);
    if(irecv & (1<<(iv-1)))
      $(this).attr("checked",true);
    else
      $(this).attr("checked",false);
  });
}

function saveAlm(){
  var spost="&setval=";
  spost+="TimeOn="+$("#atimeon").attr("value");
  spost+=",TimeRedo="+$("#atimeredo").attr("value");
  spost+=",AlmMask="+getAlmMask();
  spost+=",AlmTid=0";
  spost+=",AlmCam=0";
  spost+=",AlmSms='"+$("#almsms").attr("value");
  spost+="',AlmTel='"+$("#almtel").attr("value");
  spost+="',AlmRecv="+getRecv();
  var alm=jalm.recs[0];
  var iaid=alm.AID;
  
  // ini
  $.ajax({
    type: "POST",
    url: "action/inioprate",
    data: "op=upd&file=omAppSU.ini&Sec=APP&Key=SmsMode&value="+$("#atimeon").attr("value"),
    dataType:"json",
    success: function(msg){
      //if(msg.op=="ok")
      //  history.back();
    }
  });
  $.ajax({
    type: "POST",
    url: "action/inioprate",
    data: "op=upd&file=omAppSU.ini&Sec=APP&Key=SmsTime&value="+$("#atimeredo").attr("value"),
    dataType:"json",
    success: function(msg){
      //if(msg.op=="ok")
      //  history.back();
    }
  });
  $.ajax({
    type: "POST",
    url: "action/inioprate",
    data: "op=upd&file=omAppSU.ini&Sec=APP&Key=SmsLast&value=",
    dataType:"json",
    success: function(msg){
      //if(msg.op=="ok")
      //  history.back();
    }
  });

  $.ajax({
    type: "POST",
    url: "omdev/almx.asp",
    data: "op=upd&aid="+iaid+"&sid=-1"+spost,
    dataType:"json",
    success: function(msg){
      if(msg.op=="ok")
        history.back();
    }
  });
}
function getAlmMask(){
  var iv=0;
  $("input[name='almmask']:checked").each(function(){
    iv+=parseInt(this.value);
  });
  return iv;
}
function getRecv(){
  var iv=0;
  $("input[name='arecv']:checked").each(function(){
    iv|=(1 << (parseInt(this.value)-1));
  });
  return iv;
}

function saveclick(){
  saveAlm();
}
</script>
</body>
</html>