-
Notifications
You must be signed in to change notification settings - Fork 0
/
clas_adm.php
3022 lines (2502 loc) · 102 KB
/
clas_adm.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
/**
* OVAL (Online Video Annotation for Learning) is a video annotation tool
* that allows users to make annotations on videos uploaded to the platform.
*
* Copyright (C) 2014 Shane Dawson, University of South Australia, Australia
* Copyright (C) 2014 An Zhao, University of South Australia, Australia
* Copyright (C) 2014 Dragan Gasevic, University of Edinburgh, United Kingdom
* Copyright (C) 2014 Neging Mirriahi, University of New South Wales, Australia
* Copyright (C) 2014 Abelardo Pardo, University of Sydney, Australia
* Copyright (C) 2014 Alan Kingstone, University of British Columbia, Canada
* Copyright (C) 2014 Thomas Dang, , University of British Columbia, Canada
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
// tdang 2013
// An ZHAO 2014
// OVAL SYSTEM ADMINISTRATION TOOL (for tech-adept admin users only,
// should be hidden from instructors and students)
$OVAL_ADM_TOOL_LAST_UPDATE = "Sept 07, 2013";
include_once(dirname(__FILE__) . "/includes/global_deploy_config.php");
include_once(dirname(__FILE__) . "/includes/common.inc.php");
include_once(dirname(__FILE__) . "/includes/auth.inc.php");
include_once(dirname(__FILE__) . "/database/users.php");
include_once("/var/www/config/clas/$configFolderName/db_config.php");
// TODO: refactor this authentication! It's quite ugly now.
$Jenny_hashed_id = "";
$Thomas_hashed_id = "";
$Joanna_hashed_id = "";
$Sharon_hashed_id = "";
// Extra students' hashed Id's
$yteststudent_hashed_id = "";
// Guess ID test - Using both the user name and the ID to hash is guaranteed to give uniqueness
$iteststu_guest_id = "";
$bteststu_basic_id = "";
// DEPLOY CONFIG: Who has access to the sysadmin tool
$hashedCurrentUser = getCurrentHashedUId();
if ($DEPLOYMENT_NAME == "prod") {
if (
$hashedCurrentUser != $Jenny_hashed_id &&
$hashedCurrentUser != $Thomas_hashed_id
) {
notAuthorized();
}
} else if ($DEPLOYMENT_NAME == "dev") {
if (
$hashedCurrentUser != $Thomas_hashed_id
) {
notAuthorized();
}
} else if ($DEPLOYMENT_NAME == "demo") {
if (
$hashedCurrentUser != $Jenny_hashed_id &&
$hashedCurrentUser != $Thomas_hashed_id
) {
// notAuthorized();
}
} else if ($DEPLOYMENT_NAME == "medclas") {
if (
/* $hashedCurrentUser != $Joanna_hashed_id && */
$hashedCurrentUser != $Jenny_hashed_id &&
$hashedCurrentUser != $Thomas_hashed_id
) {
notAuthorized();
}
} else if ($DEPLOYMENT_NAME == "educ") {
if (
$hashedCurrentUser != $Jenny_hashed_id &&
$hashedCurrentUser != $Thomas_hashed_id &&
$hashedCurrentUser != $Sharon_hashed_id
) {
notAuthorized();
}
}
// Choose the theme color for the interface so that it's harder to confuse between instances
$themeColor = "#FFFFFF";
if ($DEPLOYMENT_NAME == "prod") {
$themeColor = "rgb(50,50,50)";
} else if ($DEPLOYMENT_NAME == "dev") {
$themeColor = "rgb(218,226,233)";
} else if ($DEPLOYMENT_NAME == "demo") {
$themeColor = "rgb(255,226,233)";
} else if ($DEPLOYMENT_NAME == "medclas") {
$themeColor = "rgb(150,150,255)";
} else if ($DEPLOYMENT_NAME == "educ") {
$themeColor = "rgb(218,255,233)";
}
// SIS access is limited by departments to the course codes relevant to them only
$allowedCourseCode = array("EVERY");
if ($DEPLOYMENT_NAME == "prod") {
$allowedCourseCode = array("EVERY");
} else if ($DEPLOYMENT_NAME == "dev") {
$allowedCourseCode = array("EVERY");
} else if ($DEPLOYMENT_NAME == "demo") {
$allowedCourseCode = array("EVERY");
} else if ($DEPLOYMENT_NAME == "medclas") {
$allowedCourseCode = array("EVERY"); // limit access of tool to Arts LC only until has course list
} else if ($DEPLOYMENT_NAME == "educ") {
$allowedCourseCode = array(
"ADHE",
"CCFI",
"CNPS",
"ECED",
"EDCP",
"EDST",
"EDUC",
"EPSE",
"ETEC",
"KIN",
"LIBE",
"LLED"
);
}
// Default CSV/NSV text area content, contains instructions
$DEFAULT_TEXTAREA_CONTENT = "Paste student list from spreadsheet or Connect (which is normally comma or newline separated) here.";
$DEFAULT_TEXTAREA_CONTENT_DROP_NOTE = "\n\nNote: only for Drop, put \"EVERYONE\" or \"everyone\" to drop the whole class and resets all groups.";
// connect to db
$dbConnection = mysql_connect('localhost', $mysqlUser, $mysqlPassword);
if (!$dbConnection)
die('could not connect: ' . mysql_error());
mysql_select_db($database) or die(mysql_error());
$classes = getCourses($dbConnection);
$className = "uninitialized";
$classID = "uninitialized";
$session = "uninitialized";
$department = "uninitialized";
$courseNo = "uninitialized";
$sectionNo = "uninitialized";
$season = "uninitialized";
$command = "uninitialized";
$commandState = "uninitialized";
class CommandStates
{
const Preview = 0;
const Execute = 1;
const PreviewThenExecute = 2;
const Error = 3;
}
class Commands
{
// Imports replace the class list entirely with the new list
const ImportFromSIS = 0; // DONE!
const ImportFromCSV = 1; // DONE!
// Add and drop are exactly what it says, adding and dropping users, skip if already enrolled
const AddFromCSV = 2; // DONE!
const DropFromCSV = 3; // DONE!
// Check enroll
const CheckEnroll = 4; // NO NEED FOR NOW
// Create Course merely creates a course shell, you must now run
// import from SIS or import from CSV later to fill
const CreateCourse = 5; // DONE!
const RemoveCourse = 6; // DONE!
const CleanAnnotations = 7; // DONE!
const UnassignVideos = 8;
const CheckLogin = 9; // NO NEED FOR NOW
const CheckVideoQuota = 10; // NO NEED FOR NOW
const ArchiveOldCourse = 11; // DONE
}
if (array_key_exists("bulkImportEnrollment", $_POST)) {
if ($_POST['import_source'] == "sis") {
handleImportFromSIS();
} else if ($_POST['import_source'] == "csv") {
handleImportFromCSVorNSV();
}
} else if (array_key_exists("importFromCSV", $_POST)) {
handleImportFromCSVorNSV();
} else if (array_key_exists("addFromCSV", $_POST)) {
handleAddFromCSV();
} else if (array_key_exists("dropFromCSV", $_POST)) {
handleDropFromCSV();
} else if (array_key_exists("checkEnroll", $_POST)) {
handleCheckEnroll();
} else if (array_key_exists("createCourse", $_POST)) {
handleCreateCourse();
} else if (array_key_exists("removeCourse", $_POST)) {
handleRemoveCourse();
} else if (array_key_exists("cleanAnnotations", $_POST)) {
handleCleanAnnotations();
} else if (array_key_exists("archiveOldCourse", $_POST)) {
handleArchiveOldCourse();
} else {
// shows the starting UI;
}
function populateCourseInfoFromPOST()
{
global $classID, $className, $classes, $department, $courseNo, $sectionNo, $command, $commandState;
global $session, $season;
// Search for the className, and then figure out department, courseNo, and sectionNo from that
if (array_key_exists('class', $_POST)) {
$classID = $_POST['class'];
// search for the ID of selected class, then get the name
foreach ($classes as $ID => $name) {
if ($ID == $classID)
$className = $name;
}
// ARTH100_001_2013W
// dept code is fixed to 4 chars
$department = substr($className, 0, 4);
$firstUnderscorePos = strpos($className, "_");
// fetch up to '_'
$courseNo = substr($className, 4, $firstUnderscorePos - 4);
$secondUnderscorePos = strpos($className, "_", $firstUnderscorePos + 1);
if ($secondUnderscorePos) {
$sectionNo = substr($className, $firstUnderscorePos + 1, $secondUnderscorePos - ($firstUnderscorePos + 1));
$sessionAndSeason = substr($className, $secondUnderscorePos + 1);
$sessionInName = substr($sessionAndSeason, 0, 4);
$seasonInName = substr($sessionAndSeason, 4);
if ($sessionInName != $session || $seasonInName != $season) {
if ($command == Commands::ImportFromSIS) {
print("<br/><span style=\"color:blue;font-weight:bold\">
WARNING! The Year or Season in the course name is different from the Year or Season of the command<br/>
Is this intentional? Please doublecheck before proceeding.<br/>
</span>
<br/>");
}
}
} else {
$sectionNo = substr($className, $firstUnderscorePos + 1);
}
}
// Override deparment, courseNo, and sectionNo if these are explicitly defined in the form submit
if (array_key_exists('department', $_POST)) {
$department = $_POST['department'];
}
if (array_key_exists('courseNo', $_POST)) {
$courseNo = $_POST['courseNo'];
}
if (array_key_exists('sectionNo', $_POST)) {
$sectionNo = $_POST['sectionNo'];
}
if ($className == "uninitialized") {
$className = getCourseName($department, $courseNo, $sectionNo);
}
}
// Take a textArea with comma or newline separated values, returning an array
function UTIL_textArea2Array($textAreaContent, $stripSpaces = true, $encryptionSafeParse = false)
{
if ($encryptionSafeParse) {
$stripSpaces = false;
}
// trim it or strip it
if (!$stripSpaces) {
$textAreaContent = trim($textAreaContent);
} else {
$textAreaContent = str_replace(' ', '', $textAreaContent);
}
// determine (in a semi-flexible way) whether to parse by newlines or by comma
$newlinesCount = substr_count($textAreaContent, "\n");
$commasCount = substr_count($textAreaContent, ",");
if ($newlinesCount > $commasCount) {
$csvArray = explode("\n", $textAreaContent);
} else {
$csvArray = explode(",", $textAreaContent);
}
// clean up the individual strings in this array
$csvArrayCleaned = array();
if (!empty($csvArray)) {
$csvListCount = count($csvArray);
for ($i = 0; $i < $csvListCount; $i++) {
$csvArray[$i] = trim($csvArray[$i]);
if (!$encryptionSafeParse) {
$csvArray[$i] = trim($csvArray[$i], "\"\'");
}
if (!is_null($csvArray[$i]) && strlen($csvArray[$i]) > 0) {
$csvArrayCleaned[] = $csvArray[$i];
}
}
}
return $csvArrayCleaned;
}
function handleImportFromCSVorNSV()
{
global $classID, $className, $classes, $configFolderName, $dbConnection;
global $session, $department, $courseNo, $sectionNo, $season, $yteststudent_hashed_id;
global $command, $commandState;
global $DEFAULT_TEXTAREA_CONTENT;
// get the command itself
$command = Commands::ImportFromCSV;
// get the state of the command
if (array_key_exists("execute", $_POST)) {
$commandState = CommandStates::Execute;
} else if (array_key_exists("previewThenExecute", $_POST)) {
$commandState = CommandStates::PreviewThenExecute;
} else {
$commandState = CommandStates::Preview;
}
printOutputPageHeading($commandState);
$fatalError = false;
// session and season must be present for all update commands, complain bitterly if they aren't there.
if (array_key_exists('session', $_POST) && array_key_exists('season', $_POST)) {
$session = $_POST['session'];
$season = $_POST['season'];
populateCourseInfoFromPOST();
printCourseInfo(
$commandState,
$className,
$configFolderName,
$session,
$department,
$courseNo,
$sectionNo,
$season
);
if (array_key_exists('csvStudentList', $_POST)) {
$csvStudentList = $_POST['csvStudentList'];
} else if (array_key_exists('import_source_csv_textarea', $_POST)) {
$csvStudentList = $_POST['import_source_csv_textarea'];
} else {
print("<br/><span style=\"color:red;font-weight:bold\">
FATAL ERROR! hidden or textarea CSV input missing. You have found a bug.<br/>
Please email [email protected] with as much info as possible of the context when this error appears.<br/>
</span>
<br/>");
$fatalError = true;
}
if (trim($csvStudentList) == trim($DEFAULT_TEXTAREA_CONTENT)) {
$csvStudentList = "";
}
if (!$fatalError) {
$csvStudentListArray = UTIL_textArea2Array($csvStudentList);
// clean up the individual strings in this array
if (!empty($csvStudentListArray)) {
// Hand over to the next stage of the import!
updateClassEnrollment($classID, $dbConnection, $command, $commandState, $csvStudentListArray);
} else {
print("<br/><span style=\"color:red;font-weight:bold\">
FATAL ERROR! The student list being imported has no students.<br/>
</span>
<br/>");
}
}
} else {
print("<br/><span style=\"color:red;font-weight:bold\">
FATAL ERROR! SessionYear or Season input missing. You have found a bug.<br/>
Please email [email protected] with as much info as possible of the context when this error appears.<br/>
</span>
<br/>");
}
printOutputPageFooting($commandState, $className);
}
function handleArchiveOldCourse()
{
global $classID, $className, $classes, $configFolderName, $dbConnection;
global $session, $department, $courseNo, $sectionNo, $season;
global $yteststudent_hashed_id, $iteststu_guest_id, $bteststu_basic_id;
global $command, $commandState;
// get the command itself
$command = Commands::ArchiveOldCourse;
// get the state of the command
if (array_key_exists("execute", $_POST)) {
$commandState = CommandStates::Execute;
} else if (array_key_exists("previewThenExecute", $_POST)) {
$commandState = CommandStates::PreviewThenExecute;
} else {
$commandState = CommandStates::Preview;
}
printOutputPageHeading($commandState);
if (!empty($_POST)) {
// reading and checking params for the command
if (!(array_key_exists('session', $_POST) && array_key_exists('season', $_POST))) {
$errors .= "Fatal Error: Session Year or Season is empty. This may be a bug<br/><br/>";
} else {
$session = $_POST['session'];
$season = $_POST['season'];
}
populateCourseInfoFromPOST();
printCourseInfo(
$commandState,
$className,
$configFolderName,
$session,
$department,
$courseNo,
$sectionNo,
$season
);
$errors = array();
$nothingToDo = false;
if (empty($errors)) {
if (!$nothingToDo) {
if ($commandState == CommandStates::Execute || $commandState == CommandStates::PreviewThenExecute) {
print "<div style=\"min-width:1024px;text-align:center;font-size:75%\">";
print "<div style=\"margin-left:auto;margin-right:auto;border:1px solid gray;height:200px;width:1030px;white-space:pre-wrap;overflow:scroll;\">";
UTIL_archivePreviousTermCourse($classID, $dbConnection);
print "</div></div>";
print("<br/><b>STOP! Please check the database query outputs to make sure that everything is
<span style=\"color:green;\">green</span>
before finishing.
</b><br/>");
print("<br/><span style=\"color:blue;font-weight:bold;\">
If you are archiving a course as preparation for a new term, you might also want to recreate this course name.
</span>
<br/><br/>");
printOutputPageFooting(CommandStates::Execute, $className);
} else if ($commandState == CommandStates::Preview) {
printExecuteArchiveOldCourseForm($classID, $session, $season, "Go Ahead and Execute the Course Archival");
printOutputPageFooting(CommandStates::Preview, $className);
}
} else {
printOutputPageFooting(CommandStates::Preview, $className);
}
} else {
print "$errors";
printOutputPageFooting(CommandStates::Error, $className);
}
} else {
print("<br/><span style=\"color:red;font-weight:bold\">
FATAL ERROR! POST parameter list empty. You may have found a bug.<br/>
Please email [email protected] with as much info as possible of the context when this error appears.<br/>
</span>
<br/>");
printOutputPageFooting(CommandStates::Error, $className);
}
}
function handleCleanAnnotations()
{
global $classID, $className, $classes, $configFolderName, $dbConnection;
global $session, $department, $courseNo, $sectionNo, $season;
global $yteststudent_hashed_id, $iteststu_guest_id, $bteststu_basic_id;
global $command, $commandState;
// get the command itself
$command = Commands::CleanAnnotations;
// get the state of the command
if (array_key_exists("execute", $_POST)) {
$commandState = CommandStates::Execute;
} else if (array_key_exists("previewThenExecute", $_POST)) {
$commandState = CommandStates::PreviewThenExecute;
} else {
$commandState = CommandStates::Preview;
}
printOutputPageHeading($commandState);
if (!empty($_POST)) {
// reading and checking params for the command
if (!(array_key_exists('session', $_POST) && array_key_exists('season', $_POST))) {
$errors .= "Fatal Error: Session Year or Season is empty. This may be a bug<br/><br/>";
} else {
$session = $_POST['session'];
$season = $_POST['season'];
}
populateCourseInfoFromPOST();
printCourseInfo(
$commandState,
$className,
$configFolderName,
$session,
$department,
$courseNo,
$sectionNo,
$season
);
$media = new media();
$annotationsDB = new annotationsDB();
$nothingToDo = false;
$oldAnnotationsAndComments = array();
$videosInCourse = $media->getVideosByClassID($classID);
if (!empty($videosInCourse)) {
$videosInCourseCount = count($videosInCourse);
foreach ($videosInCourse as $video) {
$videosInCourseText[] = "ID:" . $video['video_id'] . " Title:\"" . $video['title'] . "\" Length:" . $video['duration'] . "\n";
$oldAnnotationCollections[] = $annotationsDB->getAnnotations($video['video_id'], null, true, ALL);
}
foreach ($oldAnnotationCollections as $annotationCollection) {
if (!empty($annotationCollection)) {
foreach ($annotationCollection as $annotation) {
$oldAnnotationsAndComments[] = $annotation;
}
}
}
if ($commandState == CommandStates::Preview) {
print "<br/><b>There are $videosInCourseCount videos in course $className.</b><br/>";
DEBUG_printSimpleArray($videosInCourseText, 8, 70, "\n");
print "<br/>";
}
print "<br/>";
if (empty($oldAnnotationsAndComments)) {
print "<b>There is no active annotations and general comments in this course. Nothing to do.</b><br/><br/>";
$nothingToDo = true;
} else {
$oldAnnotationsAndCommentsCount = count($oldAnnotationsAndComments);
if ($commandState == CommandStates::Preview) {
print "<b>There are $oldAnnotationsAndCommentsCount annotations and general comments
for $videosInCourseCount VIDEOs in course $className. Please verify before deleting.</b><br/>";
print "<div style=\"min-width:1024px;text-align:center;font-size:75%\">";
print "<div style=\"margin-left:auto;margin-right:auto;border:1px solid gray;height:200px;width:1030px;white-space:pre-wrap;overflow:scroll;\">";
foreach ($oldAnnotationsAndComments as $annotation) {
if (!is_null($annotation)) {
if ($annotation['is_private'] == 0) {
print "Annotation ID " . $annotation['annotation_id'] . " User " .
$annotation['user_name'] . " Date " . $annotation['creation_date'] .
" Content '" . $annotation['description'] . "' Tags '" .
$annotation['tags']
/* . " is_private " . $annotation['is_private'] */
;
}
} else {
print "<span style=\"color:red\">null entry. Could be a bug.</span>";
}
print "<br/>";
}
print "</div></div>";
}
}
} else {
print "<b>There is no videos in this course yet. Nothing to do.</b><br/><br/>";
$nothingToDo = true;
}
if (empty($errors)) {
if (!$nothingToDo) {
if ($commandState == CommandStates::Execute || $commandState == CommandStates::PreviewThenExecute) {
print "<div style=\"min-width:1024px;text-align:center;font-size:75%\">";
print "<div style=\"margin-left:auto;margin-right:auto;border:1px solid gray;height:200px;width:1030px;white-space:pre-wrap;overflow:scroll;\">";
foreach ($oldAnnotationsAndComments as $annotation) {
$annotationID = $annotation['annotation_id'];
$result = $annotationsDB->deleteAnnotation($annotationID);
UTIL_printQueryResultNicely("delete annotation " . $annotationID, $result, $dbConnection);
}
if (empty($oldAnnotationsAndComments)) {
print "???";
}
print "</div></div>";
print("<br/><b>STOP! Please check the database query outputs to make sure that everything is
<span style=\"color:green;\">green</span>
before finishing.
</b><br/>");
print("<br/><span style=\"color:blue;font-weight:bold;\">
If you are cleaning annotations for a new term (so that you can reuse the same videos in a course)<br/>
You might also want to update the enrollment list afterward.
</span>
<br/><br/>");
printOutputPageFooting(CommandStates::Execute, $className);
} else if ($commandState == CommandStates::Preview) {
printExecuteRemoveAnnotationsForm($classID, $session, $season, "Go Ahead and Execute the Annotations Removal");
printOutputPageFooting(CommandStates::Preview, $className);
}
} else {
printOutputPageFooting(CommandStates::Preview, $className);
}
} else {
print "$errors";
printOutputPageFooting(CommandStates::Error, $className);
}
$media->close();
$annotationsDB->close();
} else {
print("<br/><span style=\"color:red;font-weight:bold\">
FATAL ERROR! POST parameter list empty. You may have found a bug.<br/>
Please email [email protected] with as much info as possible of the context when this error appears.<br/>
</span>
<br/>");
printOutputPageFooting(CommandStates::Error, $className);
}
}
function handleAddFromCSV()
{
global $classID, $className, $classes, $configFolderName, $dbConnection;
global $session, $department, $courseNo, $sectionNo, $season;
global $yteststudent_hashed_id, $iteststu_guest_id, $bteststu_basic_id;
global $command, $commandState;
global $DEFAULT_TEXTAREA_CONTENT;
// get the command itself
$command = Commands::AddFromCSV;
// get the state of the command
if (array_key_exists("execute", $_POST)) {
$commandState = CommandStates::Execute;
} else if (array_key_exists("previewThenExecute", $_POST)) {
$commandState = CommandStates::PreviewThenExecute;
} else {
$commandState = CommandStates::Preview;
}
printOutputPageHeading($commandState);
if (!empty($_POST)) {
// session and season must always be there
if (!(array_key_exists('session', $_POST) && array_key_exists('season', $_POST))) {
$errors .= "Fatal Error: Session Year or Season is empty. This may be a bug<br/><br/>";
} else {
$session = $_POST['session'];
$season = $_POST['season'];
}
populateCourseInfoFromPOST();
printCourseInfo(
$commandState,
$className,
$configFolderName,
$session,
$department,
$courseNo,
$sectionNo,
$season
);
$instructorIDs = $_POST['instructor_id'];
$taIDs = $_POST['TA_ids'];
$csvStudentList = $_POST['add_users_textarea'];
if (trim($csvStudentList) == trim($DEFAULT_TEXTAREA_CONTENT)) {
$csvStudentList = "";
}
$encryptionSafeParse = ($commandState != CommandStates::Preview) ? true : false;
// validate inputs
if (!empty($instructorIDs)) {
$instructorIDs = UTIL_textArea2Array($instructorIDs, true, $encryptionSafeParse);
}
if (!empty($taIDs)) {
$taIDs = UTIL_textArea2Array($taIDs, true, $encryptionSafeParse);
}
if (!empty($csvStudentList)) {
$csvStudentListArray = UTIL_textArea2Array($csvStudentList, true, $encryptionSafeParse);
}
if ($commandState == CommandStates::Preview) {
print "<br/>";
print "<b>Original Input Lists (unencrypted)</b><br/>";
print "<div style=\"min-width:790px;text-align:center;font-size:75%\">";
print "<div style=\"margin-left:auto;margin-right:auto;border:1px solid gray;height:100px;width:800px;white-space:pre-wrap;overflow:scroll;\">";
print "Instructors: " . implode(", ", $instructorIDs) .
"<br/>TA's: " . implode(", ", $taIDs) .
"<br/>Students: " . implode(", ", $csvStudentListArray);
print "</div></div><br/>";
}
if ($commandState == CommandStates::Preview) {
foreach ($instructorIDs as $ID) {
$hashedInstructorIDs[] = hashUserID($ID);
}
foreach ($taIDs as $ID) {
$hashedTAIDs[] = hashUserID($ID);
}
$oldHashedInstructors = getInstructorsInClass_FROM_OVAL_DB($classID, $dbConnection);
$oldHashedTAs = getTAsInClass_FROM_OVAL_DB($classID, $dbConnection);
$alreadyExistingInstructors = array_intersect($hashedInstructorIDs, $oldHashedInstructors);
$alreadyExistingTAs = array_intersect($hashedTAIDs, $oldHashedTAs);
$alreadyExistingInstructorsCount = count($alreadyExistingInstructors);
$alreadyExistingTAsCount = count($alreadyExistingTAs);
foreach ($csvStudentListArray as $studentID) {
$csvStudentListArrayHashed[] = hashUserID($studentID);
}
$oldHashedStudents = getStudentsInClass_FROM_OVAL_DB($classID, $dbConnection);
$oldHashedStudents = (is_null($oldHashedStudents)) ? array() : $oldHashedStudents;
$oldHashedInstructors = (is_null($oldHashedInstructors)) ? array() : $oldHashedInstructors;
$oldHashedTAs = (is_null($oldHashedTAs)) ? array() : $oldHashedTAs;
// Creating the final lists!
$instructorsToAdd = array_diff($hashedInstructorIDs, $oldHashedInstructors);
$tasToAdd = array_diff($hashedTAIDs, $oldHashedTAs);
$studentsToAdd = array_diff($csvStudentListArrayHashed, $oldHashedStudents);
} else {
// In execute mode, the $_POST lists come pre-vetted and pre-hashed, so just use them!
$instructorsToAdd = $instructorIDs;
$tasToAdd = $taIDs;
$studentsToAdd = $csvStudentListArray;
}
if ($commandState == CommandStates::Preview) {
print "<b>There are $alreadyExistingInstructorsCount instructors in the new list that is already in the course.</b><br/>";
print "<b>There are $alreadyExistingTAsCount TAs in the new list that is already in the course.</b><br/>";
}
if ($commandState == CommandStates::Preview) {
print "<br/>";
print "<b>Final (encrypted) list of instructors to be added:</b><br/>";
DEBUG_printSimpleArray($instructorsToAdd);
print "<br/><br/>";
print "<b>Final (encrypted) list of TA's to be added:</b><br/>";
DEBUG_printSimpleArray($tasToAdd);
print "<br/><br/>";
}
if ($commandState == CommandStates::Preview) {
if (empty($oldHashedStudents)) {
print "<b>Existing Student Check: This is a course shell without any students. Safe to add!</b><br/><br/>";
} else {
$alreadyEnrolled = array_intersect($csvStudentListArrayHashed, $oldHashedStudents);
$alreadyEnrolledCount = count($alreadyEnrolled);
print "<b>There are $alreadyEnrolledCount students in the new list that is already in the course.</b><br/>";
if ($alreadyEnrolledCount != 0) {
DEBUG_printSimpleArray($alreadyEnrolled);
print "<br/>";
}
print "<br/>";
}
}
if ($commandState == CommandStates::Preview) {
$studentsToAddCount = count($studentsToAdd);
print "<b>Final (encrypted) list of students to be added: $studentsToAddCount students.</b><br/>";
DEBUG_printSimpleArray($studentsToAdd);
print "<br/>";
}
if (empty($errors)) {
if ($commandState == CommandStates::Execute || $commandState == CommandStates::PreviewThenExecute) {
print "<b>Adding Instructors and TA's</b><br/>";
print "<div style=\"min-width:1024px;text-align:center;font-size:75%\">";
print "<div style=\"margin-left:auto;margin-right:auto;border:1px solid gray;height:200px;width:1030px;white-space:pre-wrap;overflow:scroll;\">";
$instructorsOVALIDs = array();
$tasOVALIDs = array();
if (!empty($instructorsToAdd)) {
$instructorsOVALIDs = createUsers($instructorsToAdd, INSTRUCTOR, $dbConnection, true);
UTIL_setDefaultUISettings($instructorsOVALIDs);
}
if (!empty($tasToAdd)) {
$tasOVALIDs = createUsers($tasToAdd, TA, $dbConnection, true);
UTIL_setDefaultUISettings($tasOVALIDs);
}
addInstructorAndTAs($classID, $instructorsOVALIDs, $tasOVALIDs, $dbConnection);
UTIL_addToEveryoneGroup($instructorsOVALIDs, $classID, $dbConnection, INSTRUCTOR);
UTIL_addToInstructorAndTAGroup($instructorsOVALIDs, $classID, $dbConnection, INSTRUCTOR);
UTIL_addToEveryoneGroup($tasOVALIDs, $classID, $dbConnection, TA);
UTIL_addToInstructorAndTAGroup($tasOVALIDs, $classID, $dbConnection, TA);
print "</div></div><br/><br/>";
print "<b>Adding Students</b><br/>";
print "<div style=\"min-width:1024px;text-align:center;font-size:75%\">";
print "<div style=\"margin-left:auto;margin-right:auto;border:1px solid gray;height:200px;width:1030px;white-space:pre-wrap;overflow:scroll;\">";
$studentsOVALIDs = array();
if (!empty($studentsToAdd)) {
$studentsOVALIDs = createUsers($studentsToAdd, STUDENT, $dbConnection, true);
UTIL_setDefaultUISettings($studentsOVALIDs);
}
addStudents($classID, $studentsOVALIDs, $dbConnection);
UTIL_addToEveryoneGroup($studentsOVALIDs, $classID, $dbConnection);
print "</div></div><br/><br/>";
print("<b>STOP! Please check the database query outputs to make sure that everything is
<span style=\"color:green;\">green</span>
before finishing.
</b><br/><br/>");
printOutputPageFooting(CommandStates::Execute, $className);
} else if ($commandState == CommandStates::Preview) {
if (!empty($instructorsToAdd) || !empty($tasToAdd) || !empty($studentsToAdd)) {
printExecuteAddFromCSVForm(
$classID,
$session,
$season,
"Go Ahead and Execute the User Additions",
$instructorsToAdd,
$tasToAdd,
$studentsToAdd
);
} else {
print("<br/><span style=\"color:blue;font-weight:bold\">
STOP! All drop lists seem to be empty. There appears to be nothing to do.
</span>
<br/>");
}
printOutputPageFooting(CommandStates::Preview);
}
} else {
print "$errors";
printOutputPageFooting(CommandStates::Error, $className);
}
} else {
print("<br/><span style=\"color:red;font-weight:bold\">
FATAL ERROR! POST parameter list empty. You may have found a bug.<br/>
Please email [email protected] with as much info as possible of the context when this error appears.<br/>
</span>
<br/>");
printOutputPageFooting(CommandStates::Error);
}
}
function handleDropFromCSV()
{
global $classID, $className, $classes, $configFolderName, $dbConnection;
global $session, $department, $courseNo, $sectionNo, $season;
global $yteststudent_hashed_id, $iteststu_guest_id, $bteststu_basic_id;
global $command, $commandState;
global $DEFAULT_TEXTAREA_CONTENT;
global $DEFAULT_TEXTAREA_CONTENT_DROP_NOTE;
// get the command itself
$command = Commands::DropFromCSV;
// get the state of the command
if (array_key_exists("execute", $_POST)) {
$commandState = CommandStates::Execute;
} else if (array_key_exists("previewThenExecute", $_POST)) {
$commandState = CommandStates::PreviewThenExecute;
} else {
$commandState = CommandStates::Preview;
}
printOutputPageHeading($commandState);
if (!empty($_POST)) {
// session and season must always be there
if (!(array_key_exists('session', $_POST) && array_key_exists('season', $_POST))) {
$errors .= "Fatal Error: Session Year or Season is empty. This may be a bug<br/><br/>";
} else {
$session = $_POST['session'];
$season = $_POST['season'];
}
populateCourseInfoFromPOST();
printCourseInfo(
$commandState,
$className,
$configFolderName,
$session,
$department,
$courseNo,
$sectionNo,
$season
);
$instructorIDs = $_POST['instructor_id'];
$taIDs = $_POST['TA_ids'];
$csvStudentList = $_POST['drop_users_textarea'];
// Handle special cases
if (strpos(trim($csvStudentList), trim($DEFAULT_TEXTAREA_CONTENT)) != false) {
$csvStudentList = "";
}
$dropAllStudents = false;
if (strtoupper(trim($csvStudentList)) == "EVERYONE") {
$dropAllStudents = true;
}
$encryptionSafeParse = ($commandState != CommandStates::Preview) ? true : false;
// validate inputs
if (!empty($instructorIDs)) {
$instructorIDs = UTIL_textArea2Array($instructorIDs, true, $encryptionSafeParse);
}
if (!empty($taIDs)) {
$taIDs = UTIL_textArea2Array($taIDs, true, $encryptionSafeParse);
}
if (!empty($csvStudentList)) {
$csvStudentListArray = UTIL_textArea2Array($csvStudentList, true, $encryptionSafeParse);
}
if ($commandState == CommandStates::Preview) {
print "<br/>";
print "<b>Original Input Lists (unencrypted)</b><br/>";
print "<div style=\"min-width:790px;text-align:center;font-size:75%\">";
print "<div style=\"margin-left:auto;margin-right:auto;border:1px solid gray;height:100px;width:800px;white-space:pre-wrap;overflow:scroll;\">";
print "Instructors: " . implode(", ", $instructorIDs) .
"<br/>TA's: " . implode(", ", $taIDs) .
"<br/>Students: " . implode(", ", $csvStudentListArray);
print "</div></div><br/>";
}
if ($commandState == CommandStates::Preview) {
foreach ($instructorIDs as $ID) {
$hashedInstructorIDs[] = hashUserID($ID);
}