Changeset - ed3b1fa80062
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 14 years ago 2012-02-19 01:21:58
ohnobinki@ohnopublishing.net
Start autocompleting course numbers as soon as possible.
1 file changed with 19 insertions and 0 deletions:
0 comments (0 inline, 0 general)
auto.php
Show inline comments
 
@@ -83,48 +83,67 @@ if (!$school['crawled']) {
 
$dept = $term_parts['department'];
 
if (!$getsections && count($term_parts) == 1 && $term_strlen == strlen($dept))
 
  {
 
    $dept_file = $cache_dir . '-depts';
 
    if (!file_exists($dept_file)) {
 
      clean_empty_exit();
 
    }
 
    $departments = unserialize(file_get_contents($dept_file));
 
    $json_depts = array();
 
    if (!empty($departments) && is_array($departments[0]))
 
      {
 
	/* New format with department names/labels */
 
	foreach ($departments as $department)
 
	  if (!strncmp($department['value'], $dept, $dept_strlen))
 
	    $json_depts[] = $department;
 
      }
 
    else
 
      {
 
	/* Old format with just department id. */
 
	foreach ($departments as $department)
 
	  if (!strncmp($department, $dept, $dept_strlen))
 
	    $json_depts[] = $department;
 
      }
 

	
 
    /*
 
     * If what the user has entered already can only be completed to a
 
     * particular department, start displaying courses from that
 
     * department instead of just returning that one department.
 
     */
 
    if (count($json_depts) == 1)
 
      {
 
	$dept = $json_depts[0];
 
	if (!empty($dept['value']))
 
	  $dept = $dept['value'];
 

	
 
	page::redirect('auto.php' . page::query_string(array('term' => $dept . '-') + $_GET));
 
      }
 

	
 
    /*
 
     * Multiple or no departments match the user's input. Perhaps
 
     * in the future, if there are no matches we can backspace for
 
     * the user...
 
     */
 
    echo json_encode($json_depts);
 
    exit(0);
 
  }
 

	
 
if ($getsections)
 
  {
 
    if (!isset($term_parts['course']))
 
      {
 
	/* user didn't give us enough information */
 
	header('HTTP/1.1 404: Nof found');
 
	header('Content-Type: text/plain; encoding=utf-8');
 
	echo 'Not a fully-qualified course name: ' . implode('-', $term_parts) . "\n";
 
	exit(0);
 
      }
 
    $section_file = $cache_dir . $dept . DIRECTORY_SEPARATOR . $term_parts['course'];
 
    if (file_exists($section_file))
 
      {
 
	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";
0 comments (0 inline, 0 general)