{% extends 'base.html' %}


{% block body %}
  <form name='newdomain' method='post'>
    {% csrf_token %}
    {% if not 'EDITUSERNEW' in securitylist %}
    <button class="btn btn-primary" type="submit" name='Nuova Email' value="Nuova Email">Nuova Email</button>
    {% endif %}
    <button class="btn btn-secondary" type="submit" name='Lista Email' value="Lista Email">Lista Stampabile Email</button>
    {% if not 'USERSHOWCLEARPASSWORD' in securitylist %}
    <button class="btn btn-secondary" type="button" data-toggle='modal' data-target='#NotaDom{{ dominio.id }}' name='Comunicazioni' value="comunicazioni">Comunicazione a tutti</button>
    {% endif %}
    <button class='btn btn-secondary' type='button' name='EMDT' value='EMDT' data-toggle='modal' data-target='#ConfirmAllDelete'>Elimina tutte le Email Disattivate</button>
    <button class='btn btn-secondary' type='submit' name='ritorno' value='ritorno'>Indietro</button>

  </form>
  <table class='table table-striped table-hover'>
    <thead class='thead-dark'>
      <tr>
        <th scope='col'>#</th>
        <th scope='col'>Mail</th>
        <th scope='col'>Nome</th>
        <th scope='col'>*</th>
        <th scope='col'>l</th>
        <th scope='col'>Quota/Warn/Limit</th>
        <th scpèe='col'>Agg.Pass</th>
        <th scope='col'>Attività</th>
      </tr>
    </thead>
    <tbody>
      <form name="userlist" method="POST">
      {% csrf_token %}
      {% for u in userlist %}
        <tr class='{% if not u.enabled %} table-dark {% else %} {% endif %}' {% if u.securitylevel.id == 5 %}*{% endif %}>
	<td> {{ u.id }} {% if u.securitylevel.id == 5 %} * {% endif %}</td>
	<td {% if 'USERSHOWPASSWORD' in securitylist %} data-toggle='tooltip' title='{{ u.clear }}' {% endif %}> {{ u.mail }} </td>
        <td> {{ u.nome }} </td>
        <td>{% if u.enabled %}*{% else %}-{% endif %}</td>
	<td>{{ u.securitylevel.id }}</td>
	<td>{{ u.mail_quota }}Mb/{% if u.warning_mail_quota == 0 %}--{% else %}{{ u.warning_mail_quota }}{% endif %}Mb/{% if u.limit_mail_quota == 0 %}--{% else %}{{ u.limit_mail_quota }}{% endif %}Mb
        <td>{% if u.last_password_update %}{{ u.last_password_update }}{% endif %}</td>
	<td><button class='btn btn-primary' type="submit" name='editbutton' value="{{ u.id }}"{% if not u.enabled %} disabled {% endif %}{% if u.tobedeleted %} disabled {% endif %}>Edit</button>
	<button class='btn btn-primary' type='button' data-toggle='modal' data-target='#ConfirmEnableDisable{{ u.id }}' name='enabledisablebutton' value='{{ u.id }}' {% if u.tobedeleted %} disabled {% endif %}> {% if u.enabled %}Disabilita{% else %}Abilita{% endif %}</button>
	    <button class='btn btn-primary' type='submit' name='enablepassword' value='{{ u.id }}' {% if u.enabled %} disabled {% endif %}{% if u.tobedeleted %} disabled {% endif %}>Enable & Password</button>
	    <button class='btn btn-primary' data-toggle='modal' data-target='#ConfirmToBeDeleted{{ u.id }}' type='button' name='tobedeletedbutton' value='{{ u.id }}' {% if u.enabled %} disabled {% endif %}>{% if u.tobedeleted %}In Cancellazione{% else %}Cancellabile{% endif %}</button>
	<button type='submit' class='btn btn-primary' name='sendInfoToAdmin' id='sendInfoToAdmin' value='{{ u.id }}' >Invia Info ad Admin</button>
	</td>
      </tr>
      <!-- Modal -->
      <div class="modal fade" id="ConfirmEnableDisable{{ 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-title" 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">
	      {% if u.enabled %}
              Sei sicuro di voler disattivare questo indirizzo Email?
	      {% else %}
	      Vuoi riattivare questo indirizzo Email?
	      {% endif %}
            </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="enabledisablebutton" value="{{ u.id }}">Conferma</button>
            </div>
          </div>
        </div>
      </div>
    </tbody>
    {{ securitylist }}
      <!-- Modal -->
      <div class="modal fade" id="ConfirmToBeDeleted{{ u.id }}" tabindex="-1" role="dialog" aria-labelledby="elemento da impostare per la cancellazione" aria-hidden="true">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <h5 class="modal-title" 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">
              {% if not u.tobedeleted %}
              Sei sicuro di voler impostare la futura cancellazione per questo elemento?
	      {% else %}
	      Vuoi Recuperare questo Elemento?
	      {% endif %}
            </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="tobedeletedbutton" value="{{ u.id }}">Conferma</button>
            </div>
          </div>
        </div>
      </div>

      {% endfor %}
    </tbody>

    <!-- Modal -->
    <div class="modal fade" id="NotaDom{{ dominio.id }}" tabindex="-1" role="dialog" aria-labelledby="Nota" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLongTitle">Nota</h5>
	  </div>
	  <div clasS='modal-body'>
	    <div class='form-check form-group'>
              <label for='recupero'>Recupero Ultimo messaggio?</label>
              <input type='checkbox' class='form-check-input' id='recupero' name='recupero'>
            </div>

	    <div class='form-group'>
              <label for='soggetto'>Soggetto</label>
              <input type='text' class='form-control' id='soggetto' name='soggetto' placeholder='soggetto' value='{{ nota.soggetto.value }}'>
            </div>

	    <div class='form-group'>
              <label for='oggetto'>Comunicazione</label>
              <textarea class='form-control' rows='3' id='oggetto' name='oggetto' placeholder='note e comunicazioni' >{{ nota.oggetto.value }}</textarea>
            </div>
            <div><br></div>
	    <div class='form-check form-group'>
	      <label for='conferma'>Conferma?</label>
              <input type='checkbox' class='form-check-input' id='conferma' name='conferma'>
            </div>
	  </div>
	  <div class='modal-footer'>
            <button type='submit' name='notaSubmit' class='btn btn-secondary'>Conferma</button>
            <button type='reset' class='btn btn-secondary'>Reset</button>
            <button type='submit' class='btn btn-secondary' name="Ritorno">Ritorno (Senza salvare)</button>
          </div>
        </div>
      </div>
    </div>

    <!-- Modal -->
    <div class="modal fade" id="ConfirmAllDelete" tabindex="-1" role="dialog" aria-labelledby="Cancellare tutte le email disattivate." aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLongTitle">Conferma Cancellazione per tutte le email disattivate.</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
          Impostare per la cancellazione immediata tutte le Email Disattivate?
          </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="alldeletedbutton" value="alldeletedbutton">Conferma</button>
          </div>
        </div>
      </div>
    </div>

</form>
</div>


{% endblock %}


