/*------------------------------------------------------------------------
   File        : getHTMLImpl
   Purpose     : 
   Syntax      : 
   Description : 
   Author(s)   : walter.riechsteiner
   Created     : Wed May 29 21:02:53 CEST 2024
   Notes       : 
 ----------------------------------------------------------------------*/

BLOCK-LEVEL ON ERROR UNDO, THROW.

USING OpenEdge.Net.HTTP.IHttpResponse FROM PROPATH.
USING OpenEdge.Net.HTTP.StatusCodeEnum FROM PROPATH.
USING OpenEdge.Web.IWebRequest FROM PROPATH.
USING OpenEdge.Web.WebHandler FROM PROPATH.
USING OpenEdge.Web.WebResponseWriter FROM PROPATH.
USING Progress.Json.ObjectModel.JsonObject FROM PROPATH.
USING Progress.Json.ObjectModel.JsonArray FROM PROPATH.
USING src.ch.adprime.gemis.WebHandlerUtilities FROM PROPATH.
USING utilities.utilitiesHandler FROM PROPATH.

CLASS getHTMLImpl INHERITS WebHandler:

    DEFINE VARIABLE outilitiesHandler AS utilitiesHandler NO-UNDO.
    DEFINE VARIABLE htviewer_ze       AS HANDLE           NO-UNDO.
    DEFINE VARIABLE iSprcd            AS INTEGER          NO-UNDO.

    DEFINE TEMP-TABLE tviewer_ko LIKE viewer_ko.
    DEFINE TEMP-TABLE tviewer_ze LIKE viewer_ze
        FIELD iMaxLaenge AS INTEGER 
        FIELD iBreite    AS INTEGER
        FIELD iDecimals  AS INTEGER 
        .

    { ttInput.i    }
    { properties_formular_html.i }


    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC LONGCHAR createHtmlFormular(  ):
        
        DEFINE VARIABLE lcHtmlFormular AS LONGCHAR  NO-UNDO.
        DEFINE VARIABLE iTabIndex      AS INTEGER   NO-UNDO.
        DEFINE VARIABLE cIndexFields   AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cString        AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cZeile         AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cAttribute     AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cTabIndex      AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cStyle         AS CHARACTER NO-UNDO.
        DEFINE VARIABLE lcSelectTexte  AS LONGCHAR  NO-UNDO.
        DEFINE VARIABLE lcSelectWerte  AS LONGCHAR  NO-UNDO.
        DEFINE VARIABLE lcOption       AS LONGCHAR  NO-UNDO.
        DEFINE VARIABLE ii             AS INTEGER   NO-UNDO.
        DEFINE VARIABLE lRetVal        AS LOGICAL   NO-UNDO.
        
        DEFINE VARIABLE cLabelText     AS CHARACTER NO-UNDO.
        DEFINE VARIABLE lFirma         AS LOGICAL   NO-UNDO INIT FALSE.
        DEFINE VARIABLE iLength        AS INTEGER   NO-UNDO.
        DEFINE VARIABLE iMaxBreite     AS INTEGER   NO-UNDO.
        DEFINE VARIABLE iAnzSpalten    AS INTEGER   NO-UNDO.
        DEFINE VARIABLE iBerechSpalten AS INTEGER   NO-UNDO.
        
        DEFINE BUFFER bFile FOR AnaDat._File.
        
        FIX-CODEPAGE (lcHtmlFormular) = 'utf-8'.
        
        FIND FIRST ttInput.

        EMPTY TEMP-TABLE tviewer_ko.
        EMPTY TEMP-TABLE tviewer_ze.
        
        htviewer_ze = TEMP-TABLE tviewer_ze:DEFAULT-BUFFER-HANDLE.
        
        DO WHILE TRUE:
            FIND FIRST viewer_ko NO-LOCK 
                WHERE viewer_ko.mandant  = ttInput.mandant
                AND   viewer_ko.benutzer = ttInput.benutzer
                AND   viewer_ko.program  = ttInput.programm
                AND   viewer_ko.tabelle  = ttInput.tabelle NO-ERROR.
            IF AVAILABLE viewer_ko THEN LEAVE. 
            FIND FIRST viewer_ko NO-LOCK 
                WHERE viewer_ko.mandant  = ttInput.mandant
                AND   viewer_ko.benutzer = 'admin'
                AND   viewer_ko.program  = ttInput.programm
                AND   viewer_ko.tabelle  = ttInput.tabelle NO-ERROR.
            IF NOT AVAILABLE viewer_ko THEN RETURN lcHtmlFormular.
            IF  viewer_ko.benutzer = 'admin' AND
                ttInput.benutzer   = 'admin' THEN LEAVE. 

            REPEAT TRANSACTION ON ERROR UNDO, LEAVE:
                CREATE  tviewer_ko.
                BUFFER-COPY viewer_ko
                    EXCEPT  viewer_ko.benutzer
                    TO      tviewer_ko
                    ASSIGN
                    tviewer_ko.benutzer = ttInput.benutzer.
                FOR EACH viewer_ze NO-LOCK OF viewer_ko:
                    CREATE  tviewer_ze.
                    BUFFER-COPY viewer_ze
                        EXCEPT  viewer_ze.benutzer
                        TO      tviewer_ze
                        ASSIGN 
                        tviewer_ze.benutzer = ttInput.benutzer.
                END.
                FIND viewer_ko OF tviewer_ko NO-ERROR.
                IF NOT AVAILABLE viewer_ko THEN 
                DO:
                    CREATE  viewer_ko.
                    BUFFER-COPY tviewer_ko TO viewer_ko.
                END.
                FOR EACH tviewer_ze NO-LOCK:
                    FIND viewer_ze OF tviewer_ze NO-ERROR.
                    IF AVAILABLE viewer_ze THEN NEXT.
                    CREATE viewer_ze.
                    BUFFER-COPY tviewer_ze TO viewer_ze.
                END.
                LEAVE.
            END.
        END.
        
        EMPTY TEMP-TABLE tviewer_ko.
        EMPTY TEMP-TABLE tviewer_ze.
        
        FIND bFile NO-LOCK 
            WHERE bFile._File-Name = viewer_ko.tabelle.
            
        IF viewer_ko.anzahlspalten < 10 THEN 
        DO:
            ASSIGN 
                iAnzSpalten    = viewer_ko.anzahlspalten
                iBerechSpalten = viewer_ko.anzahlspalten.
        END.
        ELSE 
        DO:
            cString = STRING(viewer_ko.anzahlspalten,'99').
            ASSIGN 
                iAnzSpalten    = INTEGER(SUBSTRING(cString,01,01))
                iBerechSpalten = INTEGER(SUBSTRING(cString,02,01)).
        END.
        
        cIndexFields = outilitiesHandler:getPrimaryIndexFields( INPUT viewer_ko.tabelle ) NO-ERROR.
        lcHtmlFormular = SUBSTITUTE(cform-container, iAnzSpalten) + CHR(10).

        iTabIndex = 0.
        CREATE  tviewer_ze.
        htviewer_ze = TEMP-TABLE tviewer_ze:DEFAULT-BUFFER-HANDLE.

        FOR EACH viewer_ze NO-LOCK OF viewer_ko
            BY viewer_ze.prior:
                
            IF  ttInput.params         = '' AND
                viewer_ze.privatedata <> '' THEN NEXT.
            IF ttInput.params <> '' THEN 
            DO:
                DO ii = 1 TO NUM-ENTRIES(viewer_ze.privatedata, ';'):
                    cString = ENTRY(ii, viewer_ze.privatedata, ';').
                    IF INDEX(viewer_ze.privatedata, cString) > 0 THEN LEAVE.
                END.
                IF ii > NUM-ENTRIES(viewer_ze.privatedata, ';') THEN NEXT.
            END.
                
            lcHtmlFormular = lcHtmlFormular + '    ' + cform-group + CHR(10).
            
            FIND FIRST tviewer_ze.
            BUFFER-COPY viewer_ze TO tviewer_ze.
            ASSIGN 
                tviewer_ze.iMaxLaenge = 0
                tviewer_ze.iBreite    = 0
                tviewer_ze.iDecimals  = 0
                .
            
            DO WHILE TRUE:
                cLabelText = ''.
                
                IF tviewer_ze.feld BEGINS 'Dummy' OR
                tviewer_ze.feld = 'ident'         THEN 
                DO:
                    ASSIGN 
                        tviewer_ze.lHidden    = TRUE 
                        tviewer_ze.lReadonly  = TRUE
                        tviewer_ze.styles     = ''
                        tviewer_ze.attributes = ''
                        // tviewer_ze.privatedata = ''
                        tviewer_ze.iMaxLaenge = 1
                        .
                    LEAVE.
                END.     
    
                IF NOT tviewer_ze.lHidden THEN 
                DO:
                    cString    = getLabel(INPUT 'side', INPUT iSprcd) NO-ERROR.
                    clabelText = FILL(' ',08) + SUBSTITUTE(clabel, tviewer_ze.feld, cString).
                END.
                
                IF tviewer_ze.selecttabelle = 'selections' THEN 
                DO:
                    lRetVal = fillSelection (INPUT-OUTPUT htviewer_ze, OUTPUT lcSelectWerte, OUTPUT lcSelectTexte).
                    IF lRetVal THEN 
                        ASSIGN
                            tviewer_ze.selecttabelle = ''
                            tviewer_ze.feldtype      = 'select'.
                    LEAVE.
                END.
                
                IF tviewer_ze.selecttabelle <> '' THEN 
                DO:
                    lRetVal = fillSelectionAusTabelle(INPUT-OUTPUT htviewer_ze, OUTPUT lcSelectWerte, OUTPUT lcSelectTexte).
                    IF lRetVal THEN 
                        ASSIGN
                            tviewer_ze.selecttabelle = ''
                            tviewer_ze.feldtype      = 'select'.
                    LEAVE.
                END.
                
                FIND AnaDat._Field NO-LOCK
                    WHERE AnaDat._Field._Field-name = tviewer_ze.feld
                    AND   AnaDat._FIeld._File-Recid = RECID(bFile).
                IF INDEX(_Field._View-AS, 'TOGGLE-BOX') > 0 THEN
                DO:
                    tviewer_ze.feldtype = 'checkbox'.
                    LEAVE.
                END.
                IF INDEX(_Field._View-AS, 'EDITOR') > 0 THEN
                DO:
                    tviewer_ze.feldtype = 'textarea'.
                    LEAVE.
                END.

                LEAVE.
            END.
            
            iLength   = 0.
            iDecimals = 0.
            CASE tviewer_ze.feldtype:
                WHEN 'character' THEN
                    ASSIGN 
                        tviewer_ze.iBreite    = getMaxLength(tviewer_ze.feldformat)
                        tviewer_ze.iMaxLaenge = tviewer_ze.iBreite.
                WHEN 'textarea' THEN
                    ASSIGN 
                        tviewer_ze.iBreite    = getMaxLength(tviewer_ze.feldformat)
                        tviewer_ze.iMaxLaenge = tviewer_ze.iBreite.
                WHEN 'integer' THEN 
                    ASSIGN 
                        tviewer_ze.iBreite    = LENGTH(tviewer_ze.feldformat)
                        tviewer_ze.iMaxLaenge = tviewer_ze.iBreite
                        tviewer_ze.iDecimals  = -1.
                WHEN 'decimal' THEN 
                    DO:
                        tviewer_ze.iBreite    = LENGTH(tviewer_ze.feldformat).
                        tviewer_ze.iMaxLaenge = tviewer_ze.iBreite.
                        ii                 = INDEX(tviewer_ze.feldformat, '.').
                        IF ii > 0 THEN  tviewer_ze.iDecimals = LENGTH(ENTRY(2, tviewer_ze.feldformat, '.')).
                        ELSE            tviewer_ze.iDecimals = -1.
                    END.
                WHEN 'checkbox' THEN 
                    DO:
                        tviewer_ze.iBreite = 2.
                    END.
                WHEN 'select' THEN 
                    DO:
                        tviewer_ze.iBreite = iMaxBreite.
                    END.
                OTHERWISE 
                ASSIGN 
                    tviewer_ze.iBreite    = getMaxLength(tviewer_ze.feldformat)
                    tviewer_ze.iMaxLaenge = tviewer_ze.iBreite.
            END CASE.
            
            iMaxBreite = 0.
            CASE iBerechSpalten:
                WHEN 1 THEN 
                    iMaxBreite = 90.
                WHEN 2 THEN 
                    iMaxBreite = 45.
                WHEN 3 THEN 
                    iMaxBreite = 30.
                WHEN 4 THEN 
                    iMaxBreite = 22.
                OTHERWISE 
                iMaxBreite = 20.
            END CASE.
                
            IF tviewer_ze.iBreite > iMaxBreite THEN tviewer_ze.iBreite = iMaxBreite. 
        
            cAttribute = ''.
            cTabIndex  = ''.
            cStyle     = ''.
            lcOption   = ''.
            IF  NOT tviewer_ze.lHidden   AND 
                NOT tviewer_ze.lReadonly THEN 
            DO:
                iTabIndex  = iTabIndex + 1.
                cTabIndex  = SUBSTITUTE ('tabindex="&1" ', TRIM(STRING(iTabIndex,'>>>9'))).
            END.
    
            DO WHILE lcSelectTexte <> '':
                DO ii = 1 TO NUM-ENTRIES(lcSelectWerte, ';'):
                    lcOption = lcOption
                        + (IF lcOption = '' THEN '' ELSE CHR(10))
                        + SUBSTITUTE('&3<option value="&1">&2</option>', ENTRY(ii, lcSelectWerte, ';'), ENTRY(ii, lcSelectTexte, ';'), FILL(' ',12)).
                END.
                LEAVE.
            END.
            //
            //  Attribute definieren
            //
            cAttribute = SUBSTITUTE('id= "&1" name="&1" ', tviewer_ze.feld, tviewer_ze.feld).
            IF tviewer_ze.lHidden  THEN cAttribute = cAttribute + 'type="hidden" '  .
            ELSE 
            DO:
                CASE tviewer_ze.feldtype:
                    WHEN 'checkbox' THEN 
                        cAttribute = cAttribute + 'type="checkbox" '.
                    WHEN 'textarea' THEN 
                        cAttribute = cAttribute + 'type="text" wrap="soft" '.
                    OTHERWISE    
                    cAttribute = cAttribute + 'type="text" '.
                END CASE.
            END.
            IF tviewer_ze.lReadonly THEN cAttribute = cAttribute + 'readonly="true" '.
            IF tviewer_ze.iMaxLaenge > 0 THEN cAttribute = cAttribute + SUBSTITUTE('maxlength="&1" ', TRIM(STRING(tviewer_ze.iMaxLaenge))).
            IF tviewer_ze.iDecimals  > 0 THEN cAttribute = cAttribute + SUBSTITUTE('step="0.&1" ', FILL('0', tviewer_ze.iDecimals)).
            IF tviewer_ze.iDecimals  < 0 THEN cAttribute = cAttribute + 'step="0" '.
            IF cTabIndex <> ''           THEN cAttribute = cAttribute + cTabIndex.
            //
            //  Style definieren
            //
            DO WHILE TRUE:
                IF tviewer_ze.feldtype = 'select' THEN 
                DO:
                    cStyle = SUBSTITUTE('width: &1vw; text-align: &2;', tviewer_ze.iBreite, "left").
                    LEAVE.
                END.
                IF tviewer_ze.feldtype = 'textarea' THEN 
                DO:
                    cStyle = SUBSTITUTE('width: &1vw; text-align: &2;', tviewer_ze.iBreite, "left").
                    LEAVE.
                END.
                cStyle = SUBSTITUTE('width: &1vw; text-align: &2;', tviewer_ze.iBreite, tviewer_ze.textalign).
                LEAVE.
            END.
            
            cStyle = 'style=' + QUOTER(cStyle).
            
            CASE tviewer_ze.feldtype:
                WHEN 'textarea'   THEN 
                    cZeile = FILL(' ',08) +  SUBSTITUTE(cTextarea, cAttribute, cStyle, '' ).
                WHEN 'select'    THEN 
                    cZeile = FILL(' ',08) +  SUBSTITUTE(cSelect, cAttribute, cStyle, tviewer_ze.privatedata, CHR(10), lcOption, FILL(' ',08) ).
                OTHERWISE
                cZeile = FILL(' ',08) + SUBSTITUTE(cInput , cAttribute, cStyle, '' ).
            END CASE.

            IF cLabelText <> '' THEN lcHtmlFormular = lcHtmlFormular + cLabelText + CHR(10).              
            lcHtmlFormular = lcHtmlFormular + cZeile + CHR(10).
        
            lcHtmlFormular = lcHtmlFormular + '    </div>' + CHR(10).
    
        END. 
    
        lcHtmlFormular = lcHtmlFormular + '</div>' + CHR(10).

        RETURN lcHtmlFormular.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC CHARACTER createSelections(
        INPUT  iprviewer_ze AS RECID,
        INPUT  ipiSprcd     AS INTEGER,
        OUTPUT cWerte       AS CHARACTER,
        OUTPUT cAnzeige     AS CHARACTER
        ):

        DEFINE VARIABLE cTabelle AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cInhalt  AS CHARACTER NO-UNDO.
        DEFINE VARIABLE lFound   AS LOGICAL   NO-UNDO.
    
        DEFINE BUFFER btviewer_ze FOR tviewer_ze.
    
        FIND btviewer_ze NO-LOCK WHERE RECID(btviewer_ze) = iprviewer_ze.

        FOR EACH selections NO-LOCK 
            WHERE selections.mandant = btviewer_ze.mandant
            AND   selections.tabelle = btviewer_ze.tabelle
            AND   selections.feld    = btviewer_ze.feld
            AND   selections.sprcd   = ipiSprcd:
            
            cWerte = cWerte
                + (IF cWerte = '' THEN '' ELSE ';')
                + selections.wert.     
            cAnzeige = cAnzeige
                + (IF cAnzeige = '' THEN '' ELSE ';')
                + selections.anzeige + SUBSTITUTE(' (&1) ':U, selections.wert).
        END.
    
        IF cWerte <> '' THEN RETURN cWerte.
         
        FOR EACH selections NO-LOCK 
            WHERE selections.mandant = btviewer_ze.mandant
            AND   selections.tabelle = ''
            AND   selections.feld    = btviewer_ze.feld
            AND   selections.sprcd   = ipiSprcd:
            cWerte = cWerte
                + (IF cWerte = '' THEN '' ELSE ';')
                + selections.wert.     
            cAnzeige = cAnzeige
                + (IF cAnzeige = '' THEN '' ELSE ';')
                + selections.anzeige + SUBSTITUTE(' (&1) ':U, selections.wert).
        END.
    
        IF cWerte <> '' THEN RETURN cWerte.
         
        FOR EACH selections NO-LOCK 
            WHERE selections.mandant = btviewer_ze.mandant
            AND   selections.tabelle = ''
            AND   selections.feld    = btviewer_ze.feld:
            cWerte = cWerte
                + (IF cWerte = '' THEN '' ELSE ';')
                + selections.wert.     
            cAnzeige = cAnzeige
                + (IF cAnzeige = '' THEN '' ELSE ';')
                + selections.anzeige + SUBSTITUTE(' (&1) ':U, selections.wert).
        END.
    
    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC CHARACTER getLabel(
        INPUT ipcArt    AS CHARACTER,
        INPUT ipiSprcd  AS INTEGER 
        ):
        
        DEFINE VARIABLE cLabel AS CHARACTER NO-UNDO.
    
        DEFINE BUFFER btviewer_ze FOR tviewer_ze.
    
        FIND FIRST btviewer_ze NO-LOCK.
    
        IF  ipiSprcd = 0  OR
            ipiSprcd > 10 THEN ipiSprcd = 1.
    
        FIND FIRST labeltexte NO-LOCK 
            WHERE labeltexte.mandant   = btviewer_ze.mandant
            AND   labeltexte.benutzer  = btviewer_ze.benutzer
            AND   labeltexte.program   = btviewer_ze.program
            AND   labeltexte.tabelle   = btviewer_ze.tabelle
            AND   labeltexte.feld      = btviewer_ze.feld
            AND   labeltexte.sprcd     = ipiSprcd NO-ERROR.
        IF NOT AVAILABLE labeltexte THEN 
        DO: 
            FIND FIRST labeltexte NO-LOCK 
                WHERE labeltexte.mandant   = btviewer_ze.mandant
                AND   labeltexte.program   = btviewer_ze.program
                AND   labeltexte.tabelle   = btviewer_ze.tabelle
                AND   labeltexte.feld      = btviewer_ze.feld
                AND   labeltexte.sprcd     = ipiSprcd NO-ERROR.
        END.
        IF NOT AVAILABLE labeltexte THEN 
        DO:
            FIND FIRST labeltexte NO-LOCK 
                WHERE labeltexte.mandant   = btviewer_ze.mandant
                AND   labeltexte.tabelle   = btviewer_ze.tabelle
                AND   labeltexte.feld      = btviewer_ze.feld
                AND   labeltexte.sprcd     = ipiSprcd NO-ERROR.
        END.
        IF NOT AVAILABLE labeltexte THEN 
        DO:
            FIND FIRST labeltexte NO-LOCK 
                WHERE labeltexte.mandant   = btviewer_ze.mandant
                AND   labeltexte.feld      = btviewer_ze.feld
                AND   labeltexte.sprcd     = ipiSprcd NO-ERROR.
        END.

        CASE ipcArt:
            WHEN 'side' THEN 
                cLabel = (IF AVAILABLE labeltexte THEN labeltexte.sidelabel ELSE btviewer_ze.feld).
            WHEN 'head' THEN 
                cLabel = (IF AVAILABLE labeltexte THEN labeltexte.headlabel ELSE btviewer_ze.feld).
        END CASE.
    
        RETURN cLabel.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC INTEGER getMaxLength(
        ipcFormat AS CHARACTER
        ):
        /*------------------------------------------------------------------------------
         Purpose:
         Notes:
        ------------------------------------------------------------------------------*/

        DEFINE VARIABLE x1      AS INTEGER   NO-UNDO.
        DEFINE VARIABLE cFormat AS CHARACTER NO-UNDO.
    
        x1 = INDEX(ipcFormat, '(').
        IF x1 = 0 THEN RETURN LENGTH(ipcFormat).
    
        cFormat = REPLACE(ipcFormat, '(', ';').
        cFormat = REPLACE(cFormat  , ')', ';').
        x1 = INTEGER(ENTRY(2, cFormat, ';')).

        RETURN x1.

    END METHOD.

    METHOD OVERRIDE PROTECTED INTEGER HandlePost(INPUT poRequest AS IWebRequest):
        DEFINE VARIABLE oResponse     AS IHttpResponse     NO-UNDO.
        DEFINE VARIABLE oWriter       AS WebResponseWriter NO-UNDO.
        DEFINE VARIABLE oJsonData     AS JsonObject        NO-UNDO.
        DEFINE VARIABLE lcJsonString  AS LONGCHAR          NO-UNDO.
        DEFINE VARIABLE oInput        AS JsonObject        NO-UNDO.
        
        DEFINE VARIABLE hbttDBTabelle AS HANDLE            NO-UNDO.
        DEFINE VARIABLE httDBTabelle  AS HANDLE            NO-UNDO.
        DEFINE VARIABLE hqDBTabelle   AS HANDLE            NO-UNDO.
        DEFINE VARIABLE hbDBTabelle   AS HANDLE            NO-UNDO.
    
        DEFINE VARIABLE lRetVal       AS LOGICAL           NO-UNDO.
        DEFINE VARIABLE cAktion       AS CHARACTER         NO-UNDO.
        
        EMPTY TEMP-TABLE ttInput    .

        lRetVal = WebHandlerUtilities:getJsonFromRequest(INPUT poRequest, OUTPUT oJsonData) NO-ERROR.
        MESSAGE 'getJsonFromRequest    = ' lRetVal.
        
        oJsonData:WRITE(lcJsonString, FALSE).
        MESSAGE 'ganzer eingangsstring = ' STRING(lcJsonString).
        
        //
        //  Input-Daten (Steuersatz) aus JsonObject lesen und in ttInput füllen
        //
        EMPTY TEMP-TABLE ttInput    .
        hbttInput = TEMP-TABLE ttInput:DEFAULT-BUFFER-HANDLE.
        oInput    = NEW JsonObject().
        oInput    = oJsonData:GetJsonObject('ttInput').
        lRetVal   = hbttInput:READ-JSON ('JsonObject', oInput).
        
        FIND FIRST ttInput.
        cAktion = ttInput.action.
        iSprcd  = INTEGER(ttInput.sprcd).
        IF iSprcd < 1 OR iSprcd > 10 THEN iSprcd = 1.
        
        outilitiesHandler = NEW utilitiesHandler ().
        
        DO WHILE lRetVal:
            lcJsonString = createHtmlFormular().
            
            MESSAGE 'Rückgabe: ' + STRING(lcJsonString).

            oResponse             = NEW OpenEdge.Web.WebResponse().
            oResponse:StatusCode  = INTEGER(StatusCodeEnum:OK).
            oResponse:ContentType = "text/plain".
            oWriter               = NEW WebResponseWriter(oResponse).
            
            oWriter:Open().
            /*            oWriter:Write(htmldokumente.htmltext).*/
            oWriter:Write(lcJsonString).
            oWriter:Close().
            
            LEAVE.
        END.
        
        DO WHILE NOT lRetVal: 
            oResponse = NEW OpenEdge.Web.WebResponse().
            oResponse:StatusCode = INTEGER(StatusCodeEnum:OK).
            oResponse:ContentType = "application/json;charset=utf-8".
            oWriter = NEW WebResponseWriter(oResponse).
            oWriter:Open().
            MESSAGE 'lcString Rückgabe: ' + STRING(lcJsonString) VIEW-AS ALERT-BOX.
            oWriter:Write(lcJsonString).
            oWriter:Close().
            LEAVE.
        END.

        MESSAGE "Exiting HandlePost" VIEW-AS ALERT-BOX.

        CATCH e AS Progress.Lang.Error:
            MESSAGE "Exception occurred: " + e:GetMessage(1) VIEW-AS ALERT-BOX ERROR BUTTONS OK.
            RETURN -1.
        END CATCH.
        
    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC LOGICAL fillSelection(
        INPUT-OUTPUT iphtviewer_ze AS HANDLE,
        OUTPUT oplcSelectWerte     AS LONGCHAR, 
        OUTPUT oplcSelectTexte     AS LONGCHAR 
        ):

        DEFINE VARIABLE cTabelle AS CHARACTER NO-UNDO.
                
        ASSIGN 
            iphtviewer_ze::selecttexte = ''
            iphtviewer_ze::selectwerte = ''
            cTabelle                   = iphtviewer_ze::tabelle
            oplcSelectWerte            = ''
            oplcSelectTexte            = ''
            NO-ERROR.
            
        FIND FIRST selections NO-LOCK 
            WHERE selections.mandant = iphtviewer_ze::mandant
            AND   selections.tabelle = cTabelle
            AND   selections.feld    = iphtviewer_ze::feld
            AND   selections.Sprcd   = iSprcd NO-ERROR.
        IF NOT AVAILABLE selections THEN 
        DO:
            cTabelle = ''.
            FIND FIRST selections NO-LOCK 
                WHERE selections.mandant = iphtviewer_ze::mandant
                AND   selections.tabelle = cTabelle
                AND   selections.feld    = iphtviewer_ze::feld
                AND   selections.Sprcd   = iSprcd NO-ERROR.
        END.
        IF NOT AVAILABLE (selections) THEN RETURN FALSE.

        FOR EACH selections NO-LOCK 
            WHERE selections.mandant = iphtviewer_ze::mandant
            AND   selections.tabelle = cTabelle
            AND   selections.feld    = iphtviewer_ze::feld
            AND   selections.Sprcd   = iSprcd:
            ASSIGN
                oplcSelectTexte = oplcSelectTexte
                    + (IF oplcSelectTexte = '' THEN '' ELSE ';')
                    + selections.anzeige.
            ASSIGN
                oplcSelectWerte = oplcSelectWerte
                    + (IF oplcSelectWerte = '' THEN '' ELSE ';')
                    + selections.wert.
        END.

        RETURN TRUE.

    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/

    METHOD PUBLIC LOGICAL fillSelectionAusTabelle(
        INPUT-OUTPUT iphtviewer_ze AS HANDLE,
        OUTPUT oplcSelectWerte     AS LONGCHAR, 
        OUTPUT oplcSelectTexte     AS LONGCHAR 
        ):
            
        DEFINE VARIABLE cTabelle   AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cFeld      AS CHARACTER NO-UNDO.
        DEFINE VARIABLE cAnzeige   AS CHARACTER NO-UNDO.
        DEFINE VARIABLE iFeldIndex AS INTEGER   NO-UNDO.
        DEFINE VARIABLE cString    AS CHARACTER NO-UNDO.
            
        DEFINE VARIABLE hqTabelle  AS HANDLE    NO-UNDO.
        DEFINE VARIABLE hbTabelle  AS HANDLE    NO-UNDO.
        DEFINE VARIABLE cWhere     AS CHARACTER NO-UNDO.
            
        ASSIGN 
            cTabelle        = ENTRY(1, iphtviewer_ze::selecttabelle, ';')
            cFeld           = ENTRY(2, iphtviewer_ze::selecttabelle, ';')
            cAnzeige        = ENTRY(3, iphtviewer_ze::selecttabelle, ';')
            
            oplcSelectWerte = ''
            oplcSelectTexte = ''
            NO-ERROR.
                
        CREATE QUERY hqTabelle.
        CREATE BUFFER hbTabelle FOR TABLE cTabelle.
        cWhere = SUBSTITUTE('FOR EACH &1 NO-LOCK WHERE &1.Firma = &2 ', cTabelle, QUOTER(iphtviewer_ze::mandant) ).
        hqTabelle:SET-BUFFERS (hbTabelle).
        hqTabelle:QUERY-PREPARE (cWhere).
        hqTabelle:QUERY-OPEN ().
        hqTabelle:GET-FIRST ().
        
        iFeldIndex = (IF hbTabelle:BUFFER-FIELD(cAnzeige):EXTENT = 0 THEN 0 ELSE iSprcd).

        DO WHILE NOT hqTabelle:QUERY-OFF-END:
            cString = hbTabelle:BUFFER-FIELD(cAnzeige):BUFFER-VALUE(iFeldIndex).
            oplcSelectTexte = oplcSelectTexte
                + (IF oplcSelectTexte = '' THEN '' ELSE ';')
                + cString.
                    
            cString = hbTabelle:BUFFER-FIELD(cFeld):BUFFER-VALUE(0).
            oplcSelectWerte = oplcSelectWerte
                + (IF oplcSelectWerte = '' THEN '' ELSE ';')
                + cString.
            hqTabelle:GET-NEXT ().
        END.
            
        hqTabelle:QUERY-CLOSE ().
        DELETE OBJECT hbTabelle NO-ERROR.
        DELETE OBJECT hqTabelle NO-ERROR.   
        
        RETURN TRUE .

    END METHOD.

    METHOD OVERRIDE PROTECTED INTEGER HandleNotAllowedMethod(INPUT poRequest AS IWebRequest):
        DEFINE VARIABLE result AS INTEGER NO-UNDO.
        MESSAGE "HandleNotAllowedMethod called" VIEW-AS ALERT-BOX.
        RETURN result.
    END METHOD.

    METHOD OVERRIDE PROTECTED INTEGER HandleNotImplemented(INPUT poRequest AS IWebRequest):
        DEFINE VARIABLE result AS INTEGER NO-UNDO.
        MESSAGE "HandleNotImplemented called" VIEW-AS ALERT-BOX.
        RETURN result.
    END METHOD.

END CLASS.
