query("SHOW TABLES LIKE 'admin_audit_log'")->rowCount() > 0; if (!$tableExists) { file_put_contents($debugFile, " → Table admin_audit_log NOT FOUND\n", FILE_APPEND); jsonSuccess([], 'Audit log table not found'); } $stmt = $con->prepare(" SELECT l.id, l.admin_id, e.name as admin_name, l.action, l.table_name, l.record_id, l.details, l.created_at FROM admin_audit_log l LEFT JOIN employee e ON l.admin_id = e.id ORDER BY l.created_at DESC LIMIT 100 "); $stmt->execute(); $logs = $stmt->fetchAll(PDO::FETCH_ASSOC); $count = count($logs); file_put_contents($debugFile, " → SUCCESS: fetched $count logs\n", FILE_APPEND); jsonSuccess($logs); } catch (Exception $e) { file_put_contents($debugFile, " → ERROR: " . $e->getMessage() . "\n", FILE_APPEND); jsonError('Audit log query failed: ' . $e->getMessage(), 500); } ?>