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