serials : lot of bugfixes.
[koha.git] / C4 / Output.pm
1 package C4::Output;
2
3 # $Id$
4
5 #package to deal with marking up output
6 #You will need to edit parts of this pm
7 #set the value of path to be where your html lives
8
9
10 # Copyright 2000-2002 Katipo Communications
11 #
12 # This file is part of Koha.
13 #
14 # Koha is free software; you can redistribute it and/or modify it under the
15 # terms of the GNU General Public License as published by the Free Software
16 # Foundation; either version 2 of the License, or (at your option) any later
17 # version.
18 #
19 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
20 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
21 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License along with
24 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
25 # Suite 330, Boston, MA  02111-1307 USA
26
27 # NOTE: I'm pretty sure this module is deprecated in favor of
28 # templates.
29
30 use strict;
31 require Exporter;
32
33 use C4::Context;
34 use C4::Database;
35 use HTML::Template;
36
37 use vars qw($VERSION @ISA @EXPORT);
38
39 # set the version for version checking
40 $VERSION = 0.01;
41
42 =head1 NAME
43
44 C4::Output - Functions for managing templates
45
46 =head1 FUNCTIONS
47
48 =over 2
49
50 =cut
51
52 @ISA = qw(Exporter);
53 @EXPORT = qw(
54                 &themelanguage &gettemplate setlanguagecookie
55                 );
56
57 #FIXME: this is a quick fix to stop rc1 installing broken
58 #Still trying to figure out the correct fix.
59 my $path = C4::Context->config('intrahtdocs')."/default/en/includes/";
60
61 #---------------------------------------------------------------------------------------------------------
62 # FIXME - POD
63 sub gettemplate {
64         my ($tmplbase, $opac, $query) = @_;
65 if (!$query){
66   warn "no query in gettemplate";
67   }
68         my $htdocs;
69         if ($opac ne "intranet") {
70                 $htdocs = C4::Context->config('opachtdocs');
71         } else {
72                 $htdocs = C4::Context->config('intrahtdocs');
73         }
74
75         my ($theme, $lang) = themelanguage($htdocs, $tmplbase, $opac, $query);
76
77         my $template = HTML::Template->new(filename      => "$htdocs/$theme/$lang/$tmplbase",
78                                    die_on_bad_params => 0,
79                                    global_vars       => 1,
80                                    path              => ["$htdocs/$theme/$lang/includes"]);
81
82         $template->param(themelang => ($opac ne 'intranet'? '/opac-tmpl': '/intranet-tmpl') . "/$theme/$lang",
83                                                         interface => ($opac ne 'intranet'? '/opac-tmpl': '/intranet-tmpl'),
84                                                         theme => $theme,
85                                                         lang => $lang);
86
87         
88         return $template;
89 }
90
91 #---------------------------------------------------------------------------------------------------------
92 # FIXME - POD
93 sub themelanguage {
94   my ($htdocs, $tmpl, $section, $query) = @_;
95 #   if (!$query) {
96 #     warn "no query";
97 #   }
98   my $dbh = C4::Context->dbh;
99   my @languages;
100   my @themes;
101   if ( $section eq "intranet")
102   {
103     @languages = split " ", C4::Context->preference("opaclanguages");
104     @themes = split " ", C4::Context->preference("template");
105   }
106   else
107   {
108   # we are in the opac here, what im trying to do is let the individual user
109   # set the theme they want to use.
110   # and perhaps the them as well.
111   my $lang=$query->cookie('KohaOpacLanguage');
112   if ($lang){
113   
114     push @languages,$lang;
115     @themes = split " ", C4::Context->preference("opacthemes");
116   } 
117   else {
118     @languages = split " ", C4::Context->preference("opaclanguages");
119     @themes = split " ", C4::Context->preference("opacthemes");
120     }
121   }
122
123   my ($theme, $lang);
124 # searches through the themes and languages. First template it find it returns.
125 # Priority is for getting the theme right.
126   THEME:
127   foreach my $th (@themes) {
128     foreach my $la (@languages) {
129         for (my $pass = 1; $pass <= 2; $pass += 1) {
130           $la =~ s/([-_])/ $1 eq '-'? '_': '-' /eg if $pass == 2;
131           if (-e "$htdocs/$th/$la/$tmpl") {
132               $theme = $th;
133               $lang = $la;
134               last THEME;
135           }
136         last unless $la =~ /[-_]/;
137         }
138     }
139   }
140   if ($theme and $lang) {
141     return ($theme, $lang);
142   } else {
143     return ('default', 'en');
144   }
145 }
146
147 sub setlanguagecookie {
148    my ($query,$language,$uri)=@_;
149    my $cookie=$query->cookie(-name => 'KohaOpacLanguage',
150                                            -value => $language,
151                                            -expires => '');
152    print $query->redirect(-uri=>$uri,
153    -cookie=>$cookie);
154 }                                  
155
156
157 END { }       # module clean-up code here (global destructor)
158
159 1;
160 __END__
161
162 =back
163
164 =head1 AUTHOR
165
166 Koha Developement team <info@koha.org>
167
168 =cut