prepare(?) & execute($var) modif
[koha.git] / C4 / Output.pm
index 0bd05ac..edda350 100644 (file)
@@ -32,6 +32,7 @@ require Exporter;
 
 use C4::Context;
 use C4::Database;
+use HTML::Template;
 
 use vars qw($VERSION @ISA @EXPORT);
 
@@ -78,38 +79,48 @@ my $path = C4::Context->config('includes') ||
 #---------------------------------------------------------------------------------------------------------
 # FIXME - POD
 sub gettemplate {
-    my ($tmplbase, $opac) = @_;
+       my ($tmplbase, $opac) = @_;
 
-    my $htdocs;
-    if ($opac ne "intranet") {
-       $htdocs = C4::Context->config('opachtdocs');
-    } else {
-       $htdocs = C4::Context->config('intrahtdocs');
-    }
+       my $htdocs;
+       if ($opac ne "intranet") {
+               $htdocs = C4::Context->config('opachtdocs');
+       } else {
+               $htdocs = C4::Context->config('intrahtdocs');
+       }
 
-    my ($theme, $lang) = themelanguage($htdocs, $tmplbase);
+       my ($theme, $lang) = themelanguage($htdocs, $tmplbase, $opac);
 
-    my $template = HTML::Template->new(filename      => "$htdocs/$theme/$lang/$tmplbase",
+       my $template = HTML::Template->new(filename      => "$htdocs/$theme/$lang/$tmplbase",
                                   die_on_bad_params => 0,
                                   global_vars       => 1,
                                   path              => ["$htdocs/$theme/$lang/includes"]);
 
-    $template->param(themelang => "/$theme/$lang",
-                                                       theme => $theme,
+       # XXX temporary patch for Bug 182 for themelang
+       $template->param(themelang => ($opac ne 'intranet'? '/opac-tmpl': '/intranet-tmpl') . "/$theme/$lang",
+                                                       interface => ($opac ne 'intranet'? '/opac-tmpl': '/intranet-tmpl'),
+                                                       theme => $theme,
                                                        lang => $lang);
-    return $template;
+       return $template;
 }
 
 #---------------------------------------------------------------------------------------------------------
 # FIXME - POD
 sub themelanguage {
-  my ($htdocs, $tmpl) = @_;
+  my ($htdocs, $tmpl, $section) = @_;
 
   my $dbh = C4::Context->dbh;
-  my @languages = split " ", C4::Context->preference("opaclanguages");
-                       # language preference
-  my @themes = split " ", C4::Context->preference("opacthemes");
-                       # theme preferences
+  my @languages;
+  my @themes;
+  if ( $section eq "intranet")
+  {
+    @languages = split " ", C4::Context->preference("opaclanguages");
+    @themes = split " ", C4::Context->preference("template");
+  }
+  else
+  {
+    @languages = split " ", C4::Context->preference("opaclanguages");
+    @themes = split " ", C4::Context->preference("opacthemes");
+  }
 
   my ($theme, $lang);
 # searches through the themes and languages. First template it find it returns.
@@ -117,7 +128,6 @@ sub themelanguage {
   THEME:
   foreach my $th (@themes) {
     foreach my $la (@languages) {
-#      warn "File = $htdocs/$th/$la/$tmpl\n";
        if (-e "$htdocs/$th/$la/$tmpl") {
            $theme = $th;
            $lang = $la;
@@ -341,19 +351,21 @@ sub startmenu($) {
   # edit the paths in here
   my ($type)=shift;
   if ($type eq 'issue') {
-    open (FILE,"$path/issues-top.inc") || die;
+    open (FILE,"$path/issues-top.inc") || die "could not find : $path/issues-top.inc";
   } elsif ($type eq 'opac') {
-    open (FILE,"$path/opac-top.inc") || die;
+    open (FILE,"$path/opac-top.inc") || die "could not find : $path/opac-top.inc";
   } elsif ($type eq 'member') {
-    open (FILE,"$path/members-top.inc") || die;
+    open (FILE,"$path/members-top.inc") || die "could not find : $path/members-top.inc";
   } elsif ($type eq 'acquisitions'){
-    open (FILE,"$path/acquisitions-top.inc") || die;
+    open (FILE,"$path/acquisitions-top.inc") || die "could not find : $path/acquisition-top.inc";
   } elsif ($type eq 'report'){
-    open (FILE,"$path/reports-top.inc") || die;
+    open (FILE,"$path/reports-top.inc") || die "could not find : $path/reports-top.inc";
   } elsif ($type eq 'circulation') {
-    open (FILE,"$path/circulation-top.inc") || die;
+    open (FILE,"$path/circulation-top.inc") || die "could not find : $path/circulation-top.inc";
+  } elsif ($type eq 'admin') {
+    open (FILE,"$path/parameters-top.inc") || die "could not find : $path/parameters-top.inc";
   } else {
-    open (FILE,"$path/cat-top.inc") || die;
+    open (FILE,"$path/cat-top.inc") || die "could not find : $path/cat-top.inc";
   }
   my @string=<FILE>;
   close FILE;
@@ -382,19 +394,21 @@ sub endmenu {
   # FIXME - It's bad form to die in a CGI script. It's even worse form
   # to die without issuing an error message.
   if ($type eq 'issue') {
-    open (FILE,"$path/issues-bottom.inc") || die;
+    open (FILE,"<$path/issues-bottom.inc") || die;
   } elsif ($type eq 'opac') {
-    open (FILE,"$path/opac-bottom.inc") || die;
+    open (FILE,"<$path/opac-bottom.inc") || die;
   } elsif ($type eq 'member') {
-    open (FILE,"$path/members-bottom.inc") || die;
+    open (FILE,"<$path/members-bottom.inc") || die;
   } elsif ($type eq 'acquisitions') {
-    open (FILE,"$path/acquisitions-bottom.inc") || die;
+    open (FILE,"<$path/acquisitions-bottom.inc") || die;
   } elsif ($type eq 'report') {
-    open (FILE,"$path/reports-bottom.inc") || die;
+    open (FILE,"<$path/reports-bottom.inc") || die;
   } elsif ($type eq 'circulation') {
-    open (FILE,"$path/circulation-bottom.inc") || die;
+    open (FILE,"<$path/circulation-bottom.inc") || die;
+  } elsif ($type eq 'admin') {
+    open (FILE,"<$path/parameters-bottom.inc") || die;
   } else {
-    open (FILE,"$path/cat-bottom.inc") || die;
+    open (FILE,"<$path/cat-bottom.inc") || die;
   }
   my @string=<FILE>;
   close FILE;