<%@ LANGUAGE = JavaScript %>
<% /*
    $Revision$
    $Id$

    File:               msg_show_message.asp
    Description:        Toonscherm voor berichten
    Parameters:         message_key
                        -
    Context:
    Note:               Af en toe is ook nog een reply mogelijk

*/ %>
<!-- #include file="../Shared/common.inc"-->
<!-- #include file="../Shared/iface.inc"-->
<!-- #include file="../Shared/FlexFiles.inc"-->
<%
FCLTHeader.Requires({plugins:["suggest"]});


var urole = getQParamSafe("urole");
var backo = urole=="bo";                     // voor nieuwe berichten
var frontend = (urole == "fe" || !backo );   // voor replies

var message_key    = getQParamInt("message_key", -1);
var subject;
var ilink;

  // message known, existing, so read or reply

  sql =   " SELECT m.prs_perslid_key"
        + ", m.msg_message_oms"
        + ", m.msg_message_aanmaak"
        + ", m.msg_message_replykey"
        + ", m.msg_message_onderwerp"
        + ", m.msg_message_prioriteit"
        + ", m.msg_message_url"
        + ", pf.prs_perslid_naam_full"
        + " FROM   msg_message m, prs_v_perslid_fullnames_all pf"
        + " WHERE  msg_message_key = " + message_key
        + " AND m.prs_perslid_key = pf.prs_perslid_key";
  oRsMes = Oracle.Execute(sql);
  if (!oRsMes.eof ) {
      key_sender   = oRsMes("prs_perslid_key").value;
      mess_dsc     = oRsMes("msg_message_oms").value;
      action_datum = oRsMes("msg_message_aanmaak").value;
      ref_mess_key = oRsMes("msg_message_replykey").value;
      subject      = oRsMes("msg_message_onderwerp").value;
      priority_key = oRsMes("msg_message_prioriteit").value;
      ilink        = oRsMes("msg_message_url").value;
      sender_name  = oRsMes("prs_perslid_naam_full").value;
  } else {
    Response.write("internal error or message deleted");
    Response.End;
  }
  receiver_key = user_key;  // that's me of course
  ref_mess_dsc = "";
  message_answer = (ref_mess_key != null);
  // prio: number to text
  if (priority_key == 1)
    priority = L("lcl_mes_high");
  else if (priority_key == 2) priority = L("lcl_mes_normaal");
  else priority = L("lcl_mes_low");

  oRsMes.Close();

  if (message_answer) { // originele bericht er ook bij halen
      sql =   " SELECT m.msg_message_oms"
            + " FROM   msg_message m"
            + " WHERE  m.msg_message_key = " + ref_mess_key
            + " ORDER BY m.msg_message_key desc";
      oRsMes = Oracle.Execute(sql);

      if (!oRsMes.eof) {
        ref_mess_dsc = oRsMes("msg_message_oms").value;
      }
      oRsMes.Close();
  }


  // Goed bepalen: welke rechten veris ik eigenlijk?
  // - BOF/USE -write  om aan te maken
  // - USE read om te lezen  (of is niks voldoende?)
  // - USE write om te replyen

%>
<html>
<head>
<%
   FCLTHeader.Generate();
%>
<script type="text/javascript">

  $(function()
  {
    FcltMgr.setTitle(L("lcl_mes_message"), {hot: false});
    $('textarea').resize(function () { FcltMgr.resized(window) });
    $('textarea').autogrow();
  });

</script>
</head>

<body class="showmode">
    <%
    SUBFRAME_START();
    buttons = [];
    IFRAMER_HEADER(L("lcl_mes_message"), buttons);

    BLOCK_START("msgDetails", L("lcl_details"), { icon: "fa-calendar" });
      ROFIELDTR("fld", L("lcl_mes_send_date_time"), toDateTimeString(action_datum));
      ROFIELDTR("fld", L("lcl_mes_priority"), priority);
    BLOCK_END();

    BLOCK_START("msgMessage", L("lcl_mes_message"), { icon: "fa-envelope", wide: true });
      ROFIELDTR("fld", L("lcl_from"), sender_name);
      ROFIELDTR("fld", L("lcl_mes_subject"), subject);
      ROTEXTAREATR("fldtxt", (message_answer ? L("lcl_mes_message_received_back") : L("lcl_mes_message_received")), mess_dsc,
                   { "file_params": { "module": "MES", "key": message_key }});

      if (message_answer)
      {
         ROTEXTAREATR("fldtxt", L("lcl_mes_message_send"), ref_mess_dsc, { id: "ta_message00" });
      }
      if (ilink != null) {
%>
      <tr>
        <td class="label"><label><%=L("lcl_mes_link")%></label></td>
        <td colspan="3"><a class="fldmsgurl" href="<%=safe.htmlattr(ilink)%>" target="_blank" rel="noopener noreferrer"><%=safe.html(ilink)%></a></td>
      </tr>
<%    }

     %>
    </td>
    </tr>

<%    BLOCK_END();
      SUBFRAME_END(); %>
</body>
</html>
<% ASPPAGE_END(); %>
