{extends "manage/manage.tpl.html"}

{block "manage_content"}

      <script type="text/javascript">
      <!--
      function validateForm()
      {
          if (!Validation.hasOneSelected('projects[]')) {
              alert('{t escape=js}Please select the projects for this email response.{/t}');
              Validation.selectField('projects[]');
              return false;
          }
          if (Validation.isFieldWhitespace('title')) {
              alert('{t escape=js}Please enter the title of this email response.{/t}');
              Validation.selectField('title');
              return false;
          }
          return true;
      }
      function checkDelete()
      {
          if (!Validation.hasOneChecked('items[]')) {
              alert('{t escape=js}Please select at least one of the email responses.{/t}');
              return false;
          }
          if (!confirm('{t escape=js}This action will remove the selected entries.{/t}')) {
              return false;
          } else {
              return true;
          }
      }
      $().ready(function() {
          $('#response_form').submit(validateForm);
          $('.select_all').click(function() { Eventum.toggleCheckAll('items[]'); });

          $('#delete_form').submit(checkDelete);
      });
      //-->
      </script>

      <form id="response_form" method="post">
      {if $smarty.get.cat|default:'' == 'edit'}
      <input type="hidden" name="cat" value="update">
      <input type="hidden" name="id" value="{$smarty.get.id|default:''|intval}">
      {else}
      <input type="hidden" name="cat" value="new">
      {/if}
        <table class="bordered">
          <tr class="title">
            <th colspan="2">
              {t}Manage Canned Email Responses{/t}
            </th>
          </tr>
          <tr>
            <th width="140">
              {t}Projects{/t}
            </th>
            <td width="80%">
              <select name="projects[]" multiple size="4">
                {html_options options=$project_list selected=$info.projects|default:''}
              </select>
              {include file="error_icon.tpl.html" field="projects[]"}
            </td>
          </tr>
          <tr>
            <th width="120">
              {t}Title{/t}
            </th>
            <td>
              <input type="text" name="title" size="40" value="{$info.ere_title|default:''|escape:"html"}">
              {include file="error_icon.tpl.html" field="title"}
            </td>
          </tr>
          <tr>
            <th width="120">
              {t}Response Body{/t}
            </th>
            <td>
              <textarea name="response_body" cols="50" rows="10">{$info.ere_response_body|default:''|escape:"html"}</textarea>
              {include file="error_icon.tpl.html" field="response_body"}
            </td>
          </tr>
          <tr class="buttons">
            <td colspan="2">
              {if $smarty.get.cat|default:'' == 'edit'}
              <input type="submit" value="{t}Update Email Response{/t}">
              {else}
              <input type="submit" value="{t}Create Email Response{/t}">
              {/if}
              <input type="reset" value="{t}Reset{/t}">
            </td>
          </tr>
          </table>
          </form>

        <form id="delete_form" method="post">
        <input type="hidden" name="cat" value="delete">
        <table class="bordered grid">
          <tr class="title">
            <th colspan="3">
              {t}Existing Canned Email Responses{/t}
            </th>
          </tr>
            <tr>
              <th width="4" nowrap><input type="button" value="{t}All{/t}" class="select_all"></th>
              <th width="60%">&nbsp;{t}Title{/t}</th>
              <th width="40%">&nbsp;{t}Projects{/t}</th>
            </tr>
            {section name="i" loop=$list}
            <tr class="{cycle values='odd,even'}">
              <td width="4" nowrap align="center"><input type="checkbox" name="items[]" value="{$list[i].ere_id}"></td>
              <td width="60%">
                &nbsp;<a href="{$core.rel_url}manage/email_responses.php?cat=edit&id={$list[i].ere_id}" title="{t}update this entry{/t}">{$list[i].ere_title}</a>
              </td>
              <td width="40%">
                &nbsp;{$list[i].projects|escape:"html"}
              </td>
            </tr>
            {sectionelse}
            <tr class="no_results">
              <td colspan="3">
                {t}No canned email responses could be found.{/t}
              </td>
            </tr>
            {/section}
            <tr class="buttons">
              <td width="4" align="center">
                <input type="button" value="{t}All{/t}" class="select_all">
              </td>
              <td colspan="2" align="center">
                <input type="submit" value="{t}Delete{/t}">
              </td>
            </tr>
        </table>
        </form>
{/block}
