Exemplo n.º 1
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' => FormatPorzent(CalcPorzent($auction->getPrice(), $Item->getMarketPrice())), '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;
}
Exemplo n.º 2
0
function RenderPage_myauctions()
{
    global $config, $html;
    $UseAjaxSource = FALSE;
    $config['title'] = 'My Auctions';
    // load page html
    $outputs = RenderHTML::LoadHTML('pages/myauctions.php');
    // load javascript
    $html->addToHeader($outputs['header']);
    // display error
    $messages = '';
    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']);
    }
    // display success
    if (isset($_SESSION['success'])) {
        if (is_array($_SESSION['success'])) {
            foreach ($_SESSION['success'] as $msg) {
                $messages .= str_replace('{message}', $msg, $outputs['success']);
            }
        } else {
            $messages .= str_replace('{message}', $_SESSION['success'], $outputs['success']);
        }
        unset($_SESSION['success']);
    }
    $outputs['body top'] = str_replace('{messages}', $messages, $outputs['body top']);
    unset($messages);
    // 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(), 'market price percent' => FormatPorzent(CalcPorzent($auction->getPrice(), $Item->getMarketPrice())), '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'];
}