-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.php
99 lines (87 loc) · 2.86 KB
/
settings.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
<?php
include 'core/init.php';
protect_page();
include 'includes/overall/header.php';
if (empty($_POST) === false) {
$required_fields = array('username', 'first_name', 'email');
foreach ($_POST as $key=>$value) {
if (empty($value) && in_array($key, $required_fields) === true) {
$errors[] = "Fields marked with an asterisk are required";
break 1;
}
}
if (empty($errors) === true) {
if (user_exists($_POST['username']) === true && $user_data['username'] != $_POST['username']) {
$errors[] = 'Sorry, the username \'' . $_POST['username'] . '\' is already taken.';
}
if (preg_match("/\\s/", $_POST['username']) == true) {
$errors[] = 'Your username must not contain any spaces';
}
if (strlen($_POST['username']) > 32) {
$errors[] = 'Your username must be less than 32 characters';
}
if (strlen($_POST['first_name']) > 32) {
$errors[] = 'Your first name must be less than 32 characters';
}
if (strlen($_POST['last_name']) > 32) {
$errors[] = 'Your last name must be less than 32 characters';
}
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) {
$errors[] = 'A valid email address is required';
}
if (email_exists($_POST['email']) === true && $user_data['email'] !== $_POST['email']) {
$errors[] = 'Sorry, the email \'' . $_POST['email'] . '\' is already in use.';
}
}
}
?>
<h1>Settings</h1>
<?php
if (isset($_GET['success']) ===true && empty($_GET['success']) === true) {
echo 'Your details have been updated!';
} else {
if (empty($_POST) === false && empty($errors) === true) {
$update_data = array(
'username' => $_POST['username'],
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'email' => $_POST['email'],
'allow_email' => ($_POST['allow_email'] == 'on') ? 1 : 0,
);
update_user($session_user_id, $update_data);
header('Location: settings.php?success');
exit();
} else if (empty($errors) === false) {
echo output_errors($errors);
}
?>
<form action="" method="post">
<ul>
<li>
Username*:<br>
<input type="text" name="username" value="<?php echo $user_data['username']; ?>">
</li>
<li>
First name*:<br>
<input type="text" name="first_name" value="<?php echo $user_data['first_name']; ?>">
</li>
<li>
Last name:<br>
<input type="text" name="last_name" value="<?php echo $user_data['last_name']; ?>">
</li>
<li>
Email*:<br>
<input type="text" name="email" value="<?php echo $user_data['email']; ?>">
</li>
<li>
<input type="checkbox" name="allow_email" <?php if ($user_data['allow_email'] == 1) { echo 'checked="checked"';} ?>> Would you like to receive email from us?
</li>
<li>
<input type="submit" value="Update">
</li>
</ul>
</form>
<?php
}
include 'includes/overall/footer.php';
?>