public static function SellFixed($id, $qty, $price, $desc)
 {
     global $config, $user;
     // has canSell permissions
     if (!$user->hasPerms('canSell')) {
         $_SESSION['error'][] = 'You don\'t have permission to sell.';
         return FALSE;
     }
     // sanitize args
     $id = (int) $id;
     if ($id < 1) {
         $_SESSION['error'][] = 'Invalid item id!';
         return FALSE;
     }
     $qty = floor((int) $qty);
     $price = floor($price * 100.0) / 100.0;
     if ($qty <= 0) {
         $_SESSION['error'][] = 'Invalid qty!';
         return FALSE;
     }
     if ($price <= 0.0) {
         $_SESSION['error'][] = 'Invalid price!';
         return FALSE;
     }
     if (!empty($desc)) {
         $desc = preg_replace('/<[^>]*>/', '', $desc);
         $desc = preg_replace('/\\b(https?|ftp|file):\\/\\/[-A-Z0-9+&@#\\/%?=~_|$!:,.;]*[A-Z0-9+&@#\\/%=~_|$]/i', '', strip_tags($desc));
     }
     //  if (!itemAllowed($item->name, $item->damage)){
     //    $_SESSION['error'][] = $item->fullname.' is not allowed to be sold.';
     //    header("Location: ../myauctions.php");
     //  }
     $maxSellPrice = SettingsClass::getDouble('Max Sell Price');
     if ($maxSellPrice > 0.0 && $price > $maxSellPrice) {
         $_SESSION['error'][] = 'Over max sell price of ' . SettingsClass::getString('Currency Prefix') . $maxSellPrice . SettingsClass::getString('Currency Postfix') . ' !';
         return FALSE;
     }
     // query item
     $Item = QueryItems::QuerySingle($user->getId(), $id);
     if (!$Item) {
         $_SESSION['error'][] = 'Item not found!';
         return FALSE;
     }
     // check item blacklist
     ItemFuncs::checkItemBlacklist($Item);
     if ($qty > $Item->getItemQty()) {
         $_SESSION['error'][] = 'You don\'t have that many!';
         return FALSE;
     }
     // create auction
     $query = "INSERT INTO `" . $config['table prefix'] . "Auctions` (" . "`playerId`, `itemId`, `itemDamage`, `itemData`, `qty`, `enchantments`, `itemTitle`, `price`, `created` )VALUES( " . "'" . mysql_san($user->getId()) . "', " . (int) $Item->getItemId() . ", " . (int) $Item->getItemDamage() . ", " . "'" . mysql_san($Item->getItemData()) . "', " . (int) $qty . ", " . "'" . mysql_san($Item->getEnchantmentsCompressed()) . "', " . "'" . mysql_san($Item->getItemTitle()) . "', " . (double) $price . ", NOW() )";
     $result = RunQuery($query, __FILE__, __LINE__);
     if (!$result) {
         echo '<p style="color: red;">Error creating auction!</p>';
         exit;
     }
     $auctionId = mysql_insert_id();
     // update qty / remove item stack
     if (!ItemFuncs::RemoveItem($Item->getTableRowId(), $qty < $Item->getItemQty() ? $qty : -1)) {
         echo '<p style="color: red;">Error removing item stack quantity!</p>';
         exit;
     }
     // add sale log
     $Item->setItemQty($qty);
     LogSales::addLog(LogSales::LOG_NEW, LogSales::SALE_BUYNOW, $user->getId(), NULL, $Item, $price, FALSE, '');
     return TRUE;
 }
 public static function SellShop($shopId, $qty)
 {
     global $config, $user;
     // has canSell permissions
     if (!$user->hasPerms('canSell')) {
         $_SESSION['error'][] = 'You don\'t have permission to sell.';
         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;
     }
     $shopItem = $shop->getItem();
     if (!$shopItem) {
         $_SESSION['error'][] = 'Failed to get item info for server shop!';
         return FALSE;
     }
     // query player items
     $Items = QueryItems::QueryInventory($user->getId(), $shopItem);
     if (!$Items) {
         $_SESSION['error'][] = 'Failed to get item from inventory!';
         return FALSE;
     }
     // shop price
     $shopPrice = $shop->getPriceSell();
     if ($shopPrice <= 0.0) {
         $_SESSION['error'][] = 'Cannot sell to this shop!';
         return FALSE;
     }
     // sell multiple stacks
     $hasFound = FALSE;
     $soldCount = 0;
     while (TRUE) {
         $Item = $Items->getNext();
         // no more stacks found
         if (!$Item) {
             break;
         }
         // remove empty stack
         if ($Item->getItemQty() <= 0) {
             ItemFuncs::RemoveItem($Item->getTableRowId(), -1);
             continue;
         }
         // sold enough
         if ($soldCount >= $qty) {
             break;
         }
         $hasFound = TRUE;
         // sell partial stack
         if ($qty - $soldCount < $Item->getItemQty()) {
             $sellQty = $qty - $soldCount;
             $soldCount += $sellQty;
             if (!ItemFuncs::RemoveItem($Item->getTableRowId(), $sellQty)) {
                 $_SESSION['error'][] = 'Failed to remove sold item!';
                 return FALSE;
             }
             // sell full stack
         } else {
             $soldCount += $Item->getItemQty();
             if (!ItemFuncs::RemoveItem($Item->getTableRowId(), -1)) {
                 $_SESSION['error'][] = 'Failed to remove sold item!';
                 return FALSE;
             }
         }
     }
     // no items sold
     if (!$hasFound || $soldCount <= 0) {
         $_SESSION['error'][] = 'You don\'t have any of this item!';
         return FALSE;
     }
     // price for sold items
     $priceTotal = $shopPrice * (double) $soldCount;
     // success
     $_SESSION['success'][] = 'Sold ' . $soldCount . ' items for ' . SettingsClass::getString('Currency Prefix') . $priceTotal . SettingsClass::getString('Currency Postfix');
     // make payment to seller
     UserClass::PaymentQuery($user->getName(), $user->getUUID(), $priceTotal);
     // sold less than requested
     if ($qty > $soldCount) {
         $_SESSION['error'][] = 'You don\'t have that many!';
     }
     // add sale log
     $Item->setItemQty($soldCount);
     LogSales::addLog(LogSales::LOG_SALE, LogSales::SALE_SERVER, NULL, $user->getId(), $Item, $priceTotal, FALSE, '', FALSE);
     return TRUE;
 }