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";
68 warn "Template base is $tmplbase";
70 if ( $interface ne "intranet" ) {
71 $htdocs = C4::Context->config('opachtdocs');
74 $htdocs = C4::Context->config('intrahtdocs');
76 my $path = C4::Context->preference('intranet_includes') || 'includes';
78 my ( $theme, $lang ) = themelanguage( $htdocs, $tmplbase, $interface, $query );
79 my $opacstylesheet = C4::Context->preference('opacstylesheet');
81 # if the template doesn't exist, load the English one as a last resort
82 my $filename = "$htdocs/$theme/$lang/modules/$tmplbase";
83 unless (-f $filename) {
85 $filename = "$htdocs/$theme/$lang/modules/$tmplbase";
87 my $template = HTML::Template::Pro->new(
88 filename => $filename,
89 die_on_bad_params => 1,
92 path => ["$htdocs/$theme/$lang/$path"]
96 themelang => ( $interface ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' )
98 interface => ( $interface ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' ),
100 opacstylesheet => $opacstylesheet,
101 opaccolorstylesheet => C4::Context->preference('opaccolorstylesheet'),
102 opacsmallimage => C4::Context->preference('opacsmallimage'),
107 my $current_lang = regex_lang_subtags($lang);
109 $bidi = get_bidi($current_lang->{script}) if $current_lang->{script};
111 my $languages_loop = getTranslatedLanguages($interface,$theme,$lang);
113 languages_loop => $languages_loop,
115 ) unless @$languages_loop<2;
120 #---------------------------------------------------------------------------------------------------------
123 my ( $htdocs, $tmpl, $interface, $query ) = @_;
124 ($query) or warn "no query in themelanguage";
126 # Set some defaults for language and theme
127 # First, check the user's preferences
129 my $http_accept_language = regex_lang_subtags($ENV{HTTP_ACCEPT_LANGUAGE})->{language};
130 if ($http_accept_language) {
131 $lang = accept_language($http_accept_language,getTranslatedLanguages($interface,'prog'));
133 # But, if there's a cookie set, obey it
134 $lang = $query->cookie('KohaOpacLanguage') if $query->cookie('KohaOpacLanguage');
135 # Fall back to English
136 my @languages = split " ", C4::Context->preference("opaclanguages");
138 @languages=($lang,@languages);
140 $lang = $languages[0];
142 my $theme = 'prog'; # in the event of theme failure default to 'prog' -fbcit
143 my $dbh = C4::Context->dbh;
145 if ( $interface eq "intranet" ) {
146 @themes = split " ", C4::Context->preference("template");
149 # we are in the opac here, what im trying to do is let the individual user
150 # set the theme they want to use.
151 # and perhaps the them as well.
152 #my $lang = $query->cookie('KohaOpacLanguage');
153 @themes = split " ", C4::Context->preference("opacthemes");
156 # searches through the themes and languages. First template it find it returns.
157 # Priority is for getting the theme right.
159 foreach my $th (@themes) {
160 foreach my $la (@languages) {
161 #for ( my $pass = 1 ; $pass <= 2 ; $pass += 1 ) {
162 # warn "$htdocs/$th/$la/modules/$interface-"."tmpl";
163 #$la =~ s/([-_])/ $1 eq '-'? '_': '-' /eg if $pass == 2;
164 if ( -e "$htdocs/$th/$la/modules/$tmpl") {
165 #".($interface eq 'intranet'?"modules":"")."/$tmpl" ) {
170 last unless $la =~ /[-_]/;
174 return ( $theme, $lang );
177 sub setlanguagecookie {
178 my ( $query, $language, $uri ) = @_;
179 my $cookie = $query->cookie(
180 -name => 'KohaOpacLanguage',
184 print $query->redirect(
192 pagination_bar($base_url, $nb_pages, $current_page, $startfrom_name)
194 Build an HTML pagination bar based on the number of page to display, the
195 current page and the url to give to each page link.
197 C<$base_url> is the URL for each page link. The
198 C<$startfrom_name>=page_number is added at the end of the each URL.
200 C<$nb_pages> is the total number of pages available.
202 C<$current_page> is the current page number. This page number won't become a
205 This function returns HTML, without any language dependency.
210 my ( $base_url, $nb_pages, $current_page, $startfrom_name ) = @_;
212 # how many pages to show before and after the current page?
213 my $pages_around = 2;
216 $base_url . ( $base_url =~ m/&/ ? '&' : '?' ) . $startfrom_name . '=';
218 my $pagination_bar = '';
220 # current page detection
221 if ( not defined $current_page ) {
225 # navigation bar useful only if more than one page to display !
226 if ( $nb_pages > 1 ) {
228 # link to first page?
229 if ( $current_page > 1 ) {
235 . '<<' . '</a>';
239 "\n" . ' <span class="inactive"><<</span>';
242 # link on previous page ?
243 if ( $current_page > 1 ) {
244 my $previous = $current_page - 1;
251 . '" rel="prev">' . '<' . '</a>';
255 "\n" . ' <span class="inactive"><</span>';
258 my $min_to_display = $current_page - $pages_around;
259 my $max_to_display = $current_page + $pages_around;
260 my $last_displayed_page = undef;
262 for my $page_number ( 1 .. $nb_pages ) {
265 or $page_number == $nb_pages
266 or ( $page_number >= $min_to_display
267 and $page_number <= $max_to_display )
270 if ( defined $last_displayed_page
271 and $last_displayed_page != $page_number - 1 )
274 "\n" . ' <span class="inactive">...</span>';
277 if ( $page_number == $current_page ) {
280 . '<span class="currentPage">'
289 . $page_number . '">'
290 . $page_number . '</a>';
292 $last_displayed_page = $page_number;
297 if ( $current_page < $nb_pages ) {
298 my $next = $current_page + 1;
300 $pagination_bar .= "\n"
304 . '" rel="next">' . '>' . '</a>';
308 "\n" . ' <span class="inactive">></span>';
312 if ( $current_page != $nb_pages ) {
313 $pagination_bar .= "\n"
318 . '>>' . '</a>';
322 "\n" . ' <span class="inactive">>></span>';
326 return $pagination_bar;
329 =item output_html_with_http_headers
331 &output_html_with_http_headers($query, $cookie, $html)
333 Outputs the HTML page $html with the appropriate HTTP headers,
334 with the authentication cookie $cookie and a Content-Type that
335 corresponds to the HTML page $html.
339 sub output_html_with_http_headers ($$$) {
340 my($query, $cookie, $html) = @_;
341 print $query->header(
342 -type => 'text/html',
345 -Pragma => 'no-cache',
346 -'Cache-Control' => 'no-cache',
350 END { } # module clean-up code here (global destructor)
359 Koha Developement team <info@koha.org>