*;*******************************************************************************************
*;
*; Vrati soubor s typy jidel (snidane, obed, vecere) a casy zacatku
*;
*;*******************************************************************************************
PARAMETERS p_soubor
PRIVATE vysledek, dotazString, qq, json, klicKlienta, m_jsonOK, myHkUrl
  myHkUrl = m.hk_url
	  IF USED("myCourses")
	    USE IN myCourses
	  ENDIF 
	  SELECT 0
	  * Pro novy datastore maji smysl jen prvni 2 sloupce
	  IF !EMPTY(m.p_soubor)
	    CREATE TABLE (m.p_soubor);
	     (c_name C(16), c_group C(16), order_no N(5,0), is_add L)
	    USE (m.p_soubor) ALIAS myCourses EXCLUSIVE 
	  ELSE
	    CREATE CURSOR myCourses;
	     (c_name C(16), c_group C(16), order_no N(5,0), is_add L)
	  ENDIF 
	    
	  IF VARTYPE(m.http_logovat) # "U" AND VARTYPE(m.http_auth_token) # "U"
      		m.dotazstring = "canteen/crud/courses"
			json = http_get(m.dotazstring)		
      ELSE
		  json = "Not in new datastore"
      ENDIF       
	  IF myjsonok(m.json)
		IF VARTYPE(m.http_logovat) # "U" AND VARTYPE(m.http_auth_token) # "U"
	    	DO parsuj_json_qdf WITH m.json
	    ELSE
	    	DO parsuj_json WITH m.json
	    ENDIF 
	  ELSE 
	    * Web nedostupny nebo jina chyba
	    DO CASE
	    CASE EMPTY(m.json)
	      m.vysledek = "9999 NO WEB CONNECTION"
	    CASE "99 NOT FOUND" $ m.json
	      * SOV nenalezena
	      m.vysledek = m.json
	    OTHERWISE 
	      m.vysledek = m.json
	    ENDCASE 
	  ENDIF 
	  IF VARTYPE(m.vysledek) # 'C'
		  m.vysledek = 0
	  ENDIF    
RETURN m.vysledek

**  **  **  **  **  **  **  **  **  **  **  **  **  **  **  **  **  **  
PROCEDURE parsuj_json (json)


PROCEDURE parsuj_json_qdf (json)
PRIVATE zavrit, id_kas, id_zkratka, kk
m.zavrit = .F.
IF VARTYPE(loJSON) # 'O'
	m.lcProcLibWas = SET("procedure")
	IF !("QDFOXJSON" $ UPPER(m.lcProcLibWas))
	  SET PROCEDURE TO "QDFOXJSON" ADDITIVE 
	ENDIF 
    m.loJSON = CREATEOBJECT("jsonHelper")
	loVysledek=lojson.parse(m.json)
	m.zavrit = .T.
ELSE
	loVysledek=lojson.parse(m.json)
ENDIF 

FOR m.kk = 1 TO loVysledek.Count
	m.c_name    = loVysledek.Results.Courses[m.kk].name
	m.c_group   = loVysledek.Results.Courses[m.kk].group
	m.order_no  = loVysledek.Results.Courses[m.kk].order_number
	m.is_add    = loVysledek.Results.Courses[m.kk].is_additional
	IF !EMPTY(m.c_name)
	  INSERT INTO myCourses FROM MEMVAR
	ENDIF 
ENDFOR
IF TYPE("loJSON") == 'O' AND m.zavrit
  RELEASE loJSON
ENDIF     
RETURN
