patches for members and resultlists.
[koha.git] / edithelp.pl
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
25 my $input = new CGI;
26
27 my $type    = $input->param('type');
28 my $referer = $input->param('referer');
29 my $oldreferer = $referer;
30 my $help    = $input->param('help');
31 my $error;
32
33 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
34     {
35         template_name   => "help/edithelp.tmpl",
36         query           => $input,
37         type            => "intranet",
38         authnotrequired => 0,
39         flagsrequired   => {
40             catalogue        => 1,
41             circulate        => 1,
42             parameters       => 1,
43             borrowers        => 1,
44             permissions      => 1,
45             reserveforothers => 1,
46             borrow           => 1,
47             reserveforself   => 1,
48             editcatalogue    => 1,
49             updatecharges    => 1,
50         },
51         debug => 1,
52     }
53 );
54
55 if ( $type eq 'addnew' ) {
56     $type = 'create';
57 }
58 elsif ( $type eq 'create' || $type eq 'save' ) {
59     $referer =~ /.*koha\/(.*)\.pl.*/;
60     my $from   = "help/$1.tmpl";
61     my $htdocs = C4::Context->config('intrahtdocs');
62 #    my ( $theme, $lang ) = themelanguage( $htdocs, $from, "intranet" );
63         my $theme = C4::Context->preference('template');
64         my $lang  = C4::Context->preference('language') || 'en';
65
66     #    if (! -e "$htdocs/$theme/$lang/$from") {
67     # doesnt exist
68     eval {
69         open( OUTFILE, ">$htdocs/$theme/$lang/modules/$from" ) || die "Can't open file";
70     };
71     if ($@) {
72         $error = "Cant open file $htdocs/$theme/$lang/modules/$from";
73     }
74     else {
75
76         # file is open write to it
77         print OUTFILE "<!-- TMPL_INCLUDE name=\"help-top.inc\" -->\n";
78                 if ($type eq 'create'){
79                         print OUTFILE "<div class=\"main\">\n";
80                 }
81         print OUTFILE "$help\n";
82             if ($type eq 'create'){
83                         print OUTFILE "</div>\n";
84                 }
85         print OUTFILE "<!-- TMPL_INCLUDE name=\"help-bottom.inc\" -->\n";
86         close OUTFILE;
87                 print $input->redirect("/cgi-bin/koha/help.pl?url=$oldreferer");
88     }
89
90
91     #   }
92
93 }
94 elsif ( $type eq 'modify' ) {
95
96     # open file load data, kill include calls, pass data to the template
97     $referer =~ /.*koha\/(.*)\.pl.*/;
98     my $from   = "help/$1.tmpl";
99     my $htdocs = C4::Context->config('intrahtdocs');
100     my ( $theme, $lang ) = themelanguage( $htdocs, $from, "intranet" );
101     eval {
102         open( INFILE, "$htdocs/$theme/$lang/modules/$from" ) || die "Can't open file";
103     };
104     if ($@) {
105         $error = "Cant open file $htdocs/$theme/$lang/modules/$from";
106     }
107     my $help;
108     while ( my $inp = <INFILE> ) {
109         if ( $inp =~ /TMPL\_INCLUDE/ ) {
110         }
111         else {
112             $help .= $inp;
113         }
114     }
115     close INFILE;
116     $template->param( 'help' => $help );
117
118     $type = 'save';
119 }
120
121 $template->param(
122     'referer' => $referer,
123     'type'    => $type,
124     'error'   => $error,
125
126 );
127
128 output_html_with_http_headers $input, "", $template->output;