 <!-- Main content -->
<section class="content">
  <div class="container-fluid">
    <div class="row">
      <div class="col-12">
        <div class="card">
          <div class="card-header">
            <div class="row">
              <div class="col-sm-6">
                <h3 class="card-title">Pelanggan Unmanage</h3>
              </div>
              <div class="col-sm-6">
                <ol class="float-sm-right mb-0">
                </ol>
              </div>
            </div>
          </div>
          <!-- /.card-header -->
          <div class="card-body">
            <div class="row">
              <div class="col-md-4">
                <div class="card">
                    <div class="card-body text-center text-danger">
                        <h4>INFORMASI</h4>
                        <hr>
                        <p>Ini adalah data yang termonitoring aktif di PPPOE Mikrotik tapi tidak terdaftar di aplikasi</p>
                    </div>
                </div>
              </div>
              <div class="col-md-8">
                <table id="example1" class="table table-bordered table-striped">
                  <thead>
                  <tr>
                    <th>Nama Server</th>
                    <th>Nama Mikrotik</th>
                    <th>Akun PPPOE</th>
                    <th>IP Address</th>
                    <th>Action</th>
                  </tr>
                  </thead>
                  <tbody>
                  <?php
                    $aserver = mysqli_query($con, "SELECT id, id_data_server, ppp_unmanage, nama FROM setting_mikrotik $SqlDataWHId");
                    while ($server = mysqli_fetch_assoc($aserver)) {
                        // Decode JSON dari kolom `ppp_unmanage`
                        $unmanage = json_decode($server['ppp_unmanage'], true);
                    
                        // Validasi apakah hasil decode adalah array
                        if (is_array($unmanage)) {
                            foreach ($unmanage['akun_unmanage'] as $key => $value) {
                    ?>
                    <tr>
                        <td>
                            <?php 
                            // Jika Anda ingin menampilkan data server
                            $datasv = explode("|", $server['id_data_server']);
                            foreach ($datasv as $isidata) {
                                $asv = mysqli_query($con, "SELECT nama_server FROM data_server WHERE id = '$isidata'");
                                $sv = mysqli_fetch_assoc($asv);
                                echo htmlspecialchars($sv['nama_server']);
                            }
                            ?>
                        </td>
                        <td><?php echo htmlspecialchars($server['nama']); ?></td>
                        <td><?php echo htmlspecialchars($value['akun']); ?></td>
                        <td><?php echo htmlspecialchars($value['ip_address']); ?></td>
                        <td>
                            <a href="?<?php echo encrypt_url('user_remote|0000|' . $server['id'] . '|' . $value['ip_address'] . '|' . $value['akun']); ?>" 
                               class="btn btn-sm btn-success ml-1" style="border-radius: 20px;">Remote</a>
                        </td>
                    </tr>
                    <?php 
                            } // End of foreach
                        } else {
                            echo "<tr><td colspan='5'>Data PPP Unmanage tidak valid</td></tr>";
                        }
                    } // End of while
                    ?>

                  </tbody>
                </table>   
              </div>
            </div>
          </div>
          <!-- /.card-body -->
        </div>
        <!-- /.card -->
      </div>
      <!-- /.col -->
    </div>
    <!-- /.row -->
  </div>
  <!-- /.container-fluid -->
</section>
<!-- /.content -->