# HG changeset patch # User Nathan Phillip Brink # Date 2010-10-09 01:54:03 # Node ID d903bd3d579e5c9ba361d6cad8048535d9da2eb7 # Parent 9032b77926d8f8f3d6e978c3fdd5818b072c9337 Add school profiles support. Currently, the only significant thing school profiles does is provide a different blog of HTML at the bottom of the input.php page so that users may receive school-specific instructions on how to use slate_permutate. School profiles _will_ be extended to provide autocompletion of sections for a specific course based on previously crawling a college's registration website. All-in-all, it maintains a simple school_id string which can be used by other components to uniquely identify a school for any arbitrary purpose. diff --git a/.hgignore b/.hgignore --- a/.hgignore +++ b/.hgignore @@ -2,6 +2,8 @@ style: regex # ignore all saved schedules, but keep track of the .keep file. ^saved_schedules/[^.] +# ignore all of cache except for the .keep file +^cache/[^.] # ignore common unwanted suffixes (~|\.orig|\.rej)$ diff --git a/admin/rehash.php b/admin/rehash.php new file mode 100755 --- /dev/null +++ b/admin/rehash.php @@ -0,0 +1,153 @@ +#!/usr/bin/env php + + * + * This file is a part of slate_permutate. + * + * slate_permutate is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * slate_permutate is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with slate_permutate. If not, see . + */ + +/** + * \file + * + * Runs through schools.d grabbing and caching data, such as the + * school listing used for the ``choose your school list''. + */ + +require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'school.inc'); +return main($argc, $argv); + +function main($argc, $argv) +{ + $school_id_list = school_list(); + if (!$school_id_list) + return 1; + + $schools = array(); + foreach ($school_id_list as $school_id) + { + $school = school_load($school_id); + if (!$school) + { + fprintf(STDERR, "Error loading school with school_id=%s\n", + $school_id); + return 1; + } + $schools[] = $school; + } + + if (school_cache($schools)) + { + fprintf(STDERR, "Error writing out school cache\n"); + return 1; + } + + return 0; +} + +/* + * functions which are only needed when recreating the cache. + */ + +/** + * \brief + * Returns the list of available school IDs or NULL on error. + */ +function school_list() +{ + $schoold_dir_name = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'school.d'; + $schoold_dir = opendir($schoold_dir_name); + if ($schoold_dir === FALSE) + { + fprintf(STDERR, "Unable to open school.d directory. Was using path: `%s'\n", + $schoold_dir_Name); + return NULL; + } + + $school_id_list = array(); + while ($filename = readdir($schoold_dir)) + { + if (!preg_match('/^([a-z0-9]+)\.inc$/', $filename, $matches)) + continue; + + $school_id_list[] = $matches[1]; + } + + closedir($schoold_dir); + + return $school_id_list; +} + +/** + * \brief + * Write out the cache file which remembers the list of available + * schools. + * + * \todo + * If the list of displayed schools is to be sorted, this is the + * place to do it. + * + * \param $schools + * An array of school handles. + */ +function school_cache($schools) +{ + $list_cache = array(); + $domain_cache = array(); + foreach ($schools as $school) + { + $list_cache[$school['id']] = array( + 'name' => $school['name'], + 'url' => $school['url'], + ); + foreach ($school['domains'] as $school_domain) + { + $domain_cache_ptr =& $domain_cache; + + $domain_parts = array_reverse(explode('.', $school_domain)); + while (count($domain_parts) > 1) + { + $domain_part = array_shift($domain_parts); + if (!isset($domain_cache_ptr[$domain_part]) + || !is_array($domain_cache_ptr[$domain_part])) + $domain_cache_ptr[$domain_part] = array(); + $domain_cache_ptr =& $domain_cache_ptr[$domain_part]; + } + /* + * get the last part which is unambiguously identifies this + * school combined with the previous parts + */ + $domain_part = array_shift($domain_parts); + $domain_cache_ptr[$domain_part] = $school['id']; + } + } + + $cache = array('list' => $list_cache, 'domains' => $domain_cache); + + + $cache_file_name = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' + . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'schools'; + $cache_file = fopen($cache_file_name, 'wb'); + if ($cache_file === FALSE) + { + fprintf(STDERR, "Unable to open `%s' for writing\n", + $cache_file_name); + return 1; + } + fwrite($cache_file, serialize($cache)); + fclose($cache_file); + + return 0; +} diff --git a/cache/.keep b/cache/.keep new file mode 100644 diff --git a/inc/class.page.php b/inc/class.page.php --- a/inc/class.page.php +++ b/inc/class.page.php @@ -29,8 +29,13 @@ class page private $pagetitle = ''; // Title of page private $scripts = array(); // Scripts to include on page + /* the current school. See get_school(). */ + private $school; + public function __construct($ntitle, $nscripts = array(), $immediate = TRUE) { + require_once('school.inc'); + // Scripts and styles available to include $this->headCode['jQuery'] = '', TRUE); $inputPage->head(); + +/* + * Force a student to choose a school or declare he's a generic + * student before displaying the input form. + */ +$school = $inputPage->get_school(); +if ($_REQUEST['setted'] == 1 || $school['id'] != 'default') + $_SESSION['school_setted'] = TRUE; +if ($_REQUEST['selectschool'] == 1 + || $school['id'] == 'default' && !isset($_SESSION['school_setted'])) + { +?> +

School Selection

+

+ Choose the school you attend from the list below. If you cannot + find your school, you may proceed using + the generic + settings. +

+showSchools('input.php?setted=1'); + $inputPage->foot(); + exit; + } + $inputPage->showSavedScheds($_SESSION); ?> -

Welcome to SlatePermutate! To get started, enter in some of your classes, and add available sections for each class.

+

+ Welcome to SlatePermutateaddressStudent(', ', '', + FALSE); ?>! (Not from ?) To get started, enter in some of your + classes, and add available sections for each class. +

Keyboard Shortcut: Press "c" to add a class


@@ -82,4 +112,5 @@ var sectionsOfClass = Array();

 


Advanced

*/ ?> showSchoolInstructions(); $inputPage->foot(); diff --git a/school.d/calvin.inc b/school.d/calvin.inc new file mode 100644 --- /dev/null +++ b/school.d/calvin.inc @@ -0,0 +1,52 @@ + + * + * This file is a part of slate_permutate. + * + * slate_permutate is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * slate_permutate is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with slate_permutate. If not, see . + */ + +function calvin_info() +{ + return array('name' => 'Calvin College', + 'url' => 'http://calvin.edu/', + /* + * rDNS postfixes which indicate a student is + * connecting from that college campus + */ + 'domains' => array( + 'calvin.edu', + ), + 'student_address' => 'Knight', + ); +} + +function calvin_instructions_html() +{ + return <<Calvin-specific Instructions +

+ slate_permutate can be a useful tool for scheduling your next semester at Calvin College. +

+
    +
  1. Get in touch with your advisor during advising/reading recess.
  2. +
  3. Look up each class your advisor specified in Calvin's registration page of KnightVision (soon to be moo).
  4. +
  5. Enter each class into a slate_permutate schedule and add each section that is listed that you are willing to take.
  6. +
  7. Submit your schedule and view all of the different permutations of your schedule which would work with the sections you specified.
  8. +
  9. Print our your preferred schedule by selecting a schedule an choosing your User-Agent's print option.
  10. +
  11. Wait until it's your turn to register and grab your preferred sections before they fill up!
  12. +
+EOF; +} diff --git a/school.d/default.inc b/school.d/default.inc new file mode 100644 --- /dev/null +++ b/school.d/default.inc @@ -0,0 +1,52 @@ + + * + * This file is a part of slate_permutate. + * + * slate_permutate is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * slate_permutate is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with slate_permutate. If not, see . + */ + +function default_info() +{ + return array('name' => 'Generic College', + 'url' => 'http://example.edu/', + /* + * rDNS postfixes which indicate a student is + * connecting from that college campus. + */ + 'domains' => array( + ), + 'student_address' => 'student', + ); +} + +function default_instructions_html() +{ + return <<Generic Instructions +

+ slate_permutate can be a useful tool for scheduling your next semester at the college you attend. +

+
    +
  1. Get in touch with your advisor and find out what courses you need to take next semester.
  2. +
  3. Look up each course which your advisor specified in your college's course catalog. Note the different sectxions for each course..
  4. +
  5. Enter each course into a slate_permutate schedule. For each course, add the sections listed in your school's course catalogue (at your discretion).
  6. +
  7. Submit your list of courses and their sections. Let slate_permutate perform its magic.
  8. +
  9. View all of the different permutations of your schedule and find a few that work for you.
  10. +
  11. Print our your preferred schedule by selecting a schedule an choosing your User-Agent's print option.
  12. +
  13. Wait until it's your turn to register and grab your preferred sections before they fill up!
  14. +
+EOF; +}