<?php
$tenant = $_REQUEST['tenant'];
if (file_exists('../../../' . $tenant . '/config.php')) {
    require_once('../../../' . $tenant . '/config.php');
}
if (file_exists('/config.php')) {
    require_once('/config.php');
}

$d = explode("|", $_REQUEST['data']);
?>
<style>
#newTable>tbody>tr>td,
#current>tbody>tr>th {
    vertical-align: middle
}

#popupModal .filterButtons {
    display: none
}

#popupModal .dt-buttons {
    display: none
}

#newTable_wrapper table.dataTable,
#newTable {
    width: 100% !important;
}

/* Keep table full width */
#newTable_wrapper table.dataTable {
    width: 100% !important;
    table-layout: auto !important;
}

#newTable_wrapper table.dataTable colgroup col:nth-child(1),
#newTable_wrapper table.dataTable thead th:nth-child(1),
#newTable_wrapper table.dataTable tbody td:nth-child(1) {
    width: 1% !important;
    /* shrink-to-fit */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#newTable_wrapper table.dataTable colgroup col:nth-child(3),
#newTable_wrapper table.dataTable thead th:nth-child(3),
#newTable_wrapper table.dataTable tbody td:nth-child(3) {
    width: 1% !important;
    /* shrink-to-fit */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#newTable_wrapper table.dataTable colgroup col:nth-child(4),
#newTable_wrapper table.dataTable thead th:nth-child(4),
#newTable_wrapper table.dataTable tbody td:nth-child(4) {
    width: 1% !important;
    /* shrink-to-fit */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Optional: also shrink the last Actions column */
#newTable_wrapper table.dataTable colgroup col:nth-child(5),
#newTable_wrapper table.dataTable thead th:nth-child(5),
#newTable_wrapper table.dataTable tbody td:nth-child(5) {
    width: 20% !important;
    white-space: nowrap;
}
</style>

<div class="col-md-12 p-4">

    <table id="newTable" class="table table-striped table-hover w-100">

        <thead class="table-light">
            <tr>
                <th scope="col">Code</th>
                <th scope="col">Asset Types</th>
                <th scope="col">Capacity</th>
                <th scope="col">Frequency</th>
                <th scope="col"></th>
            </tr>
        </thead>
        <tbody>
            <?php
            $recall = mysqli_query($GLOBALS['con'], "SELECT * FROM `dd_plant` ORDER BY `description`");
            while ($dta = mysqli_fetch_array($recall)) { ?>
            <tr>
                <td><?= htmlspecialchars($dta['code']) ?></td>
                <td><?= htmlspecialchars($dta['description']) ?></td>
                <td><?= htmlspecialchars($dta['size']) ?></td>
                <td><?= htmlspecialchars($dta['frequency']) ?></td>
                <td class="text-center">
                    <button class="btn btn-success btn-sm text-light"
                        onClick="loadNew('<?= htmlspecialchars($dta['code']) ?>')">
                        <i class="fad fa-plus text-dark"></i> Add item
                    </button>
                </td>
            </tr>
            <?php } ?>
        </tbody>
    </table>
</div>


<?php
$table = "newTable";
require_once("../tables/single_table.php");
?>
<div id="erm" class="text-center"></div>
<script>
function loadNew(i) {
    window.location.href = "index.php?t=includes/master/&p=asset.php&view=new_attached&type=" + i +
        "&data=<?= $_REQUEST['data'] ?>"
}

$(document).ready(function() {
    $('#newTable_filter input,#newTable_length select').addClass('form-control form-control-sm');
})
</script>