X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=C4%2FBranch.pm;h=fe67e0c175cee87ec189ad238bf9b2d61b5ea000;hb=d03c8443a4c5a4549a3ee37df201f031b40b2f41;hp=1f26e352402f2ddbaeea0aa137284a1d2eed5bbb;hpb=b5ee2f201bed91a38ff2c1c527cbf19adc76fabc;p=koha_fer diff --git a/C4/Branch.pm b/C4/Branch.pm index 1f26e35240..fe67e0c175 100644 --- a/C4/Branch.pm +++ b/C4/Branch.pm @@ -20,13 +20,12 @@ use strict; #use warnings; FIXME - Bug 2505 require Exporter; use C4::Context; -use C4::Koha; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); BEGIN { # set the version for version checking - $VERSION = 3.02; + $VERSION = 3.07.00.049; @ISA = qw(Exporter); @EXPORT = qw( &GetBranchCategory @@ -47,6 +46,7 @@ BEGIN { &DelBranchCategory &CheckCategoryUnique &mybranch + &GetBranchesCount ); @EXPORT_OK = qw( &onlymine &mybranch get_branch_code_from_name ); } @@ -155,16 +155,17 @@ sub mybranch { return C4::Context->userenv->{branch} || ''; } -sub GetBranchesLoop (;$$) { # since this is what most pages want anyway +sub GetBranchesLoop { # since this is what most pages want anyway my $branch = @_ ? shift : mybranch(); # optional first argument is branchcode of "my branch", if preselection is wanted. my $onlymine = @_ ? shift : onlymine(); my $branches = GetBranches($onlymine); my @loop; - foreach ( sort { uc($branches->{$a}->{branchname}) cmp uc($branches->{$b}->{branchname}) } keys %$branches ) { + foreach my $branchcode ( sort { uc($branches->{$a}->{branchname}) cmp uc($branches->{$b}->{branchname}) } keys %$branches ) { push @loop, { - value => $_, - selected => ($_ eq $branch) ? 1 : 0, - branchname => $branches->{$_}->{branchname}, + value => $branchcode, + branchcode => $branchcode, + selected => ($branchcode eq $branch) ? 1 : 0, + branchname => $branches->{$branchcode}->{branchname}, }; } return \@loop; @@ -203,21 +204,22 @@ sub ModBranch { my $query = " INSERT INTO branches (branchcode,branchname,branchaddress1, - branchaddress2,branchaddress3,branchzip,branchcity, + branchaddress2,branchaddress3,branchzip,branchcity,branchstate, branchcountry,branchphone,branchfax,branchemail, - branchurl,branchip,branchprinter,branchnotes) - VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) + branchurl,branchip,branchprinter,branchnotes,opac_info) + VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; my $sth = $dbh->prepare($query); $sth->execute( $data->{'branchcode'}, $data->{'branchname'}, $data->{'branchaddress1'}, $data->{'branchaddress2'}, $data->{'branchaddress3'}, $data->{'branchzip'}, - $data->{'branchcity'}, $data->{'branchcountry'}, + $data->{'branchcity'}, $data->{'branchstate'}, + $data->{'branchcountry'}, $data->{'branchphone'}, $data->{'branchfax'}, $data->{'branchemail'}, $data->{'branchurl'}, $data->{'branchip'}, $data->{'branchprinter'}, - $data->{'branchnotes'}, + $data->{'branchnotes'}, $data->{opac_info}, ); return 1 if $dbh->err; } else { @@ -225,9 +227,9 @@ sub ModBranch { UPDATE branches SET branchname=?,branchaddress1=?, branchaddress2=?,branchaddress3=?,branchzip=?, - branchcity=?,branchcountry=?,branchphone=?, + branchcity=?,branchstate=?,branchcountry=?,branchphone=?, branchfax=?,branchemail=?,branchurl=?,branchip=?, - branchprinter=?,branchnotes=? + branchprinter=?,branchnotes=?,opac_info=? WHERE branchcode=? "; my $sth = $dbh->prepare($query); @@ -235,11 +237,12 @@ sub ModBranch { $data->{'branchname'}, $data->{'branchaddress1'}, $data->{'branchaddress2'}, $data->{'branchaddress3'}, $data->{'branchzip'}, - $data->{'branchcity'}, $data->{'branchcountry'}, + $data->{'branchcity'}, $data->{'branchstate'}, + $data->{'branchcountry'}, $data->{'branchphone'}, $data->{'branchfax'}, $data->{'branchemail'}, $data->{'branchurl'}, $data->{'branchip'}, $data->{'branchprinter'}, - $data->{'branchnotes'}, + $data->{'branchnotes'}, $data->{opac_info}, $data->{'branchcode'}, ); } @@ -371,7 +374,7 @@ the categories were already here, and minimally used. =cut #TODO manage category types. rename possibly to 'agency domains' ? as borrowergroups are called categories. -sub GetCategoryTypes() { +sub GetCategoryTypes { return ( 'searchdomain','properties'); } @@ -381,7 +384,7 @@ $branch = GetBranch( $query, $branches ); =cut -sub GetBranch ($$) { +sub GetBranch { my ( $query, $branches ) = @_; # get branch for this query from branches my $branch = $query->param('branch'); my %cookie = $query->cookie('userenv'); @@ -406,34 +409,6 @@ sub GetBranchDetail { return $sth->fetchrow_hashref(); } -=head2 get_branchinfos_of - - my $branchinfos_of = get_branchinfos_of(@branchcodes); - -Associates a list of branchcodes to the information of the branch, taken in -branches table. - -Returns a href where keys are branchcodes and values are href where keys are -branch information key. - - print 'branchname is ', $branchinfos_of->{$code}->{branchname}; - -=cut - -sub get_branchinfos_of { - my @branchcodes = @_; - - my $query = ' - SELECT branchcode, - branchname - FROM branches - WHERE branchcode IN (' - . join( ',', map( { "'" . $_ . "'" } @branchcodes ) ) . ') -'; - return C4::Koha::get_infos_of( $query, 'branchcode' ); -} - - =head2 GetBranchesInCategory my $branches = GetBranchesInCategory($categorycode); @@ -442,7 +417,7 @@ Returns a href: keys %$branches eq (branchcode,branchname) . =cut -sub GetBranchesInCategory($) { +sub GetBranchesInCategory { my ($categorycode) = @_; my @branches; my $dbh = C4::Context->dbh(); @@ -607,6 +582,15 @@ sub get_branch_code_from_name { return $sth->fetchrow_array; } +sub GetBranchesCount { + my $dbh = C4::Context->dbh(); + my $query = "SELECT COUNT(*) AS branches_count FROM branches"; + my $sth = $dbh->prepare( $query ); + $sth->execute(); + my $row = $sth->fetchrow_hashref(); + return $row->{'branches_count'}; +} + 1; __END__