followup - use & in place of &
[koha.git] / C4 / Labels.pm
index db0d274..3a21bbd 100644 (file)
@@ -69,9 +69,7 @@ C4::Labels - Functions for printing spine labels and barcodes in Koha
 
 =head1 FUNCTIONS
 
-=over 2
-
-=item get_label_options;
+=head2 get_label_options;
 
        $options = get_label_options()
 
@@ -261,19 +259,25 @@ sub get_text_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
+
+=back
+
 =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";
+    # FIXME : batch_id  should be an auto_incr INT.  Temporarily casting as int ( see koha bug 2555 )
+    # until a label_batches table is added, and we can convert batch_id to int.
+    my $q ="SELECT MAX( CAST(batch_id AS SIGNED) ) FROM $table";
     my $sth = $dbh->prepare($q);
     $sth->execute();
     my ($batch_id) = $sth->fetchrow_array || 0;
@@ -567,7 +571,7 @@ sub save_layout {
     return;
 }
 
-=item GetAllPrinterProfiles;
+=head2 GetAllPrinterProfiles;
 
     @profiles = GetAllPrinterProfiles()
 
@@ -591,7 +595,7 @@ sub GetAllPrinterProfiles {
     return @resultsloop;
 }
 
-=item GetSinglePrinterProfile;
+=head2 GetSinglePrinterProfile;
 
     $profile = GetSinglePrinterProfile()
 
@@ -610,7 +614,7 @@ sub GetSinglePrinterProfile {
     return $template;
 }
 
-=item SaveProfile;
+=head2 SaveProfile;
 
     SaveProfile('parameters')
 
@@ -634,7 +638,7 @@ sub SaveProfile {
     $sth->finish;
 }
 
-=item CreateProfile;
+=head2 CreateProfile;
 
     CreateProfile('parameters')
 
@@ -663,7 +667,7 @@ sub CreateProfile {
     return $error;
 }
 
-=item DeleteProfile;
+=head2 DeleteProfile;
 
     DeleteProfile(prof_id)
 
@@ -682,7 +686,7 @@ sub DeleteProfile {
     return $error;
 }
 
-=item GetAssociatedProfile;
+=head2 GetAssociatedProfile;
 
     $assoc_prof = GetAssociatedProfile(tmpl_id)
 
@@ -705,7 +709,7 @@ sub GetAssociatedProfile {
     return $assoc_prof;
 }
 
-=item SetAssociatedProfile;
+=head2 SetAssociatedProfile;
 
     SetAssociatedProfile($prof_id, $tmpl_id)
 
@@ -726,7 +730,7 @@ sub SetAssociatedProfile {
 }
 
 
-=item GetLabelItems;
+=head2 GetLabelItems;
 
         $options = GetLabelItems()
 
@@ -800,20 +804,21 @@ sub GetItemFields {
     return @fields;
 }
 
-=head GetBarcodeData
+=head2 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();
-use Data::Dumper;
-warn Dumper($kohatables);
     my $datastring = '';
     my $match_kohatable = join(
         '|',
@@ -823,7 +828,7 @@ warn Dumper($kohatables);
             @{ $kohatables->{items} }
         )
     );
-    while ($f) {  warn $f;
+    while ($f) {  
         $f =~ s/^\s?//;
         if ( $f =~ /^'(.*)'.*/ ) {
             # single quotes indicate a static text string.
@@ -835,12 +840,20 @@ warn Dumper($kohatables);
             $f = $';
         }
         elsif ( $f =~ /^([0-9a-z]{3})(\w)(\W?).*?/ ) {
-            my $marc_field = $1;
-            $datastring .= $record->subfield($1,$2) . $3 if($record->subfield($1,$2)) ;
-            foreach my $subfield ($record->field($marc_field)) {
-                if ( $subfield->subfield('9') eq $item->{'itemnumber'} ) {
-                    $datastring .= $subfield->subfield($2 ) . $3;
-                    last;
+            my ($field,$subf,$ws) = ($1,$2,$3);
+            my $subf_data;
+            my ($itemtag, $itemsubfieldcode) = &GetMarcFromKohaField("items.itemnumber",'');
+            my @marcfield = $record->field($field);
+            if(@marcfield) {
+                if($field eq $itemtag) {  # item-level data, we need to get the right item.
+                    foreach my $itemfield (@marcfield) {
+                        if ( $itemfield->subfield($itemsubfieldcode) eq $item->{'itemnumber'} ) {
+                            $datastring .= $itemfield->subfield($subf ) . $ws;
+                            last;
+                        }
+                    }
+                } else {  # bib-level data, we'll take the first matching tag/subfield.
+                    $datastring .= $marcfield[0]->subfield($subf) . $ws ;
                 }
             }
             $f = $';
@@ -853,9 +866,11 @@ warn Dumper($kohatables);
     return $datastring;
 }
 
-=head descKohaTables
+=head2 descKohaTables
+
 Return a hashref of an array of hashes,
 with name,type keys.
+
 =cut
 
 sub _descKohaTables {
@@ -979,7 +994,7 @@ sub split_fcn {
     # Split fiction call numbers based on spaces
     SPLIT_FCN:
     while ($fcn) {
-        if ($fcn =~ m/([A-Za-z0-9]+)(\W?).*?/x) {
+        if ($fcn =~ m/([A-Za-z0-9]+\.?[0-9]?)(\W?).*?/x) {
             push (@fcn_split, $1);
             $fcn = $';
         }
@@ -1083,6 +1098,7 @@ sub DrawSpineText {
             }
             # loop for each string line
             foreach my $str (@strings) {
+                next if $str eq '';
                 my $hPos = 0;
                 my $stringwidth = prStrWidth($str, $fontname, $fontsize);
                 if ( $$conf_data->{'text_justify'} eq 'R' ) { 
@@ -1272,7 +1288,7 @@ sub DrawBarcode {
     warn "BAR_WDTH = $bar_width, TOT.BAR.LGHT=$tot_bar_length  R*TOT.BAR =$moo2" if $debug;
 }
 
-=item build_circ_barcode;
+=head2 build_circ_barcode;
 
   build_circ_barcode( $x_pos, $y_pos, $barcode,
                $barcodetype, \$item);
@@ -1568,7 +1584,7 @@ sub build_circ_barcode {
 
 }
 
-=item draw_boundaries
+=head2 draw_boundaries
 
  sub draw_boundaries ($x_pos_spine, $x_pos_circ1, $x_pos_circ2,
                 $y_pos, $spine_width, $label_height, $circ_width)  
@@ -1602,7 +1618,7 @@ sub draw_boundaries {
     }
 }
 
-=item drawbox
+=head2 drawbox
 
        sub drawbox {   $lower_left_x, $lower_left_y, 
                        $upper_right_x, $upper_right_y )
@@ -1640,8 +1656,6 @@ END { }    # module clean-up code here (global destructor)
 1;
 __END__
 
-=back
-
 =head1 AUTHOR
 
 Mason James <mason@katipo.co.nz>