prepare("SELECT * FROM items WHERE sku IN ($placeholders)"); $stmt->execute($skus); $results = $stmt->fetchAll(); // Index by SKU foreach ($results as $row) { $items[$row['sku']] = $row; } } $customWidth = $_REQUEST['custom_width'] ?? '40'; $customHeight = $_REQUEST['custom_height'] ?? '25'; // Templates configuration $templates = [ 'custom_roll' => [ 'name' => 'Custom Size / مقاس مخصص (أدخل المقاس أدناه)', 'cols' => 1, 'rows' => 1, 'width' => $customWidth . 'mm', 'height' => $customHeight . 'mm', 'margin_top' => '0mm', 'margin_left' => '0mm', 'gap_x' => '0mm', 'gap_y' => '0mm', 'page_width' => $customWidth . 'mm', 'page_height' => $customHeight . 'mm', ], 'avery_65' => [ 'name' => 'Roll / Zebra (40 x 25 mm)', 'cols' => 1, 'rows' => 1, 'width' => '40mm', 'height' => '25mm', 'margin_top' => '0mm', 'margin_left' => '0mm', 'gap_x' => '0mm', 'gap_y' => '0mm', 'page_width' => '40mm', 'page_height' => '25mm', ], 'roll_25x40' => [ 'name' => 'Roll / Zebra (25 x 40 mm)', 'cols' => 1, 'rows' => 1, 'width' => '25mm', 'height' => '40mm', 'margin_top' => '0mm', 'margin_left' => '0mm', 'gap_x' => '0mm', 'gap_y' => '0mm', 'page_width' => '25mm', 'page_height' => '40mm', ], 'roll_38x25' => [ 'name' => 'Roll / Zebra (38 x 25 mm)', 'cols' => 1, 'rows' => 1, 'width' => '38mm', 'height' => '25mm', 'margin_top' => '0mm', 'margin_left' => '0mm', 'gap_x' => '0mm', 'gap_y' => '0mm', 'page_width' => '38mm', 'page_height' => '25mm', ], 'avery_65' => [ 'name' => 'Avery L7651 - 65 Labels (38.1 x 21.2 mm)', 'cols' => 5, 'rows' => 13, 'width' => '38.1mm', 'height' => '21.2mm', 'margin_top' => '10.5mm', 'margin_left' => '4.7mm', 'gap_x' => '2.5mm', 'gap_y' => '0mm', 'page_width' => '210mm', 'page_height' => '297mm', ], 'avery_54' => [ 'name' => 'Avery 54 Labels (32 x 25.4 mm)', 'cols' => 6, 'rows' => 9, 'width' => '32mm', 'height' => '25.4mm', 'margin_top' => '10mm', 'margin_left' => '5mm', 'gap_x' => '2mm', 'gap_y' => '0mm', 'page_width' => '210mm', 'page_height' => '297mm', ], 'avery_45' => [ 'name' => 'Avery 45 Labels (38.1 x 29.6 mm)', 'cols' => 5, 'rows' => 9, 'width' => '38.1mm', 'height' => '29.6mm', 'margin_top' => '15mm', 'margin_left' => '5mm', 'gap_x' => '2mm', 'gap_y' => '0mm', 'page_width' => '210mm', 'page_height' => '297mm', ] ]; $templateId = $_REQUEST['template'] ?? 'avery_65'; $tpl = $templates[$templateId] ?? $templates['avery_65']; $pageWidth = $tpl['page_width'] ?? '210mm'; $pageHeight = $tpl['page_height'] ?? '297mm'; $pageCssSize = (isset($tpl['page_width']) && $tpl['page_width'] !== '210mm') ? "{$tpl['page_width']} {$tpl['page_height']}" : "A4 portrait"; if ($templateId !== 'custom_roll') { $customWidth = floatval(str_replace('mm', '', $tpl['width'])); $customHeight = floatval(str_replace('mm', '', $tpl['height'])); } // Prepare labels to print $labelsToPrint = []; if (!empty($items)) { // Check if quantities are posted if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['qty'])) { foreach ($_POST['qty'] as $sku => $qty) { if (isset($items[$sku])) { for ($i = 0; $i < (int)$qty; $i++) { $labelsToPrint[] = $items[$sku]; } } } } else { // Default 1 per item foreach ($skus as $sku) { if (isset($items[$sku])) { $labelsToPrint[] = $items[$sku]; } } } } $isSinglePrint = isset($_GET['sku']) && count($skus) === 1; $companyName = current_lang() === 'ar' ? get_setting('company_name_ar', 'حلوى الريامي') : get_setting('company_name_en', 'Al Riyami Sweets'); ?> <?= h(tr('طباعة ملصقات', 'Print Labels')) ?>
$item): ?>
SKU