3 #package to deal with marking up output
4 #You will need to edit parts of this pm
5 #set the value of path to be where your html lives
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307 USA
25 # NOTE: I'm pretty sure this module is deprecated in favor of
32 use C4::Languages qw(getTranslatedLanguages get_bidi regex_lang_subtags language_get_description accept_language );
34 use HTML::Template::Pro;
35 use vars qw($VERSION @ISA @EXPORT);
37 # set the version for version checking
42 C4::Output - Functions for managing templates
52 &themelanguage &gettemplate setlanguagecookie pagination_bar &output_html_with_http_headers
56 #FIXME: this is a quick fix to stop rc1 installing broken
57 #Still trying to figure out the correct fix.
58 my $path = C4::Context->config('intrahtdocs') . "/prog/en/includes/";
60 #---------------------------------------------------------------------------------------------------------
63 my ( $tmplbase, $interface, $query ) = @_;
65 warn "no query in gettemplate";
68 if ( $interface ne "intranet" ) {
69 $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, $interface, $query );
77 my $opacstylesheet = C4::Context->preference('opacstylesheet');
79 # if the template doesn't exist, load the English one as a last resort
80 my $filename = "$htdocs/$theme/$lang/".($interface eq 'intranet'?"modules":"")."/$tmplbase";
81 unless (-f $filename) {
83 $filename = "$htdocs/$theme/$lang/".($interface eq 'intranet'?"modules":"")."/$tmplbase";
85 my $template = HTML::Template::Pro->new(
86 filename => $filename,
87 die_on_bad_params => 1,
90 path => ["$htdocs/$theme/$lang/$path"]
94 themelang => ( $interface ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' )
96 interface => ( $interface ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' ),
98 opacstylesheet => $opacstylesheet,
99 opaccolorstylesheet => C4::Context->preference('opaccolorstylesheet'),
100 opacsmallimage => C4::Context->preference('opacsmallimage'),
105 my $current_lang = regex_lang_subtags($lang);
107 $bidi = get_bidi($current_lang->{script}) if $current_lang->{script};
110 my @template_languages;
111 my $languages_loop = getTranslatedLanguages($interface,$theme);
113 for my $language_hashref (@$languages_loop) {
114 $language_hashref->{'current_lang'} = $current_lang->{'language'};
115 $language_hashref->{'native_description'} = language_get_description($language_hashref->{'language_code'},$language_hashref->{'language_code'},'language');
116 #warn "($language_hashref->{'language_code'},$language_hashref->{'current_lang'},$language_hashref->{'script_code'}";
117 $language_hashref->{'locale_description'} = language_get_description($language_hashref->{'language_code'},$language_hashref->{'current_lang'},'language');
118 $language_hashref->{'language_description'} = language_get_description($language_hashref->{'language_code'},$language_hashref->{'current_lang'},'language');
119 $language_hashref->{'script_description'} = language_get_description($language_hashref->{'script_code'},$language_hashref->{'current_lang'},'script');
120 $language_hashref->{'region_description'} = language_get_description($language_hashref->{'region_code'},$language_hashref->{'current_lang'},'region');
121 $language_hashref->{'variant_description'} = language_get_description($language_hashref->{'variant_code'},$language_hashref->{'current_lang'},'variant');
123 if ($language_hashref->{'language_lang'} eq $lang) {
124 $language_hashref->{current}++;
126 push @template_languages, $language_hashref;
128 # load the languages ( for switching from one template to another )
129 $template->param( languages_loop => \@template_languages,
136 #---------------------------------------------------------------------------------------------------------
139 my ( $htdocs, $tmpl, $interface, $query ) = @_;
141 # Set some defaults for language and theme
142 # First, check the user's preferences
144 $lang = accept_language($ENV{HTTP_ACCEPT_LANGUAGE},getTranslatedLanguages($interface,'prog'));
146 # But, if there's a cookie set, obey it
147 $lang = $query->cookie('KohaOpacLanguage') if $query->cookie('KohaOpacLanguage');
149 # Fall back to English
150 $lang = 'en' unless $lang;
153 my $dbh = C4::Context->dbh;
156 if ( $interface eq "intranet" ) {
157 @languages = split " ", C4::Context->preference("opaclanguages");
158 @themes = split " ", C4::Context->preference("template");
159 pop @languages, $lang if $lang;
163 # we are in the opac here, what im trying to do is let the individual user
164 # set the theme they want to use.
165 # and perhaps the them as well.
166 #my $lang = $query->cookie('KohaOpacLanguage');
169 push @languages, $lang;
170 @themes = split " ", C4::Context->preference("opacthemes");
173 @languages = split " ", C4::Context->preference("opaclanguages");
174 @themes = split " ", C4::Context->preference("opacthemes");
178 # searches through the themes and languages. First template it find it returns.
179 # Priority is for getting the theme right.
181 foreach my $th (@themes) {
182 foreach my $la (@languages) {
183 for ( my $pass = 1 ; $pass <= 2 ; $pass += 1 ) {
184 $la =~ s/([-_])/ $1 eq '-'? '_': '-' /eg if $pass == 2;
185 if ( -e "$htdocs/$th/$la/".($interface eq 'intranet'?"modules":"")."/$tmpl" ) {
190 last unless $la =~ /[-_]/;
194 return ( $theme, $lang );
197 sub setlanguagecookie {
198 my ( $query, $language, $uri ) = @_;
199 my $cookie = $query->cookie(
200 -name => 'KohaOpacLanguage',
204 print $query->redirect(
212 pagination_bar($base_url, $nb_pages, $current_page, $startfrom_name)
214 Build an HTML pagination bar based on the number of page to display, the
215 current page and the url to give to each page link.
217 C<$base_url> is the URL for each page link. The
218 C<$startfrom_name>=page_number is added at the end of the each URL.
220 C<$nb_pages> is the total number of pages available.
222 C<$current_page> is the current page number. This page number won't become a
225 This function returns HTML, without any language dependency.
230 my ( $base_url, $nb_pages, $current_page, $startfrom_name ) = @_;
232 # how many pages to show before and after the current page?
233 my $pages_around = 2;
236 $base_url . ( $base_url =~ m/&/ ? '&' : '?' ) . $startfrom_name . '=';
238 my $pagination_bar = '';
240 # current page detection
241 if ( not defined $current_page ) {
245 # navigation bar useful only if more than one page to display !
246 if ( $nb_pages > 1 ) {
248 # link to first page?
249 if ( $current_page > 1 ) {
255 . '<<' . '</a>';
259 "\n" . ' <span class="inactive"><<</span>';
262 # link on previous page ?
263 if ( $current_page > 1 ) {
264 my $previous = $current_page - 1;
271 . '" rel="prev">' . '<' . '</a>';
275 "\n" . ' <span class="inactive"><</span>';
278 my $min_to_display = $current_page - $pages_around;
279 my $max_to_display = $current_page + $pages_around;
280 my $last_displayed_page = undef;
282 for my $page_number ( 1 .. $nb_pages ) {
285 or $page_number == $nb_pages
286 or ( $page_number >= $min_to_display
287 and $page_number <= $max_to_display )
290 if ( defined $last_displayed_page
291 and $last_displayed_page != $page_number - 1 )
294 "\n" . ' <span class="inactive">...</span>';
297 if ( $page_number == $current_page ) {
300 . '<span class="currentPage">'
309 . $page_number . '">'
310 . $page_number . '</a>';
312 $last_displayed_page = $page_number;
317 if ( $current_page < $nb_pages ) {
318 my $next = $current_page + 1;
320 $pagination_bar .= "\n"
324 . '" rel="next">' . '>' . '</a>';
328 "\n" . ' <span class="inactive">></span>';
332 if ( $current_page != $nb_pages ) {
333 $pagination_bar .= "\n"
338 . '>>' . '</a>';
342 "\n" . ' <span class="inactive">>></span>';
346 return $pagination_bar;
349 =item output_html_with_http_headers
351 &output_html_with_http_headers($query, $cookie, $html)
353 Outputs the HTML page $html with the appropriate HTTP headers,
354 with the authentication cookie $cookie and a Content-Type that
355 corresponds to the HTML page $html.
359 sub output_html_with_http_headers ($$$) {
360 my($query, $cookie, $html) = @_;
361 print $query->header(
362 -type => 'text/html',
365 -Pragma => 'no-cache',
366 -'Cache-Control' => 'no-cache',
370 END { } # module clean-up code here (global destructor)
379 Koha Developement team <info@koha.org>