<?php     
function lista_allusuarios($mysqli){
    ?>	
    <div class="page-title-box d-flex align-items-center justify-content-between">
		<h4 class="mb-0">Usuarios</h4>
		<div class="page-title-right">
			<ol class="breadcrumb m-0">
				<li class="breadcrumb-item"><a href="<?_GetDomain?>index.php">Escritorio</a></li>
				<li class="breadcrumb-item active">Usuarios</li>
			</ol>
		</div>
	</div>
    <div class="content-body">
        <div class="row">
            <div class="col-12">
                <div class="card">						
                    <div class="card-content">
                        <div class="card-body card-dashboard">
                            <table width="100%" border="0">
                            <tr>
                                <td><p class="card-text">Información de usuarios</p></td>
                                <td align="right"><a href="formulario.php?p=1&id=0" class="btn btn-info" style="padding:3px" title="Editar"> + Agregar</a> </td>
                            </tr>
                            </table>

                        </div>
                        <div class="table-responsive">
                            <table class="table table-bordered mb-0">
                                <thead>
                                    <tr>			
										<th width="50%">Nombres</th>									
                                        <th width="20%">Usuario</th>
                                        <th width="20%">Password</th>
                                        <th width="10%">Acción</th>
                                    </tr>
                                </thead>
                                <tbody>
                                <?php
                                $i=1;                                
								$rs = getAllUsuarios($mysqli);
								while ($rows = $rs->fetch_assoc()){
								    $id_usuario = $rows['id_usuario'];
									$nombres = $rows['nombres'];
									$usuario = $rows['usuario'];																		
									?>
                                    <tr>                                        
                                        <td><?=$nombres?></td>
                                        <td><?=$usuario?></td>
                                        <td>*****</td>
                                        <td align="center">                                       
                                            <a href="formulario.php?p=1&id=<?=$id_usuario?>" class="btn btn-warning" style="padding:6px" title="Editar"> <i class="ri-pencil-fill"></i></a>   &nbsp;
											<a href="#" class="btn btn-danger"  style="padding: 6px;" title="Eliminar" data-bs-toggle="modal" data-bs-target="#myModal<?=$i?>"><i class="ri-delete-bin-line"></i></a>                                 		
                                        </td>
                                    </tr>
									<div id="myModal<?=$i?>" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel<?=$i?>" aria-hidden="true">
										<div class="modal-dialog" role="document">
											<div class="modal-content">
											<div class="modal-header">
												<h5 class="modal-title">Eliminar usuario</h5>
												<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>														
											</div>
											<div class="modal-body">
												<p>¿Está seguro de eliminar este registro?</p>
											</div>
											<div class="modal-footer">
												<button type="button" class="btn btn-danger" data-bs-dismiss="modal" onclick="proc_elim(1,'<?=$id_usuario?>')">Si, eliminar</button>
												<button type="button" class="btn btn-light waves-effect" data-bs-dismiss="modal">Cerrar</button>
											</div>
											</div>
										</div>
									</div>
									<?php
									$i++;
								}
								?>	                                    											
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php
}   

function formulario_usuario($mysqli, $id){
	if ($id>0){
		$rs = getUsuarioById($mysqli, $id);
		$rows = $rs->fetch_assoc();
		$nombres  = $rows['nombres'];
		$usuario  = $rows['usuario'];
		$dato     = $rows['dato'];
		
	}else{
		$nombres = "";
		$usuario = "";
		$dato    = "";

	}
   
	?>	
	<div class="page-title-box d-flex align-items-center justify-content-between">
		<h4 class="mb-0">Usuario</h4>
		<div class="page-title-right">
			<ol class="breadcrumb m-0">
				<li class="breadcrumb-item"><a href="../index.php">Escritorio</a></li>
				<li class="breadcrumb-item active">Usuario</li>
			</ol>
		</div>
	</div>
        <div class="content-body"><!-- Description -->
	
	
	      <div class="col-md-8 offset-2">
			<div class="card">
				
				<div class="card-content collapse show">
					<div class="card-body">
						<div class="card-text">
							<p>Información del usuario</p>
						</div>
						<form class="m-t" role="form" action="act.php" method="post" enctype="multipart/form-data">
						   <input type="hidden" name="id" id="id" value="<?=$id?>">
						   <input type="hidden" name="tb_cc" id="tb_cc" value="1">						
						   <div class="form-actions" align="right"></div>						
							 <div class="form-body">														
								<div class="form-group  row"><label class="col-sm-3 col-form-label">Nombres</label>
									<div class="col-sm-9"><input type="text" class="form-control" name="nombres" id="nombres" required="" value="<?=$nombres?>" autocomplete="off"></div>
								</div>
								<div class="form-group  row" style="margin-top: 10px;"><label class="col-sm-3 col-form-label">Usuario</label>
									<div class="col-sm-9"><input type="text" class="form-control" name="usuario" id="usuario" required="" value="<?=$usuario?>" autocomplete="off"></div>
								</div>
								<div class="form-group  row" style="margin-top: 10px;"><label class="col-sm-3 col-form-label">Password</label>
									<div class="col-sm-9"><input type="password" class="form-control" name="password" id="password" required="" value="<?=$dato?>" autocomplete="off"></div>
								</div>										
							</div>
							<br><br>
							<div class="form-actions" align="right">
                                <a href="index.php?p=1" class="btn btn-warning"><i class="ft-x"></i> Volver</a> 						
								<button type="submit" class="btn btn-success">
									<i class="fa fa-check"></i> Grabar
								</button>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>	
		</div>
	<?php
}
?>          
