-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathWorkplaceAllocation.php
1102 lines (920 loc) · 42.3 KB
/
WorkplaceAllocation.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
/**
* WorkplaceAllocation class
* main class of Workplace allocation plugin
* manages the views and controllers of the plugin
*
* Workplace allocation Plugin:
* allows admins of institutes and courses to manage the registration of students to institute or course related workplaces.
*
* Created by PhpStorm.
* User: jayjay
* Date: 09.05.16
* Time: 10:26
*/
class WorkplaceAllocation extends StudIPPlugin implements StandardPlugin, HomepagePlugin
{
/** @var Flexi_TemplateFactory */
private $templateFactory;
/**
* WorkplaceAllocation constructor.
*
* called by StudIP core
*/
public function __construct()
{
parent::__construct();
StudipAutoloader::register();
StudipAutoloader::addAutoloadPath(__DIR__ . '/classes');
$this->templateFactory = new Flexi_TemplateFactory($this->getPluginPath() . '/templates');
$currentUser = User::findCurrent();
$request = Request::getInstance();
if (!isset($request['username']) || $request['username'] == $currentUser->username) {
/** @var Navigation $profileNavigation */
$profileNavigation = Navigation::getItem('/profile');
$mySchedules = new Navigation('Arbeitsplätze', PluginEngine::getURL('WorkplaceAllocation', [], 'my_schedules'));
$mySchedules->setImage(new Icon('computer'));
$mySchedules->setActiveImage(new Icon('computer'));
$profileNavigation->addSubNavigation('workplace_schedules', $mySchedules);
}
}
/**
* Return a template (an instance of the Flexi_Template class)
* to be rendered on the course summary page. Return NULL to
* render nothing for this plugin.
*
* The template will automatically get a standard layout, which
* can be configured via attributes set on the template:
*
* title title to display, defaults to plugin name
* icon_url icon for this plugin (if any)
* admin_url admin link for this plugin (if any)
* admin_title title for admin link (default: Administration)
*
* @param $course_id
* @return Flexi_Template template object to render or NULL
*/
public function getInfoTemplate($course_id)
{
return null;
}
/**
* Return a navigation object representing this plugin in the
* course overview table or return NULL if you want to display
* no icon for this plugin (or course). The navigation object's
* title will not be shown, only the image (and its associated
* attributes like 'title') and the URL are actually used.
*
* By convention, new or changed plugin content is indicated
* by a different icon and a corresponding tooltip.
*
* @param string $course_id course or institute range id
* @param int $last_visit time of user's last visit
* @param string $user_id the user to get the navigation for
*
* @return object navigation item to render or NULL
*/
public function getIconNavigation($course_id, $last_visit, $user_id)
{
return null;
}
/**
* Return a navigation object representing this plugin in the
* course overview table or return NULL if you want to display
* no icon for this plugin (or course). The navigation object's
* title will not be shown, only the image (and its associated
* attributes like 'title') and the URL are actually used.
*
* By convention, new or changed plugin content is indicated
* by a different icon and a corresponding tooltip.
*
* @param string $course_id course or institute range id
*
* @return array navigation item to render or NULL
*/
public function getTabNavigation($course_id)
{
if (!$this->isActivated($course_id)) {
return null;
}
$workplaceAllocation = new Navigation('Arbeitsplätze', PluginEngine::getURL('WorkplaceAllocation', [], 'show'));
$workplaceAllocation->setImage(new Icon('computer'));
$workplaceAllocation->setActiveImage(new Icon('computer'));
if ($this->user_has_admin_perm($course_id)) {
$workplacesAdminNav = new Navigation('Arbeitsplätze', PluginEngine::getURL('WorkplaceAllocation', [], 'admin'));
$workplacesAdminNav->setDescription('Richten Sie Anmeldungen zu Arbeitsplätzen für Ihre Studierenden ein.');
$workplacesAdminNav->setImage(new Icon('computer'));
/** @var Navigation $courseAdminNav */
$courseAdminNav = Navigation::getItem('course/admin');
$courseAdminNav->addSubNavigation('workplaces', $workplacesAdminNav);
}
return [
'workplaces' => $workplaceAllocation
];
}
/**
* return a list of ContentElement-objects, containing
* everything new in this module
*
* @param string $course_id the course-id to get the new stuff for
* @param $since
* @param string $user_id the user to get the notifcation-objects for
* @return array an array of ContentElement-objects
* @internal param int $last_visit when was the last time the user visited this module
*/
public function getNotificationObjects($course_id, $since, $user_id)
{
return [];
}
/**
* check if actual user has admin permissions in the actual context
*
* @param string $course_id context id
* @return bool
*/
private function user_has_admin_perm($course_id)
{
$status = $GLOBALS['perm']->get_studip_perm($course_id, get_userid());
if ($status == 'dozent' || $status == 'tutor' || $status == 'admin' || $status == 'root') {
return true;
} else {
return false;
}
}
/**
* check if actual user is member of the actual context
*
* @return bool
*/
private function user_is_member()
{
$current_institute = Institute::findCurrent();
$user_institutes = InstituteMember::findByUser(get_userid());
for ($i = 0, $size = count($user_institutes); $i < $size; $i++) {
if ($current_institute->getId() == $user_institutes[$i]['institut_id']) {
return true;
}
}
return false;
}
/**
* main route for students
*/
public function show_action()
{
Navigation::activateItem('/course/workplaces');
/** @var Flexi_Template $template */
$template = $this->templateFactory->open('show');
$template->set_attribute('workplaces', Workplace::getWorkplacesByContext(Request::get('cid')));
$template->set_layout($GLOBALS['template_factory']->open('layouts/base'));
print($template->render());
}
/**
* main route for admins
*
* @throws AccessDeniedException
*/
public function admin_action()
{
if (!$this->user_has_admin_perm(Request::get('cid'))) {
throw new AccessDeniedException('Du hast nicht die nötigen Rechte zum Aufruf dieser Seite');
}
$actionsWidget = new ActionsWidget();
$actionsWidget->addLink(
'Arbeitsplatz hinzufügen',
PluginEngine::getLink('WorkplaceAllocation', [], 'addWorkplace'),
new Icon('add')
);
$actionsWidget->addLink(
'Sperrungen verwalten',
PluginEngine::getLink('WorkplaceAllocation', [], 'manageBlacklist'),
new Icon('community')
);
$actionsWidget->addLink(
'Benachrichtigungstexte verwalten',
PluginEngine::getLink('WorkplaceAllocation', [], 'manageMail'),
new Icon('mail')
);
$actionsWidget->addLink(
'Mailingliste verwalten',
PluginEngine::getLink('WorkplaceAllocation', [], 'manageNotifiedUsers'),
new Icon('mail')
);
$actionsWidget->addLink(
'Alle Arbeitsplätze drucken',
PluginEngine::getLink('WorkplaceAllocation', [], 'pdf'),
new Icon('print'),
['target' => '_blank']
);
Sidebar::Get()->addWidget($actionsWidget);
Navigation::activateItem('/course/admin/workplaces');
/** @var Flexi_Template $template */
$template = $this->templateFactory->open('admin');
$template->set_layout($GLOBALS['template_factory']->open('layouts/base'));
$template->set_attribute('workplaces', Workplace::getWorkplacesByContext(Request::get('cid')));
PageLayout::addStylesheet($this->getPluginURL() . '/assets/stylesheets/link_button.css');
print($template->render());
}
/**
* save activation route
* set a new activation state for all workplaces in the POST request
*
* @throws AccessDeniedException
*/
public function saveActivation_action()
{
if (!$this->user_has_admin_perm(Request::get('cid'))) {
throw new AccessDeniedException('Du hast nicht die nötigen Rechte zum Aufruf dieser Seite');
}
if (Request::isPost()) {
CSRFProtection::verifySecurityToken();
$workplaces = Workplace::getWorkplacesByContext(Request::get('cid'));
foreach ($workplaces as $workplace) {
if (Request::get($workplace->getId()) != null) {
$workplace->activate();
} else {
$workplace->deactivate();
}
}
}
header('Location: ' . PluginEngine::getLink('WorkplaceAllocation', [], 'admin'));
exit;
}
/**
* route to create new workplace
*
* @throws AccessDeniedException
*/
public function addWorkplace_action()
{
if (!$this->user_has_admin_perm(Request::get('cid'))) {
throw new AccessDeniedException('Du hast nicht die nötigen Rechte zum Aufruf dieser Seite');
}
$errorDetails = [];
$error = false;
if (Request::isPost()) {
CSRFProtection::verifySecurityToken();
$request = Request::getInstance();
if (!($request['wp_name'])) {
$error = true;
$errorDetails[] = _('Bitte geben Sie einen Namen für den Arbeitsplatz an.');
} else {
Workplace::newWorkplace($request['wp_name'], $request['wp_description'], $request['cid']);
header('Location: ' . PluginEngine::getLink('WorkplaceAllocation', [], 'admin'));
}
} else {
Request::set('wp_name', '');
Request::set('wp_description', '');
}
Navigation::activateItem('/course/admin/workplaces');
/** @var Flexi_Template $template */
$template = $this->templateFactory->open('addWorkplace');
$template->set_layout($GLOBALS['template_factory']->open('layouts/base'));
$template->set_attribute('error', $error);
$template->set_attribute('errorDetails', $errorDetails);
print($template->render());
}
/**
* route to delete a workplace
* first ask if you really would like to delete this workplace
*
* @throws AccessDeniedException
*/
public function delWorkplace_action()
{
if (!$this->user_has_admin_perm(Request::get('cid'))) {
throw new AccessDeniedException('Du hast nicht die nötigen Rechte zum Aufruf dieser Seite');
}
if (Request::isPost()) {
CSRFProtection::verifySecurityToken();
$request = Request::getInstance();
$workplace = Workplace::getWorkplace(Request::get('wp_id'));
if (!isset($request['confirm'])) {
$trueResponse = $_POST;
$trueResponse['confirm'] = true;
$falseResponse = $_POST;
$falseResponse['confirm'] = false;
$this->admin_action();
print(createQuestion2(
'Möchten Sie den Arbeitsplatz "' . $workplace->getName() . '" wirklich löschen ?',
$trueResponse,
$falseResponse,
'?cid=' . $request['cid']
));
}
if ($request['confirm']) {
$workplace->deleteWorkplace();
}
header('Location: ' . PluginEngine::getLink('WorkplaceAllocation', [], 'admin'));
}
}
/**
* route to edit workplace
*
* @throws AccessDeniedException
*/
public function editWorkplace_action()
{
if (!$this->user_has_admin_perm(Request::get('cid'))) {
throw new AccessDeniedException('Du hast nicht die nötigen Rechte zum Aufruf dieser Seite');
}
Navigation::activateItem('/course/admin/workplaces');
$workplace = Workplace::getWorkplace(Request::get('wp_id'));
$rule = $workplace->getRule();
/** @var string[] $messageBoxes */
$messageBoxes = [];
$errorDetails = [];
$error = false;
if (Request::isPost()) {
CSRFProtection::verifySecurityToken();
$request = Request::getInstance();
if (isset($request['day']) && (empty($request['daily_start_hour']) || empty($request['daily_start_minute']) || empty($request['daily_end_hour']) || empty($request['daily_end_minute']))) {
$error = true;
$errorDetails[] = 'Bitte geben sie einen korrekten Wert für die tägliche Öffnungszeit an.';
} else {
$workplace->setDescription($request['wp_description']);
$workplace->setName($request['wp_name']);
$start = 'PT' . $request['daily_start_hour'] . 'H' . $request['daily_start_minute'] . 'M';
$end = 'PT' . $request['daily_end_hour'] . 'H' . $request['daily_end_minute'] . 'M';
if ($request['daily_pause_exist'] == 'on') {
$pauseStart = 'PT' . $request['daily_pause_start_hour'] . 'H' . $request['daily_pause_start_minute'] . 'M';
$pauseEnd = 'PT' . $request['daily_pause_end_hour'] . 'H' . $request['daily_pause_end_minute'] . 'M';
} else {
$pauseStart = null;
$pauseEnd = null;
}
if ($rule == null) {
$workplace->createRule($start, $end, $pauseStart, $pauseEnd, $request['registration_start'], $request['registration_end'], $request['slot_duration']);
$rule = $workplace->getRule();
} else {
$rule->setStart($start);
$rule->setEnd($end);
$rule->setPauseStart($pauseStart);
$rule->setPauseEnd($pauseEnd);
$rule->setRegistrationStart($request['registration_start']);
$rule->setRegistrationEnd($request['registration_end']);
$rule->setSlotDuration($request['slot_duration']);
}
if (isset($request['one_schedule_by_day_and_user']) && $request['one_schedule_by_day_and_user'] == 'on') {
$rule->setOneScheduleByDayAndUser(true);
} else {
$rule->setOneScheduleByDayAndUser(false);
}
if (isset($request['only_members_can_book']) && $request['only_members_can_book'] == 'on') {
$rule->setOnlyMembersCanBook(true);
} else {
$rule->setOnlyMembersCanBook(false);
}
if (is_array($request['day'])) {
for ($i = 0; $i < 7; $i++) {
if (in_array($i, $request['day'])) {
$rule->setDay($i, true);
} else {
$rule->setDay($i, false);
}
}
}
$messageBoxes[] = MessageBox::success(
'Erfolgreich gespeichert',
['<a href="' . PluginEngine::getLink('WorkplaceAllocation', [], 'admin') . '">Zurück zur Übersicht</a>']
);
}
}
if ($error) {
$messageBoxes[] = MessageBox::error(_('Bitte beheben Sie erst folgende Fehler, bevor Sie fortfahren:'), $errorDetails);
}
/** @var Flexi_Template $template */
$template = $this->templateFactory->open('editWorkplace');
$template->set_layout($GLOBALS['template_factory']->open('layouts/base'));
$template->set_attribute('workplace', $workplace);
$template->set_attribute('messageBoxes', $messageBoxes);
print($template->render());
}
/**
* route to add schedule
*
* @param bool $isSetNavigation if navigation has already been activated, set true
*/
public function addSchedule_action($isSetNavigation = false)
{
if (!$isSetNavigation) {
Navigation::activateItem('/course/admin/workplaces');
}
// file based lock to limit schedule manipulations to one user per workplace at once
FileLock::setDirectory($GLOBALS['TMP_PATH']);
$lock = new FileLock('wp_'.Request::get('wp_id'));
if (!$this->user_has_admin_perm(Request::get('cid'))) {
$admin = false;
} else {
$admin = true;
}
$workplace = Workplace::getWorkplace(Request::get('wp_id'));
if (!$admin && $workplace->getRule()->isOnlyMembersCanBook() && !$this->user_is_member()) {
throw new AccessDeniedException('Termine an diesem Arbeitsplatz sind nur für Mitglieder der Einrichtung buchbar');
}
$nowTime = new DateTime();
if (Request::get('day') != null) {
$day = new DateTime(Request::get('day'));
} else {
$day = new DateTime($nowTime->format('d.m.Y'));
}
$messageBox = null;
if (Request::isPost() && !(Request::get('embedded', $default = false))) {
CSRFProtection::verifySecurityToken();
$request = Request::getInstance();
if ($lock->isLocked($data)) {
if ($data['timestamp'] + 60 > time()) {
$lock->release();
} else {
$messageBoxes[] = MessageBox::error('Die Änderung konnte nicht durchgeführt werden');
$success = false;
}
}
if (!$lock->isLocked($data)) {
// closing lock for schedule manipulations or waiting
$lock->lock();
if (isset($request['next_schedule']) && $request['next_schedule'] == 'true') {
if (!$workplace->getRule()->bookFirstPossibleSchedule($workplace, $day, $admin)) {
if (!$workplace->getRule()->isDayBookable($day, $admin, $workplace)) {
$messageBox = MessageBox::error('Der Termin konnte nicht gebucht werden, dies kann verschiedene Ursachen haben', ['Sie wurden gesperrt.', 'Es ist nur ein Termin pro Nutzer und Tag zugelassen.', 'Es ist zu einer Kollision gekommen, in diesem Falle versuche in der Übersicht nochmal einen Termin für diesen Tag zu buchen um einen Platz auf der Warteliste zu bekommen.']);
} else {
//$waitingListPlacement = WaitingList::push($workplace, $day);
//if ($waitingListPlacement != null) {
// $messageBox = MessageBox::error('Am ' . $day->format('d.m.Y') . ' ist kein Termin mehr frei. Sie wurden in die Warteliste auf Platz ' . $waitingListPlacement . ' eingetragen');
//}
$messageBox = MessageBox::error('Am ' . $day->format('d.m.Y') . ' ist kein Termin mehr frei. ');
}
}
} elseif (isset($request['action']) && $request['action'] == 'move_up' && isset($request['wp_schedule_id']) && isset($request['wp_schedule_new_start'])) {
$schedule = Schedule::getSchedule($request['wp_schedule_id']);
$newStart = new DateTime('@' . $request['wp_schedule_new_start']);
$schedule->setStart($newStart, true);
$workplace->refillFromWaitingList($day);
} elseif (isset($request['dont_book'])) {
// don't book just show
} else {
$start = $request['wp_schedule_start'];
$duration = $request['wp_schedule_duration'];
if ($workplace->getRule()->isBookable(new DateTime('@' . $start), new DateInterval($duration), $workplace, $admin)) {
$blocked = false;
if (isset($request['wp_schedule_type']) && $request['wp_schedule_type'] == 'blocked') {
$blocked = true;
}
Schedule::newSchedule(get_userid(), $workplace->getId(), $start, $duration, '', $blocked);
} else {
$messageBox = MessageBox::error('Der Termin konnte nicht gebucht werden, dies kann verschiedene Ursachen haben', ['Der Termin ist bereits belegt.', 'Es ist nur ein Termin pro Nutzer und Tag zugelassen.']);
}
}
$lock->release();
}
}
/** @var Flexi_Template $template */
$template = $this->templateFactory->open('addSchedule');
$template->set_layout($GLOBALS['template_factory']->open('layouts/base'));
$template->set_attribute('messageBox', $messageBox);
$template->set_attribute('workplace', $workplace);
$template->set_attribute('admin', $admin);
$template->set_attribute('day', $day);
PageLayout::addStylesheet($this->getPluginURL() . '/assets/stylesheets/timetable.css');
print($template->render());
}
/**
* route to timetable view
*/
public function timetable_action()
{
Navigation::activateItem('/course/workplaces');
$this->addSchedule_action(true);
}
/**
* route to edit a specific schedule
*/
public function editSchedule_action()
{
if (!$this->user_has_admin_perm(Request::get('cid'))) {
Navigation::activateItem('/course/workplaces');
$admin = false;
} else {
Navigation::activateItem('/course/admin/workplaces');
$admin = true;
}
$schedule = Schedule::getSchedule(Request::get('s_id'));
// file based lock to limit schedule manipulations to one user per workplace at once
FileLock::setDirectory($GLOBALS['TMP_PATH']);
$lock = new FileLock('wp_'.$schedule->getWorkplace()->getId());
$messageBoxes = [];
if (Request::isPost()) {
CSRFProtection::verifySecurityToken();
$request = Request::getInstance();
if ($lock->isLocked($data)) {
if ($data['timestamp'] + 60 > time()) {
$lock->release();
} else {
$messageBoxes[] = MessageBox::error('Die Änderung konnte nicht durchgeführt werden');
$success = false;
}
}
if (!$lock->isLocked($data)) {
// closing lock for schedule manipulations or waiting
$lock->lock();
$success = true;
if (isset($request['s_duration']) && $admin) {
$duration = new DateInterval($request['s_duration']);
if (!$schedule->setDuration($duration)) {
$messageBoxes[] = MessageBox::error('Die Änderung der Terminlänge ist nicht zulässig');
$success = false;
}
}
if (isset($request['s_comment']) && $schedule->getOwner()->user_id == get_userid()) {
$schedule->setComment($request['s_comment']);
}
if (isset($request['s_owner']) && $admin) {
$newOwner = User::findFull($request['s_owner']);
$schedule->setOwner($newOwner);
}
if ($success) {
$backLink = PluginEngine::getLink(
'WorkplaceAllocation',
['wp_id' => $schedule->getWorkplace()->getId(),
'week' => '1',
'day' => $schedule->getStart()->format('d.m.Y')],
$admin ? 'addSchedule' : 'timetable'
);
$messageBoxes[] = MessageBox::success('Erfolgreich gespeichert', ['<a href="' . $backLink . '">zurück</a>']);
}
$lock->release();
}
}
/** @var Flexi_Template $template */
$template = $this->templateFactory->open('editSchedule');
$template->set_layout($GLOBALS['template_factory']->open('layouts/base'));
$template->set_attribute('schedule', $schedule);
$template->set_attribute('admin', $admin);
$template->set_attribute('messageBoxes', $messageBoxes);
print($template->render());
}
/**
* route to remove schedule
* first asks if you really like to remove this schedule
*
* @throws AccessDeniedException
*/
public function removeSchedule_action()
{
$schedule = Schedule::getSchedule(Request::get('s_id'));
$admin = $this->user_has_admin_perm(Request::get('cid'));
if (!($admin || $schedule->getOwner()->user_id == get_userid())) {
throw new AccessDeniedException('Du hast nicht die nötigen Rechte zum Aufruf dieser Seite');
}
if (Request::isPost()) {
CSRFProtection::verifySecurityToken();
$request = Request::getInstance();
if (!isset($request['confirm'])) {
if ($schedule->getStart() > new DateTime()) { //start liegt in Zukunft --> delete action
$request->set('day', $schedule->getStart()->format('d.m.Y'));
$request->set('wp_id', $schedule->getWorkplace()->getId());
$request->set('week', '1');
$request->set('embedded', '1');
$trueResponse = $_POST;
$trueResponse['confirm'] = true;
$falseResponse = $_POST;
$falseResponse['confirm'] = false;
$admin ? $this->addSchedule_action() : $this->timetable_action();
print(createQuestion2(
'Möchten Sie den Termin wirklich löschen ?',
$trueResponse,
$falseResponse,
'?cid=' . $request['cid']
));
} else {
throw new AccessDeniedException('Der Termin ist bereits abgelaufen');
}
}
if ($request['confirm']) {
$schedule->deleteSchedule();
}
header('Location: ' . PluginEngine::getURL('WorkplaceAllocation', ['wp_id' => $schedule->getWorkplace()->getId(), 'week' => '1', 'day' => $schedule->getStart()->format('d.m.Y')], $admin ? 'addSchedule': 'timetable'));
}
}
/**
* route to manage blacklist
*
* @throws AccessDeniedException
*/
public function manageBlacklist_action()
{
if (!$this->user_has_admin_perm(Request::get('cid'))) {
throw new AccessDeniedException('Du hast nicht die nötigen Rechte zum Aufruf dieser Seite');
}
if (Request::isPost()) {
CSRFProtection::verifySecurityToken();
$request = Request::getInstance();
if (isset($request['action']) && isset($request['user_id'])) {
$user = User::findFull($request['user_id']);
switch ($request['action']) {
case 'delete':
if (!isset($request['delete'])) {
$trueResponse = $_POST;
$trueResponse['delete'] = true;
$falseResponse = $_POST;
$falseResponse['delete'] = false;
print(createQuestion2(
'Möchten sie den Nutzer ' . $user->vorname . ' ' . $user->nachname . ' (' . $user->username . ') wirklich von der Sperrliste entfernen?',
$trueResponse,
$falseResponse,
'?cid=' . $request['cid']
));
}
if ($request['delete']) {
Blacklist::getBlacklist()->deleteFromList($user->user_id);
}
break;
case 'add':
if (!isset($request['add'])) {
$trueResponse = $_POST;
$trueResponse['add'] = true;
$falseResponse = $_POST;
$falseResponse['add'] = false;
print(createQuestion2(
'Möchten sie den Nutzer ' . $user->vorname . ' ' . $user->nachname . ' (' . $user->username . ') wirklich zur Sperrliste hinzufügen und in der Zeit der Sperrung alle Reservierungen löschen?',
$trueResponse,
$falseResponse,
'?cid=' . $request['cid']
));
}
if ($request['add']) {
$expiration = null;
if (sizeof($request['expiration']) > 0 && $request['expiration'] > 0) {
$time = new DateTime();
$today = new DateTime($time->format('d.m.Y'));
$expiration = $today->getTimestamp() + ($request['expiration'] * 24 * 60 * 60) -1;
$expirationDatetime = new DateTime('@' . $expiration);
}
$user_schedules = Schedule::getSchedulesByUser($user->user_id);
foreach ($user_schedules as $schedule) {
if ($expiration == null || $schedule->getStart() < $expirationDatetime) {
$schedule->deleteSchedule();
}
}
Blacklist::getBlacklist()->addToList($user->user_id, $expiration);
}
break;
}
}
}
Navigation::activateItem('/course/admin/workplaces');
/** @var Flexi_Template $template */
$template = $this->templateFactory->open('manageBlacklist');
$template->set_layout($GLOBALS['template_factory']->open('layouts/base'));
$template->set_attribute('blacklist', Blacklist::getBlacklist(Request::get('cid')));
PageLayout::addStylesheet($this->getPluginURL() . '/assets/stylesheets/link_button.css');
print($template->render());
}
/**
* route to manage custom StudIP mail texts
*
* @throws AccessDeniedException
*/
public function manageMail_action()
{
if (!$this->user_has_admin_perm(Request::get('cid'))) {
throw new AccessDeniedException('Du hast nicht die nötigen Rechte zum Aufruf dieser Seite');
}
Navigation::activateItem('/course/admin/workplaces');
require_once(__DIR__ . '/conf/default_mesage_texts.php');
global $defaultMessageTexts;
foreach ($defaultMessageTexts as $messageTextId => $messageTextDetails) {
$studipMessage = WpMessages::findBySQL("context_id = ? AND hook_point = ?", [Request::get('cid'), $messageTextId]);
if (sizeof($studipMessage) > 0) {
$defaultMessageTexts[$messageTextId]['studip_message'] = $studipMessage[0];
} else {
$defaultMessageTexts[$messageTextId]['studip_message'] = null;
}
}
/** @var Flexi_Template $template */
$template = $this->templateFactory->open('manageMail');
$template->set_layout($GLOBALS['template_factory']->open('layouts/base'));
$template->set_attribute('defaultMessageTexts', $defaultMessageTexts);
print($template->render());
}
/**
* route to edit custom StudIP message texts
*
* @throws AccessDeniedException
*/
public function editMailtext_action()
{
if (!$this->user_has_admin_perm(Request::get('cid'))) {
throw new AccessDeniedException('Du hast nicht die nötigen Rechte zum Aufruf dieser Seite');
}
$message = WpMessages::findBySQL("context_id = ? AND hook_point = ?", [Request::get('cid'), Request::get('hook_point')]);
if (sizeof($message) == 0) {
/** @var WpMessages $message */
$message = null;
} else {
/** @var WpMessages $message */
$message = $message[0];
}
if (Request::isPost()) {
CSRFProtection::verifySecurityToken();
$request = Request::getInstance();
$data = [
'context_id' => $request['cid'],
'hook_point' => $request['hook_point'],
'subject' => $request['subject'],
'message' => $request['text'],
'active' => isset($request['active']) && $request['active'] == 'on'
];
if ($message == null) {
$message = new WpMessages();
$message->id = $message->getNewId();
}
foreach ($data as $key => $item) {
//$message->setValue($key, $item);
$message->$key = $item;
}
$message->store();
header('Location: ' . PluginEngine::getLink('WorkplaceAllocation', [], 'manageMail'));
}
Navigation::activateItem('/course/admin/workplaces');
/** @var Flexi_Template $template */
$template = $this->templateFactory->open('editMailtext');
$template->set_layout($GLOBALS['template_factory']->open('layouts/base'));
$template->set_attribute('message', $message);
print($template->render());
}
/**
* route to manage users who get notification mails when schedules are created
*
* @throws AccessDeniedException
*/
public function manageNotifiedUsers_action()
{
if (!$this->user_has_admin_perm(Request::get('cid'))) {
throw new AccessDeniedException('Du hast nicht die nötigen Rechte zum Aufruf dieser Seite');
}
Navigation::activateItem('/course/admin/workplaces');
/** @var string[] $messageBoxes */
$messageBoxes = [];
$userlist = NotifiedUserList::getNotifiedUserList();
if (Request::isPost()) {
CSRFProtection::verifySecurityToken();
$request = Request::getInstance();
switch ($request['action']) {
case 'add':
if (!isset($request['user_id']) || $request['user_id'] == '') {
$messageBoxes[] = MessageBox::error('Kein Nutzer angegeben.');
} else {
$userlist->addToList($request['user_id']);
$messageBoxes[] = MessageBox::success('Erfolgreich gespeichert.');
}
break;
case 'delete':
if (!isset($request['confirm'])) {
$trueResponse = $_POST;
$trueResponse['confirm'] = true;
$falseResponse = $_POST;
$falseResponse['confirm'] = false;
print(createQuestion2(
'Möchten Sie den User "' . User::findFull($request['user_id'])->username . '" wirklich löschen?',
$trueResponse,
$falseResponse,
'?cid=' . $request['cid']
));
}
if ($request['confirm']) {
NotifiedUserList::getNotifiedUserList()->deleteFromList($request['user_id']);
}
header('Location: ' . PluginEngine::getLink('WorkplaceAllocation', [], 'manageNotifiedUsers'));
break;
default:
break;
}
}
/** @var Flexi_Template $template */
$template = $this->templateFactory->open('manageNotifiedUsers');
$template->set_layout($GLOBALS['template_factory']->open('layouts/base'));
$template->set_attribute('userlist', NotifiedUserList::getNotifiedUserList());
$template->set_attribute('messageBoxes', $messageBoxes);
PageLayout::addStylesheet($this->getPluginURL() . '/assets/stylesheets/link_button.css');
print($template->render());
}
/**
* show all schedules of current user
*
* @throws AccessDeniedException
*/
public function my_schedules_action()
{
$currentUser = User::findCurrent();
$request = Request::getInstance();
if (isset($request['username']) && $request['username'] != $currentUser->username) {
throw new AccessDeniedException('Du hast nicht die nötigen Rechte zum Aufruf dieser Seite');
}
Navigation::activateItem('/profile/workplace_schedules');
/** @var Flexi_Template $template */
$template = $this->templateFactory->open('user_schedules');
$template->set_layout($GLOBALS['template_factory']->open('layouts/base'));
$template->set_attribute('schedules', Schedule::getSchedulesByUser(get_userid()));
print($template->render());
}
/**
* route to get pdf export of timetable
*
* @throws AccessDeniedException
*/
public function pdf_action()
{
if (!$this->user_has_admin_perm(Request::get('cid'))) {
throw new AccessDeniedException('Du hast nicht die nötigen Rechte zum Aufruf dieser Seite');
}
if (Request::get('wp_id') != null) {
$workplace = Workplace::getWorkplace(Request::get('wp_id'));
$workplaces = [$workplace];
} else {
$workplaces = Workplace::getWorkplacesByContext(Request::get('cid'));
}
$pdf = new TCPDF();
//document information