- $VERSION = 0.03;
- require Exporter;
- @ISA = qw(Exporter);
- @EXPORT = qw(
- &get_label_options &GetLabelItems
- &build_circ_barcode &draw_boundaries
- &drawbox &GetActiveLabelTemplate
- &GetAllLabelTemplates &DeleteTemplate
- &GetSingleLabelTemplate &SaveTemplate
- &CreateTemplate &SetActiveTemplate
- &SaveConf &DrawSpineText &GetTextWrapCols
- &GetUnitsValue &DrawBarcode &DrawPatronCardText
- &get_printingtypes &GetPatronCardItems
- &get_layouts
- &get_barcode_types
- &get_batches &delete_batch
- &add_batch &printText
- &GetItemFields
- &get_text_fields
- get_layout &save_layout &add_layout
- &set_active_layout
- &build_text_dropbox
- &delete_layout &get_active_layout
- &get_highest_batch
- &deduplicate_batch
- &GetAllPrinterProfiles &GetSinglePrinterProfile
- &SaveProfile &CreateProfile &DeleteProfile
- &GetAssociatedProfile &SetAssociatedProfile
- );
-}
-
-
-=head1 NAME
-
-C4::Labels - Functions for printing spine labels and barcodes in Koha
-
-=head1 FUNCTIONS
-
-=over 2
-
-=item get_label_options;
-
- $options = get_label_options()
-
-Return a pointer on a hash list containing info from labels_conf table in Koha DB.
-
-=cut
-
-sub get_label_options {
- my $query2 = " SELECT * FROM labels_conf where active = 1"; # FIXME: exact same as get_active_layout
- my $sth = C4::Context->dbh->prepare($query2);
- $sth->execute();
- return $sth->fetchrow_hashref;
-}
-
-sub get_layouts {
- my $dbh = C4::Context->dbh;
- my @data;
- my $query = " Select * from labels_conf";
- my $sth = $dbh->prepare($query);
- $sth->execute();
- my @resultsloop;
- while ( my $data = $sth->fetchrow_hashref ) {
-
- $data->{'fieldlist'} = get_text_fields( $data->{'id'} );
- push( @resultsloop, $data );
- }
- $sth->finish;
- return @resultsloop;
-}
-
-sub get_layout {
- my ($layout_id) = @_;
- my $dbh = C4::Context->dbh;
-
- # get the actual items to be printed.
- my $query = " Select * from labels_conf where id = ?";
- my $sth = $dbh->prepare($query);
- $sth->execute($layout_id);
- my $data = $sth->fetchrow_hashref;
- $sth->finish;
- return $data;
-}
-
-sub get_active_layout {
- my $query = " Select * from labels_conf where active = 1"; # FIXME: exact same as get_label_options
- my $sth = C4::Context->dbh->prepare($query);
- $sth->execute();
- return $sth->fetchrow_hashref;
-}
-
-sub delete_layout {
- my ($layout_id) = @_;
- my $dbh = C4::Context->dbh;
-
- # get the actual items to be printed.
- my $query = "delete from labels_conf where id = ?";
- my $sth = $dbh->prepare($query);
- $sth->execute($layout_id);
- $sth->finish;
-}
-
-sub get_printingtypes {
- my ($layout_id) = @_;
- my @printtypes;
-# FIXME hard coded print types
- 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);
- my $active_printtype = $conf->{'printingtype'};
-
- # lop thru layout, insert selected to hash
-
- foreach my $printtype (@printtypes) {
- if ( $printtype->{'code'} eq $active_printtype ) {
- $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) = @_;
- my $field_count = 7; # <----------- FIXME hard coded
- my @lines;
- !$order
- ? push( @lines, { num => '', selected => '1' } )
- : push( @lines, { num => '' } );
- for ( my $i = 1 ; $i <= $field_count ; $i++ ) {
- my $line = { num => "$i" };
- $line->{'selected'} = 1 if $i eq $order;
- push( @lines, $line );
- }
- return @lines;
-}
-
-sub get_text_fields {
- my ( $layout_id, $sorttype ) = @_;
- 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
- my @text_fields = (
- {
- code => 'itemtype',
- desc => "Item Type",
- order => $sortorder->{'itemtype'}
- },
- {
- code => 'issn',
- desc => "ISSN",
- order => $sortorder->{'issn'}
- },
- {
- code => 'isbn',
- desc => "ISBN",
- order => $sortorder->{'isbn'}
- },
- {
- code => 'barcode',
- desc => "Barcode",
- order => $sortorder->{'barcode'}
- },
- {
- code => 'author',
- desc => "Author",
- order => $sortorder->{'author'}
- },
- {
- code => 'title',
- desc => "Title",
- order => $sortorder->{'title'}
- },
- {
- code => 'itemcallnumber',
- desc => "Call Number",
- order => $sortorder->{'itemcallnumber'}
- },
- );
-
- 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;
- }
-
- # 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
- return @sorted_fields;
- }
- else {
- foreach my $field (@sorted_fields) {
- $active_fields .= "$field->{'desc'} ";
- }
- return $active_fields;
- }
-
-}
-
-=head2 sub add_batch
-=over 4
- add_batch($batch_type,\@batch_list);
- if $batch_list is supplied,
- create a new batch with those items.
- else, return the next available batch_id.
-=return
-=cut
-
-sub add_batch ($;$) {
- my $table = (@_ and 'patroncards' eq shift) ? 'patroncards' : 'labels';
- my $batch_list = (@_) ? shift : undef;
- my $dbh = C4::Context->dbh;
- my $q ="SELECT MAX(DISTINCT batch_id) FROM $table";
- my $sth = $dbh->prepare($q);
- $sth->execute();
- my ($batch_id) = $sth->fetchrow_array || 0;
- $batch_id++;
- if ($batch_list) {
- if ($table eq 'patroncards') {
- $sth = $dbh->prepare("INSERT INTO $table (`batch_id`,`borrowernumber`) VALUES (?,?)");
- } else {
- $sth = $dbh->prepare("INSERT INTO $table (`batch_id`,`itemnumber` ) VALUES (?,?)");
- }
- for (@$batch_list) {
- $sth->execute($batch_id,$_);
- }
- }
- return $batch_id;
-}
-
-#FIXME: Needs to be ported to receive $batch_type
-# ... this looks eerily like add_batch() ...
-sub get_highest_batch {
- my $table = (@_ and 'patroncards' eq shift) ? 'patroncards' : 'labels';
- my $q =
- "select distinct batch_id from $table order by batch_id desc limit 1";
- my $sth = C4::Context->dbh->prepare($q);
- $sth->execute();
- my $data = $sth->fetchrow_hashref or return 1;
- return ($data->{'batch_id'} || 1);
-}
-
-
-sub get_batches (;$) {
- my $table = (@_ and 'patroncards' eq shift) ? 'patroncards' : 'labels';
- my $q = "SELECT batch_id, COUNT(*) AS num FROM $table GROUP BY batch_id";
- my $sth = C4::Context->dbh->prepare($q);
- $sth->execute();
- my $batches = $sth->fetchall_arrayref({});
- return @$batches;
-}
-
-sub delete_batch {
- my ($batch_id, $batch_type) = @_;
- warn "Deleteing batch of type $batch_type";
- my $dbh = C4::Context->dbh;
- my $q = "DELETE FROM $batch_type WHERE batch_id = ?";
- my $sth = $dbh->prepare($q);
- $sth->execute($batch_id);
- $sth->finish;
-}
-
-sub get_barcode_types {
- my ($layout_id) = @_;
- my $layout = get_layout($layout_id);
- my $barcode = $layout->{'barcodetype'};
- my @array;
-
- push( @array, { code => 'CODE39', desc => 'Code 39' } );
- push( @array, { code => 'CODE39MOD', desc => 'Code39 + Modulo43' } );
- push( @array, { code => 'CODE39MOD10', desc => 'Code39 + Modulo10' } );
- push( @array, { code => 'ITF', desc => 'Interleaved 2 of 5' } );
-
- foreach my $line (@array) {
- if ( $line->{'code'} eq $barcode ) {
- $line->{'active'} = 1;
- }
-
- }
- return @array;
-}
-
-sub GetUnitsValue {
- my ($units) = @_;
- my $unitvalue;
-
- $unitvalue = '1' if ( $units eq 'POINT' );
- $unitvalue = '2.83464567' if ( $units eq 'MM' );
- $unitvalue = '28.3464567' if ( $units eq 'CM' );
- $unitvalue = 72 if ( $units eq 'INCH' );
- return $unitvalue;
-}
-
-sub GetTextWrapCols {
- my ( $font, $fontsize, $label_width, $left_text_margin ) = @_;
- my $string = '0';
- my $strwidth;
- my $count = 0;
-# my $textlimit = $label_width - ($left_text_margin);
- my $textlimit = $label_width - ( 3 * $left_text_margin);
-
- while ( $strwidth < $textlimit ) {
- $strwidth = prStrWidth( $string, $font, $fontsize );
- $string = $string . '0';
- #warn "strwidth:$strwidth, textlimit:$textlimit, count:$count string:$string";
- $count++;
- }
- return $count;
-}
-
-sub GetActiveLabelTemplate {
- my $dbh = C4::Context->dbh;
- my $query = " SELECT * FROM labels_templates where active = 1 limit 1";
- my $sth = $dbh->prepare($query);
- $sth->execute();
- my $active_tmpl = $sth->fetchrow_hashref;
- $sth->finish;
- return $active_tmpl;
-}
-
-sub GetSingleLabelTemplate {
- my ($tmpl_id) = @_;
- my $dbh = C4::Context->dbh;
- my $query = " SELECT * FROM labels_templates where tmpl_id = ?";
- my $sth = $dbh->prepare($query);
- $sth->execute($tmpl_id);
- my $template = $sth->fetchrow_hashref;
- $sth->finish;
- return $template;
-}
-
-sub SetActiveTemplate {
-
- my ($tmpl_id) = @_;
-
- my $dbh = C4::Context->dbh;
- my $query = " UPDATE labels_templates SET active = NULL";
- my $sth = $dbh->prepare($query);
- $sth->execute();
-
- $query = "UPDATE labels_templates SET active = 1 WHERE tmpl_id = ?";
- $sth = $dbh->prepare($query);
- $sth->execute($tmpl_id);
- $sth->finish;
-}
-
-sub set_active_layout {
-
- my ($layout_id) = @_;
- my $dbh = C4::Context->dbh;
- my $query = " UPDATE labels_conf SET active = NULL";
- my $sth = $dbh->prepare($query);
- $sth->execute();
-
- $query = "UPDATE labels_conf SET active = 1 WHERE id = ?";
- $sth = $dbh->prepare($query);
- $sth->execute($layout_id);
- $sth->finish;
-}
-
-sub DeleteTemplate {
- my ($tmpl_id) = @_;
- my $dbh = C4::Context->dbh;
- my $query = " DELETE FROM labels_templates where tmpl_id = ?";
- my $sth = $dbh->prepare($query);
- $sth->execute($tmpl_id);
- $sth->finish;
-}
-
-sub SaveTemplate {
- my (
- $tmpl_id, $tmpl_code, $tmpl_desc, $page_width,
- $page_height, $label_width, $label_height, $topmargin,
- $leftmargin, $cols, $rows, $colgap,
- $rowgap, $font, $fontsize, $units
- ) = @_;
- $debug and warn "Passed \$font:$font";
- my $dbh = C4::Context->dbh;
- my $query =
- " UPDATE labels_templates SET tmpl_code=?, tmpl_desc=?, page_width=?,
- page_height=?, label_width=?, label_height=?, topmargin=?,
- leftmargin=?, cols=?, rows=?, colgap=?, rowgap=?, font=?, fontsize=?,
- units=?
- WHERE tmpl_id = ?";
-
- my $sth = $dbh->prepare($query);
- $sth->execute(
- $tmpl_code, $tmpl_desc, $page_width, $page_height,
- $label_width, $label_height, $topmargin, $leftmargin,
- $cols, $rows, $colgap, $rowgap,
- $font, $fontsize, $units, $tmpl_id
- );
- my $dberror = $sth->errstr;
- $sth->finish;
- return $dberror;
-}
-
-sub CreateTemplate {
- my $tmpl_id;
- my (
- $tmpl_code, $tmpl_desc, $page_width, $page_height,
- $label_width, $label_height, $topmargin, $leftmargin,
- $cols, $rows, $colgap, $rowgap,
- $font, $fontsize, $units
- ) = @_;
-
- my $dbh = C4::Context->dbh;
-
- my $query = "INSERT INTO labels_templates (tmpl_code, tmpl_desc, page_width,
- page_height, label_width, label_height, topmargin,
- leftmargin, cols, rows, colgap, rowgap, font, fontsize, units)
- VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
-
- my $sth = $dbh->prepare($query);
- $sth->execute(
- $tmpl_code, $tmpl_desc, $page_width, $page_height,
- $label_width, $label_height, $topmargin, $leftmargin,
- $cols, $rows, $colgap, $rowgap,
- $font, $fontsize, $units
- );
- my $dberror = $sth->errstr;
- $sth->finish;
- return $dberror;
-}
-
-sub GetAllLabelTemplates {
- my $dbh = C4::Context->dbh;
-
- # get the actual items to be printed.
- my @data;
- my $query = " Select * from labels_templates ";
- my $sth = $dbh->prepare($query);
- $sth->execute();
- my @resultsloop;
- while ( my $data = $sth->fetchrow_hashref ) {
- push( @resultsloop, $data );
- }
- $sth->finish;
-
- #warn Dumper @resultsloop;
- return @resultsloop;
-}
-
-#sub SaveConf {
-sub add_layout {
-
- my (
- $barcodetype, $title, $subtitle, $isbn, $issn,
- $itemtype, $bcn, $dcn, $classif,
- $subclass, $itemcallnumber, $author, $tmpl_id,
- $printingtype, $guidebox, $startlabel, $layoutname, $formatstring
- ) = @_;
-
- my $dbh = C4::Context->dbh;
- my $query2 = "update labels_conf set active = NULL";
- my $sth2 = $dbh->prepare($query2);
- $sth2->execute();
- $query2 = "INSERT INTO labels_conf
- ( barcodetype, title, subtitle, isbn,issn, itemtype, barcode,
- dewey, classification, subclass, itemcallnumber, author, printingtype,
- guidebox, startlabel, layoutname, formatstring, active )
- values ( ?, ?,?, ?, ?, ?, ?, ?, ?,?, ?, ?, ?, ?, ?,?,?, 1 )";
- $sth2 = $dbh->prepare($query2);
- $sth2->execute(
- $barcodetype, $title, $subtitle, $isbn, $issn,
-
- $itemtype, $bcn, $dcn, $classif,
- $subclass, $itemcallnumber, $author, $printingtype,
- $guidebox, $startlabel, $layoutname, $formatstring
- );
- $sth2->finish;
-
- SetActiveTemplate($tmpl_id);
- return;
-}
-
-sub save_layout {
-
- my (
- $barcodetype, $title, $subtitle, $isbn, $issn,
- $itemtype, $bcn, $dcn, $classif,
- $subclass, $itemcallnumber, $author, $tmpl_id,
- $printingtype, $guidebox, $startlabel, $layoutname, $formatstring,
- $layout_id
- ) = @_;
-### $layoutname
-### $layout_id
-
- my $dbh = C4::Context->dbh;
- my $query2 = "update labels_conf set
- barcodetype=?, title=?, subtitle=?, isbn=?,issn=?,
- itemtype=?, barcode=?, dewey=?, classification=?,
- subclass=?, itemcallnumber=?, author=?, printingtype=?,
- 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, $formatstring, $layout_id
- );
- $sth2->finish;
-
- return;
-}
-
-=item GetAllPrinterProfiles;
-
- @profiles = GetAllPrinterProfiles()
-
-Returns an array of references-to-hash, whos keys are .....
-
-=cut
-
-sub GetAllPrinterProfiles {
-
- my $dbh = C4::Context->dbh;
- my @data;
- my $query = "SELECT * FROM printers_profile AS pp INNER JOIN labels_templates AS lt ON pp.tmpl_id = lt.tmpl_id; ";
- my $sth = $dbh->prepare($query);
- $sth->execute();
- my @resultsloop;
- while ( my $data = $sth->fetchrow_hashref ) {
- push( @resultsloop, $data );
- }
- $sth->finish;
-
- return @resultsloop;
-}
-
-=item GetSinglePrinterProfile;
-
- $profile = GetSinglePrinterProfile()
-
-Returns a hashref whos keys are...
-
-=cut
-
-sub GetSinglePrinterProfile {
- my ($prof_id) = @_;
- my $dbh = C4::Context->dbh;
- my $query = " SELECT * FROM printers_profile WHERE prof_id = ?; ";
- my $sth = $dbh->prepare($query);
- $sth->execute($prof_id);
- my $template = $sth->fetchrow_hashref;
- $sth->finish;
- return $template;
-}
-
-=item SaveProfile;
-
- SaveProfile('parameters')
-
-When passed a set of parameters, this function updates the given profile with the new parameters.
-
-=cut
-
-sub SaveProfile {
- my (
- $prof_id, $offset_horz, $offset_vert, $creep_horz, $creep_vert, $units
- ) = @_;
- my $dbh = C4::Context->dbh;
- my $query =
- " UPDATE printers_profile
- SET offset_horz=?, offset_vert=?, creep_horz=?, creep_vert=?, unit=?
- WHERE prof_id = ? ";
- my $sth = $dbh->prepare($query);
- $sth->execute(
- $offset_horz, $offset_vert, $creep_horz, $creep_vert, $units, $prof_id
- );
- $sth->finish;
-}
-
-=item CreateProfile;
-
- CreateProfile('parameters')
-
-When passed a set of parameters, this function creates a new profile containing those parameters
-and returns any errors.
-
-=cut
-
-sub CreateProfile {
- my (
- $prof_id, $printername, $paper_bin, $tmpl_id, $offset_horz,
- $offset_vert, $creep_horz, $creep_vert, $units
- ) = @_;
- my $dbh = C4::Context->dbh;
- my $query =
- " INSERT INTO printers_profile (prof_id, printername, paper_bin, tmpl_id,
- offset_horz, offset_vert, creep_horz, creep_vert, unit)
- VALUES(?,?,?,?,?,?,?,?,?) ";
- my $sth = $dbh->prepare($query);
- $sth->execute(
- $prof_id, $printername, $paper_bin, $tmpl_id, $offset_horz,
- $offset_vert, $creep_horz, $creep_vert, $units
- );
- my $error = $sth->errstr;
- $sth->finish;
- return $error;
-}
-
-=item DeleteProfile;
-
- DeleteProfile(prof_id)
-
-When passed a profile id, this function deletes that profile from the database and returns any errors.
-
-=cut
-
-sub DeleteProfile {
- my ($prof_id) = @_;
- my $dbh = C4::Context->dbh;
- my $query = " DELETE FROM printers_profile WHERE prof_id = ?";
- my $sth = $dbh->prepare($query);
- $sth->execute($prof_id);
- my $error = $sth->errstr;
- $sth->finish;
- return $error;
-}
-
-=item GetAssociatedProfile;
-
- $assoc_prof = GetAssociatedProfile(tmpl_id)
-
-When passed a template id, this function returns the parameters from the currently associated printer profile
-in a hashref where key=fieldname and value=fieldvalue.
-
-=cut
-
-sub GetAssociatedProfile {
- my ($tmpl_id) = @_;
- my $dbh = C4::Context->dbh;
- # First we find out the prof_id for the associated profile...
- my $query = "SELECT * FROM labels_profile WHERE tmpl_id = ?";
- my $sth = $dbh->prepare($query);
- $sth->execute($tmpl_id);
- my $assoc_prof = $sth->fetchrow_hashref;
- $sth->finish;
- # Then we retrieve that profile and return it to the caller...
- $assoc_prof = GetSinglePrinterProfile($assoc_prof->{'prof_id'});
- return $assoc_prof;
-}
-
-=item SetAssociatedProfile;
-
- SetAssociatedProfile($prof_id, $tmpl_id)
-
-When passed both a profile id and template id, this function establishes an association between the two. No more
-than one profile may be associated with any given template at the same time.
-
-=cut
-
-sub SetAssociatedProfile {
-
- my ($prof_id, $tmpl_id) = @_;
-
- my $dbh = C4::Context->dbh;
- my $query = "INSERT INTO labels_profile (prof_id, tmpl_id) VALUES (?,?) ON DUPLICATE KEY UPDATE prof_id = ?";
- my $sth = $dbh->prepare($query);
- $sth->execute($prof_id, $tmpl_id, $prof_id);
- $sth->finish;
-}
-
-
-=item GetLabelItems;
-
- $options = GetLabelItems()
-
-Returns an array of references-to-hash, whos keys are the fields from the biblio, biblioitems, items and labels tables in the Koha database.
-
-=cut
-
-sub GetLabelItems {
- my ($batch_id) = @_;
- my $dbh = C4::Context->dbh;
-
- my @resultsloop = ();
- my $count;
- my @data;
- my $sth;
-
- if ($batch_id) {
- my $query3 = "
- SELECT *
- FROM labels
- WHERE batch_id = ?
- ORDER BY labelid";
- $sth = $dbh->prepare($query3);
- $sth->execute($batch_id);
- }
- else {
- my $query3 = "
- SELECT *
- FROM labels";
- $sth = $dbh->prepare($query3);
- $sth->execute();
- }
- my $cnt = $sth->rows;
- my $i1 = 1;
- while ( my $data = $sth->fetchrow_hashref ) {
-
- # lets get some summary info from each item
- my $query1 =
-# FIXME This makes for a very bulky data structure; data from tables w/duplicate col names also gets overwritten.
-# Something like this, perhaps, but this also causes problems because we need more fields sometimes.
-# SELECT i.barcode, i.itemcallnumber, i.itype, bi.isbn, bi.issn, b.title, b.author
- "SELECT bi.*, i.*, b.*
- FROM items AS i, biblioitems AS bi ,biblio AS b
- WHERE itemnumber=? AND i.biblioitemnumber=bi.biblioitemnumber AND bi.biblionumber=b.biblionumber";
- my $sth1 = $dbh->prepare($query1);
- $sth1->execute( $data->{'itemnumber'} );
-
- my $data1 = $sth1->fetchrow_hashref();
- $data1->{'labelno'} = $i1;
- $data1->{'labelid'} = $data->{'labelid'};
- $data1->{'batch_id'} = $batch_id;
- $data1->{'summary'} = "$data1->{'barcode'}, $data1->{'title'}, $data1->{'isbn'}";
-
- push( @resultsloop, $data1 );
- $sth1->finish;
-
- $i1++;
- }
- $sth->finish;
- return @resultsloop;
-
-}
-
-sub GetItemFields {
- my @fields = qw (
- barcode title
- isbn issn
- author itemtype
- itemcallnumber
- );
- 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 $match_kohatable = join(
- '|',
- (
- @{ $kohatables->{biblio} },
- @{ $kohatables->{biblioitems} },
- @{ $kohatables->{items} }
- )
- );
- while ($f) {
- $f =~ s/^\s?//;
- if ( $f =~ /^'(.*)'.*/ ) {
- # single quotes indicate a static text string.
- $datastring .= $1;
- $f = $';
- }
- elsif ( $f =~ /^($match_kohatable).*/ ) {
- $datastring .= $item->{$f};
- $f = $';
- }
- elsif ( $f =~ /^([0-9a-z]{3})(\w)(\W?).*?/ ) {
- my $marc_field = $1;
- foreach my $subfield ($record->field($marc_field)) {
- if ( $subfield->subfield('9') eq $item->{'itemnumber'} ) {
- $datastring .= $subfield->subfield($2 ) . $3;
- last;
- }
- }
- $f = $';
- }
- else {
- last; # Failed to match
- }
- }
- return $datastring;
-}
-
-=head descKohaTables
-Return a hashref of an array of hashes,
-with name,type keys.
-=cut