<?php require_once('../Connections/cmctrfdb.php'); ?>

<?php require_once('../webassist/mysqli/rsobj.php'); ?>

<?php



include('include/headscript.php');

include('languages/' . $_SESSION['langselect'] . '/tdgen.php');

?>

<?php

$archivetdlist = new WA_MySQLi_RS("archivetdlist", $cmctrfdb, 0);

$archivetdlist->setQuery("SELECT data_td.*, `trf-details`.*, data_td.zipname AS zipnametd FROM data_td LEFT JOIN `trf-details` ON `trf-details`.idtrfdetails=data_td.idtrf WHERE data_td.idcompany='$idcompany' AND data_td.signedontd IS NOT NULL ORDER BY data_td.signedontd");

$archivetdlist->execute();



?>



<?php





$drafttd = new WA_MySQLi_RS("drafttd", $cmctrfdb, 0);

$drafttd->setQuery("SELECT * FROM data_td LEFT JOIN `trf-details` ON `trf-details`.idtrfdetails=data_td.idtrf WHERE data_td.idcompany='$idcompany'  AND data_td.signedontd IS NULL ORDER BY data_td.signedontd");

$drafttd->execute();

$idtrftd = $drafttd->getColumnVal("idtrf");



?>

<!DOCTYPE html>

<html lang="en">



<head>

    <meta charset="utf-8" />

    <title><?php echo $titlepage; ?> </title>

    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <meta content="CIMAC TRF Portal" name="description" />

    <meta content="" name="author" />

    <meta http-equiv="X-UA-Compatible" content="IE=edge" />



    <!-- App favicon -->

    <link rel="shortcut icon" href="../images/favicon.ico">



    <!-- DataTables -->



    <link rel="shortcut icon" type="image/png" href="/media/images/favicon.png">

    <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://www.datatables.net/rss.xml">

    <link rel="stylesheet" type="text/css" href="/media/css/site-examples.css?_=8f7cff5ee7757412879aedf3efbfaee01">

    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.13.1/css/jquery.dataTables.min.css">

    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/2.3.2/css/buttons.dataTables.min.css">

    <style type="text/css" class="init">



    </style>

    <script type="text/javascript" src="/media/js/site.js?_=1d5abd169416a09a2b389885211721dd" data-domain="datatables.net" data-api="https://plausible.sprymedia.co.uk/api/event"></script>

    <script src="https://media.ethicalads.io/media/client/ethicalads.min.js"></script>

    <script type="text/javascript" src="/media/js/dynamic.php?comments-page=extensions%2Fbuttons%2Fexamples%2Finitialisation%2Fexport.html" async></script>

    <script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-3.5.1.js"></script>

    <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.13.1/js/jquery.dataTables.min.js"></script>

    <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/2.3.2/js/dataTables.buttons.min.js"></script>

    <script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>

    <script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>

    <script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>

    <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/2.3.2/js/buttons.html5.min.js"></script>

    <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/2.3.2/js/buttons.print.min.js"></script>

    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

    <!-- Font Awesome -->

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" integrity="sha512-RqEzHvnvS1k5K5wzgp5yoWY5U6TD5EoXyj9iikETmdcy1G6dbCVa+ZmzBm7VWzmj8Ov7VwtA9x9X7VWjG8SRFg==" crossorigin="anonymous" referrerpolicy="no-referrer" />

    <!--Form Wizard-->

    <link href="../plugins/jquery-steps/jquery.steps.css" rel="stylesheet" type="text/css">

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



    <!-- App css -->

    <link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" />

    <link href="assets/css/jquery-ui.min.css" rel="stylesheet">

    <link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" />

    <link href="assets/css/metisMenu.min.css" rel="stylesheet" type="text/css" />

    <link href="assets/css/app.min.css" rel="stylesheet" type="text/css" />





    <!-- submit form with button -->

    <script>

        function formSubmit() {

            document.forms["myForm"].submit();

        }

    </script>

    </script>

    <script type="text/javascript" class="init">

        $(document).ready(function() {

            var table = $('#example').DataTable({

                pageLength: 20,

                order: [

                    [0, 'desc']

                ],



                dom: 'Bfrtip',

                buttons: [

                    'copy', 'csv', 'excel', 'pdf'

                ]





            });



            $('a.toggle-vis').on('click', function(e) {

                e.preventDefault();



                // Get the column API object

                var column = table.column($(this).attr('data-column'));



                // Toggle the visibility

                column.visible(!column.visible());

            });



        });

    </script>



    <script type="text/javascript" class="init">

        $(document).ready(function() {

            var table = $('#readytrf').DataTable({

                pageLength: 20,

                order: [

                    [0, 'desc']

                ],



                dom: 'Bfrtip',

                buttons: [

                    'copy', 'csv', 'excel', 'pdf'

                ]





            });



            $('a.toggle-vis').on('click', function(e) {

                e.preventDefault();



                // Get the column API object

                var column = table.column($(this).attr('data-column'));



                // Toggle the visibility

                column.visible(!column.visible());

            });



        });

    </script>

    <script>

        document.getElementById('clonetrfalert').addEventListener('click', function(e) {

            e.preventDefault();

            if (confirm("Sei sicuro di voler andare al link clonetrf.php?")) {

                window.location.href = e.target.parentNode.href;

            }

        });

    </script>



</head>



<body>



    <!-- Top Bar Start -->







    <!-- Top Bar Start -->

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

    <!-- Top Bar End -->





    <!-- Left Sidenav -->

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

    <!-- end left-sidenav-->



    <div class="page-wrapper">

        <!-- Page Content-->

        <div class="page-content">



            <div class="container-fluid">

                <!-- Page-Title -->

                <div class="row">

                    <div class="col-sm-12">

                        <div class="page-title-box">

                            <div class="float-right">

                                <ol class="breadcrumb">

                                    <li class="breadcrumb-item"><a href="javascript:void(0);">TRF</a></li>

                                    <li class="breadcrumb-item active">Starter</li>

                                </ol>

                            </div>

                            <h4 class="page-title"><?php echo $titlewb; ?></h4>

                        </div><!--end page-title-box-->

                    </div><!--end col-->

                </div>

                <div class="row">

                    <div class="col-sm-12">







                        <!-- DRAFT TRF -->



                        <div class="card">





                            <!-- card for show requirements -->

                            <div class="card">

                                <div class="card-body">

                                    <h4 class="mt-0 header-title"><?php echo $drafttdtitle; ?></h4>



                                    <table id="example" class="display table table-striped table-bordered dt-responsive nowrap" style="border-collapse: collapse; border-spacing: 0; width: 100%;">

                                        <thead>

                                            <tr>

                                                <th>TD N.</th>

                                                <th>REV</th>

                                                <th>Description</th>

                                                <th>Status</th>

                                                <th><?php echo $action; ?></th>

                                                <th></th>

                                            </tr>

                                        </thead>





                                        <tbody>

                                            <?php

                                            $wa_startindex = 0;

                                            while (!$drafttd->atEnd()) {

                                                $wa_startindex = $drafttd->Index;

                                            ?>

                                                <tr><?php $iddata_td = $drafttd->getColumnVal("iddata_td"); ?>

                                                    <td><?php echo ($drafttd->getColumnVal("tdnumber")); ?></td>

                                                    <td><?php if (($drafttd->getColumnVal("td_rev")) > 0) { ?>R<?php echo $drafttd->getColumnVal("td_rev");

                                                                                                            } ?></td>



                                                    <td><?php echo ($drafttd->getColumnVal("sample_description")); ?></td>





                                                    <td><?php

                                                        $statusnow = $drafttd->getColumnVal("statustd");

                                                        if ($statusnow == "Draft") { ?>

                                                            <div class="d-flex align-items-center text-danger"> <i class="bx bx-radio-circle-marked bx-burst bx-rotate-90 align-middle font-18 me-1"></i>

                                                                <span>Draft</span>

                                                            </div>

                                                        <?php } elseif ($statusnow == "Revision") { ?>

                                                            <div class="d-flex align-items-center text-warning"> <i class="bx bx-radio-circle-marked bx-burst bx-rotate-90 align-middle font-18 me-1"></i>

                                                                <span>Revision</span>

                                                            </div>

                                                        <?php } else { ?>

                                                            <div class="d-flex align-items-center text-primary"> <i class="bx bx-radio-circle-marked bx-burst bx-rotate-90 align-middle font-18 me-1"></i>

                                                                <span>Waiting Sign</span>

                                                            </div>

                                                        <?php } ?>

                                                    </td>











                                                    <td>

                                                        <?php if ($statusnow == "Draft") { ?>

                                                            <a href="techdossier_start.php?idtd=<?php echo $iddata_td; ?>&idtrftd=<?php echo $drafttd->getColumnVal("idtrf"); ?>"><button type="button" class="btn btn-danger waves-effect waves-danger"><?php echo $proceedtd; ?></button></a>

                                                    </td>

                                                <?php } elseif ($statusnow == "Revision") { ?>

                                                    <button type="button" class="btn btn-warning"><?php echo $waitingrevision; ?></button></td>

                                                <?php } else { ?>

                                                    <a href="declarationtd.php?idtd=<?php echo $iddata_td; ?>&idtrftd=<?php echo $drafttd->getColumnVal("idtrf"); ?>""><button type=" button" class="btn btn-primary waves-effect waves-light"><?php echo $waitingsign; ?></button></a></td>

                                                <?php } ?>



                                                <td>

                                                    <a href="javascript:void(0);" onclick="confirmDeletion(<?php echo $iddata_td; ?>, '<?php echo $drafttd->getColumnVal("tdnumber"); ?>')">

                                                        <i class="fas fa-trash-alt text-danger font-16"></i>

                                                    </a>

                                                </td>





                                                </tr>

                                                <script>

                                                    function confirmDeletion(id, tdNumber) {

                                                        Swal.fire({

                                                            title: '<?php echo $areyousure; ?>',

                                                            text: "<?php echo $proceeddeletetd; ?>" + tdNumber + "?",

                                                            icon: 'warning',

                                                            showCancelButton: true,

                                                            confirmButtonColor: '#3085d6',

                                                            cancelButtonColor: '#d33',

                                                            confirmButtonText: '<?php echo $yescancel; ?>',

                                                            cancelButtonText: '<?php echo $nostop; ?>'

                                                        }).then((result) => {

                                                            if (result.isConfirmed) {

                                                                window.location.href = "deletetd.php?idtd=" + id;

                                                            }

                                                        });

                                                    }

                                                </script>





                                            <?php

                                                $drafttd->moveNext();

                                            }

                                            $drafttd->moveFirst(); //return RS to first record

                                            unset($wa_startindex);

                                            unset($wa_repeatcount);

                                            ?>

                                        </tbody>

                                    </table>





                                    <br>









                                </div><!--end card-body-->





                            </div><!--end card-->









                        </div><!--end col-->



                        <!-- COMPLETE TRF -->



                        <div class="card">





                            <!-- card for show requirements -->

                            <div class="card">

                                <div class="card-body">

                                    <h4 class="mt-0 header-title"><?php echo $archivetd; ?></h4>



                                    <table id="readytrf" class="display table table-striped table-bordered dt-responsive nowrap" style="border-collapse: collapse; border-spacing: 0; width: 100%;">

                                        <thead>

                                            <tr>

                                                <th>TD N.</th>

                                                <th>REV</th>

                                                <th>Signed On</th>

                                                <th>Description</th>

                                                <th>Insert by</th>

                                                <th>PDF</th>

                                                <th>ZIP</th>

                                                <th>ACTION</th>



                                            </tr>

                                        </thead>





                                        <tbody>

                                            <?php

                                            $wa_startindex = 0;

                                            while (!$archivetdlist->atEnd()) {

                                                $wa_startindex = $archivetdlist->Index;

                                            ?>

                                                <tr>

                                                    <td><?php echo ($archivetdlist->getColumnVal("tdnumber")); ?></td>

                                                    <td><?php if (($archivetdlist->getColumnVal("td_rev")) > 0) { ?>R<?php echo $archivetdlist->getColumnVal("td_rev");

                                                                                                                    } ?></td>

                                                    <td><?php echo ($archivetdlist->getColumnVal("signedontd")); ?></td>



                                                    <td><?php echo ($archivetdlist->getColumnVal("sample_description")); ?></td>









                                                    <td><?php echo ($archivetdlist->getColumnVal("signametd")); ?></td>

                                                    <td><a href="tdpdf/<?php echo $archivetdlist->getColumnVal("pdffilenametd"); ?>" target="_blank"><i class="fas fa-file-pdf text-danger font-20"></i></a></td>



                                                    <?php if (!empty($archivetdlist->getColumnVal("zipnametd"))) : ?>

                                                        <td>

                                                            <a href="uploadtddocuments/ziptd//<?php echo htmlspecialchars($archivetdlist->getColumnVal("zipnametd")); ?>" target="_blank">

                                                                <i class="fas fa-file-archive text-warning font-20"></i>

                                                            </a>

                                                        </td>

                                                    <?php else : ?>

                                                        <td>N/A</td> <!-- o lascia vuoto se preferisci -->

                                                    <?php endif; ?>



                                                    <td>

                                                        <button type="button" onclick="

    Swal.fire({

        title: 'Sei sicuro di voler duplicare il TF N. <?php echo $archivetdlist->getColumnVal('tdnumber'); ?>?',

        icon: 'warning',

        showCancelButton: true,

        confirmButtonColor: '#3085d6',

        cancelButtonColor: '#d33',

        confirmButtonText: 'Sì, duplica!',

        cancelButtonText: 'No, chiudi!'

    }).then((result) => {

        if (result.isConfirmed) {

            window.location.href='tdclone1step.php?idtrf=<?php echo $archivetdlist->getColumnVal('idtrfdetails'); ?>&idtd=<?php echo $archivetdlist->getColumnVal('iddata_td'); ?>';

        }

    });

" class="btn btn-outline-warning waves-effect waves-light">

                                                            <i class="far fa-copy"></i>

                                                        </button>



                                                        <button type="button" onclick="

    Swal.fire({

        title: 'Sei sicuro di voler revisionare il TF N. <?php echo $archivetdlist->getColumnVal('tdnumber'); ?>?',

        icon: 'warning',

        showCancelButton: true,

        confirmButtonColor: '#3085d6',

        cancelButtonColor: '#d33',

        confirmButtonText: 'Sì, procedi!',

        cancelButtonText: 'No, chiudi!'

    }).then((result) => {

        if (result.isConfirmed) {

            window.location.href='tdrev.php?idtrf=<?php echo $archivetdlist->getColumnVal('idtrfdetails'); ?>&idtd=<?php echo $archivetdlist->getColumnVal('iddata_td'); ?>';

        }

    });

" class="btn btn-outline-danger waves-effect waves-light">

                                                            Rev

                                                        </button>

                                                    </td>

                                                </tr>



                                            <?php

                                                $archivetdlist->moveNext();

                                            }

                                            $archivetdlist->moveFirst(); //return RS to first record

                                            unset($wa_startindex);

                                            unset($wa_repeatcount);

                                            ?>

                                        </tbody>

                                    </table>

                                    <br>









                                </div><!--end card-body-->





                            </div><!--end card-->









                        </div>

                    </div>

                    <!-- end page title end breadcrumb -->





                </div><!-- container -->

                <!-- footer start -->

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

                </footer><!--end footer-->

            </div>

            <!-- end page content -->

        </div>

        <!-- end page-wrapper -->







        <!-- jQuery  -->



        <script src="assets/js/bootstrap.bundle.min.js"></script>

        <script src="assets/js/metismenu.min.js"></script>

        <script src="assets/js/waves.js"></script>

        <script src="assets/js/feather.min.js"></script>

        <script src="assets/js/jquery.slimscroll.min.js"></script>

        <script src="assets/js/jquery-ui.min.js"></script>









        <script src="../plugins/jquery-steps/jquery.steps.min.js"></script>

        <script src="assets/pages/jquery.form-wizard.init.js"></script>



        <!-- App js -->

        <script src="assets/js/app.js"></script>



</body>



</html>