Initial commit

This commit is contained in:
Porawit Dongwang
2026-09-16 23:20:08 +07:00
commit 0041668dbb
32577 changed files with 3687927 additions and 0 deletions
@@ -0,0 +1,50 @@
<?php
// api/get_logs.php - Fetch Activity Logs for Super Admin
header("Content-Type: application/json; charset=UTF-8");
require_once '../config/db.php';
try {
$agencyId = $_GET['agency_id'] ?? '';
if ($agencyId !== 'SUPER_ADMIN') {
echo json_encode(['status' => 'error', 'message' => 'Unauthorized']);
exit;
}
$startDate = $_GET['start_date'] ?? '';
$endDate = $_GET['end_date'] ?? '';
$search = $_GET['search'] ?? '';
$db = getDbConnection();
$pdo = $db['pdo'];
$query = "SELECT * FROM activity_logs WHERE 1=1";
$params = [];
if ($startDate) {
$query .= " AND created_at >= ?";
$params[] = $startDate . ' 00:00:00';
}
if ($endDate) {
$query .= " AND created_at <= ?";
$params[] = $endDate . ' 23:59:59';
}
if ($search) {
$query .= " AND (user_name LIKE ? OR action LIKE ? OR details LIKE ?)";
$searchParam = "%$search%";
$params[] = $searchParam;
$params[] = $searchParam;
$params[] = $searchParam;
}
$query .= " ORDER BY created_at DESC LIMIT 500"; // Limit to prevent massive payload
$stmt = $pdo->prepare($query);
$stmt->execute($params);
$logs = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode(['status' => 'success', 'data' => $logs]);
} catch (\Exception $e) {
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
}