<?php
	//
	require_once $_SERVER['DOCUMENT_ROOT'] . '/db_connection.php';
// 	include("php/erster_name.inc.php");
	include("php/namen.inc.php");
	//
	if (!isset($_GET["term"])) { exit; } // "term" ist von jQuery-autocomplete festgelegt!
	$anfrage = addslashes($_GET["term"]);
	//
	$sql_select = "SELECT * FROM hermes_namen WHERE
				((Name LIKE '%$anfrage%') AND (Name NOT LIKE '%/%')) OR (Originalname LIKE '%$anfrage%') ORDER BY Name ASC";
	$sql_result = $db->query($sql_select);
	//
	while ($row = $sql_result->fetch_object()) {
		$d = $row->Name;
		if (strlen($d) > 80) {
			$d = preg_replace("/[^ ]*$/", '', substr($d, 0, 80));
		}
		// jQuery-autocomplete verlangt "value-label"
		$data[] = array('value' => $d, 'label' => $d);
	}
	//
	echo json_encode($data);
	ob_flush();
	flush();
	//
?>
