Bug 17600: Standardize our EXPORT_OK
[srvgit] / opac / sco / sco-main.pl
index 4c405f5..40d5915 100755 (executable)
@@ -35,14 +35,11 @@ use Modern::Perl;
 
 use CGI qw ( -utf8 );
 
-use C4::Auth qw(get_template_and_user checkpw in_iprange);
-use C4::Koha;
-use C4::Circulation;
+use C4::Auth qw( in_iprange get_template_and_user checkpw );
+use C4::Circulation qw( AddReturn CanBookBeIssued AddIssue CanBookBeRenewed AddRenewal );
 use C4::Reserves;
-use C4::Output;
+use C4::Output qw( output_html_with_http_headers );
 use C4::Members;
-use C4::Biblio;
-use C4::Items;
 use Koha::DateUtils qw( dt_from_string );
 use Koha::Acquisition::Currencies;
 use Koha::Items;
@@ -51,7 +48,7 @@ use Koha::Patron::Images;
 use Koha::Patron::Messages;
 use Koha::Token;
 
-my $query = new CGI;
+my $query = CGI->new;
 
 unless (C4::Context->preference('WebBasedSelfCheck')) {
     # redirect to OPAC home if self-check is not enabled
@@ -81,7 +78,6 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
         flagsrequired   => { self_check => "self_checkout_module" },
         query           => $query,
         type            => "opac",
-        debug           => 1,
     }
 );
 
@@ -135,8 +131,20 @@ if ($op eq "logout") {
     $query->param( patronid => undef, patronlogin => undef, patronpw => undef );
 }
 elsif ( $op eq "returnbook" && $allowselfcheckreturns ) {
-    my ($doreturn) = AddReturn( $barcode, $branch );
-    $template->param( returned => $doreturn );
+    my $success        = 0;
+    my $human_required = 0;
+    if ( C4::Context->preference("CircConfirmItemParts") ) {
+        my $item = Koha::Items->find( { barcode => $barcode } );
+        if ( defined($item)
+            && $item->materials )
+        {
+            $human_required = 1;
+        }
+    }
+
+    ($success) = AddReturn( $barcode, $branch )
+      unless $human_required;
+    $template->param( returned => $success );
 }
 elsif ( $patron && ( $op eq 'checkout' ) ) {
     my $impossible  = {};
@@ -150,7 +158,7 @@ elsif ( $patron && ( $op eq 'checkout' ) ) {
     );
     my $issue_error;
     if ( $confirm_required = scalar keys %$needconfirm ) {
-        for my $error ( qw( UNKNOWN_BARCODE max_loans_allowed ISSUED_TO_ANOTHER NO_MORE_RENEWALS NOT_FOR_LOAN DEBT WTHDRAWN RESTRICTED RESERVED ITEMNOTSAMEBRANCH EXPIRED DEBARRED CARD_LOST GNA INVALID_DATE UNKNOWN_BARCODE TOO_MANY DEBT_GUARANTEES USERBLOCKEDOVERDUE PATRON_CANT PREVISSUE NOT_FOR_LOAN_FORCING ITEM_LOST) ) {
+        for my $error ( qw( UNKNOWN_BARCODE max_loans_allowed ISSUED_TO_ANOTHER NO_MORE_RENEWALS NOT_FOR_LOAN DEBT WTHDRAWN RESTRICTED RESERVED ITEMNOTSAMEBRANCH EXPIRED DEBARRED CARD_LOST GNA INVALID_DATE UNKNOWN_BARCODE TOO_MANY DEBT_GUARANTEES DEBT_GUARANTORS USERBLOCKEDOVERDUE PATRON_CANT PREVISSUE NOT_FOR_LOAN_FORCING ITEM_LOST ADDITIONAL_MATERIALS ) ) {
             if ( $needconfirm->{$error} ) {
                 $issue_error = $error;
                 $confirmed = 0;
@@ -256,7 +264,7 @@ if ( $patron && ( $op eq 'renew' ) ) {
     my ($status,$renewerror) = CanBookBeRenewed( $borrower->{borrowernumber}, $item->itemnumber );
     if ($status) {
         #warn "renewing";
-        AddRenewal( $borrower->{borrowernumber}, $item->itemnumber );
+        AddRenewal( $borrower->{borrowernumber}, $item->itemnumber, undef, undef, undef, undef, 1 );
         push @newissueslist, $barcode;
         $template->param( renewed => 1 );
     }