Bug Fixing : Browse shelves not displaying results
[koha.git] / serials / subscription-add.pl
index 9d3f1c6..57902ca 100755 (executable)
@@ -43,12 +43,17 @@ my ($subscriptionid,$auser,$branchcode,$librarian,$cost,$aqbooksellerid, $aqbook
        $bibliotitle, $callnumber, $notes, $hemisphere, $letter, $manualhistory,$serialsadditems);
 
        my @budgets;
+
+# Permission needed if it is a modification : edit_subscription
+# Permission needed otherwise (nothing or dup) : create_subscription
+my $permission = ($op eq "mod") ? "edit_subscription" : "create_subscription";
+
 my ($template, $loggedinuser, $cookie)
 = get_template_and_user({template_name => "serials/subscription-add.tmpl",
                                query => $query,
                                type => "intranet",
                                authnotrequired => 0,
-                               flagsrequired => {serials => 1},
+                               flagsrequired => {serials => $permission},
                                debug => 1,
                                });
 
@@ -57,7 +62,7 @@ my ($template, $loggedinuser, $cookie)
 my $sub_on;
 my @subscription_types = (
             'issues', 'weeks', 'months'
-        ); 
+        );
 my @sub_type_data;
 
 my $letters = GetLetters('serial');
@@ -85,14 +90,14 @@ if ($op eq 'mod' || $op eq 'dup' || $op eq 'modsubscription') {
     if ($subs->{'cannotedit'} && $op eq 'mod'){
       warn "Attempt to modify subscription $subscriptionid by ".C4::Context->userenv->{'id'}." not allowed";
       print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
-    } 
+    }
     $firstissuedate = $subs->{firstacquidate};  # in iso format.
     for (qw(startdate firstacquidate histstartdate enddate histenddate)) {
        # TODO : Handle date formats properly.
          if ($subs->{$_} eq '0000-00-00') {
             $subs->{$_} = ''
        } else {
-            $subs->{$_} = format_date($subs->{$_});  
+            $subs->{$_} = format_date($subs->{$_});
         }
          }
     $subs->{'letter'}='' unless($subs->{'letter'});
@@ -109,7 +114,7 @@ if ($op eq 'mod' || $op eq 'dup' || $op eq 'modsubscription') {
                                last;
                        }
                }
-    
+
         $template->param($subs);
         $template->param(
                     $op => 1,
@@ -124,9 +129,9 @@ if ($op eq 'mod' || $op eq 'dup' || $op eq 'modsubscription') {
     }
 }
 
-my $onlymine=C4::Context->preference('IndependantBranches') && 
-             C4::Context->userenv && 
-             C4::Context->userenv->{flags}!=1 && 
+my $onlymine=C4::Context->preference('IndependantBranches') &&
+             C4::Context->userenv &&
+             C4::Context->userenv->{flags} % 2 !=1 &&
              C4::Context->userenv->{branch};
 my $branches = GetBranches($onlymine);
 my @branchloop;
@@ -280,7 +285,7 @@ if ($op eq 'addsubscription') {
         # if we have not received any issues yet, then we also must change the firstacquidate for the subs.
         $firstissuedate = $nextacquidate if($nextexpected->{isfirstissue});
     }
-    
+
     if ($history_only) {
         ModSubscriptionHistory ($subscriptionid,$histstartdate,$histenddate,$recievedlist,$missinglist,$opacnote,$librariannote);
     } else {
@@ -310,7 +315,7 @@ if ($op eq 'addsubscription') {
             $row{'selected'} = '';
            }
            push( @sub_type_data, \%row );
-        }    
+        }
     $template->param(subtype => \@sub_type_data,
        );
 
@@ -324,3 +329,19 @@ if ($op eq 'addsubscription') {
     }
        output_html_with_http_headers $query, $cookie, $template->output;
 }
+
+sub letter_loop {
+    my ($selected_letter, $template) = @_;
+    my $letters = GetLetters('serial');
+    my @letterloop;
+    foreach my $thisletter (keys %$letters) {
+        my $selected = $thisletter eq $selected_letter ? 1 : 0;
+        push @letterloop, {
+            value => $thisletter,
+            selected => $selected,
+            lettername => $letters->{$thisletter},
+        };
+    }
+    $template->param(letterloop => \@letterloop) if @letterloop;
+    return;
+}