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


$site_cd = $_REQUEST['site_cd'];
$empl_id = $_REQUEST['empl_id'];

$sql="SELECT 		cf_menu.object_name,
					cf_menu.object_descs,			
					exe_flag,					
					new_flag,
					edit_flag				

		FROM 				cf_menu (NOLOCK)
		
		INNER JOIN			cf_user_access (NOLOCK)
		ON					cf_user_access.menuid = cf_menu.rowid
		
		INNER JOIN			cf_module (NOLOCK)
		ON					cf_module.language_cd = cf_menu.language_cd
		AND					cf_module.cf_module_module_cd = cf_menu.program_category

		WHERE    			cf_user_access.site_cd = '".$site_cd ."'
		AND      			cf_user_access.empl_id = '".$empl_id."'
		AND					cf_menu.object_name IN ('w_ast_manager', 'w_wkr_manager', 'w_wko_manager','w_itm_manager', 'w_issue_trx','w_receive_trx','w_return_stk_trx','w_itm_recon_manager')
		ORDER BY cf_module.cf_module_seq, cf_menu.cf_menu_seq";
		
		$stmt = sqlsrv_query( $conn, $sql);

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

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


if ($valid) {
	
	sqlsrv_free_stmt( $stmt);
	sqlsrv_close( $conn);
	//echo $sql;
	returnData($json);	
	
}

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

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

 
?>