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

    if($is_admin!=1){
        //header("location: dashboard.php");
        print "<script>window.location='dashboard.php?error';</script>";
    }

    $registrados=mysqli_query($con, "select * from tickets where status_id=1  order by id desc");
?>

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

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

                        if (isset($_GET)) {
                           if (isset($_GET['deletesuccess'])) {
                              echo "<div class='alert alert-success' role='alert'><button type='button' class='close' data-dismiss='alert'>&times;</button>Datos Eliminado Correctamente!</div>";
                           }
                           if (isset($_GET['errordelete'])) {
                              echo "<div class='alert alert-danger' role='alert'><button type='button' class='close' data-dismiss='alert'>&times;</button>Hubo un error al eliminar los datos!</div>";
                           }
                        }

                    ?>
                <div class="box">
                    <div class="box-header">
                      <!-- <h3 class="box-title">Registro de tickets</h3> -->
                    </div>
                    <div class="row">
                <div class="col-md-2"></div>
                <div class="col-md-8">
                    <?php
                        if (isset($_GET)) {

                            if (isset($_GET['success'])) {
                                echo "<div class='alert alert-success' role='alert'><strong>Exito!</strong> Ticket Actualizado Con Exito</div>";
                            }
                            if (isset($_GET['error'])) {
                                 echo "<div class='alert alert-danger' role='alert'><strong>Error!</strong> El Ticket No Pudo Actualizarse!</div>";
                            }
                        }
                    ?>
                </div>
            </div>
                    <!-- /.box-header -->
                    <div class="box-body">
                        <table id="example1" class="table table-bordered table-striped">
                            <thead class="table_header">
                                <tr>
                                    <th style="text-align: center;"></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($registrados as $cat):
                                    $status_id=$cat['status_id'];
                                $client_id=$cat['client_id'];
                                $area=$cat['area'];

                                $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'];


                                $empresa=mysqli_query($con, "select * from clientes where id=$client_id");
                                $rows=mysqli_fetch_array($empresa);
                                    $business=$rows['business'];
                                                            
                                $area1=mysqli_query($con, "select * from area where id=$area");
                                $rows20=mysqli_fetch_array($area1);
                                    $areanom=$rows20['name'];
                            ?>
                                <tr style="text-align: center;">
                                    <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: 8%; vertical-align: middle;"><?php echo $cat['number_ticket'] ?></td>
                                    <td style="width: 8%; 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="vertical-align: middle; width: 8%; ">                        
                                        <?php
                                            if($status_id==1){
                                                echo "<span class='label label-warning'>Registrado</span>";
                                            }else if($status_id==2){
                                                echo "<span class='label label-info'>Asignado</span>";
                                            }else if($status_id==3){
                                                echo "<span class='label label-danger'>Con Incidencia</span>";
                                            }else if($status_id==4){
                                                echo "<span class='label label-success' >Atendido</span>";
                                            }
                                        ?>
                                    </td>
                                    <td style="text-align: center; vertical-align: middle; width: 12%;">
                                        <!-- 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="asignar_ticket.php?id=<?php echo $cat['id'] ?>"><i class="fa fa-child"></i> Asignar</a></li>
                                                <li><a href="ticket_detailadm.php?id=<?php echo $cat['id'] ?>"><i class="fa fa-pencil" aria-hidden="true"></i>Editar</a></li>
                                                <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" ?>
