moving boraccount.pl to members directory
[koha.git] / bull / distributedto.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19
20 use strict;
21 use CGI;
22 use C4::Date;
23 use C4::Auth;
24 use C4::Context;
25 use C4::Output;
26 use C4::Interface::CGI::Output;
27 use C4::Search;
28 use HTML::Template;
29
30 sub StringSearch  {
31         my ($searchstring)=@_;
32         my $dbh = C4::Context->dbh;
33         $searchstring=~ s/\'/\\\'/g;
34         my @data=split(' ',$searchstring);
35         my $count=@data;
36         my $sth=$dbh->prepare("Select surname,firstname from borrowers where (surname like ?) order by surname");
37         $sth->execute("$data[0]%");
38         my @results;
39         my $cnt=0;
40         while (my $data=$sth->fetchrow_hashref){
41                 push(@results,$data);
42                 $cnt ++;
43         }
44         $sth->finish;
45         return($cnt,\@results);
46 }
47
48 my $input = new CGI;
49 my $searchfield=$input->param('searchfield');
50 defined $searchfield or $searchfield='';
51 my $distributedto=$input->param('distributedto');
52 my $subscriptionid = $input->param('subscriptionid');
53 $searchfield=~ s/\,//g;
54 my $SaveList=$input->param('SaveList');
55 my $dbh = C4::Context->dbh;
56
57 unless ($distributedto) {
58         # read the previous distributedto
59         my $sth = $dbh->prepare('select distributedto from subscription where subscriptionid=?');
60         $sth->execute($subscriptionid);
61         ($distributedto) = $sth->fetchrow;
62 }
63
64 if ($SaveList) {
65         my $sth = $dbh->prepare("update subscription set distributedto=? where subscriptionid=?");
66         $sth->execute($distributedto,$subscriptionid);
67 }
68 my ($template, $borrowernumber, $cookie)
69     = get_template_and_user({template_name => "bull/distributedto.tmpl",
70                              query => $input,
71                              type => "intranet",
72                              authnotrequired => 0,
73                              flagsrequired => {cataloguing => 1},
74                              debug => 1,
75                              });
76
77 my $env;
78 my $count=0;
79 my $results;
80 ($count,$results)=StringSearch($searchfield) if $searchfield;
81 my $toggle="0";
82 my @loop_data =();
83 for (my $i=0; $i < $count; $i++){
84         if ($i % 2){
85                         $toggle=1;
86         } else {
87                         $toggle=0;
88         }
89         my %row_data;
90         $row_data{toggle} = $toggle;
91         $row_data{firstname} = $results->[$i]{'firstname'};
92         $row_data{surname} = $results->[$i]{'surname'};
93         push(@loop_data, \%row_data);
94 }
95 $template->param(borlist => \@loop_data,
96                                 searchfield => $searchfield,
97                                 distributedto => $distributedto,
98                                 SaveList => $SaveList,
99                                 subscriptionid => $subscriptionid,
100                                 );
101 output_html_with_http_headers $input, $cookie, $template->output;
102