@extends('layouts.app') @section('title', 'Ticket #' . $ticket->ID) @section('styles') @endsection @section('content') @php $locale = strtolower(app()->getLocale()); $renderRichHtml = function ($value) { $decoded = \App\Models\Ticket::decodeLegacyText($value); $decoded = preg_replace('#<(script|style|iframe|object|embed|form)(.*?)>(.*?)#is', '', $decoded) ?? $decoded; $decoded = preg_replace('/\son\w+="[^"]*"/i', '', $decoded) ?? $decoded; return preg_replace("/\son\w+='[^']*'/i", '', $decoded) ?? $decoded; }; $decodeText = static fn($value) => \App\Models\Ticket::decodeLegacyText($value); $displayUserName = static fn($user, $fallbackId = null, $fallback = 'Utilisateur supprimé') => $user ? \App\Models\Ticket::decodeLegacyText($user->name) : trim($fallback . ($fallbackId ? ' #' . $fallbackId : '')); $fieldLabel = function ($customField) use ($locale, $decodeText) { if (!$customField) { return 'Champ'; } $label = $customField->name ?? 'Champ'; if (in_array($locale, ['ar', 'arabic'], true) && !empty($customField->name_ar)) { $label = $customField->name_ar; } elseif (in_array($locale, ['en', 'english'], true) && !empty($customField->name_en)) { $label = $customField->name_en; } return $decodeText($label); }; @endphp
{{ strtoupper(substr($ticket->user->name ?? 'C', 0, 1)) }}

@php /* Fix: le titre peut contenir des balises HTML (
, etc.) et des entités HTML encodées (&#039; → ') On nettoie avant affichage */ $rawTitle = $ticket->getRawOriginal('title') ?? $ticket->title ?? ''; $cleanTitle = strip_tags(html_entity_decode($decodeText($rawTitle), ENT_QUOTES | ENT_HTML5, 'UTF-8')); @endphp {{ $cleanTitle }}

#{{ $ticket->ID }}
{{ $displayUserName($ticket->user, $ticket->userid, 'Client supprimé') }} • {{ $decodeText(optional($ticket->category)->name ?? 'Général') }} • {{ \Carbon\Carbon::createFromTimestamp($ticket->timestamp)->diffForHumans() }}
@php $noteCount = $ticket->histories->filter(fn($h) => str_starts_with($h->message, 'Note interne ajoutée :'))->count(); @endphp
@csrf
@csrf @method('DELETE')
@php $replies = $ticket->replies->sortBy('timestamp'); $ticketTimestamp = (int) $ticket->timestamp; $lastReply = $replies->last(); $lastReplyTime = $lastReply && $lastReply->created_at ? (int) $lastReply->created_at->timestamp : null; $staffIds = $staffUserIds ?? []; $isStaff = function ($userId) use ($staffIds) { return in_array((int) $userId, array_map('intval', $staffIds), true); }; $totalReplies = $replies->count(); $agentReplies = $replies->filter(fn($r) => $isStaff($r->userid))->count(); $clientReplies = $totalReplies - $agentReplies; $agentDeltas = []; $clientDeltas = []; $firstAgentResponse = null; $prevTimestamp = $ticketTimestamp; $prevIsStaff = false; foreach ($replies as $r) { $rTime = $r->created_at ? (int) $r->created_at->timestamp : 0; $rIsStaff = $isStaff($r->userid); $delta = max(0, $rTime - $prevTimestamp); if ($rIsStaff && !$prevIsStaff) { $agentDeltas[] = $delta; if ($firstAgentResponse === null) { $firstAgentResponse = $delta; } } elseif (!$rIsStaff && $prevIsStaff) { $clientDeltas[] = $delta; } $prevTimestamp = $rTime; $prevIsStaff = $rIsStaff; } $avgAgentTime = !empty($agentDeltas) ? array_sum($agentDeltas) / count($agentDeltas) : null; $avgClientTime = !empty($clientDeltas) ? array_sum($clientDeltas) / count($clientDeltas) : null; $formatDuration = function ($seconds) { if ($seconds === null) return '—'; $s = max(0, (int) $seconds); $d = floor($s / 86400); $s %= 86400; $h = floor($s / 3600); $s %= 3600; $m = floor($s / 60); if ($d > 0) return $d . 'j ' . $h . 'h'; if ($h > 0) return $h . 'h ' . $m . 'min'; return $m . 'min'; }; $ticketAge = max(0, time() - $ticketTimestamp); $resolutionTime = $lastReplyTime ? max(0, $lastReplyTime - $ticketTimestamp) : null; @endphp
{{ $ticket->user->name ?? 'Client' }}
@php $ticketFiles = $ticket->files->filter(fn($f) => (int) $f->replyid === 0); $hasCustomFields = $ticket->customFieldValues->isNotEmpty(); $hasFiles = $ticketFiles->isNotEmpty(); @endphp {{-- ═══ Tabs Navigation ═══ --}} {{-- ═══ Tab Content ═══ --}}
{{-- ── Informations Supplémentaires ── --}} @if ($hasCustomFields)
@foreach ($ticket->customFieldValues as $cfv) @if (trim((string) $cfv->value) !== '')
{{ $fieldLabel($cfv->customField) }} {!! $renderRichHtml($cfv->value) !!}
@endif @endforeach
@endif {{-- ── Message ── --}}
{!! $renderRichHtml($ticket->body) !!}
{{-- ── Documents ── --}} @if ($hasFiles)
@foreach ($ticketFiles as $file) @php $ext = strtolower(pathinfo($file->upload_file_name, PATHINFO_EXTENSION)); $isImage = in_array($ext, ['jpg','jpeg','png','gif','webp']); $fileName = basename($file->upload_file_name); $iconMap = [ 'pdf'=>'ri-file-pdf-line text-danger', 'doc'=>'ri-file-word-line text-primary','docx'=>'ri-file-word-line text-primary', 'xls'=>'ri-file-excel-line text-success','xlsx'=>'ri-file-excel-line text-success','csv'=>'ri-file-excel-line text-success', 'zip'=>'ri-file-zip-line text-warning','rar'=>'ri-file-zip-line text-warning','7z'=>'ri-file-zip-line text-warning', 'mp4'=>'ri-video-line text-info','mov'=>'ri-video-line text-info', ]; $icon = $iconMap[$ext] ?? 'ri-file-line text-secondary'; @endphp @if ($isImage && !empty($file->resolved_url))
{{ $fileName }}
{{ $fileName }}
@else
{{ $fileName }}
{{ strtoupper($ext) }}
@endif @endforeach
@endif
{{-- ── Badge compteur réponses ── --}} @php $replyCount = $ticket->replies->count(); @endphp
Fil de discussion {{ $replyCount }} {{ $replyCount === 1 ? 'réponse' : 'réponses' }}
@foreach ($ticket->replies->sortBy('timestamp') as $reply) @php $replyUser = $reply->user; $replyUserName = $displayUserName($replyUser, $reply->userid); $isClientReply = $replyUser ? $replyUser->isClient() : ((int) $reply->userid === (int) $ticket->userid); @endphp
{{ strtoupper(substr($replyUserName, 0, 1)) }}
{{ $replyUserName }} @if (!$isClientReply) Team Support @endif
{{ \Carbon\Carbon::createFromTimestamp($reply->timestamp)->format('d/m/Y \à H:i') }}
@if (Auth::id() == $reply->userid || Auth::user()->isManager()) @endif
{!! $renderRichHtml($reply->body) !!}
@if ($reply->attachments->count() > 0)
@foreach ($reply->attachments as $file) @if (!empty($file->resolved_url)) {{ Str::limit(basename((string) $file->upload_file_name), 15) }} @endif @endforeach
@endif
@endforeach
{{-- ═══ Zone de Réponse ═══ --}}
Nouvelle Réponse
@csrf {{-- ═══ Réponse Prédéfinie ═══ --}}
{{-- ═══ Zone de Réponse ═══ --}}
{{-- Zone Upload simple --}}
{{-- Input file STANDARD — pas de DataTransfer --}}
Glisser & déposer vos fichiers ici
ou cliquer pour parcourir
PDF · JPG · PNG · DOC · XLS · ZIP — max 10 MB/fichier
{{-- Assign to me --}}
{{ __('messages.ticket_details') }}
{{ __('messages.elapsed_time') }}
{{ $formatDuration($ticketAge) }}
{{ __('messages.activity') }}
{{ __('messages.view_all') }}
@foreach ($ticket->histories->sortByDesc('timestamp')->take(5) as $history)
{!! $renderRichHtml(fix_mojibake($history->message)) !!}
{{ \Carbon\Carbon::createFromTimestamp($history->timestamp)->diffForHumans() }}
@endforeach @if ($ticket->histories->isEmpty())
{{ __('messages.no_activity') }}
@endif
@endsection @section('scripts') @endsection