<?php
/* Include Files ***************************/
require_once('../db-config.php');
require_once('../inc/lib-compat-class.php');
require_once('../inc/lib-db-class.php');
require_once('../inc/lib-login-class.php');
require_once('../JSON/jsonwrapper_inner.php');
/*******************************************/
global $rSdb;

$user	= new userManagement();
if(  !$user->_logged_in  )
	die(__('Access denied.','recipeshelf'));

if( ! check_ajax_referer('auto-email', false) )
	die('0|'.__('Security Alert: Direct access not permitted!','recipeshelf'));

$q = esc_sql( (string)_rem_magic_quote($_POST['q']) );
$uid = (int)$user->_user_id;

$sql =  "SELECT object FROM {$rSdb->DBobjects} WHERE type='4' AND uid='{$uid}' AND object LIKE '%{$q}%' GROUP BY object ORDER BY object LIMIT 0,50";
$entries = $rSdb->fetchArr($sql);

if ($entries) :
	$arrJSON = array();
	$i=0;
	foreach( $entries as $r )
		$arrJSON[$i++] = $r->object;

	echo json_encode($arrJSON);
endif;
?>