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);
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
57 &output_html_with_http_headers
61 #FIXME: this is a quick fix to stop rc1 installing broken
62 #Still trying to figure out the correct fix.
63 my $path = C4::Context->config('intrahtdocs') . "/prog/en/includes/";
65 #---------------------------------------------------------------------------------------------------------
68 my ( $tmplbase, $interface, $query ) = @_;
70 warn "no query in gettemplate";
73 if ( $interface ne "intranet" ) {
74 $htdocs = C4::Context->config('opachtdocs');
77 $htdocs = C4::Context->config('intrahtdocs');
79 my $path = C4::Context->preference('intranet_includes') || 'includes';
81 # warn "PATH : $path";
82 my ( $theme, $lang ) = themelanguage( $htdocs, $tmplbase, $interface, $query );
83 my $opacstylesheet = C4::Context->preference('opacstylesheet');
85 # if the template doesn't exist, load the English one as a last resort
86 my $filename = "$htdocs/$theme/$lang/".($interface eq 'intranet'?"modules":"")."/$tmplbase";
87 unless (-f $filename) {
89 $filename = "$htdocs/$theme/$lang/".($interface eq 'intranet'?"modules":"")."/$tmplbase";
91 my $template = HTML::Template::Pro->new(
92 filename => $filename,
93 die_on_bad_params => 1,
96 path => ["$htdocs/$theme/$lang/$path"]
100 themelang => ( $interface ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' )
102 interface => ( $interface ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' ),
104 opacstylesheet => $opacstylesheet,
105 opaccolorstylesheet => C4::Context->preference('opaccolorstylesheet'),
106 opacsmallimage => C4::Context->preference('opacsmallimage'),
111 my $language_subtags_hashref = regex_lang_subtags($lang);
113 $bidi = get_bidi($language_subtags_hashref->{script}) if $language_subtags_hashref->{script};
116 my $current_lang = regex_lang_subtags($lang);
117 my @template_languages;
118 my $languages_loop = getTranslatedLanguages($interface,$theme);
119 for my $language_hashref (@$languages_loop) {
120 $language_hashref->{'current_lang'} = $current_lang->{'language'};
121 $language_hashref->{'native_description'} = language_get_description($language_hashref->{'language_code'},$language_hashref->{'language_code'},'language');
122 warn "($language_hashref->{'language_code'},$language_hashref->{'current_lang'},$language_hashref->{'script_code'}";
123 $language_hashref->{'locale_description'} = language_get_description($language_hashref->{'language_code'},$language_hashref->{'current_lang'},'language');
124 $language_hashref->{'language_description'} = language_get_description($language_hashref->{'language_code'},$language_hashref->{'current_lang'},'language');
125 $language_hashref->{'script_description'} = language_get_description($language_hashref->{'script_code'},$language_hashref->{'current_lang'},'script');
126 $language_hashref->{'region_description'} = language_get_description($language_hashref->{'region_code'},$language_hashref->{'current_lang'},'region');
127 $language_hashref->{'variant_description'} = language_get_description($language_hashref->{'variant_code'},$language_hashref->{'current_lang'},'variant');
129 if ($language_hashref->{'language_lang'} eq $lang) {
130 $language_hashref->{current}++;
132 push @template_languages, $language_hashref;
134 # load the languages ( for switching from one template to another )
135 $template->param( languages_loop => \@template_languages,
142 #---------------------------------------------------------------------------------------------------------
145 my ( $htdocs, $tmpl, $section, $query ) = @_;
151 # set some defaults for language and theme
152 my $lang = $query->cookie('KohaOpacLanguage');
153 $lang = 'en' unless $lang;
156 my $dbh = C4::Context->dbh;
159 if ( $section eq "intranet" ) {
160 @languages = split " ", C4::Context->preference("opaclanguages");
161 @themes = split " ", C4::Context->preference("template");
162 pop @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');
172 push @languages, $lang;
173 @themes = split " ", C4::Context->preference("opacthemes");
176 @languages = split " ", C4::Context->preference("opaclanguages");
177 @themes = split " ", C4::Context->preference("opacthemes");
181 # searches through the themes and languages. First template it find it returns.
182 # Priority is for getting the theme right.
184 foreach my $th (@themes) {
185 foreach my $la (@languages) {
186 for ( my $pass = 1 ; $pass <= 2 ; $pass += 1 ) {
187 $la =~ s/([-_])/ $1 eq '-'? '_': '-' /eg if $pass == 2;
188 if ( -e "$htdocs/$th/$la/modules/$tmpl" ) {
193 last unless $la =~ /[-_]/;
197 return ( $theme, $lang );
200 sub setlanguagecookie {
201 my ( $query, $language, $uri ) = @_;
202 my $cookie = $query->cookie(
203 -name => 'KohaOpacLanguage',
207 print $query->redirect(
215 pagination_bar($base_url, $nb_pages, $current_page, $startfrom_name)
217 Build an HTML pagination bar based on the number of page to display, the
218 current page and the url to give to each page link.
220 C<$base_url> is the URL for each page link. The
221 C<$startfrom_name>=page_number is added at the end of the each URL.
223 C<$nb_pages> is the total number of pages available.
225 C<$current_page> is the current page number. This page number won't become a
228 This function returns HTML, without any language dependency.
233 my ( $base_url, $nb_pages, $current_page, $startfrom_name ) = @_;
235 # how many pages to show before and after the current page?
236 my $pages_around = 2;
239 $base_url . ( $base_url =~ m/&/ ? '&' : '?' ) . $startfrom_name . '=';
241 my $pagination_bar = '';
243 # current page detection
244 if ( not defined $current_page ) {
248 # navigation bar useful only if more than one page to display !
249 if ( $nb_pages > 1 ) {
251 # link to first page?
252 if ( $current_page > 1 ) {
258 . '<<' . '</a>';
262 "\n" . ' <span class="inactive"><<</span>';
265 # link on previous page ?
266 if ( $current_page > 1 ) {
267 my $previous = $current_page - 1;
274 . '" rel="prev">' . '<' . '</a>';
278 "\n" . ' <span class="inactive"><</span>';
281 my $min_to_display = $current_page - $pages_around;
282 my $max_to_display = $current_page + $pages_around;
283 my $last_displayed_page = undef;
285 for my $page_number ( 1 .. $nb_pages ) {
288 or $page_number == $nb_pages
289 or ( $page_number >= $min_to_display
290 and $page_number <= $max_to_display )
293 if ( defined $last_displayed_page
294 and $last_displayed_page != $page_number - 1 )
297 "\n" . ' <span class="inactive">...</span>';
300 if ( $page_number == $current_page ) {
303 . '<span class="currentPage">'
312 . $page_number . '">'
313 . $page_number . '</a>';
315 $last_displayed_page = $page_number;
320 if ( $current_page < $nb_pages ) {
321 my $next = $current_page + 1;
323 $pagination_bar .= "\n"
327 . '" rel="next">' . '>' . '</a>';
331 "\n" . ' <span class="inactive">></span>';
335 if ( $current_page != $nb_pages ) {
336 $pagination_bar .= "\n"
341 . '>>' . '</a>';
345 "\n" . ' <span class="inactive">>></span>';
349 return $pagination_bar;
352 =item output_html_with_http_headers
354 &output_html_with_http_headers($query, $cookie, $html)
356 Outputs the HTML page $html with the appropriate HTTP headers,
357 with the authentication cookie $cookie and a Content-Type that
358 corresponds to the HTML page $html.
362 sub output_html_with_http_headers ($$$) {
363 my($query, $cookie, $html) = @_;
364 print $query->header(
365 -type => 'text/html',
368 -Pragma => 'no-cache',
369 -'Cache-Control' => 'no-cache',
373 END { } # module clean-up code here (global destructor)
382 Koha Developement team <info@koha.org>