Bug 6649 Allow help screens editing
[koha.git] / edithelp.pl
index d1975ba..4d7e0c0 100755 (executable)
@@ -41,7 +41,7 @@ my $error;
 
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {
-        template_name   => "help/edithelp.tmpl",
+        template_name   => "help/edithelp.tt",
         query           => $input,
         type            => "intranet",
         authnotrequired => 0,
@@ -63,29 +63,30 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
 
 sub _get_filepath ($;$) {
     my $referer = shift;
-    $referer =~ /.*koha\/(.+)\.pl.*/;
-    my $from   = "help/$1.tmpl";
+    $referer =~ /koha\/(.*)\.pl/;
+    my $from = "help/$1.tt";
     my $htdocs = C4::Context->config('intrahtdocs');
     my ($theme, $lang) = themelanguage( $htdocs, $from, "intranet", $input );
        $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' ) {
+$type = 'create' if $type eq 'addnew';
+if ( $type eq 'create' || $type eq 'save' ) {
        my $file = _get_filepath($referer);
-       unless (open (OUTFILE, ">$file")) {$error = "Cannot write file: '$file'";} else {
-        #open (OUTFILE, ">$file") or die "Cannot write file: '$file'"; # unlikely death, since we just checked
+    open my $fh, ">", $file;
+    if ( $fh ) {
         # file is open write to it
-        print OUTFILE "<!-- TMPL_INCLUDE NAME=\"help-top.inc\" -->\n";
-               print OUTFILE ($type eq 'create') ? "<div class=\"main\">\n$help\n</div>" : $help;
-        print OUTFILE "\n<!-- TMPL_INCLUDE NAME=\"help-bottom.inc\" -->\n";
-        close OUTFILE;
+        print $fh
+            " [% INCLUDE 'help-top.inc' %]\n",
+                   $type eq 'create' ? "<div class=\"main\">\n$help\n</div>" : $help,
+            "\n[% INCLUDE 'help-bottom.inc' %]\n";
+        close $fh;
                print $input->redirect("/cgi-bin/koha/help.pl?url=$oldreferer");
     }
-    
+    else {
+        $error = "Cannot write file: '$file'";
+    }
 }
 elsif ( $type eq 'modify' ) {
     # open file load data, kill include calls, pass data to the template
@@ -98,7 +99,7 @@ elsif ( $type eq 'modify' ) {
        open (INFILE, $file) or die "Cannot read file '$file'";         # unlikely death, since we just checked
                my $help = '';
                while ( my $inp = <INFILE> ) {
-                       unless ( $inp =~ /TMPL\_INCLUDE/ ) {
+                       unless ( $inp =~ /INCLUDE/ ) {
                                $help .= $inp;
                        }
                }