. */ $incdir = dirname(__FILE__) . DIRECTORY_SEPARATOR; include_once $incdir . 'class.course.inc'; include_once $incdir . 'class.section.php'; include_once $incdir . 'class.page.php'; require_once $incdir . 'school.inc'; /* * Load a Classes -> Course converter class for the sake of the * Schedule::__wakeup() magic function. */ require_once $incdir . 'class.classes_convert.inc'; /** * \brief * Finds possible Section combinations for a user's given Courses * and stores and displays the results. * * Represents a schedule of a week. Stores the classes that are part * of that week and calculates all the possible permutations. */ class Schedule { /* * Variables for upgrading from saved schedules created when there * was a class called Classes. */ private $classStorage; // array of courses private $nclasses; // Integer number of classes /* My member variables. */ private $courses; private $nPermutations = 0; // Integer number of real permutations private $possiblePermutations; // Integer number of possible permutations private $scheduleName; // String name of schedule private $storage; // Integer array of valid schedules /** * \brief * The school_id of the school this schedule was created for. */ private $school_id; /** * \brief * The semester this schedule was created for. * * The semester array is stored in full in a schedule because some * schools do not keep a backlog of all semesters for their course * data. Such a school is calvin. We want to be able to access, for * example, the friendly name and so on of a semester even one year * after the semester is created without worrying about having that * semester be stored in the autocomplete cache. */ private $semester; /* The
' . PHP_EOL . ' Edit' . PHP_EOL . ' Print' . PHP_EOL . ' ' . PHP_EOL; if ($schedule_store !== NULL && $this->parent_get() !== NULL && ($parent_schedule = schedule_store_retrieve($schedule_store, $this->parent_get())) !== NULL) echo ' Parent' . PHP_EOL; echo ' Home' . PHP_EOL . '
'. PHP_EOL . 'Having problems? Let us know.
' . PHP_EOL . 'Keyboard Shortcut: Left and right arrow keys switch between schedules
' . PHP_EOL; } echo "\n"; if($this->nPermutations > 0) { /* * Figure out if we have to deal with Saturday and then deal * with it. * * Also, ensure that our $time array is big enough for all of * these courses. */ $max_day_plusone = 5; $have_saturday = FALSE; $max_time = (int)max($time); $min_time = (int)min($time); $sort_time = FALSE; foreach ($this->courses as $course) { for ($si = 0; $si < $course->getnsections(); $si ++) foreach ($course->getSection($si)->getMeetings() as $meeting) { /* Saturdayness */ if ($meeting->getDay(5)) { $max_day_plusone = 6; $have_saturday = TRUE; } /* very late / very early classes */ while ((int)ltrim($meeting->getEndTime(), '0') > $max_time) { $max_time += $max_time + 30; while ($max_time % 100 >= 60) $max_time += 40; /* + 100 - 60 */ $time[] = $max_time; } while ((int)ltrim($meeting->getStartTime(), '0') < $min_time) { $max_time += 30; while ($min_time % 100 < 30) $min_time -= 40; /* + 60 - 100 */ $min_time -= 30; $time[] = $min_time; $sort_time = TRUE; } } } /* ensure that early times are actually first ;-) */ if ($sort_time) sort($time); echo '' . PHP_EOL . ' ' . PHP_EOL . ' Note: The registration information above corresponds to the sections' . PHP_EOL . ' displayed on the currently selected tab.' . PHP_EOL . ' ' . PHP_EOL . '
' . PHP_EOL . '' . PHP_EOL . ' ' . PHP_EOL . ' Disclaimer: You are responsible for' . PHP_EOL . ' double-checking the information you get from and input into slate_permutate' . PHP_EOL . ' when registering for classes. There is no guarantee that the harvested' . PHP_EOL . ' information is correct or that slate_permutate will handle' . PHP_EOL . ' the information you enter correctly.' . PHP_EOL . ' ' . PHP_EOL . '
' . PHP_EOL . '| ' . ($i + 1) . " | \n" . "Monday | \n" . "Tuesday | \n" . "Wednesday | \n" . "Thursday | \n" . "Friday | \n"; if ($have_saturday) echo "Saturday | \n"; echo "
| " . $this->prettyTime($time[$r]) . " | \n"; /* currently, 0-5 = monday-saturday */ for($dayLoop = 0; $dayLoop < $max_day_plusone; $dayLoop++) { /* Makes sure there is not a class already in progress */ if($rowspan[$dayLoop] <= 0) { for($j = 0; $j < count($this->courses); $j++) { $course = $this->courses[$j]; $section_index = $this->storage[$i][$j]; $section = $course->getSection($section_index); /* iterate through all of a class's meeting times */ $meetings = $section->getMeetings(); /* find any meeting which are going on at this time */ $current_meeting = NULL; foreach ($meetings as $meeting) { if ($meeting->getDay($dayLoop) && $meeting->getStartTime() >= $time[$r] && $meeting->getStartTime() < $time[$r+1]) { $current_meeting = $meeting; } } if ($current_meeting) { /* calculate how many rows this section should span */ for ($my_r = $r; $my_r < (count($time)-1) && $current_meeting->getEndTime() > $time[$my_r]; $my_r ++) ; $rowspan[$dayLoop] = $my_r - $r; $single_multi = 'single'; if ($rowspan[$dayLoop] > 1) $single_multi = 'multi'; $title = $course->title_get(); if (empty($title)) $title = ''; else $title .= ' '; $carret = ' ' . htmlentities("' . '' . htmlentities($title) . '' . PHP_EOL . htmlentities($course->getName(), ENT_QUOTES) . '-' . htmlentities($section->getLetter(), ENT_QUOTES) . "\n" . '' . htmlentities($current_meeting->instructor_get(), ENT_QUOTES) . "\n" . '' . htmlentities($current_meeting->getLocation(), ENT_QUOTES) . "\n" . '' . htmlentities($section->getSynonym(), ENT_QUOTES) . "\n" . " | \n"; /* for the ``Registration Codes'' dialogue: */ if (empty($permutations_courses[$j])) { $singleton_course = new Course($course->getName(), $course->title_get()); $singleton_course->section_add($section); $permutation_courses[$j] = $singleton_course->to_json_array(); } $filled = TRUE; } } } if ($rowspan[$dayLoop] > 0) { $filled = TRUE; $rowspan[$dayLoop] --; } /* If the cell was not filled, fill it with an empty cell. */ if(!$filled) { echo "\n"; } $filled = FALSE; } // End of row echo " | 
There are no possible schedules. Please try again.
'; } echo "There were a total of " . $this->possiblePermutations . " possible permutations. Only " . $this->nPermutations . " permutations had no class conflicts.
"; $outputPage->foot(); } //-------------------------------------------------- // Changes the title of the page. //-------------------------------------------------- function changeTitle($t) { $this->title = $t; } //-------------------------------------------------- // Make the time "pretty" //-------------------------------------------------- function prettyTime($t){ if($t >= 1200) { if ($t > 1259) $t = ($t - 1200); return substr($t, 0, strlen($t)-2) . ":" . substr($t, strlen($t)-2, strlen($t)) . " PM"; } else { return substr($t, 0, strlen($t)-2) . ":" . substr($t, strlen($t)-2, strlen($t)) . " AM"; } } /** * \brief * fetch the number of classes */ function nclasses_get() { return count($this->courses); } /** * \brief * fetch a specified class by its key */ function class_get($class_key) { return $this->courses[$class_key]; } /** * \brief * Set my global ID. * * Only to be called by schedule_store_store(). */ function id_set($id) { $this->id = $id; } /* * \brief * Get my global ID. */ function id_get() { return $this->id; } /** * \brief * Write out a relative URL for a particular schedule. * * Takes into account the $clean_urls setting. * * \param $id * The ID of the schedule to link to. Defaults to the current schedule object. * \param $page * The page of the schedule to link to. Defaults to 0. * \return * A string, the URL used to access this schedule. Remember that * if this string is inserted into an XHTML document, * htmlentities() must be called on it. */ function url($id = NULL, $page = 0) { global $clean_urls; $url = ''; if (!$clean_urls) $url .= 'process.php?s='; if (!$id) $id = $this->id; $url .= (int)$id; if ($clean_urls) $url .= '?'; else $url .= '&'; if ($page) $url .= 'page=' . (int)$page . '&'; return $url; } /** * \brief * Get the ID of the schedule from which this schedule was * derived. */ public function parent_get() { return $this->parent_id; } /** * \brief * A magic function which tries to upgrade old serialized sections * to the new format. */ function __wakeup() { if ($this->nclasses == -1) /* this Schedule doesn't need to be upgraded from Classes to Course */ return; $this->courses = array(); foreach ($this->classStorage as $classes) { $this->courses[] = $classes->to_course(); } $this->nclasses = -1; if (empty($this->parent_id)) $this->parent_id = NULL; if (empty($this->school_id)) { /* Ensure we have $_SESSION. */ page::session_start(); $school = school_load_guess(FALSE); $this->school_id = $school['id']; } if (empty($this->semester)) { if (empty($school)) { /* Ensure we have $_SESSION. */ page::session_start(); $school = school_load($this->school_id); $this->semester = school_semester_guess($school); } } } }