Repository navigation
Expand file tree
/
Copy pathindex.php
More file actions
289 lines (241 loc) · 9.95 KB
/
Copy pathindex.php
File metadata and controls
289 lines (241 loc) · 9.95 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
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Bootstrap CSS -->
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6"
crossorigin="anonymous"
/>
<!-- Bootstrap JavaScript plugins-->
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.1/dist/umd/popper.min.js" integrity="sha384-SR1sx49pcuLnqZUnnPwx6FCym0wLsk5JZuNx2bPPENzswTNFaQU1RDvt3wT4gWFG" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.min.js" integrity="sha384-j0CNLUeiqtyaRmlzUHCPZ+Gy5fQu0dQ6eZ/xAww941Ai1SxSY+0EQqNXNE6DZiVc" crossorigin="anonymous"></script>
<!-- myStyle.css contains the customised styling for this site-->
<link rel="stylesheet" href="myStyle.css" type="text/css" />
<title>The Fidgets Shop</title>
</head>
<body>
<!-- Bootstrap navbar with a sticky top. The default background colour is coral.
It contains:
1. a rounded corner logo that has a shadow effect.
2: a login button that calls a modal login form. The login is hardcoded: 'user' with password 'pass'.
3. a 'pick a colour select element' that is populated using a javascript array and loop
-->
<nav
class="navbar navbar-expand-lg navbar-light sticky-top"
style="background-color: coral"
>
<div class="container-fluid">
<a class="navbar-brand" href="index.php"
><img id=logo src="images/logo.jpg"
/></a>
<button
class="navbar-toggler"
type="button"
data-bs-toggle="collapse"
data-bs-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
</ul>
<!-- select options are populated from an array called 'myArray'. When the colour is changed it calls javascript
function 'changeNavByColour()' -->
<label>Pick a colour: </label>
<select class="form-select" id="selectColour" style="margin-right: 30px; width: auto;" onchange="changeNavBgColour()">
<script>
var myArray = ["coral", "silver", "plum", "cyan", "lime", "tan", "pink", "yellow", "blue"];
for (i = 0; i < myArray.length; i++) {
document.write(
'<option value="' +
myArray[i] +
'">' +
myArray[i] +
"</option>"
);
}
</script>
</select>
<button
type="button"
class="btn btn-secondary"
data-bs-toggle="modal"
data-bs-target="#loginModal"
>
Log In
</button>
</div>
</div>
</nav>
<!-- Bootstrap modal login form. it fades in from the top and contains the logo
It calls two javascript functions:
1. validateForm() is triggered when the 'Log in' button is clicked. It checks if the login match (user and pass)
2. clearErrorMsg() is called when 'Reset' or 'Close' is clicked. It clears the form and message.
If the user logs in successfully then he/she is taken to the shop.php page -->
<div
class="modal fade"
id="loginModal"
tabindex="-1"
aria-labelledby="exampleModalLabel"
aria-hidden="true"
>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<img src="images/logo.jpg">
<h3 class="modal-title" id="exampleModalLabel">Log In</h3>
<button
type="button"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Close"
></button>
</div>
<div class="modal-body">
<!-- if the validateForm() returns true then the shop.php page is called -->
<form name="loginForm" action="shop.php" onsubmit="return validateForm()" >
<div class="mb-3">
<label for="uname" class="form-label">Username</label>
<input
type="text"
class="form-control"
id="uname"
name="uname"
placeholder="Enter username"
required
/>
</div>
<div class="mb-3">
<label for="psw" class="form-label">Password</label>
<input
type="password"
class="form-control"
id="psw"
name="psw"
placeholder="Enter password"
required
/>
</div>
<!-- if there is an error message it will be displayed in this label in the modal-->
<div><label id="errorMsg" name="errorMsg"></label></div>
</div>
<div class="modal-footer">
<!-- -->
<button
type="button"
class="btn btn-secondary"
onclick="clearErrorMsg()"
>
Reset
</button>
<button
type="button"
class="btn btn-secondary"
data-bs-dismiss="modal"
onclick="clearErrorMsg()"
>
Close
</button>
<button
type="submit"
class="btn btn-primary"
>
Log in
</button>
</div>
</form>
</div>
</div>
</div>
<!-- main content of page- holds the slideshow-->
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<!--slide show-->
<br /><br />
<!-- Slideshow container -->
<div class="slideshow-container" >
<!-- Full-width images with number and caption text -->
<div class="mySlides sFade">
<div class="numbertext">1 / 3</div>
<img src="images/Carousel/carsouselPic1.jpg" style="width:100%;">
<div class="textSlide">One stop shop for the latest fidget toys! Log in and enjoy!</div>
</div>
<div class="mySlides sFade">
<div class="numbertext">2 / 3</div>
<img src="images/Carousel/carsouselPic2.jpg" style="width:100%">
<div class="textSlide">Log in and see the lastest fidget toys at great prices!</div>
</div>
<div class="mySlides sFade">
<div class="numbertext">3 / 3</div>
<img src="images/Carousel/carsouselPic3.jpg" style="width:100%">
<div class="textSlide">Log in to find on trend fidget toys!</div>
</div>
</div>
<!-- END of slideshow component-->
</div>
</div>
</div>
<!--page footer -->
<?php
include 'footer.php';
?>
<!-- END of page footer -->
<script>
//login form validation
function validateForm() {
//Access the username and password variable
var uName = document.forms["loginForm"]["uname"].value;
var pw = document.forms["loginForm"]["psw"].value;
//check if match correct details
if (uName == "user" && pw == "pass"){
sessionStorage.user = "Mike";
return true;
}
else {
// use DOM to display an error message in the modal
document.getElementById('errorMsg').innerHTML = "Incorrect login details! Please try again.";
return false;
}
}
//start slide show on random slide when site entered/refreshed
var slideIndex = Math.floor(Math.random() * 3); ;
//Automatic Slideshow functions showSlides taken from https://www.w3schools.com/
showSlides();
//takes the randomly set slideIndex from above from https://www.w3schools.com/
function showSlides() {
var i;
var slides = document.getElementsByClassName("mySlides");
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slideIndex++;
if (slideIndex > slides.length) {slideIndex = 1}
slides[slideIndex-1].style.display = "block";
setTimeout(showSlides, 5000); // Change image every few seconds
}
//clear any error messages from the modal login and reset the form
function clearErrorMsg(){
document.getElementById('errorMsg').innerHTML = "";
document.forms["loginForm"]["uname"].value = "";
document.forms["loginForm"]["psw"].value = "";
}
//change the navbar colour depending on the value selected in the selectColour dropdown list
function changeNavBgColour() {
var colour = document.getElementById("selectColour").value;
sessionStorage.navColour = colour;
document.getElementsByTagName("nav")[0].style.backgroundColor = colour;
}
//set some session info nav background colour and the user is set to 'Mike'
sessionStorage.navColour = document.getElementsByTagName("nav")[0].style.backgroundColor;
</script>
</body>
</html>