koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] koha/cards createcards.pl [dev_week]


From: Kyle Hall
Subject: [Koha-cvs] koha/cards createcards.pl [dev_week]
Date: Thu, 08 May 2008 15:55:44 +0000

CVSROOT:        /sources/koha
Module name:    koha
Branch:         dev_week
Changes by:     Kyle Hall <kylemhall>   08/05/08 15:55:44

Modified files:
        cards          : createcards.pl 

Log message:
        Lots of updates.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/cards/createcards.pl?cvsroot=koha&only_with_tag=dev_week&r1=1.1.2.2&r2=1.1.2.3

Patches:
Index: createcards.pl
===================================================================
RCS file: /sources/koha/koha/cards/Attic/createcards.pl,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -b -r1.1.2.2 -r1.1.2.3
--- createcards.pl      16 Apr 2008 11:43:17 -0000      1.1.2.2
+++ createcards.pl      8 May 2008 15:55:44 -0000       1.1.2.3
@@ -8,24 +8,25 @@
 use PDF::Reuse;
 use MARC::Record;
 use CGI;
+use Roman;
 
-use constant Y_TOP    => 765;
-use constant Y_OFFSET => 210;
+use constant Y_TOP    => 740; ## Top of first card
+use constant Y_OFFSET => 220; ## Distance between the tops of each card
 
-use constant X_LEFT     => 130;
-use constant X_INDENTED => X_LEFT + 50;
-use constant X_CENTER   => 325;
-use constant X_RIGHT    => 455;
+use constant X_LEFT     => 130; ## The left edge of the card
+use constant X_INDENTED => X_LEFT + 50; ## The left edge of the text
+use constant X_CENTER   => 325; ## The horizontal center of the card
+use constant X_RIGHT    => 455;  ## The right-hand edge of the card
 
-use constant INDENT => 15;
+use constant INDENT => 15; ## The distance an indent represents
 
-use constant FH => 12;    ## Font Height
+use constant FH => 10;    ## Font Height
 
-use constant MAX_LINES => 15;
+use constant MAX_LINES => 18; ## Total lines per card
 use constant STARTING_LINE => 2;
 
-use constant MAX_STRING_WIDTH     => 50;
-use constant MAX_CALLNUMBER_WIDTH => 5;
+use constant MAX_STRING_WIDTH     => 55; ## Max number of characters per line
+use constant MAX_CALLNUMBER_WIDTH => 5; ## The max characters per line for the 
callnumber
 
 my $dbh = C4::Context->dbh;
 
@@ -33,11 +34,24 @@
 my $barcodeStart = $input->param('barcodeStart');
 my $barcodeEnd   = $input->param('barcodeEnd');
 
+if ( ! $barcodeEnd ) {
+  $barcodeEnd = $barcodeStart;
+}
+
+my $printMainEntry   = $input->param('printMainEntry');
+my $printShelf   = $input->param('printShelf');
+my $printAuthor   = $input->param('printAuthor');
+my $printSubject   = $input->param('printSubject');
+my $printTitle   = $input->param('printTitle');
+
+## Outputing a PDF file directly to the browser
 prInitVars();
 $| = 1;
 print STDOUT "Content-Disposition: attachment;filename=\"cards.pdf\"\n";
 print STDOUT "Content-Type: application/pdf \r\n\r\n";
 prFile();
+#prFont('Courier');
+prFontSize( FH );
 
 my $currentCard = 1;
 for ( my $barcode = $barcodeStart ; $barcode <= $barcodeEnd ; $barcode++ ) {
@@ -50,38 +64,64 @@
     $sth->execute($barcode);
     my $item = $sth->fetchrow_hashref;
 
-    my @subjects = getSubjects($item);
+    my $marc = MARC::Record->new_from_usmarc( $item->{'marc'} );
 
+    ## Build the Tracings
     my $cardsList;
+    
+    my @subjects = getSubjects($item);
     my $i = 1;
     foreach my $subject (@subjects) {
         $cardsList .= "$i. $subject  ";
         $i++;
     }
-    $cardsList .= "I. Title";
+
+    my $romanNumeral = 1;
+    if ( defined( $marc->field('100') ) ) {
+      $cardsList .= Roman( $romanNumeral++ ) . ". Title ";
+    }
+
+    my @additionalAuthors = getAuthors($item);
+    foreach my $author (@additionalAuthors) {
+        $cardsList .= Roman( $romanNumeral++ ) . ". $author  ";
+    }
+
 
     ## Main Entry Card
-    $currentCard = createCard( $item, $currentCard,
-        $cardsList );
+    if ( $printMainEntry ) {
+      $currentCard = createCard( $item, $currentCard, $cardsList );
+    }
 
+    if ( $printShelf ) {
     $currentCard = createShelfCard( $item, $currentCard, $cardsList );
+    }
 
+    if ( $printTitle ) {
     if ( $item->{'author'} ) { ## If we have an author, we need a Title Card
       $currentCard = createCard( $item, $currentCard, $cardsList, 
$item->{'title'} );
     }
 
+      ## Additional Title      
+      if ( $marc->field('740') && $marc->field('740')->subfield("a") ) {
+        $currentCard = createCard( $item, $currentCard, $cardsList, 
$marc->field('740')->subfield("a") );
+      }      
+    }
+
     ## Need a Subject Card for each subject
+    if ( $printSubject ) {
     foreach my $subject (@subjects) {
         $currentCard = createCard( $item, $currentCard,
-            $cardsList, $subject );
+              $cardsList, uc($subject) );
+      }
     }
     
     ## Additional Author Cards
-    my $marc = MARC::Record->new_from_usmarc( $item->{'marc'} );
+    if ( $printAuthor ) {
     my @authors = $marc->field('700');
     foreach my $author ( @authors ) {
       $currentCard = createCard( $item, $currentCard, $cardsList, 
$author->subfield('a') );
     }
+    }
 }
 
 prEnd();
@@ -101,6 +141,12 @@
         $line .= $item->{'title'};    ## Title
     }
 
+    ## Subtitle i.e. Remainder of title
+    if ( $marc->field('245') && $marc->field('245')->subfield("b") ) {
+        $line .= ' ' . $marc->field('245')->subfield("b");
+    }
+
+
     ## Statement of responsibility, etc.
     if ( $marc->field('245') && $marc->field('245')->subfield("c") ) {
         $line .= " / ";               ## Separator
@@ -109,6 +155,8 @@
           ;                           ## Statement of responsibility, etc.
     }
 
+
+
     ## Edition
     if ( $marc->field('250') && $marc->field('250')->subfield("a") ) {
         $line .= " -- ";                               ## Separator
@@ -122,7 +170,7 @@
     ## Copyright
     if ( $marc->field('260') && $marc->field('260')->subfield("c") ) {
         $line .= ", ";
-        $line .= "c" . $marc->field('260')->subfield("c") . ".";
+        $line .= $marc->field('260')->subfield("c") . ".";
     }
 
     push( @lines, $line );
@@ -140,6 +188,94 @@
 
     push( @lines, $line );
 
+    ## 500 General Note
+    $line = '';
+    my $numberOfFields = 0;
+    my @fields = $marc->field('500');
+    foreach my $field ( @fields ) {
+      if ( ++$numberOfFields > 1 ) { $line .= ' -- '; }
+
+      my $numberOfaFields = 0;
+      my @a_fields = $field->subfield('a');
+      foreach my $a_field ( @a_fields ) {
+        if ( ++$numberOfaFields > 1 ) { $line .= ' -- '; }      
+        $line .= defined ( $a_field ) ? " " . $a_field : '';
+      }
+
+    }    
+    if ( @fields ) { 
+      $line .= '.';
+      push( @lines, $line );
+    }
+
+    ## 504 Bibliography, etc.. Note
+    $line = '';
+    my $numberOfFields = 0;
+    my @fields = $marc->field('504');
+    foreach my $field ( @fields ) {
+      if ( ++$numberOfFields > 1 ) { $line .= ' -- '; }
+      $line .= defined ( $field->subfield('a') ) ? $field->subfield('a') : '';
+    }    
+    if ( @fields ) { 
+      $line .= '.';
+      push( @lines, $line );
+    }
+
+    ## 505 -FORMATTED CONTENTS NOTE
+    $line = '';
+    my $numberOfFields = 0;
+    my @fields = $marc->field('505');
+    foreach my $field ( @fields ) {
+      if ( ++$numberOfFields > 1 ) { $line .= ' -- '; }
+      $line .= defined ( $field->subfield('a') ) ? $field->subfield('a') : '';
+      $line .= defined ( $field->subfield('g') ) ? " " . $field->subfield('g') 
: '';
+
+      my $numberOftFields = 0;
+      my @t_fields = $field->subfield('t');
+      foreach my $t_field ( @t_fields ) {
+        if ( ++$numberOftFields > 1 ) { $line .= ' -- '; }      
+        $line .= defined ( $t_field ) ? " " . $t_field : '';
+      }
+
+      my $numberOfrFields = 0;
+      my @r_fields = $field->subfield('r');
+      foreach my $r_field ( @r_fields ) {
+        if ( ++$numberOfrFields > 1 ) { $line .= ' -- '; }      
+        $line .= defined ( $r_field ) ? " " . $r_field : '';
+      }
+    }    
+    if ( @fields ) { 
+      $line .= '.';
+      push( @lines, $line );
+    }
+
+    ## 520 Summary, Etc. Note
+    $line = '';
+    my $numberOfFields = 0;
+    my @fields = $marc->field('520');
+    foreach my $field ( @fields ) {
+      if ( ++$numberOfFields > 1 ) { $line .= ' -- '; }
+      $line .= defined ( $field->subfield('a') ) ? $field->subfield('a') : '';
+    }    
+    if ( @fields ) { 
+      $line .= '.';
+      push( @lines, $line );
+    }
+
+    ## 586 Awards Note
+    $line = '';
+    my $numberOfFields = 0;
+    my @fields = $marc->field('586');
+    foreach my $field ( @fields ) {
+      if ( ++$numberOfFields > 1 ) { $line .= ' -- '; }
+      $line .= defined ( $field->subfield('a') ) ? $field->subfield('a') : '';
+    }    
+    if ( @fields ) { 
+      $line .= '.';
+      push( @lines, $line );
+    }
+
+
     return @lines;
 }
 
@@ -193,7 +329,17 @@
     push( @abstract, $item->{'abstract'} );
     ( $cardNumber, $line ) = printLines( $cardNumber, $line, $indentStyle = 
'none', $item, $header, @abstract );
 
-    ( $cardNumber, $line ) = printLine( 'ISBN: ' . $item->{'isbn'}, 
$cardNumber, $line, my $indent = 1, $item, $header );
+    my $marc = MARC::Record->new_from_usmarc( $item->{'marc'} );
+    my @isbns = $marc->field('020');
+    my $isbnCount = 0;
+    my $isbnLine = 'ISBN: ';
+    foreach my $isbn ( @isbns ) {
+      if ( ++$isbnCount > 1 ) {
+        $isbnLine .= " | ";
+      }
+      $isbnLine .= $isbn->subfield('a');
+    }
+    ( $cardNumber, $line ) = printLine( $isbnLine, $cardNumber, $line, my 
$indent = 1, $item, $header );
 
     $line++;
     my @cardsList;
@@ -318,7 +464,7 @@
     my ( $item, $cardNumber ) = @_;
     my @lines = split( / /, $item->{'itemcallnumber'} );
 
-    my $l = 0;
+    my $l = STARTING_LINE;
     foreach my $line (@lines) {
         my @lines;
         while ( length($line) > 0 ) {
@@ -358,20 +504,110 @@
 sub getSubjects {
     my ($item) = @_;
 
-    my $dbh = C4::Context->dbh;
-    my $sth =
-      $dbh->prepare(
-"SELECT subject FROM bibliosubject WHERE biblionumber = ? ORDER BY subject"
-      );
-    $sth->execute( $item->{'biblionumber'} );
+    my $marc = MARC::Record->new_from_usmarc( $item->{'marc'} );
     my @subjects;
-    while ( my $subject = $sth->fetchrow_hashref ) {
-        push( @subjects, $subject->{'subject'} );
+
+    my @fields = $marc->field('600');
+    foreach my $field ( @fields ) {
+      my $subject;
+      $subject .= defined ( $field->subfield('a') ) ? $field->subfield('a') : 
'';
+      $subject .= defined ( $field->subfield('q') ) ? " " . 
$field->subfield('q') : '';
+      $subject .= defined ( $field->subfield('d') ) ? " " . 
$field->subfield('d') : '';
+      $subject .= defined ( $field->subfield('v') ) ? " -- " . 
$field->subfield('v') : '';
+      $subject .= '.';
+      push( @subjects, $subject );
+    }
+
+    ## 610 Subject Added Entry -- Corporate Name
+    my @fields = $marc->field('610');
+    foreach my $field ( @fields ) {
+      my $subject;
+      $subject .= defined ( $field->subfield('a') ) ? $field->subfield('a') : 
'';
+      $subject .= defined ( $field->subfield('b') ) ? " " . 
$field->subfield('b') : '';
+      $subject .= defined ( $field->subfield('t') ) ? " " . 
$field->subfield('t') : '';
+      $subject .= defined ( $field->subfield('v') ) ? " -- " . 
$field->subfield('v') : '';
+      $subject .= defined ( $field->subfield('x') ) ? " -- " . 
$field->subfield('x') : '';
+      $subject .= defined ( $field->subfield('y') ) ? " -- " . 
$field->subfield('y') : '';
+      $subject .= defined ( $field->subfield('z') ) ? " -- " . 
$field->subfield('z') : '';
+      $subject .= '.';
+      push( @subjects, $subject );
+    }
+    
+    ## 650 Subject Added Entry - Topical Term
+    @fields = $marc->field('650');
+    foreach my $field ( @fields ) {
+      my $subject;
+      $subject .= defined ( $field->subfield('a') ) ? $field->subfield('a') : 
'';
+      $subject .= defined ( $field->subfield('z') ) ? " -- " . 
$field->subfield('z') : '';
+      $subject .= defined ( $field->subfield('v') ) ? " -- " . 
$field->subfield('v') : '';
+      $subject .= defined ( $field->subfield('x') ) ? " -- " . 
$field->subfield('x') : '';
+      $subject .= defined ( $field->subfield('y') ) ? " -- " . 
$field->subfield('y') : '';
+      $subject .= '.';
+      push( @subjects, $subject );
+    }
+
+    ## 651 Subject Added Entry - Geographic Name
+    @fields = $marc->field('651');
+    foreach my $field ( @fields ) {
+      my $subject;
+      $subject .= defined ( $field->subfield('a') ) ? $field->subfield('a') : 
'';
+      $subject .= defined ( $field->subfield('z') ) ? " -- " . 
$field->subfield('z') : '';
+      $subject .= defined ( $field->subfield('v') ) ? " -- " . 
$field->subfield('v') : '';
+      $subject .= defined ( $field->subfield('x') ) ? " -- " . 
$field->subfield('x') : '';
+      $subject .= defined ( $field->subfield('y') ) ? " -- " . 
$field->subfield('y') : '';
+      $subject .= '.';
+      push( @subjects, $subject );
     }
 
     return @subjects;
 }
 
+sub getAuthors {
+    my ($item) = @_;
+
+    my $marc = MARC::Record->new_from_usmarc( $item->{'marc'} );
+    my @authors;
+
+    ## 700 Added Entry - Personal Name
+    my @fields = $marc->field('700');
+    foreach my $field ( @fields ) {
+      my $author;
+      $author .= defined ( $field->subfield('a') ) ? $field->subfield('a') : 
'';
+      $author .= defined ( $field->subfield('q') ) ? $field->subfield('q') : 
'';
+      $author .= defined ( $field->subfield('b') ) ? $field->subfield('b') : 
'';
+      $author .= defined ( $field->subfield('c') ) ? $field->subfield('c') : 
'';
+      $author .= defined ( $field->subfield('d') ) ? $field->subfield('d') : 
'';
+      $author .= defined ( $field->subfield('e') ) ? $field->subfield('e') : 
'';            
+      $author .= defined ( $field->subfield('t') ) ? $field->subfield('t') : 
'';
+      push( @authors, $author );
+    }
+
+    ## 710 Added Entry - Corporate Name
+    my @fields = $marc->field('710');
+    foreach my $field ( @fields ) {
+      my $author;
+      $author .= defined ( $field->subfield('a') ) ? $field->subfield('a') : 
'';
+      $author .= defined ( $field->subfield('b') ) ? $field->subfield('b') : 
'';
+      $author .= defined ( $field->subfield('e') ) ? $field->subfield('e') : 
'';            
+      $author .= defined ( $field->subfield('t') ) ? $field->subfield('t') : 
'';
+      push( @authors, $author );
+    }
+
+    ## 740 Added Entry - Uncontrolled Related / Analytical Title
+    my @fields = $marc->field('740');
+    foreach my $field ( @fields ) {
+      my $author;
+      $author .= defined ( $field->subfield('a') ) ? $field->subfield('a') : 
'';
+      $author .= defined ( $field->subfield('n') ) ? $field->subfield('n') : 
'';
+      $author .= defined ( $field->subfield('p') ) ? $field->subfield('p') : 
'';            
+      $author .= defined ( $field->subfield('h') ) ? $field->subfield('h') : 
'';
+      push( @authors, $author );
+    }
+
+    return @authors;
+}
+
+
 # Perl trim function to remove whitespace from the start and end of the string
 sub trim($) {
     my $string = shift;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]