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'),
110 # Language, Script, and Locale
111 my $language_subtags_hashref = regex_lang_subtags($lang);
113 $bidi = get_bidi($language_subtags_hashref->{script}) if $language_subtags_hashref->{script};
114 my @template_languages;
115 my $languages_loop = getTranslatedLanguages($interface,$theme);
116 for my $language_hashref (@$languages_loop) {
117 $language_hashref->{'language_script_description'} = language_get_description($language_hashref->{'language_script'},$lang);
118 $language_hashref->{'language_region_description'} = language_get_description($language_hashref->{'language_region'},$lang);
119 $language_hashref->{'language_variant_description'} = language_get_description($language_hashref->{'language_variant'},$lang);
121 if ($language_hashref->{language_code} eq $language_subtags_hashref->{language}) {
122 $language_hashref->{current}++;
124 push @template_languages, $language_hashref;
126 # load the languages ( for switching from one template to another )
127 $template->param( languages_loop => \@template_languages,
134 #---------------------------------------------------------------------------------------------------------
137 my ( $htdocs, $tmpl, $section, $query ) = @_;
143 # set some defaults for language and theme
144 my $lang = $query->cookie('KohaOpacLanguage');
145 $lang = 'en' unless $lang;
148 my $dbh = C4::Context->dbh;
151 if ( $section eq "intranet" ) {
152 @languages = split " ", C4::Context->preference("opaclanguages");
153 @themes = split " ", C4::Context->preference("template");
154 pop @languages, $lang if $lang;
158 # we are in the opac here, what im trying to do is let the individual user
159 # set the theme they want to use.
160 # and perhaps the them as well.
161 #my $lang = $query->cookie('KohaOpacLanguage');
164 push @languages, $lang;
165 @themes = split " ", C4::Context->preference("opacthemes");
168 @languages = split " ", C4::Context->preference("opaclanguages");
169 @themes = split " ", C4::Context->preference("opacthemes");
173 # searches through the themes and languages. First template it find it returns.
174 # Priority is for getting the theme right.
176 foreach my $th (@themes) {
177 foreach my $la (@languages) {
178 for ( my $pass = 1 ; $pass <= 2 ; $pass += 1 ) {
179 $la =~ s/([-_])/ $1 eq '-'? '_': '-' /eg if $pass == 2;
180 if ( -e "$htdocs/$th/$la/modules/$tmpl" ) {
185 last unless $la =~ /[-_]/;
189 return ( $theme, $lang );
192 sub setlanguagecookie {
193 my ( $query, $language, $uri ) = @_;
194 my $cookie = $query->cookie(
195 -name => 'KohaOpacLanguage',
199 print $query->redirect(
207 pagination_bar($base_url, $nb_pages, $current_page, $startfrom_name)
209 Build an HTML pagination bar based on the number of page to display, the
210 current page and the url to give to each page link.
212 C<$base_url> is the URL for each page link. The
213 C<$startfrom_name>=page_number is added at the end of the each URL.
215 C<$nb_pages> is the total number of pages available.
217 C<$current_page> is the current page number. This page number won't become a
220 This function returns HTML, without any language dependency.
225 my ( $base_url, $nb_pages, $current_page, $startfrom_name ) = @_;
227 # how many pages to show before and after the current page?
228 my $pages_around = 2;
231 $base_url . ( $base_url =~ m/&/ ? '&' : '?' ) . $startfrom_name . '=';
233 my $pagination_bar = '';
235 # current page detection
236 if ( not defined $current_page ) {
240 # navigation bar useful only if more than one page to display !
241 if ( $nb_pages > 1 ) {
243 # link to first page?
244 if ( $current_page > 1 ) {
250 . '<<' . '</a>';
254 "\n" . ' <span class="inactive"><<</span>';
257 # link on previous page ?
258 if ( $current_page > 1 ) {
259 my $previous = $current_page - 1;
266 . '" rel="prev">' . '<' . '</a>';
270 "\n" . ' <span class="inactive"><</span>';
273 my $min_to_display = $current_page - $pages_around;
274 my $max_to_display = $current_page + $pages_around;
275 my $last_displayed_page = undef;
277 for my $page_number ( 1 .. $nb_pages ) {
280 or $page_number == $nb_pages
281 or ( $page_number >= $min_to_display
282 and $page_number <= $max_to_display )
285 if ( defined $last_displayed_page
286 and $last_displayed_page != $page_number - 1 )
289 "\n" . ' <span class="inactive">...</span>';
292 if ( $page_number == $current_page ) {
295 . '<span class="currentPage">'
304 . $page_number . '">'
305 . $page_number . '</a>';
307 $last_displayed_page = $page_number;
312 if ( $current_page < $nb_pages ) {
313 my $next = $current_page + 1;
315 $pagination_bar .= "\n"
319 . '" rel="next">' . '>' . '</a>';
323 "\n" . ' <span class="inactive">></span>';
327 if ( $current_page != $nb_pages ) {
328 $pagination_bar .= "\n"
333 . '>>' . '</a>';
337 "\n" . ' <span class="inactive">>></span>';
341 return $pagination_bar;
344 =item output_html_with_http_headers
346 &output_html_with_http_headers($query, $cookie, $html)
348 Outputs the HTML page $html with the appropriate HTTP headers,
349 with the authentication cookie $cookie and a Content-Type that
350 corresponds to the HTML page $html.
354 sub output_html_with_http_headers ($$$) {
355 my($query, $cookie, $html) = @_;
356 print $query->header(
357 -type => 'text/html',
360 -Pragma => 'no-cache',
361 -'Cache-Control' => 'no-cache',
365 END { } # module clean-up code here (global destructor)
374 Koha Developement team <info@koha.org>