Bug 5453 Move declarations out of conditionals in opac

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
This commit is contained in:
Colin Campbell 2010-11-29 15:15:47 +00:00 committed by Chris Cormack
parent 4a3ce35f2f
commit af3c7d4ce7
7 changed files with 75 additions and 46 deletions

View File

@ -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,

View File

@ -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" ) {

View File

@ -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(

View File

@ -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,

View File

@ -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
};
}
}

View File

@ -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;

View File

@ -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 );