VitalEnd Posted August 4, 2010 Posted August 4, 2010 Basically i am using a very good auction i found here on MWG which was free. I have recently noticed that when a user outbids someone, the user with the previous bid is not notified and does not get their money back ... I have had a go at fixing this and failed so i would ery much appreciate some help in this bit and just add it in so they get an event saying "You have been outbid on an auction" and give them their money back. The auction file: <?php //Made by zeddicus, do NOT re-distribute. //Copyright 2010 include(DIRNAME(__FILE__).'/globals.php'); $_GET['page'] = isset($_GET['page']) ? trim($_GET['page']) : 'index'; switch($_GET['page']) { case 'index' : index(); break; case 'Bid' : Bid(); break; case 'Add' : Add(); break; default : index(); break; } function index() { global $h; $Data = mysql_query("SELECT g.`ID`,g.`SellerID`,g.`ItemID`,g.`Time`,g.`CurrentBid`,g.`BuyNow`,g.`TimeLeft`,i.`itmid`,i.`itmname` FROM `gAuction` g LEFT JOIN `items` i ON (g.`ItemID` = i.`itmid`)") or die(mysql_error()); echo (' <span style = "font-size:2em; font-family:Arial,Helvetica,sans-serif; color:#8B0000">Auction House</span> <hr width = "90%"> <table border = "0" class = "table" align = "center" width = "90%" style = "text-align:center" cellspacing = "1"> <tr> <th>Seller</th> <th>Item</th> <th>Time Left</th> <th>Current Bid</th> <th>Links</th> </tr>'); if(!mysql_num_rows($Data)) { echo ('<tr> <td colspan = "5">There are no auction being held at the present time.</td> </tr> </table>'); exit($h->endpage()); }else{ while($aData = mysql_fetch_array($Data)) { $time = $aData['Time'] - time() + $aData['TimeLeft']; echo (' <tr> <td>'.$aData['SellerID'].'</td> <td>'.stripslashes(htmlentities($aData['itmname'])).'</td> <td>'.time_format($time).'</td> <td width = "15%">$'.number_format($aData['CurrentBid']).'</td> <td width = "15%" align = "center"><a href = "auction.php?page=Bid&ID='.$aData['ID'].'"><span style = "color:#8B0000">Bid</span></a>|| <a href = "iteminfo.php?ID='.$aData['ItemID'].'"><span style = "color:#8B0000">Info</span></a></td>'); } echo ('</tr> </table> '); } $h->endpage(); } function Bid() { global $h,$ir; echo (' <span style = "font-size:2em; font-family:Arial,Helvetica,sans-serif; color:#8B0000">Bidding on Item</span> <hr width = "90%">'); $Data = mysql_query("SELECT g.`ID`,g.`SellerID`,g.`ItemID`,g.`CurrentBid`,g.`BuyNow`,g.`TimeLeft`,i.`itmid`,i.`itmname` FROM `gAuction` g LEFT JOIN `items` i ON (g.`ItemID` = i.`itmid`) WHERE (g.`ID` = ".abs(intval($_GET['ID'])).")") or die(mysql_error()); if(!mysql_num_rows($Data) || !ctype_digit($_GET['ID'])) { echo ('An error has occurred, please go back and try again.'); exit($h->endpage()); } $Data = mysql_fetch_array($Data); if((isset($_POST['bid']))) { if(!ctype_digit($_POST['bid'])) { echo ('An error has occurred, please try again.'); exit($h->endpage()); } if($_POST['bid'] < $Data['CurrentBid'] || $ir['money'] < $_POST['bid']) { echo ('You\'ve bidded below the current bid, or you don\'t have enough cash to bid. <a href = "/auction.php"><span style = "color:#8B0000">Go Back</span></a>'); exit($h->endpage()); } if($_POST['bid'] >= $Data['BuyNow'] && $Data['BuyNow'] > 0) { mysql_query("DELETE FROM `gAuction` WHERE (`ID` = ".abs(intval($_GET['ID'])).")"); //Auction Delete mysql_query("UPDATE `users` SET `money` = `money` - ".abs(intval($_POST['bid']))." WHERE (`userid` = ".$_SESSION['userid'].")"); //Take cash from user mysql_query("INSERT INTO `inventory` VALUES ('',".$Data['ItemID'].",".$_SESSION['userid'].",1)"); // Credit winner item event_add($Data['SellerID'],''.mysql_real_escape_string($ir['username']).' bought your item of the auction using your "Buy It Now Price" ($'.number_format($Data['BuyNow']).')'); mysql_query("UPDATE `users` SET `money` = `money` + ".abs(intval($_POST['bid']))." WHERE (`userid` = ".$Data['SellerID'].")"); //Give cash to user echo ('You\'ve successfully purchased the item from the Auction using the "Buy It Now" price!. <a href = "/index.php"><span style = "color:#8B0000">Go Home</span></a>'); }else{ mysql_query("UPDATE `gAuction` SET `CurrentBid` = ".abs(intval($_POST['bid']))." WHERE (`ID` = ".abs(intval($_GET['ID'])).")"); // mysql_query("INSERT INTO `gAuctionBids` VALUES ('',".$Data['ID'].",".$_SESSION['userid'].",".abs(intval($_POST['bid'])).")"); //insert bid mysql_query("UPDATE `users` SET `money` = `money` - ".abs(intval($_POST['bid']))." WHERE (`userid` = ".$_SESSION['userid'].")"); //Take cash from user echo ('Your bid has been confirmed. <a href = "/auction.php"><span style = "color:#8B0000">Back to Auction</span></a>'); } } if($Data['BuyNow'] == 0) { $Buy = 'Disabled by user'; }else{ $Buy = number_format($Data['BuyNow']); } if($Data['BuyNow'] == 0) { $Sign = ''; }else{ $Sign = '$'; } echo (' <table class = "table" cellspacing = "1" width = "35%" align = "center" style = "text-align:center"> <form action = "auction.php?page=Bid&ID='.$_GET['ID'].'" method = "post"> <tr> <td width = "25%">Item Name:</td> <td><span style = "color:#8B0000">'.htmlentities($Data['itmname']).'</span></td> </tr> <tr> <td width = "25%">Current Bid:</td> <td>'.number_format($Data['CurrentBid']).'</td> </tr> <tr> <td width = "25%">Buy Now Price:</td> <td>'.$Sign.''.$Buy.'</td> </tr> <tr> <td width = "25%">Enter Bid:</td> <td><input type = "text" name = "bid" value = "0" /></td> </tr> <tr> <td colspan = "2"><input type = "submit" value = "Place Bid" /></td> </tr> </form> </table> <a href = "/auction.php"><span style = "color:#8B0000">Go Back</a>'); $h->endpage(); } function Add() { global $h; $Data = mysql_query("SELECT i.`inv_itemid`,i.`inv_userid`,i.`inv_qty`,it.`itmid`,it.`itmname` FROM `inventory` i LEFT JOIN `items` it ON (i.`inv_itemid` = it.`itmid`) WHERE (`inv_userid` = ".$_SESSION['userid'].") AND (`inv_itemid` = ".abs(intval($_GET['ID'])).")") or die(mysql_error()); if(!mysql_num_rows($Data) || !ctype_digit($_GET['ID'])) { echo ('An error has occurred, please go back and try again.'); exit($h->endpage()); } $Data = mysql_fetch_array($Data); echo (' <span style = "font-size:2em; font-family:Arial,Helvetica,sans-serif; color:#8B0000">Adding Item To Auction</span> <hr width = "90%"> You have <span style = "color:#8B0000">[i]'.number_format($Data['inv_qty']).'[/i]</span> - <span style = "color:#8B0000">[i]'.htmlentities($Data['itmname']).'[/i]</span> <hr width = "90%">'); if((isset($_POST['time']))) { $One = mysql_query("SELECT `ID` FROM `gAuction` WHERE (`SellerID` = ".$_SESSION['userid'].")"); if(mysql_num_rows($One)) { echo ('Only one item at the auction please.'); exit($h->endpage()); } if(!in_array($_POST['time'], array('1Hour','6Hours','1Day','2Days'))) { echo ('An error has occured please go back and try again.'); exit($h->endpage()); } if($Data['inv_qty'] < 1) { echo ('It seems you don\'t have enough of this item to send it to auction.'); exit($h->endpage()); } if($_POST['time'] === '1Hour') { $time = '3600'; } elseif($_POST['time'] === '6Hours') { $time = '21600'; } elseif($_POST['time'] === '1Day') { $time = '86400'; } elseif($_POST['time'] === '2Days') { $time = '172800'; } mysql_query("INSERT INTO `gAuction` VALUES ('',".$_SESSION['userid'].",".$Data['itmid'].",".abs(intval($_POST['sbid'])).",".abs(intval($_POST['buy'])).",".$time.",unix_timestamp())") or die(mysql_error()); if($Data['inv_qty'] > 1) { mysql_query("UPDATE `inventory` SET `inv_qty` = `inv_qty` - 1 WHERE (`inv_userid` = ".$_SESSION['userid'].") AND (`inv_itemid` = ".$Data['itmid'].")") OR DIE(MYSQL_ERROR()); }else{ mysql_query("DELETE FROM `inventory` WHERE (`inv_userid` = ".$_SESSION['userid'].") AND (`inv_itemid` = ".$Data['itmid'].")")OR DIE(MYSQL_ERROR()); } echo ('You\'ve successfully add the item to the auction. <a href = "/auction.php"><span style = "color:#8B0000">Click here to View</span></a>'); }else{ echo (' <table border = "0" class = "table" cellspacing = "1" width = "60%" align = "center" style = "text-align:center"> <form action = "auction.php?page=Add&ID='.$_GET['ID'].'" method = "post"> <tr> <td colspan = "2">Select the amount off time you wish your auction to last.</td> </tr> <tr> <td colspan = "2">1 Hour<input type = "radio" name = "time" value = "1Hour" /> 6 Hours<input type = "radio" name = "time" value = "6Hours" /> 24 Hours<input type = "radio" name = "time" value = "1Day" /> 48 Hours<input type = "radio" name = "time" value = "2Days" /></td> </tr> <tr> <td>Starting Bid</td> <td><input type = "text" name = "sbid" value = "0" /></td> </tr> <tr> <td>Buy It Now Price:</td> <td><input type = "text" name = "buy" value = "0" />(Enter 0 to disable)</td> </tr> <tr> <td colspan = "2"><input type = "submit" value = "Add item to auction" /></td> </tr> </form> </table> <a href = "/inventory.php"><span style = "color:#8B0000">Go Back</span></a>'); } $h->endpage(); } ?> Any help is much appreciated! Thanks Quote
Matthew Posted August 28, 2010 Posted August 28, 2010 (edited) try this auction 1.) this will be auctioncron.php <?php include "config.php"; global $_CONFIG; if($_GET['code'] != $_CONFIG['code']) { die(""); } define("MONO_ON", 1); require "class/class_db_{$_CONFIG['driver']}.php"; $db=new database; $db->configure($_CONFIG['hostname'], $_CONFIG['username'], $_CONFIG['password'], $_CONFIG['database'], $_CONFIG['persistent']); $db->connect(); $c=$db->connection_id; $db->query("UPDATE auctions SET time=time-1 WHERE time > 0"); $qqq=$db->query("SELECT * FROM auctions WHERE time = 0"); while($win=$db->fetch_row($qqq)) { $time=$win['time']; $item=$win['itemname']; $winner=$win['bidder']; $owner=$win['owner']; $iname=$db->query("SELECT itmname FROM items WHERE itmid={$item}"); $winim=$db->fetch_row($iname); if($win['bids'] > 0) { $db->query("INSERT INTO inventory VALUES('',$item,$winner,1)"); $db->query("INSERT INTO events VALUES('', $winner, unix_timestamp(), 0, 'You won the auction of the {$winim['itmname']} for ?{$win['current']}, It has been added to your items.')"); $db->query("UPDATE users SET new_events=new_events+1 WHERE userid={$winner}"); $db->query("INSERT INTO events VALUES('', $owner, unix_timestamp(), 0, 'Your {$winim['itmname']} sold succesfully on the auction market with {$win['bids']} bids! You have been paid ?{$win['current']}')"); $db->query("UPDATE users SET new_events=new_events+1 WHERE userid={$owner}"); $db->query("UPDATE users SET money=money+'{$win['current']}' WHERE userid={$owner}"); } else if($win['bids'] == 0) { $iname=$db->query("SELECT itmname FROM items WHERE itmid={$item}"); $winim=$db->fetch_row($iname); $db->query("INSERT INTO events VALUES('', $owner, unix_timestamp(), 0, 'Your item listing has ended with no bidders. Your {$winim['itmname']} has been returned to your items.')"); $db->query("UPDATE users SET new_events=new_events+1 WHERE userid={$owner}"); $winner=$win['owner']; $db->query("INSERT INTO inventory VALUES('',$item,$winner,1)"); } } $db->query("DELETE FROM auctions WHERE time=0"); ?> 2.) this will be auctionadd.php <?php include "config.php"; global $_CONFIG; if($_GET['code'] != $_CONFIG['code']) { die(""); } define("MONO_ON", 1); require "class/class_db_{$_CONFIG['driver']}.php"; $db=new database; $db->configure($_CONFIG['hostname'], $_CONFIG['username'], $_CONFIG['password'], $_CONFIG['database'], $_CONFIG['persistent']); $db->connect(); $c=$db->connection_id; $db->query("UPDATE auctions SET time=time-1 WHERE time > 0"); $qqq=$db->query("SELECT * FROM auctions WHERE time = 0"); while($win=$db->fetch_row($qqq)) { $time=$win['time']; $item=$win['itemname']; $winner=$win['bidder']; $owner=$win['owner']; $iname=$db->query("SELECT itmname FROM items WHERE itmid={$item}"); $winim=$db->fetch_row($iname); if($win['bids'] > 0) { $db->query("INSERT INTO inventory VALUES('',$item,$winner,1)"); $db->query("INSERT INTO events VALUES('', $winner, unix_timestamp(), 0, 'You won the auction of the {$winim['itmname']} for ?{$win['current']}, It has been added to your items.')"); $db->query("UPDATE users SET new_events=new_events+1 WHERE userid={$winner}"); $db->query("INSERT INTO events VALUES('', $owner, unix_timestamp(), 0, 'Your {$winim['itmname']} sold succesfully on the auction market with {$win['bids']} bids! You have been paid ?{$win['current']}')"); $db->query("UPDATE users SET new_events=new_events+1 WHERE userid={$owner}"); $db->query("UPDATE users SET money=money+'{$win['current']}' WHERE userid={$owner}"); } else if($win['bids'] == 0) { $iname=$db->query("SELECT itmname FROM items WHERE itmid={$item}"); $winim=$db->fetch_row($iname); $db->query("INSERT INTO events VALUES('', $owner, unix_timestamp(), 0, 'Your item listing has ended with no bidders. Your {$winim['itmname']} has been returned to your items.')"); $db->query("UPDATE users SET new_events=new_events+1 WHERE userid={$owner}"); $winner=$win['owner']; $db->query("INSERT INTO inventory VALUES('',$item,$winner,1)"); } } $db->query("DELETE FROM auctions WHERE time=0"); ?> 3.) this will be auctions.php <?php include "globals.php"; print "<h3>Auction House</h3> <table width='80%' border='1'><tr><th>Owner</th><th>Item</th><th>High Bid</th><th>High Bidder</th><th>Time Left</th><th>Min. Next Bid</th><th>Bids</th><th>Functions</th></tr>"; $ma=mysql_query("select * from auctions order by time asc",$c); while($my=mysql_fetch_array($ma)) { $person=mysql_query("select u.*,a.* from users u left join auctions a on a.bidder=u.userid WHERE aid={$my['aid']}",$c); $him=mysql_fetch_array($person); $owner=mysql_query("select u.*,a.* from users u left join auctions a on a.owner=u.userid WHERE aid={$my['aid']}",$c); $o=mysql_fetch_array($owner); $item=mysql_query("SELECT a.*,i.* FROM auctions a LEFT JOIN items i ON a.itemname=i.itmid WHERE aid={$my['aid']}",$c); $ie=mysql_fetch_array($item); $high=$him['username']; $aid=$my['aid']; $own=$o['username']; $item=$ie['itmname']; $startprice=$my['start']; $currentprice=$my['current']; $time=$my['time']; $bids=$my['bids']; $increase=$my['increase']+$my['current']; $t4=floor($time/60/24); $t1=floor($time/60) % 24; $t2=$time % 60; if($t2 < 10) { $t3="0".$t2; } else { $t3=$t2; } if($t4) { $t5="$t4 days, "; } else { $t5=""; } print" <tr><td>$own</td><td>$item</td><td>[b]\$$currentprice[/b]</td><td>$high</td><td>$t5$t1:$t2</td><td>\$$increase</td><td>$bids</td><td>[url="bid.php?aid=$aid>[bid]"]<a href=iteminfo.php?ID=$ie[itmid]>[info][/url]</td></tr>"; } print"</table>"; $h->endpage(); ?> 4.)Make a cron for your game called curl http://(gamename.com)/cron_weekly.php?code=(CODE) run it for the minute 5.)[mysql]Table structure for table `auctions` -- CREATE TABLE IF NOT EXISTS `auctions` ( `aid` int(11) NOT NULL auto_increment, `owner` int(11) NOT NULL default '0', `itemname` int(11) NOT NULL default '0', `start` bigint(25) NOT NULL default '0', `current` bigint(25) NOT NULL default '0', `time` int(11) NOT NULL default '0', `bids` int(11) NOT NULL default '0', `bidder` int(11) NOT NULL default '0', `increase` int(11) NOT NULL default '0', `lastbidder` int(11) NOT NULL default '0', `lastbid` bigint(25) NOT NULL default '0', PRIMARY KEY (`aid`) ) [/mysql] 6.) add this to inventory.php next to sell addtomarket info all that those will look like this [[url='auctionadd.php?ID={$i[']Add To Auction[/url]] when you see the rest that look like that but saying add to market and such and info add that next to them and you can add the items to auction from your inventory. That should do it (I did NOT make this auction i will not take credit for this mod..BUT all the files i do have are secured so i got this un secure it is secure now...) If i missed something tell me. I have the file but i just probally didn't get to it Edited April 6, 2011 by Dominion Quote
Artemis Posted April 6, 2011 Posted April 6, 2011 [quote=Matthew;238028 5.)[mysql]Table structure for table `auctions` -- CREATE TABLE IF NOT EXISTS `auctions` ( `aid` int(11) NOT NULL auto_increment, `owner` int(11) NOT NULL default '0', `itemname` int(11) NOT NULL default '0', `start` bigint(25) NOT NULL default '0', `current` bigint(25) NOT NULL default '0', `time` int(11) NOT NULL default '0', `bids` int(11) NOT NULL default '0', `bidder` int(11) NOT NULL default '0', `increase` int(11) NOT NULL default '0', `lastbidder` int(11) NOT NULL default '0', `lastbid` bigint(25) NOT NULL default '0', PRIMARY KEY (`aid`) )[/mysql] could be the change in server for the forums but the )[/mysql] at the end of the table structure could confuse newer coders as im sure a few will try and copy and paste this code into their database.. Quote
lucky3809 Posted April 6, 2011 Posted April 6, 2011 (edited) [/mysql] is showing because the new forum, I already had directed the error...It is in all php bccode areas and other bccode area such as [mysql][/mysql]. Edited April 6, 2011 by lucky3809 Quote
a_bertrand Posted April 6, 2011 Posted April 6, 2011 we can add mysql tag if needed. so far use the code tag. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.