Changeset - 828706182e2f
[Not reviewed]
default
0 6 0
Nathan Brink (binki) - 15 years ago 2011-03-22 22:21:49
ohnobinki@ohnopublishing.net
Add support for entering, storing, and displaying a course title per bug 95.
6 files changed with 126 insertions and 54 deletions:
0 comments (0 inline, 0 general)
inc/class.course.inc
Show inline comments
 
@@ -20,44 +20,50 @@
 

	
 
/**
 
 * \file
 
 *    This file represents a course (formerly class). It stores
 
 *    the section associated with the course.
 
 */
 

	
 
include_once 'class.section.php';
 

	
 
class Course implements IteratorAggregate
 
{
 
  private $name;	// String
 
  private $title;
 
  private $sections;	// Array of sections
 
  private $nsections;	// int
 
  /**
 
   * \brief
 
   *   Other courses that this course depends on.
 
   *
 
   * Example: Many calvin courses depend on lab courses.
 
   */
 
  private $dependencies;
 

	
 
  /**
 
   * \brief
 
   *    Creates a class with the given name.
 
   * \param $n
 
   *    The name of the class.
 
   * \param $course_id
 
   *    The identifier of the class. Ex., MATH-101 in
 
   *    MATH-101-A. Retrieved with Course::getName().
 
   * \param $title
 
   *    The human-friendly course title, such as 'Introduction to
 
   *    Algebra', or NULL.
 
   */
 
  function __construct($n)
 
  function __construct($course_id, $title = NULL)
 
  {
 
    $this->sections = array();
 
    $this->name = $n;
 
    $this->name = $course_id;
 
    $this->title = $title;
 
    $this->nsections = 0;
 
    $this->dependencies = array();
 
  }
 
	
 
  /**
 
   * \brief
 
   *   Adds an already-instantiated section to this class.
 
   */
 
  public function section_add(Section $section)
 
  {
 
    $this->sections[$this->nsections] = $section;
 
    $this->nsections++;
 
@@ -119,24 +125,37 @@ class Course implements IteratorAggregat
 
   * \brief
 
   *    Returns the name of the class.
 
   * \return
 
   *    The name of the class.
 
   */
 
  public function getName()
 
  {
 
    return $this->name;
 
  }
 

	
 
  /**
 
   * \brief
 
   *   Retrieve the human-friendly course title.
 
   *
 
   * \return
 
   *   A string, the human-friendly course title, or NULL if there is
 
   *   no title.
 
   */
 
  public function title_get()
 
  {
 
    return $this->title;
 
  }
 

	
 
  /**
 
   * \brief
 
   *   Add a dependency on another course.
 
   *
 
   * \param $course
 
   *   The other course to depend on.
 
   */
 
  public function dependency_add(Course $course)
 
  {
 
    $this->dependencies[] = $course;
 
  }
 

	
 
  /**
 
   * \brief
 
@@ -180,24 +199,25 @@ class Course implements IteratorAggregat
 
   *
 
   * \param $recursion_trace
 
   *   Only for internal use. Used to prevent infinite recursion.
 
   */
 
  public function to_json_array(array $recursion_trace = array())
 
  {
 
    if (!empty($recursion_trace[$this->getName()]))
 
      return NULL;
 
    $recursion_trace[$this->getName()] = TRUE;
 

	
 
    $json_array = array(
 
			'class' => $this->getName(),
 
			'title' => $this->title_get(),
 
			'sections' => array(),
 
			'dependencies' => array(),
 
			);
 
    foreach ($this->sections as $section)
 
      {
 
	$section_json_arrays = $section->to_json_arrays();
 
	foreach ($section_json_arrays as $section_json_array)
 
	  $json_array['sections'][] = $section_json_array;
 
      }
 

	
 
    foreach ($this->dependencies as $dependency)
 
      {
 
@@ -212,34 +232,40 @@ class Course implements IteratorAggregat
 
  /**
 
   * \brief
 
   *   Produce a Course object based on a JSON array compatible with
 
   *   the output of Course::to_json_array().
 
   *
 
   * \param $json
 
   *   The JSON array to parse.
 
   * \return
 
   *   A Course.
 
   */
 
  public static function from_json_array($json)
 
  {
 
    $course = new Course($json['class']);
 
    $title = NULL;
 
    if (!empty($json['title']))
 
      $title = $json['title'];
 
    $course = new Course($json['class'], $title);
 

	
 
    if (!empty($json['sections']))
 
      $course->section_add(Section::from_json_arrays($json['sections']));
 
    
 
    if (!empty($json['dependencies']))
 
      foreach ($json['dependencies'] as $dependency)
 
	$course->dependency_add(Course::from_json_array($dependency));
 

	
 
    return $course;
 
  }
 

	
 
  /**
 
   * \brief
 
   *   Upgrade a course class to a newer version of that class.
 
   */
 
  public function __wakeup()
 
  {
 
    if (!isset($this->dependencies))
 
      $this->dependencies = array();
 

	
 
    if (!isset($this->title))
 
      $this->title = NULL;
 
  }
 
}
inc/class.schedule.php
Show inline comments
 
@@ -91,30 +91,31 @@ class Schedule
 
    /* mark this as an upgraded Schedule class. See __wakeup() */
 
    $this->nclasses = -1;
 
  }
 

	
 
  //--------------------------------------------------
 
  // Mutators and Accessors
 
  //--------------------------------------------------
 
  public function getName()
 
  {
 
    return $this->scheduleName;
 
  }    
 

	
 
  //--------------------------------------------------
 
  // Adds a new class to the schedule.
 
  //--------------------------------------------------
 
  function addCourse($n)
 
  /**
 
   * \brief
 
   *   Adds a new class to the schedule.
 
   */
 
  function addCourse($course_id, $title)
 
  {
 
    $this->courses[] = new Course($n);
 
    $this->courses[] = new Course($course_id, $title);
 
  }
 

	
 
  /**
 
   * \brief
 
   *   Adds a section to this semester after finding the class.
 
   *
 
   * \return
 
   *   NULL on success, a string on error which is a message for the
 
   *   user and a valid XHTML fragment.
 
   */
 
  function addSection($course_name, $letter, $time_start, $time_end, $days, $synonym = NULL, $faculty = NULL, $location = NULL, $type = 'lecture')
 
  {
 
@@ -404,24 +405,25 @@ class Schedule
 
	/* ensure that early times are actually first ;-) */
 
	if ($sort_time)
 
	  sort($time);
 

	
 
        echo '    <div id="regDialog" title="Registration Codes">' . PHP_EOL
 
	  . '      <div id="regDialog-content"></div>' . PHP_EOL
 
	  . '      <p id="regDialog-disclaimer" class="graytext"><em>Note: The registration information above corresponds to the sections displayed on the currently selected tab.</em></p>'
 
	  . '    </div>';
 
	echo '<div id="tabs">' . "\n" .
 
               '<div id="show-box" class="show-buttons">
 
                  <form action="#"><p class="nospace">
 
                    <label><strong>Display:</strong></label>
 
                    <input id="show-course-title" name="show-course-title" type="checkbox" /><label for="show-course-title">Course Title</label>
 
                    <input id="show-prof" name="show-prof" type="checkbox" checked="checked" /><label for="show-prof">Professor</label>
 
                    <input id="show-location" name="show-location" type="checkbox" /><label for="show-location">Room</label>
 
                    <input id="show-synonym" name="show-synonym" type="checkbox" /><label for="show-synonym">Synonym</label>
 
                    <span id="regCodes"><label><a href="#"><strong>Register for Classes</strong></a></label></span></p>
 
                  </form>';
 

	
 
          echo '</div> <!-- id="show-box" -->'
 
	     . '<div id="the-tabs"><ul>' . "\n";
 
			
 
	for($nn = $first_permutation + 1; $nn <= $last_permutation; $nn++)
 
	  {
 
	    echo  "<li><a href=\"#tabs-" . $nn . "\">&nbsp;" . $nn . "&nbsp;</a></li>\n";
 
@@ -477,27 +479,27 @@ class Schedule
 

	
 
		echo "          <tr>\n"
 
		  . "            <td class=\"time\">" . $this->prettyTime($time[$r]) . "</td>\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++)
 
			{
 
			  $class = $this->courses[$j];
 
			  $course = $this->courses[$j];
 
			  $section_index = $this->storage[$i][$j];
 
			  $section = $class->getSection($section_index);
 
			  $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;
 
@@ -508,40 +510,47 @@ class Schedule
 
				    {
 
				      /* 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 .= ' ';
 
				      echo '            <td rowspan="' . $rowspan[$dayLoop]
 
					. '" class="' . $single_multi . ' class' . $j
 
					. '" title="prof: ' . htmlentities($section->getProf(), ENT_QUOTES)
 
					. '" title="' . htmlentities($title, ENT_QUOTES)
 
					. 'prof: ' . htmlentities($section->getProf(), ENT_QUOTES)
 
					. ', room: ' . htmlentities($current_meeting->getLocation(), ENT_QUOTES)
 
					. ', type: ' . htmlentities($current_meeting->type_get(), ENT_QUOTES) . '">'
 
					. htmlentities($class->getName(), ENT_QUOTES) . '-'
 
					. '<span class="course-title block">' . htmlentities($title) . '</span>' . PHP_EOL
 
					. htmlentities($course->getName(), ENT_QUOTES) . '-'
 
					. htmlentities($section->getLetter(), ENT_QUOTES) . "\n"
 
					. '<span class="prof block">' . htmlentities($section->getProf(), ENT_QUOTES) . "</span>\n"
 
					. '<span class="location block">' . htmlentities($current_meeting->getLocation(), ENT_QUOTES) . "</span>\n"
 
					. '<span class="synonym block">' . htmlentities($section->getSynonym(), ENT_QUOTES) . "</span>\n"
 
					. "</td>\n";
 

	
 
				      /* for the ``Registration Codes'' dialogue: */
 
				      if (empty($permutations_courses[$j]))
 
					{
 
					  $singleton_course = new Course($course->getName());
 
					  $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;
 
@@ -551,26 +560,24 @@ class Schedule
 
		  /* If the cell was not filled, fill it with an empty cell. */
 
			if(!$filled)
 
			{
 
				echo "            <td class=\"none\">&nbsp;</td>\n";
 
			}
 
			$filled = FALSE;
 
		}
 
		
 
		// End of row
 
		echo "          </tr>\n";
 
	      }
 

	
 
	    /* presort */
 
	    ksort($permutation_courses);
 
	    // End of table
 
	    echo "        </table>\n"
 
              . '         <span class="course-data">'.  htmlentities(json_encode($permutation_courses)) . "</span>\n"
 
	      . '      </div> <!-- id="section' . ($i + 1) . "\" -->\n";
 
	  }
 

	
 
          echo "    </div> <!-- class=\"scontent\" -->\n"
 
	     . "  </div> <!-- class=\"scroller\" -->\n"
 
	     . "</div> <!-- id=\"my-glider\" -->\n"
 
	     . $footcloser; // Closes off the content div
 
      } else {
 
      echo '<html><body><p>There are no possible schedules. Please <a href="input.php?s='.$this->id.'">try again</a>.</p></body></html>';
input.php
Show inline comments
 
@@ -62,28 +62,31 @@ if ($sch)
 
{
 
  $nclasses = $sch->nclasses_get();
 
  for ($class_key = 0; $class_key < $nclasses; $class_key ++)
 
    {
 
      $my_hc .= input_class_js($sch->class_get($class_key), '    ');
 
    }
 
}
 
elseif ($errors_fix)
 
  {
 
    foreach ($_POST['postData'] as $course)
 
      if (is_array($course))
 
	{
 
	  $title = '';
 
	  if (!empty($course['title']))
 
	    $title = $course['title'];
 
	  if (empty($course['name']))
 
	    $my_hc .= '    class_last = add_class();' . PHP_EOL;
 
	  else
 
	    $my_hc .= '    class_last = add_class_n(\'' . htmlentities($course['name'], ENT_QUOTES) . '\');' . PHP_EOL;
 
	    $my_hc .= '    class_last = add_class_n(\'' . htmlentities($course['name'], ENT_QUOTES) . '\', \'' . htmlentities($title, ENT_QUOTES) . '\');' . PHP_EOL;
 
	  foreach ($course as $section)
 
	    if (is_array($section))
 
	      $my_hc .= '    add_section_n(class_last, \'' . htmlentities($section['letter'], ENT_QUOTES) . '\', \''
 
		. htmlentities($section['synonym'], ENT_QUOTES) . '\', \'' . htmlentities($section['start'], ENT_QUOTES) . '\', \''
 
		. htmlentities($section['end'], ENT_QUOTES) . '\', '
 
		. json_encode(array('m' => !empty($section['days'][0]), 't' => !empty($section['days'][1]), 'w' => !empty($section['days'][2]),
 
				    'h' => !empty($section['days'][3]), 'f' => !empty($section['days'][4]),
 
				    's' => !empty($section['days'][5])))
 
		. ', \'' . htmlentities($section['professor'], ENT_QUOTES) . '\', \''
 
		. htmlentities($section['location'], ENT_QUOTES) . '\', \''
 
		. htmlentities($section['type'], ENT_QUOTES) . '\');' . PHP_EOL;
 
	  $my_hc .= PHP_EOL;
 
@@ -236,32 +239,36 @@ if (!empty($_REQUEST['selectsemester']))
 
</form>
 

	
 
<?php 
 

	
 
/* Show/hide Advanced Options: <p><span id="showadvanced" style="margin-left: 1em;"><a href="#">Advanced</a></span></p> */ 
 
?>
 
<div id="showInstructions" style="width: 100%; text-align: center;"><a href="#">Detailed Instructions...</a></div>
 

	
 
<?php
 
$inputPage->showSchoolInstructions();
 
$inputPage->foot();
 

	
 
function input_class_js(Course $class, $whitespace = '  ')
 
function input_class_js(Course $course, $whitespace = '  ')
 
{
 
  $js = $whitespace . 'class_last = add_class_n(\'' . htmlentities($class->getName(), ENT_QUOTES) . "');\n";
 
  $title = $course->title_get();
 
  if (empty($title))
 
    $title = '';
 
  $js = $whitespace . 'class_last = add_class_n(\'' . htmlentities($course->getName(), ENT_QUOTES) . '\', \''
 
    . htmlentities($title, ENT_QUOTES) . "');\n";
 

	
 
  $nsections  = $class->getnsections();
 
  $nsections  = $course->getnsections();
 
  for ($section_key = $nsections - 1; $section_key >= 0; $section_key --)
 
    {
 
      $section = $class->getSection($section_key);
 
      $section = $course->getSection($section_key);
 
      $meetings = $section->getMeetings();
 
      foreach ($meetings as $meeting)
 
	{
 
	  $js .= $whitespace . 'add_section_n(class_last, \'' . htmlentities($section->getLetter(), ENT_QUOTES) . '\', \''
 
	    . htmlentities($section->getSynonym(), ENT_QUOTES) . '\', \''
 
	    . $meeting->getStartTime() . '\', \''
 
	    . $meeting->getEndTime() . '\', '
 
	    . json_encode(array('m' => $meeting->getDay(0), 't' => $meeting->getDay(1), 'w' => $meeting->getDay(2), 'h' => $meeting->getDay(3), 'f' => $meeting->getDay(4),
 
				's' => $meeting->getDay(5))) . ', \''
 
	    . htmlentities($section->getProf(), ENT_QUOTES) . '\', \''
 
	    . htmlentities($meeting->getLocation(), ENT_QUOTES) . '\',\''
 
	    . htmlentities($meeting->type_get(), ENT_QUOTES) . "');\n";
process.php
Show inline comments
 
@@ -153,41 +153,44 @@ if(!$DEBUG)
 
	if (!empty($_POST['postData']['parent_schedule_id']))
 
	  {
 
	    $parent_schedule_id = (int)$_POST['postData']['parent_schedule_id'];
 
	    $parent_schedule = schedule_store_retrieve($schedule_store, $parent_schedule_id);
 
	    /* Detect bad parent_schedule reference. */
 
	    if (empty($parent_schedule))
 
	      $parent_schedule_id = NULL;
 
	  }
 

	
 
	$allClasses = new Schedule($name, $parent_schedule_id);
 

	
 
	$errors = array();
 
		foreach($_POST['postData'] as $class)
 
		{
 
		  /*
 
		   * Only add classes if the user added at least one
 
		   * section to the class. We know that $class['name']
 
		   * is not a section, so count() needs to be > 1 and
 
		   * we need to skip over 'name' in our loop.
 
		   */
 
			if(is_array($class) && count($class) > 1)
 
			{
 
				$allClasses->addCourse($class['name']);
 
		
 
				foreach($class as $section)
 
	foreach($_POST['postData'] as $course)
 
	  {
 
	    /*
 
	     * Only add classes if the user added at least one
 
	     * section to the class. We know that $course['name']
 
	     * is not a section, so count() needs to be > 1 and
 
	     * we need to skip over 'name' in our loop.
 
	     */
 
	    if(is_array($course) && count($course) > 1)
 
	      {
 
		if (empty($course['title']))
 
		  $course['title'] = '';
 

	
 
		$allClasses->addCourse($course['name'], $course['title']);
 

	
 
				foreach($course as $section)
 
				  /* Skip the section name, which isn't a section */
 
					if(is_array($section))
 
					  {
 
					    $error_string = $allClasses->addSection($class['name'], $section['letter'], $section['start'], $section['end'], arrayToDays(empty($section['days']) ? array() : $section['days'], 'alpha'), $section['synonym'], $section['professor'], $section['location'], $section['type']);
 
					    $error_string = $allClasses->addSection($course['name'], $section['letter'], $section['start'], $section['end'], arrayToDays(empty($section['days']) ? array() : $section['days'], 'alpha'), $section['synonym'], $section['professor'], $section['location'], $section['type']);
 
					    if ($error_string !== NULL)
 
					      $errors[] = $error_string;
 
					  }
 
			}
 
		}
 

	
 
		/*
 
		 * Tell the user that his input is erroneous and
 
		 * require him to fix it.
 
		 */
 
		if (count($errors))
 
		  {
school.d/umich.crawl.inc
Show inline comments
 
@@ -11,35 +11,35 @@
 
 *
 
 * SlatePermutate 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 SlatePermutate.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 

	
 
/** Filter out whitepace items */
 
function umich_arrayfilter_callback($item){
 
    if(ltrim($item) == ''){
 
      return false;
 
    }
 
    else{
 
      return true;
 
    }
 
function umich_arrayfilter_callback($item)
 
{
 
  if(ltrim($item) == '')
 
    return TRUE;
 
  else
 
    return TRUE;
 
}
 

	
 
/** Parse html at URL into array, first row is row headers */
 
function umich_table_parse($url) {
 
function umich_table_parse($url)
 
{
 
  $arr = array();
 
  $dom = new DOMDocument;
 
  $html = file_get_contents($url);
 
  if(!$html){
 
    return 1;
 
  }
 
  $dom->loadHTML($html);
 
  $dom->preserveWhiteSpace = false;
 
  $tables = $dom->getElementsByTagName('table');
 
  $rows = $tables->item(3)->getElementsByTagName('tr'); // Get first table on page 
 
  foreach ($rows as $rownum => $row) {
 
    if($rownum > 5) {
 
@@ -55,27 +55,44 @@ function umich_table_parse($url) {
 

	
 
  $arr = array_values($arr); // Reindex array
 
 
 
  // Strip navigation and trailing garbage
 
  $arr[count($arr)-3] = NULL;
 
  $arr[count($arr)-2] = NULL;
 
  $arr[count($arr)-1] = NULL;
 

	
 
  $arr = array_filter($arr);
 
  return $arr;
 
}
 

	
 
/** Crawls uMich course listings. $season is "f" or "s", year is 2-digit year */
 
function umich_crawl($semester)
 
/**
 
 * \brief
 
 *  Crawls University of Michigan's schedule.
 
 *
 
 * \param $semesters
 
 *   An array to be filled with semesters.
 
 * \param $school_crawl_log
 
 *   The school_crawl_log handle.
 
 * \return
 
 *   1 on failure, 0 on success.
 
 */
 
function umich_crawl(array &$semesters, $school_crawl_log)
 
{
 
  $url = 'http://lsa.umich.edu/cg/cg_advsearch.aspx';
 
  $cookies = array();
 

	
 
  /* determine list of semesters: */
 
  $semesters_dom = new DOMDocument();
 
  $semesters_dom->loadHTML(school_crawl_geturi($url, $cookies, $school_crawl_log));
 

	
 
  $year = substr($semester->year_get(), 2);
 
  $season = strtolower(substr($semester->season_get(), 0, 1));
 

	
 
  /* Current academic departments. Update as needed. */
 
  $departments = array('AAPTIS','ACABS','AERO','AEROSP','AMCULT','ANTHRARC','ANTHRBIO','ANTHRCUL','AOSS','APPPHYS','ARCH','ARMENIAN','ARTDES','ASIAN','ASIANLAN','ASTRO','AUTO','BCS','BIOINF','BIOLCHEM','BIOLOGY','BIOMEDE','BIOPHYS','CAAS','CEE','CHE','CHEM','CIC','CICS','CJS','CLARCH','CLCIV','CMPLXSYS','COMM','COMP','COMPLIT','CSP','CZECH','DANCE','DUTCH','ECON','EDCURINS','EDUC','EEB','EECS','ELI','ENGLISH','ENGR','ENSCEN','ENVIRON','ESENG','FRENCH','GEOG','GEOSCI','GERMAN','GREEK','GTBOOKS','HBEHED','HISTART','HISTORY','HJCS','HMP','HONORS','INTMED','IOE','ITALIAN','JAZZ','JUDAIC','KINESLGY','LACS','LATIN','LHC','LHSP','LING','MACROMOL','MATH','MATSCIE','MCDB','MECHENG','MEDADM','MEDCHEM','MEMS','MENAS','MFG','MICROBIOL','MILSCI','MKT','MODGREEK','MOVESCI','MUSEUMS','MUSICOL','MUSMETH','MUSTHTRE','NAVARCH','NAVSCI','NERS','NEUROSCI','NRE','NURS','OMS','ORGSTUDY','PAT','PATH','PHARMACY','PHIL','PHRMACOL','PHYSICS','PHYSIOL','POLISH','POLSCI','PORTUG','PSYCH','PUBHLTH','PUBPOL','RCARTS','RCCORE','RCHUMS','RCIDIV','RCLANG','RCNSCI','RCSSCI','REEES','RELIGION','ROMLANG','ROMLING','RUSSIAN','SAC','SAS','SCAND','SEAS','SI','SLAVIC','SOC','SPANISH','STATS','STDABRD','SWC','TCHNCLCM','THEORY','THTREMUS','UC','UKRAINE','UP','WOMENSTD','YIDDISH');
 

	
 
  $basepath = "http://www.lsa.umich.edu/cg/cg_results.aspx";
 
  $yearsyn = 1800 + $year; // Weird year synonym name where 2000 == 1800
 
  $basepath .= "?termArray={$season}_{$year}_${yearsyn}&cgtype=ug";
 
  $season = strtolower($season);
 
  $tables = array();
 
  foreach($departments as $department) {
scripts/scheduleInput.js
Show inline comments
 
@@ -206,62 +206,74 @@ function add_section(cnum)
 
    var section_i = add_section_n(cnum, '', '', '', '', {m: false, t: false, w: false, h: false, f: false, s: false}, '', '', '');
 
    if (cnum == slate_permutate_course_free)
 
	course_free_check(cnum);
 
    return section_i;
 
}
 

	
 
/**
 
 * Add a list of sections gotten via an AJAX call.
 
 */
 
function add_sections(cnum, data)
 
{
 
    var i;
 

	
 
    if (data.title)
 
	jQuery('.pclass' + cnum + ' .course-title-entry').val(data.title);
 

	
 
    if (!data.sections)
 
	return;
 
    /*
 
     * we get the sections in the correct order. For the user to see
 
     * them in the correct order, we must reverse the add_setion_n()
 
     * calls.
 
     */
 
    for (i = data.sections.length - 1; i >= 0; i --)
 
	{
 
	    section = data.sections[i];
 
	    add_section_n(cnum, section.section, section.synonym, section.time_start, section.time_end, section.days, section.prof, section.location, section.type);
 
	}
 

	
 
    /*
 
     * Handle course-level interdependencies.
 
     */
 
    if (data.dependencies)
 
	jQuery.each(data.dependencies, function(i, dep)
 
		    {
 
			var new_course_num = add_class_n(dep['class']);
 
			var new_course_num = add_class_n(dep['class'], dep['title'] ? dep['title'] : '');
 
			add_sections(new_course_num, dep);
 
		    });
 
}
 

	
 
	//--------------------------------------------------
 
	// Adds a new class to the input.
 
	//--------------------------------------------------
 
	function add_class_n(name)
 
/**
 
 * \brief
 
 *   Adds a new class to the input.
 
 *
 
 * \param course_id
 
 *   The course_id.
 
 * \param title
 
 *   The human-friendly course title.
 
 * \return
 
 *   The javascript-local course entry identifying number.
 
 */
 
function add_class_n(course_id, title)
 
	{
 
	    /*
 
	     * If we're adding a course entry form with preadded
 
	     * content, first remove the empty course.
 
	     */
 
	    if (name.length && slate_permutate_course_free != -1)
 
	    if (course_id.length && slate_permutate_course_free != -1)
 
		course_remove(slate_permutate_course_free);
 

	
 
		sectionsOfClass[classNum] = 0; // Initialize at 0
 
		jQuery('#jsrows').append('<tr id="tr-course-' + classNum + '" class="class class' + classNum + ' pclass' + classNum + '"><td class="nameTip"><input type="text" id="input-course-' + classNum + '" class="classRequired defText className'+classNum+' className" title="Class Name" name="postData[' + classNum + '][name]" value="' + name + '" /></td><td colspan="10"></td><td class="tdInput"><div class="deleteClass"><input type="button" value="Remove" class="gray" /></div></td><td class="none"><button type="button" class="addSection gray">+</button></td></tr>');
 
		jQuery('#jsrows').append('<tr id="tr-course-' + classNum + '" class="class class' + classNum + ' pclass' + classNum + '"><td class="nameTip"><input type="text" id="input-course-' + classNum + '" class="classRequired defText className'+classNum+' className" title="Class Name" name="postData[' + classNum + '][name]" value="' + course_id + '" /></td><td colspan="10"><label for="postData[' + classNum + '][title]">Course Title:</label><input type="text" name="postData[' + classNum + '][title]" class="course-title-entry" value="' + title + '" /></td><td class="tdInput"><div class="deleteClass"><input type="button" value="Remove" class="gray" /></div></td><td class="none"><button type="button" class="addSection gray">+</button></td></tr>');
 

	
 
		/* store classNum as course_i into the <tr />: */
 
		jQuery('#tr-course-' + classNum).data({course_i: classNum});
 

	
 
		var class_elem = jQuery('.className' + classNum);
 

	
 

	
 
		/*
 
		 * Don't let the user accidentally submit the form by
 
		 * pressing <ENTER>. Instead, select the first
 
		 * autocomplete result if possible.
 
		 */
 
@@ -334,25 +346,25 @@ function add_sections(cnum, data)
 
/**
 
 * \brief
 
 *   Ensure that there is an empty course entry and return its
 
 *   identifier.
 
 */
 
function add_class()
 
{
 
    /*
 
     * Don't add an empty new course entry if there already is
 
     * one. Otherwise, set this new class to be the ``hot'' one.
 
     */
 
    if (slate_permutate_course_free == -1)
 
	slate_permutate_course_free = add_class_n('');
 
	slate_permutate_course_free = add_class_n('', '');
 
    return slate_permutate_course_free;
 
}
 

	
 
/**
 
 * \brief
 
 *   Remove a course entry.
 
 *
 
 * Ensures that slate_permutate_course_free is kept consistent.
 
 *
 
 * \param course_i
 
 *   The internal JS identifer for the course (not the course_id which
 
 *   the PHP cares about).
0 comments (0 inline, 0 general)