*:*********************************************************************************************************
*:     Procedure file: USERS_IN.PRG
*:             prijima uzivatele, existujici updatuje, ale zachovava jim field HASH, protoze v nem je heslo, nastavovane na kase
*:             typicke volani:
*:                  GET                              <TEMP>\users.*
*:                  EXEC DO users_in with "<DATA>", "<TEMP>"
*:    
*: 2017-03-23: 
*:
*:*********************************************************************************************************
param sk_path, imp_path

imp_path = imp_path + IIF(RIGHT(m.imp_path,1)="\", "", "\")
sk_path  = sk_path  + IIF(RIGHT(m.sk_path,1) ="\", "", "\")
vysledek = " . . v.2017-0323: "

CLOSE DATABASES 
sk_otevreno = ""

LOCAL skin_oErr AS Exception
TRY 
    USE (m.imp_path + "USERS") excl ALIAS users_imp
    USE (m.sk_path + "USERS ") in 0 excl
CATCH TO skin_oErr 
    sk_otevreno = ALLTRIM(STR(skin_oErr.ErrorNo)) + ":" + skin_oErr.Message
ENDTRY 

IF EMPTY(m.sk_otevreno)    
    SELECT users_imp
    SCAN 
        SCATTER MEMVAR 
        SELECT users
        LOCATE FOR user_id = m.user_id NOOPTIMIZE 
        IF FOUND()
           SELECT users
           GATHER MEMVAR FIELDS heslo, username, jazyk, hashfood, hashoman, is_admin, mzda, sef, cen_hl
        ELSE
            INSERT INTO (m.sk_path + "USERS") FROM MEMVAR 
        ENDIF 
    ENDSCAN 
    vysledek = m.vysledek + "  ... OK "
ELSE
    vysledek = m.vysledek + m.crlf + "[2#R]  " + "  ... " + m.sk_otevreno + "  "
ENDIF
CLOSE DATABASES 
