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
31 use C4::Languages qw(getTranslatedLanguages get_bidi regex_lang_subtags language_get_description accept_language );
33 use HTML::Template::Pro;
34 use vars qw($VERSION @ISA @EXPORT);
37 # set the version for version checking
42 &themelanguage &gettemplate setlanguagecookie pagination_bar
45 &output_html_with_http_headers
51 C4::Output - Functions for managing templates
59 #FIXME: this is a quick fix to stop rc1 installing broken
60 #Still trying to figure out the correct fix.
61 my $path = C4::Context->config('intrahtdocs') . "/prog/en/includes/";
63 #---------------------------------------------------------------------------------------------------------
66 my ( $tmplbase, $interface, $query ) = @_;
67 ($query) or warn "no query in gettemplate";
69 if ( $interface ne "intranet" ) {
70 $htdocs = C4::Context->config('opachtdocs');
73 $htdocs = C4::Context->config('intrahtdocs');
75 my $path = C4::Context->preference('intranet_includes') || 'includes';
77 my ( $theme, $lang ) = themelanguage( $htdocs, $tmplbase, $interface, $query );
78 my $opacstylesheet = C4::Context->preference('opacstylesheet');
80 # if the template doesn't exist, load the English one as a last resort
81 my $filename = "$htdocs/$theme/$lang/modules/$tmplbase";
82 unless (-f $filename) {
84 $filename = "$htdocs/$theme/$lang/".($interface eq 'intranet'?"modules":"")."/$tmplbase";
86 my $template = HTML::Template::Pro->new(
87 filename => $filename,
88 die_on_bad_params => 1,
91 path => ["$htdocs/$theme/$lang/$path"]
95 themelang => ( $interface ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' )
97 interface => ( $interface ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' ),
99 opacstylesheet => $opacstylesheet,
100 opaccolorstylesheet => C4::Context->preference('opaccolorstylesheet'),
101 opacsmallimage => C4::Context->preference('opacsmallimage'),
106 my $current_lang = regex_lang_subtags($lang);
108 $bidi = get_bidi($current_lang->{script}) if $current_lang->{script};
111 my @template_languages;
112 my $languages_loop = getTranslatedLanguages($interface,$theme);
114 for my $language_hashref (@$languages_loop) {
115 $language_hashref->{'current_lang'} = $current_lang->{'language'};
116 $language_hashref->{'native_description'} = language_get_description($language_hashref->{'language_code'},$language_hashref->{'language_code'},'language');
117 #warn "($language_hashref->{'language_code'},$language_hashref->{'current_lang'},$language_hashref->{'script_code'}";
118 $language_hashref->{'locale_description'} = language_get_description($language_hashref->{'language_code'},$language_hashref->{'current_lang'},'language');
119 $language_hashref->{'language_description'} = language_get_description($language_hashref->{'language_code'},$language_hashref->{'current_lang'},'language');
120 $language_hashref->{'script_description'} = language_get_description($language_hashref->{'script_code'},$language_hashref->{'current_lang'},'script');
121 $language_hashref->{'region_description'} = language_get_description($language_hashref->{'region_code'},$language_hashref->{'current_lang'},'region');
122 $language_hashref->{'variant_description'} = language_get_description($language_hashref->{'variant_code'},$language_hashref->{'current_lang'},'variant');
124 if ($language_hashref->{'language_lang'} eq $lang) {
125 $language_hashref->{current}++;
127 push @template_languages, $language_hashref;
129 # load the languages ( for switching from one template to another )
130 $template->param( languages_loop => \@template_languages,
137 #---------------------------------------------------------------------------------------------------------
140 my ( $htdocs, $tmpl, $interface, $query ) = @_;
141 ($query) or warn "no query in themelanguage";
143 # Set some defaults for language and theme
144 # First, check the user's preferences
146 my $http_accept_language = regex_lang_subtags($ENV{HTTP_ACCEPT_LANGUAGE})->{language};
147 if ($http_accept_language) {
148 $lang = accept_language($http_accept_language,getTranslatedLanguages($interface,'prog'));
150 # But, if there's a cookie set, obey it
151 $lang = $query->cookie('KohaOpacLanguage') if $query->cookie('KohaOpacLanguage');
153 # Fall back to English
154 $lang = 'en' unless $lang;
157 my $dbh = C4::Context->dbh;
160 if ( $interface eq "intranet" ) {
161 @languages = split " ", C4::Context->preference("opaclanguages");
162 @themes = split " ", C4::Context->preference("template");
163 push @languages, $lang if $lang;
166 # we are in the opac here, what im trying to do is let the individual user
167 # set the theme they want to use.
168 # and perhaps the them as well.
169 #my $lang = $query->cookie('KohaOpacLanguage');
170 if ($lang) { # FIXME: if $lang always TRUE!
171 push @languages, $lang;
174 @languages = split " ", C4::Context->preference("opaclanguages");
176 @themes = split " ", C4::Context->preference("opacthemes");
179 # searches through the themes and languages. First template it find it returns.
180 # Priority is for getting the theme right.
182 foreach my $th (@themes) {
183 foreach my $la (@languages) {
184 for ( my $pass = 1 ; $pass <= 2 ; $pass += 1 ) {
185 $la =~ s/([-_])/ $1 eq '-'? '_': '-' /eg if $pass == 2;
186 if ( -e "$htdocs/$th/$la/".($interface eq 'intranet'?"modules":"")."/$tmpl" ) {
191 last unless $la =~ /[-_]/;
195 return ( $theme, $lang );
198 sub setlanguagecookie {
199 my ( $query, $language, $uri ) = @_;
200 my $cookie = $query->cookie(
201 -name => 'KohaOpacLanguage',
205 print $query->redirect(
213 pagination_bar($base_url, $nb_pages, $current_page, $startfrom_name)
215 Build an HTML pagination bar based on the number of page to display, the
216 current page and the url to give to each page link.
218 C<$base_url> is the URL for each page link. The
219 C<$startfrom_name>=page_number is added at the end of the each URL.
221 C<$nb_pages> is the total number of pages available.
223 C<$current_page> is the current page number. This page number won't become a
226 This function returns HTML, without any language dependency.
231 my ( $base_url, $nb_pages, $current_page, $startfrom_name ) = @_;
233 # how many pages to show before and after the current page?
234 my $pages_around = 2;
237 $base_url . ( $base_url =~ m/&/ ? '&' : '?' ) . $startfrom_name . '=';
239 my $pagination_bar = '';
241 # current page detection
242 if ( not defined $current_page ) {
246 # navigation bar useful only if more than one page to display !
247 if ( $nb_pages > 1 ) {
249 # link to first page?
250 if ( $current_page > 1 ) {
256 . '<<' . '</a>';
260 "\n" . ' <span class="inactive"><<</span>';
263 # link on previous page ?
264 if ( $current_page > 1 ) {
265 my $previous = $current_page - 1;
272 . '" rel="prev">' . '<' . '</a>';
276 "\n" . ' <span class="inactive"><</span>';
279 my $min_to_display = $current_page - $pages_around;
280 my $max_to_display = $current_page + $pages_around;
281 my $last_displayed_page = undef;
283 for my $page_number ( 1 .. $nb_pages ) {
286 or $page_number == $nb_pages
287 or ( $page_number >= $min_to_display
288 and $page_number <= $max_to_display )
291 if ( defined $last_displayed_page
292 and $last_displayed_page != $page_number - 1 )
295 "\n" . ' <span class="inactive">...</span>';
298 if ( $page_number == $current_page ) {
301 . '<span class="currentPage">'
310 . $page_number . '">'
311 . $page_number . '</a>';
313 $last_displayed_page = $page_number;
318 if ( $current_page < $nb_pages ) {
319 my $next = $current_page + 1;
321 $pagination_bar .= "\n"
325 . '" rel="next">' . '>' . '</a>';
329 "\n" . ' <span class="inactive">></span>';
333 if ( $current_page != $nb_pages ) {
334 $pagination_bar .= "\n"
339 . '>>' . '</a>';
343 "\n" . ' <span class="inactive">>></span>';
347 return $pagination_bar;
350 =item output_html_with_http_headers
352 &output_html_with_http_headers($query, $cookie, $html)
354 Outputs the HTML page $html with the appropriate HTTP headers,
355 with the authentication cookie $cookie and a Content-Type that
356 corresponds to the HTML page $html.
360 sub output_html_with_http_headers ($$$) {
361 my($query, $cookie, $html) = @_;
362 print $query->header(
363 -type => 'text/html',
366 -Pragma => 'no-cache',
367 -'Cache-Control' => 'no-cache',
371 END { } # module clean-up code here (global destructor)
380 Koha Developement team <info@koha.org>