<?php
	require_once( $GLOBALS["site_root"] . "/includes/widgets/FrontendAutocomplete.inc.php" );

	class FrontendKeywordAutocomplete extends FrontendAutocomplete {
		public function __construct( $id , $parent ) {
			parent::__construct( $id , $parent );
		}
		
		protected function getAutocompleteDatas( $filter ) {
			$retval = array();
			$retval["numofitems"]=0;
			$retval["items"]=array();
			if (empty( $filter )) return $retval;

			$prefixpos = (strrpos( $filter , " " ));
			$exclude_ids = array();
			$exstring="";
			if ($prefixpos===false) {
				$prefix="";
			} else {
				$prefix=trim( substr( $filter , 0 , $prefixpos + 1 ) ) . " ";	// prefix => minden az utolso vesszo elott + space
				$filter = trim( substr( $filter , $prefixpos + 1 ) );
			}
			$query = sprintf( "select keyword_id,keyword from keywords where lkeyword like '%s%%' order by keyword limit 10",
				FNTH_db_addslashes( FNTH_strtolower( $filter ) ) );
			$ds = FNTH_db_get_resultset( $query );
			$i=0;
			foreach ($ds as $row) {
				$name = $row["keyword"];
				$tooltip = str_replace( $filter , sprintf( "<span class=\"hl\">%s</span>" , $filter ) , $name );
				$retval["items"][]=array(
					"value" => $prefix.$name,
					"title" => $prefix.$tooltip );
				$i++;
			}
			$retval["numofitems"]=$i;
			return $retval;
		}
	}


?>
