{if $message|default:'' != ''}
<table align="center" border="0" cellspacing="0" cellpadding="1" bgcolor="red">
  <tr>
    <td>
        <table align="center" width="500" bgcolor="#FFFFFF">
            <tr>
                <td class="default" align="center">
                    {$message}
                </td>
            </tr>
        </table>
    </td>
  </tr>
</table>
<br />
{/if}

<form id="report_form" name="report_form" class="dropzone" action="new.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="cat" value="report">
<input type="hidden" name="prj_id" value="{$core.project_id}">
<input type="hidden" name="customer" value="{$customer_id|default:''}" id="customer_id">
<input type="hidden" name="contact" value="{$contact_id|default:''}">
<input type="hidden" name="attached_emails" value="{$attached_emails|default:''}">
<input type="hidden" name="iaf_ids" id="iaf_ids" value="">
{if $defaults.clone_iss_id|default:'' != ''}
    <input type="hidden" name="clone_iss_id" value="{$defaults.clone_iss_id}" />
{/if}

{if $core.current_role < $field_display_settings.assignment.min_role}
    <input type="hidden" name="assignment[]" value="">
{/if}
{if $releases|@count < 1 || $core.current_role < $field_display_settings.release.min_role}
    {* Hidden field if there are no scheduled releases *}
    <input type="hidden" name="release" value="">
{/if}
{if $cats|@count < 1 || $core.current_role < $field_display_settings.category.min_role}
    <input type="hidden" name="category" value="">
{/if}
{if $core.current_role < $field_display_settings.priority.min_role}
    <input type="hidden" name="priority" value="">
{/if}
{if $core.current_role < $field_display_settings.estimated_dev_time.min_role}
    <input type="hidden" name="estimated_dev_time" value="">
{/if}
<table class="bordered two_column" id="create_issue">
{assign var="tabindex" value=1}
    <tr class="title">
      <th colspan="2">
        {t}Create New Issue{/t}
        <span class="menu">({t}Current Project{/t}: {$core.project_name})</span>
      </th>
    </tr>
    {if $cats|@count > 0 && $core.current_role >= $field_display_settings.category.min_role}
    <tr>
      <th{if $field_display_settings.category.min_role > $core.roles.customer} class="internal"{/if}>
        {t}Category{/t} {if $field_display_settings.category.required}*{/if}
            {include file="help_link.tpl.html" topic="report_category"}
      </th>
      <td>
        <select id="category" name="category" tabindex="{$tabindex++}"
          {if $field_display_settings.category.required}data-required="true"{/if}>
          <option value="-1">{t}Please choose a category{/t}</option>
          {html_options options=$cats selected=$defaults.category|default:''}
        </select>
        {include file="error_icon.tpl.html" field="category"}
      </td>
    </tr>
    {/if}
    {if $severities|@count > 0 && $core.current_role >= $field_display_settings.severity.min_role}
    <tr>
      <th width="150"{if $field_display_settings.severity.min_role > $core.roles.customer} class="internal"{/if}>
        {t}Severity{/t} {if $field_display_settings.severity.required}*{/if}
      </th>
      <td>
        <select id="severity" name="severity" tabindex="{$tabindex++}"
                {if $field_display_settings.severity.required}data-required="true"{/if}>
          <option value="-1">{t}Please choose a severity{/t}</option>
          {foreach from=$severities item=severity}
          <option value="{$severity.sev_id}" {if $severity.sev_id == $defaults.severity|default:''}selected{/if}
            data-desc="{$severity.sev_description|escape}">{$severity.sev_title|escape}</option>
          {/foreach}
        </select>
        <span id="severity_desc" class="alerts"></span>
        {include file="error_icon.tpl.html" field="severity"}
      </td>
    </tr>
    {/if}
    {if $core.current_role >= $field_display_settings.priority.min_role}
    <tr>
      <th>
        {t}Priority{/t} {if $field_display_settings.priority.required}*{/if}
        {include file="help_link.tpl.html" topic="report_priority"}
      </th>
      <td>
        {* Figure out default priority *}
        {if $defaults.priority|default:'' != '' && $new_issue_id == ''}
          {assign var="priority" value=$defaults.priority}
        {else}
          {assign var="priority" value=3}
        {/if}
        <select id="priority" name="priority" tabindex="{$tabindex++}"
                {if $field_display_settings.priority.required}data-required="true"{/if}>
          <option value="-1">{t}Please choose a priority{/t}</option>
          {html_options options=$priorities selected=$priority}
        </select>
        {include file="error_icon.tpl.html" field="priority"}
      </td>
    </tr>
    {/if}
    {if $core.current_role >= $field_display_settings.assignment.min_role}
    <tr>
      <th{if $field_display_settings.assignment.min_role > $core.roles.customer} class="internal"{/if}>
        {t}Assignment{/t} {if $field_display_settings.assignment.required}*{/if}
        {include file="help_link.tpl.html" topic="report_assignment"}
      </th>
      <td>
        {if $new_issue_id == ''}
            {assign var='selected_users' value=$defaults.users|default:''}
        {/if}
        <select id="assignment" name="users[]" multiple size="3" tabindex="{$tabindex++}"
                data-placeholder="{t}Choose Assignees…{/t}" class="chosen-select"
                {if $field_display_settings.assignment.required}data-required="true"{/if}>
        {html_options options=$users selected=$selected_users}
        </select>
        {include file="error_icon.tpl.html" field="users[]"}
      </td>
    </tr>
    {/if}

  {if $groups|@count > 0 && $core.current_role >= $field_display_settings.group.min_role}
    <tr>
      <th{if $field_display_settings.group.min_role > $core.roles.customer} class="internal"{/if}>
        {t}Group{/t} {if $field_display_settings.group.required}*{/if}
      </th>
      <td>
        {if $new_issue_id == ''}
            {assign var='selected_group' value=$defaults.group|default:''}
        {/if}
        <select name="group" tabindex="{$tabindex++}"
                {if $field_display_settings.group.required}data-required="true"{/if}>
            <option value=""></option>
            {html_options options=$groups selected=$selected_group}
        </select>
        {include file="error_icon.tpl.html" field="group"}
      </td>
    </tr>
    {/if}

    {if $releases|@count > 0 && $core.current_role >= $field_display_settings.release.min_role}
    <tr>
      <th{if $field_display_settings.release.min_role > $core.roles.customer} class="internal"{/if}>
        {t}Scheduled Release{/t} {if $field_display_settings.release.required}*{/if}
        {include file="help_link.tpl.html" topic="report_release"}
      </th>
      <td>
        {if $new_issue_id == ''}
            {assign var='selected_release' value=$defaults.release|default:''}
        {/if}
        <select name="release" tabindex="{$tabindex++}"
                {if $field_display_settings.release.required}data-required="true"{/if}>
          <option value="0">{t}un-scheduled{/t}</option>
          {html_options options=$releases selected=$selected_release}
        </select>
      </td>
    </tr>
    {/if}

    <tr>
      <th>
        {t}Summary{/t} * {include file="help_link.tpl.html" topic="report_summary"}
      </th>
      <td>
        {if $new_issue_id != ''}
            {assign var='issue_summary' value=''}
        {elseif $issue_summary|default:'' == ''}
            {assign var='issue_summary' value=$defaults.summary|default:''}
        {/if}
        <input type="text" name="summary" size="50" tabindex="{$tabindex++}" value="{$issue_summary|default:''|escape:"html"}">
        {include file="error_icon.tpl.html" field="summary"}
      </td>
    </tr>

    <tr>
      <th class="initial_description">
        {t}Description{/t} * {include file="help_link.tpl.html" topic="report_description"}
      </th>
      <td>
        {if $new_issue_id != ''}
            {assign var='issue_description' value=''}
        {elseif $issue_description|default:'' == ''}
            {assign var='issue_description' value=$defaults.description|default:''}
        {/if}
        <textarea name="description" rows="10" tabindex="{$tabindex++}" style="width: 97%">{$issue_description|default:''}</textarea>
        {include file="error_icon.tpl.html" field="description"}
      </td>
    </tr>

    {* associated issue field *}
    {if $core.current_role >= $field_display_settings.associated_issues.min_role}
    <tr>
      <th>
        {t}Associated Issues{/t}
      </th>
      <td>
        <input type="text" name="associated_issues" size="20" tabindex="{$tabindex++}"
               value="{$associated_issues|default:''|escape:"html"}"
               {if $field_display_settings.associated_issues.required}data-required="true"{/if}>
      </td>
    </tr>
    {/if}

  {if $core.current_role > $core.roles.customer && $core.current_role >= $field_display_settings.expected_res_date.min_role}
      <tr>

        <th{if $field_display_settings.expected_res_date.min_role > $core.roles.customer} class="internal"{/if}>
          {t}Expected Resolution Date{/t} {if $field_display_settings.expected_res_date.required}*{/if}
        </th>

        <td>
          <input type="text" name="expected_resolution_date" id="expected_resolution"
                 value="{$defaults.expected_res_date|default:''}" class="date_picker"
                  {if $field_display_settings.expected_res_date.required}data-required="true"{/if}>
        </td>
      </tr>
    {/if}

    {if $core.current_role >= $field_display_settings.estimated_dev_time.min_role}
    <tr>
      <th{if $field_display_settings.estimated_dev_time.min_role > $core.roles.customer} class="internal"{/if}>
        <nobr>{t}Estimated Dev. Time{/t} {if $field_display_settings.estimated_dev_time.required}*{/if}
            {include file="help_link.tpl.html" topic="report_estimated_dev_time"}&nbsp;</nobr>
      </th>
      <td>
        {if $new_issue_id == ''}
            {assign var='estimated_dev_time' value=$defaults.estimated_dev_time|default:''}
        {/if}
        <input type="text" name="estimated_dev_time" size="10" tabindex="{$tabindex++}" value="{$estimated_dev_time}"
                {if $field_display_settings.estimated_dev_time.required}data-required="true"{/if}>
        {include file="error_icon.tpl.html" field="estimated_dev_time"} <span>({t}in hours{/t})</span>
      </td>
    </tr>
    {/if}

    {if $products|@count > 0 && $core.current_role >= $field_display_settings.product.min_role}
    <tr>
      <th width="150"{if $field_display_settings.product.min_role > $core.roles.customer} class="internal"{/if}>
        {t}Product{/t} {if $field_display_settings.product.required}*{/if}
      </th>
      <td>
        <select class="default" id="product" name="product" tabindex="{$tabindex++}"
                {if $field_display_settings.product.required}data-required="true"{/if}>
            <option value="-1"></option>
          {foreach from=$products item=product}
          <option value="{$product.pro_id}" {if $product.pro_id == $defaults.product|default:''}selected{/if}
            data-desc="{$product.pro_version_howto|escape}">{$product.pro_title|escape}</option>
          {/foreach}
        </select>
        {include file="error_icon.tpl.html" field="product"}
      </td>
    </tr>
    <tr>
      <th width="150"{if $field_display_settings.product.min_role > $core.roles.customer} class="internal"{/if}>
        {t}Product Version{/t}
      </th>
      <td>
        <input type="text" name="product_version" value="{$defaults.product_version|default:''}" size="40" />
        <span id="product_version_howto"></span>
        {include file="error_icon.tpl.html" field="product_version"}
      </td>
    </tr>
    {/if}
    {if $core.current_role >= $field_display_settings.access_level.min_role}
        {include file="fields/access_level.tpl.html"}
    {/if}
    {include file="edit_custom_fields.tpl.html" custom_fields=$custom_fields form_type='report'}
    {assign var=tabindex value=$tabindex+50}
    {if $core.has_crm}
    {include file="`$core.crm_template_path`/report_form_fields.tpl.html"}

    {* set tab index very high now to account for inputs in customer file *}
    {assign var="tabindex" value=$tabindex+30}
    {/if}

    {if $core.current_role >= $field_display_settings.file.min_role}
    <tr class="title">
      <th colspan="2">
        {t}Add Files{/t}
      </th>
    </tr>
    <tr>
      <th>
        {t}Files{/t}
      </th>
      <td>
        <div class="dz-message">
          {t}Drop files here or click to upload.{/t}<br/><br/>

          <div class="dropzone-previews"></div>

          <div class="fallback">

          <table width="100%" cellpadding="2" cellspacing="0" id="file_table">
          <tr>
            <td>
              <input type="file" name="file[]" size="40" class="growing_file_field">
            </td>
          </tr>
          </table>
          </div>

          <span><i>{t 1=$max_attachment_size}Note: The current maximum allowed upload file size is %1{/t}</i></span>

        </div>
      </td>
    </tr>
    {/if}

    <tr>
      <td colspan="2" class="footer">
        <input name="main_submit_button" type="submit" value="{t}Submit{/t}" tabindex="{$tabindex++}">
        <input type="reset" value="{t}Reset{/t}" tabindex="{$tabindex++}">
      </td>
    </tr>
    <tr>
      <td colspan="2" class="footnote">
        * {t}Required fields{/t}
      </td>
    </tr>
</table>

{if $emails|default:'' != ""}
    {include file="include/attached_emails.tpl.html"}
{/if}
</form>
