<?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;
$r=$_POST;
//定单ID
$ddno=time();
//显示商品信息
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($pid)
{global $empire,$dbtbpre;
$r=$empire->fetch1("select pid,pname,price,psay from {$dbtbpre}enewsshopps where pid='$pid'");
echo"<table width=100% border=0 align=center cellpadding=3 cellspacing=1>
  <tr> 
    <td width=69% height=23> 
      <strong>".$r[pname]."</strong>
    </td>
    <td width=31%><strong>费用:$".$r[price]."</strong></td>
  </tr>
  <tr> 
    <td colspan=2>&nbsp;".$r[psay]."</td>
  </tr>
</table>";
return $r[price];
}

//显示支付方式
function ShowPayfs($payfsid,$r,$price)
{global $empire,$user_tablename,$user_money,$user_userid,$user_userfen,$public_r,$dbtbpre;
$add=$empire->fetch1("select payid,payname,payurl,paysay,userpay,userfen from {$dbtbpre}enewsshoppayfs where payid='$payfsid'");
//总金额
$buyallmoney=$r[alltotal]+$price;
if($add[userfen]&&$r[fp])
{
printerror("FenNotFp","history.go(-1)",1);
}
//发票
if($r[fp])
{
$fptotal=$r[alltotal]*($public_r[fpnum]/100);
$afp="+发票费(".$fptotal.")";
$buyallmoney+=$fptotal;
}
$buyallfen=$r[alltotalfen]+$price;
$returntotal="采购总额(".$r[alltotal].")+发送费(".$price.")".$afp."=总额(<b>".$buyallmoney." 元</b>)";
$mytotal="结算总金额为:<b><font color=red>".$buyallmoney." 元</font></b> 全部";
//是否登陆
if($add[userfen]||$add[userpay])
{
if(!getcvar('mluserid'))
{
printerror("NotLoginTobuy","history.go(-1)",1);
}
$user=$empire->fetch1("select ".$user_userfen.",".$user_money." from ".$user_tablename." where ".$user_userid."='".getcvar('mluserid')."' limit 1");
//积分购买
if($add[userfen])
{
if($r[alltotalfen]+$price>$user[$user_userfen])
{
printerror("NotEnoughFenBuy","history.go(-1)",1);
}
$returntotal="采购总点数(".$r[alltotalfen].")+发送点数费(".$price.")=总点数(<b>".$buyallfen." 点</b>)";
$mytotal="结算总点数为:<b><font color=red>".$buyallfen." 点</font></b> 全部";
}
else//扣除余额
{
if($buyallmoney>$user[$user_money])
{
printerror("NotEnoughMoneyBuy","history.go(-1)",1);
}
}
}
echo $add[payname];
$return[0]=$returntotal;
$return[1]=$mytotal;
return $return;
}
//发票抬头
if(empty($r[fp]))
{$r[fptt]="";}
?>
<!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/css.css rel=stylesheet type=text/css>
</head>

<body>
<form action="../../enews/index.php" method="post" name="myorder" id="myorder">
<input type=hidden name=enews value=AddDd>
  <table width="100%%" border="0" align="center" cellpadding="3" cellspacing="1">
    <tr> 
      <td height="23" bgcolor="#FFFFFF"><strong>订单号: 
        <?=$ddno?>
        <input name="ddno" type="hidden" id="ddno" value="<?=$ddno?>">
        </strong></td>
    </tr>
    <tr> 
      <td height="23" bgcolor="#EFEFEF"><strong>选择的商品</strong></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%"> 
              <?=$r[truename]?>
              <input name="truename" type="hidden" id="truename" value="<?=$r[truename]?>"> 
            </td>
          </tr>
          <tr> 
            <td>OICQ:</td>
            <td> 
              <?=$r[oicq]?>
              <input name="oicq" type="hidden" id="oicq" value="<?=$r[oicq]?>"></td>
          </tr>
          <tr> 
            <td>MSN:</td>
            <td> 
              <?=$r[msn]?>
              <input name="msn" type="hidden" id="msn" value="<?=$r[msn]?>"></td>
          </tr>
          <tr> 
            <td>固定电话:</td>
            <td> 
              <?=$r[calla]?>
              <input name="call" type="hidden" id="oicq3" value="<?=$r[calla]?>"> 
            </td>
          </tr>
          <tr> 
            <td>移动电话:</td>
            <td> 
              <?=$r[phonea]?>
              <input name="phone" type="hidden" id="call" value="<?=$r[phonea]?>"></td>
          </tr>
          <tr> 
            <td>联系邮箱:</td>
            <td> 
              <?=$r[email]?>
              <input name="email" type="hidden" id="email" value="<?=$r[email]?>"> 
            </td>
          </tr>
          <tr> 
            <td>联系地址:</td>
            <td> 
              <?=$r[addressa]?>
              <input name="address" type="hidden" id="call3" value="<?=$r[addressa]?>" size="60"> 
            </td>
          </tr>
          <tr> 
            <td>邮编:</td>
            <td> 
              <?=$r[zip]?>
              <input name="zip" type="hidden" id="zip" value="<?=$r[zip]?>" size="8"> 
            </td>
          </tr>
          <tr> 
            <td>备注:</td>
            <td> 
              <?=nl2br($r[bz])?> <input name="bz" type="hidden" value="<?=$r[bz]?>" size="8"> 
            </td>
          </tr>
        </table></td>
    </tr>
    <tr> 
      <td height="23" bgcolor="#EFEFEF"><strong>选择配送方式 
        <input name="psid" type="hidden" id="psid" value="<?=$r[psid]?>" size="8">
        </strong></td>
    </tr>
    <tr> 
      <td> 
        <?
	  $price=ShowPs($r[psid]);
	  ?>
      </td>
    </tr>
    <tr> 
      <td height="23" bgcolor="#EFEFEF"><strong>选择支付方式 
        <input name="payfsid" type="hidden" id="payfsid" value="<?=$r[payfsid]?>" size="8">
        </strong></td>
    </tr>
    <tr> 
      <td> 
        <?
	  $total=ShowPayfs($r[payfsid],$r,$price);
	  ?>
      </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%"> 
              <?=$r[g_truename]?>
              <input name="g_truename" type="hidden" id="truename3" value="<?=$r[g_truename]?>"> 
            </td>
          </tr>
          <tr> 
            <td>OICQ:</td>
            <td> 
              <?=$r[g_oicq]?>
              <input name="g_oicq" type="hidden" id="oicq4" value="<?=$r[g_oicq]?>"></td>
          </tr>
          <tr> 
            <td>MSN:</td>
            <td> 
              <?=$r[g_msn]?>
              <input name="g_msn" type="hidden" id="g_msn" value="<?=$r[g_msn]?>"></td>
          </tr>
          <tr> 
            <td>固定电话:</td>
            <td> 
              <?=$r[g_call]?>
              <input name="g_call" type="hidden" id="call4" value="<?=$r[g_call]?>"> 
            </td>
          </tr>
          <tr> 
            <td>移动电话:</td>
            <td> 
              <?=$r[g_phone]?>
              <input name="g_phone" type="hidden" id="phone" value="<?=$r[g_phone]?>"></td>
          </tr>
          <tr> 
            <td>联系邮箱:</td>
            <td> 
              <?=$r[g_email]?>
              <input name="g_email" type="hidden" id="email3" value="<?=$r[g_email]?>"> 
            </td>
          </tr>
          <tr> 
            <td>联系地址:</td>
            <td> 
              <?=$r[g_address]?>
              <input name="g_address" type="hidden" id="address" size="60" value="<?=$r[g_address]?>"> 
            </td>
          </tr>
          <tr> 
            <td>邮编:</td>
            <td> 
              <?=$r[g_zip]?>
              <input name="g_zip" type="hidden" id="g_zip" size="8" value="<?=$r[g_zip]?>"> 
            </td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td height="23" bgcolor="#EFEFEF"><strong>结算信息 
        <input name="fp" type="hidden" id="fp" value="<?=$r[fp]?>">
        <input name="fptt" type="hidden" id="fptt" value="<?=$r[fptt]?>">
        </strong></td>
    </tr>
    <tr>
      <td><table width="100%%" border="0" align="center" cellpadding="3" cellspacing="1">
          <tr>
            <td><div align="center"><?=$total[0]?></div></td>
          </tr>
          <tr> 
            <td><div align="center">
                <?=$total[1]?>
              </div></td>
          </tr>
        </table></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)">
        </div></td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
    </tr>
  </table>
</form>
</body>
</html>
<?
db_close();
$empire=null;
?>