-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuser.php
280 lines (236 loc) · 8.69 KB
/
user.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
<?php
include_once("include/functions.inc.php");
session_start();
$username=$_SESSION['username'];
if(!isset($_SESSION['username'])) {
echo "<p class=\"errorText\">It looks like you aren't logged in.
This page is inaccessible until you log in or create your account.</p>";
return;
}
$queryUser = "SELECT user_id FROM users where username='$username';";
$userResult = queryResults($queryUser);
$user_id = mysqli_fetch_row($userResult)[0];
$user_view_id = $user_id;
$usernameView = $username;
if ( isset($_GET['id'])){
$user_view_id = $_GET['id'];
$queryUser = "SELECT username FROM users where user_id='$user_view_id';";
$userResult = queryResults($queryUser);
$usernameView = mysqli_fetch_row($userResult)[0];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<link rel="stylesheet" href="header.css" type="text/css">
<link rel="stylesheet" href="app.css" type="text/css">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Account</title>
</head>
<body class="App">
<div class="App-header">
<a class="home" href="browse.php">MeTube</a>
<?php if ( $user_id == $user_view_id) { ?>
<a class="home" href='mediaUpload.php'>Upload</a>
<?php } ?>
<a class="upload" href='logout.php'>logout</a>
<?php if ( $user_id == $user_view_id) { ?>
<a class="upload" href='contacts.php'>contacts</a>
<?php } ?>
</div>
<h1 style=" background-color: #08415C; width: 60%; clear: both; margin: auto;" > <?php echo "$usernameView"; ?> </h1>
<div class="baseroot2" style="margin-top: 0px;">
<br/><br/>
<?php
$query = "SELECT * from Media where user_id= $user_view_id";
$result = queryResults( $query );
if (!$result)
{
die ("Could not query the media table in the database: <br />". mysql_error());
}
?>
<div style="display: table;">
<div class="mediaText" style="background:#339900;color:#FFFFFF; width:200px; height: 40px; display: table-cell; font-size: x-large; "><?php echo "$usernameView"; ?>'s Media</div>
</div>
<table width="50%" cellpadding="0" cellspacing="0">
<?php
$html = '';
$deleteHtml = '';
$totalItemPerLine = 3;
$i = 0;
while ($result_row = mysqli_fetch_row($result))
{
if( $i % $totalItemPerLine == 0 ){
$html .= '<div class="row">'; // New Row
}
$html .= '<div class="col"> <div class="media"> <div class="mediaText" > <a href="media.php?id='.$result_row[0].'" target="_blank">'.$result_row[4].'</a><br><a href="'.$result_row[7].'" target="_blank" onclick="javascript:saveDownload('.$result_row[7].');">Download</a></div></div></div>';
$deleteHtml .= '<option value="'.$result_row[0].'">'.$result_row[4].'</option>';
if($i % $totalItemPerLine == ($totalItemPerLine-1))
{
$html .= '</div>'; // End Row
}
$i += 1;
?>
<?php
}
if($i % $totalItemPerLine != ($totalItemPerLine-1)){
$html .= '</div>';
}
echo $html;
?>
<div style="padding-top: 35px; clear: both; "> </div>
<div style="padding: 1px; background-color: #08415C; margin: auto; width: 80% "> </div>
<?php if ( $user_id == $user_view_id) { ?>
<div class="App-header" >
<form method="post" action="deleteMedia.php" enctype="multipart/form-data">
<label style="font-size: large" for="media">Delete Media:</label>
<select name="media" id="media">
<?php echo $deleteHtml; ?>
</select>
<input type="submit" value="Delete">
</form>
</div>
<?php } ?>
</table>
<!-- PLAYLISTS -->
<br/><br/>
<?php
$query = "SELECT * from playlists where user_id=$user_view_id";
$result = queryResults( $query );
?>
<div class="mediaText" style="background:#339900;color:#FFFFFF; width:200px; height: 40px; display: table-cell; font-size: x-large; "><?php echo "$usernameView"; ?>'s Playlists</div>
<table width="50%" cellpadding="0" cellspacing="0">
<?php
$html = '';
$deleteHtml = '';
$totalItemPerLine = 3;
$i = 0;
while ($result_row = mysqli_fetch_assoc($result))
{
if( $i % $totalItemPerLine == 0 ){
$html .= '<div class="row">'; // New Row
}
$html .= '<div class="col"> <div class="media"> <div class="mediaText" > <a href="playlist.php?id='.$result_row["playlist_id"].'" >'.$result_row["title"].'</a><br><h3>'.$result_row["items_count"].' Items </div></div></div>';
if($i % $totalItemPerLine == ($totalItemPerLine-1))
{
$html .= '</div>'; // End Row
}
$i += 1;
?>
<?php
}
if($i % $totalItemPerLine != ($totalItemPerLine-1)){
$html .= '</div>';
}
echo $html;
?>
</div>
</div>
</div>
</table>
</div>
<?php
if(isset($_POST['submit'])) {
if($_POST['newemail'] != "") {
$newemail = $_POST['newemail'];
$query = "SELECT email_address FROM users WHERE email_address='$newemail' AND
username IN (SELECT username FROM users WHERE username!='$_SESSION[username]')";
if(!($result = mysqli_query($conn, $query))) {
die("<p>Error changing email address</p>");
}
if(mysqli_num_rows($result)) {
$error="<p>Email address already exists.</p>";
}
else { // update email address
$query = "UPDATE users SET email_address='$newemail'
WHERE username='$_SESSION[username]'";
if (!($result = mysqli_query($conn, $query))) {
die("<p>Could not update your email address at this time.</p>");
}
else {
echo "<p>Email address updated successfully</p>";
}
}
}
if($_POST['newpass'] != "") {
$newpass = $_POST['newpass'];
if($newpass != "") {
// update password
$query = "UPDATE users SET password='$newpass' WHERE username='$_SESSION[username]'";
if(!($result = mysqli_query($conn, $query))) {
die("<p>Could not update your password at this time (No Update)</p>");
}
else {
echo "<p>Password updated successfully</p>";
}
}
}
if($_POST['newusername'] != ""){
$newusername = $_POST['newusername'];
$query = "SELECT username FROM users WHERE username='$newusername' AND username IN
(SELECT username FROM users WHERE username!='$_SESSION[username]')";
if(!($result = mysqli_query($conn, $query))) {
die("<p>Could not update your username at this time (No Validation)</p>");
}
if(mysqli_num_rows($result) > 0){
$error="<p>Username already exists</p>";
}
else {
$query = "UPDATE users SET username='$newusername' WHERE username='$_SESSION[username]'";
if(!($result = mysqli_query($conn, $query))){
die("<p>Could not update username</p>");
}
$_SESSION['username']=$newusername;
echo "<p>Username updated successfully</p>";
}
?>
<meta http-equiv="refresh" content="0;url=user.php" ?>
<?php
}
if(isset($error)) {
echo $error;
}
}
?>
<?php if ( $user_id == $user_view_id) { ?>
<div class="baseroot2">
<br/>
<div class="mediaText" style="background:#339900;color:#FFFFFF; width:400px; height: 40px; display: table-cell; font-size: x-large; ">Update Your Account</div>
<br></br>
<table style="color: #FFFFFF; font-size: x-large; width: 80%; margin: auto; border: none; border-radius: 4px; padding: 2px;">
<tr><td><p>You can change your account information here.</p></td></tr>
<tr><td>
<form method="POST" action="<?php echo "user.php"; ?>">
<table cellspacing="0" cellpadding="0">
</table>
</td></tr>
<tr><td>
<table>
<p class="generalText" style="padding-bottom: 1em; font-size: large;">
Leave fields with their starting values or blank if you do not wish to change them
</p>
<table style="margin: auto; font-size: large;">
<tr class="makealignright">
<td>Email Address:</td>
<td><input class="orangefield" type="text" name="newemail" value="">
</td>
</tr>
<tr class="makealignright">
<td class="generalText">New Password:</td>
<td><input class="orangefield" type="text" name="newpass" value""></td>
</tr>
<tr class="makealignright">
<td class="generalText">Username:</td>
<td><input class="orangefield" type="text" name="newusername" value""></td>
</td>
</tr>
<tr><td><input class="btn btn-primary" name="submit" type="submit" value="Submit"></td></tr>
</table>
</form>
</table>
</td></tr>
</table>
</div>
<?php } ?>
</body>
</html>