<?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_SMS_PHONE',
            'PARAM_REC_SMS_DATE_SCHEDULE_FROM',
            'PARAM_REC_SMS_DATE_SCHEDULE_TO',
            
            'PARAM_ORDER_FIELD',
            'PARAM_ORDER_TYPE',
            'PARAM_SKIP',
            'PARAM_LIMIT'
        ], True
    )
)
{
    Try
    {
        // Initialize
        // _______________________________________________________________________
        $PARAM_REC_SMS_PHONE = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_REC_SMS_PHONE');
        $PARAM_REC_SMS_DATE_SCHEDULE_FROM = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_REC_SMS_DATE_SCHEDULE_FROM');
        $PARAM_REC_SMS_DATE_SCHEDULE_TO = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_REC_SMS_DATE_SCHEDULE_TO');
        
        $PARAM_ORDER_FIELD = PHPCUS_PARAM::CUS_READ_SORT_FIELD
        (
            'PARAM_ORDER_FIELD',
            [
                'REC_SMS_ID',
                'REC_SMS_MESSAGE',
                'REC_SMS_PHONE',
                'REC_SMS_DATE_REQUEST',
                'REC_SMS_DATE_SCHEDULE',
                'REC_SMS_DATE_SENT',
                'REC_SMS_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_SMS_PHONE=' . urlencode($PARAM_REC_SMS_PHONE) . '&' .
        'PARAM_REC_SMS_DATE_SCHEDULE_FROM=' . urlencode($PARAM_REC_SMS_DATE_SCHEDULE_FROM) . '&' .
        'PARAM_REC_SMS_DATE_SCHEDULE_TO=' . urlencode($PARAM_REC_SMS_DATE_SCHEDULE_TO) . '&' .
        
        '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_OUTBOX, 
            $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');
}

?>