<?php  if (!defined('DASHBOARD_ROOT')) { http_response_code(403); exit; } function renderListingEditor(?int $listingId = null): string { $listing = $listingId ? Database::fetchOne("SELECT * FROM products WHERE id = :id", [":id" => $listingId]) : null; $categories = Database::fetchAll("SELECT id, name FROM categories WHERE status_code = 6001 ORDER BY display_order"); $html = "<div id=\"listing-form\" class=\"editor-form\"><input type=\"hidden\" id=\"listing-id\" value=\"" . ($listing["id"] ?? 0) . "\">"; $html .= UI::field("listing-title", "Title", "text", ($listing ? Encryption::render($listing["title"]) : "")); $html .= UI::field("listing-slug", "Slug", "text", $listing["slug"] ?? ""); $html .= UI::field("listing-sku", "SKU", "text", $listing["sku"] ?? "CE-auto"); $html .= "<div class=\"form-group\"><span>Category</span><select id=\"listing-category_id\" class=\"form-group input\">"; foreach ($categories as $c) { $sel = ($listing && (int)$listing["category_id"] === (int)$c["id"]) ? "selected" : ""; $html .= "<option value=\"{$c["id"]}\" {$sel}>" . UI::e(Encryption::render($c["name"])) . "</option>"; } $html .= "</select></div>"; $html .= "<div class=\"form-group\"><span>Description</span><input id=\"listing-description\" class=\"form-group input\" type=\"text\" value=\"" . UI::e($listing ? Encryption::render($listing["description"] ?? "") : "") . "\"></div>"; $html .= "<div class=\"form-group\"><span>Status</span><select id=\"listing-status_code\" class=\"form-group input\">"; $statuses = [3001 => 'Draft', 3002 => 'Active', 3003 => 'Sold Out', 3004 => 'Paused', 3005 => 'Suspended']; foreach ($statuses as $code => $label) { $sel = ($listing && (int)$listing["status_code"] === $code) ? "selected" : ""; $html .= "<option value=\"{$code}\" {$sel}>{$label}</option>"; } $html .= "</select></div>"; $html .= "<div class=\"form-group\"><span>Visibility</span><select id=\"listing-visibility_code\" class=\"form-group input\">"; $vis = [3050 => 'Public', 3051 => 'Private', 3052 => 'Unlisted']; foreach ($vis as $code => $label) { $sel = ($listing && (int)($listing["visibility_code"] ?? 0) === $code) ? "selected" : ""; $html .= "<option value=\"{$code}\" {$sel}>{$label}</option>"; } $html .= "</select></div>"; $html .= "</div>"; return $html; } 