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

    File:               fin/fin_edit_note.asp
    Description:        Bekijken en/of aanvullen van een notitie behorende bij een melding
                        in een apart blokje
    Parameters:         fronto/backo
    Context:            vanuit melding-detail/overzicht
    Note:               STATUS: kopie van MLD, en globaal gereplaced; werkt
*/ %>

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

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

var fin_key = getQParamInt("fin_key");

var this_fin = fin.func_enabled_factuur(fin_key); // Wat heb ik zoal aan rechten
user.auth_required_or_abort(this_fin.canWriteNotes);
%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
  <script>
    jQuery(document).ready(function()
           {
             $('textarea').resize(function () { FcltMgr.resized(window) } );
             $('textarea').autogrow();
           });
  </script>
  </head>

<%
  var note_key = getQParamInt("note_key", -1);
  var submitting = getQParamInt("submit", 0) == 1;
  if (submitting)
  {
    var note = getFParam("note", "");
    if (note != "")
    {
        var fields =  [ { dbs: "fin_factuur_key",               typ: "key",     val: fin_key },
                        { dbs: "prs_perslid_key",               typ: "key",     val: user_key },
                        { dbs: "fin_factuur_note_omschrijving", typ: "varchar", frm: "note", len:4000 }
                      ]
        if (note_key == -1)
        {
          var noteIns = buildInsert("fin_factuur_note", fields);
          Oracle.Execute(noteIns.sql);
        }
        else
        {
          var sql = buildUpdate("fin_factuur_note", fields)
                  + " fin_factuur_note_key = " + note_key
                  + " AND prs_perslid_key = " + user_key; // Voorkom dat er een notitie van een ander aangepast wordt.
          Oracle.Execute(sql);
        }
    }
%>
    <script type="text/javascript">
      FcltMgr.closeDetail(window, { refresh: true } );
    </script>
<%
    Response.End;
  }
%>

  <script type="text/javascript">
    function fin_notesubmit()
    { //TODO CheckLengte
      if (!validateForm("u2"))
        return false;
      document.u2.submit();
      return true;
    }

    function fin_notecancel()
    {
      FcltMgr.closeDetail(window, { cancel: true } );
    }
  </script>

  <body id="editbody">
    <div id="edit">
      <form name=u2 method=post action="fin_edit_note.asp?submit=1&fin_key=<%=fin_key%>&note_key=<%=note_key%>">
<%
        var buttons =  [ {title: L("lcl_submit"), icon: "opslaan.png", action:"fin_notesubmit()" },
                         {title: L("lcl_cancel"), icon: "undo.png", action:"fin_notecancel()" }];
        IFRAMER_HEADER(L("lcl_fin_frame_notes"), buttons);
          BLOCK_START("fin_note", L("lcl_fin_note"));
            var note_oms = "";
            if (note_key > -1)
            {
              sql = "SELECT fin_factuur_note_omschrijving"
                  + "  FROM fin_factuur_note"
                  + " WHERE fin_factuur_note_key = " + note_key;
              var oRs = Oracle.Execute(sql);
              note_oms = oRs("fin_factuur_note_omschrijving").value;
            }
            RWTEXTAREATR("note", "fldtxt required", L("lcl_fin_note_new"), note_oms, {html: "rows='4' cols='80'"});
          BLOCK_END();
        IFACE.FORM_END();
%>
      </form>
    </div>

    <div id="result">
<%
      sql = "SELECT n.fin_factuur_note_aanmaak"
          + "     , n.fin_factuur_note_key"
          + "     , pf.prs_perslid_naam_full"
          + "     , n.fin_factuur_note_omschrijving"
          + "  FROM fin_factuur_note n, prs_v_perslid_fullnames_all pf"
          + " WHERE n.prs_perslid_key = pf.prs_perslid_key (+)"
          + "   AND n.fin_factuur_key = " + fin_key
          + (note_key > -1? " AND n.fin_factuur_note_key <> "+note_key : "")
          + " ORDER BY n.fin_factuur_note_aanmaak "
          + (S("mld_note_sort_ascending") == 0 ? "DESC " : "");

      // Toon de overige notes onder het invulveld.
      var rst = new ResultsetTable({ sql: sql,
                                     ID: "notestable",
                                     keyColumn: "fin_factuur_note_key",
                                     noPrint: true,
                                     emptySetString : ""
                                   });

      rst.addColumn(new Column({caption: L("lcl_date_time"), content: "fin_factuur_note_aanmaak", datatype: "datetime"}));
      rst.addColumn(new Column({caption: L("lcl_fin_changedby"), content: "prs_perslid_naam_full"}));
      rst.addColumn(new Column({caption: L("lcl_fin_note"), content: "fin_factuur_note_omschrijving"}));

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