<?php
ob_start();
$forcein=null;
$LastOrderID=null;
$theTotalValue=0;
$RemarkFin='';

//获取微信信息，初始化路径和数据库
include_once 'init.php';
	if (empty($_REQUEST['OrderID']))  $FinOrderID=$LastOrderID;
	else $FinOrderID=$_REQUEST['OrderID'];
	//die($CompanyName);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta name="apple-mobile-web-app-capable" content="yes">
 <meta name="apple-mobile-web-app-status-bar-style" content="black">
 <meta name="format-detection" content="telephone=no">
 <meta name="viewport" content="width=device-width,initial-scale=1, minimum-scale=1.0, maximum-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-title" content="<?php echo $CFG_SiteName;?>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="apple-touch-icon" href="_ini/icon512x512.png" />

<!-- meta使用viewport以确保页面可自由缩放 -->
 
<!-- 引入 jQuery Mobile 样式 -->
<link rel="stylesheet" type="text/css" href="jquery.mobile-1.4.5/jquery.mobile-1.4.5.min.css"/>
<?php if ($_REQUEST['style']==1)
echo '<link rel="stylesheet" type="text/css" href="css/ROMG.min.css"/>';
else if ($_REQUEST['style']==2)
echo '<link rel="stylesheet" type="text/css" href="css/BLOR.min.css"/>';
?>
<!-- 引入 jQuery 库 -->
<script type="text/javascript" src="jquery.mobile-1.4.5/jquery-1.11.1.min.js"></script>
<!-- 引入 jQuery Mobile 库 -->
<script type="text/javascript" src="jquery.mobile-1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script>
$(document).on("pagecreate","#pageone",function(){
	var myPanelOrdersOpen = 0;
  $(document).on("swiperight",function(){
	//向右滑动，显示面板
	  if(myPanelOrdersOpen==0) $("#myPanelMenu").panel("open");
  }); 
  //$(document).on("swipeleft",function(){
	  //if(myPanelOrdersOpen==0) $("#linkPanelOrders").click();
  //});     
});
</script>
<script type="text/javascript">
function reloaddoc(var1){
	$("#showMenu").val(var1);
	document.getElementById('formMenuIndex').submit();
}
function confirmsumbit(oid,var1){
	$("#prntype").val(var1).selectmenu('refresh', true); //先修改值 然后再刷新
	$.ajax({
		type: "POST", //提交的类型
		url: "print_preview.php",//提交地址
		data: "_dc="+new Date().getTime()+"&OrderID="+oid+"&prntype=" + var1 ,//参数
		success: function(data){ //回调方法
		var msg=data;
		msg=msg.replace(/<br>/g, "\n");
		if(confirm('订单详情\n\n' + msg + '\n\n确认下单吗？'))
			 //index.php 按提交按钮
			 //：将finorder.php 的表单提交 <form id="formfinorder">
			 //：提交  prnOrderID  到init.php处理
			 formfinorder.submit();
		
		}
		});
}
function confirmdelete(){
if(confirm('确认清空吗？')) {
	reloaddoc('delete')
	};
}
function loaddesk(CustomerID){
	//alert(CustomerID);
	//设置wecheat cookie，刷新自身
	 document.cookie= "wechat=" + CustomerID ;
	reloaddoc('')
	//location.reload();
}

//　使用方法：setCookie('username','Darren',30)
function setCookie(c_name, value, expiredays){
　　　　var exdate=new Date();
　　　　exdate.setDate(exdate.getDate() + expiredays);
　　　　document.cookie=c_name+ "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function openPanelOrders(oid,prntype){
 		$.ajax({
			type: "POST", //提交的类型
			url: "finorder2.php", //提交地址
			data: "_dc=" + new Date().getTime()+"&OrderID="+oid+"&prntype="+prntype, //参数
			success: function(data) { //回调方法
     		   $("#myOrderDetalis").html(data).trigger('create');
			}
		});	 
}
function ajaxprint(prnarr){
	//alert(prnarr);
 		$.ajax({
			type: "POST", //提交的类型
			url: "token.php", //提交地址
			data: "_dc=" + new Date().getTime()+"&prnarr="+prnarr, //参数
			success: function(data) { //回调方法
     		   $("#myDivPrnResult").html('<b>打印成功'+data+'</b><hr/>').trigger('create');
			},
			error:function(data) {
				 $("#myDivPrnResult").html('<b>打印失败'+data+'</b><hr/>').trigger('create');
			}
		});	 
} 
function loadcatalogoLeft(UserCodeNO){
    //var url = "loadmenu.php?_dc="+new Date().getTime()+"&CategoryID=" + UserCodeNO;      
    //$("#myDivLoadMenu").load('loadmenu.php').trigger('create');
    //alert(url);
    $.ajax({
        type: "POST", //提交的类型
        url: "addMenu-loadcatalogoLeft.php",//提交地址
        data: "_dc="+new Date().getTime(),//参数
        success: function(data){ //回调方法
        $("#myDivLoadcatalogoLeft").html(data).trigger('create');
        }
    });
}
</script>
<style>
tr {
    border-bottom: 1px solid lightgray;
}
</style>

<title><?php echo $CFG_SiteName;?></title>
</head>
<!--<script type="text/javascript">
if (navigator.userAgent.match(/(iPad|iPhone|iPod|Android|Silk)/gi))
   document.title = "京都在线-Mobile";
</script>
--><body>
<?php if (!empty($_POST['prnOrderID'])) include_once 'print.php';?>
 

<div data-role="page" id="pageone" >
    <div data-role="popup" id="myPopupLogin" class="ui-content" style="min-width:250px;">
<form id="formLogin" method="post" action="" data-ajax="false"><div>
          <h3>登录信息
            <input type="hidden" name="showMenu"/>
            <input name="login" type="hidden" id="login" value="1"/>
          </h3>
    <label for="username3330" class="ui-hidden-accessible">用户名:</label>
          <input name="username3330" type="text" id="username3330" placeholder="用户名" value="<?php echo $_REQUEST['username3330'];?>">
          <label for="password3330" class="ui-hidden-accessible">密码:</label>
          <input type="password" name="password3330" id="password3330" placeholder="密码">
<br />
          <input type="submit" value="登录">
        </div> 
  或 	<a href="#" onclick="reloaddoc('login')"  class="ui-btn ui-corner-all ui-shadow ui-icon-user ui-btn-icon-left">注册新用户</a>
</form>
    </div>
  <div data-role="panel" id="myPanel" data-position="right" data-position-fixed="true"  data-swipe-close="true"> 
    <h2>我的资料</h2>
    <p>你可以通过点击面板外部区域或按下 Esc 键或滑动来关闭面板。</p>
   <a href="#pageone" data-rel="close" class="ui-btn ui-corner-all ui-shadow ui-icon-delete ui-btn-icon-left">关闭</a>
  </div> 

  <div data-role="panel" id="myPanelOrders" data-display="overlay"  data-position="right" data-swipe-close="false"  data-ajax="false"> 
    <h2>单据详情</h2><form id="formfinorder" method="post" action="">
<fieldset data-role="controlgroup" data-type="horizontal"  data-mini="true" <?php if ($CFG_statedisabled==1) echo 'class="ui-state-disabled"';?>>
         <label for="prnTicketAuto">自动</label>
       <input name="prntype" type="radio" id="prnTicketAuto" value="auto" checked="checked" onclick="openPanelOrders(<?php echo $LastOrderID;?>,'');"/>
         <label for="prnTicket">整单</label>
       <input name="prntype" type="radio" id="prnTicket" value="" onclick="openPanelOrders(<?php echo $LastOrderID;?>,'');"/>
         <label for="prnCookTicket">厨单</label>
       <input name="prntype" type="radio" id="prnCookTicket" value="cook" onclick="openPanelOrders(<?php echo $LastOrderID;?>,'cook');"/>
         <label for="prnBarTicket">酒水单</label>
       <input name="prntype" type="radio" id="prnBarTicket" value="bar" onclick="openPanelOrders(<?php echo $LastOrderID;?>,'bar');"/>
         <label for="prnDishTicket">催菜</label>
       <input name="prntype" type="radio" id="prnDishTicket" value="dish" onclick="openPanelOrders(<?php echo $LastOrderID;?>,'dish');"/>
         <label for="prnhelp">服务员帮助</label>
       <input name="prntype" type="radio" id="prnhelp" value="help" onclick="openPanelOrders(<?php echo $LastOrderID;?>,'help');"/>
        <!--<label for="prngod">上天</label>
       <input name="prntype" type="radio" id="prngod" value="god" onclick="openPanelOrders(<?php //echo $LastOrderID;?>,'god');"/>-->
</fieldset>
 	<span id="myOrderDetalis"></span>
	<?php include_once  'finorder.php'; ?></form>
    <h5><?php echo $LastOrderID;?></h5>
  </div> 
 
  <div data-role="panel" id="myPanelMenu" data-display="reveal"> 

<span id="myDivLoadcatalogoLeft"><script type="text/javascript">loadcatalogoLeft('');</script></span>  
<div data-role="collapsible">
  <h1>More</h1>
		<img src="_ini/code.png" width="210" height="210" alt="CODE" class="ui-btn ui-corner-all ui-shadow "/>
        <a href="tel:<?php echo $CFG_tel;?>" data-icon="phone" class="ui-btn ui-corner-all ui-shadow ui-icon-phone ui-btn-icon-left"><?php echo $CFG_tel;?></a>
        <a href="<?php echo $CFG_adressMap;?>" class="ui-btn ui-corner-all ui-shadow ui-icon-location ui-btn-icon-left"><?php echo $CFG_adress;?></a>
<a href="#" onclick="location.reload()"  class="ui-btn ui-corner-all ui-shadow ui-icon-refresh ui-btn-icon-left">刷新</a>
    <div data-role="navbar">
      <ul>
        <li><a href="?style=1" target="new">ROMG</a></li>
        <li><a href="?style=2" target="new">BLOR</a></li>
 	 <?php if ($CFG_ShowDesk==1 && $forcein<>1) {?>
	    <li><a href="#" data-icon="grid" onclick="reloaddoc('desk')">餐台</a></li> <?php } ?>
        <li><a href="#" data-icon="bullets" onclick="reloaddoc('index')">点餐</a></li> 
      <?php if (strlen($CompanyName)<>0 && $forcein<>1) { ?> 
        <li><a href="#" data-icon="star" onclick="reloaddoc('orders')">订单</a></li> 
        <li><a href="#" data-icon="delete" onclick="confirmdelete();">清空</a></li>
        <li><a href="#" data-icon="info" onclick="reloaddoc('info')">资料</a></li>
        <li><a href="#" data-icon="back" onclick="reloaddoc('logoff')" >退出</a></li>
	<?php } ?>
        <li><a href="https://pos.916423330.com/publish/res/publish.htm" target="new" data-icon="action">PC版</a></li>
        <li><a href="#pageone" data-icon="carat-l" data-rel="close">隐藏</a></li>
		
        </ul>
    </div>
	
	
	</div>


   </div> 
<form id="formMenuIndex" method="post" action=""><input type="hidden" id="showMenu" name="showMenu" value="index"/></form>

  <div data-role="header" data-position="fixed" data-tap-toggle="false" data-theme="b">
    <a href="#myPanelMenu" id="linkMenu" class="ui-btn ui-corner-all ui-shadow ui-icon-bars ui-btn-icon-left ">菜单</a> 
    <h1><?php echo $CFG_SiteName;?></h1>
	
	
    <?php if ($forcein==1) {?>
	<a href="#" class="ui-btn ui-corner-all ui-shadow ui-icon-grid ui-btn-icon-left">餐台<?php echo $CompanyName;?></a>
    <?php }elseif ($CFG_ShowDesk==1) {?>
	<a href="#" onclick="reloaddoc('desk')" class="ui-btn ui-corner-all ui-shadow ui-icon-grid ui-btn-icon-left"><?php echo  (isset($CompanyName) && strlen($CompanyName)>0)?$CompanyName:"餐台";?></a>
	<?php }elseif (isset($CompanyName)) { ?>
	<a href="#" onclick="reloaddoc('info')" class="ui-btn ui-corner-all ui-shadow ui-icon-grid ui-btn-icon-left"><?php echo $CompanyName;?></a>
	<?php }else{ ?>
	 <a href="#myPopupLogin"  data-rel="popup" data-position-to="window" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-icon-check ui-btn-icon-left ui-btn-a" data-transition="none">登录</a>
	 <?php }?>
	 
	 
	 
  </div>

  <div data-role="main" class="ui-content">
  <span id="myDivPrnResult"></span>
  <?php //include_once 'top.php';?>
<?php 
console_log('$showMenu	:	'.$showMenu);
if ($showMenu=='menu') 
	include_once  'menu.php';
else if ($showMenu=='info')
	include_once  'info.php';
else if ($showMenu=='desk') 
	include_once  'desk.php';
else if ($showMenu=='orders') 
	include_once  'orders.php';
else if ($showMenu=='login') 
	include_once  'login.php';
else if ($showMenu=='printed') 
	echo ($ticket_txt. '<hr>成功下单！<a href="#" onclick="reloaddoc(\'index\')" class="ui-btn ui-corner-all ui-shadow ui-icon-carat-r ui-btn-icon-left ">继续点餐</a>');
else {
	if ($showMenu=='delete'){
		$orders->query('delete from [Order Details] where OrderID='.$LastOrderID);	 
	}

	include_once  'addMenu.php';
	if (!empty($LastOrderID))   {
		echo '<input type="button" data-inline="false" value="确认下单" onclick="javascript:formfinorder.submit();"> '; 
		echo '  <input type="hidden" name="OrderID" id="OrderID" value="'.$LastOrderID.'"/><input type="hidden" name="prnOrderID" id="prnOrderID" value="'.$LastOrderID.'"/>';}
}
?>
   <p>&nbsp;</p>
  
  
  <div data-role="footer" data-position="fixed" data-fullscreen="true" style="text-align:center;" data-tap-toggle="false" data-theme="a">

 <a href="#" onclick="location.reload()"  class="ui-btn ui-corner-all ui-shadow ui-icon-refresh ui-btn-icon-left">刷新</a>
 <?php if (strlen($CompanyName)<>0 and $showMenu!='printed') {  
	$SQlStr="SELECT top 1 sum(UnitPrice*Quantity)  FROM [Order Details]  where OrderID='$FinOrderID'  group by   OrderID ";
	$values = $orders->query($SQlStr);
	if (is_iterable($values)){
  		 foreach ($values as $value){ 
 			$theTotalValue=$value[0]; 
				//echo $theTotalValue;
			}
	  }
			 

$SQlStr="SELECT  top 1 ShipType,PaymentType,Remark,Status FROM Orders  where OrderID='$FinOrderID' ";
//echo $SQlStr.'<br>';
	
		$values = $orders->query($SQlStr);
		if (is_iterable($values)){
  		  foreach ($values as $pSQlStr1){ 
			$pSQlStr1['ShipType']=loadFromMssql($pSQlStr1['ShipType']);
			$pSQlStr1['PaymentType']=loadFromMssql($pSQlStr1['PaymentType']);
			$pSQlStr1['Remark']=loadFromMssql($pSQlStr1['Remark']);

				$ShipTypeFin=$pSQlStr1['ShipType']; 
				$PaymentTypeFin=$pSQlStr1['PaymentType']; 
				$RemarkFin=$pSQlStr1['Remark']; 
				//echo "<br>ShipTypeFin  [$ShipTypeFin]   PaymentTypeFin  [$PaymentTypeFin]   RemarkFin  [$RemarkFin]";
			}
		}
			//return $theValue;
?>
<a href="#myPanelOrders" id="linkPanelOrders" onclick="openPanelOrders(<?php echo $LastOrderID;?>,'');"  class="ui-btn ui-corner-all ui-shadow ui-icon-shop ui-btn-icon-left "><span id="myDivTotal"> <?php echo number_format($theTotalValue,2);?></span></a>
<a href="#" onclick="confirmsumbit(<?php echo $LastOrderID;?>,'');"  class="ui-btn ui-corner-all ui-shadow ui-icon-check ui-btn-icon-left">下单</a>  
<a href="#" onclick="confirmsumbit(<?php echo $LastOrderID;?>,'cook');" class="ui-btn ui-corner-all ui-shadow ui-icon-cloud ui-btn-icon-left">厨单</a>  
<?php } ?> 
	</div>
</div>
</div>



</body>
</html>