<?php
// FECHA Y HORA
$dateStart = $_GET['dateStart'];
$dateEnd = $_GET['dateEnd'];
$timeStart = $_GET['timeStart'];
$timeEnd = $_GET['timeEnd'];
$serviceName = $_GET['service'];

include_once('../head.php');
require_once('../models/queryReports.php');
?>
<br>
<!-- Columns start at 50% wide on mobile and bump up to 33.3% wide on desktop -->

<body>
    <div class="row">
        <div class="col-6 col-md-1"></div>
        <!--<div class="col-6 col-md-10">-->
        <div class="col-sm-10">
            <h5 class="text-center"> Report: Agents Operation Panel 2 <br>
                <!--Service: <?php //echo $serviceName 
                                ?>
              <br>-->
            </h5>
            <br>
            <div class="text-center">
                    <a href="../index.php?dateStart=<?php echo urlencode($dateStart); ?>&dateEnd=<?php echo urlencode($dateEnd); ?>&timeStart=<?php echo urlencode($timeStart); ?>&timeEnd=<?php echo urlencode($timeEnd); ?>&service=<?php echo urlencode($serviceName); ?>" class="btn btn-info" id="submit">
                    <i class="fa fa-chevron-left"></i> Back
                </a>
            </div>
            <div class="text-right">
                <a href="https://cloudpbx.txmglobal.com:8443/operatorD2/Agentes/LoginAgente.jsp" class="btn btn-primary" target="_blank"><i class="fas fa-sign-in-alt"></i> Operation Panel 2 </a>
            </div>
            <br>
            <table class="table table-hover table-bordered" border="1" bordercolor="#666666" id="calls_offered_detail" style="border-collapse:collapse;">
                <thead>
                    <tr>
                        <th class="th2 text-center">Start Shift Date</th>
                        <th class="th2 text-center">Agent</th>
                        <th class="th2 text-center">User</th>
                        <th class="th2 text-center">Pass</th>
                        <th class="th2 text-center">Rotation</th>
                        <th class="th2 text-center">Queue</th>
                        <th class="th2 text-center">Client</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    $resultOfferedDetail = $mysqli->query($queryOperationPanel2);
                    while ($row = mysqli_fetch_array($resultOfferedDetail)) {
                        $date = $row["Date"];
                        $agent = $row["Agent"];
                        $speedDial = $row["SpeedDial"];
                        $area = $row["Area"];

                        $resultAgent = $mysqli->query($queryAgentOperationPanel2);
                        while ($row = mysqli_fetch_array($resultAgent)) {
                            $name = $row["Nombre"];
                            $alias = $row["Alias"];
                            $password = $row["Password"];
                            $rotation = $row["Rotacion"];

                            if ($name == $agent) {
                                $user = $alias;
                                $pass = $password;
                                $rota = $rotation;
                            }
                        }
                    ?>
                        <tr>
                            <?php
                            require('../models/queryReports.php');
                            $resultLogin = $mysqli->query($queryLogin);
                            while ($row = mysqli_fetch_array($resultLogin)) {
                                $dateLogin = $row["Fecha"];
                            ?>
                                <td><?php echo $dateLogin ?></td>
                            <?php
                            }
                            ?>
                            <td><?php echo $agent ?></td>
                            <td><?php echo $user ?></td>
                            <td><?php echo $pass ?></td>
                            <td><?php
                                if ($rota == "") {
                                    $rota = "Please Start shift and then End shift again";
                                }
                                echo $rota
                                ?>
                            </td>
                            <td>
                                <select class="form-control">
                                    <?php
                                    $resultArea = $mysqli->query($queryArea2);
                                    while ($row = mysqli_fetch_array($resultArea)) {
                                        $descripcion2 = $row["Descripcion"];
                                        $rota2 = $row["Rotacion"];
                                        $area2 = $row["Area"];
                                        $client2 = $row["Client"];
                                    ?>
                                        <option value=""><?php echo $area2 ?></option>
                                    <?php
                                    }
                                    ?>
                                </select>
                            </td>
                            <td>
                            <select class="form-control">
                                <?php
                                // Reiniciar el puntero del resultado para poder volver a recorrerlo
                                $resultArea->data_seek(0); // Vuelve al inicio del resultado
                                while ($row = mysqli_fetch_array($resultArea)) {
                                    $client2 = $row["Client"];
                                ?>
                                    <option value=""><?php echo $client2; ?></option>
                                <?php
                                }
                                ?>
                            </select>
                        </tr>
                    <?php
                    }
                    ?>
                </tbody>
            </table>
            <br />
        </div>
    </div>

    <!-- Datatables CSS -->
    <link rel="stylesheet" type="text/css" href="datatables/datatables.min.css" />
    <!-- Datatables Bootstrap 4 CSS -->
    <link rel="stylesheet" type="text/css" href="datatables/DataTables-1.10.18/css/dataTables.bootstrap4.min.css">
    <!-- Datatables JS -->
    <script type="text/javascript" src="datatables/datatables.min.js"></script>
    <!-- Usar botones en datatables JS -->
    <script src="datatables/Buttons-1.5.6/js/dataTables.buttons.min.js"></script>
    <script src="datatables/JSZip-2.5.0/jszip.min.js"></script>
    <script src="datatables/pdfmake-0.1.36/pdfmake.min.js"></script>
    <script src="datatables/pdfmake-0.1.36/vfs_fonts.js"></script>
    <script src="datatables/Buttons-1.5.6/js/buttons.html5.min.js"></script>

    <script type="text/javascript" src="js/tables.js"></script>
    <script type="text/javascript" src="js/sorttable.js"></script>

    <?php include_once('foot.php'); ?>

</body>

</html>