<?php $r=mysqli_query($GLOBALS['con'],"SELECT * FROM `locations` WHERE `clientnumber`='".$_REQUEST['clientnumber']."' AND `statuslive`='0'");?>
<script>
document.getElementById('navBox').innerHTML =
    '<li class="breadcrumb-item"><a href="index.php?t=includes/master&p=client.php&view=list">Client List</a><i class="fad fa-angle-double-right mx-2 mt-1"" aria-hidden="true"></i></li><li class="breadcrumb-item"><a href="index.php?t=includes/master&p=client.php&clientnumber=<?= $_REQUEST['clientnumber']?>&clientname=<?= $_REQUEST['clientname']?>&view=asset"><?= $_REQUEST['clientname']?></a><i class="fad fa-angle-double-right mx-2 mt-1"" aria-hidden="true"></i></li><li class="breadcrumb-item active"><strong>Archived</strong>Locations</li>'
</script>

<div class="row">
    <div class="col text-end">
        <a href="index.php?t=includes/master&p=locations.php&clientnumber=<?= $_REQUEST['clientnumber']?>&clientname=<?= $_REQUEST['clientname']?>" class="btn btn-secondary btn-sm"><i class="fa fa-plus" aria-hidden="true"></i> New
            Location</a>
        <a href="index.php?t=includes/master&p=locations.php&clientnumber=<?= $_REQUEST['clientnumber']?>&clientname=<?= $_REQUEST['clientname']?>" class="btn btn-secondary btn-sm m-0 px-3 waves-effect waves-light" data-toggle="tooltip"
           data-placement="bottom" title="View Active Locations"><i class="fad fa-upload" aria-hidden="true"></i> View Active Locations</a>
    </div>
</div>

<h3 class="lead"><span class="text-muted">Locations for</span> <strong><?= $_REQUEST['clientname']?></strong></h3>
<table id="datatables" class="table table-striped table-sm table-bordered table-hover responsive" width="100%" style="width:100%">
    <thead class="table-dark">
        <tr>
            <th class="no-sort"></th>
            <th>Location Name</th>
            <th>Address</th>
            <th>Post Code</th>
            <th>Contact</th>
            <th>Phone</th>
            <th>Notes</th>
            <th class="no-sort"></th>
        </tr>
    </thead>
    <tbody>
        <?php while($d=mysqli_fetch_array($r)){?>
        <tr>
            <td><?= $d['locnumber']?></td>
            <td><?= $d['locname']?></td>
            <td><?= $d['locaddress1']?>,<?= $d['locaddress2']?>,<?= $d['locaddress3']?>,<?= $d['locaddress4']?></td>
            <td><?= $d['postcode']?></td>
            <td><?= $d['contactlc']?></td>
            <td><?= $d['contacttel']?></td>
            <td><?= $d['locnotes']?></td>
            <td class=" text-center">
                <div class="btn-group" role="group">
                    <a href="javascript:void(0)" onclick="showPop('Plant Summary','includes/master/location-plant.php?clientnumber=<?= $_REQUEST['clientnumber']?>&locnumber=<?= $d['locnumber']?>','','')" style="z-index:999"
                       class="text-light btn btn-secondary noprint me-3" data-mdb-tooltip-init data-mdb-placement="bottom" data-mdb-trigger="hover" totitle="hover" title="Location Plant Summary"><i
                           class="fa-duotone fa-clipboard-list"></i></a>

                    <!--<a href="javascript:void(0)" onclick="showPop('Item Summary','includes/master/itemSummary.php?clientnumber=<?= $_REQUEST['clientnumber']?>&location=<?= $d['locnumber']?>','','')" style="z-index:999" class="text-light btn btn-secondary noprint me-3" data-mdb-tooltip-init data-mdb-placement="bottom" data-mdb-trigger="hover"totitle="hover"  title="Location Item Summary" ><i class="fad fa-layer-group"></i></a>-->

                    <a href="javascript:void(0)" onclick="printSchedule('<?= $_REQUEST['clientnumber']?>','<?= $d['locnumber']?>','<?= $d['postcode']?>')" style="z-index:999" class="text-light btn btn-secondary noprint me-3"
                       data-mdb-tooltip-init data-mdb-placement="bottom" data-mdb-trigger="hover" totitle="hover" title="Pretty print schedule"><i class="fad fa-print"></i></a>
                    <a href="index.php?t=includes/master&p=locations.php&view=edit&clientnumber=<?= $_REQUEST['clientnumber']?>&clientname=<?= $_REQUEST['clientname']?>&locnumber=<?= $d['locnumber']?>"
                       class="btn btn-secondary noprint me-3"><i class="fad fa-info-circle"></i></a>
                    <a href="javascript:void(0)" class="btn btn-secondary noprint archiveButton me-2 waves-effect waves-light" data-mdb-tooltip-init data-mdb-placement="top" data-mdb-trigger="hover" title="Reinstate Item"
                       onclick="reinstateLoc('<?= $d['locnumber']?>')"><i class="fad fa-upload" aria-hidden="true"></i></a>
                </div>
            </td>
        </tr>
        <?php }?>
    </tbody>
</table>
<script>
function reinstateLoc(i) {
    var dest = '<p>Are you sure you wish to reinstate this location and all items listed at this location?</p>'
    loadModalContent(dest, 'alertBox', 'modal-md', 1060, 'true', 'Reinstate Location', 'cancelConfirm', () => confirmReinstate(i))

}

function confirmReinstate(i) {
    $.post(ROOT_URL + '/includes/locations/location_functions.php', {
        FUNCTION: 'reinstate',
        locnumber: i,
        clientnumber: '<?= $_REQUEST['clientnumber']?>',
        tenant: TENANT_URL
    }, function(ret) {
        //debug(ret)
        if ($.trim(ret) == "s") {
            document.location.href = 'index.php?t=includes/master&p=locations.php&clientnumber=<?= $_REQUEST['clientnumber']?>&clientname=<?= $_REQUEST['clientname']?>'
        }
    })

}
</script>
<?php $table="datatables";
require_once(ROOT_URL.'/includes/tables/single_table.php');?>