merged with statecollection.pl
[koha.git] / serials / 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 # $Id$
21
22 =head1 NAME
23
24 distributedto
25
26 =head1 DESCRIPTION
27
28 this script is launched as a popup. It allows to choose for who the subscription can be distributed.
29
30 =head1 PARAMETERS
31
32 =over 4
33
34 =item searchfield
35 to filter on the members.
36
37 =item distributedto
38 to know if there are already some members to in the distributed list
39
40 =item subscriptionid
41 to know what subscription this scrpit have to distribute.
42
43 =item SaveList
44
45 =back
46
47 =cut
48
49
50 use strict;
51 use CGI;
52 use C4::Date;
53 use C4::Auth;
54 use C4::Context;
55 use C4::Output;
56 use C4::Interface::CGI::Output;
57 use C4::Search;
58 use HTML::Template;
59 use C4::Serials;
60 use C4::Members;
61
62 my $input = new CGI;
63 my $searchfield=$input->param('searchfield');
64 defined $searchfield or $searchfield='';
65 my $distributedto=$input->param('distributedto');
66 my $subscriptionid = $input->param('subscriptionid');
67 $searchfield=~ s/\,//g;
68 my $SaveList=$input->param('SaveList');
69 my $dbh = C4::Context->dbh;
70
71 $distributedto = GetDistributedTo($subscriptionid) unless $distributedto;
72
73 SetDistributedto($distributedto,$subscriptionid) if ($SaveList) ;
74
75 my ($template, $borrowernumber, $cookie)
76     = get_template_and_user({template_name => "serials/distributedto.tmpl",
77                  query => $input,
78                  type => "intranet",
79                  authnotrequired => 0,
80                  flagsrequired => {cataloguing => 1},
81                  debug => 1,
82                  });
83
84 my ($count,$results)=GetBorrowersFromSurname($searchfield) if $searchfield;
85 my $toggle="0";
86 my @loop_data =();
87 for (my $i=0; $i < $count; $i++){
88     if ($i % 2){
89             $toggle=1;
90     } else {
91             $toggle=0;
92     }
93     my %row_data;
94     $row_data{toggle} = $toggle;
95     $row_data{firstname} = $results->[$i]{'firstname'};
96     $row_data{surname} = $results->[$i]{'surname'};
97     push(@loop_data, \%row_data);
98 }
99 $template->param(borlist => \@loop_data,
100                 searchfield => $searchfield,
101                 distributedto => $distributedto,
102                 SaveList => $SaveList,
103                 subscriptionid => $subscriptionid,
104                 );
105 output_html_with_http_headers $input, $cookie, $template->output;