Labels update- print any marc field and add csv output.

Make any MARC data available to labels module;
Also add a csv output option, allowing export of relevant
biblio data do a 3rd party label layout application.
Note: This patch REQUIRES a forthcoming updatedatabase patch !

Signed-off-by: Joshua Ferraro <jmf@liblime.com>
This commit is contained in:
Ryan Higgins 2008-04-22 17:45:47 -05:00 committed by Joshua Ferraro
parent fdc82f6c56
commit 56b87af4db
8 changed files with 276 additions and 99 deletions

View File

@ -26,7 +26,9 @@ use Algorithm::CheckDigits;
use C4::Members;
use C4::Branch;
use C4::Debug;
#use Data::Dumper;
use C4::Biblio;
use Text::CSV_XS;
use Data::Dumper;
# use Smart::Comments;
BEGIN {
@ -50,7 +52,7 @@ BEGIN {
&GetItemFields
&get_text_fields
get_layout &save_layout &add_layout
&set_active_layout &by_order
&set_active_layout
&build_text_dropbox
&delete_layout &get_active_layout
&get_highest_batch
@ -151,11 +153,12 @@ sub get_printingtypes {
my ($layout_id) = @_;
my @printtypes;
# FIXME: hard coded print types
push( @printtypes, { code => 'BAR', desc => "barcode" } );
push( @printtypes, { code => 'BIB', desc => "biblio" } );
push( @printtypes, { code => 'BAR', desc => "barcode only" } );
push( @printtypes, { code => 'BIB', desc => "biblio only" } );
push( @printtypes, { code => 'BARBIB', desc => "barcode / biblio" } );
push( @printtypes, { code => 'BIBBAR', desc => "biblio / barcode" } );
push( @printtypes, { code => 'ALT', desc => "alternating labels" } );
push( @printtypes, { code => 'CSV', desc => "csv output" } );
push( @printtypes, { code => 'PATCRD', desc => "patron cards" } );
my $conf = get_layout($layout_id);
@ -165,12 +168,15 @@ sub get_printingtypes {
foreach my $printtype (@printtypes) {
if ( $printtype->{'code'} eq $active_printtype ) {
$printtype->{'active'} = 'MOO';
$printtype->{'active'} = 1;
}
}
return @printtypes;
}
# this sub (build_text_dropbox) is deprecated and should be deleted.
# rch 2008.04.15
#
sub build_text_dropbox {
my ($order) = @_;
@ -195,88 +201,89 @@ sub build_text_dropbox {
sub get_text_fields {
my ($layout_id, $sorttype) = @_;
my ( $a, $b, $c, $d, $e, $f, $g, $h, $i ,$j, $k );
my @sorted_fields;
my $error;
my $sortorder = get_layout($layout_id);
if( $sortorder->{formatstring}) {
if(! $sorttype) {
return $sortorder->{formatstring} ;
} else {
my $csv = Text::CSV_XS->new( { allow_whitespace => 1 } ) ;
my $line= $sortorder->{formatstring} ;
my $status = $csv->parse( $line );
@sorted_fields = map {{ 'code' => $_ , desc => $_ } } $csv->fields() ;
$error = $csv->error_input();
warn $error if $error ; # TODO - do more with this.
}
} else {
# These fields are hardcoded based on the template for label-edit-layout.pl
$a = {
my @text_fields = (
{
code => 'itemtype',
desc => "Item Type",
order => $sortorder->{'itemtype'}
};
$b = {
},
{
code => 'dewey',
desc => "Dewey",
order => $sortorder->{'dewey'}
};
$c = {
},
{
code => 'issn',
desc => "ISSN",
order => $sortorder->{'issn'}
};
$d = {
},
{
code => 'isbn',
desc => "ISBN",
order => $sortorder->{'isbn'}
};
$e = {
},
{
code => 'class',
desc => "Classification",
order => $sortorder->{'class'}
};
$f = {
},
{
code => 'subclass',
desc => "Sub-Class",
order => $sortorder->{'subclass'}
};
$g = {
},
{
code => 'barcode',
desc => "Barcode",
order => $sortorder->{'barcode'}
};
$h = {
},
{
code => 'author',
desc => "Author",
order => $sortorder->{'author'}
};
$i = {
},
{
code => 'title',
desc => "Title",
order => $sortorder->{'title'}
};
$j = {
},
{
code => 'itemcallnumber',
desc => "Call Number",
order => $sortorder->{'itemcallnumber'}
};
$k = {
},
{
code => 'subtitle',
desc => "Subtitle",
order => $sortorder->{'subtitle'}
};
}
);
my @text_fields = ( $a, $b, $c, $d, $e, $f, $g, $h, $i ,$j, $k );
my @new_fields;
foreach my $field (@text_fields) {
push( @new_fields, $field ) if $field->{'order'} > 0;
my @new_fields;
foreach my $field (@text_fields) {
push( @new_fields, $field ) if $field->{'order'} > 0;
}
@sorted_fields = sort { $$a{order} <=> $$b{order} } @new_fields;
}
my @sorted_fields = sort by_order @new_fields;
# if we have a 'formatstring', then we ignore these hardcoded fields.
my $active_fields;
if ($sorttype eq 'codes') { # FIXME: This sub should really always return the array of hashrefs and let the caller take what he wants from that -fbcit
@ -290,10 +297,6 @@ sub get_text_fields {
}
sub by_order {
$$a{order} <=> $$b{order};
}
=head2 sub add_batch
=over 4
add_batch($batch_type,\@batch_list);
@ -568,7 +571,7 @@ sub add_layout {
$barcodetype, $title, $subtitle, $isbn, $issn,
$itemtype, $bcn, $dcn, $classif,
$subclass, $itemcallnumber, $author, $tmpl_id,
$printingtype, $guidebox, $startlabel, $layoutname
$printingtype, $guidebox, $startlabel, $layoutname, $formatstring
) = @_;
my $dbh = C4::Context->dbh;
@ -586,7 +589,7 @@ sub add_layout {
$itemtype, $bcn, $dcn, $classif,
$subclass, $itemcallnumber, $author, $printingtype,
$guidebox, $startlabel, $layoutname
$guidebox, $startlabel, $layoutname, $formatstring
);
$sth2->finish;
@ -600,7 +603,7 @@ sub save_layout {
$barcodetype, $title, $subtitle, $isbn, $issn,
$itemtype, $bcn, $dcn, $classif,
$subclass, $itemcallnumber, $author, $tmpl_id,
$printingtype, $guidebox, $startlabel, $layoutname,
$printingtype, $guidebox, $startlabel, $layoutname, $formatstring,
$layout_id
) = @_;
### $layoutname
@ -611,13 +614,13 @@ sub save_layout {
barcodetype=?, title=?, subtitle=?, isbn=?,issn=?,
itemtype=?, barcode=?, dewey=?, classification=?,
subclass=?, itemcallnumber=?, author=?, printingtype=?,
guidebox=?, startlabel=?, layoutname=? where id = ?";
guidebox=?, startlabel=?, layoutname=?, formatstring=? where id = ?";
my $sth2 = $dbh->prepare($query2);
$sth2->execute(
$barcodetype, $title, $subtitle, $isbn, $issn,
$itemtype, $bcn, $dcn, $classif,
$subclass, $itemcallnumber, $author, $printingtype,
$guidebox, $startlabel, $layoutname, $layout_id
$guidebox, $startlabel, $layoutname, $formatstring, $layout_id
);
$sth2->finish;
@ -852,6 +855,57 @@ sub GetItemFields {
return @fields;
}
=head GetBarcodeData
=over 4
Parse labels_conf.formatstring value
(one value of the csv, which has already been split)
and return string from koha tables or MARC record.
=back
=cut
#'
sub GetBarcodeData {
my ($f,$item,$record) = @_;
my $kohatables= &_descKohaTables();
my $datastring;
my $last_f = $f;
my $match_kohatable = join('|', (@{$kohatables->{biblio}},@{$kohatables->{biblioitems}},@{$kohatables->{items}}) );
while( $f ) {
if( $f =~ /^'(.*)'.*/ ) {
# single quotes indicate a static text string.
$datastring .= $1 ;
$f = $';
} elsif ( $f =~ /^($match_kohatable).*/ ) {
# grep /$f/, (@$kohatables->{biblio},@$kohatables->{biblioitems},@$kohatables->{items}) ) {
$datastring .= $item->{$f};
$f = $';
} elsif ( $f =~ /^([0-9a-z]{3})(\w)(\W*).*/ ) {
$datastring .= $record->subfield($1,$2) . $3 if($record->subfield($1,$2)) ;
$f = $';
}
last if ( $f eq $last_f ); # failed to match
}
return $datastring;
}
=head descKohaTables
Return a hashref of an array of hashes,
with name,type keys.
=cut
sub _descKohaTables {
my $dbh = C4::Context->dbh();
my $kohatables;
for my $table ( 'biblio','biblioitems','items' ) {
my $sth = $dbh->column_info(undef,undef,$table,'%');
while (my $info = $sth->fetchrow_hashref()){
push @{$kohatables->{$table}} , $info->{'COLUMN_NAME'} ;
}
$sth->finish;
}
return $kohatables;
}
sub GetPatronCardItems {
my ( $batch_id ) = @_;
@ -939,28 +993,34 @@ sub DrawSpineText {
my $vPos = ( $y_pos + ( $label_height - $top_text_margin ) );
my @str_fields = get_text_fields($layout_id, 'codes' );
my @fields;
foreach my $field (@str_fields) {
push (@fields, $field->{'code'});
}
my $record = GetMarcBiblio($$item->{biblionumber});
# FIXME - returns all items, so you can't get data from an embedded holdings field.
# TODO - add a GetMarcBiblio1item(bibnum,itemnum) or a GetMarcItem(itemnum).
my $old_fontname = $fontname; # We need to keep track of the original font passed in...
foreach my $field (@fields) {
for my $field (@str_fields) {
if ($$conf_data->{'formatstring'}) {
$field->{'data'} = GetBarcodeData($field->{'code'},$$item,$record) ;
} else {
$field->{data} = $$item{$field->{'code'}} ;
}
# This allows us to print the title in italic (oblique) type... (Times Roman has a different nomenclature.)
# It seems there should be a better way to handle fonts in the label/patron card tool altogether -fbcit
($field eq 'title') ? (($old_fontname =~ /T/) ? ($fontname = 'TI') : ($fontname = ($old_fontname . 'O'))) : ($fontname = $old_fontname);
($field->{code} eq 'title') ? (($old_fontname =~ /T/) ? ($fontname = 'TI') : ($fontname = ($old_fontname . 'O'))) : ($fontname = $old_fontname);
my $font = prFont($fontname);
# if the display option for this field is selected in the DB,
# and the item record has some values for this field, display it.
if ( $$conf_data->{"$field"} && $$item->{"$field"} ) {
if ( ($$conf_data->{'formatstring'}) || ( $$conf_data->{$field->{code}} && $$item->{$field->{code}} ) ) {
# get the string
$str = $$item->{"$field"};
my $str = $field->{data} ;
# strip out naughty existing nl/cr's
$str =~ s/\n//g;
$str =~ s/\r//g;
my @strings;
if ($field eq 'itemcallnumber') { # If the field contains the call number, we do some special processing on it here...
if ($field->{code} eq 'itemcallnumber') { # If the field contains the call number, we do some special processing on it here...
if (($nowrap == 0) || (!$nowrap)) { # wrap lines based on segmentation markers: '/' (other types of segmentation markers can be added as needed here or this could be added as a syspref.)
while ( $str =~ /\// ) {
$str =~ /^(.*)\/(.*)$/;
@ -996,8 +1056,8 @@ sub DrawSpineText {
PrintText( $hPos, $vPos, $font, $fontsize, $str );
$vPos = $vPos - $line_spacer;
}
} # if field is
} #foreach feild
}
} #foreach field
}
sub PrintText {

View File

@ -493,6 +493,10 @@ fieldset.rows fieldset {
padding : .3em;
}
fieldset.disabled {
color: #999 !important;
}
.yui-b fieldset.rows label, .yui-b fieldset.rows span.label {
width: 9em;
}

View File

@ -21,7 +21,7 @@
//]]>
</script>
<ul class="toolbar">
<li><a id="newlabel" href="/cgi-bin/koha/labels/label-create-layout.pl">New Layout</a></li>
<li><a id="newlabel" href="/cgi-bin/koha/labels/label-edit-layout.pl">New Layout</a></li>
<li><a id="newtemplate" href="/cgi-bin/koha/labels/label-create-template.pl?op=blank">New Label Template</a></li>
<li><a id="newprofile" href="/cgi-bin/koha/labels/label-create-profile.pl?op=blank">New Printer Profile</a></li>
<li><a id="newlabelbatch" href="/cgi-bin/koha/labels/label-manager.pl?op=add_batch&amp;type=labels">New Label Batch</a></li>

View File

@ -1,21 +1,54 @@
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" --><title>Koha &rsaquo; Tools &rsaquo; Labels</title>
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
<script>
function jscss(action,o,c1,c2)
{
// from: http://onlinetools.org/articles/unobtrusivejavascript/cssjsseparation.html
switch (action){
case 'swap':
o.className=!jscss('check',o,c1)?o.className.replace(c2,c1): o.className.replace(c1,c2);
break;
case 'add':
if(!jscss('check',o,c1)){o.className+=o.className?' '+c1:c1;}
break;
case 'remove':
var rep=o.className.match(' '+c1)?' '+c1:c1;
o.className=o.className.replace(rep,'');
break;
case 'check':
return new RegExp('\\b'+c1+'\\b').test(o.className)
break;
}
}
function chooselayoutspec(rb) {
stringspec=document.getElementById("formatstring");
if(rb.value == 'layout_string') {
stringspec.disabled=0;
jscss('remove',document.getElementById('layout_string'),'disabled','');
jscss('add',document.getElementById('layout_tx'),'disabled','');
} else {
stringspec.disabled=1;
jscss('remove',document.getElementById('layout_tx'),'disabled','');
jscss('add',document.getElementById('layout_string'),'disabled','');
}
}
</script>
</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; <a href="/cgi-bin/koha/labels/label-home.pl">Labels</a> &rsaquo; Edit Label Layout</div>
<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; <a href="/cgi-bin/koha/labels/label-home.pl">Labels</a> &rsaquo; <!-- TMPL_IF NAME="layout_id" -->Edit<!-- TMPL_ELSE -->Create<!-- /TMPL_IF --> Label Layout</div>
<div id="doc3" class="yui-t2">
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<!-- TMPL_INCLUDE NAME="tools-labels-toolbar.inc" -->
<form name="input" action="/cgi-bin/koha/labels/label-manager.pl" method="get">
<fieldset class="rows">
<legend>Edit Label Layout</legend>
<legend><!-- TMPL_IF NAME="layout_id" -->Edit<!-- TMPL_ELSE -->Create<!-- /TMPL_IF --> Label Layout</legend>
<ol>
<li><label for="layoutname">Layout Name</label>
<input type="text" name="layoutname" id="layoutname" size="20" value="<!-- TMPL_VAR NAME="layoutname" -->" /></li>
@ -43,10 +76,14 @@
<!-- /TMPL_LOOP -->
</select></li>
<li><fieldset class="rows">
<li>
<fieldset class="rows">
<legend>
Choose Order Of Text Fields to Print
Bibliographic Data to Print
</legend>
<input type="radio" name="layoutchoice" value="layout_tx" <!-- TMPL_UNLESS NAME="layout_string" -->checked="checked"<!-- /TMPL_UNLESS --> onclick="chooselayoutspec(this);" >Choose Order Of Text Fields to Print</input>
<fieldset id="layout_tx" <!-- TMPL_IF NAME="layout_string" -->class="disabled"<!-- /TMPL_IF -->>
<table summary="fields to print">
<tr>
<td>
@ -221,9 +258,21 @@
<td>&nbsp;</td>
</tr>
</table>
</fieldset></li>
<li><label for="startlabel">Start printing from Label number: </label><input type="text" name="startlabel" id="startlabel" size="1" value="<!-- TMPL_VAR NAME="startlabel" -->" /></li>
</fieldset>
<br />
<input type="radio" name="layoutchoice" value="layout_string" <!-- TMPL_IF NAME="layout_string" -->checked="checked"<!-- /TMPL_IF --> onclick="chooselayoutspec(this);"> List Fields </input>
<fieldset id="layout_string" <!-- TMPL_UNLESS NAME="layout_string" -->class="disabled"<!-- /TMPL_UNLESS -->>
<label for="layoutname">Data Fields</label>
<input type="text" name="formatstring" id="formatstring" size="60" value="<!-- TMPL_VAR NAME="formatstring" -->" <!-- TMPL_UNLESS NAME="layout_string" -->disabled="true"<!-- /TMPL_UNLESS --> />
<div class="help">
<p>Enter a comma separated list of fields to print. You may include any <em>Koha field</em> or MARC subfield.</p>
<p>See online help for advanced options</p>
<p>ex: barcode, itemcallnumber, title, "050a 050b", 300a </p>
</div>
</fieldset>
</fieldset>
</li>
<li><label for="startlabel">Start printing from Label number: </label><input type="text" name="startlabel" id="startlabel" size="1" value="<!-- TMPL_IF NAME="startlabel" --><!-- TMPL_VAR NAME="startlabel" --><!-- TMPL_ELSE -->1<!-- /TMPL_IF -->" /></li>
<li><label for="guidebox">Draw Guide Boxes</label>
@ -237,7 +286,7 @@
</fieldset>
<fieldset class="action">
<input type="submit" value="Submit" /> <a class="cancel" href="/cgi-bin/koha/labels/label-home.pl">Cancel</a>
<input type="hidden" name="op" value="save_layout" />
<input type="hidden" name="op" value="<!-- TMPL_IF NAME="layout_id" -->save<!-- TMPL_ELSE -->add<!-- /TMPL_IF -->_layout" />
<input type="hidden" name="layout_id" value="<!-- TMPL_VAR NAME="layout_id" -->" />
</fieldset>
</form>

View File

@ -93,7 +93,7 @@
<td><!-- TMPL_VAR NAME="num" --> records</td>
<td><a href="/cgi-bin/koha/labels/label-manager.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=labels">Edit</a></td>
<td><a href="/cgi-bin/koha/labels/label-manager.pl?op=delete_batch&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=labels">Delete</a><!-- FIXME: should use POST to change server state, not GET --></td>
<td><a style="float: left;" href="/cgi-bin/koha/labels/label-print-pdf.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=labels">Generate PDF for Batch <!-- TMPL_VAR NAME="batch_id" --></a></td>
<td><a style="float: left;" href="/cgi-bin/koha/labels/label-print-<!-- TMPL_VAR NAME="outputformat" -->.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=labels">Generate and download <!-- TMPL_VAR NAME="batch_id" --></a></td>
</tr>
<!-- /TMPL_LOOP -->
</table>
@ -136,7 +136,7 @@
<td><!-- TMPL_VAR NAME="num" --> records</td>
<td><a href="/cgi-bin/koha/labels/label-manager.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=patroncards">Edit</a></td>
<td><a href="/cgi-bin/koha/labels/label-manager.pl?op=delete_batch&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=patroncards">Delete</a><!-- FIXME: should use POST to change server state, not GET --></td>
<td><a style="float: left;" href="/cgi-bin/koha/labels/label-print-pdf.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=patroncards">Generate PDF for Batch <!-- TMPL_VAR NAME="batch_id" --></a></td>
<td><a style="float: left;" href="/cgi-bin/koha/labels/label-print-<!-- TMPL_VAR NAME="outputformat" -->.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=patroncards">Generate and download <!-- TMPL_VAR NAME="batch_id" --></a></td>
</tr>
<!-- /TMPL_LOOP -->
</table>

View File

@ -8,9 +8,7 @@ use C4::Labels;
use C4::Context;
use HTML::Template::Pro;
#use Data::Dumper;
#use Smart::Comments;
my $dbh = = C4::Context->dbh;
my $query = new CGI;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
@ -25,6 +23,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
my $data = get_label_options();
my $op = $query->param('op');
my $layout_id = $query->param('layout_id');
my $active_template = GetActiveLabelTemplate();
my @label_templates = GetAllLabelTemplates();
@ -33,7 +32,10 @@ my @layouts = get_layouts();
my @barcode_types = get_barcode_types();
my @batches = get_batches();
### $data
my @barcode_types = get_barcode_types($layout_id);
my @printingtypes = get_printingtypes($layout_id);
my $layout;
$layout = get_layout($layout_id) if($layout_id);
$template->param( guidebox => 1 ) if ( $data->{'guidebox'} );
$template->param( "papertype_$data->{'papertype'}" => 1 );

View File

@ -40,6 +40,7 @@ my $startlabel = $query->param('startlabel');
my $printingtype = $query->param('printingtype');
my $guidebox = $query->param('guidebox');
my $fontsize = $query->param('fontsize');
my $formatstring = $query->param('formatstring');
my @itemnumber;
($query->param('type') eq 'labels') ? (@itemnumber = $query->param('itemnumber')) : (@itemnumber = $query->param('borrowernumber'));
my $batch_type = $query->param('type');
@ -72,24 +73,25 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
}
);
if ( $op eq 'save_conf' ) { # this early sub is depreciated, use save_layout()
SaveConf(
$barcodetype, $title, $isbn,
$issn, $itemtype, $bcn, $dcn,
$classif, $subclass, $itemcallnumber, $author,
$tmpl_id, $printingtype, $guidebox, $startlabel, $layoutname
);
print $query->redirect("label-home.pl");
exit;
}
elsif ( $op eq 'save_layout' ) {
#if ( $op eq 'save_conf' ) { # this early sub is depreciated, use save_layout()
# SaveConf(
# $barcodetype, $title, $isbn,
# $issn, $itemtype, $bcn, $dcn,
# $classif, $subclass, $itemcallnumber, $author,
# $tmpl_id, $printingtype, $guidebox, $startlabel, $layoutname
# );
# print $query->redirect("label-home.pl");
# exit;
#}
#elsif ( $op eq 'save_layout' ) {
if ( $op eq 'save_layout' ) {
save_layout(
$barcodetype, $title, $subtitle, $isbn,
$issn, $itemtype, $bcn, $dcn,
$classif, $subclass, $itemcallnumber, $author,
$tmpl_id, $printingtype, $guidebox, $startlabel, $layoutname,
$layout_id
);
, $formatstring , $layout_id
);
### $layoutname
print $query->redirect("label-home.pl");
exit;
@ -100,7 +102,7 @@ elsif ( $op eq 'add_layout' ) {
$issn, $itemtype, $bcn, $dcn,
$classif, $subclass, $itemcallnumber, $author,
$tmpl_id, $printingtype, $guidebox, $startlabel, $layoutname,
$layout_id
$formatstring , $layout_id
);
### $layoutname
print $query->redirect("label-home.pl");
@ -184,6 +186,9 @@ $template->param(
batch_count => scalar @resultsloop,
active_layout_name => $active_layout_name,
active_template_name => $active_template_name,
outputformat => ( $active_layout->{'printingtype'} eq 'CSV' ) ? 'csv' : 'pdf' ,
layout_tx => ( $active_layout->{'formatstring'}) ? 0 : 1 ,
layout_string => ( $active_layout->{'formatstring'}) ? 1 : 0 ,
resultsloop => \@resultsloop,
batches => \@batches,

57
labels/label-print-csv.pl Executable file
View File

@ -0,0 +1,57 @@
#!/usr/bin/perl
use strict;
use CGI;
use C4::Labels;
use C4::Auth;
use C4::Output;
use C4::Context;
use C4::Biblio;
use Text::CSV_XS;
my $DEBUG = 0;
my $DEBUG_LPT = 0;
my $htdocs_path = C4::Context->config('intrahtdocs');
my $cgi = new CGI;
# get the printing settings
my $template = GetActiveLabelTemplate();
my $conf_data = get_label_options();
my $batch_id = $cgi->param('batch_id');
my $exportname = 'koha_label_' . $batch_id . '.csv';
print $cgi->header(-type => 'application/vnd.sun.xml.calc',
-encoding => 'utf-8',
-attachment => $exportname,
-filename => $exportname );
my $batch_type = $conf_data->{'type'};
my $barcodetype = $conf_data->{'barcodetype'};
my $printingtype = $conf_data->{'printingtype'};
my @resultsloop = GetLabelItems($batch_id);
my $csv = Text::CSV_XS->new();
my @str_fields = get_text_fields($conf_data->{'id'}, 'codes' );
for my $item (@resultsloop) {
my $record = GetMarcBiblio($item->{biblionumber});
my @datafields = ($conf_data->{'formatstring'}) ?
map { C4::Labels::GetBarcodeData($_->{'code'},$item,$record) } @str_fields
: map { $_->{'code'} } @str_fields ;
my $csvout ;
if($csv->combine(@datafields)) {
$csvout = $csv->string();
print "$csvout\n";
} else {
warn "CSV ERROR: " . $csv->error_input;
}
} # end for item loop
exit(1);
# is that the right way to do this ?