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 ) = @_;
68 warn "no query in gettemplate";
71 if ( $interface ne "intranet" ) {
72 $htdocs = C4::Context->config('opachtdocs');
75 $htdocs = C4::Context->config('intrahtdocs');
77 my $path = C4::Context->preference('intranet_includes') || 'includes';
79 my ( $theme, $lang ) = themelanguage( $htdocs, $tmplbase, $interface, $query );
80 my $opacstylesheet = C4::Context->preference('opacstylesheet');
82 # if the template doesn't exist, load the English one as a last resort
83 my $filename = "$htdocs/$theme/$lang/modules/$tmplbase";
84 unless (-f $filename) {
86 $filename = "$htdocs/$theme/$lang/".($interface eq 'intranet'?"modules":"")."/$tmplbase";
88 my $template = HTML::Template::Pro->new(
89 filename => $filename,
90 die_on_bad_params => 1,
93 path => ["$htdocs/$theme/$lang/$path"]
97 themelang => ( $interface ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' )
99 interface => ( $interface ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' ),
101 opacstylesheet => $opacstylesheet,
102 opaccolorstylesheet => C4::Context->preference('opaccolorstylesheet'),
103 opacsmallimage => C4::Context->preference('opacsmallimage'),
108 my $current_lang = regex_lang_subtags($lang);
110 $bidi = get_bidi($current_lang->{script}) if $current_lang->{script};
113 my @template_languages;
114 my $languages_loop = getTranslatedLanguages($interface,$theme);
116 for my $language_hashref (@$languages_loop) {
117 $language_hashref->{'current_lang'} = $current_lang->{'language'};
118 $language_hashref->{'native_description'} = language_get_description($language_hashref->{'language_code'},$language_hashref->{'language_code'},'language');
119 #warn "($language_hashref->{'language_code'},$language_hashref->{'current_lang'},$language_hashref->{'script_code'}";
120 $language_hashref->{'locale_description'} = language_get_description($language_hashref->{'language_code'},$language_hashref->{'current_lang'},'language');
121 $language_hashref->{'language_description'} = language_get_description($language_hashref->{'language_code'},$language_hashref->{'current_lang'},'language');
122 $language_hashref->{'script_description'} = language_get_description($language_hashref->{'script_code'},$language_hashref->{'current_lang'},'script');
123 $language_hashref->{'region_description'} = language_get_description($language_hashref->{'region_code'},$language_hashref->{'current_lang'},'region');
124 $language_hashref->{'variant_description'} = language_get_description($language_hashref->{'variant_code'},$language_hashref->{'current_lang'},'variant');
126 if ($language_hashref->{'language_lang'} eq $lang) {
127 $language_hashref->{current}++;
129 push @template_languages, $language_hashref;
131 # load the languages ( for switching from one template to another )
132 $template->param( languages_loop => \@template_languages,
139 #---------------------------------------------------------------------------------------------------------
142 my ( $htdocs, $tmpl, $interface, $query ) = @_;
144 # Set some defaults for language and theme
145 # First, check the user's preferences
147 my $http_accept_language = regex_lang_subtags($ENV{HTTP_ACCEPT_LANGUAGE})->{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 pop @languages, $lang if $lang;
167 # we are in the opac here, what im trying to do is let the individual user
168 # set the theme they want to use.
169 # and perhaps the them as well.
170 #my $lang = $query->cookie('KohaOpacLanguage');
173 push @languages, $lang;
174 @themes = split " ", C4::Context->preference("opacthemes");
177 @languages = split " ", C4::Context->preference("opaclanguages");
178 @themes = split " ", C4::Context->preference("opacthemes");
182 # searches through the themes and languages. First template it find it returns.
183 # Priority is for getting the theme right.
185 foreach my $th (@themes) {
186 foreach my $la (@languages) {
187 for ( my $pass = 1 ; $pass <= 2 ; $pass += 1 ) {
188 $la =~ s/([-_])/ $1 eq '-'? '_': '-' /eg if $pass == 2;
189 if ( -e "$htdocs/$th/$la/".($interface eq 'intranet'?"modules":"")."/$tmpl" ) {
194 last unless $la =~ /[-_]/;
198 return ( $theme, $lang );
201 sub setlanguagecookie {
202 my ( $query, $language, $uri ) = @_;
203 my $cookie = $query->cookie(
204 -name => 'KohaOpacLanguage',
208 print $query->redirect(
216 pagination_bar($base_url, $nb_pages, $current_page, $startfrom_name)
218 Build an HTML pagination bar based on the number of page to display, the
219 current page and the url to give to each page link.
221 C<$base_url> is the URL for each page link. The
222 C<$startfrom_name>=page_number is added at the end of the each URL.
224 C<$nb_pages> is the total number of pages available.
226 C<$current_page> is the current page number. This page number won't become a
229 This function returns HTML, without any language dependency.
234 my ( $base_url, $nb_pages, $current_page, $startfrom_name ) = @_;
236 # how many pages to show before and after the current page?
237 my $pages_around = 2;
240 $base_url . ( $base_url =~ m/&/ ? '&' : '?' ) . $startfrom_name . '=';
242 my $pagination_bar = '';
244 # current page detection
245 if ( not defined $current_page ) {
249 # navigation bar useful only if more than one page to display !
250 if ( $nb_pages > 1 ) {
252 # link to first page?
253 if ( $current_page > 1 ) {
259 . '<<' . '</a>';
263 "\n" . ' <span class="inactive"><<</span>';
266 # link on previous page ?
267 if ( $current_page > 1 ) {
268 my $previous = $current_page - 1;
275 . '" rel="prev">' . '<' . '</a>';
279 "\n" . ' <span class="inactive"><</span>';
282 my $min_to_display = $current_page - $pages_around;
283 my $max_to_display = $current_page + $pages_around;
284 my $last_displayed_page = undef;
286 for my $page_number ( 1 .. $nb_pages ) {
289 or $page_number == $nb_pages
290 or ( $page_number >= $min_to_display
291 and $page_number <= $max_to_display )
294 if ( defined $last_displayed_page
295 and $last_displayed_page != $page_number - 1 )
298 "\n" . ' <span class="inactive">...</span>';
301 if ( $page_number == $current_page ) {
304 . '<span class="currentPage">'
313 . $page_number . '">'
314 . $page_number . '</a>';
316 $last_displayed_page = $page_number;
321 if ( $current_page < $nb_pages ) {
322 my $next = $current_page + 1;
324 $pagination_bar .= "\n"
328 . '" rel="next">' . '>' . '</a>';
332 "\n" . ' <span class="inactive">></span>';
336 if ( $current_page != $nb_pages ) {
337 $pagination_bar .= "\n"
342 . '>>' . '</a>';
346 "\n" . ' <span class="inactive">>></span>';
350 return $pagination_bar;
353 =item output_html_with_http_headers
355 &output_html_with_http_headers($query, $cookie, $html)
357 Outputs the HTML page $html with the appropriate HTTP headers,
358 with the authentication cookie $cookie and a Content-Type that
359 corresponds to the HTML page $html.
363 sub output_html_with_http_headers ($$$) {
364 my($query, $cookie, $html) = @_;
365 print $query->header(
366 -type => 'text/html',
369 -Pragma => 'no-cache',
370 -'Cache-Control' => 'no-cache',
374 END { } # module clean-up code here (global destructor)
383 Koha Developement team <info@koha.org>