$auction_lang[auction]";
$navtitle=$auction_lang[auction].' - ';
if(!$action){
$action='home';
$per=$auc_vars['perpage'] && $list ? $auc_vars['perpage'] : 60;
$races=$onces=array();
$page = $list ? max(1, intval($page)) : 1;
$start_limit = ($page - 1) * $per;
if($ob=='my'){
$sql=" and a.uid='$discuz_uid'";
}
if($list!='race'){
if($list){
$navigation.=" » $auction_lang[once_goods]";
$count=$db->result($db->query("select count(*) from {$tablepre}auctions a where gmode='1' $sql"),0);
$multipage=multi($count, $per, $page, "auction.php?list=$list");
$query=$db->query("select a.aid,a.goods,a.img,a.amount,a.price,a.mode,a.numbers,a.uid,a.extcredit,a.flag,a.closed,a.term,m.username,m.extcredits{$auc_vars[honor]} as honor,a.flag,a.closed from {$tablepre}auctions a left join {$tablepre}members m on m.uid=a.uid where a.gmode='1' $sql order by a.closed asc,a.aid desc limit $start_limit,$per");
}else{
$query=$db->query("select a.aid,a.goods,a.img,a.amount,a.price,a.mode,a.numbers,a.uid,a.extcredit,a.flag,a.term,m.username,m.extcredits{$auc_vars[honor]} as honor,a.flag from {$tablepre}auctions a left join {$tablepre}members m on m.uid=a.uid where a.gmode='1' and a.closed='0' $sql order by a.aid desc limit $per");
}
while($row=$db->fetch_array($query)){
$row['term']=gmdate("$dateformat $timeformat",$row['term']+$timeoffset*3600);
$row['flag']=$row['numbers']-$row['flag'];
$row['mode']=$row['mode'] ? $auction_lang['out_send'] : $auction_lang['auto_send'];
$onces[]=$row;
}
}
if($list!='once'){
if($list){
$navigation.=" » $auction_lang[race_goods]";
$count=$db->result($db->query("select count(*) from {$tablepre}auctions where gmode='0'"),0);
$multipage=multi($count, $per, $page, "auction.php?list=$list");
$query=$db->query("select a.aid,a.goods,a.price,a.mode,a.numbers,a.uid,a.extcredit,a.flag,a.term,a.closed,m.username,m.extcredits{$auc_vars[honor]} as honor,a.flag,a.closed from {$tablepre}auctions a left join {$tablepre}members m on m.uid=a.uid where a.gmode='0' $sql order by a.closed asc,a.aid desc limit $start_limit,$per");
}else{
$query=$db->query("select a.aid,a.goods,a.price,a.mode,a.numbers,a.uid,a.extcredit,a.flag,a.term,m.username,m.extcredits{$auc_vars[honor]} as honor,a.flag from {$tablepre}auctions a left join {$tablepre}members m on m.uid=a.uid where a.gmode='0' and a.closed='0' $sql order by a.aid desc limit $per");
}
while($row=$db->fetch_array($query)){
$row['term']=gmdate("$dateformat $timeformat",$row['term']+$timeoffset*3600);
$row['mode']=$row['mode'] ? $auction_lang['out_send'] : $auction_lang['auto_send'];
$races[]=$row;
}
}
}elseif($action=='public' && $discuz_uid){
$navigation.=" » $auction_lang[public]";
if(submitcheck("publicsubmit")){
$newname=trim($newname);
if(empty($newname))showmessage($auction_lang['namenull']);
$newimg=trim($newimg);
if(empty($newimg))showmessage("請填入物品圖像連結,這樣買家就更容易找上你。-- 請回上一頁");
$newprice=intval($newprice);
if(!$newprice)showmessage($auction_lang['priceerror']);
$newterm=intval($newterm);
if($newterm > $auc_vars['term'] || $newterm < 1)showmessage($auction_lang['termerror']);
$newterm=$timestamp+$newterm*3600*24;
$newamount=trim($newamount);
if($newamount < 1)showmessage("出售數量錯誤。-- 請回上一頁");
$newgmode=trim($newgmode);
if($newgmode < 1)showmessage("忘記確認?-- 請回上一頁");
/*if($newgmode){
$newnumber=intval($newnumber);
$newflag=0;
if(!$newmode){
$newmsg=explode("\n",trim($newmsg0));
if($newnumber != count($newmsg) || empty($newmsg)) showmessage($auction_lang['numbererror']);
$newmsg=addslashes(serialize($newmsg));
}else{
$newmsg=trim($newmsg1);
if($newmsg=='') showmessage($auction_lang['msgnull']);
}
}else{
$newmsg=trim(${'newmsg'.$newmode});
$newnumber=1;
$newflag=$newprice;
if($newmsg=='') showmessage($auction_lang['msgnoten']);
}*/
$db->query("insert into {$tablepre}auctions (goods,img,amount,price,extcredit,uid,mode,numbers,term,message,gmode,dateline,flag) values ('$newname','$newimg','$newamount','$newprice','$newcredit','$discuz_uid','$newmode','$newnumber','$newterm','$newmsg','$newgmode','$timestamp','$newflag')");
$aid=$db->insert_id();
if(!$newgmode)$db->query("insert into {$tablepre}auctionlog (selleruid,aid,msg) values ('$discuz_uid','$aid','$newmsg')");
showmessage($auction_lang['public_success'],"auction.php?action=view&aid=$aid");
}
}elseif($action == 'delbm'){
$query = $db->query("DELETE FROM {$tablepre}auctions WHERE aid=$aid");
showmessage('成功刪除!', 'auction.php');
}elseif($action=='view' && $aid){
$query=$db->query("select a.*,m.username,m.extcredits{$auc_vars[honor]} as honor from {$tablepre}auctions a left join {$tablepre}members m on m.uid=a.uid where a.aid='$aid' limit 1");
if($row=$db->fetch_array($query)){
$row['term']=gmdate("$dateformat $timeformat",$row['term']+$timeoffset*3600);
$row['dateline']=gmdate("$dateformat $timeformat",$row['dateline']+$timeoffset*3600);
$row['mode']=$row['mode'] ? $auction_lang['out_send'] : $auction_lang['auto_send'];
$row['flag']=$row['gmode'] ? $row['numbers']-$row['flag'] : $row['flag'];
$row['logs']=empty($row['logs']) ? array() : array_reverse(unserialize(stripslashes($row['logs'])));
if($discuz_uid==$row['uid'] && $row['mode']){
foreach($row['logs'] as $key => $val){
$val['m']=explode(":",$val['m']);
$val['m']=$auction_lang['card'].$val['m'][0].' '.$auction_lang['psw'].$val['m'][1];
$row['logs'][$key]=$val;
}
}
$row['rates']=array();
$query=$db->query("select count(*) as rates ,rate from {$tablepre}auctionlog where selleruid=$row[uid] and stat=2 group by rate order by rate desc");
while($rate=$db->fetch_array($query)){
$row['rates'][$rate[rate]]=$rate[rates];
}
$row['rates'][-1]=$row['rates'][-1] ? $row['rates'][-1] : 0;
$row['rates'][0]=$row['rates'][0] ? $row['rates'][0] : 0;
$row['rates'][1]=$row['rates'][1] ? $row['rates'][1] : 0;
}else showmessage('undefined_action');
$balance=${'extcredits'.$row[extcredit]};
$canbuy=$balance >=$row['price'] ? $auction_lang['canbuy'] : $auction_lang['cannotbuy'];
$navigation.= " » " . ($row['gmode'] ? "$auction_lang[once_goods]" : "$auction_lang[race_goods]");
}elseif($action=='buy' && $aid && $discuz_uid && submitcheck('buysubmit')){
$query=$db->query("select * from {$tablepre}auctions where aid='$aid' and closed=0 limit 1");
if(!$row=$db->fetch_array($query)) showmessage($auction_lang['goods_null']);
if($row['uid']==$discuz_uid) showmessage($auction_lang['goods_self']);
if($row['gmode']){
if(${'extcredits'.$row[credit]}>=$row['price']){
$db->query("update {$tablepre}members set extcredits{$row[extcredit]}=extcredits{$row[extcredit]}-$row[price] where uid='$discuz_uid' limit 1");
$temp=unserialize(stripslashes($row['message']));
$row['logs']=empty($row['logs']) ? array() : unserialize(stripslashes($row['logs']));
$buygoods=$row['mode'] ? $row['message'] : $temp[$row['flag']];
$row['flag']++;
$row['closed']=$row['flag']==$row['numbers'] ? 1 : 0;
$row['logs']= addslashes(serialize(array_merge($row['logs'],array(0 => array('u' => $discuz_user,'t' => $timestamp,'m' => $buygoods)))));
$db->query("insert into {$tablepre}auctionlog (selleruid,aid,msg,dateline,buyuid) values ('$row[uid]','$aid','$buygoods','$timestamp','$discuz_uid')");
$db->query("update {$tablepre}auctions set closed='$row[closed]',flag='$row[flag]',logs='$row[logs]' where aid=$aid");
showmessage($auction_lang['buy_success'],"auction.php?action=my");
} else showmessage($auction_lang['notenough']);
}else {
if(${'extcredits'.$row[credit]}>= $myprice && $row['flag'] < $myprice){
$db->query("update {$tablepre}members set extcredits{$row[extcredit]}=extcredits{$row[extcredit]}-$myprice where uid='$discuz_uid' limit 1");
$temp=unserialize(stripslashes($row['message']));
$row['logs']=empty($row['logs']) ? array() : unserialize(stripslashes($row['logs']));
if(!empty($row['logs'])){
$old=array_slice($row['logs'],-1,1);
$db->query("update {$tablepre}members set extcredits{$row[extcredit]}=extcredits{$row[extcredit]}+$old[p] where uid='$old[i]' limit 1");
}
$row['logs']= addslashes(serialize(array_merge($row['logs'],array(0 => array('u' => $discuz_user,'t' => $timestamp,'p' => $myprice,'i' => $discuz_uid)))));
$db->query("update {$tablepre}auctionlog set buyuid='$discuz_uid',dateline='$timestamp' where aid='$aid'");
$db->query("update {$tablepre}auctions set flag='$myprice',logs='$row[logs]' where aid=$aid");
showmessage($auction_lang['race_success'],"auction.php?action=view&aid=$aid");
} else showmessage($auction_lang['notenough']);
}
}elseif($action=='my' && $discuz_uid){
$per=$auc_vars['perpage'];
$page = max(1, intval($page));
$start_limit = ($page - 1) * $per;
$goods=array();
$navigation.=" » $auction_lang[my_buy]";
$count=$db->result($db->query("select count(*) from {$tablepre}auctionlog al left join {$tablepre}auctions a on a.aid=al.aid where al.buyuid='$discuz_uid' and (a.gmode=1 || a.closed=1)"),0);
$multipage=multi($count, $per, $page, "auction.php?action=my");
$query=$db->query("select al.*,a.goods,a.price,a.extcredit,a.mode,a.gmode,a.closed,a.flag,m.username,m.extcredits{$auc_vars[honor]} as honor from {$tablepre}auctionlog al left join {$tablepre}auctions a on a.aid=al.aid left join {$tablepre}members m on a.uid=m.uid where al.buyuid='$discuz_uid' and (a.gmode=1 || a.closed=1) order by al.lid desc limit $start_limit,$per");
while($row=$db->fetch_array($query)){
$row['dateline']=gmdate("$dateformat $timeformat",$row['dateline']+$timeoffset*3600);
$row['flag']=$row['numbers']-$row['flag'];
$row['rate']=$row['rate']==0 ? "$auction_lang[normal]" : ($row['rate']==1 ? "$auction_lang[good]" : $auction_lang['bad']);
$row['rateterm']=gmdate("$dateformat $timeformat",$row['rateterm']+$timeoffset*3600);
if($row['mode']) {
$row['msg']= nl2br($row['msg']);
}else {
$row['msg']=explode(':',$row['msg']);
$row['msg']=$auction_lang['card'].$row['msg'][0].' '.$auction_lang['psw'].$row['msg'][1];
}
$row['mode']=$row['mode'] ? $auction_lang['out_send'] : $auction_lang['auto_send'];
$goods[]=$row;
}
}elseif($action=='draw' && $discuz_uid && $lid){
$query=$db->query("select al.*,a.mode,a.gmode,a.goods,m.extcredits{$auc_vars[honor]} as honor,a.extcredit,a.price,a.flag from {$tablepre}auctionlog al left join {$tablepre}auctions a on a.aid=al.aid left join {$tablepre}members m on a.uid=m.uid where al.buyuid='$discuz_uid' and (a.gmode=1 || a.closed=1) and al.lid='$lid' and al.stat=0 limit 1");
if(!$draw=$db->fetch_array($query))showmessage('undefined_action');
$auc_vars['rate']=explode("\n",trim($auc_vars['rate']));
foreach($auc_vars['rate'] as $key => $val){
$val=explode(":",trim($val));
$ratedays=$val[0];
if($draw['honor']>=$val[1]){
break;
}
}
$rateterm=$timestamp+$ratedays*24*3600;
$db->query("update {$tablepre}auctionlog set stat=1 , rateterm='$rateterm' where lid='$lid'");
$db->query("update {$tablepre}members set extcredits{$draw[extcredit]}=extcredits{$draw[extcredit]}+".($draw['gmode'] ? $draw['price'] : $draw['flag'])." where uid='$draw[selleruid]'");
if(!$draw['mode']) {
$draw['msg']=explode(":",$draw['msg']);
$draw['msg']=$auction_lang['card'].$draw['msg'][0].' '.$auction_lang['psw'].$draw['msg'][1];
$draw['mode']=$auction_lang['auto_send'];
}else{
$draw['mode']=$auction_lang['out_send'];
$draw['msg']=nl2br($draw['msg']);
}
$auction_lang['drawgoods']=str_replace(array('{mode}','{goods}','{msg}','{term}'),array($draw['mode'],$draw['goods'],$draw['msg'],$ratedays),$auction_lang['drawgoods']);
showmessage($auction_lang['drawgoods']);
}elseif($action=='rate' && $discuz_uid && $lid && isset($rate)){
$query=$db->query("select al.selleruid from {$tablepre}auctionlog al left join {$tablepre}auctions a on a.aid=al.aid where buyuid='$discuz_uid' and (a.gmode=1 || a.closed=1) and al.lid='$lid' and al.stat=1 limit 1");
if(!$draw=$db->fetch_array($query))showmessage('undefined_action');
$db->query("update {$tablepre}auctionlog set rate='$rate' ,stat=2 where lid='$lid'");
$honor=$db->result($db->query("SELECT sum(rate) from {$tablepre}auctionlog where selleruid='$draw[selleruid]'"),0);
$db->query("update {$tablepre}members set extcredits{$auc_vars[honor]}='$honor' where uid='$draw[selleruid]'");
showmessage($auction_lang['ratesuccess'],"auction.php?action=my");
}else showmessage('undefined_action');
include template("auction");
?>