Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions api/entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@
AND s.status != 'X'
GROUP BY c.id
ORDER BY course";
$result = mysql_query($query);
$result = $dbConn->query($query);
if(!$result) {
die(json_encode(array("error" => "mysql", "msg" => mysql_error())));
die(json_encode(array("error" => "mysql", "msg" => $dbConn->error)));
}

// Collect the courses and turn it into a json
$courses = array();
while($course = mysql_fetch_assoc($result)) {
while($course = $result->fetch_assoc()) {
$courses[] = array(
"id" => $course['id'],
"course" => $course['course'],
Expand Down Expand Up @@ -98,14 +98,14 @@
AND number IS NOT NULL
ORDER BY id";
}
$result = mysql_query($query);
$result = $dbConn->query($query);
if(!$result) {
die(json_encode(array("error" => "mysql", "msg" => mysql_error())));
die(json_encode(array("error" => "mysql", "msg" => $dbConn->error)));
}

// Collect the departments and turn it into a json
$departments = array();
while($department = mysql_fetch_assoc($result)) {
while($department = $result->fetch_assoc()) {
$departments[] = array(
"id" => $department['id'],
"title" => $department['title'],
Expand All @@ -122,14 +122,14 @@
// REQUEST FOR LIST OF SCHOOLS /////////////////////////////////////
// Query for the schools
$query = "SELECT `id`, `number`, `code`, `title` FROM schools";
$result = mysql_query($query);
$result = $dbConn->query($query);
if(!$result) {
die(json_encode(array("error" => "database", "msg" => "The list of schools could not be retrieved at this time.")));
}

// Build an array of schools
$schools = array();
while($school = mysql_fetch_assoc($result)) {
while($school = $result->fetch_assoc()) {
$schools[] = $school;
}

Expand All @@ -154,14 +154,14 @@
$query = "SELECT id, number AS code, title FROM schools WHERE number IS NOT NULL ORDER BY number";
}
// Query for the schools
$result = mysql_query($query);
$result = $dbConn->query($query);
if(!$result) {
die(json_encode(array("error" => "database", "msg" => "The list of schools could not be retrieved at this time.")));
}

// Build an array of schools
$schools = array();
while($school = mysql_fetch_assoc($result)) {
while($school = $result->fetch_assoc()) {
$schools[] = $school;
}

Expand All @@ -186,14 +186,14 @@
WHERE s.course = '{$_POST['course']}'
AND s.status != 'X'
ORDER BY c.course, s.section";
$sectionResult = mysql_query($query);
$sectionResult = $dbConn->query($query);
if(!$sectionResult) {
die(json_encode(array("error" => "mysql", "msg" => mysql_error())));
die(json_encode(array("error" => "mysql", "msg" => $dbConn->error)));
}

// Collect the sections and their times, modify the section inline
$sections = array();
while($section = mysql_fetch_assoc($sectionResult)) {
while($section = $sectionResult->fetch_assoc()) {
$section['times'] = array();

// Set the course title depending on its section title
Expand All @@ -216,12 +216,12 @@
JOIN buildings AS b ON b.number=t.building
WHERE t.section = '{$section['id']}'
ORDER BY day, start";
$timeResult = mysql_query($query);
$timeResult = $dbConn->query($query);
if(!$timeResult) {
die(json_encode(array("error" => "mysql", "msg" => mysql_error())));
die(json_encode(array("error" => "mysql", "msg" => $dbConn->error)));
}

while($time = mysql_fetch_assoc($timeResult)) {
while($time = $timeResult->fetch_assoc()) {
$timeOutput = array(
'start' => $time['start'],
'end' => $time['end'],
Expand Down
6 changes: 3 additions & 3 deletions api/generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,14 @@ function pruneSpecialCourses($schedules, $courseGroups) {
// Close it up and provide order
$query .= " ORDER BY c.course, s.section";

$result = mysql_query($query);
$result = $dbConn->query($query);
if(!$result) {
die(json_encode(array("error" => "mysql", "msg" => "A database error occurred while searching for {$course}")));
}
if(mysql_num_rows($result) == 0) { continue; }
if($result->num_rows == 0) { continue; }

// Fetch all the results and append them to the list
while($row = mysql_fetch_assoc($result)) {
while($row = $result->fetch_assoc()) {
$courseOptions[] = getCourseBySectionId($row['id']);
}
}
Expand Down
50 changes: 27 additions & 23 deletions api/schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ function icalFormatTime($time) {

function generateIcal($schedule) {
// Globals
global $HTTPROOTADDRESS;
global $HTTPROOTADDRESS, $dbConn;

// We need to lookup the information about the quarter
$term = mysql_real_escape_string($schedule['term']);
$term = $dbConn->real_escape_string($schedule['term']);
$query = "SELECT start, end, breakstart, breakend FROM quarters WHERE quarter='{$term}'";
$result = mysql_query($query);
$term = mysql_fetch_assoc($result);
$result = $dbConn->query($query);
$term = $result->fetch_assoc();
$termStart = strtotime($term['start']);
$termEnd = date("Ymd", strtotime($term['end']));

Expand Down Expand Up @@ -103,18 +103,20 @@ function generateIcal($schedule) {
}

function getScheduleFromId($id) {
global $dbConn;

// Query to see if the id exists, if we can update the last accessed time,
// then the id most definitely exists.
$query = "UPDATE schedules SET datelastaccessed = NOW() WHERE id={$id}";
$result = mysql_query($query);
$result = $dbConn->query($query);

$query = "SELECT startday, endday, starttime, endtime, building, `quarter`, CAST(`image` AS unsigned int) AS `image` FROM schedules WHERE id={$id}";

$result = mysql_query($query);
$result = $dbConn->query($query);
if(!$result) {
return NULL;
}
$scheduleInfo = mysql_fetch_assoc($result);
$scheduleInfo = $result->fetch_assoc();
if(!$scheduleInfo) {
return NULL;
}
Expand All @@ -133,18 +135,18 @@ function getScheduleFromId($id) {

// It exists, so grab all the courses that exist for this schedule
$query = "SELECT section FROM schedulecourses WHERE schedule = {$id}";
$result = mysql_query($query);
while($course = mysql_fetch_assoc($result)) {
$result = $dbConn->query($query);
while($course = $result->fetch_assoc()) {
$schedule[] = getCourseBySectionId($course['section']);
}

// Grab all the non courses that exist for this schedule
$query = "SELECT * FROM schedulenoncourses WHERE schedule = $id";
$result = mysql_query($query);
$result = $dbConn->query($query);
if(!$result) {
echo mysql_error();
echo $dbConn->error();
}
while($nonCourseInfo = mysql_fetch_assoc($result)) {
while($nonCourseInfo = $result->fetch_assoc()) {
$schedule[] = array(
"title" => $nonCourseInfo['title'],
"courseNum" => "non",
Expand All @@ -170,12 +172,14 @@ function getScheduleFromId($id) {
}

function getScheduleFromOldId($id) {
global $dbConn;

$query = "SELECT id FROM schedules WHERE oldid = '{$id}'";
$result = mysql_query($query);
if(!$result || mysql_num_rows($result) != 1) {
$result = $dbConn->query($query);
if(!$result || $result->num_rows != 1) {
return NULL;
} else {
$newId = mysql_fetch_assoc($result);
$newId = $result->fetch_assoc();
$newId = $newId['id'];
$schedule = getScheduleFromId($newId);
$schedule['id'] = $newId;
Expand Down Expand Up @@ -337,19 +341,19 @@ function renderSvg($svg, $id) {
$query = "INSERT INTO schedules (oldid, startday, endday, starttime, endtime, building, quarter)" .
" VALUES('', '{$json['startday']}', '{$json['endday']}', '{$json['starttime']}', '{$json['endtime']}', '{$json['building']}', " .
" '{$json['term']}')";
$result = mysql_query($query);
$result = $dbConn->query($query);
if(!$result) {
die(json_encode(array("error" => "mysql", "msg" => "Failed to store the schedule: " . mysql_error($dbConn))));
die(json_encode(array("error" => "mysql", "msg" => "Failed to store the schedule: " . $dbConn->error)));
}

// Grab the latest id for the schedule
$schedId = mysql_insert_id();
$schedId = $dbConn->insert_id;

// Optionally process the svg for the schedule
$image = false;
if(!empty($_POST['svg']) && renderSvg($_POST['svg'], $schedId)) {
$query = "UPDATE schedules SET image = ((1)) WHERE id = '{$schedId}'";
mysql_query($query); // We don't particularly care if this fails
$dbConn->query($query); // We don't particularly care if this fails
}

// Now iterate through the schedule
Expand All @@ -360,18 +364,18 @@ function renderSvg($svg, $id) {
foreach($item['times'] as $time) {
$query = "INSERT INTO schedulenoncourses (title, day, start, end, schedule)" .
" VALUES('{$item['title']}', '{$time['day']}', '{$time['start']}', '{$time['end']}', '{$schedId}')";
$result = mysql_query($query);
$result = $dbConn->query($query);
if(!$result) {
die(json_encode(array("error" => "mysql", "msg" => "Storing non-course item '{$item['title']}' failed: " . mysql_error($dbConn))));
die(json_encode(array("error" => "mysql", "msg" => "Storing non-course item '{$item['title']}' failed: " . $dbConn->error)));
}
}
} else {
// Process each course. It's crazy simple now.
$query = "INSERT INTO schedulecourses (schedule, section)" .
" VALUES('{$schedId}', '{$item['id']}')";
$result = mysql_query($query);
$result = $dbConn->query($query);
if(!$result) {
die(json_encode(array("error" => "mysql", "msg" => "Storing a course '{$item['courseNum']}' failed: " . mysql_error($dbConn))));
die(json_encode(array("error" => "mysql", "msg" => "Storing a course '{$item['courseNum']}' failed: " . $dbConn->erorr)));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions api/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,19 @@ function assertNumeric($var, $name) {
}

// Run it!
$result = mysql_query($query);
$result = $dbConn->query($query);
if(!$result) {
echo json_encode(array("error" => "mysql", "msg" => "An error occurred while searching the database."));
break;
}
if(mysql_num_rows($result) == 0) {
if($result->num_rows == 0) {
echo json_encode(array("error" => "result", "msg" => "No courses matched your criteria"));
break;
}

// Now we build an array of the results
$courses = array();
while($row = mysql_fetch_assoc($result)) {
while($row = $result->fetch_assoc()) {
$courses[] = $row['id'];
}
// @todo: store this in session to avoid lengthy and costly queries
Expand Down
4 changes: 2 additions & 2 deletions api/status.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ function timeElapsed($time) {
// MAIN EXECUTION //////////////////////////////////////////////////////////
// Look up the last 20 scrape reports and store into an array
$query = "SELECT * FROM scrapelog ORDER BY timeStarted DESC LIMIT 20";
$result = mysql_query($query);
$result = $dbConn->query($query);
$lastLogs = array();
while($row = mysql_fetch_assoc($result)) {
while($row = $result->fetch_assoc()) {
$lastLogs[] = $row;
}
echo json_encode($lastLogs);
Loading