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

	class AdminArticleSelector extends AdminAutocomplete {

		public function __construct( $id , $parent = NULL ) {
			parent::__construct( $id , $parent );
			$this->setStrict( true );
			$this->setWidth( 250 );
		}
		
		protected function getAutocompleteHints( $filter ) {
			$query = sprintf( "select article_id as id,larticle_title|| ' (#'||article_id||')' as label from larticles where site_language_id=%d and larticle_title ilike '%s%%' order by larticle_title,article_id limit 50",
				$GLOBALS["langcode"],
				FNTH_db_addslashes( $filter ) );
			return FNTH_db_get_resultset($query);
		}

		protected function getLabelForId( $id ) {
			$query = sprintf( "select larticle_title|| ' (#'||article_id||')' as label from larticles where site_language_id=%d and article_id=%d" , $GLOBALS["langcode"] , $id );
			return FNTH_db_get_field( $query , "label" );
		}

	}

?>
