- my ($htdocs, $tmpl) = @_;
-
- my $dbh = C4::Context->dbh;
- my @languages = split " ", C4::Context->preference("opaclanguages");
- # language preference
- my @themes = split " ", C4::Context->preference("opacthemes");
- # theme preferences
-
- my ($theme, $lang);
-# searches through the themes and languages. First template it find it returns.
-# Priority is for getting the theme right.
- 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;
- last THEME;
- }
- }
- }
- if ($theme and $lang) {
- return ($theme, $lang);
- } else {
- return ('default', 'en');
- }
-}
-
-
-=item pathtotemplate
-
- %values = &pathtotemplate(template => $template,
- theme => $themename,
- language => $language,
- type => $ptype,
- path => $includedir);
-
-Finds a directory containing the desired template. The C<template>
-argument specifies the template you're looking for (this should be the
-name of the script you're using to generate an HTML page, without the
-C<.pl> extension). Only the C<template> argument is required; the
-others are optional.
-
-C<theme> specifies the name of the theme to use. This will be used
-only if it is allowed by the C<allowthemeoverride> system preference
-option (in the C<systempreferences> table of the Koha database).
-
-C<language> specifies the desired language. If not specified,
-C<&pathtotemplate> will use the list of acceptable languages specified
-by the browser, then C<all>, and finally C<en> as fallback options.
-
-C<type> may be C<intranet>, C<opac>, C<none>, or some other value.
-C<intranet> and C<opac> specify that you want a template for the
-internal web site or the public OPAC, respectively. C<none> specifies
-that the template you're looking for is at the top level of one of the
-include directories. Any other value is taken as-is, as a subdirectory
-of one of the include directories.
-
-C<path> specifies an include directory.
-
-C<&pathtotemplate> searches first in the directory given by the
-C<path> argument, if any, then in the directories given by the
-C<templatedirectory> and C<includes> directives in F</etc/koha.conf>,
-in that order.
-
-C<&pathtotemplate> returns a hash with the following keys:
-
-=over 4
-
-=item C<path>
-
-The full pathname to the desired template.
-
-=item C<foundlanguage>
-
-The value is set to 1 if a template in the desired language was found,
-or 0 otherwise.
-
-=item C<foundtheme>
-
-The value is set to 1 if a template of the desired theme was found, or
-0 otherwise.
-
-=back
-
-If C<&pathtotemplate> cannot find an acceptable template, it returns 0.
-
-Note that if a template of the desired language or theme cannot be
-found, C<&pathtotemplate> will print a warning message. Unless you've
-set C<$SIG{__WARN__}>, though, this won't show up in the output HTML
-document.
-
-=cut
-#'
-# FIXME - Fix POD: it doesn't look in the directory given by the
-# 'includes' option in /etc/koha.conf.
-sub pathtotemplate {
- my %params = @_;
- my $template = $params{'template'};
- my $themeor = $params{'theme'};
- my $languageor = lc($params{'language'});
- my $ptype = lc($params{'type'} or 'intranet');
-
- # FIXME - Make sure $params{'template'} was given. Or else assume
- # "default".
- my $type;
- if ($ptype eq 'opac') {$type = 'opac-tmpl/'; }
- elsif ($ptype eq 'none') {$type = ''; }
- elsif ($ptype eq 'intranet') {$type = 'intranet-tmpl/'; }
- else {$type = $ptype . '/'; }
-
- my %returns;
- my $theme = C4::Context->preference("theme") || "default";
- if ($themeor and
- C4::Context->preference("allowthemeoverride") =~ qr/$themeor/i)
- {
- $theme = $themeor;
- }
- my @languageorder = getlanguageorder();
- my $language = $languageor || shift(@languageorder);
-
- #where to search for templates
- my @tmpldirs = ("$path/templates", $path);
- unshift (@tmpldirs, C4::Context->config('templatedirectory')) if C4::Context->config('templatedirectory');
- unshift (@tmpldirs, $params{'path'}) if $params{'path'};
-
- my ($etheme, $elanguage, $epath);
-
- CHECK: foreach my $edir (@tmpldirs) {
- foreach $etheme ($theme, 'all', 'default') {
- foreach $elanguage ($language, @languageorder, 'all','en') {
- # 'en' is the fallback-language
- if (-e "$edir/$type$etheme/$elanguage/$template") {
- $epath = "$edir/$type$etheme/$elanguage/$template";
- last CHECK;
- }
- }
- }
- }
-
- unless ($epath) {
- warn "Could not find $template in @tmpldirs";
- return 0;
- }
-
- if ($language eq $elanguage) {
- $returns{'foundlanguage'} = 1;
- } else {
- $returns{'foundlanguage'} = 0;
- warn "The language $language could not be found for $template of $theme.\nServing $elanguage instead.\n";
- }
- if ($theme eq $etheme) {
- $returns{'foundtheme'} = 1;
- } else {
- $returns{'foundtheme'} = 0;
- warn "The template $template could not be found for theme $theme.\nServing $template of $etheme instead.\n";
- }
-
- $returns{'path'} = $epath;
-
- return (%returns);
-}
-
-=item getlanguageorder
-
- @languages = &getlanguageorder();
-
-Returns the list of languages that the user will accept, and returns
-them in order of decreasing preference. This is retrieved from the
-browser's headers, if possible; otherwise, C<&getlanguageorder> uses
-the C<languageorder> setting from the C<systempreferences> table in
-the Koha database. If neither is set, it defaults to C<en> (English).
-
-=cut
-#'
-sub getlanguageorder () {
- my @languageorder;
-
- if ($ENV{'HTTP_ACCEPT_LANGUAGE'}) {
- @languageorder = split (/\s*,\s*/ ,lc($ENV{'HTTP_ACCEPT_LANGUAGE'}));
- } elsif (my $order = C4::Context->preference("languageorder")) {
- @languageorder = split (/\s*,\s*/ ,lc($order));
- } else { # here should be another elsif checking for apache's languageorder
- @languageorder = ('en');
- }
-
- return (@languageorder);
-}
-
-=item startpage
-
- $str = &startpage();
- print $str;
-
-Returns a string of HTML, the beginning of a new HTML document.
-
-=cut
-#'
-sub startpage() {
- return("<html>\n");
-}
-
-=item gotopage
-
- $str = &gotopage("//opac.koha.org/index.html");
- print $str;
-
-Generates a snippet of HTML code that will redirect to the given URL
-(which should not include the initial C<http:>), and returns it.
-
-=cut
-#'
-sub gotopage($) {
- my ($target) = shift;
- #print "<br>goto target = $target<br>";
- my $string = "<META HTTP-EQUIV=Refresh CONTENT=\"0;URL=http:$target\">";
- return $string;
-}
-
-=item startmenu
-
- @lines = &startmenu($type);
- print join("", @lines);
-
-Given a page type, or category, returns a set of lines of HTML which,
-when concatenated, generate the menu at the top of the web page.
-
-C<$type> may be one of C<issue>, C<opac>, C<member>, C<acquisitions>,
-C<report>, C<circulation>, or something else, in which case the menu
-will be for the catalog pages.
-
-=cut
-#'
-sub startmenu($) {
- # edit the paths in here
- my ($type)=shift;
- if ($type eq 'issue') {
- open (FILE,"$path/issues-top.inc") || die;
- } elsif ($type eq 'opac') {
- open (FILE,"$path/opac-top.inc") || die;
- } elsif ($type eq 'member') {
- open (FILE,"$path/members-top.inc") || die;
- } elsif ($type eq 'acquisitions'){
- open (FILE,"$path/acquisitions-top.inc") || die;
- } elsif ($type eq 'report'){
- open (FILE,"$path/reports-top.inc") || die;
- } elsif ($type eq 'circulation') {
- open (FILE,"$path/circulation-top.inc") || die;
- } else {
- open (FILE,"$path/cat-top.inc") || die;
- }
- my @string=<FILE>;
- close FILE;
- # my $count=@string;
- # $string[$count]="<BLOCKQUOTE>";
- return @string;
-}
-
-=item endmenu
-
- @lines = &endmenu($type);
- print join("", @lines);
-
-Given a page type, or category, returns a set of lines of HTML which,
-when concatenated, generate the menu at the bottom of the web page.
-
-C<$type> may be one of C<issue>, C<opac>, C<member>, C<acquisitions>,
-C<report>, C<circulation>, or something else, in which case the menu
-will be for the catalog pages.
-
-=cut
-#'
-sub endmenu {
- my ($type) = @_;
- if ( ! defined $type ) { $type=''; }
- # 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;
- } elsif ($type eq 'opac') {
- open (FILE,"$path/opac-bottom.inc") || die;
- } elsif ($type eq 'member') {
- open (FILE,"$path/members-bottom.inc") || die;
- } elsif ($type eq 'acquisitions') {
- open (FILE,"$path/acquisitions-bottom.inc") || die;
- } elsif ($type eq 'report') {
- open (FILE,"$path/reports-bottom.inc") || die;
- } elsif ($type eq 'circulation') {
- open (FILE,"$path/circulation-bottom.inc") || die;
- } else {
- open (FILE,"$path/cat-bottom.inc") || die;
- }
- my @string=<FILE>;
- close FILE;
- return @string;
-}
-
-=item mktablehdr
-
- $str = &mktablehdr();
- print $str;
-
-Returns a string of HTML, which generates the beginning of a table
-declaration.
-
-=cut
-#'
-sub mktablehdr() {
- return("<table border=0 cellspacing=0 cellpadding=5>\n");
-}
-
-=item mktablerow
-
- $str = &mktablerow($columns, $color, @column_data, $bgimage);
- print $str;
-
-Returns a string of HTML, which generates a row of data inside a table
-(see also C<&mktablehdr>, C<&mktableft>).
-
-C<$columns> specifies the number of columns in this row of data.
-
-C<$color> specifies the background color for the row, e.g., C<"white">
-or C<"#ffacac">.
-
-C<@column_data> is an array of C<$columns> elements, each one a string
-of HTML. These are the contents of the row.
-
-The optional C<$bgimage> argument specifies the pathname to an image
-to use as the background for each cell in the row. This pathname will
-used as is in the output, so it should be relative to the HTTP
-document root.
-
-=cut
-#'
-sub mktablerow {
- #the last item in data may be a backgroundimage
-
- # FIXME
- # should this be a foreach (1..$cols) loop?
-
- my ($cols,$colour,@data)=@_;
- my $i=0;
- my $string="<tr valign=top bgcolor=$colour>";
- while ($i <$cols){
- if (defined $data[$cols]) { # if there is a background image
- $string.="<td background=\"$data[$cols]\">";
- } else { # if there's no background image
- $string.="<td>";
- }
- if (! defined $data[$i]) {$data[$i]="";}
- if ($data[$i] eq "") {
- $string.=" </td>";
- } else {
- $string.="$data[$i]</td>";
- }
- $i++;
- }
- $string .= "</tr>\n";
- return($string);
-}
-
-=item mktableft
-
- $str = &mktableft();
- print $str;
-
-Returns a string of HTML, which generates the end of a table
-declaration.
-
-=cut
-#'
-sub mktableft() {
- return("</table>\n");
-}
-
-# FIXME - This is never used.
-sub mkform{
- my ($action,%inputs)=@_;
- my $string="<form action=$action method=post>\n";
- $string .= mktablehdr();
- my $key;
- my @keys=sort keys %inputs;
-
- my $count=@keys;
- my $i2=0;
- while ( $i2<$count) {
- my $value=$inputs{$keys[$i2]};
- my @data=split('\t',$value);
- #my $posn = shift(@data);
- if ($data[0] eq 'hidden'){
- $string .= "<input type=hidden name=$keys[$i2] value=\"$data[1]\">\n";