<?php
require("../../class/connect.php");
include("../../class/config.php");
include("../../class/q_functions.php");
include("../../class/db_sql.php");
include("../../class/class.php");
include("../../class/user.php");
$link=db_connect();
$empire=new mysqlquery();
$editor=1;
//显示商品信息
function ShowBuyproduct(){
	global $empire,$class_r,$dbtbpre;
	$buycar=getcvar('mybuycar');
	$record="!";
	$field="|";
	$r=explode($record,$buycar);
	$alltotal=0;
	echo"<table width=100% border=0 align=center cellpadding=3 cellspacing=1>
          <tr bgcolor=#698CC3> 
            <td width=9% height=20> <div align=center><font color=#FFFFFF>编号</font></div></td>
            <td width=36%> <div align=center><font color=#FFFFFF>商品名称</font></div></td>
            <td width=13%> <div align=center><font color=#FFFFFF>市场价格</font></div></td>
            <td width=13%> <div align=center><font color=#FFFFFF>优惠价格</font></div></td>
            <td width=8%> <div align=center><font color=#FFFFFF>数量</font></div></td>
            <td width=16%> <div align=center><font color=#FFFFFF>小计</font></div></td>
          </tr>";
		  $return[0]=0;
		  $return[1]=0;
		  $return[2]=0;
	for($i=0;$i<count($r)-1;$i++)
	{
		$pr=explode($field,$r[$i]);
		$productid=$pr[1];
		$fr=explode(",",$pr[1]);
		//ID
		$classid=$fr[0];
		$id=$fr[1];
		//数量
		$num=$pr[2];
		if(empty($num))
		{$num=1;}
		//取得产品信息
		$productr=$empire->fetch1("select title,tprice,price,titleurl,groupid,classid,newspath,filename,id,titlepic,buyfen from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where classid='$classid' and id='$id' limit 1");
		//是否全部积分
		if(!$productr[buyfen])
		{
			$return[0]=1;
		}
		$return[1]+=$productr[buyfen]*$num;
		//产品图片
		if(empty($productr[titlepic]))
		{$productr[titlepic]="../../data/images/notimg.gif";}
		//返回链接
		$titleurl=sys_ReturnBqTitleLink($productr);
		$thistotal=$productr[price]*$num;
		$alltotal+=$thistotal;
		echo"<tr>
	<td align=center>".$productr[id]."</td>
	<td align=center><a href='".$titleurl."' target=_blank>".$productr[title]."</a></td>
	<td align=center>$".$productr[tprice]."</td>
	<td align=center><b>$".$productr[price]."</b></td>
	<td align=center>".$num."</td>
	<td align=center>".$thistotal."</td>
	</tr>";
    }
	//支付积分付费
	if(!$return[0])
	{
	$a="<tr> 
      <td colspan=6><div align=right>合计积分:<strong>".$return[1]."</strong></div></td>
      <td>&nbsp;</td>
    </tr>";
	}
	echo"<tr> 
      <td colspan=6><div align=right>合计:<strong>\$".$alltotal."</strong></div></td>
      <td>&nbsp;</td>
    </tr>".$a."
  </table>";
  $return[2]=$alltotal;
  return $return;
}

//显示配送方式
function ShowPs()
{global $empire,$dbtbpre;
$sql=$empire->query("select pid,pname,price,psay from {$dbtbpre}enewsshopps order by pid");
while($r=$empire->fetch($sql))
{
echo"<table width=100% border=0 align=center cellpadding=3 cellspacing=1>
  <tr> 
    <td width=69% height=23> 
      <input type=radio name=psid value=".$r[pid]."><strong>".$r[pname]."</strong>
    </td>
    <td width=31%><strong>费用:$".$r[price]."</strong></td>
  </tr>
  <tr> 
    <td colspan=2>&nbsp;".$r[psay]."</td>
  </tr>
</table>";
}
}

//显示支付方式
function ShowPayfs($pr)
{global $empire,$user_tablename,$user_money,$user_userid,$user_userfen,$dbtbpre;
$sql=$empire->query("select payid,payname,payurl,paysay,userpay,userfen from {$dbtbpre}enewsshoppayfs order by payid");
echo"<table width=100% border=0 align=center cellpadding=3 cellspacing=1>";
while($r=$empire->fetch($sql))
{
$dis="";
$words="";
//扣点数
if($r[userfen])
{
if($pr[0])
{
$dis=" disabled";
$words="(您选择的商品至少有一个不支持积分购买)";
}
else
{
	if(getcvar('mluserid'))
	{
		$user=$empire->fetch1("select ".$user_userfen." from ".$user_tablename." where ".$user_userid."='".getcvar('mluserid')."' limit 1");
		if($user[$user_userfen]<$pr[1])
		{
			$dis=" disabled";
			$words="(您的帐号积分不足,不能使用此支付方式)";
		}
	}
	else
	{
		$dis=" disabled";
		$words="(您未登陆,不能使用此支付方式)";
	}
}
}
//余额扣除
elseif($r[userpay])
{
	if(getcvar('mluserid'))
	{
		$user=$empire->fetch1("select ".$user_money." from ".$user_tablename." where ".$user_userid."='".getcvar('mluserid')."' limit 1");
		if($user[$user_money]<$pr[2])
		{
			$dis=" disabled";
			$words="(您的帐号余额不足,不能使用此支付方式)";
		}
	}
	else
	{
		$dis=" disabled";
		$words="(您未登陆,不能使用此支付方式)";
	}
}
//网上/手机支付
elseif($r[payurl])
	{
	$words="(订单下后,系统会自动转到支付接口)";
    }
else
	{}
echo"<tr><td><b><input type=radio name=payfsid value=".$r[payid].$dis.">".$r[payname]."&nbsp;".$words."</b></td></tr><tr><td>".$r[paysay]."</td></tr>";
}
echo"</table>";
}

//用户信息
if(getcvar('mluserid'))
{
$user=islogin();
$email=GetUserEmail($user[userid],$user[username]);
$r=$empire->fetch1("select truename,oicq,msn,`call`,phone,address,zip from {$dbtbpre}enewsmemberadd where userid='$user[userid]' limit 1");
}
?>
<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN>
<html>
<head>
<meta http-equiv=Content-Type content=text/html; charset=gb2312>
<title>填写订单</title>
<link href=../../data/images/qcss.css rel=stylesheet type=text/css>
<script>
function copyinfo(obj)
{
obj.g_truename.value=obj.truename.value;
obj.g_oicq.value=obj.oicq.value;
obj.g_msn.value=obj.msn.value;
obj.g_call.value=obj.calla.value;
obj.g_phone.value=obj.phonea.value;
obj.g_email.value=obj.email.value;
obj.g_address.value=obj.addressa.value;
obj.g_zip.value=obj.zip.value;
}
</script>
</head>

<body>
<form action="../SubmitOrder/index.php" method="post" name="myorder" id="myorder">
  <table width="100%%" border="0" align="center" cellpadding="3" cellspacing="1">
    <tr> 
      <td height="23" bgcolor="#EFEFEF"><strong>选择的商品</strong>[<a href="../buycar">修改购物车</a>]</td>
    </tr>
    <tr> 
      <td> 
        <?
	  $pr=ShowBuyproduct();
	  ?>
      </td>
    </tr>
    <tr> 
      <td height="23" bgcolor="#EFEFEF"><strong>订货人信息</strong></td>
    </tr>
    <tr> 
      <td><table width="100%%" border="0" cellspacing="1" cellpadding="3">
          <tr> 
            <td width="20%">真实姓名:</td>
            <td width="80%"><input name="truename" type="text" id="truename" value="<?=$r[truename]?>">
              *</td>
          </tr>
          <tr> 
            <td>OICQ:</td>
            <td><input name="oicq" type="text" id="oicq" value="<?=$r[oicq]?>"></td>
          </tr>
          <tr> 
            <td>MSN:</td>
            <td><input name="msn" type="text" id="msn" value="<?=$r[msn]?>"></td>
          </tr>
          <tr> 
            <td>固定电话:</td>
            <td><input name="calla" type="text" id="oicq3" value="<?=$r[call]?>">
              *</td>
          </tr>
          <tr> 
            <td>移动电话:</td>
            <td><input name="phonea" type="text" id="call" value="<?=$r[phone]?>"></td>
          </tr>
          <tr> 
            <td>联系邮箱:</td>
            <td><input name="email" type="text" id="email" value="<?=$email?>">
              * </td>
          </tr>
          <tr> 
            <td>联系地址:</td>
            <td><input name="addressa" type="text" id="call3" value="<?=$r[address]?>" size="60">
              * </td>
          </tr>
          <tr> 
            <td>邮编:</td>
            <td><input name="zip" type="text" id="zip" value="<?=$r[zip]?>" size="8">
              * </td>
          </tr>
          <tr> 
            <td>备注:</td>
            <td><textarea name="bz" cols="60" rows="6" id="bz"></textarea></td>
          </tr>
        </table></td>
    </tr>
    <tr> 
      <td height="23" bgcolor="#EFEFEF"><strong>选择配送方式</strong></td>
    </tr>
    <tr> 
      <td> 
        <?
	  ShowPs();
	  ?>
      </td>
    </tr>
    <tr> 
      <td height="23" bgcolor="#EFEFEF"><strong>选择支付方式</strong></td>
    </tr>
    <tr> 
      <td> 
        <?
	  ShowPayfs($pr);
	  ?>
      </td>
    </tr>
    <tr> 
      <td height="23" bgcolor="#EFEFEF"><strong>收货人信息</strong>[<a href="javascript:copyinfo(document.myorder);">复制收货人的信息</a>]</td>
    </tr>
    <tr> 
      <td><table width="100%%" border="0" cellspacing="1" cellpadding="3">
          <tr> 
            <td width="20%">真实姓名:</td>
            <td width="80%"><input name="g_truename" type="text" id="truename3">
              *</td>
          </tr>
          <tr> 
            <td>OICQ:</td>
            <td><input name="g_oicq" type="text" id="oicq4"></td>
          </tr>
          <tr> 
            <td>MSN:</td>
            <td><input name="g_msn" type="text" id="g_msn"></td>
          </tr>
          <tr> 
            <td>固定电话:</td>
            <td><input name="g_call" type="text" id="call4">
              *</td>
          </tr>
          <tr> 
            <td>移动电话:</td>
            <td><input name="g_phone" type="text" id="phone"></td>
          </tr>
          <tr> 
            <td>联系邮箱:</td>
            <td><input name="g_email" type="text" id="email3">
              *</td>
          </tr>
          <tr> 
            <td>联系地址:</td>
            <td><input name="g_address" type="text" id="address" size="60">
              *</td>
          </tr>
          <tr> 
            <td>邮编:</td>
            <td><input name="g_zip" type="text" id="g_zip" size="8">
              *</td>
          </tr>
        </table></td>
    </tr>
	<?
	//提供发票
	if($public_r[havefp])
	{
	?>
    <tr> 
      <td height="23" bgcolor="#EFEFEF">是否需要发票:
        <input name="fp" type="checkbox" id="fp" value="1">
        是(需增加 
        <?=$public_r[fpnum]?>
        %的费用),发票抬头:
        <input name="fptt" type="text" id="fptt" size="38"></td>
    </tr>
	<?
	}
	?>
    <tr> 
      <td><div align="center"> 
          <input type="submit" name="Submit" value=" 下一步 ">
          &nbsp;&nbsp; 
          <input type="reset" name="Submit2" value="重置">
          &nbsp;&nbsp; 
          <input type="button" name="Submit3" value="上一步" onclick="history.go(-1)">
          <input name="alltotal" type="hidden" id="alltotal" value="<?=$pr[2]?>">
          <input name="alltotalfen" type="hidden" id="alltotalfen" value="<?=$pr[1]?>">
        </div></td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
    </tr>
  </table>
</form>
</body>
</html>
<?
db_close();
$empire=null;
?>