-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteacherview.php
746 lines (667 loc) · 31.2 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
<?php
/**
* Contains various sub-screens that a teacher can see.
*
* @package mod
* @subpackage simplescheduler
* @copyright 2013 Nathan White and others (see README.txt)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* @todo consider "past slots" toggle
* @todo have my appointments highlighted by default
*/
defined('MOODLE_INTERNAL') || die();
function get_slot_data(&$form){
global $USER;
$form = new stdClass();
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->duration = required_param('duration', PARAM_INT);
$form->notes = required_param('notes', PARAM_TEXT);
// if no teacher specified, the current user (who edits the slot) is assumed to be the teacher
$form->teacherid = optional_param('teacherid', $USER->id, PARAM_INT);
$form->appointmentlocation = required_param('appointmentlocation', PARAM_CLEAN);
}
/**
*
*/
function get_session_data(&$form){
global $USER;
$form = new stdClass();
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->divide = optional_param('divide', 0, PARAM_INT);
$form->duration = optional_param('duration', 15, PARAM_INT);
// if no teacher specified, the current user (who edits the slot) is assumed to be the teacher
$form->teacherid = optional_param('teacherid', $USER->id, PARAM_INT);
$form->appointmentlocation = optional_param('appointmentlocation', '', PARAM_CLEAN);
$form->emailfrom = required_param('emailfrom', PARAM_CLEAN);
$form->displayfrom = required_param('displayfrom', PARAM_CLEAN);
}
// load group restrictions
$modinfo = get_fast_modinfo($course);
$usergroups = '';
if ($cm->groupmode > 0) {
$groups = groups_get_all_groups($COURSE->id, 0, $cm->groupingid);
$usergroups = array_keys($groups);
}
if ($action){
include($CFG->dirroot.'/mod/simplescheduler/teacherview.controller.php');
}
/************************************ View : New single slot form ****************************************/
if ($action == 'addslot'){
echo $OUTPUT->heading(get_string('addsingleslot', 'simplescheduler'));
$form = new stdClass();
if (!empty($errors)) {
get_slot_data($form);
$form->what = 'doaddupdateslot';
$form->appointments = $appointments;
} else {
$form->what = 'doaddupdateslot';
// blank appointment data
if (empty($form->appointments)) $form->appointments = array();
$form->starttime = time();
$form->duration = 15;
$form->exclusivity = 1;
$form->hideuntil = $simplescheduler->timemodified; // supposed being in the past so slot is visible
$form->notes = '';
$form->teacherid = $USER->id;
$form->appointmentlocation = simplescheduler_get_last_location($simplescheduler);
}
/// print errors
if (!empty($errors)){
$errorstr = '';
foreach($errors as $anError){
$errorstr .= $anError->message;
}
echo $OUTPUT->box($errorstr, 'errorbox');
}
/// print form
echo $OUTPUT->box_start('boxaligncenter');
include('oneslotform.html');
echo $OUTPUT->box_end();
echo '<br />';
// return code for include
return -1;
}
/************************************ View : Update single slot form ****************************************/
if ($action == 'updateslot') {
$slotid = required_param('slotid', PARAM_INT);
echo $OUTPUT->heading(get_string('updatesingleslot', 'simplescheduler'));
$form = new stdClass();
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 = $DB->get_record('simplescheduler_slots', array('id'=>$slotid));
$form = &$slot;
// get all appointments for this slot
$form->appointments = array();
$appointments = $DB->get_records('simplescheduler_appointment', array('slotid'=>$slotid));
// convert appointement keys to studentid
if ($appointments){
foreach($appointments as $appointment){
$form->appointments[$appointment->studentid] = $appointment;
}
}
}
// print errors and notices
if (!empty($errors)){
$errorstr = '';
foreach($errors as $anError){
$errorstr .= $anError->message;
}
echo $OUTPUT->box($errorstr, 'errorbox');
}
/// print form
$form->what = 'doaddupdateslot';
echo $OUTPUT->box_start('boxaligncenter');
include('oneslotform.html');
echo $OUTPUT->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;
}
echo $OUTPUT->box($errorstr, 'errorbox');
}
$form = new stdClass();
if (!empty($errors)){
get_session_data($data);
$form = &$data;
} else {
$form->rangestart = time();
$form->rangeend = time();
$form->timestart = time();
$form->timeend = time() + HOURSECS;
$form->hideuntil = $simplescheduler->timemodified;
$form->duration = $simplescheduler->defaultslotduration;
$form->forcewhenoverlap = 0;
$form->teacherid = $USER->id;
$form->exclusivity = 1;
$form->duration = $simplescheduler->defaultslotduration;
$form->monday = 1;
$form->tuesday = 1;
$form->wednesday = 1;
$form->thursday = 1;
$form->friday = 1;
$form->saturday = 0;
$form->sunday = 0;
}
echo $OUTPUT->heading(get_string('addsession', 'simplescheduler'));
echo $OUTPUT->box_start('boxaligncenter');
include_once('addslotsform.html');
echo $OUTPUT->box_end();
echo '<br />';
// return code for include
return -1;
}
/************************************ Schedule a student form ***********************************************/
if ($action == 'schedule') {
$form = new stdClass();
if($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 = simplescheduler_get_available_slots($form->studentid, $simplescheduler->id);
$form->what = 'doaddupdateslot';
} elseif(empty($subaction)) {
if (!empty($errors)){
get_slot_data($form);
$form->availableslots = simplescheduler_get_available_slots($form->studentid, $simplescheduler->id);
$form->studentid = required_param('studentid', PARAM_INT);
$form->slotid = optional_param('slotid', -1, PARAM_INT);
} else {
$form->studentid = required_param('studentid', PARAM_INT);
/// getting available slots
$form->availableslots = simplescheduler_get_available_slots($form->studentid, $simplescheduler->id);
$form->what = 'doaddupdateslot' ;
$form->starttime = time();
$form->duration = $simplescheduler->defaultslotduration;
$form->exclusivity = 1;
$form->hideuntil = $simplescheduler->timemodified; // supposed being in the past so slot is visible
$form->notes = '';
$form->teacherid = $USER->id;
$form->appointmentlocation = simplescheduler_get_last_location($simplescheduler);
$form->slotid = 0;
$appointment = new stdClass();
$appointment->slotid = -1;
$appointment->studentid = $form->studentid;
$appointment->appointmentnote = '';
$appointment->timecreated = time();
$appointment->timemodified = time();
$form->appointments[$form->studentid] = $appointment;
}
}
// display error or advices
if (!empty($errors)){
$errorstr = '';
foreach($errors as $anError){
$errorstr .= $anError->message;
}
echo $OUTPUT->box($errorstr, 'errorbox');
}
// diplay form
$form->student = $DB->get_record('user', array('id'=>$form->studentid));
$studentname = fullname($form->student, true);
echo $OUTPUT->heading(get_string('scheduleappointment', 'simplescheduler', $studentname));
echo $OUTPUT->box_start('boxaligncenter');
include($CFG->dirroot.'/mod/simplescheduler/oneslotform.html');
echo $OUTPUT->box_end();
// return code for include
return -1;
}
//****************** Standard view ***********************************************//
/// print top tabs
$tabrows = array();
$row = array();
switch ($action){
case 'datelist':{
$currenttab = get_string('datelist', 'simplescheduler');
break;
}
case 'viewstudent':{
$currenttab = get_string('studentdetails', 'simplescheduler');
$row[] = new tabobject($currenttab, '', $currenttab);
break;
}
case 'downloads':{
$currenttab = get_string('downloads', 'simplescheduler');
break;
}
default: {
$currenttab = get_string($page, 'simplescheduler');
}
}
$tabname = get_string('myappointments', 'simplescheduler');
$row[] = new tabobject($tabname, "view.php?id={$cm->id}&page=myappointments", $tabname);
if ($DB->count_records('simplescheduler_slots', array('simpleschedulerid'=>$simplescheduler->id)) > $DB->count_records('simplescheduler_slots', array('simpleschedulerid'=>$simplescheduler->id, 'teacherid'=>$USER->id))) {
$tabname = get_string('allappointments', 'simplescheduler');
$row[] = new tabobject($tabname, "view.php?id={$cm->id}&page=allappointments", $tabname);
} else {
// we are alone in this simplescheduler
if ($page == 'allappointements') {
$currenttab = get_string('myappointments', 'simplescheduler');
}
}
$tabname = get_string('datelist', 'simplescheduler');
$row[] = new tabobject($tabname, "view.php?id={$cm->id}&what=datelist", $tabname);
$tabname = get_string('downloads', 'simplescheduler');
$row[] = new tabobject($tabname, "view.php?what=downloads&id={$cm->id}&course={$simplescheduler->course}", $tabname);
$tabrows[] = $row;
print_tabs($tabrows, $currenttab);
/// print heading
echo $OUTPUT->heading($simplescheduler->name);
/// print page
if (trim(strip_tags($simplescheduler->intro))) {
echo $OUTPUT->box_start('mod_introbox');
echo format_module_intro('simplescheduler', $simplescheduler, $cm->id);
echo $OUTPUT->box_end();
}
if ($page == 'allappointments'){
$select = "simpleschedulerid = '". $simplescheduler->id ."'";
} else {
$select = "simpleschedulerid = '". $simplescheduler->id ."' AND teacherid = '{$USER->id}'";
$page = 'myappointments';
}
$sqlcount = $DB->count_records_select('simplescheduler_slots',$select);
if (($offset == '') && ($sqlcount > 25)){
$offsetcount = $DB->count_records_select('simplescheduler_slots', $select." AND starttime < '".strtotime('now')."'");
$offset = floor($offsetcount/25);
}
$slots = $DB->get_records_select('simplescheduler_slots', $select, null, 'starttime', '*', $offset * 25, 25);
if ($slots){
foreach(array_keys($slots) as $slotid){
$slots[$slotid]->isappointed = $DB->count_records('simplescheduler_appointment', array('slotid'=>$slotid));
}
}
$straddsession = get_string('addsession', 'simplescheduler');
$straddsingleslot = get_string('addsingleslot', 'simplescheduler');
$strdownloadexcel = get_string('downloadexcel', 'simplescheduler');
// get possible attendees
$students = simplescheduler_get_possible_attendees($cm, $usergroups);
/// some slots already exist
if ($slots){
// print instructions and button for creating slots
echo $OUTPUT->box_start('boxaligncenter');
// these instructions are too redundant and in prime real estate - the buttons themselves are quite explanatory
//print_string('addslot', 'simplescheduler');
// print add session button
$strdeleteallslots = get_string('deleteallslots', 'simplescheduler');
$strdeleteallunusedslots = get_string('deleteallunusedslots', 'simplescheduler');
$strdeleteunusedslots = get_string('deleteunusedslots', 'simplescheduler');
$strdeletemyslots = get_string('deletemyslots', 'simplescheduler');
$strstudents = get_string('students', 'simplescheduler');
$displaydeletebuttons = 1;
include $CFG->dirroot.'/mod/simplescheduler/commands.html';
echo $OUTPUT->box_end();
// prepare slots table
$table = new html_table();
if ($page == 'myappointments'){
$table->head = array ($strdate, $strstart, $strend, $strstudents, $straction);
$table->align = array ('LEFT', 'LEFT', 'LEFT', 'LEFT', 'LEFT');
} else {
$table->head = array ($strdate, $strstart, $strend, $strstudents, s(simplescheduler_get_teacher_name($simplescheduler)), $straction);
$table->align = array ('LEFT', 'LEFT', 'LEFT', 'LEFT', 'LEFT', 'LEFT');
}
$table->width = '90%';
$table->attributes = array('class' => 'generaltable boxaligncenter');
$offsetdatemem = '';
$appointedstudentids = '';
$has_appointment = array();
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
// $DB->delete_records('simplescheduler_slots', array('id'=>$slot->id));
// continue;
//}
/// Parameter $local in simplescheduler_userdate and simplescheduler_usertime added by power-web.at
/// When local Time or Date is needed the $local Param must be set to 1
$offsetdate = simplescheduler_userdate($slot->starttime,1);
$offsettime = simplescheduler_usertime($slot->starttime,1);
$endtime = simplescheduler_usertime($slot->starttime + ($slot->duration * 60),1);
// slot is appointed
$studentArray = array();
$slotappointedstudentids = array();
if ($slot->isappointed) {
$strrevoke = get_string('revoke', 'simplescheduler');
$studentcolumn = '';
$appointedstudents = $DB->get_records('simplescheduler_appointment', array('slotid'=>$slot->id));
foreach($appointedstudents as $appstudent){
$student = $DB->get_record('user', array('id'=>$appstudent->studentid));
$slotappointedstudentids[$appstudent->studentid] = $appstudent->studentid;
$appointedstudentids[$appstudent->studentid] = $appstudent->studentid;
if ($student) {
$name = "<a href=\"view.php?what=viewstudent&id={$cm->id}&studentid={$student->id}&course={$simplescheduler->course}&order=DESC\">".fullname($student).'</a>';
}
$studentcolumn .= "<p>$name";
$studentcolumn .= "<span style=\"font-size: x-small;\"><a href=\"view.php?what=revokeone&id={$cm->id}&slotid={$slot->id}&studentid={$student->id}&page={$page}\" title=\"{$strrevoke}\"><img align=\"right\" src=\"{$CFG->wwwroot}/pix/t/delete.gif\" alt=\"{$strrevoke}\" /></a></span></p>";
}
} else {
// slot is free
$studentcolumn = "";
$slotappointedstudentids = array();
}
$eligible_to_add = array();
// lets find out if we have eligible students to add to this slot
foreach ($students as $studentid => $student)
{
if (!isset($slotappointedstudentids[$studentid]))
{
if ($simplescheduler->simpleschedulermode == 'oneonly')
{
if (!isset($has_appointment[$studentid]))
{
$has_appointment[$studentid] = simplescheduler_student_has_appointment($studentid, $simplescheduler->id);
}
if ($has_appointment[$studentid]) continue; // student can only have one and already has one.
}
$eligible_to_add[$studentid] = $student;
}
}
if (!empty($eligible_to_add))
{
// lets make a form here that lets us add an eligible student
$form = '<div class="addStudent">';
// lets add add student form for this slot to actions (if available)
$form .= '<form name="addtoslotform" method="post" action="view.php?id=2">';
$form .= '<input type="hidden" value="addstudent" name="what"></input>';
$form .= '<input type="hidden" value="'.$cm->id.'" name="id"></input>';
$form .= '<input type="hidden" value="'.$slot->id.'" name="slotid"></input>';
$form .= '<input type="hidden" value="allappointments" name="page"></input>';
$form .= '<select name="studentid">';
$form .= '<option value="">'.get_string('add_a_student_pulldown', 'simplescheduler').'</option>';
foreach ($eligible_to_add as $studentid => $student)
{
$form .= '<option value="'.$studentid.'">'.fullname($student).'</option>';
}
$form .= '<input type="submit" value="Add" name="go_btn"></input>';
$form .= '</form>';
$form .= '</div>';
$studentcolumn .= $form;
}
$studentArray[] = (!empty($studentcolumn)) ? $studentcolumn : get_string('empty_slot_no_availability', 'simplescheduler');
$actions = '<span style="font-size: x-small;">';
if ($USER->id == $slot->teacherid || has_capability('mod/simplescheduler:manageallappointments', $context)){
$strdelete = get_string('delete');
$stredit = get_string('move','simplescheduler');
$strnonexclusive = get_string('isnonexclusive', 'simplescheduler');
$strallowgroup = get_string('allowgroup', 'simplescheduler');
$strforbidgroup = get_string('forbidgroup', 'simplescheduler');
$actions .= "<a href=\"view.php?what=deleteslot&id={$cm->id}&slotid={$slot->id}&page={$page}\" title=\"{$strdelete}\"><img src=\"{$CFG->wwwroot}/pix/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->wwwroot}/pix/t/edit.gif\" alt=\"{$stredit}\" /></a>";
if ($slot->isappointed > 1){
$actions .= " <img src=\"{$CFG->wwwroot}/pix/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->wwwroot}/pix/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->wwwroot}/pix/t/groupv.gif\" alt=\"{$strforbidgroup}\" /></a>";
}
}
} else {
// just signal group status
if ($slot->isappointed > 1) {
$actions .= " <img src=\"{$CFG->wwwroot}/pix/c/group.gif\" title=\"{$strnonexclusive}\" />";
} else {
if ($slot->exclusivity == 1){
$actions .= " <img src=\"{$CFG->wwwroot}/pix/t/groupn.gif\" title=\"{$strallowgroup}\" />";
} else {
$actions .= " <img src=\"{$CFG->wwwroot}/pix/t/groupv.gif\" title=\"{$strforbidgroup}\" />";
}
}
}
if ($slot->exclusivity > 1){
$actions .= ' ('.$slot->exclusivity.')';
}
$actions .= '</span>';
if($page == 'myappointments'){
$table->data[] = array (($offsetdate == $offsetdatemem) ? '' : $offsetdate, $offsettime, $endtime, implode("\n",$studentArray), $actions);
} else {
$teacherlink = "<a href=\"$CFG->wwwroot/user/view.php?id={$slot->teacherid}\">".fullname($DB->get_record('user', array('id'=> $slot->teacherid)))."</a>";
$table->data[] = array (($offsetdate == $offsetdatemem) ? '' : $offsetdate, $offsettime, $endtime, implode("\n",$studentArray), $teacherlink, $actions);
}
$offsetdatemem = $offsetdate;
}
// print slots table
echo $OUTPUT->heading(get_string('slots' ,'simplescheduler'));
echo html_writer::table($table);
?>
<?php
if ($sqlcount > 25) {
$table = new html_table();
$str = "Page : ";
$pagescount = ceil($sqlcount/25);
for ($n = 0; $n < $pagescount; $n ++){
if ($n == $offset){
$str .= ($n+1).' ';
} else {
$str .= "<a href=view.php?id={$cm->id}&page={$page}&offset={$n}>".($n+1)."</a> ";
}
}
$table->data[] = array($str);
$table->attributes = array('class' => 'generaltable boxaligncenter');
$table->width = '90%';
echo html_writer::table($table);
}
// Instruction for teacher to click Seen box after appointment
//echo '<br /><center>' . get_string('markseen', 'simplescheduler') . '</center>';
} else if ($action != 'addsession') {
/// There are no slots, should the teacher be asked to make some
echo $OUTPUT->box_start('boxaligncenter', '', '');
// these instructions are too redundant - the buttons themselves are quite explanatory
//print_string('welcomenewteacher', 'simplescheduler');
$displaydeletebuttons = 0;
include $CFG->dirroot.'/mod/simplescheduler/commands.html';
echo $OUTPUT->box_end();
}
/// print table of outstanding appointer (students)
?>
<table width="90%" class="boxaligncenter">
<tr valign="top">
<td width="50%">
<?php
//echo $OUTPUT->heading(get_string('schedulestudents', 'simplescheduler'));
if (!$students) {
$nostudentstr = get_string('noexistingstudents','simplescheduler');
if ($COURSE->id == SITEID){
$nostudentstr .= '<br/>'.get_string('howtoaddstudents','simplescheduler');
}
echo $OUTPUT->notification($nostudentstr);
} else {
$mtable = new html_table();
// build table header
$mtable->head = array ('', $strname);
$mtable->align = array ('CENTER','LEFT');
$extrafields = simplescheduler_get_user_fields(null);
foreach ($extrafields as $field) {
$mtable->head[] = $field->title;
$mtable->align[] = 'LEFT';
}
// end table header
$mtable->data = array();
// In $mailto the mailing list for reminder emails is built up
$mailto = '<a href="mailto:';
// $maillist will hold a list of email addresses for people who prefer to cut
// and paste into their To field rather than using the mailto link
$maillist = array();
$date = usergetdate(time());
foreach ($students as $student) {
if (!simplescheduler_has_slot($student->id, $simplescheduler, true)) {
$picture = $OUTPUT->user_picture($student);
$name = "<a href=\"../../user/view.php?id={$student->id}&course={$simplescheduler->course}\">";
$name .= fullname($student);
$name .= '</a>';
if (simplescheduler_has_slot($student->id, $simplescheduler, true, false) == 0){
// student has never scheduled
$mailto .= $student->email.', ';
$maillist[] = $student->email; // constructing list of email addresses to be shown later
}
$args['what'] = 'schedule';
$args['id'] = $cm->id;
$args['studentid'] = $student->id;
$args['page'] = $page;
$url = new moodle_url('view.php',$args);
$starttimenow = time();
$appointment = new stdClass();
$appointment->slotid = -1;
$appointment->studentid = $student->id;
$appointment->appointmentnote = '';
$appointment->attended = 1;
$appointment->notes = '';
$appointment->timecreated = time();
$appointment->timemodified = time();
$appointmentarr = array($appointment);
$appointmentser = serialize($appointmentarr);
$args['what'] = 'doaddupdateslot';
$args['id'] = $cm->id;
$args['teacherid'] = $USER->id;
$args['seen'] = 1;
$args['appointments'] = $appointmentser;
$args['starttime'] = $starttimenow;
$args['duration'] = $simplescheduler->defaultslotduration;
$args['hideuntil'] = $simplescheduler->timemodified;
$args['appointmentlocation'] = '';
$args['exclusivity'] = '1';
$args['notes'] = '';
$url = new moodle_url('view.php',$args);
$newdata = array($picture, $name);
$extrafields = simplescheduler_get_user_fields($student);
foreach ($extrafields as $field) {
$newdata[] = $field->value;
}
$mtable->data[] = $newdata;
}
}
// 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
echo $OUTPUT->heading(get_string('missingstudents', 'simplescheduler', $num), 3);
// Print links to print invitation or reminder emails
$strinvitation = get_string('invitation', 'simplescheduler');
$strreminder = get_string('reminder', 'simplescheduler');
$mailto = rtrim($mailto, ', ');
$subject = $strinvitation . ': ' . $simplescheduler->name;
$body = $strinvitation . ': ' . $simplescheduler->name . "\n\n";
$body .= get_string('invitationtext', 'simplescheduler');
$body .= "{$CFG->wwwroot}/mod/simplescheduler/view.php?id={$cm->id}";
$maildisplay = '';
if ($CFG->simplescheduler_showemailplain) {
$maildisplay .= '<p>'.implode(', ', $maillist).'</p>';
}
$maildisplay .= get_string('composeemail', 'simplescheduler').
$mailto.'?subject='.htmlentities(rawurlencode($subject)).
'&body='.htmlentities(rawurlencode($body)).
'"> '.$strinvitation.'</a> ';
$maildisplay .= ' — ';
$subject = $strreminder . ': ' . $simplescheduler->name;
$body = $strreminder . ': ' . $simplescheduler->name . "\n\n";
$body .= get_string('remindertext', 'simplescheduler');
$body .= "{$CFG->wwwroot}/mod/simplescheduler/view.php?id={$cm->id}";
$maildisplay .= $mailto.'?subject='.htmlentities(rawurlencode($subject)).
'&body='.htmlentities(rawurlencode($body)).
'"> '.$strreminder.'</a>';
echo $OUTPUT->box($maildisplay);
// print table of students who still have to make appointments
echo html_writer::table($mtable);
} else {
echo $OUTPUT->notification(get_string('allappointed', 'simplescheduler'));
}
}
?>
</td>
<?php
if (simplescheduler_group_scheduling_enabled($course, $cm)){
?>
<td width="50%">
<?php
/// print table of outstanding appointer (groups)
echo $OUTPUT->heading(get_string('schedulegroups', 'simplescheduler'));
if (empty($groups)){
echo $OUTPUT->notification(get_string('nogroups', 'simplescheduler'));
} else {
$mtable = new html_table();
$mtable->head = array ('', $strname, $straction);
$mtable->align = array ('CENTER', 'LEFT', 'CENTER');
foreach($groups as $group) {
$members = groups_get_members($group->id, 'u.id, lastname, firstname, email, picture', 'lastname, firstname');
if (empty($members)) continue;
if (!simplescheduler_has_slot(implode(',', array_keys($members)), $simplescheduler, true)) {
$actions = '';
$actions .= "<a href=\"view.php?what=schedulegroup&id={$cm->id}&groupid={$group->id}&page={$page}\">";
$actions .= get_string('schedule', 'simplescheduler');
$actions .= '</a>';
$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)){
echo html_writer::table($mtable);
} else {
echo $OUTPUT->notification(get_string('nogroups', 'simplescheduler'));
}
}
?>
</td>
<?php
}
?>
</tr>
</table>
<form action="<?php echo "{$CFG->wwwroot}/course/view.php" ?>" method="get">
<input type="hidden" name="id" value="<?php p($course->id) ?>" />
<input type="submit" name="go_btn" value="<?php print_string('return', 'simplescheduler') ?>" />
</form>