<%# requirements: project, report, email_notification, 
                  use_cookie, show_form, params, errors %>

<h2>Current status</h2>

<table>
  <% report.each_attr do |etype| %>
  <%  next if etype['hide_from_guest'] && Mode::GUEST.current? %>
  <tr>
    <th><%= etype.name.html_value() %></th>
    <td><%= report.element(etype.id).html_value() %></td>
  </tr>
  <% end %>

  <tr>
    <th>Created</th>
    <td><span class="date"><%= report.create_time.html_value() %></span></td>
  </tr>

  <tr>
    <th>Last modified</th>
    <td><span class="date"><%= report.modify_time.html_value() %></span></td>
  </tr>
</table>


<h2>Log</h2>

<% report.each_with_index do |message, i| %>
<div>
  <% msg_num = (i + 1).to_s %>
  <div class="message-header">
    <% params = {'name' => msg_num} %>
    <% msg_num_str = %Q!<span class="message-header">#{msg_num}</span>! %>
    <%= report.href(msg_num_str, {}, "##{msg_num}", 'message-header', params) %> | 
    <%= message.log_header() %>
  </div>
  <div class="message-body">
    <%= message.body.html_value() %>
  </div>
  
  <% message.each_fileelement do |felement| %>
  <%   next if felement.value.to_s.empty?
       felement.file_descs.each do |desc|   
         name, mtype, size, params = desc  
	 url = CGIApplication.instance.mode.url
         view_url = 'View'.href(url, params)
          
         params['d'] = 'true'
         download_url = 'Download'.href(url, params)  %>
         
         <div class="message-fileelement">
           <%= name %> (<%= mtype %>, <%= size.to_s %> bytes) 
           
           <%  if mtype != 'application/octet-stream' then %>
            [<%= view_url %>]
          <% end %>
          [<%= download_url %>]
         </div>
    <% end %>
  <% end %>
  <% if Mode::ADMIN.current? %>
    <% if message.hide? %>
      <div class="message-bottom">
        [<%= message.hide_href('show this message', false) %>]
      </div>
    <% else %>
      <div class="message-bottom">[<%= message.hide_href('hide this message') %>]</div>
    <% end %>
  <% end %>

  <br>
</div>
<% end %>

<% if show_form then %>
  <h2 id="form">Reply</h2>
  
  <%
    param = {
      :project            => project, 
      :report_id          => report.id.to_s,
      :params             => params, 
      :email_notification => email_notification,
      :use_cookie         => use_cookie, 
      :errors             => errors,
      :use_captcha        => use_captcha,
      :captcha_error      => false
    }
  %>
  
  <%= eval_template('message_form.rhtml', param) %>
<% else %>
<%
  opts = [report.href('Reply', {'s' => '1'}, '#form')]

  unless Mode::GUEST.current? then
    opts << SplitReport.href(project.id, report.id)
  end
%>

  [ <%= opts.join(' | ') %> ]
<% end %>
  
<% if Mode::ADMIN.current? then %>

<hr>
<h2>Change notification recipients</h2>

<p>Check the addresses that you wish to notify when this report is updated.</p>

<form action="<%= project.url  %>" 
      method="post" 
      accept-charset="<%= project.charset %>">

  <p>
  <% addresses = report.email_addresses(false) %>
  <% addresses.each do |addr, notify| %>
    <% checked = notify ? 'checked="checked"' : '' %>
    <input type="checkbox" name="<%= addr.escape_h %>" <%= checked %>> <%= addr.escape_h %><br>
  <% end %>
  </p>

  <p><input type="submit" value="Change settings"></p>

  <div>
    <input type="hidden" name="action" value="<%= SetEmailNotification.name %>">
    <input type="hidden" name="project" value="<%= project.id %>">
    <input type="hidden" name="id" value="<%= report.id %>">
    <% if @lang == 'ja' %>
    <input type="hidden" name="jp_enc_test" value="Æü">
    <% end %>
  </div>
</form>

<% end %>
