[Koha-patches] [PATCH] Quick Spine Label Printer

Kyle M Hall kyle.m.hall at gmail.com
Fri Jul 10 14:30:30 CEST 2009


This is a small tool for quickly printing spine labels using dedicated label printers.
It is located in the Tools page as Quick Spine Label Creator.
The system preference SpineLabelFormat defines which fields will be displayed.
The CSS file spinelabel.css controls all presentation for the labels.

The pref SpineLabelFormat defines what fields will appear in the spine label.
The pref SpineLabelAutoPrint will make the print dialog pop up automatically.
---
 installer/data/mysql/en/mandatory/sysprefs.sql     |    2 +
 .../1-Obligatoire/unimarc_standard_systemprefs.sql |    2 +
 installer/data/mysql/updatedatabase.pl             |    7 ++
 koha-tmpl/intranet-tmpl/prog/en/css/spinelabel.css |   27 +++++++
 .../prog/en/modules/labels/spinelabel-home.tmpl    |   24 ++++++
 .../prog/en/modules/labels/spinelabel-print.tmpl   |   14 ++++
 .../prog/en/modules/tools/tools-home.tmpl          |    5 ++
 labels/spinelabel-home.pl                          |   26 +++++++
 labels/spinelabel-print.pl                         |   74 ++++++++++++++++++++
 9 files changed, 181 insertions(+), 0 deletions(-)
 create mode 100644 koha-tmpl/intranet-tmpl/prog/en/css/spinelabel.css
 create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/labels/spinelabel-home.tmpl
 create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/labels/spinelabel-print.tmpl
 create mode 100755 labels/spinelabel-home.pl
 create mode 100755 labels/spinelabel-print.pl

diff --git a/installer/data/mysql/en/mandatory/sysprefs.sql b/installer/data/mysql/en/mandatory/sysprefs.sql
index a978fad..3b78ae9 100644
--- a/installer/data/mysql/en/mandatory/sysprefs.sql
+++ b/installer/data/mysql/en/mandatory/sysprefs.sql
@@ -245,3 +245,5 @@ INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('v
 INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewLabeledMARC','0','Allow display of labeled MARC view of bibiographic records','','YesNo');
 INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewMARC','1','Allow display of MARC view of bibiographic records','','YesNo');
 INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('FilterBeforeOverdueReport','0','Do not run overdue report until filter selected','','YesNo');
+INSERT INTO systempreferences (variable,value,options,explanation,type)VALUES('SpineLabelFormat', '<itemcallnumber><copynumber>', '', 'This preference defines the format for the quick spine label printer. Just list the fields you would like to see in the order you would like to see them, surrounded by <>, for example <itemcallnumber>.', 'Textarea');
+INSERT INTO systempreferences (variable,value,options,explanation,type)VALUES('SpineLabelAutoPrint', '0', '', 'If this setting is turned on, a print dialog will automatically pop up for the quick spine label printer.', 'YesNo');
diff --git a/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql b/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql
index 424b716..0f2cb57 100644
--- a/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql
+++ b/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql
@@ -247,3 +247,5 @@ INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('v
 INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewLabeledMARC','0','Autoriser l''affichage MARC labellis des notices bibliographiques','','YesNo');
 INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewMARC','1','Autoriser l''affichage de la vue MARC des notices bibliographiques','','YesNo');
 INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('FilterBeforeOverdueReport','0','Ne pas lancer le rapport sur les retards tant qu''il n''y a pas de filtre','','YesNo');
+INSERT INTO systempreferences (variable,value,options,explanation,type)VALUES('SpineLabelFormat', '<itemcallnumber><copynumber>', '', 'This preference defines the format for the quick spine label printer. Just list the fields you would like to see in the order you would like to see them, surrounded by <>, for example <itemcallnumber>.', 'Textarea');
+INSERT INTO systempreferences (variable,value,options,explanation,type)VALUES('SpineLabelAutoPrint', '0', '', 'If this setting is turned on, a print dialog will automatically pop up for the quick spine label printer.', 'YesNo');
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index 58497c8..3bf0b19 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -2467,6 +2467,13 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     print "Upgrade to $DBversion done (added FilterBeforeOverdueReport syspref and new index on authorised_values)\n";
 }
 
+$DBversion = '3.01.00.038';
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type)VALUES('SpineLabelFormat', '<itemcallnumber><copynumber>', '', 'This preference defines the format for the quick spine label printer. Just list the fields you would like to see in the order you would like to see them, surrounded by <>, for example <itemcallnumber>.', 'Textarea')");
+    SetVersion ($DBversion);
+    print "Upgrade to $DBversion done (added SpineLabelFormat syspref)\n";
+}
+
 =item DropAllForeignKeys($table)
 
   Drop all foreign keys of the table $table
diff --git a/koha-tmpl/intranet-tmpl/prog/en/css/spinelabel.css b/koha-tmpl/intranet-tmpl/prog/en/css/spinelabel.css
new file mode 100644
index 0000000..f0e3ead
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/en/css/spinelabel.css
@@ -0,0 +1,27 @@
+body {
+	font-family: arial, geneva, sans-serif;
+	font-size: 12px;
+	margin: 0px 0px 0px 0px;
+}
+
+/* Line break after each field */
+.field{
+	display: block;
+}
+
+/* Line break after each space in the itemcallnumber field */
+#itemcallnumber .space {
+	display: block;
+}
+
+/* Put the copynumber on the bottom of the label */
+#copynumber {
+	position: absolute;
+	top: 75px;
+}
+
+#print_button {
+	position: absolute;
+	top: 25px;
+	left: 500px;
+}
\ No newline at end of file
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/spinelabel-home.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/spinelabel-home.tmpl
new file mode 100644
index 0000000..c7c9879
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/spinelabel-home.tmpl
@@ -0,0 +1,24 @@
+<!-- TMPL_INCLUDE NAME="doc-head-open.inc" --><title>Koha &rsaquo; Tools &rsaquo; Labels</title>
+<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+</head>
+<body>
+<!-- TMPL_INCLUDE NAME="header.inc" -->
+<!-- TMPL_INCLUDE NAME="cat-search.inc" -->
+
+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; Spine Labels</div>
+
+<div id="doc3" class="yui-t2">
+   
+	<div id="bd">
+		<div id="yui-main">
+			<div class="yui-b">
+				<form action="/cgi-bin/koha/labels/spinelabel-print.pl" method="post">
+					<label>Barcode: </label>
+					<input type="text" name="barcode" id="barcode" />
+					<input type="submit" value="View Spine Label" />
+				</form>
+			</div>
+		</div>
+	</div>
+</div>
+<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/spinelabel-print.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/spinelabel-print.tmpl
new file mode 100644
index 0000000..8897435
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/spinelabel-print.tmpl
@@ -0,0 +1,14 @@
+<html>
+	<head>
+		<title>Koha &rsaquo; Tools &rsaquo; Spine Labels</title>
+		<link rel="stylesheet" type="text/css" href="<!-- TMPL_VAR name="themelang" -->/css/spinelabel.css" />
+	</head>
+	<body <!-- TMPL_IF NAME="autoprint">onLoad="window.print()"<!-- /TMPL_IF> >
+		<span id="spinelabel" class="label">
+			<!-- TMPL_VAR NAME="content" -->
+		</span>
+		<span id="print_button">
+			<form><input type="button" value="Print This Label" onClick="window.print()" /></form>
+		</span>
+	</body>
+</html>
\ No newline at end of file
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tmpl
index 75d8104..be817d9 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tmpl
@@ -24,6 +24,11 @@
     <dd>Create printable labels and barcodes from catalog data and patron cards from patron data</dd>
     <!-- /TMPL_IF -->
 
+    <!-- TMPL_IF NAME="CAN_user_tools_label_creator" -->
+    <dt><a href="/cgi-bin/koha/labels/spinelabel-home.pl">Quick Spine Label Creator</a></dt>
+    <dd>Enter a barcode to generate a printable spine label</dd>
+    <!-- /TMPL_IF -->
+
     <!-- TMPL_IF NAME="CAN_user_tools_edit_calendar" -->
     <dt><a href="/cgi-bin/koha/tools/holidays.pl">Calendar</a></dt>
     <dd>Define days when the library is closed</dd>
diff --git a/labels/spinelabel-home.pl b/labels/spinelabel-home.pl
new file mode 100755
index 0000000..5b271e7
--- /dev/null
+++ b/labels/spinelabel-home.pl
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+
+use strict;
+use CGI;
+use C4::Auth;
+use C4::Output;
+use C4::Labels;
+use C4::Output;
+use C4::Context;
+use HTML::Template::Pro;
+
+# use Smart::Comments;
+
+my $query = new CGI;
+my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
+    {
+        template_name   => "labels/spinelabel-home.tmpl",
+        query           => $query,
+        type            => "intranet",
+        authnotrequired => 0,
+        flagsrequired   => { catalogue => 1 },
+        debug           => 1,
+    }
+);
+
+output_html_with_http_headers $query, $cookie, $template->output;
diff --git a/labels/spinelabel-print.pl b/labels/spinelabel-print.pl
new file mode 100755
index 0000000..156c407
--- /dev/null
+++ b/labels/spinelabel-print.pl
@@ -0,0 +1,74 @@
+#!/usr/bin/perl
+
+use strict;
+use CGI;
+use C4::Auth;
+use C4::Output;
+use HTML::Template::Pro;
+
+my $scheme = C4::Context->preference('SpineLabelFormat');
+my $query = new CGI;
+my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
+    {
+        template_name   => "labels/spinelabel-print.tmpl",
+        query           => $query,
+        type            => "intranet",
+        authnotrequired => 0,
+        flagsrequired   => { catalogue => 1 },
+        debug           => 1,
+    }
+);
+
+
+my $barcode = $query->param('barcode');
+
+my $dbh = C4::Context->dbh;
+my $sth;
+
+my $item;
+
+my $sql = "SELECT * FROM biblio, biblioitems, items 
+          WHERE biblio.biblionumber = items.biblionumber 
+          AND biblioitems.biblioitemnumber = items.biblioitemnumber 
+          AND items.barcode = ?";
+$sth = $dbh->prepare( $sql );
+$sth->execute( $barcode );
+$item = $sth->fetchrow_hashref;
+
+my $body;
+
+my $data;
+while ( my ($key, $value ) = each(%$item) ) {
+  $data->{$key} .= "<span class='field' id='$key'>";
+
+  my @characters = split(//, $value );
+  my $charnum = 1;
+  my $wordnum = 1;
+  my $i = 1;
+  foreach my $char ( @characters ) {
+    if ( $char ne ' ' ) {
+      $data->{$key} .= "<span class='character word$wordnum character$charnum' id='$key$i'>$char</span>";
+    } else {
+      $data->{$key} .= "<span class='space character$charnum' id='$key$i'>$char</span>";
+      $wordnum++;
+      $charnum = 1;
+    }
+    $charnum++;
+    $i++;
+  }
+  
+  $data->{$key} .= "</span>";
+}
+
+while ( my ($key, $value ) = each(%$data) ) {
+  my $replacefield = "<$key>";
+  my $replacedby = $value;
+  $scheme =~ s/$replacefield/$replacedby/g;
+}
+
+$body = $scheme;
+
+$template->param( autoprint => C4::Context->preference("SpineLabelAutoPrint") );
+$template->param( content => $body );
+
+output_html_with_http_headers $query, $cookie, $template->output;
-- 
1.5.6.5




More information about the Koha-patches mailing list