3 # This file is part of Koha.
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
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.
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 use C4::Auth; # get_template_and_user
33 my $allsuggestions = $input->param('showall');
34 my $op = $input->param('op');
35 my $suggestion = $input->Vars;
36 delete $$suggestion{$_} foreach qw<op suggestedbyme>;
37 $op = 'else' unless $op;
39 my ( $template, $borrowernumber, $cookie );
40 my $deleted = $input->param('deleted');
41 my $submitted = $input->param('submitted');
43 if ( C4::Context->preference("AnonSuggestions") ) {
44 ( $template, $borrowernumber, $cookie ) = get_template_and_user(
46 template_name => "opac-suggestions.tmpl",
49 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
52 if ( !$$suggestion{suggestedby} ) {
53 $$suggestion{suggestedby} = C4::Context->preference("AnonymousPatron");
57 ( $template, $borrowernumber, $cookie ) = get_template_and_user(
59 template_name => "opac-suggestions.tmpl",
67 delete $$suggestion{suggestedby};
70 $$suggestion{suggestedby} ||= $borrowernumber unless ($allsuggestions);
72 # warn "bornum:",$borrowernumber;
74 my $suggestions_loop =
75 &SearchSuggestion( $suggestion);
76 if ( $op eq "add_confirm" ) {
77 if (@$suggestions_loop>=1){
78 #some suggestion are answering the request Donot Add
81 my $scrubber = C4::Scrubber->new();
82 foreach my $suggest (keys %$suggestion){
83 $suggestion->{$suggest} = $scrubber->scrub($suggestion->{$suggest});
85 $$suggestion{'suggesteddate'}=C4::Dates->today;
86 $$suggestion{'branchcode'}= $input->param('branch') || C4::Context->userenv->{"branch"};
88 &NewSuggestion($suggestion);
89 # empty fields, to avoid filter in "SearchSuggestion"
90 $$suggestion{$_}='' foreach qw<title author publishercode copyrightdate place collectiontitle isbn STATUS>;
92 &SearchSuggestion( $suggestion );
95 print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else&submitted=1");
99 if ( $op eq "delete_confirm" ) {
100 my @delete_field = $input->param("delete_field");
101 foreach my $delete_field (@delete_field) {
102 &DelSuggestion( $borrowernumber, $delete_field );
105 print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else&deleted=1");
108 map{ $_->{'branchcodesuggestedby'}=GetBranchInfo($_->{'branchcodesuggestedby'})->[0]->{'branchname'}} @$suggestions_loop;
109 my $supportlist=GetSupportList();
110 foreach my $support(@$supportlist){
111 if ($$support{'imageurl'}){
112 $$support{'imageurl'}= getitemtypeimagelocation( 'opac', $$support{'imageurl'} );
115 delete $$support{'imageurl'}
119 foreach my $suggestion(@$suggestions_loop) {
120 if($suggestion->{'suggestedby'} == $borrowernumber) {
121 $suggestion->{'showcheckbox'} = $borrowernumber;
123 $suggestion->{'showcheckbox'} = 0;
125 if($suggestion->{'patronreason'}){
126 $suggestion->{'patronreason'} = GetKohaAuthorisedValueLib("OPAC_SUG",$suggestion->{'patronreason'},1);
130 my $patron_reason_loop = GetAuthorisedValues("OPAC_SUG");
132 # Is the person allowed to choose their branch
133 if ( C4::Context->preference("AllowPurchaseSuggestionBranchChoice") ) {
134 my ( $borr ) = GetMemberDetails( $borrowernumber );
136 # pass the pickup branch along....
138 if (C4::Context->userenv && C4::Context->userenv->{'branch'}) {
139 $userbranch = C4::Context->userenv->{'branch'};
141 my $branch = $input->param('branch') || $borr->{'branchcode'} || $userbranch || '' ;
143 # make branch selection options...
144 my $branchloop = GetBranchesLoop($branch);
145 $template->param( branchloop => $branchloop );
150 itemtypeloop=> $supportlist,
151 suggestions_loop => $suggestions_loop,
152 patron_reason_loop => $patron_reason_loop,
153 showall => $allsuggestions,
155 suggestionsview => 1,
158 output_html_with_http_headers $input, $cookie, $template->output;