$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(); $alternatives = array(); $endIndex = 0; /* Course selection algorithm: