<?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_BROADCAST_PHONE',
            'PARAM_REC_BROADCAST_MESSAGE',
            'PARAM_REC_BROADCAST_REQUEST_DATE'
        ], True
        )
    )
{
    Try
    {
        // Initialize
        // _______________________________________________________________________
        $PARAM_REC_BROADCAST_PHONE = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_REC_BROADCAST_PHONE', true);
        $PARAM_REC_BROADCAST_MESSAGE = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_REC_BROADCAST_MESSAGE', true);
        $PARAM_REC_BROADCAST_REQUEST_DATE = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_REC_BROADCAST_REQUEST_DATE', true);
        $PARAM_ARRAY_COUNT = count($PARAM_REC_BROADCAST_PHONE);
        $ARRAY_CTR = 0;
        $SMS_PARAM = '';
        
        
        // Populate SMS Parameters
        // _______________________________________________________________________
        while($ARRAY_CTR < $PARAM_ARRAY_COUNT)
        {
            // Prepare Semaphore Server Requests
            // ...........................................
            $SMS_PARAM = PHPCUS_DSASMS_SERVER::CUS_ADD
            (
                $SMS_PARAM,
                $PARAM_REC_BROADCAST_MESSAGE[$ARRAY_CTR],
                PHPVC_STR::VAR_IS_MOBILE($PARAM_REC_BROADCAST_PHONE[$ARRAY_CTR], "+63"),
                $PARAM_REC_BROADCAST_REQUEST_DATE[$ARRAY_CTR]
            );
            //PHPVC_LOG::VAR_COMMENTS('$SMS_PARAM', $SMS_PARAM);
            $ARRAY_CTR ++;
        }
        
        
        // Send SMS
        // _______________________________________________________________________
        if(PHPVC_STR::VAR_IS_BLANK($SMS_PARAM) == false)
        {
            PHPVC_LOG::VAR_COMMENTS('SMS', PHPCUS_DSASMS_SERVER::CUS_SEND($SMS_PARAM));
        }
        PHPCUS_PARAM::CUS_JSON_SUCCESS('');   
    }
    Catch(Exception $ERR)
    {
        PHPCUS_PARAM::CUS_JSON_ERROR($ERR);
    }
}
else
{
    PHPCUS_PARAM::CUS_JSON_ERROR('Missing parameters');
}

?>