| Lines 785-805
          elsif ($phase eq 'Run this report'){
      
      
        Link Here | 
        
          | 785 |                             'reports'      => $report_id, | 785 |                             'reports'      => $report_id, | 
        
          | 786 |                             ); | 786 |                             ); | 
        
          | 787 |         } else { | 787 |         } else { | 
          
            
              | 788 |             # OK, we have parameters, or there are none, we run the report | 788 |             my $sql = get_prepped_report( $sql, @sql_params ); | 
            
              | 789 |             # if there were parameters, replace before running |  |  | 
            
              | 790 |             # split on ??. Each odd (2,4,6,...) entry should be a parameter to fill | 
            
              | 791 |             my @split = split /<<|>>/,$sql; | 
            
              | 792 |             my @tmpl_parameters; | 
            
              | 793 |             for(my $i=0;$i<$#split/2;$i++) { | 
            
              | 794 |                 my $quoted = $sql_params[$i]; | 
            
              | 795 |                 # if there are special regexp chars, we must \ them | 
            
              | 796 |                 $split[$i*2+1] =~ s/(\||\?|\.|\*|\(|\)|\%)/\\$1/g; | 
            
              | 797 |                 if ($split[$i*2+1] =~ /\|\s*date\s*$/) { | 
            
              | 798 |                     $quoted = output_pref({ dt => dt_from_string($quoted), dateformat => 'iso', dateonly => 1 }) if $quoted; | 
            
              | 799 |                 } | 
            
              | 800 |                 $quoted = C4::Context->dbh->quote($quoted); | 
            
              | 801 |                 $sql =~ s/<<$split[$i*2+1]>>/$quoted/; | 
            
              | 802 |             } | 
        
          | 803 |             my ( $sth, $errors ) = execute_query( $sql, $offset, $limit, undef, $report_id ); | 789 |             my ( $sth, $errors ) = execute_query( $sql, $offset, $limit, undef, $report_id ); | 
        
          | 804 |             my $total = nb_rows($sql) || 0; | 790 |             my $total = nb_rows($sql) || 0; | 
        
          | 805 |             unless ($sth) { | 791 |             unless ($sth) { | 
  
    | Lines 841-850
          elsif ($phase eq 'Run this report'){
      
      
        Link Here | 
        
          | 841 | elsif ($phase eq 'Export'){ | 827 | elsif ($phase eq 'Export'){ | 
        
          | 842 |  | 828 |  | 
        
          | 843 | 	# export results to tab separated text or CSV | 829 | 	# export results to tab separated text or CSV | 
          
            
              | 844 | 	my $sql    = $input->param('sql');  # FIXME: use sql from saved report ID#, not new user-supplied SQL! | 830 |     my $report_id      = $input->param('report_id'); | 
            
              | 845 |     my $format = $input->param('format'); | 831 |     my $report         = get_saved_report($report_id); | 
            
              | 846 |     my $reportname = $input->param('reportname'); | 832 |     my $sql            = $report->{savedsql}; | 
            
              |  |  | 833 |     my @sql_params     = $input->multi_param('sql_params'); | 
            
              | 834 |     my $format         = $input->param('format'); | 
            
              | 835 |     my $reportname     = $input->param('reportname'); | 
        
          | 847 |     my $reportfilename = $reportname ? "$reportname-reportresults.$format" : "reportresults.$format" ; | 836 |     my $reportfilename = $reportname ? "$reportname-reportresults.$format" : "reportresults.$format" ; | 
            
              |  |  | 837 |  | 
            
              | 838 |     $sql = get_prepped_report( $sql, @sql_params ); | 
        
          | 848 | 	my ($sth, $q_errors) = execute_query($sql); | 839 | 	my ($sth, $q_errors) = execute_query($sql); | 
        
          | 849 |     unless ($q_errors and @$q_errors) { | 840 |     unless ($q_errors and @$q_errors) { | 
        
          | 850 |         my ( $type, $content ); | 841 |         my ( $type, $content ); | 
  
    | Lines 1053-1055
          sub create_non_existing_group_and_subgroup {
      
      
        Link Here | 
        
          | 1053 |         } | 1044 |         } | 
        
          | 1054 |     } | 1045 |     } | 
        
          | 1055 | } | 1046 | } | 
          
            
              | 1056 | -  | 1047 |  | 
            
              |  |  | 1048 | # pass $sth and sql_params, get back an executable query | 
            
              | 1049 | sub get_prepped_report { | 
            
              | 1050 |     my ($sql, @sql_params ) = @_; | 
            
              | 1051 |     my @split = split /<<|>>/,$sql; | 
            
              | 1052 |     for(my $i=0;$i<$#split/2;$i++) { | 
            
              | 1053 |         my $quoted = $sql_params[$i]; | 
            
              | 1054 |         # if there are special regexp chars, we must \ them | 
            
              | 1055 |         $split[$i*2+1] =~ s/(\||\?|\.|\*|\(|\)|\%)/\\$1/g; | 
            
              | 1056 |         if ($split[$i*2+1] =~ /\|\s*date\s*$/) { | 
            
              | 1057 |             $quoted = output_pref({ dt => dt_from_string($quoted), dateformat => 'iso', dateonly => 1 }) if $quoted; | 
            
              | 1058 |         } | 
            
              | 1059 |         $quoted = C4::Context->dbh->quote($quoted); | 
            
              | 1060 |         $sql =~ s/<<$split[$i*2+1]>>/$quoted/; | 
            
              | 1061 |     } | 
            
              | 1062 |     return $sql; | 
            
              | 1063 | } |