Exemplo n.º 1
0
 }
 if (mysql_num_rows($result) == 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)) {
     $courses[] = $row['id'];
 }
 // @todo: store this in session to avoid lengthy and costly queries
 // Loop through all results and fill them out
 $matchingCourses = array();
 foreach ($courses as $sectionId) {
     // Look up the course
     $course = getCourseBySectionId($sectionId);
     // Do we need to exclude it because it's online?
     if ($course['online'] == true && (!isset($_POST['online']) || $_POST['online'] != true)) {
         // Yes, it should be excluded
         continue;
     }
     // Determine if its on campus
     $offCampus = false;
     if (!empty($course['times'])) {
         foreach ($course['times'] as $time) {
             if ($time['off_campus']) {
                 $offCampus = true;
                 break;
             }
         }
     }
Exemplo n.º 2
0
function getScheduleFromId($id)
{
    // 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);
    $query = "SELECT startday, endday, starttime, endtime, building, `quarter`, CAST(`image` AS unsigned int) AS `image` FROM schedules WHERE id={$id}";
    $result = mysql_query($query);
    if (!$result) {
        return NULL;
    }
    $scheduleInfo = mysql_fetch_assoc($result);
    if (!$scheduleInfo) {
        return NULL;
    }
    // Grab the metadata of the schedule
    $startDay = (int) $scheduleInfo['startday'];
    $endDay = (int) $scheduleInfo['endday'];
    $startTime = (int) $scheduleInfo['starttime'];
    $endTime = (int) $scheduleInfo['endtime'];
    $building = $scheduleInfo['building'];
    $term = $scheduleInfo['quarter'];
    $image = $scheduleInfo['image'] == 1;
    // Create storage for the courses that will be returned
    $schedule = array();
    // 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)) {
        $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);
    if (!$result) {
        echo mysql_error();
    }
    while ($nonCourseInfo = mysql_fetch_assoc($result)) {
        $schedule[] = array("title" => $nonCourseInfo['title'], "courseNum" => "non", "times" => array(array("day" => $nonCourseInfo['day'], "start" => $nonCourseInfo['start'], "end" => $nonCourseInfo['end'])));
    }
    return array("courses" => $schedule, "startTime" => $startTime, "endTime" => $endTime, "startDay" => $startDay, "endDay" => $endDay, "bldgStyle" => $building, "term" => $term, "image" => $image);
}
Exemplo n.º 3
0
                $section['title'] = $section['coursetitle'];
            }
            unset($section['sectiontitle']);
            unset($section['coursetitle']);
            // If it's online, don't bother looking up the times
            if ($section['type'] == "O") {
                $section['online'] = true;
            } else {
                // Look up the times the section meets
                $query = "SELECT day, start, end, b.code, b.number, b.off_campus AS off, room\n                          FROM times AS t\n                            JOIN buildings AS b ON b.number=t.building\n                          WHERE t.section = '{$section['id']}'\n                          ORDER BY day, start";
                $timeResult = mysql_query($query);
                if (!$timeResult) {
                    die(json_encode(array("error" => "mysql", "msg" => mysql_error())));
                }
                while ($time = mysql_fetch_assoc($timeResult)) {
                    $timeOutput = array('start' => $time['start'], 'end' => $time['end'], 'day' => $time['day'], 'bldg' => array('code' => $time['code'], 'number' => $time['number'], 'off_campus' => $time['off'] == '1'), 'room' => $time['room']);
                    $section['times'][] = $timeOutput;
                }
            }
            // Add the section to the result set
            $sections[] = array("id" => $section['id'], "department" => array("code" => $section['code'], "number" => $section['number']), "course" => $section['course'], "section" => $section['section'], "title" => $section['title'], "instructor" => $section['instructor'], "type" => $section['type'], "maxenroll" => $section['maxenroll'], "curenroll" => $section['curenroll'], "times" => $section['times']);
        }
        // Spit out the json
        echo json_encode(array("sections" => $sections));
        break;
    case "courseForSection":
        echo json_encode(getCourseBySectionId($_POST['id'], true));
        break;
    default:
        die(json_encode(array("error" => "argument", "msg" => "You must provide a valid action.")));
}
Exemplo n.º 4
0
 /**
  * array(int {course input index} => array(integer {courseId} => array(string {courseNum} => {courseInfo array})))
  */
 $courseGroupsByCourseId = array();
 $courseSet = array();
 for ($i = 1; $i <= $_POST['courseCount']; $i++) {
     // It's 1-indexed... :[
     // Iterate over the courses in that course slot
     if (!isset($_POST["courses{$i}Opt"])) {
         continue;
     }
     $courseSubSet = array();
     $courseGroupsByCourseId[$i] = array();
     foreach ($_POST["courses{$i}Opt"] as $course) {
         // Do a query to get the course specified
         $courseInfo = getCourseBySectionId($course);
         // courseIndex is only used by the frontend UI to determine what color/grouping to use
         $courseInfo['courseIndex'] = $i;
         // Remove the potential special indicators from the end of the courseNum
         $cleanCourseNum = getCleanCourseNum($courseInfo);
         // Create the group if it does not already exist
         if (!array_key_exists($cleanCourseNum, $courseGroups)) {
             $courseGroups[$cleanCourseNum] = array();
         }
         // Create the group by index and course id. Can probably ignore courseId, but will be eventually useful
         if (!array_key_exists($courseInfo['courseId'], $courseGroupsByCourseId[$i])) {
             $courseGroupsByCourseId[$i][$courseInfo['courseId']] = array();
         }
         // Check if the section is a special course: courseNum ending in a letter, then one or two digits
         if (isSpecialSection($courseInfo)) {
             if (!array_key_exists($courseInfo['courseNum'], $courseGroups[$cleanCourseNum])) {