static function getElectives($program, $elective_type, $elective_group, $exclude = []) { $results = array(); foreach (explode("|", $elective_group) as $group) { $q = new Query("electives"); $q->select("course_code"); $q->where("program_id=?\n\t\t\t\t\t\t\tAND elective_type=?\n\t\t\t\t\t\t\tAND note=?\n\t\t\t\t\t\t\tAND course_code NOT IN " . Query::valuelistsql($exclude), array_merge([$program, $elective_type, $group], $exclude)); $results = array_merge($results, $q->executeFetchAll()); } return $results; }
* @return An XML response containing programs that matched the search * * @example programs.php - This would return all of the programs * @example programs.php?program=Software - This would return all programs with a name like software */ if ($_SERVER['REQUEST_METHOD'] != 'GET') { http_response_code(405); echo '{"e":1, "msg":"Method must be GET."}'; exit; } require_once 'lib/db.php'; $has_param = in_array('program', $_GET); $q = new Query("programs"); $q->select("id"); $q->select("year"); $q->select("name"); if ($has_param) { $q->where('name LIKE ?', [$_GET['program']]); } $rows = $q->executeFetchAll(); $response = '<response e="0">'; foreach ($rows as $program) { $response .= '<program>'; $response .= "<id>{$program['0']}</id>"; $response .= "<year>{$program['1']}</year>"; $response .= "<name>{$program['2']}</name>"; $response .= '</program>'; } $response .= '</response>'; header("Content-Type", "application/xml; charset=utf-8"); echo $response;
$q->select_object('CourseOffering'); $q->where("term=? \n\t\t\t\t\t\tAND year=?\n\t\t\t\t\t\tAND course_code = ?\n\t\t\t\t\t\tAND section = ?", [$term, $year, $course_code, $section_id]); $result = $q->executeFetchAll(); if (count($result) < 1) { echo '<p style="color:red">Could not find section ' . $sectioncode . '</p>'; continue; } if ($result[0][0]->getcapacity() - $result[0][0]->getenrolled() > 0 or $result[0][0]->getcapacity() == 0) { $sql = "UPDATE course_offerings\n\t\t\t\t\t\tSET enrolled=enrolled+1\n\t\t\t\t\t\tWHERE \n\t\t\t\t\t\tterm=?\n\t\t\t\t\t\tAND year=?\n\t\t\t\t\t\tAND course_code=?\n\t\t\t\t\t\tAND section=?\n\t\t\t\t\t\tAND (enrolled < capacity OR capacity=0)"; $result = db_exec($sql, [$term, $year, $course_code, $section_id]); if ($result->rowCount() == 0) { echo '<p style="color:red">Section ' . $sectioncode . ' is now full. Continued registration in remaining courses</p>'; } else { $q = new Query('course_offerings'); $q->select_object('CourseOffering'); $q->where("term=? \n\t\t\t\t\t\tAND year=?\n\t\t\t\t\t\tAND course_code = ?\n\t\t\t\t\t\tAND section = ?", [$term, $year, $course_code, $section_id]); $result = $q->executeFetchAll(); if (isset($result[0])) { if ($result[0][0]->getcapacity() != 0) { echo '<p>Registered in ' . $sectioncode . ' Seats remaining:' . ($result[0][0]->getcapacity() - $result[0][0]->getenrolled()) . '</p>'; } else { echo '<p>Registered in ' . $sectioncode . '</p>'; } } } } else { echo '<p style="color:red">Section ' . $sectioncode . ' is now full. Continued registration in remaining courses</p>'; } } echo '<h2>Registration completed</h2>'; }
$programQuery->select("course_code"); $programQuery->select("credit_type"); $programQuery->select("elective_note"); $programQuery->select("term"); $programQuery->select("element_year"); $programQuery->where("program_id = ?\n\t\t\t\t\t\t\t AND ((credit_type <> 0 AND e.element_year>={$completed_year} AND e.term >= {$term}) OR course_code NOT IN\n\t\t\t\t\t\t\t " . Query::valuelistsql($completed) . ") AND \n\t\t\t\t\t\t\t ((EXISTS \n\t\t\t\t\t\t\t (SELECT * FROM course_offerings o\n\t\t\t\t\t\t\t WHERE o.course_code = e.course_code\n\t\t\t\t\t\t\t AND o.year={$year}\n\t\t\t\t\t\t\t AND o.term={$term}))\n\t\t\t\t\t\t\t OR\n\t\t\t\t\t\t\t (credit_type <> 0))\n\t\t\t\t\t\t\t ORDER BY element_year ASC, term ASC, credit_type DESC", array_merge([$_GET['program_select']], $completed)); $pattern = $programQuery->executeFetchAll(); } else { $programQuery = new Query("program_elements e"); $programQuery->select("course_code"); $programQuery->select("credit_type"); $programQuery->select("elective_note"); $programQuery->select("term"); $programQuery->select("element_year"); $programQuery->where("program_id = ?\n\t\t AND ((credit_type <> 0) OR course_code NOT IN\n\t\t " . Query::valuelistsql($completed) . ") AND\n\t\t ((EXISTS\n\t\t (SELECT * FROM course_offerings o\n\t\t WHERE o.course_code = e.course_code\n\t\t AND o.year={$year}\n\t\t AND o.term={$term}))\n\t\t OR\n\t\t (credit_type <> 0))\n\t\t ORDER BY element_year ASC, term ASC, credit_type DESC", array_merge([$_GET['program_select']], $completed)); $pattern = $programQuery->executeFetchAll(); //See which of their electives they have fulfilled and remove them from consideration in the pattern foreach ($pattern as $key => $course) { if ($course[1] != '0') { foreach ($completed as $considering) { if (Elective::isElective($_GET['program_select'], $considering[0], $course[1], $course[2])) { unset($pattern[$key]); } } } } } $found = 0; $discarded = array(); $scheduling = array(); $electives = array();
echo '<response e="1" msg="Method must be POST."/>'; exit; } $db->beginTransaction(); $file = fopen("php://input", "r"); $line = trim(fgets($file)); $firstLine = str_getcsv($line); $name = $firstLine[0]; $year = $firstLine[1]; $addProgram = "INSERT INTO programs (year,name)\n\t VALUES (?, ?)"; db_exec($addProgram, [$year, $name]); $programQuery = new Query("programs"); $programQuery->select("id"); $programQuery->where("name = ?", [$name]); $programQuery->where("year = ?", [$year]); $id = $programQuery->executeFetchAll(); //insert the program elements while (!feof($file)) { $insert = "INSERT INTO program_elements(\n\t\t\tprogram_id,\n\t\t\tcourse_code,\n\t\t\tcredit_type,\n\t\t\tterm,\n\t\t\telement_year,\n\t\t\telective_note\n\t\t) VALUES (?,?,?,?,?,?)"; $line = trim(fgets($file)); if ($line == 'ELECTIVES') { break; } $id = $id[0][0]; list($code, $type, $term, $year, $note) = str_getcsv($line); try { db_exec($insert, [$id, $code, $type, $term, $year, $note]); } catch (Exception $e) { echo "Skipping {$code}\n"; } }
function getOfferingInfo($course_code) { $offerings = array(); //Get all the lecture sections for a particular course $q = new Query("course_offerings"); $q->select_object("CourseOffering"); $q->where('course_code=? AND term=? AND year=? AND (capacity - enrolled) > 0 AND type=0', [$course_code, $this->term, $this->year]); $rows = $q->executeFetchAll(); //For each lecture section get the available lab/tutorial sections foreach ($rows as $row) { $sub = new Query("course_offerings"); $sub->select_object('CourseOffering'); $sub->where("course_code=?\n\t\t\t\t\t\t\t\t AND (section LIKE CONCAT(?,'%')\n\t\t\t\t\t\t\t\t OR section LIKE ('L%'))\n\t\t\t\t\t\t\t\t AND (((capacity-enrolled) > 0) OR (capacity=0))\n\t\t\t\t\t\t\t\t AND term=?\n\t\t\t\t\t\t\t\t AND year=?\n\t\t\t\t\t\t\t\t AND type <> 0", [$course_code, $row[0]->getsection(), $term, $year]); array_push($offerings, ['labs' => $sub->executeFetchAll(), 'lecture' => $row[0]]); } return $offerings; }