-# FIXME This doesn't belong here; it should be moved into a module
-sub setbranchinfo {
-# sets the data from the editbranch form, and writes to the database...
- my ($data) = @_;
- my $dbh = C4::Context->dbh;
- my $query = "replace branches (branchcode,branchname,branchaddress1,branchaddress2,branchaddress3,branchphone,branchfax,branchemail) values (";
- my $tmp;
- $tmp = $data->{'branchcode'}; $query.= $dbh->quote($tmp).",";
- $tmp = $data->{'branchname'}; $query.= $dbh->quote($tmp).",";
- $tmp = $data->{'branchaddress1'}; $query.= $dbh->quote($tmp).",";
- $tmp = $data->{'branchaddress2'}; $query.= $dbh->quote($tmp).",";
- $tmp = $data->{'branchaddress3'}; $query.= $dbh->quote($tmp).",";
- $tmp = $data->{'branchphone'}; $query.= $dbh->quote($tmp).",";
- $tmp = $data->{'branchfax'}; $query.= $dbh->quote($tmp).",";
- $tmp = $data->{'branchemail'}; $query.= $dbh->quote($tmp).")";
- my $sth=$dbh->prepare($query);
- $sth->execute;
- $sth->finish;
-# sort out the categories....
- my @checkedcats;
- my $cats = getcategoryinfo();
- foreach my $cat (@$cats) {
- my $code = $cat->{'categorycode'};
- if ($data->{$code}) {
- push(@checkedcats, $code);
- }
- }
- my $branchcode = $data->{'branchcode'};
- my $branch = getbranchinfo($branchcode);
- $branch = $branch->[0];
- my $branchcats = $branch->{'categories'};
- my @addcats;
- my @removecats;
- foreach my $bcat (@$branchcats) {
- unless (grep {/^$bcat$/} @checkedcats) {
- push(@removecats, $bcat);
- }
+ my ($branchcode,$innertemplate) = @_;
+ my $branchinfo = $branchcode ? GetBranchInfo($branchcode) : GetBranchInfo();
+ my @loop_data = ();
+ foreach my $branch (@$branchinfo) {
+ #
+ # We export the following fields to the template. These are not
+ # pre-composed as a single "address" field because the template
+ # might (and should) escape what is exported here. (See bug 180)
+ #
+ # - branch_name (Note: not "branchname")
+ # - branch_code (Note: not "branchcode")
+ # - address (containing a static error message)
+ # - branchaddress1 \
+ # - branchaddress2 |
+ # - branchaddress3 | comprising the old "address" field
+ # - branchzip |
+ # - branchcity |
+ # - branchcountry |
+ # - branchphone |
+ # - branchfax |
+ # - branchemail /
+ # - branchurl /
+ # - opac_info (can contain HTML)
+ # - address-empty-p (1 if no address information, 0 otherwise)
+ # - categories (containing a static error message)
+ # - category_list (loop containing "categoryname")
+ # - no-categories-p (1 if no categories set, 0 otherwise)
+ # - value
+ #
+ my %row = ();
+
+ # Handle address fields separately
+ my $address_empty_p = 1;
+ for my $field (
+ 'branchaddress1', 'branchaddress2',
+ 'branchaddress3', 'branchzip',
+ 'branchcity', 'branchstate', 'branchcountry',
+ 'branchphone', 'branchfax',
+ 'branchemail', 'branchurl', 'opac_info',
+ 'branchip', 'branchprinter', 'branchnotes'
+ )
+ {
+ $row{$field} = $branch->{$field};
+ $address_empty_p = 0 if ( $branch->{$field} );
+ }
+ $row{'address-empty-p'} = $address_empty_p;
+
+ # Handle categories
+ my $no_categories_p = 1;
+ my @categories;
+ foreach my $cat ( @{ $branch->{'categories'} } ) {
+ my ($catinfo) = @{ GetBranchCategory($cat) };
+ push @categories, { 'categoryname' => $catinfo->{'categoryname'} };
+ $no_categories_p = 0;
+ }
+
+ $row{'category_list'} = \@categories;
+ $row{'no-categories-p'} = $no_categories_p;
+ $row{'branch_name'} = $branch->{'branchname'};
+ $row{'branch_code'} = $branch->{'branchcode'};
+ $row{'value'} = $branch->{'branchcode'};
+
+ push @loop_data, \%row;