-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.php
More file actions
223 lines (205 loc) · 11.2 KB
/
page.php
File metadata and controls
223 lines (205 loc) · 11.2 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
<?php
ob_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tomasino Blog: Single Post</title>
<!-- Font Awesome Icons -->
<script src='https://kit.fontawesome.com/2f54b60b72.js' crossorigin='anonymous'></script>
<!-- Fonts -->
<link href="https://fonts.cdnfonts.com/css/eingrantch-mono" rel="stylesheet">
<!-- Bootstrap -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<!-- CSS Stylesheet -->
<link rel="stylesheet" href="./styles.css" />
</head>
<body>
<!-- Checks for database connection -->
<?php
include 'function.php';
$data = viewPost();
$data_com = getCom();
?>
<!-- Navbar -->
<nav class="navbar sticky-top navbar-expand-lg navbar-light bg-light mb-3 p-3">
<div class="container">
<!-- Title -->
<a href="./index.php">
<i class="fas fa-cat fa-2x me-3"></i>
<span class="navbar-brand mb-0 h1 title">Tomasino Blog</span>
</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>
<!-- Delete and Edit Post Buttons -->
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<div class="navbar-nav ms-auto order-3 right-nav">
<?php foreach ($data as $d) { ?>
<button type="button" class="btn me-4" data-bs-toggle="modal" data-bs-target="#delModal"><i class="fas fa-trash-alt fa-2x"></i></button>
<button type="button" class="btn" data-bs-toggle="modal" data-bs-target="#editModal"><i class="fas fa-edit fa-2x"></i></button>
<?php } ?>
</div>
</div>
</div>
</nav>
<!-- Body -->
<div class="container px-4 px-lg-5">
<div class="row gx-4 gx-lg-5 justify-content-center">
<div class="col-md-10 col-lg-8 col-xl-7 ">
<!-- Checks for database connection and header variables -->
<?php
checkConnection();
if (isset($_REQUEST['deleted'])) {
if ($_REQUEST['deleted'] == "success") {
alert("Succesfully deleted a comment!");
}
}
if (isset($_REQUEST['created'])) {
if ($_REQUEST['created'] == "success") {
alert("Succesfully created a comment!");
}
}
?>
<!-- Post -->
<div class="card p-3 mb-3">
<div class="card-body">
<?php foreach ($data as $d) { ?>
<h2 class="mb-2"><?php echo $d['POST_TITLE']; ?></h2>
<h6 class="mb-4"><?php echo "By: ", $d['POST_AUTHOR'], " | ", $d['POST_DATE']; ?></h6>
<div class="text-justify">
<?php echo nl2br($d['POST_CONTENT']); ?>
</div>
<?php } ?>
</div>
</div>
<!-- Comment Section -->
<div class="card p-3">
<div class="card-body">
<!-- Header and Add Comment Button -->
<div class="d-flex justify-content-between mb-4">
<h4>Comment Section:</h4>
<button type="button" class="btn" data-bs-toggle="modal" data-bs-target="#addComment"><i class="fas fa-comment fa-2x"></i></button>
</div>
<div class="row">
<div class="col">
<!-- Comment List -->
<?php foreach ($data_com as $d) { ?>
<div class="d-flex flex-start mb-3 align-items-center justify-content-center p-1" style="border: 2px solid var(--background-color); border-radius: 8px">
<!-- User Image -->
<i class='fas fa-user-alt fa-2x me-3'></i>
<div class="flex-grow-1 flex-shrink-1">
<div>
<!-- User Comment Details -->
<div class="d-flex justify-content-between align-items-center">
<p class="mb-1">
<?php echo $d['COM_AUTHOR']; ?> <span class="small">- <?php echo $d['COM_DATE']; ?></span>
</p>
<!-- Delete Comment -->
<form method="POST">
<button type="submit" class="btn" name="delete_com" value="<?php echo $d['COM_ID']; ?>"><i class="fas fa-trash-alt fa-1x"></i></button>
</form>
</div>
<p class="small mb-0">
<?php echo nl2br($d['COM_CONTENT']); ?>
</p>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Delete Post Modal -->
<?php foreach ($data as $d) { ?>
<div class="modal fade" id="delModal" tabindex="-1" aria-labelledby="delModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="delModalLabel">Are you sure you want to delete this post?</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">The article '<?php echo $d['POST_TITLE']; ?>' will be gone forver!</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-dark" data-bs-dismiss="modal">Close</button>
<form method="POST">
<button type="submit" class="btn btn-danger" name="delete_post">Confirm</button>
</form>
</div>
</div>
</div>
</div>
<?php } ?>
<!-- Edit Post Modal -->
<?php foreach ($data as $d) { ?>
<div class="modal fade" id="editModal" tabindex="-1" aria-labelledby="editModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="editModalLabel">Editing this post!</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<!-- Edit Post Form -->
<form method="POST">
<div class="modal-body">
<div class="mb-3">
<label for="Input1" class="form-label">Article Title</label>
<input type="text" name="title" class="form-control" id="Input1" value='<?php echo $d['POST_TITLE']; ?>' required>
</div>
<div class="mb-3">
<label for="Input2" class="form-label">Author</label>
<input type="text" name="author" class="form-control" id="Input2" value='<?php echo $d['POST_AUTHOR']; ?>' required>
</div>
<div class="mb-3">
<label for="Input3" class="form-label">Content</label>
<textarea class="form-control" name="content" id="Input3" rows="12" required><?php echo $d['POST_CONTENT']; ?></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-dark" data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-success" name="edit_post">Confirm Edit</button>
</form>
</div>
</div>
</div>
</div>
<?php } ?>
<!-- Add Comment Modal -->
<div class="modal fade" id="addComment" tabindex="-1" aria-labelledby="addCommentModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="addCommentModalLabel">Creating a comment!</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<!-- Add Comment Post -->
<form method="POST">
<div class="modal-body">
<div class="mb-3">
<label for="Input1" class="form-label">Author</label>
<input type="text" name="author" class="form-control" id="Input2" placeholder="Input name of author" required>
</div>
<div class="mb-3">
<label for="Input2" class="form-label">Content</label>
<textarea class="form-control" name="content" id="Input3" placeholder="Lorem ipsum..." rows="12" required></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-dark" data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-warning" name="submit_com">Submit</button>
</div>
</form>
</div>
</div>
</div>
<!-- Boostrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous"></script>
</body>
</html>