2
0
forked from Wavyzz/dolibarr

Merge branch 'develop' into patch-1

This commit is contained in:
Laurent Destailleur
2025-02-21 15:58:10 +01:00
committed by GitHub
259 changed files with 5316 additions and 2676 deletions

View File

@@ -1157,35 +1157,57 @@ function GETPOSTFLOAT($paramname, $rounding = '')
* Helper function that combines values of a dolibarr DatePicker (such as Form::selectDate) for year, month, day (and
* optionally hour, minute, second) fields to return a timestamp.
*
* @param string $prefix Prefix used to build the date selector (for instance using Form::selectDate)
* @param string $hourTime 'getpost' to include hour, minute, second values from the HTTP request,
* or 'XX:YY:ZZ' to set hour, minute, second respectively (for instance '23:59:59')
* or '' means '00:00:00' (default)
* @param int|string $gm Passed to dol_mktime
* @return int|string Date as a timestamp, '' or false if error
* @param string $prefix Prefix used to build the date selector (for instance using Form::selectDate). Example: 'select_datec'
* @param string $hourTime 'getpost' or 'getpostend' to include hour, minute, second values from the HTTP request,
* or 'XX:YY:ZZ' to set hour, minute, second respectively, for example '23:59:59'
* or 'end' means '23:59:59'
* or '' means '00:00:00' (default)
* @param int|string $gm Passed to dol_mktime. In most cases, when used with 'getpost' or 'getpostend', it should be 'tzuserrel'. Use 'auto' if you need dates related to 'tzserver' (like in accountancy).
* @param string $saverestore Use a string context to save retrieved date so it will be used on next retrieve using same context if not defined.
* @return int|string Date as a timestamp, '' or false if error
*
* @see dol_mktime()
*/
function GETPOSTDATE($prefix, $hourTime = '', $gm = 'auto')
function GETPOSTDATE($prefix, $hourTime = '', $gm = 'auto', $saverestore = '')
{
$m = array();
if ($hourTime === 'getpost') {
$hour = GETPOSTINT($prefix . 'hour');
$minute = GETPOSTINT($prefix . 'minute');
$second = GETPOSTINT($prefix . 'second');
if ($hourTime === 'getpost' || $hourTime === 'getpostend') {
$hour = (GETPOSTISSET($prefix . 'hour') && GETPOSTINT($prefix . 'hour') >= 0) ? GETPOSTINT($prefix . 'hour') : ($hourTime === 'getpostend' ? 23 : 0);
$minute = (GETPOSTISSET($prefix . 'min') && GETPOSTINT($prefix . 'min') >= 0) ? GETPOSTINT($prefix . 'min') : ($hourTime === 'getpostend' ? 59 : 0);
$second = (GETPOSTISSET($prefix . 'second') && GETPOSTINT($prefix . 'second') >= 0) ? GETPOSTINT($prefix . 'second') : ($hourTime === 'getpostend' ? 59 : 0);
} elseif (preg_match('/^(\d\d):(\d\d):(\d\d)$/', $hourTime, $m)) {
$hour = intval($m[1]);
$minute = intval($m[2]);
$second = intval($m[3]);
} elseif ($hourTime === 'end') {
$hour = 23; $minute = 59; $second = 59;
} else {
$hour = $minute = $second = 0;
}
if ($saverestore && !GETPOSTISSET($prefix.'day') && !GETPOSTISSET($prefix.'month') && !GETPOSTISSET($prefix.'year')) {
$day = $_SESSION['DOLDATE_'.$saverestore.'_day'];
$month = $_SESSION['DOLDATE_'.$saverestore.'_month'];
$year = $_SESSION['DOLDATE_'.$saverestore.'_year'];
} else {
$month = GETPOSTINT($prefix . 'month');
$day = GETPOSTINT($prefix . 'day');
$year = GETPOSTINT($prefix . 'year');
}
// normalize out of range values
$hour = (int) min($hour, 23);
$minute = (int) min($minute, 59);
$second = (int) min($second, 59);
return dol_mktime($hour, $minute, $second, GETPOSTINT($prefix . 'month'), GETPOSTINT($prefix . 'day'), GETPOSTINT($prefix . 'year'), $gm);
if ($saverestore) {
$_SESSION['DOLDATE_'.$saverestore.'_day'] = $day;
$_SESSION['DOLDATE_'.$saverestore.'_month'] = $month;
$_SESSION['DOLDATE_'.$saverestore.'_year'] = $year;
}
//print "$hour, $minute, $second, $month, $day, $year, $gm<br>";
return dol_mktime($hour, $minute, $second, $month, $day, $year, $gm);
}
@@ -1563,16 +1585,16 @@ function dol_get_object_properties($obj, $properties = [])
/**
* Create a clone of instance of object (new instance with same value for each properties)
* Create a clone of instance of object (new instance with same value for each properties)
* With native = 0: Property that are references are different memory area in the new object (full isolation clone). This means $this->object of new object may not be valid (except this->db that is voluntarly kept).
* With native = 1: Use PHP clone. Property that are reference are same pointer. This means $this->db of new object is still valid but point to same this->db than original object.
* With native = 2: Property that are reference are different memory area in the new object (full isolation clone). Only scalar and array values are cloned. This means method are not availables and $this->db of new object is not valid.
*
* @template T
*
* @param T $object Object to clone
* @param T $object Object to clone
* @param int $native 0=Full isolation method, 1=Native PHP method, 2=Full isolation method keeping only scalar and array properties (recommended)
* @return T Clone object
* @return T Clone object
*
* @see https://php.net/manual/language.oop5.cloning.php
* @phan-suppress PhanTypeExpectedObjectPropAccess
@@ -4467,6 +4489,14 @@ function dol_print_phone($phone, $countrycode = '', $cid = 0, $socid = 0, $addli
$newphonewa = $newphone;
$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 10, 3).$separ.substr($newphone, 14, 3);
}
} elseif (strtoupper($countrycode) == "IN") {//India
if (dol_strlen($phone) == 13) {
if ($withpicto == 'phone') {//ex: +91_AB_CDEF_GHIJ
$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 2).$separ.substr($newphone, 5, 4).$separ.substr($newphone, 9, 4);
} else {//ex: +91_ABCDE_FGHIJ
$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 5).$separ.substr($newphone, 8, 5);
}
}
}
$newphoneastart = $newphoneaend = '';
@@ -14139,7 +14169,7 @@ function forgeSQLFromUniversalSearchCriteria($filter, &$errorstr = '', $noand =
$ret = ($noand ? "" : " AND ").($nopar ? "" : '(').preg_replace_callback('/'.$regexstring.'/i', 'dolForgeSQLCriteriaCallback', $filter).($nopar ? "" : ')');
if (is_object($db)) {
$ret = str_replace('__NOW__', $db->idate(dol_now()), $ret);
$ret = str_replace('__NOW__', "'".$db->idate(dol_now())."'", $ret);
}
if (is_object($user)) {
$ret = str_replace('__USER_ID__', (string) $user->id, $ret);
@@ -14370,8 +14400,10 @@ function dolForgeSQLCriteriaCallback($matches)
$tmpescaped = 'NULL';
} elseif (ctype_digit((string) $tmpescaped)) { // if only 0-9 chars, no .
$tmpescaped = (int) $tmpescaped;
} else {
} elseif (is_numeric((string) $tmpescaped)) { // it can be a float with a .
$tmpescaped = (float) $tmpescaped;
} else {
$tmpescaped = preg_replace('/[^a-z0-9_]/i', '', $tmpescaped); // it can be a name of field or a substitution variable like '__NOW__'
}
}