Changeset - 435c41f135a5
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 14 years ago 2012-02-19 00:39:23
ohnobinki@ohnopublishing.net
Fix autocomplete of the course number part of a course identifier, fixing a regression from ff180c328353.
1 file changed with 3 insertions and 1 deletions:
0 comments (0 inline, 0 general)
auto.php
Show inline comments
 
@@ -123,60 +123,62 @@ if ($getsections)
 
      {
 
	readfile($section_file);
 
	exit(0);
 
      }
 
    /* Section not found! */
 
    header('HTTP/1.1 404: Not found');
 
    header('Content-Type: text/plain; encoding=utf-8');
 
    echo 'Could not find course ' . implode('-', $term_parts) . "\n";
 
    exit(0);
 
  }
 

	
 
/*
 
 * If a department is fully entered, life gets slightly more
 
 * complicated. I suppose I only want to autocomplete the first digit
 
 * of the course/class number. I.e., CS-2 for CS-262 for when the
 
 * student has entered CS- or 'CS'. But for now we can just dump the entire department at the user ;-).
 
 */
 
$classes_file = $cache_dir . $dept . '.sects';
 
if (file_exists($classes_file))
 
  {
 
    $classes = unserialize(file_get_contents($classes_file));
 
    $class_start = '';
 
    if (count($term_parts) > 1)
 
      $class_start = $term_parts['course'];
 
    $class_start_strlen = strlen($class_start);
 

	
 
    /* reduce/create resultset */
 
    $json_classes = array();
 
    if (!empty($classes) && is_array($classes[0]))
 
      {
 
	$class_start = $dept . '-' . $class_start;
 
	$class_start_strlen = strlen($class_start);
 
	foreach ($classes as $course)
 
	  if (!strncmp($course['value'], $class_start, $class_start_strlen))
 
	    $json_classes[] = $course;
 
      }
 
    else
 
      {
 
	/* Old format with just course id. */
 
	$class_start_strlen = strlen($class_start);
 
	foreach ($classes as $class)
 
	  if (!strncmp($class, $class_start, $class_start_strlen))
 
	    $json_classes[] = $dept . '-' . $class;
 
      }
 

	
 
    echo json_encode($json_classes);
 
    exit(0);
 
  }
 

	
 
/**
 
 * Nothing caught
 
 */
 
clean_empty_exit();
 

	
 
/**
 
 * \brief
 
 *   Send an empty JSON array and exit.
 
 */
 
function clean_empty_exit()
 
{
 
  echo '[]';
 
  exit(0);
 
}
0 comments (0 inline, 0 general)