* musi byt volano po vytvoreni cursoru selkasy:   SELECT DISTI id_kas, id_zkratka, lbl, stredskup FROM uzaverky INTO CURSOR selkasy READWRITE 
* nevyvolenym uzivatelum se v trzbovych sestavach ukazou jen kasy, na jejichz prirucni sklady maji prava
* pristupy se loguje do souboru TRZBOVKY_PRISTUP.TXT v hom_path
*
* 2018-04-04 vyvoleni se neloguji, is_admin ano
* 2019-10-07 hledani povolenych kas se dela jen podle poslednich 33 dni v aktualni sk_sez
*

#DEFINE VYVOLENI_UZIVATELE  "_MUZ_GOL_SPI_MAC_STE_KOZ_KRA_NEC_PRI___" 

DO CASE 
CASE ATC( "BAKARE", m.wi_zakaz) = 0
    * nic

CASE m.glis_admin
    loguj_uzivatele("IS_ADMIN")

CASE ATC(m.gcuser_id, VYVOLENI_UZIVATELE ) > 0
    * loguj_uzivatele("VYVOLENY")

OTHERWISE 

    WAIT "vidite jen sve kasy" WINDOW TIMEOUT 1
    WAIT "vidite jen sve kasy" WINDOW NOWAIT 

    SELECT id AS id_man ;
           WHERE INLIST(user_id, m.gcuser_id, "^&%") ;
           FROM (m.gchom_path + "ug___man") INTO CURSOR povolene_sklady READWRITE
    INDEX on id_man TAG id_man

    SELECT DISTINCT id_kas, id_man, .F. as povoleno WHERE uct_den > DATE()-99 ;
           FROM sk_sez INTO CURSOR man_kas READWRITE 
    SET RELATION TO id_man INTO povolene_sklady
    REPLACE ALL povoleno WITH .not. EMPTY(povolene_sklady.id_man)
    INDEX on id_kas TAG id_kas FOR povoleno UNIQUE 

    seznam_kas = ""
    SCAN 
        seznam_kas = seznam_kas + id_kas + " "
    ENDSCAN 
    loguj_uzivatele(m.seznam_kas)


    SELECT selkasy
    SET RELATION TO id_kas INTO man_kas

    REPLACE FOR EMPTY(man_kas.id_kas) id_zkratka WITH LOWER(LEFT(id_zkratka, 20)) + ": nepristupne", id_kas WITH ".."
    DELETE  FOR EMPTY(man_kas.id_kas)

    DO pozavirej WITH "povolene_sklady, man_kas"
    WAIT CLEAR 
ENDCASE 


*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    
FUNCTION loguj_uzivatele (texticek)
small_log( PADR(gcusername,18) + m.texticek, "trzbovky_pristup")
