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

{function name="rank_icon" direction="down" href=""}
  {include file="include/rank_icon.tpl.html" direction=$direction href=$href}
{/function}

{block "manage_content"}

  <script type="text/javascript">
  <!--
  function validateForm()
  {
      if (Validation.isFieldWhitespace('title')) {
          Validation.errors[Validation.errors.length] = new Option('{t escape=js}Title{/t}', 'title');
      }
      if (Eventum.getField('type').val() == -1) {
          Validation.errors[Validation.errors.length] = new Option('{t escape=js}Action Type{/t}', 'type');
      }
      if (Validation.isFieldWhitespace('rank')) {
          Validation.errors[Validation.errors.length] = new Option('{t escape=js}Rank{/t}', 'rank');
      }
      // hack to make the multiple select box actually submit something
      Eventum.selectAllOptions('user_list[]');
      return true;
  }
      function checkActionType()
      {
          var option = Eventum.getField('type').find(':selected').text();
          var action_user_list = $('#action_user_list');
          if (option.indexOf('To...') != -1) {
              action_user_list.show();
          } else {
              action_user_list.hide();
          }
      }
      function addUserList()
      {
          var field = Eventum.getField('available_users');
          var options = field.find('option:selected').toArray() ;
          var email_address = Eventum.getField('email_address').val();
          if (Validation.isEmail(email_address)) {
              options[options.length] = new Option(email_address, email_address);
          }
          Eventum.addOptions('user_list[]', options);
      }
      function removeUserList()
      {
          var field = Eventum.getField('user_list[]');
          field.find('option:selected').each(function(i) {
              $(this).remove();
          });
      }
      function checkDelete()
      {
          if (!Validation.hasOneChecked('items[]')) {
              alert('{t escape=js}Please select at least one of the actions.{/t}');
              return false;
          }
          if (!confirm('{t escape=js}This action will remove the selected entries.{/t}')) {
              return false;
          } else {
              return true;
          }
      }
  $().ready(function() {
      $('#reminder_form').submit(function() { return Validation.checkFormSubmission($('#reminder_form'), validateForm); });
      $('.select_all').click(function() { Eventum.toggleCheckAll('items[]'); });

      $('select[name=type]').change(checkActionType);
      $('#add_user_list').click(addUserList)
      $('#remove_user_list').click(removeUserList)

      $('#delete_form').submit(checkDelete);

      checkActionType();
  });
  //-->
  </script>

  <form id="reminder_form" method="post">
  <input type="hidden" name="rem_id" value="{$rem_id}">
  {if $smarty.get.cat|default:'' == 'edit'}
  <input type="hidden" name="cat" value="update">
  <input type="hidden" name="id" value="{$smarty.get.id|intval|default:''}">
  {else}
  <input type="hidden" name="cat" value="new">
  {/if}
            <table class="bordered">
              <tr class="title">
                <th colspan="2">
                    {t}Manage Reminder Actions{/t}
                  <div class="right">
                    <a href="reminders.php?cat=edit&id={$rem_id}" title="{t}view reminder details{/t}">{t}Reminder{/t} #{$rem_id}: {$rem_title}</a>
                  </div>
                </th>
              </tr>
              <tr>
                <th width="120">
                  {t}Title{/t}
                </th>
                <td>
                  <input type="text" size="50" name="title" value="{$info.rma_title|escape:"html"|default:''}">
                  {include file="error_icon.tpl.html" field="title"}
                </td>
              </tr>
              <tr>
                <th width="120">
                  {t}Action Type{/t}
                </th>
                <td>
                  <select name="type">
                    <option value="-1">{t}Please choose an option{/t}</option>
                    {html_options options=$action_types selected=$info.rma_rmt_id|default:''}
                  </select>
                  {include file="error_icon.tpl.html" field="type"}
                  <div id="action_user_list" style="display: none;">
                  <table bgcolor="#666666" style="margin-left: 30px; margin-top: 5px;">
                    <tr>
                      <td><input type="text" name="email_address"></td>
                      <td>&nbsp;</td>
                      <td valign="bottom">{t}Email List{/t}:</td>
                    </tr>
                    <tr>
                      <td>
                        <select name="available_users" multiple size="4">
                          {html_options options=$user_options|default:''}
                        </select>
                      </td>
                      <td>
                        <input type="button" id="add_user_list" value="{t}Add{/t} &gt;&gt;">
                        <br /><br />
                        <input type="button" id="remove_user_list" value="{t}Remove{/t}">
                      </td>
                      <td>
                        <select name="user_list[]" multiple size="4">
                          {if $info.user_list|default:'' != ''}
                            {html_options options=$info.user_list}
                          {/if}
                        </select>
                      </td>
                    </tr>
                  </table>
                  </div>
                </td>
              </tr>
              <tr>
                <th width="120">
                  {t}Rank{/t}
                </th>
                <td>
                  <input type="text" size="5" name="rank" value="{$info.rma_rank|default:''}">
                  {include file="error_icon.tpl.html" field="rank"}
                  <span><i>({t}this will determine the order in which actions are triggered{/t})</i></span>
                </td>
              </tr>
              <tr>
                <th width="120">
                  {t}Alert Group Leader{/t}
                </th>
                <td>
                  <label>
                    <input type="radio" name="alert_group_leader" value="1" {if $info.rma_alert_group_leader|default:''}checked{/if}>
                    {t}Yes{/t}</label>&nbsp;&nbsp;
                  <label>
                    <input type="radio" name="alert_group_leader" value="0" {if not $info.rma_alert_group_leader|default:''}checked{/if}>
                    {t}No{/t}</label>
                </td>
              </tr>
              <tr>
                <th width="120">
                  {t}Alert IRC{/t}
                </th>
                <td>
                  <label>
                    <input type="radio" name="alert_irc" value="1" {if $info.rma_alert_irc|default:''}checked{/if}>
                    {t}Yes{/t}</label>&nbsp;&nbsp;
                  <label>
                    <input type="radio" name="alert_irc" value="0" {if not $info.rma_alert_irc|default:''}checked{/if}>
                    {t}No{/t}</label>
                </td>
              </tr>
              <tr>
                <th width="120">
                  {t}Boilerplate{/t}
                </th>
                <td>
                  <input type="text" size="40" name="boilerplate" value="{$info.rma_boilerplate|default:''}">
                  {include file="error_icon.tpl.html" field="boilerplate"}
                  <span><i>({t}this will show up on the bottom of the reminder messages{/t})</i></span>
                </td>
              </tr>
              <tr class="buttons">
                <td colspan="2">
                  {if $smarty.get.cat|default:'' == 'edit'}
                  <input type="submit" value="{t}Update Action{/t}">
                  {else}
                  <input type="submit" value="{t}Add Action{/t}">
                  {/if}
                  <input type="reset" value="{t}Reset{/t}">
                </td>
              </tr>
            </table>
            </form>

            <form id="delete_form" method="post">
            <input type="hidden" name="rem_id" value="{$rem_id}">
            <input type="hidden" name="cat" value="delete">
            <table class="bordered grid">
              <tr class="title">
                <th colspan="5">
                  {t}Existing Actions{/t}
                  <div class="right">
                    <a href="reminders.php?cat=edit&id={$rem_id}">{t}Back to Reminder List{/t}</a>
                  </div>
                </th>
              </tr>
                    <tr>
                      <th width="4" nowrap><input type="button" value="{t}All{/t}" class="select_all"></th>
                      <th align="center">&nbsp;{t}Rank{/t}&nbsp;</th>
                      <th width="20%">&nbsp;{t}Title{/t}</th>
                      <th width="50%">&nbsp;{t}Type{/t}</th>
                      <th>&nbsp;{t}Details{/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].rma_id}"></td>
                      <td align="center" nowrap>
                        {rank_icon href="{$core.rel_url}manage/reminder_actions.php?cat=change_rank&id={$list[i].rma_id}&rem_id={$rem_id}&rank=desc" direction="down"}
                        {$list[i].rma_rank}
                        {rank_icon href="{$core.rel_url}manage/reminder_actions.php?cat=change_rank&id={$list[i].rma_id}&rem_id={$rem_id}&rank=asc" direction="up"}
                      </td>
                      <td width="20%">
                        &nbsp;<a href="{$core.rel_url}manage/reminder_actions.php?cat=edit&rem_id={$rem_id}&id={$list[i].rma_id}" title="{t}update this entry{/t}">{$list[i].rma_title|escape:"html"}</a>
                      </td>
                      <td width="50%">
                        &nbsp;{$list[i].rmt_title}
                        {if $list[i].rma_alert_irc} [Alert IRC]{/if}
                        {if $list[i].rma_alert_group_leader} [Alert Group Leader]{/if}
                      </td>
                      <td>
                        &nbsp;<a href="{$core.rel_url}manage/reminder_conditions.php?rem_id={$list[i].rma_rem_id}&rma_id={$list[i].rma_id}">{$list[i].total_conditions} Condition{if $list[i].total_conditions != 1}s{/if}</a><br />
                        {if $list[i].status|default:'' != ''}&nbsp;Status: {$list[i].status}{/if}
                      </td>
                    </tr>
                    {sectionelse}
                    <tr class="no_results">
                      <td colspan="5">
                        {t}No actions could be found.{/t}
                      </td>
                    </tr>
                    {/section}
                    <tr class="buttons">
                      <td width="4">
                        <input type="button" value="{t}All{/t}" class="select_all">
                      </td>
                      <td colspan="4">
                        <input type="submit" value="{t}Delete{/t}">
                      </td>
                    </tr>
                  </table>
                    </form>
{/block}
