- $referer =~ /.*koha\/(.*)\.pl.*/;
- my $from = "help/$1.tmpl";
- my $htdocs = C4::Context->config('intrahtdocs');
- my ( $theme, $lang ) = themelanguage( $htdocs, $from, "intranet", $input );
- eval {
- open( INFILE, "$htdocs/$theme/$lang/modules/$from" ) || die "Can't open file";
- };
- if ($@) {
- $error = "Cant open file $htdocs/$theme/$lang/modules/$from";
- }
- my $help;
- while ( my $inp = <INFILE> ) {
- if ( $inp =~ /TMPL\_INCLUDE/ ) {
- }
- else {
- $help .= $inp;
- }
- }
- close INFILE;
- $template->param( 'help' => $help );
-
- $type = 'save';
+ my $file = _get_filepath($referer, 1); # 2nd argument triggers themelanguage call
+ if (! -r $file) {
+ $error = "Cannot read file: '$file'.";
+ } else {
+ (-w $file) or $error =
+ "WARNING: You will not be able to save, because your webserver cannot write to '$file'. Contact your admin about help file permissions.";
+ open (my $fh, '<', $file) or die "Cannot read file '$file'"; # unlikely death, since we just checked
+ my $help = '';
+ while ( <$fh> ) {
+ $help .= /\[% INCLUDE .* %\](.*)$/ ? $1 : $_;
+ }
+ close $fh;
+ $template->param( 'help' => $help );
+ $type = 'save';
+ }