56if (!function_exists(
'utf8_encode')) {
64 function utf8_encode($elements)
66 return mb_convert_encoding($elements,
'UTF-8',
'ISO-8859-1');
70if (!function_exists(
'utf8_decode')) {
78 function utf8_decode($elements)
80 return mb_convert_encoding($elements,
'ISO-8859-1',
'UTF-8');
83if (!function_exists(
'str_starts_with')) {
92 function str_starts_with($haystack, $needle)
94 return (
string) $needle !==
'' && strncmp($haystack, $needle, strlen($needle)) === 0;
97if (!function_exists(
'str_ends_with')) {
106 function str_ends_with($haystack, $needle)
108 return $needle !==
'' && substr($haystack, -strlen($needle)) === (
string) $needle;
111if (!function_exists(
'str_contains')) {
120 function str_contains($haystack, $needle)
122 return $needle !==
'' && mb_strpos($haystack, $needle) !==
false;
137 return json_encode($data);
140 return var_export($data,
true);
160 if (!is_object(
$object) && empty($module)) {
163 if (empty($module) && !empty(
$object->element)) {
170 $module =
'ficheinter';
172 case 'invoice_supplier':
173 $module =
'supplier_invoice';
175 case 'order_supplier':
176 $module =
'supplier_order';
178 case 'recruitmentjobposition':
179 $module =
'recruitment';
180 $subdirectory =
'/recruitmentjobposition';
182 case 'recruitmentcandidature':
183 $module =
'recruitment';
184 $subdirectory =
'/recruitmentcandidature';
186 case 'knowledgerecord':
187 $module =
'knowledgemanagement';
188 $subdirectory =
'/knowledgerecord';
191 $subdirectory =
'/partnership';
193 case 'stocktransfer':
194 $subdirectory =
'/stocktransfer';
196 case 'commande_fournisseur':
197 $module =
'fournisseur';
198 $subdirectory =
'/commande';
203 $module =
'expedition';
204 $subdirectory =
'/sending';
219 if (is_object(
$object) && method_exists(
$object,
'fetchProject')) {
227 if (!empty(
$object->project->ref)) {
228 $subdirectory =
'/'.dol_sanitizeFileName(
$object->project->ref);
241 if ($mode ==
'output' || $mode ==
'outputrel' || $mode ==
'version') {
242 if (isset(
$conf->$module) && property_exists(
$conf->$module,
'multidir_output')) {
244 if ($mode !=
'outputrel') {
248 if (!isset(
$conf->$module->multidir_output[$entity])) {
249 return 'error-diroutput-not-defined-for-this-object='.$module;
251 $s =
$conf->$module->multidir_output[$entity].$subdirectory;
253 if ($forobject &&
$object->id > 0) {
257 } elseif (isset(
$conf->$module) && property_exists(
$conf->$module,
'dir_output')) {
259 if ($mode !=
'outputrel') {
260 $s =
$conf->$module->dir_output . $subdirectory;
262 if ($forobject &&
$object->id > 0) {
267 return 'error-diroutput-not-defined-for-this-object=' . $module;
269 } elseif ($mode ==
'temp') {
270 if (isset(
$conf->$module) && property_exists(
$conf->$module,
'multidir_temp')) {
273 if (!isset(
$conf->$module->multidir_temp[$entity])) {
274 return 'error-dirtemp-not-defined-for-this-object='.$module;
277 } elseif (isset(
$conf->$module) && property_exists(
$conf->$module,
'dir_temp')) {
280 return 'error-dirtemp-not-defined-for-this-object=' . $module;
283 return 'error-bad-value-for-mode';
327 return (
string) (isset(
$conf->global->$key) ?
$conf->global->$key : $default);
337 global $dolibarr_login_badcharunauthorized;
339 if (isset($dolibarr_login_badcharunauthorized)) {
340 if ($dolibarr_login_badcharunauthorized ===
'MAIN_LOGIN_BADCHARUNAUTHORIZED') {
344 return (
string) $dolibarr_login_badcharunauthorized;
362 return (
int) (isset(
$conf->global->$key) ?
$conf->global->$key : $default);
377 return (
float) (isset(
$conf->global->$key) ?
$conf->global->$key : $default);
391 return (
bool) (
$conf->global->$key ?? $default);
402 return (
string)
$conf->currency;
413 return (
string)
$conf->dol_optimize_smallscreen;
424 return (
int)
$conf->entity;
435 return $conf->db->type;
446 return str_replace(
'_',
'', basename(dirname($s)).basename($s,
'.php'));
460 if (empty($tmpuser)) {
465 return (
string) (isset($tmpuser->conf->$key) ? $tmpuser->conf->$key : $default);
478 if (empty($tmpuser)) {
483 return (
int) (isset($tmpuser->conf->$key) ? $tmpuser->conf->$key : $default);
499 'adherent' =>
'member',
500 'member_type' =>
'adherent_type',
502 'contrat' =>
'contract',
503 'entrepot' =>
'stock',
504 'projet' =>
'project',
505 'categorie' =>
'category',
506 'commande' =>
'order',
507 'expedition' =>
'shipping',
508 'facture' =>
'invoice',
509 'fichinter' =>
'intervention',
510 'ficheinter' =>
'intervention',
511 'propale' =>
'propal',
512 'societe' =>
'thirdparty',
513 'socpeople' =>
'contact',
514 'fournisseur' =>
'supplier',
516 'actioncomm' =>
'agenda',
517 'product_price' =>
'productprice',
518 'product_fournisseur_price' =>
'productsupplierprice',
538 $arrayconv[
'supplier_order'] =
'fournisseur';
539 $arrayconv[
'supplier_invoice'] =
'fournisseur';
542 $module_alt = $module;
543 if (!empty($arrayconv[$module])) {
544 $module_alt = $arrayconv[$module];
546 $module_bis = $module;
547 if (!empty($arrayconvbis[$module])) {
548 $module_bis = $arrayconvbis[$module];
551 return !empty(
$conf->modules[$module]) || !empty(
$conf->modules[$module_alt]) || !empty(
$conf->modules[$module_bis]);
569 $moduletomoduletouse = array(
570 'invoice' =>
'facture',
572 $moduleParmsMapping = array(
573 'product' =>
'produit',
576 if (!empty($moduletomoduletouse[$module])) {
577 $module = $moduletomoduletouse[$module];
580 $warningDelayPath = $parmlevel1;
581 if (!empty($moduleParmsMapping[$warningDelayPath])) {
582 $warningDelayPath = $moduleParmsMapping[$warningDelayPath];
586 if (!empty(
$conf->$module) && !empty(
$conf->$module->$warningDelayPath) && !empty(
$conf->$module->$warningDelayPath->$parmlevel2) && !empty(
$conf->$module->$warningDelayPath->$parmlevel2->warning_delay)) {
587 return (
int)
$conf->$module->$warningDelayPath->$parmlevel2->warning_delay;
590 if (!empty(
$conf->$module) && !empty(
$conf->$module->$warningDelayPath) && !empty(
$conf->$module->$warningDelayPath->warning_delay)) {
591 return (
int)
$conf->$module->$warningDelayPath->warning_delay;
606 if ($timestamp ===
'') {
607 dol_syslog(
'Using empty string for a timestamp is deprecated, prefer use of null when calling page ' . $_SERVER[
"PHP_SELF"] .
getCallerInfoString(), LOG_NOTICE);
610 if (is_null($timestamp) || !is_numeric($timestamp)) {
630 require_once DOL_DOCUMENT_ROOT .
"/core/db/" . $type .
'.class.php';
632 $class =
'DoliDB' . ucfirst($type);
633 $db =
new $class($type, $host, $user, $pass, $name, $port);
654function getEntity($element, $shared = 1, $currentobject =
null)
658 if (!is_object($hookmanager)) {
659 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
666 $element =
'project';
669 $element =
'contract';
671 case 'order_supplier':
672 $element =
'supplier_order';
674 case 'invoice_supplier':
675 $element =
'supplier_invoice';
679 if (is_object($mc)) {
680 $out = $mc->getEntity($element, $shared, $currentobject);
683 $addzero = array(
'user',
'usergroup',
'cronjob',
'c_email_templates',
'email_template',
'default_values',
'overwrite_trans');
685 $addzero[] =
'c_holiday_types';
687 if (in_array($element, $addzero)) {
690 $out .= ((int)
$conf->entity);
695 'element' => $element,
698 'currentobject' => $currentobject,
702 $reshook = $hookmanager->executeHooks(
'hookGetEntity', $parameters, $currentobject, $action);
704 if (is_numeric($reshook)) {
705 if ($reshook == 0 && !empty($hookmanager->resPrint)) {
706 $out .=
',' . $hookmanager->resPrint;
707 } elseif ($reshook == 1) {
708 $out = $hookmanager->resPrint;
725 if (is_object($mc) && method_exists($mc,
'setEntity')) {
726 return $mc->setEntity($currentobject);
728 return ((is_object($currentobject) && $currentobject->id > 0 && ((
int) $currentobject->entity) > 0) ? (
int) $currentobject->entity :
$conf->entity);
740 return preg_match(
'/(_pass|password|_pw|_key|securekey|serverkey|secret\d?|p12key|exportkey|_PW_[a-z]+|token)$/i', $keyname);
753 for ($r =
""; $n >= 0; $n = intval($n / 26) - 1) {
754 $r = chr($n % 26 + 0x41) . $r;
778 include_once DOL_DOCUMENT_ROOT .
'/includes/mobiledetect/mobiledetectlib/Mobile_Detect.php';
785 $user_agent = substr($user_agent, 0, 512);
788 $detectmobile =
new Mobile_Detect(
null, $user_agent);
789 $tablet = $detectmobile->isTablet();
791 if ($detectmobile->isMobile()) {
795 if ($detectmobile->is(
'AndroidOS')) {
796 $os = $phone =
'android';
797 } elseif ($detectmobile->is(
'BlackBerryOS')) {
798 $os = $phone =
'blackberry';
799 } elseif ($detectmobile->is(
'iOS')) {
802 } elseif ($detectmobile->is(
'PalmOS')) {
803 $os = $phone =
'palm';
804 } elseif ($detectmobile->is(
'SymbianOS')) {
806 } elseif ($detectmobile->is(
'webOS')) {
808 } elseif ($detectmobile->is(
'MaemoOS')) {
810 } elseif ($detectmobile->is(
'WindowsMobileOS') || $detectmobile->is(
'WindowsPhoneOS')) {
816 if (preg_match(
'/linux/i', $user_agent)) {
818 } elseif (preg_match(
'/macintosh/i', $user_agent)) {
820 } elseif (preg_match(
'/windows/i', $user_agent)) {
826 if (preg_match(
'/firefox(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
828 $version = empty($reg[2]) ?
'' : $reg[2];
829 } elseif (preg_match(
'/edge(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
831 $version = empty($reg[2]) ?
'' : $reg[2];
832 } elseif (preg_match(
'/chrome(\/|\s)([\d\.]+)/i', $user_agent, $reg)) {
834 $version = empty($reg[2]) ?
'' : $reg[2];
835 } elseif (preg_match(
'/chrome/i', $user_agent, $reg)) {
838 } elseif (preg_match(
'/iceweasel/i', $user_agent)) {
840 } elseif (preg_match(
'/epiphany/i', $user_agent)) {
842 } elseif (preg_match(
'/safari(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
844 $version = empty($reg[2]) ?
'' : $reg[2];
845 } elseif (preg_match(
'/opera(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
848 $version = empty($reg[2]) ?
'' : $reg[2];
849 } elseif (preg_match(
'/(MSIE\s([0-9]+\.[0-9]))|.*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) {
851 $version = end($reg);
852 } elseif (preg_match(
'/(Windows NT\s([0-9]+\.[0-9])).*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) {
855 $version = end($reg);
856 } elseif (preg_match(
'/l[iy]n(x|ks)(\(|\/|\s)*([\d\.]+)/i', $user_agent, $reg)) {
858 $name =
'textbrowser';
859 $version = empty($reg[3]) ?
'' : $reg[3];
860 } elseif (preg_match(
'/w3m\/([\d\.]+)/i', $user_agent, $reg)) {
862 $name =
'textbrowser';
863 $version = empty($reg[1]) ?
'' : $reg[1];
875 'browsername' => $name,
876 'browserversion' => $version,
878 'browserua' => $user_agent,
893 $disconnectdone =
false;
895 if (is_object(
$db) && !empty(
$db->connected)) {
896 $depth =
$db->transaction_opened;
897 $disconnectdone =
$db->close();
899 dol_syslog(
"--- End access to " . (empty($_SERVER[
"PHP_SELF"]) ?
'unknown' : $_SERVER[
"PHP_SELF"]) . (($disconnectdone && $depth) ?
' (Warn: db disconnection forced, transaction depth was ' . $depth .
')' :
''), (($disconnectdone && $depth) ? LOG_WARNING : LOG_INFO));
911function GETPOSTISSET($paramname)
915 $relativepathstring = $_SERVER[
"PHP_SELF"];
917 if (constant(
'DOL_URL_ROOT')) {
918 $relativepathstring = preg_replace(
'/^' . preg_quote(constant(
'DOL_URL_ROOT'),
'/') .
'/',
'', $relativepathstring);
920 $relativepathstring = ltrim($relativepathstring,
'/');
921 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
925 if (!empty($_GET[
'restore_lastsearch_values'])) {
926 if (!empty($_SESSION[
'lastsearch_values_' . $relativepathstring])) {
927 $tmp = json_decode($_SESSION[
'lastsearch_values_' . $relativepathstring],
true);
928 if (is_array($tmp)) {
929 foreach ($tmp as $key => $val) {
930 if ($key == $paramname) {
938 if ($paramname ==
'contextpage' && !empty($_SESSION[
'lastsearch_contextpage_' . $relativepathstring])) {
940 } elseif ($paramname ==
'limit' && !empty($_SESSION[
'lastsearch_limit_' . $relativepathstring])) {
942 } elseif ($paramname ==
'page' && !empty($_SESSION[
'lastsearch_page_' . $relativepathstring])) {
944 } elseif ($paramname ==
'mode' && !empty($_SESSION[
'lastsearch_mode_' . $relativepathstring])) {
948 $isset = (isset($_POST[$paramname]) || isset($_GET[$paramname]));
965 if (empty($method)) {
966 $val = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] :
'');
967 } elseif ($method == 1) {
968 $val = isset($_GET[$paramname]) ? $_GET[$paramname] :
'';
969 } elseif ($method == 2) {
970 $val = isset($_POST[$paramname]) ? $_POST[$paramname] :
'';
971 } elseif ($method == 3) {
972 $val = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] :
'');
974 $val =
'BadFirstParameterForGETPOST';
977 return is_array($val);
991function GETPOSTINT($paramname, $method = 0, $nodefault = 0)
993 return (
int)
GETPOST($paramname,
'int', $method,
null,
null, 0, $nodefault);
1009function GETPOSTFLOAT($paramname, $rounding =
'', $option = 2)
1030function GETPOSTDATE($prefix, $hourTime =
'', $gm =
'auto', $saverestore =
'')
1033 if ($hourTime ===
'getpost' || $hourTime ===
'getpostend') {
1034 $hour = (GETPOSTISSET($prefix .
'hour') &&
GETPOSTINT($prefix .
'hour') >= 0) ?
GETPOSTINT($prefix .
'hour') : ($hourTime ===
'getpostend' ? 23 : 0);
1035 $minute = (GETPOSTISSET($prefix .
'min') &&
GETPOSTINT($prefix .
'min') >= 0) ?
GETPOSTINT($prefix .
'min') : ($hourTime ===
'getpostend' ? 59 : 0);
1036 $second = (GETPOSTISSET($prefix .
'sec') &&
GETPOSTINT($prefix .
'sec') >= 0) ?
GETPOSTINT($prefix .
'sec') : ($hourTime ===
'getpostend' ? 59 : 0);
1037 } elseif (preg_match(
'/^(\d\d):(\d\d):(\d\d)$/', $hourTime, $m)) {
1038 $hour = intval($m[1]);
1039 $minute = intval($m[2]);
1040 $second = intval($m[3]);
1041 } elseif ($hourTime ===
'end') {
1046 $hour = $minute = $second = 0;
1051 && !GETPOSTISSET($prefix .
'day')
1052 && !GETPOSTISSET($prefix .
'month')
1053 && !GETPOSTISSET($prefix .
'year')
1054 && isset($_SESSION[
'DOLDATE_' . $saverestore .
'_day'])
1055 && isset($_SESSION[
'DOLDATE_' . $saverestore .
'_month'])
1056 && isset($_SESSION[
'DOLDATE_' . $saverestore .
'_year'])
1058 $day = $_SESSION[
'DOLDATE_' . $saverestore .
'_day'];
1059 $month = $_SESSION[
'DOLDATE_' . $saverestore .
'_month'];
1060 $year = $_SESSION[
'DOLDATE_' . $saverestore .
'_year'];
1068 $hour = (int) min($hour, 23);
1069 $minute = (int) min($minute, 59);
1070 $second = (int) min($second, 59);
1073 $_SESSION[
'DOLDATE_' . $saverestore .
'_day'] = $day;
1074 $_SESSION[
'DOLDATE_' . $saverestore .
'_month'] = $month;
1075 $_SESSION[
'DOLDATE_' . $saverestore .
'_year'] = $year;
1079 return dol_mktime($hour, $minute, $second, $month, $day, $year, $gm);
1123function GETPOST($paramname, $check =
'alphanohtml', $method = 0, $filter =
null, $options =
null, $noreplace = 0, $nodefault = 0)
1125 global $langs, $user;
1127 if (empty($paramname)) {
1128 return 'BadFirstParameterForGETPOST';
1130 if (empty($check)) {
1131 dol_syslog(
"Deprecated use of GETPOST, called with 1st param = " . $paramname .
" and a 2nd param that is '', when calling page " . $_SERVER[
"PHP_SELF"], LOG_WARNING);
1135 if (in_array($paramname, array(
'sortfield',
'sortorder'))) {
1136 $check =
'aZ09comma';
1139 if (empty($method)) {
1140 $out = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] :
'');
1141 } elseif ($method == 1) {
1142 $out = isset($_GET[$paramname]) ? $_GET[$paramname] :
'';
1143 } elseif ($method == 2) {
1144 $out = isset($_POST[$paramname]) ? $_POST[$paramname] :
'';
1145 } elseif ($method == 3) {
1146 $out = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] :
'');
1148 return 'BadThirdParameterForGETPOST';
1151 $relativepathstring =
'';
1153 if (empty($method) || $method == 3 || $method == 4) {
1154 $relativepathstring = (empty($_SERVER[
"PHP_SELF"]) ?
'' : $_SERVER[
"PHP_SELF"]);
1156 if (constant(
'DOL_URL_ROOT')) {
1157 $relativepathstring = preg_replace(
'/^' . preg_quote(constant(
'DOL_URL_ROOT'),
'/') .
'/',
'', $relativepathstring);
1159 $relativepathstring = ltrim($relativepathstring,
'/');
1160 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
1164 if (!empty($_GET[
'restore_lastsearch_values'])) {
1165 if (!empty($_SESSION[
'lastsearch_values_' . $relativepathstring])) {
1166 $tmp = json_decode($_SESSION[
'lastsearch_values_' . $relativepathstring],
true);
1167 if (is_array($tmp)) {
1168 foreach ($tmp as $key => $val) {
1169 if ($key == $paramname) {
1177 if ($paramname ==
'contextpage' && !empty($_SESSION[
'lastsearch_contextpage_' . $relativepathstring])) {
1178 $out = $_SESSION[
'lastsearch_contextpage_' . $relativepathstring];
1179 } elseif ($paramname ==
'limit' && !empty($_SESSION[
'lastsearch_limit_' . $relativepathstring])) {
1180 $out = $_SESSION[
'lastsearch_limit_' . $relativepathstring];
1181 } elseif ($paramname ==
'page' && !empty($_SESSION[
'lastsearch_page_' . $relativepathstring])) {
1182 $out = $_SESSION[
'lastsearch_page_' . $relativepathstring];
1183 } elseif ($paramname ==
'mode' && !empty($_SESSION[
'lastsearch_mode_' . $relativepathstring])) {
1184 $out = $_SESSION[
'lastsearch_mode_' . $relativepathstring];
1186 } elseif (!isset($_GET[
'sortfield'])) {
1189 if (!empty($_GET[
'action']) && $_GET[
'action'] ==
'create' && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
1192 '@phan-var-force CommonObject $object';
1193 if (is_object(
$object) && isset(
$object->fields[$paramname][
'default'])) {
1195 $out =
$object->fields[$paramname][
'default'];
1199 if (!empty($_GET[
'action']) && (preg_match(
'/^create/', $_GET[
'action']) || preg_match(
'/^presend/', $_GET[
'action'])) && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
1201 if (!empty($user->default_values)) {
1202 if (isset($user->default_values[$relativepathstring][
'createform'])) {
1203 foreach ($user->default_values[$relativepathstring][
'createform'] as $defkey => $defval) {
1205 if ($defkey !=
'_noquery_') {
1206 $tmpqueryarraytohave = explode(
'&', $defkey);
1209 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
1210 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
1222 if (isset($user->default_values[$relativepathstring][
'createform'][$defkey][$paramname])) {
1223 $out = $user->default_values[$relativepathstring][
'createform'][$defkey][$paramname];
1230 } elseif (!empty($paramname) && !isset($_GET[$paramname]) && !isset($_POST[$paramname]) && empty($nodefault)) {
1232 if (!empty($user->default_values)) {
1235 if ($paramname ==
'sortfield' || $paramname ==
'sortorder') {
1237 if (isset($user->default_values[$relativepathstring][
'sortorder'])) {
1239 foreach ($user->default_values[$relativepathstring][
'sortorder'] as $defkey => $defval) {
1241 if ($defkey !=
'_noquery_') {
1242 $tmpqueryarraytohave = explode(
'&', $defkey);
1245 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
1246 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
1258 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
1259 foreach ($user->default_values[$relativepathstring][
'sortorder'][$defkey] as $key => $val) {
1263 if ($paramname ==
'sortfield') {
1266 if ($paramname ==
'sortorder') {
1274 } elseif (isset($user->default_values[$relativepathstring][
'filters'])) {
1275 foreach ($user->default_values[$relativepathstring][
'filters'] as $defkey => $defval) {
1276 if (!empty($_GET[
'disabledefaultvalues'])) {
1280 if ($defkey !=
'_noquery_') {
1281 $tmpqueryarraytohave = explode(
'&', $defkey);
1284 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
1285 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
1296 if ($qualified && isset($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname])) {
1298 if (isset($_POST[
'search_all']) || isset($_GET[
'search_all'])) {
1301 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
1302 $out =
dol_string_nospecial($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname],
'', $forbidden_chars_to_replace);
1305 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
1306 $out =
dol_string_nospecial($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname],
'', $forbidden_chars_to_replace);
1321 '@phan-var-force string $paramname';
1322 if (!is_array($out) && empty($_POST[$paramname]) && empty($noreplace)) {
1323 if (preg_match(
'/__([A-Z0-9]+(?:_[A-Z0-9]+){0,3})__/i', $out)) {
1324 $substitutionarray = getCommonSubstitutionArray($langs, 0,
null, $user, array(
'mycompany',
'date',
'system',
'user'));
1332 if (preg_match(
'/^array/', $check)) {
1333 $tmpcheck =
'alphanohtml';
1334 if ($out ===
null || $out ===
'') {
1336 } elseif (!is_array($out)) {
1337 $out = explode(
',', $out);
1339 $tmparray = explode(
':', $check);
1340 if (!empty($tmparray[1])) {
1341 $tmpcheck = $tmparray[1];
1344 foreach ($out as $outkey => $outval) {
1345 $out[$outkey] =
sanitizeVal($outval, $tmpcheck, $filter, $options);
1350 if (strpos($paramname,
'search_') === 0) {
1351 $out = preg_replace(
'/([<>])([-+]?\d)/',
'\1 \2', $out);
1355 $out =
sanitizeVal($out, $check, $filter, $options);
1363 if (preg_match(
'/^backto/i', $paramname) || preg_match(
'/^urlfrom/i', $paramname)) {
1364 $out = str_replace(
'\\',
'/', $out);
1365 $out = str_replace(array(
':',
';',
'@',
"\t",
' '),
'', $out);
1367 $oldstringtoclean = $out;
1368 $out = str_ireplace(array(
'javascript',
'vbscript',
'&colon',
'&#'),
'', $out);
1369 $out = preg_replace(array(
'/^[^\?]*%/'),
'', $out);
1370 $out = preg_replace(array(
'/^[a-z]*\/\s*\/+/i'),
'', $out);
1371 }
while ($oldstringtoclean != $out);
1376 if (empty($method) || $method == 3 || $method == 4) {
1377 if (preg_match(
'/^search_/', $paramname) || in_array($paramname, array(
'sortorder',
'sortfield'))) {
1384 if ($out !=
'' && isset($user)) {
1385 $user->lastsearch_values_tmp[$relativepathstring][$paramname] = $out;
1390 if ($paramname ==
'hashp' && $out ==
'shared') {
1406function sanitizeVal($out =
'', $check =
'alphanohtml', $filter =
null, $options =
null)
1410 if ($out ===
null) {
1418 if (!is_numeric($out)) {
1423 if (is_array($out)) {
1424 $out = implode(
',', $out);
1426 if (preg_match(
'/[^0-9,-]+/i', $out)) {
1431 dol_syslog(
"Use of parameter value 'san_alpha' in GETPOST is deprecated. Use 'alphanohtml', 'aZ09comma', ...", LOG_WARNING);
1432 $out = filter_var($out, FILTER_SANITIZE_STRING);
1435 $out = filter_var($out, FILTER_SANITIZE_EMAIL);
1439 $out = preg_replace(
'/[^:\/\[\]a-z0-9@\$\'\*\~\.\-_,;\?\!=%&+#]+/i',
'', $out);
1443 if (!is_array($out)) {
1445 if (preg_match(
'/[^a-z]+/i', $out)) {
1451 if (!is_array($out)) {
1453 if (preg_match(
'/[^a-z0-9_\-\.]+/i', $out)) {
1459 if (!is_array($out)) {
1461 if (preg_match(
'/[^a-z0-9_\-\.@]+/i', $out)) {
1467 if (!is_array($out)) {
1469 if (preg_match(
'/[^a-z0-9_\-\.,]+/i', $out)) {
1476 if (!is_array($out)) {
1479 $oldstringtoclean = $out;
1483 $out = preg_replace(
'/\\\([0-9xu])/',
'/\1', $out);
1490 $out = str_ireplace(array(
'../',
'..\\',
'&',
'&',
'&',
'"',
'"',
'"',
'"',
'"',
'/',
'/',
'/',
'\',
'\',
'\'),
'', $out);
1491 }
while ($oldstringtoclean != $out);
1495 case 'alphawithlgt':
1496 if (!is_array($out)) {
1499 $oldstringtoclean = $out;
1503 $out = preg_replace(
'/\\\([0-9xu])/',
'/\1', $out);
1510 $out = str_ireplace(array(
'../',
'..\\',
'&',
'&',
'&',
'"',
'"',
'"',
'"',
'"',
'/',
'/',
'/',
'\',
'\',
'\'),
'', $out);
1511 }
while ($oldstringtoclean != $out);
1517 case 'restricthtmlnolink':
1518 case 'restricthtml':
1519 case 'restricthtmlallowclass':
1520 case 'restricthtmlallowiframe':
1521 case 'restricthtmlallowlinkscript':
1522 case 'restricthtmlallowunvalid':
1527 if (empty($filter)) {
1528 return 'BadParameterForGETPOST - Param 3 of sanitizeVal()';
1530 if (is_null($options)) {
1533 $out = filter_var($out, $filter, $options);
1537 dol_syslog(
"Error, you call sanitizeVal() with a bad value for the check type. Data will be sanitized with alphanohtml.", LOG_ERR);
1538 $out =
GETPOST($out,
'alphanohtml');
1553function dolSetCookie(
string $cookiename,
string $cookievalue,
int $expire = -1)
1555 include_once DOL_DOCUMENT_ROOT.
'/blockedlog/lib/securitycore.lib.php';
1557 global $dolibarr_main_force_https;
1559 if ($expire == -1) {
1560 $expire = (time() + (86400 * 354));
1563 if (PHP_VERSION_ID < 70300) {
1564 setcookie($cookiename, empty($cookievalue) ?
'' : $cookievalue, empty($cookievalue) ? 0 : $expire,
'/',
'', !(empty($dolibarr_main_force_https) &&
isHTTPS() === false), true);
1567 $cookieparams = array(
1568 'expires' => empty($cookievalue) ? 0 : $expire,
1571 'secure' => !(empty($dolibarr_main_force_https) &&
isHTTPS() === false),
1575 setcookie($cookiename, empty($cookievalue) ?
'' : $cookievalue, $cookieparams);
1577 if (empty($cookievalue)) {
1578 unset($_COOKIE[$cookiename]);
1582if (!function_exists(
'dol_getprefix')) {
1593 function dol_getprefix($mode =
'')
1596 if ($mode ==
'email') {
1602 } elseif (isset($_SERVER[
"SERVER_NAME"])) {
1603 return $_SERVER[
"SERVER_NAME"];
1608 if (!empty(
$conf->file->instance_unique_id)) {
1609 return sha1(
'dolibarr' .
$conf->file->instance_unique_id);
1613 return sha1(DOL_DOCUMENT_ROOT . DOL_URL_ROOT);
1617 global $dolibarr_main_instance_unique_id, $dolibarr_main_cookie_cryptkey;
1618 $tmp_instance_unique_id = empty($dolibarr_main_instance_unique_id) ? (empty($dolibarr_main_cookie_cryptkey) ?
'' : $dolibarr_main_cookie_cryptkey) : $dolibarr_main_instance_unique_id;
1621 if (!empty($tmp_instance_unique_id)) {
1622 return sha1(
'dolibarr' . $tmp_instance_unique_id);
1626 if (isset($_SERVER[
"SERVER_NAME"]) && isset($_SERVER[
"DOCUMENT_ROOT"])) {
1627 return sha1($_SERVER[
"SERVER_NAME"] . $_SERVER[
"DOCUMENT_ROOT"] . DOL_DOCUMENT_ROOT . DOL_URL_ROOT);
1629 return sha1(DOL_DOCUMENT_ROOT . DOL_URL_ROOT);
1648 if (strpos($relpath,
'..') !==
false) {
1650 dol_syslog(
'functions::dol_include_once Tried to load a file with a path including a forbidden sequence ".." : ' . $relpath, LOG_WARNING);
1653 if (!preg_match(
'/\.php$/', $relpath)) {
1655 dol_syslog(
'functions::dol_include_once Tried to load a file that is not a PHP file : ' . $relpath, LOG_WARNING);
1661 if (!file_exists($fullpath)) {
1662 dol_syslog(
'functions::dol_include_once Tried to load unexisting file: ' . $relpath, LOG_WARNING);
1665 if (!empty($classname) && !class_exists($classname)) {
1666 return include $fullpath;
1668 return include_once $fullpath;
1686function dol_buildpath($path, $type = 0, $returnemptyifnotfound = 0)
1690 $path = preg_replace(
'/^\//',
'', $path);
1693 $res = DOL_DOCUMENT_ROOT .
'/' . $path;
1694 if (is_array(
$conf->file->dol_document_root)) {
1695 foreach (
$conf->file->dol_document_root as $key => $dirroot) {
1696 if ($key ==
'main') {
1700 if (@file_exists($dirroot .
'/' . $path)) {
1701 if ($key !=
'main' && preg_match(
'/^core\//', $path)) {
1704 $res = $dirroot .
'/' . $path;
1709 if ($returnemptyifnotfound) {
1711 if ($returnemptyifnotfound == 1 || !file_exists($res)) {
1723 $res = DOL_URL_ROOT .
'/' . $path;
1726 $res = DOL_MAIN_URL_ROOT .
'/' . $path;
1729 $res = DOL_URL_ROOT .
'/' . $path;
1732 foreach (
$conf->file->dol_document_root as $key => $dirroot) {
1733 if ($key ==
'main') {
1738 $urlwithouturlroot = preg_replace(
'/' . preg_quote(DOL_URL_ROOT,
'/') .
'$/i',
'', trim(
$conf->file->dol_main_url_root));
1739 $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT;
1742 $res = (preg_match(
'/^http/i',
$conf->file->dol_url_root[$key]) ?
'' : $urlwithroot) .
'/' . $path;
1747 preg_match(
'/^([^\?]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i', $path, $regs);
1748 if (!empty($regs[1])) {
1751 if (@file_exists($dirroot .
'/' . $regs[1])) {
1753 $res = (preg_match(
'/^http/i',
$conf->file->dol_url_root[$key]) ?
'' : DOL_URL_ROOT) .
$conf->file->dol_url_root[$key] .
'/' . $path;
1754 } elseif ($type == 2) {
1755 $res = (preg_match(
'/^http/i',
$conf->file->dol_url_root[$key]) ?
'' : DOL_MAIN_URL_ROOT) .
$conf->file->dol_url_root[$key] .
'/' . $path;
1756 } elseif ($type == 3) {
1760 $urlwithouturlroot = preg_replace(
'/' . preg_quote(DOL_URL_ROOT,
'/') .
'$/i',
'', trim(
$conf->file->dol_main_url_root));
1761 $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT;
1764 $res = (preg_match(
'/^http/i',
$conf->file->dol_url_root[$key]) ?
'' : $urlwithroot) .
$conf->file->dol_url_root[$key] .
'/' . $path;
1784function dolBuildUrl($url, $params = [], $addtoken =
false, $anchor =
'')
1786 global
$db, $hookmanager;
1788 if (!is_object($hookmanager)) {
1789 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
1792 if ((!isset($params[
'mainmenu']) || empty($params[
'mainmenu'])) && GETPOSTISSET(
'mainmenu')) {
1793 $params = array_merge($params, [
'mainmenu' => (
GETPOST(
'mainmenu',
'restricthtml'))]);
1795 if ((!isset($params[
'leftmenu'])) && GETPOSTISSET(
'leftmenu')) {
1796 $params = array_merge($params, [
'leftmenu' => (
GETPOST(
'leftmenu',
'restricthtml'))]);
1800 'params' => &$params,
1801 'addtoken' => &$addtoken,
1803 $hookmanager->executeHooks(
'buildurl', $parameters);
1805 $params = array_merge($params, [
'token' =>
newToken()]);
1808 $url .=
'?' . http_build_query($params);
1811 $url .=
'#' . preg_replace(
'/[^a-z]/i',
'', $anchor);
1830 if (empty($properties)) {
1831 return get_object_vars($obj);
1834 $existingProperties = [];
1835 $realProperties = get_object_vars($obj);
1838 foreach ($properties as $property) {
1839 if (array_key_exists($property, $realProperties)) {
1841 $existingProperties[$property] = $obj->{$property};
1842 } elseif (property_exists($obj, $property)) {
1844 $existingProperties[$property] = $obj->{$property};
1848 return $existingProperties;
1869function dol_clone($srcobject, $native = 2)
1873 dol_syslog(
"Warning, call to dol_clone() with the deprecated parameter native=0, use 2 instead", LOG_WARNING);
1876 if (isset($srcobject->db) && isset($srcobject->db->db) && is_object($srcobject->db->db) && get_class($srcobject->db->db) ==
'PgSql\Connection') {
1877 $tmpsavdb = $srcobject->db;
1878 unset($srcobject->db);
1881 $myclone = unserialize(serialize($srcobject));
1883 if (!empty($tmpsavdb)) {
1884 $srcobject->db = $tmpsavdb;
1886 } elseif ($native == 2) {
1889 $tmparray = get_object_vars($srcobject);
1891 if (is_array($tmparray)) {
1892 foreach ($tmparray as $propertykey => $propertyval) {
1893 if (is_scalar($propertyval) || is_array($propertyval)) {
1894 $myclone->$propertykey = $propertyval;
1899 $myclone = clone $srcobject;
1916 if (is_object($srcobject)) {
1917 $srcobject = get_object_vars($srcobject);
1920 if (is_array($srcobject)) {
1922 foreach ($srcobject as $key => $value) {
1923 if (in_array($key, array(
'db',
'fields',
'error',
'errorhidden',
'errors',
'oldcopy',
'linkedObjects',
'linked_objects'))) {
1944function dol_size($size, $type =
'')
1947 if (empty(
$conf->dol_optimize_smallscreen)) {
1950 if ($type ==
'width' && $size > 250) {
1971function dol_sanitizeFileName($str, $newstr =
'_', $unaccent = 1, $includequotes = 0, $allowdash = 0)
1979 $filesystem_forbidden_chars = array(
'<',
'>',
'/',
'\\',
'?',
'*',
'|',
'"',
':',
'°',
'$',
';',
'`');
1980 if ($includequotes) {
1981 $filesystem_forbidden_chars[] =
"'";
1984 $tmp = preg_replace(
'/\-\-+/',
'_', $tmp);
1985 if (empty($allowdash)) {
1986 $tmp = preg_replace(
'/\s+\-([^\s])/',
' _$1', $tmp);
1987 $tmp = preg_replace(
'/\s+\-$/',
'', $tmp);
1989 $tmp = str_replace(
'..',
'', $tmp);
1990 $tmp = str_replace(
'~', $newstr, $tmp);
1991 $tmp = preg_replace(
'/\s{2,}/',
' ', $tmp);
2018 $filesystem_forbidden_chars = array(
'<',
'>',
'?',
'*',
'|',
'"',
'°',
'$',
';',
'`');
2025 $tmp = preg_replace(
'/\-\-+/', $newstr, $tmp);
2026 if (empty($allowdash)) {
2027 $tmp = preg_replace(
'/\s+\-([^\s])/',
' '.$newstr.
'$1', $tmp);
2028 $tmp = preg_replace(
'/\s+\-$/',
'', $tmp);
2030 $tmp = str_replace(
'..', $newstr, $tmp);
2031 $tmp = str_replace(
'~', $newstr, $tmp);
2032 $tmp = preg_replace(
'/\s{2,}/',
' ', $tmp);
2048 $stringtoclean = preg_replace(
'/[\x00-\x1F\x7F]/u',
'', $stringtoclean);
2050 $stringtoclean = preg_replace(
'/<!--[^>]*-->/',
'', $stringtoclean);
2052 $stringtoclean = str_replace(
'\\',
'/', $stringtoclean);
2056 $stringtoclean = str_replace(array(
':',
';',
'@'),
'', $stringtoclean);
2060 $oldstringtoclean = $stringtoclean;
2063 $stringtoclean = str_ireplace(array(
'javascript',
'vbscript',
'&colon',
'&#'),
'', $stringtoclean);
2064 }
while ($oldstringtoclean != $stringtoclean);
2068 $stringtoclean = preg_replace(array(
'/^[a-z]*\/\/+/i'),
'', $stringtoclean);
2071 return $stringtoclean;
2083 $oldstringtoclean = $stringtoclean;
2084 $stringtoclean = str_ireplace(array(
'"',
':',
'[',
']',
"\n",
"\r",
'\\',
'\/'),
'', $stringtoclean);
2085 }
while ($oldstringtoclean != $stringtoclean);
2087 return $stringtoclean;
2100 return preg_replace(
'/[^\w]+/',
'', $str);
2114 if (is_null($str)) {
2119 if (extension_loaded(
'intl') &&
getDolGlobalString(
'MAIN_UNACCENT_USE_TRANSLITERATOR')) {
2120 $transliterator = Transliterator::createFromRules(
':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: NFC;', Transliterator::FORWARD);
2121 return $transliterator->transliterate($str);
2124 $string = rawurlencode($str);
2125 $replacements = array(
2126 '%C3%80' =>
'A',
'%C3%81' =>
'A',
'%C3%82' =>
'A',
'%C3%83' =>
'A',
'%C3%84' =>
'A',
'%C3%85' =>
'A',
2128 '%C3%88' =>
'E',
'%C3%89' =>
'E',
'%C3%8A' =>
'E',
'%C3%8B' =>
'E',
2129 '%C3%8C' =>
'I',
'%C3%8D' =>
'I',
'%C3%8E' =>
'I',
'%C3%8F' =>
'I',
2131 '%C3%92' =>
'O',
'%C3%93' =>
'O',
'%C3%94' =>
'O',
'%C3%95' =>
'O',
'%C3%96' =>
'O',
'%C5%90' =>
'O',
2133 '%C3%99' =>
'U',
'%C3%9A' =>
'U',
'%C3%9B' =>
'U',
'%C3%9C' =>
'U',
'%C5%B0' =>
'U',
2134 '%C3%9D' =>
'Y',
'%C5%B8' =>
'y',
2135 '%C3%A0' =>
'a',
'%C3%A1' =>
'a',
'%C3%A2' =>
'a',
'%C3%A3' =>
'a',
'%C3%A4' =>
'a',
'%C3%A5' =>
'a',
2137 '%C3%A8' =>
'e',
'%C3%A9' =>
'e',
'%C3%AA' =>
'e',
'%C3%AB' =>
'e',
2138 '%C3%AC' =>
'i',
'%C3%AD' =>
'i',
'%C3%AE' =>
'i',
'%C3%AF' =>
'i',
2140 '%C3%B2' =>
'o',
'%C3%B3' =>
'o',
'%C3%B4' =>
'o',
'%C3%B5' =>
'o',
'%C3%B6' =>
'o',
'%C5%91' =>
'o',
2142 '%C3%B9' =>
'u',
'%C3%BA' =>
'u',
'%C3%BB' =>
'u',
'%C3%BC' =>
'u',
'%C5%B1' =>
'u',
2143 '%C3%BD' =>
'y',
'%C3%BF' =>
'y',
2164 $string = strtr($string, $replacements);
2165 return rawurldecode($string);
2170 "\xC0\xC1\xC2\xC3\xC4\xC5\xC7
2171 \xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1
2172 \xD2\xD3\xD4\xD5\xD8\xD9\xDA\xDB\xDD
2173 \xE0\xE1\xE2\xE3\xE4\xE5\xE7\xE8\xE9\xEA\xEB
2174 \xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF8
2175 \xF9\xFA\xFB\xFC\xFD\xFF",
2183 $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"));
2201function dol_string_nospecial($str, $newstr =
'_', $badcharstoreplace =
'', $badcharstoremove =
'', $keepspaces = 0)
2203 $forbidden_chars_to_replace = array(
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
",",
";",
"=",
'°',
'$',
';');
2204 if (empty($keepspaces)) {
2205 $forbidden_chars_to_replace[] =
" ";
2207 $forbidden_chars_to_remove = array();
2210 if (is_array($badcharstoreplace)) {
2211 $forbidden_chars_to_replace = $badcharstoreplace;
2213 if (is_array($badcharstoremove)) {
2214 $forbidden_chars_to_remove = $badcharstoremove;
2218 return str_replace($forbidden_chars_to_replace, $newstr, str_replace($forbidden_chars_to_remove,
"", $str));
2237 if ($removetabcrlf) {
2238 return preg_replace(
'/[\x00-\x1F\x7F]/u',
'', $str);
2240 return preg_replace(
'/[\x00-\x08\x11-\x12\x14-\x1F\x7F]/u',
'', $str);
2255 if (function_exists(
'iconv')) {
2256 $slug = iconv(
'UTF-8',
'ASCII//TRANSLIT//IGNORE', $slug);
2260 $slug = strtolower($slug);
2263 $slug = preg_replace(
'/[^a-z0-9]+/',
'-', $slug);
2266 $slug = trim($slug,
'-');
2279function dol_escape_js($stringtoescape, $mode = 0, $noescapebackslashn = 0)
2281 if (is_null($stringtoescape)) {
2286 $substitjs = array(
"'" =>
"\\'",
"\r" =>
'\\r');
2288 if (empty($noescapebackslashn)) {
2289 $substitjs[
"\n"] =
'\\n';
2290 $substitjs[
'\\'] =
'\\\\';
2293 $substitjs[
"'"] =
"\\'";
2294 $substitjs[
'"'] =
"\\'";
2295 } elseif ($mode == 1) {
2296 $substitjs[
"'"] =
"\\'";
2297 } elseif ($mode == 2) {
2298 $substitjs[
'"'] =
'\\"';
2299 } elseif ($mode == 3) {
2300 $substitjs[
"'"] =
"\\'";
2301 $substitjs[
'"'] =
"\\\"";
2303 return strtr((
string) $stringtoescape, $substitjs);
2317 return rawurlencode($stringtoescape);
2328 return str_replace(
'"',
'\"', $stringtoescape);
2340 if (is_null($stringtoescape)) {
2344 if ($stringforquotes == 2) {
2345 return str_replace(
'"',
"'", $stringtoescape);
2346 } elseif ($stringforquotes == 1) {
2352 $stringtoescape = str_replace(
'\\',
'', $stringtoescape);
2353 return str_replace(
"'",
"\'", str_replace(
'"',
"'", $stringtoescape));
2356 return 'Bad parameter for stringforquotes in dol_escape_php';
2367 return preg_replace(
'/[^a-z0-9_]/i',
'', $stringtoescape);
2378 return $stringtoescape;
2391 if (function_exists(
'mb_strtolower')) {
2392 return mb_strtolower($string, $encoding);
2394 return strtolower($string);
2408 if (function_exists(
'mb_strtoupper')) {
2409 return mb_strtoupper($string, $encoding);
2411 return strtoupper($string);
2425 if (function_exists(
'mb_substr')) {
2426 return mb_strtoupper(mb_substr($string, 0, 1, $encoding), $encoding) . mb_substr($string, 1,
null, $encoding);
2428 return ucfirst($string);
2442 if (function_exists(
'mb_convert_case')) {
2443 return mb_convert_case($string, MB_CASE_TITLE, $encoding);
2445 return ucwords($string);
2457 $backtrace = debug_backtrace();
2459 if (count($backtrace) >= 1) {
2461 if (count($backtrace) == 1) {
2464 $trace = $backtrace[$pos];
2465 if (isset($trace[
'file'], $trace[
'line'])) {
2466 $msg =
" From {$trace['file']}:{$trace['line']}.";
2494function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename =
'', $restricttologhandler =
'', $logcontext =
null)
2496 global
$conf, $user, $debugbar;
2504 if (defined(
'USEEXTERNALSERVER') && !defined(
'USEDOLIBARRSERVER') && !defined(
'USEDOLIBARREDITOR')) {
2505 global $website, $websitekey;
2506 if (is_object($website) && !empty($website->ref)) {
2507 $suffixinfilename .=
'_website_' . $website->ref;
2508 } elseif (!empty($websitekey)) {
2509 $suffixinfilename .=
'_website_' . $websitekey;
2514 if (defined(
'USESUFFIXINLOG')) {
2515 $suffixinfilename .= constant(
'USESUFFIXINLOG');
2519 foreach (
$conf->loghandlers as $loghandlerinstance) {
2520 $loghandlerinstance->setIdent($ident);
2524 if (!empty($message)) {
2527 $logLevels = array(LOG_EMERG =>
'EMERG', LOG_ALERT =>
'ALERT', LOG_CRIT =>
'CRITICAL', LOG_ERR =>
'ERR', LOG_WARNING =>
'WARN', LOG_NOTICE =>
'NOTICE', LOG_INFO =>
'INFO', LOG_DEBUG =>
'DEBUG');
2529 if (!array_key_exists($level, $logLevels)) {
2530 dol_syslog(
'Error Bad Log Level ' . $level, LOG_ERR);
2538 $message = preg_replace(
'/password=\'[^\']*\'/',
'password=\'hidden\'', $message);
2542 if ((!empty($_REQUEST[
'logtohtml']) &&
getDolGlobalString(
'MAIN_ENABLE_LOG_TO_HTML'))
2543 || (is_object($user) && $user->hasRight(
'debugbar',
'read') && is_object($debugbar))
2545 $ospid = sprintf(
"%7s",
dol_trunc((
string) getmypid(), 7,
'right',
'UTF-8', 1));
2546 $osuser =
" " . sprintf(
"%6s",
dol_trunc(function_exists(
'posix_getuid') ? posix_getuid() :
'', 6,
'right',
'UTF-8', 1));
2548 $conf->logbuffer[] =
dol_print_date(time(),
"%Y-%m-%d %H:%M:%S") .
" " . sprintf(
"%-7s", $logLevels[$level]) .
" " . $ospid .
" " . $osuser .
" " . $message;
2554 print
"\n\n<!-- Log start\n";
2556 print
"Log end -->\n";
2560 'message' => $message,
2561 'script' => (isset($_SERVER[
'PHP_SELF']) ? basename($_SERVER[
'PHP_SELF'],
'.php') :
''),
2563 'user' => ((is_object($user) && $user->id) ? $user->login :
''),
2565 'osuser' => function_exists(
'posix_getuid') ? (
string) posix_getuid() :
'',
2566 'ospid' => (
string) getmypid()
2571 if (!empty($remoteip)) {
2572 $data[
'ip'] = $remoteip;
2576 if (!empty($_SERVER[
'HTTP_X_FORWARDED_FOR'])) {
2577 $tmpips = explode(
',', $_SERVER[
'HTTP_X_FORWARDED_FOR']);
2581 foreach ($tmpips as $tmpip) {
2582 $tmpip = trim($tmpip);
2583 if (strtolower($tmpip) == strtolower($remoteip)) {
2586 if (empty($data[
'ip'])) {
2587 $data[
'ip'] = $tmpip;
2590 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $tmpip;
2593 if (!$foundremoteip) {
2595 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $remoteip;
2597 $data[
'ip'] .= (($j > 0) ?
']' :
'');
2598 } elseif (!empty($_SERVER[
'HTTP_CLIENT_IP'])) {
2599 $tmpips = explode(
',', $_SERVER[
'HTTP_CLIENT_IP']);
2603 foreach ($tmpips as $tmpip) {
2604 $tmpip = trim($tmpip);
2605 if (strtolower($tmpip) == strtolower($remoteip)) {
2608 if (empty($data[
'ip'])) {
2609 $data[
'ip'] = $tmpip;
2612 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $tmpip;
2615 if (!$foundremoteip) {
2617 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $remoteip;
2619 $data[
'ip'] .= (($j > 0) ?
']' :
'');
2621 } elseif (!empty($_SERVER[
'SERVER_ADDR'])) {
2623 $data[
'ip'] = (
string) $_SERVER[
'SERVER_ADDR'];
2624 } elseif (!empty($_SERVER[
'COMPUTERNAME'])) {
2626 $data[
'ip'] = (
string) $_SERVER[
'COMPUTERNAME'];
2628 $data[
'ip'] =
'???';
2631 if (!empty($_SERVER[
'USERNAME'])) {
2633 $data[
'osuser'] = (
string) $_SERVER[
'USERNAME'];
2634 } elseif (!empty($_SERVER[
'LOGNAME'])) {
2636 $data[
'osuser'] = (
string) $_SERVER[
'LOGNAME'];
2640 foreach (
$conf->loghandlers as $loghandlerinstance) {
2641 if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler) {
2644 $loghandlerinstance->export($data, $suffixinfilename);
2650 foreach (
$conf->loghandlers as $loghandlerinstance) {
2651 $loghandlerinstance->setIdent($ident);
2672 global $langs, $hookmanager;
2675 $countriesusingstate = array(
'AU',
'CA',
'US',
'IN',
'GB',
'ES',
'UK',
'TR',
'CN');
2680 $ret .= (($extralangcode && !empty(
$object->array_languages[
'address'][$extralangcode])) ?
$object->array_languages[
'address'][$extralangcode] : (empty(
$object->
address) ?
'' : preg_replace(
'/(\r\n|\r|\n)+/', $sep,
$object->
address)));
2683 if (isset(
$object->country_code) && in_array(
$object->country_code, array(
'AU',
'CA',
'US',
'CN')) ||
getDolGlobalString(
'MAIN_FORCE_STATE_INTO_ADDRESS')) {
2685 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
2686 $ret .= (($ret && $town) ? $sep :
'') . $town;
2689 $ret .= ($ret ? ($town ?
", " : $sep) :
'') .
$object->state;
2692 $ret .= ($ret ? (($town ||
$object->state) ?
", " : $sep) :
'') .
$object->zip;
2694 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'GB',
'UK'))) {
2696 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
2697 $ret .= ($ret ? $sep :
'') . $town;
2699 $ret .= ($ret ?
", " :
'') .
$object->state;
2702 $ret .= ($ret ? $sep :
'') .
$object->zip;
2704 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'ES',
'TR'))) {
2706 $ret .= ($ret ? $sep :
'') .
$object->zip;
2707 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
2708 $ret .= ($town ? ((
$object->zip ?
' ' :
'') . $town) :
'');
2710 $ret .= $sep .
$object->state;
2712 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'JP'))) {
2715 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
2717 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'IT'))) {
2719 $ret .= ($ret ? $sep :
'') .
$object->zip;
2720 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
2721 $ret .= ($town ? ((
$object->zip ?
' ' :
'') . $town) :
'');
2722 $ret .= (empty(
$object->state_code) ?
'' : (
' ' .
$object->state_code));
2725 $town = (($extralangcode && !empty(
$object->array_languages[
'address'][$extralangcode])) ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
2726 $ret .= !empty(
$object->zip) ? (($ret ? $sep :
'') .
$object->zip) :
'';
2727 $ret .= ($town ? ((
$object->zip ?
' ' : ($ret ? $sep :
'')) . $town) :
'');
2728 if (!empty(
$object->state) && in_array(
$object->country_code, $countriesusingstate)) {
2729 $ret .= ($ret ?
", " :
'') .
$object->state;
2733 if (!is_object($outputlangs)) {
2734 $outputlangs = $langs;
2737 $langs->load(
"dict");
2738 $ret .= (empty(
$object->country_code) ?
'' : ($ret ? $sep :
'') . $outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv(
"Country" .
$object->country_code)));
2741 $parameters = array(
'withcountry' => $withcountry,
'sep' => $sep,
'outputlangs' => $outputlangs,
'mode' => $mode,
'extralangcode' => $extralangcode);
2742 $reshook = $hookmanager->executeHooks(
'formatAddress', $parameters,
$object);
2746 $ret .= $hookmanager->resPrint;
2763function dol_strftime($fmt, $ts =
false, $is_gmt =
false)
2765 if ((abs($ts) <= 0x7FFFFFFF)) {
2768 return 'Error date outside supported range';
2794function dol_print_date($time, $format =
'', $tzoutput =
'auto', $outputlangs =
null, $encodetooutput =
false, $decorate = 0)
2796 global
$conf, $langs;
2803 if ($tzoutput ===
'auto') {
2804 $tzoutput = (empty(
$conf) ?
'tzserver' : (isset(
$conf->tzuserinputkey) ?
$conf->tzuserinputkey :
'tzserver'));
2809 $offsettz = $offsetdst = 0;
2812 if (is_string($tzoutput)) {
2813 if ($tzoutput ==
'tzserver') {
2815 $offsettzstring = @date_default_timezone_get();
2820 } elseif ($tzoutput ==
'tzuser' || $tzoutput ==
'tzuserrel') {
2823 $offsettzstring = (empty($_SESSION[
'dol_tz_string']) ?
getDolGlobalString(
'MAIN_DOLIBARR_USER_TIMEZONE',
'UTC') : $_SESSION[
'dol_tz_string']);
2825 if (class_exists(
'DateTimeZone')) {
2827 $user_date_tz =
new DateTimeZone($offsettzstring);
2830 dol_syslog(
"DateInvalidTimeZoneException for timezone string '".$offsettzstring.
"'. Falling back to UTC.", LOG_ERR);
2831 $user_date_tz =
new DateTimeZone(
'UTC');
2833 $user_dt =
new DateTime();
2834 $user_dt->setTimezone($user_date_tz);
2835 $user_dt->setTimestamp($tzoutput ==
'tzuser' ?
dol_now() : (int) $time);
2836 $offsettz = $user_dt->getOffset();
2838 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
2839 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
2844 if (!is_object($outputlangs)) {
2845 $outputlangs = $langs;
2848 $format =
'daytextshort';
2853 $reduceformat = (!empty(
$conf->dol_optimize_smallscreen) && in_array($format, array(
'day',
'dayhour',
'dayhoursec'))) ? 1 : 0;
2854 $format = preg_replace(
'/inputnoreduce/',
'', $format);
2855 $formatwithoutreduce = preg_replace(
'/reduceformat/',
'', $format);
2856 if ($formatwithoutreduce != $format) {
2857 $format = $formatwithoutreduce;
2863 if ($format ==
'day') {
2864 $format = ($outputlangs->trans(
"FormatDateShort") !=
"FormatDateShort" ? $outputlangs->trans(
"FormatDateShort") :
$conf->format_date_short);
2865 } elseif ($format ==
'hour') {
2866 $format = ($outputlangs->trans(
"FormatHourShort") !=
"FormatHourShort" ? $outputlangs->trans(
"FormatHourShort") :
$conf->format_hour_short);
2867 } elseif ($format ==
'hoursec') {
2868 $s1 = $outputlangs->trans(
"FormatDateShort");
2869 $s2 = $outputlangs->trans(
"FormatDateHourSecShort");
2870 $s3 = trim(preg_replace(
'/'.preg_quote($s1,
'/').
'/',
'', $s2));
2873 } elseif ($format ==
'hourduration') {
2874 $format = ($outputlangs->trans(
"FormatHourShortDuration") !=
"FormatHourShortDuration" ? $outputlangs->trans(
"FormatHourShortDuration") :
$conf->format_hour_short_duration);
2875 } elseif ($format ==
'daytext') {
2876 $format = ($outputlangs->trans(
"FormatDateText") !=
"FormatDateText" ? $outputlangs->trans(
"FormatDateText") :
$conf->format_date_text);
2877 } elseif ($format ==
'daytextshort') {
2878 $format = ($outputlangs->trans(
"FormatDateTextShort") !=
"FormatDateTextShort" ? $outputlangs->trans(
"FormatDateTextShort") :
$conf->format_date_text_short);
2879 } elseif ($format ==
'dayhour') {
2880 $format = ($outputlangs->trans(
"FormatDateHourShort") !=
"FormatDateHourShort" ? $outputlangs->trans(
"FormatDateHourShort") :
$conf->format_date_hour_short);
2881 } elseif ($format ==
'dayhoursec') {
2882 $format = ($outputlangs->trans(
"FormatDateHourSecShort") !=
"FormatDateHourSecShort" ? $outputlangs->trans(
"FormatDateHourSecShort") :
$conf->format_date_hour_sec_short);
2883 } elseif ($format ==
'dayhourtext') {
2884 $format = ($outputlangs->trans(
"FormatDateHourText") !=
"FormatDateHourText" ? $outputlangs->trans(
"FormatDateHourText") :
$conf->format_date_hour_text);
2885 } elseif ($format ==
'dayhourtextshort') {
2886 $format = ($outputlangs->trans(
"FormatDateHourTextShort") !=
"FormatDateHourTextShort" ? $outputlangs->trans(
"FormatDateHourTextShort") :
$conf->format_date_hour_text_short);
2887 } elseif ($format ==
'dayhourlog') {
2889 $format =
'%Y%m%d%H%M%S';
2890 } elseif ($format ==
'dayhourlogsmall') {
2892 $format =
'%y%m%d%H%M';
2893 } elseif ($format ==
'dayhourldap') {
2894 $format =
'%Y%m%d%H%M%SZ';
2895 } elseif ($format ==
'dayhourxcard') {
2896 $format =
'%Y%m%dT%H%M%SZ';
2897 } elseif ($format ==
'dayxcard') {
2899 } elseif ($format ==
'dayrfc') {
2900 $format =
'%Y-%m-%d';
2901 } elseif ($format ==
'dayhourrfc') {
2902 $format =
'%Y-%m-%dT%H:%M:%SZ';
2903 } elseif ($format ==
'standard') {
2904 $format =
'%Y-%m-%d %H:%M:%S';
2907 if ($reduceformat) {
2908 $format = str_replace(
'%Y',
'%y', $format);
2909 $format = str_replace(
'yyyy',
'yy', $format);
2913 if (preg_match(
'/%b/i', $format)) {
2915 $format = str_replace(
'%b',
'__b__', $format);
2916 $format = str_replace(
'%B',
'__B__', $format);
2918 if (preg_match(
'/%a/i', $format)) {
2920 $format = str_replace(
'%a',
'__a__', $format);
2921 $format = str_replace(
'%A',
'__A__', $format);
2926 if (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', (
string) $time, $reg)) {
2929 } elseif (preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', (
string) $time, $reg)) {
2933 $syear = (!empty($reg[1]) ? $reg[1] :
'');
2934 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
2935 $sday = (!empty($reg[3]) ? $reg[3] :
'');
2936 $shour = (!empty($reg[4]) ? $reg[4] :
'');
2937 $smin = (!empty($reg[5]) ? $reg[5] :
'');
2938 $ssec = (!empty($reg[6]) ? $reg[6] :
'');
2940 $time =
dol_mktime((
int) $shour, (
int) $smin, (
int) $ssec, (
int) $smonth, (
int) $sday, (
int) $syear,
true);
2943 $tzo =
new DateTimeZone(
'UTC');
2945 $tzo =
new DateTimeZone(date_default_timezone_get());
2947 $dtts =
new DateTime();
2948 $dtts->setTimestamp($time);
2949 $dtts->setTimezone($tzo);
2950 $newformat = str_replace(
2951 array(
'%Y',
'%y',
'%m',
'%d',
'%H',
'%I',
'%M',
'%S',
'%p',
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
2952 array(
'Y',
'y',
'm',
'd',
'H',
'h',
'i',
's',
'A',
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
2955 $ret = $dtts->format($newformat);
2957 array(
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
2958 array(
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
2963 if ($time < 100000000000) {
2964 $dtts =
new DateTime();
2967 $timetouse = (int) $time + $offsettz + $offsetdst;
2969 $tzo =
new DateTimeZone(
'UTC');
2970 $dtts->setTimezone($tzo);
2971 $dtts->setTimestamp($timetouse);
2973 $timetouse = (int) $time + $offsettz + $offsetdst;
2975 $tzo =
new DateTimeZone(date_default_timezone_get());
2976 $dtts->setTimestamp($timetouse);
2977 $dtts->setTimezone($tzo);
2980 $newformat = str_replace(
2981 array(
'%Y',
'%y',
'%m',
'%d',
'%H',
'%I',
'%M',
'%S',
'%p',
'%w',
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
2982 array(
'Y',
'y',
'm',
'd',
'H',
'h',
'i',
's',
'A',
'w',
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
2986 $ret = $dtts->format($newformat);
2989 array(
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
2990 array(
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
2994 $ret =
'Bad value ' . $time .
' for date';
2998 if (preg_match(
'/__b__/i', $format)) {
2999 $timetouse = $time + $offsettz + $offsetdst;
3002 $tzo =
new DateTimeZone(
'UTC');
3004 $tzo =
new DateTimeZone(date_default_timezone_get());
3006 $dtts =
new DateTime();
3007 $dtts->setTimestamp($timetouse);
3008 $dtts->setTimezone($tzo);
3009 $month = (int) $dtts->format(
"m");
3010 $month = sprintf(
"%02d", $month);
3011 if ($encodetooutput) {
3012 $monthtext = $outputlangs->transnoentities(
'Month' . $month);
3013 $monthtextshort = $outputlangs->transnoentities(
'MonthShort' . $month);
3015 $monthtext = $outputlangs->transnoentitiesnoconv(
'Month' . $month);
3016 $monthtextshort = $outputlangs->transnoentitiesnoconv(
'MonthShort' . $month);
3019 $ret = str_replace(
'__b__', $monthtextshort, $ret);
3020 $ret = str_replace(
'__B__', $monthtext, $ret);
3024 if (preg_match(
'/__a__/i', $format)) {
3026 $timetouse = $time + $offsettz + $offsetdst;
3029 $tzo =
new DateTimeZone(
'UTC');
3031 $tzo =
new DateTimeZone(date_default_timezone_get());
3033 $dtts =
new DateTime();
3034 $dtts->setTimestamp($timetouse);
3035 $dtts->setTimezone($tzo);
3036 $w = $dtts->format(
"w");
3037 $dayweek = $outputlangs->transnoentitiesnoconv(
'Day' . $w);
3039 $ret = str_replace(
'__A__', $dayweek, $ret);
3040 $ret = str_replace(
'__a__',
dol_substr($dayweek, 0, 3), $ret);
3044 $ret = preg_replace(
'/(\d\d:\d\d [AP]M)$/',
'<span class="'.($decorate === 1 ?
'opacitymedium' : $decorate).
'">\1</span>', $ret);
3045 $ret = preg_replace(
'/(\d\d:\d\d)$/',
'<span class="'.($decorate === 1 ?
'opacitymedium' : $decorate).
'">\1</span>', $ret);
3072function dol_getdate($timestamp, $fast =
false, $forcetimezone =
'')
3074 if ($timestamp ===
'') {
3078 $datetimeobj =
new DateTime();
3079 $datetimeobj->setTimestamp($timestamp);
3080 if ($forcetimezone) {
3081 $datetimeobj->setTimezone(
new DateTimeZone($forcetimezone ==
'gmt' ?
'UTC' : $forcetimezone));
3084 'year' => ((
int) date_format($datetimeobj,
'Y')),
3085 'mon' => ((
int) date_format($datetimeobj,
'm')),
3086 'mday' => ((
int) date_format($datetimeobj,
'd')),
3087 'wday' => ((
int) date_format($datetimeobj,
'w')),
3088 'yday' => ((
int) date_format($datetimeobj,
'z')),
3089 'hours' => ((
int) date_format($datetimeobj,
'H')),
3090 'minutes' => ((
int) date_format($datetimeobj,
'i')),
3091 'seconds' => ((
int) date_format($datetimeobj,
's')),
3119function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm =
'auto', $check = 1)
3124 if ($gm ===
'auto') {
3125 $gm = (empty(
$conf) ?
'tzserver' :
$conf->tzuserinputkey);
3130 if ($hour == -1 || empty($hour)) {
3133 if ($minute == -1 || empty($minute)) {
3136 if ($second == -1 || empty($second)) {
3142 if (!$month || !$day) {
3151 if ($hour < 0 || $hour > 24) {
3154 if ($minute < 0 || $minute > 60) {
3157 if ($second < 0 || $second > 60) {
3162 if (empty($gm) || ($gm ===
'server' || $gm ===
'tzserver')) {
3163 $default_timezone = @date_default_timezone_get();
3164 $localtz =
new DateTimeZone($default_timezone);
3165 } elseif ($gm ===
'user' || $gm ===
'tzuser' || $gm ===
'tzuserrel') {
3167 $default_timezone = (empty($_SESSION[
"dol_tz_string"]) ? @date_default_timezone_get() : $_SESSION[
"dol_tz_string"]);
3169 $localtz =
new DateTimeZone($default_timezone);
3171 dol_syslog(
"Warning dol_tz_string contains an invalid value " . json_encode($_SESSION[
"dol_tz_string"] ??
null), LOG_WARNING);
3172 $default_timezone = @date_default_timezone_get();
3174 } elseif (strrpos($gm,
"tz,") !==
false) {
3175 $timezone = (
string) str_replace(
"tz,",
"", $gm);
3177 $localtz =
new DateTimeZone($timezone);
3179 dol_syslog(
"Warning passed timezone contains an invalid value " . $timezone, LOG_WARNING);
3183 if (empty($localtz)) {
3184 $localtz =
new DateTimeZone(
'UTC');
3186 $dt =
new DateTime(
'now', $localtz);
3187 $dt->setDate((
int) $year, (
int) $month, (
int) $day);
3188 $dt->setTime((
int) $hour, (
int) $minute, (
int) $second);
3189 $date = $dt->getTimestamp();
3205function dol_now($mode =
'gmt')
3209 if ($mode ===
'auto') {
3213 if ($mode ==
'gmt') {
3215 } elseif ($mode ==
'tzserver') {
3216 require_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
3218 $ret = (int) (
dol_now(
'gmt') + ($tzsecond * 3600));
3223 } elseif ($mode ==
'tzuser' || $mode ==
'tzuserrel') {
3226 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
3227 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
3228 $ret = (int) (
dol_now(
'gmt') + ($offsettz + $offsetdst));
3245 global
$conf, $langs;
3248 if (!empty(
$conf->dol_optimize_smallscreen)) {
3253 if (empty($shortvalue) || $size < ($level * 10)) {
3255 $textunitshort = $langs->trans(
"b");
3256 $textunitlong = $langs->trans(
"Bytes");
3258 $ret = round($size / $level, 0);
3259 $textunitshort = $langs->trans(
"Kb");
3260 $textunitlong = $langs->trans(
"KiloBytes");
3263 if (empty($shortunit)) {
3264 $ret .=
' ' . $textunitlong;
3266 $ret .=
' ' . $textunitshort;
3282function dol_print_url($url, $target =
'_blank', $max = 32, $withpicto = 0, $morecss =
'')
3290 $linkstart =
'<a href="';
3291 if (!preg_match(
'/^http/i', $url)) {
3292 $linkstart .=
'http://';
3297 $linkstart .=
' target="' . $target .
'"';
3299 $linkstart .=
' title="' . $langs->trans(
"URL") .
': ' . $url .
'"';
3303 if (!preg_match(
'/^http/i', $url)) {
3310 if ($morecss ==
'float') {
3311 return '<div class="nospan' . ($morecss ?
' ' . $morecss :
'') .
'" style="margin-right: 10px">' . ($withpicto ?
img_picto($langs->trans(
"Url"),
'globe',
'class="paddingrightonly"') :
'') . $link .
'</div>';
3313 return $linkstart .
'<span class="nospan' . ($morecss ?
' ' . $morecss :
'') .
'" style="margin-right: 10px">' . ($withpicto ?
img_picto(
'',
'globe',
'class="paddingrightonly"') :
'') . $link .
'</span>' . $linkend;
3330function dol_print_email($email, $contactid = 0, $socid = 0, $addlink = 0, $max = 0, $showinvalid = 2, $withpicto = 0, $morecss =
'paddingrightonly')
3332 global $user, $langs, $hookmanager;
3343 if (empty($email)) {
3347 if ($addlink == 1) {
3348 $newemail =
'<a class="' . ($morecss ? $morecss :
'') .
'" style="text-overflow: ellipsis;" href="';
3349 if (!preg_match(
'/^mailto:/i', $email)) {
3350 $newemail .=
'mailto:';
3352 $newemail .= $email;
3353 $newemail .=
'" target="_blank">';
3355 $newemail .= ($withpicto ?
img_picto($langs->trans(
"EMail") .
' : ' . $email, (is_numeric($withpicto) ?
'email' : $withpicto),
'class="paddingrightonly"') :
'');
3360 $newemail .= $email;
3362 $newemail .=
'</a>';
3365 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
3366 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
3369 $langs->load(
"errors");
3370 $newemail .=
img_warning($langs->transnoentitiesnoconv(
"ErrorBadEMail", $emailonly),
'',
'paddingrightonly');
3372 $langs->load(
"errors");
3373 $newemail .=
img_warning($langs->transnoentitiesnoconv(
"ErrorBadMXDomain", $emailonly),
'',
'paddingrightonly');
3377 if (($contactid || $socid) &&
isModEnabled(
'agenda') && $user->hasRight(
"agenda",
"myactions",
"create")) {
3379 $linktoaddaction =
'';
3381 $linktoaddaction =
'<a href="' . DOL_URL_ROOT .
'/comm/action/card.php?action=create&backtopage=1&actioncode=' . urlencode($type) .
'&contactid=' . ((int) $contactid) .
'&socid=' . ((int) $socid) .
'">' .
img_object($langs->trans(
"AddAction"),
"calendar") .
'</a>';
3383 if ($linktoaddaction) {
3384 $newemail =
'<div>' . $newemail .
' ' . $linktoaddaction .
'</div>';
3387 } elseif ($addlink ===
'thirdparty') {
3388 $tmpnewemail =
'<a class="' . ($morecss ? $morecss :
'') .
'" style="text-overflow: ellipsis;" href="' . DOL_URL_ROOT .
'/societe/card.php?socid=' . $socid .
'&action=presend&mode=init#formmailbeforetitle">';
3389 $tmpnewemail .= ($withpicto ?
img_picto($langs->trans(
"EMail") .
' : ' . $email, (is_numeric($withpicto) ?
'email' : $withpicto),
'class="paddingrightonly"') :
'');
3390 if ($withpicto == 1) {
3391 $tmpnewemail .= $newemail;
3393 $tmpnewemail .=
'</a>';
3395 $newemail = $tmpnewemail;
3397 $newemail = ($withpicto ?
img_picto($langs->trans(
"EMail") .
' : ' . $email, (is_numeric($withpicto) ?
'email' : $withpicto),
'class="paddingrightonly"') :
'') . $newemail;
3400 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
3401 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
3404 $langs->load(
"errors");
3405 $newemail .=
img_warning($langs->transnoentitiesnoconv(
"ErrorBadEMail", $email));
3407 $langs->load(
"errors");
3408 $newemail .=
img_warning($langs->transnoentitiesnoconv(
"ErrorBadMXDomain", $emailonly));
3422 $parameters = array(
'cid' => $contactid,
'socid' => $socid,
'addlink' => $addlink,
'picto' => $withpicto);
3424 $reshook = $hookmanager->executeHooks(
'printEmail', $parameters, $email);
3428 $rep .= $hookmanager->resPrint;
3444 $socialnetworks = array();
3446 require_once DOL_DOCUMENT_ROOT .
'/core/lib/memory.lib.php';
3450 if (!is_null($dataretrieved)) {
3451 $socialnetworks = $dataretrieved;
3453 $sql =
"SELECT rowid, code, label, url, icon, active FROM " . MAIN_DB_PREFIX .
"c_socialnetworks";
3454 $sql .=
" WHERE entity IN (" .
getEntity(
'c_socialnetworks').
")";
3456 $resql =
$db->query($sql);
3458 while ($obj =
$db->fetch_object($resql)) {
3459 $socialnetworks[$obj->code] = array(
3460 'rowid' => $obj->rowid,
3461 'label' => $obj->label,
3463 'icon' => $obj->icon,
3464 'active' => $obj->active,
3471 return (is_array($socialnetworks) ? $socialnetworks : array());
3486 global $hookmanager, $langs, $user;
3490 if (empty($value)) {
3494 if (!empty($type)) {
3495 $htmllink =
'<div class="divsocialnetwork inline-block valignmiddle">';
3497 $htmllink .=
'<span class="fab pictofixedwidth ' . ($dictsocialnetworks[$type][
'icon'] ? $dictsocialnetworks[$type][
'icon'] :
'fa-link') .
'"></span>';
3498 if ($type ==
'skype') {
3500 $htmllink .=
' <a href="skype:';
3502 $htmllink .=
'?call" alt="' . $langs->trans(
"Call") .
' ' . $value .
'" title="' .
dol_escape_htmltag($langs->trans(
"Call") .
' ' . $value) .
'">';
3503 $htmllink .=
'<img src="' . DOL_URL_ROOT .
'/theme/common/skype_callbutton.png" border="0">';
3504 $htmllink .=
'</a><a href="skype:';
3506 $htmllink .=
'?chat" alt="' . $langs->trans(
"Chat") .
' ' . $value .
'" title="' .
dol_escape_htmltag($langs->trans(
"Chat") .
' ' . $value) .
'">';
3507 $htmllink .=
'<img class="paddingleft" src="' . DOL_URL_ROOT .
'/theme/common/skype_chatbutton.png" border="0">';
3508 $htmllink .=
'</a>';
3509 if (($contactid || $socid) &&
isModEnabled(
'agenda') && $user->hasRight(
'agenda',
'myactions',
'create')) {
3510 $addlink =
'AC_SKYPE';
3513 $link =
'<a href="' . DOL_URL_ROOT .
'/comm/action/card.php?action=create&backtopage=1&actioncode=' . $addlink .
'&contactid=' . $contactid .
'&socid=' . $socid .
'">' .
img_object($langs->trans(
"AddAction"),
"calendar") .
'</a>';
3515 $htmllink .= ($link ?
' ' . $link :
'');
3518 if (!empty($dictsocialnetworks[$type][
'url'])) {
3519 $tmpvirginurl = preg_replace(
'/\/?{socialid}/',
'', $dictsocialnetworks[$type][
'url']);
3520 if ($tmpvirginurl) {
3521 $value = preg_replace(
'/^www\.' . preg_quote($tmpvirginurl,
'/') .
'\/?/',
'', $value);
3522 $value = preg_replace(
'/^' . preg_quote($tmpvirginurl,
'/') .
'\/?/',
'', $value);
3524 $tmpvirginurl3 = preg_replace(
'/^https:\/\//i',
'https://www.', $tmpvirginurl);
3525 if ($tmpvirginurl3) {
3526 $value = preg_replace(
'/^www\.' . preg_quote($tmpvirginurl3,
'/') .
'\/?/',
'', $value);
3527 $value = preg_replace(
'/^' . preg_quote($tmpvirginurl3,
'/') .
'\/?/',
'', $value);
3530 $tmpvirginurl2 = preg_replace(
'/^https?:\/\//i',
'', $tmpvirginurl);
3531 if ($tmpvirginurl2) {
3532 $value = preg_replace(
'/^www\.' . preg_quote($tmpvirginurl2,
'/') .
'\/?/',
'', $value);
3533 $value = preg_replace(
'/^' . preg_quote($tmpvirginurl2,
'/') .
'\/?/',
'', $value);
3536 if (preg_match(
'/^https?:\/\//i', $value)) {
3539 $link = str_replace(
'{socialid}', $value, $dictsocialnetworks[$type][
'url']);
3541 $valuetoshow = $value;
3542 $valuetoshow = preg_replace(
'/https:\/\/www\.(twitter|x|linkedin)\.com\/?/',
'', $valuetoshow);
3543 if (preg_match(
'/^https?:\/\//i', $link)) {
3552 $htmllink .=
'</div>';
3554 $langs->load(
"errors");
3555 $htmllink .=
img_warning($langs->trans(
"ErrorBadSocialNetworkValue", $value));
3559 $parameters = array(
3561 'cid' => $contactid,
3564 'dictsocialnetworks' => $dictsocialnetworks,
3567 $reshook = $hookmanager->executeHooks(
'printSocialNetworks', $parameters);
3571 $htmllink .= $hookmanager->resPrint;
3586function dol_print_profids($profID, $profIDtype, $countrycode =
'', $addcpButton = 1)
3590 if (empty($profID) || empty($profIDtype)) {
3593 if (empty($countrycode)) {
3594 $countrycode =
$mysoc->country_code;
3596 $newProfID = $profID;
3597 $id = substr($profIDtype, -1);
3599 if (strtoupper($countrycode) ==
'FR') {
3605 $newProfID = substr($newProfID, 0, 3) .
' ' . substr($newProfID, 3, 3) .
' ' . substr($newProfID, 6, 3);
3609 $newProfID = substr($newProfID, 0, 3) .
' ' . substr($newProfID, 3, 3) .
' ' . substr($newProfID, 6, 3) .
' ' . substr($newProfID, 9, 5);
3613 $newProfID = substr($newProfID, 0, 2) .
'.' . substr($newProfID, 2, 3);
3615 if ($profIDtype ===
'VAT' &&
dol_strlen($newProfID) == 13) {
3617 $newProfID = substr($newProfID, 0, 4) .
' ' . substr($newProfID, 4, 3) .
' ' . substr($newProfID, 7, 3) .
' ' . substr($newProfID, 10, 3);
3620 if (!empty($addcpButton)) {
3643function dol_print_phone($phone, $countrycode =
'', $contactid = 0, $socid = 0, $addlink =
'', $separ =
" ", $withpicto =
'', $titlealt =
'', $adddivfloat = 0, $morecss =
'paddingright')
3645 global
$conf, $user, $langs,
$mysoc, $hookmanager;
3648 $phone = is_null($phone) ?
'' : preg_replace(
"/[\s.-]/",
"", trim($phone));
3649 if (empty($phone)) {
3655 if (empty($countrycode) && is_object(
$mysoc)) {
3656 $countrycode =
$mysoc->country_code;
3660 if (!empty(
$conf->dol_optimize_smallscreen) && $separ !=
'hidenum') {
3665 $newphonewa = $phone;
3666 if (strtoupper($countrycode) ==
"FR") {
3669 $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);
3671 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 2) . $separ . substr($newphone, 5, 2);
3673 $newphone = substr($newphone, 0, 2) . $separ . substr($newphone, 2, 3) . $separ . substr($newphone, 5, 2) . $separ . substr($newphone, 7, 2);
3675 $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);
3677 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 1) . $separ . substr($newphone, 4, 2) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 2) . $separ . substr($newphone, 10, 2);
3679 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 2) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 3) . $separ . substr($newphone, 11, 2);
3681 } elseif (strtoupper($countrycode) ==
"CA") {
3683 $newphone = ($separ !=
'' ?
'(' :
'') . substr($newphone, 0, 3) . ($separ !=
'' ?
')' :
'') . $separ . substr($newphone, 3, 3) . ($separ !=
'' ?
'-' :
'') . substr($newphone, 6, 4);
3685 } elseif (strtoupper($countrycode) ==
"PT") {
3687 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
3689 } elseif (strtoupper($countrycode) ==
"SR") {
3691 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3);
3693 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 4);
3695 } elseif (strtoupper($countrycode) ==
"DE") {
3697 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4) . $separ . substr($newphone, 7, 4) . $separ . substr($newphone, 11, 3);
3699 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 4) . $separ . substr($newphone, 10, 3);
3701 } elseif (strtoupper($countrycode) ==
"ES") {
3703 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
3705 } elseif (strtoupper($countrycode) ==
"BF") {
3707 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 1) . $separ . substr($newphone, 4, 2) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 2) . $separ . substr($newphone, 10, 2);
3709 } elseif (strtoupper($countrycode) ==
"RO") {
3711 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 2) . $separ . substr($newphone, 5, 3) . $separ . substr($newphone, 8, 2) . $separ . substr($newphone, 10, 2);
3713 } elseif (strtoupper($countrycode) ==
"TR") {
3715 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 4);
3717 } elseif (strtoupper($countrycode) ==
"US") {
3719 $newphone = substr($newphone, 0, 2) . $separ . substr($newphone, 2, 3) . $separ . substr($newphone, 5, 3) . $separ . substr($newphone, 8, 4);
3721 } elseif (strtoupper($countrycode) ==
"MX") {
3723 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 2);
3725 $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);
3727 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 4);
3729 } elseif (strtoupper($countrycode) ==
"ML") {
3731 $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);
3733 } elseif (strtoupper($countrycode) ==
"TH") {
3735 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 3);
3737 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 1) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 2) . $separ . substr($newphone, 9, 3);
3739 } elseif (strtoupper($countrycode) ==
"MU") {
3742 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 2) . $separ . substr($newphone, 9, 2);
3744 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 4) . $separ . substr($newphone, 8, 2) . $separ . substr($newphone, 10, 2);
3746 } elseif (strtoupper($countrycode) ==
"ZA") {
3748 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 2) . $separ . substr($newphone, 5, 3) . $separ . substr($newphone, 8, 2) . $separ . substr($newphone, 10, 2);
3750 } elseif (strtoupper($countrycode) ==
"SY") {
3752 $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);
3754 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 2) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 2) . $separ . substr($newphone, 10, 3);
3756 } elseif (strtoupper($countrycode) ==
"AE") {
3758 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 2);
3760 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
3762 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 4);
3764 } elseif (strtoupper($countrycode) ==
"DZ") {
3766 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
3768 } elseif (strtoupper($countrycode) ==
"BE") {
3770 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 3);
3772 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
3774 } elseif (strtoupper($countrycode) ==
"PF") {
3776 $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);
3778 } elseif (strtoupper($countrycode) ==
"CO") {
3780 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 2) . $separ . substr($newphone, 11, 2);
3782 } elseif (strtoupper($countrycode) ==
"JO") {
3784 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 1) . $separ . substr($newphone, 5, 3) . $separ . substr($newphone, 8, 2) . $separ . substr($newphone, 10, 2);
3786 } elseif (strtoupper($countrycode) ==
"JM") {
3788 $newphone = substr($newphone, 0, 5) . $separ . substr($newphone, 5, 3) . $separ . substr($newphone, 8, 4);
3790 } elseif (strtoupper($countrycode) ==
"MG") {
3792 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 2) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 3) . $separ . substr($newphone, 11, 2);
3794 } elseif (strtoupper($countrycode) ==
"GB") {
3796 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
3798 } elseif (strtoupper($countrycode) ==
"CH") {
3800 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 2) . $separ . substr($newphone, 5, 3) . $separ . substr($newphone, 8, 2) . $separ . substr($newphone, 10, 2);
3802 $newphone = $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 2) . $separ . substr($newphone, 5, 3) . $separ . substr($newphone, 8, 3) . $separ . substr($newphone, 11, 4);
3804 } elseif (strtoupper($countrycode) ==
"TN") {
3806 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 2) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
3808 } elseif (strtoupper($countrycode) ==
"GF") {
3810 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 2) . $separ . substr($newphone, 9, 2) . $separ . substr($newphone, 11, 2);
3812 } elseif (strtoupper($countrycode) ==
"GP") {
3814 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 2) . $separ . substr($newphone, 9, 2) . $separ . substr($newphone, 11, 2);
3816 } elseif (strtoupper($countrycode) ==
"MQ") {
3818 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 2) . $separ . substr($newphone, 9, 2) . $separ . substr($newphone, 11, 2);
3820 } elseif (strtoupper($countrycode) ==
"IT") {
3822 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
3824 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 2) . $separ . substr($newphone, 11, 2);
3826 } elseif (strtoupper($countrycode) ==
"AU") {
3830 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 1) . $separ . substr($newphone, 4, 4) . $separ . substr($newphone, 8, 4);
3832 } elseif (strtoupper($countrycode) ==
"LU") {
3835 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 2) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 2);
3837 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 2) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 2) . $separ . substr($newphone, 10, 1);
3839 $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);
3841 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 2) . $separ . substr($newphone, 9, 2) . $separ . substr($newphone, 11, 2);
3843 } elseif (strtoupper($countrycode) ==
"PE") {
3846 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4);
3848 $newphonewa =
'+51' . $newphone;
3849 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3);
3851 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 4);
3853 $newphonewa = $newphone;
3854 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
3856 } elseif (strtoupper($countrycode) ==
"IN") {
3858 if ($withpicto ==
'phone') {
3859 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 2) . $separ . substr($newphone, 5, 4) . $separ . substr($newphone, 9, 4);
3861 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 5) . $separ . substr($newphone, 8, 5);
3866 $newphoneastart = $newphoneaend =
'';
3867 if (!empty($addlink)) {
3869 $newphoneastart =
'<a href="tel:' . urlencode($phone) .
'">';
3870 $newphoneaend .=
'</a>';
3871 } elseif (
isModEnabled(
'clicktodial') && $addlink ==
'AC_TEL') {
3872 if (empty($user->clicktodial_loaded)) {
3873 $user->fetch_clicktodial();
3877 $urlmask =
getDolGlobalString(
'CLICKTODIAL_URL',
'ErrorClickToDialModuleNotConfigured');
3878 if (!empty($user->clicktodial_url)) {
3879 $urlmask = $user->clicktodial_url;
3882 $clicktodial_poste = (!empty($user->clicktodial_poste) ? urlencode($user->clicktodial_poste) :
'');
3883 $clicktodial_login = (!empty($user->clicktodial_login) ? urlencode($user->clicktodial_login) :
'');
3884 $clicktodial_password = (!empty($user->clicktodial_password) ? urlencode($user->clicktodial_password) :
'');
3886 $url = sprintf($urlmask, urlencode($phone), $clicktodial_poste, $clicktodial_login, $clicktodial_password);
3888 $substitarray = array(
3889 '__PHONEFROM__' => $clicktodial_poste,
3890 '__PHONETO__' => urlencode($phone),
3891 '__LOGIN__' => $clicktodial_login,
3892 '__PASS__' => $clicktodial_password
3897 $newphoneastart =
'<a href="' . $url .
'" class="cssforclicktodial">';
3898 $newphoneaend =
'</a>';
3901 $newphoneastart =
'<a href="' . $url .
'"';
3903 $newphoneastart .=
' target="_blank" rel="noopener noreferrer"';
3905 $newphoneastart .=
'>';
3906 $newphoneaend .=
'</a>';
3910 if (
isModEnabled(
'agenda') && $user->hasRight(
"agenda",
"myactions",
"create")) {
3912 $addlinktoagenda =
'';
3913 if ($addlink ==
'AC_FAX') {
3917 $addlinktoagenda =
'<a href="' . DOL_URL_ROOT .
'/comm/action/card.php?action=create&backtopage=' . urlencode($_SERVER[
'REQUEST_URI']) .
'&actioncode=' . $type . ($contactid ?
'&contactid=' . $contactid :
'') . ($socid ?
'&socid=' . $socid :
'') .
'">' .
img_object($langs->trans(
"AddAction"),
"calendar") .
'</a>';
3919 if ($addlinktoagenda) {
3920 $newphone =
'<span>' . $newphone .
' ' . $addlinktoagenda .
'</span>';
3925 if (
getDolGlobalString(
'CONTACT_PHONEMOBILE_SHOW_LINK_TO_WHATSAPP') && $withpicto ==
'mobile') {
3927 $newphone .=
' <a href="https://wa.me/' . $newphonewa .
'" target="_blank"';
3928 $newphone .=
'><span class="paddingright fab fa-whatsapp" style="color:#25D366;" title="WhatsApp"></span></a>';
3931 if (empty($titlealt)) {
3932 $titlealt = ($withpicto ==
'fax' ? $langs->trans(
"Fax") : $langs->trans(
"Phone"));
3937 $parameters = array(
'countrycode' => $countrycode,
'cid' => $contactid,
'socid' => $socid,
'titlealt' => $titlealt,
'picto' => $withpicto);
3938 $reshook = $hookmanager->executeHooks(
'printPhone', $parameters, $phone);
3939 $rep .= $hookmanager->resPrint;
3941 if (empty($reshook)) {
3944 if ($withpicto ==
'fax') {
3945 $picto =
'phoning_fax';
3946 } elseif ($withpicto ==
'phone') {
3948 } elseif ($withpicto ==
'mobile') {
3949 $picto =
'phoning_mobile';
3954 if ($adddivfloat == 1) {
3955 $rep .=
'<div class="nospan float' . ($morecss ?
' ' . $morecss :
'') .
'">';
3956 } elseif (empty($adddivfloat)) {
3957 $rep .=
'<span' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
'>';
3960 $rep .= $newphoneastart;
3961 $rep .= ($withpicto ?
img_picto($titlealt, $picto) :
'');
3962 if ($separ !=
'hidenum') {
3963 $rep .= ($withpicto ?
' ' :
'') . $newphone;
3965 $rep .= $newphoneaend;
3967 if ($adddivfloat == 1) {
3969 } elseif (empty($adddivfloat)) {
3990 if (!isset(
$conf->cache[
'resolveips'])) {
3991 $conf->cache[
'resolveips'] = array();
3997 if (file_exists(DOL_DOCUMENT_ROOT .
'/theme/common/flags/' . $countrycode .
'.png')) {
4000 $ret .=
'(' . $countrycode .
')';
4008 if (in_array($mode, [0, 2])) {
4011 if (!array_key_exists($ip,
$conf->cache[
'resolveips'])) {
4012 $domain = gethostbyaddr($ip);
4013 $conf->cache[
'resolveips'][$ip] = $domain;
4015 $domain =
$conf->cache[
'resolveips'][$ip];
4043 $ip = (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']);
4050 if (empty($_SERVER[
'HTTP_X_FORWARDED_FOR']) || preg_match(
'/[^0-9\.\:,\[\]\s]/', $_SERVER[
'HTTP_X_FORWARDED_FOR'])) {
4051 if (empty($_SERVER[
'HTTP_CLIENT_IP']) || preg_match(
'/[^0-9\.\:,\[\]\s]/', $_SERVER[
'HTTP_CLIENT_IP'])) {
4052 if (empty($_SERVER[
"HTTP_CF_CONNECTING_IP"])) {
4053 $ip = (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']);
4055 $ip = $_SERVER[
"HTTP_CF_CONNECTING_IP"];
4058 $ip = preg_replace(
'/,.*$/',
'', $_SERVER[
'HTTP_CLIENT_IP']);
4061 $ip = preg_replace(
'/,.*$/',
'', $_SERVER[
'HTTP_X_FORWARDED_FOR']);
4081 $datafile = $diroffile .
'/' .
getDolGlobalString(
'GEOIPMAXMIND_COUNTRY_DATAFILE_EMBEDDED');
4087 include_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeoip.class.php';
4088 $geoip =
new DolGeoIP(
'country', $datafile);
4090 $countrycode = $geoip->getCountryCodeFromIP($ip);
4097 return $countrycode;
4116 include_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeoip.class.php';
4117 $geoip =
new DolGeoIP(
'country', $datafile);
4118 $countrycode = $geoip->getCountryCodeFromIP($ip);
4119 $ret = $countrycode;
4138 global $hookmanager;
4144 $parameters = array(
'element' => $element,
'id' =>
$id);
4145 $reshook = $hookmanager->executeHooks(
'printAddress', $parameters, $address);
4146 $out .= $hookmanager->resPrint;
4148 if (empty($reshook)) {
4149 if (empty($charfornl)) {
4150 $out .= nl2br((
string) $address);
4152 $out .= preg_replace(
'/[\r\n]+/', $charfornl, (
string) $address);
4156 $showgmap = $showomap = 0;
4182 $url =
dol_buildpath(
'/google/gmaps.php?mode=' . $element .
'&id=' .
$id, 1);
4183 $out .=
' <a href="' . $url .
'" target="_gmaps"><img id="' . $htmlid .
'" class="valigntextbottom" src="' . DOL_URL_ROOT .
'/theme/common/gmap.png"></a>';
4186 $url =
dol_buildpath(
'/openstreetmap/maps.php?mode=' . $element .
'&id=' .
$id, 1);
4187 $out .=
' <a href="' . $url .
'" target="_gmaps"><img id="' . $htmlid .
'_openstreetmap" class="valigntextbottom" src="' . DOL_URL_ROOT .
'/theme/common/gmap.png"></a>';
4209function isValidEmail($address, $acceptsupervisorkey = 0, $acceptuserkey = 0)
4211 if ($acceptsupervisorkey && $address ==
'__SUPERVISOREMAIL__') {
4214 if ($acceptuserkey && $address ==
'__USER_EMAIL__') {
4217 if (filter_var($address, FILTER_VALIDATE_EMAIL)) {
4235 if (function_exists(
'idn_to_ascii') && function_exists(
'checkdnsrr')) {
4236 if (!checkdnsrr(idn_to_ascii($domain),
'MX')) {
4239 if (function_exists(
'getmxrr')) {
4242 getmxrr(idn_to_ascii($domain), $mxhosts, $weight);
4243 if (count($mxhosts) > 1) {
4246 if (count($mxhosts) == 1 && !in_array((
string) $mxhosts[0], array(
'',
'.'))) {
4283 $tmparray = explode(
' ', $s);
4284 foreach ($tmparray as $tmps) {
4299function dol_strlen($string, $stringencoding =
'UTF-8')
4301 if (is_null($string)) {
4305 if (function_exists(
'mb_strlen')) {
4306 return mb_strlen($string, $stringencoding);
4308 return strlen($string);
4322function dol_substr($string, $start, $length =
null, $stringencoding =
'', $trunconbytes = 0)
4326 if (empty($stringencoding)) {
4327 $stringencoding = (empty($langs) ?
'UTF-8' : $langs->charset_output);
4331 if (empty($trunconbytes)) {
4332 if (function_exists(
'mb_substr')) {
4333 $ret = mb_substr($string, $start, $length, $stringencoding);
4335 $ret = substr($string, $start, $length);
4338 if (function_exists(
'mb_strcut')) {
4339 $ret = mb_strcut($string, $start, $length, $stringencoding);
4341 $ret = substr($string, $start, $length);
4361function dol_trunc($string, $size = 40, $trunc =
'right', $stringencoding =
'UTF-8', $nodot = 0, $display = 0)
4369 if (empty($stringencoding)) {
4370 $stringencoding =
'UTF-8';
4373 if (!empty(
$conf->dol_optimize_smallscreen) &&
$conf->dol_optimize_smallscreen == 1 && $display == 1) {
4374 $size = round($size / 3);
4378 if ($trunc ==
'right') {
4380 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
4382 return dol_substr($newstring, 0, $size, $stringencoding) . ($nodot ?
'' :
'…');
4387 } elseif ($trunc ==
'middle') {
4389 if (
dol_strlen($newstring, $stringencoding) > 2 &&
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
4390 $size1 = (int) round($size / 2);
4391 $size2 = (int) round($size / 2);
4392 return dol_substr($newstring, 0, $size1, $stringencoding) .
'…' .
dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size2, $size2, $stringencoding);
4396 } elseif ($trunc ==
'left') {
4398 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
4400 return '…' .
dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size, $size, $stringencoding);
4404 } elseif ($trunc ==
'wrap') {
4406 if (
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
4412 return 'BadParam3CallingDolTrunc';
4428function vatrate($rate, $addpercent =
false, $info_bits = 0, $usestarfornpr = 0, $html = 0)
4432 if (preg_match(
'/%/', $rate)) {
4433 $rate = str_replace(
'%',
'', $rate);
4437 if (preg_match(
'/\((.*)\)/', $rate, $reg)) {
4438 $morelabel =
' (' . $reg[1] .
')';
4439 $rate = preg_replace(
'/\s*' . preg_quote($morelabel,
'/') .
'/',
'', $rate);
4440 $morelabel =
' ' . ($html ?
'<span class="opacitymedium small">' :
'') .
'(' . $reg[1] .
')' . ($html ?
'</span>' :
'');
4442 if (preg_match(
'/\*/', $rate)) {
4443 $rate = str_replace(
'*',
'', $rate);
4448 if (!preg_match(
'/\//', $rate)) {
4449 $ret =
price($rate, 0,
'', 0, 0) . ($addpercent ?
'%' :
'');
4452 $ret = $rate . ($addpercent ?
'%' :
'');
4454 if (($info_bits & 1) && $usestarfornpr >= 0) {
4476function price($amount, $form = 0, $outlangs =
'', $trunc = 1, $rounding = -1, $forcerounding = -1, $currency_code =
'')
4478 global $langs,
$conf;
4481 if (empty($amount)) {
4484 $amount = (is_numeric($amount) ? $amount : 0);
4485 if ($rounding == -1) {
4488 $nbdecimal = $rounding;
4490 if ($outlangs ===
'none') {
4500 if (!($outlangs instanceof
Translate)) {
4504 if ($outlangs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
4505 $dec = $outlangs->transnoentitiesnoconv(
"SeparatorDecimal");
4507 if ($outlangs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
4508 $thousand = $outlangs->transnoentitiesnoconv(
"SeparatorThousand");
4510 if ($thousand ==
'None') {
4512 } elseif ($thousand ==
'Space') {
4519 $amount = str_replace(
',',
'.', $amount);
4521 $data = explode(
'.', $amount);
4522 $decpart = isset($data[1]) ? $data[1] :
'';
4523 $decpart = preg_replace(
'/0+$/i',
'', $decpart);
4533 $nbdecimalmaxshown = (int) str_replace(
'...',
'',
getDolGlobalString(
'MAIN_MAX_DECIMALS_SHOWN'));
4534 if ($trunc && $nbdecimal > $nbdecimalmaxshown) {
4535 $nbdecimal = $nbdecimalmaxshown;
4543 if ((
string) $forcerounding !=
'-1' && (
string) $forcerounding !=
'') {
4544 if ($forcerounding ===
'MU') {
4546 } elseif ($forcerounding ===
'MT') {
4548 } elseif ($forcerounding >= 0) {
4549 $nbdecimal = (int) $forcerounding;
4554 $output = number_format((
float) $amount, $nbdecimal, $dec, $thousand);
4556 $cursymbolbefore = $cursymbolafter =
'';
4557 if ($currency_code && is_object($outlangs)) {
4558 if ($currency_code ==
'auto') {
4559 $currency_code =
$conf->currency;
4562 $listofcurrenciesbefore = array(
'AUD',
'CAD',
'CNY',
'COP',
'CLP',
'GBP',
'HKD',
'MXN',
'PEN',
'USD',
'CRC',
'ZAR');
4563 $listoflanguagesbefore = array(
'nl_NL');
4564 if (in_array($currency_code, $listofcurrenciesbefore) || in_array($outlangs->defaultlang, $listoflanguagesbefore)) {
4565 $cursymbolbefore .= $outlangs->getCurrencySymbol($currency_code);
4567 $tmpcur = $outlangs->getCurrencySymbol($currency_code);
4568 $cursymbolafter .= ($tmpcur == $currency_code ?
' ' . $tmpcur : $tmpcur);
4572 $output = preg_replace(
'/\s/',
' ', $output);
4573 $output = $cursymbolbefore . $output . $end . ($cursymbolafter ?
' <span class="small">'.$cursymbolafter.
'</span>' :
'');
4574 $output = preg_replace(
'/\'/',
''', $output);
4576 $output = $cursymbolbefore . $output . $end . ($cursymbolafter ?
' '.$cursymbolafter :
'');
4607function price2num($amount, $rounding =
'', $option = 0)
4612 if (is_null($amount)) {
4621 if (is_null($langs)) {
4625 if ($langs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
4626 $dec = $langs->transnoentitiesnoconv(
"SeparatorDecimal");
4628 if ($langs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
4629 $thousand = $langs->transnoentitiesnoconv(
"SeparatorThousand");
4632 if ($thousand ==
'None') {
4634 } elseif ($thousand ==
'Space') {
4642 if (!is_numeric($amount)) {
4643 $amount = preg_replace(
'/[a-zA-Z\/\\\*\(\)<>\_]/',
'', $amount);
4646 if ($option == 2 && $thousand ==
'.' && preg_match(
'/\.(\d\d\d)$/', (
string) $amount)) {
4647 $amount = str_replace($thousand,
'', $amount);
4653 if (is_numeric($amount)) {
4655 $temps = sprintf(
"%10.10F", $amount - intval($amount));
4656 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
4658 $amount = number_format($amount, $nbofdec, $dec, $thousand);
4664 if ($thousand !=
',' && $thousand !=
'.') {
4677 if (preg_match(
'/^(?<int>[^,]*,|[^.]*\.)(?<dec>[^.,]*)$/u', $amount, $matches)) {
4678 $intPart = $matches[
'int'];
4679 $decPart = $matches[
'dec'];
4682 $intPart = str_replace([
'.',
','],
'', $intPart);
4685 $amount = $intPart . $dec . $decPart;
4689 $amount = str_replace(
' ',
'', $amount);
4690 $amount = str_replace($thousand,
'', $amount);
4691 $amount = str_replace($dec,
'.', $amount);
4693 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
4699 $nbofdectoround =
'';
4700 if ($rounding ==
'MU') {
4702 } elseif ($rounding ==
'MT') {
4704 } elseif ($rounding ==
'MS') {
4706 } elseif ($rounding ==
'CU') {
4708 } elseif ($rounding ==
'CT') {
4710 } elseif (is_numeric($rounding)) {
4711 $nbofdectoround = (int) $rounding;
4716 $amount = round(is_string($amount) ? (
float) $amount : $amount, $nbofdectoround);
4718 return 'ErrorBadParameterProvidedToFunction';
4724 if (is_numeric($amount)) {
4726 $temps = sprintf(
"%10.10F", $amount - intval($amount));
4727 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
4729 $amount = number_format($amount, min($nbofdec, $nbofdectoround), $dec, $thousand);
4735 if ($thousand !=
',' && $thousand !=
'.') {
4736 $amount = str_replace(
',',
'.', $amount);
4739 $amount = str_replace(
' ',
'', $amount);
4740 $amount = str_replace($thousand,
'', $amount);
4741 $amount = str_replace($dec,
'.', $amount);
4743 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
4762function get_localtax($vatrate, $local, $thirdparty_buyer =
null, $thirdparty_seller =
null, $vatnpr = 0)
4766 if (empty($thirdparty_seller) || !is_object($thirdparty_seller)) {
4767 $thirdparty_seller =
$mysoc;
4771 "get_localtax tva=" . $vatrate .
" local=" . $local
4772 .
" thirdparty_buyer id=" . (is_object($thirdparty_buyer) ? $thirdparty_buyer->id :
'') .
"/country_code=" . (is_object($thirdparty_buyer) ? $thirdparty_buyer->country_code :
'')
4773 .
" thirdparty_seller id=" . $thirdparty_seller->id .
"/country_code=" . $thirdparty_seller->country_code
4774 .
" thirdparty_seller localtax1_assuj=" . $thirdparty_seller->localtax1_assuj .
" thirdparty_seller localtax2_assuj=" . $thirdparty_seller->localtax2_assuj
4777 $vatratecleaned = $vatrate;
4779 if (preg_match(
'/^(.*)\s*\((.*)\)$/', (
string) $vatrate, $reg)) {
4780 $vatratecleaned = trim($reg[1]);
4781 $vatratecode = $reg[2];
4790 if (
$mysoc->country_code ==
'ES') {
4792 if (!
$mysoc->localtax1_assuj || (
string) $vatratecleaned ==
"0") {
4795 if ($thirdparty_seller->id ==
$mysoc->id) {
4796 if (!$thirdparty_buyer->localtax1_assuj) {
4800 if (!$thirdparty_seller->localtax1_assuj) {
4808 if (!
$mysoc->localtax2_assuj) {
4811 if ($thirdparty_seller->id ==
$mysoc->id) {
4812 if (!$thirdparty_buyer->localtax2_assuj) {
4816 if (!$thirdparty_seller->localtax2_assuj) {
4822 if ($local == 1 && !$thirdparty_seller->localtax1_assuj) {
4825 if ($local == 2 && !$thirdparty_seller->localtax2_assuj) {
4831 if (in_array(
$mysoc->country_code, array(
'ES'))) {
4832 $conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY = 1;
4838 if ($thirdparty_seller !=
$mysoc) {
4840 return $thirdparty_seller->localtax1_value;
4849 if ($thirdparty_seller !=
$mysoc) {
4852 return $thirdparty_seller->localtax2_value;
4855 if (in_array(
$mysoc->country_code, array(
'ES'))) {
4856 return $thirdparty_buyer->localtax2_value;
4865 $sql =
"SELECT t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
4866 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t, " . MAIN_DB_PREFIX .
"c_country as c";
4867 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '" .
$db->escape($thirdparty_seller->country_code) .
"'";
4868 $sql .=
" AND t.taux = " . ((float) $vatratecleaned) .
" AND t.active = 1";
4869 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
4870 if (!empty($vatratecode)) {
4871 $sql .=
" AND t.code ='" .
$db->escape($vatratecode) .
"'";
4873 $sql .=
" AND t.recuperableonly = '" .
$db->escape((
string) $vatnpr) .
"'";
4876 $resql =
$db->query($sql);
4879 $obj =
$db->fetch_object($resql);
4882 return $obj->localtax1;
4883 } elseif ($local == 2) {
4884 return $obj->localtax2;
4905 $valors = explode(
":", $tax);
4907 if (count($valors) > 1) {
4924 $sql =
" SELECT t.localtax" . ((int) $local) .
" as localtax";
4925 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t INNER JOIN " . MAIN_DB_PREFIX .
"c_country as c ON c.rowid = t.fk_pays";
4926 $sql .=
" WHERE c.code = '" .
$db->escape(
$mysoc->country_code) .
"' AND t.active = 1 AND t.entity IN (" .
getEntity(
'c_tva') .
") AND t.taux = (";
4927 $sql .=
"SELECT MAX(tt.taux) FROM " . MAIN_DB_PREFIX .
"c_tva as tt INNER JOIN " . MAIN_DB_PREFIX .
"c_country as c ON c.rowid = tt.fk_pays";
4928 $sql .=
" WHERE c.code = '" .
$db->escape(
$mysoc->country_code) .
"' AND t.entity IN (" .
getEntity(
'c_tva') .
") AND tt.active = 1)";
4929 $sql .=
" AND t.localtax" . ((int) $local) .
"_type <> '0'";
4930 $sql .=
" ORDER BY t.rowid DESC";
4932 $resql =
$db->query($sql);
4934 $obj =
$db->fetch_object($resql);
4936 return $obj->localtax;
4957function getTaxesFromId($vatrate, $buyer =
null, $seller =
null, $firstparamisid = 1)
4961 dol_syslog(
"getTaxesFromId vat id or rate = " . $vatrate);
4964 $sql =
"SELECT t.rowid, t.code, t.taux as rate, t.recuperableonly as npr, t.accountancy_code_sell, t.accountancy_code_buy,";
4965 $sql .=
" t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type";
4966 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t";
4967 if ($firstparamisid) {
4968 $sql .=
" WHERE t.rowid = " . (int) $vatrate;
4970 $vatratecleaned = $vatrate;
4973 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
4974 $vatratecleaned = $reg[1];
4975 $vatratecode = $reg[2];
4978 $sql .=
", " . MAIN_DB_PREFIX .
"c_country as c";
4981 $sql .=
" WHERE t.fk_pays = c.rowid";
4983 $sql .=
" AND c.code = '" .
$db->escape($buyer->country_code) .
"'";
4985 $sql .=
" AND c.code = '" .
$db->escape($seller->country_code) .
"'";
4987 $sql .=
" AND t.taux = " . ((float) $vatratecleaned) .
" AND t.active = 1";
4988 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
4990 $sql .=
" AND t.code = '" .
$db->escape($vatratecode) .
"'";
4994 $resql =
$db->query($sql);
4996 $obj =
$db->fetch_object($resql);
4999 'rowid' => $obj->rowid,
5000 'code' => $obj->code,
5001 'rate' => $obj->rate,
5002 'localtax1' => $obj->localtax1,
5003 'localtax1_type' => $obj->localtax1_type,
5004 'localtax2' => $obj->localtax2,
5005 'localtax2_type' => $obj->localtax2_type,
5007 'accountancy_code_sell' => $obj->accountancy_code_sell,
5008 'accountancy_code_buy' => $obj->accountancy_code_buy
5040 dol_syslog(
"getLocalTaxesFromRate vatrate=" . $vatrate .
" local=" . $local);
5043 $sql =
"SELECT t.taux as rate, t.code, t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.accountancy_code_sell, t.accountancy_code_buy";
5044 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t";
5045 if ($firstparamisid) {
5046 $sql .=
" WHERE t.rowid = " . (int) $vatrate;
5048 $vatratecleaned = $vatrate;
5051 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
5052 $vatratecleaned = $reg[1];
5053 $vatratecode = $reg[2];
5056 $sql .=
", " . MAIN_DB_PREFIX .
"c_country as c";
5058 $countrycodetouse = ((empty($buyer) || empty($buyer->country_code)) ?
$mysoc->country_code : $buyer->country_code);
5059 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '" .
$db->escape($countrycodetouse) .
"'";
5061 $countrycodetouse = ((empty($seller) || empty($seller->country_code)) ?
$mysoc->country_code : $seller->country_code);
5062 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '" .
$db->escape($countrycodetouse) .
"'";
5064 $sql .=
" AND t.taux = " . ((float) $vatratecleaned) .
" AND t.active = 1";
5066 $sql .=
" AND t.code = '" .
$db->escape($vatratecode) .
"'";
5070 $resql =
$db->query($sql);
5072 $obj =
$db->fetch_object($resql);
5075 $vateratestring = $obj->rate . ($obj->code ?
' (' . $obj->code .
')' :
'');
5078 return array($obj->localtax1_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
5079 } elseif ($local == 2) {
5080 return array($obj->localtax2_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
5082 return array($obj->localtax1_type,
get_localtax($vateratestring, 1, $buyer, $seller), $obj->localtax2_type,
get_localtax($vateratestring, 2, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
5104 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
5112 $product->fetch($idprod);
5114 if ((
$mysoc->country_code == $thirdpartytouseforcountry->country_code)
5115 || (in_array(
$mysoc->country_code, array(
'FR',
'MC')) && in_array($thirdpartytouseforcountry->country_code, array(
'FR',
'MC')))
5116 || (in_array(
$mysoc->country_code, array(
'MQ',
'GP')) && in_array($thirdpartytouseforcountry->country_code, array(
'MQ',
'GP')))
5119 if ($idprodfournprice > 0) {
5120 $result = $product->get_buyprice($idprodfournprice, 0, 0,
'');
5122 $ret = $product->vatrate_supplier;
5123 if ($product->default_vat_code_supplier) {
5124 $ret .=
' (' . $product->default_vat_code_supplier .
')';
5130 $ret = $product->tva_tx;
5131 if ($product->default_vat_code) {
5132 $ret .=
' (' . $product->default_vat_code .
')';
5145 $sql =
"SELECT t.taux as vat_rate, t.code as default_vat_code";
5146 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t, " . MAIN_DB_PREFIX .
"c_country as c";
5147 $sql .=
" WHERE t.active = 1 AND t.fk_pays = c.rowid AND c.code = '" .
$db->escape($thirdpartytouseforcountry->country_code) .
"'";
5148 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
5149 $sql .=
" ORDER BY t.use_default DESC, t.taux DESC, t.code ASC, t.recuperableonly ASC";
5150 $sql .=
$db->plimit(1);
5152 $resql =
$db->query($sql);
5154 $obj =
$db->fetch_object($resql);
5156 $ret = $obj->vat_rate;
5157 if ($obj->default_vat_code) {
5158 $ret .=
' (' . $obj->default_vat_code .
')';
5182 dol_syslog(
"get_product_vat_for_country: ret=" . $ret);
5200 if (!class_exists(
'Product')) {
5201 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
5210 $result = $product->fetch($idprod);
5212 if (
$mysoc->country_code == $thirdpartytouseforcountry->country_code) {
5226 $sql =
"SELECT taux as vat_rate, localtax1, localtax2";
5227 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t, " . MAIN_DB_PREFIX .
"c_country as c";
5228 $sql .=
" WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code='" .
$db->escape($thirdpartytouseforcountry->country_code) .
"'";
5229 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
5230 $sql .=
" ORDER BY t.taux DESC, t.recuperableonly ASC";
5231 $sql .=
$db->plimit(1);
5233 $resql =
$db->query($sql);
5235 $obj =
$db->fetch_object($resql);
5238 $ret = $obj->localtax1;
5239 } elseif ($local == 2) {
5240 $ret = $obj->localtax2;
5248 dol_syslog(
"get_product_localtax_for_country: ret=" . $ret);
5274 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
5277 $seller_use_vat = ((is_numeric($thirdparty_seller->tva_assuj) && !$thirdparty_seller->tva_assuj) || (!is_numeric($thirdparty_seller->tva_assuj) && $thirdparty_seller->tva_assuj ==
'franchise')) ? 0 : 1;
5279 if (empty($thirdparty_seller->country_code)) {
5280 $thirdparty_seller->country_code =
$mysoc->country_code;
5282 $seller_country_code = $thirdparty_seller->country_code;
5283 $seller_in_cee =
isInEEC($thirdparty_seller);
5285 if (empty($thirdparty_buyer->country_code)) {
5286 $thirdparty_buyer->country_code =
$mysoc->country_code;
5288 $buyer_country_code = $thirdparty_buyer->country_code;
5289 $buyer_in_cee =
isInEEC($thirdparty_buyer);
5292 "get_default_tva: seller use vat=" . $seller_use_vat .
", seller country=" . $seller_country_code .
", seller in cee=" . ((
string) (
int) $seller_in_cee)
5293 .
", buyer vat number=" . $thirdparty_buyer->tva_intra .
" buyer country=" . $buyer_country_code .
", buyer state=" . $thirdparty_buyer->state_id .
" buyer in cee=" . ((
string) (
int) $buyer_in_cee)
5294 .
", idprod=" . $idprod .
", idprodfournprice=" . $idprodfournprice .
", SERVICE_ARE_ECOMMERCE_200238EC=" .
getDolGlobalString(
'SERVICE_ARE_ECOMMERCE_200238EC')
5303 if ($seller_in_cee && $buyer_in_cee) {
5304 $isacompany = $thirdparty_buyer->
isACompany();
5305 if ($isacompany && !
getDolGlobalString(
'MAIN_USE_VAT_ZERO_FOR_COMPANIES_IN_EEC_EVEN_IF_VAT_ID_UNKNOWN')) {
5306 require_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
5314 $vatrule =
'VATRULE 0';
5320 if (empty($vatrule) && !$seller_use_vat) {
5328 $vatrule =
'VATRULE 1';
5332 if (empty($vatrule) && !empty($thirdparty_buyer->state_id)) {
5333 $sql =
"SELECT d.rowid, t.taux as vat_default_rate, t.code as vat_default_code ";
5334 $sql .=
" FROM " .
$db->prefix() .
"c_tva as t";
5335 $sql .=
" INNER JOIN " .
$db->prefix() .
"c_departements as d ON t.fk_department_buyer = d.rowid";
5336 $sql .=
" WHERE d.rowid = " . ((int) $thirdparty_buyer->state_id);
5337 $sql .=
" AND t.active > 0";
5338 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
5339 $sql .=
" ORDER BY t.use_default DESC, t.taux DESC, t.code ASC, t.recuperableonly ASC";
5341 $res =
$db->query($sql);
5343 if (
$db->num_rows($res)) {
5344 $obj =
$db->fetch_object($res);
5346 $vatvalue = $obj->vat_default_rate .
' (' . $obj->vat_default_code .
')';
5347 $vatrule =
'VATRULE 2';
5354 if (empty($vatrule) && (
5355 ($seller_country_code == $buyer_country_code)
5356 || (in_array($seller_country_code, array(
'FR',
'MC')) && in_array($buyer_country_code, array(
'FR',
'MC')))
5357 || (in_array($seller_country_code, array(
'MQ',
'GP')) && in_array($buyer_country_code, array(
'MQ',
'GP')))
5362 if ($seller_country_code ==
'IN' &&
getDolGlobalString(
'MAIN_SALETAX_AUTOSWITCH_I_CS_FOR_INDIA')) {
5366 if (preg_match(
'/C+S-(\d+)/', $tmpvat, $reg) && $thirdparty_seller->state_id != $thirdparty_buyer->state_id) {
5368 $tmpvat = str_replace(
"C+S",
"I", $tmpvat);
5369 } elseif (preg_match(
'/I-(\d+)/', $tmpvat, $reg) && $thirdparty_seller->state_id == $thirdparty_buyer->state_id) {
5371 $tmpvat = str_replace(
"I",
"C+S", $tmpvat);
5375 $vatvalue = $tmpvat;
5376 $vatrule =
'VATRULE 3b';
5384 if (empty($vatrule) && ($seller_in_cee && $buyer_in_cee)) {
5385 $isacompany = $thirdparty_buyer->
isACompany();
5386 if ($isacompany && !
getDolGlobalString(
'MAIN_USE_VAT_ZERO_FOR_COMPANIES_IN_EEC_EVEN_IF_VAT_ID_UNKNOWN')) {
5387 require_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
5396 $vatrule =
'VATRULE 5';
5403 $vatrule =
'VATRULE 6';
5409 if (empty($vatrule) &&
getDolGlobalString(
'MAIN_USE_VAT_OF_PRODUCT_FOR_INDIVIDUAL_CUSTOMER_OUT_OF_EEC') && empty($buyer_in_cee)) {
5410 $isacompany = $thirdparty_buyer->
isACompany();
5413 $vatrule =
'VATRULE extra';
5426 $parameters = array(
'vatvalue' => $vatvalue,
'vatrule' => $vatrule);
5430 $reshook = $hookmanager->executeHooks(
'get_default_tva', $parameters, $tmpobject, $tmpaction);
5431 if ($reshook > 0 && !empty($hookmanager->resArray[
'vatvalue'])) {
5432 $vatvalue = $hookmanager->resArray[
'vatvalue'];
5433 $vatrule = $hookmanager->resArray[
'vatrule'];
5454 if ($idprodfournprice > 0) {
5455 if (!class_exists(
'ProductFournisseur')) {
5456 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.product.class.php';
5459 $prodprice->fetch_product_fournisseur_price($idprodfournprice);
5460 return $prodprice->fourn_tva_npr;
5461 } elseif ($idprod > 0) {
5462 if (!class_exists(
'Product')) {
5463 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
5466 $prod->fetch($idprod);
5467 return $prod->tva_npr;
5490 if (!is_object($thirdparty_seller)) {
5493 if (!is_object($thirdparty_buyer)) {
5497 if (empty($thirdparty_seller->country_code)) {
5498 $thirdparty_seller->country_code =
$mysoc->country_code;
5500 $seller_country_code = $thirdparty_seller->country_code;
5503 if (empty($thirdparty_buyer->country_code)) {
5504 $thirdparty_buyer->country_code =
$mysoc->country_code;
5506 $buyer_country_code = $thirdparty_buyer->country_code;
5510 if (
$mysoc->country_code ==
'ES') {
5511 if (is_numeric($thirdparty_buyer->localtax1_assuj) && !$thirdparty_buyer->localtax1_assuj) {
5516 if (is_numeric($thirdparty_seller->localtax1_assuj) && !$thirdparty_seller->localtax1_assuj) {
5519 if (!is_numeric($thirdparty_seller->localtax1_assuj) && $thirdparty_seller->localtax1_assuj ==
'localtax1off') {
5523 } elseif ($local == 2) {
5525 if (is_numeric($thirdparty_seller->localtax2_assuj) && !$thirdparty_seller->localtax2_assuj) {
5528 if (!is_numeric($thirdparty_seller->localtax2_assuj) && $thirdparty_seller->localtax2_assuj ==
'localtax2off') {
5533 if ($seller_country_code == $buyer_country_code) {
5559function get_exdir($num, $level, $alpha, $withoutslash,
$object, $modulepart =
'')
5561 if (empty($modulepart) && is_object(
$object)) {
5562 if (!empty(
$object->module)) {
5563 $modulepart =
$object->module;
5564 } elseif (!empty(
$object->element)) {
5565 $modulepart =
$object->element;
5572 $arrayforoldpath = array(
'cheque' => 2,
'category' => 2,
'supplier_invoice' => 2,
'invoice_supplier' => 2,
'mailing' => 2,
'supplier_payment' => 2);
5574 $arrayforoldpath[
'product'] = 2;
5577 if (empty($level) && array_key_exists($modulepart, $arrayforoldpath)) {
5578 $level = $arrayforoldpath[$modulepart];
5580 if (!empty($level) && array_key_exists($modulepart, $arrayforoldpath)) {
5582 if (empty($num) && is_object(
$object)) {
5585 if (empty($alpha)) {
5586 $num = preg_replace(
'/([^0-9])/i',
'', $num);
5588 $num = preg_replace(
'/^.*\-/i',
'', $num);
5590 $num = substr(
"000" . $num, -$level);
5592 $path = substr($num, 0, 1);
5595 $path = substr($num, 1, 1) .
'/' . substr($num, 0, 1);
5598 $path = substr($num, 2, 1) .
'/' . substr($num, 1, 1) .
'/' . substr($num, 0, 1);
5604 if (in_array($modulepart, array(
'societe',
'thirdparty')) &&
$object instanceof
Societe) {
5612 if (empty($withoutslash) && !empty($path)) {
5627function dol_mkdir($dir, $dataroot =
'', $newmask =
'')
5629 dol_syslog(
"functions.lib::dol_mkdir: dir=" . $dir, LOG_INFO);
5634 if (@is_dir($dir_osencoded)) {
5642 if (!empty($dataroot)) {
5644 $dir = str_replace($dataroot .
'/',
'', $dir);
5645 $ccdir = $dataroot .
'/';
5648 $cdir = explode(
"/", $dir);
5649 $num = count($cdir);
5650 for ($i = 0; $i < $num; $i++) {
5652 $ccdir .=
'/' . $cdir[$i];
5654 $ccdir .= $cdir[$i];
5657 if (preg_match(
"/^.:$/", $ccdir, $regs)) {
5665 if (!@is_dir($ccdir_osencoded)) {
5666 dol_syslog(
"functions.lib::dol_mkdir: Directory '" . $ccdir .
"' is not found (does not exists or is outside open_basedir PHP setting).", LOG_DEBUG);
5669 $dirmaskdec = octdec((
string) $newmask);
5670 if (empty($newmask)) {
5673 $dirmaskdec |= octdec(
'0111');
5674 if (!@mkdir($ccdir_osencoded, $dirmaskdec)) {
5676 dol_syslog(
"functions.lib::dol_mkdir: Fails to create directory '" . $ccdir .
"' (no permission to write into parent or directory already exists).", LOG_WARNING);
5679 dol_syslog(
"functions.lib::dol_mkdir: Directory '" . $ccdir .
"' created", LOG_DEBUG);
5688 return ($nberr ? -$nberr : $nbcreated);
5699function dolChmod($filepath, $newmask =
'')
5701 if (!empty($newmask)) {
5702 @chmod($filepath, octdec($newmask));
5716 return '<span class="fieldrequired">*</span>';
5736function dol_string_nohtmltag($stringtoclean, $removelinefeed = 1, $pagecodeto =
'UTF-8', $strip_tags = 0, $removedoublespaces = 1)
5738 if (is_null($stringtoclean)) {
5742 if ($removelinefeed == 2) {
5743 $stringtoclean = preg_replace(
'/<br[^>]*>(\n|\r)+/ims',
'<br>', $stringtoclean);
5745 $temp = preg_replace(
'/<br[^>]*>/i',
"\n", $stringtoclean);
5750 $temp = str_replace(
'< ',
'__ltspace__', $temp);
5751 $temp = str_replace(
'<:',
'__lttwopoints__', $temp);
5754 $temp = strip_tags($temp);
5757 $pattern =
"/<[^<>]+>/";
5764 $tempbis = str_replace(
'<>',
'', $temp);
5765 $tempbis = preg_replace($pattern,
'', $tempbis);
5767 }
while ($tempbis != $temp);
5772 $temp = preg_replace(
'/<+([a-z]+)/i',
'\1', $temp);
5778 if ($removelinefeed == 1) {
5779 $temp = str_replace(array(
"\r\n",
"\r",
"\n"),
" ", $temp);
5783 if ($removedoublespaces) {
5784 while (strpos($temp,
" ") !==
false) {
5785 $temp = str_replace(
" ",
" ", $temp);
5789 $temp = str_replace(
'__ltspace__',
'< ', $temp);
5790 $temp = str_replace(
'__lttwopoints__',
'<:', $temp);
5814function dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles = 1, $removeclassattribute = 1, $cleanalsojavascript = 0, $allowiframe = 0, $allowed_tags = array(), $allowlink = 0, $allowscript = 0, $allowstyle = 0, $allowphp = 0)
5816 $sav_allowed_tags = $allowed_tags;
5818 if (empty($allowed_tags) || (is_string($allowed_tags) && preg_match(
'/^common/', $allowed_tags))) {
5819 $allowed_tags = array(
5876 $allowed_tags[] =
"comment";
5878 if (!in_array(
'iframe', $allowed_tags)) {
5879 $allowed_tags[] =
"iframe";
5883 if (!in_array(
'link', $allowed_tags)) {
5884 $allowed_tags[] =
"link";
5886 if (!in_array(
'meta', $allowed_tags)) {
5887 $allowed_tags[] =
"meta";
5891 if (!in_array(
'script', $allowed_tags)) {
5892 $allowed_tags[] =
"script";
5896 if (!in_array(
'style', $allowed_tags)) {
5897 $allowed_tags[] =
"style";
5900 if (is_string($sav_allowed_tags)) {
5901 $tmptags = explode(
',', $sav_allowed_tags);
5902 foreach ($tmptags as $tag) {
5903 if ($tag !=
'common') {
5904 $allowed_tags[] = $tag;
5910 $allowed_tags_string = implode(
"><", $allowed_tags);
5911 $allowed_tags_string =
'<' . $allowed_tags_string .
'>';
5913 $stringtoclean = str_replace(
'<!DOCTYPE html>',
'__!DOCTYPE_HTML__', $stringtoclean);
5918 $stringtoclean = preg_replace(
'/<!--([^>]*)-->/',
'<comment>\1</comment>', $stringtoclean);
5921 $allowed_tags[] =
"commentphp";
5922 $stringtoclean = preg_replace(
'/^<\?php([^"]+)\?>$/i',
'<commentphp>\1__</commentphp>', $stringtoclean);
5923 $stringtoclean = preg_replace(
'/"<\?php([^"]+)\?>"/i',
'"<commentphp>\1</commentphp>"', $stringtoclean);
5926 $stringtoclean = preg_replace(
'/:/i',
':', $stringtoclean);
5927 $stringtoclean = preg_replace(
'/:|�+58|:/i',
'', $stringtoclean);
5930 $temp = strip_tags($stringtoclean, $allowed_tags_string);
5932 if ($cleanalsosomestyles) {
5934 $temp = preg_replace(
'/position\s*:\s*(absolute|fixed)/i',
'', $temp);
5935 $temp = preg_replace(
'/z-index\s*:/i',
'', $temp);
5937 if ($removeclassattribute) {
5938 $temp = preg_replace(
'/(<[^>]+)\s+class=((["\']).*?\\3|\\w*)/i',
'\\1', $temp);
5943 if ($cleanalsojavascript) {
5944 $temp = preg_replace(
'/j\s*a\s*v\s*a\s*s\s*c\s*r\s*i\s*p\s*t\s*:/i',
'', $temp);
5947 $temp = str_replace(
'__!DOCTYPE_HTML__',
'<!DOCTYPE html>', $temp);
5950 $temp = preg_replace(
'/<commentphp>(.*)<\/commentphp>/',
'<?php\1?>', $temp);
5953 $temp = preg_replace(
'/<comment>([^>]*)<\/comment>/',
'<!--\1-->', $temp);
5975 if (is_null($allowed_attributes)) {
5976 $allowed_attributes = array(
6010 if (!in_array(
"content", $allowed_attributes)) {
6011 $allowed_attributes[] =
"content";
6013 if (!in_array(
"http-equiv", $allowed_attributes)) {
6014 $allowed_attributes[] =
"http-equiv";
6017 if (class_exists(
'DOMDocument') && !empty($stringtoclean)) {
6018 if ($ishtml === 0) {
6019 $stringtoclean = str_replace(
'&',
'__AMPINTEXT__', $stringtoclean);
6023 $dom =
new DOMDocument(
'',
'UTF-8');
6025 $savwarning = error_reporting();
6026 error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE);
6027 $wrapperId =
"dol_string_onlythesehtmlattributes___wrapper";
6028 $dom->loadHTML(
'<?xml encoding="UTF-8"><div id="' . $wrapperId .
'">' . $stringtoclean .
'</div>', LIBXML_HTML_NODEFDTD | LIBXML_ERR_NONE | LIBXML_HTML_NOIMPLIED | LIBXML_NONET | LIBXML_NOWARNING | LIBXML_NOERROR | LIBXML_NOXMLDECL);
6029 error_reporting($savwarning);
6031 if ($dom instanceof DOMDocument) {
6032 for ($els = $dom->getElementsByTagname(
'*'), $i = $els->length - 1; $i >= 0; $i--) {
6033 $el = $els->item($i);
6034 if (!$el instanceof DOMElement) {
6037 $attrs = $el->attributes;
6038 for ($ii = $attrs->length - 1; $ii >= 0; $ii--) {
6040 if (!empty($attrs->item($ii)->name)) {
6041 if (! in_array($attrs->item($ii)->name, $allowed_attributes)) {
6043 $els->item($i)->removeAttribute($attrs->item($ii)->name);
6044 } elseif (in_array($attrs->item($ii)->name, array(
'style'))) {
6046 $valuetoclean = $attrs->item($ii)->value;
6048 if (isset($valuetoclean)) {
6050 $oldvaluetoclean = $valuetoclean;
6051 $valuetoclean = preg_replace(
'/\/\*.*\*\//m',
'', $valuetoclean);
6052 $valuetoclean = preg_replace(
'/position\s*:\s*[a-z]+/mi',
'', $valuetoclean);
6053 if ($els->item($i)->tagName ==
'a') {
6054 $valuetoclean = preg_replace(
'/display\s*:/mi',
'', $valuetoclean);
6055 $valuetoclean = preg_replace(
'/z-index\s*:/mi',
'', $valuetoclean);
6056 $valuetoclean = preg_replace(
'/\s+(top|left|right|bottom)\s*:/mi',
'', $valuetoclean);
6060 $valuetoclean = preg_replace(
'/(logout|passwordforgotten)\.php/mi',
'', $valuetoclean);
6061 $valuetoclean = preg_replace(
'/action=/mi',
'', $valuetoclean);
6062 }
while ($oldvaluetoclean != $valuetoclean);
6065 $attrs->item($ii)->value = $valuetoclean;
6072 $dom->encoding =
'UTF-8';
6073 $wrapper = $dom->getElementById($wrapperId);
6075 foreach ($wrapper->childNodes as $child) {
6076 $return .= $dom->saveHTML($child);
6079 if ($ishtml === 0) {
6080 $return = str_replace(
'__AMPINTEXT__',
'&', $return);
6083 return trim($return);
6085 return $stringtoclean;
6102 $temp = $stringtoclean;
6103 foreach ($disallowed_tags as $tagtoremove) {
6104 $temp = preg_replace(
'/<\/?' . $tagtoremove .
'>/',
'', $temp);
6105 $temp = preg_replace(
'/<\/?' . $tagtoremove .
'\s+[^>]*>/',
'', $temp);
6108 if ($cleanalsosomestyles) {
6109 $temp = preg_replace(
'/position\s*:\s*(absolute|fixed)\s*!\s*important/',
'', $temp);
6127 if (!is_string($text) || $text ===
'') {
6132 $selfclosing = array(
'br',
'hr',
'img',
'input',
'meta',
'link',
'source',
'col',
'area',
'base',
'embed',
'param',
'track',
'wbr');
6135 if (preg_match_all(
'/<\s*(\/?)([a-zA-Z][a-zA-Z0-9]*)[^>]*?(\/?)\s*>/', $text, $matches, PREG_SET_ORDER)) {
6136 foreach ($matches as $match) {
6137 $tag = strtolower($match[2]);
6138 if (in_array($tag, $selfclosing) || !empty($match[3])) {
6141 if (empty($match[1])) {
6145 $idx = array_search($tag, array_reverse($opened,
true),
true);
6146 if ($idx !==
false) {
6147 unset($opened[$idx]);
6153 foreach (array_reverse($opened) as $tag) {
6154 $text .=
'</'.$tag.
'>';
6171 if ($nboflines == 1) {
6173 $firstline = preg_replace(
'/<br[^>]*>.*$/s',
'', $text);
6174 $firstline = preg_replace(
'/<div[^>]*>.*$/s',
'', $firstline);
6177 $firstline = preg_replace(
'/[\n\r].*/',
'', $text);
6182 return $firstline . (isset($firstline) && isset($text) && (strlen($firstline) != strlen($text)) ?
'...' :
'');
6186 $text = preg_replace(
'/\n/',
'', $text);
6188 $repTable = array(
"\t" =>
" ",
"\n" =>
" ",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
6190 $repTable = array(
"\t" =>
" ",
"\n" =>
"<br>",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
6193 $text = strtr($text, $repTable);
6194 if ($charset ==
'UTF-8') {
6195 $pattern =
'/(<br[^>]*>)/Uu';
6198 $pattern =
'/(<br[^>]*>)/U';
6200 $a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
6205 $lastaddediscontent = 1;
6206 while ($countline < $nboflines && isset($a[$i])) {
6207 if (preg_match(
'/<br[^>]*>/', $a[$i])) {
6208 if (array_key_exists($i + 1, $a) && !empty($a[$i + 1])) {
6209 $firstline .= ($ishtml ?
"<br>\n" :
"\n");
6211 if (!$lastaddediscontent) {
6214 $lastaddediscontent = 0;
6217 $firstline .= $a[$i];
6218 $lastaddediscontent = 1;
6224 $adddots = (isset($a[$i]) && (!preg_match(
'/<br[^>]*>/', $a[$i]) || (array_key_exists($i + 1, $a) && !empty($a[$i + 1]))));
6226 $ret = $firstline . ($adddots ?
'...' :
'');
6244function dol_nl2br($stringtoencode, $nl2brmode = 0, $forxml =
false)
6246 if (is_null($stringtoencode)) {
6251 return nl2br($stringtoencode, $forxml);
6253 $ret = preg_replace(
'/(\r\n|\r|\n)/i', ($forxml ?
'<br />' :
'<br>'), $stringtoencode);
6267function dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox = 0, $check =
'restricthtml')
6269 if (empty($nouseofiframesandbox) &&
getDolGlobalString(
'MAIN_SECURITY_USE_SANDBOX_FOR_HTMLWITHNOJS')) {
6274 return $stringtoencode;
6276 $out = $stringtoencode;
6280 $oldstringtoclean = $out;
6288 if (!empty($out) &&
getDolGlobalInt(
'MAIN_RESTRICTHTML_ONLY_VALID_HTML') && $check !=
'restricthtmlallowunvalid') {
6290 libxml_use_internal_errors(
false);
6291 if (LIBXML_VERSION < 20900) {
6295 libxml_disable_entity_loader(
true);
6298 $dom =
new DOMDocument();
6306 $out = preg_replace(
'/&(?![a-zA-Z0-9#]+;)/',
'__AMPINTEXT__', $out);
6313 $out = preg_replace_callback(
6314 '/__\[([0-9a-zA-Z_]+)\]__/',
6320 return '__BRACKETSTART' . $m[1] .
'BRACKETEND__';
6324 $wrapperId =
"dol_htmlwithnojs___wrapper___toremove";
6325 $dom->loadHTML(
'<?xml encoding="UTF-8"><div id="' . $wrapperId .
'">' . $out .
'</div>', LIBXML_HTML_NODEFDTD | LIBXML_ERR_NONE | LIBXML_HTML_NOIMPLIED | LIBXML_NONET | LIBXML_NOWARNING | LIBXML_NOERROR | LIBXML_NOXMLDECL);
6327 $dom->encoding =
'UTF-8';
6331 foreach ($dom->getElementsByTagName(
'*') as $el) {
6332 if (!$el instanceof DOMElement) {
6337 if ($el->hasAttribute(
'style')) {
6339 $style = $el->getAttribute(
'style');
6342 $style = preg_replace(
'/z-index\s*:/i',
'', $style);
6343 $style = preg_replace(
'/position\s*:/i',
'', $style);
6344 $style = preg_replace(
'/top\s*:/i',
'', $style);
6345 $style = preg_replace(
'/left\s*:/i',
'', $style);
6346 $style = preg_replace(
'/background\s*:/i',
'', $style);
6352 if (trim($style) ===
'') {
6354 $el->removeAttribute(
'style');
6357 $el->setAttribute(
'style', $style);
6363 $wrapper = $dom->getElementById($wrapperId);
6365 foreach ($wrapper->childNodes as $child) {
6366 $result .= $dom->saveHTML($child);
6368 $out = trim($result);
6371 $out = preg_replace_callback(
6372 '/__BRACKETSTART([0-9a-zA-Z_]+)BRACKETEND__/',
6378 return '__[' . $m[1] .
']__';
6384 $out = str_replace(
'__AMPINTEXT__',
'&', $out);
6385 $out = preg_replace(
'/<br\s*\/?>/i',
"\n", $out);
6390 $out =
'InvalidHTMLStringCantBeCleaned ' . $e->getMessage();
6397 if (!empty($out) &&
getDolGlobalInt(
'MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY') && !in_array($check, array(
'restricthtmlallowunvalid',
'restricthtmlallowlinkscript')) && $outishtml) {
6403 if (extension_loaded(
'tidy') && class_exists(
"tidy")) {
6410 'quote-marks' =>
false,
6411 'doctype' =>
'strict',
6412 'show-body-only' =>
true,
6413 "indent-attributes" =>
false,
6414 "vertical-space" =>
false,
6417 'preserve-entities' =>
true
6426 $locale = setlocale(LC_NUMERIC,
'0');
6429 $out = $tidy->repairString($out, $config,
'utf8');
6431 setlocale(LC_NUMERIC, $locale);
6440 $out =
'InvalidHTMLStringCantBeCleaned ' . $e->getMessage();
6446 $out = preg_replace(
'/[\x{200B}-\x{200D}\x{FEFF}]/u',
' ', $out);
6449 $out = preg_replace(
'/&(tab|newline);/i',
' ', $out);
6453 $out = preg_replace(
'/'/i',
''', $out);
6458 if (function_exists(
'realCharForNumericEntities')) {
6459 $out = preg_replace_callback(
6460 '/&#(x?[0-9][0-9a-f]+;?)/i',
6465 static function ($m) {
6473 $out = preg_replace(
'/&#x?[0-9]+/i',
'', $out);
6476 if ($check ==
'restricthtmlallowlinkscript') {
6478 } elseif ($check ==
'restricthtmlallowclass' || $check ==
'restricthtmlallowunvalid') {
6480 } elseif ($check ==
'restricthtmlallowiframe') {
6493 $out = preg_replace(
'/'/i',
"'", $out);
6497 $out = preg_replace(
'/on(mouse|drag|key|load|touch|pointer|select|transition)[a-z]*\s*=/i',
'', $out);
6498 $out = preg_replace(
'/on(abort|after|animation|auxclick|before|blur|cancel|canplay|canplaythrough|change|click|close|command|contentvisibility|context|cuechange|copy|cut)[a-z]*\s*=/i',
'', $out);
6499 $out = preg_replace(
'/on(dblclick|drop|durationchange|emptied|end|ended|error|focus(in|out)?|formdata|gotpointercapture|hashchange|input|invalid)[a-z]*\s*=/i',
'', $out);
6500 $out = preg_replace(
'/on(lost|offline|online|message|pagehide|pageshow)[a-z]*\s*=/i',
'', $out);
6501 $out = preg_replace(
'/on(paste|pause|play|playing|progress|ratechange|rejectionn|reset|resize|scroll|search|security|seeked|seeking|show|stalled|start|submit|suspend)[a-z]*\s*=/i',
'', $out);
6502 $out = preg_replace(
'/on(timeupdate|toggle|unhandled|unload|volumechange|waiting|wheel)[a-z]*\s*=/i',
'', $out);
6504 $out = preg_replace(
'/on(repeat|begin|finish|beforeinput)[a-z]*\s*=/i',
'', $out);
6506 $out = preg_replace(
'/\son[a-z]+\s*=/i',
' ', $out);
6507 }
while ($oldstringtoclean != $out);
6514 $tmpout = preg_replace(
'/<img src="data:/mi',
'<__IMG_SRC_DATA__ src="data:', $out);
6515 preg_match_all(
'/(<img|url\(|<link)/i', $tmpout, $reg);
6516 $nblinks = count($reg[0]);
6517 if ($nblinks >
getDolGlobalInt(
"MAIN_SECURITY_MAX_IMG_IN_HTML_CONTENT", 1000)) {
6518 $out =
'ErrorTooManyLinksIntoHTMLString';
6521 if (
getDolGlobalInt(
'MAIN_DISALLOW_URL_INTO_DESCRIPTIONS') == 2 || $check ==
'restricthtmlnolink') {
6523 $out =
'ErrorHTMLLinksNotAllowed';
6525 } elseif (
getDolGlobalInt(
'MAIN_DISALLOW_URL_INTO_DESCRIPTIONS') == 1) {
6530 $pattern =
'/src=["\']?(http[^"\']+)|url\(["\']?(http[^\)]+)/';
6535 if (preg_match_all($pattern, $out, $matches)) {
6538 foreach ($matches[1] as $tmpval) {
6539 if (!empty($tmpval)) {
6543 foreach ($matches[2] as $tmpval) {
6544 if (!empty($tmpval)) {
6552 foreach ($urls as $url) {
6554 $parsedurl = parse_url($url);
6555 if (!empty($parsedurl)) {
6564 if (empty($firstexturl)) {
6565 $firstexturl = $url;
6566 } elseif (empty($secondexturl)) {
6567 $secondexturl = $url;
6573 $out =
'ErrorHTMLExternalLinksNotAllowed (Example: '.$firstexturl.($secondexturl ?
' '.$secondexturl :
'').
')';
6602function dol_htmlentitiesbr($stringtoencode, $nl2brmode = 0, $pagecodefrom =
'UTF-8', $removelasteolbr = 1)
6604 if (is_null($stringtoencode)) {
6608 $newstring = $stringtoencode;
6610 $newstring = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>/i',
'<br>', $newstring);
6611 if ($removelasteolbr) {
6612 $newstring = preg_replace(
'/<br>$/i',
'', $newstring);
6614 $newstring = preg_replace(
'/[\x{200B}-\x{200D}\x{FEFF}]/u',
' ', $newstring);
6615 $newstring = strtr($newstring, array(
'&' =>
'__PROTECTand__',
'<' =>
'__PROTECTlt__',
'>' =>
'__PROTECTgt__',
'"' =>
'__PROTECTdquot__'));
6617 $newstring = strtr($newstring, array(
'__PROTECTand__' =>
'&',
'__PROTECTlt__' =>
'<',
'__PROTECTgt__' =>
'>',
'__PROTECTdquot__' =>
'"'));
6619 if ($removelasteolbr) {
6620 $newstring = preg_replace(
'/(\r\n|\r|\n)$/i',
'', $newstring);
6639 $ret = preg_replace(
'/' .
"\r\n" .
'<br(\s[\sa-zA-Z_="]*)?\/?>/i',
"<br>", $ret);
6640 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>' .
"\r\n" .
'/i',
"\r\n", $ret);
6641 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>' .
"\n" .
'/i',
"\n", $ret);
6642 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>/i',
"\n", $ret);
6654 $ret = preg_replace(
'/ $/i',
"", $stringtodecode);
6655 $ret = preg_replace(
'/(<br>|<br(\s[\sa-zA-Z_="]*)?\/?>|' .
"\n" .
'|' .
"\r" .
')+$/i',
"", $ret);
6671 if ($keepsomeentities) {
6672 $newstring = strtr($newstring, array(
'&' =>
'__andamp__',
'<' =>
'__andlt__',
'>' =>
'__andgt__',
'"' =>
'__dquot__'));
6674 $newstring = html_entity_decode((
string) $newstring, (
int) $b, (
string)
$c);
6675 if ($keepsomeentities) {
6676 $newstring = strtr($newstring, array(
'__andamp__' =>
'&',
'__andlt__' =>
'<',
'__andgt__' =>
'>',
'__dquot__' =>
'"'));
6692function dol_htmlentities($string, $flags = ENT_QUOTES | ENT_SUBSTITUTE, $encoding =
'UTF-8', $double_encode =
false)
6694 return htmlentities($string, $flags, $encoding, $double_encode);
6713 for ($scursor = 0; $scursor < $len; $scursor++) {
6714 $ordchar = ord($s[$scursor]);
6716 if ($ordchar < 32 && $ordchar != 13 && $ordchar != 10) {
6719 } elseif ($ordchar > 126 && $ordchar < 160) {
6723 $out .= $s[$scursor];
6745 $arraystring = explode(
"\n", $s);
6746 $nb = count($arraystring);
6763 $repTable = array(
"\t" =>
" ",
"\n" =>
"<br>",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
6765 $repTable = array(
"\t" =>
" ",
"\n" =>
" ",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
6768 $text = strtr($text, $repTable);
6769 if ($charset ==
'UTF-8') {
6770 $pattern =
'/(<br[^>]*>)/Uu';
6773 $pattern =
'/(<br[^>]*>)/U';
6775 $a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
6777 $nblines = (int) floor((count($a) + 1) / 2);
6780 foreach ($a as $line) {
6783 $line_dec = html_entity_decode($line);
6785 $line_dec = wordwrap($line_dec, $maxlinesize,
'\n',
true);
6786 $nblines += substr_count($line_dec,
'\n');
6806 if (is_null($msg)) {
6811 if (preg_match(
'/<(html|link|script)/i', $msg)) {
6813 } elseif (preg_match(
'/<body/i', $msg)) {
6815 } elseif (preg_match(
'/<\/textarea/i', $msg)) {
6817 } elseif (preg_match(
'/<(b|em|i|u)(\s+[^>]+)?>/i', $msg)) {
6819 } elseif (preg_match(
'/<br/i', $msg)) {
6825 $msg = preg_replace(
'/https?:\/\/[^"\'\s]+/i',
'', $msg);
6826 if (preg_match(
'/<(html|link|script|body)/i', $msg)) {
6828 } elseif (preg_match(
'/<\/textarea/i', $msg)) {
6830 } elseif (preg_match(
'/<(b|em|i|u)(\s+[^>]+)?>/i', $msg)) {
6832 } elseif (preg_match(
'/<(br|hr)\/>/i', $msg)) {
6834 } elseif (preg_match(
'/<(br|hr|div|font|li|p|span|strong|table)>/i', $msg)) {
6836 } elseif (preg_match(
'/<(br|hr|div|font|li|p|span|strong|table)\s+[^<>\/]*\/?>/i', $msg)) {
6838 } elseif (preg_match(
'/<img\s+[^<>]*src[^<>]*>/i', $msg)) {
6840 } elseif (preg_match(
'/<a\s+[^<>]*href[^<>]*>/i', $msg)) {
6842 } elseif (preg_match(
'/<h[0-9]>/i', $msg)) {
6844 } elseif (preg_match(
'/&[A-Z0-9]{1,6};/i', $msg)) {
6847 } elseif (preg_match(
'/&#[0-9]{2,3};/i', $msg)) {
6849 } elseif (preg_match(
'/&#x[a-f0-9][a-f0-9];/i', $msg)) {
6871function dol_concatdesc($text1, $text2, $forxml =
false, $invert =
false)
6873 if (!empty($invert)) {
6881 $ret .= (!empty($text1) && !empty($text2)) ? ((
dol_textishtml($text1) ||
dol_textishtml($text2)) ? ($forxml ?
"<br >\n" :
"<br>\n") :
"\n") :
"";
6896 return $text1.$text2;
6908 if (!is_string($callback)) {
6909 throw new InvalidArgumentException(
"Les callbacks sont désactivés.");
6912 $allowed_callbacks = [
'strtolower',
'strtoupper',
'intval'];
6913 if (!in_array($callback, $allowed_callbacks,
true)) {
6914 throw new InvalidArgumentException(
"Callback function not allowed.");
6916 return array_map($callback, $array);
6933function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude =
null,
$object =
null, $include =
null)
6937 $substitutionarray = array();
6939 if ((empty($exclude) || !in_array(
'user', $exclude)) && (empty($include) || in_array(
'user', $include)) && $user instanceof
User) {
6943 $emailsendersignature = $user->signature;
6944 $usersignature = $user->signature;
6945 if (
getDolGlobalString(
'MAIN_MAIL_DEFAULT_SIGNATURE_FOR_ALL_USERS') && !empty($user->employee)) {
6946 $emailsendersignature =
getDolGlobalString(
'MAIN_MAIL_DEFAULT_SIGNATURE_FOR_ALL_USERS');
6949 $substitutionarray = array_merge($substitutionarray, array(
6950 '__SENDEREMAIL_SIGNATURE__' => (
string) ((!
getDolGlobalString(
'MAIN_MAIL_DO_NOT_USE_SIGN')) ? ($onlykey == 2 ?
dol_trunc(
'SignatureFromTheSelectedSenderProfile', 30) : $emailsendersignature) :
''),
6954 if (is_object($user) && ($user instanceof
User)) {
6955 $substitutionarray = array_merge($substitutionarray, array(
6956 '__USER_ID__' => (
string) $user->id,
6957 '__USER_LOGIN__' => (
string) $user->login,
6958 '__USER_EMAIL__' => (
string) $user->email,
6959 '__USER_PHONE__' => (
string)
dol_print_phone($user->office_phone,
'', 0, 0,
'',
" ",
'',
'', -1),
6960 '__USER_PHONEPRO__' => (
string)
dol_print_phone($user->user_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
6961 '__USER_PHONEMOBILE__' => (
string)
dol_print_phone($user->personal_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
6962 '__USER_FAX__' => (
string) $user->office_fax,
6963 '__USER_LASTNAME__' => (
string) $user->lastname,
6964 '__USER_FIRSTNAME__' => (
string) $user->firstname,
6965 '__USER_FULLNAME__' => (
string) $user->getFullName($outputlangs),
6966 '__USER_SUPERVISOR_ID__' => (
string) ($user->fk_user ? $user->fk_user :
'0'),
6967 '__USER_JOB__' => (
string) $user->job,
6969 '__USER_VCARD_URL__' => (
string) $user->getOnlineVirtualCardUrl(
'',
'external')
6972 $substitutionarray = array_merge($substitutionarray, array(
6973 '__USER_WAREHOUSE_ID__' => isset($user->warehouse->id) ? $user->warehouse->id :
'',
6974 '__USER_WAREHOUSE_REF__' => isset($user->warehouse->
ref) ? $user->warehouse->
ref :
'',
6975 '__USER_WAREHOUSE_DESCRIPTION__' => isset($user->warehouse->
description) ? $user->warehouse->
description :
'',
6976 '__USER_WAREHOUSE_ADDRESS__' => isset($user->warehouse->
address) ? $user->warehouse->
address :
'',
6977 '__USER_WAREHOUSE_ZIP__' => isset($user->warehouse->zip) ? $user->warehouse->zip :
'',
6978 '__USER_WAREHOUSE_TOWN__' => isset($user->warehouse->town) ? $user->warehouse->town :
'',
6979 '__USER_WAREHOUSE_PHONE__' => isset($user->warehouse->phone) ? (
string)
dol_print_phone($user->warehouse->phone,
'', 0, 0,
'',
" ",
'',
'', -1) :
'',
6980 '__USER_WAREHOUSE_FAX__' => isset($user->warehouse->fax) ? (
string)
dol_print_phone($user->warehouse->fax,
'', 0, 0,
'',
" ",
'',
'', -1) :
''
6985 if ((empty($exclude) || !in_array(
'mycompany', $exclude)) && is_object(
$mysoc) && (empty($include) || in_array(
'mycompany', $include))) {
6986 $substitutionarray = array_merge($substitutionarray, array(
6987 '__MYCOMPANY_NAME__' =>
$mysoc->name,
6988 '__MYCOMPANY_EMAIL__' =>
$mysoc->email,
6989 '__MYCOMPANY_URL__' =>
$mysoc->url,
6991 '__MYCOMPANY_PHONEMOBILE__' =>
dol_print_phone((
string)
$mysoc->phone_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
6993 '__MYCOMPANY_PROFID1__' =>
$mysoc->idprof1,
6994 '__MYCOMPANY_PROFID2__' =>
$mysoc->idprof2,
6995 '__MYCOMPANY_PROFID3__' =>
$mysoc->idprof3,
6996 '__MYCOMPANY_PROFID4__' =>
$mysoc->idprof4,
6997 '__MYCOMPANY_PROFID5__' =>
$mysoc->idprof5,
6998 '__MYCOMPANY_PROFID6__' =>
$mysoc->idprof6,
6999 '__MYCOMPANY_PROFID7__' =>
$mysoc->idprof7,
7000 '__MYCOMPANY_PROFID8__' =>
$mysoc->idprof8,
7001 '__MYCOMPANY_PROFID9__' =>
$mysoc->idprof9,
7002 '__MYCOMPANY_PROFID10__' =>
$mysoc->idprof10,
7003 '__MYCOMPANY_CAPITAL__' =>
$mysoc->capital,
7004 '__MYCOMPANY_FULLADDRESS__' => (method_exists(
$mysoc,
'getFullAddress') ?
$mysoc->getFullAddress(1,
', ') :
''),
7006 '__MYCOMPANY_VATNUMBER__' =>
$mysoc->tva_intra,
7007 '__MYCOMPANY_ZIP__' =>
$mysoc->zip,
7008 '__MYCOMPANY_TOWN__' =>
$mysoc->town,
7009 '__MYCOMPANY_STATE__' =>
$mysoc->state,
7010 '__MYCOMPANY_COUNTRY__' =>
$mysoc->country,
7011 '__MYCOMPANY_COUNTRY_ID__' =>
$mysoc->country_id,
7012 '__MYCOMPANY_COUNTRY_CODE__' =>
$mysoc->country_code,
7013 '__MYCOMPANY_CURRENCY_CODE__' =>
$conf->currency
7017 if (($onlykey || is_object(
$object)) && (empty($exclude) || !in_array(
'object', $exclude)) && (empty($include) || in_array(
'object', $include))) {
7019 $substitutionarray[
'__ID__'] =
'__ID__';
7020 $substitutionarray[
'__REF__'] =
'__REF__';
7021 $substitutionarray[
'__NEWREF__'] =
'__NEWREF__';
7022 $substitutionarray[
'__LABEL__'] =
'__LABEL__';
7023 $substitutionarray[
'__REF_CLIENT__'] =
'__REF_CLIENT__';
7024 $substitutionarray[
'__REF_SUPPLIER__'] =
'__REF_SUPPLIER__';
7025 $substitutionarray[
'__NOTE_PUBLIC__'] =
'__NOTE_PUBLIC__';
7026 $substitutionarray[
'__NOTE_PRIVATE__'] =
'__NOTE_PRIVATE__';
7027 $substitutionarray[
'__EXTRAFIELD_XXX__'] =
'__EXTRAFIELD_XXX__';
7030 $substitutionarray[
'__THIRDPARTY_ID__'] =
'__THIRDPARTY_ID__';
7031 $substitutionarray[
'__THIRDPARTY_NAME__'] =
'__THIRDPARTY_NAME__';
7032 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] =
'__THIRDPARTY_NAME_ALIAS__';
7033 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] =
'__THIRDPARTY_CODE_CLIENT__';
7034 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] =
'__THIRDPARTY_CODE_FOURNISSEUR__';
7035 $substitutionarray[
'__THIRDPARTY_EMAIL__'] =
'__THIRDPARTY_EMAIL__';
7037 $substitutionarray[
'__THIRDPARTY_URL__'] =
'__THIRDPARTY_URL__';
7039 $substitutionarray[
'__THIRDPARTY_PHONE__'] =
'__THIRDPARTY_PHONE__';
7040 $substitutionarray[
'__THIRDPARTY_FAX__'] =
'__THIRDPARTY_FAX__';
7041 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] =
'__THIRDPARTY_ADDRESS__';
7042 $substitutionarray[
'__THIRDPARTY_ZIP__'] =
'__THIRDPARTY_ZIP__';
7043 $substitutionarray[
'__THIRDPARTY_TOWN__'] =
'__THIRDPARTY_TOWN__';
7044 $substitutionarray[
'__THIRDPARTY_STATE__'] =
'__THIRDPARTY_STATE__';
7045 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] =
'__THIRDPARTY_IDPROF1__';
7046 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] =
'__THIRDPARTY_IDPROF2__';
7047 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] =
'__THIRDPARTY_IDPROF3__';
7048 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] =
'__THIRDPARTY_IDPROF4__';
7049 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] =
'__THIRDPARTY_IDPROF5__';
7050 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] =
'__THIRDPARTY_IDPROF6__';
7051 $substitutionarray[
'__THIRDPARTY_IDPROF7__'] =
'__THIRDPARTY_IDPROF7__';
7052 $substitutionarray[
'__THIRDPARTY_IDPROF8__'] =
'__THIRDPARTY_IDPROF8__';
7053 $substitutionarray[
'__THIRDPARTY_IDPROF9__'] =
'__THIRDPARTY_IDPROF9__';
7054 $substitutionarray[
'__THIRDPARTY_IDPROF10__'] =
'__THIRDPARTY_IDPROF10__';
7055 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] =
'__THIRDPARTY_TVAINTRA__';
7056 $substitutionarray[
'__THIRDPARTY_NOTE_PUBLIC__'] =
'__THIRDPARTY_NOTE_PUBLIC__';
7057 $substitutionarray[
'__THIRDPARTY_NOTE_PRIVATE__'] =
'__THIRDPARTY_NOTE_PRIVATE__';
7059 if (
isModEnabled(
'member') && (!is_object(
$object) ||
$object->element ==
'adherent') && (empty($exclude) || !in_array(
'member', $exclude)) && (empty($include) || in_array(
'member', $include))) {
7060 $substitutionarray[
'__MEMBER_ID__'] =
'__MEMBER_ID__';
7061 $substitutionarray[
'__MEMBER_TITLE__'] =
'__MEMBER_TITLE__';
7062 $substitutionarray[
'__MEMBER_FIRSTNAME__'] =
'__MEMBER_FIRSTNAME__';
7063 $substitutionarray[
'__MEMBER_LASTNAME__'] =
'__MEMBER_LASTNAME__';
7064 $substitutionarray[
'__MEMBER_USER_LOGIN_INFORMATION__'] =
'Login and pass of the external user account';
7069 if (
isModEnabled(
'ticket') && (!is_object(
$object) ||
$object->element ==
'ticket') && (empty($exclude) || !in_array(
'ticket', $exclude)) && (empty($include) || in_array(
'ticket', $include))) {
7070 $substitutionarray[
'__TICKET_TRACKID__'] =
'__TICKET_TRACKID__';
7071 $substitutionarray[
'__TICKET_SUBJECT__'] =
'__TICKET_SUBJECT__';
7072 $substitutionarray[
'__TICKET_TYPE__'] =
'__TICKET_TYPE__';
7073 $substitutionarray[
'__TICKET_SEVERITY__'] =
'__TICKET_SEVERITY__';
7074 $substitutionarray[
'__TICKET_CATEGORY__'] =
'__TICKET_CATEGORY__';
7075 $substitutionarray[
'__TICKET_ANALYTIC_CODE__'] =
'__TICKET_ANALYTIC_CODE__';
7076 $substitutionarray[
'__TICKET_MESSAGE__'] =
'__TICKET_MESSAGE__';
7077 $substitutionarray[
'__TICKET_PROGRESSION__'] =
'__TICKET_PROGRESSION__';
7078 $substitutionarray[
'__TICKET_USER_ASSIGN__'] =
'__TICKET_USER_ASSIGN__';
7080 if (
isModEnabled(
'recruitment') && (!is_object(
$object) ||
$object->element ==
'recruitmentcandidature') && (empty($exclude) || !in_array(
'recruitment', $exclude)) && (empty($include) || in_array(
'recruitment', $include))) {
7081 $substitutionarray[
'__CANDIDATE_FULLNAME__'] =
'__CANDIDATE_FULLNAME__';
7082 $substitutionarray[
'__CANDIDATE_FIRSTNAME__'] =
'__CANDIDATE_FIRSTNAME__';
7083 $substitutionarray[
'__CANDIDATE_LASTNAME__'] =
'__CANDIDATE_LASTNAME__';
7085 if (
isModEnabled(
'holiday') && (!is_object(
$object) ||
$object->element ==
'holiday') && (empty($exclude) || !in_array(
'holiday', $exclude)) && (empty($include) || in_array(
'holiday', $include))) {
7086 $substitutionarray[
'__HOLIDAY_ARRAY_PER_EMPLOYEE_FOR_PERIOD__'] =
'__HOLIDAY_ARRAY_PER_EMPLOYEE_FOR_PERIOD__';
7088 if (
isModEnabled(
'project') && (empty($exclude) || !in_array(
'project', $exclude)) && (empty($include) || in_array(
'project', $include))) {
7089 $substitutionarray[
'__PROJECT_ID__'] =
'__PROJECT_ID__';
7090 $substitutionarray[
'__PROJECT_REF__'] =
'__PROJECT_REF__';
7091 $substitutionarray[
'__PROJECT_NAME__'] =
'__PROJECT_NAME__';
7095 if (
isModEnabled(
'contract') && (!is_object(
$object) ||
$object->element ==
'contract') && (empty($exclude) || !in_array(
'contract', $exclude)) && (empty($include) || in_array(
'contract', $include))) {
7096 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE__'] =
'Highest date planned for a service start';
7097 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATETIME__'] =
'Highest date and hour planned for service start';
7098 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE__'] =
'Lowest data for planned expiration of service';
7099 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATETIME__'] =
'Lowest date and hour for planned expiration of service';
7101 if (
isModEnabled(
"propal") && (!is_object(
$object) ||
$object->element ==
'propal') && (empty($exclude) || !in_array(
'propal', $exclude)) && (empty($include) || in_array(
'propal', $include))) {
7102 $substitutionarray[
'__ONLINE_SIGN_URL__'] =
'ToOfferALinkForOnlineSignature';
7104 if (
isModEnabled(
"intervention") && (!is_object(
$object) ||
$object->element ==
'fichinter') && (empty($exclude) || !in_array(
'intervention', $exclude)) && (empty($include) || in_array(
'intervention', $include))) {
7105 $substitutionarray[
'__ONLINE_SIGN_FICHINTER_URL__'] =
'ToOfferALinkForOnlineSignature';
7107 $substitutionarray[
'__ONLINE_PAYMENT_URL__'] =
'UrlToPayOnlineIfApplicable';
7108 $substitutionarray[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'TextAndUrlToPayOnlineIfApplicable';
7109 $substitutionarray[
'__SECUREKEYPAYMENT__'] =
'Security key (if key is not unique per record)';
7110 $substitutionarray[
'__SECUREKEYPAYMENT_MEMBER__'] =
'Security key for payment on a member subscription (one key per member)';
7111 $substitutionarray[
'__SECUREKEYPAYMENT_ORDER__'] =
'Security key for payment on an order';
7112 $substitutionarray[
'__SECUREKEYPAYMENT_INVOICE__'] =
'Security key for payment on an invoice';
7113 $substitutionarray[
'__SECUREKEYPAYMENT_CONTRACTLINE__'] =
'Security key for payment on a service of a contract';
7115 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
'Direct download url of a proposal';
7116 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
'Direct download url of an order';
7117 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
'Direct download url of an invoice';
7118 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
'Direct download url of a contract';
7119 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
'Direct download url of a supplier proposal';
7120 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_ORDER__'] =
'Direct download url of a supplier order';
7121 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_INVOICE__'] =
'Direct download url of a supplier invoice';
7124 $substitutionarray[
'__SHIPPINGTRACKNUM__'] =
'Shipping tracking number';
7125 $substitutionarray[
'__SHIPPINGTRACKNUMURL__'] =
'Shipping tracking url';
7126 $substitutionarray[
'__SHIPPINGMETHOD__'] =
'Shipping method';
7129 $substitutionarray[
'__RECEPTIONTRACKNUM__'] =
'Shipping tracking number of shipment';
7130 $substitutionarray[
'__RECEPTIONTRACKNUMURL__'] =
'Shipping tracking url';
7133 '@phan-var-force Adherent|Delivery $object';
7135 $substitutionarray[
'__ID__'] =
$object->id;
7136 $substitutionarray[
'__REF__'] =
$object->ref;
7137 $substitutionarray[
'__NEWREF__'] =
$object->newref;
7139 $substitutionarray[
'__REF_CLIENT__'] = (isset(
$object->ref_client) ?
$object->ref_client : (isset(
$object->ref_customer) ?
$object->ref_customer :
null));
7140 $substitutionarray[
'__REF_SUPPLIER__'] = (isset(
$object->ref_supplier) ?
$object->ref_supplier :
null);
7141 $substitutionarray[
'__NOTE_PUBLIC__'] = (isset(
$object->note_public) ?
$object->note_public :
null);
7142 $substitutionarray[
'__NOTE_PRIVATE__'] = (isset(
$object->note_private) ?
$object->note_private :
null);
7144 $substitutionarray[
'__DATE_CREATION__'] = (isset(
$object->date_creation) ?
dol_print_date(
$object->date_creation,
'day',
false, $outputlangs) :
'');
7145 $substitutionarray[
'__DATE_MODIFICATION__'] = (isset(
$object->date_modification) ?
dol_print_date(
$object->date_modification,
'day',
false, $outputlangs) :
'');
7146 $substitutionarray[
'__DATE_VALIDATION__'] = (isset(
$object->date_validation) ?
dol_print_date(
$object->date_validation,
'day',
false, $outputlangs) :
'');
7149 $date_delivery =
null;
7150 if (property_exists(
$object,
'date_delivery')) {
7151 $date_delivery =
$object->date_delivery;
7152 } elseif (property_exists(
$object,
'delivery_date')) {
7153 $date_delivery =
$object->delivery_date;
7155 $substitutionarray[
'__DATE_DELIVERY__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
'day',
false, $outputlangs) :
'');
7156 $substitutionarray[
'__DATE_DELIVERY_DAY__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%d") :
'');
7157 $substitutionarray[
'__DATE_DELIVERY_DAY_TEXT__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%A") :
'');
7158 $substitutionarray[
'__DATE_DELIVERY_MON__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%m") :
'');
7159 $substitutionarray[
'__DATE_DELIVERY_MON_TEXT__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%b") :
'');
7160 $substitutionarray[
'__DATE_DELIVERY_YEAR__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%Y") :
'');
7161 $substitutionarray[
'__DATE_DELIVERY_HH__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%H") :
'');
7162 $substitutionarray[
'__DATE_DELIVERY_MM__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%M") :
'');
7163 $substitutionarray[
'__DATE_DELIVERY_SS__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%S") :
'');
7166 $substitutionarray[
'__REFCLIENT__'] = (isset(
$object->ref_client) ?
$object->ref_client : (isset(
$object->ref_customer) ?
$object->ref_customer :
null));
7167 $substitutionarray[
'__REFSUPPLIER__'] = (isset(
$object->ref_supplier) ?
$object->ref_supplier :
null);
7169 $substitutionarray[
'__SUPPLIER_ORDER_DATE_DELIVERY__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
'day',
false, $outputlangs) :
'');
7170 $substitutionarray[
'__SUPPLIER_ORDER_DELAY_DELIVERY__'] = (isset(
$object->availability_code) ? ($outputlangs->transnoentities(
"AvailabilityType" .
$object->availability_code) !=
'AvailabilityType' .
$object->availability_code ? $outputlangs->transnoentities(
"AvailabilityType" .
$object->availability_code) : $outputlangs->convToOutputCharset(isset(
$object->availability) ?
$object->availability :
'')) :
'');
7174 '@phan-var-force Adherent $object';
7178 $substitutionarray[
'__MEMBER_ID__'] = (isset(
$object->id) ?
$object->id :
'');
7179 if (method_exists(
$object,
'getCivilityLabel')) {
7180 $substitutionarray[
'__MEMBER_TITLE__'] =
$object->getCivilityLabel();
7182 $substitutionarray[
'__MEMBER_FIRSTNAME__'] = (isset(
$object->firstname) ?
$object->firstname :
'');
7183 $substitutionarray[
'__MEMBER_LASTNAME__'] = (isset(
$object->lastname) ?
$object->lastname :
'');
7184 $substitutionarray[
'__MEMBER_USER_LOGIN_INFORMATION__'] =
'';
7185 if (method_exists(
$object,
'getFullName')) {
7186 $substitutionarray[
'__MEMBER_FULLNAME__'] =
$object->getFullName($outputlangs);
7188 $substitutionarray[
'__MEMBER_COMPANY__'] = (isset(
$object->societe) ?
$object->societe :
'');
7189 $substitutionarray[
'__MEMBER_ADDRESS__'] = (isset(
$object->address) ?
$object->address :
'');
7190 $substitutionarray[
'__MEMBER_ZIP__'] = (isset(
$object->zip) ?
$object->zip :
'');
7191 $substitutionarray[
'__MEMBER_TOWN__'] = (isset(
$object->town) ?
$object->town :
'');
7192 $substitutionarray[
'__MEMBER_STATE__'] = (isset(
$object->state) ?
$object->state :
'');
7193 $substitutionarray[
'__MEMBER_COUNTRY__'] = (isset(
$object->country) ?
$object->country :
'');
7194 $substitutionarray[
'__MEMBER_EMAIL__'] = (isset(
$object->email) ?
$object->email :
'');
7195 $substitutionarray[
'__MEMBER_BIRTH__'] = (isset($birthday) ? $birthday :
'');
7196 $substitutionarray[
'__MEMBER_PHOTO__'] = (isset(
$object->photo) ?
$object->photo :
'');
7197 $substitutionarray[
'__MEMBER_LOGIN__'] = (isset(
$object->login) ?
$object->login :
'');
7198 $substitutionarray[
'__MEMBER_PASSWORD__'] = (isset(
$object->pass) ?
$object->pass :
'');
7202 $substitutionarray[
'__MEMBER_TYPE__'] = (isset(
$object->type) ?
$object->type :
'');
7203 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE__'] =
dol_print_date(
$object->first_subscription_date,
'day');
7205 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_RFC__'] =
dol_print_date(
$object->first_subscription_date,
'dayrfc');
7206 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_START__'] = (isset(
$object->first_subscription_date_start) ?
dol_print_date(
$object->first_subscription_date_start,
'day') :
'');
7207 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_START_RFC__'] = (isset(
$object->first_subscription_date_start) ?
dol_print_date(
$object->first_subscription_date_start,
'dayrfc') :
'');
7208 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_END__'] = (isset(
$object->first_subscription_date_end) ?
dol_print_date(
$object->first_subscription_date_end,
'day') :
'');
7209 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_END_RFC__'] = (isset(
$object->first_subscription_date_end) ?
dol_print_date(
$object->first_subscription_date_end,
'dayrfc') :
'');
7210 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE__'] =
dol_print_date(
$object->last_subscription_date,
'day');
7211 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_RFC__'] =
dol_print_date(
$object->last_subscription_date,
'dayrfc');
7212 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_START__'] =
dol_print_date(
$object->last_subscription_date_start,
'day');
7213 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_START_RFC__'] =
dol_print_date(
$object->last_subscription_date_start,
'dayrfc');
7214 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_END__'] =
dol_print_date(
$object->last_subscription_date_end,
'day');
7215 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_END_RFC__'] =
dol_print_date(
$object->last_subscription_date_end,
'dayrfc');
7220 '@phan-var-force Societe $object';
7221 $substitutionarray[
'__THIRDPARTY_ID__'] =
$object->id ??
'';
7222 $substitutionarray[
'__THIRDPARTY_NAME__'] =
$object->name ??
'';
7223 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] =
$object->name_alias ??
'';
7224 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] =
$object->code_client ??
'';
7225 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] =
$object->code_fournisseur ??
'';
7226 $substitutionarray[
'__THIRDPARTY_EMAIL__'] =
$object->email ??
'';
7227 $substitutionarray[
'__THIRDPARTY_EMAIL_URLENCODED__'] = urlencode(
$object->email ??
'');
7228 $substitutionarray[
'__THIRDPARTY_URL__'] =
$object->url ??
'';
7229 $substitutionarray[
'__THIRDPARTY_URL_URLENCODED__'] = urlencode(
$object->url ??
'');
7232 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] =
$object->address ??
'';
7233 $substitutionarray[
'__THIRDPARTY_ZIP__'] =
$object->zip ??
'';
7234 $substitutionarray[
'__THIRDPARTY_TOWN__'] =
$object->town ??
'';
7235 $substitutionarray[
'__THIRDPARTY_STATE__'] =
$object->state ??
'';
7236 $substitutionarray[
'__THIRDPARTY_COUNTRY_ID__'] = (
$object->country_id > 0 ?:
'');
7237 $substitutionarray[
'__THIRDPARTY_COUNTRY_CODE__'] =
$object->country_code ??
'';
7238 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] =
$object->idprof1 ??
'';
7239 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] =
$object->idprof2 ??
'';
7240 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] =
$object->idprof3 ??
'';
7241 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] =
$object->idprof4 ??
'';
7242 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] =
$object->idprof5 ??
'';
7243 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] =
$object->idprof6 ??
'';
7244 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] =
$object->tva_intra ??
'';
7247 } elseif (is_object(
$object) && is_object(
$object->thirdparty)) {
7248 $substitutionarray[
'__THIRDPARTY_ID__'] =
$object->thirdparty->id ??
'';
7249 $substitutionarray[
'__THIRDPARTY_NAME__'] =
$object->thirdparty->name ??
'';
7250 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] =
$object->thirdparty->name_alias ??
'';
7251 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] =
$object->thirdparty->code_client ??
'';
7252 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] =
$object->thirdparty->code_fournisseur ??
'';
7253 $substitutionarray[
'__THIRDPARTY_EMAIL__'] =
$object->thirdparty->email ??
'';
7254 $substitutionarray[
'__THIRDPARTY_EMAIL_URLENCODED__'] = urlencode(
$object->thirdparty->email ??
'');
7257 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] =
$object->thirdparty->address ??
'';
7258 $substitutionarray[
'__THIRDPARTY_ZIP__'] =
$object->thirdparty->zip ??
'';
7259 $substitutionarray[
'__THIRDPARTY_TOWN__'] =
$object->thirdparty->town ??
'';
7260 $substitutionarray[
'__THIRDPARTY_STATE__'] =
$object->thirdparty->state ??
'';
7261 $substitutionarray[
'__THIRDPARTY_COUNTRY_ID__'] = (
$object->thirdparty->country_id > 0 ?:
'');
7262 $substitutionarray[
'__THIRDPARTY_COUNTRY_CODE__'] =
$object->thirdparty->country_code ??
'';
7263 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] =
$object->thirdparty->idprof1 ??
'';
7264 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] =
$object->thirdparty->idprof2 ??
'';
7265 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] =
$object->thirdparty->idprof3 ??
'';
7266 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] =
$object->thirdparty->idprof4 ??
'';
7267 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] =
$object->thirdparty->idprof5 ??
'';
7268 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] =
$object->thirdparty->idprof6 ??
'';
7269 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] =
$object->thirdparty->tva_intra ??
'';
7274 if (is_object(
$object) &&
$object->element ==
'recruitmentcandidature') {
7275 '@phan-var-force RecruitmentCandidature $object';
7277 $substitutionarray[
'__CANDIDATE_FULLNAME__'] =
$object->getFullName($outputlangs);
7278 $substitutionarray[
'__CANDIDATE_FIRSTNAME__'] = isset(
$object->firstname) ?
$object->firstname :
'';
7279 $substitutionarray[
'__CANDIDATE_LASTNAME__'] = isset(
$object->lastname) ?
$object->lastname :
'';
7281 if (is_object(
$object) &&
$object->element ==
'conferenceorboothattendee') {
7282 '@phan-var-force ConferenceOrBoothAttendee $object';
7284 $substitutionarray[
'__ATTENDEE_FULLNAME__'] =
$object->getFullName($outputlangs);
7285 $substitutionarray[
'__ATTENDEE_FIRSTNAME__'] = isset(
$object->firstname) ?
$object->firstname :
'';
7286 $substitutionarray[
'__ATTENDEE_LASTNAME__'] = isset(
$object->lastname) ?
$object->lastname :
'';
7290 '@phan-var-force Project $object';
7292 $substitutionarray[
'__PROJECT_ID__'] =
$object->id;
7293 $substitutionarray[
'__PROJECT_REF__'] =
$object->ref;
7294 $substitutionarray[
'__PROJECT_NAME__'] =
$object->title;
7295 } elseif (is_object(
$object)) {
7297 if (!empty(
$object->project)) {
7300 if (!is_null($project) && is_object($project)) {
7301 $substitutionarray[
'__PROJECT_ID__'] = $project->id;
7302 $substitutionarray[
'__PROJECT_REF__'] = $project->ref;
7303 $substitutionarray[
'__PROJECT_NAME__'] = $project->title;
7308 $project_id =
$object->fk_project;
7309 } elseif (!empty(
$object->fk_projet) &&
$object->fk_projet > 0) {
7310 $project_id =
$object->fk_project;
7312 if ($project_id > 0) {
7314 $substitutionarray[
'__PROJECT_ID__@lazyload'] =
'/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id;
7315 $substitutionarray[
'__PROJECT_REF__@lazyload'] =
'/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id;
7316 $substitutionarray[
'__PROJECT_NAME__@lazyload'] =
'/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id;
7322 '@phan-var-force Facture $object';
7324 $substitutionarray[
'__INVOICE_SITUATION_NUMBER__'] = isset(
$object->situation_counter) ?
$object->situation_counter :
'';
7327 '@phan-var-force Expedition $object';
7329 $substitutionarray[
'__SHIPPINGTRACKNUM__'] =
$object->tracking_number;
7330 $substitutionarray[
'__SHIPPINGTRACKNUMURL__'] =
$object->tracking_url;
7331 $substitutionarray[
'__SHIPPINGMETHOD__'] =
$object->shipping_method;
7334 '@phan-var-force Reception $object';
7336 $substitutionarray[
'__RECEPTIONTRACKNUM__'] =
$object->tracking_number;
7337 $substitutionarray[
'__RECEPTIONTRACKNUMURL__'] =
$object->tracking_url;
7341 '@phan-var-force Contrat $object';
7343 $dateplannedstart =
'';
7344 $datenextexpiration =
'';
7345 foreach (
$object->lines as $line) {
7346 if ($line->date_start > $dateplannedstart) {
7347 $dateplannedstart = $line->date_start;
7349 if ($line->statut == 4 && $line->date_end && (!$datenextexpiration || $line->date_end < $datenextexpiration)) {
7350 $datenextexpiration = $line->date_end;
7353 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE__'] =
dol_print_date($dateplannedstart,
'day');
7354 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE_RFC__'] =
dol_print_date($dateplannedstart,
'dayrfc');
7355 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATETIME__'] =
dol_print_date($dateplannedstart,
'standard');
7357 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE__'] =
dol_print_date($datenextexpiration,
'day');
7358 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE_RFC__'] =
dol_print_date($datenextexpiration,
'dayrfc');
7359 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATETIME__'] =
dol_print_date($datenextexpiration,
'standard');
7363 '@phan-var-force Ticket $object';
7365 $substitutionarray[
'__TICKET_TRACKID__'] =
$object->track_id;
7366 $substitutionarray[
'__TICKET_SUBJECT__'] =
$object->subject;
7367 $substitutionarray[
'__TICKET_TYPE__'] =
$object->type_code;
7368 $substitutionarray[
'__TICKET_SEVERITY__'] =
$object->severity_code;
7369 $substitutionarray[
'__TICKET_CATEGORY__'] =
$object->category_code;
7370 $substitutionarray[
'__TICKET_ANALYTIC_CODE__'] =
$object->category_code;
7371 $substitutionarray[
'__TICKET_MESSAGE__'] =
$object->message;
7372 $substitutionarray[
'__TICKET_PROGRESSION__'] =
$object->progress;
7374 if (
$object->fk_user_assign > 0) {
7375 $userstat->fetch(
$object->fk_user_assign);
7376 $substitutionarray[
'__TICKET_USER_ASSIGN__'] =
dolGetFirstLastname($userstat->firstname, $userstat->lastname);
7379 if (
$object->fk_user_create > 0) {
7380 $userstat->fetch(
$object->fk_user_create);
7381 $substitutionarray[
'__USER_CREATE__'] =
dolGetFirstLastname($userstat->firstname, $userstat->lastname);
7387 if (!is_object($extrafields)) {
7390 $extrafields->fetch_name_optionals_label(
$object->table_element,
true);
7392 if (
$object->fetch_optionals() > 0) {
7393 if (is_array($extrafields->attributes[
$object->table_element][
'label']) && count($extrafields->attributes[
$object->table_element][
'label']) > 0) {
7394 foreach ($extrafields->attributes[
$object->table_element][
'label'] as $key => $label) {
7395 if ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'date') {
7396 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] =
dol_print_date(
$object->array_options[
'options_' . $key],
'day');
7397 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_LOCALE__'] =
dol_print_date(
$object->array_options[
'options_' . $key],
'day',
'tzserver', $outputlangs);
7398 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_RFC__'] =
dol_print_date(
$object->array_options[
'options_' . $key],
'dayrfc');
7399 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'datetime') {
7400 $datetime =
$object->array_options[
'options_' . $key];
7401 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhour') :
'');
7402 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_LOCALE__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhour',
'tzserver', $outputlangs) :
'');
7403 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_DAY_LOCALE__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'day',
'tzserver', $outputlangs) :
'');
7404 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_RFC__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhourrfc') :
'');
7405 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'phone') {
7406 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] =
dol_print_phone(
$object->array_options[
'options_' . $key]);
7407 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'price') {
7408 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] =
$object->array_options[
'options_' . $key];
7409 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_FORMATED__'] =
price(
$object->array_options[
'options_' . $key]);
7410 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_FORMATTED__'] =
price(
$object->array_options[
'options_' . $key]);
7411 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'select') {
7412 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] = !empty(
$object->array_options[
'options_' . $key]) ?
$object->array_options[
'options_' . $key] :
'';
7413 $val = $extrafields->attributes[
$object->table_element][
'param'][$key][
'options'][
$object->array_options[
'options_'.$key]] ??
$object->array_options[
'options_'.$key];
7414 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'_LABEL__'] = $val;
7415 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] !=
'separator') {
7416 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] = !empty(
$object->array_options[
'options_' . $key]) ?
$object->array_options[
'options_' . $key] :
'';
7424 if (empty($substitutionarray[
'__REF__'])) {
7428 require_once DOL_DOCUMENT_ROOT .
'/core/lib/payments.lib.php';
7429 $outputlangs->loadLangs(array(
'paypal',
'other'));
7432 $typeforonlinepayment =
'free';
7434 $typeforonlinepayment =
'order';
7437 $typeforonlinepayment =
'invoice';
7440 $typeforonlinepayment =
'member';
7441 if (!empty(
$object->last_subscription_amount)) {
7442 $amounttouse =
$object->last_subscription_amount;
7446 $typeforonlinepayment =
'contract';
7449 $typeforonlinepayment =
'ficheinter';
7452 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $substitutionarray[
'__REF__'], (
float) $amounttouse);
7457 $substitutionarray[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = ($paymenturl ? str_replace(
'\n',
"\n", $outputlangs->trans(
"PredefinedMailContentLink", $paymenturl)) :
'');
7458 $substitutionarray[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
7462 include_once DOL_DOCUMENT_ROOT .
'/core/lib/functions_be.lib.php';
7467 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
$object->getLastMainDocLink(
$object->element);
7469 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
'';
7472 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
$object->getLastMainDocLink(
$object->element);
7474 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
'';
7477 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
$object->getLastMainDocLink(
$object->element);
7479 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
'';
7482 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
$object->getLastMainDocLink(
$object->element);
7484 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
'';
7487 $substitutionarray[
'__DIRECTDOWNLOAD_URL_FICHINTER__'] =
$object->getLastMainDocLink(
$object->element);
7489 $substitutionarray[
'__DIRECTDOWNLOAD_URL_FICHINTER__'] =
'';
7492 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
$object->getLastMainDocLink(
$object->element);
7494 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
'';
7497 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_ORDER__'] =
$object->getLastMainDocLink(
$object->element);
7499 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_ORDER__'] =
'';
7502 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_INVOICE__'] =
$object->getLastMainDocLink(
$object->element);
7504 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_INVOICE__'] =
'';
7508 '@phan-var-force Propal $object';
7510 $substitutionarray[
'__URL_PROPOSAL__'] = DOL_MAIN_URL_ROOT .
"/comm/propal/card.php?id=" .
$object->id;
7511 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
7512 $substitutionarray[
'__ONLINE_SIGN_URL__'] = getOnlineSignatureUrl(0,
'proposal', (
string)
$object->ref, 1,
$object);
7515 '@phan-var-force Commande $object';
7517 $substitutionarray[
'__URL_ORDER__'] = DOL_MAIN_URL_ROOT .
"/commande/card.php?id=" .
$object->id;
7520 '@phan-var-force Facture $object';
7522 $substitutionarray[
'__URL_INVOICE__'] = DOL_MAIN_URL_ROOT .
"/compta/facture/card.php?id=" .
$object->id;
7525 '@phan-var-force Contrat $object';
7527 $substitutionarray[
'__URL_CONTRACT__'] = DOL_MAIN_URL_ROOT .
"/contrat/card.php?id=" .
$object->id;
7528 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
7529 $substitutionarray[
'__ONLINE_SIGN_URL__'] = getOnlineSignatureUrl(0,
'contract', (
string)
$object->ref, 1,
$object);
7532 '@phan-var-force Fichinter $object';
7534 $substitutionarray[
'__URL_FICHINTER__'] = DOL_MAIN_URL_ROOT .
"/fichinter/card.php?id=" .
$object->id;
7535 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
7536 $substitutionarray[
'__ONLINE_SIGN_FICHINTER_URL__'] = getOnlineSignatureUrl(0,
'fichinter', (
string)
$object->ref, 1,
$object);
7538 if (is_object(
$object) &&
$object->element ==
'supplier_proposal') {
7539 '@phan-var-force SupplierProposal $object';
7541 $substitutionarray[
'__URL_SUPPLIER_PROPOSAL__'] = DOL_MAIN_URL_ROOT .
"/supplier_proposal/card.php?id=" .
$object->id;
7543 if (is_object(
$object) &&
$object->element ==
'invoice_supplier') {
7544 '@phan-var-force FactureFournisseur $object';
7546 $substitutionarray[
'__URL_SUPPLIER_INVOICE__'] = DOL_MAIN_URL_ROOT .
"/fourn/facture/card.php?id=" .
$object->id;
7548 if (is_object(
$object) &&
$object->element ==
'payment_supplier') {
7549 '@phan-var-force PaiementFourn $object';
7552 $liste_factures = [];
7556 $sql =
'SELECT f.ref,f.multicurrency_code as f_mccode, pf.*
7557 FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf
7558 JOIN '.MAIN_DB_PREFIX.
'facture_fourn as f ON pf.fk_facturefourn = f.rowid
7559 WHERE pf.fk_paiementfourn = '.((int)
$object->id);
7561 $resql =
$db->query($sql);
7563 while ($objp =
$db->fetch_object($resql)) {
7564 $liste_factures[] =
' - '.$outputlangs->trans(
'Invoice').
' '. $objp->ref.
' '.$outputlangs->trans(
'AmountPayed').
' '.
price($objp->multicurrency_amount, 0, $outputlangs, 0, -1, -1, $objp->multicurrency_code);
7567 $substitutionarray[
'__SUPPLIER_PAYMENT_INVOICES_LIST__'] = implode(
"\n", $liste_factures);
7569 $substitutionarray[
'__SUPPLIER_PAYMENT_INVOICES_TOTAL__'] =
price(
$object->multicurrency_amount, 0, $outputlangs, 0, -1, -1,
$object->multicurrency_code ?
$object->multicurrency_code :
$conf->currency);
7572 '@phan-var-force Expedition $object';
7574 $substitutionarray[
'__URL_SHIPMENT__'] = DOL_MAIN_URL_ROOT .
"/expedition/card.php?id=" .
$object->id;
7576 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
7577 $substitutionarray[
'__ONLINE_SIGN_URL__'] = getOnlineSignatureUrl(0,
'expedition', (
string)
$object->ref, 1,
$object);
7583 '@phan-var-force ActionComm $object';
7585 $substitutionarray[
'__EVENT_LABEL__'] =
$object->label;
7586 $substitutionarray[
'__EVENT_DESCRIPTION__'] =
$object->note;
7587 $substitutionarray[
'__EVENT_TYPE__'] = $outputlangs->trans(
"Action" .
$object->type_code);
7589 $substitutionarray[
'__EVENT_TIME__'] =
dol_print_date(
$object->datep,
'hour',
'auto', $outputlangs);
7590 $substitutionarray[
'__EVENT_DATE_TZUSER__'] =
dol_print_date(
$object->datep,
'day',
'tzuserrel', $outputlangs);
7591 $substitutionarray[
'__EVENT_TIME_TZUSER__'] =
dol_print_date(
$object->datep,
'hour',
'tzuserrel', $outputlangs);
7596 if ((empty($exclude) || !in_array(
'objectamount', $exclude)) && (empty($include) || in_array(
'objectamount', $include))) {
7597 '@phan-var-force Facture|FactureRec $object';
7599 include_once DOL_DOCUMENT_ROOT .
'/core/lib/functionsnumtoword.lib.php';
7602 $substitutionarray[
'__DATE_DUE_YMD__'] = is_object(
$object) ? (isset(
$object->date_lim_reglement) ?
dol_print_date(
$object->date_lim_reglement,
'day',
false, $outputlangs) : null) :
'';
7604 $substitutionarray[
'__DATE_DUE_YMD_TEXT__'] = is_object(
$object) ? (isset(
$object->date_lim_reglement) ?
dol_print_date(
$object->date_lim_reglement,
'daytext',
false, $outputlangs) : null) :
'';
7606 $already_payed_all = 0;
7612 $substitutionarray[
'__AMOUNT_EXCL_TAX__'] = is_object(
$object) ?
$object->total_ht :
'';
7616 $substitutionarray[
'__AMOUNT__'] = is_object(
$object) ?
$object->total_ttc :
'';
7620 $substitutionarray[
'__DEPOSIT_PERCENT__'] = is_object(
$object) ?
$object->deposit_percent :
'';
7623 $substitutionarray[
'__AMOUNT_REMAIN__'] = is_object(
$object) ?
price2num(
$object->total_ttc - $already_payed_all,
'MT') :
'';
7625 $substitutionarray[
'__AMOUNT_VAT__'] = is_object(
$object) ? (isset(
$object->total_vat) ?
$object->total_vat :
$object->total_tva) :
'';
7629 $mysocuselocaltax1 =
false;
7630 $mysocuselocaltax2 =
false;
7632 $tmparray =
$mysoc->useLocalTax(-1);
7633 $mysocuselocaltax1 = $tmparray[1];
7634 $mysocuselocaltax2 = $tmparray[2];
7638 if ($onlykey != 2 || $mysocuselocaltax1) {
7639 $substitutionarray[
'__AMOUNT_TAX2__'] = is_object(
$object) ?
$object->total_localtax1 :
'';
7641 if ($onlykey != 2 || $mysocuselocaltax2) {
7642 $substitutionarray[
'__AMOUNT_TAX3__'] = is_object(
$object) ?
$object->total_localtax2 :
'';
7646 $substitutionarray[
'__AMOUNT_EXCL_TAX_FORMATTED__'] = is_object(
$object) ? (
$object->total_ht ?
price(
$object->total_ht, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null) :
'';
7647 $substitutionarray[
'__AMOUNT_FORMATTED__'] = is_object(
$object) ? (
$object->total_ttc ?
price(
$object->total_ttc, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null) :
'';
7648 $substitutionarray[
'__AMOUNT_REMAIN_FORMATTED__'] = is_object(
$object) ? (
$object->total_ttc ?
price(
$object->total_ttc - $already_payed_all, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null) :
'';
7649 $substitutionarray[
'__AMOUNT_VAT_FORMATTED__'] = is_object(
$object) ? (isset(
$object->total_vat) ?
price(
$object->total_vat, 0, $outputlangs, 0, -1, -1,
$conf->currency) : (
$object->total_tva ?
price(
$object->total_tva, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null)) :
'';
7650 if ($onlykey != 2 || $mysocuselocaltax1) {
7651 $substitutionarray[
'__AMOUNT_TAX2_FORMATTED__'] = is_object(
$object) ? (
$object->total_localtax1 ?
price(
$object->total_localtax1, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null) :
'';
7653 if ($onlykey != 2 || $mysocuselocaltax2) {
7654 $substitutionarray[
'__AMOUNT_TAX3_FORMATTED__'] = is_object(
$object) ? (
$object->total_localtax2 ?
price(
$object->total_localtax2, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null) :
'';
7657 if ($onlykey != 2) {
7658 $substitutionarray[
'__AMOUNT_EXCL_TAX_FORMATED__'] = $substitutionarray[
'__AMOUNT_EXCL_TAX_FORMATTED__'];
7659 $substitutionarray[
'__AMOUNT_FORMATED__'] = $substitutionarray[
'__AMOUNT_FORMATTED__'];
7660 $substitutionarray[
'__AMOUNT_REMAIN_FORMATED__'] = $substitutionarray[
'__AMOUNT_REMAIN_FORMATTED__'];
7661 $substitutionarray[
'__AMOUNT_VAT_FORMATED__'] = $substitutionarray[
'__AMOUNT_VAT_FORMATTED__'];
7662 if ($mysocuselocaltax1) {
7663 $substitutionarray[
'__AMOUNT_TAX2_FORMATED__'] = $substitutionarray[
'__AMOUNT_TAX2_FORMATTED__'];
7665 if (
$mysoc->useLocalTax2) {
7666 $substitutionarray[
'__AMOUNT_TAX3_FORMATED__'] = $substitutionarray[
'__AMOUNT_TAX3_FORMATTED__'];
7670 $substitutionarray[
'__AMOUNT_MULTICURRENCY__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
$object->multicurrency_total_ttc :
'';
7671 $substitutionarray[
'__AMOUNT_MULTICURRENCY_FORMATED__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
price(
$object->multicurrency_total_ttc, 0, $outputlangs, 0, -1, -1,
$object->multicurrency_code) :
'';
7672 $substitutionarray[
'__AMOUNT_MULTICURRENCY_TEXT__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
dol_convertToWord(
$object->multicurrency_total_ttc, $outputlangs,
'',
true) :
'';
7673 $substitutionarray[
'__AMOUNT_MULTICURRENCY_TEXTCURRENCY__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
dol_convertToWord(
$object->multicurrency_total_ttc, $outputlangs,
$object->multicurrency_code,
true) :
'';
7674 $substitutionarray[
'__MULTICURRENCY_CODE__'] = (is_object(
$object) && isset(
$object->multicurrency_code)) ?
$object->multicurrency_code :
'';
7678 if ($onlykey != 2) {
7679 $substitutionarray[
'__TOTAL_TTC__'] = is_object(
$object) ?
$object->total_ttc :
'';
7680 $substitutionarray[
'__TOTAL_HT__'] = is_object(
$object) ?
$object->total_ht :
'';
7685 if ((empty($exclude) || !in_array(
'date', $exclude)) && (empty($include) || in_array(
'date', $include))) {
7686 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
7696 $daytext = $outputlangs->trans(
'Day' . $tmp[
'wday']);
7698 $substitutionarray = array_merge($substitutionarray, array(
7699 '__NOW_TMS__' => (
string) $now,
7700 '__NOW_TMS_YMD__' =>
dol_print_date($now,
'day',
'auto', $outputlangs),
7701 '__DAY__' => (
string) $tmp[
'mday'],
7702 '__DAY_TEXT__' => $daytext,
7703 '__DAY_TEXT_SHORT__' =>
dol_trunc($daytext, 3,
'right',
'UTF-8', 1),
7704 '__DAY_TEXT_MIN__' =>
dol_trunc($daytext, 1,
'right',
'UTF-8', 1),
7705 '__MONTH__' => (
string) $tmp[
'mon'],
7706 '__MONTH_TEXT__' => $outputlangs->transnoentitiesnoconv(
'Month' . sprintf(
"%02d", $tmp[
'mon'])),
7707 '__MONTH_TEXT_SHORT__' => $outputlangs->transnoentitiesnoconv(
'MonthShort' . sprintf(
"%02d", $tmp[
'mon'])),
7708 '__MONTH_TEXT_MIN__' => $outputlangs->transnoentitiesnoconv(
'MonthVeryShort' . sprintf(
"%02d", $tmp[
'mon'])),
7709 '__YEAR__' => (
string) $tmp[
'year'],
7710 '__YEAR_PREVIOUS_MONTH__' => (
string) $tmp3[
'year'],
7711 '__YEAR_NEXT_MONTH__' => (
string) $tmp5[
'year'],
7712 '__PREVIOUS_DAY__' => (
string) $tmp2[
'day'],
7713 '__PREVIOUS_MONTH__' => (
string) $tmp3[
'month'],
7714 '__PREVIOUS_MONTH_TEXT__' => $outputlangs->transnoentitiesnoconv(
'Month' . sprintf(
"%02d", $tmp3[
'month'])),
7715 '__PREVIOUS_MONTH_TEXT_SHORT__' => $outputlangs->transnoentitiesnoconv(
'MonthShort' . sprintf(
"%02d", $tmp3[
'month'])),
7716 '__PREVIOUS_MONTH_TEXT_MIN__' => $outputlangs->transnoentitiesnoconv(
'MonthVeryShort' . sprintf(
"%02d", $tmp3[
'month'])),
7717 '__PREVIOUS_YEAR__' => (
string) ($tmp[
'year'] - 1),
7718 '__NEXT_DAY__' => (
string) $tmp4[
'day'],
7719 '__NEXT_MONTH__' => (
string) $tmp5[
'month'],
7720 '__NEXT_MONTH_TEXT__' => $outputlangs->transnoentitiesnoconv(
'Month' . sprintf(
"%02d", $tmp5[
'month'])),
7721 '__NEXT_MONTH_TEXT_SHORT__' => $outputlangs->transnoentitiesnoconv(
'MonthShort' . sprintf(
"%02d", $tmp5[
'month'])),
7722 '__NEXT_MONTH_TEXT_MIN__' => $outputlangs->transnoentitiesnoconv(
'MonthVeryShort' . sprintf(
"%02d", $tmp5[
'month'])),
7723 '__NEXT_YEAR__' => (
string) ($tmp[
'year'] + 1),
7728 $substitutionarray = array_merge($substitutionarray, array(
'__ENTITY_ID__' =>
$conf->entity));
7730 if ((empty($exclude) || !in_array(
'system', $exclude)) && (empty($include) || in_array(
'user', $include))) {
7731 $substitutionarray[
'__DOL_MAIN_URL_ROOT__'] = DOL_MAIN_URL_ROOT;
7732 $substitutionarray[
'__(AnyTranslationKey)__'] = $outputlangs->transnoentitiesnoconv(
'TranslationOfKey');
7733 $substitutionarray[
'__(AnyTranslationKey|langfile)__'] = $outputlangs->transnoentitiesnoconv(
'TranslationOfKey') .
' (load also language file before)';
7734 $substitutionarray[
'__[AnyConstantKey]__'] = $outputlangs->transnoentitiesnoconv(
'ValueOfConstantKey');
7739 return $substitutionarray;
7758function make_substitutions($text, $substitutionarray, $outputlangs =
null, $converttextinhtmlifnecessary = 0)
7762 if (!is_array($substitutionarray)) {
7763 return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions';
7766 if (empty($outputlangs)) {
7767 $outputlangs = $langs;
7777 if (is_object($outputlangs)) {
7779 while (preg_match(
'/__\(([^\)]+)\)__/', $text, $reg)) {
7781 $tmp = explode(
'|', $reg[1]);
7782 if (!empty($tmp[1])) {
7783 $outputlangs->load($tmp[1]);
7786 $value = $outputlangs->transnoentitiesnoconv($reg[1]);
7788 if (empty($converttextinhtmlifnecessary)) {
7790 $text = preg_replace(
'/__\(' . preg_quote($reg[1],
'/') .
'\)__/', $msgishtml ?
dol_htmlentitiesbr($value) : $value, $text);
7804 $text = preg_replace(
'/__\(' . preg_quote($reg[1],
'/') .
'\)__/', $value, $text);
7812 while (preg_match(
'/__\[([^\]]+)\]__/', $text, $reg)) {
7813 $originalkeyfound = $reg[1];
7814 $keyfound = preg_replace(
'/\|urlencode$/',
'', $originalkeyfound);
7817 $value =
'*****forbidden*****';
7821 if (preg_match(
'/\|urlencode$/', $originalkeyfound)) {
7822 $value = urlencode($value);
7826 if (empty($converttextinhtmlifnecessary)) {
7828 $text = preg_replace(
'/__\[' . preg_quote($originalkeyfound,
'/') .
'\]__/', $msgishtml ?
dol_htmlentitiesbr($value) : $value, $text);
7841 $text = preg_replace(
'/__\[' . preg_quote($originalkeyfound,
'/') .
'\]__/', $value, $text);
7846 foreach ($substitutionarray as $key => $value) {
7847 if (!isset($value)) {
7851 if (
getDolGlobalString(
'MAIN_MAIL_DO_NOT_USE_SIGN') && ($key ==
'__USER_SIGNATURE__' || $key ==
'__SENDEREMAIL_SIGNATURE__')) {
7855 if (empty($converttextinhtmlifnecessary)) {
7856 $text = str_replace((
string) $key, (
string) $value, $text);
7868 $text = str_replace((
string) $key, (
string) $value, $text);
7883 $memory_object_list = array();
7884 foreach ($substitutionarray as $key => $value) {
7885 $lazy_load_arr = array();
7886 if (preg_match(
'/(__[A-Z\_]+__)@lazyload$/', $key, $lazy_load_arr)) {
7887 if (isset($lazy_load_arr[1]) && !empty($lazy_load_arr[1])) {
7888 $key_to_substitute = $lazy_load_arr[1];
7889 if (preg_match(
'/' . preg_quote($key_to_substitute,
'/') .
'/', $text)) {
7890 $param_arr = explode(
':', (
string) $value);
7892 if (count($param_arr) >= 4) {
7893 $path = $param_arr[0];
7894 $class = $param_arr[1];
7895 $method = $param_arr[2];
7896 $id = (int) $param_arr[3];
7897 $keyinarrayresult = empty($param_arr[4]) ?
'' : $param_arr[4];
7900 if (!isset($memory_object_list[$class])) {
7902 require_once DOL_DOCUMENT_ROOT . $path;
7903 if (class_exists($class)) {
7904 $memory_object_list[$class] = array(
7912 if (isset($memory_object_list[$class]) && isset($memory_object_list[$class][
'list'])) {
7913 if (method_exists($class, $method)) {
7914 if (!isset($memory_object_list[$class][
'list'][
$id])) {
7915 $tmpobj =
new $class(
$db);
7917 $tmpvaluetouseforsubstitution = $tmpobj->$method(
$id, $key_to_substitute);
7918 $memory_object_list[$class][
'list'][
$id] = $tmpobj;
7921 $tmpobj = $memory_object_list[$class][
'list'][
$id];
7923 $tmpvaluetouseforsubstitution = $tmpobj->$method(
$id, $key_to_substitute,
true);
7926 if ($keyinarrayresult) {
7927 $valuetouseforsubstitution = (
string) $tmpvaluetouseforsubstitution[$keyinarrayresult];
7929 $valuetouseforsubstitution = (
string) $tmpvaluetouseforsubstitution;
7931 $text = str_replace((
string) $key_to_substitute, $valuetouseforsubstitution, $text);
7957 global
$conf, $user;
7959 require_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
7964 $dirsubstitutions = array_merge(array(), (array)
$conf->modules_parts[
'substitutions']);
7966 foreach ($dirsubstitutions as $reldir) {
7974 $substitfiles =
dol_dir_list($dir,
'files', 0,
'functions_');
7975 foreach ($substitfiles as $substitfile) {
7977 if (preg_match(
'/functions_(.*)\.lib\.php/i', $substitfile[
'name'], $reg)) {
7980 dol_syslog(
"Library " . $substitfile[
'name'] .
" found into " . $dir);
7982 require_once $dir . $substitfile[
'name'];
7984 $function_name = $module .
"_" . $callfunc;
7985 if (function_exists($function_name)) {
7986 $function_name($substitutionarray, $outputlangs,
$object, $parameters);
7994 foreach ($substitutionarray as $key => $value) {
7995 $tags .=
'{' . $key .
'} => ' . $value .
"\n";
7997 $substitutionarray = array_merge($substitutionarray, array(
'__ALL_TAGS__' => $tags));
8031 if (!is_object($outputlangs)) {
8032 $outputlangs = $langs;
8036 $out .= ($withparenthesis ? ($withparenthesis == 1 ?
' ' :
'').
'(' :
'') . $outputlangs->transnoentitiesnoconv(
'DateFromTo',
dol_print_date(
$date_start, $format, false, $outputlangs),
dol_print_date($date_end, $format, false, $outputlangs)) . ($withparenthesis ?
')' :
'');
8039 $out .= ($withparenthesis ? ($withparenthesis == 1 ?
' ' :
'').
'(' :
'') . $outputlangs->transnoentitiesnoconv(
'DateFrom',
dol_print_date(
$date_start, $format, false, $outputlangs)) . ($withparenthesis ?
')' :
'');
8042 $out .= ($withparenthesis ? ($withparenthesis == 1 ?
' ' :
'').
'(' :
'') . $outputlangs->transnoentitiesnoconv(
'DateUntil',
dol_print_date($date_end, $format, false, $outputlangs)) . ($withparenthesis ?
')' :
'');
8060 if ($nameorder < 0) {
8063 if ($nameorder == 1) {
8065 if ($firstname && $lastname) {
8069 } elseif ($nameorder == 2 || $nameorder == 3) {
8071 if (empty($ret) && $nameorder == 3) {
8076 if (empty($ret) && $nameorder == 5) {
8079 if ($nameorder == 0) {
8080 if ($firstname && $lastname) {
8100 return $arraytosort;
8124function dol_sort_array(&$array, $index, $order =
'asc', $natsort = 0, $case_sensitive = 0, $keepindex = 0)
8127 $order = strtolower($order);
8129 if (is_array($array)) {
8130 $sizearray = count($array);
8131 if ($sizearray > 0) {
8134 foreach (array_keys($array) as $key) {
8135 $tmpmultikey = explode(
',', $index);
8136 $newindex = $tmpmultikey[0];
8137 if (is_object($array[$key])) {
8138 $temp[$key] = empty($array[$key]->$newindex) ? 0 : $array[$key]->$newindex;
8140 if (!empty($tmpmultikey[1])) {
8141 $newindex = $tmpmultikey[1];
8142 $temp[$key] .=
'__' . (empty($array[$key]->$newindex) ? 0 : $array[$key]->$newindex);
8146 $temp[$key] = empty($array[$key][$newindex]) ? 0 : $array[$key][$newindex];
8148 if (!empty($tmpmultikey[1])) {
8149 $newindex = $tmpmultikey[1];
8151 $temp[$key] .=
'__' . (empty($array[$key][$newindex]) ? 0 : $array[$key][$newindex]);
8154 if ($natsort == -1) {
8155 $temp[$key] =
'___' . $temp[$key];
8158 if (empty($natsort) || $natsort == -1) {
8159 if ($order ==
'asc') {
8165 if ($case_sensitive) {
8170 if ($order !=
'asc') {
8171 $temp = array_reverse($temp,
true);
8177 foreach (array_keys($temp) as $key) {
8178 (is_numeric($key) && empty($keepindex)) ? $sorted[] = $array[$key] : $sorted[$key] = $array[$key];
8200 $strLength = strlen($str);
8201 for ($i = 0; $i < $strLength; $i++) {
8202 if (ord($str[$i]) < 0x80) {
8204 } elseif ((ord($str[$i]) & 0xE0) == 0xC0) {
8206 } elseif ((ord($str[$i]) & 0xF0) == 0xE0) {
8208 } elseif ((ord($str[$i]) & 0xF8) == 0xF0) {
8210 } elseif ((ord($str[$i]) & 0xFC) == 0xF8) {
8212 } elseif ((ord($str[$i]) & 0xFE) == 0xFC) {
8217 for ($j = 0; $j < $n; $j++) {
8218 if ((++$i == strlen($str)) || ((ord($str[$i]) & 0xC0) != 0x80)) {
8239 return preg_match(
'//u', $str) ? true :
false;
8251 if (function_exists(
'mb_check_encoding')) {
8253 if (!mb_check_encoding($str,
'ASCII')) {
8257 if (preg_match(
'/[^\x00-\x7f]/', $str)) {
8275 $tmp = ini_get(
"unicode.filesystem_encoding");
8276 if (empty($tmp) && !empty($_SERVER[
"WINDIR"])) {
8277 $tmp =
'iso-8859-1';
8286 if ($tmp ==
'iso-8859-1') {
8287 return mb_convert_encoding($str,
'ISO-8859-1',
'UTF-8');
8308function dol_getIdFromCode(
$db, $key, $tablename, $fieldkey =
'code', $fieldid =
'id', $entityfilter = 0, $filters =
'', $useCache =
true)
8318 if ($useCache && isset(
$conf->cache[
'codeid'][$tablename][$key][$fieldid])) {
8319 return $conf->cache[
'codeid'][$tablename][$key][$fieldid];
8322 dol_syslog(
'dol_getIdFromCode (value for field ' . $fieldid .
' from key ' . $key .
' not found into cache)', LOG_DEBUG);
8324 $sql =
"SELECT " .
$db->sanitize($fieldid) .
" as valuetoget";
8325 $sql .=
" FROM " . MAIN_DB_PREFIX .
$db->sanitize($tablename);
8326 if ($fieldkey ==
'id' || $fieldkey ==
'rowid') {
8327 $sql .=
" WHERE " .
$db->sanitize($fieldkey) .
" = " . ((int) $key);
8329 $sql .=
" WHERE " .
$db->sanitize($fieldkey) .
" = '" .
$db->escape($key) .
"'";
8331 if (!empty($entityfilter)) {
8332 $sql .=
" AND entity IN (" .
getEntity($tablename) .
")";
8338 $resql =
$db->query($sql);
8340 $obj =
$db->fetch_object($resql);
8343 $valuetoget = $obj->valuetoget;
8344 $conf->cache[
'codeid'][$tablename][$key][$fieldid] = $valuetoget;
8346 $conf->cache[
'codeid'][$tablename][$key][$fieldid] =
'';
8370 $regextext = preg_replace(
'#^/\^?#',
'', (
string) $regextext);
8371 $regextext = preg_replace(
'#\$?/[imsxuADSUXJ]*$#',
'', $regextext);
8373 if ($matchrule == 1) {
8374 if ($var ==
'mainmenu') {
8376 return (preg_match(
'/^' . $regextext .
'/', $mainmenu));
8377 } elseif ($var ==
'leftmenu') {
8379 return (preg_match(
'/^' . $regextext .
'/', $leftmenu));
8381 return 'This variable is not accessible with dol_eval';
8384 return 'This value '.$matchrule.
' for param $matchrule is not yet implemented';
8398function verifCond($strToEvaluate, $onlysimplestring =
'1')
8402 if (isset($strToEvaluate) && $strToEvaluate !==
'') {
8405 $rep =
dol_eval($strToEvaluate, 1, 1, $onlysimplestring);
8409 $rights = (bool) $rep && (!is_string($rep) || (strpos($rep,
'Exception during') ===
false && strpos($rep,
'Bad call of') ===
false && strpos($rep,
'Bad string syntax to evaluate') ===
false));
8430function dol_eval($s, $returnvalue = 1, $hideerrors = 1, $onlysimplestring =
'1')
8432 if ($returnvalue != 1) {
8433 dol_syslog(
"Use of dol_eval with parameter returnvalue = 0 is now forbidden. Please fix this", LOG_ERR);
8436 global $dolibarr_main_use_dol_eval_new;
8437 if (!empty($dolibarr_main_use_dol_eval_new)) {
8458 $db, $langs, $user, $website, $websitepage,
8459 $action, $mainmenu, $leftmenu,
8471 defined(
'T_COALESCE_EQUAL') || define(
'T_COALESCE_EQUAL', PHP_INT_MAX);
8472 defined(
'T_FN') || define(
'T_FN', PHP_INT_MAX);
8475 defined(
'T_ATTRIBUTE') || define(
'T_ATTRIBUTE', PHP_INT_MAX);
8476 defined(
'T_MATCH') || define(
'T_MATCH', PHP_INT_MAX);
8477 defined(
'T_NAME_FULLY_QUALIFIED') || define(
'T_NAME_FULLY_QUALIFIED', PHP_INT_MAX);
8478 defined(
'T_NAME_QUALIFIED') || define(
'T_NAME_QUALIFIED', PHP_INT_MAX);
8479 defined(
'T_NAME_RELATIVE') || define(
'T_NAME_RELATIVE', PHP_INT_MAX);
8482 defined(
'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG') || define(
'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG', PHP_INT_MAX);
8483 defined(
'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG') || define(
'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG', PHP_INT_MAX);
8484 defined(
'T_ENUM') || define(
'T_ENUM', PHP_INT_MAX);
8485 defined(
'T_READONLY') || define(
'T_READONLY', PHP_INT_MAX);
8488 defined(
'T_PRIVATE_SET') || define(
'T_PRIVATE_SET', PHP_INT_MAX);
8489 defined(
'T_PROTECTED_SET') || define(
'T_PROTECTED_SET', PHP_INT_MAX);
8490 defined(
'T_PUBLIC_SET') || define(
'T_PUBLIC_SET', PHP_INT_MAX);
8492 $prohibited_token_ids = [
8499 'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG',
8500 'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG',
8550 'T_OPEN_TAG_WITH_ECHO',
8584 $prohibited_variables = [
8596 $forbiddenphpfunctions = array();
8597 $forbiddenphpmethods = array();
8600 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"override_function",
"session_id",
"session_create_id",
"session_regenerate_id"));
8601 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"get_defined_functions",
"get_defined_vars",
"get_defined_constants",
"get_declared_classes"));
8602 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"function"));
8604 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"GETPOST"));
8606 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"ob_start"));
8609 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"call_user_func",
"call_user_func_array"));
8610 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"array_all",
"array_any",
"array_diff_ukey",
"array_filter",
"array_find",
"array_find_key",
"array_map",
"array_reduce",
"array_intersect_uassoc",
"array_intersect_ukey",
"array_walk",
"array_walk_recursive"));
8611 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"usort",
"uasort",
"uksort"));
8612 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"preg_replace_callback",
"preg_replace_callback_array",
"header_register_callback"));
8613 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"error_log",
"set_error_handler",
"set_exception_handler",
"libxml_set_external_entity_loader",
"register_shutdown_function",
"register_tick_function",
"unregister_tick_function"));
8614 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"spl_autoload_register",
"spl_autoload_unregister",
"iterator_apply",
"session_set_save_handler"));
8615 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"forward_static_call",
"forward_static_call_array",
"register_postsend_function"));
8616 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"readline_completion_function",
"readline_callback_handler_install"));
8619 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"exec",
"passthru",
"shell_exec",
"system",
"proc_open",
"popen"));
8620 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"pcntl_alarm",
"pcntl_exec",
"pcntl_fork",
"pcntl_waitpid",
"pcntl_wait",
"pcntl_wifexited",
"pcntl_wifstopped",
"pcntl_wifsignaled",
"pcntl_wifcontinued",
"pcntl_wexitstatus",
"pcntl_wtermsig",
"pcntl_wstopsig",
"pcntl_signal"));
8621 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"pcntl_signal_get_handler",
"pcntl_signal_dispatch",
"pcntl_get_last_error",
"pcntl_strerror",
"pcntl_sigprocmask",
"pcntl_sigwaitinfo",
"pcntl_sigtimedwait",
"pcntl_getpriority",
"pcntl_async_signals",
"pcntl_unshare", ));
8622 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"putenv",
"dl",
"apache_child_terminate",
"apache_setenv"));
8623 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_eval",
"dol_eval_new",
"dol_eval_standard",
"executeCLI",
"verifCond",
"dolEncrypt",
"dolDecrypt"));
8624 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"eval",
"create_function",
"assert",
"mb_ereg_replace"));
8627 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"require",
"include",
"require_once",
"include_once"));
8629 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_compress_dir",
"dol_decode",
"dol_dir_list",
"dol_dir_list_in_database",
"dol_delete_file",
"dol_delete_dir",
"dol_delete_dir_recursive",
"dol_copy",
"archiveOrBackupFile"));
8630 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"chdir",
"dir",
"fopen",
"file",
"file_exists",
"file_get_contents",
"file_put_contents",
"fget",
"fgetc",
"fgetcsv",
"flock",
"fputs",
"fputscsv",
"fpassthru",
"fscanf",
"fseek",
"fwrite",
"is_file",
"is_dir",
"is_link",
"mkdir",
"opendir",
"rmdir",
"scandir",
"symlink",
"touch",
"unlink",
"umask"));
8634 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"base64" .
"_" .
"decode",
"rawurl" .
"decode",
"url" .
"decode",
"str" .
"_rot13",
"hex" .
"2bin",
"printf",
"sprintf"));
8635 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_concat",
"dol_concatdesc"));
8638 $forbiddenphpmethods = array_merge($forbiddenphpmethods, array(
'invoke',
'invokeArgs'));
8640 $prohibited_functions = array_merge($forbiddenphpfunctions, $forbiddenphpmethods);
8642 $prohibited_token_arrangements = [
8647 ' T_CONSTANT_ENCAPSED_STRING ( ',
8651 $tokens = token_get_all(
"<?php return {$s};", TOKEN_PARSE);
8653 $tokens_arrangement =
' ';
8655 for ($i = 2,
$c = count($tokens) - 1; $i <
$c; ++$i) {
8656 if (is_array($tokens[$i])) {
8657 $token_id = $tokens[$i][0];
8658 $token_value = $tokens[$i][1];
8659 $token_name = token_name($tokens[$i][0]);
8661 $token_id = $tokens[$i];
8662 $token_value = $tokens[$i];
8663 $token_name = $tokens[$i];
8667 if (T_WHITESPACE === $token_id) {
8672 $tokens_arrangement .=
"{$token_name} ";
8676 T_VARIABLE === $token_id
8677 && in_array($token_value, $prohibited_variables,
true)
8679 return "Bad string syntax to evaluate. « {$token_value} » is prohibited in « {$s} »";
8684 T_STRING === $token_id
8685 && in_array($token_value, $prohibited_functions,
true)
8687 return "Bad string syntax to evaluate. « {$token_value} » is prohibited in « {$s} »";
8692 $maxi = count($prohibited_token_ids);
8693 for ($i = 0; $i < $maxi; ++$i) {
8694 if (
false !== strpos($tokens_arrangement,
" {$prohibited_token_ids[$i]} ")) {
8695 return "Bad string syntax to evaluate. « {$prohibited_token_ids[$i]} » is prohibited in « {$s} »";
8700 $maxi = count($prohibited_token_arrangements);
8701 for ($i = 0; $i < $maxi; ++$i) {
8702 if (
false !== strpos($tokens_arrangement, $prohibited_token_arrangements[$i])) {
8703 return "Bad string syntax to evaluate. « {$prohibited_token_arrangements[$i]} » is prohibited in « {$s} »";
8709 return @eval(
"return {$s};") ??
'';
8710 }
catch (Throwable $ex) {
8711 return "Bad string syntax to evaluate. Exception during evaluation: " . $s .
" - " . $ex->getMessage();
8735 global
$db, $langs, $user, $website, $websitepage;
8736 global $action, $mainmenu, $leftmenu;
8738 global $objectoffield;
8746 $isObBufferActive =
false;
8747 if ($onlysimplestring ==
'0') {
8748 $onlysimplestring =
'1';
8750 if (!in_array($onlysimplestring, array(
'1',
'2'))) {
8751 return "Bad call of dol_eval. Parameter onlysimplestring must be '1' or '2'.";
8753 if (!is_scalar($s)) {
8754 return "Bad call of dol_eval. First parameter must be a string, found ".var_export($s,
true);
8758 global $dolibarr_main_restrict_eval_methods;
8761 if (!isset($dolibarr_main_restrict_eval_methods)) {
8762 $dolibarr_main_restrict_eval_methods =
'getDolGlobalString, getDolGlobalInt, getDolCurrency, getDolEntity, getDolDBType, fetchNoCompute, hasRight, isAdmin, isExternalUser, isModEnabled, isStringVarMatching, abs, min, max, round, dol_now, preg_match';
8765 $dolibarr_main_restrict_eval_methods_array = explode(
',', str_replace(
" ",
"", $dolibarr_main_restrict_eval_methods));
8773 $specialcharsallowed =
'^$_+-.*>&|=!?():"\',/@';
8774 if ($onlysimplestring ==
'2') {
8775 $specialcharsallowed .=
'<[]';
8777 global $dolibarr_main_allow_unsecured_special_chars_in_dol_eval;
8778 if (!empty($dolibarr_main_allow_unsecured_special_chars_in_dol_eval)) {
8779 $specialcharsallowed .= (
string) $dolibarr_main_allow_unsecured_special_chars_in_dol_eval;
8781 if (preg_match(
'/[^a-z0-9\s' . preg_quote($specialcharsallowed,
'/') .
']/i', $s)) {
8782 return 'Bad string syntax to evaluate (found chars that are not chars for a simple one line clean eval string): ' . $s;
8794 if (strpos($s,
'/*') !==
false || strpos($s,
'//') !==
false) {
8795 return 'Bad string syntax to evaluate (The comment string /* and // are not allowed): ' . $s;
8799 $tmps = str_replace(
' ? ',
'__XXX__', $s);
8800 if (strpos($tmps,
'?') !==
false) {
8801 return 'Bad string syntax to evaluate (The char ? can be used only with a space before and after): ' . $s;
8805 if (preg_match(
'/<=?[^\s]/', $s)) {
8806 return 'Bad string syntax to evaluate (mode ' . $onlysimplestring .
', found a < or <= without space after): ' . $s;
8810 if (preg_match(
'/(include|include_once|require|require_once)/', $s)) {
8811 return 'Bad string syntax to evaluate (found not allowed key include|include_once|require|require_once): ' . $s;
8815 if (preg_match(
'/\$[\w]*\s*\(/', $s)) {
8816 return 'Bad string syntax to evaluate (mode ' . $onlysimplestring .
', found a call using "$abc(" or "$abc (" instead of using the direct name of the function): ' . $s;
8819 if (empty($dolibarr_main_restrict_eval_methods)) {
8825 while ($scheck && $savescheck != $scheck) {
8826 $savescheck = $scheck;
8827 $scheck = preg_replace(
'/->[a-zA-Z0-9_]+\(/',
'->__METHOD__', $scheck);
8828 $scheck = preg_replace(
'/::[a-zA-Z0-9_]+\(/',
'->__METHOD__', $scheck);
8829 $scheck = preg_replace(
'/^\(+/',
'__PARENTHESIS__ ', $scheck);
8830 $scheck = preg_replace(
'/\&\&\s+\(/',
'__ANDPARENTHESIS__ ', $scheck);
8831 $scheck = preg_replace(
'/\|\|\s+\(/',
'__ORPARENTHESIS__ ', $scheck);
8832 $scheck = preg_replace(
'/^!?[a-zA-Z0-9_]+\(/',
'__FUNCTION__', $scheck);
8833 $scheck = preg_replace(
'/\s!?[a-zA-Z0-9_]+\(/',
'__FUNCTION__', $scheck);
8834 $scheck = preg_replace(
'/^!\(/',
'__NOTANDPARENTHESIS__', $scheck);
8835 $scheck = preg_replace(
'/\s!\(/',
' __NOTANDPARENTHESIS__', $scheck);
8836 $scheck = preg_replace(
'/(\^|\')\(/',
'__REGEXSTART__', $scheck);
8841 if (strpos($scheck,
'(') !==
false) {
8842 return 'Bad string syntax to evaluate (mode ' . $onlysimplestring .
', found call of a function or method without using the direct name of the function): ' . $s;
8846 if (strpos($s,
'`') !==
false) {
8847 return 'Bad string syntax to evaluate (backtick char is forbidden): ' . $s;
8852 if (preg_match(
'/[^0-9]+\.[^0-9]+/', $s)) {
8853 return 'Bad string syntax to evaluate (dot char is forbidden if not strictly between 2 numbers): ' . $s;
8861 while ($scheck && $savescheck != $scheck) {
8862 $savescheck = $scheck;
8863 $scheck = preg_replace(
'/\$conf->[a-z\_]+->enabled/',
'__VARCONFENABLED__', $scheck);
8864 $scheck = preg_replace(
'/\$user->id/',
'__VARUSERID__', $scheck);
8865 $scheck = preg_replace(
'/\$user->hasRight/',
'__VARUSERHASRIGHT__', $scheck);
8866 $scheck = preg_replace(
'/\$user->rights/',
'__VARUSERHASRIGHT__', $scheck);
8867 $scheck = preg_replace(
'/\$user->isAdmin/',
'__VARUSERHASRIGHT__', $scheck);
8868 $scheck = preg_replace(
'/\$user->admin/',
'__VARUSERISADMIN__', $scheck);
8869 $scheck = preg_replace(
'/\$user->isExternalUser/',
'__VARUSERSOCID__', $scheck);
8870 $scheck = preg_replace(
'/\$user->socid/',
'__VARUSERSOCID__', $scheck);
8871 $scheck = preg_replace(
'/\(\$db\)/',
'__VARDB__', $scheck);
8872 $scheck = preg_replace(
'/\$langs/',
'__VARLANGSTRANS__', $scheck);
8873 $scheck = preg_replace(
'/\$mysoc/',
'__VARMYSOC__', $scheck);
8874 $scheck = preg_replace(
'/\$action/',
'__VARACTION__', $scheck);
8875 $scheck = preg_replace(
'/\$mainmenu/',
'__VARMAINMENU__', $scheck);
8876 $scheck = preg_replace(
'/\$leftmenu/',
'__VARLEFTMENU__', $scheck);
8877 $scheck = preg_replace(
'/\$websitepage/',
'__VARWEBSITEPAGE__', $scheck);
8878 $scheck = preg_replace(
'/\$website/',
'__VARWEBSITE__', $scheck);
8879 $scheck = preg_replace(
'/\$objectoffield/',
'__VAROBJECTOFFIELD__', $scheck);
8880 $scheck = preg_replace(
'/\$object/',
'__VAROBJECT__', $scheck);
8881 $scheck = preg_replace(
'/\$var/',
'__VARVAR__', $scheck);
8884 $scheck = preg_replace(
'/\$soc->canvas/',
'__VARSOCCANVAS__', $scheck);
8885 $scheck = preg_replace(
'/\$obj->canvas/',
'__VAROBJCANVAS__', $scheck);
8888 if (strpos($scheck,
'$') !==
false) {
8889 dol_syslog(
'Bad string syntax to evaluate (found use of $ not matching pattern: $user->hasRight, ($db), $langs, $mysoc, $action, $mainmenu, $leftmenu, $website, $websitepage, $objectoffield or $var123): ' . $s, LOG_WARNING);
8890 return 'Bad string syntax to evaluate (found use of $ not matching pattern: $user->hasRight, ($db), $langs, $mysoc, $action, $mainmenu, $leftmenu, $website, $websitepage, $objectoffield or $var123): ' . $s;
8895 $forbiddenphpstrings = array(
'_ENV',
'_SESSION',
'_COOKIE',
'_GET',
'_GLOBAL',
'_POST',
'_REQUEST',
'ReflectionFunction',
'SplFileObject',
'SplTempFileObject');
8897 if (empty($dolibarr_main_restrict_eval_methods)) {
8901 $forbiddenphpfunctions = array();
8902 $forbiddenphpmethods = array();
8904 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"override_function",
"session_id",
"session_create_id",
"session_regenerate_id"));
8905 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"get_defined_functions",
"get_defined_vars",
"get_defined_constants",
"get_declared_classes"));
8906 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"function"));
8908 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"GETPOST"));
8910 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"ob_start"));
8913 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"call_user_func",
"call_user_func_array"));
8914 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"array_all",
"array_any",
"array_diff_ukey",
"array_filter",
"array_find",
"array_find_key",
"array_map",
"array_reduce",
"array_intersect_uassoc",
"array_intersect_ukey",
"array_walk",
"array_walk_recursive"));
8915 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"usort",
"uasort",
"uksort"));
8916 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"preg_replace_callback",
"preg_replace_callback_array",
"header_register_callback"));
8917 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"error_log",
"set_error_handler",
"set_exception_handler",
"libxml_set_external_entity_loader",
"register_shutdown_function",
"register_tick_function",
"unregister_tick_function"));
8918 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"spl_autoload_register",
"spl_autoload_unregister",
"iterator_apply",
"session_set_save_handler"));
8919 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"forward_static_call",
"forward_static_call_array",
"register_postsend_function"));
8920 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"readline_completion_function",
"readline_callback_handler_install"));
8923 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"exec",
"passthru",
"shell_exec",
"system",
"proc_open",
"popen"));
8924 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"pcntl_alarm",
"pcntl_exec",
"pcntl_fork",
"pcntl_waitpid",
"pcntl_wait",
"pcntl_wifexited",
"pcntl_wifstopped",
"pcntl_wifsignaled",
"pcntl_wifcontinued",
"pcntl_wexitstatus",
"pcntl_wtermsig",
"pcntl_wstopsig",
"pcntl_signal"));
8925 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"pcntl_signal_get_handler",
"pcntl_signal_dispatch",
"pcntl_get_last_error",
"pcntl_strerror",
"pcntl_sigprocmask",
"pcntl_sigwaitinfo",
"pcntl_sigtimedwait",
"pcntl_getpriority",
"pcntl_async_signals",
"pcntl_unshare", ));
8926 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"putenv",
"dl",
"apache_child_terminate",
"apache_setenv"));
8927 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_eval",
"dol_eval_new",
"dol_eval_standard",
"executeCLI",
"verifCond",
"dolEncrypt",
"dolDecrypt"));
8928 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"eval",
"create_function",
"assert",
"mb_ereg_replace"));
8931 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"require",
"include",
"require_once",
"include_once"));
8933 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_compress_dir",
"dol_decode",
"dol_dir_list",
"dol_dir_list_in_database",
"dol_delete_file",
"dol_delete_dir",
"dol_delete_dir_recursive",
"dol_copy",
"archiveOrBackupFile"));
8934 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"chdir",
"dir",
"fopen",
"file",
"file_exists",
"file_get_contents",
"file_put_contents",
"fget",
"fgetc",
"fgetcsv",
"flock",
"fputs",
"fputscsv",
"fpassthru",
"fscanf",
"fseek",
"fwrite",
"is_file",
"is_dir",
"is_link",
"mkdir",
"opendir",
"rmdir",
"scandir",
"symlink",
"touch",
"unlink",
"umask"));
8938 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"base64" .
"_" .
"decode",
"rawurl" .
"decode",
"url" .
"decode",
"str" .
"_rot13",
"hex" .
"2bin",
"printf",
"sprintf"));
8939 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_concat",
"dol_concatdesc"));
8948 $forbiddenphpmethods = array_merge($forbiddenphpmethods, array(
'invoke',
'invokeArgs'));
8956 $forbiddenphpregex =
'global\s*\$';
8957 $forbiddenphpregex .=
'|posix_[a-zA-Z0-9_]*|';
8958 $forbiddenphpregex .=
'\b(' . implode(
'|', $forbiddenphpfunctions) .
')\b';
8960 $forbiddenphpmethodsregex =
'->(' . implode(
'|', $forbiddenphpmethods) .
')';
8964 $oldstringtoclean = $s;
8965 $s = str_ireplace($forbiddenphpstrings,
'__forbiddenstring__', $s);
8966 $s = preg_replace(
'/' . $forbiddenphpregex .
'/i',
'__forbiddenstring__', $s);
8967 $s = preg_replace(
'/' . $forbiddenphpmethodsregex .
'/i',
'__forbiddenstring__', $s);
8969 }
while ($oldstringtoclean != $s);
8971 if (strpos($s,
'__forbiddenstring__') !==
false) {
8972 dol_syslog(
'Bad string syntax to evaluate: ' . $s, LOG_WARNING);
8973 return 'Bad string syntax to evaluate: ' . $s;
8977 if (!empty($dolibarr_main_restrict_eval_methods)) {
8980 $pattern =
'/([\s\w\'\]\"]+)\(/';
8983 preg_match_all($pattern, $s, $matches);
8985 if (count($matches)) {
8986 foreach ($matches[1] as $m) {
8992 if (!preg_match(
'/new ([A-Z][\w]+)/i', $m, $reg)) {
8993 if (!in_array($m, $dolibarr_main_restrict_eval_methods_array)) {
8994 if ($m !=
"'" && $m !=
'"') {
8995 dol_syslog(
'Bad string syntax to evaluate: ' . $s, LOG_WARNING);
8996 return 'Bad string syntax to evaluate. A function or method "'.$m.
'" was called and is not into the parameter $dolibarr_main_restrict_eval_methods of white-listed functions and methods: ' . $s;
9000 if (!class_exists($reg[1])) {
9001 dol_syslog(
'Bad string syntax to evaluate: Class "'.$reg[1].
'" does not exist. ' . $s, LOG_WARNING);
9002 return 'Bad string syntax to evaluate. Class "'.$reg[1].
'" does not exist. ' . $s;
9004 $parents = class_parents($reg[1]);
9005 if (!in_array(
'CommonObject', $parents)) {
9006 dol_syslog(
'Bad string syntax to evaluate: Class "'.$reg[1].
'" is not allowed because only classes extended CommonObject can be used in dynamic evaluation. ' . $s, LOG_WARNING);
9007 return 'Bad string syntax to evaluate. Class "'.$reg[1].
'" is not allowed because only classes extended CommonObject can be used in dynamic evaluation. ' . $s;
9013 $forbiddenphpregex =
'global\s*\$';
9014 $forbiddenphpregex .=
'|';
9015 $forbiddenphpregex .=
'}\s*\[';
9016 $forbiddenphpregex .=
'|';
9017 $forbiddenphpregex .=
'\)\s*\(';
9021 $oldstringtoclean = $s;
9022 $s = str_ireplace($forbiddenphpstrings,
'__forbiddenstring__', $s);
9023 $s = preg_replace(
'/' . $forbiddenphpregex .
'/i',
'__forbiddenstring__', $s);
9026 }
while ($oldstringtoclean != $s);
9028 if (strpos($s,
'__forbiddenstring__') !==
false) {
9029 dol_syslog(
'Bad string syntax to evaluate: ' . $s, LOG_WARNING);
9030 return 'Bad string syntax to evaluate: ' . $s;
9036 $isObBufferActive =
true;
9037 $tmps = $hideerrors ? @eval(
'return ' . $s .
';') : eval(
'return ' . $s .
';');
9038 $tmpo = ob_get_clean();
9039 $isObBufferActive =
false;
9041 print
'Bad string syntax to evaluate. Some data were output when it should not when evaluating: ' . $s;
9045 if ($isObBufferActive) {
9047 $tmpo = ob_get_clean();
9048 $isObBufferActive =
false;
9050 $error =
'dol_eval try/catch error for string: ' . $s .
' - Error: ';
9051 $error .= $e->getMessage();
9053 return 'Exception during evaluation: ' . $s;
9054 }
catch (Error $e) {
9055 if ($isObBufferActive) {
9057 $tmpo = ob_get_clean();
9058 $isObBufferActive =
false;
9060 $error =
'dol_eval try/catch error for string: ' . $s .
' - Error: ';
9061 $error .= $e->getMessage();
9063 return 'Exception during evaluation: ' . $s;
9076 return (trim($element) !=
'');
9091 if (empty($countrycode)) {
9095 if (strtoupper($countrycode) ==
'MQ') {
9098 if (strtoupper($countrycode) ==
'SE') {
9101 if (strtoupper($countrycode) ==
'CH') {
9102 if (
$mysoc->country_code ==
'FR') {
9105 if (
$mysoc->country_code ==
'DE') {
9108 if (
$mysoc->country_code ==
'IT') {
9290 $buildprimarykeytotest = strtolower($countrycode) .
'-' . strtoupper($countrycode);
9291 if (in_array($buildprimarykeytotest, $locales)) {
9292 return strtolower($countrycode) .
'_' . strtoupper($countrycode);
9295 if (function_exists(
'locale_get_primary_language') && function_exists(
'locale_get_region')) {
9296 foreach ($locales as $locale) {
9297 $locale_language = locale_get_primary_language($locale);
9298 $locale_region = locale_get_region($locale);
9299 if (strtoupper($countrycode) == $locale_region) {
9301 return strtolower($locale_language) .
'_' . strtoupper($locale_region);
9305 dol_syslog(
"Warning Extension php-intl is not available", LOG_WARNING);
9343 global $hookmanager,
$db;
9345 if (isset(
$conf->modules_parts[
'tabs'][$type]) && is_array(
$conf->modules_parts[
'tabs'][$type])) {
9346 foreach (
$conf->modules_parts[
'tabs'][$type] as $value) {
9347 $values = explode(
':', $value);
9350 if ($mode ==
'add' && !preg_match(
'/^\-/', $values[1])) {
9351 if (count($values) !== 6) {
9352 dol_syslog(
'The module_parts["tabs"] entries must be composed of 6 values separated by ":", but got "' . $value .
'". Please check your module descriptor classes.', LOG_ERR);
9359 if ($values[0] != $type) {
9367 $posstart = strpos($str,
'(');
9368 if ($posstart > 0) {
9369 $posend = strpos($str,
')');
9370 if ($posstart > 0) {
9371 $res1 = substr($str, $posstart + 1, $posend - $posstart - 1);
9372 if (is_numeric($res1)) {
9373 $postab = (int) $res1;
9374 $values[1] =
'+' . substr($str, $posend + 1);
9379 global $objectoffield;
9387 if ($filterorigmodule) {
9388 if (strpos($values[3],
'@')) {
9389 if ($filterorigmodule !=
'external') {
9393 if ($filterorigmodule !=
'core') {
9398 $langs->load($values[3]);
9401 if (preg_match(
'/SUBSTITUTION_([^_]+)/i', $values[2], $reg)) {
9403 $substitutionarray = array();
9408 $labeltemp = explode(
',', $values[2]);
9409 $label = $langs->trans($labeltemp[0]);
9411 if (!empty($labeltemp[1]) && is_object(
$object) && !empty(
$object->id)) {
9413 $classtoload = $labeltemp[1];
9414 if (class_exists($classtoload)) {
9415 $obj =
new $classtoload(
$db);
9416 $function = $labeltemp[3];
9417 if ($obj && $function && method_exists($obj, $function)) {
9419 $nbrec = $obj->$function(
$object->id, $obj);
9420 if (!empty($nbrec)) {
9421 $label .=
'<span class="badge marginleftonlyshort">' . $nbrec .
'</span>';
9427 $url = preg_replace(
'/__ID__/i', ((is_object(
$object) && !empty(
$object->id)) ?
$object->id :
''), $values[5]);
9428 $link = parse_url($url);
9430 if (isset($link[
'query'])) {
9431 parse_str($link[
'query'], $query);
9434 $newtab[1] = $label;
9435 $newtab[2] = str_replace(
'+',
'', $values[1]);
9439 $head = array_merge(array_slice($head, 0, $postab), array($newtab), array_slice($head, $postab));
9440 } elseif ($mode ==
'remove' && preg_match(
'/^\-/', $values[1])) {
9441 if ($values[0] != $type) {
9444 $tabname = str_replace(
'-',
'', $values[1]);
9445 foreach ($head as $key => $val) {
9446 $condition = (!empty($values[3]) ?
verifCond($values[3],
'2') : 1);
9448 if ($head[$key][2] == $tabname && $condition) {
9458 if (!empty($hookmanager)) {
9459 $parameters = array(
'object' =>
$object,
'mode' => $mode,
'head' => &$head,
'filterorigmodule' => $filterorigmodule,
'type' => $type);
9461 $reshook = $hookmanager->executeHooks(
'completeTabsHead', $parameters,
$object);
9463 $head = $hookmanager->resArray;
9465 $head = array_merge($head, $hookmanager->resArray);
9483 if (is_null($string)) {
9487 if (preg_match(
'/^\[.*\]$/sm', $delimiter) || preg_match(
'/^\(.*\)$/sm', $delimiter)) {
9489 $newdelimiter = $delimiter;
9493 $newdelimiter = preg_quote($delimiter,
'/');
9496 if ($a = preg_split(
'/' . $newdelimiter .
'/', $string)) {
9498 foreach ($a as $s) {
9500 if ($pos = strpos($s, $kv)) {
9501 $ka[trim(substr($s, 0, $pos))] = trim(substr($s, $pos + strlen($kv)));
9524 preg_match_all(
'/"([^"]*)"|\'([^\']*)\'|(\S+)/', $input, $matches);
9528 $result = array_map(
9535 static function ($a, $b,
$c) {
9551 return array_values(array_filter(
9559 static function ($val) {
9575 if (!function_exists(
'getmypid')) {
9576 return mt_rand(99900000, 99965535);
9604function natural_search($fields, $value, $mode = 0, $nofirstand = 0, $sqltoadd =
'')
9608 $value = trim($value);
9611 $value = preg_replace(
'/\*/',
'%', $value);
9614 $value = preg_replace(
'/([!<>=]+)\s+([0-9' . preg_quote($langs->trans(
"SeparatorDecimal"),
'/') .
'\-])/',
'\1\2', $value);
9617 $value = preg_replace(
'/\s*\|\s*/',
'|', $value);
9621 if ($mode != -3 && $mode != 3) {
9624 $crits = array($value);
9628 if (!is_array($fields)) {
9629 $fields = array($fields);
9632 foreach ($crits as $crit) {
9633 $crit = trim($crit);
9637 foreach ($fields as $field) {
9639 $tmpcrits = explode(
'|', $crit);
9641 foreach ($tmpcrits as $tmpcrit) {
9642 if ($tmpcrit !==
'0' && empty($tmpcrit)) {
9645 $tmpcrit = trim($tmpcrit);
9647 $newres .= (($i2 > 0 || $i3 > 0) ?
' OR ' :
'');
9650 $newcrit = preg_replace(
'/([!<>=]+)/',
'', $tmpcrit);
9653 preg_match(
'/([!<>=]+)/', $tmpcrit, $reg);
9654 if (!empty($reg[1])) {
9655 $operator = $reg[1];
9657 if ($newcrit !=
'') {
9659 if (is_numeric($numnewcrit)) {
9660 $newres .=
$db->sanitize($field) .
' ' . $operator .
' ' . ((float) $numnewcrit);
9668 } elseif ($mode == 2 || $mode == -2) {
9669 $crit = preg_replace(
'/[^\-0-9,]/',
'', $crit);
9670 $newres .= ($i2 > 0 ?
' OR ' :
'') .
$db->sanitize($field) .
" " . ($mode == -2 ?
'NOT ' :
'');
9671 $newres .= $crit ?
"IN (" .
$db->sanitize(
$db->escape($crit)) .
")" :
"IN (0)";
9673 $newres .=
' OR ' .
$db->sanitize($field) .
' IS NULL';
9676 } elseif ($mode == 3 || $mode == -3) {
9677 $tmparray = explode(
',', $crit);
9678 if (count($tmparray)) {
9680 $listofcodesnot =
'';
9681 foreach ($tmparray as $val) {
9684 if (preg_match(
'/^!/', $val)) {
9685 $listofcodesnot .= ($listofcodesnot ?
',' :
'');
9686 $listofcodesnot .=
"'" .
$db->escape(preg_replace(
'/^!=?/',
'', $val)) .
"'";
9688 $listofcodes .= ($listofcodes ?
',' :
'');
9689 $listofcodes .=
"'" .
$db->escape($val) .
"'";
9693 $newres .= ($i2 > 0 ?
' OR ' :
'');
9694 if ($listofcodes && $listofcodesnot) {
9698 $newres .=
$db->sanitize($field) .
" " . ($mode == -3 ?
'NOT IN' :
'IN') .
" (" .
$db->sanitize($listofcodes, 1, 0, 1) .
")";
9700 if ($listofcodes && $listofcodesnot) {
9703 if ($listofcodesnot) {
9704 $newres .=
$db->sanitize($field) .
" " . ($mode == -3 ?
'IN ' :
'NOT IN') .
" (" .
$db->sanitize($listofcodesnot, 1, 0, 1) .
")";
9706 if ($listofcodes && $listofcodesnot) {
9712 $newres .=
' OR ' .
$db->sanitize($field) .
' IS NULL';
9714 } elseif ($mode == 4) {
9715 $tmparray = explode(
',', $crit);
9716 if (count($tmparray)) {
9718 foreach ($tmparray as $val) {
9721 $newres .= ($i2 > 0 ?
" OR (" :
"(") .
$db->sanitize($field) .
" LIKE '" .
$db->escape($val) .
",%'";
9722 $newres .=
' OR ' .
$db->sanitize($field) .
" = '" .
$db->escape($val) .
"'";
9723 $newres .=
' OR ' .
$db->sanitize($field) .
" LIKE '%," .
$db->escape($val) .
"'";
9724 $newres .=
' OR ' .
$db->sanitize($field) .
" LIKE '%," .
$db->escape($val) .
",%'";
9731 $tmpcrits = explode(
'|', $crit);
9733 foreach ($tmpcrits as $tmpcrit) {
9734 if ($tmpcrit !==
'0' && empty($tmpcrit)) {
9737 $tmpcrit = trim($tmpcrit);
9739 if ($tmpcrit ==
'^$' || strpos($crit,
'!') === 0) {
9740 $newres .= (($i2 > 0 || $i3 > 0) ?
' AND ' :
'');
9742 $newres .= (($i2 > 0 || $i3 > 0) ?
' OR ' :
'');
9746 $table = $label = $key =
null;
9748 if (strpos($field,
'ef.') === 0) {
9749 $extrafieldName = substr($field, 3);
9751 $extrafields->fetch_name_optionals_label(
'product');
9753 if (isset($extrafields->attributes[
'product'][
'type'][$extrafieldName]) && $extrafields->attributes[
'product'][
'type'][$extrafieldName] ===
'sellist') {
9755 $paramArray = $extrafields->attributes[
'product'][
'param'][$extrafieldName][
'options'] ?? [];
9756 $param = array_key_first($paramArray);
9757 list($table, $label, $key) = explode(
':', $param);
9761 if (preg_match(
'/\.(id|rowid)$/', $field)) {
9762 $newres .=
$db->sanitize($field) .
" = " . (is_numeric($tmpcrit) ? ((float) $tmpcrit) :
'0');
9764 $tmpcrit2 = $tmpcrit;
9770 $newres .= $field .
" IN (SELECT t." . $key .
" FROM " .
$db->prefix() . $table .
" AS t WHERE t." . $label .
" LIKE '%" .
$db->escape($tmpcrit2) .
"%')";
9772 if (preg_match(
'/^!/', $tmpcrit)) {
9773 $tmps .=
$db->sanitize($field) .
" NOT LIKE ";
9774 $tmpcrit2 = preg_replace(
'/^!/',
'', $tmpcrit2);
9776 $tmps .=
$db->sanitize($field) .
" LIKE ";
9780 if (preg_match(
'/^[\^\$]/', $tmpcrit)) {
9782 $tmpcrit2 = preg_replace(
'/^[\^\$]/',
'', $tmpcrit2);
9784 if (preg_match(
'/[\^\$]$/', $tmpcrit)) {
9786 $tmpcrit2 = preg_replace(
'/[\^\$]$/',
'', $tmpcrit2);
9789 if ($tmpcrit2 ==
'' || preg_match(
'/^!/', $tmpcrit)) {
9790 $tmps =
"(" . $tmps;
9793 $newres .= $tmpbefore;
9794 $newres .=
$db->escape($tmpcrit2);
9795 $newres .= $tmpafter;
9797 if ($tmpcrit2 ==
'' || preg_match(
'/^!/', $tmpcrit)) {
9798 $newres .=
" OR " . $field .
" IS NULL)";
9811 $newres .= ($newres ?
'' :
' OR ').str_replace(
'__KEYTOSEARCH__', $crit, $sqltoadd);
9815 $res = $res . ($res ?
' AND ' :
'') . ($i2 > 1 ?
'(' :
'') . $newres . ($i2 > 1 ?
')' :
'');
9819 $res = ($nofirstand ?
"" :
" AND ") .
"(" . $res .
")";
9835 $dirName = dirname($file);
9836 if ($dirName ==
'.') {
9840 if (!in_array($extName, array(
'',
'_small',
'_mini'))) {
9841 return 'Bad parameter extName';
9844 $fileName = preg_replace(
'/(\.gif|\.jpeg|\.jpg|\.png|\.bmp|\.webp|\.avif)$/i',
'', $file);
9845 $fileName = basename($fileName);
9847 if (empty($extImgTarget)) {
9848 $extImgTarget = (preg_match(
'/\.jpg$/i', $file) ?
'.jpg' :
'');
9850 if (empty($extImgTarget)) {
9851 $extImgTarget = (preg_match(
'/\.jpeg$/i', $file) ?
'.jpeg' :
'');
9853 if (empty($extImgTarget)) {
9854 $extImgTarget = (preg_match(
'/\.gif$/i', $file) ?
'.gif' :
'');
9856 if (empty($extImgTarget)) {
9857 $extImgTarget = (preg_match(
'/\.png$/i', $file) ?
'.png' :
'');
9859 if (empty($extImgTarget)) {
9860 $extImgTarget = (preg_match(
'/\.bmp$/i', $file) ?
'.bmp' :
'');
9862 if (empty($extImgTarget)) {
9863 $extImgTarget = (preg_match(
'/\.webp$/i', $file) ?
'.webp' :
'');
9865 if (empty($extImgTarget)) {
9866 $extImgTarget = (preg_match(
'/\.avif$/i', $file) ?
'.avif' :
'');
9869 if (!$extImgTarget) {
9875 $subdir =
'thumbs/';
9878 return ($dirName ? $dirName .
'/' :
'') . $subdir . $fileName . $extName . $extImgTarget;
9892 $arrayspecialines = array(1 =>
'Transport', 2 =>
'EcoTax', 3 =>
'Option');
9894 return 'Module ID ' . $idcode;
9896 if (!empty($arrayspecialines[$idcode])) {
9897 return $langs->trans($arrayspecialines[$idcode]);
9913 if (preg_match(
'/\.noexe$/i', $file)) {
9918 $mime_preview = array(
'avif',
'bmp',
'jpeg',
'png',
'gif',
'tiff',
'pdf',
'plain',
'css',
'webp',
'webm',
'mp4');
9920 $mime_preview[] =
'svg+xml';
9924 $num_mime = array_search(
dol_mimetype($file,
'', 1), $mime_preview);
9925 if ($num_mime !==
false) {
9943function dol_mimetype($file, $default =
'application/octet-stream', $mode = 0)
9946 $imgmime =
'other.png';
9950 $tmpfile = preg_replace(
'/\.noexe$/',
'', $file);
9953 if (preg_match(
'/\.txt$/i', $tmpfile)) {
9954 $mime =
'text/plain';
9955 $imgmime =
'text.png';
9956 $famime =
'file-alt';
9957 } elseif (preg_match(
'/\.rtx$/i', $tmpfile)) {
9958 $mime =
'text/richtext';
9959 $imgmime =
'text.png';
9960 $famime =
'file-alt';
9961 } elseif (preg_match(
'/\.csv$/i', $tmpfile)) {
9963 $imgmime =
'text.png';
9964 $famime =
'file-csv';
9965 } elseif (preg_match(
'/\.tsv$/i', $tmpfile)) {
9966 $mime =
'text/tab-separated-values';
9967 $imgmime =
'text.png';
9968 $famime =
'file-alt';
9969 } elseif (preg_match(
'/\.(cf|conf|log)$/i', $tmpfile)) {
9970 $mime =
'text/plain';
9971 $imgmime =
'text.png';
9972 $famime =
'file-alt';
9973 } elseif (preg_match(
'/\.ini$/i', $tmpfile)) {
9974 $mime =
'text/plain';
9975 $imgmime =
'text.png';
9977 $famime =
'file-alt';
9978 } elseif (preg_match(
'/\.md$/i', $tmpfile)) {
9979 $mime =
'text/plain';
9980 $imgmime =
'text.png';
9982 $famime =
'file-alt';
9983 } elseif (preg_match(
'/\.css$/i', $tmpfile)) {
9985 $imgmime =
'css.png';
9987 $famime =
'file-alt';
9988 } elseif (preg_match(
'/\.lang$/i', $tmpfile)) {
9989 $mime =
'text/plain';
9990 $imgmime =
'text.png';
9992 $famime =
'file-alt';
9993 } elseif (preg_match(
'/\.(crt|cer|key|pub)$/i', $tmpfile)) {
9994 $mime =
'text/plain';
9995 $imgmime =
'text.png';
9996 $famime =
'file-alt';
9997 } elseif (preg_match(
'/\.(html|htm|shtml)$/i', $tmpfile)) {
9998 $mime =
'text/html';
9999 $imgmime =
'html.png';
10001 $famime =
'file-alt';
10002 } elseif (preg_match(
'/\.(xml|xhtml)$/i', $tmpfile)) {
10003 $mime =
'text/xml';
10004 $imgmime =
'other.png';
10006 $famime =
'file-alt';
10007 } elseif (preg_match(
'/\.xaml$/i', $tmpfile)) {
10008 $mime =
'text/xml';
10009 $imgmime =
'other.png';
10011 $famime =
'file-alt';
10012 } elseif (preg_match(
'/\.bas$/i', $tmpfile)) {
10013 $mime =
'text/plain';
10014 $imgmime =
'text.png';
10016 $famime =
'file-code';
10017 } elseif (preg_match(
'/\.(c)$/i', $tmpfile)) {
10018 $mime =
'text/plain';
10019 $imgmime =
'text.png';
10021 $famime =
'file-code';
10022 } elseif (preg_match(
'/\.(cpp)$/i', $tmpfile)) {
10023 $mime =
'text/plain';
10024 $imgmime =
'text.png';
10026 $famime =
'file-code';
10027 } elseif (preg_match(
'/\.cs$/i', $tmpfile)) {
10028 $mime =
'text/plain';
10029 $imgmime =
'text.png';
10031 $famime =
'file-code';
10032 } elseif (preg_match(
'/\.(h)$/i', $tmpfile)) {
10033 $mime =
'text/plain';
10034 $imgmime =
'text.png';
10036 $famime =
'file-code';
10037 } elseif (preg_match(
'/\.(java|jsp)$/i', $tmpfile)) {
10038 $mime =
'text/plain';
10039 $imgmime =
'text.png';
10041 $famime =
'file-code';
10042 } elseif (preg_match(
'/\.php([0-9]{1})?$/i', $tmpfile)) {
10043 $mime =
'text/plain';
10044 $imgmime =
'php.png';
10046 $famime =
'file-code';
10047 } elseif (preg_match(
'/\.phtml$/i', $tmpfile)) {
10048 $mime =
'text/plain';
10049 $imgmime =
'php.png';
10051 $famime =
'file-code';
10052 } elseif (preg_match(
'/\.(pl|pm)$/i', $tmpfile)) {
10053 $mime =
'text/plain';
10054 $imgmime =
'pl.png';
10056 $famime =
'file-code';
10057 } elseif (preg_match(
'/\.sql$/i', $tmpfile)) {
10058 $mime =
'text/plain';
10059 $imgmime =
'text.png';
10061 $famime =
'file-code';
10062 } elseif (preg_match(
'/\.js$/i', $tmpfile)) {
10063 $mime =
'text/x-javascript';
10064 $imgmime =
'jscript.png';
10066 $famime =
'file-code';
10067 } elseif (preg_match(
'/\.odp$/i', $tmpfile)) {
10068 $mime =
'application/vnd.oasis.opendocument.presentation';
10069 $imgmime =
'ooffice.png';
10070 $famime =
'file-powerpoint';
10071 } elseif (preg_match(
'/\.ods$/i', $tmpfile)) {
10072 $mime =
'application/vnd.oasis.opendocument.spreadsheet';
10073 $imgmime =
'ooffice.png';
10074 $famime =
'file-excel';
10075 } elseif (preg_match(
'/\.odt$/i', $tmpfile)) {
10076 $mime =
'application/vnd.oasis.opendocument.text';
10077 $imgmime =
'ooffice.png';
10078 $famime =
'file-word';
10079 } elseif (preg_match(
'/\.mdb$/i', $tmpfile)) {
10080 $mime =
'application/msaccess';
10081 $imgmime =
'mdb.png';
10083 } elseif (preg_match(
'/\.doc[xm]?$/i', $tmpfile)) {
10084 $mime =
'application/msword';
10085 $imgmime =
'doc.png';
10086 $famime =
'file-word';
10087 } elseif (preg_match(
'/\.dot[xm]?$/i', $tmpfile)) {
10088 $mime =
'application/msword';
10089 $imgmime =
'doc.png';
10090 $famime =
'file-word';
10091 } elseif (preg_match(
'/\.xlt(x)?$/i', $tmpfile)) {
10092 $mime =
'application/vnd.ms-excel';
10093 $imgmime =
'xls.png';
10094 $famime =
'file-excel';
10095 } elseif (preg_match(
'/\.xla(m)?$/i', $tmpfile)) {
10096 $mime =
'application/vnd.ms-excel';
10097 $imgmime =
'xls.png';
10098 $famime =
'file-excel';
10099 } elseif (preg_match(
'/\.xls$/i', $tmpfile)) {
10100 $mime =
'application/vnd.ms-excel';
10101 $imgmime =
'xls.png';
10102 $famime =
'file-excel';
10103 } elseif (preg_match(
'/\.xls[bmx]$/i', $tmpfile)) {
10104 $mime =
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
10105 $imgmime =
'xls.png';
10106 $famime =
'file-excel';
10107 } elseif (preg_match(
'/\.pps[mx]?$/i', $tmpfile)) {
10108 $mime =
'application/vnd.ms-powerpoint';
10109 $imgmime =
'ppt.png';
10110 $famime =
'file-powerpoint';
10111 } elseif (preg_match(
'/\.ppt[mx]?$/i', $tmpfile)) {
10112 $mime =
'application/x-mspowerpoint';
10113 $imgmime =
'ppt.png';
10114 $famime =
'file-powerpoint';
10115 } elseif (preg_match(
'/\.pdf$/i', $tmpfile)) {
10116 $mime =
'application/pdf';
10117 $imgmime =
'pdf.png';
10118 $famime =
'file-pdf';
10119 } elseif (preg_match(
'/\.bat$/i', $tmpfile)) {
10120 $mime =
'text/x-bat';
10121 $imgmime =
'script.png';
10123 $famime =
'file-code';
10124 } elseif (preg_match(
'/\.sh$/i', $tmpfile)) {
10125 $mime =
'text/x-sh';
10126 $imgmime =
'script.png';
10128 $famime =
'file-code';
10129 } elseif (preg_match(
'/\.ksh$/i', $tmpfile)) {
10130 $mime =
'text/x-ksh';
10131 $imgmime =
'script.png';
10133 $famime =
'file-code';
10134 } elseif (preg_match(
'/\.bash$/i', $tmpfile)) {
10135 $mime =
'text/x-bash';
10136 $imgmime =
'script.png';
10138 $famime =
'file-code';
10139 } elseif (preg_match(
'/\.ico$/i', $tmpfile)) {
10140 $mime =
'image/x-icon';
10141 $imgmime =
'image.png';
10142 $famime =
'file-image';
10143 } elseif (preg_match(
'/\.(jpg|jpeg)$/i', $tmpfile)) {
10144 $mime =
'image/jpeg';
10145 $imgmime =
'image.png';
10146 $famime =
'file-image';
10147 } elseif (preg_match(
'/\.png$/i', $tmpfile)) {
10148 $mime =
'image/png';
10149 $imgmime =
'image.png';
10150 $famime =
'file-image';
10151 } elseif (preg_match(
'/\.gif$/i', $tmpfile)) {
10152 $mime =
'image/gif';
10153 $imgmime =
'image.png';
10154 $famime =
'file-image';
10155 } elseif (preg_match(
'/\.bmp$/i', $tmpfile)) {
10156 $mime =
'image/bmp';
10157 $imgmime =
'image.png';
10158 $famime =
'file-image';
10159 } elseif (preg_match(
'/\.(tif|tiff)$/i', $tmpfile)) {
10160 $mime =
'image/tiff';
10161 $imgmime =
'image.png';
10162 $famime =
'file-image';
10163 } elseif (preg_match(
'/\.svg$/i', $tmpfile)) {
10164 $mime =
'image/svg+xml';
10165 $imgmime =
'image.png';
10166 $famime =
'file-image';
10167 } elseif (preg_match(
'/\.webp$/i', $tmpfile)) {
10168 $mime =
'image/webp';
10169 $imgmime =
'image.png';
10170 $famime =
'file-image';
10171 } elseif (preg_match(
'/\.vcs$/i', $tmpfile)) {
10172 $mime =
'text/calendar';
10173 $imgmime =
'other.png';
10174 $famime =
'file-alt';
10175 } elseif (preg_match(
'/\.ics$/i', $tmpfile)) {
10176 $mime =
'text/calendar';
10177 $imgmime =
'other.png';
10178 $famime =
'file-alt';
10179 } elseif (preg_match(
'/\.torrent$/i', $tmpfile)) {
10180 $mime =
'application/x-bittorrent';
10181 $imgmime =
'other.png';
10182 $famime =
'file-o';
10183 } elseif (preg_match(
'/\.(mp3|ogg|au|wav|wma|mid)$/i', $tmpfile)) {
10185 $imgmime =
'audio.png';
10186 $famime =
'file-audio';
10187 } elseif (preg_match(
'/\.mp4$/i', $tmpfile)) {
10188 $mime =
'video/mp4';
10189 $imgmime =
'video.png';
10190 $famime =
'file-video';
10191 } elseif (preg_match(
'/\.ogv$/i', $tmpfile)) {
10192 $mime =
'video/ogg';
10193 $imgmime =
'video.png';
10194 $famime =
'file-video';
10195 } elseif (preg_match(
'/\.webm$/i', $tmpfile)) {
10196 $mime =
'video/webm';
10197 $imgmime =
'video.png';
10198 $famime =
'file-video';
10199 } elseif (preg_match(
'/\.avif$/i', $tmpfile)) {
10200 $mime =
'image/avif';
10201 $imgmime =
'image.png';
10202 $famime =
'file-image';
10203 } elseif (preg_match(
'/\.avi$/i', $tmpfile)) {
10204 $mime =
'video/x-msvideo';
10205 $imgmime =
'video.png';
10206 $famime =
'file-video';
10207 } elseif (preg_match(
'/\.divx$/i', $tmpfile)) {
10208 $mime =
'video/divx';
10209 $imgmime =
'video.png';
10210 $famime =
'file-video';
10211 } elseif (preg_match(
'/\.xvid$/i', $tmpfile)) {
10212 $mime =
'video/xvid';
10213 $imgmime =
'video.png';
10214 $famime =
'file-video';
10215 } elseif (preg_match(
'/\.(wmv|mpg|mpeg)$/i', $tmpfile)) {
10217 $imgmime =
'video.png';
10218 $famime =
'file-video';
10219 } elseif (preg_match(
'/\.(zip|rar|gz|tgz|xz|z|cab|bz2|7z|tar|lzh|zst)$/i', $tmpfile)) {
10222 $imgmime =
'archive.png';
10223 $famime =
'file-archive';
10224 } elseif (preg_match(
'/\.(exe|com)$/i', $tmpfile)) {
10225 $mime =
'application/octet-stream';
10226 $imgmime =
'other.png';
10227 $famime =
'file-o';
10228 } elseif (preg_match(
'/\.(dll|lib|o|so|a)$/i', $tmpfile)) {
10230 $imgmime =
'library.png';
10231 $famime =
'file-o';
10232 } elseif (preg_match(
'/\.err$/i', $tmpfile)) {
10234 $imgmime =
'error.png';
10235 $famime =
'file-alt';
10238 if ($famime ==
'file-o') {
10244 switch ((
int) $mode) {
10246 $tmp = explode(
'/', $mime);
10247 return (!empty($tmp[1]) ? $tmp[1] : $tmp[0]);
10273 $tablename = preg_replace(
'/^' . preg_quote(MAIN_DB_PREFIX,
'/') .
'/',
'', $tablename);
10275 $dictvalues = (isset(
$conf->cache[
'dictvalues_' . $tablename]) ?
$conf->cache[
'dictvalues_' . $tablename] :
null);
10277 if (is_null($dictvalues)) {
10278 $dictvalues = array();
10280 $sql =
"SELECT * FROM " . MAIN_DB_PREFIX . $tablename .
" WHERE 1 = 1";
10281 if ($checkentity) {
10282 $sql .=
' AND entity IN (0,' .
getEntity($tablename) .
')';
10285 $resql =
$db->query($sql);
10287 while ($obj =
$db->fetch_object($resql)) {
10288 $dictvalues[$obj->$rowidfield] = $obj;
10294 $conf->cache[
'dictvalues_' . $tablename] = $dictvalues;
10297 if (!empty($dictvalues[
$id])) {
10299 $tmp = $dictvalues[
$id];
10300 return (property_exists($tmp, $field) ? $tmp->$field :
'');
10315 $stringcolor = str_replace(
'#',
'', $stringcolor);
10317 if (!empty($stringcolor)) {
10319 $tmp = explode(
',', $stringcolor);
10320 if (count($tmp) > 1) {
10325 $hexr = $stringcolor[0] . $stringcolor[1];
10326 $hexg = $stringcolor[2] . $stringcolor[3];
10327 $hexb = $stringcolor[4] . $stringcolor[5];
10328 $r = hexdec($hexr);
10329 $g = hexdec($hexg);
10330 $b = hexdec($hexb);
10332 $bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0;
10333 if ($bright > 0.6) {
10352 if (empty($menuentry[
'enabled'])) {
10355 if ($type_user && array_key_exists(
'module', $menuentry) && $menuentry[
'module']) {
10356 $tmploops = explode(
'|', $menuentry[
'module']);
10358 foreach ($tmploops as $tmploop) {
10359 if (in_array($tmploop, $listofmodulesforexternal)) {
10368 if (!$menuentry[
'perms'] && $type_user) {
10374 if (!$menuentry[
'perms']) {
10389 $result = (ceil($n) % $x === 0) ? ceil($n) : (round(($n + $x / 2) / $x) * $x);
10390 return (
int) $result;
10412 $classfile = $classname = $classpath = $subdir = $dir_output = $dir_temp = $parent_element =
'';
10415 $module = $elementType;
10416 $element = $elementType;
10417 $subelement = $elementType;
10418 $table_element = $elementType;
10421 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $elementType, $regs)) {
10422 $element = $subelement = $regs[1];
10423 $module = $regs[2];
10424 } elseif (preg_match(
'/^([^_]+)_([^_]+)/i', $element, $regs)) {
10427 $module = $element = $regs[1];
10428 $subelement = $regs[2];
10432 if (substr($elementType, -3) ==
'det') {
10433 $module = preg_replace(
'/det$/',
'', $element);
10434 $subelement = preg_replace(
'/det$/',
'', $subelement);
10435 $classpath = $module .
'/class';
10436 $classfile = $module;
10437 $classname = preg_replace(
'/det$/',
'Line', $element);
10438 if (in_array($module, array(
'expedition',
'propale',
'facture',
'contrat',
'fichinter',
'supplier_order',
'commandefournisseur'))) {
10439 $classname = preg_replace(
'/det$/',
'Ligne', $element);
10443 if ($elementType ==
"action" || $elementType ==
"actioncomm") {
10444 $classpath =
'comm/action/class';
10445 $subelement =
'Actioncomm';
10446 $module =
'agenda';
10447 $table_element =
'actioncomm';
10448 } elseif ($elementType ==
'cronjob') {
10449 $classpath =
'cron/class';
10451 $table_element =
'cron';
10452 } elseif ($elementType ==
'adherent_type') {
10453 $classpath =
'adherents/class';
10454 $classfile =
'adherent_type';
10455 $module =
'adherent';
10456 $subelement =
'adherent_type';
10457 $classname =
'AdherentType';
10458 $table_element =
'adherent_type';
10459 } elseif ($elementType ==
'bank_account') {
10460 $classpath =
'compta/bank/class';
10462 $classfile =
'account';
10463 $classname =
'Account';
10464 } elseif ($elementType ==
'bank_line') {
10465 $classpath =
'compta/bank/class';
10467 $classfile =
'account';
10468 $classname =
'AccountLine';
10469 } elseif ($elementType ==
'category') {
10470 $classpath =
'categories/class';
10471 $module =
'categorie';
10472 $subelement =
'categorie';
10473 $table_element =
'categorie';
10474 } elseif ($elementType ==
'contact') {
10475 $classpath =
'contact/class';
10476 $classfile =
'contact';
10477 $module =
'societe';
10478 $subelement =
'contact';
10479 $table_element =
'socpeople';
10480 $subdir =
'/contact';
10481 } elseif ($elementType ==
'inventory') {
10482 $module =
'product';
10483 $classpath =
'product/inventory/class';
10484 } elseif ($elementType ==
'inventoryline') {
10485 $module =
'product';
10486 $classpath =
'product/inventory/class';
10487 $table_element =
'inventorydet';
10488 $parent_element =
'inventory';
10489 } elseif ($elementType ==
'stock' || $elementType ==
'entrepot' || $elementType ==
'warehouse') {
10491 $classpath =
'product/stock/class';
10492 $classfile =
'entrepot';
10493 $classname =
'Entrepot';
10494 $table_element =
'entrepot';
10495 } elseif ($elementType ==
'project') {
10496 $classpath =
'projet/class';
10497 $module =
'projet';
10498 $table_element =
'projet';
10499 } elseif ($elementType ==
'project_task') {
10500 $classpath =
'projet/class';
10501 $module =
'projet';
10502 $subelement =
'task';
10503 $table_element =
'projet_task';
10504 } elseif ($elementType ==
'mo') {
10505 $classpath =
'mrp/class';
10509 $table_element =
'mrp_mo';
10510 } elseif ($elementType ==
'facture' || $elementType ==
'invoice') {
10511 $classpath =
'compta/facture/class';
10512 $module =
'facture';
10513 $subelement =
'facture';
10514 $table_element =
'facture';
10515 } elseif ($elementType ==
'facturedet') {
10516 $classpath =
'compta/facture/class';
10517 $classfile =
'facture';
10518 $classname =
'FactureLigne';
10519 $module =
'facture';
10520 $table_element =
'facturedet';
10521 $parent_element =
'facture';
10522 } elseif ($elementType ==
'facturerec' || $elementType ==
'facture_rec') {
10523 $classpath =
'compta/facture/class';
10524 $classfile =
'facture-rec';
10525 $module =
'facture';
10526 $classname =
'FactureRec';
10527 } elseif ($elementType ==
'commande' || $elementType ==
'order') {
10528 $classpath =
'commande/class';
10529 $module =
'commande';
10530 $subelement =
'commande';
10531 $table_element =
'commande';
10532 } elseif ($elementType ==
'commandedet') {
10533 $classpath =
'commande/class';
10534 $classfile =
'commande';
10535 $classname =
'OrderLine';
10536 $module =
'commande';
10537 $table_element =
'commandedet';
10538 $parent_element =
'commande';
10539 } elseif ($elementType ==
'propal') {
10540 $classpath =
'comm/propal/class';
10541 $table_element =
'propal';
10542 } elseif ($elementType ==
'propaldet') {
10543 $classpath =
'comm/propal/class';
10544 $classfile =
'propal';
10545 $subelement =
'propaleligne';
10546 $module =
'propal';
10547 $table_element =
'propaldet';
10548 $parent_element =
'propal';
10549 } elseif ($elementType ==
'shipping' || $elementType ==
'shipment') {
10550 $classpath =
'expedition/class';
10551 $classfile =
'expedition';
10552 $classname =
'Expedition';
10553 $module =
'expedition';
10554 $table_element =
'expedition';
10555 } elseif ($elementType ==
'expeditiondet' || $elementType ==
'shippingdet') {
10556 $classpath =
'expedition/class';
10557 $classfile =
'expedition';
10558 $classname =
'ExpeditionLigne';
10559 $module =
'expedition';
10560 $table_element =
'expeditiondet';
10561 $parent_element =
'expedition';
10562 } elseif ($elementType ==
'delivery_note') {
10563 $classpath =
'delivery/class';
10564 $subelement =
'delivery';
10565 $module =
'expedition';
10566 } elseif ($elementType ==
'delivery') {
10567 $classpath =
'delivery/class';
10568 $subelement =
'delivery';
10569 $module =
'expedition';
10570 } elseif ($elementType ==
'deliverydet') {
10572 } elseif ($elementType ==
'supplier_proposal') {
10573 $classpath =
'supplier_proposal/class';
10574 $module =
'supplier_proposal';
10575 $element =
'supplierproposal';
10576 $classfile =
'supplier_proposal';
10577 $subelement =
'supplierproposal';
10578 } elseif ($elementType ==
'supplier_proposaldet') {
10579 $classpath =
'supplier_proposal/class';
10580 $module =
'supplier_proposal';
10581 $classfile =
'supplier_proposal';
10582 $classname =
'SupplierProposalLine';
10583 $table_element =
'supplier_proposaldet';
10584 $parent_element =
'supplier_proposal';
10585 } elseif ($elementType ==
'contract') {
10586 $classpath =
'contrat/class';
10587 $module =
'contrat';
10588 $subelement =
'contrat';
10589 $table_element =
'contract';
10590 } elseif ($elementType ==
'contratdet') {
10591 $classpath =
'contrat/class';
10592 $module =
'contrat';
10593 $table_element =
'contratdet';
10594 $parent_element =
'contrat';
10595 } elseif ($elementType ==
'mailing') {
10596 $classpath =
'comm/mailing/class';
10597 $module =
'mailing';
10598 $classfile =
'mailing';
10599 $classname =
'Mailing';
10601 } elseif ($elementType ==
'member' || $elementType ==
'adherent') {
10602 $classpath =
'adherents/class';
10603 $module =
'adherent';
10604 $subelement =
'adherent';
10605 $table_element =
'adherent';
10606 } elseif ($elementType ==
'subscription') {
10607 $classpath =
'adherents/class';
10608 $classfile =
'subscription';
10609 $module =
'adherent';
10610 $subelement =
'subscription';
10611 $classname =
'Subscription';
10612 $table_element =
'subscription';
10613 } elseif ($elementType ==
'usergroup') {
10614 $classpath =
'user/class';
10616 } elseif ($elementType ==
'mrp') {
10617 $classpath =
'mrp/class';
10622 $table_element =
'mrp_mo';
10623 } elseif ($elementType ==
'mrp_production') {
10624 $classpath =
'mrp/class';
10626 $classname =
'MoLine';
10629 $table_element =
'mrp_production';
10630 $parent_element =
'mo';
10631 } elseif ($elementType ==
'cabinetmed_cons') {
10632 $classpath =
'cabinetmed/class';
10633 $module =
'cabinetmed';
10634 $subelement =
'cabinetmedcons';
10635 $table_element =
'cabinetmedcons';
10636 } elseif ($elementType ==
'fichinter') {
10637 $classpath =
'fichinter/class';
10638 $module =
'ficheinter';
10639 $subelement =
'fichinter';
10640 $table_element =
'fichinter';
10641 } elseif ($elementType ==
'dolresource' || $elementType ==
'resource') {
10642 $classpath =
'resource/class';
10643 $module =
'resource';
10644 $subelement =
'dolresource';
10645 $table_element =
'resource';
10646 } elseif ($elementType ==
'opensurvey_sondage') {
10647 $classpath =
'opensurvey/class';
10648 $module =
'opensurvey';
10649 $subelement =
'opensurveysondage';
10650 } elseif ($elementType ==
'order_supplier' || $elementType ==
'supplier_order' || $elementType ==
'commande_fournisseur' || $elementType ==
'commandefournisseur') {
10651 $classpath =
'fourn/class';
10652 $module =
'fournisseur';
10653 $classfile =
'fournisseur.commande';
10654 $element =
'order_supplier';
10656 $classname =
'CommandeFournisseur';
10657 $table_element =
'commande_fournisseur';
10658 } elseif ($elementType ==
'commande_fournisseurdet') {
10659 $classpath =
'fourn/class';
10660 $module =
'fournisseur';
10661 $classfile =
'fournisseur.commande';
10662 $element =
'commande_fournisseurdet';
10664 $classname =
'CommandeFournisseurLigne';
10665 $table_element =
'commande_fournisseurdet';
10666 $parent_element =
'commande_fournisseur';
10667 } elseif ($elementType ==
'invoice_supplier' || $elementType ==
'supplier_invoice' || $elementType ==
'facture_fourn') {
10668 $classpath =
'fourn/class';
10669 $module =
'fournisseur';
10670 $classfile =
'fournisseur.facture';
10671 $element =
'invoice_supplier';
10673 $classname =
'FactureFournisseur';
10674 $table_element =
'facture_fourn';
10675 } elseif ($elementType ==
'facture_fourn_det') {
10676 $classpath =
'fourn/class';
10677 $module =
'fournisseur';
10678 $classfile =
'fournisseur.facture';
10679 $element =
'facture_fourn_det';
10681 $classname =
'SupplierInvoiceLine';
10682 $table_element =
'facture_fourn_det';
10683 $parent_element =
'invoice_supplier';
10684 } elseif ($elementType ==
"service") {
10685 $classpath =
'product/class';
10686 $module =
'product';
10687 $subelement =
'product';
10688 $table_element =
'product';
10689 } elseif ($elementType ==
'product_attribute') {
10690 $module =
'variants';
10691 $element =
'product_attribute';
10692 $subelement =
'product_attribute';
10693 $classpath =
'variants/class';
10694 $classfile =
'ProductAttribute';
10695 $classname =
'ProductAttribute';
10696 $table_element =
'product_attribute';
10697 } elseif ($elementType ==
'product_attribute_value') {
10698 $module =
'variants';
10699 $element =
'product_attribute_value';
10700 $subelement =
'product_attribute_value';
10701 $classpath =
'variants/class';
10702 $classfile =
'ProductAttributeValue';
10703 $classname =
'ProductAttributeValue';
10704 $table_element =
'product_attribute_value';
10705 $parent_element =
'product_attribute';
10706 } elseif ($elementType ==
'salary') {
10707 $classpath =
'salaries/class';
10708 $module =
'salaries';
10709 } elseif ($elementType ==
'payment_salary') {
10710 $classpath =
'salaries/class';
10711 $classfile =
'paymentsalary';
10712 $classname =
'PaymentSalary';
10713 $module =
'salaries';
10714 } elseif ($elementType ==
'payment') {
10715 $classpath =
'compta/paiement/class';
10716 $classfile =
'paiement';
10717 $classname =
'Paiement';
10718 $module =
'facture';
10719 $element =
'payment';
10720 $subelement =
'payment';
10721 $table_element =
'paiement';
10722 } elseif ($elementType ==
'payment_supplier') {
10723 $classpath =
'fourn/class';
10724 $classfile =
'paiementfourn';
10725 $classname =
'PaiementFourn';
10726 $module =
'fournisseur';
10727 $element =
'payment_supplier';
10728 $subelement =
'payment_supplier';
10729 $table_element =
'paiementfourn';
10730 } elseif ($elementType ==
'payment_various') {
10731 $classpath =
'compta/bank/class';
10732 $classfile =
'paymentvarious';
10733 $classname =
'PaymentVarious';
10735 $element =
'payment_various';
10736 $subelement =
'payment_various';
10737 $table_element =
'payment_various';
10738 } elseif ($elementType ==
'stocktransfer') {
10739 $classpath =
'product/stock/stocktransfer/class';
10740 $classfile =
'stocktransfer';
10741 $classname =
'StockTransfer';
10742 $module =
'stocktransfer';
10743 $subelement =
'stocktransfer';
10744 $table_element =
'stocktransfer_stocktransfer';
10745 } elseif ($elementType ==
'job' || $elementType ==
'position' || $elementType ==
'skill' || $elementType ==
'evaluation') {
10746 $classpath =
'hrm/class';
10747 $classfile = $elementType;
10748 $classname = ucfirst($elementType);
10750 $subelement = $elementType;
10751 $table_element = ($elementType ==
'position' ?
'hrm_job_user' :
'hrm_'.$elementType);
10752 $subdir =
'/'.$elementType;
10753 } elseif ($elementType ==
'productlot') {
10754 $module =
'productbatch';
10755 $classpath =
'product/stock/class';
10756 $classfile =
'productlot';
10757 $classname =
'Productlot';
10758 $element =
'productlot';
10760 $table_element =
'product_lot';
10761 } elseif ($elementType ==
'societeaccount') {
10762 $classpath =
'societe/class';
10763 $classfile =
'societeaccount';
10764 $classname =
'SocieteAccount';
10765 $module =
'societe';
10766 } elseif ($elementType ==
'websitepage' || $elementType ==
'website_page') {
10767 $classpath =
'website/class';
10768 $classfile =
'websitepage';
10769 $classname =
'Websitepage';
10770 $module =
'website';
10771 $subelement =
'websitepage';
10772 $table_element =
'website_page';
10773 } elseif ($elementType ==
'fiscalyear') {
10774 $classpath =
'core/class';
10775 $module =
'accounting';
10776 $subelement =
'fiscalyear';
10777 } elseif ($elementType ==
'chargesociales') {
10778 $classpath =
'compta/sociales/class';
10780 $table_element =
'chargesociales';
10781 } elseif ($elementType ==
'tva') {
10782 $classpath =
'compta/tva/class';
10785 $table_element =
'tva';
10786 } elseif ($elementType ==
'emailsenderprofile') {
10788 $classpath =
'core/class';
10789 $classfile =
'emailsenderprofile';
10790 $classname =
'EmailSenderProfile';
10791 $table_element =
'c_email_senderprofile';
10793 } elseif ($elementType ==
'conferenceorboothattendee') {
10794 $classpath =
'eventorganization/class';
10795 $classfile =
'conferenceorboothattendee';
10796 $classname =
'ConferenceOrBoothAttendee';
10797 $module =
'eventorganization';
10798 } elseif ($elementType ==
'conferenceorbooth') {
10799 $classpath =
'eventorganization/class';
10800 $classfile =
'conferenceorbooth';
10801 $classname =
'ConferenceOrBooth';
10802 $module =
'eventorganization';
10803 $subdir =
'/conferenceorbooth';
10804 } elseif ($elementType ==
'ccountry') {
10806 $classpath =
'core/class';
10807 $classfile =
'ccountry';
10808 $classname =
'Ccountry';
10809 $table_element =
'c_country';
10811 } elseif ($elementType ==
'ecmfiles') {
10813 $classpath =
'ecm/class';
10814 $classfile =
'ecmfiles';
10815 $classname =
'Ecmfiles';
10816 $table_element =
'ecmfiles';
10818 } elseif ($elementType ==
'knowledgerecord' || $elementType ==
'knowledgemanagement') {
10819 $module =
'knowledgemanagement';
10820 $classpath =
'knowledgemanagement/class';
10821 $classfile =
'knowledgerecord';
10822 $classname =
'KnowledgeRecord';
10823 $table_element =
'knowledgemanagement_knowledgerecord';
10825 } elseif ($elementType ==
'customer') {
10826 $module =
'societe';
10827 $classpath =
'societe/class';
10828 $classfile =
'client';
10829 $classname =
'Client';
10830 $table_element =
'societe';
10832 } elseif ($elementType ==
'fournisseur' || $elementType ==
'supplier') {
10833 $module =
'societe';
10834 $classpath =
'fourn/class';
10835 $classfile =
'fournisseur';
10836 $classname =
'Fournisseur';
10837 $table_element =
'societe';
10839 } elseif ($elementType ==
'recruitmentcandidature') {
10840 $module =
'recruitment';
10841 $classfile =
'recruitmentcandidature';
10842 $classpath =
'recruitment/class';
10843 $classname =
'RecruitmentCandidature';
10844 $subelement =
'recruitmentcandidature';
10845 $subdir =
'/recruitmentcandidature';
10846 } elseif ($elementType ==
'recruitmentjobposition') {
10847 $module =
'recruitment';
10848 $classfile =
'recruitmentjobposition';
10849 $classpath =
'recruitment/class';
10850 $classname =
'RecruitmentJobPosition';
10851 $subelement =
'recruitmentjobposition';
10852 $subdir =
'/recruitmentjobposition';
10856 if (empty($classfile)) {
10857 $classfile = strtolower($subelement);
10859 if (empty($classname)) {
10860 $classname = ucfirst($subelement);
10862 if (empty($classpath)) {
10863 $classpath = $module .
'/class';
10869 if ($module && isset(
$conf->$module)) {
10870 if (!empty(
$conf->$module->multidir_output[
$conf->entity])) {
10871 $dir_output =
$conf->$module->multidir_output[
$conf->entity];
10872 } elseif (!empty(
$conf->$module->output[
$conf->entity])) {
10873 $dir_output =
$conf->$module->output[
$conf->entity];
10874 } elseif (!empty(
$conf->$module->dir_output)) {
10875 $dir_output =
$conf->$module->dir_output;
10877 if (!empty(
$conf->$module->multidir_temp[
$conf->entity])) {
10878 $dir_temp =
$conf->$module->multidir_temp[
$conf->entity];
10879 } elseif (!empty(
$conf->$module->temp[
$conf->entity])) {
10880 $dir_temp =
$conf->$module->temp[
$conf->entity];
10881 } elseif (!empty(
$conf->$module->dir_temp)) {
10882 $dir_temp =
$conf->$module->dir_temp;
10887 if ($element ==
'order_supplier' &&
isModEnabled(
'fournisseur')) {
10888 $dir_output =
$conf->fournisseur->commande->dir_output;
10889 $dir_temp =
$conf->fournisseur->commande->dir_temp;
10890 } elseif ($element ==
'invoice_supplier' &&
isModEnabled(
'fournisseur')) {
10891 $dir_output =
$conf->fournisseur->facture->dir_output;
10892 $dir_temp =
$conf->fournisseur->facture->dir_temp;
10893 } elseif ($elementType ==
'payment' &&
isModEnabled(
'invoice') && isset(
$conf->compta->payment)) {
10897 $dir_output =
$conf->compta->payment->dir_output;
10898 $dir_temp =
$conf->compta->payment->dir_temp;
10899 } elseif ($elementType ==
'payment_supplier' &&
isModEnabled(
'fournisseur') && isset(
$conf->fournisseur->payment)) {
10900 $dir_output =
$conf->fournisseur->payment->dir_output;
10901 $dir_temp =
$conf->fournisseur->payment->dir_temp;
10905 if (!empty($dir_output)) {
10906 $dir_output .= $subdir;
10908 if (!empty($dir_temp)) {
10909 $dir_temp .= $subdir;
10912 $elementProperties = array(
10913 'module' => $module,
10914 'element' => $element,
10915 'table_element' => $table_element,
10916 'subelement' => $subelement,
10917 'classpath' => $classpath,
10918 'classfile' => $classfile,
10919 'classname' => $classname,
10920 'dir_output' => $dir_output,
10921 'dir_temp' => $dir_temp,
10922 'parent_element' => $parent_element,
10927 if (!is_object($hookmanager)) {
10928 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
10931 $hookmanager->initHooks(array(
'elementproperties'));
10935 $parameters = array(
10936 'elementType' => $elementType,
10937 'elementProperties' => $elementProperties
10940 $reshook = $hookmanager->executeHooks(
'getElementProperties', $parameters);
10943 $elementProperties = $hookmanager->resArray;
10944 } elseif (!empty($hookmanager->resArray) && is_array($hookmanager->resArray)) {
10945 $elementProperties = array_replace($elementProperties, $hookmanager->resArray);
10949 if (($key = array_search(
'elementproperties', $hookmanager->contextarray)) !==
false) {
10950 unset($hookmanager->contextarray[$key]);
10953 return $elementProperties;
10969function fetchObjectByElement($element_id, $element_type, $element_ref =
'', $useCache = 0, $maxCacheByType = 10)
10978 if ($element_prop[
'module'] ==
'product' || $element_prop[
'module'] ==
'service') {
10984 } elseif ($element_prop[
'module'] ==
'societeaccount') {
10987 $ismodenabled =
isModEnabled($element_prop[
'module']);
10992 if (is_array($element_prop) && (empty($element_prop[
'module']) || $ismodenabled)) {
10993 if ($useCache === 1 && $element_id > 0
10994 && !empty(
$conf->cache[
'fetchObjectByElement'][$element_type])
10995 && !empty(
$conf->cache[
'fetchObjectByElement'][$element_type][$element_id])
10996 && is_object(
$conf->cache[
'fetchObjectByElement'][$element_type][$element_id])
10998 return $conf->cache[
'fetchObjectByElement'][$element_type][$element_id];
11001 dol_include_once(
'/' . $element_prop[
'classpath'] .
'/' . $element_prop[
'classfile'] .
'.class.php');
11003 if (class_exists($element_prop[
'classname'])) {
11004 $className = $element_prop[
'classname'];
11005 $objecttmp =
new $className(
$db);
11006 '@phan-var-force CommonObject $objecttmp';
11009 if ($element_id > 0 || !empty($element_ref)) {
11010 $ret = $objecttmp->fetch($element_id, $element_ref);
11012 if (empty($objecttmp->module)) {
11013 $objecttmp->module = $element_prop[
'module'];
11016 if ($useCache > 0) {
11017 if (!isset(
$conf->cache[
'fetchObjectByElement'][$element_type])) {
11018 $conf->cache[
'fetchObjectByElement'][$element_type] = [];
11022 if (! empty(
$conf->cache[
'fetchObjectByElement'][$element_type]) && is_array(
$conf->cache[
'fetchObjectByElement'][$element_type]) && count(
$conf->cache[
'fetchObjectByElement'][$element_type]) >= $maxCacheByType) {
11023 array_shift(
$conf->cache[
'fetchObjectByElement'][$element_type]);
11026 $conf->cache[
'fetchObjectByElement'][$element_type][$element_id] = $objecttmp;
11035 dol_syslog($element_prop[
'classname'] .
' doesn\'t exists in /' . $element_prop[
'classpath'] .
'/' . $element_prop[
'classfile'] .
'.class.php');
11050 $arrayofregexextension = array(
11077 return $arrayofregexextension;
11090 foreach ($arrayofregexextension as $fileextension) {
11091 if (preg_match(
'/\.' . preg_quote($fileextension,
'/') .
'$/i', $filename)) {
11108 return empty($_SESSION[
'newtoken']) ?
'' : $_SESSION[
'newtoken'];
11120 return isset($_SESSION[
'token']) ? $_SESSION[
'token'] :
'';
11132 if (empty(
$conf->cache[
'nonce'])) {
11133 include_once DOL_DOCUMENT_ROOT .
'/core/lib/security.lib.php';
11137 return $conf->cache[
'nonce'];
11151 if ($method == -1) {
11162 $level = ob_get_level();
11164 while (ob_get_level() > $level) {
11169 if ($method == 0) {
11170 readfile($fullpath_original_file_osencoded);
11171 } elseif ($method == 1) {
11173 $handle = fopen($fullpath_original_file_osencoded,
"rb");
11174 while (!feof($handle)) {
11175 print fread($handle, 8192);
11178 } elseif ($method == 2) {
11180 $handle1 = fopen($fullpath_original_file_osencoded,
"rb");
11181 $handle2 = fopen(
"php://output",
"wb");
11182 stream_copy_to_stream($handle1, $handle2);
11198 $result = json_decode($stringtodecode, $assoc);
11199 if ($result ===
null) {
11200 $result = unserialize($stringtodecode, [
'allowed_classes' =>
false]);
11228 if (is_null($filter) || !is_string($filter) || $filter ===
'') {
11231 if (!preg_match(
'/^\(.*\)$/', $filter)) {
11232 $filter =
'(' . $filter .
')';
11235 $regexstring =
'\(([a-zA-Z0-9_\.]+:[<>!=insotlke]+:[^\(\)]+)\)';
11236 $firstandlastparenthesis = 0;
11238 if (!
dolCheckFilters($filter, $errorstr, $firstandlastparenthesis)) {
11242 return 'Filter syntax error - ' . $errorstr;
11247 $t = preg_replace_callback(
'/' . $regexstring .
'/i',
'dolForgeDummyCriteriaCallback', $filter);
11248 $t = str_ireplace(array(
'and',
'or',
' '),
'', $t);
11251 if (preg_match(
'/[^\(\)]/', $t)) {
11252 $tmperrorstr =
'Bad syntax of the search string';
11253 $errorstr =
'Bad syntax of the search string: ' . $filter;
11257 dol_syslog(
"forgeSQLFromUniversalSearchCriteria Filter error - " . $errorstr, LOG_WARNING);
11258 return 'Filter error - ' . $tmperrorstr;
11262 global $globalforbiddenfields;
11263 $globalforbiddenfields = $forbiddenfields;
11265 $ret = ($noand ?
"" :
" AND ") . ($nopar ?
"" :
'(');
11266 $ret .= preg_replace_callback(
'/' . $regexstring .
'/i',
'dolForgeSQLCriteriaCallback', $filter);
11267 $ret .= ($nopar ?
"" :
')');
11269 if (is_object(
$db)) {
11270 $ret = str_replace(
'__NOW__',
"'" .
$db->idate(
dol_now()) .
"'", $ret);
11272 if (is_object($user)) {
11273 $ret = str_replace(
'__USER_ID__', (
string) $user->id, $ret);
11288 $arrayofandtags = array();
11292 $parenthesislevel = 0;
11297 if ($parenthesislevel >= 1) {
11298 $sqlfilters = preg_replace(
'/^\(/',
'', preg_replace(
'/\)$/',
'', $sqlfilters));
11303 $countparenthesis = 0;
11304 while ($i < $nbofchars) {
11307 if ($char ==
'(') {
11308 $countparenthesis++;
11309 } elseif ($char ==
')') {
11310 $countparenthesis--;
11313 if ($countparenthesis == 0) {
11314 $char2 =
dol_substr($sqlfilters, $i + 1, 1);
11315 $char3 =
dol_substr($sqlfilters, $i + 2, 1);
11316 if ($char ==
'A' && $char2 ==
'N' && $char3 ==
'D') {
11319 if (!preg_match(
'/^\(.*\)$/', $s)) {
11320 $s =
'(' . $s .
')';
11322 $arrayofandtags[] = $s;
11335 if (!preg_match(
'/^\(.*\)$/', $s)) {
11336 $s =
'(' . $s .
')';
11338 $arrayofandtags[] = $s;
11341 return $arrayofandtags;
11353function dolCheckFilters($sqlfilters, &$error =
'', &$parenthesislevel = 0)
11357 $tmp = $sqlfilters;
11361 $parenthesislevel = 0;
11369 if ($char ==
'(') {
11370 if ($i == $parenthesislevel && $parenthesislevel == $counter) {
11372 $parenthesislevel++;
11375 } elseif ($char ==
')') {
11376 $nbcharremaining = ($nb - $i - 1);
11377 if ($nbcharremaining >= $counter) {
11378 $parenthesislevel = min($parenthesislevel, $counter - 1);
11380 if ($parenthesislevel > $counter && $nbcharremaining >= $counter) {
11381 $parenthesislevel = $counter;
11386 if ($counter < 0) {
11387 $error =
"Wrong balance of parenthesis in sqlfilters=" . $sqlfilters;
11388 $parenthesislevel = 0;
11396 if ($counter > 0) {
11397 $error =
"Wrong balance of parenthesis in sqlfilters=" . $sqlfilters;
11398 $parenthesislevel = 0;
11416 if (empty($matches[1])) {
11419 $tmp = explode(
':', $matches[1]);
11420 if (count($tmp) < 3) {
11439 global $globalforbiddenfields;
11442 if (empty($matches[1])) {
11445 $tmp = explode(
':', $matches[1], 3);
11446 if (count($tmp) < 3) {
11452 $newforbiddenfields = $globalforbiddenfields;
11453 if (!is_array($newforbiddenfields)) {
11454 $newforbiddenfields = array();
11457 $newforbiddenfields[] =
'pass';
11458 $newforbiddenfields[] =
'pass_crypted';
11459 $newforbiddenfields[] =
'api_key';
11461 $operand = preg_replace(
'/[^a-z0-9\._]/i',
'', trim($tmp[0]));
11464 if (!empty($newforbiddenfields)) {
11465 $operandwithoutprefix = preg_replace(
'/^[a-z0-9_]+\./i',
'', $operand);
11466 if (in_array(strtolower($operandwithoutprefix), $newforbiddenfields)) {
11471 $operator = strtoupper(preg_replace(
'/[^a-z<>!=]/i',
'', trim($tmp[1])));
11474 'NOTLIKE' =>
'NOT LIKE',
11475 'ISNOT' =>
'IS NOT',
11476 'NOTIN' =>
'NOT IN',
11480 if (array_key_exists($operator, $realOperator)) {
11481 $operator = $realOperator[$operator];
11484 $tmpescaped = $tmp[2];
11490 if ($operator ==
'IN' || $operator ==
'NOT IN') {
11491 global $dolibarr_allow_unsecured_select_in_extrafields_filter;
11494 $tmpescaped2 =
'(';
11496 $tmpelemarray = explode(
',', $tmpescaped);
11497 foreach ($tmpelemarray as $tmpkey => $tmpelem) {
11499 $tmpelem = trim($tmpelem);
11500 if (preg_match(
'/^\'(.*)\'$/', $tmpelem, $reg)) {
11501 $tmpelemarray[$tmpkey] =
"'" .
$db->escape(
$db->sanitize($reg[1], 2, 1, 1, 1)) .
"'";
11502 } elseif (ctype_digit((
string) $tmpelem)) {
11503 $tmpelemarray[$tmpkey] = (int) $tmpelem;
11504 } elseif (is_numeric((
string) $tmpelem)) {
11505 $tmpelemarray[$tmpkey] = (float) $tmpelem;
11506 } elseif (!empty($dolibarr_allow_unsecured_select_in_extrafields_filter)) {
11507 $tmpelemarray[$tmpkey] = preg_replace(
'/[^a-z0-9_<>=!\s]/i',
'', $tmpelem);
11509 $tmpelemarray[$tmpkey] = preg_replace(
'/[^a-z0-9_]/i',
'', $tmpelem);
11512 $tmpescaped2 .= implode(
',', $tmpelemarray);
11513 $tmpescaped2 .=
')';
11515 $tmpescaped = $tmpescaped2;
11516 } elseif ($operator ==
'LIKE' || $operator ==
'NOT LIKE') {
11517 if (preg_match(
'/^\'([^\']*)\'$/', $tmpescaped, $regbis)) {
11518 $tmpescaped = $regbis[1];
11521 $tmpescaped =
"'" .
$db->escape($tmpescaped) .
"'";
11522 } elseif (preg_match(
'/^\'(.*)\'$/', $tmpescaped, $regbis)) {
11525 $tmpescaped =
"'" .
$db->escape($regbis[1]) .
"'";
11527 if (strtoupper($tmpescaped) ==
'NULL') {
11528 $tmpescaped =
'NULL';
11529 } elseif (ctype_digit((
string) $tmpescaped)) {
11530 $tmpescaped = (int) $tmpescaped;
11531 } elseif (is_numeric((
string) $tmpescaped)) {
11532 $tmpescaped = (float) $tmpescaped;
11534 $tmpescaped = preg_replace(
'/[^a-z0-9_]/i',
'', $tmpescaped);
11538 return '(' .
$db->escape($operand) .
' ' . strtoupper($operator) .
' ' . $tmpescaped .
')';
11553 dol_syslog(
'getTimelineIcon::begin', LOG_DEBUG);
11556 $out =
'<!-- timeline icon -->' .
"\n";
11557 $iconClass =
'fa fa-comments';
11562 if ($histo[$key][
'percent'] == -1) {
11563 $colorClass =
'timeline-icon-not-applicble';
11564 $pictoTitle = $langs->trans(
'StatusNotApplicable');
11565 } elseif ($histo[$key][
'percent'] == 0) {
11566 $colorClass =
'timeline-icon-todo';
11567 $pictoTitle = $langs->trans(
'StatusActionToDo') .
' (0%)';
11568 } elseif ($histo[$key][
'percent'] > 0 && $histo[$key][
'percent'] < 100) {
11569 $colorClass =
'timeline-icon-in-progress';
11570 $pictoTitle = $langs->trans(
'StatusActionInProcess') .
' (' . $histo[$key][
'percent'] .
'%)';
11571 } elseif ($histo[$key][
'percent'] >= 100) {
11572 $colorClass =
'timeline-icon-done';
11573 $pictoTitle = $langs->trans(
'StatusActionDone') .
' (100%)';
11576 if ($actionstatic->code ==
'AC_TICKET_CREATE') {
11577 $iconClass =
'fa fa-ticket';
11578 } elseif ($actionstatic->code ==
'AC_TICKET_MODIFY') {
11579 $iconClass =
'fa fa-pencilxxx';
11580 } elseif (preg_match(
'/^TICKET_MSG/', $actionstatic->code)) {
11581 $iconClass =
'fa fa-comments';
11582 } elseif (preg_match(
'/^TICKET_MSG_PRIVATE/', $actionstatic->code)) {
11583 $iconClass =
'fa fa-mask';
11585 if ($actionstatic->type_picto) {
11586 $img_picto =
img_picto(
'', $actionstatic->type_picto);
11588 if ($actionstatic->type_code ==
'AC_RDV') {
11589 $iconClass =
'fa fa-handshake';
11590 } elseif ($actionstatic->type_code ==
'AC_TEL') {
11591 $iconClass =
'fa fa-phone';
11592 } elseif ($actionstatic->type_code ==
'AC_FAX') {
11593 $iconClass =
'fa fa-fax';
11594 } elseif ($actionstatic->type_code ==
'AC_EMAIL') {
11595 $iconClass =
'fa fa-envelope';
11596 } elseif ($actionstatic->type_code ==
'AC_INT') {
11597 $iconClass =
'fa fa-shipping-fast';
11598 } elseif ($actionstatic->type_code ==
'AC_OTH_AUTO') {
11599 $iconClass =
'fa fa-robot';
11600 } elseif (!preg_match(
'/_AUTO/', $actionstatic->type_code)) {
11601 $iconClass =
'fa fa-robot';
11606 $out .=
'<i class="' . $iconClass .
' ' . $colorClass .
'" title="' . $pictoTitle .
'">' . $img_picto .
'</i>' .
"\n";
11620 $documents = array();
11622 $sql =
'SELECT ecm.rowid as id, ecm.src_object_type, ecm.src_object_id, ecm.filepath, ecm.filename, ecm.agenda_id';
11623 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'ecm_files ecm';
11624 $sql .=
" WHERE ecm.filepath = 'agenda/" . ((int)
$object->id) .
"'";
11626 $sql .=
' OR ecm.agenda_id = ' . (int)
$object->id;
11627 $sql .=
' ORDER BY ecm.position ASC';
11629 $resql =
$db->query($sql);
11631 if (
$db->num_rows($resql)) {
11632 while ($obj =
$db->fetch_object($resql)) {
11633 $documents[$obj->id] = $obj;
11653function buildParamDate($prefix, $timestamp =
null, $hourTime =
'', $gm =
'auto')
11655 if ($timestamp ===
null) {
11656 $timestamp =
GETPOSTDATE($prefix, $hourTime, $gm);
11663 if ($hourTime ===
'getpost' || ($timestamp !==
null &&
dol_print_date($timestamp,
'%H:%M:%S') !==
'00:00:00')) {
11664 $TParam = array_merge($TParam, array(
11671 return '&' . http_build_query($TParam);
11692function recordNotFound($message =
'', $printheader = 1, $printfooter = 1, $showonlymessage = 0, $params =
null)
11694 global
$conf,
$db, $langs, $hookmanager;
11697 if (!is_object($langs)) {
11698 include_once DOL_DOCUMENT_ROOT .
'/core/class/translate.class.php';
11700 $langs->setDefaultLang();
11703 $langs->load(
"errors");
11705 if ($printheader) {
11706 if (function_exists(
"llxHeader")) {
11708 } elseif (function_exists(
"llxHeaderVierge")) {
11713 print
'<div class="error">';
11714 if (empty($message)) {
11715 print $langs->trans(
"ErrorRecordNotFound");
11717 print $langs->trans($message);
11722 if (empty($showonlymessage)) {
11723 if (empty($hookmanager)) {
11724 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
11727 $hookmanager->initHooks(array(
'main'));
11730 $parameters = array(
'message' => $message,
'params' => $params);
11731 $reshook = $hookmanager->executeHooks(
'getErrorRecordNotFound', $parameters,
$object, $action);
11732 print $hookmanager->resPrint;
11735 if ($printfooter && function_exists(
"llxFooter")) {
11737 if (is_object(
$db)) {
11778 foreach ($array2 as $key => $value) {
11779 if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
11782 $merged[$key] = $value;
11797 if (!empty($obj->socid)) {
11798 return (
int) $obj->socid;
11799 } elseif (!empty($obj->soc_id)) {
11800 return (
int) $obj->soc_id;
11801 } elseif (!empty($obj->societe_id)) {
11802 return (
int) $obj->societe_id;
11815 if (!empty($_SESSION[
'dol_screenheight']) && $_SESSION[
'dol_screenheight'] < 700) {
11817 } elseif (!empty($_SESSION[
'dol_screenheight']) && $_SESSION[
'dol_screenheight'] < 950) {
11819 } elseif (!empty($_SESSION[
'dol_screenheight']) && $_SESSION[
'dol_screenheight'] > 1130) {
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
global $dolibarr_main_url_root
if(!defined( 'NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined( 'NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined( 'NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined( 'NOIPCHECK')) llxHeaderVierge($title, $head="", $disablejs=0, $disablehead=0, $arrayofjs=[], $arrayofcss=[], $ws='')
Header function.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
static getValidAddress($address, $format, $encode=0, $maxnumberofemail=0)
Return a formatted address string for SMTP protocol.
Class to manage GeoIP conversion Usage: $geoip=new GeoIP('country',$datfile); $geoip->getCountryCodeF...
Class to manage invoices.
Class to manage predefined suppliers products.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
isACompany()
Check if third party is a company (Business) or an end user (Consumer)
Class to manage translations.
Class to manage Dolibarr users.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
dol_get_prev_month($month, $year)
Return previous month.
dol_get_next_day($day, $month, $year)
Return next day.
getServerTimeZoneInt($refgmtdate='now')
Return server timezone int.
dol_get_prev_day($day, $month, $year)
Return previous day.
dol_get_next_month($month, $year)
Return next month.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_is_file($pathoffile)
Return if path is a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_is_dir($folder)
Test if filename is a directory.
$date_start
Variables from include:
isValidMailDomain($mail)
Return true if email has a domain name that can be resolved to MX type.
isValidVATID($company)
Check if VAT numero is valid (check done on syntax only, no database or remote access)
dol_html_entity_decode($a, $b, $c='UTF-8', $keepsomeentities=0)
Replace html_entity_decode functions to manage errors.
dol_now($mode='gmt')
Return date for now.
dolSort($arraytosort)
Sort an array using a user defined function.
verifCond($strToEvaluate, $onlysimplestring='1')
Verify if condition in string is ok or not.
getDolGlobalLoginBadCharUnauthorized()
Return the list of unauthorized characters in user logins.
recordNotFound($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Displays an error page when a record is not found.
getDolGlobalFloat($key, $default=0)
Return a Dolibarr global constant float value.
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formatted size.
isOnlyOneLocalTax($local)
Return true if LocalTax (1 or 2) is unique.
getExecutableContent()
Return array of extension for executable files of text files that can contains executable code.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
dol_print_email($email, $contactid=0, $socid=0, $addlink=0, $max=0, $showinvalid=2, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
get_default_localtax($thirdparty_seller, $thirdparty_buyer, $local, $idprod=0)
Function that return localtax of a product line (according to seller, buyer and product vat rate) If ...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
dolCheckFilters($sqlfilters, &$error='', &$parenthesislevel=0)
Return if a $sqlfilters parameter has a valid balance of parenthesis.
dol_getmypid()
Return getmypid() or random PID when function is disabled Some web hosts disable this php function fo...
getLanguageCodeFromCountryCode($countrycode)
Return default language from country code.
setEntity($currentobject)
Set entity id to use when to create an object.
dolForgeExplodeAnd($sqlfilters)
Explode an universal search string with AND parts.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
dolExplodeIntoArray($string, $delimiter=';', $kv='=')
Split a string with 2 keys into key array.
GETPOSTDATE($prefix, $hourTime='', $gm='auto', $saverestore='')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
dol_print_ip($ip, $mode=0, $showname=0)
Return an IP formatted to be shown on screen.
dol_ucfirst($string, $encoding="UTF-8")
Convert first character of the first word of a string to upper.
dol_print_phone($phone, $countrycode='', $contactid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
dol_strtolower($string, $encoding="UTF-8")
Convert a string to lower.
dol_htmlentitiesbr_decode($stringtodecode, $pagecodeto='UTF-8')
This function is called to decode a HTML string (it decodes entities and br tags)
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
isVisibleToUserType($type_user, &$menuentry, &$listofmodulesforexternal)
Function to test if an entry is enabled or not.
dolGetFirstLineOfText($text, $nboflines=1, $charset='UTF-8')
Return first line of text.
dol_format_address($object, $withcountry=0, $sep="\n", $outputlangs=null, $mode=0, $extralangcode='')
Return a formatted address (part address/zip/town/state) according to country rules.
getDolUserInt($key, $default=0, $tmpuser=null)
Return Dolibarr user constant int value.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
getObjectSocId($obj)
Get the socid of an object, supporting legacy attribute names.
getListLimitFromScreenHeight()
Get the limit of list to show according to the screen height.
isASecretKey($keyname)
Return if string has a name dedicated to store a secret.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_string_onlythesehtmlattributes($stringtoclean, $allowed_attributes=null, $ishtml=null)
Clean a string from some undesirable HTML tags.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_eval_new($s)
Replace eval function to add more security.
getCallerInfoString()
Get caller info as a string that can be appended to a log message.
roundUpToNextMultiple($n, $x=5)
Round to next multiple.
dol_user_country()
Return country code for current user.
getLabelSpecialCode($idcode)
Make content of an input box selected when we click into input field.
getMultidirTemp($object, $module='', $forobject=0)
Return the full path of the directory where a module (or an object of a module) stores its temporary ...
currentToken()
Return the value of token currently saved into session with name 'token'.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
getDolEntity()
Return the current entity.
picto_required()
Return picto saying a field is required.
isDolTms($timestamp)
isDolTms check if a timestamp is valid.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_print_url($url, $target='_blank', $max=32, $withpicto=0, $morecss='')
Show Url link.
dol_sanitizePathName($str, $newstr='_', $unaccent=0, $allowdash=0)
Clean a string to use it as a path name.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getTaxesFromId($vatrate, $buyer=null, $seller=null, $firstparamisid=1)
Get tax (VAT) main information from Id.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
utf8_valid($str)
Check if a string is in UTF8.
getDolUserString($key, $default='', $tmpuser=null)
Return Dolibarr user constant string value.
getDolOptimizeSmallScreen()
Return if render must be optimized for small screen.
isValidMXRecord($domain)
Return if the domain name has a valid MX record.
GETPOSTISARRAY($paramname, $method=0)
Return true if the parameter $paramname is submit from a POST OR GET as an array.
jsonOrUnserialize($stringtodecode, $assoc=true)
Decode an encoded string.
dol_print_socialnetworks($value, $contactid, $socid, $type, $dictsocialnetworks=array())
Show social network link.
dolChmod($filepath, $newmask='')
Change mod of a file.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
get_localtax_by_third($local)
Get values of localtaxes (1 or 2) for company country for the common vat with the highest value.
dol_escape_php($stringtoescape, $stringforquotes=2)
Returns text escaped for inclusion into a php string, build with double quotes " or '.
dolSetCookie(string $cookiename, string $cookievalue, int $expire=-1)
Set a cookie.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getElementProperties($elementType)
Get an array with properties of an element.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
dol_get_object_properties($obj, $properties=[])
Get value of properties for an object - including magic properties when requested.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_strftime($fmt, $ts=false, $is_gmt=false)
Format a string.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_string_neverthesehtmltags($stringtoclean, $disallowed_tags=array('textarea'), $cleanalsosomestyles=0)
Clean a string from some undesirable HTML tags.
isValidPhone($phone)
Return true if phone number syntax is ok TODO Decide what to do with this.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.: VAT NPR in France)
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
getBrowserInfo($user_agent)
Return information about user browser.
dolGetFirstLetters($s, $nbofchar=1)
Return first letters of a strings.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
dol_clone_in_array($srcobject, $startlevel=0)
Create a clone of instance of object into a full array, using recursive call.
dol_strtoupper($string, $encoding="UTF-8")
Convert a string to upper.
getMultidirVersion($object, $module='', $forobject=0)
Return the full path of the directory where a module (or an object of a module) stores its versioned ...
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
dol_sanitizeUrl($stringtoclean, $type=1)
Clean a string to use it as an URL (into a href or src attribute)
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
ascii_check($str)
Check if a string is in ASCII.
get_date_range($date_start, $date_end, $format='', $outputlangs=null, $withparenthesis=1)
Format output for start and end date.
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
print_date_range($date_start, $date_end, $format='', $outputlangs=null)
Format output for start and end date.
getArrayOfSocialNetworks()
Get array of social network dictionary.
getDolDefaultContextPage($s)
Return the default context page string.
safeArrayMap($callback, array $array)
Add a function to replace array_map with allowed callback.
num2Alpha($n)
Return a numeric value into an Excel like column number.
dol_size($size, $type='')
Optimize a size for some browsers (phone, smarphone...)
dolGetCountryCodeFromIp($ip)
Return a country code from IP.
dol_textishtml($msg, $option=0)
Return if a text is a html content.
colorIsLight($stringcolor)
Return true if the color is light.
dol_escape_all($stringtoescape)
Returns text escaped for all protocols (so only alpha chars and numbers)
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dolExplodeKeepIfQuotes($input)
Explode a search string into an array but do not explode when keys are inside quotes.
readfileLowMemory($fullpath_original_file_osencoded, $method=-1)
Return a file on output using a low memory.
dolIsAllowedForPreview($file)
Return if a file is qualified for preview.
dolForgeSQLCriteriaCallback($matches)
Function to forge a SQL criteria from a USF (Universal Filter Syntax) string.
dol_shutdown()
Function called at end of web php process.
dol_print_address($address, $htmlid, $element, $id, $noprint=0, $charfornl='')
Format address string.
dol_escape_uri($stringtoescape)
Returns text escaped by RFC 3986 for inclusion into a clickable link.
dol_print_profids($profID, $profIDtype, $countrycode='', $addcpButton=1)
Format professional IDs according to their country.
if(!function_exists( 'utf8_encode')) if(!function_exists('utf8_decode')) if(!function_exists( 'str_starts_with')) if(!function_exists('str_ends_with')) if(!function_exists( 'str_contains')) formatLogObject($data)
Return a string serialized to be output on log with dol_syslog() An option allow to output log in one...
getDolDBType()
Return the current entity.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_string_nounprintableascii($str, $removetabcrlf=1)
Clean a string from all non printable ASCII chars (0x00-0x1F and 0x7F).
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalBool($key, $default=false)
Return a Dolibarr global constant boolean value.
getTimelineIcon($actionstatic, &$histo, $key)
Get timeline icon.
dolCloseUnclosedHtmlTags($text)
Close the HTML tags left open in a truncated HTML string.
get_product_localtax_for_country($idprod, $local, $thirdpartytouseforcountry)
Return localtax vat rate of a product in a particular country or default country vat if product is un...
getUserRemoteIP($trusted=0)
Return the real IP of remote user.
buildParamDate($prefix, $timestamp=null, $hourTime='', $gm='auto')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
isAFileWithExecutableContent($filename)
Return if a file can contains executable content.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
dol_string_is_good_iso($s, $clean=0)
Check if a string is a correct iso string If not, it will not be considered as HTML encoded even if i...
getNonce()
Return a random string to be used as a nonce value for js.
isStringVarMatching($var, $regextext, $matchrule=1)
Check if a variable with name $var start with $regextext.
dolSlugify($stringtoslugify)
Returns text slugified (lowercase and no special char, separator is "-").
dol_concat($text1, $text2)
Concat 2 strings.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
dol_nboflines($s, $maxchar=0)
Return nb of lines of a clear text.
dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox=0, $check='restricthtml')
Sanitize a HTML to remove js, dangerous content and external links.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
dol_escape_xml($stringtoescape)
Returns text escaped for inclusion into a XML string.
getActionCommEcmList($object)
getActionCommEcmList
dol_ucwords($string, $encoding="UTF-8")
Convert first character of all the words of a string to upper.
dolForgeDummyCriteriaCallback($matches)
Function to forge a SQL criteria from a Dolibarr filter syntax string.
dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0, $allowed_tags=array(), $allowlink=0, $allowscript=0, $allowstyle=0, $allowphp=0)
Clean a string to keep only desirable HTML tags.
dol_escape_json($stringtoescape)
Returns text escaped for inclusion into javascript code.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.
dol_validElement($element)
Return if var element is ok.
dol_sanitizeKeyCode($str)
Clean a string to use it as a key or code.
isModEnabled($module)
Is Dolibarr module enabled.
array_merge_recursive_distinct(array $array1, array $array2)
Recursively merges two arrays while preserving keys and replacing existing values.
getWarningDelay($module, $parmlevel1, $parmlevel2='')
Return a warning delay You can use it like this: if (getWarningDelay('module', 'paramlevel1')) It rep...
utf8_check($str)
Check if a string is in UTF8.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular VAT rate, when selling a product with vat $vatrate,...
dol_eval_standard($s, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
get_product_vat_for_country($idprod, $thirdpartytouseforcountry, $idprodfournprice=0)
Return vat rate of a product in a particular country, or default country vat if product is unknown.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
getDoliDBInstance($type, $host, $user, $pass, $name, $port)
Return a DoliDB instance (database handler).
dol_sanitizeEmail($stringtoclean)
Clean a string to use it as an Email.
dol_nboflines_bis($text, $maxlinesize=0, $charset='UTF-8')
Return nb of lines of a formatted text with and (WARNING: string must not have mixed and br sep...
const MODULE_MAPPING
This mapping defines the conversion to the current internal names from the alternative allowed names ...
dolBECalculateStructuredCommunication($invoice_number, $invoice_type)
Calculate Structured Communication / BE Bank payment reference number.
dol_convertToWord($num, $langs, $currency='', $centimes=false)
Function to return a number into a text.
div refaddress div address
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
showSimpleHTMLTable($outputlangs, $object)
Returns simple order table template as string.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
dol_setcache($memoryid, $data, $expire=0, $filecache=0, $replace=0)
Save data into a memory area shared by all users, all sessions on server.
dol_getcache($memoryid, $filecache=0)
Read a memory area shared by all users, all sessions on server.
dolGetRandomBytes($length)
Return a string of random bytes (hexa string) with length = $length for cryptographic purposes.
isHTTPS()
Return if we are using a HTTPS connection Check HTTPS (no way to be modified by user but may be empty...
realCharForNumericEntities($matches)
Return the real char for a numeric entities.