-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmedia.php
233 lines (195 loc) · 6.21 KB
/
media.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
session_start();
include_once "include/functions.inc.php";
include_once "include/likes.inc.php";
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<link rel="stylesheet" href="app.css" type="text/css">
<link rel="stylesheet" href="header.css" type="text/css">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Media</title>
<script src="Scripts/AC_ActiveX.js" type="text/javascript"></script>
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
</head>
<body class="App">
<div class="App-header">
<a class="home" href="browse.php">MeTube</a>
<?php
if( isset($_SESSION['username'])){
$username = $_SESSION['username'];
echo '<a class="upload" href="user.php">'.$username.'</a>';
}
?>
</div>
<div class="baseroot2">
<?php
if(isset($_POST['removeComment'])){
$comment = $_POST['removeComment'];
$query = "DELETE FROM comments WHERE comment_id=$comment";
$result = queryResults($query);
}
if(isset($_POST['reply'])) { // post a reply to the discussion
$user = $_SESSION['username'];
$query = "SELECT user_id FROM users WHERE username='user';";
if(!($result = mysqli_query($conn, $query))) {
die("<p>Error accessing account</p>");
}else{
$user_id = mysqli_fetch_assoc($result);
}
$query = "INSERT INTO comments (user_id, content, media_id) VALUES ('$user_id', '$_POST[commentText]','$_GET[id]')";
if(!($result = mysqli_query($conn, $query))) {
echo "<p>Could not create your comment at this time</p>";
}
}
if(isset($_GET['id'])) {
$query = "SELECT * FROM Media WHERE media_id='".$_GET['id']."'";
$result = queryResults( $query );
$result_row = mysqli_fetch_assoc($result);
$comment_query = "SELECT * FROM comments WHERE media_id='".$_GET['id']."'";
$comment_result = mysqli_query($conn, $comment_query);
// $comment_data = mysqli_fetch_assoc($comment_result);
$user_query = "SELECT username FROM users WHERE user_id='".$result_row['user_id']."';";
$user_result= queryResults( $user_query);
$username_media = mysqli_fetch_row($user_result)[0];
$filename=$result_row["title"];
$filepath=$result_row["file_ulr"];
$type=$result_row["duration"];
if($type == 0 ) //view image
{
echo "<h1>$filename</h1>";
echo "<h2>Uploaded By: $username_media</h2><br>";
echo "<img style='margin-top: 2%; width: 80%; height: 60%; object-fit: contain;' src='".$filepath."'/><br>";
echo "</br>Description: ";
echo $result_row["description"];
echo "</br>Category: ";
echo $result_row["category"];
echo "</br></br></br>Keywords: ";
echo $result_row["keywords"];
}
else //view movie
{
?>
<h1><?php echo $result_row["title"];?></h1><br>
<h2><?php echo "Uploaded By: $username_media";?></h2><br>
<?php
$video_location = $result_row['file_ulr'];
echo '<video width="320" height="240" controls autoplay muted>';
echo '<source src='.$video_location.' type="video/mp4"> Your browser does not support the video tag.
</video>';
echo "</br>Description: ";
echo $result_row["description"];
echo "</br>Category: ";
echo $result_row["category"];
echo "</br></br></br>Keywords: ";
echo $result_row["keywords"];
?>
</object>
<?php
}
} else {
?>
</div>
<meta http-equiv="refresh" content="0;url=browse.php">
<?php
}
?>
<!-- Add to Playlist -->
<?php
if( isset($_SESSION['username'])){
$userValidate = "SELECT user_id FROM users WHERE username='".$username."';";
$userResult = queryResults( $userValidate );
$user_id = mysqli_fetch_row( $userResult )[0];
$query = "SELECT * FROM playlists WHERE user_id=".$user_id.";";
$result = queryResults( $query );
$html = '';
$totalItemPerLine = 3;
$i = 0;
while ($result_row = mysqli_fetch_row($result))
{
if( $i % $totalItemPerLine == 0 ){
$html .= '<div class="row">'; // New Row
}
$html .= '<option value="'.$result_row[0].'">'.$result_row[2].'</option>';
if($i % $totalItemPerLine == ($totalItemPerLine-1))
{
$html .= '</div>'; // End Row
}
$i += 1;
}
?>
<div style="padding-top: 35px; clear: both; "> </div>
<div style="padding: 1px; background-color: #08415C; margin: auto; width: 80% "> </div>
<div class="App-header" >
<form method="post" action="addToPlaylist.php?id=<?php echo $_GET['id'];?>" enctype="multipart/form-data">
<label style="font-size: large" for="playlist">Add to Playlist:</label>
<select name="playlist" id="playlist">
<?php echo $html; ?>
</select>
<input type="submit" value="Add">
</form>
</div>
</br>
<!-- Method for Liking and Disliking media -->
<?php
$media_id = $_GET['id'];
$likeQuery = "SELECT SUM(CASE WHEN type=True THEN 1 ELSE 0 END) , SUM(CASE WHEN type=False THEN 1 ELSE 0 END) FROM ratings WHERE media_id=$media_id ;";
$result = queryResults($likeQuery);
$ratings = mysqli_fetch_row($result);
if ( $ratings[0]== NULL ){
$likeNum = 0;
$dislikeNum = 0;
}
else{
$likeNum = $ratings[0];
$dislikeNum = $ratings[1];
}
echo "$likeNum Likes ";
echo " $dislikeNum Dislikes ";
?>
<form method="post" action="ratingProcess.php?id=<?php echo $_GET['id'];?>&uid=<?php echo $user_id;?>" enctype="multipart/form-data">
<input type="submit" id="submit" name="submit" value="Like">
<input type="submit" id="submit" name="submit" value="Dislike">
</form>
<?php
}
?>
</div>
<div class="baseroot2" >
<h2>Comments</h2>
<table width="50%" cellpadding="0" cellspacing="0">
<?php
$html = '';
if(mysqli_num_rows($comment_result) == 0){
echo "</br>";
echo "No Comments on this post";
}else{
$i = 1;
while ($comment_result_row = mysqli_fetch_row($comment_result))
{
$html .= '<p> '.$comment_result_row[2];
if( isset($_SESSION['username'])){
$html .= '<form action="" method="post">
<input type="submit" name="submit" value="Delete">
<input type="hidden" name="removeComment" value='.$comment_result_row[0].'>
</form></p>';
}
$i += 1;
?>
<?php
}
}
echo $html;
?>
</br>
<?php if( isset($_SESSION['username'])){ ?>
<form method="POST" id="makecomment">
<textarea class="field" rows="4" cols="50" name="commentText" maxlength="1000" required="true"></textarea></br>
<input class="buttonOnOrange" type="submit" name="reply" value="Comment">
</form>
<?php } ?>
</table>
</div>
</body>
</html>