--freemarker template

<#assign makros = [
{"tid":"44070"},
{"tid":"44190"},
{"tid":"44660"},
{"tid":"44690"}
] />


<#assign masken = [
{"makro":"44070", "tid":"44020", "sortnr":"1"},
{"makro":"44070", "tid":"44020", "sortnr":"10"},
{"makro":"44070", "tid":"44020", "sortnr":"20"},

{"makro":"44070", "tid":"44020", "sortnr":"30"},
{"makro":"44070", "tid":"44020", "sortnr":"40"},
{"makro":"44070", "tid":"44020", "sortnr":"50"},

{"makro":"44070", "tid":"44020", "sortnr":"60"},
{"makro":"44070", "tid":"44020", "sortnr":"70"},
{"makro":"44070", "tid":"44020", "sortnr":"80"},

{"makro":"44190", "tid":"44630", "sortnr":"0"},
{"makro":"44190", "tid":"44570", "sortnr":"1"},
{"makro":"44190", "tid":"44220", "sortnr":"10"},
{"makro":"44190", "tid":"44280", "sortnr":"20"},
{"makro":"44190", "tid":"44310", "sortnr":"30"},
{"makro":"44190", "tid":"44310", "sortnr":"40"},
{"makro":"44190", "tid":"44340", "sortnr":"50"},
{"makro":"44190", "tid":"44600", "sortnr":"60"},

{"makro":"44660", "tid":"44630", "sortnr":"0"},
{"makro":"44660", "tid":"44570", "sortnr":"10"},
{"makro":"44660", "tid":"44570", "sortnr":"20"},
{"makro":"44660", "tid":"44570", "sortnr":"30"},

{"makro":"44690", "tid":"44630", "sortnr":"0"},
{"makro":"44690", "tid":"44570", "sortnr":"10"},
{"makro":"44690", "tid":"44570", "sortnr":"20"},
{"makro":"44690", "tid":"44570", "sortnr":"30"},
{"makro":"44690", "tid":"44720", "sortnr":"40"},
{"makro":"44690", "tid":"44720", "sortnr":"50"},
{"makro":"44690", "tid":"44720", "sortnr":"60"}



] />

<#assign felder = [
{"makro":"44070", "sortnr":"1", "feldname":"Köpfe oder Fälle ?", "value":"studiengang_nr = 1 and fach_nr = 1"},
{"makro":"44070", "sortnr":"1", "feldname":"Felder", "value":"sos_stg_aggr.geschlecht|sos_stg_aggr.sem_rueck_beur_ein|sos_stg_aggr.summe"},
{"makro":"44070", "sortnr":"1", "feldname":"Grafik", "value":"STUD_ENTW_SEM_GESCHL_LINE"},
{"makro":"44070", "sortnr":"1", "feldname":"Weitere Tabellen", "value":"dim_studiengang"},
{"makro":"44070", "sortnr":"1", "feldname":"tablestylesheet", "value":"tabelle_html_datenblatt.xsl"},

{"makro":"44070", "sortnr":"10", "feldname":"Köpfe oder Fälle ?", "value":"studiengang_nr = 1 and fach_nr = 1"},
{"makro":"44070", "sortnr":"10", "feldname":"Felder", "value":"dim_staat.inl_ausl_lang|sos_stg_aggr.sem_rueck_beur_ein|sos_stg_aggr.summe"},
{"makro":"44070", "sortnr":"10", "feldname":"Grafik", "value":"STUD_ENTW_SEM_STAAT_LINE"},
{"makro":"44070", "sortnr":"10", "feldname":"Weitere Tabellen", "value":"dim_staat"},
{"makro":"44070", "sortnr":"10", "feldname":"tablestylesheet", "value":"tabelle_html_datenblatt.xsl"},

{"makro":"44070", "sortnr":"20", "feldname":"Köpfe oder Fälle ?", "value":"studiengang_nr = 1 and fach_nr = 1"},
{"makro":"44070", "sortnr":"20", "feldname":"Felder", "value":"dim_studiengang.abschlussart_str|sos_stg_aggr.sem_rueck_beur_ein|sos_stg_aggr.summe"},
{"makro":"44070", "sortnr":"20", "feldname":"Grafik", "value":"STUD_ENTW_SEM_ABSCHLUSS_LINE"},
{"makro":"44070", "sortnr":"20", "feldname":"Weitere Tabellen", "value":"dim_studiengang"},
{"makro":"44070", "sortnr":"20", "feldname":"tablestylesheet", "value":"tabelle_html_datenblatt.xsl"},

{"makro":"44070", "sortnr":"30", "feldname":"Köpfe oder Fälle ?", "value":"studiengang_nr = 1 and fach_nr = 1"},
{"makro":"44070", "sortnr":"30", "feldname":"Felder", "value":"sos_stg_aggr.geschlecht|sos_stg_aggr.sem_rueck_beur_ein|sos_stg_aggr.summe"},
{"makro":"44070", "sortnr":"30", "feldname":"Grafik", "value":"STUD_ENTW_SEM_GESCHL_LINE_1"},
{"makro":"44070", "sortnr":"30", "feldname":"Weitere Tabellen", "value":"dim_studiengang"},
{"makro":"44070", "sortnr":"30", "feldname":"bis Fachsemester", "value":"1"},
{"makro":"44070", "sortnr":"30", "feldname":"tablestylesheet", "value":"tabelle_html_datenblatt.xsl"},

{"makro":"44070", "sortnr":"40", "feldname":"Köpfe oder Fälle ?", "value":"studiengang_nr = 1 and fach_nr = 1"},
{"makro":"44070", "sortnr":"40", "feldname":"Felder", "value":"dim_staat.inl_ausl_lang|sos_stg_aggr.sem_rueck_beur_ein|sos_stg_aggr.summe"},
{"makro":"44070", "sortnr":"40", "feldname":"Grafik", "value":"STUD_ENTW_SEM_STAAT_LINE_1"},
{"makro":"44070", "sortnr":"40", "feldname":"Weitere Tabellen", "value":"dim_staat"},
{"makro":"44070", "sortnr":"40", "feldname":"bis Fachsemester", "value":"1"},
{"makro":"44070", "sortnr":"40", "feldname":"tablestylesheet", "value":"tabelle_html_datenblatt.xsl"},

{"makro":"44070", "sortnr":"50", "feldname":"Köpfe oder Fälle ?", "value":"studiengang_nr = 1 and fach_nr = 1"},
{"makro":"44070", "sortnr":"50", "feldname":"Felder", "value":"dim_studiengang.abschlussart_str|sos_stg_aggr.sem_rueck_beur_ein|sos_stg_aggr.summe"},
{"makro":"44070", "sortnr":"50", "feldname":"Grafik", "value":"STUD_ENTW_SEM_ABSCHLUSS_LINE_1"},
{"makro":"44070", "sortnr":"50", "feldname":"Weitere Tabellen", "value":"dim_studiengang"},
{"makro":"44070", "sortnr":"50", "feldname":"bis Fachsemester", "value":"1"},
{"makro":"44070", "sortnr":"50", "feldname":"tablestylesheet", "value":"tabelle_html_datenblatt.xsl"},

{"makro":"44070", "sortnr":"60", "feldname":"Köpfe oder Fälle ?", "value":"studiengang_nr = 1 and fach_nr = 1"},
{"makro":"44070", "sortnr":"60", "feldname":"Felder", "value":"sos_stg_aggr.geschlecht|sos_stg_aggr.sem_rueck_beur_ein|sos_stg_aggr.summe"},
{"makro":"44070", "sortnr":"60", "feldname":"Grafik", "value":"STUD_ENTW_SEM_GESCHL_LINE_1HS"},
{"makro":"44070", "sortnr":"60", "feldname":"Weitere Tabellen", "value":"dim_studiengang"},
{"makro":"44070", "sortnr":"60", "feldname":"Filter Studierende", "value":"SOS_HSSEM_1"},
{"makro":"44070", "sortnr":"60", "feldname":"tablestylesheet", "value":"tabelle_html_datenblatt.xsl"},

{"makro":"44070", "sortnr":"70", "feldname":"Köpfe oder Fälle ?", "value":"studiengang_nr = 1 and fach_nr = 1"},
{"makro":"44070", "sortnr":"70", "feldname":"Felder", "value":"dim_staat.inl_ausl_lang|sos_stg_aggr.sem_rueck_beur_ein|sos_stg_aggr.summe"},
{"makro":"44070", "sortnr":"70", "feldname":"Grafik", "value":"STUD_ENTW_SEM_STAAT_LINE_1HS"},
{"makro":"44070", "sortnr":"70", "feldname":"Weitere Tabellen", "value":"dim_staat"},
{"makro":"44070", "sortnr":"70", "feldname":"Filter Studierende", "value":"SOS_HSSEM_1"},
{"makro":"44070", "sortnr":"70", "feldname":"tablestylesheet", "value":"tabelle_html_datenblatt.xsl"},

{"makro":"44070", "sortnr":"80", "feldname":"Köpfe oder Fälle ?", "value":"studiengang_nr = 1 and fach_nr = 1"},
{"makro":"44070", "sortnr":"80", "feldname":"Felder", "value":"dim_studiengang.abschlussart_str|sos_stg_aggr.sem_rueck_beur_ein|sos_stg_aggr.summe"},
{"makro":"44070", "sortnr":"80", "feldname":"Grafik", "value":"STUD_ENTW_SEM_ABSCHLUSS_LINE_1HS"},
{"makro":"44070", "sortnr":"80", "feldname":"Weitere Tabellen", "value":"dim_studiengang"},
{"makro":"44070", "sortnr":"80", "feldname":"Filter Studierende", "value":"SOS_HSSEM_1"},
{"makro":"44070", "sortnr":"80", "feldname":"tablestylesheet", "value":"tabelle_html_datenblatt.xsl"},

{"makro":"44190", "sortnr":"0", "feldname":"Dashboard", "value":"STUD"},
{"makro":"44190", "sortnr":"1", "feldname":"Köpfe oder Fälle ?", "value":"studiengang_nr = 1 and fach_nr = 1"},
{"makro":"44190", "sortnr":"1", "feldname":"Spaltenlayout", "value":"sos_stud_sem_dashboard"},
{"makro":"44190", "sortnr":"1", "feldname":"Grafik", "value":"STUD_SEM_LINE"},
{"makro":"44190", "sortnr":"1", "feldname":"tablestylesheet", "value":"tabelle_html_datenblatt.xsl"},

{"makro":"44190", "sortnr":"10", "feldname":"Köpfe oder Fälle ?", "value":"studiengang_nr = 1 and fach_nr = 1"},
{"makro":"44190", "sortnr":"10", "feldname":"Spaltenlayout", "value":"sos_stud_geschl_dashboard"},
{"makro":"44190", "sortnr":"10", "feldname":"Grafik", "value":"STUD_GESCHL_W_DONUT"},
{"makro":"44190", "sortnr":"10", "feldname":"tablestylesheet", "value":"tabelle_html_datenblatt.xsl"},
{"makro":"44190", "sortnr":"10", "feldname":"Nur Endsemester", "value":"1"},

{"makro":"44190", "sortnr":"20", "feldname":"Köpfe oder Fälle ?", "value":"studiengang_nr = 1 and fach_nr = 1"},
{"makro":"44190", "sortnr":"20", "feldname":"Spaltenlayout", "value":"sos_stud_fak_dashboard"},
{"makro":"44190", "sortnr":"20", "feldname":"Grafik", "value":"STUDANF_FAK_BAR"},
{"makro":"44190", "sortnr":"20", "feldname":"tablestylesheet", "value":"tabelle_html_datenblatt.xsl"},
{"makro":"44190", "sortnr":"20", "feldname":"Nur Endsemester", "value":"1"},

{"makro":"44190", "sortnr":"30", "feldname":"Köpfe oder Fälle ?", "value":"1=1"},
{"makro":"44190", "sortnr":"30", "feldname":"Spaltenlayout", "value":"sos_stud_abgrp_dashboard"},
{"makro":"44190", "sortnr":"30", "feldname":"Grafik", "value":"STUDANF_ABGRP_BAR_Y_ECHART"},
{"makro":"44190", "sortnr":"30", "feldname":"tablestylesheet", "value":"tabelle_html_datenblatt.xsl"},
{"makro":"44190", "sortnr":"30", "feldname":"Nur Endsemester", "value":"1"},

{"makro":"44190", "sortnr":"40", "feldname":"Köpfe oder Fälle ?", "value":"1=1"},
{"makro":"44190", "sortnr":"40", "feldname":"Spaltenlayout", "value":"sos_stud_la_dashboard"},
{"makro":"44190", "sortnr":"40", "feldname":"Grafik", "value":"STUD_LEHRAMT_DONUT"},
{"makro":"44190", "sortnr":"40", "feldname":"tablestylesheet", "value":"tabelle_html_datenblatt.xsl"},
{"makro":"44190", "sortnr":"40", "feldname":"Nur Endsemester", "value":"1"},

{"makro":"44190", "sortnr":"50", "feldname":"Köpfe oder Fälle ?", "value":"studiengang_nr = 1 and fach_nr = 1"},
{"makro":"44190", "sortnr":"50", "feldname":"Spaltenlayout", "value":"sos_stud_bildungstyp_dashboard"},
{"makro":"44190", "sortnr":"50", "feldname":"Grafik", "value":"STUD_BILDUNGSTYP_DONUT"},
{"makro":"44190", "sortnr":"50", "feldname":"tablestylesheet", "value":"tabelle_html_datenblatt.xsl"},
{"makro":"44190", "sortnr":"50", "feldname":"Nur Endsemester", "value":"1"},

{"makro":"44190", "sortnr":"60", "feldname":"Köpfe oder Fälle ?", "value":"studiengang_nr = 1 and fach_nr = 1"},
{"makro":"44190", "sortnr":"60", "feldname":"Spaltenlayout", "value":"sos_stud_hzb_bland_dashboard"},
{"makro":"44190", "sortnr":"60", "feldname":"Grafik", "value":"STUDANF_HZB_LAND_BAR"},
{"makro":"44190", "sortnr":"60", "feldname":"tablestylesheet", "value":"tabelle_html_datenblatt.xsl"},
{"makro":"44190", "sortnr":"60", "feldname":"Nur Endsemester", "value":"1"},

{"makro":"44660", "sortnr":"0", "feldname":"Dashboard", "value":"STUD"},

{"makro":"44660", "sortnr":"10", "feldname":"Köpfe oder Fälle ?", "value":"studiengang_nr = 1 and fach_nr = 1"},
{"makro":"44660", "sortnr":"10", "feldname":"Spaltenlayout", "value":"sos_stud_sem_dashboard"},
{"makro":"44660", "sortnr":"10", "feldname":"Grafik", "value":"STUD_SEM_LINE"},
{"makro":"44660", "sortnr":"10", "feldname":"Grafiktitel", "value":"Studienanfänger*innen 1.HS"},
{"makro":"44660", "sortnr":"10", "feldname":"Filter Studierende", "value":"SOS_HSSEM_1"},
{"makro":"44660", "sortnr":"10", "feldname":"tablestylesheet", "value":"tabelle_html_datenblatt.xsl"},

{"makro":"44660", "sortnr":"20", "feldname":"Köpfe oder Fälle ?", "value":"studiengang_nr = 1 and fach_nr = 1"},
{"makro":"44660", "sortnr":"20", "feldname":"Spaltenlayout", "value":"sos_stud_sem_dashboard"},
{"makro":"44660", "sortnr":"20", "feldname":"Grafik", "value":"STUD_SEM_LINE"},
{"makro":"44660", "sortnr":"20", "feldname":"Grafiktitel", "value":"Studienanfänger*innen 1.FS"},
{"makro":"44660", "sortnr":"20", "feldname":"bis Fachsemester", "value":"1"},
{"makro":"44660", "sortnr":"20", "feldname":"tablestylesheet", "value":"tabelle_html_datenblatt.xsl"},

{"makro":"44660", "sortnr":"30", "feldname":"Köpfe oder Fälle ?", "value":"studiengang_nr = 1 and fach_nr = 1"},
{"makro":"44660", "sortnr":"30", "feldname":"Spaltenlayout", "value":"sos_stud_sem_dashboard"},
{"makro":"44660", "sortnr":"30", "feldname":"Grafik", "value":"STUD_SEM_LINE"},
{"makro":"44660", "sortnr":"30", "feldname":"tablestylesheet", "value":"tabelle_html_datenblatt.xsl"},

{"makro":"44690", "sortnr":"0", "feldname":"Dashboard", "value":"STUDABSOLV"},

{"makro":"44690", "sortnr":"10", "feldname":"Köpfe oder Fälle ?", "value":"studiengang_nr = 1 and fach_nr = 1"},
{"makro":"44690", "sortnr":"10", "feldname":"Spaltenlayout", "value":"sos_stud_sem_dashboard"},
{"makro":"44690", "sortnr":"10", "feldname":"Grafik", "value":"STUD_SEM_LINE"},
{"makro":"44690", "sortnr":"10", "feldname":"tablestylesheet", "value":"tabelle_html_datenblatt.xsl"},

{"makro":"44690", "sortnr":"20", "feldname":"Köpfe oder Fälle ?", "value":"studiengang_nr = 1 and fach_nr = 1"},
{"makro":"44690", "sortnr":"20", "feldname":"Spaltenlayout", "value":"sos_stud_sem_dashboard"},
{"makro":"44690", "sortnr":"20", "feldname":"Grafik", "value":"STUD_SEM_LINE"},
{"makro":"44690", "sortnr":"20", "feldname":"Grafiktitel", "value":"Studienanfänger*innen 1.HS"},
{"makro":"44690", "sortnr":"20", "feldname":"Filter Studierende", "value":"SOS_HSSEM_1"},
{"makro":"44690", "sortnr":"20", "feldname":"tablestylesheet", "value":"tabelle_html_datenblatt.xsl"},

{"makro":"44690", "sortnr":"30", "feldname":"Köpfe oder Fälle ?", "value":"studiengang_nr = 1 and fach_nr = 1"},
{"makro":"44690", "sortnr":"30", "feldname":"Spaltenlayout", "value":"sos_stud_sem_dashboard"},
{"makro":"44690", "sortnr":"30", "feldname":"Grafik", "value":"STUD_SEM_LINE"},
{"makro":"44690", "sortnr":"30", "feldname":"Grafiktitel", "value":"Studienanfänger*innen 1.FS"},
{"makro":"44690", "sortnr":"30", "feldname":"bis Fachsemester", "value":"1"},
{"makro":"44690", "sortnr":"30", "feldname":"tablestylesheet", "value":"tabelle_html_datenblatt.xsl"},

{"makro":"44690", "sortnr":"40", "feldname":"Köpfe oder Fälle ?", "value":"1=1"},
{"makro":"44690", "sortnr":"40", "feldname":"Spaltenlayout", "value":"rpta_sos_lab_aggr_sem"},
{"makro":"44690", "sortnr":"40", "feldname":"Grafik", "value":"ABSOLV_SEM_LINE"},
{"makro":"44690", "sortnr":"40", "feldname":"tablestylesheet", "value":"tabelle_html_datenblatt.xsl"},

{"makro":"44690", "sortnr":"50", "feldname":"Köpfe oder Fälle ?", "value":"1=1"},
{"makro":"44690", "sortnr":"50", "feldname":"Spaltenlayout", "value":"rpta_sos_lab_aggr_in_rsz_sem"},
{"makro":"44690", "sortnr":"50", "feldname":"Grafik", "value":"ABSOLV_RSZ_SEM_BAR"},
{"makro":"44690", "sortnr":"50", "feldname":"tablestylesheet", "value":"tabelle_html_datenblatt.xsl"},

{"makro":"44690", "sortnr":"60", "feldname":"Köpfe oder Fälle ?", "value":"1=1"},
{"makro":"44690", "sortnr":"60", "feldname":"Spaltenlayout", "value":"rpta_sos_lab_aggr_abgrp_sem"},
{"makro":"44690", "sortnr":"60", "feldname":"Grafik", "value":"ABSOLV_ABGRP_SEM_AREA"},
{"makro":"44690", "sortnr":"60", "feldname":"tablestylesheet", "value":"tabelle_html_datenblatt.xsl"}

] />

-- ab hier nicht mehr ändern:

CREATE TEMP TABLE tmp_macro_masken_bez (
    maskeninfo_id1 integer NOT NULL,
    maskeninfo_id2 integer NOT NULL,
    active integer DEFAULT 1 NOT NULL,
    sortnr smallint NOT NULL,
    schleifenrelation character(255),
    schleifenfeldname character(255),
    alias character(255),
    schleifenfstand character(255),
    schleifenfsicht character(255),
    aktion character(255)
);
CREATE TEMP TABLE tmp_macro_feld_wert (
    macro integer NOT NULL,
    sortnr integer NOT NULL,
    feldname character(255) NOT NULL,
    alias character(255) NOT NULL,
    value character(255),
    value_caption character(255),
    feldstand character(255),
    feldsicht character(255),
    active integer DEFAULT 1 NOT NULL
);


<#foreach makro in makros>
<#foreach maske in masken>
<#if maske.makro==makro.tid>

insert into tmp_macro_masken_bez(maskeninfo_id1,
       maskeninfo_id2,
       active,
       sortnr)
select ${makro.tid},--maskeninfo_id1,
       ${maske.tid},--maskeninfo_id2,
       1,--active,
       ${maske.sortnr} --sortnr
       from xdummy;
       
<#foreach feld in felder>
<#if feld.makro==makro.tid && feld.sortnr==maske.sortnr>

--Tab.12: alle ohne Exmatr
insert into tmp_macro_feld_wert
( macro,
       sortnr,
       feldname,
       alias,
       value,
       value_caption,
       feldstand,
       feldsicht,
       active)
 SELECT ${makro.tid}, --macro
       ${maske.sortnr},--sortnr
       '${feld.feldname}',--feldname,
       '',--alias,
       '${feld.value}', --value, 
       '',--value_caption,
       '', --feldstand,
       '',--feldsicht,
       1 --active
FROM xdummy;

</#if>
</#foreach>


</#if>
</#foreach>
</#foreach>

      
delete from macro_masken_bez where maskeninfo_id1 in (select maskeninfo_id1 from tmp_macro_masken_bez)
;


insert into macro_masken_bez
(maskeninfo_id1,
       maskeninfo_id2,
       active,
       sortnr,
       schleifenrelation,
       schleifenfeldname,
       alias,
       schleifenfstand,
       schleifenfsicht,
       aktion)
select maskeninfo_id1,
       maskeninfo_id2,
       active,
       sortnr,
       schleifenrelation,
       schleifenfeldname,
       alias,
       schleifenfstand,
       schleifenfsicht,
       aktion
FROM tmp_macro_masken_bez
;

delete from macro_feld_wert where macro in (select macro from tmp_macro_feld_wert); 

insert into macro_feld_wert
( macro,
       sortnr,
       feldname,
       alias,
       value,
       value_caption,
       feldstand,
       feldsicht,
       active)
 SELECT macro,
       sortnr,
       feldname,
       alias,
       value,
       value_caption,
       feldstand,
       feldsicht,
       active
FROM tmp_macro_feld_wert;


drop table tmp_macro_masken_bez;
drop table tmp_macro_feld_wert;


