<%@ 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"-->
<%
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 messageReply() {
  // let the user construct a reply
  window.location = 'msg_edit_message.asp?urole=<%=urole%>&message_key=<%=message_key%>';

}
      jQuery(document).ready(function()
                             {
                               $('textarea').resize(function () { FcltMgr.resized(window) });
                               $('textarea').autogrow();
                             });

</script>
</head>

<body id="editbody">
    <%
        buttons = [];
        if (S("msg_reply_enabled") == '1' /*&& user.checkAutorisation("WEB_MSGUSE", true)*/ && !message_answer ) // Op een antwoord kan ik nooit antwoorden
            buttons.push({ icon: "email.png", title: L("lcl_mes_send_reply"), action: 'messageReply()' });

        IFRAMER_HEADER(L("lcl_mes_message"), buttons);
    %>
    <div id="show">
    <form name="u2"  onSubmit="return false;">
    <%
      BLOCK_START("msgMessage", L("lcl_mes_message"));
    %>
    <tr>
        <td class="label"><label><%=L("lcl_from")%>:</label></td>
        <td><input value="<%=safe.htmlattr(sender_name)%>" type="text" id="receiver" readonly></td>
        <td class="label"><label><%=L("lcl_mes_send_date_time")%>:</label></td>
        <td><input class="flddatetime" value="<%=toDateTimeString(action_datum)%>" type="text" id="time" readonly></td>
    </tr><tr>
        <td class="label"><label><%=L("lcl_mes_subject")%>:</label></td>
        <td>
          <input class="fldmsgsubj" value="<%=safe.htmlattr(subject)%>" type="text" id="subject0" name="subject0"  readonly>
        </td>
        <td class="label"><label><%=L("lcl_mes_priority")%>:</label></td>
        <td><input class="fldmsgprio" value="<%=priority%>" type="text" id="priority0" name="priority0" readonly></td>
      </tr>

<%
      ROTEXTAREATR("fldmsgmessage",
                   (message_answer ? L("lcl_mes_message_received_back") : L("lcl_mes_message_received")),
                   mess_dsc,
                   {id: "ta_message0",
                    tdhtml_ta: "colspan='4'"});

       if (message_answer) {
         ROTEXTAREATR("fldmsgmessage",
                      L("lcl_mes_message_send"),
                      ref_mess_dsc,
                      {id: "ta_message00",
                       tdhtml_ta: "colspan='4'"});
        }
        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"><%=ilink%></a></td>
      </tr>
    <% }

     %>
      </div>
    </td>
    </tr>

    </form>
    </div>
</body>
</html>
