3 # Copyright 2007 Liblime Ltd
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
28 $debug = $ENV{DEBUG} || 0;
33 my $type = $input->param('type');
34 my $referer = $input->param('referer');
35 my $oldreferer = $referer;
36 my $help = $input->param('help');
39 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
41 template_name => "help/edithelp.tmpl",
51 reserveforothers => 1,
61 sub _get_filepath ($;$) {
63 $referer =~ /.*koha\/(.+)\.pl.*/;
64 my $from = "help/$1.tmpl";
65 my $htdocs = C4::Context->config('intrahtdocs');
67 # This split behavior was part of the old script. I'm not sure why. -atz
69 ($theme, $lang) = themelanguage( $htdocs, $from, "intranet", $input );
71 $theme = C4::Context->preference('template');
72 $lang = C4::Context->preference('language') || 'en';
74 $debug and print STDERR "help filepath: $htdocs/$theme/$lang/modules/$from";
75 return "$htdocs/$theme/$lang/modules/$from";
78 if ( $type eq 'addnew' ) {
81 elsif ( $type eq 'create' || $type eq 'save' ) {
82 my $file = _get_filepath($referer);
84 $error = "Cannot write file: '$file'";
86 open (OUTFILE, ">$file") or die "Cannot write file: '$file'"; # unlikely death, since we just checked
87 # file is open write to it
88 print OUTFILE "<!-- TMPL_INCLUDE NAME=\"help-top.inc\" -->\n";
89 print OUTFILE ($type eq 'create') ? "<div class=\"main\">\n$help\n</div>" : $help;
90 print OUTFILE "\n<!-- TMPL_INCLUDE NAME=\"help-bottom.inc\" -->\n";
92 print $input->redirect("/cgi-bin/koha/help.pl?url=$oldreferer");
95 elsif ( $type eq 'modify' ) {
96 # open file load data, kill include calls, pass data to the template
97 my $file = _get_filepath($referer, 1); # 2nd argument triggers themelanguage call
99 $error = "Cannot read file: '$file'.";
101 (-w $file) or $error =
102 "WARNING: You will not be able save, because your webserver cannot write to '$file'. Contact your admin about help file permissions.";
103 open (INFILE, $file) or die "Cannot read file '$file'"; # unlikely death, since we just checked
105 while ( my $inp = <INFILE> ) {
106 unless ( $inp =~ /TMPL\_INCLUDE/ ) {
111 $template->param( 'help' => $help );
117 'referer' => $referer,
120 ($error) and $template->param('error' => $error);
121 output_html_with_http_headers $input, "", $template->output;