64 lines
2.2 KiB
PHP
64 lines
2.2 KiB
PHP
<?php
|
|
/**
|
|
* WEVAL Support Tickets sovereign 21avr2026
|
|
* Local JSONL + status tracking (open/resolved/closed)
|
|
* Storage: /opt/weval-l99/data/tickets.jsonl
|
|
*/
|
|
header('Content-Type: application/json');
|
|
|
|
$STORAGE = '/opt/weval-l99/data/tickets.jsonl';
|
|
@mkdir(dirname($STORAGE), 0755, true);
|
|
|
|
$action = $_GET['action'] ?? ($_POST['action'] ?? 'stats');
|
|
|
|
if ($action === 'create' && $_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$subject = substr(trim($_POST['subject'] ?? ''), 0, 200);
|
|
$body = substr(trim($_POST['body'] ?? ''), 0, 2000);
|
|
$user = substr(trim($_POST['user'] ?? 'anonymous'), 0, 60);
|
|
$priority = in_array($_POST['priority'] ?? '', ['low','medium','high','critical']) ? $_POST['priority'] : 'medium';
|
|
if (!$subject) {
|
|
echo json_encode(['ok'=>false,'error'=>'subject_required']);
|
|
exit;
|
|
}
|
|
$id = 'TKT-' . date('Ymd') . '-' . substr(md5($subject.microtime()), 0, 6);
|
|
$record = ['ts'=>date('c'),'id'=>$id,'status'=>'open','subject'=>$subject,'body'=>$body,'user'=>$user,'priority'=>$priority,'resolved_at'=>null];
|
|
@file_put_contents($STORAGE, json_encode($record)."\n", FILE_APPEND | LOCK_EX);
|
|
echo json_encode(['ok'=>true,'ticket_id'=>$id]);
|
|
exit;
|
|
}
|
|
|
|
$tickets = [];
|
|
if (is_readable($STORAGE)) {
|
|
foreach (file($STORAGE) as $line) {
|
|
$r = @json_decode(trim($line), true);
|
|
if ($r) $tickets[] = $r;
|
|
}
|
|
}
|
|
|
|
// Stats
|
|
$total = count($tickets);
|
|
$open = 0; $resolved = 0; $mttr_hours = 0; $mttr_count = 0;
|
|
foreach ($tickets as $t) {
|
|
if ($t['status'] === 'open') $open++;
|
|
elseif ($t['status'] === 'resolved' || $t['status'] === 'closed') {
|
|
$resolved++;
|
|
if (!empty($t['resolved_at'])) {
|
|
$delta = (strtotime($t['resolved_at']) - strtotime($t['ts'])) / 3600;
|
|
if ($delta > 0) { $mttr_hours += $delta; $mttr_count++; }
|
|
}
|
|
}
|
|
}
|
|
$mttr = $mttr_count > 0 ? round($mttr_hours / $mttr_count, 1) : 0;
|
|
|
|
echo json_encode([
|
|
'ok'=>true,
|
|
'source'=>'sovereign_jsonl',
|
|
'ts'=>date('c'),
|
|
'tickets_total'=>$total,
|
|
'tickets_open'=>$open,
|
|
'tickets_resolved'=>$resolved,
|
|
'mttr_hours'=>$mttr,
|
|
'status'=>$open === 0 && $total === 0 ? 'wire_needed' : ($open <= 5 ? 'ok' : 'warn'),
|
|
'endpoint_create'=>'/api/tickets-api.php?action=create',
|
|
]);
|