koha-cvs
[Top][All Lists]
Advanced

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

[Koha-cvs] koha/C4 Labels.pm [rel_2_2]


From: Mason James
Subject: [Koha-cvs] koha/C4 Labels.pm [rel_2_2]
Date: Mon, 16 Jul 2007 21:13:55 +0000

CVSROOT:        /sources/koha
Module name:    koha
Branch:         rel_2_2
Changes by:     Mason James <sushi>     07/07/16 21:13:54

Modified files:
        C4             : Labels.pm 

Log message:
        rewinding rel_2_2 barcodes back to pre-july07 LibLime dev work.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Labels.pm?cvsroot=koha&only_with_tag=rel_2_2&r1=1.3.2.6&r2=1.3.2.7

Patches:
Index: Labels.pm
===================================================================
RCS file: /sources/koha/koha/C4/Labels.pm,v
retrieving revision 1.3.2.6
retrieving revision 1.3.2.7
diff -u -b -r1.3.2.6 -r1.3.2.7
--- Labels.pm   11 Jul 2007 12:55:39 -0000      1.3.2.6
+++ Labels.pm   16 Jul 2007 21:13:54 -0000      1.3.2.7
@@ -22,11 +22,10 @@
 
 use vars qw($VERSION @ISA @EXPORT);
 
+#use Data::Dumper;
 use PDF::Reuse;
 use Text::Wrap;
 use Algorithm::CheckDigits;
-# use Data::Dumper;
-# use Smart::Comments;
 
 $VERSION = 0.01;
 
@@ -50,18 +49,7 @@
   &CreateTemplate &SetActiveTemplate
   &SaveConf &DrawSpineText &GetTextWrapCols
   &GetUnitsValue &DrawBarcode
-  &get_printingtypes
-  &get_layouts
-  &get_barcode_types
-  &get_batches &delete_batch
-  &add_batch &SetFontSize &printText
-  &GetItemFields
-  &get_text_fields
-  get_layout &save_layout
-  &set_active_layout &by_order
-  &build_text_dropbox
-  &delete_layout &get_active_layout
-&get_highest_batch
+
 );
 
 =item get_label_options;
@@ -76,7 +64,7 @@
 #'
 sub get_label_options {
     my $dbh    = C4::Context->dbh;
-    my $query2 = " SELECT * FROM labels_conf where active = 1";
+    my $query2 = " SELECT * FROM labels_conf LIMIT 1 ";
     my $sth    = $dbh->prepare($query2);
     $sth->execute();
     my $conf_data = $sth->fetchrow_hashref;
@@ -84,261 +72,6 @@
     return $conf_data;
 }
 
-sub get_layouts {
-
-## FIXME: this if/else could be compacted...
-    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;
-
-    # @resultsloop
-
-    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 ($layout_id) = @_;
-    my $dbh = C4::Context->dbh;
-
-    # get the actual items to be printed.
-    my $query = " Select * from labels_conf where active = 1";
-    my $sth   = $dbh->prepare($query);
-    $sth->execute();
-    my $data = $sth->fetchrow_hashref;
-    $sth->finish;
-    return $data;
-}
-
-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;
-
-    push( @printtypes, { code => 'BAR',    desc => "barcode" } );
-    push( @printtypes, { code => 'BIB',    desc => "biblio" } );
-    push( @printtypes, { code => 'BARBIB', desc => "barcode / biblio" } );
-    push( @printtypes, { code => 'BIBBAR', desc => "biblio / barcode" } );
-    push( @printtypes, { code => 'ALT',    desc => "alternating labels" } );
-
-    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'} = 'MOO';
-        }
-    }
-    return @printtypes;
-}
-
-sub build_text_dropbox {
-    my ($order) = @_;
-
-    #  my @fields      = get_text_fields();
-    #    my $field_count = scalar @fields;
-    my $field_count = 10;    # <-----------       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 );
-    }
-
-    # add a blank row too
-
-    return @lines;
-}
-
-sub get_text_fields {
-    my ($layout_id, $sorttype) = @_;
-
-    my ( $a, $b, $c, $d, $e, $f, $g, $h, $i );
-
-    my $sortorder = get_layout($layout_id);
-
-    # $sortorder
-
-    $a = {
-        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  => 'classification',
-        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'} };
-
-    my @text_fields = ( $a, $b, $c, $d, $e, $f, $g, $h, $i );
-
-    my @new_fields;
-    foreach my $field (@text_fields) {
-        push( @new_fields, $field ) if $field->{'order'} > 0;
-    }
-
-    my @sorted_fields = sort by_order @new_fields;
-
-    my $active_fields;
-    foreach my $field (@sorted_fields) {
-     $sorttype eq 'codes' ?   $active_fields .= "$field->{'code'} " :
-          $active_fields .= "$field->{'desc'} ";
-    }
-    return $active_fields;
-
-}
-
-sub by_order {
-    $$a{order} <=> $$b{order};
-}
-
-sub add_batch {
-    my $new_batch;
-    my $dbh = C4::Context->dbh;
-    my $q =
-      "select distinct batch_id from labels order by batch_id desc limit 1";
-    my $sth = $dbh->prepare($q);
-    $sth->execute();
-    my $data = $sth->fetchrow_hashref;
-    $sth->finish;
-
-    if ( !$data->{'batch_id'} ) {
-        $new_batch = 1;
-    }
-    else {
-        $new_batch = ( $data->{'batch_id'} + 1 );
-    }
-
-    return $new_batch;
-}
-
-
-sub get_highest_batch {
-    my $new_batch;
-    my $dbh = C4::Context->dbh;
-    my $q =
-      "select distinct batch_id from labels order by batch_id desc limit 1";
-    my $sth = $dbh->prepare($q);
-    $sth->execute();
-    my $data = $sth->fetchrow_hashref;
-    $sth->finish;
-
-    if ( !$data->{'batch_id'} ) {
-        $new_batch = 1;
-    }
-    else {
-        $new_batch =  $data->{'batch_id'};
-    }
-
-    return $new_batch;
-}
-
-
-sub get_batches {
-    my $dbh = C4::Context->dbh;
-    my $q   = "select distinct batch_id from labels";
-    my $sth = $dbh->prepare($q);
-    $sth->execute();
-    my @resultsloop;
-    while ( my $data = $sth->fetchrow_hashref ) {
-        push( @resultsloop, $data );
-    }
-    $sth->finish;
-
-    # adding a dummy batch=1 value , if none exists in the db
-    if ( !scalar(@resultsloop) ) {
-        push( @resultsloop, { batch_id => '1' } );
-    }
-    return @resultsloop;
-}
-
-sub delete_batch {
-    my ($batch_id) = @_;
-    my $dbh        = C4::Context->dbh;
-    my $q          = "DELETE FROM labels 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 => '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;
@@ -347,6 +80,7 @@
     $unitvalue = '2.83464567' if ( $units eq 'MM' );
     $unitvalue = '28.3464567' if ( $units eq 'CM' );
     $unitvalue = 72           if ( $units eq 'INCH' );
+    warn $units, $unitvalue;
     return $unitvalue;
 }
 
@@ -379,11 +113,11 @@
 }
 
 sub GetSingleLabelTemplate {
-    my ($tmpl_id) = @_;
+    my ($tmpl_code) = @_;
     my $dbh       = C4::Context->dbh;
-    my $query     = " SELECT * FROM labels_templates where tmpl_id = ?";
+    my $query       = " SELECT * FROM labels_templates where tmpl_code = ?";
     my $sth       = $dbh->prepare($query);
-    $sth->execute($tmpl_id);
+    $sth->execute($tmpl_code);
     my $template = $sth->fetchrow_hashref;
     $sth->finish;
     return $template;
@@ -392,7 +126,7 @@
 sub SetActiveTemplate {
 
     my ($tmpl_id) = @_;
-  
+    warn "TMPL_ID = $tmpl_id";
     my $dbh   = C4::Context->dbh;
     my $query = " UPDATE labels_templates SET active = NULL";
     my $sth   = $dbh->prepare($query);
@@ -404,36 +138,29 @@
     $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();
-
-    my $query = "UPDATE labels_conf SET active = 1 WHERE id = ?";
-    my $sth   = $dbh->prepare($query);
-    $sth->execute($layout_id);
-    $sth->finish;
-}
-
 sub DeleteTemplate {
-    my ($tmpl_id) = @_;
+    my ($tmpl_code) = @_;
     my $dbh       = C4::Context->dbh;
-    my $query     = " DELETE  FROM labels_templates where tmpl_id = ?";
+    my $query       = " DELETE  FROM labels_templates where tmpl_code = ?";
     my $sth       = $dbh->prepare($query);
-    $sth->execute($tmpl_id);
+    $sth->execute($tmpl_code);
     $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,      $fontsize,     $units
-    ) = @_;
+        $rowgap,      $active,      $fontsize,     $units
+      )
+      = @_;
+
+    warn "FONTSIZE =$fontsize";
+
+    #    warn Dumper @_;
+
     my $dbh = C4::Context->dbh;
     my $query =
       " UPDATE labels_templates SET tmpl_code=?, tmpl_desc=?, page_width=?,
@@ -450,6 +177,8 @@
         $fontsize,    $units,        $tmpl_id
     );
     $sth->finish;
+
+    SetActiveTemplate($tmpl_id) if ( $active eq '1' );
 }
 
 sub CreateTemplate {
@@ -458,8 +187,9 @@
         $tmpl_code,   $tmpl_desc,    $page_width, $page_height,
         $label_width, $label_height, $topmargin,  $leftmargin,
         $cols,        $rows,         $colgap,     $rowgap,
-        $fontsize,     $units
-    ) = @_;
+        $active,      $fontsize,     $units
+      )
+      = @_;
 
     my $dbh = C4::Context->dbh;
 
@@ -475,6 +205,24 @@
         $cols,        $rows,         $colgap,     $rowgap,
         $fontsize,    $units
     );
+
+    warn "ACTIVE = $active";
+
+    if ( $active eq '1' ) {
+
+  # get the tmpl_id of the newly created template, then call 
SetActiveTemplate()
+        my $query =
+          "SELECT tmpl_id from labels_templates order by tmpl_id desc limit 1";
+        my $sth = $dbh->prepare($query);
+        $sth->execute();
+
+        my $data    = $sth->fetchrow_hashref;
+        my $tmpl_id = $data->{'tmpl_id'};
+
+        SetActiveTemplate($tmpl_id);
+        $sth->finish;
+    }
+    return $tmpl_id;
 }
 
 sub GetAllLabelTemplates {
@@ -498,28 +246,28 @@
 sub SaveConf {
 
     my (
-        $barcodetype,  $title,          $isbn,       $issn,
-        $itemtype,     $bcn,            $dcn,        $classif,
-        $subclass,     $itemcallnumber, $author,     $tmpl_id,
-        $printingtype, $guidebox,       $startlabel, $layoutname
-    ) = @_;
+        $barcodetype,    $title,  $isbn,    $itemtype,
+        $bcn,            $dcn,    $classif, $subclass,
+        $itemcallnumber, $author, $tmpl_id, $printingtype,
+        $guidebox,       $startlabel
+      )
+      = @_;
 
     my $dbh    = C4::Context->dbh;
-    my $query2 = "update labels_conf set active = NULL";
+    my $query2 = "DELETE FROM labels_conf";
     my $sth2   = $dbh->prepare($query2);
     $sth2->execute();
     my $query2 = "INSERT INTO labels_conf
-            ( barcodetype, title, isbn,issn, itemtype, barcode,
+            ( barcodetype, title, isbn, itemtype, barcode,
               dewey, class, subclass, itemcallnumber, author, printingtype,
-                guidebox, startlabel, layoutname, active )
-               values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?, 1 )";
+                guidebox, startlabel )
+               values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
     my $sth2 = $dbh->prepare($query2);
     $sth2->execute(
-        $barcodetype, $title, $isbn, $issn,
-
-        $itemtype, $bcn,            $dcn,    $classif,
-        $subclass, $itemcallnumber, $author, $printingtype,
-        $guidebox, $startlabel,     $layoutname
+        $barcodetype,    $title,  $isbn,         $itemtype,
+        $bcn,            $dcn,    $classif,      $subclass,
+        $itemcallnumber, $author, $printingtype, $guidebox,
+        $startlabel
     );
     $sth2->finish;
 
@@ -527,36 +275,6 @@
     return;
 }
 
-sub save_layout {
-
-    my (
-        $barcodetype,  $title,          $isbn,       $issn,
-        $itemtype,     $bcn,            $dcn,        $classif,
-        $subclass,     $itemcallnumber, $author,     $tmpl_id,
-        $printingtype, $guidebox,       $startlabel, $layoutname,
-        $layout_id
-    ) = @_;
-### $layoutname
-### $layout_id
-
-    my $dbh    = C4::Context->dbh;
-    my $query2 = "update labels_conf set 
-             barcodetype=?, title=?, isbn=?,issn=?, 
-            itemtype=?, barcode=?,    dewey=?, class=?,
-             subclass=?, itemcallnumber=?, author=?,  printingtype=?,  
-               guidebox=?, startlabel=?, layoutname=? where id = ?";
-    my $sth2 = $dbh->prepare($query2);
-    $sth2->execute(
-        $barcodetype, $title,          $isbn,       $issn,
-        $itemtype,    $bcn,            $dcn,        $classif,
-        $subclass,    $itemcallnumber, $author,     $printingtype,
-        $guidebox,    $startlabel,     $layoutname, $layout_id
-    );
-    $sth2->finish;
-
-    return;
-}
-
 =item get_label_items;
 
         $options = get_label_items()
@@ -568,46 +286,28 @@
 
 #'
 sub get_label_items {
-    my ($batch_id) = @_;
     my $dbh = C4::Context->dbh;
 
-    my @resultsloop = ();
-    my $count;
+    # get the actual items to be printed.
     my @data;
-    my $sth;
-
-    if ($batch_id) {
-        my $query3 = "Select * from labels where batch_id = ? ";
-        $sth = $dbh->prepare($query3);
-        $sth->execute($batch_id);
-
-    }
-    else {
-
-        my $query3 = "Select * from labels";
-        $sth = $dbh->prepare($query3);
+    my $query3 = " Select * from labels ";
+    my $sth    = $dbh->prepare($query3);
         $sth->execute();
-    }
+    my @resultsloop;
     my $cnt = $sth->rows;
     my $i1  = 1;
     while ( my $data = $sth->fetchrow_hashref ) {
 
         # lets get some summary info from each item
-        my $query1 = " 
-            select * from biblio,biblioitems,items where itemnumber=? and 
+        my $query1 =
+          " select * from biblio, biblioitems, items where itemnumber = ? and
                 items.biblioitemnumber=biblioitems.biblioitemnumber and 
                 biblioitems.biblionumber=biblio.biblionumber";
 
         my $sth1 = $dbh->prepare($query1);
         $sth1->execute( $data->{'itemnumber'} );
-
         my $data1 = $sth1->fetchrow_hashref();
 
-        $data1->{'labelno'}  = $i1;
-        $data1->{'batch_id'} = $batch_id;
-        $data1->{'summary'} =
-          "$data1->{'barcode'}, $data1->{'title'}, $data1->{'isbn'}";
-
         push( @resultsloop, $data1 );
         $sth1->finish;
 
@@ -615,17 +315,6 @@
     }
     $sth->finish;
     return @resultsloop;
-
-}
-
-sub GetItemFields {
-    my @fields = qw (
-      barcode title
-      dewey isbn issn author classification
-      itemtype subclass itemcallnumber
-
-    );
-    return @fields;
 }
 
 sub DrawSpineText {
@@ -638,21 +327,13 @@
     $Text::Wrap::separator = "\n";
 
     my $str;
-    ##      $item
 
     my $top_text_margin = ( $fontsize + 3 );
     my $line_spacer = ($fontsize);    # number of pixels between text rows.
 
     # add your printable fields manually in here
-
-my $layout_id = $$conf_data->{'id'};
-
-#    my @fields = GetItemFields();
-
-my $str_fields = get_text_fields($layout_id, 'codes' );
-my @fields = split(/ /, $str_fields);
-### @fields
-
+    my @fields =
+      qw (dewey isbn classification itemtype subclass itemcallnumber);
     my $vPos   = ( $y_pos + ( $label_height - $top_text_margin ) );
     my $hPos   = ( $x_pos + $left_text_margin );
 
@@ -661,9 +342,6 @@
 
     foreach my $field (@fields) {
 
-        # testing hack
-#     $$item->{"$field"} = $field . ": " . $$item->{"$field"};
-
         # 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"} ) {
@@ -690,33 +368,15 @@
             foreach my $str (@strings) {
 
                 #warn "HPOS ,  VPOS $hPos, $vPos ";
-                # set the font size A
-
-                #   prText( $hPos, $vPos, $str );
-                PrintText( $hPos, $vPos, $fontsize, $str );
+                prText( $hPos, $vPos, $str );
                 $vPos = $vPos - $line_spacer;
             }
-        }    # if field is     }    #foreach feild
-    }
-}
-
-sub PrintText {
-    my ( $hPos, $vPos, $fontsize, $text ) = @_;
-    my $str = "BT /Ft1 $fontsize Tf $hPos $vPos Td ($text) Tj ET";
-    prAdd($str);
-}
-
-sub SetFontSize {
-
-    my ($fontsize) = @_;
-### fontsize
-    my $str = "BT/F13 30 Tf288 720 Td( AAAAAAAAAA ) TjET";
-    prAdd($str);
+        }    # if field is valid
+    }    #foreach feild
 }
 
 sub DrawBarcode {
 
-    # x and y are from the top-left :)
     my ( $x_pos, $y_pos, $height, $width, $barcode, $barcodetype ) = @_;
     my $num_of_bars = length($barcode);
     my $bar_width   = $width * .8;        # %80 of length of label width
@@ -1127,7 +787,8 @@
     my (
         $x_pos_spine, $x_pos_circ1,  $x_pos_circ2, $y_pos,
         $spine_width, $label_height, $circ_width
-    ) = @_;
+      )
+      = @_;
 
     my $y_pos_initial = ( ( 792 - 36 ) - 90 );
     my $y_pos         = $y_pos_initial;
@@ -1168,9 +829,7 @@
     my $str = "q\n";    # save the graphic state
     $str .= "0.5 w\n";              # border color red
     $str .= "1.0 0.0 0.0  RG\n";    # border color red
-         #   $str .= "0.5 0.75 1.0 rg\n";           # fill color blue
-    $str .= "1.0 1.0 1.0  rg\n";    # fill color white
-
+    $str .= "0.5 0.75 1.0 rg\n";           # fill color blue
     $str .= "$llx $lly $urx $ury re\n";    # a rectangle
     $str .= "B\n";                         # fill (and a little more)
     $str .= "Q\n";                         # save the graphic state




reply via email to

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