-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclass.controller.php
1852 lines (1564 loc) · 68.1 KB
/
class.controller.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
/**
* class handles input and other data
*/
class Controller {
/**
* @var Model instance of model to be used in this class
*/
protected $model;
/**
* @var array combined POST & GET data received from client
*/
protected $input = array();
/**
* @var User
*/
protected static $user;
/**
* @var logfile
*/
protected $logfile = "vpaction.log";
/**
* @var sessiontime in Minutes
*/
protected $sessionValidity = 20;
/**
* @return User
*/
public static function getUser() {
return self::$user;
}
/**
* Controller constructor.
*
* @param $input
*/
public function __construct($input) {
if ($this->model == null)
$this->model = Model::getInstance();
$this->input = $input;
$this->infoToView = array();
$this->chooseLogicHandler();
}
/**
*debug function
*/
protected function readSession(){
$msg="";
if(!empty($_SESSION) ){
$msg = "SESSION:\r\n";
foreach ($_SESSION as $key => $value){
if ($key != "notifications") {
$msg .= $key." -- ";
if (is_array($value) ) {
foreach ($value as $k=>$v) {
$msg .= "[".$k. " : ".$v."]\r\n";
}
} else {
$msg .= $value;
}
$msg .="\r\n";
}
}
} else {
$msg = "No Session set";
}
return $msg;
}
/*
* check which logicHandler will be used
* admin login uses handler in admin.controller class
*/
protected function chooseLogicHandler(){
//choose the logic handler for admin and other users
if (isset($_SESSION['user']) ) {
if ($_SESSION['user']['type'] == 0){
//admin is logged in
if (!$this->checkLoginTimeout()) {
die($this->logout(true));//calls admin controllers logout()
}else {
return;
}
} else {
//all other users
//Debug::writeDebugLog(__method__,$this->readSession()."\r\nother than Admin logged in");
if (!$this->checkLoginTimeout()) {
die($this->logout(true));//calls admin controllers logout()
} else {
$this->handleLogic();
}
}
} else {
//no user logged in - goto login page
//System Timeout, i.e. SESSION timeout of server OR NEVER LOGGED IN, i.e. START ???
//need to show a message
//Debug::writeDebugLog(__method__,$this->readSession()."\r\nNo one logged in");
$this->handleLogic();
}
}
/*
* handle logic
* start all relevant logic actions
*/
protected function handleLogic() {
//check for active login when javascript calls
if (isset($this->input['console'])) {
header('Content-Type: text/json');
//check for SessionTimeout
if (isset($_SESSION['user'])) {
if (!$this->checkLoginTimeout() ) {
$this->notify("Login timed out!");
$_SESSSION['timeout'] = true;
isset($this->input['type']) ? $type = $this->input['type'] : "ohne";
//Debug::writeDebugLog(__method__,"JavaScriptCall - Type Parameter:".$type);
die(header('Location: ../') );
die( json_encode(array("status" => "timeout","notify" => "Login timed out!")));
}
}
}
//=========end of javascript timeout check=======
//can't we get rid of that???
if(isset($this->input['debugcaptcha'])) {
Model::$debugCaptcha = true;
}
//can we?
if (!isset($this->input['type']))
$this->input['type'] = null;
if ($this->handleCoverLessonDataTransmission()) {
echo "Nothing to Do!";
die;
}
//this is where the action starts
$this->display($this->handleType());
}
protected function getEmptyIfNotExistent($array, $key) {
return (isset($array[$key])) ? $array[$key] : "";
}
/**
* handle inputs, which decides the action taken
* the core of all action
* @return string
*/
protected function handleType() {
$template = "login";
//Debug::writeDebugLog(__method__,$this->input['type']);
//go straight to logout
if($this->input['type'] == "logout") {
$_SESSION['logout'] = true;
die($this->logout());
}
//all other cases
$this->sendOptions();
if (isset(self::$user)) {
if (self::$user instanceof Guardian) {
//$this->infoToView['welcomeText'] = str_replace("\\n", "<br>", str_replace("\\r\\n", "<br>", $this->getOption('welcomeparent', '')));
$this->infoToView['welcomeText'] = $this->getEmptyIfNotExistent($this->model->getOptions(), 'welcomeparent');
$this->infoToView['children'] = self::$user->getChildren();
$this->infoToView['dsgvo'] = self::$user->getDsgvo(self::$user);
} else if (self::$user instanceof Teacher) {
$this->infoToView['welcomeText'] = $this->getEmptyIfNotExistent($this->model->getOptions(), 'welcometeacher');
$this->infoToView['dsgvo'] = self::$user->getDsgvo(self::$user);
} else if (self::$user instanceof StudentUser) {
$this->infoToView['welcomeText'] = $this->getEmptyIfNotExistent($this->model->getOptions(), 'welcomestudent');
$this->infoToView['dsgvo'] = self::$user->getDsgvo(self::$user);
}
}
if (self::$user != null || $this->input['type'] == "app" || $this->input['type'] == "public" || $this->input['type'] == "login" || $this->input['type'] == "register" || $this->input['type'] == "pwdreset" || isset($_SESSION['timeout']) || isset($_SESSION['logout']) || $this->input['type'] == "confirm" ) // those cases work without login
{
switch ($this->input['type']) {
case "public":
//public access to events
$this->infoToView['public_access'] = true;
$template = $this->handleEvents();
break;
case "lest": //Teacher chooses est
$template = $this->teacherSlotDetermination();
break;
case "eest": //Parent chooses est
$template = $this->handleParentEst();
break;
case "events":
//Modul Termine
if (isset($this->input['all'])) $this->infoToView['showAllEvents'] = true;
$template = $this->handleEvents();
break;
case "childsel":
if (self::$user == null)
break;
if (!self::$user instanceof Guardian) {
$this->notify("Sie müssen ein Elternteil sein, um auf diese Seite zugreifen zu können!");
return $this->getDashBoardName();
}
$this->infoToView['user'] = self::$user;
$template = "parent_child_select";
break;
case "login":
$template = $this->login();
break;
case "register":
$template = $this->register();
break;
case "confirm":
$template = $this->confirmRegistration($this->input['tkn']);
break;
case "logout":
$_SESSION['logout'] = true;
die($this->logout());
break;
case "addstudent":
$this->addStudent();
break;
case "requestkey":
$this->requestKey();
break;
case "parent_editdata":
$template = $this->handleParentEditData();
break;
case "teacher_editdata":
$template = $this->handleTeacherEditData();
break;
case "student_editdata":
$template = $this->handleStudentEditData();
break;
case "vplan":
$template = $this->handleCoverLessons();
break;
case "pwdreset":
$template = $this->handlePwdReset();
break;
case "news":
if (self::$user == null)
break;
$template = "newsletter";
$this->infoToView['user'] = self::$user;
$this->getNewsletters();
break;
//view news
case "view":
$this->infoToView['title'] = "Newsletter lesen";
$this->infoToView['user'] = self::$user;
$newsletter = new Newsletter();
$newsletter->createFromId($this->input['nl']);
$this->infoToView["newsletter"] = $newsletter;
$this->display("viewnews");
break;
case "handledsgvo":
$status = array();
if (isset($this->input['console']) ) {
if (isset($this->input['decline']) ) {
$status = array("status" => "declined");
} else if (isset($this->input['accept'])) {
$status = array("status" => "accepted");
//fill db
if(isset(self::$user))
self::$user->acceptDsgvo();
}
die();
}
break;
case "pupilsrch":
//for Teacher User - detect all students taucght by a teacher including absence state
if (isset($this->input['console']) && isset($this->input['partname'])) {
$taughtStudents = self::$user->getAllTaughtPupilsByName($this->input['partname']);
$students = array();
foreach($taughtStudents as $stud) {
$students[]= array("absent" => $stud['absent'],
"id" => $stud['student']->getId(),
"name" => $stud['student']->getFullName(),
"klasse" => $stud['student']->getClass());
}
die(json_encode($students) );
}
break;
case "markabsent":
if (isset($this->input['console']) ) {
$single = (isset($this->input['single']) ) ? $this->input['single'] : null;
if (isset($single) ) {
$text = "";
foreach ($this->input as $key => $value) {
$text .= "*".$key;
}
$this->input['id']." -- ";
foreach ($single as $s) {
$text .= $s;
}
Debug::writeDebugLog(__method__,$text);
}
if (self::$user instanceof Guardian) {
$this->model->enterAbsentPupil($this->input['id'],$this->input['start'],$this->input['end'],$this->input['comment'],self::$user->getParentId(),null,2,null,$single);
$arr = array("status"=>"absenceEntered","id"=>$this->input['id'],"children" => $this->model->getChildrenAbsenceState($this->infoToView["children"]) );
} else if (self::$user instanceof Teacher) {
$this->model->enterAbsentPupil($this->input['id'],$this->input['start'],$this->input['end'],$this->input['comment'],self::$user->getId(),null,3,null,$single);
$arr = array("status"=>"absenceEntered",
"id"=>$this->input['id'],
"children" => json_encode($this->model->getTaughtStudentsOfTeacher(self::$user->getId())) );
}
Debug::writeDebugLog(__method__,json_encode($arr));
echo json_encode($arr);
die;
}
break;
case "entersingleabsence":
if(isset($this->input['console']) ) {
$absenceState = null;
$aid = ($this->input['aid'] != "" ) ? $this->input['aid'] : null;
$sid = $this->input['sid'];
$period = $this->input['period'];
$comment = $this->input['comment'];
$absenceState = $this->model->enterSingleLessonAbsence(self::$user,$aid,$sid,$this->input['start'],$period,$comment);
$arr = array("status" => $absenceState['action'],"aid" => $absenceState['aid'],"period" => $period,"sid" => $sid, "comment" => $comment, "missingPeriods" => $absenceState['missingPeriods']);
Debug::writeDebugLog(__method__, json_encode($arr) );
die(json_encode($arr) );
}
break;
case "getsingleabsencestate":
if(isset($this->input['console']) ){
//$this->model->getSingleAbsenceState($this->input['aid']);
die(json_encode(array("status"=>"singleabsencestate")));
}
break;
case "checkprevabs":
//check if absence one day before startdate exists
if(isset($this->input['console'])) {
$previousDayAbsence = $this->model->getPreviousDayAbsence($this->input['id'],$this->input['date']);
$arr = array("status" => "previousDayAbsence","aid" => $previousDayAbsence);
die(json_encode($arr));
}
break;
case "addtoabsence":
if(isset($this->input['console'])) {
if (self::$user instanceof Guardian) {
$arr = array("status" => "absenceProlonged",
"children" => $this->model->getChildrenAbsenceState($this->infoToView["children"]));
} else if (self::$user instanceof Teacher) {
$this->model->addToAbsence($this->input['aid'],$this->input['end'],self::$user->getId());
$arr = array("status" => "absenceProlonged",
"children" => json_encode($this->model->getTaughtStudentsOfTeacher(self::$user->getId())));
} else {
//admin enters
$this->model->addToAbsence($this->input['aid'],$this->input['end'],self::$user->getId(),true);
}
$text = "";
foreach ($arr as $a) {
$text .= $a ;
}
die(json_encode($arr));
}
break;
case "deleteabsence":
if(isset($this->input['console'])) {
$this->model->deleteAbsence($this->input['aid']);
$arr = array("status" => "absenceDeleted","aid" => $this->input['aid']);
die(json_encode($arr));
}
break;
case "excuse":
if(isset($this->input['console'])) {
$this->model->enterExcuse($this->input['aid'],$this->input['date'],$this->input['comment']);
$arr = array("status" => "absenceExcused",
"aid" =>$this->input['aid'],
"excused" => $this->input['date'],
"children" => json_encode($this->model->getTaughtStudentsOfTeacher(self::$user->getId())) );
die(json_encode($arr));
}
break;
case "editabsence":
if(isset($this->input['console'])) {
$editedDataSet = $this->model->editAbsence($this->input['aid'],$this->input['start'],$this->input['end'],$this->input['ecomment'],$this->input['evia'],self::$user->getId());
$arr = array("status" => "absenceEdited",
"aid" => $this->input['aid'],
"children" => json_encode($this->model->getTaughtStudentsOfTeacher(self::$user->getId())) );
die(json_encode($arr));
}
break;
default:
if(isset($_SESSION['user'] ) ) {
switch ($_SESSION['user']['type'] ) {
case 1:
//parent Login
$guardian = self::$user = $this->model->getTeacherByTeacherId($_SESSION['user']['id']); //Can That Be true? getTeacher?????
//is it needed at all, because ist will be null?????
break;
case 2:
break;
case 3:
break;
default:
break;
}
}else if (self::$user == null) { // not logged in
if (isset($_SESSION['logout'])) { // if just logged out display toast
session_destroy();
session_start();
$this->notify('Abmeldung erfolgreich!');
}
if (isset($_SESSION['timeout'])) { // if timed out out display toast
session_destroy();
session_start();
$this->notify('Login ungültig nach '.$this->sessionValidity. ' Minuten!');
}
return "login";
}
return $this->getDashBoardName();
break;
}
} else {
return "login";
}
return $template;
}
/**
*Creates view and sends relevant data
*
* @param $template string the template to be displayed
*/
protected function display($template) {
$view = View::getInstance();
$this->infoToView['usr'] = self::$user;
//set Module activity
$this->infoToView['modules'] = array("vplan" => true, "events" => true, "news" => true);
if(isset($this->model->getIniParams()['captcha_public_debug']) && Model::$debugCaptcha)
{
$this->infoToView['captcha'] = $this->model->getIniParams()['captcha_public_debug'];
} else {
$this->infoToView['captcha'] = $this->model->getIniParams()['captcha_public'];
}
if (isset($_SESSION['notifications'])) {
if (!isset($this->infoToView['notifications']))
$this->infoToView['notifications'] = array();
foreach ($_SESSION['notifications'] as $notification)
array_push($this->infoToView['notifications'], $notification);
unset($_SESSION['notifications']);
}
$view->setDataForView($this->infoToView);
$view->header($this->getHeaderFix());
$view->loadTemplate($template);
}
/**
* HandleCoverLesson Module - data transmission
*
* @return Boolean
*/
private function handleCoverLessonDataTransmission() {
//Handle data sent per POST
$text = null;
if (isset($this->input["datum"])) {
//bereite DB vor für Einlesen der aktiven Vertretungen
$this->model->prepareForEntry($this->input["datum"]);
//Debug Eintrag in Logdatei
$text = "heutiger Tag: " . $this->input["datum"] . " prepared for entry\r\n";
//$this->model->writeToVpLog($text);
return true;
} else if (isset($this->input["absT"])) {
//Trage abwesende Lehrer ein
$this->model->insertAbsentee($this->input["absT"]);
//Debug Eintrag in Logdatei
$text = "abwesender Lehrer (" . $this->input["absT"] . ") eintragen\r\n";
//$this->model->writeToVpLog($text);
return true;
} else if (isset($this->input["blockR"])) {
//Trage blockierte Räume ein
$this->model->insertBlockedRoom($this->input["blockR"]);
//Debug Eintrag in Logdatei
$text = "blockierte Räume (" . $this->input["blockR"] . ") eintragen\r\n";
//$this->model->writeToVpLog($text);
return true;
} else if (isset($this->input["content"])) {
//Trage Vertretungen ein
$this->model->insertCoverLesson($this->input["content"]);
return true;
} else if (isset($this->input["mail"])) {
//per POST
//Starte Mailversand
$this->sendMails($this->model->getMailList());
//Lösche entfernte Zeilen
$this->model->DeleteInactiveEntries();
return true;
}
return false;
}
/**
* Send all options to view
*/
protected function sendOptions() {
$this->infoToView['assign_end'] = $this->model->getOptions()['assignend'];
$this->infoToView['assign_start'] = $this->model->getOptions()['assignstart'];
$this->infoToView['book_end'] = $this->model->getOptions()['close'];
$this->infoToView['book_start'] = $this->model->getOptions()['open'];
$this->infoToView['est_date'] = $this->model->getOptions()['date'];
if (self::$user instanceof Guardian) {
//nothing happening here ???
} else if (self::$user instanceof Teacher) {
}
}
/**
* Creates userobject of logged in user and saves it to Controller:$user
* NEEDED CHANGES FOR V2
* @param User $usr specify if object already created
*
* @return User the current userobject
*/
protected function createUserObject($usr = null) {
//Debug::writeDebugLog(__method__,"Why am I here?");
if (self::$user != null)
return self::getUser();
if (isset($_SESSION['user']) ) {
$id = $_SESSION['user']['id'];
if ($_SESSION['user']['type'] == 2 ) {
//teacher Login
self::$user = Model::getInstance()->getTeacherByTeacherId($id) ;
} else if ($_SESSION['user']['type'] == 3) {
//student user login
self::$user = Model::getInstance()->getStudentUserById($id) ;
} else {
//same process for admins and parents
self::$user = Model::getInstance()->getUserById($id) ;
}
}
return self::getUser();
}
/**
* teacher's Open Day Management
* assignment of visitable slots
* @return string template to display
*/
protected function teacherSlotDetermination() {
if (self::$user == null)
return "login";
if (!self::$user instanceof Teacher) {
$this->notify("Sie müssen ein Lehrer sein, um auf diese Seite zugreifen zu können!");
return $this->getDashBoardName();
}
if (isset($this->input['asgn'])) {
$this->model->setAssignedSlot($this->input['asgn'], self::$user->getId());
} else if (isset($this->input['del'])) {
$this->model->deleteAssignedSlot($this->input['del'], self::$user->getId());
}
/** @var Teacher $teacher */
$teacher = self::$user;
$this->infoToView['deputat'] = $teacher->getLessonAmount();
$this->infoToView['requiredSlots'] = $teacher->getRequiredSlots();
$this->infoToView['user'] = $teacher;
$missingSlots = ($teacher->getMissingSlots() > 0) ? $teacher->getMissingSlots() : 0;
$this->infoToView['missing_slots'] = $missingSlots;
$this->infoToView['card_title'] = "Sprechzeiten am Elternsprechtag";
if ($missingSlots != 0) {
$this->infoToView['card_title'] = "Festlegung der Sprechzeiten";
}
$this->infoToView['slots_to_show'] = $teacher->getSlotListToAssign();
//To show final bookings appointments of teacher must be read
if (date('Ymd H:i') > $this->infoToView['assign_end']) {
$this->infoToView['teacher_classes'] = $teacher->getTaughtClasses();
$this->infoToView['teacher_appointments'] = $teacher->getAppointmentsOfTeacher();
$this->infoToView['card_title'] = "Ihre Termine am Elternsprechtag";
}
return "tchr_slots";
}
/**
* Logout logic
*
* @return void
*/
protected function logout() {
if(isset($_SESSION['app'])) {
//$this->model->endAppUserSession(self::$user);
}
if (isset($_SESSION['timeout']) ){
session_destroy();
session_start();
$_SESSION['timeout'] = true;
}
if (isset($_SESSION['logout']) ){
session_destroy();
session_start();
$_SESSION['logout'] = true;
}
header("Location: ./");
/*
if (!isset($this->input["console"])) {
header("Location: ./");
}
die(json_encode(array("code" => 200, "message" => "OK", "type" => "logout"))); // should not be needed
*/
}
/**
* Handle pwd reset logic
*/
public function handlePwdReset() {
$this->model->cleanUpPwdReset();
if (isset($this->input['token'])) {
$token = $this->input['token'];
$validToken = $this->model->checkPasswordResetToken($token);
if (isset($this->input['console'])) {
if (!$validToken) {
die(json_encode(array("success" => false, "message" => "Ungültige oder abgelaufene Anfrage")));
}
if (isset($this->input['pwdreset']['pwd'])) {
$array = $this->model->redeemPasswordReset($token, $this->input['pwdreset']['pwd']);
if ($array['success'])
$this->notify("Ihr Passwort wurde erfolgreich geändert!", 4000, true);
die(json_encode($array));
}
}
$this->infoToView['validRequest'] = $validToken;
return "pwdreset";
}
if (!isset($this->input['console']))
return "login";
$success = true;
$message = "OK";
$code = 200;
if (isset($this->input['pwdreset']['mail'])) {
$email = $this->input['pwdreset']['mail'];
if (self::$user != null) {
$message = "Logged in";
$success = false;
$code = 400;
} else {
$validEmail = filter_var($email, FILTER_VALIDATE_EMAIL);
if ($validEmail) {
$isUser = ($usr = $this->model->getUserByMail($email)) != null && $usr->getType() == 1;
if (!$isUser) {
$message = "Diese Email ist mit keinem Benutzer verknüpft!";
$success = false;
$code = 404;
} else {
$resp = $this->model->generatePasswordReset($email);
if (!$resp['success']) {
$message = $resp['message'];
$success = false;
$code = 500;
} else {
$key = $resp['key'];
$resp = $this->sendPwdResetMail($email, $key);
if (!$resp['success']) {
$success = false;
$message = "Error while sending mail: " . $resp['message'];
$code = 500;
}
}
}
} else {
$message = "Invalid Email";
$success = false;
$code = 400;
}
}
} else {
$success = false;
$message = "Invalid Input";
$code = 400;
}
ChromePhp::info("boii");
die(json_encode(array("success" => $success, "message" => $message, "code" => $code)));
}
/**
* Sends password reset email to specified email in which password reset link is given
* @param $email
* @param $token
* @return array
*/
public function sendPwdResetMail($email, $token) {
require "PHPMailer.php";
$mail = new PHPMailer();
$mail->setFrom("[email protected]", "Suso Gymnasium Intern");
$mail->CharSet = "UTF-8";
$mail->isHTML();
$mail->Subject = "Passwort vergessen";
$url = $_SERVER['HTTP_HOST'] . "/intern/index.php?type=pwdreset&token=$token";
ob_start();
include("templates/resetmail.php");
$body = ob_get_clean();
$mail->Body = $body;
$mail->addAddress($email);
if ($mail->send())
return array("success" => true);
return array("success" => false, "message" => $mail->ErrorInfo);
}
/**
* Handles parent's est logic (Open Day bookings)
* complex functions of bookins and view of bookes slote
* @return string template to be displayed
*/
protected function handleParentEst() {
if (self::$user == null) {
return "login";
} else if (!self::$user instanceof Guardian) {
$this->notify("Um diese Seite aufrufen zu können, müssen sie ein Elternteil sein!");
return $this->getDashBoardName();
} else if (($open = $this->getOption("open", "20000101")) > ($today = date("Ymd H:i"))) {
$date = DateTime::createFromFormat("Ymd H:i", $open);
if ($date == false)
$this->notify("Diese Seite kann noch nicht aufgerufen werden!");
else
$this->notify("Diese Seite kann erst am " . date("d.m.Y", $date->getTimestamp()) . " aufgerufen werden!");
return $this->getDashBoardName();
}
/** @var Guardian $guardian */
$guardian = self::$user;
$bookingTimeIsOver = ($today > ($end = $this->getOption('close')));
if (isset($this->input['slot']) && isset($this->input['action'])) { //TODO: maybe do this with js?
$slot = $this->input['slot'];
$action = $this->input['action'];
if ($bookingTimeIsOver) {
$date = DateTime::createFromFormat("Ymd H:i", $open);
$this->notify("Es ist nicht länger möglich zu buchen" . ($date != false ? ". Die Frist war bis zum " . date("d.m.Y", $date->getTimestamp()) : "") . '!');
} else if ($this->model->parentOwnsAppointment($guardian->getParentId(), $slot)) {
if ($action == 'book') {
//book
$this->model->bookingAdd($slot, $guardian->getParentId());
} else if ($action == 'del') {
//delete booking
$this->model->bookingDelete($slot);
}
header("Location: .?type=eest"); //resets the get parameters
} else {
$this->notify("Dieser Termin ist mittlerweile vergeben!");
}
}
$students = array();
$this->infoToView['user'] = $guardian;
$this->infoToView['estdate'] = $this->getOption('date', '20000101');
if (!$bookingTimeIsOver) {
$limit = $this->getOption('limit', 10);
$teachers = $guardian->getTeachersOfAllChildren($limit);
$this->sortByAppointment($teachers);
$this->infoToView['parents'] = $this->model->identifySecondParent($guardian->getParentId() );
$this->infoToView['teachers'] = $teachers;
$this->infoToView['maxAppointments'] = $this->getOption('allowedbookings', 3) * count($guardian->getESTChildren($limit));
$this->infoToView['appointments'] = $guardian->getAppointments();
$this->infoToView['bookedTeachers'] = $guardian->getBookedTeachers();
} else {
$this->infoToView['bookingDetails'] = $this->model->getBookingDetails($guardian->getParentId());
}
return "parent_est";
}
/**
* Events Logic
* used for creation of school itinerary
* @return string template to be displayed
*/
private function handleEvents() {
$path = $this->model->getIniParams();
$filePathBase = './' . $path['download'] . '/' . $path['icsfile'];
$this->infoToView['user'] = self::$user;
if (self::$user instanceof Guardian || self::$user instanceof StudentUser) {
$this->infoToView['events'] = $this->model->getEvents();
$icsfile = $filePathBase . "Public.ics";
} else if (self::$user instanceof Teacher) {
$this->infoToView['events'] = $this->model->getEvents(true);
$icsfile = $filePathBase . "Staff.ics";
} else {
//no user object instantiated
$this->infoToView['events'] = $this->model->getEvents();
$icsfile = $filePathBase . "Public.ics";
}
$this->infoToView['months'] = $this->model->getMonths();
$this->infoToView['icsPath'] = $icsfile;
return "events";
}
/**
* Coverlesson logic
*
* @return string
*/
private function handleCoverLessons() {
$usr = self::getUser();
if (isset($this->input['user']) && isset($this->input['pwd'])) {
$usr = $this->model->getLdapUserByLdapNameAndPwd($this->input['user'], $this->input['pwd']);
}
if ($usr == null && isset($this->input['console']))
die(json_encode(array("code" => 404, "message" => "Invalid userdata!")));
else if ($usr == null)
return "login";
$isStaff = (self::$user instanceOf Teacher) ? true : false;
$this->infoToView["VP_showAll"] = $usr instanceof Teacher && $usr->getVpViewStatus();
$inputAll = isset($this->input['all']) ? ($this->input['all'] == null ? true : $this->input['all']) : false;
if (isset($this->input['all']))
$this->infoToView['VP_showAll'] = $inputAll;
$this->infoToView['VP_allDays'] = $this->model->getVPDays($isStaff || $this->infoToView['VP_showAll']);
$this->infoToView['user'] = $usr;
if ($this->infoToView['VP_showAll']) {
$this->infoToView['VP_coverLessons'] = $this->model->getAllCoverLessons($this->infoToView['VP_showAll'], null, $this->infoToView['VP_allDays']);
$this->infoToView['VP_blockedRooms'] = $this->model->getBlockedRooms($this->infoToView['VP_allDays']);
$this->infoToView['VP_absentTeachers'] = $this->model->getAbsentTeachers($this->infoToView['VP_allDays']);
}
if ($usr instanceof Teacher) {
$isStaff = true;
$this->infoToView['VP_coverLessons'] = $this->model->getAllCoverLessons($this->infoToView['VP_showAll'], $usr, $this->infoToView['VP_allDays']);
$this->infoToView['VP_blockedRooms'] = $this->model->getBlockedRooms($this->infoToView['VP_allDays']);
$this->infoToView['VP_absentTeachers'] = $this->model->getAbsentTeachers($this->infoToView['VP_allDays']);
} else if ($usr instanceOf Guardian) {
/** @var Student $child */
$classes = array();
foreach ($this->infoToView["children"] as $child) {
$classes[] = $child->getClass();
}
if (!isset($this->infoToView['VP_coverLessons'])) {
$this->infoToView['VP_coverLessons'] = $this->model->getAllCoverLessonsParents($classes, $this->infoToView['VP_allDays']);
}
} else if ($usr instanceof StudentUser) {
if (!isset($this->infoToView['VP_coverLessons'])) {
$this->infoToView['VP_coverLessons'] = $this->model->getAllCoverLessonsStudents($usr, $this->infoToView['VP_allDays']);
}
}
$this->infoToView['VP_lastUpdate'] = $this->model->getUpdateTime();
$this->infoToView['VP_termine'] = $this->model->getNextDates($isStaff);
if (isset($this->input['console'])) {
$lessons = array();
try {
if (isset($this->infoToView['VP_coverLessons']) ) {
foreach ($this->infoToView['VP_coverLessons'] as $date => $data) {
$coverLessonsThisDay = array();
/** @var CoverLesson $coverLesson */
foreach ($data as $coverLesson) {
$coverLessonArr = array("subject" => $coverLesson->eFach, "teacher" => $coverLesson->eTeacherObject->getShortName(),
"subteacher" => $coverLesson->vTeacherObject->getUntisName(), "subsubject" => $coverLesson->vFach, "subroom" => $coverLesson->vRaum,
"classes" => $coverLesson->klassen, "comment" => $coverLesson->kommentar, "hour" => $coverLesson->stunde);
$coverLessonsThisDay[] = $coverLessonArr;
}
$lessons[$date] = $coverLessonsThisDay;
}
}
} catch (Exception $e) {
ChromePhp::error("Exception while trying to put coverLessons into array: " . $e->getMessage());
}
$data = array("user" => $usr, "coverlessons" => $lessons);
header('Content-Type: application/json');
die(json_encode($data, JSON_PRETTY_PRINT));
}
return "vplan";
}
/**
* Register logic
*
* @return string returns template to be displayed
*/
protected function register() {
$input = $this->input;
$model = $this->model;
# check, then write into database, then login (session var...)
$success = true;
$notification = array();
ChromePhp::info("-- Register --");
$pwd = $input['register']['pwd'];
$mail = $input['register']['mail'];
$name = $input['register']['name'];
$surname = $input['register']['surname'];
ChromePhp::info("Email: " . $mail);
if (!filter_var($mail, FILTER_VALIDATE_EMAIL)) {
array_push($notification, "Bitte geben Sie eine valide Email-Addresse an.");
ChromePhp::info("Invalid email");
$success = false;
}
if ($success && ($userObj = $model->getUserByMail($mail)) != null) {
$id = $userObj->getId();
array_push($notification, "Diese Email-Addresse ist bereits registriert.");
ChromePhp::info("Email bereits registriert mit id $id");
$success = false;
}
/*
if ($success && !isset($input['captcha'])) {
$success = false;
ChromePhp::error("No captcha given!");
array_push($notification, "Das Captcha wurde nicht ausgeführt!");
}
if ($success) {
$success = $this->checkCaptcha($input['captcha']);
if (!$success) {
ChromePhp::error("Invalid captcha!");
array_push($notification, "Das ist invalide!");
}
}*/