use strict;
use warnings;
-use C4::Context;
-use C4::Debug;
+use base qw(C4::Creators::Batch);
+
+use autouse 'Data::Dumper' => qw(Dumper);
BEGIN {
use version; our $VERSION = qv('1.0.0_1');
}
-sub _check_params {
- my $given_params = {};
- my $exit_code = 0;
- my @valid_template_params = (
- 'label_id',
- 'batch_id',
- 'item_number',
- 'branch_code',
- );
- if (scalar(@_) >1) {
- $given_params = {@_};
- foreach my $key (keys %{$given_params}) {
- if (!(grep m/$key/, @valid_template_params)) {
- warn sprintf('Unrecognized parameter type of "%s".', $key);
- $exit_code = 1;
- }
- }
- }
- else {
- if (!(grep m/$_/, @valid_template_params)) {
- warn sprintf('Unrecognized parameter type of %s', $_);
- $exit_code = 1;
- }
- }
- return $exit_code;
-}
+__PACKAGE__ =~ m/^C4::(.+)::.+$/;
+my $me = $1;
sub new {
- my ($invocant) = shift;
- my $type = ref($invocant) || $invocant;
- my $self = {
- batch_id => 0,
- items => [],
- branch_code => 'NB',
- batch_stat => 0, # False if any data has changed and the db has not been updated
- @_,
- };
- my $sth = C4::Context->dbh->prepare("SELECT MAX(batch_id) FROM labels_batches;");
- $sth->execute();
- my $batch_id = $sth->fetchrow_array;
- $self->{'batch_id'} = ++$batch_id unless $self->{'batch_id'} != 0; # this allows batch_id to be passed in for individual label printing
- bless ($self, $type);
- return $self;
-}
-
-sub add_item {
- my $self = shift;
- my $item_number = shift;
- my $query = "INSERT INTO labels_batches (batch_id, item_number, branch_code) VALUES (?,?,?);";
- my $sth = C4::Context->dbh->prepare($query);
-# $sth->{'TraceLevel'} = 3;
- $sth->execute($self->{'batch_id'}, $item_number, $self->{'branch_code'});
- if ($sth->err) {
- warn sprintf('Database returned the following error on attempted INSERT: %s', $sth->errstr);
- return -1;
- }
- $query = "SELECT max(label_id) FROM labels_batches WHERE batch_id=? AND item_number=? AND branch_code=?;";
- my $sth1 = C4::Context->dbh->prepare($query);
- $sth1->execute($self->{'batch_id'}, $item_number, $self->{'branch_code'});
- my $label_id = $sth1->fetchrow_array;
- push (@{$self->{'items'}}, {item_number => $item_number, label_id => $label_id});
- $self->{'batch_stat'} = 1;
- return 0;
-}
-
-sub get_attr {
my $self = shift;
- return $self->{$_[0]};
+ push @_, "creator", $me;
+ return $self->SUPER::new(@_);
}
-sub remove_item {
+sub save {
my $self = shift;
- my $label_id = shift;
- my $query = "DELETE FROM labels_batches WHERE label_id=? AND batch_id=?;";
- my $sth = C4::Context->dbh->prepare($query);
-# $sth->{'TraceLevel'} = 3;
- $sth->execute($label_id, $self->{'batch_id'});
- if ($sth->err) {
- warn sprintf('Database returned the following error on attempted DELETE: %s', $sth->errstr);
- return -1;
- }
- @{$self->{'items'}} = grep{$_->{'label_id'} != $label_id} @{$self->{'items'}};
- $self->{'batch_stat'} = 1;
- return 0;
+ push @_, "creator", $me;
+ return $self->SUPER::save(@_);
}
-# FIXME: This method is effectively useless the way the current add_item method is written. Ideally, the items should be added to the object
-# and then the save method called. This does not work well in practice due to the inability to pass objects accross cgi script calls.
-# I'm leaving it here because it should be here and for consistency's sake. -cnighswonger
-#
-#=head2 $batch->save()
-#
-# Invoking the I<save> method attempts to insert the batch into the database. The method returns
-# the new record batch_id upon success and -1 upon failure (This avoids conflicting with a record
-# batch_id of 1). Errors are logged to the Apache log.
-#
-# example:
-# my $exitstat = $batch->save(); # to save the record behind the $batch object
-#
-#=cut
-#
-#sub save {
-# my $self = shift;
-# foreach my $item_number (@{$self->{'items'}}) {
-# my $query = "INSERT INTO labels_batches (batch_id, item_number, branch_code) VALUES (?,?,?);";
-# my $sth1 = C4::Context->dbh->prepare($query);
-# $sth1->execute($self->{'batch_id'}, $item_number->{'item_number'}, $self->{'branch_code'});
-# if ($sth1->err) {
-# warn sprintf('Database returned the following error on attempted INSERT: %s', $sth1->errstr);
-# return -1;
-# }
-# $self->{'batch_stat'} = 1;
-# return $self->{'batch_id'};
-# }
-#}
-
sub retrieve {
- my $invocant = shift;
- my %opts = @_;
- my $type = ref($invocant) || $invocant;
- my $record_flag = 0;
- my $query = "SELECT * FROM labels_batches WHERE batch_id = ? ORDER BY label_id";
- my $sth = C4::Context->dbh->prepare($query);
-# $sth->{'TraceLevel'} = 3;
- $sth->execute($opts{'batch_id'});
- my $self = {
- batch_id => $opts{'batch_id'},
- items => [],
- };
- while (my $record = $sth->fetchrow_hashref) {
- $self->{'branch_code'} = $record->{'branch_code'};
- push (@{$self->{'items'}}, {item_number => $record->{'item_number'}, label_id => $record->{'label_id'}});
- $record_flag = 1; # true if one or more rows were retrieved
- }
- return -2 if $record_flag == 0; # a hackish sort of way of indicating no such record exists
- if ($sth->err) {
- warn sprintf('Database returned the following error on attempted SELECT: %s', $sth->errstr);
- return -1;
- }
- $self->{'batch_stat'} = 1;
- bless ($self, $type);
- return $self;
+ my $self = shift;
+ push @_, "creator", $me;
+ return $self->SUPER::retrieve(@_);
}
sub delete {
- my $self = {};
- my %opts = ();
- my $call_type = '';
- my @query_params = ();
if (ref($_[0])) {
- $self = shift; # check to see if this is a method call
- $call_type = 'C4::Labels::Batch->delete';
- @query_params = ($self->{'batch_id'}, $self->{'branch_code'});
+ my $self = shift; # check to see if this is a method call
+ push @_, "creator", $me;
+ return $self->SUPER::delete(@_);
}
else {
- %opts = @_;
- $call_type = 'C4::Labels::Batch::delete';
- @query_params = ($opts{'batch_id'}, $opts{'branch_code'});
+ push @_, "creator", $me;
+ return __PACKAGE__->SUPER::delete(@_); # XXX: is this too hackish?
}
- if ($query_params[0] eq '') { # If there is no template id then we cannot delete it
- warn sprtinf('%s : Cannot delete batch as the batch id is invalid or non-existent.', $call_type);
- return -1;
- }
- my $query = "DELETE FROM labels_batches WHERE batch_id = ? AND branch_code =?";
- my $sth = C4::Context->dbh->prepare($query);
-# $sth->{'TraceLevel'} = 3;
- $sth->execute(@query_params);
- if ($sth->err) {
- warn sprintf('%s : Database returned the following error on attempted INSERT: %s', $call_type, $sth->errstr);
- return -1;
- }
- return 0;
-}
-
-sub remove_duplicates {
- my $self = shift;
- my %seen=();
- my $query = "DELETE FROM labels_batches WHERE label_id = ?;"; # ORDER BY timestamp ASC LIMIT ?;";
- my $sth = C4::Context->dbh->prepare($query);
- my @duplicate_items = grep{$seen{$_->{'item_number'}}++} @{$self->{'items'}};
- foreach my $item (@duplicate_items) {
- $sth->execute($item->{'label_id'});
- if ($sth->err) {
- warn sprintf('Database returned the following error on attempted DELETE for label_id %s: %s', $item->{'label_id'}, $sth->errstr);
- return -1;
- }
- $sth->finish(); # Per DBI.pm docs: "If execute() is called on a statement handle that's still active ($sth->{Active} is true) then it should effectively call finish() to tidy up the previous execution results before starting this new execution."
- @{$self->{'items'}} = grep{$_->{'label_id'} != $item->{'label_id'}} @{$self->{'items'}}; # the correct label/item must be removed from the current batch object as well; this should be done *after* each sql DELETE in case the DELETE fails
- }
- return scalar(@duplicate_items);
}
1;
-__END__
-
-=head1 NAME
-
-C4::Labels::Batch - A class for creating and manipulating batch objects in Koha
-
-=head1 ABSTRACT
-
-This module provides methods for creating, and otherwise manipulating batch objects used by Koha to create and export labels.
-
-=head1 METHODS
-
-=head2 new()
-
- Invoking the I<new> method constructs a new batch object with no items. It is possible to pre-populate the batch with items and a branch code by passing them
- as in the second example below.
-
- B<NOTE:> The items list must be an arrayref pointing to an array of hashes containing a key/data pair after this fashion: {item_number => item_number}. The order of
- the array elements determines the order of the items in the batch.
-
- example:
- C<my $batch = C4::Labels::Batch->new(); # Creates and returns a new batch object>
-
- C<my $batch = C4::Labels::Batch->new(items => $arrayref, branch_code => branch_code) # Creates and returns a new batch object containing the items passed in
- with the branch code passed in.>
-
- B<NOTE:> This batch is I<not> written to the database until C<$batch->save()> is invoked. You have been warned!
-
-=head2 $batch->add_item(item_number => $item_number, branch_code => $branch_code)
-
- Invoking the I<add_item> method will add the supplied item to the batch object.
-
- example:
- $batch->add_item(item_number => $item_number, branch_code => $branch_code);
-
-=head2 $batch->get_attr($attribute)
-
- Invoking the I<get_attr> method will return the requested attribute.
-
- example:
- my @items = $batch->get_attr('items');
-
-=head2 $batch->remove_item($item_number)
-
- Invoking the I<remove_item> method will remove the supplied item number from the batch object.
-
- example:
- $batch->remove_item($item_number);
-
-=head2 C4::Labels::Batch->retrieve(batch_id => $batch_id)
-
- Invoking the I<retrieve> method constructs a new batch object containing the current values for batch_id. The method returns a new object upon success and 1 upon failure.
- Errors are logged to the Apache log.
-
- examples:
-
- my $batch = C4::Labels::Batch->retrieve(batch_id => 1); # Retrieves batch 1 and returns an object containing the record
-
-=head2 delete()
-
- Invoking the delete method attempts to delete the template from the database. The method returns -1 upon failure. Errors are logged to the Apache log.
- NOTE: This method may also be called as a function and passed a key/value pair simply deleteing that batch from the database. See the example below.
-
- examples:
- my $exitstat = $batch->delete(); # to delete the record behind the $batch object
- my $exitstat = C4::Labels::Batch->delete(batch_id => 1); # to delete batch 1
-
-=head2 remove_duplicates()
-
- Invoking the remove_duplicates method attempts to remove duplicate items in the batch from the database. The method returns the count of duplicate records removed upon
- success and -1 upon failure. Errors are logged to the Apache log.
- NOTE: This method may also be called as a function and passed a key/value pair removing duplicates in the batch passed in. See the example below.
-
- examples:
- my $remove_count = $batch->remove_duplicates(); # to remove duplicates the record behind the $batch object
- my $remove_count = C4::Labels::Batch->remove_duplicates(batch_id => 1); # to remove duplicates in batch 1
-
-=head1 AUTHOR
-
-Chris Nighswonger <cnighswonger AT foundations DOT edu>
-
-=head1 COPYRIGHT
-
-Copyright 2009 Foundations Bible College.
-
-=head1 LICENSE
-
-This file is part of Koha.
-
-Koha is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
-Foundation; either version 2 of the License, or (at your option) any later version.
-
-You should have received a copy of the GNU General Public License along with Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-Suite 330, Boston, MA 02111-1307 USA
-
-=head1 DISCLAIMER OF WARRANTY
-
-Koha is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
-=cut
-
LABEL_LINES: # generate lines of label text for current field
foreach my $line (@label_lines) {
next LABEL_LINES if $line eq '';
- my $string_width = C4::Labels::PDF->StrWidth($line, $font, $self->{'font_size'});
+ my $string_width = C4::Creators::PDF->StrWidth($line, $font, $self->{'font_size'});
if ($self->{'justify'} eq 'R') {
$text_llx = $params{'llx'} + $self->{'width'} - ($self->{'left_text_margin'} + $string_width);
}
use strict;
use warnings;
-use DBI qw(neat);
+use base qw(C4::Creators::Layout);
-use C4::Context;
-use C4::Debug;
-use C4::Labels::PDF;
+use autouse 'Data::Dumper' => qw(Dumper);
BEGIN {
use version; our $VERSION = qv('1.0.0_1');
}
-# FIXME: Consider this style parameter verification instead...
-# my %param = @_;
-# for (keys %param)
-# { my $lc = lc($_);
-# if (exists $default{$lc})
-# { $default{$lc} = $param{$_};
-# }
-# else
-# { print STDERR "Unknown parameter $_ , not used \n";
-# }
-# }
-
-sub _check_params {
- my $exit_code = 0;
- my @valtmpl_id_params = (
- 'barcode_type',
- 'printing_type',
- 'layout_name',
- 'guidebox',
- 'font',
- 'font_size',
- 'callnum_split',
- 'text_justify',
- 'format_string',
- );
- if (scalar(@_) >1) {
- my %given_params = @_;
- foreach my $key (keys %given_params) {
- if (!(grep m/$key/, @valtmpl_id_params)) {
- warn sprintf('(Multiple parameters) Unrecognized parameter type of "%s".', $key);
- $exit_code = 1;
- }
- }
- }
- else {
- if (!(grep m/$_/, @valtmpl_id_params)) {
- warn sprintf('(Single parameter) Unrecognized parameter type of "%s".', $_);
- $exit_code = 1;
- }
- }
- return $exit_code;
-}
+__PACKAGE__ =~ m/^C4::(.+)::.+$/;
+my $me = $1;
sub new {
- my $invocant = shift;
- if (_check_params(@_) eq 1) {
- return -1;
- }
- my $type = ref($invocant) || $invocant;
- my $self = {
- barcode_type => 'CODE39',
- printing_type => 'BAR',
- layout_name => 'DEFAULT',
- guidebox => 0,
- font => 'TR',
- font_size => 3,
- callnum_split => 0,
- text_justify => 'L',
- format_string => 'title, author, isbn, issn, itemtype, barcode, callnumber',
- @_,
- };
- bless ($self, $type);
- return $self;
-}
-
-sub retrieve {
- my $invocant = shift;
- my %opts = @_;
- my $type = ref($invocant) || $invocant;
- my $query = "SELECT * FROM labels_layouts WHERE layout_id = ?";
- my $sth = C4::Context->dbh->prepare($query);
- $sth->execute($opts{'layout_id'});
- if ($sth->err) {
- warn sprintf('Database returned the following error: %s', $sth->errstr);
- return -1;
- }
- my $self = $sth->fetchrow_hashref;
- bless ($self, $type);
- return $self;
-}
-
-sub delete {
- my $self = {};
- my %opts = ();
- my $call_type = '';
- my $query_param = '';
- if (ref($_[0])) {
- $self = shift; # check to see if this is a method call
- $call_type = 'C4::Labels::Layout->delete';
- $query_param = $self->{'layout_id'};
- }
- else {
- %opts = @_;
- $call_type = 'C4::Labels::Layout::delete';
- $query_param = $opts{'layout_id'};
- }
- if ($query_param eq '') { # If there is no layout id then we cannot delete it
- warn sprintf('%s : Cannot delete layout as the layout id is invalid or non-existant.', $call_type);
- return -1;
- }
- my $query = "DELETE FROM labels_layouts WHERE layout_id = ?";
- my $sth = C4::Context->dbh->prepare($query);
- $sth->execute($query_param);
- if ($sth->err) {
- warn sprintf('%s : Database returned the following error: %s', $call_type, $sth->errstr);
- return -1;
- }
- return 0;
+ my $self = shift;
+ push @_, "creator", $me;
+ return $self->SUPER::new(@_);
}
sub save {
my $self = shift;
- if ($self->{'layout_id'}) { # if we have an id, the record exists and needs UPDATE
- my @params;
- my $query = "UPDATE labels_layouts SET ";
- foreach my $key (keys %{$self}) {
- next if $key eq 'layout_id';
- push (@params, $self->{$key});
- $query .= "$key=?, ";
- }
- $query = substr($query, 0, (length($query)-2));
- $query .= " WHERE layout_id=?;";
- push (@params, $self->{'layout_id'});
- my $sth = C4::Context->dbh->prepare($query);
- #local $sth->{TraceLevel} = "3"; # enable DBI trace and set level; outputs to STDERR
- $sth->execute(@params);
- if ($sth->err) {
- warn sprintf('Database returned the following error: %s', $sth->errstr);
- return -1;
- }
- return $self->{'layout_id'};
- }
- else { # otherwise create a new record
- my @params;
- my $query = "INSERT INTO labels_layouts (";
- foreach my $key (keys %{$self}) {
- push (@params, $self->{$key});
- $query .= "$key, ";
- }
- $query = substr($query, 0, (length($query)-2));
- $query .= ") VALUES (";
- for (my $i=1; $i<=(scalar keys %$self); $i++) {
- $query .= "?,";
- }
- $query = substr($query, 0, (length($query)-1));
- $query .= ");";
- my $sth = C4::Context->dbh->prepare($query);
- $sth->execute(@params);
- if ($sth->err) {
- warn sprintf('Database returned the following error: %s', $sth->errstr);
- return -1;
- }
- my $sth1 = C4::Context->dbh->prepare("SELECT MAX(layout_id) FROM labels_layouts;");
- $sth1->execute();
- my $id = $sth1->fetchrow_array;
- return $id;
- }
+ push @_, "creator", $me;
+ return $self->SUPER::save(@_);
}
-sub get_attr {
+sub retrieve {
my $self = shift;
- if (_check_params(@_) eq 1) {
- return -1;
- }
- my ($attr) = @_;
- if (exists($self->{$attr})) {
- return $self->{$attr};
- }
- else {
- return -1;
- }
- return;
+ push @_, "creator", $me;
+ return $self->SUPER::retrieve(@_);
}
-sub set_attr {
- my $self = shift;
- if (_check_params(@_) eq 1) {
- return -1;
+sub delete {
+ if (ref($_[0])) {
+ my $self = shift; # check to see if this is a method call
+ push @_, "creator", $me;
+ return $self->SUPER::delete(@_);
}
- my %attrs = @_;
- foreach my $attrib (keys(%attrs)) {
- $self->{$attrib} = $attrs{$attrib};
- };
- return 0;
-}
-
-sub get_text_wrap_cols {
- my $self = shift;
- my %params = @_;
- my $string = '';
- my $strwidth = 0;
- my $col_count = 0;
- my $textlimit = $params{'label_width'} - ( 3 * $params{'left_text_margin'});
-
- while ($strwidth < $textlimit) {
- $string .= '0';
- $col_count++;
- $strwidth = C4::Labels::PDF->StrWidth( $string, $self->{'font'}, $self->{'font_size'} );
+ else {
+ push @_, "creator", $me;
+ return __PACKAGE__->SUPER::delete(@_); # XXX: is this too hackish?
}
- return $col_count;
}
1;
-__END__
-
-=head1 NAME
-
-C4::Labels::Layout -A class for creating and manipulating layout objects in Koha
-
-=head1 ABSTRACT
-
-This module provides methods for creating, retrieving, and otherwise manipulating label layout objects used by Koha to create and export labels.
-
-=head1 METHODS
-
-=head2 new()
-
- Invoking the I<new> method constructs a new layout object containing the default values for a layout.
- The following parameters are optionally accepted as key => value pairs:
-
- C<barcode_type> Defines the barcode type to be used on labels. NOTE: At present only the following barcode types are supported in the label creator code:
-
-=over 9
-
-=item .
- CODE39 = Code 3 of 9
-
-=item .
- CODE39MOD = Code 3 of 9 with modulo 43 checksum
-
-=item .
- CODE39MOD10 = Code 3 of 9 with modulo 10 checksum
-
-=item .
- COOP2OF5 = A varient of 2 of 5 barcode based on NEC's "Process 8000" code
-
-=item .
- INDUSTRIAL2OF5 = The standard 2 of 5 barcode (a binary level bar code developed by Identicon Corp. and Computer Identics Corp. in 1970)
-
-=back
-
- C<printing_type> Defines the general layout to be used on labels. NOTE: At present there are only five printing types supported in the label creator code:
-
-=over 9
-
-=item .
-BIB = Only the bibliographic data is printed
-
-=item .
-BARBIB = Barcode proceeds bibliographic data
-
-=item .
-BIBBAR = Bibliographic data proceeds barcode
-
-=item .
-ALT = Barcode and bibliographic data are printed on alternating labels
-
-=item .
-BAR = Only the barcode is printed
-
-=back
-
- C<layout_name> The descriptive name for this layout.
- C<guidebox> Setting this to '1' will result in a guide box being drawn around the labels marking the edge of each label
- C<font> Defines the type of font to be used on labels. NOTE: The following fonts are available by default on most systems:
-
-=over 9
-
-=item .
-TR = Times-Roman
-
-=item .
-TB = Times Bold
-
-=item .
-TI = Times Italic
-
-=item .
-TBI = Times Bold Italic
-
-=item .
-C = Courier
-
-=item .
-CB = Courier Bold
-
-=item .
-CO = Courier Oblique (Italic)
-
-=item .
-CBO = Courier Bold Oblique
-
-=item .
-H = Helvetica
-
-=item .
-HB = Helvetica Bold
-
-=item .
-HBO = Helvetical Bold Oblique
-
-=back
-
- C<font_size> Defines the size of the font in postscript points to be used on labels
- C<callnum_split> Setting this to '1' will enable call number splitting on labels
- C<text_justify> Defines the text justification to be used on labels. NOTE: The following justification styles are currently supported by label creator code:
-
-=over 9
-
-=item .
-L = Left
-
-=item .
-C = Center
-
-=item .
-R = Right
-
-=back
-
- C<format_string> Defines what fields will be printed and in what order they will be printed on labels. These include any of the data fields that may be mapped
- to your MARC frameworks. Specify MARC subfields as a 4-character tag-subfield string: ie. 254a Enclose a whitespace-separated list of fields
- to concatenate on one line in double quotes. ie. "099a 099b" or "itemcallnumber barcode" Static text strings may be entered in single-quotes:
- ie. 'Some static text here.'
-
- example:
- C<my $layout = Layout->new(); # Creates and returns a new layout object>
-
- C<my $layout = C4::Labels::Layout->new(barcode_type => 'CODE39', printing_type => 'BIBBAR', font => 'C', font_size => 6); # Creates and returns a new layout object using
- the supplied values to override the defaults>
-
- B<NOTE:> This layout is I<not> written to the database until save() is invoked. You have been warned!
-
-=head2 retrieve(layout_id => layout_id)
-
- Invoking the I<retrieve> method constructs a new layout object containing the current values for layout_id. The method returns a new object upon success and 1 upon failure.
- Errors are logged to the Apache log.
-
- example:
- C<my $layout = Layout->retrieve(layout_id => 1); # Retrieves layout record 1 and returns an object containing the record>
-
-=head2 delete()
-
- Invoking the delete method attempts to delete the layout from the database. The method returns 0 upon success and -1 upon failure. Errors are logged to the Apache log.
- NOTE: This method may also be called as a function and passed a key/value pair simply deleteing that template from the database. See the example below.
-
- examples:
- C<my $exitstat = $layout->delete(); # to delete the record behind the $layout object>
- C<my $exitstat = Layout->delete(layout_id => 1); # to delete layout record 1>
-
-=head2 save()
-
- Invoking the I<save> method attempts to insert the layout into the database if the layout is new and update the existing layout record if the layout exists.
- The method returns the new record id upon success and -1 upon failure (This avoids conflicting with a record id of 1). Errors are logged to the Apache log.
-
- example:
- C<my $exitstat = $layout->save(); # to save the record behind the $layout object>
-
-=head2 get_attr($attribute)
-
- Invoking the I<get_attr> method will return the value of the requested attribute or -1 on errors.
-
- example:
- C<my $value = $layout->get_attr($attribute);>
-
-=head2 set_attr(attribute => value, attribute_2 => value)
-
- Invoking the I<set_attr> method will set the value of the supplied attributes to the supplied values. The method accepts key/value pairs separated by
- commas.
-
- example:
- C<$layout->set_attr(attribute => value);>
-
-=head2 get_text_wrap_cols()
-
- Invoking the I<get_text_wrap_cols> method will return the number of columns that can be printed on the label before wrapping to the next line.
-
- examples:
- C<my $text_wrap_cols = $layout->get_text_wrap_cols();>
-
-=head1 AUTHOR
-
-Chris Nighswonger <cnighswonger AT foundations DOT edu>
-
-=head1 COPYRIGHT
-
-Copyright 2009 Foundations Bible College.
-
-=head1 LICENSE
-
-This file is part of Koha.
-
-Koha is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
-Foundation; either version 2 of the License, or (at your option) any later version.
-
-You should have received a copy of the GNU General Public License along with Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-Suite 330, Boston, MA 02111-1307 USA
-
-=head1 DISCLAIMER OF WARRANTY
-
-Koha is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
-=cut
# Copyright 2009 Foundations Bible College.
#
# This file is part of Koha.
-#
+#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
use strict;
use warnings;
-use Data::Dumper;
+use autouse 'Data::Dumper' => qw(Dumper);
use C4::Context;
use C4::Debug;
{type => 'L', name => 'Left', selected => 0},
{type => 'C', name => 'Center', selected => 0},
{type => 'R', name => 'Right', selected => 0},
-# {type => 'F', name => 'Full', selected => 0},
+# {type => 'F', name => 'Full', selected => 0},
];
my $unit_values = [
This function returns an arrayref whose elements are hashes containing the batch_ids of current batches along with the item count
for each batch upon success and 1 upon failure. Item counts are stored under the key '_item_count' Errors are logged to the Apache log.
One parameter is accepted which limits the records returned based on a string containing a valud SQL 'WHERE' filter.
-
+
NOTE: Do not pass in the keyword 'WHERE.'
examples:
This function returns an arrayref whose elements are hashes containing the label_ids of current labels along with the item count
for each label upon success and 1 upon failure. Item counts are stored under the key '_item_count' Errors are logged to the Apache log.
One parameter is accepted which limits the records returned based on a string containing a valud SQL 'WHERE' filter.
-
+
NOTE: Do not pass in the keyword 'WHERE.'
examples:
return undef if scalar(@$data) == 0; # no need to generate a table if there is not data to display
my $table = [];
my $fields = [];
- my @headers = ();
my @table_columns = ();
my ($row_index, $col_index) = (0,0);
my $cols = 0; # number of columns to wrap on
sub Jpeg {
my $self = shift;
- my ($imageFile, $width, $height) = @_;
- return prJpeg($imageFile, $width, $height);
+ my ($imageData, $width, $height, $imageFormat) = @_;
+ return prJpeg($imageData, $width, $height, $imageFormat);
}
sub Js {
use strict;
use warnings;
-use C4::Context;
-use C4::Debug;
-use C4::Labels::Lib 1.000000 qw(get_unit_values);
+use base qw(C4::Creators::Profile);
+
+use autouse 'Data::Dumper' => qw(Dumper);
BEGIN {
use version; our $VERSION = qv('1.0.0_1');
}
-sub _check_params {
- my $given_params = {};
- my $exit_code = 0;
- my @valid_profile_params = (
- 'printer_name',
- 'template_id',
- 'paper_bin',
- 'offset_horz',
- 'offset_vert',
- 'creep_horz',
- 'creep_vert',
- 'units',
- );
- if (scalar(@_) >1) {
- $given_params = {@_};
- foreach my $key (keys %{$given_params}) {
- if (!(grep m/$key/, @valid_profile_params)) {
- warn sprintf('Unrecognized parameter type of "%s".', $key);
- $exit_code = 1;
- }
- }
- }
- else {
- if (!(grep m/$_/, @valid_profile_params)) {
- warn sprintf('Unrecognized parameter type of "%s".', $_);
- $exit_code = 1;
- }
- }
- return $exit_code;
-}
+__PACKAGE__ =~ m/^C4::(.+)::.+$/;
+my $me = $1;
-sub _conv_points {
+sub new {
my $self = shift;
- my @unit_value = grep {$_->{'type'} eq $self->{units}} @{get_unit_values()};
- $self->{offset_horz} = $self->{offset_horz} * $unit_value[0]->{'value'};
- $self->{offset_vert} = $self->{offset_vert} * $unit_value[0]->{'value'};
- $self->{creep_horz} = $self->{creep_horz} * $unit_value[0]->{'value'};
- $self->{creep_vert} = $self->{creep_vert} * $unit_value[0]->{'value'};
- return $self;
+ push @_, "creator", $me;
+ return $self->SUPER::new(@_);
}
-sub new {
- my $invocant = shift;
- if (_check_params(@_) eq 1) {
- return -1;
- }
- my $type = ref($invocant) || $invocant;
- my $self = {
- printer_name => 'Default Printer',
- template_id => '',
- paper_bin => 'Tray 1',
- offset_horz => 0,
- offset_vert => 0,
- creep_horz => 0,
- creep_vert => 0,
- units => 'POINT',
- @_,
- };
- bless ($self, $type);
- return $self;
+sub save {
+ my $self = shift;
+ push @_, "creator", $me;
+ return $self->SUPER::save(@_);
}
sub retrieve {
- my $invocant = shift;
- my %opts = @_;
- my $type = ref($invocant) || $invocant;
- my $query = "SELECT * FROM printers_profile WHERE profile_id = ?";
- my $sth = C4::Context->dbh->prepare($query);
- $sth->execute($opts{profile_id});
- if ($sth->err) {
- warn sprintf('Database returned the following error: %s', $sth->errstr);
- return -1;
- }
- my $self = $sth->fetchrow_hashref;
- $self = _conv_points($self) if ($opts{convert} && $opts{convert} == 1);
- bless ($self, $type);
- return $self;
+ my $self = shift;
+ push @_, "creator", $me;
+ return $self->SUPER::retrieve(@_);
}
sub delete {
- my $self = {};
- my %opts = ();
- my $call_type = '';
- my $query_param = '';
if (ref($_[0])) {
- $self = shift; # check to see if this is a method call
- $call_type = 'C4::Labels::Profile->delete';
- $query_param = $self->{'profile_id'};
+ my $self = shift; # check to see if this is a method call
+ push @_, "creator", $me;
+ return $self->SUPER::delete(@_);
}
else {
- %opts = @_;
- $call_type = 'C4::Labels::Profile::delete';
- $query_param = $opts{'profile_id'};
- }
- if ($query_param eq '') { # If there is no profile id then we cannot delete it
- warn sprintf('%s : Cannot delete layout as the profile id is invalid or non-existant.', $call_type);
- return -1;
- }
- my $query = "DELETE FROM printers_profile WHERE profile_id = ?";
- my $sth = C4::Context->dbh->prepare($query);
-# $sth->{'TraceLevel'} = 3;
- $sth->execute($query_param);
-}
-
-sub save {
- my $self = shift;
- if ($self->{'profile_id'}) { # if we have an profile_id, the record exists and needs UPDATE
- my @params;
- my $query = "UPDATE printers_profile SET ";
- foreach my $key (keys %{$self}) {
- next if $key eq 'profile_id';
- push (@params, $self->{$key});
- $query .= "$key=?, ";
- }
- $query = substr($query, 0, (length($query)-2));
- push (@params, $self->{'profile_id'});
- $query .= " WHERE profile_id=?;";
- my $sth = C4::Context->dbh->prepare($query);
-# $sth->{'TraceLevel'} = 3;
- $sth->execute(@params);
- if ($sth->err) {
- warn sprintf('Database returned the following error on attempted UPDATE: %s', $sth->errstr);
- return -1;
- }
- return $self->{'profile_id'};
- }
- else { # otherwise create a new record
- my @params;
- my $query = "INSERT INTO printers_profile (";
- foreach my $key (keys %{$self}) {
- push (@params, $self->{$key});
- $query .= "$key, ";
- }
- $query = substr($query, 0, (length($query)-2));
- $query .= ") VALUES (";
- for (my $i=1; $i<=(scalar keys %$self); $i++) {
- $query .= "?,";
- }
- $query = substr($query, 0, (length($query)-1));
- $query .= ");";
- my $sth = C4::Context->dbh->prepare($query);
- $sth->execute(@params);
- if ($sth->err) {
- warn sprintf('Database returned the following error on attempted INSERT: %s', $sth->errstr);
- return -1;
- }
- my $sth1 = C4::Context->dbh->prepare("SELECT MAX(profile_id) FROM printers_profile;");
- $sth1->execute();
- my $tmpl_id = $sth1->fetchrow_array;
- return $tmpl_id;
+ push @_, "creator", $me;
+ return __PACKAGE__->SUPER::delete(@_); # XXX: is this too hackish?
}
}
-sub get_attr {
- my $self = shift;
- if (_check_params(@_) eq 1) {
- return -1;
- }
- my ($attr) = @_;
- if (exists($self->{$attr})) {
- return $self->{$attr};
- }
- else {
- warn sprintf('%s is currently undefined.', $attr);
- return -1;
- }
-}
-
-sub set_attr {
- my $self = shift;
- if (_check_params(@_) eq 1) {
- return -1;
- }
- my %attrs = @_;
- foreach my $attrib (keys(%attrs)) {
- $self->{$attrib} = $attrs{$attrib};
- };
- return 0;
-}
-
1;
-__END__
-
-=head1 NAME
-
-C4::Labels::Profile - A class for creating and manipulating profile objects in Koha
-
-=head1 ABSTRACT
-
-This module provides methods for creating, retrieving, and otherwise manipulating label profile objects used by Koha to create and export labels.
-
-=head1 METHODS
-
-=head2 new()
-
- Invoking the I<new> method constructs a new profile object containing the default values for a template.
- The following parameters are optionally accepted as key => value pairs:
-
- C<printer_name> The name of the printer to which this profile applies.
- C<template_id> The template to which this profile may be applied. NOTE: There may be multiple profiles which may be applied to the same template.
- C<paper_bin> The paper bin of the above printer to which this profile applies. NOTE: printer name, template id, and paper bin must form a unique combination.
- C<offset_horz> Amount of compensation for horizontal offset (position of text on a single label). This amount is measured in the units supplied by the units parameter in this profile.
- C<offset_vert> Amount of compensation for vertical offset.
- C<creep_horz> Amount of compensation for horizontal creep (tendency of text to 'creep' off of the labels over the span of the entire page).
- C<creep_vert> Amount of compensation for vertical creep.
- C<units> The units of measure used for this template. These B<must> match the measures you supply above or
- bad things will happen to your document. NOTE: The only supported units at present are:
-
-=over 9
-
-=item .
-POINT = Postscript Points (This is the base unit in the Koha label creator.)
-
-=item .
-AGATE = Adobe Agates (5.1428571 points per)
-
-=item .
-INCH = US Inches (72 points per)
-
-=item .
-MM = SI Millimeters (2.83464567 points per)
-
-=item .
-CM = SI Centimeters (28.3464567 points per)
-
-=back
-
- example:
- C<my $profile = C4::Labels::Profile->new(); # Creates and returns a new profile object>
-
- C<my $profile = C4::Labels::Profile->new(template_id => 1, paper_bin => 'Bypass Tray', offset_horz => 0.02, units => 'POINT'); # Creates and returns a new profile object using
- the supplied values to override the defaults>
-
- B<NOTE:> This profile is I<not> written to the database until save() is invoked. You have been warned!
-
-=head2 retrieve(profile_id => $profile_id, convert => 1)
-
- Invoking the I<retrieve> method constructs a new profile object containing the current values for profile_id. The method returns a new object upon success and 1 upon failure.
- Errors are logged to the Apache log. One further option maybe accessed. See the examples below for further description.
-
- examples:
-
- C<my $profile = C4::Labels::Profile->retrieve(profile_id => 1); # Retrieves profile record 1 and returns an object containing the record>
-
- C<my $profile = C4::Labels::Profile->retrieve(profile_id => 1, convert => 1); # Retrieves profile record 1, converts the units to points and returns an object containing the record>
-
-=head2 delete()
-
- Invoking the delete method attempts to delete the profile from the database. The method returns -1 upon failure. Errors are logged to the Apache log.
- NOTE: This method may also be called as a function and passed a key/value pair simply deleteing that profile from the database. See the example below.
-
- examples:
- C<my $exitstat = $profile->delete(); # to delete the record behind the $profile object>
- C<my $exitstat = C4::Labels::Profile::delete(profile_id => 1); # to delete profile record 1>
-
-=head2 save()
-
- Invoking the I<save> method attempts to insert the profile into the database if the profile is new and update the existing profile record if the profile exists. The method returns
- the new record profile_id upon success and -1 upon failure (This avoids conflicting with a record profile_id of 1). Errors are logged to the Apache log.
-
- example:
- C<my $exitstat = $profile->save(); # to save the record behind the $profile object>
-
-=head2 get_attr($attribute)
-
- Invoking the I<get_attr> method will return the value of the requested attribute or -1 on errors.
-
- example:
- C<my $value = $profile->get_attr($attribute);>
-
-=head2 set_attr(attribute => value, attribute_2 => value)
-
- Invoking the I<set_attr> method will set the value of the supplied attributes to the supplied values. The method accepts key/value pairs separated by commas.
-
- example:
- $profile->set_attr(attribute => value);
-
-=head1 AUTHOR
-
-Chris Nighswonger <cnighswonger AT foundations DOT edu>
-
-=head1 COPYRIGHT
-
-Copyright 2009 Foundations Bible College.
-
-=head1 LICENSE
-
-This file is part of Koha.
-
-Koha is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
-Foundation; either version 2 of the License, or (at your option) any later version.
-
-You should have received a copy of the GNU General Public License along with Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-Suite 330, Boston, MA 02111-1307 USA
-
-=head1 DISCLAIMER OF WARRANTY
-
-Koha is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
-=cut
-
-#=head1
-#drawbox( ($left_margin), ($top_margin), ($page_width-(2*$left_margin)), ($page_height-(2*$top_margin)) ); # FIXME: Breakout code to print alignment page for printer profile setup
-#
-#=head2 draw_boundaries
-#
-# sub draw_boundaries ($llx_spine, $llx_circ1, $llx_circ2,
-# $lly, $spine_width, $label_height, $circ_width)
-#
-#This sub draws boundary lines where the label outlines are, to aid in printer testing, and debugging.
-#
-#=cut
-#
-## FIXME: Template use for profile adjustment...
-##sub draw_boundaries {
-##
-## my (
-## $llx_spine, $llx_circ1, $llx_circ2, $lly,
-## $spine_width, $label_height, $circ_width
-## ) = @_;
-##
-## my $lly_initial = ( ( 792 - 36 ) - 90 );
-## $lly = $lly_initial; # FIXME - why are we ignoring the y_pos parameter by redefining it?
-## my $i = 1;
-##
-## for ( $i = 1 ; $i <= 8 ; $i++ ) {
-##
-## _draw_box( $llx_spine, $lly, ($spine_width), ($label_height) );
-##
-## #warn "OLD BOXES x=$llx_spine, y=$lly, w=$spine_width, h=$label_height";
-## _draw_box( $llx_circ1, $lly, ($circ_width), ($label_height) );
-## _draw_box( $llx_circ2, $lly, ($circ_width), ($label_height) );
-##
-## $lly = ( $lly - $label_height );
-##
-## }
-##}
-#
-#
-#
-#=cut
use strict;
use warnings;
-use PDF::Reuse;
-use POSIX qw(ceil);
-use C4::Context;
-use C4::Debug;
-use C4::Labels::Profile 1.000000;
-use C4::Labels::PDF 1.000000;
-use C4::Labels::Lib 1.000000 qw(get_unit_values);
+use base qw(C4::Creators::Template);
+
+use autouse 'Data::Dumper' => qw(Dumper);
BEGIN {
use version; our $VERSION = qv('1.0.0_1');
}
-sub _check_params {
- my $given_params = {};
- my $exit_code = 0;
- my @valid_template_params = (
- 'profile_id',
- 'template_code',
- 'template_desc',
- 'page_width',
- 'page_height',
- 'label_width',
- 'label_height',
- 'top_text_margin',
- 'left_text_margin',
- 'top_margin',
- 'left_margin',
- 'cols',
- 'rows',
- 'col_gap',
- 'row_gap',
- 'units',
- );
- if (scalar(@_) >1) {
- $given_params = {@_};
- foreach my $key (keys %{$given_params}) {
- if (!(grep m/$key/, @valid_template_params)) {
- warn sprintf('Unrecognized parameter type of "%s".', $key);
- $exit_code = 1;
- }
- }
- }
- else {
- if (!(grep m/$_/, @valid_template_params)) {
- warn sprintf('Unrecognized parameter type of "%s".', $_);
- $exit_code = 1;
- }
- }
- return $exit_code;
-}
+use constant TEMPLATE_TABLE => 'creator_templates';
-sub _conv_points {
- my $self = shift;
- my @unit_value = grep {$_->{'type'} eq $self->{'units'}} @{get_unit_values()};
- $self->{'page_width'} = $self->{'page_width'} * $unit_value[0]->{'value'};
- $self->{'page_height'} = $self->{'page_height'} * $unit_value[0]->{'value'};
- $self->{'label_width'} = $self->{'label_width'} * $unit_value[0]->{'value'};
- $self->{'label_height'} = $self->{'label_height'} * $unit_value[0]->{'value'};
- $self->{'top_text_margin'} = $self->{'top_text_margin'} * $unit_value[0]->{'value'};
- $self->{'left_text_margin'} = $self->{'left_text_margin'} * $unit_value[0]->{'value'};
- $self->{'top_margin'} = $self->{'top_margin'} * $unit_value[0]->{'value'};
- $self->{'left_margin'} = $self->{'left_margin'} * $unit_value[0]->{'value'};
- $self->{'col_gap'} = $self->{'col_gap'} * $unit_value[0]->{'value'};
- $self->{'row_gap'} = $self->{'row_gap'} * $unit_value[0]->{'value'};
- return $self;
-}
-
-sub _apply_profile {
- my $self = shift;
- my $profile = C4::Labels::Profile->retrieve(profile_id => $self->{'profile_id'}, convert => 1);
- $self->{'top_margin'} = $self->{'top_margin'} + $profile->get_attr('offset_vert'); # controls vertical offset
- $self->{'left_margin'} = $self->{'left_margin'} + $profile->get_attr('offset_horz'); # controls horizontal offset
- $self->{'label_height'} = $self->{'label_height'} + $profile->get_attr('creep_vert'); # controls vertical creep
- $self->{'label_width'} = $self->{'label_width'} + $profile->get_attr('creep_horz'); # controls horizontal creep
- return $self;
-}
+__PACKAGE__ =~ m/^C4::(.+)::.+$/;
+my $me = $1;
sub new {
- my $invocant = shift;
- if (_check_params(@_) eq 1) {
- return -1;
- }
- my $type = ref($invocant) || $invocant;
- my $self = {
- profile_id => '0',
- template_code => 'DEFAULT TEMPLATE',
- template_desc => 'Default description',
- page_width => 0,
- page_height => 0,
- label_width => 0,
- label_height => 0,
- top_text_margin => 0,
- left_text_margin => 0,
- top_margin => 0,
- left_margin => 0,
- cols => 0,
- rows => 0,
- col_gap => 0,
- row_gap => 0,
- units => 'POINT',
- template_stat => 0, # false if any data has changed and the db has not been updated
- @_,
- };
- bless ($self, $type);
- return $self;
+ my $self = shift;
+ push @_, "creator", $me;
+ return $self->SUPER::new(@_);
}
sub retrieve {
- my $invocant = shift;
- my %opts = @_;
- my $type = ref($invocant) || $invocant;
- my $query = "SELECT * FROM labels_templates WHERE template_id = ?";
- my $sth = C4::Context->dbh->prepare($query);
- $sth->execute($opts{template_id});
- if ($sth->err) {
- warn sprintf('Database returned the following error: %s', $sth->errstr);
- return -1;
- }
- my $self = $sth->fetchrow_hashref;
- $self = _conv_points($self) if (($opts{convert} && $opts{convert} == 1) || $opts{profile_id});
- $self = _apply_profile($self) if $opts{profile_id} && $self->{'profile_id'}; # don't bother if there is no profile_id
- $self->{'template_stat'} = 1;
- bless ($self, $type);
- return $self;
-}
-
-sub delete {
- my $self = {};
- my %opts = ();
- my $call_type = '';
- my $query_param = '';
- if (ref($_[0])) {
- $self = shift; # check to see if this is a method call
- $call_type = 'C4::Labels::Template->delete';
- $query_param = $self->{'template_id'};
- }
- else {
- %opts = @_;
- $call_type = 'C4::Labels::Template::delete';
- $query_param = $opts{'template_id'};
- }
- if ($query_param eq '') { # If there is no template id then we cannot delete it
- warn sprintf('%s : Cannot delete layout as the template id is invalid or non-existant.', $call_type);
- return -1;
- }
- my $query = "DELETE FROM labels_templates WHERE template_id = ?";
- my $sth = C4::Context->dbh->prepare($query);
- $sth->execute($query_param);
- $self->{'template_stat'} = 0;
-}
-
-sub save {
my $self = shift;
- if ($self->{'template_id'}) { # if we have an template_id, the record exists and needs UPDATE
- my @params;
- my $query = "UPDATE labels_templates SET ";
- foreach my $key (keys %{$self}) {
- next if ($key eq 'template_id') || ($key eq 'template_stat');
- push (@params, $self->{$key});
- $query .= "$key=?, ";
- }
- $query = substr($query, 0, (length($query)-2));
- push (@params, $self->{'template_id'});
- $query .= " WHERE template_id=?;";
- my $sth = C4::Context->dbh->prepare($query);
- $sth->execute(@params);
- if ($sth->err) {
- warn sprintf('Database returned the following error: %s', $sth->errstr);
- return -1;
- }
- $self->{'template_stat'} = 1;
- return $self->{'template_id'};
- }
- else { # otherwise create a new record
- my @params;
- my $query = "INSERT INTO labels_templates (";
- foreach my $key (keys %{$self}) {
- next if $key eq 'template_stat';
- push (@params, $self->{$key});
- $query .= "$key, ";
- }
- $query = substr($query, 0, (length($query)-2));
- $query .= ") VALUES (";
- for (my $i=1; $i<=((scalar keys %$self) - 1); $i++) { # key count less keys not db related...
- $query .= "?,";
- }
- $query = substr($query, 0, (length($query)-1));
- $query .= ");";
- my $sth = C4::Context->dbh->prepare($query);
- $sth->execute(@params);
- if ($sth->err) {
- warn sprintf('Database returned the following error: %s', $sth->errstr);
- return -1;
- }
- my $sth1 = C4::Context->dbh->prepare("SELECT MAX(template_id) FROM labels_templates;");
- $sth1->execute();
- my $template_id = $sth1->fetchrow_array;
- $self->{'template_id'} = $template_id;
- $self->{'template_stat'} = 1;
- return $template_id;
- }
+ push @_, "table_name", TEMPLATE_TABLE, "creator", $me;
+ return $self->SUPER::retrieve(@_);
}
-sub get_attr {
+sub delete {
my $self = shift;
- if (_check_params(@_) eq 1) {
- return -1;
- }
- my ($attr) = @_;
- if (exists($self->{$attr})) {
- return $self->{$attr};
- }
- else {
- return -1;
- }
+ push @_, "table_name", TEMPLATE_TABLE, "creator", $me;
+ return $self->SUPER::delete(@_);
}
-sub set_attr {
+sub save {
my $self = shift;
- if (_check_params(@_) eq 1) {
- return -1;
- }
- my %attrs = @_;
- foreach my $attrib (keys(%attrs)) {
- $self->{$attrib} = $attrs{$attrib};
- };
-}
-
-sub get_label_position {
- my ($self, $start_label) = @_;
- my ($row_count, $col_count, $llx, $lly) = 0,0,0,0;
- if ($start_label eq 1) {
- $row_count = 1;
- $col_count = 1;
- $llx = $self->{'left_margin'};
- $lly = ($self->{'page_height'} - $self->{'top_margin'} - $self->{'label_height'});
- return ($row_count, $col_count, $llx, $lly);
- }
- else {
- $row_count = ceil($start_label / $self->{'cols'});
- $col_count = ($start_label - (($row_count - 1) * $self->{'cols'}));
- $llx = $self->{'left_margin'} + ($self->{'label_width'} * ($col_count - 1)) + ($self->{'col_gap'} * ($col_count - 1));
- $lly = $self->{'page_height'} - $self->{'top_margin'} - ($self->{'label_height'} * $row_count) - ($self->{'row_gap'} * ($row_count - 1));
- return ($row_count, $col_count, $llx, $lly);
- }
+ push @_, "table_name", TEMPLATE_TABLE, "creator", $me;
+ return $self->SUPER::save(@_);
}
1;
-__END__
-
-=head1 NAME
-
-C4::Labels::Template - A class for creating and manipulating template objects in Koha
-
-=head1 ABSTRACT
-
-This module provides methods for creating, retrieving, and otherwise manipulating label template objects used by Koha to create and export labels.
-
-=head1 METHODS
-
-=head2 new()
-
- Invoking the I<new> method constructs a new template object containing the default values for a template.
- The following parameters are optionally accepted as key => value pairs:
-
- C<profile_id> A valid profile id to be assciated with this template. NOTE: The profile must exist in the database and B<not> be assigned to another template.
- C<template_code> A template code. ie. 'Avery 5160 | 1 x 2-5/8'
- C<template_desc> A readable description of the template. ie. '3 columns, 10 rows of labels'
- C<page_width> The width of the page measured in the units supplied by the units parameter in this template.
- C<page_height> The height of the page measured in the same units.
- C<label_width> The width of a single label on the page this template applies to.
- C<label_height> The height of a single label on the page.
- C<top_text_margin> The measure of the top margin on a single label on the page.
- C<left_text_margin> The measure of the left margin on a single label on the page.
- C<top_margin> The measure of the top margin of the page.
- C<left_margin> The measure of the left margin of the page.
- C<cols> The number of columns of labels on the page.
- C<rows> The number of rows of labels on the page.
- C<col_gap> The measure of the gap between the columns of labels on the page.
- C<row_gap> The measure of the gap between the rows of labels on the page.
- C<units> The units of measure used for this template. These B<must> match the measures you supply above or
- bad things will happen to your document. NOTE: The only supported units at present are:
-
-=over 9
-
-=item .
-POINT = Postscript Points (This is the base unit in the Koha label creator.)
-
-=item .
-AGATE = Adobe Agates (5.1428571 points per)
-
-=item .
-INCH = US Inches (72 points per)
-
-=item .
-MM = SI Millimeters (2.83464567 points per)
-
-=item .
-CM = SI Centimeters (28.3464567 points per)
-
-=back
-
- example:
- my $template = Template->new(); # Creates and returns a new template object with the defaults
-
- my $template = C4::Labels::Template->new(profile_id => 1, page_width => 8.5, page_height => 11.0, units => 'INCH'); # Creates and returns a new template object using
- the supplied values to override the defaults
-
- B<NOTE:> This template is I<not> written to the database untill save() is invoked. You have been warned!
-
-=head2 retrieve(template_id => $template_id)
-
- Invoking the I<retrieve> method constructs a new template object containing the current values for template_id. The method returns
- a new object upon success and -1 upon failure. Errors are logged to the Apache log. Two further options may be accessed. See the example
- below for further description.
-
- examples:
-
- C<my $template = C4::Labels::Template->retrieve(template_id => 1); # Retrieves template record 1 and returns an object containing the record>
-
- C<my $template = C4::Labels::Template->retrieve(template_id => 1, convert => 1); # Retrieves template record 1, converts the units to points,
- and returns an object containing the record>
-
- C<my $template = C4::Labels::Template->retrieve(template_id => 1, profile_id => 1); # Retrieves template record 1, converts the units
- to points, applies the currently associated profile id, and returns an object containing the record.>
-
-=head2 delete()
-
- Invoking the delete method attempts to delete the template from the database. The method returns -1 upon failure. Errors are logged to the Apache log.
- NOTE: This method may also be called as a function and passed a key/value pair simply deleteing that template from the database. See the example below.
-
- examples:
- C<my $exitstat = $template->delete(); # to delete the record behind the $template object>
- C<my $exitstat = C4::Labels::Template::delete(template_id => 1); # to delete template record 1>
-
-=head2 save()
-
- Invoking the I<save> method attempts to insert the template into the database if the template is new and update the existing template record if
- the template exists. The method returns the new record template_id upon success and -1 upon failure (This avoids template_ids conflicting with a
- record template_id of 1). Errors are logged to the Apache log.
-
- example:
- C<my $template_id = $template->save(); # to save the record behind the $template object>
-
-=head2 get_attr($attribute)
-
- Invoking the I<get_attr> method will return the value of the requested attribute or -1 on errors.
-
- example:
- C<my $value = $template->get_attr($attribute);>
-
-=head2 set_attr(attribute => value, attribute_2 => value)
-
- Invoking the I<set_attr> method will set the value of the supplied attributes to the supplied values. The method accepts key/value pairs separated by
- commas.
-
- example:
- C<$template->set_attr(attribute => value);>
-
-=head2 get_label_position($start_label)
-
- Invoking the I<get_label_position> method will return the row, column coordinates on the starting page and the lower left x,y coordinates on the starting
- label for the template object.
-
- examples:
- C<my ($row_count, $col_count, $llx, $lly) = $template->get_label_position($start_label);>
-
-=head1 AUTHOR
-
-Chris Nighswonger <cnighswonger AT foundations DOT edu>
-
-=head1 COPYRIGHT
-
-Copyright 2009 Foundations Bible College.
-
-=head1 LICENSE
-
-This file is part of Koha.
-
-Koha is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
-Foundation; either version 2 of the License, or (at your option) any later version.
-
-You should have received a copy of the GNU General Public License along with Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-Suite 330, Boston, MA 02111-1307 USA
-
-=head1 DISCLAIMER OF WARRANTY
-
-Koha is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
-=cut
<!-- TMPL_INCLUDE NAME="header.inc" -->
<!-- TMPL_INCLUDE NAME="cat-search.inc" -->
<div id="breadcrumbs">
- <a href="/cgi-bin/koha/mainpage.pl">Home</a> ›
+ <a href="/cgi-bin/koha/mainpage.pl">Home</a> ›
<a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> ›
<a href="/cgi-bin/koha/labels/label-home.pl">Labels Home</a> ›
Manage Label <!-- TMPL_VAR NAME="label_element_title" -->
<!-- TMPL_IF NAME="error" -->
<div class="yui-u">
<div class="dialog alert">
- <strong>WARNING:</strong> An error was encountered and <!-- TMPL_VAR NAME="label_element" --> <!-- TMPL_VAR NAME="element_id" --> was not deleted. Please have your system administrator check the error log for details.
+ <strong>WARNING:</strong> An error was encountered and the <!--TMPL_VAR NAME="op" --> operation for <!-- TMPL_VAR NAME="label_element" --> <!-- TMPL_VAR NAME="element_id" --> was not completed. Please have your system administrator check the error log for details.
</div>
</div>
<!-- /TMPL_IF -->
<dt><a href="/cgi-bin/koha/tools/koha-news.pl">News</a></dt>
<dd>Write news for the OPAC and staff interfaces</dd>
<!-- /TMPL_IF -->
-
+
<!-- TMPL_IF NAME="CAN_user_tools_label_creator" -->
<dt><a href="/cgi-bin/koha/labels/label-home.pl">Label Creator</a></dt>
<dd>Create printable labels and barcodes from catalog data</dd>
<div class="hint"><dd>For use with dedicated label printers</dd></div>
<!-- /TMPL_IF -->
+ <!-- TMPL_IF NAME="CAN_user_tools_label_creator" -->
+ <dt><a href="/cgi-bin/koha/patroncards/home.pl">Patron Card Creator</a></dt>
+ <dd>Create printable patron cards</dd>
+ <!-- /TMPL_IF -->
+
+
<!-- TMPL_IF NAME="CAN_user_tools_edit_calendar" -->
<dt><a href="/cgi-bin/koha/tools/holidays.pl">Calendar</a></dt>
<dd>Define days when the library is closed</dd>
<dt><a href="/cgi-bin/koha/tools/inventory.pl">Inventory/stocktaking</a></dt>
<dd>Perform inventory (stocktaking) of your catalog</dd>
<!-- /TMPL_IF -->
-
+
<!-- TMPL_IF NAME="CAN_user_tools_batchmod" -->
<dt><a href="/cgi-bin/koha/tools/batchMod.pl">Modify a queryset of items</a></dt>
<dd>Perform batch modification of items</dd>
<dt><a href="/cgi-bin/koha/tools/scheduler.pl">Task Scheduler</a></dt>
<dd>Schedule tasks to run</dd>
<!-- /TMPL_IF -->
-
+
</dl>
</div>
use C4::Labels::Batch 1.000000;
use C4::Labels::Template 1.000000;
use C4::Labels::Layout 1.000000;
-use C4::Labels::PDF 1.000000;
+use C4::Creators::PDF 1.000000;
use C4::Labels::Label 1.000000;
=head
use C4::Labels::Batch 1.000000;
use C4::Labels::Template 1.000000;
use C4::Labels::Layout 1.000000;
-use C4::Labels::PDF 1.000000;
+use C4::Creators::PDF 1.000000;
use C4::Labels::Label 1.000000;
my $cgi = new CGI;
-attachment => "$pdf_file.pdf",
);
-my $pdf = C4::Labels::PDF->new(InitVars => 0);
+my $pdf = C4::Creators::PDF->new(InitVars => 0);
my $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
my $template = C4::Labels::Template->retrieve(template_id => $template_id, profile_id => 1);
my $layout = C4::Labels::Layout->retrieve(layout_id => $layout_id);
use C4::Labels::Batch 1.000000;
use C4::Labels::Template 1.000000;
use C4::Labels::Layout 1.000000;
-use C4::Labels::PDF 1.000000;
+use C4::Creators::PDF 1.000000;
use C4::Labels::Label 1.000000;
=head
# Parts Copyright 2009 Foundations Bible College.
#
# This file is part of Koha.
-#
+#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
use C4::Auth qw(get_template_and_user);
use C4::Output qw(output_html_with_http_headers);
use C4::Branch qw(get_branch_code_from_name);
-use C4::Labels::Lib 1.000000 qw(get_label_summary html_table);
+use C4::Creators::Lib 1.000000 qw(get_label_summary html_table);
use C4::Labels::Batch 1.000000;
my $cgi = new CGI;
my $table = html_table($display_columns, $db_rows);
-$template->param(
+$template->param(
err => $err,
errstr => $errstr,
) if ($err ne 0);
use C4::Auth qw(get_template_and_user);
use C4::Output qw(output_html_with_http_headers);
-use C4::Labels::Lib 1.000000 qw(get_barcode_types get_label_types get_font_types get_text_justification_types);
+use C4::Creators::Lib 1.000000 qw(get_barcode_types get_label_types get_font_types get_text_justification_types);
use C4::Labels::Layout 1.000000;
my $cgi = new CGI;
if ($layout_id) { # if a label_id was passed in, this is an update to an existing layout
$layout = C4::Labels::Layout->retrieve(layout_id => $layout_id);
$layout->set_attr(@params);
- $layout->save();
+ $layout_id = $layout->save();
}
else { # if no label_id, this is a new layout so insert it
$layout = C4::Labels::Layout->new(@params);
- $layout->save();
+ $layout_id = $layout->save();
}
- print $cgi->redirect("label-manage.pl?label_element=layout");
+ print $cgi->redirect("label-manage.pl?label_element=layout" . ($layout_id == -1 ? "&element_id=$layout_id&op=$op&error=1" : ''));
exit;
}
else { # if we get here, this is a new layout
# Parts Copyright 2009 Foundations Bible College.
#
# This file is part of Koha.
-#
+#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
use C4::Auth qw(get_template_and_user);
use C4::Output qw(output_html_with_http_headers);
-use C4::Labels::Lib 1.000000 qw(get_all_templates get_unit_values);
+use C4::Creators::Lib 1.000000 qw(get_all_templates get_unit_values);
use C4::Labels::Profile 1.000000;
my $cgi = new CGI;
if ($op eq 'edit') {
$profile = C4::Labels::Profile->retrieve(profile_id => $profile_id);
- $template_list = get_all_templates(field_list => 'template_id,template_code, profile_id');
+ $template_list = get_all_templates(table_name => 'creator_templates', field_list => 'template_id,template_code, profile_id');
}
elsif ($op eq 'save') {
my @params = (
}
if ($profile_id) {
- @label_template = grep{($_->{'profile_id'} == $profile->get_attr('profile_id')) && ($_->{'template_id'} == $profile->get_attr('template_id'))} @$template_list;
+ @label_template = grep {
+ ($_->{'profile_id'} == $profile->get_attr('profile_id')) && ($_->{'template_id'} == $profile->get_attr('template_id'));
+ } @$template_list;
}
foreach my $unit (@$units) {
use C4::Auth qw(get_template_and_user);
use C4::Output qw(output_html_with_http_headers);
-use C4::Labels::Lib 1.000000 qw(get_all_profiles get_unit_values);
+use C4::Creators::Lib 1.000000 qw(get_all_profiles get_unit_values);
use C4::Labels::Template 1.000000;
my $cgi = new CGI;
);
if ($template_id) { # if a label_id was passed in, this is an update to an existing layout
$label_template = C4::Labels::Template->retrieve(template_id => $template_id);
- my $old_profile = C4::Labels::Profile->retrieve(profile_id => $label_template->get_attr('profile_id'));
- my $new_profile = C4::Labels::Profile->retrieve(profile_id => $cgi->param('profile_id'));
- if ($label_template->get_attr('template_id') != $new_profile->get_attr('template_id')) {
- $new_profile->set_attr(template_id => $label_template->get_attr('template_id'));
- $old_profile->set_attr(template_id => 0);
- $new_profile->save();
- $old_profile->save();
+ if ($cgi->param('profile_id')) {
+ my $old_profile = C4::Labels::Profile->retrieve(profile_id => $label_template->get_attr('profile_id'));
+ my $new_profile = C4::Labels::Profile->retrieve(profile_id => $cgi->param('profile_id'));
+ if ($label_template->get_attr('template_id') != $new_profile->get_attr('template_id')) {
+ $new_profile->set_attr(template_id => $label_template->get_attr('template_id'));
+ $old_profile->set_attr(template_id => 0);
+ $new_profile->save();
+ $old_profile->save();
+ }
}
$label_template->set_attr(@params);
$label_template->save();
use C4::Biblio qw(TransformMarcToKoha);
use C4::Items qw(GetItemInfosOf get_itemnumbers_of);
use C4::Koha qw(GetItemTypes); # XXX subfield_is_koha_internal_p
-use C4::Labels::Lib qw(html_table);
+use C4::Creators::Lib qw(html_table);
use C4::Debug;
BEGIN {
# Parts Copyright 2009 Foundations Bible College.
#
# This file is part of Koha.
-#
+#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
use C4::Auth qw(get_template_and_user);
use C4::Output qw(output_html_with_http_headers);
use autouse 'C4::Branch' => qw(get_branch_code_from_name);
-use C4::Labels::Lib 1.000000 qw(get_all_templates get_all_layouts get_all_profiles get_batch_summary html_table);
+use C4::Creators::Lib 1.000000 qw(get_all_templates get_all_layouts get_all_profiles get_batch_summary html_table);
use C4::Labels::Layout 1.000000;
use C4::Labels::Template 1.000000;
use C4::Labels::Profile 1.000000;
}
);
-my $error = 0;
my $db_rows = {};
-my $display_columns = { layout => [ # db column => {col label is link?
+my $display_columns = { layout => [ # db column => {col label is link?
{layout_id => {label => 'Layout ID', link_field => 0}},
{layout_name => {label => 'Layout', link_field => 0}},
{barcode_type => {label => 'Barcode Type', link_field => 0}},
],
};
-my $label_element = $cgi->param('label_element') || undef;
+my $label_element = $cgi->param('label_element') || 'template'; # default to template managment
my $op = $cgi->param('op') || 'none';
my $element_id = $cgi->param('element_id') || undef;
+my $error = $cgi->param('error') || 0;
my $branch_code = ($label_element eq 'batch' ? get_branch_code_from_name($template->param('LoginBranchname')) : '');
elsif ($label_element eq 'template') {$error = C4::Labels::Template::delete(template_id => $element_id);}
elsif ($label_element eq 'profile') {$error = C4::Labels::Profile::delete(profile_id => $element_id);}
elsif ($label_element eq 'batch') {$error = C4::Labels::Batch::delete(batch_id => $element_id, branch_code => $branch_code);}
- else {} # FIXME: Some error trapping code
+ else {} # FIXME: Some error trapping code
}
-if ($label_element eq 'layout') {$db_rows = get_all_layouts();}
-elsif ($label_element eq 'template') {$db_rows = get_all_templates();}
-elsif ($label_element eq 'profile') {$db_rows = get_all_profiles();}
-elsif ($label_element eq 'batch') {$db_rows = get_batch_summary(filter => "branch_code=\'$branch_code\' OR branch_code=\'NB\'");}
+if ($label_element eq 'layout') {$db_rows = get_all_layouts(table_name => 'creator_layouts', filter => 'creator=\'Labels\'');}
+elsif ($label_element eq 'template') {$db_rows = get_all_templates(table_name => 'creator_templates', filter => 'creator=\'Labels\'');}
+elsif ($label_element eq 'profile') {$db_rows = get_all_profiles(table_name => 'printers_profile', filter => 'creator=\'Labels\'');}
+elsif ($label_element eq 'batch') {$db_rows = get_batch_summary(filter => "branch_code=\'$branch_code\' OR branch_code=\'NB\'", creator => 'Labels');}
else {} # FIXME: Some error trapping code
my $table = html_table($display_columns->{$label_element}, $db_rows);
-$template->param(error => $error) if ($error ne 0);
+$template->param(error => $error) if ($error) && ($error ne 0);
$template->param(print => 1) if ($label_element eq 'batch');
$template->param(
op => $op,
# Copyright 2009 Foundations Bible College.
#
# This file is part of Koha.
-#
+#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
use C4::Auth qw(get_template_and_user);
use C4::Output qw(output_html_with_http_headers);
-use C4::Labels::Lib 1.000000 qw(get_all_templates get_all_layouts get_label_output_formats);
+use C4::Creators::Lib 1.000000 qw(get_all_templates get_all_layouts get_output_formats);
use C4::Labels::Batch 1.000000;
my $cgi = new CGI;
my $op = $cgi->param('op') || 'none';
my @label_ids = $cgi->param('label_id') if $cgi->param('label_id'); # this will handle individual label printing
my @batch_ids = $cgi->param('batch_id') if $cgi->param('batch_id');
-my $layout_id = $cgi->param('layout_id') || undef;
-my $template_id = $cgi->param('template_id') || undef;
+my $layout_id = $cgi->param('layout_id') || undef;
+my $template_id = $cgi->param('template_id') || undef;
my $start_label = $cgi->param('start_label') || 1;
my @item_numbers = $cgi->param('item_number') if $cgi->param('item_number');
my $output_format = $cgi->param('output_format') || 'pdf';
my $layouts = undef;
my $templates = undef;
-my $label_output_formats = undef;
+my $output_formats = undef;
my @batches = ();
my $multi_batch_count = scalar(@batch_ids);
my $label_count = scalar(@label_ids);
@batch_ids = grep{$_ = {batch_id => $_}} @batch_ids;
@label_ids = grep{$_ = {label_id => $_}} @label_ids;
@item_numbers = grep{$_ = {item_number => $_}} @item_numbers;
- $templates = get_all_templates(field_list => 'template_id, template_code');
- $layouts = get_all_layouts(field_list => 'layout_id, layout_name');
- $label_output_formats = get_label_output_formats();
+ $templates = get_all_templates(field_list => 'template_id, template_code', filter => 'creator = "Labels"');
+ $layouts = get_all_layouts(field_list => 'layout_id, layout_name', filter => 'creator = "Labels"');
+ $output_formats = get_output_formats();
$template->param(
batch_ids => \@batch_ids,
label_ids => \@label_ids,
item_numbers => \@item_numbers,
templates => $templates,
layouts => $layouts,
- label_output_formats => $label_output_formats,
+ output_formats => $output_formats,
multi_batch_count => $multi_batch_count,
label_count => $label_count,
item_count => $item_count,