4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
25 use vars qw($VERSION @ISA @EXPORT);
31 C4::Koha - Perl Module containing convenience functions for Koha scripts
38 $date = slashifyDate("01-01-2002")
39 $ethnicity = fixEthnicity('asian');
40 ($categories, $labels) = borrowercategories();
41 ($categories, $labels) = ethnicitycategories();
45 Koha.pm provides many functions for Koha scripts.
54 @EXPORT = qw(&slashifyDate
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;
95 my $sth=$dbh->prepare("Select name from ethnicity where code = ?");
96 $sth->execute($ethnicity);
97 my $data=$sth->fetchrow_hashref;
100 return $data->{'name'};
103 =item borrowercategories
105 ($codes_arrayref, $labels_hashref) = &borrowercategories();
107 Looks up the different types of borrowers in the database. Returns two
108 elements: a reference-to-array, which lists the borrower category
109 codes, and a reference-to-hash, which maps the borrower category codes
110 to category descriptions.
115 sub borrowercategories {
117 my $sth=$dbh->prepare("Select categorycode,description from categories order by description");
121 while (my $data=$sth->fetchrow_hashref){
122 push @codes,$data->{'categorycode'};
123 $labels{$data->{'categorycode'}}=$data->{'description'};
127 return(\@codes,\%labels);
130 =item ethnicitycategories
132 ($codes_arrayref, $labels_hashref) = ðnicitycategories();
134 Looks up the different ethnic types in the database. Returns two
135 elements: a reference-to-array, which lists the ethnicity codes, and a
136 reference-to-hash, which maps the ethnicity codes to ethnicity
142 sub ethnicitycategories {
144 my $sth=$dbh->prepare("Select code,name from ethnicity order by name");
148 while (my $data=$sth->fetchrow_hashref){
149 push @codes,$data->{'code'};
150 $labels{$data->{'code'}}=$data->{'name'};
154 return(\@codes,\%labels);
164 Pat Eyler, pate@gnu.org