18-vm/index.php
Flatlogic Bot 00a5c5a638 Version 1
2026-01-19 00:06:34 +00:00

235 lines
12 KiB
PHP

<?php
require_once 'db/config.php';
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$task = $_POST['task'] ?? '';
$project = $_POST['project'] ?? '';
$output_type = $_POST['output_type'] ?? '';
$duration = $_POST['duration'] ?? '';
if ($task && $project && $output_type && $duration) {
try {
$pdo = db();
$stmt = $pdo->prepare("INSERT INTO activity_log (task, project, output_type, duration) VALUES (?, ?, ?, ?)");
$stmt->execute([$task, $project, $output_type, $duration]);
header("Location: " . $_SERVER['PHP_SELF']);
exit;
} catch (PDOException $e) {
error_log("DB Error: " . $e->getMessage());
}
}
}
try {
$pdo = db();
// Seed data if the table is empty
$stmt = $pdo->query("SELECT COUNT(*) FROM activity_log");
if ($stmt->fetchColumn() == 0) {
$seed_data = [
['task' => 'Analyzed quarterly sales report for new market trends.', 'output_type' => 'AI', 'duration' => '00:02:35', 'project' => 'Q1 Sales Analysis'],
['task' => 'Verified data extraction accuracy from scanned invoices.', 'output_type' => 'Human', 'duration' => '00:05:10', 'project' => 'Invoice Processing'],
['task' => 'Generated Python script for automating data cleanup.', 'output_type' => 'AI', 'duration' => '00:03:50', 'project' => 'Data Migration Tool'],
];
$stmt = $pdo->prepare("INSERT INTO activity_log (task, output_type, duration, project) VALUES (?, ?, ?, ?)");
foreach ($seed_data as $row) {
$stmt->execute([$row['task'], $row['output_type'], $row['duration'], $row['project']]);
}
}
// Fetch data for the log
$log_stmt = $pdo->query("SELECT *, DATE_FORMAT(created_at, '%Y-%m-%d %H:%i:%s') as timestamp FROM activity_log ORDER BY created_at DESC");
$log_data = $log_stmt->fetchAll();
} catch (PDOException $e) {
die("DB ERROR: " . $e->getMessage());
}
// Calculate AI vs Human contribution
$total_duration_ai = 0;
$total_duration_human = 0;
foreach ($log_data as $log) {
list($h, $m, $s) = explode(':', $log['duration']);
$duration_in_seconds = $h * 3600 + $m * 60 + $s;
if ($log['output_type'] === 'AI') {
$total_duration_ai += $duration_in_seconds;
} else {
$total_duration_human += $duration_in_seconds;
}
}
$total_duration = $total_duration_ai + $total_duration_human;
$ai_percentage = $total_duration > 0 ? round(($total_duration_ai / $total_duration) * 100) : 0;
$human_percentage = $total_duration > 0 ? round(($total_duration_human / $total_duration) * 100) : 0;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'AI Agent Digital Labor'); ?></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<div class="container my-5">
<header class="mb-5 text-center">
<h1 class="display-5 fw-bold"><?php echo htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'AI Agent Digital Labor'); ?></h1>
<p class="lead text-secondary"><?php echo htmlspecialchars($_SERVER['PROJECT_DESCRIPTION'] ?? 'A real-time demonstration of an AI Agent for enterprise automation.'); ?></p>
<div id="clock" class="fs-4 text-muted"></div>
</header>
<div class="row">
<div class="col-md-5">
<div class="card" id="chat-container">
<div class="card-header">
AI Agent Chat
</div>
<div class="card-body" id="chat-box">
<div class="message bot-message">
Hello! How can I help you today?
</div>
</div>
<div class="card-footer">
<form id="chat-form">
<div class="input-group">
<input type="text" id="chat-input" class="form-control" placeholder="Type your message..." autocomplete="off">
<button class="btn btn-primary" type="submit" id="chat-submit">Send</button>
</div>
</form>
</div>
</div>
</div>
<div class="col-md-7">
<div class="card mb-4" id="manual-log-container">
<div class="card-header">
Log Human Action
</div>
<div class="card-body">
<form id="manual-log-form">
<div class="row">
<div class="col-md-6 mb-3">
<label for="action-type" class="form-label">Action Type</label>
<select id="action-type" class="form-select">
<option>Opened App</option>
<option>Browsed URL</option>
<option>Typing</option>
<option>Cursor Control</option>
</select>
</div>
<div class="col-md-6 mb-3">
<label for="manual-project" class="form-label">Project</label>
<input type="text" id="manual-project" class="form-control" placeholder="E.g., Q2 Marketing">
</div>
</div>
<div class="mb-3">
<label for="manual-task" class="form-label">Task Description</label>
<textarea id="manual-task" class="form-control" rows="2" placeholder="Describe the action taken..."></textarea>
</div>
<button class="btn btn-secondary w-100" type="submit" id="manual-log-submit">Log Action</button>
</form>
</div>
</div>
<main>
<div class="row justify-content-center mb-4">
<div class="col-lg-8">
<div class="card text-center">
<div class="card-header">
Today's Contribution
</div>
<div class="card-body">
<div class="row">
<div class="col">
<h3 class="fw-bold text-primary"><?php echo $ai_percentage; ?>%</h3>
<p class="text-secondary mb-0">AI Contribution</p>
</div>
<div class="col">
<h3 class="fw-bold text-secondary"><?php echo $human_percentage; ?>%</h3>
<p class="text-secondary mb-0">Human Contribution</p>
</div>
</div>
</div>
</div>
</div>
</div>
<ul class="nav nav-tabs" id="timesheetTabs" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="live-activity-tab" data-bs-toggle="tab" data-bs-target="#live-activity" type="button" role="tab" aria-controls="live-activity" aria-selected="true">Live Activity</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="past-timesheets-tab" data-bs-toggle="tab" data-bs-target="#past-timesheets" type="button" role="tab" aria-controls="past-timesheets" aria-selected="false">Past Daily Timesheets</button>
</li>
</ul>
<div class="tab-content" id="timesheetTabsContent">
<div class="tab-pane fade show active" id="live-activity" role="tabpanel" aria-labelledby="live-activity-tab">
<div class="card">
<div class="card-header">
Live Activity Log
</div>
<div class="table-responsive">
<table class="table table-striped table-hover mb-0">
<thead class="table-light">
<tr>
<th scope="col">Timestamp</th>
<th scope="col">Task</th>
<th scope="col">Project</th>
<th scope="col" class="text-center">Output Type</th>
<th scope="col" class="text-end">Duration</th>
</tr>
</thead>
<tbody id="activity-log-body">
<?php foreach ($log_data as $log): ?>
<tr>
<td><?php echo htmlspecialchars($log['timestamp']); ?></td>
<td><?php echo htmlspecialchars($log['task']); ?></td>
<td><?php echo htmlspecialchars($log['project']); ?></td>
<td class="text-center">
<span class="badge rounded-pill <?php echo $log['output_type'] === 'AI' ? 'badge-ai' : 'badge-human'; ?>">
<?php echo htmlspecialchars($log['output_type']); ?>
</span>
</td>
<td class="text-end"><?php echo htmlspecialchars($log['duration']); ?></td>
</tr>
<?php endforeach; ?>
<?php if (empty($log_data)): ?>
<tr id="empty-log-row">
<td colspan="5" class="text-center text-muted">No activity logged yet.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
<div class="card-footer text-muted">
Showing <span id="log-count"><?php echo count($log_data); ?></span> most recent events.
</div>
</div>
</div>
<div class="tab-pane fade" id="past-timesheets" role="tabpanel" aria-labelledby="past-timesheets-tab">
<div class="card">
<div class="card-header">
Past Daily Timesheets
</div>
<div class="card-body">
<p class="text-center text-muted">Past timesheets will be shown here.</p>
</div>
</div>
</div>
</div>
</main>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
</body>
</html>