<?php
include_once '../header.php';
include_once '../php/config.php';
$cur_user = $_GET['usuario'];
$ruta = $_GET['ruta'];
$zona = $_GET['zona'];


	
	if($_GET["acceso"]=="1"){

	
	 mysql_query("delete from rutas_cobrador where cobrador='$cur_user' and ruta = '$ruta'") or die(mysql_error()); 	
	 mysql_query("insert into rutas_cobrador set ruta='$ruta', zona='$zona',  cobrador='$cur_user'") or die(mysql_error());
	}

if($_GET["acceso"]=="0"){
	mysql_query("delete from rutas_cobrador where cobrador='$cur_user' and ruta = '$ruta'") or die(mysql_error());
	}


?>

<style>
	td,th{
		font-size: 19px;
	}
</style>

<div class="container" style="background:white; padding:45px">
	<div class="row">
		<div clas="co-md-12">
			<span class="text-rojo" style="font-size:20px;"><i class="bi bi-user"></i> Asignar rutas a cobrador</span>
			<?php echo ": <b>".$cur_user."</b>";?>
			<br><br>
			


			<hr>
			<span class="text-info h3"><b>Rutas asignadas </b></span>
			<a class="btn btn-orange pull-right" href="javascript:void(0)" onClick="$('#modalModulos').modal('show')"><b>Asignar mas rutas</b></a><br><br><br>
			<div class="table-responsive">
				<table class="table">
				
					<th>Rurta</th>
					<th>Zona</th>
					
					
					<th>Quitar</th>
				
				<?php 
				$sql = mysql_query("select * from rutas_cobrador where  cobrador='$cur_user'") or die(mysql_error());
				while($row =mysql_fetch_array($sql)){
					$ruta = $row["ruta"];
				?>
				<tr>
					<td><?php echo $row["ruta"]?></td>
					<td><?php echo $row["zona"]?></td>
					
					
		
					
						<td><a class="btn btn-rojo" href="rutas_cobrador.php?ruta=<?php echo $ruta?>&acceso=0&usuario=<?php echo $cur_user?>"><i class="bi bi-person-dash"></i> Quitar</a></td>
				</tr>
			
			
				<?php }?>
				</table>
			</div>
		</div>
	</div>

</div>


			<!--MODAL MODULOS-->
			<div class="modal" id="modalModulos" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog modal-md" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h2 class="modal-title text-dark" id="exampleModalLabel"><i class="fa fa-w fa-edit"></i> Rutas</h2>
            <button class="close" type="button" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">×</span>
            </button>
          </div>
          <div class="modal-body">


			


			<div class="table-responsive lista">
				<table class="table">
					<th>Ruta</th>
					<th>Zona</th>
					
					<th width="85">Asignar</th>
					
				
				<?php 
				$sql0 = mysql_query("select * from rutas") or die(mysql_error());
				while($row0 =mysql_fetch_array($sql0)){
					$ruta = $row0["nombre"];
					$zona = $row0["zona"];
				?>
				<tr>
					<td><?php echo $row0["nombre"]?></td>
					<td><?php echo $row0["zona"]?></td>
					
					
					<td><a class="btn btn-success" href="rutas_cobrador.php?ruta=<?php echo $ruta?>&acceso=1&usuario=<?php echo $cur_user?>&zona=<?php echo $zona?>"><i class="bi bi-person-check-fill"></i> Asignar </a></td>
					
				</tr>	
				<?php }?>
				</table>
			</div>
	<div class="modal-footer">
	
	</div>
	</div>
	</div>
</div>
</div>
<!--/MODAL MODULOS-->


<?php
include_once '../footer.php';

?>

<script>
$(function(){
	$(".table").DataTable();
})
</script>