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

     File:          fac_user_messages.asp (formerly news/news.asp)
     Description:   Toont de gebruikersberichten (statusinfo) in een grid

    Note:           Niet erg gewijzigd, wel wat harde aannames toegevoegd,
                    Functioneel is de noodzaak voor deze info veel minder
                    geworden vanwege fac_list die veel meer info toont.

                    Geen resulttable hier, bij uitzondering

*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<%
  FCLTHeader.Requires({ plugins: ["jQuery"],
                        js: ["./fac_user_messages.js"] });
%>
<html>
  <head>
<%  FCLTHeader.Generate() %>
  </head>

  <body class="listbody" id="usermessbody">
<%  var buttons = [];
    buttons.push({title: L("lcl_mark_as_read_all"), icon: "bin_closed.png", action: "MarkAsReadAll()"});
    IFRAMER_HEADER(L("lcl_recent_news"), buttons); %>

    <table id="usermess" width='100%'>
<%    if (user_key != -1)
      {
        var sql = "SELECT m.web_user_mess_dsc"
                + ",     sn.fac_srtnotificatie_url"
                + ",     COALESCE(m.web_user_mess_action_params, ' ') web_user_mess_action_params"
                + ",     m.web_user_mess_action_status"
                + ",     m.web_user_mess_action_datum"
                + ",     m.web_user_message_key"
                + ",     web_user_mess_prioriteit"
                + " FROM web_user_messages m, fac_srtnotificatie sn"
                + " WHERE (m.prs_perslid_key_receiver = " + user_key
                + "    OR m.prs_perslid_key_receiver IS NULL) "   // General messages
                + " AND sn.fac_srtnotificatie_key(+)=m.fac_srtnotificatie_key"
                + " ORDER BY m.web_user_mess_action_datum DESC, m.web_user_message_key DESC";

        // Tweeledig: beperken, maar tevens zorgen dat de sortering goed blijft!
        // Dat is: de nieuwste berichten bovenaan
        sql = "SELECT * FROM (" + sql + ") WHERE ROWNUM < " + S("portalnewsmax");
        oRs = Oracle.Execute(sql);

        while (!oRs.eof)
        {
          var isNew = oRs("web_user_mess_action_status").Value == 1;

          if (oRs("fac_srtnotificatie_url").Value != null )
          {
            var action = oRs("fac_srtnotificatie_url").Value + oRs("web_user_mess_action_params").Value;
            action = action.replace(/\#/g, "&");
            if (action.indexOf("&urole") < 0)
                action += "&urole=fe";
          }
          else
            var action = false;

          var headline=oRs("web_user_mess_dsc").value;
          var headlinetitle = ""
          if (action)
          {
            // limit the length if it is too long and the user may click on it
            if (headline.length > S("portalnewslength"))
            {
              headlinetitle = headline;
              headline = headline.substr(0,S("portalnewslength"))+'...';
            }
          }
%>        <tr messKey=<%=oRs("web_user_message_key")%> class="<% = (isNew ? (oRs("web_user_mess_prioriteit").value==1?'newstextFreshRed':'newstextFresh') : 'newstext')%>">
            <td class="markread"
                title="<%=L("lcl_mark_as_read")%>"
                onClick="MarkAsRead(<%=oRs("web_user_message_key")%>, <%=isNew?1:0%>, 1)">
            </td>
            <td class="usermsgdate"><%=toDateTimeString(new Date(oRs("web_user_mess_action_datum").value), false, false, true)%></td>
            <td class="usermessage"><%
          if (action)
          {
%>          <a class="<%=(isNew ? (oRs("web_user_mess_prioriteit").value==1?'newstextFreshRed':'newstextFresh') : 'newstext')%>"
               onclick='DoAction("<%=oRs("web_user_message_key").Value%>","<%=isNew?'true':'false'%>","appl/<%=safe.htmlattr(action)%>")'
               title="<%=safe.htmlattr(headlinetitle)%>"
               target="_parent"><% = safe.html(headline) %></a><%
          }
          else
          {
            Response.Write(safe.html(headline));
          }
%>        </td></tr><%
          oRs.MoveNext();
        }
      }
%>
    </table>
  </body>
</html>
