+
+@branch_loop = sort {$a->{branchname} cmp $b->{branchname}} @branch_loop;
+my @authorised_value_list;
+my $authorisedvalue_categories = '';
+
+my $frameworks = getframeworks();
+$frameworks->{''} = {frameworkcode => ''}; # Add the default framework
+
+for my $fwk (keys %$frameworks){
+ my $fwkcode = $frameworks->{$fwk}->{'frameworkcode'};
+ my $authcode = GetAuthValCode('items.location', $fwkcode);
+ if ($authcode && $authorisedvalue_categories!~/\b$authcode\W/){
+ $authorisedvalue_categories.="$authcode ";
+ my $data=GetAuthorisedValues($authcode);
+ foreach my $value (@$data){
+ $value->{selected}=1 if ($value->{authorised_value} eq ($location));
+ }
+ push @authorised_value_list,@$data;
+ }
+}
+
+my $statuses = [];
+for my $statfield (qw/items.notforloan items.itemlost items.wthdrawn items.damaged/){
+ my $hash = {};
+ $hash->{fieldname} = $statfield;
+ $hash->{authcode} = GetAuthValCode($statfield);
+ if ($hash->{authcode}){
+ my $arr = GetAuthorisedValues($hash->{authcode});
+ $hash->{values} = $arr;
+ push @$statuses, $hash;
+ }
+}
+$template->param( statuses => $statuses );
+my $staton = {}; #authorized values that are ticked
+for my $authvfield (@$statuses) {
+ $staton->{$authvfield->{fieldname}} = [];
+ for my $authval (@{$authvfield->{values}}){
+ if ( defined $input->param('status-' . $authvfield->{fieldname} . '-' . $authval->{id}) && $input->param('status-' . $authvfield->{fieldname} . '-' . $authval->{id}) eq 'on' ){
+ push @{$staton->{$authvfield->{fieldname}}}, $authval->{id};
+ }
+ }
+}
+
+my $statussth = '';
+for my $authvfield (@$statuses) {
+ if ( scalar @{$staton->{$authvfield->{fieldname}}} > 0 ){
+ my $joinedvals = join ',', @{$staton->{$authvfield->{fieldname}}};
+ $statussth .= "$authvfield->{fieldname} in ($joinedvals) and ";
+ }
+}
+$statussth =~ s, and $,,g;
+