Exemplo n.º 1
0
 public static function QuerySingle($id)
 {
     if ($id < 1) {
         $this->result = FALSE;
         return FALSE;
     }
     $class = new QueryAuctions();
     $class->doQuery("`id` = " . (int) $id);
     if (!$class->result) {
         return FALSE;
     }
     return $class->getNext();
 }
 public static function QuerySingleShop($shopId)
 {
     global $config;
     if ($shopId < 1) {
         $this->result = FALSE;
         return FALSE;
     }
     $class = new QueryAuctions();
     $class->doQuery("`id` = " . (int) $shopId, TRUE);
     if (!$class->result) {
         return FALSE;
     }
     return $class->getNext();
 }
Exemplo n.º 3
0
function RenderPage_auctions_ajax()
{
    global $config, $html;
    //file_put_contents('ajax_get.txt',print_r($_GET,TRUE));
    header('Content-Type: text/plain');
    // list auctions
    $auctions = QueryAuctions::QueryCurrent();
    $TotalDisplaying = QueryAuctions::TotalDisplaying();
    $TotalAllRows = QueryAuctions::TotalAllRows();
    $outputRows = "{\n" . "\t" . '"iTotalDisplayRecords" : ' . $TotalDisplaying . ",\n" . "\t" . '"iTotalRecords" : ' . $TotalAllRows . ",\n" . "\t" . '"sEcho" : ' . (int) getVar('sEcho', 'int') . ",\n" . "\t" . '"aaData" : [' . "\n";
    if ($TotalDisplaying < 1) {
        unset($auctions);
    } else {
        $outputRows .= "\t{\n";
        $count = 0;
        while (TRUE) {
            $auction = $auctions->getNext();
            if (!$auction) {
                break;
            }
            $Item = $auction->getItem();
            if (!$Item) {
                continue;
            }
            if ($count != 0) {
                $outputRows .= "\t},\n\t{\n";
            }
            $count++;
            $data = array('item' => $Item->getDisplay(), 'seller' => '<img src="./?page=mcskin&user='******'" width="32" height="32" alt="" /><br />' . $auction->getSeller(), 'price each' => FormatPrice($auction->getPrice()), 'price total' => FormatPrice($auction->getPriceTotal()), 'market percent' => '--', 'qty' => (int) $Item->getItemQty());
            // buy button
            if ($config['user']->hasPerms('canBuy')) {
                $data['canBuy'] = '
          <form action="./" method="post">
          ' . CSRF::getTokenForm() . '
          <input type="hidden" name="page"      value="' . $config['page'] . '" />
          <input type="hidden" name="action"    value="buy" />
          <input type="hidden" name="auctionid" value="' . (int) $auction->getTableRowId() . '" />
          <input type="text" name="qty" value="' . (int) $data['qty'] . '" onkeypress="return numbersonly(this, event);" ' . 'class="input" style="width: 60px; margin-bottom: 5px; text-align: center;" /><br />
          <input type="submit" value="Buy" class="button" />
          </form>
';
            }
            // cancel button
            if ($config['user']->hasPerms('isAdmin')) {
                $data['isAdmin'] = '
          <form action="./" method="post">
          ' . CSRF::getTokenForm() . '
          <input type="hidden" name="page"      value="' . $config['page'] . '" />
          <input type="hidden" name="action"    value="cancel" />
          <input type="hidden" name="auctionid" value="' . (int) $auction->getTableRowId() . '" />
          <input type="submit" value="Cancel" class="button" />
          </form>
';
            }
            // sanitize
            $data = str_replace(array('/', '"', "\r", "\n"), array('\\/', '\\"', '', '\\n'), $data);
            $rowClass = 'gradeU';
            //TODO:
            //gradeA
            //gradeC
            //gradeX
            //gradeU
            $outputRows .= "\t\t" . '"DT_RowClass":"' . $rowClass . '",' . "\n";
            $i = -1;
            foreach ($data as $v) {
                $i++;
                if ($i != 0) {
                    $outputRows .= ",\n";
                }
                $outputRows .= "\t\t" . '"' . $i . '":"' . $v . '"';
            }
            $outputRows .= "\n";
        }
        unset($auctions, $Item);
        $outputRows .= "\t}\n";
    }
    $outputRows .= ']}' . "\n";
    //file_put_contents('ajax_output.txt',$outputRows);
    echo $outputRows;
    exit;
}
 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;
 }
Exemplo n.º 5
0
function RenderPage_servershops_ajax()
{
    global $config, $html;
    //file_put_contents('ajax_get.txt',print_r($_GET,TRUE));
    header('Content-Type: text/plain');
    // list server shops
    $shops = QueryAuctions::QueryShops();
    $TotalDisplaying = QueryAuctions::TotalDisplaying();
    $TotalAllRows = QueryAuctions::TotalAllRows();
    $outputRows = "{\n" . "\t" . '"iTotalDisplayRecords" : ' . $TotalDisplaying . ",\n" . "\t" . '"iTotalRecords" : ' . $TotalAllRows . ",\n" . "\t" . '"sEcho" : ' . (int) getVar('sEcho', 'int') . ",\n" . "\t" . '"aaData" : [' . "\n";
    if ($TotalDisplaying < 1) {
        unset($shops);
    } else {
        $outputRows .= "\t{\n";
        $count = 0;
        while (TRUE) {
            $shop = $shops->getNext();
            if (!$shop) {
                break;
            }
            $Item = $shop->getItem();
            if (!$Item) {
                continue;
            }
            if ($count != 0) {
                $outputRows .= "\t},\n\t{\n";
            }
            $count++;
            $qty = $Item->getItemQty();
            if ($qty == 0) {
                $qty = 'Unlimited';
            }
            $buyAvailable = $shop->getPriceBuy() > 0.0;
            $sellAvailable = $shop->getPriceSell() > 0.0;
            $data = array('item' => $Item->getDisplay(), 'buy price' => $buyAvailable ? FormatPrice($shop->getPriceBuy()) : '---', 'sell price' => $sellAvailable ? FormatPrice($shop->getPriceSell()) : '---', 'qty' => $qty, 'buy/sell' => '');
            // buy/sell button
            if ($config['user']->hasPerms('canBuy') || $config['user']->hasPerms('canSell')) {
                $data['buy/sell'] = '
<form action="./" method="post">
' . CSRF::getTokenForm() . '
<input type="hidden" name="page"      value="' . $config['page'] . '" />
<input type="hidden" name="shopid" value="' . (int) $shop->getTableRowId() . '" />
<input type="text" name="qty" value="' . ($qty < 64 && $qty != 0 ? (int) $qty : 1) . '" onkeypress="return numbersonly(this, event);" ' . 'class="input" style="width: 60px; margin-bottom: 5px; text-align: center;" /><br />' . "\n" . ($config['user']->hasPerms('canBuy') && $buyAvailable ? '<input type="submit" name="action" value="Buy"  class="button" />' . "\n" : '') . ($config['user']->hasPerms('canSell') && $sellAvailable ? '<input type="submit" name="action" value="Sell" class="button" />' . "\n" : '') . '
</form>
';
            }
            // cancel button
            if ($config['user']->hasPerms('isAdmin')) {
                $data['isAdmin'] = '
<form action="./" method="post">
' . CSRF::getTokenForm() . '
<input type="hidden" name="page"      value="' . $config['page'] . '" />
<input type="hidden" name="action"    value="cancel" />
<input type="hidden" name="shopid" value="' . (int) $shop->getTableRowId() . '" />
<input type="submit" value="Cancel" class="button" />
</form>
';
            }
            // sanitize
            $data = str_replace(array('/', '"', "\r", "\n"), array('\\/', '\\"', '', '\\n'), $data);
            $rowClass = 'gradeU';
            $outputRows .= "\t\t" . '"DT_RowClass":"' . $rowClass . '",' . "\n";
            $i = -1;
            foreach ($data as $v) {
                $i++;
                if ($i != 0) {
                    $outputRows .= ",\n";
                }
                $outputRows .= "\t\t" . '"' . $i . '":"' . $v . '"';
            }
            $outputRows .= "\n";
        }
        unset($shops, $Item);
        $outputRows .= "\t}\n";
    }
    $outputRows .= ']}' . "\n";
    //file_put_contents('ajax_output.txt',$outputRows);
    echo $outputRows;
    exit;
}
 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;
 }
Exemplo n.º 7
0
function RenderPage_myauctions()
{
    global $config, $html;
    $output = '';
    $UseAjaxSource = FALSE;
    $config['title'] = 'My Auctions';
    // load page html
    $outputs = RenderHTML::LoadHTML('pages/myauctions.php');
    $html->addTags(array('messages' => ''));
    // load javascript
    $html->addToHeader($outputs['header']);
    // display error
    if (isset($config['error'])) {
        $config['tags']['messages'] .= str_replace('{message}', $config['error'], $outputs['error']);
    }
    if (isset($_SESSION['error'])) {
        $config['tags']['messages'] .= str_replace('{message}', $_SESSION['error'], $outputs['error']);
        unset($_SESSION['error']);
    }
    // display success
    if (isset($_SESSION['success'])) {
        $config['tags']['messages'] .= str_replace('{message}', $_SESSION['success'], $outputs['success']);
        unset($_SESSION['success']);
    }
    // list auctions
    $auctions = QueryAuctions::QueryMy();
    $outputRows = '';
    while (TRUE) {
        $auction = $auctions->getNext();
        if (!$auction) {
            break;
        }
        $Item = $auction->getItem();
        if (!$Item) {
            continue;
        }
        $tags = array('auction id' => (int) $auction->getTableRowId(), 'seller name' => $auction->getSeller(), 'item' => $Item->getDisplay(), 'qty' => (int) $Item->getItemQty(), 'price each' => FormatPrice($auction->getPrice()), 'price total' => FormatPrice($auction->getPriceTotal()), 'created' => $auction->getCreated(), 'expire' => $auction->getExpire(), 'market price percent' => '--', 'rowclass' => 'gradeU');
        //  if($Item->itemType=='tool'){
        //    $output.='<br />'.$Item->getDamagedChargedStr();
        //    foreach($Item->getEnchantmentsArray() as $ench){
        //      $output.='<br /><span style="font-size: smaller;"><i>'.$ench['enchName'].' '.numberToRoman($ench['level']).'</i></span>';
        //    }
        //  }
        //$marketPrice=getMarketPrice($id, 1);
        //if($marketPrice>0){
        //  $marketPercent=round((($price/$marketPrice)*100), 1);
        //}else{
        //  $marketPercent='N/A';
        //}if($marketPercent=='N/A'){
        //  $grade='gradeU';
        //}elseif($marketPercent<=50){
        //  $grade='gradeA';
        //}elseif($marketPercent<=150){
        //  $grade='gradeC';
        //}else{
        //  $grade='gradeX';
        //}
        $htmlRow = $outputs['body row'];
        RenderHTML::RenderTags($htmlRow, $tags);
        $outputRows .= $htmlRow;
    }
    unset($auctions, $Item);
    return $outputs['body top'] . "\n" . $outputRows . "\n" . $outputs['body bottom'];
}