diff --git a/edithelp.pl b/edithelp.pl index 0ce65f9fca..d4cdd5c91d 100755 --- a/edithelp.pl +++ b/edithelp.pl @@ -22,7 +22,13 @@ use C4::Auth; use CGI; -my $input = new CGI; +use vars qw($debug); + +BEGIN { + $debug = $ENV{DEBUG} || 0; +} + +our $input = new CGI; my $type = $input->param('type'); my $referer = $input->param('referer'); @@ -52,77 +58,64 @@ } ); +sub _get_filepath ($;$) { + my $referer = shift; + $referer =~ /.*koha\/(.+)\.pl.*/; + my $from = "help/$1.tmpl"; + my $htdocs = C4::Context->config('intrahtdocs'); + my ($theme, $lang); + # This split behavior was part of the old script. I'm not sure why. -atz + if (@_) { + ($theme, $lang) = themelanguage( $htdocs, $from, "intranet", $input ); + } else { + $theme = C4::Context->preference('template'); + $lang = C4::Context->preference('language') || 'en'; + } + $debug and print STDERR "help filepath: $htdocs/$theme/$lang/modules/$from"; + return "$htdocs/$theme/$lang/modules/$from"; +} + if ( $type eq 'addnew' ) { $type = 'create'; } elsif ( $type eq 'create' || $type eq 'save' ) { - $referer =~ /.*koha\/(.*)\.pl.*/; - my $from = "help/$1.tmpl"; - my $htdocs = C4::Context->config('intrahtdocs'); -# my ( $theme, $lang ) = themelanguage( $htdocs, $from, "intranet" ); - my $theme = C4::Context->preference('template'); - my $lang = C4::Context->preference('language') || 'en'; - - # if (! -e "$htdocs/$theme/$lang/$from") { - # doesnt exist - eval { - open( OUTFILE, ">$htdocs/$theme/$lang/modules/$from" ) || die "Can't open file"; - }; - if ($@) { - $error = "Cant open file $htdocs/$theme/$lang/modules/$from"; - } - else { - + my $file = _get_filepath($referer); + if (! -w $file) { + $error = "Cannot write file: '$file'"; + } else { + open (OUTFILE, ">$file") or die "Cannot write file: '$file'"; # unlikely death, since we just checked # file is open write to it - print OUTFILE "\n"; - if ($type eq 'create'){ - print OUTFILE "