Exemplo n.º 1
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;
}