X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FBranch.pm;h=5770f7ba17985ece28de2ca00fa547d436ace7e0;hb=ca33b7fc635d93b3029831da7496372fb34c798f;hp=fe67e0c175cee87ec189ad238bf9b2d61b5ea000;hpb=5d7b5533f1565a55ff269fd82690a71a697901f1;p=koha.git diff --git a/C4/Branch.pm b/C4/Branch.pm index fe67e0c175..5770f7ba17 100644 --- a/C4/Branch.pm +++ b/C4/Branch.pm @@ -69,7 +69,7 @@ The functions in this module deal with branches. $branches = &GetBranches(); -Returns informations about ALL branches, IndependantBranches Insensitive. +Returns informations about ALL branches, IndependentBranches Insensitive. GetBranchInfo() returns the same information without the problems of this function (namespace collision, mainly). @@ -143,7 +143,7 @@ sub GetBranches { sub onlymine { return - C4::Context->preference('IndependantBranches') && + C4::Context->preference('IndependentBranches') && C4::Context->userenv && C4::Context->userenv->{flags} %2 != 1 && C4::Context->userenv->{branch} ; @@ -328,7 +328,7 @@ sub GetBranchCategory { =head2 GetBranchCategories - my $categories = GetBranchCategories($branchcode,$categorytype); + my $categories = GetBranchCategories($branchcode,$categorytype,$show_in_pulldown,$selected_in_pulldown); Returns a list ref of anon hashrefs with keys eq columns of branchcategories table, i.e. categorycode, categorydescription, categorytype, categoryname. @@ -338,27 +338,43 @@ $branchcode is a member of , and to $categorytype. =cut sub GetBranchCategories { - my ($branchcode,$categorytype) = @_; - my $dbh = C4::Context->dbh(); - my $query = "SELECT c.* FROM branchcategories c"; - my (@where, @bind); - if($branchcode) { - $query .= ",branchrelations r, branches b "; - push @where, "c.categorycode=r.categorycode and r.branchcode=? "; - push @bind , $branchcode; - } - if ($categorytype) { - push @where, " c.categorytype=? "; - push @bind, $categorytype; - } - $query .= " where " . join(" and ", @where) if(@where); - $query .= " order by categorytype,c.categorycode"; - my $sth=$dbh->prepare( $query); - $sth->execute(@bind); - - my $branchcats = $sth->fetchall_arrayref({}); - $sth->finish(); - return( $branchcats ); + my ( $branchcode, $categorytype, $show_in_pulldown, $selected_in_pulldown ) = @_; + my $dbh = C4::Context->dbh(); + + my $query = "SELECT c.* FROM branchcategories c"; + my ( @where, @bind ); + + if( $branchcode ) { + $query .= ",branchrelations r, branches b "; + push @where, "c.categorycode = r.categorycode AND r.branchcode = ? "; + push @bind , $branchcode; + } + + if ( $categorytype ) { + push @where, " c.categorytype = ? "; + push @bind, $categorytype; + } + + if ( defined( $show_in_pulldown ) ) { + push( @where, " c.show_in_pulldown = ? " ); + push( @bind, $show_in_pulldown ); + } + + $query .= " WHERE " . join(" AND ", @where) if(@where); + $query .= " ORDER BY categorytype,c.categorycode"; + my $sth=$dbh->prepare( $query); + $sth->execute(@bind); + + my $branchcats = $sth->fetchall_arrayref({}); + $sth->finish(); + + if ( $selected_in_pulldown ) { + foreach my $bc ( @$branchcats ) { + $bc->{'selected'} = 1 if ( $bc->{'categorycode'} eq $selected_in_pulldown ); + } + } + + return( $branchcats ); } =head2 GetCategoryTypes @@ -506,14 +522,14 @@ sub ModBranchCategoryInfo { my $dbh = C4::Context->dbh; if ($data->{'add'}){ # we are doing an insert - my $sth = $dbh->prepare("INSERT INTO branchcategories (categorycode,categoryname,codedescription,categorytype) VALUES (?,?,?,?)"); - $sth->execute(uc( $data->{'categorycode'} ),$data->{'categoryname'}, $data->{'codedescription'},$data->{'categorytype'} ); + my $sth = $dbh->prepare("INSERT INTO branchcategories (categorycode,categoryname,codedescription,categorytype,show_in_pulldown) VALUES (?,?,?,?,?)"); + $sth->execute(uc( $data->{'categorycode'} ),$data->{'categoryname'}, $data->{'codedescription'},$data->{'categorytype'},$data->{'show_in_pulldown'} ); $sth->finish(); } else { # modifying - my $sth = $dbh->prepare("UPDATE branchcategories SET categoryname=?,codedescription=?,categorytype=? WHERE categorycode=?"); - $sth->execute($data->{'categoryname'}, $data->{'codedescription'},$data->{'categorytype'},uc( $data->{'categorycode'} ) ); + my $sth = $dbh->prepare("UPDATE branchcategories SET categoryname=?,codedescription=?,categorytype=?,show_in_pulldown=? WHERE categorycode=?"); + $sth->execute($data->{'categoryname'}, $data->{'codedescription'},$data->{'categorytype'},$data->{'show_in_pulldown'},uc( $data->{'categorycode'} ) ); $sth->finish(); } }