Bug 22120: Add price formattig to patron summary print
[koha.git] / members / member.pl
index a93e79a..11cbc41 100755 (executable)
@@ -27,11 +27,9 @@ use Modern::Perl;
 use C4::Auth;
 use C4::Output;
 use CGI qw( -utf8 );
-use C4::Branch;
-use C4::Category;
-use C4::Members qw( GetMember );
 use Koha::DateUtils;
 use Koha::List::Patron;
+use Koha::Patrons;
 
 my $input = new CGI;
 
@@ -40,72 +38,34 @@ my ($template, $loggedinuser, $cookie)
                  query => $input,
                  type => "intranet",
                  authnotrequired => 0,
-                 flagsrequired => {borrowers => 1},
+                 flagsrequired => {borrowers => 'edit_borrowers'},
                  });
 
 my $theme = $input->param('theme') || "default";
 
-my $patron = $input->Vars;
-foreach (keys %$patron){
-    delete $patron->{$_} unless($patron->{$_});
-}
-
 my $searchmember = $input->param('searchmember');
 my $quicksearch = $input->param('quicksearch') // 0;
 
 if ( $quicksearch and $searchmember ) {
     my $branchcode;
-    if ( C4::Branch::onlymine ) {
+    if ( C4::Context::only_my_library ) {
         my $userenv = C4::Context->userenv;
         $branchcode = $userenv->{'branch'};
     }
-    my $member = GetMember(
-        cardnumber => $searchmember,
-        ( $branchcode ? ( branchcode => $branchcode ) : () ),
-    );
-    if( $member ){
-        print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=" . $member->{borrowernumber});
+    my $patron = Koha::Patrons->find( { cardnumber => $searchmember } );
+    if (
+        $patron
+        and (  ( $branchcode and $patron->branchcode eq $branchcode )
+            or ( not $branchcode ) )
+      )
+    {
+        print $input->redirect( "/cgi-bin/koha/members/moremember.pl?borrowernumber=" . $patron->borrowernumber );
         exit;
     }
 }
 
 my $searchfieldstype = $input->param('searchfieldstype') || 'standard';
 
-if ( $searchfieldstype eq "dateofbirth" ) {
-    $searchmember = output_pref({dt => dt_from_string($searchmember), dateformat => 'iso', dateonly => 1});
-}
-
-my $branches = C4::Branch::GetBranches;
-my @branches_loop;
-if ( C4::Branch::onlymine ) {
-    my $userenv = C4::Context->userenv;
-    my $branch = C4::Branch::GetBranchDetail( $userenv->{'branch'} );
-    push @branches_loop, {
-        value => $branch->{branchcode},
-        branchcode => $branch->{branchcode},
-        branchname => $branch->{branchname},
-        selected => 1
-    }
-} else {
-    foreach ( sort { lc($branches->{$a}->{branchname}) cmp lc($branches->{$b}->{branchname}) } keys %$branches ) {
-        my $selected = 0;
-        $selected = 1 if($patron->{branchcode} and $patron->{branchcode} eq $_);
-        push @branches_loop, {
-            value => $_,
-            branchcode => $_,
-            branchname => $branches->{$_}->{branchname},
-            selected => $selected
-        };
-    }
-}
-
-my @categories = C4::Category->all;
-if ( $patron->{categorycode} ) {
-    foreach my $category ( grep { $_->{categorycode} eq $patron->{categorycode} } @categories ) {
-        $category->{selected} = 1;
-    }
-}
-
 $template->param( 'alphabet' => C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' );
 
 my $view = $input->request_method() eq "GET" ? "show_form" : "show_results";
@@ -113,11 +73,9 @@ my $view = $input->request_method() eq "GET" ? "show_form" : "show_results";
 $template->param(
     patron_lists => [ GetPatronLists() ],
     searchmember        => $searchmember,
-    branchloop          => \@branches_loop,
-    categories          => \@categories,
-    branchcode          => $patron->{branchcode},
-    categorycode        => $patron->{categorycode},
-    searchtype          => $input->param('searchtype') || 'start_with',
+    branchcode_filter   => scalar $input->param('branchcode_filter'),
+    categorycode_filter => scalar $input->param('categorycode_filter'),
+    searchtype          => scalar $input->param('searchtype') || 'contain',
     searchfieldstype    => $searchfieldstype,
     PatronsPerPage      => C4::Context->preference("PatronsPerPage") || 20,
     view                => $view,