{% extends 'base.html' %}

{% block top %}
  <p>
    utente che sta effettuando gli aggiornamenti {{ utenteautorizzato.mail }}@{{ utenteautorizzato.domain.nome }}
  </p>
{% endblock %}

{% block body %}

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

<form name='FormCausale' method='post'>
    {% csrf_token %}

    <div class='form-inline'>
      <div class='form-group mb-2'>
        <label for='nome'>Nome Causale</label>
	<input type='text' class='form-control' id='nome' name='nome' placeholder='causale' value='{{ formcausale.nome.value }}'>
      </div>
      <div class='form-check-inline form-group mb-3'>
	<label for='enabled' class='form-check-label'>Abilitato</label>
        <input type='checkbox' class='form-check-input' id='enabled' name='enabled' {% if formcausale.enabled.value %} checked {% endif %}>
      </div>
      <div class='form-group mb-4'>
        <label for='valore'>Valore</label>
	<input type='integer' class='form-control' id='valore' name='valore' value='{{ formcausale.valore.value }}'>
	<label for='ordine'>Ordine</label>
	<input type='integer' class='form-control' id='ordine' name='ordine' value='{{ formcausale.ordine.value }}'>
      </div>
    </div>
    <div class='form-group mb-4'>
      <label for 'domain_service'>Servizio Associato</label>
      <select class='form-select' id='domain_service' name='domain_service'>
        <option value="0">-- -- --</option>
        {% for i in servizi %}
	<option value="{{ i.id }}" {% if i.id|stringformat:'s' == formcausale.domain_service.value|stringformat:'s' %} selected {% endif %}>{{ i.id }} - {{ i.nome }}</option>
        {% endfor %}
      </select>
    </div>
    <hr>

    <div class='input-group my-2'> <!-- sezione invio mail all'utente -->
      <label for='send_email_user' class='form-check-label pe-2'>Invia la mail al/agli utenti registrati per il dominio</label>
      <input type='checkbox' class='form-check-input' id='send_email_user' name='send_email_user' {% if formcausale.send_email_user.value %}checked{% endif %}>
      <label for='template' class='form-select-label px-2'>Template: </label>
      <select class='form-select' id='template' name='template'>
        <option value="0">-- -- --</option>
        {% for i in template %}
	<option value="{{ i.id }}" {% if i.id|stringformat:'s' == formcausale.template.value|stringformat:'s' %} selected {% endif %}>{{ i.id }} - {{ i.nome }}</option>
        {% endfor %}
      </select>
    </div>


    <div class='input-group my-2'> <!-- sezione invia la mail al/agli amministratori del pannello -->
      <label for='send_email_admin' class='form-check-label pe-2'>Invia Mail Agli Amministratori</LAbel>
      <input type='checkbox' class='form-check-input' id='send_email_admin' name='send_email_admin' {% if formcausale.send_email_admin.value %} checked {% endif %}>
      <label for='send_email_user' class='form-label px-2'>Mail Amministratori:</label>
      <input type='text' class='form-control' id='to_admin' name='to_admin' value='{{ formcausale.to_admin.value }}'></input>
      <label for='template' class='form-select-label px-2'>Template: </label>
      <select class='form-select' id='template_admin' name='template_admin'>
        <option value="0">-- -- --</option>
        {% for i in template %}
	<option value="{{ i.id }}" {% if i.id|stringformat:'s' == formcausale.template_admin.value|stringformat:'s' %} selected {% endif %}>{{ i.id }} - {{ i.nome }}</option>
        {% endfor %}
      </select>
    </div>

    <div class='input-group'> <!-- sezione invia la mail alla contabilita' -->
      <label for='send_email_account' class='form-check-label pe-2'>Invia Mail Contabilita'</label>
      <input type='checkbox' class='form-check-input' id='send_email_account' name='send_email_account' {% if formcausale.send_email_account.value %} checked {% endif %}>
      <label for='to_account' class='form-label px-2'>Mail Contabilita':</label>
      <input type='text' class='form-control' id='to_account' name='to_account' value='{{ formcausale.to_account.value }}'></input>
      <label for='template' class='form-select-label px-2'>Template: </label>
      <select class='form-select' id='template_account' name='template_account'>
        <option value="0">-- -- --</option>
        {% for i in template %}
          <option value="{{ i.id }}" {% if i.id|stringformat:'s' == formcausale.template_account.value|stringformat:'s' %} selected {% endif %}>{{ i.id }} - {{ i.nome }}</option>
        {% endfor %}
      </select>

    </div>

    <div class='input-group my-2'> <!-- invio mail eventualmente ad altri account -->
      <label for='send_email_other' class='form-check-label pe-2'>Invia Mail ad Altri</label>
      <input type='checkbox' class='form-check-input' id='send_email_other' name='send_email_other' {% if formcausale.send_email_other.value %} checked {% endif %}>
      <label for='to_account' class='form-label px-2'>Mail Esterne:</label>
      <input type='text' class='form-control' id='to_other' name='to_other' value='{{ formcausale.to_other.value }}'></input>
      <label for='template' class='form-select-label px-2'>Template: </label>
      <select class='form-select' id='template_other' name='template_other'>
        <option value="0">-- -- --</option>
        {% for i in template %}
          <option value="{{ i.id }}" {% if i.id|stringformat:'s' == formcausale.template_other.value|stringformat:'s' %} selected {% endif %}>{{ i.id }} - {{ i.nome }}</option>
        {% endfor %}
      </select>

    </div>

    <div class='input-group'>
      <label for='from_email' class='form-input-label pe-2'>Mittente email:</label>
      <input type='text' class='form-control' id='from_email' name='from_email' value='{{ formcausale.from_email.value }}'></input>
    </div>

    <hr>

    <div class='row'>
      Servizi Associati:
    </div>

    <div class='form-group'>
      <label for='date_expire_contract' class='form-check-label'>Data Scadenza Contratto: </label>
      <input type='checkbox' class='form-check-input' id='date_expire_contract' name='date_expire_contract' {% if formcausale.date_expire_contract.value %} checked {% endif %}
    </div>

    <div class='form-group'>
      <label for='date_expire_registrar' class='form-check-label'>Data Scadenza Presso il Registrar: </label>
      <input type='checkbox' class='form-check-input' id='date_expire_registrar' name='date_expire_registrar' {% if formcausale.date_expire_registrar.value %} checked {% endif %}
    </div>
    <div class='form-group'>
      <label for='check_registrar' class='form-check-label'>Verifica Registrar: </label>
      <input type='checkbox' class='form-check-input' id='check_registrar' name='check_registrar' {% if formcausale.check_registrar.value %} checked {% endif %}
    </div>
    <div class='form-group'>
      <label for='domain_tobedeleted' class='form-check-label'>Dominio da Cancellare Fisicamente: </label>
      <input type='checkbox' class='form-check-input' id='domain_tobedeleted' name='domain_tobedeleted' {% if formcausale.domain_tobedeleted %}checked{% endif %}>
    </div>

    <hr>

  <div class='btn-group' role='group' aria-label='conferme'>
    <button type='submit' class='btn btn-primary'>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>

  </form>

{% endblock %}

  template = models.IntegerField(db_column='template')

  ##template_subject = models.CharField(db_column='template_subject',max_length=128)
  #template_txt = models.CharField(db_column='template_txt',max_length=128)
  #template_html = models.CharField(db_column='template_html',max_length=128)
  #template_sms = models.CharField(db_column='template_sms',max_length=128)

  renew_request = models.BooleanField(db_column='renew_request')
  renew_authorized = models.BooleanField(db_column='renew_authorized')
  close_request = models.BooleanField(db_column='close_request')
  domain_opened = models.BooleanField(db_column='domain_opened')
  domain_closed = models.BooleanField(db_column='domain_closed')
  domain_suspended = models.BooleanField(db_column='domain_suspended')
  domain_enabled = models.BooleanField(db_column='domain_enabled')
  domain_tobedeleted = models.BooleanField(db_column='domain_tobedelete')
  transferring_in = models.BooleanField(db_column='transferring_in')
  transferring_out = models.BooleanField(db_column='transferring_out')
  transferred_in_complete = models.BooleanField(db_column='transferred_in_complete')
  transferred_out_complete = models.BooleanField(db_column='transferred_out_complete')
  domain_service = models.ForeignKey('Service',db_column='domain_service',on_delete=models.PROTECT)
  domain_service_active = models.BooleanField(db_column='domain_service_active')
  domain_expired = models.BooleanField(db_column='domain_expired')
  mail_opened = models.BooleanField(db_column='mail_opened')
  mail_closed = models.BooleanField(db_column='mail_closed')
  mail_tobedeleted = models.BooleanField(db_column='mail_tobedeleted')
  mail_password= models.BooleanField(db_column='mail_password')
  mail_resend = models.BooleanField(db_column='mail_resend')
  mail_test = models.BooleanField(db_column='mail_test')
  payment_ok = models.BooleanField(db_column='payment_ok')
  payment_ko = models.BooleanField(db_column='payment_ko')
  ordine = models.IntegerField(db_column='ordine')
  template = models.ForeignKey("template.Template",db_column="template",on_delete=models.PROTECT)
  renew_code = models.BooleanField(db_column='renew_code',default=0)
  erase = models.BooleanField(db_column='erase',default=0)
  automatico = models.BooleanField(db_column='automatico',default=0)

