<?php include('../include/headscript.php'); ?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <?php include('../include/seo.php'); ?>
    <title>EasySpec - Reportify</title>

    <!-- Favicon -->
    <link rel="shortcut icon" href="../assets/images/favicon.ico">

    <!-- Bootstrap CSS -->
    <link href="../assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="../assets/css/icons.css" rel="stylesheet" type="text/css">
    <link href="../assets/css/style.css" rel="stylesheet" type="text/css">

    <!-- DataTables CSS -->
    <link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css">
    <link rel="stylesheet" href="https://cdn.datatables.net/buttons/2.4.1/css/buttons.dataTables.min.css">

    <!-- SweetAlert CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@10/dist/sweetalert2.min.css">

    <!-- Boxicons -->
    <link href="https://cdn.jsdelivr.net/npm/boxicons@2.0.7/css/boxicons.min.css" rel="stylesheet">

    <style>
        .table-custom th,
        .table-custom td {
            word-wrap: break-word;
        }

        .table td {
            white-space: nowrap;
            /* Impedisce che i contenuti vadano a capo automaticamente */
        }

        .table td:first-child {
            white-space: normal;
            /* Forza il nome dell'analisi ad andare a capo */
            word-wrap: break-word;
            max-width: 200px;
            /* Regola la larghezza massima della cella */
        }

        .table td:last-child .btn {
            margin-right: 5px;
            /* Aggiunge spazi tra i pulsanti */
        }
    </style>

</head>

<body class="fixed-left">

    <div id="wrapper">

        <?php include('../include/navigationbar.php'); ?>

        <div class="content-page">
            <div class="content">
                <?php include('../include/topbar.php'); ?>

                <div class="page-content-wrapper">
                    <div class="container-fluid">

                        <!-- Page Title -->
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="page-title-box">
                                    <div class="btn-group float-right">
                                        <ol class="breadcrumb hide-phone p-0 m-0">
                                            <li class="breadcrumb-item"><a href="#">Reportify</a></li>
                                            <li class="breadcrumb-item active">EasySpec</li>
                                        </ol>
                                    </div>
                                    <h4 class="page-title">EasySpec</h4>
                                </div>
                            </div>
                        </div>

                        <!-- Action Buttons -->
                        <div class="row">
                            <div class="col-xl-12">
                                <div class="card">
                                    <div class="card-body">
                                        <h5 class="header-title pb-3 mt-0">EasySpec</h5>
                                        <a class="btn btn-danger" href="insert-analysis.php" role="button">Insert Analysis</a>
                                        <a class="btn btn-danger" href="analysis-category.php" role="button">Analysis Category</a>
                                        <a class="btn btn-danger" href="rsl.php" role="button">RSL</a>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- DataTable -->
                        <div class="row">
                            <div class="col-xl-12">
                                <div class="card">
                                    <div class="card-body">
                                        <div class="table-responsive">
                                            <table id="datatable-analysis" class="table table-striped table-sm table-custom">
                                                <thead>
                                                    <tr>
                                                        <th>Name</th>
                                                        <th>Description</th>
                                                        <th>Family</th>
                                                        <th>SuperGroup</th>
                                                        <th>Analysis Code</th>
                                                        <th>Actions</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <?php
                                                    $tablequery = new WA_MySQLi_RS("analysis", $repnew, 0);
                                                    $tablequery->setQuery("SELECT * FROM `analysisvocabulary`
            LEFT JOIN family_analysis ON family_analysis.idfamilyanalysis = analysisvocabulary.family_analysis 
            LEFT JOIN supergroup ON analysisvocabulary.supergroup=supergroup.idsupergroup
            WHERE analysisvocabulary.preferred = 'Y' 
            ORDER BY analysisvocabulary.nameanalysisvoc");
                                                    $tablequery->execute();

                                                    while (!$tablequery->atEnd()) {
                                                    ?>
                                                        <tr>
                                                            <td><?php echo $tablequery->getColumnVal("nameanalysisvoc"); ?></td>
                                                            <td><?php echo $tablequery->getColumnVal("description_analysis"); ?></td>
                                                            <td><?php echo $tablequery->getColumnVal("namefamily"); ?></td>
                                                            <td><?php echo $tablequery->getColumnVal("name"); ?></td>
                                                            <td><?php echo $tablequery->getColumnVal("analysiscode"); ?></td>
                                                            <td>
                                                                <a class="btn btn-success" href="update-component-list.php?idanalysis=<?php echo $tablequery->getColumnVal('idanalysisvocabulary'); ?>">Component List</a>
                                                                <a class="btn btn-warning" href="update-analysis.php?idanalysis=<?php echo htmlspecialchars($tablequery->getColumnVal('idanalysisvocabulary')); ?>"><i class="fas fa-pencil-alt text-white"></i></a>
                                                                <a class="btn btn-danger" onclick="confirmDeletion(<?php echo htmlspecialchars($tablequery->getColumnVal('idanalysisvocabulary')); ?>);"><i class="fas fa-trash-alt text-white"></i></a>
                                                            </td>
                                                        </tr>
                                                    <?php
                                                        $tablequery->moveNext();
                                                    }
                                                    $tablequery->moveFirst();
                                                    ?>
                                                </tbody>
                                            </table>

                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>

            </div>

            <?php include('../include/footer.php'); ?>

        </div>
    </div>

    <!-- jQuery -->
    <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>

    <!-- Bootstrap JS -->
    <script src="../assets/js/bootstrap.min.js"></script>

    <!-- DataTables JS -->
    <script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/2.4.1/js/dataTables.buttons.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/2.4.1/js/buttons.html5.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/2.4.1/js/buttons.print.min.js"></script>

    <!-- SweetAlert2 JS -->
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@10/dist/sweetalert2.min.js"></script>

    <!-- DataTable Initialization -->
    <script>
        $(document).ready(function() {
            $('#datatable-analysis').DataTable({
                dom: 'lBfrtip',
                buttons: ['copy', 'csv', 'excel', 'pdf', 'print'],
                paging: true,
                searching: true,
                pageLength: 50,
                ordering: true,
                responsive: true,
                language: {
                    url: "https://cdn.datatables.net/plug-ins/1.13.6/i18n/en-GB.json"
                }
            });
        });

        function confirmDeletion(idAnalysis) {
            Swal.fire({
                title: 'Do you want to cancel the analysis?',
                text: "The Analysis will be deactivated!",
                icon: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: 'Yes, delete it!'
            }).then((result) => {
                if (result.isConfirmed) {
                    window.location.href = `cancel-analysis.php?idanalysis=${idAnalysis}`;
                }
            });
        }
    </script>

</body>

</html>