Added copyright statement to all .pl and .pm files
[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 @ISA = qw(Exporter);
30 @EXPORT = qw(&slashifyDate
31              &fixEthnicity
32              &borrowercategories
33              &ethnicitycategories
34              $DEBUG); 
35
36 use vars qw();
37         
38 my $DEBUG = 0;
39
40 sub slashifyDate {
41     # accepts a date of the form xx-xx-xx[xx] and returns it in the 
42     # form xx/xx/xx[xx]
43     my @dateOut = split('-', shift);
44     return("$dateOut[2]/$dateOut[1]/$dateOut[0]")
45 }
46
47 sub fixEthnicity($) { 
48
49     my $ethnicity = shift;
50     my $dbh=C4Connect;
51     my $sth=$dbh->prepare("Select name from ethnicity where code = ?");
52     $sth->execute($ethnicity);
53     my $data=$sth->fetchrow_hashref;
54     $sth->finish;
55     $dbh->disconnect;
56     return $data->{'name'};
57 }
58
59 sub borrowercategories {
60     my $dbh=C4Connect;
61     my $sth=$dbh->prepare("Select categorycode,description from categories order by description");
62     $sth->execute;
63     my %labels;
64     my @codes;
65     while (my $data=$sth->fetchrow_hashref){
66       push @codes,$data->{'categorycode'};
67       $labels{$data->{'categorycode'}}=$data->{'description'};
68     }
69     $sth->finish;
70     $dbh->disconnect;
71     return(\@codes,\%labels);
72 }
73
74 sub ethnicitycategories {
75     my $dbh=C4Connect;
76     my $sth=$dbh->prepare("Select code,name from ethnicity order by name");
77     $sth->execute;
78     my %labels;
79     my @codes;
80     while (my $data=$sth->fetchrow_hashref){
81       push @codes,$data->{'code'};
82       $labels{$data->{'code'}}=$data->{'name'};
83     }
84     $sth->finish;
85     $dbh->disconnect;
86     return(\@codes,\%labels);
87 }
88
89 1;
90 __END__
91
92 =head1 NAME
93
94 Koha - Perl Module containing convenience functions for Koha scripts
95
96 =head1 SYNOPSIS
97
98   use Koha;
99
100
101   $date = slashifyDate("01-01-2002")
102   $ethnicity=fixEthnicity('asian');
103   ($categories,$labels)=borrowercategories();
104
105 =head1 DESCRIPTION
106
107 Koha.pm provides many functions for Koha scripts.
108
109 slashifyDate() takes a dash separated date string and returns a slash 
110 separated date string
111
112 =head1 AUTHOR
113
114 Pat Eyler, pate@gnu.org
115
116 =head1 SEE ALSO
117
118 perl(1).
119
120 =cut
121
122
123
124
125