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 {
111 my $query = "SELECT " . ($params{'field_list'} ? $params{'field_list'} : '*') . " FROM labels_templates";
112 $query .= ($params{'filter'} ? " WHERE $params{'filter'};" : ';');
113 my $sth = C4::Context->dbh->prepare($query);
116 syslog("LOG_ERR", "C4::Labels::Lib::get_all_templates : Database returned the following error: %s", $sth->errstr);
120 while (my $template = $sth->fetchrow_hashref) {
121 push(@templates, $template);
126 =head2 C4::Labels::Lib::get_all_layouts()
128 This function returns a reference to a hash containing all layouts upon success and 1 upon failure. Errors are logged to the syslog.
132 my $layouts = get_all_layouts();
136 sub get_all_layouts {
138 my $query = "SELECT * FROM labels_layouts;";
139 my $sth = C4::Context->dbh->prepare($query);
142 syslog("LOG_ERR", "C4::Labels::Lib::get_all_layouts : Database returned the following error: %s", $sth->errstr);
146 while (my $layout = $sth->fetchrow_hashref) {
147 push(@layouts, $layout);
152 =head2 C4::Labels::Lib::get_all_profiles()
154 This function returns an arrayref whose elements are hashes containing all profiles upon success and 1 upon failure. Errors are logged
155 to the syslog. Two parameters are accepted. The first limits the field(s) returned. This parameter should be string of comma separted
156 fields. ie. "field_1, field_2, ...field_n" The second limits the records returned based on a string containing a valud SQL 'WHERE' filter.
157 NOTE: Do not pass in the keyword 'WHERE.'
161 my $profiles = get_all_profiles();
162 my $profiles = get_all_profiles(field_list => field_list, filter => filter_string);
166 sub get_all_profiles {
169 my $query = "SELECT " . ($params{'field_list'} ? $params{'field_list'} : '*') . " FROM printers_profile";
170 $query .= ($params{'filter'} ? " WHERE $params{'filter'};" : ';');
171 my $sth = C4::Context->dbh->prepare($query);
172 # $sth->{'TraceLevel'} = 3 if $debug;
175 syslog("LOG_ERR", "C4::Labels::Lib::get_all_profiles : Database returned the following error: %s", $sth->errstr);
179 while (my $profile = $sth->fetchrow_hashref) {
180 push(@profiles, $profile);
185 =head2 C4::Labels::Lib::get_barcode_types()
187 This function returns a reference to an array of hashes containing all barcode types along with their name and description.
191 my $barcode_types = get_barcode_types();
195 sub get_barcode_types {
196 return $barcode_types;
199 =head2 C4::Labels::Lib::get_label_types()
201 This function returns a reference to an array of hashes containing all label types along with their name and description.
205 my $label_types = get_label_types();
209 sub get_label_types {
213 =head2 C4::Labels::Lib::get_font_types()
215 This function returns a reference to an array of hashes containing all font types along with their name and description.
219 my $font_types = get_font_types();
227 =head2 C4::Labels::Lib::get_text_justification_types()
229 This function returns a reference to an array of hashes containing all text justification types along with their name and description.
233 my $text_justification_types = get_text_justification_types();
237 sub get_text_justification_types {
238 return $text_justification_types;
241 =head2 C4::Labels::Lib::get_unit_values()
243 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.
244 There are 72 PS points to the inch.
248 my $unit_values = get_unit_values();
252 sub get_unit_values {
256 =head2 C4::Labels::Lib::get_column_names($table_name)
258 Return an arrayref of an array containing the column names of the supplied table.
262 sub get_column_names {
264 my $dbh = C4::Context->dbh();
265 my $column_names = [];
266 my $sth = $dbh->column_info(undef,undef,$table,'%');
267 while (my $info = $sth->fetchrow_hashref()){
268 $$column_names[$info->{'ORDINAL_POSITION'}] = $info->{'COLUMN_NAME'};
270 return $column_names;
273 =head2 C4::Labels::Lib::get_table_names($search_term)
275 Return an arrayref of an array containing the table names which contain the supplied search term.
279 sub get_table_names {
280 my $search_term = shift;
281 my $dbh = C4::Context->dbh();
282 my $table_names = [];
283 my $sth = $dbh->table_info(undef,undef,"%$search_term%");
284 while (my $info = $sth->fetchrow_hashref()){
285 push (@$table_names, $info->{'TABLE_NAME'});
290 =head2 C4::Labels::Lib::SELECT()
292 This function returns a recordset upon success and 1 upon failure. Errors are logged to the syslog.
296 my $field_value = SELECT(field_name, table_name, condition);
302 my $query = "SELECT $params[0] FROM $params[1]";
303 $params[2] ? $query .= " WHERE $params[2];" : $query .= ';';
304 my $sth = C4::Context->dbh->prepare($query);
305 # $sth->{'TraceLevel'} = 3;
308 syslog("LOG_ERR", "C4::Labels::Lib::get_single_field_value : Database returned the following error: %s", $sth->errstr);
312 while (my $row = $sth->fetchrow_hashref()) {
313 push(@$record_set, $row);
323 Chris Nighswonger <cnighswonger AT foundations DOT edu>