*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
*
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  

PARAMETERS cely_string, auth_string

#DEFINE CRLF CHR(13)+CHR(10)
#DEFINE PAGESIZE  "3"

DO publikuj WITH "http_adresa", ""
DO publikuj WITH "http_auth_body_string", ""
DO publikuj WITH "http_path", ""
DO publikuj WITH "http_auth_token", ""
DO publikuj WITH "http_jmeno_logu", ""

http_adresa = "canteen-adient-backend.alto-production.mine.nu"
http_auth_body_string = '{"username": "admin", "password": "admin" }'


CLEAR 
SET EXACT OFF

http_path = LOWER(JUSTPATH(sys(16))) + "\"

SET PATH TO (http_path)                       ADDITIVE
SET PATH TO (http_path + "west-wind")         ADDITIVE 
SET PATH TO (http_path + "west-wind\classes") ADDITIVE 

SET PROCEDURE TO (SYS(16))                    ADDITIVE 

DO wwHTTP

DO vytvor_objekty_http    && objekty wwHttp se vytvori zde a existuji po celou dobu behu programu, jinak se tvori pri kazdem volani http_get/put/delete

http_jmeno_logu = IIF( VARTYPE(gccen_path) = "C", m.gccen_path, ".\") + "zu_http" + LEFT(STRTRAN(TTOC(DATETIME(), 3), ":", "-"), 16) + ".txt"

DO http_log WITH chr(9) + program(4) + " " + program(5) + " " + program(6) + " from " + UPPER(m.machine), "WestWind initialized to " + m.http_adresa
? "- - -  " + TTOC(datetime()) + "  WestWind initialized to " + m.http_adresa + "  - - -"

auth_json = http_auth()
ACTIVATE SCREEN 
? m.http_auth_token



*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
PROCEDURE http_get (url_end)
request_string = m.http_adresa + url_end

IF VARTYPE(http_auth_token) = "C" .and. LEN(m.http_auth_token) > 11
    get_HTTP.AddHeader('Authorization', "Token " + m.http_auth_token)
ENDIF 
http_zacatek_prace = SECONDS()

*** Send the request and retrieve HTTP result
lcHTML=""
lnText=0

lnResult=get_HTTP.HTTPGetEx( m.url_end, @lcHTML, @lnText )
IF lnResult # 0
   ? lnResult, get_HTTP.cErrorMsg
*   RETURN
ENDIF
*** Send the request and retrieve HTTP result


retval_string = sloz_response_string ( m.lcHTML, get_HTTP.cResultCode, get_HTTP.cResultCodeMessage, get_HTTP.nError, get_HTTP.cErrorMSg )
*retval_string = sloz_response_string ( get_HTTP.HttpGet(m.request_string), get_HTTP.cResultCode, get_HTTP.cResultCodeMessage, get_HTTP.nError, get_HTTP.cErrorMSg )
DO http_log WITH m.retval_string, "GET " + m.url_end + " (" + ALLTRIM(STR(SECONDS() - m.http_zacatek_prace, 7, 2)) + "sec)" 

IF "403" $ get_string_item (m.retval_string, "http_status")
    auth_json = http_auth()
*    ? "AUTH:", m.auth_json
    IF .not. ("403" $ get_string_item (m.auth_json, "http_status"))
        IF .not. EMPTY(m.http_auth_token)
            get_HTTP.AddHeader('Authorization', "Token " + m.http_auth_token)
        ENDIF 
        lcHTML=""
        lnText=0
        lnResult=get_HTTP.HTTPGetEx("/" + m.url_end, @lcHTML, @lnText)
        retval_string = sloz_response_string ( m.lcHTML, get_HTTP.cResultCode, get_HTTP.cResultCodeMessage, get_HTTP.nError, get_HTTP.cErrorMSg )
*        retval_string = sloz_response_string ( get_HTTP.HttpGet(m.request_string), get_HTTP.cResultCode, get_HTTP.cResultCodeMessage, get_HTTP.nError, get_HTTP.cErrorMSg )
        DO http_log WITH m.retval_string, "GET " + m.url_end + " (" + ALLTRIM(STR(SECONDS() - m.http_zacatek_prace, 7, 2)) + "sec)" 
    ENDIF 
ENDIF 

*get_HTTP.httpclose()
RETURN m.retval_string 


*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
PROCEDURE http_request (url_end, sloveso, body_string)     && PUT POST PATCH DELETE
request_string = m.http_adresa + m.url_end

IF VARTYPE(pp_HTTP) # "O"           && pokud objekt neexistuje, je vytvoren a nastaven
    pp_HTTP = CREATEOBJECT("wwHttp")
    DO set_http_parms WITH pp_HTTP, "PUT"
ENDIF

IF VARTYPE(http_auth_token) = "C" .and. LEN(m.http_auth_token) > 11
    pp_HTTP.AddHeader('Authorization', "Token " + m.http_auth_token)
ENDIF 

IF VARTYPE(body_string) = "C" .and. LEN(m.body_string) > 0
    pp_HTTP.AddPostKey()    && to reset post buffer
    pp_HTTP.AddPostKey(strconv(strconv(body_string,1),9))   && do UTF-8
ELSE
    body_string = ""
ENDIF 

pp_HTTP.cHttpVerb = m.sloveso
http_zacatek_prace = SECONDS()

IF VARTYPE(http_read_only_mode) = "U"
    retval_string = sloz_response_string ( pp_HTTP.HttpGet(m.request_string), pp_HTTP.cResultCode, pp_HTTP.cResultCodeMessage, pp_HTTP.nError, pp_HTTP.cErrorMSg )
ELSE
    retval_string = "200 OK http_read_only_mode"
ENDIF 

DO http_log WITH m.retval_string, m.sloveso + " " + m.request_string + " (" + ALLTRIM(STR(SECONDS() - m.http_zacatek_prace, 7, 2)) + "sec)" + IIF(EMPTY(m.body_string), "", CRLF + CHR(9) + "BODY>>> " + m.body_string + " <<<BODY ")

IF "403" $ get_string_item (m.retval_string, "http_status")
    auth_json = http_auth()
*    ? "AUTH:", m.auth_json
    IF .not. ("403" $ get_string_item (m.auth_json, "http_status"))

        IF VARTYPE(http_auth_token) = "C" .and. LEN(m.http_auth_token) > 11
            pp_HTTP.AddHeader('Authorization', "Token " + m.http_auth_token)
        ENDIF 
        pp_HTTP.cHttpVerb = m.sloveso
        IF VARTYPE(body_string) = "C" .and. LEN(m.body_string) > 0
            pp_HTTP.AddPostKey()    && to reset post buffer
            pp_HTTP.AddPostKey(strconv(strconv(body_string,1),9))   && do UTF-8
        ELSE
            body_string = ""
        ENDIF 

        retval_string = sloz_response_string ( pp_HTTP.HttpGet(m.request_string), pp_HTTP.cResultCode, pp_HTTP.cResultCodeMessage, pp_HTTP.nError, pp_HTTP.cErrorMSg )
        DO http_log WITH m.retval_string, m.sloveso + " " + m.request_string + " (" + ALLTRIM(STR(SECONDS() - m.http_zacatek_prace, 7, 2)) + "sec)" + IIF(EMPTY(m.body_string), "", CRLF + CHR(9) + "BODY>>> " + m.body_string + " <<<BODY ")
    ENDIF 

ENDIF 

*pp_HTTP.httpclose()
RETURN m.retval_string 


*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
PROCEDURE http_auth 

auth_request_string = "https://canteen-adient-backend.alto-production.mine.nu"  + "/auth/get_token"

auth_HTTP=CREATEOBJECT("wwHttp")
DO set_http_parms WITH auth_HTTP, "PUT"
auth_HTTP.AddPostKey()    && to reset post buffer
auth_HTTP.AddPostKey(strconv(strconv(http_auth_body_string,1),9))   && do UTF-8
auth_HTTP.cHttpVerb = "POST"

auth_retval_string = sloz_response_string ( auth_HTTP.HttpGet(m.auth_request_string), auth_HTTP.cResultCode, auth_HTTP.cResultCodeMessage, auth_HTTP.nError, auth_HTTP.cErrorMSg )

DO http_log WITH m.auth_retval_string, "AUTH "
*auth_HTTP.httpclose()

IF json_ok(m.auth_retval_string)
    http_auth_token = get_string_item (m.auth_retval_string, "token")
    IF VARTYPE(m.http_auth_token) # "C"
            http_auth_token = "-- DENIED --"
    ENDIF 
ELSE
    http_auth_token = ""
ENDIF 
RETURN m.auth_retval_string 


*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
PROCEDURE vytvor_objekty_http
   IF VARTYPE(get_HTTP) = "U"           && objekt pro cteci routy (GET)
       PUBLIC get_HTTP
   ENDIF
   get_HTTP=CREATEOBJECT("wwHttp")
   DO set_http_parms WITH get_HTTP, "GET"
   get_HTTP.HTTPConnect( m.http_adresa, "", "", .T. )
   DO set_http_parms WITH get_HTTP, "GET"

   IF VARTYPE(del_HTTP) = "U"           && objekt pro deletovaci routy (DELETE)
       PUBLIC del_HTTP
   ENDIF
   del_HTTP=CREATEOBJECT("wwHttp")
   DO set_http_parms WITH del_HTTP, "GET"

   IF VARTYPE(pp_HTTP) = "U"        && objekt pro zapisovaci routy (PUT, POST)
       PUBLIC pp_HTTP
   ENDIF
   pp_HTTP = CREATEOBJECT("wwHttp")
   DO set_http_parms WITH pp_HTTP, "PUT"


*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
PROCEDURE set_http_parms
PARAMETERS http_object, typ_objectu

http_object.nHttpServiceFlags = BITOR( 0x00400000, 0x00002000, 0x00001000 )  && keep connection + ignore cert
http_object.nconnecttimeout = 6
http_object.cUserAgent = "Alto-WW"
http_object.lIgnoreCertificateWarnings = .T.
http_object.cpassword = "1alto2alta"
http_object.cusername = "alto"

IF m.typ_objectu = "PUT"
    http_object.nHttpPostMode = 8
    http_object.cContentType = "application/json; charset=UTF-8"
ENDIF 


*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
FUNCTION sloz_response_string (response, ResultCode, ResultMsg, ErrNo, ErrMsg)
http_response = STRCONV(STRCONV(m.response, 11),2)
status_string = ' "http_status":"' + ResultCode + " " + ResultMsg + '", '
IF Errno # 0
   status_string = m.status_string + '"http_error":"'  + ALLTRIM(STR(ErrNo)) + ErrMSg + '", '
ENDIF
zacatek_json = AT("{", m.http_response)
IF BETWEEN(m.zacatek_json, 1, 11)
    RETURN LEFT(m.http_response, m.zacatek_json) + m.status_string + SUBSTR(m.http_response, m.zacatek_json+1)
ELSE
    RETURN '{' + m.status_string + '}'
ENDIF 


*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
*     hleda v parametru retezec za "http_status" hodnotu "200" a "OK"
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
FUNCTION json_ok (json)
retval = LEFT(SUBSTR(json, ATC('"http_status":', m.json)+11), 22)
RETURN ("20" $ m.retval .and. "OK" $ m.retval)


*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
*      hleda v parametru hodnotu (cislo) za "count"
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
FUNCTION json_rowcount (json)
pozice = ATC('"count":', m.json)
IF m.pozice > 0
    retval = ALLTRIM(LEFT(SUBSTR(json, m.pozice+8), 22))
    RETURN INT(VAL(m.retval))
ELSE
    RETURN -1
ENDIF 


*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
FUNCTION get_integer_item (json, item, poradi)
IF EMPTY(m.poradi)
    poradi = 1
ENDIF 
LOCAL at_item, texticek
at_item = ATC('"' + m.item + '":', m.json, m.poradi)
IF m.at_item > 0
   texticek = LEFT(SUBSTR(m.json, m.at_item + LEN(ALLTRIM(m.item)) + 3), 33)
   RETURN INT(VAL(m.texticek))
ELSE
   RETURN 0
ENDIF 

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
FUNCTION get_num_item (json, item, poradi)
IF EMPTY(m.poradi)
    poradi = 1
ENDIF 
LOCAL at_item, o_set_point, textcislo, texticek, ii, retval
at_item = ATC('"' + m.item + '":', m.json, m.poradi)
IF m.at_item > 0
   texticek = SUBSTR(m.json, m.at_item + LEN(ALLTRIM(m.item)) + 3)
   IF ATC("null", LEFT(texticek, 6)) = 0
       textcislo = ""
       FOR ii = 1 TO LEN(m.texticek)
          pismenko = SUBSTR(m.texticek, m.ii, 1)
          IF m.pismenko $ ",]}"
              EXIT 
          ELSE 
              textcislo = m.textcislo + m.pismenko
          ENDIF 
       ENDFOR 
       o_set_point = SET("POINT")
       SET POINT TO "."
       retval = VAL(m.textcislo)
       SET POINT TO (m.o_set_point)
       RETURN m.retval
   ENDIF 
ELSE
   RETURN .null.
ENDIF 

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
FUNCTION get_boolean_item (json, item, poradi)
IF EMPTY(m.poradi)
    poradi = 1
ENDIF 
LOCAL at_item, o_set_point, textcislo, texticek, ii, retval
at_item = ATC('"' + m.item + '":', m.json, m.poradi)
IF m.at_item > 0
   texticek = SUBSTR(m.json, m.at_item + LEN(ALLTRIM(m.item)) + 3)
   IF ATC("null", LEFT(texticek, 6)) = 0
       textcislo = ""
       FOR ii = 1 TO LEN(m.texticek)
          pismenko = SUBSTR(m.texticek, m.ii, 1)
          IF m.pismenko $ ",]}"
              EXIT 
          ELSE 
              textcislo = m.textcislo + m.pismenko
          ENDIF 
       ENDFOR 
       retval = ATC("true", m.textcislo) > 0
       RETURN m.retval
   ELSE
       RETURN .null.
   ENDIF 
ELSE
   RETURN .null.
ENDIF 

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
FUNCTION get_string_item (json, item, poradi)
IF EMPTY(m.poradi)
    poradi = 1
ENDIF 
LOCAL at_item, o_set_point, textcislo, texticek, ii, retval
at_item = ATC('"' + m.item + '":', m.json, m.poradi)
IF m.at_item > 0
    texticek = ALLTRIM(SUBSTR(m.json, m.at_item + LEN(ALLTRIM(m.item)) + 3))
    IF ATC("null", LEFT(texticek, 6)) = 0
        at_quote1 = AT('"', m.texticek, 1)
        at_quote2 = AT('"', m.texticek, 2)
        IF m.at_quote2 > 0
           retval = SUBSTR(m.texticek, m.at_quote1 + 1, m.at_quote2 - m.at_quote1-1)
           RETURN m.retval
        ENDIF 
    ENDIF 
ENDIF 
RETURN .null.

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
FUNCTION get_object_item (json, item, poradi)
IF EMPTY(m.poradi)
    poradi = 1
ENDIF 
LOCAL at_item, o_set_point, textcislo, texticek, ii, retval
at_item = ATC('"' + m.item + '":', m.json, m.poradi)
IF m.at_item > 0
    texticek = ALLTRIM(SUBSTR(m.json, m.at_item + LEN(ALLTRIM(m.item)) + 3))
    IF ATC("null", LEFT(texticek, 6)) = 0
        at_quote1 = AT('{', m.texticek, 1)
        IF at_quote1 > 0
            texticek = SUBSTR(m.texticek, m.at_quote1 + 1)
            text_obj = ""
            vnoreni = 1
            FOR ii = 1 TO LEN(m.texticek)
               pismenko = SUBSTR(m.texticek, m.ii, 1)
               DO CASE 
               CASE pismenko = "{"
                   vnoreni = m.vnoreni + 1
                   text_obj = m.text_obj + m.pismenko
               CASE pismenko = "}"
                   vnoreni = m.vnoreni - 1
                   IF m.vnoreni = 0
                       EXIT 
                   ENDIF 
                   text_obj = m.text_obj + m.pismenko
               OTHERWISE 
                   text_obj = m.text_obj + m.pismenko
               ENDCASE 
            ENDFOR 
            RETURN m.text_obj
        ENDIF 
    ENDIF 
ENDIF 
RETURN .null.

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
FUNCTION get_array_item (json, item, poradi)
IF EMPTY(m.poradi)
    poradi = 1
ENDIF 
LOCAL at_item, o_set_point, textcislo, texticek, ii, retval
at_item = ATC('"' + m.item + '":', m.json, m.poradi)
IF m.at_item > 0
    texticek = ALLTRIM(SUBSTR(m.json, m.at_item + LEN(ALLTRIM(m.item)) + 3))
    IF ATC("null", LEFT(texticek, 6)) = 0
        at_quote1 = AT('[', m.texticek, 1)
        IF at_quote1 > 0
            texticek = SUBSTR(m.texticek, m.at_quote1 + 1)
            text_obj = ""
            vnoreni = 1
            FOR ii = 1 TO LEN(m.texticek)
               pismenko = SUBSTR(m.texticek, m.ii, 1)
               DO CASE 
               CASE pismenko = "["
                   vnoreni = m.vnoreni + 1
                   text_obj = m.text_obj + m.pismenko
               CASE pismenko = "]"
                   vnoreni = m.vnoreni - 1
                   IF m.vnoreni = 0
                       EXIT 
                   ENDIF 
                   text_obj = m.text_obj + m.pismenko
               OTHERWISE 
                   text_obj = m.text_obj + m.pismenko
               ENDCASE 
            ENDFOR 
            RETURN m.text_obj
        ENDIF 
    ENDIF 
ENDIF 
RETURN .null.

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
FUNCTION beautify_json (odpoved)
return_string = ""
predposledni = "QWE"
delka_radku = 0
FOR ii = 1 TO LEN(m.odpoved)
   pismenko = SUBSTR(m.odpoved, ii, 1)
   IF (pismenko # CHR(10)) .and. (pismenko # CHR(13))
       IF (pismenko = "{")  .or.  (m.pismenko = '"' .and. predposledni = ',' .and. m.delka_radku > 133) .or. (m.delka_radku > 155)
          return_string = return_string + CHR(13)+CHR(10)
          delka_radku = 0
       ELSE
          delka_radku = delka_radku + 1
       ENDIF
       return_string = return_string + m.pismenko
       predposledni = m.pismenko
   ENDIF
ENDFOR 
RETURN m.return_string

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
*    pred carku a "}" se da tabulator, ktery se v dalsim parsovani uziva jako ukoncovac itemu
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
FUNCTION strip_whitespaces (json_txt)
LOCAL json, znak, ii
json = ""
uvnitr_stringu = .F.
FOR ii = 1 TO LEN(m.json_txt)
   znak = SUBSTR(m.json_txt, m.ii, 1)
   DO CASE 
   CASE m.znak = '"'
      uvnitr_stringu = .not. uvnitr_stringu
      json = m.json + m.znak

   CASE m.uvnitr_stringu
      IF m.znak = CHR(9)
         json = m.json + " "
      ELSE
         json = m.json + m.znak
      ENDIF 

   OTHERWISE     && vne stringu
      DO CASE 
      CASE m.znak = ','
        json = m.json + CHR(9) + m.znak
      CASE m.znak = '}'
        json = m.json + CHR(9) + m.znak
      CASE m.znak > ' '
        json = m.json + m.znak
      ENDCASE 
   ENDCASE 
ENDFOR 
RETURN m.json


*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
FUNCTION d_to_s
LPARAMETERS datum
pom_d = DTOS(m.datum)
RETURN LEFT(m.pom_d, 4) + "-" + SUBSTR(m.pom_d, 5,2) + "-" + SUBSTR(m.pom_d, 7,2)


*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
FUNCTION float2quoted_string (cislo, desetin)
IF EMPTY(m.desetin)
    desetin = 2
ENDIF 
RETURN  '"' + STRTRAN( ALLTRIM(STR(m.cislo, 12, m.desetin)), ",", "." ) + '"'


*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
FUNCTION str2uri (pcString)
LOCAL i, bajt, ret, retez, pismenko
ret = ""
retez = "0123456789ABCDEF"
pcString = ALLTRIM(m.pcString)

FOR i = 1 TO LEN(pcString)
    pismenko = SUBSTR(pcString,i,1)
    DO CASE
    CASE BETWEEN(m.pismenko, "0", "9")
        ret = m.ret + m.pismenko
    CASE BETWEEN(m.pismenko, "a", "z")
        ret = m.ret + m.pismenko
    CASE BETWEEN(m.pismenko, "A", "Z")
        ret = m.ret + m.pismenko
    OTHERWISE
        bajt = ASC(m.pismenko)
        ret = m.ret + "%" + ;
            SUBSTR(m.retez,INT(bajt/16)+1,1) + ;
            SUBSTR(m.retez,MOD(bajt,16)+1,1)
    ENDCASE
ENDFOR
RETURN ret


*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
PROCEDURE http_log
LPARAMETERS text_do_logu, poznamecka
RETURN 
#DEFINE NEJMENSI_HLASENA_DELKA 999

IF VARTYPE(http_logovat) # "U" .and. EMPTY(m.http_logovat)
     * n i c
ELSE 
     log_prefix = CRLF + REPLICATE("      *", 22) + CRLF + LEFT(TTOC(DATETIME(), 3), 16) + "  " + IIF(VARTYPE(poznamecka)="C", m.poznamecka, "")
     IF LEN(m.text_do_logu) > NEJMENSI_HLASENA_DELKA
         log_prefix = log_prefix + CRLF + CHR(9) + "response length: " + ALLTRIM(TRANS(LEN(m.text_do_logu), "9999 999"))
     ENDIF 
     IF ATC("evzen", m.machine) > 0
         STRTOFILE( log_prefix + CRLF + STRTRAN(m.text_do_logu, '{"id":', CRLF + '{"id":') + CRLF, m.http_jmeno_logu, 1 )
     ELSE
         STRTOFILE( log_prefix + CRLF + m.text_do_logu + CRLF, m.http_jmeno_logu, 1 )
     ENDIF 
ENDIF 


*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
PROCEDURE oznam_hotovo
? CRLF + CRLF + PADC("   HOTOVO   ", 99, "=") + CRLF
WAIT CLEAR 

*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    
PROCEDURE publikuj
LPARAMETERS jmeno_promenne, default_value
IF TYPE(jmeno_promenne) = "U" 
    PUBLIC (jmeno_promenne)
    &jmeno_promenne = m.default_value
ENDIF 

