Adding ESCAPE=JS to TMPL_Tokenizer
[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 use warnings;
20
21 use CGI;
22 use C4::Auth;    # get_template_and_user
23 use C4::Branch;
24 use C4::Koha;
25 use C4::Output;
26 use C4::Suggestions;
27
28 my $input           = new CGI;
29 my $suggestedbyme   = (defined $input->param('suggestedby')? $input->param('suggestedby'):1);
30 my $op              = $input->param('op');
31 my $suggestion      = $input->Vars;
32 delete $$suggestion{$_} foreach qw<op suggestedbyme>;
33 $op = 'else' unless $op;
34
35 my ( $template, $borrowernumber, $cookie );
36
37 my $dbh = C4::Context->dbh;
38
39 if ( C4::Context->preference("AnonSuggestions") ) {
40     ( $template, $borrowernumber, $cookie ) = get_template_and_user(
41         {
42             template_name   => "opac-suggestions.tmpl",
43             query           => $input,
44             type            => "opac",
45             authnotrequired => 1,
46         }
47     );
48     if ( !$$suggestion{suggestedby} ) {
49         $$suggestion{suggestedby} = C4::Context->preference("AnonSuggestions");
50     }
51 }
52 else {
53     ( $template, $borrowernumber, $cookie ) = get_template_and_user(
54         {
55             template_name   => "opac-suggestions.tmpl",
56             query           => $input,
57             type            => "opac",
58             authnotrequired => 0,
59         }
60     );
61 }
62 $$suggestion{suggestedby} ||= $borrowernumber;
63
64 my $suggestions_loop =
65   &SearchSuggestion( $suggestion,
66     $suggestedbyme );
67 if ( $op eq "add_confirm" ) {
68         if (@$suggestions_loop>=1){
69                 #some suggestion are answering the request Donot Add    
70         } 
71         else {
72                 $$suggestion{'suggestioncreatedon'}=C4::Dates->today;
73                 $$suggestion{'branchcode'}=C4::Context->userenv->{"branch"};
74                 &NewSuggestion($suggestion);
75                 # empty fields, to avoid filter in "SearchSuggestion"
76                 $$suggestion{$_}='' foreach qw<title author publishercode copyrightdate place collectiontitle isbn STATUS>;
77                 $suggestions_loop =
78                    &SearchSuggestion( $suggestion,
79                          $suggestedbyme );
80         }
81         $op              = 'else';
82 }
83
84 if ( $op eq "delete_confirm" ) {
85     my @delete_field = $input->param("delete_field");
86     foreach my $delete_field (@delete_field) {
87         &DelSuggestion( $borrowernumber, $delete_field );
88     }
89     $op = 'else';
90 }
91
92 map{ $_->{'branchcodesuggestedby'}=GetBranchInfo($_->{'branchcodesuggestedby'})->[0]->{'branchname'}} @$suggestions_loop;  
93 my $supportlist=GetSupportList();                               
94 foreach my $support(@$supportlist){
95         if ($$support{'imageurl'}){
96                 $$support{'imageurl'}= getitemtypeimagelocation( 'intranet', $$support{'imageurl'} );
97         }
98         else {
99            delete $$support{'imageurl'}
100         }
101 }
102 $template->param(
103         %$suggestion,
104         itemtypeloop=> $supportlist,
105     suggestions_loop => $suggestions_loop,
106     suggestedbyme    => $suggestedbyme,
107     "op_$op"         => 1,
108         suggestionsview => 1
109 );
110 output_html_with_http_headers $input, $cookie, $template->output;