[biblibre-newacq](bug #3611) really disable buttons
[koha.git] / edithelp.pl
blob362f678e86045c61b70bd813f17444a07c361152
1 #!/usr/bin/perl
3 # Copyright 2007 Liblime Ltd
5 # This file is part of Koha.
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.
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.
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
20 use strict;
21 use C4::Output;
22 use C4::Auth;
23 use CGI;
25 use vars qw($debug);
27 BEGIN {
28 $debug = $ENV{DEBUG} || 0;
31 our $input = new CGI;
33 my $type = $input->param('type');
34 my $referer = $input->param('referer');
35 my $oldreferer = $referer;
36 my $help = $input->param('help');
37 # strip any DOS-newlines that TinyMCE may have sneaked in
38 $help =~ s/\r//g;
39 my $error;
41 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
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,
59 debug => 1,
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');
68 my ($theme, $lang) = themelanguage( $htdocs, $from, "intranet", $input );
69 $debug and print STDERR "help filepath: $htdocs/$theme/$lang/modules/$from";
70 return "$htdocs/$theme/$lang/modules/$from";
73 if ( $type eq 'addnew' ) {
74 $type = 'create';
76 elsif ( $type eq 'create' || $type eq 'save' ) {
77 my $file = _get_filepath($referer);
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
80 # file is open write to it
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";
84 close OUTFILE;
85 print $input->redirect("/cgi-bin/koha/help.pl?url=$oldreferer");
89 elsif ( $type eq 'modify' ) {
90 # open file load data, kill include calls, pass data to the template
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;
104 close INFILE;
105 $template->param( 'help' => $help );
106 $type = 'save';
110 $template->param(
111 'referer' => $referer,
112 'type' => $type,
114 ($error) and $template->param('error' => $error);
115 output_html_with_http_headers $input, "", $template->output;