Lines 38-44
use Koha::DateUtils qw( dt_from_string );
Link Here
|
38 |
my $input = new CGI; |
38 |
my $input = new CGI; |
39 |
my $op = $input->param('op'); |
39 |
my $op = $input->param('op'); |
40 |
my $biblionumber = $input->param('biblionumber'); |
40 |
my $biblionumber = $input->param('biblionumber'); |
41 |
my $suggestion = $input->Vars; |
|
|
42 |
my $negcaptcha = $input->param('negcap'); |
41 |
my $negcaptcha = $input->param('negcap'); |
43 |
my $suggested_by_anyone = $input->param('suggested_by_anyone') || 0; |
42 |
my $suggested_by_anyone = $input->param('suggested_by_anyone') || 0; |
44 |
my $need_confirm = 0; |
43 |
my $need_confirm = 0; |
Lines 47-56
my $need_confirm = 0;
Link Here
|
47 |
if ($negcaptcha ) { |
46 |
if ($negcaptcha ) { |
48 |
print $input->redirect("/cgi-bin/koha/opac-suggestions.pl"); |
47 |
print $input->redirect("/cgi-bin/koha/opac-suggestions.pl"); |
49 |
exit; |
48 |
exit; |
50 |
} else { |
|
|
51 |
# don't pass 'negcap' column to DB, else DBI::Class will error |
52 |
# DBIx::Class::Row::store_column(): No such column 'negcap' on Koha::Schema::Result::Suggestion at Koha/C4/Suggestions.pm |
53 |
delete $suggestion->{negcap}; |
54 |
} |
49 |
} |
55 |
|
50 |
|
56 |
#If suggestions are turned off we redirect to 404 error. This will also redirect guest suggestions |
51 |
#If suggestions are turned off we redirect to 404 error. This will also redirect guest suggestions |
Lines 59-65
if ( ! C4::Context->preference('suggestion') ) {
Link Here
|
59 |
exit; |
54 |
exit; |
60 |
} |
55 |
} |
61 |
|
56 |
|
62 |
delete $suggestion->{$_} foreach qw<op suggested_by_anyone confirm>; |
|
|
63 |
$op = 'else' unless $op; |
57 |
$op = 'else' unless $op; |
64 |
|
58 |
|
65 |
my ( $template, $borrowernumber, $cookie, @messages ); |
59 |
my ( $template, $borrowernumber, $cookie, @messages ); |
Lines 87-122
else {
Link Here
|
87 |
); |
81 |
); |
88 |
} |
82 |
} |
89 |
|
83 |
|
|
|
84 |
my $suggested_by; |
90 |
if ( $op eq 'else' ) { |
85 |
if ( $op eq 'else' ) { |
91 |
if ( C4::Context->preference("OPACViewOthersSuggestions") ) { |
86 |
if ( C4::Context->preference("OPACViewOthersSuggestions") ) { |
92 |
if ( $borrowernumber ) { |
87 |
if ( $borrowernumber ) { |
93 |
# A logged in user is able to see suggestions from others |
88 |
# A logged in user is able to see suggestions from others |
94 |
$suggestion->{suggestedby} = $suggested_by_anyone |
89 |
$suggested_by = $suggested_by_anyone |
95 |
? undef |
90 |
? undef |
96 |
: $borrowernumber; |
91 |
: $borrowernumber; |
97 |
} |
92 |
} |
98 |
else { |
93 |
# else: Non logged in user is able to see all suggestions |
99 |
# Non logged in user is able to see all suggestions |
|
|
100 |
$suggestion->{suggestedby} = undef; |
101 |
} |
102 |
} |
94 |
} |
103 |
else { |
95 |
else { |
104 |
if ( $borrowernumber ) { |
96 |
if ( $borrowernumber ) { |
105 |
$suggestion->{suggestedby} = $borrowernumber; |
97 |
$suggested_by = $borrowernumber; |
106 |
} |
98 |
} |
107 |
else { |
99 |
else { |
108 |
$suggestion->{suggestedby} = -1; |
100 |
$suggested_by = -1; |
109 |
} |
101 |
} |
110 |
} |
102 |
} |
111 |
} else { |
103 |
} else { |
112 |
if ( $borrowernumber ) { |
104 |
if ( $borrowernumber ) { |
113 |
$suggestion->{suggestedby} = $borrowernumber; |
105 |
$suggested_by = $borrowernumber; |
114 |
} |
106 |
} |
115 |
else { |
107 |
else { |
116 |
$suggestion->{suggestedby} = C4::Context->preference("AnonymousPatron"); |
108 |
$suggested_by = C4::Context->preference("AnonymousPatron"); |
117 |
} |
109 |
} |
118 |
} |
110 |
} |
119 |
|
111 |
|
|
|
112 |
my @suggestion_fields = |
113 |
qw( title author copyrightdate isbn publishercode collectiontitle place quantity itemtype patronreason note ); |
114 |
my $suggestion = { |
115 |
map { |
116 |
# Keep parameters that are not an empty string |
117 |
my $p = $input->param($_); |
118 |
( defined $p && $p ne '' ? ( $_ => $p ) : () ) |
119 |
} @suggestion_fields |
120 |
}; |
121 |
|
120 |
if ( $op eq "add_validate" && not $biblionumber ) { # If we are creating the suggestion from an existing record we do not want to search for duplicates |
122 |
if ( $op eq "add_validate" && not $biblionumber ) { # If we are creating the suggestion from an existing record we do not want to search for duplicates |
121 |
$op = 'add_confirm'; |
123 |
$op = 'add_confirm'; |
122 |
my $biblio = MarcRecordFromNewSuggestion($suggestion); |
124 |
my $biblio = MarcRecordFromNewSuggestion($suggestion); |
Lines 129-152
if ( $op eq "add_validate" && not $biblionumber ) { # If we are creating the sug
Link Here
|
129 |
|
131 |
|
130 |
my $patrons_pending_suggestions_count = 0; |
132 |
my $patrons_pending_suggestions_count = 0; |
131 |
if ( $borrowernumber && C4::Context->preference("MaxOpenSuggestions") ne '' ) { |
133 |
if ( $borrowernumber && C4::Context->preference("MaxOpenSuggestions") ne '' ) { |
132 |
$patrons_pending_suggestions_count = scalar @{ SearchSuggestion( { suggestedby => $borrowernumber, STATUS => 'ASKED' } ) } ; |
134 |
$patrons_pending_suggestions_count = Koha::Suggestions->search( |
|
|
135 |
{ |
136 |
suggestedby => $borrowernumber, |
137 |
STATUS => 'ASKED', |
138 |
} |
139 |
)->count; |
133 |
} |
140 |
} |
134 |
|
141 |
|
135 |
if ( $op eq "add_confirm" ) { |
142 |
if ( $op eq "add_confirm" ) { |
136 |
my $suggestions_loop = &SearchSuggestion($suggestion); |
143 |
my $suggestions = Koha::Suggestions->search($suggestion); |
137 |
if ( C4::Context->preference("MaxOpenSuggestions") ne '' && $patrons_pending_suggestions_count >= C4::Context->preference("MaxOpenSuggestions") ) #only check limit for signed in borrowers |
144 |
if ( C4::Context->preference("MaxOpenSuggestions") ne '' && $patrons_pending_suggestions_count >= C4::Context->preference("MaxOpenSuggestions") ) #only check limit for signed in borrowers |
138 |
{ |
145 |
{ |
139 |
push @messages, { type => 'error', code => 'too_many' }; |
146 |
push @messages, { type => 'error', code => 'too_many' }; |
140 |
} |
147 |
} |
141 |
elsif ( @$suggestions_loop >= 1 ) { |
148 |
elsif ( $suggestions->count >= 1 ) { |
142 |
|
149 |
|
143 |
#some suggestion are answering the request Donot Add |
150 |
#some suggestion are answering the request Donot Add |
144 |
for my $suggestion (@$suggestions_loop) { |
151 |
while ( my $suggestion = $suggestions->next ) { |
145 |
push @messages, |
152 |
push @messages, |
146 |
{ |
153 |
{ |
147 |
type => 'error', |
154 |
type => 'error', |
148 |
code => 'already_exists', |
155 |
code => 'already_exists', |
149 |
id => $suggestion->{suggestionid} |
156 |
id => $suggestion->suggestionid |
150 |
}; |
157 |
}; |
151 |
last; |
158 |
last; |
152 |
} |
159 |
} |
Lines 165-183
if ( $op eq "add_confirm" ) {
Link Here
|
165 |
&NewSuggestion($suggestion); |
172 |
&NewSuggestion($suggestion); |
166 |
$patrons_pending_suggestions_count++; |
173 |
$patrons_pending_suggestions_count++; |
167 |
|
174 |
|
168 |
# delete empty fields, to avoid filter in "SearchSuggestion" |
|
|
169 |
foreach my $field ( qw( title author publishercode copyrightdate place collectiontitle isbn STATUS ) ) { |
170 |
delete $suggestion->{$field}; #clear search filters (except borrower related) to show all suggestions after placing a new one |
171 |
} |
172 |
$suggestions_loop = &SearchSuggestion($suggestion); |
173 |
|
174 |
push @messages, { type => 'info', code => 'success_on_inserted' }; |
175 |
push @messages, { type => 'info', code => 'success_on_inserted' }; |
175 |
|
176 |
|
176 |
} |
177 |
} |
177 |
$op = 'else'; |
178 |
$op = 'else'; |
178 |
} |
179 |
} |
179 |
|
180 |
|
180 |
my $suggestions_loop = &SearchSuggestion({suggestedby => $suggestion->{suggestedby}}); |
181 |
my $suggestions = Koha::Suggestions->search( |
|
|
182 |
{ |
183 |
$suggestion->{suggestedby} |
184 |
? ( suggestedby => $suggestion->{suggestedby} ) |
185 |
: () |
186 |
} |
187 |
); |
188 |
|
181 |
if ( $op eq "delete_confirm" ) { |
189 |
if ( $op eq "delete_confirm" ) { |
182 |
my @delete_field = $input->multi_param("delete_field"); |
190 |
my @delete_field = $input->multi_param("delete_field"); |
183 |
foreach my $delete_field (@delete_field) { |
191 |
foreach my $delete_field (@delete_field) { |
Lines 188-211
if ( $op eq "delete_confirm" ) {
Link Here
|
188 |
exit; |
196 |
exit; |
189 |
} |
197 |
} |
190 |
|
198 |
|
191 |
map{ |
|
|
192 |
my $s = $_; |
193 |
my $library = Koha::Libraries->find($s->{branchcodesuggestedby}); |
194 |
$library ? $s->{branchcodesuggestedby} = $library->branchname : () |
195 |
} @$suggestions_loop; |
196 |
|
197 |
foreach my $suggestion(@$suggestions_loop) { |
198 |
if($suggestion->{'suggestedby'} == $borrowernumber) { |
199 |
$suggestion->{'showcheckbox'} = $borrowernumber; |
200 |
} else { |
201 |
$suggestion->{'showcheckbox'} = 0; |
202 |
} |
203 |
if($suggestion->{'patronreason'}){ |
204 |
my $av = Koha::AuthorisedValues->search({ category => 'OPAC_SUG', authorised_value => $suggestion->{patronreason} }); |
205 |
$suggestion->{'patronreason'} = $av->count ? $av->next->opac_description : ''; |
206 |
} |
207 |
} |
208 |
|
209 |
my $patron_reason_loop = GetAuthorisedValues("OPAC_SUG"); |
199 |
my $patron_reason_loop = GetAuthorisedValues("OPAC_SUG"); |
210 |
|
200 |
|
211 |
# Is the person allowed to choose their branch |
201 |
# Is the person allowed to choose their branch |
Lines 247-253
my @mandatoryfields;
Link Here
|
247 |
|
237 |
|
248 |
$template->param( |
238 |
$template->param( |
249 |
%$suggestion, |
239 |
%$suggestion, |
250 |
suggestions_loop => $suggestions_loop, |
240 |
suggestions => $suggestions, |
251 |
patron_reason_loop => $patron_reason_loop, |
241 |
patron_reason_loop => $patron_reason_loop, |
252 |
"op_$op" => 1, |
242 |
"op_$op" => 1, |
253 |
$op => 1, |
243 |
$op => 1, |
254 |
- |
|
|