MT 1816: Granular permissions for the serials module
[koha.git] / reports / bor_issues_top.pl
index 7761366..bb17d0a 100755 (executable)
@@ -26,6 +26,7 @@ use C4::Branch; # GetBranches
 use C4::Koha;
 use C4::Circulation;
 use C4::Members;
+use C4::Reports;
 use C4::Debug;
 use C4::Dates qw(format_date format_date_in_iso);
 
@@ -54,7 +55,6 @@ foreach ( @filters[0..3] ) {
 my $output   = $input->param("output");
 my $basename = $input->param("basename");
 # my $mime     = $input->param("MIME");
-my $del      = $input->param("sep");
 my ($template, $borrowernumber, $cookie)
     = get_template_and_user({template_name => $fullreportname,
                 query => $input,
@@ -63,6 +63,8 @@ my ($template, $borrowernumber, $cookie)
                 flagsrequired => {reports => 1},
                 debug => 1,
                 });
+our $sep     = $input->param("sep");
+$sep = "\t" if ($sep eq 'tabulation');
 $template->param(do_it => $do_it,
         DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
         );
@@ -81,8 +83,6 @@ if ($do_it) {
                             -filename=>"$basename.csv" );
         my $cols  = @$results[0]->{loopcol};
         my $lines = @$results[0]->{looprow};
-        my $sep;
-        $sep =C4::Context->preference("delimiter");
 # header top-right
         print @$results[0]->{line} ."/". @$results[0]->{column} .$sep;
 # Other header
@@ -109,8 +109,8 @@ my $dbh = C4::Context->dbh;
 my @values;
 
 # here each element returned by map is a hashref, get it?
-my @mime  = ( map { +{type =>$_} } (split /[;:]/,C4::Context->preference("MIME")) );
-my @delim = ( map { +{delim=>$_} } (split //,C4::Context->preference("delimiter")) );
+my @mime  = ( map { {type =>$_} } (split /[;:]/,C4::Context->preference("MIME")) );
+my $delims = GetDelimiterChoices;
 my $branches = GetBranches;
 my @branchloop;
 foreach (sort keys %$branches) {
@@ -142,7 +142,7 @@ foreach (sort keys %$labels) {
     
 $template->param(
            mimeloop => \@mime,
-            seploop => \@delim,
+         CGIseplist => $delims,
          branchloop => \@branchloop,
        itemtypeloop => \@itemtypeloop,
          borcatloop => \@borcatloop,
@@ -264,7 +264,7 @@ sub calculate {
         print DEBUG "rows: ", $sth2->rows, "\n";
         while (my @row = $sth2->fetchrow) {
                        $columns{($row[0] ||'NULL')}++;
-            push @loopcol, +{ coltitle => $row[0] || 'NULL' };
+            push @loopcol, { coltitle => $row[0] || 'NULL' };
         }
 
                $strsth2 =~ s/old_issues/issues/g;
@@ -274,9 +274,11 @@ sub calculate {
         $debug and print DEBUG "rows: ", $sth2->rows, "\n";
         while (my @row = $sth2->fetchrow) {
                        $columns{($row[0] ||'NULL')}++;
-            push @loopcol, +{ coltitle => $row[0] || 'NULL' };
+            push @loopcol, { coltitle => $row[0] || 'NULL' };
         }
                $debug and print DEBUG "full array: ", Dumper(\%columns), "\n";
+    }else{
+        $columns{''} = 1;
     }
 
     #Initialization of cell values.....
@@ -340,7 +342,7 @@ sub calculate {
        #       )
     while (my @data = $dbcalc->fetchrow) {
         my ($row, $rank, $id, $col) = @data;
-        $col = "zzEMPTY" if ($col eq undef);
+        $col = "zzEMPTY" if (!defined($col));
                unless ($patrons{$id}) {
                        $patrons{$id} = {name=>$row, allcols=>{}, newcols=>{}, oldcols=>{}};
                }
@@ -356,7 +358,7 @@ sub calculate {
     $debug and print DEBUG "rows: ", $dbcalc->rows, "\n";
     while (my @data = $dbcalc->fetchrow) {
         my ($row, $rank, $id, $col) = @data;
-        $col = "zzEMPTY" if ($col eq undef);
+        $col = "zzEMPTY" if (!defined($col));
                unless ($patrons{$id}) {
                        $patrons{$id} = {name=>$row, allcols=>{}, newcols=>{}, oldcols=>{}};
                }
@@ -383,11 +385,19 @@ sub calculate {
     foreach my $id (@ranked_ids) {
         my @loopcell;
         foreach my $key (@cols_in_order) {
-            push @loopcell, {
+                       if($column){
+                     push @loopcell, {
                                value => $patrons{$id}->{name},
+                               reference => $id,
                                count => $patrons{$id}->{allcols}->{$key},
+                         };
+                       }else{
+                         push @loopcell, {
+                               value => $patrons{$id}->{name},
                                reference => $id,
-                       };
+                               count => $patrons{$id}->{total},
+                         };  
+                       }
         }
         push @looprow,{ 'rowtitle' => $i++ ,
                         'loopcell' => \@loopcell,
@@ -399,7 +409,7 @@ sub calculate {
     $globalline{loopfilter}=\@loopfilter;
     # the core of the table
     $globalline{looprow} = \@looprow;
-    $globalline{loopcol} = [ map {+{coltitle=>$_}} @cols_in_order ];
+    $globalline{loopcol} = [ map {{coltitle=>$_}} @cols_in_order ];
        # the foot (totals by borrower type)
     $globalline{loopfooter} = [];
     $globalline{total}= $grantotal;            # FIXME: useless