Update: 2026-06-21 18:58:05

This commit is contained in:
Hamza-Ayed
2026-06-21 18:58:13 +03:00
parent b492b5076b
commit e73be65a72
8755 changed files with 92977 additions and 99 deletions

View File

@@ -0,0 +1,55 @@
<?php
require_once __DIR__ . '/../../connect.php';
if ($role !== 'admin' && $role !== 'super_admin') {
http_response_code(403);
echo json_encode(['status' => 'failure', 'message' => 'Unauthorized access. Admin role required.']);
exit;
}
try {
$countryCode = filterRequest('country_code');
$countSql = "SELECT COUNT(*) FROM marketing_campaigns_log";
$params = [];
if ($countryCode) {
$countSql .= " WHERE country_code = :country";
$params[':country'] = strtoupper($countryCode);
}
$stmt = $con->prepare($countSql);
foreach ($params as $key => $val) {
$stmt->bindValue($key, $val);
}
$stmt->execute();
$campaignCount = (int)$stmt->fetchColumn();
$estTokensPerCampaign = 3250;
$estCostPerCampaign = 0.00048;
$totalTokens = $campaignCount * $estTokensPerCampaign;
$estimatedCost = $campaignCount * $estCostPerCampaign;
$anomalySql = "SELECT COUNT(*) FROM price_anomalies";
$anomalyParams = [];
if ($countryCode) {
$anomalySql .= " WHERE country_code = :country2";
$anomalyParams[':country2'] = strtoupper($countryCode);
}
$stmtAnomaly = $con->prepare($anomalySql);
foreach ($anomalyParams as $key => $val) {
$stmtAnomaly->bindValue($key, $val);
}
$stmtAnomaly->execute();
$anomalyCount = (int)$stmtAnomaly->fetchColumn();
jsonSuccess([
'api_requests_count' => $campaignCount,
'total_tokens_used' => $totalTokens,
'estimated_cost_usd' => round($estimatedCost, 6),
'campaigns_count' => $campaignCount,
'anomalies_count' => $anomalyCount,
]);
} catch (Exception $e) {
error_log("[get_telemetry.php] Error: " . $e->getMessage());
jsonError("Failed to fetch telemetry: " . $e->getMessage());
}