<?php

// Check nonce
PHPCUS_PARAM::CUS_REQUIRES_NONCE();

// Check array size
PHPCUS_PARAM::CUS_ARRAY_TOO_LARGE();

// Check already authenticated
PHPCUS_PARAM::CUS_REQUIRES_AUTHENTICATION();

if
(
    PHPRC_HTTP_PARAM::REF_ISSET_IN_ARRAY
    (
        [
            'PARAM_REC_RELOAD_CODE',
            'PARAM_REC_RELOAD_DATE_TRANSACT_FROM',
            'PARAM_REC_RELOAD_DATE_TRANSACT_TO',
            'PARAM_REC_RELOAD_HAS_BILL',
            'PARAM_REC_RELOAD_REFERENCE_CODE',
            
            'PARAM_ORDER_FIELD',
            'PARAM_ORDER_TYPE',
            'PARAM_SKIP',
            'PARAM_LIMIT'
        ], True
    )
)
{
    Try
    {
        // Initialize
        // _______________________________________________________________________
        $PARAM_REC_RELOAD_CODE = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_REC_RELOAD_CODE');
        $PARAM_REC_RELOAD_DATE_TRANSACT_FROM = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_REC_RELOAD_DATE_TRANSACT_FROM');
        $PARAM_REC_RELOAD_DATE_TRANSACT_TO = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_REC_RELOAD_DATE_TRANSACT_TO');
        $PARAM_REC_RELOAD_HAS_BILL = PHPCUS_PARAM::CUS_READ_INT('PARAM_REC_RELOAD_HAS_BILL');
        $PARAM_REC_RELOAD_REFERENCE_CODE = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_REC_RELOAD_REFERENCE_CODE');
        
        $PARAM_ORDER_FIELD = PHPCUS_PARAM::CUS_READ_SORT_FIELD
        (
            'PARAM_ORDER_FIELD',
            [
                'REC_RELOAD_ID',
                'REC_RELOAD_REC_BALANCE_ID',
                'REC_RELOAD_ACC_GROUP_ID',
                'REC_RELOAD_CODE',
                'REC_RELOAD_PRICE_SMS',
                'REC_RELOAD_PRICE_TOTAL',
                'REC_RELOAD_BALANCE_ADD',
                'REC_RELOAD_BALANCE_OLD',
                'REC_RELOAD_BALANCE_NEW',
                'REC_RELOAD_DATE_TRANSACT',
                'REC_RELOAD_HAS_BILL',
                'REC_RELOAD_REFERENCE_CODE',
                'REC_RELOAD_DATE_BILL',
                'REC_RELOAD_REMARKS',
                'REC_RELOAD_STATUS'
                ,
                'REC_BALANCE_ID',
                'REC_BALANCE_ACC_GROUP_ID',
                'REC_BALANCE_SHORTCODE',
                'REC_BALANCE_API_KEY',
                'REC_BALANCE_OWNER',
                'REC_BALANCE_VALUE',
                'REC_BALANCE_STATUS',
                'ACC_GROUP_ID',
                'ACC_GROUP_DESCRIPTION',
                'ACC_GROUP_STATUS',
                'ACC_GROUP_SYSTEM_GENERATED'
            ]
            );
        $PARAM_ORDER_TYPE = PHPCUS_PARAM::CUS_READ_SORT_TYPE('PARAM_ORDER_TYPE');
        $PARAM_SKIP	= PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_SKIP');
        $PARAM_LIMIT = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_LIMIT');
        
        
        // Populate SMS Parameters
        // _______________________________________________________________________
        $HTTP_PARAM =
        'PARAM_REC_RELOAD_CODE=' . urlencode($PARAM_REC_RELOAD_CODE) . '&' .
        'PARAM_REC_RELOAD_DATE_TRANSACT_FROM=' . urlencode($PARAM_REC_RELOAD_DATE_TRANSACT_FROM) . '&' .
        'PARAM_REC_RELOAD_DATE_TRANSACT_TO=' . urlencode($PARAM_REC_RELOAD_DATE_TRANSACT_TO) . '&' .
        'PARAM_REC_RELOAD_HAS_BILL=' . urlencode($PARAM_REC_RELOAD_HAS_BILL) . '&' .
        'PARAM_REC_RELOAD_REFERENCE_CODE=' . urlencode($PARAM_REC_RELOAD_REFERENCE_CODE) . '&' .

        'PARAM_ORDER_FIELD=' . urlencode($PARAM_ORDER_FIELD) . '&' . 
        'PARAM_ORDER_TYPE=' . urlencode($PARAM_ORDER_TYPE) . '&' . 
        'PARAM_SKIP=' . urlencode($PARAM_SKIP) . '&' . 
        'PARAM_LIMIT=' . urlencode($PARAM_LIMIT) . '&' .
        
        'PARAM_ACCOUNT_USERNAME=' . urlencode(PHPSET::$MOBILE_USERNAME) . '&' .
        'PARAM_ACCOUNT_PASSWORD=' . urlencode(PHPSET::$MOBILE_PASSWORD);
        
        $SMS_RESPONSE = PHPRC_HTTP::REF_REQUEST
        (
            PHPSET::$MOBILE_BILLING, 
            $HTTP_PARAM
        );
        
        // Send SMS
        // _______________________________________________________________________
        echo $SMS_RESPONSE;
        exit;
    }
    Catch(Exception $ERR)
    {
        PHPCUS_PARAM::CUS_JSON_ERROR($ERR);
    }
}
else
{
    PHPCUS_PARAM::CUS_JSON_ERROR('Missing parameters');
}

?>