<?php
	chdir('../..');
	require_once('api/Simpla.php');
	$simpla = new Simpla();
	$limit = 100;
	
	$keyword = $simpla->request->get('query', 'string');
	
	$simpla->db->query('SELECT id, name FROM __pages
	                    WHERE name LIKE "%'.mysql_real_escape_string($keyword).'%" AND menu_id=3 ORDER BY name LIMIT ?', $limit);
	$products = $simpla->db->results();

	foreach($products as $product)
	{
	    $products_names[] = $product->name;	
				
		$products_data[] = $product;
	}

	$res->query = $keyword;
	$res->suggestions = $products_names;
	$res->data = $products_data;
	header("Content-type: application/json; charset=UTF-8");
	header("Cache-Control: must-revalidate");
	header("Pragma: no-cache");
	header("Expires: -1");		
	print json_encode($res);