diff --git a/print_labels.php b/print_labels.php index 667f162..10e56c0 100644 --- a/print_labels.php +++ b/print_labels.php @@ -8,6 +8,7 @@ $items = []; $skus = []; if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['skus'])) { $skus = is_array($_POST['skus']) ? $_POST['skus'] : explode(',', $_POST['skus']); + $skus = array_values(array_filter(array_map('trim', $skus))); } elseif (!empty($_GET['sku'])) { $skus = [$_GET['sku']]; } @@ -23,8 +24,63 @@ if (!empty($skus)) { } } +$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, @@ -35,6 +91,8 @@ $templates = [ '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)', @@ -46,6 +104,8 @@ $templates = [ '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)', @@ -57,12 +117,23 @@ $templates = [ '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)) { @@ -85,6 +156,8 @@ if (!empty($items)) { } } +$isSinglePrint = isset($_GET['sku']) && count($skus) === 1; + ?> @@ -99,8 +172,8 @@ if (!empty($items)) { .print-only { display: none; } .page { - width: 210mm; - min-height: 297mm; + width: = $pageWidth ?>; + height: = $pageHeight ?>; padding-top: = $tpl['margin_top'] ?>; padding-left: = $tpl['margin_left'] ?>; padding-right: = $tpl['margin_left'] ?>; @@ -116,6 +189,7 @@ if (!empty($items)) { row-gap: = $tpl['gap_y'] ?>; box-sizing: border-box; page-break-after: always; + overflow: hidden; } .label-item { @@ -146,16 +220,21 @@ if (!empty($items)) { margin: 0; border: initial; border-radius: initial; - width: 210mm; - min-height: 297mm; + width: = $pageWidth ?>; + height: = $pageHeight ?>; box-shadow: initial; background: initial; page-break-after: always; + overflow: hidden; + } + .page:last-of-type { + page-break-after: auto; } .label-item { border: none; } - @page { size: A4 portrait; margin: 0; } + @page { size: = $pageCssSize ?>; margin: 0; } } +
@@ -171,13 +250,15 @@ if (!empty($items)) {