<%@ language = "JavaScript" %>
<% /*
     $Revision$
     $Id$

     File:          fac_edit_template_save.asp
     Description:   Sla de template wijziging op en toon direct een preview
     Parameters:

     Context:       Vanuit fac_edit_template.asp

*/ %>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="../Shared/persoonselector.inc" -->
<!-- #include file="../Shared/plaatsselector.inc" -->
<!-- #include file="../Shared/afdelingselector.inc" -->
<!-- #include file="../Shared/calendar.inc" -->
<!-- #include file="../Shared/resultset_table_v2.inc" -->
<!-- #include file="../shared/save2db.inc" -->
<%
FCLTHeader.Requires({ plugins: ["jQuery", "kenmerk"],
                      js: ["../res/res_search.js"]
                    });

var authparams = user.checkAutorisation("WEB_LAYOUT");

var previewmode = getFParamInt("previewmode");
var submitting = getFParamInt("submitting", 0);
var csscust = getFParam("csscust", "");

var cssparams = { cssmode: previewmode };
if (previewmode == 2)
{
    cssparams.csstemplate = {};
    for (item in FCLTHeader.defaultTemplate)
    {
        var conceptval = getFParam(item);
        if (conceptval != "")
            cssparams.csstemplate[item] = conceptval;
        else
            delete cssparams.csstemplate[item];
    }

    var mainColorContrast = getFParamInt("main-color-contrast", 0);
    if (mainColorContrast) {
        cssparams.csstemplate["main-color-contrast"] = mainColorContrast;
    }
    var accentColorContrast = getFParamInt("accent-color-contrast", 0);
    if (accentColorContrast) {
        cssparams.csstemplate["accent-color-contrast"] = accentColorContrast;
    }
    var frameheaderBackgroundColor = getFParamInt("frameheader-bg-color", 0);
    if (frameheaderBackgroundColor) {
        cssparams.csstemplate["frameheader-bg-color"] = frameheaderBackgroundColor;
    }

    if (submitting)
    {
        var fields =  [ { dbs: "fac_setting_pvalue", typ: "varchar", val: JSON.stringify(cssparams.csstemplate) },
                        { dbs: "fac_setting_datum",  typ: "sql",     val: "SYSDATE" },
                        { dbs: "prs_perslid_key",    typ: "key",     val: user_key  }];

        sql = buildUpdate("fac_setting", fields)
            + "     fac_setting_name = 'csstemplate'";

        var err = Oracle.Execute(sql, true);
        if (err.friendlyMsg)
            abort_with_warning(err.friendlyMsg);

        if (user.has("WEB_PRSSYS"))
        {
            var fields =  [ { dbs: "fac_setting_pvalue", typ: "varchar", val: csscust },
                            { dbs: "fac_setting_datum",  typ: "sql",     val: "SYSDATE" },
                            { dbs: "prs_perslid_key",    typ: "key",     val: user_key  }];

            sql = buildUpdate("fac_setting", fields)
                + "     fac_setting_name = 'csscust'";

            var err = Oracle.Execute(sql, true);
            if (err.friendlyMsg)
                abort_with_warning(err.friendlyMsg);

            settings.loadSET(true); // Forceer caching opnieuw
        }
    }
    if (user.has("WEB_PRSSYS"))
        settings.overrule_setting("csscust", csscust);

}
%>

<html>
  <head>
<%  FCLTHeader.Generate(cssparams); %>

    <script type="text/javascript">

        async function myModal(init)
        {
          var key = $('#act').val();
          var url = "load_kenmerk.asp";
          var titel = L("lcl_res_kenmerken");
          await showKenmerkModal(url, titel, init)
        }
        function sample()
        {
            FcltMgr.alert("This is just a sample");
        }

    </script>
  </head>

<body>
  <section id="searchbody">
    <h1><%=L("lcl_fac_template_preview")%></h1>
<%
    buttons = [];
    buttons.push ({title: L("lcl_submit"),  icon: "fa-fclt-save", action: "sample()" });
    buttons.push( {title: L("lcl_cancel"), icon: "fa-fclt-cancel", action: "sample()" } );
    //IFRAMER_HEADER("Voorbeeld header", buttons);
%>
      <form name="u2" action="javascript:return false;" method="post">
<%    SEARCH_PAGE_START({ header: L("lcl_filterblok") });
        SEARCH_BLOCK_START();
%>
            <tr class="primsearch">
              <td class="label"><label for="resnum"><%=L("lcl_res_number")%></label></td>
              <td><input type="text" class="fldshort"></td>
            </tr>

<%            FCLTcalendar("date_from",
                           { label : L("lcl_period_from"),
                             //datum: date_from,
                             trclass: "primsearch",
                             volgnr: 1
                           });
              FCLTcalendar("date_to",
                           { label: L("lcl_period_to"),
                             //datum: date_to,
                             trclass: "primsearch",
                             volgnr: 2
                           });

              FCLTplaatsselector(authparams.ALGreadlevel, { startlevel: 1,
                                                            eindlevel: 3,
                                                            filtercode: "FAC",
                                                            requiredlevel: 2,
                                                            whenEmpty: L("lcl_search_generic")  // want filter
                                                          });
           SEARCH_BLOCK_END();
            // Start responsive search_column 2
            SEARCH_BLOCK_START();
%>
            <tr class="primsearch">
              <!-- Description/remark -->
              <td class="label"><label for="searchtext"><%=L("lcl_search_diff_fields")%></label></td>
              <td>
                <input type="text" class="fld" name="searchtext" value="Zoektekst">
              </td>
            </tr>

<%                FCLTpersoonselector("sName_key",
                                      "sgPerson",
                                      { perslidKey: user_key,
                                        label: L("lcl_res_requestor"),
                                        trclass: "primsearch",
                                        whenEmpty: L("lcl_search_generic")  // want filter
                                      });


              sql = "SELECT rd.ins_discipline_key dis_key"
                      + ", "+ lcl.xsql('rd.ins_discipline_omschrijving','rd.ins_discipline_key') +" omschrijving"
                      + " FROM res_v_aanwezigdiscipline rd"
                      + ", fac_v_webgebruiker fw"
                      + ", fac_functie fwf"
                      + " WHERE rd.ins_discipline_min_level = 3"
                      + " AND fw.ins_discipline_key = rd.ins_discipline_key"
                      + " AND fw.fac_functie_key = fwf.fac_functie_key"
                      + " AND fwf.fac_functie_code = 'WEB_RESFOF'"
                      + " AND fw.prs_perslid_key = " + user_key
                      + " ORDER BY ins_discipline_volgnr, 2";
                FCLTselector("roomcatmulti",
                             sql,
                             { label: L("lcl_res_roomcat"),
                               trclass: "primsearch",
                               multi: true,
                               emptyOption: L("lcl_all")
                             });
        SEARCH_BLOCK_END();
        SIMPLE_BLOCK_START();
        var buttons =  [];
          buttons.push ( { title: L("lcl_overview_list"), action: "sample()", icon: "fa-clipboard-list" } );   // Overzicht
          buttons.push ( { title: L("lcl_planboard"),     action: "sample()", icon: "fa-calendar-day" } );
        CreateButtons(buttons, { showIcons: true } );
        SIMPLE_BLOCK_END();
      SEARCH_PAGE_END();
%>
      </form>

  </section>
  <section id="listbody">
    <h1><%=L("lcl_fac_template_preview")%></h1>
    <script type="text/javascript">
      function doZet(row)
      {
        var url = "appl/fac/fac_show_api.asp?api_key=" + row.getAttribute("ROWKEY");
        FcltMgr.openDetail(url, L('lcl_fac_api')+' '+row.getAttribute("ROWKEY"));
      }
    </script>
<%
    var sql = "SELECT * FROM"
            + "     (SELECT fac_functie_key, fac_functie_code, fac_functie_module,"
            + "             lcl.l(fac_functie_omschrijving, 1) fac_functie_omschrijving FROM fac_functie"
            + "      ORDER BY fac_functie_code)"
            + " WHERE ROWNUM < 10";

    var rst = new ResultsetTable({ sql: sql,
                                   keyColumn: "fac_functie_key",
                                   ID: "apitable",
                                   title : "Facilitor functies"
                                 });

    rst.addColumn(new Column({caption: "Key", content: "fac_functie_key"}));
    rst.addColumn(new Column({caption: "Code", content: "fac_functie_code"}));
    rst.addColumn(new Column({caption: "Module", content: "fac_functie_module"}));
    rst.addColumn(new Column({caption: "Omschrijving", content: "fac_functie_omschrijving"}));

    rst.addAction({ action: "sample", caption: L("lcl_obj_lend_out") });
    rst.addAction({ action: "sample", caption: L("lcl_obj_receive") });

    var cnt = rst.processResultset();
%>
  </section>
</body>
</html>
<% ASPPAGE_END(); %>
