");
exit();
}
}
$password = $HTTP_POST_VARS['password'];
if ($password == null)
{
$password = $HTTP_GET_VARS['password'];
if ($password == null)
{
printError($scriptName, $startTime, "PutBid", "You must provide a password!
");
exit();
}
}
$itemId = $HTTP_POST_VARS['itemId'];
if ($itemId == null)
{
$itemId = $HTTP_GET_VARS['itemId'];
if ($itemId == null)
{
printError($scriptName, $startTime, "PutBid", "You must provide an item identifier!
");
exit();
}
}
getDatabaseLink($link);
beginRO($link);
// Authenticate the user
$userId = authenticate($nickname, $password, $link);
if ($userId == -1)
{
printError($scriptName, $startTime, "Authentication", "You don't have an account on RUBiS!
You have to register first.
\n");
exit();
}
function putbid($link, $itemId) {
$row = getItem($link, $itemId);
if (!$row)
{
global $scriptName, $startTime;
printError($scriptName, $startTime, "PutBid", "Sorry, but this item does not exist.
");
exit();
}
txcache_invaltag("bids", "item_id", $row["id"]);
$maxBidResult = sql_query("SELECT MAX(bid) AS bid FROM bids WHERE item_id=".$row["id"], $link) or die("ERROR: Max bid query failed");
$maxBidRow = sql_fetch_array($maxBidResult);
$maxBid = $maxBidRow["bid"];
if ($maxBid == 0)
{
$maxBid = $row["initial_price"];
$buyNow = $row["buy_now"];
$firstBid = "none";
}
else
{
if ($row["quantity"] > 1)
{
$xRes = sql_query("SELECT bid,qty FROM bids WHERE item_id=".$row["id"]." ORDER BY bid DESC LIMIT ".$row["quantity"], $link) or die("ERROR: Quantity query failed");
$nb = 0;
while ($xRow = sql_fetch_array($xRes))
{
$nb = $nb + $xRow["qty"];
if ($nb > $row["quantity"])
{
$maxBid = $row["bid"];
break;
}
}
}
$firstBid = $maxBid;
$nbOfBidsResult = sql_query("SELECT COUNT(*) AS bid FROM bids WHERE item_id=".$row["id"], $link) or die("ERROR: Nb of bids query failed");
$nbOfBidsRow = sql_fetch_array($nbOfBidsResult);
$nbOfBids = $nbOfBidsRow["bid"];
sql_free_result($nbOfBidsResult);
}
printHTMLheader("RUBiS: Bidding");
printHTMLHighlighted("You are ready to bid on: ".$row["name"]);
print("\n".
"| Currently | $maxBid\n");
// Check if the reservePrice has been met (if any)
$reservePrice = $row["reserve_price"];
if ($reservePrice > 0)
{
if ($maxBid >= $reservePrice)
{
print("(The reserve price has been met)\n");
}
else
{
print("(The reserve price has NOT been met)\n");
}
}
txcache_invaltag("users", "id", $row["seller"]);
$sellerNameResult = sql_query("SELECT users.nickname FROM users WHERE id=".$row["seller"], $link) or die("ERROR: Seller name query failed");
$sellerNameRow = sql_fetch_array($sellerNameResult);
$sellerName = $sellerNameRow["nickname"];
sql_free_result($sellerNameResult);
print(" |
| Quantity | ".$row["quantity"]."\n");
print(" |
| First bid | $firstBid\n");
print(" |
| # of bids | $nbOfBids (bid history)\n");
print(" |
| Seller | $sellerName (Leave a comment on this user)\n");
print(" |
| Started | ".$row["start_date"]."\n");
print(" |
| Ends | ".$row["end_date"]."\n");
print(" |
\n");
// Can the user by this item now ?
if (isset($buynow) && $buyNow > 0)
print("".
"
".
" You can buy this item right now for only \$$buyNow
\n");
printHTMLHighlighted("Item description");
print($row["description"]);
print("
\n");
printHTMLHighlighted("Bidding");
$minBid = $maxBid+1;
$out = '';
$out .= ("