IF m.issql
	rv("fooddat","food_dat")
	=CURSORSETPROP("Buffering",5,"food_dat")
ELSE
	USE (m.fn_food_dat) IN 0 ALIAS food_dat
ENDIF
SELECT id_menu,dat_path,pozadi,pgm_param,COMMENT, stredskup WHERE pgm LIKE "%UCTO%" FROM food_dat INTO CURSOR ucto
IF ! prazdna()
	IF !m.issql
		IF FILE(m.gchom_path+"s_ucto.dbf")
			IF ".FXP"$UPPER(SYS(16,0))
				DO set_scat WITH (m.gcini_path+"progs_sk\ucto_set.dbf"),(m.gchom_path+"s_ucto.dbf")
			ELSE
				DO set_scat WITH (m.gcini_path+"progs\ucto_set.dbf"),(m.gchom_path+"s_ucto.dbf")
			ENDIF 
		ENDIF
	ELSE
		IF ".FXP"$UPPER(SYS(16,0))
			DO sql_set_scat WITH (m.gcini_path+"progs_sk\ucto_set.dbf"),UPPER("ucto"),""
		ELSE
			DO sql_set_scat WITH (m.gcini_path+"progs\ucto_set.dbf"),UPPER("ucto"),""
		ENDIF 
	ENDIF
	SELECT ucto
	GO TOP
	m.gcucto_path = ALLTRIM(dat_path)
	IF !EMPTY(ucto.pozadi) OR !EMPTY(ucto.id_menu) OR !EMPTY(ucto.pgm_param) OR !EMPTY(ucto.COMMENT)
		PRIVATE pomocna,pomii
		m.gcuexp_path = ALLTRIM(ucto.pozadi)
		backslash( @m.gcuexp_path )
		m.gcuct_typ = ALLTRIM(ucto.pgm_param)
		DO CASE
			CASE LOWER(m.gcuct_typ)=="sapnbs"
				m.gcuct_typ="SAP"
				m.gcuct_spec="NBS"
			CASE LOWER(m.gcuct_typ)=="kros_kosice"
				m.gcuct_typ="KROS"
				m.gcuct_spec="KOSICE"
			OTHERWISE
				m.gcuct_typ=UPPER(m.gcuct_typ)
				m.gcuct_spec=""
		ENDCASE
		m.gcuct_city=UPPER(ALLTRIM(ucto.id_menu))
		m.gcuct_evidencia1=UPPER(ALLTRIM(ucto.stredskup))
		m.pomocna=LOWER(ALLTRIM(ucto.COMMENT))
		IF !EMPTY(m.pomocna)
			IF "pole="$m.pomocna
				FOR m.pomii=AT("pole=",m.pomocna) TO LEN(m.pomocna)
					IF INLIST(SUBSTR(m.pomocna,m.pomii,1),";"," ")
						EXIT
					ELSE
						m.gcuct_pole=m.gcuct_pole+SUBSTR(m.pomocna,m.pomii,1)
					ENDIF
				ENDFOR
			ELSE
				m.gcuct_pole="SPART"
			ENDIF
			m.gcuct_pole=UPPER(STRTRAN(m.gcuct_pole,"pole=",""))
			IF "trzba="$m.pomocna
				m.gcuct_trzba=""
				FOR m.pomii=AT("trzba=",m.pomocna) TO LEN(m.pomocna)
					IF INLIST(SUBSTR(m.pomocna,m.pomii,1),";"," ")
						EXIT
					ELSE
						m.gcuct_trzba=m.gcuct_trzba+SUBSTR(m.pomocna,m.pomii,1)
					ENDIF
				ENDFOR
			ELSE
				m.gcuct_trzba="n"
			ENDIF
			IF "hores="$m.pomocna
				m.gcuct_hores=""
				FOR m.pomii=AT("hores=",m.pomocna) TO LEN(m.pomocna)
					IF INLIST(SUBSTR(m.pomocna,m.pomii,1),";"," ")
						EXIT
					ELSE
						m.gcuct_hores=m.gcuct_hores+SUBSTR(m.pomocna,m.pomii,1)
					ENDIF
				ENDFOR
			ELSE
				m.gcuct_hores="n"
			ENDIF
			m.gcuct_hores=STRTRAN(m.gcuct_hores,"hores=","")
			m.gcuct_hores=LOWER(m.gcuct_hores)
			m.gcuct_trzba=STRTRAN(m.gcuct_trzba,"trzba=","")
			m.gcuct_trzba=LOWER(m.gcuct_trzba)
			DO CASE
				CASE LOWER(m.gcuct_typ)="magma"
					m.gcuct_trzba=.T.
					m.gcuct_hores=.T.
				CASE LOWER(m.gcuct_typ)="ekoadam"
					m.gcuct_trzba=.F.
					m.gcuct_hores=.F.
				OTHERWISE
					IF INLIST(m.gcuct_trzba,"a","1","t","y")
						m.gcuct_trzba=.T.
					ELSE
						m.gcuct_trzba=.F.
					ENDIF
					IF INLIST(m.gcuct_hores,"a","1","t","y")
						m.gcuct_hores=.T.
					ELSE
						m.gcuct_hores=.F.
					ENDIF
			ENDCASE
			IF "per="$m.pomocna
				FOR m.pomii=AT("per=",m.pomocna) TO LEN(m.pomocna)
					IF INLIST(SUBSTR(m.pomocna,m.pomii,1),";"," ")
						EXIT
					ELSE
						m.gcuct_perioda=m.gcuct_perioda+SUBSTR(m.pomocna,m.pomii,1)
					ENDIF
				ENDFOR
				m.gcuct_perioda=UPPER(STRTRAN(m.gcuct_perioda,"per=",""))
				IF EMPTY(m.gcuct_perioda) .OR. !INLIST(m.gcuct_perioda,"M","O","D")
					m.gcuct_perioda="M"
				ENDIF
			ELSE
				m.gcuct_perioda="M"
			ENDIF
			IF "rastre="$m.pomocna
				m.gcuct_rastre=""
				FOR m.pomii=AT("rastre=",m.pomocna) TO LEN(m.pomocna)
					IF INLIST(SUBSTR(m.pomocna,m.pomii,1),";"," ")
						EXIT
					ELSE
						m.gcuct_rastre=m.gcuct_rastre+SUBSTR(m.pomocna,m.pomii,1)
					ENDIF
				ENDFOR
				m.gcuct_rastre=STRTRAN(m.gcuct_rastre,"rastre=","")
				IF INLIST(m.gcuct_rastre,"a","1","t","y")
					m.gcuct_rastre=.T.
				ELSE
					m.gcuct_rastre=.F.
				ENDIF
			ELSE
				m.gcuct_rastre=.F.
			ENDIF
		ELSE
			m.gcuct_rastre=.F.
			m.gcuct_perioda="M"
			m.gcuct_hores=.F.
			m.gcuct_trzba=.F.
			m.gcuct_pole="SPART"
		ENDIF
		RELEASE m.pomocna,m.pomii
		IF m.issql
			PRIVATE m.hladajmodul, m.hladajvarname, m.hladajsetupskup
			m.hladajmodul="UCTO"
			m.hladajsetupskup=""
			m.hladajvarname="gcuexp_path"
			SELECT 0
			USE (m.sqlprefix+"rdefsuborvarname") IN 0 ALIAS s_ucto
			=CURSORSETPROP("Buffering",5,"s_ucto")
			IF RECCOUNT()=1
				UPDATE s_ucto SET var_value='"'+ALLTRIM(m.gcuexp_path)+'"' WHERE var_name="gcuexp_path"
			ELSE
				INSERT INTO s_ucto (var_name, var_value, MODUL, setup_skup) VALUES ("gcuexp_path",'"'+ALLTRIM(m.gcuexp_path)+'"',"UCTO","")
			ENDIF
			=tux(.T.,.T.,"s_ucto")
			m.hladajvarname="gcuct_typ"
			=REQUERY("s_ucto")
			IF RECCOUNT()=1
				UPDATE s_ucto SET var_value='"'+ALLTRIM(m.gcuct_typ)+'"' WHERE var_name="gcuct_typ"
			ELSE
				INSERT INTO s_ucto (var_name, var_value, MODUL, setup_skup) VALUES ("gcuct_typ",'"'+ALLTRIM(m.gcuct_typ)+'"',"UCTO","")
			ENDIF
			=tux(.T.,.T.,"s_ucto")
			m.hladajvarname="gcuct_spec"
			=REQUERY("s_ucto")
			IF RECCOUNT()=1
				UPDATE s_ucto SET var_value='"'+ALLTRIM(m.gcuct_spec)+'"' WHERE var_name="gcuct_spec"
			ELSE
				INSERT INTO s_ucto (var_name, var_value, MODUL, setup_skup) VALUES ("gcuct_spec",'"'+ALLTRIM(m.gcuct_spec)+'"',"UCTO","")
			ENDIF
			=tux(.T.,.T.,"s_ucto")
			m.hladajvarname="gcuct_city"
			=REQUERY("s_ucto")
			IF RECCOUNT()=1
				UPDATE s_ucto SET var_value='"'+ALLTRIM(m.gcuct_city)+'"' WHERE var_name="gcuct_city"
			ELSE
				INSERT INTO s_ucto (var_name, var_value, MODUL, setup_skup) VALUES ("gcuct_city",'"'+ALLTRIM(m.gcuct_city)+'"',"UCTO","")
			ENDIF
			=tux(.T.,.T.,"s_ucto")
			m.hladajvarname="gcuct_pole"
			=REQUERY("s_ucto")
			IF RECCOUNT()=1
				UPDATE s_ucto SET var_value='"'+ALLTRIM(m.gcuct_pole)+'"' WHERE var_name="gcuct_pole"
			ELSE
				INSERT INTO s_ucto (var_name, var_value, MODUL, setup_skup) VALUES ("gcuct_pole",'"'+ALLTRIM(m.gcuct_pole)+'"',"UCTO","")
			ENDIF
			=tux(.T.,.T.,"s_ucto")
			m.hladajvarname="gcuct_perioda"
			=REQUERY("s_ucto")
			IF RECCOUNT()=1
				UPDATE s_ucto SET var_value='"'+ALLTRIM(m.gcuct_perioda)+'"' WHERE var_name="gcuct_perioda"
			ELSE
				INSERT INTO s_ucto (var_name, var_value, MODUL, setup_skup) VALUES ("gcuct_perioda",'"'+ALLTRIM(m.gcuct_perioda)+'"',"UCTO","")
			ENDIF
			=tux(.T.,.T.,"s_ucto")
			m.hladajvarname="gcuct_trzba"
			=REQUERY("s_ucto")
			IF RECCOUNT()=1
				UPDATE s_ucto SET var_value=IIF(m.gcuct_trzba,".T.",".F.") WHERE var_name="gcuct_trzba"
			ELSE
				INSERT INTO s_ucto (var_name, var_value, MODUL, setup_skup) VALUES ("gcuct_trzba",IIF(m.gcuct_trzba,".T.",".F."),"UCTO","")
			ENDIF
			=tux(.T.,.T.,"s_ucto")
			m.hladajvarname="gcuct_hores"
			=REQUERY("s_ucto")
			IF RECCOUNT()=1
				UPDATE s_ucto SET var_value=IIF(m.gcuct_hores,".T.",".F.") WHERE var_name="gcuct_hores"
			ELSE
				INSERT INTO s_ucto (var_name, var_value, MODUL, setup_skup) VALUES ("gcuct_hores",IIF(m.gcuct_hores,".T.",".F."),"UCTO","")
			ENDIF
			=tux(.T.,.T.,"s_ucto")
			m.hladajvarname="gcuct_rastre"
			=REQUERY("s_ucto")
			IF RECCOUNT()=1
				UPDATE s_ucto SET var_value=IIF(m.gcuct_rastre,".T.",".F.") WHERE var_name="gcuct_rastre"
			ELSE
				INSERT INTO s_ucto (var_name, var_value, MODUL, setup_skup) VALUES ("gcuct_rastre",IIF(m.gcuct_rastre,".T.",".F."),"UCTO","")
			ENDIF
			=tux(.T.,.T.,"s_ucto")
			IF !EMPTY(m.gcuct_evidencia1)
				m.hladajvarname="gcuct_evidencia1"
				=REQUERY("s_ucto")
				IF RECCOUNT()=1
					UPDATE s_ucto SET var_value='"'+ALLTRIM(m.gcuct_evidencia1)+'"' WHERE var_name="gcuct_evidencia1"
				ELSE
					INSERT INTO s_ucto (var_name, var_value, MODUL, setup_skup) VALUES ("gcuct_evidencia1",'"'+ALLTRIM(gcuct_evidencia1)+'"',"UCTO","")
				ENDIF
				=tux(.T.,.T.,"s_ucto")
				m.hladajvarname="gcuct_evidencia2"
				=REQUERY("s_ucto")
				IF RECCOUNT()=1
					UPDATE s_ucto SET var_value='"'+ALLTRIM(m.gcuct_evidencia1)+'"' WHERE var_name="gcuct_evidencia2"
				ELSE
					INSERT INTO s_ucto (var_name, var_value, MODUL, setup_skup) VALUES ("gcuct_evidencia2",'"'+ALLTRIM(gcuct_evidencia1)+'"',"UCTO","")
				ENDIF
				=tux(.T.,.T.,"s_ucto")
				m.hladajvarname="gcuct_cisrad1"
				=REQUERY("s_ucto")
				IF RECCOUNT()=1
					UPDATE s_ucto SET var_value='"'+ALLTRIM(m.gcuct_evidencia1)+'"' WHERE var_name="gcuct_cisrad1"
				ELSE
					INSERT INTO s_ucto (var_name, var_value, MODUL, setup_skup) VALUES ("gcuct_cisrad1",'"'+ALLTRIM(gcuct_evidencia1)+'"',"UCTO","")
				ENDIF
				=tux(.T.,.T.,"s_ucto")
				m.hladajvarname="gcuct_cisrad2"
				=REQUERY("s_ucto")
				IF RECCOUNT()=1
					UPDATE s_ucto SET var_value='"'+ALLTRIM(m.gcuct_evidencia1)+'"' WHERE var_name="gcuct_cisrad2"
				ELSE
					INSERT INTO s_ucto (var_name, var_value, MODUL, setup_skup) VALUES ("gcuct_cisrad2",'"'+ALLTRIM(gcuct_evidencia1)+'"',"UCTO","")
				ENDIF
				=tux(.T.,.T.,"s_ucto")
			ENDIF
			USE IN s_ucto
			DO sql_set_scat WITH (m.gcini_path+"progs_sk\ucto_set.dbf"),"UCTO",""
		ELSE
			IF FILE(m.gchom_path+"s_ucto.dbf")
				USE (m.gchom_path+"s_ucto.dbf") IN 0
				UPDATE s_ucto SET var_value='"'+ALLTRIM(m.gcuexp_path)+'"' WHERE var_name="gcuexp_path"
				UPDATE s_ucto SET var_value='"'+ALLTRIM(m.gcuct_typ)+'"' WHERE var_name="gcuct_typ"
				UPDATE s_ucto SET var_value='"'+ALLTRIM(m.gcuct_spec)+'"' WHERE var_name="gcuct_spec"
				UPDATE s_ucto SET var_value='"'+ALLTRIM(m.gcuct_city)+'"' WHERE var_name="gcuct_city"
				UPDATE s_ucto SET var_value='"'+ALLTRIM(m.gcuct_pole)+'"' WHERE var_name="gcuct_pole"
				UPDATE s_ucto SET var_value=IIF(m.gcuct_trzba,".T.",".F.") WHERE var_name="gcuct_trzba"
				UPDATE s_ucto SET var_value=IIF(m.gcuct_hores,".T.",".F.") WHERE var_name="gcuct_hores"
				UPDATE s_ucto SET var_value='"'+ALLTRIM(m.gcuct_perioda)+'"' WHERE var_name="gcuct_perioda"
				UPDATE s_ucto SET var_value=IIF(m.gcuct_rastre,".T.",".F.") WHERE var_name="gcuct_rastre"
				IF !EMPTY(m.gcuct_evidencia1)
					UPDATE s_ucto SET var_value='"'+ALLTRIM(m.gcuct_evidencia1)+'"' WHERE var_name="gcuct_evidencia1"
					UPDATE s_ucto SET var_value='"'+ALLTRIM(m.gcuct_evidencia1)+'"' WHERE var_name="gcuct_evidencia2"
					UPDATE s_ucto SET var_value='"'+ALLTRIM(m.gcuct_evidencia1)+'"' WHERE var_name="gcuct_cisrad1"
					UPDATE s_ucto SET var_value='"'+ALLTRIM(m.gcuct_evidencia1)+'"' WHERE var_name="gcuct_cisrad2"
				ENDIF
				USE IN s_ucto
				DO set_scat WITH (m.gcini_path+"progs_sk\ucto_set.dbf"),(m.gchom_path+"s_ucto.dbf")
			ENDIF
		ENDIF
		IF !USED("food_dat")
			IF m.issql
				rv("fooddat","food_dat")
				=CURSORSETPROP("Buffering",5,"food_dat")
			ELSE
				USE (m.fn_food_dat) IN 0 ALIAS food_dat
			ENDIF
		ENDIF
		SELECT food_dat
		LOCATE FOR ALLTRIM(pgm)=="UCTO"
		IF FOUND()
			REPLACE id_menu WITH "", pgm_param WITH "", COMMENT WITH "", stredskup WITH "", pozadi WITH ""
			IF m.issql
				=tux(.T.,.T.,"food_dat")
			ENDIF
		ENDIF
		USE IN food_dat
	ELSE
		IF m.issql
			IF ".FXP"$UPPER(SYS(16,0))
				DO sql_set_scat WITH (m.gcini_path+"progs_sk\ucto_set.dbf"),UPPER("ucto"),""
			ELSE
				DO sql_set_scat WITH (m.gcini_path+"progs\ucto_set.dbf"),UPPER("ucto"),""
			ENDIF 
		ELSE
			DO set_scat WITH (m.gcini_path+"progs_sk\ucto_set.dbf"),(m.gchom_path+"s_ucto.dbf")
		ENDIF
	ENDIF
	IF !m.issql
		IF !EMPTY(m.gcucto_path) AND !DIRECTORY(m.gcucto_path)
			MKDIR(m.gcucto_path)
		ENDIF
		IF m.slovenskaverzia
			DO ini_files IN uctoexp
		ELSE
			DO ini_files IN ucto_exp
		ENDIF
		USE (m.fn_food_dat) IN 0 ALIAS food_dat
	ENDIF
ENDIF
IF VARTYPE(m.gcuct_typ)=="C" AND LOWER(m.gcuct_typ)=="navision"
	LOCAL bazconnectstring, m.bazconnection, m.ret
	DO open_database
	m.bazconnectstring="DRIVER=SQL Server;APP=Microsoft Visual FoxPro;Trusted_Connection=no;DATABASE="+ALLTRIM(m.navision_databaza)+";SERVER="+ALLTRIM(m.navision_server)+IIF(!EMPTY(m.navision_port),";PORT="+ALLTRIM(m.navision_port),"")+";UID="+ALLTRIM(m.navision_user)+";PWD="+m.navision_heslo
	IF m.bazconnectstring<>DBGETPROP("Navision","CONNECTION","Connectstring")
		DBSETPROP("Navision","CONNECTION","ConnectString",m.bazconnectstring)
	ENDIF 
	m.bazconnection=SQLCONNECT("Navision",.t.)
	IF m.bazconnection>0
		=SQLDISCONNECT(m.bazconnection)
		m.ret=.t.
	ELSE
		=MESSAGEBOX(jaz("form_nedostupny_navision_servr"),48,"FoodMan")
	ENDIF 
ENDIF 
