<?php

require("config/datenbankanbindung.php");     // f&uuml;gt die Datenbankanbindung ein: Sys:\php\includes\kurs\datenbankanbindung.php
$db = dbconnect();
require_once("config.inc.php");

#header("Content-Type: text/html;charset=utf-8");

if(isset($_GET['getWord']) && isset($_GET['letters'])){
	$letters = $_GET['letters'];
	$letters = strtoupper($_GET['letters']);
	$letters = str_replace (array("ä", "ö", "ü", "ß", "Ä", "Ö", "Ü"), array("&AUML;", "&OUML;", "&UUML;", "&SZLIG;", "&AUML;", "&OUML;", "&UUML;"), $letters);
	
	#$letters = preg_replace("/[^a-z0-9 ]/si","",$letters);
	$res = $db->query("SELECT vid, betreff
	                      FROM imt_vorschlag a
	                     WHERE (upper(vid) LIKE '%".$letters."%'
	                        OR upper(betreff) LIKE '%".$letters."%')
	                       AND vid IN (SELECT vid FROM imt_gutachter WHERE imtuid ='$uid' AND frist_datum_abgabe != '0000-00-00')
	                       AND 1 = (SELECT CASE 1 WHEN (SELECT count(*)
			                               FROM imt_verlauf d
			                              WHERE d.vid=a.vid
			                                AND d.status IN ('7', '8')
			                              GROUP BY vid
			                            )>0 
			                       THEN '0'
			                       ELSE '1'
			                       END 
			                       # Man darf den Fall solange sehen, bis er abgeschlossen ist, also entweder mit Status 7 oder 8
			               )
	                     ORDER BY betreff") or die(mysql_error());
	#echo "1###select ID,textstelle Name from ajax_countries where textstelleName like '".$letters."%'|";
	while($inf = $res->fetch_array()){
		echo $inf["vid"]." - ".$inf["betreff"]."|";
	}	
}
?>
