263 lines
11 KiB
PHP
263 lines
11 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
try {
|
|
$pdo = db();
|
|
|
|
// Fetch all AI call logs
|
|
$stmt_call_logs = $pdo->query('SELECT * FROM ai_call_logs ORDER BY call_start_time DESC');
|
|
$call_logs = $stmt_call_logs->fetchAll();
|
|
|
|
// Calculate performance metrics
|
|
$total_calls = count($call_logs);
|
|
|
|
$total_duration_seconds = 0;
|
|
foreach ($call_logs as $log) {
|
|
$start = new DateTime($log['call_start_time']);
|
|
$end = new DateTime($log['call_end_time']);
|
|
$duration = $end->getTimestamp() - $start->getTimestamp();
|
|
$total_duration_seconds += $duration;
|
|
}
|
|
$avg_call_duration = $total_calls > 0 ? $total_duration_seconds / $total_calls : 0;
|
|
|
|
// Data for charts
|
|
$intent_distribution = [];
|
|
$outcome_distribution = [];
|
|
foreach ($call_logs as $log) {
|
|
$intent_distribution[$log['call_intent']] = ($intent_distribution[$log['call_intent']] ?? 0) + 1;
|
|
$outcome_distribution[$log['call_outcome']] = ($outcome_distribution[$log['call_outcome']] ?? 0) + 1;
|
|
}
|
|
|
|
} catch (PDOException $e) {
|
|
$error = "Database error: " . $e->getMessage();
|
|
}
|
|
|
|
$project_name = "HVAC Command Center";
|
|
$page_title = "AI Call Logs";
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<title><?= htmlspecialchars($page_title) ?> | <?= htmlspecialchars($project_name) ?></title>
|
|
|
|
<!-- Styles -->
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
|
|
<!-- Fonts -->
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@700&family=Roboto:wght@400;500&display=swap" rel="stylesheet">
|
|
|
|
<!-- Chart.js -->
|
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
|
</head>
|
|
<body>
|
|
|
|
<header class="header text-white">
|
|
<div class="container-fluid">
|
|
<h1 class="display-6 m-0"><?= htmlspecialchars($project_name) ?></h1>
|
|
</div>
|
|
</header>
|
|
|
|
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
|
<div class="container-fluid">
|
|
<a class="navbar-brand" href="index.php">Dashboard</a>
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navbarNav">
|
|
<ul class="navbar-nav">
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="customers.php">Customers</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="bookings.php">Bookings</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="ai-call-logs.php">AI Call Logs</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="container-fluid mt-4">
|
|
|
|
<?php if (isset($error)): ?>
|
|
<div class="alert alert-danger">
|
|
<i class="bi bi-exclamation-triangle-fill"></i> <?= htmlspecialchars($error) ?>
|
|
</div>
|
|
<?php else: ?>
|
|
|
|
<!-- Performance Metrics -->
|
|
<div class="row g-4">
|
|
<div class="col-md-6">
|
|
<div class="card h-100 shadow-sm">
|
|
<div class="card-body d-flex align-items-center">
|
|
<i class="bi bi-telephone-fill display-4 text-primary me-3"></i>
|
|
<div>
|
|
<h5 class="card-title">Total Calls</h5>
|
|
<p class="card-text fs-2 fw-bold"><?= htmlspecialchars($total_calls) ?></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="card h-100 shadow-sm">
|
|
<div class="card-body d-flex align-items-center">
|
|
<i class="bi bi-clock-history display-4 text-info me-3"></i>
|
|
<div>
|
|
<h5 class="card-title">Avg. Call Duration</h5>
|
|
<p class="card-text fs-2 fw-bold"><?= htmlspecialchars(round($avg_call_duration)) ?>s</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Charts -->
|
|
<div class="row g-4 mt-2">
|
|
<div class="col-md-6">
|
|
<div class="card shadow-sm">
|
|
<div class="card-header">
|
|
<h5 class="m-0">Call Intent Distribution</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<canvas id="intentChart"></canvas>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="card shadow-sm">
|
|
<div class="card-header">
|
|
<h5 class="m-0">Call Outcome Distribution</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<canvas id="outcomeChart"></canvas>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<!-- Call Logs Table -->
|
|
<div class="card shadow-sm mt-4">
|
|
<div class="card-header">
|
|
<h5 class="m-0"><i class="bi bi-list-ul me-2"></i>All AI Call Logs</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table class="table table-hover align-middle">
|
|
<thead class="table-light">
|
|
<tr>
|
|
<th>Call ID</th>
|
|
<th>Start Time</th>
|
|
<th>End Time</th>
|
|
<th>Intent</th>
|
|
<th>Outcome</th>
|
|
<th>Summary</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($call_logs as $log): ?>
|
|
<tr>
|
|
<td><?= htmlspecialchars($log['call_id']) ?></td>
|
|
<td><?= htmlspecialchars(date("M d, Y H:i:s", strtotime($log['call_start_time']))) ?></td>
|
|
<td><?= htmlspecialchars(date("M d, Y H:i:s", strtotime($log['call_end_time']))) ?></td>
|
|
<td><?= htmlspecialchars($log['call_intent']) ?></td>
|
|
<td><?= htmlspecialchars($log['call_outcome']) ?></td>
|
|
<td><?= htmlspecialchars($log['call_summary']) ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php if (empty($call_logs)): ?>
|
|
<tr>
|
|
<td colspan="6" class="text-center text-muted">No call logs found.</td>
|
|
</tr>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</main>
|
|
|
|
<footer class="container-fluid text-center text-muted py-3 mt-4">
|
|
<small>Powered by Flatlogic</small>
|
|
</footer>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
// Intent Chart
|
|
const intentCtx = document.getElementById('intentChart').getContext('2d');
|
|
new Chart(intentCtx, {
|
|
type: 'doughnut',
|
|
data: {
|
|
labels: <?= json_encode(array_keys($intent_distribution)) ?>,
|
|
datasets: [{
|
|
label: 'Call Intents',
|
|
data: <?= json_encode(array_values($intent_distribution)) ?>,
|
|
backgroundColor: [
|
|
'rgba(54, 162, 235, 0.8)',
|
|
'rgba(255, 206, 86, 0.8)',
|
|
'rgba(75, 192, 192, 0.8)',
|
|
'rgba(153, 102, 255, 0.8)',
|
|
'rgba(255, 159, 64, 0.8)'
|
|
],
|
|
borderColor: '#fff',
|
|
borderWidth: 2
|
|
}]
|
|
},
|
|
options: {
|
|
responsive: true,
|
|
plugins: {
|
|
legend: {
|
|
position: 'bottom',
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
// Outcome Chart
|
|
const outcomeCtx = document.getElementById('outcomeChart').getContext('2d');
|
|
new Chart(outcomeCtx, {
|
|
type: 'pie',
|
|
data: {
|
|
labels: <?= json_encode(array_keys($outcome_distribution)) ?>,
|
|
datasets: [{
|
|
label: 'Call Outcomes',
|
|
data: <?= json_encode(array_values($outcome_distribution)) ?>,
|
|
backgroundColor: [
|
|
'rgba(75, 192, 192, 0.8)',
|
|
'rgba(255, 99, 132, 0.8)',
|
|
'rgba(255, 205, 86, 0.8)',
|
|
'rgba(201, 203, 207, 0.8)',
|
|
'rgba(54, 162, 235, 0.8)'
|
|
],
|
|
borderColor: '#fff',
|
|
borderWidth: 2
|
|
}]
|
|
},
|
|
options: {
|
|
responsive: true,
|
|
plugins: {
|
|
legend: {
|
|
position: 'bottom',
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|