small fixes in french translation
[koha.git] / serials / subscription-detail.pl
index 7110476..6d4d202 100755 (executable)
@@ -19,7 +19,7 @@ use strict;
 use CGI;
 use C4::Auth;
 use C4::Koha;
-use C4::Date;
+use C4::Dates qw/format_date/;
 use C4::Serials;
 use C4::Output;
 use C4::Context;
@@ -31,27 +31,20 @@ my $op = $query->param('op');
 my $dbh = C4::Context->dbh;
 my $sth;
 # my $id;
-my ($template, $loggedinuser, $cookie, $subs);
-my ($subscriptionid,$auser,$librarian,$cost,$aqbooksellerid, $aqbooksellername,$aqbudgetid, $bookfundid, $startdate, $periodicity,
-    $firstacquidate, $dow, $irregularity, $sublength, $subtype, $numberpattern, $numberlength, $weeklength, $monthlength,
-    $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
-    $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
-    $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
-    $numberingmethod, $status, $biblionumber, $bibliotitle, $callnumber, $notes, $hemisphere,$letter,$manualhistory,$histstartdate,$enddate,$missinglist,$recievedlist,$opacnote,$librariannote);
-
-$subscriptionid = $query->param('subscriptionid');
+my ($template, $loggedinuser, $cookie, $hemisphere);
+my $subscriptionid = $query->param('subscriptionid');
 my $subs = &GetSubscription($subscriptionid);
+
 $subs->{enddate} = GetExpirationDate($subscriptionid);
 
 if ($op eq 'del') {
-    if ($subs->{'cannotedit'}){
-      warn "Attempt to delete subscription $subscriptionid by ".C4::Context->userenv->{'id'}." not allowed";
-      print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
-    }  
-    &DelSubscription($subscriptionid);
-    print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=serials-home.pl\"></html>";
-    exit;
-
+       if ($subs->{'cannotedit'}){
+               warn "Attempt to delete subscription $subscriptionid by ".C4::Context->userenv->{'id'}." not allowed";
+               print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
+       }  
+       &DelSubscription($subscriptionid);
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=serials-home.pl\"></html>";
+       exit;
 }
 my ($routing, @routinglist) = getroutinglist($subscriptionid);
 my ($totalissues,@serialslist) = GetSerials($subscriptionid);
@@ -67,7 +60,8 @@ $totalissues-- if $totalissues; # the -1 is to have 0 if this is a new subscript
                 debug => 1,
                 });
 
-my ($user, $cookie, $sessionID, $flags)
+my ($user, $sessionID, $flags);
+($user, $cookie, $sessionID, $flags)
     = checkauth($query, 0, {catalogue => 1}, "intranet");
 
 my $weekarrayjs='';
@@ -81,7 +75,8 @@ for(my $i=$firstday;$i<($firstday+365);$i=$i+7){
             if($wkno > 52){$year++; $wkno=1;}
             if($count>365){$count=$i-365;}
             my ($y,$m,$d) =  Add_Delta_Days($year,1,1, $count - 1);#Date_NthDayOfYear($year,$count);
-            my $output = "$y-$m-$d";
+            # padding Add_Delta_Days;
+            my $output  = sprintf("%04d-%02d-%02d",$y , $m, $d );
             $weekarrayjs .= "'Wk $wkno: ".format_date($output)."',";
             $wkno++;
     }
@@ -89,11 +84,12 @@ chop($weekarrayjs);
 
 # COMMENT hdl : IMHO, we should think about passing more and more data hash to template->param rather than duplicating code a new coding Guideline ?
 
-$subs->{startdate}=format_date($subs->{startdate});
-$subs->{firstacquidate}=format_date($subs->{firstacquidate});
-$subs->{histstartdate}=format_date($subs->{histstartdate});
-$subs->{enddate}=format_date($subs->{enddate});
-$subs->{abouttoexpire}=abouttoexpire($subs->{subscriptionid});
+$subs->{startdate}      = format_date($subs->{startdate});
+$subs->{firstacquidate} = format_date($subs->{firstacquidate});
+$subs->{histstartdate}  = format_date($subs->{histstartdate});
+$subs->{enddate}        = format_date($subs->{enddate});
+$subs->{histenddate}    = format_date($subs->{histenddate});
+$subs->{abouttoexpire}  = abouttoexpire($subs->{subscriptionid});
 # Done in Serials.pm
 # $subs->{'donotedit'}=(C4::Context->preference('IndependantBranches') && 
 #         C4::Context->userenv && 
@@ -104,10 +100,16 @@ $subs->{abouttoexpire}=abouttoexpire($subs->{subscriptionid});
 $template->param($subs);
 
 $template->param(
+       subscriptionid => $subscriptionid,
     routing => $routing,
     serialslist => \@serialslist,
     totalissues => $totalissues,
     hemisphere => $hemisphere,
+    cannotedit =>(C4::Context->preference('IndependantBranches') && 
+                C4::Context->userenv && 
+                C4::Context->userenv->{flags} !=1  && 
+                C4::Context->userenv->{branch} && $subs->{branchcode} &&
+                (C4::Context->userenv->{branch} ne $subs->{branchcode})),
     );
 $template->param(
             "periodicity".($subs->{periodicity}?$subs->{periodicity}:'0') => 1,