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

<!--#include file="../Shared/common.inc"-->
<!--#include file="../Shared/resultset_table_v2.inc" -->
<!--#include file="../bez/bez.inc" -->
<!--#include file="../mld/mld.inc" -->
<%
FCLTHeader.Requires({ plugins:[],
                      js: ["../mld/mld_list.js"]});

var mld_opdr_key = getQParamInt("mld_opdr_key");
var urole = getQParamSafe("urole");

var this_opdr = mld.func_enabled_opdracht(mld_opdr_key); // faalt eventueel
user.auth_required_or_abort(this_opdr.canReadAny);

var autfunction = ["WEB_BEZUSE"]; // Lopende zaken worden alleen getoond.
var authparams = user.checkAutorisation(autfunction);

%>
<html>
    <head>
<%
   FCLTHeader.Generate();
%>
      <script type="text/javascript">
        function bez_add()
        {
          FcltMgr.openDetail("appl/bez/bez_afspraak.asp?urole=<%=urole%>&mld_opdr_key=<%=mld_opdr_key%>",  L("lcl_vis_appointment"));
        }

        function bez_edit(row)
        {
          $(row).addClass('dirty');
          var afspr_key = row.getAttribute("ROWKEY");
          url = "appl/bez/bez_afspraak.asp?urole=<%=urole%>&afspr_key=" + afspr_key;
          FcltMgr.openDetail(url, { reuse: true });
        }

      </script>
    </head>
<body id="listbody">
<%
  function fncolStatus(oRs)
  {
    return mld.getmldstatustext(oRs("mld_melding_status").Value);
  }

  // Workflow Details for Root call of a workflow sequence
  // Or follow-up calls for this one
  sql = "SELECT ba.bez_afspraak_key"
      + "     , ba.bez_afspraak_datum"
      + "     , ba.bez_afspraak_eind"
      + (S("vis_afspraak_host_uses_keys") == 1
        ? "   , (SELECT prs_perslid_naam_full"
          + "      FROM prs_v_perslid_fullnames_all"
          + "     WHERE prs_perslid_key = bez_afspraak_host_key)"
        : "   , ba.bez_afspraak_gastheer") + " gastheer"
      + (S("vis_afspraak_onrgoed_uses_keys") == 1
        ? "   , (SELECT alg_plaatsaanduiding"
          + "      FROM alg_v_onroerendgoed_gegevens"
          + "     WHERE alg_onroerendgoed_keys = ba.alg_onrgoed_keys)"
        : "   , ba.bez_afspraak_ruimte") + " ruimte"
      + "  FROM bez_afspraak ba"
      + " WHERE mld_opdr_key = " + mld_opdr_key
      + " ORDER BY ba.bez_afspraak_datum";

    buttons = [];

    if (authparams.ALGwritelevel < 9 || authparams.PRSwritelevel < 9)
        buttons.push({ title: L("lcl_add"), icon: "fa-plus", action:"bez_add()", tooltip: L("lcl_continue_hint") });
    buttons.push({ icon: "fa-fclt-refresh", title: L("lcl_refresh"), action: "FcltMgr.reload()" });


    var rst = new ResultsetTable({ sql: sql,
                                   keyColumn: "bez_afspraak_key",
                                   ID: "appointmenttable",
                                   buttons: buttons,
                                   title: L("lcl_bez_appointments")
                                 });

    var plaatslcl = "";
    if (S("vis_afspraak_onrgoed_uses_keys") == 0)
    {
      switch (S("vis_mandatory_alg_level"))
      {
        case "L" :  plaatslcl = L("lcl_location"); break;
        case "G" :  plaatslcl = L("lcl_building"); break;
        case "V" :  plaatslcl = L("lcl_floor"); break;
        case "R" :  plaatslcl = L("lcl_room"); break;
      }
    }
    else
    {
      switch (S("vis_show_alg_level"))
      {
          case "L": plaatslcl = L("lcl_location"); break;
          case "G": plaatslcl = L("lcl_building"); break;
          case "V": plaatslcl = L("lcl_floor"); break;
          case "R": plaatslcl = L("lcl_room"); break;
      }
    }

    rst.addColumn(new Column({caption: L("lcl_date"), content: "bez_afspraak_datum", datatype: "date"}));
    rst.addColumn(new Column({caption: L("lcl_vis_start_date"), content: "bez_afspraak_datum", datatype: "time"}));
    rst.addColumn(new Column({caption: L("lcl_vis_end_date"), content: "bez_afspraak_eind", datatype: "time"}));
    rst.addColumn(new Column({caption: plaatslcl, content: "ruimte"}));
    rst.addColumn(new Column({caption: L("lcl_vis_appointment"), content: "bez_afspraak_key"}));
    rst.addColumn(new Column({caption: L("lcl_vis_visit"), content: "gastheer"}));

    rst.addAction({action: "bez_edit", caption: L("lcl_edit"), isDefault: true});

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