From e0090dcdaaf5691de7a840bc5ee9062945397476 Mon Sep 17 00:00:00 2001 From: plg Date: Tue, 4 Apr 2006 10:05:48 +0000 Subject: [PATCH] new: authorities in prog/en template, only partial import from default/en template. improved: C4::Output::pagination_bar builds an HTML pagination bar with no language dependency. This function hugely simplifies templates and offers a standard pagination method. This function also improves preformances. --- C4/Output.pm | 141 +++++++++++- authorities/authorities-home.pl | 136 +++++------ .../prog/en/authorities/authorities-home.tmpl | 105 +++++++++ .../prog/en/authorities/authorities.tmpl | 212 ++++++++++++++++++ .../prog/en/authorities/detail.tmpl | 53 +++++ .../prog/en/authorities/searchresultlist.tmpl | 64 ++++++ .../prog/en/includes/menu-authorities.inc | 15 ++ 7 files changed, 658 insertions(+), 68 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/authorities/authorities-home.tmpl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/authorities/authorities.tmpl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/authorities/detail.tmpl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/authorities/searchresultlist.tmpl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/menu-authorities.inc diff --git a/C4/Output.pm b/C4/Output.pm index 343326f832..0ce78f0be3 100644 --- a/C4/Output.pm +++ b/C4/Output.pm @@ -51,7 +51,7 @@ C4::Output - Functions for managing templates @ISA = qw(Exporter); @EXPORT = qw( - &themelanguage &gettemplate setlanguagecookie + &themelanguage &gettemplate setlanguagecookie pagination_bar ); #FIXME: this is a quick fix to stop rc1 installing broken @@ -146,6 +146,7 @@ sub themelanguage { } } + sub setlanguagecookie { my ($query,$language,$uri)=@_; my $cookie=$query->cookie(-name => 'KohaOpacLanguage', @@ -155,6 +156,144 @@ sub setlanguagecookie { -cookie=>$cookie); } +=item pagination_bar + + pagination_bar($base_url, $nb_pages, $current_page, $startfrom_name) + +Build an HTML pagination bar based on the number of page to display, the +current page and the url to give to each page link. + +C<$base_url> is the URL for each page link. The +C<$startfrom_name>=page_number is added at the end of the each URL. + +C<$nb_pages> is the total number of pages available. + +C<$current_page> is the current page number. This page number won't become a +link. + +This function returns HTML, without any language dependency. + +=cut + +sub pagination_bar { + my ($base_url, $nb_pages, $current_page, $startfrom_name) = @_; + + # how many pages to show before and after the current page? + my $pages_around = 2; + + my $url = + $base_url + .($base_url =~ m/&/ ? '&' : '?') + .$startfrom_name.'=' + ; + + my $pagination_bar = ''; + + # current page detection + if (not defined $current_page) { + $current_page = 1; + } + + # navigation bar useful only if more than one page to display ! + if ($nb_pages > 1) { + # link to first page? + if ($current_page > 1) { + $pagination_bar.= + "\n".' ' + .'' + .'<<' + .'' + ; + } + else { + $pagination_bar.= + "\n".' <<'; + } + + # link on previous page ? + if ($current_page > 1) { + my $previous = $current_page - 1; + + $pagination_bar.= + "\n".' ' + .'' + ; + } + else { + $pagination_bar.= + "\n".' <'; + } + + my $min_to_display = $current_page - $pages_around; + my $max_to_display = $current_page + $pages_around; + my $last_displayed_page = undef; + + for my $page_number (1..$nb_pages) { + if ($page_number == 1 + or $page_number == $nb_pages + or ($page_number >= $min_to_display and $page_number <= $max_to_display) + ) { + if (defined $last_displayed_page + and $last_displayed_page != $page_number - 1 + ) { + $pagination_bar.= + "\n".' ...' + ; + } + + if ($page_number == $current_page) { + $pagination_bar.= + "\n".' ' + .''.$page_number.'' + ; + } + else { + $pagination_bar.= + "\n".' ' + .''.$page_number.'' + ; + } + $last_displayed_page = $page_number; + } + } + + # link on next page? + if ($current_page < $nb_pages) { + my $next = $current_page + 1; + + $pagination_bar.= + "\n".' ' + ; + } + else { + $pagination_bar.= + "\n".' >' + ; + } + + # link to last page? + if ($current_page != $nb_pages) { + $pagination_bar.= + "\n".' ' + .'>>' + .'' + ; + } + else { + $pagination_bar.= + "\n".' >>'; + } + } + + return $pagination_bar; +} + END { } # module clean-up code here (global destructor) diff --git a/authorities/authorities-home.pl b/authorities/authorities-home.pl index 02814d20b8..f38ace0b9c 100755 --- a/authorities/authorities-home.pl +++ b/authorities/authorities-home.pl @@ -38,11 +38,8 @@ my $op = $query->param('op'); my $authtypecode = $query->param('authtypecode'); my $dbh = C4::Context->dbh; -my $startfrom=$query->param('startfrom'); my $authid=$query->param('authid'); -$startfrom=0 if(!defined $startfrom); my ($template, $loggedinuser, $cookie); -my $resultsperpage; my $authtypes = getauthtypes; my @authtypesloop; @@ -62,85 +59,90 @@ if ($op eq "do_search") { my @operator = $query->param('operator'); my @value = $query->param('value'); - $resultsperpage= $query->param('resultsperpage'); - $resultsperpage = 19 if(!defined $resultsperpage); - my @tags; - my ($results,$total) = authoritysearch($dbh, \@marclist,\@and_or, - \@excluding, \@operator, \@value, - $startfrom*$resultsperpage, $resultsperpage,$authtypecode); - ($template, $loggedinuser, $cookie) - = get_template_and_user({template_name => "authorities/searchresultlist.tmpl", - query => $query, - type => 'intranet', - authnotrequired => 0, - flagsrequired => {borrowers => 1}, - flagsrequired => {catalogue => 1}, - debug => 1, - }); + my $startfrom = $query->param('startfrom') || 1; + my $resultsperpage = $query->param('resultsperpage') || 19; + + my ($results,$total) = authoritysearch( + $dbh, + \@marclist, + \@and_or, + \@excluding, + \@operator, + \@value, + ($startfrom - 1)*$resultsperpage, + $resultsperpage, + $authtypecode + ); - # multi page display gestion - my $displaynext=0; - my $displayprev=$startfrom; - if(($total - (($startfrom+1)*($resultsperpage))) > 0 ){ - $displaynext = 1; - } + ($template, $loggedinuser, $cookie) + = get_template_and_user({ + template_name => "authorities/searchresultlist.tmpl", + query => $query, + type => 'intranet', + authnotrequired => 0, + flagsrequired => {borrowers => 1}, + flagsrequired => {catalogue => 1}, + debug => 1, + }); my @field_data = (); - # we must get parameters once again. Because if there is a mainentry, it has been replaced by something else during the search, thus the links next/previous would not work anymore + # we must get parameters once again. Because if there is a mainentry, it + # has been replaced by something else during the search, thus the links + # next/previous would not work anymore my @marclist_ini = $query->param('marclist'); for(my $i = 0 ; $i <= $#marclist ; $i++) { - push @field_data, { term => "marclist", val=>$marclist_ini[$i] }; - push @field_data, { term => "and_or", val=>$and_or[$i] }; - push @field_data, { term => "excluding", val=>$excluding[$i] }; - push @field_data, { term => "operator", val=>$operator[$i] }; - push @field_data, { term => "value", val=>$value[$i] }; + push @field_data, { term => "marclist" , val=>$marclist_ini[$i] }; + push @field_data, { term => "and_or" , val=>$and_or[$i] }; + push @field_data, { term => "excluding" , val=>$excluding[$i] }; + push @field_data, { term => "operator" , val=>$operator[$i] }; + push @field_data, { term => "value" , val=>$value[$i] }; } - my @numbers = (); - - if ($total>$resultsperpage) - { - for (my $i=1; $i<$total/$resultsperpage+1; $i++) - { - if ($i<16) - { - my $highlight=0; - ($startfrom==($i-1)) && ($highlight=1); - push @numbers, { number => $i, - highlight => $highlight , - searchdata=> \@field_data, - startfrom => ($i-1)}; - } - } - } - - my $from = $startfrom*$resultsperpage+1; + # construction of the url of each page + my $base_url = + 'authorities-home.pl?' + .join( + '&', + map { $_->{term}.'='.$_->{val} } @field_data + ) + .'&' + .join( + '&', + map { $_->{term}.'='.$_->{val} } ( + {term => 'resultsperpage', val => $resultsperpage}, + {term => 'type' , val => 'intranet'}, + {term => 'op' , val => 'do_search'}, + {term => 'authtypecode' , val => $authtypecode} + ) + ) + ; + + my $from = ($startfrom - 1) * $resultsperpage + 1; my $to; - if($total < (($startfrom+1)*$resultsperpage)) - { + if ($total < $startfrom * $resultsperpage) { $to = $total; - } else { - $to = (($startfrom+1)*$resultsperpage); } + else { + $to = $startfrom * $resultsperpage; + } + $template->param(result => $results) if $results; + $template->param( - startfrom=> $startfrom, - displaynext=> $displaynext, - displayprev=> $displayprev, - resultsperpage => $resultsperpage, - startfromnext => $startfrom+1, - startfromprev => $startfrom-1, - searchdata=>\@field_data, - total=>$total, - from=>$from, - to=>$to, - numbers=>\@numbers, - authtypecode=>$authtypecode, - isEDITORS => $authtypecode eq 'EDITORS', - ); + pagination_bar => pagination_bar( + $base_url, + int($total/$resultsperpage)+1, + $startfrom, + 'startfrom' + ), + total=>$total, + from=>$from, + to=>$to, + isEDITORS => $authtypecode eq 'EDITORS', + ); } elsif ($op eq "delete") { diff --git a/koha-tmpl/intranet-tmpl/prog/en/authorities/authorities-home.tmpl b/koha-tmpl/intranet-tmpl/prog/en/authorities/authorities-home.tmpl new file mode 100644 index 0000000000..a31895149f --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/authorities/authorities-home.tmpl @@ -0,0 +1,105 @@ + +Koha -- Authorities + + + + + + + +
+ Add authority + +
+ + + + + +
+ + + +
+ +
+ +
+
+
+ + diff --git a/koha-tmpl/intranet-tmpl/prog/en/authorities/authorities.tmpl b/koha-tmpl/intranet-tmpl/prog/en/authorities/authorities.tmpl new file mode 100644 index 0000000000..1093a2900d --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/authorities/authorities.tmpl @@ -0,0 +1,212 @@ + +Koha -- Authority details + + + + + +
+ + Modify authority # () + + Adding authority () + +
+ + + "> + "> + +
+ + + + + +
+ + +
+

Duplicate suspected with

+

You must either :

+ +
+ + + + +

+ + "> + "> - + + )">+ + +

+ + +

+ + + "> + "> + "> + "> +

+ + + +
+ + "> + "> + "> + "> + "> + +
+ + "> + "> + "> + + "> + "> + "> + "> + + "> + "> + +
+
+ + + + \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/en/authorities/detail.tmpl b/koha-tmpl/intranet-tmpl/prog/en/authorities/detail.tmpl new file mode 100644 index 0000000000..bdb0e8334c --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/authorities/detail.tmpl @@ -0,0 +1,53 @@ + +Koha -- Authority details + + + + + +

Authority # ()

+ +
+ +
+ +
+ + + + + + + + + + + +
+ +
+ + + + \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/en/authorities/searchresultlist.tmpl b/koha-tmpl/intranet-tmpl/prog/en/authorities/searchresultlist.tmpl new file mode 100644 index 0000000000..274f96ad43 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/authorities/searchresultlist.tmpl @@ -0,0 +1,64 @@ + +Koha -- Authorities -- Search result list + + + + + +

Authority search results

+ +
+ +

+ + Results to of + + No results found. + +

+ +
+ + + + + + + + + + + + + + + + + + + +
SummaryUsed inViewDelete
+ &operator==&value=&and_or=and&excluding=" class="button authority"> biblio(s) + + ">Authority number + + + )">Delete + +
+
+ +
+ + + + \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/menu-authorities.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/menu-authorities.inc new file mode 100644 index 0000000000..55c5a6efc0 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/menu-authorities.inc @@ -0,0 +1,15 @@ + -- 2.20.1