<?php

// get these values from your DB.
require_once('config.php');


$json_return = array();
$json_link = array();


$sql="select * from cf_label (NOLOCK) where  
		column_name IN ('wko_mst_originator',			'wko_mst_phone',			'wko_mst_assetno',			'wko_mst_pm_grp',
						'wko_mst_asset_group_code',		'wko_mst_asset_location',	'wko_mst_asset_level',		'wko_mst_chg_costcenter',
						'wko_mst_wo_no',				'wko_mst_orig_priority',	'wko_mst_plan_priority',	'wko_mst_org_date',
						'wko_mst_due_date',				'wko_mst_org_time',			'wko_mst_due_time',			'wko_det_work_type',
						'wko_mst_flt_code',				'wko_mst_status',			'wko_mst_descs',			'wko_det_assign_to',
						'wko_det_lab_cost',				'wko_det_con_cost',			'wko_det_mtl_cost',			'wko_mst_project_id',
						'wko_det_numeric1',				'wko_det_numeric2',			'wko_det_numeric3',			'ast_mst_asset_no',
						'ast_mst_asset_shortdesc',		'ast_mst_asset_type',		'ast_mst_asset_grpcode',	'ast_mst_asset_code',
						'ast_mst_work_area',			'ast_mst_asset_locn',		'ast_mst_ast_lvl',			'ast_det_from_date',
						'ast_det_to_date',				'ast_mst_asset_status',		'wko_det_work_grp',			'wko_det_planner') 
		and language_cd = 'DEFAULT' order by column_name";


$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_link[$row['column_name']] = $row['customize_header'];
		 $json_link['vf_' . $row['column_name']] = $row['cf_label_required'];
		
	
	 }
	 array_push($json_return, $json_link);
} while ( sqlsrv_next_result($stmt_asset_list) );



if( $stmt_asset_list) {
		 sqlsrv_commit( $conn );
		 sqlsrv_close( $conn);	
		 returnData($json_return);	
	} 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();
		
}
	

 
?>