<?php

// Check nonce
PHPCUS_PARAM::CUS_REQUIRES_NONCE();

// Check Array Input
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_ONLY, 'addon_queuing');

if
(
    PHPRC_HTTP_PARAM::REF_ISSET_IN_ARRAY
    (
        [
            'PARAM_ADD_QUEUING_ID',
            'PARAM_ADD_QUEUING_NUMBER_FROM',
            'PARAM_ADD_QUEUING_NUMBER_TO',
            'PARAM_ADD_QUEUING_EXTRA_VALUE',
            'PARAM_ADD_QUEUING_PUBLIC_KEY',
            'PARAM_ADD_QUEUING_STATION',
            'PARAM_ADD_QUEUING_REMARKS',
            'PARAM_ADD_QUEUING_DATE_REQUEST_FROM',
            'PARAM_ADD_QUEUING_DATE_REQUEST_TO',
            'PARAM_ADD_QUEUING_DATE_PROCESSED_FROM',
            'PARAM_ADD_QUEUING_DATE_PROCESSED_TO',
            'PARAM_ADD_QUEUING_DATE_LAST_CALLED_FROM',
            'PARAM_ADD_QUEUING_DATE_LAST_CALLED_TO',
            'PARAM_ADD_QUEUING_DATE_LAST_DISPLAYED_FROM',
            'PARAM_ADD_QUEUING_DATE_LAST_DISPLAYED_TO',
            'PARAM_ADD_QUEUING_STATUS',
            
            'PARAM_ORDER_FIELD',
            'PARAM_ORDER_TYPE',
            'PARAM_SKIP',
            'PARAM_LIMIT'
        ], True
        )
    )
{
    Try
    {
        // Read params
        // ------------------------------------------------------------------
        $PARAM_ADD_QUEUING_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_ADD_QUEUING_ID');
        $PARAM_ADD_QUEUING_NUMBER_FROM = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_ADD_QUEUING_NUMBER_FROM');
        $PARAM_ADD_QUEUING_NUMBER_TO = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_ADD_QUEUING_NUMBER_TO');
        $PARAM_ADD_QUEUING_EXTRA_VALUE = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_ADD_QUEUING_EXTRA_VALUE');
        $PARAM_ADD_QUEUING_PUBLIC_KEY = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_ADD_QUEUING_PUBLIC_KEY');
        $PARAM_ADD_QUEUING_STATION = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_ADD_QUEUING_STATION');
        $PARAM_ADD_QUEUING_REMARKS = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_ADD_QUEUING_REMARKS');
        $PARAM_ADD_QUEUING_DATE_REQUEST_FROM = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_ADD_QUEUING_DATE_REQUEST_FROM');
        $PARAM_ADD_QUEUING_DATE_REQUEST_TO = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_ADD_QUEUING_DATE_REQUEST_TO');
        $PARAM_ADD_QUEUING_DATE_PROCESSED_FROM = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_ADD_QUEUING_DATE_PROCESSED_FROM');
        $PARAM_ADD_QUEUING_DATE_PROCESSED_TO = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_ADD_QUEUING_DATE_PROCESSED_TO');
        $PARAM_ADD_QUEUING_DATE_LAST_CALLED_FROM = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_ADD_QUEUING_DATE_LAST_CALLED_FROM');
        $PARAM_ADD_QUEUING_DATE_LAST_CALLED_TO = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_ADD_QUEUING_DATE_LAST_CALLED_TO');
        $PARAM_ADD_QUEUING_DATE_LAST_DISPLAYED_FROM = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_ADD_QUEUING_DATE_LAST_DISPLAYED_FROM');
        $PARAM_ADD_QUEUING_DATE_LAST_DISPLAYED_TO = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_ADD_QUEUING_DATE_LAST_DISPLAYED_TO');
        $PARAM_ADD_QUEUING_STATUS = PHPCUS_PARAM::CUS_READ_INT('PARAM_ADD_QUEUING_STATUS');
        
        $PARAM_ORDER_FIELD = PHPCUS_PARAM::CUS_READ_SORT_FIELD
        (
            'PARAM_ORDER_FIELD',
            [
                'ADD_QUEUING_ID',
                'ADD_QUEUING_NUMBER',
                'ADD_QUEUING_EXTRA_VALUE',
                'ADD_QUEUING_PUBLIC_KEY',
                'ADD_QUEUING_STATION',
                'ADD_QUEUING_REMARKS',
                'ADD_QUEUING_DATE_REQUEST',
                'ADD_QUEUING_DATE_PROCESSED',
                'ADD_QUEUING_DATE_LAST_CALLED',
                'ADD_QUEUING_DATE_LAST_DISPLAYED',
                'ADD_QUEUING_STATUS'
            ]
            );
        $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 Map Array
        // ...........................................
        $GET_MAP_ARRAY = PHPCUS_ADDON_QUEUING::CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
        
        $GET_MAP_ARRAY['PARAM_ADD_QUEUING_ID'] = $PARAM_ADD_QUEUING_ID;
        $GET_MAP_ARRAY['PARAM_ADD_QUEUING_NUMBER_FROM'] = $PARAM_ADD_QUEUING_NUMBER_FROM;
        $GET_MAP_ARRAY['PARAM_ADD_QUEUING_NUMBER_TO'] = $PARAM_ADD_QUEUING_NUMBER_TO;
        $GET_MAP_ARRAY['PARAM_ADD_QUEUING_EXTRA_VALUE'] = $PARAM_ADD_QUEUING_EXTRA_VALUE;
        $GET_MAP_ARRAY['PARAM_ADD_QUEUING_PUBLIC_KEY'] = $PARAM_ADD_QUEUING_PUBLIC_KEY;
        $GET_MAP_ARRAY['PARAM_ADD_QUEUING_STATION'] = $PARAM_ADD_QUEUING_STATION;
        $GET_MAP_ARRAY['PARAM_ADD_QUEUING_REMARKS'] = $PARAM_ADD_QUEUING_REMARKS;
        $GET_MAP_ARRAY['PARAM_ADD_QUEUING_DATE_REQUEST_FROM'] = $PARAM_ADD_QUEUING_DATE_REQUEST_FROM;
        $GET_MAP_ARRAY['PARAM_ADD_QUEUING_DATE_REQUEST_TO'] = $PARAM_ADD_QUEUING_DATE_REQUEST_TO;
        $GET_MAP_ARRAY['PARAM_ADD_QUEUING_DATE_PROCESSED_FROM'] = $PARAM_ADD_QUEUING_DATE_PROCESSED_FROM;
        $GET_MAP_ARRAY['PARAM_ADD_QUEUING_DATE_PROCESSED_TO'] = $PARAM_ADD_QUEUING_DATE_PROCESSED_TO;
        $GET_MAP_ARRAY['PARAM_ADD_QUEUING_DATE_LAST_CALLED_FROM'] = $PARAM_ADD_QUEUING_DATE_LAST_CALLED_FROM;
        $GET_MAP_ARRAY['PARAM_ADD_QUEUING_DATE_LAST_CALLED_TO'] = $PARAM_ADD_QUEUING_DATE_LAST_CALLED_TO;
        $GET_MAP_ARRAY['PARAM_ADD_QUEUING_DATE_LAST_DISPLAYED_FROM'] = $PARAM_ADD_QUEUING_DATE_LAST_DISPLAYED_FROM;
        $GET_MAP_ARRAY['PARAM_ADD_QUEUING_DATE_LAST_DISPLAYED_TO'] = $PARAM_ADD_QUEUING_DATE_LAST_DISPLAYED_TO;
        $GET_MAP_ARRAY['PARAM_ADD_QUEUING_STATUS'] = $PARAM_ADD_QUEUING_STATUS;
        
        $GET_MAP_ARRAY["PARAM_ORDER_FIELD"] = $PARAM_ORDER_FIELD;
        $GET_MAP_ARRAY["PARAM_ORDER_TYPE"] = $PARAM_ORDER_TYPE;
        $GET_MAP_ARRAY["PARAM_SKIP"] = $PARAM_SKIP;
        $GET_MAP_ARRAY["PARAM_LIMIT"] = $PARAM_LIMIT;
        
        
        // Execute Stored Procedure
        // ...........................................
        $DATA_SET = PHPCUS_ADDON_QUEUING::CUS_GET_MA($GET_MAP_ARRAY);
        
        
        // Return JSON response
        // ...........................................
        if(empty($DATA_SET) === False)
        {
            PHPCUS_PARAM::CUS_JSON_SUCCESS($DATA_SET);
        }
        else
        {
            PHPCUS_PARAM::CUS_JSON_SUCCESS('');
        }
        
    }
    Catch(Exception $ERR)
    {
        PHPVC_LOG::VAR_REPORT_ERROR($ERR, 0);
        PHPCUS_PARAM::CUS_JSON_ERROR($ERR->getMessage());
    }
}
else
{
    PHPCUS_PARAM::CUS_JSON_ERROR('Missing parameters');
}

?>