diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index b87c8a55ce1..8b54369d2ac 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -33,7 +33,7 @@
if (! function_exists('json_encode'))
{
- include_once(DOL_DOCUMENT_ROOT ."/core/lib/json.lib.php");
+ include_once(DOL_DOCUMENT_ROOT ."/core/lib/json.lib.php");
}
/**
@@ -77,11 +77,11 @@ function getStaticMember($class, $member)
*/
function getDoliDBInstance($type, $host, $user, $pass, $name, $port)
{
- require_once(DOL_DOCUMENT_ROOT ."/core/db/".$type.".class.php");
+ require_once(DOL_DOCUMENT_ROOT ."/core/db/".$type.".class.php");
- $class='DoliDB'.ucfirst($type);
- $dolidb=new $class($type, $host, $user, $pass, $name, $port);
- return $dolidb;
+ $class='DoliDB'.ucfirst($type);
+ $dolidb=new $class($type, $host, $user, $pass, $name, $port);
+ return $dolidb;
}
/**
@@ -119,34 +119,34 @@ function getEntity($element=false, $shared=false)
*/
function getBrowserInfo()
{
- $name='unknown'; $version=''; $os='unknown'; $phone='';
+ $name='unknown'; $version=''; $os='unknown'; $phone='';
- // 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
- 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)([\d\.]*)/i', $_SERVER["HTTP_USER_AGENT"], $reg)) { $name='ie'; $version=$reg[2]; } // MS products at end
- // Other
- $firefox=0;
- if (in_array($name,array('firefox','iceweasel'))) $firefox=1;
+ // 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
+ 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)([\d\.]*)/i', $_SERVER["HTTP_USER_AGENT"], $reg)) { $name='ie'; $version=$reg[2]; } // MS products at end
+ // Other
+ $firefox=0;
+ if (in_array($name,array('firefox','iceweasel'))) $firefox=1;
- return array('browsername'=>$name, 'browserversion'=>$version, 'browseros'=>$os, 'phone'=>$phone, 'browserfirefox'=>$firefox);
+ return array('browsername'=>$name, 'browserversion'=>$version, 'browseros'=>$os, 'phone'=>$phone, 'browserfirefox'=>$firefox);
}
/**
@@ -156,10 +156,10 @@ function getBrowserInfo()
*/
function dol_shutdown()
{
- global $conf,$user,$langs,$db;
- $disconnectdone=false; $depth=0;
- if (is_object($db) && ! empty($db->connected)) { $depth=$db->transaction_opened; $disconnectdone=$db->close(); }
- dol_syslog("--- End access to ".$_SERVER["PHP_SELF"].($disconnectdone?' (Warn: db disconnection forced, transaction depth was '.$depth.')':''), ($disconnectdone?LOG_WARNING:LOG_DEBUG));
+ global $conf,$user,$langs,$db;
+ $disconnectdone=false; $depth=0;
+ if (is_object($db) && ! empty($db->connected)) { $depth=$db->transaction_opened; $disconnectdone=$db->close(); }
+ dol_syslog("--- End access to ".$_SERVER["PHP_SELF"].($disconnectdone?' (Warn: db disconnection forced, transaction depth was '.$depth.')':''), ($disconnectdone?LOG_WARNING:LOG_DEBUG));
}
@@ -177,7 +177,7 @@ function GETPOST($paramname,$check='',$method=0)
elseif ($method==1) $out = isset($_GET[$paramname])?$_GET[$paramname]:'';
elseif ($method==2) $out = isset($_POST[$paramname])?$_POST[$paramname]:'';
elseif ($method==3) $out = isset($_POST[$paramname])?$_POST[$paramname]:(isset($_GET[$paramname])?$_GET[$paramname]:'');
- else return 'BadParameter';
+ else return 'BadParameter';
if (! empty($check))
{
@@ -191,9 +191,9 @@ function GETPOST($paramname,$check='',$method=0)
elseif ($check == 'alpha')
{
$out=trim($out);
- // '"' is dangerous because param in url can close the href= or src= and add javascript functions.
- // '../' is dangerous because it allows dir transversals
- if (preg_match('/"/',$out)) $out='';
+ // '"' is dangerous because param in url can close the href= or src= and add javascript functions.
+ // '../' is dangerous because it allows dir transversals
+ if (preg_match('/"/',$out)) $out='';
else if (preg_match('/\.\.\//',$out)) $out='';
}
elseif ($check == 'array')
@@ -215,7 +215,7 @@ function GETPOST($paramname,$check='',$method=0)
*/
function dol_getprefix()
{
- return dol_hash($_SERVER["SERVER_NAME"].$_SERVER["DOCUMENT_ROOT"].DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
+ return dol_hash($_SERVER["SERVER_NAME"].$_SERVER["DOCUMENT_ROOT"].DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
}
/**
@@ -231,12 +231,12 @@ function dol_getprefix()
*/
function dol_include_once($relpath, $classname='')
{
- global $conf,$langs,$user,$mysoc; // Other global var must be retreived with $GLOBALS['var']
- if (! empty($classname) && ! class_exists($classname)) {
- return @include dol_buildpath($relpath);
- } else {
- return @include_once dol_buildpath($relpath);
- }
+ global $conf,$langs,$user,$mysoc; // Other global var must be retreived with $GLOBALS['var']
+ if (! empty($classname) && ! class_exists($classname)) {
+ return @include dol_buildpath($relpath);
+ } else {
+ return @include_once dol_buildpath($relpath);
+ }
}
@@ -249,47 +249,47 @@ function dol_include_once($relpath, $classname='')
*/
function dol_buildpath($path, $type=0)
{
- if (empty($type)) // For a filesystem path
- {
- $res = DOL_DOCUMENT_ROOT.$path; // Standard value
- if (defined('DOL_DOCUMENT_ROOT_ALT') && DOL_DOCUMENT_ROOT_ALT) // We check only if alternate feature is used
- {
- if (! file_exists(DOL_DOCUMENT_ROOT.$path)) $res = DOL_DOCUMENT_ROOT_ALT.$path;
- }
- }
- else // For an url path
- {
- // We try to get local path of file on filesystem from url
- // Note that trying to know if a file on disk exist by forging path on disk from url
- // works only for some web server and some setup. This is bugged when
- // using proxy, rewriting, virtual path, etc...
- if ($type == 1)
- {
- $res = DOL_URL_ROOT.$path; // Standard value
- if (defined('DOL_URL_ROOT_ALT') && DOL_URL_ROOT_ALT) // We check only if alternate feature is used
- {
- preg_match('/^([^\?]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i',$path,$regs); // Take part before '?'
- if (! empty($regs[1]))
- {
- if (! file_exists(DOL_DOCUMENT_ROOT.$regs[1])) $res = DOL_URL_ROOT_ALT.$path;
- }
- }
- }
- else if ($type == 2)
- {
- $res = DOL_MAIN_URL_ROOT.$path; // Standard value
- if (defined('DOL_URL_ROOT_ALT') && DOL_URL_ROOT_ALT) // We check only if alternate feature is used
- {
- preg_match('/^([^\?]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i',$path,$regs); // Take part before '?'
- if (! empty($regs[1]))
- {
- if (! file_exists(DOL_DOCUMENT_ROOT.$regs[1])) $res = DOL_MAIN_URL_ROOT_ALT.$path;
- }
- }
- }
- }
+ if (empty($type)) // For a filesystem path
+ {
+ $res = DOL_DOCUMENT_ROOT.$path; // Standard value
+ if (defined('DOL_DOCUMENT_ROOT_ALT') && DOL_DOCUMENT_ROOT_ALT) // We check only if alternate feature is used
+ {
+ if (! file_exists(DOL_DOCUMENT_ROOT.$path)) $res = DOL_DOCUMENT_ROOT_ALT.$path;
+ }
+ }
+ else // For an url path
+ {
+ // We try to get local path of file on filesystem from url
+ // Note that trying to know if a file on disk exist by forging path on disk from url
+ // works only for some web server and some setup. This is bugged when
+ // using proxy, rewriting, virtual path, etc...
+ if ($type == 1)
+ {
+ $res = DOL_URL_ROOT.$path; // Standard value
+ if (defined('DOL_URL_ROOT_ALT') && DOL_URL_ROOT_ALT) // We check only if alternate feature is used
+ {
+ preg_match('/^([^\?]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i',$path,$regs); // Take part before '?'
+ if (! empty($regs[1]))
+ {
+ if (! file_exists(DOL_DOCUMENT_ROOT.$regs[1])) $res = DOL_URL_ROOT_ALT.$path;
+ }
+ }
+ }
+ else if ($type == 2)
+ {
+ $res = DOL_MAIN_URL_ROOT.$path; // Standard value
+ if (defined('DOL_URL_ROOT_ALT') && DOL_URL_ROOT_ALT) // We check only if alternate feature is used
+ {
+ preg_match('/^([^\?]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i',$path,$regs); // Take part before '?'
+ if (! empty($regs[1]))
+ {
+ if (! file_exists(DOL_DOCUMENT_ROOT.$regs[1])) $res = DOL_MAIN_URL_ROOT_ALT.$path;
+ }
+ }
+ }
+ }
- return $res;
+ return $res;
}
/**
@@ -301,15 +301,15 @@ function dol_buildpath($path, $type=0)
*/
function dol_clone($object)
{
- dol_syslog("Functions.lib::dol_clone Clone object");
+ dol_syslog("Functions.lib::dol_clone Clone object");
- // We create dynamically a clone function, making a =
- if (version_compare(phpversion(), '5.0') < 0 && ! function_exists('clone'))
- {
- eval('function clone($object){return($object);}');
- }
- $myclone=clone($object);
- return $myclone;
+ // We create dynamically a clone function, making a =
+ if (version_compare(phpversion(), '5.0') < 0 && ! function_exists('clone'))
+ {
+ eval('function clone($object){return($object);}');
+ }
+ $myclone=clone($object);
+ return $myclone;
}
/**
@@ -323,10 +323,10 @@ function dol_clone($object)
*/
function dol_size($size,$type='')
{
- global $conf;
- if (empty($conf->browser->phone)) return $size;
- if ($type == 'width' && $size > 250) return 250;
- else return 10;
+ global $conf;
+ if (empty($conf->browser->phone)) return $size;
+ if ($type == 'width' && $size > 250) return 250;
+ else return 10;
}
@@ -343,7 +343,7 @@ function dol_size($size,$type='')
function dol_sanitizeFileName($str,$newstr='_',$unaccent=1)
{
$filesystem_forbidden_chars = array('<','>',':','/','\\','?','*','|','"');
- return dol_string_nospecial($unaccent?dol_string_unaccent($str):$str, $newstr, $filesystem_forbidden_chars);
+ return dol_string_nospecial($unaccent?dol_string_unaccent($str):$str, $newstr, $filesystem_forbidden_chars);
}
/**
@@ -356,10 +356,10 @@ function dol_sanitizeFileName($str,$newstr='_',$unaccent=1)
*/
function dol_string_unaccent($str)
{
- if (utf8_check($str))
- {
- $string = rawurlencode($str);
- $replacements = array(
+ if (utf8_check($str))
+ {
+ $string = rawurlencode($str);
+ $replacements = array(
'%C3%80' => 'A','%C3%81' => 'A',
'%C3%88' => 'E','%C3%89' => 'E',
'%C3%8C' => 'I','%C3%8D' => 'I',
@@ -373,27 +373,27 @@ function dol_string_unaccent($str)
);
$string=strtr($string, $replacements);
return rawurldecode($string);
- }
- else
- {
- $string = strtr(
- $str,
- "\xC0\xC1\xC2\xC3\xC5\xC7
- \xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1
- \xD2\xD3\xD4\xD5\xD8\xD9\xDA\xDB\xDD
- \xE0\xE1\xE2\xE3\xE5\xE7\xE8\xE9\xEA\xEB
- \xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF8
- \xF9\xFA\xFB\xFD\xFF",
- "AAAAAC
- EEEEIIIIDN
- OOOOOUUUY
- aaaaaceeee
- iiiidnooooo
- uuuyy"
- );
- $string = strtr($string, array("\xC4"=>"Ae", "\xC6"=>"AE", "\xD6"=>"Oe", "\xDC"=>"Ue", "\xDE"=>"TH", "\xDF"=>"ss", "\xE4"=>"ae", "\xE6"=>"ae", "\xF6"=>"oe", "\xFC"=>"ue", "\xFE"=>"th"));
- return $string;
- }
+ }
+ else
+ {
+ $string = strtr(
+ $str,
+ "\xC0\xC1\xC2\xC3\xC5\xC7
+ \xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1
+ \xD2\xD3\xD4\xD5\xD8\xD9\xDA\xDB\xDD
+ \xE0\xE1\xE2\xE3\xE5\xE7\xE8\xE9\xEA\xEB
+ \xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF8
+ \xF9\xFA\xFB\xFD\xFF",
+ "AAAAAC
+ EEEEIIIIDN
+ OOOOOUUUY
+ aaaaaceeee
+ iiiidnooooo
+ uuuyy"
+ );
+ $string = strtr($string, array("\xC4"=>"Ae", "\xC6"=>"AE", "\xD6"=>"Oe", "\xDC"=>"Ue", "\xDE"=>"TH", "\xDF"=>"ss", "\xE4"=>"ae", "\xE6"=>"ae", "\xF6"=>"oe", "\xFC"=>"ue", "\xFE"=>"th"));
+ return $string;
+ }
}
/**
@@ -408,12 +408,12 @@ function dol_string_unaccent($str)
*/
function dol_string_nospecial($str,$newstr='_',$badchars='')
{
- $forbidden_chars_to_replace=array(" ","'","/","\\",":","*","?","\"","<",">","|","[","]",",",";","=");
- $forbidden_chars_to_remove=array();
- if (is_array($badchars)) $forbidden_chars_to_replace=$badchars;
- //$forbidden_chars_to_remove=array("(",")");
+ $forbidden_chars_to_replace=array(" ","'","/","\\",":","*","?","\"","<",">","|","[","]",",",";","=");
+ $forbidden_chars_to_remove=array();
+ if (is_array($badchars)) $forbidden_chars_to_replace=$badchars;
+ //$forbidden_chars_to_remove=array("(",")");
- return str_replace($forbidden_chars_to_replace,$newstr,str_replace($forbidden_chars_to_remove,"",$str));
+ return str_replace($forbidden_chars_to_replace,$newstr,str_replace($forbidden_chars_to_remove,"",$str));
}
/**
@@ -424,9 +424,9 @@ function dol_string_nospecial($str,$newstr='_',$badchars='')
*/
function dol_escape_js($stringtoescape)
{
- // escape quotes and backslashes, newlines, etc.
- $substitjs=array("'"=>"\\'",'\\'=>'\\\\',"'"=>"\\'",'"'=>"\\'","\r"=>'\\r',"\n"=>'\\n',''=>'<\/');
- return strtr($stringtoescape, $substitjs);
+ // escape quotes and backslashes, newlines, etc.
+ $substitjs=array("'"=>"\\'",'\\'=>'\\\\',"'"=>"\\'",'"'=>"\\'","\r"=>'\\r',"\n"=>'\\n',''=>'<\/');
+ return strtr($stringtoescape, $substitjs);
}
@@ -439,11 +439,11 @@ function dol_escape_js($stringtoescape)
*/
function dol_escape_htmltag($stringtoescape,$keepb=0)
{
- // escape quotes and backslashes, newlines, etc.
- $tmp=dol_html_entity_decode($stringtoescape,ENT_COMPAT,'UTF-8');
- if ($keepb) $tmp=strtr($tmp, array("\r"=>'\\r',"\n"=>'\\n'));
- else $tmp=strtr($tmp, array("\r"=>'\\r',"\n"=>'\\n',""=>'',''=>''));
- return dol_htmlentities($tmp,ENT_COMPAT,'UTF-8');
+ // escape quotes and backslashes, newlines, etc.
+ $tmp=dol_html_entity_decode($stringtoescape,ENT_COMPAT,'UTF-8');
+ if ($keepb) $tmp=strtr($tmp, array("\r"=>'\\r',"\n"=>'\\n'));
+ else $tmp=strtr($tmp, array("\r"=>'\\r',"\n"=>'\\n',""=>'',''=>''));
+ return dol_htmlentities($tmp,ENT_COMPAT,'UTF-8');
}
/**
@@ -465,124 +465,124 @@ function dol_escape_htmltag($stringtoescape,$keepb=0)
*/
function dol_syslog($message, $level=LOG_INFO)
{
- global $conf,$user,$langs,$_REQUEST;
+ global $conf,$user,$langs,$_REQUEST;
- // If adding log inside HTML page is required
- if (! empty($_REQUEST['logtohtml']) && ! empty($conf->global->MAIN_LOGTOHTML))
- {
- $conf->logbuffer[]=dol_print_date(time(),"%Y-%m-%d %H:%M:%S")." ".$message;
- }
+ // If adding log inside HTML page is required
+ if (! empty($_REQUEST['logtohtml']) && ! empty($conf->global->MAIN_LOGTOHTML))
+ {
+ $conf->logbuffer[]=dol_print_date(time(),"%Y-%m-%d %H:%M:%S")." ".$message;
+ }
- // If syslog module enabled
- if (! empty($conf->syslog->enabled))
- {
- //print $level.' - '.$conf->global->SYSLOG_LEVEL.' - '.$conf->syslog->enabled." \n";
- if ($level > $conf->global->SYSLOG_LEVEL) return;
+ // If syslog module enabled
+ if (! empty($conf->syslog->enabled))
+ {
+ //print $level.' - '.$conf->global->SYSLOG_LEVEL.' - '.$conf->syslog->enabled." \n";
+ if ($level > $conf->global->SYSLOG_LEVEL) return;
- // Translate error message if this is an error message (rare) and langs is loaded
- if ($level == LOG_ERR)
- {
- if (is_object($langs))
- {
- $langs->load("errors");
- if ($message != $langs->trans($message)) $message = $langs->trans($message);
- }
- }
+ // Translate error message if this is an error message (rare) and langs is loaded
+ if ($level == LOG_ERR)
+ {
+ if (is_object($langs))
+ {
+ $langs->load("errors");
+ if ($message != $langs->trans($message)) $message = $langs->trans($message);
+ }
+ }
- // Add page/script name to log message
- $script=isset($_SERVER['PHP_SELF'])?basename($_SERVER['PHP_SELF'],'.php').' ':'';
- $message=$script.$message;
+ // Add page/script name to log message
+ $script=isset($_SERVER['PHP_SELF'])?basename($_SERVER['PHP_SELF'],'.php').' ':'';
+ $message=$script.$message;
- // Add user to log message
- $login='nologin';
- if (is_object($user) && $user->id) $login=$user->login;
- $message=sprintf("%-8s",$login)." ".$message;
+ // Add user to log message
+ $login='nologin';
+ if (is_object($user) && $user->id) $login=$user->login;
+ $message=sprintf("%-8s",$login)." ".$message;
- // Check if log is to a file (SYSLOG_FILE_ON defined)
- if (defined("SYSLOG_FILE_ON") && constant("SYSLOG_FILE_ON"))
- {
- $filelog=SYSLOG_FILE;
- $filelog=preg_replace('/DOL_DATA_ROOT/i',DOL_DATA_ROOT,$filelog);
- //print "filelog=".$filelog."\n";
- if (defined("SYSLOG_FILE_NO_ERROR")) $file=@fopen($filelog,"a+");
- else $file=fopen($filelog,"a+");
+ // Check if log is to a file (SYSLOG_FILE_ON defined)
+ if (defined("SYSLOG_FILE_ON") && constant("SYSLOG_FILE_ON"))
+ {
+ $filelog=SYSLOG_FILE;
+ $filelog=preg_replace('/DOL_DATA_ROOT/i',DOL_DATA_ROOT,$filelog);
+ //print "filelog=".$filelog."\n";
+ if (defined("SYSLOG_FILE_NO_ERROR")) $file=@fopen($filelog,"a+");
+ else $file=fopen($filelog,"a+");
- if ($file)
- {
- $ip='???'; // $ip contains information to identify computer that run the code
- if (! empty($_SERVER["REMOTE_ADDR"])) $ip=$_SERVER["REMOTE_ADDR"]; // In most cases.
- else if (! empty($_SERVER['SERVER_ADDR'])) $ip=$_SERVER['SERVER_ADDR']; // This is when PHP session is ran inside a web server but not inside a client request (example: init code of apache)
- else if (! empty($_SERVER['COMPUTERNAME'])) $ip=$_SERVER['COMPUTERNAME'].(empty($_SERVER['USERNAME'])?'':'@'.$_SERVER['USERNAME']); // This is when PHP session is ran outside a web server, like from Windows command line (Not always defined, but usefull if OS defined it).
- else if (! empty($_SERVER['LOGNAME'])) $ip='???@'.$_SERVER['LOGNAME']; // This is when PHP session is ran outside a web server, like from Linux command line (Not always defined, but usefull if OS defined it).
+ if ($file)
+ {
+ $ip='???'; // $ip contains information to identify computer that run the code
+ if (! empty($_SERVER["REMOTE_ADDR"])) $ip=$_SERVER["REMOTE_ADDR"]; // In most cases.
+ else if (! empty($_SERVER['SERVER_ADDR'])) $ip=$_SERVER['SERVER_ADDR']; // This is when PHP session is ran inside a web server but not inside a client request (example: init code of apache)
+ else if (! empty($_SERVER['COMPUTERNAME'])) $ip=$_SERVER['COMPUTERNAME'].(empty($_SERVER['USERNAME'])?'':'@'.$_SERVER['USERNAME']); // This is when PHP session is ran outside a web server, like from Windows command line (Not always defined, but usefull if OS defined it).
+ else if (! empty($_SERVER['LOGNAME'])) $ip='???@'.$_SERVER['LOGNAME']; // This is when PHP session is ran outside a web server, like from Linux command line (Not always defined, but usefull if OS defined it).
- $liblevelarray=array(LOG_ERR=>'ERROR',LOG_WARNING=>'WARN',LOG_INFO=>'INFO',LOG_DEBUG=>'DEBUG');
- $liblevel=$liblevelarray[$level];
- if (! $liblevel) $liblevel='UNDEF';
+ $liblevelarray=array(LOG_ERR=>'ERROR',LOG_WARNING=>'WARN',LOG_INFO=>'INFO',LOG_DEBUG=>'DEBUG');
+ $liblevel=$liblevelarray[$level];
+ if (! $liblevel) $liblevel='UNDEF';
- $message=dol_print_date(time(),"%Y-%m-%d %H:%M:%S")." ".sprintf("%-5s",$liblevel)." ".sprintf("%-15s",$ip)." ".$message;
+ $message=dol_print_date(time(),"%Y-%m-%d %H:%M:%S")." ".sprintf("%-5s",$liblevel)." ".sprintf("%-15s",$ip)." ".$message;
- fwrite($file,$message."\n");
- fclose($file);
- // This is for log file, we do not change permissions
+ fwrite($file,$message."\n");
+ fclose($file);
+ // This is for log file, we do not change permissions
- // 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"]))
- {
- print "\n\n\n";
- }
- }
- elseif (! defined("SYSLOG_FILE_NO_ERROR"))
- {
- // Do not use here a call to functions that make call to dol_syslog so making call to langs. A simple print is enough.
- print "Error, failed to open file ".$filelog."\n";
- }
- }
+ // 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"]))
+ {
+ print "\n\n\n";
+ }
+ }
+ elseif (! defined("SYSLOG_FILE_NO_ERROR"))
+ {
+ // Do not use here a call to functions that make call to dol_syslog so making call to langs. A simple print is enough.
+ print "Error, failed to open file ".$filelog."\n";
+ }
+ }
- // Check if log is to syslog (SYSLOG_SYSLOG_ON defined)
- if (defined("SYSLOG_SYSLOG_ON") && constant("SYSLOG_SYSLOG_ON"))
- {
- if (function_exists('openlog')) // This function does not exists on some ISP (Ex: Free in France)
- {
- $facility = LOG_USER;
- if (defined("SYSLOG_FACILITY") && constant("SYSLOG_FACILITY"))
- {
- // Exemple: SYSLOG_FACILITY vaut LOG_USER qui vaut 8. On a besoin de 8 dans $facility.
- $facility = constant("SYSLOG_FACILITY");
- }
+ // Check if log is to syslog (SYSLOG_SYSLOG_ON defined)
+ if (defined("SYSLOG_SYSLOG_ON") && constant("SYSLOG_SYSLOG_ON"))
+ {
+ if (function_exists('openlog')) // This function does not exists on some ISP (Ex: Free in France)
+ {
+ $facility = LOG_USER;
+ if (defined("SYSLOG_FACILITY") && constant("SYSLOG_FACILITY"))
+ {
+ // Exemple: SYSLOG_FACILITY vaut LOG_USER qui vaut 8. On a besoin de 8 dans $facility.
+ $facility = constant("SYSLOG_FACILITY");
+ }
- openlog("dolibarr", LOG_PID | LOG_PERROR, (int) $facility); // (int) is required to avoid error parameter 3 expected to be long
- if (! $level) syslog(LOG_ERR, $message);
- else syslog($level, $message);
- closelog();
- }
- }
+ openlog("dolibarr", LOG_PID | LOG_PERROR, (int) $facility); // (int) is required to avoid error parameter 3 expected to be long
+ if (! $level) syslog(LOG_ERR, $message);
+ else syslog($level, $message);
+ closelog();
+ }
+ }
- // Check if log is to syslog (SYSLOG_FIREPHP_ON defined)
- if (defined("SYSLOG_FIREPHP_ON") && constant("SYSLOG_FIREPHP_ON") && ! empty($_SERVER["SERVER_NAME"])) //! empty($_SERVER["SERVER_NAME"]) to be sure to enable this in Web mode only
- {
- try
- {
- // Warning FirePHPCore must be into PHP include path. It is not possible to use into require_once() a constant from
- // database or config file because we must be able to log data before database or config file read.
- $oldinclude=get_include_path();
- set_include_path('/usr/share/php/');
- include_once('FirePHPCore/FirePHP.class.php');
- set_include_path($oldinclude);
- ob_start();
- $firephp = FirePHP::getInstance(true);
- if ($level == LOG_ERR) $firephp->error($message);
- elseif ($level == LOG_WARNING) $firephp->warn($message);
- elseif ($level == LOG_INFO) $firephp->log($message);
- else $firephp->log($message);
- }
- catch(Exception $e)
- {
- // Do not use dol_syslog to avoid infinite loop
- }
- }
- }
+ // Check if log is to syslog (SYSLOG_FIREPHP_ON defined)
+ if (defined("SYSLOG_FIREPHP_ON") && constant("SYSLOG_FIREPHP_ON") && ! empty($_SERVER["SERVER_NAME"])) //! empty($_SERVER["SERVER_NAME"]) to be sure to enable this in Web mode only
+ {
+ try
+ {
+ // Warning FirePHPCore must be into PHP include path. It is not possible to use into require_once() a constant from
+ // database or config file because we must be able to log data before database or config file read.
+ $oldinclude=get_include_path();
+ set_include_path('/usr/share/php/');
+ include_once('FirePHPCore/FirePHP.class.php');
+ set_include_path($oldinclude);
+ ob_start();
+ $firephp = FirePHP::getInstance(true);
+ if ($level == LOG_ERR) $firephp->error($message);
+ elseif ($level == LOG_WARNING) $firephp->warn($message);
+ elseif ($level == LOG_INFO) $firephp->log($message);
+ else $firephp->log($message);
+ }
+ catch(Exception $e)
+ {
+ // Do not use dol_syslog to avoid infinite loop
+ }
+ }
+ }
}
@@ -598,7 +598,7 @@ function dol_syslog($message, $level=LOG_INFO)
*/
function dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='')
{
- print dol_get_fiche_head($links, $active, $title, $notab, $picto);
+ print dol_get_fiche_head($links, $active, $title, $notab, $picto);
}
/**
@@ -613,60 +613,60 @@ function dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto
*/
function dol_get_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='')
{
- $out="\n".'
'."\n";
+ $out="\n".'
'."\n";
- // Affichage titre
- if ($title)
- {
- $limittitle=30;
- $out.='
';
- if ($picto) $out.=img_object('',$picto).' ';
- $out.=dol_trunc($title,$limittitle);
- $out.='';
- }
+ // Affichage titre
+ if ($title)
+ {
+ $limittitle=30;
+ $out.='
';
+ if ($picto) $out.=img_object('',$picto).' ';
+ $out.=dol_trunc($title,$limittitle);
+ $out.='';
+ }
- // Define max of key (max may be higher than sizeof because of hole due to module disabling some tabs).
- $maxkey=-1;
- if (is_array($links))
- {
- $keys=array_keys($links);
- if (count($keys)) $maxkey=max($keys);
- }
+ // Define max of key (max may be higher than sizeof because of hole due to module disabling some tabs).
+ $maxkey=-1;
+ if (is_array($links))
+ {
+ $keys=array_keys($links);
+ if (count($keys)) $maxkey=max($keys);
+ }
- // Show tabs
- for ($i = 0 ; $i <= $maxkey ; $i++)
- {
- if (isset($links[$i][2]) && $links[$i][2] == 'image')
- {
- if (!empty($links[$i][0]))
- {
- $out.='
'.$links[$i][1].''."\n";
- }
- else
- {
- $out.='
'.$links[$i][1].''."\n";
- }
- }
- else if (! empty($links[$i][1]))
- {
- //print "x $i $active ".$links[$i][2]." z";
- if ((is_numeric($active) && $i == $active)
- || (! is_numeric($active) && $active == $links[$i][2]))
- {
- $out.='
'.$links[$i][1].''."\n";
- }
- else
- {
- $out.='
'.$links[$i][1].''."\n";
- }
- }
- }
+ // Show tabs
+ for ($i = 0 ; $i <= $maxkey ; $i++)
+ {
+ if (isset($links[$i][2]) && $links[$i][2] == 'image')
+ {
+ if (!empty($links[$i][0]))
+ {
+ $out.='
'.$links[$i][1].''."\n";
+ }
+ else
+ {
+ $out.='
'.$links[$i][1].''."\n";
+ }
+ }
+ else if (! empty($links[$i][1]))
+ {
+ //print "x $i $active ".$links[$i][2]." z";
+ if ((is_numeric($active) && $i == $active)
+ || (! is_numeric($active) && $active == $links[$i][2]))
+ {
+ $out.='
'.$links[$i][1].''."\n";
+ }
+ else
+ {
+ $out.='
'.$links[$i][1].''."\n";
+ }
+ }
+ }
- $out.="
\n";
+ $out.="
\n";
- if (! $notab) $out.="\n".''."\n";
+ if (! $notab) $out.="\n".'
'."\n";
- return $out;
+ return $out;
}
/**
@@ -677,7 +677,7 @@ function dol_get_fiche_head($links=array(), $active='0', $title='', $notab=0, $p
*/
function dol_fiche_end($notab=0)
{
- print dol_get_fiche_end($notab);
+ print dol_get_fiche_end($notab);
}
/**
@@ -688,8 +688,8 @@ function dol_fiche_end($notab=0)
*/
function dol_get_fiche_end($notab=0)
{
- if (! $notab) return "\n
\n";
- else return '';
+ if (! $notab) return "\n
\n";
+ else return '';
}
/**
@@ -750,131 +750,131 @@ function dol_format_address($object)
*/
function dol_print_date($time,$format='',$tzoutput='tzserver',$outputlangs='',$encodetooutput=false)
{
- global $conf,$langs;
+ global $conf,$langs;
- $to_gmt=false;
- $offsettz=$offsetdst=0;
- if ($tzoutput)
- {
- $to_gmt=true; // For backward compatibility
- if (is_string($tzoutput))
- {
- if ($tzoutput == 'tzserver')
- {
- $to_gmt=false;
- $offsettz=$offsetdst=0;
- }
- elseif ($tzoutput == 'tzuser')
- {
- $to_gmt=true;
- $offsettz=(empty($_SESSION['dol_tz'])?0:$_SESSION['dol_tz'])*60*60;
- $offsetdst=(empty($_SESSION['dol_dst'])?0:$_SESSION['dol_dst'])*60*60;
- }
- elseif ($tzoutput == 'tzcompany')
- {
- $to_gmt=false;
- $offsettz=$offsetdst=0; // TODO Define this and use it later
- }
- }
- }
+ $to_gmt=false;
+ $offsettz=$offsetdst=0;
+ if ($tzoutput)
+ {
+ $to_gmt=true; // For backward compatibility
+ if (is_string($tzoutput))
+ {
+ if ($tzoutput == 'tzserver')
+ {
+ $to_gmt=false;
+ $offsettz=$offsetdst=0;
+ }
+ elseif ($tzoutput == 'tzuser')
+ {
+ $to_gmt=true;
+ $offsettz=(empty($_SESSION['dol_tz'])?0:$_SESSION['dol_tz'])*60*60;
+ $offsetdst=(empty($_SESSION['dol_dst'])?0:$_SESSION['dol_dst'])*60*60;
+ }
+ elseif ($tzoutput == 'tzcompany')
+ {
+ $to_gmt=false;
+ $offsettz=$offsetdst=0; // TODO Define this and use it later
+ }
+ }
+ }
- if (! is_object($outputlangs)) $outputlangs=$langs;
+ if (! is_object($outputlangs)) $outputlangs=$langs;
- // Si format non defini, on prend $conf->format_date_text_short sinon %Y-%m-%d %H:%M:%S
- if (! $format) $format=(isset($conf->format_date_text_short) ? $conf->format_date_text_short : '%Y-%m-%d %H:%M:%S');
+ // Si format non defini, on prend $conf->format_date_text_short sinon %Y-%m-%d %H:%M:%S
+ if (! $format) $format=(isset($conf->format_date_text_short) ? $conf->format_date_text_short : '%Y-%m-%d %H:%M:%S');
- // Change predefined format into computer format. If found translation in lang file we use it, otherwise we use default.
- if ($format == 'day') $format=($outputlangs->trans("FormatDateShort")!="FormatDateShort"?$outputlangs->trans("FormatDateShort"):$conf->format_date_short);
- if ($format == 'hour') $format=($outputlangs->trans("FormatHourShort")!="FormatHourShort"?$outputlangs->trans("FormatHourShort"):$conf->format_hour_short);
- if ($format == 'hourduration') $format=($outputlangs->trans("FormatHourShortDuration")!="FormatHourShortDuration"?$outputlangs->trans("FormatHourShortDuration"):$conf->format_hour_short_duration);
- if ($format == 'daytext') $format=($outputlangs->trans("FormatDateText")!="FormatDateText"?$outputlangs->trans("FormatDateText"):$conf->format_date_text);
- if ($format == 'daytextshort') $format=($outputlangs->trans("FormatDateTextShort")!="FormatDateTextShort"?$outputlangs->trans("FormatDateTextShort"):$conf->format_date_text_short);
- if ($format == 'dayhour') $format=($outputlangs->trans("FormatDateHourShort")!="FormatDateHourShort"?$outputlangs->trans("FormatDateHourShort"):$conf->format_date_hour_short);
- if ($format == 'dayhourtext') $format=($outputlangs->trans("FormatDateHourText")!="FormatDateHourText"?$outputlangs->trans("FormatDateHourText"):$conf->format_date_hour_text);
- if ($format == 'dayhourtextshort') $format=($outputlangs->trans("FormatDateHourTextShort")!="FormatDateHourTextShort"?$outputlangs->trans("FormatDateHourTextShort"):$conf->format_date_hour_text_short);
+ // Change predefined format into computer format. If found translation in lang file we use it, otherwise we use default.
+ if ($format == 'day') $format=($outputlangs->trans("FormatDateShort")!="FormatDateShort"?$outputlangs->trans("FormatDateShort"):$conf->format_date_short);
+ if ($format == 'hour') $format=($outputlangs->trans("FormatHourShort")!="FormatHourShort"?$outputlangs->trans("FormatHourShort"):$conf->format_hour_short);
+ if ($format == 'hourduration') $format=($outputlangs->trans("FormatHourShortDuration")!="FormatHourShortDuration"?$outputlangs->trans("FormatHourShortDuration"):$conf->format_hour_short_duration);
+ if ($format == 'daytext') $format=($outputlangs->trans("FormatDateText")!="FormatDateText"?$outputlangs->trans("FormatDateText"):$conf->format_date_text);
+ if ($format == 'daytextshort') $format=($outputlangs->trans("FormatDateTextShort")!="FormatDateTextShort"?$outputlangs->trans("FormatDateTextShort"):$conf->format_date_text_short);
+ if ($format == 'dayhour') $format=($outputlangs->trans("FormatDateHourShort")!="FormatDateHourShort"?$outputlangs->trans("FormatDateHourShort"):$conf->format_date_hour_short);
+ if ($format == 'dayhourtext') $format=($outputlangs->trans("FormatDateHourText")!="FormatDateHourText"?$outputlangs->trans("FormatDateHourText"):$conf->format_date_hour_text);
+ if ($format == 'dayhourtextshort') $format=($outputlangs->trans("FormatDateHourTextShort")!="FormatDateHourTextShort"?$outputlangs->trans("FormatDateHourTextShort"):$conf->format_date_hour_text_short);
- // Format not sensitive to language
- if ($format == 'dayhourlog') $format='%Y%m%d%H%M%S';
- if ($format == 'dayhourldap') $format='%Y%m%d%H%M%SZ';
- if ($format == 'dayhourxcard') $format='%Y%m%dT%H%M%SZ';
- if ($format == 'dayxcard') $format='%Y%m%d';
- if ($format == 'dayrfc') $format='%Y-%m-%d'; // DATE_RFC3339
- if ($format == 'dayhourrfc') $format='%Y-%m-%dT%H:%M:%SZ'; // DATETIME RFC3339
+ // Format not sensitive to language
+ if ($format == 'dayhourlog') $format='%Y%m%d%H%M%S';
+ if ($format == 'dayhourldap') $format='%Y%m%d%H%M%SZ';
+ if ($format == 'dayhourxcard') $format='%Y%m%dT%H%M%SZ';
+ if ($format == 'dayxcard') $format='%Y%m%d';
+ if ($format == 'dayrfc') $format='%Y-%m-%d'; // DATE_RFC3339
+ if ($format == 'dayhourrfc') $format='%Y-%m-%dT%H:%M:%SZ'; // DATETIME RFC3339
- // If date undefined or "", we return ""
- if (dol_strlen($time) == 0) return ''; // $time=0 allowed (it means 01/01/1970 00:00:00)
+ // If date undefined or "", we return ""
+ if (dol_strlen($time) == 0) return ''; // $time=0 allowed (it means 01/01/1970 00:00:00)
- //print 'x'.$time;
+ //print 'x'.$time;
- if (preg_match('/%b/i',$format)) // There is some text to translate
- {
- // We inhibate translation to text made by strftime functions. We will use trans instead later.
- $format=str_replace('%b','__b__',$format);
- $format=str_replace('%B','__B__',$format);
- }
- if (preg_match('/%a/i',$format)) // There is some text to translate
- {
- // We inhibate translation to text made by strftime functions. We will use trans instead later.
- $format=str_replace('%a','__a__',$format);
- $format=str_replace('%A','__A__',$format);
- }
+ if (preg_match('/%b/i',$format)) // There is some text to translate
+ {
+ // We inhibate translation to text made by strftime functions. We will use trans instead later.
+ $format=str_replace('%b','__b__',$format);
+ $format=str_replace('%B','__B__',$format);
+ }
+ if (preg_match('/%a/i',$format)) // There is some text to translate
+ {
+ // We inhibate translation to text made by strftime functions. We will use trans instead later.
+ $format=str_replace('%a','__a__',$format);
+ $format=str_replace('%A','__A__',$format);
+ }
- // Analyze date (deprecated) Ex: 1970-01-01, 1970-01-01 01:00:00, 19700101010000
- if (preg_match('/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i',$time,$reg)
- || preg_match('/^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$/i',$time,$reg))
- {
- // This part of code should not be used.
- dol_syslog("Functions.lib::dol_print_date function call with deprecated value of time in page ".$_SERVER["PHP_SELF"], LOG_WARNING);
- // Date has format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS' or 'YYYYMMDDHHMMSS'
- $syear = (! empty($reg[1]) ? $reg[1] : '');
- $smonth = (! empty($reg[2]) ? $reg[2] : '');
- $sday = (! empty($reg[3]) ? $reg[3] : '');
- $shour = (! empty($reg[4]) ? $reg[4] : '');
- $smin = (! empty($reg[5]) ? $reg[5] : '');
- $ssec = (! empty($reg[6]) ? $reg[6] : '');
+ // Analyze date (deprecated) Ex: 1970-01-01, 1970-01-01 01:00:00, 19700101010000
+ if (preg_match('/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i',$time,$reg)
+ || preg_match('/^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$/i',$time,$reg))
+ {
+ // This part of code should not be used.
+ dol_syslog("Functions.lib::dol_print_date function call with deprecated value of time in page ".$_SERVER["PHP_SELF"], LOG_WARNING);
+ // Date has format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS' or 'YYYYMMDDHHMMSS'
+ $syear = (! empty($reg[1]) ? $reg[1] : '');
+ $smonth = (! empty($reg[2]) ? $reg[2] : '');
+ $sday = (! empty($reg[3]) ? $reg[3] : '');
+ $shour = (! empty($reg[4]) ? $reg[4] : '');
+ $smin = (! empty($reg[5]) ? $reg[5] : '');
+ $ssec = (! empty($reg[6]) ? $reg[6] : '');
- $time=dol_mktime($shour,$smin,$ssec,$smonth,$sday,$syear,true);
- $ret=adodb_strftime($format,$time+$offsettz+$offsetdst,$to_gmt);
- }
- else
- {
- // Date is a timestamps
- if ($time < 100000000000) // Protection against bad date values
- {
- $ret=adodb_strftime($format,$time+$offsettz+$offsetdst,$to_gmt);
- }
- else $ret='Bad value '.$time.' for date';
- }
+ $time=dol_mktime($shour,$smin,$ssec,$smonth,$sday,$syear,true);
+ $ret=adodb_strftime($format,$time+$offsettz+$offsetdst,$to_gmt);
+ }
+ else
+ {
+ // Date is a timestamps
+ if ($time < 100000000000) // Protection against bad date values
+ {
+ $ret=adodb_strftime($format,$time+$offsettz+$offsetdst,$to_gmt);
+ }
+ else $ret='Bad value '.$time.' for date';
+ }
- if (preg_match('/__b__/i',$format))
- {
- // Here ret is string in PHP setup language (strftime was used). Now we convert to $outputlangs.
- $month=adodb_strftime('%m',$time+$offsettz+$offsetdst);
- if ($encodetooutput)
- {
- $monthtext=$outputlangs->transnoentities('Month'.$month);
- $monthtextshort=$outputlangs->transnoentities('MonthShort'.$month);
- }
- else
- {
- $monthtext=$outputlangs->transnoentitiesnoconv('Month'.$month);
- $monthtextshort=$outputlangs->transnoentitiesnoconv('MonthShort'.$month);
- }
- //print 'monthtext='.$monthtext.' monthtextshort='.$monthtextshort;
- $ret=str_replace('__b__',$monthtextshort,$ret);
- $ret=str_replace('__B__',$monthtext,$ret);
- //print 'x'.$outputlangs->charset_output.'-'.$ret.'x';
- //return $ret;
- }
- if (preg_match('/__a__/i',$format))
- {
- $w=adodb_strftime('%w',$time+$offsettz+$offsetdst);
- $dayweek=$outputlangs->transnoentitiesnoconv('Day'.$w);
- $ret=str_replace('__A__',$dayweek,$ret);
- $ret=str_replace('__a__',dol_substr($dayweek,0,3),$ret);
- }
+ if (preg_match('/__b__/i',$format))
+ {
+ // Here ret is string in PHP setup language (strftime was used). Now we convert to $outputlangs.
+ $month=adodb_strftime('%m',$time+$offsettz+$offsetdst);
+ if ($encodetooutput)
+ {
+ $monthtext=$outputlangs->transnoentities('Month'.$month);
+ $monthtextshort=$outputlangs->transnoentities('MonthShort'.$month);
+ }
+ else
+ {
+ $monthtext=$outputlangs->transnoentitiesnoconv('Month'.$month);
+ $monthtextshort=$outputlangs->transnoentitiesnoconv('MonthShort'.$month);
+ }
+ //print 'monthtext='.$monthtext.' monthtextshort='.$monthtextshort;
+ $ret=str_replace('__b__',$monthtextshort,$ret);
+ $ret=str_replace('__B__',$monthtext,$ret);
+ //print 'x'.$outputlangs->charset_output.'-'.$ret.'x';
+ //return $ret;
+ }
+ if (preg_match('/__a__/i',$format))
+ {
+ $w=adodb_strftime('%w',$time+$offsettz+$offsetdst);
+ $dayweek=$outputlangs->transnoentitiesnoconv('Day'.$w);
+ $ret=str_replace('__A__',$dayweek,$ret);
+ $ret=str_replace('__a__',dol_substr($dayweek,0,3),$ret);
+ }
- return $ret;
+ return $ret;
}
@@ -912,20 +912,20 @@ function dol_print_date($time,$format='',$tzoutput='tzserver',$outputlangs='',$e
*/
function dol_getdate($timestamp,$fast=false)
{
- $usealternatemethod=false;
- if ($timestamp <= 0) $usealternatemethod=true; // <= 1970
- if ($timestamp >= 2145913200) $usealternatemethod=true; // >= 2038
+ $usealternatemethod=false;
+ if ($timestamp <= 0) $usealternatemethod=true; // <= 1970
+ if ($timestamp >= 2145913200) $usealternatemethod=true; // >= 2038
- if ($usealternatemethod)
- {
- $arrayinfo=adodb_getdate($timestamp,$fast);
- }
- else
- {
- $arrayinfo=getdate($timestamp);
- }
+ if ($usealternatemethod)
+ {
+ $arrayinfo=adodb_getdate($timestamp,$fast);
+ }
+ else
+ {
+ $arrayinfo=getdate($timestamp);
+ }
- return $arrayinfo;
+ return $arrayinfo;
}
/**
@@ -946,50 +946,50 @@ function dol_getdate($timestamp,$fast=false)
*/
function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1)
{
- global $conf;
- //print "- ".$hour.",".$minute.",".$second.",".$month.",".$day.",".$year.",".$_SERVER["WINDIR"]." -";
+ global $conf;
+ //print "- ".$hour.",".$minute.",".$second.",".$month.",".$day.",".$year.",".$_SERVER["WINDIR"]." -";
- // Clean parameters
- if ($hour == -1) $hour=0;
- if ($minute == -1) $minute=0;
- if ($second == -1) $second=0;
+ // Clean parameters
+ if ($hour == -1) $hour=0;
+ if ($minute == -1) $minute=0;
+ if ($second == -1) $second=0;
- // Check parameters
- if ($check)
- {
- if (! $month || ! $day) return '';
- if ($day > 31) return '';
- if ($month > 12) return '';
- if ($hour < 0 || $hour > 24) return '';
- if ($minute< 0 || $minute > 60) return '';
- if ($second< 0 || $second > 60) return '';
- }
+ // Check parameters
+ if ($check)
+ {
+ if (! $month || ! $day) return '';
+ if ($day > 31) return '';
+ if ($month > 12) return '';
+ if ($hour < 0 || $hour > 24) return '';
+ if ($minute< 0 || $minute > 60) return '';
+ if ($second< 0 || $second > 60) return '';
+ }
- if (method_exists('DateTime','getTimestamp') && empty($conf->global->MAIN_OLD_DATE))
- {
- if (empty($gm)) $localtz = new DateTimeZone(date_default_timezone_get());
- else $localtz = new DateTimeZone('UTC');
- $dt = new DateTime(null,$localtz);
- $dt->setDate($year,$month,$day);
- $dt->setTime((int) $hour, (int) $minute, (int) $second);
- $date=$dt->getTimestamp();
- }
- else
- {
- $usealternatemethod=false;
- if ($year <= 1970) $usealternatemethod=true; // <= 1970
- if ($year >= 2038) $usealternatemethod=true; // >= 2038
+ if (method_exists('DateTime','getTimestamp') && empty($conf->global->MAIN_OLD_DATE))
+ {
+ if (empty($gm)) $localtz = new DateTimeZone(date_default_timezone_get());
+ else $localtz = new DateTimeZone('UTC');
+ $dt = new DateTime(null,$localtz);
+ $dt->setDate($year,$month,$day);
+ $dt->setTime((int) $hour, (int) $minute, (int) $second);
+ $date=$dt->getTimestamp();
+ }
+ else
+ {
+ $usealternatemethod=false;
+ if ($year <= 1970) $usealternatemethod=true; // <= 1970
+ if ($year >= 2038) $usealternatemethod=true; // >= 2038
- if ($usealternatemethod || $gm) // Si time gm, seule adodb peut convertir
- {
- $date=adodb_mktime($hour,$minute,$second,$month,$day,$year,0,$gm);
- }
- else
- {
- $date=mktime($hour,$minute,$second,$month,$day,$year);
- }
- }
- return $date;
+ if ($usealternatemethod || $gm) // Si time gm, seule adodb peut convertir
+ {
+ $date=adodb_mktime($hour,$minute,$second,$month,$day,$year,0,$gm);
+ }
+ else
+ {
+ $date=mktime($hour,$minute,$second,$month,$day,$year);
+ }
+ }
+ return $date;
}
@@ -1004,29 +1004,29 @@ function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1)
*/
function dol_now($mode='gmt')
{
- // Note that gmmktime and mktime return same value (GMT) whithout parameters
+ // Note that gmmktime and mktime return same value (GMT) whithout parameters
//if ($mode == 'gmt') $ret=gmmktime(); // Strict Standards: gmmktime(): You should be using the time() function instead
- if ($mode == 'gmt') $ret=time(); // Time for now at greenwich.
- else if ($mode == 'tzserver') // Time for now with PHP server timezone added
- {
- require_once(DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php');
- $tzsecond=getServerTimeZoneInt('now'); // Contains tz+dayling saving time
- $ret=dol_now('gmt')+($tzsecond*3600);
- }
- /*else if ($mode == 'tzref') // Time for now with parent company timezone is added
- {
- require_once(DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php');
- $tzsecond=getParentCompanyTimeZoneInt(); // Contains tz+dayling saving time
- $ret=dol_now('gmt')+($tzsecond*3600);
- }*/
- else if ($mode == 'tzuser') // Time for now with user timezone is added
- {
- //print 'eeee'.time().'-'.mktime().'-'.gmmktime();
- $offsettz=(empty($_SESSION['dol_tz'])?0:$_SESSION['dol_tz'])*60*60;
- $offsetdst=(empty($_SESSION['dol_dst'])?0:$_SESSION['dol_dst'])*60*60;
- $ret=dol_now('gmt')+($offsettz+$offsetdst);
- }
- return $ret;
+ if ($mode == 'gmt') $ret=time(); // Time for now at greenwich.
+ else if ($mode == 'tzserver') // Time for now with PHP server timezone added
+ {
+ require_once(DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php');
+ $tzsecond=getServerTimeZoneInt('now'); // Contains tz+dayling saving time
+ $ret=dol_now('gmt')+($tzsecond*3600);
+ }
+ /*else if ($mode == 'tzref') // Time for now with parent company timezone is added
+ {
+ require_once(DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php');
+ $tzsecond=getParentCompanyTimeZoneInt(); // Contains tz+dayling saving time
+ $ret=dol_now('gmt')+($tzsecond*3600);
+ }*/
+ else if ($mode == 'tzuser') // Time for now with user timezone is added
+ {
+ //print 'eeee'.time().'-'.mktime().'-'.gmmktime();
+ $offsettz=(empty($_SESSION['dol_tz'])?0:$_SESSION['dol_tz'])*60*60;
+ $offsetdst=(empty($_SESSION['dol_dst'])?0:$_SESSION['dol_dst'])*60*60;
+ $ret=dol_now('gmt')+($offsettz+$offsetdst);
+ }
+ return $ret;
}
@@ -1040,27 +1040,27 @@ function dol_now($mode='gmt')
*/
function dol_print_size($size,$shortvalue=0,$shortunit=0)
{
- global $langs;
- $level=1024;
+ global $langs;
+ $level=1024;
- // Set value text
- if (empty($shortvalue) || $size < ($level*10))
- {
- $ret=$size;
- $textunitshort=$langs->trans("b");
- $textunitlong=$langs->trans("Bytes");
- }
- else
- {
- $ret=round($size/$level,0);
- $textunitshort=$langs->trans("Kb");
- $textunitlong=$langs->trans("KiloBytes");
- }
- // Use long or short text unit
- if (empty($shortunit)) { $ret.=' '.$textunitlong; }
- else { $ret.=' '.$textunitshort; }
+ // Set value text
+ if (empty($shortvalue) || $size < ($level*10))
+ {
+ $ret=$size;
+ $textunitshort=$langs->trans("b");
+ $textunitlong=$langs->trans("Bytes");
+ }
+ else
+ {
+ $ret=round($size/$level,0);
+ $textunitshort=$langs->trans("Kb");
+ $textunitlong=$langs->trans("KiloBytes");
+ }
+ // Use long or short text unit
+ if (empty($shortunit)) { $ret.=' '.$textunitlong; }
+ else { $ret.=' '.$textunitshort; }
- return $ret;
+ return $ret;
}
/**
@@ -1073,16 +1073,16 @@ function dol_print_size($size,$shortvalue=0,$shortunit=0)
*/
function dol_print_url($url,$target='_blank',$max=32)
{
- if (empty($url)) return '';
+ if (empty($url)) return '';
- $link='';
- if (! preg_match('/^http/i',$url)) $link.='http://';
- $link.=dol_trunc($url,$max);
- $link.='';
- return $link;
+ $link='';
+ if (! preg_match('/^http/i',$url)) $link.='http://';
+ $link.=dol_trunc($url,$max);
+ $link.='';
+ return $link;
}
/**
@@ -1098,42 +1098,42 @@ function dol_print_url($url,$target='_blank',$max=32)
*/
function dol_print_email($email,$cid=0,$socid=0,$addlink=0,$max=64,$showinvalid=1)
{
- global $conf,$user,$langs;
+ global $conf,$user,$langs;
- $newemail=$email;
+ $newemail=$email;
- if (empty($email)) return ' ';
+ if (empty($email)) return ' ';
- if (! empty($addlink))
- {
- $newemail='';
- $newemail.=dol_trunc($email,$max);
- $newemail.='';
- if ($showinvalid && ! isValidEmail($email))
- {
- $langs->load("errors");
- $newemail.=img_warning($langs->trans("ErrorBadEMail",$email));
- }
+ if (! empty($addlink))
+ {
+ $newemail='';
+ $newemail.=dol_trunc($email,$max);
+ $newemail.='';
+ if ($showinvalid && ! isValidEmail($email))
+ {
+ $langs->load("errors");
+ $newemail.=img_warning($langs->trans("ErrorBadEMail",$email));
+ }
- if (($cid || $socid) && $conf->agenda->enabled && $user->rights->agenda->myactions->create)
- {
- $type='AC_EMAIL'; $link='';
- if (! empty($conf->global->AGENDA_ADDACTIONFOREMAIL)) $link=''.img_object($langs->trans("AddAction"),"calendar").'';
- $newemail='';
- }
- }
- else
- {
- if ($showinvalid && ! isValidEmail($email))
- {
- $langs->load("errors");
- $newemail.=img_warning($langs->trans("ErrorBadEMail",$email));
- }
- }
- return $newemail;
+ if (($cid || $socid) && $conf->agenda->enabled && $user->rights->agenda->myactions->create)
+ {
+ $type='AC_EMAIL'; $link='';
+ if (! empty($conf->global->AGENDA_ADDACTIONFOREMAIL)) $link=''.img_object($langs->trans("AddAction"),"calendar").'';
+ $newemail='';
+ }
+ }
+ else
+ {
+ if ($showinvalid && ! isValidEmail($email))
+ {
+ $langs->load("errors");
+ $newemail.=img_warning($langs->trans("ErrorBadEMail",$email));
+ }
+ }
+ return $newemail;
}
/**
@@ -1149,73 +1149,73 @@ function dol_print_email($email,$cid=0,$socid=0,$addlink=0,$max=64,$showinvalid=
*/
function dol_print_phone($phone,$country="FR",$cid=0,$socid=0,$addlink=0,$separ=" ")
{
- global $conf,$user,$langs;
+ global $conf,$user,$langs;
- // Clean phone parameter
- $phone = preg_replace("/[\s.-]/","",trim($phone));
- if (empty($phone)) { return ''; }
+ // Clean phone parameter
+ $phone = preg_replace("/[\s.-]/","",trim($phone));
+ if (empty($phone)) { return ''; }
- $newphone=$phone;
- if (strtoupper($country) == "FR")
- {
- // France
- if (dol_strlen($phone) == 10) {
- $newphone=substr($newphone,0,2).$separ.substr($newphone,2,2).$separ.substr($newphone,4,2).$separ.substr($newphone,6,2).$separ.substr($newphone,8,2);
- }
- elseif (dol_strlen($newphone) == 7)
- {
- $newphone=substr($newphone,0,3).$separ.substr($newphone,3,2).$separ.substr($newphone,5,2);
- }
- elseif (dol_strlen($newphone) == 9)
- {
- $newphone=substr($newphone,0,2).$separ.substr($newphone,2,3).$separ.substr($newphone,5,2).$separ.substr($newphone,7,2);
- }
- elseif (dol_strlen($newphone) == 11)
- {
- $newphone=substr($newphone,0,3).$separ.substr($newphone,3,2).$separ.substr($newphone,5,2).$separ.substr($newphone,7,2).$separ.substr($newphone,9,2);
- }
- elseif (dol_strlen($newphone) == 12)
- {
- $newphone=substr($newphone,0,4).$separ.substr($newphone,4,2).$separ.substr($newphone,6,2).$separ.substr($newphone,8,2).$separ.substr($newphone,10,2);
- }
- }
+ $newphone=$phone;
+ if (strtoupper($country) == "FR")
+ {
+ // France
+ if (dol_strlen($phone) == 10) {
+ $newphone=substr($newphone,0,2).$separ.substr($newphone,2,2).$separ.substr($newphone,4,2).$separ.substr($newphone,6,2).$separ.substr($newphone,8,2);
+ }
+ elseif (dol_strlen($newphone) == 7)
+ {
+ $newphone=substr($newphone,0,3).$separ.substr($newphone,3,2).$separ.substr($newphone,5,2);
+ }
+ elseif (dol_strlen($newphone) == 9)
+ {
+ $newphone=substr($newphone,0,2).$separ.substr($newphone,2,3).$separ.substr($newphone,5,2).$separ.substr($newphone,7,2);
+ }
+ elseif (dol_strlen($newphone) == 11)
+ {
+ $newphone=substr($newphone,0,3).$separ.substr($newphone,3,2).$separ.substr($newphone,5,2).$separ.substr($newphone,7,2).$separ.substr($newphone,9,2);
+ }
+ elseif (dol_strlen($newphone) == 12)
+ {
+ $newphone=substr($newphone,0,4).$separ.substr($newphone,4,2).$separ.substr($newphone,6,2).$separ.substr($newphone,8,2).$separ.substr($newphone,10,2);
+ }
+ }
- if (! empty($addlink))
- {
- if (! empty($conf->clicktodial->enabled) && $addlink == 'AC_TEL')
- {
- if (empty($user->clicktodial_loaded)) $user->fetch_clicktodial();
+ if (! empty($addlink))
+ {
+ if (! empty($conf->clicktodial->enabled) && $addlink == 'AC_TEL')
+ {
+ if (empty($user->clicktodial_loaded)) $user->fetch_clicktodial();
- if (empty($conf->global->CLICKTODIAL_URL)) $urlmask='ErrorClickToDialModuleNotConfigured';
- else $urlmask=$conf->global->CLICKTODIAL_URL;
- $clicktodial_poste=(! empty($user->clicktodial_poste)?urlencode($user->clicktodial_poste):'');
- $clicktodial_login=(! empty($user->clicktodial_login)?urlencode($user->clicktodial_login):'');
- $clicktodial_password=(! empty($user->clicktodial_password)?urlencode($user->clicktodial_password):'');
- // This line is for backward compatibility
- $url = sprintf($urlmask, urlencode($phone), $clicktodial_poste, $clicktodial_login, $clicktodial_password);
- // Thoose lines are for substitution
- $substitarray=array('__PHONEFROM__'=>$clicktodial_poste,
- '__PHONETO__'=>urlencode($phone),
- '__LOGIN__'=>$clicktodial_login,
- '__PASS__'=>$clicktodial_password);
- $url = make_substitutions($url, $substitarray);
- $newphonesav=$newphone;
- $newphone ='global->CLICKTODIAL_FORCENEWTARGET)) $newphone.=' target="_blank"';
- $newphone.='>'.$newphonesav.'';
- }
+ if (empty($conf->global->CLICKTODIAL_URL)) $urlmask='ErrorClickToDialModuleNotConfigured';
+ else $urlmask=$conf->global->CLICKTODIAL_URL;
+ $clicktodial_poste=(! empty($user->clicktodial_poste)?urlencode($user->clicktodial_poste):'');
+ $clicktodial_login=(! empty($user->clicktodial_login)?urlencode($user->clicktodial_login):'');
+ $clicktodial_password=(! empty($user->clicktodial_password)?urlencode($user->clicktodial_password):'');
+ // This line is for backward compatibility
+ $url = sprintf($urlmask, urlencode($phone), $clicktodial_poste, $clicktodial_login, $clicktodial_password);
+ // Thoose lines are for substitution
+ $substitarray=array('__PHONEFROM__'=>$clicktodial_poste,
+ '__PHONETO__'=>urlencode($phone),
+ '__LOGIN__'=>$clicktodial_login,
+ '__PASS__'=>$clicktodial_password);
+ $url = make_substitutions($url, $substitarray);
+ $newphonesav=$newphone;
+ $newphone ='global->CLICKTODIAL_FORCENEWTARGET)) $newphone.=' target="_blank"';
+ $newphone.='>'.$newphonesav.'';
+ }
- //if (($cid || $socid) && $conf->agenda->enabled && $user->rights->agenda->myactions->create)
- if (! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create)
- {
- $type='AC_TEL'; $link='';
- if ($addlink == 'AC_FAX') $type='AC_FAX';
- if (! empty($conf->global->AGENDA_ADDACTIONFORPHONE)) $link=''.img_object($langs->trans("AddAction"),"calendar").'';
- $newphone='';
- }
- }
+ //if (($cid || $socid) && $conf->agenda->enabled && $user->rights->agenda->myactions->create)
+ if (! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create)
+ {
+ $type='AC_TEL'; $link='';
+ if ($addlink == 'AC_FAX') $type='AC_FAX';
+ if (! empty($conf->global->AGENDA_ADDACTIONFORPHONE)) $link=''.img_object($langs->trans("AddAction"),"calendar").'';
+ $newphone='';
+ }
+ }
- return $newphone;
+ return $newphone;
}
/**
@@ -1227,34 +1227,34 @@ function dol_print_phone($phone,$country="FR",$cid=0,$socid=0,$addlink=0,$separ=
*/
function dol_print_ip($ip,$mode=0)
{
- global $conf,$langs;
+ global $conf,$langs;
- $ret='';
+ $ret='';
- if (empty($mode)) $ret.=$ip;
+ if (empty($mode)) $ret.=$ip;
- if (! empty($conf->geoipmaxmind->enabled) && $mode != 2)
- {
- $datafile=$conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE;
- //$ip='24.24.24.24';
- //$datafile='E:\Mes Sites\Web\Admin1\awstats\maxmind\GeoIP.dat'; Note that this must be downloaded datafile (not same than datafile provided with ubuntu packages)
+ if (! empty($conf->geoipmaxmind->enabled) && $mode != 2)
+ {
+ $datafile=$conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE;
+ //$ip='24.24.24.24';
+ //$datafile='E:\Mes Sites\Web\Admin1\awstats\maxmind\GeoIP.dat'; Note that this must be downloaded datafile (not same than datafile provided with ubuntu packages)
- include_once(DOL_DOCUMENT_ROOT.'/core/class/dolgeoip.class.php');
- $geoip=new DolGeoIP('country',$datafile);
- //print 'ip='.$ip.' databaseType='.$geoip->gi->databaseType." GEOIP_CITY_EDITION_REV1=".GEOIP_CITY_EDITION_REV1."\n";
- //print "geoip_country_id_by_addr=".geoip_country_id_by_addr($geoip->gi,$ip)."\n";
- $countrycode=$geoip->getCountryCodeFromIP($ip);
- if ($countrycode) // If success, countrycode is us, fr, ...
- {
- if (file_exists(DOL_DOCUMENT_ROOT.'/theme/common/flags/'.$countrycode.'.png'))
- {
- $ret.=' '.img_picto($countrycode.' '.$langs->trans("AccordingToGeoIPDatabase"),DOL_URL_ROOT.'/theme/common/flags/'.$countrycode.'.png','',1);
- }
- else $ret.=' ('.$countrycode.')';
- }
- }
+ include_once(DOL_DOCUMENT_ROOT.'/core/class/dolgeoip.class.php');
+ $geoip=new DolGeoIP('country',$datafile);
+ //print 'ip='.$ip.' databaseType='.$geoip->gi->databaseType." GEOIP_CITY_EDITION_REV1=".GEOIP_CITY_EDITION_REV1."\n";
+ //print "geoip_country_id_by_addr=".geoip_country_id_by_addr($geoip->gi,$ip)."\n";
+ $countrycode=$geoip->getCountryCodeFromIP($ip);
+ if ($countrycode) // If success, countrycode is us, fr, ...
+ {
+ if (file_exists(DOL_DOCUMENT_ROOT.'/theme/common/flags/'.$countrycode.'.png'))
+ {
+ $ret.=' '.img_picto($countrycode.' '.$langs->trans("AccordingToGeoIPDatabase"),DOL_URL_ROOT.'/theme/common/flags/'.$countrycode.'.png','',1);
+ }
+ else $ret.=' ('.$countrycode.')';
+ }
+ }
- return $ret;
+ return $ret;
}
/**
@@ -1265,22 +1265,22 @@ function dol_print_ip($ip,$mode=0)
*/
function dol_user_country()
{
- global $conf,$langs,$user;
+ global $conf,$langs,$user;
- //$ret=$user->xxx;
- $ret='';
- if (! empty($conf->geoipmaxmind->enabled))
- {
- $ip=$_SERVER["REMOTE_ADDR"];
- $datafile=$conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE;
- //$ip='24.24.24.24';
- //$datafile='E:\Mes Sites\Web\Admin1\awstats\maxmind\GeoIP.dat';
- include_once(DOL_DOCUMENT_ROOT.'/core/class/dolgeoip.class.php');
- $geoip=new DolGeoIP('country',$datafile);
- $countrycode=$geoip->getCountryCodeFromIP($ip);
- $ret=$countrycode;
- }
- return $ret;
+ //$ret=$user->xxx;
+ $ret='';
+ if (! empty($conf->geoipmaxmind->enabled))
+ {
+ $ip=$_SERVER["REMOTE_ADDR"];
+ $datafile=$conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE;
+ //$ip='24.24.24.24';
+ //$datafile='E:\Mes Sites\Web\Admin1\awstats\maxmind\GeoIP.dat';
+ include_once(DOL_DOCUMENT_ROOT.'/core/class/dolgeoip.class.php');
+ $geoip=new DolGeoIP('country',$datafile);
+ $countrycode=$geoip->getCountryCodeFromIP($ip);
+ $ret=$countrycode;
+ }
+ return $ret;
}
/**
@@ -1294,31 +1294,31 @@ function dol_user_country()
*/
function dol_print_address($address, $htmlid, $mode, $id)
{
- global $conf,$user,$langs;
+ global $conf,$user,$langs;
- if ($address)
- {
- print nl2br($address);
- $showgmap=$showomap=0;
- if ($mode=='thirdparty' && ! empty($conf->google->enabled) && ! empty($conf->global->GOOGLE_ENABLE_GMAPS)) $showgmap=1;
- if ($mode=='contact' && ! empty($conf->google->enabled) && ! empty($conf->global->GOOGLE_ENABLE_GMAPS_CONTACTS)) $showgmap=1;
- if ($mode=='member' && ! empty($conf->google->enabled) && ! empty($conf->global->GOOGLE_ENABLE_GMAPS_MEMBERS)) $showgmap=1;
- if ($mode=='thirdparty' && ! empty($conf->openstreetmap->enabled) && ! empty($conf->global->OPENSTREETMAP_ENABLE_MAPS)) $showomap=1;
- if ($mode=='contact' && ! empty($conf->openstreetmap->enabled) && ! empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_CONTACTS)) $showomap=1;
- if ($mode=='member' && ! empty($conf->openstreetmap->enabled) && ! empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_MEMBERS)) $showomap=1;
+ if ($address)
+ {
+ print nl2br($address);
+ $showgmap=$showomap=0;
+ if ($mode=='thirdparty' && ! empty($conf->google->enabled) && ! empty($conf->global->GOOGLE_ENABLE_GMAPS)) $showgmap=1;
+ if ($mode=='contact' && ! empty($conf->google->enabled) && ! empty($conf->global->GOOGLE_ENABLE_GMAPS_CONTACTS)) $showgmap=1;
+ if ($mode=='member' && ! empty($conf->google->enabled) && ! empty($conf->global->GOOGLE_ENABLE_GMAPS_MEMBERS)) $showgmap=1;
+ if ($mode=='thirdparty' && ! empty($conf->openstreetmap->enabled) && ! empty($conf->global->OPENSTREETMAP_ENABLE_MAPS)) $showomap=1;
+ if ($mode=='contact' && ! empty($conf->openstreetmap->enabled) && ! empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_CONTACTS)) $showomap=1;
+ if ($mode=='member' && ! empty($conf->openstreetmap->enabled) && ! empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_MEMBERS)) $showomap=1;
- // TODO Add a hook here
- if ($showgmap)
- {
- $url=dol_buildpath('/google/gmaps.php?mode='.$mode.'&id='.$id,1);
- print '
';
- }
- if ($showomap)
- {
- $url=dol_buildpath('/openstreetmap/maps.php?mode='.$mode.'&id='.$id,1);
- print '
';
- }
- }
+ // TODO Add a hook here
+ if ($showgmap)
+ {
+ $url=dol_buildpath('/google/gmaps.php?mode='.$mode.'&id='.$id,1);
+ print '
';
+ }
+ if ($showomap)
+ {
+ $url=dol_buildpath('/openstreetmap/maps.php?mode='.$mode.'&id='.$id,1);
+ print '
';
+ }
+ }
}
@@ -1330,19 +1330,19 @@ function dol_print_address($address, $htmlid, $mode, $id)
*/
function isValidEmail($address)
{
- if (preg_match("/.*<(.+)>/i", $address, $regs)) {
- $address = $regs[1];
- }
- // 2 letters domains extensions are for countries
- // 3 letters domains extensions: biz|com|edu|gov|int|mil|net|org|pro|...
- if (preg_match("/^[^@\s\t]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2,3}|asso|aero|coop|info|name)\$/i",$address))
- {
- return true;
- }
- else
- {
- return false;
- }
+ if (preg_match("/.*<(.+)>/i", $address, $regs)) {
+ $address = $regs[1];
+ }
+ // 2 letters domains extensions are for countries
+ // 3 letters domains extensions: biz|com|edu|gov|int|mil|net|org|pro|...
+ if (preg_match("/^[^@\s\t]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2,3}|asso|aero|coop|info|name)\$/i",$address))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
}
/**
@@ -1353,7 +1353,7 @@ function isValidEmail($address)
*/
function isValidPhone($phone)
{
- return true;
+ return true;
}
@@ -1366,8 +1366,8 @@ function isValidPhone($phone)
*/
function dol_strlen($string,$stringencoding='UTF-8')
{
- if (function_exists('mb_strlen')) return mb_strlen($string,$stringencoding);
- else return strlen($string);
+ if (function_exists('mb_strlen')) return mb_strlen($string,$stringencoding);
+ else return strlen($string);
}
/**
@@ -1381,20 +1381,20 @@ function dol_strlen($string,$stringencoding='UTF-8')
*/
function dol_substr($string,$start,$length,$stringencoding='')
{
- global $langs;
+ global $langs;
- if (empty($stringencoding)) $stringencoding=$langs->charset_output;
+ if (empty($stringencoding)) $stringencoding=$langs->charset_output;
- $ret='';
- if (function_exists('mb_substr'))
- {
- $ret=mb_substr($string,$start,$length,$stringencoding);
- }
- else
- {
- $ret=substr($string,$start,$length);
- }
- return $ret;
+ $ret='';
+ if (function_exists('mb_substr'))
+ {
+ $ret=mb_substr($string,$start,$length,$stringencoding);
+ }
+ else
+ {
+ $ret=substr($string,$start,$length);
+ }
+ return $ret;
}
@@ -1573,48 +1573,48 @@ function dol_print_graph($htmlid,$width,$height,$data,$showlegend=0,$type='pie',
*/
function dol_trunc($string,$size=40,$trunc='right',$stringencoding='UTF-8',$nodot=0)
{
- global $conf;
+ global $conf;
- if ($size==0 || ! empty($conf->global->MAIN_DISABLE_TRUNC)) return $string;
+ if ($size==0 || ! empty($conf->global->MAIN_DISABLE_TRUNC)) return $string;
- // We go always here
- if ($trunc == 'right')
- {
- $newstring=dol_textishtml($string)?dol_string_nohtmltag($string,1):$string;
- if (dol_strlen($newstring,$stringencoding) > ($size+($nodot?0:1)))
- return dol_substr($newstring,0,$size,$stringencoding).($nodot?'':'...');
- else
- return $string;
- }
- elseif ($trunc == 'middle')
- {
- $newstring=dol_textishtml($string)?dol_string_nohtmltag($string,1):$string;
- if (dol_strlen($newstring,$stringencoding) > 2 && dol_strlen($newstring,$stringencoding) > ($size+1))
- {
- $size1=round($size/2);
- $size2=round($size/2);
- return dol_substr($newstring,0,$size1,$stringencoding).'...'.dol_substr($newstring,dol_strlen($newstring,$stringencoding) - $size2,$size2,$stringencoding);
- }
- else
- return $string;
- }
- elseif ($trunc == 'left')
- {
- $newstring=dol_textishtml($string)?dol_string_nohtmltag($string,1):$string;
- if (dol_strlen($newstring,$stringencoding) > ($size+1))
- return '...'.dol_substr($newstring,dol_strlen($newstring,$stringencoding) - $size,$size,$stringencoding);
- else
- return $string;
- }
- elseif ($trunc == 'wrap')
- {
- $newstring=dol_textishtml($string)?dol_string_nohtmltag($string,1):$string;
- if (dol_strlen($newstring,$stringencoding) > ($size+1))
- return dol_substr($newstring,0,$size,$stringencoding)."\n".dol_trunc(dol_substr($newstring,$size,dol_strlen($newstring,$stringencoding)-$size,$stringencoding),$size,$trunc);
- else
- return $string;
- }
- else return 'BadParam3CallingDolTrunc';
+ // We go always here
+ if ($trunc == 'right')
+ {
+ $newstring=dol_textishtml($string)?dol_string_nohtmltag($string,1):$string;
+ if (dol_strlen($newstring,$stringencoding) > ($size+($nodot?0:1)))
+ return dol_substr($newstring,0,$size,$stringencoding).($nodot?'':'...');
+ else
+ return $string;
+ }
+ elseif ($trunc == 'middle')
+ {
+ $newstring=dol_textishtml($string)?dol_string_nohtmltag($string,1):$string;
+ if (dol_strlen($newstring,$stringencoding) > 2 && dol_strlen($newstring,$stringencoding) > ($size+1))
+ {
+ $size1=round($size/2);
+ $size2=round($size/2);
+ return dol_substr($newstring,0,$size1,$stringencoding).'...'.dol_substr($newstring,dol_strlen($newstring,$stringencoding) - $size2,$size2,$stringencoding);
+ }
+ else
+ return $string;
+ }
+ elseif ($trunc == 'left')
+ {
+ $newstring=dol_textishtml($string)?dol_string_nohtmltag($string,1):$string;
+ if (dol_strlen($newstring,$stringencoding) > ($size+1))
+ return '...'.dol_substr($newstring,dol_strlen($newstring,$stringencoding) - $size,$size,$stringencoding);
+ else
+ return $string;
+ }
+ elseif ($trunc == 'wrap')
+ {
+ $newstring=dol_textishtml($string)?dol_string_nohtmltag($string,1):$string;
+ if (dol_strlen($newstring,$stringencoding) > ($size+1))
+ return dol_substr($newstring,0,$size,$stringencoding)."\n".dol_trunc(dol_substr($newstring,$size,dol_strlen($newstring,$stringencoding)-$size,$stringencoding),$size,$trunc);
+ else
+ return $string;
+ }
+ else return 'BadParam3CallingDolTrunc';
}
@@ -1631,29 +1631,29 @@ function dol_trunc($string,$size=40,$trunc='right',$stringencoding='UTF-8',$nodo
*/
function img_object($alt, $picto, $options='', $pictoisfullpath=0)
{
- global $conf;
+ global $conf;
- // Clean parameters
- if (! preg_match('/(\.png|\.gif)$/i',$picto) && ! preg_match('/^([^@]+)@([^@]+)$/i',$picto)) $picto.='.png';
+ // Clean parameters
+ if (! preg_match('/(\.png|\.gif)$/i',$picto) && ! preg_match('/^([^@]+)@([^@]+)$/i',$picto)) $picto.='.png';
- // Define fullpathpicto to use into src
- if (! empty($pictoisfullpath)) $fullpathpicto=$picto;
- else
- {
- // By default, we search into theme directory
- $url = DOL_URL_ROOT;
- $path = 'theme/'.$conf->theme;
- if (! empty($conf->global->MAIN_FORCETHEMEDIR)) $path=preg_replace('/^\//','',$conf->global->MAIN_FORCETHEMEDIR).'/'.$path;
- // If we ask an image into module/img (not into a theme path)
- if (preg_match('/^([^@]+)@([^@]+)$/i',$picto,$regs)) { $picto = $regs[1]; $path=$regs[2]; } // If image into a module/img path
- if (! preg_match('/(\.png|\.gif)$/i',$picto)) $picto.='.png';
- // If img file not into standard path, we use alternate path
- if (defined('DOL_URL_ROOT_ALT') && DOL_URL_ROOT_ALT && ! file_exists(DOL_DOCUMENT_ROOT.'/'.$path.'/img/object_'.$picto)) $url = DOL_URL_ROOT_ALT;
+ // Define fullpathpicto to use into src
+ if (! empty($pictoisfullpath)) $fullpathpicto=$picto;
+ else
+ {
+ // By default, we search into theme directory
+ $url = DOL_URL_ROOT;
+ $path = 'theme/'.$conf->theme;
+ if (! empty($conf->global->MAIN_FORCETHEMEDIR)) $path=preg_replace('/^\//','',$conf->global->MAIN_FORCETHEMEDIR).'/'.$path;
+ // If we ask an image into module/img (not into a theme path)
+ if (preg_match('/^([^@]+)@([^@]+)$/i',$picto,$regs)) { $picto = $regs[1]; $path=$regs[2]; } // If image into a module/img path
+ if (! preg_match('/(\.png|\.gif)$/i',$picto)) $picto.='.png';
+ // If img file not into standard path, we use alternate path
+ if (defined('DOL_URL_ROOT_ALT') && DOL_URL_ROOT_ALT && ! file_exists(DOL_DOCUMENT_ROOT.'/'.$path.'/img/object_'.$picto)) $url = DOL_URL_ROOT_ALT;
- $fullpathpicto=$url.'/'.$path.'/img/object_'.$picto;
- }
+ $fullpathpicto=$url.'/'.$path.'/img/object_'.$picto;
+ }
- return '
';
+ return '
';
}
/**
@@ -1672,29 +1672,29 @@ function img_object($alt, $picto, $options='', $pictoisfullpath=0)
*/
function img_picto($alt, $picto, $options='', $pictoisfullpath=0)
{
- global $conf;
+ global $conf;
- // Clean parameters
- if (! preg_match('/(\.png|\.gif)$/i',$picto) && ! preg_match('/^([^@]+)@([^@]+)$/i',$picto)) $picto.='.png';
+ // Clean parameters
+ if (! preg_match('/(\.png|\.gif)$/i',$picto) && ! preg_match('/^([^@]+)@([^@]+)$/i',$picto)) $picto.='.png';
- // Define fullpathpicto to use into src
- if (! empty($pictoisfullpath)) $fullpathpicto=$picto;
- else
- {
- // By default, we search into theme directory
- $url = DOL_URL_ROOT;
- $path = 'theme/'.$conf->theme;
- if (! empty($conf->global->MAIN_FORCETHEMEDIR)) $path=preg_replace('/^\//','',$conf->global->MAIN_FORCETHEMEDIR).'/'.$path;
- // If we ask an image into module/img (not into a theme path)
- if (preg_match('/^([^@]+)@([^@]+)$/i',$picto,$regs)) { $picto = $regs[1]; $path=$regs[2]; } // If image into a module/img path
- if (! preg_match('/(\.png|\.gif)$/i',$picto)) $picto.='.png';
- // If img file not into standard path, we use alternate path
- if (defined('DOL_URL_ROOT_ALT') && DOL_URL_ROOT_ALT && ! file_exists(DOL_DOCUMENT_ROOT.'/'.$path.'/img/'.$picto)) $url = DOL_URL_ROOT_ALT;
+ // Define fullpathpicto to use into src
+ if (! empty($pictoisfullpath)) $fullpathpicto=$picto;
+ else
+ {
+ // By default, we search into theme directory
+ $url = DOL_URL_ROOT;
+ $path = 'theme/'.$conf->theme;
+ if (! empty($conf->global->MAIN_FORCETHEMEDIR)) $path=preg_replace('/^\//','',$conf->global->MAIN_FORCETHEMEDIR).'/'.$path;
+ // If we ask an image into module/img (not into a theme path)
+ if (preg_match('/^([^@]+)@([^@]+)$/i',$picto,$regs)) { $picto = $regs[1]; $path=$regs[2]; } // If image into a module/img path
+ if (! preg_match('/(\.png|\.gif)$/i',$picto)) $picto.='.png';
+ // If img file not into standard path, we use alternate path
+ if (defined('DOL_URL_ROOT_ALT') && DOL_URL_ROOT_ALT && ! file_exists(DOL_DOCUMENT_ROOT.'/'.$path.'/img/'.$picto)) $url = DOL_URL_ROOT_ALT;
- $fullpathpicto=$url.'/'.$path.'/img/'.$picto;
- }
+ $fullpathpicto=$url.'/'.$path.'/img/'.$picto;
+ }
- return '
';
+ return '
';
}
/**
@@ -1709,24 +1709,24 @@ function img_picto($alt, $picto, $options='', $pictoisfullpath=0)
*/
function img_picto_common($alt, $picto, $options = '', $pictoisfullpath = 0)
{
- global $conf;
+ global $conf;
- if (! preg_match('/(\.png|\.gif)$/i', $picto)) $picto .= '.png';
+ if (! preg_match('/(\.png|\.gif)$/i', $picto)) $picto .= '.png';
- if ($pictoisfullpath) $path = $picto;
- else
- {
- $path = DOL_URL_ROOT.'/theme/common/'.$picto;
-
- if (! empty($conf->global->MAIN_MODULE_CAN_OVERWRITE_COMMONICONS))
- {
- $themepath = DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/img/'.$picto;
+ if ($pictoisfullpath) $path = $picto;
+ else
+ {
+ $path = DOL_URL_ROOT.'/theme/common/'.$picto;
+
+ if (! empty($conf->global->MAIN_MODULE_CAN_OVERWRITE_COMMONICONS))
+ {
+ $themepath = DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/img/'.$picto;
- if (file_exists($themepath)) return img_picto($alt, $themepath, $options, 1);
- }
- }
+ if (file_exists($themepath)) return img_picto($alt, $themepath, $options, 1);
+ }
+ }
- return img_picto($alt, $path, $options, 1);
+ return img_picto($alt, $path, $options, 1);
}
/**
@@ -1738,18 +1738,18 @@ function img_picto_common($alt, $picto, $options = '', $pictoisfullpath = 0)
*/
function img_action($alt, $numaction)
{
- global $conf, $langs;
+ global $conf, $langs;
- if ($alt == 'default')
- {
- if ($numaction == -1) $alt = $langs->transnoentitiesnoconv('ChangeDoNotContact');
- if ($numaction == 0) $alt = $langs->transnoentitiesnoconv('ChangeNeverContacted');
- if ($numaction == 1) $alt = $langs->transnoentitiesnoconv('ChangeToContact');
- if ($numaction == 2) $alt = $langs->transnoentitiesnoconv('ChangeContactInProcess');
- if ($numaction == 3) $alt = $langs->transnoentitiesnoconv('ChangeContactDone');
- }
+ if ($alt == 'default')
+ {
+ if ($numaction == -1) $alt = $langs->transnoentitiesnoconv('ChangeDoNotContact');
+ if ($numaction == 0) $alt = $langs->transnoentitiesnoconv('ChangeNeverContacted');
+ if ($numaction == 1) $alt = $langs->transnoentitiesnoconv('ChangeToContact');
+ if ($numaction == 2) $alt = $langs->transnoentitiesnoconv('ChangeContactInProcess');
+ if ($numaction == 3) $alt = $langs->transnoentitiesnoconv('ChangeContactDone');
+ }
- return img_picto($alt, 'stcomm'.$numaction.'.png');
+ return img_picto($alt, 'stcomm'.$numaction.'.png');
}
/**
@@ -1761,11 +1761,11 @@ function img_action($alt, $numaction)
*/
function img_pdf($alt = 'default', $size = 3)
{
- global $conf, $langs;
+ global $conf, $langs;
- if ($alt == 'default') $alt = $langs->trans('Show');
+ if ($alt == 'default') $alt = $langs->trans('Show');
- return img_picto($alt, 'pdf'.$size.'.png');
+ return img_picto($alt, 'pdf'.$size.'.png');
}
/**
@@ -1776,11 +1776,11 @@ function img_pdf($alt = 'default', $size = 3)
*/
function img_edit_add($alt = 'default')
{
- global $conf, $langs;
+ global $conf, $langs;
- if ($alt == 'default') $alt = $langs->trans('Add');
+ if ($alt == 'default') $alt = $langs->trans('Add');
- return img_picto($alt, 'edit_add.png');
+ return img_picto($alt, 'edit_add.png');
}
/**
* Show logo -
@@ -1790,11 +1790,11 @@ function img_edit_add($alt = 'default')
*/
function img_edit_remove($alt = 'default')
{
- global $conf, $langs;
+ global $conf, $langs;
- if ($alt == 'default') $alt = $langs->trans('Remove');
+ if ($alt == 'default') $alt = $langs->trans('Remove');
- return img_picto($alt, 'edit_remove.png');
+ return img_picto($alt, 'edit_remove.png');
}
/**
@@ -1807,11 +1807,11 @@ function img_edit_remove($alt = 'default')
*/
function img_edit($alt = 'default', $float = 0, $other = '')
{
- global $conf, $langs;
+ global $conf, $langs;
- if ($alt == 'default') $alt = $langs->trans('Modify');
+ if ($alt == 'default') $alt = $langs->trans('Modify');
- return img_picto($alt, 'edit.png', ($float ? 'style="float: right"' : $other));
+ return img_picto($alt, 'edit.png', ($float ? 'style="float: right"' : $other));
}
/**
@@ -1824,13 +1824,13 @@ function img_edit($alt = 'default', $float = 0, $other = '')
*/
function img_view($alt = 'default', $float = 0, $other = '')
{
- global $conf, $langs;
+ global $conf, $langs;
- if ($alt == 'default') $alt = $langs->trans('View');
+ if ($alt == 'default') $alt = $langs->trans('View');
- $options = ($float ? 'style="float: right" ' : '').$other;
-
- return img_picto($alt, 'view.png', $options);
+ $options = ($float ? 'style="float: right" ' : '').$other;
+
+ return img_picto($alt, 'view.png', $options);
}
/**
@@ -1842,11 +1842,11 @@ function img_view($alt = 'default', $float = 0, $other = '')
*/
function img_delete($alt = 'default', $other = '')
{
- global $conf, $langs;
+ global $conf, $langs;
- if ($alt == 'default') $alt = $langs->trans('Delete');
+ if ($alt == 'default') $alt = $langs->trans('Delete');
- return img_picto($alt, 'delete.png', $other);
+ return img_picto($alt, 'delete.png', $other);
}
/**
@@ -1858,15 +1858,15 @@ function img_delete($alt = 'default', $other = '')
*/
function img_help($usehelpcursor = 1, $usealttitle = 1)
{
- global $conf, $langs;
+ global $conf, $langs;
- if ($usealttitle)
- {
- if (is_string($usealttitle)) $alt = dol_escape_htmltag($usealttitle);
- else $alt = $langs->trans('Info');
- }
+ if ($usealttitle)
+ {
+ if (is_string($usealttitle)) $alt = dol_escape_htmltag($usealttitle);
+ else $alt = $langs->trans('Info');
+ }
- return img_picto($usealttitle, 'info.png', ($usehelpcursor ? 'style="cursor: help"' : ''));
+ return img_picto($usealttitle, 'info.png', ($usehelpcursor ? 'style="cursor: help"' : ''));
}
/**
@@ -1877,11 +1877,11 @@ function img_help($usehelpcursor = 1, $usealttitle = 1)
*/
function img_info($alt = 'default')
{
- global $conf, $langs;
+ global $conf, $langs;
- if ($alt == 'default') $alt = $langs->trans('Informations');
+ if ($alt == 'default') $alt = $langs->trans('Informations');
- return img_picto($alt, 'info.png');
+ return img_picto($alt, 'info.png');
}
/**
@@ -1893,11 +1893,11 @@ function img_info($alt = 'default')
*/
function img_warning($alt = 'default', $float = 0)
{
- global $conf, $langs;
+ global $conf, $langs;
- if ($alt == 'default') $alt = $langs->trans('Warning');
+ if ($alt == 'default') $alt = $langs->trans('Warning');
- return img_picto($alt, 'warning.png', ($float ? 'style="float: right"' : ''));
+ return img_picto($alt, 'warning.png', ($float ? 'style="float: right"' : ''));
}
/**
@@ -1908,11 +1908,11 @@ function img_warning($alt = 'default', $float = 0)
*/
function img_error($alt = 'default')
{
- global $conf, $langs;
+ global $conf, $langs;
- if ($alt == 'default') $alt = $langs->trans('Error');
+ if ($alt == 'default') $alt = $langs->trans('Error');
- return img_picto($alt, 'error.png');
+ return img_picto($alt, 'error.png');
}
/**
@@ -1923,11 +1923,11 @@ function img_error($alt = 'default')
*/
function img_next($alt = 'default')
{
- global $conf, $langs;
+ global $conf, $langs;
- if ($alt == 'default') $alt = $langs->trans('Next');
+ if ($alt == 'default') $alt = $langs->trans('Next');
- return img_picto($alt, 'next.png');
+ return img_picto($alt, 'next.png');
}
/**
@@ -1938,11 +1938,11 @@ function img_next($alt = 'default')
*/
function img_previous($alt = 'default')
{
- global $conf, $langs;
+ global $conf, $langs;
- if ($alt == 'default') $alt = $langs->trans('Previous');
+ if ($alt == 'default') $alt = $langs->trans('Previous');
- return img_picto($alt, 'previous.png');
+ return img_picto($alt, 'previous.png');
}
/**
@@ -1954,11 +1954,11 @@ function img_previous($alt = 'default')
*/
function img_down($alt = 'default', $selected = 0)
{
- global $conf, $langs;
+ global $conf, $langs;
- if ($alt == 'default') $alt = $langs->trans('Down');
+ if ($alt == 'default') $alt = $langs->trans('Down');
- return img_picto($alt, ($selected ? '1downarrow_selected.png' : '1downarrow.png'), 'class="imgdown"');
+ return img_picto($alt, ($selected ? '1downarrow_selected.png' : '1downarrow.png'), 'class="imgdown"');
}
/**
@@ -1970,11 +1970,11 @@ function img_down($alt = 'default', $selected = 0)
*/
function img_up($alt = 'default', $selected = 0)
{
- global $conf, $langs;
+ global $conf, $langs;
- if ($alt == 'default') $alt = $langs->trans('Up');
+ if ($alt == 'default') $alt = $langs->trans('Up');
- return img_picto($alt, ($selected ? '1uparrow_selected.png' : '1uparrow.png'), 'class="imgup"');
+ return img_picto($alt, ($selected ? '1uparrow_selected.png' : '1uparrow.png'), 'class="imgup"');
}
/**
@@ -1986,11 +1986,11 @@ function img_up($alt = 'default', $selected = 0)
*/
function img_left($alt = 'default', $selected = 0)
{
- global $conf, $langs;
+ global $conf, $langs;
- if ($alt == 'default') $alt = $langs->trans('Left');
+ if ($alt == 'default') $alt = $langs->trans('Left');
- return img_picto($alt, ($selected ? '1leftarrow_selected.png' : '1leftarrow.png'));
+ return img_picto($alt, ($selected ? '1leftarrow_selected.png' : '1leftarrow.png'));
}
/**
@@ -2002,11 +2002,11 @@ function img_left($alt = 'default', $selected = 0)
*/
function img_right($alt = 'default', $selected = 0)
{
- global $conf, $langs;
+ global $conf, $langs;
- if ($alt == 'default') $alt = $langs->trans('Right');
+ if ($alt == 'default') $alt = $langs->trans('Right');
- return img_picto($alt, ($selected ? '1rightarrow_selected.png' : '1rightarrow.png'));
+ return img_picto($alt, ($selected ? '1rightarrow_selected.png' : '1rightarrow.png'));
}
/**
@@ -2018,13 +2018,13 @@ function img_right($alt = 'default', $selected = 0)
*/
function img_allow($allow, $alt = 'default')
{
- global $conf, $langs;
+ global $conf, $langs;
- if ($alt == 'default') $alt = $langs->trans('Active');
+ if ($alt == 'default') $alt = $langs->trans('Active');
- if ($allow == 1) return img_picto($alt, 'tick.png');
-
- return '-';
+ if ($allow == 1) return img_picto($alt, 'tick.png');
+
+ return '-';
}
@@ -2037,14 +2037,14 @@ function img_allow($allow, $alt = 'default')
*/
function img_mime($file, $alt = '')
{
- require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
- $mimetype = dol_mimetype($file, '', 1);
- $mimeimg = dol_mimetype($file, '', 2);
+ $mimetype = dol_mimetype($file, '', 1);
+ $mimeimg = dol_mimetype($file, '', 2);
- if (empty($alt)) $alt = 'Mime type: '.$mimetype;
+ if (empty($alt)) $alt = 'Mime type: '.$mimetype;
- return img_picto_common($alt, 'mime/'.$mimeimg);
+ return img_picto_common($alt, 'mime/'.$mimeimg);
}
@@ -2079,14 +2079,14 @@ function img_phone($alt = 'default', $option = 0)
*/
function info_admin($text, $infoonimgalt = 0)
{
- global $conf, $langs;
+ global $conf, $langs;
- if ($infoonimgalt)
- {
- return img_picto($text, 'star');
- }
-
- return ''.img_picto($langs->trans('InfoAdmin'), 'star').' '.$text.'
';
+ if ($infoonimgalt)
+ {
+ return img_picto($text, 'star');
+ }
+
+ return ''.img_picto($langs->trans('InfoAdmin'), 'star').' '.$text.'
';
}
@@ -2103,109 +2103,109 @@ function info_admin($text, $infoonimgalt = 0)
*/
function dol_print_error($db='',$error='')
{
- global $conf,$langs,$argv;
- global $dolibarr_main_prod;
+ global $conf,$langs,$argv;
+ global $dolibarr_main_prod;
- $out = '';
- $syslog = '';
+ $out = '';
+ $syslog = '';
- // Si erreur intervenue avant chargement langue
- if (! $langs)
- {
- require_once DOL_DOCUMENT_ROOT .'/core/class/translate.class.php';
- $langs = new Translate('', $conf);
- $langs->load("main");
- }
- $langs->load("main");
- $langs->load("errors");
+ // Si erreur intervenue avant chargement langue
+ if (! $langs)
+ {
+ require_once DOL_DOCUMENT_ROOT .'/core/class/translate.class.php';
+ $langs = new Translate('', $conf);
+ $langs->load("main");
+ }
+ $langs->load("main");
+ $langs->load("errors");
- if ($_SERVER['DOCUMENT_ROOT']) // Mode web
- {
- $out.=$langs->trans("DolibarrHasDetectedError").".
\n";
- if (! empty($conf->global->MAIN_FEATURES_LEVEL))
- $out.="You use an experimental level of features, so please do NOT report any bugs, anywhere, until going back to MAIN_FEATURES_LEVEL = 0.
\n";
- $out.=$langs->trans("InformationToHelpDiagnose").":
\n";
+ if ($_SERVER['DOCUMENT_ROOT']) // Mode web
+ {
+ $out.=$langs->trans("DolibarrHasDetectedError").".
\n";
+ if (! empty($conf->global->MAIN_FEATURES_LEVEL))
+ $out.="You use an experimental level of features, so please do NOT report any bugs, anywhere, until going back to MAIN_FEATURES_LEVEL = 0.
\n";
+ $out.=$langs->trans("InformationToHelpDiagnose").":
\n";
- $out.="".$langs->trans("Date").": ".dol_print_date(time(),'dayhourlog')."
\n";;
- $out.="".$langs->trans("Dolibarr").": ".DOL_VERSION."
\n";;
- if (isset($conf->global->MAIN_FEATURES_LEVEL)) $out.="".$langs->trans("LevelOfFeature").": ".$conf->global->MAIN_FEATURES_LEVEL."
\n";;
- if (function_exists("phpversion"))
- {
- $out.="".$langs->trans("PHP").": ".phpversion()."
\n";
- //phpinfo(); // This is to show location of php.ini file
- }
- $out.="".$langs->trans("Server").": ".$_SERVER["SERVER_SOFTWARE"]."
\n";;
- $out.="
\n";
- $out.="".$langs->trans("RequestedUrl").": ".$_SERVER["REQUEST_URI"]."
\n";;
- $out.="".$langs->trans("Referer").": ".(isset($_SERVER["HTTP_REFERER"])?$_SERVER["HTTP_REFERER"]:'')."
\n";;
- $out.="".$langs->trans("MenuManager").": ".$conf->top_menu."
\n";
- $out.="
\n";
- $syslog.="url=".$_SERVER["REQUEST_URI"];
- $syslog.=", query_string=".$_SERVER["QUERY_STRING"];
- }
- else // Mode CLI
- {
- $out.='> '.$langs->transnoentities("ErrorInternalErrorDetected").":\n".$argv[0]."\n";
- $syslog.="pid=".getmypid();
- }
+ $out.="".$langs->trans("Date").": ".dol_print_date(time(),'dayhourlog')."
\n";;
+ $out.="".$langs->trans("Dolibarr").": ".DOL_VERSION."
\n";;
+ if (isset($conf->global->MAIN_FEATURES_LEVEL)) $out.="".$langs->trans("LevelOfFeature").": ".$conf->global->MAIN_FEATURES_LEVEL."
\n";;
+ if (function_exists("phpversion"))
+ {
+ $out.="".$langs->trans("PHP").": ".phpversion()."
\n";
+ //phpinfo(); // This is to show location of php.ini file
+ }
+ $out.="".$langs->trans("Server").": ".$_SERVER["SERVER_SOFTWARE"]."
\n";;
+ $out.="
\n";
+ $out.="".$langs->trans("RequestedUrl").": ".$_SERVER["REQUEST_URI"]."
\n";;
+ $out.="".$langs->trans("Referer").": ".(isset($_SERVER["HTTP_REFERER"])?$_SERVER["HTTP_REFERER"]:'')."
\n";;
+ $out.="".$langs->trans("MenuManager").": ".$conf->top_menu."
\n";
+ $out.="
\n";
+ $syslog.="url=".$_SERVER["REQUEST_URI"];
+ $syslog.=", query_string=".$_SERVER["QUERY_STRING"];
+ }
+ else // Mode CLI
+ {
+ $out.='> '.$langs->transnoentities("ErrorInternalErrorDetected").":\n".$argv[0]."\n";
+ $syslog.="pid=".getmypid();
+ }
- if (is_object($db))
- {
- if ($_SERVER['DOCUMENT_ROOT']) // Mode web
- {
- $out.="".$langs->trans("DatabaseTypeManager").": ".$db->type."
\n";
- $out.="".$langs->trans("RequestLastAccessInError").": ".($db->lastqueryerror()?$db->lastqueryerror():$langs->trans("ErrorNoRequestInError"))."
\n";
- $out.="".$langs->trans("ReturnCodeLastAccessInError").": ".($db->lasterrno()?$db->lasterrno():$langs->trans("ErrorNoRequestInError"))."
\n";
- $out.="".$langs->trans("InformationLastAccessInError").": ".($db->lasterror()?$db->lasterror():$langs->trans("ErrorNoRequestInError"))."
\n";
- $out.="
\n";
- }
- else // Mode CLI
- {
- $out.='> '.$langs->transnoentities("DatabaseTypeManager").":\n".$db->type."\n";
- $out.='> '.$langs->transnoentities("RequestLastAccessInError").":\n".($db->lastqueryerror()?$db->lastqueryerror():$langs->trans("ErrorNoRequestInError"))."\n";
- $out.='> '.$langs->transnoentities("ReturnCodeLastAccessInError").":\n".($db->lasterrno()?$db->lasterrno():$langs->trans("ErrorNoRequestInError"))."\n";
- $out.='> '.$langs->transnoentities("InformationLastAccessInError").":\n".($db->lasterror()?$db->lasterror():$langs->trans("ErrorNoRequestInError"))."\n";
+ if (is_object($db))
+ {
+ if ($_SERVER['DOCUMENT_ROOT']) // Mode web
+ {
+ $out.="".$langs->trans("DatabaseTypeManager").": ".$db->type."
\n";
+ $out.="".$langs->trans("RequestLastAccessInError").": ".($db->lastqueryerror()?$db->lastqueryerror():$langs->trans("ErrorNoRequestInError"))."
\n";
+ $out.="".$langs->trans("ReturnCodeLastAccessInError").": ".($db->lasterrno()?$db->lasterrno():$langs->trans("ErrorNoRequestInError"))."
\n";
+ $out.="".$langs->trans("InformationLastAccessInError").": ".($db->lasterror()?$db->lasterror():$langs->trans("ErrorNoRequestInError"))."
\n";
+ $out.="
\n";
+ }
+ else // Mode CLI
+ {
+ $out.='> '.$langs->transnoentities("DatabaseTypeManager").":\n".$db->type."\n";
+ $out.='> '.$langs->transnoentities("RequestLastAccessInError").":\n".($db->lastqueryerror()?$db->lastqueryerror():$langs->trans("ErrorNoRequestInError"))."\n";
+ $out.='> '.$langs->transnoentities("ReturnCodeLastAccessInError").":\n".($db->lasterrno()?$db->lasterrno():$langs->trans("ErrorNoRequestInError"))."\n";
+ $out.='> '.$langs->transnoentities("InformationLastAccessInError").":\n".($db->lasterror()?$db->lasterror():$langs->trans("ErrorNoRequestInError"))."\n";
- }
- $syslog.=", sql=".$db->lastquery();
- $syslog.=", db_error=".$db->lasterror();
- }
+ }
+ $syslog.=", sql=".$db->lastquery();
+ $syslog.=", db_error=".$db->lasterror();
+ }
- if ($error)
- {
- $langs->load("errors");
+ if ($error)
+ {
+ $langs->load("errors");
- if (is_array($error)) $errors=$error;
- else $errors=array($error);
+ if (is_array($error)) $errors=$error;
+ else $errors=array($error);
- foreach($errors as $msg)
- {
- $msg=$langs->trans($msg);
- if ($_SERVER['DOCUMENT_ROOT']) // Mode web
- {
- $out.="".$langs->trans("Message").": ".$msg."
\n" ;
- }
- else // Mode CLI
- {
- $out.='> '.$langs->transnoentities("Message").":\n".$msg."\n" ;
- }
- $syslog.=", msg=".$msg;
- }
- }
- if (empty($dolibarr_main_prod) && $_SERVER['DOCUMENT_ROOT'] && function_exists('xdebug_print_function_stack') && function_exists('xdebug_call_file'))
- {
- xdebug_print_function_stack();
- $out.='XDebug informations:'."
\n";
- $out.='File: '.xdebug_call_file()."
\n";
- $out.='Line: '.xdebug_call_line()."
\n";
- $out.='Function: '.xdebug_call_function()."
\n";
- $out.="
\n";
- }
+ foreach($errors as $msg)
+ {
+ $msg=$langs->trans($msg);
+ if ($_SERVER['DOCUMENT_ROOT']) // Mode web
+ {
+ $out.="".$langs->trans("Message").": ".$msg."
\n" ;
+ }
+ else // Mode CLI
+ {
+ $out.='> '.$langs->transnoentities("Message").":\n".$msg."\n" ;
+ }
+ $syslog.=", msg=".$msg;
+ }
+ }
+ if (empty($dolibarr_main_prod) && $_SERVER['DOCUMENT_ROOT'] && function_exists('xdebug_print_function_stack') && function_exists('xdebug_call_file'))
+ {
+ xdebug_print_function_stack();
+ $out.='XDebug informations:'."
\n";
+ $out.='File: '.xdebug_call_file()."
\n";
+ $out.='Line: '.xdebug_call_line()."
\n";
+ $out.='Function: '.xdebug_call_function()."
\n";
+ $out.="
\n";
+ }
- if (empty($dolibarr_main_prod)) print $out;
- else define("MAIN_CORE_ERROR", 1);
- //else print 'Sorry, an error occured but the parameter $dolibarr_main_prod is defined in conf file so no message is reported to your browser. Please read the log file for error message.';
- dol_syslog("Error ".$syslog, LOG_ERR);
+ if (empty($dolibarr_main_prod)) print $out;
+ else define("MAIN_CORE_ERROR", 1);
+ //else print 'Sorry, an error occured but the parameter $dolibarr_main_prod is defined in conf file so no message is reported to your browser. Please read the log file for error message.';
+ dol_syslog("Error ".$syslog, LOG_ERR);
}
/**
@@ -2215,11 +2215,11 @@ function dol_print_error($db='',$error='')
*/
function dol_print_error_email()
{
- global $langs,$conf;
+ global $langs,$conf;
- $langs->load("errors");
- $now=dol_now();
- print '
'.$langs->trans("ErrorContactEMail",$conf->global->MAIN_INFO_SOCIETE_MAIL,'ERRORNEWPAYMENT'.dol_print_date($now,'%Y%m%d')).'
';
+ $langs->load("errors");
+ $now=dol_now();
+ print '
'.$langs->trans("ErrorContactEMail",$conf->global->MAIN_INFO_SOCIETE_MAIL,'ERRORNEWPAYMENT'.dol_print_date($now,'%Y%m%d')).'
';
}
/**
@@ -2256,59 +2256,59 @@ function print_liste_field_titre($name, $file="", $field="", $begin="", $morepar
*/
function getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="")
{
- global $conf;
- //print "$name, $file, $field, $begin, $options, $moreattrib, $sortfield, $sortorder
\n";
+ global $conf;
+ //print "$name, $file, $field, $begin, $options, $moreattrib, $sortfield, $sortorder
\n";
- $out='';
+ $out='';
// If field is used as sort criteria we use a specific class
- // Example if (sortfield,field)=("nom","xxx.nom") or (sortfield,field)=("nom","nom")
- if ($field && ($sortfield == $field || $sortfield == preg_replace("/^[^\.]+\./","",$field)))
- {
- $out.= '';
- }
- else
- {
- $out.= ' | ';
- }
- $out.=$name;
+ // Example if (sortfield,field)=("nom","xxx.nom") or (sortfield,field)=("nom","nom")
+ if ($field && ($sortfield == $field || $sortfield == preg_replace("/^[^\.]+\./","",$field)))
+ {
+ $out.= ' | ';
+ }
+ else
+ {
+ $out.= ' | ';
+ }
+ $out.=$name;
- if (empty($thead) && $field) // If this is a sort field
- {
- $options=preg_replace('/sortfield=([a-zA-Z0-9,\s\.]+)/i','',$moreparam);
- $options=preg_replace('/sortorder=([a-zA-Z0-9,\s\.]+)/i','',$options);
- $options=preg_replace('/&+/i','&',$options);
- if (! preg_match('/^&/',$options)) $options='&'.$options;
+ if (empty($thead) && $field) // If this is a sort field
+ {
+ $options=preg_replace('/sortfield=([a-zA-Z0-9,\s\.]+)/i','',$moreparam);
+ $options=preg_replace('/sortorder=([a-zA-Z0-9,\s\.]+)/i','',$options);
+ $options=preg_replace('/&+/i','&',$options);
+ if (! preg_match('/^&/',$options)) $options='&'.$options;
- //print " ";
- $out.= ' ';
- if (! $sortorder)
- {
- $out.= ''.img_down("A-Z",0).'';
- $out.= ''.img_up("Z-A",0).'';
- }
- else
- {
- if ($field != $sortfield)
- {
- $out.= ''.img_down("A-Z",0).'';
- $out.= ''.img_up("Z-A",0).'';
- }
- else {
- $sortorder=strtoupper($sortorder);
- if ($sortorder == 'DESC' ) {
- $out.= ''.img_down("A-Z",0).'';
- $out.= ''.img_up("Z-A",1).'';
- }
- if ($sortorder == 'ASC' ) {
- $out.= ''.img_down("A-Z",1).'';
- $out.= ''.img_up("Z-A",0).'';
- }
- }
- }
- }
- $out.=' | ';
+ //print " ";
+ $out.= '
';
+ if (! $sortorder)
+ {
+ $out.= ''.img_down("A-Z",0).'';
+ $out.= ''.img_up("Z-A",0).'';
+ }
+ else
+ {
+ if ($field != $sortfield)
+ {
+ $out.= ''.img_down("A-Z",0).'';
+ $out.= ''.img_up("Z-A",0).'';
+ }
+ else {
+ $sortorder=strtoupper($sortorder);
+ if ($sortorder == 'DESC' ) {
+ $out.= ''.img_down("A-Z",0).'';
+ $out.= ''.img_up("Z-A",1).'';
+ }
+ if ($sortorder == 'ASC' ) {
+ $out.= ''.img_down("A-Z",1).'';
+ $out.= ''.img_up("Z-A",0).'';
+ }
+ }
+ }
+ }
+ $out.='';
- return $out;
+ return $out;
}
/**
@@ -2319,7 +2319,7 @@ function getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $m
*/
function print_titre($title)
{
- print ''.$title.'
';
+ print ''.$title.'
';
}
/**
@@ -2334,7 +2334,7 @@ function print_titre($title)
*/
function print_fiche_titre($titre, $mesg='', $picto='title.png', $pictoisfullpath=0, $id='')
{
- print load_fiche_titre($titre, $mesg, $picto, $pictoisfullpath, $id);
+ print load_fiche_titre($titre, $mesg, $picto, $pictoisfullpath, $id);
}
/**
@@ -2349,26 +2349,26 @@ function print_fiche_titre($titre, $mesg='', $picto='title.png', $pictoisfullpat
*/
function load_fiche_titre($titre, $mesg='', $picto='title.png', $pictoisfullpath=0, $id='')
{
- global $conf;
+ global $conf;
- $return='';
+ $return='';
- if ($picto == 'setup') $picto='title.png';
- if (!empty($conf->browser->ie) && $picto=='title.png') $picto='title.gif';
+ if ($picto == 'setup') $picto='title.png';
+ if (!empty($conf->browser->ie) && $picto=='title.png') $picto='title.gif';
- $return.= "\n";
- $return.= '';
- if ($picto) $return.= '| '.img_picto('',$picto, 'id="pictotitle"', $pictoisfullpath).' | ';
- $return.= '';
- $return.= ' '.$titre.' ';
- $return.= ' | ';
- if (dol_strlen($mesg))
- {
- $return.= ''.$mesg.' | ';
- }
- $return.= '
'."\n";
+ $return.= "\n";
+ $return.= '';
+ if ($picto) $return.= '| '.img_picto('',$picto, 'id="pictotitle"', $pictoisfullpath).' | ';
+ $return.= '';
+ $return.= ' '.$titre.' ';
+ $return.= ' | ';
+ if (dol_strlen($mesg))
+ {
+ $return.= ''.$mesg.' | ';
+ }
+ $return.= '
'."\n";
- return $return;
+ return $return;
}
/**
@@ -2389,97 +2389,97 @@ function load_fiche_titre($titre, $mesg='', $picto='title.png', $pictoisfullpath
*/
function print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $center='', $num=-1, $totalnboflines=0, $picto='title.png', $pictoisfullpath=0)
{
- global $conf,$langs;
+ global $conf,$langs;
- if ($picto == 'setup') $picto='title.png';
- if (!empty($conf->browser->ie) && $picto=='title.png') $picto='title.gif';
+ if ($picto == 'setup') $picto='title.png';
+ if (!empty($conf->browser->ie) && $picto=='title.png') $picto='title.gif';
- if ($num > $conf->liste_limit or $num == -1)
- {
- $nextpage = 1;
- }
- else
- {
- $nextpage = 0;
- }
+ if ($num > $conf->liste_limit or $num == -1)
+ {
+ $nextpage = 1;
+ }
+ else
+ {
+ $nextpage = 0;
+ }
- print "\n";
- print "\n";
- print '';
+ print "\n";
+ print "\n";
+ print '';
- $pagelist = '';
+ $pagelist = '';
- // Left
- if ($page > 0 || $num > $conf->liste_limit)
- {
- if ($totalnboflines)
- {
- if ($picto && $titre) print '| '.img_picto('',$picto, '', $pictoisfullpath).' | ';
- print '';
- print ' '.$titre.' ';
- print ' | ';
+ // Left
+ if ($page > 0 || $num > $conf->liste_limit)
+ {
+ if ($totalnboflines)
+ {
+ if ($picto && $titre) print ''.img_picto('',$picto, '', $pictoisfullpath).' | ';
+ print '';
+ print ' '.$titre.' ';
+ print ' | ';
- $maxnbofpage=10;
+ $maxnbofpage=10;
- $nbpages=ceil($totalnboflines/$conf->liste_limit);
- $cpt=($page-$maxnbofpage);
- if ($cpt < 0) { $cpt=0; }
- $pagelist.=$langs->trans('Page');
- if ($cpt>=1)
- {
- $pagelist.=' 1';
- if ($cpt >= 2) $pagelist.=' ...';
- }
- do
- {
- if($cpt==$page)
- {
- $pagelist.= ' '.($page+1).'';
- }
- else
- {
- $pagelist.= ' '.($cpt+1).'';
- }
- $cpt++;
- }
- while ($cpt < $nbpages && $cpt<=$page+$maxnbofpage);
- if ($cpt<$nbpages)
- {
- if ($cpt<$nbpages-1) $pagelist.= ' ...';
- $pagelist.= ' '.$nbpages.'';
- }
- }
- else
- {
- if (empty($conf->browser->phone) && $picto && $titre) print ''.img_picto('',$picto, '', $pictoisfullpath).' | ';
- print '';
- print ' '.$titre.' ';
- $pagelist.= $langs->trans('Page').' '.($page+1);
- print ' | ';
- }
- }
- else
- {
- if (empty($conf->browser->phone) && $picto && $titre) print ''.img_picto('',$picto, '', $pictoisfullpath).' | ';
- print ''.$titre.' | ';
- }
+ $nbpages=ceil($totalnboflines/$conf->liste_limit);
+ $cpt=($page-$maxnbofpage);
+ if ($cpt < 0) { $cpt=0; }
+ $pagelist.=$langs->trans('Page');
+ if ($cpt>=1)
+ {
+ $pagelist.=' 1';
+ if ($cpt >= 2) $pagelist.=' ...';
+ }
+ do
+ {
+ if($cpt==$page)
+ {
+ $pagelist.= ' '.($page+1).'';
+ }
+ else
+ {
+ $pagelist.= ' '.($cpt+1).'';
+ }
+ $cpt++;
+ }
+ while ($cpt < $nbpages && $cpt<=$page+$maxnbofpage);
+ if ($cpt<$nbpages)
+ {
+ if ($cpt<$nbpages-1) $pagelist.= ' ...';
+ $pagelist.= ' '.$nbpages.'';
+ }
+ }
+ else
+ {
+ if (empty($conf->browser->phone) && $picto && $titre) print ''.img_picto('',$picto, '', $pictoisfullpath).' | ';
+ print '';
+ print ' '.$titre.' ';
+ $pagelist.= $langs->trans('Page').' '.($page+1);
+ print ' | ';
+ }
+ }
+ else
+ {
+ if (empty($conf->browser->phone) && $picto && $titre) print ''.img_picto('',$picto, '', $pictoisfullpath).' | ';
+ print ''.$titre.' | ';
+ }
- // Center
- if ($center)
- {
- print ''.$center.' | ';
- }
+ // Center
+ if ($center)
+ {
+ print ''.$center.' | ';
+ }
- // Right
- print '';
- if ($sortfield) $options .= "&sortfield=".$sortfield;
- if ($sortorder) $options .= "&sortorder=".$sortorder;
- // Affichage des fleches de navigation
- print_fleche_navigation($page,$file,$options,$nextpage,$pagelist);
- print ' | ';
+ // Right
+ print '';
+ if ($sortfield) $options .= "&sortfield=".$sortfield;
+ if ($sortorder) $options .= "&sortorder=".$sortorder;
+ // Affichage des fleches de navigation
+ print_fleche_navigation($page,$file,$options,$nextpage,$pagelist);
+ print ' | ';
- print '
'."\n";
- print "\n\n";
+ print '
'."\n";
+ print "\n\n";
}
/**
@@ -2494,16 +2494,16 @@ function print_barre_liste($titre, $page, $file, $options='', $sortfield='', $so
*/
function print_fleche_navigation($page,$file,$options='',$nextpage=0,$betweenarrows='')
{
- global $conf, $langs;
- if ($page > 0)
- {
- print ''.img_previous($langs->trans("Previous")).'';
- }
- if ($betweenarrows) print ($page > 0?' ':'').$betweenarrows.($nextpage>0?' ':'');
- if ($nextpage > 0)
- {
- print ''.img_next($langs->trans("Next")).'';
- }
+ global $conf, $langs;
+ if ($page > 0)
+ {
+ print ''.img_previous($langs->trans("Previous")).'';
+ }
+ if ($betweenarrows) print ($page > 0?' ':'').$betweenarrows.($nextpage>0?' ':'');
+ if ($nextpage > 0)
+ {
+ print ''.img_next($langs->trans("Next")).'';
+ }
}
@@ -2519,21 +2519,21 @@ function print_fleche_navigation($page,$file,$options='',$nextpage=0,$betweenarr
*/
function vatrate($rate,$addpercent=false,$info_bits=0,$usestarfornpr=0)
{
- // Test for compatibility
- if (preg_match('/%/',$rate))
- {
- $rate=str_replace('%','',$rate);
- $addpercent=true;
- }
- if (preg_match('/\*/',$rate) || preg_match('/'.constant('MAIN_LABEL_MENTION_NPR').'/i',$rate))
- {
- $rate=str_replace('*','',$rate);
- $info_bits |= 1;
- }
+ // Test for compatibility
+ if (preg_match('/%/',$rate))
+ {
+ $rate=str_replace('%','',$rate);
+ $addpercent=true;
+ }
+ if (preg_match('/\*/',$rate) || preg_match('/'.constant('MAIN_LABEL_MENTION_NPR').'/i',$rate))
+ {
+ $rate=str_replace('*','',$rate);
+ $info_bits |= 1;
+ }
- $ret=price($rate,0,'',0,0).($addpercent?'%':'');
- if ($info_bits & 1) $ret.=' '.($usestarfornpr?'*':constant('MAIN_LABEL_MENTION_NPR'));
- return $ret;
+ $ret=price($rate,0,'',0,0).($addpercent?'%':'');
+ if ($info_bits & 1) $ret.=' '.($usestarfornpr?'*':constant('MAIN_LABEL_MENTION_NPR'));
+ return $ret;
}
@@ -2553,62 +2553,62 @@ function vatrate($rate,$addpercent=false,$info_bits=0,$usestarfornpr=0)
*/
function price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1)
{
- global $langs,$conf;
+ global $langs,$conf;
- // Clean parameters
- if (empty($amount)) $amount=0; // To have a numeric value if amount not defined or = ''
- if ($rounding < 0) $rounding=min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
+ // Clean parameters
+ if (empty($amount)) $amount=0; // To have a numeric value if amount not defined or = ''
+ if ($rounding < 0) $rounding=min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
- $nbdecimal=$rounding;
+ $nbdecimal=$rounding;
- // Output separators by default (french)
- $dec=','; $thousand=' ';
+ // Output separators by default (french)
+ $dec=','; $thousand=' ';
- // If $outlangs not forced, we use use language
- if (! is_object($outlangs)) $outlangs=$langs;
+ // If $outlangs not forced, we use use language
+ if (! is_object($outlangs)) $outlangs=$langs;
- if ($outlangs->trans("SeparatorDecimal") != "SeparatorDecimal") $dec=$outlangs->trans("SeparatorDecimal");
- if ($outlangs->trans("SeparatorThousand")!= "SeparatorThousand") $thousand=$outlangs->trans("SeparatorThousand");
- if ($thousand == 'None') $thousand='';
- //print "amount=".$amount." html=".$form." trunc=".$trunc." nbdecimal=".$nbdecimal." dec='".$dec."' thousand='".$thousand."'
";
+ if ($outlangs->trans("SeparatorDecimal") != "SeparatorDecimal") $dec=$outlangs->trans("SeparatorDecimal");
+ if ($outlangs->trans("SeparatorThousand")!= "SeparatorThousand") $thousand=$outlangs->trans("SeparatorThousand");
+ if ($thousand == 'None') $thousand='';
+ //print "amount=".$amount." html=".$form." trunc=".$trunc." nbdecimal=".$nbdecimal." dec='".$dec."' thousand='".$thousand."'
";
- //print "amount=".$amount."-";
- $amount = str_replace(',','.',$amount); // should be useless
- //print $amount."-";
- $datas = explode('.',$amount);
- $decpart = isset($datas[1])?$datas[1]:'';
- $decpart = preg_replace('/0+$/i','',$decpart); // Supprime les 0 de fin de partie decimale
- //print "decpart=".$decpart."
";
- $end='';
+ //print "amount=".$amount."-";
+ $amount = str_replace(',','.',$amount); // should be useless
+ //print $amount."-";
+ $datas = explode('.',$amount);
+ $decpart = isset($datas[1])?$datas[1]:'';
+ $decpart = preg_replace('/0+$/i','',$decpart); // Supprime les 0 de fin de partie decimale
+ //print "decpart=".$decpart."
";
+ $end='';
- // We increase nbdecimal if there is more decimal than asked (to not loose information)
- if (dol_strlen($decpart) > $nbdecimal) $nbdecimal=dol_strlen($decpart);
- // Si on depasse max
- if ($trunc && $nbdecimal > $conf->global->MAIN_MAX_DECIMALS_SHOWN)
- {
- $nbdecimal=$conf->global->MAIN_MAX_DECIMALS_SHOWN;
- if (preg_match('/\.\.\./i',$conf->global->MAIN_MAX_DECIMALS_SHOWN))
- {
- // Si un affichage est tronque, on montre des ...
- $end='...';
- }
- }
+ // We increase nbdecimal if there is more decimal than asked (to not loose information)
+ if (dol_strlen($decpart) > $nbdecimal) $nbdecimal=dol_strlen($decpart);
+ // Si on depasse max
+ if ($trunc && $nbdecimal > $conf->global->MAIN_MAX_DECIMALS_SHOWN)
+ {
+ $nbdecimal=$conf->global->MAIN_MAX_DECIMALS_SHOWN;
+ if (preg_match('/\.\.\./i',$conf->global->MAIN_MAX_DECIMALS_SHOWN))
+ {
+ // Si un affichage est tronque, on montre des ...
+ $end='...';
+ }
+ }
- // If force rounding
- if ($forcerounding >= 0) $nbdecimal = $forcerounding;
+ // If force rounding
+ if ($forcerounding >= 0) $nbdecimal = $forcerounding;
- // Format number
- if ($form)
- {
- $output=preg_replace('/\s/',' ',number_format($amount, $nbdecimal, $dec, $thousand));
- }
- else
- {
- $output=number_format($amount, $nbdecimal, $dec, $thousand);
- }
- $output.=$end;
+ // Format number
+ if ($form)
+ {
+ $output=preg_replace('/\s/',' ',number_format($amount, $nbdecimal, $dec, $thousand));
+ }
+ else
+ {
+ $output=number_format($amount, $nbdecimal, $dec, $thousand);
+ }
+ $output.=$end;
- return $output;
+ return $output;
}
/**
@@ -2628,75 +2628,75 @@ function price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerou
*/
function price2num($amount,$rounding='',$alreadysqlnb=0)
{
- global $langs,$conf;
+ global $langs,$conf;
- // Round PHP function does not allow number like '1,234.56' nor '1.234,56' nor '1 234,56'
- // Numbers must be '1234.56'
- // Decimal delimiter for PHP and database SQL requests must be '.'
- $dec=','; $thousand=' ';
- if ($langs->trans("SeparatorDecimal") != "SeparatorDecimal") $dec=$langs->trans("SeparatorDecimal");
- if ($langs->trans("SeparatorThousand")!= "SeparatorThousand") $thousand=$langs->trans("SeparatorThousand");
- if ($thousand == 'None') $thousand='';
- //print "amount=".$amount." html=".$form." trunc=".$trunc." nbdecimal=".$nbdecimal." dec='".$dec."' thousand='".$thousand."'
";
+ // Round PHP function does not allow number like '1,234.56' nor '1.234,56' nor '1 234,56'
+ // Numbers must be '1234.56'
+ // Decimal delimiter for PHP and database SQL requests must be '.'
+ $dec=','; $thousand=' ';
+ if ($langs->trans("SeparatorDecimal") != "SeparatorDecimal") $dec=$langs->trans("SeparatorDecimal");
+ if ($langs->trans("SeparatorThousand")!= "SeparatorThousand") $thousand=$langs->trans("SeparatorThousand");
+ if ($thousand == 'None') $thousand='';
+ //print "amount=".$amount." html=".$form." trunc=".$trunc." nbdecimal=".$nbdecimal." dec='".$dec."' thousand='".$thousand."'
";
- // Convert value to universal number format (no thousand separator, '.' as decimal separator)
- if ($alreadysqlnb != 1) // If not a PHP number or unknown, we change format
- {
- //print 'PP'.$amount.' - '.$dec.' - '.$thousand.'
';
+ // Convert value to universal number format (no thousand separator, '.' as decimal separator)
+ if ($alreadysqlnb != 1) // If not a PHP number or unknown, we change format
+ {
+ //print 'PP'.$amount.' - '.$dec.' - '.$thousand.'
';
- // 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.
- if (is_numeric($amount))
- {
- // We put in temps value of decimal ("0.00001"). Works with 0 and 2.0E-5 and 9999.10
- $temps=sprintf("%0.10F",$amount-intval($amount)); // temps=0.0000000000 or 0.0000200000 or 9999.1000000000
- $temps=preg_replace('/([\.1-9])0+$/','\\1',$temps); // temps=0. or 0.00002 or 9999.1
- $nbofdec=max(0,dol_strlen($temps)-2); // -2 to remove "0."
- $amount=number_format($amount,$nbofdec,$dec,$thousand);
- }
- //print "QQ".$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.
+ if (is_numeric($amount))
+ {
+ // We put in temps value of decimal ("0.00001"). Works with 0 and 2.0E-5 and 9999.10
+ $temps=sprintf("%0.10F",$amount-intval($amount)); // temps=0.0000000000 or 0.0000200000 or 9999.1000000000
+ $temps=preg_replace('/([\.1-9])0+$/','\\1',$temps); // temps=0. or 0.00002 or 9999.1
+ $nbofdec=max(0,dol_strlen($temps)-2); // -2 to remove "0."
+ $amount=number_format($amount,$nbofdec,$dec,$thousand);
+ }
+ //print "QQ".$amount.'
';
- // Now make replace (the main goal of function)
- if ($thousand != ',' && $thousand != '.') $amount=str_replace(',','.',$amount); // To accept 2 notations for french users
- $amount=str_replace(' ','',$amount); // To avoid spaces
- $amount=str_replace($thousand,'',$amount); // Replace of thousand before replace of dec to avoid pb if thousand is .
- $amount=str_replace($dec,'.',$amount);
- }
+ // Now make replace (the main goal of function)
+ if ($thousand != ',' && $thousand != '.') $amount=str_replace(',','.',$amount); // To accept 2 notations for french users
+ $amount=str_replace(' ','',$amount); // To avoid spaces
+ $amount=str_replace($thousand,'',$amount); // Replace of thousand before replace of dec to avoid pb if thousand is .
+ $amount=str_replace($dec,'.',$amount);
+ }
- // Now, make a rounding if required
- if ($rounding)
- {
- $nbofdectoround='';
- if ($rounding == 'MU') $nbofdectoround=$conf->global->MAIN_MAX_DECIMALS_UNIT;
- elseif ($rounding == 'MT') $nbofdectoround=$conf->global->MAIN_MAX_DECIMALS_TOT;
- elseif ($rounding == 'MS') $nbofdectoround=$conf->global->MAIN_MAX_DECIMALS_SHOWN;
- elseif ($rounding == '2') $nbofdectoround=2; // For admin info page
- //print "RR".$amount.' - '.$nbofdectoround.'
';
- if (dol_strlen($nbofdectoround)) $amount = round($amount,$nbofdectoround); // $nbofdectoround can be 0.
- else return 'ErrorBadParameterProvidedToFunction';
- //print 'SS'.$amount.' - '.$nbofdec.' - '.$dec.' - '.$thousand.' - '.$nbofdectoround.'
';
+ // Now, make a rounding if required
+ if ($rounding)
+ {
+ $nbofdectoround='';
+ if ($rounding == 'MU') $nbofdectoround=$conf->global->MAIN_MAX_DECIMALS_UNIT;
+ elseif ($rounding == 'MT') $nbofdectoround=$conf->global->MAIN_MAX_DECIMALS_TOT;
+ elseif ($rounding == 'MS') $nbofdectoround=$conf->global->MAIN_MAX_DECIMALS_SHOWN;
+ elseif ($rounding == '2') $nbofdectoround=2; // For admin info page
+ //print "RR".$amount.' - '.$nbofdectoround.'
';
+ if (dol_strlen($nbofdectoround)) $amount = round($amount,$nbofdectoround); // $nbofdectoround can be 0.
+ else return 'ErrorBadParameterProvidedToFunction';
+ //print 'SS'.$amount.' - '.$nbofdec.' - '.$dec.' - '.$thousand.' - '.$nbofdectoround.'
';
- // 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 defined by 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
- $temps=sprintf("%0.10F",$amount-intval($amount)); // temps=0.0000000000 or 0.0000200000 or 9999.1000000000
- $temps=preg_replace('/([\.1-9])0+$/','\\1',$temps); // temps=0. or 0.00002 or 9999.1
- $nbofdec=max(0,dol_strlen($temps)-2); // -2 to remove "0."
- $amount=number_format($amount,min($nbofdec,$nbofdectoround),$dec,$thousand); // Convert amount to format with dolibarr dec and thousand
- }
- //print "TT".$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 defined by 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
+ $temps=sprintf("%0.10F",$amount-intval($amount)); // temps=0.0000000000 or 0.0000200000 or 9999.1000000000
+ $temps=preg_replace('/([\.1-9])0+$/','\\1',$temps); // temps=0. or 0.00002 or 9999.1
+ $nbofdec=max(0,dol_strlen($temps)-2); // -2 to remove "0."
+ $amount=number_format($amount,min($nbofdec,$nbofdectoround),$dec,$thousand); // Convert amount to format with dolibarr dec and thousand
+ }
+ //print "TT".$amount.'
';
- // Always make replace because each math function (like round) replace
- // with local values and we want a number that has a SQL string format x.y
- if ($thousand != ',' && $thousand != '.') $amount=str_replace(',','.',$amount); // To accept 2 notations for french users
- $amount=str_replace(' ','',$amount); // To avoid spaces
- $amount=str_replace($thousand,'',$amount); // Replace of thousand before replace of dec to avoid pb if thousand is .
- $amount=str_replace($dec,'.',$amount);
- }
+ // Always make replace because each math function (like round) replace
+ // with local values and we want a number that has a SQL string format x.y
+ if ($thousand != ',' && $thousand != '.') $amount=str_replace(',','.',$amount); // To accept 2 notations for french users
+ $amount=str_replace(' ','',$amount); // To avoid spaces
+ $amount=str_replace($thousand,'',$amount); // Replace of thousand before replace of dec to avoid pb if thousand is .
+ $amount=str_replace($dec,'.',$amount);
+ }
- return $amount;
+ return $amount;
}
/**
@@ -2709,35 +2709,35 @@ function price2num($amount,$rounding='',$alreadysqlnb=0)
*/
function get_localtax($tva, $local, $societe_acheteuse="")
{
- global $db, $conf, $mysoc;
+ global $db, $conf, $mysoc;
- if ($local == 1 && ! $mysoc->localtax1_assuj) return 0;
- if ($local == 2 && ! $mysoc->localtax2_assuj) return 0;
+ if ($local == 1 && ! $mysoc->localtax1_assuj) return 0;
+ if ($local == 2 && ! $mysoc->localtax2_assuj) return 0;
- $code_pays=$mysoc->pays_code;
+ $code_pays=$mysoc->pays_code;
- if (is_object($societe_acheteuse))
- {
- if ($code_pays!=$societe_acheteuse->pays_code) return 0;
- if ($local==1 && !$societe_acheteuse->localtax1_assuj) return 0;
- elseif ($local==2 && !$societe_acheteuse->localtax2_assuj) return 0;
- }
+ if (is_object($societe_acheteuse))
+ {
+ if ($code_pays!=$societe_acheteuse->pays_code) return 0;
+ if ($local==1 && !$societe_acheteuse->localtax1_assuj) return 0;
+ elseif ($local==2 && !$societe_acheteuse->localtax2_assuj) return 0;
+ }
- // Search local taxes
- $sql = "SELECT t.localtax1, t.localtax2";
- $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_pays as p";
- $sql .= " WHERE t.fk_pays = p.rowid AND p.code = '".$code_pays."'";
- $sql .= " AND t.taux = ".$tva." AND t.active = 1";
+ // Search local taxes
+ $sql = "SELECT t.localtax1, t.localtax2";
+ $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_pays as p";
+ $sql .= " WHERE t.fk_pays = p.rowid AND p.code = '".$code_pays."'";
+ $sql .= " AND t.taux = ".$tva." AND t.active = 1";
- $resql=$db->query($sql);
- if ($resql)
- {
- $obj = $db->fetch_object($resql);
- if ($local==1) return $obj->localtax1;
- elseif ($local==2) return $obj->localtax2;
- }
+ $resql=$db->query($sql);
+ if ($resql)
+ {
+ $obj = $db->fetch_object($resql);
+ if ($local==1) return $obj->localtax1;
+ elseif ($local==2) return $obj->localtax2;
+ }
- return 0;
+ return 0;
}
/**
@@ -2752,61 +2752,61 @@ function get_localtax($tva, $local, $societe_acheteuse="")
*/
function get_product_vat_for_country($idprod, $thirdparty_seller, $idprodfournprice=0)
{
- global $db,$mysoc;
+ global $db,$mysoc;
- $ret=0;
- $found=0;
+ $ret=0;
+ $found=0;
- if ($idprod > 0)
- {
- // Load product
- $product=new Product($db);
- $result=$product->fetch($idprod);
+ if ($idprod > 0)
+ {
+ // Load product
+ $product=new Product($db);
+ $result=$product->fetch($idprod);
- if ($mysoc->pays_code == $thirdparty_seller->country_code) // If selling country is ours
- {
- if ($idprodfournprice > 0) // We want vat for product for a supplier order or invoice
- {
- $product->get_buyprice($idprodfournprice,0,0,0);
- $ret=$product->vatrate_supplier;
- }
- else
- {
- $ret=$product->tva_tx; // Default vat of product we defined
- }
- $found=1;
- }
- else
- {
- // TODO Read default product vat according to countrycode and product
+ if ($mysoc->pays_code == $thirdparty_seller->country_code) // If selling country is ours
+ {
+ if ($idprodfournprice > 0) // We want vat for product for a supplier order or invoice
+ {
+ $product->get_buyprice($idprodfournprice,0,0,0);
+ $ret=$product->vatrate_supplier;
+ }
+ else
+ {
+ $ret=$product->tva_tx; // Default vat of product we defined
+ }
+ $found=1;
+ }
+ else
+ {
+ // TODO Read default product vat according to countrycode and product
- }
- }
+ }
+ }
- if (! $found)
- {
- // If vat of product for the country not found or not defined, we return higher vat of country.
- $sql = "SELECT taux as vat_rate";
- $sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_pays as p";
- $sql.= " WHERE t.active=1 AND t.fk_pays = p.rowid AND p.code='".$thirdparty_seller->country_code."'";
- $sql.= " ORDER BY t.taux DESC, t.recuperableonly ASC";
- $sql.= $db->plimit(1);
+ if (! $found)
+ {
+ // If vat of product for the country not found or not defined, we return higher vat of country.
+ $sql = "SELECT taux as vat_rate";
+ $sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_pays as p";
+ $sql.= " WHERE t.active=1 AND t.fk_pays = p.rowid AND p.code='".$thirdparty_seller->country_code."'";
+ $sql.= " ORDER BY t.taux DESC, t.recuperableonly ASC";
+ $sql.= $db->plimit(1);
- $resql=$db->query($sql);
- if ($resql)
- {
- $obj=$db->fetch_object($resql);
- if ($obj)
- {
- $ret=$obj->vat_rate;
- }
- }
- else dol_print_error($db);
- }
+ $resql=$db->query($sql);
+ if ($resql)
+ {
+ $obj=$db->fetch_object($resql);
+ if ($obj)
+ {
+ $ret=$obj->vat_rate;
+ }
+ }
+ else dol_print_error($db);
+ }
- dol_syslog("get_product_vat_for_country: ret=".$ret);
- return $ret;
+ dol_syslog("get_product_vat_for_country: ret=".$ret);
+ return $ret;
}
/**
@@ -2820,15 +2820,15 @@ function get_product_vat_for_country($idprod, $thirdparty_seller, $idprodfournpr
*/
function get_product_localtax_for_country($idprod, $local, $countrycode)
{
- global $db;
+ global $db;
- $product=new Product($db);
- $product->fetch($idprod);
+ $product=new Product($db);
+ $product->fetch($idprod);
- if ($local==1) return $product->localtax1_tx;
- elseif ($local==2) return $product->localtax2_tx;
+ if ($local==1) return $product->localtax1_tx;
+ elseif ($local==2) return $product->localtax2_tx;
- return -1;
+ return -1;
}
/**
@@ -2848,72 +2848,72 @@ function get_product_localtax_for_country($idprod, $local, $countrycode)
*/
function get_default_tva($societe_vendeuse, $societe_acheteuse, $idprod=0, $idprodfournprice=0)
{
- global $conf;
+ global $conf;
- if (!is_object($societe_vendeuse)) return -1;
- if (!is_object($societe_acheteuse)) return -1;
+ if (!is_object($societe_vendeuse)) return -1;
+ if (!is_object($societe_acheteuse)) return -1;
- dol_syslog("get_default_tva: seller use vat=".$societe_vendeuse->tva_assuj.", seller country=".$societe_vendeuse->pays_code.", seller in cee=".$societe_vendeuse->isInEEC().", buyer country=".$societe_acheteuse->pays_code.", buyer in cee=".$societe_acheteuse->isInEEC().", idprod=".$idprod.", idprodfournprice=".$idprodfournprice.", SERVICE_ARE_ECOMMERCE_200238EC=".(! empty($conf->global->SERVICES_ARE_ECOMMERCE_200238EC)?$conf->global->SERVICES_ARE_ECOMMERCE_200238EC:''));
+ dol_syslog("get_default_tva: seller use vat=".$societe_vendeuse->tva_assuj.", seller country=".$societe_vendeuse->pays_code.", seller in cee=".$societe_vendeuse->isInEEC().", buyer country=".$societe_acheteuse->pays_code.", buyer in cee=".$societe_acheteuse->isInEEC().", idprod=".$idprod.", idprodfournprice=".$idprodfournprice.", SERVICE_ARE_ECOMMERCE_200238EC=".(! empty($conf->global->SERVICES_ARE_ECOMMERCE_200238EC)?$conf->global->SERVICES_ARE_ECOMMERCE_200238EC:''));
- // Si vendeur non assujeti a TVA (tva_assuj vaut 0/1 ou franchise/reel)
- if (is_numeric($societe_vendeuse->tva_assuj) && ! $societe_vendeuse->tva_assuj)
- {
- //print 'VATRULE 1';
- return 0;
- }
- if (! is_numeric($societe_vendeuse->tva_assuj) && $societe_vendeuse->tva_assuj=='franchise')
- {
- //print 'VATRULE 2';
- return 0;
- }
+ // Si vendeur non assujeti a TVA (tva_assuj vaut 0/1 ou franchise/reel)
+ if (is_numeric($societe_vendeuse->tva_assuj) && ! $societe_vendeuse->tva_assuj)
+ {
+ //print 'VATRULE 1';
+ return 0;
+ }
+ if (! is_numeric($societe_vendeuse->tva_assuj) && $societe_vendeuse->tva_assuj=='franchise')
+ {
+ //print 'VATRULE 2';
+ return 0;
+ }
- //if (is_object($societe_acheteuse) && ($societe_vendeuse->country_id == $societe_acheteuse->country_id) && ($societe_acheteuse->tva_assuj == 1 || $societe_acheteuse->tva_assuj == 'reel'))
- // Le test ci-dessus ne devrait pas etre necessaire. Me signaler l'exemple du cas juridique concerne si le test suivant n'est pas suffisant.
+ //if (is_object($societe_acheteuse) && ($societe_vendeuse->country_id == $societe_acheteuse->country_id) && ($societe_acheteuse->tva_assuj == 1 || $societe_acheteuse->tva_assuj == 'reel'))
+ // Le test ci-dessus ne devrait pas etre necessaire. Me signaler l'exemple du cas juridique concerne si le test suivant n'est pas suffisant.
- // Si le (pays vendeur = pays acheteur) alors la TVA par defaut=TVA du produit vendu. Fin de regle.
- if (($societe_vendeuse->country_code == $societe_acheteuse->country_code)
- || (in_array($societe_vendeuse->country_code,array('FR,MC')) && in_array($societe_acheteuse->country_code,array('FR','MC')))) // Warning ->country_code not always defined
- {
- //print 'VATRULE 3';
- return get_product_vat_for_country($idprod,$societe_vendeuse,$idprodfournprice);
- }
+ // Si le (pays vendeur = pays acheteur) alors la TVA par defaut=TVA du produit vendu. Fin de regle.
+ if (($societe_vendeuse->country_code == $societe_acheteuse->country_code)
+ || (in_array($societe_vendeuse->country_code,array('FR,MC')) && in_array($societe_acheteuse->country_code,array('FR','MC')))) // Warning ->country_code not always defined
+ {
+ //print 'VATRULE 3';
+ return get_product_vat_for_country($idprod,$societe_vendeuse,$idprodfournprice);
+ }
- // Si (vendeur et acheteur dans Communaute europeenne) et (bien vendu = moyen de transports neuf comme auto, bateau, avion) alors TVA par defaut=0 (La TVA doit etre paye par l'acheteur au centre d'impots de son pays et non au vendeur). Fin de regle.
- // Non gere
+ // Si (vendeur et acheteur dans Communaute europeenne) et (bien vendu = moyen de transports neuf comme auto, bateau, avion) alors TVA par defaut=0 (La TVA doit etre paye par l'acheteur au centre d'impots de son pays et non au vendeur). Fin de regle.
+ // Non gere
- // Si (vendeur et acheteur dans Communaute europeenne) et (acheteur = entreprise) alors TVA par defaut=0. Fin de regle
- // Si (vendeur et acheteur dans Communaute europeenne) et (acheteur = particulier) alors TVA par defaut=TVA du produit vendu. Fin de regle
- if (($societe_vendeuse->isInEEC() && $societe_acheteuse->isInEEC()))
- {
- $isacompany=$societe_acheteuse->isACompany();
- if ($isacompany)
- {
- //print 'VATRULE 4';
- return 0;
- }
- else
- {
- //print 'VATRULE 5';
- return get_product_vat_for_country($idprod,$societe_vendeuse,$idprodfournprice);
- }
- }
+ // Si (vendeur et acheteur dans Communaute europeenne) et (acheteur = entreprise) alors TVA par defaut=0. Fin de regle
+ // Si (vendeur et acheteur dans Communaute europeenne) et (acheteur = particulier) alors TVA par defaut=TVA du produit vendu. Fin de regle
+ if (($societe_vendeuse->isInEEC() && $societe_acheteuse->isInEEC()))
+ {
+ $isacompany=$societe_acheteuse->isACompany();
+ if ($isacompany)
+ {
+ //print 'VATRULE 4';
+ return 0;
+ }
+ else
+ {
+ //print 'VATRULE 5';
+ return get_product_vat_for_country($idprod,$societe_vendeuse,$idprodfournprice);
+ }
+ }
- // If services are eServices according to EU Council Directive 2002/38/EC (ec.europa.eu/taxation_customs/taxation/v.../article_1610_en.htm)
- // we use the buyer VAT.
- if (! empty($conf->global->SERVICE_ARE_ECOMMERCE_200238EC))
- {
- //print "eee".$societe_acheteuse->isACompany();exit;
- if (! $societe_vendeuse->isInEEC() && $societe_acheteuse->isInEEC() && ! $societe_acheteuse->isACompany())
- {
- //print 'VATRULE 6';
- return get_product_vat_for_country($idprod,$societe_acheteuse,$idprodfournprice);
- }
- }
+ // If services are eServices according to EU Council Directive 2002/38/EC (ec.europa.eu/taxation_customs/taxation/v.../article_1610_en.htm)
+ // we use the buyer VAT.
+ if (! empty($conf->global->SERVICE_ARE_ECOMMERCE_200238EC))
+ {
+ //print "eee".$societe_acheteuse->isACompany();exit;
+ if (! $societe_vendeuse->isInEEC() && $societe_acheteuse->isInEEC() && ! $societe_acheteuse->isACompany())
+ {
+ //print 'VATRULE 6';
+ return get_product_vat_for_country($idprod,$societe_acheteuse,$idprodfournprice);
+ }
+ }
- // Sinon la TVA proposee par defaut=0. Fin de regle.
- // Rem: Cela signifie qu'au moins un des 2 est hors Communaute europeenne et que le pays differe
- //print 'VATRULE 7';
- return 0;
+ // Sinon la TVA proposee par defaut=0. Fin de regle.
+ // Rem: Cela signifie qu'au moins un des 2 est hors Communaute europeenne et que le pays differe
+ //print 'VATRULE 7';
+ return 0;
}
@@ -2927,7 +2927,7 @@ function get_default_tva($societe_vendeuse, $societe_acheteuse, $idprod=0, $idpr
*/
function get_default_npr($societe_vendeuse, $societe_acheteuse, $idprod)
{
- return 0;
+ return 0;
}
/**
@@ -2941,28 +2941,28 @@ function get_default_npr($societe_vendeuse, $societe_acheteuse, $idprod)
*/
function get_default_localtax($societe_vendeuse, $societe_acheteuse, $local, $idprod=0)
{
- if (!is_object($societe_vendeuse)) return -1;
- if (!is_object($societe_acheteuse)) return -1;
+ if (!is_object($societe_vendeuse)) return -1;
+ if (!is_object($societe_acheteuse)) return -1;
- if ($societe_vendeuse->country_id=='ES' || $societe_vendeuse->country_code=='ES')
- {
- if ($local==1) //RE
- {
- // Si achatteur non assujeti a RE, localtax1 par default=0
- if (is_numeric($societe_acheteuse->localtax1_assuj) && ! $societe_acheteuse->localtax1_assuj) return 0;
- if (! is_numeric($societe_acheteuse->localtax1_assuj) && $societe_acheteuse->localtax1_assuj=='localtax1off') return 0;
- }
- elseif ($local==2) //IRPF
- {
- // Si vendeur non assujeti a IRPF, localtax2 par default=0
- if (is_numeric($societe_vendeuse->localtax2_assuj) && ! $societe_vendeuse->localtax2_assuj) return 0;
- if (! is_numeric($societe_vendeuse->localtax2_assuj) && $societe_vendeuse->localtax2_assuj=='localtax2off') return 0;
- } else return -1;
+ if ($societe_vendeuse->country_id=='ES' || $societe_vendeuse->country_code=='ES')
+ {
+ if ($local==1) //RE
+ {
+ // Si achatteur non assujeti a RE, localtax1 par default=0
+ if (is_numeric($societe_acheteuse->localtax1_assuj) && ! $societe_acheteuse->localtax1_assuj) return 0;
+ if (! is_numeric($societe_acheteuse->localtax1_assuj) && $societe_acheteuse->localtax1_assuj=='localtax1off') return 0;
+ }
+ elseif ($local==2) //IRPF
+ {
+ // Si vendeur non assujeti a IRPF, localtax2 par default=0
+ if (is_numeric($societe_vendeuse->localtax2_assuj) && ! $societe_vendeuse->localtax2_assuj) return 0;
+ if (! is_numeric($societe_vendeuse->localtax2_assuj) && $societe_vendeuse->localtax2_assuj=='localtax2off') return 0;
+ } else return -1;
- if ($idprod) return get_product_localtax_for_country($idprod, $local, $societe_vendeuse->country_code);
- else return -1;
- }
- return 0;
+ if ($idprod) return get_product_localtax_for_country($idprod, $local, $societe_vendeuse->country_code);
+ else return -1;
+ }
+ return 0;
}
/**
@@ -2975,21 +2975,21 @@ function get_default_localtax($societe_vendeuse, $societe_acheteuse, $local, $id
*/
function yn($yesno, $case=1, $color=0)
{
- global $langs;
- $result='unknown';
- if ($yesno == 1 || strtolower($yesno) == 'yes' || strtolower($yesno) == 'true') // A mettre avant test sur no a cause du == 0
- {
- $result=($case?$langs->trans("Yes"):$langs->trans("yes"));
- $classname='ok';
- }
- elseif ($yesno == 0 || strtolower($yesno) == 'no' || strtolower($yesno) == 'false')
- {
- $result=($case?$langs->trans("No"):$langs->trans("no"));
- if ($color == 2) $classname='ok';
- else $classname='error';
- }
- if ($color) return ''.$result.'';
- return $result;
+ global $langs;
+ $result='unknown';
+ if ($yesno == 1 || strtolower($yesno) == 'yes' || strtolower($yesno) == 'true') // A mettre avant test sur no a cause du == 0
+ {
+ $result=($case?$langs->trans("Yes"):$langs->trans("yes"));
+ $classname='ok';
+ }
+ elseif ($yesno == 0 || strtolower($yesno) == 'no' || strtolower($yesno) == 'false')
+ {
+ $result=($case?$langs->trans("No"):$langs->trans("no"));
+ if ($color == 2) $classname='ok';
+ else $classname='error';
+ }
+ if ($color) return ''.$result.'';
+ return $result;
}
@@ -3006,15 +3006,15 @@ function yn($yesno, $case=1, $color=0)
*/
function get_exdir($num,$level=3,$alpha=0,$withoutslash=0)
{
- $path = '';
- if (empty($alpha)) $num = preg_replace('/([^0-9])/i','',$num);
- else $num = preg_replace('/^.*\-/i','',$num);
- $num = substr("000".$num, -$level);
- if ($level == 1) $path = substr($num,0,1);
- if ($level == 2) $path = substr($num,1,1).'/'.substr($num,0,1);
- if ($level == 3) $path = substr($num,2,1).'/'.substr($num,1,1).'/'.substr($num,0,1);
- if (empty($withoutslash)) $path.='/';
- return $path;
+ $path = '';
+ if (empty($alpha)) $num = preg_replace('/([^0-9])/i','',$num);
+ else $num = preg_replace('/^.*\-/i','',$num);
+ $num = substr("000".$num, -$level);
+ if ($level == 1) $path = substr($num,0,1);
+ if ($level == 2) $path = substr($num,1,1).'/'.substr($num,0,1);
+ if ($level == 3) $path = substr($num,2,1).'/'.substr($num,1,1).'/'.substr($num,0,1);
+ if (empty($withoutslash)) $path.='/';
+ return $path;
}
/**
@@ -3025,58 +3025,58 @@ function get_exdir($num,$level=3,$alpha=0,$withoutslash=0)
*/
function dol_mkdir($dir)
{
- global $conf;
+ global $conf;
- dol_syslog("functions.lib::dol_mkdir: dir=".$dir,LOG_INFO);
+ dol_syslog("functions.lib::dol_mkdir: dir=".$dir,LOG_INFO);
- $dir_osencoded=dol_osencode($dir);
- if (@is_dir($dir_osencoded)) return 0;
+ $dir_osencoded=dol_osencode($dir);
+ if (@is_dir($dir_osencoded)) return 0;
- $nberr=0;
- $nbcreated=0;
+ $nberr=0;
+ $nbcreated=0;
- $ccdir = '';
- $cdir = explode("/",$dir);
- $num=count($cdir);
- for ($i = 0; $i < $num; $i++)
- {
- if ($i > 0) $ccdir .= '/'.$cdir[$i];
- else $ccdir = $cdir[$i];
- if (preg_match("/^.:$/",$ccdir,$regs)) continue; // Si chemin Windows incomplet, on poursuit par rep suivant
+ $ccdir = '';
+ $cdir = explode("/",$dir);
+ $num=count($cdir);
+ for ($i = 0; $i < $num; $i++)
+ {
+ if ($i > 0) $ccdir .= '/'.$cdir[$i];
+ else $ccdir = $cdir[$i];
+ if (preg_match("/^.:$/",$ccdir,$regs)) continue; // Si chemin Windows incomplet, on poursuit par rep suivant
- // Attention, le is_dir() peut echouer bien que le rep existe.
- // (ex selon config de open_basedir)
- if ($ccdir)
- {
- $ccdir_osencoded=dol_osencode($ccdir);
- if (! @is_dir($ccdir_osencoded))
- {
- dol_syslog("functions.lib::dol_mkdir: Directory '".$ccdir."' does not exists or is outside open_basedir PHP setting.",LOG_DEBUG);
+ // Attention, le is_dir() peut echouer bien que le rep existe.
+ // (ex selon config de open_basedir)
+ if ($ccdir)
+ {
+ $ccdir_osencoded=dol_osencode($ccdir);
+ if (! @is_dir($ccdir_osencoded))
+ {
+ dol_syslog("functions.lib::dol_mkdir: Directory '".$ccdir."' does not exists or is outside open_basedir PHP setting.",LOG_DEBUG);
- umask(0);
- $dirmaskdec=octdec('0755');
- if (! empty($conf->global->MAIN_UMASK)) $dirmaskdec=octdec($conf->global->MAIN_UMASK);
- $dirmaskdec |= octdec('0111'); // Set x bit required for directories
- if (! @mkdir($ccdir_osencoded, $dirmaskdec))
- {
- // Si le is_dir a renvoye une fausse info, alors on passe ici.
- dol_syslog("functions.lib::dol_mkdir: Fails to create directory '".$ccdir."' or directory already exists.",LOG_WARNING);
- $nberr++;
- }
- else
- {
- dol_syslog("functions.lib::dol_mkdir: Directory '".$ccdir."' created",LOG_DEBUG);
- $nberr=0; // On remet a zero car si on arrive ici, cela veut dire que les echecs precedents peuvent etre ignore
- $nbcreated++;
- }
- }
- else
- {
- $nberr=0; // On remet a zero car si on arrive ici, cela veut dire que les echecs precedents peuvent etre ignores
- }
- }
- }
- return ($nberr ? -$nberr : $nbcreated);
+ umask(0);
+ $dirmaskdec=octdec('0755');
+ if (! empty($conf->global->MAIN_UMASK)) $dirmaskdec=octdec($conf->global->MAIN_UMASK);
+ $dirmaskdec |= octdec('0111'); // Set x bit required for directories
+ if (! @mkdir($ccdir_osencoded, $dirmaskdec))
+ {
+ // Si le is_dir a renvoye une fausse info, alors on passe ici.
+ dol_syslog("functions.lib::dol_mkdir: Fails to create directory '".$ccdir."' or directory already exists.",LOG_WARNING);
+ $nberr++;
+ }
+ else
+ {
+ dol_syslog("functions.lib::dol_mkdir: Directory '".$ccdir."' created",LOG_DEBUG);
+ $nberr=0; // On remet a zero car si on arrive ici, cela veut dire que les echecs precedents peuvent etre ignore
+ $nbcreated++;
+ }
+ }
+ else
+ {
+ $nberr=0; // On remet a zero car si on arrive ici, cela veut dire que les echecs precedents peuvent etre ignores
+ }
+ }
+ }
+ return ($nberr ? -$nberr : $nbcreated);
}
@@ -3087,7 +3087,7 @@ function dol_mkdir($dir)
*/
function picto_required()
{
- return '*';
+ return '*';
}
@@ -3101,20 +3101,20 @@ function picto_required()
*/
function dol_string_nohtmltag($StringHtml,$removelinefeed=1,$pagecodeto='UTF-8')
{
- $pattern = "/<[^>]+>/";
- $temp = dol_html_entity_decode($StringHtml,ENT_COMPAT,$pagecodeto);
- $temp = preg_replace($pattern,"",$temp);
+ $pattern = "/<[^>]+>/";
+ $temp = dol_html_entity_decode($StringHtml,ENT_COMPAT,$pagecodeto);
+ $temp = preg_replace($pattern,"",$temp);
- // Supprime aussi les retours
- if ($removelinefeed) $temp=str_replace(array("\r\n","\r","\n")," ",$temp);
+ // Supprime aussi les retours
+ if ($removelinefeed) $temp=str_replace(array("\r\n","\r","\n")," ",$temp);
- // et les espaces doubles
- while(strpos($temp," "))
- {
- $temp = str_replace(" "," ",$temp);
- }
- $CleanString = trim($temp);
- return $CleanString;
+ // et les espaces doubles
+ while(strpos($temp," "))
+ {
+ $temp = str_replace(" "," ",$temp);
+ }
+ $CleanString = trim($temp);
+ return $CleanString;
}
@@ -3128,17 +3128,17 @@ function dol_string_nohtmltag($StringHtml,$removelinefeed=1,$pagecodeto='UTF-8')
*/
function dol_nl2br($stringtoencode,$nl2brmode=0,$forxml=false)
{
- if (! $nl2brmode)
- {
- // We use @ to avoid warning on PHP4 that does not support entity encoding from UTF8;
- if (version_compare(PHP_VERSION, '5.3.0') < 0) return @nl2br($stringtoencode);
- else return @nl2br($stringtoencode,$forxml);
- }
- else
- {
- $ret=preg_replace('/(\r\n|\r|\n)/i',($forxml?'
':'
'),$stringtoencode);
- return $ret;
- }
+ if (! $nl2brmode)
+ {
+ // We use @ to avoid warning on PHP4 that does not support entity encoding from UTF8;
+ if (version_compare(PHP_VERSION, '5.3.0') < 0) return @nl2br($stringtoencode);
+ else return @nl2br($stringtoencode,$forxml);
+ }
+ else
+ {
+ $ret=preg_replace('/(\r\n|\r|\n)/i',($forxml?'
':'
'),$stringtoencode);
+ return $ret;
+ }
}
/**
@@ -3159,23 +3159,23 @@ function dol_nl2br($stringtoencode,$nl2brmode=0,$forxml=false)
*/
function dol_htmlentitiesbr($stringtoencode,$nl2brmode=0,$pagecodefrom='UTF-8')
{
- if (dol_textishtml($stringtoencode))
- {
- $newstring=$stringtoencode;
- $newstring=preg_replace('/
/i','
',$newstring); // Replace "
" by "
". It's same and avoid pb with FPDF.
- $newstring=preg_replace('/
$/i','',$newstring); // Remove last
- $newstring=strtr($newstring,array('&'=>'__and__','<'=>'__lt__','>'=>'__gt__','"'=>'__dquot__'));
- $newstring=dol_htmlentities($newstring,ENT_COMPAT,$pagecodefrom); // Make entity encoding
- $newstring=strtr($newstring,array('__and__'=>'&','__lt__'=>'<','__gt__'=>'>','__dquot__'=>'"'));
- //$newstring=strtr($newstring,array('__li__'=>"\n")); // Restore \n
- }
- else
- {
- $newstring=dol_nl2br(dol_htmlentities($stringtoencode,ENT_COMPAT,$pagecodefrom),$nl2brmode);
- }
- // Other substitutions that htmlentities does not do
- //$newstring=str_replace(chr(128),'€',$newstring); // 128 = 0x80. Not in html entity table. // Seems useles with TCPDF. Make bug with UTF8 languages
- return $newstring;
+ if (dol_textishtml($stringtoencode))
+ {
+ $newstring=$stringtoencode;
+ $newstring=preg_replace('/
/i','
',$newstring); // Replace "
" by "
". It's same and avoid pb with FPDF.
+ $newstring=preg_replace('/
$/i','',$newstring); // Remove last
+ $newstring=strtr($newstring,array('&'=>'__and__','<'=>'__lt__','>'=>'__gt__','"'=>'__dquot__'));
+ $newstring=dol_htmlentities($newstring,ENT_COMPAT,$pagecodefrom); // Make entity encoding
+ $newstring=strtr($newstring,array('__and__'=>'&','__lt__'=>'<','__gt__'=>'>','__dquot__'=>'"'));
+ //$newstring=strtr($newstring,array('__li__'=>"\n")); // Restore \n
+ }
+ else
+ {
+ $newstring=dol_nl2br(dol_htmlentities($stringtoencode,ENT_COMPAT,$pagecodefrom),$nl2brmode);
+ }
+ // Other substitutions that htmlentities does not do
+ //$newstring=str_replace(chr(128),'€',$newstring); // 128 = 0x80. Not in html entity table. // Seems useles with TCPDF. Make bug with UTF8 languages
+ return $newstring;
}
/**
@@ -3187,12 +3187,12 @@ function dol_htmlentitiesbr($stringtoencode,$nl2brmode=0,$pagecodefrom='UTF-8')
*/
function dol_htmlentitiesbr_decode($stringtodecode,$pagecodeto='UTF-8')
{
- $ret=dol_html_entity_decode($stringtodecode,ENT_COMPAT,$pagecodeto);
- $ret=preg_replace('/'."\r\n".'
/i',"
",$ret);
- $ret=preg_replace('/
'."\r\n".'/i',"\r\n",$ret);
- $ret=preg_replace('/
'."\n".'/i',"\n",$ret);
- $ret=preg_replace('/
/i',"\n",$ret);
- return $ret;
+ $ret=dol_html_entity_decode($stringtodecode,ENT_COMPAT,$pagecodeto);
+ $ret=preg_replace('/'."\r\n".'
/i',"
",$ret);
+ $ret=preg_replace('/
'."\r\n".'/i',"\r\n",$ret);
+ $ret=preg_replace('/
'."\n".'/i',"\n",$ret);
+ $ret=preg_replace('/
/i',"\n",$ret);
+ return $ret;
}
/**
@@ -3203,8 +3203,8 @@ function dol_htmlentitiesbr_decode($stringtodecode,$pagecodeto='UTF-8')
*/
function dol_htmlcleanlastbr($stringtodecode)
{
- $ret=preg_replace('/(
|
|'."\n".'|'."\r".')+$/i',"",$stringtodecode);
- return $ret;
+ $ret=preg_replace('/(
|
|'."\n".'|'."\r".')+$/i',"",$stringtodecode);
+ return $ret;
}
/**
@@ -3217,9 +3217,9 @@ function dol_htmlcleanlastbr($stringtodecode)
*/
function dol_html_entity_decode($a,$b,$c='UTF-8')
{
- // We use @ to avoid warning on PHP4 that does not support entity decoding to UTF8;
- $ret=@html_entity_decode($a,$b,$c);
- return $ret;
+ // We use @ to avoid warning on PHP4 that does not support entity decoding to UTF8;
+ $ret=@html_entity_decode($a,$b,$c);
+ return $ret;
}
/**
@@ -3232,9 +3232,9 @@ function dol_html_entity_decode($a,$b,$c='UTF-8')
*/
function dol_htmlentities($a,$b,$c='UTF-8')
{
- // We use @ to avoid warning on PHP4 that does not support entity decoding to UTF8;
- $ret=@htmlentities($a,$b,$c);
- return $ret;
+ // We use @ to avoid warning on PHP4 that does not support entity decoding to UTF8;
+ $ret=@htmlentities($a,$b,$c);
+ return $ret;
}
@@ -3248,16 +3248,16 @@ function dol_htmlentities($a,$b,$c='UTF-8')
*/
function dol_string_is_good_iso($s)
{
- $len=dol_strlen($s);
- $ok=1;
- for($scursor=0;$scursor<$len;$scursor++)
- {
- $ordchar=ord($s{$scursor});
- //print $scursor.'-'.$ordchar.'
';
- if ($ordchar < 32 && $ordchar != 13 && $ordchar != 10) { $ok=0; break; }
- if ($ordchar > 126 && $ordchar < 160) { $ok=0; break; }
- }
- return $ok;
+ $len=dol_strlen($s);
+ $ok=1;
+ for($scursor=0;$scursor<$len;$scursor++)
+ {
+ $ordchar=ord($s{$scursor});
+ //print $scursor.'-'.$ordchar.'
';
+ if ($ordchar < 32 && $ordchar != 13 && $ordchar != 10) { $ok=0; break; }
+ if ($ordchar > 126 && $ordchar < 160) { $ok=0; break; }
+ }
+ return $ok;
}
@@ -3270,11 +3270,11 @@ function dol_string_is_good_iso($s)
*/
function dol_nboflines($s,$maxchar=0)
{
- if ($s == '') return 0;
- $arraystring=explode("\n",$s);
- $nb=count($arraystring);
+ if ($s == '') return 0;
+ $arraystring=explode("\n",$s);
+ $nb=count($arraystring);
- return $nb;
+ return $nb;
}
@@ -3288,33 +3288,33 @@ function dol_nboflines($s,$maxchar=0)
*/
function dol_nboflines_bis($text,$maxlinesize=0,$charset='UTF-8')
{
- $repTable = array("\t" => " ", "\n" => "
", "\r" => " ", "\0" => " ", "\x0B" => " ");
- if (dol_textishtml($text)) $repTable = array("\t" => " ", "\n" => " ", "\r" => " ", "\0" => " ", "\x0B" => " ");
+ $repTable = array("\t" => " ", "\n" => "
", "\r" => " ", "\0" => " ", "\x0B" => " ");
+ if (dol_textishtml($text)) $repTable = array("\t" => " ", "\n" => " ", "\r" => " ", "\0" => " ", "\x0B" => " ");
- $text = strtr($text, $repTable);
- if ($charset == 'UTF-8') { $pattern = '/(
]*>)/Uu'; } // /U is to have UNGREEDY regex to limit to one html tag. /u is for UTF8 support
- else $pattern = '/(
]*>)/U'; // /U is to have UNGREEDY regex to limit to one html tag.
- $a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
+ $text = strtr($text, $repTable);
+ if ($charset == 'UTF-8') { $pattern = '/(
]*>)/Uu'; } // /U is to have UNGREEDY regex to limit to one html tag. /u is for UTF8 support
+ else $pattern = '/(
]*>)/U'; // /U is to have UNGREEDY regex to limit to one html tag.
+ $a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
- $nblines = floor((count($a)+1)/2);
- // count possible auto line breaks
- if($maxlinesize)
- {
- foreach ($a as $line)
- {
- if (dol_strlen($line)>$maxlinesize)
- {
- //$line_dec = html_entity_decode(strip_tags($line));
- $line_dec = html_entity_decode($line);
- if(dol_strlen($line_dec)>$maxlinesize)
- {
- $line_dec=wordwrap($line_dec,$maxlinesize,'\n',true);
- $nblines+=substr_count($line_dec,'\n');
- }
- }
- }
- }
- return $nblines;
+ $nblines = floor((count($a)+1)/2);
+ // count possible auto line breaks
+ if($maxlinesize)
+ {
+ foreach ($a as $line)
+ {
+ if (dol_strlen($line)>$maxlinesize)
+ {
+ //$line_dec = html_entity_decode(strip_tags($line));
+ $line_dec = html_entity_decode($line);
+ if(dol_strlen($line_dec)>$maxlinesize)
+ {
+ $line_dec=wordwrap($line_dec,$maxlinesize,'\n',true);
+ $nblines+=substr_count($line_dec,'\n');
+ }
+ }
+ }
+ }
+ return $nblines;
}
/**
@@ -3324,8 +3324,8 @@ function dol_nboflines_bis($text,$maxlinesize=0,$charset='UTF-8')
*/
function dol_microtime_float()
{
- list($usec, $sec) = explode(" ", microtime());
- return ((float) $usec + (float) $sec);
+ list($usec, $sec) = explode(" ", microtime());
+ return ((float) $usec + (float) $sec);
}
/**
@@ -3337,31 +3337,31 @@ function dol_microtime_float()
*/
function dol_textishtml($msg,$option=0)
{
- if ($option == 1)
- {
- if (preg_match('//i',$msg)) return true;
- elseif (preg_match('//i',$msg)) return true;
- elseif (preg_match('/&[A-Z0-9]{1,6};/i',$msg)) return true; // Html entities names (http://www.w3schools.com/tags/ref_entities.asp)
- elseif (preg_match('/[0-9]{2,3};/i',$msg)) return true; // Html entities numbers (http://www.w3schools.com/tags/ref_entities.asp)
- return false;
- }
+ if ($option == 1)
+ {
+ if (preg_match('//i',$msg)) return true;
+ elseif (preg_match('//i',$msg)) return true;
+ elseif (preg_match('/&[A-Z0-9]{1,6};/i',$msg)) return true; // Html entities names (http://www.w3schools.com/tags/ref_entities.asp)
+ elseif (preg_match('/[0-9]{2,3};/i',$msg)) return true; // Html entities numbers (http://www.w3schools.com/tags/ref_entities.asp)
+ return false;
+ }
}
/**
@@ -3377,14 +3377,14 @@ function dol_textishtml($msg,$option=0)
*/
function make_substitutions($chaine,$substitutionarray)
{
- if (! is_array($substitutionarray)) return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions';
+ if (! is_array($substitutionarray)) return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions';
- // Make substitition
- foreach ($substitutionarray as $key => $value)
- {
- $chaine=str_replace("$key","$value",$chaine); // We must keep the " to work when value is 123.5 for example
- }
- return $chaine;
+ // Make substitition
+ foreach ($substitutionarray as $key => $value)
+ {
+ $chaine=str_replace("$key","$value",$chaine); // We must keep the " to work when value is 123.5 for example
+ }
+ return $chaine;
}
/**
@@ -3398,34 +3398,34 @@ function make_substitutions($chaine,$substitutionarray)
*/
function complete_substitutions_array(&$substitutionarray,$outputlangs,$object='')
{
- global $conf,$user;
+ global $conf,$user;
- require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
+ require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
- // Check if there is external substitution to do asked by plugins
- $dirsubstitutions=array_merge(array(),(array) $conf->modules_parts['substitutions']);
+ // Check if there is external substitution to do asked by plugins
+ $dirsubstitutions=array_merge(array(),(array) $conf->modules_parts['substitutions']);
- foreach($dirsubstitutions as $reldir)
- {
- $dir=dol_buildpath($reldir,0);
+ foreach($dirsubstitutions as $reldir)
+ {
+ $dir=dol_buildpath($reldir,0);
- // Check if directory exists
- if (! dol_is_dir($dir)) continue;
+ // Check if directory exists
+ if (! dol_is_dir($dir)) continue;
- $substitfiles=dol_dir_list($dir,'files',0,'functions_');
- foreach($substitfiles as $substitfile)
- {
- if (preg_match('/functions_(.*)\.lib\.php/i',$substitfile['name'],$reg))
- {
- $module=$reg[1];
+ $substitfiles=dol_dir_list($dir,'files',0,'functions_');
+ foreach($substitfiles as $substitfile)
+ {
+ if (preg_match('/functions_(.*)\.lib\.php/i',$substitfile['name'],$reg))
+ {
+ $module=$reg[1];
- dol_syslog("Library functions_".$substitfile['name']." found into ".$dir);
- require_once($dir.$substitfile['name']);
- $function_name=$module."_completesubstitutionarray";
- $function_name($substitutionarray,$outputlangs,$object);
- }
- }
- }
+ dol_syslog("Library functions_".$substitfile['name']." found into ".$dir);
+ require_once($dir.$substitfile['name']);
+ $function_name=$module."_completesubstitutionarray";
+ $function_name($substitutionarray,$outputlangs,$object);
+ }
+ }
+ }
}
/**
@@ -3439,7 +3439,7 @@ function complete_substitutions_array(&$substitutionarray,$outputlangs,$object='
*/
function print_date_range($date_start,$date_end,$format = '',$outputlangs='')
{
- print get_date_range($date_start,$date_end,$format,$outputlangs);
+ print get_date_range($date_start,$date_end,$format,$outputlangs);
}
/**
@@ -3453,26 +3453,26 @@ function print_date_range($date_start,$date_end,$format = '',$outputlangs='')
*/
function get_date_range($date_start,$date_end,$format = '',$outputlangs='')
{
- global $langs;
+ global $langs;
- $out='';
+ $out='';
- if (! is_object($outputlangs)) $outputlangs=$langs;
+ if (! is_object($outputlangs)) $outputlangs=$langs;
- if ($date_start && $date_end)
- {
- $out.= ' ('.$outputlangs->trans('DateFromTo',dol_print_date($date_start, $format, false, $outputlangs),dol_print_date($date_end, $format, false, $outputlangs)).')';
- }
- if ($date_start && ! $date_end)
- {
- $out.= ' ('.$outputlangs->trans('DateFrom',dol_print_date($date_start, $format, false, $outputlangs)).')';
- }
- if (! $date_start && $date_end)
- {
- $out.= ' ('.$outputlangs->trans('DateUntil',dol_print_date($date_end, $format, false, $outputlangs)).')';
- }
+ if ($date_start && $date_end)
+ {
+ $out.= ' ('.$outputlangs->trans('DateFromTo',dol_print_date($date_start, $format, false, $outputlangs),dol_print_date($date_end, $format, false, $outputlangs)).')';
+ }
+ if ($date_start && ! $date_end)
+ {
+ $out.= ' ('.$outputlangs->trans('DateFrom',dol_print_date($date_start, $format, false, $outputlangs)).')';
+ }
+ if (! $date_start && $date_end)
+ {
+ $out.= ' ('.$outputlangs->trans('DateUntil',dol_print_date($date_end, $format, false, $outputlangs)).')';
+ }
- return $out;
+ return $out;
}
/**
@@ -3529,61 +3529,61 @@ function dol_htmloutput_events()
*/
function get_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepembedded=0)
{
- global $conf, $langs;
+ global $conf, $langs;
- $ret='';
- $out='';
- $divstart=$divend='';
+ $ret='';
+ $out='';
+ $divstart=$divend='';
- // If inline message with no format, we add it.
- if ((empty($conf->use_javascript_ajax) || ! empty($conf->global->MAIN_DISABLE_JQUERY_JNOTIFY) || $keepembedded) && ! preg_match('//i',$out))
- {
- $divstart='
';
- $divend='
';
- }
+ // If inline message with no format, we add it.
+ if ((empty($conf->use_javascript_ajax) || ! empty($conf->global->MAIN_DISABLE_JQUERY_JNOTIFY) || $keepembedded) && ! preg_match('/
/i',$out))
+ {
+ $divstart='
';
+ $divend='
';
+ }
- if ((is_array($mesgarray) && count($mesgarray)) || $mesgstring)
- {
- $langs->load("errors");
- $out.=$divstart;
- if (is_array($mesgarray) && count($mesgarray))
- {
- foreach($mesgarray as $message)
- {
- $ret++;
- $out.= $langs->trans($message);
- if ($ret < count($mesgarray)) $out.= "
\n";
- }
- }
- if ($mesgstring)
- {
- $langs->load("errors");
- $ret++;
- $out.= $langs->trans($mesgstring);
- }
- $out.=$divend;
- }
+ if ((is_array($mesgarray) && count($mesgarray)) || $mesgstring)
+ {
+ $langs->load("errors");
+ $out.=$divstart;
+ if (is_array($mesgarray) && count($mesgarray))
+ {
+ foreach($mesgarray as $message)
+ {
+ $ret++;
+ $out.= $langs->trans($message);
+ if ($ret < count($mesgarray)) $out.= "
\n";
+ }
+ }
+ if ($mesgstring)
+ {
+ $langs->load("errors");
+ $ret++;
+ $out.= $langs->trans($mesgstring);
+ }
+ $out.=$divend;
+ }
- if ($out)
- {
- if ($conf->use_javascript_ajax && empty($conf->global->MAIN_DISABLE_JQUERY_JNOTIFY) && empty($keepembedded))
- {
- $return = '';
- }
- else
- {
- $return = $out;
- }
- }
+ if ($out)
+ {
+ if ($conf->use_javascript_ajax && empty($conf->global->MAIN_DISABLE_JQUERY_JNOTIFY) && empty($keepembedded))
+ {
+ $return = '';
+ }
+ else
+ {
+ $return = $out;
+ }
+ }
- return $return;
+ return $return;
}
/**
@@ -3599,7 +3599,7 @@ function get_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepemb
*/
function get_htmloutput_errors($mesgstring='', $mesgarray='', $keepembedded=0)
{
- return get_htmloutput_mesg($mesgstring, $mesgarray,'error',$keepembedded);
+ return get_htmloutput_mesg($mesgstring, $mesgarray,'error',$keepembedded);
}
/**
@@ -3616,45 +3616,45 @@ function get_htmloutput_errors($mesgstring='', $mesgarray='', $keepembedded=0)
*/
function dol_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepembedded=0)
{
- if (empty($mesgstring) && (! is_array($mesgarray) || count($mesgarray) == 0)) return;
+ if (empty($mesgstring) && (! is_array($mesgarray) || count($mesgarray) == 0)) return;
- $iserror=0;
- $iswarning=0;
- if (is_array($mesgarray))
- {
- foreach($mesgarray as $val)
- {
- if ($val && preg_match('/class="error"/i',$val)) { $iserror++; break; }
- if ($val && preg_match('/class="warning"/i',$val)) { $iswarning++; break; }
- }
- }
- else if ($mesgstring && preg_match('/class="error"/i',$mesgstring)) $iserror++;
- else if ($mesgstring && preg_match('/class="warning"/i',$mesgstring)) $iswarning++;
- if ($style=='error') $iserror++;
- if ($style=='warning') $iswarning++;
+ $iserror=0;
+ $iswarning=0;
+ if (is_array($mesgarray))
+ {
+ foreach($mesgarray as $val)
+ {
+ if ($val && preg_match('/class="error"/i',$val)) { $iserror++; break; }
+ if ($val && preg_match('/class="warning"/i',$val)) { $iswarning++; break; }
+ }
+ }
+ else if ($mesgstring && preg_match('/class="error"/i',$mesgstring)) $iserror++;
+ else if ($mesgstring && preg_match('/class="warning"/i',$mesgstring)) $iswarning++;
+ if ($style=='error') $iserror++;
+ if ($style=='warning') $iswarning++;
- if ($iserror || $iswarning)
- {
- // Remove div from texts
- $mesgstring=preg_replace('/<\/div>
/','
',$mesgstring);
- $mesgstring=preg_replace('/
/','',$mesgstring);
- $mesgstring=preg_replace('/<\/div>/','',$mesgstring);
- // Remove div from texts array
- if (is_array($mesgarray))
- {
- $newmesgarray=array();
- foreach($mesgarray as $val)
- {
- $tmpmesgstring=preg_replace('/<\/div>
/','
',$val);
- $tmpmesgstring=preg_replace('/
/','',$tmpmesgstring);
- $tmpmesgstring=preg_replace('/<\/div>/','',$tmpmesgstring);
- $newmesgarray[]=$tmpmesgstring;
- }
- $mesgarray=$newmesgarray;
- }
- print get_htmloutput_mesg($mesgstring,$mesgarray,($iserror?'error':'warning'),$keepembedded);
- }
- else print get_htmloutput_mesg($mesgstring,$mesgarray,'ok',$keepembedded);
+ if ($iserror || $iswarning)
+ {
+ // Remove div from texts
+ $mesgstring=preg_replace('/<\/div>
/','
',$mesgstring);
+ $mesgstring=preg_replace('/
/','',$mesgstring);
+ $mesgstring=preg_replace('/<\/div>/','',$mesgstring);
+ // Remove div from texts array
+ if (is_array($mesgarray))
+ {
+ $newmesgarray=array();
+ foreach($mesgarray as $val)
+ {
+ $tmpmesgstring=preg_replace('/<\/div>
/','
',$val);
+ $tmpmesgstring=preg_replace('/
/','',$tmpmesgstring);
+ $tmpmesgstring=preg_replace('/<\/div>/','',$tmpmesgstring);
+ $newmesgarray[]=$tmpmesgstring;
+ }
+ $mesgarray=$newmesgarray;
+ }
+ print get_htmloutput_mesg($mesgstring,$mesgarray,($iserror?'error':'warning'),$keepembedded);
+ }
+ else print get_htmloutput_mesg($mesgstring,$mesgarray,'ok',$keepembedded);
}
/**
@@ -3670,7 +3670,7 @@ function dol_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepemb
*/
function dol_htmloutput_errors($mesgstring='', $mesgarray='', $keepembedded=0)
{
- dol_htmloutput_mesg($mesgstring, $mesgarray, 'error', $keepembedded);
+ dol_htmloutput_mesg($mesgstring, $mesgarray, 'error', $keepembedded);
}
/**
@@ -3687,23 +3687,23 @@ function dol_htmloutput_errors($mesgstring='', $mesgarray='', $keepembedded=0)
*/
function dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0)
{
- // Clean parameters
- $order=strtolower($order);
+ // Clean parameters
+ $order=strtolower($order);
- $sizearray=count($array);
- if (is_array($array) && $sizearray>0)
- {
- foreach(array_keys($array) as $key) $temp[$key]=$array[$key][$index];
- if (!$natsort) ($order=='asc') ? asort($temp) : arsort($temp);
- else
- {
- ($case_sensitive) ? natsort($temp) : natcasesort($temp);
- if($order!='asc') $temp=array_reverse($temp,TRUE);
- }
- foreach(array_keys($temp) as $key) (is_numeric($key))? $sorted[]=$array[$key] : $sorted[$key]=$array[$key];
- return $sorted;
- }
- return $array;
+ $sizearray=count($array);
+ if (is_array($array) && $sizearray>0)
+ {
+ foreach(array_keys($array) as $key) $temp[$key]=$array[$key][$index];
+ if (!$natsort) ($order=='asc') ? asort($temp) : arsort($temp);
+ else
+ {
+ ($case_sensitive) ? natsort($temp) : natcasesort($temp);
+ if($order!='asc') $temp=array_reverse($temp,TRUE);
+ }
+ foreach(array_keys($temp) as $key) (is_numeric($key))? $sorted[]=$array[$key] : $sorted[$key]=$array[$key];
+ return $sorted;
+ }
+ return $array;
}
@@ -3715,23 +3715,23 @@ function dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensiti
*/
function utf8_check($str)
{
- // We must use here a binary strlen function (so not dol_strlen)
- $strLength = dol_strlen($str);
- for ($i=0; $i<$strLength; $i++)
- {
- if (ord($str[$i]) < 0x80) continue; // 0bbbbbbb
- elseif ((ord($str[$i]) & 0xE0) == 0xC0) $n=1; // 110bbbbb
- elseif ((ord($str[$i]) & 0xF0) == 0xE0) $n=2; // 1110bbbb
- elseif ((ord($str[$i]) & 0xF8) == 0xF0) $n=3; // 11110bbb
- elseif ((ord($str[$i]) & 0xFC) == 0xF8) $n=4; // 111110bb
- elseif ((ord($str[$i]) & 0xFE) == 0xFC) $n=5; // 1111110b
- else return false; // Does not match any model
- for ($j=0; $j<$n; $j++) { // n bytes matching 10bbbbbb follow ?
- if ((++$i == strlen($str)) || ((ord($str[$i]) & 0xC0) != 0x80))
- return false;
- }
- }
- return true;
+ // We must use here a binary strlen function (so not dol_strlen)
+ $strLength = dol_strlen($str);
+ for ($i=0; $i<$strLength; $i++)
+ {
+ if (ord($str[$i]) < 0x80) continue; // 0bbbbbbb
+ elseif ((ord($str[$i]) & 0xE0) == 0xC0) $n=1; // 110bbbbb
+ elseif ((ord($str[$i]) & 0xF0) == 0xE0) $n=2; // 1110bbbb
+ elseif ((ord($str[$i]) & 0xF8) == 0xF0) $n=3; // 11110bbb
+ elseif ((ord($str[$i]) & 0xFC) == 0xF8) $n=4; // 111110bb
+ elseif ((ord($str[$i]) & 0xFE) == 0xFC) $n=5; // 1111110b
+ else return false; // Does not match any model
+ for ($j=0; $j<$n; $j++) { // n bytes matching 10bbbbbb follow ?
+ if ((++$i == strlen($str)) || ((ord($str[$i]) & 0xC0) != 0x80))
+ return false;
+ }
+ }
+ return true;
}
@@ -3744,15 +3744,15 @@ function utf8_check($str)
*/
function dol_osencode($str)
{
- global $conf;
+ global $conf;
- $tmp=ini_get("unicode.filesystem_encoding"); // Disponible avec PHP 6.0
- if (empty($tmp) && ! empty($_SERVER["WINDIR"])) $tmp='iso-8859-1'; // By default for windows
- if (empty($tmp)) $tmp='utf-8'; // By default for other
- if (! empty($conf->global->MAIN_FILESYSTEM_ENCODING)) $tmp=$conf->global->MAIN_FILESYSTEM_ENCODING;
+ $tmp=ini_get("unicode.filesystem_encoding"); // Disponible avec PHP 6.0
+ if (empty($tmp) && ! empty($_SERVER["WINDIR"])) $tmp='iso-8859-1'; // By default for windows
+ if (empty($tmp)) $tmp='utf-8'; // By default for other
+ if (! empty($conf->global->MAIN_FILESYSTEM_ENCODING)) $tmp=$conf->global->MAIN_FILESYSTEM_ENCODING;
- if ($tmp == 'iso-8859-1') return utf8_decode($str);
- return $str;
+ if ($tmp == 'iso-8859-1') return utf8_decode($str);
+ return $str;
}
@@ -3768,35 +3768,35 @@ function dol_osencode($str)
*/
function dol_getIdFromCode($db,$key,$tablename,$fieldkey='code',$fieldid='id')
{
- global $cache_codes;
+ global $cache_codes;
- // If key empty
- if ($key == '') return '';
+ // If key empty
+ if ($key == '') return '';
- // Check in cache
- if (isset($cache_codes[$tablename][$key])) // Can be defined to 0 or ''
- {
- return $cache_codes[$tablename][$key]; // Found in cache
- }
+ // Check in cache
+ if (isset($cache_codes[$tablename][$key])) // Can be defined to 0 or ''
+ {
+ return $cache_codes[$tablename][$key]; // Found in cache
+ }
- $sql = "SELECT ".$fieldid." as id";
- $sql.= " FROM ".MAIN_DB_PREFIX.$tablename;
- $sql.= " WHERE ".$fieldkey." = '".$key."'";
- dol_syslog('dol_getIdFromCode sql='.$sql,LOG_DEBUG);
- $resql = $db->query($sql);
- if ($resql)
- {
- $obj = $db->fetch_object($resql);
- if ($obj) $cache_codes[$tablename][$key]=$obj->id;
- else $cache_codes[$tablename][$key]='';
- $db->free($resql);
- return $cache_codes[$tablename][$key];
- }
- else
- {
- dol_syslog("dol_getIdFromCode error=".$db->lasterror(),LOG_ERR);
- return -1;
- }
+ $sql = "SELECT ".$fieldid." as id";
+ $sql.= " FROM ".MAIN_DB_PREFIX.$tablename;
+ $sql.= " WHERE ".$fieldkey." = '".$key."'";
+ dol_syslog('dol_getIdFromCode sql='.$sql,LOG_DEBUG);
+ $resql = $db->query($sql);
+ if ($resql)
+ {
+ $obj = $db->fetch_object($resql);
+ if ($obj) $cache_codes[$tablename][$key]=$obj->id;
+ else $cache_codes[$tablename][$key]='';
+ $db->free($resql);
+ return $cache_codes[$tablename][$key];
+ }
+ else
+ {
+ dol_syslog("dol_getIdFromCode error=".$db->lasterror(),LOG_ERR);
+ return -1;
+ }
}
/**
@@ -3807,23 +3807,23 @@ function dol_getIdFromCode($db,$key,$tablename,$fieldkey='code',$fieldid='id')
*/
function verifCond($strRights)
{
- global $user,$conf,$langs;
- global $leftmenu;
- global $rights; // To export to dol_eval function
+ global $user,$conf,$langs;
+ global $leftmenu;
+ global $rights; // To export to dol_eval function
- //print $strRights."
\n";
- $rights = true;
- if ($strRights != '')
- {
- //$tab_rights = explode('&&', $strRights);
- //$i = 0;
- //while (($i < count($tab_rights)) && ($rights == true)) {
- $str = 'if(!(' . $strRights . ')) { $rights = false; }';
- dol_eval($str);
- // $i++;
- //}
- }
- return $rights;
+ //print $strRights."
\n";
+ $rights = true;
+ if ($strRights != '')
+ {
+ //$tab_rights = explode('&&', $strRights);
+ //$i = 0;
+ //while (($i < count($tab_rights)) && ($rights == true)) {
+ $str = 'if(!(' . $strRights . ')) { $rights = false; }';
+ dol_eval($str);
+ // $i++;
+ //}
+ }
+ return $rights;
}
/**
@@ -3835,13 +3835,13 @@ function verifCond($strRights)
*/
function dol_eval($s)
{
- // Only global variables can be changed by eval function and returned to caller
- global $langs, $user, $conf;
- global $leftmenu;
- global $rights;
+ // Only global variables can be changed by eval function and returned to caller
+ global $langs, $user, $conf;
+ global $leftmenu;
+ global $rights;
- //print $s."
\n";
- eval($s);
+ //print $s."
\n";
+ eval($s);
}
/**
@@ -3863,34 +3863,34 @@ function dol_validElement($element)
*/
function picto_from_langcode($codelang)
{
- global $langs;
+ global $langs;
- if (! empty($codelang))
- {
- if ($codelang == 'auto')
- {
- return img_picto_common($langs->trans('AutoDetectLang'), 'flags/int.png');
- }
+ if (! empty($codelang))
+ {
+ if ($codelang == 'auto')
+ {
+ return img_picto_common($langs->trans('AutoDetectLang'), 'flags/int.png');
+ }
- $langtocountryflag = array(
- 'ar_AR' => '',
- 'ca_ES' => 'catalonia',
- 'da_DA' => 'dk',
- 'fr_CA' => 'mq',
- 'sv_SV' => 'se'
- );
+ $langtocountryflag = array(
+ 'ar_AR' => '',
+ 'ca_ES' => 'catalonia',
+ 'da_DA' => 'dk',
+ 'fr_CA' => 'mq',
+ 'sv_SV' => 'se'
+ );
- if (isset($langtocountryflag[$codelang])) $tmpcode = $langtocountryflag[$codelang];
- else
- {
- $tmparray = explode('_', $codelang);
- $tmpcode = empty($tmparray[1]) ? $tmparray[0] : $tmparray[1];
- }
+ if (isset($langtocountryflag[$codelang])) $tmpcode = $langtocountryflag[$codelang];
+ else
+ {
+ $tmparray = explode('_', $codelang);
+ $tmpcode = empty($tmparray[1]) ? $tmparray[0] : $tmparray[1];
+ }
- if (isset($tmpcode)) return img_picto_common($codelang, 'flags/'.strtolower($tmpcode).'.png');
- }
+ if (isset($tmpcode)) return img_picto_common($codelang, 'flags/'.strtolower($tmpcode).'.png');
+ }
- return '';
+ return '';
}
/**
@@ -3990,76 +3990,76 @@ function complete_head_from_modules($conf,$langs,$object,&$head,&$h,$type,$mode=
*/
function printCommonFooter($zone='private')
{
- global $conf;
+ global $conf;
global $micro_start_time;
- if ($zone == 'private') print "\n".''."\n";
- else print "\n".''."\n";
+ if ($zone == 'private') print "\n".''."\n";
+ else print "\n".''."\n";
- if (! empty($conf->global->MAIN_HTML_FOOTER)) print $conf->global->MAIN_HTML_FOOTER."\n";
+ if (! empty($conf->global->MAIN_HTML_FOOTER)) print $conf->global->MAIN_HTML_FOOTER."\n";
- // Google Analytics (need Google module)
- if (! empty($conf->global->MAIN_GOOGLE_AN_ID))
- {
- print "\n";
- print ''."\n";
- }
+ // Google Analytics (need Google module)
+ if (! empty($conf->global->MAIN_GOOGLE_AN_ID))
+ {
+ print "\n";
+ print ''."\n";
+ }
- // End of tuning
- if (! empty($_SERVER['DOL_TUNING']))
- {
- $micro_end_time=dol_microtime_float(true);
- print "\n".''."\n";
+ // End of tuning
+ if (! empty($_SERVER['DOL_TUNING']))
+ {
+ $micro_end_time=dol_microtime_float(true);
+ print "\n".''."\n";
- // Add Xdebug coverage of code
- if (defined('XDEBUGCOVERAGE')) {
- var_dump(xdebug_get_code_coverage());
- }
- }
+ // Add Xdebug coverage of code
+ if (defined('XDEBUGCOVERAGE')) {
+ var_dump(xdebug_get_code_coverage());
+ }
+ }
- // If there is some logs in buffer to show
- if (count($conf->logbuffer))
- {
- print "\n";
- print "\n";
- }
+ // If there is some logs in buffer to show
+ if (count($conf->logbuffer))
+ {
+ print "\n";
+ print "\n";
+ }
}
@@ -4072,8 +4072,8 @@ function printCommonFooter($zone='private')
*/
function colorArrayToHex($arraycolor,$colorifnotfound='888888')
{
- if (! is_array($arraycolor)) return $colorifnotfound;
- return dechex($arraycolor[0]).dechex($arraycolor[1]).dechex($arraycolor[2]);
+ if (! is_array($arraycolor)) return $colorifnotfound;
+ return dechex($arraycolor[0]).dechex($arraycolor[1]).dechex($arraycolor[2]);
}
/**