<?php
include("session.php");
?>
<!DOCTYPE html>
<html>


  <?php

   include("head.php"); ?>
<body>
    <div id="wrapper">
       <?php
        include ("menu.php");
       ?>

        <div id="page-wrapper" class="gray-bg dashbard-1">
        <div class="row border-bottom">
        <nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0">
        <div class="navbar-header">
            <a class="navbar-minimalize minimalize-styl-2 btn btn-primary " href="#"><i class="fa fa-bars"></i> </a>
            
        </div>
            <ul class="nav navbar-top-links navbar-right">

                <li>
                    <a href="index.php">
                    
                        <i class="fa fa-sign-out"></i> Salir
                    </a>
                </li>
                
            </ul>

        </nav>
        </div>
               
        <div class="row">
            <div class="col-lg-12">
                 <div class="ibox float-e-margins">
                    
                            <div class="ibox-title">
                                <div class="pull-right">
                                     <?php 
                                             if ($_SESSION["roles"]==1 || $_SESSION["roles"]==2) {
                                             ?>   
                                <button class="btn btn-primary" data-toggle="modal" data-target="#myModal">Nuevo Usuario</button>
                                   <?php 
                                            }
                                             ?>   
                                </div>
                                <h5>Registro de Usuarios</h5>
                                
                            </div>
                            <div class="ibox-content">
                                
                                <div class="table-responsive">
                                    <table class="table table-striped table-hover dataTables-example">
                                        <thead style="color: #1f51a3">
                                        <tr>

                                            <th>ID</th>
                                          <th>Nombre de Usuario</th>
                                            <th>Rol/Perfil</th>
                                            <th>Permisos</th>
                                             <?php 
                                             if ($_SESSION["roles"]==1 || $_SESSION["roles"]==2) {
                                             ?>                  
                                            <th>Editar</th>

                                            <?php if ($_SESSION["roles"]==1) {
                                              ?>
                                            <th>Eliminar</th>

                                            <?php
                                          }
                                          }
                                          ?>
                                            </tr>
                                        </thead>
                                        <tbody style="font-weight: bold;">
                                             <?php 
                                             include("conexion.php");
                                             


     $query="SELECT * FROM `usuarios` where id_usu!=1";
    $resultadoc=$conexion->query($query);
           while ($rowc=$resultadoc->fetch_assoc()) {


                                                ?>
                                        <tr style="font-size: 10px">

                                           
                                           <td><?php echo str_pad($rowc['id_usu'], 4, "0", STR_PAD_LEFT); ?></td>
                                         
                                            <td><?php echo strtoupper($rowc['nombre_usu']); ?></td>
                                            <td><?php 
                                            if ($rowc['rol']==1) {
                                              echo "Administrador (Master)";
                                              }
                                              if ($rowc['rol']==2) {
                                              echo "Operador";
                                              }
                                              if ($rowc['rol']==3) {
                                              echo "Usuario";
                                              }
                                               ?></td>
                                            <td>
                                              <ul>
                                                <?php 

////op1= Nuevo Pedido-
////op2= Real Importado-
////op3= Clientes-
////op4= Tela-
////op10= Proforma-
///op5= Pagos-
///op6= PRoveedores
//op7= libro Diario -
//op8 pusuarios  -                              
//op9 informes     -    

                                echo "<li>Checklist</li>";
                                                if ($rowc['op1']==1) {
                                                  echo "<li>Pedidos</li>";
                                                } ?>
                                                 <?php if ($rowc['op2']==1) {
                                                  echo "<li>Real Importado</li>";
                                                } ?>
                                                <?php if ($rowc['op7']==1) {
                                                  echo "<li>Libro Diario</li>";
                                                } ?>
                                                  <?php if ($rowc['op5']==1) {
                                                  echo "<li>Cartera</li>";
                                                } ?>
                                                 <?php if ($rowc['op9']==1) {
                                                  echo "<li>Informes</li>";
                                                } ?>
                                                <?php if ($rowc['op10']==1) {
                                                  echo "<li>Visitas</li>";
                                                } ?>
                                                <?php if ($rowc['op3']==1) {
                                                  echo "<li>Tablas Maestras</li>";
                                                } ?>
                                                
                                              
                                                 
                                              </ul>
                                            </td>
                                             <?php 
                                             if ($_SESSION["roles"]==1 || $_SESSION["roles"]==2) {
                                             ?>                  
                                           <td><a href="usuarios.php?id=<?php echo $rowc['id_usu'] ?>"><i class="fa fa-pencil"></i></a></td>

                                            <?php if ($_SESSION["roles"]==1) {
                                              ?>
                                            <td><a href="elim_usuarios.php?id=<?php echo $rowc['id_usu'] ?>"><i class="fa fa-trash"></i></a></td>

                                            <?php
                                          }
                                          }
                                          ?>
                                            
                                            
                                        </tr>

                                         <?php 
}
                     ?>
                                        </tbody>
                                    </table>
                                </div>

                            </div>
                        </div>
               
            </div>
        </div>

        
        <?php include("footer.php"); ?>
</div>
      
        
 <!-- MODAL -->  
   
  <div class="modal inmodal" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">
                                
                                <form enctype="multipart/form-data" class="form-horizontal" action="<?php 
                                  if (isset($_GET['id'])) {
                                                    echo "act_usuarios.php";
                                             }
                                             else
                                             {
                                                echo "reg_usuarios.php";
                                             }
                                              ?>" method="POST" name="formulario" >
                                    <div class="modal-dialog">
                                    <div class="modal-content animated bounceInRight">
                                            <div class="modal-header" style="text-align: left">
                                                <a href="usuarios.php"><button type="button" class="close"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button></a>
                                                
                                                 <h4 class="modal-title"><img alt="Logo" src="img/logo.png" height="10%" width="10%"> Usuarios</h4>
                                                <!-- <small class="font-bold">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</small> -->
                                            </div>
                                            <div class="modal-body">
                                               
                                               <?php
$id_usu=0;
                                                if (isset($_GET['id'])) {
                                                    $id_usu=$_GET['id'];
                                                   
                                             }  

                                             



                                                  $query="SELECT * FROM `usuarios` where id_usu='$id_usu'";
    $resultadoc=$conexion->query($query);
     $rowx=$resultadoc->fetch_assoc();


?>                                          

                                                           <div class="form-group">
                                                            <label><input type="checkbox" name="check_cliente" id="check_cliente" onclick="validar_cliente()"> Cliente</label>
                                                            <script type="text/javascript">
                                                              function validar_cliente(){
                                                                if (document.getElementById('check_cliente').checked) {

                                                                  document.getElementById('id_cliente').style.display="block";
                                                                }
                                                                else
                                                                {
                                                                  document.getElementById('id_cliente').style.display="block";

                                                                }
                                                              }
                                                            </script>
                                                            <select class="form-control" name="id_cliente" id="id_cliente" 
<?php
    
    if ($rowcx['id_cliente']=="") {
     echo "style='display: none'";
    }
    else
    {
       echo "style='display: block'";
    }

 ?>
                                                        >
                                                               <option selected value="">Seleccione</option>
                                                                                              <?php
                                                         
                                         $querycl="SELECT * FROM `clientes` where `tipo_tercero`='2'  or `tipo_tercero`='3'  order by nombre asc";
                                        $resultadocl=$conexion->query($querycl);
                                        while ($rowcl=$resultadocl->fetch_assoc()) {
                                            if ($rowcl['id']==$rowcx['id_cliente']) {
                                               $supliers .="<option selected value='".$rowcl['id']."'>".$rowcl['nombre'] ."</option>";
                                            }
                                            else
                                            {
 $supliers .="<option  value='".$rowcl['id']."'>".$rowcl['nombre'] ."</option>";
                                            }
                                           
                                        };


 echo $supliers;
                                        ?>
                                  </select>
                                                            </div>
                
                                                        <div class="form-group"><label>Nombre de Usuario o login</label>
                                                          <input  type="text" placeholder="Ingresa login" class="form-control" name="login" value="<?php echo $rowx['nombre_usu'] ;?>">
<input type="hidden" placeholder="Ingresa login" class="form-control" name="id_usu" value="<?php echo $rowx['id_usu'] ;?>" >
                                                        </div>
                                                        <div class="form-group"><label>Password</label> <input  type="password" placeholder="Ingresa el password o clave" class="form-control" name="password"  value="<?php echo $rowx['clave_usu'] ;?>"  ></div>
                                                       
                                                         <div class="form-group"><label>Rol o Perfil</label> <select name="roles" id="roles" class="col-sm-2 form-control">
                                                            <option>Seleccione</option>
                                                                   <option <?php if ($rowx['rol']==1){echo "selected"; } ;?> value="1">Administrador (Master)</option>
                                                                   <option <?php if ($rowx['rol']==2){echo "selected"; } ;?> value="2">Operador</option>
                                                                   <option <?php if ($rowx['rol']==3){echo "selected"; } ;?> value="3">Usuario</option>
                                                                   
                                                              </select></div>
                                                              
                                                   <div class="row">
                              <div class="col-sm-12">
                                <label  class="control-label">ACCESOS ESPECIALES</label>
                                <p>

                                  <div class="col-sm-4">
                                <input type="checkbox" <?php if ($rowx['op1']==1){echo "checked"; } ;?> id="op1" name="op1" class="" >Pedidos
                              </div> 


                                <div class="col-sm-4">
                                <input type="checkbox" <?php if ($rowx['op5']==1){echo "checked"; } ;?> id="op5" name="op5" class="">Cartera
                              </div> 

                                 <div class="col-sm-4">
                                <input type="checkbox" <?php if ($rowx['op3']==1){echo "checked"; } ;?> id="op3" name="op3" class="">Tablas Maestras
                              </div>


                                <div class="col-sm-4">
                                <input type="checkbox" <?php if ($rowx['op2']==1){echo "checked"; } ;?> id="op2" name="op2" class="">Real Importado
                              </div>

                                <div class="col-sm-8">
                                <input type="checkbox" <?php if ($rowx['op9']==1){echo "checked"; } ;?> id="op9" name="op9" class="">Informes
                              </div>


                                <div class="col-sm-4">
                                <input type="checkbox" <?php if ($rowx['op7']==1){echo "checked"; } ;?> id="op7" name="op7" class="">Libro Diario
                              </div>
                                
                               

                                
                                <div class="col-sm-4">
                                <input type="checkbox" <?php if ($rowx['op10']==1){echo "checked"; } ;?> id="op10" name="op10" class="">Visitas
                              </div>
                              
                               
                                <div style="display: none" class="col-sm-4">
                                <input  type="checkbox" <?php if ($rowx['op4']==1){echo "checked"; } ;?> id="op4" name="op4" class="">Telas</div>
                                <div style="display: none" class="col-sm-4">
                                <input  type="checkbox" <?php if ($rowx['op8']==1){echo "checked"; } ;?> id="op8" name="op8" class="">Usuarios</div>
                               

                                </p>
                              </div>
                            </div>      

                                               
                                                

                                            </div>
                                            <div class="modal-footer">
                                                <a href="usuarios.php"><button type="button" class="btn btn-white">Cerrar</button></a>
                                                <button type="submit" class="btn btn-primary">Guardar cambios</button>
                                            
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
 <!-- MODAL -->
    </div>
    <?php include("script.php"); ?>

       <script type="text/javascript">
           <?php
                    if (isset($_GET['id'])) {
                    ?>
                    $('#myModal').modal('show');
                      <?php                       }  
           ?>


          
       </script>
</body>
</html>
