#!/usr/local/bin/perl # trade.pl. This program allows users to interact # with the WWWWS system. Set these variables # appropriately before use. $dataPath = "/CHANGE/THIS/PATH/wwwws"; $programUrl = "/CHANGE/THIS/URL/cgi-bin/trade.pl"; require "cgi-lib.pl"; require "chart.pl"; require "ctime.pl"; $historySize = 30; srand(); $accountName = $ENV{'REMOTE_USER'}; if ($accountName eq "") { # This shouldn't happen! But it will happen # if the program is not installed according # to the instructions, or if the server # has bugs regarding user authentication. print "Pragma: no-cache\n"; print "Content-type: text/html\n\n"; print "\n"; print "
\n"; close(CURRENT); close(PERMANENT); } sub LogTransaction { local($text) = @_; print CURRENT $text, "
\n"; print PERMANENT $text, " Time: ", &ctime(time), "
\n"; } sub History { local($symbol) = @_; local(@history); print "Pragma: no-cache\n"; print "Content-type: text/html\n\n"; print "\n"; print "
\n"; } print "Prices for the past 30 days are shown.\n"; print "
\n"; } else { print $symbol, ": trading at ", $price; if (int(@fields) > 2) { $move = $fields[$#fields] - $fields[$#fields - 1]; $move = sprintf("%.4f", $move); if ($move == 0.0) { print " unchanged"; } elsif ($move > 0.0) { print " UP ", $move; } else { print " DOWN ", $move; } } print "\n"; print "See History
\n"; } } close(NEWSPAPERIN); print "
\n";
print "Newspaper \n";
print "Past Transactions \n";
print "\n";
return 0;
}
sub getStockPrice {
local($sym, $s) = @_;
local(@fields, $s);
$s = $dataPath . "/database";
if (!open(PRICEIN, $s)) {
return 0;
}
while(