{% extends 'base.html' %}

{% block headersupplement %}
  <script>
    function updatepasswordchanged() {
      document.getElementById('passwordchanged').value=1;
    }
function getJsonPassword() {
        jQuery.noConflict();
        $.getJSON('/dashboard4/configurazione',
                  function(data) {
                    console.log(data);
                    $('#clear').val(data.newPassword);
                    $('#password1').val(data.newPassword);
                    $('#password2').val(data.newPassword);
                    $('#password1').get(0).type='text';
                    $('#password2').get(0).type='text';
                   });
    }
  </script>
    <script>
    function setPasswordField() {
     if( $('#password_change_enabled').is(":checked")) {
       $('#password1').attr('readonly',false);
       $('#password2').attr('readonly',false);
       $('#UpdatePWD').attr('disabled',false);
       $('#UpdatePWD').click(getJsonPassword);
     } else {
       $('#password1').attr('readonly',true);
       $('#password2').attr('readonly',true);
       $('#UpdatePWD').attr('disabled',true);
       $('#UpdatePWD').click(false);
     }
   };
  </script>
  <script>
    $(document).ready(function() { setPasswordField(); });
  </script>
  <script>
    $(function () {
      $('updatepwd').popover({
        container: 'body'
      });
    });
  </script>

{% endblock %}

{% block top %}
  <p>
    utente che sta effettuando gli aggiornamenti {{ utenteautorizzato.mail }}@{{ utenteautorizzato.domain.nome }}
  </p>
  {% if user %}
    <p>
      si stanno effettuando aggiornamenti su: {{ formftp.utente.value }}@{{ formftp.dominio_domain.value }}
    </p>
    <p>Home attuale: {{ formftp.homedir.value }}</p>
  {% endif %}
{% endblock %}
{% block body %}

<div>Pannello Controllo Ftp - Aggiornamento</div>
<div></div>

<div>
  <br>
  <div>
    {% if formftp.errors %}
       <p>Rilevati Errori, impossibile proseguire.</p>
       <br>
       {% for f in formftp %}
         {% for e in f.errors %}
           <div class="alter alter-danger">
             <strong>{{f.label|escape }}: {{ e|escape }}</strong>
           </div>
         {% endfor %}
       {% endfor %}
       {% for e in formemail.non_field_errors %}
         <div class="alter alter-danger">
           <strong>{{ e|escape }}</strong>
         </div>
       {% endfor %}
     {% endif %}
   </div>
   </br>
</div>

<form name='ftpedit' method='post'>
  {% csrf_token %}
  <div class='row'>
    <div class='col'>
      <label for='utente'>Ftp Account</label>
      <input type='text' class='form-control' id='user' name='utente' placeholder='account ftp' value='{{ formftp.utente.value }}' {% if not CANWRITE and not 'EDITUSERNEW' in securitylist %} readonly='' {% endif %}>
    </div>
    <div class='col'>
      <label for='domain'>Dominio</label>
      <input type='text' class='form-control' id='dominio_domain' name='dominio_domain' value='{{ formftp.dominio_domain.value }}' readonly>
      <input type='hidden' name='dominio' value='{{ formftp.dominio.value }}'>
    </div>
  </div>
  <div class='row'>
    <div class='col'>
	    l'utente che si collega al server ftp si definisce come: utente @ dominio_di_appartenenza<br>
	    se l'utente e' nuovo, viene proposto un id univoco.
    </div>
  </div>

  <div class='row'>
    <br>
  </div>

 <div class='row'>
    <div class='col'>
	    <label for="ftpgroup">Posizione Home: {{ formftp.ftpgroup.value}} </label>
      <select name='ftpgroup' id='ftpgroup' class='form-control'>
        {% for g in ftpgroupv %}
          <option value='{{ g.id }}' {% if g.id|stringformat:'s' == formftp.ftpgroup.value|stringformat:'s' %}selected{% endif %}>{{g.id}}: {{ g.nomegruppo }}</option>
        {% endfor %}
      </select>
    </div>
  </div>
  <div class='row'>
    <div class='col'>
      <label for='ftpserver' class='label'>Server di accesso:</label>
      <select name='ftpserver' id='ftpserver' class='form-control' {% if not formftp.edit %}readonly{% endif %} >
        {% for s in ftpserverv %}
          <option value='{{ s.id }}' {% if s.id|stringformat:'s' == formftp.ftpserver.value|stringformat:'s'  %}selected{% endif %}>{{s.id}}: {{ s.nome }}</option>
        {% endfor %}
      </select>
   </div>
  </div>
  <div class='row'>
	  <br>
  </div>

  <div class='row'>
    <div class='col'>
      <label for='homedir'>Home</label>
      <input type='text' class='form-control' id='homedir' name='homedir' value='{{ formftp.homedir.value }}' readonly>
    </div>
  </div>
  <div class='row'>
    <div class='col'>
      Posizione fisica del server (puo' servire con alcune applicazioni).
    </div>
  </div>

   <div class='row'>
    <br>
  </div>

 <div class='row form-group' id='updatepwd'>
    <div class='col'>
      <label for='password1'>Password</label>
      <input type='password' class='form-control' id='password1' name='password1' value='{{ formftp.clear.value }}' placeholder='digita la password' {% if not 'FTPEDITPASSWORD' in securitylist %} readonly {% endif %} {% if not formftp.password_change_enabled.value %} readonly {% endif %} oninput='updatepasswordchanged()' data-toggle='popover' title='{{ ftp_password_message }}'>
    </div>
    <div class='col'>
      <label for='password2'>Ripetere</label>
      <input type='password' class='form-control' id='password2' name='password2' value='{{ formftp.clear.value }}' placeholder='ripeti la password' {% if not 'FTPEDITPASSWORD' in securitylist %} readonly {% endif %} {% if not formftp.password_change_enabled.value %} readonly {% endif %} oninput='updatepasswordchanged()'>
    </div>
    
   {% if 'FTPSHOWPASSWORD' in securitylist %}
    <div class='col'>
      <label for='clear'>In chiaro</label>
      <input type='text' class='form-control' id='clear' name='clear' value='{{ formftp.clear.value }}' readonly>
    </div>
    <div class='collapse' id='PasswordMemo'>
      <h2 class="lead">Requisiti necessari per la password</h2>
      <p class="lead">La password non deve essere di lunghezza inferiore a {{ mail_password_length }} caratteri.</p>
      <p class="lead">Non deve essere la ripetizione di quella attuale.</p>
      <p class="lead">Non devono essere presenti spazi vuoti.</p>
      <p class="lead">La password deve contenere almeno un carattere maiuscolo, uno minuscolo, un numero e un simbolo.</p>
    </div>
    {% endif %}

    {% if 'FTPEDITPASSWORD' in securitylist %}
      <div class='col'><!-- richiesta nuova password e relativo aggiornamento -->
        <label for='UpdatePWD'>Cambia Password</label>
        <button type='button' class='form-control btn btn-secondary' name='UpdatePWD' id='UpdatePWD'
		{% if formftp.password_change_enabled.value == 1 %} onclick='getJsonPassword()'>
		{% else %}Disabled>
	  {% endif %}Password</button>
      </div>
    {% endif %}

    {% if 'FTPCHANGEPASSWORD' in securitylist %}
        <div class='col form-inline'>
          <label for='password_change_enabled' class="form-check-label">Cambio password abilitato</label>
          <input type='checkbox' class='form-check-input' id='password_change_enabled' name='password_change_enabled' {% if formftp.password_change_enabled.value %} checked {% endif %} onclick='setPasswordField()'>
        </div>
    {% endif %}
 </div>
 <hr>
  <div class='row'>
    {% if 'FTPEDIT' in securitylist %}
      <div class='col form-inline'>
        <label for='edit' class='form-check-label'>Edit Parametri</label>
        <input type='checkbox' class='form-check-input' name='edit' {% if formftp.edit %} checked {% endif %}>
      </div>


      {% if 'FTPEDIT' in securitylist %}
        <div class='col form-inline'>
          <label for='enabled' class='form-check-label'>Abilitato:</label>
          <input type='checkbox' id='enabled' class='form-check-input' name='enabled' {% if formftp.enabled.value %} checked {% endif %}>
        </div>
      {% endif %} 

      {% if 'USERTOBEDELETED' in securitylist %}
        <div class='col from-inlineì>
        <label class='form-check-label' for='tobedeleted'>Da eliminare:</label>
  	 <input type='checkbox' class='form-check-input' id='tobedeleted' name='tobedeleted' {% if formftp.tobedeleted.value %} checked {% endif %}>
	</label>
	</div>
      {% endif %}
    {% endif %}
  </div>

  <hr class='half-rule'/>
    {% if 'EDITUSERINFO' in securitylist %}
      <div class='col'>
        <div class='row'>
          <label for='nota'>Note e appunti</label>
          <textarea class='form-control' rows='3' id='note' placeholder='note e appunti'>{{ formftp.nota.value }}</textarea>
        </div>
        <p></p>
        <div class='row'>
          <div class='col'>
            <label for='quota'>Quota (in Mb):</label>
            <input type='text' class='form-control' id='quota' name='quota' value='{{ ftp.quota }}' placeholder='0' readonly=''>
          </div>
          <div class='col'>
            <label for='warning_mail_quota'>Spazio suggerito (in Mb):</label>
            <input type='text' class='form-control' id='warning_mail_quota' name='warning_mail_quota' value='{{ user.warning_mail_quota }}' placeholder='{{ user.domain.warning_mail_quota }}' {%  if not 'EDITUSERWARNINGMAILQUOTA' in securitylist %} readonly='' {% endif %}> (Mbyte - il valore viene calcolato tenendo presente l'intero contenuto della casella, posta cancellata compresa')
          </div>
          <div class='col'>
            <label for='warning_mail_quota_check' class='form-check-label'>Controllo Soglia</label>
            <input type='checkbox' class='form-check-input' id='warning_mail_quota_check' name='warning_mail_quota_check' {% if user.warning_mail_quota_check %} checked {% endif %}{% if not 'EDITUSERWARNINGMAILQUOTA' in secufirtlist %} disabled {% endif %}>
          </div>
          <div class='col'>
            <label for='warning_mail_quota_send' class='form-check-label'>Avviso Superamento Soglia</label>
            <input type='checkbox' class='form-check-input' id='warning_mail_quota_send' name='warning_mail_quota_send' {% if user.warning_mail_quota_send %} checked {% endif %}{% if not 'EDITUSERWARNINGMAILQUOTA' in securitylist %} disabled {% endif %}>
          </div>
        </div>
        <p></p>
       <p></p>
  {% endif %}

  <div class='form-group'>
    <div class='row'>
      <div class='col'>
        <label class='form-check-label' for='mail_send'>Invia Credenziali</label>
        <input type='checkbox' class='form-check-input' id='mail_send' name='mail_send' {% if formftp.mail_send.value %} checked {% endif %}>
      </div>
      <div class='col'>
        <label for='mail'>Destinatario Credenziali</label>
        <input type='text' class='form-control' id='mail' name='mail' value='{{ formftp.mail.value }}'>
      </div>
    </div>
  </div>


  </div>

  <div class='form-group btn-group' role='group' aria-label='conferme'>
    <button type='submit' class='btn btn-primary'>Salva/Aggiorna</button>
    <button type='reset' class='btn btn-secondary'>Reset</button>
    <button type='submit' class='btn btn-secondary' name="Ritorno">Ritorno (Senza salvare)</button>
  </div>
</form>
</div>

{% endblock %}
