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