Esempio n. 1
0
     $stmt->bindValue(1, $workOffered);
     $stmt->execute();
     // Cancel any other trades or auctions involving this work.
     clearWorkFromOtherTransactions($workOffered);
 }
 foreach ($worksRequested as $workRequested) {
     // Remove requested work from destination's table
     $stmt = $dbh->prepare("DELETE FROM " . $destTable . " WHERE work = ?");
     $stmt->bindValue(1, $workRequested);
     $stmt->execute();
     // Add requested work to origin's table.
     $stmt = $dbh->prepare("INSERT INTO " . $originTable . " VALUES( ? )");
     $stmt->bindValue(1, $workRequested);
     $stmt->execute();
     // Cancel any other trades or auctions involving this work.
     clearWorkFromOtherTransactions($workRequested);
 }
 // Create a global announcement that this trade has been accepted (or rejected)
 $headline = getUsername($destination) . " accepted " . getUsername($origin) . "'s trade proposal";
 $stmt = $dbh->prepare("UPDATE events SET type = ?, headline = ? WHERE xref = ? AND type = ?");
 $stmt->bindValue(1, $E_TRADE_ACCEPTED);
 $stmt->bindValue(2, $headline);
 $stmt->bindValue(3, $tid);
 $stmt->bindValue(4, $E_TRADE_PROPOSED);
 $stmt->execute();
 createNotification($origin, $E_TRADE_ACCEPTED, getUsername($destination) . " accepted your trade proposal.");
 // If there was a message associated with the rejection, notify the recipient.
 if ($tradeMessage != "") {
     $substmt = $dbh->prepare("INSERT INTO msgs(uidf,uidt,gid,string,rr) VALUES( ?, ?, ?, ?, ? )");
     $substmt->bindParam(1, $uuid);
     $substmt->bindParam(2, $origin);
Esempio n. 2
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);
    }
}