WebOrbiton
v1.1.0.0

StocketBase

428 lines · 24.0 KB
  1. <?php
  2. ​
  3. declare(strict_types=1);
  4. ​
  5. if (count(get_included_files()) === 1) {
  6. http_response_code(403);
  7. exit;
  8. }
  9. ​
  10. require_once __DIR__ . '/../includes/currency.php';
  11. require_once __DIR__ . '/../includes/digital-files.php';
  12. ​
  13. $db = Database::site();
  14. ​
  15. $productId = (int) ($_GET['id'] ?? 0) ?: null;
  16. $product = null;
  17. ​
  18. if ($productId !== null) {
  19. $statement = $db->prepare('SELECT * FROM products WHERE id = :id LIMIT 1');
  20. $statement->execute(['id' => $productId]);
  21. $product = $statement->fetch();
  22. ​
  23. if (!$product) {
  24. echo '<p>We couldn\'t find this product. It may have been deleted.</p>';
  25. return;
  26. }
  27. ​
  28. $isOwner = (int) $product['created_by'] === (int) $currentUser['id'];
  29. $canEditAny = Auth::hasRoleAtLeast(Auth::ROLE_STORE_OWNER);
  30. $canProofread = Auth::role() === Auth::ROLE_CATALOG_ASSISTANT;
  31. ​
  32. if (!$isOwner && !$canEditAny && !$canProofread) {
  33. echo '<p>You don\'t have access to this product.</p>';
  34. return;
  35. }
  36. ​
  37. if ($product['deleted_at'] !== null) {
  38. echo '<div class="dash-flash dash-flash-error">This product is in the trash. Restore it to make changes.</div>';
  39. if ($isOwner || $canEditAny) {
  40. echo '<form method="post">' . Csrf::field()
  41. . '<input type="hidden" name="action" value="restore_product">'
  42. . '<input type="hidden" name="product_id" value="' . (int) $product['id'] . '">'
  43. . '<button type="submit" class="dash-btn dash-btn-primary">Restore product</button></form>';
  44. }
  45. return;
  46. }
  47. }
  48. ​
  49. $categories = $db->query('SELECT id, name FROM categories ORDER BY name ASC')->fetchAll();
  50. $blocksJson = $product['content_blocks'] ?? '{"blocks":[]}';
  51. $readOnlyMeta = $product !== null && Auth::role() === Auth::ROLE_CATALOG_ASSISTANT && (int) $product['created_by'] !== (int) $currentUser['id'];
  52. ​
  53. $storeSettings = SiteFront::settings();
  54. $pricingModel = $storeSettings['pricing_model'] ?? 'per_product';
  55. $storeCategory = $storeSettings['store_category'] ?? 'general';
  56. $paymentProvider = $storeSettings['payment_provider'] ?? 'stripe';
  57. $currencyCode = Currency::normalize((string) ($product['currency'] ?? $storeSettings['store_currency'] ?? 'USD'));
  58. [$priceMajor, $priceMinor] = Currency::split((int) ($product['price_cents'] ?? 0), $currencyCode);
  59. [$comparePriceMajor, $comparePriceMinor] = $product && $product['compare_at_price_cents'] !== null
  60. ? Currency::split((int) $product['compare_at_price_cents'], $currencyCode)
  61. : [null, 0];
  62. ​
  63. $variants = $product ? $db->prepare('SELECT * FROM product_variants WHERE product_id = :id ORDER BY sort_order ASC') : null;
  64. if ($variants) {
  65. $variants->execute(['id' => (int) $product['id']]);
  66. $variants = $variants->fetchAll();
  67. } else {
  68. $variants = [];
  69. }
  70. ​
  71. ?>
  72. <div class="dash-header-row">
  73. <h1 class="dash-title"><?= Icons::icon('edit', 'icon icon-lg') ?><?= $product ? 'Edit product' : 'New product' ?></h1>
  74. <?php if ($product): ?>
  75. <?php if ($product['status'] === 'published' && !empty($product['slug'])): ?>
  76. <a href="<?= htmlspecialchars(SiteFront::productUrl($product['slug'])) ?>" class="dash-btn-small" target="_blank" rel="noopener noreferrer"><?= Icons::icon('eye', 'icon icon-sm') ?>View</a>
  77. <?php else: ?>
  78. <a href="product.php?preview=<?= (int) $product['id'] ?>" class="dash-btn-small" target="_blank" rel="noopener noreferrer"><?= Icons::icon('eye', 'icon icon-sm') ?>Preview</a>
  79. <?php endif; ?>
  80. <?php endif; ?>
  81. </div>
  82. ​
  83. <form method="post" id="product-form" class="article-form">
  84. <?= Csrf::field() ?>
  85. <input type="hidden" name="action" value="save_product">
  86. <?php if ($product): ?>
  87. <input type="hidden" name="product_id" value="<?= (int) $product['id'] ?>">
  88. <?php endif; ?>
  89. <input type="hidden" name="blocks_json" id="blocks_json_input">
  90. ​
  91. <div class="article-form-grid">
  92. <div class="article-form-main">
  93. ​
  94. <label><?= Icons::icon('heading', 'icon icon-sm') ?>Title</label>
  95. <input type="text" name="title" value="<?= htmlspecialchars($product['title'] ?? '') ?>" <?= $readOnlyMeta ? 'readonly' : '' ?> required>
  96. ​
  97. <label><?= Icons::icon('quote', 'icon icon-sm') ?>Short summary (shown on product cards)</label>
  98. <textarea name="excerpt" rows="2" <?= $readOnlyMeta ? 'readonly' : '' ?>><?= htmlspecialchars($product['excerpt'] ?? '') ?></textarea>
  99. ​
  100. <label><?= Icons::icon('grid', 'icon icon-sm') ?>Full description</label>
  101. <div id="block-editor-root" data-initial-blocks='<?= htmlspecialchars($blocksJson, ENT_QUOTES) ?>'></div>
  102. ​
  103. <?php if (!$readOnlyMeta): ?>
  104. <div class="sidebar-box">
  105. <label><?= Icons::icon('layers', 'icon icon-sm') ?>Variants (optional, like sizes or colors, one per row)</label>
  106. <table class="dash-table" id="variants-table">
  107. <thead><tr><th>Name</th><th>SKU</th><th>Different price</th><th>Stock</th><th></th></tr></thead>
  108. <tbody>
  109. <?php foreach ($variants as $variant): ?>
  110. <tr>
  111. <td><input type="text" name="variant_name[]" value="<?= htmlspecialchars($variant['name']) ?>"></td>
  112. <td><input type="text" name="variant_sku[]" value="<?= htmlspecialchars((string) ($variant['sku'] ?? '')) ?>"></td>
  113. <td><input type="number" step="0.01" name="variant_price_cents[]" value="<?= $variant['price_cents'] !== null ? htmlspecialchars((string) ($variant['price_cents'] / 100)) : '' ?>"></td>
  114. <td><input type="number" name="variant_stock[]" value="<?= htmlspecialchars((string) ($variant['stock_quantity'] ?? '')) ?>"></td>
  115. <td><button type="button" class="dash-btn-small dash-btn-danger js-remove-variant-row"><?= Icons::icon('x', 'icon icon-sm') ?></button></td>
  116. </tr>
  117. <?php endforeach; ?>
  118. </tbody>
  119. </table>
  120. <button type="button" class="dash-btn-small" id="js-add-variant-row"><?= Icons::icon('plus', 'icon icon-sm') ?>Add variant</button>
  121. </div>
  122. <script>
  123. (function () {
  124. var table = document.getElementById('variants-table').querySelector('tbody');
  125. document.getElementById('js-add-variant-row').addEventListener('click', function () {
  126. var row = document.createElement('tr');
  127. row.innerHTML = '<td><input type="text" name="variant_name[]"></td>'
  128. + '<td><input type="text" name="variant_sku[]"></td>'
  129. + '<td><input type="number" step="0.01" name="variant_price_cents[]"></td>'
  130. + '<td><input type="number" name="variant_stock[]"></td>'
  131. + '<td><button type="button" class="dash-btn-small dash-btn-danger js-remove-variant-row">&times;</button></td>';
  132. table.appendChild(row);
  133. });
  134. table.addEventListener('click', function (event) {
  135. if (event.target.closest('.js-remove-variant-row')) {
  136. event.target.closest('tr').remove();
  137. }
  138. });
  139. })();
  140. </script>
  141. <?php endif; ?>
  142. ​
  143. </div>
  144. ​
  145. <div class="article-form-sidebar">
  146. ​
  147. <div class="sidebar-box">
  148. <label>Category</label>
  149. <select name="category_id" <?= $readOnlyMeta ? 'disabled' : '' ?>>
  150. <option value="">No category</option>
  151. <?php foreach ($categories as $category): ?>
  152. <option value="<?= (int) $category['id'] ?>" <?= (int) ($product['category_id'] ?? 0) === (int) $category['id'] ? 'selected' : '' ?>>
  153. <?= htmlspecialchars($category['name']) ?>
  154. </option>
  155. <?php endforeach; ?>
  156. </select>
  157. ​
  158. <label>What kind of product is it?</label>
  159. <select name="product_kind" <?= $readOnlyMeta ? 'disabled' : '' ?>>
  160. <option value="physical" <?= ($product['product_kind'] ?? 'physical') === 'physical' ? 'selected' : '' ?>>Something I ship</option>
  161. <option value="digital" <?= ($product['product_kind'] ?? '') === 'digital' ? 'selected' : '' ?>>A file to download</option>
  162. <option value="saas_plan" <?= ($product['product_kind'] ?? '') === 'saas_plan' ? 'selected' : '' ?>>A software plan (SaaS)</option>
  163. </select>
  164. ​
  165. <label>SKU (your own product code, optional)</label>
  166. <input type="text" name="sku" value="<?= htmlspecialchars((string) ($product['sku'] ?? '')) ?>" <?= $readOnlyMeta ? 'readonly' : '' ?>>
  167. </div>
  168. ​
  169. <div class="sidebar-box">
  170. <label>Currency</label>
  171. <input type="text" name="currency" list="currency-list" value="<?= htmlspecialchars($currencyCode) ?>" maxlength="3" <?= $readOnlyMeta ? 'readonly' : '' ?>>
  172. <datalist id="currency-list">
  173. <?php foreach (Currency::all() as $code => $label): ?>
  174. <option value="<?= htmlspecialchars($code) ?>"><?= htmlspecialchars($label) ?></option>
  175. <?php endforeach; ?>
  176. </datalist>
  177. ​
  178. <?php if ($pricingModel === 'subscription'): ?>
  179. <label>Customers pay</label>
  180. <select name="billing_interval" <?= $readOnlyMeta ? 'disabled' : '' ?>>
  181. <option value="month" <?= ($product['billing_interval'] ?? $storeSettings['subscription_interval']) === 'month' ? 'selected' : '' ?>>Monthly</option>
  182. <option value="year" <?= ($product['billing_interval'] ?? '') === 'year' ? 'selected' : '' ?>>Yearly</option>
  183. <option value="one_time" <?= ($product['billing_interval'] ?? '') === 'one_time' ? 'selected' : '' ?>>Once (keep forever)</option>
  184. </select>
  185. <label>Price</label>
  186. <div style="display:flex;gap:6px;">
  187. <input type="number" name="price_major" value="<?= (int) $priceMajor ?>" min="0" style="flex:2;" <?= $readOnlyMeta ? 'readonly' : '' ?>>
  188. <input type="number" name="price_minor" value="<?= (int) $priceMinor ?>" min="0" style="flex:1;" <?= $readOnlyMeta ? 'readonly' : '' ?>>
  189. </div>
  190. <?php else: ?>
  191. <label>Price</label>
  192. <div style="display:flex;gap:6px;">
  193. <input type="number" name="price_major" value="<?= (int) $priceMajor ?>" min="0" style="flex:2;" <?= $readOnlyMeta ? 'readonly' : '' ?>>
  194. <input type="number" name="price_minor" value="<?= (int) $priceMinor ?>" min="0" style="flex:1;" <?= $readOnlyMeta ? 'readonly' : '' ?>>
  195. </div>
  196. <label>Old price (optional, shown crossed out)</label>
  197. <div style="display:flex;gap:6px;">
  198. <input type="number" name="compare_price_major" value="<?= $comparePriceMajor !== null ? (int) $comparePriceMajor : '' ?>" min="0" style="flex:2;" <?= $readOnlyMeta ? 'readonly' : '' ?>>
  199. <input type="number" name="compare_price_minor" value="<?= (int) $comparePriceMinor ?>" min="0" style="flex:1;" <?= $readOnlyMeta ? 'readonly' : '' ?>>
  200. </div>
  201. <label><input type="checkbox" name="track_inventory" <?= (int) ($product['track_inventory'] ?? 0) === 1 ? 'checked' : '' ?> <?= $readOnlyMeta ? 'disabled' : '' ?>> Keep track of stock</label>
  202. <label>How many in stock</label>
  203. <input type="number" name="stock_quantity" value="<?= htmlspecialchars((string) ($product['stock_quantity'] ?? '0')) ?>" <?= $readOnlyMeta ? 'readonly' : '' ?>>
  204. <label>Weight in grams (optional, for shipping)</label>
  205. <input type="number" name="weight_grams" value="<?= htmlspecialchars((string) ($product['weight_grams'] ?? '')) ?>" <?= $readOnlyMeta ? 'readonly' : '' ?>>
  206. <?php endif; ?>
  207. </div>
  208. ​
  209. <?php if ($product && !$readOnlyMeta && Auth::role() !== Auth::ROLE_CATALOG_ASSISTANT): ?>
  210. <?php
  211. $productFiles = DigitalFiles::filesForProduct((int) $product['id']);
  212. $downloadLoginRequired = ($storeSettings['require_account_to_purchase'] ?? '0') === '1';
  213. ?>
  214. <div class="sidebar-box" id="product-files">
  215. <label><?= Icons::icon('download', 'icon icon-sm') ?>Files to download</label>
  216. <p class="product-files-hint">Customers get these files once they pay. If the price is 0, anyone can grab them for free<?= $downloadLoginRequired ? ' after logging in' : ', no account needed' ?>.</p>
  217. <?php if (!empty($productFiles) && DigitalFiles::isFree($product, $variants)): ?>
  218. <div class="dash-flash dash-flash-error" style="margin:0 0 10px;"><?= Icons::icon('info', 'icon icon-sm') ?>The price is 0, so<?= $downloadLoginRequired ? ' any logged-in customer' : ' anyone' ?> can download these files for free. Set a price if you want to sell them.</div>
  219. <?php endif; ?>
  220. <?php if (!empty($productFiles)): ?>
  221. <ul class="product-files-list">
  222. <?php foreach ($productFiles as $productFile): ?>
  223. <li class="product-files-item">
  224. <div class="product-files-row">
  225. <span class="product-files-name"><?= htmlspecialchars($productFile['original_name']) ?><small><?= htmlspecialchars(DigitalFiles::formatSize((int) $productFile['size_bytes'])) ?></small></span>
  226. <button type="submit" form="product-file-delete-form" name="file_id" value="<?= (int) $productFile['id'] ?>" class="dash-btn-small dash-btn-danger" onclick="return confirm('Delete this file? Customers won\'t be able to download it anymore.');"><?= Icons::icon('trash', 'icon icon-sm') ?></button>
  227. </div>
  228. <input type="text" name="button_label[<?= (int) $productFile['id'] ?>]" form="product-file-label-form" value="<?= htmlspecialchars((string) ($productFile['button_label'] ?? '')) ?>" maxlength="120" placeholder="Button text (optional), like Download theme" aria-label="Button text for <?= htmlspecialchars($productFile['original_name']) ?>">
  229. </li>
  230. <?php endforeach; ?>
  231. </ul>
  232. <button type="submit" form="product-file-label-form" class="dash-btn-small"><?= Icons::icon('check', 'icon icon-sm') ?>Save button text</button>
  233. <p class="product-files-hint">With no button text, we show "Download" and the file name.</p>
  234. <?php endif; ?>
  235. <input type="file" name="product_file" form="product-file-upload-form" required>
  236. <button type="submit" form="product-file-upload-form" class="dash-btn-small"><?= Icons::icon('upload', 'icon icon-sm') ?>Upload file</button>
  237. <p class="product-files-hint">Max <?= htmlspecialchars((string) ini_get('upload_max_filesize')) ?> per file. Files are kept private and can only be downloaded through a secure link.</p>
  238. </div>
  239. <?php endif; ?>
  240. ​
  241. <?php if ($product && !$readOnlyMeta && Auth::hasRoleAtLeast(Auth::ROLE_STORE_MANAGER)): ?>
  242. <?php
  243. require_once __DIR__ . '/../includes/licenses.php';
  244. $licenseMode = Licenses::mode($product);
  245. $licenseCounts = Licenses::counts((int) $product['id']);
  246. $licenseRows = $licenseMode === 'pool' || $licenseCounts['assigned'] > 0 ? Licenses::recentForProduct((int) $product['id'], 30) : [];
  247. $licenseFlash = $_SESSION['license_flash'] ?? null;
  248. unset($_SESSION['license_flash']);
  249. ?>
  250. <div class="sidebar-box" id="product-licenses">
  251. <label><?= Icons::icon('lock', 'icon icon-sm') ?>License keys</label>
  252. <?php if ($licenseFlash !== null): ?>
  253. <div class="dash-flash dash-flash-success" style="margin:0 0 10px;"><?= Icons::icon('check', 'icon icon-sm') ?><?= htmlspecialchars((string) $licenseFlash) ?></div>
  254. <?php endif; ?>
  255. <p class="product-files-hint">Give every buyer a key, shown on the order page, in the email and in their account.</p>
  256. <select name="license_mode" form="product-license-form" id="license-mode-select">
  257. <option value="none" <?= $licenseMode === 'none' ? 'selected' : '' ?>>No keys</option>
  258. <option value="generate" <?= $licenseMode === 'generate' ? 'selected' : '' ?>>New key for each purchase</option>
  259. <option value="pool" <?= $licenseMode === 'pool' ? 'selected' : '' ?>>Keys from my own list</option>
  260. </select>
  261. <div data-license-section="generate" <?= $licenseMode === 'generate' ? '' : 'hidden' ?>>
  262. <label>Key pattern (X = letter or digit, # = digit)</label>
  263. <input type="text" name="license_pattern" form="product-license-form" maxlength="80" value="<?= htmlspecialchars((string) ($product['license_pattern'] ?? '')) ?>" placeholder="<?= htmlspecialchars(Licenses::DEFAULT_PATTERN) ?>">
  264. <p class="product-files-hint">Example key: <code><?= htmlspecialchars(Licenses::generate((string) ($product['license_pattern'] ?? ''))) ?></code></p>
  265. </div>
  266. <div data-license-section="pool" <?= $licenseMode === 'pool' ? '' : 'hidden' ?>>
  267. <p class="product-files-hint"><strong><?= (int) $licenseCounts['available'] ?></strong> keys left · <?= (int) $licenseCounts['assigned'] ?> sent<?= $licenseCounts['available'] === 0 ? ' · <span style="color:var(--danger);">add keys before you sell</span>' : '' ?></p>
  268. <label>Add keys (one per line)</label>
  269. <textarea name="license_keys" form="product-license-form" rows="4" placeholder="AAAA-BBBB-CCCC&#10;DDDD-EEEE-FFFF" spellcheck="false" style="font-family:monospace;font-size:12.5px;"></textarea>
  270. </div>
  271. <button type="submit" form="product-license-form" class="dash-btn-small"><?= Icons::icon('check', 'icon icon-sm') ?>Save keys</button>
  272. <?php if (!empty($licenseRows)): ?>
  273. <details style="margin-top:10px;">
  274. <summary style="cursor:pointer;font-size:12.5px;">Show keys</summary>
  275. <ul class="product-license-rows">
  276. <?php foreach ($licenseRows as $licenseRow): ?>
  277. <li>
  278. <code><?= htmlspecialchars((string) $licenseRow['license_key']) ?></code>
  279. <?php if ($licenseRow['order_id'] !== null): ?>
  280. <a href="dashboard.php?view=order-detail&amp;id=<?= (int) $licenseRow['order_id'] ?>"><?= htmlspecialchars((string) ($licenseRow['order_number'] ?? ('#' . (int) $licenseRow['order_id']))) ?></a><?= $licenseRow['revoked_at'] !== null ? ' <small>(turned off)</small>' : '' ?>
  281. <?php else: ?>
  282. <button type="submit" form="product-license-delete-form" name="key_id" value="<?= (int) $licenseRow['id'] ?>" class="dash-btn-small dash-btn-danger" title="Remove this key"><?= Icons::icon('trash', 'icon icon-sm') ?></button>
  283. <?php endif; ?>
  284. </li>
  285. <?php endforeach; ?>
  286. </ul>
  287. </details>
  288. <?php endif; ?>
  289. <script>
  290. (function () {
  291. var select = document.getElementById('license-mode-select');
  292. if (!select) { return; }
  293. function apply() {
  294. document.querySelectorAll('[data-license-section]').forEach(function (section) {
  295. section.hidden = section.getAttribute('data-license-section') !== select.value;
  296. });
  297. }
  298. select.addEventListener('change', apply);
  299. })();
  300. </script>
  301. </div>
  302. <?php endif; ?>
  303. ​
  304. <div class="sidebar-box">
  305. <label>Stripe price ID (optional, leave empty to charge the price above)</label>
  306. <input type="text" name="stripe_price_id" value="<?= htmlspecialchars((string) ($product['stripe_price_id'] ?? '')) ?>" placeholder="price_..." <?= $readOnlyMeta ? 'readonly' : '' ?>>
  307. <?php if ($storeCategory === 'saas' && $paymentProvider === 'polar'): ?>
  308. <label>Polar.sh product ID</label>
  309. <input type="text" name="polar_product_id" value="<?= htmlspecialchars((string) ($product['polar_product_id'] ?? '')) ?>" <?= $readOnlyMeta ? 'readonly' : '' ?>>
  310. <p style="font-size:12px;color:var(--muted);margin:6px 0 0;">Create the plan in Polar.sh first, then paste its product ID here.</p>
  311. <?php endif; ?>
  312. </div>
  313. ​
  314. <?php if (ProductTags::isEnabled()): ?>
  315. <div class="sidebar-box">
  316. <label>Tags (separate with commas, up to <?= ProductTags::MAX_TAGS ?>)</label>
  317. <input type="text" name="tags" maxlength="700" value="<?= htmlspecialchars($product ? ProductTags::csvFor((int) $product['id']) : '') ?>" placeholder="new-arrival, bestseller" <?= $readOnlyMeta ? 'readonly' : '' ?>>
  318. </div>
  319. <?php endif; ?>
  320. ​
  321. <?php if ($product && !$readOnlyMeta && Languages::enabled() && !empty(Languages::all())): ?>
  322. <?php $translatedProductLanguages = []; foreach (Languages::all() as $translationLanguage) { $found = Languages::translation('product', (int) $product['id'], $translationLanguage['code']); $translatedProductLanguages[$translationLanguage['code']] = $found !== null && trim((string) $found['title']) !== ''; } ?>
  323. <div class="sidebar-box">
  324. <label>Translations</label>
  325. <ul style="list-style:none;padding:0;margin:0;display:grid;gap:8px;font-size:13px;">
  326. <?php foreach (Languages::all() as $translationLanguage): ?>
  327. <li style="display:flex;justify-content:space-between;align-items:center;gap:8px;">
  328. <span><?= htmlspecialchars($translationLanguage['name']) ?> <span style="color:var(--muted);"><?= $translatedProductLanguages[$translationLanguage['code']] ? 'translated' : 'not translated' ?></span></span>
  329. <a href="translate.php?type=product&id=<?= (int) $product['id'] ?>&lang=<?= urlencode($translationLanguage['code']) ?>" class="dash-btn-small"><?= Icons::icon('translate', 'icon icon-sm') ?><?= $translatedProductLanguages[$translationLanguage['code']] ? 'Edit' : 'Translate' ?></a>
  330. </li>
  331. <?php endforeach; ?>
  332. </ul>
  333. </div>
  334. <?php endif; ?>
  335. ​
  336. <div class="sidebar-box">
  337. <label>Main photo</label>
  338. <input type="text" name="cover_image_path" data-image-upload value="<?= htmlspecialchars($product['cover_image_path'] ?? '') ?>" <?= $readOnlyMeta ? 'readonly' : '' ?>>
  339. ​
  340. <label>Title in Google (optional)</label>
  341. <input type="text" name="seo_title" value="<?= htmlspecialchars($product['seo_title'] ?? '') ?>" <?= $readOnlyMeta ? 'readonly' : '' ?>>
  342. ​
  343. <label>Description in Google (optional)</label>
  344. <textarea name="seo_description" rows="2" <?= $readOnlyMeta ? 'readonly' : '' ?>><?= htmlspecialchars($product['seo_description'] ?? '') ?></textarea>
  345. </div>
  346. ​
  347. <?php if (!$readOnlyMeta): ?>
  348. <div class="sidebar-box">
  349. <label>Publish on</label>
  350. <input type="datetime-local" name="scheduled_at" value="<?= htmlspecialchars(!empty($product['scheduled_at']) ? date('Y-m-d\TH:i', strtotime((string) $product['scheduled_at'])) : '') ?>">
  351. ​
  352. <div class="publish-actions">
  353. <button type="submit" name="publish_action" value="save_draft" class="dash-btn"><?= Icons::icon('pages', 'icon icon-sm') ?>Save draft</button>
  354. <?php if (!Auth::canPublishDirectly()): ?>
  355. <button type="submit" name="publish_action" value="submit_for_review" class="dash-btn dash-btn-primary"><?= Icons::icon('check', 'icon icon-sm') ?>Send for approval</button>
  356. <?php else: ?>
  357. <button type="submit" name="publish_action" value="publish_now" class="dash-btn dash-btn-primary"><?= Icons::icon('check', 'icon icon-sm') ?>Publish now</button>
  358. <button type="submit" name="publish_action" value="schedule" class="dash-btn"><?= Icons::icon('stats', 'icon icon-sm') ?>Schedule</button>
  359. <?php endif; ?>
  360. </div>
  361. </div>
  362. <?php else: ?>
  363. <button type="submit" class="dash-btn dash-btn-primary"><?= Icons::icon('check', 'icon icon-sm') ?>Save corrections</button>
  364. <?php endif; ?>
  365. ​
  366. <?php $productVersions = ($product && !$readOnlyMeta) ? ProductVersions::recent((int) $product['id']) : []; ?>
  367. <?php if (!empty($productVersions)): ?>
  368. <div class="sidebar-box">
  369. <label>Earlier versions</label>
  370. <ul style="list-style:none;padding:0;margin:0;display:grid;gap:10px;font-size:13px;">
  371. <?php foreach ($productVersions as $version): ?>
  372. <li style="display:flex;justify-content:space-between;align-items:center;gap:8px;">
  373. <span><?= htmlspecialchars($version['created_at']) ?><br><span style="color:var(--muted);"><?= htmlspecialchars((string) $version['saved_by_name']) ?> &middot; <?= htmlspecialchars($version['note']) ?></span></span>
  374. <button type="submit" form="version-restore-form" name="version_id" value="<?= (int) $version['id'] ?>" class="dash-btn-small" onclick="return confirm('Go back to this version? Don\'t worry, we\'ll keep the current one too.');"><?= Icons::icon('refresh', 'icon icon-sm') ?>Restore</button>
  375. </li>
  376. <?php endforeach; ?>
  377. </ul>
  378. </div>
  379. <?php endif; ?>
  380. ​
  381. <?php if ($product && $product['status'] === 'rejected' && !empty($product['rejection_reason'])): ?>
  382. <div class="dash-flash dash-flash-error">Sent back with a note: <?= htmlspecialchars($product['rejection_reason']) ?></div>
  383. <?php endif; ?>
  384. ​
  385. </div>
  386. </div>
  387. </form>
  388. ​
  389. <?php if ($product && !$readOnlyMeta && Auth::role() !== Auth::ROLE_CATALOG_ASSISTANT): ?>
  390. <form method="post" action="dashboard.php?view=product-edit&amp;id=<?= (int) $product['id'] ?>" enctype="multipart/form-data" id="product-file-upload-form">
  391. <?= Csrf::field() ?>
  392. <input type="hidden" name="action" value="upload_product_file">
  393. <input type="hidden" name="product_id" value="<?= (int) $product['id'] ?>">
  394. </form>
  395. <form method="post" action="dashboard.php?view=product-edit&amp;id=<?= (int) $product['id'] ?>" id="product-file-label-form">
  396. <?= Csrf::field() ?>
  397. <input type="hidden" name="action" value="save_product_file_labels">
  398. <input type="hidden" name="product_id" value="<?= (int) $product['id'] ?>">
  399. </form>
  400. <form method="post" action="dashboard.php?view=product-edit&amp;id=<?= (int) $product['id'] ?>" id="product-file-delete-form">
  401. <?= Csrf::field() ?>
  402. <input type="hidden" name="action" value="delete_product_file">
  403. <input type="hidden" name="product_id" value="<?= (int) $product['id'] ?>">
  404. </form>
  405. <?php endif; ?>
  406. ​
  407. <?php if ($product && !$readOnlyMeta && Auth::hasRoleAtLeast(Auth::ROLE_STORE_MANAGER)): ?>
  408. <form method="post" action="dashboard.php?view=product-edit&amp;id=<?= (int) $product['id'] ?>" id="product-license-form">
  409. <?= Csrf::field() ?>
  410. <input type="hidden" name="action" value="product_licenses">
  411. <input type="hidden" name="product_id" value="<?= (int) $product['id'] ?>">
  412. </form>
  413. <form method="post" action="dashboard.php?view=product-edit&amp;id=<?= (int) $product['id'] ?>" id="product-license-delete-form" onsubmit="return confirm('Remove this key from the list?');">
  414. <?= Csrf::field() ?>
  415. <input type="hidden" name="action" value="product_licenses">
  416. <input type="hidden" name="license_tool" value="delete_key">
  417. <input type="hidden" name="product_id" value="<?= (int) $product['id'] ?>">
  418. </form>
  419. <?php endif; ?>
  420. ​
  421. <?php if (!empty($productVersions)): ?>
  422. <form method="post" id="version-restore-form">
  423. <?= Csrf::field() ?>
  424. <input type="hidden" name="action" value="restore_version">
  425. <input type="hidden" name="product_id" value="<?= (int) $product['id'] ?>">
  426. </form>
  427. <?php endif; ?>
  428. ​