| 
      
            Lines 21-26
          
      
      
        Link Here
      
     | 
  
        
          | 21 | 
          use CGI qw/-utf8/;  | 
          21 | 
          use CGI qw/-utf8/;  | 
        
        
          | 22 | 
          use Text::CSV;  | 
          22 | 
          use Text::CSV;  | 
        
        
          | 23 | 
          use URI::Escape;  | 
          23 | 
          use URI::Escape;  | 
        
            
               | 
               | 
              24 | 
              use File::Temp;  | 
            
        
          | 24 | 
          use C4::Reports::Guided;  | 
          25 | 
          use C4::Reports::Guided;  | 
        
        
          | 25 | 
          use C4::Auth qw/:DEFAULT get_session/;  | 
          26 | 
          use C4::Auth qw/:DEFAULT get_session/;  | 
        
        
          | 26 | 
          use C4::Output;  | 
          27 | 
          use C4::Output;  | 
        
  
    | 
      
            Lines 761-766
          elsif ($phase eq 'Run this report'){
      
      
        Link Here
      
     | 
  
        
          | 761 | 
              else { | 
          762 | 
              else { | 
        
        
          | 762 | 
                  push @errors, { no_sql_for_id => $report_id }; | 
          763 | 
                  push @errors, { no_sql_for_id => $report_id }; | 
        
        
          | 763 | 
              }  | 
          764 | 
              }  | 
        
            
               | 
               | 
              765 | 
                  my $csv2ods_cmd = qx|which csv2ods|;  | 
            
            
              | 766 | 
                  chomp $csv2ods_cmd;  | 
            
            
              | 767 | 
                  my $csv2ods_is_installed =  | 
            
            
              | 768 | 
                      ( not $csv2ods_cmd or not -f $csv2ods_cmd )  | 
            
            
              | 769 | 
                          ? 0  | 
            
            
              | 770 | 
                          : 1;  | 
            
            
              | 771 | 
                  $template->param( csv2ods_is_installed => $csv2ods_is_installed );  | 
            
        
          | 764 | 
          }  | 
          772 | 
          }  | 
        
        
          | 765 | 
           | 
          773 | 
           | 
        
        
          | 766 | 
          elsif ($phase eq 'Export'){ | 
          774 | 
          elsif ($phase eq 'Export'){ | 
        
  
    | 
      
            Lines 780-799
          elsif ($phase eq 'Export'){
      
      
        Link Here
      
     | 
  
        
          | 780 | 
                          print join("\t", @$row), "\n"; | 
          788 | 
                          print join("\t", @$row), "\n"; | 
        
        
          | 781 | 
                      }  | 
          789 | 
                      }  | 
        
        
          | 782 | 
                  } else { | 
          790 | 
                  } else { | 
        
          
            
              | 783 | 
                          my $csv = Text::CSV->new({binary => 1}); | 
              791 | 
                          my $delimiter = C4::Context->preference('delimiter') || ','; | 
            
            
               | 
               | 
              792 | 
                          my $csv_content = q||;  | 
            
            
              | 793 | 
                          my $csv = Text::CSV->new({binary => 1, sep_char => $delimiter}); | 
            
        
          | 784 | 
                      $csv or die "Text::CSV->new({binary => 1}) FAILED: " . Text::CSV->error_diag(); | 
          794 | 
                      $csv or die "Text::CSV->new({binary => 1}) FAILED: " . Text::CSV->error_diag(); | 
        
        
          | 785 | 
                      if ($csv->combine(header_cell_values($sth))) { | 
          795 | 
                      if ($csv->combine(header_cell_values($sth))) { | 
        
          
            
              | 786 | 
                              print $csv->string(), "\n";  | 
              796 | 
                              $csv_content .= $csv->string(). "\n";  | 
            
        
          | 787 | 
                      } else { | 
          797 | 
                      } else { | 
        
        
          | 788 | 
                          push @$q_errors, { combine => 'HEADER ROW: ' . $csv->error_diag() } ; | 
          798 | 
                          push @$q_errors, { combine => 'HEADER ROW: ' . $csv->error_diag() } ; | 
        
        
          | 789 | 
                      }  | 
          799 | 
                      }  | 
        
        
          | 790 | 
                      while (my $row = $sth->fetchrow_arrayref()) { | 
          800 | 
                      while (my $row = $sth->fetchrow_arrayref()) { | 
        
        
          | 791 | 
                          if ($csv->combine(@$row)) { | 
          801 | 
                          if ($csv->combine(@$row)) { | 
        
          
            
              | 792 | 
                                  print $csv->string(), "\n";   | 
              802 | 
                                  $csv_content .= $csv->string(). "\n";  | 
            
        
          | 793 | 
                          } else { | 
          803 | 
                          } else { | 
        
        
          | 794 | 
                              push @$q_errors, { combine => $csv->error_diag() } ; | 
          804 | 
                              push @$q_errors, { combine => $csv->error_diag() } ; | 
        
        
          | 795 | 
                          }  | 
          805 | 
                          }  | 
        
        
          | 796 | 
                      }  | 
          806 | 
                      }  | 
        
            
               | 
               | 
              807 | 
                          if ( $format eq 'csv' ) { | 
            
            
              | 808 | 
                              print $csv_content;  | 
            
            
              | 809 | 
                          }  | 
            
            
              | 810 | 
                          elsif ( $format eq 'ods' ) { | 
            
            
              | 811 | 
                              my $csv_fh = File::Temp->new();  | 
            
            
              | 812 | 
                              my $ods_fh = File::Temp->new();  | 
            
            
              | 813 | 
                              print $csv_fh $csv_content;  | 
            
            
              | 814 | 
                              my $csv_filepath = $csv_fh->filename;  | 
            
            
              | 815 | 
                              my $ods_filepath = $ods_fh->filename;  | 
            
            
              | 816 | 
               | 
            
            
              | 817 | 
                              my $csv2ods_cmd = qx|which csv2ods|;  | 
            
            
              | 818 | 
                              chomp $csv2ods_cmd;  | 
            
            
              | 819 | 
                              qx|  | 
            
            
              | 820 | 
                                  $csv2ods_cmd -i $csv_filepath -o $ods_filepath -d '$delimiter'  | 
            
            
              | 821 | 
                              |;  | 
            
            
              | 822 | 
                              qx|cp $ods_filepath /tmp/pouet.ods|;  | 
            
            
              | 823 | 
                              qx|cp $csv_filepath /tmp/pouet.csv|;  | 
            
            
              | 824 | 
                              print $_ while <$ods_fh>;  | 
            
            
              | 825 | 
                              close $csv_fh;  | 
            
            
              | 826 | 
                          }  | 
            
        
          | 797 | 
                  }  | 
          827 | 
                  }  | 
        
        
          | 798 | 
                  foreach my $err (@$q_errors, @errors) { | 
          828 | 
                  foreach my $err (@$q_errors, @errors) { | 
        
        
          | 799 | 
                      print "# ERROR: " . (map {$_ . ": " . $err->{$_}} keys %$err) . "\n"; | 
          829 | 
                      print "# ERROR: " . (map {$_ . ": " . $err->{$_}} keys %$err) . "\n"; | 
        
            
              | 800 | 
              -   | 
               | 
               |