105 lines
3.7 KiB
PHP
105 lines
3.7 KiB
PHP
<?php
|
|
require __DIR__ . "/../config/connect.php";
|
|
require __DIR__ . "/../config/encrypt.php";
|
|
|
|
$datadecrypt = decrypt_url($_GET['data']);
|
|
$dataurl = json_decode($datadecrypt, true);
|
|
|
|
$SqlSvData = $dataurl[0];
|
|
$SqlDataWHIdM = $dataurl[1];
|
|
$hotspotAktif = !empty($dataurl[2]) && $dataurl[2] == 1;
|
|
|
|
// Definisi kolom sesuai thead (No dihitung otomatis)
|
|
$columns = ['nama','nik','akun'];
|
|
if($hotspotAktif) {
|
|
$columns[] = 'user_hotspot';
|
|
}
|
|
$columns = array_merge($columns, [
|
|
'alamat','latitude','nomor_whatsapp','nama_server','nama_mikrotik','nama_paket','status_koneksi','time_start'
|
|
]);
|
|
|
|
// Paging
|
|
$limit = intval($_POST['length']);
|
|
$offset = intval($_POST['start']);
|
|
|
|
// Order
|
|
$orderIndex = intval($_POST['order'][0]['column']) - 1; // kurangi 1 karena No di kolom pertama
|
|
$orderCol = $columns[$orderIndex] ?? 'nama';
|
|
$orderDir = $_POST['order'][0]['dir'] ?? 'asc';
|
|
|
|
// Search
|
|
$search = $_POST['search']['value'] ?? '';
|
|
$where = "WHERE $SqlSvData status = 'aktif'";
|
|
if(!empty($search)) {
|
|
$where .= " AND (nama LIKE :search OR nik LIKE :search OR akun LIKE :search OR status_koneksi LIKE :search OR nomor_whatsapp LIKE :search OR nama_paket LIKE :search OR nama_server LIKE :search OR alamat LIKE :search OR time_start LIKE :search)";
|
|
}
|
|
|
|
// Hitung total
|
|
$totalStmt = $pdo->query("SELECT COUNT(id) FROM v_pelanggan WHERE $SqlSvData status = 'aktif'");
|
|
$recordsTotal = $totalStmt->fetchColumn();
|
|
|
|
// Query data
|
|
$sql = "SELECT id,akun,user_hotspot,nama,alamat,latitude,longitude,nomor_whatsapp,email,nik,
|
|
nama_server,nama_paket,time_start,status_koneksi,nama_mikrotik,id_setting_mikrotik,
|
|
time_update,ip_address
|
|
FROM v_pelanggan $where
|
|
ORDER BY $orderCol $orderDir
|
|
LIMIT :limit OFFSET :offset";
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
if(!empty($search)) $stmt->bindValue(':search', "%$search%");
|
|
$stmt->bindValue(':limit', $limit, PDO::PARAM_INT);
|
|
$stmt->bindValue(':offset', $offset, PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
// Format data
|
|
$no = $offset + 1;
|
|
$dataArray = [];
|
|
foreach($data as $row) {
|
|
$latlong = (substr($row['latitude'],0,1) != '-')
|
|
? "<a href='https://google.com/maps/?q={$row['latitude']}' target='_blank'>{$row['latitude']}</a>"
|
|
: "<a href='https://google.com/maps/?q={$row['latitude']},{$row['longitude']}' target='_blank'>{$row['latitude']}, {$row['longitude']}</a>";
|
|
|
|
$wa = "{$row['nomor_whatsapp']} <a href='https://wa.me/{$row['nomor_whatsapp']}' target='_blank' class='btn btn-sm btn-success' style='border-radius:20px;'><i class='fab fa-whatsapp'></i></a><br>{$row['email']}";
|
|
|
|
$status = $row['status_koneksi'];
|
|
if($status == 'On') {
|
|
$status .= " <a href='?".encrypt_url("user_remote|{$row['id']}|{$row['id_setting_mikrotik']}")."' class='btn btn-sm btn-success ml-1' style='border-radius: 20px;'>Remote</a><br>{$row['ip_address']}";
|
|
}
|
|
$status .= "<br>{$row['time_update']}";
|
|
|
|
$aksi = "<a href='?".encrypt_url("user_detail|{$row['id']}")."' class='btn btn-sm btn-info m-1'>Detail</a>";
|
|
|
|
// Build row sesuai urutan thead
|
|
$rowData = [
|
|
$no++,
|
|
$row['nama'],
|
|
$row['nik'],
|
|
$row['akun']
|
|
];
|
|
|
|
if($hotspotAktif) {
|
|
$rowData[] = $row['user_hotspot'];
|
|
}
|
|
|
|
$rowData[] = $row['alamat'];
|
|
$rowData[] = $latlong;
|
|
$rowData[] = $wa;
|
|
$rowData[] = $row['nama_server'];
|
|
$rowData[] = $row['nama_mikrotik'];
|
|
$rowData[] = $row['nama_paket'];
|
|
$rowData[] = $status;
|
|
$rowData[] = $row['time_start'];
|
|
$rowData[] = $aksi;
|
|
|
|
$dataArray[] = $rowData;
|
|
}
|
|
|
|
echo json_encode([
|
|
"draw" => intval($_POST['draw']),
|
|
"recordsTotal" => $recordsTotal,
|
|
"recordsFiltered" => $recordsTotal,
|
|
"data" => $dataArray
|
|
]);
|