From a5bd2403218b5add150088ab525b1f00e50a0c12 Mon Sep 17 00:00:00 2001 From: paul Date: Thu, 4 Oct 2007 07:16:39 +0200 Subject: [PATCH] FIX for Date calculation 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 --- C4/NewsChannels.pm | 84 +- C4/Serials.pm | 17 - acqui/histsearch.pl | 4 +- circ/pendingreserves.pl | 15 +- .../prog/en/modules/acqui/histsearch.tmpl | 4 +- .../prog/en/modules/circ/pendingreserves.tmpl | 4 +- .../prog/en/modules/labels/search.tmpl | 4 +- .../modules/reports/acquisitions_stats.tmpl | 8 +- .../en/modules/reports/bor_issues_top.tmpl | 8 +- .../en/modules/reports/borrowers_out.tmpl | 2 +- .../en/modules/reports/borrowers_stats.tmpl | 4 +- .../en/modules/reports/cat_issues_top.tmpl | 8 +- .../en/modules/reports/issues_avg_stats.tmpl | 8 +- .../prog/en/modules/reports/issues_stats.tmpl | 4 +- .../en/modules/serials/checkexpiration.tmpl | 2 +- .../prog/en/modules/tools/cleanborrowers.tmpl | 4 +- .../prog/en/modules/tools/koha-news.tmpl | 2 +- .../prog/en/modules/tools/viewlog.tmpl | 4 +- .../prog/fr/modules/labels/search.tmpl | 2 +- labels/label-item-search.pl | 11 +- reports/acquisitions_stats.pl | 16 +- reports/bor_issues_top.pl | 623 ++++++------ reports/borrowers_out.pl | 470 +++++---- reports/borrowers_stats.pl | 3 +- reports/cat_issues_top.pl | 642 ++++++------ reports/issues_avg_stats.pl | 960 +++++++++--------- reports/issues_stats.pl | 28 +- serials/checkexpiration.pl | 14 +- tools/cleanborrowers.pl | 22 +- tools/koha-news.pl | 16 +- tools/viewlog.pl | 1 + 31 files changed, 1507 insertions(+), 1487 deletions(-) diff --git a/C4/NewsChannels.pm b/C4/NewsChannels.pm index 0d8f458354..ea361fdf88 100644 --- a/C4/NewsChannels.pm +++ b/C4/NewsChannels.pm @@ -45,7 +45,7 @@ This module provides the functions needed to admin the news channels and its cat @ISA = qw(Exporter); -@EXPORT = qw( +@EXPORT = qw( &GetNewsToDisplay &news_channels &get_new_channel &del_channels &add_channel &update_channel &news_channels_categories &get_new_channel_category &del_channels_categories @@ -240,7 +240,7 @@ sub update_channel_category { } sub add_opac_new { - my ($title, $new, $lang, $expirationdate, $number) = @_; + my ($title, $new, $lang, $expirationdate, $number) = @_; my $dbh = C4::Context->dbh; my $sth = $dbh->prepare("INSERT INTO opac_news (title, new, lang, expirationdate, number) VALUES (?,?,?,?,?)"); $sth->execute($title, $new, $lang, $expirationdate, $number); @@ -251,14 +251,14 @@ sub add_opac_new { sub upd_opac_new { my ($idnew, $title, $new, $lang, $expirationdate, $number) = @_; my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare(" - UPDATE opac_news SET - title = ?, - new = ?, - lang = ?, - expirationdate = ?, - number = ? - WHERE idnew = ? + my $sth = $dbh->prepare(" + UPDATE opac_news SET + title = ?, + new = ?, + lang = ?, + expirationdate = ?, + number = ? + WHERE idnew = ? "); $sth->execute($title, $new, $lang, $expirationdate,$number,$idnew); $sth->finish; @@ -285,6 +285,7 @@ sub get_opac_new { $sth->execute($idnew); my $data = $sth->fetchrow_hashref; $data->{$data->{'lang'}} = 1; + $data->{expirationdate} = format_date($data->{expirationdate}); $sth->finish; return $data; } @@ -292,7 +293,7 @@ sub get_opac_new { sub get_opac_news { my ($limit, $lang) = @_; my $dbh = C4::Context->dbh; - my $query = "SELECT *, DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate FROM opac_news"; + my $query = "SELECT *, timestamp AS newdate FROM opac_news"; if ($lang) { $query.= " WHERE lang = '" .$lang ."' "; } @@ -307,43 +308,44 @@ sub get_opac_news { while (my $row = $sth->fetchrow_hashref) { if ((($limit) && ($count < $limit)) || (!$limit)) { $row->{'newdate'} = format_date($row->{'newdate'}); + $row->{'expirationdate'} = format_date($row->{'expirationdate'}); push @opac_news, $row; } $count++; } return ($count, \@opac_news); } - -=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; + +=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; my $dbh = C4::Context->dbh; - 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 = " + 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; +} ### get electronic databases diff --git a/C4/Serials.pm b/C4/Serials.pm index 30b5deb4e0..6c93e8223f 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -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; diff --git a/acqui/histsearch.pl b/acqui/histsearch.pl index 6613415481..1da1fc3b24 100755 --- a/acqui/histsearch.pl +++ b/acqui/histsearch.pl @@ -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; diff --git a/circ/pendingreserves.pl b/circ/pendingreserves.pl index ac223905e5..3a7b720a60 100755 --- a/circ/pendingreserves.pl +++ b/circ/pendingreserves.pl @@ -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; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tmpl index b801f55485..b1970bf4df 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tmpl @@ -59,7 +59,7 @@ Calendar.setup( { inputField : "from", - ifFormat : "%Y-%m-%d", + ifFormat : "", button : "openCalendarFrom", disableFunc : validate1, dateStatusFunc : validate1 @@ -88,7 +88,7 @@ Calendar.setup( { inputField : "to", - ifFormat : "%Y-%m-%d", + ifFormat : "", button : "openCalendarTo", disableFunc : validate2, dateStatusFunc : validate2 diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tmpl index 18fd11e278..d60bdc4341 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tmpl @@ -52,7 +52,7 @@ function validate1(date) { Calendar.setup( { inputField : "from", - ifFormat : "%Y-%m-%d", + ifFormat : "", button : "openCalendarFrom", disableFunc : validate1, dateStatusFunc : validate1 @@ -84,7 +84,7 @@ Calendar.setup( Calendar.setup( { inputField : "to", - ifFormat : "%Y-%m-%d", + ifFormat : "", button : "openCalendarTo", disableFunc : validate2, dateStatusFunc : validate2 diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/search.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/search.tmpl index ec67198373..382c26d287 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/search.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/search.tmpl @@ -80,7 +80,7 @@

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/cleanborrowers.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/cleanborrowers.tmpl index b76b0b0282..c146e8a70c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/cleanborrowers.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/cleanborrowers.tmpl @@ -64,7 +64,7 @@ Calendar.setup( { inputField : "date1", - ifFormat : "%Y-%m-%d", + ifFormat : "", } ); @@ -77,7 +77,7 @@ Calendar.setup( { inputField : "date2", - ifFormat : "%Y-%m-%d", + ifFormat : "", } ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tmpl index 5f6154a021..5f40e7e850 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tmpl @@ -42,7 +42,7 @@ Calendar.setup( { inputField : "expirationdate", - ifFormat : "%Y-%m-%d", + ifFormat : "", } ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tmpl index 57bff5bbcc..b5cdffe2fe 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tmpl @@ -44,7 +44,7 @@ Calendar.setup( { inputField : "from", - ifFormat : "%Y-%m-%d", + ifFormat : "", button : "openCalendarFrom", disableFunc : validate1, dateStatusFunc : validate1 @@ -72,7 +72,7 @@ Calendar.setup( { inputField : "to", - ifFormat : "%Y-%m-%d", + ifFormat : "", button : "openCalendarTo", disableFunc : validate2, dateStatusFunc : validate2 diff --git a/koha-tmpl/intranet-tmpl/prog/fr/modules/labels/search.tmpl b/koha-tmpl/intranet-tmpl/prog/fr/modules/labels/search.tmpl index 0684a320ac..e442f3437b 100644 --- a/koha-tmpl/intranet-tmpl/prog/fr/modules/labels/search.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/fr/modules/labels/search.tmpl @@ -80,7 +80,7 @@