<?php if (!defined('DASHBOARD_ROOT')) define('DASHBOARD_ROOT', realpath(__DIR__ . '/../..')); require_once DASHBOARD_ROOT . '/api/bootstrap.php'; header('Content-Type: application/json'); if ($_SERVER['REQUEST_METHOD'] !== 'POST') { exit(json_encode(['success' => false, 'error' => 'POST required'])); } CSRF::enforce(); RBAC::enforce('create.content'); $storeId = (int)($_POST['store_id'] ?? 0); $rowType = strtoupper(trim($_POST['row_type'] ?? 'A')); if (!$storeId || !in_array($rowType, ['A', 'B', 'C'], true)) { exit(json_encode(['success' => false, 'error' => 'Invalid store_id or row_type'])); } $next = Database::fetchOne("SELECT COALESCE(MAX(row_order),0)+1 as n FROM storefront_rows WHERE store_id = :s", [':s' => $storeId]); $nextOrder = (int)($next['n'] ?? 1); $encName = Encryption::encrypt('Row ' . $rowType, 'product'); $newId = Database::insert( "INSERT INTO storefront_rows (store_id, row_type, row_order, category_name) VALUES (:s, :t, :o, :n)", [':s' => $storeId, ':t' => $rowType, ':o' => $nextOrder, ':n' => $encName] ); exit(json_encode(['success' => true, 'row_id' => $newId, 'row_type' => $rowType, 'row_order' => $nextOrder])); 