-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathindex.php
More file actions
121 lines (103 loc) · 5.36 KB
/
Copy pathindex.php
File metadata and controls
121 lines (103 loc) · 5.36 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
<?php
include("functions.php");
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Notification System in PHP and MySql</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
<a class="navbar-brand" href="#">Notification System in PHP and MySql</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<li class="nav-item dropdown">
<a class="nav-link" href="http://example.com" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Notifications
<?php
$query = "SELECT * from `notifications` where `status` = 'unread' order by `date` DESC";
if(count(fetchAll($query))>0){
?>
<span class="badge badge-light"><?php echo count(fetchAll($query)); ?></span>
<?php
}
?>
</a>
<div class="dropdown-menu" aria-labelledby="dropdown01">
<?php
$query = "SELECT * from `notifications` order by `date` DESC";
if(count(fetchAll($query))>0){
foreach(fetchAll($query) as $i){
?>
<a style ="
<?php
if($i['status']=='unread'){
echo "font-weight:bold;";
}
?>
" class="dropdown-item" href="view.php?id=<?php echo $i['id'] ?>">
<small><i><?php echo date('F j, Y, g:i a',strtotime($i['date'])) ?></i></small><br/>
<?php
if($i['type']=='comment'){
echo "Someone commented on your post.";
}else if($i['type']=='like'){
echo ucfirst($i['name'])." liked your post.";
}
?>
</a>
<div class="dropdown-divider"></div>
<?php
}
}else{
echo "No Records yet.";
}
?>
</div>
</li>
</ul>
<?php
if(isset($_POST['submit'])){
$message = $_POST['message'];
$query ="INSERT INTO `notifications` (`id`, `name`, `type`, `message`, `status`, `date`) VALUES (NULL, '', 'comment', '$message', 'unread', CURRENT_TIMESTAMP)";
if(performQuery($query)){
header("location:index.php");
}
}
?>
<form method="post" class="form-inline my-2 my-lg-0">
<input name="message"class="form-control mr-sm-2" type="text" placeholder="Message" required>
<button name="submit" class="btn btn-outline-success my-2 my-sm-0" type="submit">Submit</button>
</form> |
<?php
if(isset($_POST['like'])){
$name = $_POST['name'];
$query ="INSERT INTO `notifications` (`id`, `name`, `type`, `message`, `status`, `date`) VALUES (NULL, '$name', 'like', '', 'unread', CURRENT_TIMESTAMP)";
if(performQuery($query)){
header("location:index.php");
}
}
?>
<form method="post" class="form-inline my-2 my-lg-0">
<input name="name" class="form-control mr-sm-2" type="text" placeholder="Name" required>
<button name="like" class="btn btn-outline-success my-2 my-sm-0" type="submit">Like </button>
</form>
</div>
</nav>
<main role="main" class="container">
<div class="starter-template">
<h1>Bootstrap starter template</h1>
<p class="lead">Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</p>
</div>
</main><!-- /.container -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>