-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
521 lines (436 loc) · 19.9 KB
/
search.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
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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
<?php
session_start();
if(!isset($_SESSION['email'])) {
//header("Location: signin.php");
}
else{
//session variables for default login
$id = $_SESSION['user'];
$user = $_SESSION['username'];
$lastname = $_SESSION['lastname'];
$firstname = $_SESSION['firstname'];
$fullname = $firstname." ".$lastname;
$email = $_SESSION['email'];
$profile_image = $_SESSION['profile_image'];
}
require 'dbconn.php';
$errorss = array();
$successs = array();
//if suscribe button is clicked
if (isset($_POST['subscribe'])) {
$name = $_POST['name'];
$subscriber_email = $_POST['subscriber_email'];
$website = $_POST['website'];
$postingdate = date("Y-m-d H:i:s", time());
if ($name === "" || $subscriber_email === "") {
$errorss['pass'] = "the name and email field are both required";
}
$query = mysqli_query($conn, "SELECT email FROM subscribers WHERE email='$subscriber_email'");
if(mysqli_num_rows($query) > 0){
$errorss['pass'] = "Hi, you've already subscribed";
}else{
$sql = 'INSERT INTO subscribers(name, email, website, PostingDate) VALUES(:name, :email, :website, :postingdate)';
$statement = $connection->prepare($sql);
if ($statement->execute([':name' => $name, ':email' => $subscriber_email, ':website' => $website, ':postingdate' => $postingdate])) {
$successs['data'] = 'Subscribed successfully';
}else{
$errorss['data'] = 'Ooops, an error occured';
}
}
}
$sql = 'SELECT * FROM affiliate WHERE Is_Active=1';
$statement = $connection->prepare($sql);
$statement->execute();
$affiliate = $statement->fetchAll(PDO::FETCH_ASSOC);
$sql = 'SELECT * FROM announcement WHERE Is_Active=1';
$statement = $connection->prepare($sql);
$statement->execute();
$announcement = $statement->fetchAll(PDO::FETCH_ASSOC);
function timeago($time, $tense='ago'){
static $periods = array('year', 'month', 'day', 'hour', 'minute', 'second');
if (!(strtotime($time)>0)) {
//return trigger_error("wrong time format: '$time'", E_USER_ERROR);
}
$now = new DateTime('now');
$time = new DateTime($time);
$diff = $now->diff($time)->format('%y %m %d %h %i %s');
$diff = explode(' ', $diff);
$diff = array_combine($periods, $diff);
$diff = array_filter($diff);
$period = key($diff);
$value = current($diff);
if (!$value) {
$period = '';
$tense = '';
$value = 'just now';
}else{
if ($period == 'day' && $value >= 7) {
$period = 'week';
$value = floor($value/7);
}if ($value > 1) {
$period .='s';
}
}
return "$value $period $tense";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>One meta home Page</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div class="container-fluid bg-warning">
<div class="row justify-content-center">
<?php foreach($affiliate as $aff): ?>
<a href="<?php echo $aff["link"]; ?>" target = "_blank" class="btn btn-dark btn-sm text-white mr-2 mt-2 mb-2" alt="<?php echo $aff["alt"]; ?>"><?php echo $aff["alt"]; ?></a>
<?php endforeach; ?>
</div>
</div>
<section class="w-100 shadow-sm bg-dark">
<div class="container-fluid">
<nav class="navbar navbar-expand-xl navbar-light text-white bg-transparent" data-aos="fade-left" data-aos-duration="500">
<a class="navbar-brand" href="index.php">
<img src="img/Logo.png" alt="logo" class="img-responsive" height="100" width="auto">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ml-auto">
<li class="nav-item line">
<a class="nav-link mr-1 text-white font-weight-bold active" href="index.php">Home</a>
</li>
<li class="nav-item line">
<a class="nav-link mr-1 text-white font-weight-bold active" href="#">Trends</a>
</li>
<li class="nav-item line">
<a class="nav-link mr-1 text-white font-weight-bold" href="#">Articles & Updates</a>
</li>
<li class="nav-item line">
<a class="nav-link mr-1 text-white font-weight-bold" href="#">Top Ranks</a>
</li>
<li class="nav-item line">
<a class="nav-link mr-1 text-white font-weight-bold" href="#">Reviews & Ratings</a>
</li>
<li class="nav-item line">
<a class="nav-link mr-1 text-white font-weight-bold" href="#">Genre</a>
</li>
<li class="nav-item line">
<a class="nav-link mb-2 text-white font-weight-bold" href="#">Reports</a>
</li>
<li class="nav-item line">
<a class="nav-link mb-2 text-white font-weight-bold" href="#">Commentaries</a>
</li>
<?php
if(!isset($_SESSION['email'])) {
?>
<li class="nav-item line">
<a class="nav-link mb-2 text-white font-weight-bold" href="signin.php">Signin</a>
</li>
<li class="nav-item line">
<a class="nav-link mb-2 text-white font-weight-bold" href="signup.php">Sign Up</a>
</li>
<?php
}
?>
</ul>
<?php
if(isset($_SESSION['email'])) {
?>
<ul class="navbar-nav ml-auto">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<label for="" class="text-white">Hi,
<?php
echo "$user";
?>
</label>
<?php
if(isset($_SESSION['email'])) {
echo '<img src="img/avatar.jpg" width="40" height="40" class="rounded-circle ml-2">';
}
?>
</a>
<div class="dropdown-menu bg-dark text-white" aria-labelledby="navbarDropdownMenuLink">
<?php
if ($_SESSION['role'] === "admin") {
?>
<a class="dropdown-item text-white bg-transparent" href="admin/index.php">My Account</a>
<?php
}else{
?>
<a class="dropdown-item text-white bg-transparent" href="user/index.php">My Account</a>
<?php
}
?>
<a class="dropdown-item text-white bg-transparent" href="logout.php">Log Out</a>
</div>
</li>
</ul>
<?php
}
?>
</div>
</nav>
</div>
</section>
<div class="container-fluid bg-light">
<div class="row justify-content-center">
<div class="col-lg-12">
<div class="ticker w-100">
<marquee class="news-content mt-3 mb-3">
<?php foreach($announcement as $ann): ?>
<p><?php echo $ann["announcement"]; ?></p>
<?php endforeach; ?>
</marquee>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row justify-content-center">
<div class="col-12 col-md-8 col-lg-7 mt-4 mb-4">
<form class="card card-md shadow" action="search.php" method="post">
<div class="card-body row no-gutters align-items-center">
<div class="col">
<input class="form-control form-control-lg form-control-borderless" name="searchcriteria" type="search" placeholder="Search Articles">
</div>
<!--end of col-->
<div class="col-auto ml-3">
<button class="btn btn-lg btn-dark" type="submit"><i class="fa fa-search"></i></button>
</div>
<!--end of col-->
</div>
</form>
</div>
</div>
</div>
<div class="container-fluid">
<div class="mt-5 mb-5">
<ol class="breadcrumb mb-4 d-block" style="margin-top: 80px;">
<li class="breadcrumb-item active">Article Search Results</li>
</ol>
</div>
<div class="row justify-content-center">
<?php
//if search button is clicked anywhere, select db for a match else echo error
if(isset($_POST['submit'])) {
$searchcriteria = $_POST['searchcriteria'];
$sql = 'SELECT * FROM article WHERE title LIKE :searchcriteria OR author LIKE :searchcriteria OR description LIKE :searchcriteria OR category LIKE :searchcriteria';
$statement = $connection->prepare($sql);
$statement->execute(array(':searchcriteria' => '%'.$searchcriteria.'%'));
$article = $statement->fetchAll(PDO::FETCH_OBJ);
if(sizeof($article) == 0){
echo '<div class="container">
<div class="alert alert-danger text-center">
<li>Oooops... No Record Found.</li>
</div>
</div>
';
}else{
foreach ($article as $art) {
// if a match is found, foreach of the records print them out with the below template
$media = $art->image;
$temp = array();
$media=trim($media, '/,');
$temp = explode(',', $media);
$temp = array_filter($temp);
$images = array();
foreach($temp as $image){
$images[]="article_images/".trim( str_replace(array('[',']') ,"" ,$image ) );
}
?>
<div class="col-lg-3" id="blogs">
<div class="card-deck h-100">
<div class="card row no-gutters border rounded overflow-hidden flex-md-row mb-4 shadow-sm h-md-250 position-relative">
<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block w-100" src="<?php echo $images[0];?>" alt="Card image cap" style=" height: 30vh;">
</div>
<?php
if (sizeof($images) > 1) {
?>
<div class="carousel-item">
<img class="d-block w-100" src="<?php echo $images[1];?>" alt="Card image cap" style=" height: 30vh;">
</div>
<?php
}
?>
<?php
if (sizeof($images) > 2) {
?>
<div class="carousel-item">
<img class="d-block w-100" src="<?php echo $images[2];?>" alt="Card image cap" style=" height: 30vh;">
</div>
<?php
}
?>
</div>
</div>
<div class="card-body text-justify">
<h5 class="card-title article"><b><?php echo $art->title ?></h5></b>
<p class="card-text"><small><b><?php echo $art->catchy_phrase ?>
<p class="card-text"><small><b>Posted by <?php echo $art->author ?>,
<?php
//date_default_timezone_set('Africa/Lagos');
$time_posted = $art->created_on;
$time = date($time_posted); //now
$timeago = timeago($time);
echo $timeago;
?>
</b></small>
<form action="article-details.php" method="post">
<input type="hidden" name="edit_id" value="<?php echo $art->id ?>">
<button type="submit" name="btn_edit" class="btn btn-link btn-sm stretched-link"></button>
</form>
</div>
</div>
</div>
</div>
<?php
}
}
}
?>
</div>
</div>
<div class="container-fluid mt-5 mb-3">
<div class="row justify-content-center">
<div class="col-lg-6">
<div class="card shadow h-auto">
<div class="card-body text-center">
<p class="card-title">Ad will be placed here</p>
</div>
</div>
</div>
</div>
</div>
<div class="footer bg-dark">
<div class="container-fluid">
<div class="row justify-content-center">
<div class="col-lg-4 mt-5">
<a class="navbar-brand" href="index.php">
<img src="img/Logo.png" alt="logo" class="img-responsive" height="100" width="auto">
</a>
<p class="text-white footer-text">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum delenit augue duis dolore te feugait. <a class="text-decoration-none" href="aboutus.php">Read More <i class="fas fa-long-arrow-alt-right"></i></a> </p>
</div>
<div class="col-lg-2 mt-5">
<h3 class="text-white mb-5 text-justify">Explore</h3>
<li class="mb-2 text-white text-justify ml-2"><a href="#" class="text-white">About Us</a></li>
<li class="mb-2 text-white text-justify ml-2"><a href="#" class="text-white">Events</a></li>
<li class="mb-2 text-white text-justify ml-2"><a href="#" class="text-white">Publications</a></li>
<li class="mb-2 text-white text-justify ml-2"><a href="#" class="text-white">Contact</a></li>
</div>
<div class="col-lg-2 mt-5">
<h3 class="text-white mb-5 text-justify">Activities</h3>
<li class="mb-2 text-white text-justify"><a href="" class="text-white">Press Releases</a></li>
<li class="mb-2 text-white text-justify"><a href="" class="text-white">Multimedia</a></li>
<li class="mb-2 text-white text-justify"><a href="" class="text-white">Blog</a></li>
<li class="mb-2 text-white text-justify"><a href="" class="text-white">LSA in the Media</a></li>
</div>
<div class="col-lg-4 mt-5">
<h3 class="text-white mb-5 text-justify">Subscribe</h3>
<?php if (count($errorss) > 0): ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<?php foreach($errorss as $error): ?>
<li class="text-danger"><?php echo $error; ?></li>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if (count($successs) > 0): ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<?php foreach($successs as $succes): ?>
<li class="text-success"><?php echo $succes; ?></li>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<?php endforeach; ?>
</div>
<?php endif; ?>
<form action="search.php" method="post">
<div class="form-group">
<input type="text" class="form-control form-control-sm" name="name" placeholder = "Your name" required value="<?= $fullname ?? '' ?>">
</div>
<div class="form-group">
<input type="email" class="form-control form-control-sm" name="subscriber_email" placeholder = "Your email" required value="<?= $email ?? '' ?>">
</div>
<div class="form-group">
<input type="text" class="form-control form-control-sm" name="website" placeholder = "Your website (Optional)">
</div>
<input type="submit" name="subscribe" class="btn btn-primary btn-sm mb-2" value = "subscribe">
</form>
<p class="text-justify text-white mt-2 mb-2">Get latest updates and offers.</p>
<hr class="bg-white">
<div class="row justify-content-center mt-4 mb-4 text-white">
<a href="" title="link to shop" class="btn btn-default border mr-2 icon"><i class="fas fa-store-alt"></i></a>
<a href="" class="btn btn-default border mr-2 icon"><i class="fab fa-facebook-f"></i></a>
<a href="" class="btn btn-default border mr-2 icon"><i class="fab fa-twitter"></i></a>
<a href="" class="btn btn-default border mr-2 icon"><i class="fab fa-tiktok"></i></a>
<a href="" class="btn btn-default border mr-2 icon"><i class="fab fa-instagram"></i></a>
<a href="" class="btn btn-default border icon"><i class="fab fa-youtube"></i></a>
</div>
</div>
</div>
</div>
</div>
<div class="container-fluid bg-dark">
<div class="row justify-content-center">
<?php foreach($affiliate as $aff): ?>
<a href="<?php echo $aff["link"]; ?>" target = "_blank" class="btn bg-dark btn-sm text-white mr-2 mt-2 mb-2" alt="<?php echo $aff["alt"]; ?>"><?php echo $aff["alt"]; ?></a>
<?php endforeach; ?>
</div>
</div>
<script src="js/jquery-3.5.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script>
const searchButton = document.getElementById('search-button');
const searchInput = document.getElementById('search-input');
searchButton.addEventListener('click', () => {
const inputValue = searchInput.value;
alert(inputValue);
});
</script>
<script>
(function() {
const idleDurationSecs = 1800;
const redirectUrl = 'logout.php';
let idleTimeout;
const resetIdleTimeout = function() {
if(idleTimeout) clearTimeout(idleTimeout);
idleTimeout = setTimeout(() => location.href = redirectUrl, idleDurationSecs * 1000);
};
// Key events for reset time
resetIdleTimeout();
window.onmousemove = resetIdleTimeout;
window.onkeypress = resetIdleTimeout;
window.click = resetIdleTimeout;
window.onclick = resetIdleTimeout;
window.touchstart = resetIdleTimeout;
window.onfocus = resetIdleTimeout;
window.onchange = resetIdleTimeout;
window.onmouseover = resetIdleTimeout;
window.onmouseout = resetIdleTimeout;
window.onmousemove = resetIdleTimeout;
window.onmousedown = resetIdleTimeout;
window.onmouseup = resetIdleTimeout;
window.onkeypress = resetIdleTimeout;
window.onkeydown = resetIdleTimeout;
window.onkeyup = resetIdleTimeout;
window.onsubmit = resetIdleTimeout;
window.onreset = resetIdleTimeout;
window.onselect = resetIdleTimeout;
window.onscroll = resetIdleTimeout;
})();
</script>
</body>
</html>