<?php
/*
 *  Copyright (C) 2018 Laksamadi Guko.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
session_start();
// hide all error
error_reporting(0);
if (!isset($_SESSION["mikhmon"])) {
	header("Location:../admin.php?id=login");
} else {

	// load session MikroTik
	$session = $_GET['session'];
	$serveractive = $_GET['server'];


	$getactive = $API->comm("/ppp/active/print");
	$TotalReg = count($getactive);

	$countactive = $API->comm("/ppp/active/print", array(
		"count-only" => "",
	));
	
	$all_users = $API->comm("/ppp/secret/print");

// Buat array nama user yang sedang aktif
$active_usernames = array_column($getactive, 'name');

// Filter user offline
$offline_users = array_filter($all_users, function($user) use ($active_usernames) {
    return !in_array($user['name'], $active_usernames);
});
}

?>
<div class="row">
	<div id="reloadHotspotActive">
		<div class="col-12">
			<div class="card">
				<div class="card-header">
					<h3><i class="fa fa-user-times"></i> Offline PPP Users</h3>
				</div>
				<div class="card-body overflow">
					<br>
					<table id="dataTable" class="table table-bordered table-hover text-nowrap">
						<thead>
                <tr>
                    <th class="text-center">#</th>
                    <th><?= $_name ?></th>
                    <th>Profile</th>
                    <th>Last Logged Out</th>
                    <th>Last Disconnect Reason</th>
                </tr>
						</thead>
		            <tbody>
                <?php
                if (count($offline_users) === 0) {
                    echo "<tr><td colspan='4' class='text-center'>All users are currently online.</td></tr>";
                } else {
                    $no = 1;
                    foreach ($offline_users as $user) {
                        echo "<tr>";
                        echo "<td class='text-center'>{$no}</td>";
                        echo "<td>" . $user['name'] . "</td>";
                        echo "<td>" . $user['profile'] . "</td>";
                        echo "<td>" . $user['last-logged-out'] . "</td>"; 
                        echo "<td>" . $user['last-disconnect-reason'] . "</td>";echo "</tr>";
                        $no++;
                    }
                }
                ?>
            </tbody>
					</table>
				</div>
			</div>
		</div>
	</div>
</div>