<?php  if (!defined('DASHBOARD_ROOT')) { http_response_code(403); exit; } function renderTrackingLinker(int $orderId): string { $order = Database::fetchOne("SELECT id, order_ref, tracking_ref, canada_post_tracking, fulfillment_stage FROM orders WHERE id=:id", [":id"=>$orderId]); if (!$order) return ""; $tracking = $order["tracking_ref"] ?: $order["canada_post_tracking"] ?: null; $hasTracking = !empty($tracking); $stageLabel = UI::e($order["fulfillment_stage"] ?? 'order_submitted'); return "<div class=\"tracking-linker\"><h3>Tracking</h3>" . ($hasTracking ? "<p>Ref: " . UI::e($tracking) . " — " . $stageLabel . "</p>" : "<input type=\"text\" id=\"tracking-input\" placeholder=\"Enter tracking number\"><button class=\"btn\" data-action=\"linkTracking\" data-id=\"{$orderId}\">Link</button>") . "</div>"; } 