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

     File:               CNT/cnt_show_note.asp
     Description:        Functie bestaand contractrecord toont
     Parameters:         cnt_key              Contract key
     Context:            frame (embedded) in cnt_show_contract/cnt_edit_contract
     Note:               Inspired by mld_show_note.asp ;-)
                         TODO: ik heb WEB_CNTMAN (later: CNTUSE) lees resp. schrijfrechten nodig.

*/%>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/resultset_table_v2.inc" -->
<!-- #include file="./cnt.inc" -->

<%
FCLTHeader.Requires({js: []})

var cnt_key = getQParamInt("cnt_key");
var outputmode = getQParam ("outputmode",0);

var this_cnt = cnt.func_enabled_contract(cnt_key); // Wat heb ik zoal aan rechten op dit contract?
user.auth_required_or_abort(this_cnt.canReadNotes);
%>

<html>
  <head>
<%  FCLTHeader.Generate({outputmode: outputmode}); %>
    <script type="text/javascript">
      function cnt_notechange(cnt_note_key)
      {
        if (FcltMgr.startEdit(window))
          window.location.href = "cnt_edit_note.asp?cnt_key=<%=cnt_key%>" + (cnt_note_key?"&note_key="+cnt_note_key:"") + "&embedded=1"
      }

    </script>
  </head>

  <body class="listbody">
<%
    var buttons = [];
    if (this_cnt.canWriteNotes)
    {
        var sql = "SELECT cnt_contract_note_key, prs_perslid_key"
                + "  FROM cnt_contract_note"
                + " WHERE cnt_contract_key =" + cnt_key
                + " ORDER BY cnt_contract_note_aanmaak DESC";
        var oRs = Oracle.Execute(sql);
        if (!oRs.eof)
        {
          if (oRs("prs_perslid_key").value == user_key)
          {
            buttons.push({title: L("lcl_cnt_note_edit"), icon: "wijzigen.png", action: "cnt_notechange("+oRs("cnt_contract_note_key").value+")", id: "bedit_cnt_note"});
          }
        }
        oRs.Close();
        buttons.push({title: L("lcl_cnt_note_append"), icon: "plus.png", action: "cnt_notechange()", id: "bchange_cnt_note"});
    }

    sql = "SELECT n.cnt_contract_note_aanmaak"
        + ", n.cnt_contract_note_key"
        + ", pf.prs_perslid_naam_full"
        + ", n.cnt_contract_note_omschrijving"
        + " FROM cnt_contract_note n, prs_v_perslid_fullnames_all pf"
        + " WHERE n.prs_perslid_key = pf.prs_perslid_key (+)"
        + " AND n.cnt_contract_key = " + cnt_key
        + " ORDER BY n.cnt_contract_note_aanmaak "
        + (true? "DESC " : "");  // wordt setting (zie UWVA#14408)


    var rst = new ResultsetTable({ sql: sql,
                                   keyColumn: "cnt_contract_note_key",
                                   ID: "notestable",
                                   title: L("lcl_mld_frame_notes"),
                                   outputmode: outputmode,
                                   buttons: buttons,
                                   emptySetString : L("lcl_cnt_note_emptyset")
                                 });

    rst.addColumn(new Column({caption: L("lcl_date_time"), content: "cnt_contract_note_aanmaak", datatype:"datetime"}));
    rst.addColumn(new Column({caption: L("lcl_mld_changedby"), content: "prs_perslid_naam_full"}));
    rst.addColumn(new Column({caption: L("lcl_mld_note"), content: "cnt_contract_note_omschrijving"}));

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