<?php  if (!defined('DASHBOARD_ROOT')) { http_response_code(403); exit; } function sendReply(int $userId, string $message): array { if (trim($message) === '') return ['ok' => false, 'error' => 'Empty message']; $encrypted = Encryption::encrypt($message, 'user'); $adminId = (int)($_SESSION['admin_id'] ?? 0); $id = Database::insert( "INSERT INTO support_messages (user_id, message, body, is_admin, admin_user_id, is_read, created_at)          VALUES (:uid, :msg, :body, 1, :aid, 1, NOW())", [':uid' => $userId, ':msg' => $encrypted, ':body' => $encrypted, ':aid' => $adminId] ); Events::record(Events::CAT_CREATE, 'support.reply_sent', 'user', $userId, ['preview' => substr($message, 0, 60), 'admin_id' => $adminId]); return ['ok' => true, 'message_id' => $id]; } function renderReplyForm(int $userId): string { $html = '<form class="reply-form" data-submit="sendReply" data-id="' . $userId . '">'; $html .= '<textarea name="message" placeholder="Type reply... (Ctrl+Enter to send)" rows="3" required class="form-group input" style="width:100%"></textarea>'; $html .= '<div class="reply-actions">'; $html .= '<label><input type="checkbox" name="is_internal"> Internal note</label>'; $html .= '<button type="submit" class="btn btn-primary"><span>Send</span></button>'; $html .= '</div>'; $html .= CSRF::field(); $html .= '</form>'; return $html; } 