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

     File:           fac_show_menu.asp
     Description:
     Parameters:     menu_key
                     TODO: nog niet gebruikte items..?
*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="fac.inc" -->
<!-- #include file="../Shared/FlexFiles.inc" -->
<!-- #include file="../Shared/selector.inc" -->

<%
FCLTHeader.Requires({ plugins:["jQuery"] })

var autfunction = "WEB_PRSSYS";
var authparams = user.checkAutorisation(autfunction);

var menu_key = getQParamInt("menu_key", -1);
var menuitem_key = getQParamInt("menuitem_key", -1);

var sql = "SELECT m.fac_menu_altlabel menu_label, "
        + "       mi.fac_menuitems_label menuitems_label,"
        + "       mi.fac_menuitems_module,"
        + "       COALESCE(m.fac_menu_altgroep, mi.fac_menuitems_groep) groep,"
        + "       m.fac_menu_level,"
        + "       m.fac_menu_volgnr,"
        + "       COALESCE(m.fac_menu_alturl, mi.fac_menuitems_url) url,"
        + "       mi.fac_menuitems_srtdisc,"
        + "       mi.fac_menuitems_disc,"
        + "       mi.fac_menuitems_rw,"
        + "       m.fac_functie_key                         extFkey,"
        + "       m.ins_srtdiscipline_key,"
        + "       m.ins_discipline_key,"
        + "       mi.fac_functie_key,"
        + "       f.fac_functie_code,"
        + "       lcl.l (f.fac_functie_omschrijving, 1)     fac_functie_omschrijving,"
        + "       COALESCE(m.fac_menu_info, mi.fac_menuitems_oms) uitleg,"
        + "       m.fac_menu_message,"
        + "       m.fac_menu_portal,"
        + "       COALESCE(m.fac_menu_image, mi.fac_menuitems_image) image"
        + "  FROM fac_menu m, fac_menuitems mi, fac_functie f"
        + " WHERE     m.fac_menuitems_key = mi.fac_menuitems_key(+)"
        + "       AND mi.fac_functie_key = f.fac_functie_key(+)"
        + "       AND m.fac_menu_key = " + menu_key;

var oRs = Oracle.Execute(sql);

var module = oRs("fac_menuitems_module").Value;
var groep = fncolGroep(oRs("groep").Value);
var mobilemenu = S("mobile_enabled") && oRs("groep").Value == 3;
var niveau = oRs("fac_menu_level").Value;
var volgnr = oRs("fac_menu_volgnr").Value;
var url = oRs("url").Value;
var urlType = "path";
if ((url || "").match(/[\?\\\/:]/g) === null) { // Het is een url als het 1 van de volgende tekens bevat; Forward slash (/), backslash (\) of een colon (:)
    urlType = "file";
}
// P.S.: De 'oude' bestanden die door ons waren geupload worden hiermee als path geinterpreteerd, dat lijkt me acceptabel

// Systeem autorisatieFunctie
var sysFsrtdisc = oRs("fac_menuitems_srtdisc").Value;
var sysFdisc = oRs("fac_menuitems_disc").Value;
var sysFrw = oRs("fac_menuitems_rw").Value;
var sysFunc = oRs("fac_functie_key").Value ? oRs("fac_functie_omschrijving").value + " (" + oRs("fac_functie_code").value + ")" : "";

if (oRs("menu_label").Value)
{
    var label_db = L(oRs("menu_label").Value, { autolcl: true });
    var label = L(label_db, { autolcl: true });
}
else
{
    var label_db = L(oRs("menuitems_label").Value, { autolcl: true });
    var label = L(label_db, { autolcl: true });
    if (sysFsrtdisc == 1)
        label += " (+ " + L("lcl_vakgroup_type") + ")";
    if (sysFdisc == 1)
        label += " (+ " + L("lcl_discipline") + ")";
}

// Extra autorisatieFunctie
var extFkey = oRs("extFkey").value;
var extFsrtdisc_key = oRs("ins_srtdiscipline_key").value;
var extFdisc_key = oRs("ins_discipline_key").value;

var uitleg = oRs("uitleg").Value;
var alert = oRs("fac_menu_message").Value;
var portal = oRs("fac_menu_portal").Value;
var image = oRs("image").Value;

if (oRs.eof) {
  oRs.Close();
  Response.End();
}

oRs.Close();

function fncolGroep(oRsvalue)
{
  var lgrtext = "";
  switch (oRsvalue)
  {
    case 0 : lgrtext = L("lcl_menu_pers") ; break;
    case 1 : lgrtext = L("lcl_menu_prof") ;  break;
    case 2 : lgrtext = L("lcl_menu_config") ;  break;
    case 3 : lgrtext = L("lcl_menu_mobile") ;  break;
  }
  return lgrtext;
}


%>
<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script>
      function edit_menu()
      {
        if (FcltMgr.startEdit(window))
          window.location.href = "fac_edit_menu.asp?menu_key=<%=menu_key%>&menuitem_key=<%=menuitem_key%>";
      }

      function copy_menu()
      {
        FcltMgr.openDetail("/appl/fac/fac_menu.asp?copy=1&menu_key=<%=menu_key%>",  L("lcl_fac_menu_copy") + " " + L("lcl_fac_menuoptie").toLowerCase());
      }

      function delete_menu()
      {
         FcltMgr.confirm(L("lcl_fac_del_txt_menu"), function() {
             var menu_key = <%=menu_key%>;
             var data = {
                 key: <%=menu_key%>,
                 level: "FM"
             };
             <% protectRequest.dataToken("data"); %>
             $.post("fac_delete.asp",
                 data,
                 FcltCallbackClose,
                 "json");
         });
      }

      $(function() {
        FcltMgr.setTitle(L("lcl_fac_menuoptie")+" "+"<%=menu_key%>", { hot: false });
      })

    </script>
  </head>

  <body class="showmode">
<%
SUBFRAME_START();
    buttons = [ { title: L("lcl_change"),         icon: "fa-fclt-edit", action: "edit_menu()" },
                { title: L("lcl_fac_menu_copy"),  icon: "fa-copy",      action: "copy_menu()", tooltip: L("lcl_fac_menu_copy_hint") },
                { title: L("lcl_delete"),         icon: "fa-trash-alt", action: "delete_menu()" }];
    IFRAMER_HEADER(L("lcl_fac_menuoptie"), buttons);
%>
      <form name="u2" onSubmit="return false;">
<%      BLOCK_START("menuOptie", L("lcl_menu_menublock"), { icon: "fa-clipboard-list" });
          // Menulabel
          ROFIELDTR("fld", L("lcl_fac_menuoptie"), label_db, { translate: { fld: "fac_menu_altlabel", key : menu_key } });
          ROFIELDTR("fld", L("lcl_fac_menuoptie_label"), label);

          ROFIELDTR("fld", L("lcl_menu_module"), module, { suppressEmpty: true });

          // Tabblad
          ROFIELDTR("fld", L("lcl_menugroep"), groep);

          sql = "SELECT 1, " + safe.qL("lcl_menu_level1") + " FROM DUAL UNION ALL "
              + "SELECT 2, " + safe.qL("lcl_menu_level2") + " FROM DUAL";
          FCLTselector("level",
                      sql,
                      { label: L("lcl_menu_level"),
                        initKey: niveau,
                        readonly: true
                      });

          ROFIELDTR("fld", L("lcl_menuvolgnr"), volgnr);

          if (urlType == "file") {
            FILEPICKERTR("url", L("lcl_menu_fac_file"), url, { "module": "MENUURL", "key": menu_key, "readonly": true });
          } else {
            ROFIELDTR("fld", L("lcl_menu_fac_url"), url, { suppressEmpty: true });
          }
        BLOCK_END();

        BLOCK_START("menuAuth", L("lcl_menu_authblock"), { icon: "fa-portal-enter" });
          ROFIELDTR("fld", L("lcl_fac_menusysautorisatie"), sysFunc, { suppressEmpty: true });
          ROFIELDTR("fld", L("lcl_menu_fac_rw"), sysFrw, { suppressEmpty: true });

          var laltfunctie;
          if (extFkey)
          {
            lsql = "SELECT fac_functie_key, fac_functie_code||': '||lcl.l(fac_functie_omschrijving, 1) altfunctie FROM fac_functie WHERE fac_functie_key=" + extFkey;
            loRs = Oracle.Execute(lsql);
            laltfunctie = loRs('altfunctie').value;
            loRs.Close();
          }
          ROFIELDTR("fld", L("lcl_fac_menuautorisatie"), laltfunctie, { suppressEmpty: true });
          var lsrtdisc;
          if (extFsrtdisc_key)
          {
            lsql = "SELECT "+ lcl.xsqla("ins_srtdiscipline_omschrijving", "ins_srtdiscipline_key", "ins_srtdiscipline_omschrijving")
                + " FROM ins_srtdiscipline WHERE ins_srtdiscipline_key=" + extFsrtdisc_key;
            loRs = Oracle.Execute(lsql);
            lsrtdisc = loRs('ins_srtdiscipline_omschrijving').value;
            loRs.Close();
          }
          ROFIELDTR("fld", L("lcl_mld_vakgroeptype"), lsrtdisc, { suppressEmpty: true });
          var ldisc;
          if (extFdisc_key)
          {
            lsql = "SELECT " + lcl.xsqla("ins_discipline_omschrijving", "ins_discipline_key", "ins_discipline_omschrijving")
                + " FROM ins_tab_discipline WHERE ins_discipline_key=" + extFdisc_key;
            loRs = Oracle.Execute(lsql);
            ldisc = loRs('ins_discipline_omschrijving').value;
            loRs.Close();
          }
          ROFIELDTR("fld", L("lcl_bes_discipline"), ldisc, { suppressEmpty: true });
        BLOCK_END();

        BLOCK_START("menuMore", L("lcl_menu_moreblock"), { icon: "fa-cogs" });
          // Uitleg
          ROFIELDTR("fld", L("lcl_menuinfo"), uitleg, {suppressEmpty: true, translate: { fld: "fac_menu_info", key : menu_key }});

          // Mededeling
          ROFIELDTR("fld", L("lcl_menumessage"), alert, { suppressEmpty: true });

          // In portaal
          ROCHECKBOXTR("fldcheck", mobilemenu ? L("lcl_menu_app") : L("lcl_menuportal"), portal, { suppressEmpty: true });

          // Afbeelding
          ROSYMBOLTR("fld", L("lcl_image"), image, { "key": menu_key, "module": "MENU" });
        BLOCK_END();
%>
      </form>
<% SUBFRAME_END(); %>
  </body>
</html>
<% ASPPAGE_END(); %>
