"); exit(); } } $password = $HTTP_POST_VARS['password']; if ($password == null) { $password = $HTTP_GET_VARS['password']; if ($password == null) { printError($scriptName, $startTime, "About me", "You must provide your password!
"); exit(); } } getDatabaseLink($link); beginRO($link); // Authenticate the user $userId = authenticate($nickname, $password, $link); if ( $userId == -1) { die("

ERROR: You don't have an account on RUBis! You have to register first.


"); } function getUserBids($link, $userId) { txcache_invaltag("bids", "user_id", $userId); $bidsResult = sql_query("SELECT item_id, MAX(max_bid) AS max_bid FROM bids WHERE bids.user_id=$userId GROUP BY item_id", $link) or die("ERROR: Query failed for getting bids list."); $bids = array(); while ($bidsRow = sql_fetch_array($bidsResult)) { $bids[$bidsRow["item_id"]] = $bidsRow["max_bid"]; } sql_free_result($bidsResult); return $bids; } function aboutmeBidAndWon($link, $userId) { $vtime = virtualTime(); $now = virtualTimeSQL(); $bids = wrap(true, 'getUserBids', $link, $userId); $activeBidItems = array(); $won30Items = array(); foreach ($bids as $itemId => $maxBid) { $item = getAnyItem($link, $itemId); if (!$item) { continue; } // Stuff our bid in with the rest of the item data $item["my_max_bid"] = $maxBid; $endDate = strtotime($item["end_date"]); if ($endDate > $vtime) { $activeBidItems[] = $item; } else if (($vtime - $endDate) < 30*86400) { /* XXX(DRKP) This is actually all items *bid* on in the * last 30 days, not items won. For whatever reason, * that's what RUBiS displays... */ $won30Items[] = $item; } } // Get the items the user has bid on if (count($activeBidItems) == 0) printHTMLHighlighted("

You did not bid on any item.

\n"); else { printHTMLHighlighted("

Items you have bid on.

\n"); print("\n". "\n". "\n"); foreach ($activeBidItems as $itemRow) { $maxBid = $itemRow["my_max_bid"]; $currentPrice = $itemRow["max_bid"]; if ($currentPrice == null) $currentPrice = "none"; $itemName = $itemRow["name"]; $itemInitialPrice = $itemRow["initial_price"]; $quantity = $itemRow["quantity"]; $itemReservePrice = $itemRow["reserve_price"]; $startDate = $itemRow["start_date"]; $endDate = $itemRow["end_date"]; $sellerId = $itemRow["seller"]; $sellerRow = getUser($link, $sellerId); if (!$sellerRow) { die("

ERROR: This seller does not exist.


\n"); } $sellerNickname = $sellerRow["nickname"]; print("
DesignationInitial PriceCurrent priceYour max bidQuantity". "Start DateEnd DateSellerPut a new bid\n". "
".$itemName. "".$itemInitialPrice."".$currentPrice."".$maxBid."".$quantity. "".$startDate."".$endDate. "".$sellerNickname. "\n"); } print("

\n"); } // Get the items the user won in the past 30 days if (count($won30Items) == 0) printHTMLHighlighted("

You didn't win any item.

\n"); else { printHTMLHighlighted("

Items you won in the past 30 days.

\n"); print("

\n". "\n". "\n"); foreach ($won30Items as $itemRow) { $currentPrice = $itemRow["max_bid"]; if ($currentPrice == null) $currentPrice = "none"; $itemName = $itemRow["name"]; $sellerId = $itemRow["seller"]; $sellerRow = getUser($link, $sellerId); if (!$sellerRow) { die("

ERROR: This seller does not exist.


\n"); } $sellerNickname = $sellerRow["nickname"]; print("
DesignationPrice you bought itSeller". "
".$itemName. "".$currentPrice. "".$sellerNickname. "\n"); } print("

\n"); } } function aboutmeBuyNow($link, $userId) { $vtime = virtualTime(); $now = virtualTimeSQL(); // Get the items the user bought in the past 30 days txcache_invaltag("buy_now", "buyer_id", $userId); $buyNowResult = sql_query("SELECT * FROM buy_now WHERE buy_now.buyer_id=$userId AND buy_now.date >= '$now'::date - '30 days'::interval", $link)or die("ERROR: Query failed for getting buy now list."); if (sql_num_rows($buyNowResult) == 0) printHTMLHighlighted("

You didn't buy any item in the past 30 days.

\n"); else { printHTMLHighlighted("

Items you bought in the past 30 days.

\n"); print("

\n". "\n". "\n"); while ($buyNowRow = sql_fetch_array($buyNowResult)) { $itemId = $buyNowRow["item_id"]; // XXX(Austin) Why did RUBiS assume it would be an old item? $itemRow = getAnyItem($link, $itemId); if (!$itemRow) { die("

ERROR: This item does not exist.


\n"); } $itemName = $itemRow["name"]; $sellerId = $itemRow["seller"]; $price = $itemRow["buy_now"]*$buyNowRow["qty"]; $sellerRow = getUser($link, $sellerId); if (!$sellerRow) { die("

ERROR: This seller does not exist.


\n"); } $sellerNickname = $sellerRow["nickname"]; print("
DesignationQuantityPrice you bought itSeller". "
".$itemName. "".$buyNowRow["qty"]."$price". "".$sellerNickname. "\n"); } print("

\n"); } sql_free_result($buyNowResult); } function aboutmeSeller($link, $userId) { $vtime = virtualTime(); $now = virtualTimeSQL(); // Get the items the user is currently selling txcache_invaltag("items", "seller", $userId); $currentSellsResult = sql_query("SELECT * FROM items WHERE items.seller=$userId AND items.end_date>='$now'", $link) or die("ERROR: Query failed for getting current sellings."); if (sql_num_rows($currentSellsResult) == 0) printHTMLHighlighted("

You are currently selling no item.

\n"); else { printHTMLHighlighted("

Items you are selling.

\n"); print("

\n". "\n". "\n"); while ($currentSellsRow = sql_fetch_array($currentSellsResult)) { $itemName = $currentSellsRow["name"]; $itemInitialPrice = $currentSellsRow["initial_price"]; $quantity = $currentSellsRow["quantity"]; $itemReservePrice = $currentSellsRow["reserve_price"]; $buyNow = $currentSellsRow["buy_now"]; $endDate = $currentSellsRow["end_date"]; $startDate = $currentSellsRow["start_date"]; $itemId = $currentSellsRow["id"]; // $currentPriceResult = sql_query("SELECT MAX(bid) AS bid FROM bids WHERE item_id=$itemId", $link) or die("ERROR: Query failed for getting the item current price (sold item)."); // if (sql_num_rows($currentPriceResult) == 0) // die ("ERROR: Cannot get the current price (sold item)."); // $currentPriceRow = sql_fetch_array($currentPriceResult); $currentPrice = $currentSellsResult["max_bid"]; if ($currentPrice == null) $currentPrice = "none"; print("
DesignationInitial PriceCurrent priceQuantityReservePriceBuy Now". "Start DateEnd Date\n". "
".$itemName. "".$itemInitialPrice."".$currentPrice."".$quantity. "".$itemReservePrice."".$buyNow. "".$startDate."".$endDate."\n"); // sql_free_result($currentPriceResult); } print("

\n"); } // Get the items the user sold the last 30 days txcache_invaltag("old_items", "seller", $userId); $pastSellsResult = sql_query("SELECT * FROM old_items WHERE old_items.seller=$userId AND old_items.end_date > '$now'::date - '30 days'::interval", $link) or die("ERROR: Query failed for getting sold items list."); if (sql_num_rows($pastSellsResult) == 0) printHTMLHighlighted("

You didn't sell any item in the last 30 days.

\n"); else { printHTMLHighlighted("

Items you sold in the last 30 days.

\n"); print("

\n". "\n". "\n"); while ($pastSellsRow = sql_fetch_array($pastSellsResult)) { $itemName = $pastSellsRow["name"]; $itemInitialPrice = $pastSellsRow["initial_price"]; $quantity = $pastSellsRow["quantity"]; $itemReservePrice = $pastSellsRow["reserve_price"]; $buyNow = $pastSellsRow["buy_now"]; $endDate = $pastSellsRow["end_date"]; $startDate = $pastSellsRow["start_date"]; $itemId = $pastSellsRow["id"]; // $currentPriceResult = sql_query("SELECT MAX(bid) AS bid FROM bids WHERE item_id=$itemId", $link) or die("ERROR: Query failed for getting the item current price (sold item)."); // if (sql_num_rows($currentPriceResult) == 0) // die ("ERROR: Cannot get the current price (sold item)."); // $currentPriceRow = sql_fetch_array($currentPriceResult); $currentPrice = $pastSellsResult["max_bid"]; if ($currentPrice == null) $currentPrice = "none"; print("
DesignationInitial PriceCurrent priceQuantityReservePriceBuy Now". "Start DateEnd Date\n". "
".$itemName. "".$itemInitialPrice."".$currentPrice."".$quantity. "".$itemReservePrice."".$buyNow. "".$startDate."".$endDate."\n"); } print("

\n"); } sql_free_result($currentSellsResult); sql_free_result($pastSellsResult); } function aboutmeComments($link, $userId) { $vtime = virtualTime(); $now = virtualTimeSQL(); // Get the comments about the user txcache_invaltag("comments", "to_user", $userId); $commentsResult = sql_query("SELECT * FROM comments WHERE comments.to_user_id=$userId", $link) or die("ERROR: Query failed for the list of comments."); if (sql_num_rows($commentsResult) == 0) printHTMLHighlighted("

There is no comment for this user.

\n"); else { print("

\n"); printHTMLHighlighted("

Comments about you.

\n"); while ($commentsRow = sql_fetch_array($commentsResult)) { $authorId = $commentsRow["from_user_id"]; $authorRow = getUser($link, $authorId); if (!$authorRow) { die("ERROR: This author does not exist.
\n"); } else { $authorName = $authorRow["nickname"]; } $date = $commentsRow["date"]; $comment = $commentsRow["comment"]; print("
$authorName"." wrote the ".$date."
".$comment."

\n"); } print("

\n"); } sql_free_result($commentsResult); } function aboutme($link, $userId, $password) { $userRow = getUser($link, $userId); if (!$userRow) { die("

ERROR: Sorry, but this user does not exist.


\n"); } printHTMLheader("RUBiS: About me"); // Get general information about the user $firstname = $userRow["firstname"]; $lastname = $userRow["lastname"]; $nickname = $userRow["nickname"]; $email = $userRow["email"]; $creationDate = $userRow["creation_date"]; $rating = $userRow["rating"]; printHTMLHighlighted("

Information about ".$nickname."

"); print("Real life name : ".$firstname." ".$lastname."
"); print("Email address : ".$email."
"); print("User since : ".$creationDate."
"); print("Current rating : ".$rating."

"); $vtime = virtualTime(); $now = virtualTimeSQL(); wrap(true, 'aboutmeBidAndWon', $link, $userId); wrap(true, 'aboutmeBuyNow', $link, $userId); wrap(true, 'aboutmeSeller', $link, $userId); printCommentTable($link, $userId); } // wrap(true, 'aboutme', $link, $userId, $password); aboutme($link, $userId, $password); commit($link); sql_close($link); printHTMLfooter($scriptName, $startTime); ?>