1 package C4::Labels::Lib;
3 # Copyright 2009 Foundations Bible College.
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
22 use Sys::Syslog qw(syslog);
29 use version; our $VERSION = qv('1.0.0_1');
30 use base qw(Exporter);
31 our @EXPORT_OK = qw(get_all_templates
37 get_text_justification_types
46 {type => 'CODE39', name => 'Code 39', desc => 'Translates the characters 0-9, A-Z, \'-\', \'*\', \'+\', \'$\', \'%\', \'/\', \'.\' and \' \' to a barcode pattern.', selected => 0},
47 {type => 'CODE39MOD', name => 'Code 39 + Modulo43', desc => 'Translates the characters 0-9, A-Z, \'-\', \'*\', \'+\', \'$\', \'%\', \'/\', \'.\' and \' \' to a barcode pattern. Encodes Mod 43 checksum.', selected => 0},
48 {type => 'CODE39MOD10', name => 'Code 39 + Modulo10', desc => 'Translates the characters 0-9, A-Z, \'-\', \'*\', \'+\', \'$\', \'%\', \'/\', \'.\' and \' \' to a barcode pattern. Encodes Mod 10 checksum.', selected => 0},
49 {type => 'COOP2OF5', name => 'COOP2of5', desc => 'Creates COOP2of5 barcodes from a string consisting of the numeric characters 0-9', selected => 0},
50 # {type => 'EAN13', name => 'EAN13', desc => 'Creates EAN13 barcodes from a string of 12 or 13 digits. The check number (the 13:th digit) is calculated if not supplied.', selected => 0},
51 # {type => 'EAN8', name => 'EAN8', desc => 'Translates a string of 7 or 8 digits to EAN8 barcodes. The check number (the 8:th digit) is calculated if not supplied.', selected => 0},
52 # {type => 'IATA2of5', name => 'IATA2of5', desc => 'Creates IATA2of5 barcodes from a string consisting of the numeric characters 0-9', selected => 0},
53 {type => 'INDUSTRIAL2OF5', name => 'Industrial2of5', desc => 'Creates Industrial2of5 barcodes from a string consisting of the numeric characters 0-9', selected => 0},
54 # {type => 'ITF', name => 'Interleaved2of5', desc => 'Translates the characters 0-9 to a barcodes. These barcodes could also be called 'Interleaved2of5'.', selected => 0},
55 # {type => 'MATRIX2OF5', name => 'Matrix2of5', desc => 'Creates Matrix2of5 barcodes from a string consisting of the numeric characters 0-9', selected => 0},
56 # {type => 'NW7', name => 'NW7', desc => 'Creates a NW7 barcodes from a string consisting of the numeric characters 0-9', selected => 0},
57 # {type => 'UPCA', name => 'UPCA', desc => 'Translates a string of 11 or 12 digits to UPCA barcodes. The check number (the 12:th digit) is calculated if not supplied.', selected => 0},
58 # {type => 'UPCE', name => 'UPCE', desc => 'Translates a string of 6, 7 or 8 digits to UPCE barcodes. If the string is 6 digits long, '0' is added first in the string. The check number (the 8:th digit) is calculated if not supplied.', selected => 0},
62 {type => 'BIB', name => 'Biblio', desc => 'Only the bibliographic data is printed.', selected => 0},
63 {type => 'BARBIB', name => 'Barcode/Biblio', desc => 'Barcode proceeds bibliographic data.', selected => 0},
64 {type => 'BIBBAR', name => 'Biblio/Barcode', desc => 'Bibliographic data proceeds barcode.', selected => 0},
65 {type => 'ALT', name => 'Alternating', desc => 'Barcode and bibliographic data are printed on alternating labels.', selected => 0},
66 {type => 'BAR', name => 'Barcode', desc => 'Only the barcode is printed.', selected => 0},
70 {type => 'TR', name => 'Times-Roman', selected => 0},
71 {type => 'TB', name => 'Times-Bold', selected => 0},
72 {type => 'TI', name => 'Times-Italic', selected => 0},
73 {type => 'TBI', name => 'Times-Bold-Italic', selected => 0},
74 {type => 'C', name => 'Courier', selected => 0},
75 {type => 'CB', name => 'Courier-Bold', selected => 0},
76 {type => 'CO', name => 'Courier-Oblique', selected => 0},
77 {type => 'CBO', name => 'Courier-Bold-Oblique', selected => 0},
78 {type => 'H', name => 'Helvetica', selected => 0},
79 {type => 'HB', name => 'Helvetica-Bold', selected => 0},
80 {type => 'HBO', name => 'Helvetica-Bold-Oblique', selected => 0},
83 my $text_justification_types = [
84 {type => 'L', name => 'Left', selected => 0},
85 {type => 'C', name => 'Center', selected => 0},
86 {type => 'R', name => 'Right', selected => 0},
87 # {type => 'F', name => 'Full', selected => 0},
91 {type => 'POINT', desc => 'PostScript Points', value => 1, selected => 0},
92 {type => 'AGATE', desc => 'Adobe Agates', value => 5.1428571, selected => 0},
93 {type => 'INCH', desc => 'US Inches', value => 72, selected => 0},
94 {type => 'MM', desc => 'SI Millimeters', value => 2.83464567, selected => 0},
95 {type => 'CM', desc => 'SI Centimeters', value => 28.3464567, selected => 0},
98 =head2 C4::Labels::Lib::get_all_templates()
100 This function returns a reference to a hash containing all templates upon success and 1 upon failure. Errors are logged to the syslog.
104 my $templates = get_all_templates();
108 sub get_all_templates {
110 my $query = "SELECT * FROM labels_templates;";
111 my $sth = C4::Context->dbh->prepare($query);
114 syslog("LOG_ERR", "C4::Labels::Lib::get_all_templates : Database returned the following error: %s", $sth->errstr);
118 while (my $template = $sth->fetchrow_hashref) {
119 push(@templates, $template);
124 =head2 C4::Labels::Lib::get_all_layouts()
126 This function returns a reference to a hash containing all layouts upon success and 1 upon failure. Errors are logged to the syslog.
130 my $layouts = get_all_layouts();
134 sub get_all_layouts {
136 my $query = "SELECT * FROM labels_layouts;";
137 my $sth = C4::Context->dbh->prepare($query);
140 syslog("LOG_ERR", "C4::Labels::Lib::get_all_layouts : Database returned the following error: %s", $sth->errstr);
144 while (my $layout = $sth->fetchrow_hashref) {
145 push(@layouts, $layout);
150 =head2 C4::Labels::Lib::get_all_profiles()
152 This function returns an arrayref whose elements are hashes containing all profiles upon success and 1 upon failure. Errors are logged
153 to the syslog. Two parameters are accepted. The first limits the field(s) returned. This parameter should be string of comma separted
154 fields. ie. "field_1, field_2, ...field_n" The second limits the records returned based on a string containing a valud SQL 'WHERE' filter.
155 NOTE: Do not pass in the keyword 'WHERE.'
159 my $profiles = get_all_profiles();
160 my $profiles = get_all_profiles(field_list => field_list, filter => filter_string);
164 sub get_all_profiles {
167 my $query = "SELECT " . ($params{'field_list'} ? $params{'field_list'} : '*') . " FROM printers_profile";
168 $query .= ($params{'filter'} ? " WHERE $params{'filter'};" : ';');
169 my $sth = C4::Context->dbh->prepare($query);
170 # $sth->{'TraceLevel'} = 3 if $debug;
173 syslog("LOG_ERR", "C4::Labels::Lib::get_all_profiles : Database returned the following error: %s", $sth->errstr);
177 while (my $profile = $sth->fetchrow_hashref) {
178 push(@profiles, $profile);
183 =head2 C4::Labels::Lib::get_barcode_types()
185 This function returns a reference to an array of hashes containing all barcode types along with their name and description.
189 my $barcode_types = get_barcode_types();
193 sub get_barcode_types {
194 return $barcode_types;
197 =head2 C4::Labels::Lib::get_label_types()
199 This function returns a reference to an array of hashes containing all label types along with their name and description.
203 my $label_types = get_label_types();
207 sub get_label_types {
211 =head2 C4::Labels::Lib::get_font_types()
213 This function returns a reference to an array of hashes containing all font types along with their name and description.
217 my $font_types = get_font_types();
225 =head2 C4::Labels::Lib::get_text_justification_types()
227 This function returns a reference to an array of hashes containing all text justification types along with their name and description.
231 my $text_justification_types = get_text_justification_types();
235 sub get_text_justification_types {
236 return $text_justification_types;
239 =head2 C4::Labels::Lib::get_unit_values()
241 This function returns a reference to an array of hashes containing all unit types along with their description and multiplier. NOTE: All units are relative to a PostScript Point.
242 There are 72 PS points to the inch.
246 my $unit_values = get_unit_values();
250 sub get_unit_values {
254 =head2 C4::Labels::Lib::get_column_names($table_name)
256 Return an arrayref of an array containing the column names of the supplied table.
260 sub get_column_names {
262 my $dbh = C4::Context->dbh();
263 my $column_names = [];
264 my $sth = $dbh->column_info(undef,undef,$table,'%');
265 while (my $info = $sth->fetchrow_hashref()){
266 $$column_names[$info->{'ORDINAL_POSITION'}] = $info->{'COLUMN_NAME'};
268 return $column_names;
271 =head2 C4::Labels::Lib::get_table_names($search_term)
273 Return an arrayref of an array containing the table names which contain the supplied search term.
277 sub get_table_names {
278 my $search_term = shift;
279 my $dbh = C4::Context->dbh();
280 my $table_names = [];
281 my $sth = $dbh->table_info(undef,undef,"%$search_term%");
282 while (my $info = $sth->fetchrow_hashref()){
283 push (@$table_names, $info->{'TABLE_NAME'});
288 =head2 C4::Labels::Lib::SELECT()
290 This function returns a recordset upon success and 1 upon failure. Errors are logged to the syslog.
294 my $field_value = SELECT(field_name, table_name, condition);
300 my $query = "SELECT $params[0] FROM $params[1]";
301 $params[2] ? $query .= " WHERE $params[2];" : $query .= ';';
302 my $sth = C4::Context->dbh->prepare($query);
303 # $sth->{'TraceLevel'} = 3;
306 syslog("LOG_ERR", "C4::Labels::Lib::get_single_field_value : Database returned the following error: %s", $sth->errstr);
310 while (my $row = $sth->fetchrow_hashref()) {
311 push(@$record_set, $row);
321 Chris Nighswonger <cnighswonger AT foundations DOT edu>