<?php
//====== 前台首页 ======
require "common.php";
$m=file_get_contents("php://input");if($m=="")$m='{"act":"index"}';$m=Dec($m,true);
switch($m["act"]){
	case "lgn"://登录
	$q=Qry("Select ID,Ar From ".$pre."admin Where Ah=0 And Si=".$m["ush"]." And Au='".$m["unm"]."' And Ap='".md5($m["upw"])."'");
	if(Qrc($q)==0)die('{"msg":"登录失败！用户名或密码错误！"}');$r=Qra($q);$d=Rnd();
	Qry("Update ".$pre."admin Set Ad=Now(),Ak='".$d."' Where Si=".$m["ush"]." And Au='".$m["unm"]."'");
	echo '{"msg":"ok","nid":"'.$m["ush"].'","uid":"'.$r["ID"].'","rid":"'.$r["Ar"].'","sid":"'.$d.'"}';
	break;

	case "lgo"://退出
	Qry("Update ".$pre."admin Set Ni='' Where Mi=".$m["nid"]." And ID=".$m["uid"]);
	echo '{"msg":"ok"}';
	break;

	default:
	$q=Qry("Select Si,Sn From ".$pre."shop Where Sh<2 Order By Si Asc");
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=360, initial-scale=1, user-scalable=yes">
<title><?php echo $cfg["An"];?></title>
<style type="text/css">
input[type=text],input[type=password],select{font-size:16px;padding:3px;border:1px solid #CCC;width:160px;font-family:Consolas,微软雅黑;}
.btn {display:inline-block;background-color:#09F;color:#FFF;line-height:30px;padding:0px 16px;border-radius:5px;box-shadow:2px 2px 2px #666;cursor:pointer;}
.btm {display:inline-block;background-color:#999;color:#FFF;line-height:30px;padding:0px 16px;border-radius:5px;box-shadow:2px 2px 2px #666;cursor:pointer;}
#msk {position:fixed;width:360px;left:0px;top:0px;background-color:#000;opacity:0.2;z-index:9;display:none;}
#tip {position:fixed;max-width:300px;background-color:#000;color:#FFF;padding:5px 10px;z-index:99;display:none;}
#cfn {position:fixed;background-color:#FFF;padding:20px;width:280px;border:1px solid #CCC;line-height:24px;box-shadow:2px 2px 2px #666;display:none;z-index:98;}
.bn0 {display:inline-block;line-height:24px;padding:0px 6px;border:1px solid #CCC;text-align:center;cursor:pointer;}
.bn1 {display:inline-block;line-height:24px;padding:0px 6px;border:1px solid #CCC;background-color:#09F;color:#FFF;text-align:center;cursor:pointer;}
</style>
<script type="text/javascript">
function $(o){return document.getElementById(o);}function $$(o){return document.getElementsByName(o);}
function xml(u,p,f){var x;try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(f){x=false;}}if(!x&&typeof XMLHttpRequest!='undefined'){x=new XMLHttpRequest();}if(!x){alt('创建XHR对象失败！');return;}x.open(p?'Post':'Get',u,true);x.setRequestHeader('Content-Type','application/json;');x.onreadystatechange=function(){if(x.readyState==4&&x.status==200){try{var s=JSON.parse(x.responseText.replace(/\&\#32;/gi,' ').replace(/\&\#34;/gi,'&quot;').replace(/\&\#37;/gi,'%').replace(/\&\#39;/gi,'\''));if(s.msg!='ok'){alt(s.msg);return;}}catch(e){alt('响应JSON解析错误！\n'+x.responseText+'\n'+e);return;}f(s);}};x.send(p?JSON.stringify(p):null);}
function rnd(n,c){var s='';for(var i=0;i<(n||16);i++)s+='1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'.substr(Math.floor((c?10:62)*Math.random()),1);return s;}
function sck(n,v){var d=new Date();d.setTime(d.getTime()+1080000000);document.cookie=n+'='+encodeURI(v)+'; expires='+d.toGMTString();}
function gck(n){var c=document.cookie.split("; ");for(var i=0;i<c.length;i++){var t=c[i].split("=");if(t[0]==n)return decodeURI(t[1]);}return '';}
function fio(m,n,o){if(o&&o!=1){o=o.split(',');for(var i=0;i<o.length;i++)$(o[i]).style.display='none';}o=o?1:0;$(m).style.display='block';if(o)msk.style.display='block';var c=Math.round(parseFloat($(m).style.opacity||(n>0?0:1))*100)/100;c+=0.1*n;if(c<=1&&c>0){$(m).style.opacity=c;if(o)msk.style.opacity=c/5;$(m).style.left=(pw-parseInt($(m).offsetWidth))/2+'px';$(m).style.top=(ph-parseInt($(m).offsetHeight))/2+20-c*20+'px';setTimeout('fio(\''+m+'\','+n+','+o+')',20);}if(c==0){$(m).style.display='none';if(o)msk.style.display='none';}}
function alt(n){tip.innerText=n;if(tip.style.display=='block')return;fio('tip',1);setTimeout(function(){fio('tip',-1);},2000);}
function cfm(n,s,c){var m=msk.style.display=='block'?false:1;msk.style.zIndex=97;cfn.innerHTML=n.replace(/\n/gi,'<br>')+'<div style="text-align:right;"><br><span id="cfc" class="bn0">取消</span>　<span id="cfs" class="bn1">确定</span></div>';cfc.addEventListener('click',function(){fio('cfn',-1,m);msk.style.zIndex=9;if(c)c();});cfs.addEventListener('click',function(){fio('cfn',-1,m);msk.style.zIndex=9;s();});fio('cfn',1,m);}
//----------------------------------------------------------------
var uri='index.php';
var ua=navigator.userAgent.toLowerCase();
var ism=ua.indexOf('windows')<0&&ua.indexOf('macintosh')<0?1:0;//是否手机
if(ism)document.write('<meta name="viewport" content="width=360, initial-scale='+parseInt(document.documentElement.clientWidth)/360+', user-scalable=yes">');
var pw,ph,nid,uid,sid,rid,mid=[];
<?php
while($r=Qra($q))echo "mid.push(['".$r["Si"]."','".$r["Sn"]."']);";
?>
function rsz(n){pw=parseInt(document.documentElement.clientWidth);ph=parseInt(document.documentElement.clientHeight);msk.style.width=pw+'px';msk.style.height=ph+'px';db.style.width=pw+'px';db.style.height=ph+'px';dm.style.width=(ism?300:480)+'px';dm.style.height=(ism?240:300)+'px';dm.style.left=((pw-(ism?300:480))/2)+'px';dm.style.top=((ph-(ism?240:300))/2)+'px';dn.style.width=(ism?280:460)+'px';dn.style.height=(ism?220:280)+'px';dn.style.left=((pw-(ism?300:480))/2)+'px';dn.style.top=((ph-(ism?240:300))/2)+'px';df.style.fontSize=(ism?18:24)+'px';di.style.display=ism?'none':'block';if(n){if(ism&&gck('Jir_AddFav')==''){dc.style.display='block';sck('Jir_AddFav',1);}var s='';for(var i=0;i<mid.length;i++)s+='<option value="'+mid[i][0]+'"'+(mid[i][0]==gck('Jir_SysShop')?' selected':'')+'>[ID:'+mid[i][0]+']'+mid[i][1]+'</option>';uss.innerHTML='<select id="ush" style="width:166px;">'+s+'</select>';unm.focus();uat.checked=gck('Jir_SysAuto')=='1';unm.value=gck('Jir_SysUser');upw.value=gck('Jir_SysPass');}setTimeout('rsz()',1000);}
function lgn(){xml(uri,{act:'lgn',ush:ush.value,unm:unm.value,upw:upw.value},function(r){nid=r.nid;uid=r.uid;sid=r.sid;rid=r.rid;dt.style.display='none';dk.style.display='block';lgd.innerText=ush.options[ush.selectedIndex].text;sck('Jir_SysShop',ush.value);sck('Jir_SysUser',unm.value);if(uat.checked&&rid.indexOf('S')<0){sck('Jir_SysAuto','1');sck('Jir_SysPass',upw.value);}else{sck('Jir_SysAuto','');sck('Jir_SysPass','');}if(rid.indexOf('A')==-1&&rid.indexOf('B')==-1)bn1.className='btm';if(rid.indexOf('C')==-1&&rid.indexOf('D')==-1)bn2.className='btm';if(rid.indexOf('E')==-1)bn5.className='btm';if(ism||rid.indexOf('F')==-1)bn3.className='btm';if(ism||rid.indexOf('S')==-1)bn4.className='btm';});}
function lgo(){cfm('确认退出？',function(){xml(uri,{act:'lgo',nid:nid,uid:uid},function(r){sck('Jir_SysAuto','');sck('Jir_SysPass','');location.reload();});});}
function goo(n){document.fm.uid.value=uid;document.fm.nid.value=nid;document.fm.sid.value=sid;document.fm.action=n;document.fm.submit();};
</script>
</head>
<body style="margin:0px;padding:0px;font-size:16px;font-family:Consolas,微软雅黑;" onLoad="rsz(1);">
<div id="msk"></div><div id="tip"></div><div id="cfn"></div>
<div id="dc" style="position:absolute;top:0px;left:0px;z-index:30;display:none;" onClick="dc.style.display='none';"><img src="images/favi.png"></div>
<div id="db" style="background-image:url(images/back.jpg);background-position:center;"></div>
<div id="dm" style="position:absolute;background-color:#FFF;border-radius:5px;opacity:0.3;box-shadow:2px 2px 2px #666;"></div>
<div id="dn" style="position:absolute;padding:10px;text-align:center;color:#FFF;text-shadow:2px 2px 2px #666;line-height:40px;">
  <span id="df"><?php echo $cfg["An"];?> - 登录</span><hr color="#FFF">
  <div id="dt">店　铺： <span id="uss"></span><br>
  用户名： <input type="text" id="unm" onKeyUp="if(event.keyCode==13)upw.focus();"><br>
  密　码： <input type="password" id="upw" onKeyUp="if(event.keyCode==13)lgn();"><br>
  <input type="checkbox" id="uat" onClick="if(!this.checked)sck('Jir_SysPass','');"> 自动登录　　<span class="btn" onClick="lgn();">登　录</span></div>
  <div id="dk" style="display:none;">当前店铺：<span id="lgd"></span><br><span id="bn1" class="btn" onClick="if((rid.indexOf('A')>-1||rid.indexOf('B')>-1))goo('waiter.php');">点单管理</span>　　<span id="bn2" class="btn" onClick="if(rid.indexOf('C')>-1||rid.indexOf('D')>-1)goo('cooker.php');">厨房送餐</span><br><span id="bn3" class="btn" onClick="if(!ism&&rid.indexOf('F')>-1)goo('manage.php');">前台管理</span>　　<span id="bn5" class="btn" onClick="if(rid.indexOf('E')>-1)goo('sender.php');">外卖送餐</span><br><span id="bn4" class="btn" onClick="if(!ism&&rid.indexOf('S')>-1)goo('system.php');">餐厅设置</span>　　<span class="btn" onClick="lgo();">退出登录</span></div>
  <div id="di" style="font-size:12px;display:none;line-height:26px;"><br>&copy; 2018 - 2020 All Rights Reserved By software.bbxdn.com</div>
</div>
<form name="fm" action="" method="post" target="_blank"><input type="hidden" name="act" value="index"><input type="hidden" name="uid"><input type="hidden" name="nid"><input type="hidden" name="sid"></form>
</body>
</html>
<?php
}
?>