<?php 
    /*-------------------------
    Autor: Amner Saucedo Sosa
    Web: www.abisoftgt.net
    E-Mail: waptoing7@gmail.com
    ---------------------------*/
    $active14="active";
    include "header.php";
    include "sidebar.php";
    $id=$_SESSION['admin_id'];
    $registrados1=mysqli_query($con, "select * from tickets where asigned_id=$id");
    $prioridad=mysqli_query($con, "select * from area where priority_id=$id");
        $registrados=mysqli_query($con, "select * from tickets where status_id=1");
    $asignados=mysqli_query($con, "select * from tickets where status_id=2 && asigned_id!=0");
    $cancelados=mysqli_query($con, "select * from tickets where status_id=3");
    $atendidos=mysqli_query($con, "select * from tickets where status_id=4");


    $sesion_id=$_SESSION['admin_id'];
//registro empleados
    $registrados_emp=mysqli_query($con, "select * from tickets where status_id=1 && asigned_id=$sesion_id");
    $asignados_emp=mysqli_query($con, "select * from tickets where status_id=2 && asigned_id!=0 && asigned_id=$sesion_id");
    $cancelados_emp=mysqli_query($con, "select * from tickets where status_id=3 && asigned_id=$sesion_id");
    $atendidos_emp=mysqli_query($con, "select * from tickets where status_id=4 && asigned_id=$sesion_id");

?>
        

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>Resúmen de tu día
        <a class="btn btn-success btn-social pull-right" href="../addticket.php" title="Agregar Ticket" data-toggle="tooltip">
          <i class="fa fa-plus"></i> Abrir Ticket
        </a></h1>
    </section>

    <!-- Main content -->
    <section class="content-header">
      <!-- Info boxes -->
      <?php if($is_admin==1){?>
      <div class="row">
        <div class="col-md-3 col-sm-6 col-xs-12">
          <div class="info-box">
          <a href="mistickets.php">
            <span class="info-box-icon bg-blue"><i class="fa fa-glass"></i></span>

            </a>
            <div class="info-box-content">
              <span class="info-box-text">Registrados</span>
              <span class="info-box-number"><?php echo mysqli_num_rows($registrados1) ?></span>
            </div>
            <!-- /.info-box-content -->
          </div>
          <!-- /.info-box -->
        </div>
        <!-- /.col -->



        <!-- fix for small devices only -->
        <div class="clearfix visible-sm-block"></div>

        <div class="col-md-3 col-sm-6 col-xs-12">
          <div class="info-box">
          <a href="mistickets.php">
            <span class="info-box-icon bg-yellow"><i class="fa fa-rocket"></i></span>
        </a>
            <div class="info-box-content">
              <span class="info-box-text">Asignados</span>
              <span class="info-box-number"><?php echo mysqli_num_rows($asignados) ?></span>
            </div>
            <!-- /.info-box-content -->
          </div>
          <!-- /.info-box -->
        </div>
        <!-- /.col -->
        <div class="col-md-3 col-sm-6 col-xs-12">
          <div class="info-box">
          <a href="mistickets.php">
            <span class="info-box-icon bg-red"><i class="fa fa-ban"></i></span>
            </a>
            <div class="info-box-content">
              <span class="info-box-text">Pausados</span>
              <span class="info-box-number"><?php echo mysqli_num_rows($cancelados) ?></span>
            </div>
            <!-- /.info-box-content -->
          </div>
          <!-- /.info-box -->
        </div>
        <!-- /.col -->
                <div class="col-md-3 col-sm-6 col-xs-12">
          <div class="info-box">
          <a href="mistickets.php">
            <span class="info-box-icon bg-green"><i class="fa fa-flask"></i></span>
        </a>
            <div class="info-box-content">
              <span class="info-box-text">Solucionados</span>
              <span class="info-box-number"><?php echo mysqli_num_rows($atendidos) ?></span>
            </div>
            <!-- /.info-box-content -->
          </div>
          <!-- /.info-box -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
<?php }  ?>

<!-- empleado -->


      <!-- Info boxes -->
      <?php if($is_admin!=1){?>
      <div class="row">


            <div class="col-md-12">
            <?php if(isset($_GET['error'])) {
                    // echo "<br><div class='alert alert-warning' role='alert'>
                    // <button type='button' class='close' data-dismiss='alert'>&times;</button>
                    // <strong>¡Error!</strong> Estas accediendo a una area restringida!
                    // </div>";
            } ?>
            </div>


        <!-- fix for small devices only -->
        <div class="clearfix visible-sm-block"></div>

        <div class="col-md-3 col-sm-6 col-xs-12">
          <div class="info-box">
          <a href="mistickets.php">
            <span class="info-box-icon bg-blue"><i class="fa fa-rocket"></i></span>
        </a>
            <div class="info-box-content">
              <span class="info-box-text">Asignados</span>
              <span class="info-box-number"><?php echo mysqli_num_rows($asignados_emp) ?></span>
            </div>
            <!-- /.info-box-content -->
          </div>
          <!-- /.info-box -->
        </div>
        <!-- /.col -->
        <div class="col-md-3 col-sm-6 col-xs-12">
          <div class="info-box">
          <a href="mistickets.php">
            <span class="info-box-icon bg-red"><i class="fa fa-ban"></i></span>
            </a>
            <div class="info-box-content">
              <span class="info-box-text">Pausados</span>
              <span class="info-box-number"><?php echo mysqli_num_rows($cancelados_emp) ?></span>
            </div>
            <!-- /.info-box-content -->
          </div>
          <!-- /.info-box -->
        </div>
        <!-- /.col -->
        <div class="col-md-3 col-sm-6 col-xs-12">
          <div class="info-box">
          <a href="mistickets.php">
            <span class="info-box-icon bg-green"><i class="fa fa-flask"></i></span>
        </a>
            <div class="info-box-content">
              <span class="info-box-text">Solucionados</span>
              <span class="info-box-number"><?php echo mysqli_num_rows($atendidos_emp) ?></span>
            </div>
            <!-- /.info-box-content -->
          </div>
          <!-- /.info-box -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
<?php }  ?>
<!-- end empleado -->
    </section>
    <section class="content-header">
        <h1>Tickets </h1>
        <ol class="breadcrumb">
            <li><a href="dashboard.php"><i class="fa fa-dashboard"></i> Dashboard</a></li>
            <li class="active">Tickets </li>
        </ol>
    </section>

    <!-- Main content -->
        <!-- 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>
                    <!-- /.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;">Prioridad</th>
                                    <th style="text-align: center;" style="width: 7%;">Estado</th>
                                    <th style="text-align: center;" style="text-align: center;"></th>
                                </tr>
                            </thead>
                            <tbody>
                            <?php 
                                foreach($registrados1 as $cat):
                                    $status_id=$cat['status_id'];

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

                                $clients=mysqli_query($con, "select * from clientes where id=$business");
                                
                    

                                $rows=mysqli_fetch_array($clients);
                                   $business=$rows['business'];
                                
                                
                                $prioridad=mysqli_query($con, "select * from area where id=$area");
                                $prioridad1=mysqli_query($con, "select * from area where id=$area");
                                
                    

                                $rows1=mysqli_fetch_array($prioridad);
                                   $priority_id=$rows1['priority_id'];
                                
                                $rows2=mysqli_fetch_array($prioridad1);
                                   $servicio_name=$rows2['name'];
                               
                            ?>
                                <tr style="text-align: center;">
                                    <td style="vertical-align: middle;" 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;"><?php echo $cat['name'] ?></td>
                                    <td style="vertical-align: middle;"><?php echo $cat['email'] ?></td>
                                    <td style="vertical-align: middle;"><?php echo $cat['number_ticket'] ?></td>
                                    <td style="vertical-align: middle;"><?php echo $business ?></td>
                                    <td style="vertical-align: middle;"><?php echo $name_kind ?></td>
                                    <td style="width: 8%; vertical-align: middle;" ><?php echo $servicio_name?></td>
                                    <td style="text-align: center; width: 3%; vertical-align: middle;"><?php echo $priority_id ?></td>
                                    <td style="vertical-align: middle;">                        
                                        <?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' >Solucionado</span>";
                                            }
                                        ?>
                                    </td>
                                    <td style="text-align: center; vertical-align: middle;">
                                        <!-- 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="atender_ticket.php?id=<?php echo $cat['id'] ?>"><i class="fa fa-check"></i> Cerrar Ticket</a></li>
                                                <!-- 
                                                <li><a href="incidencias.php?id=<?php echo $cat['id'] ?>"><i class="fa fa-ban"></i> Agregar Pausa</a></li>-->
                                            </ul>
                                        </div>
                                    </td>
                                </tr>
                            <?php endforeach; ?>    
                            </tbody>
                        </table>
                    </div><!-- /.box-body -->
                </div><!-- /.box -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </section><!-- /.content -->
</div><!-- /.content-wrapper -->

<script language="javascript">
setInterval(function(){
   window.location.reload(1);
}, 60000);
</script>

  <?php include "footer.php" ?>