Bug 5698: Add date picker option to SQL Runtime Parameters
[koha.git] / reports / guided_reports.pl
index 40983fd..ce9370a 100755 (executable)
@@ -21,6 +21,7 @@ use strict;
 #use warnings; FIXME - Bug 2505
 use CGI;
 use Text::CSV;
+use URI::Escape;
 use C4::Reports::Guided;
 use C4::Auth qw/:DEFAULT get_session/;
 use C4::Output;
@@ -419,7 +420,21 @@ elsif ($phase eq 'Run this report'){
         for(my $i=0;$i<($#split/2);$i++) {
             my ($text,$authorised_value) = split /\|/,$split[$i*2+1];
             my $input;
-            if ($authorised_value) {
+            if ($authorised_value eq "date") {
+               $input = qq(<input id="date_$text" type="text" value="" size="10" name="sql_params">
+                         <img id="date_picker_$text" alt="Show Calendar" src="/intranet-tmpl/prog/en/lib/calendar/cal.gif">
+                         <script type="text/javascript">
+                              Calendar.setup(
+                              {
+                                 inputField : "date_$text",
+                                 ifFormat : "%Y-%m-%d",
+                                 button : "date_picker_$text"
+                              }
+                              );
+                         </script>
+                         );
+            }
+            elsif ($authorised_value) {
                 my $dbh=C4::Context->dbh;
                 my @authorised_values;
                 my %authorised_lib;
@@ -521,6 +536,9 @@ elsif ($phase eq 'Run this report'){
 
         my $totpages = int($total/$limit) + (($total % $limit) > 0 ? 1 : 0);
         my $url = "/cgi-bin/koha/reports/guided_reports.pl?reports=$report&amp;phase=Run%20this%20report";
+        if (@sql_params) {
+            $url = join('&amp;sql_params=', $url, map { URI::Escape::uri_escape($_) } @sql_params);
+        }
         $template->param(
             'results' => \@rows,
             'sql'     => $sql,
@@ -535,7 +553,7 @@ elsif ($phase eq 'Run this report'){
 }
 
 elsif ($phase eq 'Export'){
-    binmode STDOUT, ':utf8';
+    binmode STDOUT, ':encoding(UTF-8)';
 
        # export results to tab separated text or CSV
        my $sql    = $input->param('sql');  # FIXME: use sql from saved report ID#, not new user-supplied SQL!