5 #package to deal with marking up output
6 #You will need to edit parts of this pm
7 #set the value of path to be where your html lives
10 # Copyright 2000-2002 Katipo Communications
12 # This file is part of Koha.
14 # Koha is free software; you can redistribute it and/or modify it under the
15 # terms of the GNU General Public License as published by the Free Software
16 # Foundation; either version 2 of the License, or (at your option) any later
19 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
20 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
21 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License along with
24 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
25 # Suite 330, Boston, MA 02111-1307 USA
27 # NOTE: I'm pretty sure this module is deprecated in favor of
37 use vars qw($VERSION @ISA @EXPORT);
39 # set the version for version checking
44 C4::Output - Functions for managing templates
54 &themelanguage &gettemplate setlanguagecookie pagination_bar
57 #FIXME: this is a quick fix to stop rc1 installing broken
58 #Still trying to figure out the correct fix.
59 my $path = C4::Context->config('intrahtdocs')."/default/en/includes/";
61 #---------------------------------------------------------------------------------------------------------
64 my ($tmplbase, $opac, $query) = @_;
66 warn "no query in gettemplate";
69 if ($opac ne "intranet") {
70 $htdocs = C4::Context->config('opachtdocs');
72 $htdocs = C4::Context->config('intrahtdocs');
74 my $path = C4::Context->preference('intranet_includes') || 'includes';
76 my ($theme, $lang) = themelanguage($htdocs, $tmplbase, $opac, $query);
77 my $opacstylesheet = C4::Context->preference('opacstylesheet');
78 my $template = HTML::Template->new(filename => "$htdocs/$theme/$lang/$tmplbase",
79 die_on_bad_params => 0,
81 path => ["$htdocs/$theme/$lang/$path"]);
83 $template->param(themelang => ($opac ne 'intranet'? '/opac-tmpl': '/intranet-tmpl') . "/$theme/$lang",
84 interface => ($opac ne 'intranet'? '/opac-tmpl': '/intranet-tmpl'),
86 opacstylesheet => $opacstylesheet,
87 opaccolorstylesheet => C4::Context->preference('opaccolorstylesheet'),
88 opacsmallimage => C4::Context->preference('opacsmallimage'),
95 #---------------------------------------------------------------------------------------------------------
98 my ($htdocs, $tmpl, $section, $query) = @_;
102 my $dbh = C4::Context->dbh;
105 if ( $section eq "intranet")
107 @languages = split " ", C4::Context->preference("opaclanguages");
108 @themes = split " ", C4::Context->preference("template");
112 # we are in the opac here, what im trying to do is let the individual user
113 # set the theme they want to use.
114 # and perhaps the them as well.
115 my $lang=$query->cookie('KohaOpacLanguage');
118 push @languages,$lang;
119 @themes = split " ", C4::Context->preference("opacthemes");
122 @languages = split " ", C4::Context->preference("opaclanguages");
123 @themes = split " ", C4::Context->preference("opacthemes");
128 # searches through the themes and languages. First template it find it returns.
129 # Priority is for getting the theme right.
131 foreach my $th (@themes) {
132 foreach my $la (@languages) {
133 for (my $pass = 1; $pass <= 2; $pass += 1) {
134 $la =~ s/([-_])/ $1 eq '-'? '_': '-' /eg if $pass == 2;
135 if (-e "$htdocs/$th/$la/$tmpl") {
140 last unless $la =~ /[-_]/;
144 if ($theme and $lang) {
145 return ($theme, $lang);
147 return ('default', 'en');
152 sub setlanguagecookie {
153 my ($query,$language,$uri)=@_;
154 my $cookie=$query->cookie(-name => 'KohaOpacLanguage',
157 print $query->redirect(-uri=>$uri,
163 pagination_bar($base_url, $nb_pages, $current_page, $startfrom_name)
165 Build an HTML pagination bar based on the number of page to display, the
166 current page and the url to give to each page link.
168 C<$base_url> is the URL for each page link. The
169 C<$startfrom_name>=page_number is added at the end of the each URL.
171 C<$nb_pages> is the total number of pages available.
173 C<$current_page> is the current page number. This page number won't become a
176 This function returns HTML, without any language dependency.
181 my ($base_url, $nb_pages, $current_page, $startfrom_name) = @_;
183 # how many pages to show before and after the current page?
184 my $pages_around = 2;
188 .($base_url =~ m/&/ ? '&' : '?')
192 my $pagination_bar = '';
194 # current page detection
195 if (not defined $current_page) {
199 # navigation bar useful only if more than one page to display !
201 # link to first page?
202 if ($current_page > 1) {
205 .'<a href="'.$url.'1" rel="start">'
212 "\n".' <span class="inactive"><<</span>';
215 # link on previous page ?
216 if ($current_page > 1) {
217 my $previous = $current_page - 1;
230 "\n".' <span class="inactive"><</span>';
233 my $min_to_display = $current_page - $pages_around;
234 my $max_to_display = $current_page + $pages_around;
235 my $last_displayed_page = undef;
237 for my $page_number (1..$nb_pages) {
238 if ($page_number == 1
239 or $page_number == $nb_pages
240 or ($page_number >= $min_to_display and $page_number <= $max_to_display)
242 if (defined $last_displayed_page
243 and $last_displayed_page != $page_number - 1
246 "\n".' <span class="inactive">...</span>'
250 if ($page_number == $current_page) {
253 .'<span class="currentPage">'.$page_number.'</span>'
259 .'<a href="'.$url.$page_number.'">'.$page_number.'</a>'
262 $last_displayed_page = $page_number;
267 if ($current_page < $nb_pages) {
268 my $next = $current_page + 1;
271 "\n".' <a href="'.$url.$next.'" rel="next">'
278 "\n".' <span class="inactive">></span>'
283 if ($current_page != $nb_pages) {
285 "\n".' <a href="'.$url.$nb_pages.'" rel="last">'
292 "\n".' <span class="inactive">>></span>';
296 return $pagination_bar;
300 END { } # module clean-up code here (global destructor)
309 Koha Developement team <info@koha.org>