forked from mholt/ysaward
-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.php
386 lines (318 loc) · 11.5 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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
<?php
require_once("lib/init.php");
protectPage();
// Parse the apartment/address for display
$unit = $MEMBER->Apartment;
// Get parts of the birth date
$date = date('F d, Y', strtotime($MEMBER->Birthday));
// Build month list
$months = array("January", "February", "March", "April",
"May", "June", "July", "August", "September", "October",
"November", "December");
// Profile picture filename
$profilePic = $MEMBER->PictureFile();
// Get a list of residences in the ward so the user can conveniently pick one
$residences = $WARD->Residences();
// Get the member's current residence
$currentResidence = $MEMBER->Residence();
$isCustom = $currentResidence ? $currentResidence->Custom() : false;
?>
<!DOCTYPE html>
<html>
<head>
<title>Edit profile — <?php echo $WARD ? $WARD->Name." Ward" : SITE_NAME; ?></title>
<?php include "includes/head.php"; ?>
<style>
#chgward {
display: none;
}
select {
margin-bottom: .5em;
}
#ppic {
max-width: <?php echo Member::MEDIUM_DIM / 2; ?>px;
max-height: <?php echo Member::MEDIUM_DIM / 2; ?>px;
}
#pic {
line-height: 1em;
}
</style>
</head>
<body>
<?php include "includes/header.php"; ?>
<form method="post" action="/api/saveprofile" class="narrow" autocomplete="off">
<div class="text-center">
<h1>Edit profile</h1>
</div>
<fieldset>
<legend>
Email and password
</legend>
<input type="email" name="email" placeholder="Email address" maxlength="255" value="<?php echo htmlentities($MEMBER->Email); ?>" required autocomplete="off">
<input type="password" name="oldpwd" placeholder="Current password" autocomplete="off">
<input type="password" name="pwd1" placeholder="New password" autocomplete="off">
<input type="password" name="pwd2" placeholder="New password again" autocomplete="off">
</fieldset>
<br>
<fieldset>
<legend>
Personal
</legend>
<input type="text" name="fname" placeholder="First name" maxlength="45" value="<?php echo htmlentities($MEMBER->FirstName); ?>" required>
<input type="text" name="mname" placeholder="Middle name or initial" maxlength="45" value="<?php echo htmlentities($MEMBER->MiddleName); ?>">
<input type="text" name="lname" placeholder="Last name" maxlength="45" value="<?php echo htmlentities($MEMBER->LastName); ?>" required>
<hr>
<input type="text" name="dob" id="dob" placeholder="Date of birth" maxlength="100" value="<?php echo $date; ?>" required>
<input type="tel" name="phone" placeholder="Phone number" maxlength="20" value="<?php echo htmlentities($MEMBER->PhoneNumber); ?>">
<hr>
<div class="text-center">
<input type="radio" name="gender" data-label="I'm a guy" value="<?php echo Gender::Male; ?>"<?php echo $MEMBER->Gender == Gender::Male ? ' checked' : ''; ?>>
<input type="radio" name="gender" data-label="I'm a girl" value="<?php echo Gender::Female; ?>"<?php echo $MEMBER->Gender == Gender::Female ? ' checked' : ''; ?>>
</div>
</fieldset>
<br>
<fieldset>
<legend>
Where you live
</legend>
<!-- HOUSING -->
<select size="1" name="resID" id="bldg" required>
<option value=""<?php if (!$currentResidence) echo ' selected'; ?>>Housing...</option>
<?php foreach ($residences as $residence): ?>
<option value="<?php echo $residence->ID(); ?>"<?php if ($currentResidence && $currentResidence->ID() == $residence->ID()) echo ' selected'; ?>><?php echo $residence->Name; if (!$residence->NameUnique()) echo ' ('.$residence->Address.')'; ?></option>
<?php endforeach; ?>
<option value="-"<?php if ($isCustom) echo ' selected'; ?>>(Other)</option>
</select>
<span id="usualapt"<?php if ($isCustom) echo ' style="display: none;"'; ?>>
<input type="text" name="aptnum" maxlength="4" placeholder="Unit #"<?php if ($unit) echo ' value="'.htmlentities($unit).'"'; ?>>
</span>
<span id="otherapt"<?php if (!$isCustom) echo ' style="display: none;"'; ?>>
<input type="text" id="address" placeholder="Your full address" name="address" size="45" maxlength="255"<?php if ($isCustom) echo ' value="'.htmlentities($currentResidence->String()).'"'; ?>>
</span>
<input type="hidden" name="streetAddress" id="streetAddress" value="">
<input type="hidden" name="city" id="city" value="">
<input type="hidden" name="state" id="state" value="">
<input type="hidden" name="zipcode" id="zipcode" value="">
<!-- END HOUSING -->
</fieldset>
<br>
<fieldset>
<legend>
<input type="checkbox" data-label="Change ward" id="change-ward">
</legend>
<div id="chgward">
<?php require "includes/controls/wardpicker.php"; ?>
<input type="password" name="wardpwd" id="wardpwd" placeholder="Ward password">
</div>
</fieldset>
<script>
// TODO: Move this in permanently with the JS on this page when finished...
$(function() {
$('#wardid').val('');
$('#change-ward').change(function() {
if ($(this).is(':checked'))
$('#chgward').slideDown().find('input, select').prop('required', true);
else
$('#chgward').slideUp().find('input, select').prop('required', false);
});
});
</script>
<hr>
<fieldset id="pic">
<legend>
Current profile picture
</legend>
<img src="<?php echo $profilePic; ?>" id="ppic">
<hr>
<legend style="margin-bottom: 1em;">
Change picture
</legend>
<small>
<i>
<b>This is very important!</b>
<br>
Please choose a picture with just you in it,
<br>
then submit the form to save your new picture.
<br>
(Max size: 5 MB)
</i>
</small>
<br><br>
<input type="file" name="profilepic" id="profilepic" accept="image/jpeg" style="font-size: 16px;">
</fieldset>
<br>
<fieldset>
<legend>
Privacy
</legend>
<div class="text-left">
<input type="checkbox" data-label="Keep birth year private" checked disabled>
<input type="checkbox" name="hideBirthday" data-label="Keep birth month and day private"<?php if ($MEMBER->HideBirthday) echo ' checked'; ?>>
<input type="checkbox" name="hidePhone" data-label="Keep phone number private"<?php if ($MEMBER->HidePhone) echo ' checked'; ?>>
<input type="checkbox" name="hideEmail" data-label="Keep email address private"<?php if ($MEMBER->HideEmail) echo ' checked'; ?>>
<br><br>
<input type="checkbox" name="receiveSms" data-label="Receive occasional ward-related texts"<?php if ($MEMBER->ReceiveTexts) echo ' checked'; ?>>
</div>
</fieldset>
<hr>
<div class="text-center">
<button type="submit">Save</button>
<br>
<br>
</div>
</form>
<?php include "includes/footer.php"; ?>
<?php include "includes/nav.php"; ?>
<script src="//d79i1fxsrar4t.cloudfront.net/jquery.liveaddress/2.4/jquery.liveaddress.min.js"></script>
<script>
$(function()
{
// Stores a custom address in case the user hides then displays it again (cross-browserness)
var addrCache = $('#address').val();
// Functionality for changing wards (ward picker)
$('#wardid').val('');
$('#change-ward').change(function() {
if ($(this).is(':checked'))
$('#chgward').slideDown().find('input, select').prop('required', true);
else
$('#chgward').slideUp().find('input, select').prop('required', false);
});
// Verify date of birth is a good date format
$('#dob').change(function()
{
$.get('/api/tryparsedate', {
input: $(this).val(),
strictMonthDayYear: '1'
})
.success(function()
{
$(this).css('color', '');
$('[type=submit]').prop('disabled', false);
})
.fail(function(jqxhr)
{
$(this).css('color', '#CC0000');
$('[type=submit]').prop('disabled', true);
$.sticky(jqxhr.responseText || "Please type a better date, for example: July 3, 1990.", { classList: "error" });
});
});
$('#bldg').change(function()
{
if ($(this).val() == "-")
{
// Show the "full address" field
$('#usualapt input').prop('required', false);
$('#address').val(addrCache);
$('#usualapt').hide();
$('#otherapt').show();
$('#otherapt input').prop('required', true).focus();
liveaddress.mapFields('auto');
}
else if ($(this).val() != "")
{
// Show the "unit number" field
$('#otherapt input').prop('required', false);
$('#otherapt').hide();
addrCache = $('#address').val();
$('#address').val();
$('#usualapt').show();
$('#usualapt input').prop('required', true).focus();
liveaddress.deactivate();
}
else
{
$('#usualapt input, #otherapt input').prop('required', false);
$('#usualapt, #otherapt').hide();
liveaddress.deactivate();
}
});
// ajaxForm from: http://malsup.com/jquery/form/progress.html
// (Also on GitHub; documentation is lame: https://github.com/malsup/form)
// The code below sup(*love*ports a progress bar which I haven't bothered
// to implement yet.
// We use this plugin instead of hijax because hijax doesn't support
// file uploads...
//var bar = $('.bar');
//var percent = $('.percent');
//var status = $('#status');
var hasPic = false;
$('form').ajaxForm({
beforeSend: function(formData, jqForm, options)
{
//var queryString = $.param(formData); // Not needed, just an example. -- actually, this and the arguments go for "beforeSubmit" callback
//status.empty();
//var percentVal = '0%';
//bar.width(percentVal)
//percent.html(percentVal);
hasPic = $('#profilepic').val().length > 0;
$('[type=submit]').showSpinner();
},
uploadProgress: function(event, position, total, percentComplete)
{
// Also not needed, but here in case we implement it
//var percentVal = percentComplete + '%';
//bar.width(percentVal)
//percent.html(percentVal);
},
complete: function(jqxhr)
{
if (jqxhr.status == 200)
{
_gaq.push(['_trackEvent', 'Account', 'Submit Form', 'Edit Profile']);
if ($('#wardpwd').is(':visible'))
{
$.sticky("Redirecting...");
setTimeout(function() { window.location = "/answers?new"; }, 1500);
}
$.sticky(jqxhr.responseText || "Saved your profile!");
if (hasPic)
{
$.hijax({
url: '/api/currentmemberpicturepath',
complete: function(jqxhr) {
$('#ppic').show().attr('src', jqxhr.responseText);
hasPic = false;
}
});
}
}
else
$.sticky(jqxhr.responseText || "There might have been a problem. Please check your Internet connection and try again.", { classList: "error" });
$('[type=submit]').hideSpinner();
}
});
});
var liveaddress = $.LiveAddress({
key: "<?php echo SMARTYSTREETS_HTML_KEY; ?>",
autoMap: false
});
<?php if ($isCustom): ?>
$('#usualapt input').removeAttr('required');
liveaddress.mapFields("auto");
<?php endif; ?>
liveaddress.on("AddressAccepted", function(event, data, previousHandler)
{
if (data.response.isMissingSecondary())
{
data.address.abort(event);
alert("Don't forget your apartment number!");
}
else
{
if (data.response.chosen)
fillOutAddressFields(data.response.chosen);
previousHandler(event, data);
}
});
function fillOutAddressFields(responseAddr)
{
$('#streetAddress').val(responseAddr.delivery_line_1);
$('#city').val(responseAddr.components.city_name);
$('#state').val(responseAddr.components.state_abbreviation);
$('#zipcode').val(responseAddr.components.zipcode); // 5-digit only; this is on purpose
}
</script>
</body>
</html>