[23/40] Initial work on label export interface.
authorChris Nighswonger <cnighswonger@foundations.edu>
Mon, 10 Aug 2009 20:32:01 +0000 (16:32 -0400)
committerChris Nighswonger <cnighswonger@foundations.edu>
Tue, 1 Sep 2009 19:51:47 +0000 (15:51 -0400)
C4/Labels/Lib.pm
C4/Labels/PDF.pm
C4/Labels/Template.pm
koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css
koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-manage.tmpl
koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-print.tmpl
labels/label-create-csv.pl [moved from labels/label-print-csv.pl with 100% similarity]
labels/label-create-pdf.pl [moved from labels/label-print-pdf.pl with 99% similarity]
labels/label-manage.pl
labels/label-print.pl [new file with mode: 0755]

index 4a918ac..f2e2056 100644 (file)
@@ -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.
index d95ba21..b661d45 100644 (file)
@@ -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 = @_;
index 5410d99..977fae9 100644 (file)
@@ -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;
index 5324c70..deef877 100644 (file)
@@ -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;
index 609b32f..40874a0 100644 (file)
             function Print() {
                 var element_id = selected_layout("print");
                 if (element_id>-1) {
-                    window.location = "/cgi-bin/koha/labels/label-edit-<!-- TMPL_VAR NAME="label_element" -->.pl?op=edit&amp;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) {
                             <div style="margin: 10px 10px 10px 0px;">
                                 <span class="yui-button yui-link-button"><span class="first-child"><input type="button" id="edit" onclick="Edit()" value="Edit"></span></span>
                                 <span class="yui-button yui-link-button"><span class="first-child"><input type="button" id="delete" onclick="DeleteConfirm()" value="Delete"></span></span>
-                                <!-- TMPL_IF NAME="print" --><span class="yui-button yui-link-button"><span class="first-child"><input type="button" id="print" onclick="Print()" value="Print"></span></span><!-- /TMPL_IF -->
+                                <!-- TMPL_IF NAME="print" --><span class="yui-button yui-link-button"><span class="first-child"><input type="button" id="print" onclick="Xport()" value="Export"></span></span><!-- /TMPL_IF -->
                             </div>
                             </form>
                         </div>
                         <!-- TMPL_IF NAME="error" -->
                         <div class="yui-u">
-                            <div class="dialog alert">
+                            <div class="alert">
                                 <strong>WARNING: 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 syslog for details.</strong>
                             </div>
                         </div>
index 8898b5f..1468d73 100644 (file)
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<html>
-<head>
-<meta http-equiv="content-type" content="text/html; charset=utf-8">
-<title>Print Preview</title>
-<style type="text/css" media="screen">
-/* need to set print margins for sheet */
-body {
-        margin:48px; /* 1/2" at 96dpi */
-/*      margin:36px */  /* 1/2" at 72dpi */
-}
-/*
-8 1/2" x 11" sheet size
-
-spine data
-        1 1/4"H x 1"W
-                at 96dpi -> 120px H x 96px W
-                at 72dpi -> 90px H x 72px W
-space between cells - 1/2"
-        at 96dpi -> 48px
-        at 72dpi -> 36px
-circ data
-        1 1/4"H x 2 7/8"W
-                at 96dpi -> 120px H x 276px W
-                at 72dpi -> 90px H x 207px W
-*/
-table.print-preview {
-        border-collapse:collapse;
-        border-spacing:0;
-        empty-cells: show;
-}
-.print-preview td {
-        font-family:arial,helvetica,sans-serif;
-        font-size:10px;
-        padding:0 4px 0 4px
-}
-/* 96dpi */
-.spine-label-8511 {
-        border:dashed 1px #999999;
-        width: 88px;
-        height: 112px;
-        text-align: center
-}
-.space-8511 {
-        width:40px
-}
-.circ-label-8511 {
-        border:dashed 1px #999999;
-        width:268px;
-        text-align: center
-}
-/* 72dpi
-.spine-label-8511 {
-        border:dashed 1px #999999;
-        width: 64px;
-        height: 82px;
-        text-align: center
-}
-.space-8511 {
-        width:28px
-}
-.circ-label-8511 {
-        border:dashed 1px #999999;
-        width:199px;
-        text-align: center
-}
-*/
-</style>
-<style type="text/css" media="print">
-/* need to set print margins for sheet */
-body {
-        margin:48px; /* 1/2" at 96dpi */
-        /*      margin:36px */  /* 1/2" at 72dpi */
-}
-.noprint {
-        display:none
-}
-table.print-preview {
-        border-collapse:collapse;
-        border-spacing:0;
-}
-/* need to set printer font size */
-.print-preview td {
-        font-family:arial,helvetica,sans-serif;
-        font-size:10px;
-        padding:0 4px 0 4px
-}
-/* 96dpi */
-.spine-label-8511 {
-        border:dashed 1px #999999;
-        width: 88px;
-        height: 112px;
-}
-.space-8511 {
-        width:40px;
-}
-.circ-label-8511 {
-        border:dashed 1px #999999;
-        width:268px;
-        height:112px;
-}
-/* 72dpi
-.spine-label-8511 {
-        border:none;
-        width: 64px;
-        height: 82px;
-        text-align: center
-}
-.space-8511 {
-        width:28px
-}
-.circ-label-8511 {
-        border:none;
-        width:199px;
-        text-align: left
-}
-*/
-</style>
+    <!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
+    <title>Koha &rsaquo; Tools &rsaquo; Labels &rsaquo; Label Printing/Exporting</title>
+    <!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+    <style type="text/css">#custom-doc {width:47.23em; *width:46.04em; min-width:610px; margin:auto; margin-top:0.4em;}</style>
+</head>
 <body>
-
-<div class="noprint">
-        <h3 class="bull">Print Preview<br />
-        Barcodetype:<!-- TMPL_VAR NAME="barcodetype_opt" --><br />
-        Papertype:<!-- TMPL_VAR NAME="papertype_opt" --><br />
-        Field Options: <!-- TMPL_IF NAME="author_opt" -->Author <!-- /TMPL_IF -->
-        <!-- TMPL_IF NAME="itemtype_opt" -->Itemtype <!-- /TMPL_IF -->
-        <!-- TMPL_IF NAME="title_opt" -->Title <!-- /TMPL_IF -->
-        <!-- TMPL_IF NAME="isbn_opt" -->ISBN <!-- /TMPL_IF -->
-        <!-- TMPL_IF NAME="dewey_opt" -->Dewey <!-- /TMPL_IF -->
-        <!-- TMPL_IF NAME="class_opt" -->Class<!-- /TMPL_IF -->
-       <!-- TMPL_IF NAME="subclass_opt" -->Subclass<!-- /TMPL_IF -->
-       <!-- TMPL_IF NAME="itemcallnumber_opt" -->Itemcallnumber<!-- /TMPL_IF -->
-
-</h3>
-</div>
-
-
-<table summary="print preview" class="print-preview">
-
-<!-- TMPL_LOOP NAME="resultsloop" -->
-<tr>
-        <td class="spine-label-8511">
-      <!-- TMPL_IF NAME="itemtype_opt" --><!-- TMPL_VAR NAME="itemtype" --><br /><!-- /TMPL_IF -->
-      <!-- TMPL_IF NAME="papertype_opt" --><!-- TMPL_VAR NAME="papertype" --><br /><!-- /TMPL_IF -->
-      <!-- TMPL_IF NAME="author_opt" --><!-- TMPL_VAR NAME="author" --><br /><!-- /TMPL_IF -->
-      <!-- TMPL_IF NAME="title_opt" --><!-- TMPL_VAR NAME="title" --><br /><!-- /TMPL_IF -->
-      <!-- TMPL_IF NAME="isbn_opt" --><!-- TMPL_VAR NAME="isbn" --><br /><!-- /TMPL_IF -->
-      <!-- TMPL_IF NAME="dewey_opt" --><!-- TMPL_VAR NAME="dewey" --><br /><!-- /TMPL_IF -->
-      <!-- TMPL_IF NAME="class_opt" --><!-- TMPL_VAR NAME="class" --><!-- /TMPL_IF -->
-      <!-- TMPL_IF NAME="subclass_opt" --><!-- TMPL_VAR NAME="subclass" --><!-- /TMPL_IF -->
-      <!-- TMPL_IF NAME="itemcallnumber_opt" --><!-- TMPL_VAR NAME="itemcallnumber" --><!-- /TMPL_IF -->
-        </td>
-        <td class="space-8511">&nbsp;</td>
-        <td class="circ-label-8511">
-                <img src="/intranet-tmpl/barcodes/<!-- TMPL_VAR NAME="barcodetype_opt" -->-<!-- TMPL_VAR NAME="barcode" -->.png">
- <!-- TMPL_IF NAME="barcodeerror" -->
-                <div class="noprint">'<!-- TMPL_VAR NAME="barcode" -->'<br />
-        not '<!-- TMPL_VAR NAME="barcodetype_opt" -->' format.</div>
-        <!-- /TMPL_IF -->
-        </td>
-        <td class="space-8511">&nbsp;</td>
-        <td class="circ-label-8511">
-                <img src="/intranet-tmpl/barcodes/<!-- TMPL_VAR NAME="barcodetype_opt" -->-<!-- TMPL_VAR NAME="barcode" -->.png">
-        <!-- TMPL_IF NAME="barcodeerror" -->
-                <div class="noprint">'<!-- TMPL_VAR NAME="barcode" -->'<br />
-        not '<!-- TMPL_VAR NAME="barcodetype_opt" -->' format.</div>
-        <!-- /TMPL_IF -->
-        </td>
-</tr>
-<!-- /TMPL_LOOP -->
-</table>
-
-<div class="noprint"><br />
-       <a href="/cgi-bin/koha/barcodes/label-manager.pl"
-class="button">Back</a> &nbsp;
-       <a href="/cgi-bin/koha/barcodes/label-print-pdf.pl" class="button">Print</a> &nbsp;
-</div>
-
-
-</body>
-</html>
+    <div id="custom-doc" class="yui-t2">
+        <div id="bd">
+            <!-- TMPL_IF NAME="batches" -->
+            <form name="exporting" method="post" action="/cgi-bin/koha/labels/label-manage.pl">
+                <input type="hidden" name="label_element" value="batch" />
+                <div align="center">
+                    <div class="message">
+                        <h2>Click on the following link(s) to download the exported batch(es).</h2>
+                    </div>
+                </div>
+                <fieldset class="rows">
+                    <table class="borderless">
+                        <!-- TMPL_LOOP NAME="batches" -->
+                        <tr>
+                            <td class="borderless">
+                                <a href="/cgi-bin/koha/labels/<!-- TMPL_VAR NAME="create_script" -->?batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;template_id=<!-- TMPL_VAR NAME="template_id" -->&amp;layout_id=<!-- TMPL_VAR NAME="layout_id" -->&amp;start_label=<!-- TMPL_VAR NAME="start_label" -->">label_batch_<!-- TMPL_VAR NAME="batch_id" -->.pdf</a>
+                            </td>
+                        </tr>
+                        <!-- /TMPL_LOOP -->
+                    </table>
+                </fieldset>
+                <fieldset class="action">
+                    <input type="submit" value="Done" class="submit" />
+                </fieldset>
+            </form>
+            <!-- TMPL_ELSE -->
+            <div align="center">
+                <div class="message">
+                    <h2><!-- TMPL_VAR NAME="multi_batch_count" --> batch(es) to export.</h2>
+                </div>
+            </div>
+            <form name="exporting" method="post" action="/cgi-bin/koha/labels/label-print.pl">
+                <input type="hidden" name="op" value="export" />
+                <!-- TMPL_LOOP NAME="batch_ids" -->
+                    <input type="hidden" name="batch_id" value="<!-- TMPL_VAR NAME="batch_id" -->" />
+                <!-- /TMPL_LOOP -->
+                <fieldset class="rows">
+                    <table class="borderless">
+                        <tr>
+                            <td class="borderless">
+                                <label for="template">Select a template to be applied: </label>
+                            </td>
+                            <td class="borderless">
+                                <select name="template_id">
+                                    <!-- TMPL_LOOP NAME="templates" -->
+                                    <option value="<!-- TMPL_VAR NAME="template_id" -->"><!-- TMPL_VAR NAME="template_code"  --></option>
+                                    <!-- /TMPL_LOOP -->
+                                </select>
+                            </td>
+                        </tr>
+                        <tr>
+                            <td class="borderless">
+                                <label for="layout">Select a layout to be applied: </label>
+                            </td>
+                            <td class="borderless">
+                                <select name="layout_id">
+                                    <!-- TMPL_LOOP NAME="layouts" -->
+                                    <option value="<!-- TMPL_VAR NAME="layout_id" -->"><!-- TMPL_VAR NAME="layout_name"  --></option>
+                                    <!-- /TMPL_LOOP -->
+                                </select>
+                            </td>
+                        </tr>
+                        <tr>
+                            <td class="borderless">
+                                <label for="start_label">Enter starting label number: </label>
+                            </td>
+                            <td class="borderless">
+                                <input type="text" size="5" id="start_label" name="start_label" class="focus" title="Starting label number" value="1"/>
+                            </td>
+                        </tr>
+                        <tr>
+                            <td class="borderless">
+                                <label for="output_type">Select output format: </label>
+                            </td>
+                            <td class="borderless">
+                                <select name="output_format">
+                                    <!-- TMPL_LOOP NAME="label_output_formats" -->
+                                    <option value="<!-- TMPL_VAR NAME="type" -->"><!-- TMPL_VAR NAME="desc"  --></option>
+                                    <!-- /TMPL_LOOP -->
+                                </select>
+                            </td>
+                        </tr>
+                    </table>
+                </fieldset>
+                <fieldset class="action">
+                    <input type="submit" value="Export" class="submit" />
+                    <a class="cancel close" href="#">Cancel</a>
+                </fieldset>
+            </form>
+            <!-- /TMPL_IF -->
+        </div>
+    <!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
similarity index 99%
rename from labels/label-print-pdf.pl
rename to labels/label-create-pdf.pl
index 1c6bbba..9c28128 100755 (executable)
@@ -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);
index 8c90f44..427adad 100755 (executable)
@@ -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 (executable)
index 0000000..32eeb07
--- /dev/null
@@ -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;