fixing help feature with new template structure
[koha.git] / opac / opac-suggestions.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 USA
17
18 use strict;
19 require Exporter;
20 use CGI;
21 use C4::Auth;    # get_template_and_user
22 use C4::Output;
23 use C4::Suggestions;
24
25 my $input           = new CGI;
26 my $title           = $input->param('title');
27 my $author          = $input->param('author');
28 my $note            = $input->param('note');
29 my $copyrightdate   = $input->param('copyrightdate');
30 my $publishercode   = $input->param('publishercode');
31 my $volumedesc      = $input->param('volumedesc');
32 my $publicationyear = $input->param('publicationyear');
33 my $place           = $input->param('place');
34 my $isbn            = $input->param('isbn');
35 my $status          = $input->param('status');
36 my $suggestedbyme   = $input->param('suggestedbyme');
37 my $op              = $input->param('op');
38 $op = 'else' unless $op;
39
40 my ( $template, $borrowernumber, $cookie );
41
42 my $dbh = C4::Context->dbh;
43
44 if ( C4::Context->preference("AnonSuggestions") ) {
45     ( $template, $borrowernumber, $cookie ) = get_template_and_user(
46         {
47             template_name   => "opac-suggestions.tmpl",
48             query           => $input,
49             type            => "opac",
50             authnotrequired => 1,
51         }
52     );
53     if ( !$borrowernumber ) {
54         $borrowernumber = C4::Context->preference("AnonSuggestions");
55     }
56 }
57 else {
58     ( $template, $borrowernumber, $cookie ) = get_template_and_user(
59         {
60             template_name   => "opac-suggestions.tmpl",
61             query           => $input,
62             type            => "opac",
63             authnotrequired => 1,
64         }
65     );
66 }
67
68 if ( $op eq "add_confirm" ) {
69     &NewSuggestion(
70         $borrowernumber, $title,         $author,     $publishercode,
71         $note,           $copyrightdate, $volumedesc, $publicationyear,
72         $place,          $isbn,          ''
73     );
74
75     # empty fields, to avoid filter in "SearchSuggestion"
76     $title           = '';
77     $author          = '';
78     $publishercode   = '';
79     $copyrightdate   = '';
80     $volumedesc      = '';
81     $publicationyear = '';
82     $place           = '';
83     $isbn            = '';
84     $op              = 'else';
85 }
86
87 if ( $op eq "delete_confirm" ) {
88     my @delete_field = $input->param("delete_field");
89     foreach my $delete_field (@delete_field) {
90         &DelSuggestion( $borrowernumber, $delete_field );
91     }
92     $op = 'else';
93 }
94
95 my $suggestions_loop =
96   &SearchSuggestion( $borrowernumber, $author, $title, $publishercode, $status,
97     $suggestedbyme );
98 $template->param(
99     suggestions_loop => $suggestions_loop,
100     title            => $title,
101     author           => $author,
102     publishercode    => $publishercode,
103     status           => $status,
104     suggestedbyme    => $suggestedbyme,
105     "op_$op"         => 1,
106 );
107
108 output_html_with_http_headers $input, $cookie, $template->output;