Initial commit with barely functional code.

This commit is contained in:
2025-11-14 22:41:25 +00:00
parent 04e5be681c
commit aa07adc096
213 changed files with 34850 additions and 1 deletions

216
index.php Normal file
View File

@@ -0,0 +1,216 @@
<?php
// Databrae (working name)
// Proof of concept
$autoloadOk = file_exists(__DIR__ . '/vendor/autoload.php');
if ($autoloadOk) {
require __DIR__ . '/vendor/autoload.php';
}
// Using Tecnick's barcode library to generate data matrix barcodes
use Com\Tecnick\Barcode\Barcode;
function safe($s) {
return htmlspecialchars(trim($s ?? ''), ENT_QUOTES, 'UTF-8');
}
// Set up the form input
$data1 = $_POST['data1'] ?? '';
$data2 = $_POST['data2'] ?? '';
$data3 = $_POST['data3'] ?? '';
$data4 = $_POST['data4'] ?? '';
$barcodeText = $_POST['barcode'] ?? '';
$isPosted = ($_SERVER['REQUEST_METHOD'] === 'POST');
// Declare some variables
$svgBarcode = '';
$errorMsg = '';
// Generate the data matrix barcode and handle some common errors where I've already screwed up
if ($isPosted) {
if (!$autoloadOk) {
$errorMsg = 'Composer autoload not found. Run <code>composer require tecnickcom/tc-lib-barcode</code> in this folder.';
} elseif ($barcodeText === '') {
$errorMsg = 'Please provide a Barcode value.';
} else {
try {
$barcode = new Barcode();
// Create the data matrix as an SVG
$bobj = $barcode->getBarcodeObj(
'DATAMATRIX',
$barcodeText,
-1, // width auto
-1, // height auto
'black',
[0, 0, 0, 0]
);
$bobj->setBackgroundColor('white');
$svgBarcode = $bobj->getSvgCode();
} catch (Throwable $e) {
$errorMsg = 'Barcode generation error: ' . safe($e->getMessage());
}
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Spine Label Generator</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
:root {
--font: "Helvetica Neue", Arial, sans-serif;
}
body {
font-family: var(--font);
margin: 1.5rem;
color: #222;
line-height: 1.35;
}
form {
display: grid;
gap: .75rem;
max-width: 520px;
margin-bottom: 1.5rem;
}
label { font-weight: 600; }
input[type="text"] {
padding: .5rem .6rem;
border: 1px solid #bbb;
border-radius: 6px;
font-size: 1rem;
width: 100%;
}
.row { display: grid; gap: .35rem; }
.actions { margin-top: .5rem; }
button {
padding: .6rem .9rem;
border: 1px solid #444;
background: #111;
color: #fff;
border-radius: 8px;
cursor: pointer;
font-weight: 600;
}
button:hover { filter: brightness(1.05); }
.note {
font-size: .9rem;
color: #555;
}
.error {
padding: .75rem 1rem;
border: 1px solid #d33;
background: #fee;
color: #a00;
border-radius: 8px;
max-width: 520px;
margin-bottom: 1rem;
}
/* ===== Label (exact print size) ===== */
.preview-wrap {
display: grid;
gap: 1rem;
}
.label-card {
width: 2.5cm; /* fixed physical width */
height: 3.5cm; /* fixed physical height */
box-sizing: border-box; /* include padding in the fixed size */
border: 1px dashed #aaa;/* guide border (hidden on print) */
padding: 0.2cm; /* compact padding to fit content */
display: flex;
flex-direction: column;
justify-content: space-between; /* push barcode to bottom */
background: #fff;
}
.label-text {
display: grid;
gap: 0.1cm; /* tight vertical spacing between Data 13 */
text-align: center; /* center the three lines */
margin: .2cm;
line-height: 1.2;
font-size: 0.35cm; /* ~8pt—adjust as needed */
word-break: break-word;
}
.label-text-line { white-space: pre-wrap; }
.barcode-block {
display: flex;
justify-content: center; /* center code horizontally */
align-items: flex-end;
margin-top: 0.05cm; /* tiny breathing room under Data 3 */
}
/* Keep the Data Matrix exactly 1.5 cm in height; width auto to keep it square */
.barcode-block svg {
display: block;
height: .5cm; /* requested fixed height */
width: auto;
}
@media print {
form, .note, .error, h1 { display: none !important; }
body { margin: 0; }
.label-card { border: none; } /* remove guide border on print */
/* Ensure the browser doesn't scale */
@page { margin: 0; }
}
</style>
</head>
<body>
<h1>Spine Label Generator</h1>
<form method="post">
<div class="row">
<label for="data1">Data 1</label>
<input type="text" id="data1" name="data1" value="<?= safe($data1) ?>" placeholder="e.g., QA76.73.P224">
</div>
<div class="row">
<label for="data2">Data 2</label>
<input type="text" id="data2" name="data2" value="<?= safe($data2) ?>" placeholder="e.g., 2025">
</div>
<div class="row">
<label for="data3">Data 3</label>
<input type="text" id="data3" name="data3" value="<?= safe($data3) ?>" placeholder="e.g., v.2">
</div>
<div class="row">
<label for="data4">Data 4</label>
<input type="text" id="data4" name="data4" value="<?= safe($_POST['data4'] ?? '') ?>" placeholder="e.g., Copy 1">
</div>
<div class="row">
<label for="barcode">Barcode (alphanumeric)</label>
<input type="text" id="barcode" name="barcode" value="<?= safe($barcodeText) ?>" placeholder="e.g., 1230004231819">
</div>
<div class="actions">
<button type="submit">Build Label</button>
</div>
<p class="note">Tip: In the browser print dialog, set scale to <strong>100% / Actual size</strong>.</p>
</form>
<?php if ($errorMsg): ?>
<div class="error"><?= $errorMsg ?></div>
<?php endif; ?>
<?php if ($isPosted && !$errorMsg): ?>
<div class="preview-wrap">
<div class="label-card">
<div class="label-text">
<div class="label-text-line"><?= nl2br(safe($data1)) ?></div>
<div class="label-text-line"><?= nl2br(safe($data2)) ?></div>
<div class="label-text-line"><?= nl2br(safe($data3)) ?></div>
<div class="label-text-line"><?= nl2br(safe($_POST['data4'] ?? '')) ?></div>
</div>
<div class="barcode-block">
<?= $svgBarcode /* Inline SVG keeps print quality high */ ?>
</div>
</div>
</div>
<?php endif; ?>
</body>
</html>