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

     File:        mld_fe_menu.asp
     Description: Alternatieve interface om (eenvoudig) een melding te kunnen kiezen
                  Veronderstelt wel dat er niet al te schrikbarend veel meldingen zijn.
     Parameters:  lvl: het groeperingslevel,
                        1=vakgroep (default)
                        0=vakgroeptype
                        2=mld_stdmeldinggroep
                        n= als 1

     Context:     -
     Note:        -

*/%>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../shared/iface.inc" -->
<%
FCLTHeader.Requires({ plugins: ["jQuery"],
                      js: ["jQuery-ui.js"]
                    });

var disckeyArr = getQParamIntArray("disc", []);
var srtdisckeyArr = getQParamIntArray("srtdisc", []);
var stdmgroepkeyArr = getQParamIntArray("stdmgroepkey",[]);
var lvl = getQParamInt("lvl", 1);
%>
<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script type="text/javascript">
        function run_create_mld (p_srtdisc, p_mld_stdkey)
        {
   			FcltMgr.openDetail('appl/mld/mld_melding.asp?urole=fe&srtdisc=' + p_srtdisc + '&mld_defaultstdmelding=' + p_mld_stdkey,L("lcl_complain"));
	    }

         $(function ()
         {  // Noot: vrijwel identieke code te vinden in bes_fe_menu.asp
            var accord = $('#accordion');
            var nnheads = accord.children("h3").length; // Voordat accordion de DOM heeft aangepast

            accord.accordion({collapsible: true,
                              active: false,
                              heightStyle: "content",
                              activate: FcltMgr.resized,
                              beforeActivate: function(event, ui)
                                  {   // delay load images
                                      $("img", ui.newPanel).each(function ()
                                              {
                                                  this.src = this.getAttribute("theSrc");
                                              }
                                           );
                                  }
                              });

            if (nnheads == 1) // Dan direct openklappen
                accord.accordion({ active: 0 });
         });
    </script>
  </head>

<body id="iconbody">
<%
    var buttons =  [];
    IFRAMER_HEADER(L("lcl_mld_fe_menu_frame"), buttons);
%>
<div id='accordion'>
<%
var sql = "SELECT sm.mld_stdmelding_key,"
        + "       "+lcl.xsqla('sm.mld_stdmelding_omschrijving','sm.mld_stdmelding_key') + ","
        + "       "+lcl.xsqla('sm.mld_stdmelding_hint','sm.mld_stdmelding_key') + ","
        + "       "+lcl.xsqla('d.ins_discipline_omschrijving', 'd.ins_discipline_key') + ","
        + "       "+lcl.xsqla('sd.ins_srtdiscipline_omschrijving', 'sd.ins_srtdiscipline_key') + ","
        + "       "+lcl.xsqla('mg.mld_stdmeldinggroep_naam','mg.mld_stdmeldinggroep_key') + ","
        + "       sm.mld_stdmeldinggroep_key,"
        + "       d.ins_discipline_key,"
        + "       sd.ins_srtdiscipline_key,"
        + "       ins_srtdiscipline_prefix,"
        + "       mld_stdmelding_image foto"
        + "  FROM mld_stdmelding sm,"
        + "       mld_stdmeldinggroep mg,"
        + "       mld_discipline d,"
        + "       ins_srtdiscipline sd,"
        + "       fac_v_webgebruiker fvw,"
        + "       fac_functie f"
        + " WHERE     mld_stdmelding_notfrontend = 0"
        + "       AND mld_stdmelding_verwijder IS NULL"
        + "       AND d.ins_discipline_key = sm.mld_ins_discipline_key"
        + "       AND sd.ins_srtdiscipline_key = d.ins_srtdiscipline_key"
        + "       AND fvw.ins_discipline_key = d.ins_discipline_key"
        + "       AND sm.mld_stdmeldinggroep_key = mg.mld_stdmeldinggroep_key (+)"
        + "       AND fvw.fac_functie_key = f.fac_functie_key"
        + "       AND fvw.fac_gebruiker_alg_level_write < 9"
        + "       AND fvw.fac_gebruiker_prs_level_write < 9"
        + "       AND f.fac_functie_code = 'WEB_MLDUSE'"
        + "       AND sd.ins_srtdiscipline_key <>" + S("kto_srtdiscipline_key")
        + "       AND fvw.prs_perslid_key = " + user_key
        + "       AND (sm.mld_stdmelding_vervaldatum IS NULL OR"
        + "            sm.mld_stdmelding_vervaldatum > SYSDATE)";

if (lvl == 2) { // Geen lege groepen tonen
      sql += " AND sm.mld_stdmeldinggroep_key IS NOT NULL";
}

if (disckeyArr.length){
      sql += " AND d.ins_discipline_key IN (" + disckeyArr.join(",") + ")";
}
if (srtdisckeyArr.length){
      sql += " AND d.ins_srtdiscipline_key IN (" + srtdisckeyArr.join(",") + ")";
}
if (stdmgroepkeyArr.length){
      sql += " AND sm.mld_stdmeldinggroep_key IN (" + stdmgroepkeyArr.join(",") + ")";
}
switch (lvl) {
    case 2: {
            sql+= "       ORDER BY " + lcl.xsql('mg.mld_stdmeldinggroep_naam','mg.mld_stdmeldinggroep_key')
                             + " , mld_stdmelding_volgnr, " + lcl.xsql('sm.mld_stdmelding_omschrijving','sm.mld_stdmelding_key');
            break;
        }
    case 0: {
         sql+= "       ORDER BY " + lcl.xsql('sd.ins_srtdiscipline_omschrijving', 'sd.ins_srtdiscipline_key')
                             + " , mld_stdmelding_volgnr, " + lcl.xsql('sm.mld_stdmelding_omschrijving','sm.mld_stdmelding_key');
            break;
        }
    default: {
         sql+= "       ORDER BY " + lcl.xsql('d.ins_discipline_omschrijving', 'd.ins_discipline_key')
                             + " , mld_stdmelding_volgnr, " + lcl.xsql('sm.mld_stdmelding_omschrijving','sm.mld_stdmelding_key');
    }
}
var oRs=  Oracle.Execute(sql)
var last_disc = -1;
var last_grp = "#initial#";
while (!oRs.Eof)
{

switch (lvl) {
    case 2: {
        if (last_grp != oRs("mld_stdmeldinggroep_key").Value)
        {   // Groep header
            %>
             <h3><a><%=L("lcl_fe_menu_stdmeldinggroep")+" "+safe.html(oRs("mld_stdmeldinggroep_naam").Value)%></a></h3>
                <div style='display:none'>
                    <table width="100%"><tr>
            <%
            pos = 0;
        }
        break;
    }
    case 0: {
        if (last_disc != oRs("ins_srtdiscipline_key").Value)
        {   // Vakgroeptype header
            %>
             <h3><a><%=L("lcl_fe_menu_srtdiscipline")+" "+safe.html(oRs("ins_srtdiscipline_omschrijving").Value)%></a></h3>
                <div style='display:none'>
                    <table width="100%"><tr>
            <%
            pos = 0;
        }
        break;
    }
    default: {
        if (last_disc != oRs("ins_discipline_key").Value)
        {   // Vakgroep header
            var prefix = (oRs("ins_srtdiscipline_prefix").Value==null || srtdisckeyArr.length==1)?"":oRs("ins_srtdiscipline_prefix").Value+"-";
            %>
             <h3><a><%=L("lcl_fe_menu_discipline")+" "+safe.html(prefix+oRs("ins_discipline_omschrijving").Value)%></a></h3>
                <div style='display:none'>
                    <table width="100%"><tr>
            <%
            pos = 0;
        }
    }
}
    // Wel erg hard...
    if (oRs("foto").Value)
        var url = S("mlds_image_path") + (oRs("foto").Value);
    else
        var url = "../Pictures/mld_stdm_default.jpg";

  	var maxcol = S("iconcolumns");
  	if (pos > 0 && pos%maxcol == 0) {
  	    %></tr><tr><%
    }
    %><td class='iconmenu' width='<%=Math.floor(100/maxcol)%>%'
          title='<%=safe.htmlattr(oRs("mld_stdmelding_hint").Value || oRs("mld_stdmelding_omschrijving").Value)%>'
          onclick='run_create_mld (<%=oRs("ins_srtdiscipline_key").Value%>,<%=oRs("mld_stdmelding_key").Value%>);'>
       <img theSrc='<%=safe.htmlattr(url)%>'>
       <div class="iconlabel"><%=safe.html(oRs("mld_stdmelding_omschrijving").value) %></div>
      </td><%
    pos ++;
    last_disc = (lvl==1 ? oRs("ins_discipline_key").Value : oRs("ins_srtdiscipline_key").Value);
    last_grp = (lvl==2 ? oRs("mld_stdmeldinggroep_key").Value : 0);
    oRs.MoveNext();
    if (oRs.Eof
       || (lvl==0 && last_disc !=  oRs("ins_srtdiscipline_key").Value)
       || (lvl==2 && last_grp != oRs("mld_stdmeldinggroep_key").Value)
       || (lvl!=0 && lvl!=2 && last_disc != oRs("ins_discipline_key").Value ))
    { %>
       </tr></table></div>
       <%
    }
}
%>
    </div>
</body>
</html>

