Bug 17600: Standardize our EXPORT_OK
[srvgit] / members / member.pl
index e7f297b..4b4578c 100755 (executable)
 
 
 # Copyright 2000-2002 Katipo Communications
+# Copyright 2013 BibLibre
 #
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA  02111-1307 USA
+# 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 C4::Auth;
-use C4::Output;
-use CGI;
-use C4::Members;
-use C4::Branch;
-use C4::Category;
+use Modern::Perl;
+use C4::Auth qw( get_template_and_user );
+use C4::Output qw( output_html_with_http_headers );
+use CGI qw( -utf8 );
+use Koha::List::Patron qw( GetPatronLists );
+use Koha::Patrons;
 
-my $input = new CGI;
-my $quicksearch = $input->param('quicksearch');
-my $startfrom = $input->param('startfrom')||1;
-my $resultsperpage = $input->param('resultsperpage')||C4::Context->preference("PatronsPerPage")||20;
+my $input = CGI->new;
 
-my ($template, $loggedinuser, $cookie);
-if($quicksearch){
-    ($template, $loggedinuser, $cookie)
-    = get_template_and_user({template_name => "members/member-quicksearch-results.tmpl",
+my ($template, $loggedinuser, $cookie)
+    = get_template_and_user({template_name => "members/member.tt",
                  query => $input,
                  type => "intranet",
-                 authnotrequired => 0,
-                 flagsrequired => {borrowers => 1},
+                 flagsrequired => {borrowers => 'edit_borrowers'},
                  });
-} else {
-    ($template, $loggedinuser, $cookie)
-    = get_template_and_user({template_name => "members/member.tmpl",
-                 query => $input,
-                 type => "intranet",
-                 authnotrequired => 0,
-                 flagsrequired => {borrowers => 1},
-                 });
-}
-my $theme = $input->param('theme') || "default";
-
-my @categories=C4::Category->all;
-my $branches=GetBranchesLoop();
-
-my %categories_dislay;
-
-foreach my $category (@categories){
-       my $hash={
-                       category_description=>$$category{description},
-                       category_type=>$$category{category_type}
-                        };
-       $categories_dislay{$$category{categorycode}} = $hash;
-}
-$template->param( 
-        "AddPatronLists_".C4::Context->preference("AddPatronLists")=> "1",
-            );
-if (C4::Context->preference("AddPatronLists")=~/code/){
-    $categories[0]->{'first'}=1;
-}  
-
-my $member=$input->param('member');
-my $orderby=$input->param('orderby');
-$orderby = "surname,firstname" unless $orderby;
-$member =~ s/,//g;   #remove any commas from search string
-$member =~ s/\*/%/g;
-
-my ($count,$results);
 
-my $patron = $input->Vars;
-foreach (keys %$patron){
-       delete $$patron{$_} unless($$patron{$_}); 
-}
-if (C4::Context->preference("IndependantBranches")){
-   if (C4::Context->userenv && C4::Context->userenv->{flags} % 2 !=1 && C4::Context->userenv->{'branch'}){
-        $$patron{branchcode}=C4::Context->userenv->{'branch'} unless (C4::Context->userenv->{'branch'} eq "insecure");
-   }
-}
-$$patron{firstname}.="\%" if ($$patron{firstname});
+my $theme = $input->param('theme') || "default";
 
-my @searchpatron;
-push @searchpatron, $member if ($member);
-push @searchpatron, $patron if (keys %$patron);
-my $from= ($startfrom-1)*$resultsperpage;
-my $to=$from+$resultsperpage;
- #($results)=Search(\@searchpatron,{surname=>1,firstname=>1},[$from,$to],undef,["firstname","surname","email","othernames"]  ) if (@searchpatron);
- ($results)=Search(\@searchpatron,{surname=>1,firstname=>1},undef,undef,["firstname","surname","email","othernames","cardnumber"]  ) if (@searchpatron);
-if ($results){
-       $count =scalar(@$results);
+my $searchmember = $input->param('searchmember');
+my $quicksearch = $input->param('quicksearch') // 0;
+
+if ( $quicksearch and $searchmember ) {
+    my $branchcode;
+    if ( C4::Context::only_my_library ) {
+        my $userenv = C4::Context->userenv;
+        $branchcode = $userenv->{'branch'};
+    }
+    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 @resultsdata;
-my $to=($count>$to?$to:$count);
-my $index=$from;
-foreach my $borrower(@$results[$from..$to-1]){
-  #find out stats
-  my ($od,$issue,$fines)=GetMemberIssuesAndFines($$borrower{'borrowernumber'});
 
-  $$borrower{'dateexpiry'}= C4::Dates->new($$borrower{'dateexpiry'},'iso')->output('syspref');
+my $searchfieldstype = $input->param('searchfieldstype') || 'standard';
 
-  my %row = (
-    count => $index++,
-       %$borrower,
-       %{$categories_dislay{$$borrower{categorycode}}},
-    overdues => $od,
-    issues => $issue,
-    odissue => "$od/$issue",
-    fines =>  sprintf("%.2f",$fines),
-    );
-  push(@resultsdata, \%row);
-}
+$template->param( 'alphabet' => C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' );
 
-if ($$patron{branchcode}){
-       foreach my $branch (grep{$_->{value} eq $$patron{branchcode}}@$branches){
-               $$branch{selected}=1;
-       }
-}
-if ($$patron{categorycode}){
-       foreach my $category (grep{$_->{categorycode} eq $$patron{categorycode}}@categories){
-               $$category{selected}=1;
-       }
-}
-my %parameters=
-        (  %$patron
-               , 'orderby'                     => $orderby 
-               , 'resultsperpage'      => $resultsperpage 
-        , 'type'=> 'intranet'); 
-my $base_url =
-    'member.pl?&amp;'
-  . join(
-    '&amp;',
-    map { "$_=$parameters{$_}" } (keys %parameters)
-  );
+my $view = $input->request_method() eq "GET" ? "show_form" : "show_results";
 
 $template->param(
-    paginationbar => pagination_bar(
-        $base_url,  int( $count / $resultsperpage ) + 1,
-        $startfrom, 'startfrom'
-    ),
-    startfrom => $startfrom,
-    from      => ($startfrom-1)*$resultsperpage+1,  
-    to        => $to,
-    multipage => ($count != $to+1 || $startfrom!=1),
-);
-$template->param(
-    branchloop=>$branches,
-       categoryloop=>\@categories,
+    patron_lists => [ GetPatronLists() ],
+    searchmember        => $searchmember,
+    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,
 );
 
-
-$template->param( 
-        searching       => "1",
-               %$patron,
-        numresults      => $count,
-        resultsloop     => \@resultsdata,
-            );
-
 output_html_with_http_headers $input, $cookie, $template->output;