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

    File:               prs_obligations.asp
    Description:        Toont alle verplichtingen van een persoon
    Parameters:         prs_key
    Context:            embedded in prs_perslid frame
    Noot:

*/ %>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/json2.js" -->
<!-- #include file="../Shared/resultset_table_v2.inc" -->
<!-- #include file="prs.inc" -->
<%
FCLTHeader.Requires({ js: ["../PRS/prs_obligations.js", "jquery-ui.js"] });

var prs_key = getQParamInt("prs_key");
var outputmode = getQParamInt("outputmode", 0);
var showall = getQParamInt("showall", 0) == 1;

// De functie checkAutorisation(autfunction) geeft een Response.End indien er geen autorisatie voor autfunction wordt gevonden
var authparams = user.checkAutorisation("WEB_PRSUSE");
var authparamsPRSMAN = user.checkAutorisation("WEB_PRSMAN", true);

var prsauthparams = prs.checkAutorisation(prs_key);
//user.auth_required_or_abort(prsauthparams.writeman || prsauthparams.writeuse || prsauthparams.writeself);


%>

<html>
  <head>
<%  FCLTHeader.Generate({outputmode: outputmode}); %>
    <script type="text/javascript">
      var prs_key = <%=prs_key%>;
    </script>
  </head>

  <body>
    <form id="verplichtform" name="verplichtform">
      <input type="hidden" id="messagecodes" name="messagecodes" value="">
      <input type="hidden" id="item_keys" name="item_keys" value="">
    </form>
<%  var sql = "SELECT DISTINCT xmlnode" // DISTINCT omdat prs_v_verplichting besteller en besteller_voor op een hoop gooit
            + ", pv.item"
            + ", pv.item_key"
            + ", pv.fac_message_code"
            + " FROM prs_v_verplichting pv"
            + ", prs_perslid p"
            + " WHERE p.prs_perslid_key = pv.prs_perslid_key"
            + " AND pv.prs_perslid_key = " + prs_key
            + " ORDER BY 1, 2, 3";

    // Extra data voor de client om daar dynamisch buttons te kunnen activeren.
    function fnrowData(oRs)
    {
      var xmlnode = oRs("xmlnode").value;
      var item = oRs("item").value;
      var messagecode = oRs("fac_message_code").value;
      data = {xmlnode: xmlnode, item: item, messagecode: messagecode};
      return JSON.stringify(data);
    }

    function fnItem (oRs)
    {
      return oRs("item");
    }

    function fnObligation (oRs)
    {
      var message_code = oRs("fac_message_code").value;
      var message_text = L(message_code);
      return message_text;
    }

    function fnrowActionEnabler(oRs)
    {
      var xmlnode = oRs("xmlnode").value;

      var eEdit = false;
      var eTransfer = false;
      switch(xmlnode)
      {
        case null:
        case "afspraak":
        case "bestelling":
        case "deel":
        case "melding":
        case "reservering":
        case "contract":     {
                               eEdit = true;                 
                               eTransfer = true;
                               break;
                             }
      }

      var data = {eTransfer: eTransfer};
      return data;
    }
    var buttons = [{ icon: "page_refresh.png", title: L("lcl_refresh"), action: "FcltMgr.reload()" }];

    var rst = new ResultsetTable({ sql: sql,
                                   keyColumn: "item_key",   //dummy
                                   ID: "verplichttable",
                                   showAll: showall,
                                   outputmode: outputmode,
                                   rowData: fnrowData,
                                   rowActionEnabler: fnrowActionEnabler,
                                   title: L("lcl_prs_obligations"),
                                   buttons: buttons
                                 });

    rst.addColumn(new Column({caption: L("lcl_prs_obligation"), content: fnObligation}));
    rst.addColumn(new Column({caption: L("lcl_prs_details"), content: fnItem}));

    if (prsauthparams.writeuse)
    {
      rst.addAction({ action: "prs_edit", caption: L("lcl_edit"), isDefault: true});
      if (authparamsPRSMAN)
      {
        rst.addAction({ action: "prs_transfer", caption: L("lcl_prs_transfer_opvolger"), enabler: "eTransfer", multi: true, multiOnce: true});
      }
    }

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