*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *
*
* program cte CSV soubor klientu adientu a posle je na datastore do tabulek clients, client_infos a users
*
*
*    *    *    *    *    *    *    *    *    *    *    *      #> ver. 2019-01-24 <#       *    *    *    *    *    *    *    *    *    *    *    *    *

#DEFINE ODD          ";"
#DEFINE IMPORT_PATH  "i:\food600\"

mail_domain = "@psp.com"

o_set_point = SET("POINT")

*HTTP_READ_ONLY_MODE = .T.

DO (LOWER(JUSTPATH(sys(16))) + "\http_ppgm") WITH "https://alto:1991.Altopraha@btr.psp.cz/"
DO (LOWER(JUSTPATH(sys(16))) + "\ppgm_klienti") WITH "logovat"

ACTIVATE SCREEN 
_screen.Cls
IF importuj_csv() > 0
    DO stahni_webovy_klienty

    DO priprav_co_delat
    
    SELECT stravnici_karty_web

    DO posli_cloveky

ENDIF 

SET POINT TO (m.o_set_point)
oznam_hotovo()

*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *
PROCEDURE  importuj_csv

fh = FOPEN(IMPORT_PATH + "policajti.csv")
IF m.fh > 0 
    DO while ! feof(m.fh)

*!*    Os. císlo;Jméno;Príjmení;Císlo karty;Heslo
*!*    321126;Hana;Balogová;047866D25A4E80;WB682LVC
*!*    329817;Jan;Bártl;044777425D3F80;KTHQWRN2
*!*    313433;Petra;Bužgová;#N/A;M3PK2EQ7

        radek     = fgets(m.fh,333) + REPLICATE(ODD, 11) 
        client_id =       vrat_item()
        firstname =       vrat_item()
        surname   =       vrat_item()
        chip_id   = UPPER(vrat_item())
        heslo     =       vrat_item()
        
        IF "N/A" $ m.chip_id
            chip_id = m.client_id + "99"
        ENDIF 
        
        firma     = "Policie"
        ico       = "3"
        max_denne = 1
        limit     = -9993
        comment   = "IMPORTED (PSP)"

        IF VAL(m.client_id) # 0
            INSERT INTO stravnici_karty FROM MEMVAR 
        ENDIF 
        
    ENDDO 
    FCLOSE(m.fh)
ELSE
    WAIT "nelze otevrit soubor karet.csv" WINDOW TIMEOUT 3 AT 22,22
ENDIF 
RETURN m.fh


*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *
FUNCTION vrat_item
PRIVATE at1, retval
at1     = at(ODD, m.radek, 1)
retval  = LEFT(m.radek, m.at1-1)
radek   = SUBSTR(m.radek, m.at1+1)
RETURN ALLTRIM(STRTRAN(m.retval, '"', ''))
