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 @EXPORT_OK %EXPORT_TAGS);
37 # set the version for version checking
41 @EXPORT_OK = qw(&output_ajax_with_http_headers); # More stuff should go here instead
42 %EXPORT_TAGS = ( all =>[qw(&themelanguage &gettemplate setlanguagecookie pagination_bar
43 &output_ajax_with_http_headers &output_html_with_http_headers)],
44 ajax =>[qw(&output_ajax_with_http_headers)],
45 html =>[qw(&output_html_with_http_headers)]
48 &themelanguage &gettemplate setlanguagecookie pagination_bar
51 &output_html_with_http_headers
57 C4::Output - Functions for managing templates
65 #FIXME: this is a quick fix to stop rc1 installing broken
66 #Still trying to figure out the correct fix.
67 my $path = C4::Context->config('intrahtdocs') . "/prog/en/includes/";
69 #---------------------------------------------------------------------------------------------------------
72 my ( $tmplbase, $interface, $query ) = @_;
73 ($query) or warn "no query in gettemplate";
75 if ( $interface ne "intranet" ) {
76 $htdocs = C4::Context->config('opachtdocs');
79 $htdocs = C4::Context->config('intrahtdocs');
81 my $path = C4::Context->preference('intranet_includes') || 'includes';
83 my ( $theme, $lang ) = themelanguage( $htdocs, $tmplbase, $interface, $query );
84 my $opacstylesheet = C4::Context->preference('opacstylesheet');
86 # if the template doesn't exist, load the English one as a last resort
87 my $filename = "$htdocs/$theme/$lang/modules/$tmplbase";
88 unless (-f $filename) {
90 $filename = "$htdocs/$theme/$lang/modules/$tmplbase";
92 my $template = HTML::Template::Pro->new(
93 filename => $filename,
94 die_on_bad_params => 1,
97 loop_context_vars => 1, # enable: __first__, __last__, __inner__, __odd__, __counter__
98 path => ["$htdocs/$theme/$lang/$path"]
100 my $themelang=( $interface ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' )
103 themelang => $themelang,
104 yuipath => (C4::Context->preference("yuipath") eq "local"?"$themelang/lib/yui":C4::Context->preference("yuipath")),
105 interface => ( $interface ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' ),
107 opacstylesheet => $opacstylesheet,
108 opaccolorstylesheet => C4::Context->preference('opaccolorstylesheet'),
109 opacsmallimage => C4::Context->preference('opacsmallimage'),
114 my $current_lang = regex_lang_subtags($lang);
116 $bidi = get_bidi($current_lang->{script}) if $current_lang->{script};
118 my $languages_loop = getTranslatedLanguages($interface,$theme,$lang);
120 languages_loop => $languages_loop,
122 ) unless @$languages_loop<2;
127 #---------------------------------------------------------------------------------------------------------
130 my ( $htdocs, $tmpl, $interface, $query ) = @_;
131 ($query) or warn "no query in themelanguage";
133 # Set some defaults for language and theme
134 # First, check the user's preferences
136 my $http_accept_language = regex_lang_subtags($ENV{HTTP_ACCEPT_LANGUAGE})->{language};
137 if ($http_accept_language) {
138 $lang = accept_language($http_accept_language,getTranslatedLanguages($interface,'prog'));
140 # But, if there's a cookie set, obey it
141 $lang = $query->cookie('KohaOpacLanguage') if $query->cookie('KohaOpacLanguage');
142 # Fall back to English
143 my @languages = split " ", C4::Context->preference("opaclanguages");
145 @languages=($lang,@languages);
147 $lang = $languages[0];
149 my $theme = 'prog'; # in the event of theme failure default to 'prog' -fbcit
150 my $dbh = C4::Context->dbh;
152 if ( $interface eq "intranet" ) {
153 @themes = split " ", C4::Context->preference("template");
156 # we are in the opac here, what im trying to do is let the individual user
157 # set the theme they want to use.
158 # and perhaps the them as well.
159 #my $lang = $query->cookie('KohaOpacLanguage');
160 @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 # warn "$htdocs/$th/$la/modules/$interface-"."tmpl";
170 #$la =~ s/([-_])/ $1 eq '-'? '_': '-' /eg if $pass == 2;
171 if ( -e "$htdocs/$th/$la/modules/$tmpl") {
172 #".($interface eq 'intranet'?"modules":"")."/$tmpl" ) {
177 last unless $la =~ /[-_]/;
181 return ( $theme, $lang );
184 sub setlanguagecookie {
185 my ( $query, $language, $uri ) = @_;
186 my $cookie = $query->cookie(
187 -name => 'KohaOpacLanguage',
191 print $query->redirect(
199 pagination_bar($base_url, $nb_pages, $current_page, $startfrom_name)
201 Build an HTML pagination bar based on the number of page to display, the
202 current page and the url to give to each page link.
204 C<$base_url> is the URL for each page link. The
205 C<$startfrom_name>=page_number is added at the end of the each URL.
207 C<$nb_pages> is the total number of pages available.
209 C<$current_page> is the current page number. This page number won't become a
212 This function returns HTML, without any language dependency.
217 my ( $base_url, $nb_pages, $current_page, $startfrom_name ) = @_;
219 # how many pages to show before and after the current page?
220 my $pages_around = 2;
223 $base_url . ( $base_url =~ m/[?&]/ ? '&' : '?' ) . $startfrom_name . '=';
225 my $pagination_bar = '';
227 # current page detection
228 if ( not defined $current_page ) {
232 # navigation bar useful only if more than one page to display !
233 if ( $nb_pages > 1 ) {
235 # link to first page?
236 if ( $current_page > 1 ) {
242 . '<<' . '</a>';
246 "\n" . ' <span class="inactive"><<</span>';
249 # link on previous page ?
250 if ( $current_page > 1 ) {
251 my $previous = $current_page - 1;
258 . '" rel="prev">' . '<' . '</a>';
262 "\n" . ' <span class="inactive"><</span>';
265 my $min_to_display = $current_page - $pages_around;
266 my $max_to_display = $current_page + $pages_around;
267 my $last_displayed_page = undef;
269 for my $page_number ( 1 .. $nb_pages ) {
272 or $page_number == $nb_pages
273 or ( $page_number >= $min_to_display
274 and $page_number <= $max_to_display )
277 if ( defined $last_displayed_page
278 and $last_displayed_page != $page_number - 1 )
281 "\n" . ' <span class="inactive">...</span>';
284 if ( $page_number == $current_page ) {
287 . '<span class="currentPage">'
296 . $page_number . '">'
297 . $page_number . '</a>';
299 $last_displayed_page = $page_number;
304 if ( $current_page < $nb_pages ) {
305 my $next = $current_page + 1;
307 $pagination_bar .= "\n"
311 . '" rel="next">' . '>' . '</a>';
315 "\n" . ' <span class="inactive">></span>';
319 if ( $current_page != $nb_pages ) {
320 $pagination_bar .= "\n"
325 . '>>' . '</a>';
329 "\n" . ' <span class="inactive">>></span>';
333 return $pagination_bar;
336 =item output_html_with_http_headers
338 &output_html_with_http_headers($query, $cookie, $html)
340 Outputs the HTML page $html with the appropriate HTTP headers,
341 with the authentication cookie $cookie and a Content-Type that
342 corresponds to the HTML page $html.
346 sub output_html_with_http_headers ($$$) {
347 my($query, $cookie, $html) = @_;
348 print $query->header(
349 -type => 'text/html',
352 -Pragma => 'no-cache',
353 -'Cache-Control' => 'no-cache',
357 sub output_ajax_with_http_headers ($$) {
358 my ($query, $js) = @_;
359 print $query->header(
360 -type => 'text/javascript',
362 -Pragma => 'no-cache',
363 -'Cache-Control' => 'no-cache',
368 END { } # module clean-up code here (global destructor)
377 Koha Developement team <info@koha.org>