115 lines
3.0 KiB
PHP
115 lines
3.0 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
|
|
require __DIR__ . '/../config/connect.php';
|
|
require __DIR__ . "/../config/encrypt.php";
|
|
|
|
$q = isset($_GET['search']) ? trim($_GET['search']) : '';
|
|
$ids = isset($_GET['ids']) ? trim($_GET['ids']) : '';
|
|
|
|
if (strlen($q) < 3) {
|
|
echo json_encode([
|
|
'status' => true,
|
|
'data' => []
|
|
]);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
|
|
/* ===============================
|
|
PROSES IDS (2,3,4 → array)
|
|
=============================== */
|
|
$idArray = [];
|
|
if (!empty($ids)) {
|
|
$idArray = array_filter(
|
|
array_map('intval', explode(',', $ids))
|
|
);
|
|
}
|
|
|
|
/* ===============================
|
|
BUILD QUERY DINAMIS
|
|
=============================== */
|
|
$where = [];
|
|
$params = [];
|
|
|
|
// filter data server
|
|
if (!empty($idArray)) {
|
|
$placeholders = implode(',', array_fill(0, count($idArray), '?'));
|
|
$where[] = "id_data_server IN ($placeholders)";
|
|
$params = array_merge($params, $idArray);
|
|
}
|
|
|
|
// ✅ filter status pelanggan
|
|
$where[] = "status IN (?, ?)";
|
|
$params[] = 'aktif';
|
|
$params[] = 'tidak aktif';
|
|
|
|
// search nama / akun
|
|
$where[] = "(nama LIKE ? OR akun LIKE ?)";
|
|
$params[] = '%' . $q . '%';
|
|
$params[] = '%' . $q . '%';
|
|
|
|
$sql = "
|
|
SELECT
|
|
id,
|
|
nama,
|
|
akun,
|
|
jenis_layanan,
|
|
status,
|
|
status_koneksi,
|
|
alamat,
|
|
desa,
|
|
nama_paket,
|
|
ip_address,
|
|
mac_address,
|
|
serial_number,
|
|
tanggal_bayar,
|
|
nama_server,
|
|
nomor_whatsapp
|
|
FROM v_pelanggan
|
|
WHERE " . implode(' AND ', $where) . "
|
|
ORDER BY nama ASC
|
|
LIMIT 10
|
|
";
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute($params);
|
|
|
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
$data = [];
|
|
foreach ($rows as $row) {
|
|
$data[] = [
|
|
'id' => $row['id'],
|
|
'name' => $row['nama'],
|
|
'service' => $row['nama_paket'] ?? $row['jenis_layanan'],
|
|
'status' => $row['status'],
|
|
|
|
'akun' => $row['akun'],
|
|
'status_koneksi' => $row['status_koneksi'],
|
|
'alamat' => $row['alamat'],
|
|
'desa' => $row['desa'],
|
|
'ip_address' => $row['ip_address'],
|
|
'mac_address' => $row['mac_address'],
|
|
'serial_number' => $row['serial_number'],
|
|
'tanggal_bayar' => $row['tanggal_bayar'],
|
|
'nama_server' => $row['nama_server'],
|
|
'nomor_whatsapp' => $row['nomor_whatsapp'],
|
|
'button_detail' => encrypt_url('user_detail_view|' . $row['id'])
|
|
];
|
|
}
|
|
|
|
echo json_encode([
|
|
'status' => true,
|
|
'data' => $data
|
|
]);
|
|
|
|
} catch (Throwable $e) {
|
|
http_response_code(500);
|
|
echo json_encode([
|
|
'status' => false,
|
|
'message' => 'Gagal mengambil data pelanggan'
|
|
]);
|
|
}
|