Bug 13890 - Switch from full serials permission to 'routing' permission for reorderin...
[srvgit] / serials / showpredictionpattern.pl
index e56695c..6945a36 100755 (executable)
@@ -1,20 +1,21 @@
 #!/usr/bin/perl
 
-# Copyright 2011 BibLibre SARL
+# Copyright 2011-2013 Biblibre SARL
+#
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 =head1 NAME
 
@@ -29,7 +30,7 @@ publication date, based on frequency and first publication date.
 
 use Modern::Perl;
 
-use CGI;
+use CGI qw ( -utf8 );
 use Date::Calc qw(Today Day_of_Year Week_of_Year Day_of_Week Days_in_Year Delta_Days Add_Delta_Days Add_Delta_YM);
 use C4::Auth;
 use C4::Output;
@@ -54,16 +55,13 @@ my $subtype = $input->param('subtype');
 my $sublength = $input->param('sublength');
 my $custompattern = $input->param('custompattern');
 
+my $frequency = GetSubscriptionFrequency($frequencyid);
 
-my %val = (
-    locale          => $input->param('locale') // '',
+my %pattern = (
     numberingmethod => $input->param('numberingmethod') // '',
     numbering1      => $input->param('numbering1') // '',
     numbering2      => $input->param('numbering2') // '',
     numbering3      => $input->param('numbering3') // '',
-    lastvalue1      => $input->param('lastvalue1') // '',
-    lastvalue2      => $input->param('lastvalue2') // '',
-    lastvalue3      => $input->param('lastvalue3') // '',
     add1            => $input->param('add1') // '',
     add2            => $input->param('add2') // '',
     add3            => $input->param('add3') // '',
@@ -76,9 +74,6 @@ my %val = (
     every1          => $input->param('every1') // '',
     every2          => $input->param('every2') // '',
     every3          => $input->param('every3') // '',
-    innerloop1      => $input->param('innerloop1') // '',
-    innerloop2      => $input->param('innerloop2') // '',
-    innerloop3      => $input->param('innerloop3') // '',
 );
 
 if(!defined $firstacquidate || $firstacquidate eq ''){
@@ -100,6 +95,13 @@ if($nextacquidate) {
 my $date = $nextacquidate;
 
 my %subscription = (
+    locale      => $input->param('locale') // '',
+    lastvalue1      => $input->param('lastvalue1') // '',
+    lastvalue2      => $input->param('lastvalue2') // '',
+    lastvalue3      => $input->param('lastvalue3') // '',
+    innerloop1      => $input->param('innerloop1') // '',
+    innerloop2      => $input->param('innerloop2') // '',
+    innerloop3      => $input->param('innerloop3') // '',
     irregularity    => '',
     periodicity     => $frequencyid,
     countissuesperunit  => 1,
@@ -114,7 +116,7 @@ if(defined $subscriptionid) {
 }
 
 my @predictions_loop;
-my ($calculated) = GetSeq(\%val);
+my ($calculated) = GetSeq(\%subscription, \%pattern);
 push @predictions_loop, {
     number => $calculated,
     publicationdate => $date,
@@ -159,7 +161,7 @@ while( $i < 1000 ) {
         last;
     }
 
-    ($calculated, $val{'lastvalue1'}, $val{'lastvalue2'}, $val{'lastvalue3'}, $val{'innerloop1'}, $val{'innerloop2'}, $val{'innerloop3'}) = GetNextSeq(\%val);
+    ($calculated, $subscription{'lastvalue1'}, $subscription{'lastvalue2'}, $subscription{'lastvalue3'}, $subscription{'innerloop1'}, $subscription{'innerloop2'}, $subscription{'innerloop3'}) = GetNextSeq(\%subscription, \%pattern);
     $issuenumber++;
     $line{'number'} = $calculated;
     $line{'issuenumber'} = $issuenumber;
@@ -176,8 +178,6 @@ $template->param(
     predictions_loop => \@predictions_loop,
 );
 
-my $frequency = GetSubscriptionFrequency($frequencyid);
-
 if ( $frequency->{unit} and not $custompattern ) {
     $template->param( ask_for_irregularities => 1 );
     if ( $frequency->{unit} eq 'day' and $frequency->{unitsperissue} == 1 ) {