{% extends 'base.html' %}

{% block top %}
  <p>
    utente che sta effettuando gli aggiornamenti {{ utenteautorizzato.mail }}@{{ utenteautorizzato.domain.nome }}
  </p>
  {% if dominio %}
    <p>
      Dominio su cui si sta' lavorando: {{ dominio.nome }}
    </p>
  {% endif %}
  {% if user %}
    <p>
      si stanno effettuando aggiornamenti su: {{ user.mail }}@{{ user.domain.nome }}
    </p>
  {% endif %}
{% endblock %}

{% block body %}
  <form name='sqllist' method='post'>
    {% csrf_token %}
    {% if not 'EDITSQLNEW' in securitylist %}
    <button class="btn btn-primary" type="submit" name='NuovoSqlDatabase' value="Nuovo database">Nuovo Database</button>
    <button type='submit' class='btn btn-secondary' name='BackupDbDom' {% if not has_http_server %}disabled {% endif %}>Backup di tutti i Database del dominio</button>
    <button type='submit' class='btn btn-secondary' name='AggiornaDbConf' {% if not has_http_server %}disabled {% endif %}>Aggiorna db.conf</button>
    <button type='submit' class='btn btn-secondary' name='LeggiDbConf' {% if not has_http_server %}disabled {% endif %}>Leggi db.conf</button>
      {% if not has_http_server %}
    <button type='button' class='btn btn-secondary'>!! Non risulta indicato il server HTTP !!</button>
      {% endif %}
    {% endif %}
  </form>
  <table class='table'>
    <thead>
      <tr>
        <th scope='col'>Nome</th>
        <th scope='col'>Username</th>
        <th scope='col'>Server</th>
        <th scope='col'>L</th>
        <th scope='col'>E</th>
	<th scope='col'>D</th>
        <th scope='col'>quota</th>
	<th scope='col'>backup manuale</th>
        <th scope='col'>Attività</th>
      </tr>
    </thead>
    <tbody>
      <form name="userlist" method="POST">
      {% csrf_token %}
      {% for u in sqldatabaselist %}
        <tr>
          <td> {{ u.nome }} - id: {{ u.id }}<br>{{ u.nota }}</d>
          <td> {{ u.username }} </td>
	  <td> {{ u.server.nome }}</td>
	  <td>{% if u.locked %}*{% else %}-{% endif %}</td>
          <td>{% if u.enabled %}*{% else %}-{% endif %}</td>
          <td>{% if u.tobedeleted%}*{% else %}-{% endif %}</td>
	  <td>{{ u.quota }}</td>
	  <td>{% if u.inbackup %}In corso{% else %} {% if u.datebackup %}{{ u.datebackup }}{% endif %}{% endif %}</td>
	  <td><button class="btn btn-primary" type="submit" name='edit' value="{{ u.id }}"{% if not u.enabled %} disabled {% endif %}>Edit</button>

	      <button class="btn {% if not u.enabled %} btn-secondary {% else %} btn-primary {% endif %}" type="button" name='disable' value='{{ u.id }}' data-toggle='modal' data-target='#ConfirmDisable{{ u.id }}' {% if not u.enabled %} disabled {% endif %}>Disabilitato</button>

              <button class="btn {% if u.enabled %} btn-secondary {% else %} btn-primary {% endif %}" type="submit" name='enable' value="{{ u.id }}" {% if u.enabled %} disabled {% endif %}>Abilitato</button>

	      {% if not u.enabled and not u.locked %}
 	        <button class="btn btn-primary" type="button" name='delete' value='{{ u.id }}' data-toggle='modal' data-target='#ConfirmDelete{{ u.id }}'> 
		{% if not u.tobedeleted %}Cancella{% else %}Cancellazione impostata{% endif %}</button>
              {% else %}
  	        <button class="btn btn-secondary" type="button" name='delete' disabled>{% if not u.tobedeleted %}Cancella{% else %}Cancellazione impostata{% endif %}</button>
              {% endif %}
              <button class="btn btn-secondary" type='button' name='backup' value='{{ u.id }}' data-toggle='modal' data-target='#ConfirmBackup{{ u.id }}' {% if not u.enabled %} disabled {% endif %}>Backup</button>
	      <button type='submit' class="btn btn-secondary" type='button' name='phpmyadmin' value='{{ u.id }}'>PMA</button></td>
        </tr>

        <!-- Modal -->
        <div class="modal fade" id="ConfirmDisable{{ u.id }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
          <div class="modal-dialog" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <h5 class="modal fade" id="exampleModalLongTitle">Conferma Disattivazione</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span>
                </button>
              </div>
              <div class="modal-body">
                Sei sicuro di voler disattivare questo Database?
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="submit" class="btn btn-primary" name="disable" value="{{ u.id }}">Conferma</button>
              </div>
            </div>
          </div>
        </div>

        <!-- Modal -->
        <div class="modal fade" id="ConfirmDelete{{ u.id }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
          <div class="modal-dialog" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <h5 class="modal fade" id="exampleModalLongTitle">Conferma Cancellazione</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span>
                </button>
              </div>
              <div class="modal-body">
                Sei sicuro di voler impostare la cancellazioen per  questo Database?
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
		<button type="submit" class="btn btn-primary" name="delete" value="{{ u.id }}">Cancellazione</button>
              </div>
            </div>
          </div>
        </div>

        <!-- Modal -->
        <div class="modal fade" id="ConfirmBackup{{ u.id }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
          <div class="modal-dialog" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <h5 class="modal fade" id="exampleModalLongTitle">Conferma Backup</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span>
                </button>
              </div>
              <div class="modal-body">
                Vuoi effettuare il backup di questo db?
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="submit" class="btn btn-primary" name="backup" value="{{ u.id }}">Conferma</button>
              </div>
            </div>
          </div>
        </div>

      {% endfor %}
      </form>
    </tbody>
{% endblock %}

{% block bodybottom %}
<ul class="list-group">
  <li class="list-group-item">L: Locked - non si possono modificare i parametri registrati</li>
  <li class="list-group-item">E: Enabled - il database è abilitato e utilizzabile</li>
  <li class="list-group-item">D: ToBeDeleted - il database è disattivato e pronto per essere cancellato</li>
</ul>
{% endblock %}

