*!*****************************************************************************
*!      Procedure: JAZYKINI
*!*****************************************************************************
PROCEDURE jazykini
PARAMETERS nepridajtexty
PRIVATE old_sel, fn_pom, m.hladajmodul, s_pgm

hladajmodul = m.gcpgm
s_pgm       = m.gcpgm
fn_pom = m.gcpri_path + "pom"
DO pozavirej WITH "fn_hesla"
fn_hesla  = m.gcpri_path + "j_" + m.gcuser_id + "_" + m.gcpgm_id

IF EMPTY(m.gcuser_id)    && volano jeste pred prihlasenim uzivatele, jen aby se hlasky zobrazovaly spravne cesky nebo slovensky
    DO use_sele WITH gcpgm_path + "jazyky", "jazyky"
    SELECT klic, is_menu, j0 AS j, j0, j1 FROM (gcpgm_path + 'jazyky') INTO TABLE (m.fn_hesla)
    USE IN jazyky
    USE (m.fn_hesla) ALIAS fn_hesla EXCLUSIVE
    INDEX on klic TAG klic
    domaci_jazyk_do_j0()
    REPLACE ALL j WITH j0
    REPLACE FOR EMPTY(j) j WITH klic
	SELECT fn_hesla
	IF !m.nepridajtexty
		IF m.issql
			DO open_database
			TRY 
				=rv("texty","texty")
			CATCH
				=rv("textymin","textymin")
			ENDTRY 		
			IF USED("texty")
				SELECT texty
				SCAN FOR modul = "FOOD"
					klic = LOWER(texty.kluc)
					j    = texty.hodnota
					IF !EMPTY(m.j) AND !ISNULL(m.j)
						INSERT INTO fn_hesla FROM MEMVAR 
					ENDIF 
				ENDSCAN 
				USE IN texty
			ENDIF 
			IF USED("textymin")
				SELECT textymin
				SCAN ALL
					klic = LOWER(textymin.kluc)
					j    = textymin.hodnota
					IF !EMPTY(m.j) AND !ISNULL(m.j)
						INSERT INTO fn_hesla FROM MEMVAR 
					ENDIF 
				ENDSCAN 
				USE IN textymin
			ENDIF 
		ELSE 
			fh = FOPEN(m.gchom_path + "texty.txt",0)
			IF m.fh > 0
				DO WHILE ! FEOF(m.fh)
					STR = ALLTRIM(FGETS(fh))
					IF ! EMPTY(m.str)
						pozice = AT("=", m.str)
						IF pozice > 0
							klic = lower(PADR(LEFT(m.str, m.pozice-1), 30))
							j    = ALLTRIM(SUBSTR(m.str, m.pozice+1))
	                        DO CASE 
	                        CASE m.j = ",,"
	                            * nic
							CASE ! EMPTY(m.j)
	                            LOCATE FOR klic = m.klic
	                            IF .not. FOUND()
								    INSERT INTO fn_hesla FROM MEMVAR
	                            ENDIF 
							ENDCASE
						ENDIF
					ENDIF
				ENDDO
				= FCLOSE(m.fh)
			ENDIF
			IF ! FILE(m.gchom_path + "texty.txt")
				fh = FCREATE(m.gchom_path + "texty.txt")
				= FCLOSE(m.fh)
			ENDIF
		ENDIF 
	ENDIF 
	DO pozavirej WITH "ug, gr_pgm"
    USE 
    RETURN 
ENDIF 

IF m.issql
    DO open_database
	SELECT 0
	USE (m.sqlprefix+"rug") ALIAS ug
ELSE 
	DO use_sele WITH m.gchom_path + "ug___" + m.gcpgm, "ug"
ENDIF 
LOCATE FOR user_id = m.gcuser_id .AND. ID = m.gcpgm_id
IF FOUND()
	SCATTER FIELD g0,g1,g2,g3,g4,g5,g6,g7,g8,g9 MEMVAR
ELSE
	STORE .F. TO g0,g1,g2,g3,g4,g5,g6,g7,g8,g9
ENDIF
LOCATE FOR user_id = m.gcuser_id .AND. ID = m.gcprava_skup
IF FOUND()
	g0 = m.g0 .OR. g0
	g1 = m.g1 .OR. g1
	g2 = m.g2 .OR. g2
	g3 = m.g3 .OR. g3
	g4 = m.g4 .OR. g4
	g5 = m.g5 .OR. g5
	g6 = m.g6 .OR. g6
	g7 = m.g7 .OR. g7
	g8 = m.g8 .OR. g8
	g9 = m.g9 .OR. g9
ENDIF

IF FILE(m.fn_hesla + ".dbf")
	USE (m.fn_hesla) ALIAS fn_hesla ORDER klic 
ELSE
	DO use_sele WITH gcpgm_path + "jazyky", "jazyky"
    domaci_jazyk_do_j0()

	SELECT 0
	CREATE TABLE (m.fn_hesla) FREE (klic c(30), j c(76), is_menu L) 
	
	INDEX on klic TAG klic
	USE (m.fn_hesla) ALIAS fn_hesla ORDER klic 
	cmd = "INSERT INTO fn_hesla (klic, is_menu, j) SELECT klic, is_menu, j" + m.gcjazyk + " AS j FROM (gcpgm_path + 'jazyky')"
	&cmd
	SELECT fn_hesla
	REPLACE FOR EMPTY(j) j WITH klic

	IF m.gcuser_id = "___" .OR. m.glis_admin
		IF gcuser_id = "___"
			REPLACE FOR is_menu j WITH "\" + IIF(LEFT(j,2)="\<", SUBSTR(j,3), j)
		ENDIF
	ELSE
		IF m.issql
			SELECT 0
			USE (m.sqlprefix+"rgr") ALIAS gr_pgm
		ELSE 
			DO use_sele WITH gchom_path + "gr___" + LEFT(m.gcpgm, 3), "gr_pgm"
		ENDIF 
		COPY ALL TO (m.fn_pom)
		USE (m.fn_pom) ALIAS fn_pom EXCL
		DELETE FOR (g0 .AND. m.g0) .OR. (g1 .AND. m.g1) .OR. (g2 .AND. m.g2) .OR. (g3 .AND. m.g3) .OR. (g4 .AND. m.g4) ;
              .OR. (g5 .AND. m.g5) .OR. (g6 .AND. m.g6) .OR. (g7 .AND. m.g7) .OR. (g8 .AND. m.g8) .OR. (g9 .AND. m.g9)
		PACK
		SET RELATION TO klic INTO fn_hesla
		REPLACE ALL fn_hesla.j WITH "\" + IIF(LEFT(fn_hesla.j,2)="\<", SUBSTR(fn_hesla.j,3), fn_hesla.j)
	ENDIF

	SELECT fn_hesla
	IF m.issql
		TRY 
			=rv("texty","texty")
		CATCH
			=rv("textymin","textymin")
		ENDTRY 		
		IF USED("texty")
			SELECT texty
			SCAN FOR modul = "FOOD"
				klic = LOWER(texty.kluc)
				j    = texty.hodnota
				IF !EMPTY(m.j) AND !ISNULL(m.j)
					INSERT INTO fn_hesla FROM MEMVAR 
				ENDIF 
			ENDSCAN 
			USE IN texty
		ENDIF 
		IF USED("textymin")
			SELECT textymin
			SCAN ALL
				klic = LOWER(textymin.kluc)
				j    = textymin.hodnota
				IF !EMPTY(m.j) AND !ISNULL(m.j)
					INSERT INTO fn_hesla FROM MEMVAR 
				ENDIF 
			ENDSCAN 
			USE IN textymin
		ENDIF 
	ELSE 
		fh = FOPEN(m.gchom_path + "texty.txt",0)
		IF m.fh > 0
			DO WHILE ! FEOF(m.fh)
				STR = ALLTRIM(FGETS(fh))
				IF ! EMPTY(m.str)
					pozice = AT("=", m.str)
					IF pozice > 0
						klic = lower(PADR(LEFT(m.str, m.pozice-1), 30))
						j    = ALLTRIM(SUBSTR(m.str, m.pozice+1))
                        DO CASE 
                        CASE m.j = ",,"
                            * nic
						CASE ! EMPTY(m.j)
                            LOCATE FOR klic = m.klic
                            IF .not. FOUND()
							    INSERT INTO fn_hesla FROM MEMVAR
                            ENDIF 
						ENDCASE
					ENDIF
				ENDIF
			ENDDO
			= FCLOSE(m.fh)
		ENDIF
		IF ! FILE(m.gchom_path + "texty.txt")
			fh = FCREATE(m.gchom_path + "texty.txt")
			= FCLOSE(m.fh)
		ENDIF
	ENDIF 
	DO pozavirej WITH "ug, gr_pgm"
ENDIF


*!*****************************************************************************
PROCEDURE domaci_jazyk_do_j0
IF m.slovenskaverzia
    test_jazyk = "SLOV"
ELSE
    test_jazyk = "CES"
ENDIF
LOCATE FOR klic = "jazyk"
IF ! m.test_jazyk $ j0
    SCAN
        pom = j0
        REPLACE j0 WITH j1, j1 WITH m.pom
    ENDSCAN
ENDIF
