{% extends "@ContaoInstallation/layout.html.twig" %}
{% trans_default_domain 'ContaoInstallationBundle' %}

{% block main %}
  {% if optionKey is defined %}
    <fieldset class="tl_tbox nolegend">
        <p class="tl_error">{{ 'strict_sql_mode'|trans }}</p>
        <p>{{ 'strict_sql_mode_explain'|trans|raw }}</p>
        <div id="sql_wrapper">
        <pre>doctrine:
    dbal:
        connections:
            default:
                options:
                    {{ optionKey }}: "SET SESSION sql_mode=(SELECT CONCAT(@@sql_mode, ',TRADITIONAL'))"</pre>
        </div>
    </fieldset>
  {% endif %}
  <fieldset class="tl_tbox{% if sql_form is empty and sql_message is empty %} collapsed{% endif %}">
    <legend onclick="this.getParent().toggleClass('collapsed')">{{ 'update_tables'|trans }}</legend>
    <div>
      <h3>{{ 'update_tables'|trans }}</h3>
      {% if sql_form is empty %}
        <p class="tl_confirm">{{ 'update_tables_confirm'|trans }}</p>
      {% endif %}
      <p>{{ 'update_tables_explain'|trans|raw }}</p>
      {% if sql_message is not empty %}
        <div id="sql_message">{{ sql_message|raw }}</div>
      {% endif %}
      {% if sql_form is not empty %}
        <form method="post">
          <div class="tl_formbody">
            <input type="hidden" name="FORM_SUBMIT" value="tl_database_update">
            <input type="hidden" name="REQUEST_TOKEN" value="{{ request_token }}">
            <div id="sql_wrapper">
              <table id="sql_table">
              {% for category, commands in sql_form %}
                {% if commands is not empty %}
                  <tr>
                    <td colspan="2" class="tl_col_0">{{ category|trans }}</td>
                  </tr>
                  <tr>
                    <td class="tl_col_1"><input type="checkbox" id="check_all_{{ loop.index }}" class="tl_checkbox" onclick="Backend.toggleCheckboxElements(this, '{{ category }}')"{% if 'DROP' not in category or 'DROP INDEX' in category %} checked{% endif %}></td>
                    <td class="tl_col_2"><label for="check_all_{{ loop.index }}" style="color:#a6a6a6"><em>{{ 'select_all'|trans }}</em></label></td>
                  </tr>
                  {% for md5, command in commands %}
                    <tr>
                      <td class="tl_col_1"><input type="checkbox" name="sql[]" id="sql_{{ loop.parent.loop.index }}_{{ loop.index }}" class="tl_checkbox {{ category }}" value="{{ md5 }}"{% if 'DROP' not in command or 'DROP INDEX' in command %} checked{% endif %}></td>
                      <td class="tl_col_2"><pre><label for="sql_{{ loop.parent.loop.index }}_{{ loop.index }}">{% if 'CREATE' in command %}{{ command|doctrine_pretty_query }}{% else %}{{ command }}{% endif %}</label></pre></td>
                    </tr>
                  {% endfor %}
                {% endif %}
              {% endfor %}
              </table>
            </div>
          </div>
          <div class="tl_formbody_submit">
            <div class="tl_submit_container">
              <button type="submit" class="tl_submit">{{ 'update_save'|trans }}</button>
            </div>
          </div>
        </form>
      {% endif %}
    </div>
  </fieldset>
  <fieldset class="tl_box{% if has_admin %} collapsed{% endif %}">
    <legend onclick="this.getParent().toggleClass('collapsed')">{{ 'template_import'|trans }}</legend>
    <div>
      <h3>{{ 'template_import'|trans }}</h3>
      {% if import_error is defined %}
        <p class="tl_error">{{ import_error|nl2br }}</p>
      {% elseif import_date is defined %}
        <p class="tl_confirm">{{ 'imported_on'|trans([import_date]) }}</p>
      {% else %}
        <p class="tl_info">{{ 'import_data_will_be_deleted'|trans }}</p>
      {% endif %}
      <p>{{ 'template_import_explain'|trans|raw }}</p>
      <form method="post">
        <div class="tl_formbody_submit">
          <input type="hidden" name="FORM_SUBMIT" value="tl_template_import">
          <input type="hidden" name="REQUEST_TOKEN" value="{{ request_token }}">
          <h4><label for="template">{{ 'templates'|trans }}</label></h4>
          <select name="template" id="template" class="tl_select" required>
            <option value="">-</option>
            {% for template in templates %}
              <option value="{{ template }}">{{ template }}</option>
            {% endfor %}
          </select>
          <div class="tl_checkbox_container" style="margin-top:3px">
            <input type="checkbox" name="preserve" id="ctrl_preserve" class="tl_checkbox" value="1"> <label for="ctrl_preserve">{{ 'do_not_truncate'|trans }}</label>
          </div>
        </div>
        <div class="tl_formbody_submit">
          <div class="tl_submit_container">
            <button type="submit" class="tl_submit" onclick="if(!confirm('{{ 'import_confirm'|trans }}'))return false;Backend.getScrollOffset()">{{ 'template_save'|trans }}</button>
          </div>
        </div>
      </form>
    </div>
  </fieldset>
  {% if not hide_admin %}
    <fieldset class="tl_box{% if has_admin %} collapsed{% endif %}">
      <legend onclick="this.getParent().toggleClass('collapsed')">{{ 'admin_create'|trans }}</legend>
      <div>
        <h3>{{ 'admin_create'|trans }}</h3>
        {% if admin_error is defined %}
          <p class="tl_error">{{ admin_error }}</p>
        {% elseif has_admin %}
          <p class="tl_confirm">{{ 'admin_confirm'|trans }}</p>
        {% endif %}
        <p>{{ 'admin_create_explain'|trans }}</p>
        {% if not has_admin %}
          <form method="post">
            <div class="tl_formbody">
              <input type="hidden" name="FORM_SUBMIT" value="tl_admin">
              <input type="hidden" name="REQUEST_TOKEN" value="{{ request_token }}">
              <h4><label for="username">{{ 'admin_username'|trans }}</label></h4>
              {% if admin_username_error is defined %}
                <p class="tl_error">{{ admin_username_error }}</p>
              {% endif %}
              <input type="text" name="username" id="username" class="tl_text" value="{{ admin_username_value|default }}" required>
              <h4><label for="name">{{ 'admin_name'|trans }}</label></h4>
              <input type="text" name="name" id="name" class="tl_text" value="{{ admin_name_value|default }}" required>
              <h4><label for="email">{{ 'admin_email'|trans }}</label></h4>
              {% if admin_email_error is defined %}
                <p class="tl_error">{{ admin_email_error }}</p>
              {% endif %}
              <input type="email" name="email" id="email" class="tl_text" value="{{ admin_email_value|default }}" required>
              <h4><label for="password">{{ 'password'|trans }}</label></h4>
              {% if admin_password_error is defined %}
                <p class="tl_error">{{ admin_password_error }}</p>
              {% endif %}
              <input type="password" name="password" id="password" class="tl_text" value="{{ admin_password_value|default }}" required>
            </div>
            <div class="tl_formbody_submit">
              <div class="tl_submit_container">
                <button type="submit" class="tl_submit">{{ 'admin_save'|trans }}</button>
              </div>
            </div>
          </form>
        {% endif %}
      </div>
    </fieldset>
    {% if has_admin %}
      <fieldset class="tl_box last">
        <legend onclick="this.getParent().toggleClass('collapsed')">{{ 'installation_complete'|trans }}</legend>
        <div>
          <h3>{{ 'congratulations'|trans }}</h3>
          <p class="tl_confirm">{{ 'congratulations_explain'|trans }}</p>
          <p>{{ 'installation_complete_explain'|trans }}</p>
        </div>
      </fieldset>
      <p id="back_end"><a href="{{ path('contao_backend', [], true) }}">{{ 'back_end'|trans }} ›</a></p>
    {% endif %}
  {% endif %}
{% endblock %}
