-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathportfolio.php
More file actions
118 lines (101 loc) · 3.93 KB
/
portfolio.php
File metadata and controls
118 lines (101 loc) · 3.93 KB
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
<!-- http://clipart-library.com/clip-art/coming-soon-transparent-17.htm -->
<?php
// Initialize session
session_start();
// Require files
require_once 'config.php';
require_once 'db-classes.php';
// Connection to databases
$conn = DatabaseHelper::createConnection(array(DBCONNSTRING, DBUSER, DBPASS));
$hdb = new HistoryDB($conn);
$pdb = new PortfolioDB($conn);
$phcdb = new PortfolioHistoryCompanyDB($conn);
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./css/mycss.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" />
</head>
<body>
<nav>
<input type="checkbox" id="check">
<label for="check" class="checkbtn">
<i class="fas fa-bars"></i>
</label>
<a class="active" href="index.php"><label class="logo"><img id="stockifylogo" src="images/stockify.png" alt="stockify" width="50" height="50"></label></a>
<ul>
<?php
// Change website layout depending on session status
if (isset($_SESSION['loggedin-status'])) {
echo "<li><a href='index.php'>Home</a></li>
<li><a href='about.php'>About</a></li>
<li><a href='list.php'>Companies</a></li>
<li><a class='active' href='portfolio.php'>Portfolio</a></li>
<li><a href='profile.php'>Profile</a></li>
<li><a href='favorites.php'>Favorites</a></li>
<li>
<form method='post'>
<button id='hamburgerLogout' type='hidden' name='logout' value='Logout'>Logout</button>
</form>
</li>";
} else {
echo "<li><a href='index.php'>Home</a></li>
<li><a href='about.php'>About</a></li>
<li><a href='list.php'>Companies</a></li>
<li><a href='login.php'>Login</a></li>";
}
// End the session and clears the session variables
if (isset($_POST['logout'])) {
$_SESSION = array();
session_destroy();
header("Location: index.php");
}
?>
</ul>
</nav>
<h1>PORTFOLIO</h1>
<section class="mainSection">
<table id='stockDataTableHeader'>
<?php
// Markup for portfolio
echo "<tr>";
echo "<th></th>";
echo "<th class='PortHeader' id='symbol'>Symbol</th>";
echo "<th class='PortHeader' id='name'>Name</th>";
echo "<th class='PortHeader' id='shares'>Number of Shares</th>";
echo "<th class='PortHeader' id='close'>Close Value</th>";
echo "<th class='PortHeader' id='value'>Value of Shares</th>";
echo "</tr>";
// Fills portfolio with user specific information
if (isset($_SESSION['user-id'])) {
$uID = $_SESSION['user-id'];
$port = $pdb->getAllForUser($uID);
$portfolioValue = 0;
$errorCheck = false;
foreach ($phcdb->getAllForUser($uID) as $row) {
if ($row['userId'] == $uID) {
$highest = $hdb->getLatestForSymbol($row['symbol']);
echo "<tr>";
echo "<td><img src='./logos/" . $row['symbol'] . ".svg' width='37px' height='50px'></td>";
echo "<td >" . $row['symbol'] . "</td>";
echo "<td >" . $row['name'] . "</td>";
echo "<td >" . $row['amount'] . "</td>";
$x = number_format($highest[0]['close'], 2, '.', ',');
echo "<td >" . $x . "</td>";
$value = $row['amount'] * $highest[0]['close'];
echo "<td >" . number_format($value) . "</td>";
echo "</tr>";
$portfolioValue += $value;
}
}
}
$pdo = null;
echo "<tr><td></td><td></td><td></td><td></td><td></td><td>Total Portfolio Value: " . number_format($portfolioValue, 2, '.', ',') . "</td></tr>";
echo "</table>";
?>
</section>
</body>
</html>