<?php
/*
	// Perform Login
    $SHORTCODE_STATUS = PHPCUS_SHORTCODE::CUS_QUICK_LOGIN();
	
	// Check nonce
	if($SHORTCODE_STATUS == false)
    {
		PHPCUS_PARAM::CUS_REQUIRES_NONCE();
	}
	
	// Check array size
	PHPCUS_PARAM::CUS_DOES_NOT_SUPPORT_ARRAY();
	
	// Check already authenticated
	PHPCUS_PARAM::CUS_REQUIRES_AUTHENTICATION();

	// Check access rights
	PHPCUS_PARAM::CUS_HAS_PERMISSION(PHPCUS_SYSTEM::AUTHORITY_VIEW_EDIT, 'record_transaction');
	
	if
	(
		PHPRC_HTTP_PARAM::REF_ISSET_IN_ARRAY
		(
			[
					'PARAM_REC_TRANSACTION_ID',
					'PARAM_REC_TRANSACTION_FLOW_REMARKS', 
					'PARAM_REC_TRANSACTION_FLOW_FOR_FORWARDING'
			], True
		)
	)
	{
		Try
		{
			// Read params
			// ------------------------------------------------------------------
			$PARAM_REC_TRANSACTION_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_REC_TRANSACTION_ID');
			$PARAM_REC_TRANSACTION_FLOW_REMARKS = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_REC_TRANSACTION_FLOW_REMARKS');
			$PARAM_REC_TRANSACTION_FLOW_FOR_FORWARDING = PHPCUS_PARAM::CUS_READ_INT('PARAM_REC_TRANSACTION_FLOW_FOR_FORWARDING');
			
				
			// Prepare PDO Handler
			// ------------------------------------------------------------------	
			$SAVE_MAP_ARRAY = [];
			$PDO_HANDLE = PHPRC_PDO_MYSQL::REF_CONNECT();
			PHPRC_PDO_MYSQL::REF_TRANSACTION_BEGIN($PDO_HANDLE);
			
		
			// Execute Stored Procedure
			// ------------------------------------------------------------------
			Try
			{
					$SAVE_MAP_ARRAY = PHPCUS_RECORD_TRANSACTION_CUSTOM::CUS_PREPARE_MAPPED_ARRAY_FOR_MOVE_HOLDER();
					$SAVE_MAP_ARRAY['PARAM_REC_TRANSACTION_ID'] = $PARAM_REC_TRANSACTION_ID;
					$SAVE_MAP_ARRAY['PARAM_REC_TRANSACTION_FLOW_REMARKS'] = $PARAM_REC_TRANSACTION_FLOW_REMARKS;
					$SAVE_MAP_ARRAY['PARAM_REC_TRANSACTION_FLOW_FOR_FORWARDING'] = $PARAM_REC_TRANSACTION_FLOW_FOR_FORWARDING;
                    							
					$DATA_SET = PHPCUS_RECORD_TRANSACTION_CUSTOM::CUS_MOVE_HOLDER_MA
					(
							$SAVE_MAP_ARRAY,
							true,
							$PDO_HANDLE
					);	
			}
			Catch(Exception $PDO_ERR)
			{
				PHPRC_PDO_MYSQL::REF_TRANSACTION_ROLLBACK($PDO_HANDLE);
				//PHPRC_UPLOAD::REF_UPLOAD_TRANSACTION_ROLLBACK();
				PHPCUS_PARAM::CUS_JSON_ERROR($PDO_ERR);
			}
			PHPRC_PDO_MYSQL::REF_TRANSACTION_COMMIT($PDO_HANDLE);
			//PHPRC_UPLOAD::REF_UPLOAD_TRANSACTION_COMMIT();
			
			
			// Get Current timestamp for sending SMS
			// ------------------------------------------------------------------
			$DATE_NOW = date_format
			(
			    PHPVC_DATETIME::VAR_NOW(),
			    'Y-m-d H:i:s.u'
			);
				
			// Send SMS for Completion
			// ------------------------------------------------------------------
			if(PHPVC_NUM::VAR_NVAL($DATA_SET[0]['REC_TRANSACTION_STATUS']) == 4)
			{
			    $SMS_MESSAGE = 'Hi there, your transaction ' . $DATA_SET[0]['REC_TRANSACTION_CODE'] . ' has COMPLETED processing.';
			    if(PHPVC_STR::VAR_LEN($SMS_MESSAGE) > 140)
			    {
			        $SMS_MESSAGE = PHPVC_STR::VAR_LEFT($SMS_MESSAGE, 140);
			    }
			    
			    $HTTP_PARAM =
			    'PARAM_REC_CLIENT_USERNAME[]=' . urlencode(PHPSET::$MOBILE_USERNAME) . '&' .
			    'PARAM_REC_CLIENT_PASSWORD[]=' . urlencode(PHPSET::$MOBILE_PASSWORD) . '&' .
			    'PARAM_REC_BROADCAST_PHONE[]=' . urlencode($DATA_SET[0]['REC_TRANSACTION_CLIENT_MOBILE']) . '&' .
			    'PARAM_REC_BROADCAST_MESSAGE[]=' . urlencode($SMS_MESSAGE . "\r\n\r\n" . 'BARMM-MENRE') . '&' .
			    'PARAM_REC_BROADCAST_REQUEST_DATE[]=' . urlencode($DATE_NOW) . '&' .
			    'PARAM_REC_BROADCAST_DEVICE[]=' . urlencode('PHP Server') . '&' .
			    'PARAM_REC_BROADCAST_STATUS[]=2';
			    
			    PHPRC_HTTP::REF_REQUEST(PHPSET::$MOBILE_URL, $HTTP_PARAM);
			}
				
			// Rejected
			// ------------------------------------------------------------------
			else if
			(
			    PHPVC_STR::VAR_IS_BLANK($DATA_SET[0]['ACC_GROUP_DESCRIPTION']) == false && 
			    $PARAM_REC_TRANSACTION_FLOW_FOR_FORWARDING == PHPCUS_SP::STATUS_INACTIVE
			)
			{
			    $SMS_MESSAGE = 'Hi there, your transaction ' . $DATA_SET[0]['REC_TRANSACTION_CODE'] . ' has been sent back to ' . $DATA_SET[0]['ACC_GROUP_DESCRIPTION'] . ' for re-evaluation.';
			    if(PHPVC_STR::VAR_LEN($SMS_MESSAGE) > 140)
			    {
			        $SMS_MESSAGE = PHPVC_STR::VAR_LEFT($SMS_MESSAGE, 140);
			    }
			    
			    $HTTP_PARAM =
			    'PARAM_REC_CLIENT_USERNAME[]=' . urlencode(PHPSET::$MOBILE_USERNAME) . '&' .
			    'PARAM_REC_CLIENT_PASSWORD[]=' . urlencode(PHPSET::$MOBILE_PASSWORD) . '&' .
			    'PARAM_REC_BROADCAST_PHONE[]=' . urlencode($DATA_SET[0]['REC_TRANSACTION_CLIENT_MOBILE']) . '&' .
			    'PARAM_REC_BROADCAST_MESSAGE[]=' . urlencode($SMS_MESSAGE . "\r\n\r\n" . 'BARMM-MENRE') . '&' .
			    'PARAM_REC_BROADCAST_REQUEST_DATE[]=' . urlencode($DATE_NOW) . '&' .
			    'PARAM_REC_BROADCAST_DEVICE[]=' . urlencode('PHP Server') . '&' .
			    'PARAM_REC_BROADCAST_STATUS[]=2';
			    
			    PHPRC_HTTP::REF_REQUEST(PHPSET::$MOBILE_URL, $HTTP_PARAM);
			}
						
			// Forward
			// ------------------------------------------------------------------
			else if
			(
			    PHPVC_STR::VAR_IS_BLANK($DATA_SET[0]['ACC_GROUP_DESCRIPTION']) == false &&
			    $PARAM_REC_TRANSACTION_FLOW_FOR_FORWARDING == PHPCUS_SP::STATUS_ACTIVE
			)
			{
			    $SMS_MESSAGE = 'Hi there, your transaction ' . $DATA_SET[0]['REC_TRANSACTION_CODE'] . ' has been evaluated in ' . $DATA_SET[0]['ACC_GROUP_DESCRIPTION'] . ' and is in transit for the next step of processing.';
	            if(PHPVC_STR::VAR_LEN($SMS_MESSAGE) > 140)
	            {
	                $SMS_MESSAGE = PHPVC_STR::VAR_LEFT($SMS_MESSAGE, 140);
	            }
			    
			    $HTTP_PARAM =
			    'PARAM_REC_CLIENT_USERNAME[]=' . urlencode(PHPSET::$MOBILE_USERNAME) . '&' .
			    'PARAM_REC_CLIENT_PASSWORD[]=' . urlencode(PHPSET::$MOBILE_PASSWORD) . '&' .
			    'PARAM_REC_BROADCAST_PHONE[]=' . urlencode($DATA_SET[0]['REC_TRANSACTION_CLIENT_MOBILE']) . '&' .
			    'PARAM_REC_BROADCAST_MESSAGE[]=' . urlencode($SMS_MESSAGE . "\r\n\r\n" . 'BARMM-MENRE') . '&' .
			    'PARAM_REC_BROADCAST_REQUEST_DATE[]=' . urlencode($DATE_NOW) . '&' .
			    'PARAM_REC_BROADCAST_DEVICE[]=' . urlencode('PHP Server') . '&' .
			    'PARAM_REC_BROADCAST_STATUS[]=2';   
			    
			    PHPRC_HTTP::REF_REQUEST(PHPSET::$MOBILE_URL, $HTTP_PARAM);
			}
			
			// Dismissed
			// ------------------------------------------------------------------
			else if($PARAM_REC_TRANSACTION_FLOW_FOR_FORWARDING == PHPCUS_SP::STATUS_CLOSED)
			{
			    $SMS_MESSAGE = 'Sorry, your transaction ' . $DATA_SET[0]['REC_TRANSACTION_CODE'] . ' has been dismissed.';
			    if(PHPVC_STR::VAR_LEN($SMS_MESSAGE) > 140)
			    {
			        $SMS_MESSAGE = PHPVC_STR::VAR_LEFT($SMS_MESSAGE, 140);
			    }
			    
			    $HTTP_PARAM =
			    'PARAM_REC_CLIENT_USERNAME[]=' . urlencode(PHPSET::$MOBILE_USERNAME) . '&' .
			    'PARAM_REC_CLIENT_PASSWORD[]=' . urlencode(PHPSET::$MOBILE_PASSWORD) . '&' .
			    'PARAM_REC_BROADCAST_PHONE[]=' . urlencode($DATA_SET[0]['REC_TRANSACTION_CLIENT_MOBILE']) . '&' .
			    'PARAM_REC_BROADCAST_MESSAGE[]=' . urlencode($SMS_MESSAGE . "\r\n\r\n" . 'BARMM-MENRE') . '&' .
			    'PARAM_REC_BROADCAST_REQUEST_DATE[]=' . urlencode($DATE_NOW) . '&' .
			    'PARAM_REC_BROADCAST_DEVICE[]=' . urlencode('PHP Server') . '&' .
			    'PARAM_REC_BROADCAST_STATUS[]=2';
			    
			    PHPRC_HTTP::REF_REQUEST(PHPSET::$MOBILE_URL, $HTTP_PARAM);
			}
			
			// Receive
			// ------------------------------------------------------------------
			else if
			(
			    PHPVC_STR::VAR_IS_BLANK($DATA_SET[0]['ACC_GROUP_DESCRIPTION']) == false &&
			    $PARAM_REC_TRANSACTION_FLOW_FOR_FORWARDING == PHPCUS_SP::STATUS_COMPLETED
			)
			{
			    $SMS_MESSAGE = 'Hi there, your transaction ' . $DATA_SET[0]['REC_TRANSACTION_CODE'] . ' was received by ' . $DATA_SET[0]['ACC_GROUP_DESCRIPTION'] . ' for evaluation and processing.';
			    if(PHPVC_STR::VAR_LEN($SMS_MESSAGE) > 140)
			    {
			        $SMS_MESSAGE = PHPVC_STR::VAR_LEFT($SMS_MESSAGE, 140);
			    }
			    
			    $HTTP_PARAM =
			    'PARAM_REC_CLIENT_USERNAME[]=' . urlencode(PHPSET::$MOBILE_USERNAME) . '&' .
			    'PARAM_REC_CLIENT_PASSWORD[]=' . urlencode(PHPSET::$MOBILE_PASSWORD) . '&' .
			    'PARAM_REC_BROADCAST_PHONE[]=' . urlencode($DATA_SET[0]['REC_TRANSACTION_CLIENT_MOBILE']) . '&' .
			    'PARAM_REC_BROADCAST_MESSAGE[]=' . urlencode($SMS_MESSAGE . "\r\n\r\n" . 'BARMM-MENRE') . '&' .
			    'PARAM_REC_BROADCAST_REQUEST_DATE[]=' . urlencode($DATE_NOW) . '&' .
			    'PARAM_REC_BROADCAST_DEVICE[]=' . urlencode('PHP Server') . '&' .
			    'PARAM_REC_BROADCAST_STATUS[]=2';
			    
			    PHPRC_HTTP::REF_REQUEST(PHPSET::$MOBILE_URL, $HTTP_PARAM);
			}
			
			// Return JSON response
			// ------------------------------------------------------------------
			PHPCUS_PARAM::CUS_JSON_SUCCESS($DATA_SET);
			
		}
		Catch(Exception $ERR)
		{
			PHPCUS_PARAM::CUS_JSON_ERROR($ERR);
		}
	}
	else
	{
		PHPCUS_PARAM::CUS_JSON_ERROR('Missing parameters');
	}
*/

    PHPCUS_PARAM::CUS_JSON_ERROR('For development only');
    
?>