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);
172 case 'invoice_supplier':
175 case 'order_supplier':
178 case 'recruitmentjobposition':
180 $subdirectory =
'/recruitmentjobposition';
182 case 'recruitmentcandidature':
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':
198 $subdirectory =
'/commande';
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-entity-and-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-entity-and-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-entity-and-object='.$module;
277 } elseif (isset(
$conf->$module) && property_exists(
$conf->$module,
'dir_temp')) {
280 return 'error-dirtemp-not-defined-for-this-entity-and-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 static $arrayconv =
null;
539 static $arrayconvbis =
null;
540 if ($arrayconv ===
null) {
546 $arrayconv[
'supplier_order'] =
'fournisseur';
547 $arrayconv[
'supplier_invoice'] =
'fournisseur';
576 $moduletomoduletouse = array(
577 'invoice' =>
'facture',
579 $moduleParmsMapping = array(
580 'product' =>
'produit',
583 if (!empty($moduletomoduletouse[
$module])) {
587 $warningDelayPath = $parmlevel1;
588 if (!empty($moduleParmsMapping[$warningDelayPath])) {
589 $warningDelayPath = $moduleParmsMapping[$warningDelayPath];
593 if (!empty(
$conf->$module) && !empty(
$conf->$module->$warningDelayPath) && !empty(
$conf->$module->$warningDelayPath->$parmlevel2) && !empty(
$conf->$module->$warningDelayPath->$parmlevel2->warning_delay)) {
594 return (
int)
$conf->$module->$warningDelayPath->$parmlevel2->warning_delay;
597 if (!empty(
$conf->$module) && !empty(
$conf->$module->$warningDelayPath) && !empty(
$conf->$module->$warningDelayPath->warning_delay)) {
598 return (
int)
$conf->$module->$warningDelayPath->warning_delay;
613 if ($timestamp ===
'') {
614 dol_syslog(
'Using empty string for a timestamp is deprecated, prefer use of null when calling page ' . $_SERVER[
"PHP_SELF"] .
getCallerInfoString(), LOG_DEBUG);
617 if (is_null($timestamp) || !is_numeric($timestamp)) {
636function getDoliDBInstance($type, $host, $user, $pass, $name, $port, $forcenew =
false)
638 require_once DOL_DOCUMENT_ROOT .
"/core/db/" . $type .
'.class.php';
640 $class =
'DoliDB' . ucfirst($type);
641 $db =
new $class($type, $host, $user, $pass, $name, $port, $forcenew);
662function getEntity($element, $shared = 1, $currentobject =
null)
666 if (!is_object($hookmanager)) {
667 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
674 $element =
'project';
677 $element =
'contract';
679 case 'order_supplier':
680 $element =
'supplier_order';
682 case 'invoice_supplier':
683 $element =
'supplier_invoice';
687 if (is_object($mc)) {
688 $out = $mc->getEntity($element, $shared, $currentobject);
691 $addzero = array(
'user',
'usergroup',
'cronjob',
'c_email_templates',
'email_template',
'default_values',
'overwrite_trans',
'extrafields');
693 $addzero[] =
'c_holiday_types';
695 if (in_array($element, $addzero)) {
698 $out .= ((int)
$conf->entity);
703 'element' => $element,
706 'currentobject' => $currentobject,
710 $reshook = $hookmanager->executeHooks(
'hookGetEntity', $parameters, $currentobject, $action);
712 if (is_numeric($reshook)) {
713 if ($reshook == 0 && !empty($hookmanager->resPrint)) {
714 $out .=
',' . $hookmanager->resPrint;
715 } elseif ($reshook == 1) {
716 $out = $hookmanager->resPrint;
733 if (is_object($mc) && method_exists($mc,
'setEntity')) {
734 return $mc->setEntity($currentobject);
736 return ((is_object($currentobject) && $currentobject->id > 0 && ((
int) $currentobject->entity) > 0) ? (
int) $currentobject->entity :
$conf->entity);
748 return preg_match(
'/(_pass|password|_pw|_key|securekey|serverkey|secret\d?|p12key|exportkey|_PW_[a-z]+|token)$/i', $keyname);
761 for ($r =
""; $n >= 0; $n = intval($n / 26) - 1) {
762 $r = chr($n % 26 + 0x41) . $r;
786 include_once DOL_DOCUMENT_ROOT .
'/includes/mobiledetect/mobiledetectlib/Mobile_Detect.php';
793 $user_agent = substr($user_agent, 0, 512);
796 $detectmobile =
new Mobile_Detect(
null, $user_agent);
797 $tablet = $detectmobile->isTablet();
799 if ($detectmobile->isMobile()) {
803 if ($detectmobile->is(
'AndroidOS')) {
804 $os = $phone =
'android';
805 } elseif ($detectmobile->is(
'BlackBerryOS')) {
806 $os = $phone =
'blackberry';
807 } elseif ($detectmobile->is(
'iOS')) {
810 } elseif ($detectmobile->is(
'PalmOS')) {
811 $os = $phone =
'palm';
812 } elseif ($detectmobile->is(
'SymbianOS')) {
814 } elseif ($detectmobile->is(
'webOS')) {
816 } elseif ($detectmobile->is(
'MaemoOS')) {
818 } elseif ($detectmobile->is(
'WindowsMobileOS') || $detectmobile->is(
'WindowsPhoneOS')) {
824 if (preg_match(
'/linux/i', $user_agent)) {
826 } elseif (preg_match(
'/macintosh/i', $user_agent)) {
828 } elseif (preg_match(
'/windows/i', $user_agent)) {
834 if (preg_match(
'/firefox(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
836 $version = empty($reg[2]) ?
'' : $reg[2];
837 } elseif (preg_match(
'/edge(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
839 $version = empty($reg[2]) ?
'' : $reg[2];
840 } elseif (preg_match(
'/chrome(\/|\s)([\d\.]+)/i', $user_agent, $reg)) {
842 $version = empty($reg[2]) ?
'' : $reg[2];
843 } elseif (preg_match(
'/chrome/i', $user_agent, $reg)) {
846 } elseif (preg_match(
'/iceweasel/i', $user_agent)) {
848 } elseif (preg_match(
'/epiphany/i', $user_agent)) {
850 } elseif (preg_match(
'/safari(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
852 $version = empty($reg[2]) ?
'' : $reg[2];
853 } elseif (preg_match(
'/opera(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
856 $version = empty($reg[2]) ?
'' : $reg[2];
857 } elseif (preg_match(
'/(MSIE\s([0-9]+\.[0-9]))|.*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) {
859 $version = end($reg);
860 } elseif (preg_match(
'/(Windows NT\s([0-9]+\.[0-9])).*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) {
863 $version = end($reg);
864 } elseif (preg_match(
'/l[iy]n(x|ks)(\(|\/|\s)*([\d\.]+)/i', $user_agent, $reg)) {
866 $name =
'textbrowser';
867 $version = empty($reg[3]) ?
'' : $reg[3];
868 } elseif (preg_match(
'/w3m\/([\d\.]+)/i', $user_agent, $reg)) {
870 $name =
'textbrowser';
871 $version = empty($reg[1]) ?
'' : $reg[1];
883 'browsername' => $name,
884 'browserversion' => $version,
886 'browserua' => $user_agent,
901 $disconnectdone =
false;
903 if (is_object($db) && !empty($db->connected)) {
904 $depth = $db->transaction_opened;
905 $disconnectdone = $db->close();
907 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));
923 $relativepathstring = $_SERVER[
"PHP_SELF"];
925 if (constant(
'DOL_URL_ROOT')) {
926 $relativepathstring = preg_replace(
'/^' . preg_quote(constant(
'DOL_URL_ROOT'),
'/') .
'/',
'', $relativepathstring);
928 $relativepathstring = ltrim($relativepathstring,
'/');
929 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
933 if (!empty($_GET[
'restore_lastsearch_values'])) {
934 if (!empty($_SESSION[
'lastsearch_values_' . $relativepathstring])) {
935 $tmp = json_decode($_SESSION[
'lastsearch_values_' . $relativepathstring],
true);
936 if (is_array($tmp)) {
937 foreach ($tmp as $key => $val) {
938 if ($key == $paramname) {
946 if ($paramname ==
'contextpage' && !empty($_SESSION[
'lastsearch_contextpage_' . $relativepathstring])) {
948 } elseif ($paramname ==
'limit' && !empty($_SESSION[
'lastsearch_limit_' . $relativepathstring])) {
950 } elseif ($paramname ==
'page' && !empty($_SESSION[
'lastsearch_page_' . $relativepathstring])) {
952 } elseif ($paramname ==
'mode' && !empty($_SESSION[
'lastsearch_mode_' . $relativepathstring])) {
956 $isset = (isset($_POST[$paramname]) || isset($_GET[$paramname]));
973 if (empty($method)) {
974 $val = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] :
'');
975 } elseif ($method == 1) {
976 $val = isset($_GET[$paramname]) ? $_GET[$paramname] :
'';
977 } elseif ($method == 2) {
978 $val = isset($_POST[$paramname]) ? $_POST[$paramname] :
'';
979 } elseif ($method == 3) {
980 $val = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] :
'');
982 $val =
'BadFirstParameterForGETPOST';
985 return is_array($val);
999function GETPOSTINT($paramname, $method = 0, $nodefault = 0)
1001 return (
int)
GETPOST($paramname,
'int', $method,
null,
null, 0, $nodefault);
1017function GETPOSTFLOAT($paramname, $rounding =
'', $option = 2)
1038function GETPOSTDATE($prefix, $hourTime =
'', $gm =
'auto', $saverestore =
'')
1041 if ($hourTime ===
'getpost' || $hourTime ===
'getpostend') {
1045 } elseif (preg_match(
'/^(\d\d):(\d\d):(\d\d)$/', $hourTime, $m)) {
1046 $hour = intval($m[1]);
1047 $minute = intval($m[2]);
1048 $second = intval($m[3]);
1049 } elseif ($hourTime ===
'end') {
1054 $hour = $minute = $second = 0;
1062 && isset($_SESSION[
'DOLDATE_' . $saverestore .
'_day'])
1063 && isset($_SESSION[
'DOLDATE_' . $saverestore .
'_month'])
1064 && isset($_SESSION[
'DOLDATE_' . $saverestore .
'_year'])
1066 $day = $_SESSION[
'DOLDATE_' . $saverestore .
'_day'];
1067 $month = $_SESSION[
'DOLDATE_' . $saverestore .
'_month'];
1068 $year = $_SESSION[
'DOLDATE_' . $saverestore .
'_year'];
1076 $hour = (int) min($hour, 23);
1077 $minute = (int) min($minute, 59);
1078 $second = (int) min($second, 59);
1081 $_SESSION[
'DOLDATE_' . $saverestore .
'_day'] = $day;
1082 $_SESSION[
'DOLDATE_' . $saverestore .
'_month'] = $month;
1083 $_SESSION[
'DOLDATE_' . $saverestore .
'_year'] = $year;
1087 return dol_mktime($hour, $minute, $second, $month, $day, $year, $gm);
1131function GETPOST($paramname, $check =
'alphanohtml', $method = 0, $filter =
null, $options =
null, $noreplace = 0, $nodefault = 0)
1133 global $langs, $user;
1135 if (empty($paramname)) {
1136 return 'BadFirstParameterForGETPOST';
1138 if (empty($check)) {
1139 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);
1143 if (in_array($paramname, array(
'sortfield',
'sortorder'))) {
1144 $check =
'aZ09comma';
1147 if (empty($method)) {
1148 $out = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] :
'');
1149 } elseif ($method == 1) {
1150 $out = isset($_GET[$paramname]) ? $_GET[$paramname] :
'';
1151 } elseif ($method == 2) {
1152 $out = isset($_POST[$paramname]) ? $_POST[$paramname] :
'';
1153 } elseif ($method == 3) {
1154 $out = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] :
'');
1156 return 'BadThirdParameterForGETPOST';
1159 $relativepathstring =
'';
1161 if (empty($method) || $method == 3 || $method == 4) {
1162 $relativepathstring = (empty($_SERVER[
"PHP_SELF"]) ?
'' : $_SERVER[
"PHP_SELF"]);
1164 if (constant(
'DOL_URL_ROOT')) {
1165 $relativepathstring = preg_replace(
'/^' . preg_quote(constant(
'DOL_URL_ROOT'),
'/') .
'/',
'', $relativepathstring);
1167 $relativepathstring = ltrim($relativepathstring,
'/');
1168 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
1172 if (!empty($_GET[
'restore_lastsearch_values'])) {
1173 if (!empty($_SESSION[
'lastsearch_values_' . $relativepathstring])) {
1174 $tmp = json_decode($_SESSION[
'lastsearch_values_' . $relativepathstring],
true);
1175 if (is_array($tmp)) {
1176 foreach ($tmp as $key => $val) {
1177 if ($key == $paramname) {
1185 if ($paramname ==
'contextpage' && !empty($_SESSION[
'lastsearch_contextpage_' . $relativepathstring])) {
1186 $out = $_SESSION[
'lastsearch_contextpage_' . $relativepathstring];
1187 } elseif ($paramname ==
'limit' && !empty($_SESSION[
'lastsearch_limit_' . $relativepathstring])) {
1188 $out = $_SESSION[
'lastsearch_limit_' . $relativepathstring];
1189 } elseif ($paramname ==
'page' && !empty($_SESSION[
'lastsearch_page_' . $relativepathstring])) {
1190 $out = $_SESSION[
'lastsearch_page_' . $relativepathstring];
1191 } elseif ($paramname ==
'mode' && !empty($_SESSION[
'lastsearch_mode_' . $relativepathstring])) {
1192 $out = $_SESSION[
'lastsearch_mode_' . $relativepathstring];
1194 } elseif (!isset($_GET[
'sortfield'])) {
1197 if (!empty($_GET[
'action']) && $_GET[
'action'] ==
'create' && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
1200 '@phan-var-force CommonObject $object';
1201 if (is_object(
$object) && isset(
$object->fields[$paramname][
'default'])) {
1203 $out =
$object->fields[$paramname][
'default'];
1207 if (!empty($_GET[
'action']) && (preg_match(
'/^create/', $_GET[
'action']) || preg_match(
'/^presend/', $_GET[
'action'])) && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
1209 if (!empty($user->default_values)) {
1210 if (isset($user->default_values[$relativepathstring][
'createform'])) {
1211 foreach ($user->default_values[$relativepathstring][
'createform'] as $defkey => $defval) {
1213 if ($defkey !=
'_noquery_') {
1214 $tmpqueryarraytohave = explode(
'&', $defkey);
1217 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
1218 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
1230 if (isset($user->default_values[$relativepathstring][
'createform'][$defkey][$paramname])) {
1231 $out = $user->default_values[$relativepathstring][
'createform'][$defkey][$paramname];
1238 } elseif (!empty($paramname) && !isset($_GET[$paramname]) && !isset($_POST[$paramname]) && empty($nodefault)) {
1240 if (!empty($user->default_values)) {
1243 if ($paramname ==
'sortfield' || $paramname ==
'sortorder') {
1245 if (isset($user->default_values[$relativepathstring][
'sortorder'])) {
1247 foreach ($user->default_values[$relativepathstring][
'sortorder'] as $defkey => $defval) {
1249 if ($defkey !=
'_noquery_') {
1250 $tmpqueryarraytohave = explode(
'&', $defkey);
1253 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
1254 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
1266 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
1267 foreach ($user->default_values[$relativepathstring][
'sortorder'][$defkey] as $key => $val) {
1271 if ($paramname ==
'sortfield') {
1274 if ($paramname ==
'sortorder') {
1282 } elseif (isset($user->default_values[$relativepathstring][
'filters'])) {
1283 foreach ($user->default_values[$relativepathstring][
'filters'] as $defkey => $defval) {
1284 if (!empty($_GET[
'disabledefaultvalues'])) {
1288 if ($defkey !=
'_noquery_') {
1289 $tmpqueryarraytohave = explode(
'&', $defkey);
1292 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
1293 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
1304 if ($qualified && isset($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname])) {
1306 if (isset($_POST[
'search_all']) || isset($_GET[
'search_all'])) {
1309 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
1310 $out =
dol_string_nospecial($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname],
'', $forbidden_chars_to_replace);
1313 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
1314 $out =
dol_string_nospecial($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname],
'', $forbidden_chars_to_replace);
1329 '@phan-var-force string $paramname';
1330 if (!is_array($out) && empty($_POST[$paramname]) && empty($noreplace)) {
1331 if (preg_match(
'/__([A-Z0-9]+(?:_[A-Z0-9]+){0,3})__/i', $out)) {
1332 $substitutionarray = getCommonSubstitutionArray($langs, 0,
null, $user, array(
'mycompany',
'date',
'system',
'user'));
1340 if (preg_match(
'/^array/', $check)) {
1341 $tmpcheck =
'alphanohtml';
1342 if ($out ===
null || $out ===
'') {
1344 } elseif (!is_array($out)) {
1345 $out = explode(
',', $out);
1347 $tmparray = explode(
':', $check);
1348 if (!empty($tmparray[1])) {
1349 $tmpcheck = $tmparray[1];
1352 foreach ($out as $outkey => $outval) {
1353 $out[$outkey] =
sanitizeVal($outval, $tmpcheck, $filter, $options);
1358 if (strpos($paramname,
'search_') === 0) {
1359 $out = preg_replace(
'/([<>])([-+]?\d)/',
'\1 \2', $out);
1363 $out =
sanitizeVal($out, $check, $filter, $options);
1371 if (preg_match(
'/^backto/i', $paramname) || preg_match(
'/^urlfrom/i', $paramname)) {
1372 $out = str_replace(
'\\',
'/', $out);
1373 $out = str_replace(array(
':',
';',
'@',
"\t",
' '),
'', $out);
1375 $oldstringtoclean = $out;
1376 $out = str_ireplace(array(
'javascript',
'vbscript',
'&colon',
'&#'),
'', $out);
1377 $out = preg_replace(array(
'/^[^\?]*%/'),
'', $out);
1378 $out = preg_replace(array(
'/^[a-z]*\/\s*\/+/i'),
'', $out);
1379 }
while ($oldstringtoclean != $out);
1384 if (empty($method) || $method == 3 || $method == 4) {
1385 if (preg_match(
'/^search_/', $paramname) || in_array($paramname, array(
'sortorder',
'sortfield'))) {
1392 if ($out !=
'' && isset($user)) {
1393 $user->lastsearch_values_tmp[$relativepathstring][$paramname] = $out;
1398 if ($paramname ==
'hashp' && $out ==
'shared') {
1414function sanitizeVal($out =
'', $check =
'alphanohtml', $filter =
null, $options =
null)
1418 if ($out ===
null) {
1426 if (!is_numeric($out)) {
1431 if (is_array($out)) {
1432 $out = implode(
',', $out);
1434 if (preg_match(
'/[^0-9,-]+/i', $out)) {
1439 dol_syslog(
"Use of parameter value 'san_alpha' in GETPOST is deprecated. Use 'alphanohtml', 'aZ09comma', ...", LOG_WARNING);
1440 $out = filter_var($out, FILTER_SANITIZE_STRING);
1443 $out = filter_var($out, FILTER_SANITIZE_EMAIL);
1447 $out = preg_replace(
'/[^:\/\[\]a-z0-9@\$\'\*\~\.\-_,;\?\!=%&+#]+/i',
'', $out);
1451 if (!is_array($out)) {
1453 if (preg_match(
'/[^a-z]+/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)) {
1475 if (!is_array($out)) {
1477 if (preg_match(
'/[^a-z0-9_\-\.,]+/i', $out)) {
1484 if (!is_array($out)) {
1487 $oldstringtoclean = $out;
1491 $out = preg_replace(
'/\\\([0-9xu])/',
'/\1', $out);
1498 $out = str_ireplace(array(
'../',
'..\\',
'&',
'&',
'&',
'"',
'"',
'"',
'"',
'"',
'/',
'/',
'/',
'\',
'\',
'\'),
'', $out);
1499 }
while ($oldstringtoclean != $out);
1503 case 'alphawithlgt':
1504 if (!is_array($out)) {
1507 $oldstringtoclean = $out;
1511 $out = preg_replace(
'/\\\([0-9xu])/',
'/\1', $out);
1518 $out = str_ireplace(array(
'../',
'..\\',
'&',
'&',
'&',
'"',
'"',
'"',
'"',
'"',
'/',
'/',
'/',
'\',
'\',
'\'),
'', $out);
1519 }
while ($oldstringtoclean != $out);
1525 case 'restricthtmlnolink':
1526 case 'restricthtml':
1527 case 'restricthtmlallowclass':
1528 case 'restricthtmlallowiframe':
1529 case 'restricthtmlallowlinkscript':
1530 case 'restricthtmlallowunvalid':
1535 if (empty($filter)) {
1536 return 'BadParameterForGETPOST - Param 3 of sanitizeVal()';
1538 if (is_null($options)) {
1541 $out = filter_var($out, $filter, $options);
1545 dol_syslog(
"Error, you call sanitizeVal() with a bad value for the check type. Data will be sanitized with alphanohtml.", LOG_ERR);
1546 $out =
GETPOST($out,
'alphanohtml');
1561function dolSetCookie(
string $cookiename,
string $cookievalue,
int $expire = -1)
1563 include_once DOL_DOCUMENT_ROOT.
'/blockedlog/lib/securitycore.lib.php';
1565 global $dolibarr_main_force_https;
1567 if ($expire == -1) {
1568 $expire = (time() + (86400 * 354));
1571 if (PHP_VERSION_ID < 70300) {
1572 setcookie($cookiename, empty($cookievalue) ?
'' : $cookievalue, empty($cookievalue) ? 0 : $expire,
'/',
'', !(empty($dolibarr_main_force_https) &&
isHTTPS() === false), true);
1575 $cookieparams = array(
1576 'expires' => empty($cookievalue) ? 0 : $expire,
1579 'secure' => !(empty($dolibarr_main_force_https) &&
isHTTPS() === false),
1583 setcookie($cookiename, empty($cookievalue) ?
'' : $cookievalue, $cookieparams);
1585 if (empty($cookievalue)) {
1586 unset($_COOKIE[$cookiename]);
1590if (!function_exists(
'dol_getprefix')) {
1601 function dol_getprefix($mode =
'')
1604 if ($mode ==
'email') {
1610 } elseif (isset($_SERVER[
"SERVER_NAME"])) {
1611 return $_SERVER[
"SERVER_NAME"];
1616 if (!empty(
$conf->file->instance_unique_id)) {
1617 return sha1(
'dolibarr' .
$conf->file->instance_unique_id);
1621 return sha1(DOL_DOCUMENT_ROOT . DOL_URL_ROOT);
1625 global $dolibarr_main_instance_unique_id, $dolibarr_main_cookie_cryptkey;
1626 $tmp_instance_unique_id = empty($dolibarr_main_instance_unique_id) ? (empty($dolibarr_main_cookie_cryptkey) ?
'' : $dolibarr_main_cookie_cryptkey) : $dolibarr_main_instance_unique_id;
1629 if (!empty($tmp_instance_unique_id)) {
1630 return sha1(
'dolibarr' . $tmp_instance_unique_id);
1634 if (isset($_SERVER[
"SERVER_NAME"]) && isset($_SERVER[
"DOCUMENT_ROOT"])) {
1635 return sha1($_SERVER[
"SERVER_NAME"] . $_SERVER[
"DOCUMENT_ROOT"] . DOL_DOCUMENT_ROOT . DOL_URL_ROOT);
1637 return sha1(DOL_DOCUMENT_ROOT . DOL_URL_ROOT);
1656 if (strpos($relpath,
'..') !==
false) {
1658 dol_syslog(
'functions::dol_include_once Tried to load a file with a path including a forbidden sequence ".." : ' . $relpath, LOG_WARNING);
1661 if (!preg_match(
'/\.php$/', $relpath)) {
1663 dol_syslog(
'functions::dol_include_once Tried to load a file that is not a PHP file : ' . $relpath, LOG_WARNING);
1669 if (!file_exists($fullpath)) {
1670 dol_syslog(
'functions::dol_include_once Tried to load unexisting file: ' . $relpath, LOG_WARNING);
1673 if (!empty($classname) && !class_exists($classname)) {
1674 return include $fullpath;
1676 return include_once $fullpath;
1694function dol_buildpath($path, $type = 0, $returnemptyifnotfound = 0)
1698 $path = preg_replace(
'/^\//',
'', $path);
1701 $res = DOL_DOCUMENT_ROOT .
'/' . $path;
1702 if (is_array(
$conf->file->dol_document_root)) {
1703 foreach (
$conf->file->dol_document_root as $key => $dirroot) {
1704 if ($key ==
'main') {
1708 if (@file_exists($dirroot .
'/' . $path)) {
1709 if ($key !=
'main' && preg_match(
'/^core\//', $path)) {
1712 $res = $dirroot .
'/' . $path;
1717 if ($returnemptyifnotfound) {
1719 if ($returnemptyifnotfound == 1 || !file_exists($res)) {
1731 $res = DOL_URL_ROOT .
'/' . $path;
1734 $res = DOL_MAIN_URL_ROOT .
'/' . $path;
1737 $res = DOL_URL_ROOT .
'/' . $path;
1740 foreach (
$conf->file->dol_document_root as $key => $dirroot) {
1741 if ($key ==
'main') {
1746 $urlwithouturlroot = preg_replace(
'/' . preg_quote(DOL_URL_ROOT,
'/') .
'$/i',
'', trim(
$conf->file->dol_main_url_root));
1747 $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT;
1750 $res = (preg_match(
'/^http/i',
$conf->file->dol_url_root[$key]) ?
'' : $urlwithroot) .
'/' . $path;
1755 preg_match(
'/^([^\?]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i', $path, $regs);
1756 if (!empty($regs[1])) {
1759 if (@file_exists($dirroot .
'/' . $regs[1])) {
1761 $res = (preg_match(
'/^http/i',
$conf->file->dol_url_root[$key]) ?
'' : DOL_URL_ROOT) .
$conf->file->dol_url_root[$key] .
'/' . $path;
1762 } elseif ($type == 2) {
1763 $res = (preg_match(
'/^http/i',
$conf->file->dol_url_root[$key]) ?
'' : DOL_MAIN_URL_ROOT) .
$conf->file->dol_url_root[$key] .
'/' . $path;
1764 } elseif ($type == 3) {
1768 $urlwithouturlroot = preg_replace(
'/' . preg_quote(DOL_URL_ROOT,
'/') .
'$/i',
'', trim(
$conf->file->dol_main_url_root));
1769 $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT;
1772 $res = (preg_match(
'/^http/i',
$conf->file->dol_url_root[$key]) ?
'' : $urlwithroot) .
$conf->file->dol_url_root[$key] .
'/' . $path;
1800 if (empty($theme)) {
1801 $theme =
$conf->theme;
1803 $file =
'/theme/'.$theme.
'/'.preg_replace(
'/^\//',
'', $file);
1807 if (empty(
$conf->modules_parts[
'theme'])) {
1808 return DOL_DOCUMENT_ROOT.$file;
1813 if (file_exists(DOL_DOCUMENT_ROOT.$file)) {
1814 return DOL_DOCUMENT_ROOT.$file;
1816 foreach (
$conf->modules_parts[
'theme'] as $reldir) {
1835function dolBuildUrl($url, $params = [], $addtoken =
false, $anchor =
'')
1837 global $db, $hookmanager;
1839 if (!is_object($hookmanager)) {
1840 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
1843 if ((!isset($params[
'mainmenu']) || empty($params[
'mainmenu'])) &&
GETPOSTISSET(
'mainmenu')) {
1844 $params = array_merge($params, [
'mainmenu' => (
GETPOST(
'mainmenu',
'restricthtml'))]);
1846 if ((!isset($params[
'leftmenu'])) &&
GETPOSTISSET(
'leftmenu')) {
1847 $params = array_merge($params, [
'leftmenu' => (
GETPOST(
'leftmenu',
'restricthtml'))]);
1851 'params' => &$params,
1852 'addtoken' => &$addtoken,
1854 $hookmanager->executeHooks(
'buildurl', $parameters);
1856 $params = array_merge($params, [
'token' =>
newToken()]);
1859 $url .=
'?' . http_build_query($params);
1862 $url .=
'#' . preg_replace(
'/[^a-z]/i',
'', $anchor);
1881 if (empty($properties)) {
1882 return get_object_vars($obj);
1885 $existingProperties = [];
1886 $realProperties = get_object_vars($obj);
1889 foreach ($properties as $property) {
1890 if (array_key_exists($property, $realProperties)) {
1892 $existingProperties[$property] = $obj->{$property};
1893 } elseif (property_exists($obj, $property)) {
1895 $existingProperties[$property] = $obj->{$property};
1899 return $existingProperties;
1920function dol_clone($srcobject, $native = 2)
1924 dol_syslog(
"Warning, call to dol_clone() with the deprecated parameter native=0, use 2 instead", LOG_WARNING);
1927 if (isset($srcobject->db) && isset($srcobject->db->db) && is_object($srcobject->db->db) && get_class($srcobject->db->db) ==
'PgSql\Connection') {
1928 $tmpsavdb = $srcobject->db;
1929 unset($srcobject->db);
1932 $myclone = unserialize(serialize($srcobject));
1934 if (!empty($tmpsavdb)) {
1935 $srcobject->db = $tmpsavdb;
1937 } elseif ($native == 2) {
1940 $tmparray = get_object_vars($srcobject);
1942 if (is_array($tmparray)) {
1943 foreach ($tmparray as $propertykey => $propertyval) {
1944 if (is_scalar($propertyval) || is_array($propertyval)) {
1945 $myclone->$propertykey = $propertyval;
1950 $myclone = clone $srcobject;
1967 if (is_object($srcobject)) {
1968 $srcobject = get_object_vars($srcobject);
1971 if (is_array($srcobject)) {
1973 foreach ($srcobject as $key => $value) {
1974 if (in_array($key, array(
'db',
'fields',
'error',
'errorhidden',
'errors',
'oldcopy',
'linkedObjects',
'linked_objects'))) {
1995function dol_size($size, $type =
'')
1998 if (empty(
$conf->dol_optimize_smallscreen)) {
2001 if ($type ==
'width' && $size > 250) {
2022function dol_sanitizeFileName($str, $newstr =
'_', $unaccent = 1, $includequotes = 0, $allowdash = 0)
2024 $str = (string) $str;
2030 $filesystem_forbidden_chars = array(
'<',
'>',
'/',
'\\',
'?',
'*',
'|',
'"',
':',
'°',
'$',
';',
'`');
2031 if ($includequotes) {
2032 $filesystem_forbidden_chars[] =
"'";
2035 $tmp = preg_replace(
'/\-\-+/',
'_', $tmp);
2036 if (empty($allowdash)) {
2037 $tmp = preg_replace(
'/\s+\-([^\s])/',
' _$1', $tmp);
2038 $tmp = preg_replace(
'/\s+\-$/',
'', $tmp);
2040 $tmp = str_replace(
'..',
'', $tmp);
2041 $tmp = str_replace(
'~', $newstr, $tmp);
2042 $tmp = preg_replace(
'/\s{2,}/',
' ', $tmp);
2069 $filesystem_forbidden_chars = array(
'<',
'>',
'?',
'*',
'|',
'"',
'°',
'$',
';',
'`');
2076 $tmp = preg_replace(
'/\-\-+/', $newstr, $tmp);
2077 if (empty($allowdash)) {
2078 $tmp = preg_replace(
'/\s+\-([^\s])/',
' '.$newstr.
'$1', $tmp);
2079 $tmp = preg_replace(
'/\s+\-$/',
'', $tmp);
2081 $tmp = str_replace(
'..', $newstr, $tmp);
2082 $tmp = str_replace(
'~', $newstr, $tmp);
2083 $tmp = preg_replace(
'/\s{2,}/',
' ', $tmp);
2100 $stringtoclean = preg_replace(
'/[\x00-\x1F\x7F]/u',
'', $stringtoclean);
2102 $stringtoclean = preg_replace(
'/<!--[^>]*-->/',
'', $stringtoclean);
2104 $stringtoclean = str_replace(
'\\',
'/', $stringtoclean);
2108 $stringtoclean = str_replace(array(
':',
';',
'@'),
'', $stringtoclean);
2112 $oldstringtoclean = $stringtoclean;
2115 $stringtoclean = str_ireplace(array(
'javascript',
'vbscript',
'&colon',
'&#'),
'', $stringtoclean);
2116 }
while ($oldstringtoclean != $stringtoclean);
2120 $stringtoclean = preg_replace(array(
'/^[a-z]*\/\/+/i'),
'', $stringtoclean);
2124 $stringtoclean = str_replace(array(
'<',
'>'), array(
'%3C',
'%3E'), $stringtoclean);
2126 return $stringtoclean;
2138 $oldstringtoclean = $stringtoclean;
2139 $stringtoclean = str_ireplace(array(
'"',
':',
'[',
']',
"\n",
"\r",
'\\',
'\/'),
'', $stringtoclean);
2140 }
while ($oldstringtoclean != $stringtoclean);
2142 return $stringtoclean;
2155 return preg_replace(
'/[^\w]+/',
'', $str);
2169 if (is_null($str)) {
2174 if (extension_loaded(
'intl') &&
getDolGlobalString(
'MAIN_UNACCENT_USE_TRANSLITERATOR')) {
2175 $transliterator = Transliterator::createFromRules(
':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: NFC;', Transliterator::FORWARD);
2176 return $transliterator->transliterate($str);
2179 $string = rawurlencode($str);
2180 $replacements = array(
2181 '%C3%80' =>
'A',
'%C3%81' =>
'A',
'%C3%82' =>
'A',
'%C3%83' =>
'A',
'%C3%84' =>
'A',
'%C3%85' =>
'A',
2183 '%C3%88' =>
'E',
'%C3%89' =>
'E',
'%C3%8A' =>
'E',
'%C3%8B' =>
'E',
2184 '%C3%8C' =>
'I',
'%C3%8D' =>
'I',
'%C3%8E' =>
'I',
'%C3%8F' =>
'I',
2186 '%C3%92' =>
'O',
'%C3%93' =>
'O',
'%C3%94' =>
'O',
'%C3%95' =>
'O',
'%C3%96' =>
'O',
'%C5%90' =>
'O',
2188 '%C3%99' =>
'U',
'%C3%9A' =>
'U',
'%C3%9B' =>
'U',
'%C3%9C' =>
'U',
'%C5%B0' =>
'U',
2189 '%C3%9D' =>
'Y',
'%C5%B8' =>
'y',
2190 '%C3%A0' =>
'a',
'%C3%A1' =>
'a',
'%C3%A2' =>
'a',
'%C3%A3' =>
'a',
'%C3%A4' =>
'a',
'%C3%A5' =>
'a',
2192 '%C3%A8' =>
'e',
'%C3%A9' =>
'e',
'%C3%AA' =>
'e',
'%C3%AB' =>
'e',
2193 '%C3%AC' =>
'i',
'%C3%AD' =>
'i',
'%C3%AE' =>
'i',
'%C3%AF' =>
'i',
2195 '%C3%B2' =>
'o',
'%C3%B3' =>
'o',
'%C3%B4' =>
'o',
'%C3%B5' =>
'o',
'%C3%B6' =>
'o',
'%C5%91' =>
'o',
2197 '%C3%B9' =>
'u',
'%C3%BA' =>
'u',
'%C3%BB' =>
'u',
'%C3%BC' =>
'u',
'%C5%B1' =>
'u',
2198 '%C3%BD' =>
'y',
'%C3%BF' =>
'y',
2219 $string = strtr($string, $replacements);
2220 return rawurldecode($string);
2225 "\xC0\xC1\xC2\xC3\xC4\xC5\xC7
2226 \xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1
2227 \xD2\xD3\xD4\xD5\xD8\xD9\xDA\xDB\xDD
2228 \xE0\xE1\xE2\xE3\xE4\xE5\xE7\xE8\xE9\xEA\xEB
2229 \xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF8
2230 \xF9\xFA\xFB\xFC\xFD\xFF",
2238 $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"));
2256function dol_string_nospecial($str, $newstr =
'_', $badcharstoreplace =
'', $badcharstoremove =
'', $keepspaces = 0)
2258 $forbidden_chars_to_replace = array(
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
",",
";",
"=",
'°',
'$',
';');
2259 if (empty($keepspaces)) {
2260 $forbidden_chars_to_replace[] =
" ";
2262 $forbidden_chars_to_remove = array();
2265 if (is_array($badcharstoreplace)) {
2266 $forbidden_chars_to_replace = $badcharstoreplace;
2268 if (is_array($badcharstoremove)) {
2269 $forbidden_chars_to_remove = $badcharstoremove;
2273 return str_replace($forbidden_chars_to_replace, $newstr, str_replace($forbidden_chars_to_remove,
"", $str));
2292 if ($removetabcrlf) {
2293 return preg_replace(
'/[\x00-\x1F\x7F]/u',
'', $str);
2295 return preg_replace(
'/[\x00-\x08\x11-\x12\x14-\x1F\x7F]/u',
'', $str);
2310 if (function_exists(
'iconv')) {
2311 $slug = iconv(
'UTF-8',
'ASCII//TRANSLIT//IGNORE', $slug);
2315 $slug = strtolower($slug);
2318 $slug = preg_replace(
'/[^a-z0-9]+/',
'-', $slug);
2321 $slug = trim($slug,
'-');
2334function dol_escape_js($stringtoescape, $mode = 0, $noescapebackslashn = 0)
2336 if (is_null($stringtoescape)) {
2341 $substitjs = array(
"'" =>
"\\'",
"\r" =>
'\\r');
2343 if (empty($noescapebackslashn)) {
2344 $substitjs[
"\n"] =
'\\n';
2345 $substitjs[
'\\'] =
'\\\\';
2348 $substitjs[
"'"] =
"\\'";
2349 $substitjs[
'"'] =
"\\'";
2350 } elseif ($mode == 1) {
2351 $substitjs[
"'"] =
"\\'";
2352 } elseif ($mode == 2) {
2353 $substitjs[
'"'] =
'\\"';
2354 } elseif ($mode == 3) {
2355 $substitjs[
"'"] =
"\\'";
2356 $substitjs[
'"'] =
"\\\"";
2359 return preg_replace(
'/<\/(script)/i',
'<\\/$1', strtr((
string) $stringtoescape, $substitjs));
2373 return rawurlencode($stringtoescape);
2384 return str_replace(
'"',
'\"', $stringtoescape);
2396 if (is_null($stringtoescape)) {
2400 if ($stringforquotes == 2) {
2401 return str_replace(
'"',
"'", $stringtoescape);
2402 } elseif ($stringforquotes == 1) {
2408 $stringtoescape = str_replace(
'\\',
'', $stringtoescape);
2409 return str_replace(
"'",
"\'", str_replace(
'"',
"'", $stringtoescape));
2412 return 'Bad parameter for stringforquotes in dol_escape_php';
2423 return preg_replace(
'/[^a-z0-9_]/i',
'', $stringtoescape);
2434 $stringtoescape = (string) preg_replace(
'/[\x00-\x08\x0B\x0C\x0E-\x1F]/',
'', (
string) $stringtoescape);
2436 return htmlspecialchars($stringtoescape, ENT_XML1 | ENT_QUOTES,
'UTF-8');
2449 if (function_exists(
'mb_strtolower')) {
2450 return mb_strtolower($string, $encoding);
2452 return strtolower($string);
2466 if (function_exists(
'mb_strtoupper')) {
2467 return mb_strtoupper($string, $encoding);
2469 return strtoupper($string);
2483 if (function_exists(
'mb_substr')) {
2484 return mb_strtoupper(mb_substr($string, 0, 1, $encoding), $encoding) . mb_substr($string, 1,
null, $encoding);
2486 return ucfirst($string);
2500 if (function_exists(
'mb_convert_case')) {
2501 return mb_convert_case($string, MB_CASE_TITLE, $encoding);
2503 return ucwords($string);
2515 $backtrace = debug_backtrace();
2517 if (count($backtrace) >= 1) {
2519 if (count($backtrace) == 1) {
2522 $trace = $backtrace[$pos];
2523 if (isset($trace[
'file'], $trace[
'line'])) {
2524 $msg =
" From {$trace['file']}:{$trace['line']}.";
2552function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename =
'', $restricttologhandler =
'', $logcontext =
null)
2554 global
$conf, $user, $debugbar;
2562 if (defined(
'USEEXTERNALSERVER') && !defined(
'USEDOLIBARRSERVER') && !defined(
'USEDOLIBARREDITOR')) {
2563 global $website, $websitekey;
2564 if (is_object($website) && !empty($website->ref)) {
2565 $suffixinfilename .=
'_website_' . $website->ref;
2566 } elseif (!empty($websitekey)) {
2567 $suffixinfilename .=
'_website_' . $websitekey;
2572 if (defined(
'USESUFFIXINLOG')) {
2573 $suffixinfilename .= constant(
'USESUFFIXINLOG');
2577 foreach (
$conf->loghandlers as $loghandlerinstance) {
2578 $loghandlerinstance->setIdent($ident);
2582 if (!empty($message)) {
2585 $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');
2587 if (!array_key_exists($level, $logLevels)) {
2588 dol_syslog(
'Error Bad Log Level ' . $level, LOG_ERR);
2596 $message = preg_replace(
'/password=\'[^\']*\'/',
'password=\'hidden\'', $message);
2600 if ((!empty($_REQUEST[
'logtohtml']) &&
getDolGlobalString(
'MAIN_ENABLE_LOG_TO_HTML'))
2601 || (is_object($user) && $user->hasRight(
'debugbar',
'read') && is_object($debugbar))
2603 $ospid = sprintf(
"%7s",
dol_trunc((
string) getmypid(), 7,
'right',
'UTF-8', 1));
2604 $osuser =
" " . sprintf(
"%6s",
dol_trunc(function_exists(
'posix_getuid') ? posix_getuid() :
'', 6,
'right',
'UTF-8', 1));
2606 $conf->logbuffer[] =
dol_print_date(
dol_now(),
"%Y-%m-%d %H:%M:%S") .
" " . sprintf(
"%-7s", $logLevels[$level]) .
" " . $ospid .
" " . $osuser .
" " . $message;
2612 print
"\n\n<!-- Log start\n";
2614 print
"Log end -->\n";
2618 'message' => $message,
2619 'script' => (isset($_SERVER[
'PHP_SELF']) ? basename($_SERVER[
'PHP_SELF'],
'.php') :
''),
2621 'user' => ((is_object($user) && $user->id) ? $user->login :
''),
2623 'osuser' => function_exists(
'posix_getuid') ? (string) posix_getuid() :
'',
2624 'ospid' => (string) getmypid()
2629 if (!empty($remoteip)) {
2630 $data[
'ip'] = $remoteip;
2634 if (!empty($_SERVER[
'HTTP_X_FORWARDED_FOR'])) {
2635 $tmpips = explode(
',', $_SERVER[
'HTTP_X_FORWARDED_FOR']);
2639 foreach ($tmpips as $tmpip) {
2640 $tmpip = trim($tmpip);
2641 if (strtolower($tmpip) == strtolower($remoteip)) {
2644 if (empty($data[
'ip'])) {
2645 $data[
'ip'] = $tmpip;
2648 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $tmpip;
2651 if (!$foundremoteip) {
2653 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $remoteip;
2655 $data[
'ip'] .= (($j > 0) ?
']' :
'');
2656 } elseif (!empty($_SERVER[
'HTTP_CLIENT_IP'])) {
2657 $tmpips = explode(
',', $_SERVER[
'HTTP_CLIENT_IP']);
2661 foreach ($tmpips as $tmpip) {
2662 $tmpip = trim($tmpip);
2663 if (strtolower($tmpip) == strtolower($remoteip)) {
2666 if (empty($data[
'ip'])) {
2667 $data[
'ip'] = $tmpip;
2670 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $tmpip;
2673 if (!$foundremoteip) {
2675 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $remoteip;
2677 $data[
'ip'] .= (($j > 0) ?
']' :
'');
2679 } elseif (!empty($_SERVER[
'SERVER_ADDR'])) {
2681 $data[
'ip'] = (string) $_SERVER[
'SERVER_ADDR'];
2682 } elseif (!empty($_SERVER[
'COMPUTERNAME'])) {
2684 $data[
'ip'] = (string) $_SERVER[
'COMPUTERNAME'];
2686 $data[
'ip'] =
'???';
2689 if (!empty($_SERVER[
'USERNAME'])) {
2691 $data[
'osuser'] = (string) $_SERVER[
'USERNAME'];
2692 } elseif (!empty($_SERVER[
'LOGNAME'])) {
2694 $data[
'osuser'] = (string) $_SERVER[
'LOGNAME'];
2698 foreach (
$conf->loghandlers as $loghandlerinstance) {
2699 if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler) {
2702 $loghandlerinstance->export($data, $suffixinfilename);
2708 foreach (
$conf->loghandlers as $loghandlerinstance) {
2709 $loghandlerinstance->setIdent($ident);
2730 global $langs, $hookmanager;
2733 $countriesusingstate = array(
'AU',
'CA',
'US',
'IN',
'GB',
'ES',
'UK',
'TR',
'CN');
2738 $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)));
2741 if (isset(
$object->country_code) && in_array(
$object->country_code, array(
'AU',
'CA',
'US',
'CN')) ||
getDolGlobalString(
'MAIN_FORCE_STATE_INTO_ADDRESS')) {
2743 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
2744 $ret .= (($ret && $town) ? $sep :
'') . $town;
2747 $ret .= ($ret ? ($town ?
", " : $sep) :
'') .
$object->state;
2750 $ret .= ($ret ? (($town ||
$object->state) ?
", " : $sep) :
'') .
$object->zip;
2752 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'GB',
'UK'))) {
2754 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
2755 $ret .= ($ret ? $sep :
'') . $town;
2757 $ret .= ($ret ?
", " :
'') .
$object->state;
2760 $ret .= ($ret ? $sep :
'') .
$object->zip;
2762 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'ES',
'TR'))) {
2764 $ret .= ($ret ? $sep :
'') .
$object->zip;
2765 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
2766 $ret .= ($town ? ((
$object->zip ?
' ' :
'') . $town) :
'');
2768 $ret .= $sep .
$object->state;
2770 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'JP'))) {
2773 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
2775 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'IT'))) {
2777 $ret .= ($ret ? $sep :
'') .
$object->zip;
2778 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
2779 $ret .= ($town ? ((
$object->zip ?
' ' :
'') . $town) :
'');
2780 $ret .= (empty(
$object->state_code) ?
'' : (
' ' .
$object->state_code));
2783 $town = (($extralangcode && !empty(
$object->array_languages[
'address'][$extralangcode])) ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
2784 $ret .= !empty(
$object->zip) ? (($ret ? $sep :
'') .
$object->zip) :
'';
2785 $ret .= ($town ? ((
$object->zip ?
' ' : ($ret ? $sep :
'')) . $town) :
'');
2786 if (!empty(
$object->state) && in_array(
$object->country_code, $countriesusingstate)) {
2787 $ret .= ($ret ?
", " :
'') .
$object->state;
2791 if (!is_object($outputlangs)) {
2792 $outputlangs = $langs;
2795 $langs->load(
"dict");
2796 $ret .= (empty(
$object->country_code) ?
'' : ($ret ? $sep :
'') . $outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv(
"Country" .
$object->country_code)));
2799 $parameters = array(
'withcountry' => $withcountry,
'sep' => $sep,
'outputlangs' => $outputlangs,
'mode' => $mode,
'extralangcode' => $extralangcode);
2800 $reshook = $hookmanager->executeHooks(
'formatAddress', $parameters,
$object);
2804 $ret .= $hookmanager->resPrint;
2821function dol_strftime($fmt, $ts =
false, $is_gmt =
false)
2823 if ((abs($ts) <= 0x7FFFFFFF)) {
2826 return 'Error date outside supported range';
2852function dol_print_date($time, $format =
'', $tzoutput =
'auto', $outputlangs =
null, $encodetooutput =
false, $decorate = 0)
2854 global
$conf, $langs;
2861 if ($tzoutput ===
'auto') {
2862 $tzoutput = (empty(
$conf) ?
'tzserver' : (isset(
$conf->tzuserinputkey) ?
$conf->tzuserinputkey :
'tzserver'));
2867 $offsettz = $offsetdst = 0;
2870 if (is_string($tzoutput)) {
2871 if ($tzoutput ==
'tzserver') {
2873 $offsettzstring = @date_default_timezone_get();
2878 } elseif ($tzoutput ==
'tzuser' || $tzoutput ==
'tzuserrel') {
2881 $offsettzstring = (empty($_SESSION[
'dol_tz_string']) ?
getDolGlobalString(
'MAIN_DOLIBARR_USER_TIMEZONE',
'UTC') : $_SESSION[
'dol_tz_string']);
2883 if (class_exists(
'DateTimeZone')) {
2885 $user_date_tz =
new DateTimeZone($offsettzstring);
2888 dol_syslog(
"DateInvalidTimeZoneException for timezone string '".$offsettzstring.
"'. Falling back to UTC.", LOG_ERR);
2889 $user_date_tz =
new DateTimeZone(
'UTC');
2891 $user_dt =
new DateTime();
2892 $user_dt->setTimezone($user_date_tz);
2893 $user_dt->setTimestamp($tzoutput ==
'tzuser' ?
dol_now() : (int) $time);
2894 $offsettz = $user_dt->getOffset();
2896 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
2897 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
2902 if (!is_object($outputlangs)) {
2903 $outputlangs = $langs;
2906 $format =
'daytextshort';
2911 $reduceformat = (!empty(
$conf->dol_optimize_smallscreen) && in_array($format, array(
'day',
'dayhour',
'dayhoursec'))) ? 1 : 0;
2912 $format = preg_replace(
'/inputnoreduce/',
'', $format);
2913 $formatwithoutreduce = preg_replace(
'/reduceformat/',
'', $format);
2914 if ($formatwithoutreduce != $format) {
2915 $format = $formatwithoutreduce;
2921 if ($format ==
'day') {
2922 $format = ($outputlangs->trans(
"FormatDateShort") !=
"FormatDateShort" ? $outputlangs->trans(
"FormatDateShort") :
$conf->format_date_short);
2923 } elseif ($format ==
'hour') {
2924 $format = ($outputlangs->trans(
"FormatHourShort") !=
"FormatHourShort" ? $outputlangs->trans(
"FormatHourShort") :
$conf->format_hour_short);
2925 } elseif ($format ==
'hoursec') {
2926 $s1 = $outputlangs->trans(
"FormatDateShort");
2927 $s2 = $outputlangs->trans(
"FormatDateHourSecShort");
2928 $s3 = trim(preg_replace(
'/'.preg_quote($s1,
'/').
'/',
'', $s2));
2931 } elseif ($format ==
'hourduration') {
2932 $format = ($outputlangs->trans(
"FormatHourShortDuration") !=
"FormatHourShortDuration" ? $outputlangs->trans(
"FormatHourShortDuration") :
$conf->format_hour_short_duration);
2933 } elseif ($format ==
'daytext') {
2934 $format = ($outputlangs->trans(
"FormatDateText") !=
"FormatDateText" ? $outputlangs->trans(
"FormatDateText") :
$conf->format_date_text);
2935 } elseif ($format ==
'daytextshort') {
2936 $format = ($outputlangs->trans(
"FormatDateTextShort") !=
"FormatDateTextShort" ? $outputlangs->trans(
"FormatDateTextShort") :
$conf->format_date_text_short);
2937 } elseif ($format ==
'dayhour') {
2938 $format = ($outputlangs->trans(
"FormatDateHourShort") !=
"FormatDateHourShort" ? $outputlangs->trans(
"FormatDateHourShort") :
$conf->format_date_hour_short);
2939 } elseif ($format ==
'dayhoursec') {
2940 $format = ($outputlangs->trans(
"FormatDateHourSecShort") !=
"FormatDateHourSecShort" ? $outputlangs->trans(
"FormatDateHourSecShort") :
$conf->format_date_hour_sec_short);
2941 } elseif ($format ==
'dayhourtext') {
2942 $format = ($outputlangs->trans(
"FormatDateHourText") !=
"FormatDateHourText" ? $outputlangs->trans(
"FormatDateHourText") :
$conf->format_date_hour_text);
2943 } elseif ($format ==
'dayhourtextshort') {
2944 $format = ($outputlangs->trans(
"FormatDateHourTextShort") !=
"FormatDateHourTextShort" ? $outputlangs->trans(
"FormatDateHourTextShort") :
$conf->format_date_hour_text_short);
2945 } elseif ($format ==
'dayhourlog') {
2947 $format =
'%Y%m%d%H%M%S';
2948 } elseif ($format ==
'dayhourlogsmall') {
2950 $format =
'%y%m%d%H%M';
2951 } elseif ($format ==
'dayhourldap') {
2952 $format =
'%Y%m%d%H%M%SZ';
2953 } elseif ($format ==
'dayhourxcard') {
2954 $format =
'%Y%m%dT%H%M%SZ';
2955 } elseif ($format ==
'dayxcard') {
2957 } elseif ($format ==
'dayrfc') {
2958 $format =
'%Y-%m-%d';
2959 } elseif ($format ==
'dayhourrfc') {
2960 $format =
'%Y-%m-%dT%H:%M:%SZ';
2961 } elseif ($format ==
'standard') {
2962 $format =
'%Y-%m-%d %H:%M:%S';
2965 if ($reduceformat) {
2966 $format = str_replace(
'%Y',
'%y', $format);
2967 $format = str_replace(
'yyyy',
'yy', $format);
2971 if (preg_match(
'/%b/i', $format)) {
2973 $format = str_replace(
'%b',
'__b__', $format);
2974 $format = str_replace(
'%B',
'__B__', $format);
2976 if (preg_match(
'/%a/i', $format)) {
2978 $format = str_replace(
'%a',
'__a__', $format);
2979 $format = str_replace(
'%A',
'__A__', $format);
2984 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)) {
2985 dol_print_error(
null,
"Functions.lib::dol_print_date function called with a bad value" .
getCallerInfoString());
2987 } elseif (preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', (
string) $time, $reg)) {
2991 $syear = (!empty($reg[1]) ? $reg[1] :
'');
2992 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
2993 $sday = (!empty($reg[3]) ? $reg[3] :
'');
2994 $shour = (!empty($reg[4]) ? $reg[4] :
'');
2995 $smin = (!empty($reg[5]) ? $reg[5] :
'');
2996 $ssec = (!empty($reg[6]) ? $reg[6] :
'');
2998 $time =
dol_mktime((
int) $shour, (
int) $smin, (
int) $ssec, (
int) $smonth, (
int) $sday, (
int) $syear,
true);
3001 $tzo =
new DateTimeZone(
'UTC');
3003 $tzo =
new DateTimeZone(date_default_timezone_get());
3005 $dtts =
new DateTime();
3006 $dtts->setTimestamp($time);
3007 $dtts->setTimezone($tzo);
3008 $newformat = str_replace(
3009 array(
'%Y',
'%y',
'%m',
'%d',
'%H',
'%I',
'%M',
'%S',
'%p',
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
3010 array(
'Y',
'y',
'm',
'd',
'H',
'h',
'i',
's',
'A',
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
3013 $ret = $dtts->format($newformat);
3015 array(
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
3016 array(
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
3021 if ($time < 100000000000) {
3022 $dtts =
new DateTime();
3025 $timetouse = (int) $time + $offsettz + $offsetdst;
3027 $tzo =
new DateTimeZone(
'UTC');
3028 $dtts->setTimezone($tzo);
3029 $dtts->setTimestamp($timetouse);
3031 $timetouse = (int) $time + $offsettz + $offsetdst;
3033 $tzo =
new DateTimeZone(date_default_timezone_get());
3034 $dtts->setTimestamp($timetouse);
3035 $dtts->setTimezone($tzo);
3038 $newformat = str_replace(
3039 array(
'%Y',
'%y',
'%m',
'%d',
'%H',
'%I',
'%M',
'%S',
'%p',
'%w',
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
3040 array(
'Y',
'y',
'm',
'd',
'H',
'h',
'i',
's',
'A',
'w',
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
3044 $ret = $dtts->format($newformat);
3047 array(
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
3048 array(
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
3052 $ret =
'Bad value ' . $time .
' for date';
3056 if (preg_match(
'/__b__/i', $format)) {
3057 $timetouse = $time + $offsettz + $offsetdst;
3060 $tzo =
new DateTimeZone(
'UTC');
3062 $tzo =
new DateTimeZone(date_default_timezone_get());
3064 $dtts =
new DateTime();
3065 $dtts->setTimestamp($timetouse);
3066 $dtts->setTimezone($tzo);
3067 $month = (int) $dtts->format(
"m");
3068 $month = sprintf(
"%02d", $month);
3069 if ($encodetooutput) {
3070 $monthtext = $outputlangs->transnoentities(
'Month' . $month);
3071 $monthtextshort = $outputlangs->transnoentities(
'MonthShort' . $month);
3073 $monthtext = $outputlangs->transnoentitiesnoconv(
'Month' . $month);
3074 $monthtextshort = $outputlangs->transnoentitiesnoconv(
'MonthShort' . $month);
3077 $ret = str_replace(
'__b__', $monthtextshort, $ret);
3078 $ret = str_replace(
'__B__', $monthtext, $ret);
3082 if (preg_match(
'/__a__/i', $format)) {
3084 $timetouse = $time + $offsettz + $offsetdst;
3087 $tzo =
new DateTimeZone(
'UTC');
3089 $tzo =
new DateTimeZone(date_default_timezone_get());
3091 $dtts =
new DateTime();
3092 $dtts->setTimestamp($timetouse);
3093 $dtts->setTimezone($tzo);
3094 $w = $dtts->format(
"w");
3095 $dayweek = $outputlangs->transnoentitiesnoconv(
'Day' . $w);
3097 $ret = str_replace(
'__A__', $dayweek, $ret);
3098 $ret = str_replace(
'__a__',
dol_substr($dayweek, 0, 3), $ret);
3102 $ret = preg_replace(
'/(\d\d:\d\d [AP]M)$/',
'<span class="'.($decorate === 1 ?
'opacitymedium' : $decorate).
'">\1</span>', $ret);
3103 $ret = preg_replace(
'/(\d\d:\d\d)$/',
'<span class="'.($decorate === 1 ?
'opacitymedium' : $decorate).
'">\1</span>', $ret);
3130function dol_getdate($timestamp, $fast =
false, $forcetimezone =
'')
3132 if ($timestamp ===
'') {
3136 $datetimeobj =
new DateTime();
3137 $datetimeobj->setTimestamp($timestamp);
3138 if ($forcetimezone && $forcetimezone !=
'tzserver') {
3139 $datetimeobj->setTimezone(
new DateTimeZone($forcetimezone ==
'gmt' ?
'UTC' : $forcetimezone));
3142 'year' => ((
int) date_format($datetimeobj,
'Y')),
3143 'mon' => ((
int) date_format($datetimeobj,
'm')),
3144 'mday' => ((
int) date_format($datetimeobj,
'd')),
3145 'wday' => ((
int) date_format($datetimeobj,
'w')),
3146 'yday' => ((
int) date_format($datetimeobj,
'z')),
3147 'hours' => ((
int) date_format($datetimeobj,
'H')),
3148 'minutes' => ((
int) date_format($datetimeobj,
'i')),
3149 'seconds' => ((
int) date_format($datetimeobj,
's')),
3177function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm =
'auto', $check = 1)
3182 if ($gm ===
'auto') {
3183 $gm = (empty(
$conf) ?
'tzserver' :
$conf->tzuserinputkey);
3188 if ($hour == -1 || empty($hour)) {
3191 if ($minute == -1 || empty($minute)) {
3194 if ($second == -1 || empty($second)) {
3200 if (!$month || !$day) {
3209 if ($hour < 0 || $hour > 24) {
3212 if ($minute < 0 || $minute > 60) {
3215 if ($second < 0 || $second > 60) {
3220 if (empty($gm) || ($gm ===
'server' || $gm ===
'tzserver')) {
3221 $default_timezone = @date_default_timezone_get();
3222 $localtz =
new DateTimeZone($default_timezone);
3223 } elseif ($gm ===
'user' || $gm ===
'tzuser' || $gm ===
'tzuserrel') {
3225 $default_timezone = (empty($_SESSION[
"dol_tz_string"]) ? @date_default_timezone_get() : $_SESSION[
"dol_tz_string"]);
3227 $localtz =
new DateTimeZone($default_timezone);
3229 dol_syslog(
"Warning dol_tz_string contains an invalid value " . json_encode($_SESSION[
"dol_tz_string"] ??
null), LOG_WARNING);
3230 $default_timezone = @date_default_timezone_get();
3232 } elseif (strrpos($gm,
"tz,") !==
false) {
3233 $timezone = (string) str_replace(
"tz,",
"", $gm);
3235 $localtz =
new DateTimeZone($timezone);
3237 dol_syslog(
"Warning passed timezone contains an invalid value " . $timezone, LOG_WARNING);
3241 if (empty($localtz)) {
3242 $localtz =
new DateTimeZone(
'UTC');
3244 $dt =
new DateTime(
'now', $localtz);
3245 $dt->setDate((
int) $year, (
int) $month, (
int) $day);
3246 $dt->setTime((
int) $hour, (
int) $minute, (
int) $second);
3247 $date = $dt->getTimestamp();
3263function dol_now($mode =
'gmt')
3267 if ($mode ===
'auto') {
3271 if ($mode ==
'gmt') {
3273 } elseif ($mode ==
'tzserver') {
3274 require_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
3276 $ret = (int) (
dol_now(
'gmt') + ($tzsecond * 3600));
3281 } elseif ($mode ==
'tzuser' || $mode ==
'tzuserrel') {
3284 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
3285 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
3286 $ret = (int) (
dol_now(
'gmt') + ($offsettz + $offsetdst));
3303 global
$conf, $langs;
3306 if (!empty(
$conf->dol_optimize_smallscreen)) {
3311 if (empty($shortvalue) || $size < ($level * 10)) {
3313 $textunitshort = $langs->trans(
"b");
3314 $textunitlong = $langs->trans(
"Bytes");
3316 $ret = round($size / $level, 0);
3317 $textunitshort = $langs->trans(
"Kb");
3318 $textunitlong = $langs->trans(
"KiloBytes");
3321 if (empty($shortunit)) {
3322 $ret .=
' ' . $textunitlong;
3324 $ret .=
' ' . $textunitshort;
3340function dol_print_url($url, $target =
'_blank', $max = 32, $withpicto = 0, $morecss =
'')
3348 $linkstart =
'<a href="';
3349 if (!preg_match(
'/^http/i', $url)) {
3350 $linkstart .=
'http://';
3355 $linkstart .=
' target="' . $target .
'"';
3357 $linkstart .=
' title="' . $langs->trans(
"URL") .
': ' . $url .
'"';
3361 if (!preg_match(
'/^http/i', $url)) {
3368 if ($morecss ==
'float') {
3369 return '<div class="nospan' . ($morecss ?
' ' . $morecss :
'') .
'" style="margin-right: 10px">' . ($withpicto ? img_picto($langs->trans(
"Url"),
'globe',
'class="paddingrightonly"') :
'') . $link .
'</div>';
3371 return $linkstart .
'<span class="nospan' . ($morecss ?
' ' . $morecss :
'') .
'" style="margin-right: 10px">' . ($withpicto ? img_picto(
'',
'globe',
'class="paddingrightonly"') :
'') . $link .
'</span>' . $linkend;
3388function dol_print_email($email, $contactid = 0, $socid = 0, $addlink = 0, $max = 0, $showinvalid = 2, $withpicto = 0, $morecss =
'paddingrightonly')
3390 global $user, $langs, $hookmanager;
3401 if (empty($email)) {
3405 if ($addlink == 1) {
3406 $newemail =
'<a class="' . ($morecss ? $morecss :
'') .
'" style="text-overflow: ellipsis;" href="';
3407 if (!preg_match(
'/^mailto:/i', $email)) {
3408 $newemail .=
'mailto:';
3410 $newemail .= $email;
3411 $newemail .=
'" target="_blank">';
3413 $newemail .= ($withpicto ? img_picto($langs->trans(
"EMail") .
' : ' . $email, (is_numeric($withpicto) ?
'email' : $withpicto),
'class="paddingrightonly"') :
'');
3418 $newemail .= $email;
3420 $newemail .=
'</a>';
3423 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
3424 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
3427 $langs->load(
"errors");
3428 $newemail .= img_warning($langs->transnoentitiesnoconv(
"ErrorBadEMail", $emailonly),
'',
'paddingrightonly');
3430 $langs->load(
"errors");
3431 $newemail .= img_warning($langs->transnoentitiesnoconv(
"ErrorBadMXDomain", $emailonly),
'',
'paddingrightonly');
3435 if (($contactid || $socid) &&
isModEnabled(
'agenda') && $user->hasRight(
"agenda",
"myactions",
"create")) {
3437 $linktoaddaction =
'';
3439 $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>';
3441 if ($linktoaddaction) {
3442 $newemail =
'<div>' . $newemail .
' ' . $linktoaddaction .
'</div>';
3445 } elseif ($addlink ===
'thirdparty') {
3446 $tmpnewemail =
'<a class="' . ($morecss ? $morecss :
'') .
'" style="text-overflow: ellipsis;" href="' . DOL_URL_ROOT .
'/societe/card.php?socid=' . $socid .
'&action=presend&mode=init#formmailbeforetitle">';
3447 $tmpnewemail .= ($withpicto ? img_picto($langs->trans(
"EMail") .
' : ' . $email, (is_numeric($withpicto) ?
'email' : $withpicto),
'class="paddingrightonly"') :
'');
3448 if ($withpicto == 1) {
3449 $tmpnewemail .= $newemail;
3451 $tmpnewemail .=
'</a>';
3453 $newemail = $tmpnewemail;
3455 $newemail = ($withpicto ? img_picto($langs->trans(
"EMail") .
' : ' . $email, (is_numeric($withpicto) ?
'email' : $withpicto),
'class="paddingrightonly"') :
'') . $newemail;
3458 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
3459 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
3462 $langs->load(
"errors");
3463 $newemail .= img_warning($langs->transnoentitiesnoconv(
"ErrorBadEMail", $email));
3465 $langs->load(
"errors");
3466 $newemail .= img_warning($langs->transnoentitiesnoconv(
"ErrorBadMXDomain", $emailonly));
3480 $parameters = array(
'cid' => $contactid,
'socid' => $socid,
'addlink' => $addlink,
'picto' => $withpicto);
3482 $reshook = $hookmanager->executeHooks(
'printEmail', $parameters, $email);
3486 $rep .= $hookmanager->resPrint;
3502 $socialnetworks = array();
3504 require_once DOL_DOCUMENT_ROOT .
'/core/lib/memory.lib.php';
3508 if (!is_null($dataretrieved)) {
3509 $socialnetworks = $dataretrieved;
3511 $sql =
"SELECT rowid, code, label, url, icon, active FROM " . MAIN_DB_PREFIX .
"c_socialnetworks";
3512 $sql .=
" WHERE entity IN (" .
getEntity(
'c_socialnetworks').
")";
3514 $resql = $db->query($sql);
3516 while ($obj = $db->fetch_object($resql)) {
3517 $socialnetworks[$obj->code] = array(
3518 'rowid' => $obj->rowid,
3519 'label' => $obj->label,
3521 'icon' => $obj->icon,
3522 'active' => $obj->active,
3529 return (is_array($socialnetworks) ? $socialnetworks : array());
3544 global $hookmanager, $langs, $user;
3548 if (empty($value)) {
3552 if (!empty($type)) {
3553 $htmllink =
'<div class="divsocialnetwork inline-block valignmiddle">';
3555 $htmllink .=
'<span class="fab pictofixedwidth ' . ($dictsocialnetworks[$type][
'icon'] ? $dictsocialnetworks[$type][
'icon'] :
'fa-link') .
'"></span>';
3556 if ($type ==
'skype') {
3558 $htmllink .=
' <a href="skype:';
3560 $htmllink .=
'?call" alt="' . $langs->trans(
"Call") .
' ' . $value .
'" title="' .
dol_escape_htmltag($langs->trans(
"Call") .
' ' . $value) .
'">';
3561 $htmllink .=
'<img src="' . DOL_URL_ROOT .
'/theme/common/skype_callbutton.png" border="0">';
3562 $htmllink .=
'</a><a href="skype:';
3564 $htmllink .=
'?chat" alt="' . $langs->trans(
"Chat") .
' ' . $value .
'" title="' .
dol_escape_htmltag($langs->trans(
"Chat") .
' ' . $value) .
'">';
3565 $htmllink .=
'<img class="paddingleft" src="' . DOL_URL_ROOT .
'/theme/common/skype_chatbutton.png" border="0">';
3566 $htmllink .=
'</a>';
3567 if (($contactid || $socid) &&
isModEnabled(
'agenda') && $user->hasRight(
'agenda',
'myactions',
'create')) {
3568 $addlink =
'AC_SKYPE';
3571 $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>';
3573 $htmllink .= ($link ?
' ' . $link :
'');
3576 if (!empty($dictsocialnetworks[$type][
'url'])) {
3577 $tmpvirginurl = preg_replace(
'/\/?{socialid}/',
'', $dictsocialnetworks[$type][
'url']);
3578 if ($tmpvirginurl) {
3579 $value = preg_replace(
'/^www\.' . preg_quote($tmpvirginurl,
'/') .
'\/?/',
'', $value);
3580 $value = preg_replace(
'/^' . preg_quote($tmpvirginurl,
'/') .
'\/?/',
'', $value);
3582 $tmpvirginurl3 = preg_replace(
'/^https:\/\//i',
'https://www.', $tmpvirginurl);
3583 if ($tmpvirginurl3) {
3584 $value = preg_replace(
'/^www\.' . preg_quote($tmpvirginurl3,
'/') .
'\/?/',
'', $value);
3585 $value = preg_replace(
'/^' . preg_quote($tmpvirginurl3,
'/') .
'\/?/',
'', $value);
3588 $tmpvirginurl2 = preg_replace(
'/^https?:\/\//i',
'', $tmpvirginurl);
3589 if ($tmpvirginurl2) {
3590 $value = preg_replace(
'/^www\.' . preg_quote($tmpvirginurl2,
'/') .
'\/?/',
'', $value);
3591 $value = preg_replace(
'/^' . preg_quote($tmpvirginurl2,
'/') .
'\/?/',
'', $value);
3594 if (preg_match(
'/^https?:\/\//i', $value)) {
3597 $link = str_replace(
'{socialid}', $value, $dictsocialnetworks[$type][
'url']);
3599 $valuetoshow = $value;
3600 $valuetoshow = preg_replace(
'/https:\/\/www\.(twitter|x|linkedin)\.com\/?/',
'', $valuetoshow);
3601 if (preg_match(
'/^https?:\/\//i', $link)) {
3610 $htmllink .=
'</div>';
3612 $langs->load(
"errors");
3613 $htmllink .= img_warning($langs->trans(
"ErrorBadSocialNetworkValue", $value));
3617 $parameters = array(
3619 'cid' => $contactid,
3622 'dictsocialnetworks' => $dictsocialnetworks,
3625 $reshook = $hookmanager->executeHooks(
'printSocialNetworks', $parameters);
3629 $htmllink .= $hookmanager->resPrint;
3644function dol_print_profids($profID, $profIDtype, $countrycode =
'', $addcpButton = 1)
3648 if (empty($profID) || empty($profIDtype)) {
3651 if (empty($countrycode)) {
3652 $countrycode = (is_object(
$mysoc) ?
$mysoc->country_code :
'');
3654 $newProfID = $profID;
3655 $id = substr($profIDtype, -1);
3657 if (strtoupper($countrycode) ==
'FR') {
3663 $newProfID = substr($newProfID, 0, 3) .
' ' . substr($newProfID, 3, 3) .
' ' . substr($newProfID, 6, 3);
3667 $newProfID = substr($newProfID, 0, 3) .
' ' . substr($newProfID, 3, 3) .
' ' . substr($newProfID, 6, 3) .
' ' . substr($newProfID, 9, 5);
3671 $newProfID = substr($newProfID, 0, 2) .
'.' . substr($newProfID, 2, 3);
3673 if ($profIDtype ===
'VAT' &&
dol_strlen($newProfID) == 13) {
3675 $newProfID = substr($newProfID, 0, 4) .
' ' . substr($newProfID, 4, 3) .
' ' . substr($newProfID, 7, 3) .
' ' . substr($newProfID, 10, 3);
3678 if (!empty($addcpButton)) {
3701function dol_print_phone($phone, $countrycode =
'', $contactid = 0, $socid = 0, $addlink =
'', $separ =
" ", $withpicto =
'', $titlealt =
'', $adddivfloat = 0, $morecss =
'paddingright')
3703 global
$conf, $user, $langs,
$mysoc, $hookmanager;
3706 $phone = is_null($phone) ?
'' : preg_replace(
"/[\s.-]/",
"", trim($phone));
3707 if (empty($phone)) {
3713 if (empty($countrycode) && is_object(
$mysoc)) {
3714 $countrycode =
$mysoc->country_code;
3718 if (!empty(
$conf->dol_optimize_smallscreen) && $separ !=
'hidenum') {
3723 $newphonewa = $phone;
3724 if (strtoupper($countrycode) ==
"FR") {
3727 $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);
3729 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 2) . $separ . substr($newphone, 5, 2);
3731 $newphone = substr($newphone, 0, 2) . $separ . substr($newphone, 2, 3) . $separ . substr($newphone, 5, 2) . $separ . substr($newphone, 7, 2);
3733 $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);
3735 $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);
3737 $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);
3739 } elseif (strtoupper($countrycode) ==
"CA") {
3741 $newphone = ($separ !=
'' ?
'(' :
'') . substr($newphone, 0, 3) . ($separ !=
'' ?
')' :
'') . $separ . substr($newphone, 3, 3) . ($separ !=
'' ?
'-' :
'') . substr($newphone, 6, 4);
3743 } elseif (strtoupper($countrycode) ==
"PT") {
3745 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
3747 } elseif (strtoupper($countrycode) ==
"SR") {
3749 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3);
3751 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 4);
3753 } elseif (strtoupper($countrycode) ==
"DE") {
3755 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4) . $separ . substr($newphone, 7, 4) . $separ . substr($newphone, 11, 3);
3757 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 4) . $separ . substr($newphone, 10, 3);
3759 } elseif (strtoupper($countrycode) ==
"ES") {
3761 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
3763 } elseif (strtoupper($countrycode) ==
"BF") {
3765 $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);
3767 } elseif (strtoupper($countrycode) ==
"RO") {
3769 $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);
3771 } elseif (strtoupper($countrycode) ==
"TR") {
3773 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 4);
3775 } elseif (strtoupper($countrycode) ==
"US") {
3777 $newphone = substr($newphone, 0, 2) . $separ . substr($newphone, 2, 3) . $separ . substr($newphone, 5, 3) . $separ . substr($newphone, 8, 4);
3779 } elseif (strtoupper($countrycode) ==
"MX") {
3781 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 2);
3783 $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);
3785 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 4);
3787 } elseif (strtoupper($countrycode) ==
"ML") {
3789 $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);
3791 } elseif (strtoupper($countrycode) ==
"TH") {
3793 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 3);
3795 $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);
3797 } elseif (strtoupper($countrycode) ==
"MU") {
3800 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 2) . $separ . substr($newphone, 9, 2);
3802 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 4) . $separ . substr($newphone, 8, 2) . $separ . substr($newphone, 10, 2);
3804 } elseif (strtoupper($countrycode) ==
"ZA") {
3806 $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);
3808 } elseif (strtoupper($countrycode) ==
"SY") {
3810 $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);
3812 $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);
3814 } elseif (strtoupper($countrycode) ==
"AE") {
3816 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 2);
3818 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
3820 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 4);
3822 } elseif (strtoupper($countrycode) ==
"DZ") {
3824 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
3826 } elseif (strtoupper($countrycode) ==
"BE") {
3828 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 3);
3830 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
3832 } elseif (strtoupper($countrycode) ==
"PF") {
3834 $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);
3836 } elseif (strtoupper($countrycode) ==
"CO") {
3838 $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);
3840 } elseif (strtoupper($countrycode) ==
"JO") {
3842 $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);
3844 } elseif (strtoupper($countrycode) ==
"JM") {
3846 $newphone = substr($newphone, 0, 5) . $separ . substr($newphone, 5, 3) . $separ . substr($newphone, 8, 4);
3848 } elseif (strtoupper($countrycode) ==
"MG") {
3850 $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);
3852 } elseif (strtoupper($countrycode) ==
"GB") {
3854 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
3856 } elseif (strtoupper($countrycode) ==
"CH") {
3858 $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);
3860 $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);
3862 } elseif (strtoupper($countrycode) ==
"TN") {
3864 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 2) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
3866 } elseif (strtoupper($countrycode) ==
"GF") {
3868 $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);
3870 } elseif (strtoupper($countrycode) ==
"GP") {
3872 $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);
3874 } elseif (strtoupper($countrycode) ==
"MQ") {
3876 $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);
3878 } elseif (strtoupper($countrycode) ==
"IT") {
3880 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
3882 $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);
3884 } elseif (strtoupper($countrycode) ==
"AU") {
3888 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 1) . $separ . substr($newphone, 4, 4) . $separ . substr($newphone, 8, 4);
3890 } elseif (strtoupper($countrycode) ==
"LU") {
3893 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 2) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 2);
3895 $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);
3897 $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);
3899 $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);
3901 } elseif (strtoupper($countrycode) ==
"PE") {
3904 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4);
3906 $newphonewa =
'+51' . $newphone;
3907 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3);
3909 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 4);
3911 $newphonewa = $newphone;
3912 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
3914 } elseif (strtoupper($countrycode) ==
"IN") {
3916 if ($withpicto ==
'phone') {
3917 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 2) . $separ . substr($newphone, 5, 4) . $separ . substr($newphone, 9, 4);
3919 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 5) . $separ . substr($newphone, 8, 5);
3922 } elseif (strtoupper($countrycode) ==
"CI") {
3924 $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) . $separ.substr($newphone, 12, 2);
3928 $newphoneastart = $newphoneaend =
'';
3929 if (!empty($addlink)) {
3931 $newphoneastart =
'<a href="tel:' . urlencode($phone) .
'">';
3932 $newphoneaend .=
'</a>';
3933 } elseif (
isModEnabled(
'clicktodial') && $addlink ==
'AC_TEL') {
3934 if (empty($user->clicktodial_loaded)) {
3935 $user->fetch_clicktodial();
3939 $urlmask =
getDolGlobalString(
'CLICKTODIAL_URL',
'ErrorClickToDialModuleNotConfigured');
3940 if (!empty($user->clicktodial_url)) {
3941 $urlmask = $user->clicktodial_url;
3944 $clicktodial_poste = (!empty($user->clicktodial_poste) ? urlencode($user->clicktodial_poste) :
'');
3945 $clicktodial_login = (!empty($user->clicktodial_login) ? urlencode($user->clicktodial_login) :
'');
3946 $clicktodial_password = (!empty($user->clicktodial_password) ? urlencode($user->clicktodial_password) :
'');
3948 $url = sprintf($urlmask, urlencode($phone), $clicktodial_poste, $clicktodial_login, $clicktodial_password);
3950 $substitarray = array(
3951 '__PHONEFROM__' => $clicktodial_poste,
3952 '__PHONETO__' => urlencode($phone),
3953 '__LOGIN__' => $clicktodial_login,
3954 '__PASS__' => $clicktodial_password
3959 $newphoneastart =
'<a href="' . $url .
'" class="cssforclicktodial">';
3960 $newphoneaend =
'</a>';
3963 $newphoneastart =
'<a href="' . $url .
'"';
3965 $newphoneastart .=
' target="_blank" rel="noopener noreferrer"';
3967 $newphoneastart .=
'>';
3968 $newphoneaend .=
'</a>';
3972 if (
isModEnabled(
'agenda') && $user->hasRight(
"agenda",
"myactions",
"create")) {
3974 $addlinktoagenda =
'';
3975 if ($addlink ==
'AC_FAX') {
3979 $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>';
3981 if ($addlinktoagenda) {
3982 $newphone =
'<span>' . $newphone .
' ' . $addlinktoagenda .
'</span>';
3987 if (
getDolGlobalString(
'CONTACT_PHONEMOBILE_SHOW_LINK_TO_WHATSAPP') && $withpicto ==
'mobile') {
3989 $newphone .=
' <a href="https://wa.me/' . $newphonewa .
'" target="_blank"';
3990 $newphone .=
'><span class="paddingright fab fa-whatsapp" style="color:#25D366;" title="WhatsApp"></span></a>';
3993 if (empty($titlealt) && isset($langs)) {
3994 $titlealt = ($withpicto ==
'fax' ? $langs->trans(
"Fax") : $langs->trans(
"Phone"));
3999 $parameters = array(
'countrycode' => $countrycode,
'cid' => $contactid,
'socid' => $socid,
'titlealt' => $titlealt,
'picto' => $withpicto);
4000 $reshook = $hookmanager->executeHooks(
'printPhone', $parameters, $phone);
4001 $rep .= $hookmanager->resPrint;
4003 if (empty($reshook)) {
4006 if ($withpicto ==
'fax') {
4007 $picto =
'phoning_fax';
4008 } elseif ($withpicto ==
'phone') {
4010 } elseif ($withpicto ==
'mobile') {
4011 $picto =
'phoning_mobile';
4016 if ($adddivfloat == 1) {
4017 $rep .=
'<div class="nospan float' . ($morecss ?
' ' . $morecss :
'') .
'">';
4018 } elseif (empty($adddivfloat)) {
4019 $rep .=
'<span' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
'>';
4022 $rep .= $newphoneastart;
4023 $rep .= ($withpicto ? img_picto($titlealt, $picto) :
'');
4024 if ($separ !=
'hidenum') {
4025 $rep .= ($withpicto ?
' ' :
'') . $newphone;
4027 $rep .= $newphoneaend;
4029 if ($adddivfloat == 1) {
4031 } elseif (empty($adddivfloat)) {
4052 if (!isset(
$conf->cache[
'resolveips'])) {
4053 $conf->cache[
'resolveips'] = array();
4059 if (file_exists(DOL_DOCUMENT_ROOT .
'/theme/common/flags/' . $countrycode .
'.png')) {
4062 $ret .=
'(' . $countrycode .
')';
4075 if (in_array($mode, [0, 2])) {
4078 if (!array_key_exists($ip,
$conf->cache[
'resolveips'])) {
4079 $domain = gethostbyaddr($ip);
4080 $conf->cache[
'resolveips'][$ip] = $domain;
4082 $domain =
$conf->cache[
'resolveips'][$ip];
4110 $ip = (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']);
4117 if (empty($_SERVER[
'HTTP_X_FORWARDED_FOR']) || preg_match(
'/[^0-9\.\:,\[\]\s]/', $_SERVER[
'HTTP_X_FORWARDED_FOR'])) {
4118 if (empty($_SERVER[
'HTTP_CLIENT_IP']) || preg_match(
'/[^0-9\.\:,\[\]\s]/', $_SERVER[
'HTTP_CLIENT_IP'])) {
4119 if (empty($_SERVER[
"HTTP_CF_CONNECTING_IP"])) {
4120 $ip = (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']);
4122 $ip = $_SERVER[
"HTTP_CF_CONNECTING_IP"];
4125 $ip = preg_replace(
'/,.*$/',
'', $_SERVER[
'HTTP_CLIENT_IP']);
4128 $ip = preg_replace(
'/,.*$/',
'', $_SERVER[
'HTTP_X_FORWARDED_FOR']);
4148 $datafile = $diroffile .
'/' .
getDolGlobalString(
'GEOIPMAXMIND_COUNTRY_DATAFILE_EMBEDDED');
4154 include_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeoip.class.php';
4155 $geoip =
new DolGeoIP(
'country', $datafile);
4157 $countrycode = $geoip->getCountryCodeFromIP($ip);
4164 return $countrycode;
4183 $datafile = $diroffile .
'/' .
getDolGlobalString(
'GEOIPMAXMIND_COUNTRY_DATAFILE_EMBEDDED');
4187 include_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeoip.class.php';
4188 $geoip =
new DolGeoIP(
'country', $datafile);
4189 $cityname = $geoip->getCityNameFromIP($ip);
4215 include_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeoip.class.php';
4216 $geoip =
new DolGeoIP(
'country', $datafile);
4217 $countrycode = $geoip->getCountryCodeFromIP($ip);
4218 $ret = $countrycode;
4237 global $hookmanager;
4243 $parameters = array(
'element' => $element,
'id' =>
$id);
4244 $reshook = $hookmanager->executeHooks(
'printAddress', $parameters, $address);
4245 $out .= $hookmanager->resPrint;
4247 if (empty($reshook)) {
4248 if (empty($charfornl)) {
4249 $out .= nl2br((
string) $address);
4251 $out .= preg_replace(
'/[\r\n]+/', $charfornl, (
string) $address);
4255 $showgmap = $showomap = 0;
4281 $url =
dol_buildpath(
'/google/gmaps.php?mode=' . $element .
'&id=' .
$id, 1);
4282 $out .=
' <a href="' . $url .
'" target="_gmaps"><img id="' . $htmlid .
'" class="valigntextbottom" src="' . DOL_URL_ROOT .
'/theme/common/gmap.png"></a>';
4285 $url =
dol_buildpath(
'/openstreetmap/maps.php?mode=' . $element .
'&id=' .
$id, 1);
4286 $out .=
' <a href="' . $url .
'" target="_gmaps"><img id="' . $htmlid .
'_openstreetmap" class="valigntextbottom" src="' . DOL_URL_ROOT .
'/theme/common/gmap.png"></a>';
4308function isValidEmail($address, $acceptsupervisorkey = 0, $acceptuserkey = 0)
4310 if ($acceptsupervisorkey && $address ==
'__SUPERVISOREMAIL__') {
4313 if ($acceptuserkey && $address ==
'__USER_EMAIL__') {
4316 if (filter_var($address, FILTER_VALIDATE_EMAIL)) {
4334 if (function_exists(
'idn_to_ascii') && function_exists(
'checkdnsrr')) {
4335 if (!checkdnsrr(idn_to_ascii($domain),
'MX')) {
4338 if (function_exists(
'getmxrr')) {
4341 getmxrr(idn_to_ascii($domain), $mxhosts, $weight);
4342 if (count($mxhosts) > 1) {
4345 if (count($mxhosts) == 1 && !in_array((
string) $mxhosts[0], array(
'',
'.'))) {
4382 $tmparray = explode(
' ', $s);
4383 foreach ($tmparray as $tmps) {
4399function dol_strlen($string, $stringencoding =
'UTF-8', $binarycount = 0)
4401 if (is_null($string)) {
4405 if (function_exists(
'mb_strlen') && empty($binarycount)) {
4406 return mb_strlen($string, $stringencoding);
4408 return strlen($string);
4422function dol_substr($string, $start, $length =
null, $stringencoding =
'', $trunconbytes = 0)
4426 if (empty($stringencoding)) {
4427 $stringencoding = (empty($langs) ?
'UTF-8' : $langs->charset_output);
4431 if (empty($trunconbytes)) {
4432 if (function_exists(
'mb_substr')) {
4433 $ret = mb_substr($string, $start, $length, $stringencoding);
4435 $ret = substr($string, $start, $length);
4438 if (function_exists(
'mb_strcut')) {
4439 $ret = mb_strcut($string, $start, $length, $stringencoding);
4441 $ret = substr($string, $start, $length);
4461function dol_trunc($string, $size = 40, $trunc =
'right', $stringencoding =
'UTF-8', $nodot = 0, $display = 0)
4469 if (empty($stringencoding)) {
4470 $stringencoding =
'UTF-8';
4473 if (!empty(
$conf->dol_optimize_smallscreen) &&
$conf->dol_optimize_smallscreen == 1 && $display == 1) {
4474 $size = round($size / 3);
4478 if ($trunc ==
'right') {
4480 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
4482 return dol_substr($newstring, 0, $size, $stringencoding) . ($nodot ?
'' :
'…');
4487 } elseif ($trunc ==
'middle') {
4489 if (
dol_strlen($newstring, $stringencoding) > 2 &&
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
4490 $size1 = (int) round($size / 2);
4491 $size2 = (int) round($size / 2);
4492 return dol_substr($newstring, 0, $size1, $stringencoding) .
'…' .
dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size2, $size2, $stringencoding);
4496 } elseif ($trunc ==
'left') {
4498 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
4500 return '…' .
dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size, $size, $stringencoding);
4504 } elseif ($trunc ==
'wrap') {
4506 if (
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
4512 return 'BadParam3CallingDolTrunc';
4528function vatrate($rate, $addpercent =
false, $info_bits = 0, $usestarfornpr = 0, $html = 0)
4532 if (preg_match(
'/%/', $rate)) {
4533 $rate = str_replace(
'%',
'', $rate);
4537 if (preg_match(
'/\((.*)\)/', $rate, $reg)) {
4538 $morelabel =
' (' . $reg[1] .
')';
4539 $rate = preg_replace(
'/\s*' . preg_quote($morelabel,
'/') .
'/',
'', $rate);
4540 $morelabel =
' ' . ($html ?
'<span class="opacitymedium small">' :
'') .
'(' . $reg[1] .
')' . ($html ?
'</span>' :
'');
4542 if (preg_match(
'/\*/', $rate)) {
4543 $rate = str_replace(
'*',
'', $rate);
4548 if (!preg_match(
'/\//', $rate)) {
4549 $ret =
price($rate, 0,
'', 0, 0) . ($addpercent ?
'%' :
'');
4552 $ret = $rate . ($addpercent ?
'%' :
'');
4554 if (($info_bits & 1) && $usestarfornpr >= 0) {
4576function price($amount, $form = 0, $outlangs =
'', $trunc = 1, $rounding = -1, $forcerounding = -1, $currency_code =
'')
4578 global $langs,
$conf;
4581 if (empty($amount)) {
4584 $amount = (is_numeric($amount) ? $amount : 0);
4585 if ($rounding == -1) {
4586 $curcode = $currency_code;
4587 if ($curcode ===
'auto') {
4588 $curcode =
$conf->currency;
4595 $max_decimals_unit =
getDolGlobalInt(
'MAIN_MAX_DECIMALS_UNIT_'.$curcode);
4598 $max_decimals_tot =
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT_'.$curcode);
4602 $rounding = min($max_decimals_unit, $max_decimals_tot);
4604 $nbdecimal = $rounding;
4606 if ($outlangs ===
'none') {
4616 if (!($outlangs instanceof
Translate)) {
4620 if ($outlangs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
4621 $dec = $outlangs->transnoentitiesnoconv(
"SeparatorDecimal");
4623 if ($outlangs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
4624 $thousand = $outlangs->transnoentitiesnoconv(
"SeparatorThousand");
4626 if ($thousand ==
'None') {
4628 } elseif ($thousand ==
'Space') {
4635 $amount = str_replace(
',',
'.', $amount);
4637 $data = explode(
'.', $amount);
4638 $decpart = isset($data[1]) ? $data[1] :
'';
4639 $decpart = preg_replace(
'/0+$/i',
'', $decpart);
4648 $curcode = $currency_code;
4649 if ($curcode ===
'auto') {
4650 $curcode =
$conf->currency;
4659 $nbdecimalmaxshown = (int) str_replace(
'...',
'', $max_decimals_shown);
4660 if ($trunc && $nbdecimal > $nbdecimalmaxshown) {
4661 $nbdecimal = $nbdecimalmaxshown;
4662 if (preg_match(
'/\.\.\./i', $max_decimals_shown)) {
4669 if ((
string) $forcerounding !=
'-1' && (string) $forcerounding !=
'') {
4674 $max_decimals_unit =
getDolGlobalInt(
'MAIN_MAX_DECIMALS_UNIT_'.$curcode);
4677 $max_decimals_tot =
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT_'.$curcode);
4681 if ($forcerounding ===
'MU' || $forcerounding ===
'CU') {
4682 $nbdecimal = $max_decimals_unit;
4683 } elseif ($forcerounding ===
'MT' || $forcerounding ===
'CT') {
4684 $nbdecimal = $max_decimals_tot;
4685 } elseif ($forcerounding >= 0) {
4686 $nbdecimal = (int) $forcerounding;
4691 $output = number_format((
float) $amount, $nbdecimal, $dec, $thousand);
4693 $cursymbolbefore = $cursymbolafter =
'';
4694 if ($currency_code && is_object($outlangs)) {
4695 if ($currency_code ==
'auto') {
4696 $currency_code =
$conf->currency;
4699 $listofcurrenciesbefore = array(
'AUD',
'CAD',
'CNY',
'COP',
'CLP',
'GBP',
'HKD',
'MXN',
'PEN',
'USD',
'CRC',
'ZAR');
4700 $listoflanguagesbefore = array(
'nl_NL');
4701 if (in_array($currency_code, $listofcurrenciesbefore) || in_array($outlangs->defaultlang, $listoflanguagesbefore)) {
4702 $cursymbolbefore .= $outlangs->getCurrencySymbol($currency_code);
4704 $tmpcur = $outlangs->getCurrencySymbol($currency_code);
4705 $cursymbolafter .= ($tmpcur == $currency_code ?
' ' . $tmpcur : $tmpcur);
4709 $output = preg_replace(
'/\s/',
' ', $output);
4710 $output = $cursymbolbefore . $output . $end . ($cursymbolafter ?
' <span class="small">'.$cursymbolafter.
'</span>' :
'');
4711 $output = preg_replace(
'/\'/',
''', $output);
4713 $output = $cursymbolbefore . $output . $end . ($cursymbolafter ?
' '.$cursymbolafter :
'');
4746function price2num($amount, $rounding =
'', $option = 0, $currencycode =
'')
4751 if (is_null($amount)) {
4760 if (is_null($langs)) {
4764 if ($langs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
4765 $dec = $langs->transnoentitiesnoconv(
"SeparatorDecimal");
4767 if ($langs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
4768 $thousand = $langs->transnoentitiesnoconv(
"SeparatorThousand");
4771 if ($thousand ==
'None') {
4773 } elseif ($thousand ==
'Space') {
4781 if (!is_numeric($amount)) {
4782 $amount = preg_replace(
'/[a-zA-Z\/\\\*\(\)<>\_]/',
'', $amount);
4785 if ($option == 2 && $thousand ==
'.' && preg_match(
'/\.(\d\d\d)$/', (
string) $amount)) {
4786 $amount = str_replace($thousand,
'', $amount);
4792 if (is_numeric($amount)) {
4794 $temps = sprintf(
"%10.10F", $amount - intval($amount));
4795 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
4797 $amount = number_format($amount, $nbofdec, $dec, $thousand);
4803 if ($thousand !=
',' && $thousand !=
'.') {
4816 if (preg_match(
'/^(?<int>[^,]*,|[^.]*\.)(?<dec>[^.,]*)$/u', $amount, $matches)) {
4817 $intPart = $matches[
'int'];
4818 $decPart = $matches[
'dec'];
4821 $intPart = str_replace([
'.',
','],
'', $intPart);
4824 $amount = $intPart . $dec . $decPart;
4828 $amount = str_replace(
' ',
'', $amount);
4829 $amount = str_replace($thousand,
'', $amount);
4830 $amount = str_replace($dec,
'.', $amount);
4832 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
4838 $nbofdectoround =
'';
4839 if ($rounding ==
'MU') {
4841 $nbofdectoround =
getDolGlobalInt(
'MAIN_MAX_DECIMALS_UNIT_'.$currencycode);
4845 } elseif ($rounding ==
'MT') {
4847 $nbofdectoround =
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT_'.$currencycode);
4851 } elseif ($rounding ==
'MS') {
4853 } elseif ($rounding ==
'CU' || preg_match(
'/^CU_([a-zA-Z]+)$/', (
string) $rounding, $regscu)) {
4854 $cur = !empty($regscu[1]) ? $regscu[1] : $currencycode;
4860 } elseif ($rounding ==
'CT' || preg_match(
'/^CT_([a-zA-Z]+)$/', (
string) $rounding, $regsct)) {
4861 $cur = !empty($regsct[1]) ? $regsct[1] : $currencycode;
4867 } elseif ($rounding ==
'CR' || preg_match(
'/^CR_([a-zA-Z]+)$/', (
string) $rounding, $regscr)) {
4868 $cur = !empty($regscr[1]) ? $regscr[1] : $currencycode;
4869 if (empty($cur) && (
string)
getDolGlobalString(
'MULTICURRENCY_USE_LIMIT_BY_CURRENCY')) {
4872 $rounding_const =
'MAIN_MAX_DECIMALS_CURRENCY_RATE' . (!empty($cur) ?
'_' . $cur :
'');
4874 } elseif (is_numeric($rounding)) {
4875 $nbofdectoround = (int) $rounding;
4880 $amount = round(is_string($amount) ? (
float) $amount : $amount, $nbofdectoround);
4882 return 'ErrorBadParameterProvidedToFunction';
4888 if (is_numeric($amount)) {
4890 $temps = sprintf(
"%10.10F", $amount - intval($amount));
4891 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
4893 $amount = number_format($amount, min($nbofdec, $nbofdectoround), $dec, $thousand);
4899 if ($thousand !=
',' && $thousand !=
'.') {
4900 $amount = str_replace(
',',
'.', $amount);
4903 $amount = str_replace(
' ',
'', $amount);
4904 $amount = str_replace($thousand,
'', $amount);
4905 $amount = str_replace($dec,
'.', $amount);
4907 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
4926function get_localtax($vatrate, $local, $thirdparty_buyer =
null, $thirdparty_seller =
null, $vatnpr = 0)
4930 if (empty($thirdparty_seller) || !is_object($thirdparty_seller)) {
4931 $thirdparty_seller =
$mysoc;
4934 if (!is_object($thirdparty_seller)) {
4939 "get_localtax tva=" . $vatrate .
" local=" . $local
4940 .
" thirdparty_buyer id=" . (is_object($thirdparty_buyer) ? $thirdparty_buyer->id :
'') .
"/country_code=" . (is_object($thirdparty_buyer) ? $thirdparty_buyer->country_code :
'')
4941 .
" thirdparty_seller id=" . $thirdparty_seller->id .
"/country_code=" . $thirdparty_seller->country_code
4942 .
" thirdparty_seller localtax1_assuj=" . $thirdparty_seller->localtax1_assuj .
" thirdparty_seller localtax2_assuj=" . $thirdparty_seller->localtax2_assuj
4945 $vatratecleaned = $vatrate;
4947 if (preg_match(
'/^(.*)\s*\((.*)\)$/', (
string) $vatrate, $reg)) {
4948 $vatratecleaned = trim($reg[1]);
4949 $vatratecode = $reg[2];
4958 if (
$mysoc->country_code ==
'ES') {
4960 if (!
$mysoc->localtax1_assuj || (
string) $vatratecleaned ==
"0") {
4963 if ($thirdparty_seller->id ==
$mysoc->id) {
4964 if (!$thirdparty_buyer->localtax1_assuj) {
4968 if (!$thirdparty_seller->localtax1_assuj) {
4976 if (!
$mysoc->localtax2_assuj) {
4979 if ($thirdparty_seller->id ==
$mysoc->id) {
4980 if (!$thirdparty_buyer->localtax2_assuj) {
4984 if (!$thirdparty_seller->localtax2_assuj) {
4990 if ($local == 1 && !$thirdparty_seller->localtax1_assuj) {
4993 if ($local == 2 && !$thirdparty_seller->localtax2_assuj) {
4999 if (in_array(
$mysoc->country_code, array(
'ES'))) {
5000 $conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY = 1;
5006 if ($thirdparty_seller !=
$mysoc) {
5008 return $thirdparty_seller->localtax1_value;
5017 if ($thirdparty_seller !=
$mysoc) {
5020 return $thirdparty_seller->localtax2_value;
5023 if (in_array(
$mysoc->country_code, array(
'ES'))) {
5024 return $thirdparty_buyer->localtax2_value;
5033 $sql =
"SELECT t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
5034 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t, " . MAIN_DB_PREFIX .
"c_country as c";
5035 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '" . $db->escape($thirdparty_seller->country_code) .
"'";
5036 $sql .=
" AND t.taux = " . ((float) $vatratecleaned) .
" AND t.active = 1";
5037 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
5038 if (!empty($vatratecode)) {
5039 $sql .=
" AND t.code ='" . $db->escape($vatratecode) .
"'";
5041 $sql .=
" AND t.recuperableonly = '" . $db->escape((
string) $vatnpr) .
"'";
5044 $resql = $db->query($sql);
5047 $obj = $db->fetch_object($resql);
5050 return $obj->localtax1;
5051 } elseif ($local == 2) {
5052 return $obj->localtax2;
5073 $valors = explode(
":", $tax);
5075 if (count($valors) > 1) {
5092 $sql =
" SELECT t.localtax" . ((int) $local) .
" as localtax";
5093 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t INNER JOIN " . MAIN_DB_PREFIX .
"c_country as c ON c.rowid = t.fk_pays";
5094 $sql .=
" WHERE c.code = '" . $db->escape(
$mysoc->country_code) .
"' AND t.active = 1 AND t.entity IN (" .
getEntity(
'c_tva') .
") AND t.taux = (";
5095 $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";
5096 $sql .=
" WHERE c.code = '" . $db->escape(
$mysoc->country_code) .
"' AND t.entity IN (" .
getEntity(
'c_tva') .
") AND tt.active = 1)";
5097 $sql .=
" AND t.localtax" . ((int) $local) .
"_type <> '0'";
5098 $sql .=
" ORDER BY t.rowid DESC";
5100 $resql = $db->query($sql);
5102 $obj = $db->fetch_object($resql);
5104 return $obj->localtax;
5125function getTaxesFromId($vatrate, $buyer =
null, $seller =
null, $firstparamisid = 1)
5129 dol_syslog(
"getTaxesFromId vat id or rate = " . $vatrate);
5132 $sql =
"SELECT t.rowid, t.code, t.taux as rate, t.recuperableonly as npr, t.accountancy_code_sell, t.accountancy_code_buy,";
5133 $sql .=
" t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type";
5134 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t";
5135 if ($firstparamisid) {
5136 $sql .=
" WHERE t.rowid = " . (int) $vatrate;
5138 $vatratecleaned = $vatrate;
5141 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
5142 $vatratecleaned = $reg[1];
5143 $vatratecode = $reg[2];
5146 $sql .=
", " . MAIN_DB_PREFIX .
"c_country as c";
5149 $sql .=
" WHERE t.fk_pays = c.rowid";
5151 $sql .=
" AND c.code = '" . $db->escape($buyer->country_code) .
"'";
5153 $sql .=
" AND c.code = '" . $db->escape($seller->country_code) .
"'";
5155 $sql .=
" AND t.taux = " . ((float) $vatratecleaned) .
" AND t.active = 1";
5156 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
5158 $sql .=
" AND t.code = '" . $db->escape($vatratecode) .
"'";
5162 $resql = $db->query($sql);
5164 $obj = $db->fetch_object($resql);
5167 'rowid' => $obj->rowid,
5168 'code' => $obj->code,
5169 'rate' => $obj->rate,
5170 'localtax1' => $obj->localtax1,
5171 'localtax1_type' => $obj->localtax1_type,
5172 'localtax2' => $obj->localtax2,
5173 'localtax2_type' => $obj->localtax2_type,
5175 'accountancy_code_sell' => $obj->accountancy_code_sell,
5176 'accountancy_code_buy' => $obj->accountancy_code_buy
5182 dol_print_error($db);
5208 dol_syslog(
"getLocalTaxesFromRate vatrate=" . $vatrate .
" local=" . $local);
5211 $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";
5212 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t";
5213 if ($firstparamisid) {
5214 $sql .=
" WHERE t.rowid = " . (int) $vatrate;
5216 $vatratecleaned = $vatrate;
5219 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
5220 $vatratecleaned = $reg[1];
5221 $vatratecode = $reg[2];
5224 $sql .=
", " . MAIN_DB_PREFIX .
"c_country as c";
5226 $countrycodetouse = ((empty($buyer) || empty($buyer->country_code)) ?
$mysoc->country_code : $buyer->country_code);
5227 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '" . $db->escape($countrycodetouse) .
"'";
5229 $countrycodetouse = ((empty($seller) || empty($seller->country_code)) ?
$mysoc->country_code : $seller->country_code);
5230 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '" . $db->escape($countrycodetouse) .
"'";
5232 $sql .=
" AND t.taux = " . ((float) $vatratecleaned) .
" AND t.active = 1";
5234 $sql .=
" AND t.code = '" . $db->escape($vatratecode) .
"'";
5238 $resql = $db->query($sql);
5240 $obj = $db->fetch_object($resql);
5243 $vateratestring = $obj->rate . ($obj->code ?
' (' . $obj->code .
')' :
'');
5246 return array($obj->localtax1_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
5247 } elseif ($local == 2) {
5248 return array($obj->localtax2_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
5250 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);
5272 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
5280 $product->fetch($idprod);
5282 if ((
$mysoc->country_code == $thirdpartytouseforcountry->country_code)
5283 || (in_array(
$mysoc->country_code, array(
'FR',
'MC')) && in_array($thirdpartytouseforcountry->country_code, array(
'FR',
'MC')))
5284 || (in_array(
$mysoc->country_code, array(
'MQ',
'GP')) && in_array($thirdpartytouseforcountry->country_code, array(
'MQ',
'GP')))
5287 if ($idprodfournprice > 0) {
5288 $result = $product->get_buyprice($idprodfournprice, 0, 0,
'');
5290 $ret = $product->vatrate_supplier;
5291 if ($product->default_vat_code_supplier) {
5292 $ret .=
' (' . $product->default_vat_code_supplier .
')';
5298 $ret = $product->tva_tx;
5299 if ($product->default_vat_code) {
5300 $ret .=
' (' . $product->default_vat_code .
')';
5313 $sql =
"SELECT t.taux as vat_rate, t.code as default_vat_code";
5314 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t, " . MAIN_DB_PREFIX .
"c_country as c";
5315 $sql .=
" WHERE t.active = 1 AND t.fk_pays = c.rowid AND c.code = '" . $db->escape($thirdpartytouseforcountry->country_code) .
"'";
5316 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
5317 $sql .=
" ORDER BY t.use_default DESC, t.taux DESC, t.code ASC, t.recuperableonly ASC";
5318 $sql .= $db->plimit(1);
5320 $resql = $db->query($sql);
5322 $obj = $db->fetch_object($resql);
5324 $ret = $obj->vat_rate;
5325 if ($obj->default_vat_code) {
5326 $ret .=
' (' . $obj->default_vat_code .
')';
5331 dol_print_error($db);
5350 dol_syslog(
"get_product_vat_for_country: ret=" . $ret);
5368 if (!class_exists(
'Product')) {
5369 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
5378 $result = $product->fetch($idprod);
5380 if (
$mysoc->country_code == $thirdpartytouseforcountry->country_code) {
5394 $sql =
"SELECT taux as vat_rate, localtax1, localtax2";
5395 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t, " . MAIN_DB_PREFIX .
"c_country as c";
5396 $sql .=
" WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code='" . $db->escape($thirdpartytouseforcountry->country_code) .
"'";
5397 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
5398 $sql .=
" ORDER BY t.taux DESC, t.recuperableonly ASC";
5399 $sql .= $db->plimit(1);
5401 $resql = $db->query($sql);
5403 $obj = $db->fetch_object($resql);
5406 $ret = $obj->localtax1;
5407 } elseif ($local == 2) {
5408 $ret = $obj->localtax2;
5412 dol_print_error($db);
5416 dol_syslog(
"get_product_localtax_for_country: ret=" . $ret);
5440 global
$mysoc, $db, $hookmanager;
5442 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
5445 $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;
5447 if (empty($thirdparty_seller->country_code)) {
5448 $thirdparty_seller->country_code =
$mysoc->country_code;
5450 $seller_country_code = $thirdparty_seller->country_code;
5451 $seller_in_cee =
isInEEC($thirdparty_seller);
5453 if (empty($thirdparty_buyer->country_code)) {
5454 $thirdparty_buyer->country_code =
$mysoc->country_code;
5456 $buyer_country_code = $thirdparty_buyer->country_code;
5457 $buyer_in_cee =
isInEEC($thirdparty_buyer);
5460 "get_default_tva: seller use vat=" . $seller_use_vat .
", seller country=" . $seller_country_code .
", seller in cee=" . ((
string) (
int) $seller_in_cee)
5461 .
", 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)
5462 .
", idprod=" . $idprod .
", idprodfournprice=" . $idprodfournprice .
", SERVICE_ARE_ECOMMERCE_200238EC=" .
getDolGlobalString(
'SERVICE_ARE_ECOMMERCE_200238EC')
5471 if ($seller_in_cee && $buyer_in_cee) {
5472 $isacompany = $thirdparty_buyer->
isACompany();
5473 if ($isacompany && !
getDolGlobalString(
'MAIN_USE_VAT_ZERO_FOR_COMPANIES_IN_EEC_EVEN_IF_VAT_ID_UNKNOWN')) {
5474 require_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
5482 $vatrule =
'VATRULE 0';
5488 if (empty($vatrule) && !$seller_use_vat) {
5496 $vatrule =
'VATRULE 1';
5500 if (empty($vatrule) && !empty($thirdparty_buyer->state_id)) {
5501 $sql =
"SELECT d.rowid, t.taux as vat_default_rate, t.code as vat_default_code ";
5502 $sql .=
" FROM " . $db->prefix() .
"c_tva as t";
5503 $sql .=
" INNER JOIN " . $db->prefix() .
"c_departements as d ON t.fk_department_buyer = d.rowid";
5504 $sql .=
" WHERE d.rowid = " . ((int) $thirdparty_buyer->state_id);
5505 $sql .=
" AND t.active > 0";
5506 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
5507 $sql .=
" ORDER BY t.use_default DESC, t.taux DESC, t.code ASC, t.recuperableonly ASC";
5509 $res = $db->query($sql);
5511 if ($db->num_rows($res)) {
5512 $obj = $db->fetch_object($res);
5514 $vatvalue = $obj->vat_default_rate .
' (' . $obj->vat_default_code .
')';
5515 $vatrule =
'VATRULE 2';
5522 if (empty($vatrule) && (
5523 ($seller_country_code == $buyer_country_code)
5524 || (in_array($seller_country_code, array(
'FR',
'MC')) && in_array($buyer_country_code, array(
'FR',
'MC')))
5525 || (in_array($seller_country_code, array(
'MQ',
'GP')) && in_array($buyer_country_code, array(
'MQ',
'GP')))
5530 if ($seller_country_code ==
'IN' &&
getDolGlobalString(
'MAIN_SALETAX_AUTOSWITCH_I_CS_FOR_INDIA')) {
5534 if (preg_match(
'/C+S-(\d+)/', $tmpvat, $reg) && $thirdparty_seller->state_id != $thirdparty_buyer->state_id) {
5536 $tmpvat = str_replace(
"C+S",
"I", $tmpvat);
5537 } elseif (preg_match(
'/I-(\d+)/', $tmpvat, $reg) && $thirdparty_seller->state_id == $thirdparty_buyer->state_id) {
5539 $tmpvat = str_replace(
"I",
"C+S", $tmpvat);
5543 $vatvalue = $tmpvat;
5544 $vatrule =
'VATRULE 3b';
5552 if (empty($vatrule) && ($seller_in_cee && $buyer_in_cee)) {
5553 $isacompany = $thirdparty_buyer->
isACompany();
5554 if ($isacompany && !
getDolGlobalString(
'MAIN_USE_VAT_ZERO_FOR_COMPANIES_IN_EEC_EVEN_IF_VAT_ID_UNKNOWN')) {
5555 require_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
5564 $vatrule =
'VATRULE 5';
5571 $vatrule =
'VATRULE 6';
5577 if (empty($vatrule) &&
getDolGlobalString(
'MAIN_USE_VAT_OF_PRODUCT_FOR_INDIVIDUAL_CUSTOMER_OUT_OF_EEC') && empty($buyer_in_cee)) {
5578 $isacompany = $thirdparty_buyer->
isACompany();
5581 $vatrule =
'VATRULE extra';
5594 $parameters = array(
'vatvalue' => $vatvalue,
'vatrule' => $vatrule);
5598 $reshook = $hookmanager->executeHooks(
'get_default_tva', $parameters, $tmpobject, $tmpaction);
5599 if ($reshook > 0 && !empty($hookmanager->resArray[
'vatvalue'])) {
5600 $vatvalue = $hookmanager->resArray[
'vatvalue'];
5601 $vatrule = $hookmanager->resArray[
'vatrule'];
5622 if ($idprodfournprice > 0) {
5623 if (!class_exists(
'ProductFournisseur')) {
5624 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.product.class.php';
5627 $prodprice->fetch_product_fournisseur_price($idprodfournprice);
5628 return $prodprice->fourn_tva_npr;
5629 } elseif ($idprod > 0) {
5630 if (!class_exists(
'Product')) {
5631 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
5634 $prod->fetch($idprod);
5635 return $prod->tva_npr;
5658 if (!is_object($thirdparty_seller)) {
5661 if (!is_object($thirdparty_buyer)) {
5665 if (empty($thirdparty_seller->country_code)) {
5666 $thirdparty_seller->country_code =
$mysoc->country_code;
5668 $seller_country_code = $thirdparty_seller->country_code;
5671 if (empty($thirdparty_buyer->country_code)) {
5672 $thirdparty_buyer->country_code =
$mysoc->country_code;
5674 $buyer_country_code = $thirdparty_buyer->country_code;
5678 if (
$mysoc->country_code ==
'ES') {
5679 if (is_numeric($thirdparty_buyer->localtax1_assuj) && !$thirdparty_buyer->localtax1_assuj) {
5684 if (is_numeric($thirdparty_seller->localtax1_assuj) && !$thirdparty_seller->localtax1_assuj) {
5687 if (!is_numeric($thirdparty_seller->localtax1_assuj) && $thirdparty_seller->localtax1_assuj ==
'localtax1off') {
5691 } elseif ($local == 2) {
5693 if (is_numeric($thirdparty_seller->localtax2_assuj) && !$thirdparty_seller->localtax2_assuj) {
5696 if (!is_numeric($thirdparty_seller->localtax2_assuj) && $thirdparty_seller->localtax2_assuj ==
'localtax2off') {
5701 if ($seller_country_code == $buyer_country_code) {
5727function get_exdir($num, $level, $alpha, $withoutslash,
$object, $modulepart =
'')
5729 if (empty($modulepart) && is_object(
$object)) {
5730 if (!empty(
$object->module)) {
5731 $modulepart =
$object->module;
5732 } elseif (!empty(
$object->element)) {
5733 $modulepart =
$object->element;
5740 $arrayforoldpath = array(
'cheque' => 2,
'category' => 2,
'supplier_invoice' => 2,
'invoice_supplier' => 2,
'mailing' => 2,
'supplier_payment' => 2);
5742 $arrayforoldpath[
'product'] = 2;
5745 if (empty($level) && array_key_exists($modulepart, $arrayforoldpath)) {
5746 $level = $arrayforoldpath[$modulepart];
5748 if (!empty($level) && array_key_exists($modulepart, $arrayforoldpath)) {
5750 if (empty($num) && is_object(
$object)) {
5753 if (empty($alpha)) {
5754 $num = preg_replace(
'/([^0-9])/i',
'', $num);
5756 $num = preg_replace(
'/^.*\-/i',
'', $num);
5758 $num = substr(
"000" . $num, -$level);
5760 $path = substr($num, 0, 1);
5763 $path = substr($num, 1, 1) .
'/' . substr($num, 0, 1);
5766 $path = substr($num, 2, 1) .
'/' . substr($num, 1, 1) .
'/' . substr($num, 0, 1);
5772 if (in_array($modulepart, array(
'societe',
'thirdparty')) &&
$object instanceof
Societe) {
5780 if (empty($withoutslash) && !empty($path)) {
5795function dol_mkdir($dir, $dataroot =
'', $newmask =
'')
5797 dol_syslog(
"functions.lib::dol_mkdir: dir=" . $dir, LOG_INFO);
5802 if (@is_dir($dir_osencoded)) {
5810 if (!empty($dataroot)) {
5812 $dir = str_replace($dataroot .
'/',
'', $dir);
5813 $ccdir = $dataroot .
'/';
5816 $cdir = explode(
"/", $dir);
5817 $num = count($cdir);
5818 for ($i = 0; $i < $num; $i++) {
5820 $ccdir .=
'/' . $cdir[$i];
5822 $ccdir .= $cdir[$i];
5825 if (preg_match(
"/^.:$/", $ccdir, $regs)) {
5833 if (!@is_dir($ccdir_osencoded)) {
5834 dol_syslog(
"functions.lib::dol_mkdir: Directory '" . $ccdir .
"' is not found (does not exists or is outside open_basedir PHP setting).", LOG_DEBUG);
5837 $dirmaskdec = octdec((
string) $newmask);
5838 if (empty($newmask)) {
5841 $dirmaskdec |= octdec(
'0111');
5842 if (!@mkdir($ccdir_osencoded, $dirmaskdec)) {
5844 dol_syslog(
"functions.lib::dol_mkdir: Fails to create directory '" . $ccdir .
"' (no permission to write into parent or directory already exists).", LOG_WARNING);
5847 dol_syslog(
"functions.lib::dol_mkdir: Directory '" . $ccdir .
"' created", LOG_DEBUG);
5856 return ($nberr ? -$nberr : $nbcreated);
5867function dolChmod($filepath, $newmask =
'')
5869 if (!empty($newmask)) {
5870 @chmod($filepath, octdec($newmask));
5884 return '<span class="fieldrequired">*</span>';
5904function dol_string_nohtmltag($stringtoclean, $removelinefeed = 1, $pagecodeto =
'UTF-8', $strip_tags = 0, $removedoublespaces = 1)
5906 if (is_null($stringtoclean)) {
5910 if ($removelinefeed == 2) {
5911 $stringtoclean = preg_replace(
'/<br[^>]*>(\n|\r)+/ims',
'<br>', $stringtoclean);
5913 $temp = preg_replace(
'/<br[^>]*>/i',
"\n", $stringtoclean);
5918 $temp = str_replace(
'< ',
'__ltspace__', $temp);
5919 $temp = str_replace(
'<:',
'__lttwopoints__', $temp);
5922 $temp = strip_tags($temp);
5925 $pattern =
"/<[^<>]+>/";
5932 $tempbis = str_replace(
'<>',
'', $temp);
5933 $tempbis = preg_replace($pattern,
'', $tempbis);
5935 }
while ($tempbis != $temp);
5940 $temp = preg_replace(
'/<+([a-z]+)/i',
'\1', $temp);
5946 if ($removelinefeed == 1) {
5947 $temp = str_replace(array(
"\r\n",
"\r",
"\n"),
" ", $temp);
5951 if ($removedoublespaces) {
5952 while (strpos($temp,
" ") !==
false) {
5953 $temp = str_replace(
" ",
" ", $temp);
5957 $temp = str_replace(
'__ltspace__',
'< ', $temp);
5958 $temp = str_replace(
'__lttwopoints__',
'<:', $temp);
5982function dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles = 1, $removeclassattribute = 1, $cleanalsojavascript = 0, $allowiframe = 0, $allowed_tags = array(), $allowlink = 0, $allowscript = 0, $allowstyle = 0, $allowphp = 0)
5984 $sav_allowed_tags = $allowed_tags;
5986 if (empty($allowed_tags) || (is_string($allowed_tags) && preg_match(
'/^common/', $allowed_tags))) {
5987 $allowed_tags = array(
6044 $allowed_tags[] =
"comment";
6046 if (!in_array(
'iframe', $allowed_tags)) {
6047 $allowed_tags[] =
"iframe";
6051 if (!in_array(
'link', $allowed_tags)) {
6052 $allowed_tags[] =
"link";
6054 if (!in_array(
'meta', $allowed_tags)) {
6055 $allowed_tags[] =
"meta";
6059 if (!in_array(
'script', $allowed_tags)) {
6060 $allowed_tags[] =
"script";
6064 if (!in_array(
'style', $allowed_tags)) {
6065 $allowed_tags[] =
"style";
6068 if (is_string($sav_allowed_tags)) {
6069 $tmptags = explode(
',', $sav_allowed_tags);
6070 foreach ($tmptags as $tag) {
6071 if ($tag !=
'common') {
6072 $allowed_tags[] = $tag;
6078 $allowed_tags_string = implode(
"><", $allowed_tags);
6079 $allowed_tags_string =
'<' . $allowed_tags_string .
'>';
6081 $stringtoclean = str_replace(
'<!DOCTYPE html>',
'__!DOCTYPE_HTML__', $stringtoclean);
6086 $stringtoclean = preg_replace(
'/<!--([^>]*)-->/',
'<comment>\1</comment>', $stringtoclean);
6089 $allowed_tags[] =
"commentphp";
6090 $stringtoclean = preg_replace(
'/^<\?php([^"]+)\?>$/i',
'<commentphp>\1__</commentphp>', $stringtoclean);
6091 $stringtoclean = preg_replace(
'/"<\?php([^"]+)\?>"/i',
'"<commentphp>\1</commentphp>"', $stringtoclean);
6094 $stringtoclean = preg_replace(
'/:/i',
':', $stringtoclean);
6095 $stringtoclean = preg_replace(
'/:|�+58|:/i',
'', $stringtoclean);
6098 $temp = strip_tags($stringtoclean, $allowed_tags_string);
6100 if ($cleanalsosomestyles) {
6102 $temp = preg_replace(
'/position\s*:\s*(absolute|fixed)/i',
'', $temp);
6103 $temp = preg_replace(
'/z-index\s*:/i',
'', $temp);
6105 if ($removeclassattribute) {
6106 $temp = preg_replace(
'/(<[^>]+)\s+class=((["\']).*?\\3|\\w*)/i',
'\\1', $temp);
6111 if ($cleanalsojavascript) {
6112 $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);
6115 $temp = str_replace(
'__!DOCTYPE_HTML__',
'<!DOCTYPE html>', $temp);
6118 $temp = preg_replace(
'/<commentphp>(.*)<\/commentphp>/',
'<?php\1?>', $temp);
6121 $temp = preg_replace(
'/<comment>([^>]*)<\/comment>/',
'<!--\1-->', $temp);
6143 if (is_null($allowed_attributes)) {
6144 $allowed_attributes = array(
6178 if (!in_array(
"content", $allowed_attributes)) {
6179 $allowed_attributes[] =
"content";
6181 if (!in_array(
"http-equiv", $allowed_attributes)) {
6182 $allowed_attributes[] =
"http-equiv";
6185 if (class_exists(
'DOMDocument') && !empty($stringtoclean)) {
6186 if ($ishtml === 0) {
6187 $stringtoclean = str_replace(
'&',
'__AMPINTEXT__', $stringtoclean);
6191 $dom =
new DOMDocument(
'',
'UTF-8');
6193 $savwarning = error_reporting();
6194 error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE);
6195 $wrapperId =
"dol_string_onlythesehtmlattributes___wrapper";
6196 $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);
6197 error_reporting($savwarning);
6199 for ($els = $dom->getElementsByTagname(
'*'), $i = $els->length - 1; $i >= 0; $i--) {
6200 $el = $els->item($i);
6201 if (!$el instanceof DOMElement) {
6204 $attrs = $el->attributes;
6205 for ($ii = $attrs->length - 1; $ii >= 0; $ii--) {
6207 if (!empty($attrs->item($ii)->name)) {
6208 if (! in_array($attrs->item($ii)->name, $allowed_attributes)) {
6210 $els->item($i)->removeAttribute($attrs->item($ii)->name);
6211 } elseif (in_array($attrs->item($ii)->name, array(
'style'))) {
6213 $valuetoclean = $attrs->item($ii)->value;
6215 if ($valuetoclean !==
null) {
6217 $oldvaluetoclean = $valuetoclean;
6218 $valuetoclean = preg_replace(
'/\/\*.*\*\//m',
'', $valuetoclean);
6219 $valuetoclean = preg_replace(
'/position\s*:\s*[a-z]+/mi',
'', $valuetoclean);
6220 if ($els->item($i)->tagName ==
'a') {
6221 $valuetoclean = preg_replace(
'/display\s*:/mi',
'', $valuetoclean);
6222 $valuetoclean = preg_replace(
'/z-index\s*:/mi',
'', $valuetoclean);
6223 $valuetoclean = preg_replace(
'/\s+(top|left|right|bottom)\s*:/mi',
'', $valuetoclean);
6227 $valuetoclean = preg_replace(
'/(logout|passwordforgotten)\.php/mi',
'', $valuetoclean);
6228 $valuetoclean = preg_replace(
'/action=/mi',
'', $valuetoclean);
6229 }
while ($oldvaluetoclean != $valuetoclean);
6232 $attrs->item($ii)->value = $valuetoclean;
6238 $dom->encoding =
'UTF-8';
6239 $wrapper = $dom->getElementById($wrapperId);
6241 foreach ($wrapper->childNodes as $child) {
6242 $return .= $dom->saveHTML($child);
6245 if ($ishtml === 0) {
6246 $return = str_replace(
'__AMPINTEXT__',
'&', $return);
6249 return trim($return);
6251 return $stringtoclean;
6268 $temp = $stringtoclean;
6269 foreach ($disallowed_tags as $tagtoremove) {
6270 $temp = preg_replace(
'/<\/?' . $tagtoremove .
'>/',
'', $temp);
6271 $temp = preg_replace(
'/<\/?' . $tagtoremove .
'\s+[^>]*>/',
'', $temp);
6274 if ($cleanalsosomestyles) {
6275 $temp = preg_replace(
'/position\s*:\s*(absolute|fixed)\s*!\s*important/',
'', $temp);
6293 if (!is_string($text) || $text ===
'') {
6298 $selfclosing = array(
'br',
'hr',
'img',
'input',
'meta',
'link',
'source',
'col',
'area',
'base',
'embed',
'param',
'track',
'wbr');
6301 if (preg_match_all(
'/<\s*(\/?)([a-zA-Z][a-zA-Z0-9]*)[^>]*?(\/?)\s*>/', $text, $matches, PREG_SET_ORDER)) {
6302 foreach ($matches as $match) {
6303 $tag = strtolower($match[2]);
6304 if (in_array($tag, $selfclosing) || !empty($match[3])) {
6307 if (empty($match[1])) {
6311 $idx = array_search($tag, array_reverse($opened,
true),
true);
6312 if ($idx !==
false) {
6313 unset($opened[$idx]);
6319 foreach (array_reverse($opened) as $tag) {
6320 $text .=
'</'.$tag.
'>';
6337 if ($nboflines == 1) {
6339 $firstline = preg_replace(
'/<br[^>]*>.*$/s',
'', $text);
6340 $firstline = preg_replace(
'/<div[^>]*>.*$/s',
'', $firstline);
6343 $firstline = preg_replace(
'/[\n\r].*/',
'', $text);
6348 return $firstline . (isset($firstline) && isset($text) && (strlen($firstline) != strlen($text)) ?
'...' :
'');
6352 $text = preg_replace(
'/\n/',
'', $text);
6354 $repTable = array(
"\t" =>
" ",
"\n" =>
" ",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
6356 $repTable = array(
"\t" =>
" ",
"\n" =>
"<br>",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
6359 $text = strtr($text, $repTable);
6360 if ($charset ==
'UTF-8') {
6361 $pattern =
'/(<br[^>]*>)/Uu';
6364 $pattern =
'/(<br[^>]*>)/U';
6366 $a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
6371 $lastaddediscontent = 1;
6372 while ($countline < $nboflines && isset($a[$i])) {
6373 if (preg_match(
'/<br[^>]*>/', $a[$i])) {
6374 if (array_key_exists($i + 1, $a) && !empty($a[$i + 1])) {
6375 $firstline .= ($ishtml ?
"<br>\n" :
"\n");
6377 if (!$lastaddediscontent) {
6380 $lastaddediscontent = 0;
6383 $firstline .= $a[$i];
6384 $lastaddediscontent = 1;
6390 $adddots = (isset($a[$i]) && (!preg_match(
'/<br[^>]*>/', $a[$i]) || (array_key_exists($i + 1, $a) && !empty($a[$i + 1]))));
6392 $ret = $firstline . ($adddots ?
'...' :
'');
6410function dol_nl2br($stringtoencode, $nl2brmode = 0, $forxml =
false)
6412 if (is_null($stringtoencode)) {
6417 return nl2br($stringtoencode, $forxml);
6419 $ret = preg_replace(
'/(\r\n|\r|\n)/i', ($forxml ?
'<br />' :
'<br>'), $stringtoencode);
6434function dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox = 0, $check =
'restricthtml')
6436 if (empty($nouseofiframesandbox) &&
getDolGlobalString(
'MAIN_SECURITY_USE_SANDBOX_FOR_HTMLWITHNOJS')) {
6441 return $stringtoencode;
6443 $out = $stringtoencode;
6445 $antiinfinitloop = 0;
6449 if ($antiinfinitloop >= 20) {
6450 dol_print_error(
null,
"Infinite loop detected after ".$antiinfinitloop.
" iterations in dol_htmlwithnojs");
6455 $oldstringtoclean = $out;
6463 if (!empty($out) &&
getDolGlobalInt(
'MAIN_RESTRICTHTML_ONLY_VALID_HTML') && $check !=
'restricthtmlallowunvalid') {
6465 libxml_use_internal_errors(
false);
6466 if (LIBXML_VERSION < 20900) {
6470 libxml_disable_entity_loader(
true);
6474 $out = preg_replace(
'/&(?![a-zA-Z0-9#]+;)/',
'__AMPINTEXT__', $out);
6477 $dom =
new DOMDocument();
6481 $out = preg_replace_callback(
6482 '/__\[([0-9a-zA-Z_]+)\]__/',
6488 return '__BRACKETSTART' . $m[1] .
'BRACKETEND__';
6492 $wrapperId =
"dol_htmlwithnojs___wrapper___toremove";
6493 $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);
6495 $dom->encoding =
'UTF-8';
6499 foreach ($dom->getElementsByTagName(
'*') as $el) {
6500 if (!$el instanceof DOMElement) {
6505 if ($el->hasAttribute(
'style')) {
6507 $style = $el->getAttribute(
'style');
6510 $style = preg_replace(
'/z-index\s*:/i',
'', $style);
6511 $style = preg_replace(
'/position\s*:/i',
'', $style);
6512 $style = preg_replace(
'/top\s*:/i',
'', $style);
6513 $style = preg_replace(
'/left\s*:/i',
'', $style);
6514 $style = preg_replace(
'/background\s*:/i',
'', $style);
6520 if (trim($style) ===
'') {
6522 $el->removeAttribute(
'style');
6525 $el->setAttribute(
'style', $style);
6531 $wrapper = $dom->getElementById($wrapperId);
6533 foreach ($wrapper->childNodes as $child) {
6534 $result .= $dom->saveHTML($child);
6537 $out = trim($result);
6540 $out = preg_replace_callback(
6541 '/__BRACKETSTART([0-9a-zA-Z_]+)BRACKETEND__/',
6547 return '__[' . $m[1] .
']__';
6553 $out = str_replace(
'__AMPINTEXT__',
'&', $out);
6554 $out = preg_replace(
'/<br\s*\/?>/i',
"\n", $out);
6559 $out =
'InvalidHTMLStringCantBeCleaned ' . $e->getMessage();
6566 if (!empty($out) &&
getDolGlobalInt(
'MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY') && !in_array($check, array(
'restricthtmlallowunvalid',
'restricthtmlallowlinkscript')) && $outishtml) {
6572 if (extension_loaded(
'tidy') && class_exists(
"tidy")) {
6579 'quote-marks' =>
false,
6580 'doctype' =>
'strict',
6581 'show-body-only' =>
true,
6582 "indent-attributes" =>
false,
6583 "vertical-space" =>
false,
6586 'preserve-entities' =>
true
6595 $locale = setlocale(LC_NUMERIC,
'0');
6598 $out = $tidy->repairString($out, $config,
'utf8');
6600 setlocale(LC_NUMERIC, $locale);
6609 $out =
'InvalidHTMLStringCantBeCleaned ' . $e->getMessage();
6615 $out = preg_replace(
'/[\x{200B}-\x{200D}\x{FEFF}]/u',
' ', $out);
6618 $out = preg_replace(
'/&(tab|newline);/i',
' ', $out);
6622 $out = preg_replace(
'/'/i',
''', $out);
6627 if (function_exists(
'realCharForNumericEntities')) {
6628 $out = preg_replace_callback(
6629 '/&#(x?[0-9][0-9a-f]+;?)/i',
6634 static function ($m) {
6642 $out = preg_replace(
'/&#x?[0-9]+/i',
'', $out);
6645 if ($check ==
'restricthtmlallowlinkscript') {
6647 } elseif ($check ==
'restricthtmlallowclass' || $check ==
'restricthtmlallowunvalid') {
6649 } elseif ($check ==
'restricthtmlallowiframe') {
6662 $out = preg_replace(
'/'/i',
"'", $out);
6666 $out = preg_replace(
'/on(mouse|drag|key|load|touch|pointer|select|transition)[a-z]*\s*=/i',
'', $out);
6667 $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);
6668 $out = preg_replace(
'/on(dblclick|drop|durationchange|emptied|end|ended|error|focus(in|out)?|formdata|gotpointercapture|hashchange|input|invalid)[a-z]*\s*=/i',
'', $out);
6669 $out = preg_replace(
'/on(lost|offline|online|message|pagehide|pageshow)[a-z]*\s*=/i',
'', $out);
6670 $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);
6671 $out = preg_replace(
'/on(timeupdate|toggle|unhandled|unload|volumechange|waiting|wheel)[a-z]*\s*=/i',
'', $out);
6673 $out = preg_replace(
'/on(repeat|begin|finish|beforeinput)[a-z]*\s*=/i',
'', $out);
6675 $out = preg_replace(
'/\son[a-z]+\s*=/i',
' ', $out);
6676 }
while ($oldstringtoclean != $out);
6683 $tmpout = preg_replace(
'/<img src="data:/mi',
'<__IMG_SRC_DATA__ src="data:', $out);
6684 preg_match_all(
'/(<img|url\(|<link)/i', $tmpout, $reg);
6685 $nblinks = count($reg[0]);
6686 if ($nblinks >
getDolGlobalInt(
"MAIN_SECURITY_MAX_IMG_IN_HTML_CONTENT", 1000)) {
6687 $out =
'ErrorTooManyLinksIntoHTMLString';
6690 if (
getDolGlobalInt(
'MAIN_DISALLOW_URL_INTO_DESCRIPTIONS') == 2 || $check ==
'restricthtmlnolink') {
6692 $out =
'ErrorHTMLLinksNotAllowed';
6694 } elseif (
getDolGlobalInt(
'MAIN_DISALLOW_URL_INTO_DESCRIPTIONS') == 1) {
6699 $pattern =
'/src=["\']?(http[^"\']+)|url\(["\']?(http[^\)]+)/';
6704 if (preg_match_all($pattern, $out, $matches)) {
6707 foreach ($matches[1] as $tmpval) {
6708 if (!empty($tmpval)) {
6712 foreach ($matches[2] as $tmpval) {
6713 if (!empty($tmpval)) {
6721 foreach ($urls as $url) {
6723 $parsedurl = parse_url($url);
6724 if (!empty($parsedurl)) {
6733 if (empty($firstexturl)) {
6734 $firstexturl = $url;
6735 } elseif (empty($secondexturl)) {
6736 $secondexturl = $url;
6742 $out =
'ErrorHTMLExternalLinksNotAllowed (Example: '.$firstexturl.($secondexturl ?
' '.$secondexturl :
'').
')';
6771function dol_htmlentitiesbr($stringtoencode, $nl2brmode = 0, $pagecodefrom =
'UTF-8', $removelasteolbr = 1)
6773 if (is_null($stringtoencode)) {
6777 $newstring = $stringtoencode;
6779 $newstring = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>/i',
'<br>', $newstring);
6780 if ($removelasteolbr) {
6781 $newstring = preg_replace(
'/<br>$/i',
'', $newstring);
6783 $newstring = preg_replace(
'/[\x{200B}-\x{200D}\x{FEFF}]/u',
' ', $newstring);
6784 $newstring = strtr($newstring, array(
'&' =>
'__PROTECTand__',
'<' =>
'__PROTECTlt__',
'>' =>
'__PROTECTgt__',
'"' =>
'__PROTECTdquot__'));
6786 $newstring = strtr($newstring, array(
'__PROTECTand__' =>
'&',
'__PROTECTlt__' =>
'<',
'__PROTECTgt__' =>
'>',
'__PROTECTdquot__' =>
'"'));
6788 if ($removelasteolbr) {
6789 $newstring = preg_replace(
'/(\r\n|\r|\n)$/i',
'', $newstring);
6808 $ret = preg_replace(
'/' .
"\r\n" .
'<br(\s[\sa-zA-Z_="]*)?\/?>/i',
"<br>", $ret);
6809 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>' .
"\r\n" .
'/i',
"\r\n", $ret);
6810 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>' .
"\n" .
'/i',
"\n", $ret);
6811 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>/i',
"\n", $ret);
6823 $ret = preg_replace(
'/ $/i',
"", $stringtodecode);
6824 $ret = preg_replace(
'/(<br>|<br(\s[\sa-zA-Z_="]*)?\/?>|' .
"\n" .
'|' .
"\r" .
')+$/i',
"", $ret);
6840 if ($keepsomeentities) {
6841 $newstring = strtr($newstring, array(
'&' =>
'__andamp__',
'<' =>
'__andlt__',
'>' =>
'__andgt__',
'"' =>
'__dquot__'));
6843 $newstring = html_entity_decode((
string) $newstring, (
int) $b, (
string)
$c);
6844 if ($keepsomeentities) {
6845 $newstring = strtr($newstring, array(
'__andamp__' =>
'&',
'__andlt__' =>
'<',
'__andgt__' =>
'>',
'__dquot__' =>
'"'));
6861function dol_htmlentities($string, $flags = ENT_QUOTES | ENT_SUBSTITUTE, $encoding =
'UTF-8', $double_encode =
false)
6863 return htmlentities($string, $flags, $encoding, $double_encode);
6882 for ($scursor = 0; $scursor < $len; $scursor++) {
6883 $ordchar = ord($s[$scursor]);
6885 if ($ordchar < 32 && $ordchar != 13 && $ordchar != 10) {
6888 } elseif ($ordchar > 126 && $ordchar < 160) {
6892 $out .= $s[$scursor];
6914 $arraystring = explode(
"\n", $s);
6915 $nb = count($arraystring);
6932 $repTable = array(
"\t" =>
" ",
"\n" =>
"<br>",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
6934 $repTable = array(
"\t" =>
" ",
"\n" =>
" ",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
6937 $text = strtr($text, $repTable);
6938 if ($charset ==
'UTF-8') {
6939 $pattern =
'/(<br[^>]*>)/Uu';
6942 $pattern =
'/(<br[^>]*>)/U';
6944 $a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
6946 $nblines = (int) floor((count($a) + 1) / 2);
6949 foreach ($a as $line) {
6952 $line_dec = html_entity_decode($line);
6954 $line_dec = wordwrap($line_dec, $maxlinesize,
'\n',
true);
6955 $nblines += substr_count($line_dec,
'\n');
6975 if (is_null($msg)) {
6981 if (strpos($msg,
'<') ===
false && strpos($msg,
'&') ===
false) {
6986 if (preg_match(
'/<(html|link|script)/i', $msg)) {
6988 } elseif (preg_match(
'/<body/i', $msg)) {
6990 } elseif (preg_match(
'/<\/textarea/i', $msg)) {
6992 } elseif (preg_match(
'/<(b|em|i|u)(\s+[^>]+)?>/i', $msg)) {
6994 } elseif (preg_match(
'/<br/i', $msg)) {
7000 $msg = preg_replace(
'/https?:\/\/[^"\'\s]+/i',
'', $msg);
7001 if (preg_match(
'/<(html|link|script|body)/i', $msg)) {
7003 } elseif (preg_match(
'/<\/textarea/i', $msg)) {
7005 } elseif (preg_match(
'/<(b|em|i|u)(\s+[^>]+)?>/i', $msg)) {
7007 } elseif (preg_match(
'/<(br|hr)\/>/i', $msg)) {
7009 } elseif (preg_match(
'/<(br|hr|div|font|li|p|span|strong|table)>/i', $msg)) {
7011 } elseif (preg_match(
'/<(br|hr|div|font|li|p|span|strong|table)\s+[^<>\/]*\/?>/i', $msg)) {
7013 } elseif (preg_match(
'/<img\s+[^<>]*src[^<>]*>/i', $msg)) {
7015 } elseif (preg_match(
'/<a\s+[^<>]*href[^<>]*>/i', $msg)) {
7017 } elseif (preg_match(
'/<h[0-9]>/i', $msg)) {
7019 } elseif (preg_match(
'/&[A-Z0-9]{1,6};/i', $msg)) {
7022 } elseif (preg_match(
'/&#[0-9]{2,3};/i', $msg)) {
7024 } elseif (preg_match(
'/&#x[a-f0-9][a-f0-9];/i', $msg)) {
7046function dol_concatdesc($text1, $text2, $forxml =
false, $invert =
false)
7048 if (!empty($invert)) {
7056 $ret .= (!empty($text1) && !empty($text2)) ? ((
dol_textishtml($text1) ||
dol_textishtml($text2)) ? ($forxml ?
"<br >\n" :
"<br>\n") :
"\n") :
"";
7071 return $text1.$text2;
7083 if (!is_string($callback)) {
7084 throw new InvalidArgumentException(
"Les callbacks sont désactivés.");
7087 $allowed_callbacks = [
'strtolower',
'strtoupper',
'intval'];
7088 if (!in_array($callback, $allowed_callbacks,
true)) {
7089 throw new InvalidArgumentException(
"Callback function not allowed.");
7091 return array_map($callback, $array);
7113function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude =
null,
$object =
null, $include =
null)
7117 $substitutionarray = array();
7119 if ((empty($exclude) || !in_array(
'user', $exclude)) && (empty($include) || in_array(
'user', $include)) && $user instanceof
User) {
7123 $emailsendersignature = $user->signature;
7124 $usersignature = $user->signature;
7125 if (
getDolGlobalString(
'MAIN_MAIL_DEFAULT_SIGNATURE_FOR_ALL_USERS') && !empty($user->employee)) {
7126 $emailsendersignature =
getDolGlobalString(
'MAIN_MAIL_DEFAULT_SIGNATURE_FOR_ALL_USERS');
7129 $substitutionarray = array_merge($substitutionarray, array(
7130 '__SENDEREMAIL_SIGNATURE__' => (
string) ((!
getDolGlobalString(
'MAIN_MAIL_DO_NOT_USE_SIGN')) ? ($onlykey == 2 ?
dol_trunc(
'SignatureFromTheSelectedSenderProfile', 30) : $emailsendersignature) :
''),
7134 if (is_object($user)) {
7135 $substitutionarray = array_merge($substitutionarray, array(
7136 '__USER_ID__' => (
string) $user->id,
7137 '__USER_LOGIN__' => (
string) $user->login,
7138 '__USER_EMAIL__' => (
string) $user->email,
7139 '__USER_PHONE__' => (
string)
dol_print_phone($user->office_phone,
'', 0, 0,
'',
" ",
'',
'', -1),
7140 '__USER_PHONEPRO__' => (
string)
dol_print_phone($user->user_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
7141 '__USER_PHONEMOBILE__' => (
string)
dol_print_phone($user->personal_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
7142 '__USER_FAX__' => (
string) $user->office_fax,
7143 '__USER_LASTNAME__' => (
string) $user->lastname,
7144 '__USER_FIRSTNAME__' => (
string) $user->firstname,
7145 '__USER_FULLNAME__' => (
string) $user->getFullName($outputlangs),
7146 '__USER_SUPERVISOR_ID__' => (
string) ($user->fk_user ? $user->fk_user :
'0'),
7147 '__USER_JOB__' => (string) $user->job,
7149 '__USER_VCARD_URL__' => (string) $user->getOnlineVirtualCardUrl(
'',
'external')
7152 $substitutionarray = array_merge($substitutionarray, array(
7153 '__USER_WAREHOUSE_ID__' => isset($user->warehouse->id) ? $user->warehouse->id :
'',
7154 '__USER_WAREHOUSE_REF__' => isset($user->warehouse->
ref) ? $user->warehouse->
ref :
'',
7155 '__USER_WAREHOUSE_DESCRIPTION__' => isset($user->warehouse->
description) ? $user->warehouse->
description :
'',
7156 '__USER_WAREHOUSE_ADDRESS__' => isset($user->warehouse->
address) ? $user->warehouse->
address :
'',
7157 '__USER_WAREHOUSE_ZIP__' => isset($user->warehouse->zip) ? $user->warehouse->zip :
'',
7158 '__USER_WAREHOUSE_TOWN__' => isset($user->warehouse->town) ? $user->warehouse->town :
'',
7159 '__USER_WAREHOUSE_PHONE__' => isset($user->warehouse->phone) ? (string)
dol_print_phone($user->warehouse->phone,
'', 0, 0,
'',
" ",
'',
'', -1) :
'',
7160 '__USER_WAREHOUSE_FAX__' => isset($user->warehouse->fax) ? (string)
dol_print_phone($user->warehouse->fax,
'', 0, 0,
'',
" ",
'',
'', -1) :
''
7165 if ((empty($exclude) || !in_array(
'mycompany', $exclude)) && is_object(
$mysoc) && (empty($include) || in_array(
'mycompany', $include))) {
7166 $substitutionarray = array_merge($substitutionarray, array(
7167 '__MYCOMPANY_NAME__' =>
$mysoc->name,
7168 '__MYCOMPANY_EMAIL__' =>
$mysoc->email,
7169 '__MYCOMPANY_URL__' =>
$mysoc->url,
7171 '__MYCOMPANY_PHONEMOBILE__' =>
dol_print_phone((
string)
$mysoc->phone_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
7173 '__MYCOMPANY_PROFID1__' =>
$mysoc->idprof1,
7174 '__MYCOMPANY_PROFID2__' =>
$mysoc->idprof2,
7175 '__MYCOMPANY_PROFID3__' =>
$mysoc->idprof3,
7176 '__MYCOMPANY_PROFID4__' =>
$mysoc->idprof4,
7177 '__MYCOMPANY_PROFID5__' =>
$mysoc->idprof5,
7178 '__MYCOMPANY_PROFID6__' =>
$mysoc->idprof6,
7179 '__MYCOMPANY_PROFID7__' =>
$mysoc->idprof7,
7180 '__MYCOMPANY_PROFID8__' =>
$mysoc->idprof8,
7181 '__MYCOMPANY_PROFID9__' =>
$mysoc->idprof9,
7182 '__MYCOMPANY_PROFID10__' =>
$mysoc->idprof10,
7183 '__MYCOMPANY_OBJECT__' =>
$mysoc->socialobject,
7184 '__MYCOMPANY_CAPITAL__' =>
$mysoc->capital,
7185 '__MYCOMPANY_FULLADDRESS__' => (method_exists(
$mysoc,
'getFullAddress') ?
$mysoc->getFullAddress(1,
', ') :
''),
7187 '__MYCOMPANY_VATNUMBER__' =>
$mysoc->tva_intra,
7188 '__MYCOMPANY_ZIP__' =>
$mysoc->zip,
7189 '__MYCOMPANY_TOWN__' =>
$mysoc->town,
7190 '__MYCOMPANY_STATE__' =>
$mysoc->state,
7191 '__MYCOMPANY_COUNTRY__' =>
$mysoc->country,
7192 '__MYCOMPANY_COUNTRY_ID__' =>
$mysoc->country_id,
7193 '__MYCOMPANY_COUNTRY_CODE__' =>
$mysoc->country_code,
7194 '__MYCOMPANY_CURRENCY__' => $outputlangs->transnoentitiesnoconv(
"Currency".
$conf->currency),
7195 '__MYCOMPANY_CURRENCY_CODE__' =>
$conf->currency
7199 if (($onlykey || is_object(
$object)) && (empty($exclude) || !in_array(
'object', $exclude)) && (empty($include) || in_array(
'object', $include))) {
7201 $substitutionarray[
'__ID__'] =
'__ID__';
7202 $substitutionarray[
'__REF__'] =
'__REF__';
7203 $substitutionarray[
'__NEWREF__'] =
'__NEWREF__';
7204 $substitutionarray[
'__LABEL__'] =
'__LABEL__';
7205 $substitutionarray[
'__REF_CLIENT__'] =
'__REF_CLIENT__';
7206 $substitutionarray[
'__REF_SUPPLIER__'] =
'__REF_SUPPLIER__';
7207 $substitutionarray[
'__NOTE_PUBLIC__'] =
'__NOTE_PUBLIC__';
7208 $substitutionarray[
'__NOTE_PRIVATE__'] =
'__NOTE_PRIVATE__';
7209 $substitutionarray[
'__EXTRAFIELD_XXX__'] =
'__EXTRAFIELD_XXX__';
7212 $substitutionarray[
'__THIRDPARTY_ID__'] =
'__THIRDPARTY_ID__';
7213 $substitutionarray[
'__THIRDPARTY_NAME__'] =
'__THIRDPARTY_NAME__';
7214 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] =
'__THIRDPARTY_NAME_ALIAS__';
7215 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] =
'__THIRDPARTY_CODE_CLIENT__';
7216 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] =
'__THIRDPARTY_CODE_FOURNISSEUR__';
7217 $substitutionarray[
'__THIRDPARTY_EMAIL__'] =
'__THIRDPARTY_EMAIL__';
7219 $substitutionarray[
'__THIRDPARTY_URL__'] =
'__THIRDPARTY_URL__';
7221 $substitutionarray[
'__THIRDPARTY_PHONE__'] =
'__THIRDPARTY_PHONE__';
7222 $substitutionarray[
'__THIRDPARTY_FAX__'] =
'__THIRDPARTY_FAX__';
7223 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] =
'__THIRDPARTY_ADDRESS__';
7224 $substitutionarray[
'__THIRDPARTY_ZIP__'] =
'__THIRDPARTY_ZIP__';
7225 $substitutionarray[
'__THIRDPARTY_TOWN__'] =
'__THIRDPARTY_TOWN__';
7226 $substitutionarray[
'__THIRDPARTY_STATE__'] =
'__THIRDPARTY_STATE__';
7227 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] =
'__THIRDPARTY_IDPROF1__';
7228 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] =
'__THIRDPARTY_IDPROF2__';
7229 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] =
'__THIRDPARTY_IDPROF3__';
7230 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] =
'__THIRDPARTY_IDPROF4__';
7231 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] =
'__THIRDPARTY_IDPROF5__';
7232 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] =
'__THIRDPARTY_IDPROF6__';
7233 $substitutionarray[
'__THIRDPARTY_IDPROF7__'] =
'__THIRDPARTY_IDPROF7__';
7234 $substitutionarray[
'__THIRDPARTY_IDPROF8__'] =
'__THIRDPARTY_IDPROF8__';
7235 $substitutionarray[
'__THIRDPARTY_IDPROF9__'] =
'__THIRDPARTY_IDPROF9__';
7236 $substitutionarray[
'__THIRDPARTY_IDPROF10__'] =
'__THIRDPARTY_IDPROF10__';
7237 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] =
'__THIRDPARTY_TVAINTRA__';
7238 $substitutionarray[
'__THIRDPARTY_NOTE_PUBLIC__'] =
'__THIRDPARTY_NOTE_PUBLIC__';
7239 $substitutionarray[
'__THIRDPARTY_NOTE_PRIVATE__'] =
'__THIRDPARTY_NOTE_PRIVATE__';
7241 if (
isModEnabled(
'member') && (!is_object(
$object) ||
$object->element ==
'adherent') && (empty($exclude) || !in_array(
'member', $exclude)) && (empty($include) || in_array(
'member', $include))) {
7242 $substitutionarray[
'__MEMBER_ID__'] =
'__MEMBER_ID__';
7243 $substitutionarray[
'__MEMBER_TITLE__'] =
'__MEMBER_TITLE__';
7244 $substitutionarray[
'__MEMBER_FIRSTNAME__'] =
'__MEMBER_FIRSTNAME__';
7245 $substitutionarray[
'__MEMBER_LASTNAME__'] =
'__MEMBER_LASTNAME__';
7246 $substitutionarray[
'__MEMBER_USER_LOGIN_INFORMATION__'] =
'Login and pass of the external user account';
7251 if (
isModEnabled(
'ticket') && (!is_object(
$object) ||
$object->element ==
'ticket') && (empty($exclude) || !in_array(
'ticket', $exclude)) && (empty($include) || in_array(
'ticket', $include))) {
7252 $substitutionarray[
'__TICKET_TRACKID__'] =
'__TICKET_TRACKID__';
7253 $substitutionarray[
'__TICKET_SUBJECT__'] =
'__TICKET_SUBJECT__';
7254 $substitutionarray[
'__TICKET_TYPE__'] =
'__TICKET_TYPE__';
7255 $substitutionarray[
'__TICKET_SEVERITY__'] =
'__TICKET_SEVERITY__';
7256 $substitutionarray[
'__TICKET_CATEGORY__'] =
'__TICKET_CATEGORY__';
7257 $substitutionarray[
'__TICKET_ANALYTIC_CODE__'] =
'__TICKET_ANALYTIC_CODE__';
7258 $substitutionarray[
'__TICKET_MESSAGE__'] =
'__TICKET_MESSAGE__';
7259 $substitutionarray[
'__TICKET_PROGRESSION__'] =
'__TICKET_PROGRESSION__';
7260 $substitutionarray[
'__TICKET_USER_ASSIGN__'] =
'__TICKET_USER_ASSIGN__';
7261 $substitutionarray[
'__TICKET_TYPE_LABEL__'] =
'__TICKET_TYPE_LABEL__';
7262 $substitutionarray[
'__TICKET_SEVERITY_LABEL__'] =
'__TICKET_SEVERITY_LABEL__';
7263 $substitutionarray[
'__TICKET_CATEGORY_LABEL__'] =
'__TICKET_CATEGORY_LABEL__';
7264 $substitutionarray[
'__TICKET_PUBLIC_URL__'] =
'__TICKET_PUBLIC_URL__';
7265 $substitutionarray[
'__TICKET_MANAGEMENT_URL__'] =
'__TICKET_MANAGEMENT_URL__';
7267 if (
isModEnabled(
'recruitment') && (!is_object(
$object) ||
$object->element ==
'recruitmentcandidature') && (empty($exclude) || !in_array(
'recruitment', $exclude)) && (empty($include) || in_array(
'recruitment', $include))) {
7268 $substitutionarray[
'__CANDIDATE_FULLNAME__'] =
'__CANDIDATE_FULLNAME__';
7269 $substitutionarray[
'__CANDIDATE_FIRSTNAME__'] =
'__CANDIDATE_FIRSTNAME__';
7270 $substitutionarray[
'__CANDIDATE_LASTNAME__'] =
'__CANDIDATE_LASTNAME__';
7272 if (
isModEnabled(
'holiday') && (!is_object(
$object) ||
$object->element ==
'holiday') && (empty($exclude) || !in_array(
'holiday', $exclude)) && (empty($include) || in_array(
'holiday', $include))) {
7273 $substitutionarray[
'__HOLIDAY_ARRAY_PER_EMPLOYEE_FOR_PERIOD__'] =
'__HOLIDAY_ARRAY_PER_EMPLOYEE_FOR_PERIOD__';
7275 if (
isModEnabled(
'project') && (empty($exclude) || !in_array(
'project', $exclude)) && (empty($include) || in_array(
'project', $include))) {
7276 $substitutionarray[
'__PROJECT_ID__'] =
'__PROJECT_ID__';
7277 $substitutionarray[
'__PROJECT_REF__'] =
'__PROJECT_REF__';
7278 $substitutionarray[
'__PROJECT_NAME__'] =
'__PROJECT_NAME__';
7282 if (
isModEnabled(
'contract') && (!is_object(
$object) ||
$object->element ==
'contract') && (empty($exclude) || !in_array(
'contract', $exclude)) && (empty($include) || in_array(
'contract', $include))) {
7283 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE__'] =
'Highest date planned for a service start';
7284 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATETIME__'] =
'Highest date and hour planned for service start';
7285 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE__'] =
'Lowest data for planned expiration of service';
7286 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATETIME__'] =
'Lowest date and hour for planned expiration of service';
7288 if (
isModEnabled(
"propal") && (!is_object(
$object) ||
$object->element ==
'propal') && (empty($exclude) || !in_array(
'propal', $exclude)) && (empty($include) || in_array(
'propal', $include))) {
7289 $substitutionarray[
'__ONLINE_SIGN_URL__'] =
'ToOfferALinkForOnlineSignature';
7291 if (
isModEnabled(
"intervention") && (!is_object(
$object) ||
$object->element ==
'fichinter') && (empty($exclude) || !in_array(
'intervention', $exclude)) && (empty($include) || in_array(
'intervention', $include))) {
7292 $substitutionarray[
'__ONLINE_SIGN_FICHINTER_URL__'] =
'ToOfferALinkForOnlineSignature';
7294 $substitutionarray[
'__ONLINE_PAYMENT_URL__'] =
'UrlToPayOnlineIfApplicable';
7295 $substitutionarray[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'TextAndUrlToPayOnlineIfApplicable';
7296 $substitutionarray[
'__SECUREKEYPAYMENT__'] =
'Security key (if key is not unique per record)';
7297 $substitutionarray[
'__SECUREKEYPAYMENT_MEMBER__'] =
'Security key for payment on a member subscription (one key per member)';
7298 $substitutionarray[
'__SECUREKEYPAYMENT_ORDER__'] =
'Security key for payment on an order';
7299 $substitutionarray[
'__SECUREKEYPAYMENT_INVOICE__'] =
'Security key for payment on an invoice';
7300 $substitutionarray[
'__SECUREKEYPAYMENT_CONTRACTLINE__'] =
'Security key for payment on a service of a contract';
7302 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
'Direct download url of a proposal';
7303 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
'Direct download url of an order';
7304 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
'Direct download url of an invoice';
7305 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
'Direct download url of a contract';
7306 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
'Direct download url of a supplier proposal';
7307 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_ORDER__'] =
'Direct download url of a supplier order';
7308 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_INVOICE__'] =
'Direct download url of a supplier invoice';
7311 $substitutionarray[
'__SHIPPINGTRACKNUM__'] =
'Shipping tracking number';
7312 $substitutionarray[
'__SHIPPINGTRACKNUMURL__'] =
'Shipping tracking url';
7313 $substitutionarray[
'__SHIPPINGMETHOD__'] =
'Shipping method';
7316 $substitutionarray[
'__RECEPTIONTRACKNUM__'] =
'Shipping tracking number of shipment';
7317 $substitutionarray[
'__RECEPTIONTRACKNUMURL__'] =
'Shipping tracking url';
7320 '@phan-var-force Adherent|Delivery $object';
7322 $substitutionarray[
'__ID__'] =
$object->id;
7323 $substitutionarray[
'__REF__'] =
$object->ref;
7324 $substitutionarray[
'__NEWREF__'] =
$object->newref;
7326 $substitutionarray[
'__REF_CLIENT__'] = (isset(
$object->ref_client) ?
$object->ref_client : (isset(
$object->ref_customer) ?
$object->ref_customer :
null));
7327 $substitutionarray[
'__REF_SUPPLIER__'] = (isset(
$object->ref_supplier) ?
$object->ref_supplier :
null);
7328 $substitutionarray[
'__NOTE_PUBLIC__'] = (isset(
$object->note_public) ?
$object->note_public :
null);
7329 $substitutionarray[
'__NOTE_PRIVATE__'] = (isset(
$object->note_private) ?
$object->note_private :
null);
7331 $substitutionarray[
'__DATE_CREATION__'] = (isset(
$object->date_creation) ?
dol_print_date(
$object->date_creation,
'day',
false, $outputlangs) :
'');
7332 $substitutionarray[
'__DATE_MODIFICATION__'] = (isset(
$object->date_modification) ?
dol_print_date(
$object->date_modification,
'day',
false, $outputlangs) :
'');
7333 $substitutionarray[
'__DATE_VALIDATION__'] = (isset(
$object->date_validation) ?
dol_print_date(
$object->date_validation,
'day',
false, $outputlangs) :
'');
7336 $date_delivery =
null;
7337 if (property_exists(
$object,
'date_delivery')) {
7338 $date_delivery =
$object->date_delivery;
7339 } elseif (property_exists(
$object,
'delivery_date')) {
7340 $date_delivery =
$object->delivery_date;
7342 $substitutionarray[
'__DATE_DELIVERY__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
'day',
false, $outputlangs) :
'');
7343 $substitutionarray[
'__DATE_DELIVERY_DAY__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%d") :
'');
7344 $substitutionarray[
'__DATE_DELIVERY_DAY_TEXT__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%A") :
'');
7345 $substitutionarray[
'__DATE_DELIVERY_MON__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%m") :
'');
7346 $substitutionarray[
'__DATE_DELIVERY_MON_TEXT__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%b") :
'');
7347 $substitutionarray[
'__DATE_DELIVERY_YEAR__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%Y") :
'');
7348 $substitutionarray[
'__DATE_DELIVERY_HH__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%H") :
'');
7349 $substitutionarray[
'__DATE_DELIVERY_MM__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%M") :
'');
7350 $substitutionarray[
'__DATE_DELIVERY_SS__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%S") :
'');
7353 $substitutionarray[
'__REFCLIENT__'] = (isset(
$object->ref_client) ?
$object->ref_client : (isset(
$object->ref_customer) ?
$object->ref_customer :
null));
7354 $substitutionarray[
'__REFSUPPLIER__'] = (isset(
$object->ref_supplier) ?
$object->ref_supplier :
null);
7356 $substitutionarray[
'__SUPPLIER_ORDER_DATE_DELIVERY__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
'day',
false, $outputlangs) :
'');
7357 $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 :
'')) :
'');
7361 '@phan-var-force Adherent $object';
7365 $substitutionarray[
'__MEMBER_ID__'] = (isset(
$object->id) ?
$object->id :
'');
7366 if (method_exists(
$object,
'getCivilityLabel')) {
7367 $substitutionarray[
'__MEMBER_TITLE__'] =
$object->getCivilityLabel();
7369 $substitutionarray[
'__MEMBER_FIRSTNAME__'] = (isset(
$object->firstname) ?
$object->firstname :
'');
7370 $substitutionarray[
'__MEMBER_LASTNAME__'] = (isset(
$object->lastname) ?
$object->lastname :
'');
7371 $substitutionarray[
'__MEMBER_USER_LOGIN_INFORMATION__'] =
'';
7372 if (method_exists(
$object,
'getFullName')) {
7373 $substitutionarray[
'__MEMBER_FULLNAME__'] =
$object->getFullName($outputlangs);
7375 $substitutionarray[
'__MEMBER_COMPANY__'] = (isset(
$object->societe) ?
$object->societe :
'');
7376 $substitutionarray[
'__MEMBER_ADDRESS__'] = (isset(
$object->address) ?
$object->address :
'');
7377 $substitutionarray[
'__MEMBER_ZIP__'] = (isset(
$object->zip) ?
$object->zip :
'');
7378 $substitutionarray[
'__MEMBER_TOWN__'] = (isset(
$object->town) ?
$object->town :
'');
7379 $substitutionarray[
'__MEMBER_STATE__'] = (isset(
$object->state) ?
$object->state :
'');
7380 $substitutionarray[
'__MEMBER_COUNTRY__'] = (isset(
$object->country) ?
$object->country :
'');
7381 $substitutionarray[
'__MEMBER_EMAIL__'] = (isset(
$object->email) ?
$object->email :
'');
7382 $substitutionarray[
'__MEMBER_BIRTH__'] = (isset($birthday) ? $birthday :
'');
7383 $substitutionarray[
'__MEMBER_PHOTO__'] = (isset(
$object->photo) ?
$object->photo :
'');
7384 $substitutionarray[
'__MEMBER_LOGIN__'] = (isset(
$object->login) ?
$object->login :
'');
7385 $substitutionarray[
'__MEMBER_PASSWORD__'] = (isset(
$object->pass) ?
$object->pass :
'');
7389 $substitutionarray[
'__MEMBER_TYPE__'] = (isset(
$object->type) ?
$object->type :
'');
7390 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE__'] =
dol_print_date(
$object->first_subscription_date,
'day');
7392 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_RFC__'] =
dol_print_date(
$object->first_subscription_date,
'dayrfc');
7393 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_START__'] = (isset(
$object->first_subscription_date_start) ?
dol_print_date(
$object->first_subscription_date_start,
'day') :
'');
7394 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_START_RFC__'] = (isset(
$object->first_subscription_date_start) ?
dol_print_date(
$object->first_subscription_date_start,
'dayrfc') :
'');
7395 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_END__'] = (isset(
$object->first_subscription_date_end) ?
dol_print_date(
$object->first_subscription_date_end,
'day') :
'');
7396 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_END_RFC__'] = (isset(
$object->first_subscription_date_end) ?
dol_print_date(
$object->first_subscription_date_end,
'dayrfc') :
'');
7397 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE__'] =
dol_print_date(
$object->last_subscription_date,
'day');
7398 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_RFC__'] =
dol_print_date(
$object->last_subscription_date,
'dayrfc');
7399 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_START__'] =
dol_print_date(
$object->last_subscription_date_start,
'day');
7400 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_START_RFC__'] =
dol_print_date(
$object->last_subscription_date_start,
'dayrfc');
7401 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_END__'] =
dol_print_date(
$object->last_subscription_date_end,
'day');
7402 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_END_RFC__'] =
dol_print_date(
$object->last_subscription_date_end,
'dayrfc');
7407 '@phan-var-force Societe $object';
7408 $substitutionarray[
'__THIRDPARTY_ID__'] = (
$object->id > 0 ?
$object->id :
'');
7409 $substitutionarray[
'__THIRDPARTY_NAME__'] = (string)
$object->name;
7410 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] = (string)
$object->name_alias;
7411 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] =
$object->code_client ??
'';
7412 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] =
$object->code_fournisseur ??
'';
7413 $substitutionarray[
'__THIRDPARTY_EMAIL__'] =
$object->email ??
'';
7414 $substitutionarray[
'__THIRDPARTY_EMAIL_URLENCODED__'] = urlencode(
$object->email ??
'');
7415 $substitutionarray[
'__THIRDPARTY_URL__'] =
$object->url ??
'';
7416 $substitutionarray[
'__THIRDPARTY_URL_URLENCODED__'] = urlencode(
$object->url ??
'');
7419 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] =
$object->address ??
'';
7420 $substitutionarray[
'__THIRDPARTY_ZIP__'] =
$object->zip ??
'';
7421 $substitutionarray[
'__THIRDPARTY_TOWN__'] =
$object->town ??
'';
7422 $substitutionarray[
'__THIRDPARTY_STATE__'] =
$object->state ??
'';
7423 $substitutionarray[
'__THIRDPARTY_COUNTRY_ID__'] = (
$object->country_id > 0 ?
$object->country_id :
'');
7424 $substitutionarray[
'__THIRDPARTY_COUNTRY_CODE__'] =
$object->country_code;
7425 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] =
$object->idprof1 ??
'';
7426 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] =
$object->idprof2 ??
'';
7427 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] =
$object->idprof3 ??
'';
7428 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] =
$object->idprof4 ??
'';
7429 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] =
$object->idprof5 ??
'';
7430 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] =
$object->idprof6 ??
'';
7431 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] =
$object->tva_intra ??
'';
7434 } elseif (is_object(
$object) && is_object(
$object->thirdparty)) {
7435 $substitutionarray[
'__THIRDPARTY_ID__'] =
$object->thirdparty->id ??
'';
7436 $substitutionarray[
'__THIRDPARTY_NAME__'] =
$object->thirdparty->name ??
'';
7437 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] =
$object->thirdparty->name_alias ??
'';
7438 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] =
$object->thirdparty->code_client ??
'';
7439 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] =
$object->thirdparty->code_fournisseur ??
'';
7440 $substitutionarray[
'__THIRDPARTY_EMAIL__'] =
$object->thirdparty->email ??
'';
7441 $substitutionarray[
'__THIRDPARTY_EMAIL_URLENCODED__'] = urlencode(
$object->thirdparty->email ??
'');
7444 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] =
$object->thirdparty->address ??
'';
7445 $substitutionarray[
'__THIRDPARTY_ZIP__'] =
$object->thirdparty->zip ??
'';
7446 $substitutionarray[
'__THIRDPARTY_TOWN__'] =
$object->thirdparty->town ??
'';
7447 $substitutionarray[
'__THIRDPARTY_STATE__'] =
$object->thirdparty->state ??
'';
7448 $substitutionarray[
'__THIRDPARTY_COUNTRY_ID__'] = (
$object->thirdparty->country_id > 0 ?
$object->thirdparty->country_id :
'');
7449 $substitutionarray[
'__THIRDPARTY_COUNTRY_CODE__'] =
$object->thirdparty->country_code ??
'';
7450 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] =
$object->thirdparty->idprof1 ??
'';
7451 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] =
$object->thirdparty->idprof2 ??
'';
7452 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] =
$object->thirdparty->idprof3 ??
'';
7453 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] =
$object->thirdparty->idprof4 ??
'';
7454 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] =
$object->thirdparty->idprof5 ??
'';
7455 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] =
$object->thirdparty->idprof6 ??
'';
7456 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] =
$object->thirdparty->tva_intra ??
'';
7461 if (is_object(
$object) &&
$object->element ==
'recruitmentcandidature') {
7462 '@phan-var-force RecruitmentCandidature $object';
7464 $substitutionarray[
'__CANDIDATE_FULLNAME__'] =
$object->getFullName($outputlangs);
7465 $substitutionarray[
'__CANDIDATE_FIRSTNAME__'] = isset(
$object->firstname) ?
$object->firstname :
'';
7466 $substitutionarray[
'__CANDIDATE_LASTNAME__'] = isset(
$object->lastname) ?
$object->lastname :
'';
7468 if (is_object(
$object) &&
$object->element ==
'conferenceorboothattendee') {
7469 '@phan-var-force ConferenceOrBoothAttendee $object';
7471 $substitutionarray[
'__ATTENDEE_FULLNAME__'] =
$object->getFullName($outputlangs);
7472 $substitutionarray[
'__ATTENDEE_FIRSTNAME__'] = isset(
$object->firstname) ?
$object->firstname :
'';
7473 $substitutionarray[
'__ATTENDEE_LASTNAME__'] = isset(
$object->lastname) ?
$object->lastname :
'';
7477 '@phan-var-force Project $object';
7479 $substitutionarray[
'__PROJECT_ID__'] =
$object->id;
7480 $substitutionarray[
'__PROJECT_REF__'] =
$object->ref;
7481 $substitutionarray[
'__PROJECT_NAME__'] =
$object->title;
7482 } elseif (is_object(
$object)) {
7484 if (!empty(
$object->project)) {
7487 if (!is_null($project) && is_object($project)) {
7488 $substitutionarray[
'__PROJECT_ID__'] = $project->id;
7489 $substitutionarray[
'__PROJECT_REF__'] = $project->ref;
7490 $substitutionarray[
'__PROJECT_NAME__'] = $project->title;
7495 $project_id =
$object->fk_project;
7496 } elseif (!empty(
$object->fk_projet) &&
$object->fk_projet > 0) {
7497 $project_id =
$object->fk_project;
7499 if ($project_id > 0) {
7501 $substitutionarray[
'__PROJECT_ID__@lazyload'] =
'/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id;
7502 $substitutionarray[
'__PROJECT_REF__@lazyload'] =
'/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id;
7503 $substitutionarray[
'__PROJECT_NAME__@lazyload'] =
'/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id;
7509 '@phan-var-force Facture $object';
7511 $substitutionarray[
'__INVOICE_SITUATION_NUMBER__'] = isset(
$object->situation_counter) ?
$object->situation_counter :
'';
7514 '@phan-var-force Expedition $object';
7516 $substitutionarray[
'__SHIPPINGTRACKNUM__'] =
$object->tracking_number;
7517 $substitutionarray[
'__SHIPPINGTRACKNUMURL__'] =
$object->tracking_url;
7518 $substitutionarray[
'__SHIPPINGMETHOD__'] =
$object->shipping_method;
7521 '@phan-var-force Reception $object';
7523 $substitutionarray[
'__RECEPTIONTRACKNUM__'] =
$object->tracking_number;
7524 $substitutionarray[
'__RECEPTIONTRACKNUMURL__'] =
$object->tracking_url;
7528 '@phan-var-force Contrat $object';
7530 $dateplannedstart =
'';
7531 $datenextexpiration =
'';
7532 foreach (
$object->lines as $line) {
7533 if ($line->date_start > $dateplannedstart) {
7534 $dateplannedstart = $line->date_start;
7536 if ($line->statut == 4 && $line->date_end && (!$datenextexpiration || $line->date_end < $datenextexpiration)) {
7537 $datenextexpiration = $line->date_end;
7540 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE__'] =
dol_print_date($dateplannedstart,
'day');
7541 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE_RFC__'] =
dol_print_date($dateplannedstart,
'dayrfc');
7542 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATETIME__'] =
dol_print_date($dateplannedstart,
'standard');
7544 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE__'] =
dol_print_date($datenextexpiration,
'day');
7545 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE_RFC__'] =
dol_print_date($datenextexpiration,
'dayrfc');
7546 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATETIME__'] =
dol_print_date($datenextexpiration,
'standard');
7550 '@phan-var-force Ticket $object';
7552 $substitutionarray[
'__TICKET_TRACKID__'] =
$object->track_id;
7553 $substitutionarray[
'__TICKET_SUBJECT__'] =
$object->subject;
7554 $substitutionarray[
'__TICKET_TYPE__'] =
$object->type_code;
7555 $substitutionarray[
'__TICKET_SEVERITY__'] =
$object->severity_code;
7556 $substitutionarray[
'__TICKET_CATEGORY__'] =
$object->category_code;
7557 $substitutionarray[
'__TICKET_ANALYTIC_CODE__'] =
$object->category_code;
7558 $substitutionarray[
'__TICKET_MESSAGE__'] =
$object->message;
7559 $substitutionarray[
'__TICKET_PROGRESSION__'] =
$object->progress;
7562 $substitutionarray[
'__TICKET_TYPE_LABEL__'] = empty(
$object->type_code) ?
'' : $outputlangs->getLabelFromKey($db,
'TicketTypeShort'.
$object->type_code,
'c_ticket_type',
'code',
'label',
$object->type_code);
7563 $substitutionarray[
'__TICKET_SEVERITY_LABEL__'] = empty(
$object->severity_code) ?
'' : $outputlangs->getLabelFromKey($db,
'TicketSeverityShort'.
$object->severity_code,
'c_ticket_severity',
'code',
'label',
$object->severity_code);
7564 $substitutionarray[
'__TICKET_CATEGORY_LABEL__'] = empty(
$object->category_code) ?
'' : $outputlangs->getLabelFromKey($db,
'TicketCategoryShort'.
$object->category_code,
'c_ticket_category',
'code',
'label',
$object->category_code);
7565 $substitutionarray[
'__TICKET_PUBLIC_URL__'] =
getDolGlobalString(
'TICKET_URL_PUBLIC_INTERFACE',
dol_buildpath(
'/public/ticket/', 2)).
'view.php?track_id='.urlencode((
string)
$object->track_id);
7566 $substitutionarray[
'__TICKET_MANAGEMENT_URL__'] =
dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.urlencode((
string)
$object->track_id);
7567 $userstat =
new User($db);
7568 if (
$object->fk_user_assign > 0) {
7569 $userstat->fetch(
$object->fk_user_assign);
7570 $substitutionarray[
'__TICKET_USER_ASSIGN__'] =
dolGetFirstLastname($userstat->firstname, $userstat->lastname);
7573 if (
$object->fk_user_create > 0) {
7574 $userstat->fetch(
$object->fk_user_create);
7575 $substitutionarray[
'__USER_CREATE__'] =
dolGetFirstLastname($userstat->firstname, $userstat->lastname);
7581 if (!is_object($extrafields)) {
7584 $extrafields->fetch_name_optionals_label(
$object->table_element,
true);
7586 if (
$object->fetch_optionals() > 0) {
7587 if (is_array($extrafields->attributes[
$object->table_element][
'label']) && count($extrafields->attributes[
$object->table_element][
'label']) > 0) {
7588 foreach ($extrafields->attributes[
$object->table_element][
'label'] as $key => $label) {
7589 if ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'date') {
7590 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] =
dol_print_date(
$object->array_options[
'options_' . $key],
'day');
7591 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_LOCALE__'] =
dol_print_date(
$object->array_options[
'options_' . $key],
'day',
'tzserver', $outputlangs);
7592 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_RFC__'] =
dol_print_date(
$object->array_options[
'options_' . $key],
'dayrfc');
7593 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'datetime') {
7594 $datetime =
$object->array_options[
'options_' . $key];
7595 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhour') :
'');
7596 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_LOCALE__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhour',
'tzserver', $outputlangs) :
'');
7597 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_DAY_LOCALE__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'day',
'tzserver', $outputlangs) :
'');
7598 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_RFC__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhourrfc') :
'');
7599 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'phone') {
7600 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] =
dol_print_phone(
$object->array_options[
'options_' . $key]);
7601 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'price') {
7602 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] =
$object->array_options[
'options_' . $key];
7603 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_FORMATED__'] =
price(
$object->array_options[
'options_' . $key]);
7604 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_FORMATTED__'] =
price(
$object->array_options[
'options_' . $key]);
7605 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'select') {
7606 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] = !empty(
$object->array_options[
'options_' . $key]) ?
$object->array_options[
'options_' . $key] :
'';
7607 $val = $extrafields->attributes[
$object->table_element][
'param'][$key][
'options'][
$object->array_options[
'options_'.$key]] ??
$object->array_options[
'options_'.$key];
7608 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'_LABEL__'] = $val;
7609 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] !=
'separator') {
7610 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] = !empty(
$object->array_options[
'options_' . $key]) ?
$object->array_options[
'options_' . $key] :
'';
7618 if (empty($substitutionarray[
'__REF__'])) {
7622 require_once DOL_DOCUMENT_ROOT .
'/core/lib/payments.lib.php';
7623 $outputlangs->loadLangs(array(
'paypal',
'other'));
7626 $typeforonlinepayment =
'free';
7628 $typeforonlinepayment =
'order';
7631 $typeforonlinepayment =
'invoice';
7634 $typeforonlinepayment =
'member';
7635 if (!empty(
$object->last_subscription_amount)) {
7636 $amounttouse =
$object->last_subscription_amount;
7640 $typeforonlinepayment =
'contract';
7643 $typeforonlinepayment =
'ficheinter';
7646 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $substitutionarray[
'__REF__'], (
float) $amounttouse);
7651 $substitutionarray[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = ($paymenturl ? str_replace(
'\n',
"\n", $outputlangs->trans(
"PredefinedMailContentLink", $paymenturl)) :
'');
7652 $substitutionarray[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
7656 include_once DOL_DOCUMENT_ROOT .
'/core/lib/functions_be.lib.php';
7661 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
$object->getLastMainDocLink(
$object->element);
7663 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
'';
7666 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
$object->getLastMainDocLink(
$object->element);
7668 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
'';
7671 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
$object->getLastMainDocLink(
$object->element);
7673 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
'';
7676 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
$object->getLastMainDocLink(
$object->element);
7678 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
'';
7681 $substitutionarray[
'__DIRECTDOWNLOAD_URL_FICHINTER__'] =
$object->getLastMainDocLink(
$object->element);
7683 $substitutionarray[
'__DIRECTDOWNLOAD_URL_FICHINTER__'] =
'';
7686 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
$object->getLastMainDocLink(
$object->element);
7688 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
'';
7691 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_ORDER__'] =
$object->getLastMainDocLink(
$object->element);
7693 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_ORDER__'] =
'';
7696 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_INVOICE__'] =
$object->getLastMainDocLink(
$object->element);
7698 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_INVOICE__'] =
'';
7702 '@phan-var-force Propal $object';
7704 $substitutionarray[
'__URL_PROPOSAL__'] = DOL_MAIN_URL_ROOT .
"/comm/propal/card.php?id=" .
$object->id;
7705 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
7706 $substitutionarray[
'__ONLINE_SIGN_URL__'] = getOnlineSignatureUrl(0,
'proposal', (
string)
$object->ref, 1,
$object);
7709 '@phan-var-force Commande $object';
7711 $substitutionarray[
'__URL_ORDER__'] = DOL_MAIN_URL_ROOT .
"/commande/card.php?id=" .
$object->id;
7714 '@phan-var-force Facture $object';
7716 $substitutionarray[
'__URL_INVOICE__'] = DOL_MAIN_URL_ROOT .
"/compta/facture/card.php?id=" .
$object->id;
7719 '@phan-var-force Contrat $object';
7721 $substitutionarray[
'__URL_CONTRACT__'] = DOL_MAIN_URL_ROOT .
"/contrat/card.php?id=" .
$object->id;
7722 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
7723 $substitutionarray[
'__ONLINE_SIGN_URL__'] = getOnlineSignatureUrl(0,
'contract', (
string)
$object->ref, 1,
$object);
7726 '@phan-var-force Fichinter $object';
7728 $substitutionarray[
'__URL_FICHINTER__'] = DOL_MAIN_URL_ROOT .
"/fichinter/card.php?id=" .
$object->id;
7729 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
7730 $substitutionarray[
'__ONLINE_SIGN_FICHINTER_URL__'] = getOnlineSignatureUrl(0,
'fichinter', (
string)
$object->ref, 1,
$object);
7732 if (is_object(
$object) &&
$object->element ==
'supplier_proposal') {
7733 '@phan-var-force SupplierProposal $object';
7735 $substitutionarray[
'__URL_SUPPLIER_PROPOSAL__'] = DOL_MAIN_URL_ROOT .
"/supplier_proposal/card.php?id=" .
$object->id;
7737 if (is_object(
$object) &&
$object->element ==
'invoice_supplier') {
7738 '@phan-var-force FactureFournisseur $object';
7740 $substitutionarray[
'__URL_SUPPLIER_INVOICE__'] = DOL_MAIN_URL_ROOT .
"/fourn/facture/card.php?id=" .
$object->id;
7742 if (is_object(
$object) &&
$object->element ==
'payment_supplier') {
7743 '@phan-var-force PaiementFourn $object';
7746 $liste_factures = [];
7750 $sql =
'SELECT f.ref,f.multicurrency_code as f_mccode, pf.*
7751 FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf
7752 JOIN '.MAIN_DB_PREFIX.
'facture_fourn as f ON pf.fk_facturefourn = f.rowid
7753 WHERE pf.fk_paiementfourn = '.((int)
$object->id);
7755 $resql = $db->query($sql);
7757 while ($objp = $db->fetch_object($resql)) {
7758 $liste_factures[] =
' - '.$outputlangs->trans(
'Invoice').
' '. $objp->ref.
' '.$outputlangs->trans(
'AmountPayed').
' '.
price($objp->multicurrency_amount, 0, $outputlangs, 0, -1, -1, $objp->multicurrency_code);
7761 $substitutionarray[
'__SUPPLIER_PAYMENT_INVOICES_LIST__'] = implode(
"\n", $liste_factures);
7763 $substitutionarray[
'__SUPPLIER_PAYMENT_INVOICES_TOTAL__'] =
price(
$object->multicurrency_amount, 0, $outputlangs, 0, -1, -1,
$object->multicurrency_code ?
$object->multicurrency_code :
$conf->currency);
7766 '@phan-var-force Expedition $object';
7768 $substitutionarray[
'__URL_SHIPMENT__'] = DOL_MAIN_URL_ROOT .
"/expedition/card.php?id=" .
$object->id;
7770 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
7771 $substitutionarray[
'__ONLINE_SIGN_URL__'] = getOnlineSignatureUrl(0,
'expedition', (
string)
$object->ref, 1,
$object);
7777 '@phan-var-force ActionComm $object';
7779 $substitutionarray[
'__EVENT_LABEL__'] =
$object->label;
7780 $substitutionarray[
'__EVENT_DESCRIPTION__'] =
$object->note;
7781 $substitutionarray[
'__EVENT_TYPE__'] = $outputlangs->trans(
"Action" .
$object->type_code);
7783 $substitutionarray[
'__EVENT_TIME__'] =
dol_print_date(
$object->datep,
'hour',
'auto', $outputlangs);
7784 $substitutionarray[
'__EVENT_DATE_TZUSER__'] =
dol_print_date(
$object->datep,
'day',
'tzuserrel', $outputlangs);
7785 $substitutionarray[
'__EVENT_TIME_TZUSER__'] =
dol_print_date(
$object->datep,
'hour',
'tzuserrel', $outputlangs);
7790 if ((empty($exclude) || !in_array(
'objectamount', $exclude)) && (empty($include) || in_array(
'objectamount', $include))) {
7791 '@phan-var-force Facture|FactureRec $object';
7793 include_once DOL_DOCUMENT_ROOT .
'/core/lib/functionsnumtoword.lib.php';
7796 $substitutionarray[
'__DATE_DUE_YMD__'] = is_object(
$object) ? (isset(
$object->date_lim_reglement) ?
dol_print_date(
$object->date_lim_reglement,
'day',
false, $outputlangs) : null) :
'';
7798 $substitutionarray[
'__DATE_DUE_YMD_TEXT__'] = is_object(
$object) ? (isset(
$object->date_lim_reglement) ?
dol_print_date(
$object->date_lim_reglement,
'daytext',
false, $outputlangs) : null) :
'';
7800 $already_payed_all = 0;
7806 $substitutionarray[
'__AMOUNT_EXCL_TAX__'] = is_object(
$object) ?
$object->total_ht :
'';
7810 $substitutionarray[
'__AMOUNT__'] = is_object(
$object) ?
$object->total_ttc :
'';
7814 $substitutionarray[
'__DEPOSIT_PERCENT__'] = is_object(
$object) ?
$object->deposit_percent :
'';
7817 $substitutionarray[
'__AMOUNT_REMAIN__'] = is_object(
$object) ?
price2num(
$object->total_ttc - $already_payed_all,
'MT') :
'';
7819 $substitutionarray[
'__AMOUNT_VAT__'] = is_object(
$object) ? (isset(
$object->total_vat) ?
$object->total_vat :
$object->total_tva) :
'';
7823 $mysocuselocaltax1 =
false;
7824 $mysocuselocaltax2 =
false;
7826 $tmparray =
$mysoc->useLocalTax(-1);
7827 if (is_array($tmparray)) {
7828 $mysocuselocaltax1 = $tmparray[1];
7829 $mysocuselocaltax2 = $tmparray[2];
7834 if ($onlykey != 2 || $mysocuselocaltax1) {
7835 $substitutionarray[
'__AMOUNT_TAX2__'] = is_object(
$object) ?
$object->total_localtax1 :
'';
7837 if ($onlykey != 2 || $mysocuselocaltax2) {
7838 $substitutionarray[
'__AMOUNT_TAX3__'] = is_object(
$object) ?
$object->total_localtax2 :
'';
7842 $substitutionarray[
'__AMOUNT_EXCL_TAX_FORMATTED__'] = is_object(
$object) ? (
$object->total_ht ?
price(
$object->total_ht, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null) :
'';
7843 $substitutionarray[
'__AMOUNT_FORMATTED__'] = is_object(
$object) ? (
$object->total_ttc ?
price(
$object->total_ttc, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null) :
'';
7844 $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) :
'';
7845 $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)) :
'';
7846 if ($onlykey != 2 || $mysocuselocaltax1) {
7847 $substitutionarray[
'__AMOUNT_TAX2_FORMATTED__'] = is_object(
$object) ? (
$object->total_localtax1 ?
price(
$object->total_localtax1, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null) :
'';
7849 if ($onlykey != 2 || $mysocuselocaltax2) {
7850 $substitutionarray[
'__AMOUNT_TAX3_FORMATTED__'] = is_object(
$object) ? (
$object->total_localtax2 ?
price(
$object->total_localtax2, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null) :
'';
7853 if ($onlykey != 2) {
7854 $substitutionarray[
'__AMOUNT_EXCL_TAX_FORMATED__'] = $substitutionarray[
'__AMOUNT_EXCL_TAX_FORMATTED__'];
7855 $substitutionarray[
'__AMOUNT_FORMATED__'] = $substitutionarray[
'__AMOUNT_FORMATTED__'];
7856 $substitutionarray[
'__AMOUNT_REMAIN_FORMATED__'] = $substitutionarray[
'__AMOUNT_REMAIN_FORMATTED__'];
7857 $substitutionarray[
'__AMOUNT_VAT_FORMATED__'] = $substitutionarray[
'__AMOUNT_VAT_FORMATTED__'];
7858 if ($mysocuselocaltax1) {
7859 $substitutionarray[
'__AMOUNT_TAX2_FORMATED__'] = $substitutionarray[
'__AMOUNT_TAX2_FORMATTED__'];
7861 if (
$mysoc->useLocalTax2) {
7862 $substitutionarray[
'__AMOUNT_TAX3_FORMATED__'] = $substitutionarray[
'__AMOUNT_TAX3_FORMATTED__'];
7866 $substitutionarray[
'__AMOUNT_MULTICURRENCY__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
$object->multicurrency_total_ttc :
'';
7867 $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) :
'';
7868 $substitutionarray[
'__AMOUNT_MULTICURRENCY_TEXT__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
dol_convertToWord(
$object->multicurrency_total_ttc, $outputlangs,
'',
true) :
'';
7869 $substitutionarray[
'__AMOUNT_MULTICURRENCY_TEXTCURRENCY__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
dol_convertToWord(
$object->multicurrency_total_ttc, $outputlangs,
$object->multicurrency_code,
true) :
'';
7870 $substitutionarray[
'__MULTICURRENCY_CODE__'] = (is_object(
$object) && isset(
$object->multicurrency_code)) ?
$object->multicurrency_code :
'';
7874 if ($onlykey != 2) {
7875 $substitutionarray[
'__TOTAL_TTC__'] = is_object(
$object) ?
$object->total_ttc :
'';
7876 $substitutionarray[
'__TOTAL_HT__'] = is_object(
$object) ?
$object->total_ht :
'';
7881 if ((empty($exclude) || !in_array(
'date', $exclude)) && (empty($include) || in_array(
'date', $include))) {
7882 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
7892 $daytext = $outputlangs->trans(
'Day' . $tmp[
'wday']);
7894 $substitutionarray = array_merge($substitutionarray, array(
7895 '__NOW_TMS__' => (
string) $now,
7896 '__NOW_TMS_YMD__' =>
dol_print_date($now,
'day',
'auto', $outputlangs),
7897 '__DAY__' => (
string) $tmp[
'mday'],
7898 '__DAY_TEXT__' => $daytext,
7899 '__DAY_TEXT_SHORT__' =>
dol_trunc($daytext, 3,
'right',
'UTF-8', 1),
7900 '__DAY_TEXT_MIN__' =>
dol_trunc($daytext, 1,
'right',
'UTF-8', 1),
7901 '__MONTH__' => (
string) $tmp[
'mon'],
7902 '__MONTH_TEXT__' => $outputlangs->transnoentitiesnoconv(
'Month' . sprintf(
"%02d", $tmp[
'mon'])),
7903 '__MONTH_TEXT_SHORT__' => $outputlangs->transnoentitiesnoconv(
'MonthShort' . sprintf(
"%02d", $tmp[
'mon'])),
7904 '__MONTH_TEXT_MIN__' => $outputlangs->transnoentitiesnoconv(
'MonthVeryShort' . sprintf(
"%02d", $tmp[
'mon'])),
7905 '__YEAR__' => (
string) $tmp[
'year'],
7906 '__YEAR_PREVIOUS_MONTH__' => (
string) $tmp3[
'year'],
7907 '__YEAR_NEXT_MONTH__' => (
string) $tmp5[
'year'],
7908 '__PREVIOUS_DAY__' => (
string) $tmp2[
'day'],
7909 '__PREVIOUS_MONTH__' => (
string) $tmp3[
'month'],
7910 '__PREVIOUS_MONTH_TEXT__' => $outputlangs->transnoentitiesnoconv(
'Month' . sprintf(
"%02d", $tmp3[
'month'])),
7911 '__PREVIOUS_MONTH_TEXT_SHORT__' => $outputlangs->transnoentitiesnoconv(
'MonthShort' . sprintf(
"%02d", $tmp3[
'month'])),
7912 '__PREVIOUS_MONTH_TEXT_MIN__' => $outputlangs->transnoentitiesnoconv(
'MonthVeryShort' . sprintf(
"%02d", $tmp3[
'month'])),
7913 '__PREVIOUS_YEAR__' => (
string) ($tmp[
'year'] - 1),
7914 '__NEXT_DAY__' => (
string) $tmp4[
'day'],
7915 '__NEXT_MONTH__' => (
string) $tmp5[
'month'],
7916 '__NEXT_MONTH_TEXT__' => $outputlangs->transnoentitiesnoconv(
'Month' . sprintf(
"%02d", $tmp5[
'month'])),
7917 '__NEXT_MONTH_TEXT_SHORT__' => $outputlangs->transnoentitiesnoconv(
'MonthShort' . sprintf(
"%02d", $tmp5[
'month'])),
7918 '__NEXT_MONTH_TEXT_MIN__' => $outputlangs->transnoentitiesnoconv(
'MonthVeryShort' . sprintf(
"%02d", $tmp5[
'month'])),
7919 '__NEXT_YEAR__' => (
string) ($tmp[
'year'] + 1),
7924 $substitutionarray = array_merge($substitutionarray, array(
'__ENTITY_ID__' =>
$conf->entity));
7926 if ((empty($exclude) || !in_array(
'system', $exclude)) && (empty($include) || in_array(
'user', $include))) {
7927 $substitutionarray[
'__DOL_MAIN_URL_ROOT__'] = DOL_MAIN_URL_ROOT;
7928 $substitutionarray[
'__(AnyTranslationKey)__'] = $outputlangs->transnoentitiesnoconv(
'TranslationOfKey');
7929 $substitutionarray[
'__(AnyTranslationKey|langfile)__'] = $outputlangs->transnoentitiesnoconv(
'TranslationOfKey') .
' (load also language file before)';
7930 $substitutionarray[
'__[AnyConstantKey]__'] = $outputlangs->transnoentitiesnoconv(
'ValueOfConstantKey');
7935 return $substitutionarray;
7954function make_substitutions($text, $substitutionarray, $outputlangs =
null, $converttextinhtmlifnecessary = 0)
7958 if (!is_array($substitutionarray)) {
7959 return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions';
7962 if (empty($outputlangs)) {
7963 $outputlangs = $langs;
7973 if (is_object($outputlangs)) {
7975 while (preg_match(
'/__\(([^\)]+)\)__/', $text, $reg)) {
7977 $tmp = explode(
'|', $reg[1]);
7978 if (!empty($tmp[1])) {
7979 $outputlangs->load($tmp[1]);
7982 $value = $outputlangs->transnoentitiesnoconv($reg[1]);
7984 if (empty($converttextinhtmlifnecessary)) {
7986 $text = preg_replace(
'/__\(' . preg_quote($reg[1],
'/') .
'\)__/', $msgishtml ?
dol_htmlentitiesbr($value) : $value, $text);
7988 if (preg_match(
'/__\(' . preg_quote($reg[1],
'/') .
'\)__/', $text)) {
8001 $text = preg_replace(
'/__\(' . preg_quote($reg[1],
'/') .
'\)__/', $value, $text);
8009 while (preg_match(
'/__\[([^\]]+)\]__/', $text, $reg)) {
8010 $originalkeyfound = $reg[1];
8011 $keyfound = preg_replace(
'/\|urlencode$/',
'', $originalkeyfound);
8014 $value =
'*****forbidden*****';
8018 if (preg_match(
'/\|urlencode$/', $originalkeyfound)) {
8019 $value = urlencode($value);
8023 if (empty($converttextinhtmlifnecessary)) {
8025 $text = preg_replace(
'/__\[' . preg_quote($originalkeyfound,
'/') .
'\]__/', $msgishtml ?
dol_htmlentitiesbr($value) : $value, $text);
8027 if (preg_match(
'/__\[' . preg_quote($originalkeyfound,
'/') .
'\]__/', $text)) {
8039 $text = preg_replace(
'/__\[' . preg_quote($originalkeyfound,
'/') .
'\]__/', $value, $text);
8044 foreach ($substitutionarray as $key => $value) {
8045 if (!isset($value)) {
8049 if (
getDolGlobalString(
'MAIN_MAIL_DO_NOT_USE_SIGN') && ($key ==
'__USER_SIGNATURE__' || $key ==
'__SENDEREMAIL_SIGNATURE__')) {
8052 if (empty($converttextinhtmlifnecessary)) {
8053 $text = str_replace((
string) $key, (
string) $value, $text);
8055 if (strpos($text, (
string) $key) !==
false) {
8067 $text = str_replace((
string) $key, (
string) $value, $text);
8082 $memory_object_list = array();
8083 foreach ($substitutionarray as $key => $value) {
8084 $lazy_load_arr = array();
8085 if (preg_match(
'/(__[A-Z\_]+__)@lazyload$/', $key, $lazy_load_arr)) {
8086 if (!empty($lazy_load_arr[1])) {
8087 $key_to_substitute = $lazy_load_arr[1];
8088 if (preg_match(
'/' . preg_quote($key_to_substitute,
'/') .
'/', $text)) {
8089 $param_arr = explode(
':', (
string) $value);
8091 if (count($param_arr) >= 4) {
8092 $path = $param_arr[0];
8093 $class = $param_arr[1];
8094 $method = $param_arr[2];
8095 $id = (int) $param_arr[3];
8096 $keyinarrayresult = empty($param_arr[4]) ?
'' : $param_arr[4];
8099 if (!isset($memory_object_list[$class])) {
8101 require_once DOL_DOCUMENT_ROOT . $path;
8102 if (class_exists($class)) {
8103 $memory_object_list[$class] = array(
8111 if (isset($memory_object_list[$class][
'list'])) {
8112 if (method_exists($class, $method)) {
8113 if (!isset($memory_object_list[$class][
'list'][
$id])) {
8114 $tmpobj =
new $class($db);
8116 $tmpvaluetouseforsubstitution = $tmpobj->$method(
$id, $key_to_substitute);
8117 $memory_object_list[$class][
'list'][
$id] = $tmpobj;
8120 $tmpobj = $memory_object_list[$class][
'list'][
$id];
8122 $tmpvaluetouseforsubstitution = $tmpobj->$method(
$id, $key_to_substitute,
true);
8125 if ($keyinarrayresult) {
8126 $valuetouseforsubstitution = (string) $tmpvaluetouseforsubstitution[$keyinarrayresult];
8128 $valuetouseforsubstitution = (string) $tmpvaluetouseforsubstitution;
8130 $text = str_replace((
string) $key_to_substitute, $valuetouseforsubstitution, $text);
8156 global
$conf, $user;
8158 require_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
8163 $dirsubstitutions = array_merge(array(), (array)
$conf->modules_parts[
'substitutions']);
8165 foreach ($dirsubstitutions as $reldir) {
8173 $substitfiles =
dol_dir_list($dir,
'files', 0,
'functions_');
8174 foreach ($substitfiles as $substitfile) {
8176 if (preg_match(
'/functions_(.*)\.lib\.php/i', $substitfile[
'name'], $reg)) {
8179 dol_syslog(
"Library " . $substitfile[
'name'] .
" found into " . $dir);
8181 require_once $dir . $substitfile[
'name'];
8183 $function_name =
$module .
"_" . $callfunc;
8184 if (function_exists($function_name)) {
8185 $function_name($substitutionarray, $outputlangs,
$object, $parameters);
8193 foreach ($substitutionarray as $key => $value) {
8194 $tags .=
'{' . $key .
'} => ' . $value .
"\n";
8196 $substitutionarray = array_merge($substitutionarray, array(
'__ALL_TAGS__' => $tags));
8230 if (!is_object($outputlangs)) {
8231 $outputlangs = $langs;
8235 $out .= ($withparenthesis ? ($withparenthesis == 1 ?
' ' :
'').
'(' :
'') . $outputlangs->transnoentitiesnoconv(
'DateFromTo',
dol_print_date(
$date_start, $format, false, $outputlangs),
dol_print_date($date_end, $format, false, $outputlangs)) . ($withparenthesis ?
')' :
'');
8238 $out .= ($withparenthesis ? ($withparenthesis == 1 ?
' ' :
'').
'(' :
'') . $outputlangs->transnoentitiesnoconv(
'DateFrom',
dol_print_date(
$date_start, $format, false, $outputlangs)) . ($withparenthesis ?
')' :
'');
8241 $out .= ($withparenthesis ? ($withparenthesis == 1 ?
' ' :
'').
'(' :
'') . $outputlangs->transnoentitiesnoconv(
'DateUntil',
dol_print_date($date_end, $format, false, $outputlangs)) . ($withparenthesis ?
')' :
'');
8259 if ($nameorder < 0) {
8262 if ($nameorder == 1) {
8264 if ($firstname && $lastname) {
8268 } elseif ($nameorder == 2 || $nameorder == 3) {
8270 if (empty($ret) && $nameorder == 3) {
8275 if (empty($ret) && $nameorder == 5) {
8278 if ($nameorder == 0) {
8279 if ($firstname && $lastname) {
8299 return $arraytosort;
8323function dol_sort_array(&$array, $index, $order =
'asc', $natsort = 0, $case_sensitive = 0, $keepindex = 0)
8326 $order = strtolower($order);
8328 if (is_array($array)) {
8329 $sizearray = count($array);
8330 if ($sizearray > 0) {
8333 foreach (array_keys($array) as $key) {
8334 $tmpmultikey = explode(
',', $index);
8335 $newindex = $tmpmultikey[0];
8336 if (is_object($array[$key])) {
8337 $temp[$key] = empty($array[$key]->$newindex) ? 0 : $array[$key]->$newindex;
8339 if (!empty($tmpmultikey[1])) {
8340 $newindex = $tmpmultikey[1];
8341 $temp[$key] .=
'__' . (empty($array[$key]->$newindex) ? 0 : $array[$key]->$newindex);
8345 $temp[$key] = empty($array[$key][$newindex]) ? 0 : $array[$key][$newindex];
8347 if (!empty($tmpmultikey[1])) {
8348 $newindex = $tmpmultikey[1];
8350 $temp[$key] .=
'__' . (empty($array[$key][$newindex]) ? 0 : $array[$key][$newindex]);
8353 if ($natsort == -1) {
8354 $temp[$key] =
'___' . $temp[$key];
8357 if (empty($natsort) || $natsort == -1) {
8358 if ($order ==
'asc') {
8364 if ($case_sensitive) {
8369 if ($order !=
'asc') {
8370 $temp = array_reverse($temp,
true);
8376 foreach (array_keys($temp) as $key) {
8377 (is_numeric($key) && empty($keepindex)) ? $sorted[] = $array[$key] : $sorted[$key] = $array[$key];
8396 $str = (string) $str;
8399 $strLength = strlen($str);
8400 for ($i = 0; $i < $strLength; $i++) {
8401 if (ord($str[$i]) < 0x80) {
8403 } elseif ((ord($str[$i]) & 0xE0) == 0xC0) {
8405 } elseif ((ord($str[$i]) & 0xF0) == 0xE0) {
8407 } elseif ((ord($str[$i]) & 0xF8) == 0xF0) {
8409 } elseif ((ord($str[$i]) & 0xFC) == 0xF8) {
8411 } elseif ((ord($str[$i]) & 0xFE) == 0xFC) {
8416 for ($j = 0; $j < $n; $j++) {
8417 if ((++$i == strlen($str)) || ((ord($str[$i]) & 0xC0) != 0x80)) {
8438 return preg_match(
'//u', $str) ? true :
false;
8450 if (function_exists(
'mb_check_encoding')) {
8452 if (!mb_check_encoding($str,
'ASCII')) {
8456 if (preg_match(
'/[^\x00-\x7f]/', $str)) {
8474 $tmp = ini_get(
"unicode.filesystem_encoding");
8475 if (empty($tmp) && !empty($_SERVER[
"WINDIR"])) {
8476 $tmp =
'iso-8859-1';
8485 if ($tmp ==
'iso-8859-1') {
8486 return mb_convert_encoding($str,
'ISO-8859-1',
'UTF-8');
8507function dol_getIdFromCode($db, $key, $tablename, $fieldkey =
'code', $fieldid =
'id', $entityfilter = 0, $filters =
'', $useCache =
true)
8517 if ($useCache && isset(
$conf->cache[
'codeid'][$tablename][$key][$fieldid])) {
8518 return $conf->cache[
'codeid'][$tablename][$key][$fieldid];
8521 dol_syslog(
'dol_getIdFromCode (value for field ' . $fieldid .
' from key ' . $key .
' not found into cache)', LOG_DEBUG);
8523 $sql =
"SELECT " . $db->sanitize($fieldid) .
" as valuetoget";
8524 $sql .=
" FROM " . MAIN_DB_PREFIX . $db->sanitize($tablename);
8525 if ($fieldkey ==
'id' || $fieldkey ==
'rowid') {
8526 $sql .=
" WHERE " . $db->sanitize($fieldkey) .
" = " . ((int) $key);
8528 $sql .=
" WHERE " . $db->sanitize($fieldkey) .
" = '" . $db->escape($key) .
"'";
8530 if (!empty($entityfilter)) {
8531 $sql .=
" AND entity IN (" .
getEntity($tablename) .
")";
8537 $resql = $db->query($sql);
8539 $obj = $db->fetch_object($resql);
8542 $valuetoget = $obj->valuetoget;
8543 $conf->cache[
'codeid'][$tablename][$key][$fieldid] = $valuetoget;
8545 $conf->cache[
'codeid'][$tablename][$key][$fieldid] =
'';
8569 $regextext = preg_replace(
'#^/\^?#',
'', (
string) $regextext);
8570 $regextext = preg_replace(
'#\$?/[imsxuADSUXJ]*$#',
'', $regextext);
8572 if ($matchrule == 1) {
8573 if ($var ==
'mainmenu') {
8575 return (preg_match(
'/^' . $regextext .
'/', $mainmenu));
8576 } elseif ($var ==
'leftmenu') {
8578 return (preg_match(
'/^' . $regextext .
'/', $leftmenu));
8580 return 'This variable is not accessible with dol_eval';
8583 return 'This value '.$matchrule.
' for param $matchrule is not yet implemented';
8602 global
$conf, $user, $leftmenu, $mainmenu;
8604 $s = trim((
string) $s);
8605 if ($s ===
'1' || $s ===
'true') {
8608 if ($s ===
'0' || $s ===
'false') {
8612 if (!preg_match(
'/^[a-zA-Z0-9_$>=!&|\s\'",()-]+$/', $s)) {
8615 if (strpbrk($s,
'()') !==
false && !preg_match(
'/^(?:[^()]*\((?:\s*[\'"][a-zA-Z0-9_]+[\'"]\s*)(?:,\s*[\'"][a-zA-Z0-9_]+[\'"]\s*)*\))*[^()]*$/', $s)) {
8618 $hasand = (strpos($s,
'&&') !==
false);
8619 $hasor = (strpos($s,
'||') !==
false);
8620 if ($hasand && $hasor) {
8623 $terms = ($hasor ? explode(
'||', $s) : ($hasand ? explode(
'&&', $s) : array($s)));
8626 foreach ($terms as $term) {
8627 $term = trim($term);
8629 if (substr($term, 0, 1) ===
'!') {
8631 $term = ltrim(substr($term, 1));
8634 if (preg_match(
'/^isModEnabled\(\s*[\'"]([a-zA-Z0-9_]+)[\'"]\s*\)$/', $term, $reg)) {
8636 } elseif (preg_match(
'/^\$user->hasRight\(\s*[\'"]([a-zA-Z0-9_]+)[\'"]\s*,\s*[\'"]([a-zA-Z0-9_]+)[\'"]\s*(?:,\s*[\'"]([a-zA-Z0-9_]+)[\'"]\s*)?\)$/', $term, $reg)) {
8637 $value = (bool) (!empty($reg[3]) ? $user->hasRight($reg[1], $reg[2], $reg[3]) : $user->hasRight($reg[1], $reg[2]));
8638 } elseif (preg_match(
'/^\$user->rights->([a-zA-Z0-9_]+)->([a-zA-Z0-9_]+)(?:->([a-zA-Z0-9_]+))?$/', $term, $reg)) {
8639 if (!empty($reg[3])) {
8640 $value = !empty($user->rights->{$reg[1]}->{$reg[2]}->{$reg[3]});
8642 $value = !empty($user->rights->{$reg[1]}->{$reg[2]});
8644 } elseif ($term ===
'$user->admin') {
8645 $value = !empty($user->admin);
8646 } elseif (preg_match(
'/^\$conf->([a-zA-Z0-9_]+)->enabled$/', $term, $reg)) {
8647 $value = !empty(
$conf->{$reg[1]}->enabled);
8648 } elseif (preg_match(
'/^getDolGlobal(String|Int)\(\s*[\'"]([a-zA-Z0-9_]+)[\'"]\s*\)$/', $term, $reg)) {
8650 } elseif (preg_match(
'/^\$(leftmenu|mainmenu)\s*(==|!=)\s*[\'"]([a-zA-Z0-9_]*)[\'"]$/', $term, $reg)) {
8651 $current = ($reg[1] ==
'leftmenu' ? $leftmenu : $mainmenu);
8652 $value = ($reg[2] ==
'==' ? ($current == $reg[3]) : ($current != $reg[3]));
8653 } elseif ($term ===
'1' || $term ===
'true') {
8655 } elseif ($term ===
'0' || $term ===
'false') {
8663 if ($result ===
null) {
8666 $result = ($result || $value);
8668 $result = ($result && $value);
8684function verifCond($strToEvaluate, $onlysimplestring =
'1')
8688 if (isset($strToEvaluate) && $strToEvaluate !==
'') {
8692 if ($rights !==
null) {
8697 $rep =
dol_eval($strToEvaluate, 1, 1, $onlysimplestring);
8701 $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));
8722function dol_eval($s, $returnvalue = 1, $hideerrors = 1, $onlysimplestring =
'1')
8724 if ($returnvalue != 1) {
8725 dol_syslog(
"Use of dol_eval with parameter returnvalue = 0 is now forbidden. Please fix this", LOG_ERR);
8728 global $dolibarr_main_use_dol_eval_new;
8729 if (!empty($dolibarr_main_use_dol_eval_new)) {
8750 $db, $langs, $user, $website, $websitepage,
8751 $action, $mainmenu, $leftmenu,
8763 defined(
'T_COALESCE_EQUAL') || define(
'T_COALESCE_EQUAL', PHP_INT_MAX);
8764 defined(
'T_FN') || define(
'T_FN', PHP_INT_MAX);
8767 defined(
'T_ATTRIBUTE') || define(
'T_ATTRIBUTE', PHP_INT_MAX);
8768 defined(
'T_MATCH') || define(
'T_MATCH', PHP_INT_MAX);
8769 defined(
'T_NAME_FULLY_QUALIFIED') || define(
'T_NAME_FULLY_QUALIFIED', PHP_INT_MAX);
8770 defined(
'T_NAME_QUALIFIED') || define(
'T_NAME_QUALIFIED', PHP_INT_MAX);
8771 defined(
'T_NAME_RELATIVE') || define(
'T_NAME_RELATIVE', PHP_INT_MAX);
8774 defined(
'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG') || define(
'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG', PHP_INT_MAX);
8775 defined(
'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG') || define(
'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG', PHP_INT_MAX);
8776 defined(
'T_ENUM') || define(
'T_ENUM', PHP_INT_MAX);
8777 defined(
'T_READONLY') || define(
'T_READONLY', PHP_INT_MAX);
8780 defined(
'T_PRIVATE_SET') || define(
'T_PRIVATE_SET', PHP_INT_MAX);
8781 defined(
'T_PROTECTED_SET') || define(
'T_PROTECTED_SET', PHP_INT_MAX);
8782 defined(
'T_PUBLIC_SET') || define(
'T_PUBLIC_SET', PHP_INT_MAX);
8784 $prohibited_token_ids = [
8791 'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG',
8792 'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG',
8842 'T_OPEN_TAG_WITH_ECHO',
8876 $prohibited_variables = [
8888 $forbiddenphpfunctions = array();
8889 $forbiddenphpmethods = array();
8892 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"override_function",
"session_id",
"session_create_id",
"session_regenerate_id"));
8893 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"get_defined_functions",
"get_defined_vars",
"get_defined_constants",
"get_declared_classes"));
8894 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"function"));
8896 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"GETPOST"));
8898 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"ob_start"));
8901 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"call_user_func",
"call_user_func_array"));
8902 $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"));
8903 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"usort",
"uasort",
"uksort"));
8904 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"preg_replace_callback",
"preg_replace_callback_array",
"header_register_callback"));
8905 $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"));
8906 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"spl_autoload_register",
"spl_autoload_unregister",
"iterator_apply",
"session_set_save_handler"));
8907 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"forward_static_call",
"forward_static_call_array",
"register_postsend_function"));
8908 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"readline_completion_function",
"readline_callback_handler_install"));
8911 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"exec",
"passthru",
"shell_exec",
"system",
"proc_open",
"popen"));
8912 $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"));
8913 $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", ));
8914 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"putenv",
"dl",
"apache_child_terminate",
"apache_setenv"));
8915 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_eval",
"dol_eval_new",
"dol_eval_standard",
"executeCLI",
"verifCond",
"dolEncrypt",
"dolDecrypt"));
8916 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"eval",
"create_function",
"assert",
"mb_ereg_replace"));
8919 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"require",
"include",
"require_once",
"include_once"));
8921 $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"));
8922 $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"));
8926 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"base64" .
"_" .
"decode",
"rawurl" .
"decode",
"url" .
"decode",
"str" .
"_rot13",
"hex" .
"2bin",
"printf",
"sprintf"));
8927 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_concat",
"dol_concatdesc"));
8930 $forbiddenphpmethods = array_merge($forbiddenphpmethods, array(
'invoke',
'invokeArgs'));
8932 $prohibited_functions = array_merge($forbiddenphpfunctions, $forbiddenphpmethods);
8934 $prohibited_token_arrangements = [
8939 ' T_CONSTANT_ENCAPSED_STRING ( ',
8943 $tokens = token_get_all(
"<?php return {$s};", TOKEN_PARSE);
8945 $tokens_arrangement =
' ';
8947 for ($i = 2,
$c = count($tokens) - 1; $i <
$c; ++$i) {
8948 if (is_array($tokens[$i])) {
8949 $token_id = $tokens[$i][0];
8950 $token_value = $tokens[$i][1];
8951 $token_name = token_name($tokens[$i][0]);
8953 $token_id = $tokens[$i];
8954 $token_value = $tokens[$i];
8955 $token_name = $tokens[$i];
8959 if (T_WHITESPACE === $token_id) {
8964 $tokens_arrangement .=
"{$token_name} ";
8968 T_VARIABLE === $token_id
8969 && in_array($token_value, $prohibited_variables,
true)
8971 return "Bad string syntax to evaluate. « {$token_value} » is prohibited in « {$s} »";
8976 T_STRING === $token_id
8977 && in_array($token_value, $prohibited_functions,
true)
8979 return "Bad string syntax to evaluate. « {$token_value} » is prohibited in « {$s} »";
8984 $maxi = count($prohibited_token_ids);
8985 for ($i = 0; $i < $maxi; ++$i) {
8986 if (
false !== strpos($tokens_arrangement,
" {$prohibited_token_ids[$i]} ")) {
8987 return "Bad string syntax to evaluate. « {$prohibited_token_ids[$i]} » is prohibited in « {$s} »";
8992 $maxi = count($prohibited_token_arrangements);
8993 for ($i = 0; $i < $maxi; ++$i) {
8994 if (
false !== strpos($tokens_arrangement, $prohibited_token_arrangements[$i])) {
8995 return "Bad string syntax to evaluate. « {$prohibited_token_arrangements[$i]} » is prohibited in « {$s} »";
9001 return @eval(
"return {$s};") ??
'';
9002 }
catch (Throwable $ex) {
9003 return "Bad string syntax to evaluate. Exception during evaluation: " . $s .
" - " . $ex->getMessage();
9027 global $db, $langs, $user, $website, $websitepage;
9028 global $action, $mainmenu, $leftmenu;
9030 global $objectoffield;
9038 $isObBufferActive =
false;
9039 if ($onlysimplestring ==
'0') {
9040 $onlysimplestring =
'1';
9042 if (!in_array($onlysimplestring, array(
'1',
'2'))) {
9043 return "Bad call of dol_eval. Parameter onlysimplestring must be '1' or '2'.";
9045 if (!is_scalar($s)) {
9046 return "Bad call of dol_eval. First parameter must be a string, found ".var_export($s,
true);
9050 global $dolibarr_main_restrict_eval_methods;
9053 if (!isset($dolibarr_main_restrict_eval_methods)) {
9054 $dolibarr_main_restrict_eval_methods =
'getDolGlobalString, getDolGlobalInt, getDolCurrency, getDolEntity, getDolDBType, fetchNoCompute, hasRight, isAdmin, isExternalUser, isModEnabled, isStringVarMatching, abs, min, max, round, dol_now, preg_match';
9057 $dolibarr_main_restrict_eval_methods_array = explode(
',', str_replace(
" ",
"", $dolibarr_main_restrict_eval_methods));
9065 $specialcharsallowed =
'^$_+-.*>&|=!?():"\',/@';
9066 if ($onlysimplestring ==
'2') {
9067 $specialcharsallowed .=
'<[]';
9069 global $dolibarr_main_allow_unsecured_special_chars_in_dol_eval;
9070 if (!empty($dolibarr_main_allow_unsecured_special_chars_in_dol_eval)) {
9071 $specialcharsallowed .= (string) $dolibarr_main_allow_unsecured_special_chars_in_dol_eval;
9073 if (preg_match(
'/[^a-z0-9\s' . preg_quote($specialcharsallowed,
'/') .
']/i', $s)) {
9074 return 'Bad string syntax to evaluate (found chars that are not chars for a simple one line clean eval string): ' . $s;
9086 if (strpos($s,
'/*') !==
false || strpos($s,
'//') !==
false) {
9087 return 'Bad string syntax to evaluate (The comment string /* and // are not allowed): ' . $s;
9091 $tmps = str_replace(
' ? ',
'__XXX__', $s);
9092 if (strpos($tmps,
'?') !==
false) {
9093 return 'Bad string syntax to evaluate (The char ? can be used only with a space before and after): ' . $s;
9097 if (preg_match(
'/<=?[^\s]/', $s)) {
9098 return 'Bad string syntax to evaluate (mode ' . $onlysimplestring .
', found a < or <= without space after): ' . $s;
9102 if (preg_match(
'/(include|include_once|require|require_once)/', $s)) {
9103 return 'Bad string syntax to evaluate (found not allowed key include|include_once|require|require_once): ' . $s;
9107 if (preg_match(
'/\$[\w]*\s*\(/', $s)) {
9108 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;
9111 if (empty($dolibarr_main_restrict_eval_methods)) {
9117 while ($scheck && $savescheck != $scheck) {
9118 $savescheck = $scheck;
9119 $scheck = preg_replace(
'/->[a-zA-Z0-9_]+\(/',
'->__METHOD__', $scheck);
9120 $scheck = preg_replace(
'/::[a-zA-Z0-9_]+\(/',
'->__METHOD__', $scheck);
9121 $scheck = preg_replace(
'/^\(+/',
'__PARENTHESIS__ ', $scheck);
9122 $scheck = preg_replace(
'/\&\&\s+\(/',
'__ANDPARENTHESIS__ ', $scheck);
9123 $scheck = preg_replace(
'/\|\|\s+\(/',
'__ORPARENTHESIS__ ', $scheck);
9124 $scheck = preg_replace(
'/^!?[a-zA-Z0-9_]+\(/',
'__FUNCTION__', $scheck);
9125 $scheck = preg_replace(
'/\s!?[a-zA-Z0-9_]+\(/',
'__FUNCTION__', $scheck);
9126 $scheck = preg_replace(
'/^!\(/',
'__NOTANDPARENTHESIS__', $scheck);
9127 $scheck = preg_replace(
'/\s!\(/',
' __NOTANDPARENTHESIS__', $scheck);
9128 $scheck = preg_replace(
'/(\^|\')\(/',
'__REGEXSTART__', $scheck);
9133 if (strpos($scheck,
'(') !==
false) {
9134 return 'Bad string syntax to evaluate (mode ' . $onlysimplestring .
', found call of a function or method without using the direct name of the function): ' . $s;
9138 if (strpos($s,
'`') !==
false) {
9139 return 'Bad string syntax to evaluate (backtick char is forbidden): ' . $s;
9144 if (preg_match(
'/[^0-9]+\.[^0-9]+/', $s)) {
9145 return 'Bad string syntax to evaluate (dot char is forbidden if not strictly between 2 numbers): ' . $s;
9153 while ($scheck && $savescheck != $scheck) {
9154 $savescheck = $scheck;
9155 $scheck = preg_replace(
'/\$conf->[a-z\_]+->enabled/',
'__VARCONFENABLED__', $scheck);
9156 $scheck = preg_replace(
'/\$user->id/',
'__VARUSERID__', $scheck);
9157 $scheck = preg_replace(
'/\$user->hasRight/',
'__VARUSERHASRIGHT__', $scheck);
9158 $scheck = preg_replace(
'/\$user->rights/',
'__VARUSERHASRIGHT__', $scheck);
9159 $scheck = preg_replace(
'/\$user->isAdmin/',
'__VARUSERHASRIGHT__', $scheck);
9160 $scheck = preg_replace(
'/\$user->admin/',
'__VARUSERISADMIN__', $scheck);
9161 $scheck = preg_replace(
'/\$user->isExternalUser/',
'__VARUSERSOCID__', $scheck);
9162 $scheck = preg_replace(
'/\$user->socid/',
'__VARUSERSOCID__', $scheck);
9163 $scheck = preg_replace(
'/\(\$db\)/',
'__VARDB__', $scheck);
9164 $scheck = preg_replace(
'/\$langs/',
'__VARLANGSTRANS__', $scheck);
9165 $scheck = preg_replace(
'/\$mysoc/',
'__VARMYSOC__', $scheck);
9166 $scheck = preg_replace(
'/\$action/',
'__VARACTION__', $scheck);
9167 $scheck = preg_replace(
'/\$mainmenu/',
'__VARMAINMENU__', $scheck);
9168 $scheck = preg_replace(
'/\$leftmenu/',
'__VARLEFTMENU__', $scheck);
9169 $scheck = preg_replace(
'/\$websitepage/',
'__VARWEBSITEPAGE__', $scheck);
9170 $scheck = preg_replace(
'/\$website/',
'__VARWEBSITE__', $scheck);
9171 $scheck = preg_replace(
'/\$objectoffield/',
'__VAROBJECTOFFIELD__', $scheck);
9172 $scheck = preg_replace(
'/\$object/',
'__VAROBJECT__', $scheck);
9173 $scheck = preg_replace(
'/\$var/',
'__VARVAR__', $scheck);
9176 $scheck = preg_replace(
'/\$soc->canvas/',
'__VARSOCCANVAS__', $scheck);
9177 $scheck = preg_replace(
'/\$obj->canvas/',
'__VAROBJCANVAS__', $scheck);
9180 if (strpos($scheck,
'$') !==
false) {
9181 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);
9182 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;
9187 $forbiddenphpstrings = array(
'_ENV',
'_SESSION',
'_COOKIE',
'_GET',
'_GLOBAL',
'_POST',
'_REQUEST',
'ReflectionFunction',
'SplFileObject',
'SplTempFileObject');
9189 if (empty($dolibarr_main_restrict_eval_methods)) {
9193 $forbiddenphpfunctions = array();
9194 $forbiddenphpmethods = array();
9196 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"override_function",
"session_id",
"session_create_id",
"session_regenerate_id"));
9197 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"get_defined_functions",
"get_defined_vars",
"get_defined_constants",
"get_declared_classes"));
9198 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"function"));
9200 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"GETPOST"));
9202 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"ob_start"));
9205 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"call_user_func",
"call_user_func_array"));
9206 $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"));
9207 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"usort",
"uasort",
"uksort"));
9208 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"preg_replace_callback",
"preg_replace_callback_array",
"header_register_callback"));
9209 $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"));
9210 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"spl_autoload_register",
"spl_autoload_unregister",
"iterator_apply",
"session_set_save_handler"));
9211 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"forward_static_call",
"forward_static_call_array",
"register_postsend_function"));
9212 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"readline_completion_function",
"readline_callback_handler_install"));
9215 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"exec",
"passthru",
"shell_exec",
"system",
"proc_open",
"popen"));
9216 $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"));
9217 $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", ));
9218 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"putenv",
"dl",
"apache_child_terminate",
"apache_setenv"));
9219 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_eval",
"dol_eval_new",
"dol_eval_standard",
"executeCLI",
"verifCond",
"dolEncrypt",
"dolDecrypt"));
9220 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"eval",
"create_function",
"assert",
"mb_ereg_replace"));
9223 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"require",
"include",
"require_once",
"include_once"));
9225 $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"));
9226 $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"));
9230 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"base64" .
"_" .
"decode",
"rawurl" .
"decode",
"url" .
"decode",
"str" .
"_rot13",
"hex" .
"2bin",
"printf",
"sprintf"));
9231 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_concat",
"dol_concatdesc"));
9240 $forbiddenphpmethods = array_merge($forbiddenphpmethods, array(
'invoke',
'invokeArgs'));
9248 $forbiddenphpregex =
'global\s*\$';
9249 $forbiddenphpregex .=
'|posix_[a-zA-Z0-9_]*|';
9250 $forbiddenphpregex .=
'\b(' . implode(
'|', $forbiddenphpfunctions) .
')\b';
9252 $forbiddenphpmethodsregex =
'->(' . implode(
'|', $forbiddenphpmethods) .
')';
9256 $oldstringtoclean = $s;
9257 $s = str_ireplace($forbiddenphpstrings,
'__forbiddenstring__', $s);
9258 $s = preg_replace(
'/' . $forbiddenphpregex .
'/i',
'__forbiddenstring__', $s);
9259 $s = preg_replace(
'/' . $forbiddenphpmethodsregex .
'/i',
'__forbiddenstring__', $s);
9261 }
while ($oldstringtoclean != $s);
9263 if (strpos($s,
'__forbiddenstring__') !==
false) {
9264 dol_syslog(
'Bad string syntax to evaluate: ' . $s, LOG_WARNING);
9265 return 'Bad string syntax to evaluate: ' . $s;
9269 if (!empty($dolibarr_main_restrict_eval_methods)) {
9272 $pattern =
'/([\s\w\'\]\"]+)\(/';
9275 preg_match_all($pattern, $s, $matches);
9277 if (count($matches)) {
9278 foreach ($matches[1] as $m) {
9284 if (!preg_match(
'/new ([A-Z][\w]+)/i', $m, $reg)) {
9285 if (!in_array($m, $dolibarr_main_restrict_eval_methods_array)) {
9286 if ($m !=
"'" && $m !=
'"') {
9287 dol_syslog(
'Bad string syntax to evaluate: ' . $s, LOG_WARNING);
9288 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;
9292 if (!class_exists($reg[1])) {
9293 dol_syslog(
'Bad string syntax to evaluate: Class "'.$reg[1].
'" does not exist. ' . $s, LOG_WARNING);
9294 return 'Bad string syntax to evaluate. Class "'.$reg[1].
'" does not exist. ' . $s;
9296 $parents = class_parents($reg[1]);
9297 if (!in_array(
'CommonObject', $parents)) {
9298 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);
9299 return 'Bad string syntax to evaluate. Class "'.$reg[1].
'" is not allowed because only classes extended CommonObject can be used in dynamic evaluation. ' . $s;
9305 $forbiddenphpregex =
'global\s*\$';
9306 $forbiddenphpregex .=
'|';
9307 $forbiddenphpregex .=
'}\s*\[';
9308 $forbiddenphpregex .=
'|';
9309 $forbiddenphpregex .=
'\)\s*\(';
9313 $oldstringtoclean = $s;
9314 $s = str_ireplace($forbiddenphpstrings,
'__forbiddenstring__', $s);
9315 $s = preg_replace(
'/' . $forbiddenphpregex .
'/i',
'__forbiddenstring__', $s);
9318 }
while ($oldstringtoclean != $s);
9320 if (strpos($s,
'__forbiddenstring__') !==
false) {
9321 dol_syslog(
'Bad string syntax to evaluate: ' . $s, LOG_WARNING);
9322 return 'Bad string syntax to evaluate: ' . $s;
9328 $isObBufferActive =
true;
9329 $tmps = $hideerrors ? @eval(
'return ' . $s .
';') : eval(
'return ' . $s .
';');
9330 $tmpo = ob_get_clean();
9331 $isObBufferActive =
false;
9333 print
'Bad string syntax to evaluate. Some data were output when it should not when evaluating: ' . $s;
9337 if ($isObBufferActive) {
9339 $tmpo = ob_get_clean();
9340 $isObBufferActive =
false;
9342 $error =
'dol_eval try/catch error for string: ' . $s .
' - Error: ';
9343 $error .= $e->getMessage();
9345 return 'Exception during evaluation: ' . $s;
9346 }
catch (Error $e) {
9347 if ($isObBufferActive) {
9349 $tmpo = ob_get_clean();
9350 $isObBufferActive =
false;
9352 $error =
'dol_eval try/catch error for string: ' . $s .
' - Error: ';
9353 $error .= $e->getMessage();
9355 return 'Exception during evaluation: ' . $s;
9368 return (trim($element) !=
'');
9383 if (empty($countrycode)) {
9387 if (strtoupper($countrycode) ==
'MQ') {
9390 if (strtoupper($countrycode) ==
'SE') {
9393 if (strtoupper($countrycode) ==
'CH') {
9394 if (
$mysoc->country_code ==
'FR') {
9397 if (
$mysoc->country_code ==
'DE') {
9400 if (
$mysoc->country_code ==
'IT') {
9582 $buildprimarykeytotest = strtolower($countrycode) .
'-' . strtoupper($countrycode);
9583 if (in_array($buildprimarykeytotest, $locales)) {
9584 return strtolower($countrycode) .
'_' . strtoupper($countrycode);
9587 if (function_exists(
'locale_get_primary_language') && function_exists(
'locale_get_region')) {
9588 foreach ($locales as $locale) {
9589 $locale_language = locale_get_primary_language($locale);
9590 $locale_region = locale_get_region($locale);
9591 if (strtoupper($countrycode) == $locale_region) {
9593 return strtolower($locale_language) .
'_' . strtoupper($locale_region);
9597 dol_syslog(
"Warning Extension php-intl is not available", LOG_WARNING);
9635 global $hookmanager, $db;
9637 if (isset(
$conf->modules_parts[
'tabs'][$type]) && is_array(
$conf->modules_parts[
'tabs'][$type])) {
9638 foreach (
$conf->modules_parts[
'tabs'][$type] as $value) {
9639 $values = explode(
':', $value);
9642 if ($mode ==
'add' && !preg_match(
'/^\-/', $values[1])) {
9643 if (count($values) !== 6) {
9644 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);
9651 if ($values[0] != $type) {
9659 $posstart = strpos($str,
'(');
9660 if ($posstart > 0) {
9661 $posend = strpos($str,
')');
9662 if ($posstart > 0) {
9663 $res1 = substr($str, $posstart + 1, $posend - $posstart - 1);
9664 if (is_numeric($res1)) {
9665 $postab = (int) $res1;
9666 $values[1] =
'+' . substr($str, $posend + 1);
9671 global $objectoffield;
9679 if ($filterorigmodule) {
9680 if (strpos($values[3],
'@')) {
9681 if ($filterorigmodule !=
'external') {
9685 if ($filterorigmodule !=
'core') {
9690 $langs->load($values[3]);
9693 if (preg_match(
'/SUBSTITUTION_([^_]+)/i', $values[2], $reg)) {
9695 $substitutionarray = array();
9700 $labeltemp = explode(
',', $values[2]);
9701 $label = $langs->trans($labeltemp[0]);
9703 if (!empty($labeltemp[1]) && is_object(
$object) && !empty(
$object->id)) {
9705 $classtoload = $labeltemp[1];
9706 if (class_exists($classtoload)) {
9707 $obj =
new $classtoload($db);
9708 $function = $labeltemp[3];
9709 if ($obj && $function && method_exists($obj, $function)) {
9711 $nbrec = $obj->$function(
$object->id, $obj);
9712 if (!empty($nbrec)) {
9713 $label .=
'<span class="badge marginleftonlyshort">' . $nbrec .
'</span>';
9719 $url = preg_replace(
'/__ID__/i', ((is_object(
$object) && !empty(
$object->id)) ?
$object->id :
''), $values[5]);
9720 $link = parse_url($url);
9722 if (isset($link[
'query'])) {
9723 parse_str($link[
'query'], $query);
9726 $newtab[1] = $label;
9727 $newtab[2] = str_replace(
'+',
'', $values[1]);
9731 $head = array_merge(array_slice($head, 0, $postab), array($newtab), array_slice($head, $postab));
9732 } elseif ($mode ==
'remove' && preg_match(
'/^\-/', $values[1])) {
9733 if ($values[0] != $type) {
9736 $tabname = str_replace(
'-',
'', $values[1]);
9737 foreach ($head as $key => $val) {
9738 $condition = (!empty($values[3]) ?
verifCond($values[3],
'2') : 1);
9740 if ($head[$key][2] == $tabname && $condition) {
9750 if (!empty($hookmanager)) {
9751 $parameters = array(
'object' =>
$object,
'mode' => $mode,
'head' => &$head,
'filterorigmodule' => $filterorigmodule,
'type' => $type);
9753 $reshook = $hookmanager->executeHooks(
'completeTabsHead', $parameters,
$object);
9755 $head = $hookmanager->resArray;
9757 $head = array_merge($head, $hookmanager->resArray);
9775 if (is_null($string)) {
9779 if (preg_match(
'/^\[.*\]$/sm', $delimiter) || preg_match(
'/^\(.*\)$/sm', $delimiter)) {
9781 $newdelimiter = $delimiter;
9785 $newdelimiter = preg_quote($delimiter,
'/');
9788 if ($a = preg_split(
'/' . $newdelimiter .
'/', $string)) {
9790 foreach ($a as $s) {
9792 if ($pos = strpos($s, $kv)) {
9793 $ka[trim(substr($s, 0, $pos))] = trim(substr($s, $pos + strlen($kv)));
9816 preg_match_all(
'/"([^"]*)"|\'([^\']*)\'|(\S+)/', $input, $matches);
9820 $result = array_map(
9827 static function ($a, $b,
$c) {
9843 return array_values(array_filter(
9851 static function ($val) {
9867 if (!function_exists(
'getmypid')) {
9868 return mt_rand(99900000, 99965535);
9896function natural_search($fields, $value, $mode = 0, $nofirstand = 0, $sqltoadd =
'')
9900 $value = trim($value);
9903 $value = preg_replace(
'/\*/',
'%', $value);
9906 $value = preg_replace(
'/([!<>=]+)\s+([0-9' . preg_quote($langs->trans(
"SeparatorDecimal"),
'/') .
'\-])/',
'\1\2', $value);
9909 $value = preg_replace(
'/\s*\|\s*/',
'|', $value);
9913 if ($mode != -3 && $mode != 3) {
9916 $crits = array($value);
9920 if (!is_array($fields)) {
9921 $fields = array($fields);
9924 foreach ($crits as $crit) {
9925 $crit = trim($crit);
9929 foreach ($fields as $field) {
9931 $tmpcrits = explode(
'|', $crit);
9933 foreach ($tmpcrits as $tmpcrit) {
9934 if ($tmpcrit !==
'0' && empty($tmpcrit)) {
9937 $tmpcrit = trim($tmpcrit);
9939 $newres .= (($i2 > 0 || $i3 > 0) ?
' OR ' :
'');
9942 $newcrit = preg_replace(
'/([!<>=]+)/',
'', $tmpcrit);
9945 preg_match(
'/([!<>=]+)/', $tmpcrit, $reg);
9946 if (!empty($reg[1])) {
9947 $operator = $reg[1];
9949 if ($newcrit !=
'') {
9951 if (is_numeric($numnewcrit)) {
9952 $newres .= $db->sanitize($field) .
' ' . $operator .
' ' . ((float) $numnewcrit);
9960 } elseif ($mode == 2 || $mode == -2) {
9961 $crit = preg_replace(
'/[^\-0-9,]/',
'', $crit);
9962 $newres .= ($i2 > 0 ?
' OR ' :
'') . $db->sanitize($field) .
" " . ($mode == -2 ?
'NOT ' :
'');
9963 $newres .= $crit ?
"IN (" . $db->sanitize($db->escape($crit)) .
")" :
"IN (0)";
9965 $newres .=
' OR ' . $db->sanitize($field) .
' IS NULL';
9968 } elseif ($mode == 3 || $mode == -3) {
9969 $tmparray = explode(
',', $crit);
9970 if (count($tmparray)) {
9972 $listofcodesnot =
'';
9973 foreach ($tmparray as $val) {
9976 if (preg_match(
'/^!/', $val)) {
9977 $listofcodesnot .= ($listofcodesnot ?
',' :
'');
9978 $listofcodesnot .=
"'" . $db->escape(preg_replace(
'/^!=?/',
'', $val)) .
"'";
9980 $listofcodes .= ($listofcodes ?
',' :
'');
9981 $listofcodes .=
"'" . $db->escape($val) .
"'";
9985 $newres .= ($i2 > 0 ?
' OR ' :
'');
9986 if ($listofcodes && $listofcodesnot) {
9990 $newres .= $db->sanitize($field) .
" " . ($mode == -3 ?
'NOT IN' :
'IN') .
" (" . $db->sanitize($listofcodes, 1, 0, 1) .
")";
9992 if ($listofcodes && $listofcodesnot) {
9995 if ($listofcodesnot) {
9996 $newres .= $db->sanitize($field) .
" " . ($mode == -3 ?
'IN ' :
'NOT IN') .
" (" . $db->sanitize($listofcodesnot, 1, 0, 1) .
")";
9998 if ($listofcodes && $listofcodesnot) {
10004 $newres .=
' OR ' . $db->sanitize($field) .
' IS NULL';
10006 } elseif ($mode == 4) {
10007 $tmparray = explode(
',', $crit);
10008 if (count($tmparray)) {
10010 foreach ($tmparray as $val) {
10013 $newres .= ($i2 > 0 ?
" OR (" :
"(") . $db->sanitize($field) .
" LIKE '" . $db->escape($val) .
",%'";
10014 $newres .=
' OR ' . $db->sanitize($field) .
" = '" . $db->escape($val) .
"'";
10015 $newres .=
' OR ' . $db->sanitize($field) .
" LIKE '%," . $db->escape($val) .
"'";
10016 $newres .=
' OR ' . $db->sanitize($field) .
" LIKE '%," . $db->escape($val) .
",%'";
10023 $tmpcrits = explode(
'|', $crit);
10025 foreach ($tmpcrits as $tmpcrit) {
10026 if ($tmpcrit !==
'0' && empty($tmpcrit)) {
10029 $tmpcrit = trim($tmpcrit);
10031 if ($tmpcrit ==
'^$' || strpos($crit,
'!') === 0) {
10032 $newres .= (($i2 > 0 || $i3 > 0) ?
' AND ' :
'');
10034 $newres .= (($i2 > 0 || $i3 > 0) ?
' OR ' :
'');
10037 $isSellist =
false;
10038 $table = $label = $key =
null;
10040 if (strpos($field,
'ef.') === 0) {
10041 $extrafieldName = substr($field, 3);
10043 $extrafields->fetch_name_optionals_label(
'product');
10045 if (isset($extrafields->attributes[
'product'][
'type'][$extrafieldName]) && $extrafields->attributes[
'product'][
'type'][$extrafieldName] ===
'sellist') {
10047 $paramArray = $extrafields->attributes[
'product'][
'param'][$extrafieldName][
'options'] ?? [];
10048 $param = array_key_first($paramArray);
10049 list($table, $label, $key) = explode(
':', $param);
10053 if (preg_match(
'/\.(id|rowid)$/', $field)) {
10054 $newres .= $db->sanitize($field) .
" = " . (is_numeric($tmpcrit) ? ((float) $tmpcrit) :
'0');
10056 $tmpcrit2 = $tmpcrit;
10061 if ($isSellist && $key && $table && $label) {
10062 $newres .= $field .
" IN (SELECT t." . $db->sanitize((
string) $key) .
" FROM " . $db->prefix() . $db->sanitize((
string) $table) .
" AS t WHERE t." . $db->sanitize((
string) $label) .
" LIKE '%" . $db->escape($tmpcrit2) .
"%')";
10064 if (preg_match(
'/^!/', $tmpcrit)) {
10065 $tmps .= $db->sanitize($field) .
" NOT LIKE ";
10066 $tmpcrit2 = preg_replace(
'/^!/',
'', $tmpcrit2);
10068 $tmps .= $db->sanitize($field) .
" LIKE ";
10072 if (preg_match(
'/^[\^\$]/', $tmpcrit)) {
10074 $tmpcrit2 = preg_replace(
'/^[\^\$]/',
'', $tmpcrit2);
10076 if (preg_match(
'/[\^\$]$/', $tmpcrit)) {
10078 $tmpcrit2 = preg_replace(
'/[\^\$]$/',
'', $tmpcrit2);
10081 if ($tmpcrit2 ==
'' || preg_match(
'/^!/', $tmpcrit)) {
10082 $tmps =
"(" . $tmps;
10085 $newres .= $tmpbefore;
10086 $newres .= $db->escape($tmpcrit2);
10087 $newres .= $tmpafter;
10089 if ($tmpcrit2 ==
'' || preg_match(
'/^!/', $tmpcrit)) {
10090 $newres .=
" OR " . $db->sanitize($field) .
" IS NULL)";
10103 $newres .= ($newres ?
'' :
' OR ').str_replace(
'__KEYTOSEARCH__', $db->escape($crit), $sqltoadd);
10107 $res = $res . ($res ?
' AND ' :
'') . ($i2 > 1 ?
'(' :
'') . $newres . ($i2 > 1 ?
')' :
'');
10111 $res = ($nofirstand ?
"" :
" AND ") .
"(" . $res .
")";
10127 $dirName = dirname($file);
10128 if ($dirName ==
'.') {
10132 if (!in_array($extName, array(
'',
'_small',
'_mini'))) {
10133 return 'Bad parameter extName';
10136 $fileName = preg_replace(
'/(\.gif|\.jpeg|\.jpg|\.png|\.bmp|\.webp|\.avif)$/i',
'', $file);
10137 $fileName = basename($fileName);
10139 if (empty($extImgTarget)) {
10140 $extImgTarget = (preg_match(
'/\.jpg$/i', $file) ?
'.jpg' :
'');
10142 if (empty($extImgTarget)) {
10143 $extImgTarget = (preg_match(
'/\.jpeg$/i', $file) ?
'.jpeg' :
'');
10145 if (empty($extImgTarget)) {
10146 $extImgTarget = (preg_match(
'/\.gif$/i', $file) ?
'.gif' :
'');
10148 if (empty($extImgTarget)) {
10149 $extImgTarget = (preg_match(
'/\.png$/i', $file) ?
'.png' :
'');
10151 if (empty($extImgTarget)) {
10152 $extImgTarget = (preg_match(
'/\.bmp$/i', $file) ?
'.bmp' :
'');
10154 if (empty($extImgTarget)) {
10155 $extImgTarget = (preg_match(
'/\.webp$/i', $file) ?
'.webp' :
'');
10157 if (empty($extImgTarget)) {
10158 $extImgTarget = (preg_match(
'/\.avif$/i', $file) ?
'.avif' :
'');
10161 if (!$extImgTarget) {
10167 $subdir =
'thumbs/';
10170 return ($dirName ? $dirName .
'/' :
'') . $subdir . $fileName . $extName . $extImgTarget;
10184 $arrayspecialines = array(1 =>
'Transport', 2 =>
'EcoTax', 3 =>
'Option');
10185 if ($idcode > 10) {
10186 return 'Module ID ' . $idcode;
10188 if (!empty($arrayspecialines[$idcode])) {
10189 return $langs->trans($arrayspecialines[$idcode]);
10205 if (preg_match(
'/\.noexe$/i', $file)) {
10210 $mime_preview = array(
'avif',
'bmp',
'jpeg',
'png',
'gif',
'tiff',
'pdf',
'plain',
'css',
'webp',
'webm',
'mp4');
10212 $mime_preview[] =
'svg+xml';
10215 $mime_preview[] =
'xml';
10220 $num_mime = array_search(
dol_mimetype($file,
'', 1), $mime_preview);
10221 if ($num_mime !==
false) {
10239function dol_mimetype($file, $default =
'application/octet-stream', $mode = 0)
10242 $imgmime =
'other.png';
10243 $famime =
'file-o';
10246 $tmpfile = preg_replace(
'/\.noexe$/',
'', $file);
10249 if (preg_match(
'/\.txt$/i', $tmpfile)) {
10250 $mime =
'text/plain';
10251 $imgmime =
'text.png';
10252 $famime =
'file-alt';
10253 } elseif (preg_match(
'/\.rtx$/i', $tmpfile)) {
10254 $mime =
'text/richtext';
10255 $imgmime =
'text.png';
10256 $famime =
'file-alt';
10257 } elseif (preg_match(
'/\.csv$/i', $tmpfile)) {
10258 $mime =
'text/csv';
10259 $imgmime =
'text.png';
10260 $famime =
'file-csv';
10261 } elseif (preg_match(
'/\.tsv$/i', $tmpfile)) {
10262 $mime =
'text/tab-separated-values';
10263 $imgmime =
'text.png';
10264 $famime =
'file-alt';
10265 } elseif (preg_match(
'/\.(cf|conf|log)$/i', $tmpfile)) {
10266 $mime =
'text/plain';
10267 $imgmime =
'text.png';
10268 $famime =
'file-alt';
10269 } elseif (preg_match(
'/\.ini$/i', $tmpfile)) {
10270 $mime =
'text/plain';
10271 $imgmime =
'text.png';
10273 $famime =
'file-alt';
10274 } elseif (preg_match(
'/\.md$/i', $tmpfile)) {
10275 $mime =
'text/plain';
10276 $imgmime =
'text.png';
10278 $famime =
'file-alt';
10279 } elseif (preg_match(
'/\.css$/i', $tmpfile)) {
10280 $mime =
'text/css';
10281 $imgmime =
'css.png';
10283 $famime =
'file-alt';
10284 } elseif (preg_match(
'/\.lang$/i', $tmpfile)) {
10285 $mime =
'text/plain';
10286 $imgmime =
'text.png';
10288 $famime =
'file-alt';
10289 } elseif (preg_match(
'/\.(crt|cer|key|pub)$/i', $tmpfile)) {
10290 $mime =
'text/plain';
10291 $imgmime =
'text.png';
10292 $famime =
'file-alt';
10293 } elseif (preg_match(
'/\.(html|htm|shtml)$/i', $tmpfile)) {
10294 $mime =
'text/html';
10295 $imgmime =
'html.png';
10297 $famime =
'file-alt';
10298 } elseif (preg_match(
'/\.(xml|xhtml)$/i', $tmpfile)) {
10299 $mime =
'text/xml';
10300 $imgmime =
'other.png';
10302 $famime =
'file-alt';
10303 } elseif (preg_match(
'/\.xaml$/i', $tmpfile)) {
10304 $mime =
'text/xml';
10305 $imgmime =
'other.png';
10307 $famime =
'file-alt';
10308 } elseif (preg_match(
'/\.bas$/i', $tmpfile)) {
10309 $mime =
'text/plain';
10310 $imgmime =
'text.png';
10312 $famime =
'file-code';
10313 } elseif (preg_match(
'/\.(c)$/i', $tmpfile)) {
10314 $mime =
'text/plain';
10315 $imgmime =
'text.png';
10317 $famime =
'file-code';
10318 } elseif (preg_match(
'/\.(cpp)$/i', $tmpfile)) {
10319 $mime =
'text/plain';
10320 $imgmime =
'text.png';
10322 $famime =
'file-code';
10323 } elseif (preg_match(
'/\.cs$/i', $tmpfile)) {
10324 $mime =
'text/plain';
10325 $imgmime =
'text.png';
10327 $famime =
'file-code';
10328 } elseif (preg_match(
'/\.(h)$/i', $tmpfile)) {
10329 $mime =
'text/plain';
10330 $imgmime =
'text.png';
10332 $famime =
'file-code';
10333 } elseif (preg_match(
'/\.(java|jsp)$/i', $tmpfile)) {
10334 $mime =
'text/plain';
10335 $imgmime =
'text.png';
10337 $famime =
'file-code';
10338 } elseif (preg_match(
'/\.php([0-9]{1})?$/i', $tmpfile)) {
10339 $mime =
'text/plain';
10340 $imgmime =
'php.png';
10342 $famime =
'file-code';
10343 } elseif (preg_match(
'/\.phtml$/i', $tmpfile)) {
10344 $mime =
'text/plain';
10345 $imgmime =
'php.png';
10347 $famime =
'file-code';
10348 } elseif (preg_match(
'/\.(pl|pm)$/i', $tmpfile)) {
10349 $mime =
'text/plain';
10350 $imgmime =
'pl.png';
10352 $famime =
'file-code';
10353 } elseif (preg_match(
'/\.sql$/i', $tmpfile)) {
10354 $mime =
'text/plain';
10355 $imgmime =
'text.png';
10357 $famime =
'file-code';
10358 } elseif (preg_match(
'/\.js$/i', $tmpfile)) {
10359 $mime =
'text/x-javascript';
10360 $imgmime =
'jscript.png';
10362 $famime =
'file-code';
10363 } elseif (preg_match(
'/\.odp$/i', $tmpfile)) {
10364 $mime =
'application/vnd.oasis.opendocument.presentation';
10365 $imgmime =
'ooffice.png';
10366 $famime =
'file-powerpoint';
10367 } elseif (preg_match(
'/\.ods$/i', $tmpfile)) {
10368 $mime =
'application/vnd.oasis.opendocument.spreadsheet';
10369 $imgmime =
'ooffice.png';
10370 $famime =
'file-excel';
10371 } elseif (preg_match(
'/\.odt$/i', $tmpfile)) {
10372 $mime =
'application/vnd.oasis.opendocument.text';
10373 $imgmime =
'ooffice.png';
10374 $famime =
'file-word';
10375 } elseif (preg_match(
'/\.mdb$/i', $tmpfile)) {
10376 $mime =
'application/msaccess';
10377 $imgmime =
'mdb.png';
10379 } elseif (preg_match(
'/\.doc[xm]?$/i', $tmpfile)) {
10380 $mime =
'application/msword';
10381 $imgmime =
'doc.png';
10382 $famime =
'file-word';
10383 } elseif (preg_match(
'/\.dot[xm]?$/i', $tmpfile)) {
10384 $mime =
'application/msword';
10385 $imgmime =
'doc.png';
10386 $famime =
'file-word';
10387 } elseif (preg_match(
'/\.xlt(x)?$/i', $tmpfile)) {
10388 $mime =
'application/vnd.ms-excel';
10389 $imgmime =
'xls.png';
10390 $famime =
'file-excel';
10391 } elseif (preg_match(
'/\.xla(m)?$/i', $tmpfile)) {
10392 $mime =
'application/vnd.ms-excel';
10393 $imgmime =
'xls.png';
10394 $famime =
'file-excel';
10395 } elseif (preg_match(
'/\.xls$/i', $tmpfile)) {
10396 $mime =
'application/vnd.ms-excel';
10397 $imgmime =
'xls.png';
10398 $famime =
'file-excel';
10399 } elseif (preg_match(
'/\.xls[bmx]$/i', $tmpfile)) {
10400 $mime =
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
10401 $imgmime =
'xls.png';
10402 $famime =
'file-excel';
10403 } elseif (preg_match(
'/\.pps[mx]?$/i', $tmpfile)) {
10404 $mime =
'application/vnd.ms-powerpoint';
10405 $imgmime =
'ppt.png';
10406 $famime =
'file-powerpoint';
10407 } elseif (preg_match(
'/\.ppt[mx]?$/i', $tmpfile)) {
10408 $mime =
'application/x-mspowerpoint';
10409 $imgmime =
'ppt.png';
10410 $famime =
'file-powerpoint';
10411 } elseif (preg_match(
'/\.pdf$/i', $tmpfile)) {
10412 $mime =
'application/pdf';
10413 $imgmime =
'pdf.png';
10414 $famime =
'file-pdf';
10415 } elseif (preg_match(
'/\.bat$/i', $tmpfile)) {
10416 $mime =
'text/x-bat';
10417 $imgmime =
'script.png';
10419 $famime =
'file-code';
10420 } elseif (preg_match(
'/\.sh$/i', $tmpfile)) {
10421 $mime =
'text/x-sh';
10422 $imgmime =
'script.png';
10424 $famime =
'file-code';
10425 } elseif (preg_match(
'/\.ksh$/i', $tmpfile)) {
10426 $mime =
'text/x-ksh';
10427 $imgmime =
'script.png';
10429 $famime =
'file-code';
10430 } elseif (preg_match(
'/\.bash$/i', $tmpfile)) {
10431 $mime =
'text/x-bash';
10432 $imgmime =
'script.png';
10434 $famime =
'file-code';
10435 } elseif (preg_match(
'/\.ico$/i', $tmpfile)) {
10436 $mime =
'image/x-icon';
10437 $imgmime =
'image.png';
10438 $famime =
'file-image';
10439 } elseif (preg_match(
'/\.(jpg|jpeg)$/i', $tmpfile)) {
10440 $mime =
'image/jpeg';
10441 $imgmime =
'image.png';
10442 $famime =
'file-image';
10443 } elseif (preg_match(
'/\.png$/i', $tmpfile)) {
10444 $mime =
'image/png';
10445 $imgmime =
'image.png';
10446 $famime =
'file-image';
10447 } elseif (preg_match(
'/\.gif$/i', $tmpfile)) {
10448 $mime =
'image/gif';
10449 $imgmime =
'image.png';
10450 $famime =
'file-image';
10451 } elseif (preg_match(
'/\.bmp$/i', $tmpfile)) {
10452 $mime =
'image/bmp';
10453 $imgmime =
'image.png';
10454 $famime =
'file-image';
10455 } elseif (preg_match(
'/\.(tif|tiff)$/i', $tmpfile)) {
10456 $mime =
'image/tiff';
10457 $imgmime =
'image.png';
10458 $famime =
'file-image';
10459 } elseif (preg_match(
'/\.svg$/i', $tmpfile)) {
10460 $mime =
'image/svg+xml';
10461 $imgmime =
'image.png';
10462 $famime =
'file-image';
10463 } elseif (preg_match(
'/\.webp$/i', $tmpfile)) {
10464 $mime =
'image/webp';
10465 $imgmime =
'image.png';
10466 $famime =
'file-image';
10467 } elseif (preg_match(
'/\.vcs$/i', $tmpfile)) {
10468 $mime =
'text/calendar';
10469 $imgmime =
'other.png';
10470 $famime =
'file-alt';
10471 } elseif (preg_match(
'/\.ics$/i', $tmpfile)) {
10472 $mime =
'text/calendar';
10473 $imgmime =
'other.png';
10474 $famime =
'file-alt';
10475 } elseif (preg_match(
'/\.torrent$/i', $tmpfile)) {
10476 $mime =
'application/x-bittorrent';
10477 $imgmime =
'other.png';
10478 $famime =
'file-o';
10479 } elseif (preg_match(
'/\.(mp3|ogg|au|wav|wma|mid)$/i', $tmpfile)) {
10481 $imgmime =
'audio.png';
10482 $famime =
'file-audio';
10483 } elseif (preg_match(
'/\.mp4$/i', $tmpfile)) {
10484 $mime =
'video/mp4';
10485 $imgmime =
'video.png';
10486 $famime =
'file-video';
10487 } elseif (preg_match(
'/\.ogv$/i', $tmpfile)) {
10488 $mime =
'video/ogg';
10489 $imgmime =
'video.png';
10490 $famime =
'file-video';
10491 } elseif (preg_match(
'/\.webm$/i', $tmpfile)) {
10492 $mime =
'video/webm';
10493 $imgmime =
'video.png';
10494 $famime =
'file-video';
10495 } elseif (preg_match(
'/\.avif$/i', $tmpfile)) {
10496 $mime =
'image/avif';
10497 $imgmime =
'image.png';
10498 $famime =
'file-image';
10499 } elseif (preg_match(
'/\.avi$/i', $tmpfile)) {
10500 $mime =
'video/x-msvideo';
10501 $imgmime =
'video.png';
10502 $famime =
'file-video';
10503 } elseif (preg_match(
'/\.divx$/i', $tmpfile)) {
10504 $mime =
'video/divx';
10505 $imgmime =
'video.png';
10506 $famime =
'file-video';
10507 } elseif (preg_match(
'/\.xvid$/i', $tmpfile)) {
10508 $mime =
'video/xvid';
10509 $imgmime =
'video.png';
10510 $famime =
'file-video';
10511 } elseif (preg_match(
'/\.(wmv|mpg|mpeg)$/i', $tmpfile)) {
10513 $imgmime =
'video.png';
10514 $famime =
'file-video';
10515 } elseif (preg_match(
'/\.(zip|rar|gz|tgz|xz|z|cab|bz2|7z|tar|lzh|zst)$/i', $tmpfile)) {
10518 $imgmime =
'archive.png';
10519 $famime =
'file-archive';
10520 } elseif (preg_match(
'/\.(exe|com)$/i', $tmpfile)) {
10521 $mime =
'application/octet-stream';
10522 $imgmime =
'other.png';
10523 $famime =
'file-o';
10524 } elseif (preg_match(
'/\.(dll|lib|o|so|a)$/i', $tmpfile)) {
10526 $imgmime =
'library.png';
10527 $famime =
'file-o';
10528 } elseif (preg_match(
'/\.err$/i', $tmpfile)) {
10530 $imgmime =
'error.png';
10531 $famime =
'file-alt';
10534 if ($famime ==
'file-o') {
10540 switch ((
int) $mode) {
10542 $tmp = explode(
'/', $mime);
10543 return (!empty($tmp[1]) ? $tmp[1] : $tmp[0]);
10569 $tablename = preg_replace(
'/^' . preg_quote(MAIN_DB_PREFIX,
'/') .
'/',
'', $tablename);
10571 $dictvalues = (isset(
$conf->cache[
'dictvalues_' . $tablename]) ?
$conf->cache[
'dictvalues_' . $tablename] :
null);
10573 if (is_null($dictvalues)) {
10574 $dictvalues = array();
10576 $sql =
"SELECT * FROM " . MAIN_DB_PREFIX . $tablename .
" WHERE 1 = 1";
10577 if ($checkentity) {
10578 $sql .=
' AND entity IN (0,' .
getEntity($tablename) .
')';
10581 $resql = $db->query($sql);
10583 while ($obj = $db->fetch_object($resql)) {
10584 $dictvalues[$obj->$rowidfield] = $obj;
10587 dol_print_error($db);
10590 $conf->cache[
'dictvalues_' . $tablename] = $dictvalues;
10593 if (!empty($dictvalues[
$id])) {
10595 $tmp = $dictvalues[
$id];
10596 return (property_exists($tmp, $field) ? $tmp->$field :
'');
10611 $stringcolor = str_replace(
'#',
'', $stringcolor);
10613 if (!empty($stringcolor)) {
10615 $tmp = explode(
',', $stringcolor);
10616 if (count($tmp) > 1) {
10621 $hexr = $stringcolor[0] . $stringcolor[1];
10622 $hexg = $stringcolor[2] . $stringcolor[3];
10623 $hexb = $stringcolor[4] . $stringcolor[5];
10624 $r = hexdec($hexr);
10625 $g = hexdec($hexg);
10626 $b = hexdec($hexb);
10628 $bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0;
10629 if ($bright > 0.6) {
10648 if (empty($menuentry[
'enabled'])) {
10651 if ($type_user && array_key_exists(
'module', $menuentry) && $menuentry[
'module']) {
10652 $tmploops = explode(
'|', $menuentry[
'module']);
10654 foreach ($tmploops as $tmploop) {
10655 if (in_array($tmploop, $listofmodulesforexternal)) {
10664 if (!$menuentry[
'perms'] && $type_user) {
10670 if (!$menuentry[
'perms']) {
10685 $result = (ceil($n) % $x === 0) ? ceil($n) : (round(($n + $x / 2) / $x) * $x);
10686 return (
int) $result;
10702 global
$conf, $db, $hookmanager;
10708 $classfile = $classname = $classpath = $subdir = $dir_output = $dir_temp = $parent_element =
'';
10712 $element = $elementType;
10713 $subelement = $elementType;
10714 $table_element = $elementType;
10717 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $elementType, $regs)) {
10718 $element = $subelement = $regs[1];
10719 $table_element = $regs[2].
'_'.$regs[1];
10720 $subdir =
'/'.$regs[1];
10722 } elseif (preg_match(
'/^([^_]+)_([^_]+)/i', $element, $regs)) {
10725 $module = $element = $regs[1];
10726 $table_element = $elementType;
10727 $subelement = $regs[2];
10731 if (substr($elementType, -3) ==
'det') {
10732 $module = preg_replace(
'/det$/',
'', $element);
10733 $subelement = preg_replace(
'/det$/',
'', $subelement);
10734 $classpath =
$module .
'/class';
10736 $classname = preg_replace(
'/det$/',
'Line', $element);
10737 if (in_array(
$module, array(
'expedition',
'propale',
'facture',
'contrat',
'fichinter',
'ficheinter',
'supplier_order',
'commandefournisseur'))) {
10738 $classname = preg_replace(
'/det$/',
'Ligne', $element);
10742 if ($elementType ==
"action" || $elementType ==
"actioncomm") {
10743 $classpath =
'comm/action/class';
10744 $subelement =
'Actioncomm';
10746 $table_element =
'actioncomm';
10747 } elseif ($elementType ==
'cronjob') {
10748 $classpath =
'cron/class';
10750 $table_element =
'cron';
10751 } elseif ($elementType ==
'adherent_type') {
10752 $classpath =
'adherents/class';
10753 $classfile =
'adherent_type';
10755 $subelement =
'adherent_type';
10756 $classname =
'AdherentType';
10757 $table_element =
'adherent_type';
10758 } elseif ($elementType ==
'bank_account' || $elementType ==
'bank' || $elementType ==
'banque') {
10760 $classpath =
'compta/bank/class';
10762 $classfile =
'account';
10763 $classname =
'Account';
10764 $element = $subelement =
'bank_account';
10765 $table_element =
'bank_account';
10766 } elseif ($elementType ==
'bank_line') {
10767 $classpath =
'compta/bank/class';
10769 $classfile =
'account';
10770 $classname =
'AccountLine';
10771 } elseif ($elementType ==
'remisecheque') {
10772 $classpath =
'compta/paiement/cheque/class';
10773 $classfile =
'remisecheque';
10774 $classname =
'RemiseCheque';
10776 $element =
'chequereceipt';
10777 $subelement =
'cheque';
10778 $table_element =
'bordereau_cheque';
10779 } elseif ($elementType ==
'category') {
10780 $classpath =
'categories/class';
10782 $subelement =
'categorie';
10783 $table_element =
'categorie';
10784 } elseif ($elementType ==
'contact') {
10785 $classpath =
'contact/class';
10786 $classfile =
'contact';
10788 $subelement =
'contact';
10789 $table_element =
'socpeople';
10790 $subdir =
'/contact';
10791 } elseif ($elementType ==
'inventory') {
10793 $classpath =
'product/inventory/class';
10794 } elseif ($elementType ==
'inventoryline') {
10796 $classpath =
'product/inventory/class';
10797 $table_element =
'inventorydet';
10798 $parent_element =
'inventory';
10799 } elseif ($elementType ==
'stock' || $elementType ==
'entrepot' || $elementType ==
'warehouse') {
10801 $classpath =
'product/stock/class';
10802 $classfile =
'entrepot';
10803 $classname =
'Entrepot';
10804 $table_element =
'entrepot';
10805 } elseif ($elementType ==
'project' || $elementType ==
'projet') {
10806 $classpath =
'projet/class';
10808 $table_element =
'projet';
10809 $classfile =
'project';
10810 $classname =
'Project';
10811 } elseif ($elementType ==
'project_task') {
10812 $classpath =
'projet/class';
10814 $subelement =
'task';
10815 $table_element =
'projet_task';
10816 } elseif ($elementType ==
'mo') {
10817 $classpath =
'mrp/class';
10821 $table_element =
'mrp_mo';
10822 } elseif ($elementType ==
'facture' || $elementType ==
'invoice') {
10823 $classpath =
'compta/facture/class';
10825 $subelement =
'facture';
10826 $table_element =
'facture';
10827 } elseif ($elementType ==
'facturedet') {
10828 $classpath =
'compta/facture/class';
10829 $classfile =
'facture';
10830 $classname =
'FactureLigne';
10832 $table_element =
'facturedet';
10833 $parent_element =
'facture';
10834 } elseif ($elementType ==
'facturerec' || $elementType ==
'facture_rec') {
10835 $classpath =
'compta/facture/class';
10836 $classfile =
'facture-rec';
10838 $classname =
'FactureRec';
10839 } elseif ($elementType ==
'commande' || $elementType ==
'order') {
10840 $classpath =
'commande/class';
10842 $subelement =
'commande';
10843 $table_element =
'commande';
10844 } elseif ($elementType ==
'commandedet') {
10845 $classpath =
'commande/class';
10846 $classfile =
'commande';
10847 $classname =
'OrderLine';
10849 $table_element =
'commandedet';
10850 $parent_element =
'commande';
10851 } elseif ($elementType ==
'propal') {
10852 $classpath =
'comm/propal/class';
10853 $table_element =
'propal';
10854 } elseif ($elementType ==
'propaldet') {
10855 $classpath =
'comm/propal/class';
10856 $classfile =
'propal';
10857 $subelement =
'propaleligne';
10859 $table_element =
'propaldet';
10860 $parent_element =
'propal';
10861 } elseif ($elementType ==
'shipping' || $elementType ==
'shipment') {
10862 $classpath =
'expedition/class';
10863 $classfile =
'expedition';
10864 $classname =
'Expedition';
10866 $table_element =
'expedition';
10867 } elseif ($elementType ==
'expeditiondet' || $elementType ==
'shippingdet') {
10868 $classpath =
'expedition/class';
10869 $classfile =
'expedition';
10870 $classname =
'ExpeditionLigne';
10872 $table_element =
'expeditiondet';
10873 $parent_element =
'expedition';
10874 } elseif ($elementType ==
'delivery_note') {
10875 $classpath =
'delivery/class';
10876 $subelement =
'delivery';
10878 } elseif ($elementType ==
'delivery') {
10879 $classpath =
'delivery/class';
10880 $subelement =
'delivery';
10882 } elseif ($elementType ==
'deliverydet') {
10884 } elseif ($elementType ==
'supplier_proposal') {
10885 $classpath =
'supplier_proposal/class';
10886 $module =
'supplier_proposal';
10887 $element =
'supplierproposal';
10888 $classfile =
'supplier_proposal';
10889 $subelement =
'supplierproposal';
10890 } elseif ($elementType ==
'supplier_proposaldet') {
10891 $classpath =
'supplier_proposal/class';
10892 $module =
'supplier_proposal';
10893 $classfile =
'supplier_proposal';
10894 $classname =
'SupplierProposalLine';
10895 $table_element =
'supplier_proposaldet';
10896 $parent_element =
'supplier_proposal';
10897 } elseif ($elementType ==
'contract') {
10898 $classpath =
'contrat/class';
10900 $subelement =
'contrat';
10901 $table_element =
'contract';
10902 } elseif ($elementType ==
'contratdet') {
10903 $classpath =
'contrat/class';
10905 $table_element =
'contratdet';
10906 $parent_element =
'contrat';
10907 } elseif ($elementType ==
'mailing') {
10908 $classpath =
'comm/mailing/class';
10910 $classfile =
'mailing';
10911 $classname =
'Mailing';
10913 } elseif ($elementType ==
'member' || $elementType ==
'adherent') {
10914 $classpath =
'adherents/class';
10916 $subelement =
'adherent';
10917 $table_element =
'adherent';
10918 } elseif ($elementType ==
'subscription') {
10919 $classpath =
'adherents/class';
10920 $classfile =
'subscription';
10922 $subelement =
'subscription';
10923 $classname =
'Subscription';
10924 $table_element =
'subscription';
10925 } elseif ($elementType ==
'usergroup') {
10926 $classpath =
'user/class';
10928 } elseif ($elementType ==
'mrp') {
10929 $classpath =
'mrp/class';
10934 $table_element =
'mrp_mo';
10935 } elseif ($elementType ==
'mrp_production') {
10936 $classpath =
'mrp/class';
10938 $classname =
'MoLine';
10941 $table_element =
'mrp_production';
10942 $parent_element =
'mo';
10943 } elseif ($elementType ==
'cabinetmed_cons') {
10944 $classpath =
'cabinetmed/class';
10946 $subelement =
'cabinetmedcons';
10947 $table_element =
'cabinetmedcons';
10948 } elseif ($elementType ==
'fichinter' || $elementType ==
'ficheinter') {
10949 $classpath =
'fichinter/class';
10951 $subelement =
'fichinter';
10952 $table_element =
'fichinter';
10953 } elseif ($elementType ==
'dolresource' || $elementType ==
'resource') {
10954 $classpath =
'resource/class';
10956 $subelement =
'dolresource';
10957 $table_element =
'resource';
10958 } elseif ($elementType ==
'opensurvey_sondage') {
10959 $classpath =
'opensurvey/class';
10961 $subelement =
'opensurveysondage';
10962 } elseif ($elementType ==
'order_supplier' || $elementType ==
'supplier_order' || $elementType ==
'commande_fournisseur' || $elementType ==
'commandefournisseur') {
10963 $classpath =
'fourn/class';
10965 $classfile =
'fournisseur.commande';
10966 $element =
'order_supplier';
10968 $classname =
'CommandeFournisseur';
10969 $table_element =
'commande_fournisseur';
10970 } elseif ($elementType ==
'commande_fournisseurdet') {
10971 $classpath =
'fourn/class';
10973 $classfile =
'fournisseur.commande';
10974 $element =
'commande_fournisseurdet';
10976 $classname =
'CommandeFournisseurLigne';
10977 $table_element =
'commande_fournisseurdet';
10978 $parent_element =
'commande_fournisseur';
10979 } elseif ($elementType ==
'invoice_supplier' || $elementType ==
'supplier_invoice' || $elementType ==
'facture_fourn') {
10980 $classpath =
'fourn/class';
10982 $classfile =
'fournisseur.facture';
10983 $element =
'invoice_supplier';
10985 $classname =
'FactureFournisseur';
10986 $table_element =
'facture_fourn';
10987 } elseif ($elementType ==
'invoice_supplier_rec' || $elementType ==
'supplier_invoice_rec' || $elementType ==
'facture_fourn_rec') {
10988 $classpath =
'fourn/class';
10990 $classfile =
'fournisseur.facture-rec';
10991 $element =
'invoice_supplier_rec';
10993 $classname =
'FactureFournisseurRec';
10994 $table_element =
'facture_fourn_rec';
10995 } elseif ($elementType ==
'facture_fourn_det') {
10996 $classpath =
'fourn/class';
10998 $classfile =
'fournisseur.facture';
10999 $element =
'facture_fourn_det';
11001 $classname =
'SupplierInvoiceLine';
11002 $table_element =
'facture_fourn_det';
11003 $parent_element =
'invoice_supplier';
11004 } elseif ($elementType ==
"service") {
11005 $classpath =
'product/class';
11007 $subelement =
'product';
11008 $table_element =
'product';
11009 } elseif ($elementType ==
'product_attribute') {
11011 $element =
'product_attribute';
11012 $subelement =
'product_attribute';
11013 $classpath =
'variants/class';
11014 $classfile =
'ProductAttribute';
11015 $classname =
'ProductAttribute';
11016 $table_element =
'product_attribute';
11017 } elseif ($elementType ==
'product_attribute_value') {
11019 $element =
'product_attribute_value';
11020 $subelement =
'product_attribute_value';
11021 $classpath =
'variants/class';
11022 $classfile =
'ProductAttributeValue';
11023 $classname =
'ProductAttributeValue';
11024 $table_element =
'product_attribute_value';
11025 $parent_element =
'product_attribute';
11026 } elseif ($elementType ==
'salary') {
11027 $classpath =
'salaries/class';
11029 } elseif ($elementType ==
'payment_salary') {
11030 $classpath =
'salaries/class';
11031 $classfile =
'paymentsalary';
11032 $classname =
'PaymentSalary';
11034 } elseif ($elementType ==
'payment') {
11035 $classpath =
'compta/paiement/class';
11036 $classfile =
'paiement';
11037 $classname =
'Paiement';
11039 $element =
'payment';
11040 $subelement =
'payment';
11041 $table_element =
'paiement';
11042 } elseif ($elementType ==
'payment_supplier') {
11043 $classpath =
'fourn/class';
11044 $classfile =
'paiementfourn';
11045 $classname =
'PaiementFourn';
11047 $element =
'payment_supplier';
11048 $subelement =
'payment_supplier';
11049 $table_element =
'paiementfourn';
11050 } elseif ($elementType ==
'payment_various') {
11051 $classpath =
'compta/bank/class';
11052 $classfile =
'paymentvarious';
11053 $classname =
'PaymentVarious';
11055 $element =
'payment_various';
11056 $subelement =
'payment_various';
11057 $table_element =
'payment_various';
11058 } elseif ($elementType ==
'stocktransfer') {
11059 $classpath =
'product/stock/stocktransfer/class';
11060 $classfile =
'stocktransfer';
11061 $classname =
'StockTransfer';
11063 $subelement =
'stocktransfer';
11064 $table_element =
'stocktransfer_stocktransfer';
11065 } elseif ($elementType ==
'job' || $elementType ==
'position' || $elementType ==
'skill' || $elementType ==
'evaluation') {
11066 $classpath =
'hrm/class';
11067 $classfile = $elementType;
11068 $classname = ucfirst($elementType);
11070 $subelement = $elementType;
11071 $table_element = ($elementType ==
'position' ?
'hrm_job_user' :
'hrm_'.$elementType);
11072 $subdir =
'/'.$elementType;
11073 } elseif ($elementType ==
'evaluationdet') {
11074 $classpath =
'hrm/class';
11075 $classfile =
'evaluationdet';
11076 $classname =
'EvaluationLine';
11078 $subelement =
'evaluationdet';
11079 $table_element =
'hrm_evaluationdet';
11080 } elseif ($elementType ==
'productlot') {
11082 $classpath =
'product/stock/class';
11083 $classfile =
'productlot';
11084 $classname =
'Productlot';
11085 $element =
'productlot';
11087 $table_element =
'product_lot';
11088 } elseif ($elementType ==
'societeaccount') {
11089 $classpath =
'societe/class';
11090 $classfile =
'societeaccount';
11091 $classname =
'SocieteAccount';
11093 } elseif ($elementType ==
'websitepage' || $elementType ==
'website_page') {
11094 $classpath =
'website/class';
11095 $classfile =
'websitepage';
11096 $classname =
'Websitepage';
11098 $subelement =
'websitepage';
11099 $table_element =
'website_page';
11100 } elseif ($elementType ==
'fiscalyear') {
11101 $classpath =
'core/class';
11103 $subelement =
'fiscalyear';
11104 } elseif ($elementType ==
'chargesociales') {
11105 $classpath =
'compta/sociales/class';
11107 $table_element =
'chargesociales';
11108 } elseif ($elementType ==
'tva') {
11109 $classpath =
'compta/tva/class';
11112 $table_element =
'tva';
11113 } elseif ($elementType ==
'cashcontrol') {
11114 $classpath =
'compta/cashcontrol/class';
11115 $classfile =
'cashcontrol';
11116 $classname =
'CashControl';
11118 $table_element =
'pos_cash_fence';
11119 } elseif ($elementType ==
'emailsenderprofile') {
11121 $classpath =
'core/class';
11122 $classfile =
'emailsenderprofile';
11123 $classname =
'EmailSenderProfile';
11124 $table_element =
'c_email_senderprofile';
11126 } elseif ($elementType ==
'conferenceorboothattendee') {
11127 $classpath =
'eventorganization/class';
11128 $classfile =
'conferenceorboothattendee';
11129 $classname =
'ConferenceOrBoothAttendee';
11130 $module =
'eventorganization';
11131 } elseif ($elementType ==
'conferenceorbooth') {
11132 $classpath =
'eventorganization/class';
11133 $classfile =
'conferenceorbooth';
11134 $classname =
'ConferenceOrBooth';
11135 $module =
'eventorganization';
11136 $subdir =
'/conferenceorbooth';
11137 } elseif ($elementType ==
'ccountry') {
11139 $classpath =
'core/class';
11140 $classfile =
'ccountry';
11141 $classname =
'Ccountry';
11142 $table_element =
'c_country';
11144 } elseif ($elementType ==
'ecmfiles') {
11146 $classpath =
'ecm/class';
11147 $classfile =
'ecmfiles';
11148 $classname =
'Ecmfiles';
11149 $table_element =
'ecmfiles';
11151 } elseif ($elementType ==
'knowledgerecord' || $elementType ==
'knowledgemanagement') {
11152 $module =
'knowledgemanagement';
11153 $classpath =
'knowledgemanagement/class';
11154 $classfile =
'knowledgerecord';
11155 $classname =
'KnowledgeRecord';
11156 $table_element =
'knowledgemanagement_knowledgerecord';
11158 } elseif ($elementType ==
'customer') {
11160 $classpath =
'societe/class';
11161 $classfile =
'client';
11162 $classname =
'Client';
11163 $table_element =
'societe';
11165 } elseif ($elementType ==
'fournisseur' || $elementType ==
'supplier') {
11167 $classpath =
'fourn/class';
11168 $classfile =
'fournisseur';
11169 $classname =
'Fournisseur';
11170 $table_element =
'societe';
11172 } elseif ($elementType ==
'recruitmentcandidature') {
11174 $classfile =
'recruitmentcandidature';
11175 $classpath =
'recruitment/class';
11176 $classname =
'RecruitmentCandidature';
11177 $subelement =
'recruitmentcandidature';
11178 $subdir =
'/recruitmentcandidature';
11179 } elseif ($elementType ==
'recruitmentjobposition') {
11181 $classfile =
'recruitmentjobposition';
11182 $classpath =
'recruitment/class';
11183 $classname =
'RecruitmentJobPosition';
11184 $subelement =
'recruitmentjobposition';
11185 $subdir =
'/recruitmentjobposition';
11186 } elseif ($elementType ==
'recruitment') {
11191 $classfile =
'recruitmentjobposition';
11192 $classpath =
'recruitment/class';
11193 $classname =
'RecruitmentJobPosition';
11194 $element = $subelement =
'recruitmentjobposition';
11195 $table_element =
'recruitment_recruitmentjobposition';
11196 $subdir =
'/recruitmentjobposition';
11197 } elseif ($elementType ==
'product_attribute_combination') {
11199 $classpath =
'variants/class';
11200 $classfile =
'ProductCombination';
11201 $classname =
'ProductCombination';
11202 $element =
'productcombination';
11204 $table_element =
'product_attribute_combination';
11205 } elseif ($elementType ==
'product_attribute_combination2val') {
11207 $classpath =
'variants/class';
11208 $classfile =
'ProductCombination2ValuePair';
11209 $classname =
'ProductCombination2ValuePair';
11210 $element =
'productcombination2valuepair';
11212 $table_element =
'product_attribute_combination2val';
11213 } elseif ($elementType ==
'product_attribute_combination_price_level') {
11216 $classpath =
'variants/class';
11217 $classfile =
'ProductCombination';
11218 $classname =
'ProductCombinationLevel';
11219 $element =
'productcombinationlevel';
11221 $table_element =
'product_attribute_combination_price_level';
11225 if (empty($classfile)) {
11226 $classfile = strtolower($subelement);
11228 if (empty($classname)) {
11229 $classname = ucfirst($subelement);
11231 if (empty($classpath)) {
11232 $classpath =
$module .
'/class';
11239 if (!empty(
$conf->$module->multidir_output[
$conf->entity])) {
11240 $dir_output =
$conf->$module->multidir_output[
$conf->entity];
11241 } elseif (!empty(
$conf->$module->output[
$conf->entity])) {
11242 $dir_output =
$conf->$module->output[
$conf->entity];
11243 } elseif (!empty(
$conf->$module->dir_output)) {
11244 $dir_output =
$conf->$module->dir_output;
11246 if (!empty(
$conf->$module->multidir_temp[
$conf->entity])) {
11247 $dir_temp =
$conf->$module->multidir_temp[
$conf->entity];
11248 } elseif (!empty(
$conf->$module->temp[
$conf->entity])) {
11249 $dir_temp =
$conf->$module->temp[
$conf->entity];
11250 } elseif (!empty(
$conf->$module->dir_temp)) {
11251 $dir_temp =
$conf->$module->dir_temp;
11256 if ($element ==
'order_supplier' &&
isModEnabled(
'fournisseur')) {
11257 $dir_output =
$conf->fournisseur->commande->dir_output;
11258 $dir_temp =
$conf->fournisseur->commande->dir_temp;
11259 } elseif ($element ==
'invoice_supplier' &&
isModEnabled(
'fournisseur')) {
11260 $dir_output =
$conf->fournisseur->facture->dir_output;
11261 $dir_temp =
$conf->fournisseur->facture->dir_temp;
11262 } elseif ($elementType ==
'payment' &&
isModEnabled(
'invoice') && isset(
$conf->compta->payment)) {
11266 $dir_output =
$conf->compta->payment->dir_output;
11267 $dir_temp =
$conf->compta->payment->dir_temp;
11268 } elseif ($elementType ==
'payment_supplier' &&
isModEnabled(
'fournisseur') && isset(
$conf->fournisseur->payment)) {
11269 $dir_output =
$conf->fournisseur->payment->dir_output;
11270 $dir_temp =
$conf->fournisseur->payment->dir_temp;
11275 if (!empty($dir_output)) {
11276 $dir_output .= $subdir;
11278 if (!empty($dir_temp)) {
11280 $dir_temp .= $subdir;
11283 $elementProperties = array(
11285 'element' => $element,
11286 'table_element' => $table_element,
11287 'subelement' => $subelement,
11288 'classpath' => $classpath,
11289 'classfile' => $classfile,
11290 'classname' => $classname,
11291 'dir_output' => $dir_output,
11292 'dir_temp' => $dir_temp,
11293 'parent_element' => $parent_element,
11298 if (!is_object($hookmanager)) {
11299 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
11302 $hookmanager->initHooks(array(
'elementproperties'));
11306 $parameters = array(
11307 'elementType' => $elementType,
11308 'elementProperties' => $elementProperties
11311 $reshook = $hookmanager->executeHooks(
'getElementProperties', $parameters);
11314 $elementProperties = $hookmanager->resArray;
11315 } elseif (!empty($hookmanager->resArray) && is_array($hookmanager->resArray)) {
11316 $elementProperties = array_replace($elementProperties, $hookmanager->resArray);
11320 if (($key = array_search(
'elementproperties', $hookmanager->contextarray)) !==
false) {
11321 unset($hookmanager->contextarray[$key]);
11324 return $elementProperties;
11340function fetchObjectByElement($element_id, $element_type, $element_ref =
'', $useCache = 0, $maxCacheByType = 10)
11350 if ($element_prop[
'module'] ==
'product' || $element_prop[
'module'] ==
'service') {
11356 } elseif ($element_prop[
'module'] ==
'societeaccount') {
11359 $ismodenabled =
isModEnabled($element_prop[
'module']);
11365 if (is_array($element_prop) && (empty($element_prop[
'module']) || $ismodenabled)) {
11366 if ($useCache === 1 && $element_id > 0
11367 && !empty(
$conf->cache[
'fetchObjectByElement'][$element_type])
11368 && !empty(
$conf->cache[
'fetchObjectByElement'][$element_type][$element_id])
11369 && is_object(
$conf->cache[
'fetchObjectByElement'][$element_type][$element_id])
11371 return $conf->cache[
'fetchObjectByElement'][$element_type][$element_id];
11374 $includeresult =
dol_include_once(
'/' . $element_prop[
'classpath'] .
'/' . $element_prop[
'classfile'] .
'.class.php');
11375 if ($includeresult ===
false) {
11376 dol_syslog(
'fetchObjectByElement: class file /' . $element_prop[
'classpath'] .
'/' . $element_prop[
'classfile'] .
'.class.php not found for element ' . $element_type, LOG_WARNING);
11380 if (class_exists($element_prop[
'classname'])) {
11381 $className = $element_prop[
'classname'];
11385 $isinternalclass = (
new ReflectionClass($className))->isInternal();
11386 }
catch (ReflectionException $e) {
11387 $isinternalclass =
false;
11389 if ($isinternalclass) {
11390 dol_syslog(
'fetchObjectByElement: refuse to instantiate PHP internal class ' . $className .
' for element ' . $element_type, LOG_ERR);
11393 $objecttmp =
new $className($db);
11394 '@phan-var-force CommonObject $objecttmp';
11397 if ($element_id > 0 || !empty($element_ref)) {
11400 if (empty($element_id) && !empty($element_ref) && (in_array($objecttmp->element, array(
'evaluation',
'job',
'position',
'skill')))) {
11401 $element_id = $element_ref;
11405 $ret = $objecttmp->fetch($element_id, $element_ref);
11407 if (empty($objecttmp->module)) {
11408 $objecttmp->module = $element_prop[
'module'];
11411 if ($useCache > 0) {
11412 if (!isset(
$conf->cache[
'fetchObjectByElement'][$element_type])) {
11413 $conf->cache[
'fetchObjectByElement'][$element_type] = [];
11417 if (! empty(
$conf->cache[
'fetchObjectByElement'][$element_type]) && is_array(
$conf->cache[
'fetchObjectByElement'][$element_type]) && count(
$conf->cache[
'fetchObjectByElement'][$element_type]) >= $maxCacheByType) {
11418 array_shift(
$conf->cache[
'fetchObjectByElement'][$element_type]);
11421 $conf->cache[
'fetchObjectByElement'][$element_type][$element_id] = $objecttmp;
11430 dol_syslog($element_prop[
'classname'] .
" doesn't exists in /" . $element_prop[
'classpath'] .
"/" . $element_prop[
'classfile'] .
".class.php");
11445 $arrayofregexextension = array(
11472 return $arrayofregexextension;
11485 foreach ($arrayofregexextension as $fileextension) {
11486 if (preg_match(
'/\.' . preg_quote($fileextension,
'/') .
'$/i', $filename)) {
11503 return empty($_SESSION[
'newtoken']) ?
'' : $_SESSION[
'newtoken'];
11515 return isset($_SESSION[
'token']) ? $_SESSION[
'token'] :
'';
11527 if (empty(
$conf->cache[
'nonce'])) {
11528 include_once DOL_DOCUMENT_ROOT .
'/core/lib/security.lib.php';
11532 return $conf->cache[
'nonce'];
11546 if ($method == -1) {
11557 $level = ob_get_level();
11559 while (ob_get_level() > $level) {
11564 if ($method == 0) {
11565 readfile($fullpath_original_file_osencoded);
11566 } elseif ($method == 1) {
11568 $handle = fopen($fullpath_original_file_osencoded,
"rb");
11569 while (!feof($handle)) {
11570 print fread($handle, 8192);
11573 } elseif ($method == 2) {
11575 $handle1 = fopen($fullpath_original_file_osencoded,
"rb");
11576 $handle2 = fopen(
"php://output",
"wb");
11577 stream_copy_to_stream($handle1, $handle2);
11593 $result = json_decode($stringtodecode, $assoc);
11594 if ($result ===
null) {
11595 $result = unserialize($stringtodecode, [
'allowed_classes' =>
false]);
11623 if (is_null($filter) || !is_string($filter) || $filter ===
'') {
11626 if (!preg_match(
'/^\(.*\)$/', $filter)) {
11627 $filter =
'(' . $filter .
')';
11630 $regexstring =
'\(([a-zA-Z0-9_\.]+:[<>!=insotlke]+:[^\(\)]+)\)';
11631 $firstandlastparenthesis = 0;
11633 if (!
dolCheckFilters($filter, $errorstr, $firstandlastparenthesis)) {
11637 return 'Filter syntax error - ' . $errorstr;
11642 $t = preg_replace_callback(
'/' . $regexstring .
'/i',
'dolForgeDummyCriteriaCallback', $filter);
11643 $t = str_ireplace(array(
'and',
'or',
' '),
'', $t);
11646 if (preg_match(
'/[^\(\)]/', $t)) {
11647 $tmperrorstr =
'Bad syntax of the search string';
11648 $errorstr =
'Bad syntax of the search string: ' . $filter;
11652 dol_syslog(
"forgeSQLFromUniversalSearchCriteria Filter error - " . $errorstr, LOG_WARNING);
11653 return 'Filter error - ' . $tmperrorstr;
11657 global $globalforbiddenfields;
11658 $globalforbiddenfields = $forbiddenfields;
11660 $ret = ($noand ?
"" :
" AND ") . ($nopar ?
"" :
'(');
11661 $ret .= preg_replace_callback(
'/' . $regexstring .
'/i',
'dolForgeSQLCriteriaCallback', $filter);
11662 $ret .= ($nopar ?
"" :
')');
11664 if (is_object($db)) {
11665 $ret = str_replace(
'__NOW__',
"'" . $db->idate(
dol_now()) .
"'", $ret);
11667 if (is_object($user)) {
11668 $ret = str_replace(
'__USER_ID__', (
string) $user->id, $ret);
11683 $arrayofandtags = array();
11687 $parenthesislevel = 0;
11692 if ($parenthesislevel >= 1) {
11693 $sqlfilters = preg_replace(
'/^\(/',
'', preg_replace(
'/\)$/',
'', $sqlfilters));
11698 $countparenthesis = 0;
11699 while ($i < $nbofchars) {
11702 if ($char ==
'(') {
11703 $countparenthesis++;
11704 } elseif ($char ==
')') {
11705 $countparenthesis--;
11708 if ($countparenthesis == 0) {
11709 $char2 =
dol_substr($sqlfilters, $i + 1, 1);
11710 $char3 =
dol_substr($sqlfilters, $i + 2, 1);
11711 if ($char ==
'A' && $char2 ==
'N' && $char3 ==
'D') {
11714 if (!preg_match(
'/^\(.*\)$/', $s)) {
11715 $s =
'(' . $s .
')';
11717 $arrayofandtags[] = $s;
11730 if (!preg_match(
'/^\(.*\)$/', $s)) {
11731 $s =
'(' . $s .
')';
11733 $arrayofandtags[] = $s;
11736 return $arrayofandtags;
11748function dolCheckFilters($sqlfilters, &$error =
'', &$parenthesislevel = 0)
11752 $tmp = $sqlfilters;
11756 $parenthesislevel = 0;
11764 if ($char ==
'(') {
11765 if ($i == $parenthesislevel && $parenthesislevel == $counter) {
11767 $parenthesislevel++;
11770 } elseif ($char ==
')') {
11771 $nbcharremaining = ($nb - $i - 1);
11772 if ($nbcharremaining >= $counter) {
11773 $parenthesislevel = min($parenthesislevel, $counter - 1);
11775 if ($parenthesislevel > $counter && $nbcharremaining >= $counter) {
11776 $parenthesislevel = $counter;
11781 if ($counter < 0) {
11782 $error =
"Wrong balance of parenthesis in sqlfilters=" . $sqlfilters;
11783 $parenthesislevel = 0;
11791 if ($counter > 0) {
11792 $error =
"Wrong balance of parenthesis in sqlfilters=" . $sqlfilters;
11793 $parenthesislevel = 0;
11811 if (empty($matches[1])) {
11814 $tmp = explode(
':', $matches[1]);
11815 if (count($tmp) < 3) {
11834 global $globalforbiddenfields;
11837 if (empty($matches[1])) {
11840 $tmp = explode(
':', $matches[1], 3);
11841 if (count($tmp) < 3) {
11847 $newforbiddenfields = $globalforbiddenfields;
11848 if (!is_array($newforbiddenfields)) {
11849 $newforbiddenfields = array();
11852 $newforbiddenfields[] =
'pass';
11853 $newforbiddenfields[] =
'pass_crypted';
11854 $newforbiddenfields[] =
'pass_temp';
11855 $newforbiddenfields[] =
'api_key';
11857 $operand = preg_replace(
'/[^a-z0-9\._]/i',
'', trim($tmp[0]));
11861 if (substr_count($operand,
'.') > 1) {
11866 if (!empty($newforbiddenfields)) {
11867 $operandwithoutprefix = preg_replace(
'/^[a-z0-9_]+\./i',
'', $operand);
11868 if (in_array(strtolower($operandwithoutprefix), $newforbiddenfields)) {
11873 $operator = strtoupper(preg_replace(
'/[^a-z<>!=]/i',
'', trim($tmp[1])));
11876 'NOTLIKE' =>
'NOT LIKE',
11877 'ISNOT' =>
'IS NOT',
11878 'NOTIN' =>
'NOT IN',
11882 if (array_key_exists($operator, $realOperator)) {
11883 $operator = $realOperator[$operator];
11886 $tmpescaped = $tmp[2];
11892 if ($operator ==
'IN' || $operator ==
'NOT IN') {
11893 global $dolibarr_allow_unsecured_select_in_extrafields_filter;
11896 $tmpescaped2 =
'(';
11898 $tmpelemarray = explode(
',', $tmpescaped);
11899 foreach ($tmpelemarray as $tmpkey => $tmpelem) {
11901 $tmpelem = trim($tmpelem);
11902 if (preg_match(
'/^\'(.*)\'$/', $tmpelem, $reg)) {
11903 $tmpelemarray[$tmpkey] =
"'".$db->escape($db->sanitize($reg[1], 2, 1, 1, 1)).
"'";
11904 } elseif (preg_match(
'/^[0-9]+$/', (
string) $tmpelem)) {
11905 $tmpelemarray[$tmpkey] = (int) $tmpelem;
11906 } elseif (is_numeric((
string) $tmpelem)) {
11907 $tmpelemarray[$tmpkey] = (float) $tmpelem;
11908 } elseif (!empty($dolibarr_allow_unsecured_select_in_extrafields_filter)) {
11909 $tmpelemarray[$tmpkey] = preg_replace(
'/[^a-z0-9_<>=!\s]/i',
'', $tmpelem);
11911 $tmpelemarray[$tmpkey] = preg_replace(
'/[^a-z0-9_]/i',
'', $tmpelem);
11914 $tmpescaped2 .= implode(
',', $tmpelemarray);
11915 $tmpescaped2 .=
')';
11917 $tmpescaped = $tmpescaped2;
11918 } elseif ($operator ==
'LIKE' || $operator ==
'NOT LIKE') {
11919 if (preg_match(
'/^\'([^\']*)\'$/', $tmpescaped, $regbis)) {
11920 $tmpescaped = $regbis[1];
11923 $tmpescaped =
"'" . $db->escape($tmpescaped) .
"'";
11924 } elseif (preg_match(
'/^\'(.*)\'$/', $tmpescaped, $regbis)) {
11927 $tmpescaped =
"'" . $db->escape($regbis[1]) .
"'";
11929 if (strtoupper($tmpescaped) ==
'NULL') {
11930 $tmpescaped =
'NULL';
11931 } elseif (preg_match(
'/^[0-9]+$/', (
string) $tmpescaped)) {
11932 $tmpescaped = (int) $tmpescaped;
11933 } elseif (is_numeric((
string) $tmpescaped)) {
11934 $tmpescaped = (float) $tmpescaped;
11936 $tmpescaped = preg_replace(
'/[^a-z0-9_]/i',
'', $tmpescaped);
11940 return '(' . $db->escape($operand) .
' ' . strtoupper($operator) .
' ' . $tmpescaped .
')';
11955 dol_syslog(
'getTimelineIcon::begin', LOG_DEBUG);
11958 $out =
'<!-- timeline icon -->' .
"\n";
11959 $iconClass =
'fa fa-comments';
11964 if ($histo[$key][
'percent'] == -1) {
11965 $colorClass =
'timeline-icon-not-applicble';
11966 $pictoTitle = $langs->trans(
'StatusNotApplicable');
11967 } elseif ($histo[$key][
'percent'] == 0) {
11968 $colorClass =
'timeline-icon-todo';
11969 $pictoTitle = $langs->trans(
'StatusActionToDo') .
' (0%)';
11970 } elseif ($histo[$key][
'percent'] > 0 && $histo[$key][
'percent'] < 100) {
11971 $colorClass =
'timeline-icon-in-progress';
11972 $pictoTitle = $langs->trans(
'StatusActionInProcess') .
' (' . $histo[$key][
'percent'] .
'%)';
11973 } elseif ($histo[$key][
'percent'] >= 100) {
11974 $colorClass =
'timeline-icon-done';
11975 $pictoTitle = $langs->trans(
'StatusActionDone') .
' (100%)';
11978 if ($actionstatic->code ==
'AC_TICKET_CREATE') {
11979 $iconClass =
'fa fa-ticket';
11980 } elseif ($actionstatic->code ==
'AC_TICKET_MODIFY') {
11981 $iconClass =
'fa fa-pencilxxx';
11982 } elseif (preg_match(
'/^TICKET_MSG/', $actionstatic->code)) {
11983 $iconClass =
'fa fa-comments';
11984 } elseif (preg_match(
'/^TICKET_MSG_PRIVATE/', $actionstatic->code)) {
11985 $iconClass =
'fa fa-mask';
11987 if ($actionstatic->type_picto) {
11988 $img_picto = img_picto(
'', $actionstatic->type_picto);
11990 if ($actionstatic->type_code ==
'AC_RDV') {
11991 $iconClass =
'fa fa-handshake';
11992 } elseif ($actionstatic->type_code ==
'AC_TEL') {
11993 $iconClass =
'fa fa-phone';
11994 } elseif ($actionstatic->type_code ==
'AC_FAX') {
11995 $iconClass =
'fa fa-fax';
11996 } elseif ($actionstatic->type_code ==
'AC_EMAIL') {
11997 $iconClass =
'fa fa-envelope';
11998 } elseif ($actionstatic->type_code ==
'AC_INT') {
11999 $iconClass =
'fa fa-shipping-fast';
12000 } elseif ($actionstatic->type_code ==
'AC_OTH_AUTO') {
12001 $iconClass =
'fa fa-robot';
12002 } elseif (!preg_match(
'/_AUTO/', $actionstatic->type_code)) {
12003 $iconClass =
'fa fa-robot';
12008 $out .=
'<i class="' . $iconClass .
' ' . $colorClass .
'" title="' . $pictoTitle .
'">' . $img_picto .
'</i>' .
"\n";
12022 $documents = array();
12024 $sql =
'SELECT ecm.rowid as id, ecm.src_object_type, ecm.src_object_id, ecm.filepath, ecm.filename, ecm.agenda_id';
12025 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'ecm_files ecm';
12026 $sql .=
" WHERE ecm.filepath = 'agenda/" . ((int)
$object->id) .
"'";
12028 $sql .=
' OR ecm.agenda_id = ' . (int)
$object->id;
12029 $sql .=
' ORDER BY ecm.position ASC';
12031 $resql = $db->query($sql);
12033 if ($db->num_rows($resql)) {
12034 while ($obj = $db->fetch_object($resql)) {
12035 $documents[$obj->id] = $obj;
12055function buildParamDate($prefix, $timestamp =
null, $hourTime =
'', $gm =
'auto')
12057 if ($timestamp ===
null) {
12058 $timestamp =
GETPOSTDATE($prefix, $hourTime, $gm);
12065 if ($hourTime ===
'getpost' || ($timestamp !==
null &&
dol_print_date($timestamp,
'%H:%M:%S') !==
'00:00:00')) {
12066 $TParam = array_merge($TParam, array(
12073 return '&' . http_build_query($TParam);
12094function recordNotFound($message =
'', $printheader = 1, $printfooter = 1, $showonlymessage = 0, $params =
null)
12096 global
$conf, $db, $langs, $hookmanager;
12099 if (!is_object($langs)) {
12100 include_once DOL_DOCUMENT_ROOT .
'/core/class/translate.class.php';
12102 $langs->setDefaultLang();
12105 $langs->load(
"errors");
12107 if ($printheader) {
12108 if (function_exists(
"llxHeader")) {
12110 } elseif (function_exists(
"llxHeaderVierge")) {
12115 print
'<div class="error">';
12116 if (empty($message)) {
12117 print $langs->trans(
"ErrorRecordNotFound");
12119 print $langs->trans($message);
12124 if (empty($showonlymessage)) {
12125 if (empty($hookmanager)) {
12126 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
12129 $hookmanager->initHooks(array(
'main'));
12132 $parameters = array(
'message' => $message,
'params' => $params);
12133 $reshook = $hookmanager->executeHooks(
'getErrorRecordNotFound', $parameters,
$object, $action);
12134 print $hookmanager->resPrint;
12137 if ($printfooter && function_exists(
"llxFooter")) {
12139 if (is_object($db)) {
12180 foreach ($array2 as $key => $value) {
12181 if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
12184 $merged[$key] = $value;
12201 foreach ($parameters as $key => $value) {
12202 if ($value ==
'' || $value ==
'-1') {
12203 unset($parameters[$key]);
12207 return $parameters;
12238 preg_match(
'/list$/',
$context) &&
12239 GETPOST(
'action') ==
'list' &&
12240 in_array(
GETPOST(
'formfilteraction'), array(
'list',
'listafterchangingselectedfields')) &&
12241 $_SERVER[
'REQUEST_METHOD'] ==
'POST'
12244 if (!
GETPOST(
'massaction')) {
12245 $postData = $_POST;
12248 unset($postData[
'massaction']);
12249 unset($postData[
'confirmmassactioninvisible']);
12250 unset($postData[
'token']);
12255 $newLocationUrl = $_SERVER[
'SCRIPT_NAME'];
12256 $urlParams = http_build_query($postData);
12257 if ($urlParams !==
'') {
12258 $newLocationUrl .=
'?' . $urlParams;
12262 $maxUrlLength =
getDolGlobalInt(
"MAIN_REDIRECT_POST_AS_GET_IF_POSSIBLE");
12263 if (strlen($newLocationUrl) <= $maxUrlLength) {
12264 header(
'Location: ' . $newLocationUrl);
12279 if (!empty($obj->socid)) {
12280 return (
int) $obj->socid;
12281 } elseif (!empty($obj->soc_id)) {
12282 return (
int) $obj->soc_id;
12283 } elseif (!empty($obj->societe_id)) {
12284 return (
int) $obj->societe_id;
12297 if (!empty($_SESSION[
'dol_screenheight']) && $_SESSION[
'dol_screenheight'] < 700) {
12299 } elseif (!empty($_SESSION[
'dol_screenheight']) && $_SESSION[
'dol_screenheight'] < 950) {
12301 } 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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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.
if(! $sortfield) if(! $sortorder) $module
$context
@method int call_trigger(string $triggerName, ?User $user)
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.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
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)
getDoliDBInstance($type, $host, $user, $pass, $name, $port, $forcenew=false)
Return a DoliDB instance (database handler).
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.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
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.
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.
dol_getThemeFilePath($file, $theme='')
Return the full filesystem path of a file located in the currently selected theme directory.
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.
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, or into a js string that is a locat...
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.
dolRemoveDefaultParameters(array $parameters)
Function to remove parameters having their default value.
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.
dolEvalSimpleCondition($s)
Evaluate a condition made of simple terms, without eval().
dolRedirectPostSearchListRequestToGetIfPossible(string $context)
Function to redirect search list forms from POST to GET request.
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).
dolGetCityFromIp($ip)
Return a city name from IP.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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)
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.
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).
showSimpleHTMLTable($outputlangs, $object)
Returns simple order table template as string.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
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...
div refaddress div address
realCharForNumericEntities($matches)
Return the real char for a numeric entities.