3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
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
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.
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
26 use C4
::Dates qw
/format_date/;
34 my $op = $query->param('op') || q{};
35 my $dbh = C4
::Context
->dbh;
39 my ($template, $loggedinuser, $cookie);
40 ($template, $loggedinuser, $cookie)
41 = get_template_and_user
({template_name
=> "serials/serials-collection.tmpl",
45 flagsrequired
=> {serials
=> 1},
48 my $biblionumber = $query->param('biblionumber');
49 my @subscriptionid = $query->param('subscriptionid');
51 my $subscriptiondescs ;
54 if($op eq 'gennext' && @subscriptionid){
55 my $subscriptionid = $subscriptionid[0];
56 my $subscription = GetSubscription
($subscriptionid);
58 my $sth = $dbh->prepare("SELECT publisheddate, serialid, serialseq, planneddate
59 FROM serial WHERE status = 1 AND subscriptionid = ?");
60 $sth->execute($subscriptionid);
62 # modify actual expected issue, to generate the next
63 if ( my $issue = $sth->fetchrow_hashref ) {
64 ModSerialStatus
( $issue->{serialid
}, $issue->{serialseq
},
65 $issue->{planneddate
}, $issue->{publisheddate
},
68 my $expected = GetNextExpected
($subscriptionid);
70 $newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3,
71 $newinnerloop1, $newinnerloop2, $newinnerloop3
72 ) = GetNextSeq
($subscription);
74 ## We generate the next publication date
75 my $nextpublisheddate = GetNextDate
( $expected->{planneddate
}->output('iso'), $subscription );
76 ## Creating the new issue
77 NewIssue
( $newserialseq, $subscriptionid, $subscription->{'biblionumber'},
78 1, $nextpublisheddate, $nextpublisheddate );
80 ## Updating the subscription seq status
81 my $squery = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
82 WHERE subscriptionid = ?";
83 $sth = $dbh->prepare($squery);
85 $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1,
86 $newinnerloop2, $newinnerloop3, $subscriptionid
91 print $query->redirect('/cgi-bin/koha/serials/serials-collection.pl?subscriptionid='.$subscriptionid);
95 my @subscriptioninformation=();
96 foreach my $subscriptionid (@subscriptionid){
97 my $subs= GetSubscription
($subscriptionid);
98 $subs->{opacnote
} =~ s/\n/\<br\/\
>/g
;
99 $subs->{missinglist
} =~ s/\n/\<br\/\
>/g
;
100 $subs->{recievedlist
} =~ s/\n/\<br\/\
>/g
;
101 ##these are display information
102 $subs->{ "periodicity" . $subs->{periodicity
} } = 1;
103 $subs->{ "numberpattern" . $subs->{numberpattern
} } = 1;
104 $subs->{ "status" . $subs->{'status'} } = 1;
105 $subs->{startdate
} = format_date
( $subs->{startdate
} );
106 $subs->{histstartdate
} = format_date
( $subs->{histstartdate
} );
107 if ( !defined $subs->{enddate
} || $subs->{enddate
} eq '0000-00-00' ) {
108 $subs->{enddate
} = '';
111 $subs->{enddate
} = format_date
( $subs->{enddate
} );
113 $subs->{'abouttoexpire'}=abouttoexpire
($subs->{'subscriptionid'});
114 $subs->{'subscriptionexpired'}=HasSubscriptionExpired
($subs->{'subscriptionid'});
115 $subs->{'subscriptionid'} = $subscriptionid; # FIXME - why was this lost ?
116 push @
$subscriptiondescs,$subs;
117 my $tmpsubscription= GetFullSubscription
($subscriptionid);
118 @subscriptioninformation=(@
$tmpsubscription,@subscriptioninformation);
120 $subscriptions=PrepareSerialsData
(\
@subscriptioninformation);
122 $subscriptiondescs = GetSubscriptionsFromBiblionumber
($biblionumber) ;
123 my $subscriptioninformation = GetFullSubscriptionsFromBiblionumber
($biblionumber);
124 $subscriptions=PrepareSerialsData
($subscriptioninformation);
127 my $title = $subscriptiondescs->[0]{bibliotitle
};
128 my $yearmax=($subscriptions->[0]{year
} eq "manage" && scalar(@
$subscriptions)>1)?
$subscriptions->[1]{year
} :$subscriptions->[0]{year
};
129 my $yearmin=$subscriptions->[scalar(@
$subscriptions)-1]{year
};
130 my $subscriptionidlist="";
131 foreach my $subscription (@
$subscriptiondescs){
132 $subscriptionidlist.=$subscription->{'subscriptionid'}."," ;
133 $biblionumber = $subscription->{'bibnum'} unless ($biblionumber);
136 # warn "title : $title yearmax : $yearmax nombre d'elements dans le tableau :".scalar(@$subscriptions);
137 # use Data::Dumper; warn Dumper($subscriptions);
138 chop $subscriptionidlist;
140 onesubscription
=> (scalar(@
$subscriptiondescs)==1),
141 subscriptionidlist
=> $subscriptionidlist,
142 biblionumber
=> $biblionumber,
143 subscriptions
=> $subscriptiondescs,
144 years
=> $subscriptions,
147 bibliotitle
=> $title,
148 suggestion
=> C4
::Context
->preference("suggestion"),
149 virtualshelves
=> C4
::Context
->preference("virtualshelves"),
150 subscr
=>$query->param('subscriptionid'),
153 output_html_with_http_headers
$query, $cookie, $template->output;