{% include 'a_header.twig' %}



          <!-- Table -->
          <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
              <div class="x_panel">
                <div class="x_title">
                  <h2>Usuarios </h2>
                  <div class="clearfix"></div>
                </div>
                <div class="x_content">
                  <p><button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bs-modal-createuser">Crear usuario</button></p>
                  <p class="text-muted font-13 m-b-30">
                    Tabla de usuarios
                  </p>


                  <table id="datatable" class="table table-striped table-bordered">
                      <thead>
                        <tr>
                          <th># </th>
                          <th>Usuario</th>
                          <th>Habilitado</th>
                          <th>Editar servidores</th>
                          <th>Recibir email de incidencias</th>
                          <th>Admin</th>
                          <th>Editar</th>
                        </tr>
                      </thead>

                      <tbody>
                      {% for userp in users %}
                        <tr {% if userp.Enabled == 1 %}style="background-color: #eaffde;"{%else%}style="background-color: #ffe6e6;"{% endif %} >
                          <td class=" "><b>{{userp.ID_U}}</b></td>
                          <td class=" ">{{userp.Name}} {% if userp.Enabled == 0 %}<br/><i>Disabled</i>{%endif%}</td>
                          <td class=" ">
                          <input onClick="permajax('{{userp.ID_U}}','Enabled');" type="checkbox" {%if userp.Enabled == 1 %} checked="checked" {% endif %} {%if userp.ID_U == user.ID_U %} onclick="return false;" onkeydown="return false;" {% endif %}>
                          </td>
                          <td class=" ">
                          <input onClick="permajax('{{userp.ID_U}}','PE_editserv');" type="checkbox" {%if userp.PE_editserv == 1 %} checked="checked" {% endif %} {%if userp.ID_U == user.ID_U %} onclick="return false;" onkeydown="return false;" {% endif %}>
                          </td>
                          <td class=" ">
                          <input onClick="permajax('{{userp.ID_U}}','SendMail');" type="checkbox" {%if userp.SendMail == 1 %} checked="checked" {% endif %}>
                          </td>
                          <td class=" ">
                          <input onClick="permajax('{{userp.ID_U}}','PE_admin');" type="checkbox" {%if userp.PE_admin == 1 %} checked="checked" {% endif %} {%if userp.ID_U == user.ID_U %} onclick="return false;" onkeydown="return false;" {% endif %}>
                          </td>
                          <td class=" last">
                          {% if userp.ID_U == user.ID_U %} {# Change password if is your user #}
                          <button type="button" class="btn btn-info" data-toggle="modal" data-target=".bs-modal-changepass-{{userp.ID_U}}">Cambiar tu contraseña</button>
                          <!-- Modal cambiar password -->
                          <div class="modal fade bs-modal-changepass-{{userp.ID_U}}" tabindex="-1" role="dialog" aria-hidden="true" style="display: none;">
                            <div class="modal-dialog modal-lg">
                              <form method="POST" data-parsley-validate class="form-horizontal form-label-left">
                                <div class="modal-content">

                                  <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span>
                                    </button>
                                    <h4 class="modal-title" id="myModalLabel">Cambiar contraseña para el usuario {{userp.Name}}</h4>
                                  </div>
                                  <div class="modal-body">      
                                    <div class="form-group">
                                      <label class="control-label col-md-3 col-sm-3 col-xs-12" for="pass1">Nueva contraseña <span class="required">*</span>
                                      </label>
                                      <div class="col-md-6 col-sm-6 col-xs-12">
                                        <input type="password" id="pass1" name="pass1" required="required" class="form-control col-md-7 col-xs-12">
                                      </div>
                                    </div>
                                    <div class="form-group">
                                      <label class="control-label col-md-3 col-sm-3 col-xs-12" for="pass2">Repita la contraseña <span class="required">*</span>
                                      </label>
                                      <div class="col-md-6 col-sm-6 col-xs-12">
                                        <input type="password" id="pass2" name="pass2" required="required" class="form-control col-md-7 col-xs-12">
                                      </div>
                                    </div>
                                  </div>
                                  <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
                                    <button type="submit" class="btn btn-primary">Cambiar</button>
                                  </div>
                                </div>
                              </form>
                            </div>
                          </div>
                         </td>
                         {% elseif user.PE_admin == 1 %}
                          <button type="button" class="btn btn-warning" data-toggle="modal" data-target=".bs-modal-deleteuser-{{userp.ID_U}}">Borrar usuario</button>
                          <!-- Modal borrar usuario -->
                          <div class="modal fade bs-modal-deleteuser-{{userp.ID_U}}" tabindex="-1" role="dialog" aria-hidden="true" style="display: none;">
                            <div class="modal-dialog modal-lg">
                              <form method="POST" action="?page=users&delete={{userp.ID_U}}" data-parsley-validate class="form-horizontal form-label-left">
                                <div class="modal-content">

                                  <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span>
                                    </button>
                                    <h4 class="modal-title" id="myModalLabel">Borrar usuario <small>No se puede recuperar un usuario que se borre</small></h4>
                                  </div>
                                  <div class="modal-body">      

                                    <p>No hay vuelta atrás, si aceptas se borrará el usuario {{userp.Name}}</p>
                                  </div>
                                  <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
                                    <button type="submit" class="btn btn-primary">Borrar</button>
                                  </div>
                                </div>
                              </form>
                            </div>
                          </div>
                         </td>
                          {% endif %}
                        </tr>
                        {% endfor %}
                    </tbody>
                  </table>
                </div>
              </div>
            </div>
            
          </div>

          <script>
          function permajax(ID_U,perm){
            conexion = new XMLHttpRequest();
            // Preparar la funcion de respuesta
            conexion.onreadystatechange = function() {  /* Mostrar */
            if(conexion.readyState == 4 && conexion.status == 200) {
                  console.log("OK")
                }
            }
            // Realizar peticion HTTP
            conexion.open('POST', 'ajaxfunc.php');
            conexion.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            conexion.send("do=toggleperm&ID_U="+ID_U+"&perm="+perm);
          }
          </script>


          <!-- Modal nuevo usuario -->
          <div class="modal fade bs-modal-createuser" tabindex="-1" role="dialog" aria-hidden="true" style="display: none;">
            <div class="modal-dialog modal-lg">
              <form method="POST" data-parsley-validate class="form-horizontal form-label-left">
                <div class="modal-content">

                  <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span>
                    </button>
                    <h4 class="modal-title" id="myModalLabel">Crear usuario <small>Se crearán con permisos básicos que luego se pueden editar</small></h4>
                  </div>
                  <div class="modal-body">      

                    <div class="form-group">
                      <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Nombre del usuario <span class="required">*</span>
                      </label>
                      <div class="col-md-6 col-sm-6 col-xs-12">
                        <input type="text" id="name" name="name" required="required" class="form-control col-md-7 col-xs-12">
                      </div>
                    </div>
                    <div class="form-group">
                      <label class="control-label col-md-3 col-sm-3 col-xs-12" for="password">Contraseña <span class="required">*</span>
                      </label>
                      <div class="col-md-6 col-sm-6 col-xs-12">
                        <input type="password" id="password" name="password" required="required" class="form-control col-md-7 col-xs-12">
                      </div>
                    </div>
                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="submit" class="btn btn-primary">Crear</button>
                  </div>
                </div>
              </form>
            </div>
          </div>

          <!-- Modal borrar usuario -->
          <div class="modal fade bs-modal-deleteuser" tabindex="-1" role="dialog" aria-hidden="true" style="display: none;">
            <div class="modal-dialog modal-lg">
              <form method="POST" data-parsley-validate class="form-horizontal form-label-left">
                <div class="modal-content">

                  <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span>
                    </button>
                    <h4 class="modal-title" id="myModalLabel">Borrar usuario <small>No se puede recuperar un usuario que se borre</small></h4>
                  </div>
                  <div class="modal-body">      

                    <p>No hay vuelta atrás, si aceptas se borrará el usuario</p>
                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
                    <button type="submit" class="btn btn-primary">Borrar</button>
                  </div>
                </div>
              </form>
            </div>
          </div>


        </div>
        <!-- /page content -->


{% include 'a_footer.twig' %}