<?php
						ini_set('display_errors',1); //initialize error handling
						error_reporting(E_ALL & ~E_NOTICE);
						
						$dbuser="root";
						$dbpass="fvvetatu7";
						$dbname="gpagas";  //the name of the database
		
						$con = mysql_connect("localhost", $dbuser,$dbpass)  or die("Connection Failure to Database");
						mysql_select_db($dbname, $con) or die ($dbname . " Database not found. " . $dbuser);
						mysql_query( "SET NAMES 'utf8' " ); //Greek Characters
					//content query 
					$frontpage = "SELECT cat_name FROM tbl_category";
					$result = mysql_query($frontpage) or die("Query failed : " . mysql_error());
						if (mysql_num_rows($result) == 0){
						echo $error001;
							}
							else {
							$vascat=array();
							while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
							$vascat[]=$line["cat_name"];
							//echo $vascat;
							}
					}
					

					
	$aInfo = array();
	
	$input = strtolower( $_GET['input'] );
	$len = strlen($input);
	$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 0;
	
	
	$aResults = array();
	$count = 0;
	
	if ($len)
	{
		for ($i=0;$i<count($vascat);$i++)
		{
			// had to use utf_decode, here
			// not necessary if the results are coming from mysql
			//
			if (strtolower(substr(utf8_decode($vascat[$i]),0,$len)) == $input)
			{
				$count++;
				$aResults[] = array( "id"=>($i+1) ,"value"=>htmlspecialchars($vascat[$i]), "info"=>"" );
			}
			
			if ($limit && $count==$limit)
				break;
		}
	}
	
	
	
	
	
	header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
	header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
	header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
	header ("Pragma: no-cache"); // HTTP/1.0
	
	
	
	if (isset($_REQUEST['json']))
	{
		header("Content-Type: application/json");
	
		echo "{\"results\": [";
		$arr = array();
		for ($i=0;$i<count($aResults);$i++)
		{
			$arr[] = "{\"id\": \"".$aResults[$i]['id']."\", \"value\": \"".$aResults[$i]['value']."\", \"info\": \"\"}";
		}
		echo implode(", ", $arr);
		echo "]}";
	}
	else
	{
		header("Content-Type: text/xml");

		echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?><results>";
		for ($i=0;$i<count($aResults);$i++)
		{
                    echo "<rs id=\"".$aResults[$i]['id']."\" info=\"".$aResults[$i]['info']."\">".$aResults[$i]['value']."</rs>";
		}
		echo "</results>";
	}
?>