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;
 }
Exemplo n.º 2
0
function RenderPage_sell()
{
    global $config, $html, $user;
    $config['title'] = 'Sell Items';
    $id = getVar('id', 'int');
    // load page html
    $outputs = RenderHTML::LoadHTML('pages/sell.php');
    if (!is_array($outputs)) {
        echo 'Failed to load html!';
        exit;
    }
    // load javascript
    $html->addToHeader($outputs['header']);
    // query item
    $Item = QueryItems::QuerySingle($user->getId(), $id);
    if (!$Item) {
        return '<h2 style="text-align: center;">The item you\'re trying to sell couldn\'t be found!</h2>';
    }
    // check item blacklist
    ItemFuncs::checkItemBlacklist($Item);
    $qty = getVar('qty');
    $priceFixed = getVar('priceFixed', 'double');
    $priceStart = getVar('priceStart', 'double');
    $priceBuy = getVar('priceBuy', 'double');
    $priceSell = getVar('priceSell', 'double');
    if (empty($qty)) {
        $qty = $Item->getItemQty();
    }
    if ($priceFixed < 0.0) {
        $priceFixed = 0.0;
    }
    if ($priceStart < 0.0) {
        $priceStart = 0.0;
    }
    if ($priceBuy < 0.0) {
        $priceBuy = 0.0;
    }
    if ($priceSell < 0.0) {
        $priceSell = 0.0;
    }
    $messages = '';
    $tags = array('messages' => &$messages, 'item id' => (int) $id, 'item display' => $Item->getDisplay(), 'have qty' => (int) $Item->getItemQty(), 'qty' => (int) $qty, 'price fixed' => (double) $priceFixed, 'price start' => (double) $priceStart, 'price buy' => (double) $priceBuy, 'price sell' => (double) $priceSell, 'currency prefix' => SettingsClass::getString('Currency Prefix'), 'currency postfix' => SettingsClass::getString('Currency Postfix'));
    unset($Item);
    // input errors
    if (isset($_SESSION['error'])) {
        if (is_array($_SESSION['error'])) {
            foreach ($_SESSION['error'] as $msg) {
                $messages .= str_replace('{message}', $msg, $outputs['error']);
            }
        } else {
            $messages .= str_replace('{message}', $_SESSION['error'], $outputs['error']);
        }
        unset($_SESSION['error']);
    }
    if (!$user->hasPerms('canSell')) {
        $messages .= str_replace('{message}', 'You don\'t have permission to sell.', $outputs['error']);
    }
    RenderHTML::RenderTags($outputs['body'], $tags);
    unset($tags);
    return $outputs['body'];
}