Merge remote-tracking branch 'kc/new/bug_6521' into kcmaster
[koha.git] / admin / aqbudget_owner_search.pl
1 #!/usr/bin/perl
2
3 # script to find a guarantor
4
5 # Copyright 2008-2009 BibLibre SARL
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
22 use strict;
23 #use warnings; FIXME - Bug 2505
24 use C4::Auth ;
25 use C4::Output;
26 use CGI;
27 use C4::Dates qw/format_date/;
28 use C4::Members;
29
30 my $input = new CGI;
31
32 my $dbh = C4::Context->dbh;
33
34 my ( $template, $loggedinuser, $cookie, $staff_flags ) = get_template_and_user(
35     {   template_name   => "admin/aqbudget_owner_search.tmpl",
36         query           => $input,
37         type            => "intranet",
38         authnotrequired => 0,
39         flagsrequired   => { acquisition => 'budget_modify'  },
40         debug           => 1,
41     }
42 );
43
44 my $theme = $input->param('theme') || "default";
45
46 # only used if allowthemeoverride is set
47 my $member  = $input->param('member');
48 my $orderby = $input->param('orderby');
49
50 my $op = $input->param('op');
51 $template->param( $op || else => 1, );
52
53 $orderby = "surname,firstname" unless $orderby;
54 $member =~ s/,//g;     #remove any commas from search string
55 $member =~ s/\*/%/g;
56 if ( $member eq '' ) {
57     $template->param( results => 0 );
58 } else {
59     $template->param( results => 1 );
60 }
61
62 my ( $count, $count2, $results );
63 my @resultsdata;
64 my $toggle = 0;
65
66 if ( $member ) {
67         my $results= SearchMember($member,"surname",undef,undef,undef);
68
69     foreach my $res (@$results) {
70
71         my $perms = haspermission( $res->{'userid'} );
72         my $subperms =  get_user_subpermissions  ($res->{'userid'} );
73
74
75         # if the member has 'acqui' permission set, then display to table.
76         if (    $perms->{superlibrarian} == 1  || 
77                 $perms->{acquisition} == 1  || 
78                 $subperms->{acquisition}->{'budget_manage'} || 
79                 $subperms->{acquisition}->{'budget_modify'} || 
80                 $subperms->{acquisition}->{'budget_add_del'}  ) {
81
82             $count2++;
83             #find out stats
84 #            my ( $od, $issue, $fines ) = GetMemberIssuesAndFines( $res->{'borrowerid'} );
85                         #This looks unused and very unuseful
86             my $guarantorinfo = uc( $res->{'surname'} ) . " , " . ucfirst( $res->{'firstname'} );
87             my $budget_owner_name = $res->{'firstname'} . ' ' . $res->{'surname'}, my $budget_owner_id = $res->{'borrowernumber'};
88
89             my %row = (
90                 borrowernumber    => $res->{'borrowernumber'},
91                 cardnumber        => $res->{'cardnumber'},
92                 surname           => $res->{'surname'},
93                 firstname         => $res->{'firstname'},
94                 categorycode      => $res->{'categorycode'},
95                 branchcode        => $res->{'branchcode'},
96                 guarantorinfo     => $guarantorinfo,
97                 budget_owner_id   => $budget_owner_id,
98                 budget_owner_name => $budget_owner_name,
99 #                odissue           => "$od/$issue",
100 #                fines             => $fines,
101 #                borrowernotes     => $res->{'borrowernotes'}
102             );
103             push( @resultsdata, \%row );
104         }
105     }
106 }
107
108 $template->param(
109     member => $member,
110     numres => $count2,
111     resultsloop => \@resultsdata
112 );
113
114 output_html_with_http_headers $input, $cookie, $template->output;