<?php
// (C) 2000 LinuxFutures.com, Inc.
//
// Part of UPmarkets - the software behind the LinuxFutures game site
// visit www.LinuxFutures.com to play
//
// We are making the software available to you under the GNU General Public License,
// a copy of which should accompany this software in the file LICENSE.
//
// A web-based copy of the LICENSE is located at http://www.gnu.org/copyleft/gpl.txt
//
// While there is no charge for using this software, there are important restrictions.
//
// This LICENSE does not allow, in general, proprietary modifications or proprietary derivative works.
// If you base new software on our work, great, but you have to give them away just as we did.
//
// This software carries ABSOLUTELY NO WARRANTY. It is offered AS-IS, and may not work at all
// or may have harmful or hazardous side effects.
//
//
// -------------------- what this file does ---------------------
// provides a function quotes_as_discussion(symbolid, options) that
// returns an HTML string of the quotes as if they were a flat, nonthreaded
// discussion in a newsgroup
//
// options
// only_active_quotes - only show active quotes
// color_by_price > 0 , price level to color by price
// blue, priced below , red, priced above, black imbetween
//
function quotes_as_discussion($symbolid="0", $options) {
global $db_link;
$symbolid = (int) $symbolid; //trust no one
if ($symbolid <= 0) { echo "error: symbolid <= 0"; exit(); }
$sql = "SELECT * from quotes WHERE quotes.symbolid=".$symbolid." ";
$sql = "SELECT quotes.posted as posted,
quotes.userid as userid,
quotes.buy_price as buy_price,
quotes.sell_price as sell_price,
quotes.quantity as quantity,
quotes.rationale as rationale,
sum(ledgers.amount) as holdings
FROM
quotes LEFT JOIN ledgers USING(userid,symbolid)
WHERE
quotes.symbolid = ".$symbolid." ";
if ($options["only_active_quotes"]) {
$sql .= "AND active=1 ";
}
$sql .= " GROUP BY quotes.posted ORDER BY quotes.posted ASC;";
$r_quotes = mysql_query($sql, $db_link);
mysql_error_sanity("f_quotes_as_discussion SELECT");
$number_of_quotes = mysql_num_rows($r_quotes);
$o = "";
$r1m = rand(1,1000000);
for($i=0; $i < $number_of_quotes; $i++){
$quote = mysql_fetch_array($r_quotes);
$o .= "<HR>";
$o .= "<table columns=4 width=40 bgcolor=#cccccc>";
$o .= "<tr>
<td>Posted</td>
<td>Userid#</td>
<td>Buy@</td>
<td>Sell@</td>
<td>Quantity</td>
<td>Current Holdings</td>
</tr>";
$o .= "<tr>
<td><font color=black>".$quote["posted"]."</font></td>";
$o .= "<td align=right><font color=black>";
$o .= '<A href="user_home_page.php?userid='.$quote["userid"].'&r='.$r1m.'">';
$o .= $quote["userid"]."</A></font></td>";
$o .= "<td align=right><font color=blue>".$quote["buy_price"]."</font></td>";
$o .= "<td align=right><font color=red>".$quote["sell_price"]."</font></td>";
$o .= "<td align=right><font color=black>".$quote["quantity"]."</font></td>";
$o .= "<td align=right><font color=black>".$quote["holdings"]."</font></td>";
$o .= "</tr></table>";
$o .= "<br><img src=armored_email.php?userid=".$quote["userid"]."&r=".$r1m."> says:";
$o .= "<font color=black>";
if ($options["color_by_price"] > 0) {
if ( $options["color_by_price"] <= $quote["buy_price"] ){
$o .= "<font color=blue>";
} elseif ( $options["color_by_price"] >= $quote["sell_price"] ){
$o .= "<font color=red>";
} else {
$o .= "<font color=black>";
}
} else {
$o .= "<font color=black>";
}
$o .= htmlspecialchars($quote["rationale"]);
$o .= "</font><br>";
}
return($o);
}
?>