4 #package to deal with marking up output
5 #You will need to edit parts of this pm
6 #set the value of path to be where your html lives
9 # Copyright 2000-2002 Katipo Communications
11 # This file is part of Koha.
13 # Koha is free software; you can redistribute it and/or modify it under the
14 # terms of the GNU General Public License as published by the Free Software
15 # Foundation; either version 2 of the License, or (at your option) any later
18 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
20 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License along with
23 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
24 # Suite 330, Boston, MA 02111-1307 USA
31 use HTML::Template::Pro;
33 use vars qw($VERSION @ISA @EXPORT);
35 # set the version for version checking
40 C4::Output - Functions for managing templates
50 &themelanguage &gettemplate setlanguagecookie pagination_bar
53 #FIXME: this is a quick fix to stop rc1 installing broken
54 #Still trying to figure out the correct fix.
55 my $path = C4::Context->config('intrahtdocs')."/default/en/includes/";
57 #---------------------------------------------------------------------------------------------------------
60 my ($tmplbase, $opac, $query) = @_;
62 warn "no query in gettemplate";
65 if ($opac ne "intranet") {
66 $htdocs = C4::Context->config('opachtdocs');
68 $htdocs = C4::Context->config('intrahtdocs');
70 my $path = C4::Context->preference('intranet_includes') || 'includes';
71 # warn "PATH : $path";
74 $_=~s /\xef\xbb\xbf//g;
76 my ($theme, $lang) = themelanguage($htdocs, $tmplbase, $opac, $query);
77 my $opacstylesheet = C4::Context->preference('opacstylesheet');
79 my $template = HTML::Template::Pro->new(filename => "$htdocs/$theme/$lang/$tmplbase", case_sensitive=>1,
80 die_on_bad_params => 0,
82 path => ["$htdocs/$theme/$lang/$path"]);
84 $template->param(themelang => ($opac ne 'intranet'? '/opac-tmpl': '/intranet-tmpl') . "/$theme/$lang",
85 interface => ($opac ne 'intranet'? '/opac-tmpl': '/intranet-tmpl'),
87 opacstylesheet => $opacstylesheet,
88 opaccolorstylesheet => C4::Context->preference('opaccolorstylesheet'),
89 opacsmallimage => C4::Context->preference('opacsmallimage'),
96 #---------------------------------------------------------------------------------------------------------
99 my ($htdocs, $tmpl, $section, $query) = @_;
103 my $dbh = C4::Context->dbh;
107 if ($section eq "intranet"){
108 $lang=$query->cookie('KohaOpacLanguage');
112 push @languages,$lang;
113 @themes = split " ", C4::Context->preference("template");
116 @languages = split " ", C4::Context->preference("opaclanguages");
117 @themes = split " ", C4::Context->preference("template");
120 $lang=$query->cookie('KohaOpacLanguage');
124 push @languages,$lang;
125 @themes = split " ", C4::Context->preference("opacthemes");
128 @languages = split " ", C4::Context->preference("opaclanguages");
129 @themes = split " ", C4::Context->preference("opacthemes");
134 # searches through the themes and languages. First template it find it returns.
135 # Priority is for getting the theme right.
137 foreach my $th (@themes) {
138 foreach my $la (@languages) {
139 for (my $pass = 1; $pass <= 2; $pass += 1) {
140 $la =~ s/([-_])/ $1 eq '-'? '_': '-' /eg if $pass == 2;
141 if (-e "$htdocs/$th/$la/$tmpl") {
146 last unless $la =~ /[-_]/;
150 if ($theme and $lang) {
151 return ($theme, $lang);
153 return ('default', 'en');
158 sub setlanguagecookie {
159 my ($query,$language,$uri)=@_;
160 my $cookie=$query->cookie(-name => 'KohaOpacLanguage',
163 print $query->redirect(-uri=>$uri,
169 pagination_bar($base_url, $nb_pages, $current_page, $startfrom_name)
171 Build an HTML pagination bar based on the number of page to display, the
172 current page and the url to give to each page link.
174 C<$base_url> is the URL for each page link. The
175 C<$startfrom_name>=page_number is added at the end of the each URL.
177 C<$nb_pages> is the total number of pages available.
179 C<$current_page> is the current page number. This page number won't become a
182 This function returns HTML, without any language dependency.
187 my ($base_url, $nb_pages, $current_page, $startfrom_name) = @_;
189 # how many pages to show before and after the current page?
190 my $pages_around = 2;
194 .($base_url =~ m/&/ ? '&' : '?')
198 my $pagination_bar = '';
200 # current page detection
201 if (not defined $current_page) {
205 # navigation bar useful only if more than one page to display !
207 # link to first page?
208 if ($current_page > 1) {
211 .'<a href="'.$url.'1" rel="start">'
218 "\n".' <span class="inactive"><<</span>';
221 # link on previous page ?
222 if ($current_page > 1) {
223 my $previous = $current_page - 1;
236 "\n".' <span class="inactive"><</span>';
239 my $min_to_display = $current_page - $pages_around;
240 my $max_to_display = $current_page + $pages_around;
241 my $last_displayed_page = undef;
243 for my $page_number (1..$nb_pages) {
244 if ($page_number == 1
245 or $page_number == $nb_pages
246 or ($page_number >= $min_to_display and $page_number <= $max_to_display)
248 if (defined $last_displayed_page
249 and $last_displayed_page != $page_number - 1
252 "\n".' <span class="inactive">...</span>'
256 if ($page_number == $current_page) {
259 .'<span class="currentPage">'.$page_number.'</span>'
265 .'<a href="'.$url.$page_number.'">'.$page_number.'</a>'
268 $last_displayed_page = $page_number;
273 if ($current_page < $nb_pages) {
274 my $next = $current_page + 1;
277 "\n".' <a href="'.$url.$next.'" rel="next">'
284 "\n".' <span class="inactive">></span>'
289 if ($current_page != $nb_pages) {
291 "\n".' <a href="'.$url.$nb_pages.'" rel="last">'
298 "\n".' <span class="inactive">>></span>';
302 return $pagination_bar;
306 END { } # module clean-up code here (global destructor)
315 Koha Developement team <info@koha.org>