sandbox-reports/webhook_caller.php
DJP facacc94d4 Update AI Tools Usage Report System - Multi-Tool Support
Enhanced the VEO3 usage report system to support all AI tool types:
- Added support for 6 tool types: VEO3, TEXT2IMAGE, TEXT2VOICE, SPEECH2SPEECH, DOCUMENT_TRANSLATION, VIDEOQUERY
- Updated Python report generator (veo3_report.py) with dynamic tool detection
- Updated PHP report page (report.php) with tool usage breakdown section
- Changed all "Prompts" references to "Requests" for clarity
- Updated refresh button to fetch only last 12 weeks (84 days) for better performance
- Made system dynamic to handle unknown tool types automatically
- Renamed report titles from "VEO3 Usage Report" to "AI Tools Usage Report"

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
2026-01-08 14:50:04 -05:00

205 lines
6 KiB
PHP

<?php
// SSO Authentication
require_once __DIR__ . '/AuthMiddleware.php';
$auth = new AuthMiddleware();
$user = $auth->requireAuth(); // This will redirect to login if not authenticated
// Configuration
$webhookUrl = 'https://hook.us1.make.celonis.com/v7ev5x3j50oy1n1iqd6u6462cg0cz4yy';
$responseFile = 'webhook_response.json';
// Initialize variables
$response = null;
$error = null;
$isAjax = isset($_POST['ajax']) && $_POST['ajax'] == '1';
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['start_date']) && isset($_POST['end_date'])) {
$startDate = $_POST['start_date'];
$endDate = $_POST['end_date'];
// Prepare the data to send
$postData = [
'start_date' => $startDate,
'end_date' => $endDate
];
// Initialize cURL
$ch = curl_init($webhookUrl);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Accept: application/json'
]);
// Execute request
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Check for errors
if (curl_errno($ch)) {
$error = 'cURL Error: ' . curl_error($ch);
} elseif ($httpCode !== 200) {
$error = "HTTP Error: Received status code $httpCode";
} else {
// Save response to file
file_put_contents($responseFile, $response);
$error = null;
}
curl_close($ch);
// If AJAX request, return JSON
if ($isAjax) {
header('Content-Type: application/json');
if ($error) {
echo json_encode(['success' => false, 'error' => $error]);
} else {
echo json_encode(['success' => true, 'message' => 'Data refreshed successfully']);
}
exit;
}
}
// Set default dates (last 30 days)
$defaultEndDate = date('Y-m-d');
$defaultStartDate = date('Y-m-d', strtotime('-30 days'));
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Webhook Caller</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 1200px;
margin: 20px auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
margin-bottom: 20px;
}
h1 {
color: #333;
margin-top: 0;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #555;
}
input[type="date"] {
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 14px;
width: 200px;
}
button {
background-color: #007bff;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
}
button:hover {
background-color: #0056b3;
}
.response {
background: #f8f9fa;
border: 1px solid #ddd;
border-radius: 4px;
padding: 15px;
overflow-x: auto;
}
.error {
background: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
border-radius: 4px;
padding: 15px;
margin-bottom: 20px;
}
.success {
background: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
border-radius: 4px;
padding: 15px;
margin-bottom: 20px;
}
pre {
margin: 0;
white-space: pre-wrap;
word-wrap: break-word;
}
</style>
</head>
<body>
<div class="container">
<h1>Webhook Caller</h1>
<form method="POST">
<div class="form-group">
<label for="start_date">Start Date:</label>
<input type="date" id="start_date" name="start_date"
value="<?php echo htmlspecialchars($_POST['start_date'] ?? $defaultStartDate); ?>" required>
</div>
<div class="form-group">
<label for="end_date">End Date:</label>
<input type="date" id="end_date" name="end_date"
value="<?php echo htmlspecialchars($_POST['end_date'] ?? $defaultEndDate); ?>" required>
</div>
<button type="submit">Call Webhook</button>
</form>
</div>
<?php if ($error): ?>
<div class="container">
<div class="error">
<strong>Error:</strong> <?php echo htmlspecialchars($error); ?>
</div>
</div>
<?php endif; ?>
<?php if ($response && !$error): ?>
<div class="container">
<div class="success">
<strong>Success!</strong> Response received and saved to <code><?php echo htmlspecialchars($responseFile); ?></code>
</div>
<h2>Response:</h2>
<div class="response">
<pre><?php echo htmlspecialchars($response); ?></pre>
</div>
<h3>Formatted JSON:</h3>
<div class="response">
<pre><?php
$jsonData = json_decode($response, true);
if ($jsonData !== null) {
echo htmlspecialchars(json_encode($jsonData, JSON_PRETTY_PRINT));
} else {
echo "Unable to parse as JSON";
}
?></pre>
</div>
</div>
<?php endif; ?>
</body>
</html>