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
26 # NOTE: I'm pretty sure this module is deprecated in favor of
33 use HTML::Template::Pro;
35 use vars qw($VERSION @ISA @EXPORT);
37 # set the version for version checking
38 $VERSION = do { my @v = '$Revision$' =~ /\d+/g; shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v ); };
42 C4::Output - Functions for managing templates
52 &themelanguage &gettemplate setlanguagecookie pagination_bar
55 #FIXME: this is a quick fix to stop rc1 installing broken
56 #Still trying to figure out the correct fix.
57 my $path = C4::Context->config('intrahtdocs') . "/default/en/includes/";
59 #---------------------------------------------------------------------------------------------------------
62 my ( $tmplbase, $opac, $query ) = @_;
64 warn "no query in gettemplate";
67 if ( $opac ne "intranet" ) {
68 $htdocs = C4::Context->config('opachtdocs');
71 $htdocs = C4::Context->config('intrahtdocs');
73 my $path = C4::Context->preference('intranet_includes') || 'includes';
75 # warn "PATH : $path";
76 my ( $theme, $lang ) = themelanguage( $htdocs, $tmplbase, $opac, $query );
77 my $opacstylesheet = C4::Context->preference('opacstylesheet');
78 my $template = HTML::Template::Pro->new(
79 filename => "$htdocs/$theme/$lang/$tmplbase",
80 die_on_bad_params => 1,
83 path => ["$htdocs/$theme/$lang/$path"]
87 themelang => ( $opac ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' )
89 interface => ( $opac ne 'intranet' ? '/opac-tmpl' : '/intranet-tmpl' ),
91 opacstylesheet => $opacstylesheet,
92 opaccolorstylesheet => C4::Context->preference('opaccolorstylesheet'),
93 opacsmallimage => C4::Context->preference('opacsmallimage'),
100 #---------------------------------------------------------------------------------------------------------
103 my ( $htdocs, $tmpl, $section, $query ) = @_;
108 my $dbh = C4::Context->dbh;
111 if ( $section eq "intranet" ) {
112 @languages = split " ", C4::Context->preference("opaclanguages");
113 @themes = split " ", C4::Context->preference("template");
117 # we are in the opac here, what im trying to do is let the individual user
118 # set the theme they want to use.
119 # and perhaps the them as well.
120 my $lang = $query->cookie('KohaOpacLanguage');
123 push @languages, $lang;
124 @themes = split " ", C4::Context->preference("opacthemes");
127 @languages = split " ", C4::Context->preference("opaclanguages");
128 @themes = split " ", C4::Context->preference("opacthemes");
132 my ( $theme, $lang );
134 # searches through the themes and languages. First template it find it returns.
135 # Priority is for getting the theme right.
137 foreach my $th (@themes) {
138 foreach my $la (@languages) {
139 for ( my $pass = 1 ; $pass <= 2 ; $pass += 1 ) {
140 $la =~ s/([-_])/ $1 eq '-'? '_': '-' /eg if $pass == 2;
141 if ( -e "$htdocs/$th/$la/$tmpl" ) {
146 last unless $la =~ /[-_]/;
150 if ( $theme and $lang ) {
151 return ( $theme, $lang );
154 return ( 'prog', 'en' );
158 sub setlanguagecookie {
159 my ( $query, $language, $uri ) = @_;
160 my $cookie = $query->cookie(
161 -name => 'KohaOpacLanguage',
165 print $query->redirect(
173 pagination_bar($base_url, $nb_pages, $current_page, $startfrom_name)
175 Build an HTML pagination bar based on the number of page to display, the
176 current page and the url to give to each page link.
178 C<$base_url> is the URL for each page link. The
179 C<$startfrom_name>=page_number is added at the end of the each URL.
181 C<$nb_pages> is the total number of pages available.
183 C<$current_page> is the current page number. This page number won't become a
186 This function returns HTML, without any language dependency.
191 my ( $base_url, $nb_pages, $current_page, $startfrom_name ) = @_;
193 # how many pages to show before and after the current page?
194 my $pages_around = 2;
197 $base_url . ( $base_url =~ m/&/ ? '&' : '?' ) . $startfrom_name . '=';
199 my $pagination_bar = '';
201 # current page detection
202 if ( not defined $current_page ) {
206 # navigation bar useful only if more than one page to display !
207 if ( $nb_pages > 1 ) {
209 # link to first page?
210 if ( $current_page > 1 ) {
216 . '<<' . '</a>';
220 "\n" . ' <span class="inactive"><<</span>';
223 # link on previous page ?
224 if ( $current_page > 1 ) {
225 my $previous = $current_page - 1;
232 . '" rel="prev">' . '<' . '</a>';
236 "\n" . ' <span class="inactive"><</span>';
239 my $min_to_display = $current_page - $pages_around;
240 my $max_to_display = $current_page + $pages_around;
241 my $last_displayed_page = undef;
243 for my $page_number ( 1 .. $nb_pages ) {
246 or $page_number == $nb_pages
247 or ( $page_number >= $min_to_display
248 and $page_number <= $max_to_display )
251 if ( defined $last_displayed_page
252 and $last_displayed_page != $page_number - 1 )
255 "\n" . ' <span class="inactive">...</span>';
258 if ( $page_number == $current_page ) {
261 . '<span class="currentPage">'
270 . $page_number . '">'
271 . $page_number . '</a>';
273 $last_displayed_page = $page_number;
278 if ( $current_page < $nb_pages ) {
279 my $next = $current_page + 1;
281 $pagination_bar .= "\n"
285 . '" rel="next">' . '>' . '</a>';
289 "\n" . ' <span class="inactive">></span>';
293 if ( $current_page != $nb_pages ) {
294 $pagination_bar .= "\n"
299 . '>>' . '</a>';
303 "\n" . ' <span class="inactive">>></span>';
307 return $pagination_bar;
310 END { } # module clean-up code here (global destructor)
319 Koha Developement team <info@koha.org>