mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-09 02:58:23 +01:00
Merge remote-tracking branch 'upstream/develop' into develop
Conflicts: htdocs/core/lib/functions.lib.php
This commit is contained in:
@@ -44,6 +44,7 @@ include_once DOL_DOCUMENT_ROOT .'/core/lib/json.lib.php';
|
||||
* @param string $class Class name
|
||||
* @param string $member Name of property
|
||||
* @return mixed Return value of static property
|
||||
* @deprecated Dolibarr now requires 5.3.0+
|
||||
*/
|
||||
function getStaticMember($class, $member)
|
||||
{
|
||||
@@ -122,49 +123,85 @@ function getEntity($element=false, $shared=0)
|
||||
/**
|
||||
* Return information about user browser
|
||||
*
|
||||
* @return array Array of information ('browsername'=>,'browseros'=>,'browserversion'=>,'layout'=>(classic|phone|tablet))
|
||||
* Returns array with the following format:
|
||||
* array(
|
||||
* 'browsername' => Browser name (firefox|chrome|iceweasel|epiphany|safari|opera|ie|unknown)
|
||||
* 'browserversion' => Browser version. Empty if unknown
|
||||
* 'browseros' => Set with mobile OS (android|blackberry|ios|palm|symbian|webos|maemo|windows|unknown)
|
||||
* 'layout' => (tablet|phone|classic)
|
||||
* 'phone' => empty if not mobile, (android|blackberry|ios|palm|unknown) if mobile
|
||||
* 'tablet' => true/false
|
||||
* )
|
||||
*
|
||||
* @param string $user_agent Content of $_SERVER["HTTP_USER_AGENT"] variable
|
||||
* @return array Check function documentation
|
||||
*/
|
||||
function getBrowserInfo()
|
||||
function getBrowserInfo($user_agent)
|
||||
{
|
||||
$name='unknown'; $version=''; $os='unknown'; $phone=''; $tablet='';
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/mobiledetect.class.php';
|
||||
|
||||
// If phone/smartphone, we set phone os name.
|
||||
if (preg_match('/android/i',$_SERVER["HTTP_USER_AGENT"])) { $os=$phone='android'; }
|
||||
elseif (preg_match('/blackberry/i',$_SERVER["HTTP_USER_AGENT"])) { $os=$phone='blackberry'; }
|
||||
elseif (preg_match('/iphone/i',$_SERVER["HTTP_USER_AGENT"])) { $os='ios'; $phone='iphone'; }
|
||||
elseif (preg_match('/ipod/i',$_SERVER["HTTP_USER_AGENT"])) { $os='ios'; $phone='iphone'; }
|
||||
elseif (preg_match('/palm/i',$_SERVER["HTTP_USER_AGENT"])) { $os=$phone='palm'; }
|
||||
elseif (preg_match('/symbian/i',$_SERVER["HTTP_USER_AGENT"])) { $os='symbian'; $phone='unknown'; }
|
||||
elseif (preg_match('/webos/i',$_SERVER["HTTP_USER_AGENT"])) { $os='webos'; $phone='unknown'; }
|
||||
elseif (preg_match('/maemo/i',$_SERVER["HTTP_USER_AGENT"])) { $os='maemo'; $phone='unknown'; }
|
||||
// MS products at end
|
||||
elseif (preg_match('/iemobile/i',$_SERVER["HTTP_USER_AGENT"])) { $os='windows'; $phone='unkown'; }
|
||||
elseif (preg_match('/windows ce/i',$_SERVER["HTTP_USER_AGENT"])) { $os='windows'; $phone='unkown'; }
|
||||
$name='unknown';
|
||||
$version='';
|
||||
$os='unknown';
|
||||
$phone = '';
|
||||
|
||||
$detectmobile = new MobileDetect(null, $user_agent);
|
||||
$tablet = $detectmobile->isTablet();
|
||||
|
||||
if ($detectmobile->isMobile()) {
|
||||
|
||||
$phone = 'unknown';
|
||||
|
||||
// If phone/smartphone, we set phone os name.
|
||||
if ($detectmobile->is('AndroidOS')) {
|
||||
$os = $phone = 'android';
|
||||
} elseif ($detectmobile->is('BlackBerryOS')) {
|
||||
$os = $phone = 'blackberry';
|
||||
} elseif ($detectmobile->is('iOS')) {
|
||||
$os = 'ios';
|
||||
$phone = 'iphone';
|
||||
} elseif ($detectmobile->is('PalmOS')) {
|
||||
$os = $phone = 'palm';
|
||||
} elseif ($detectmobile->is('SymbianOS')) {
|
||||
$os = 'symbian';
|
||||
} elseif ($detectmobile->is('webOS')) {
|
||||
$os = 'webos';
|
||||
} elseif ($detectmobile->is('MaemoOS')) {
|
||||
$os = 'maemo';
|
||||
} elseif ($detectmobile->is('WindowsMobileOS') || $detectmobile->is('WindowsPhoneOS')) {
|
||||
$os = 'windows';
|
||||
}
|
||||
}
|
||||
|
||||
// OS
|
||||
if (preg_match('/android/i',$_SERVER["HTTP_USER_AGENT"])) { $os='android'; }
|
||||
elseif (preg_match('/linux/i',$_SERVER["HTTP_USER_AGENT"])) { $os='linux'; }
|
||||
if (preg_match('/linux/i', $user_agent)) { $os='linux'; }
|
||||
|
||||
// Name
|
||||
if (preg_match('/firefox(\/|\s)([\d\.]*)/i', $_SERVER["HTTP_USER_AGENT"], $reg)) { $name='firefox'; $version=$reg[2]; }
|
||||
elseif (preg_match('/chrome(\/|\s)([\d\.]+)/i', $_SERVER["HTTP_USER_AGENT"], $reg)) { $name='chrome'; $version=$reg[2]; } // we can have 'chrome (Mozilla...) chrome x.y' in one string
|
||||
elseif (preg_match('/chrome/i', $_SERVER["HTTP_USER_AGENT"], $reg)) { $name='chrome'; }
|
||||
elseif (preg_match('/iceweasel/i',$_SERVER["HTTP_USER_AGENT"])) { $name='iceweasel'; $version=$reg[2]; }
|
||||
elseif (preg_match('/epiphany/i',$_SERVER["HTTP_USER_AGENT"])) { $name='epiphany'; $version=$reg[2]; }
|
||||
elseif ((empty($phone) || preg_match('/iphone/i',$_SERVER["HTTP_USER_AGENT"])) && preg_match('/safari(\/|\s)([\d\.]*)/i',$_SERVER["HTTP_USER_AGENT"], $reg)) { $name='safari'; $version=$reg[2]; } // Safari is often present in string for mobile but its not.
|
||||
elseif (preg_match('/opera(\/|\s)([\d\.]*)/i', $_SERVER["HTTP_USER_AGENT"], $reg)) { $name='opera'; $version=$reg[2]; }
|
||||
elseif (preg_match('/(MSIE\s([0-9]+\.[0-9]))|.*(Trident\/[0-9]+.[0-9];\srv:([0-9]+\.[0-9]+))/i', $_SERVER["HTTP_USER_AGENT"], $reg)) { $name='ie'; $version= end($reg); } // MS products at end
|
||||
// Other
|
||||
$firefox=0;
|
||||
if (in_array($name,array('firefox','iceweasel'))) $firefox=1;
|
||||
if (preg_match('/firefox(\/|\s)([\d\.]*)/i', $user_agent, $reg)) { $name='firefox'; $version=$reg[2]; }
|
||||
elseif (preg_match('/chrome(\/|\s)([\d\.]+)/i', $user_agent, $reg)) { $name='chrome'; $version=$reg[2]; } // we can have 'chrome (Mozilla...) chrome x.y' in one string
|
||||
elseif (preg_match('/chrome/i', $user_agent, $reg)) { $name='chrome'; }
|
||||
elseif (preg_match('/iceweasel/i', $user_agent)) { $name='iceweasel'; $version=$reg[2]; }
|
||||
elseif (preg_match('/epiphany/i', $user_agent)) { $name='epiphany'; $version=$reg[2]; }
|
||||
elseif (preg_match('/safari(\/|\s)([\d\.]*)/i', $user_agent, $reg)) { $name='safari'; $version=$reg[2]; } // Safari is often present in string for mobile but its not.
|
||||
elseif (preg_match('/opera(\/|\s)([\d\.]*)/i', $user_agent, $reg)) { $name='opera'; $version=$reg[2]; }
|
||||
elseif (preg_match('/(MSIE\s([0-9]+\.[0-9]))|.*(Trident\/[0-9]+.[0-9];\srv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) { $name='ie'; $version=end($reg); } // MS products at end
|
||||
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/mobiledetect.class.php';
|
||||
$detectmobile=new MobileDetect();
|
||||
$phone=$detectmobile->isMobile();
|
||||
$tablet=$detectmobile->isTablet();
|
||||
unset($detectmobile); // free memory
|
||||
if ($tablet) {
|
||||
$layout = 'tablet';
|
||||
} elseif ($phone) {
|
||||
$layout = 'phone';
|
||||
} else {
|
||||
$layout = 'classic';
|
||||
}
|
||||
|
||||
return array('browsername'=>$name, 'browserversion'=>$version, 'browseros'=>$os, 'browserfirefox'=>$firefox, 'layout'=> ($tablet?'tablet':($phone?'phone':'classic')), 'phone'=>$phone, 'tablet'=>$tablet);
|
||||
return array(
|
||||
'browsername' => $name,
|
||||
'browserversion' => $version,
|
||||
'browseros' => $os,
|
||||
'layout' => $layout,
|
||||
'phone' => $phone,
|
||||
'tablet' => $tablet
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -382,7 +419,7 @@ function dol_size($size,$type='')
|
||||
*
|
||||
* @param string $str String to clean
|
||||
* @param string $newstr String to replace bad chars with
|
||||
* @param string $unaccent 1=Remove also accent (default), 0 do not remove them
|
||||
* @param int $unaccent 1=Remove also accent (default), 0 do not remove them
|
||||
* @return string String cleaned (a-zA-Z_)
|
||||
*
|
||||
* @see dol_string_nospecial, dol_string_unaccent
|
||||
@@ -484,8 +521,8 @@ function dolEscapeXML($string)
|
||||
* Returns text escaped for inclusion into javascript code
|
||||
*
|
||||
* @param string $stringtoescape String to escape
|
||||
* @param string $mode 0=Escape also ' and " into ', 1=Escape ' but not " for usage into 'string', 2=Escape " but not ' for usage into "string", 3=Escape ' and " with \
|
||||
* @param string $noescapebackslashn 0=Escape also \n. 1=Do not escape \n.
|
||||
* @param int $mode 0=Escape also ' and " into ', 1=Escape ' but not " for usage into 'string', 2=Escape " but not ' for usage into "string", 3=Escape ' and " with \
|
||||
* @param int $noescapebackslashn 0=Escape also \n. 1=Do not escape \n.
|
||||
* @return string Escaped string. Both ' and " are escaped into ' if they are escaped.
|
||||
*/
|
||||
function dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
|
||||
@@ -569,7 +606,7 @@ function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename='
|
||||
global $conf, $user;
|
||||
|
||||
// If syslog module enabled
|
||||
if (empty($conf->syslog->enabled)) return false;
|
||||
if (empty($conf->syslog->enabled)) return;
|
||||
|
||||
if (! empty($level))
|
||||
{
|
||||
@@ -579,7 +616,7 @@ function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename='
|
||||
{
|
||||
throw new Exception('Incorrect log level');
|
||||
}
|
||||
if ($level > $conf->global->SYSLOG_LEVEL) return false;
|
||||
if ($level > $conf->global->SYSLOG_LEVEL) return;
|
||||
|
||||
// If adding log inside HTML page is required
|
||||
if (! empty($_REQUEST['logtohtml']) && ! empty($conf->global->MAIN_LOGTOHTML))
|
||||
@@ -587,6 +624,7 @@ function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename='
|
||||
$conf->logbuffer[] = dol_print_date(time(),"%Y-%m-%d %H:%M:%S")." ".$message;
|
||||
}
|
||||
|
||||
//TODO: Remove this. MAIN_ENABLE_LOG_HTML should be deprecated and use a HTML handler
|
||||
// If enable html log tag enabled and url parameter log defined, we show output log on HTML comments
|
||||
if (! empty($conf->global->MAIN_ENABLE_LOG_HTML) && ! empty($_GET["log"]))
|
||||
{
|
||||
@@ -812,7 +850,7 @@ function dol_bc($var,$moreclass='')
|
||||
* @param Object $object A company or contact object
|
||||
* @param int $withcountry 1=Add country into address string
|
||||
* @param string $sep Separator to use to build string
|
||||
* @param Tranlsate $outputlangs Object lang that contains language for text translation.
|
||||
* @param Translate $outputlangs Object lang that contains language for text translation.
|
||||
* @return string Formated string
|
||||
*/
|
||||
function dol_format_address($object,$withcountry=0,$sep="\n",$outputlangs='')
|
||||
@@ -1393,7 +1431,7 @@ function dol_print_skype($skype,$cid=0,$socid=0,$addlink=0,$max=64)
|
||||
* @param string $country Country code to use for formatting
|
||||
* @param int $cid Id of contact if known
|
||||
* @param int $socid Id of third party if known
|
||||
* @param int $addlink ''=no link to create action, 'AC_TEL'=add link to clicktodial (if module enabled) and add link to create event (if conf->global->AGENDA_ADDACTIONFORPHONE set)
|
||||
* @param string $addlink ''=no link to create action, 'AC_TEL'=add link to clicktodial (if module enabled) and add link to create event (if conf->global->AGENDA_ADDACTIONFORPHONE set)
|
||||
* @param string $separ Separation between numbers for a better visibility example : xx.xx.xx.xx.xx
|
||||
* @param string $withpicto Show picto
|
||||
* @return string Formated phone number
|
||||
@@ -1610,6 +1648,7 @@ function isValidEmail($address)
|
||||
/**
|
||||
* Return true if phone number syntax is ok
|
||||
*
|
||||
* TODO: Decide what to do with this
|
||||
* @param string $phone phone (Ex: "0601010101")
|
||||
* @return boolean true if phone syntax is OK, false if KO or empty string
|
||||
*/
|
||||
@@ -2697,7 +2736,7 @@ function print_fiche_titre($title, $mesg='', $picto='title.png', $pictoisfullpat
|
||||
* @param int $id To force an id on html objects
|
||||
* @return string
|
||||
*/
|
||||
function load_fiche_titre($titre, $mesg='', $picto='title.png', $pictoisfullpath=0, $id='')
|
||||
function load_fiche_titre($titre, $mesg='', $picto='title.png', $pictoisfullpath=0, $id=0)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
@@ -3243,7 +3282,7 @@ function getLocalTaxesFromRate($vatrate, $local, $buyer, $seller)
|
||||
{
|
||||
global $db;
|
||||
|
||||
dol_syslog("getLocalTaxesFromRate vatrate=".$vatrate." local=".$local." thirdparty id=".(is_object($thirdparty)?$thirdparty->id:''));
|
||||
dol_syslog("getLocalTaxesFromRate vatrate=".$vatrate." local=".$local);
|
||||
|
||||
// Search local taxes
|
||||
$sql = "SELECT t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.accountancy_code_sell, t.accountancy_code_buy";
|
||||
@@ -3301,30 +3340,6 @@ function getLocalTaxesFromRate($vatrate, $local, $buyer, $seller)
|
||||
return array($obj->localtax1_type, $obj->localtax1, $obj->localtax2_type, $obj->localtax2,$obj->accountancy_code_sell,$obj->accountancy_code_buy);
|
||||
}
|
||||
}
|
||||
|
||||
if(! isOnlyOneLocalTax(2))
|
||||
{
|
||||
if(! isOnlyOneLocalTax(1))
|
||||
{
|
||||
return array($obj->localtax2_type, get_localtax($vatrate, 1, $buyer, $seller), $obj->localtax2_type, get_localtax($vatrate, 2, $buyer, $seller),$obj->accountancy_code_sell,$obj->accountancy_code_buy);
|
||||
}
|
||||
else
|
||||
{
|
||||
return array($obj->localtax2_type, get_localtax($vatrate, 1, $buyer, $seller), $obj->localtax2_type, $obj->localtax2,$obj->accountancy_code_sell,$obj->accountancy_code_buy);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(! isOnlyOneLocalTax(1))
|
||||
{
|
||||
return array($obj->localtax2_type, $obj->localtax2, $obj->localtax1_type,get_localtax($vatrate, 1, $buyer, $seller) ,$obj->accountancy_code_sell,$obj->accountancy_code_buy);
|
||||
}
|
||||
else
|
||||
{
|
||||
return array($obj->localtax2_type, $obj->localtax2, $obj->localtax1_type, $obj->localtax1,$obj->accountancy_code_sell,$obj->accountancy_code_buy);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3836,8 +3851,8 @@ function dol_nl2br($stringtoencode,$nl2brmode=0,$forxml=false)
|
||||
|
||||
/**
|
||||
* This function is called to encode a string into a HTML string but differs from htmlentities because
|
||||
* all entities but &,<,> are converted. This permits to encode special chars to entities with no double
|
||||
* encoding for already encoded HTML strings.
|
||||
* a detection is done before to see if text is already HTML or not. Also, all entities but &,<,> are converted.
|
||||
* This permits to encode special chars to entities with no double encoding for already encoded HTML strings.
|
||||
* This function also remove last EOL or BR if $removelasteolbr=1 (default).
|
||||
* For PDF usage, you can show text by 2 ways:
|
||||
* - writeHTMLCell -> param must be encoded into HTML.
|
||||
@@ -3854,7 +3869,7 @@ function dol_nl2br($stringtoencode,$nl2brmode=0,$forxml=false)
|
||||
function dol_htmlentitiesbr($stringtoencode,$nl2brmode=0,$pagecodefrom='UTF-8',$removelasteolbr=1)
|
||||
{
|
||||
$newstring=$stringtoencode;
|
||||
if (dol_textishtml($stringtoencode))
|
||||
if (dol_textishtml($stringtoencode)) // Check if text is already HTML or not
|
||||
{
|
||||
$newstring=preg_replace('/<br(\s[\sa-zA-Z_="]*)?\/?>/i','<br>',$newstring); // Replace "<br type="_moz" />" by "<br>". It's same and avoid pb with FPDF.
|
||||
if ($removelasteolbr) $newstring=preg_replace('/<br>$/i','',$newstring); // Remove last <br> (remove only last one)
|
||||
@@ -3915,8 +3930,8 @@ function dol_html_entity_decode($a,$b,$c='UTF-8')
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace htmlentities functions to manage errors
|
||||
* http://php.net/manual/en/function.htmlentities.php
|
||||
* Replace htmlentities functions to manage errors http://php.net/manual/en/function.htmlentities.php
|
||||
* Goal of this function is to be sure to have default values of htmlentities that match what we need.
|
||||
*
|
||||
* @param string $string The input string.
|
||||
* @param int $flags Flags(see PHP doc above)
|
||||
@@ -4063,7 +4078,7 @@ function dol_textishtml($msg,$option=0)
|
||||
*
|
||||
* @param string $text1 Text 1
|
||||
* @param string $text2 Text 2
|
||||
* @param string $forxml false=Use <br>, true=Use <br />
|
||||
* @param bool $forxml false=Use <br>, true=Use <br />
|
||||
* @return string Text 1 + new line + Text2
|
||||
* @see dol_textishtml
|
||||
*/
|
||||
@@ -4105,7 +4120,7 @@ function make_substitutions($chaine,$substitutionarray)
|
||||
*
|
||||
* @param array $substitutionarray Array substitution old value => new value value
|
||||
* @param Translate $outputlangs If we want substitution from special constants, we provide a language
|
||||
* @param Object $object If we want substitution from special constants, we provide data in a source object
|
||||
* @param object $object If we want substitution from special constants, we provide data in a source object
|
||||
* @param Mixed $parameters Add more parameters (useful to pass product lines)
|
||||
* @param string $callfunc What is the name of the custom function that will be called? (default: completesubstitutionarray)
|
||||
* @return void
|
||||
@@ -4148,8 +4163,8 @@ function complete_substitutions_array(&$substitutionarray,$outputlangs,$object='
|
||||
/**
|
||||
* Format output for start and end date
|
||||
*
|
||||
* @param timestamp $date_start Start date
|
||||
* @param timestamp $date_end End date
|
||||
* @param int $date_start Start date
|
||||
* @param int $date_end End date
|
||||
* @param string $format Output format
|
||||
* @param Translate $outputlangs Output language
|
||||
* @return void
|
||||
@@ -4162,8 +4177,8 @@ function print_date_range($date_start,$date_end,$format = '',$outputlangs='')
|
||||
/**
|
||||
* Format output for start and end date
|
||||
*
|
||||
* @param timestamp $date_start Start date
|
||||
* @param timestamp $date_end End date
|
||||
* @param int $date_start Start date
|
||||
* @param int $date_end End date
|
||||
* @param string $format Output format
|
||||
* @param Translate $outputlangs Output language
|
||||
* @param string $withparenthesis 1=Add parenthesis, 0=non parenthesis
|
||||
@@ -4708,6 +4723,7 @@ function picto_from_langcode($codelang)
|
||||
* 'member' to add a tab in fundation member view
|
||||
* 'categories_x' to add a tab in category view ('x': type of category (0=product, 1=supplier, 2=customer, 3=member)
|
||||
* 'ecm' to add a tab for another ecm view
|
||||
* 'stock' to add a tab for warehouse view
|
||||
* @param string $mode 'add' to complete head, 'remove' to remove entries
|
||||
* @return void
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user