From cd9654978b5c3e9ff47abf1a564e588973cd9b98 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 9 Oct 2016 19:49:09 +0200 Subject: [PATCH] NEW Filters can accept generic search key like __DAY__, __MONTH__, __YEAR__ replaced with current day, month year before making the search. --- htdocs/comm/propal/list.php | 3 ++- htdocs/core/lib/functions.lib.php | 27 +++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/htdocs/comm/propal/list.php b/htdocs/comm/propal/list.php index 7441fb751b9..41cd63ff446 100644 --- a/htdocs/comm/propal/list.php +++ b/htdocs/comm/propal/list.php @@ -79,9 +79,10 @@ $object_statut=GETPOST('propal_statut'); $sall=GETPOST("sall"); $mesg=(GETPOST("msg") ? GETPOST("msg") : GETPOST("mesg")); + $day=GETPOST("day","int"); -$year=GETPOST("year","int"); $month=GETPOST("month","int"); +$year=GETPOST("year","int"); $limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index ba745ad04ce..9f71539478a 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -228,7 +228,7 @@ function dol_shutdown() * Return value of a param into GET or POST supervariable * * @param string $paramname Name of parameter to found - * @param string $check Type of check (''=no check, 'int'=check it's numeric, 'alpha'=check it's text and sign, 'aZ'=check it's a-z only, 'array'=check it's array, 'san_alpha'=Use filter_var with FILTER_SANITIZE_STRING (do not use this for free text string), 'custom'= custom filter specify $filter and $options) + * @param string $check Type of check (''=no check, 'int'=check it's numeric, 'alpha'=check it's text and sign, 'aZ'=check it's a-z only, 'array'=check it's array, 'san_alpha'=Use filter_var with FILTER_SANITIZE_STRING (do not use this for free text string), 'day', 'month', 'year', 'custom'= custom filter specify $filter and $options) * @param int $method Type of method (0 = get then post, 1 = only get, 2 = only post, 3 = post then get, 4 = post then get then cookie) * @param int $filter Filter to apply when $check is set to custom. (See http://php.net/manual/en/filter.filters.php for détails) * @param mixed $options Options to pass to filter_var when $check is set to custom @@ -245,6 +245,25 @@ function GETPOST($paramname,$check='',$method=0,$filter=NULL,$options=NULL) if (! empty($check)) { + if (preg_match('/^__([a-z0-9]+)__$/i', $out, $reg)) + { + if ($reg[1] == 'DAY') + { + $tmp=dol_getdate(dol_now(), true); + $out = $tmp['mday']; + } + elseif ($reg[1] == 'MONTH') + { + $tmp=dol_getdate(dol_now(), true); + $out = $tmp['mon']; + } + elseif ($reg[1] == 'YEAR') + { + $tmp=dol_getdate(dol_now(), true); + $out = $tmp['year']; + } + } + switch ($check) { case 'int': @@ -271,13 +290,13 @@ function GETPOST($paramname,$check='',$method=0,$filter=NULL,$options=NULL) case 'array': if (! is_array($out) || empty($out)) $out=array(); break; + case 'nohtml': + $out=dol_string_nohtmltag($out); + break; case 'custom': if (empty($filter)) return 'BadFourthParameterForGETPOST'; $out=filter_var($out, $filter, $options); break; - case 'nohtml': - $out=dol_string_nohtmltag($out); - break; } }