Changeset - 0b6f69a3ae0e
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 15 years ago 2010-10-16 13:00:32
ohnobinki@ohnopublishing.net
For autocompleting course departments, omit the trailing '-' so that the user has to type a space or other delimiter himself. This make the interface more intuitive.
1 file changed with 1 insertions and 1 deletions:
0 comments (0 inline, 0 general)
auto.php
Show inline comments
 
@@ -56,49 +56,49 @@ if (!count($term_parts))
 

	
 
$school = school_load_guess();
 
if (!$school['crawled'])
 
  clean_empty_exit();
 

	
 
$cache_dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'auto' . DIRECTORY_SEPARATOR . $school['id'] . DIRECTORY_SEPARATOR;
 

	
 
/*
 
 * autocomplete the list of departments. If the user has already
 
 * entered a valid department name _and_ delimitted it, however, go on
 
 * to the next autocompletion step.
 
 */
 
$term_strlen = strlen($term);
 
$dept_strlen = strlen($term_parts['department']);
 
$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();
 
    $deptartments = unserialize(file_get_contents($dept_file));
 
    foreach ($deptartments as $key => $department)
 
      {
 
	if (!strncmp($department, $dept, $term_strlen))
 
	  $departments[$key] = $department . '-';
 
	  $departments[$key] = $department;
 
	else
 
	  unset($departments[$key]);
 
      }
 
    echo json_encode($departments);
 
    exit(0);
 
  }
 

	
 
if ($getsections)
 
  {
 
    $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";
 
    exit(0);
 
  }
 

	
 
/*
 
 * if a department is fully entered, life gets slightly more
0 comments (0 inline, 0 general)