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 {
&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
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);
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) = @_;
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
}
-sub by_order {
- $$a{order} <=> $$b{order};
-}
-
=head2 sub add_batch
=over 4
add_batch($batch_type,\@batch_list);
$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;
$itemtype, $bcn, $dcn, $classif,
$subclass, $itemcallnumber, $author, $printingtype,
- $guidebox, $startlabel, $layoutname
+ $guidebox, $startlabel, $layoutname, $formatstring
);
$sth2->finish;
$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
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;
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 ) = @_;
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 =~ /^(.*)\/(.*)$/;
PrintText( $hPos, $vPos, $font, $fontsize, $str );
$vPos = $vPos - $line_spacer;
}
- } # if field is
- } #foreach feild
+ }
+ } #foreach field
}
sub PrintText {
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" --><title>Koha › Tools › 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> › <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> › <a href="/cgi-bin/koha/labels/label-home.pl">Labels</a> › Edit Label Layout</div>
+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> › <a href="/cgi-bin/koha/labels/label-home.pl">Labels</a> › <!-- 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>
<!-- /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>
<td> </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>
</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>
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');
}
);
-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;
$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");
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,