210 lines
9.6 KiB
PHP
210 lines
9.6 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://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.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">
|
|
</head>
|
|
<body>
|
|
|
|
<div class="sidebar">
|
|
<div class="sidebar-header">
|
|
<h2 class="h5"><i class="fas fa-tachometer-alt me-2"></i><?= htmlspecialchars($project_name) ?></h2>
|
|
</div>
|
|
<ul class="nav flex-column">
|
|
<li class="nav-item"><a class="nav-link" href="index.php"><i class="fas fa-home"></i>Dashboard</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="customers.php"><i class="fas fa-users"></i>Customers</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="bookings.php"><i class="fas fa-calendar-check"></i>Bookings</a></li>
|
|
<li class="nav-item"><a class="nav-link active" href="ai-call-logs.php"><i class="fas fa-robot"></i>AI Call Logs</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="chat-logs.php"><i class="fas fa-comments"></i>Chat Logs</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="call-tracking.php"><i class="fas fa-phone-alt"></i>Call Tracking</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="reviews.php"><i class="fas fa-star"></i>Reviews</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="calendar.php"><i class="fas fa-calendar-alt"></i>Calendar</a></li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="main-content">
|
|
<header class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1><?= htmlspecialchars($page_title) ?></h1>
|
|
</header>
|
|
|
|
<?php if (isset($error)): ?>
|
|
<div class="alert alert-danger"><i class="fas fa-exclamation-triangle me-2"></i><?= htmlspecialchars($error) ?></div>
|
|
<?php else: ?>
|
|
|
|
<!-- Performance Metrics -->
|
|
<div class="row g-4 mb-4">
|
|
<div class="col-md-6">
|
|
<div class="card stat-card h-100">
|
|
<div class="card-body d-flex justify-content-between align-items-center">
|
|
<div>
|
|
<h6 class="text-muted">Total Calls</h6>
|
|
<h4 class="fw-bold mb-0"><?= htmlspecialchars($total_calls) ?></h4>
|
|
</div>
|
|
<div class="icon"><i class="fas fa-phone-volume"></i></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="card stat-card h-100">
|
|
<div class="card-body d-flex justify-content-between align-items-center">
|
|
<div>
|
|
<h6 class="text-muted">Avg. Call Duration</h6>
|
|
<h4 class="fw-bold mb-0"><?= htmlspecialchars(round($avg_call_duration)) ?>s</h4>
|
|
</div>
|
|
<div class="icon"><i class="fas fa-clock"></i></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Charts -->
|
|
<div class="row g-4 mb-4">
|
|
<div class="col-md-6">
|
|
<div class="card">
|
|
<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">
|
|
<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">
|
|
<div class="card-header"><h5 class="m-0"><i class="fas fa-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>
|
|
<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><span class="badge bg-info"><?= htmlspecialchars($log['call_intent']) ?></span></td>
|
|
<td><span class="badge bg-primary"><?= htmlspecialchars($log['call_outcome']) ?></span></td>
|
|
<td><small><?= htmlspecialchars($log['call_summary']) ?></small></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; ?>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.2/dist/chart.umd.min.js"></script>
|
|
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
Chart.defaults.color = '#aab0bb';
|
|
Chart.defaults.borderColor = 'rgba(255, 255, 255, 0.1)';
|
|
|
|
const chartBackgroundColor = ['#4dc9ff', '#ff6384', '#ffce56', '#36a2eb', '#9966ff', '#ff9f40'];
|
|
|
|
// Intent Chart
|
|
const intentCtx = document.getElementById('intentChart').getContext('2d');
|
|
new Chart(intentCtx, {
|
|
type: 'doughnut',
|
|
data: {
|
|
labels: <?= json_encode(array_keys($intent_distribution)) ?>,
|
|
datasets: [{
|
|
data: <?= json_encode(array_values($intent_distribution)) ?>,
|
|
backgroundColor: chartBackgroundColor,
|
|
borderColor: '#2d3446',
|
|
borderWidth: 3
|
|
}]
|
|
},
|
|
options: {
|
|
responsive: true,
|
|
plugins: { legend: { position: 'bottom', labels: { color: '#aab0bb' } } }
|
|
}
|
|
});
|
|
|
|
// Outcome Chart
|
|
const outcomeCtx = document.getElementById('outcomeChart').getContext('2d');
|
|
new Chart(outcomeCtx, {
|
|
type: 'pie',
|
|
data: {
|
|
labels: <?= json_encode(array_keys($outcome_distribution)) ?>,
|
|
datasets: [{
|
|
data: <?= json_encode(array_values($outcome_distribution)) ?>,
|
|
backgroundColor: chartBackgroundColor,
|
|
borderColor: '#2d3446',
|
|
borderWidth: 3
|
|
}]
|
|
},
|
|
options: {
|
|
responsive: true,
|
|
plugins: { legend: { position: 'bottom', labels: { color: '#aab0bb' } } }
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|