fix parsing of X-ica using http://www.cap.srce.hr/IzgledX.aspx
[koha.git] / members / member.pl
index d58b08e..c5ea894 100755 (executable)
@@ -1,8 +1,7 @@
 #!/usr/bin/perl
 
-# $Id$
 
-#script to do a borrower enquiery/brin up borrower details etc
+#script to do a borrower enquiry/bring up borrower details etc
 #written 20/12/99 by chris@katipo.co.nz
 
 
 # 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, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 use strict;
+#use warnings; FIXME - Bug 2505
 use C4::Auth;
 use C4::Output;
-use C4::Interface::CGI::Output;
 use CGI;
 use C4::Members;
-
+use C4::Branch;
+use C4::Category;
+use File::Basename;
 
 my $input = new CGI;
 my $quicksearch = $input->param('quicksearch');
-my ($template, $loggedinuser, $cookie);
-if($quicksearch){
-    ($template, $loggedinuser, $cookie)
-    = get_template_and_user({template_name => "members/member-quicksearch-results.tmpl",
-                 query => $input,
-                 type => "intranet",
-                 authnotrequired => 0,
-                 flagsrequired => {borrowers => 1},
-                 debug => 1,
-                 });
-} else {
-    ($template, $loggedinuser, $cookie)
+my $startfrom = $input->param('startfrom')||1;
+my $resultsperpage = $input->param('resultsperpage')||C4::Context->preference("PatronsPerPage")||20;
+
+my ($template, $loggedinuser, $cookie)
     = get_template_and_user({template_name => "members/member.tmpl",
                  query => $input,
                  type => "intranet",
                  authnotrequired => 0,
                  flagsrequired => {borrowers => 1},
-                 debug => 1,
                  });
-}
+
 my $theme = $input->param('theme') || "default";
-            # only used if allowthemeoverride is set
-#my %tmpldata = pathtotemplate ( template => 'member.tmpl', theme => $theme, language => 'fi' );
-    # FIXME - Error-checking
-#my $template = HTML::Template->new( filename => $tmpldata{'path'},
-#                   die_on_bad_params => 0,
-#                   loop_context_vars => 1 );
 
+my $patron = $input->Vars;
+foreach (keys %$patron){
+       delete $$patron{$_} unless($$patron{$_});
+}
+my @categories=C4::Category->all;
+
+my $branches = GetBranches;
+my @branchloop;
+
+foreach (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) {
+  my $selected = 1 if $branches->{$_}->{branchcode} eq $$patron{branchcode};
+  my %row = ( value => $_,
+        selected => $selected,
+        branchname => $branches->{$_}->{branchname},
+      );
+  push @branchloop, \%row;
+}
+
+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;
+my $orderbyparams=$input->param('orderby');
+my @orderby;
+if ($orderbyparams){
+       my @orderbyelt=split(/,/,$orderbyparams);
+       push @orderby, {$orderbyelt[0]=>$orderbyelt[1]||0};
+}
+else {
+       @orderby = ({surname=>0},{firstname=>0});
+}
+
+warn "[$member]";
+# FIXME dpavlin - FER
+$member =~ s/^.*%B601983\d\d(\d{10})\d&.*$/S$1/ && warn "JMBAG: $1";
 $member =~ s/,//g;   #remove any commas from search string
 $member =~ s/\*/%/g;
-my $env;
 
 my ($count,$results);
 
-if(length($member) == 1)
-{
-    ($count,$results)=BornameSearch($env,$member,$orderby,"simple");
+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);
+ my $search_scope=($quicksearch?"field_start_with":"contain");
+ ($results)=Search(\@searchpatron,\@orderby,undef,undef,["firstname","surname","email","othernames","cardnumber","userid"],$search_scope  ) if (@searchpatron);
+if ($results){
+       $count =scalar(@$results);
 }
-else
-{
-    ($count,$results)=BornameSearch($env,$member,$orderby,"advanced");
-}
-
-
 my @resultsdata;
-my $background = 0;
-for (my $i=0; $i < $count; $i++){
+$to=($count>$to?$to:$count);
+my $index=$from;
+foreach my $borrower(@$results[$from..$to-1]){
   #find out stats
-  my ($od,$issue,$fines)=borrdata2($env,$results->[$i]{'borrowernumber'});
+  my ($od,$issue,$fines)=GetMemberIssuesAndFines($$borrower{'borrowernumber'});
+
+  $$borrower{'dateexpiry'}= C4::Dates->new($$borrower{'dateexpiry'},'iso')->output('syspref');
 
   my %row = (
-    background => $background,
-    count => $i+1,
-    borrowernumber => $results->[$i]{'borrowernumber'},
-    cardnumber => $results->[$i]{'cardnumber'},
-    surname => $results->[$i]{'surname'},
-    firstname => $results->[$i]{'firstname'},
-    categorycode => $results->[$i]{'categorycode'},
-    category_type => $results->[$i]{'category_type'},
-    category_description => $results->[$i]{'description'},
-    streetaddress => $results->[$i]{'streetaddress'},
-    city => $results->[$i]{'city'},
-    branchcode => $results->[$i]{'branchcode'},
+    count => $index++,
+       %$borrower,
+       %{$categories_dislay{$$borrower{categorycode}}},
     overdues => $od,
     issues => $issue,
     odissue => "$od/$issue",
     fines =>  sprintf("%.2f",$fines),
-    borrowernotes => $results->[$i]{'borrowernotes'},
-    sort1 => $results->[$i]{'sort1'},
-    sort2 => $results->[$i]{'sort2'},
     );
-  if ( $background ) { $background = 0; } else {$background = 1; }
   push(@resultsdata, \%row);
 }
 
-$template->param( 
-        searching       => "1",
-        member          => $member,
+if ($$patron{categorycode}){
+       foreach my $category (grep{$_->{categorycode} eq $$patron{categorycode}}@categories){
+               $$category{selected}=1;
+       }
+}
+my %parameters=
+        (  %$patron
+               , 'orderby'                     => $orderbyparams 
+               , 'resultsperpage'      => $resultsperpage 
+        , 'type'=> 'intranet'); 
+my $base_url =
+    'member.pl?&amp;'
+  . join(
+    '&amp;',
+    map { "$_=$parameters{$_}" } (keys %parameters)
+  );
+
+my @letters = map { {letter => $_} } ( 'A' .. 'Z');
+
+$template->param(
+    letters => \@letters,
+    paginationbar => pagination_bar(
+        $base_url,
+        int( $count / $resultsperpage ) + ($count % $resultsperpage ? 1 : 0),
+        $startfrom, 'startfrom'
+    ),
+    startfrom => $startfrom,
+    from      => ($startfrom-1)*$resultsperpage+1,  
+    to        => $to,
+    multipage => ($count != $to || $startfrom!=1),
+    advsearch => ($$patron{categorycode} || $$patron{branchcode}),
+    branchloop=>\@branchloop,
+    categories=>\@categories,
+    searching       => "1",
+               actionname              =>basename($0),
+               %$patron,
         numresults      => $count,
         resultsloop     => \@resultsdata,
-        intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
-        intranetstylesheet => C4::Context->preference("intranetstylesheet"),
-        IntranetNav => C4::Context->preference("IntranetNav"),
             );
 
 output_html_with_http_headers $input, $cookie, $template->output;