Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 121 lines (109 sloc) 3.896 kb
b8250af Editing help system.
Chris Cormack authored
1 #!/usr/bin/perl
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');
37 my $error;
38
39 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
40 {
41 template_name => "help/edithelp.tmpl",
42 query => $input,
43 type => "intranet",
44 authnotrequired => 0,
45 flagsrequired => {
46 catalogue => 1,
47 circulate => 1,
48 parameters => 1,
49 borrowers => 1,
50 permissions => 1,
51 reserveforothers => 1,
52 borrow => 1,
53 reserveforself => 1,
54 editcatalogue => 1,
55 updatecharges => 1,
56 },
57 debug => 1,
58 }
59 );
60
536b855 edithelp.pl - cleanup, refactor and error feedback to user
Joe Atzberger authored
61 sub _get_filepath ($;$) {
62 my $referer = shift;
63 $referer =~ /.*koha\/(.+)\.pl.*/;
64 my $from = "help/$1.tmpl";
65 my $htdocs = C4::Context->config('intrahtdocs');
66 my ($theme, $lang);
67 # This split behavior was part of the old script. I'm not sure why. -atz
68 if (@_) {
69 ($theme, $lang) = themelanguage( $htdocs, $from, "intranet", $input );
70 } else {
71 $theme = C4::Context->preference('template');
72 $lang = C4::Context->preference('language') || 'en';
73 }
74 $debug and print STDERR "help filepath: $htdocs/$theme/$lang/modules/$from";
75 return "$htdocs/$theme/$lang/modules/$from";
76 }
77
b8250af Editing help system.
Chris Cormack authored
78 if ( $type eq 'addnew' ) {
79 $type = 'create';
80 }
81 elsif ( $type eq 'create' || $type eq 'save' ) {
536b855 edithelp.pl - cleanup, refactor and error feedback to user
Joe Atzberger authored
82 my $file = _get_filepath($referer);
7319cdf Try to edit help, don't test, for some reason -w wasn't working
Joshua Ferraro authored
83 unless (open (OUTFILE, ">$file")) {$error = "Cannot write file: '$file'";} else {
84 #open (OUTFILE, ">$file") or die "Cannot write file: '$file'"; # unlikely death, since we just checked
b8250af Editing help system.
Chris Cormack authored
85 # file is open write to it
536b855 edithelp.pl - cleanup, refactor and error feedback to user
Joe Atzberger authored
86 print OUTFILE "<!-- TMPL_INCLUDE NAME=\"help-top.inc\" -->\n";
87 print OUTFILE ($type eq 'create') ? "<div class=\"main\">\n$help\n</div>" : $help;
88 print OUTFILE "\n<!-- TMPL_INCLUDE NAME=\"help-bottom.inc\" -->\n";
b8250af Editing help system.
Chris Cormack authored
89 close OUTFILE;
90 print $input->redirect("/cgi-bin/koha/help.pl?url=$oldreferer");
91 }
7319cdf Try to edit help, don't test, for some reason -w wasn't working
Joshua Ferraro authored
92
b8250af Editing help system.
Chris Cormack authored
93 }
94 elsif ( $type eq 'modify' ) {
95 # 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
96 my $file = _get_filepath($referer, 1); # 2nd argument triggers themelanguage call
97 if (! -r $file) {
98 $error = "Cannot read file: '$file'.";
99 } else {
100 (-w $file) or $error =
101 "WARNING: You will not be able save, because your webserver cannot write to '$file'. Contact your admin about help file permissions.";
102 open (INFILE, $file) or die "Cannot read file '$file'"; # unlikely death, since we just checked
103 my $help = '';
104 while ( my $inp = <INFILE> ) {
105 unless ( $inp =~ /TMPL\_INCLUDE/ ) {
106 $help .= $inp;
107 }
108 }
109 close INFILE;
110 $template->param( 'help' => $help );
111 $type = 'save';
112 }
b8250af Editing help system.
Chris Cormack authored
113 }
114
115 $template->param(
116 'referer' => $referer,
117 'type' => $type,
118 );
536b855 edithelp.pl - cleanup, refactor and error feedback to user
Joe Atzberger authored
119 ($error) and $template->param('error' => $error);
b8250af Editing help system.
Chris Cormack authored
120 output_html_with_http_headers $input, "", $template->output;
Something went wrong with that request. Please try again.