<?php
    /*-------------------------
    Autor: Amner Saucedo Sosa
    Web: www.abisoftgt.net
    E-Mail: waptoing7@gmail.com
    ---------------------------*/
    $active2="active";
    $active5="active";
    include "header.php";
    include "sidebar.php";

    if($is_admin!=1){
        //header("location: dashboard.php");
        print "<script>window.location='dashboard.php?error';</script>";
    }
    $atendidos=mysqli_query($con, "select * from tickets where status_id=2 && asigned_id!=0 order by id desc");
?>

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>Tickets Asignados</h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Dashboard</a></li>
            <li class="active">Tickets Asignados</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">

                <div class="box">
                    <div class="box-header">
                      <!-- <h3 class="box-title">Registro de tickets</h3> -->
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body">
                        <table id="example1" class="table table-bordered table-striped">
                            <thead class="table_header">
                                <tr>
                                    <th></th>
                                    <th style="text-align: center;">Nombre</th>
                                    <th style="text-align: center;">E-mail</th>
                                    <th style="text-align: center;">N° Ticket</th>
                                    <th style="text-align: center;">Empresa</th>
                                    <th style="text-align: center;">Área</th>
                                    <th style="text-align: center;">Servicio</th>
                                    <th style="text-align: center;">Estado</th>
                                    <th style="text-align: center;">Acciones</th>
                                </tr>
                            </thead>
                            <tbody>
                            <?php
                                foreach($atendidos as $cat):
                                    $status_id=$cat['status_id'];
                                    $asigned_id=$cat['asigned_id'];
                                    $client_id=$cat['client_id'];
                                    $area=$cat['area']; 

                                    $sql=mysqli_query($con, "select * from user where id=$asigned_id");
                                    $rows=mysqli_fetch_array($sql);
                                        $name_user=$rows['name'];
                                        $lastname_user=$rows['lastname'];
                                        $email_user=$rows['email'];


                                $empresa=mysqli_query($con, "select * from clientes where id=$client_id");
                                $rows=mysqli_fetch_array($empresa);
                                    $business=$rows['business'];
                                
                                $kind_id=$cat['kind_id'];
                                $sql=mysqli_query($con, "select * from kind where id=$kind_id");
                                $row=mysqli_fetch_array($sql);
                                    $name_kind=$row['name'];
                                
                                $area1=mysqli_query($con, "select * from area where id=$area");
                                $rows20=mysqli_fetch_array($area1);
                                    $areanom=$rows20['name'];


                            ?>
                                <tr>
                                    <td style="vertical-align: middle; width: 3%; " width='30' class='center'><a class="btn btn-default btn-xs" href="ticket_detail.php?id=<?php echo $cat['id'] ?>">Ver <span class="glyphicon glyphicon-arrow-right"></span></a></td>
                                    <td style="vertical-align: middle; width: 8%;"><?php echo $cat['name'] ?></td>
                                    <td style="width: 8%; vertical-align: middle;"><?php echo $cat['email'] ?></td>
                                    <td style="width: 5%; vertical-align: middle;"><?php echo $cat['number_ticket'] ?></td>
                                    <td style="width: 6%; vertical-align: middle;"><?php echo $business ?></td>
                                    <td style="vertical-align: middle; width: 8%;"><?php echo $name_kind ?></td>
                                    <td style="vertical-align: middle; width: 8%; " ><?php echo $areanom?></td>
                                    <td style="text-align: center; vertical-align: middle; width: 8%; "><?php echo "<span class='label label-info'>Asignado</span>"; ?></td>
                                    <td style="text-align: center; width: 8%; ">
                                        <!-- Split button -->
                                        <div class="btn-group">
                                            <button type="button" class="btn btn-default">Acción</button>
                                            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                                <span class="caret"></span>
                                                <span class="sr-only">Toggle Dropdown</span>
                                            </button>
                                            <ul class="dropdown-menu">
                                                <li><a href="incidencias.php?id=<?php echo $cat['id'] ?>"><i class="fa fa-pause"></i> Agregar Pausa</a></li>
                                                <li><a href="reasignar_ticket.php?id=<?php echo $cat['id'] ?>"><i class="fa fa-child"></i> Reasignar</a></li>
                                                <!--AQUI AGREGAMOS LA FUNCION PARA BORRAR TICKETS TICKET-->
                                                <li><a href="borrar_ticket.php?id=<?php echo $cat['id'] ?>"><i class="fa fa-ban"></i>Borrar</a></li>
                                            </ul>
                                            
                                            
                                        </div>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                            </tbody>
                        </table>
                    </div><!-- /.box-body -->
                </div><!-- /.box -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </section><!-- /.content -->
</div><!-- /.content-wrapper -->

  <?php include "footer.php" ?>
