<?php
// get these values from your DB.
require_once('config.php');
$error_message;
$valid = true;

$empl_id = $_REQUEST['empl_id'];

//Version
$sql="select default_site = default_site + ' : ' + site_name from  cf_user (NOLOCK),cf_site (NOLOCK) Where
cf_user.default_site = cf_site.site_cd
and cf_user.empl_id =? ";
		
$params_default= array($empl_id);		
		
$stmt = sqlsrv_query( $conn, $sql,$params_default,array("Scrollable"=>'keyset'));

$row = sqlsrv_has_rows( $stmt );

if( !$stmt ) {
     $error_message = "Error selecting table (sys_ver)";
	 returnError($error_message);
     die( print_r( sqlsrv_errors(), true));
	 
}

if ($row == true) { 
	do {
		 while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
		 
		$default_site = $row ['default_site'];	
		// echo  $sts_typ_typ_cd; 
		
			 
	   }
	} while ( sqlsrv_next_result($stmt));
	//sqlsrv_free_stmt( $stmt);
	
}else{
	
	$default_site = '';	
	
	
}


if ($valid) {

	
	//echo $sql;
	returnData($default_site);	
	sqlsrv_free_stmt( $stmt);
	sqlsrv_close( $conn);	
	
}

function returnData($default_site){
	$returnData = array(
	'status' => 'SUCCESS',
	'message' => 'Successfully',
	'default_site'=>$default_site);
	
	echo json_encode($returnData);	
}

function returnError($error_message){
	$json = array();
	
	$returnData = array(
	'status' => 'ERROR',
	'message' => $error_message,
	'data' => '');
	
	echo json_encode($returnData);	
	exit();	
		
}
	

 
?>