public static function CreateShop($id, $qty, $priceBuy, $priceSell)
 {
     global $config, $user;
     // has isAdmin permissions
     if (!$user->hasPerms('isAdmin')) {
         $_SESSION['error'][] = 'You don\'t have permission to create a server shop.';
         return FALSE;
     }
     // sanitize args
     $id = (int) $id;
     $qty = (int) $qty;
     if ($id < 1) {
         $_SESSION['error'][] = 'Invalid item id!';
         return FALSE;
     }
     if ($qty < 0) {
         $_SESSION['error'][] = 'Invalid qty!';
         return FALSE;
     }
     $priceBuy = floor($priceBuy * 100.0) / 100.0;
     $priceSell = floor($priceSell * 100.0) / 100.0;
     if ($priceBuy <= 0.0 && $priceSell <= 0.0) {
         $_SESSION['error'][] = 'Invalid price! Must provide either buy, sell, or both.';
         return FALSE;
     }
     // check max price
     $maxSellPrice = SettingsClass::getDouble('Max Sell Price');
     if ($maxSellPrice > 0.0 && $priceBuy > $maxSellPrice) {
         $_SESSION['error'][] = 'Over max buy price of ' . SettingsClass::getString('Currency Prefix') . $maxSellPrice . SettingsClass::getString('Currency Postfix') . ' !';
         return FALSE;
     }
     if ($maxSellPrice > 0.0 && $priceSell > $maxSellPrice) {
         $_SESSION['error'][] = 'Over max sell price of ' . SettingsClass::getString('Currency Prefix') . $maxSellPrice . SettingsClass::getString('Currency Postfix') . ' !';
         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));
     }
     // query item
     $Item = QueryItems::QuerySingle($user->getId(), $id);
     if (!$Item) {
         $_SESSION['error'][] = 'Item not found!';
         return FALSE;
     }
     // create server shop
     $query = "INSERT INTO `" . $config['table prefix'] . "ServerShops` (" . "`itemId`, `itemDamage`, `itemData`, `qty`, `enchantments`, `priceBuy`, `priceSell`, `created`, `itemTitle` )VALUES( " . (int) $Item->getItemId() . ", " . (int) $Item->getItemDamage() . ", " . "'" . mysql_san($Item->getItemData()) . "', " . (int) $qty . ", " . "'" . mysql_san($Item->getEnchantmentsCompressed()) . "', " . (double) $priceBuy . ", " . (double) $priceSell . ", " . "NOW(), " . "'" . mysql_san($Item->getItemTitle()) . "' )";
     $result = RunQuery($query, __FILE__, __LINE__);
     if (!$result) {
         echo '<p style="color: red;">Error creating server shop!</p>';
         exit;
     }
     return TRUE;
 }
 public static function BuyFixed($auctionId, $qty)
 {
     global $config, $user;
     // validate args
     $auctionId = (int) $auctionId;
     $qty = (int) $qty;
     if ($auctionId < 1) {
         $_SESSION['error'][] = 'Invalid auction id!';
         return FALSE;
     }
     if ($qty < 1) {
         $_SESSION['error'][] = 'Invalid qty!';
         return FALSE;
     }
     // has canBuy permissions
     if (!$user->hasPerms('canBuy')) {
         $_SESSION['error'][] = 'You don\'t have permission to buy.';
         return FALSE;
     }
     // query auction
     $auction = QueryAuctions::QuerySingle($auctionId);
     if (!$auction) {
         $_SESSION['error'][] = 'Auction not found!';
         return FALSE;
     }
     $Item = $auction->getItemCopy();
     //  // is item allowed
     //  if (!itemAllowed($item->name, $item->damage)){
     //    $_SESSION['error'][] = $item->fullname.' is not allowed to be sold.';
     //    header("Location: ../myauctions.php");
     //  }
     // buying validation
     if ($auction->getSellerId() == $user->getId()) {
         $_SESSION['error'][] = 'Can\'t buy from yourself!';
         return FALSE;
     }
     if ($qty > $Item->getItemQty()) {
         $_SESSION['error'][] = 'Not that many for sale!';
         return FALSE;
     }
     $maxSellPrice = SettingsClass::getDouble('Max Sell Price');
     $sellPrice = $auction->getPrice();
     $priceTotal = $sellPrice * (double) $qty;
     if ($maxSellPrice > 0.0 && $sellPrice > $maxSellPrice) {
         $_SESSION['error'][] = 'Over max sell price of ' . SettingsClass::getBoolean('Currency Prefix') . $maxSellPrice . SettingsClass::getBoolean('Currency Prefix') . ' !';
         return FALSE;
     }
     if ($priceTotal > $user->getMoney()) {
         $_SESSION['error'][] = 'You don\'t have enough money!';
         return FALSE;
     }
     // make payment from buyer to seller
     UserClass::MakePayment($user->getName(), $user->getUUID(), $auction->getSeller(), $auction->getSellerUUID(), $priceTotal, 'Bought auction ' . (int) $auction->getTableRowId() . ' ' . $Item->getItemTitle() . ' x' . (int) $Item->getItemQty());
     // remove auction
     if (!self::RemoveAuction($auctionId, $qty < $Item->getItemQty() ? $qty : -1)) {
         echo '<p style="color: red;">Error removing/updating auction!</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;
     }
     // add sale log
     LogSales::addLog(LogSales::LOG_SALE, LogSales::SALE_BUYNOW, $auction->getSellerId(), $user->getId(), $Item, $sellPrice, FALSE, '', TRUE);
     return TRUE;
 }