<?
	include("config/connect.php");
	include("functions.php");
	
	function uploadimage($i)
{
	$time = time();
	$imagename = $time."_".$_FILES["image".$i]["name"];
	$dest = "uploads/show/";
	copy($_FILES['image'.$i]['tmp_name'],"uploads/show/".$imagename);
}
	
	
	if($_POST["add"]!="")
	{   
		$aid= $_REQUEST["aid"];
		$wid= $_REQUEST["wid"];
	    $qry = "select *  from  auction where auctionID=$aid";
	    $res = mysql_query($qry);
	   $obj2 = mysql_fetch_object($res);

	    $qryu = "select *  from  registration  where id=".$_SESSION["userid"];
	    $resu = mysql_query($qryu);
	//$total = mysql_num_rows($ressel);
	   $obju = mysql_fetch_object($resu);


		$qryins = "insert into auc_show (username,headering,title,detail,spread_price,end_time,addtime,bid_id,member_id,money) values('".$obju->username."','".$obju->header."','". $_POST["title"]."','".addslashes($_POST["description1"])."',".$obj2->auc_final_price.",".$obj2->auc_final_end_date.",".time().",$aid,".$_SESSION["userid"].",".$obj2->showpoint.")";
		mysql_query($qryins) or die(mysql_error());
		$show_id=mysql_insert_id ();

		$qryw = "update won_auctions  set show_flag=1 where id=".$wid;
		mysql_query($qryw) or die(mysql_error());

		for($i=1;$i<=4;$i++)
				{
				   uploadimage($i);
				   $imagenameb = "uploads/show/".time()."_".$_FILES["image".$i]["name"];
			if($_FILES["image".$i]["name"]!="")
			 {
			$qryupd = "insert into show_photo(detail_img,show_id) values ('".$imagenameb."',$show_id)";	
			mysql_query($qryupd) or die(mysql_error());
			}
		}


		echo "<script language='javascript'>window.parent.location.replace('index.php');</script>";
		
	}
    $wid  = $_REQUEST["sid"];
	$user = $_SESSION["userid"];
	
	$qrysel = "select *  from won_auctions w left join auction a on w.auction_id=a.auctionID  left join products p on a.productID=p.productID where w.id=$wid and w.show_flag=0";
	$ressel = mysql_query($qrysel);
	//$total = mysql_num_rows($ressel);
	$obj = mysql_fetch_object($ressel);
	if($obj->userid!=$user)
	{
	 echo "<script language='javascript'>window.parent.location.replace('index.php');</script>";
	}
?>

<!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>
<title>申请晒单，获得奖励</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link href="css/dedecms.css" rel="stylesheet" media="screen" type="text/css" />
<link href="css/table.css" rel="stylesheet" media="screen" type="text/css" />
<link href="css/page.css" rel="stylesheet" media="screen" type="text/css" />
<script language="javascript" type="text/javascript" src="siteadmin/editor/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript" src="siteadmin/editor.js"></script>
</head>
<body class="buycarpage">
<?
	include("d1.php");
?>

<div class="w960 clear center mt1 cmt-box">
	<div class="buycar">
		<form name="f1"  enctype="multipart/form-data"  action="apply_show.php" method="post">
        
        <table cellpadding="0" cellspacing="0" class="flow">
			<tr>
				<td class="thisclass">申请晒单</td>
				<td>等待审核</td>
				<td>晒单成功获得奖励 </td>
			</tr>
		</table>
		<table width="100%" border="1" cellpadding="0" cellspacing="0" class="dede_table">
			<thead>
				<tr>
					<td colspan=2>项目详情</td>

				</tr>
			</thead>
			<tbody>
				<tr>
					<td  class="td1">项目：</td>
					<td><?=$obj->name;?></td>
				</tr>
				<tr>
					<td class="td1">成交价格：</td>
					<td><?=$obj->auc_final_price;?></td>
				</tr>
				<tr>
					<td  class="td1">市场价：</td>
					<td><?=$obj->price;?></td>
				</tr>
				<tr>
					<td class="td1">折扣：</td>
					<td><?=($obj->price-$obj->auc_final_price)/$obj->price;?></td>
				</tr>
				<tr>
					<td class="td1">结束时间：</td>
					<td><?=date("Y-m-d H:i:s",$obj->auc_final_end_date);?></td>
				</tr>
				
			</tbody>
		</table>
        
        
		<table width="100%" border="1" cellpadding="0" cellspacing="0" class="dede_table">
			<thead>
				<tr>
					<td colspan="2">填写详细申请表</td>
				</tr>
			</thead>            
			<tbody>
				<tr>
					<td >标题 :</td>
					<td  align=left> <input name="title" id="title" type="text" class="ipt-txt" size="50" /> </td>
				</tr>
				<tr>
					<td >内容 :</td>
					<td align=left><textarea rows="20" cols="75" id="description1" name="description1"></textarea></td>
				</tr>
				<tr>
				<td class="f-c"  align="right">图片 :</td>
				<td  align=left>
				<table>
					<tr>
					<td><input name="image1" type="file" class="solidinput"  value="<? echo $image;?>" size="35">
					</td>
					</tr>
					<tr>
					<td ><input name="image2" type="file" class="solidinput"  value="<? echo $image;?>" size="35">
					</td>
					</tr>
					<tr>
					<td ><input name="image3" type="file" class="solidinput"  value="<? echo $image;?>" size="35">
					</td>
					</tr>
					<tr>
					<td ><input name="image4" type="file" class="solidinput"  value="<? echo $image;?>" size="35">
					</td>
					</tr>
					<tr>
					<td class="a">(推荐图片尺寸: 350 &times; 275 像素)</td>
					</tr>
				</table>
				</td>
			</tr>
			</tbody>
		</table>
        
        			
		<table width="100%" border="0" cellpadding="0" cellspacing="0" class="dede_table">
			<tfoot>
				<tr>
					<td colspan="2">
					<INPUT type="hidden" value="<?=$obj->auctionID;?>" name="aid">
					<INPUT type="hidden" value="<?=$obj->id;?>" name="wid">
					<INPUT type="submit" value="申请" name="add" class="bttn">
					</td>
				</tr>
			</tfoot>
		</table>		
		</form>
	</div>
	
</div>




</body>
</html>
