- $categories = '(no categories set)' unless ($categories);
- $table .= <<EOF;
-<tr bgcolor='$color'>
- <td align='left' valign='top'>$branch->{'branchname'}</td>
- <td align='left' valign='top'>$branch->{'branchcode'}</td>
- <td align='left' valign='top'>$address</td>
- <td align='left' valign='top'>$categories</td>
- <td align='left' valign='top'>
-<form action='$script_name' method=post>
-<input type='hidden' name='op' value='edit'>
-<input type='hidden' name='branchcode' value='$branch->{'branchcode'}'>
-<input type=submit value=Edit>
-</form>
-<form action='$script_name' method=post>
-<input type='hidden' name='branchcode' value='$branch->{'branchcode'}'>
-<input type='hidden' name='op' value='delete'><input type=submit value=Delete>
-</form></td>
-</tr>
-EOF
- }
- $table .= "</table><br>";
- return $table;
+ my $toggle;
+ my $i;
+ my @loop_data =();
+ foreach my $branch (@$branchinfo) {
+ ($i % 2) ? ($toggle = 1) : ($toggle = 0);
+ #
+ # 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)
+ #
+ # - color
+ # - branch_name (Note: not "branchname")
+ # - branch_code (Note: not "branchcode")
+ # - address (containing a static error message)
+ # - branchaddress1 \
+ # - branchaddress2 |
+ # - branchaddress3 | comprising the old "address" field
+ # - branchphone |
+ # - branchfax |
+ # - branchemail /
+ # - 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
+ # - action
+ #
+ my %row = ();
+
+ # Handle address fields separately
+ my $address_empty_p = 1;
+ for my $field ('branchaddress1', 'branchaddress2', 'branchaddress3',
+ 'branchphone', 'branchfax', 'branchemail', 'branchip', 'branchprinter') {
+ $row{$field} = $branch->{$field};
+ if ( $branch->{$field} ) {
+ $address_empty_p = 0;
+ }
+ }
+ $row{'address-empty-p'} = $address_empty_p;
+ # {{{ Leave this here until bug 180 is completely resolved in templates
+ $row{'address'} = 'Your template is out of date (see bug 180)';
+ # }}}
+
+ # Handle categories
+ my $no_categories_p = 1;
+ my @categories = '';
+ foreach my $cat (@{$branch->{'categories'}}) {
+ my ($catinfo) = @{getcategoryinfo($cat)};
+ push @categories, {'categoryname' => $catinfo->{'categoryname'}};
+ $no_categories_p = 0;
+ }
+ # {{{ Leave this here until bug 180 is completely resolved in templates
+ $row{'categories'} = 'Your template is out of date (see bug 180)';
+ # }}}
+ $row{'category_list'} = \@categories;
+ $row{'no-categories-p'} = $no_categories_p;
+
+ # Handle all other fields
+ $row{'branch_name'} = $branch->{'branchname'};
+ $row{'branch_code'} = $branch->{'branchcode'};
+ $row{'toggle'} = $toggle;
+ $row{'value'} = $branch->{'branchcode'};
+ $row{'action'} = '/cgi-bin/koha/admin/branches.pl';
+
+ push @loop_data, { %row };
+ $i++;
+ }
+ my @branchcategories =();
+ my $catinfo = getcategoryinfo();
+ my $toggle;
+ my $i = 0;
+ foreach my $cat (@$catinfo) {
+ ($i % 2) ? ($toggle = 1) : ($toggle = 0);
+ push @branchcategories, {
+ toggle => $toggle,
+ categoryname => $cat->{'categoryname'},
+ categorycode => $cat->{'categorycode'},
+ codedescription => $cat->{'codedescription'},
+ };
+ $i++;
+ }
+
+ $template->param(branches => \@loop_data,
+ branchcategories => \@branchcategories);
+