-
Notifications
You must be signed in to change notification settings - Fork 0
/
listIndex.php
319 lines (296 loc) · 10.5 KB
/
listIndex.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
<?php
session_start();
if (!isset($_GET['page']) || !isset($_GET['pageNumber'])) {
header('Location:listIndex.php?page=all&pageNumber=1');
}
$page = $_GET['page'];
$pageNumber = $_GET['pageNumber'];
if($page != '5' && $page != '10' && $page != '20' && $page != 'all') {
header('Location:listIndex.php?page=all&pageNumber=1');
} else if ($pageNumber > 100 || $pageNumber < 0) {
header('Location:listIndex.php?page=all&pageNumber=1');
} else if ($pageNumber == '') {
header('Location:listIndex.php?page=all&pageNumber=1');
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Shanasahugh Soundboard</title>
<link rel="stylesheet" href="index.css">
<style type="text/css">
#content > div {
height: 120px;
}
.modal {
max-height: 100%;
position: fixed;
background-color: #4ea0ed;
border-radius: 15px;
left: 50%;
top: 50%;
text-align: center;
box-shadow: 3px 5px 5px #555;
padding-right: 20px;
padding-left: 20px;
}
#modal_login {
transform: translate(-50%, -50%);
}
#modal_signup {
transform: translate(-50%, -50%);
}
.modal > .close {
font-size: 48px;
float: right;
cursor: pointer;
}
.modal > .close:hover {
color: #FFF;
}
.modal > h1 {
margin: 20px;
font-size: 48px;
}
.modalForm > input {
margin: 10px;
border-radius: 10px;
border: 2px solid black;
padding: 5px;
font-size: 30px;
cursor: pointer;
}
@media screen and (min-width: 1106px) {
.modal {
width: 50%;
}
.modalForm > input {
width: 40%;
}
}
@media screen and (min-width: 985px) and (max-width: 1105px) {
.modal {
width: 70%;
}
.modalForm > input {
width: 60%;
}
}
@media screen and (min-width: 469px) and (max-width: 984px) {
.modal {
width: 80%;
}
.modalForm > input {
width: 50%;
}
}
@media screen and (max-width: 468px) {
.modal {
width: 80%;
}
.modalForm > input {
width: 60%;
font-size: 26px;
}
}
.submit {
background-color: #999;
}
.submit:hover {
background-color: #589;
}
.userControls {
color: #000;
}
.userControls:hover {
color: #FFF;
}
.boardTitle {
font-size: 26px;
}
</style>
</head>
<body>
<div class="modal" id="modal_signup" style='display: none;'>
<span class="close">×</span>
<h1>Sign Up! It's Free!</h1>
<form class="modalForm" id="signUpForm" action= 'dosignup.php' method= 'post'>
<input type= 'text' name= 'fname' placeholder="First name" maxlength= '20' required><br>
<input type= 'text' name= 'lname' placeholder="Last name" maxlength= '30' required><br>
<input type= 'text' name= 'email' placeholder="Email address" maxlength= '40' required><br>
<input type= 'text' name= 'username' placeholder="Username" maxlength= '20' required><br>
<input type= 'password' name= 'password' placeholder="Password" maxlength= '30' required><br>
<input class="submit" type= 'submit' value= 'Submit'>
<p><?= isset($_SESSION['signup_error'])?$_SESSION['signup_error']:"" ?></p>
</form>
</div>
<div class="modal" id="modal_login" style='display: none;'>
<span class="close">×</span>
<h1>Login</h1>
<form class="modalForm" id="loginForm" action= 'dologin.php' method= 'post'>
<input type= 'text' name= 'username' placeholder="Username" maxlength= '20' required>
<input type= 'password' name= 'password' placeholder="Password" maxlength= '30' required>
<input class="submit" type= 'submit' value= 'Log In'>
<p><?= isset($_SESSION['login_error'])? $_SESSION['login_error']:"" ?></p>
</form>
</div>
<div id="heading">
<p>Shanasahugh Soundboards</p>
<?php
if (isset($_SESSION["allowed"])&&$_SESSION['allowed']) {
echo "<span><p><a href='logout.php'>Logout</a></p></span>";
echo "<span><p><a href='myboards.php?page=all&pageNumber=1'>My Boards</a></p></span>";
} else {
echo "<span><p class=\"userControls\" id=\"signup\">Sign Up</p></span>
<span><p class=\"userControls\" id=\"login\">Login</p></span>";
}
?>
</div>
<div id="content">
<?php
echo "
<p>
<button id= 'changeView'>Change the view</button>
<form id= 'changePage' action= 'listIndex.php' method='get'>
<select id= 'choosePage' name= 'page'>
<option value= 'all' "; if ($page == 'all') {echo "selected";} echo ">All</option>
<option value= '5' "; if ($page == '5') {echo "selected";} echo ">5</option>
<option value= '10' "; if ($page == '10') {echo "selected";} echo ">10</option>
<option value= '20' "; if ($page == '20') {echo "selected";} echo ">20</option>
</select>
<input type= 'hidden' name= 'pageNumber' value= '1'>
</form>
</p>";
require_once 'helperscripts/config.inc';
$sql = "select COUNT(title) as total from boards where public= '1'";
$result = mysqli_query($link, $sql);
if($result) {
$row = mysqli_fetch_assoc($result);
$total = $row['total'];
}
if($page == 'all') {
$sql="select title from Boards where public = '1'";
}
else if($total > $page) {
$lowerBound = $page * ($pageNumber - 1);
$pages = min ($page, $total);
$sql="select title from Boards where public = '1' limit $lowerBound, $pages";
echo "<form id= 'pageChange' action= 'listIndex.php' method = 'get'>
<input type = 'hidden' name= 'page' value = $page>
<input id = 'pageNumber' type= 'hidden' name= 'pageNumber'>";
if($lowerBound == 0) {
echo"<button id = 'prev' style= 'visibility: hidden'>Prev</button>";
echo"<button id = 'next' style = 'visibility: visible'>Next</button>";
}
else if($upperBound == $total || $total - ($page * ($pageNumber - 1)) < $page) {
echo"<button id = 'prev' style = 'visibility: visible'>Prev</button>";
echo"<button id = 'next' style= 'visibility: hidden'>Next</button>";
} else {
echo"<button id = 'prev' style = 'visibility: visible'>Prev</button>";
echo"<button id = 'next' style= 'visibility: visible'>Next</button>";
}
echo"</form>";
}
else if($total <= $page) {
$sql="select title from Boards where public = '1'";
}
$result = mysqli_query($link, $sql);
if ($result) {
while($row=mysqli_fetch_assoc($result)) {
$title = $row['title'];
echo "<div class='sBoardDiv' style = 'display: block; margin: 20px auto;'>
<p class='boardTitle'>$title</p>
<form action='publicboard.php' method='get'>
<input type='hidden' name='title' value='$title'>
<input type='hidden' name='page' value='all'>
<input type='hidden' name='pageNumber' value='1'>
</form>
</div>";
}
}
?>
</div>
<footer>© Shanasahugh 2017</footer>
<script type="text/javascript">
window.onload = function() {
var boards = document.querySelectorAll('#content > div');
var modal_signup = document.querySelector('#modal_signup');
var modal_login = document.querySelector('#modal_login');
var closeButtonSignup = document.querySelector('#modal_signup > .close');
var closeButtonLogin = document.querySelector('#modal_login > .close');
var signup = document.querySelector('#signup');
var login = document.querySelector('#login');
var changeView = document.querySelector('#changeView');
var changePage = document.querySelector('#changePage');
var choosePage = document.querySelector('#choosePage');
var pageChange = document.querySelector('#pageChange');
var pageNumber = document.querySelector('#pageNumber');
var prevBtn = document.querySelector('#prev');
var nextBtn = document.querySelector('#next');
changeView.addEventListener('click', function() {
window.location = 'index.php?page=all&pageNumber=1';
});
choosePage.onchange = function() {
changePage.submit();
};
<?php
echo "
if(prevBtn) {
prevBtn.addEventListener('click', function() {
pageNumber.value = $pageNumber-1;
pageChange.submit();
});
}
if(nextBtn) {
nextBtn.addEventListener('click', function() {
pageNumber.value = $pageNumber+1;
pageChange.submit();
});
}";
?>
for (var index = 0; index < boards.length; index++) {
boards[index].addEventListener('click', function() {
if (login && signup) {
if (!(modal_signup.style.display == 'block') &&
!(modal_login.style.display == 'block')) {
this.querySelector('form').submit();
}
} else {
this.querySelector('form').submit();
}
});
}
if (signup) {
signup.addEventListener('click', function() {
if (!(modal_login.style.display == 'block')) {
if (modal_signup.style.display == 'none') {
modal_signup.style.display = 'block';
} else {
modal_signup.style.display = 'none';
}
}
});
closeButtonSignup.addEventListener('click', function() {
modal_signup.style.display = 'none';
});
}
if (login) {
login.addEventListener('click', function() {
if (!(modal_signup.style.display == 'block')) {
if (modal_login.style.display == 'none') {
modal_login.style.display = 'block';
} else {
modal_login.style.display = 'none';
}
}
});
closeButtonLogin.addEventListener('click', function() {
modal_login.style.display = 'none';
});
}
};
</script>
</body>
</html>