-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateSchedule.php
More file actions
836 lines (649 loc) · 23.8 KB
/
Copy pathgenerateSchedule.php
File metadata and controls
836 lines (649 loc) · 23.8 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
<?php
// Connects to the database
mysql_connect("127.0.0.1", "jakekra1_katie", "database238") or die(mysql_error());
mysql_select_db("jakekra1_katie") or die(mysql_error());
/**** Verify that you are logged in *****/
// Checks the cookie to be sure you are logged in
if(isset($_COOKIE['courseplanner_user'])) {
$username = $_COOKIE['courseplanner_user'];
$pass = $_COOKIE['courseplanner_key'];
$check = mysql_query("SELECT * FROM Student WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check )) {
// If the cookie has the wrong password, you are taken to the login page
if ($pass != $info['password']) {
header("Location: index.php");
}
}
}// If you are not logged in, you are redirected to the login screen
else {
header("Location: index.php");
}
// check database for username
$check = mysql_query("SELECT * FROM Student WHERE username='".strtolower($_COOKIE['courseplanner_user'])."';");
// username was not found
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
//header("Location: ./login.php?error=1");
die('That user does not exist in our database.');
}
$student = mysql_fetch_array( $check );
//while($info = mysql_fetch_array( $check )) {
// $info['password'] = stripslashes($info['password']);
//}
?>
<!-- Course Table -->
<SCRIPT LANGUAGE="JavaScript">
var classList = [];
var sectionList = [];
var schedule = [];
var scheduleList = [];
var scheduleIDList = [];
var coursesSelected = [];
var filteredSections = [];
var sTable, sTableBody;
var mainTableCreated = false;
var scheduleTableId = 0;
var daysOfWeek = ['M', 'T', 'W', 'R', 'F'];
var timeSlots = ["8:00", "9:00", "10:00", "11:00", "12:00", "1:00", "2:00", "3:00", "4:00", "5:00", "6:00"];
var colorTable = ["#75FF75", "#7575FF", "#FF7575", "#75FFFF", "#FFFF75", "#757575", "#BCA9F5","#FAAC58","#F781F3","#CCEEFF","#CCEE33"];
<?php
if (isSet($_GET['regenerate'])) {
// echo("printSchedules();");
}
?>
function writeClassList(text) {
classList.push(text);
document.getElementById("classListing").innerHTML = "";
for (i = 0; i < classList.length; i ++) {
document.getElementById("classListing").innerHTML += classList[i] + '<br>';
}
}
function writeSectionList(text) {
sectionList.push(text);
document.getElementById("sectionListing").innerHTML = "";
for (i = 0; i < sectionList.length; i ++) {
if(sectionList[i] == "space") { document.getElementById("sectionListing").innerHTML +='<br>';}
else{
document.getElementById("sectionListing").innerHTML += sectionList[i] + ' ';
}
}
}
function writeScheduleList(text) {
scheduleList.push(text);
document.getElementById("scheduleListing").innerHTML = "";
for (i = 0; i < scheduleList.length; i ++) {
document.getElementById("scheduleListing").innerHTML += scheduleList[i] + '<br>';
}
}
function writeScheduleIDList(text) {
scheduleIDList.push(text);
document.getElementById("scheduleIDListing").innerHTML = "";
for (i = 0; i < scheduleIDList.length; i ++) {
document.getElementById("scheduleIDListing").innerHTML += scheduleIDList[i] + '<br>';
}
}
function printSchedules(){
if (schedule.length > 0) {
<?php
/* if (isSet($_GET['regenerate'])) {
echo("window.location.href = window.location.href;");
}else {
echo("window.location.href = window.location.href + \"?regenerate=1\"");
}*/
?>
}
getCourses(<?php echo($student['studentID']); ?>);
}
// Selected courses
function getCourses(stuid) {
var xmlHttp = getXMLHttp();
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState == 4) {
HandleResponseGetCourses(xmlHttp.responseText);
}
}
// NOTICE cmd=getCourseNames
xmlHttp.open("GET", "databaseFunctions.php?cmd=getCourses&stuid=" + stuid, true);
xmlHttp.send(null);
}
// HANDLE RESPONSE getSelectedCourses
function HandleResponseGetCourses(response) {
//array returning courses listed in coursesSelected table
coursesSelected = (response.substring(0,response.length-1)).split(",");
if (coursesSelected.length == 0) return alert("There are no classes selected for generating a schedule.");
else if (coursesSelected.length == 1) return alert("Choose at least two classes for generating a schedule.");
// getFilteredSections(<?php echo($student['studentID']); ?>);
// alert(coursesSelected[0])
getSectionsWithFilter(<?php echo($student['studentID']); ?>);
}
// Get Sections to be remove
function getSectionsWithFilter(stuid) {
var xmlHttp = getXMLHttp();
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState == 4) {
HandleResponseGetSectionsWithFilter(xmlHttp.responseText);
}
}
// NOTICE cmd=getCourseNames
xmlHttp.open("GET", "databaseFunctions.php?cmd=getSectionsWithFilter&stuid=" + stuid, true);
xmlHttp.send(null);
}
// HANDLE RESPONSE getSections
function HandleResponseGetSectionsWithFilter(response) {
//temp = response.split("~");
response = response.substring(0, response.length -1);
// No Classes were selected
if (response.length <= 0) return alert("There are no classes selected for generating a schedule");
rtemp = response.split("~");
sectionsAvail = [];
for (j = 0; j < rtemp.length; j ++) {
rtempinner = rtemp[j].split(",");
if (sectionsAvail.indexOf(rtempinner[0]) < 0 && rtempinner[0].length > 1) {
sectionsAvail.push(rtempinner[0]);
sectionsAvail.push([]);
}
sectionsAvail[sectionsAvail.indexOf(rtempinner[0]) + 1].push(rtempinner[1].split("#"));
}
if ( (sectionsAvail.length / 2) < coursesSelected.length ) {
alert("No schedules can be created with the preferences you selected.")
return;
}
//alert(coursesSelected.length)
// return;
getSchedules();
}
// Creates array full of schedules determined by constraints
function getSchedules(){
temp1 = [];
temp2 = [];
schedule = [];
// Only 1 class selected
if (sectionsAvail.length <= 2) {
for (i = 0; i < sectionsAvail[1].length; i ++) {
schedule.push(sectionsAvail[1][i][0]);
}
return storeSchedule();
}
for (i = 0; i < sectionsAvail[1].length; i ++) {
for (j = 0; j < sectionsAvail[3].length; j ++) {
if (noConflict(sectionsAvail[1][i][0], sectionsAvail[3][j][0])) {
temp1.push([sectionsAvail[1][i][0], sectionsAvail[3][j][0]]);
}
}
}
// Only 2 classes selected
if (sectionsAvail.length <= 4) {
schedule = temp1.slice();
return storeSchedule();
}
var c = 0;
for (k = 5; k < sectionsAvail.length; k += 2) {
var z = 0;
for (i = 0; i < ((c%2) ? temp2.length : temp1.length); i ++) {
for (j = 0; j < sectionsAvail[k].length; j ++) {
if (!(c%2)) {
temp2[z] = temp1[i].slice();
check = true;
for (l = 0; l < temp2[z].length; l ++) {
check = noConflict(temp2[z][l], sectionsAvail[k][j][0]);
if ( !check) break;
}
if (check) {
temp2[z].push(sectionsAvail[k][j][0]);
}
} else {
temp1[z] = temp2[i].slice();
check = true;
for (l = 0; l < temp1[z].length; l ++) {
check = noConflict(temp1[z][l], sectionsAvail[k][j][0]);
if ( !check) break;
}
if (check) {
temp1[z].push(sectionsAvail[k][j][0]);
}
}
z ++;
}
}
if (!(c%2)) {
temp1 = [];
}else {
temp2 = [];
}
c ++;
}
tempschedule = ((c-1) % 2) ? temp1 : temp2;
for (i = 0; i < tempschedule.length; i ++) {
if (tempschedule[i].length != sectionsAvail.length / 2) continue;
schedule.push(tempschedule[i]);
}
if (schedule.length > 300){
alert(schedule.length + " schedules can be created from this set of selected courses. Select more preferences in order to narrow down your options.");
return;
}
storeSchedule();
}
// STORE SCHEDULE
function storeSchedule() {
// Remove previously stored schedules
removeAllSchedules();
// Add new Schedules
// If only one course exists in each schedule
if (schedule[0][0].length == 1) {
for (i = 0; i < schedule.length; i ++) {
insertSchedule( i, schedule[i], <?php echo($student['studentID']); ?> )
}
}
// Multiple courses per schedule
else{
for (i = 0; i < schedule.length; i ++) {
for (j = 0; j < schedule[i].length; j++)
{
insertSchedule( i, schedule[i][j], <?php echo($student['studentID']); ?> )
}
}
}
printNumSchedules( <?php echo($student['studentID']); ?>)
if (mainTableCreated) {
clearScheduleTable();
}else
generateTable();
}
function generateTable(){
// Create Larger Table
createScheduleTable();
sTable = document.getElementById("scheduleTable");
sTableBody = sTable.tBodies[0];
var newRow = sTable.insertRow(0);
var newCell = newRow.insertCell(0);
newCell.colSpan = "2";
newCell.innerHTML = '<center><font size = 6> Possible Schedules: ' + schedule.length + '<br><font size = 4>Select one to become your wish list.<br></font></center>'
for (g = 0; g < schedule.length; g ++) {
populateTable();
}
}
function createScheduleTable() {
// <TABLE border="1" id="scheduleDisplay" align="center" bgcolor="#FFFFFF" cellspacing="1" cellpadding="2" WIDTH="400">
var body = document.getElementById("scheduleDisplayContainer");
var tbl = document.createElement("table");
//tbl.id = "sTable" + scheduleTableId;
//tbl.align="center";
var tblBody = document.createElement("tbody");
//alert("created");
tbl.setAttribute("border", 1);
tbl.setAttribute("id", "scheduleDisplay");
tbl.setAttribute("align", "center");
tbl.setAttribute("width", 400);
mainTableCreated = true;
body.appendChild(tbl);
}
function clearScheduleTable() {
// alert("Clearing it " + document.getElementById("scheduleDisplay").parentNode);
var body = document.getElementById("scheduleDisplayContainer");
body.innerHTML = "";
// document.getElementById("scheduleDisplay").removeNode(true);
/*var body = document.getElementsByTagName('body')[0];
var el = document.getElementById("scheduleDisplay");
body.removeChild(el);*/
//alert("Clearing it2");
mainTableCreated = false;
/*
var table = document.getElementById("scheduleTable");
var tablebodies = table.getElementsByTagName('tbody');
var tablebodieslength = tablebodies.length;
alert("Size of table: " + tablebodieslength);
for (i = tablebodies.length-1; i > 0; i --) {
alert("removing row " + i);
var cell = tablebodies[i].parentNode;
while ( cell.childNodes.length >= 1 ) {
cell.removeChild( cell.firstChild );
}
//tablebodies[i].parentNode.removeChild(tablebodies[i]);
}
*/
/*
while (tablebodieslength > 0) {
tablebodieslength--;
alert("removing row " + tablebodieslength);
table.removeChild(tablebodies[0]);
}*/
/*
var cell = document.getElementById("scheduleTable");
if ( cell.hasChildNodes() ) {
while ( cell.childNodes.length >= 1 ) {
alert(cell.firstChild.className);
cell.removeChild( cell.firstChild );
}
}*/
}
function populateTable() {
sTable = document.getElementById("scheduleTable");
if (scheduleTableId%2 == 0){
var newRow = sTable.insertRow((scheduleTableId/2 + 1));
newRow.setAttribute("id", "schRow" + scheduleTableId + "-" + (scheduleTableId/2 + 1));
}else {
var newRow = document.getElementById("schRow" + (scheduleTableId-1) + "-" + ((scheduleTableId-1)/2 + 1));
}
var newCell = newRow.insertCell(scheduleTableId%2);
//newCell.innerHTML= numSchedules;
// get the reference for the body
// var body = document.getElementsByTagName("body")[0];
// creates a <table> element and a <tbody> element
var tbl = document.createElement("table");
//tbl.id = "sTable" + scheduleTableId;
//tbl.align="center";
var tblBody = document.createElement("tbody");
// MON - FRI ROW
var row = document.createElement("tr");
for (var i = 0; i < daysOfWeek.length+1; i ++) {
if (i == 0) {
var cell = document.createElement("td");
var cellText = document.createTextNode(scheduleTableId);
//cell.style.fontSize = "14px";
}else {
var cell = document.createElement("td");
var cellText = document.createTextNode(daysOfWeek[i-1]);
if (i == daysOfWeek.length) {
cell.style.borderRight="1px black solid";
}
}
cell.style.borderLeft="1px black solid";
cell.style.borderTop="1px black solid";
cell.style.borderBottom="1px black solid";
cell.style.textAlign="center";
cell.appendChild(cellText);
row.appendChild(cell);
}
tblBody.appendChild(row);
// creating all cells
for (var j = 0; j < timeSlots.length * 4 ; j++) {
// creates a table row
var row = document.createElement("tr");
// row.colSpan = "0";
for (var i = 0; i < daysOfWeek.length+1; i++) {
// Create a <td> element and a text node, make the text
// node the contents of the <td>, and put the <td> at
// the end of the table row
var cell = document.createElement("td");
if (i > 0) {
cell.setAttribute('name', 'sch' + ((j*daysOfWeek.length)+(i-1)));
cell.style.fontSize = "14px";
cell.style.fontWeight = "bold";
cell.style.borderLeft="1px black solid";
if (i == daysOfWeek.length) {
cell.style.borderRight="1px black solid";
}
var cellText = document.createTextNode("");
cell.innerHTML = "<div style=\"font-size:0%;\"> </div>";
//cell.style.fontSize = "1px";
if ((j+1) % 4 == 0) {
cell.style.borderBottom="1px black solid";
var cellText = document.createTextNode("");
//var cellText = document.createTextNode("cell: " + cell.getAttribute('name') + " " + tbl.id);
}
cell.appendChild(cellText);
row.appendChild(cell);
}else if (j % 4 == 0) {
var cell = document.createElement("td");
var cellText = document.createTextNode(timeSlots[Math.floor(j / 4)]);
cell.style.borderLeft="1px black solid";
cell.style.borderBottom="1px black solid";
cell.rowSpan = "4";
cell.appendChild(cellText);
row.appendChild(cell);
}
cell.style.textAlign="center";
cell.height = "1";
}
// add the row to the end of the table body
tblBody.appendChild(row);
}
// put the <tbody> in the <table>
tbl.appendChild(tblBody);
// appends <table> into <body>
// body.appendChild(tbl);
newCell.appendChild(tbl);
// sets the border attribute of tbl to 2;
tbl.setAttribute("border", "0");
tbl.setAttribute("cellpadding", "1");
tbl.setAttribute("cellspacing", "0");
tbl.setAttribute("width", "600");
tbl.setAttribute("height", "60");
//document.getElementsByName("sch"+(20+4))[0].style.backgroundColor = "#68EE68";
//document.getElementsByName("sch"+(20+4))[0].innerHTML = "hi";
//alert("hi1");
fillScheduleTable(scheduleTableId);
//alert("hi2");
// ADD BUTTON
// var button = '<img src="./select1.png" onMouseOver="this.src=\'./select2.png\'" onMouseOut="this.src=\'./select1.png\' ">';
//newCell.innerHTML = '<img src="./select1.png" onMouseOver="this.src=\'./select2.png\'" onMouseOut="this.src=\'./select1.png\' ">';
var selectBtn = document.createElement("IMG");
//selectBtn.setAttribute("align","bottom");
selectBtn.setAttribute("src","./select1.png");
selectBtn.setAttribute("onMouseOver","src=\'./select2.png\'");
selectBtn.setAttribute("onMouseOut","src=\'./select1.png\'");
selectBtn.setAttribute("onClick", "scheduleSelected(" + scheduleTableId + ");");
//selectBtn.setAttribute("id", numSchedules);
selectBtn.style.marginLeft = "244px";
//selectBtn.style.marginTop = "50px";
newCell.appendChild(selectBtn);
selectBtn.style.position = "relative";
selectBtn.style.verticalAlign = "bottom";
selectBtn.style.top = "0";
//var mybutton=document.createElement("BUTTON");
// mybutton.style.height=50;
//mybutton.style.width=200;
//mybutton.
//theText=document.createTextNode("Select");
//mybutton.appendChild(theText);
//mybutton.innerHTML ='<font size = 3>Select</font>'
scheduleTableId ++;
}
function scheduleSelected(tableid) {
confirm("Do you want to add Schedule #" + tableid + " with sections " + schedule[tableid] + " to your wish list?");
}
function getPosition(arrayName,arrayItem)
{
for(var i=0;i<arrayName.length;i++){
if(arrayName[i]==arrayItem)
return i;
}
}
/*
Array.prototype.position = function (s) {
var pos = 0;
while (pos < this.length && this [pos] != s) {pos++};
return pos < this.length ? pos : undefined;
}*/
function getSectionInfo(secid) {
var cid = secid - (secid % 100);
//return sectionsAvail[sectionsAvail.position(cid) + 1][secid % 100];
var tempinfo = sectionsAvail[getPosition(sectionsAvail, cid) + 1];
// alert(tempinfo);
var i;
for (i = 0; i < tempinfo.length; i ++) {
if (tempinfo[i][0] == secid) break;
}
// alert("cid is " + cid + " " + sectionsAvail + " +++ " + i);
return tempinfo[i];
}
//function roundTo(num,to) { // num is an exponent of 10
// return Math.round(info[2]/100)*100;
//}
function fillScheduleTable(schid) {
for (i = 0; i < schedule[schid].length; i ++) {
var info = getSectionInfo(schedule[schid][i]);
//var cNamePos = Math.floor(sectionsAvail.position(info[0] - (info[0]%100)) / 2);
var cNamePos = Math.floor(getPosition(sectionsAvail, (info[0] - (info[0]%100))) / 2);
var iName = getSectionInfo(schedule[schid][i])[6];
var sTime = getDisplayTime(getSectionInfo(schedule[schid][i])[1]);
var eTime = getDisplayTime(getSectionInfo(schedule[schid][i])[2]);
var location = getSectionInfo(schedule[schid][i])[4];
var cColor = colorTable[cNamePos];
var cName = coursesSelected[cNamePos];
// alert(coursesSelected[cInstructorPos]);
hourSegments = Math.floor((Math.round(info[2]/100)*100 - info[1]) / 25);
for (j = 0; j < hourSegments; j ++) {
stime = Math.round(info[1]) + (j*15)%60;
// adjust time
stime = (j*15)/60 >= 1 ? (stime + 100 * Math.floor((j*15)/60)) : stime;
for (k = 0; k < info[3].length; k ++) {
day = daysOfWeek.indexOf(info[3].substring(k, k+1));
getScheduleCell(schid, stime, day).style.backgroundColor = cColor;
switch (j) {
case 0:// Course Name
getScheduleCell(schid, stime, day).innerHTML = cName;
break;
case 1: // Time
getScheduleCell(schid, stime, day).innerHTML = sTime + " - " + eTime;
break;
case 2: // Instructor Name
getScheduleCell(schid, stime, day).innerHTML = iName;
break;
case 3: // Section Letter
getScheduleCell(schid, stime, day).innerHTML = location;
break;
}
}
}
}
}
//document.getElementsByName("sch"+(1*5))[scheduleTableId].innerHTML = "hi";
function getScheduleCell(schid, time, day) {
//alert("Getting " + time + " sch"+(20* (Math.floor((time-800)/100)) +day));
min = time % 100;
return document.getElementsByName( "sch" + (20 * (Math.floor((time-800)/100)) + ((min*100/60)/25)*5 + day))[schid];
}
// Count Schedules
function printNumSchedules(stuid) {
var xmlHttp = getXMLHttp();
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState == 4) {
HandleResponseCountSchedules(xmlHttp.responseText);
}
}
// NOTICE cmd=countCourseSelected
xmlHttp.open("GET", "databaseFunctions.php?cmd=countSchedules&stuid=" + stuid, true);
xmlHttp.send(null);
/// Change to numSchedules = Count(Rows in Schedule) / Count(Rows in courseSelected
}
// HANDLE RESPONSE Num Schedules
function HandleResponseCountSchedules(response) {
document.getElementById("numSchedules").innerHTML = response;
}
// INSERT into Schedule
function insertSchedule(schedID, secID, stuid) {
var xmlHttp = getXMLHttp();
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState == 4) {
HandleResponse(xmlHttp.responseText);
}
}
// NOTICE cmd=addSchedule to signify that we're adding
xmlHttp.open("GET", "databaseFunctions.php?cmd=addSchedule&schedID=" + schedID + "&secID=" + secID + "&stuid=" + stuid, true);
xmlHttp.send(null);
}
function removeAllSchedules(){
var xmlHttp = getXMLHttp();
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState == 4) {
HandleResponse(xmlHttp.responseText);
}
}
// NOTICE cmd=removeAllSchedule
xmlHttp.open("GET", "databaseFunctions.php?cmd=removeAllSchedules", true);
xmlHttp.send(null);
}
// Return true if no time conflict exists between the two sections
//function noConflict(i,j,k,m){
function noConflict(sec1,sec2){
var i,j,k,m;
outerloop:
for (i = 0; i < sectionsAvail.length; i ++) {
for (j = 0; j < sectionsAvail[i].length; j ++) {
if (sectionsAvail[i][j][0] == sec1) break outerloop;
}
}
outerloop2:
for (k = 0; k < sectionsAvail.length; k ++) {
for (m = 0; m < sectionsAvail[k].length; m ++) {
if (sectionsAvail[k][m][0] == sec2) break outerloop2;
}
}
s1 = sectionsAvail[i][j][1];
e1 = sectionsAvail[i][j][2];
s2 = sectionsAvail[k][m][1];
e2 = sectionsAvail[k][m][2];
//Compare Times
var noTimeConflict = ((e2 < s1) || (s2 > e1));
//Compare Days
var noDayConflict = true;
// Num chars in first section
var numDaysij= sectionsAvail[i][j][3].length;
var numDayskm= sectionsAvail[k][m][3].length;
for (var n = 0; n < numDaysij; n++) {
for (var p = 0; p < numDayskm;p++) {
if (sectionsAvail[k][m][3].substring(p,p+1) == sectionsAvail[i][j][3].substring(n,n+1)){
noDayConflict = false;
}
}
}
return (noDayConflict || noTimeConflict);
}
function getDisplayTime(time) {
dayTypes = ['AM', 'PM'];
var hour = Math.floor(time / 100) % 12;
hour = !hour ? 12:hour;
var min = time % 100 + dayTypes[Math.floor(time / 1200)];
if (time % 100 == 0) {
min = "00" + dayTypes[Math.floor(time / 1200)];
}
return hour + ':' + min;
}
// This is just an initialization function- do not edit.
function getXMLHttp() {
var xmlHttp
try {
//Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
}
catch(e) {
//Internet Explorer
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e) {
alert("Your browser does not support AJAX!")
return false;
}
}
}
return xmlHttp;
}
</SCRIPT>
<body>
<center>
<!-- Generate Schedules Button -->
<button type="button" id="newclassbutton" style="height: 40px; width: 400px" onclick="printSchedules();"><font size = "4">
Generate Schedules</button></font></center>
<br><br>
<div id="regText">
<?php
//if (isSet($_GET['regenerate'])) {
// echo("<div id=\"regText\"><h1><center>Regenerating list</center></h1></div>");
//}
?>
</div>
<!-- Holds all schedules-->
<TABLE border="0" id="scheduleTable" align="center" bgcolor="#FFFFFF" cellspacing="0" cellpadding="20">
</Table>
<br>
<br>
<div id="scheduleDisplayContainer">
</div>
<br><br><br><br>
</body>