From 51db13b8da9a63f0f08e361f61ed9df36f4e236a Mon Sep 17 00:00:00 2001 From: Chris Nighswonger Date: Mon, 10 Aug 2009 16:32:01 -0400 Subject: [PATCH] [23/40] Initial work on label export interface. --- C4/Labels/Lib.pm | 25 +- C4/Labels/PDF.pm | 8 +- C4/Labels/Template.pm | 5 +- .../prog/en/css/staff-global.css | 10 + .../prog/en/modules/labels/label-manage.tmpl | 39 ++- .../prog/en/modules/labels/label-print.tmpl | 277 ++++++------------ ...label-print-csv.pl => label-create-csv.pl} | 0 ...label-print-pdf.pl => label-create-pdf.pl} | 2 +- labels/label-manage.pl | 1 + labels/label-print.pl | 83 ++++++ 10 files changed, 256 insertions(+), 194 deletions(-) rename labels/{label-print-csv.pl => label-create-csv.pl} (100%) rename labels/{label-print-pdf.pl => label-create-pdf.pl} (99%) create mode 100755 labels/label-print.pl diff --git a/C4/Labels/Lib.pm b/C4/Labels/Lib.pm index 4a918ac28b..f2e205630e 100644 --- a/C4/Labels/Lib.pm +++ b/C4/Labels/Lib.pm @@ -37,6 +37,7 @@ BEGIN { get_label_types get_font_types get_text_justification_types + get_label_output_formats get_column_names get_table_names get_unit_values @@ -125,6 +126,11 @@ my $unit_values = [ {type => 'CM', desc => 'SI Centimeters', value => 28.3464567, selected => 0}, ]; +my $label_output_formats = [ + {type => 'pdf', desc => 'PDF File'}, + {type => 'csv', desc => 'CSV File'}, +]; + =head2 C4::Labels::Lib::get_all_templates() This function returns a reference to a hash containing all templates upon success and 1 upon failure. Errors are logged to the syslog. @@ -164,8 +170,11 @@ sub get_all_templates { =cut sub get_all_layouts { + my %params = @_; my @layouts = (); - my $query = "SELECT * FROM labels_layouts;"; + #my $query = "SELECT * FROM labels_layouts;"; + my $query = "SELECT " . ($params{'field_list'} ? $params{'field_list'} : '*') . " FROM labels_layouts"; + $query .= ($params{'filter'} ? " WHERE $params{'filter'};" : ';'); my $sth = C4::Context->dbh->prepare($query); $sth->execute(); if ($sth->err) { @@ -369,6 +378,20 @@ sub get_unit_values { return $unit_values; } +=head2 C4::Labels::Lib::get_label_output_formats() + + This function returns a reference to an array of hashes containing all label output formats along with their description. + + examples: + + my $label_output_formats = get_label_output_formats(); + +=cut + +sub get_label_output_formats { + return $label_output_formats; +} + =head2 C4::Labels::Lib::get_column_names($table_name) Return an arrayref of an array containing the column names of the supplied table. diff --git a/C4/Labels/PDF.pm b/C4/Labels/PDF.pm index d95ba213ae..b661d45046 100644 --- a/C4/Labels/PDF.pm +++ b/C4/Labels/PDF.pm @@ -40,6 +40,8 @@ sub new { _InitVars() if ($opts{InitVars} == 0); _InitVars($opts{InitVars}) if ($opts{InitVars} > 0); delete($opts{InitVars}); + prDocDir($opts{'DocDir'}) if $opts{'DocDir'}; + delete($opts{'DocDir'}); prFile(%opts); bless ($self, $type); return $self; @@ -74,12 +76,6 @@ sub Doc { prDoc(%params); } -sub DocDir { - my $self = shift; - my $directoryName = shift; - prDocDir($directoryName); -} - sub DocForm { my $self = shift; my %params = @_; diff --git a/C4/Labels/Template.pm b/C4/Labels/Template.pm index 5410d99cd5..977fae90d9 100644 --- a/C4/Labels/Template.pm +++ b/C4/Labels/Template.pm @@ -90,8 +90,7 @@ sub _conv_points { sub _apply_profile { my $self = shift; - my $profile_id = shift; - my $profile = C4::Labels::Profile->retrieve(profile_id => $profile_id, convert => 1); + 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 @@ -179,7 +178,7 @@ sub retrieve { } my $self = $sth->fetchrow_hashref; $self = _conv_points($self) if (($opts{convert} && $opts{convert} == 1) || $opts{profile_id}); - $self = _apply_profile($self, $opts{profile_id}) if $opts{profile_id}; + $self = _apply_profile($self) if $opts{profile_id}; $self->{'tmpl_stat'} = 1; bless ($self, $type); return $self; diff --git a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css index 5324c70ae1..deef8775bb 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css +++ b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css @@ -227,6 +227,11 @@ table { border-right : 1px solid #BCBCBC; } +table.borderless { + border-collapse : separate; + border: 0 none; +} + #label-search-results { width: 700px; } @@ -241,6 +246,11 @@ td { background-color : White; } +td.borderless { + border-collapse : separate; + border : 0 none; +} + th { background-color : #E8E8E8; font-weight : bold; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-manage.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-manage.tmpl index 609b32fe81..40874a08e7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-manage.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-manage.tmpl @@ -31,12 +31,45 @@ function Print() { var element_id = selected_layout("print"); if (element_id>-1) { - window.location = "/cgi-bin/koha/labels/label-edit-.pl?op=edit&element_id=" + element_id; + window.location = "/cgi-bin/koha/labels/label-print.pl?batch_id=" + element_id; } else { return; // no layout selected }; }; + + + function Xport() { + batches= new Array; + if(document.layouts.action.length > 0) { + for (var i=0; i < document.layouts.action.length; i++) { + if (document.layouts.action[i].checked) { + batches.push("batch_id=" + document.layouts.action[i].value); + } + } + if (batches.length < 1) { + alert("Please select at least one batch to export."); + return; // no batch selected + } + getstr = batches.join("&"); + } + else if (document.layouts.action.checked) { + getstr = "batch_id="+document.layouts.action.value; + } + else { + alert("Please select at least one batch to export."); + return; // no batch selected + } + var msg = "Are you sure you want to export the selected batch(s)?" + var answer = confirm(msg); + if (answer) { + window.location = "/cgi-bin/koha/labels/label-print.pl?" + getstr; + } + else { + return; // abort export + } + }; + function selected_layout(op) { var selected = new Array; if (document.layouts.action.length) { @@ -112,13 +145,13 @@
- +
-
+
WARNING: An error was encountered and was not deleted. Please have your system administrator check the syslog for details.
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-print.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-print.tmpl index 8898b5fda4..1468d73784 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-print.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-print.tmpl @@ -1,181 +1,98 @@ - - - - -Print Preview - - + + Koha › Tools › Labels › Label Printing/Exporting + + + - -
-

Print Preview
- Barcodetype:
- Papertype:
- Field Options: Author - Itemtype - Title - ISBN - Dewey - Class - Subclass - Itemcallnumber - -

-
- - - - - - - - - - - - - - - -

- Back   - Print   -
- - - - +
+
+ +
+ +
+
+

Click on the following link(s) to download the exported batch(es).

+
+
+
+ + + + + + +
+ ?batch_id=&template_id=&layout_id=&start_label=">label_batch_.pdf +
+
+
+ +
+
+ +
+
+

batch(es) to export.

+
+
+
+ + + " /> + +
+ + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+ + + +
+
+
+ + Cancel +
+
+ +
+ diff --git a/labels/label-print-csv.pl b/labels/label-create-csv.pl similarity index 100% rename from labels/label-print-csv.pl rename to labels/label-create-csv.pl diff --git a/labels/label-print-pdf.pl b/labels/label-create-pdf.pl similarity index 99% rename from labels/label-print-pdf.pl rename to labels/label-create-pdf.pl index 1c6bbba184..9c2812822e 100755 --- a/labels/label-print-pdf.pl +++ b/labels/label-create-pdf.pl @@ -48,7 +48,7 @@ my $template_id = $cgi->param('template_id') || $ARGV[1]; my $layout_id = $cgi->param('layout_id') || $ARGV[2]; my $start_label = $cgi->param('start_label') || $ARGV[3]; -print $cgi->header( -type => 'application/pdf', -attachment => "koha_batch_$batch_id.pdf" ); +print $cgi->header( -type => 'application/pdf', -attachment => "label_batch_$batch_id.pdf" ); my $pdf = C4::Labels::PDF->new(InitVars => 0); my $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id); diff --git a/labels/label-manage.pl b/labels/label-manage.pl index 8c90f4493e..427adad133 100755 --- a/labels/label-manage.pl +++ b/labels/label-manage.pl @@ -77,6 +77,7 @@ my $display_columns = { layout => [ #db column => display column my $label_element = $cgi->param('label_element'); my $op = $cgi->param('op'); my $element_id = $cgi->param('element_id'); + my $branch_code = ($label_element eq 'batch' ? get_branch_code_from_name($template->param('LoginBranchname')) : ''); if ($op eq 'delete') { diff --git a/labels/label-print.pl b/labels/label-print.pl new file mode 100755 index 0000000000..32eeb076f3 --- /dev/null +++ b/labels/label-print.pl @@ -0,0 +1,83 @@ +#!/usr/bin/perl +# +# 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 +# version. +# +# 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. +# +# 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 + +use strict; +use warnings; + +use CGI; +use HTML::Template::Pro; +use Data::Dumper; + +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); + +my $cgi = new CGI; +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "labels/label-print.tmpl", + query => $cgi, + type => "intranet", + authnotrequired => 0, + flagsrequired => { catalogue => 1 }, + debug => 1, + } +); + +my $op = $cgi->param('op') || 'none'; +my @select_labels = $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 $start_label = $cgi->param('start_label') || 1; +my $output_format = $cgi->param('output_format') || 'pdf'; +my $layouts = undef; +my $templates = undef; +my $label_output_formats = undef; +my @batches = (); +my $multi_batch_count = scalar(@batch_ids); + +if ($op eq 'export') { + foreach my $batch_id (@batch_ids) { + push (@batches, {create_script => ($output_format eq 'pdf' ? 'label-create-pdf.pl' : 'label-create-csv.pl'), + batch_id => $batch_id, + template_id => $template_id, + layout_id => $layout_id, + start_label => $start_label, + }); + } + $template->param( + batches => \@batches, + ); +} +elsif ($op eq 'none') { + # setup select menus for selecting layout and template for this run... + @batch_ids = grep{$_ = {batch_id => $_}} @batch_ids; + $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(); + $template->param( + batch_ids => \@batch_ids, + templates => $templates, + layouts => $layouts, + label_output_formats => $label_output_formats, + multi_batch_count => $multi_batch_count, + ); +} +output_html_with_http_headers $cgi, $cookie, $template->output; -- 2.39.2