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);
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');
84 my $template = HTML::Template::Pro->new(
85 filename => "$htdocs/$theme/$lang/modules/$tmplbase",
86 die_on_bad_params => 1,
89 path => ["$htdocs/$theme/$lang/$path"]
93 themelang => ( $interface ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' )
95 interface => ( $interface ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' ),
97 opacstylesheet => $opacstylesheet,
98 opaccolorstylesheet => C4::Context->preference('opaccolorstylesheet'),
99 opacsmallimage => C4::Context->preference('opacsmallimage'),
103 # Languages and Locale
105 my @template_languages;
106 my $languages_loop = getTranslatedLanguages($interface,$theme);
107 for my $language_hashref (@$languages_loop) {
108 if ($language_hashref->{language_code} eq $lang) {
109 $language_hashref->{current}++;
110 if ($language_hashref->{bidi}) {
111 $bidi = $language_hashref->{bidi};
114 push @template_languages, $language_hashref;
116 # load the languages ( for switching from one template to another )
117 $template->param( languages_loop => \@template_languages,
124 #---------------------------------------------------------------------------------------------------------
127 my ( $htdocs, $tmpl, $section, $query ) = @_;
133 # set some defaults for language and theme
134 my $lang = $query->cookie('KohaOpacLanguage');
135 $lang = 'en' unless $lang;
138 my $dbh = C4::Context->dbh;
141 if ( $section eq "intranet" ) {
142 @languages = split " ", C4::Context->preference("opaclanguages");
143 @themes = split " ", C4::Context->preference("template");
144 pop @languages, $lang if $lang;
148 # we are in the opac here, what im trying to do is let the individual user
149 # set the theme they want to use.
150 # and perhaps the them as well.
151 #my $lang = $query->cookie('KohaOpacLanguage');
154 push @languages, $lang;
155 @themes = split " ", C4::Context->preference("opacthemes");
158 @languages = split " ", C4::Context->preference("opaclanguages");
159 @themes = split " ", C4::Context->preference("opacthemes");
163 # searches through the themes and languages. First template it find it returns.
164 # Priority is for getting the theme right.
166 foreach my $th (@themes) {
167 foreach my $la (@languages) {
168 for ( my $pass = 1 ; $pass <= 2 ; $pass += 1 ) {
169 $la =~ s/([-_])/ $1 eq '-'? '_': '-' /eg if $pass == 2;
170 if ( -e "$htdocs/$th/$la/modules/$tmpl" ) {
175 last unless $la =~ /[-_]/;
179 return ( $theme, $lang );
182 sub setlanguagecookie {
183 my ( $query, $language, $uri ) = @_;
184 my $cookie = $query->cookie(
185 -name => 'KohaOpacLanguage',
189 print $query->redirect(
197 pagination_bar($base_url, $nb_pages, $current_page, $startfrom_name)
199 Build an HTML pagination bar based on the number of page to display, the
200 current page and the url to give to each page link.
202 C<$base_url> is the URL for each page link. The
203 C<$startfrom_name>=page_number is added at the end of the each URL.
205 C<$nb_pages> is the total number of pages available.
207 C<$current_page> is the current page number. This page number won't become a
210 This function returns HTML, without any language dependency.
215 my ( $base_url, $nb_pages, $current_page, $startfrom_name ) = @_;
217 # how many pages to show before and after the current page?
218 my $pages_around = 2;
221 $base_url . ( $base_url =~ m/&/ ? '&' : '?' ) . $startfrom_name . '=';
223 my $pagination_bar = '';
225 # current page detection
226 if ( not defined $current_page ) {
230 # navigation bar useful only if more than one page to display !
231 if ( $nb_pages > 1 ) {
233 # link to first page?
234 if ( $current_page > 1 ) {
240 . '<<' . '</a>';
244 "\n" . ' <span class="inactive"><<</span>';
247 # link on previous page ?
248 if ( $current_page > 1 ) {
249 my $previous = $current_page - 1;
256 . '" rel="prev">' . '<' . '</a>';
260 "\n" . ' <span class="inactive"><</span>';
263 my $min_to_display = $current_page - $pages_around;
264 my $max_to_display = $current_page + $pages_around;
265 my $last_displayed_page = undef;
267 for my $page_number ( 1 .. $nb_pages ) {
270 or $page_number == $nb_pages
271 or ( $page_number >= $min_to_display
272 and $page_number <= $max_to_display )
275 if ( defined $last_displayed_page
276 and $last_displayed_page != $page_number - 1 )
279 "\n" . ' <span class="inactive">...</span>';
282 if ( $page_number == $current_page ) {
285 . '<span class="currentPage">'
294 . $page_number . '">'
295 . $page_number . '</a>';
297 $last_displayed_page = $page_number;
302 if ( $current_page < $nb_pages ) {
303 my $next = $current_page + 1;
305 $pagination_bar .= "\n"
309 . '" rel="next">' . '>' . '</a>';
313 "\n" . ' <span class="inactive">></span>';
317 if ( $current_page != $nb_pages ) {
318 $pagination_bar .= "\n"
323 . '>>' . '</a>';
327 "\n" . ' <span class="inactive">>></span>';
331 return $pagination_bar;
334 =item output_html_with_http_headers
336 &output_html_with_http_headers($query, $cookie, $html)
338 Outputs the HTML page $html with the appropriate HTTP headers,
339 with the authentication cookie $cookie and a Content-Type that
340 corresponds to the HTML page $html.
344 sub output_html_with_http_headers ($$$) {
345 my($query, $cookie, $html) = @_;
346 print $query->header(
347 -type => 'text/html',
350 -Pragma => 'no-cache',
351 -'Cache-Control' => 'no-cache',
355 END { } # module clean-up code here (global destructor)
364 Koha Developement team <info@koha.org>