-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuid.php
More file actions
407 lines (376 loc) · 18.4 KB
/
Copy pathbuid.php
File metadata and controls
407 lines (376 loc) · 18.4 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
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/build.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<title>Desktop Designer</title>
<link rel="icon" type="image/x-icon" href="images/pcIcon.jpg">
<link rel="stylesheet" href="css/buid.css">
<link rel="stylesheet" href="css/common-styles.css">
</head>
<body>
<main>
<nav class="py-2 bg-body-tertiary border-bottom">
<div class="container d-flex flex-wrap">
<!-- Unneeded ul -->
<ul class="nav me-auto">
<li class="nav-item">
<a href="index.php"><img src="images/pcIcon.jpg" alt="PC Icon" class="icon"></a>
<a href="index.php" class="fs-4 nav-link link-body-emphasis px-2 active"
aria-current="page">Desktop
Designer</a>
</li>
</ul>
<ul class="nav align-items-center">
<div class="username"> <?php function getProfilePic($username)
{
// Your database connection code goes here
$servername = "localhost:3306"; // Change this to your database server hostname
$username_db = "hc920_1"; // Change this to your database username
$password = "PC_PARTS_BRIGHTON"; // Change this to your database password
$dbname = "hc920_pc_parts"; // Change this to your database name
// Create connection
$conn = new mysqli($servername, $username_db, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Query the database for the user's profile picture
$query = "SELECT profilePic FROM tblUsers WHERE Username = '$username'";
$result = $conn->query($query);
// Return the profile picture if it exists, otherwise return null
if ($result && $result->num_rows > 0) {
$row = $result->fetch_assoc();
$profilePic = $row['profilePic'];
} else {
$profilePic = null;
}
// Close the database connection
$conn->close();
return $profilePic;
}
if (isset($_COOKIE['username'])) {
// Display username
echo '<span class="username">' . $_COOKIE['username'] . '</span>';
// Get the user's profile picture
$profilePic = getProfilePic($_COOKIE['username']);
// Display profile icon
echo '
<!-- Trigger the Modal -->
<img id="myImg" src="images/userIcon/icon' . $profilePic . '.jpg" alt="Profile Picture">
<!-- The Modal -->
<div id="myModal2" class="modal">
<!-- The Close Button -->
<span class="close">×</span>
<!-- Modal content -->
<div class="modal-content">
<h2>User Profile</h2>
<div class="user-info">
<img src="images/userIcon/icon' . $profilePic . '.jpg" alt="Profile Picture">
<div>
<span class="nameuser">' . $_COOKIE['username'] . '</span>
<a href="#" class="logout-button" onclick="signOut()">Sign Out</a>
</div>
</div>
</div>
</div>
';
} else {
// Display login and signup buttons
echo '<a href="login.php" class="nav-link link-body-emphasis px-2"><i class="fa fa-fw fa-user"></i>Login</a>';
echo '<a href="signup.php" class="nav-link link-body-emphasis px-2">Sign up</a>';
}
?>
<div class="modal fade" id="my-modal" tabindex="-1" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="btn-close" data-mdb-dismiss="modal"
aria-label="Close"></button>
</div>
<div class="modal-body">
Name: <span id="modal-name"></span>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary"
data-mdb-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>
</ul>
</div>
</nav>
<nav class="py-2 bg-body-tertiary border-bottom">
<div class="container d-flex flex-wrap">
<ul class="nav me-auto">
<li class="nav-item"><a href="buid.php" class="nav-link link-body-emphasis px-2 active"
aria-current="page">Build</a></li>
<li class="nav-item"><a href="prebuilt.php" class="nav-link link-body-emphasis px-2 active"
aria-current="page">Prebuilt</a></li>
<li class="nav-item"><a href="help.php" class="nav-link link-body-emphasis px-2 active"
aria-current="page">Help</a></li>
</ul>
</div>
</nav>
<section class="py-5 text-center container">
<div class="row py-lg-5">
<div class="col-lg-6 col-md-8 mx-auto">
<h1 class="fw-light">Build Your PC</h1>
<p class="lead text-body-secondary">Something short and leading about the collection
below—its contents, the creator, etc. Make it short and sweet, but not too short
so folks do not simply skip over it entirely.</p>
</div>
</div>
</section>
<!-- bruuuh -->
<div class="table-section">
<div id="navbar">
<a id="import">Import</a>
<a id="export">Export</a>
<a>Total:</a>
<a id="price"></a>
<a id="remove-all">Clear</a>
</div>
<p></p>
<div class="content">
<table>
<thead>
<tr>
<th>Part</th>
<th>Add</th>
<th>Item</th>
<th>Price</th>
<th>Remove</th>
</tr>
</thead>
<tbody>
<!-- Row 1 -->
<tr>
<td>CPU</td>
<td><button class="director cpu"><a>Add</a></button></td>
<td class="cpu">No part added yet.</td>
<td class="price" id="cpu"></td>
<td><button class="remove cpu">X</button></td>
</tr>
<!-- Row 2 -->
<tr>
<td>CPU cooler</td>
<td><button class="director cpu-cooler"><a>Add</a></button></td>
<td class="cpu-cooler">No part added yet.</td>
<td class="price" id="cpu-cooler"></td>
<td><button class="remove cpu-cooler">X</button></td>
</tr>
<!-- Row 3 -->
<tr>
<td>Motherboard</td>
<td><button class="director motherboard"><a>Add</a></button></td>
<td class="motherboard">No part added yet.</td>
<td class="price" id="motherboard"></td>
<td><button class="remove motherboard">X</button></td>
</tr>
<!-- Row 4 -->
<tr>
<td>Memory</td>
<td><button class="director memory"><a>Add</a></button></td>
<td class="memory">No part added yet.</td>
<td class="price" id="memory"></td>
<td><button class="remove memory">X</button></td>
</tr>
<!-- Row 5 -->
<tr>
<td>Storage</td>
<td><button class="director external-hard-drive"><a>Add</a></button></td>
<td class="external-hard-drive">No part added yet.</td>
<td class="price" id="external-hard-drive"></td>
<td><button class="remove external-hard-drive">X</button></td>
</tr>
<!-- Row 6 -->
<tr>
<td>Video card</td>
<td><button class="director video-card"><a>Add</a></button></td>
<td class="video-card">No part added yet.</td>
<td class="price" id="video-card"></td>
<td><button class="remove video-card">X</button></td>
</tr>
<!-- Row 7 -->
<tr>
<td>Case</td>
<td><button class="director case"><a>Add</a></button></td>
<td class="case">No part added yet.</td>
<td class="price" id="case"></td>
<td><button class="remove case">X</button></td>
</tr>
<!-- Row 8 -->
<tr>
<td>Power supply</td>
<td><button class="director power-supply"><a>Add</a></button></td>
<td class="power-supply">No part added yet.</td>
<td class="price" id="power-supply"></td>
<td><button class="remove power-supply">X</button></td>
</tr>
<!-- Row 9 -->
<tr>
<td>Operating system</td>
<td><button class="director os"><a>Add</a></button></td>
<td class="os">No part added yet.</td>
<td class="price" id="os"></td>
<td><button class="remove os">X</button></td>
</tr>
<!-- Row 10 -->
<tr>
<td>Monitor</td>
<td><button class="director monitor"><a>Add</a></button></td>
<td class="monitor">No part added yet.</td>
<td class="price" id="monitor"></td>
<td><button class="remove monitor">X</button></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="container">
<footer class="d-flex flex-wrap justify-content-between align-items-center py-3 my-4 border-top">
<p class="col-md-4 mb-0 text-body-secondary">© 2024 Desktop Designer</p>
<!-- Middle section with the clickable image -->
<a href="index.php"
class="col-md-4 d-flex align-items-center justify-content-center mb-3 mb-md-0 me-md-auto link-body-emphasis text-decoration-none">
<!-- Inserting the PC icon here -->
<img src="images/pcIcon.jpg" alt="PC Icon" class="icon">
</a>
<ul class="nav col-md-4 justify-content-end">
<li class="nav-item"><a href="index.php" class="nav-link px-2 text-body-secondary">Home</a></li>
<li class="nav-item"><a href="buid.php" class="nav-link px-2 text-body-secondary">Build</a></li>
<li class="nav-item"><a href="prebuilt.php" class="nav-link px-2 text-body-secondary">Prebuilt</a>
</li>
<li class="nav-item"><a href="help.php" class="nav-link px-2 text-body-secondary">Help</a></li>
</ul>
</footer>
</div>
</main>
<script>
window.onscroll = function () { myFunction() };
function myFunction() {
if (window.scrollY >= sticky) {
navbar.classList.add("sticky")
} else {
navbar.classList.remove("sticky");
}
}
window.addEventListener("load", () => {
// lazy button event assign Zzz
for (let i = 0; i < directors.length; i++) {
const selected = directors[i];
const remover = removers[i];
selected.addEventListener("click", () => {
directTo(selected.getAttribute("class").split(" ")[1]);
})
// part2 Electric removaloo.
remover.addEventListener("click", () => {
localStorage.removeItem(remover.getAttribute("class").split(" ")[1]);
// refresh the table aka the page
location.reload();
})
}
})
// export your local storage to somewhere else
document.getElementById("export").addEventListener("click", () => {
localStorage.removeItem("selecting");
navigator.clipboard.writeText(JSON.stringify(localStorage));
alert("Copied build to clipboard");
})
// import a build
document.getElementById("import").addEventListener("click", async () => {
let loaded = navigator.clipboard.readText();
try {
let result = JSON.parse(await loaded);
Object.entries(result).forEach((k) => {
// Ide is shouting at me but it works!
localStorage.setItem(k[0], k[1]);
location.reload();
})
} catch (error) {
alert(error);
}
})
// clear the current
document.getElementById("remove-all").addEventListener("click", () => {
localStorage.clear();
location.reload();
})
const navbar = document.getElementById("navbar");
const sticky = navbar.offsetTop;
const removers = document.getElementsByClassName("remove");
const directors = document.getElementsByClassName("director");
// load stored data from other pages
window.addEventListener("load", () => {
Object.keys(localStorage).forEach((key) => {
// whitelist the desirable :)
switch (key) {
case "cpu":
case "cpu-cooler":
case "motherboard":
case "memory":
case "external-hard-drive":
case "video-card":
case "case":
case "power-supply":
case "os":
case "monitor":
const retrievedSlice = JSON.parse(localStorage.getItem(key))
document.querySelector("td." + key).innerText = retrievedSlice.name;
document.querySelector("td.price#" + key).innerText = retrievedSlice.price;
break
default:
console.log("caught a stray!" + key);
}
})
// sum prices
let total = 0;
document.querySelectorAll("td.price").forEach(v => total += Number(v.innerText));
document.querySelector("a#price").innerText = "£" + total;
})
// smart code to basically send the correct data to the part-select page to load its Jsons etc
function directTo(direction) {
localStorage.setItem("selecting", direction);
location.href = "partPages/part_select.php";
}
document.addEventListener('DOMContentLoaded', function () {
// Get the modal
var modal = document.getElementById("myModal");
// Get the image that opens the modal
var IMG = document.getElementById("myImg");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks the image, open the modal
IMG.onclick = function () {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function () {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function (event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
});
function signOut() {
// Delete the username cookie
document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/";
// Redirect to the login page
window.location.href = "login.php";
}
</script>
</body>
</html>