Beispiel #1
0
/**
 * placeBidFixedEnd: Enter a bid at auction.  Parameters are checked before being passed (in marketplace.php).
 * This function is used in the current auction system; placeBid() is the corresponding function for the live/
 * rapid auction system, which may be re-implemented in future releases.
 *
 * @param auc The auction id.
 * @param user The user id of the bidder.
 * @param amt The amount of this bid.
 * @param gi The game instance
 */
function placeBidFixedEnd($auc, $user, $amt, $gi)
{
    global $dbh;
    $utable = $user . "_" . $gi . "_coll";
    // :(
    // insert the bid data into the bids table
    $query = $dbh->prepare("INSERT INTO bids(uid, aid, amt) VALUES(?,?,?)");
    $query->bindParam(1, $user);
    $query->bindParam(2, $auc);
    $query->bindParam(3, $amt);
    $query->execute();
    // Drop these events because they're now obsolete (there's a new high bid)
    $query = $dbh->prepare("DROP EVENT IF EXISTS auctionEnd" . $auc);
    $query->execute();
    $query = $dbh->prepare("DROP EVENT IF EXISTS notifyWinner" . $auc);
    $query->execute();
    $query = $dbh->prepare("DROP EVENT IF EXISTS notifySeller" . $auc);
    $query->execute();
    $wid = "";
    $reserve = 0;
    $selleruid = 0;
    // Find out the user, work id, and reserve amount of this auction
    $w = $dbh->prepare("SELECT uid,wid,reserve FROM auctions WHERE id=?");
    $w->bindParam(1, $auc);
    $w->execute();
    while ($row = $w->fetch()) {
        $wid = $row['wid'];
        $selleruid = $row['uid'];
        $reserve = $row['reserve'];
    }
    $sellertable = $selleruid . "_" . $gi . "_coll";
    if ($amt < $reserve) {
        // Scheduled event that specifies no winner @ auction end.
        $z = $dbh->prepare("CREATE EVENT auctionEnd" . $auc . " ON SCHEDULE AT '" . getAuctionEnd($auc) . "' DO BEGIN UPDATE auctions SET pending=0,winner=-1,highbid=?,end=NOW() WHERE id=?;SELECT uid,wid,highbid INTO @uid,@wid,@high FROM auctions WHERE id=?; END");
        $z->bindParam(1, $amt);
        $z->bindParam(2, $auc);
        $z->bindParam(3, $auc);
        $z->execute();
        // Event that notifies seller of the failure to meet reserve...
        $ye = $dbh->prepare("CREATE EVENT notifySeller" . $auc . " ON SCHEDULE AT '" . getAuctionEnd($auc) . "' DO BEGIN SELECT uid INTO @uid FROM auctions WHERE id = ?; INSERT INTO notifications(type,text,target) VALUES(10,'Your work failed to sell at auction!  It has been returned to your collection.',@uid); END");
        $ye->bindParam(1, $auc);
        $ye->execute();
        // And the event that notifies the would-be winner of the same.
        $ze = $dbh->prepare("CREATE EVENT notifyWinner" . $auc . " ON SCHEDULE AT '" . getAuctionEnd($auc) . "' DO BEGIN INSERT INTO notifications(type,text,target) VALUES(10, 'Your high bid failed to meet the reserve price!', " . $user . "); END");
        $ze->execute();
    } else {
        // Successful sale.
        $z = $dbh->prepare("CREATE EVENT auctionEnd" . $auc . " ON SCHEDULE AT '" . getAuctionEnd($auc) . "' DO BEGIN UPDATE auctions SET pending=0,winner=?,highbid=? WHERE id=?;SELECT winner,uid,wid,highbid INTO @winner,@uid,@wid,@high FROM auctions WHERE id=?;INSERT INTO " . $utable . " VALUES(@wid);DELETE FROM " . $sellertable . " WHERE work = @wid;UPDATE collectors SET points = (points - @high) WHERE id=@winner;UPDATE collectors SET points = ( points + FLOOR(@high * .9) ) WHERE id=@uid; END");
        $z->bindParam(1, $user);
        $z->bindParam(2, $amt);
        $z->bindParam(3, $auc);
        $z->bindParam(4, $auc);
        $z->execute();
        $ye = $dbh->prepare("CREATE EVENT notifySeller" . $auc . " ON SCHEDULE AT '" . getAuctionEnd($auc) . "' DO BEGIN SELECT uid INTO @uid FROM auctions WHERE id = ?; INSERT INTO notifications(type,text,target) VALUES(9,'Your work sold at auction!',@uid); END");
        $ye->bindParam(1, $auc);
        $ye->execute();
        $ze = $dbh->prepare("CREATE EVENT notifyWinner" . $auc . " ON SCHEDULE AT '" . getAuctionEnd($auc) . "' DO BEGIN INSERT INTO notifications(type,text,target) VALUES(9, 'Your high bid met the reserve price.  You won an auction!', " . $user . "); END");
        $ze->execute();
        // Remove work from any other pending transactions.
        clearWorkFromOtherTransactions($wid);
    }
}
Beispiel #2
0
		<button id="deleteListing">Cancel Selected Auction</button>
		<p/>
		<form id="dummy">
		<?php 
// Get a list of auctions owned by this player; print them out alongside a radio button
// that allows users to select an auction for deletion.  the deleteListing button is managed
// in (document).ready().
$stmt = $dbh->prepare("SELECT * FROM auctions WHERE UNIX_TIMESTAMP(end) > UNIX_TIMESTAMP(NOW()) AND uid = ?");
$stmt->bindParam(1, $uuid);
$stmt->execute();
if ($stmt->rowCount() == 0) {
    echo "<div style=\"display:inline-block;clear:both;margin-left:20px;font-size:18pt;\">You have no auctions.</div>\n";
}
while ($row = $stmt->fetch()) {
    echo "<div style=\"background-color:lightgray;width:100%;height:150px;padding-bottom:2px;\">\n";
    echo "<input type=\"radio\" name=\"radio\" value=\"" . $row['id'] . "\" style=\"vertical-align:middle;width:40px;position:relative;left:10px;\"><img src=\"img.php?img=" . $row['wid'] . "\" style=\"height:150px;position:relative;left:0px;display:inline-block;vertical-align:middle;\"/> <div style=\"display:inline-block;width:70%;\">Current bid: " . $CURRENCY_SYMBOL . getHighBidAmountForAuction($row['id']) . " (" . getHighBidderForAuction($row['id']) . ")<br/>Reserve: " . $CURRENCY_SYMBOL . getReserve($row['id']) . "<br/>Ends: " . getAuctionEnd($row['id']) . " </div>";
    echo "</div>\n";
}
?>
		</form>
	</div>

	<div id="auctions"> 

	<?php 
// Here's where we list all the active auctions and allow players to bid on them.
// Select list of active auctions...
$stmt = $dbh->prepare("SELECT * FROM auctions WHERE UNIX_TIMESTAMP(end) > UNIX_TIMESTAMP(NOW()) ORDER BY end ASC");
$stmt->execute();
while ($row = $stmt->fetch()) {
    // ..and for each one, display a form with the work image, a link to workview,php, the work tombstone,