<?
	include_once("admin.config.inc.php");
	include("connect.php");
	include("functions.php");
	include("security.php");
	$qrysmscharge = "select * from general_setting where id='1'";
	$ressmscharge = mysql_query($qrysmscharge);
	$objsmscharge = mysql_fetch_object($ressmscharge);
	$SMSCHARGE = $objsmscharge->smsrateincl;
	$dinarvalue = $objsmscharge->dinars;
		
		if(!$_GET['pgno'])
		{
			$PageNo = 1;
		}
		else
		{
			$PageNo = $_GET['pgno'];
		}
	if($_POST["submit"]!="" || $_GET["info"]!="")
	{
		if($_POST["submit"]!="")
		{
			if($_POST["datefrom"]!="") { $startdate = ChangeDateFormat($_POST["datefrom"]); }
			if($_POST["dateto"]!="") { $enddate = ChangeDateFormat($_POST["dateto"]); }

			$aid = $_POST["auctionid"];
			
			if($_POST["auctiontype_standard"]=="std") { $auctype = ""; } 
			if($_POST["auctiontype_fixedprice"]=="fix") { $auctype = "fixedpriceauction=1";} 
			if($_POST["auctiontype_off"]=="off") { if($_POST["auctiontype_fixedprice"]!="") { $auctype .= " or offauction=1"; } else {$auctype = "offauction=1"; }} 
	
			if($_POST["auctionstatus_future"]=="1") { $aucstatus = " a.auc_status=1 ";} 
			if($_POST["auctionstatus_running"]=="2") {  if($_POST["auctionstatus_future"]!="") { $aucstatus .= " or a.auc_status=2 "; } else { $aucstatus = " a.auc_status=2 "; }} 
			if($_POST["auctionstatus_ended"]=="3") {  if($_POST["auctionstatus_future"]!="" || $_POST["auctionstatus_running"]!="") { $aucstatus .= " or a.auc_status=3"; } else { $aucstatus = "a.auc_status=3"; } } 
			
			if($_POST["orderby"]=="code") { $orderby = " order by a.auctionID"; }
			if($_POST["orderby"]=="dateend") { $orderby = " order by a.auc_end_date"; }
			if($_POST["orderby"]=="itemname") { $orderby = " order by p.name"; }
			if($_POST["orderby"]=="datestart") { $orderby = " order by a.auc_start_date"; }
			if($_POST["orderby"]=="category") { $orderby = " order by a.categoryID"; }
		}
		else
		{
			$info = explode("|",$_GET["info"]);
			$startdate = $info[0];
			$enddate = $info[1];
			$aid = $info[2];
			$auctype = stripslashes($info[3]);
			$aucstatus = $info[4];
			$orderby = $info[5];
		}

	if($_POST["listtype"]=="list" || $_POST["listtype"]=="")
	{
		if($aid!="")
		{
		$qrysel = "select *,p.name as pname from auction a left join products p on a.productID=p.productID left join categories c on a.categoryID=c.categoryID where a.auctionID='$aid' ";
		}
		else
		{
			$qrysel = "select *,p.name as pname from auction a left join products p on a.productID=p.productID left join categories c on a.categoryID=c.categoryID where auc_start_date>='$startdate' and auc_end_date<='$enddate'";
		}
		
		if($aid=="" && ($auctype!="" || $aucstatus!=""))
		{
			$qrysel = "select *,p.name as pname from auction a left join products p on a.productID=p.productID left join categories c on a.categoryID=c.categoryID where auc_start_date>='$startdate' and auc_end_date<='$enddate' and ";
			
		}
		
		if($aid=="")
		{
			
			if($aucstatus!="")
			{
				if($aid!="" || $auctype!="")
				{
					$qrysel .= " ($aucstatus) and ";
				}
				else
				{
					$qrysel .= " ($aucstatus)";
				}
			}
			
			if($auctype!="" && $auctype!="standard")
			{
				if($aid!="")
				{
					$qrysel .= " ($auctype) and ";	
				}
				else
				{
					$qrysel .= " ($auctype) ";
				}
			}
			
			if($aid!="")
			{
					$qrysel .= " a.auctionID='$aid' ";
			}
	
			if($orderby!="")
			{
				$qrysel .= $orderby;
			}

		}
	$urldata1 = "info=".$startdate."|".$enddate."|".$aid."|".$auctype."|".$aucstatus."|".$orderby;	
	$urldata = $urldata1;
	}
	
	elseif($_POST["listtype"]=="aggregate")
	{
		$qrysel = "select *,p.name as pname from auction a left join products p on a.productID=p.productID where auc_start_date >= '".$startdate."' and auc_end_date <= '".$enddate."' and auc_status='3'";
		if($auctype!="" && $auctype!="standard")
		{
			if($aid=="")
			{
			$qrysel .= " and (".$auctype.")";
			}
		}
		if($aid!="")
		{
			$qrysel .= " and a.auctionID='".$aid."'";
		}
	}
		$ressel = mysql_query($qrysel);
		$total = mysql_num_rows($ressel);
		$totalpages=ceil($total/$PRODUCTSPERPAGE);

	if($_POST["listtype"]!="aggregate")
	{
		if($totalpages>=1)
		{
			$startrow=$PRODUCTSPERPAGE*($PageNo-1);
			$qrysel	.=" LIMIT $startrow,$PRODUCTSPERPAGE";
			$ressel=mysql_query($qrysel);
			$total=mysql_num_rows($ressel);
		}
	}
}
?>
<!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 http-equiv="Content-Type" content="text/html; charset=<?=$lng_characset;?>" />
<META content="MSHTML 6.00.2600.0" name=GENERATOR>
<link rel="stylesheet" href="main.css" type="text/css">
<link href="zpcal/themes/aqua.css" rel="stylesheet" type="text/css" media="all" title="Calendar Theme - aqua.css" />
<script type="text/javascript" src="zpcal/src/utils.js"></script>
<script type="text/javascript" src="zpcal/src/calendar.js"></script>
<script type="text/javascript" src="zpcal/lang/calendar-en.js"></script>
<script type="text/javascript" src="zpcal/src/calendar-setup.js"></script>
<script language="javascript">
function calc_counter_from_time(diff) {
  if (diff > 0) {
    hours=Math.floor(diff / 3600)

    minutes=Math.floor((diff / 3600 - hours) * 60)

    seconds=Math.round((((diff / 3600 - hours) * 60) - minutes) * 60)
  } else {
    hours = 0;
    minutes = 0;
    seconds = 0;
  }

  if (seconds == 60) {
    seconds = 0;
  }

  if (minutes < 10) {
    if (minutes < 0) {
      minutes = 0;
    }
    minutes = '0' + minutes;
  }
  if (seconds < 10) {
    if (seconds < 0) {
      seconds = 0;
    }
    seconds = '0' + seconds;
  }
  if (hours < 10) {
    if (hours < 0) {
      hours = 0;
    }
    hours = '0' + hours;
  }
  return hours + ":" + minutes + ":" + seconds;
}
</script>
<title><? echo $ADMIN_MAIN_SITE_NAME." - Bidding Report"; ?></title>
</head>

<body>
<TABLE width="100%"  border=0 cellPadding=0 cellSpacing=10>
  <!--DWLayoutTable-->
    <TR> 
      <TD width="100%" class="H1">查询拍卖结果</TD>
    </TR>
  	<TR>
    <TD background="images/vdots.gif"><IMG height=1 
      src="images/spacer.gif" width=1 border=0></TD>
	</TR>
	<tr>
		<td height="10"></td>
	</tr>
	<tr>
		<td height="5"></td>
	</tr>
		<? if(isset($total))
		{
			if($total==0)
			{
		?>
	<TR>
    	<TD><!--content-->
		<table width="70%" border="0" cellspacing="1" cellpadding="1" align="center"> 
		<tr>
			<td height="8"></td>
		</tr>
		<tr>
			<td>
				<table width="100%" border="0" cellspacing="1" cellpadding="1" align="center" bgcolor="#000000">
					<tr> 
					  <td> 
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
						  <tr> 
							<td class=th-a > 
							  <div align="center">没有数据.</div>
							</td>
						  </tr>
						</table>
					  </td>
					</tr>
				</table>
			</td>
		</tr>			
      </table>
	 </TD>
   </TR>
	 <?
	 	}
		else
		{
			if($_POST["listtype"]=="list" || $_POST["listtype"]=="")
			{
	?>
	<TR>
    	<TD><!--content-->
          <TABLE width="100%" border=1 cellSpacing=0 class=t-a>
            <!--DWLayoutTable-->
              <TR class=th-a> 
				<!--<TD nowrap width="5%">User Id</TD>-->
				<TD width="7%" align="left" nowrap="nowrap">Type</TD>
				<TD width="10%" align="center">Status</TD>
				<TD width="10%" nowrap="nowrap" align="center">拍卖编号</TD>
				<TD width="30%" nowrap="nowrap" align="center">商品名称</TD>
				<TD width="10%" align="center" nowrap="nowrap">类别</TD>
				<TD width="10%" align="center" nowrap="nowrap">开始日期</TD>
				<TD width="10%" align="center" nowrap="nowrap">结束日期</TD>
				<TD width="10%" align="center" nowrap="nowrap">持续时长</TD>
				<TD width="10%" align="center" nowrap="nowrap">价格</TD>
				<TD width="10%" align="center" nowrap="nowrap">参与会员数</TD>
				<TD width="10%" align="center" nowrap="nowrap">出价次数</TD>
				<TD width="10%" align="center" nowrap="nowrap">收入</TD>
				<TD width="10%" align="center" nowrap="nowrap">选项</TD>
			 </TR>
		<?
			while($obj = mysql_fetch_object($ressel))
			{
				if ($colorflg==1){
					$colorflg=0;
					echo "<TR bgcolor=\"#f4f4f4\"> ";
				}else{
					$colorflg=1;
				  	echo "<TR> ";
				}
				if($obj->auc_status=="2") {
					if($obj->pause_status=="1")
					{
						$status = "<font color='green'>已暂停</font>";	
					}
					else
					{
					 $status = "<font color='red'>进行中</font>";
					}
				  }
				 if($obj->auc_status=="1") { $status = "<font color='green'>等待上架</font>"; }
				if($obj->auc_status=="3") { $status = "<font color='blue'>已卖出</font>"; }
				if($obj->auc_status=="4") { $status = "<font color='green'>待定</font>"; }				
				$qr1 = "select *,sum(bid_count) as totalbids from bid_account where auction_id='".$obj->auctionID."' and bid_flag='d' group by auction_id";
				$rs1 = mysql_query($qr1);
				$objbids1 = mysql_fetch_object($rs1);
				
				$qr2 = "select * from bid_account where auction_id='".$obj->auctionID."' and bid_flag='d' group by user_id";
				$rs2 = mysql_query($qr2);
				$totaluser = mysql_num_rows($rs2);
				
				if($obj->fixedpriceauction=="1"){ $auctiontype = "定价"; }
				if($obj->pennyauction=="1"){ $auctiontype = "加一分"; }
				if($obj->nailbiterauction=="1"){ $auctiontype = "不眨眼"; }
				if($obj->offauction=="1"){ $auctiontype = "100%免费"; }
				if($obj->nightauction=="1"){ $auctiontype = "晚上"; }
				if($obj->openauction=="1"){ $auctiontype = "一般"; }
				
				$revenues = explode("|",GetTotalBidsAmount($obj->auctionID,$SMSCHARGE));
		?>
				<TD width="7%" align="left" nowrap="nowrap"><?=$auctiontype;?></TD>
				<TD width="10%" align="center"><?=$status;?></TD>
				<TD width="10%" nowrap="nowrap" align="center"><?=$obj->auctionID;?></TD>
				<TD width="10%" nowrap="nowrap" align="center"><?=$obj->pname;?></TD>
				<TD width="10%" align="center" nowrap="nowrap"><?=$obj->name;?></TD>
				<TD width="10%" align="center" nowrap="nowrap"><?=arrangedate($obj->auc_start_date);?>&nbsp;<?=$obj->auc_start_time;?></TD>
				<TD width="10%" align="center" nowrap="nowrap">
				<?
					if($obj->auc_status=="3")
					{
					   echo	arrangedate(substr($obj->auc_final_end_date,0,10))."&nbsp;".substr($obj->auc_final_end_date,11);
					}
					else
					{
						echo arrangedate($obj->auc_end_date)."&nbsp;".$obj->auc_end_time;
					}
					?>
				</TD>
				<TD width="10%" align="center" nowrap="nowrap">
				<span id="time_<?=$obj->auctionID;?>">
					<?
						echo "<script language='javascript'>
							document.getElementById('time_".$obj->auctionID."').innerHTML = calc_counter_from_time('".$obj->total_time."');
							</script>";	
					?>
				</span>
				</TD>
				<TD width="10%" align="right" nowrap="nowrap"><?=$Currency.$obj->auc_final_price;?></TD>
				<TD width="10%" align="center" nowrap="nowrap"><?=$totaluser!=""?$totaluser:"0";?></TD>
				<TD width="10%" align="center" nowrap="nowrap"><?=$objbids1->totalbids!=""?$objbids1->totalbids:"0";?></TD>
				<TD width="10%" align="center" nowrap="nowrap"><?=$revenues[0];?></TD>
				<TD width="10%" align="center" nowrap="nowrap">
				<? if($obj->auc_status!=1){ ?>
					<input type="button" name="details" class="bttn" value="详情" onclick="javascript: window.location.href='searchauctiondetails.php?aid=<?=$obj->auctionID;?>&<?=$urldata;?>&pgno=<?=$PageNo;?>'" />
				<? } else { ?>
					<input type="button" name="details" class="bttn" value="Details" />
				<? } ?>
				</TD>
			</tr>
		<?
			}
		?>		
		 </TABLE>
		</TD>	
	</TR>
	<Tr>
		<td>
		  <?
			if($PageNo>1)
			{
			  $PrevPageNo = $PageNo-1;
		  ?>
		  <A class='paging' href="searchauctionresult.php?pgno=<?=$PrevPageNo;?>&<?=$urldata;?>">&lt; 上一页</A>
		  <?
		   }
		  ?> &nbsp;&nbsp;&nbsp;
		  <?php
			if($PageNo<$totalpages)
			{
			 $NextPageNo = 	$PageNo + 1;
		  ?>
		  <A class='paging' id='next' href="searchauctionresult.php?pgno=<?=$NextPageNo;?>&<?=$urldata;?>">下一页 &gt;</A>
		  <?
		   }
		  ?>
		 </td>
		</Tr>
	<?
		
		}
		elseif($_POST["listtype"]=="aggregate")
		{
			while($obj = mysql_fetch_object($ressel))
			{
				if($obj->fixedpriceauction=="1")
				{
					$fprice = $obj->auc_fixed_price;
				}
				elseif($obj->offauction=="1")
				{
					$fprice = "0.00";
				}
				else
				{
					$fprice = $obj->auc_final_price;
				}
				
				$totalcost = $obj->actual_cost + $totalcostplus;
				$totalcostplus = $totalcost;
				
				$finalprice = $fprice + $fpriceplus;
				$fpriceplus = $finalprice;
				
				$priceinfo = explode("|",GetTotalBidsAmount($obj->auctionID,$SMSCHARGE));
				
				$biddingprice = $priceinfo[0] + $biddingprice1;
				$biddingprice1 = $biddingprice;
	
				$onlineprice = $priceinfo[1] + $onlineprice1;
				$onlineprice1 = $onlineprice;
	
				$smsprice = $priceinfo[2] + $smsprice1;
				$smsprice1 = $smsprice;
			}
	?>
	<TR>
    	<TD width="500px"><!--content-->
          <TABLE width="100%" border=1 cellSpacing=0 class=t-a>
            <!--DWLayoutTable-->
              <TR class=th-a> 
					<td><? if($_POST["auctiontype"]=="std") { ?>全部标准拍卖报表<? } elseif($_POST["auctiontype"]=="fix"){?>全部定价拍卖报表<? } elseif($_POST["auctiontype"]=="off"){ ?>全部免费拍卖报表<? } ?></td>
			  </TR>
		 </TABLE>
		<TABLE width="100%" border="0">
			<tr height="5">
				<td colspan="3">&nbsp;</td>
			</tr>
			<tr>
				<td width="70%"><strong>所有已结束的拍卖</strong></td>
				<td width="15%" align="center"><strong>Dinars</strong></td>
				<td width="25%" align="center"><strong>Euro</strong></td>
			</tr>
			<tr>
				<td colspan="2">
					<TABLE width="70%" border="0">
						<tr>
							<td width="70%">已获胜拍卖</td>
							<td width="15%"><?=$total;?></td>
						</tr>
					</TABLE>
				</td>
			</tr>
			<tr>
				<td width="70%">商品成本支出</td>
				<td align="right" style="padding-right: 20px;" width="15%"><?=number_format(($totalcost * $dinarvalue),2);?></td>
				<td width="25%" align="right"><?=$Currency;?><?=number_format($totalcost,2);?></td>
			</tr>
			<tr height="5">
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td width="70%">短信投标收入</td>
				<td align="right" style="padding-right: 20px;" width="15%"><?=number_format(($smsprice * $dinarvalue),2);?></td>
				<td width="25%" align="right"><?=$Currency;?><?=number_format($smsprice,2);?></td>
			</tr>
			<tr>
				<td width="70%">在线投标收入</td>
				<td align="right" style="padding-right: 20px;" width="15%"><?=number_format(($onlineprice * $dinarvalue),2);?></td>
				<td width="25%" align="right"><?=$Currency;?><?=number_format($onlineprice,2);?></td>
			</tr>
			<tr>
				<td width="70%">获胜者出价</td>
				<td align="right" style="padding-right: 20px;" width="15%"><?=number_format(($finalprice * $dinarvalue),2);?></td>
				<td width="25%" align="right"><?=$Currency;?><?=number_format($finalprice,2);?></td>
			</tr>
			<tr height="5">
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td width="70%">总支出</td>
				<td align="right" style="padding-right: 20px;" width="15%"><?=number_format(($totalcost * $dinarvalue),2);?></td>
				<td width="25%" align="right"><?=$Currency;?><?=number_format($totalcost,2);?></td>
			</tr>
				<?
				$totalearn = $smsprice  + $onlineprice + $finalprice;
				$comgain = $totalearn - $totalcost;
				if($comgain<0)
				{
					$comgain1 = "<font color='red'>-&euro;".substr(number_format($comgain,2),1)."</font>";
					$comgain2 = "<font color='red'>-&euro;".substr(number_format($comgain * $dinarvalue,2),1)."</font>";
				}
				else
				{
					$comgain1 = "<font color='green'>&euro;".number_format($comgain,2)."</font>";
					$comgain1 = "<font color='green'>&euro;".number_format($comgain * $dinarvalue,2)."</font>";
				}
				?>
			<tr>
				<td width="70%">总收入</td>
				<td align="right" style="padding-right: 20px;" width="15%" nowrap="nowrap"><?=number_format($totalearn * $dinarvalue,2);?></td>
				<td width="25% "align="right" nowrap="nowrap"><?=$Currency;?><?=number_format($totalearn,2);?></td>
			</tr>
			<tr height="5">
				<td>&nbsp;</td>
			</tr>
		</TABLE>
		</TD>
   </TR>
   <TR>
   	<td>
		<table width="62%" cellpadding="0" cellspacing="0" border="0">
		   <TR class=th-a> 
				<td width="70%" align="right" style="padding-right: 20px;">公司收入</td>
				<td align="right" style="padding-right: 20px;" width="15%" nowrap="nowrap"><?=$comgain2;?></td>
				<td align="right" width="25%" nowrap="nowrap"><?=$comgain1;?></td>
		   </TR>
		</table>
	</td>
   </TR>
	<?
		}
	  }
	}
	 ?>
	</TABLE>	 
</body>
</html>
