This repository has been archived by the owner on Feb 10, 2020. It is now read-only.
/
index.php
1146 lines (847 loc) · 31.3 KB
/
index.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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// We use this same text file for editing a user's details (both THEUSER's and
// a different user's), and letting a new user join.
// This means we can keep all the form validation and display code in one place.
/* What happens?
1) We check what $this_page is going to be. This depends on:
* the value of $pg, if anything;
* whether $THEUSER is logged in or not;
* whether $THEUSER has appropriate security privileges;
* and whether we've been passed the ID of a user to view/edit.
2) If we've come to this page after submitting its form, we check the form data.
If the data is OK, we either edit or add the user and display the new info.
If there were errors, the same form is displayed again with error messages.
3) On the other hand, if the form hasn't been submitted we've just arrived here.
In that case the form (or the user info, if just viewing) is displayed.
After the first part of working out which page we're on, and munging any data
various functions in this file are used:
check_input() Validates the edited or added user data and creates error messages.
add_user() Calls $THEUSER->add() and displays the results, depending on success.
update_user() Calls the appropriate functions and updates, displays results.
display_form() Displays the form for editing or adding a user.
display_user() Displays a user's details.
*/
include_once "../../includes/easyparliament/init.php";
include_once "../../includes/easyparliament/member.php";
// Which page we're on all depends on the value of the "pg" variable...
switch (get_http_var("pg")) {
case "join": // A new user signing up.
$this_page = "userjoin";
break;
case "editother": // Editing someone else's info.
// We need a user_id. So make sure that exists.
// And make sure the user is allowed to do this!
if (is_numeric( get_http_var("u") ) && $THEUSER->is_able_to("edituser")) {
$this_page = "otheruseredit";
} else {
// Revert to editing THEUSER's own info.
$this_page = "useredit";
}
break;
case "edit": // Edit this user's owninfo.
if ($THEUSER->isloggedin()) {
$this_page = "useredit";
} else {
// Unlikely to get to this page without being logged in,
// but just in case, show them the blank form.
$this_page = "userjoin";
}
break;
default:
if ($THEUSER->isloggedin() &&
(get_http_var('u') == '' || get_http_var('u') == $THEUSER->user_id())
) {
// Logged in user viewing their own details.
$this_page = 'userviewself';
} else {
// Viewing someone else's details.
$this_page = "userview";
}
}
// A little detail... we want to change text in the page depending on whose
// info is being changed or added.
$who = $this_page == "otheruseredit" ? "the user's" : "your";
if (get_http_var("submitted") == "true") {
// The edit or join form has been submitted, so check input.
// Put all the user-submitted data in an array.
$details = array();
$details["firstname"] = trim(get_http_var("firstname"));
$details["lastname"] = trim(get_http_var("lastname"));
$details["email"] = trim(get_http_var("em"));
// We use boolean true/false internally. Convert the text from the form to boolean.
$details["emailpublic"] = get_http_var("emailpublic") == "true" ? true : false;
$details["password"] = trim(get_http_var("password"));
$details["password2"] = trim(get_http_var("password2"));
$details["optin"] = get_http_var("optin") == "true" ? true : false;
$details['mp_alert'] = get_http_var('mp_alert') == 'true' ? true : false;
if (get_http_var("remember") != "") {
$remember = get_http_var("remember");
$details["remember"] = $remember[0] == "true" ? true : false;
}
$details["postcode"] = trim(get_http_var("postcode"));
$details["url"] = trim(get_http_var("url"));
if ($details['url'] != '' && !preg_match('/^http/', $details['url'])) {
$details['url'] = 'http://' . $details['url'];
}
if ($this_page == "otheruseredit") {
$details["user_id"] = trim(get_http_var("u"));
$details["status"] = trim(get_http_var("status"));
if (get_http_var("deleted") != "") {
$deleted = get_http_var("deleted");
$details["deleted"] = $deleted[0] == "true" ? true : false;
} else {
$details['deleted'] = false;
}
if (get_http_var("confirmed") != "") {
$confirmed = get_http_var("confirmed");
$details["confirmed"] = $confirmed[0] == "true" ? true : false;
} else {
$details['confirmed'] = false;
}
}
//$details['status'] = $THEUSER->status();
// Check the input.
// If there are any errors with the submission, $errors (an array)
// will have elements. The keys will be the name of form elements,
// and the values will be text to display when we show the form again.
$errors = check_input($details);
if (sizeof($errors) > 0) {
// Validation errors. Print form again.
$PAGE->page_start();
display_form($details, $errors);
$PAGE->page_end();
} elseif ($this_page == "userjoin") {
// No errors so far, so try to sign up and log in.
add_user( $details );
} else {
// No errors so far, editing an existing user,
// $this_page == "useredit" or "otheruseredit".
update_user( $details );
}
} else {
// THEUSER has just arrived at this page, no form submitted.
if ($this_page == "userview" || $this_page == 'userviewself') {
display_user ();
} else {
$PAGE->page_start();
if ($this_page == "useredit") {
// We're editing THEUSER's own info, so set all the vars.
$details = array();
$details["firstname"] = $THEUSER->firstname();
$details["lastname"] = $THEUSER->lastname();
$details["email"] = $THEUSER->email();
$details["emailpublic"] = $THEUSER->emailpublic();
$details["password"] = $THEUSER->password();
$details["optin"] = $THEUSER->optin();
$details["postcode"] = $THEUSER->postcode();
$details["url"] = $THEUSER->url();
$details["status"] = $THEUSER->status();
// display the form with this user's info.
display_form ($details);
} elseif ($this_page == "otheruseredit") {
// We're editing the info of a different user.
// So set up a new user object with the id supplied
// and get the user's info.
$USER = new USER;
$USER->init( get_http_var("u") );
$details = array();
$details["user_id"] = $USER->user_id();
$details["firstname"] = $USER->firstname();
$details["lastname"] = $USER->lastname();
$details["email"] = $USER->email();
$details["emailpublic"] = $USER->emailpublic();
$details["password"] = $USER->password();
$details["optin"] = $USER->optin();
$details["postcode"] = $USER->postcode();
$details["url"] = $USER->url();
$details["status"] = $USER->status();
$details["deleted"] = $USER->deleted();
$details["confirmed"] = $USER->confirmed();
// Display the form with the other user's info.
display_form ($details);
} else {
// $this_page == "userjoin".
// Display a blank form.
display_form ();
}
$PAGE->page_end();
}
}
function check_input ($details) {
global $THEUSER, $this_page, $who;
// This may be a URL that will send the user back to where they were before they
// wanted to join.
$ret = get_http_var("ret");
$errors = array();
// Check each of the things the user has input.
// If there is a problem with any of them, set an entry in the $errors array.
// This will then be used to (a) indicate there were errors and (b) display
// error messages when we show the form again.
// Check first name.
if ($details["firstname"] == "") {
$errors["firstname"] = "Please enter $who first name";
}
// They don't need a last name. In case Madonna joins.
// Check email address is valid and unique.
if ($details["email"] == "") {
$errors["email"] = "Please enter $who email address";
} elseif (!validate_email($details["email"])) {
// validate_email() is in includes/utilities.php
$errors["email"] = "Please enter a valid email address";
} else {
$USER = new USER;
$id_of_user_with_this_addresss = $USER->email_exists($details["email"]);
if ($this_page == "useredit" &&
get_http_var("u") == "" &&
$THEUSER->isloggedin()) {
// User is updating their own info.
// Check no one else has this email.
if ($id_of_user_with_this_addresss &&
$id_of_user_with_this_addresss != $THEUSER->user_id()) {
$errors["email"] = "Someone else has already joined with this email address";
}
} else {
// User is joining. Check no one is already here with this email.
if ($this_page == "userjoin" && $id_of_user_with_this_addresss) {
$errors["email"] = "There is already a user with this email address";
}
}
}
// Check passwords.
if ($this_page == "userjoin") {
// Only *must* enter a password if they're joining.
if ($details["password"] == "") {
$errors["password"] = "Please enter $who password";
} elseif (strlen($details["password"]) < 6) {
$errors["password"] = "Please enter at least six characters";
}
if ($details["password2"] == "") {
$errors["password2"] = "Please enter $who password again";
}
if ($details["password"] != "" && $details["password2"] != "" && $details["password"] != $details["password2"]) {
$errors["password"] = ucfirst($who) . " passwords did not match. Please try again.";
}
} else {
// Update details pages.
if ($details["password"] != "" && strlen($details["password"]) < 6) {
$errors["password"] = "Please enter at least six characters";
}
if ($details["password"] != $details["password2"]) {
$errors["password"] = ucfirst($who) . " passwords did not match. Please try again.";
}
}
// Check postcode (which is not a compulsory field).
if ($details["postcode"] != "" && !validate_postcode($details["postcode"])) {
$errors["postcode"] = "Sorry, this isn't a valid UK postcode.";
}
// No checking of URL.
if ($this_page == "otheruseredit") {
// We're editing another user's info.
// Could check status here...?
}
// Send the array of any errors back...
return $errors;
}
function add_user ( $details) {
global $THEUSER, $PAGE, $this_page;
// If this goes well, the user will have their data
// added to the database and a confirmation email
// will be sent to them.
$success = $THEUSER->add ( $details );
if ($success) {
// No validation errors.
$this_page = 'userwelcome';
$PAGE->page_start();
$PAGE->stripe_start();
$message = array(
'title' => "We're nearly done...",
'text' => "You should receive an email shortly which will contain a link. You will need to follow that link to confirm your email address before you can log in. Thanks."
);
$PAGE->message($message);
$PAGE->stripe_end();
/* We used to log the user in straight away.
Now we send them a confirmation email.
Keeping this code here, just in case.
Note that you'll probably have to add the 'remember' checkbox
back into the sign-up form.
// Does this user want to a long-term cookie?
if (isset($details["remember"]) && $details["remember"]) {
$expire = "never";
} else {
$expire ="session";
}
// Wherever the user ends up next, we'll display a welcome message to them
// indicated by the 'newuser' element in the URL....
// $ret might be a URL that will take the user back to where they
// where before joining.
if (get_http_var("ret") != "") {
$url = get_http_var("ret");
// We're now going to have to fudge things a bit. Want to add "newuser=1"
// on to the end of wherever we were before, so a welcome message will
// be displayed.
if (preg_match("/\?.+/", $url)) {
$url .= "&newuser=1";
} else {
$url .= "?newuser=1";
}
} else {
// We'll send the user to the front page after they've joined.
$URL = new URL("home");
$URL->insert(array("newuser"=>"1"));
$url = $URL->generate();
}
// Log the new user in. They'll be sent off elsewhere, so we don't output any
// HTML here.
$THEUSER->login($url, $expire);
*/
} else {
// Something went wrong, so display the form (with error messages).
$this_page = 'userjoin';
$PAGE->page_start();
$errors["db"] = "Sorry, we were unable to create an account for you. Please <a href=\"mailto:". CONTACTEMAIL . "\">let us know</a>. Thanks.";
display_form( $details, $errors);
}
$PAGE->page_end();
}
function update_user ( $details ) {
global $THEUSER, $this_page, $PAGE, $who;
// There were no errors when the edit user form was submitted,
// so make the changes in the DB.
// Who are we updating? $THEUSER or someone else?
if ($this_page == "otheruseredit") {
// Someone else.
$success = $THEUSER->update_other_user ( $details );
// For displaying the altered info.
$user_id = $details["user_id"];
} else {
// $this_page == "useredit"
$success = $THEUSER->update_self ( $details );
// For displaying the altered info.
$user_id = $THEUSER->user_id;
}
if ($success) {
// No errors, all updated, show results.
if ($this_page == 'otheruseredit') {
$this_page = "userview";
} else {
$this_page = "userviewself";
}
display_user( $user_id );
} else {
// Something went wrong.
$PAGE->page_start();
$errors["db"] = "Sorry, we were unable to update $who details. Please <a href=\"mailto:" . CONTACTEMAIL . "\">let us know</a> what you were trying to change. Thanks.";
display_form($details, $errors);
$PAGE->page_end();
}
}
function display_form ( $details = array(), $errors = array() ) {
global $this_page, $THEUSER, $who, $PAGE;
$PAGE->stripe_start();
if (isset($errors["db"])) {
$PAGE->error_message($errors["db"]);
} else {
$URL = new URL("userlogin");
$URL->insert(array('ret'=>get_http_var('ret')));
if (!$THEUSER->isloggedin()) {
?>
<p>Already joined? <a href="<?php echo $URL->generate(); ?>">Then sign in!</a></p>
<?php
}
}
$ACTIONURL = new URL($this_page);
$ACTIONURL->reset();
?>
<form method="post" action="<?php echo $ACTIONURL->generate(); ?>">
<?php
if ($this_page == "otheruseredit") {
?>
<div class="row">
<span class="label">User ID:</span>
<span class="formw"><?php echo htmlentities($details["user_id"]); ?></span>
</div>
<?php
}
if ($this_page == 'useredit' && isset($details['status'])) {
?>
<div class="row">
<span class="label">Status:</span>
<span class="formw"><?php echo htmlentities($details['status']); ?></span>
</div>
<?php
}
if (isset($errors["firstname"])) {
$PAGE->error_message($errors["firstname"]);
}
?>
<div class="row">
<span class="label"><label for="firstname">Your first name:</label></span>
<span class="formw"><input type="text" name="firstname" id="firstname" value="<?php if (isset($details["firstname"])) { echo htmlentities($details["firstname"]); } ?>" maxlength="255" size="30" class="form"></span>
</div>
<?php
if (isset($errors["lastname"])) {
$PAGE->error_message($errors["lastname"]);
}
?>
<div class="row">
<span class="label"><label for="lastname">Your last name:</label></span>
<span class="formw"><input type="text" name="lastname" id="lastname" value="<?php if (isset($details["lastname"])) { echo htmlentities($details["lastname"]); } ?>" maxlength="255" size="30" class="form"></span>
</div>
<?php
if (isset($errors["email"])) {
$PAGE->error_message($errors["email"]);
}
?>
<div class="row">
<span class="label"><label for="em">Email address:</label></span>
<span class="formw"><input type="text" name="em" id="em" value="<?php if (isset($details["email"])) { echo htmlentities($details["email"]); } ?>" maxlength="255" size="30" class="form"></span>
</div>
<?php
if ($this_page == "useredit" || $this_page == "otheruseredit") {
// If not, the user's joining.
?>
<div class="row">
<br><small>To change <?php echo $who; ?> password enter a new one twice below (otherwise, leave blank).</small>
</div>
<?php
}
if (isset($errors["password"])) {
$PAGE->error_message($errors["password"]);
}
?>
<div class="row">
<span class="label"><label for="password">Password:</label></span>
<span class="formw"><input type="password" name="password" id="password" value="" maxlength="30" size="20" class="form"> <small>At least six characters</small></span>
</div>
<?php
if (isset($errors["password2"])) {
$PAGE->error_message($errors["password2"]);
}
?>
<div class="row">
<span class="label"><label for="password2">Repeat password:</label></span>
<span class="formw"><input type="password" name="password2" id="password2" value="" maxlength="30" size="20" class="form"></span>
</div>
<br style="clear: left;"> <br>
<?php
if (isset($errors["postcode"])) {
$PAGE->error_message($errors["postcode"]);
}
?>
<div class="row">
<span class="label"><label for="postcode">Your UK postcode:</label></span>
<span class="formw"><input type="postcode" name="postcode" id="postcode" value="<?php if (isset($details["postcode"])) { echo htmlentities($details["postcode"]); } ?>" maxlength="10" size="10" class="form"> <small>Optional and not public</small></span>
</div>
<?php
if (isset($errors["url"])) {
$PAGE->error_message($errors["url"]);
}
?>
<div class="row">
<span class="label"><label for="url">Your website:</label></span>
<span class="formw"><input type="url" name="url" id="url" value="<?php if (isset($details['url'])) { echo htmlentities($details['url']); } ?>" maxlength="255" size="20" class="form"> <small>Optional and public</small></span>
</div>
<div class="row">
<br>Let other users see <?php echo $who; ?> email address?
</div>
<?php
if (isset($errors["emailpublic"])) {
$PAGE->error_message($errors["emailpublic"]);
}
?>
<div class="row">
<span class="label"> </span>
<span class="formw"><input type="radio" name="emailpublic" id="emailpublictrue" value="true"<?php
if (isset($details["emailpublic"]) && $details["emailpublic"] == true) {
print " checked";
}
?>> <label for="emailpublictrue">Yes</label><br>
<input type="radio" name="emailpublic" id="emailpublicfalse" value="false"<?php
if (($this_page == "userjoin" && get_http_var("submitted") != "true")
||
(isset($details["emailpublic"]) && $details["emailpublic"] == false)
) {
print " checked";
}
?>> <label for="emailpublicfalse">No</label></span>
</div>
<div class="row">
<br>Do <?php if ($this_page == "otheruseredit") { echo "they"; } else { echo "you"; } ?> wish to receive occasional update emails about TheyWorkForYou.com?
</div>
<?php
if (isset($errors["optin"])) {
$PAGE->error_message($errors["optin"]);
}
?>
<div class="row">
<span class="label"> </span>
<span class="formw"><input type="radio" name="optin" id="optintrue" value="true"<?php
if (isset($details["optin"]) && $details["optin"] == true) {
print " checked";
}
?>> <label for="optintrue">Yes</label><br>
<input type="radio" name="optin" id="optinfalse" value="false"<?php
if (($this_page == "userjoin" && get_http_var("submitted") != "true")
||
(isset($details["optin"]) && $details["optin"] == false)
) {
print " checked";
}
?>> <label for="optinfalse">No</label></span>
</div>
<?php if ($this_page == 'userjoin') { ?>
<div class="row">
<br>Would <?php if ($this_page == "otheruseredit") { echo "they"; } else { echo "you"; } ?> like to receive an email whenever your MP does something in Parliament?
<br><small> (if you're already getting email alerts to your address, don't worry about this)</small>
</div>
<div class="row">
<span class="label"> </span>
<span class="formw"><input type="radio" name="mp_alert" id="mp_alerttrue" value="true"<?php
if (isset($details["mp_alert"]) && $details["mp_alert"] == true) {
print ' checked';
}
?>> <label for="mp_alerttrue">Yes</label><br>
<input type="radio" name="mp_alert" id="mp_alertfalse" value="false"<?php
if (($this_page == "userjoin" && get_http_var("submitted") != "true")
||
(isset($details["mp_alert"]) && $details["mp_alert"] == false)
) {
print ' checked';
}
?>> <label for="mp_alertfalse">No</label></span>
</div>
<?php }
if ($this_page == "otheruseredit") {
if (isset($errors["status"])) {
$PAGE->error_message($errors["status"]);
}
?>
<div class="row">
<span class="label">Security status:</span>
<span class="formw"><select name="status">
<?php
$USER = new USER;
$statuses = $USER->possible_statuses();
foreach ($statuses as $n => $status) {
print "\t<option value=\"$status\"";
if ($status == $details["status"]) {
print " checked";
}
print ">$status</option>\n";
}
?>
</select></span>
</div>
<div class="row">
<span class="label"><label for="confirmed">Confirmed?</label></span>
<span class="formw"><input type="checkbox" name="confirmed[]" id="confirmed" value="true"<?php
if (isset($details["confirmed"]) && $details["confirmed"] == true) {
print " checked";
}
?>></span>
</div>
<div class="row">
<span class="label"><label for="deleted">"Deleted"?</label></span>
<span class="formw"><input type="checkbox" name="deleted[]" id="deleted" value="true"<?php
if (isset($details["deleted"]) && $details["deleted"] == true) {
print " checked";
}
?>> <small>(No data will actually be deleted.)</small></span>
</div>
<?php
}
if ($this_page == "useredit" || $this_page == "otheruseredit") {
$submittext = "Update details";
} else {
$submittext = "Join TheyWorkForYou.com";
}
$TERMSURL = new URL('houserules');
?>
<div class="row">
<span class="label"> </span>
<span class="formw"> <br><small>Read our <a href="<?php echo $TERMSURL->generate(); ?>">Terms of Use</a>.</small></span>
</div>
<div class="row">
<span class="label"> </span>
<span class="formw"><input type="submit" class="submit" value="<?php echo $submittext; ?>"><!-- this space makes the submit button appear on Mac IE 5! --> </span>
</div>
<input type="hidden" name="submitted" value="true">
<?php
if (get_http_var("ret") != "") {
// The user was probably trying to add a writer but is joining first.
?>
<input type="hidden" name="ret" value="<?php echo htmlentities(get_http_var("ret")); ?>">
<?php
}
if (get_http_var("pg") != "") {
// So that we get to the right page.
?>
<input type="hidden" name="pg" value="<?php echo htmlentities(get_http_var("pg")); ?>">
<?php
}
if ($this_page == "otheruseredit") {
// Need to store the id of the user we're editing.
?>
<input type="hidden" name="u" value="<?php echo htmlentities($details["user_id"]); ?>">
<?php
}
?>
</form>
<?php
if ($this_page == 'userjoin') {
$PAGE->stripe_end(array (
array (
'type' => 'include',
'content' => 'userjoin'
)
));
} else {
$PAGE->stripe_end();
}
} // End display_form()
function display_user ($user_id="") {
global $THEUSER, $PAGE, $DATA, $this_page, $who;
// We're either going to be:
// Displaying the details of a user who's just been edited
// (their user_id will be in $user_id now).
// Viewing THEUSER's own data.
// Viewing someone else's data (their id will be in the GET string
// user_id variable).
// We could do something cleverer so that if THEUSER has sufficient
// privileges we display more data when they're viewing someone else's info
// than what your average punter sees.
// If $user_id is a user id, we've just edited that user's info.
// FIRST: Work out whose info we're going to show.
$edited = false; // Have we just edited someone's info?
if (is_numeric($user_id) && $user_id == $THEUSER->user_id()) {
// Display this user's just edited info.
$display = "this user";
$edited = true;
} elseif (is_numeric($user_id)) {
// Display someone else's just edited info.
$display = "another user";
$edited = true;
} elseif (is_numeric(get_http_var("u"))) {
// Display someone else's info.
$user_id = get_http_var("u");
$display = "another user";
} elseif ($THEUSER->isloggedin()) {
// Display this user's info.
$display = "this user";
$user_id = $THEUSER->user_id();
} else {
// Nothing to show!
$URL = new URL('userlogin');
$URL->insert(array('ret'=>'/user/'));
$loginurl = $URL->generate();
header("Location: $loginurl");
exit;
}
// SECOND: Get the data for whoever we're going to show.
$db = new ParlDB;
if ($display == "another user") {
// Viewing someone else's info.
$USER = new USER;
$valid = $USER->init($user_id);
if ($valid && $USER->confirmed() && !$USER->deleted()) {
// Don't want to display unconfirmed or deleted users.
$name = $USER->firstname() . " " . $USER->lastname();
$url = $USER->url();
if ($USER->emailpublic() == true) {
$email = $USER->email();
}
$status = $USER->status();
$registrationtime = $USER->registrationtime();
// Change the page title to reflect whose info we're viewing.
$DATA->set_page_metadata($this_page, "title", "$name");
$q = $db->query('select count(*) as c from video_timestamps where deleted=0 and user_id= ' . $USER->user_id());
$video = $q->field(0, 'c');
} else {
// This user_id doesn't exist.
$display = "none";
}
} elseif ($display == "this user") {
// Display THEUSER's info.
$name = $THEUSER->firstname() . " " . $THEUSER->lastname();
$url = $THEUSER->url();
if ($edited) {
// We want to show all the info to the user.
$email = $THEUSER->email();
$emailpublic = $THEUSER->emailpublic() == true ? "Yes" : "No";
$optin = $THEUSER->optin() == true ? "Yes" : "No";
$postcode = $THEUSER->postcode();
} else {
// We're showing them how they're seen to other people.
if ($THEUSER->emailpublic()) {
$email = $THEUSER->email();
}
$registrationtime = $THEUSER->registrationtime();
$status = $THEUSER->status();
}
$q = $db->query('select count(*) as c from video_timestamps where deleted=0 and user_id= ' . $THEUSER->user_id());
$video = $q->field(0, 'c');
// Change the page title to make it clear we're viewing THEUSER's
// own info. Make them less worried about other people seeing some of the
// info that shouldn't be public.
$DATA->set_page_metadata($this_page, "title", "Your details");
} else {
// There's nothing to display!
}
// THIRD: Print out what we've got.
$PAGE->page_start();
if ($display != "none") {
$PAGE->stripe_start();
if (isset($registrationtime)) {
// Make registration time more user-friendly.
list($date, $time) = explode(' ', $registrationtime);
$registrationtime = format_date ($date, LONGDATEFORMAT);
}
if ($edited) {
print "\t\t\t\t<p><strong>" . ucfirst($who) . " details have been updated:</strong></p>\n";
}
if ($this_page == 'userviewself' && !$edited) {
$EDITURL = new URL('useredit');
?>
<p><strong>This is how other people see you.</strong> <a href="<?php echo $EDITURL->generate(); ?>">Edit your details</a>.</p>
<?php
}
?>
<div class="row">
<span class="label">Name</span>
<span class="formw"><?php
if (substr($name, -3) == ' MP') print '<a href="/mp/' . make_member_url(substr($name, 0, -3)) . '">';
echo htmlentities($name);
if (substr($name, -3) == ' MP') print '</a>';
?></span>
</div>
<div class="row">
<span class="label">Email</span>
<span class="formw"><?php
if (isset($email)) {
$escaped_email = str_replace('@', '@', htmlentities($email));
?><a href="mailto:<?php echo $escaped_email . "\">" . $escaped_email; ?></a><?php
} else {
?>Not public<?php
}
?></span>
</div>
<?php