-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform.php
382 lines (354 loc) · 9.4 KB
/
form.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
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<?php
session_start();
if(!$_SESSION["user"])
header('location: index.php');
global $e;
$e=$_SESSION["user"];
include("includes/db.php");
if($_GET["code"])
{
$c=$_GET["code"];
$con=mysqli_connect('sql308.byethost11.com','b11_18001806','eshu@123','b11_18001806_dbms');
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql1="select * from company where code='$c'";
$result=mysqli_query($con,$sql1);
if($result)
{
if(mysqli_num_rows($result)==0)
{
echo '<script language="javascript">';
echo 'alert("code adding failed not a valid code")'; //not showing an alert box.
echo '</script>';
}
else
{
$sql="INSERT INTO com(username,code) VALUES('$e','$c')";
$query=mysqli_query($con,$sql);
if($query)
{
echo '<script language="javascript">';
echo 'alert("Successful")'; //not showing an alert box.
echo '</script>';
main($c);
}
}
}
else
{
echo '<script language="javascript">';
echo 'alert("code adding failed ")'; //not showing an alert box.
echo '</script>';
}
}
function createURL($tickername)
{
return "http://www.google.com/finance/historical?q=$tickername&startdate=AUG+1%2C+2017&enddate=NOV+19%2C+2017&output=csv";
}
function getCSVFile($url,$outputFile)
{
$content=file_get_contents($url);
$content=str_replace("Date,Open,High,Low,Close,Volume","",$content);
$content=trim($content);
file_put_contents($outputFile,$content);
}
function filetoDatabase($textfile,$tablename)
{
$count=0;
$file = fopen($textfile,"r");
$line=fgets($file);
while(!feof($file))
{
$line=fgets($file);
$pieces=explode(",",$line);
$date=$pieces[0];
$mdate=date("Y-m-d",strtotime($date));
$open=$pieces[1];
$high=$pieces[2];
$low=$pieces[3];
$close=$pieces[4];
$volume=$pieces[5];
$amount_change=$close-$open;
if($open==0)
{
continue;
}
$percent_change=(($amount_change/$open)*100);
$connect=mysqli_connect('sql308.byethost11.com','b11_18001806','eshu@123')or die("error");
mysqli_select_db($connect,"b11_18001806_dbms")or die("error");
$sql="SELECT * FROM $tablename";
$result=mysqli_query($connect,$sql);
if(!$result)
{
$sql2= "CREATE TABLE $tablename(Date VARCHAR(10) PRIMARY KEY,Open FLOAT,High FLOAT,Low FLOAT,Close FLOAT,Volume INT(6),amount_change FLOAT,percent_change FLOAT) ";
mysqli_query($connect,$sql2);
}
$sql4="SELECT * FROM $tablename where date='$date'";
$result1=mysqli_query($connect,$sql4);
if($result1)
{
if(mysqli_num_rows($result1)==0)
{
$sql3="INSERT INTO $tablename(Date,Open,High,Low,Close,Volume,amount_change,percent_change) VALUES('$mdate','$open','$high','$low','$close','$volume','$amount_change','$percent_change')";
mysqli_query($connect,$sql3);
}
}
else
{
echo "error processing query";
}
}
fclose($file);
}
function main($e)
{
$companyticker=trim($e);
$fileurl=createURL($companyticker);
$companytxtfile="txtfiles/".$companyticker.".txt";
getCSVFile($fileurl,$companytxtfile);
filetoDatabase($companytxtfile,$companyticker);
}
?>
<html>
<head>
<script>
function myFunction() {
var input, filter, ul, li, a, i;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
ul = document.getElementById("myUL");
li = ul.getElementsByTagName("li");
for (i = 0; i < li.length; i++) {
a = li[i].getElementsByTagName("a")[0];
if (a.innerHTML.toUpperCase().indexOf(filter) > -1) {
li[i].style.display = "";
} else {
li[i].style.display = "none";
}
}
}
function showResult(str) {
if (str.length==0) {
document.getElementById("livesearch").innerHTML="";
document.getElementById("livesearch").style.border="0px";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (this.readyState==4 && this.status==200) {
document.getElementById("livesearch").innerHTML=this.responseText;
document.getElementById("livesearch").style.border="1px solid #A5ACB2";
}
}
xmlhttp.open("GET","search.php?key="+str,true);
xmlhttp.send();
}
</script>
<style>
* {
box-sizing: border-box;
}
#myInput {
background-image: url('/css/searchicon.png');
background-position: 10px 12px;
background-repeat: no-repeat;
width: 100%;
font-size: 16px;
padding: 12px 20px 12px 40px;
border: 1px solid #ddd;
margin-bottom: 12px;
}
#myUL {
list-style-type: none;
padding: 0;
margin: 0;
}
#myUL li a {
border: 1px solid #ddd;
margin-top: -1px; /* Prevent double borders */
background-color: #f6f6f6;
padding: 12px;
text-decoration: none;
font-size: 18px;
color: black;
display: block
}
#myUL li a:hover:not(.header) {
background-color: #eee;
}
body {
margin: 0;
}
/* Style the header */
.header {
background-color: #f1f1f1;
text-align: center;
}
/* Style the top navigation bar */
.topnav {
margin: 7px;
overflow: hidden;
background-color: white;
height: 350px;
}
/* Style the topnav links */
.topnav a {
padding: 14px 16px;
float: left;
display: block;
color: black;
text-align: center;
text-decoration: none;
}
/* Change color on hover */
.topnav a:hover {
background-color: #4CAF50;
color: black;
}
/* Create three unequal columns that floats next to each other */
.column {
float: left;
padding: 15px;
}
/* Left and right column */
.column.side {
width: 26%;
background-color: #e1e8e5;
}
/* Middle column */
.column.middle {
background-color: white;
width: 47.5%;
margin-left: 0.20%;
margin-right: 0.20%;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
/* Responsive layout - makes the three columns stack on top of each other instead of next to each other */
@media (max-width: 600px) {
.column.side, .column.middle {
width: 100%;
}
}
/* Style the footer */
.footer {
background-color: #f1f1f1;
padding: 10px;
text-align: center;
}
input[type=submit] {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover {
background-color: #45a049;
}
</style>
</head>
<body bgcolor= #cfd1d3>
<div class="row " style="background-color: #f1f1f1">
<div class="header">
<div class="header" style="float:left;">
<?php
echo " welcome " ;
echo $e;
?>
</div>
<div class="header" style="float: right;">
<a href=logout.php>logout</a>
</div>
</div>
</div>
<div class="row">
<div class="header">
<a href="index.php"> <img src="banner.png" height=44% width=100%></a>
</div>
</div>
<div class="row">
<div class="column side" style="height: 350px; overflow: hidden;">
<div class="topnav" >
<div style="background-color:#434547; border: 2px solid white; border-radius: 1em;">
<h2 ><center><font color="white">Navigation Bar</font></center></h2>
</div>
<p><a href=two.php>click here to see stock of company side by side</a></p>
<p><a href=analysis_a.php>click here to see analysis of company by observing history</a></p>
<p><a href=account.php>click here to edit details of account</a></p><br>
</div>
</div>
<div class="column middle" style=" height: 350px;" >
<div style=" margin: auto; width: 90%;">
<div>
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for companies click on them to add" title="Type in a name">
</div>
<div style="overflow-y: scroll; height: 250px;">
<ul id="myUL">
<?php
$key=$_GET['key'];
$array = array();
$con=mysqli_connect('sql308.byethost11.com','b11_18001806','eshu@123','b11_18001806_dbms');
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$query=mysqli_query($con,"select * from company ");
while($row=mysqli_fetch_assoc($query))
{
$s="form.php?code=".$row['code'];
?>
<li><a href="<?php echo $s ?>"><?php echo $row['name'] ?></a></li>
<?php
}
?>
</ul>
</div>
</div>
</div>
<div class="column side" style=" height:350px;">
<div style=" margin: 7px; background-color: white; ">
<div style="background-color: #434547; border: 2px solid white; border-radius: 1em;">
<center><font color="white"><h2 >Your installed companies:</h2>Select the company to see stock</font></center>
</div>
<div style="height: 250px;overflow-y: scroll;">
<?php
$con=mysqli_connect('sql308.byethost11.com','b11_18001806','eshu@123','b11_18001806_dbms');
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$e=$_SESSION["user"];
$query=mysqli_query($con,"select * from com where username = '$e'");
while($row=mysqli_fetch_assoc($query))
{
?>
<p>
<form action="individualcompany.php" method="post">
<input name="code" type="hidden" value=" <?php echo $row["code"] ; ?>" >
<input type=submit value=" <?php echo htmlspecialchars($row["code"]) ; ?>" >
</form>
</p>
<?php
}
?>
</div>
</div>
</div>
</div>
</body>
</html>