Skip to content

Commit 0031977

Browse files
authored
Merge pull request #1782 from ikedas/issue-1751 by ikedas
Use browser's built-in "date" widget instead of jQuery UI Datepicker that is inaccessible using keyboard (#1751)
2 parents 2deda25 + 1b044b0 commit 0031977

File tree

8 files changed

+71
-132
lines changed

8 files changed

+71
-132
lines changed

default/web_tt2/head_javascript.tt2

-5
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,13 @@
1111
[%# A few configuration settings and miscellaneous vars. ~%]
1212
var sympa = {
1313
backText: '[%"Back"|loc|escape_cstr%]',
14-
calendarButtonText: '[%"Calendar"|loc|escape_cstr%]',
15-
calendarFirstDay: 0,
1614
closeText: '[%"Close"|loc|escape_cstr%]',
1715
copiedText: '[%"Copied!"|loc|escape_cstr%]',
1816
copyPermalinkText: '[%"Copy permalink"|loc|escape_cstr%]',
19-
dayNames: '[%"Sunday:Monday:Tuesday:Wednesday:Thursday:Friday:Saturday"|loc|escape_cstr%]'.split(":"),
20-
dayNamesMin: '[%"Su:Mo:Tu:We:Th:Fr:Sa"|loc|escape_cstr%]'.split(":"),
2117
home_url: '[% path_cgi | escape_cstr %]/',
2218
icons_url: '[% icons_url | escape_cstr %]',
2319
lang: '[% lang | escape_cstr %]',
2420
loadingText: '[%"Please Wait..."|loc|escape_cstr%]',
25-
monthNamesShort: '[%"Jan:Feb:Mar:Apr:May:Jun:Jul:Aug:Sep:Oct:Nov:Dec"|loc|escape_cstr%]'.split(":"),
2621
openInNewWinText: '[%"Open in a new window"|loc|escape_cstr%]',
2722
resetText: '[%"Reset"|loc|escape_cstr%]'
2823
};

default/web_tt2/suboptions.tt2

+7-7
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@
118118

119119
<div>
120120
<label for="date_deb">[%|loc%]From:[%END%] </label>
121-
<input type="text" id="date_deb" name="date_deb" maxlength="10" size="10" style="display: inline-block; max-width: 40%"
122-
value="[% d_day %]" placeholder="[%|loc%]dd-mm-yyyy[%END%]" />
121+
<input type="date" id="date_deb" name="date_deb"
122+
style="display: inline-block; max-width: 40%"
123+
value="[% d_day %]"
124+
placeholder="[%|loc%]yyyy-mm-dd[%END%]" />
123125
<label for="date_fin">[%|loc%]To:[%END%] </label>
124-
<input type="text" id="date_fin" name="date_fin" maxlength="10" size="10" style="display: inline-block; max-width: 40%"
125-
placeholder="[%|loc%]dd-mm-yyyy[%END%]" />
126-
<noscript>
127-
([%|loc%]dd-mm-yyyy[%END%])
128-
</noscript>
126+
<input type="date" id="date_fin" name="date_fin"
127+
style="display: inline-block; max-width: 40%"
128+
placeholder="[%|loc%]yyyy-mm-dd[%END%]" />
129129
<input type="checkbox" name="indefinite" />
130130
[%|loc%]Suspend my membership indefinitely[%END%]
131131
</div>

default/web_tt2/suspend_request.tt2

+5-5
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@
8888
<input class="MainMenuLinks" type="submit" name="sub_action_suspendsave" value="[%|loc%]Suspend my subscriptions[%END%]"/>
8989
<div>
9090
<label for="date_deb">[%|loc%]From:[%END%]</label>
91-
<input type="text" id="date_deb" name="date_deb" maxlength="10" size="10"
91+
<input type="date" id="date_deb" name="date_deb"
9292
style="display: inline-block; max-width: 40%"
93-
value="[% d_day %]" placeholder="[%|loc%]dd-mm-yyyy[%END%]" />
93+
value="[% d_day %]"
94+
placeholder="[%|loc%]yyyy-mm-dd[%END%]" />
9495
<label for="date_fin">[%|loc%]To:[%END%]</label>
95-
<input type="text" id="date_fin" name="date_fin" maxlength="10" size="10"
96+
<input type="date" id="date_fin" name="date_fin"
9697
style="display: inline-block; max-width: 40%"
97-
placeholder="[%|loc%]dd-mm-yyyy[%END%]" />
98-
<noscript>([%|loc%]dd-mm-yyyy[%END%])</noscript>
98+
placeholder="[%|loc%]yyyy-mm-dd[%END%]" />
9999
<input type="checkbox" name="indefinite" /> [%|loc%]Suspend my membership indefinitely[%END%]
100100
</div>
101101
[% IF suspended %]

default/web_tt2/viewlogs.tt2

+6-4
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@
2525
</div>
2626
<div>
2727
<label for="date_from">[%|loc%]Search by date from:[%END%]</label>
28-
<input type="text" id="date_from" name="date_from" maxlength="10" size="10"
28+
<input type="date" id="date_from" name="date_from"
2929
style="display: inline-block; max-width: 40%"
30-
value="[% date_from %]" placeholder="[%|loc%]dd-mm-yyyy[%END%]" />
30+
value="[% date_from %]"
31+
placeholder="[%|loc%]yyyy-mm-dd[%END%]" />
3132
<label for="date_to">[%|loc%]to:[%END%]</label>
32-
<input type="text" id="date_to" name="date_to" maxlength="10" size="10"
33+
<input type="date" id="date_to" name="date_to"
3334
style="display: inline-block; max-width: 40%"
34-
value="[% date_to %]" placeholder="[%|loc%]dd-mm-yyyy[%END%]" />
35+
value="[% date_to %]"
36+
placeholder="[%|loc%]yyyy-mm-dd[%END%]" />
3537
<noscript>([%|loc%]ex: 24-05-2006[%END%])</noscript>
3638
</div>
3739
<div>

src/cgi/wwsympa.fcgi.in

+42-80
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
1010
# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
1111
# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER
12-
# Copyright 2017, 2018, 2019, 2020, 2021, 2022 The Sympa Community. See the
13-
# AUTHORS.md file at the top-level directory of this distribution and at
14-
# <https://github.com/sympa-community/sympa.git>.
12+
# Copyright 2017, 2018, 2019, 2020, 2021, 2022, 2023 The Sympa Community.
13+
# See the AUTHORS.md file at the top-level directory of this distribution
14+
# and at <https://github.com/sympa-community/sympa.git>.
1515
#
1616
# This program is free software; you can redistribute it and/or modify
1717
# it under the terms of the GNU General Public License as published by
@@ -39,7 +39,6 @@ use IO::File qw();
3939
use MIME::EncWords;
4040
use MIME::Lite::HTML;
4141
use POSIX qw();
42-
use Time::Local qw();
4342
use URI;
4443
use Data::Dumper; # tentative
4544

@@ -4108,7 +4107,7 @@ sub do_my {
41084107
wwslog('info', '');
41094108

41104109
# Sets the date of the field "start date" to "today"
4111-
$param->{'d_day'} = POSIX::strftime('%d-%m-%Y', localtime time);
4110+
$param->{'d_day'} = POSIX::strftime('%Y-%m-%d', localtime time);
41124111
_set_my_lists_info();
41134112
return 1;
41144113
}
@@ -8681,21 +8680,8 @@ sub do_latest_arc {
86818680
return 1;
86828681
}
86838682

8684-
sub get_timelocal_from_date {
8685-
my ($mday, $mon, $yr, $hr, $min, $sec, $zone) = @_;
8686-
my ($time) = 0;
8687-
8688-
$yr -= 1900 if $yr >= 1900; # if given full 4 digit year
8689-
$yr += 100 if $yr <= 37; # in case of 2 digit years
8690-
if (($yr < 70) || ($yr > 137)) {
8691-
warn "Warning: Bad year (", $yr + 1900, ") using current\n";
8692-
$yr = (localtime(time))[5];
8693-
}
8694-
8695-
$time = Time::Local::timelocal($sec, $min, $hr, $mday, $mon, $yr);
8696-
return $time;
8697-
8698-
}
8683+
# No longer used.
8684+
#sub get_timelocal_from_date;
86998685

87008686
####################################################
87018687
# do_remove_arc
@@ -13755,7 +13741,7 @@ sub do_suspend_request {
1375513741
wwslog('info', '');
1375613742

1375713743
## Sets the date of the field "start date" to "today"
13758-
$param->{'d_day'} = POSIX::strftime('%d-%m-%Y', localtime time);
13744+
$param->{'d_day'} = POSIX::strftime('%Y-%m-%d', localtime time);
1375913745
_set_my_lists_info();
1376013746

1376113747
# Compatibility with Sympa <= 6.1b.1.
@@ -13937,6 +13923,12 @@ sub do_suspend_request_action {
1393713923

1393813924
my $previous_action = $in{'previous_action'} || 'suspend_request';
1393913925

13926+
# Compat. <= 6.2.72
13927+
$in{'date_deb'} =~ s/(\d\d)-(\d\d)-(\d\d\d\d)/$3-$2-$1/
13928+
if $in{'date_deb'};
13929+
$in{'date_fin'} =~ s/(\d\d)-(\d\d)-(\d\d\d\d)/$3-$2-$1/
13930+
if $in{'date_fin'};
13931+
1394013932
if ($in{'sub_action'} eq 'suspendsave') {
1394113933

1394213934
# to retrieve the selected list
@@ -13961,59 +13953,23 @@ sub do_suspend_request_action {
1396113953
return $previous_action;
1396213954
}
1396313955

13964-
if ($in{'date_deb'}) {
13965-
($day1, $month1, $year1) = split(/\-/, $in{'date_deb'});
13966-
$month1 = $month1 - 1;
13967-
13968-
if ( ($day1 =~ /([0-9]*)/)
13969-
&& ($month1 =~ /([0-9]*)/)
13970-
&& ($year1 =~ /([0-9]*)/)) {
13971-
if ( ((1 <= $day1) && ($day1 <= 31))
13972-
&& ((0 <= $month1) && ($month1 <= 11))
13973-
&& (1900 <= $year1)) {
13974-
## Return an epoch date
13975-
$data->{'startdate'} =
13976-
Time::Local::timelocal(0, 0, 0, $day1, $month1,
13977-
$year1);
13978-
} else {
13979-
add_stash('user', 'missing_arg',
13980-
{argument => 'Start Date doesn\'t exist.'});
13981-
wwslog('info', 'Date doesn\'t exist');
13982-
return $previous_action;
13983-
}
13984-
} else {
13985-
add_stash('user', 'missing_arg',
13986-
{argument => 'Start Date doesn\'t exist.'});
13987-
wwslog('info', 'Date doesn\'t exist');
13988-
return $previous_action;
13989-
}
13990-
## Case 1 : Start date & End date (without indefinite)
13991-
if (($in{'date_fin'}) && (!$in{'indefinite'})) {
13992-
($day2, $month2, $year2) = split(/\-/, $in{'date_fin'});
13993-
$month2 = $month2 - 1;
13994-
13995-
if ( ($day2 =~ /([0-9]*)/)
13996-
&& ($month2 =~ /([0-9]*)/)
13997-
&& ($year2 =~ /([0-9]*)/)) {
13998-
if ( ((1 <= $day2) && ($day2 <= 31))
13999-
&& ((0 <= $month2) && ($month2 <= 11))
14000-
&& (1900 <= $year2)) {
14001-
## Return an epoch date
14002-
$data->{'enddate'} =
14003-
Time::Local::timelocal(0, 0, 0, $day2, $month2,
14004-
$year2);
14005-
} else {
14006-
add_stash('user', 'missing_arg',
14007-
{argument => 'End Date doesn\'t exist.'});
14008-
wwslog('info', 'Date doesn\'t exist');
14009-
return $previous_action;
14010-
}
14011-
} else {
14012-
add_stash('user', 'missing_arg',
14013-
{argument => 'End Date doesn\'t exist.'});
14014-
wwslog('info', 'Date doesn\'t exist');
14015-
return $previous_action;
14016-
}
13956+
my $html_date_re = Sympa::Regexps::html_date();
13957+
if (($in{'date_deb'} // '') =~ /\A$html_date_re\z/) {
13958+
($year1, $month1, $day1) = split /-/, $in{'date_deb'};
13959+
# Return an epoch date
13960+
$data->{'startdate'} =
13961+
POSIX::mktime(0, 0, 0, $day1 + 0, $month1 - 1, $year1 - 1900);
13962+
13963+
if (($in{'date_fin'} // '') =~ /\A$html_date_re\z/
13964+
and not $in{'indefinite'}) {
13965+
# Case 1 : Start date & End date (without indefinite)
13966+
($year2, $month2, $day2) = split /-/, $in{'date_fin'};
13967+
# Return an epoch date
13968+
$data->{'enddate'} = POSIX::mktime(
13969+
0, 0, 0, $day2 + 0,
13970+
$month2 - 1,
13971+
$year2 - 1900
13972+
);
1401713973

1401813974
unless ($data->{'startdate'} <= $data->{'enddate'}) {
1401913975
add_stash(
@@ -14027,27 +13983,27 @@ sub do_suspend_request_action {
1402713983
'The start date must be less than the end date.');
1402813984
return $previous_action;
1402913985
}
14030-
## Case 2 : Start date & without indefinite (without end date)
14031-
} elsif ((!$in{'date_fin'}) && ($in{'indefinite'})) {
13986+
} elsif ($in{'indefinite'}) {
13987+
# Case 2 : Start date & without indefinite (without end date)
1403213988
$data->{'enddate'} = undef;
1403313989
} else {
1403413990
add_stash(
1403513991
'user',
1403613992
'missing_arg',
1403713993
{ argument =>
14038-
'Choose end date (dd/mm/yyyy) or indefinite end date'
13994+
'Choose end date (yyyy-mm-dd) or indefinite end date'
1403913995
}
1404013996
);
1404113997
wwslog('info',
14042-
'Missing argument for the end date or syntax error : dd/mm/yyyy or must choose a end date or indefinite end date'
13998+
'Missing argument for the end date or syntax error : yyyy-mm-dd or must choose a end date or indefinite end date'
1404313999
);
1404414000
return $previous_action;
1404514001
}
1404614002
} else {
1404714003
add_stash('user', 'missing_arg',
14048-
{argument => 'Miss start date (dd/mm/yyyy)'});
14004+
{argument => 'Miss start date (yyyy-mm-dd)'});
1404914005
wwslog('info',
14050-
'Missing argument for the start date or syntax error : dd/mm/yyyy'
14006+
'Missing argument for the start date or syntax error : yyyy-mm-dd'
1405114007
);
1405214008
return $previous_action;
1405314009
}
@@ -15598,6 +15554,12 @@ sub do_viewlogs {
1559815554

1559915555
$param->{'total_results'} = 0;
1560015556

15557+
# Compat. <= 6.2.72
15558+
$in{'date_from'} =~ s/(\d\d)-(\d\d)-(\d\d\d\d)/$3-$2-$1/
15559+
if $in{'date_from'};
15560+
$in{'date_to'} =~ s/(\d\d)-(\d\d)-(\d\d\d\d)/$3-$2-$1/
15561+
if $in{'date_to'};
15562+
1560115563
my @dates = $log->get_log_date;
1560215564
($param->{'date_from_formated'}, $param->{'date_to_formated'}) = @dates
1560315565
if @dates;

src/lib/Sympa/Log.pm

+8-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
99
# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
1010
# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER
11-
# Copyright 2017, 2021 The Sympa Community. See the
11+
# Copyright 2017, 2021, 2023 The Sympa Community. See the
1212
# AUTHORS.md file at the top-level directory of this distribution and at
1313
# <https://github.com/sympa-community/sympa.git>.
1414
#
@@ -35,6 +35,7 @@ use Scalar::Util;
3535
use Sys::Syslog qw();
3636
use Time::Local qw();
3737

38+
use Sympa::Regexps;
3839
use Sympa::Tools::Time;
3940

4041
use base qw(Class::Singleton);
@@ -490,24 +491,21 @@ sub get_first_db_log {
490491
@{$action_type{$select->{'type'}}};
491492
}
492493

494+
my $html_date_re = Sympa::Regexps::html_date();
493495
#if the search is between two date
494-
if ($select->{'date_from'}) {
496+
if (($select->{'date_from'} // '') =~ /\A$html_date_re\z/) {
495497
my ($yyyy, $mm, $dd) = split /[^\da-z]/i, $select->{'date_from'};
496-
($dd, $mm, $yyyy) = ($yyyy, $mm, $dd) if 31 < $dd;
497-
$yyyy += ($yyyy < 50 ? 2000 : $yyyy < 100 ? 1900 : 0);
498498

499-
my $date_from = POSIX::mktime(0, 0, -1, $dd, $mm - 1, $yyyy - 1900);
500-
unless ($select->{'date_to'}) {
499+
my $date_from = POSIX::mktime(0, 0, -1, $dd + 0, $mm - 1, $yyyy - 1900);
500+
unless (($select->{'date_to'} // '') =~ /\A$html_date_re\z/) {
501501
my $date_from2 =
502-
POSIX::mktime(0, 0, 25, $dd, $mm - 1, $yyyy - 1900);
502+
POSIX::mktime(0, 0, 25, $dd + 0, $mm - 1, $yyyy - 1900);
503503
$statement .= sprintf "AND date_logs >= %s AND date_logs <= %s ",
504504
$date_from, $date_from2;
505505
} else {
506506
my ($yyyy, $mm, $dd) = split /[^\da-z]/i, $select->{'date_to'};
507-
($dd, $mm, $yyyy) = ($yyyy, $mm, $dd) if 31 < $dd;
508-
$yyyy += ($yyyy < 50 ? 2000 : $yyyy < 100 ? 1900 : 0);
509507

510-
my $date_to = POSIX::mktime(0, 0, 25, $dd, $mm - 1, $yyyy - 1900);
508+
my $date_to = POSIX::mktime(0, 0, 25, $dd + 0, $mm - 1, $yyyy - 1900);
511509
$statement .= sprintf "AND date_logs >= %s AND date_logs <= %s ",
512510
$date_from, $date_to;
513511
}

src/lib/Sympa/Regexps.pm

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
88
# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
99
# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER
10-
# Copyright 2017, 2021, 2022 The Sympa Community. See the
10+
# Copyright 2017, 2021, 2022, 2023 The Sympa Community. See the
1111
# AUTHORS.md file at the top-level directory of this distribution and at
1212
# <https://github.com/sympa-community/sympa.git>.
1313
#
@@ -54,6 +54,8 @@ use constant hostport => qr{(?:
5454
| [:0-9a-f]*:[:0-9a-f]*:[:0-9a-f]*
5555
| \[ [:0-9a-f]*:[:0-9a-f]*:[:0-9a-f]* \] (?::\d+)?
5656
)}ix;
57+
use constant html_date =>
58+
qr'[0-9]{4}[0-9]*-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12][0-9]|3[01])';
5759
use constant ipv6 => qr'[:0-9a-f]*:[:0-9a-f]*:[:0-9a-f]*'i;
5860
#FIXME: Cannot contain IPv6 address.
5961
use constant multiple_host_with_port =>

www/js/sympa.js

-20
Original file line numberDiff line numberDiff line change
@@ -156,26 +156,6 @@ $(function() {
156156
}
157157
});
158158

159-
/* Loading jQuery-UI Datepicker Widget. */
160-
$(function() {
161-
var options = {
162-
buttonText: sympa.calendarButtonText,
163-
changeMonth: true,
164-
changeYear: true,
165-
dateFormat: 'dd-mm-yy',
166-
dayNames: sympa.dayNames,
167-
dayNamesMin: sympa.dayNamesMin,
168-
firstDay: sympa.calendarFirstDay,
169-
monthNamesShort: sympa.monthNamesShort,
170-
shortYearCutoff: 50,
171-
showOn: "button"
172-
};
173-
$('#date_deb').datepicker(options);
174-
$('#date_from').datepicker(options);
175-
$('#date_fin').datepicker(options);
176-
$('#date_to').datepicker(options);
177-
});
178-
179159
/* Emulates AJAX reveal modal button of Foundation 5. */
180160
/* The element specified by data-reveal-id is the container of content
181161
* specified by href attribute of the item which have data-reveal-ajax="true".

0 commit comments

Comments
 (0)