<?php

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

//Asset Code:



$sql="select * from cf_label (NOLOCK) where  
		column_name IN ('wkr_mst_originator',
						'wkr_mst_requestor',
						'wkr_mst_requestor_phone',
						'wkr_mst_wr_no',
						'wkr_mst_orig_priority',
						'wkr_mst_org_date',
						'wkr_mst_due_date',
						'wkr_mst_due_time',
						'wkr_mst_org_time',
						'wkr_mst_work_group',
						'wkr_mst_fault_code',
						'wkr_mst_wr_descs',
						'wkr_mst_assetno',
						'wkr_mst_assetdesc',
						'wkr_mst_work_area',
						'wkr_mst_assetlocn',
						'wkr_mst_location',
						'wkr_mst_chg_costcenter',
						'wkr_det_from_date',
						'wkr_det_to_date',
						'wkr_mst_work_type',
						'wkr_mst_work_class')  
		and language_cd = 'DEFAULT' order by customize_label";


$stmt_asset_list = sqlsrv_query( $conn, $sql);

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

$json = array();

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



if( $stmt_asset_list) {
		 sqlsrv_commit( $conn );
		 sqlsrv_close( $conn);	
		 returnData($json);	
	} else {
		 sqlsrv_rollback( $conn );
		 $error_message = "Transaction rolled back.<br />";
		 returnError($error_message);
	} 



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

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

 
?>