From af3c7d4ce7af4bfd104c4dc94c5c2da9a7b1863a Mon Sep 17 00:00:00 2001 From: Colin Campbell Date: Mon, 29 Nov 2010 15:15:47 +0000 Subject: [PATCH] Bug 5453 Move declarations out of conditionals in opac Signed-off-by: Chris Cormack --- opac/opac-ISBDdetail.pl | 5 +++- opac/opac-authorities-home.pl | 26 +++++++++--------- opac/opac-authoritiesdetail.pl | 16 +++++------ opac/opac-detail.pl | 5 +++- opac/opac-search.pl | 49 ++++++++++++++++++++++++---------- opac/opac-topissues.pl | 6 ++--- opac/opac-user.pl | 14 ++++++---- 7 files changed, 75 insertions(+), 46 deletions(-) diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl index e141da7ff9..c80d41c8c5 100755 --- a/opac/opac-ISBDdetail.pl +++ b/opac/opac-ISBDdetail.pl @@ -85,7 +85,10 @@ my $upc = GetNormalizedUPC($record,$marcflavour); my $ean = GetNormalizedEAN($record,$marcflavour); my $oclc = GetNormalizedOCLCNumber($record,$marcflavour); my $isbn = GetNormalizedISBN(undef,$record,$marcflavour); -my $content_identifier_exists = 1 if ($isbn or $ean or $oclc or $upc); +my $content_identifier_exists; +if ( $isbn or $ean or $oclc or $upc ) { + $content_identifier_exists = 1; +} $template->param( normalized_upc => $upc, normalized_ean => $ean, diff --git a/opac/opac-authorities-home.pl b/opac/opac-authorities-home.pl index a87030ef98..acff077caf 100755 --- a/opac/opac-authorities-home.pl +++ b/opac/opac-authorities-home.pl @@ -41,18 +41,20 @@ $startfrom = 0 if ( !defined $startfrom ); my ( $template, $loggedinuser, $cookie ); my $resultsperpage; -my $authtypes = getauthtypes; -my @authtypesloop; -foreach my $thisauthtype ( sort { $authtypes->{$a}{'authtypetext'} cmp $authtypes->{$b}{'authtypetext'} } - keys %$authtypes ) -{ - my $selected = 1 if $thisauthtype eq $authtypecode; - my %row = ( - value => $thisauthtype, - selected => $selected, - authtypetext => $authtypes->{$thisauthtype}{'authtypetext'}, - ); - push @authtypesloop, \%row; +my $authtypes = getauthtypes(); +my @authtypesloop = (); +foreach my $thisauthtype ( + sort { + $authtypes->{$a}->{'authtypetext'} + cmp $authtypes->{$b}->{'authtypetext'} + } + keys %{$authtypes} + ) { + push @authtypesloop, + { value => $thisauthtype, + selected => $thisauthtype eq $authtypecode, + authtypetext => $authtypes->{$thisauthtype}->{'authtypetext'}, + }; } if ( $op eq "do_search" ) { diff --git a/opac/opac-authoritiesdetail.pl b/opac/opac-authoritiesdetail.pl index 27ca8cc8a2..6610dfda5c 100755 --- a/opac/opac-authoritiesdetail.pl +++ b/opac/opac-authoritiesdetail.pl @@ -170,16 +170,14 @@ foreach my $field (@fields) { } $template->param( "Tab0XX" => \@loop_data ); -my $authtypes = getauthtypes; -my @authtypesloop; -foreach my $thisauthtype ( keys %$authtypes ) { - my $selected = 1 if $thisauthtype eq $authtypecode; - my %row = ( - value => $thisauthtype, - selected => $selected, +my $authtypes = getauthtypes(); +my @authtypesloop = (); +foreach my $thisauthtype ( keys %{$authtypes} ) { + push @authtypesloop, + { value => $thisauthtype, + selected => $thisauthtype eq $authtypecode, authtypetext => $authtypes->{$thisauthtype}{'authtypetext'}, - ); - push @authtypesloop, \%row; + }; } $template->param( diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 37a1bd4666..e18e0469c2 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -281,7 +281,10 @@ my $upc = GetNormalizedUPC($record,$marcflavour); my $ean = GetNormalizedEAN($record,$marcflavour); my $oclc = GetNormalizedOCLCNumber($record,$marcflavour); my $isbn = GetNormalizedISBN(undef,$record,$marcflavour); -my $content_identifier_exists = 1 if ($isbn or $ean or $oclc or $upc); +my $content_identifier_exists; +if ( $isbn or $ean or $oclc or $upc ) { + $content_identifier_exists = 1; +} $template->param( normalized_upc => $upc, normalized_ean => $ean, diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 7f247c7ea4..cd3461071d 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -207,9 +207,13 @@ if ( $template_type && $template_type eq 'advsearch' ) { $template->param(outer_sup_servers_loop => $secondary_servers_loop,); # set the default sorting - my $default_sort_by = C4::Context->preference('OPACdefaultSortField')."_".C4::Context->preference('OPACdefaultSortOrder') - if (C4::Context->preference('OPACdefaultSortField') && C4::Context->preference('OPACdefaultSortOrder')); - $template->param($default_sort_by => 1); + if ( C4::Context->preference('OPACdefaultSortField') + && C4::Context->preference('OPACdefaultSortOrder') ) { + my $default_sort_by = + C4::Context->preference('OPACdefaultSortField') . '_' + . C4::Context->preference('OPACdefaultSortOrder'); + $template->param( $default_sort_by => 1 ); + } # determine what to display next to the search boxes (ie, boolean option # shouldn't appear on the first one, scan indexes should, adding a new @@ -273,8 +277,13 @@ $tag = $params->{tag} if $params->{tag}; # sort by is used to sort the query # in theory can have more than one but generally there's just one my @sort_by; -my $default_sort_by = C4::Context->preference('OPACdefaultSortField')."_".C4::Context->preference('OPACdefaultSortOrder') - if (C4::Context->preference('OPACdefaultSortField') && C4::Context->preference('OPACdefaultSortOrder')); +my $default_sort_by; +if ( C4::Context->preference('OPACdefaultSortField') + && C4::Context->preference('OPACdefaultSortOrder') ) { + $default_sort_by = + C4::Context->preference('OPACdefaultSortField') . '_' + . C4::Context->preference('OPACdefaultSortOrder'); +} @sort_by = split("\0",$params->{'sort_by'}) if $params->{'sort_by'}; $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by); @@ -568,8 +577,13 @@ for (my $i=0;$i<@servers;$i++) { my $pages = ceil($hits / $results_per_page); # default page number my $current_page_number = 1; - $current_page_number = ($offset / $results_per_page + 1) if $offset; - my $previous_page_offset = $offset - $results_per_page unless ($offset - $results_per_page <0); + if ($offset) { + $current_page_number = ( $offset / $results_per_page + 1 ); + } + my $previous_page_offset; + if ( $offset >= $results_per_page ) { + $previous_page_offset = $offset - $results_per_page; + } my $next_page_offset = $offset + $results_per_page; # If we're within the first 10 pages, keep it simple #warn "current page:".$current_page_number; @@ -583,11 +597,14 @@ for (my $i=0;$i<@servers;$i++) { my $this_offset = (($i*$results_per_page)-$results_per_page); # the page number for this page my $this_page_number = $i; - # it should only be highlighted if it's the current page - my $highlight = 1 if ($this_page_number == $current_page_number); # put it in the array - push @page_numbers, { offset => $this_offset, pg => $this_page_number, highlight => $highlight, sort_by => join " ",@sort_by }; - + push @page_numbers, + { offset => $this_offset, + pg => $this_page_number, + highlight => $this_page_number == $current_page_number, + sort_by => join ' ', @sort_by + }; + } } @@ -596,9 +613,13 @@ for (my $i=0;$i<@servers;$i++) { for ($i=$current_page_number; $i<=($current_page_number + 20 );$i++) { my $this_offset = ((($i-9)*$results_per_page)-$results_per_page); my $this_page_number = $i-9; - my $highlight = 1 if ($this_page_number == $current_page_number); - if ($this_page_number <= $pages) { - push @page_numbers, { offset => $this_offset, pg => $this_page_number, highlight => $highlight, sort_by => join " ",@sort_by }; + if ( $this_page_number <= $pages ) { + push @page_numbers, + { offset => $this_offset, + pg => $this_page_number, + highlight => $this_page_number == $current_page_number, + sort_by => join ' ', @sort_by + }; } } diff --git a/opac/opac-topissues.pl b/opac/opac-topissues.pl index 80e7c35aba..6899215cc7 100755 --- a/opac/opac-topissues.pl +++ b/opac/opac-topissues.pl @@ -127,13 +127,11 @@ $template->param( branchloop => GetBranchesLoop(C4::Context->userenv->{'branch'} my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype'; $itemtypes = GetItemTypes; my @itemtypesloop; -my $selected=1; if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') { foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) { - my $selected = 1 if $thisitemtype eq $itemtype; my %row =( value => $thisitemtype, description => $itemtypes->{$thisitemtype}->{'description'}, - selected => $selected, + selected => $thisitemtype eq $itemtype, ); push @itemtypesloop, \%row; } @@ -142,7 +140,7 @@ if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') { for my $thisitemtype (@$advsearchtypes) { my $selected = 1 if $thisitemtype->{authorised_value} eq $itemtype; my %row =( value => $thisitemtype->{authorised_value}, - selected => $selected, + selected => $thisitemtype eq $itemtype, description => $thisitemtype->{'lib'}, ); push @itemtypesloop, \%row; diff --git a/opac/opac-user.pl b/opac/opac-user.pl index a2f7d9b121..2c31ce7aa9 100755 --- a/opac/opac-user.pl +++ b/opac/opac-user.pl @@ -193,13 +193,17 @@ $template->param( show_barcode => 1 ) if $show_barcode; # load the branches my $branches = GetBranches(); my @branch_loop; -for my $branch_hash (sort keys %$branches ) { - my $selected=(C4::Context->userenv && ($branch_hash eq C4::Context->userenv->{branch})) if (C4::Context->preference('SearchMyLibraryFirst')); +for my $branch_hash ( sort keys %{$branches} ) { + my $selected; + if ( C4::Context->preference('SearchMyLibraryFirst') ) { + $selected = + ( C4::Context->userenv + && ( $branch_hash eq C4::Context->userenv->{branch} ) ); + } push @branch_loop, - { - value => "branch: $branch_hash", + { value => "branch: $branch_hash", branchname => $branches->{$branch_hash}->{'branchname'}, - selected => $selected + selected => $selected, }; } $template->param( branchloop => \@branch_loop ); -- 2.39.5