forked from howest-wsde/owaes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.user.php
2387 lines (2201 loc) · 91.1 KB
/
class.user.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
define ("GETSET", 1);
define ("ADD", 2);
define ("VISIBILITY_HIDDEN", 0);
define ("VISIBILITY_VISIBLE", 1);
define ("VISIBILITY_FRIENDS", 2);
define ("FRIEND_NOFRIENDS", 0);
define ("FRIEND_ASKED", 1); // de andere heeft invite gestuurd
define ("FRIEND_REQUESTED", 2); // ik heb reeds aanvraag gedaan
define ("FRIEND_FRIENDS", 10);
$ar_GLOBAL_users = array();
function user($iID = NULL) { // FUNCTION user(5) == CLASS new user(5) // Enkel ID !
global $ar_GLOBAL_users;
if (!isset($ar_GLOBAL_users[$iID])) {
$oUser = new user($iID);
$ar_GLOBAL_users[$iID] = &$oUser;
}
return $ar_GLOBAL_users[$iID];
}
function loadedUsers(){
global $ar_GLOBAL_users;
$arUsers = array();
foreach ($ar_GLOBAL_users as $iID=>$oUser) $arUsers[] = intval($iID);
return $arUsers;
}
class user {
private $iID = NULL;
private $strAlias = NULL;
private $strLogin = NULL;
private $strFirstname = NULL;
private $strLastname = NULL;
private $strEmail = NULL;
private $strDescription = NULL;
private $strIMG = NULL;
private $strPassword = NULL;
private $strLocation = NULL;
private $strTelephone = NULL;
private $strGender = NULL;
private $ibirthdate = NULL;
private $iLocationLat = NULL;
private $iLocationLong = NULL;
private $arBadges = NULL;
private $arCertificates = NULL;
private $arPayments = NULL;
private $iStars = NULL;
private $iCredits = NULL;
private $bIsCurrentUser;
private $iPhysical = NULL;
private $iMental = NULL;
private $iEmotional = NULL;
private $iSocial = NULL;
private $iLastUpdate = NULL;
private $arGroups = NULL;
private $iPosts = NULL;
private $iSubscriptions = NULL;
private $arBestanden = NULL;
private $iLevel = NULL;
private $bVisible = NULL;
private $oExperience = NULL;
private $arVisible = array();
private $bUnlocked = FALSE; // als user unlocked wordt (->unlock() ) kan e-mailadres en dergelijke ook opgevraagd worden zonder vriend te moeten zijn
private $arData = NULL;
private $iFriendStatus = NULL;
private $bAdmin = NULL;
private $arFollowed = NULL;
private $arFollowers = NULL;
private $iActief = NULL;
private $iStatus = NULL;
private $arStatus = NULL;
private $bAlgemeneVoorwaarden = NULL;
private $arMailalerts = NULL;
private $iDienstverlener = NULL;
private $bMailVerified = NULL;
private $bNEW = TRUE;
public function user($strKey=NULL) { // $strKey = ID or ALIAS // when not defined: create new user
if (!is_null($strKey)) {
if (is_numeric($strKey)) {
$this->id($strKey);
} else {
$this->alias($strKey);
}
$this->bNEW = FALSE;
} else {
$this->bNEW = TRUE;
$this->id(0);
}
}
public function savePostData() {
if (isset($_POST["edit-profile"])) if ($_POST["edit-profile"] == $this->editkey()) {
foreach ($_POST as $strKey=>$strVal) {
switch($strKey) {
case "edit-profile": break;
case "firstname":
$this->firstname($strVal);
break;
case "lastname":
$this->lastname($strVal);
break;
case "email":
if ($strVal != $this->email()) {
$this->changeEmail($strVal, TRUE);
$oAlert = new action($this->id());
$oAlert->type("alert");
$oAlert->data("title", "E-mail validatie");
$oAlert->data("text", "Er werd een validatiemail gestuurd naar uw nieuw e-mailadres. De aanpassing wordt geldig vanaf deze bevestigd werd.");
$oAlert->update();
}
//$this->email($strVal);
break;
case "description":
$this->description($strVal);
break;
case "telephone":
$this->telephone($strVal);
break;
case "gender":
$this->gender($strVal);
break;
case "birthdate":
$this->birthdate(ddmmyyyyTOdate($strVal));
break;
case "location":
if (trim($strVal) != "") {
$arLoc = getXY($strVal);
} else {
$arLoc = array("latitude"=>0, "longitude"=>0);
}
$this->location($strVal, $arLoc["latitude"], $arLoc["longitude"], TRUE);
break;
case "showlocation":
$this->visible("location", $_POST["showlocation"]);
break;
case "showemail":
$this->visible("email", $_POST["showemail"]);
break;
case "showtelephone":
$this->visible("telephone", $_POST["showtelephone"]);
break;
case "showbirthdate":
$this->visible("birthdate", $_POST["showbirthdate"]);
break;
case "showgender":
$this->visible("gender", $_POST["showgender"]);
break;
case "showfirstname":
$this->visible("firstname", $_POST["showfirstname"]);
break;
case "showlastname":
$this->visible("lastname", $_POST["showlastname"]);
break;
case "showimg":
$this->visible("img", $_POST["showimg"]);
break;
case "files":
foreach ($strVal as $strSubVal) {
$arInputs = explode(",", $strSubVal);
$strFolder = "upload/userfiles/" . $this->id();
if (!file_exists($strFolder)) mkdir($strFolder);
$strFileLoc = $strFolder . "/" . md5(time() . $_FILES[$arInputs[1]]["name"]);
if($_FILES[$arInputs[1]]["name"] != "") {
move_uploaded_file($_FILES[$arInputs[1]]["tmp_name"], $strFileLoc);
$this->addFile($_FILES[$arInputs[1]]["name"], $strFileLoc, $_POST[$arInputs[0]], $_POST[$arInputs[2]]);
}
}
break;
case "existingfiles":
foreach ($strVal as $strSubVal) {
$arInputs = explode(",", $strSubVal);
$strKey = $arInputs[3];
$this->arBestanden[$strKey]["visible"] = intval($_POST[ $arInputs[2] ]);
$this->arBestanden[$strKey]["title"] = $_POST[ $arInputs[0] ];
//$this->addFile($_FILES[$arFile[1]]["name"], $strFileLoc, $_POST[$arFile[0]], $_POST[$arFile[2]]);
}
break;
case "dienstverlener":
$this->dienstverlener($strVal);
break;
default:
$arKey = explode("-", $strKey, 2);
switch ($arKey[0]) {
case "showdata":
$this->datavisible($arKey[1], $strVal);
break;
default:
$this->data($strKey, $strVal);
}
}
$this->update();
}
foreach ($_FILES as $strKey=>$strVal) {
switch($strKey) {
case "img":
$strTmp = "upload/tmp/" . $_FILES["img"]["name"];
move_uploaded_file($_FILES["img"]["tmp_name"], $strTmp);
createProfilePicture($strTmp, $this->id());
break;
}
}
}
}
public function unlocked($bValue = NULL) { // als een user unlocked is kan ook een niet-aangemelde gebruiker bv. emailadres opvragen of aanpassingen doen (nodig voor "paswoord vergeten")
if(!is_null($bValue)) $this->bUnlocked = $bValue;
return $this->bUnlocked || user(me())->admin();
}
public function admin($bAdmin = NULL) {
if (!is_null($bAdmin)) $this->bAdmin = $bAdmin;
if (is_null($this->bAdmin)) $this->load();
return $this->bAdmin;
}
public function id($iID = NULL) { // get / set ID (enkel set via DB)
if (!is_null($iID)) $this->iID = $iID;
if (is_null($this->iID)) $this->load();
$this->bNEW = ($this->iID == 0);
return $this->iID;
}
public function mailalert($strID, $iValue = NULL) {
if (is_null($this->arMailalerts)) $this->load();
if (!is_null($iValue)) $this->arMailalerts[$strID] = $iValue;
return isset($this->arMailalerts[$strID]) ? $this->arMailalerts[$strID] : 0;
}
public function alias($strAlias = NULL, $bCreate = FALSE) { // if bCreate == TRUE -> alias will be set to unique alias
if (!is_null($strAlias)) {
if ($bCreate) {
$strProposition = $strAlias;
if ($strProposition == "") $strProposition = trim($this->firstname()) . "_" . trim($this->lastname());
$strProposition = str2url($strProposition);
$strProposition = str_replace(".", "-", $strProposition);
$iTeller = 0;
do {
$strAlias = $strProposition . (($iTeller ++ > 0) ? $iTeller : "" );
$oCount = new database();
$oCount->execute("select count(id) as aantal from tblUsers where alias = '" . $oCount->escape($strAlias) . "' and id != " . $this->id() . ";");
} while ($oCount->get("aantal") > 0);
}
$this->strAlias = $strAlias;
}
if (is_null($this->strAlias)) $this->load();
return $this->strAlias;
}
public function addFile($strFilename, $strLoc, $strTitel, $iPrivacy, $strKey = NULL) {
if (is_null($this->arBestanden)) $this->load();
if (is_null($strKey)) $strKey = md5($strLoc . time());
if ($strFilename != "") {
if (in_array(pathinfo($strFilename, PATHINFO_EXTENSION), array("pdf", "doc", "docx", "txt", "jpg", "jpeg", "gif", "bmp", "png", "xls", "xlsx", "md", "ppt", "pps", "odt", "ods", "odp", "csv", "svg"))) {
$this->arBestanden[$strKey] = array(
"title" => $strTitel,
"filename" => $strFilename,
"location" => $strLoc,
"visible" => intval($iPrivacy),
);
}
}
}
public function status($bForce = FALSE) {
if (is_null($this->arStatus)) $this->load();
if (!isset($this->arStatus["updated"])) { // nog geen status gechecked
$bForce = TRUE;
} else {
if ($this->arStatus["updated"] < owaestime()-2*24*60*60) $bForce = TRUE; // ouder dan 2 dagen
}
if ($bForce) {
$this->arStatus["updated"] = owaestime();
$oDB = new database();
$oDB->execute("select count(distinct vPartners.pB) as partnercount, count(vPartners.pB) as transcount
from ((select id, receiver as pA, sender as pB from tblPayments where receivergroup = 0 and voorschot = 0 and actief = 1)
union (select id, sender as pA, receiver as pB from tblPayments where sendergroup = 0 and voorschot = 0 and actief = 1))
as vPartners where vPartners.pA = " . $this->id());
$this->arStatus["partnercount"] = $oDB->get("partnercount");
$this->arStatus["transactiecount"] = $oDB->get("transcount");
$this->arStatus["diversiteit"] = ($this->arStatus["transactiecount"]==0) ? 1 : ($this->arStatus["partnercount"] / $this->arStatus["transactiecount"]);
$oDB->execute("select count(id) as schenkingen from tblPayments where sender = " . $this->id() . " and market = 0 and voorschcot = 0 and actief = 1 and datum > " . (owaestime()-60*24*60*60) . "; ");
$this->arStatus["schenkingen"] = $oDB->get("schenkingen");
$this->arStatus["social"] = $this->social();
$this->arStatus["physical"] = $this->physical();
$this->arStatus["mental"] = $this->mental();
$this->arStatus["emotional"] = $this->emotional();
$this->arStatus["indictatorensom"] = $this->social() + $this->physical() + $this->mental() + $this->emotional();
$this->arStatus["credits"] = ($this->credits()-settings("startvalues", "credits"));
$this->arStatus["waarderingen"] = $this->stars();
// $oDB->execute("select sum(if(market=0,1,0)) as straffen, count(id) as aantalwaarderingen, sum(stars) as waardering from tblStars where receiver = " . $this->id() . "; ");
$this->arStatus["score"] = $this->arStatus["diversiteit"] * (abs($this->arStatus["credits"]) + 10*($this->social()+$this->physical()+$this->mental()+$this->emotional())) - $this->arStatus["schenkingen"];
// $this->arStatus["straffen"] = $oDB->get("straffen");
// $this->arStatus["waarderingen"] = $oDB->get("aantalwaarderingen");
// $this->arStatus["sterren"] = $oDB->get("waardering") / ($this->arStatus["waarderingen"] - $this->arStatus["straffen"]);
$this->iStatus = 0;
$arWarnings = array();
foreach (settings("warnings") as $iStatus => $arTresholds) {
if ($this->arStatus["schenkingen"] >= $arTresholds["schenkingen"]) $arWarnings[$iStatus][] = "schenkingen";
if ($this->arStatus["diversiteit"] <= $arTresholds["transactiediversiteit"] ) $arWarnings[$iStatus][] = "diversiteit";
if (abs($this->arStatus["credits"]) > $arTresholds["credits"] ) $arWarnings[$iStatus][] = "credits";
if ($this->stars()>0 && $this->stars() <= $arTresholds["waardering"] ) $arWarnings[$iStatus][] = "waardering";
if ($this->social() <= $arTresholds["social"] ) $arWarnings[$iStatus][] = "indicatoren.social";
if ($this->physical() <= $arTresholds["physical"] ) $arWarnings[$iStatus][] = "indicatoren.physical";
if ($this->mental() <= $arTresholds["mental"] ) $arWarnings[$iStatus][] = "indicatoren.mental";
if ($this->emotional() <= $arTresholds["emotional"] ) $arWarnings[$iStatus][] = "indicatoren.emotional";
if ($this->arStatus["indictatorensom"] <= $arTresholds["indicatorsom"] ) $arWarnings[$iStatus][] = "indicatoren.som";
}
$arCorrigeer = array();
if ($this->social(NULL, FALSE) < 0) $arCorrigeer["social"] = 0-$this->social(NULL, FALSE);
if ($this->physical(NULL, FALSE) < 0) $arCorrigeer["physical"] = 0-$this->physical(NULL, FALSE);
if ($this->mental(NULL, FALSE) < 0) $arCorrigeer["mental"] = 0-$this->mental(NULL, FALSE);
if ($this->emotional(NULL, FALSE) < 0) $arCorrigeer["emotional"] = 0-$this->emotional(NULL, FALSE);
if ($this->social(NULL, FALSE) > 100) $arCorrigeer["social"] = 100-$this->social(NULL, FALSE);
if ($this->physical(NULL, FALSE) > 100) $arCorrigeer["physical"] = 100-$this->physical(NULL, FALSE);
if ($this->mental(NULL, FALSE) > 100) $arCorrigeer["mental"] = 100-$this->mental(NULL, FALSE);
if ($this->emotional(NULL, FALSE) > 100) $arCorrigeer["emotional"] = 100-$this->emotional(NULL, FALSE);
if (count(array_keys($arCorrigeer))>0) $this->addIndicators($arCorrigeer);
$this->arStatus["warnings"] = $arWarnings;
foreach ($arWarnings as $iWarning => $arValues) $this->iStatus = $iWarning;
$arMails = array();
if (!isset($this->arStatus["status"])) $this->arStatus["status"] = $this->iStatus;
if ($this->arStatus["status"] != $this->iStatus) {
if ($this->arStatus["status"] > $this->iStatus) { // heeft het nu beter gedaan
switch($this->iStatus) {
case 0:
$arMails["owner"] = "Proficiat, je waarden zijn terug op peil!";
break;
case 1:
$arMails["owner"] = "Proficiat, je waarden zijn al een stuk beter. Nog even volhouden en ze zijn terug volledig op peil. ";
break;
case 2:
$arMails["owner"] = "Proficiat, je waarden zijn uit alarmniveau. Probeer deze nog iets beter te krijgen. ";
break;
case 3:
$arMails["owner"] = "Proficiat, je werd gedeblokkeerd. Let op: je waarden staan nog in alarmniveau, probeer deze zo snel mogelijk te verbeteren om een nieuwe blokkering tegen te gaan. ";
// unfreeze
break;
}
} else { // nu slechtere status
switch($this->iStatus) {
case 1:
if (count($arWarnings[$this->iStatus]) == 1) {
$arReden = explode(".", $arWarnings[$this->iStatus][0]);
switch($arReden[0]) {
case "indicatoren":
$arMails["owner"] = "We merken dat je indicatoren te laag zakken. Probeer deze boven de 60 te houden.";
break;
case "waardering":
$arMails["owner"] = "We merken dat je gemiddeld een lage waardering krijgt. Probeer te zorgen dat deze betert.";
break;
case "schenkingen":
$arMails["owner"] = "We merken dat je veel schenkingen uitvoert. Probeer deze te beperken.";
break;
case "diversiteit":
$arMails["owner"] = "We merken dat je vaak met dezelfde personen werkt. Probeer hier af te wisselen. ";
break;
case "credits":
$arMails["owner"] = "We merken dat je " . settings("credits", "name", "x") . " uit balans staan. Probeer dit te herstellen. ";
break;
}
} else {
//foreach ($arWarnings[$this->iStatus] as $strWarnings) {
//}
$arMails["owner"] = "We merken dat verschillende waarden te laag zakken. Probeer deze op peil te houden";
}
break;
case 2:
$arMails["owner"] = "Opgelet, we zien dat je waarden verder achteruit gaan. Het wordt tijd hier iets aan te doen";
break;
case 3:
$arMails["owner"] = "Opgelet! we merken dat waarden kritisch laag staan. Zorg dat deze verhogen of de toegang tot OWAES kan geblokkeerd worden";
$arMails["owaes"] = "We merken dat waarden van " . $this->getName() . " kritisch laag staan. De gebruiker werd hiervan op de hoogte gebracht via mail. ";
break;
case 4:
// FREEZE
$this->unlocked(TRUE);
$this->actief(0);
$this->update();
$oDB = new database("update tblUserSessions set stop = '" . owaesTime() . "' where user = '" . $this->id() . "'; ", TRUE);
$arMails["owaes"] = "Gebruiker " . $this->getName() . " werd geblokkeerd wegens te lage waarden (" . implode(", ", $arWarnings[$this->iStatus]) . ")";
}
}
foreach ($arMails as $strTo=>$strMelding) {
switch($strTo) {
case "owner":
$oMessage = new message();
$oMessage->sender(0);
$oMessage->receiver($this->id());
$oMessage->body($strMelding);
$oMessage->update();
break;
case "owaes":
$arAdmins = new userlist();
$arAdmins->filter("admin");
foreach ($arAdmins->getList() as $oAdmin) {
$oMessage = new message();
$oMessage->sender(0);
$oMessage->receiver($oAdmin->id());
$oMessage->body($strMelding);
$oMessage->data("user", $this->id());
$oMessage->update();
}
break;
}
}
}
$this->arStatus["status"] = $this->iStatus;
$oDB->execute("update tblUsers set statusinfo = '" . $oDB->escape(json_encode($this->arStatus)) . "', status = '$iStatus', statusdate = '" . owaestime() . "' where id = '" . $this->id() . "'; ");
}
return $this->iStatus;
}
public function files($strKey = NULL) { // if $strKEY defined: returns filepath of FALSE / else: returns array met alle files
if (is_null($this->arBestanden)) $this->load();
if (is_null($this->arBestanden)) $this->arBestanden = array();
if (is_null($strKey)) {
$arBestanden = array();
foreach ($this->arBestanden as $strKey=>$arBestand) {
if ($arBestand["visible"] != -1) {
if ($this->visible4me("file:$strKey")) {
$arBestanden[] = array(
"key" => $strKey,
"link" => fixPath("download.php?u=" . $this->id() . "&f=" . $strKey),
"filename" => $arBestand["filename"],
"title" => $arBestand["title"],
"visible" => $arBestand["visible"],
);
}
}
}
return $arBestanden;
} else {
if ($this->visible4me("file:$strKey")) {
return $this->arBestanden[$strKey];
} else {
return FALSE;
}
}
}
public function password($strPassword = NULL, $bEncode = TRUE) { /*
get / set password:
get: returns md5 password
set: if ($bEncode==TRUE) => send MD5-string / $bEncode==FALSe => send user input
*/
if (!is_null($strPassword)) $this->strPassword = $bEncode ? md5(trim($strPassword)) : $strPassword;
if (is_null($this->strPassword)) $this->load();
return $this->strPassword;
}
public function location($strLocation = NULL, $iLocationLat = NULL, $iLocationLong = NULL, $bBadge = FALSE) { /* get / set location
set : strlocation en lat + long doorgeven
get: returns strLocation (voor lat + long: LatLong())
*/
if (!is_null($strLocation)) $this->strLocation = $strLocation;
if (!is_null($iLocationLat)) $this->iLocationLat = $iLocationLat;
if (!is_null($iLocationLong)) $this->iLocationLong = $iLocationLong;
if (is_null($this->strLocation)) $this->load();
if ($bBadge) if ($iLocationLat*$iLocationLong!=0) $this->addBadge("location");
return $this->visible4me("location") ? $this->strLocation : "";
}
public function LatLong() { // returns arra(iLat, iLong)
if (is_null($this->iLocationLat)||is_null($this->iLocationLong)) $this->load();
return array($this->iLocationLat, $this->iLocationLong);
}
public function latitude($iLocationLat = NULL) {
if (!is_null($iLocationLat)) $this->iLocationLat = $iLocationLat;
if (is_null($this->iLocationLat)) $this->load();
return $this->iLocationLat;
}
public function longitude($iLocationLong = NULL) {
if (!is_null($iLocationLong)) $this->iLocationLong = $iLocationLong;
if (is_null($this->iLocationLong)) $this->load();
return $this->iLocationLong;
}
public function posts() { // returns count posts from this user
if (is_null($this->iPosts)){
$oDB = new database();
$strSQL = "select count(id) as aantal from tblMarket where author = '" . $this->id() . "'; ";
$oDB->execute($strSQL);
$this->iPosts = $oDB->get("aantal");
}
return $this->iPosts;
}
public function subscriptions() { // returns count subscriptions from this user
if (is_null($this->iSubscriptions)){
$oDB = new database();
$strSQL = "select count(distinct market) as aantal from tblMarketSubscriptions where doneby = '" . $this->id() . "'; ";
$oDB->execute($strSQL);
$this->iSubscriptions = $oDB->get("aantal");
}
return $this->iSubscriptions;
}
public function score() { //
return floor($this->posts()/5);
}
public function experience() {
if (is_null($this->oExperience)) $this->oExperience = new experience($this->id());
return $this->oExperience;
}
public function follows($iUser, $bValue = NULL) {
$arFollowed = $this->followed();
$bFollowed = FALSE;
foreach ($arFollowed as $oUser) if ($oUser->id() == $iUser) $bFollowed = TRUE;
if (isset($bValue)) {
if ($bFollowed != $bValue) {
$oDB = new database();
if ($bValue) {
$oDB->execute("insert into tblFollowers (user, followed, startdate) values ('" . $this->id() . "', '$iUser', '" . owaestime() . "'); ");
$this->addbadge("follower");
$oExperience = new experience($this->id());
$oExperience->detail("reason", "follower");
$oExperience->add(50);
} else {
$oDB->execute("delete from tblFollowers where user = '" . $this->id() . "' and followed = '$iUser'; ");
}
$this->arFollowed = NULL;
}
return $bValue;
}
return $bFollowed;
}
public function isFriend() { // GET boolean
if (is_null($this->iFriendStatus)) $this->loadFriendship();
return ($this->id() == me() || $this->iFriendStatus == FRIEND_FRIENDS);
}
public function removeFriend() {
$iMe = me();
$iFriend = $this->id();
if (is_null($this->iFriendStatus)) $this->loadFriendship();
$oDB = new database();
$oDB->execute("update tblFriends set confirmed = 0 where user = $iFriend and friend = $iMe; ");
$oDB->execute("delete from tblFriends where user = $iMe and friend = $iFriend; ");
$this->iFriendStatus = FRIEND_NOFRIENDS;
}
public function addFriend() { // GET boolean
$iMe = me();
$iFriend = $this->id();
if (is_null($this->iFriendStatus)) $this->loadFriendship();
$oDB = new database();
switch($this->iFriendStatus) {
case FRIEND_FRIENDS: // had been confirmed by both sides
break;
case FRIEND_REQUESTED: // request had already been made by me
break;
case FRIEND_ASKED: // other party had already asked friendship
$oDB->execute("insert into tblFriends (user, friend, datum, confirmed) values ($iMe, $iFriend, " . owaestime() . ", 1);");
$oDB->execute("update tblFriends set confirmed = 1 where user = $iFriend and friend = $iMe; ");
$oNotification = new notification($iFriend);
$oNotification->key("friendship.$iMe.$iFriend");
$oNotification->message(user($iMe)->getName() . " heeft je vriendschapaanvraag bevestigd");
$oNotification->link(user($iMe)->getURL());
$oNotification->sender($iMe);
$oNotification->send();
$this->iFriendStatus = FRIEND_FRIENDS;
switch(count($this->friends())) {
case 1:
$this->addbadge("1friend");
break;
case 10:
$this->addbadge("10friends");
break;
}
switch(count(user($iMe)->friends())) {
case 1:
user($iMe)->addbadge("1friend");
break;
case 10:
user($iMe)->addbadge("10friends");
break;
}
$oExperience = new experience($iMe);
$oExperience->detail("reason", "friendschip_accept");
$oExperience->add(50);
$oExperience = new experience($iFriend);
$oExperience->detail("reason", "friendschip_add");
$oExperience->add(80);
break;
case FRIEND_NOFRIENDS: // nothing asked yet
default:
$oDB->execute("insert into tblFriends (user, friend, datum) values ($iMe, $iFriend, " . owaestime() . ") ");
$oNotification = new notification($iFriend);
$oNotification->key("friendship.$iMe.$iFriend");
$oNotification->message(user($iMe)->getName() . " heeft een vriendschapaanvraag verstuurd");
$oNotification->link(user($iMe)->getURL());
$oNotification->sender(0);
$oNotification->send();
$this->iFriendStatus = FRIEND_REQUESTED;
break;
}
}
public function visible4me($oSelector) { /* get visible-value (TRUE/FALSE) van specifiek veld voor actieve gebruiker
bv. $oUser->visible4me("firstname") => checkt of actieve gebruiker de voornaam van $oUser kan zien (afhankelijk van settings en al dan niet friend zijn )
*/
if ($this->unlocked()) return TRUE;
if ($this->id() == me()) return TRUE;
//if (user(me())->admin()) return TRUE;
$arParts = explode(":", $oSelector, 2);
switch ($arParts[0]) {
case "file":
if (is_null($this->arBestanden)) $this->load();
switch($this->arBestanden[$arParts[1]]["visible"]) {
case VISIBILITY_HIDDEN:
return ($this->id() == me());
break;
case VISIBILITY_VISIBLE:
return TRUE;
break;
case VISIBILITY_FRIENDS:
return $this->isFriend();
break;
}
break;
case "data":
switch($this->datavisible($arParts[1])) {
case VISIBILITY_HIDDEN:
return ($this->id() == me());
break;
case VISIBILITY_VISIBLE:
return TRUE;
break;
case VISIBILITY_FRIENDS:
return $this->isFriend();
break;
}
break;
default:
switch($this->visible($oSelector)) {
case VISIBILITY_HIDDEN:
return ($this->id() == me());
break;
case VISIBILITY_VISIBLE:
return TRUE;
break;
case VISIBILITY_FRIENDS:
return $this->isFriend();
break;
default:
error("class.user.php line " . __LINE__ . ": '" . $this->visible($oSelector) . "' ongeldige waarde");
}
}
}
public function visible($oSelector = NULL, $iValue = NULL) { /*
zichtbaarheid van het profiel get/setten
->visible(); = get / profiel zichtbaar in het overzicht van gebruikers
->visible(VISIBILITY_HIDDEN); = set / profiel zichtbaar in het overzicht van gebruikers
->visible("firstname"); = get / voornaam zichtbaar
->visible("firstname", VISIBILITY_VISIBLE); = set / voornaam zichtbaar
VISIBILITY_HIDDEN / VISIBILITY_VISIBLE / VISIBILITY_FRIENDS
*/
if (is_numeric($oSelector)) $oSelector = intval($oSelector);
if (is_numeric($iValue)) $iValue = intval($iValue);
if (!is_null($oSelector)) {
if (is_null($iValue)) {
if ($oSelector === 1 || $oSelector === TRUE || $oSelector === VISIBILITY_VISIBLE || $oSelector === "yes") {
$this->bVisible = TRUE;
$this->arVisible["profile"] = VISIBILITY_VISIBLE;
return TRUE;
} else if ($oSelector === 0 || $oSelector === FALSE || $oSelector === VISIBILITY_HIDDEN || $oSelector === "no") {
$this->bVisible = FALSE;
$this->arVisible["profile"] = VISIBILITY_HIDDEN;
return FALSE;
} else if ($oSelector === VISIBILITY_FRIENDS) {
$this->arVisible["profile"] = VISIBILITY_FRIENDS;
return FALSE; // TODO: should return value in functie van vriend zijn of nie
} else {
$oSelector = strtolower($oSelector);
switch($oSelector) {
case "firstname":
case "lastname":
case "location":
case "email":
case "profile":
case "telephone":
case "gender":
case "birthdate":
case "description":
case "img":
if (!isset($this->arVisible[$oSelector])) $this->load();
return $this->arVisible[$oSelector];
default:
//error("class.user.php line " . __LINE__ . ": '" . $oSelector . "' ongeldige waarde");
return FALSE;
}
}
} else {
$this->arVisible[$oSelector] = intval($iValue);
return $this->arVisible[$oSelector];
}
} else {
return $this->bVisible;
}
}
public function showable($oSelector = NULL) { // checkt of gevraagd item "visible" EN ingevuld is
if ($this->visible($oSelector)) {
switch(strtolower($oSelector)) {
case "firstname":
return ($this->firstname() != "");
break;
case "lastname":
return ($this->lastname() != "");
break;
case "location":
return ($this->location() != "");
break;
case "email":
return ($this->email() != "");
break;
case "telephone":
return ($this->telephone() != "");
break;
case "gender":
return ($this->gender() != "");
break;
case "birthdate":
return ($this->birthdate() != 0);
break;
case "description":
return ($this->description() != "");
break;
default:
error ("veld niet gedefineerd: class.user.php" . __LINE__ );
}
} else return FALSE;
}
public function physical($iValue = NULL, $bBoundaries = TRUE) {
if (!is_null($iValue)) $this->iPhysical = $iValue;
if (is_null($this->iPhysical)) $this->loadIndicators();
if ($this->iPhysical > 100 && $bBoundaries) return 100;
if ($this->iPhysical < 0 && $bBoundaries) return 0;
return $this->iPhysical;
}
public function mental($iValue = NULL, $bBoundaries = TRUE) {
if (!is_null($iValue)) $this->iMental = $iValue;
if (is_null($this->iMental)) $this->loadIndicators();
if ($this->iMental > 100 && $bBoundaries) return 100;
if ($this->iMental < 0 && $bBoundaries) return 0;
return $this->iMental;
}
public function emotional($iValue = NULL, $bBoundaries = TRUE) {
if (!is_null($iValue)) $this->iEmotional = $iValue;
if (is_null($this->iEmotional)) $this->loadIndicators();
if ($this->iEmotional > 100 && $bBoundaries) return 100;
if ($this->iEmotional < 0 && $bBoundaries) return 0;
return $this->iEmotional;
}
public function social($iValue = NULL, $bBoundaries = TRUE) {
if (!is_null($iValue)) $this->iSocial = $iValue;
if (is_null($this->iSocial)) $this->loadIndicators();
if ($this->iSocial > 100 && $bBoundaries) return 100;
if ($this->iSocial < 0 && $bBoundaries) return 0;
return $this->iSocial;
}
public function data($strKey, $strValue = NULL) {
if (is_null($this->arData)) $this->load();
if (!is_null($strValue)) {
if (isset($this->arData[$strKey])) {
$this->arData[$strKey]["value"] = $strValue;
} else {
$this->arData[$strKey] = array("value" => $strValue);
}
}
$strVal = (isset($this->arData[$strKey]["value"])) ? $this->arData[$strKey]["value"] : "";
return ($this->visible4me("data:$strKey"))? $strVal : "";
}
public function datavisible($strKey, $iValue = NULL) {
if (is_null($this->arData)) $this->load();
if (!is_null($iValue)) {
if (isset($this->arData[$strKey])) {
$this->arData[$strKey]["visible"] = $iValue;
} else {
$this->arData[$strKey] = array("visible" => $iValue);
}
}
return (isset($this->arData[$strKey]["visible"])) ? $this->arData[$strKey]["visible"] : VISIBILITY_VISIBLE;
}
public function login($strLogin = NULL, $bCheck = TRUE) { /*
get / set login
TODO: checken of login nog niet bestaat!
*/
if (!is_null($strLogin)) {
$oReturn = $strLogin;
if ($bCheck) {
if ($strLogin == "") $strLogin = randomstring(8);
if (!strrpos($strLogin, "@") === false) {
$strLogin = str_replace("@", "", $strLogin);
$oReturn = FALSE;
}
$oDB = new database();
do {
$oDB->execute("select count(id) as aantal from tblUsers where login='" . $oDB->escape($strLogin) . "' and id != " . $this->id() . ";");
if ($oDB->get("aantal") > 0) {
$strLogin = randomstring(8);
$oReturn = FALSE;
}
} while ($oDB->get("aantal") > 0);
}
$this->strLogin = $strLogin;
return $oReturn;
}
if (is_null($this->strLogin)) $this->load();
return $this->strLogin;
}
public function firstname($strFirstname = NULL) { // get / set first name
if (!is_null($strFirstname)) {
$this->strFirstname = $strFirstname;
return TRUE;
}
if (is_null($this->strFirstname)) $this->load();
return ($this->visible4me("firstname")) ? $this->strFirstname : "";
}
public function lastname($strLastname = NULL) { // get / set last name
if (!is_null($strLastname)) {
$this->strLastname = $strLastname;
return TRUE;
}
if (is_null($this->strLastname)) $this->load();
return ($this->visible4me("lastname")) ? $this->strLastname : "";
}
public function gender($strGender = NULL) { // get / set gender (string)
if (!is_null($strGender)) {
$this->strGender = $strGender;
return TRUE;
}
if (is_null($this->strGender)) $this->load();
return ($this->visible4me("gender")) ? $this->strGender : "";
}
public function telephone($strTelephone = NULL) { // get / set telephone (string)
if (!is_null($strTelephone)) {
$this->strTelephone = $strTelephone;
return TRUE;
}
if (is_null($this->strTelephone)) $this->load();
return ($this->visible4me("telephone")) ? $this->strTelephone : "";
}
public function birthdate($ibirthdate = NULL) { // get / set birthdate (integer)
if (!is_null($ibirthdate)){
$this->ibirthdate = $ibirthdate;
return TRUE;
}
if (is_null($this->ibirthdate)) $this->load();
return ($this->visible4me("birthdate")) ? $this->ibirthdate : 0;
}
public function actief($iActief = NULL) {
if (!is_null($iActief)) {
if (is_null($this->iActief)) {
$this->iActief = $iActief;
} else {
if ($this->unlocked()) {
$this->iActief = $iActief; // actief-value kan enkel aangepast worden door admins
if ($iActief == 1) $oDB = new database("insert into tblIndicators (user, datum, physical, mental, emotional, social, reason, link) values ('" . $this->id() . "', '" . owaestime() . "', 0, 0, 0, 0, 0, 0); ", TRUE); // nodig bij ontdooien
}
}
}
if (is_null($this->iActief)) $this->load();
return ($this->iActief==1);
}
public function changeEmail($strEmail, $bDoChange = FALSE) {
$oDB = new database();
$oDB->execute("select count(id) as aantal from tblUsers where mail='" . $oDB->escape($strEmail) . "' and id != " . $this->id() . ";");
if ($oDB->get("aantal") > 0) return FALSE;
if ($bDoChange) {
if ($this->id() == 0) {exit("Change mail kan enkel bij bestaande gebruikers (eerst opslaan)");}
if (!$this->mailVerified()) {
$this->email($strEmail);
$this->update();
}
$strSleutel = md5(time() . $strEmail);
$arFields = array(
"user" => $this->id(),
"email" => "'" . $oDB->escape($strEmail) . "'",
"sleutel" => "'" . $strSleutel . "'",
"verified" => "0",
"datum" => time(),
);
$oDB->sql("insert into tblUserEmailVerify (" . implode(", ", array_keys($arFields)) . ") values (" . implode(", ", array_values($arFields)) . "); ");
$oDB->execute();
$iInsertID = $oDB->lastInsertId();
$strURL = fixPath("verifymail.php?u=" . $this->id() . "&k=" . $strSleutel, TRUE);
$oMail = new email();
$oMail->setTo($strEmail, $this->getName());
$oMail->template("mailtemplate.html");
$strMailBody = $this->HTML("mail.subscribe.html");
$strMailBody = str_replace("[mailverify:url]", $strURL, $strMailBody);
$oMail->setBody($strMailBody);
$oMail->setSubject("OWAES inschrijving");
$oMail->send();
}
return TRUE;
}
public function validateEmail($strKey) {
$bDone = FALSE;
$oDB = new database();
$oDB->execute("select * from tblUserEmailVerify where user = " . $this->id() . ";");
while ($oDB->nextRecord()) {
if ($oDB->get("sleutel") == $strKey) {
$bDone = TRUE;
$this->unlocked(TRUE);
$this->email($oDB->get("email"));
$this->mailVerified(TRUE);
$this->update();
$oAlert = new action($this->id());
$oAlert->type("alert");
$oAlert->data("title", "E-mail gevalideerd");
$oAlert->data("text", "Uw e-mailadres werd gevalideerd");
$oAlert->update();
}
}
return $bDone;
}
public function mailVerified($bMailVerified = NULL) {
if (!is_null($bMailVerified)) $this->bMailVerified = $bMailVerified;
if (is_null($this->bMailVerified)) $this->load();
return ($this->bMailVerified);
}
public function algemenevoorwaarden($bAlgemeneVoorwaarden = NULL) {
if (!is_null($bAlgemeneVoorwaarden)) {
if (is_bool($bAlgemeneVoorwaarden)) $bAlgemeneVoorwaarden = ($bAlgemeneVoorwaarden?1:0);
if (is_null($this->bAlgemeneVoorwaarden)) {
$this->bAlgemeneVoorwaarden = $bAlgemeneVoorwaarden;
} else {
if ($this->unlocked()) $this->bAlgemeneVoorwaarden = $bAlgemeneVoorwaarden;
}
}
if (is_null($this->bAlgemeneVoorwaarden)) $this->load();
return ($this->bAlgemeneVoorwaarden==1);
}
public function description($strDescription = NULL) { // get / set omschrijving
if (!is_null($strDescription)) {