-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
191 lines (178 loc) · 4.67 KB
/
index.php
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
<?php
if(!isset($_COOKIE["money"]))
{
// cookie set:-----money
$expire=time()+60*60*24*30;
setcookie("money","100000.00",$expire);
echo "<script language=\"JavaScript\"> window.location.reload();</script>";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="Jianming Chen">
<link rel="icon" href="../../favicon.ico">
<center><title>Simple Stock Exchange</title></center>
<style type="text/css">
#leftDiv {
background-color: #FFFFFF;
height: 250px;
width: 50%;
position: absolute;
top: 90px;
left: 0px;
overflow: auto;
}
#rightDiv {
background-color: #FFFFFF;
height: 800px;
width: 50%;
right:0px;
top: 90px;
position: absolute;
overflow: auto;
}
#leftDownDiv{
background-color: #FFFFFF;
height: 250px;
width: 50%;
position: absolute;
top: 340px;
left: 0px;
overflow: auto;
}
</style>
</head>
<body>
<p align =center><font size="22">Simple Stock Exchange </font></p>
<hr>
<div id="leftDiv">
<center>
Search Symbol
<form name="searchForm" action="index.php" method="POST" >
<input type="text" name="symbol" placeholder = "Enter Symbol" id="searchText" align = right size ="50">
<input type="submit" name="submit1" value="Search" id = "search" >
</form>
<?PHP
if(isset($_POST['submit1'])){
// if the submit button is pressed
$symbol = $_POST['symbol'];
$url = "http://data.benzinga.com/stock/";
$url .=$symbol;
$content=file_get_contents($url);
$obj= json_decode($content);
if(isset($obj->{'status'})|| empty($symbol))
{
// if the status exists; meaning its fail to retrieve the info.u
echo "The symbol is empty or not found, please enter another symbol";
}
else
{
// the info is found .
echo "<br />";
echo "<br />";
echo $obj->{'name'};
echo "<br />";
echo "<br />";
echo "<table width=\"500\" border=\"1\" align=\"center\" style=\"border-collapse:collapse;table-layout:fixed;word-break:break-all;\">";
echo "<tr>";
echo "<th>Bid</th>";
echo "<th>Ask</th>";
echo "</tr>";
echo "<tr>";
echo "<th>".$obj->{'bid'}."</th>";
echo "<th>".$obj->{'ask'}."</th>";
echo "</tr>";
echo "</table>";
}
}
?>
</div>
</center>
<center>
<div id="leftDownDiv">
<form name="form" action = "BuySell.php" method="POST" >
<input type="text" id="quan" name="quantitys" placeholder = "Quantity" align = left size="50">
<input type="submit" id="buy" name="method" value="Buy">
<input type="submit" id="sell" name="method" value="Sell" >
<input type="hidden" name="Buy" value=<?php echo $obj->{'ask'}; ?> >
<input type="hidden" name="Sell" value=<?php echo $obj->{'bid'}; ?> >
<input type="hidden" name="name" value="<?php echo $obj->{'name'}; ?>" >
<input type="hidden" name="symbol" value="<?php echo $obj->{'symbol'}; ?> ">
</form>
</center>
</div>
<div id="rightDiv">
<p>Your Cash:$
<?php
echo $_COOKIE["money"];
?>
</p>
<center><p>Current Portfolio</p></center>
<table id = "myTable" width="90%" border="1" align="center" style="border-collapse:collapse;table-layout:fixed;word-break:break-all;">
<tr>
<th>Company</th>
<th>Quantity</th>
<th>PricePaid</th>
<th> </th>
</tr>
<?php
if(isset($_COOKIE["name"]))
{
// there is shares in your Portfolio
$arrayNames=unserialize($_COOKIE['name']);
$arrayQuantity=unserialize($_COOKIE['quantity']);
$arrayPrice=unserialize($_COOKIE['price']);
$arraySymbol=unserialize($_COOKIE['symbol']);
$num = count($arrayNames);
for($i=0 ; $i<$num ; ++$i)
{
// show one share
echo "<center><tr>";
echo "<td width=\"50%\" align=center>".$arrayNames[$i]."</td>";
echo "<td width=\"17%\" align=center>".$arrayQuantity[$i]."</td>";
echo "<td width=\"17%\" align=center>".$arrayPrice[$i]."</td>";
echo "<td align=center><button type = \"button\" onclick = \"viewStock('".$arraySymbol[$i]."')\" >View Stock</button></td>";
echo "</tr></center>";
}
}
?>
</table>
</div>
<script language="javascript">
var searched= false;
function viewStock( symbol ){
// imitate the fill and press
searchForm.symbol.value= symbol;
searchForm.submit1.click();
}
function judge()
{
if(searchForm.symbol.value==" " || searchForm.symbol.value=="")
{
alert("Please enter the quantity first.");
searched = false;
}
searched=true;
}
function judgeSearched()
{
if(!searched)
{
alert("You haven't searched any symbol yet. Please search a symbol first.");
return false;
}
var str = form.quantitys.value;
if(str.trim()=="")
{
alert("Please enter the quantity first.");
return false;
}
}
</script>
</body>
</html>