Bug 23523: (follow-up) Adjust tests for new expectations
[srvgit] / opac / opac-suggestions.pl
index b183364..8f792cd 100755 (executable)
 # You should have received a copy of the GNU General Public License
 # along with Koha; if not, see <http://www.gnu.org/licenses>.
 
-use strict;
-use warnings;
+use Modern::Perl;
+
 
 use CGI qw ( -utf8 );
 use Encode qw( encode );
 use C4::Auth;    # get_template_and_user
 use C4::Members;
-use C4::Branch;
 use C4::Koha;
 use C4::Output;
 use C4::Suggestions;
 use C4::Koha;
 use C4::Scrubber;
+
+use Koha::AuthorisedValues;
 use Koha::Libraries;
+use Koha::Patrons;
 
 use Koha::DateUtils qw( dt_from_string );
 
@@ -185,7 +187,8 @@ foreach my $suggestion(@$suggestions_loop) {
         $suggestion->{'showcheckbox'} = 0;
     }
     if($suggestion->{'patronreason'}){
-        $suggestion->{'patronreason'} = GetKohaAuthorisedValueLib("OPAC_SUG",$suggestion->{'patronreason'},1);
+        my $av = Koha::AuthorisedValues->search({ category => 'OPAC_SUG', authorised_value => $suggestion->{patronreason} });
+        $suggestion->{'patronreason'} = $av->count ? $av->next->opac_description : '';
     }
 }
 
@@ -193,25 +196,26 @@ my $patron_reason_loop = GetAuthorisedValues("OPAC_SUG");
 
 # Is the person allowed to choose their branch
 if ( C4::Context->preference("AllowPurchaseSuggestionBranchChoice") ) {
-    my ( $borr ) = GetMemberDetails( $borrowernumber );
+    my $branchcode = $input->param('branchcode') || q{};
 
-# pass the pickup branch along....
-    my $userbranch = '';
-    if (C4::Context->userenv && C4::Context->userenv->{'branch'}) {
-        $userbranch = C4::Context->userenv->{'branch'};
+    if ( !$branchcode
+        && C4::Context->userenv
+        && C4::Context->userenv->{branch} )
+    {
+        $branchcode = C4::Context->userenv->{branch};
     }
-    my $branchcode = $input->param('branchcode') || $borr->{'branchcode'} || $userbranch || '' ;
 
-# make branch selection options...
-    my $branchloop = GetBranchesLoop($branchcode);
-    $template->param( branchloop => $branchloop );
+    $template->param( branchcode => $branchcode );
 }
 
-my $mandatoryfields = '';
+my @mandatoryfields;
 {
     last unless ($op eq 'add');
     my $fldsreq_sp = C4::Context->preference("OPACSuggestionMandatoryFields") || 'title';
-    $mandatoryfields = join(', ', (map { '"'.$_.'"'; } sort split(/\s*\,\s*/, $fldsreq_sp)));
+    @mandatoryfields = sort split(/\s*\,\s*/, $fldsreq_sp);
+    foreach (@mandatoryfields) {
+        $template->param( $_."_required" => 1);
+    }
 }
 
 $template->param(
@@ -223,9 +227,8 @@ $template->param(
     messages              => \@messages,
     suggestionsview       => 1,
     suggested_by_anyone   => $suggested_by_anyone,
-    mandatoryfields       => $mandatoryfields,
     patrons_pending_suggestions_count => $patrons_pending_suggestions_count,
 );
 
-output_html_with_http_headers $input, $cookie, $template->output;
+output_html_with_http_headers $input, $cookie, $template->output, undef, { force_no_caching => 1 };