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

<% error = !errors.empty? || captcha_error %>

<% if error then %>

<p>The following errors occurred:</p>

<ul>
  <% errors.each do |key, value| %>
  <li><%= MessageBundle[key] %></li>
  <ul>
    <% value.each do |e| %>
    <li><%= project.report_type[e].name %></li>
    <% end %>
  </ul>
  <% end %>
  <% if captcha_error then %>
  <li>Incorrect captcha code.</li>
  <% end %>
</ul>

<p>Please correct these errors and resubmit.</p>

<% end %>

<form action="<%= project.url  %>" 
      method="post" 
      enctype="multipart/form-data"
      accept-charset="<%= project.charset %>">
  <table>

  <!-- Generated from the ReportType input field -->
  <% project.report_type.each do |etype| %>
    <% next if etype.report_attr && etype['hide_from_guest'] && Mode::GUEST.current? %>
    <% next if etype.report_attr && !etype.allow_guest && Mode::GUEST.current? %>
    <% next if etype.report_attr && !etype.allow_user && Mode::USER.current? %>
  <tr>
   <th <%= errors.tag_class(etype.id) %>>
     <%= etype.name %><%= etype.required? ? '<small>*</small>' : '' %>
   </th>
    <td>
      <% 
         attr = params.attr(etype.id)
         unless error then
           input_f = etype.use_cookie? ? etype.html_input() : etype.html_input(attr)
         else
           input_f = etype.html_input_with_error(attr)
         end
      %>
      <%= input_f %>
      <span class="form-desc">
        <%= etype.html_description() %>
      </span>
    </td>
  </tr>
  <% end %>

  <tr>
    <th>Options</th>

    <td>
      <input type="checkbox" name="email_notification"
             <%= email_notification ? 'checked="checked"' : '' %>> Send
      		e-mail when there are replies
      <% if project.report_type.use_cookie? %>
        <br>
        <input type="checkbox" name="allow_cookie"
               <%= use_cookie ? 'checked="checked"' : '' %>> Remember
        <%= project.report_type.use_cookie_element_list() %> for future
	visits
      <% end %>
    </td>
  </tr>

  <% if use_captcha && Mode::GUEST.current? then %>
  <tr>
    <th  <%= captcha_error ? 'class="error"' : ''%>>captcha*</th>
    <td>
       <% captcha_url = project.url() + "&action=#{CaptchaImage.name}" %>
       <img src="<%= captcha_url %>" alt="captcha" ><br>
       <input name="<%= CaptchaHandler::CAPTCHA_CODE_KEY %>" type="text" size="6">
       Type the code shown
    </td>
  </tr>
  <% end %>

  </table>
  <div>
    <small>Items marked with an asterisk are required.</small><br>
    <input type="submit" value="Submit">
  </div>

  <div>
    <input type="hidden" name="action" value="<%= AddMessage.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>

<ul>
  <li>URLs are automatically converted to links.</li>
  <li>To link to another bug in the same project, write "&lt;BTS:bug_id&gt;".</li>
  <li>To link to another bug in a different project, write "&lt;BTS:project_id:bug_id&gt;".</li>
  <li>Lines beginning with "&gt" or blank space are treated as preformatted text, and will not be wrapped.</li>
</ul>
