adding minor features to barcode generator :
authortipaul <tipaul>
Tue, 19 Oct 2004 11:50:18 +0000 (11:50 +0000)
committertipaul <tipaul>
Tue, 19 Oct 2004 11:50:18 +0000 (11:50 +0000)
- possibility to print continuous barcodes numbers, but not from items
- possibility to replace the title/author by a manually typed text under the barcode itself.

barcodes/barcodes.pl
barcodes/barcodesGenerator.pl
koha-tmpl/intranet-tmpl/default/en/barcodes/barcodes-top.inc
koha-tmpl/intranet-tmpl/default/en/barcodes/barcodes.tmpl

index fb6b3c6..70f95de 100755 (executable)
@@ -82,7 +82,7 @@ my $input = new CGI;
 my @labelTable = C4::Barcodes::PrinterConfig::labelsPage($labelConfig{'rows'}, $labelConfig{'columns'});
 
 # It creates a list of posible intervals to choose codes to generate
-my %list = ('continuous' => 'Continuous Range', 'individuals' => 'Individual Codes');
+my %list = ('continuous' => 'Continuous Range of items', 'individuals' => 'Individual Codes', 'continuous2' => 'Continuous range (from - to)');
 my @listValues = keys(%list);
 my $rangeType = CGI::scrolling_list(-name => 'rangeType',
                                        -values => \@listValues,
index 867f9ee..808227d 100755 (executable)
@@ -85,9 +85,11 @@ my $cgi = new CGI;
 my $from = $cgi->param('from');
 my $to = $cgi->param('to');
 my $individualCodes = $cgi->param('individualCodes');
+my $rangeType = $cgi->param('rangeType');
 my $pageType = $cgi->param('pages');
 my $label = $cgi->param('label');
 my $numbersystem = $cgi->param('numbersystem');
+my $text_under_label = $cgi->param('text_under_label');
 
 # Generate the checksum from an inventary code
 sub checksum {
@@ -135,86 +137,150 @@ sub assingFilename {
 # Takes inventary codes from database and if they are between
 # the interval specify by parameters, it generates the correspond barcodes
 sub barcodesGenerator {
-  my ($from, $to, $individualCodes) = @_;
-  # Returns a database handler
-  my $dbh = C4::Context->dbh;
-  # Create the query to database
-  my $rangeCondition;
-  if ($individualCodes ne "") {
-    $rangeCondition = "AND (I.barcode IN " . $individualCodes . ")";
-  } else {
-    $rangeCondition =  "AND (I.barcode >= " . $from . " AND I.barcode <="  . $to . " )";
-  }
-        
-  my $query = "SELECT CONCAT('$numbersystem',REPEAT('0',((12 - LENGTH('$numbersystem')) - LENGTH(I.barcode))), I.barcode) AS Codigo, B.title, B.author FROM biblio B, items I WHERE (I.biblionumber = B.biblioNumber ) " .$rangeCondition. " AND (I.barcode <> 'FALTA') ORDER BY Codigo";
-  
-  # Prepare the query
-  my $sth = $dbh->prepare($query);
-  # Executes the query
-  $sth->execute;
-  if ($sth->rows) { # There are inventary codes
-       # Set the temp directory for pdf´s files
-       if (!defined($ENV{'TEMP'})) {
-               $ENV{'TEMP'} = '/tmp/';
-       }       
+       my ($from, $to, $rangeType, $individualCodes,$text_under_label) = @_;
+       # Returns a database handler
+       my $dbh = C4::Context->dbh;
+       # Create the query to database
        # Assigns a temporary filename for the pdf file
-       my $tmpFileName = &assingFilename($from, $to);
-       $tmpFileName = $ENV{'TEMP'}.$tmpFileName;
-    # Creates a PDF object
-    my $pdf = PDF::API2->new(-file => $tmpFileName);
-    # Set the positions where barcodes are going to be placed
-       C4::Barcodes::PrinterConfig::setPositionsForX($labelConfig{'marginLeft'}, $labelConfig{'labelWidth'}, $labelConfig{'columns'}, $labelConfig{'pageType'});
-       C4::Barcodes::PrinterConfig::setPositionsForY($labelConfig{'marginBottom'}, $labelConfig{'labelHeigth'}, $labelConfig{'rows'}, $labelConfig{'pageType'});
-    # Creates a font object
-    my $tr = $pdf->corefont('Helvetica-Bold');
-    # Barcode position
-       my ($page, $gfx, $text);
-    while (my ($code,$title,$author) = $sth->fetchrow_array) {
-      # Generetase checksum
-      $code = &checksum($code);
-      # Generate the corresponde barcode to $code
-      my $barcode = $pdf->barcode(-font => $tr,        # The font object to use
-                                     -type => 'ean13', # Standard of codification
-                                     -code => $code, # Text to codify
-                                     -extn     => '012345',    # Barcode extension (if it is aplicable)
-                                     -umzn => 10,              # Top limit of the finished bar
-                                     -lmzn => 10,              # Bottom limit of the finished bar
-                                     -zone => 15,              # Bars size
-                                         -quzn => 0,           # Space destinated for legend
-                                     -ofwt => 0.01,    # Bars width
-                                         -fnsz => 8,           # Font size
-                                         -text => ''
-                                    );
-       
-         (my $x, my $y, $pdf, $page, $gfx, $text, $tr, $label) = C4::Barcodes::PrinterConfig::getLabelPosition(
-                                                                                                                                                               $label, 
-                                                                                                                                               $pdf, 
-                                                                                                                                                               $page,
-                                                                                                                                                               $gfx,
-                                                                                                                                                               $text,
-                                                                                                                                                               $tr,
-                                                                                                                                                               $pageType);     
-      # Assigns a barcodes to $gfx
-         $gfx->barcode($barcode, $x, $y , (72/$labelConfig{'systemDpi'}));
-      # Assigns the additional information to the barcode (Legend)
-         $text->translate($x - 48, $y - 22);
-      $text->text(substr $title, 0, 30);
-      $text->translate($x - 48, $y - 29);
-      $text->text(substr $author, 0, 30);
-    }
-    # Writes the objects added in $gfx to $page
-    $pdf->finishobjects($page,$gfx, $text);
-    # Save changes to the PDF
-    $pdf->saveas;
-    # Close the conection with the PDF file
-    $pdf->end;
-    # Show the PDF file
-    print $cgi->redirect("/cgi-bin/koha/barcodes/pdfViewer.pl?tmpFileName=$tmpFileName");
-  } else {
-       # Rollback and shows the error legend
-    print $cgi->redirect("/cgi-bin/koha/barcodes/barcodes.pl?error=1");
-  }
-  $sth->finish;
+       my $tmpFileName = &assingFilename($from, $to);
+       if ($rangeType eq 'continuous2') {
+               # Set the temp directory for pdf´s files
+               if (!defined($ENV{'TEMP'})) {
+                       $ENV{'TEMP'} = '/tmp/';
+               }       
+               $tmpFileName = $ENV{'TEMP'}.$tmpFileName;
+               # Creates a PDF object
+               my $pdf = PDF::API2->new(-file => $tmpFileName);
+               # Set the positions where barcodes are going to be placed
+               C4::Barcodes::PrinterConfig::setPositionsForX($labelConfig{'marginLeft'}, $labelConfig{'labelWidth'}, $labelConfig{'columns'}, $labelConfig{'pageType'});
+               C4::Barcodes::PrinterConfig::setPositionsForY($labelConfig{'marginBottom'}, $labelConfig{'labelHeigth'}, $labelConfig{'rows'}, $labelConfig{'pageType'});
+               # Creates a font object
+               my $tr = $pdf->corefont('Helvetica-Bold');
+               # Barcode position
+               my ($page, $gfx, $text);
+               for (my $code=$from; $code<=$to; $code++) {
+                       # Generetase checksum
+                       my $codeC = &checksum($code);
+                       # Generate the corresponde barcode to $code
+                       my $barcode = $pdf->barcode(-font => $tr,       # The font object to use
+                                                                               -type => 'ean13',       # Standard of codification
+                                                                               -code => $codeC, # Text to codify
+                                                                               -extn   => '012345',    # Barcode extension (if it is aplicable)
+                                                                               -umzn => 10,            # Top limit of the finished bar
+                                                                               -lmzn => 10,            # Bottom limit of the finished bar
+                                                                               -zone => 15,            # Bars size
+                                                                               -quzn => 0,             # Space destinated for legend
+                                                                               -ofwt => 0.01,  # Bars width
+                                                                               -fnsz => 8,             # Font size
+                                                                               -text => ''
+                                                                               );
+                       
+                       (my $x, my $y, $pdf, $page, $gfx, $text, $tr, $label) = C4::Barcodes::PrinterConfig::getLabelPosition(
+                                                                                                                                                                               $label, 
+                                                                                                                                                                               $pdf, 
+                                                                                                                                                                               $page,
+                                                                                                                                                                               $gfx,
+                                                                                                                                                                               $text,
+                                                                                                                                                                               $tr,
+                                                                                                                                                                               $pageType);     
+                       # Assigns a barcodes to $gfx
+                       $gfx->barcode($barcode, $x, $y , (72/$labelConfig{'systemDpi'}));
+                       # Assigns the additional information to the barcode (Legend)
+                       $text->translate($x - 48, $y - 22);
+                       if ($text_under_label) {
+                               $text->text($text_under_label);
+                       }
+               }
+               # Writes the objects added in $gfx to $page
+               $pdf->finishobjects($page,$gfx, $text);
+               # Save changes to the PDF
+               $pdf->saveas;
+               # Close the conection with the PDF file
+               $pdf->end;
+               # Show the PDF file
+               print $cgi->redirect("/cgi-bin/koha/barcodes/pdfViewer.pl?tmpFileName=$tmpFileName");
+       } else {
+               my $rangeCondition;
+               if ($individualCodes ne "") {
+                       $rangeCondition = "AND (I.barcode IN " . $individualCodes . ")";
+               } else {
+                       $rangeCondition =  "AND (I.barcode >= " . $from . " AND I.barcode <="  . $to . " )";
+               }
+                       
+               my $query = "SELECT CONCAT('$numbersystem',REPEAT('0',((12 - LENGTH('$numbersystem')) - LENGTH(I.barcode))), I.barcode) AS Codigo, B.title, B.author FROM biblio B, items I WHERE (I.biblionumber = B.biblioNumber ) " .$rangeCondition. " AND (I.barcode <> 'FALTA') ORDER BY Codigo";
+               
+               # Prepare the query
+               my $sth = $dbh->prepare($query);
+               # Executes the query
+               $sth->execute;
+               if ($sth->rows) { # There are inventary codes
+                       # Set the temp directory for pdf´s files
+                       if (!defined($ENV{'TEMP'})) {
+                               $ENV{'TEMP'} = '/tmp/';
+                       }       
+                       # Assigns a temporary filename for the pdf file
+                       my $tmpFileName = &assingFilename($from, $to);
+                       $tmpFileName = $ENV{'TEMP'}.$tmpFileName;
+                       # Creates a PDF object
+                       my $pdf = PDF::API2->new(-file => $tmpFileName);
+                       # Set the positions where barcodes are going to be placed
+                       C4::Barcodes::PrinterConfig::setPositionsForX($labelConfig{'marginLeft'}, $labelConfig{'labelWidth'}, $labelConfig{'columns'}, $labelConfig{'pageType'});
+                       C4::Barcodes::PrinterConfig::setPositionsForY($labelConfig{'marginBottom'}, $labelConfig{'labelHeigth'}, $labelConfig{'rows'}, $labelConfig{'pageType'});
+                       # Creates a font object
+                       my $tr = $pdf->corefont('Helvetica-Bold');
+                       # Barcode position
+                       my ($page, $gfx, $text);
+                       while (my ($code,$title,$author) = $sth->fetchrow_array) {
+                               # Generetase checksum
+                               $code = &checksum($code);
+                               # Generate the corresponde barcode to $code
+                               my $barcode = $pdf->barcode(-font => $tr,       # The font object to use
+                                                                                       -type => 'ean13',       # Standard of codification
+                                                                                       -code => $code, # Text to codify
+                                                                                       -extn   => '012345',    # Barcode extension (if it is aplicable)
+                                                                                       -umzn => 10,            # Top limit of the finished bar
+                                                                                       -lmzn => 10,            # Bottom limit of the finished bar
+                                                                                       -zone => 15,            # Bars size
+                                                                                       -quzn => 0,             # Space destinated for legend
+                                                                                       -ofwt => 0.01,  # Bars width
+                                                                                       -fnsz => 8,             # Font size
+                                                                                       -text => ''
+                                                                                       );
+                               
+                               (my $x, my $y, $pdf, $page, $gfx, $text, $tr, $label) = C4::Barcodes::PrinterConfig::getLabelPosition(
+                                                                                                                                                                                       $label, 
+                                                                                                                                                                                       $pdf, 
+                                                                                                                                                                                       $page,
+                                                                                                                                                                                       $gfx,
+                                                                                                                                                                                       $text,
+                                                                                                                                                                                       $tr,
+                                                                                                                                                                                       $pageType);     
+                               # Assigns a barcodes to $gfx
+                               $gfx->barcode($barcode, $x, $y , (72/$labelConfig{'systemDpi'}));
+                               # Assigns the additional information to the barcode (Legend)
+                               $text->translate($x - 48, $y - 22);
+                               if ($text_under_label) {
+                                       $text->text($text_under_label);
+                               } else {
+                                       $text->text(substr $title, 0, 30);
+                                       $text->translate($x - 48, $y - 29);
+                                       $text->text(substr $author, 0, 30);
+                               }
+                       }
+                       # Writes the objects added in $gfx to $page
+                       $pdf->finishobjects($page,$gfx, $text);
+                       # Save changes to the PDF
+                       $pdf->saveas;
+                       # Close the conection with the PDF file
+                       $pdf->end;
+                       # Show the PDF file
+                       print $cgi->redirect("/cgi-bin/koha/barcodes/pdfViewer.pl?tmpFileName=$tmpFileName");
+               } else {
+                       # Rollback and shows the error legend
+                       print $cgi->redirect("/cgi-bin/koha/barcodes/barcodes.pl?error=1");
+               }
+       $sth->finish;
+       }
 }
 
-barcodesGenerator($from, $to, $individualCodes);
\ No newline at end of file
+barcodesGenerator($from, $to, $rangeType, $individualCodes,$text_under_label);
\ No newline at end of file
index 28d7f01..5cf8f58 100644 (file)
@@ -102,7 +102,7 @@ function emptyField (field) {
 \r
 function checkFields (aForm) {\r
   var option = document.getElementById('rangeType').value;\r
-  if (option == 'continuous') {\r
+  if (option == 'continuous' || option == 'continuous2') {\r
        if (emptyField(aForm.from.value) || emptyField(aForm.to.value)) {\r
                alert("Please, complete all fields");\r
            return false;\r
index 16557e5..fa4d395 100644 (file)
@@ -63,7 +63,7 @@
                        <!-- TMPL_IF NAME="ERROR" -->\r
                        <tr align="center">\r
                                <td colspan="2" >\r
-                                       <p style="font-size:13pt;color:red">Can´t find inventary codes on that range. Please try again.</p>\r
+                                       <p style="font-size:13pt;color:red">Can't find inventary codes on that range. Please try again.</p>\r
                                </td>\r
                        </tr>\r
                        <!-- /TMPL_IF -->\r
                                                </tr>\r
                                        </table>\r
                                </td>\r
-                       </tr>   \r
+                       </tr>\r
+                       <tr> \r
+                               <td align="right" style="padding-left:20px">Text under label</td>\r
+                               <td>\r
+                                       <input type="text" name="text_under_label" size="40" value="<!-- TMPL_VAR name="text_under_label -->"> If this field is empty, author and title will be put instead\r
+                               </td>\r
+                       </tr>\r
                        <tr valign="top">\r
                            <td colspan="2" align="center">\r
                                <table style='width:50%'>\r