{% extends 'base.html' %}

{% block title %}{{ _("Settings") }} - {{ super() }} {% endblock %}
{% block subtitle %}{{ _("Settings") }}{% endblock %}

{% block head %}
<script type="text/javascript" src="{{url_for('static', filename='vendor/MooTools/TinyTab/tinytab.js')}}"></script>
<script type="text/javascript" src="{{url_for('static', filename='vendor/MooTools/MooDropMenu/MooDropMenu.js')}}"></script>
<script type="text/javascript" src="{{theme_template('js/settings.js')}}"></script>
{% endblock %}

{% block content %}
    <ul id="toptabs" class="tabs">
            <li><a class="selected" href="#">{{ _("General") }}</a></li>
            <li><a href="#">{{ _("Plugins") }}</a></li>
            <li><a href="#">{{ _("Accounts") }}</a></li>
            {% if user.is_admin %}
            <li><a href="#">{{ _("Admin") }}</a></li>
            {% endif %}
    </ul>

    <div id="tabsback" style="height: 20px; padding-left: 150px; color: white; font-weight: bold;"></div>

    <span id="tabs-body">
            <!-- General -->
            <span id="general" class="active tabContent">
                <ul class="nav tabs">
                    <li class>
                        <a>Menu</a>
                        <ul id="general-menu">
                            {% for entry,name in conf.general %}
                                <nobr>
                                    <li id="core|{{ entry }}">{{ name }}</li>
                                </nobr>
                                <br>
                            {% endfor %}
                        </ul>
                    </li>
                </ul>

                <form id="core_form" action="" method="POST" autocomplete="off">
                    <span id="general_form_content">
                    <br>
                    <h3>&nbsp;&nbsp; {{ _("Choose a section from the menu") }}</h3>
                    <br>
                    </span>

                  <input id="core|submit" class="styled_button" type="submit" value="{{_("Submit")}}"/>
                </form>
            </span>

            <!-- Plugins -->
            <span id="plugins" class="tabContent">
                <ul class="nav tabs">
                    <li class>
                        <a>Menu</a>
                        <ul id="plugin-menu">
                            {% for entry,name in conf.plugin %}
                                <nobr>
                                    <li id="plugin|{{ entry }}">{{ name }}</li>
                                </nobr>
                                <br>
                            {% endfor %}
                        </ul>
                    </li>
                </ul>


                 <form id="plugin_form" action="" method="POST" autocomplete="off">

                     <span id="plugin_form_content">
                    <br>
                    <h3>&nbsp;&nbsp; {{ _("Choose a section from the menu") }}</h3>
                    <br>
                         </span>
                     <input id="plugin|submit" class="styled_button" type="submit" value="{{_("Submit")}}"/>
                </form>

            </span>

            <!-- Accounts -->
            <span id="accounts" class="tabContent">
              <form id="account_form" action="{{url_for('json.update_accounts')}}" method="POST">
                <table class="settable wide">
                  <thead>
                  <tr>
                      <th>{{ _("Plugin") }}</th>
                      <th>{{ _("Name") }}</th>
                      <th>{{ _("Password") }}</th>
                      <th>{{ _("Status") }}</th>
                      <th>{{ _("Premium") }}</th>
                      <th>{{ _("Valid until") }}</th>
                      <th>{{ _("Traffic left") }}</th>
                      <th>{{ _("Time") }}</th>
                      <th>{{ _("Max Parallel") }}</th>
                      <th>{{ _("Delete?") }}</th>
                  </tr>
                  </thead>

                  {% for account in conf.accs %}
                    {% set plugin = account.type %}
                    <tr>
                      <td><span style="padding:5px">{{ plugin }}</span></td>
                      <td><label for="{{ plugin }}|password;{{ account.login }}" style="color:#424242;">{{ account.login }}</label></td>
                      <td><input id="{{ plugin }}|password;{{ account.login }}" name="{{ plugin }}|password;{{ account.login }}" type="password" value="{{ account.password }}" size="12"/></td>
                      <td>
                        {% if account.valid %}
                           <span style="font-weight: bold; color: #006400;">{{ _("valid") }}
                         {% else %}
                           <span style="font-weight: bold; color: #8b0000;">{{ _("not valid") }}
                         {% endif %}
                         </span>
                      </td>
                      <td>
                        {% if account.premium %}
                          <span style="font-weight: bold; color: #006400;">{{ _("yes") }}
                        {% else %}
                          <span style="font-weight: bold; color: #8b0000;">{{ _("no") }}
                        {% endif %}
                         </span>
                      </td>
                      <td><span style="font-weight: bold;">{{ account.validuntil }}</span></td>
                      <td><span style="font-weight: bold;">{{ account.trafficleft }}</span></td>
                      <td><input id="{{ plugin }}|time;{{ account.login }}" name="{{ plugin }}|time;{{ account.login }}" type="text" size="7" value="{{ account.time }}"/></td>
                      <td><input id="{{ plugin }}|limitdl;{{ account.login }}" name="{{ plugin }}|limitdl;{{ account.login }}" type="text" size="2" value="{{ account.limitdl }}"/></td>
                      <td><input id="{{ plugin }}|delete;{{ account.login }}" name="{{ plugin }}|delete;{{ account.login }}" type="checkbox" value="True"/></td>
                    </tr>
                  {% endfor %}
                </table>

                <button id="account_submit" type="submit" class="styled_button">{{_("Submit")}}</button>
                <button id="account_add" style="margin-left: 0" type="submit" class="styled_button">{{_("Add")}}</button>
              </form>
            </span>

          <!-- Admin -->
          {% if user.is_admin %}
            <span id="general" class="active tabContent">

              <div style="margin: 15px">
                <a href="#" id="quit-pyload" style="font-size: large; font-weight: bold;">{{_("Quit pyLoad")}}</a> |
                <a href="#" id="restart-pyload" style="font-size: large; font-weight: bold;">{{_("Restart pyLoad")}}</a>
              </div>

              {{ _("To reset default admin login run:") }} <b>pyload -r</b><br>
              {{ _("Important: Admin user have always all permissions!") }}

              <form id="user_form" action="{{url_for('json.update_users')}}" method="POST">
                <table class="settable wide">
                  <thead style="font-size: 11px">
                    <tr>
                      <th>{{ _("Name") }}</th>
                      <th>{{ _("Change Password") }}</th>
                      <th>{{ _("Admin") }}</th>
                      <th>{{ _("Permissions") }}</th>
                      <th>{{ _("Delete?") }}</th>
                    </tr>
                    </thead>

                  {% for name, data in conf.admin.users.items() %}
                    <tr>
                      <td>{{ name }}</td>
                      <td><a class="change_password" href="#" id="change_pw|{{name}}">{{ _("change") }}</a></td>
                      <td>
                        {% if user.name == name %}
                          <input class="is_admin" name="{{ name }}|admin" type="checkbox" {% if data.perms.admin %}checked="checked" disabled="disabled" {% endif %}>
                          <input name="{{ name }}|admin" type="checkbox" {% if data.perms.admin %}checked="checked" hidden="hidden" {% endif %}>
                        {% else %}
                          <input class="is_admin" name="{{ name }}|admin" type="checkbox" {% if data.perms.admin %}checked="checked" {% endif %}>
                        {% endif %}
                      </td>
                      <td>
                        <select id="{{ name }}|perms" multiple="multiple" size="{{ conf.admin.permlist|length }}" name="{{ name }}|perms" {% if data.perms.admin %} disabled="disabled" {% endif %}>
                          {% for perm in conf.admin.permlist %}
                            {% if data.perms[perm] %}
                              <option selected="selected">{{ perm }}</option>
                            {% else %}
                              <option>{{ perm }}</option>
                            {% endif %}
                          {% endfor %}
                        </select>
                      </td>
                      {% if user.is_admin %}
                      <td>
                        {% if user.name != name %}
                          <input id="{{name}}|delete" name="{{name}}|delete" type="checkbox" value="True"/>
                        {% endif %}
                      </td>
                      {% endif %}
                    </tr>
                  {% endfor %}

                </table>

                <button id="user_submit" class="styled_button" type="submit">{{ _("Submit") }}</button>
                <button id="user_add" style="margin-left: 0" type="submit" class="styled_button">{{_("Add")}}</button>
              </form>
            </span>
          {% endif %}
        </span>
{% endblock %}
{% block hidden %}
<div id="account_box" class="window_box" style="z-index: 2">
  <form id="add_account_form" action="{{url_for('json.add_account')}}" method="POST" enctype="multipart/form-data">
    <h1>{{_("Add Account")}}</h1>
    <p>{{_("Enter your account data to use premium features.")}}</p>
    <label for="account_login">{{_("Login")}}<span class="small">{{_("Your username.")}}</span></label>
    <input id="account_login" name="account_login" type="text" size="20" />

    <label for="account_password">{{_("Password")}}<span class="small">{{_("The password for this account.")}}</span></label>
    <input id="account_password" name="account_password" type="password" size="20" />

    <label for="account_type">{{_("Type")}}<span class="small">{{_("Choose the hoster for your account.")}}</span></label>
    <select name=account_type id="account_type">
      {% for type in types|sort %}
        <option value="{{ type }}">{{ type }}</option>
      {% endfor %}
    </select>

    <button id="account_add_button" type="submit">{{_("Add")}}</button>
    <button id="account_reset" style="margin-left: 0" type="reset">{{_("Reset")}}</button>
    <div class="spacer"></div>
  </form>
</div>

<div id="password_box" class="window_box" style="z-index: 2">
  <form id="password_form" action="{{url_for('json.change_password')}}" method="POST" enctype="multipart/form-data">
    <h1>{{ _("Change Password") }}</h1>

    <p>{{ _("Enter your current and desired Password.") }}</p>
    <label for="user_login">{{ _("User") }}<span class="small">{{ _("Your username.") }}</span></label>
    <input id="user_login" name="user_login" type="text" size="20" readonly style="background-color: #eaeaea; cursor: not-allowed"/>

    <label for="login_current_password">{{ _("Current password") }}<span class="small">{{ _("The password for this account.") }}</span></label>
    <input id="login_current_password" name="login_current_password" type="password" size="20"/>

    <label for="login_new_password">{{ _("New password") }}<span class="small">{{ _("The new password.") }}</span></label>
    <input id="login_new_password" name="login_new_password" type="password" size="20"/>

    <label for="login_new_password2">{{ _("New password (repeat)") }}<span class="small">{{ _("Please repeat the new password.") }}</span></label>
    <input id="login_new_password2" name="login_new_password2" type="password" size="20"/>

    <button id="login_password_button" type="submit">{{ _("Submit") }}</button>
    <button id="login_password_reset" style="margin-left: 0" type="reset">{{ _("Reset") }}</button>
    <div class="spacer"></div>
  </form>
</div>

<div id="user_box" class="window_box" style="z-index: 2">
  <form id="user_add_form" action="{{url_for('json.add_user')}}" method="POST" enctype="multipart/form-data">
    <h1>{{ _("Create new pyLoad login") }}</h1>

    <p>{{ _("Enter new user name and password.") }}</p>
    <label for="new_user">{{ _("Login") }}<span class="small">{{ _("New username.") }}</span></label>
    <input id="new_user" name="new_user" type="text" size="20" autocomplete="off"/>

    <label for="new_password">{{ _("Password") }}<span class="small">{{ _("The password for the new login.") }}</span></label>
    <input id="new_password" name="new_password" type="password" size="20"/>

    <label for="new_password2">{{ _("Password (repeat)") }}<span class="small">{{ _("Please repeat the password.") }}</span></label>
    <input id="new_password2" name="new_password2" type="password" size="20"/>

    <label for="new_role">{{ _("Admin") }}<span class="small">{{ _("Shall the user be an admin?") }}</span></label>
    <input id="new_role" name="new_role" type="checkbox" />

    <label for="new_perms">{{ _("Permissions") }}<span class="small">{{ _("Permmisions for the new user.") }}</span></label>
    <select multiple="multiple" id="new_perms" size="{{conf.admin.permlist|length}}" name="new_perms">
      {% for perm in conf.admin.permlist %}
        <option>{{perm}}</option>
      {% endfor %}
    </select>

    <button id="new_user_button" type="submit">{{ _("Submit") }}</button>
    <button id="new_user_reset" style="margin-left: 0" type="reset">{{ _("Reset") }}</button>
    <div class="spacer"></div>
  </form>
</div>
{% endblock %}
