<%@ 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" -->

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

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

if (menu_key == -1 && menuitem_key == -1) Response.End;

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

if (menu_key != -1 && menuitem_key != -1)
{
  var sql = "SELECT mi.fac_menuitems_key"
          + "     , mi.fac_menuitems_groep"
          + "     , mi.fac_menuitems_image"
          + "     , mi.fac_menuitems_label"
          + "     , mi.fac_menuitems_oms"
          + "     , mi.fac_menuitems_module"
          + "     , mi.fac_menuitems_url"
          + "     , mi.fac_menuitems_srtdisc"
          + "     , mi.fac_menuitems_disc"
          + "     , mi.fac_functie_key"
          + "     , mi.fac_menuitems_rw"
          + "     , mi.fac_menuitems_default"
          + "     , m.fac_menu_key"
          + "     , m.fac_menu_volgnr"
          + "     , m.fac_menuitems_key"
          + "     , m.fac_menu_info"
          + "     , m.fac_menu_altlabel"
          + "     , m.fac_menu_alturl"
          + "     , m.fac_menu_altgroep"
          + "     , m.fac_menu_image"
          + "     , m.ins_srtdiscipline_key"
          + "     , m.ins_discipline_key"
          + "     , m.fac_functie_key altfunctiekey"
          + "     , f.fac_functie_code"
          + "     , f.fac_functie_omschrijving"
          + "     , m.fac_menu_level"
          + "     , m.fac_menu_portal"
          + "  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;
}
else if (menuitem_key != -1)
{
  var sql = "SELECT mi.fac_menuitems_key"
          + "     , mi.fac_menuitems_groep"
          + "     , mi.fac_menuitems_image"
          + "     , mi.fac_menuitems_label"
          + "     , mi.fac_menuitems_oms"
          + "     , mi.fac_menuitems_module"
          + "     , mi.fac_menuitems_url"
          + "     , mi.fac_menuitems_srtdisc"
          + "     , mi.fac_menuitems_disc"
          + "     , mi.fac_functie_key"
          + "     , mi.fac_menuitems_rw"
          + "     , mi.fac_menuitems_default"
          + "     , f.fac_functie_code"
          + "     , f.fac_functie_omschrijving"
          + "  FROM fac_menuitems mi, fac_functie f"
          + " WHERE mi.fac_functie_key = f.fac_functie_key"
          + "   AND mi.fac_menuitems_key = " + menuitem_key;
}
else if (menu_key != -1)
{
  var sql = "SELECT m.fac_menu_key"
          + "     , m.fac_menu_volgnr"
          + "     , m.fac_menuitems_key"
          + "     , m.fac_menu_info"
          + "     , m.fac_menu_altlabel"
          + "     , m.fac_menu_alturl"
          + "     , m.fac_menu_altgroep"
          + "     , m.fac_menu_image"
          + "     , m.ins_srtdiscipline_key"
          + "     , m.ins_discipline_key"
          + "     , m.fac_functie_key altfunctiekey"
          + "     , m.fac_menu_level"
          + "     , m.fac_menu_portal"
          + "  FROM fac_menu m"
          + " WHERE m.fac_menu_key = " + menu_key;
}

var oRs = Oracle.Execute(sql);

if (menuitem_key != -1)
{
  var fac_milbl      = oRs("fac_menuitems_label").value;
  var fac_misrtdisc  = oRs("fac_menuitems_srtdisc").value;
  var fac_midisc     = oRs("fac_menuitems_disc").value;
  var fac_migrp      = fncolGroep(oRs("fac_menuitems_groep").value);
  var fac_mimod      = oRs("fac_menuitems_module").value;
  var fac_mioms      = oRs("fac_menuitems_oms").value;
  var fac_func       = oRs("fac_functie_omschrijving").value + " (" + oRs("fac_functie_code").value + ")";
  var fac_mirw       = oRs("fac_menuitems_rw").value;
  var fac_miurl      = oRs("fac_menuitems_url").value;
  var fac_miimage    = oRs("fac_menuitems_image").value;

  var ml = fac.localstring(fac_milbl);
  if (fac_misrtdisc == 1)
    ml += " (+ " + L("lcl_vakgroup_type") + ")";
  if (fac_midisc == 1)
    ml += " (+ " + L("lcl_discipline") + ")";
}

if (menu_key != -1)
{
  var fac_maltlbl    = oRs("fac_menu_altlabel").value;
  var fac_maltgrp    = fncolGroep(oRs("fac_menu_altgroep").value);
  var fac_mimage     = oRs('fac_menu_image').value;
  var fac_minfo      = oRs("fac_menu_info").value;
  var fac_altfunc    = oRs("altfunctiekey").value;
  var fac_mvolgnr    = oRs("fac_menu_volgnr").value;
  var fac_malturl    = oRs("fac_menu_alturl").value
  var fac_mdisckey   = oRs("ins_discipline_key").value
  var fac_msrtdisckey= oRs("ins_srtdiscipline_key").value
  var fac_mlevel     = oRs("fac_menu_level").value;
  var fac_mportal    = oRs("fac_menu_portal").value;
}

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

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;
  }
  return lgrtext;
}


%>
<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script type="text/javascript" >
      function menuChange()
      {
        if (FcltMgr.startEdit(window))
          window.location.href = "fac_edit_menu.asp?menu_key=<%=menu_key%>&menuitem_key=<%=menuitem_key%>";
      }
      function menuDelete()
      {
         var menu_key = <%=menu_key%>;
         if (confirm(L("lcl_fac_del_txt_menu")))
         {
           var data = { key: <%=menu_key%>,
                        level: "FM"
                      };
           <% protectRequest.dataToken("data"); %>
           $.post("fac_delete.asp",
                  data,
                  FcltCallbackClose,
                  "json");
         }
      }

      function edit_image()
      {
        var url = "<%=protectQS.create("../../appl/shared/BijlagenForm.asp?module=MENU&multi=1")%>";
        FcltMgr.openModalDetail(url, L("lcl_mrk_upload_foto") );
      }
    </script>
  </head>

  <body id="showbody">
<%
    buttons = [ {title: "lcl_photos", action: "edit_image()", icon: "folder.png" },
                {title: L("lcl_change"), icon: "wijzigen.png", action:"menuChange()" },
                {title: L("lcl_delete"), icon: "delete.png",   action:"menuDelete()"}];
    IFRAMER_HEADER(L("lcl_fac_menuoptie"), buttons);
%>
    <div id="show">
      <form name=u2 onSubmit="return false;">
<%      BLOCK_START("menuStd", L("lcl_menu_menuitemblock"));
        ROFIELDTR("fld", L("lcl_fac_menuoptie"), ml, {suppressEmpty: true});
        ROFIELDTR("fld", L("lcl_menugroep"), fac_migrp, {suppressEmpty: true});
        ROFIELDTR("fld", L("lcl_menu_module"), fac_mimod, {suppressEmpty: true});
        ROFIELDTR("fld", L("lcl_menuinfo"), fac_mioms, {suppressEmpty: true});
        ROFIELDTR("fld", L("lcl_fac_menusysautorisatie"), fac_func, {suppressEmpty: true});
        ROFIELDTR("fld", L("lcl_menu_fac_rw"), fac_mirw, {suppressEmpty: true});
        ROFIELDTR("fld", L("lcl_menu_fac_url"), fac_miurl, {suppressEmpty: true});
        ROFIELDTR("fld", L("lcl_image"), fac_miimage, {suppressEmpty: true});
        BLOCK_END();

        BLOCK_START("menuCust", L("lcl_menu_menublock"));
        ROFIELDTR("fld", L("lcl_fac_menuoptie"), fac_maltlbl, {suppressEmpty: false, translate: { fld: "fac_menu_altlabel", key : menu_key }});
        ROFIELDTR("fld", L("lcl_menugroep"), fac_maltgrp, {suppressEmpty: true});
        ROFIELDTR("fld", L("lcl_menuvolgnr"), fac_mvolgnr, {suppressEmpty: true});
        ROFIELDTR("fld", L("lcl_menuinfo"), fac_minfo, {suppressEmpty: true, translate: { fld: "fac_menu_info", key : menu_key }});
        var laltfunctie;
        if (fac_altfunc)
        {
          lsql = "SELECT fac_functie_key, fac_functie_code||': '||fac_functie_omschrijving altfunctie FROM fac_functie WHERE fac_functie_key="+fac_altfunc;
          loRs = Oracle.Execute(lsql);
          laltfunctie = loRs('altfunctie').value;
        }
        ROFIELDTR("fld", L("lcl_fac_menuautorisatie"), laltfunctie, {suppressEmpty: true});
        var ldisc;
        if (fac_mdisckey)
        {
          lsql = "SELECT " + lcl.xsqla("ins_discipline_omschrijving", "ins_discipline_key", "ins_discipline_omschrijving")
               + " FROM ins_tab_discipline WHERE ins_discipline_key="+fac_mdisckey;
          loRs = Oracle.Execute(lsql);
          ldisc = loRs('ins_discipline_omschrijving').value;
        }
        ROFIELDTR("fld", L("lcl_bes_discipline"), ldisc, {suppressEmpty: true});
        var lsrtdisc;
        if (fac_msrtdisckey)
        {
          lsql = "SELECT "+ lcl.xsqla("ins_srtdiscipline_omschrijving", "ins_srtdiscipline_key", "ins_srtdiscipline_omschrijving")
               + " FROM ins_srtdiscipline WHERE ins_srtdiscipline_key="+fac_msrtdisckey;
          loRs = Oracle.Execute(lsql);
          lsrtdisc = loRs('ins_srtdiscipline_omschrijving').value;
        }
        ROFIELDTR("fld", L("lcl_mld_vakgroeptype"), lsrtdisc, {suppressEmpty: true});
        ROCHECKBOXTR("fldcheck", L("lcl_menulevel"), fac_mlevel, {suppressEmpty: true});
        ROCHECKBOXTR("fldcheck", L("lcl_menuportal"), fac_mportal, {suppressEmpty: true});
        ROFIELDTR("fld", L("lcl_menu_fac_url"), fac_malturl, {suppressEmpty: true});
        ROFIELDTR("fld", L("lcl_image"), fac_mimage, {suppressEmpty: true});
        BLOCK_END();
%>
      </form>
    </div>
  </body>
</html>
