-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathportOutline.pl
252 lines (202 loc) · 5.61 KB
/
portOutline.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#!/usr/bin/perl -w
my $debug=0; # default - will be overriden by a form parameter or cookie
my @sqlinput=();
my @sqloutput=();
use strict;
use CGI qw(:standard);
use DBI;
use Time::ParseDate;
my $dbuser="rmx035";
my $dppasswd ="zwpG66Qtv";
my $cookiename="PortSession";
my $debugcookiename="PortDebug";
#
## Get the session input and debug cookies, if any
##
my $inputcookiecontent = cookie($cookiename);
my $inputdebugcookiecontent = cookie($debugcookiename);
my $outputcookiecontent = undef;
my $outputdebugcookiecontent = undef;
my $deletecookie=0;
my $user = undef;
my $password = undef;
my $logincomplain=0;
my $action;
#action can be login, logout, base, register, getstats, strategy, getsymb (displ ay history and
# createport, deleteport, getport, recstock (record new stock info either by user input or by pulling from service),
my $run;
if (defined(param("act"))) {
$action=param("act");
if (defined(param("run"))) {
$run = param("run") == 1;
} else {
$run = 0;
}
} else {
$action="base";
$run = 1;
}
my $dstr;
if (defined(param("debug"))) {
# parameter has priority over cookie
if (param("debug") == 0) {
$debug = 0;
} else {
$debug = 1;
}
} else {
if (defined($inputdebugcookiecontent)) {
$debug = $inputdebugcookiecontent;
} else {
# debug default from script
}
}
$outputdebugcookiecontent=$debug;
if (defined($inputcookiecontent)) {
($user, $password) = split(/\//, $inputcookiecontent);
$outputcookiecontent = $inputcookiecontent;
} else {
($user, $password) = ("anon", "anonanon");
}
if ($action eq "login") {
if ($run) {
($user, $password) = (param('user'), param('password'));
if (ValidUser($user,$password)) {
$outputcookiecontent=join("/",$user,$password);
$action= "base";
$run = 1;
} else {
$logincomplain=1;
$action = "login";
$run = 0;
}
} else {
undef $inputcookiecontent;
($user,$password)= ("anon","anonanon");
}
}
if ($action eq "logout") {
$deletecookie=1;
$action = "base";
$user = "anon";
$password = "anonanon";
$run = 1;
}
my @outputcookies;
if (defined($outputcookiecontent)) {
my $cookie=cookie(-name=>$cookiename,
-value=>$outputcookiecontent,
-expires=>($deletecookie ? '-1h' : '+1h'));
push @outputcookies, $cookie;
}
if (defined($outputdebugcookiecontent)) {
my $cookie=cookie(-name=>$debugcookiename,
-value=>$outputdebugcookiecontent);
push @outputcookies, $cookie;
}
##### need to invoke the code we were provided #####
print header(-expires=>'now', -cookie=>\@outputcookies);
print start_html('Portfolio');
print "<html style=\"height: 100\%\">";
print "<head>";
print "<title>Portfolio</title>";
print "</head>";
print "<h1 style=\"text-align:center\">Welcome to My Portfolio!</h1>";
print "<body style=\"height:100\%;margin:0;background-color:lightblue\">";
print "<style type=\"text/css\">\n\@import \"port.css\";\n</style>\n";
#ACTS
#login
#register
#seeports
#strategy
#updatecash
#newport
#getport
#getsymb
#stocktrans
#getstats
print end_html();
#SUBFUNCTIONS-> sql calls
#UserAdd
#ValidUser
#AddPortfolio
#portID, name, numStocks, useremail
#DeletePortfolio
#AddStock
#symb, count, portID
#DeleteStock
#DepositCash
#Widthdraw Cash
#ValidStock
#GetStocks
#GetStockValue -quote ? not needed ?
#GetPortValue
#GetCashAccount
#UpdateStock - insertion into our NewData
#ExecSQL
#sub ExecSQL {
# my ($user, $passwd, $querystring, $type, @fill) =@_;
# if ($debug) {
# # if we are recording inputs, just push the query string and fill list onto the
# # global sqlinput list
# push @sqlinput, "$querystring (".join(",",map {"'$_'"} @fill).")";
# }
# my $dbh = DBI->connect("DBI:Oracle:",$user,$passwd);
# if (not $dbh) {
# # if the connect failed, record the reason to the sqloutput list (if set)
# # and then die.
# if ($debug) {
# push @sqloutput, "<b>ERROR: Can't connect to the database because of ".$DBI::errstr."</b>";
# }
# die "Can't connect to database because of ".$DBI::errstr;
# }
# my $sth = $dbh->prepare($querystring);
# if (not $sth) {
# #
# # If prepare failed, then record reason to sqloutput and then die
# #
# if ($debug) {
# push @sqloutput, "<b>ERROR: Can't prepare '$querystring' because of ".$DBI::errstr."</b>";
# }
# my $errstr="Can't prepare $querystring because of ".$DBI::errstr;
# $dbh->disconnect();
# die $errstr;
# }
# if (not $sth->execute(@fill)) {
#
# if exec failed, record to sqlout and die.
# if ($debug) {
# push @sqloutput, "<b>ERROR: Can't execute '$querystring' with fill (".join(",",map {"'$_'"} @fill).") because of ".$DBI::errstr."</b>";
# }
# my $errstr="Can't execute $querystring with fill (".join(",",map {"'$_'"} @fill).") because of ".$DBI::errstr;
# $dbh->disconnect();
# die $errstr;
# }
#
# The rest assumes that the data will be forthcoming.
#
#
# my @data;
# if (defined $type and $type eq "ROW") {
# @data=$sth->fetchrow_array();
# $sth->finish();
# if ($debug) {push @sqloutput, MakeTable("debug_sqloutput","ROW",undef,@data);}
# $dbh->disconnect();
# return @data;
# }
# my @ret;
# while (@data=$sth->fetchrow_array()) {
# push @ret, [@data];
# }
# if (defined $type and $type eq "COL") {
# @data = map {$_->[0]} @ret;
# $sth->finish();
# if ($debug) {push @sqloutput, MakeTable("debug_sqloutput","COL",undef,@data);}
# $dbh->disconnect();
# return @data;
# }
# $sth->finish();
# if ($debug) {push @sqloutput, MakeTable("debug_sql_output","2D",undef,@ret);}
# $dbh->disconnect();
# return @ret;
#}