<?php
ob_start();
ini_set('session.gc_maxlifetime', 14400);
session_set_cookie_params(14400);
session_start();

if (!isset($_SESSION["nombre"]))
{
    header("Location: ../../login/login.php");
}
else
{
    require '../header.php';
    

if($_SESSION['averia']==1 AND $_SESSION['nombrecargo']!=='Cuadrilla'){
?>

<style>
    textarea#descripcion {
    resize: vertical; /* Permite cambiar solo la altura */
    min-height: 100px; /* Altura mínima */
    max-width: 100%; /* Asegura que no se desborde */
}
    </style>

            <div class="content-wrapper">
                <!-- Breadcrumb Section -->
                <section class="content-header">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-sm-12">
                                <nav aria-label="breadcrumb">
                                    <ol class="breadcrumb">
                                        <li class="breadcrumb-item">
                                            <a href="#"><i class="fas fa-home"></i> Panel</a>
                                        </li>
                                        <li class="breadcrumb-item active" aria-current="page">
                                            <a href="list.php">
                                                <i class="module-icon"></i> Averias 
                                            </a>
                                        </li>
                                    </ol>
                                </nav>
                            </div>
                          
                            <div class="col-sm-12" style="margin-top: 20px;">
                                <div class="card  ">
                                    <div class="card-header bg-primary">
                                        <h3 class="card-title">
                                            <i class="fas fa-search"></i>
                                            Listado de Trabajos
                                        </h3>
                                    </div>
                                    <div class="card-body" style="display: block;">
                                        <div class="container-fluid ">
                                            <div class="row">
                                                <div class="col-12 col-sm-12 col-md-2">
                                                    </div>
                                                <div class="col-12 col-sm-12 col-md-3">
                                                    <div class="form-group">
                                                        <br>
                                                        <select  name="idcategoria_ingreso" id="idcategoria_ingreso" class="form-control"  data-live-search="true" data-style="btn-default" required>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="col-12 col-sm-12 col-md-3">
                                                    <div class="form-group">
                                                        <br>
                                                        <select  name="idcuadrilla" id="idcuadrilla" class="form-control"  data-live-search="true" data-style="btn-default" required>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="col-12 col-sm-12 col-md-1">
                                                    <div class="form-group">
                                                        <br>
                                                        <button class="btn btn-success btn-flat " style="margin-bottom:-10px" onclick="listar()">Mostrar</button>
                                                    </div>
                                                </div>
                                                <div class="col-12 col-sm-12 col-md-1">
                                                    <br>
                                                    <strong>PUNTUACION: </strong> <strong id="puntuacion"></strong>
                                                </div>
                                            </div><br><br>
                                            </div>
                                            </div>
                                            <div class="card-body" style="display: block;">
                                                 <div class="container-fluid">
                                                    <table style="width:100%;" class="table table-bordered" id="producto">
                                                        <thead>
                                                            <tr>
                                                            <th>#</th>   
                                                            <th width="2%">Accion</th>
                                                                <th width="15%">Cliente</th>
                                                                <th>Tecnico</th>
                                                                <th>Tipo Trabajo</th>                                                  
                                                                <th>Tecnologia</th>
                                                                <th>Prioridad</th>
                                                                <th>Fecha Programada</th>
                                                                <th>Registrato Por</th>
                                                                <th>Direccion</th>
                                                                <th>Historial/Ubicacion</th>
                                                                <th>Estado</th>
                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                        </tbody>
                                                    </table>
                                       
                                    </div>
                                    </div>
                                        <div class="card-footer">
                                            <!-- Footer buttons -->
                                            <a href="create.php" class="btn btn-primary btn-flat">
                                                <i class="fas fa-plus"></i> Nuevo Registro Averia
                                            </a>
                                            <a href="create_visita.php" class="btn btn-danger btn-flat">
                                                <i class="fas fa-plus"></i> Nuevo Registro Visita
                                            </a>
                                            <a href="list.php" class="btn btn-success btn-flat">
                                                <i class="fas fa-sync-alt"></i> Actualizar
                                            </a>
                                        </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </section>                
            </div>

            <div class="modal fade" id="modalProducto" tabindex="-1" role="dialog" aria-labelledby="modalLabel" aria-hidden="true">
                <div class="modal-dialog modal-xl" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="modalLabel"><i class="fa-solid fa-magnifying-glass"></i> Detalle Ingreso</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Cerrar">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                            <div class="modal-body">
                                <!-- Campo para mostrar el dato -->
                                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                                    <div id="tblarticulos" class="table table-striped table-bordered table-condensed table-hover">                       
                                     </div>
                                    <div id="tbldetalle" class="table table-striped table-bordered table-condensed table-hover">
                                    </div>
                                </div>
                            </div>
                                <div class="modal-footer">
                                 <button type="button" class="btn btn-danger btn-flat" data-dismiss="modal">Cerrar</button>
                                </div>
                    </div>
                </div>
            </div>

            <div class="modal fade" id="modal_chat" tabindex="-1" role="dialog"  >
                <div class="modal-dialog modal-lg " role="document">
                    <div class="modal-content">
                        <div class="modal-header"  style="background:#3e038c; color:white">
                            <h5 class="modal-title" id="Label">Chat Averia</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span>&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <form id="chatForm">
                                <div class="row">
                                <input type="hidden"  class="form-control" name="idaveria1" id="idaveria1"  >
                                        <div class="col-md-12">
                                            <div class="form-group"> 
                                                <div id="tblarticuloss" class="table table-striped table-bordered table-condensed table-hover">                       
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-12">
                                            <div class="form-group"> 
                                                <textarea id="descripcion" class="form-control"   name="descripcion" rows="5"  required="" placeholder="Escribe una descripcion"></textarea>
                                            </div>
                                        </div>
                                        <div class="form-group col-lg-6 col-md-6 col-sm-6 col-xs-6">                
                                            <label>Fecha/Hora Reprogramacion(*)</label>                           
                                            <input type="datetime-local"  class="form-control" name="fecha" id="fecha"  >
                                        </div> 
                                        <div class="form-group col-lg-6 col-md-6 col-sm-6 col-xs-6">                
                                            <label>Estado Calificar(*):</label>                           
                                            <input type="checkbox" name="estado" value="4" id="estado">
                                        </div>               
                                       
                                    </div>
                                 </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary  btn-flat" data-dismiss="modal">Cerrar</button>
                                    <button type="submit" id="btnChat" class="btn btn-flat" style='background-color:#3e038c;color: #FFFFFF'> <i class="fas fa-save"></i> Registrar Chat</button>
                                </div>
                         </form>
                    </div>
                </div>
            </div>


            <div class="modal fade" id="modal_Descripcion" tabindex="-1" role="dialog"  >
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header bg-dark" >
                            <h5 class="modal-title" id="Label">Calificar y Verificar la Averia</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span>&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <form id="calificarForm">
                                <div class="row">
                                <input type="hidden"  class="form-control" name="idaveria" id="idaveria">
                                        <div class="col-12">
                                            <div class="form-group"> 
                                                <textarea id="descripcion" class="form-control"   name="descripcion" rows="5"  required="" placeholder="Escribe una descripcion"></textarea>
                                            </div>
                                        </div>
                                        <div class="form-group col-lg-12 col-md-12 col-sm-12 col-xs-12">                
                                        <label>Calificacion del Responsable: (*)</label>                
                                            <select class="form-control select-picker" name="calificacion" id="calificacion" required>
                                                <option value="5">Excelente</option>
                                                <option value="4">Bueno</option>
                                                <option value="3">Medio</option>
                                                <option value="2">Regular</option>
                                                <option value="1">Malo</option>                         
                                            </select>
                                        </div> 
                                        <div class="form-group col-lg-12 col-md-12 col-sm-12 col-xs-12"> 
                                        <label>Puntos Adicionales: (*)</label> 
                                        <input type="number" class="form-control" name="adicional" value="0" placeholder="Escribe el valor"></inpunt>
                                        </div>
                                    </div>
                                 </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-danger  btn-flat" data-dismiss="modal">Cerrar</button>
                                    <button type="submit" id="btnCalificar" class="btn btn-dark btn-flat"> <i class="fas fa-save"></i> Registrar Calificacion</button>
                                </div>
                         </form>
                    </div>
                </div>
            </div>

<?php
}else if ($_SESSION['averia']==1 and $_SESSION['nombrecargo']=='Cuadrilla' ){
?>

<style>
    textarea#descripcion {
    resize: vertical; /* Permite cambiar solo la altura */
    min-height: 100px; /* Altura mínima */
    max-width: 100%; /* Asegura que no se desborde */
}
    </style>

            <div class="content-wrapper">
                <!-- Breadcrumb Section -->
                <section class="content-header">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-sm-12">
                                <nav aria-label="breadcrumb">
                                    <ol class="breadcrumb">
                                        <li class="breadcrumb-item">
                                            <a href="#"><i class="fas fa-home"></i> Panel</a>
                                        </li>
                                        <li class="breadcrumb-item active" aria-current="page">
                                            <a href="list.php">
                                                <i class="module-icon"></i> Averias 
                                            </a>
                                        </li>
                                    </ol>
                                </nav>
                            </div>
                          
                            <div class="col-sm-12" style="margin-top: 20px;">
                                <div class="card  ">
                                    <div class="card-header bg-primary">
                                        <h3 class="card-title">
                                            <i class="fas fa-search"></i>
                                            Listado de Trabajos Tecnicos
                                        </h3>
                                    </div>
                                    <div class="card-body" style="display: block;">
                                        <div class="container-fluid  table-responsive">
                                            <br>
                                            <table style="width:100%;" class="table table-bordered" id="producto_tecnico">
                                                <thead>
                                                <tr>
                                                    <th width="1%">Accion</th>
                                                    <th width="15%">Cliente</th>
                                                    <th>Registrato Por</th>
                                                    <th>Tipo Trabajo</th>                                                  
                                                    <th>Tecnologia</th>
                                                    <th>Prioridad</th>
                                                    <th>Fecha Programada</th>
                                                    <th>Direccion</th>
                                                    <th>Historial</th>
                                                    <th>Ubicacion</th>
                                                    <th>Estado</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </section>                
            </div>


            <div class="modal fade" id="modal_chat" tabindex="-1" role="dialog"  >
                <div class="modal-dialog modal-lg " role="document">
                    <div class="modal-content">
                        <div class="modal-header"  style="background:#3e038c; color:white">
                            <h5 class="modal-title" id="Label">Chat Averia</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span>&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <form id="chatForm">
                                <div class="row">
                                <input type="hidden"  class="form-control" name="idaveria1" id="idaveria1"  >
                                        <div class="col-md-12">
                                            <div class="form-group"> 
                                                <div id="tblarticuloss" class="table table-striped table-bordered table-condensed table-hover">                       
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-12">
                                            <div class="form-group"> 
                                                <textarea id="descripcion" class="form-control"   name="descripcion" rows="5"  required="" placeholder="Escribe una descripcion"></textarea>
                                            </div>
                                        </div>
                                        <div class="form-group col-lg-6 col-md-6 col-sm-6 col-xs-6">                
                                            <label>Fecha/Hora Reprogramacion(*)</label>                           
                                            <input type="datetime-local"  class="form-control" name="fecha" id="fecha"  >
                                        </div> 
                                       
                                    </div>
                                 </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary  btn-flat" data-dismiss="modal">Cerrar</button>
                                    <button type="submit" id="btnChat" class="btn btn-flat" style='background-color:#3e038c;color: #FFFFFF'> <i class="fas fa-save"></i> Registrar Chat</button>
                                </div>
                         </form>
                    </div>
                </div>
            </div>

            <div class="modal fade" id="modal_imagen_contrato" tabindex="-1" role="dialog"  >
                <div class="modal-dialog modal-lg " role="document">
                    <div class="modal-content">
                        <div class="modal-header"  style="background:#3e038c; color:white">
                            <h5 class="modal-title" id="Label">Registro Imagen Contrato</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span>&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <form id="ImagenFormContrato">
                                <div class="row">
                                <input type="hidden"  class="form-control" name="idaveriac" id="idaveriac">
                                    <div class="form-group col-lg-6 col-md-12 col-sm-12 col-xs-12">
                                        <label>Imagen Facha Casa:</label>
                                        <input type="file" class="form-control" name="imagen1" id="imagen1" required>
                                        <input type="hidden" name="imagenactual1" id="imagenactual1">
                                        <img src="" width="200px" height="200px" id="imagenmuestra1">
                                    </div>
                                    <div class="form-group col-lg-6 col-md-12 col-sm-12 col-xs-12">
                                        <label>Imagen Dni:</label>
                                        <input type="file" class="form-control" name="imagen2" id="imagen2" required>
                                        <input type="hidden" name="imagenactual2" id="imagenactual2">
                                        <img src="" width="200px" height="200px" id="imagenmuestra2">
                                    </div>
                                    <div class="form-group col-lg-6 col-md-12 col-sm-12 col-xs-12">
                                        <label>Imagen Contrato:</label>
                                        <input type="file" class="form-control" name="imagen3" id="imagen3" required>
                                        <input type="hidden" name="imagenactual3" id="imagenactual3">
                                        <img src="" width="200px" height="200px" id="imagenmuestra3">
                                    </div>
                                    <div class="form-group col-lg-6 col-md-12 col-sm-12 col-xs-12">
                                        <label>Imagen Orden:</label>
                                        <input type="file" class="form-control" name="imagen4" id="imagen4" required>
                                        <input type="hidden" name="imagenactual4" id="imagenactual4">
                                        <img src="" width="200px" height="200px" id="imagenmuestra4">
                                    </div>
                                    <div class="form-group col-lg-6 col-md-12 col-sm-12 col-xs-12">
                                        <label>Imagen Medidor:</label>
                                        <input type="file" class="form-control" name="imagen5" id="imagen5" required>
                                        <input type="hidden" name="imagenactual5" id="imagenactual5">
                                        <img src="" width="200px" height="200px" id="imagenmuestra5">
                                    </div>
                                    <div class="form-group col-lg-6 col-md-12 col-sm-12 col-xs-12">
                                        <label>Imagen Caja:</label>
                                        <input type="file" class="form-control" name="imagen6" id="imagen6" required>
                                        <input type="hidden" name="imagenactual6" id="imagenactual6">
                                        <img src="" width="200px" height="200px" id="imagenmuestra6">
                                    </div>
                                    </div>
                                 </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary  btn-flat" data-dismiss="modal">Cerrar</button>
                                    <button type="submit" id="btnImagen" class="btn btn-flat" style='background-color:#3e038c;color: #FFFFFF'> <i class="fas fa-save"></i> Registrar Imagenes</button>
                                </div>
                         </form>
                    </div>
                </div>
            </div>

            <div class="modal fade" id="modal_imagen" tabindex="-1" role="dialog"  >
                <div class="modal-dialog modal-lg " role="document">
                    <div class="modal-content">
                        <div class="modal-header"  style="background:#3e038c; color:white">
                            <h5 class="modal-title" id="Label">Registro Imagen </h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span>&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <form id="ImagenFormAveria">
                                <div class="row">
                                <input type="hidden" class="form-control" name="idaveriacc" id="idaveriacc">
                                    <div class="form-group col-lg-6 col-md-12 col-sm-12 col-xs-12">
                                        <label>Imagen 1:</label>
                                        <input type="file" class="form-control" name="imagen1" id="imagen1" required>
                                        <input type="hidden" name="imagenactual1" id="imagenactual1">
                                        <img src="" width="200px" height="200px" id="imagenmuestra7">
                                    </div>
                                    <div class="form-group col-lg-6 col-md-12 col-sm-12 col-xs-12">
                                        <label>Imagen 2:</label>
                                        <input type="file" class="form-control" name="imagen2" id="imagen2" required>
                                        <input type="hidden" name="imagenactual2" id="imagenactual2">
                                        <img src="" width="200px" height="200px" id="imagenmuestra8">
                                    </div>
                                    </div>
                                 </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary  btn-flat" data-dismiss="modal">Cerrar</button>
                                    <button type="submit" id="btnImagen" class="btn btn-flat" style='background-color:#3e038c;color: #FFFFFF'><i class="fas fa-save"></i> Registrar Imagenes</button>
                                </div>
                         </form>
                    </div>
                </div>
            </div>
 

<?php
}
require '../footer.php';
?>
<script type="text/javascript" src="../../scripts/averia.js"></script>
<?php 
}
ob_end_flush();
?>