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
65 $slash_date = &slashifyDate($dash_date);
67 Takes a string of the form "DD-MM-YYYY" (or anything separated by
68 dashes), converts it to the form "YYYY/MM/DD", and returns the result.
73 # accepts a date of the form xx-xx-xx[xx] and returns it in the
75 my @dateOut = split('-', shift);
76 return("$dateOut[2]/$dateOut[1]/$dateOut[0]")
81 $ethn_name = &fixEthnicity($ethn_code);
83 Takes an ethnicity code (e.g., "european" or "pi") and returns the
84 corresponding descriptive name from the C<ethnicity> table in the
85 Koha database ("European" or "Pacific Islander").
92 my $ethnicity = shift;
93 my $dbh = C4::Context->dbh;
94 my $sth=$dbh->prepare("Select name from ethnicity where code = ?");
95 $sth->execute($ethnicity);
96 my $data=$sth->fetchrow_hashref;
98 return $data->{'name'};
101 =item borrowercategories
103 ($codes_arrayref, $labels_hashref) = &borrowercategories();
105 Looks up the different types of borrowers in the database. Returns two
106 elements: a reference-to-array, which lists the borrower category
107 codes, and a reference-to-hash, which maps the borrower category codes
108 to category descriptions.
113 sub borrowercategories {
114 my $dbh = C4::Context->dbh;
115 my $sth=$dbh->prepare("Select categorycode,description from categories order by description");
119 while (my $data=$sth->fetchrow_hashref){
120 push @codes,$data->{'categorycode'};
121 $labels{$data->{'categorycode'}}=$data->{'description'};
124 return(\@codes,\%labels);
127 =item ethnicitycategories
129 ($codes_arrayref, $labels_hashref) = ðnicitycategories();
131 Looks up the different ethnic types in the database. Returns two
132 elements: a reference-to-array, which lists the ethnicity codes, and a
133 reference-to-hash, which maps the ethnicity codes to ethnicity
139 sub ethnicitycategories {
140 my $dbh = C4::Context->dbh;
141 my $sth=$dbh->prepare("Select code,name from ethnicity order by name");
145 while (my $data=$sth->fetchrow_hashref){
146 push @codes,$data->{'code'};
147 $labels{$data->{'code'}}=$data->{'name'};
150 return(\@codes,\%labels);
160 Pat Eyler, pate@gnu.org