Beispiel #1
0
// 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();
// Echo all of the classes as JSON
echo json_encode($professors);
// Finally, close the connection
$conn->close();
Beispiel #2
0
 public static function new_from_db_row($conn, $db_row)
 {
     $section = new ValpoSection();
     $class = get_x_with_id($conn, "Class", $db_row[SECTION_CLASS]);
     $professor = get_x_with_id($conn, "Professor", $db_row[SECTION_PROF]);
     $semester = get_x_with_id($conn, "Semester", $db_row[SECTION_SEM]);
     $section->database_id = $db_row[SECTION_DBID];
     $section->name = $class[CLASS_NAME] . "-" . $db_row[SECTION_ID];
     $section->title = $class[CLASS_TITLE];
     $section->semester = $semester[SEMESTER_NAME];
     $section->meeting_type = $db_row[SECTION_TYPE];
     $section->professor = $professor[PROFESSOR_NAME];
     $section->meeting_times = json_decode($db_row[SECTION_TIMES]);
     // Load the number of credit hours from the row at first
     $section->credit_hours = $db_row[SECTION_CRHR];
     // But if it is null
     if (is_null($section->credit_hours)) {
         // Grab them from the class instead
         $section->credit_hours = $class[CLASS_CREDITHOURS];
     }
     // Load the number of credit hours from the row at first
     $section->tl_credits = $db_row[SECTION_TLC];
     // But if it is null
     if (is_null($section->tl_credits)) {
         // Grab them from the class instead
         $section->tl_credits = $class[CLASS_CONTACTHOURS];
         // If it is still null, the number of tlc = credithours
         if (is_null($section->tl_credits)) {
             $section->tl_credits = $section->credit_hours;
         }
     }
     $section->rooms = array();
     $smallest_cap = PHP_INT_MAX;
     $section->room_ids = json_decode($db_row[SECTION_ROOMS]);
     foreach ($section->room_ids as $room_id) {
         $room = get_x_with_id($conn, "Room", $room_id);
         $building = get_x_with_id($conn, "Building", $room[ROOM_BLDG]);
         if ($room[ROOM_CAP] < $smallest_cap) {
             $smallest_cap = $room[ROOM_CAP];
         }
         array_push($section->rooms, $building[BUILDING_ABRV] . "-" . $room[ROOM_NMBR]);
     }
     $section->capacity = $db_row[SECTION_MCAP];
     // If the section does not provide a meeting size cap
     if (!$section->capacity) {
         // Assign to smallest capacity
         $section->capacity = $smallest_cap;
     }
     return $section;
 }
Beispiel #3
0
// 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];
$building = $_GET["building"];
$id = $_GET["id"];
$query = "SELECT *\n              FROM  `Room`\n\t\t\t  WHERE `UserID` = {$userId}";
if ($building) {
    $query .= PHP_EOL . "AND `Building`={$building}";
} else {
    if ($id) {
        $query .= PHP_EOL . "AND `id`={$id}";
    }
}
$result = $conn->query($query);
$rooms = array();
while ($row = $result->fetch_row()) {
    if ($row[ROOM_ID]) {
        $building = get_x_with_id($conn, "Building", $row[ROOM_BLDG]);
        $name = $building[BUILDING_ABRV] . "-" . $row[ROOM_NMBR];
        array_push($rooms, array("id" => $row[ROOM_ID], "name" => $name, "building" => $row[ROOM_BLDG], "nmbr" => $row[ROOM_NMBR], "cap" => $row[ROOM_CAP], "handicap_accessible" => $row[HANDICAP_ACCESSIBLE]));
    }
}
$result->close();
// Echo all of the classes as JSON
echo json_encode($rooms);
// Finally, close the connection
$conn->close();