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/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};
110 my $languages_loop = getTranslatedLanguages($interface,$theme,$lang);
112 languages_loop => $languages_loop,
114 ) unless @$languages_loop<2;
119 #---------------------------------------------------------------------------------------------------------
122 my ( $htdocs, $tmpl, $interface, $query ) = @_;
123 ($query) or warn "no query in themelanguage";
125 # Set some defaults for language and theme
126 # First, check the user's preferences
128 my $http_accept_language = regex_lang_subtags($ENV{HTTP_ACCEPT_LANGUAGE})->{language};
129 if ($http_accept_language) {
130 $lang = accept_language($http_accept_language,getTranslatedLanguages($interface,'prog'));
132 # But, if there's a cookie set, obey it
133 $lang = $query->cookie('KohaOpacLanguage') if $query->cookie('KohaOpacLanguage');
134 # Fall back to English
135 my @languages = split " ", C4::Context->preference("opaclanguages");
137 @languages=($lang,@languages);
139 $lang = $languages[0];
143 my $dbh = C4::Context->dbh;
146 if ( $interface eq "intranet" ) {
147 @themes = split " ", C4::Context->preference("template");
150 # we are in the opac here, what im trying to do is let the individual user
151 # set the theme they want to use.
152 # and perhaps the them as well.
153 #my $lang = $query->cookie('KohaOpacLanguage');
154 @themes = split " ", C4::Context->preference("opacthemes");
157 # searches through the themes and languages. First template it find it returns.
158 # Priority is for getting the theme right.
160 foreach my $th (@themes) {
161 foreach my $la (@languages) {
162 #for ( my $pass = 1 ; $pass <= 2 ; $pass += 1 ) {
163 # warn "$htdocs/$th/$la/modules/$interface-"."tmpl";
164 #$la =~ s/([-_])/ $1 eq '-'? '_': '-' /eg if $pass == 2;
165 if ( -e "$htdocs/$th/$la/modules/$tmpl") {
166 #".($interface eq 'intranet'?"modules":"")."/$tmpl" ) {
171 last unless $la =~ /[-_]/;
175 return ( $theme, $lang );
178 sub setlanguagecookie {
179 my ( $query, $language, $uri ) = @_;
180 my $cookie = $query->cookie(
181 -name => 'KohaOpacLanguage',
185 print $query->redirect(
193 pagination_bar($base_url, $nb_pages, $current_page, $startfrom_name)
195 Build an HTML pagination bar based on the number of page to display, the
196 current page and the url to give to each page link.
198 C<$base_url> is the URL for each page link. The
199 C<$startfrom_name>=page_number is added at the end of the each URL.
201 C<$nb_pages> is the total number of pages available.
203 C<$current_page> is the current page number. This page number won't become a
206 This function returns HTML, without any language dependency.
211 my ( $base_url, $nb_pages, $current_page, $startfrom_name ) = @_;
213 # how many pages to show before and after the current page?
214 my $pages_around = 2;
217 $base_url . ( $base_url =~ m/&/ ? '&' : '?' ) . $startfrom_name . '=';
219 my $pagination_bar = '';
221 # current page detection
222 if ( not defined $current_page ) {
226 # navigation bar useful only if more than one page to display !
227 if ( $nb_pages > 1 ) {
229 # link to first page?
230 if ( $current_page > 1 ) {
236 . '<<' . '</a>';
240 "\n" . ' <span class="inactive"><<</span>';
243 # link on previous page ?
244 if ( $current_page > 1 ) {
245 my $previous = $current_page - 1;
252 . '" rel="prev">' . '<' . '</a>';
256 "\n" . ' <span class="inactive"><</span>';
259 my $min_to_display = $current_page - $pages_around;
260 my $max_to_display = $current_page + $pages_around;
261 my $last_displayed_page = undef;
263 for my $page_number ( 1 .. $nb_pages ) {
266 or $page_number == $nb_pages
267 or ( $page_number >= $min_to_display
268 and $page_number <= $max_to_display )
271 if ( defined $last_displayed_page
272 and $last_displayed_page != $page_number - 1 )
275 "\n" . ' <span class="inactive">...</span>';
278 if ( $page_number == $current_page ) {
281 . '<span class="currentPage">'
290 . $page_number . '">'
291 . $page_number . '</a>';
293 $last_displayed_page = $page_number;
298 if ( $current_page < $nb_pages ) {
299 my $next = $current_page + 1;
301 $pagination_bar .= "\n"
305 . '" rel="next">' . '>' . '</a>';
309 "\n" . ' <span class="inactive">></span>';
313 if ( $current_page != $nb_pages ) {
314 $pagination_bar .= "\n"
319 . '>>' . '</a>';
323 "\n" . ' <span class="inactive">>></span>';
327 return $pagination_bar;
330 =item output_html_with_http_headers
332 &output_html_with_http_headers($query, $cookie, $html)
334 Outputs the HTML page $html with the appropriate HTTP headers,
335 with the authentication cookie $cookie and a Content-Type that
336 corresponds to the HTML page $html.
340 sub output_html_with_http_headers ($$$) {
341 my($query, $cookie, $html) = @_;
342 print $query->header(
343 -type => 'text/html',
346 -Pragma => 'no-cache',
347 -'Cache-Control' => 'no-cache',
351 END { } # module clean-up code here (global destructor)
360 Koha Developement team <info@koha.org>