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