Added PODs.
[koha.git] / C4 / Koha.pm
1 package C4::Koha;
2
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
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
11 # version.
12 #
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.
16 #
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
20
21 use strict;
22 require Exporter;
23 use C4::Database;
24
25 use vars qw($VERSION @ISA @EXPORT);
26   
27 $VERSION = 0.01;
28     
29 =head1 NAME
30
31 C4::Koha - Perl Module containing convenience functions for Koha scripts
32
33 =head1 SYNOPSIS
34
35   use C4::Koha;
36
37
38   $date = slashifyDate("01-01-2002")
39   $ethnicity = fixEthnicity('asian');
40   ($categories, $labels) = borrowercategories();
41   ($categories, $labels) = ethnicitycategories();
42
43 =head1 DESCRIPTION
44
45 Koha.pm provides many functions for Koha scripts.
46
47 =head1 FUNCTIONS
48
49 =over 2
50
51 =cut
52
53 @ISA = qw(Exporter);
54 @EXPORT = qw(&slashifyDate
55              &fixEthnicity
56              &borrowercategories
57              &ethnicitycategories
58              $DEBUG); 
59
60 use vars qw();
61         
62 my $DEBUG = 0;
63
64 =item slashifyDate
65
66   $slash_date = &slashifyDate($dash_date);
67
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.
70
71 =cut
72
73 sub slashifyDate {
74     # accepts a date of the form xx-xx-xx[xx] and returns it in the 
75     # form xx/xx/xx[xx]
76     my @dateOut = split('-', shift);
77     return("$dateOut[2]/$dateOut[1]/$dateOut[0]")
78 }
79
80 =item fixEthnicity
81
82   $ethn_name = &fixEthnicity($ethn_code);
83
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").
87
88 =cut
89 #'
90
91 sub fixEthnicity($) { 
92
93     my $ethnicity = shift;
94     my $dbh=C4Connect;
95     my $sth=$dbh->prepare("Select name from ethnicity where code = ?");
96     $sth->execute($ethnicity);
97     my $data=$sth->fetchrow_hashref;
98     $sth->finish;
99     $dbh->disconnect;
100     return $data->{'name'};
101 }
102
103 =item borrowercategories
104
105   ($codes_arrayref, $labels_hashref) = &borrowercategories();
106
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.
111
112 =cut
113 #'
114
115 sub borrowercategories {
116     my $dbh=C4Connect;
117     my $sth=$dbh->prepare("Select categorycode,description from categories order by description");
118     $sth->execute;
119     my %labels;
120     my @codes;
121     while (my $data=$sth->fetchrow_hashref){
122       push @codes,$data->{'categorycode'};
123       $labels{$data->{'categorycode'}}=$data->{'description'};
124     }
125     $sth->finish;
126     $dbh->disconnect;
127     return(\@codes,\%labels);
128 }
129
130 =item ethnicitycategories
131
132   ($codes_arrayref, $labels_hashref) = &ethnicitycategories();
133
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
137 descriptions.
138
139 =cut
140 #'
141
142 sub ethnicitycategories {
143     my $dbh=C4Connect;
144     my $sth=$dbh->prepare("Select code,name from ethnicity order by name");
145     $sth->execute;
146     my %labels;
147     my @codes;
148     while (my $data=$sth->fetchrow_hashref){
149       push @codes,$data->{'code'};
150       $labels{$data->{'code'}}=$data->{'name'};
151     }
152     $sth->finish;
153     $dbh->disconnect;
154     return(\@codes,\%labels);
155 }
156
157 1;
158 __END__
159
160 =back
161
162 =head1 AUTHOR
163
164 Pat Eyler, pate@gnu.org
165
166 =head1 SEE ALSO
167
168 perl(1).
169
170 =cut