Usability change: Added example of 5.00 to fines/manual credit and fines/manual invoi...
[koha.git] / edithelp.pl
blob5d236c2fd286a8eb53534ce34f2d382b6a00a64a
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 my $error;
39 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
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,
57 debug => 1,
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) = themelanguage( $htdocs, $from, "intranet", $input );
67 $debug and print STDERR "help filepath: $htdocs/$theme/$lang/modules/$from";
68 return "$htdocs/$theme/$lang/modules/$from";
71 if ( $type eq 'addnew' ) {
72 $type = 'create';
74 elsif ( $type eq 'create' || $type eq 'save' ) {
75 my $file = _get_filepath($referer);
76 unless (open (OUTFILE, ">$file")) {$error = "Cannot write file: '$file'";} else {
77 #open (OUTFILE, ">$file") or die "Cannot write file: '$file'"; # unlikely death, since we just checked
78 # file is open write to it
79 print OUTFILE "<!-- TMPL_INCLUDE NAME=\"help-top.inc\" -->\n";
80 print OUTFILE ($type eq 'create') ? "<div class=\"main\">\n$help\n</div>" : $help;
81 print OUTFILE "\n<!-- TMPL_INCLUDE NAME=\"help-bottom.inc\" -->\n";
82 close OUTFILE;
83 print $input->redirect("/cgi-bin/koha/help.pl?url=$oldreferer");
87 elsif ( $type eq 'modify' ) {
88 # open file load data, kill include calls, pass data to the template
89 my $file = _get_filepath($referer, 1); # 2nd argument triggers themelanguage call
90 if (! -r $file) {
91 $error = "Cannot read file: '$file'.";
92 } else {
93 (-w $file) or $error =
94 "WARNING: You will not be able save, because your webserver cannot write to '$file'. Contact your admin about help file permissions.";
95 open (INFILE, $file) or die "Cannot read file '$file'"; # unlikely death, since we just checked
96 my $help = '';
97 while ( my $inp = <INFILE> ) {
98 unless ( $inp =~ /TMPL\_INCLUDE/ ) {
99 $help .= $inp;
102 close INFILE;
103 $template->param( 'help' => $help );
104 $type = 'save';
108 $template->param(
109 'referer' => $referer,
110 'type' => $type,
112 ($error) and $template->param('error' => $error);
113 output_html_with_http_headers $input, "", $template->output;