[Barcode] Web Frontend
dani@enpl.es
dani@enpl.es
Tue, 6 Feb 2001 09:46:48 -0500 (EST)
Hi All. I've written a little CGI that acts as a frontend to the barcode
utility. You can specify the destination printer, the numer of pages,
encoding, margins etc..
It might be useful to some dumb user in your netowrk in order to easily
print barcodes. =20
Notice it might be full of security holes,=20
It also has a missing feature: It doesn't print EAN-128 O:-)
=20
-------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
use CGI;
my $query;
my @codificacions;
my @impresores;
my $codificacio;
my $codi;
my $impresora;
my $horitz;
my $pagina;
my $copies;
my $vert;
my $marge_sup;
my $marge_inf;
my $sh;
@codificacions=3D("EAN-13","EAN-8","UPC","ISBN","CODE39","CODE128","i25","C=
ODABAR","MSI","PLESSEY");
@impresores=3D("hpmanip","haley","hpexped","apple","lexmark","laserjet5");
$query=3Dnew CGI;
if($query->param())
{
# Recollida de parametres
$codificacio=3D$query->param("codificacio");
$codi=3D$query->param("codi");
$impresora=3D$query->param("impresora");
$horitz=3D$query->param("horitz");
$vert=3D$query->param("vert");
$pagina=3D$query->param("pagina");
$copies=3D$query->param("copies");
$marge_sup=3D$query->param("marge_sup");
$marge_inf=3D$query->param("marge_inf");
# Capcalera HTML
print $query->header();
print $query->start_html("Generaci=F3 de codis de barra");
print '<meta HTTP-EQUIV=3D"EXPIRES" CONTENT=3D"0">';
print '<BODY BGCOLOR=3D"#FFFFFF">';
=20
if ($codi eq "")
{
print "<BR><B> Error: No has posat res en el el camp codi</B>";exit;
}
if (!($horitz=3D~/(\d+)/) or(!($vert=3D~/(\d+)/)))
{
print "<BR><B> Error: No has entrat b=E9 la distribuci=F3 d'etiquetes</=
B>";exit;
}
if (!($pagina=3D~/(\d+)x(\d+)/))
{
print "<BR><B> Error: No has entrat b=E9 el tipo de pagina</B>"; exit;
} =20
if (!($copies=3D~/(\d+)/))
{
print "<BR><B> Error: No has entrat be el Num. de copies</B>"; exit;
}
if((!($marge_sup=3D~/\d+/)) or (!($marge_inf=3D~/\d+/)))
{
print "<BR><B> Error: No has entrat b=E9 els marges</B>";exit();
}
$sh=3D"/usr/local/bin/barcode -u mm -e " . lc($codificacio);
$sh.=3D " -t " . $horitz . "x" . $vert . "+0+0-0-" . $marge_inf;
$sh.=3D " -g " . $pagina . "+2+" . $marge_sup; # Marge esquere de 2 mm.=
=20
=20
=20
$sh .=3D (" -b " . $codi) x ($horitz * $vert);
# printf("<B>%s</B>",$sh);
=20
open(PIPE,"$sh 2>&1 1>/tmp/ean |");
while(<PIPE>)
{
# Si hi ha algo a STDERR, ho ensenyem i sortim
printf("<BR>%s",$_);
exit();=09
}
close(PIPE);
system("/usr/bin/lp -d $impresora -n $copies /tmp/ean >/dev/null");
print "<B>Fet</B>";
print $query->end_html;
}
else
{
=09# No hi ha parametres, fem la pagina
print $query->header();
print $query->start_html("Generaci=F3 de codis de barra");
print '<meta HTTP-EQUIV=3D"EXPIRES" CONTENT=3D"0">';
print '<BODY BGCOLOR=3D"#FFFFFF">';
print $query->start_form;
$query->delete_all();
print '<TABLE BORDER=3D"0" WIDTH=3D"100%">';
print '<TR VALIGN=3D"TOP"><TD ROWSPAN=3D"3" WIDTH=3D"30%"><img
src=3D"http://calix:85/enplater.jpg" HEIGHT=3D70
WIDTH=3D197></TD>';
print '<TD colspan=3D"2" rowspan=3D"2" width=3D"195">';
print '<UL><font size=3D+3><BR>Generaci=F3 de codis de barra ';
print '</font></TD>';
print '</TR></TABLE>';
print $query->hr;
print 'Codificaci=F3: ' . $query->popup_menu("codificacio",\@codificacions=
) . " Codi: " . $query->textfield("codi","8410435",20);
print '<BR>Impresora: ' . $query->popup_menu("impresora",\@impresores);
print $query->hr;
print '<B>Etiquetes</B><BR>Horitz: ' . $query->textfield("horitz","3",5) .=
"Vert: " . $query->textfield("vert","5",5);
print '<BR><BR><B>Copies</B><BR>Treure ' . $query->textfield("copies","1",=
5) . ' Copies';
=20
print '<BR><BR><B>P=E0gina</B><BR>Dimensions(mm): ' . $query->textfield("p=
agina","210x297",10);
print '<BR>Marge Superior(mm): ' . $query->textfield("marge_sup","20",10);
print '<BR>Marge Inferior(mm): ' . $query->textfield("marge_inf","20",10);
print '<BR><BR>' . $query->submit(-name=3D>'Imprmir');
print $query->end_form;
print $query->end_html;
}