-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabaseFunctions.php
More file actions
394 lines (305 loc) · 14.4 KB
/
databaseFunctions.php
File metadata and controls
394 lines (305 loc) · 14.4 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
<?php
$cmd = $_GET['cmd'];
$params = array(
"cid" => $_GET["cid"],
"stuid" => $_GET["stuid"],
"schedID" => $_GET["schedID"],
"secID" => $_GET["secID"],
"startTime" => $_GET["startTime"],
"endTime" => $_GET["endTime"],
"days" => $_GET["days"]
);
$type = $_GET['type'];
// Connects to the database
$connection = mysql_connect("127.0.0.1", "jakekra1_katie", "database238") or die(mysql_error());
mysql_select_db("jakekra1_katie") or die(mysql_error());
if ($cmd == "addCourseSelected") {
mysql_query("INSERT INTO CourseSelected VALUES(".$params['cid'].", ".$params['stuid'].");");
} else if ($cmd == "delCourseSelected") {
// Remove selected course goes here
mysql_query("DELETE FROM CourseSelected WHERE courseID='".$params['cid']."' AND studentID='".$params['stuid']."';");
}else if ($cmd == "sumCourseSelected") {
// Return the value of the aggregate function as an echo
// then in javascript handle it using the HandleResponse event
//$sumCredits = mysql_query("SELECT courseid,SUM(courseID) AS TotalCredits FROM CourseSelected GROUP BY courseID;");
$sumCredits = "SELECT SUM(credits) AS \"TotalCredits\"
FROM CourseSelected CS, Course C
WHERE CS.courseID = C.courseID AND studentID='".$params['stuid']."';";
$result = mysql_query($sumCredits) or die(mysql_error());
// Print out result
while($row = mysql_fetch_array($result)){
echo($row['TotalCredits']);
}
}else if ($cmd == "info") {
// Return the class information as an echo
// then in javascript handle it using the HandleResponse event
$courseInfo = "SELECT department AS \"dept\", catalogNumber AS \"cnum\", name AS \"name\"
FROM CourseSelected CS, Course C
WHERE CS.courseID = C.courseID AND C.courseID = ".$params['cid'].";";
$result = mysql_query($courseInfo) or die(mysql_error());
// Print out result
while($row = mysql_fetch_array($result)){
echo($row['dept']." ".$row['cnum']." - ".$row['name']);
}
}else if ($cmd == "getCourses") {
// Return the dept+no of classes selected by a student as an echo
// then in javascript handle it using the HandleResponse event
$courseName = "SELECT department AS \"dept\", catalogNumber AS \"num\"
FROM CourseSelected CS, Course C
WHERE CS.courseID = C.courseID AND studentID='".$params['stuid']."'";
$result = mysql_query($courseName) or die(mysql_error());
//Print out result
while($row = mysql_fetch_array($result)){
echo($row['dept']. " " . $row['num'] . "," );
}
}else if ($cmd == "getSections") {
// Return the section info of classes selected as an echo
// then in javascript handle it using the HandleResponse event
$sectionInfo = "SELECT sectionID, sTime, eTime, day, location, letter, instructor, availability, courseID
FROM CourseSelected CS, Section S
WHERE CS.courseID = S.cid AND studentID='".$params['stuid']."'";
$result = mysql_query($sectionInfo) or die(mysql_error());
//Print out result
while($row = mysql_fetch_array($result)){
echo($row['courseID']. "," .$row['sectionID']. "#" .$row['sTime'] . "#" .$row['eTime']. "#" .$row['day'] . "#" .$row['location'] . "#" .$row['letter'] . "#" .$row['instructor'] . "#" .$row['availability'] ."~" );
}
}else if ($cmd == "addSchedule") {
mysql_query("INSERT INTO Schedule VALUES(".$params['schedID'].", ".$params['secID'].", ".$params['stuid'].");");
}else if ($cmd == "removeAllSchedules") {
mysql_query("DELETE * FROM Schedule;");
echo("success");
}else if ($cmd == "getPrerequisites") {
// Return the courseIDs of courses and their requirements
$prereqInfo = "SELECT cid1, cid2, cName1, cName2
FROM CourseRequirement";
$result = mysql_query($prereqInfo) or die(mysql_error());
//Print out result
while($row = mysql_fetch_array($result)){
echo($row['cid1']. "," .$row['cid2']. "," .$row['cName1']. "," .$row['cName2']. "~" );
}
}else if ($cmd == "getStudentTranscript") {
// Return the courseIDs of courses and their requirements
$coursesPassed = "SELECT courseTaken
FROM StudentTranscript T
WHERE (T.grade = 'A' OR T.grade = 'B' OR T.grade = 'C') AND T.sid='".$params['stuid']."'";
$result = mysql_query($coursesPassed) or die(mysql_error());
//Print out result
while($row = mysql_fetch_array($result)){
echo($row['courseTaken']. "," );
}
}
// Insert a new instructor into Instructor table
else if($cmd == "addInstructorSection"){
mysql_query("INSERT INTO Instructor VALUES(".$params['cid'].", ".$params['stuid'].", ".$params['secID'].");");
}
// Remove an instructor from the Instructor table
else if($cmd == "delInstructorSection"){
mysql_query("DELETE FROM Instructor WHERE studentID='".$params['stuid']."' AND sectionID='".$params['secID']."';");
}
// A list of all of the instructors and course names for the selected courses
else if($cmd == "getInstructors"){
$sectionInfo = "SELECT department, catalogNumber, sectionID, instructor
FROM CourseSelected CS, Section S, Course CO
WHERE CS.courseID = S.cid AND CO.courseID = S.cid AND studentID='".$params['stuid']."'";
$result = mysql_query($sectionInfo) or die(mysql_error());
//Print out result
while($row = mysql_fetch_array($result))
{
echo($row['department']. " " .$row['catalogNumber']. "#" .$row['sectionID'] . "#" .$row['instructor']."~" );
}
}
// A list of all of the sectionIDs from the instructor table
else if($cmd == "getExistingInstructorPreferences"){
$sectionInfo = "SELECT sectionID
FROM Instructor I
WHERE I.studentID='".$params['stuid']."'";
$result = mysql_query($sectionInfo) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
echo($row['sectionID']. "~");
}
}
else if($cmd == "getSectionsForPreferences")
{
$sectionInfo = "SELECT department, catalogNumber, sectionID, letter, sTime, eTime, instructor
FROM CourseSelected CS, Section S, Course CO
WHERE CS.courseID = S.cid AND CO.courseID = S.cid AND studentID='".$params['stuid']."'";
$result = mysql_query($sectionInfo) or die(mysql_error());
//Print out result
while($row = mysql_fetch_array($result))
{
echo($row['department']. " " .$row['catalogNumber']. "#" .$row['sectionID']. "#" .$row['letter']."#" .$row['sTime']. "#" .$row['eTime']. "#" .$row['instructor']."~" );
}
}
else if($cmd == "addSectionPreference")
{
mysql_query("INSERT INTO SectionPreference VALUES(".$params['cid'].", ".$params['stuid'].", ".$params['secID'].");");
}
else if($cmd == "delSectionPreference")
{
mysql_query("DELETE FROM SectionPreference WHERE studentID='".$params['stuid']."' AND sectionID='".$params['secID']."';");
}
else if($cmd == "getLocationForPreferences")
{
$sectionInfo = "SELECT department, catalogNumber, location, sectionID
FROM CourseSelected CS, Section S, Course CO
WHERE CS.courseID = S.cid AND CO.courseID = S.cid AND studentID='".$params['stuid']."'";
$result = mysql_query($sectionInfo) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
echo($row['department']." ".$row['catalogNumber']. "#" .$row['location']. "#" . $row['sectionID']."~");
}
}
else if($cmd == "addLocationPreference")
{
mysql_query("INSERT INTO Location VALUES(".$params['cid'].", ".$params['stuid'].", ".$params['secID'].");");
}
else if($cmd == "delLocationPreference")
{
mysql_query("DELETE FROM Location WHERE studentID='".$params['stuid']."' AND sectionID='".$params['secID']."';");
}
else if($cmd == "getAvailableForPreferences"){
$sectionInfo = "SELECT department, catalogNumber, availability, sectionID
FROM CourseSelected CS, Section S, Course CO
WHERE CS.courseID = S.cid AND CO.courseID = S.cid AND studentID='".$params['stuid']."'";
$result = mysql_query($sectionInfo) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
echo($row['department']." ".$row['catalogNumber']."#".$row['availability']."#".$row['sectionID']."~");
}
}
else if($cmd == "addAvailablePreference"){
mysql_query("INSERT INTO Availability VALUES(".$params['cid'].", ".$params['stuid'].", ".$params['secID'].");");
}
else if($cmd == "delAvailablePreference"){
mysql_query("DELETE FROM Availability WHERE studentID='".$params['stuid']."' AND sectionID='".$params['secID']."';");
}
else if($cmd == "getExistingLocationPreferences")
{
$sectionInfo = "SELECT sectionID
FROM Location L
WHERE L.studentID='".$params['stuid']."'";
$result = mysql_query($sectionInfo) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
echo($row['sectionID']. "~");
}
}
else if($cmd == "getExistingSectionPreferences"){
$sectionInfo = "SELECT sectionID
FROM SectionPreference SP
WHERE SP.studentID='".$params['stuid']."'";
$result = mysql_query($sectionInfo) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
echo($row['sectionID']. "~");
}
}
else if($cmd == "getExistingAvailablePreferences")
{
$sectionInfo = "SELECT sectionID
FROM Availability A
WHERE A.studentID='".$params['stuid']."'";
$result = mysql_query($sectionInfo) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
echo($row['sectionID']. "~");
}
}
// All Preferences that are removed from the list of schedules
else if ($cmd == "getSectionsWithFilter") {
// Return the section info of classes selected as an echo
// then in javascript handle it using the HandleResponse event
$removedSections = "SELECT I.sectionID
FROM Instructor I
WHERE I.studentID='".$params['stuid']."'
UNION
SELECT P.sectionID
FROM SectionPreference P
WHERE P.studentID='".$params['stuid']."'
UNION
SELECT L.sectionID
FROM Location L
WHERE L.studentID='".$params['stuid']."'
UNION
SELECT A.sectionID
FROM Availability A
WHERE A.studentID='".$params['stuid']."'
UNION
SELECT S.sectionID
FROM Timeslot T, Section S, CourseSelected C
WHERE C.studentID='".$params['stuid']."' AND
C.courseID = S.cid AND
(T.startTime >= S.sTime AND T.endTime >= S.sTime) OR
(T.startTime <= S.eTime AND T.endTime > S.eTime)
AND
S.day LIKE T.day
";
// while($row = mysql_fetch_array($result1)){
// $removedSections = "'".$row['sectionID']. "',";
//}
$removedSections = subStr($removedSections, 0, strlen($listofsections)-1);
$sectionInfo = "
SELECT sectionID, sTime, eTime, day, location, letter, instructor, availability, courseID
FROM CourseSelected CS, Section S
WHERE CS.courseID = S.cid AND studentID='".$params['stuid']."' AND sectionID NOT IN($removedSections)
;";
$result = mysql_query($sectionInfo) or die(mysql_error());
//Print out result
while($row = mysql_fetch_array($result)){
echo($row['courseID']. "," .$row['sectionID']. "#" .$row['sTime'] . "#" .$row['eTime']. "#" .$row['day'] . "#" .$row['location'] . "#" .$row['letter'] . "#" .$row['instructor'] . "#" .$row['availability'] ."~" );
}
}
else if($cmd == "getPreferencesToBeRemoved") {
$removedSections = "SELECT I.sectionID
FROM Instructor I
WHERE I.studentID='".$params['stuid']."'
UNION
SELECT P.sectionID
FROM SectionPreference P
WHERE P.studentID='".$params['stuid']."'
UNION
SELECT L.sectionID
FROM Location L
WHERE L.studentID='".$params['stuid']."'
UNION
SELECT A.sectionID
FROM Availability A
WHERE A.studentID='".$params['stuid']."'
";
$result = mysql_query($removedSections) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo($row['sectionID']."~");
}
}
// Add a new timeslot to the timeslot table
else if ($cmd == "addNewTimeSlot") {
mysql_query("INSERT INTO Timeslot VALUES('".$params['stuid']."', '".$params['startTime']."', '".$params['endTime']."', '".$params['days']."');");
}else if ($cmd == "removeTimeSlot") {
//mysql_query("INSERT INTO Timeslot VALUES('".$params['stuid']."', '".$params['startTime']."', '".$params['endTime']."', '".$params['days']."');");
mysql_query("DELETE FROM Timeslot WHERE studentID='".$params['stuid']."' AND startTime='".$params['startTime']."' AND endTime='".$params['endTime']."' AND day='".$params['days']."';");
}
// Aggregate function which could be used to return the number of possible schedules
/*
else if ($cmd == "countSchedules") {
// Aggregate function which counts all rows in schedule table and rows in CourseSelected table
// Number of rows in schedule / Number of courses = Number of schedules
$rowsInSchedule = "SELECT COUNT(*) AS \"scheduleRows\"
FROM Schedule
WHERE studentID='".$params['stuid']."';";
$rowsInCourseSelected = "SELECT COUNT(*) AS \"courseRows\"
FROM CourseSelected
WHERE studentID='".$params['stuid']."';";
$rowSchedule = mysql_query($rowsInSchedule) or die(mysql_error());
$rowCourses = mysql_query($rowsInCourseSelected) or die(mysql_error());
while($row1 = mysql_fetch_array($rowSchedule)){
$result1 = ($row1['scheduleRows'] );
}
while( $row2 = mysql_fetch_array($rowCourses) ){
$result2 = ($row2['courseRows'] );
}
echo($result1 / $result2);
}
*/
mysql_close($connection);
?>