-
Notifications
You must be signed in to change notification settings - Fork 0
/
editUser.php
executable file
·91 lines (76 loc) · 3.46 KB
/
editUser.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
<?php
require_once("functions.php");
if (!$isLoggedIn) {
header("Location:login.php");
exit;
}
$submitted = isset($_POST['updateUser']) ? true : false;
$updatedImage = isset($_FILES['avatar']) ? true : false;
unset($_POST['updateUser']);
$errorMsg = NULL;
if ($submitted) {
$submittingDetails = $_POST;
if ($updatedImage) {
$image = $_FILES['avatar'];
$imageTempDir = $image['tmp_name'];
$imageName = $image['name'];
$imagesDir = "avatars/";
$permission = 0777;
if (!file_exists($imagesDir)) mkdir($imagesDir, $permission);
$imagePath = $imagesDir . $imageName;
$uploaded = move_uploaded_file($imageTempDir, $imagePath);
if ($uploaded) {
$imageURL = $imagePath;
$submittingDetails['profileImage'] = $imageURL;
squareImageAtPath($imagePath, $imagePath, 200);
}
}
if (isValidEmail($_POST['emailAddress'])) {
updateUserForID($myUserID, $submittingDetails);
} else {
$errorMsg = "<b>* Invalid email address</b><br><br>";
}
}
$user = getUserForID($myUserID);
$profilePicURL = $user['profileImage'] ? $user['profileImage'] : NULL;
$profilePic = file_exists($profilePicURL) ? $profilePicURL : "images/default.png";
$fullName = $user['fullName'] ? $user['fullName'] : "No name set";
$username = $user['username'] ? $user['username'] : "No username set";
$emailAdd = $user['emailAddress'] ? $user['emailAddress'] : "No email address set";
?>
<!DOCTYPE html>
<html>
<head>
<title>Account Settings</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="css/main.css" type="text/css" />
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<!--[if lte IE 7]>
<link rel="stylesheet" type="text/css" media="all" href="css/ie.css"/>
<script src="js/IE8.js" type="text/javascript"></script><![endif]-->
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" media="all" href="css/ie6.css"/><![endif]-->
</head>
<body>
<?php echo $htmlNavigation; ?>
<section id="logins" class="body">
<div id="login" align="center">
<div id="backing" align="center" style="width:400px;background-color:rgba(32,44,75,0.90);">
<header>
<h2>Update Account</h2>
</header>
<?php echo '<img class="profilePic_user" src="' .$profilePic .'" alt="Default Profile Pic"><br>' .$errorMsg; ?>
<form method="post" enctype="multipart/form-data">
Avatar: <input type="file" name="avatar"><br><br>
<input type="text" name="fullName" style="text-align:center; height:30px;" placeholder="Full Name" value="<?php echo $fullName; ?>">
<input type="text" name="username" style="text-align:center; height:30px;" placeholder="Username" value="<?php echo $username; ?>">
<input type="text" name="emailAddress" style="text-align:center; height:30px;" placeholder="Email Address" value="<?php echo $emailAdd; ?>">
<br>
<input type="submit" style="height:35px;" name="updateUser" value="UPDATE">
</form>
</div>
</div>
</section>
</body>
</html>