FIX for Date calculation
authorpaul <paul@localhost.(none)>
Thu, 4 Oct 2007 05:16:39 +0000 (07:16 +0200)
committerJoshua Ferraro <jmf@liblime.com>
Thu, 11 Oct 2007 16:51:12 +0000 (11:51 -0500)
Rule :
- always format_date() before sending date to template
- always format_date_in_iso immediatly after reading a date coming from a parameter
- deal internally only with dates in iso

Note that :
- I could not test things related to issues stats due to the my DB -issues.issuedate not filled, see commit about 3.00.00.006
- acquisitions_stats does not work when you filter on date

Signed-off-by: Joshua Ferraro <jmf@liblime.com>
31 files changed:
C4/NewsChannels.pm
C4/Serials.pm
acqui/histsearch.pl
circ/pendingreserves.pl
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tmpl
koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tmpl
koha-tmpl/intranet-tmpl/prog/en/modules/labels/search.tmpl
koha-tmpl/intranet-tmpl/prog/en/modules/reports/acquisitions_stats.tmpl
koha-tmpl/intranet-tmpl/prog/en/modules/reports/bor_issues_top.tmpl
koha-tmpl/intranet-tmpl/prog/en/modules/reports/borrowers_out.tmpl
koha-tmpl/intranet-tmpl/prog/en/modules/reports/borrowers_stats.tmpl
koha-tmpl/intranet-tmpl/prog/en/modules/reports/cat_issues_top.tmpl
koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_avg_stats.tmpl
koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_stats.tmpl
koha-tmpl/intranet-tmpl/prog/en/modules/serials/checkexpiration.tmpl
koha-tmpl/intranet-tmpl/prog/en/modules/tools/cleanborrowers.tmpl
koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tmpl
koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tmpl
koha-tmpl/intranet-tmpl/prog/fr/modules/labels/search.tmpl
labels/label-item-search.pl
reports/acquisitions_stats.pl
reports/bor_issues_top.pl
reports/borrowers_out.pl
reports/borrowers_stats.pl
reports/cat_issues_top.pl
reports/issues_avg_stats.pl
reports/issues_stats.pl
serials/checkexpiration.pl
tools/cleanborrowers.pl
tools/koha-news.pl
tools/viewlog.pl

index 0d8f458..ea361fd 100644 (file)
@@ -45,7 +45,7 @@ This module provides the functions needed to admin the news channels and its cat
 \r
 \r
 @ISA = qw(Exporter);\r
-@EXPORT = qw(
+@EXPORT = qw(\r
   &GetNewsToDisplay\r
   &news_channels &get_new_channel &del_channels &add_channel &update_channel\r
   &news_channels_categories &get_new_channel_category &del_channels_categories\r
@@ -240,7 +240,7 @@ sub update_channel_category {
 }\r
 \r
 sub add_opac_new {\r
-    my ($title, $new, $lang, $expirationdate, $number) = @_;
+    my ($title, $new, $lang, $expirationdate, $number) = @_;\r
     my $dbh = C4::Context->dbh;\r
     my $sth = $dbh->prepare("INSERT INTO opac_news (title, new, lang, expirationdate, number) VALUES (?,?,?,?,?)");\r
     $sth->execute($title, $new, $lang, $expirationdate, $number);\r
@@ -251,14 +251,14 @@ sub add_opac_new {
 sub upd_opac_new {\r
     my ($idnew, $title, $new, $lang, $expirationdate, $number) = @_;\r
     my $dbh = C4::Context->dbh;\r
-    my $sth = $dbh->prepare("
-        UPDATE opac_news SET 
-            title = ?,
-            new = ?,
-            lang = ?,
-            expirationdate = ?,
-            number = ?
-        WHERE idnew = ?
+    my $sth = $dbh->prepare("\r
+        UPDATE opac_news SET \r
+            title = ?,\r
+            new = ?,\r
+            lang = ?,\r
+            expirationdate = ?,\r
+            number = ?\r
+        WHERE idnew = ?\r
     ");\r
     $sth->execute($title, $new, $lang, $expirationdate,$number,$idnew);\r
     $sth->finish;\r
@@ -285,6 +285,7 @@ sub get_opac_new {
     $sth->execute($idnew);\r
     my $data = $sth->fetchrow_hashref;\r
     $data->{$data->{'lang'}} = 1;\r
+    $data->{expirationdate} = format_date($data->{expirationdate});\r
     $sth->finish;\r
     return $data;\r
 }\r
@@ -292,7 +293,7 @@ sub get_opac_new {
 sub get_opac_news {\r
     my ($limit, $lang) = @_;\r
     my $dbh = C4::Context->dbh;\r
-    my $query = "SELECT *, DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate FROM opac_news";\r
+    my $query = "SELECT *, timestamp AS newdate FROM opac_news";\r
     if ($lang) {\r
         $query.= " WHERE lang = '" .$lang ."' ";\r
     }\r
@@ -307,43 +308,44 @@ sub get_opac_news {
     while (my $row = $sth->fetchrow_hashref) {\r
         if ((($limit) && ($count < $limit)) || (!$limit)) {\r
             $row->{'newdate'} = format_date($row->{'newdate'});\r
+            $row->{'expirationdate'} = format_date($row->{'expirationdate'});\r
             push @opac_news, $row;\r
         }\r
         $count++;\r
     }\r
     return ($count, \@opac_news);\r
 }\r
-
-=head2 GetNewsToDisplay
-    
-    $news = &GetNewsToDisplay($lang);
-    C<$news> is a ref to an array which containts
-    all news with expirationdate > today or expirationdate is null.
-    
-=cut
-
-sub GetNewsToDisplay {
-    my $lang = shift;
+\r
+=head2 GetNewsToDisplay\r
+    \r
+    $news = &GetNewsToDisplay($lang);\r
+    C<$news> is a ref to an array which containts\r
+    all news with expirationdate > today or expirationdate is null.\r
+    \r
+=cut\r
+\r
+sub GetNewsToDisplay {\r
+    my $lang = shift;\r
     my $dbh = C4::Context->dbh;\r
-    my $query = "
-     SELECT *,DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate
-     FROM   opac_news
-     WHERE   (
-        expirationdate > CURRENT_DATE()
-        OR    expirationdate IS NULL
-        OR    expirationdate = '00-00-0000'
-      )
-      AND   lang = ?
-      ORDER BY number
-    ";
-    my $sth = $dbh->prepare($query);
-    $sth->execute($lang);
-    my @results;
-    while ( my $row = $sth->fetchrow_hashref ){
-        push @results, $row;
-    }
-    return \@results;
-}
+    my $query = "\r
+     SELECT *,DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate\r
+     FROM   opac_news\r
+     WHERE   (\r
+        expirationdate > CURRENT_DATE()\r
+        OR    expirationdate IS NULL\r
+        OR    expirationdate = '00-00-0000'\r
+      )\r
+      AND   lang = ?\r
+      ORDER BY number\r
+    ";\r
+    my $sth = $dbh->prepare($query);\r
+    $sth->execute($lang);\r
+    my @results;\r
+    while ( my $row = $sth->fetchrow_hashref ){\r
+        push @results, $row;\r
+    }\r
+    return \@results;\r
+}\r
 \r
 ### get electronic databases\r
 \r
index 30b5deb..6c93e82 100644 (file)
@@ -1038,18 +1038,12 @@ sub GetExpirationDate {
     my $enddate          = $subscription->{startdate};
 
 # we don't do the same test if the subscription is based on X numbers or on X weeks/months
-#     warn "SUBSCRIPTIONID :$subscriptionid";
-#      use Data::Dumper; warn Dumper($subscription);
-
-#          warn "dateCHECKRESERV :".$subscription->{startdate};
     if ($subscription->{periodicity}){
       if ( $subscription->{numberlength} ) {
           #calculate the date of the last issue.
           my $length = $subscription->{numberlength};
-  #         warn "ENDDATE ".$enddate;
           for ( my $i = 1 ; $i <= $length ; $i++ ) {
               $enddate = GetNextDate( $enddate, $subscription );
-  #             warn "AFTER ENDDATE ".$enddate;
           }
       }
       elsif ( $subscription->{monthlength} ){
@@ -1058,20 +1052,9 @@ sub GetExpirationDate {
           $enddate=sprintf("%04d-%02d-%02d",$enddate[0],$enddate[1],$enddate[2]);
       } elsif ( $subscription->{weeklength} ){
           my @date=split (/-/,$subscription->{startdate});
-  #         warn "dateCHECKRESERV :".$subscription->{startdate};
-  #### An other way to do it
-  #         if ( $subscription->{weeklength} ){
-  #           my ($weeknb,$year)=Week_of_Year(@startdate);
-  #           $weeknb += $subscription->{weeklength};
-  #           my $weeknbcalc= $weeknb % 52;
-  #           $year += int($weeknb/52);
-  # #           warn "year : $year weeknb :$weeknb weeknbcalc $weeknbcalc";
-  #           @endofsubscriptiondate=Monday_of_Week($weeknbcalc,$year);
-  #         }
           my @enddate = Add_Delta_Days($date[0],$date[1],$date[2],$subscription->{weeklength}*7);
           $enddate=sprintf("%04d-%02d-%02d",$enddate[0],$enddate[1],$enddate[2]);
       }
-  #     warn "date de fin :$enddate";
       return $enddate;
     } else {
       return 0;  
index 6613415..1da1fc3 100755 (executable)
@@ -54,13 +54,14 @@ use CGI;
 use C4::Auth;    # get_template_and_user
 use C4::Output;
 use C4::Acquisition;
+use C4::Date;
 
 my $input          = new CGI;
 my $title          = $input->param('title');
 my $author         = $input->param('author');
 my $name           = $input->param('name');
 my $from_placed_on = $input->param('fromplacedon');
-my $to_placed_on   = $input->param('toplacedon');
+my $to_placed_on   = format_date_in_iso($input->param('toplacedon'));
 
 my $dbh = C4::Context->dbh;
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
@@ -92,6 +93,7 @@ $template->param(
       C4::Context->preference("intranetcolorstylesheet"),
     intranetstylesheet => C4::Context->preference("intranetstylesheet"),
     IntranetNav        => C4::Context->preference("IntranetNav"),
+    DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(),
 );
 
 output_html_with_http_headers $input, $cookie, $template->output;
index ac22390..3a7b720 100755 (executable)
@@ -29,7 +29,7 @@ use C4::Date;
 my $input = new CGI;
 my $order = $input->param('order');
 my $startdate=$input->param('from');
-my $enddate=$input->param('to');
+my $enddate=format_date_in_iso($input->param('to'));
 
 my $theme = $input->param('theme');    # only used if allowthemeoverride is set
 
@@ -146,15 +146,12 @@ while ( my $data = $sth->fetchrow_hashref ) {
 $sth->finish;
 
 $template->param(
-    todaysdate              => format_date($todaysdate),
-       from                        => $startdate,
-       to                                  => $enddate,
-    reserveloop             => \@reservedata,
-    intranetcolorstylesheet =>
-      C4::Context->preference("intranetcolorstylesheet"),
-    intranetstylesheet => C4::Context->preference("intranetstylesheet"),
-    IntranetNav        => C4::Context->preference("IntranetNav"),
+    todaysdate      => format_date($todaysdate),
+    fro             => $startdate,
+    to              => $enddate,
+    reserveloop     => \@reservedata,
     "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
+    DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(),
 );
 
 output_html_with_http_headers $input, $cookie, $template->output;
index b801f55..b1970bf 100644 (file)
@@ -59,7 +59,7 @@
                                                        Calendar.setup(
                                                                {
                                                                        inputField : "from",
-                                                                       ifFormat : "%Y-%m-%d",
+                                                                       ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                                                                        button : "openCalendarFrom",
                                                                        disableFunc : validate1,
                                                                        dateStatusFunc : validate1
@@ -88,7 +88,7 @@
                                                        Calendar.setup(
                                                                {
                                                                        inputField : "to",
-                                                                       ifFormat : "%Y-%m-%d",
+                                                                       ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                                                                        button : "openCalendarTo",
                                                                        disableFunc : validate2,
                                                                        dateStatusFunc : validate2
index 18fd11e..d60bdc4 100644 (file)
@@ -52,7 +52,7 @@ function validate1(date) {
 Calendar.setup(
         {
         inputField : "from",
-        ifFormat : "%Y-%m-%d",
+        ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
         button : "openCalendarFrom",
         disableFunc : validate1,
         dateStatusFunc : validate1
@@ -84,7 +84,7 @@ Calendar.setup(
         Calendar.setup(
                 {
                     inputField : "to",
-                    ifFormat : "%Y-%m-%d",
+                    ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                     button : "openCalendarTo",
                     disableFunc : validate2,
                     dateStatusFunc : validate2
index ec67198..382c26d 100644 (file)
@@ -80,7 +80,7 @@
 <script type="text/javascript">
     Calendar.setup({
         inputField     :    "datefrom",
-      ifFormat : "%Y-%m-%d",
+      ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
         button         :    "openCalendarFrom",
         align          :    "Tl",
         singleClick    :    false
 <script type="text/javascript">
     Calendar.setup({
         inputField     :    "dateto",
-      ifFormat : "%Y-%m-%d",
+      ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
         button         :    "openCalendarTo",
         align          :    "Tl",
     });
index e8f274c..07a93ae 100644 (file)
@@ -99,7 +99,7 @@
                                                                        Calendar.setup(
                                                                                {
                                                                                        inputField : "from",
-                                                                                       ifFormat : "%Y-%m-%d",
+                                                                                       ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                                                                                        button : "openCalendarFrom",
                                                                                        disableFunc : validate1,
                                                                                        dateStatusFunc : validate1
                                                                Calendar.setup(
                                                                        {
                                                                                inputField : "to",
-                                                                               ifFormat : "%Y-%m-%d",
+                                                                               ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                                                                                button : "openCalendarTo",
                                                                                disableFunc : validate2,
                                                                                dateStatusFunc : validate2
                                                                        Calendar.setup(
                                                                                {
                                                                                        inputField : "fromRO",
-                                                                                       ifFormat : "%Y-%m-%d",
+                                                                                       ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                                                                                        button : "openCalendarFromRO",
                                                                                        disableFunc : validate1,
                                                                                        dateStatusFunc : validate1
                                                                Calendar.setup(
                                                                        {
                                                                                inputField : "toRO",
-                                                                               ifFormat : "%Y-%m-%d",
+                                                                               ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                                                                                button : "openCalendarToRO",
                                                                                disableFunc : validate2,
                                                                                dateStatusFunc : validate2
index 2600709..7df9d58 100644 (file)
@@ -130,7 +130,7 @@ function Dopop(link) {
                                                                        Calendar.setup(
                                                                                {
                                                                                        inputField : "from",
-                                                                                       ifFormat : "%Y-%m-%d",
+                                                                                       ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                                                                                        button : "openCalendarFrom",
                                                                                        disableFunc : validate1,
                                                                                        dateStatusFunc : validate1
@@ -159,7 +159,7 @@ function Dopop(link) {
                                                                Calendar.setup(
                                                                        {
                                                                                inputField : "to",
-                                                                               ifFormat : "%Y-%m-%d",
+                                                                               ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                                                                                button : "openCalendarTo",
                                                                                disableFunc : validate2,
                                                                                dateStatusFunc : validate2
@@ -193,7 +193,7 @@ function Dopop(link) {
                                                                        Calendar.setup(
                                                                                {
                                                                                        inputField : "fromRO",
-                                                                                       ifFormat : "%Y-%m-%d",
+                                                                                       ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                                                                                        button : "openCalendarFromRO",
                                                                                        disableFunc : validate1,
                                                                                        dateStatusFunc : validate1
@@ -222,7 +222,7 @@ function Dopop(link) {
                                                                Calendar.setup(
                                                                        {
                                                                                inputField : "toRO",
-                                                                               ifFormat : "%Y-%m-%d",
+                                                                               ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                                                                                button : "openCalendarToRO",
                                                                                disableFunc : validate2,
                                                                                dateStatusFunc : validate2
index b7525cd..082dc08 100644 (file)
@@ -95,7 +95,7 @@
                                 Calendar.setup(
                                     {
                                         inputField : "to",
-                                        ifFormat : "%Y-%m-%d",
+                                        ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                                         button : "openCalendarTo",
                                     }
                                 );
index 476bb23..16d70d7 100644 (file)
                     Calendar.setup(
                         {
                             inputField : "from",
-                            ifFormat : "%Y-%m-%d",
+                            ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                             button : "openCalendarFrom",
                             disableFunc : validate1,
                             dateStatusFunc : validate1
                             Calendar.setup(
                                 {
                                     inputField : "to",
-                                    ifFormat : "%Y-%m-%d",
+                                    ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                                     button : "openCalendarTo",
                                     disableFunc : validate2,
                                     dateStatusFunc : validate2
index f679593..f2a237f 100644 (file)
@@ -133,7 +133,7 @@ function Dopop(link) {
                                                                        Calendar.setup(
                                                                                {
                                                                                        inputField : "from",
-                                                                                       ifFormat : "%Y-%m-%d",
+                                                                                       ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                                                                                        button : "openCalendarFrom",
                                                                                        disableFunc : validate1,
                                                                                        dateStatusFunc : validate1
@@ -162,7 +162,7 @@ function Dopop(link) {
                                                                Calendar.setup(
                                                                        {
                                                                                inputField : "to",
-                                                                               ifFormat : "%Y-%m-%d",
+                                                                               ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                                                                                button : "openCalendarTo",
                                                                                disableFunc : validate2,
                                                                                dateStatusFunc : validate2
@@ -196,7 +196,7 @@ function Dopop(link) {
                                                                        Calendar.setup(
                                                                                {
                                                                                        inputField : "fromRO",
-                                                                                       ifFormat : "%Y-%m-%d",
+                                                                                       ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                                                                                        button : "openCalendarFromRO",
                                                                                        disableFunc : validate1,
                                                                                        dateStatusFunc : validate1
@@ -225,7 +225,7 @@ function Dopop(link) {
                                                                Calendar.setup(
                                                                        {
                                                                                inputField : "toRO",
-                                                                               ifFormat : "%Y-%m-%d",
+                                                                               ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                                                                                button : "openCalendarToRO",
                                                                                disableFunc : validate2,
                                                                                dateStatusFunc : validate2
index ff99777..de76287 100644 (file)
@@ -97,7 +97,7 @@
                                                                        Calendar.setup(
                                                                                {
                                                                                        inputField : "from",
-                                                                                       ifFormat : "%Y-%m-%d",
+                                                                                       ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                                                                                        button : "openCalendarFrom",
                                                                                        disableFunc : validate1,
                                                                                        dateStatusFunc : validate1
                                                                Calendar.setup(
                                                                        {
                                                                                inputField : "to",
-                                                                               ifFormat : "%Y-%m-%d",
+                                                                               ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                                                                                button : "openCalendarTo",
                                                                                disableFunc : validate2,
                                                                                dateStatusFunc : validate2
                                                                        Calendar.setup(
                                                                                {
                                                                                        inputField : "fromRO",
-                                                                                       ifFormat : "%Y-%m-%d",
+                                                                                       ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                                                                                        button : "openCalendarFromRO",
                                                                                        disableFunc : validate1,
                                                                                        dateStatusFunc : validate1
                                                                Calendar.setup(
                                                                        {
                                                                                inputField : "toRO",
-                                                                               ifFormat : "%Y-%m-%d",
+                                                                               ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                                                                                button : "openCalendarToRO",
                                                                                disableFunc : validate2,
                                                                                dateStatusFunc : validate2
index dfdfa51..f31a061 100644 (file)
                     Calendar.setup(
                         {
                             inputField : "from",
-                            ifFormat : "%Y-%m-%d",
+                            ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                             button : "openCalendarFrom",
                             disableFunc : validate1,
                             dateStatusFunc : validate1
                             Calendar.setup(
                                 {
                                     inputField : "to",
-                                    ifFormat : "%Y-%m-%d",
+                                    ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                                     button : "openCalendarTo",
                                     disableFunc : validate2,
                                     dateStatusFunc : validate2
index f179179..1388595 100644 (file)
@@ -54,7 +54,7 @@
                 Calendar.setup(
                  {
                      inputField : "date",
-                     ifFormat : "%Y-%m-%d",
+                     ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                  }
                 );
             </script></p>
index b76b0b0..c146e8a 100644 (file)
@@ -64,7 +64,7 @@
                 Calendar.setup(
                  {
                      inputField : "date1",
-                     ifFormat : "%Y-%m-%d",
+                     ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                  }
                 );
             </script>
@@ -77,7 +77,7 @@
                 Calendar.setup(
                  {
                      inputField : "date2",
-                     ifFormat : "%Y-%m-%d",
+                     ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                  }
                 );
             </script>
index 5f6154a..5f40e7e 100644 (file)
@@ -42,7 +42,7 @@
                     Calendar.setup(
                     {
                         inputField : "expirationdate",
-                        ifFormat : "%Y-%m-%d",
+                        ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                     }
                     );
                 </script>
index 57bff5b..b5cdffe 100644 (file)
@@ -44,7 +44,7 @@
                                                                        Calendar.setup(
                                                                                {
                                                                                        inputField : "from",
-                                                                                       ifFormat : "%Y-%m-%d",
+                                                                                       ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                                                                                        button : "openCalendarFrom",
                                                                                        disableFunc : validate1,
                                                                                        dateStatusFunc : validate1
@@ -72,7 +72,7 @@
                                                Calendar.setup(
                                        {
                                                        inputField : "to",
-                                                       ifFormat : "%Y-%m-%d",
+                                                       ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
                                                        button : "openCalendarTo",
                                                        disableFunc : validate2,
                                                        dateStatusFunc : validate2
index 0684a32..e442f34 100644 (file)
@@ -80,7 +80,7 @@
 <script type="text/javascript">
     Calendar.setup({
         inputField     :    "datefrom",
-      ifFormat : "%Y-%m-%d",
+      ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
         button         :    "openCalendarFrom",
         align          :    "Tl",
         singleClick    :    false
index 45d87d4..d3c7816 100755 (executable)
@@ -249,14 +249,11 @@ else {
         batch_id     => $batch_id,
     );
 
-    # Print the page
-    $template->param(
-        intranetcolorstylesheet =>
-          C4::Context->preference("intranetcolorstylesheet"),
-        intranetstylesheet => C4::Context->preference("intranetstylesheet"),
-        IntranetNav        => C4::Context->preference("IntranetNav"),
-    );
 }
+# Print the page
+$template->param(
+    DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(),
+);
 output_html_with_http_headers $query, $cookie, $template->output;
 
 # Local Variables:
index b6d60d2..2c55ead 100755 (executable)
@@ -29,6 +29,7 @@ use C4::Context;
 use C4::Output;
 use C4::Koha;
 use C4::Circulation;
+use C4::Date;
 
 =head1 NAME
 
@@ -46,6 +47,10 @@ my $fullreportname = "reports/acquisitions_stats.tmpl";
 my $line           = $input->param("Line");
 my $column         = $input->param("Column");
 my @filters        = $input->param("Filter");
+$filters[0]=format_date_in_iso($filters[0]);
+$filters[1]=format_date_in_iso($filters[1]);
+$filters[2]=format_date_in_iso($filters[2]);
+$filters[3]=format_date_in_iso($filters[3]);
 my $podsp          = $input->param("PlacedOnDisplay");
 my $rodsp          = $input->param("ReceivedOnDisplay");
 my $aodsp          = $input->param("AcquiredOnDisplay");    ##added by mason.
@@ -65,9 +70,7 @@ my ($template, $borrowernumber, $cookie)
                                debug => 1,
                                });
 $template->param(do_it => $do_it,
-               intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
-               intranetstylesheet => C4::Context->preference("intranetstylesheet"),
-               IntranetNav => C4::Context->preference("IntranetNav"),
+        DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(),
                );
 if ($do_it) {
 
@@ -294,7 +297,12 @@ sub calculate {
             if ( ( ( $i == 1 ) or ( $i == 3 ) ) and ( @$filters[ $i - 1 ] ) ) {
                 $cell{err} = 1 if ( @$filters[$i] < @$filters[ $i - 1 ] );
             }
-            $cell{filter} .= @$filters[$i];
+            # format the dates filters, otherwise just fill as is
+            if ($i>=4) {
+                $cell{filter} .= @$filters[$i];
+            } else {
+                $cell{filter} .= format_date(@$filters[$i]);
+            }
             $cell{crit}   .= "Placed On From" if ( $i == 0 );
             $cell{crit}   .= "Placed On To" if ( $i == 1 );
             $cell{crit}   .= "Received On From" if ( $i == 2 );
index e784b4f..0f7dc0e 100755 (executable)
@@ -28,7 +28,7 @@ use C4::Branch; # GetBranches
 use C4::Koha;
 use C4::Circulation;
 use C4::Members;
-use Date::Manip;
+use C4::Date;
 
 =head1 NAME
 
@@ -46,140 +46,142 @@ my $fullreportname = "reports/bor_issues_top.tmpl";
 my $limit = $input->param("Limit");
 my $column = $input->param("Criteria");
 my @filters = $input->param("Filter");
+$filters[0]=format_date_in_iso($filters[0]);
+$filters[1]=format_date_in_iso($filters[1]);
+$filters[2]=format_date_in_iso($filters[2]);
+$filters[3]=format_date_in_iso($filters[3]);
 my $output = $input->param("output");
 my $basename = $input->param("basename");
 my $mime = $input->param("MIME");
 my $del = $input->param("sep");
 #warn "calcul : ".$calc;
 my ($template, $borrowernumber, $cookie)
-       = get_template_and_user({template_name => $fullreportname,
-                               query => $input,
-                               type => "intranet",
-                               authnotrequired => 0,
-                               flagsrequired => {reports => 1},
-                               debug => 1,
-                               });
+    = get_template_and_user({template_name => $fullreportname,
+                query => $input,
+                type => "intranet",
+                authnotrequired => 0,
+                flagsrequired => {reports => 1},
+                debug => 1,
+                });
 $template->param(do_it => $do_it,
-               intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
-               intranetstylesheet => C4::Context->preference("intranetstylesheet"),
-               IntranetNav => C4::Context->preference("IntranetNav"),
-               );
+        DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(),
+        );
 if ($do_it) {
 # Displaying results
-       my $results = calculate($limit, $column, \@filters);
-       if ($output eq "screen"){
+    my $results = calculate($limit, $column, \@filters);
+    if ($output eq "screen"){
 # Printing results to screen
-               $template->param(mainloop => $results, limit=>$limit);
-               output_html_with_http_headers $input, $cookie, $template->output;
-               exit(1);
-       } else {
+        $template->param(mainloop => $results, limit=>$limit);
+        output_html_with_http_headers $input, $cookie, $template->output;
+        exit(1);
+    } else {
 # Printing to a csv file
-               print $input->header(-type => 'application/vnd.sun.xml.calc',
-                                     -encoding    => 'utf-8',
-                       -attachment=>"$basename.csv",
-                       -filename=>"$basename.csv" );
-               my $cols = @$results[0]->{loopcol};
-               my $lines = @$results[0]->{looprow};
-               my $sep;
-               $sep =C4::Context->preference("delimiter");
+        print $input->header(-type => 'application/vnd.sun.xml.calc',
+                            -encoding    => 'utf-8',
+                            -attachment=>"$basename.csv",
+                            -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;
+        print @$results[0]->{line} ."/". @$results[0]->{column} .$sep;
 # Other header
-               foreach my $col ( @$cols ) {
-                       print $col->{coltitle}.$sep;
-               }
-               print "Total\n";
+        foreach my $col ( @$cols ) {
+            print $col->{coltitle}.$sep;
+        }
+        print "Total\n";
 # Table
-               foreach my $line ( @$lines ) {
-                       my $x = $line->{loopcell};
-                       print $line->{rowtitle}.$sep;
-                       foreach my $cell (@$x) {
-                               print $cell->{value}.$sep;
-                       }
-                       print $line->{totalrow};
-                       print "\n";
-               }
+        foreach my $line ( @$lines ) {
+            my $x = $line->{loopcell};
+            print $line->{rowtitle}.$sep;
+            foreach my $cell (@$x) {
+                print $cell->{value}.$sep;
+            }
+            print $line->{totalrow};
+            print "\n";
+        }
 # footer
-               print "TOTAL";
-               $cols = @$results[0]->{loopfooter};
-               foreach my $col ( @$cols ) {
-                       print $sep.$col->{totalcol};
-               }
-               print $sep.@$results[0]->{total};
-               exit(1);
-       }
+        print "TOTAL";
+        $cols = @$results[0]->{loopfooter};
+        foreach my $col ( @$cols ) {
+            print $sep.$col->{totalcol};
+        }
+        print $sep.@$results[0]->{total};
+        exit(1);
+    }
 # Displaying choices
 } else {
-       my $dbh = C4::Context->dbh;
-       my @values;
-       my %labels;
-       my %select;
-       my $req;
-       
-       my @mime = ( C4::Context->preference("MIME") );
+    my $dbh = C4::Context->dbh;
+    my @values;
+    my %labels;
+    my %select;
+    my $req;
+    
+    my @mime = ( C4::Context->preference("MIME") );
 #      foreach my $mime (@mime){
 #              warn "".$mime;
 #      }
-       
-       my $CGIextChoice=CGI::scrolling_list(
-                               -name     => 'MIME',
-                               -id       => 'MIME',
-                               -values   => \@mime,
-                               -size     => 1,
-                               -multiple => 0 );
-       
-       my @dels = ( C4::Context->preference("delimiter") );
-       my $CGIsepChoice=CGI::scrolling_list(
-                               -name     => 'sep',
-                               -id       => 'sep',
-                               -values   => \@dels,
-                               -size     => 1,
-                               -multiple => 0 );
-       #branch
-       my $branches = GetBranches;
-       my @branchloop;
-       foreach my $thisbranch (keys %$branches) {
+    
+    my $CGIextChoice=CGI::scrolling_list(
+                -name     => 'MIME',
+                -id       => 'MIME',
+                -values   => \@mime,
+                -size     => 1,
+                -multiple => 0 );
+    
+    my @dels = ( C4::Context->preference("delimiter") );
+    my $CGIsepChoice=CGI::scrolling_list(
+                -name     => 'sep',
+                -id       => 'sep',
+                -values   => \@dels,
+                -size     => 1,
+                -multiple => 0 );
+    #branch
+    my $branches = GetBranches;
+    my @branchloop;
+    foreach my $thisbranch (keys %$branches) {
 #                      my $selected = 1 if $thisbranch eq $branch;
-                       my %row =(value => $thisbranch,
+            my %row =(value => $thisbranch,
 #                                                                      selected => $selected,
-                                                                       branchname => $branches->{$thisbranch}->{'branchname'},
-                                                       );
-                       push @branchloop, \%row;
-       }
+                                    branchname => $branches->{$thisbranch}->{'branchname'},
+                            );
+            push @branchloop, \%row;
+    }
 
-       #doctype
-       my $itemtypes = GetItemTypes;
-       my @itemtypeloop;
-       foreach my $thisitemtype (keys %$itemtypes) {
+    #doctype
+    my $itemtypes = GetItemTypes;
+    my @itemtypeloop;
+    foreach my $thisitemtype (keys %$itemtypes) {
 #                      my $selected = 1 if $thisbranch eq $branch;
-                       my %row =(value => $thisitemtype,
+            my %row =(value => $thisitemtype,
 #                                                                      selected => $selected,
-                                                                       description => $itemtypes->{$thisitemtype}->{'description'},
-                                                       );
-                       push @itemtypeloop, \%row;
-       }
-       
-       #borcat
-       my ($codes,$labels) = GetborCatFromCatType(undef,undef);
-       my @borcatloop;
-       foreach my $thisborcat (sort keys %$labels) {
- #                     my $selected = 1 if $thisbranch eq $branch;
-                       my %row =(value => $thisborcat,
- #                                                                     selected => $selected,
-                                                                       description => $labels->{$thisborcat},
-                                                       );
-                       push @borcatloop, \%row;
-       }
-       
-       #Day
-       #Month
-       $template->param(
-                                       CGIextChoice => $CGIextChoice,
-                                       CGIsepChoice => $CGIsepChoice,
-                                       branchloop =>\@branchloop,
-                                       itemtypeloop =>\@itemtypeloop,
-                                       borcatloop =>\@borcatloop,
-                                       );
+                                    description => $itemtypes->{$thisitemtype}->{'description'},
+                            );
+            push @itemtypeloop, \%row;
+    }
+    
+    #borcat
+    my ($codes,$labels) = GetborCatFromCatType(undef,undef);
+    my @borcatloop;
+    foreach my $thisborcat (sort keys %$labels) {
+                     my $selected = 1 if $thisbranch eq $branch;
+            my %row =(value => $thisborcat,
+                                                                     selected => $selected,
+                                    description => $labels->{$thisborcat},
+                            );
+            push @borcatloop, \%row;
+    }
+    
+    #Day
+    #Month
+    $template->param(
+                    CGIextChoice => $CGIextChoice,
+                    CGIsepChoice => $CGIsepChoice,
+                    branchloop =>\@branchloop,
+                    itemtypeloop =>\@itemtypeloop,
+                    borcatloop =>\@borcatloop,
+                    );
 output_html_with_http_headers $input, $cookie, $template->output;
 }
 
@@ -187,229 +189,234 @@ output_html_with_http_headers $input, $cookie, $template->output;
 
 
 sub calculate {
-       my ($line, $column, $filters) = @_;
-       my @mainloop;
-       my @loopfooter;
-       my @loopcol;
-       my @loopline;
-       my @looprow;
-       my %globalline;
-       my $grantotal =0;
+    my ($line, $column, $filters) = @_;
+    my @mainloop;
+    my @loopfooter;
+    my @loopcol;
+    my @loopline;
+    my @looprow;
+    my %globalline;
+    my $grantotal =0;
 # extract parameters
-       my $dbh = C4::Context->dbh;
+    my $dbh = C4::Context->dbh;
 
 # Filters
 # Checking filters
 #
-       my @loopfilter;
-       for (my $i=0;$i<=6;$i++) {
-               my %cell;
-               if ( @$filters[$i] ) {
-                       if (($i==1) and (@$filters[$i-1])) {
-                               $cell{err} = 1 if (@$filters[$i]<@$filters[$i-1]) ;
-                       }
-                       $cell{filter} .= @$filters[$i];
-                       $cell{crit} .="Issue From" if ($i==0);
-                       $cell{crit} .="Issue To" if ($i==1);
-                       $cell{crit} .="Return From" if ($i==2);
-                       $cell{crit} .="Return To" if ($i==3);
-                       $cell{crit} .="Branch" if ($i==4);
-                       $cell{crit} .="Doc Type" if ($i==5);
-                       $cell{crit} .="Bor Cat" if ($i==6);
-                       $cell{crit} .="Day" if ($i==7);
-                       $cell{crit} .="Month" if ($i==8);
-                       $cell{crit} .="Year" if ($i==9);
-                       push @loopfilter, \%cell;
-               }
-       }
-       my $colfield;
-       my $colorder;
-       if ($column){
-               $column = "issues.".$column if (($column=~/branchcode/) or ($column=~/timestamp/));
-               $column = "biblioitems.".$column if $column=~/itemtype/;
-               $column = "borrowers.".$column if $column=~/categorycode/;
-               my @colfilter ;
-               $colfilter[0] = @$filters[0] if ($column =~ /timestamp/ )  ;
-               $colfilter[1] = @$filters[1] if ($column =~ /timestamp/ )  ;
-               $colfilter[0] = @$filters[2] if ($column =~ /returndate/ )  ;
-               $colfilter[1] = @$filters[3] if ($column =~ /returndate/ )  ;
-               $colfilter[0] = @$filters[4] if ($column =~ /branch/ )  ;
-               $colfilter[0] = @$filters[5] if ($column =~ /itemtype/ )  ;
-               $colfilter[0] = @$filters[6] if ($column =~ /category/ )  ;
-       #       $colfilter[0] = @$filters[11] if ($column =~ /sort2/ ) ;
-               $colfilter[0] = @$filters[7] if ($column =~ /timestamp/ ) ;
-               $colfilter[0] = @$filters[8] if ($column =~ /timestamp/ ) ;
-               $colfilter[0] = @$filters[9] if ($column =~ /timestamp/ ) ;
-       #warn "filtre col ".$colfilter[0]." ".$colfilter[1];
-                                                                                               
-       # loop cols.
-               if ($column eq "Day") {
-                       #Display by day
-                       $column = "issues.timestamp";
-                       $colfield .="dayname($column)";  
-                       $colorder .="weekday($column)";
-               } elsif ($column eq "Month") {
-                       #Display by Month
-                       $column = "issues.timestamp";
-                       $colfield .="monthname($column)";  
-                       $colorder .="month($column)";  
-               } elsif ($column eq "Year") {
-                       #Display by Year
-                       $column = "issues.timestamp";
-                       $colfield .="Year($column)";
-                       $colorder .= $column;
-               } else {
-                       $colfield .= $column;
-                       $colorder .= $column;
-               }  
-               
-               my $strsth2;
-               $strsth2 .= "select distinctrow $colfield FROM `issues`,borrowers,biblioitems LEFT JOIN items ON (biblioitems.biblioitemnumber=items.biblioitemnumber) WHERE issues.itemnumber=items.itemnumber AND issues.borrowernumber=borrowers.borrowernumber and returndate is not null";
-               if (($column=~/timestamp/) or ($column=~/returndate/)){
-                       if ($colfilter[1] and ($colfilter[0])){
-                               $strsth2 .= " and $column between '$colfilter[0]' and '$colfilter[1]' " ;
-                       } elsif ($colfilter[1]) {
-                                       $strsth2 .= " and $column < '$colfilter[1]' " ;
-                       } elsif ($colfilter[0]) {
-                               $strsth2 .= " and $column > '$colfilter[0]' " ;
-                       }
-               } elsif ($colfilter[0]) {
-                       $colfilter[0] =~ s/\*/%/g;
-                       $strsth2 .= " and $column LIKE '$colfilter[0]' " ;
-               }
-               $strsth2 .=" group by $colfield";
-               $strsth2 .=" order by $colorder";
-               warn "". $strsth2;
-               
-               my $sth2 = $dbh->prepare( $strsth2 );
-               $sth2->execute;
-       
-               while (my ($celvalue) = $sth2->fetchrow) {
-                       my %cell;
-                       $cell{'coltitle'} = ($celvalue?$celvalue:"NULL");
-                       push @loopcol, \%cell;
-               }
-       #       warn "fin des titres colonnes";
-       }
-       
-       my $i=0;
+    my @loopfilter;
+    for (my $i=0;$i<=6;$i++) {
+        my %cell;
+        if ( @$filters[$i] ) {
+            if (($i==1) and (@$filters[$i-1])) {
+                $cell{err} = 1 if (@$filters[$i]<@$filters[$i-1]) ;
+            }
+            # format the dates filters, otherwise just fill as is
+            if ($i>=4) {
+                $cell{filter} .= @$filters[$i];
+            } else {
+                $cell{filter} .= format_date(@$filters[$i]);
+            }
+            $cell{crit} .="Issue From" if ($i==0);
+            $cell{crit} .="Issue To" if ($i==1);
+            $cell{crit} .="Return From" if ($i==2);
+            $cell{crit} .="Return To" if ($i==3);
+            $cell{crit} .="Branch" if ($i==4);
+            $cell{crit} .="Doc Type" if ($i==5);
+            $cell{crit} .="Bor Cat" if ($i==6);
+            $cell{crit} .="Day" if ($i==7);
+            $cell{crit} .="Month" if ($i==8);
+            $cell{crit} .="Year" if ($i==9);
+            push @loopfilter, \%cell;
+        }
+    }
+    my $colfield;
+    my $colorder;
+    if ($column){
+        $column = "issues.".$column if (($column=~/branchcode/) or ($column=~/timestamp/));
+        $column = "biblioitems.".$column if $column=~/itemtype/;
+        $column = "borrowers.".$column if $column=~/categorycode/;
+        my @colfilter ;
+        $colfilter[0] = @$filters[0] if ($column =~ /timestamp/ )  ;
+        $colfilter[1] = @$filters[1] if ($column =~ /timestamp/ )  ;
+        $colfilter[0] = @$filters[2] if ($column =~ /returndate/ )  ;
+        $colfilter[1] = @$filters[3] if ($column =~ /returndate/ )  ;
+        $colfilter[0] = @$filters[4] if ($column =~ /branch/ )  ;
+        $colfilter[0] = @$filters[5] if ($column =~ /itemtype/ )  ;
+        $colfilter[0] = @$filters[6] if ($column =~ /category/ )  ;
+    #  $colfilter[0] = @$filters[11] if ($column =~ /sort2/ ) ;
+        $colfilter[0] = @$filters[7] if ($column =~ /timestamp/ ) ;
+        $colfilter[0] = @$filters[8] if ($column =~ /timestamp/ ) ;
+        $colfilter[0] = @$filters[9] if ($column =~ /timestamp/ ) ;
+    #warn "filtre col ".$colfilter[0]." ".$colfilter[1];
+                                                
+    # loop cols.
+        if ($column eq "Day") {
+            #Display by day
+            $column = "issues.timestamp";
+            $colfield .="dayname($column)";  
+            $colorder .="weekday($column)";
+        } elsif ($column eq "Month") {
+            #Display by Month
+            $column = "issues.timestamp";
+            $colfield .="monthname($column)";  
+            $colorder .="month($column)";  
+        } elsif ($column eq "Year") {
+            #Display by Year
+            $column = "issues.timestamp";
+            $colfield .="Year($column)";
+            $colorder .= $column;
+        } else {
+            $colfield .= $column;
+            $colorder .= $column;
+        }  
+        
+        my $strsth2;
+        $strsth2 .= "select distinctrow $colfield FROM `issues`,borrowers,biblioitems LEFT JOIN items ON (biblioitems.biblioitemnumber=items.biblioitemnumber) WHERE issues.itemnumber=items.itemnumber AND issues.borrowernumber=borrowers.borrowernumber and returndate is not null";
+        if (($column=~/timestamp/) or ($column=~/returndate/)){
+            if ($colfilter[1] and ($colfilter[0])){
+                $strsth2 .= " and $column between '$colfilter[0]' and '$colfilter[1]' " ;
+            } elsif ($colfilter[1]) {
+                    $strsth2 .= " and $column < '$colfilter[1]' " ;
+            } elsif ($colfilter[0]) {
+                $strsth2 .= " and $column > '$colfilter[0]' " ;
+            }
+        } elsif ($colfilter[0]) {
+            $colfilter[0] =~ s/\*/%/g;
+            $strsth2 .= " and $column LIKE '$colfilter[0]' " ;
+        }
+        $strsth2 .=" group by $colfield";
+        $strsth2 .=" order by $colorder";
+        warn "". $strsth2;
+        
+        my $sth2 = $dbh->prepare( $strsth2 );
+        $sth2->execute;
+    
+        while (my ($celvalue) = $sth2->fetchrow) {
+            my %cell;
+            $cell{'coltitle'} = ($celvalue?$celvalue:"NULL");
+            push @loopcol, \%cell;
+        }
+    #  warn "fin des titres colonnes";
+    }
+    
+    my $i=0;
 #      my @totalcol;
-       my $hilighted=-1;
-       
-       #Initialization of cell values.....
-       my @table;
-       
+    my $hilighted=-1;
+    
+    #Initialization of cell values.....
+    my @table;
+    
 #      warn "init table";
-       for (my $i=1;$i<=$line;$i++) {
-               foreach my $col ( @loopcol ) {
+    for (my $i=1;$i<=$line;$i++) {
+        foreach my $col ( @loopcol ) {
 #                      warn " init table : $row->{rowtitle} / $col->{coltitle} ";
-                       $table[$i]->{($col->{coltitle})?$col->{coltitle}:"total"}->{'name'}=0;
-               }
-       }
+            $table[$i]->{($col->{coltitle})?$col->{coltitle}:"total"}->{'name'}=0;
+        }
+    }
 
 
 # preparing calculation
-       my $strcalc ;
-       
+    my $strcalc ;
+    
 # Processing average loanperiods
-       $strcalc .= "SELECT  CONCAT(borrowers.surname , \"\\t\",borrowers.firstname),  COUNT(*) AS RANK, borrowers.borrowernumber AS ID";
-       $strcalc .= " , $colfield " if ($colfield);
-       $strcalc .= " FROM `issues`,borrowers,biblioitems LEFT JOIN items ON (biblioitems.biblioitemnumber=items.biblioitemnumber)  WHERE issues.itemnumber=items.itemnumber AND issues.borrowernumber=borrowers.borrowernumber and returndate is not null";
+    $strcalc .= "SELECT  CONCAT(borrowers.surname , \"\\t\",borrowers.firstname),  COUNT(*) AS RANK, borrowers.borrowernumber AS ID";
+    $strcalc .= " , $colfield " if ($colfield);
+    $strcalc .= " FROM `issues`,borrowers,biblioitems LEFT JOIN items ON (biblioitems.biblioitemnumber=items.biblioitemnumber)  WHERE issues.itemnumber=items.itemnumber AND issues.borrowernumber=borrowers.borrowernumber and returndate is not null";
 
-       @$filters[0]=~ s/\*/%/g if (@$filters[0]);
-       $strcalc .= " AND issues.timestamp > '" . @$filters[0] ."'" if ( @$filters[0] );
-       @$filters[1]=~ s/\*/%/g if (@$filters[1]);
-       $strcalc .= " AND issues.timestamp < '" . @$filters[1] ."'" if ( @$filters[1] );
-       @$filters[2]=~ s/\*/%/g if (@$filters[2]);
-       $strcalc .= " AND issues.returndate > '" . @$filters[2] ."'" if ( @$filters[2] );
-       @$filters[3]=~ s/\*/%/g if (@$filters[3]);
-       $strcalc .= " AND issues.returndate < '" . @$filters[3] ."'" if ( @$filters[3] );
-       @$filters[4]=~ s/\*/%/g if (@$filters[4]);
-       $strcalc .= " AND issues.branchcode like '" . @$filters[4] ."'" if ( @$filters[4] );
-       @$filters[5]=~ s/\*/%/g if (@$filters[5]);
-       $strcalc .= " AND biblioitems.itemtype like '" . @$filters[5] ."'" if ( @$filters[5] );
-       @$filters[6]=~ s/\*/%/g if (@$filters[6]);
-       $strcalc .= " AND borrowers.categorycode like '" . @$filters[6] ."'" if ( @$filters[6] );
-       @$filters[7]=~ s/\*/%/g if (@$filters[7]);
-       $strcalc .= " AND dayname(issues.timestamp) like '" . @$filters[7]."'" if (@$filters[7]);
-       @$filters[8]=~ s/\*/%/g if (@$filters[8]);
-       $strcalc .= " AND monthname(issues.timestamp) like '" . @$filters[8]."'" if (@$filters[8]);
-       @$filters[9]=~ s/\*/%/g if (@$filters[9]);
-       $strcalc .= " AND year(issues.timestamp) like '" . @$filters[9] ."'" if ( @$filters[9] );
-       
-       $strcalc .= " group by borrowers.borrowernumber";
-       $strcalc .= ", $colfield" if ($column);
-       $strcalc .= " order by RANK DESC";
-       $strcalc .= ",$colfield " if ($colfield);
+    @$filters[0]=~ s/\*/%/g if (@$filters[0]);
+    $strcalc .= " AND issues.timestamp > '" . @$filters[0] ."'" if ( @$filters[0] );
+    @$filters[1]=~ s/\*/%/g if (@$filters[1]);
+    $strcalc .= " AND issues.timestamp < '" . @$filters[1] ."'" if ( @$filters[1] );
+    @$filters[2]=~ s/\*/%/g if (@$filters[2]);
+    $strcalc .= " AND issues.returndate > '" . @$filters[2] ."'" if ( @$filters[2] );
+    @$filters[3]=~ s/\*/%/g if (@$filters[3]);
+    $strcalc .= " AND issues.returndate < '" . @$filters[3] ."'" if ( @$filters[3] );
+    @$filters[4]=~ s/\*/%/g if (@$filters[4]);
+    $strcalc .= " AND issues.branchcode like '" . @$filters[4] ."'" if ( @$filters[4] );
+    @$filters[5]=~ s/\*/%/g if (@$filters[5]);
+    $strcalc .= " AND biblioitems.itemtype like '" . @$filters[5] ."'" if ( @$filters[5] );
+    @$filters[6]=~ s/\*/%/g if (@$filters[6]);
+    $strcalc .= " AND borrowers.categorycode like '" . @$filters[6] ."'" if ( @$filters[6] );
+    @$filters[7]=~ s/\*/%/g if (@$filters[7]);
+    $strcalc .= " AND dayname(issues.timestamp) like '" . @$filters[7]."'" if (@$filters[7]);
+    @$filters[8]=~ s/\*/%/g if (@$filters[8]);
+    $strcalc .= " AND monthname(issues.timestamp) like '" . @$filters[8]."'" if (@$filters[8]);
+    @$filters[9]=~ s/\*/%/g if (@$filters[9]);
+    $strcalc .= " AND year(issues.timestamp) like '" . @$filters[9] ."'" if ( @$filters[9] );
+    
+    $strcalc .= " group by borrowers.borrowernumber";
+    $strcalc .= ", $colfield" if ($column);
+    $strcalc .= " order by RANK DESC";
+    $strcalc .= ",$colfield " if ($colfield);
 #      my $max;
 #      if (@loopcol) {
 #              $max = $line*@loopcol;
 #      } else { $max=$line;}
 #      $strcalc .= " LIMIT 0,$max";
-       warn "SQL :". $strcalc;
-       
-       my $dbcalc = $dbh->prepare($strcalc);
-       $dbcalc->execute;
+    warn "SQL :". $strcalc;
+    
+    my $dbcalc = $dbh->prepare($strcalc);
+    $dbcalc->execute;
 #      warn "filling table";
-       my $previous_col;
-       my %indice;
-       while (my  @data = $dbcalc->fetchrow) {
-               my ($row, $rank, $id, $col )=@data;
-               $col = "zzEMPTY" if ($col eq undef);
-               $indice{$col}=1 if (not($indice{$col}));
-               $table[$indice{$col}]->{$col}->{'name'}=$row;
-               $table[$indice{$col}]->{$col}->{'count'}=$rank;
-               $table[$indice{$col}]->{$col}->{'link'}=$id;
+    my $previous_col;
+    my %indice;
+    while (my  @data = $dbcalc->fetchrow) {
+        my ($row, $rank, $id, $col )=@data;
+        $col = "zzEMPTY" if ($col eq undef);
+        $indice{$col}=1 if (not($indice{$col}));
+        $table[$indice{$col}]->{$col}->{'name'}=$row;
+        $table[$indice{$col}]->{$col}->{'count'}=$rank;
+        $table[$indice{$col}]->{$col}->{'link'}=$id;
 #              warn " ".$i." ".$col. " ".$row;
-               $indice{$col}++;
-       }
-       
-       push @loopcol,{coltitle => "Global"} if not($column);
-       
-       for ($i=1; $i<=$line;$i++) {
-               my @loopcell;
-               warn " $i";
-               #@loborrowersopcol ensures the order for columns is common with column titles
-               # and the number matches the number of columns
-               my $colcount=0;
-               foreach my $col ( @loopcol ) {
+        $indice{$col}++;
+    }
+    
+    push @loopcol,{coltitle => "Global"} if not($column);
+    
+    for ($i=1; $i<=$line;$i++) {
+        my @loopcell;
+        warn " $i";
+        #@loborrowersopcol ensures the order for columns is common with column titles
+        # and the number matches the number of columns
+        my $colcount=0;
+        foreach my $col ( @loopcol ) {
 #                      warn " colonne :$col->{coltitle}";
-                       my $value;
-                       my $count=0;
-                       my $link;
-                       if (@loopcol){
-                               $value =$table[$i]->{(($col->{coltitle} eq "NULL") or ($col->{coltitle} eq "Global"))?"zzEMPTY":$col->{coltitle}}->{'name'};
-                               $count =$table[$i]->{(($col->{coltitle} eq "NULL") or ($col->{coltitle} eq "Global"))?"zzEMPTY":$col->{coltitle}}->{'count'};
-                               $link =$table[$i]->{(($col->{coltitle} eq "NULL") or ($col->{coltitle} eq "Global"))?"zzEMPTY":$col->{coltitle}}->{'link'};
-                       } else {
-                               $value =$table[$i]->{"zzEMPTY"}->{'name'};
-                               $count =$table[$i]->{"zzEMPTY"}->{'count'};
-                               $link =$table[$i]->{"zzEMPTY"}->{'link'};
-                       }
+            my $value;
+            my $count=0;
+            my $link;
+            if (@loopcol){
+                $value =$table[$i]->{(($col->{coltitle} eq "NULL") or ($col->{coltitle} eq "Global"))?"zzEMPTY":$col->{coltitle}}->{'name'};
+                $count =$table[$i]->{(($col->{coltitle} eq "NULL") or ($col->{coltitle} eq "Global"))?"zzEMPTY":$col->{coltitle}}->{'count'};
+                $link =$table[$i]->{(($col->{coltitle} eq "NULL") or ($col->{coltitle} eq "Global"))?"zzEMPTY":$col->{coltitle}}->{'link'};
+            } else {
+                $value =$table[$i]->{"zzEMPTY"}->{'name'};
+                $count =$table[$i]->{"zzEMPTY"}->{'count'};
+                $link =$table[$i]->{"zzEMPTY"}->{'link'};
+            }
 #                      warn " ".$i ." value:$value count:$count reference:$link";
-                       push @loopcell, {value => $value, count =>$count, reference => $link} ;
-               }
-               push @looprow,{ 'rowtitle' => $i ,
-                                               'loopcell' => \@loopcell,
-                                               'hilighted' => ($hilighted >0),
-                                       };
-               $hilighted = -$hilighted;
-       }
+            push @loopcell, {value => $value, count =>$count, reference => $link} ;
+        }
+        push @looprow,{ 'rowtitle' => $i ,
+                        'loopcell' => \@loopcell,
+                        'hilighted' => ($hilighted >0),
+                    };
+        $hilighted = -$hilighted;
+    }
 #      
-                       
+            
 
-       # the header of the table
-       $globalline{loopfilter}=\@loopfilter;
-       # the core of the table
-       $globalline{looprow} = \@looprow;
-       $globalline{loopcol} = \@loopcol;
+    # the header of the table
+    $globalline{loopfilter}=\@loopfilter;
+    # the core of the table
+    $globalline{looprow} = \@looprow;
+    $globalline{loopcol} = \@loopcol;
 #      # the foot (totals by borrower type)
-       $globalline{loopfooter} = \@loopfooter;
-       $globalline{total}= $grantotal;
-       $globalline{line} = $line;
-       $globalline{column} = $column;
-       push @mainloop,\%globalline;
-       return \@mainloop;
+    $globalline{loopfooter} = \@loopfooter;
+    $globalline{total}= $grantotal;
+    $globalline{line} = $line;
+    $globalline{column} = $column;
+    push @mainloop,\%globalline;
+    return \@mainloop;
 }
 
 1;
index f4eb50d..6a31475 100755 (executable)
@@ -27,7 +27,7 @@ use C4::Koha;
 use C4::Output;
 use C4::Circulation;
 use C4::Members;
-use Date::Manip;
+use C4::Date;
 
 =head1 NAME
 
@@ -51,107 +51,103 @@ my $mime = $input->param("MIME");
 my $del = $input->param("sep");
 #warn "calcul : ".$calc;
 my ($template, $borrowernumber, $cookie)
-       = get_template_and_user({template_name => $fullreportname,
-                               query => $input,
-                               type => "intranet",
-                               authnotrequired => 0,
-                               flagsrequired => {reports => 1},
-                               debug => 1,
-                               });
+    = get_template_and_user({template_name => $fullreportname,
+                query => $input,
+                type => "intranet",
+                authnotrequired => 0,
+                flagsrequired => {reports => 1},
+                debug => 1,
+                });
 $template->param(do_it => $do_it,
-               intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
-               intranetstylesheet => C4::Context->preference("intranetstylesheet"),
-               IntranetNav => C4::Context->preference("IntranetNav"),
-               );
+        DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(),
+        );
 if ($do_it) {
 # Displaying results
-       my $results = calculate($limit, $column, \@filters);
-       if ($output eq "screen"){
+    my $results = calculate($limit, $column, \@filters);
+    if ($output eq "screen"){
 # Printing results to screen
-               $template->param(mainloop => $results);
-               output_html_with_http_headers $input, $cookie, $template->output;
-               exit(1);
-       } else {
+        $template->param(mainloop => $results);
+        output_html_with_http_headers $input, $cookie, $template->output;
+        exit(1);
+    } else {
 # Printing to a csv file
-               print $input->header(-type => 'application/vnd.sun.xml.calc',
-                                     -encoding    => 'utf-8',
-                       -attachment=>"$basename.csv",
-                       -filename=>"$basename.csv" );
-               my $cols = @$results[0]->{loopcol};
-               my $lines = @$results[0]->{looprow};
-               my $sep;
-               $sep =C4::Context->preference("delimiter");
+        print $input->header(-type => 'application/vnd.sun.xml.calc',
+                            -encoding    => 'utf-8',
+                            -attachment=>"$basename.csv",
+                            -filename=>"$basename.csv" );
+        my $cols = @$results[0]->{loopcol};
+        my $lines = @$results[0]->{looprow};
+        my $sep;
+        $sep =C4::Context->preference("delimiter");
 # header top-right
-               print "num /". @$results[0]->{column} .$sep;
+        print "num /". @$results[0]->{column} .$sep;
 # Other header
-               foreach my $col ( @$cols ) {
-                       print $col->{coltitle}.$sep;
-               }
-               print "Total\n";
+        foreach my $col ( @$cols ) {
+            print $col->{coltitle}.$sep;
+        }
+        print "Total\n";
 # Table
-               foreach my $line ( @$lines ) {
-                       my $x = $line->{loopcell};
-                       print $line->{rowtitle}.$sep;
-                       foreach my $cell (@$x) {
-                               print $cell->{value}.$sep;
-                       }
-                       print $line->{totalrow};
-                       print "\n";
-               }
+        foreach my $line ( @$lines ) {
+            my $x = $line->{loopcell};
+            print $line->{rowtitle}.$sep;
+            foreach my $cell (@$x) {
+                print $cell->{value}.$sep;
+            }
+            print $line->{totalrow};
+            print "\n";
+        }
 # footer
-               print "TOTAL";
-               $cols = @$results[0]->{loopfooter};
-               foreach my $col ( @$cols ) {
-                       print $sep.$col->{totalcol};
-               }
-               print $sep.@$results[0]->{total};
-               exit(1);
-       }
+        print "TOTAL";
+        $cols = @$results[0]->{loopfooter};
+        foreach my $col ( @$cols ) {
+            print $sep.$col->{totalcol};
+        }
+        print $sep.@$results[0]->{total};
+        exit(1);
+    }
 # Displaying choices
 } else {
-       my $dbh = C4::Context->dbh;
-       my @values;
-       my %labels;
-       my %select;
-       my $req;
-       
-       my @mime = ( C4::Context->preference("MIME") );
+    my $dbh = C4::Context->dbh;
+    my @values;
+    my %labels;
+    my %select;
+    my $req;
+    
+    my @mime = ( C4::Context->preference("MIME") );
 #      foreach my $mime (@mime){
 #              warn "".$mime;
 #      }
-       
-       my $CGIextChoice=CGI::scrolling_list(
-                               -name     => 'MIME',
-                               -id       => 'MIME',
-                               -values   => \@mime,
-                               -size     => 1,
-                               -multiple => 0 );
-       
-       my @dels = ( C4::Context->preference("delimiter") );
-       my $CGIsepChoice=CGI::scrolling_list(
-                               -name     => 'sep',
-                               -id       => 'sep',
-                               -values   => \@dels,
-                               -size     => 1,
-                               -multiple => 0 );
-       
-       my ($codes,$labels) = GetborCatFromCatType(undef,undef);
-       my @borcatloop;
-       foreach my $thisborcat (sort keys %$labels) {
- #                     my $selected = 1 if $thisbranch eq $branch;
-                       my %row =(value => $thisborcat,
- #                                                                     selected => $selected,
-                                                                       description => $labels->{$thisborcat},
-                                                       );
-                       push @borcatloop, \%row;
-       }
-       
-       
-       $template->param(
-                                       CGIextChoice => $CGIextChoice,
-                                       CGIsepChoice => $CGIsepChoice,
-                                       borcatloop =>\@borcatloop,
-                                       );
+    
+    my $CGIextChoice=CGI::scrolling_list(
+                -name     => 'MIME',
+                -id       => 'MIME',
+                -values   => \@mime,
+                -size     => 1,
+                -multiple => 0 );
+    
+    my @dels = ( C4::Context->preference("delimiter") );
+    my $CGIsepChoice=CGI::scrolling_list(
+                -name     => 'sep',
+                -id       => 'sep',
+                -values   => \@dels,
+                -size     => 1,
+                -multiple => 0 );
+    
+    my ($codes,$labels) = GetborCatFromCatType(undef,undef);
+    my @borcatloop;
+    foreach my $thisborcat (sort keys %$labels) {
+#                      my $selected = 1 if $thisbranch eq $branch;
+            my %row =(value => $thisborcat,
+#                                                                      selected => $selected,
+                                    description => $labels->{$thisborcat},
+                            );
+            push @borcatloop, \%row;
+    }
+    $template->param(
+                    CGIextChoice => $CGIextChoice,
+                    CGIsepChoice => $CGIsepChoice,
+                    borcatloop =>\@borcatloop,
+                    );
 output_html_with_http_headers $input, $cookie, $template->output;
 }
 
@@ -159,179 +155,179 @@ output_html_with_http_headers $input, $cookie, $template->output;
 
 
 sub calculate {
-       my ($line, $column, $filters) = @_;
-       my @mainloop;
-       my @loopfooter;
-       my @loopcol;
-       my @loopline;
-       my @looprow;
-       my %globalline;
-       my $grantotal =0;
+    my ($line, $column, $filters) = @_;
+    my @mainloop;
+    my @loopfooter;
+    my @loopcol;
+    my @loopline;
+    my @looprow;
+    my %globalline;
+    my $grantotal =0;
 # extract parameters
-       my $dbh = C4::Context->dbh;
+    my $dbh = C4::Context->dbh;
 
 # Filters
 # Checking filters
 #
-       my @loopfilter;
-       for (my $i=0;$i<=2;$i++) {
-               my %cell;
-               if ( @$filters[$i] ) {
-                       if (($i==1) and (@$filters[$i-1])) {
-                               $cell{err} = 1 if (@$filters[$i]<@$filters[$i-1]) ;
-                       }
-                       $cell{filter} .= @$filters[$i];
-                       $cell{crit} .="Bor Cat" if ($i==0);
-                       $cell{crit} .="Without issues since" if ($i==1);
-                       push @loopfilter, \%cell;
-               }
-       }
-       my $colfield;
-       my $colorder;
-       if ($column){
-               $column = "borrowers.".$column if $column=~/categorycode/;
-               my @colfilter ;
-               $colfilter[0] = @$filters[0] if ($column =~ /category/ )  ;
-       #       $colfilter[0] = @$filters[11] if ($column =~ /sort2/ ) ;
-       #warn "filtre col ".$colfilter[0]." ".$colfilter[1];
-                                                                                               
-       # loop cols.
-               $colfield .= $column;
-               $colorder .= $column;
-               
-               my $strsth2;
-               $strsth2 .= "select distinctrow $colfield FROM borrowers LEFT JOIN `issues` ON issues.borrowernumber=borrowers.borrowernumber";
-               if ($colfilter[0]) {
-                       $colfilter[0] =~ s/\*/%/g;
-                       $strsth2 .= " and $column LIKE '$colfilter[0]' " ;
-               }
-               $strsth2 .=" group by $colfield";
-               $strsth2 .=" order by $colorder";
-               warn "". $strsth2;
-               
-               my $sth2 = $dbh->prepare( $strsth2 );
-               $sth2->execute;
+    my @loopfilter;
+    for (my $i=0;$i<=2;$i++) {
+        my %cell;
+        if ( @$filters[$i] ) {
+            if (($i==1) and (@$filters[$i-1])) {
+                $cell{err} = 1 if (@$filters[$i]<@$filters[$i-1]) ;
+            }
+            $cell{filter} .= @$filters[$i];
+            $cell{crit} .="Bor Cat" if ($i==0);
+            $cell{crit} .="Without issues since" if ($i==1);
+            push @loopfilter, \%cell;
+        }
+    }
+    my $colfield;
+    my $colorder;
+    if ($column){
+        $column = "borrowers.".$column if $column=~/categorycode/;
+        my @colfilter ;
+        $colfilter[0] = @$filters[0] if ($column =~ /category/ )  ;
+    #  $colfilter[0] = @$filters[11] if ($column =~ /sort2/ ) ;
+    #warn "filtre col ".$colfilter[0]." ".$colfilter[1];
+                                                
+    # loop cols.
+        $colfield .= $column;
+        $colorder .= $column;
+        
+        my $strsth2;
+        $strsth2 .= "select distinctrow $colfield FROM borrowers LEFT JOIN `issues` ON issues.borrowernumber=borrowers.borrowernumber";
+        if ($colfilter[0]) {
+            $colfilter[0] =~ s/\*/%/g;
+            $strsth2 .= " and $column LIKE '$colfilter[0]' " ;
+        }
+        $strsth2 .=" group by $colfield";
+        $strsth2 .=" order by $colorder";
+        warn "". $strsth2;
+        
+        my $sth2 = $dbh->prepare( $strsth2 );
+        $sth2->execute;
 
-               
-       
-               while (my ($celvalue) = $sth2->fetchrow) {
-                       my %cell;
-       #               my %ft;
-       #               warn "coltitle :".$celvalue;
-                       $cell{coltitle} = $celvalue;
-       #               $ft{totalcol} = 0;
-                       push @loopcol, \%cell;
-               }
-       #       warn "fin des titres colonnes";
-       }
-       
-       my $i=0;
+        
+    
+        while (my ($celvalue) = $sth2->fetchrow) {
+            my %cell;
+    #          my %ft;
+    #          warn "coltitle :".$celvalue;
+            $cell{coltitle} = $celvalue;
+    #          $ft{totalcol} = 0;
+            push @loopcol, \%cell;
+        }
+    #  warn "fin des titres colonnes";
+    }
+    
+    my $i=0;
 #      my @totalcol;
-       my $hilighted=-1;
-       
-       #Initialization of cell values.....
-       my @table;
-       
+    my $hilighted=-1;
+    
+    #Initialization of cell values.....
+    my @table;
+    
 #      warn "init table";
-       for (my $i=1;$i<=$line;$i++) {
-               foreach my $col ( @loopcol ) {
+    for (my $i=1;$i<=$line;$i++) {
+        foreach my $col ( @loopcol ) {
 #                      warn " init table : $row->{rowtitle} / $col->{coltitle} ";
-                       $table[$i]->{($col->{coltitle})?$col->{coltitle}:"Global"}=0;
-               }
-       }
+            $table[$i]->{($col->{coltitle})?$col->{coltitle}:"Global"}=0;
+        }
+    }
 
 
 # preparing calculation
-       my $strcalc ;
-       
+    my $strcalc ;
+    
 # Processing calculation
-       $strcalc .= "SELECT CONCAT( borrowers.surname , \"\\t\",borrowers.firstname, \"\\t\", borrowers.cardnumber)";
-       $strcalc .= " , $colfield " if ($colfield);
-       $strcalc .= " FROM borrowers ";
-       $strcalc .= "WHERE 1 ";
-       @$filters[0]=~ s/\*/%/g if (@$filters[0]);
-       $strcalc .= " AND borrowers.categorycode like '" . @$filters[0] ."'" if ( @$filters[0] );
-       if (@$filters[1]){
-               my $strqueryfilter="SELECT DISTINCT borrowernumber FROM issues where issues.timestamp> @$filters[1] ";
-               my $queryfilter = $dbh->prepare("SELECT DISTINCT borrowernumber FROM issues where issues.timestamp> @$filters[1] ");
-               $strcalc .= " AND borrowers.borrowernumber not in ($strqueryfilter)";
-               
+    $strcalc .= "SELECT CONCAT( borrowers.surname , \"\\t\",borrowers.firstname, \"\\t\", borrowers.cardnumber)";
+    $strcalc .= " , $colfield " if ($colfield);
+    $strcalc .= " FROM borrowers ";
+    $strcalc .= "WHERE 1 ";
+    @$filters[0]=~ s/\*/%/g if (@$filters[0]);
+    $strcalc .= " AND borrowers.categorycode like '" . @$filters[0] ."'" if ( @$filters[0] );
+    if (@$filters[1]){
+        my $strqueryfilter="SELECT DISTINCT borrowernumber FROM issues where issues.timestamp> @$filters[1] ";
+        my $queryfilter = $dbh->prepare("SELECT DISTINCT borrowernumber FROM issues where issues.timestamp> ".format_date_in_iso(@$filters[1]));
+        $strcalc .= " AND borrowers.borrowernumber not in ($strqueryfilter)";
+        
 #              $queryfilter->execute(@$filters[1]);
 #              while (my ($borrowernumber)=$queryfilter->fetchrow){
 #                      $strcalc .= " AND borrowers.borrowernumber <> $borrowernumber ";
 #              }
-       } else {
-               my $strqueryfilter="SELECT DISTINCT borrowernumber FROM issues ";
-               my $queryfilter = $dbh->prepare("SELECT DISTINCT borrowernumber FROM issues ");
-               $queryfilter->execute;
-               $strcalc .= " AND borrowers.borrowernumber not in ($strqueryfilter)";
+    } else {
+        my $strqueryfilter="SELECT DISTINCT borrowernumber FROM issues ";
+        my $queryfilter = $dbh->prepare("SELECT DISTINCT borrowernumber FROM issues ");
+        $queryfilter->execute;
+        $strcalc .= " AND borrowers.borrowernumber not in ($strqueryfilter)";
 #              while (my ($borrowernumber)=$queryfilter->fetchrow){
 #                      $strcalc .= " AND borrowers.borrowernumber <> $borrowernumber ";
 #              }
-       }
-       $strcalc .= " group by borrowers.borrowernumber";
-       $strcalc .= ", $colfield" if ($column);
-       $strcalc .= " order by $colfield " if ($colfield);
-       my $max;
-       if (@loopcol) {
-               $max = $line*@loopcol;
-       } else { $max=$line;}
-       $strcalc .= " LIMIT 0,$max" if ($line);
-       warn "SQL :". $strcalc;
-       
-       my $dbcalc = $dbh->prepare($strcalc);
-       $dbcalc->execute;
+    }
+    $strcalc .= " group by borrowers.borrowernumber";
+    $strcalc .= ", $colfield" if ($column);
+    $strcalc .= " order by $colfield " if ($colfield);
+    my $max;
+    if (@loopcol) {
+        $max = $line*@loopcol;
+    } else { $max=$line;}
+    $strcalc .= " LIMIT 0,$max" if ($line);
+    warn "SQL :". $strcalc;
+    
+    my $dbcalc = $dbh->prepare($strcalc);
+    $dbcalc->execute;
 #      warn "filling table";
-       my $previous_col;
-       my $i=1;
-       while (my  @data = $dbcalc->fetchrow) {
-               my ($row, $col )=@data;
-               $col = "zzEMPTY" if ($col eq undef);
-               $i=1 if (($previous_col) and not($col eq $previous_col));
-               $table[$i]->{$col}=$row;
+    my $previous_col;
+    my $i=1;
+    while (my  @data = $dbcalc->fetchrow) {
+        my ($row, $col )=@data;
+        $col = "zzEMPTY" if ($col eq undef);
+        $i=1 if (($previous_col) and not($col eq $previous_col));
+        $table[$i]->{$col}=$row;
 #              warn " ".$i." ".$col. " ".$row;
-               $i++;
-               $previous_col=$col;
-       }
-       
-       push @loopcol,{coltitle => "Global"} if not($column);
-       
-       my $max =(($line)?$line:@table -1);
-       for ($i=1; $i<=$max;$i++) {
-               my @loopcell;
-               #@loopcol ensures the order for columns is common with column titles
-               # and the number matches the number of columns
-               my $colcount=0;
-               foreach my $col ( @loopcol ) {
-                       my $value;
-                       if (@loopcol){
-                               $value =$table[$i]->{(($col->{coltitle} eq "NULL") or ($col->{coltitle} eq "Global"))?"zzEMPTY":$col->{coltitle}};
-                       } else {
-                               $value =$table[$i]->{"zzEMPTY"};
-                       }
-                       push @loopcell, {value => $value} ;
-               }
-               push @looprow,{ 'rowtitle' => $i ,
-                                               'loopcell' => \@loopcell,
-                                               'hilighted' => ($hilighted >0),
-                                       };
-               $hilighted = -$hilighted;
-       }
-       
-                       
+        $i++;
+        $previous_col=$col;
+    }
+    
+    push @loopcol,{coltitle => "Global"} if not($column);
+    
+    my $max =(($line)?$line:@table -1);
+    for ($i=1; $i<=$max;$i++) {
+        my @loopcell;
+        #@loopcol ensures the order for columns is common with column titles
+        # and the number matches the number of columns
+        my $colcount=0;
+        foreach my $col ( @loopcol ) {
+            my $value;
+            if (@loopcol){
+                $value =$table[$i]->{(($col->{coltitle} eq "NULL") or ($col->{coltitle} eq "Global"))?"zzEMPTY":$col->{coltitle}};
+            } else {
+                $value =$table[$i]->{"zzEMPTY"};
+            }
+            push @loopcell, {value => $value} ;
+        }
+        push @looprow,{ 'rowtitle' => $i ,
+                        'loopcell' => \@loopcell,
+                        'hilighted' => ($hilighted >0),
+                    };
+        $hilighted = -$hilighted;
+    }
+    
+            
 
-       # the header of the table
-       $globalline{loopfilter}=\@loopfilter;
-       # the core of the table
-       $globalline{looprow} = \@looprow;
-       $globalline{loopcol} = \@loopcol;
+    # the header of the table
+    $globalline{loopfilter}=\@loopfilter;
+    # the core of the table
+    $globalline{looprow} = \@looprow;
+    $globalline{loopcol} = \@loopcol;
 #      # the foot (totals by borrower type)
-       $globalline{loopfooter} = \@loopfooter;
-       $globalline{total}= $grantotal;
-       $globalline{line} = $line;
-       $globalline{column} = $column;
-       push @mainloop,\%globalline;
-       return \@mainloop;
+    $globalline{loopfooter} = \@loopfooter;
+    $globalline{total}= $grantotal;
+    $globalline{line} = $line;
+    $globalline{column} = $column;
+    push @mainloop,\%globalline;
+    return \@mainloop;
 }
 
 1;
index b5a4f07..eef4676 100755 (executable)
@@ -237,7 +237,8 @@ foreach my $thisbranch (keys %$branches) {
                                        CGIsepChoice => $CGIsepChoice,
                                        CGIBranch => $CGIBranch
 #                                      CGIBranch => \@branchloop
-                                       );
+                        DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(),
+                    );
 
 }
 output_html_with_http_headers $input, $cookie, $template->output;
index 5e9be89..d033b49 100755 (executable)
@@ -27,7 +27,7 @@ use C4::Branch; # GetBranches
 use C4::Output;
 use C4::Koha;
 use C4::Circulation;
-use Date::Manip;
+use C4::Date;
 use C4::Members;
 
 =head1 NAME
@@ -46,141 +46,141 @@ my $fullreportname = "reports/cat_issues_top.tmpl";
 my $limit = $input->param("Limit");
 my $column = $input->param("Criteria");
 my @filters = $input->param("Filter");
+$filters[0]=format_date_in_iso($filters[0]);
+$filters[1]=format_date_in_iso($filters[1]);
 my $output = $input->param("output");
 my $basename = $input->param("basename");
 my $mime = $input->param("MIME");
 my $del = $input->param("sep");
 #warn "calcul : ".$calc;
 my ($template, $borrowernumber, $cookie)
-       = get_template_and_user({template_name => $fullreportname,
-                               query => $input,
-                               type => "intranet",
-                               authnotrequired => 0,
-                               flagsrequired => { reports => 1},
-                               debug => 1,
-                               });
+    = get_template_and_user({template_name => $fullreportname,
+                query => $input,
+                type => "intranet",
+                authnotrequired => 0,
+                flagsrequired => { reports => 1},
+                debug => 1,
+                });
 $template->param(do_it => $do_it,
-               intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
-               intranetstylesheet => C4::Context->preference("intranetstylesheet"),
-               IntranetNav => C4::Context->preference("IntranetNav"),
-               );
+        DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(),
+        );
 if ($do_it) {
 # Displaying results
-       my $results = calculate($limit, $column, \@filters);
-       if ($output eq "screen"){
+    my $results = calculate($limit, $column, \@filters);
+    if ($output eq "screen"){
 # Printing results to screen
-               $template->param(mainloop => $results,
-                                               limit => $limit);
-               output_html_with_http_headers $input, $cookie, $template->output;
-               exit(1);
-       } else {
+        $template->param(mainloop => $results,
+                        limit => $limit);
+        output_html_with_http_headers $input, $cookie, $template->output;
+        exit(1);
+    } else {
 # Printing to a csv file
-               print $input->header(-type => 'application/vnd.sun.xml.calc',
-                                     -encoding    => 'utf-8',
-                       -attachment=>"$basename.csv",
-                       -filename=>"$basename.csv" );
-               my $cols = @$results[0]->{loopcol};
-               my $lines = @$results[0]->{looprow};
-               my $sep;
-               $sep =C4::Context->preference("delimiter");
+        print $input->header(-type => 'application/vnd.sun.xml.calc',
+                            -encoding    => 'utf-8',
+                            -attachment=>"$basename.csv",
+                            -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;
+        print @$results[0]->{line} ."/". @$results[0]->{column} .$sep;
 # Other header
-               foreach my $col ( @$cols ) {
-                       print $col->{coltitle}.$sep;
-               }
-               print "Total\n";
+        foreach my $col ( @$cols ) {
+            print $col->{coltitle}.$sep;
+        }
+        print "Total\n";
 # Table
-               foreach my $line ( @$lines ) {
-                       my $x = $line->{loopcell};
-                       print $line->{rowtitle}.$sep;
-                       foreach my $cell (@$x) {
-                               print $cell->{value}.$sep;
-                       }
-                       print $line->{totalrow};
-                       print "\n";
-               }
+        foreach my $line ( @$lines ) {
+            my $x = $line->{loopcell};
+            print $line->{rowtitle}.$sep;
+            foreach my $cell (@$x) {
+                print $cell->{value}.$sep;
+            }
+            print $line->{totalrow};
+            print "\n";
+        }
 # footer
-               print "TOTAL";
-               $cols = @$results[0]->{loopfooter};
-               foreach my $col ( @$cols ) {
-                       print $sep.$col->{totalcol};
-               }
-               print $sep.@$results[0]->{total};
-               exit(1);
-       }
+        print "TOTAL";
+        $cols = @$results[0]->{loopfooter};
+        foreach my $col ( @$cols ) {
+            print $sep.$col->{totalcol};
+        }
+        print $sep.@$results[0]->{total};
+        exit(1);
+    }
 # Displaying choices
 } else {
-       my $dbh = C4::Context->dbh;
-       my @values;
-       my %labels;
-       my %select;
-       my $req;
-       
-       my @mime = ( C4::Context->preference("MIME") );
+    my $dbh = C4::Context->dbh;
+    my @values;
+    my %labels;
+    my %select;
+    my $req;
+    
+    my @mime = ( C4::Context->preference("MIME") );
 #      foreach my $mime (@mime){
 #              warn "".$mime;
 #      }
-       
-       my $CGIextChoice=CGI::scrolling_list(
-                               -name     => 'MIME',
-                               -id       => 'MIME',
-                               -values   => \@mime,
-                               -size     => 1,
-                               -multiple => 0 );
-       
-       my @dels = ( C4::Context->preference("delimiter") );
-       my $CGIsepChoice=CGI::scrolling_list(
-                               -name     => 'sep',
-                               -id       => 'sep',
-                               -values   => \@dels,
-                               -size     => 1,
-                               -multiple => 0 );
-       #branch
-       my $branches = GetBranches;
-       my @branchloop;
-       foreach my $thisbranch (keys %$branches) {
+    
+    my $CGIextChoice=CGI::scrolling_list(
+                -name     => 'MIME',
+                -id       => 'MIME',
+                -values   => \@mime,
+                -size     => 1,
+                -multiple => 0 );
+    
+    my @dels = ( C4::Context->preference("delimiter") );
+    my $CGIsepChoice=CGI::scrolling_list(
+                -name     => 'sep',
+                -id       => 'sep',
+                -values   => \@dels,
+                -size     => 1,
+                -multiple => 0 );
+    #branch
+    my $branches = GetBranches;
+    my @branchloop;
+    foreach my $thisbranch (keys %$branches) {
 #                      my $selected = 1 if $thisbranch eq $branch;
-                       my %row =(value => $thisbranch,
+            my %row =(value => $thisbranch,
 #                                                                      selected => $selected,
-                                                                       branchname => $branches->{$thisbranch}->{'branchname'},
-                                                       );
-                       push @branchloop, \%row;
-       }
+                                    branchname => $branches->{$thisbranch}->{'branchname'},
+                            );
+            push @branchloop, \%row;
+    }
 
-       #doctype
-       my $itemtypes = GetItemTypes;
-       my @itemtypeloop;
-       foreach my $thisitemtype (keys %$itemtypes) {
+    #doctype
+    my $itemtypes = GetItemTypes;
+    my @itemtypeloop;
+    foreach my $thisitemtype (keys %$itemtypes) {
 #                      my $selected = 1 if $thisbranch eq $branch;
-                       my %row =(value => $thisitemtype,
+            my %row =(value => $thisitemtype,
 #                                                                      selected => $selected,
-                                                                       description => $itemtypes->{$thisitemtype}->{'description'},
-                                                       );
-                       push @itemtypeloop, \%row;
-       }
-       
-       #borcat
-       my ($codes,$labels) = GetborCatFromCatType(undef,undef);
-       my @borcatloop;
-       foreach my $thisborcat (sort keys %$labels) {
- #                     my $selected = 1 if $thisbranch eq $branch;
-                       my %row =(value => $thisborcat,
- #                                                                     selected => $selected,
-                                                                       description => $labels->{$thisborcat},
-                                                       );
-                       push @borcatloop, \%row;
-       }
-       
-       #Day
-       #Month
-       $template->param(
-                                       CGIextChoice => $CGIextChoice,
-                                       CGIsepChoice => $CGIsepChoice,
-                                       branchloop =>\@branchloop,
-                                       itemtypeloop =>\@itemtypeloop,
-                                       borcatloop =>\@borcatloop,
-                                       );
+                                    description => $itemtypes->{$thisitemtype}->{'description'},
+                            );
+            push @itemtypeloop, \%row;
+    }
+    
+    #borcat
+    my ($codes,$labels) = GetborCatFromCatType(undef,undef);
+    my @borcatloop;
+    foreach my $thisborcat (sort keys %$labels) {
+                     my $selected = 1 if $thisbranch eq $branch;
+            my %row =(value => $thisborcat,
+                                                                     selected => $selected,
+                                    description => $labels->{$thisborcat},
+                            );
+            push @borcatloop, \%row;
+    }
+    
+    #Day
+    #Month
+    $template->param(
+                    CGIextChoice => $CGIextChoice,
+                    CGIsepChoice => $CGIsepChoice,
+                    branchloop =>\@branchloop,
+                    itemtypeloop =>\@itemtypeloop,
+                    borcatloop =>\@borcatloop,
+                    );
 output_html_with_http_headers $input, $cookie, $template->output;
 }
 
@@ -188,239 +188,243 @@ output_html_with_http_headers $input, $cookie, $template->output;
 
 
 sub calculate {
-       my ($line, $column, $filters) = @_;
-       my @mainloop;
-       my @loopfooter;
-       my @loopcol;
-       my @loopline;
-       my @looprow;
-       my %globalline;
-       my $grantotal =0;
+    my ($line, $column, $filters) = @_;
+    my @mainloop;
+    my @loopfooter;
+    my @loopcol;
+    my @loopline;
+    my @looprow;
+    my %globalline;
+    my $grantotal =0;
 # extract parameters
-       my $dbh = C4::Context->dbh;
+    my $dbh = C4::Context->dbh;
 
 # Filters
 # Checking filters
 #
-       my @loopfilter;
-       for (my $i=0;$i<=6;$i++) {
-               my %cell;
-               if ( @$filters[$i] ) {
-                       if (($i==1) and (@$filters[$i-1])) {
-                               $cell{err} = 1 if (@$filters[$i]<@$filters[$i-1]) ;
-                       }
-                       $cell{filter} .= @$filters[$i];
-                       $cell{crit} .="Issue From" if ($i==0);
-                       $cell{crit} .="Issue To" if ($i==1);
-                       $cell{crit} .="Return From" if ($i==2);
-                       $cell{crit} .="Return To" if ($i==3);
-                       $cell{crit} .="Branch" if ($i==4);
-                       $cell{crit} .="Doc Type" if ($i==5);
-                       $cell{crit} .="Bor Cat" if ($i==6);
-                       $cell{crit} .="Day" if ($i==7);
-                       $cell{crit} .="Month" if ($i==8);
-                       $cell{crit} .="Year" if ($i==9);
-                       push @loopfilter, \%cell;
-               }
-       }
-       my $colfield;
-       my $colorder;
-       if ($column){
-               $column = "issues.".$column if (($column=~/branchcode/) or ($column=~/timestamp/));
-               $column = "biblioitems.".$column if $column=~/itemtype/;
-               $column = "borrowers.".$column if $column=~/categorycode/;
-               my @colfilter ;
-               $colfilter[0] = @$filters[0] if ($column =~ /timestamp/ )  ;
-               $colfilter[1] = @$filters[1] if ($column =~ /timestamp/ )  ;
-               $colfilter[0] = @$filters[2] if ($column =~ /returndate/ )  ;
-               $colfilter[1] = @$filters[3] if ($column =~ /returndate/ )  ;
-               $colfilter[0] = @$filters[4] if ($column =~ /branch/ )  ;
-               $colfilter[0] = @$filters[5] if ($column =~ /itemtype/ )  ;
-               $colfilter[0] = @$filters[6] if ($column =~ /category/ )  ;
-       #       $colfilter[0] = @$filters[11] if ($column =~ /sort2/ ) ;
-               $colfilter[0] = @$filters[7] if ($column =~ /timestamp/ ) ;
-               $colfilter[0] = @$filters[8] if ($column =~ /timestamp/ ) ;
-               $colfilter[0] = @$filters[9] if ($column =~ /timestamp/ ) ;
-       #warn "filtre col ".$colfilter[0]." ".$colfilter[1];
-                                                                                               
-       # loop cols.
-               if ($column eq "Day") {
-                       #Display by day
-                       $column = "issues.timestamp";
-                       $colfield .="dayname($column)";  
-                       $colorder .="weekday($column)";
-               } elsif ($column eq "Month") {
-                       #Display by Month
-                       $column = "issues.timestamp";
-                       $colfield .="monthname($column)";  
-                       $colorder .="month($column)";  
-               } elsif ($column eq "Year") {
-                       #Display by Year
-                       $column = "issues.timestamp";
-                       $colfield .="Year($column)";
-                       $colorder .= $column;
-               } else {
-                       $colfield .= $column;
-                       $colorder .= $column;
-               }  
-               
-               my $strsth2;
-               $strsth2 .= "select distinctrow $colfield FROM `issues`,borrowers,biblioitems LEFT JOIN items ON (biblioitems.biblioitemnumber=items.biblioitemnumber) WHERE issues.itemnumber=items.itemnumber AND issues.borrowernumber=borrowers.borrowernumber and returndate is not null";
-               if (($column=~/timestamp/) or ($column=~/returndate/)){
-                       if ($colfilter[1] and ($colfilter[0])){
-                               $strsth2 .= " and $column between '$colfilter[0]' and '$colfilter[1]' " ;
-                       } elsif ($colfilter[1]) {
-                                       $strsth2 .= " and $column < '$colfilter[1]' " ;
-                       } elsif ($colfilter[0]) {
-                               $strsth2 .= " and $column > '$colfilter[0]' " ;
-                       }
-               } elsif ($colfilter[0]) {
-                       $colfilter[0] =~ s/\*/%/g;
-                       $strsth2 .= " and $column LIKE '$colfilter[0]' " ;
-               }
-               $strsth2 .=" group by $colfield";
-               $strsth2 .=" order by $colorder";
-               warn "". $strsth2;
-               
-               my $sth2 = $dbh->prepare( $strsth2 );
-               if (( @colfilter ) and ($colfilter[1])){
-                       $sth2->execute("'".$colfilter[0]."'","'".$colfilter[1]."'");
-               } elsif ($colfilter[0]) {
-                       $sth2->execute($colfilter[0]);
-               } else {
-                       $sth2->execute;
-               }
-               
-       
-               while (my ($celvalue) = $sth2->fetchrow) {
-                       my %cell;
-                       $cell{coltitle} = ($celvalue?$celvalue:"NULL");
-                       push @loopcol, \%cell;
-               }
-       #       warn "fin des titres colonnes";
-       }
-       
-       my $i=0;
+    my @loopfilter;
+    for (my $i=0;$i<=6;$i++) {
+        my %cell;
+        if ( @$filters[$i] ) {
+            if (($i==1) and (@$filters[$i-1])) {
+                $cell{err} = 1 if (@$filters[$i]<@$filters[$i-1]) ;
+            }
+            # format the dates filters, otherwise just fill as is
+            if ($i>=2) {
+                $cell{filter} .= @$filters[$i];
+            } else {
+                $cell{filter} .= format_date(@$filters[$i]);
+            }            $cell{crit} .="Issue From" if ($i==0);
+            $cell{crit} .="Issue To" if ($i==1);
+            $cell{crit} .="Return From" if ($i==2);
+            $cell{crit} .="Return To" if ($i==3);
+            $cell{crit} .="Branch" if ($i==4);
+            $cell{crit} .="Doc Type" if ($i==5);
+            $cell{crit} .="Bor Cat" if ($i==6);
+            $cell{crit} .="Day" if ($i==7);
+            $cell{crit} .="Month" if ($i==8);
+            $cell{crit} .="Year" if ($i==9);
+            push @loopfilter, \%cell;
+        }
+    }
+    my $colfield;
+    my $colorder;
+    if ($column){
+        $column = "issues.".$column if (($column=~/branchcode/) or ($column=~/timestamp/));
+        $column = "biblioitems.".$column if $column=~/itemtype/;
+        $column = "borrowers.".$column if $column=~/categorycode/;
+        my @colfilter ;
+        $colfilter[0] = @$filters[0] if ($column =~ /timestamp/ )  ;
+        $colfilter[1] = @$filters[1] if ($column =~ /timestamp/ )  ;
+        $colfilter[0] = @$filters[2] if ($column =~ /returndate/ )  ;
+        $colfilter[1] = @$filters[3] if ($column =~ /returndate/ )  ;
+        $colfilter[0] = @$filters[4] if ($column =~ /branch/ )  ;
+        $colfilter[0] = @$filters[5] if ($column =~ /itemtype/ )  ;
+        $colfilter[0] = @$filters[6] if ($column =~ /category/ )  ;
+    #  $colfilter[0] = @$filters[11] if ($column =~ /sort2/ ) ;
+        $colfilter[0] = @$filters[7] if ($column =~ /timestamp/ ) ;
+        $colfilter[0] = @$filters[8] if ($column =~ /timestamp/ ) ;
+        $colfilter[0] = @$filters[9] if ($column =~ /timestamp/ ) ;
+    #warn "filtre col ".$colfilter[0]." ".$colfilter[1];
+                                                
+    # loop cols.
+        if ($column eq "Day") {
+            #Display by day
+            $column = "issues.timestamp";
+            $colfield .="dayname($column)";  
+            $colorder .="weekday($column)";
+        } elsif ($column eq "Month") {
+            #Display by Month
+            $column = "issues.timestamp";
+            $colfield .="monthname($column)";  
+            $colorder .="month($column)";  
+        } elsif ($column eq "Year") {
+            #Display by Year
+            $column = "issues.timestamp";
+            $colfield .="Year($column)";
+            $colorder .= $column;
+        } else {
+            $colfield .= $column;
+            $colorder .= $column;
+        }  
+        
+        my $strsth2;
+        $strsth2 .= "select distinctrow $colfield FROM `issues`,borrowers,biblioitems LEFT JOIN items ON (biblioitems.biblioitemnumber=items.biblioitemnumber) WHERE issues.itemnumber=items.itemnumber AND issues.borrowernumber=borrowers.borrowernumber and returndate is not null";
+        if (($column=~/timestamp/) or ($column=~/returndate/)){
+            if ($colfilter[1] and ($colfilter[0])){
+                $strsth2 .= " and $column between '$colfilter[0]' and '$colfilter[1]' " ;
+            } elsif ($colfilter[1]) {
+                    $strsth2 .= " and $column < '$colfilter[1]' " ;
+            } elsif ($colfilter[0]) {
+                $strsth2 .= " and $column > '$colfilter[0]' " ;
+            }
+        } elsif ($colfilter[0]) {
+            $colfilter[0] =~ s/\*/%/g;
+            $strsth2 .= " and $column LIKE '$colfilter[0]' " ;
+        }
+        $strsth2 .=" group by $colfield";
+        $strsth2 .=" order by $colorder";
+        warn "". $strsth2;
+        
+        my $sth2 = $dbh->prepare( $strsth2 );
+        if (( @colfilter ) and ($colfilter[1])){
+            $sth2->execute("'".$colfilter[0]."'","'".$colfilter[1]."'");
+        } elsif ($colfilter[0]) {
+            $sth2->execute($colfilter[0]);
+        } else {
+            $sth2->execute;
+        }
+        
+    
+        while (my ($celvalue) = $sth2->fetchrow) {
+            my %cell;
+            $cell{coltitle} = ($celvalue?$celvalue:"NULL");
+            push @loopcol, \%cell;
+        }
+    #  warn "fin des titres colonnes";
+    }
+    
+    my $i=0;
 #      my @totalcol;
-       my $hilighted=-1;
-       
-       #Initialization of cell values.....
-       my @table;
-       
+    my $hilighted=-1;
+    
+    #Initialization of cell values.....
+    my @table;
+    
 #      warn "init table";
-       for (my $i=1;$i<=$line;$i++) {
-               foreach my $col ( @loopcol ) {
+    for (my $i=1;$i<=$line;$i++) {
+        foreach my $col ( @loopcol ) {
 #                      warn " init table : $row->{rowtitle} / $col->{coltitle} ";
-                       $table[$i]->{($col->{coltitle})?$col->{coltitle}:"total"}->{'name'}=0;
-               }
-       }
+            $table[$i]->{($col->{coltitle})?$col->{coltitle}:"total"}->{'name'}=0;
+        }
+    }
 
 
 # preparing calculation
-       my $strcalc ;
-       
+    my $strcalc ;
+    
 # Processing average loanperiods
-       $strcalc .= "SELECT DISTINCT biblio.title, COUNT(biblio.biblionumber) AS RANK, biblio.biblionumber AS ID";
-       $strcalc .= " , $colfield " if ($colfield);
-       $strcalc .= " FROM `issues`,borrowers,(items LEFT JOIN biblioitems ON biblioitems.biblioitemnumber=items.biblioitemnumber) LEFT JOIN biblio ON (biblio.biblionumber=items.biblionumber) WHERE issues.itemnumber=items.itemnumber AND issues.borrowernumber=borrowers.borrowernumber and returndate is not null";
+    $strcalc .= "SELECT DISTINCT biblio.title, COUNT(biblio.biblionumber) AS RANK, biblio.biblionumber AS ID";
+    $strcalc .= " , $colfield " if ($colfield);
+    $strcalc .= " FROM `issues`,borrowers,(items LEFT JOIN biblioitems ON biblioitems.biblioitemnumber=items.biblioitemnumber) LEFT JOIN biblio ON (biblio.biblionumber=items.biblionumber) WHERE issues.itemnumber=items.itemnumber AND issues.borrowernumber=borrowers.borrowernumber and returndate is not null";
 
-       @$filters[0]=~ s/\*/%/g if (@$filters[0]);
-       $strcalc .= " AND issues.timestamp > '" . @$filters[0] ."'" if ( @$filters[0] );
-       @$filters[1]=~ s/\*/%/g if (@$filters[1]);
-       $strcalc .= " AND issues.timestamp < '" . @$filters[1] ."'" if ( @$filters[1] );
-       @$filters[2]=~ s/\*/%/g if (@$filters[2]);
-       $strcalc .= " AND issues.returndate > '" . @$filters[2] ."'" if ( @$filters[2] );
-       @$filters[3]=~ s/\*/%/g if (@$filters[3]);
-       $strcalc .= " AND issues.returndate < '" . @$filters[3] ."'" if ( @$filters[3] );
-       @$filters[4]=~ s/\*/%/g if (@$filters[4]);
-       $strcalc .= " AND issues.branchcode like '" . @$filters[4] ."'" if ( @$filters[4] );
-       @$filters[5]=~ s/\*/%/g if (@$filters[5]);
-       $strcalc .= " AND biblioitems.itemtype like '" . @$filters[5] ."'" if ( @$filters[5] );
-       @$filters[6]=~ s/\*/%/g if (@$filters[6]);
-       $strcalc .= " AND borrowers.categorycode like '" . @$filters[6] ."'" if ( @$filters[6] );
-       @$filters[7]=~ s/\*/%/g if (@$filters[7]);
-       $strcalc .= " AND dayname(issues.timestamp) like '" . @$filters[7]."'" if (@$filters[7]);
-       @$filters[8]=~ s/\*/%/g if (@$filters[8]);
-       $strcalc .= " AND monthname(issues.timestamp) like '" . @$filters[8]."'" if (@$filters[8]);
-       @$filters[9]=~ s/\*/%/g if (@$filters[9]);
-       $strcalc .= " AND year(issues.timestamp) like '" . @$filters[9] ."'" if ( @$filters[9] );
-       
-       $strcalc .= " group by biblio.biblionumber";
-       $strcalc .= ", $colfield" if ($column);
-       $strcalc .= " order by RANK DESC";
-       $strcalc .= ", $colfield " if ($colfield);
+    @$filters[0]=~ s/\*/%/g if (@$filters[0]);
+    $strcalc .= " AND issues.timestamp > '" . @$filters[0] ."'" if ( @$filters[0] );
+    @$filters[1]=~ s/\*/%/g if (@$filters[1]);
+    $strcalc .= " AND issues.timestamp < '" . @$filters[1] ."'" if ( @$filters[1] );
+    @$filters[2]=~ s/\*/%/g if (@$filters[2]);
+    $strcalc .= " AND issues.returndate > '" . @$filters[2] ."'" if ( @$filters[2] );
+    @$filters[3]=~ s/\*/%/g if (@$filters[3]);
+    $strcalc .= " AND issues.returndate < '" . @$filters[3] ."'" if ( @$filters[3] );
+    @$filters[4]=~ s/\*/%/g if (@$filters[4]);
+    $strcalc .= " AND issues.branchcode like '" . @$filters[4] ."'" if ( @$filters[4] );
+    @$filters[5]=~ s/\*/%/g if (@$filters[5]);
+    $strcalc .= " AND biblioitems.itemtype like '" . @$filters[5] ."'" if ( @$filters[5] );
+    @$filters[6]=~ s/\*/%/g if (@$filters[6]);
+    $strcalc .= " AND borrowers.categorycode like '" . @$filters[6] ."'" if ( @$filters[6] );
+    @$filters[7]=~ s/\*/%/g if (@$filters[7]);
+    $strcalc .= " AND dayname(issues.timestamp) like '" . @$filters[7]."'" if (@$filters[7]);
+    @$filters[8]=~ s/\*/%/g if (@$filters[8]);
+    $strcalc .= " AND monthname(issues.timestamp) like '" . @$filters[8]."'" if (@$filters[8]);
+    @$filters[9]=~ s/\*/%/g if (@$filters[9]);
+    $strcalc .= " AND year(issues.timestamp) like '" . @$filters[9] ."'" if ( @$filters[9] );
+    
+    $strcalc .= " group by biblio.biblionumber";
+    $strcalc .= ", $colfield" if ($column);
+    $strcalc .= " order by RANK DESC";
+    $strcalc .= ", $colfield " if ($colfield);
 #      my $max;
 #      if (@loopcol) {
 #              $max = $line*@loopcol;
 #      } else { $max=$line;}
 #      $strcalc .= " LIMIT 0,$max";
-       warn "SQL :". $strcalc;
-       
-       my $dbcalc = $dbh->prepare($strcalc);
-       $dbcalc->execute;
+    warn "SQL :". $strcalc;
+    
+    my $dbcalc = $dbh->prepare($strcalc);
+    $dbcalc->execute;
 #      warn "filling table";
-       my $previous_col;
-       my %indice;
-       while (my  @data = $dbcalc->fetchrow) {
-               my ($row, $rank, $id, $col )=@data;
-               $col = "zzEMPTY" if ($col eq undef);
-               $indice{$col}=1 if (not($indice{$col}));
-               $table[$indice{$col}]->{$col}->{'name'}=$row;
-               $table[$indice{$col}]->{$col}->{'count'}=$rank;
-               $table[$indice{$col}]->{$col}->{'link'}=$id;
+    my $previous_col;
+    my %indice;
+    while (my  @data = $dbcalc->fetchrow) {
+        my ($row, $rank, $id, $col )=@data;
+        $col = "zzEMPTY" if ($col eq undef);
+        $indice{$col}=1 if (not($indice{$col}));
+        $table[$indice{$col}]->{$col}->{'name'}=$row;
+        $table[$indice{$col}]->{$col}->{'count'}=$rank;
+        $table[$indice{$col}]->{$col}->{'link'}=$id;
 #              warn " ".$i." ".$col. " ".$row;
-               $indice{$col}++;
-       }
-       
-       push @loopcol,{coltitle => "Global"} if not($column);
-       
-       for ($i=1; $i<=$line;$i++) {
-               my @loopcell;
-               warn " $i";
-               #@loopcol ensures the order for columns is common with column titles
-               # and the number matches the number of columns
-               my $colcount=0;
-               foreach my $col ( @loopcol ) {
+        $indice{$col}++;
+    }
+    
+    push @loopcol,{coltitle => "Global"} if not($column);
+    
+    for ($i=1; $i<=$line;$i++) {
+        my @loopcell;
+        warn " $i";
+        #@loopcol ensures the order for columns is common with column titles
+        # and the number matches the number of columns
+        my $colcount=0;
+        foreach my $col ( @loopcol ) {
 #                      warn " colonne :$col->{coltitle}";
-                       my $value;
-                       my $count=0;
-                       my $link;
-                       if (@loopcol){
-                               $value =$table[$i]->{(($col->{coltitle} eq "NULL") or ($col->{coltitle} eq "Global"))?"zzEMPTY":$col->{coltitle}}->{'name'};
-                               $count =$table[$i]->{(($col->{coltitle} eq "NULL") or ($col->{coltitle} eq "Global"))?"zzEMPTY":$col->{coltitle}}->{'count'};
-                               $link =$table[$i]->{(($col->{coltitle} eq "NULL") or ($col->{coltitle} eq "Global"))?"zzEMPTY":$col->{coltitle}}->{'link'};
-                       } else {
-                               $value =$table[$i]->{"zzEMPTY"}->{'name'};
-                               $count =$table[$i]->{"zzEMPTY"}->{'count'};
-                               $link =$table[$i]->{"zzEMPTY"}->{'link'};
-                       }
+            my $value;
+            my $count=0;
+            my $link;
+            if (@loopcol){
+                $value =$table[$i]->{(($col->{coltitle} eq "NULL") or ($col->{coltitle} eq "Global"))?"zzEMPTY":$col->{coltitle}}->{'name'};
+                $count =$table[$i]->{(($col->{coltitle} eq "NULL") or ($col->{coltitle} eq "Global"))?"zzEMPTY":$col->{coltitle}}->{'count'};
+                $link =$table[$i]->{(($col->{coltitle} eq "NULL") or ($col->{coltitle} eq "Global"))?"zzEMPTY":$col->{coltitle}}->{'link'};
+            } else {
+                $value =$table[$i]->{"zzEMPTY"}->{'name'};
+                $count =$table[$i]->{"zzEMPTY"}->{'count'};
+                $link =$table[$i]->{"zzEMPTY"}->{'link'};
+            }
 #                      warn " ".$i ." value:$value count:$count reference:$link";
-                       push @loopcell, {value => $value, count =>$count, reference => $link} ;
-               }
-               #warn "row : $row colcount:$colcount";
-               #my $total = $table[$i]->{totalrow}/$colcount if ($colcount>0);
-               push @looprow,{ 'rowtitle' => $i ,
-                                               'loopcell' => \@loopcell,
-                                               'hilighted' => ($hilighted >0),
-                                               #'totalrow' => ($total)?sprintf("%.2f",$total):0
-                                       };
-               $hilighted = -$hilighted;
-       }
+            push @loopcell, {value => $value, count =>$count, reference => $link} ;
+        }
+        #warn "row : $row colcount:$colcount";
+        #my $total = $table[$i]->{totalrow}/$colcount if ($colcount>0);
+        push @looprow,{ 'rowtitle' => $i ,
+                        'loopcell' => \@loopcell,
+                        'hilighted' => ($hilighted >0),
+                        #'totalrow' => ($total)?sprintf("%.2f",$total):0
+                    };
+        $hilighted = -$hilighted;
+    }
 #      
-                       
+            
 
-       # the header of the table
-       $globalline{loopfilter}=\@loopfilter;
-       # the core of the table
-       $globalline{looprow} = \@looprow;
-       $globalline{loopcol} = \@loopcol;
+    # the header of the table
+    $globalline{loopfilter}=\@loopfilter;
+    # the core of the table
+    $globalline{looprow} = \@looprow;
+    $globalline{loopcol} = \@loopcol;
 #      # the foot (totals by borrower type)
-       $globalline{loopfooter} = \@loopfooter;
-       $globalline{total}= $grantotal;
-       $globalline{line} = $line;
-       $globalline{column} = $column;
-       push @mainloop,\%globalline;
-       return \@mainloop;
+    $globalline{loopfooter} = \@loopfooter;
+    $globalline{total}= $grantotal;
+    $globalline{line} = $line;
+    $globalline{column} = $column;
+    push @mainloop,\%globalline;
+    return \@mainloop;
 }
 
 1;
index 8cb2176..f82847a 100755 (executable)
@@ -27,6 +27,7 @@ use C4::Branch; # GetBranches
 use C4::Output;
 use C4::Koha;
 use C4::Circulation;
+use C4::Date;
 use Date::Calc qw(Delta_Days);
 
 =head1 NAME
@@ -45,6 +46,10 @@ my $fullreportname = "reports/issues_avg_stats.tmpl";
 my $line = $input->param("Line");
 my $column = $input->param("Column");
 my @filters = $input->param("Filter");
+$filters[0]=format_date_in_iso($filters[0]);
+$filters[1]=format_date_in_iso($filters[1]);
+$filters[2]=format_date_in_iso($filters[2]);
+$filters[3]=format_date_in_iso($filters[3]);
 my $podsp = $input->param("IssueDisplay");
 my $rodsp = $input->param("ReturnDisplay");
 my $calc = $input->param("Cellvalue");
@@ -54,182 +59,180 @@ my $mime = $input->param("MIME");
 my $del = $input->param("sep");
 #warn "calcul : ".$calc;
 my ($template, $borrowernumber, $cookie)
-       = get_template_and_user({template_name => $fullreportname,
-                               query => $input,
-                               type => "intranet",
-                               authnotrequired => 0,
-                               flagsrequired => {reports => 1},
-                               debug => 1,
-                               });
+    = get_template_and_user({template_name => $fullreportname,
+                query => $input,
+                type => "intranet",
+                authnotrequired => 0,
+                flagsrequired => {reports => 1},
+                debug => 1,
+                    });
 $template->param(do_it => $do_it,
-               intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
-               intranetstylesheet => C4::Context->preference("intranetstylesheet"),
-               IntranetNav => C4::Context->preference("IntranetNav"),
-               );
+        DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(),
+    );
 if ($do_it) {
 # Displaying results
-       my $results = calculate($line, $column, $rodsp, $podsp, $calc, \@filters);
-       if ($output eq "screen"){
+    my $results = calculate($line, $column, $rodsp, $podsp, $calc, \@filters);
+    if ($output eq "screen"){
 # Printing results to screen
-               $template->param(mainloop => $results);
-               output_html_with_http_headers $input, $cookie, $template->output;
-               exit(1);
-       } else {
+        $template->param(mainloop => $results);
+        output_html_with_http_headers $input, $cookie, $template->output;
+        exit(1);
+    } else {
 # Printing to a csv file
-               print $input->header(-type => 'application/vnd.sun.xml.calc',
-                                     -encoding    => 'utf-8',
-                       -attachment=>"$basename.csv",
-                       -filename=>"$basename.csv" );
-               my $cols = @$results[0]->{loopcol};
-               my $lines = @$results[0]->{looprow};
-               my $sep;
-               $sep =C4::Context->preference("delimiter");
+        print $input->header(-type => 'application/vnd.sun.xml.calc',
+                                    -encoding    => 'utf-8',
+            -attachment=>"$basename.csv",
+            -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;
+        print @$results[0]->{line} ."/". @$results[0]->{column} .$sep;
 # Other header
-               foreach my $col ( @$cols ) {
-                       print $col->{coltitle}.$sep;
-               }
-               print "Total\n";
+        foreach my $col ( @$cols ) {
+            print $col->{coltitle}.$sep;
+        }
+        print "Total\n";
 # Table
-               foreach my $line ( @$lines ) {
-                       my $x = $line->{loopcell};
-                       print $line->{rowtitle}.$sep;
-                       foreach my $cell (@$x) {
-                               print $cell->{value}.$sep;
-                       }
-                       print $line->{totalrow};
-                       print "\n";
-               }
+        foreach my $line ( @$lines ) {
+            my $x = $line->{loopcell};
+            print $line->{rowtitle}.$sep;
+            foreach my $cell (@$x) {
+                print $cell->{value}.$sep;
+            }
+            print $line->{totalrow};
+            print "\n";
+        }
 # footer
-               print "TOTAL";
-               $cols = @$results[0]->{loopfooter};
-               foreach my $col ( @$cols ) {
-                       print $sep.$col->{totalcol};
-               }
-               print $sep.@$results[0]->{total};
-               exit(1);
-       }
+        print "TOTAL";
+        $cols = @$results[0]->{loopfooter};
+        foreach my $col ( @$cols ) {
+            print $sep.$col->{totalcol};
+        }
+        print $sep.@$results[0]->{total};
+        exit(1);
+    }
 # Displaying choices
 } else {
-       my $dbh = C4::Context->dbh;
-       my @values;
-       my %labels;
-       my %select;
-       my $req;
-       $req = $dbh->prepare("select distinctrow categorycode,description from categories order by description");
-       $req->execute;
-       my @select;
-       push @select,"";
-       $select{""}="";
-       while (my ($value, $desc) =$req->fetchrow) {
-               push @select, $value;
-               $select{$value}=$desc;
-       }
-       my $CGIBorCat=CGI::scrolling_list( -name     => 'Filter',
-                               -id => 'borcat',
-                               -values   => \@select,
-                               -labels   => \%select,
-                               -size     => 1,
-                               -multiple => 0 );
-       
-       $req = $dbh->prepare( "select distinctrow itemtype,description from itemtypes order by description");
-       $req->execute;
-       undef @select;
-       undef %select;
-       push @select,"";
-       $select{""}="";
-       while (my ($value,$desc) =$req->fetchrow) {
-               push @select, $value;
-               $select{$value}=$desc;
-       }
-       my $CGIItemTypes=CGI::scrolling_list( -name     => 'Filter',
-                               -id => 'itemtypes',
-                               -values   => \@select,
-                               -labels    => \%select,
-                               -size     => 1,
-                               -multiple => 0 );
-       
-       $req = $dbh->prepare("select distinctrow sort1 from borrowers where sort1 is not null order by sort1");
-       $req->execute;
-       undef @select;
-       push @select,"";
-       my $hassort1;
-       while (my ($value) =$req->fetchrow) {
-               $hassort1 =1 if ($value);
-               push @select, $value;
-       }
-       my $branches=GetBranches();
-       my @select_branch;
-       my %select_branches;
-       push @select_branch,"";
-       $select_branches{""} = "";
-       foreach my $branch (keys %$branches) {
-               push @select_branch, $branch;
-               $select_branches{$branch} = $branches->{$branch}->{'branchname'};
-       }
-       my $CGIBranch=CGI::scrolling_list( -name     => 'Filter',
-                               -id => 'branch',
-                               -values   => \@select_branch,
-                               -labels   => \%select_branches,
-                               -size     => 1,
-                               -multiple => 0 );
-       
-       my $CGISort1=CGI::scrolling_list( -name     => 'Filter',
-                               -id => 'sort1',
-                               -values   => \@select,
-                               -size     => 1,
-                               -multiple => 0 );
-       
-       $req = $dbh->prepare("select distinctrow sort2 from borrowers where sort2 is not null order by sort2");
-       $req->execute;
-       undef @select;
-       push @select,"";
-       my $hassort2;
-       my $hglghtsort2;
-       while (my ($value) =$req->fetchrow) {
-               $hassort2 =1 if ($value);
-               $hglghtsort2= !($hassort1);
-               push @select, $value;
-       }
-       my $CGISort2=CGI::scrolling_list( -name     => 'Filter',
-                               -id => 'sort2',
-                               -values   => \@select,
-                               -size     => 1,
-                               -multiple => 0 );
-       
-       my @mime = ( C4::Context->preference("MIME") );
+    my $dbh = C4::Context->dbh;
+    my @values;
+    my %labels;
+    my %select;
+    my $req;
+    $req = $dbh->prepare("select distinctrow categorycode,description from categories order by description");
+    $req->execute;
+    my @select;
+    push @select,"";
+    $select{""}="";
+    while (my ($value, $desc) =$req->fetchrow) {
+        push @select, $value;
+        $select{$value}=$desc;
+    }
+    my $CGIBorCat=CGI::scrolling_list( -name     => 'Filter',
+                -id => 'borcat',
+                -values   => \@select,
+                -labels   => \%select,
+                -size     => 1,
+                -multiple => 0 );
+    
+    $req = $dbh->prepare( "select distinctrow itemtype,description from itemtypes order by description");
+    $req->execute;
+    undef @select;
+    undef %select;
+    push @select,"";
+    $select{""}="";
+    while (my ($value,$desc) =$req->fetchrow) {
+        push @select, $value;
+        $select{$value}=$desc;
+    }
+    my $CGIItemTypes=CGI::scrolling_list( -name     => 'Filter',
+                -id => 'itemtypes',
+                -values   => \@select,
+                -labels    => \%select,
+                -size     => 1,
+                -multiple => 0 );
+    
+    $req = $dbh->prepare("select distinctrow sort1 from borrowers where sort1 is not null order by sort1");
+    $req->execute;
+    undef @select;
+    push @select,"";
+    my $hassort1;
+    while (my ($value) =$req->fetchrow) {
+        $hassort1 =1 if ($value);
+        push @select, $value;
+    }
+    my $branches=GetBranches();
+    my @select_branch;
+    my %select_branches;
+    push @select_branch,"";
+    $select_branches{""} = "";
+    foreach my $branch (keys %$branches) {
+        push @select_branch, $branch;
+        $select_branches{$branch} = $branches->{$branch}->{'branchname'};
+    }
+    my $CGIBranch=CGI::scrolling_list( -name     => 'Filter',
+                -id => 'branch',
+                -values   => \@select_branch,
+                -labels   => \%select_branches,
+                -size     => 1,
+                -multiple => 0 );
+    
+    my $CGISort1=CGI::scrolling_list( -name     => 'Filter',
+                -id => 'sort1',
+                -values   => \@select,
+                -size     => 1,
+                -multiple => 0 );
+    
+    $req = $dbh->prepare("select distinctrow sort2 from borrowers where sort2 is not null order by sort2");
+    $req->execute;
+    undef @select;
+    push @select,"";
+    my $hassort2;
+    my $hglghtsort2;
+    while (my ($value) =$req->fetchrow) {
+        $hassort2 =1 if ($value);
+        $hglghtsort2= !($hassort1);
+        push @select, $value;
+    }
+    my $CGISort2=CGI::scrolling_list( -name     => 'Filter',
+                -id => 'sort2',
+                -values   => \@select,
+                -size     => 1,
+                -multiple => 0 );
+    
+    my @mime = ( C4::Context->preference("MIME") );
 #      foreach my $mime (@mime){
 #              warn "".$mime;
 #      }
-       
-       my $CGIextChoice=CGI::scrolling_list(
-                               -name     => 'MIME',
-                               -id       => 'MIME',
-                               -values   => \@mime,
-                               -size     => 1,
-                               -multiple => 0 );
-       
-       my @dels = ( C4::Context->preference("delimiter") );
-       my $CGIsepChoice=CGI::scrolling_list(
-                               -name     => 'sep',
-                               -id       => 'sep',
-                               -values   => \@dels,
-                               -size     => 1,
-                               -multiple => 0 );
-       
-       $template->param(
-                                       CGIBorCat => $CGIBorCat,
-                                       CGIItemType => $CGIItemTypes,
-                                       CGIBranch => $CGIBranch,
-                                       hassort1=> $hassort1,
-                                       hassort2=> $hassort2,
-                                       HlghtSort2 => $hglghtsort2,
-                                       CGISort1 => $CGISort1,
-                                       CGISort2 => $CGISort2,
-                                       CGIextChoice => $CGIextChoice,
-                                       CGIsepChoice => $CGIsepChoice
-                                       );
+    
+    my $CGIextChoice=CGI::scrolling_list(
+                -name     => 'MIME',
+                -id       => 'MIME',
+                -values   => \@mime,
+                -size     => 1,
+                -multiple => 0 );
+    
+    my @dels = ( C4::Context->preference("delimiter") );
+    my $CGIsepChoice=CGI::scrolling_list(
+                -name     => 'sep',
+                -id       => 'sep',
+                -values   => \@dels,
+                -size     => 1,
+                -multiple => 0 );
+    
+    $template->param(
+                    CGIBorCat => $CGIBorCat,
+                    CGIItemType => $CGIItemTypes,
+                    CGIBranch => $CGIBranch,
+                    hassort1=> $hassort1,
+                    hassort2=> $hassort2,
+                    HlghtSort2 => $hglghtsort2,
+                    CGISort1 => $CGISort1,
+                    CGISort2 => $CGISort2,
+                    CGIextChoice => $CGIextChoice,
+                    CGIsepChoice => $CGIsepChoice
+                    );
 output_html_with_http_headers $input, $cookie, $template->output;
 }
 
@@ -237,358 +240,363 @@ output_html_with_http_headers $input, $cookie, $template->output;
 
 
 sub calculate {
-       my ($line, $column, $rodsp, $podsp, $process, $filters) = @_;
-       my @mainloop;
-       my @loopfooter;
-       my @loopcol;
-       my @loopline;
-       my @looprow;
-       my %globalline;
-       my $grantotal =0;
+    my ($line, $column, $rodsp, $podsp, $process, $filters) = @_;
+    my @mainloop;
+    my @loopfooter;
+    my @loopcol;
+    my @loopline;
+    my @looprow;
+    my %globalline;
+    my $grantotal =0;
 # extract parameters
-       my $dbh = C4::Context->dbh;
+    my $dbh = C4::Context->dbh;
 
 # Filters
 # Checking filters
 #
-       my @loopfilter;
-       for (my $i=0;$i<=6;$i++) {
-               my %cell;
-               if ( @$filters[$i] ) {
-                       if (($i==1) and (@$filters[$i-1])) {
-                               $cell{err} = 1 if (@$filters[$i]<@$filters[$i-1]) ;
-                       }
-                       $cell{filter} .= @$filters[$i];
-                       $cell{crit} .="Issue From" if ($i==0);
-                       $cell{crit} .="Issue To" if ($i==1);
-                       $cell{crit} .="Issue Month" if ($i==2);
-                       $cell{crit} .="Issue Day" if ($i==3);
-                       $cell{crit} .="Return From" if ($i==4);
-                       $cell{crit} .="Return To" if ($i==5);
-                       $cell{crit} .="Return Month" if ($i==6);
-                       $cell{crit} .="Return Day" if ($i==7);
-                       $cell{crit} .="Borrower Cat" if ($i==8);
-                       $cell{crit} .="Doc Type" if ($i==9);
-                       $cell{crit} .="Branch" if ($i==10);
-                       $cell{crit} .="Sort1" if ($i==11);
-                       $cell{crit} .="Sort2" if ($i==12);
-                       push @loopfilter, \%cell;
-               }
-       }
-       push @loopfilter,{crit=>"Issue Display",filter=>$rodsp} if ($rodsp);
-       push @loopfilter,{crit=>"Return Display",filter=>$podsp} if ($podsp);
+    my @loopfilter;
+    for (my $i=0;$i<=6;$i++) {
+        my %cell;
+        if ( @$filters[$i] ) {
+            if (($i==1) and (@$filters[$i-1])) {
+                $cell{err} = 1 if (@$filters[$i]<@$filters[$i-1]) ;
+            }
+            # format the dates filters, otherwise just fill as is
+            if ($i>=4) {
+                $cell{filter} .= @$filters[$i];
+            } else {
+                $cell{filter} .= format_date(@$filters[$i]);
+            }
+            $cell{crit} .="Issue From" if ($i==0);
+            $cell{crit} .="Issue To" if ($i==1);
+            $cell{crit} .="Issue Month" if ($i==2);
+            $cell{crit} .="Issue Day" if ($i==3);
+            $cell{crit} .="Return From" if ($i==4);
+            $cell{crit} .="Return To" if ($i==5);
+            $cell{crit} .="Return Month" if ($i==6);
+            $cell{crit} .="Return Day" if ($i==7);
+            $cell{crit} .="Borrower Cat" if ($i==8);
+            $cell{crit} .="Doc Type" if ($i==9);
+            $cell{crit} .="Branch" if ($i==10);
+            $cell{crit} .="Sort1" if ($i==11);
+            $cell{crit} .="Sort2" if ($i==12);
+            push @loopfilter, \%cell;
+        }
+    }
+    push @loopfilter,{crit=>"Issue Display",filter=>$rodsp} if ($rodsp);
+    push @loopfilter,{crit=>"Return Display",filter=>$podsp} if ($podsp);
 
-       
-       
-       my @linefilter;
+    
+    
+    my @linefilter;
 #      warn "filtres ".@filters[0];
 #      warn "filtres ".@filters[1];
 #      warn "filtres ".@filters[2];
 #      warn "filtres ".@filters[3];
-       $line = "issues.".$line if ($line=~/branchcode/) or ($line=~/timestamp/);
-       $line = "biblioitems.".$line if $line=~/itemtype/;
-       
-       $linefilter[0] = @$filters[0] if ($line =~ /timestamp/ )  ;
-       $linefilter[1] = @$filters[1] if ($line =~ /timestamp/ )  ;
-       $linefilter[2] = @$filters[2] if ($line =~ /timestamp/ )  ;
-       $linefilter[3] = @$filters[3] if ($line =~ /timestamp/ )  ;
-       $linefilter[0] = @$filters[4] if ($line =~ /returndate/ )  ;
-       $linefilter[1] = @$filters[5] if ($line =~ /returndate/ )  ;
-       $linefilter[2] = @$filters[6] if ($line =~ /returndate/ )  ;
-       $linefilter[3] = @$filters[7] if ($line =~ /returndate/ )  ;
-       $linefilter[0] = @$filters[8] if ($line =~ /category/ )  ;
-       $linefilter[0] = @$filters[9] if ($line =~ /itemtype/ )  ;
-       $linefilter[0] = @$filters[10] if ($line =~ /branch/ )  ;
+    $line = "issues.".$line if ($line=~/branchcode/) or ($line=~/timestamp/);
+    $line = "biblioitems.".$line if $line=~/itemtype/;
+    
+    $linefilter[0] = @$filters[0] if ($line =~ /timestamp/ )  ;
+    $linefilter[1] = @$filters[1] if ($line =~ /timestamp/ )  ;
+    $linefilter[2] = @$filters[2] if ($line =~ /timestamp/ )  ;
+    $linefilter[3] = @$filters[3] if ($line =~ /timestamp/ )  ;
+    $linefilter[0] = @$filters[4] if ($line =~ /returndate/ )  ;
+    $linefilter[1] = @$filters[5] if ($line =~ /returndate/ )  ;
+    $linefilter[2] = @$filters[6] if ($line =~ /returndate/ )  ;
+    $linefilter[3] = @$filters[7] if ($line =~ /returndate/ )  ;
+    $linefilter[0] = @$filters[8] if ($line =~ /category/ )  ;
+    $linefilter[0] = @$filters[9] if ($line =~ /itemtype/ )  ;
+    $linefilter[0] = @$filters[10] if ($line =~ /branch/ )  ;
 #      $linefilter[0] = @$filters[11] if ($line =~ /sort2/ ) ;
-       $linefilter[0] = @$filters[11] if ($line =~ /sort1/ ) ;
-       $linefilter[0] = @$filters[12] if ($line =~ /sort2/ ) ;
+    $linefilter[0] = @$filters[11] if ($line =~ /sort1/ ) ;
+    $linefilter[0] = @$filters[12] if ($line =~ /sort2/ ) ;
 #warn "filtre lignes".$linefilter[0]." ".$linefilter[1];
 # 
-       $column = "issues.".$column if (($column=~/branchcode/) or ($column=~/timestamp/));
-       $column = "biblioitems.".$column if $column=~/itemtype/;
-       my @colfilter ;
-       $colfilter[0] = @$filters[0] if ($column =~ /timestamp/ )  ;
-       $colfilter[1] = @$filters[1] if ($column =~ /timestamp/ )  ;
-       $colfilter[2] = @$filters[2] if ($column =~ /timestamp/ )  ;
-       $colfilter[3] = @$filters[3] if ($column =~ /timestamp/ )  ;
-       $colfilter[0] = @$filters[4] if ($column =~ /returndate/ )  ;
-       $colfilter[1] = @$filters[5] if ($column =~ /returndate/ )  ;
-       $colfilter[2] = @$filters[6] if ($column =~ /returndate/ )  ;
-       $colfilter[3] = @$filters[7] if ($column =~ /returndate/ )  ;
-       $colfilter[0] = @$filters[8] if ($column =~ /category/ )  ;
-       $colfilter[0] = @$filters[9] if ($column =~ /itemtype/ )  ;
-       $colfilter[0] = @$filters[10] if ($column =~ /branch/ )  ;
+    $column = "issues.".$column if (($column=~/branchcode/) or ($column=~/timestamp/));
+    $column = "biblioitems.".$column if $column=~/itemtype/;
+    my @colfilter ;
+    $colfilter[0] = @$filters[0] if ($column =~ /timestamp/ )  ;
+    $colfilter[1] = @$filters[1] if ($column =~ /timestamp/ )  ;
+    $colfilter[2] = @$filters[2] if ($column =~ /timestamp/ )  ;
+    $colfilter[3] = @$filters[3] if ($column =~ /timestamp/ )  ;
+    $colfilter[0] = @$filters[4] if ($column =~ /returndate/ )  ;
+    $colfilter[1] = @$filters[5] if ($column =~ /returndate/ )  ;
+    $colfilter[2] = @$filters[6] if ($column =~ /returndate/ )  ;
+    $colfilter[3] = @$filters[7] if ($column =~ /returndate/ )  ;
+    $colfilter[0] = @$filters[8] if ($column =~ /category/ )  ;
+    $colfilter[0] = @$filters[9] if ($column =~ /itemtype/ )  ;
+    $colfilter[0] = @$filters[10] if ($column =~ /branch/ )  ;
 #      $colfilter[0] = @$filters[11] if ($column =~ /sort2/ ) ;
-       $colfilter[0] = @$filters[11] if ($column =~ /sort1/ ) ;
-       $colfilter[0] = @$filters[12] if ($column =~ /sort2/ ) ;
+    $colfilter[0] = @$filters[11] if ($column =~ /sort1/ ) ;
+    $colfilter[0] = @$filters[12] if ($column =~ /sort2/ ) ;
 #warn "filtre col ".$colfilter[0]." ".$colfilter[1];
-                                              
+                                            
 # 1st, loop rows.                             
-       my $linefield;
-       my $lineorder;                               
-       if ((($line =~/timestamp/) and ($podsp == 1)) or  (($line =~/returndate/) and ($rodsp == 1))) {
-               #Display by day
-               $linefield .="dayname($line)";  
-               $lineorder .="weekday($line)";  
-       } elsif ((($line =~/timestamp/) and ($podsp == 2)) or  (($line =~/returndate/) and ($rodsp == 2))) {
-               #Display by Month
-               $linefield .="monthname($line)";  
-               $lineorder .="month($line)";  
-       } elsif ((($line =~/timestamp/) and ($podsp == 3)) or  (($line =~/returndate/) and ($rodsp == 3))) {
-               #Display by Year
-               $linefield .="Year($line)";
-               $lineorder .= $line;  
-       } elsif (($line=~/timestamp/) or ($line=~/returndate/)){
-               $linefield .= "date_format(\'$line\',\"%Y-%m-%d\")";
-               $lineorder .= $line;  
-       } else {
-               $linefield .= $line;
-               $lineorder .= $line;  
-       }  
-       
-       my $strsth;
-       $strsth .= "select distinctrow $linefield FROM `issues`,borrowers,biblioitems LEFT JOIN items ON (biblioitems.biblioitemnumber=items.biblioitemnumber) LEFT JOIN issuingrules ON (issuingrules.branchcode=issues.branchcode AND  issuingrules.itemtype=biblioitems.itemtype AND  issuingrules.categorycode=borrowers.categorycode) WHERE issues.itemnumber=items.itemnumber AND issues.borrowernumber=borrowers.borrowernumber and returndate is not null";
-       
-       if (($line=~/timestamp/) or ($line=~/returndate/)){
-               if ($linefilter[1] and ($linefilter[0])){
-                       $strsth .= " and $line between '$linefilter[0]' and '$linefilter[1]' " ;
-               } elsif ($linefilter[1]) {
-                               $strsth .= " and $line < \'$linefilter[1]\' " ;
-               } elsif ($linefilter[0]) {
-                       $strsth .= " and $line > \'$linefilter[0]\' " ;
-               }
-               if ($linefilter[2]){
-                       $strsth .= " and dayname($line) = '$linefilter[2]' " ;
-               }
-               if ($linefilter[3]){
-                       $strsth .= " and monthname($line) = '$linefilter[3]' " ;
-               }
-       } elsif ($linefilter[0]) {
-               $linefilter[0] =~ s/\*/%/g;
-               $strsth .= " and $line LIKE '$linefilter[0]' " ;
-       }
-       $strsth .=" group by $linefield";
-       $strsth .=" order by $lineorder";
-       warn "". $strsth;
-       
-       my $sth = $dbh->prepare( $strsth );
-       $sth->execute;
+    my $linefield;
+    my $lineorder;                               
+    if ((($line =~/timestamp/) and ($podsp == 1)) or  (($line =~/returndate/) and ($rodsp == 1))) {
+        #Display by day
+        $linefield .="dayname($line)";  
+        $lineorder .="weekday($line)";  
+    } elsif ((($line =~/timestamp/) and ($podsp == 2)) or  (($line =~/returndate/) and ($rodsp == 2))) {
+        #Display by Month
+        $linefield .="monthname($line)";  
+        $lineorder .="month($line)";  
+    } elsif ((($line =~/timestamp/) and ($podsp == 3)) or  (($line =~/returndate/) and ($rodsp == 3))) {
+        #Display by Year
+        $linefield .="Year($line)";
+        $lineorder .= $line;  
+    } elsif (($line=~/timestamp/) or ($line=~/returndate/)){
+        $linefield .= "date_format(\'$line\',\"%Y-%m-%d\")";
+        $lineorder .= $line;  
+    } else {
+        $linefield .= $line;
+        $lineorder .= $line;  
+    }  
+    
+    my $strsth;
+    $strsth .= "select distinctrow $linefield FROM `issues`,borrowers,biblioitems LEFT JOIN items ON (biblioitems.biblioitemnumber=items.biblioitemnumber) LEFT JOIN issuingrules ON (issuingrules.branchcode=issues.branchcode AND  issuingrules.itemtype=biblioitems.itemtype AND  issuingrules.categorycode=borrowers.categorycode) WHERE issues.itemnumber=items.itemnumber AND issues.borrowernumber=borrowers.borrowernumber and returndate is not null";
+    
+    if (($line=~/timestamp/) or ($line=~/returndate/)){
+        if ($linefilter[1] and ($linefilter[0])){
+            $strsth .= " and $line between '$linefilter[0]' and '$linefilter[1]' " ;
+        } elsif ($linefilter[1]) {
+                $strsth .= " and $line < \'$linefilter[1]\' " ;
+        } elsif ($linefilter[0]) {
+            $strsth .= " and $line > \'$linefilter[0]\' " ;
+        }
+        if ($linefilter[2]){
+            $strsth .= " and dayname($line) = '$linefilter[2]' " ;
+        }
+        if ($linefilter[3]){
+            $strsth .= " and monthname($line) = '$linefilter[3]' " ;
+        }
+    } elsif ($linefilter[0]) {
+        $linefilter[0] =~ s/\*/%/g;
+        $strsth .= " and $line LIKE '$linefilter[0]' " ;
+    }
+    $strsth .=" group by $linefield";
+    $strsth .=" order by $lineorder";
+    
+    my $sth = $dbh->prepare( $strsth );
+    $sth->execute;
 
-       
-       while ( my ($celvalue) = $sth->fetchrow) {
-               my %cell;
-               if ($celvalue) {
-                       $cell{rowtitle} = $celvalue;
-               } else {
-                       $cell{rowtitle} = "";
-               }
-               $cell{totalrow} = 0;
-               push @loopline, \%cell;
-       }
+    
+    while ( my ($celvalue) = $sth->fetchrow) {
+        my %cell;
+        if ($celvalue) {
+            $cell{rowtitle} = $celvalue;
+        } else {
+            $cell{rowtitle} = "";
+        }
+        $cell{totalrow} = 0;
+        push @loopline, \%cell;
+    }
 
 # 2nd, loop cols.
-       my $colfield;
-       my $colorder;                               
-       if ((($column =~/timestamp/) and ($podsp == 1)) or  (($column =~/returndate/) and ($rodsp == 1))) {
-               #Display by day
-               $colfield .="dayname($column)";  
-               $colorder .="weekday($column)";
-       } elsif ((($column =~/timestamp/) and ($podsp == 2)) or  (($column =~/returndate/) and ($rodsp == 2))) {
-               #Display by Month
-               $colfield .="monthname($column)";  
-               $colorder .="month($column)";  
-       } elsif ((($column =~/timestamp/) and ($podsp == 3)) or  (($column =~/returndate/) and ($rodsp == 3))) {
-               #Display by Year
-               $colfield .="Year($column)";
-               $colorder .= $column;
-       } elsif (($column=~/timestamp/) or ($column=~/returndate/)){
-               $colfield .= 'date_format( '."'".$column."'". ', "%Y-%m-%d")';
-               $colorder .= $column;
-       } else {
-               $colfield .= $column;
-               $colorder .= $column;
-       }  
-       
-       my $strsth2;
-       $strsth2 .= "select distinctrow $colfield FROM `issues`,borrowers,biblioitems LEFT JOIN items ON (biblioitems.biblioitemnumber=items.biblioitemnumber) LEFT JOIN issuingrules ON (issuingrules.branchcode=issues.branchcode AND  issuingrules.itemtype=biblioitems.itemtype AND  issuingrules.categorycode=borrowers.categorycode) WHERE issues.itemnumber=items.itemnumber AND issues.borrowernumber=borrowers.borrowernumber and returndate is not null";
-       
-       if (($column=~/timestamp/) or ($column=~/returndate/)){
-               if ($colfilter[1] and ($colfilter[0])){
-                       $strsth2 .= " and $column between '$colfilter[0]' and '$colfilter[1]' " ;
-               } elsif ($colfilter[1]) {
-                               $strsth2 .= " and $column < '$colfilter[1]' " ;
-               } elsif ($colfilter[0]) {
-                       $strsth2 .= " and $column > '$colfilter[0]' " ;
-               }
-               if ($colfilter[2]){
-                       $strsth2 .= " and dayname($column) = '$colfilter[2]' " ;
-               }
-               if ($colfilter[3]){
-                       $strsth2 .= " and monthname($column) = '$colfilter[3]' " ;
-               }
-       } elsif ($colfilter[0]) {
-               $colfilter[0] =~ s/\*/%/g;
-               $strsth2 .= " and $column LIKE '$colfilter[0]' " ;
-       }
-       $strsth2 .=" group by $colfield";
-       $strsth2 .=" order by $colorder";
-       warn "". $strsth2;
-       
-       my $sth2 = $dbh->prepare( $strsth2 );
-       if (( @colfilter ) and ($colfilter[1])){
-               $sth2->execute("'".$colfilter[0]."'","'".$colfilter[1]."'");
-       } elsif ($colfilter[0]) {
-               $sth2->execute($colfilter[0]);
-       } else {
-               $sth2->execute;
-       }
-       
+    my $colfield;
+    my $colorder;                               
+    if ((($column =~/timestamp/) and ($podsp == 1)) or  (($column =~/returndate/) and ($rodsp == 1))) {
+        #Display by day
+        $colfield .="dayname($column)";  
+        $colorder .="weekday($column)";
+    } elsif ((($column =~/timestamp/) and ($podsp == 2)) or  (($column =~/returndate/) and ($rodsp == 2))) {
+        #Display by Month
+        $colfield .="monthname($column)";  
+        $colorder .="month($column)";  
+    } elsif ((($column =~/timestamp/) and ($podsp == 3)) or  (($column =~/returndate/) and ($rodsp == 3))) {
+        #Display by Year
+        $colfield .="Year($column)";
+        $colorder .= $column;
+    } elsif (($column=~/timestamp/) or ($column=~/returndate/)){
+        $colfield .= 'date_format( '."'".$column."'". ', "%Y-%m-%d")';
+        $colorder .= $column;
+    } else {
+        $colfield .= $column;
+        $colorder .= $column;
+    }  
+    
+    my $strsth2;
+    $strsth2 .= "select distinctrow $colfield FROM `issues`,borrowers,biblioitems LEFT JOIN items ON (biblioitems.biblioitemnumber=items.biblioitemnumber) LEFT JOIN issuingrules ON (issuingrules.branchcode=issues.branchcode AND  issuingrules.itemtype=biblioitems.itemtype AND  issuingrules.categorycode=borrowers.categorycode) WHERE issues.itemnumber=items.itemnumber AND issues.borrowernumber=borrowers.borrowernumber and returndate is not null";
+    
+    if (($column=~/timestamp/) or ($column=~/returndate/)){
+        if ($colfilter[1] and ($colfilter[0])){
+            $strsth2 .= " and $column between '$colfilter[0]' and '$colfilter[1]' " ;
+        } elsif ($colfilter[1]) {
+                $strsth2 .= " and $column < '$colfilter[1]' " ;
+        } elsif ($colfilter[0]) {
+            $strsth2 .= " and $column > '$colfilter[0]' " ;
+        }
+        if ($colfilter[2]){
+            $strsth2 .= " and dayname($column) = '$colfilter[2]' " ;
+        }
+        if ($colfilter[3]){
+            $strsth2 .= " and monthname($column) = '$colfilter[3]' " ;
+        }
+    } elsif ($colfilter[0]) {
+        $colfilter[0] =~ s/\*/%/g;
+        $strsth2 .= " and $column LIKE '$colfilter[0]' " ;
+    }
+    $strsth2 .=" group by $colfield";
+    $strsth2 .=" order by $colorder";
+    warn "". $strsth2;
+    
+    my $sth2 = $dbh->prepare( $strsth2 );
+    if (( @colfilter ) and ($colfilter[1])){
+        $sth2->execute("'".$colfilter[0]."'","'".$colfilter[1]."'");
+    } elsif ($colfilter[0]) {
+        $sth2->execute($colfilter[0]);
+    } else {
+        $sth2->execute;
+    }
+    
 
-       while (my ($celvalue) = $sth2->fetchrow) {
-               my %cell;
-               my %ft;
+    while (my ($celvalue) = $sth2->fetchrow) {
+        my %cell;
+        my %ft;
 #              warn "coltitle :".$celvalue;
-               $cell{coltitle} = $celvalue;
-               $ft{totalcol} = 0;
-               push @loopcol, \%cell;
-       }
+        $cell{coltitle} = $celvalue;
+        $ft{totalcol} = 0;
+        push @loopcol, \%cell;
+    }
 #      warn "fin des titres colonnes";
 
-       my $i=0;
-       my @totalcol;
-       my $hilighted=-1;
-       
-       #Initialization of cell values.....
-       my %table;
-       my %wgttable;
-       my %cnttable;
-       
+    my $i=0;
+    my @totalcol;
+    my $hilighted=-1;
+    
+    #Initialization of cell values.....
+    my %table;
+    my %wgttable;
+    my %cnttable;
+    
 #      warn "init table";
-       foreach my $row ( @loopline ) {
-               foreach my $col ( @loopcol ) {
+    foreach my $row ( @loopline ) {
+        foreach my $col ( @loopcol ) {
 #                      warn " init table : $row->{rowtitle} / $col->{coltitle} ";
-                       $table{$row->{rowtitle}}->{$col->{coltitle}}=0;
-               }
-               $table{$row->{rowtitle}}->{totalrow}=0;
-       }
+            $table{$row->{rowtitle}}->{$col->{coltitle}}=0;
+        }
+        $table{$row->{rowtitle}}->{totalrow}=0;
+    }
 
 # preparing calculation
-       my $strcalc ;
-       
+    my $strcalc ;
+    
 # Processing average loanperiods
-       $strcalc .= "SELECT $linefield, $colfield, ";
-       $strcalc .= " issuedate, returndate, COUNT(*), date_due, issues.renewals, issuelength FROM `issues`,borrowers,biblioitems LEFT JOIN items ON (biblioitems.biblioitemnumber=items.biblioitemnumber) LEFT JOIN issuingrules ON (issuingrules.branchcode=issues.branchcode AND  issuingrules.itemtype=biblioitems.itemtype AND  issuingrules.categorycode=borrowers.categorycode) WHERE issues.itemnumber=items.itemnumber AND issues.borrowernumber=borrowers.borrowernumber and returndate is not null";
+    $strcalc .= "SELECT $linefield, $colfield, ";
+    $strcalc .= " issuedate, returndate, timestamp, COUNT(*), date_due, issues.renewals, issuelength FROM `issues`,borrowers,biblioitems LEFT JOIN items ON (biblioitems.biblioitemnumber=items.biblioitemnumber) LEFT JOIN issuingrules ON (issuingrules.branchcode=issues.branchcode AND  issuingrules.itemtype=biblioitems.itemtype AND  issuingrules.categorycode=borrowers.categorycode) WHERE issues.itemnumber=items.itemnumber AND issues.borrowernumber=borrowers.borrowernumber AND returndate IS NOT NULL";
 
-       @$filters[0]=~ s/\*/%/g if (@$filters[0]);
-       $strcalc .= " AND issues.timestamp > '" . @$filters[0] ."'" if ( @$filters[0] );
-       @$filters[1]=~ s/\*/%/g if (@$filters[1]);
-       $strcalc .= " AND issues.timestamp < '" . @$filters[1] ."'" if ( @$filters[1] );
-       @$filters[4]=~ s/\*/%/g if (@$filters[4]);
-       $strcalc .= " AND issues.returndate > '" . @$filters[4] ."'" if ( @$filters[4] );
-       @$filters[5]=~ s/\*/%/g if (@$filters[5]);
-       $strcalc .= " AND issues.returndate < '" . @$filters[5] ."'" if ( @$filters[5] );
-       @$filters[8]=~ s/\*/%/g if (@$filters[8]);
-       $strcalc .= " AND borrowers.categorycode like '" . @$filters[8] ."'" if ( @$filters[8] );
-       @$filters[9]=~ s/\*/%/g if (@$filters[9]);
-       $strcalc .= " AND biblioitems.itemtype like '" . @$filters[9] ."'" if ( @$filters[9] );
-       @$filters[10]=~ s/\*/%/g if (@$filters[10]);
-       $strcalc .= " AND issues.branchcode like '" . @$filters[10] ."'" if ( @$filters[10] );
-       @$filters[11]=~ s/\*/%/g if (@$filters[11]);
-       $strcalc .= " AND borrowers.sort1 like '" . @$filters[11] ."'" if ( @$filters[11] );
-       @$filters[12]=~ s/\*/%/g if (@$filters[12]);
-       $strcalc .= " AND borrowers.sort2 like '" . @$filters[12] ."'" if ( @$filters[12] );
-       $strcalc .= " AND dayname(timestamp) like '" . @$filters[2]."'" if (@$filters[2]);
-       $strcalc .= " AND monthname(timestamp) like '" . @$filters[3] ."'" if ( @$filters[3] );
-       $strcalc .= " AND dayname(returndate) like '" . @$filters[5]."'" if (@$filters[5]);
-       $strcalc .= " AND monthname(returndate) like '" . @$filters[6] ."'" if ( @$filters[6] );
-       
-       $strcalc .= " group by  $linefield, $colfield, issuedate, returndate order by $linefield, $colfield";
-       warn "SQL :". $strcalc;
-       
-       my $dbcalc = $dbh->prepare($strcalc);
-       $dbcalc->execute;
+    @$filters[0]=~ s/\*/%/g if (@$filters[0]);
+    $strcalc .= " AND issues.timestamp > '" . @$filters[0] ."'" if ( @$filters[0] );
+    @$filters[1]=~ s/\*/%/g if (@$filters[1]);
+    $strcalc .= " AND issues.timestamp < '" . @$filters[1] ."'" if ( @$filters[1] );
+    @$filters[4]=~ s/\*/%/g if (@$filters[4]);
+    $strcalc .= " AND issues.returndate > '" . @$filters[4] ."'" if ( @$filters[4] );
+    @$filters[5]=~ s/\*/%/g if (@$filters[5]);
+    $strcalc .= " AND issues.returndate < '" . @$filters[5] ."'" if ( @$filters[5] );
+    @$filters[8]=~ s/\*/%/g if (@$filters[8]);
+    $strcalc .= " AND borrowers.categorycode like '" . @$filters[8] ."'" if ( @$filters[8] );
+    @$filters[9]=~ s/\*/%/g if (@$filters[9]);
+    $strcalc .= " AND biblioitems.itemtype like '" . @$filters[9] ."'" if ( @$filters[9] );
+    @$filters[10]=~ s/\*/%/g if (@$filters[10]);
+    $strcalc .= " AND issues.branchcode like '" . @$filters[10] ."'" if ( @$filters[10] );
+    @$filters[11]=~ s/\*/%/g if (@$filters[11]);
+    $strcalc .= " AND borrowers.sort1 like '" . @$filters[11] ."'" if ( @$filters[11] );
+    @$filters[12]=~ s/\*/%/g if (@$filters[12]);
+    $strcalc .= " AND borrowers.sort2 like '" . @$filters[12] ."'" if ( @$filters[12] );
+    $strcalc .= " AND dayname(timestamp) like '" . @$filters[2]."'" if (@$filters[2]);
+    $strcalc .= " AND monthname(timestamp) like '" . @$filters[3] ."'" if ( @$filters[3] );
+    $strcalc .= " AND dayname(returndate) like '" . @$filters[5]."'" if (@$filters[5]);
+    $strcalc .= " AND monthname(returndate) like '" . @$filters[6] ."'" if ( @$filters[6] );
+    
+    $strcalc .= " group by  $linefield, $colfield, issuedate, returndate order by $linefield, $colfield";
+    warn "SQL :". $strcalc;
+    
+    my $dbcalc = $dbh->prepare($strcalc);
+    $dbcalc->execute;
 #      warn "filling table";
-       my $issues_count=0;
-       my $previous_row; 
-       my $previous_col;
-       my $loanlength; 
-       my $err;
-       my $emptycol;
-       my $weightrow;
-       
-       while (my  @data = $dbcalc->fetchrow) {
-               my ($row, $col, $issuedate, $returndate, $weight)=@data;
+    my $issues_count=0;
+    my $previous_row; 
+    my $previous_col;
+    my $loanlength; 
+    my $err;
+    my $emptycol;
+    my $weightrow;
+    
+    while (my  @data = $dbcalc->fetchrow) {
+        my ($row, $col, $issuedate, $returndate, $weight)=@data;
 #              warn "filling table $row / $col / $issuedate / $returndate /$weight";
-               $emptycol=1 if ($col eq undef);
-               $col = "zzEMPTY" if ($col eq undef);
-               $row = "zzEMPTY" if ($row eq undef);
-#              warn "506 row :".$row." column :".$col;
-               my $result =Delta_Days(split(/-/,$issuedate),split (/-/,$returndate)) ;
-#  DateCalc returns => 0:0:WK:DD:HH:MM:SS   the weeks, days, hours, minutes,
-#  and seconds between the two
-               $loanlength = $result;
-#              warn "512 Same row and col DateCalc returns :$loanlength with return ". $returndate ."issue ". $issuedate ."weight : ". $weight;
-#              warn "513 row :".$row." column :".$col;
-               $table{$row}->{$col}+=$weight*$loanlength;
-#              $table{$row}->{totalrow}+=$weight*$loanlength;
-               $cnttable{$row}->{$col}= 1;
-               $wgttable{$row}->{$col}+=$weight;
-       }
-       
-       push @loopcol,{coltitle => "NULL"} if ($emptycol);
-       
-       foreach my $row ( sort keys %table ) {
-               my @loopcell;
-       #@loopcol ensures the order for columns is common with column titles
-       # and the number matches the number of columns
-               my $colcount=0;
-               foreach my $col ( @loopcol ) {
-                       my $value =$table{$row}->{(($col->{coltitle} eq "NULL")or ($col->{coltitle} eq ""))?"zzEMPTY":$col->{coltitle}} / $wgttable{$row}->{(($col->{coltitle} eq "NULL")or ($col->{coltitle} eq ""))?"zzEMPTY":$col->{coltitle}} if ($table{$row}->{(($col->{coltitle} eq "NULL")or ($col->{coltitle} eq ""))?"zzEMPTY":$col->{coltitle}});
+        $emptycol=1 if ($col eq undef);
+        $col = "zzEMPTY" if ($col eq undef);
+        $row = "zzEMPTY" if ($row eq undef);
+        # fill returndate to avoid an error with date calc (needed for all non returned issues)
+        $returndate= join '-',Date::Calc::Today if $returndate eq '0000-00-00';
+        my $result =Delta_Days(split(/-/,$issuedate),split (/-/,$returndate)) ;
+    #  DateCalc returns => 0:0:WK:DD:HH:MM:SS   the weeks, days, hours, minutes,
+    #  and seconds between the two
+        $loanlength = $result;
+    #          warn "512 Same row and col DateCalc returns :$loanlength with return ". $returndate ."issue ". $issuedate ."weight : ". $weight;
+    #          warn "513 row :".$row." column :".$col;
+        $table{$row}->{$col}+=$weight*$loanlength;
+    #          $table{$row}->{totalrow}+=$weight*$loanlength;
+        $cnttable{$row}->{$col}= 1;
+        $wgttable{$row}->{$col}+=$weight;
+    }
+    
+    push @loopcol,{coltitle => "NULL"} if ($emptycol);
+    
+    foreach my $row ( sort keys %table ) {
+        my @loopcell;
+    #@loopcol ensures the order for columns is common with column titles
+    # and the number matches the number of columns
+        my $colcount=0;
+        foreach my $col ( @loopcol ) {
+            my $value =$table{$row}->{(($col->{coltitle} eq "NULL")or ($col->{coltitle} eq ""))?"zzEMPTY":$col->{coltitle}} / $wgttable{$row}->{(($col->{coltitle} eq "NULL")or ($col->{coltitle} eq ""))?"zzEMPTY":$col->{coltitle}} if ($table{$row}->{(($col->{coltitle} eq "NULL")or ($col->{coltitle} eq ""))?"zzEMPTY":$col->{coltitle}});
 
-                       $table{$row}->{(($col->{coltitle} eq "NULL")or ($col->{coltitle} eq ""))?"zzEMPTY":$col->{coltitle}} = $value;
-                       $table{$row}->{totalrow}+=$value;
-                       #warn "row : $row col:$col  $cnttable{$row}->{(($col->{coltitle} eq \"NULL\")or ($col->{coltitle} eq \"\"))?\"zzEMPTY\":$col->{coltitle}}";
-                       $colcount+=$cnttable{$row}->{(($col->{coltitle} eq "NULL")or ($col->{coltitle} eq ""))?"zzEMPTY":$col->{coltitle}};
-                       push @loopcell, {value => ($value)?sprintf("%.2f",$value):0  } ;
-               }
-               #warn "row : $row colcount:$colcount";
-               my $total = $table{$row}->{totalrow}/$colcount if ($colcount>0);
-               push @looprow,{ 'rowtitle' => ($row eq "zzEMPTY")?"NULL":$row,
-                                               'loopcell' => \@loopcell,
-                                               'hilighted' => ($hilighted >0),
-                                               'totalrow' => ($total)?sprintf("%.2f",$total):0
-                                       };
-               $hilighted = -$hilighted;
-       }
+            $table{$row}->{(($col->{coltitle} eq "NULL")or ($col->{coltitle} eq ""))?"zzEMPTY":$col->{coltitle}} = $value;
+            $table{$row}->{totalrow}+=$value;
+            #warn "row : $row col:$col  $cnttable{$row}->{(($col->{coltitle} eq \"NULL\")or ($col->{coltitle} eq \"\"))?\"zzEMPTY\":$col->{coltitle}}";
+            $colcount+=$cnttable{$row}->{(($col->{coltitle} eq "NULL")or ($col->{coltitle} eq ""))?"zzEMPTY":$col->{coltitle}};
+            push @loopcell, {value => ($value)?sprintf("%.2f",$value):0  } ;
+        }
+        #warn "row : $row colcount:$colcount";
+        my $total = $table{$row}->{totalrow}/$colcount if ($colcount>0);
+        push @looprow,{ 'rowtitle' => ($row eq "zzEMPTY")?"NULL":$row,
+                        'loopcell' => \@loopcell,
+                        'hilighted' => ($hilighted >0),
+                        'totalrow' => ($total)?sprintf("%.2f",$total):0
+                    };
+        $hilighted = -$hilighted;
+    }
 #      
 # #    warn "footer processing";
-       foreach my $col ( @loopcol ) {
-               my $total=0;
-               my $nbrow=0;
-               foreach my $row ( @looprow ) {
-                       $total += $cnttable{($row->{rowtitle} eq "NULL")?"zzEMPTY":$row->{rowtitle}}->{($col->{coltitle} eq "NULL")?"zzEMPTY":$col->{coltitle}}*$table{($row->{rowtitle} eq "NULL")?"zzEMPTY":$row->{rowtitle}}->{($col->{coltitle} eq "NULL")?"zzEMPTY":$col->{coltitle}};
-                       $nbrow +=$cnttable{($row->{rowtitle} eq "NULL")?"zzEMPTY":$row->{rowtitle}}->{($col->{coltitle} eq "NULL")?"zzEMPTY":$col->{coltitle}};;
+    foreach my $col ( @loopcol ) {
+        my $total=0;
+        my $nbrow=0;
+        foreach my $row ( @looprow ) {
+            $total += $cnttable{($row->{rowtitle} eq "NULL")?"zzEMPTY":$row->{rowtitle}}->{($col->{coltitle} eq "NULL")?"zzEMPTY":$col->{coltitle}}*$table{($row->{rowtitle} eq "NULL")?"zzEMPTY":$row->{rowtitle}}->{($col->{coltitle} eq "NULL")?"zzEMPTY":$col->{coltitle}};
+            $nbrow +=$cnttable{($row->{rowtitle} eq "NULL")?"zzEMPTY":$row->{rowtitle}}->{($col->{coltitle} eq "NULL")?"zzEMPTY":$col->{coltitle}};;
 #                      warn "value added ".$table{$row->{rowtitle}}->{$col->{coltitle}}. "for line ".$row->{rowtitle};
-               }
+        }
 #              warn "summ for column ".$col->{coltitle}."  = ".$total;
-               $total = $total/$nbrow if ($nbrow);
-               push @loopfooter, {'totalcol' => ($total)?sprintf("%.2f",$total):0};
-       
-       }
-                       
+        $total = $total/$nbrow if ($nbrow);
+        push @loopfooter, {'totalcol' => ($total)?sprintf("%.2f",$total):0};
+    
+    }
+            
 
-       # the header of the table
-       $globalline{loopfilter}=\@loopfilter;
-       # the core of the table
-       $globalline{looprow} = \@looprow;
-       $globalline{loopcol} = \@loopcol;
+    # the header of the table
+    $globalline{loopfilter}=\@loopfilter;
+    # the core of the table
+    $globalline{looprow} = \@looprow;
+    $globalline{loopcol} = \@loopcol;
 #      # the foot (totals by borrower type)
-       $globalline{loopfooter} = \@loopfooter;
-       $globalline{total}= $grantotal;
-       $globalline{line} = $line;
-       $globalline{column} = $column;
-       push @mainloop,\%globalline;
-       return \@mainloop;
+    $globalline{loopfooter} = \@loopfooter;
+    $globalline{total}= $grantotal;
+    $globalline{line} = $line;
+    $globalline{column} = $column;
+    push @mainloop,\%globalline;
+    return \@mainloop;
 }
 
 1;
index 68a3442..5ed632e 100755 (executable)
@@ -27,6 +27,7 @@ use C4::Branch; # GetBranches
 use C4::Koha;
 use C4::Output;
 use C4::Circulation;
+use C4::Date;
 use Date::Manip;
 
 =head1 NAME
@@ -45,6 +46,8 @@ my $fullreportname = "reports/issues_stats.tmpl";
 my $line = $input->param("Line");
 my $column = $input->param("Column");
 my @filters = $input->param("Filter");
+$filters[0]=format_date_in_iso($filters[0]);
+$filters[1]=format_date_in_iso($filters[1]);
 my $podsp = $input->param("DisplayBy");
 my $type = $input->param("PeriodTypeSel");
 my $daysel = $input->param("PeriodDaySel");
@@ -64,9 +67,7 @@ my ($template, $borrowernumber, $cookie)
                             debug => 1,
                             });
 $template->param(do_it => $do_it,
-                intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
-                intranetstylesheet => C4::Context->preference("intranetstylesheet"),
-                IntranetNav => C4::Context->preference("IntranetNav"),
+        DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(),
                 );
 if ($do_it) {
 # Displaying results
@@ -80,8 +81,8 @@ if ($do_it) {
 # Printing to a csv file
         print $input->header(-type => 'application/vnd.sun.xml.calc',
                             -encoding    => 'utf-8',
-                -attachment=>"$basename.csv",
-                -filename=>"$basename.csv" );
+                            -attachment=>"$basename.csv",
+                            -filename=>"$basename.csv" );
         my $cols = @$results[0]->{loopcol};
         my $lines = @$results[0]->{looprow};
         my $sep;
@@ -270,8 +271,13 @@ sub calculate {
                 if ( @$filters[$i] ) {
                         if (($i==1) and (@$filters[$i-1])) {
                                 $cell{err} = 1 if (@$filters[$i]<@$filters[$i-1]) ;
+                            }
+                        # format the dates filters, otherwise just fill as is
+                        if ($i>=2) {
+                            $cell{filter} .= @$filters[$i];
+                        } else {
+                            $cell{filter} .= format_date(@$filters[$i]);
                         }
-                        $cell{filter} .= @$filters[$i];
                         $cell{crit} .="Period From" if ($i==0);
                         $cell{crit} .="Period To" if ($i==1);
                         $cell{crit} .="Borrower Cat=" if ($i==2);
@@ -357,7 +363,7 @@ sub calculate {
         }
         $strsth .=" group by $linefield";
         $strsth .=" order by $lineorder";
-        warn "". $strsth;
+        warn "". $strsth;
         
         my $sth = $dbh->prepare( $strsth );
         if (( @linefilter ) and ($linefilter[1])){
@@ -510,7 +516,7 @@ sub calculate {
 #      warn "filling table";
         my $emptycol; 
         while (my ($row, $col, $value) = $dbcalc->fetchrow) {
-                warn "filling table $row / $col / $value ";
+                warn "filling table $row / $col / $value ";
                 $emptycol = 1 if ($col eq undef);
                 $col = "zzEMPTY" if ($col eq undef);
                 $row = "zzEMPTY" if ($row eq undef);
@@ -530,9 +536,9 @@ sub calculate {
                         push @loopcell, {value => $value  } ;
                 }
                 push @looprow,{ 'rowtitle' => ($row->{rowtitle} eq "NULL")?"zzEMPTY":$row->{rowtitle},
-                                                        'loopcell' => \@loopcell,
-                                                        'hilighted' => ($hilighted >0),
-                                                        'totalrow' => $table{($row->{rowtitle} eq "NULL")?"zzEMPTY":$row->{rowtitle}}->{totalrow}
+                                'loopcell' => \@loopcell,
+                                'hilighted' => ($hilighted >0),
+                                'totalrow' => $table{($row->{rowtitle} eq "NULL")?"zzEMPTY":$row->{rowtitle}}->{totalrow}
                                                 };
                 $hilighted = -$hilighted;
         }
index de711b4..7ff00c1 100755 (executable)
@@ -49,6 +49,7 @@ use C4::Auth;
 use C4::Serials; # GetExpirationDate
 use C4::Output;
 use C4::Context;
+use C4::Date;
 use Date::Calc qw/Today Date_to_Days/;
 
 my $query = new CGI;
@@ -66,7 +67,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user (
 
 my $title = $query->param('title');
 my $issn  = $query->param('issn');
-my $date  = $query->param('date');
+my $date  = format_date_in_iso($query->param('date'));
 my $today = join "-",&Today;
 
 if ($date) {
@@ -81,8 +82,9 @@ if ($date) {
         $subscription->{expirationdate} = $expirationdate;
         next if $expirationdate !~ /\d{4}-\d{2}-\d{2}/; # next if not in good format.
         if ( Date_to_Days(split "-",$expirationdate) < Date_to_Days(split "-",$date) &&
-             Date_to_Days(split "-",$expirationdate) > Date_to_Days(split "-",$today) ) {
-            push @subscriptions_loop,$subscription;             
+        Date_to_Days(split "-",$expirationdate) > Date_to_Days(split "-",$today) ) {
+            $subscription->{expirationdate}=format_date($subscription->{expirationdate});
+            push @subscriptions_loop,$subscription;
         }
     }
     
@@ -90,10 +92,12 @@ if ($date) {
         title           => $title,
         issn            => $issn,
         numsubscription => scalar @subscriptions_loop,
-        date => $date,
+        date => format_date($date),
         subscriptions_loop => \@subscriptions_loop,
         "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
     );
 }
-
+$template->param (
+    DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(),
+);
 output_html_with_http_headers $query, $cookie, $template->output;
index c67f756..1385aa8 100755 (executable)
@@ -37,6 +37,7 @@ use strict;
 use CGI;
 use C4::Auth;
 use C4::Output;
+use C4::Date;
 
 
 use C4::Members;               # GetBorrowersWhoHavexxxBorrowed.
@@ -66,20 +67,18 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
 );
 
 if ( $params->{'step2'} ) {
-    $filterdate1 = $params->{'filterdate1'};
-    $filterdate2 = $params->{'filterdate2'};
+    $filterdate1 = format_date_in_iso($params->{'filterdate1'});
+    $filterdate2 = format_date_in_iso($params->{'filterdate2'});
     my $checkbox = $params->{'checkbox'};
 
     my $totalDel;
     if ($checkbox eq "borrower") {
-        $filterdate1 = $params->{'filterdate1'};
         my $membersToDelete = GetBorrowersWhoHaveNotBorrowedSince($filterdate1);
         $totalDel = scalar @$membersToDelete;
     }
 
     my $totalAno;
     if ($checkbox eq "issue") {
-        $filterdate2 = $params->{'filterdate2'};
         my $membersToAnonymize =
           GetBorrowersWithIssuesHistoryOlderThan($filterdate2);
         $totalAno = scalar @$membersToAnonymize;
@@ -89,8 +88,8 @@ if ( $params->{'step2'} ) {
         step2            => 1,
         totalToDelete    => $totalDel,
         totalToAnonymize => $totalAno,
-        filterdate1      => $filterdate1,
-        filterdate2      => $filterdate2
+        filterdate1      => format_date($filterdate1),
+        filterdate2      => format_date($filterdate2),
     );
 
     #writing the template
@@ -99,8 +98,8 @@ if ( $params->{'step2'} ) {
 }
 
 if ( $params->{'step3'} ) {
-    $filterdate1 = $params->{'filterdate1'};
-    $filterdate2 = $params->{'filterdate2'};
+    $filterdate1 = format_date_in_iso($params->{'filterdate1'});
+    $filterdate2 = format_date_in_iso($params->{'filterdate2'});
     my $do_delete = $params->{'do_delete'};
     my $do_anonym = $params->{'do_anonym'};
 
@@ -153,13 +152,14 @@ if ( $params->{'step3'} ) {
 my ( $year, $month, $day ) = &Today();
 my $tmpyear  = $year - 1;
 my $tmpmonth = $month - 3;
-$filterdate1 = $tmpyear . "-" . $month . "-" . $day;
-$filterdate2 = $year . "-" . $tmpmonth . "-" . $day;
+$filterdate1 = format_date($tmpyear . "-" . $month . "-" . $day);
+$filterdate2 = format_date($year . "-" . $tmpmonth . "-" . $day);
 
 $template->param(
     step1       => '1',
     filterdate1 => $filterdate1,
-    filterdate2 => $filterdate2
+    filterdate2 => $filterdate2,
+    DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(),
 );
 
 #writing the template
index 68ea675..c19dae7 100755 (executable)
@@ -29,6 +29,7 @@ use C4::Context;
 use C4::Output;
 use C4::NewsChannels;
 use C4::Languages;
+use C4::Date;
 use Date::Calc qw/Date_to_Days Today/;
 
 my $cgi = new CGI;
@@ -36,7 +37,7 @@ my $cgi = new CGI;
 my $id             = $cgi->param('id');
 my $title          = $cgi->param('title');
 my $new            = $cgi->param('new');
-my $expirationdate = $cgi->param('expirationdate');
+my $expirationdate = format_date_in_iso($cgi->param('expirationdate'));
 my $number         = $cgi->param('number');
 my $lang           = $cgi->param('lang');
 
@@ -69,16 +70,19 @@ $template->param( lang_list => \@lang_list );
 my $op = $cgi->param('op');
 
 if ( $op eq 'add_form' ) {
-    $template->param( add_form => 1 );
+    $template->param( add_form => 1,
+        DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(),
+    );
     if ($id) {
         $template->param( 
             op => 'edit',
-            id => $new_detail->{'idnew'}
+            id => $new_detail->{'idnew'},
         );
-        $template->param($new_detail);
+        $template->param($new_detail,);
     }
     else {
-        $template->param( op => 'add' );
+        $template->param( op => 'add',
+        );
     }
 }
 elsif ( $op eq 'add' ) {
@@ -102,7 +106,7 @@ else {
     foreach my $new ( @$opac_news ) {
         next unless $new->{'expirationdate'};
         next if $new->{'expirationdate'} eq '0000-00-00';
-        if (Date_to_Days( split "-" ,$new->{'expirationdate'} ) < Date_to_Days(&Today) ){
+        if (Date_to_Days( split "-" ,format_date_in_iso($new->{'expirationdate'}) ) < Date_to_Days(&Today) ){
             $new->{'hasexpirated'} = 1;
         }
     }
index 080b1cc..f26757c 100755 (executable)
@@ -139,6 +139,7 @@ else {
         total        => 0,
         CGIextChoice => $CGIextChoice,
         CGIsepChoice => $CGIsepChoice
+        DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(),
     );
     output_html_with_http_headers $input, $cookie, $template->output;
 }