diff --git a/htdocs/admin/defaultvalues.php b/htdocs/admin/defaultvalues.php
index 013be811b5b..7ebc67472d1 100644
--- a/htdocs/admin/defaultvalues.php
+++ b/htdocs/admin/defaultvalues.php
@@ -271,6 +271,12 @@ if ($mode != 'focus')
$texthelp.='__DAY__
';
$texthelp.='__MONTH__
';
$texthelp.='__YEAR__
';
+ $texthelp.='__PREVIOUS_DAY__
';
+ $texthelp.='__PREVIOUS_MONTH__
';
+ $texthelp.='__PREVIOUS_YEAR__
';
+ $texthelp.='__NEXT_DAY__
';
+ $texthelp.='__NEXT_MONTH__
';
+ $texthelp.='__NEXT_YEAR__
';
if (! empty($conf->multicompany->enabled)) $texthelp.='__ENTITYID__
';
$textvalue=$form->textwithpicto($langs->trans("Value"), $texthelp, 1, 'help', '', 0, 2, '');
}
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index d2638898a33..63990112be5 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -240,7 +240,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), 'day', 'month', 'year', 'custom'= custom filter specify $filter and $options)
+ * @param string $check Type of check (''=no check, 'none'=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'.
@@ -249,6 +249,8 @@ function dol_shutdown()
*/
function GETPOST($paramname, $check='', $method=0, $filter=NULL, $options=NULL)
{
+ global $mysoc,$user,$conf;
+
if (empty($method)) $out = isset($_GET[$paramname])?$_GET[$paramname]:(isset($_POST[$paramname])?$_POST[$paramname]:'');
elseif ($method==1) $out = isset($_GET[$paramname])?$_GET[$paramname]:'';
elseif ($method==2) $out = isset($_POST[$paramname])?$_POST[$paramname]:'';
@@ -258,8 +260,6 @@ function GETPOST($paramname, $check='', $method=0, $filter=NULL, $options=NULL)
if (empty($method) || $method == 3 || $method == 4)
{
- global $conf;
-
// Management of default values
if (! isset($_GET['sortfield']) && ! empty($conf->global->MAIN_ENABLE_DEFAULT_VALUES)) // If we did a click on a field to sort, we do no apply default values. Same if option MAIN_DISABLE_DEFAULT_VALUES is on
{
@@ -320,43 +320,41 @@ function GETPOST($paramname, $check='', $method=0, $filter=NULL, $options=NULL)
if (! empty($check))
{
// Replace vars like __DAY__, __MONTH__, __YEAR__, __MYCOUNTRYID__, __USERID__, __ENTITYID__
- // TODO Add more var like __PREVIOUSDAY__, __PREVIOUSMONTH__, __PREVIOUSYEAR__
- if (! is_array($out) && preg_match('/^__([a-z0-9]+)__$/i', $out, $reg))
+ if (! is_array($out))
{
- if ($reg[1] == 'DAY')
+ $maxloop=20; $loopnb=0; // Protection against infinite loop
+ while (preg_match('/__([A-Z0-9]+_?[A-Z0-9]+)__/i', $out, $reg) && ($loopnb < $maxloop)) // Detect '__ABCDEF__' as key 'ABCDEF' and '__ABC_DEF__' as key 'ABC_DEF'
{
- $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'];
- }
- elseif ($reg[1] == 'MYCOUNTRYID')
- {
- global $mysoc;
- $out = $mysoc->country_id;
- }
- elseif ($reg[1] == 'USERID')
- {
- global $user;
- $out = $user->id;
- }
- elseif ($reg[1] == 'SUPERVISORID')
- {
- global $user;
- $out = $user->fk_user;
- }
- elseif ($reg[1] == 'ENTITYID')
- {
- global $conf;
- $out = $conf->entity;
+ $loopnb++; $newout = '';
+
+ if ($reg[1] == 'DAY') { $tmp=dol_getdate(dol_now(), true); $newout = $tmp['mday']; }
+ elseif ($reg[1] == 'MONTH') { $tmp=dol_getdate(dol_now(), true); $newout = $tmp['mon']; }
+ elseif ($reg[1] == 'YEAR') { $tmp=dol_getdate(dol_now(), true); $newout = $tmp['year']; }
+ elseif ($reg[1] == 'PREVIOUS_DAY') { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_prev_day($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['day']; }
+ elseif ($reg[1] == 'PREVIOUS_MONTH') { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_prev_month($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['month']; }
+ elseif ($reg[1] == 'PREVIOUS_YEAR') { $tmp=dol_getdate(dol_now(), true); $newout = ($tmp['year'] - 1); }
+ elseif ($reg[1] == 'NEXT_DAY') { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_next_day($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['day']; }
+ elseif ($reg[1] == 'NEXT_MONTH') { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_next_month($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['month']; }
+ elseif ($reg[1] == 'NEXT_YEAR') { $tmp=dol_getdate(dol_now(), true); $newout = ($tmp['year'] + 1); }
+ elseif ($reg[1] == 'MYCOUNTRYID')
+ {
+ $newout = $mysoc->country_id;
+ }
+ elseif ($reg[1] == 'USERID')
+ {
+ $newout = $user->id;
+ }
+ elseif ($reg[1] == 'SUPERVISORID')
+ {
+ $newout = $user->fk_user;
+ }
+ elseif ($reg[1] == 'ENTITYID')
+ {
+ $newout = $conf->entity;
+ }
+ else $newout = ''; // Key not found, we replace with empty string
+ //var_dump('__'.$reg[1].'__ -> '.$newout);
+ $out = preg_replace('/__'.preg_quote($reg[1],'/').'__/', $newout, $out);
}
}
diff --git a/htdocs/projet/card.php b/htdocs/projet/card.php
index 791cd6855f0..1ee81f7b917 100644
--- a/htdocs/projet/card.php
+++ b/htdocs/projet/card.php
@@ -142,9 +142,9 @@ if (empty($reshook))
$db->begin();
$object->ref = GETPOST('ref','alpha');
- $object->title = GETPOST('title'); // Do not use 'alpha' here, we want field as it is
+ $object->title = GETPOST('title','none'); // Do not use 'alpha' here, we want field as it is
$object->socid = GETPOST('socid','int');
- $object->description = GETPOST('description'); // Do not use 'alpha' here, we want field as it is
+ $object->description = GETPOST('description','none'); // Do not use 'alpha' here, we want field as it is
$object->public = GETPOST('public','alpha');
$object->opp_amount = price2num(GETPOST('opp_amount'));
$object->budget_amount = price2num(GETPOST('budget_amount'));
@@ -243,9 +243,9 @@ if (empty($reshook))
$old_start_date = $object->date_start;
$object->ref = GETPOST('ref','alpha');
- $object->title = GETPOST('title'); // Do not use 'alpha' here, we want field as it is
+ $object->title = GETPOST('title','none'); // Do not use 'alpha' here, we want field as it is
$object->socid = GETPOST('socid','int');
- $object->description = GETPOST('description'); // Do not use 'alpha' here, we want field as it is
+ $object->description = GETPOST('description','none'); // Do not use 'alpha' here, we want field as it is
$object->public = GETPOST('public','alpha');
$object->date_start = empty($_POST["projectstart"])?'':$date_start;
$object->date_end = empty($_POST["projectend"])?'':$date_end;
@@ -509,7 +509,7 @@ if ($action == 'create' && $user->rights->projet->creer)
print '';
// Label
- print '