<%Links::Tools::editor_size%>
<%set font_tag = '<font face="Tahoma,Arial,Helvetica" size="2">'%>
<html>
<head>
  <title>Gossamer Links - Build - Email Templates</title>
  <base target="_self">
</head>
<%set template_root = $config.admin_root_path%>
<%set template_root .= "/templates"%>
<%set setcookie = 'set-cookie'%>
<%if save_template%>
  <%if save_as%>
    <%set template_file = $save_as%>
    <%set tpl_file = $save_as%>
  <%else%>
    <%set template_file = $tpl_file%>
  <%endif%>
<!--
-->
  <%GT::Mail::Editor::tpl_save(
      dir           => $template_root,
      template      => $tpl_dir,
      file          => $template_file,
      header        => To      => $header_To,
      header        => Subject => $header_Subject,
      header        => From    => $header_From,
      extra_headers => $extra_headers,
      body          => $body
  )%>
  <%if error%>
    <%set error_message = "Unable to save template: $error"%>
    <%set display_template = 1%><%-- All the variables will still be there, left over from whatever we just submitted --%>
  <%else%>
    <%set save_as = ""%>
    <%set success_message = "Template saved successfully"%>
    <%GT::Mail::Editor::tpl_load(
        dir      => $template_root,
        template => $tpl_dir,
        file     => $template_file,
        header   => To,
        header   => Subject,
        header   => From
    )%>
    <%if error%>
      <%set error_message = "Unable to load template: $error"%>
    <%else%>
      <%set displaying_template = 1%>
    <%endif%>
  <%endif%>
<%elsif load_template%>
  <%if not tpl_file%>
    <%set error_message = "Unable to load template: No template selected"%>
  <%else%>
    <%GT::Mail::Editor::tpl_load(
        dir      => $template_root,
        template => $tpl_dir,
        file     => $tpl_file,
        header   => To,
        header   => From,
        header   => Subject
    )%>
    <%if error%>
      <%set error_message = "Unable to load template: $error"%>
    <%else%>
      <%set displaying_template = 1%>
    <%endif%>
  <%endif%>
<%elsif restore_template%>
  <%if not tpl_file%>
    <%set error_message = "Unable to restore template: No template specified"%>
  <%else%>
<!--
-->
    <%GT::Mail::Editor::tpl_delete(
        dir      => $template_root,
        template => $tpl_dir,
        file     => $tpl_file,
    )%>
    <%if error%>
      <%set error_message = "Unable to restore template: $error"%>
      <%set displaying_template = 1%>
    <%else%>
      <%set success_message = "Template restored successfully"%>
    <%endif%>

    <%GT::Mail::Editor::tpl_load(
        dir      => $template_root,
        template => $tpl_dir,
        file     => $tpl_file,
        header   => To,
        header   => Subject,
        header   => From
    )%>
    <%if error%>
      <%set error_message = "Unable to load template: $error"%>
    <%else%>
      <%set displaying_template = 1%>
    <%endif%>
  <%endif%>
<%elsif delete_template%>
  <%if not tpl_file%>
    <%set error_message = "Unable to delete template: No template specified"%>
  <%else%>
<!--
-->
    <%GT::Mail::Editor::tpl_delete(
        dir     => $template_root,
        template => $tpl_dir,
        file     => $tpl_file,
    )%>
    <%if error%>
      <%set error_message = "Unable to delete template: $error"%>
      <%set displaying_template = 1%>
    <%else%>
      <%set success_message = "Template deleted successfully"%>
    <%endif%>
  <%endif%>
<%elsif in.$setcookie%>
  <%set displaying_template = 1%>
<%endif%>

<body bgcolor="#ffffff">
  <table border="1" cellpadding="0" cellspacing="0">
    <tr>
      <td>
        <table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="3" width="500" valign="top">
          <tr>
            <td align="left" bgcolor="navy">
              <b><%font_tag%><font color="white">Email Templates</font></font></b>
            </td>
          </tr>
          <tr>
            <td>
              <p align="center"><b><%font_tag%>Email Templates</font></b></p>
              <p><%font_tag%>From here you can quickly edit the e-mail templates for any e-mails sent.</font>
              <%if success_message%><p><%font_tag%><font color="green"><b><%success_message%></b></font></font></p><%endif%>
              <%if error_message%><p><%font_tag%><font color="red"><b><%error_message%></b></font></font></p><%endif%>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
  <br>
  <form action="admin.cgi" method="post" style="margin: 0px">
  <input type="hidden" name="do" value="page">
  <input type="hidden" name="page" value="build_email.html">

  <table border="1" cellpadding="0" cellspacing="0">
    <tr>
      <td>
        <table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="3" width="500" valign="top">
          <tr>
            <td>
<%Links::Tools::tpl_dir_select($tpl_dir, 'browser')%>
<%Links::Tools::tpl_file_select($tpl_dir, '', '.*\.eml')%>
              <p><%font_tag%>Currently working on template set: <select name="tpl_dir"><%loop template_set_loop%><option<%if dir_selected%> selected<%endif%>><%directory%></option><%endloop%></select> <input type="submit" value="Change" name="change"></font></p>
              <p><%font_tag%>Available templates: <select name="tpl_file"><option value="">---</option><%loop template_loop%><option value="<%filename%>"<%if filename eq $tpl_file%> selected<%set tpl_local = $local%><%set tpl_new_local = $new_local%><%endif%>><%filename%><%if local and new_local%> *<%elsif local%> +<%endif%></option><%endloop%></select> <input type="submit" value="Load" name="load_template"></font></p>
              <p><%font_tag%>* modified template<br>
              + non-default template</font></p>
              <%if tpl_local%><p><%font_tag%>Template actions: <%if tpl_new_local%><a href="admin.cgi?do=fileman_diff;cmd_do=cmd_diff;txt_input=local/<%tpl_file%>;c_edit=<%tpl_file%>;work_path=<%tpl_dir%>;hide_back_button=1" target="_blank">diff</a> or <a href="admin.cgi?do=page;page=build_email.html;restore_template=<%escape_url tpl_file%>;tpl_dir=<%escape_url tpl_dir%>;tpl_file=<%escape_url tpl_file%>" onClick="return confirm('Are you sure you want to restore the <%tpl_file%> template?')">Restore</a><%else%><a href="admin.cgi?do=page;page=build_email.html;delete_template=<%escape_url tpl_file%>;tpl_dir=<%escape_url tpl_dir%>;tpl_file=<%escape_url tpl_file%>" onClick="return confirm('Are you sure you want to delete the <%tpl_file%> template?')">Delete</a><%endif%></font></p><%endif%>
              <table border="0" cellpadding="0" cellspacing="2" width="100%">
                <tr>
                  <td width="15%">
                    <%font_tag%>To:</font>
                  </td>
                  <td>
                    <input type="text" size="<%editor_cols%>" name="header_To" value="<%if displaying_template%><%escape_html header_To%><%endif%>">
                  </td>
                </tr>
                <tr>
                  <td>
                    <%font_tag%>From:</font>
                  </td>
                  <td>
                    <input type="text" size="<%editor_cols%>" name="header_From" value="<%if displaying_template%><%escape_html header_From%><%endif%>">
                  </td>
                </tr>
                <tr>
                  <td>
                    <%font_tag%>Subject:</font>
                  </td>
                  <td>
                    <input type="text" size="<%editor_cols%>" name="header_Subject" value="<%if displaying_template%><%escape_html header_Subject%><%endif%>">
                  </td>
                </tr>
                <tr>
                  <td colspan="2">
                    <%font_tag%>Extra Headers:<br></font>
                    <textarea name="extra_headers" rows="3" cols="<%editor_cols%>"><%if displaying_template%><%loop extra_headers%><%escape_html name%>: <%escape_html value%>
<%endloop%><%endif%></textarea>
                  </td>
                </tr>
              </table>
              <%font_tag%>Body:<br></font>
              <textarea rows="<%editor_rows%>" name="body" cols="<%editor_cols%>" wrap="off"><%if displaying_template%><%escape_html body%><%endif%></textarea>
              <br>
              <p><%font_tag%>Save template as: <input type="text" name="save_as" value="<%if tpl_file%><%tpl_file%><%endif%>" size="20"><input type="submit" value="Save" name="save_template"></font></p>
              <p><%font_tag%>Resize Textarea to: <input type="text" name="cookie-editor_rows" value="<%editor_rows%>" size="3"> rows, <input type="text" name="cookie-editor_cols" value="<%editor_cols%>" size="3"> columns <input type="submit" name="set-cookie" value="Change"></font></p>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
  </form>
</body>
</html>
