<?php

// Check Array Input
PHPCUS_PARAM::CUS_DOES_NOT_SUPPORT_ARRAY();

if
(
    PHPRC_HTTP_PARAM::REF_ISSET_IN_ARRAY
    (
        [
            'PARAM_ACC_GROUP_ID',
            'PARAM_ACC_GROUP_DESCRIPTION',
            
            'PARAM_ACC_LINKSVR_USERNAME',
            'PARAM_ACC_LINKSVR_PASSWORD'
        ], True
        )
    )
{
    Try
    {
        // Read params
        // ------------------------------------------------------------------
        $PARAM_ACC_GROUP_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_ACC_GROUP_ID');
        $PARAM_ACC_GROUP_DESCRIPTION = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_ACC_GROUP_DESCRIPTION');
        $PARAM_ACC_GROUP_STATUS = 2;
        $PARAM_ACC_GROUP_SYSTEM_GENERATED = 1;
        
        $PARAM_ORDER_FIELD = 'ACC_GROUP_DESCRIPTION';
        $PARAM_ORDER_TYPE = 'ASC';
        $PARAM_SKIP	= 0;
        $PARAM_LIMIT = 1000;
        
        $PARAM_ACC_LINKSVR_USERNAME = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_ACC_LINKSVR_USERNAME');
        $PARAM_ACC_LINKSVR_PASSWORD = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_ACC_LINKSVR_PASSWORD');
        // ------------------------------------------------------------------
        
        
        // Verify Auth Username and Password
        // ...........................................
        $DATASET = PHPCUS_ACCOUNT_LINKSVR_CUSTOM::CUS_LOGIN
        (
            $PARAM_ACC_LINKSVR_USERNAME,
            $PARAM_ACC_LINKSVR_PASSWORD
            );
        if(empty($DATASET))
        {
            PHPCUS_PARAM::CUS_JSON_ERROR('Invalid username or password.');
        }
        $ACC_LINKSVR_ID = $DATASET[0]['ACC_LINKSVR_ID'];
        
        
        // Verify Auth (Server will forward an auth of current server)
        // ...........................................
        PHPCUS_SP::CUS_AUTHENTICATION_OVERRIDE('system_automation', '6UGlJNVxnQlBOCBoHJdvoYTg6HxKIGrY3862653932616634663463303736643732316230353234616335366436393137626539376633353837663763396262303265333265393534306234326664653562666361303464663234366234323166623633343939313236643238303461343239643537613666323736393835396635356466343138383137393565346532');
        $GET_MAPPED_ARRAY = PHPCUS_ACCOUNT_LINKSVR::CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
        $GET_MAPPED_ARRAY["PARAM_ACC_LINKSVR_ID"] = $ACC_LINKSVR_ID;
        $GET_MAPPED_ARRAY["PARAM_ACC_LINKSVR_IS_SELF"] = PHPCUS_SP::STATUS_ACTIVE;
        $GET_MAPPED_ARRAY["PARAM_ACC_LINKSVR_STATUS"] = PHPCUS_SP::STATUS_ACTIVE;
        $GET_MAPPED_ARRAY["PARAM_LIMIT"] = 1;
        
        PHPCUS_ACCOUNT_LINKSVR::CUS_GET_MA($GET_MAPPED_ARRAY);
        if(empty($DATASET))
        {
            PHPCUS_PARAM::CUS_JSON_ERROR('You don\'t have enough rights to access this feature.');
        }
        
        
        // Populate Map Array
        // ...........................................
        $GET_MAP_ARRAY = PHPCUS_ACCOUNT_GROUP::CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
        
        $GET_MAP_ARRAY['PARAM_ACC_GROUP_ID'] = $PARAM_ACC_GROUP_ID;
        $GET_MAP_ARRAY['PARAM_ACC_GROUP_DESCRIPTION'] = $PARAM_ACC_GROUP_DESCRIPTION;
        $GET_MAP_ARRAY['PARAM_ACC_GROUP_STATUS'] = $PARAM_ACC_GROUP_STATUS;
        $GET_MAP_ARRAY['PARAM_ACC_GROUP_SYSTEM_GENERATED'] = $PARAM_ACC_GROUP_SYSTEM_GENERATED;
        
        $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
        // ...........................................
        PHPCUS_SP::CUS_AUTHENTICATION_OVERRIDE('system_automation', '6UGlJNVxnQlBOCBoHJdvoYTg6HxKIGrY3862653932616634663463303736643732316230353234616335366436393137626539376633353837663763396262303265333265393534306234326664653562666361303464663234366234323166623633343939313236643238303461343239643537613666323736393835396635356466343138383137393565346532');
        $DATA_SET = PHPCUS_ACCOUNT_GROUP::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');
}

?>