<%
__header("Content-Type","text/html; charset=gb2312");
var serr="{\"op\":\"op err\"}";
if (op=="")
  write(serr);
else
{
var sql;
var iupd=-1;
db_Open("/NandFlash/dbCfg.db3");
if (op=="qry")
  db_QryAdv("select * from tbAlm");
if (op=="del")
  iupd=db_UpdAdv("delete from tbAlm where AID="+aid);
if (op=="ins")
{
  sql = "insert into tbAlm(Type,SID,AlmTid,Note,State,TimeOn,TimeOn2,TimeRedo,AlmStyle,AlmMask,AlmSms,AlmTel,AlmCam,AlmOffMask,AlmOff,AlmRecv)";
  sql = sql+" values("+type+","+sid+","+tid+",'"+note+"',"+state+","+timeon+","+timeon2+","+timeredo;
  sql = sql+","+astyle+","+amask+",'"+asms+"','"+atel+"',"+acam+","+aoffmask+",'"+aoff+"',"+arecv+")";
  iupd=db_UpdAdv(sql,1);
}
if (op=="upd")
{
  sql = "update tbAlm set Type="+type+",SID="+sid+",AlmTid="+tid+",Note='"+note+"',State="+state;
  sql = sql+",TimeOn="+timeon+",TimeOn2="+timeon2+",TimeRedo="+timeredo+",AlmStyle="+astyle+",AlmMask="+amask;
  sql = sql+",AlmSms='"+asms+"',AlmTel='"+atel+"',AlmCam="+acam+",AlmOffMask="+aoffmask;
  sql = sql+",AlmOff='"+aoff+"',AlmRecv="+arecv+" where AID="+aid;
  iupd=db_UpdAdv(sql,1);
}

if (iupd<0 && iupd!=-1)
  write(serr);
if (iupd>=0)
{
  var lastId = db_QryLastRowId();
  write("{\"op\":\"ok\",\"aid\":"+lastId+"}");
}
db_Close();
}
%>