-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfavorites.php
More file actions
125 lines (107 loc) · 3.96 KB
/
favorites.php
File metadata and controls
125 lines (107 loc) · 3.96 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
119
120
121
122
123
124
125
<?php
// Initialize session
session_start();
// Reguired files
require_once 'config.php';
require_once 'db-classes.php';
// Connection to database
$conn = DatabaseHelper::createConnection(array(DBCONNSTRING, DBUSER, DBPASS));
$cdb = new CompanyDB($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 href='portfolio.php'>Portfolio</a></li>
<li><a href='profile.php'>Profile</a></li>
<li><a class='active' 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>FAVORITES</h1>
<section class="mainSection">
<?php
// Getting the user's favorited companies and outputting the markup
if (isset($_GET['fav'])) {
$sybo = isset($_SESSION['sy']) ? $_SESSION['sy'] : array();
$sybo[] = $_GET['fav'];
$_SESSION['sy'] = $sybo;
$symbo = array_unique($_SESSION['sy']);
}
if (sizeof($_SESSION['sy']) > 0) {
$sybo = isset($_SESSION['sy']) ? $_SESSION['sy'] : array();
$_SESSION['sy'] = $sybo;
$symbo = array_unique($_SESSION['sy']);
foreach ($symbo as $i => $s) {
foreach ($cdb->getAllForSymbol($s) as $row) {
$index = 0;
echo "<li class='companyListItem'>";
echo "<div><img src='./logos/" . $row['symbol'] . ".svg' id='favouritesCompanyLogo'></div>";
echo "<div id='favouritesCompanySymbol'><a href='single-company.php?symbol=" . $row['symbol'] . "'>" . $row['symbol'] . "</a></div>";
echo "<div id='favouritesCompanyName'><a href='single-company.php?symbol=" . $row['symbol'] . "'>" . $row['name'] . "</a></div>";
echo "</br>";
echo "<form action='favorites.php'>
<button class='removeButton' name='re' value='" . $row['symbol'] . "' type='submit'>Remove</button>
</form>";
echo "</li>";
echo "</br>";
}
}
echo "<form action='favorites.php'>
<input id='removeAllButton' type='submit' name='submit' value='Remove All'>
</form>";
if (isset($_GET['re'])) {
foreach ($_SESSION['sy'] as $i => $s) {
if ($_GET['re'] == $s) {
unset($_SESSION['sy'][$i]);
}
}
print_r($symbo);
header('Location: favorites.php');
}
} else {
echo "No Favorites yet!";
}
if (isset($_GET['submit'])) {
$_SESSION['sy'] = [];
header('Location: favorites.php');
}
?>
</section>
</body>
</html>