-
Notifications
You must be signed in to change notification settings - Fork 3
/
profile.php
262 lines (226 loc) · 7.69 KB
/
profile.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
<?php
/*
* profile.php
*
* A place for a user to edit/update his own info
*
*/
include_once 'checkinstance.php';
include 'db.php';
include 'lib/utility.php';
// ini_set('display_errors', 'On');
if ( !isset( $enable_PAM ) ) {
$enable_PAM = false;
}
if ( $enable_PAM
&& $_SESSION['authenticatePAM'] == true ) {
include 'header.php';
include 'footer.php';
exit();
}
if ( !isset( $_SESSION['id'] ) ) {
include 'login.php';
exit();
}
// Are we being directed here from a push button?
if (isset($_POST['update']))
{
do_update($link);
exit();
}
// Start displaying page
$page_title = 'My Profile';
$js = 'js/edit_users.js';
include 'header.php';
?>
<div id='content'>
<h1 class="title">My Profile</h1>
<?php if ( isset($_SESSION['message']) )
{
echo "<p class='message'>{$_SESSION['message']}</p>\n";
unset($_SESSION['message']);
} ?>
<?php
// Edit or display a record
if ( isset($_POST['edit']) || isset($_GET['edit']) )
edit_record($link);
else
display_record($link);
?>
</div>
<?php
include 'footer.php';
exit();
// Function to update the current record
function do_update($link)
{
$ID = $_SESSION['id'];
include 'get_user_info.php';
$pw1 = trim(substr(addslashes(htmlentities($_POST['pw1'])), 0,128));
$pw2 = trim(substr(addslashes(htmlentities($_POST['pw2'])), 0,128));
if ( $pw1 != $pw2 )
$message .= "--passwords do not match.";
if ( empty($message) )
{
$query = "UPDATE people " .
"SET lname = '$lname', " .
"fname = '$fname', " .
"organization = '$organization', " .
"address = '$address', " .
"city = '$city', " .
"state = '$state', " .
"zip = '$zip', " .
"country = '$country', " .
"phone = '$phone', " .
"email = '$email' ";
// See if password has changed
if ( $pw1 )
{
$pw = md5($pw1);
$query .= ", password = '$pw' ";
}
$query .= "WHERE personID = $ID ";
mysqli_query($link, $query)
or die("Query failed : $query<br />\n" . mysqli_error($link));
// Now update the session variables
$_SESSION['firstname'] = $fname;
$_SESSION['lastname'] = $lname;
$_SESSION['phone'] = $phone;
$_SESSION['email'] = $email;
$_SESSION['message'] = "Personal information updated.";
}
else
$_SESSION['message'] = "The following errors were noted:<br />" .
$message .
"Changes were not recorded.";
header("Location: {$_SERVER['PHP_SELF']}");
exit();
}
// Function to display record
function display_record($link)
{
$ID = $_SESSION['id'];
$query = "SELECT lname, fname, organization, " .
"address, city, state, zip, country, phone, email " .
"FROM people " .
"WHERE personID = $ID ";
$result = mysqli_query($link, $query)
or die("Query failed : $query<br />\n" . mysqli_error($link));
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
foreach ($row as $key => $value)
{
$$key = (empty($value)) ? "" : html_entity_decode(stripslashes( $value ));
}
echo<<<HTML
<form action="{$_SERVER['PHP_SELF']}" method='post'>
<table cellspacing='0' cellpadding='10' class='style1'>
<thead>
<tr><th colspan='8'>Edit My Information</th></tr>
</thead>
<tfoot>
<tr><td colspan='2'>
<input type='submit' name='edit' value='Edit' />
<input type='hidden' name='personID' value='$ID' />
</td></tr>
</tfoot>
<tbody>
<tr><th>First Name:</th>
<td>$fname</td></tr>
<tr><th>Last Name:</th>
<td>$lname</td></tr>
<tr><th>Organization:</th>
<td>$organization</td></tr>
<tr><th>Address:</th>
<td>$address</td></tr>
<tr><th>City:</th>
<td>$city</td></tr>
<tr><th>State (Province):</th>
<td>$state</td></tr>
<tr><th>Postal Code (Zip):</th>
<td>$zip</td></tr>
<tr><th>Country:</th>
<td>$country</td></tr>
<tr><th>Phone:</th>
<td>$phone</td></tr>
<tr><th>Email:</th>
<td>$email</td></tr>
</tbody>
</table>
</form>
HTML;
}
// Function to edit a record
function edit_record($link)
{
$ID = $_SESSION['id'];
$query = "SELECT lname, fname, organization, " .
"address, city, state, zip, country, phone, email " .
"FROM people " .
"WHERE personID = $ID ";
$result = mysqli_query($link, $query)
or die("Query failed : $query<br />\n" . mysqli_error($link));
$row = mysqli_fetch_array($result);
$lname = html_entity_decode(stripslashes($row['lname']));
$fname = html_entity_decode(stripslashes($row['fname']));
$organization = html_entity_decode(stripslashes($row['organization']));
$address = html_entity_decode(stripslashes($row['address']));
$city = html_entity_decode(stripslashes($row['city']));
$state = html_entity_decode(stripslashes($row['state']));
$zip = html_entity_decode(stripslashes($row['zip']));
$country = html_entity_decode(stripslashes($row['country']));
$phone = $row['phone'];
$email = stripslashes($row['email']);
echo<<<HTML
<form action="{$_SERVER['PHP_SELF']}" method="post"
onsubmit="return validate(this);">
<table cellspacing='0' cellpadding='10' class='style1'>
<thead>
<tr><th colspan='8'>Edit My Information</th></tr>
</thead>
<tfoot>
<tr><td colspan='2'><input type='submit' name='update' value='Update' />
<input type='reset' /></td></tr>
</tfoot>
<tbody>
<tr><th>First Name:</th>
<td><input type='text' name='fname' size='40'
maxlength='64' value='$fname' /></td></tr>
<tr><th>Last Name:</th>
<td><input type='text' name='lname' size='40'
maxlength='64' value='$lname' /></td></tr>
<tr><th>Organization:</th>
<td><input type='text' name='organization' size='40'
maxlength='128' value='$organization' /></td></tr>
<tr><th>Address:</th>
<td><input type='text' name='address' size='40'
maxlength='128' value='$address' /></td></tr>
<tr><th>City:</th>
<td><input type='text' name='city' size='40'
maxlength='64' value='$city' /></td></tr>
<tr><th>State (Province):</th>
<td><input type='text' name='state' size='40'
maxlength='64' value='$state' /></td></tr>
<tr><th>Postal Code (Zip):</th>
<td><input type='text' name='zip' size='40'
maxlength='16' value='$zip' /></td></tr>
<tr><th>Country:</th>
<td><input type='text' name='country' size='40'
maxlength='64' value='$country' /></td></tr>
<tr><th>Phone:</th>
<td><input type='text' name='phone' size='40'
maxlength='64' value='$phone' /></td></tr>
<tr><th>Email (required):</th>
<td><input type='text' name='email' size='40'
maxlength='64' value='$email' /></td></tr>
<tr><th>New Password (or leave blank to leave password unchanged):</th>
<td><input type='password' name='pw1' size='40'
maxlength='128' /></td></tr>
<tr><th>New Password Again (must match):</th>
<td><input type='password' name='pw2' size='40'
maxlength='128' /></td></tr>
</tbody>
</table>
</form>
HTML;
}
?>