public static function CancelAuction($auctionId)
 {
     global $config, $user;
     // validate args
     $auctionId = floor((int) $auctionId);
     if ($auctionId < 1) {
         $_SESSION['error'][] = 'Invalid auction id!';
         return FALSE;
     }
     // query auction
     $auction = QueryAuctions::QuerySingle($auctionId);
     if (!$auction) {
         $_SESSION['error'][] = 'Auction not found!';
         return FALSE;
     }
     // isAdmin or owns auction
     if (!$user->hasPerms('isAdmin') && $auction->getSellerId() != $user->getId()) {
         $_SESSION['error'][] = 'You don\'t own that auction!';
         return FALSE;
     }
     // remove auction
     self::RemoveAuction($auctionId, -1);
     // add item to inventory
     $tableRowId = ItemFuncs::AddCreateItem($auction->getSellerId(), $auction->getItem());
     // add sale log
     $Item = $auction->getItem();
     LogSales::addLog(LogSales::LOG_CANCEL, LogSales::SALE_BUYNOW, $user->getId(), NULL, $Item, 0.0, FALSE, '');
     return TRUE;
 }
 public static function BuyShop($shopId, $qty)
 {
     global $config, $user;
     // has canBuy permissions
     if (!$user->hasPerms('canBuy')) {
         $_SESSION['error'][] = 'You don\'t have permission to buy.';
         return FALSE;
     }
     // sanitize args
     $shopId = (int) $shopId;
     $qty = (int) $qty;
     if ($shopId < 1) {
         $_SESSION['error'][] = 'Invalid server shop id!';
         return FALSE;
     }
     if ($qty < 1) {
         $_SESSION['error'][] = 'Invalid qty!';
         return FALSE;
     }
     // query shop
     $shop = QueryAuctions::QuerySingleShop($shopId);
     if (!$shop) {
         $_SESSION['error'][] = 'Shop not found!';
         return FALSE;
     }
     $Item = $shop->getItemCopy();
     if ($Item->getItemQty() > 0 && $qty > $Item->getItemQty()) {
         $_SESSION['error'][] = 'Not that many for sale!';
         return FALSE;
     }
     // shop price
     $shopPrice = $shop->getPriceBuy();
     if ($shopPrice <= 0.0) {
         $_SESSION['error'][] = 'Cannot buy from this shop!';
         return FALSE;
     }
     $priceTotal = $shopPrice * (double) $qty;
     if ($priceTotal > $user->getMoney()) {
         $_SESSION['error'][] = 'You don\'t have enough money!';
         return FALSE;
     }
     // make payment from buyer
     UserClass::PaymentQuery($user->getName(), $user->getUUID(), 0 - $priceTotal);
     // remove shop
     if ($Item->getItemQty() != 0) {
         if (!self::RemoveShop($shopId, $qty < $Item->getItemQty() ? $qty : -1)) {
             echo '<p style="color: red;">Error removing/updating shop!</p>';
             exit;
         }
     }
     // add to inventory
     $Item->setItemQty($qty);
     $tableRowId = ItemFuncs::AddCreateItem($user->getId(), $Item);
     if (!$tableRowId) {
         echo '<p style="color: red;">Error adding item to your inventory!</p>';
         exit;
     }
     // success
     $_SESSION['success'][] = 'Bought ' . $qty . ' items for ' . SettingsClass::getString('Currency Prefix') . $priceTotal . SettingsClass::getString('Currency Postfix');
     // add sale log
     LogSales::addLog(LogSales::LOG_SALE, LogSales::SALE_SERVER, NULL, $user->getId(), $Item, $priceTotal, FALSE, '', FALSE);
     return TRUE;
 }