-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcalendar_main.php
More file actions
1305 lines (1237 loc) · 58.9 KB
/
calendar_main.php
File metadata and controls
1305 lines (1237 loc) · 58.9 KB
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
# Calendar Version 4.4, J. Kenney 2015-2024
define('CALENDAR_VERSION', '4.4.20240129');
# Determine what directories should be scanned for files.
$COMPONENTS = array();
foreach ($DOW as $i => $type) {
$type = str_replace(' ', '-', strtolower($type));
$COMPONENTS[$type] = $type;
}
if (isset($OVERRIDE)) {
foreach ($OVERRIDE as $i => $m) {
foreach ($m as $d => $type) {
$type = str_replace(' ', '-', strtolower($type));
$COMPONENTS[$type] = $type;
}
}
}
if (isset($COMBINE)) {
foreach ($COMBINE as $type => $cset) {
$COMPONENTS[$type] = $type;
foreach ($cset as $day => $inside) {
foreach ($inside as $ntype) {
$COMPONENTS[$ntype] = $ntype;
}
}
}
}
# Load in the configuration for all virtual files
# $virtual = array('class'=>array(1 => array(array('answers.html', 'homework/answers05.html'))));
$virtual = array();
if (file_exists($CLASS_FILE)) {
if (!is_readable($CLASS_FILE)) {
if (isset($_REQUEST['event'])) { unset($_REQUEST['event']); }
if (isset($_REQUEST['type'])) { unset($_REQUEST['type']); }
if (isset($_REQUEST['key'])) { unset($_REQUEST['key']); }
if (isset($_REQUEST['show'])) { unset($_REQUEST['show']); }
$PAGE_MODIFY['error'] = "The Virtual Class File ($CLASS_FILE) can not be opened.";
$PAGE_MODIFY['error-comment'] = "The file was detected but the system was unable to read it, as a precaution the calendar will not show any content until this is corrected.";
$_REQUEST['load'] = 'error';
} else {
$vdata = file($CLASS_FILE);
foreach($vdata as $line) {
$line = trim($line);
$line = preg_split('/\s+/', $line);
if (count($line) == 4) {
if (!isset($virtual[$line[2]][$line[3]])) {
$virtual[$line[2]][$line[3]] = array();
}
$virtual[$line[2]][$line[3]][] = array($line[0], $line[1]);
}
}
}
}
# Load in the configuration for all access configurations
# 2 fields provided, $access = array('class01.html' => array('month'=>2, 'day'=>4, 'year'=>1, dynamic=>''));
# 3 fields provided, $access = array('class01.html' => array('month'=>2, 'day'=>4, 'year'=>2018, dynamic=>''));
# 1 field provided, $access = array('class01.html' => array('month'=>1, 'day'=>1, 'year'=>1, dynamic'=>'-2'));
$access = array();
if (file_exists($ACCESS_FILE)) {
if (!is_readable($ACCESS_FILE)) {
if (isset($_REQUEST['event'])) { unset($_REQUEST['event']); }
if (isset($_REQUEST['type'])) { unset($_REQUEST['type']); }
if (isset($_REQUEST['key'])) { unset($_REQUEST['key']); }
if (isset($_REQUEST['show'])) { unset($_REQUEST['show']); }
$PAGE_MODIFY['error'] = "The Access File ($ACCESS_FILE) can not be opened.";
$PAGE_MODIFY['error-comment'] = "The file was detected but the system was unable to read it, as a precaution the calendar will not show any content until this is corrected.";
$_REQUEST['load'] = 'error';
} else {
$vdata = file($ACCESS_FILE);
foreach($vdata as $line) {
$line = trim($line);
$line = preg_split('/\s+/', $line);
if (count($line) == 2 && (strpos($line[1], '-') === 0 || strpos($line[1], '+') === 0)) {
$access[$line[0]] = array('month'=>1, 'day'=>1, 'year'=>1, 'dynamic'=> $line[1]);
} elseif (count($line) == 3) {
$access[$line[0]] = array('month'=> intval($line[1]), 'day'=> intval($line[2]), 'year'=>$YEAR, 'dynamic'=>'');
} elseif (count($line) == 4) {
$access[$line[0]] = array('month'=> intval($line[1]), 'day'=> intval($line[2]), 'year'=>intval($line[3]), 'dynamic'=>'');
}
}
}
}
# Validate a filename to see if is using the legacy security format
# which was filename.month.day.extension,
# This is a rather old concept that should be removed!!!!
# Returns array(VisibleInGeneral, VisibleOnCalendar, Year, Month, Day)
function validate_file($instructor, $filename, $filewithpath, $access) {
$dynamic = '';
if (is_dir($filewithpath)) {
return array(False, False, 1, 1, 1, '', $dynamic);
}
$today = getdate();
$open_year = $today['year'];
$open_month = 1;
$open_day = 1;
$cat_file = $filename;
if (True) {
$cp = array_reverse(explode('.', basename($filewithpath)));
if (count($cp) > 3 && is_numeric($cp[1]) && is_numeric($cp[2])) {
$open_day = intval($cp[1]);
$open_month = intval($cp[2]);
$cat_file = $cp[3] . '.' . $cp[0];
}
}
return array(True, True, $open_year, $open_month, $open_day, $cat_file, $dynamic);
}
# Determine what type of category the file is
# types = html, link, src, txt, powerpoint, pdf (aka the extension!)
function categorize_file($instructor, $filename, $filewithpath, $filereduced, $categories) {
$mytype = '';
$myboxblock = '';
if (isset($categories[$filereduced])) {
$mytype = $categories[$filereduced]['type'];
$myboxblock = $categories[$filereduced]['boxblock'];
} elseif (isset($categories[$filename])) {
$mytype = $categories[$filename]['type'];
$myboxblock = $categories[$filename]['boxblock'];
}
return array($mytype, $myboxblock);
}
# Function to get function()[], a feature that doesnt exist in older versions of PHP
function ancient($results, $index) {
if (!isset($results[$index])) {
return False;
}
return $results[$index];
}
# Retrieve a list of directories and their files, that are sourced from the
# content directories. Files will be validated for access
function get_files($instructor=False, $sources=array('class', 'lab', 'project', 'exam', 'review', 'capstone', 'continued-lab'), $file_path = '.', $access=array(), $virtual=array(), $categories=array(), $secret='really') {
$results = array();
$basedir = scandir($file_path);
foreach ($sources as $i => $l0) {
if (in_array($l0, $basedir) && is_dir($file_path . '/' . $l0)) {
$level1 = scandir($file_path . '/' . $l0);
sort($level1);
foreach ($level1 as $i => $l1) {
if (substr($l1, 0, 1) != '.' && is_dir($file_path . '/' . $l0 . '/' . $l1)) {
// The following code allows the system recursively look through the Directory
// structure within a class, and the system can now process RELATIVE links
// that go into those subordinate directories
$level2 = array();
try {
$Iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($file_path . '/' . $l0 . '/' . $l1),
RecursiveIteratorIterator::LEAVES_ONLY,
RecursiveIteratorIterator::CATCH_GET_CHILD);
foreach($Iterator as $name => $object) {
$name = explode("/", $name);
unset($name[2]);
unset($name[1]);
unset($name[0]);
$name = implode("/", $name);
$level2[] = $name;
}
} catch (Exception $e) {
// Unable to recurse, so don't bother...
}
// $level2 = scandir($file_path . '/' . $l0 . '/' . $l1);
$results[$l0][$l1] = array();
sort($level2);
foreach ($level2 as $i => $l2) {
$key = sha1($secret.$l0.$l1.$l2);
if (substr($l2, 0, 1) != '.' && ancient(validate_file($instructor, $l2, $file_path . '/' . $l0 . '/' . $l1 . '/' . $l2, $access), 0)) {
if (is_link($file_path . '/' . $l0 . '/' . $l1 . '/' . $l2)) {
if (validate_file($instructor, readlink($file_path . '/' . $l0 . '/' . $l1 . '/' . $l2), ancient(readlink($file_path . '/' . $l0 . '/' . $l1 . '/' . $l2), $access),0)) {
$vf = validate_file($instructor, readlink($file_path . '/' . $l0 . '/' . $l1 . '/' . $l2), readlink($file_path . '/' . $l0 . '/' . $l1 . '/' . $l2), $access);
$category = categorize_file($instructor, $l2, readlink($file_path . '/' . $l0 . '/' . $l1 . '/' . $l2), $vf[5], $categories);
$results[$l0][$l1][$l2] = array('actual' => $file_path . '/' . $l0 . '/' . $l1 . '/' . readlink($file_path . '/' . $l0 . '/' . $l1 . '/' . $l2),
'visible' => $vf[1],
'year' => $vf[2],
'month' => $vf[3],
'day' => $vf[4],
'dynamic' => $vf[6],
'type' => $category[0],
'category' => $category[1],
'key' => $key,
'filename' => $l2);
}
} else {
$vf = validate_file($instructor, $l2, $file_path . '/' . $l0 . '/' . $l1 . '/' . $l2, $access);
$category = categorize_file($instructor, $l2, $file_path . '/' . $l0 . '/' . $l1 . '/' . $l2, $vf[5], $categories);
$results[$l0][$l1][$l2] = array('actual' => $file_path . '/' . $l0 . '/' . $l1 . '/' . $l2,
'visible' => $vf[1],
'year' => $vf[2],
'month' => $vf[3],
'day' => $vf[4],
'dynamic' => $vf[6],
'type' => $category[0],
'category' => $category[1],
'key' => $key,
'filename' => $l2);
}
}
}
}
}
}
}
# Add Virtual files, format like array('class'=>array(1 => array(array('answers.html', 'homework/answers05.html'))))
foreach ($virtual as $l0 => $l1array) {
if (isset($results[$l0])) {
$classes = array_keys($results[$l0]);
foreach ($l1array as $day => $l2array) {
if (isset($classes[$day-1])) {
foreach ($l2array as $i => $values) {
$virt_file = $values[0];
$real_file = $values[1];
if (ancient(validate_file($instructor, $real_file, $real_file, $access),0)) {
$key = sha1($secret.$real_file.$virt_file);
$vf = validate_file($instructor, $real_file, $real_file, $access);
$category = categorize_file($instructor, $virt_file, $real_file, $vf[5], $categories);
$results[$l0][$classes[$day-1]][$virt_file] = array('actual' => $real_file,
'visible' => $vf[1],
'year' => $vf[2],
'month' => $vf[3],
'day' => $vf[4],
'dynamic' => $vf[6],
'type' => $category[0],
'category' => $category[1],
'key' => $key,
'filename' => $real_file);
}
}
}
}
}
}
return $results;
}
# Determine what file security parameters to use, based on access file.
function get_file_security($YEAR, $month, $day, $l0, $l1, $cate, $filename, $access) {
$sspec = False;
if (isset($access[$l0."_".$l1."/".$filename])) {
$sspec = $l0."_".$l1."/".$filename;
} elseif (isset($access[$filename])) {
$sspec = $filename;
} elseif (isset($access[$l0."_".$l1."/".$cate])) {
$sspec = $l0."_".$l1."/".$cate;
} elseif (isset($access[$l0."/".$cate])) {
$sspec = $l0."/".$cate;
} elseif (isset($access[$l0."_".$l1])) {
$sspec = $l0."_".$l1;
} elseif (isset($access[$l0."/*"])) {
$sspec = $l0."/*";
} elseif (isset($access[$l0."_".$l1."/all"])) {
$sspec = $l0."_".$l1."/all";
} elseif (isset($access[$l0."_".$l1."/*"])) {
$sspec = $l0."_".$l1."/*";
} elseif (isset($access["*/".$cate])) {
$sspec = "*/".$cate;
} elseif (isset($access[$l0])) {
$sspec = $l0;
} elseif (isset($access["*"])) {
$sspec = "*";
}
if ($sspec !== False && isset($access[$sspec])) {
$today = getdate();
if ($access[$sspec]['dynamic'] == '') {
if ( ($today['year'] > $access[$sspec]['year'] && 12 >= $access[$sspec]['month'] && 31 >= $access[$sspec]['day'])
|| ($today['year'] >= $access[$sspec]['year'] && $today['mon'] > $access[$sspec]['month'])
|| ($today['year'] == $access[$sspec]['year'] && $today['mon'] == $access[$sspec]['month'] && $today['mday'] >= $access[$sspec]['day'])) {
return array(True, $access[$sspec]['year'], $access[$sspec]['month'], $access[$sspec]['day'], $access[$sspec]['dynamic']);
} else {
return array(False, $access[$sspec]['year'], $access[$sspec]['month'], $access[$sspec]['day'], $access[$sspec]['dynamic']);
}
} else {
$delta = substr($access[$sspec]['dynamic'], 1);
$d0 = new DateTime("$YEAR-$month-$day 00:00:01");
$today = new DateTime();
if ($delta != '0') {
if (substr($access[$sspec]['dynamic'], 0, 1) == '+') {
if (is_numeric($delta)) {
$diffDay = new DateInterval("P".$delta."D");
$d0->add($diffDay);
} else {
$d0->modify('next '.$delta);
}
} elseif (substr($access[$sspec]['dynamic'], 0, 1) == '-') {
if (is_numeric($delta)) {
$diffDay = new DateInterval("P".$delta."D");
$d0->sub($diffDay);
} else {
if (strtoupper($d0->format('l')) != strtoupper($delta)) {
$d0->modify('last '.$delta);
}
}
}
}
$d0v = explode('-', $d0->format('Y-n-j'));
if ($today >= $d0) {
return array(True, $d0v[0], $d0v[1], $d0v[2], $access[$sspec]['dynamic']);
} else {
return array(False, $d0v[0], $d0v[1], $d0v[2], $access[$sspec]['dynamic']);
}
}
}
return array(True, 1,1,1,'');
}
# Build type tree
function build_types($BOX, $HTML, $LINK, $PDF, $PPT, $SRC) {
$categories = array();
foreach (array('html'=>$HTML, 'link'=>$LINK, 'pdf'=>$PDF, 'ppt'=>$PPT, 'src'=>$SRC) as $item => $values) {
foreach ($values as $cat => $value) {
$categories[$value] = array('type'=>$item, 'boxblock'=>$cat);
}
}
return $categories;
}
# Update the events with the date of the class
function calendar_events($events, $YEAR, $MONTH_START, $DAY_START, $WEEKENDS, $MONTH_END, $DOW, $OVERRIDE, $BOX, $COMBINE=array()) {
$results = array('year'=>$YEAR, 'month_start'=>$MONTH_START, 'month_end'=>$MONTH_END, 'box'=>$BOX);
$results_counter = array();
$POSDOW = array(0 => 'sun', 1 => 'mon', 2 => 'tue', 3 => 'wed', 4 => 'thu', 5 => 'fri', 6 => 'sat', 7 => 'sun');
## Lets walk through all possible months...
for($month=$MONTH_START; $month <= $MONTH_END; $month++) {
$month_len = cal_days_in_month(CAL_GREGORIAN, $month, $YEAR);
$month_name = cal_info(0);
$month_name = $month_name['months'][$month];
$first = date("w", mktime(0, 0, 0, $month, 1, $YEAR));
## Lets walk through the days of this specific month
for($day=1; $day <= $month_len; $day++) {
$day_type = '';
$day_num = '';
$force_day = False;
## Lets determine what type of day it is...
## If we are before the semester starts
if ($month == $MONTH_START && $day < $DAY_START) {
## If we are overriding a specific day
} elseif (isset($OVERRIDE[$month][$day])) {
$day_type = $OVERRIDE[$month][$day];
$force_day = True;
## If it is just a normal day
} elseif (isset($DOW[$POSDOW[$first]])) {
$day_type = $DOW[$POSDOW[$first]];
}
## If it is an actual day, lets do some work...
if ($day_type != '') {
## Lets figure out what class/lab/project/etc # we are dealing with
if (isset($events[$day_type])) {
if (!isset($results_counter[$day_type])) {
$results_counter[$day_type] = 1;
} else {
$results_counter[$day_type]++;
}
}
## lets figure out what the event entails
if (isset($events[$day_type]) && isset($events[$day_type][$results_counter[$day_type]])) {
$event = $events[$day_type][$results_counter[$day_type]];
$day_num = $results_counter[$day_type];
} else {
$event = array();
}
## Are we forcing today to be something else...
if ($force_day || !empty($event)) {
$results[$month][$day] = array('month'=>$month, 'day'=>$day, 'type'=>$day_type, 'type_num'=>$day_num,
'dow'=>$first, 'dow_eng'=>$POSDOW[$first], 'event'=>$event);
$results['map'][$day_type][$day_num] = array($month, $day);
}
## Did we want two things to occur on the same day???
## Example: $COMBINE = array('class'=>array(3=>array('class', 'class')));
if (isset($COMBINE[$day_type][$day_num])) {
foreach ($COMBINE[$day_type][$day_num] as $nday_type) {
if (!isset($results_counter[$nday_type])) {
$results_counter[$nday_type] = 1;
} else {
$results_counter[$nday_type]++;
}
## lets figure out what the event entails
$nday_num = -1;
if (isset($events[$nday_type]) && isset($events[$nday_type][$results_counter[$nday_type]])) {
$event = $events[$nday_type][$results_counter[$nday_type]];
$nday_num = $results_counter[$nday_type];
} else {
$event = array();
}
if (!isset($results[$month][$day]['combine'])) {
$results[$month][$day]['combine'] = array();
}
$results[$month][$day]['combine'][] = array('month'=>$month, 'day'=>$day,
'type'=>$nday_type, 'type_num'=>$nday_num,
'dow'=>$first, 'dow_eng'=>$POSDOW[$first],
'event'=>$event);
$results['map'][$nday_type][$nday_num] = array($month, $day);
}
}
}
## Some code to figure out where in the week we are...
$first++;
if ($first == 7) {$first = 0;}
}
}
return $results;
}
# Build events (these will be used to display the calendar)
function build_events($files, $categories, $BOX) {
$events = array();
foreach ($files as $cat => $catarray) {
$events[$cat] = array();
$counter = 1;
foreach ($catarray as $event => $earray) {
$cevent = explode('.', $event);
if (count($cevent) > 1) {
$cevent = $cevent[1];
} else {
$cevent = $cevent[0];
}
$events[$cat][$counter] = array('name' => $cevent, 'box' => array());
$fcounter = 0;
foreach ($earray as $fn => $fndata) {
if ($fndata['category'] != '' && !isset($events[$cat][$counter]['box'][$fndata['category']])) {
$events[$cat][$counter]['box'][$fndata['category']] = $fndata;
$events[$cat][$counter]['box'][$fndata['category']]['filename'] = $fn;
$events[$cat][$counter]['box'][$fndata['category']]['ftype'] = $cat;
$events[$cat][$counter]['box'][$fndata['category']]['fclass'] = $counter;
$events[$cat][$counter]['box'][$fndata['category']]['fid'] = $fcounter;
}
$fcounter++;
}
$counter++;
}
}
return $events;
}
# Build keypairs (these link files to a sha1 hash)
function build_keypairs($files) {
$keypairs = array();
foreach ($files as $type => $classes) {
foreach ($classes as $classname => $classfiles) {
foreach ($classfiles as $filename => $values) {
$keypairs[$values['key']] = $values['actual'];
}
}
}
return $keypairs;
}
# load and provide the contents of a file to the browser
# sets appropriate mime types
function provide_file($filename) {
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$MODE = 'txt';
$attachment = "attachment; ";
if ($ext != '') {
$MODE = $ext;
}
switch ($MODE) {
case "bz2": $ctype="application/x-bzip2"; break;
case "css": $ctype="text/css"; break;
case "gz": $ctype="application/x-gzip"; break;
case "gzip": $ctype="application/x-gzip"; break;
case "java": $ctype="text/x-java-source"; $attachment=""; break;
case "tgz": $ctype="application/x-compressed"; break;
case "pdf": $ctype="application/pdf"; $attachment=""; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "docx": $ctype="application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "xlsx": $ctype="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "pptx": $ctype="application/vnd.openxmlformats-officedocument.presentationml.presentation"; break;
case "svg": $ctype="image/svg+xml"; $attachment=""; break;
case "gif": $ctype="image/gif"; $attachment=""; break;
case "png": $ctype="image/png"; $attachment=""; break;
case "jpe": $ctype="image/jpg"; $attachment=""; break;
case "jpeg": $ctype="image/jpg"; $attachment=""; break;
case "jpg": $ctype="image/jpg"; $attachment=""; break;
case "sql": $ctype="text/plain"; $attachment=""; break;
case "txt": $ctype="text/plain"; $attachment=""; break;
case "htm": $ctype="text/html"; $attachment=""; break;
case "html": $ctype="text/html"; $attachment=""; break;
case "htmls": $ctype="text/html"; $attachment=""; break;
default: $ctype="application/octet-stream";
}
header("Content-Type: $ctype");
header('Content-Disposition: '.$attachment.'filename="'.basename($filename).'"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
echo file_get_contents($filename);
}
# Determine the valid categories for files
$categories = build_types($BOX, $HTML, $LINK, $PDF, $PPT, $SRC);
# Set valid logon time (based on cookie auth)
if (!isset($LOGON_TIME)) {
$LOGON_TIME = 43200;
}
# Perform Authentication
session_start();
if ($ADMIN != '') {
if (isset($_REQUEST['password']) && $_REQUEST['password'] == $ADMIN) {
$_SESSION["cal4-$COURSE"] = sha1($SECRET.$ADMIN.$COURSE.$_SESSION["cal4-$COURSE-nonce"].session_id());
setcookie("cal4-$COURSE", sha1($SECRET.$ADMIN.$COURSE.$_COOKIE["cal4-$COURSE-nonce"].session_id()), time()+$LOGON_TIME);
$_COOKIE["cal4-$COURSE"] = sha1($SECRET.$ADMIN.$COURSE.$_COOKIE["cal4-$COURSE-nonce"].session_id());
} elseif (isset($_REQUEST['password'])
&& isset($_COOKIE["cal4-$COURSE-nonce"])
&& $_REQUEST['password'] == hash('sha256', $ADMIN.$_COOKIE["cal4-$COURSE-nonce"])) {
$_SESSION["cal4-$COURSE"] = sha1($SECRET.$ADMIN.$COURSE.$_COOKIE["cal4-$COURSE-nonce"].session_id());
setcookie("cal4-$COURSE", sha1($SECRET.$ADMIN.$COURSE.$_COOKIE["cal4-$COURSE-nonce"].session_id()), time()+$LOGON_TIME);
$_COOKIE["cal4-$COURSE"] = sha1($SECRET.$ADMIN.$COURSE.$_COOKIE["cal4-$COURSE-nonce"].session_id());
} elseif (isset($_REQUEST['password'])
&& isset($_SESSION["cal4-$COURSE-nonce"])
&& $_REQUEST['password'] == hash('sha256', $ADMIN.$_SESSION["cal4-$COURSE-nonce"])) {
$_SESSION["cal4-$COURSE"] = sha1($SECRET.$ADMIN.$COURSE.$_SESSION["cal4-$COURSE-nonce"].session_id());
setcookie("cal4-$COURSE", sha1($SECRET.$ADMIN.$COURSE.$_COOKIE["cal4-$COURSE-nonce"].session_id()), time()+$LOGON_TIME);
$_COOKIE["cal4-$COURSE"] = sha1($SECRET.$ADMIN.$COURSE.$_COOKIE["cal4-$COURSE-nonce"].session_id());
} elseif (isset($_REQUEST['password']) && (isset($_SESSION["cal4-$COURSE"]) || isset($_COOKIE["cal4-$COURSE"]) )) {
if (isset($_SESSION["cal4-$COURSE"])) {
unset($_SESSION["cal4-$COURSE"]);
}
if (isset($_COOKIE["cal4-$COURSE"])) {
unset($_COOKIE["cal4-$COURSE"]);
setcookie("cal4-$COURSE", '', time()-3600);
}
}
# Verify that authentication code is correct
if (isset($_COOKIE["cal4-$COURSE"])
&& isset($_COOKIE["cal4-$COURSE-nonce"])
&& $_COOKIE["cal4-$COURSE"] == sha1($SECRET.$ADMIN.$COURSE.$_COOKIE["cal4-$COURSE-nonce"].session_id())) {
$INSTRUCTOR = True;
} elseif (isset($_SESSION["cal4-$COURSE"])
&& $_SESSION["cal4-$COURSE"] == sha1($SECRET.$ADMIN.$COURSE.$_SESSION["cal4-$COURSE-nonce"].session_id())) {
$INSTRUCTOR = True;
} else {
$myNonce = hash('sha256',"{".rand()."-".rand()."}");
$_SESSION["cal4-$COURSE-nonce"] = $myNonce;
setcookie("cal4-$COURSE-nonce", $myNonce, time()+$LOGON_TIME);
$_COOKIE["cal4-$COURSE-nonce"] = $myNonce;
}
# Default to Student User Mode
if (!isset($INSTRUCTOR)) {
$INSTRUCTOR = False;
}
}
# Add a record of the visit to this page if $ACCESS_LOG is set
if (isset($ACCESS_LOG) && file_exists($ACCESS_LOG)) {
$URI = explode("?", $_SERVER['REQUEST_URI']);
if (isset($URI[1])) {
$URI = $URI[1];
} else {
$URI = "home";
}
$fp = fopen($ACCESS_LOG, 'a');
if ($fp) {
$fpl = date('Ymd-H:i:s'). " " . $_SERVER['REMOTE_ADDR'] . " " . $URI . PHP_EOL;
fwrite($fp, $fpl);
fclose($fp);
}
}
# Lock the calendar if requested via lock files
if (!$INSTRUCTOR && isset($LOCK) && ($LOCK === true || file_exists($LOCK))) {
if (isset($_REQUEST['event'])) { unset($_REQUEST['event']); }
if (isset($_REQUEST['type'])) { unset($_REQUEST['type']); }
if (isset($_REQUEST['key'])) { unset($_REQUEST['key']); }
if (isset($_REQUEST['show'])) { unset($_REQUEST['show']); }
$_REQUEST['load'] = 'lock';
}
# Get accessibles files located within the various component directories
$files = get_files($INSTRUCTOR, array_keys($COMPONENTS), '.', $access, $virtual, $categories, $SECRET);
# Remove keys from memory, incase something goes wrong... (such as embedded PHP)
unset($ADMIN);
unset($SECRET);
# Retrieve a list of file=>keys
$keypairs = build_keypairs($files);
# Build an array of all of the events (day by day, class or lab by class)
$events = build_events($files, $categories, $BOX);
if (!isset($COMBINE)) {
$COMBINE = array();
}
$events_list = calendar_events($events, $YEAR, $MONTH_START, $DAY_START, $WEEKENDS, $MONTH_END, $DOW, $OVERRIDE, $BOX, $COMBINE);
# Trim the $events_list variable removing any dynamically controlled content
# as part of the dynamic date security protocol.
for ($month = 1; $month < 13; $month++) {
for ($day = 1; $day < 32; $day++) {
if ( isset($events_list[$month][$day])
&& isset($events_list[$month][$day]['event'])
&& isset($events_list[$month][$day]['event']['box'])) {
foreach ($events_list[$month][$day]['event']['box'] as $ibox => $iset) {
$x = get_file_security($YEAR, $month, $day, $iset['ftype'], $iset['fclass'], $iset['category'], $iset['filename'], $access);
$events_list[$month][$day]['event']['box'][$ibox]['year'] = $x[1];
$events_list[$month][$day]['event']['box'][$ibox]['month'] = $x[2];
$events_list[$month][$day]['event']['box'][$ibox]['day'] = $x[3];
$events_list[$month][$day]['event']['box'][$ibox]['dynamic'] = $x[4];
if (!$x[0]) {
$events_list[$month][$day]['event']['box'][$ibox]['visible'] = False;
if (!$INSTRUCTOR) {
unset($events[$iset['ftype']][$iset['fclass']]['box'][$iset['category']]);
unset($events_list[$month][$day]['event']['box'][$ibox]);
}
}
}
}
# Handle Dynamic [COMBINED] Content
if ( isset($events_list[$month][$day])
&& isset($events_list[$month][$day]['combine'])) {
foreach ($events_list[$month][$day]['combine'] as $outerbox => $outerset) {
if ( isset($outerset['event'])
&& isset($outerset['event']['box'])) {
foreach($events_list[$month][$day]['combine'][$outerbox]['event']['box'] as $ibox => $iset) {
$x = get_file_security($YEAR, $month, $day, $iset['ftype'], $iset['fclass'], $iset['category'], $iset['filename'], $access);
$events_list[$month][$day]['combine'][$outerbox]['event']['box'][$ibox]['year'] = $x[1];
$events_list[$month][$day]['combine'][$outerbox]['event']['box'][$ibox]['month'] = $x[2];
$events_list[$month][$day]['combine'][$outerbox]['event']['box'][$ibox]['day'] = $x[3];
$events_list[$month][$day]['combine'][$outerbox]['event']['box'][$ibox]['dynamic'] = $x[4];
if (!$x[0]) {
$events_list[$month][$day]['combine'][$outerbox]['event']['box'][$ibox]['visible'] = False;
if (!$INSTRUCTOR) {
unset($events[$iset['ftype']][$iset['fclass']]['box'][$iset['category']]);
unset($events_list[$month][$day]['combine'][$outerbox]['event']['box'][$ibox]);
}
}
}
}
}
}
}
}
# Retrieve the other files in the specific lecture
$other = array();
if (isset($_REQUEST['event']) && isset($_REQUEST['type']) && isset($events[$_REQUEST['type']])) {
$other = array_keys($files[$_REQUEST['type']]);
$other = $files[$_REQUEST['type']][$other[$_REQUEST['event']-1]];
if (isset($events_list['map'][$_REQUEST['type']][$_REQUEST['event']])) {
$month = $events_list['map'][$_REQUEST['type']][$_REQUEST['event']][0];
$day = $events_list['map'][$_REQUEST['type']][$_REQUEST['event']][1];
} else {
$month=12;
$day=31;
}
# Verify Security of other files...
foreach($other as $ibox => $iset) {
// function get_file_security($YEAR, $month, $day, $l0, $l1, $cate, $filename, $access) {
$x = get_file_security($YEAR, $month, $day, $_REQUEST['type'], $_REQUEST['event'], $iset['category'], $iset['filename'], $access);
$other[$ibox]['year'] = $x[1];
$other[$ibox]['month'] = $x[2];
$other[$ibox]['day'] = $x[3];
$other[$ibox]['dynamic'] = $x[4];
if (!$x[0]) {
$other[$ibox]['visible'] = False;
if (!$INSTRUCTOR) {
unset($other[$ibox]);
}
}
}
}
# Was a specific event requested, if so process the html and;
# - embed any local images
# - remove all <inst> tags if not the instructor
# - remove all <student> tags if answers were not requested
# Place the results in $contents
$contents = '';
$actual = '';
$find_student = False;
$find_instructor = False;
$navbar_display = "";
$file_type = '?';
# Decide what to show if coming to the main page without anything selected
if (!isset($_REQUEST['event']) && !isset($_REQUEST['type']) && !isset($_REQUEST['load']) && !isset($_REQUEST['show']) && !isset($_REQUEST['key'])) {
if ($DEFAULT_TODAYS_LECTURE) {
$today = getdate();
$today_mon = $today['mon'];
$today_day = $today['mday'];
if (isset($events_list[$today_mon][$today_day]['event']['box']['title'])) {
if (isset($events_list[$today_mon][$today_day]['event']['box']['title']['type']) && $events_list[$today_mon][$today_day]['event']['box']['title']['type'] == 'html') {
$_REQUEST['type'] = $events_list[$today_mon][$today_day]['type'];
$_REQUEST['event'] = $events_list[$today_mon][$today_day]['type_num'];
}
} else {
$_REQUEST['load'] = 'home';
}
} else {
$_REQUEST['load'] = 'home';
}
}
# Check to see if event and type were provided and if they are valid
if (isset($_REQUEST['event']) && isset($_REQUEST['type']) && isset($events[$_REQUEST['type']])) {
$file_type = '?';
$ext = '?';
# If a valid keypair is provided use that file as the source
if (isset($_REQUEST['key']) && isset($keypairs[$_REQUEST['key']])) {
foreach ($other as $ofile => $odata) {
if ($_REQUEST['key'] == $odata['key']) {
$actual = $keypairs[$_REQUEST['key']];
$ext = pathinfo($actual, PATHINFO_EXTENSION);
}
}
} elseif (isset($events[$_REQUEST['type']][$_REQUEST['event']]['box']['title']['actual']) && isset($events[$_REQUEST['type']][$_REQUEST['event']]['box']['title']['type'])) {
$actual = $events[$_REQUEST['type']][$_REQUEST['event']]['box']['title']['actual'];
$file_type = $events[$_REQUEST['type']][$_REQUEST['event']]['box']['title']['type'];
$ext = pathinfo($actual, PATHINFO_EXTENSION);
}
# If the source is not html, provide the unprocessed file
if ($file_type != 'html' && $ext != 'html' && $actual != '' && $ext != 'htm' && !isset($_REQUEST['navbaronly'])) {
provide_file($actual);
die;
} elseif ($ext == 'htm') {
$_REQUEST['nocss'] = 'yes';
}
# Set the navbar title to the title of this lecture
if (isset($events[$_REQUEST['type']][$_REQUEST['event']]['name'])) {
$navbar_display = $events[$_REQUEST['type']][$_REQUEST['event']]['name'];
}
# Retrieve the contents of this file
if ($actual != '') {
$contents = file_get_contents($actual);
$contents_clean = $contents;
$actual_file = $actual;
}
}
# Check to see if a web page is requested
# This will provide .html files in the root directory
if (isset($_REQUEST['load'])) {
$actual = $_REQUEST['load'].'.pdf';
if (file_exists(basename($actual))) {
provide_file(basename($actual));
die;
}
$actual = $_REQUEST['load'].'.html';
if (file_exists('calendar/'.$actual)) {
$contents = file_get_contents('calendar/'.basename($actual));
} elseif (file_exists(basename($actual))) {
$contents = file_get_contents(basename($actual));
}
}
# Build default replace values
if (!isset($PAGE_MODIFY['event']) && isset($_REQUEST['event'])) {
$PAGE_MODIFY['event'] = $_REQUEST['event'];
}
if (!isset($PAGE_MODIFY['zevent']) && isset($_REQUEST['event'])) {
$PAGE_MODIFY['zevent'] = str_pad($_REQUEST['event'],2,"0",STR_PAD_LEFT);
}
if (!isset($PAGE_MODIFY['type']) && isset($_REQUEST['type'])) {
$PAGE_MODIFY['type'] = $_REQUEST['type'];
}
if (!isset($PAGE_MODIFY['ctype']) && isset($_REQUEST['type'])) {
$PAGE_MODIFY['ctype'] = ucfirst($_REQUEST['type']);
}
if (!isset($PAGE_MODIFY['course']) && isset($COURSE)) {
$PAGE_MODIFY['course'] = $COURSE;
}
if (!isset($PAGE_MODIFY['coursename']) && isset($COURSENAME)) {
$PAGE_MODIFY['coursename'] = $COURSENAME;
}
if (!isset($PAGE_MODIFY['coursenamefull']) && isset($COURSENAMEFULL)) {
$PAGE_MODIFY['coursenamefull'] = $COURSENAMEFULL;
}
if (!isset($PAGE_MODIFY['title']) && isset($navbar_display)) {
$PAGE_MODIFY['title'] = $navbar_display;
}
if (!isset($PAGE_MODIFY['access_file']) && isset($ACCESS_FILE)) {
$PAGE_MODIFY['access_file'] = $ACCESS_FILE;
}
if (!isset($PAGE_MODIFY['class_file']) && isset($CLASS_FILE)) {
$PAGE_MODIFY['class_file'] = $CLASS_FILE;
}
# Allow multiple levels of loading files (5 levels by default)
# I should probably make this loop exit if nothing changes...
# Or continue until nothing changes (and a max...)
for ($loop_count = 0; $loop_count < 5; $loop_count++) {
# Replace image <img src>, <source src= />, and anchor <a href> links with the key'd version of the file
foreach ($other as $fn => $value) {
$link = "calendar.php?key=". strip_tags($value['key']);
if (isset($_REQUEST['type'])) {
$link .= '&type=' . strip_tags($_REQUEST['type']);
}
if (isset($_REQUEST['event'])) {
$link .= '&event=' . strip_tags($_REQUEST['event']);
}
$contents = str_ireplace('<img src="'.$fn.'"', '<img src="'.$link.'"', $contents);
$contents = str_ireplace("<img src='".$fn."'", "<img src='".$link."'", $contents);
$contents = str_ireplace('<source src="'.$fn.'"', '<source src="'.$link.'"', $contents);
$contents = str_ireplace("<source src='".$fn."'", "<source src='".$link."'", $contents);
$contents = str_ireplace('<a href="'.$fn.'"', '<a href="'.$link.'"', $contents);
$contents = str_ireplace("<a href='".$fn."'", "<a href='".$link."'", $contents);
$contents = str_ireplace('<showlink src="'.$fn.'">', $link, $contents);
$contents = str_ireplace("<showlink src='".$fn."'>", $link, $contents);
}
# Search for <replace value=""> tags and directly copy the the information
# from $PAGE_MODIFY into them.
preg_match_all('/<replace[^>]+>/i', $contents, $injects);
foreach($injects[0] as $row => $inject_tag) {
preg_match_all('/value=(\x27[^\x27]*\x27|\x22[^\x22]*\x22)/i',$inject_tag, $tag_src);
$tag_src = substr($tag_src[1][0],1,-1);
if ($tag_src != "" && isset($PAGE_MODIFY[$tag_src])) {
$inject_data = $PAGE_MODIFY[$tag_src];
$inject_data = str_ireplace('<', '<', $inject_data);
$inject_data = str_ireplace('>', '>', $inject_data);
$contents = str_ireplace('<replace value="'.$tag_src.'">', $inject_data, $contents);
$contents = str_ireplace("<replace value='$tag_src'>", $inject_data, $contents);
$contents = str_ireplace('<replace value="'.$tag_src.'"/>', $inject_data, $contents);
$contents = str_ireplace("<replace value='$tag_src'"."/>", $inject_data, $contents);
$contents = str_ireplace('<replace value="'.$tag_src.'" />', $inject_data, $contents);
$contents = str_ireplace("<replace value='$tag_src'"." />", $inject_data, $contents);
}
}
# Search for <inject src=""> tags and directly copy the contents into this tag area
preg_match_all('/<inject[^>]+>/i', $contents, $injects);
foreach($injects[0] as $row => $inject_tag) {
preg_match_all('/src=(\x27[^\x27]*\x27|\x22[^\x22]*\x22)/i',$inject_tag, $tag_src);
$tag_src = substr($tag_src[1][0],1,-1);
if ($tag_src != "" && isset($other[$tag_src])) {
$inject_data = file_get_contents($other[$tag_src]['actual']);
$inject_src[] = $tag_src;
$contents = str_ireplace('<inject src="'.$tag_src.'">', $inject_data, $contents);
$contents = str_ireplace("<inject src='$tag_src'>", $inject_data, $contents);
$contents = str_ireplace('<inject src="'.$tag_src.'"/>', $inject_data, $contents);
$contents = str_ireplace("<inject src='$tag_src'"."/>", $inject_data, $contents);
$contents = str_ireplace('<inject src="'.$tag_src.'" />', $inject_data, $contents);
$contents = str_ireplace("<inject src='$tag_src'"." />", $inject_data, $contents);
}
}
# Search for <codeinject src=""> tags and directly copy the contents into this tag area
preg_match_all('/<codeinject[^>]+>/i', $contents, $injects);
foreach($injects[0] as $row => $inject_tag) {
preg_match_all('/src=(\x27[^\x27]*\x27|\x22[^\x22]*\x22)/i',$inject_tag, $tag_src);
$tag_src = substr($tag_src[1][0],1,-1);
if ($tag_src != "" && isset($other[$tag_src])) {
$inject_data = file_get_contents($other[$tag_src]['actual']);
$inject_data = str_ireplace('&', '&', $inject_data);
$inject_data = str_ireplace('<', '<', $inject_data);
$inject_data = str_ireplace('>', '>', $inject_data);
$contents = str_ireplace('<codeinject src="'.$tag_src.'">', $inject_data, $contents);
$contents = str_ireplace("<codeinject src='$tag_src'>", $inject_data, $contents);
$contents = str_ireplace('<codeinject src="'.$tag_src.'"/>', $inject_data, $contents);
$contents = str_ireplace("<codeinject src='$tag_src'"."/>", $inject_data, $contents);
$contents = str_ireplace('<codeinject src="'.$tag_src.'" />', $inject_data, $contents);
$contents = str_ireplace("<codeinject src='$tag_src'"." />", $inject_data, $contents);
}
}
}
# Addition to allow automatic reveal of the shown in class examples, etc AFTER the days
# classes have occured.
# First we check the current year vs the course year - if greater no reason to continue
# Then we check the current month vs the requested asset month - if greater no reason to continue.
# The we check the current day vs the requested asset day - if greater no reason to continue.
# Lastly we check the current hour vs the set reveal hour - if greater no reason to continue.
# If all these fail, then we strip out the revealed content.
# Uses the new tag <postmeeting>
# The time to reveal is from the $REVEALHOUR variable located in calendar.php
if ((!isset($INSTRUCTOR) || !$INSTRUCTOR) && isset($REVEALHOUR)) {
$today_date_time = getdate();
if (
($today_date_time['year'] > $YEAR)
||
(
($today_date_time['year'] >= $YEAR)
&&
($today_date_time['mon'] > $events_list[map][$_REQUEST['type']][$_REQUEST['event']][0])
)
||
(
($today_date_time['year'] == $YEAR)
&&
($today_date_time['mon'] == $events_list[map][$_REQUEST['type']][$_REQUEST['event']][0])
&&
($today_date_time['mday'] > $events_list[map][$_REQUEST['type']][$_REQUEST['event']][1])
)
||
(
($today_date_time['year'] == $YEAR)
&&
($today_date_time['mon'] == $events_list[map][$_REQUEST['type']][$_REQUEST['event']][0])
&&
($today_date_time['mday'] == $events_list[map][$_REQUEST['type']][$_REQUEST['event']][1])
&&
($today_date_time['hours'] >= $REVEALHOUR)
)
){
#show the content
echo "Would show content";
$contents = preg_replace('/<postmeeting[^>]*>([\s\S]*?)<\/postmeeting[^>]*>/', '\1', $contents);
}
else {
#DO NOT show the content
$contents = preg_replace('/<postmeeting[^>]*>([\s\S]*?)<\/postmeeting[^>]*>/', '', $contents);
}
}
# Remove the contents of <inst>...</inst> tags if not logged on
if (!isset($INSTRUCTOR) || !$INSTRUCTOR) {
$contents = preg_replace('/<inst[^>]*>([\s\S]*?)<\/inst[^>]*>/', '', $contents);
}
else {
$contents = preg_replace('/<inst[^>]*>([\s\S]*?)<\/inst[^>]*>/', '\1', $contents);
}
# Remove the contents of <host server="">...</host> tags if not on the
# specified server (use $_SERVER['SERVER_NAME'])
preg_match_all('/<host[^>]+>/i', $contents, $injects);
foreach($injects[0] as $row => $inject_tag) {
preg_match_all('/server=("[^"]*")/i',$inject_tag, $tag_src);
$codes = str_replace('"','', $tag_src[1][0]);
$codes = str_replace("'",'', $codes);
$codes = explode(',', $codes);
foreach($codes as $rowi => $thiscode) {
if ($_SERVER['SERVER_NAME'] == trim($thiscode) ||
$_SERVER['SERVER_ADDR'] == trim($thiscode) ) {
$contents = str_ireplace($injects[0][$row], '<unhost>', $contents);
}
}
}
$contents = preg_replace('/<host[^>]*>([\s\S]*?)<\/host[^>]*>/', '', $contents);
# Remove all <lock></lock> tags if no code provided
if (isset($_REQUEST['lock'])) {
$_SESSION['lock'] = $_REQUEST['lock'];
}
if (isset($_SESSION['lock'])) {
preg_match_all('/<lock[^>]+>/i', $contents, $injects);
foreach($injects[0] as $row => $inject_tag) {
preg_match_all('/code=("[^"]*")/i',$inject_tag, $tag_src);
$codes = str_replace('"','', $tag_src[1][0]);
$codes = str_replace("'",'', $codes);
$codes = explode(',', $codes);
foreach($codes as $rowi => $thiscode) {
if ($_SESSION['lock'] == trim($thiscode)) {
$contents = str_ireplace($injects[0][$row], '<unlock>', $contents);
}
}
}
}
if (!isset($INSTRUCTOR) || !$INSTRUCTOR) {
$unlocker = '
<div class="jumbotron">
<form method=POST>
<label for="input-group"><span style="color:blue">Enter Password to See Hidden Content</span></label>
<div class="input-group">
<input type="password" class="form-control" placeholder="" name="lock" id="lock">
<div class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-lock"></i></button>
</div>
</div>
</form>
</div>';
$contents = preg_replace('/<lock[^>]*>([\s\S]*?)<\/lock[^>]*>/', $unlocker, $contents);
}
# Search for student and instructor tags
$find_student = (strpos($contents, '<student>') > 0);
$find_instructor = (strpos($contents, '<inst>') > 0);
# Remove the contents of <student>...</student> tags if answers are to be hidden
if (!isset($_REQUEST['answers'])) {
$contents = preg_replace('/<student[^>]*>([\s\S]*?)<\/student[^>]*>/', '', $contents);
}
# Remove the student tag - in case it is used in problem sets
$contents = str_replace('<student>','',$contents);
$contents = str_replace('</student>','',$contents);
# Remove TABs, they are evil!
$contents = str_ireplace("\t", ' ', $contents);
# Search for editable code via ACE
# Example: <ace name="ace1" mode="html_elixir" height="48px" theme="tomorrow"></ace>
# Defaults show above