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

    File:               opdr_show_note.asp
    Description:        Toont een overzicht van de notes die aan het filter voldoen
                        Dit zal alleen zijn als Behorend bij een bepaalde opdracht
    Parameters:         opdr_key

    Note:


*/
var opdr_key = getQParamInt("opdr_key");
var LOCKED_USER_OK = { "xmlnode": "opdracht", "key": opdr_key };
%>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/status.inc"-->
<!-- #include file="./mld.inc" -->
<!-- #include file="../Shared/resultset_table_v2.inc" -->
<%
FCLTHeader.Requires({ })

var urole = getQParamSafe("urole", "fe");
var embedded = getQParamInt("embedded", -1);
var outputmode = getQParamInt("outputmode", 0);
var showall = getQParamInt("showall", 0) == 1;
var tracking = getQParamInt("tracking", 1) == 1; // tracking erbij tonen? Onderdrukken met 0

cache.whenNoRecords("SELECT 1 FROM mld_opdr_note WHERE mld_opdr_key = " + opdr_key);

var this_opdr = mld.func_enabled_opdracht(opdr_key); // wat mag ik zoal op deze opdracht
user.auth_required_or_abort(this_opdr.canShowOpdrNote);

mld_opdr = this_opdr.mld_opdr;
lcl.set_dialect(mld_opdr.opdr_type, "MLD_TYPEOPDR_KEY");

%>
<html>
<head>
<%  FCLTHeader.Generate({outputmode: outputmode}); %>
   <script type='text/javascript'>
        function persoonDetails(evt, perslid_key)
        {
            FcltMgr.stopPropagation(evt);
            FcltMgr.openDetail("appl/fac/fac_user.asp?prs_key=" + perslid_key);
        }
        function opdr_notechange(opdr_note_key)
        {
            if (FcltMgr.startEdit(window))
                window.location.href = "opdr_edit_note.asp?urole=<%=urole%>&opdr_key=<%=opdr_key%>" + (opdr_note_key?"&note_key="+opdr_note_key:"") + "&embedded=<%=embedded%>"
        }
   </script>
</head>

<body id="listbody">
<%
    SUBFRAME_START();
    function fnPerslidNaamFull(oRs)
    {
        var html = "<span class='details' onclick='persoonDetails(event,"+ oRs("prs_perslid_key").Value +")'>"
                 + safe.html(oRs("prs_perslid_naam_full").Value)
                 + "</span>";

        return html;
    }

    var buttons = [];
    buttons.push({ icon: "fa-fclt-refresh", title: L("lcl_refresh"), action: "FcltMgr.reload()" });

    if (this_opdr.canEditOpdrNote) // Manual allowed
    {
      var sql = "SELECT mld_opdr_note_key, prs_perslid_key"
              + "  FROM mld_opdr_note"
              + " WHERE mld_opdr_key =" + opdr_key
              + " ORDER BY mld_opdr_note_aanmaak DESC";
      var oRs = Oracle.Execute(sql);
      if (!oRs.eof)
      {
         if (user.isCollega(oRs("prs_perslid_key").Value))
         {
            buttons.push({title: L("lcl_change"), icon: "fa-fclt-edit", action: "opdr_notechange(" + oRs("mld_opdr_note_key").Value + ")", id: "bedit_opdr_note"});
         }
      }
      oRs.Close();
      buttons.push({title: L("lcl_add"), icon: "fa-plus", action:"opdr_notechange()", id:"bchange_opdr_note" });
    }

    function fnrowClass(oRs)
    {
        var rclass = ""
        if (oRs("prs_perslid_key").Value == user_key)
            rclass = rclass + "self";
        if (oRs("fac_srtnotificatie_code").Value)
            rclass = rclass + " trtrack";
        else
            rclass = rclass + " trnote";
        return rclass;
    }

    function fnOmschrijving(oRs)
    {
        var html = "";
        if (oRs("mld_opdr_note_omschrijving").Value)
        {
            html = safe.mldlinkhtml(safe.html(oRs("mld_opdr_note_omschrijving").Value));
            html = safe.cntlinkhtml(html);
            if (outputmode != 0)
                html = shared.stripbbcodes(html);
        }
        else if (oRs("fac_srtnotificatie_code").Value)
            html = status.getsrtnotificatietext(oRs("fac_srtnotificatie_code").Value);

        return html;
    }

   var sql = "SELECT n.mld_opdr_note_aanmaak"
           + ",      n.mld_opdr_note_key"
           + ",      pf.prs_perslid_key"
           + ",      pf.prs_perslid_naam_full"
           + ",      n.mld_opdr_note_omschrijving"
           + ",      NULL fac_srtnotificatie_code"
           + "  FROM mld_opdr_note n, prs_v_perslid_fullnames_all pf"
           + " WHERE n.prs_perslid_key = pf.prs_perslid_key (+)"
           + "   AND n.mld_opdr_key = " + opdr_key;
   var sqls = [sql];

   if (tracking)    // tracking info erbij?
   {
        var sql = "SELECT tr.fac_tracking_datum"
                + "     , tr.fac_tracking_key"
                + "     , tr.prs_perslid_key"
                + "     , pf.prs_perslid_naam_friendly"
                + "     , tr.fac_tracking_oms"
                + "     , str.fac_srtnotificatie_code"
                + "  FROM fac_tracking tr, fac_srtnotificatie str, prs_v_perslid_fullnames_all pf"
                + " WHERE tr.fac_srtnotificatie_key = str.fac_srtnotificatie_key"
                + "   AND tr.prs_perslid_key = pf.prs_perslid_key (+)"
                + "   AND (tr.fac_tracking_refkey = " + opdr_key
                + "   AND str.fac_srtnotificatie_xmlnode IN ('opdracht'))";
        sqls.push(sql);
   }
   var desc = (S("mld_note_sort_ascending") == 0 ? " DESC " : "");
   sql = "SELECT * FROM ("+ sqls.join(" UNION ") + ") ORDER BY 1 {0}, 2 {0}".format(desc)

    var pageTitle = this_opdr.mld_opdr.opdr_type_omschr + " " + (this_opdr.mld_opdr.srtdiscprefix || "") + this_opdr.mld_opdr.mld_key + "/" + this_opdr.mld_opdr.volgnr;
    var rst = new ResultsetTable({ sql:sql,
                                   keyColumn: "mld_opdr_note_key",
                                   noPrint:(embedded != -1),
                                   ID: "notestable",
                                   buttons: buttons,
                                   title: (opdr_key == -1 || !tracking ? L("lcl_opdr_frame_notes"): L("lcl_opdr_frame_trackandnotes")) + " " + pageTitle,
                                   rowClass: fnrowClass,
                                   outputmode: outputmode,
                                   showAll: showall,
                                   emptySetString : L("lcl_mld_note_emptyset")
                                 });

    rst.addColumn(new Column({caption: L("lcl_date"), content: "mld_opdr_note_aanmaak", datatype:"date", prettydate: true, nowrap: true}));
    rst.addColumn(new Column({caption: L("lcl_time"), content: "mld_opdr_note_aanmaak", datatype:"time"}));
    rst.addColumn(new Column({caption: L("lcl_mld_changedby"), content: fnPerslidNaamFull}));
    rst.addColumn(new Column({caption: L("lcl_mld_note"), content: fnOmschrijving}));

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