<?php
if (!defined('sugarEntry') || !sugarEntry) {
	die('-1');
}
if (!$_POST ['job'] || $_POST ['job'] == '') {
	die('-1');
}
switch ($_POST ['job']) {
	case 'checkCode' :
		checkCode ($_POST ['kod']);
		break;
}

function checkCode($code) {
	$db = $GLOBALS ['db'];
	$query = "SELECT count(id) as c FROM ecmsyntheticaccounts WHERE account_code='" . $code."'";
	$r = $db->fetchByAssoc ( $db->query ( $query ) );
	if (! $r || ! $r ['c'] || $r ['c'] == '')
		$count = 0;
	else
		$count = intval ( $r ['c'] );
	
	if($count > 0 ){
		$json = json_encode (true);
	}else{
		$json = json_encode (false);
	}
	print $json;
}