This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
teacherview.php
1014 lines (931 loc) · 43.9 KB
/
teacherview.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 // $Id: teacherview.php,v 1.2.2.12 2011/03/15 21:46:18 diml Exp $
/**
* @package mod-scheduler
* @category mod
* @author Gustav Delius, Valery Fremaux > 1.8
*
* This page prints the screen view for the teachers. It realizes all "view" related use cases.
*
* @usecase addslot
* @usecase updateslot
* @usecase addsession
* @usecase addaperiodsession
* @usecase schedule
* @usecase schedulegroup
* @usecase viewstatistics
* @usecase viewstudent
* @usecase downloads
*/
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from view.php in mod/scheduler
}
/**
*
*/
function get_slot_data(&$form){
if (!$form->hideuntil = optional_param('hideuntil', '', PARAM_INT)){
$form->displayyear = required_param('displayyear', PARAM_INT);
$form->displaymonth = required_param('displaymonth', PARAM_INT);
$form->displayday = required_param('displayday', PARAM_INT);
$form->hideuntil = make_timestamp($form->displayyear, $form->displaymonth, $form->displayday);
}
if (!$form->starttime = optional_param('starttime', '', PARAM_INT)){
$form->year = required_param('year', PARAM_INT);
$form->month = required_param('month', PARAM_INT);
$form->day = required_param('day', PARAM_INT);
$form->hour = required_param('hour', PARAM_INT);
$form->minute = required_param('minute', PARAM_INT);
$form->starttime = make_timestamp($form->year, $form->month, $form->day, $form->hour, $form->minute);
}
$form->exclusivity = required_param('exclusivity', PARAM_INT);
$form->reuse = required_param('reuse', PARAM_INT);
$form->duration = required_param('duration', PARAM_INT);
$form->notes = required_param('notes', PARAM_TEXT);
$form->teacherid = required_param('teacherid', PARAM_INT);
$form->appointmentlocation = required_param('appointmentlocation', PARAM_CLEAN);
}
/**
*
*/
function get_session_data(&$form){
if (!$form->rangestart = optional_param('rangestart', '', PARAM_INT)){
$year = required_param('startyear', PARAM_INT);
$month = required_param('startmonth', PARAM_INT);
$day = required_param('startday', PARAM_INT);
$form->rangestart = make_timestamp($year, $month, $day);
$form->starthour = required_param('starthour', PARAM_INT);
$form->startminute = required_param('startminute', PARAM_INT);
$form->timestart = make_timestamp($year, $month, $day, $form->starthour, $form->startminute);
}
if (!$form->rangeend = optional_param('rangeend', '', PARAM_INT)){
$year = required_param('endyear', PARAM_INT);
$month = required_param('endmonth', PARAM_INT);
$day = required_param('endday', PARAM_INT);
$form->rangeend = make_timestamp($year, $month, $day);
$form->endhour = required_param('endhour', PARAM_INT);
$form->endminute = required_param('endminute', PARAM_INT);
$form->timeend = make_timestamp($year, $month, $day, $form->endhour, $form->endminute);
}
$form->monday = optional_param('monday', 0, PARAM_INT);
$form->tuesday = optional_param('tuesday', 0, PARAM_INT);
$form->wednesday = optional_param('wednesday', 0, PARAM_INT);
$form->thursday = optional_param('thursday', 0, PARAM_INT);
$form->friday = optional_param('friday', 0, PARAM_INT);
$form->saturday = optional_param('saturday', 0, PARAM_INT);
$form->sunday = optional_param('sunday', 0, PARAM_INT);
$form->forcewhenoverlap = required_param('forcewhenoverlap', PARAM_INT);
$form->exclusivity = required_param('exclusivity', PARAM_INT);
$form->reuse = required_param('reuse', PARAM_INT);
$form->divide = optional_param('divide', 0, PARAM_INT);
$form->duration = optional_param('duration', 15, PARAM_INT);
$form->teacherid = required_param('teacherid', PARAM_INT);
$form->appointmentlocation = optional_param('appointmentlocation', '', PARAM_CLEAN);
$form->emailfrom = required_param('emailfrom', PARAM_CLEAN);
$form->displayfrom = required_param('displayfrom', PARAM_CLEAN);
}
/**
*
*/
function get_aperiod_session_data(&$form){
$listdatestxt = required_param('listdates', PARAM_TEXT);//string var.
$form->listdates = explode(",",$listdatestxt); //array of string dates
if (!$form->rangestart = optional_param('rangestart', '', PARAM_INT)){
$year = date("Y", strtotime($form->listdates[0]));
$month = date("m", strtotime($form->listdates[0]));
$day = date("d", strtotime($form->listdates[0]));
$form->rangestart = make_timestamp($year, $month, $day);//first date in the list
$form->starthour = required_param('starthour', PARAM_INT);
$form->startminute = required_param('startminute', PARAM_INT);
$form->timestart = make_timestamp($year, $month, $day, $form->starthour, $form->startminute);//first date/time in the list
}
if (!$form->rangeend = optional_param('rangeend', '', PARAM_INT)){
$year = date("Y", strtotime($form->listdates[(count($form->listdates)-1)]));
$month = date("m", strtotime($form->listdates[(count($form->listdates)-1)]));
$day = date("d", strtotime($form->listdates[(count($form->listdates)-1)]));
$form->rangeend = make_timestamp($year, $month, $day);//last date in the list
$form->endhour = required_param('endhour', PARAM_INT);
$form->endminute = required_param('endminute', PARAM_INT);
$form->timeend = make_timestamp($year, $month, $day, $form->endhour, $form->endminute);//last date/time in the list
}
$form->forcewhenoverlap = required_param('forcewhenoverlap', PARAM_INT);
$form->exclusivity = required_param('exclusivity', PARAM_INT);
$form->reuse = required_param('reuse', PARAM_INT);
$form->divide = optional_param('divide', 0, PARAM_INT);
$form->duration = optional_param('duration', 15, PARAM_INT);
$form->teacherid = required_param('teacherid', PARAM_INT);
$form->appointmentlocation = optional_param('appointmentlocation', '', PARAM_CLEAN);
$form->emailfrom = required_param('emailfrom', PARAM_CLEAN);
$form->displayfrom = required_param('displayfrom', PARAM_CLEAN);
}
/**
*
*/
if (!defined('MOODLE_INTERNAL')){
error("This file cannot be loaded directly");
}
if ($action){
include_once('teacherview.controller.php');
}
/************************************ View : New single slot form ****************************************/
if ($action == 'addslot'){
print_heading(get_string('addsingleslot', 'scheduler'));
if (empty($subaction)){
$form->what = 'doaddupdateslot';
// blank appointment data
if (empty($form->appointments)) $form->appointments = array();
$form->starttime = time();
// $form->duration = 15;
$form->duration = $scheduler->defaultslotduration;//set default
$form->reuse = 1;
$form->exclusivity = 1;
$form->hideuntil = $scheduler->timemodified; // supposed being in the past so slot is visible
$form->notes = '';
$form->teacherid = $USER->id;
$form->appointmentlocation = scheduler_get_last_location($scheduler);
} elseif($subaction == 'cancel') {
get_slot_data($form);
$form->what = 'doaddupdateslot';
$form->appointments = unserialize(stripslashes(required_param('appointmentssaved', PARAM_RAW)));
} else {
$retcode = include_once "teacherview.subcontroller.php";
if ($retcode == -1) return -1;
}
/// print errors
if (!empty($errors)){
$errorstr = '';
foreach($errors as $anError){
$errorstr .= $anError->message;
}
print_simple_box($errorstr, 'center', '70%', '', 5, 'scheduler_errorbox errorbox');
}
/// print form
print_simple_box_start('center', '', '');
include('oneslotform.html');
print_simple_box_end();
echo '<br />';
// return code for include
return -1;
}
/************************************ View : Update single slot form ****************************************/
if ($action == 'updateslot') {
$slotid = required_param('slotid', PARAM_INT);
print_heading(get_string('updatesingleslot', 'scheduler'));
if(empty($subaction)){
if(!empty($errors)){ // if some errors, get data from client side
get_slot_data($form);
$form->appointments = unserialize(stripslashes(required_param('appointments', PARAM_RAW)));
} else {
/// get data from the last inserted
$slot = get_record('scheduler_slots', 'id', $slotid);
$form = &$slot;
// get all appointments for this slot
$form->appointments = array();
$appointments = get_records('scheduler_appointment', 'slotid', $slotid);
// convert appointement keys to studentid
if ($appointments){
foreach($appointments as $appointment){
$form->appointments[$appointment->studentid] = $appointment;
}
}
}
} elseif($subaction == 'cancel') {
get_slot_data($form);
$form->appointments = unserialize(stripslashes(required_param('appointmentssaved', PARAM_RAW)));
$form->studentid = required_param('studentid', PARAM_INT);
$form->slotid = required_param('slotid', PARAM_INT);
$form->what = 'doaddupdateslot';
} elseif($subaction != '') {
$retcode = include_once "teacherview.subcontroller.php";
if ($retcode == -1) return -1;
}
// print errors and notices
if (!empty($errors)){
$errorstr = '';
foreach($errors as $anError){
$errorstr .= $anError->message;
}
print_simple_box($errorstr, 'center', '70%', '', 5, 'scheduler_errorbox errorbox');
}
/// print form
$form->what = 'doaddupdateslot';
print_simple_box_start('center', '', '');
include('oneslotform.html');
print_simple_box_end();
echo '<br />';
// return code for include
return -1;
}
/************************************ Add session multiple slots form ****************************************/
if ($action == 'addsession') {
// if there is some error from controller, display it
if (!empty($errors)){
$errorstr = '';
foreach($errors as $anError){
$errorstr .= $anError->message;
}
print_simple_box($errorstr, 'center', '70%', '', 5, 'scheduler_errorbox errorbox');
}
if (!empty($errors)){
get_session_data($data);
$form = &$data;
} else {
$form->rangestart = time();
$form->rangeend = time();
$form->timestart = time();
// $form->timeend = time() + HOURSECS;
//time end propouse time interval with length 5 minutes more than default duration - guarantee for one slot
$form->timeend = time() + ($scheduler->defaultslotduration+5)*60;
$form->hideuntil = $scheduler->timemodified;
$form->duration = $scheduler->defaultslotduration;
$form->forcewhenoverlap = 0;
$form->teacherid = $USER->id;
$form->exclusivity = 1;
// $form->duration = $scheduler->defaultslotduration;
$form->reuse = 1;
$form->monday = 1;
$form->tuesday = 1;
$form->wednesday = 1;
$form->thursday = 1;
$form->friday = 1;
$form->saturday = 0;
$form->sunday = 0;
}
print_heading(get_string('addsession', 'scheduler'));
print_simple_box_start('center', '', '');
include_once('addslotsform.html');
print_simple_box_end();
echo '<br />';
// return code for include
return -1;
}
/******************************** Add aperiodic session multiple slots form ******************************/
if ($action == 'addaperiodsession') {
// if there is some error from controller, display it
if (!empty($errors)){
$errorstr = '';
foreach($errors as $anError){
$errorstr .= $anError->message;
}
print_simple_box($errorstr, 'center', '70%', '', 5, 'scheduler_errorbox errorbox');
}
if (!empty($errors)){
get_aperiod_session_data($data);
$form = &$data;
} else {
$form->rangestart = time();
$form->rangeend = time();
$form->timestart = time();
//time end propouse time interval with length 5 minutes more than default duration - guarantee for one slot
$form->timeend = time() + ($scheduler->defaultslotduration+5)*60;
$form->hideuntil = $scheduler->timemodified;
$form->duration = $scheduler->defaultslotduration;
$form->forcewhenoverlap = 0;
$form->teacherid = $USER->id;
$form->exclusivity = 1;
$form->duration = $scheduler->defaultslotduration;
$form->reuse = 1;
}
print_heading(get_string('addaperiodsession', 'scheduler'));
print_simple_box_start('center', '', '');
include_once('addaperiodslotsform.html');
print_simple_box_end();
echo '<br />';
// return code for include
return -1;
}
/************************************ Schedule a student form ***********************************************/
if ($action == 'schedule') {
if ($subaction == 'dochooseslot'){
/// set an advice message
unset($erroritem);
$erroritem->message = get_string('dontforgetsaveadvice', 'scheduler');
$erroritem->on = '';
$errors[] = $erroritem;
$slotid = required_param('slotid', PARAM_INT);
$studentid = required_param('studentid', PARAM_INT);
if ($slot = get_record('scheduler_slots', 'id', $slotid)){
$form = &$slot;
$form->studentid = $studentid;
$form->what = 'doaddupdateslot';
$form->slotid = $slotid;
$form->availableslots = scheduler_get_available_slots($studentid, $scheduler->id);
$appointment->studentid = $studentid;
$appointment->attended = optional_param('attended', 0, PARAM_INT);
$appointment->grade = optional_param('grade', 0, PARAM_INT);
$appointment->appointmentnote = optional_param('appointmentnote', '', PARAM_TEXT);
$appointment->timecreated = time();
$appointment->timemodified = time();
$appointments = get_records('scheduler_appointment', 'slotid', $slotid);
$appointments[$appointment->studentid] = $appointment;
$form->appointments = $appointments;
} else {
$form->studentid = $studentid;
$form->what = 'doaddupdateslot';
$form->slotid = 0;
$form->starttime = time();
$form->duration = $scheduler->defaultslotduration;//was 15
$form->reuse = 1;
$form->exclusivity = 1;
$form->hideuntil = $scheduler->timemodified; // supposed being in the past so slot is visible
$form->notes = '';
$form->teacherid = $USER->id;
$form->appointmentlocation = scheduler_get_last_location($scheduler);
$form->availableslots = scheduler_get_available_slots($studentid, $scheduler->id);
$form->appointments = unserialize(stripslashes(required_param('appointments', PARAM_RAW)));
}
} elseif($subaction == 'cancel') {
get_slot_data($form);
$form->appointments = unserialize(stripslashes(required_param('appointments', PARAM_RAW)));
$form->studentid = required_param('studentid', PARAM_INT);
$form->slotid = required_param('slotid', PARAM_INT);
$form->availableslots = scheduler_get_available_slots($form->studentid, $scheduler->id);
$form->what = 'doaddupdateslot';
} elseif(empty($subaction)) {
if (!empty($errors)){
get_slot_data($form);
$form->availableslots = scheduler_get_available_slots($form->studentid, $scheduler->id);
$form->studentid = required_param('studentid', PARAM_INT);
$form->seen = optional_param('seen', 0, PARAM_INT);
$form->slotid = optional_param('slotid', -1, PARAM_INT);
} else {
$form->studentid = required_param('studentid', PARAM_INT);
$form->seen = optional_param('seen', 0, PARAM_INT);
/// getting available slots
$form->availableslots = scheduler_get_available_slots($form->studentid, $scheduler->id);
$form->what = 'doaddupdateslot' ;
$form->starttime = time();
$form->duration = $scheduler->defaultslotduration;
$form->reuse = 1;
$form->exclusivity = 1;
$form->hideuntil = $scheduler->timemodified; // supposed being in the past so slot is visible
$form->notes = '';
$form->teacherid = $USER->id;
$form->appointmentlocation = scheduler_get_last_location($scheduler);
$form->slotid = 0;
$appointment->slotid = -1;
$appointment->studentid = $form->studentid;
$appointment->appointmentnote = '';
$appointment->attended = $form->seen;
$appointment->grade = '';
$appointment->timecreated = time();
$appointment->timemodified = time();
$form->appointments[$form->studentid] = $appointment;
}
} elseif($subaction != '') {
$retcode = include_once "teacherview.subcontroller.php";
if ($retcode == -1) return -1;
}
// display error or advices
if (!empty($errors)){
$errorstr = '';
foreach($errors as $anError){
$errorstr .= $anError->message;
}
print_simple_box($errorstr, 'center', '70%', '', 5, 'scheduler_errorbox errorbox');
}
// diplay form
$form->student = get_record('user', 'id', $form->studentid);
$studentname = fullname($form->student, true);
print_heading(get_string('scheduleappointment', 'scheduler', $studentname));
print_simple_box_start('center', '', '');
include('oneslotform.html');
print_simple_box_end();
echo '<br />';
// return code for include
return -1;
}
/************************************ Schedule a whole group in form ***********************************************/
if ($action == 'schedulegroup') {
if($subaction == 'dochooseslot'){
/// set an advice message
unset($erroritem);
$erroritem->message = get_string('dontforgetsaveadvice', 'scheduler');
$erroritem->on = '';
$errors[] = $erroritem;
$slotid = required_param('slotid', PARAM_INT);
if ($slot = get_record('scheduler_slots', 'id', $slotid)){
$form = &$slot;
$form->groupid = required_param('groupid', PARAM_INT);
$form->what = 'doaddupdateslot';
$form->slotid = $slotid;
$form->availableslots = scheduler_get_unappointed_slots($scheduler->id);
$appointments = array();
$members = groups_get_members($form->groupid);
// add all group members to the slot, and match exclusivity
foreach($members as $member){
unset($appointment);
// hack for 1.8 / 1.9 compatibility of groups_get_members() call
if (is_numeric($member)){
$appointment->studentid = $member;
} else {
$appointment->studentid = $member->id;
}
$appointment->attended = optional_param('attended', 0, PARAM_INT);
$appointment->grade = optional_param('grade', 0, PARAM_INT);
$appointment->appointmentnote = optional_param('appointmentnote', '', PARAM_TEXT);
$appointment->timecreated = time();
$appointment->timemodified = time();
$appointments[$appointment->studentid] = $appointment;
}
$form->appointments = $appointments;
} else {
$form->groupid = $groupid;
$form->what = 'doaddupdateslot';
$form->slotid = 0;
$form->starttime = time();
$form->duration = $scheduler->defaultslotduration;//was 15
$form->reuse = 1;
$form->exclusivity = 1;
$form->hideuntil = $scheduler->timemodified; // supposed being in the past so slot is visible
$form->notes = '';
$form->teacherid = $USER->id;
$form->appointmentlocation = scheduler_get_last_location($scheduler);
$form->availableslots = scheduler_get_unappointed_slots($scheduler->id);
$form->appointments = unserialize(stripslashes(required_param('appointments', PARAM_RAW)));
}
} elseif($subaction == 'cancel') {
get_slot_data($form);
$form->appointments = unserialize(stripslashes(required_param('appointments', PARAM_RAW)));
$form->studentid = required_param('studentid', PARAM_INT);
$form->slotid = required_param('slotid', PARAM_INT);
$form->availableslots = scheduler_get_unappointed_slots($scheduler->id);
$form->what = 'doaddupdateslot';
} elseif(empty($subaction)) {
if (!empty($errors)){
get_slot_data($form);
$form->availableslots = scheduler_get_unappointed_slots($scheduler->id);
$form->groupid = required_param('groupid', PARAM_INT);
$form->seen = optional_param('seen', 0, PARAM_INT);
$form->slotid = optional_param('slotid', -1, PARAM_INT);
} else {
$form->groupid = required_param('groupid', PARAM_INT);
$form->seen = optional_param('seen', 0, PARAM_INT);
/// getting available slots
$form->availableslots = scheduler_get_unappointed_slots($scheduler->id);
$form->what = 'doaddupdateslot' ;
$form->starttime = time();
$form->duration = $scheduler->defaultslotduration;
$form->reuse = 1;
$form->hideuntil = $scheduler->timemodified; // supposed being in the past so slot is visible
$form->notes = '';
$form->teacherid = $USER->id;
$form->appointmentlocation = scheduler_get_last_location($scheduler);
$form->slotid = 0;
$members = groups_get_members($form->groupid);
$form->exclusivity = count($members);
foreach($members as $member){
unset($appointment);
$appointment->slotid = -1;
// hack for 1.8 / 1.9 compatibility of groups_get_members() call
if (is_numeric($member)){
$appointment->studentid = $member;
} else {
$appointment->studentid = $member->id;
}
$appointment->appointmentnote = '';
$appointment->attended = $form->seen;
$appointment->grade = '';
$appointment->timecreated = time();
$appointment->timemodified = time();
$form->appointments[$appointment->studentid] = $appointment;
}
}
} elseif($subaction != '') {
$retcode = include_once "teacherview.subcontroller.php";
if ($retcode == -1) return -1;
}
// display error or advices
if (!empty($errors)){
$errorstr = '';
foreach($errors as $anError){
$errorstr .= $anError->message;
}
print_simple_box($errorstr, 'center', '70%', '', 5, 'scheduler_errorbox errorbox');
}
// diplay form
$form->group = get_record('groups', 'id', $form->groupid);
print_heading(get_string('scheduleappointment', 'scheduler', $form->group->name));
print_simple_box_start('center', '', '');
include('oneslotform.html');
print_simple_box_end();
echo '<br />';
// return code for include
return -1;
}
//****************** Standard view ***********************************************//
/// print top tabs
$tabrows = array();
$row = array();
switch ($action){
case 'viewstatistics':{
$currenttab = get_string('statistics', 'scheduler');
break;
}
case 'datelist':{
$currenttab = get_string('datelist', 'scheduler');
break;
}
case 'viewstudent':{
$currenttab = get_string('studentdetails', 'scheduler');
$row[] = new tabobject($currenttab, '', $currenttab);
break;
}
case 'downloads':{
$currenttab = get_string('downloads', 'scheduler');
break;
}
default: {
$currenttab = get_string($page, 'scheduler');
}
}
$tabname = get_string('myappointments', 'scheduler');
$row[] = new tabobject($tabname, "view.php?id={$cm->id}&page=myappointments", $tabname);
if (count_records('scheduler_slots', 'schedulerid', $scheduler->id) > count_records('scheduler_slots', 'schedulerid', $scheduler->id, 'teacherid', $USER->id)) {
$tabname = get_string('allappointments', 'scheduler');
$row[] = new tabobject($tabname, "view.php?id={$cm->id}&page=allappointments", $tabname);
} else {
// we are alone in this scheduler
if ($page == 'allappointements') {
$currenttab = get_string('myappointments', 'scheduler');
}
}
$tabname = get_string('datelist', 'scheduler');
$row[] = new tabobject($tabname, "view.php?id={$cm->id}&what=datelist", $tabname);
$tabname = get_string('statistics', 'scheduler');
$row[] = new tabobject($tabname, "view.php?what=viewstatistics&id={$cm->id}&course={$scheduler->course}&page=overall", $tabname);
$tabname = get_string('downloads', 'scheduler');
$row[] = new tabobject($tabname, "view.php?what=downloads&id={$cm->id}&course={$scheduler->course}", $tabname);
$tabrows[] = $row;
print_tabs($tabrows, $currenttab);
/// print heading
print_heading($scheduler->name);
/// print page
if ($scheduler->description) {
print_simple_box(format_text($scheduler->description), 'center');
}
if ($page == 'allappointments'){
$select = "schedulerid = '". $scheduler->id ."'";
} else {
$select = "schedulerid = '". $scheduler->id ."' AND teacherid = '{$USER->id}'";
$page = 'myappointments';
}
$sqlcount = count_records_select('scheduler_slots',$select);
if (($offset == '') && ($sqlcount > 25)){
$offsetcount = count_records_select('scheduler_slots', $select." AND starttime < '".strtotime('now')."'");
$offset = floor($offsetcount/25);
}
/*
$sql = "
SELECT
s.*,
COUNT(IF(a.studentid IS NOT NULL, 1, NULL)) as isappointed,
COUNT(IF(a.attended IS NOT NULL AND a.attended > 0, 1, NULL)) as isattended
FROM
{$CFG->prefix}scheduler_slots AS s
LEFT JOIN
{$CFG->prefix}scheduler_appointment AS a
ON
s.id = a.slotid
WHERE
{$select}
GROUP BY
s.id
ORDER BY
starttime ASC
";
$slots = get_records_sql($sql, $offset * 25, 25);
*/
// More compatible way to do it :
$slots = get_records_select('scheduler_slots', $select, 'starttime', '*', $offset * 25, 25);
if ($slots){
foreach(array_keys($slots) as $slotid){
$slots[$slotid]->isappointed = count_records('scheduler_appointment', 'slotid', $slotid);
$slots[$slotid]->isattended = record_exists('scheduler_appointment', 'slotid', $slotid, 'attended', 1);
}
}
$straddsession = get_string('addsession', 'scheduler');
$straddaperiodsession = get_string('addaperiodsession', 'scheduler');
$straddsingleslot = get_string('addsingleslot', 'scheduler');
$strdownloadexcel = get_string('downloadexcel', 'scheduler');
/// some slots already exist
if ($slots){
// print instructions and button for creating slots
print_simple_box_start('center', '', '');
print_string('addslot', 'scheduler');
// print add session button
$strdeleteallslots = get_string('deleteallslots', 'scheduler');
$strdeleteallunusedslots = get_string('deleteallunusedslots', 'scheduler');
$strdeleteunusedslots = get_string('deleteunusedslots', 'scheduler');
$strdeletemyslots = get_string('deletemyslots', 'scheduler');
$strstudents = get_string('students', 'scheduler');
$displaydeletebuttons = 1;
echo '<center>';
include_once "commands.html";
echo '</center>';
print_simple_box_end();
// prepare slots table
if ($page == 'myappointments'){
$table->head = array ('', $strdate, $strstart, $strend, $strstudents, $straction);
$table->align = array ('CENTER', 'LEFT', 'LEFT', 'CENTER', 'CENTER', 'CENTER', 'LEFT', 'CENTER');
$table->width = '80%';
} else {
$table->head = array ('', $strdate, $strstart, $strend, $strstudents, format_string($scheduler->staffrolename), $straction);
$table->align = array ('CENTER', 'LEFT', 'LEFT', 'CENTER', 'CENTER', 'CENTER', 'LEFT', 'LEFT', 'CENTER');
$table->width = '80%';
}
$offsetdatemem = '';
foreach($slots as $slot) {
if (!$slot->isappointed && $slot->starttime + (60 * $slot->duration) < time()) {
// This slot is in the past and has not been chosen by any student, so delete
delete_records('scheduler_slots', 'id', $slot->id);
continue;
}
/// Parameter $local in scheduler_userdate and scheduler_usertime added by power-web.at
/// When local Time or Date is needed the $local Param must be set to 1
$offsetdate = scheduler_userdate($slot->starttime,1);
$offsettime = scheduler_usertime($slot->starttime,1);
$endtime = scheduler_usertime($slot->starttime + ($slot->duration * 60),1);
/// make a slot select box
if ($USER->id == $slot->teacherid || has_capability('mod/scheduler:manageallappointments', $context)){
$selectcheck = "<input type=\"checkbox\" id=\"sel_{$slot->id}\" name=\"sel_{$slot->id}\" onclick=\"document.forms['deleteslotsform'].items.value = toggleListState(document.forms['deleteslotsform'].items.value, 'sel_{$slot->id}', '{$slot->id}');\" />";
} else {
$selectcheck = '';
}
// slot is appointed
$studentArray = array();
if ($slot->isappointed) {
$appointedstudents = get_records('scheduler_appointment', 'slotid', $slot->id);
$studentArray[] = "<form name=\"appointementseen_{$slot->id}\" method=\"post\" action=\"view.php\">";
$studentArray[] = "<input type=\"hidden\" name=\"id\" value=\"".$cm->id."\" />";
$studentArray[] = "<input type=\"hidden\" name=\"slotid\" value=\"".$slot->id."\" />";
$studentArray[] = "<input type=\"hidden\" name=\"what\" value=\"saveseen\" />";
$studentArray[] = "<input type=\"hidden\" name=\"page\" value=\"".$page."\" />";
foreach($appointedstudents as $appstudent){
$student = get_record('user', 'id', $appstudent->studentid);
$picture = print_user_picture($appstudent->studentid, $course->id, $student->picture, 0, true, true);
$name = "<a href=\"view.php?what=viewstudent&id={$cm->id}&studentid={$student->id}&course={$scheduler->course}&order=DESC\">".fullname($student).'</a>';
/// formatting grade
$grade = scheduler_format_grade($scheduler, $appstudent->grade, true);
if ($USER->id == $slot->teacherid || has_capability('mod/scheduler:manageallappointments', $context)){
$checked = ($appstudent->attended) ? 'checked="checked"' : '' ;
$checkbox = "<input type=\"checkbox\" name=\"seen[]\" value=\"{$appstudent->id}\" {$checked} />";
} else {
// same thing but no link
if ($appstudent->attended == 1) {
$checkbox .= '<img src="pix/ticked.gif" border="0">';
} else {
$checkbox .= '<img src="pix/unticked.gif" border="0">';
}
}
$studentArray[] = "$checkbox $picture $name $grade<br/>";
}
$studentArray[] = "<a href=\"javascript:document.forms['appointementseen_{$slot->id}'].submit();\">".get_string('saveseen','scheduler').'</a>';
$studentArray[] = "</form>";
} else {
// slot is free
$picture = '';
$name = '';
$checkbox = '';
}
$actions = '<span style="font-size: x-small;">';
if ($USER->id == $slot->teacherid || has_capability('mod/scheduler:manageallappointments', $context)){
$strdelete = get_string('delete');
$stredit = get_string('move','scheduler');
$strattended = get_string('attended','scheduler');
$strnonexclusive = get_string('isnonexclusive', 'scheduler');
$strallowgroup = get_string('allowgroup', 'scheduler');
$strforbidgroup = get_string('forbidgroup', 'scheduler');
$strrevoke = get_string('revoke', 'scheduler');
$strreused = get_string('setreused', 'scheduler');
$strunreused = get_string('setunreused', 'scheduler');
$actions .= "<a href=\"view.php?what=deleteslot&id={$cm->id}&slotid={$slot->id}&page={$page}\" title=\"{$strdelete}\"><img src=\"{$CFG->pixpath}/t/delete.gif\" alt=\"{$strdelete}\" /></a>";
$actions .= " <a href=\"view.php?what=updateslot&id={$cm->id}&slotid={$slot->id}&page={$page}\" title=\"{$stredit}\"><img src=\"{$CFG->pixpath}/t/edit.gif\" alt=\"{$stredit}\" /></a>";
if ($slot->isattended){
$actions .= " <img src=\"{$CFG->pixpath}/c/group.gif\" title=\"{$strattended}\" />";
} else {
if ($slot->isappointed > 1){
$actions .= " <img src=\"{$CFG->pixpath}/c/group.gif\" title=\"{$strnonexclusive}\" />";
} else {
if ($slot->exclusivity == 1){
$actions .= " <a href=\"view.php?what=allowgroup&id={$cm->id}&slotid={$slot->id}&page={$page}\" title=\"{$strallowgroup}\"><img src=\"{$CFG->pixpath}/t/groupn.gif\" alt=\"{$strallowgroup}\" /></a>";
} else {
$actions .= " <a href=\"view.php?what=forbidgroup&id={$cm->id}&slotid={$slot->id}&page={$page}\" title=\"{$strforbidgroup}\"><img src=\"{$CFG->pixpath}/t/groupv.gif\" alt=\"{$strforbidgroup}\" /></a>";
}
}
}
if ($slot->isappointed){
$actions .= " <a href=\"view.php?what=revokeall&id={$cm->id}&slotid={$slot->id}&page={$page}\" title=\"{$strrevoke}\"><img src=\"{$CFG->pixpath}/s/no.gif\" alt=\"{$strrevoke}\" /></a>";
}
} else {
// just signal group status
if ($slot->isattended){
$actions .= " <img src=\"{$CFG->pixpath}/c/group.gif\" title=\"{$strattended}\" />";
} else {
if ($slot->isappointed > 1){
$actions .= " <img src=\"{$CFG->pixpath}/c/group.gif\" title=\"{$strnonexclusive}\" />";
} else {
if ($slot->exclusivity == 1){
$actions .= " <img src=\"{$CFG->pixpath}/t/groupn.gif\" title=\"{$strallowgroup}\" />";
} else {
$actions .= " <img src=\"{$CFG->pixpath}/t/groupv.gif\" title=\"{$strforbidgroup}\" />";
}
}
}
}
if ($slot->exclusivity > 1){
$actions .= ' ('.$slot->exclusivity.')';
}
if ($slot->reuse){
$actions .= " <a href=\"view.php?what=unreuse&id={$cm->id}&slotid={$slot->id}&page={$page}\" title=\"{$strunreused}\" ><img src=\"pix/volatile_shadow.gif\" alt=\"{$strunreused}\" border=\"0\" /></a>";
} else {
$actions .= " <a href=\"view.php?what=reuse&id={$cm->id}&slotid={$slot->id}&page={$page}\" title=\"{$strreused}\" ><img src=\"pix/volatile.gif\" alt=\"{$strreused}\" border=\"0\" /></a>";
}
$actions .= '</span>';
if($page == 'myappointments'){
$table->data[] = array ($selectcheck, ($offsetdate == $offsetdatemem) ? '' : $offsetdate, $offsettime, $endtime, implode("\n",$studentArray), $actions);
} else {
$teacherlink = "<a href=\"$CFG->wwwroot/user/view.php?id={$slot->teacherid}\">".fullname(get_record('user', 'id', $slot->teacherid))."</a>";
$table->data[] = array ($selectcheck, ($offsetdate == $offsetdatemem) ? '' : $offsetdate, $offsettime, $endtime, implode("\n",$studentArray), $teacherlink, $actions);
}
$offsetdatemem = $offsetdate;
}
// print slots table
print_heading(get_string('slots' ,'scheduler'));
print_table($table);
?>
<center>
<table width="80%">
<tr>
<td align="left">
<script src="<?php echo "{$CFG->wwwroot}/mod/scheduler/scripts/listlib.js" ?>"></script>
<form name="deleteslotsform" style="display : inline">
<input type="hidden" name="id" value="<?php p($cm->id) ?>" />
<input type="hidden" name="page" value="<?php echo $page ?>" />
<input type="hidden" name="what" value="deleteslots" />
<input type="hidden" name="items" value="" />
</form>
<a href="javascript:document.forms['deleteslotsform'].submit()"><?php print_string('deleteselection','scheduler') ?></a>
<br />
</td>
</tr>
</table>
<?php
if ($sqlcount > 25){
echo "Page : ";
$pagescount = ceil($sqlcount/25);
for ($n = 0; $n < $pagescount; $n ++){
if ($n == $offset){
echo ($n+1).' ';
} else {
echo "<a href=view.php?id={$cm->id}&page={$page}&offset={$n}>".($n+1)."</a> ";
}
}
}
echo '</center>';
// Instruction for teacher to click Seen box after appointment
echo '<br /><center>' . get_string('markseen', 'scheduler') . '</center>';
} else if ($action != 'addsession') {
/// There are no slots, should the teacher be asked to make some
print_simple_box_start('center', '', '');
print_string('welcomenewteacher', 'scheduler');
echo '<center>';
$displaydeletebuttons = 0;
include_once "commands.html";
echo '</center>';
print_simple_box_end();
}
/// print table of outstanding appointer (students)
?>
<center>
<table width="90%">
<tr valign="top">
<td width="50%">
<?php
print_heading(get_string('schedulestudents', 'scheduler'));
if ($cm->groupmembersonly){
$groups = groups_get_all_groups($COURSE->id, 0, $cm->groupingid);
$usergroups = array_keys($groups);
} else {
$groups = get_groups($COURSE->id);
$usergroups = '';
}
$students = get_users_by_capability ($context, 'mod/scheduler:appoint', 'u.id,lastname,firstname,email,picture', 'lastname', '', '', $usergroups);
if (!$students) {
$nostudentstr = get_string('noexistingstudents');
if ($COURSE->id == SITEID){
$nostudentstr .= '<br/>'.get_string('howtoaddstudents','scheduler');
}
notify($nostudentstr);
} else {
$mtable->head = array ('', $strname, $stremail, $strseen, $straction);
$mtable->align = array ('CENTER','LEFT','LEFT','CENTER','CENTER');
$mtable->width = array('', '', '', '', '');
$mtable->data = array();
// In $mailto the mailing list for reminder emails is built up
$mailto = '<a href="mailto:';
$date = usergetdate(time());
foreach ($students as $student) {
if (!scheduler_has_slot($student->id, $scheduler, true, $scheduler->schedulermode == 'onetime')) {
$picture = print_user_picture($student->id, $course->id, $student->picture, false, true);
$name = "<a href=\"../../user/view.php?id={$student->id}&course={$scheduler->course}\">";
$name .= fullname($student);
$name .= '</a>';
$email = obfuscate_mailto($student->email);
if (scheduler_has_slot($student->id, $scheduler, true, false) == 0){
// student has never scheduled
$mailto .= $student->email.', ';
}
$checkbox = "<a href=\"view.php?what=schedule&id={$cm->id}&studentid={$student->id}&page={$page}&seen=1\">";
$checkbox .= '<img src="pix/unticked.gif" border="0" />';
$checkbox .= '</a>';
$actions = '<span style="font-size: x-small;">';
$actions .= "<a href=\"view.php?what=schedule&id={$cm->id}&studentid={$student->id}&page={$page}\">";
$actions .= get_string('schedule', 'scheduler');
$actions .= '</a></span>';
$mtable->data[] = array($picture, $name, $email, $checkbox, $actions);
}
}
// dont print if allowed to book multiple appointments
// There are students who still have to make appointments
if (($num = count($mtable->data)) > 0) {
// Print number of students who still have to make an appointment
print_heading(get_string('missingstudents', 'scheduler', $num), 'center', 3);
// Print links to print invitation or reminder emails
$strinvitation = get_string('invitation', 'scheduler');
$strreminder = get_string('reminder', 'scheduler');
$mailto = rtrim($mailto, ', ');
$subject = $strinvitation . ': ' . $scheduler->name;
$body = $strinvitation . ': ' . $scheduler->name . "\n\n";
$body .= get_string('invitationtext', 'scheduler');
$body .= "{$CFG->wwwroot}/mod/scheduler/view.php?id={$cm->id}";
echo '<center>'.get_string('composeemail', 'scheduler').
$mailto.'?subject='.htmlentities(rawurlencode($subject)).
'&body='.htmlentities(rawurlencode($body)).
'"> '.$strinvitation.'</a> ';
$maillist = ' — ';
$subject = $strreminder . ': ' . $scheduler->name;
$body = $strreminder . ': ' . $scheduler->name . "\n\n";
$body .= get_string('remindertext', 'scheduler');
$body .= "{$CFG->wwwroot}/mod/scheduler/view.php?id={$cm->id}";
echo $mailto.'?subject='.htmlentities(rawurlencode($subject)).
'&body='.htmlentities(rawurlencode($body)).
'"> '.$strreminder.'</a></center><br />';
// print table of students who still have to make appointments
print_table($mtable);
} else {
notify(get_string('nostudents', 'scheduler'));
}
}
?>
</td>
<?php
if ($groupmode){
?>
<td width="50%">
<?php
/// print table of outstanding appointer (groups)
print_heading(get_string('schedulegroups', 'scheduler'));
if (empty($groups)){
notify(get_string('nogroups', 'scheduler'));
} else {
$mtable->head = array ('', $strname, $straction);
$mtable->align = array ('CENTER','LEFT','CENTER');
$mtable->width = array('', '', '');
$mtable->data = array();
foreach($groups as $group){
$members = get_group_users($group->id, 'lastname', '', 'u.id, lastname, firstname, email, picture');
if (empty($members)) continue;
if (!scheduler_has_slot(implode(',', array_keys($members)), $scheduler, true, $scheduler->schedulermode == 'onetime')) {
$actions = '<span style="font-size: x-small;">';
$actions .= "<a href=\"view.php?what=schedulegroup&id={$cm->id}&groupid={$group->id}&page={$page}\">";
$actions .= get_string('schedule', 'scheduler');
$actions .= '</a></span>';
$groupmembers = array();
foreach($members as $member){
$groupmembers[] = fullname($member);
}
$groupcrew = '['. implode(", ", $groupmembers) . ']';
$mtable->data[] = array('', $groups[$group->id]->name.' '.$groupcrew, $actions);
}
}
// print table of students who still have to make appointments
if (!empty($mtable->data)){
print_table($mtable);
} else {
notify(get_string('nogroups', 'scheduler'));
}
}
?>