Most of these merges are just removing unused parts of the perl modules.
[koha.git] / C4 / Koha.pm
1 package C4::Koha;
2
3 use strict;
4 require Exporter;
5 use C4::Database;
6
7 use vars qw($VERSION @ISA @EXPORT);
8   
9 $VERSION = 0.01;
10     
11 @ISA = qw(Exporter);
12 @EXPORT = qw(&slashifyDate
13              &fixEthnicity
14              &borrowercategories
15              &ethnicitycategories
16              $DEBUG); 
17
18 use vars qw();
19         
20 my $DEBUG = 0;
21
22 sub slashifyDate {
23     # accepts a date of the form xx-xx-xx[xx] and returns it in the 
24     # form xx/xx/xx[xx]
25     my @dateOut = split('-', shift);
26     return("$dateOut[2]/$dateOut[1]/$dateOut[0]")
27 }
28
29 sub fixEthnicity($) { 
30
31     my $ethnicity = shift;
32     my $dbh=C4Connect;
33     my $sth=$dbh->prepare("Select name from ethnicity where code = ?");
34     $sth->execute($ethnicity);
35     my $data=$sth->fetchrow_hashref;
36     $sth->finish;
37     $dbh->disconnect;
38     return $data->{'name'};
39 }
40
41 sub borrowercategories {
42     my $dbh=C4Connect;
43     my $sth=$dbh->prepare("Select categorycode,description from categories order by description");
44     $sth->execute;
45     my %labels;
46     my @codes;
47     while (my $data=$sth->fetchrow_hashref){
48       push @codes,$data->{'categorycode'};
49       $labels{$data->{'categorycode'}}=$data->{'description'};
50     }
51     $sth->finish;
52     $dbh->disconnect;
53     return(\@codes,\%labels);
54 }
55
56 sub ethnicitycategories {
57     my $dbh=C4Connect;
58     my $sth=$dbh->prepare("Select code,name from ethnicity order by name");
59     $sth->execute;
60     my %labels;
61     my @codes;
62     while (my $data=$sth->fetchrow_hashref){
63       push @codes,$data->{'code'};
64       $labels{$data->{'code'}}=$data->{'name'};
65     }
66     $sth->finish;
67     $dbh->disconnect;
68     return(\@codes,\%labels);
69 }
70
71 1;
72 __END__
73
74 =head1 NAME
75
76 Koha - Perl Module containing convenience functions for Koha scripts
77
78 =head1 SYNOPSIS
79
80   use Koha;
81
82
83   $date = slashifyDate("01-01-2002")
84   $ethnicity=fixEthnicity('asian');
85   ($categories,$labels)=borrowercategories();
86
87 =head1 DESCRIPTION
88
89 Koha.pm provides many functions for Koha scripts.
90
91 slashifyDate() takes a dash separated date string and returns a slash 
92 separated date string
93
94 =head1 AUTHOR
95
96 Pat Eyler, pate@gnu.org
97
98 =head1 SEE ALSO
99
100 perl(1).
101
102 =cut
103
104
105
106
107