<%Links::Tools::editor_size%>
<%set font_tag = '<font face="Tahoma,Arial,Helvetica" size="2">'%>
<html>
<head>
  <title>Gossamer Links - Build - CSS Editor</title>
  <base target="_self">
</head>
<%if not css_dir or css_dir contains '..' or css_dir contains '/' or css_dir contains '\\'%>
  <%set css_dir = Links::template_set%>
<%endif%>
<!--
-->
<%set demo = 0%>
<%set setcookie = 'set-cookie'%>
<%if action eq 'load'%>
  <%Links::Tools::css_editor(
      action   => 'load',
      css_dir  => $css_dir,
      css_file => $css_file
  )%>
  <%if error%>
    <%set error_message = "Unable to load CSS: $error"%>
  <%else%>
    <%set displaying_css = 1%>
  <%endif%>
<%elsif action eq 'save'%>
  <%if save_as%>
    <%set css_file = $save_as%>
  <%endif%>
  <%if css_file ne 'luna_core.css'%>
    <%Links::Tools::css_editor(
        action   => 'save',
        css_dir  => $css_dir,
        css_file => $css_file,
        css      => $css,
        demo     => $demo
    )%>
  <%else%>
    <%set error = "You should not be modifying this file, please save your changes in the luna.css file."%>
  <%endif%>
  <%if error%>
    <%set error_message = "Unable to save CSS: $error"%>
    <%set displaying_css = 1%>
  <%else%>
    <%set success_message = "CSS file saved sucessfully"%>
    <%Links::Tools::css_editor(
        action   => 'load',
        css_dir  => $css_dir,
        css_file => $css_file
    )%>
    <%if error%>
      <%set error_message = "Unable to load CSS: $error"%>
    <%else%>
      <%set displaying_css = 1%>
    <%endif%>
  <%endif%>
<%elsif action eq 'delete'%>
  <%Links::Tools::css_editor(
      action   => 'delete',
      css_dir  => $css_dir,
      css_file => $css_file,
      demo     => $demo
  )%>
  <%if error%>
    <%set error_message = "Unable to delete CSS: $error"%>
  <%else%>
    <%set success_message = "CSS deleted successfully"%>
  <%endif%>
<%elsif in.$setcookie%>
  <%set displaying_css = 1%>
<%endif%>
<%set css_dir_exists = 0%>
<%Links::Tools::file_select($config.build_static_path, '(?:\.\.?|CVS|admin|browser|fileman)', '', 'd')%>
<%if not file_loop.length%>
  <%set error_message = "Could not find CSS files.  Perhaps your build_static_path is incorrect?"%>
<%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">CSS Editor</font></font></b>
            </td>
          </tr>
          <tr>
            <td>
              <p align="center"><b><%font_tag%>CSS Editor</font></b></p>
              <p><%font_tag%>From here you can quickly edit the CSS files for your templates.</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_css.html">

<%if file_loop.length%>
  <table border="1" cellpadding="0" cellspacing="0">
    <tr>
      <td>
        <table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="3" width="500" valign="top">
          <tr>
            <td>
              <p><%font_tag%>Template set: <select id="css_dir" name="css_dir"><%loop file_loop%><option<%if loop_value eq $css_dir%> selected<%set css_dir_exists = 1%><%endif%>><%loop_value%></option><%endloop%></select> <input type="submit" name="action=load_tpl" value="Change"></font></p>
<%unless css_dir_exists%><%set css_dir = $file_loop.0%><%endunless%>
<%Links::Tools::file_select("${config.build_static_path}/$css_dir", '', '.*\.css', 'f')%>
              <p><%font_tag%>CSS files: <select id="css_file" name="css_file"><option value="">---</option><%loop file_loop%><option<%if loop_value eq $css_file%> selected<%endif%>><%loop_value%></option><%endloop%></select> <input type="submit" name="action=load" value="Load"> <input type="submit" name="action=delete" value="Delete" onclick="return confirm('Are you sure you want to delete \'' + document.getElementById('css_file').value + '\' from the \'' + document.getElementById('css_dir').value + '\' template set?')"></font></p>
              <textarea rows="<%editor_rows%>" name="css" cols="<%editor_cols%>" wrap="off"><%if displaying_css%><%escape_html css%><%endif%></textarea>
              <br>
              <p><%font_tag%>Save file as: <input type="text" name="save_as" value="<%if css_file%><%css_file%><%endif%>" size="20"><input type="submit" name="action=save" value="Save"></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>
<%endif%>
  </form>
</body>
</html>
