3 # Copyright 2000-2002 Katipo Communications
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
24 use vars qw($VERSION @ISA @EXPORT);
30 C4::Koha - Perl Module containing convenience functions for Koha scripts
37 $date = slashifyDate("01-01-2002")
38 $ethnicity = fixEthnicity('asian');
39 ($categories, $labels) = borrowercategories();
40 ($categories, $labels) = ethnicitycategories();
44 Koha.pm provides many functions for Koha scripts.
53 @EXPORT = qw(&slashifyDate
57 &subfield_is_koha_internal_p
66 $slash_date = &slashifyDate($dash_date);
68 Takes a string of the form "DD-MM-YYYY" (or anything separated by
69 dashes), converts it to the form "YYYY/MM/DD", and returns the result.
74 # accepts a date of the form xx-xx-xx[xx] and returns it in the
76 my @dateOut = split('-', shift);
77 return("$dateOut[2]/$dateOut[1]/$dateOut[0]")
82 $ethn_name = &fixEthnicity($ethn_code);
84 Takes an ethnicity code (e.g., "european" or "pi") and returns the
85 corresponding descriptive name from the C<ethnicity> table in the
86 Koha database ("European" or "Pacific Islander").
93 my $ethnicity = shift;
94 my $dbh = C4::Context->dbh;
95 my $sth=$dbh->prepare("Select name from ethnicity where code = ?");
96 $sth->execute($ethnicity);
97 my $data=$sth->fetchrow_hashref;
99 return $data->{'name'};
102 =item borrowercategories
104 ($codes_arrayref, $labels_hashref) = &borrowercategories();
106 Looks up the different types of borrowers in the database. Returns two
107 elements: a reference-to-array, which lists the borrower category
108 codes, and a reference-to-hash, which maps the borrower category codes
109 to category descriptions.
114 sub borrowercategories {
115 my $dbh = C4::Context->dbh;
116 my $sth=$dbh->prepare("Select categorycode,description from categories order by description");
120 while (my $data=$sth->fetchrow_hashref){
121 push @codes,$data->{'categorycode'};
122 $labels{$data->{'categorycode'}}=$data->{'description'};
125 return(\@codes,\%labels);
128 =item ethnicitycategories
130 ($codes_arrayref, $labels_hashref) = ðnicitycategories();
132 Looks up the different ethnic types in the database. Returns two
133 elements: a reference-to-array, which lists the ethnicity codes, and a
134 reference-to-hash, which maps the ethnicity codes to ethnicity
140 sub ethnicitycategories {
141 my $dbh = C4::Context->dbh;
142 my $sth=$dbh->prepare("Select code,name from ethnicity order by name");
146 while (my $data=$sth->fetchrow_hashref){
147 push @codes,$data->{'code'};
148 $labels{$data->{'code'}}=$data->{'name'};
151 return(\@codes,\%labels);
154 # FIXME.. this should be moved to a MARC-specific module
155 sub subfield_is_koha_internal_p ($) {
158 # We could match on 'lib' and 'tab' (and 'mandatory', & more to come!)
159 # But real MARC subfields are always single-character
160 # so it really is safer just to check the length
162 return length $subfield != 1;
172 Pat Eyler, pate@gnu.org