2
0
forked from Wavyzz/dolibarr

Merge branch 'develop' of https://github.com/dolibarr/dolibarr into develop

This commit is contained in:
Laurent Destailleur
2020-11-30 07:50:26 +01:00
161 changed files with 1885 additions and 1685 deletions

View File

@@ -1060,7 +1060,7 @@ function dol_escape_json($stringtoescape)
* Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
*
* @param string $stringtoescape String to escape
* @param int $keepb 1=Preserve b tags (otherwise, remove them)
* @param int $keepb 1=Keep b tags and escape them, 0=remove them
* @param int $keepn 1=Preserve \r\n strings (otherwise, replace them with escaped value). Set to 1 when escaping for a <textarea>.
* @param string $keepmoretags '' or 'common' or list of tags
* @param int $escapeonlyhtmltags 1=Escape only html tags, not the special chars like accents.
@@ -1069,7 +1069,7 @@ function dol_escape_json($stringtoescape)
*/
function dol_escape_htmltag($stringtoescape, $keepb = 0, $keepn = 0, $keepmoretags = '', $escapeonlyhtmltags = 0)
{
if ($keepmoretags == 'common') $keepmoretags = 'html,body,a,em,i,u,ul,li,br,div,img,font,p,span,strong,table,tr,td,th,tbody';
if ($keepmoretags == 'common') $keepmoretags = 'html,body,a,b,em,i,u,ul,li,br,div,img,font,p,span,strong,table,tr,td,th,tbody';
// TODO Implement $keepmoretags
// escape quotes and backslashes, newlines, etc.
@@ -3192,7 +3192,7 @@ function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = false, $
$pictowithouttext = preg_replace('/(\.png|\.gif|\.svg)$/', '', $picto);
if (empty($srconly) && in_array($pictowithouttext, array(
'1downarrow', '1uparrow', '1leftarrow', '1rightarrow', '1uparrow_selected', '1downarrow_selected', '1leftarrow_selected', '1rightarrow_selected',
'accountancy', 'account', 'accountline', 'action', 'add', 'address', 'bank_account', 'barcode', 'bank', 'bill', 'bookmark', 'bom', 'building',
'accountancy', 'account', 'accountline', 'action', 'add', 'address', 'bank_account', 'barcode', 'bank', 'bill', 'billa', 'billr', 'billd', 'bookmark', 'bom', 'building',
'cash-register', 'category', 'check', 'clock', 'close_title', 'company', 'contact', 'contract', 'cubes',
'delete', 'dolly', 'dollyrevert', 'donation', 'edit', 'ellipsis-h', 'email', 'eraser', 'external-link-alt', 'external-link-square-alt',
'filter', 'file-code', 'file-export', 'file-import', 'file-upload', 'folder', 'folder-open', 'globe', 'globe-americas', 'grip', 'grip_title', 'group',
@@ -4761,14 +4761,15 @@ function price($amount, $form = 0, $outlangs = '', $trunc = 1, $rounding = -1, $
* 'MS'=Round to Max for stock quantity (MAIN_MAX_DECIMALS_STOCK)
* 'CR'=Currency rate
* Numeric = Nb of digits for rounding
* @param int $alreadysqlnb Put 1 if you know that content is already universal format number
* @param int $option Put 1 if you know that content is already universal format number (so no correction on decimal will be done)
* Put 2 if you know that number is a user input (so we know we don't have to fix decimal separator).
* @return string Amount with universal numeric format (Example: '99.99999').
* If conversion fails, it return text unchanged if $rounding = '' or '0' if $rounding is defined.
* If amount is null or '', it returns '' if $rounding = '' or '0' if $rounding is defined..
*
* @see price() Opposite function of price2num
*/
function price2num($amount, $rounding = '', $alreadysqlnb = 0)
function price2num($amount, $rounding = '', $option = 0)
{
global $langs, $conf;
@@ -4783,14 +4784,19 @@ function price2num($amount, $rounding = '', $alreadysqlnb = 0)
//print "amount=".$amount." html=".$form." trunc=".$trunc." nbdecimal=".$nbdecimal." dec='".$dec."' thousand='".$thousand."'<br>";
// Convert value to universal number format (no thousand separator, '.' as decimal separator)
if ($alreadysqlnb != 1) { // If not a PHP number or unknown, we change or clean format
if ($option != 1) { // If not a PHP number or unknown, we change or clean format
//print 'PP'.$amount.' - '.$dec.' - '.$thousand.' - '.intval($amount).'<br>';
if ($thousand == '.' && preg_match('/\.(\d\d\d)$/', (string) $amount)) { // It means the . is used as a thousand separator, not as a decimal separator
$amount = str_replace($thousand, '', $amount); // Replace of thousand before test of is_numeric to avoid pb if thousand is . and there is 3 numbers after
if (!is_numeric($amount)) {
$amount = preg_replace('/[a-zA-Z\/\\\*\(\)\<\>\-]/', '', $amount);
}
if ($option == 2 && $thousand == '.' && preg_match('/\.(\d\d\d)$/', (string) $amount)) { // It means the . is used as a thousand separator and string come frominput data, so 1.123 is 1123
$amount = str_replace($thousand, '', $amount);
}
// Convert amount to format with dolibarr dec and thousand (this is because PHP convert a number
// to format defined by LC_NUMERIC after a calculation and we want source format to be like defined by Dolibarr setup.
// So if number was already a good number, it is converted into local Dolibarr setup.
if (is_numeric($amount))
{
// We put in temps value of decimal ("0.00001"). Works with 0 and 2.0E-5 and 9999.10
@@ -4799,7 +4805,7 @@ function price2num($amount, $rounding = '', $alreadysqlnb = 0)
$nbofdec = max(0, dol_strlen($temps) - 2); // -2 to remove "0."
$amount = number_format($amount, $nbofdec, $dec, $thousand);
}
//print "QQ".$amount.'<br>';
//print "QQ".$amount."<br>\n";
// Now make replace (the main goal of function)
if ($thousand != ',' && $thousand != '.') {
@@ -6731,7 +6737,7 @@ function get_date_range($date_start, $date_end, $format = '', $outputlangs = '',
*
* @param string $firstname Firstname
* @param string $lastname Lastname
* @param int $nameorder -1=Auto, 0=Lastname+Firstname, 1=Firstname+Lastname, 2=Firstname, 3=Firstname if defined else lastname
* @param int $nameorder -1=Auto, 0=Lastname+Firstname, 1=Firstname+Lastname, 2=Firstname, 3=Firstname if defined else lastname, 4=Lastname, 5=Lastname if defined else firstname
* @return string Firstname + lastname or Lastname + firstname
*/
function dolGetFirstLastname($firstname, $lastname, $nameorder = -1)
@@ -6741,22 +6747,24 @@ function dolGetFirstLastname($firstname, $lastname, $nameorder = -1)
$ret = '';
// If order not defined, we use the setup
if ($nameorder < 0) $nameorder = (empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION) ? 1 : 0);
if ($nameorder && $nameorder != 2 && $nameorder != 3)
{
if ($nameorder == 1) {
$ret .= $firstname;
if ($firstname && $lastname) $ret .= ' ';
$ret .= $lastname;
} elseif ($nameorder == 2 || $nameorder == 3)
{
} elseif ($nameorder == 2 || $nameorder == 3) {
$ret .= $firstname;
if (empty($ret) && $nameorder == 3)
{
if (empty($ret) && $nameorder == 3) {
$ret .= $lastname;
}
} else {
} else { // 0, 4 or 5
$ret .= $lastname;
if ($firstname && $lastname) $ret .= ' ';
$ret .= $firstname;
if (empty($ret) && $nameorder == 5) {
$ret .= $firstname;
}
if ($nameorder == 0) {
if ($firstname && $lastname) $ret .= ' ';
$ret .= $firstname;
}
}
return $ret;
}
@@ -7256,14 +7264,12 @@ function dol_validElement($element)
/**
* Return img flag of country for a language code or country code
*
* @param string $codelang Language code (en_IN, fr_CA...) or Country code (IN, FR)
* @param string $moreatt Add more attribute on img tag (For example 'style="float: right"')
* @param string $codelang Language code ('en_IN', 'fr_CA', ...) or ISO Country code on 2 characters in uppercase ('IN', 'FR')
* @param string $moreatt Add more attribute on img tag (For example 'style="float: right"' or 'class="saturatemedium"')
* @return string HTML img string with flag.
*/
function picto_from_langcode($codelang, $moreatt = '')
{
global $langs;
if (empty($codelang)) return '';
if ($codelang == 'auto')
@@ -7276,7 +7282,14 @@ function picto_from_langcode($codelang, $moreatt = '')
'ca_ES' => 'catalonia',
'da_DA' => 'dk',
'fr_CA' => 'mq',
'sv_SV' => 'se'
'sv_SV' => 'se',
'AQ' => 'unknown',
'CW' => 'unknown',
'IM' => 'unknown',
'JE' => 'unknown',
'MF' => 'unknown',
'BL' => 'unknown',
'SX' => 'unknown'
);
if (isset($langtocountryflag[$codelang])) $flagImage = $langtocountryflag[$codelang];