<?php
	define('thisscript','ajax');

	require_once "global_simple.php";
	
	/* sanitize post, get, request, cookie */
	$_POST['doing'] = ((empty($_POST['doing']))?"":$_POST['doing']);
	$_GET['doing'] = ((empty($_GET['doing']))?"":$_GET['doing']);
	/* end sanitize */
	
	if ($_POST['doing'] == 'changelanguage'){
		$_POST['langid'] = ((empty($_POST['langid']))?"":$_POST['langid']);
		if (!empty($_POST['langid'])){
			if (!empty($cookieid)){
				$db->query("UPDATE online SET languageid='".$db->clean($_POST['langid'])."' WHERE cookieid='".$db->clean($cookieid)."'");
			}
		}
		exit;
	}
	
	if ($_GET['doing'] == 'getproductsuggestion'){
		$_GET['term'] = ((empty($_GET['term']))?"":$_GET['term']);
		$filters = strtolower(trim($_GET['term']));
		$limitsearch = empty($general['limitsearchsuggestioninheader'])?5:$general['limitsearchsuggestioninheader'];
		$arraylist = array();
		/* if (strlen($filters) >= 3){ */
			$getsuggest = $db->fetch_all("
				SELECT
					productname
				FROM
					product
				WHERE
					LOWER(productname) LIKE '%".$db->clean($filters)."%' AND status = 1
				ORDER BY
					productname
			");
			if (sizeof($getsuggest) > 0){
				foreach ($getsuggest as $gs){
					array_push($arraylist,$gs['productname']);
				}
			}
		/* } */
		echo json_encode($arraylist);
		exit;
	}
	else if ($_GET['doing'] == 'getbrandsuggestion'){
		$_GET['term'] = ((empty($_GET['term']))?"":$_GET['term']);
		$filters = strtolower(trim($_GET['term']));
		$limitsearch = empty($general['limitsearchsuggestioninheader'])?5:$general['limitsearchsuggestioninheader'];
		$arraylist = array();
		$getsuggest = $db->fetch_all("
			SELECT
				id, brand
			FROM
				brand
			WHERE
				LOWER(brand) LIKE '%".$db->clean($filters)."%' AND status = 1
			ORDER BY
				brand
			LIMIT
				".$limitsearch."
		");
		
		if (sizeof($getsuggest) > 0){
			foreach ($getsuggest as $gs){
				$x = array();
				$x['id'] = $gs['id'];
				$x['value'] = $gs['brand'];
				array_push($arraylist,$x);
			}
		}
		echo json_encode($arraylist);
		exit;
	}
?>