Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 116 lines (104 sloc) 3.753 kb
a0b06fb @ctfliblime Prepare for perlbrew usage by changing all script magic to "#!/usr/bin/e...
ctfliblime authored
1 #!/usr/bin/env perl
b8250af Editing help system.
Chris Cormack authored
2
3 # Copyright 2007 Liblime Ltd
4 #
5 # This file is part of Koha.
6 #
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
10 # version.
11 #
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.
15 #
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
19
20 use strict;
21 use C4::Output;
22 use C4::Auth;
23 use CGI;
24
536b855 edithelp.pl - cleanup, refactor and error feedback to user
Joe Atzberger authored
25 use vars qw($debug);
26
27 BEGIN {
28 $debug = $ENV{DEBUG} || 0;
29 }
30
31 our $input = new CGI;
b8250af Editing help system.
Chris Cormack authored
32
33 my $type = $input->param('type');
34 my $referer = $input->param('referer');
35 my $oldreferer = $referer;
36 my $help = $input->param('help');
b5ab0da bug 3272: preserve formatting when editing help
Galen Charlton authored
37 # strip any DOS-newlines that TinyMCE may have sneaked in
38 $help =~ s/\r//g;
b8250af Editing help system.
Chris Cormack authored
39 my $error;
40
41 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
42 {
43 template_name => "help/edithelp.tmpl",
44 query => $input,
45 type => "intranet",
46 authnotrequired => 0,
47 flagsrequired => {
48 catalogue => 1,
49 circulate => 1,
50 parameters => 1,
51 borrowers => 1,
52 permissions => 1,
53 reserveforothers => 1,
54 borrow => 1,
55 reserveforself => 1,
56 editcatalogue => 1,
57 updatecharges => 1,
58 },
59 debug => 1,
60 }
61 );
62
536b855 edithelp.pl - cleanup, refactor and error feedback to user
Joe Atzberger authored
63 sub _get_filepath ($;$) {
64 my $referer = shift;
65 $referer =~ /.*koha\/(.+)\.pl.*/;
66 my $from = "help/$1.tmpl";
67 my $htdocs = C4::Context->config('intrahtdocs');
1465844 @fredericd Patches bug #2308
fredericd authored
68 my ($theme, $lang) = themelanguage( $htdocs, $from, "intranet", $input );
536b855 edithelp.pl - cleanup, refactor and error feedback to user
Joe Atzberger authored
69 $debug and print STDERR "help filepath: $htdocs/$theme/$lang/modules/$from";
70 return "$htdocs/$theme/$lang/modules/$from";
71 }
72
b8250af Editing help system.
Chris Cormack authored
73 if ( $type eq 'addnew' ) {
74 $type = 'create';
75 }
76 elsif ( $type eq 'create' || $type eq 'save' ) {
536b855 edithelp.pl - cleanup, refactor and error feedback to user
Joe Atzberger authored
77 my $file = _get_filepath($referer);
7319cdf Try to edit help, don't test, for some reason -w wasn't working
Joshua Ferraro authored
78 unless (open (OUTFILE, ">$file")) {$error = "Cannot write file: '$file'";} else {
79 #open (OUTFILE, ">$file") or die "Cannot write file: '$file'"; # unlikely death, since we just checked
b8250af Editing help system.
Chris Cormack authored
80 # file is open write to it
536b855 edithelp.pl - cleanup, refactor and error feedback to user
Joe Atzberger authored
81 print OUTFILE "<!-- TMPL_INCLUDE NAME=\"help-top.inc\" -->\n";
82 print OUTFILE ($type eq 'create') ? "<div class=\"main\">\n$help\n</div>" : $help;
83 print OUTFILE "\n<!-- TMPL_INCLUDE NAME=\"help-bottom.inc\" -->\n";
b8250af Editing help system.
Chris Cormack authored
84 close OUTFILE;
85 print $input->redirect("/cgi-bin/koha/help.pl?url=$oldreferer");
86 }
7319cdf Try to edit help, don't test, for some reason -w wasn't working
Joshua Ferraro authored
87
b8250af Editing help system.
Chris Cormack authored
88 }
89 elsif ( $type eq 'modify' ) {
90 # open file load data, kill include calls, pass data to the template
536b855 edithelp.pl - cleanup, refactor and error feedback to user
Joe Atzberger authored
91 my $file = _get_filepath($referer, 1); # 2nd argument triggers themelanguage call
92 if (! -r $file) {
93 $error = "Cannot read file: '$file'.";
94 } else {
95 (-w $file) or $error =
96 "WARNING: You will not be able save, because your webserver cannot write to '$file'. Contact your admin about help file permissions.";
97 open (INFILE, $file) or die "Cannot read file '$file'"; # unlikely death, since we just checked
98 my $help = '';
99 while ( my $inp = <INFILE> ) {
100 unless ( $inp =~ /TMPL\_INCLUDE/ ) {
101 $help .= $inp;
102 }
103 }
104 close INFILE;
105 $template->param( 'help' => $help );
106 $type = 'save';
107 }
b8250af Editing help system.
Chris Cormack authored
108 }
109
110 $template->param(
111 'referer' => $referer,
112 'type' => $type,
113 );
536b855 edithelp.pl - cleanup, refactor and error feedback to user
Joe Atzberger authored
114 ($error) and $template->param('error' => $error);
b8250af Editing help system.
Chris Cormack authored
115 output_html_with_http_headers $input, "", $template->output;
Something went wrong with that request. Please try again.