Problem with error message
[koha.git] / serials / routing.pl
index c612a78..1b3da2d 100755 (executable)
@@ -26,10 +26,11 @@ printed out
 =cut
 
 use strict;
+use warnings;
 use CGI;
 use C4::Koha;
 use C4::Auth;
-use C4::Date;
+use C4::Dates;
 use C4::Output;
 use C4::Acquisition;
 use C4::Output;
@@ -38,13 +39,15 @@ use C4::Context;
 use C4::Members;
 use C4::Serials;
 
+use URI::Escape;
+
 my $query = new CGI;
 my $subscriptionid = $query->param('subscriptionid');
 my $serialseq = $query->param('serialseq');
 my $routingid = $query->param('routingid');
 my $borrowernumber = $query->param('borrowernumber');
 my $notes = $query->param('notes');
-my $op = $query->param('op');
+my $op = $query->param('op') || q{};
 my $date_selected = $query->param('date_selected');
 my $dbh = C4::Context->dbh;
 
@@ -58,9 +61,10 @@ if($op eq 'add'){
 if($op eq 'save'){
     my $sth = $dbh->prepare("UPDATE serial SET routingnotes = ? WHERE subscriptionid = ?");
     $sth->execute($notes,$subscriptionid);
-    print $query->redirect("routing-preview.pl?subscriptionid=$subscriptionid&issue=$date_selected");
+    my $urldate = URI::Escape::uri_escape($date_selected);
+    print $query->redirect("routing-preview.pl?subscriptionid=$subscriptionid&issue=$urldate");
 }
-    
+
 my ($routing, @routinglist) = getroutinglist($subscriptionid);
 my $subs = GetSubscription($subscriptionid);
 my ($count,@serials) = GetSerials($subscriptionid);
@@ -85,7 +89,7 @@ my ($template, $loggedinuser, $cookie)
                                query => $query,
                                type => "intranet",
                                authnotrequired => 0,
-                               flagsrequired => {serials => 1},
+                               flagsrequired => {serials => 'routing'},
                                debug => 1,
                                });
 # my $date;
@@ -101,26 +105,38 @@ my ($template, $loggedinuser, $cookie)
 # }
 
 # my $issue = "$serialseq ($date)";
-  
+
 my @results;
 my $data;
 for(my $i=0;$i<$routing;$i++){
     $data=GetMember($routinglist[$i]->{'borrowernumber'},'borrowernumber');
-    $data->{'location'}=$data->{'streetaddress'};
-    $data->{'name'}="$data->{'firstname'} $data->{'surname'}";
+    $data->{'location'}=$data->{'branchcode'};
+    if ($data->{firstname} ) {
+        $data->{name} = $data->{firstname} . q| |;
+    }
+    else {
+        $data->{name} = q{};
+    }
+    if ($data->{surname} ) {
+        $data->{name} .= $data->{surname};
+    }
     $data->{'routingid'}=$routinglist[$i]->{'routingid'};
     $data->{'subscriptionid'}=$subscriptionid;
-    my $rankingbox = '<select name="itemrank" onchange="reorder_item('.$subscriptionid.','.$routinglist[$i]->{'routingid'}.',this.options[this.selectedIndex].value)">';
+    if (! $routinglist[$i]->{routingid} ) {
+        $routinglist[$i]->{routingid} = q||;
+    }
+    my $rankingbox = '<select name="itemrank" onchange="reorder_item('
+    . $subscriptionid . ',' .$routinglist[$i]->{'routingid'} . ',this.options[this.selectedIndex].value)">';
     for(my $j=1; $j <= $routing; $j++) {
        $rankingbox .= "<option ";
-       if($routinglist[$i]->{'ranking'} == $j){
+       if($routinglist[$i]->{ranking} && $routinglist[$i]->{ranking} == $j){
            $rankingbox .= " selected=\"selected\"";
        }
        $rankingbox .= " value=\"$j\">$j</option>";
     }
     $rankingbox .= "</select>";
     $data->{'routingbox'} = $rankingbox;
-    
+
     push(@results, $data);
 }
 
@@ -130,13 +146,13 @@ if ($op eq 'new') {
     $new = 1;
 } else {
 # for modify routing list default
-    $new => 0;
+    $new = 0;
 }
 
 $template->param(
     title => $subs->{'bibliotitle'},
     subscriptionid => $subscriptionid,
-    memberloop => \@results,    
+    memberloop => \@results,
     op => $new,
     dates => \@dates,
     routingnotes => $serials[0]->{'routingnotes'},