Example #1
0
function show_orders()
{
    global $uid;
    global $PHP_SELF;
    // BUY ORDERS
    $sth = mysql_query("SELECT * FROM stockmarket_orders WHERE uid=" . $uid . " AND type=" . BUY_ORDER . " ORDER by stockmarket, time");
    if (!$sth) {
        show_message("ERROR:: GET BUY ORDERS");
        return false;
    }
    if (mysql_num_rows($sth) == 0) {
        table_start("center", 500);
        table_text(array("Buy Orders"), "", "", "5", "head");
        table_text(array("No orders"), "", "", "5", "text");
        table_end();
    } else {
        table_start("center", 500);
        table_text(array("Buy Orders"), "", "", "5", "head");
        table_text(array(" ", "amount", "max buy price", "time", " "), "", "", "", "text");
        while ($buy_order = mysql_fetch_assoc($sth)) {
            $resource = get_resource_name($buy_order["stockmarket"]);
            $pic = "<img src=\"arts/" . $resource . ".gif\" alt=\"" . $resource . "\" border=\"0\" />\n";
            $link = "<a href=\"" . $PHP_SELF . "?act=remove_order&type=" . BUY_ORDER . "&res=" . $buy_order["stockmarket"] . "&time=" . $buy_order["time"] . "\">remove order</a>";
            table_text(array($pic, $buy_order["amount"], $buy_order["price"] < 100 ? $buy_order["price"] : "unlimited", $buy_order["time"], $link), "", "", "", "text");
        }
        table_end();
    }
    echo "<br />\n";
    // SELL ORDERS
    $sth = mysql_query("SELECT * FROM stockmarket_orders WHERE uid=" . $uid . " AND type=" . SELL_ORDER . " ORDER by stockmarket, time");
    if (!$sth) {
        show_message("ERROR:: GET SELL ORDERS");
        return false;
    }
    if (mysql_num_rows($sth) == 0) {
        table_start("center", 500);
        table_text(array("Sell Orders"), "", "", "5", "head");
        table_text(array("No orders"), "", "", "5", "text");
        table_end();
    } else {
        table_start("center", 500);
        table_text(array("Sell Orders"), "", "", "5", "head");
        table_text(array("&nbsp;", "amount", "min sell price", "time", "&nbsp;"), "", "", "", "text");
        while ($sell_order = mysql_fetch_assoc($sth)) {
            $resource = get_resource_name($sell_order["stockmarket"]);
            $pic = "<img src=\"arts/" . $resource . ".gif\" alt=\"" . $resource . "\" border=\"0\" />\n";
            $link = "<a href=\"" . $PHP_SELF . "?act=remove_order&type=" . SELL_ORDER . "&res=" . $sell_order["stockmarket"] . "&time=" . $sell_order["time"] . "\">remove order</a>";
            table_text(array($pic, $sell_order["amount"], $sell_order["price"] > 0 ? $sell_order["price"] : "unlimited", $sell_order["time"], $link), "", "", "", "text");
        }
        table_end();
    }
}
		<input type="hidden" name="a" value="' . $_GET[a] . '" />
		<input type="hidden" name="req" value="1">
		<input class="fav" type="submit" value="' . $fav_add[$lang] . '" />
		</form>';
    print '<a id="pretty" title="' . $tip_export[$lang] . '" class="menu_chat" href="export.php?a=' . $e_string . '">' . $export_link[$lang] . '</a>&nbsp; | &nbsp;';
    print $all_for_u[$lang];
    print '<a id="pretty" title="' . $all_for_u_m2_d[$lang] . '" class="menu_chat" href="chat_map.php?chat_map=' . $predefined . '"><u>' . $all_for_u_m2[$lang] . '</u></a>';
    print '&nbsp;<small>|</small>&nbsp;';
    print '<a id="pretty" title="' . $all_for_u_m_d[$lang] . '" class="menu_chat" href="search_v2.php?b=' . $predefined_s . '"><u>' . $all_for_u_m[$lang] . '</u></a>';
    print '&nbsp; | &nbsp;';
    print '<a id="pretty" title="' . $tip_delete[$lang] . '" class="menu_chat" href="calendar_view.php?a=' . $action_link . '">' . $del_t[$lang] . '</a>';
    print '</td></tr>';
    print '<tr class="spacer"><td colspan="7"></td></tr>';
    print '<tbody id="searchfield">' . "\n";
    while ($entry = mysql_fetch_array($result)) {
        $resource = get_resource_name($entry[peer_resource_id], $xmpp_host);
        $licz++;
        if ($entry["direction"] == "to") {
            $col = "main_row_a";
        } else {
            $col = "main_row_b";
        }
        $ts = strstr($entry["ts"], ' ');
        // time calc
        $pass_to_next = $entry["ts"];
        $new_d = $entry["ts"];
        $time_diff = abs(strtotime("{$old_d}") - strtotime(date("{$new_d}")));
        $old_d = $pass_to_next;
        // end time calc
        if ($time_diff > $split_line and $licz > 1) {
            $in_minutes = round($time_diff / 60, 0);
 function sell_commit($trade_number, $price, $fail_chance)
 {
     // Resourcen von der Tradestation entfernen und geld gutschreiben
     $resource = get_resource_name($this->stockmarket);
     if ($trade_number >= $this->amount) {
         $stocks_to_sell = $this->amount;
         $sth = mysql_query("DELETE FROM stockmarket_orders WHERE uid=" . $this->uid . " AND stockmarket = '" . $this->stockmarket . "' AND time = '" . $this->time . "' AND type=" . SELL_ORDER);
     } else {
         $stocks_to_sell = $trade_number;
         $sth = mysql_query("UPDATE stockmarket_orders SET amount = amount - " . $stocks_to_sell . ", time = time WHERE uid=" . $this->uid . " AND stockmarket = '" . $this->stockmarket . "' AND time = '" . $this->time . "' AND type=" . SELL_ORDER);
     }
     if (!$sth) {
         show_error("ERROR::DELETE / UPDATE BUY ORDER");
         return false;
     }
     $credit_uid = $this->uid;
     $failed = $this->transaction_fails($fail_chance);
     // FAIL CHANCE
     if ($failed) {
         $credit_uid = $this->get_random_trade_uid();
     }
     $sth = mysql_query("UPDATE ressources SET money = money + " . $stocks_to_sell * $price . " WHERE uid=" . $credit_uid);
     if (!$sth) {
         show_error("ERROR::PAY SELLER");
         return false;
     }
     $sth = mysql_query("UPDATE tradestations set " . $resource . " = " . $resource . " - " . $stocks_to_sell . " WHERE uid=" . $this->uid);
     if (!$sth) {
         show_error("ERROR::REMOVE RES FROM STATION");
         return false;
     }
     $trade_number -= $stocks_to_sell;
     $this->amount -= $stocks_to_sell;
     if ($failed && $credit_uid != $this->uid) {
         send_stockmarket_ticker($this->uid, "SIR! Our files say that we have SOLD: " . $stocks_to_sell . " units of " . get_resource_name($this->stockmarket) . " for " . $price . " &euro; each!<br> <strong>But we have never recieved the money!</strong>");
         send_ticker_from_to(false, $credit_uid, "w", "Sir! " . $price * $stocks_to_sell . " &euro; from a trade transaction seems to be misleaded to us! Lucky, isn't it?");
     } else {
         if ($this->amount > 0) {
             send_stockmarket_ticker($this->uid, "PARTIAL SOLD: " . $stocks_to_sell . " units of " . get_resource_name($this->stockmarket) . " for " . $price . " &euro; each.");
         } else {
             send_stockmarket_ticker($this->uid, "COMPLETE SOLD: " . $stocks_to_sell . " units of " . get_resource_name($this->stockmarket) . " for " . $price . " &euro; each.");
         }
     }
     return $trade_number;
 }