[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)
12 files changed:
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 [new file with mode: 0755]
labels/label-create-pdf.pl [new file with mode: 0755]
labels/label-manage.pl
labels/label-print-csv.pl [deleted file]
labels/label-print-pdf.pl [deleted file]
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_types
                         get_font_types
                         get_text_justification_types
+                        get_label_output_formats
                         get_column_names
                         get_table_names
                         get_unit_values
                         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},
 ];
 
     {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.
 =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 {
 =cut
 
 sub get_all_layouts {
+    my %params = @_;
     my @layouts = ();
     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) {
     my $sth = C4::Context->dbh->prepare($query);
     $sth->execute();
     if ($sth->err) {
@@ -369,6 +378,20 @@ sub get_unit_values {
     return $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.
 =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});
     _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;
     prFile(%opts);
     bless ($self, $type);
     return $self;
@@ -74,12 +76,6 @@ sub Doc {
     prDoc(%params);
 }
 
     prDoc(%params);
 }
 
-sub DocDir {
-    my $self = shift;
-    my $directoryName = shift;
-    prDocDir($directoryName);
-}
-
 sub DocForm {
     my $self = shift;
     my %params = @_;
 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;
 
 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
     $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});
     }
     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;
     $self->{'tmpl_stat'} = 1;
     bless ($self, $type);
     return $self;
index 5324c70..deef877 100644 (file)
@@ -227,6 +227,11 @@ table {
        border-right : 1px solid #BCBCBC;
 }
 
        border-right : 1px solid #BCBCBC;
 }
 
+table.borderless {
+    border-collapse : separate;
+    border: 0 none;
+}
+
 #label-search-results {
         width: 700px;
 }
 #label-search-results {
         width: 700px;
 }
@@ -241,6 +246,11 @@ td {
        background-color : White;
 }
 
        background-color : White;
 }
 
+td.borderless {
+    border-collapse : separate;
+    border : 0 none;
+}
+
 th {
        background-color : #E8E8E8;
        font-weight : bold;
 th {
        background-color : #E8E8E8;
        font-weight : bold;
index 609b32f..40874a0 100644 (file)
             function Print() {
                 var element_id = selected_layout("print");
                 if (element_id>-1) {
             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
                 };
             };
                 }
                 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) {
             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>
                             <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>
                             </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>
                                 <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>
 <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" -->
diff --git a/labels/label-create-csv.pl b/labels/label-create-csv.pl
new file mode 100755 (executable)
index 0000000..be29afa
--- /dev/null
@@ -0,0 +1,55 @@
+#!/usr/bin/perl
+
+use strict;
+use CGI;
+use C4::Labels;
+use C4::Auth;
+use C4::Output;
+use C4::Context;
+use C4::Biblio;
+use Text::CSV_XS;
+
+my $DEBUG = 0;
+my $DEBUG_LPT = 0;
+
+my $htdocs_path = C4::Context->config('intrahtdocs');
+my $cgi         = new CGI;
+
+
+# get the printing settings
+my $template    = GetActiveLabelTemplate();
+my $conf_data   = get_label_options();
+
+my $batch_id =   $cgi->param('batch_id');
+my $exportname = 'koha_label_' . $batch_id . '.csv';
+
+print $cgi->header(-type => 'application/vnd.sun.xml.calc',
+                            -encoding    => 'utf-8',
+                            -attachment => $exportname,
+                            -filename => $exportname );
+
+my $batch_type   = $conf_data->{'type'};
+my $barcodetype  = $conf_data->{'barcodetype'};
+my $printingtype = $conf_data->{'printingtype'};
+
+my @resultsloop = GetLabelItems($batch_id);
+my $csv = Text::CSV_XS->new();
+my @str_fields = get_text_fields($conf_data->{'id'}, 'codes' );
+for my $item (@resultsloop) {
+    my $record = GetMarcBiblio($item->{biblionumber});
+    my @datafields = map { C4::Labels::GetBarcodeData($_->{'code'},$item,$record) } @str_fields ;
+       my $csvout ;
+       if($csv->combine(@datafields)) {
+               $csvout = $csv->string();
+               print "$csvout\n";
+       } else {
+               warn "CSV ERROR: " . $csv->error_input;
+       }
+
+}    # end for item loop
+
+exit(1);
+# is that the right way to do this ?
+
+
+
diff --git a/labels/label-create-pdf.pl b/labels/label-create-pdf.pl
new file mode 100755 (executable)
index 0000000..9c28128
--- /dev/null
@@ -0,0 +1,176 @@
+#!/usr/bin/perl
+
+# Copyright 2006 Katipo Communications.
+# Some 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
+# 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 POSIX qw(ceil);
+use Data::Dumper;
+use Sys::Syslog qw(syslog);
+
+use C4::Labels;
+use C4::Auth;
+use C4::Output;
+use C4::Context;
+use C4::Members;
+use C4::Branch;
+use C4::Debug;
+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::Labels::Label 1.000000;
+
+my $cgi = new CGI;
+
+my $htdocs_path = C4::Context->config('intrahtdocs');
+my $batch_id    = $cgi->param('batch_id') || $ARGV[0];
+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 => "label_batch_$batch_id.pdf" );
+
+my $pdf = C4::Labels::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);
+
+sub _calc_next_label_pos {
+    my ($row_count, $col_count, $llx, $lly) = @_;
+    if ($col_count lt $template->get_attr('cols')) {
+        $llx = ($llx + $template->get_attr('label_width') + $template->get_attr('col_gap'));
+        $col_count++;
+    }
+    else {
+        $llx = $template->get_attr('left_margin');
+        if ($row_count eq $template->get_attr('rows')) {
+            $pdf->Page();
+            $lly = ($template->get_attr('page_height') - $template->get_attr('top_margin') - $template->get_attr('label_height'));
+            $row_count = 1;
+        }
+        else {
+            $lly = ($lly - $template->get_attr('row_gap') - $template->get_attr('label_height'));
+            $row_count++;
+        }
+        $col_count = 1;
+    }
+    return ($row_count, $col_count, $llx, $lly);
+}
+
+sub _print_text {
+    my $label_text = shift;
+    foreach my $text_line (@$label_text) {
+        my $pdf_font = $pdf->Font($text_line->{'font'});
+        my $line = "BT /$pdf_font $text_line->{'font_size'} Tf $text_line->{'text_llx'} $text_line->{'text_lly'} Td ($text_line->{'line'}) Tj ET";
+        $pdf->Add($line);
+    }
+}
+
+$| = 1;
+
+# set the paper size
+my $lowerLeftX  = 0;
+my $lowerLeftY  = 0;
+my $upperRightX = $template->get_attr('page_width');
+my $upperRightY = $template->get_attr('page_height');
+
+$pdf->Compress(1);
+$pdf->Mbox($lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY);
+
+my ($row_count, $col_count, $llx, $lly) = $template->get_label_position($start_label);
+LABEL_ITEMS:
+foreach my $item (@{$batch->get_attr('items')}) {
+    my ($barcode_llx, $barcode_lly, $barcode_width, $barcode_y_scale_factor) = 0,0,0,0;
+    my $label = C4::Labels::Label->new(
+                                    batch_id            => $batch_id,
+                                    item_number         => $item->{'item_number'},
+                                    width               => $template->get_attr('label_width'),
+                                    height              => $template->get_attr('label_height'),
+                                    top_text_margin     => $template->get_attr('top_text_margin'),
+                                    left_text_margin    => $template->get_attr('left_text_margin'),
+                                    barcode_type        => $layout->get_attr('barcode_type'),
+                                    printing_type       => $layout->get_attr('printing_type'),
+                                    guidebox            => $layout->get_attr('guidebox'),
+                                    font                => $layout->get_attr('font'),
+                                    font_size           => $layout->get_attr('font_size'),
+                                    callnum_split       => $layout->get_attr('callnum_split'),
+                                    justify             => $layout->get_attr('text_justify'),
+                                    format_string       => $layout->get_attr('format_string'),
+                                    text_wrap_cols      => $layout->get_text_wrap_cols(label_width => $template->get_attr('label_width'), left_text_margin => $template->get_attr('left_text_margin')),
+                                      );
+    my $label_type = $label->get_label_type;
+    if ($label_type eq 'BIB') {
+        my $line_spacer = ($label->get_attr('font_size') * 1);    # number of pixels between text rows (This is actually leading: baseline to baseline minus font size. Recommended starting point is 20% of font size.).
+        my $text_lly = ($lly + ($template->get_attr('label_height') - $template->get_attr('top_text_margin')));
+        my $label_text = $label->draw_label_text(
+                                        llx             => $llx,
+                                        lly             => $text_lly,
+                                        line_spacer     => $line_spacer,
+                                        );
+        _print_text($label_text);
+        ($row_count, $col_count, $llx, $lly) = _calc_next_label_pos($row_count, $col_count, $llx, $lly);
+        next LABEL_ITEMS;
+    }
+    elsif ($label_type eq 'BARBIB') {
+        $barcode_llx = $llx + $template->get_attr('left_text_margin');                             # this places the bottom left of the barcode the left text margin distance to right of the the left edge of the label ($llx)
+        $barcode_lly = ($lly + $template->get_attr('label_height')) - $template->get_attr('top_text_margin');        # this places the bottom left of the barcode the top text margin distance below the top of the label ($lly)
+        $barcode_width = 0.8 * $template->get_attr('label_width');                                 # this scales the barcode width to 80% of the label width
+        $barcode_y_scale_factor = 0.01 * $template->get_attr('label_height');                      # this scales the barcode height to 10% of the label height
+        my $line_spacer = ($label->get_attr('font_size') * 1);    # number of pixels between text rows (This is actually leading: baseline to baseline minus font size. Recommended starting point is 20% of font size.).
+        my $text_lly = ($lly + ($template->get_attr('label_height') - $template->get_attr('top_text_margin')));
+        my $label_text = $label->draw_label_text(
+                                        llx             => $llx,
+                                        lly             => $text_lly,
+                                        line_spacer     => $line_spacer,
+                                        );
+        _print_text($label_text);
+    }
+    else {
+        $barcode_llx = $llx + $template->get_attr('left_text_margin');             # this places the bottom left of the barcode the left text margin distance to right of the the left edge of the label ($llx)
+        $barcode_lly = $lly + $template->get_attr('top_text_margin');              # this places the bottom left of the barcode the top text margin distance above the bottom of the label ($lly)
+        $barcode_width = 0.8 * $template->get_attr('label_width');                 # this scales the barcode width to 80% of the label width
+        $barcode_y_scale_factor = 0.01 * $template->get_attr('label_height');      # this scales the barcode height to 10% of the label height
+        if ($label_type eq 'BIBBAR' || $label_type eq 'ALT') {
+            my $line_spacer = ($label->get_attr('font_size') * 1);    # number of pixels between text rows (This is actually leading: baseline to baseline minus font size. Recommended starting point is 20% of font size.).
+            my $text_lly = ($lly + ($template->get_attr('label_height') - $template->get_attr('top_text_margin')));
+            my $label_text = $label->draw_label_text(
+                                            llx             => $llx,
+                                            lly             => $text_lly,
+                                            line_spacer     => $line_spacer,
+                                            );
+            _print_text($label_text);
+        }
+        if ($label_type eq 'ALT') {
+        ($row_count, $col_count, $llx, $lly) = _calc_next_label_pos($row_count, $col_count, $llx, $lly);
+        }
+    }
+    $label->barcode(
+                llx                 => $barcode_llx,
+                lly                 => $barcode_lly,
+                width               => $barcode_width,
+                y_scale_factor      => $barcode_y_scale_factor,
+    );
+    ($row_count, $col_count, $llx, $lly) = _calc_next_label_pos($row_count, $col_count, $llx, $lly);
+}
+
+$pdf->End();
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 $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') {
 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-csv.pl b/labels/label-print-csv.pl
deleted file mode 100755 (executable)
index be29afa..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use CGI;
-use C4::Labels;
-use C4::Auth;
-use C4::Output;
-use C4::Context;
-use C4::Biblio;
-use Text::CSV_XS;
-
-my $DEBUG = 0;
-my $DEBUG_LPT = 0;
-
-my $htdocs_path = C4::Context->config('intrahtdocs');
-my $cgi         = new CGI;
-
-
-# get the printing settings
-my $template    = GetActiveLabelTemplate();
-my $conf_data   = get_label_options();
-
-my $batch_id =   $cgi->param('batch_id');
-my $exportname = 'koha_label_' . $batch_id . '.csv';
-
-print $cgi->header(-type => 'application/vnd.sun.xml.calc',
-                            -encoding    => 'utf-8',
-                            -attachment => $exportname,
-                            -filename => $exportname );
-
-my $batch_type   = $conf_data->{'type'};
-my $barcodetype  = $conf_data->{'barcodetype'};
-my $printingtype = $conf_data->{'printingtype'};
-
-my @resultsloop = GetLabelItems($batch_id);
-my $csv = Text::CSV_XS->new();
-my @str_fields = get_text_fields($conf_data->{'id'}, 'codes' );
-for my $item (@resultsloop) {
-    my $record = GetMarcBiblio($item->{biblionumber});
-    my @datafields = map { C4::Labels::GetBarcodeData($_->{'code'},$item,$record) } @str_fields ;
-       my $csvout ;
-       if($csv->combine(@datafields)) {
-               $csvout = $csv->string();
-               print "$csvout\n";
-       } else {
-               warn "CSV ERROR: " . $csv->error_input;
-       }
-
-}    # end for item loop
-
-exit(1);
-# is that the right way to do this ?
-
-
-
diff --git a/labels/label-print-pdf.pl b/labels/label-print-pdf.pl
deleted file mode 100755 (executable)
index 1c6bbba..0000000
+++ /dev/null
@@ -1,176 +0,0 @@
-#!/usr/bin/perl
-
-# Copyright 2006 Katipo Communications.
-# Some 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
-# 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 POSIX qw(ceil);
-use Data::Dumper;
-use Sys::Syslog qw(syslog);
-
-use C4::Labels;
-use C4::Auth;
-use C4::Output;
-use C4::Context;
-use C4::Members;
-use C4::Branch;
-use C4::Debug;
-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::Labels::Label 1.000000;
-
-my $cgi = new CGI;
-
-my $htdocs_path = C4::Context->config('intrahtdocs');
-my $batch_id    = $cgi->param('batch_id') || $ARGV[0];
-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" );
-
-my $pdf = C4::Labels::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);
-
-sub _calc_next_label_pos {
-    my ($row_count, $col_count, $llx, $lly) = @_;
-    if ($col_count lt $template->get_attr('cols')) {
-        $llx = ($llx + $template->get_attr('label_width') + $template->get_attr('col_gap'));
-        $col_count++;
-    }
-    else {
-        $llx = $template->get_attr('left_margin');
-        if ($row_count eq $template->get_attr('rows')) {
-            $pdf->Page();
-            $lly = ($template->get_attr('page_height') - $template->get_attr('top_margin') - $template->get_attr('label_height'));
-            $row_count = 1;
-        }
-        else {
-            $lly = ($lly - $template->get_attr('row_gap') - $template->get_attr('label_height'));
-            $row_count++;
-        }
-        $col_count = 1;
-    }
-    return ($row_count, $col_count, $llx, $lly);
-}
-
-sub _print_text {
-    my $label_text = shift;
-    foreach my $text_line (@$label_text) {
-        my $pdf_font = $pdf->Font($text_line->{'font'});
-        my $line = "BT /$pdf_font $text_line->{'font_size'} Tf $text_line->{'text_llx'} $text_line->{'text_lly'} Td ($text_line->{'line'}) Tj ET";
-        $pdf->Add($line);
-    }
-}
-
-$| = 1;
-
-# set the paper size
-my $lowerLeftX  = 0;
-my $lowerLeftY  = 0;
-my $upperRightX = $template->get_attr('page_width');
-my $upperRightY = $template->get_attr('page_height');
-
-$pdf->Compress(1);
-$pdf->Mbox($lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY);
-
-my ($row_count, $col_count, $llx, $lly) = $template->get_label_position($start_label);
-LABEL_ITEMS:
-foreach my $item (@{$batch->get_attr('items')}) {
-    my ($barcode_llx, $barcode_lly, $barcode_width, $barcode_y_scale_factor) = 0,0,0,0;
-    my $label = C4::Labels::Label->new(
-                                    batch_id            => $batch_id,
-                                    item_number         => $item->{'item_number'},
-                                    width               => $template->get_attr('label_width'),
-                                    height              => $template->get_attr('label_height'),
-                                    top_text_margin     => $template->get_attr('top_text_margin'),
-                                    left_text_margin    => $template->get_attr('left_text_margin'),
-                                    barcode_type        => $layout->get_attr('barcode_type'),
-                                    printing_type       => $layout->get_attr('printing_type'),
-                                    guidebox            => $layout->get_attr('guidebox'),
-                                    font                => $layout->get_attr('font'),
-                                    font_size           => $layout->get_attr('font_size'),
-                                    callnum_split       => $layout->get_attr('callnum_split'),
-                                    justify             => $layout->get_attr('text_justify'),
-                                    format_string       => $layout->get_attr('format_string'),
-                                    text_wrap_cols      => $layout->get_text_wrap_cols(label_width => $template->get_attr('label_width'), left_text_margin => $template->get_attr('left_text_margin')),
-                                      );
-    my $label_type = $label->get_label_type;
-    if ($label_type eq 'BIB') {
-        my $line_spacer = ($label->get_attr('font_size') * 1);    # number of pixels between text rows (This is actually leading: baseline to baseline minus font size. Recommended starting point is 20% of font size.).
-        my $text_lly = ($lly + ($template->get_attr('label_height') - $template->get_attr('top_text_margin')));
-        my $label_text = $label->draw_label_text(
-                                        llx             => $llx,
-                                        lly             => $text_lly,
-                                        line_spacer     => $line_spacer,
-                                        );
-        _print_text($label_text);
-        ($row_count, $col_count, $llx, $lly) = _calc_next_label_pos($row_count, $col_count, $llx, $lly);
-        next LABEL_ITEMS;
-    }
-    elsif ($label_type eq 'BARBIB') {
-        $barcode_llx = $llx + $template->get_attr('left_text_margin');                             # this places the bottom left of the barcode the left text margin distance to right of the the left edge of the label ($llx)
-        $barcode_lly = ($lly + $template->get_attr('label_height')) - $template->get_attr('top_text_margin');        # this places the bottom left of the barcode the top text margin distance below the top of the label ($lly)
-        $barcode_width = 0.8 * $template->get_attr('label_width');                                 # this scales the barcode width to 80% of the label width
-        $barcode_y_scale_factor = 0.01 * $template->get_attr('label_height');                      # this scales the barcode height to 10% of the label height
-        my $line_spacer = ($label->get_attr('font_size') * 1);    # number of pixels between text rows (This is actually leading: baseline to baseline minus font size. Recommended starting point is 20% of font size.).
-        my $text_lly = ($lly + ($template->get_attr('label_height') - $template->get_attr('top_text_margin')));
-        my $label_text = $label->draw_label_text(
-                                        llx             => $llx,
-                                        lly             => $text_lly,
-                                        line_spacer     => $line_spacer,
-                                        );
-        _print_text($label_text);
-    }
-    else {
-        $barcode_llx = $llx + $template->get_attr('left_text_margin');             # this places the bottom left of the barcode the left text margin distance to right of the the left edge of the label ($llx)
-        $barcode_lly = $lly + $template->get_attr('top_text_margin');              # this places the bottom left of the barcode the top text margin distance above the bottom of the label ($lly)
-        $barcode_width = 0.8 * $template->get_attr('label_width');                 # this scales the barcode width to 80% of the label width
-        $barcode_y_scale_factor = 0.01 * $template->get_attr('label_height');      # this scales the barcode height to 10% of the label height
-        if ($label_type eq 'BIBBAR' || $label_type eq 'ALT') {
-            my $line_spacer = ($label->get_attr('font_size') * 1);    # number of pixels between text rows (This is actually leading: baseline to baseline minus font size. Recommended starting point is 20% of font size.).
-            my $text_lly = ($lly + ($template->get_attr('label_height') - $template->get_attr('top_text_margin')));
-            my $label_text = $label->draw_label_text(
-                                            llx             => $llx,
-                                            lly             => $text_lly,
-                                            line_spacer     => $line_spacer,
-                                            );
-            _print_text($label_text);
-        }
-        if ($label_type eq 'ALT') {
-        ($row_count, $col_count, $llx, $lly) = _calc_next_label_pos($row_count, $col_count, $llx, $lly);
-        }
-    }
-    $label->barcode(
-                llx                 => $barcode_llx,
-                lly                 => $barcode_lly,
-                width               => $barcode_width,
-                y_scale_factor      => $barcode_y_scale_factor,
-    );
-    ($row_count, $col_count, $llx, $lly) = _calc_next_label_pos($row_count, $col_count, $llx, $lly);
-}
-
-$pdf->End();
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;