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 HTML::Template::Pro;
34 use vars qw($VERSION @ISA @EXPORT);
36 # set the version for version checking
41 C4::Output - Functions for managing templates
51 &themelanguage &gettemplate setlanguagecookie pagination_bar
56 &output_html_with_http_headers
60 #FIXME: this is a quick fix to stop rc1 installing broken
61 #Still trying to figure out the correct fix.
62 my $path = C4::Context->config('intrahtdocs') . "/prog/en/includes/";
64 #---------------------------------------------------------------------------------------------------------
67 my ( $tmplbase, $interface, $query ) = @_;
69 warn "no query in gettemplate";
72 if ( $interface ne "intranet" ) {
73 $htdocs = C4::Context->config('opachtdocs');
76 $htdocs = C4::Context->config('intrahtdocs');
78 my $path = C4::Context->preference('intranet_includes') || 'includes';
80 # warn "PATH : $path";
81 my ( $theme, $lang ) = themelanguage( $htdocs, $tmplbase, $interface, $query );
82 my $opacstylesheet = C4::Context->preference('opacstylesheet');
83 my $template = HTML::Template::Pro->new(
84 filename => "$htdocs/$theme/$lang/modules/$tmplbase",
85 die_on_bad_params => 1,
88 path => ["$htdocs/$theme/$lang/$path"]
92 themelang => ( $interface ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' )
94 interface => ( $interface ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' ),
96 opacstylesheet => $opacstylesheet,
97 opaccolorstylesheet => C4::Context->preference('opaccolorstylesheet'),
98 opacsmallimage => C4::Context->preference('opacsmallimage'),
105 #---------------------------------------------------------------------------------------------------------
108 my ( $htdocs, $tmpl, $section, $query ) = @_;
113 my $dbh = C4::Context->dbh;
116 if ( $section eq "intranet" ) {
117 @languages = split " ", C4::Context->preference("opaclanguages");
118 @themes = split " ", C4::Context->preference("template");
122 # we are in the opac here, what im trying to do is let the individual user
123 # set the theme they want to use.
124 # and perhaps the them as well.
125 my $lang = $query->cookie('KohaOpacLanguage');
128 push @languages, $lang;
129 @themes = split " ", C4::Context->preference("opacthemes");
132 @languages = split " ", C4::Context->preference("opaclanguages");
133 @themes = split " ", C4::Context->preference("opacthemes");
137 my ( $theme, $lang );
139 # searches through the themes and languages. First template it find it returns.
140 # Priority is for getting the theme right.
142 foreach my $th (@themes) {
143 foreach my $la (@languages) {
144 for ( my $pass = 1 ; $pass <= 2 ; $pass += 1 ) {
145 $la =~ s/([-_])/ $1 eq '-'? '_': '-' /eg if $pass == 2;
146 if ( -e "$htdocs/$th/$la/modules/$tmpl" ) {
151 last unless $la =~ /[-_]/;
155 if ( $theme and $lang ) {
156 return ( $theme, $lang );
159 return ( 'prog', 'en' );
163 sub setlanguagecookie {
164 my ( $query, $language, $uri ) = @_;
165 my $cookie = $query->cookie(
166 -name => 'KohaOpacLanguage',
170 print $query->redirect(
178 pagination_bar($base_url, $nb_pages, $current_page, $startfrom_name)
180 Build an HTML pagination bar based on the number of page to display, the
181 current page and the url to give to each page link.
183 C<$base_url> is the URL for each page link. The
184 C<$startfrom_name>=page_number is added at the end of the each URL.
186 C<$nb_pages> is the total number of pages available.
188 C<$current_page> is the current page number. This page number won't become a
191 This function returns HTML, without any language dependency.
196 my ( $base_url, $nb_pages, $current_page, $startfrom_name ) = @_;
198 # how many pages to show before and after the current page?
199 my $pages_around = 2;
202 $base_url . ( $base_url =~ m/&/ ? '&' : '?' ) . $startfrom_name . '=';
204 my $pagination_bar = '';
206 # current page detection
207 if ( not defined $current_page ) {
211 # navigation bar useful only if more than one page to display !
212 if ( $nb_pages > 1 ) {
214 # link to first page?
215 if ( $current_page > 1 ) {
221 . '<<' . '</a>';
225 "\n" . ' <span class="inactive"><<</span>';
228 # link on previous page ?
229 if ( $current_page > 1 ) {
230 my $previous = $current_page - 1;
237 . '" rel="prev">' . '<' . '</a>';
241 "\n" . ' <span class="inactive"><</span>';
244 my $min_to_display = $current_page - $pages_around;
245 my $max_to_display = $current_page + $pages_around;
246 my $last_displayed_page = undef;
248 for my $page_number ( 1 .. $nb_pages ) {
251 or $page_number == $nb_pages
252 or ( $page_number >= $min_to_display
253 and $page_number <= $max_to_display )
256 if ( defined $last_displayed_page
257 and $last_displayed_page != $page_number - 1 )
260 "\n" . ' <span class="inactive">...</span>';
263 if ( $page_number == $current_page ) {
266 . '<span class="currentPage">'
275 . $page_number . '">'
276 . $page_number . '</a>';
278 $last_displayed_page = $page_number;
283 if ( $current_page < $nb_pages ) {
284 my $next = $current_page + 1;
286 $pagination_bar .= "\n"
290 . '" rel="next">' . '>' . '</a>';
294 "\n" . ' <span class="inactive">></span>';
298 if ( $current_page != $nb_pages ) {
299 $pagination_bar .= "\n"
304 . '>>' . '</a>';
308 "\n" . ' <span class="inactive">>></span>';
312 return $pagination_bar;
315 =item output_html_with_http_headers
317 &output_html_with_http_headers($query, $cookie, $html)
319 Outputs the HTML page $html with the appropriate HTTP headers,
320 with the authentication cookie $cookie and a Content-Type that
321 corresponds to the HTML page $html.
325 sub output_html_with_http_headers ($$$) {
326 my($query, $cookie, $html) = @_;
327 print $query->header(
328 -type => 'text/html',
331 -Pragma => 'no-cache',
332 -'Cache-Control' => 'no-cache',
336 END { } # module clean-up code here (global destructor)
345 Koha Developement team <info@koha.org>