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

$site_cd = $_REQUEST['site_cd'];

//Mydefault values
$sql= "SELECT 
		 dft_mst_wko_sts = dft_mst_wko_sts + ' : ' + wrk_sts_desc, 
		 dft_mst_lab_act , 
		 dft_mst_mat_act , 
		 dft_mst_con_act , 
		 dft_mst_wko_pri = dft_mst_wko_pri + ' : ' + wrk_pri_desc + ' - ' + cast(wrk_pri_due_date_count as varchar), 
		 dft_mst_temp_ast , 
		 dft_mst_wko_asset_no , 
		 dft_mst_wo_default_cc , 
		 dft_mst_time_card_by , 
		 dft_mst_itm_resv , 
		 dft_mst_mr_approval , 
		 dft_mst_pur_email_approver , 
		 dft_mst_mtr_email_approver , 
		 dft_mst_gen_inv
	FROM dft_mst (NOLOCK) ,wrk_pri (NOLOCK), wrk_sts (NOLOCK) 
	WHERE dft_mst.site_cd = wrk_pri.site_cd 
	AND dft_mst.dft_mst_wko_pri = wrk_pri.wrk_pri_pri_cd 
	AND dft_mst.site_cd = wrk_sts.site_cd
	AND dft_mst.dft_mst_wko_sts = wrk_sts.wrk_sts_status 
	AND	dft_mst.site_cd ='".$site_cd."'";
$stmt = sqlsrv_query( $conn, $sql);

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

$Defaultvalue = array();

do {
     while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {		
		$Defaultvalue[] = $row;	
	
     }
} while ( sqlsrv_next_result($stmt) );


if ($valid) {
	
	sqlsrv_free_stmt( $stmt);
	sqlsrv_close( $conn);

	//echo $sql;
	returnData($Defaultvalue);	
	
}

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

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

 
?>