Пример #1
0
<?php

// Import the "Grab Bag"
require "../common.php";
// Open an (OO) MySQL Connection
$conn = new mysqli($GLOBALS["dbhost"], $GLOBALS["dbuser"], $GLOBALS["dbpass"], $GLOBALS["dbname"]);
// Check connection
if ($conn->connect_error || !session_start()) {
    die("Connection failed: " . $conn->connect_error);
}
$userId = $_SESSION[USER_ID];
$id = $_GET["id"];
$query = "SELECT *\n\t\t\t  FROM  `Professor`\n\t\t\t  WHERE `UserID` = {$userId}";
if ($id) {
    $id = implode_parameters($id);
    $query .= PHP_EOL . "AND `id` IN (" . $id . ")";
}
$result = $conn->query($query);
$professors = array();
while ($row = $result->fetch_row()) {
    $credit_hours = $row[PROFESSOR_MAXHRS];
    if (!$credit_hours) {
        /* We should consider making this a cached map so we don't have to query
         * the database so often
         */
        $type = get_x_with_id($conn, "ProfessorType", $row[PROFESSOR_TYPE]);
        $credit_hours = $type[PROFESSORTYPE_CRHR];
    }
    array_push($professors, array("id" => $row[PROFESSOR_ID], "name" => $row[PROFESSOR_NAME], "professor_type" => $row[PROFESSOR_TYPE], "valpo_id" => $row[PROFESSOR_VID], "max_credit_hours" => $credit_hours));
}
$result->close();
Пример #2
0
    // Decode the JSON
    $professors = implode_parameters($professors);
    // Append the professors Query
    $query .= PHP_EOL . "AND `Professor` IN ( {$professors} )";
}
// If we were provided with a semesters
if ($semesters) {
    // Decode the JSON
    $semesters = implode_parameters($semesters);
    // Append the semesters Query
    $query .= PHP_EOL . "AND `Semester` IN ({$semesters})";
}
// If we were provided with a classes
if ($classes) {
    // Decode the JSON
    $classes = implode_parameters($classes);
    // Append the classes Query
    $query .= PHP_EOL . "AND `Class` IN ({$classes})";
}
// Then, load only the desired sections (which is potentially all of them)
$sections_pool = get_all_sections_with_query($conn, $query);
$filtered_sections = array();
foreach ($sections_pool as $section) {
    // This is what does all the room/building filtering, it (probably) could be simplified but I'm lazy
    if ($rooms || $buildings) {
        $section_rooms = json_decode($section[SECTION_ROOMS]);
        $skip = true;
        foreach ($section_rooms as $section_room) {
            if ($rooms && in_array($section_room, $rooms)) {
                $skip = false;
                break;