forked from markusberg/barcode-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
299 lines (271 loc) · 10.4 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<?php
/**
* Barcode
* Online barcode generator
* Version 1.0
*
* Written by Markus Berg
* email: [email protected]
* http://kelvin.nu/software/barcode/
*
* Copyright 2013 Markus Berg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
include "Page.class.php";
$page = new Page();
$page->setTitle("Barcode generator");
$page->printHeader();
?>
<style type="text/css">
th {
text-align: right;
white-space: nowrap;
}
#advanced {
padding: 0.3em;
cursor: pointer;
font-style: italic;
text-decoration: underline;
color: blue;
}
#advancedBlock {
border: 1px solid grey;
background: #efefef;
display: none;
padding: 0.5em 1em;
margin-bottom: 1em;
}
#prefix {
text-transform: uppercase;
}
#warning {
color: red;
font-style: italic;
display: none;
}
</style>
<script type="text/javascript">
function zeropad(n, width) {
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join('0') + n;
}
function toggleDisplay( sName ) {
var domName = document.getElementById( sName );
domName.style.display = ( domName.style.display=="block" ? "none" : "block" );
}
function toggleAdvanced() {
if ( domAdvancedBlock.style.display=="block" ) {
domAdvancedBlock.style.display="none";
domAdvanced.innerHTML="Display advanced layout options";
} else {
domAdvancedBlock.style.display="block";
domAdvanced.innerHTML="Hide advanced layout options";
}
}
function reloadSample() {
var image = document.createElement('img');
var fileName = (domTape.value=="dlt" ? "dlt" : "lto") + "-" + domTextOrientation.value + "-" + (domColorized.checked ? "color" : "bw") + ".png";
domSample.setAttribute("src", fileName);
}
function sanityCheck() {
// Ensure that startno contains only digits
var test = domStartno.value.replace(/\D/g, '');
if (test !== domStartno.value) {
domStartno.value = test;
}
// Sanity check the length of the label
if (domPrefix.value.length + domStartno.value.length > 6) {
domWarning.style.display="block";
} else {
domWarning.style.display="none";
}
}
// Set margins for LTO layout
function setMarginsLTO() {
document.getElementById('textOrientation').value='vertical';
document.getElementById('cols').value=2;
document.getElementById('rows').value=16;
document.getElementById('marginPageLeft').value=18.5;
document.getElementById('marginPageTop').value=22;
document.getElementById('spacingCol').value=20.5;
document.getElementById('spacingRow').value=0;
}
// Set margins for Super DLT layout
function setMarginsDLT() {
document.getElementById('textOrientation').value='horizontal';
document.getElementById('cols').value=3;
document.getElementById('rows').value=13;
document.getElementById('marginPageLeft').value=15;
document.getElementById('marginPageTop').value=15;
document.getElementById('spacingCol').value=0;
document.getElementById('spacingRow').value=0;
}
// Reset margins if tape type is changed from Super DLT to LTO or vice versa
function tapeChange() {
if (oldTapeType == 'dlt' && this.value != 'dlt') {
setMarginsLTO();
} else if (oldTapeType != 'dlt' && this.value=='dlt') {
setMarginsDLT();
}
// Save the current value for next time
oldTapeType = this.value;
if (this.value == "custom") {
domSuffix.value = "";
// domSuffix.disabled = false;
domSuffix.focus();
} else {
domSuffix.value = this.value.toUpperCase();
// domSuffix.disabled = true;
}
}
function init() {
domAdvanced = document.getElementById('advanced');
domAdvancedBlock = document.getElementById('advancedBlock');
domAdvanced.addEventListener("click", toggleAdvanced, false);
domTape = document.getElementById("tape");
domPrefix = document.getElementById("prefix");
domSuffix = document.getElementById("suffix");
domStartno = document.getElementById("startno");
domWarning = document.getElementById("warning");
domTextOrientation = document.getElementById("textOrientation");
domColorized = document.getElementById("colorized");
// Display appropriate sample image depending on current selections
domTape.addEventListener("change", tapeChange);
domTape.addEventListener("change", reloadSample);
domTextOrientation.addEventListener("change", reloadSample);
domColorized.addEventListener("change", reloadSample);
// Sanity check length of labels
domPrefix.addEventListener("keyup", sanityCheck);
domStartno.addEventListener("keyup", sanityCheck);
// Reload sample image in case of back-button-press
domSample = document.getElementById('sample');
setMarginsLTO();
reloadSample();
}
var domTape;
var domPrefix;
var domSuffix;
var domStartno;
var domWarning;
var domTextOrientation;
var domColorized;
var domAdvanced;
var domAdvancedBlock;
var domSample;
var oldTapeType = "l3";
window.onload = init;
</script>
<?php
$page->printMenu();
?>
<h1>Barcode label generator</h1>
<p>Use this form to generate barcodes for your tape library. Each LTO label can contain at most six characters
plus a two-character media identifier (L3, L4, etc.). A DLT label is limited to six characters.</p>
<p>All feedback is welcome.</p>
<p>Latest update: 2015-08-04</p>
<form name="barcodeGenerator" method="post" action="print.php">
<table>
<tr>
<th>Tape type: </th>
<td><select name="tape" id="tape">
<option value="dlt">Super DLT</option>
<option value="l3" selected="selected">LTO-3</option>
<option value="l4">LTO-4</option>
<option value="l5">LTO-5</option>
<option value="l6">LTO-6</option>
<option value="lw">LTO-6 Worm</option>
<option value="cu">Cleaning unit</option>
<option value="custom">Custom...</option>
</select>
<input type="text" name="suffix" id="suffix" value="L3" size="2" maxlength="2" /></td>
</tr>
<tr>
<th>Prefix: </th>
<td><input type="text" maxlength=6 name="prefix" id="prefix" value="ZF" /></td>
<td rowspan=2><div id="warning">Warning: a label can at most contain six characters</div></td>
</tr>
<tr>
<th>Starting number: </th>
<td><input type="text" maxlength=6 name="startno" id="startno" value="0001" /></td>
</tr>
</tr>
<th>Sample: </th>
<td colspan=2><img src="lto-vertical-bw.png" id="sample"/></td>
<tr>
</table>
<p id="advanced">Display advanced layout options</p>
<div id="advancedBlock">
<table>
<!--
<tr>
<th>Checksum: </th>
<td><input type="checkbox" name="checksum" value="true" id="checksum" /><label for="checksum"> (not all tape libraries require this)</label></td>
</tr>
-->
<tr>
<th>Borders: </th>
<td><input type="checkbox" name="borders" value="true" id="borders" checked="checked" /><label for="borders"> labels are printed with borders</label></td>
</tr>
<tr>
<th>Colorized: </th>
<td><input type="checkbox" name="colorized" value="true" id="colorized" /><label for="colorized"> labels are colorized (tri-optic vibrant compatible)</label></td>
</tr>
<tr>
<th>Text orientation: </th>
<td><select name="textOrientation" id="textOrientation">
<option value="vertical">Vertical</option>
<option value="horizontal">Horizontal</option>
</select></td>
</tr>
<tr>
<th>Page size: </th>
<td><select name="pageSize" />
<option value="a4">A4</option>
<option value="letter">Letter</option>
</select></td>
</tr>
<tr>
<th>Columns: </th>
<td><input type="text" name="cols" id="cols" /></td>
</tr>
<tr>
<th>Rows: </th>
<td><input type="text" name="rows" id="rows" /></td>
</tr>
<tr>
<th>Page left margin: </th>
<td><input type="text" name="marginPageLeft" id="marginPageLeft" />mm</td>
</tr>
<tr>
<th>Page top margin: </th>
<td><input type="text" name="marginPageTop" id="marginPageTop" />mm</td>
</tr>
<tr>
<th>Spacing between columns: </th>
<td><input type="text" name="spacingCol" id="spacingCol" />mm</td>
</tr>
<tr>
<th>Spacing between rows: </th>
<td><input type="text" name="spacingRow" id="spacingRow" />mm</td>
</tr>
</table>
</div>
<input type="submit" value="Generate PDF" />
</form>
<p>This software is open source, and licensed under the Apache License v2. You can download the source from github:<br />
<code>https://github.com/markusberg/barcode</code></p>
<?php
$page->printFooter();
?>