From 9ac07b38be223b6fe361fd932db97988ae81017b Mon Sep 17 00:00:00 2001 From: tipaul Date: Tue, 18 May 2004 11:54:07 +0000 Subject: [PATCH] getitemtypes moved in Koha.pm --- C4/Biblio.pm | 21 ++------- C4/Koha.pm | 119 ++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 103 insertions(+), 37 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 5c6ee7baed..b0baee599e 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -40,7 +40,7 @@ $VERSION = 0.01; &newitems &modbibitem &modsubtitle &modsubject &modaddauthor &moditem &countitems &delitem &deletebiblioitem &delbiblio - &getitemtypes &getbiblio + &getbiblio &getbiblioitembybiblionumber &getbiblioitem &getitemsbybiblioitem &skip @@ -1867,22 +1867,6 @@ sub delbiblio { &MARCdelbiblio($dbh,$bibid,0); } -sub getitemtypes { - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("select * from itemtypes order by description"); - my $count = 0; - my @results; - - $sth->execute; - while (my $data = $sth->fetchrow_hashref) { - $results[$count] = $data; - $count++; - } # while - - $sth->finish; - return($count, @results); -} # sub getitemtypes - sub getbiblio { my ($biblionumber) = @_; my $dbh = C4::Context->dbh; @@ -2194,6 +2178,9 @@ Paul POULAIN paul.poulain@free.fr # $Id$ # $Log$ +# Revision 1.87 2004/05/18 11:54:07 tipaul +# getitemtypes moved in Koha.pm +# # Revision 1.86 2004/05/03 09:19:22 tipaul # some fixes for mysql prepare & execute # diff --git a/C4/Koha.pm b/C4/Koha.pm index a4ba11b1b3..69642a492d 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -55,15 +55,16 @@ Koha.pm provides many functions for Koha scripts. &borrowercategories ðnicitycategories &subfield_is_koha_internal_p - &getbranches &getbranch &CGIbranches + &getbranches &getbranch &getprinters &getprinter + &getitemtypes &getitemtypeinfo $DEBUG); use vars qw(); my $DEBUG = 0; -=item slashifyDate +=head2 slashifyDate $slash_date = &slashifyDate($dash_date); @@ -79,7 +80,7 @@ sub slashifyDate { return("$dateOut[2]/$dateOut[1]/$dateOut[0]") } -=item fixEthnicity +=head2 fixEthnicity $ethn_name = &fixEthnicity($ethn_code); @@ -101,7 +102,7 @@ sub fixEthnicity($) { return $data->{'name'}; } -=item borrowercategories +=head2 borrowercategories ($codes_arrayref, $labels_hashref) = &borrowercategories(); @@ -127,7 +128,7 @@ sub borrowercategories { return(\@codes,\%labels); } -=item ethnicitycategories +=head2 ethnicitycategories ($codes_arrayref, $labels_hashref) = ðnicitycategories(); @@ -164,23 +165,33 @@ sub subfield_is_koha_internal_p ($) { return length $subfield != 1; } -=item getbranches +=head2 getbranches $branches = &getbranches(); - @branch_codes = keys %$branches; - %main_branch_info = %{$branches->{"MAIN"}}; - -Returns information about existing library branches. + returns informations about branches. + Create a branch selector with the following code + +=head3 in PERL SCRIPT + +my $branches = getbranches; +my @branchloop; +foreach my $thisbranch (keys %$branches) { + my $selected = 1 if $thisbranch eq $branch; + my %row =(value => $thisbranch, + selected => $selected, + branchname => $branches->{$thisbranch}->{'branchname'}, + ); + push @branchloop, \%row; +} -C<$branches> is a reference-to-hash. Its keys are the branch codes for -all of the existing library branches, and its values are -references-to-hash describing that particular branch. -In each branch description (C<%main_branch_info>, above), there is a -key for each field in the branches table of the Koha database. In -addition, there is a key for each branch category code to which the -branch belongs (the category codes are taken from the branchrelations -table). +=head3 in TEMPLATE + =cut @@ -210,7 +221,75 @@ sub getbranches { return (\%branches); } -=item getprinters +=head2 itemtypes + + $itemtypes = &getitemtypes(); + +Returns information about existing itemtypes. + +build a HTML select with the following code : + +=head3 in PERL SCRIPT + +my $itemtypes = getitemtypes; +my @itemtypesloop; +foreach my $thisitemtype (keys %$itemtypes) { + my $selected = 1 if $thisitemtype eq $itemtype; + my %row =(value => $thisitemtype, + selected => $selected, + description => $itemtypes->{$thisitemtype}->{'description'}, + ); + push @itemtypesloop, \%row; +} +$template->param(itemtypeloop => \@itemtypesloop); + +=head3 in TEMPLATE + +
+ + "> + +
+ + +=cut + +sub getitemtypes { +# returns a reference to a hash of references to branches... + my %itemtypes; + my $dbh = C4::Context->dbh; + my $sth=$dbh->prepare("select * from itemtypes"); + $sth->execute; + while (my $IT=$sth->fetchrow_hashref) { + $itemtypes{$IT->{'itemtype'}}=$IT; + } + return (\%itemtypes); +} + + +=head2 itemtypes + + $itemtype = &getitemtype($itemtype); + +Returns information about an itemtype. + +=cut + +sub getitemtypeinfo { + my ($itemtype) = @_; + my $dbh = C4::Context->dbh; + my $sth=$dbh->prepare("select * from itemtypes where itemtype=?"); + $sth->execute($itemtype); + my $res = $sth->fetchrow_hashref; + return $res; +} + +=head2 getprinters $printers = &getprinters($env); @queues = keys %$printers; @@ -260,6 +339,6 @@ __END__ =head1 AUTHOR -Pat Eyler, pate@gnu.org +Koha Team =cut -- 2.39.2