-
Notifications
You must be signed in to change notification settings - Fork 0
/
watch_video.php
310 lines (243 loc) · 10.6 KB
/
watch_video.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
<?php
include 'components/connect.php';
if(isset($_COOKIE['user_id'])){
$user_id = $_COOKIE['user_id'];
}else{
$user_id = '';
}
if(isset($_GET['get_id'])){
$get_id = $_GET['get_id'];
}else{
$get_id = '';
header('location:home.php');
}
if(isset($_POST['like_content'])){
if($user_id != ''){
$content_id = $_POST['content_id'];
$content_id = filter_var($content_id, FILTER_SANITIZE_STRING);
$select_content = $conn->prepare("SELECT * FROM `content` WHERE id = ? LIMIT 1");
$select_content->execute([$content_id]);
$fetch_content = $select_content->fetch(PDO::FETCH_ASSOC);
$tutor_id = $fetch_content['tutor_id'];
$select_likes = $conn->prepare("SELECT * FROM `likes` WHERE user_id = ? AND content_id = ?");
$select_likes->execute([$user_id, $content_id]);
if($select_likes->rowCount() > 0){
$remove_likes = $conn->prepare("DELETE FROM `likes` WHERE user_id = ? AND content_id = ?");
$remove_likes->execute([$user_id, $content_id]);
$message[] = 'removed from likes!';
}else{
$insert_likes = $conn->prepare("INSERT INTO `likes`(user_id, tutor_id, content_id) VALUES(?,?,?)");
$insert_likes->execute([$user_id, $tutor_id, $content_id]);
$message[] = 'added to likes!';
}
}else{
$message[] = 'please login first!';
}
}
if(isset($_POST['add_comment'])){
if($user_id != ''){
$id = unique_id();
$comment_box = $_POST['comment_box'];
$comment_box = filter_var($comment_box, FILTER_SANITIZE_STRING);
$content_id = $_POST['content_id'];
$content_id = filter_var($content_id, FILTER_SANITIZE_STRING);
$select_content = $conn->prepare("SELECT * FROM `content` WHERE id = ? LIMIT 1");
$select_content->execute([$content_id]);
$fetch_content = $select_content->fetch(PDO::FETCH_ASSOC);
$tutor_id = $fetch_content['tutor_id'];
if($select_content->rowCount() > 0){
$select_comment = $conn->prepare("SELECT * FROM `comments` WHERE content_id = ? AND user_id = ? AND tutor_id = ? AND comment = ?");
$select_comment->execute([$content_id, $user_id, $tutor_id, $comment_box]);
if($select_comment->rowCount() > 0){
$message[] = 'comment already added!';
}else{
$insert_comment = $conn->prepare("INSERT INTO `comments`(id, content_id, user_id, tutor_id, comment) VALUES(?,?,?,?,?)");
$insert_comment->execute([$id, $content_id, $user_id, $tutor_id, $comment_box]);
$message[] = 'new comment added!';
}
}else{
$message[] = 'something went wrong!';
}
}else{
$message[] = 'please login first!';
}
}
if(isset($_POST['delete_comment'])){
$delete_id = $_POST['comment_id'];
$delete_id = filter_var($delete_id, FILTER_SANITIZE_STRING);
$verify_comment = $conn->prepare("SELECT * FROM `comments` WHERE id = ?");
$verify_comment->execute([$delete_id]);
if($verify_comment->rowCount() > 0){
$delete_comment = $conn->prepare("DELETE FROM `comments` WHERE id = ?");
$delete_comment->execute([$delete_id]);
$message[] = 'comment deleted successfully!';
}else{
$message[] = 'comment already deleted!';
}
}
if(isset($_POST['update_now'])){
$update_id = $_POST['update_id'];
$update_id = filter_var($update_id, FILTER_SANITIZE_STRING);
$update_box = $_POST['update_box'];
$update_box = filter_var($update_box, FILTER_SANITIZE_STRING);
$verify_comment = $conn->prepare("SELECT * FROM `comments` WHERE id = ? AND comment = ?");
$verify_comment->execute([$update_id, $update_box]);
if($verify_comment->rowCount() > 0){
$message[] = 'comment already added!';
}else{
$update_comment = $conn->prepare("UPDATE `comments` SET comment = ? WHERE id = ?");
$update_comment->execute([$update_box, $update_id]);
$message[] = 'comment edited successfully!';
}
}
?>
<!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>watch video</title>
<!-- font awesome cdn link -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css">
<!-- custom css file link -->
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<?php include 'components/user_header.php'; ?>
<?php
if(isset($_POST['edit_comment'])){
$edit_id = $_POST['comment_id'];
$edit_id = filter_var($edit_id, FILTER_SANITIZE_STRING);
$verify_comment = $conn->prepare("SELECT * FROM `comments` WHERE id = ? LIMIT 1");
$verify_comment->execute([$edit_id]);
if($verify_comment->rowCount() > 0){
$fetch_edit_comment = $verify_comment->fetch(PDO::FETCH_ASSOC);
?>
<section class="edit-comment">
<h1 class="heading">edti comment</h1>
<form action="" method="post">
<input type="hidden" name="update_id" value="<?= $fetch_edit_comment['id']; ?>">
<textarea name="update_box" class="box" maxlength="1000" required placeholder="please enter your comment" cols="30" rows="10"><?= $fetch_edit_comment['comment']; ?></textarea>
<div class="flex">
<a href="watch_video.php?get_id=<?= $get_id; ?>" class="inline-option-btn">cancel edit</a>
<input type="submit" value="update now" name="update_now" class="inline-btn">
</div>
</form>
</section>
<?php
}else{
$message[] = 'comment was not found!';
}
}
?>
<!-- watch video section starts -->
<section class="watch-video">
<?php
$select_content = $conn->prepare("SELECT * FROM `content` WHERE id = ? AND status = ?");
$select_content->execute([$get_id, 'active']);
if($select_content->rowCount() > 0){
while($fetch_content = $select_content->fetch(PDO::FETCH_ASSOC)){
$content_id = $fetch_content['id'];
$select_likes = $conn->prepare("SELECT * FROM `likes` WHERE content_id = ?");
$select_likes->execute([$content_id]);
$total_likes = $select_likes->rowCount();
$verify_likes = $conn->prepare("SELECT * FROM `likes` WHERE user_id = ? AND content_id = ?");
$verify_likes->execute([$user_id, $content_id]);
$select_tutor = $conn->prepare("SELECT * FROM `tutors` WHERE id = ? LIMIT 1");
$select_tutor->execute([$fetch_content['tutor_id']]);
$fetch_tutor = $select_tutor->fetch(PDO::FETCH_ASSOC);
?>
<div class="video-details">
<video src="uploaded_files/<?= $fetch_content['video']; ?>" class="video" poster="uploaded_files/<?= $fetch_content['thumb']; ?>" controls autoplay></video>
<h3 class="title"><?= $fetch_content['title']; ?></h3>
<div class="info">
<p><i class="fas fa-calendar"></i><span><?= $fetch_content['date']; ?></span></p>
<p><i class="fas fa-heart"></i><span><?= $total_likes; ?> likes</span></p>
</div>
<div class="tutor">
<img src="uploaded_files/<?= $fetch_tutor['image']; ?>" alt="">
<div>
<h3><?= $fetch_tutor['name']; ?></h3>
<span><?= $fetch_tutor['profession']; ?></span>
</div>
</div>
<form action="" method="post" class="flex">
<input type="hidden" name="content_id" value="<?= $content_id; ?>">
<a href="playlist.php?get_id=<?= $fetch_content['playlist_id']; ?>" class="inline-btn">view playlist</a>
<?php
if($verify_likes->rowCount() > 0){
?>
<button type="submit" name="like_content"><i class="fas fa-heart"></i><span>liked</span></button>
<?php
}else{
?>
<button type="submit" name="like_content"><i class="far fa-heart"></i><span>like</span></button>
<?php
}
?>
</form>
<div class="description"><p><?= $fetch_content['description']; ?></p></div>
</div>
<?php
}
}else{
echo '<p class="empty">no videos added yet!</p>';
}
?>
</section>
<!-- watch video section ends -->
<!-- comments section starts -->
<section class="comments">
<h1 class="heading">add a comment</h1>
<form action="" method="post" class="add-comment">
<input type="hidden" name="content_id" value="<?= $get_id; ?>">
<textarea name="comment_box" required placeholder="write your comment..." maxlength="1000" cols="30" rows="10"></textarea>
<input type="submit" value="add comment" name="add_comment" class="inline-btn">
</form>
<h1 class="heading">user comments</h1>
<div class="show-comments">
<?php
$select_comments = $conn->prepare("SELECT * FROM `comments` WHERE content_id = ?");
$select_comments->execute([$get_id]);
if($select_comments->rowCount() > 0){
while($fetch_comment = $select_comments->fetch(PDO::FETCH_ASSOC)){
$select_commentor = $conn->prepare("SELECT * FROM `users` WHERE id = ?");
$select_commentor->execute([$fetch_comment['user_id']]);
$fetch_commentor = $select_commentor->fetch(PDO::FETCH_ASSOC);
?>
<div class="box" style="<?php if($fetch_comment['user_id'] == $user_id){echo 'order:-1;';} ?>">
<div class="user">
<img src="uploaded_files/<?= $fetch_commentor['image']; ?>" alt="">
<div>
<h3><?= $fetch_commentor['name']; ?></h3>
<span><?= $fetch_comment['date']; ?></span>
</div>
</div>
<p class="text"><?= $fetch_comment['comment']; ?></p>
<?php
if($fetch_comment['user_id'] == $user_id){
?>
<form action="" method="post" class="flex-btn">
<input type="hidden" name="comment_id" value="<?= $fetch_comment['id']; ?>">
<button type="submit" name="edit_comment" class="inline-option-btn">edit comment</button>
<button type="submit" name="delete_comment" class="inline-delete-btn" onclick="return confirm('delete this comment?');">delete comment</button>
</form>
<?php
}
?>
</div>
<?php
}
}else{
echo '<p class="empty">no comments added yet!</p>';
}
?>
</div>
</section>
<!-- comments section ends -->
<?php include 'components/footer.php'; ?>
<!-- custom js file link -->
<script src="js/script.js"></script>
</body>
</html>