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');
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[
'"'] =
"\\\"";
2358 return strtr((
string) $stringtoescape, $substitjs);
2372 return rawurlencode($stringtoescape);
2383 return str_replace(
'"',
'\"', $stringtoescape);
2395 if (is_null($stringtoescape)) {
2399 if ($stringforquotes == 2) {
2400 return str_replace(
'"',
"'", $stringtoescape);
2401 } elseif ($stringforquotes == 1) {
2407 $stringtoescape = str_replace(
'\\',
'', $stringtoescape);
2408 return str_replace(
"'",
"\'", str_replace(
'"',
"'", $stringtoescape));
2411 return 'Bad parameter for stringforquotes in dol_escape_php';
2422 return preg_replace(
'/[^a-z0-9_]/i',
'', $stringtoescape);
2433 return $stringtoescape;
2446 if (function_exists(
'mb_strtolower')) {
2447 return mb_strtolower($string, $encoding);
2449 return strtolower($string);
2463 if (function_exists(
'mb_strtoupper')) {
2464 return mb_strtoupper($string, $encoding);
2466 return strtoupper($string);
2480 if (function_exists(
'mb_substr')) {
2481 return mb_strtoupper(mb_substr($string, 0, 1, $encoding), $encoding) . mb_substr($string, 1,
null, $encoding);
2483 return ucfirst($string);
2497 if (function_exists(
'mb_convert_case')) {
2498 return mb_convert_case($string, MB_CASE_TITLE, $encoding);
2500 return ucwords($string);
2512 $backtrace = debug_backtrace();
2514 if (count($backtrace) >= 1) {
2516 if (count($backtrace) == 1) {
2519 $trace = $backtrace[$pos];
2520 if (isset($trace[
'file'], $trace[
'line'])) {
2521 $msg =
" From {$trace['file']}:{$trace['line']}.";
2549function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename =
'', $restricttologhandler =
'', $logcontext =
null)
2551 global
$conf, $user, $debugbar;
2559 if (defined(
'USEEXTERNALSERVER') && !defined(
'USEDOLIBARRSERVER') && !defined(
'USEDOLIBARREDITOR')) {
2560 global $website, $websitekey;
2561 if (is_object($website) && !empty($website->ref)) {
2562 $suffixinfilename .=
'_website_' . $website->ref;
2563 } elseif (!empty($websitekey)) {
2564 $suffixinfilename .=
'_website_' . $websitekey;
2569 if (defined(
'USESUFFIXINLOG')) {
2570 $suffixinfilename .= constant(
'USESUFFIXINLOG');
2574 foreach (
$conf->loghandlers as $loghandlerinstance) {
2575 $loghandlerinstance->setIdent($ident);
2579 if (!empty($message)) {
2582 $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');
2584 if (!array_key_exists($level, $logLevels)) {
2585 dol_syslog(
'Error Bad Log Level ' . $level, LOG_ERR);
2593 $message = preg_replace(
'/password=\'[^\']*\'/',
'password=\'hidden\'', $message);
2597 if ((!empty($_REQUEST[
'logtohtml']) &&
getDolGlobalString(
'MAIN_ENABLE_LOG_TO_HTML'))
2598 || (is_object($user) && $user->hasRight(
'debugbar',
'read') && is_object($debugbar))
2600 $ospid = sprintf(
"%7s",
dol_trunc((
string) getmypid(), 7,
'right',
'UTF-8', 1));
2601 $osuser =
" " . sprintf(
"%6s",
dol_trunc(function_exists(
'posix_getuid') ? posix_getuid() :
'', 6,
'right',
'UTF-8', 1));
2603 $conf->logbuffer[] =
dol_print_date(
dol_now(),
"%Y-%m-%d %H:%M:%S") .
" " . sprintf(
"%-7s", $logLevels[$level]) .
" " . $ospid .
" " . $osuser .
" " . $message;
2609 print
"\n\n<!-- Log start\n";
2611 print
"Log end -->\n";
2615 'message' => $message,
2616 'script' => (isset($_SERVER[
'PHP_SELF']) ? basename($_SERVER[
'PHP_SELF'],
'.php') :
''),
2618 'user' => ((is_object($user) && $user->id) ? $user->login :
''),
2620 'osuser' => function_exists(
'posix_getuid') ? (string) posix_getuid() :
'',
2621 'ospid' => (string) getmypid()
2626 if (!empty($remoteip)) {
2627 $data[
'ip'] = $remoteip;
2631 if (!empty($_SERVER[
'HTTP_X_FORWARDED_FOR'])) {
2632 $tmpips = explode(
',', $_SERVER[
'HTTP_X_FORWARDED_FOR']);
2636 foreach ($tmpips as $tmpip) {
2637 $tmpip = trim($tmpip);
2638 if (strtolower($tmpip) == strtolower($remoteip)) {
2641 if (empty($data[
'ip'])) {
2642 $data[
'ip'] = $tmpip;
2645 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $tmpip;
2648 if (!$foundremoteip) {
2650 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $remoteip;
2652 $data[
'ip'] .= (($j > 0) ?
']' :
'');
2653 } elseif (!empty($_SERVER[
'HTTP_CLIENT_IP'])) {
2654 $tmpips = explode(
',', $_SERVER[
'HTTP_CLIENT_IP']);
2658 foreach ($tmpips as $tmpip) {
2659 $tmpip = trim($tmpip);
2660 if (strtolower($tmpip) == strtolower($remoteip)) {
2663 if (empty($data[
'ip'])) {
2664 $data[
'ip'] = $tmpip;
2667 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $tmpip;
2670 if (!$foundremoteip) {
2672 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $remoteip;
2674 $data[
'ip'] .= (($j > 0) ?
']' :
'');
2676 } elseif (!empty($_SERVER[
'SERVER_ADDR'])) {
2678 $data[
'ip'] = (string) $_SERVER[
'SERVER_ADDR'];
2679 } elseif (!empty($_SERVER[
'COMPUTERNAME'])) {
2681 $data[
'ip'] = (string) $_SERVER[
'COMPUTERNAME'];
2683 $data[
'ip'] =
'???';
2686 if (!empty($_SERVER[
'USERNAME'])) {
2688 $data[
'osuser'] = (string) $_SERVER[
'USERNAME'];
2689 } elseif (!empty($_SERVER[
'LOGNAME'])) {
2691 $data[
'osuser'] = (string) $_SERVER[
'LOGNAME'];
2695 foreach (
$conf->loghandlers as $loghandlerinstance) {
2696 if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler) {
2699 $loghandlerinstance->export($data, $suffixinfilename);
2705 foreach (
$conf->loghandlers as $loghandlerinstance) {
2706 $loghandlerinstance->setIdent($ident);
2727 global $langs, $hookmanager;
2730 $countriesusingstate = array(
'AU',
'CA',
'US',
'IN',
'GB',
'ES',
'UK',
'TR',
'CN');
2735 $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)));
2738 if (isset(
$object->country_code) && in_array(
$object->country_code, array(
'AU',
'CA',
'US',
'CN')) ||
getDolGlobalString(
'MAIN_FORCE_STATE_INTO_ADDRESS')) {
2740 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
2741 $ret .= (($ret && $town) ? $sep :
'') . $town;
2744 $ret .= ($ret ? ($town ?
", " : $sep) :
'') .
$object->state;
2747 $ret .= ($ret ? (($town ||
$object->state) ?
", " : $sep) :
'') .
$object->zip;
2749 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'GB',
'UK'))) {
2751 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
2752 $ret .= ($ret ? $sep :
'') . $town;
2754 $ret .= ($ret ?
", " :
'') .
$object->state;
2757 $ret .= ($ret ? $sep :
'') .
$object->zip;
2759 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'ES',
'TR'))) {
2761 $ret .= ($ret ? $sep :
'') .
$object->zip;
2762 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
2763 $ret .= ($town ? ((
$object->zip ?
' ' :
'') . $town) :
'');
2765 $ret .= $sep .
$object->state;
2767 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'JP'))) {
2770 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
2772 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'IT'))) {
2774 $ret .= ($ret ? $sep :
'') .
$object->zip;
2775 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
2776 $ret .= ($town ? ((
$object->zip ?
' ' :
'') . $town) :
'');
2777 $ret .= (empty(
$object->state_code) ?
'' : (
' ' .
$object->state_code));
2780 $town = (($extralangcode && !empty(
$object->array_languages[
'address'][$extralangcode])) ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
2781 $ret .= !empty(
$object->zip) ? (($ret ? $sep :
'') .
$object->zip) :
'';
2782 $ret .= ($town ? ((
$object->zip ?
' ' : ($ret ? $sep :
'')) . $town) :
'');
2783 if (!empty(
$object->state) && in_array(
$object->country_code, $countriesusingstate)) {
2784 $ret .= ($ret ?
", " :
'') .
$object->state;
2788 if (!is_object($outputlangs)) {
2789 $outputlangs = $langs;
2792 $langs->load(
"dict");
2793 $ret .= (empty(
$object->country_code) ?
'' : ($ret ? $sep :
'') . $outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv(
"Country" .
$object->country_code)));
2796 $parameters = array(
'withcountry' => $withcountry,
'sep' => $sep,
'outputlangs' => $outputlangs,
'mode' => $mode,
'extralangcode' => $extralangcode);
2797 $reshook = $hookmanager->executeHooks(
'formatAddress', $parameters,
$object);
2801 $ret .= $hookmanager->resPrint;
2818function dol_strftime($fmt, $ts =
false, $is_gmt =
false)
2820 if ((abs($ts) <= 0x7FFFFFFF)) {
2823 return 'Error date outside supported range';
2849function dol_print_date($time, $format =
'', $tzoutput =
'auto', $outputlangs =
null, $encodetooutput =
false, $decorate = 0)
2851 global
$conf, $langs;
2858 if ($tzoutput ===
'auto') {
2859 $tzoutput = (empty(
$conf) ?
'tzserver' : (isset(
$conf->tzuserinputkey) ?
$conf->tzuserinputkey :
'tzserver'));
2864 $offsettz = $offsetdst = 0;
2867 if (is_string($tzoutput)) {
2868 if ($tzoutput ==
'tzserver') {
2870 $offsettzstring = @date_default_timezone_get();
2875 } elseif ($tzoutput ==
'tzuser' || $tzoutput ==
'tzuserrel') {
2878 $offsettzstring = (empty($_SESSION[
'dol_tz_string']) ?
getDolGlobalString(
'MAIN_DOLIBARR_USER_TIMEZONE',
'UTC') : $_SESSION[
'dol_tz_string']);
2880 if (class_exists(
'DateTimeZone')) {
2882 $user_date_tz =
new DateTimeZone($offsettzstring);
2885 dol_syslog(
"DateInvalidTimeZoneException for timezone string '".$offsettzstring.
"'. Falling back to UTC.", LOG_ERR);
2886 $user_date_tz =
new DateTimeZone(
'UTC');
2888 $user_dt =
new DateTime();
2889 $user_dt->setTimezone($user_date_tz);
2890 $user_dt->setTimestamp($tzoutput ==
'tzuser' ?
dol_now() : (int) $time);
2891 $offsettz = $user_dt->getOffset();
2893 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
2894 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
2899 if (!is_object($outputlangs)) {
2900 $outputlangs = $langs;
2903 $format =
'daytextshort';
2908 $reduceformat = (!empty(
$conf->dol_optimize_smallscreen) && in_array($format, array(
'day',
'dayhour',
'dayhoursec'))) ? 1 : 0;
2909 $format = preg_replace(
'/inputnoreduce/',
'', $format);
2910 $formatwithoutreduce = preg_replace(
'/reduceformat/',
'', $format);
2911 if ($formatwithoutreduce != $format) {
2912 $format = $formatwithoutreduce;
2918 if ($format ==
'day') {
2919 $format = ($outputlangs->trans(
"FormatDateShort") !=
"FormatDateShort" ? $outputlangs->trans(
"FormatDateShort") :
$conf->format_date_short);
2920 } elseif ($format ==
'hour') {
2921 $format = ($outputlangs->trans(
"FormatHourShort") !=
"FormatHourShort" ? $outputlangs->trans(
"FormatHourShort") :
$conf->format_hour_short);
2922 } elseif ($format ==
'hoursec') {
2923 $s1 = $outputlangs->trans(
"FormatDateShort");
2924 $s2 = $outputlangs->trans(
"FormatDateHourSecShort");
2925 $s3 = trim(preg_replace(
'/'.preg_quote($s1,
'/').
'/',
'', $s2));
2928 } elseif ($format ==
'hourduration') {
2929 $format = ($outputlangs->trans(
"FormatHourShortDuration") !=
"FormatHourShortDuration" ? $outputlangs->trans(
"FormatHourShortDuration") :
$conf->format_hour_short_duration);
2930 } elseif ($format ==
'daytext') {
2931 $format = ($outputlangs->trans(
"FormatDateText") !=
"FormatDateText" ? $outputlangs->trans(
"FormatDateText") :
$conf->format_date_text);
2932 } elseif ($format ==
'daytextshort') {
2933 $format = ($outputlangs->trans(
"FormatDateTextShort") !=
"FormatDateTextShort" ? $outputlangs->trans(
"FormatDateTextShort") :
$conf->format_date_text_short);
2934 } elseif ($format ==
'dayhour') {
2935 $format = ($outputlangs->trans(
"FormatDateHourShort") !=
"FormatDateHourShort" ? $outputlangs->trans(
"FormatDateHourShort") :
$conf->format_date_hour_short);
2936 } elseif ($format ==
'dayhoursec') {
2937 $format = ($outputlangs->trans(
"FormatDateHourSecShort") !=
"FormatDateHourSecShort" ? $outputlangs->trans(
"FormatDateHourSecShort") :
$conf->format_date_hour_sec_short);
2938 } elseif ($format ==
'dayhourtext') {
2939 $format = ($outputlangs->trans(
"FormatDateHourText") !=
"FormatDateHourText" ? $outputlangs->trans(
"FormatDateHourText") :
$conf->format_date_hour_text);
2940 } elseif ($format ==
'dayhourtextshort') {
2941 $format = ($outputlangs->trans(
"FormatDateHourTextShort") !=
"FormatDateHourTextShort" ? $outputlangs->trans(
"FormatDateHourTextShort") :
$conf->format_date_hour_text_short);
2942 } elseif ($format ==
'dayhourlog') {
2944 $format =
'%Y%m%d%H%M%S';
2945 } elseif ($format ==
'dayhourlogsmall') {
2947 $format =
'%y%m%d%H%M';
2948 } elseif ($format ==
'dayhourldap') {
2949 $format =
'%Y%m%d%H%M%SZ';
2950 } elseif ($format ==
'dayhourxcard') {
2951 $format =
'%Y%m%dT%H%M%SZ';
2952 } elseif ($format ==
'dayxcard') {
2954 } elseif ($format ==
'dayrfc') {
2955 $format =
'%Y-%m-%d';
2956 } elseif ($format ==
'dayhourrfc') {
2957 $format =
'%Y-%m-%dT%H:%M:%SZ';
2958 } elseif ($format ==
'standard') {
2959 $format =
'%Y-%m-%d %H:%M:%S';
2962 if ($reduceformat) {
2963 $format = str_replace(
'%Y',
'%y', $format);
2964 $format = str_replace(
'yyyy',
'yy', $format);
2968 if (preg_match(
'/%b/i', $format)) {
2970 $format = str_replace(
'%b',
'__b__', $format);
2971 $format = str_replace(
'%B',
'__B__', $format);
2973 if (preg_match(
'/%a/i', $format)) {
2975 $format = str_replace(
'%a',
'__a__', $format);
2976 $format = str_replace(
'%A',
'__A__', $format);
2981 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)) {
2982 dol_print_error(
null,
"Functions.lib::dol_print_date function called with a bad value" .
getCallerInfoString());
2984 } elseif (preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', (
string) $time, $reg)) {
2988 $syear = (!empty($reg[1]) ? $reg[1] :
'');
2989 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
2990 $sday = (!empty($reg[3]) ? $reg[3] :
'');
2991 $shour = (!empty($reg[4]) ? $reg[4] :
'');
2992 $smin = (!empty($reg[5]) ? $reg[5] :
'');
2993 $ssec = (!empty($reg[6]) ? $reg[6] :
'');
2995 $time =
dol_mktime((
int) $shour, (
int) $smin, (
int) $ssec, (
int) $smonth, (
int) $sday, (
int) $syear,
true);
2998 $tzo =
new DateTimeZone(
'UTC');
3000 $tzo =
new DateTimeZone(date_default_timezone_get());
3002 $dtts =
new DateTime();
3003 $dtts->setTimestamp($time);
3004 $dtts->setTimezone($tzo);
3005 $newformat = str_replace(
3006 array(
'%Y',
'%y',
'%m',
'%d',
'%H',
'%I',
'%M',
'%S',
'%p',
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
3007 array(
'Y',
'y',
'm',
'd',
'H',
'h',
'i',
's',
'A',
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
3010 $ret = $dtts->format($newformat);
3012 array(
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
3013 array(
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
3018 if ($time < 100000000000) {
3019 $dtts =
new DateTime();
3022 $timetouse = (int) $time + $offsettz + $offsetdst;
3024 $tzo =
new DateTimeZone(
'UTC');
3025 $dtts->setTimezone($tzo);
3026 $dtts->setTimestamp($timetouse);
3028 $timetouse = (int) $time + $offsettz + $offsetdst;
3030 $tzo =
new DateTimeZone(date_default_timezone_get());
3031 $dtts->setTimestamp($timetouse);
3032 $dtts->setTimezone($tzo);
3035 $newformat = str_replace(
3036 array(
'%Y',
'%y',
'%m',
'%d',
'%H',
'%I',
'%M',
'%S',
'%p',
'%w',
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
3037 array(
'Y',
'y',
'm',
'd',
'H',
'h',
'i',
's',
'A',
'w',
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
3041 $ret = $dtts->format($newformat);
3044 array(
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
3045 array(
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
3049 $ret =
'Bad value ' . $time .
' for date';
3053 if (preg_match(
'/__b__/i', $format)) {
3054 $timetouse = $time + $offsettz + $offsetdst;
3057 $tzo =
new DateTimeZone(
'UTC');
3059 $tzo =
new DateTimeZone(date_default_timezone_get());
3061 $dtts =
new DateTime();
3062 $dtts->setTimestamp($timetouse);
3063 $dtts->setTimezone($tzo);
3064 $month = (int) $dtts->format(
"m");
3065 $month = sprintf(
"%02d", $month);
3066 if ($encodetooutput) {
3067 $monthtext = $outputlangs->transnoentities(
'Month' . $month);
3068 $monthtextshort = $outputlangs->transnoentities(
'MonthShort' . $month);
3070 $monthtext = $outputlangs->transnoentitiesnoconv(
'Month' . $month);
3071 $monthtextshort = $outputlangs->transnoentitiesnoconv(
'MonthShort' . $month);
3074 $ret = str_replace(
'__b__', $monthtextshort, $ret);
3075 $ret = str_replace(
'__B__', $monthtext, $ret);
3079 if (preg_match(
'/__a__/i', $format)) {
3081 $timetouse = $time + $offsettz + $offsetdst;
3084 $tzo =
new DateTimeZone(
'UTC');
3086 $tzo =
new DateTimeZone(date_default_timezone_get());
3088 $dtts =
new DateTime();
3089 $dtts->setTimestamp($timetouse);
3090 $dtts->setTimezone($tzo);
3091 $w = $dtts->format(
"w");
3092 $dayweek = $outputlangs->transnoentitiesnoconv(
'Day' . $w);
3094 $ret = str_replace(
'__A__', $dayweek, $ret);
3095 $ret = str_replace(
'__a__',
dol_substr($dayweek, 0, 3), $ret);
3099 $ret = preg_replace(
'/(\d\d:\d\d [AP]M)$/',
'<span class="'.($decorate === 1 ?
'opacitymedium' : $decorate).
'">\1</span>', $ret);
3100 $ret = preg_replace(
'/(\d\d:\d\d)$/',
'<span class="'.($decorate === 1 ?
'opacitymedium' : $decorate).
'">\1</span>', $ret);
3127function dol_getdate($timestamp, $fast =
false, $forcetimezone =
'')
3129 if ($timestamp ===
'') {
3133 $datetimeobj =
new DateTime();
3134 $datetimeobj->setTimestamp($timestamp);
3135 if ($forcetimezone) {
3136 $datetimeobj->setTimezone(
new DateTimeZone($forcetimezone ==
'gmt' ?
'UTC' : $forcetimezone));
3139 'year' => ((
int) date_format($datetimeobj,
'Y')),
3140 'mon' => ((
int) date_format($datetimeobj,
'm')),
3141 'mday' => ((
int) date_format($datetimeobj,
'd')),
3142 'wday' => ((
int) date_format($datetimeobj,
'w')),
3143 'yday' => ((
int) date_format($datetimeobj,
'z')),
3144 'hours' => ((
int) date_format($datetimeobj,
'H')),
3145 'minutes' => ((
int) date_format($datetimeobj,
'i')),
3146 'seconds' => ((
int) date_format($datetimeobj,
's')),
3174function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm =
'auto', $check = 1)
3179 if ($gm ===
'auto') {
3180 $gm = (empty(
$conf) ?
'tzserver' :
$conf->tzuserinputkey);
3185 if ($hour == -1 || empty($hour)) {
3188 if ($minute == -1 || empty($minute)) {
3191 if ($second == -1 || empty($second)) {
3197 if (!$month || !$day) {
3206 if ($hour < 0 || $hour > 24) {
3209 if ($minute < 0 || $minute > 60) {
3212 if ($second < 0 || $second > 60) {
3217 if (empty($gm) || ($gm ===
'server' || $gm ===
'tzserver')) {
3218 $default_timezone = @date_default_timezone_get();
3219 $localtz =
new DateTimeZone($default_timezone);
3220 } elseif ($gm ===
'user' || $gm ===
'tzuser' || $gm ===
'tzuserrel') {
3222 $default_timezone = (empty($_SESSION[
"dol_tz_string"]) ? @date_default_timezone_get() : $_SESSION[
"dol_tz_string"]);
3224 $localtz =
new DateTimeZone($default_timezone);
3226 dol_syslog(
"Warning dol_tz_string contains an invalid value " . json_encode($_SESSION[
"dol_tz_string"] ??
null), LOG_WARNING);
3227 $default_timezone = @date_default_timezone_get();
3229 } elseif (strrpos($gm,
"tz,") !==
false) {
3230 $timezone = (string) str_replace(
"tz,",
"", $gm);
3232 $localtz =
new DateTimeZone($timezone);
3234 dol_syslog(
"Warning passed timezone contains an invalid value " . $timezone, LOG_WARNING);
3238 if (empty($localtz)) {
3239 $localtz =
new DateTimeZone(
'UTC');
3241 $dt =
new DateTime(
'now', $localtz);
3242 $dt->setDate((
int) $year, (
int) $month, (
int) $day);
3243 $dt->setTime((
int) $hour, (
int) $minute, (
int) $second);
3244 $date = $dt->getTimestamp();
3260function dol_now($mode =
'gmt')
3264 if ($mode ===
'auto') {
3268 if ($mode ==
'gmt') {
3270 } elseif ($mode ==
'tzserver') {
3271 require_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
3273 $ret = (int) (
dol_now(
'gmt') + ($tzsecond * 3600));
3278 } elseif ($mode ==
'tzuser' || $mode ==
'tzuserrel') {
3281 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
3282 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
3283 $ret = (int) (
dol_now(
'gmt') + ($offsettz + $offsetdst));
3300 global
$conf, $langs;
3303 if (!empty(
$conf->dol_optimize_smallscreen)) {
3308 if (empty($shortvalue) || $size < ($level * 10)) {
3310 $textunitshort = $langs->trans(
"b");
3311 $textunitlong = $langs->trans(
"Bytes");
3313 $ret = round($size / $level, 0);
3314 $textunitshort = $langs->trans(
"Kb");
3315 $textunitlong = $langs->trans(
"KiloBytes");
3318 if (empty($shortunit)) {
3319 $ret .=
' ' . $textunitlong;
3321 $ret .=
' ' . $textunitshort;
3337function dol_print_url($url, $target =
'_blank', $max = 32, $withpicto = 0, $morecss =
'')
3345 $linkstart =
'<a href="';
3346 if (!preg_match(
'/^http/i', $url)) {
3347 $linkstart .=
'http://';
3352 $linkstart .=
' target="' . $target .
'"';
3354 $linkstart .=
' title="' . $langs->trans(
"URL") .
': ' . $url .
'"';
3358 if (!preg_match(
'/^http/i', $url)) {
3365 if ($morecss ==
'float') {
3366 return '<div class="nospan' . ($morecss ?
' ' . $morecss :
'') .
'" style="margin-right: 10px">' . ($withpicto ? img_picto($langs->trans(
"Url"),
'globe',
'class="paddingrightonly"') :
'') . $link .
'</div>';
3368 return $linkstart .
'<span class="nospan' . ($morecss ?
' ' . $morecss :
'') .
'" style="margin-right: 10px">' . ($withpicto ? img_picto(
'',
'globe',
'class="paddingrightonly"') :
'') . $link .
'</span>' . $linkend;
3385function dol_print_email($email, $contactid = 0, $socid = 0, $addlink = 0, $max = 0, $showinvalid = 2, $withpicto = 0, $morecss =
'paddingrightonly')
3387 global $user, $langs, $hookmanager;
3398 if (empty($email)) {
3402 if ($addlink == 1) {
3403 $newemail =
'<a class="' . ($morecss ? $morecss :
'') .
'" style="text-overflow: ellipsis;" href="';
3404 if (!preg_match(
'/^mailto:/i', $email)) {
3405 $newemail .=
'mailto:';
3407 $newemail .= $email;
3408 $newemail .=
'" target="_blank">';
3410 $newemail .= ($withpicto ? img_picto($langs->trans(
"EMail") .
' : ' . $email, (is_numeric($withpicto) ?
'email' : $withpicto),
'class="paddingrightonly"') :
'');
3415 $newemail .= $email;
3417 $newemail .=
'</a>';
3420 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
3421 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
3424 $langs->load(
"errors");
3425 $newemail .= img_warning($langs->transnoentitiesnoconv(
"ErrorBadEMail", $emailonly),
'',
'paddingrightonly');
3427 $langs->load(
"errors");
3428 $newemail .= img_warning($langs->transnoentitiesnoconv(
"ErrorBadMXDomain", $emailonly),
'',
'paddingrightonly');
3432 if (($contactid || $socid) &&
isModEnabled(
'agenda') && $user->hasRight(
"agenda",
"myactions",
"create")) {
3434 $linktoaddaction =
'';
3436 $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>';
3438 if ($linktoaddaction) {
3439 $newemail =
'<div>' . $newemail .
' ' . $linktoaddaction .
'</div>';
3442 } elseif ($addlink ===
'thirdparty') {
3443 $tmpnewemail =
'<a class="' . ($morecss ? $morecss :
'') .
'" style="text-overflow: ellipsis;" href="' . DOL_URL_ROOT .
'/societe/card.php?socid=' . $socid .
'&action=presend&mode=init#formmailbeforetitle">';
3444 $tmpnewemail .= ($withpicto ? img_picto($langs->trans(
"EMail") .
' : ' . $email, (is_numeric($withpicto) ?
'email' : $withpicto),
'class="paddingrightonly"') :
'');
3445 if ($withpicto == 1) {
3446 $tmpnewemail .= $newemail;
3448 $tmpnewemail .=
'</a>';
3450 $newemail = $tmpnewemail;
3452 $newemail = ($withpicto ? img_picto($langs->trans(
"EMail") .
' : ' . $email, (is_numeric($withpicto) ?
'email' : $withpicto),
'class="paddingrightonly"') :
'') . $newemail;
3455 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
3456 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
3459 $langs->load(
"errors");
3460 $newemail .= img_warning($langs->transnoentitiesnoconv(
"ErrorBadEMail", $email));
3462 $langs->load(
"errors");
3463 $newemail .= img_warning($langs->transnoentitiesnoconv(
"ErrorBadMXDomain", $emailonly));
3477 $parameters = array(
'cid' => $contactid,
'socid' => $socid,
'addlink' => $addlink,
'picto' => $withpicto);
3479 $reshook = $hookmanager->executeHooks(
'printEmail', $parameters, $email);
3483 $rep .= $hookmanager->resPrint;
3499 $socialnetworks = array();
3501 require_once DOL_DOCUMENT_ROOT .
'/core/lib/memory.lib.php';
3505 if (!is_null($dataretrieved)) {
3506 $socialnetworks = $dataretrieved;
3508 $sql =
"SELECT rowid, code, label, url, icon, active FROM " . MAIN_DB_PREFIX .
"c_socialnetworks";
3509 $sql .=
" WHERE entity IN (" .
getEntity(
'c_socialnetworks').
")";
3511 $resql = $db->query($sql);
3513 while ($obj = $db->fetch_object($resql)) {
3514 $socialnetworks[$obj->code] = array(
3515 'rowid' => $obj->rowid,
3516 'label' => $obj->label,
3518 'icon' => $obj->icon,
3519 'active' => $obj->active,
3526 return (is_array($socialnetworks) ? $socialnetworks : array());
3541 global $hookmanager, $langs, $user;
3545 if (empty($value)) {
3549 if (!empty($type)) {
3550 $htmllink =
'<div class="divsocialnetwork inline-block valignmiddle">';
3552 $htmllink .=
'<span class="fab pictofixedwidth ' . ($dictsocialnetworks[$type][
'icon'] ? $dictsocialnetworks[$type][
'icon'] :
'fa-link') .
'"></span>';
3553 if ($type ==
'skype') {
3555 $htmllink .=
' <a href="skype:';
3557 $htmllink .=
'?call" alt="' . $langs->trans(
"Call") .
' ' . $value .
'" title="' .
dol_escape_htmltag($langs->trans(
"Call") .
' ' . $value) .
'">';
3558 $htmllink .=
'<img src="' . DOL_URL_ROOT .
'/theme/common/skype_callbutton.png" border="0">';
3559 $htmllink .=
'</a><a href="skype:';
3561 $htmllink .=
'?chat" alt="' . $langs->trans(
"Chat") .
' ' . $value .
'" title="' .
dol_escape_htmltag($langs->trans(
"Chat") .
' ' . $value) .
'">';
3562 $htmllink .=
'<img class="paddingleft" src="' . DOL_URL_ROOT .
'/theme/common/skype_chatbutton.png" border="0">';
3563 $htmllink .=
'</a>';
3564 if (($contactid || $socid) &&
isModEnabled(
'agenda') && $user->hasRight(
'agenda',
'myactions',
'create')) {
3565 $addlink =
'AC_SKYPE';
3568 $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>';
3570 $htmllink .= ($link ?
' ' . $link :
'');
3573 if (!empty($dictsocialnetworks[$type][
'url'])) {
3574 $tmpvirginurl = preg_replace(
'/\/?{socialid}/',
'', $dictsocialnetworks[$type][
'url']);
3575 if ($tmpvirginurl) {
3576 $value = preg_replace(
'/^www\.' . preg_quote($tmpvirginurl,
'/') .
'\/?/',
'', $value);
3577 $value = preg_replace(
'/^' . preg_quote($tmpvirginurl,
'/') .
'\/?/',
'', $value);
3579 $tmpvirginurl3 = preg_replace(
'/^https:\/\//i',
'https://www.', $tmpvirginurl);
3580 if ($tmpvirginurl3) {
3581 $value = preg_replace(
'/^www\.' . preg_quote($tmpvirginurl3,
'/') .
'\/?/',
'', $value);
3582 $value = preg_replace(
'/^' . preg_quote($tmpvirginurl3,
'/') .
'\/?/',
'', $value);
3585 $tmpvirginurl2 = preg_replace(
'/^https?:\/\//i',
'', $tmpvirginurl);
3586 if ($tmpvirginurl2) {
3587 $value = preg_replace(
'/^www\.' . preg_quote($tmpvirginurl2,
'/') .
'\/?/',
'', $value);
3588 $value = preg_replace(
'/^' . preg_quote($tmpvirginurl2,
'/') .
'\/?/',
'', $value);
3591 if (preg_match(
'/^https?:\/\//i', $value)) {
3594 $link = str_replace(
'{socialid}', $value, $dictsocialnetworks[$type][
'url']);
3596 $valuetoshow = $value;
3597 $valuetoshow = preg_replace(
'/https:\/\/www\.(twitter|x|linkedin)\.com\/?/',
'', $valuetoshow);
3598 if (preg_match(
'/^https?:\/\//i', $link)) {
3607 $htmllink .=
'</div>';
3609 $langs->load(
"errors");
3610 $htmllink .= img_warning($langs->trans(
"ErrorBadSocialNetworkValue", $value));
3614 $parameters = array(
3616 'cid' => $contactid,
3619 'dictsocialnetworks' => $dictsocialnetworks,
3622 $reshook = $hookmanager->executeHooks(
'printSocialNetworks', $parameters);
3626 $htmllink .= $hookmanager->resPrint;
3641function dol_print_profids($profID, $profIDtype, $countrycode =
'', $addcpButton = 1)
3645 if (empty($profID) || empty($profIDtype)) {
3648 if (empty($countrycode)) {
3649 $countrycode =
$mysoc->country_code;
3651 $newProfID = $profID;
3652 $id = substr($profIDtype, -1);
3654 if (strtoupper($countrycode) ==
'FR') {
3660 $newProfID = substr($newProfID, 0, 3) .
' ' . substr($newProfID, 3, 3) .
' ' . substr($newProfID, 6, 3);
3664 $newProfID = substr($newProfID, 0, 3) .
' ' . substr($newProfID, 3, 3) .
' ' . substr($newProfID, 6, 3) .
' ' . substr($newProfID, 9, 5);
3668 $newProfID = substr($newProfID, 0, 2) .
'.' . substr($newProfID, 2, 3);
3670 if ($profIDtype ===
'VAT' &&
dol_strlen($newProfID) == 13) {
3672 $newProfID = substr($newProfID, 0, 4) .
' ' . substr($newProfID, 4, 3) .
' ' . substr($newProfID, 7, 3) .
' ' . substr($newProfID, 10, 3);
3675 if (!empty($addcpButton)) {
3698function dol_print_phone($phone, $countrycode =
'', $contactid = 0, $socid = 0, $addlink =
'', $separ =
" ", $withpicto =
'', $titlealt =
'', $adddivfloat = 0, $morecss =
'paddingright')
3700 global
$conf, $user, $langs,
$mysoc, $hookmanager;
3703 $phone = is_null($phone) ?
'' : preg_replace(
"/[\s.-]/",
"", trim($phone));
3704 if (empty($phone)) {
3710 if (empty($countrycode) && is_object(
$mysoc)) {
3711 $countrycode =
$mysoc->country_code;
3715 if (!empty(
$conf->dol_optimize_smallscreen) && $separ !=
'hidenum') {
3720 $newphonewa = $phone;
3721 if (strtoupper($countrycode) ==
"FR") {
3724 $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);
3726 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 2) . $separ . substr($newphone, 5, 2);
3728 $newphone = substr($newphone, 0, 2) . $separ . substr($newphone, 2, 3) . $separ . substr($newphone, 5, 2) . $separ . substr($newphone, 7, 2);
3730 $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);
3732 $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);
3734 $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);
3736 } elseif (strtoupper($countrycode) ==
"CA") {
3738 $newphone = ($separ !=
'' ?
'(' :
'') . substr($newphone, 0, 3) . ($separ !=
'' ?
')' :
'') . $separ . substr($newphone, 3, 3) . ($separ !=
'' ?
'-' :
'') . substr($newphone, 6, 4);
3740 } elseif (strtoupper($countrycode) ==
"PT") {
3742 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
3744 } elseif (strtoupper($countrycode) ==
"SR") {
3746 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3);
3748 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 4);
3750 } elseif (strtoupper($countrycode) ==
"DE") {
3752 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4) . $separ . substr($newphone, 7, 4) . $separ . substr($newphone, 11, 3);
3754 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 4) . $separ . substr($newphone, 10, 3);
3756 } elseif (strtoupper($countrycode) ==
"ES") {
3758 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
3760 } elseif (strtoupper($countrycode) ==
"BF") {
3762 $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);
3764 } elseif (strtoupper($countrycode) ==
"RO") {
3766 $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);
3768 } elseif (strtoupper($countrycode) ==
"TR") {
3770 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 4);
3772 } elseif (strtoupper($countrycode) ==
"US") {
3774 $newphone = substr($newphone, 0, 2) . $separ . substr($newphone, 2, 3) . $separ . substr($newphone, 5, 3) . $separ . substr($newphone, 8, 4);
3776 } elseif (strtoupper($countrycode) ==
"MX") {
3778 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 2);
3780 $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);
3782 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 4);
3784 } elseif (strtoupper($countrycode) ==
"ML") {
3786 $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);
3788 } elseif (strtoupper($countrycode) ==
"TH") {
3790 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 3);
3792 $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);
3794 } elseif (strtoupper($countrycode) ==
"MU") {
3797 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 2) . $separ . substr($newphone, 9, 2);
3799 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 4) . $separ . substr($newphone, 8, 2) . $separ . substr($newphone, 10, 2);
3801 } elseif (strtoupper($countrycode) ==
"ZA") {
3803 $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);
3805 } elseif (strtoupper($countrycode) ==
"SY") {
3807 $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);
3809 $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);
3811 } elseif (strtoupper($countrycode) ==
"AE") {
3813 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 2);
3815 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
3817 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 4);
3819 } elseif (strtoupper($countrycode) ==
"DZ") {
3821 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
3823 } elseif (strtoupper($countrycode) ==
"BE") {
3825 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 3);
3827 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
3829 } elseif (strtoupper($countrycode) ==
"PF") {
3831 $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);
3833 } elseif (strtoupper($countrycode) ==
"CO") {
3835 $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);
3837 } elseif (strtoupper($countrycode) ==
"JO") {
3839 $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);
3841 } elseif (strtoupper($countrycode) ==
"JM") {
3843 $newphone = substr($newphone, 0, 5) . $separ . substr($newphone, 5, 3) . $separ . substr($newphone, 8, 4);
3845 } elseif (strtoupper($countrycode) ==
"MG") {
3847 $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);
3849 } elseif (strtoupper($countrycode) ==
"GB") {
3851 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
3853 } elseif (strtoupper($countrycode) ==
"CH") {
3855 $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);
3857 $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);
3859 } elseif (strtoupper($countrycode) ==
"TN") {
3861 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 2) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
3863 } elseif (strtoupper($countrycode) ==
"GF") {
3865 $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);
3867 } elseif (strtoupper($countrycode) ==
"GP") {
3869 $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);
3871 } elseif (strtoupper($countrycode) ==
"MQ") {
3873 $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);
3875 } elseif (strtoupper($countrycode) ==
"IT") {
3877 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
3879 $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);
3881 } elseif (strtoupper($countrycode) ==
"AU") {
3885 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 1) . $separ . substr($newphone, 4, 4) . $separ . substr($newphone, 8, 4);
3887 } elseif (strtoupper($countrycode) ==
"LU") {
3890 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 2) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 2);
3892 $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);
3894 $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);
3896 $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);
3898 } elseif (strtoupper($countrycode) ==
"PE") {
3901 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4);
3903 $newphonewa =
'+51' . $newphone;
3904 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3);
3906 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 4);
3908 $newphonewa = $newphone;
3909 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
3911 } elseif (strtoupper($countrycode) ==
"IN") {
3913 if ($withpicto ==
'phone') {
3914 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 2) . $separ . substr($newphone, 5, 4) . $separ . substr($newphone, 9, 4);
3916 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 5) . $separ . substr($newphone, 8, 5);
3919 } elseif (strtoupper($countrycode) ==
"CI") {
3921 $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);
3925 $newphoneastart = $newphoneaend =
'';
3926 if (!empty($addlink)) {
3928 $newphoneastart =
'<a href="tel:' . urlencode($phone) .
'">';
3929 $newphoneaend .=
'</a>';
3930 } elseif (
isModEnabled(
'clicktodial') && $addlink ==
'AC_TEL') {
3931 if (empty($user->clicktodial_loaded)) {
3932 $user->fetch_clicktodial();
3936 $urlmask =
getDolGlobalString(
'CLICKTODIAL_URL',
'ErrorClickToDialModuleNotConfigured');
3937 if (!empty($user->clicktodial_url)) {
3938 $urlmask = $user->clicktodial_url;
3941 $clicktodial_poste = (!empty($user->clicktodial_poste) ? urlencode($user->clicktodial_poste) :
'');
3942 $clicktodial_login = (!empty($user->clicktodial_login) ? urlencode($user->clicktodial_login) :
'');
3943 $clicktodial_password = (!empty($user->clicktodial_password) ? urlencode($user->clicktodial_password) :
'');
3945 $url = sprintf($urlmask, urlencode($phone), $clicktodial_poste, $clicktodial_login, $clicktodial_password);
3947 $substitarray = array(
3948 '__PHONEFROM__' => $clicktodial_poste,
3949 '__PHONETO__' => urlencode($phone),
3950 '__LOGIN__' => $clicktodial_login,
3951 '__PASS__' => $clicktodial_password
3956 $newphoneastart =
'<a href="' . $url .
'" class="cssforclicktodial">';
3957 $newphoneaend =
'</a>';
3960 $newphoneastart =
'<a href="' . $url .
'"';
3962 $newphoneastart .=
' target="_blank" rel="noopener noreferrer"';
3964 $newphoneastart .=
'>';
3965 $newphoneaend .=
'</a>';
3969 if (
isModEnabled(
'agenda') && $user->hasRight(
"agenda",
"myactions",
"create")) {
3971 $addlinktoagenda =
'';
3972 if ($addlink ==
'AC_FAX') {
3976 $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>';
3978 if ($addlinktoagenda) {
3979 $newphone =
'<span>' . $newphone .
' ' . $addlinktoagenda .
'</span>';
3984 if (
getDolGlobalString(
'CONTACT_PHONEMOBILE_SHOW_LINK_TO_WHATSAPP') && $withpicto ==
'mobile') {
3986 $newphone .=
' <a href="https://wa.me/' . $newphonewa .
'" target="_blank"';
3987 $newphone .=
'><span class="paddingright fab fa-whatsapp" style="color:#25D366;" title="WhatsApp"></span></a>';
3990 if (empty($titlealt) && isset($langs)) {
3991 $titlealt = ($withpicto ==
'fax' ? $langs->trans(
"Fax") : $langs->trans(
"Phone"));
3996 $parameters = array(
'countrycode' => $countrycode,
'cid' => $contactid,
'socid' => $socid,
'titlealt' => $titlealt,
'picto' => $withpicto);
3997 $reshook = $hookmanager->executeHooks(
'printPhone', $parameters, $phone);
3998 $rep .= $hookmanager->resPrint;
4000 if (empty($reshook)) {
4003 if ($withpicto ==
'fax') {
4004 $picto =
'phoning_fax';
4005 } elseif ($withpicto ==
'phone') {
4007 } elseif ($withpicto ==
'mobile') {
4008 $picto =
'phoning_mobile';
4013 if ($adddivfloat == 1) {
4014 $rep .=
'<div class="nospan float' . ($morecss ?
' ' . $morecss :
'') .
'">';
4015 } elseif (empty($adddivfloat)) {
4016 $rep .=
'<span' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
'>';
4019 $rep .= $newphoneastart;
4020 $rep .= ($withpicto ? img_picto($titlealt, $picto) :
'');
4021 if ($separ !=
'hidenum') {
4022 $rep .= ($withpicto ?
' ' :
'') . $newphone;
4024 $rep .= $newphoneaend;
4026 if ($adddivfloat == 1) {
4028 } elseif (empty($adddivfloat)) {
4049 if (!isset(
$conf->cache[
'resolveips'])) {
4050 $conf->cache[
'resolveips'] = array();
4056 if (file_exists(DOL_DOCUMENT_ROOT .
'/theme/common/flags/' . $countrycode .
'.png')) {
4059 $ret .=
'(' . $countrycode .
')';
4072 if (in_array($mode, [0, 2])) {
4075 if (!array_key_exists($ip,
$conf->cache[
'resolveips'])) {
4076 $domain = gethostbyaddr($ip);
4077 $conf->cache[
'resolveips'][$ip] = $domain;
4079 $domain =
$conf->cache[
'resolveips'][$ip];
4107 $ip = (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']);
4114 if (empty($_SERVER[
'HTTP_X_FORWARDED_FOR']) || preg_match(
'/[^0-9\.\:,\[\]\s]/', $_SERVER[
'HTTP_X_FORWARDED_FOR'])) {
4115 if (empty($_SERVER[
'HTTP_CLIENT_IP']) || preg_match(
'/[^0-9\.\:,\[\]\s]/', $_SERVER[
'HTTP_CLIENT_IP'])) {
4116 if (empty($_SERVER[
"HTTP_CF_CONNECTING_IP"])) {
4117 $ip = (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']);
4119 $ip = $_SERVER[
"HTTP_CF_CONNECTING_IP"];
4122 $ip = preg_replace(
'/,.*$/',
'', $_SERVER[
'HTTP_CLIENT_IP']);
4125 $ip = preg_replace(
'/,.*$/',
'', $_SERVER[
'HTTP_X_FORWARDED_FOR']);
4145 $datafile = $diroffile .
'/' .
getDolGlobalString(
'GEOIPMAXMIND_COUNTRY_DATAFILE_EMBEDDED');
4151 include_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeoip.class.php';
4152 $geoip =
new DolGeoIP(
'country', $datafile);
4154 $countrycode = $geoip->getCountryCodeFromIP($ip);
4161 return $countrycode;
4180 $datafile = $diroffile .
'/' .
getDolGlobalString(
'GEOIPMAXMIND_COUNTRY_DATAFILE_EMBEDDED');
4184 include_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeoip.class.php';
4185 $geoip =
new DolGeoIP(
'country', $datafile);
4186 $cityname = $geoip->getCityNameFromIP($ip);
4212 include_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeoip.class.php';
4213 $geoip =
new DolGeoIP(
'country', $datafile);
4214 $countrycode = $geoip->getCountryCodeFromIP($ip);
4215 $ret = $countrycode;
4234 global $hookmanager;
4240 $parameters = array(
'element' => $element,
'id' =>
$id);
4241 $reshook = $hookmanager->executeHooks(
'printAddress', $parameters, $address);
4242 $out .= $hookmanager->resPrint;
4244 if (empty($reshook)) {
4245 if (empty($charfornl)) {
4246 $out .= nl2br((
string) $address);
4248 $out .= preg_replace(
'/[\r\n]+/', $charfornl, (
string) $address);
4252 $showgmap = $showomap = 0;
4278 $url =
dol_buildpath(
'/google/gmaps.php?mode=' . $element .
'&id=' .
$id, 1);
4279 $out .=
' <a href="' . $url .
'" target="_gmaps"><img id="' . $htmlid .
'" class="valigntextbottom" src="' . DOL_URL_ROOT .
'/theme/common/gmap.png"></a>';
4282 $url =
dol_buildpath(
'/openstreetmap/maps.php?mode=' . $element .
'&id=' .
$id, 1);
4283 $out .=
' <a href="' . $url .
'" target="_gmaps"><img id="' . $htmlid .
'_openstreetmap" class="valigntextbottom" src="' . DOL_URL_ROOT .
'/theme/common/gmap.png"></a>';
4305function isValidEmail($address, $acceptsupervisorkey = 0, $acceptuserkey = 0)
4307 if ($acceptsupervisorkey && $address ==
'__SUPERVISOREMAIL__') {
4310 if ($acceptuserkey && $address ==
'__USER_EMAIL__') {
4313 if (filter_var($address, FILTER_VALIDATE_EMAIL)) {
4331 if (function_exists(
'idn_to_ascii') && function_exists(
'checkdnsrr')) {
4332 if (!checkdnsrr(idn_to_ascii($domain),
'MX')) {
4335 if (function_exists(
'getmxrr')) {
4338 getmxrr(idn_to_ascii($domain), $mxhosts, $weight);
4339 if (count($mxhosts) > 1) {
4342 if (count($mxhosts) == 1 && !in_array((
string) $mxhosts[0], array(
'',
'.'))) {
4379 $tmparray = explode(
' ', $s);
4380 foreach ($tmparray as $tmps) {
4395function dol_strlen($string, $stringencoding =
'UTF-8')
4397 if (is_null($string)) {
4401 if (function_exists(
'mb_strlen')) {
4402 return mb_strlen($string, $stringencoding);
4404 return strlen($string);
4418function dol_substr($string, $start, $length =
null, $stringencoding =
'', $trunconbytes = 0)
4422 if (empty($stringencoding)) {
4423 $stringencoding = (empty($langs) ?
'UTF-8' : $langs->charset_output);
4427 if (empty($trunconbytes)) {
4428 if (function_exists(
'mb_substr')) {
4429 $ret = mb_substr($string, $start, $length, $stringencoding);
4431 $ret = substr($string, $start, $length);
4434 if (function_exists(
'mb_strcut')) {
4435 $ret = mb_strcut($string, $start, $length, $stringencoding);
4437 $ret = substr($string, $start, $length);
4457function dol_trunc($string, $size = 40, $trunc =
'right', $stringencoding =
'UTF-8', $nodot = 0, $display = 0)
4465 if (empty($stringencoding)) {
4466 $stringencoding =
'UTF-8';
4469 if (!empty(
$conf->dol_optimize_smallscreen) &&
$conf->dol_optimize_smallscreen == 1 && $display == 1) {
4470 $size = round($size / 3);
4474 if ($trunc ==
'right') {
4476 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
4478 return dol_substr($newstring, 0, $size, $stringencoding) . ($nodot ?
'' :
'…');
4483 } elseif ($trunc ==
'middle') {
4485 if (
dol_strlen($newstring, $stringencoding) > 2 &&
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
4486 $size1 = (int) round($size / 2);
4487 $size2 = (int) round($size / 2);
4488 return dol_substr($newstring, 0, $size1, $stringencoding) .
'…' .
dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size2, $size2, $stringencoding);
4492 } elseif ($trunc ==
'left') {
4494 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
4496 return '…' .
dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size, $size, $stringencoding);
4500 } elseif ($trunc ==
'wrap') {
4502 if (
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
4508 return 'BadParam3CallingDolTrunc';
4524function vatrate($rate, $addpercent =
false, $info_bits = 0, $usestarfornpr = 0, $html = 0)
4528 if (preg_match(
'/%/', $rate)) {
4529 $rate = str_replace(
'%',
'', $rate);
4533 if (preg_match(
'/\((.*)\)/', $rate, $reg)) {
4534 $morelabel =
' (' . $reg[1] .
')';
4535 $rate = preg_replace(
'/\s*' . preg_quote($morelabel,
'/') .
'/',
'', $rate);
4536 $morelabel =
' ' . ($html ?
'<span class="opacitymedium small">' :
'') .
'(' . $reg[1] .
')' . ($html ?
'</span>' :
'');
4538 if (preg_match(
'/\*/', $rate)) {
4539 $rate = str_replace(
'*',
'', $rate);
4544 if (!preg_match(
'/\//', $rate)) {
4545 $ret =
price($rate, 0,
'', 0, 0) . ($addpercent ?
'%' :
'');
4548 $ret = $rate . ($addpercent ?
'%' :
'');
4550 if (($info_bits & 1) && $usestarfornpr >= 0) {
4572function price($amount, $form = 0, $outlangs =
'', $trunc = 1, $rounding = -1, $forcerounding = -1, $currency_code =
'')
4574 global $langs,
$conf;
4577 if (empty($amount)) {
4580 $amount = (is_numeric($amount) ? $amount : 0);
4581 if ($rounding == -1) {
4584 $nbdecimal = $rounding;
4586 if ($outlangs ===
'none') {
4596 if (!($outlangs instanceof
Translate)) {
4600 if ($outlangs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
4601 $dec = $outlangs->transnoentitiesnoconv(
"SeparatorDecimal");
4603 if ($outlangs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
4604 $thousand = $outlangs->transnoentitiesnoconv(
"SeparatorThousand");
4606 if ($thousand ==
'None') {
4608 } elseif ($thousand ==
'Space') {
4615 $amount = str_replace(
',',
'.', $amount);
4617 $data = explode(
'.', $amount);
4618 $decpart = isset($data[1]) ? $data[1] :
'';
4619 $decpart = preg_replace(
'/0+$/i',
'', $decpart);
4629 $nbdecimalmaxshown = (int) str_replace(
'...',
'',
getDolGlobalString(
'MAIN_MAX_DECIMALS_SHOWN'));
4630 if ($trunc && $nbdecimal > $nbdecimalmaxshown) {
4631 $nbdecimal = $nbdecimalmaxshown;
4639 if ((
string) $forcerounding !=
'-1' && (string) $forcerounding !=
'') {
4640 if ($forcerounding ===
'MU') {
4642 } elseif ($forcerounding ===
'MT') {
4644 } elseif ($forcerounding >= 0) {
4645 $nbdecimal = (int) $forcerounding;
4650 $output = number_format((
float) $amount, $nbdecimal, $dec, $thousand);
4652 $cursymbolbefore = $cursymbolafter =
'';
4653 if ($currency_code && is_object($outlangs)) {
4654 if ($currency_code ==
'auto') {
4655 $currency_code =
$conf->currency;
4658 $listofcurrenciesbefore = array(
'AUD',
'CAD',
'CNY',
'COP',
'CLP',
'GBP',
'HKD',
'MXN',
'PEN',
'USD',
'CRC',
'ZAR');
4659 $listoflanguagesbefore = array(
'nl_NL');
4660 if (in_array($currency_code, $listofcurrenciesbefore) || in_array($outlangs->defaultlang, $listoflanguagesbefore)) {
4661 $cursymbolbefore .= $outlangs->getCurrencySymbol($currency_code);
4663 $tmpcur = $outlangs->getCurrencySymbol($currency_code);
4664 $cursymbolafter .= ($tmpcur == $currency_code ?
' ' . $tmpcur : $tmpcur);
4668 $output = preg_replace(
'/\s/',
' ', $output);
4669 $output = $cursymbolbefore . $output . $end . ($cursymbolafter ?
' <span class="small">'.$cursymbolafter.
'</span>' :
'');
4670 $output = preg_replace(
'/\'/',
''', $output);
4672 $output = $cursymbolbefore . $output . $end . ($cursymbolafter ?
' '.$cursymbolafter :
'');
4704function price2num($amount, $rounding =
'', $option = 0)
4709 if (is_null($amount)) {
4718 if (is_null($langs)) {
4722 if ($langs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
4723 $dec = $langs->transnoentitiesnoconv(
"SeparatorDecimal");
4725 if ($langs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
4726 $thousand = $langs->transnoentitiesnoconv(
"SeparatorThousand");
4729 if ($thousand ==
'None') {
4731 } elseif ($thousand ==
'Space') {
4739 if (!is_numeric($amount)) {
4740 $amount = preg_replace(
'/[a-zA-Z\/\\\*\(\)<>\_]/',
'', $amount);
4743 if ($option == 2 && $thousand ==
'.' && preg_match(
'/\.(\d\d\d)$/', (
string) $amount)) {
4744 $amount = str_replace($thousand,
'', $amount);
4750 if (is_numeric($amount)) {
4752 $temps = sprintf(
"%10.10F", $amount - intval($amount));
4753 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
4755 $amount = number_format($amount, $nbofdec, $dec, $thousand);
4761 if ($thousand !=
',' && $thousand !=
'.') {
4774 if (preg_match(
'/^(?<int>[^,]*,|[^.]*\.)(?<dec>[^.,]*)$/u', $amount, $matches)) {
4775 $intPart = $matches[
'int'];
4776 $decPart = $matches[
'dec'];
4779 $intPart = str_replace([
'.',
','],
'', $intPart);
4782 $amount = $intPart . $dec . $decPart;
4786 $amount = str_replace(
' ',
'', $amount);
4787 $amount = str_replace($thousand,
'', $amount);
4788 $amount = str_replace($dec,
'.', $amount);
4790 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
4796 $nbofdectoround =
'';
4797 if ($rounding ==
'MU') {
4799 } elseif ($rounding ==
'MT') {
4801 } elseif ($rounding ==
'MS') {
4803 } elseif ($rounding ==
'CU') {
4805 } elseif ($rounding ==
'CT') {
4807 } elseif ($rounding ==
'CR') {
4809 $rounding_const =
'MAIN_MAX_DECIMALS_CURRENCY_RATE' . ($currencycode ?
'_' . $currencycode :
'');
4811 } elseif (is_numeric($rounding)) {
4812 $nbofdectoround = (int) $rounding;
4817 $amount = round(is_string($amount) ? (
float) $amount : $amount, $nbofdectoround);
4819 return 'ErrorBadParameterProvidedToFunction';
4825 if (is_numeric($amount)) {
4827 $temps = sprintf(
"%10.10F", $amount - intval($amount));
4828 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
4830 $amount = number_format($amount, min($nbofdec, $nbofdectoround), $dec, $thousand);
4836 if ($thousand !=
',' && $thousand !=
'.') {
4837 $amount = str_replace(
',',
'.', $amount);
4840 $amount = str_replace(
' ',
'', $amount);
4841 $amount = str_replace($thousand,
'', $amount);
4842 $amount = str_replace($dec,
'.', $amount);
4844 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
4863function get_localtax($vatrate, $local, $thirdparty_buyer =
null, $thirdparty_seller =
null, $vatnpr = 0)
4867 if (empty($thirdparty_seller) || !is_object($thirdparty_seller)) {
4868 $thirdparty_seller =
$mysoc;
4872 "get_localtax tva=" . $vatrate .
" local=" . $local
4873 .
" thirdparty_buyer id=" . (is_object($thirdparty_buyer) ? $thirdparty_buyer->id :
'') .
"/country_code=" . (is_object($thirdparty_buyer) ? $thirdparty_buyer->country_code :
'')
4874 .
" thirdparty_seller id=" . $thirdparty_seller->id .
"/country_code=" . $thirdparty_seller->country_code
4875 .
" thirdparty_seller localtax1_assuj=" . $thirdparty_seller->localtax1_assuj .
" thirdparty_seller localtax2_assuj=" . $thirdparty_seller->localtax2_assuj
4878 $vatratecleaned = $vatrate;
4880 if (preg_match(
'/^(.*)\s*\((.*)\)$/', (
string) $vatrate, $reg)) {
4881 $vatratecleaned = trim($reg[1]);
4882 $vatratecode = $reg[2];
4891 if (
$mysoc->country_code ==
'ES') {
4893 if (!
$mysoc->localtax1_assuj || (
string) $vatratecleaned ==
"0") {
4896 if ($thirdparty_seller->id ==
$mysoc->id) {
4897 if (!$thirdparty_buyer->localtax1_assuj) {
4901 if (!$thirdparty_seller->localtax1_assuj) {
4909 if (!
$mysoc->localtax2_assuj) {
4912 if ($thirdparty_seller->id ==
$mysoc->id) {
4913 if (!$thirdparty_buyer->localtax2_assuj) {
4917 if (!$thirdparty_seller->localtax2_assuj) {
4923 if ($local == 1 && !$thirdparty_seller->localtax1_assuj) {
4926 if ($local == 2 && !$thirdparty_seller->localtax2_assuj) {
4932 if (in_array(
$mysoc->country_code, array(
'ES'))) {
4933 $conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY = 1;
4939 if ($thirdparty_seller !=
$mysoc) {
4941 return $thirdparty_seller->localtax1_value;
4950 if ($thirdparty_seller !=
$mysoc) {
4953 return $thirdparty_seller->localtax2_value;
4956 if (in_array(
$mysoc->country_code, array(
'ES'))) {
4957 return $thirdparty_buyer->localtax2_value;
4966 $sql =
"SELECT t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
4967 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t, " . MAIN_DB_PREFIX .
"c_country as c";
4968 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '" . $db->escape($thirdparty_seller->country_code) .
"'";
4969 $sql .=
" AND t.taux = " . ((float) $vatratecleaned) .
" AND t.active = 1";
4970 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
4971 if (!empty($vatratecode)) {
4972 $sql .=
" AND t.code ='" . $db->escape($vatratecode) .
"'";
4974 $sql .=
" AND t.recuperableonly = '" . $db->escape((
string) $vatnpr) .
"'";
4977 $resql = $db->query($sql);
4980 $obj = $db->fetch_object($resql);
4983 return $obj->localtax1;
4984 } elseif ($local == 2) {
4985 return $obj->localtax2;
5006 $valors = explode(
":", $tax);
5008 if (count($valors) > 1) {
5025 $sql =
" SELECT t.localtax" . ((int) $local) .
" as localtax";
5026 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t INNER JOIN " . MAIN_DB_PREFIX .
"c_country as c ON c.rowid = t.fk_pays";
5027 $sql .=
" WHERE c.code = '" . $db->escape(
$mysoc->country_code) .
"' AND t.active = 1 AND t.entity IN (" .
getEntity(
'c_tva') .
") AND t.taux = (";
5028 $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";
5029 $sql .=
" WHERE c.code = '" . $db->escape(
$mysoc->country_code) .
"' AND t.entity IN (" .
getEntity(
'c_tva') .
") AND tt.active = 1)";
5030 $sql .=
" AND t.localtax" . ((int) $local) .
"_type <> '0'";
5031 $sql .=
" ORDER BY t.rowid DESC";
5033 $resql = $db->query($sql);
5035 $obj = $db->fetch_object($resql);
5037 return $obj->localtax;
5058function getTaxesFromId($vatrate, $buyer =
null, $seller =
null, $firstparamisid = 1)
5062 dol_syslog(
"getTaxesFromId vat id or rate = " . $vatrate);
5065 $sql =
"SELECT t.rowid, t.code, t.taux as rate, t.recuperableonly as npr, t.accountancy_code_sell, t.accountancy_code_buy,";
5066 $sql .=
" t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type";
5067 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t";
5068 if ($firstparamisid) {
5069 $sql .=
" WHERE t.rowid = " . (int) $vatrate;
5071 $vatratecleaned = $vatrate;
5074 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
5075 $vatratecleaned = $reg[1];
5076 $vatratecode = $reg[2];
5079 $sql .=
", " . MAIN_DB_PREFIX .
"c_country as c";
5082 $sql .=
" WHERE t.fk_pays = c.rowid";
5084 $sql .=
" AND c.code = '" . $db->escape($buyer->country_code) .
"'";
5086 $sql .=
" AND c.code = '" . $db->escape($seller->country_code) .
"'";
5088 $sql .=
" AND t.taux = " . ((float) $vatratecleaned) .
" AND t.active = 1";
5089 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
5091 $sql .=
" AND t.code = '" . $db->escape($vatratecode) .
"'";
5095 $resql = $db->query($sql);
5097 $obj = $db->fetch_object($resql);
5100 'rowid' => $obj->rowid,
5101 'code' => $obj->code,
5102 'rate' => $obj->rate,
5103 'localtax1' => $obj->localtax1,
5104 'localtax1_type' => $obj->localtax1_type,
5105 'localtax2' => $obj->localtax2,
5106 'localtax2_type' => $obj->localtax2_type,
5108 'accountancy_code_sell' => $obj->accountancy_code_sell,
5109 'accountancy_code_buy' => $obj->accountancy_code_buy
5115 dol_print_error($db);
5141 dol_syslog(
"getLocalTaxesFromRate vatrate=" . $vatrate .
" local=" . $local);
5144 $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";
5145 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t";
5146 if ($firstparamisid) {
5147 $sql .=
" WHERE t.rowid = " . (int) $vatrate;
5149 $vatratecleaned = $vatrate;
5152 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
5153 $vatratecleaned = $reg[1];
5154 $vatratecode = $reg[2];
5157 $sql .=
", " . MAIN_DB_PREFIX .
"c_country as c";
5159 $countrycodetouse = ((empty($buyer) || empty($buyer->country_code)) ?
$mysoc->country_code : $buyer->country_code);
5160 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '" . $db->escape($countrycodetouse) .
"'";
5162 $countrycodetouse = ((empty($seller) || empty($seller->country_code)) ?
$mysoc->country_code : $seller->country_code);
5163 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '" . $db->escape($countrycodetouse) .
"'";
5165 $sql .=
" AND t.taux = " . ((float) $vatratecleaned) .
" AND t.active = 1";
5167 $sql .=
" AND t.code = '" . $db->escape($vatratecode) .
"'";
5171 $resql = $db->query($sql);
5173 $obj = $db->fetch_object($resql);
5176 $vateratestring = $obj->rate . ($obj->code ?
' (' . $obj->code .
')' :
'');
5179 return array($obj->localtax1_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
5180 } elseif ($local == 2) {
5181 return array($obj->localtax2_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
5183 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);
5205 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
5213 $product->fetch($idprod);
5215 if ((
$mysoc->country_code == $thirdpartytouseforcountry->country_code)
5216 || (in_array(
$mysoc->country_code, array(
'FR',
'MC')) && in_array($thirdpartytouseforcountry->country_code, array(
'FR',
'MC')))
5217 || (in_array(
$mysoc->country_code, array(
'MQ',
'GP')) && in_array($thirdpartytouseforcountry->country_code, array(
'MQ',
'GP')))
5220 if ($idprodfournprice > 0) {
5221 $result = $product->get_buyprice($idprodfournprice, 0, 0,
'');
5223 $ret = $product->vatrate_supplier;
5224 if ($product->default_vat_code_supplier) {
5225 $ret .=
' (' . $product->default_vat_code_supplier .
')';
5231 $ret = $product->tva_tx;
5232 if ($product->default_vat_code) {
5233 $ret .=
' (' . $product->default_vat_code .
')';
5246 $sql =
"SELECT t.taux as vat_rate, t.code as default_vat_code";
5247 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t, " . MAIN_DB_PREFIX .
"c_country as c";
5248 $sql .=
" WHERE t.active = 1 AND t.fk_pays = c.rowid AND c.code = '" . $db->escape($thirdpartytouseforcountry->country_code) .
"'";
5249 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
5250 $sql .=
" ORDER BY t.use_default DESC, t.taux DESC, t.code ASC, t.recuperableonly ASC";
5251 $sql .= $db->plimit(1);
5253 $resql = $db->query($sql);
5255 $obj = $db->fetch_object($resql);
5257 $ret = $obj->vat_rate;
5258 if ($obj->default_vat_code) {
5259 $ret .=
' (' . $obj->default_vat_code .
')';
5264 dol_print_error($db);
5283 dol_syslog(
"get_product_vat_for_country: ret=" . $ret);
5301 if (!class_exists(
'Product')) {
5302 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
5311 $result = $product->fetch($idprod);
5313 if (
$mysoc->country_code == $thirdpartytouseforcountry->country_code) {
5327 $sql =
"SELECT taux as vat_rate, localtax1, localtax2";
5328 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t, " . MAIN_DB_PREFIX .
"c_country as c";
5329 $sql .=
" WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code='" . $db->escape($thirdpartytouseforcountry->country_code) .
"'";
5330 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
5331 $sql .=
" ORDER BY t.taux DESC, t.recuperableonly ASC";
5332 $sql .= $db->plimit(1);
5334 $resql = $db->query($sql);
5336 $obj = $db->fetch_object($resql);
5339 $ret = $obj->localtax1;
5340 } elseif ($local == 2) {
5341 $ret = $obj->localtax2;
5345 dol_print_error($db);
5349 dol_syslog(
"get_product_localtax_for_country: ret=" . $ret);
5373 global
$mysoc, $db, $hookmanager;
5375 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
5378 $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;
5380 if (empty($thirdparty_seller->country_code)) {
5381 $thirdparty_seller->country_code =
$mysoc->country_code;
5383 $seller_country_code = $thirdparty_seller->country_code;
5384 $seller_in_cee =
isInEEC($thirdparty_seller);
5386 if (empty($thirdparty_buyer->country_code)) {
5387 $thirdparty_buyer->country_code =
$mysoc->country_code;
5389 $buyer_country_code = $thirdparty_buyer->country_code;
5390 $buyer_in_cee =
isInEEC($thirdparty_buyer);
5393 "get_default_tva: seller use vat=" . $seller_use_vat .
", seller country=" . $seller_country_code .
", seller in cee=" . ((
string) (
int) $seller_in_cee)
5394 .
", 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)
5395 .
", idprod=" . $idprod .
", idprodfournprice=" . $idprodfournprice .
", SERVICE_ARE_ECOMMERCE_200238EC=" .
getDolGlobalString(
'SERVICE_ARE_ECOMMERCE_200238EC')
5404 if ($seller_in_cee && $buyer_in_cee) {
5405 $isacompany = $thirdparty_buyer->
isACompany();
5406 if ($isacompany && !
getDolGlobalString(
'MAIN_USE_VAT_ZERO_FOR_COMPANIES_IN_EEC_EVEN_IF_VAT_ID_UNKNOWN')) {
5407 require_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
5415 $vatrule =
'VATRULE 0';
5421 if (empty($vatrule) && !$seller_use_vat) {
5429 $vatrule =
'VATRULE 1';
5433 if (empty($vatrule) && !empty($thirdparty_buyer->state_id)) {
5434 $sql =
"SELECT d.rowid, t.taux as vat_default_rate, t.code as vat_default_code ";
5435 $sql .=
" FROM " . $db->prefix() .
"c_tva as t";
5436 $sql .=
" INNER JOIN " . $db->prefix() .
"c_departements as d ON t.fk_department_buyer = d.rowid";
5437 $sql .=
" WHERE d.rowid = " . ((int) $thirdparty_buyer->state_id);
5438 $sql .=
" AND t.active > 0";
5439 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
5440 $sql .=
" ORDER BY t.use_default DESC, t.taux DESC, t.code ASC, t.recuperableonly ASC";
5442 $res = $db->query($sql);
5444 if ($db->num_rows($res)) {
5445 $obj = $db->fetch_object($res);
5447 $vatvalue = $obj->vat_default_rate .
' (' . $obj->vat_default_code .
')';
5448 $vatrule =
'VATRULE 2';
5455 if (empty($vatrule) && (
5456 ($seller_country_code == $buyer_country_code)
5457 || (in_array($seller_country_code, array(
'FR',
'MC')) && in_array($buyer_country_code, array(
'FR',
'MC')))
5458 || (in_array($seller_country_code, array(
'MQ',
'GP')) && in_array($buyer_country_code, array(
'MQ',
'GP')))
5463 if ($seller_country_code ==
'IN' &&
getDolGlobalString(
'MAIN_SALETAX_AUTOSWITCH_I_CS_FOR_INDIA')) {
5467 if (preg_match(
'/C+S-(\d+)/', $tmpvat, $reg) && $thirdparty_seller->state_id != $thirdparty_buyer->state_id) {
5469 $tmpvat = str_replace(
"C+S",
"I", $tmpvat);
5470 } elseif (preg_match(
'/I-(\d+)/', $tmpvat, $reg) && $thirdparty_seller->state_id == $thirdparty_buyer->state_id) {
5472 $tmpvat = str_replace(
"I",
"C+S", $tmpvat);
5476 $vatvalue = $tmpvat;
5477 $vatrule =
'VATRULE 3b';
5485 if (empty($vatrule) && ($seller_in_cee && $buyer_in_cee)) {
5486 $isacompany = $thirdparty_buyer->
isACompany();
5487 if ($isacompany && !
getDolGlobalString(
'MAIN_USE_VAT_ZERO_FOR_COMPANIES_IN_EEC_EVEN_IF_VAT_ID_UNKNOWN')) {
5488 require_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
5497 $vatrule =
'VATRULE 5';
5504 $vatrule =
'VATRULE 6';
5510 if (empty($vatrule) &&
getDolGlobalString(
'MAIN_USE_VAT_OF_PRODUCT_FOR_INDIVIDUAL_CUSTOMER_OUT_OF_EEC') && empty($buyer_in_cee)) {
5511 $isacompany = $thirdparty_buyer->
isACompany();
5514 $vatrule =
'VATRULE extra';
5527 $parameters = array(
'vatvalue' => $vatvalue,
'vatrule' => $vatrule);
5531 $reshook = $hookmanager->executeHooks(
'get_default_tva', $parameters, $tmpobject, $tmpaction);
5532 if ($reshook > 0 && !empty($hookmanager->resArray[
'vatvalue'])) {
5533 $vatvalue = $hookmanager->resArray[
'vatvalue'];
5534 $vatrule = $hookmanager->resArray[
'vatrule'];
5555 if ($idprodfournprice > 0) {
5556 if (!class_exists(
'ProductFournisseur')) {
5557 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.product.class.php';
5560 $prodprice->fetch_product_fournisseur_price($idprodfournprice);
5561 return $prodprice->fourn_tva_npr;
5562 } elseif ($idprod > 0) {
5563 if (!class_exists(
'Product')) {
5564 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
5567 $prod->fetch($idprod);
5568 return $prod->tva_npr;
5591 if (!is_object($thirdparty_seller)) {
5594 if (!is_object($thirdparty_buyer)) {
5598 if (empty($thirdparty_seller->country_code)) {
5599 $thirdparty_seller->country_code =
$mysoc->country_code;
5601 $seller_country_code = $thirdparty_seller->country_code;
5604 if (empty($thirdparty_buyer->country_code)) {
5605 $thirdparty_buyer->country_code =
$mysoc->country_code;
5607 $buyer_country_code = $thirdparty_buyer->country_code;
5611 if (
$mysoc->country_code ==
'ES') {
5612 if (is_numeric($thirdparty_buyer->localtax1_assuj) && !$thirdparty_buyer->localtax1_assuj) {
5617 if (is_numeric($thirdparty_seller->localtax1_assuj) && !$thirdparty_seller->localtax1_assuj) {
5620 if (!is_numeric($thirdparty_seller->localtax1_assuj) && $thirdparty_seller->localtax1_assuj ==
'localtax1off') {
5624 } elseif ($local == 2) {
5626 if (is_numeric($thirdparty_seller->localtax2_assuj) && !$thirdparty_seller->localtax2_assuj) {
5629 if (!is_numeric($thirdparty_seller->localtax2_assuj) && $thirdparty_seller->localtax2_assuj ==
'localtax2off') {
5634 if ($seller_country_code == $buyer_country_code) {
5660function get_exdir($num, $level, $alpha, $withoutslash,
$object, $modulepart =
'')
5662 if (empty($modulepart) && is_object(
$object)) {
5663 if (!empty(
$object->module)) {
5664 $modulepart =
$object->module;
5665 } elseif (!empty(
$object->element)) {
5666 $modulepart =
$object->element;
5673 $arrayforoldpath = array(
'cheque' => 2,
'category' => 2,
'supplier_invoice' => 2,
'invoice_supplier' => 2,
'mailing' => 2,
'supplier_payment' => 2);
5675 $arrayforoldpath[
'product'] = 2;
5678 if (empty($level) && array_key_exists($modulepart, $arrayforoldpath)) {
5679 $level = $arrayforoldpath[$modulepart];
5681 if (!empty($level) && array_key_exists($modulepart, $arrayforoldpath)) {
5683 if (empty($num) && is_object(
$object)) {
5686 if (empty($alpha)) {
5687 $num = preg_replace(
'/([^0-9])/i',
'', $num);
5689 $num = preg_replace(
'/^.*\-/i',
'', $num);
5691 $num = substr(
"000" . $num, -$level);
5693 $path = substr($num, 0, 1);
5696 $path = substr($num, 1, 1) .
'/' . substr($num, 0, 1);
5699 $path = substr($num, 2, 1) .
'/' . substr($num, 1, 1) .
'/' . substr($num, 0, 1);
5705 if (in_array($modulepart, array(
'societe',
'thirdparty')) &&
$object instanceof
Societe) {
5713 if (empty($withoutslash) && !empty($path)) {
5728function dol_mkdir($dir, $dataroot =
'', $newmask =
'')
5730 dol_syslog(
"functions.lib::dol_mkdir: dir=" . $dir, LOG_INFO);
5735 if (@is_dir($dir_osencoded)) {
5743 if (!empty($dataroot)) {
5745 $dir = str_replace($dataroot .
'/',
'', $dir);
5746 $ccdir = $dataroot .
'/';
5749 $cdir = explode(
"/", $dir);
5750 $num = count($cdir);
5751 for ($i = 0; $i < $num; $i++) {
5753 $ccdir .=
'/' . $cdir[$i];
5755 $ccdir .= $cdir[$i];
5758 if (preg_match(
"/^.:$/", $ccdir, $regs)) {
5766 if (!@is_dir($ccdir_osencoded)) {
5767 dol_syslog(
"functions.lib::dol_mkdir: Directory '" . $ccdir .
"' is not found (does not exists or is outside open_basedir PHP setting).", LOG_DEBUG);
5770 $dirmaskdec = octdec((
string) $newmask);
5771 if (empty($newmask)) {
5774 $dirmaskdec |= octdec(
'0111');
5775 if (!@mkdir($ccdir_osencoded, $dirmaskdec)) {
5777 dol_syslog(
"functions.lib::dol_mkdir: Fails to create directory '" . $ccdir .
"' (no permission to write into parent or directory already exists).", LOG_WARNING);
5780 dol_syslog(
"functions.lib::dol_mkdir: Directory '" . $ccdir .
"' created", LOG_DEBUG);
5789 return ($nberr ? -$nberr : $nbcreated);
5800function dolChmod($filepath, $newmask =
'')
5802 if (!empty($newmask)) {
5803 @chmod($filepath, octdec($newmask));
5817 return '<span class="fieldrequired">*</span>';
5837function dol_string_nohtmltag($stringtoclean, $removelinefeed = 1, $pagecodeto =
'UTF-8', $strip_tags = 0, $removedoublespaces = 1)
5839 if (is_null($stringtoclean)) {
5843 if ($removelinefeed == 2) {
5844 $stringtoclean = preg_replace(
'/<br[^>]*>(\n|\r)+/ims',
'<br>', $stringtoclean);
5846 $temp = preg_replace(
'/<br[^>]*>/i',
"\n", $stringtoclean);
5851 $temp = str_replace(
'< ',
'__ltspace__', $temp);
5852 $temp = str_replace(
'<:',
'__lttwopoints__', $temp);
5855 $temp = strip_tags($temp);
5858 $pattern =
"/<[^<>]+>/";
5865 $tempbis = str_replace(
'<>',
'', $temp);
5866 $tempbis = preg_replace($pattern,
'', $tempbis);
5868 }
while ($tempbis != $temp);
5873 $temp = preg_replace(
'/<+([a-z]+)/i',
'\1', $temp);
5879 if ($removelinefeed == 1) {
5880 $temp = str_replace(array(
"\r\n",
"\r",
"\n"),
" ", $temp);
5884 if ($removedoublespaces) {
5885 while (strpos($temp,
" ") !==
false) {
5886 $temp = str_replace(
" ",
" ", $temp);
5890 $temp = str_replace(
'__ltspace__',
'< ', $temp);
5891 $temp = str_replace(
'__lttwopoints__',
'<:', $temp);
5915function dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles = 1, $removeclassattribute = 1, $cleanalsojavascript = 0, $allowiframe = 0, $allowed_tags = array(), $allowlink = 0, $allowscript = 0, $allowstyle = 0, $allowphp = 0)
5917 $sav_allowed_tags = $allowed_tags;
5919 if (empty($allowed_tags) || (is_string($allowed_tags) && preg_match(
'/^common/', $allowed_tags))) {
5920 $allowed_tags = array(
5977 $allowed_tags[] =
"comment";
5979 if (!in_array(
'iframe', $allowed_tags)) {
5980 $allowed_tags[] =
"iframe";
5984 if (!in_array(
'link', $allowed_tags)) {
5985 $allowed_tags[] =
"link";
5987 if (!in_array(
'meta', $allowed_tags)) {
5988 $allowed_tags[] =
"meta";
5992 if (!in_array(
'script', $allowed_tags)) {
5993 $allowed_tags[] =
"script";
5997 if (!in_array(
'style', $allowed_tags)) {
5998 $allowed_tags[] =
"style";
6001 if (is_string($sav_allowed_tags)) {
6002 $tmptags = explode(
',', $sav_allowed_tags);
6003 foreach ($tmptags as $tag) {
6004 if ($tag !=
'common') {
6005 $allowed_tags[] = $tag;
6011 $allowed_tags_string = implode(
"><", $allowed_tags);
6012 $allowed_tags_string =
'<' . $allowed_tags_string .
'>';
6014 $stringtoclean = str_replace(
'<!DOCTYPE html>',
'__!DOCTYPE_HTML__', $stringtoclean);
6019 $stringtoclean = preg_replace(
'/<!--([^>]*)-->/',
'<comment>\1</comment>', $stringtoclean);
6022 $allowed_tags[] =
"commentphp";
6023 $stringtoclean = preg_replace(
'/^<\?php([^"]+)\?>$/i',
'<commentphp>\1__</commentphp>', $stringtoclean);
6024 $stringtoclean = preg_replace(
'/"<\?php([^"]+)\?>"/i',
'"<commentphp>\1</commentphp>"', $stringtoclean);
6027 $stringtoclean = preg_replace(
'/:/i',
':', $stringtoclean);
6028 $stringtoclean = preg_replace(
'/:|�+58|:/i',
'', $stringtoclean);
6031 $temp = strip_tags($stringtoclean, $allowed_tags_string);
6033 if ($cleanalsosomestyles) {
6035 $temp = preg_replace(
'/position\s*:\s*(absolute|fixed)/i',
'', $temp);
6036 $temp = preg_replace(
'/z-index\s*:/i',
'', $temp);
6038 if ($removeclassattribute) {
6039 $temp = preg_replace(
'/(<[^>]+)\s+class=((["\']).*?\\3|\\w*)/i',
'\\1', $temp);
6044 if ($cleanalsojavascript) {
6045 $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);
6048 $temp = str_replace(
'__!DOCTYPE_HTML__',
'<!DOCTYPE html>', $temp);
6051 $temp = preg_replace(
'/<commentphp>(.*)<\/commentphp>/',
'<?php\1?>', $temp);
6054 $temp = preg_replace(
'/<comment>([^>]*)<\/comment>/',
'<!--\1-->', $temp);
6076 if (is_null($allowed_attributes)) {
6077 $allowed_attributes = array(
6111 if (!in_array(
"content", $allowed_attributes)) {
6112 $allowed_attributes[] =
"content";
6114 if (!in_array(
"http-equiv", $allowed_attributes)) {
6115 $allowed_attributes[] =
"http-equiv";
6118 if (class_exists(
'DOMDocument') && !empty($stringtoclean)) {
6119 if ($ishtml === 0) {
6120 $stringtoclean = str_replace(
'&',
'__AMPINTEXT__', $stringtoclean);
6124 $dom =
new DOMDocument(
'',
'UTF-8');
6126 $savwarning = error_reporting();
6127 error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE);
6128 $wrapperId =
"dol_string_onlythesehtmlattributes___wrapper";
6129 $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);
6130 error_reporting($savwarning);
6132 if ($dom instanceof DOMDocument) {
6133 for ($els = $dom->getElementsByTagname(
'*'), $i = $els->length - 1; $i >= 0; $i--) {
6134 $el = $els->item($i);
6135 if (!$el instanceof DOMElement) {
6138 $attrs = $el->attributes;
6139 for ($ii = $attrs->length - 1; $ii >= 0; $ii--) {
6141 if (!empty($attrs->item($ii)->name)) {
6142 if (! in_array($attrs->item($ii)->name, $allowed_attributes)) {
6144 $els->item($i)->removeAttribute($attrs->item($ii)->name);
6145 } elseif (in_array($attrs->item($ii)->name, array(
'style'))) {
6147 $valuetoclean = $attrs->item($ii)->value;
6149 if (isset($valuetoclean)) {
6151 $oldvaluetoclean = $valuetoclean;
6152 $valuetoclean = preg_replace(
'/\/\*.*\*\//m',
'', $valuetoclean);
6153 $valuetoclean = preg_replace(
'/position\s*:\s*[a-z]+/mi',
'', $valuetoclean);
6154 if ($els->item($i)->tagName ==
'a') {
6155 $valuetoclean = preg_replace(
'/display\s*:/mi',
'', $valuetoclean);
6156 $valuetoclean = preg_replace(
'/z-index\s*:/mi',
'', $valuetoclean);
6157 $valuetoclean = preg_replace(
'/\s+(top|left|right|bottom)\s*:/mi',
'', $valuetoclean);
6161 $valuetoclean = preg_replace(
'/(logout|passwordforgotten)\.php/mi',
'', $valuetoclean);
6162 $valuetoclean = preg_replace(
'/action=/mi',
'', $valuetoclean);
6163 }
while ($oldvaluetoclean != $valuetoclean);
6166 $attrs->item($ii)->value = $valuetoclean;
6173 $dom->encoding =
'UTF-8';
6174 $wrapper = $dom->getElementById($wrapperId);
6176 foreach ($wrapper->childNodes as $child) {
6177 $return .= $dom->saveHTML($child);
6180 if ($ishtml === 0) {
6181 $return = str_replace(
'__AMPINTEXT__',
'&', $return);
6184 return trim($return);
6186 return $stringtoclean;
6203 $temp = $stringtoclean;
6204 foreach ($disallowed_tags as $tagtoremove) {
6205 $temp = preg_replace(
'/<\/?' . $tagtoremove .
'>/',
'', $temp);
6206 $temp = preg_replace(
'/<\/?' . $tagtoremove .
'\s+[^>]*>/',
'', $temp);
6209 if ($cleanalsosomestyles) {
6210 $temp = preg_replace(
'/position\s*:\s*(absolute|fixed)\s*!\s*important/',
'', $temp);
6228 if (!is_string($text) || $text ===
'') {
6233 $selfclosing = array(
'br',
'hr',
'img',
'input',
'meta',
'link',
'source',
'col',
'area',
'base',
'embed',
'param',
'track',
'wbr');
6236 if (preg_match_all(
'/<\s*(\/?)([a-zA-Z][a-zA-Z0-9]*)[^>]*?(\/?)\s*>/', $text, $matches, PREG_SET_ORDER)) {
6237 foreach ($matches as $match) {
6238 $tag = strtolower($match[2]);
6239 if (in_array($tag, $selfclosing) || !empty($match[3])) {
6242 if (empty($match[1])) {
6246 $idx = array_search($tag, array_reverse($opened,
true),
true);
6247 if ($idx !==
false) {
6248 unset($opened[$idx]);
6254 foreach (array_reverse($opened) as $tag) {
6255 $text .=
'</'.$tag.
'>';
6272 if ($nboflines == 1) {
6274 $firstline = preg_replace(
'/<br[^>]*>.*$/s',
'', $text);
6275 $firstline = preg_replace(
'/<div[^>]*>.*$/s',
'', $firstline);
6278 $firstline = preg_replace(
'/[\n\r].*/',
'', $text);
6283 return $firstline . (isset($firstline) && isset($text) && (strlen($firstline) != strlen($text)) ?
'...' :
'');
6287 $text = preg_replace(
'/\n/',
'', $text);
6289 $repTable = array(
"\t" =>
" ",
"\n" =>
" ",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
6291 $repTable = array(
"\t" =>
" ",
"\n" =>
"<br>",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
6294 $text = strtr($text, $repTable);
6295 if ($charset ==
'UTF-8') {
6296 $pattern =
'/(<br[^>]*>)/Uu';
6299 $pattern =
'/(<br[^>]*>)/U';
6301 $a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
6306 $lastaddediscontent = 1;
6307 while ($countline < $nboflines && isset($a[$i])) {
6308 if (preg_match(
'/<br[^>]*>/', $a[$i])) {
6309 if (array_key_exists($i + 1, $a) && !empty($a[$i + 1])) {
6310 $firstline .= ($ishtml ?
"<br>\n" :
"\n");
6312 if (!$lastaddediscontent) {
6315 $lastaddediscontent = 0;
6318 $firstline .= $a[$i];
6319 $lastaddediscontent = 1;
6325 $adddots = (isset($a[$i]) && (!preg_match(
'/<br[^>]*>/', $a[$i]) || (array_key_exists($i + 1, $a) && !empty($a[$i + 1]))));
6327 $ret = $firstline . ($adddots ?
'...' :
'');
6345function dol_nl2br($stringtoencode, $nl2brmode = 0, $forxml =
false)
6347 if (is_null($stringtoencode)) {
6352 return nl2br($stringtoencode, $forxml);
6354 $ret = preg_replace(
'/(\r\n|\r|\n)/i', ($forxml ?
'<br />' :
'<br>'), $stringtoencode);
6369function dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox = 0, $check =
'restricthtml')
6371 if (empty($nouseofiframesandbox) &&
getDolGlobalString(
'MAIN_SECURITY_USE_SANDBOX_FOR_HTMLWITHNOJS')) {
6376 return $stringtoencode;
6378 $out = $stringtoencode;
6380 $antiinfinitloop = 0;
6384 if ($antiinfinitloop >= 20) {
6385 dol_print_error(
null,
"Infinite loop detected after ".$antiinfinitloop.
" iterations in dol_htmlwithnojs");
6390 $oldstringtoclean = $out;
6398 if (!empty($out) &&
getDolGlobalInt(
'MAIN_RESTRICTHTML_ONLY_VALID_HTML') && $check !=
'restricthtmlallowunvalid') {
6400 libxml_use_internal_errors(
false);
6401 if (LIBXML_VERSION < 20900) {
6405 libxml_disable_entity_loader(
true);
6409 $out = preg_replace(
'/&(?![a-zA-Z0-9#]+;)/',
'__AMPINTEXT__', $out);
6412 $dom =
new DOMDocument();
6416 $out = preg_replace_callback(
6417 '/__\[([0-9a-zA-Z_]+)\]__/',
6423 return '__BRACKETSTART' . $m[1] .
'BRACKETEND__';
6427 $wrapperId =
"dol_htmlwithnojs___wrapper___toremove";
6428 $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);
6430 $dom->encoding =
'UTF-8';
6434 foreach ($dom->getElementsByTagName(
'*') as $el) {
6435 if (!$el instanceof DOMElement) {
6440 if ($el->hasAttribute(
'style')) {
6442 $style = $el->getAttribute(
'style');
6445 $style = preg_replace(
'/z-index\s*:/i',
'', $style);
6446 $style = preg_replace(
'/position\s*:/i',
'', $style);
6447 $style = preg_replace(
'/top\s*:/i',
'', $style);
6448 $style = preg_replace(
'/left\s*:/i',
'', $style);
6449 $style = preg_replace(
'/background\s*:/i',
'', $style);
6455 if (trim($style) ===
'') {
6457 $el->removeAttribute(
'style');
6460 $el->setAttribute(
'style', $style);
6466 $wrapper = $dom->getElementById($wrapperId);
6468 foreach ($wrapper->childNodes as $child) {
6469 $result .= $dom->saveHTML($child);
6472 $out = trim($result);
6475 $out = preg_replace_callback(
6476 '/__BRACKETSTART([0-9a-zA-Z_]+)BRACKETEND__/',
6482 return '__[' . $m[1] .
']__';
6488 $out = str_replace(
'__AMPINTEXT__',
'&', $out);
6489 $out = preg_replace(
'/<br\s*\/?>/i',
"\n", $out);
6494 $out =
'InvalidHTMLStringCantBeCleaned ' . $e->getMessage();
6501 if (!empty($out) &&
getDolGlobalInt(
'MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY') && !in_array($check, array(
'restricthtmlallowunvalid',
'restricthtmlallowlinkscript')) && $outishtml) {
6507 if (extension_loaded(
'tidy') && class_exists(
"tidy")) {
6514 'quote-marks' =>
false,
6515 'doctype' =>
'strict',
6516 'show-body-only' =>
true,
6517 "indent-attributes" =>
false,
6518 "vertical-space" =>
false,
6521 'preserve-entities' =>
true
6530 $locale = setlocale(LC_NUMERIC,
'0');
6533 $out = $tidy->repairString($out, $config,
'utf8');
6535 setlocale(LC_NUMERIC, $locale);
6544 $out =
'InvalidHTMLStringCantBeCleaned ' . $e->getMessage();
6550 $out = preg_replace(
'/[\x{200B}-\x{200D}\x{FEFF}]/u',
' ', $out);
6553 $out = preg_replace(
'/&(tab|newline);/i',
' ', $out);
6557 $out = preg_replace(
'/'/i',
''', $out);
6562 if (function_exists(
'realCharForNumericEntities')) {
6563 $out = preg_replace_callback(
6564 '/&#(x?[0-9][0-9a-f]+;?)/i',
6569 static function ($m) {
6577 $out = preg_replace(
'/&#x?[0-9]+/i',
'', $out);
6580 if ($check ==
'restricthtmlallowlinkscript') {
6582 } elseif ($check ==
'restricthtmlallowclass' || $check ==
'restricthtmlallowunvalid') {
6584 } elseif ($check ==
'restricthtmlallowiframe') {
6597 $out = preg_replace(
'/'/i',
"'", $out);
6601 $out = preg_replace(
'/on(mouse|drag|key|load|touch|pointer|select|transition)[a-z]*\s*=/i',
'', $out);
6602 $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);
6603 $out = preg_replace(
'/on(dblclick|drop|durationchange|emptied|end|ended|error|focus(in|out)?|formdata|gotpointercapture|hashchange|input|invalid)[a-z]*\s*=/i',
'', $out);
6604 $out = preg_replace(
'/on(lost|offline|online|message|pagehide|pageshow)[a-z]*\s*=/i',
'', $out);
6605 $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);
6606 $out = preg_replace(
'/on(timeupdate|toggle|unhandled|unload|volumechange|waiting|wheel)[a-z]*\s*=/i',
'', $out);
6608 $out = preg_replace(
'/on(repeat|begin|finish|beforeinput)[a-z]*\s*=/i',
'', $out);
6610 $out = preg_replace(
'/\son[a-z]+\s*=/i',
' ', $out);
6611 }
while ($oldstringtoclean != $out);
6618 $tmpout = preg_replace(
'/<img src="data:/mi',
'<__IMG_SRC_DATA__ src="data:', $out);
6619 preg_match_all(
'/(<img|url\(|<link)/i', $tmpout, $reg);
6620 $nblinks = count($reg[0]);
6621 if ($nblinks >
getDolGlobalInt(
"MAIN_SECURITY_MAX_IMG_IN_HTML_CONTENT", 1000)) {
6622 $out =
'ErrorTooManyLinksIntoHTMLString';
6625 if (
getDolGlobalInt(
'MAIN_DISALLOW_URL_INTO_DESCRIPTIONS') == 2 || $check ==
'restricthtmlnolink') {
6627 $out =
'ErrorHTMLLinksNotAllowed';
6629 } elseif (
getDolGlobalInt(
'MAIN_DISALLOW_URL_INTO_DESCRIPTIONS') == 1) {
6634 $pattern =
'/src=["\']?(http[^"\']+)|url\(["\']?(http[^\)]+)/';
6639 if (preg_match_all($pattern, $out, $matches)) {
6642 foreach ($matches[1] as $tmpval) {
6643 if (!empty($tmpval)) {
6647 foreach ($matches[2] as $tmpval) {
6648 if (!empty($tmpval)) {
6656 foreach ($urls as $url) {
6658 $parsedurl = parse_url($url);
6659 if (!empty($parsedurl)) {
6668 if (empty($firstexturl)) {
6669 $firstexturl = $url;
6670 } elseif (empty($secondexturl)) {
6671 $secondexturl = $url;
6677 $out =
'ErrorHTMLExternalLinksNotAllowed (Example: '.$firstexturl.($secondexturl ?
' '.$secondexturl :
'').
')';
6706function dol_htmlentitiesbr($stringtoencode, $nl2brmode = 0, $pagecodefrom =
'UTF-8', $removelasteolbr = 1)
6708 if (is_null($stringtoencode)) {
6712 $newstring = $stringtoencode;
6714 $newstring = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>/i',
'<br>', $newstring);
6715 if ($removelasteolbr) {
6716 $newstring = preg_replace(
'/<br>$/i',
'', $newstring);
6718 $newstring = preg_replace(
'/[\x{200B}-\x{200D}\x{FEFF}]/u',
' ', $newstring);
6719 $newstring = strtr($newstring, array(
'&' =>
'__PROTECTand__',
'<' =>
'__PROTECTlt__',
'>' =>
'__PROTECTgt__',
'"' =>
'__PROTECTdquot__'));
6721 $newstring = strtr($newstring, array(
'__PROTECTand__' =>
'&',
'__PROTECTlt__' =>
'<',
'__PROTECTgt__' =>
'>',
'__PROTECTdquot__' =>
'"'));
6723 if ($removelasteolbr) {
6724 $newstring = preg_replace(
'/(\r\n|\r|\n)$/i',
'', $newstring);
6743 $ret = preg_replace(
'/' .
"\r\n" .
'<br(\s[\sa-zA-Z_="]*)?\/?>/i',
"<br>", $ret);
6744 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>' .
"\r\n" .
'/i',
"\r\n", $ret);
6745 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>' .
"\n" .
'/i',
"\n", $ret);
6746 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>/i',
"\n", $ret);
6758 $ret = preg_replace(
'/ $/i',
"", $stringtodecode);
6759 $ret = preg_replace(
'/(<br>|<br(\s[\sa-zA-Z_="]*)?\/?>|' .
"\n" .
'|' .
"\r" .
')+$/i',
"", $ret);
6775 if ($keepsomeentities) {
6776 $newstring = strtr($newstring, array(
'&' =>
'__andamp__',
'<' =>
'__andlt__',
'>' =>
'__andgt__',
'"' =>
'__dquot__'));
6778 $newstring = html_entity_decode((
string) $newstring, (
int) $b, (
string)
$c);
6779 if ($keepsomeentities) {
6780 $newstring = strtr($newstring, array(
'__andamp__' =>
'&',
'__andlt__' =>
'<',
'__andgt__' =>
'>',
'__dquot__' =>
'"'));
6796function dol_htmlentities($string, $flags = ENT_QUOTES | ENT_SUBSTITUTE, $encoding =
'UTF-8', $double_encode =
false)
6798 return htmlentities($string, $flags, $encoding, $double_encode);
6817 for ($scursor = 0; $scursor < $len; $scursor++) {
6818 $ordchar = ord($s[$scursor]);
6820 if ($ordchar < 32 && $ordchar != 13 && $ordchar != 10) {
6823 } elseif ($ordchar > 126 && $ordchar < 160) {
6827 $out .= $s[$scursor];
6849 $arraystring = explode(
"\n", $s);
6850 $nb = count($arraystring);
6867 $repTable = array(
"\t" =>
" ",
"\n" =>
"<br>",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
6869 $repTable = array(
"\t" =>
" ",
"\n" =>
" ",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
6872 $text = strtr($text, $repTable);
6873 if ($charset ==
'UTF-8') {
6874 $pattern =
'/(<br[^>]*>)/Uu';
6877 $pattern =
'/(<br[^>]*>)/U';
6879 $a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
6881 $nblines = (int) floor((count($a) + 1) / 2);
6884 foreach ($a as $line) {
6887 $line_dec = html_entity_decode($line);
6889 $line_dec = wordwrap($line_dec, $maxlinesize,
'\n',
true);
6890 $nblines += substr_count($line_dec,
'\n');
6910 if (is_null($msg)) {
6916 if (strpos($msg,
'<') ===
false && strpos($msg,
'&') ===
false) {
6921 if (preg_match(
'/<(html|link|script)/i', $msg)) {
6923 } elseif (preg_match(
'/<body/i', $msg)) {
6925 } elseif (preg_match(
'/<\/textarea/i', $msg)) {
6927 } elseif (preg_match(
'/<(b|em|i|u)(\s+[^>]+)?>/i', $msg)) {
6929 } elseif (preg_match(
'/<br/i', $msg)) {
6935 $msg = preg_replace(
'/https?:\/\/[^"\'\s]+/i',
'', $msg);
6936 if (preg_match(
'/<(html|link|script|body)/i', $msg)) {
6938 } elseif (preg_match(
'/<\/textarea/i', $msg)) {
6940 } elseif (preg_match(
'/<(b|em|i|u)(\s+[^>]+)?>/i', $msg)) {
6942 } elseif (preg_match(
'/<(br|hr)\/>/i', $msg)) {
6944 } elseif (preg_match(
'/<(br|hr|div|font|li|p|span|strong|table)>/i', $msg)) {
6946 } elseif (preg_match(
'/<(br|hr|div|font|li|p|span|strong|table)\s+[^<>\/]*\/?>/i', $msg)) {
6948 } elseif (preg_match(
'/<img\s+[^<>]*src[^<>]*>/i', $msg)) {
6950 } elseif (preg_match(
'/<a\s+[^<>]*href[^<>]*>/i', $msg)) {
6952 } elseif (preg_match(
'/<h[0-9]>/i', $msg)) {
6954 } elseif (preg_match(
'/&[A-Z0-9]{1,6};/i', $msg)) {
6957 } elseif (preg_match(
'/&#[0-9]{2,3};/i', $msg)) {
6959 } elseif (preg_match(
'/&#x[a-f0-9][a-f0-9];/i', $msg)) {
6981function dol_concatdesc($text1, $text2, $forxml =
false, $invert =
false)
6983 if (!empty($invert)) {
6991 $ret .= (!empty($text1) && !empty($text2)) ? ((
dol_textishtml($text1) ||
dol_textishtml($text2)) ? ($forxml ?
"<br >\n" :
"<br>\n") :
"\n") :
"";
7006 return $text1.$text2;
7018 if (!is_string($callback)) {
7019 throw new InvalidArgumentException(
"Les callbacks sont désactivés.");
7022 $allowed_callbacks = [
'strtolower',
'strtoupper',
'intval'];
7023 if (!in_array($callback, $allowed_callbacks,
true)) {
7024 throw new InvalidArgumentException(
"Callback function not allowed.");
7026 return array_map($callback, $array);
7043function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude =
null,
$object =
null, $include =
null)
7047 $substitutionarray = array();
7049 if ((empty($exclude) || !in_array(
'user', $exclude)) && (empty($include) || in_array(
'user', $include)) && $user instanceof
User) {
7053 $emailsendersignature = $user->signature;
7054 $usersignature = $user->signature;
7055 if (
getDolGlobalString(
'MAIN_MAIL_DEFAULT_SIGNATURE_FOR_ALL_USERS') && !empty($user->employee)) {
7056 $emailsendersignature =
getDolGlobalString(
'MAIN_MAIL_DEFAULT_SIGNATURE_FOR_ALL_USERS');
7059 $substitutionarray = array_merge($substitutionarray, array(
7060 '__SENDEREMAIL_SIGNATURE__' => (
string) ((!
getDolGlobalString(
'MAIN_MAIL_DO_NOT_USE_SIGN')) ? ($onlykey == 2 ?
dol_trunc(
'SignatureFromTheSelectedSenderProfile', 30) : $emailsendersignature) :
''),
7064 if (is_object($user) && ($user instanceof
User)) {
7065 $substitutionarray = array_merge($substitutionarray, array(
7066 '__USER_ID__' => (
string) $user->id,
7067 '__USER_LOGIN__' => (
string) $user->login,
7068 '__USER_EMAIL__' => (
string) $user->email,
7069 '__USER_PHONE__' => (
string)
dol_print_phone($user->office_phone,
'', 0, 0,
'',
" ",
'',
'', -1),
7070 '__USER_PHONEPRO__' => (
string)
dol_print_phone($user->user_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
7071 '__USER_PHONEMOBILE__' => (
string)
dol_print_phone($user->personal_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
7072 '__USER_FAX__' => (
string) $user->office_fax,
7073 '__USER_LASTNAME__' => (
string) $user->lastname,
7074 '__USER_FIRSTNAME__' => (
string) $user->firstname,
7075 '__USER_FULLNAME__' => (
string) $user->getFullName($outputlangs),
7076 '__USER_SUPERVISOR_ID__' => (
string) ($user->fk_user ? $user->fk_user :
'0'),
7077 '__USER_JOB__' => (string) $user->job,
7079 '__USER_VCARD_URL__' => (string) $user->getOnlineVirtualCardUrl(
'',
'external')
7082 $substitutionarray = array_merge($substitutionarray, array(
7083 '__USER_WAREHOUSE_ID__' => isset($user->warehouse->id) ? $user->warehouse->id :
'',
7084 '__USER_WAREHOUSE_REF__' => isset($user->warehouse->
ref) ? $user->warehouse->
ref :
'',
7085 '__USER_WAREHOUSE_DESCRIPTION__' => isset($user->warehouse->
description) ? $user->warehouse->
description :
'',
7086 '__USER_WAREHOUSE_ADDRESS__' => isset($user->warehouse->
address) ? $user->warehouse->
address :
'',
7087 '__USER_WAREHOUSE_ZIP__' => isset($user->warehouse->zip) ? $user->warehouse->zip :
'',
7088 '__USER_WAREHOUSE_TOWN__' => isset($user->warehouse->town) ? $user->warehouse->town :
'',
7089 '__USER_WAREHOUSE_PHONE__' => isset($user->warehouse->phone) ? (string)
dol_print_phone($user->warehouse->phone,
'', 0, 0,
'',
" ",
'',
'', -1) :
'',
7090 '__USER_WAREHOUSE_FAX__' => isset($user->warehouse->fax) ? (string)
dol_print_phone($user->warehouse->fax,
'', 0, 0,
'',
" ",
'',
'', -1) :
''
7095 if ((empty($exclude) || !in_array(
'mycompany', $exclude)) && is_object(
$mysoc) && (empty($include) || in_array(
'mycompany', $include))) {
7096 $substitutionarray = array_merge($substitutionarray, array(
7097 '__MYCOMPANY_NAME__' =>
$mysoc->name,
7098 '__MYCOMPANY_EMAIL__' =>
$mysoc->email,
7099 '__MYCOMPANY_URL__' =>
$mysoc->url,
7101 '__MYCOMPANY_PHONEMOBILE__' =>
dol_print_phone((
string)
$mysoc->phone_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
7103 '__MYCOMPANY_PROFID1__' =>
$mysoc->idprof1,
7104 '__MYCOMPANY_PROFID2__' =>
$mysoc->idprof2,
7105 '__MYCOMPANY_PROFID3__' =>
$mysoc->idprof3,
7106 '__MYCOMPANY_PROFID4__' =>
$mysoc->idprof4,
7107 '__MYCOMPANY_PROFID5__' =>
$mysoc->idprof5,
7108 '__MYCOMPANY_PROFID6__' =>
$mysoc->idprof6,
7109 '__MYCOMPANY_PROFID7__' =>
$mysoc->idprof7,
7110 '__MYCOMPANY_PROFID8__' =>
$mysoc->idprof8,
7111 '__MYCOMPANY_PROFID9__' =>
$mysoc->idprof9,
7112 '__MYCOMPANY_PROFID10__' =>
$mysoc->idprof10,
7113 '__MYCOMPANY_OBJECT__' =>
$mysoc->socialobject,
7114 '__MYCOMPANY_CAPITAL__' =>
$mysoc->capital,
7115 '__MYCOMPANY_FULLADDRESS__' => (method_exists(
$mysoc,
'getFullAddress') ?
$mysoc->getFullAddress(1,
', ') :
''),
7117 '__MYCOMPANY_VATNUMBER__' =>
$mysoc->tva_intra,
7118 '__MYCOMPANY_ZIP__' =>
$mysoc->zip,
7119 '__MYCOMPANY_TOWN__' =>
$mysoc->town,
7120 '__MYCOMPANY_STATE__' =>
$mysoc->state,
7121 '__MYCOMPANY_COUNTRY__' =>
$mysoc->country,
7122 '__MYCOMPANY_COUNTRY_ID__' =>
$mysoc->country_id,
7123 '__MYCOMPANY_COUNTRY_CODE__' =>
$mysoc->country_code,
7124 '__MYCOMPANY_CURRENCY__' => $outputlangs->transnoentitiesnoconv(
"Currency".
$conf->currency),
7125 '__MYCOMPANY_CURRENCY_CODE__' =>
$conf->currency
7129 if (($onlykey || is_object(
$object)) && (empty($exclude) || !in_array(
'object', $exclude)) && (empty($include) || in_array(
'object', $include))) {
7131 $substitutionarray[
'__ID__'] =
'__ID__';
7132 $substitutionarray[
'__REF__'] =
'__REF__';
7133 $substitutionarray[
'__NEWREF__'] =
'__NEWREF__';
7134 $substitutionarray[
'__LABEL__'] =
'__LABEL__';
7135 $substitutionarray[
'__REF_CLIENT__'] =
'__REF_CLIENT__';
7136 $substitutionarray[
'__REF_SUPPLIER__'] =
'__REF_SUPPLIER__';
7137 $substitutionarray[
'__NOTE_PUBLIC__'] =
'__NOTE_PUBLIC__';
7138 $substitutionarray[
'__NOTE_PRIVATE__'] =
'__NOTE_PRIVATE__';
7139 $substitutionarray[
'__EXTRAFIELD_XXX__'] =
'__EXTRAFIELD_XXX__';
7142 $substitutionarray[
'__THIRDPARTY_ID__'] =
'__THIRDPARTY_ID__';
7143 $substitutionarray[
'__THIRDPARTY_NAME__'] =
'__THIRDPARTY_NAME__';
7144 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] =
'__THIRDPARTY_NAME_ALIAS__';
7145 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] =
'__THIRDPARTY_CODE_CLIENT__';
7146 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] =
'__THIRDPARTY_CODE_FOURNISSEUR__';
7147 $substitutionarray[
'__THIRDPARTY_EMAIL__'] =
'__THIRDPARTY_EMAIL__';
7149 $substitutionarray[
'__THIRDPARTY_URL__'] =
'__THIRDPARTY_URL__';
7151 $substitutionarray[
'__THIRDPARTY_PHONE__'] =
'__THIRDPARTY_PHONE__';
7152 $substitutionarray[
'__THIRDPARTY_FAX__'] =
'__THIRDPARTY_FAX__';
7153 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] =
'__THIRDPARTY_ADDRESS__';
7154 $substitutionarray[
'__THIRDPARTY_ZIP__'] =
'__THIRDPARTY_ZIP__';
7155 $substitutionarray[
'__THIRDPARTY_TOWN__'] =
'__THIRDPARTY_TOWN__';
7156 $substitutionarray[
'__THIRDPARTY_STATE__'] =
'__THIRDPARTY_STATE__';
7157 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] =
'__THIRDPARTY_IDPROF1__';
7158 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] =
'__THIRDPARTY_IDPROF2__';
7159 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] =
'__THIRDPARTY_IDPROF3__';
7160 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] =
'__THIRDPARTY_IDPROF4__';
7161 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] =
'__THIRDPARTY_IDPROF5__';
7162 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] =
'__THIRDPARTY_IDPROF6__';
7163 $substitutionarray[
'__THIRDPARTY_IDPROF7__'] =
'__THIRDPARTY_IDPROF7__';
7164 $substitutionarray[
'__THIRDPARTY_IDPROF8__'] =
'__THIRDPARTY_IDPROF8__';
7165 $substitutionarray[
'__THIRDPARTY_IDPROF9__'] =
'__THIRDPARTY_IDPROF9__';
7166 $substitutionarray[
'__THIRDPARTY_IDPROF10__'] =
'__THIRDPARTY_IDPROF10__';
7167 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] =
'__THIRDPARTY_TVAINTRA__';
7168 $substitutionarray[
'__THIRDPARTY_NOTE_PUBLIC__'] =
'__THIRDPARTY_NOTE_PUBLIC__';
7169 $substitutionarray[
'__THIRDPARTY_NOTE_PRIVATE__'] =
'__THIRDPARTY_NOTE_PRIVATE__';
7171 if (
isModEnabled(
'member') && (!is_object(
$object) ||
$object->element ==
'adherent') && (empty($exclude) || !in_array(
'member', $exclude)) && (empty($include) || in_array(
'member', $include))) {
7172 $substitutionarray[
'__MEMBER_ID__'] =
'__MEMBER_ID__';
7173 $substitutionarray[
'__MEMBER_TITLE__'] =
'__MEMBER_TITLE__';
7174 $substitutionarray[
'__MEMBER_FIRSTNAME__'] =
'__MEMBER_FIRSTNAME__';
7175 $substitutionarray[
'__MEMBER_LASTNAME__'] =
'__MEMBER_LASTNAME__';
7176 $substitutionarray[
'__MEMBER_USER_LOGIN_INFORMATION__'] =
'Login and pass of the external user account';
7181 if (
isModEnabled(
'ticket') && (!is_object(
$object) ||
$object->element ==
'ticket') && (empty($exclude) || !in_array(
'ticket', $exclude)) && (empty($include) || in_array(
'ticket', $include))) {
7182 $substitutionarray[
'__TICKET_TRACKID__'] =
'__TICKET_TRACKID__';
7183 $substitutionarray[
'__TICKET_SUBJECT__'] =
'__TICKET_SUBJECT__';
7184 $substitutionarray[
'__TICKET_TYPE__'] =
'__TICKET_TYPE__';
7185 $substitutionarray[
'__TICKET_SEVERITY__'] =
'__TICKET_SEVERITY__';
7186 $substitutionarray[
'__TICKET_CATEGORY__'] =
'__TICKET_CATEGORY__';
7187 $substitutionarray[
'__TICKET_ANALYTIC_CODE__'] =
'__TICKET_ANALYTIC_CODE__';
7188 $substitutionarray[
'__TICKET_MESSAGE__'] =
'__TICKET_MESSAGE__';
7189 $substitutionarray[
'__TICKET_PROGRESSION__'] =
'__TICKET_PROGRESSION__';
7190 $substitutionarray[
'__TICKET_USER_ASSIGN__'] =
'__TICKET_USER_ASSIGN__';
7191 $substitutionarray[
'__TICKET_TYPE_LABEL__'] =
'__TICKET_TYPE_LABEL__';
7192 $substitutionarray[
'__TICKET_SEVERITY_LABEL__'] =
'__TICKET_SEVERITY_LABEL__';
7193 $substitutionarray[
'__TICKET_CATEGORY_LABEL__'] =
'__TICKET_CATEGORY_LABEL__';
7194 $substitutionarray[
'__TICKET_PUBLIC_URL__'] =
'__TICKET_PUBLIC_URL__';
7195 $substitutionarray[
'__TICKET_MANAGEMENT_URL__'] =
'__TICKET_MANAGEMENT_URL__';
7197 if (
isModEnabled(
'recruitment') && (!is_object(
$object) ||
$object->element ==
'recruitmentcandidature') && (empty($exclude) || !in_array(
'recruitment', $exclude)) && (empty($include) || in_array(
'recruitment', $include))) {
7198 $substitutionarray[
'__CANDIDATE_FULLNAME__'] =
'__CANDIDATE_FULLNAME__';
7199 $substitutionarray[
'__CANDIDATE_FIRSTNAME__'] =
'__CANDIDATE_FIRSTNAME__';
7200 $substitutionarray[
'__CANDIDATE_LASTNAME__'] =
'__CANDIDATE_LASTNAME__';
7202 if (
isModEnabled(
'holiday') && (!is_object(
$object) ||
$object->element ==
'holiday') && (empty($exclude) || !in_array(
'holiday', $exclude)) && (empty($include) || in_array(
'holiday', $include))) {
7203 $substitutionarray[
'__HOLIDAY_ARRAY_PER_EMPLOYEE_FOR_PERIOD__'] =
'__HOLIDAY_ARRAY_PER_EMPLOYEE_FOR_PERIOD__';
7205 if (
isModEnabled(
'project') && (empty($exclude) || !in_array(
'project', $exclude)) && (empty($include) || in_array(
'project', $include))) {
7206 $substitutionarray[
'__PROJECT_ID__'] =
'__PROJECT_ID__';
7207 $substitutionarray[
'__PROJECT_REF__'] =
'__PROJECT_REF__';
7208 $substitutionarray[
'__PROJECT_NAME__'] =
'__PROJECT_NAME__';
7212 if (
isModEnabled(
'contract') && (!is_object(
$object) ||
$object->element ==
'contract') && (empty($exclude) || !in_array(
'contract', $exclude)) && (empty($include) || in_array(
'contract', $include))) {
7213 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE__'] =
'Highest date planned for a service start';
7214 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATETIME__'] =
'Highest date and hour planned for service start';
7215 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE__'] =
'Lowest data for planned expiration of service';
7216 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATETIME__'] =
'Lowest date and hour for planned expiration of service';
7218 if (
isModEnabled(
"propal") && (!is_object(
$object) ||
$object->element ==
'propal') && (empty($exclude) || !in_array(
'propal', $exclude)) && (empty($include) || in_array(
'propal', $include))) {
7219 $substitutionarray[
'__ONLINE_SIGN_URL__'] =
'ToOfferALinkForOnlineSignature';
7221 if (
isModEnabled(
"intervention") && (!is_object(
$object) ||
$object->element ==
'fichinter') && (empty($exclude) || !in_array(
'intervention', $exclude)) && (empty($include) || in_array(
'intervention', $include))) {
7222 $substitutionarray[
'__ONLINE_SIGN_FICHINTER_URL__'] =
'ToOfferALinkForOnlineSignature';
7224 $substitutionarray[
'__ONLINE_PAYMENT_URL__'] =
'UrlToPayOnlineIfApplicable';
7225 $substitutionarray[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'TextAndUrlToPayOnlineIfApplicable';
7226 $substitutionarray[
'__SECUREKEYPAYMENT__'] =
'Security key (if key is not unique per record)';
7227 $substitutionarray[
'__SECUREKEYPAYMENT_MEMBER__'] =
'Security key for payment on a member subscription (one key per member)';
7228 $substitutionarray[
'__SECUREKEYPAYMENT_ORDER__'] =
'Security key for payment on an order';
7229 $substitutionarray[
'__SECUREKEYPAYMENT_INVOICE__'] =
'Security key for payment on an invoice';
7230 $substitutionarray[
'__SECUREKEYPAYMENT_CONTRACTLINE__'] =
'Security key for payment on a service of a contract';
7232 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
'Direct download url of a proposal';
7233 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
'Direct download url of an order';
7234 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
'Direct download url of an invoice';
7235 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
'Direct download url of a contract';
7236 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
'Direct download url of a supplier proposal';
7237 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_ORDER__'] =
'Direct download url of a supplier order';
7238 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_INVOICE__'] =
'Direct download url of a supplier invoice';
7241 $substitutionarray[
'__SHIPPINGTRACKNUM__'] =
'Shipping tracking number';
7242 $substitutionarray[
'__SHIPPINGTRACKNUMURL__'] =
'Shipping tracking url';
7243 $substitutionarray[
'__SHIPPINGMETHOD__'] =
'Shipping method';
7246 $substitutionarray[
'__RECEPTIONTRACKNUM__'] =
'Shipping tracking number of shipment';
7247 $substitutionarray[
'__RECEPTIONTRACKNUMURL__'] =
'Shipping tracking url';
7250 '@phan-var-force Adherent|Delivery $object';
7252 $substitutionarray[
'__ID__'] =
$object->id;
7253 $substitutionarray[
'__REF__'] =
$object->ref;
7254 $substitutionarray[
'__NEWREF__'] =
$object->newref;
7256 $substitutionarray[
'__REF_CLIENT__'] = (isset(
$object->ref_client) ?
$object->ref_client : (isset(
$object->ref_customer) ?
$object->ref_customer :
null));
7257 $substitutionarray[
'__REF_SUPPLIER__'] = (isset(
$object->ref_supplier) ?
$object->ref_supplier :
null);
7258 $substitutionarray[
'__NOTE_PUBLIC__'] = (isset(
$object->note_public) ?
$object->note_public :
null);
7259 $substitutionarray[
'__NOTE_PRIVATE__'] = (isset(
$object->note_private) ?
$object->note_private :
null);
7261 $substitutionarray[
'__DATE_CREATION__'] = (isset(
$object->date_creation) ?
dol_print_date(
$object->date_creation,
'day',
false, $outputlangs) :
'');
7262 $substitutionarray[
'__DATE_MODIFICATION__'] = (isset(
$object->date_modification) ?
dol_print_date(
$object->date_modification,
'day',
false, $outputlangs) :
'');
7263 $substitutionarray[
'__DATE_VALIDATION__'] = (isset(
$object->date_validation) ?
dol_print_date(
$object->date_validation,
'day',
false, $outputlangs) :
'');
7266 $date_delivery =
null;
7267 if (property_exists(
$object,
'date_delivery')) {
7268 $date_delivery =
$object->date_delivery;
7269 } elseif (property_exists(
$object,
'delivery_date')) {
7270 $date_delivery =
$object->delivery_date;
7272 $substitutionarray[
'__DATE_DELIVERY__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
'day',
false, $outputlangs) :
'');
7273 $substitutionarray[
'__DATE_DELIVERY_DAY__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%d") :
'');
7274 $substitutionarray[
'__DATE_DELIVERY_DAY_TEXT__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%A") :
'');
7275 $substitutionarray[
'__DATE_DELIVERY_MON__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%m") :
'');
7276 $substitutionarray[
'__DATE_DELIVERY_MON_TEXT__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%b") :
'');
7277 $substitutionarray[
'__DATE_DELIVERY_YEAR__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%Y") :
'');
7278 $substitutionarray[
'__DATE_DELIVERY_HH__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%H") :
'');
7279 $substitutionarray[
'__DATE_DELIVERY_MM__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%M") :
'');
7280 $substitutionarray[
'__DATE_DELIVERY_SS__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%S") :
'');
7283 $substitutionarray[
'__REFCLIENT__'] = (isset(
$object->ref_client) ?
$object->ref_client : (isset(
$object->ref_customer) ?
$object->ref_customer :
null));
7284 $substitutionarray[
'__REFSUPPLIER__'] = (isset(
$object->ref_supplier) ?
$object->ref_supplier :
null);
7286 $substitutionarray[
'__SUPPLIER_ORDER_DATE_DELIVERY__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
'day',
false, $outputlangs) :
'');
7287 $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 :
'')) :
'');
7291 '@phan-var-force Adherent $object';
7295 $substitutionarray[
'__MEMBER_ID__'] = (isset(
$object->id) ?
$object->id :
'');
7296 if (method_exists(
$object,
'getCivilityLabel')) {
7297 $substitutionarray[
'__MEMBER_TITLE__'] =
$object->getCivilityLabel();
7299 $substitutionarray[
'__MEMBER_FIRSTNAME__'] = (isset(
$object->firstname) ?
$object->firstname :
'');
7300 $substitutionarray[
'__MEMBER_LASTNAME__'] = (isset(
$object->lastname) ?
$object->lastname :
'');
7301 $substitutionarray[
'__MEMBER_USER_LOGIN_INFORMATION__'] =
'';
7302 if (method_exists(
$object,
'getFullName')) {
7303 $substitutionarray[
'__MEMBER_FULLNAME__'] =
$object->getFullName($outputlangs);
7305 $substitutionarray[
'__MEMBER_COMPANY__'] = (isset(
$object->societe) ?
$object->societe :
'');
7306 $substitutionarray[
'__MEMBER_ADDRESS__'] = (isset(
$object->address) ?
$object->address :
'');
7307 $substitutionarray[
'__MEMBER_ZIP__'] = (isset(
$object->zip) ?
$object->zip :
'');
7308 $substitutionarray[
'__MEMBER_TOWN__'] = (isset(
$object->town) ?
$object->town :
'');
7309 $substitutionarray[
'__MEMBER_STATE__'] = (isset(
$object->state) ?
$object->state :
'');
7310 $substitutionarray[
'__MEMBER_COUNTRY__'] = (isset(
$object->country) ?
$object->country :
'');
7311 $substitutionarray[
'__MEMBER_EMAIL__'] = (isset(
$object->email) ?
$object->email :
'');
7312 $substitutionarray[
'__MEMBER_BIRTH__'] = (isset($birthday) ? $birthday :
'');
7313 $substitutionarray[
'__MEMBER_PHOTO__'] = (isset(
$object->photo) ?
$object->photo :
'');
7314 $substitutionarray[
'__MEMBER_LOGIN__'] = (isset(
$object->login) ?
$object->login :
'');
7315 $substitutionarray[
'__MEMBER_PASSWORD__'] = (isset(
$object->pass) ?
$object->pass :
'');
7319 $substitutionarray[
'__MEMBER_TYPE__'] = (isset(
$object->type) ?
$object->type :
'');
7320 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE__'] =
dol_print_date(
$object->first_subscription_date,
'day');
7322 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_RFC__'] =
dol_print_date(
$object->first_subscription_date,
'dayrfc');
7323 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_START__'] = (isset(
$object->first_subscription_date_start) ?
dol_print_date(
$object->first_subscription_date_start,
'day') :
'');
7324 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_START_RFC__'] = (isset(
$object->first_subscription_date_start) ?
dol_print_date(
$object->first_subscription_date_start,
'dayrfc') :
'');
7325 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_END__'] = (isset(
$object->first_subscription_date_end) ?
dol_print_date(
$object->first_subscription_date_end,
'day') :
'');
7326 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_END_RFC__'] = (isset(
$object->first_subscription_date_end) ?
dol_print_date(
$object->first_subscription_date_end,
'dayrfc') :
'');
7327 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE__'] =
dol_print_date(
$object->last_subscription_date,
'day');
7328 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_RFC__'] =
dol_print_date(
$object->last_subscription_date,
'dayrfc');
7329 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_START__'] =
dol_print_date(
$object->last_subscription_date_start,
'day');
7330 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_START_RFC__'] =
dol_print_date(
$object->last_subscription_date_start,
'dayrfc');
7331 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_END__'] =
dol_print_date(
$object->last_subscription_date_end,
'day');
7332 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_END_RFC__'] =
dol_print_date(
$object->last_subscription_date_end,
'dayrfc');
7337 '@phan-var-force Societe $object';
7338 $substitutionarray[
'__THIRDPARTY_ID__'] =
$object->id ??
'';
7339 $substitutionarray[
'__THIRDPARTY_NAME__'] =
$object->name ??
'';
7340 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] =
$object->name_alias ??
'';
7341 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] =
$object->code_client ??
'';
7342 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] =
$object->code_fournisseur ??
'';
7343 $substitutionarray[
'__THIRDPARTY_EMAIL__'] =
$object->email ??
'';
7344 $substitutionarray[
'__THIRDPARTY_EMAIL_URLENCODED__'] = urlencode(
$object->email ??
'');
7345 $substitutionarray[
'__THIRDPARTY_URL__'] =
$object->url ??
'';
7346 $substitutionarray[
'__THIRDPARTY_URL_URLENCODED__'] = urlencode(
$object->url ??
'');
7349 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] =
$object->address ??
'';
7350 $substitutionarray[
'__THIRDPARTY_ZIP__'] =
$object->zip ??
'';
7351 $substitutionarray[
'__THIRDPARTY_TOWN__'] =
$object->town ??
'';
7352 $substitutionarray[
'__THIRDPARTY_STATE__'] =
$object->state ??
'';
7353 $substitutionarray[
'__THIRDPARTY_COUNTRY_ID__'] = (
$object->country_id > 0 ?:
'');
7354 $substitutionarray[
'__THIRDPARTY_COUNTRY_CODE__'] =
$object->country_code ??
'';
7355 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] =
$object->idprof1 ??
'';
7356 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] =
$object->idprof2 ??
'';
7357 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] =
$object->idprof3 ??
'';
7358 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] =
$object->idprof4 ??
'';
7359 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] =
$object->idprof5 ??
'';
7360 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] =
$object->idprof6 ??
'';
7361 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] =
$object->tva_intra ??
'';
7364 } elseif (is_object(
$object) && is_object(
$object->thirdparty)) {
7365 $substitutionarray[
'__THIRDPARTY_ID__'] =
$object->thirdparty->id ??
'';
7366 $substitutionarray[
'__THIRDPARTY_NAME__'] =
$object->thirdparty->name ??
'';
7367 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] =
$object->thirdparty->name_alias ??
'';
7368 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] =
$object->thirdparty->code_client ??
'';
7369 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] =
$object->thirdparty->code_fournisseur ??
'';
7370 $substitutionarray[
'__THIRDPARTY_EMAIL__'] =
$object->thirdparty->email ??
'';
7371 $substitutionarray[
'__THIRDPARTY_EMAIL_URLENCODED__'] = urlencode(
$object->thirdparty->email ??
'');
7374 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] =
$object->thirdparty->address ??
'';
7375 $substitutionarray[
'__THIRDPARTY_ZIP__'] =
$object->thirdparty->zip ??
'';
7376 $substitutionarray[
'__THIRDPARTY_TOWN__'] =
$object->thirdparty->town ??
'';
7377 $substitutionarray[
'__THIRDPARTY_STATE__'] =
$object->thirdparty->state ??
'';
7378 $substitutionarray[
'__THIRDPARTY_COUNTRY_ID__'] = (
$object->thirdparty->country_id > 0 ?:
'');
7379 $substitutionarray[
'__THIRDPARTY_COUNTRY_CODE__'] =
$object->thirdparty->country_code ??
'';
7380 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] =
$object->thirdparty->idprof1 ??
'';
7381 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] =
$object->thirdparty->idprof2 ??
'';
7382 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] =
$object->thirdparty->idprof3 ??
'';
7383 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] =
$object->thirdparty->idprof4 ??
'';
7384 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] =
$object->thirdparty->idprof5 ??
'';
7385 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] =
$object->thirdparty->idprof6 ??
'';
7386 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] =
$object->thirdparty->tva_intra ??
'';
7391 if (is_object(
$object) &&
$object->element ==
'recruitmentcandidature') {
7392 '@phan-var-force RecruitmentCandidature $object';
7394 $substitutionarray[
'__CANDIDATE_FULLNAME__'] =
$object->getFullName($outputlangs);
7395 $substitutionarray[
'__CANDIDATE_FIRSTNAME__'] = isset(
$object->firstname) ?
$object->firstname :
'';
7396 $substitutionarray[
'__CANDIDATE_LASTNAME__'] = isset(
$object->lastname) ?
$object->lastname :
'';
7398 if (is_object(
$object) &&
$object->element ==
'conferenceorboothattendee') {
7399 '@phan-var-force ConferenceOrBoothAttendee $object';
7401 $substitutionarray[
'__ATTENDEE_FULLNAME__'] =
$object->getFullName($outputlangs);
7402 $substitutionarray[
'__ATTENDEE_FIRSTNAME__'] = isset(
$object->firstname) ?
$object->firstname :
'';
7403 $substitutionarray[
'__ATTENDEE_LASTNAME__'] = isset(
$object->lastname) ?
$object->lastname :
'';
7407 '@phan-var-force Project $object';
7409 $substitutionarray[
'__PROJECT_ID__'] =
$object->id;
7410 $substitutionarray[
'__PROJECT_REF__'] =
$object->ref;
7411 $substitutionarray[
'__PROJECT_NAME__'] =
$object->title;
7412 } elseif (is_object(
$object)) {
7414 if (!empty(
$object->project)) {
7417 if (!is_null($project) && is_object($project)) {
7418 $substitutionarray[
'__PROJECT_ID__'] = $project->id;
7419 $substitutionarray[
'__PROJECT_REF__'] = $project->ref;
7420 $substitutionarray[
'__PROJECT_NAME__'] = $project->title;
7425 $project_id =
$object->fk_project;
7426 } elseif (!empty(
$object->fk_projet) &&
$object->fk_projet > 0) {
7427 $project_id =
$object->fk_project;
7429 if ($project_id > 0) {
7431 $substitutionarray[
'__PROJECT_ID__@lazyload'] =
'/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id;
7432 $substitutionarray[
'__PROJECT_REF__@lazyload'] =
'/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id;
7433 $substitutionarray[
'__PROJECT_NAME__@lazyload'] =
'/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id;
7439 '@phan-var-force Facture $object';
7441 $substitutionarray[
'__INVOICE_SITUATION_NUMBER__'] = isset(
$object->situation_counter) ?
$object->situation_counter :
'';
7444 '@phan-var-force Expedition $object';
7446 $substitutionarray[
'__SHIPPINGTRACKNUM__'] =
$object->tracking_number;
7447 $substitutionarray[
'__SHIPPINGTRACKNUMURL__'] =
$object->tracking_url;
7448 $substitutionarray[
'__SHIPPINGMETHOD__'] =
$object->shipping_method;
7451 '@phan-var-force Reception $object';
7453 $substitutionarray[
'__RECEPTIONTRACKNUM__'] =
$object->tracking_number;
7454 $substitutionarray[
'__RECEPTIONTRACKNUMURL__'] =
$object->tracking_url;
7458 '@phan-var-force Contrat $object';
7460 $dateplannedstart =
'';
7461 $datenextexpiration =
'';
7462 foreach (
$object->lines as $line) {
7463 if ($line->date_start > $dateplannedstart) {
7464 $dateplannedstart = $line->date_start;
7466 if ($line->statut == 4 && $line->date_end && (!$datenextexpiration || $line->date_end < $datenextexpiration)) {
7467 $datenextexpiration = $line->date_end;
7470 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE__'] =
dol_print_date($dateplannedstart,
'day');
7471 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE_RFC__'] =
dol_print_date($dateplannedstart,
'dayrfc');
7472 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATETIME__'] =
dol_print_date($dateplannedstart,
'standard');
7474 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE__'] =
dol_print_date($datenextexpiration,
'day');
7475 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE_RFC__'] =
dol_print_date($datenextexpiration,
'dayrfc');
7476 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATETIME__'] =
dol_print_date($datenextexpiration,
'standard');
7480 '@phan-var-force Ticket $object';
7482 $substitutionarray[
'__TICKET_TRACKID__'] =
$object->track_id;
7483 $substitutionarray[
'__TICKET_SUBJECT__'] =
$object->subject;
7484 $substitutionarray[
'__TICKET_TYPE__'] =
$object->type_code;
7485 $substitutionarray[
'__TICKET_SEVERITY__'] =
$object->severity_code;
7486 $substitutionarray[
'__TICKET_CATEGORY__'] =
$object->category_code;
7487 $substitutionarray[
'__TICKET_ANALYTIC_CODE__'] =
$object->category_code;
7488 $substitutionarray[
'__TICKET_MESSAGE__'] =
$object->message;
7489 $substitutionarray[
'__TICKET_PROGRESSION__'] =
$object->progress;
7492 $substitutionarray[
'__TICKET_TYPE_LABEL__'] = empty(
$object->type_code) ?
'' : $outputlangs->getLabelFromKey($db,
'TicketTypeShort'.
$object->type_code,
'c_ticket_type',
'code',
'label',
$object->type_code);
7493 $substitutionarray[
'__TICKET_SEVERITY_LABEL__'] = empty(
$object->severity_code) ?
'' : $outputlangs->getLabelFromKey($db,
'TicketSeverityShort'.
$object->severity_code,
'c_ticket_severity',
'code',
'label',
$object->severity_code);
7494 $substitutionarray[
'__TICKET_CATEGORY_LABEL__'] = empty(
$object->category_code) ?
'' : $outputlangs->getLabelFromKey($db,
'TicketCategoryShort'.
$object->category_code,
'c_ticket_category',
'code',
'label',
$object->category_code);
7495 $substitutionarray[
'__TICKET_PUBLIC_URL__'] =
getDolGlobalString(
'TICKET_URL_PUBLIC_INTERFACE',
dol_buildpath(
'/public/ticket/', 2)).
'view.php?track_id='.urlencode((
string)
$object->track_id);
7496 $substitutionarray[
'__TICKET_MANAGEMENT_URL__'] =
dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.urlencode((
string)
$object->track_id);
7497 $userstat =
new User($db);
7498 if (
$object->fk_user_assign > 0) {
7499 $userstat->fetch(
$object->fk_user_assign);
7500 $substitutionarray[
'__TICKET_USER_ASSIGN__'] =
dolGetFirstLastname($userstat->firstname, $userstat->lastname);
7503 if (
$object->fk_user_create > 0) {
7504 $userstat->fetch(
$object->fk_user_create);
7505 $substitutionarray[
'__USER_CREATE__'] =
dolGetFirstLastname($userstat->firstname, $userstat->lastname);
7511 if (!is_object($extrafields)) {
7514 $extrafields->fetch_name_optionals_label(
$object->table_element,
true);
7516 if (
$object->fetch_optionals() > 0) {
7517 if (is_array($extrafields->attributes[
$object->table_element][
'label']) && count($extrafields->attributes[
$object->table_element][
'label']) > 0) {
7518 foreach ($extrafields->attributes[
$object->table_element][
'label'] as $key => $label) {
7519 if ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'date') {
7520 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] =
dol_print_date(
$object->array_options[
'options_' . $key],
'day');
7521 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_LOCALE__'] =
dol_print_date(
$object->array_options[
'options_' . $key],
'day',
'tzserver', $outputlangs);
7522 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_RFC__'] =
dol_print_date(
$object->array_options[
'options_' . $key],
'dayrfc');
7523 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'datetime') {
7524 $datetime =
$object->array_options[
'options_' . $key];
7525 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhour') :
'');
7526 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_LOCALE__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhour',
'tzserver', $outputlangs) :
'');
7527 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_DAY_LOCALE__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'day',
'tzserver', $outputlangs) :
'');
7528 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_RFC__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhourrfc') :
'');
7529 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'phone') {
7530 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] =
dol_print_phone(
$object->array_options[
'options_' . $key]);
7531 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'price') {
7532 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] =
$object->array_options[
'options_' . $key];
7533 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_FORMATED__'] =
price(
$object->array_options[
'options_' . $key]);
7534 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_FORMATTED__'] =
price(
$object->array_options[
'options_' . $key]);
7535 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'select') {
7536 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] = !empty(
$object->array_options[
'options_' . $key]) ?
$object->array_options[
'options_' . $key] :
'';
7537 $val = $extrafields->attributes[
$object->table_element][
'param'][$key][
'options'][
$object->array_options[
'options_'.$key]] ??
$object->array_options[
'options_'.$key];
7538 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'_LABEL__'] = $val;
7539 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] !=
'separator') {
7540 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] = !empty(
$object->array_options[
'options_' . $key]) ?
$object->array_options[
'options_' . $key] :
'';
7548 if (empty($substitutionarray[
'__REF__'])) {
7552 require_once DOL_DOCUMENT_ROOT .
'/core/lib/payments.lib.php';
7553 $outputlangs->loadLangs(array(
'paypal',
'other'));
7556 $typeforonlinepayment =
'free';
7558 $typeforonlinepayment =
'order';
7561 $typeforonlinepayment =
'invoice';
7564 $typeforonlinepayment =
'member';
7565 if (!empty(
$object->last_subscription_amount)) {
7566 $amounttouse =
$object->last_subscription_amount;
7570 $typeforonlinepayment =
'contract';
7573 $typeforonlinepayment =
'ficheinter';
7576 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $substitutionarray[
'__REF__'], (
float) $amounttouse);
7581 $substitutionarray[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = ($paymenturl ? str_replace(
'\n',
"\n", $outputlangs->trans(
"PredefinedMailContentLink", $paymenturl)) :
'');
7582 $substitutionarray[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
7586 include_once DOL_DOCUMENT_ROOT .
'/core/lib/functions_be.lib.php';
7591 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
$object->getLastMainDocLink(
$object->element);
7593 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
'';
7596 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
$object->getLastMainDocLink(
$object->element);
7598 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
'';
7601 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
$object->getLastMainDocLink(
$object->element);
7603 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
'';
7606 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
$object->getLastMainDocLink(
$object->element);
7608 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
'';
7611 $substitutionarray[
'__DIRECTDOWNLOAD_URL_FICHINTER__'] =
$object->getLastMainDocLink(
$object->element);
7613 $substitutionarray[
'__DIRECTDOWNLOAD_URL_FICHINTER__'] =
'';
7616 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
$object->getLastMainDocLink(
$object->element);
7618 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
'';
7621 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_ORDER__'] =
$object->getLastMainDocLink(
$object->element);
7623 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_ORDER__'] =
'';
7626 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_INVOICE__'] =
$object->getLastMainDocLink(
$object->element);
7628 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_INVOICE__'] =
'';
7632 '@phan-var-force Propal $object';
7634 $substitutionarray[
'__URL_PROPOSAL__'] = DOL_MAIN_URL_ROOT .
"/comm/propal/card.php?id=" .
$object->id;
7635 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
7636 $substitutionarray[
'__ONLINE_SIGN_URL__'] = getOnlineSignatureUrl(0,
'proposal', (
string)
$object->ref, 1,
$object);
7639 '@phan-var-force Commande $object';
7641 $substitutionarray[
'__URL_ORDER__'] = DOL_MAIN_URL_ROOT .
"/commande/card.php?id=" .
$object->id;
7644 '@phan-var-force Facture $object';
7646 $substitutionarray[
'__URL_INVOICE__'] = DOL_MAIN_URL_ROOT .
"/compta/facture/card.php?id=" .
$object->id;
7649 '@phan-var-force Contrat $object';
7651 $substitutionarray[
'__URL_CONTRACT__'] = DOL_MAIN_URL_ROOT .
"/contrat/card.php?id=" .
$object->id;
7652 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
7653 $substitutionarray[
'__ONLINE_SIGN_URL__'] = getOnlineSignatureUrl(0,
'contract', (
string)
$object->ref, 1,
$object);
7656 '@phan-var-force Fichinter $object';
7658 $substitutionarray[
'__URL_FICHINTER__'] = DOL_MAIN_URL_ROOT .
"/fichinter/card.php?id=" .
$object->id;
7659 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
7660 $substitutionarray[
'__ONLINE_SIGN_FICHINTER_URL__'] = getOnlineSignatureUrl(0,
'fichinter', (
string)
$object->ref, 1,
$object);
7662 if (is_object(
$object) &&
$object->element ==
'supplier_proposal') {
7663 '@phan-var-force SupplierProposal $object';
7665 $substitutionarray[
'__URL_SUPPLIER_PROPOSAL__'] = DOL_MAIN_URL_ROOT .
"/supplier_proposal/card.php?id=" .
$object->id;
7667 if (is_object(
$object) &&
$object->element ==
'invoice_supplier') {
7668 '@phan-var-force FactureFournisseur $object';
7670 $substitutionarray[
'__URL_SUPPLIER_INVOICE__'] = DOL_MAIN_URL_ROOT .
"/fourn/facture/card.php?id=" .
$object->id;
7672 if (is_object(
$object) &&
$object->element ==
'payment_supplier') {
7673 '@phan-var-force PaiementFourn $object';
7676 $liste_factures = [];
7680 $sql =
'SELECT f.ref,f.multicurrency_code as f_mccode, pf.*
7681 FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf
7682 JOIN '.MAIN_DB_PREFIX.
'facture_fourn as f ON pf.fk_facturefourn = f.rowid
7683 WHERE pf.fk_paiementfourn = '.((int)
$object->id);
7685 $resql = $db->query($sql);
7687 while ($objp = $db->fetch_object($resql)) {
7688 $liste_factures[] =
' - '.$outputlangs->trans(
'Invoice').
' '. $objp->ref.
' '.$outputlangs->trans(
'AmountPayed').
' '.
price($objp->multicurrency_amount, 0, $outputlangs, 0, -1, -1, $objp->multicurrency_code);
7691 $substitutionarray[
'__SUPPLIER_PAYMENT_INVOICES_LIST__'] = implode(
"\n", $liste_factures);
7693 $substitutionarray[
'__SUPPLIER_PAYMENT_INVOICES_TOTAL__'] =
price(
$object->multicurrency_amount, 0, $outputlangs, 0, -1, -1,
$object->multicurrency_code ?
$object->multicurrency_code :
$conf->currency);
7696 '@phan-var-force Expedition $object';
7698 $substitutionarray[
'__URL_SHIPMENT__'] = DOL_MAIN_URL_ROOT .
"/expedition/card.php?id=" .
$object->id;
7700 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
7701 $substitutionarray[
'__ONLINE_SIGN_URL__'] = getOnlineSignatureUrl(0,
'expedition', (
string)
$object->ref, 1,
$object);
7707 '@phan-var-force ActionComm $object';
7709 $substitutionarray[
'__EVENT_LABEL__'] =
$object->label;
7710 $substitutionarray[
'__EVENT_DESCRIPTION__'] =
$object->note;
7711 $substitutionarray[
'__EVENT_TYPE__'] = $outputlangs->trans(
"Action" .
$object->type_code);
7713 $substitutionarray[
'__EVENT_TIME__'] =
dol_print_date(
$object->datep,
'hour',
'auto', $outputlangs);
7714 $substitutionarray[
'__EVENT_DATE_TZUSER__'] =
dol_print_date(
$object->datep,
'day',
'tzuserrel', $outputlangs);
7715 $substitutionarray[
'__EVENT_TIME_TZUSER__'] =
dol_print_date(
$object->datep,
'hour',
'tzuserrel', $outputlangs);
7720 if ((empty($exclude) || !in_array(
'objectamount', $exclude)) && (empty($include) || in_array(
'objectamount', $include))) {
7721 '@phan-var-force Facture|FactureRec $object';
7723 include_once DOL_DOCUMENT_ROOT .
'/core/lib/functionsnumtoword.lib.php';
7726 $substitutionarray[
'__DATE_DUE_YMD__'] = is_object(
$object) ? (isset(
$object->date_lim_reglement) ?
dol_print_date(
$object->date_lim_reglement,
'day',
false, $outputlangs) : null) :
'';
7728 $substitutionarray[
'__DATE_DUE_YMD_TEXT__'] = is_object(
$object) ? (isset(
$object->date_lim_reglement) ?
dol_print_date(
$object->date_lim_reglement,
'daytext',
false, $outputlangs) : null) :
'';
7730 $already_payed_all = 0;
7736 $substitutionarray[
'__AMOUNT_EXCL_TAX__'] = is_object(
$object) ?
$object->total_ht :
'';
7740 $substitutionarray[
'__AMOUNT__'] = is_object(
$object) ?
$object->total_ttc :
'';
7744 $substitutionarray[
'__DEPOSIT_PERCENT__'] = is_object(
$object) ?
$object->deposit_percent :
'';
7747 $substitutionarray[
'__AMOUNT_REMAIN__'] = is_object(
$object) ?
price2num(
$object->total_ttc - $already_payed_all,
'MT') :
'';
7749 $substitutionarray[
'__AMOUNT_VAT__'] = is_object(
$object) ? (isset(
$object->total_vat) ?
$object->total_vat :
$object->total_tva) :
'';
7753 $mysocuselocaltax1 =
false;
7754 $mysocuselocaltax2 =
false;
7756 $tmparray =
$mysoc->useLocalTax(-1);
7757 $mysocuselocaltax1 = $tmparray[1];
7758 $mysocuselocaltax2 = $tmparray[2];
7762 if ($onlykey != 2 || $mysocuselocaltax1) {
7763 $substitutionarray[
'__AMOUNT_TAX2__'] = is_object(
$object) ?
$object->total_localtax1 :
'';
7765 if ($onlykey != 2 || $mysocuselocaltax2) {
7766 $substitutionarray[
'__AMOUNT_TAX3__'] = is_object(
$object) ?
$object->total_localtax2 :
'';
7770 $substitutionarray[
'__AMOUNT_EXCL_TAX_FORMATTED__'] = is_object(
$object) ? (
$object->total_ht ?
price(
$object->total_ht, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null) :
'';
7771 $substitutionarray[
'__AMOUNT_FORMATTED__'] = is_object(
$object) ? (
$object->total_ttc ?
price(
$object->total_ttc, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null) :
'';
7772 $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) :
'';
7773 $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)) :
'';
7774 if ($onlykey != 2 || $mysocuselocaltax1) {
7775 $substitutionarray[
'__AMOUNT_TAX2_FORMATTED__'] = is_object(
$object) ? (
$object->total_localtax1 ?
price(
$object->total_localtax1, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null) :
'';
7777 if ($onlykey != 2 || $mysocuselocaltax2) {
7778 $substitutionarray[
'__AMOUNT_TAX3_FORMATTED__'] = is_object(
$object) ? (
$object->total_localtax2 ?
price(
$object->total_localtax2, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null) :
'';
7781 if ($onlykey != 2) {
7782 $substitutionarray[
'__AMOUNT_EXCL_TAX_FORMATED__'] = $substitutionarray[
'__AMOUNT_EXCL_TAX_FORMATTED__'];
7783 $substitutionarray[
'__AMOUNT_FORMATED__'] = $substitutionarray[
'__AMOUNT_FORMATTED__'];
7784 $substitutionarray[
'__AMOUNT_REMAIN_FORMATED__'] = $substitutionarray[
'__AMOUNT_REMAIN_FORMATTED__'];
7785 $substitutionarray[
'__AMOUNT_VAT_FORMATED__'] = $substitutionarray[
'__AMOUNT_VAT_FORMATTED__'];
7786 if ($mysocuselocaltax1) {
7787 $substitutionarray[
'__AMOUNT_TAX2_FORMATED__'] = $substitutionarray[
'__AMOUNT_TAX2_FORMATTED__'];
7789 if (
$mysoc->useLocalTax2) {
7790 $substitutionarray[
'__AMOUNT_TAX3_FORMATED__'] = $substitutionarray[
'__AMOUNT_TAX3_FORMATTED__'];
7794 $substitutionarray[
'__AMOUNT_MULTICURRENCY__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
$object->multicurrency_total_ttc :
'';
7795 $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) :
'';
7796 $substitutionarray[
'__AMOUNT_MULTICURRENCY_TEXT__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
dol_convertToWord(
$object->multicurrency_total_ttc, $outputlangs,
'',
true) :
'';
7797 $substitutionarray[
'__AMOUNT_MULTICURRENCY_TEXTCURRENCY__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
dol_convertToWord(
$object->multicurrency_total_ttc, $outputlangs,
$object->multicurrency_code,
true) :
'';
7798 $substitutionarray[
'__MULTICURRENCY_CODE__'] = (is_object(
$object) && isset(
$object->multicurrency_code)) ?
$object->multicurrency_code :
'';
7802 if ($onlykey != 2) {
7803 $substitutionarray[
'__TOTAL_TTC__'] = is_object(
$object) ?
$object->total_ttc :
'';
7804 $substitutionarray[
'__TOTAL_HT__'] = is_object(
$object) ?
$object->total_ht :
'';
7809 if ((empty($exclude) || !in_array(
'date', $exclude)) && (empty($include) || in_array(
'date', $include))) {
7810 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
7820 $daytext = $outputlangs->trans(
'Day' . $tmp[
'wday']);
7822 $substitutionarray = array_merge($substitutionarray, array(
7823 '__NOW_TMS__' => (
string) $now,
7824 '__NOW_TMS_YMD__' =>
dol_print_date($now,
'day',
'auto', $outputlangs),
7825 '__DAY__' => (
string) $tmp[
'mday'],
7826 '__DAY_TEXT__' => $daytext,
7827 '__DAY_TEXT_SHORT__' =>
dol_trunc($daytext, 3,
'right',
'UTF-8', 1),
7828 '__DAY_TEXT_MIN__' =>
dol_trunc($daytext, 1,
'right',
'UTF-8', 1),
7829 '__MONTH__' => (
string) $tmp[
'mon'],
7830 '__MONTH_TEXT__' => $outputlangs->transnoentitiesnoconv(
'Month' . sprintf(
"%02d", $tmp[
'mon'])),
7831 '__MONTH_TEXT_SHORT__' => $outputlangs->transnoentitiesnoconv(
'MonthShort' . sprintf(
"%02d", $tmp[
'mon'])),
7832 '__MONTH_TEXT_MIN__' => $outputlangs->transnoentitiesnoconv(
'MonthVeryShort' . sprintf(
"%02d", $tmp[
'mon'])),
7833 '__YEAR__' => (
string) $tmp[
'year'],
7834 '__YEAR_PREVIOUS_MONTH__' => (
string) $tmp3[
'year'],
7835 '__YEAR_NEXT_MONTH__' => (
string) $tmp5[
'year'],
7836 '__PREVIOUS_DAY__' => (
string) $tmp2[
'day'],
7837 '__PREVIOUS_MONTH__' => (
string) $tmp3[
'month'],
7838 '__PREVIOUS_MONTH_TEXT__' => $outputlangs->transnoentitiesnoconv(
'Month' . sprintf(
"%02d", $tmp3[
'month'])),
7839 '__PREVIOUS_MONTH_TEXT_SHORT__' => $outputlangs->transnoentitiesnoconv(
'MonthShort' . sprintf(
"%02d", $tmp3[
'month'])),
7840 '__PREVIOUS_MONTH_TEXT_MIN__' => $outputlangs->transnoentitiesnoconv(
'MonthVeryShort' . sprintf(
"%02d", $tmp3[
'month'])),
7841 '__PREVIOUS_YEAR__' => (
string) ($tmp[
'year'] - 1),
7842 '__NEXT_DAY__' => (
string) $tmp4[
'day'],
7843 '__NEXT_MONTH__' => (
string) $tmp5[
'month'],
7844 '__NEXT_MONTH_TEXT__' => $outputlangs->transnoentitiesnoconv(
'Month' . sprintf(
"%02d", $tmp5[
'month'])),
7845 '__NEXT_MONTH_TEXT_SHORT__' => $outputlangs->transnoentitiesnoconv(
'MonthShort' . sprintf(
"%02d", $tmp5[
'month'])),
7846 '__NEXT_MONTH_TEXT_MIN__' => $outputlangs->transnoentitiesnoconv(
'MonthVeryShort' . sprintf(
"%02d", $tmp5[
'month'])),
7847 '__NEXT_YEAR__' => (
string) ($tmp[
'year'] + 1),
7852 $substitutionarray = array_merge($substitutionarray, array(
'__ENTITY_ID__' =>
$conf->entity));
7854 if ((empty($exclude) || !in_array(
'system', $exclude)) && (empty($include) || in_array(
'user', $include))) {
7855 $substitutionarray[
'__DOL_MAIN_URL_ROOT__'] = DOL_MAIN_URL_ROOT;
7856 $substitutionarray[
'__(AnyTranslationKey)__'] = $outputlangs->transnoentitiesnoconv(
'TranslationOfKey');
7857 $substitutionarray[
'__(AnyTranslationKey|langfile)__'] = $outputlangs->transnoentitiesnoconv(
'TranslationOfKey') .
' (load also language file before)';
7858 $substitutionarray[
'__[AnyConstantKey]__'] = $outputlangs->transnoentitiesnoconv(
'ValueOfConstantKey');
7863 return $substitutionarray;
7882function make_substitutions($text, $substitutionarray, $outputlangs =
null, $converttextinhtmlifnecessary = 0)
7886 if (!is_array($substitutionarray)) {
7887 return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions';
7890 if (empty($outputlangs)) {
7891 $outputlangs = $langs;
7901 if (is_object($outputlangs)) {
7903 while (preg_match(
'/__\(([^\)]+)\)__/', $text, $reg)) {
7905 $tmp = explode(
'|', $reg[1]);
7906 if (!empty($tmp[1])) {
7907 $outputlangs->load($tmp[1]);
7910 $value = $outputlangs->transnoentitiesnoconv($reg[1]);
7912 if (empty($converttextinhtmlifnecessary)) {
7914 $text = preg_replace(
'/__\(' . preg_quote($reg[1],
'/') .
'\)__/', $msgishtml ?
dol_htmlentitiesbr($value) : $value, $text);
7916 if (preg_match(
'/__\(' . preg_quote($reg[1],
'/') .
'\)__/', $text)) {
7929 $text = preg_replace(
'/__\(' . preg_quote($reg[1],
'/') .
'\)__/', $value, $text);
7937 while (preg_match(
'/__\[([^\]]+)\]__/', $text, $reg)) {
7938 $originalkeyfound = $reg[1];
7939 $keyfound = preg_replace(
'/\|urlencode$/',
'', $originalkeyfound);
7942 $value =
'*****forbidden*****';
7946 if (preg_match(
'/\|urlencode$/', $originalkeyfound)) {
7947 $value = urlencode($value);
7951 if (empty($converttextinhtmlifnecessary)) {
7953 $text = preg_replace(
'/__\[' . preg_quote($originalkeyfound,
'/') .
'\]__/', $msgishtml ?
dol_htmlentitiesbr($value) : $value, $text);
7955 if (preg_match(
'/__\[' . preg_quote($originalkeyfound,
'/') .
'\]__/', $text)) {
7967 $text = preg_replace(
'/__\[' . preg_quote($originalkeyfound,
'/') .
'\]__/', $value, $text);
7972 foreach ($substitutionarray as $key => $value) {
7973 if (!isset($value)) {
7977 if (
getDolGlobalString(
'MAIN_MAIL_DO_NOT_USE_SIGN') && ($key ==
'__USER_SIGNATURE__' || $key ==
'__SENDEREMAIL_SIGNATURE__')) {
7980 if (empty($converttextinhtmlifnecessary)) {
7981 $text = str_replace((
string) $key, (
string) $value, $text);
7983 if (strpos($text, (
string) $key) !==
false) {
7995 $text = str_replace((
string) $key, (
string) $value, $text);
8010 $memory_object_list = array();
8011 foreach ($substitutionarray as $key => $value) {
8012 $lazy_load_arr = array();
8013 if (preg_match(
'/(__[A-Z\_]+__)@lazyload$/', $key, $lazy_load_arr)) {
8014 if (!empty($lazy_load_arr[1])) {
8015 $key_to_substitute = $lazy_load_arr[1];
8016 if (preg_match(
'/' . preg_quote($key_to_substitute,
'/') .
'/', $text)) {
8017 $param_arr = explode(
':', (
string) $value);
8019 if (count($param_arr) >= 4) {
8020 $path = $param_arr[0];
8021 $class = $param_arr[1];
8022 $method = $param_arr[2];
8023 $id = (int) $param_arr[3];
8024 $keyinarrayresult = empty($param_arr[4]) ?
'' : $param_arr[4];
8027 if (!isset($memory_object_list[$class])) {
8029 require_once DOL_DOCUMENT_ROOT . $path;
8030 if (class_exists($class)) {
8031 $memory_object_list[$class] = array(
8039 if (isset($memory_object_list[$class][
'list'])) {
8040 if (method_exists($class, $method)) {
8041 if (!isset($memory_object_list[$class][
'list'][
$id])) {
8042 $tmpobj =
new $class($db);
8044 $tmpvaluetouseforsubstitution = $tmpobj->$method(
$id, $key_to_substitute);
8045 $memory_object_list[$class][
'list'][
$id] = $tmpobj;
8048 $tmpobj = $memory_object_list[$class][
'list'][
$id];
8050 $tmpvaluetouseforsubstitution = $tmpobj->$method(
$id, $key_to_substitute,
true);
8053 if ($keyinarrayresult) {
8054 $valuetouseforsubstitution = (string) $tmpvaluetouseforsubstitution[$keyinarrayresult];
8056 $valuetouseforsubstitution = (string) $tmpvaluetouseforsubstitution;
8058 $text = str_replace((
string) $key_to_substitute, $valuetouseforsubstitution, $text);
8084 global
$conf, $user;
8086 require_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
8091 $dirsubstitutions = array_merge(array(), (array)
$conf->modules_parts[
'substitutions']);
8093 foreach ($dirsubstitutions as $reldir) {
8101 $substitfiles =
dol_dir_list($dir,
'files', 0,
'functions_');
8102 foreach ($substitfiles as $substitfile) {
8104 if (preg_match(
'/functions_(.*)\.lib\.php/i', $substitfile[
'name'], $reg)) {
8107 dol_syslog(
"Library " . $substitfile[
'name'] .
" found into " . $dir);
8109 require_once $dir . $substitfile[
'name'];
8111 $function_name =
$module .
"_" . $callfunc;
8112 if (function_exists($function_name)) {
8113 $function_name($substitutionarray, $outputlangs,
$object, $parameters);
8121 foreach ($substitutionarray as $key => $value) {
8122 $tags .=
'{' . $key .
'} => ' . $value .
"\n";
8124 $substitutionarray = array_merge($substitutionarray, array(
'__ALL_TAGS__' => $tags));
8158 if (!is_object($outputlangs)) {
8159 $outputlangs = $langs;
8163 $out .= ($withparenthesis ? ($withparenthesis == 1 ?
' ' :
'').
'(' :
'') . $outputlangs->transnoentitiesnoconv(
'DateFromTo',
dol_print_date(
$date_start, $format, false, $outputlangs),
dol_print_date($date_end, $format, false, $outputlangs)) . ($withparenthesis ?
')' :
'');
8166 $out .= ($withparenthesis ? ($withparenthesis == 1 ?
' ' :
'').
'(' :
'') . $outputlangs->transnoentitiesnoconv(
'DateFrom',
dol_print_date(
$date_start, $format, false, $outputlangs)) . ($withparenthesis ?
')' :
'');
8169 $out .= ($withparenthesis ? ($withparenthesis == 1 ?
' ' :
'').
'(' :
'') . $outputlangs->transnoentitiesnoconv(
'DateUntil',
dol_print_date($date_end, $format, false, $outputlangs)) . ($withparenthesis ?
')' :
'');
8187 if ($nameorder < 0) {
8190 if ($nameorder == 1) {
8192 if ($firstname && $lastname) {
8196 } elseif ($nameorder == 2 || $nameorder == 3) {
8198 if (empty($ret) && $nameorder == 3) {
8203 if (empty($ret) && $nameorder == 5) {
8206 if ($nameorder == 0) {
8207 if ($firstname && $lastname) {
8227 return $arraytosort;
8251function dol_sort_array(&$array, $index, $order =
'asc', $natsort = 0, $case_sensitive = 0, $keepindex = 0)
8254 $order = strtolower($order);
8256 if (is_array($array)) {
8257 $sizearray = count($array);
8258 if ($sizearray > 0) {
8261 foreach (array_keys($array) as $key) {
8262 $tmpmultikey = explode(
',', $index);
8263 $newindex = $tmpmultikey[0];
8264 if (is_object($array[$key])) {
8265 $temp[$key] = empty($array[$key]->$newindex) ? 0 : $array[$key]->$newindex;
8267 if (!empty($tmpmultikey[1])) {
8268 $newindex = $tmpmultikey[1];
8269 $temp[$key] .=
'__' . (empty($array[$key]->$newindex) ? 0 : $array[$key]->$newindex);
8273 $temp[$key] = empty($array[$key][$newindex]) ? 0 : $array[$key][$newindex];
8275 if (!empty($tmpmultikey[1])) {
8276 $newindex = $tmpmultikey[1];
8278 $temp[$key] .=
'__' . (empty($array[$key][$newindex]) ? 0 : $array[$key][$newindex]);
8281 if ($natsort == -1) {
8282 $temp[$key] =
'___' . $temp[$key];
8285 if (empty($natsort) || $natsort == -1) {
8286 if ($order ==
'asc') {
8292 if ($case_sensitive) {
8297 if ($order !=
'asc') {
8298 $temp = array_reverse($temp,
true);
8304 foreach (array_keys($temp) as $key) {
8305 (is_numeric($key) && empty($keepindex)) ? $sorted[] = $array[$key] : $sorted[$key] = $array[$key];
8324 $str = (string) $str;
8327 $strLength = strlen($str);
8328 for ($i = 0; $i < $strLength; $i++) {
8329 if (ord($str[$i]) < 0x80) {
8331 } elseif ((ord($str[$i]) & 0xE0) == 0xC0) {
8333 } elseif ((ord($str[$i]) & 0xF0) == 0xE0) {
8335 } elseif ((ord($str[$i]) & 0xF8) == 0xF0) {
8337 } elseif ((ord($str[$i]) & 0xFC) == 0xF8) {
8339 } elseif ((ord($str[$i]) & 0xFE) == 0xFC) {
8344 for ($j = 0; $j < $n; $j++) {
8345 if ((++$i == strlen($str)) || ((ord($str[$i]) & 0xC0) != 0x80)) {
8366 return preg_match(
'//u', $str) ? true :
false;
8378 if (function_exists(
'mb_check_encoding')) {
8380 if (!mb_check_encoding($str,
'ASCII')) {
8384 if (preg_match(
'/[^\x00-\x7f]/', $str)) {
8402 $tmp = ini_get(
"unicode.filesystem_encoding");
8403 if (empty($tmp) && !empty($_SERVER[
"WINDIR"])) {
8404 $tmp =
'iso-8859-1';
8413 if ($tmp ==
'iso-8859-1') {
8414 return mb_convert_encoding($str,
'ISO-8859-1',
'UTF-8');
8435function dol_getIdFromCode($db, $key, $tablename, $fieldkey =
'code', $fieldid =
'id', $entityfilter = 0, $filters =
'', $useCache =
true)
8445 if ($useCache && isset(
$conf->cache[
'codeid'][$tablename][$key][$fieldid])) {
8446 return $conf->cache[
'codeid'][$tablename][$key][$fieldid];
8449 dol_syslog(
'dol_getIdFromCode (value for field ' . $fieldid .
' from key ' . $key .
' not found into cache)', LOG_DEBUG);
8451 $sql =
"SELECT " . $db->sanitize($fieldid) .
" as valuetoget";
8452 $sql .=
" FROM " . MAIN_DB_PREFIX . $db->sanitize($tablename);
8453 if ($fieldkey ==
'id' || $fieldkey ==
'rowid') {
8454 $sql .=
" WHERE " . $db->sanitize($fieldkey) .
" = " . ((int) $key);
8456 $sql .=
" WHERE " . $db->sanitize($fieldkey) .
" = '" . $db->escape($key) .
"'";
8458 if (!empty($entityfilter)) {
8459 $sql .=
" AND entity IN (" .
getEntity($tablename) .
")";
8465 $resql = $db->query($sql);
8467 $obj = $db->fetch_object($resql);
8470 $valuetoget = $obj->valuetoget;
8471 $conf->cache[
'codeid'][$tablename][$key][$fieldid] = $valuetoget;
8473 $conf->cache[
'codeid'][$tablename][$key][$fieldid] =
'';
8497 $regextext = preg_replace(
'#^/\^?#',
'', (
string) $regextext);
8498 $regextext = preg_replace(
'#\$?/[imsxuADSUXJ]*$#',
'', $regextext);
8500 if ($matchrule == 1) {
8501 if ($var ==
'mainmenu') {
8503 return (preg_match(
'/^' . $regextext .
'/', $mainmenu));
8504 } elseif ($var ==
'leftmenu') {
8506 return (preg_match(
'/^' . $regextext .
'/', $leftmenu));
8508 return 'This variable is not accessible with dol_eval';
8511 return 'This value '.$matchrule.
' for param $matchrule is not yet implemented';
8530 global
$conf, $user, $leftmenu, $mainmenu;
8532 $s = trim((
string) $s);
8533 if ($s ===
'1' || $s ===
'true') {
8536 if ($s ===
'0' || $s ===
'false') {
8540 if (!preg_match(
'/^[a-zA-Z0-9_$>=!&|\s\'",()-]+$/', $s)) {
8543 if (strpbrk($s,
'()') !==
false && !preg_match(
'/^(?:[^()]*\((?:\s*[\'"][a-zA-Z0-9_]+[\'"]\s*)(?:,\s*[\'"][a-zA-Z0-9_]+[\'"]\s*)*\))*[^()]*$/', $s)) {
8546 $hasand = (strpos($s,
'&&') !==
false);
8547 $hasor = (strpos($s,
'||') !==
false);
8548 if ($hasand && $hasor) {
8551 $terms = ($hasor ? explode(
'||', $s) : ($hasand ? explode(
'&&', $s) : array($s)));
8554 foreach ($terms as $term) {
8555 $term = trim($term);
8557 if (substr($term, 0, 1) ===
'!') {
8559 $term = ltrim(substr($term, 1));
8562 if (preg_match(
'/^isModEnabled\(\s*[\'"]([a-zA-Z0-9_]+)[\'"]\s*\)$/', $term, $reg)) {
8564 } 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)) {
8565 $value = (bool) (!empty($reg[3]) ? $user->hasRight($reg[1], $reg[2], $reg[3]) : $user->hasRight($reg[1], $reg[2]));
8566 } elseif (preg_match(
'/^\$user->rights->([a-zA-Z0-9_]+)->([a-zA-Z0-9_]+)(?:->([a-zA-Z0-9_]+))?$/', $term, $reg)) {
8567 if (!empty($reg[3])) {
8568 $value = !empty($user->rights->{$reg[1]}->{$reg[2]}->{$reg[3]});
8570 $value = !empty($user->rights->{$reg[1]}->{$reg[2]});
8572 } elseif ($term ===
'$user->admin') {
8573 $value = !empty($user->admin);
8574 } elseif (preg_match(
'/^\$conf->([a-zA-Z0-9_]+)->enabled$/', $term, $reg)) {
8575 $value = !empty(
$conf->{$reg[1]}->enabled);
8576 } elseif (preg_match(
'/^getDolGlobal(String|Int)\(\s*[\'"]([a-zA-Z0-9_]+)[\'"]\s*\)$/', $term, $reg)) {
8578 } elseif (preg_match(
'/^\$(leftmenu|mainmenu)\s*(==|!=)\s*[\'"]([a-zA-Z0-9_]*)[\'"]$/', $term, $reg)) {
8579 $current = ($reg[1] ==
'leftmenu' ? $leftmenu : $mainmenu);
8580 $value = ($reg[2] ==
'==' ? ($current == $reg[3]) : ($current != $reg[3]));
8581 } elseif ($term ===
'1' || $term ===
'true') {
8583 } elseif ($term ===
'0' || $term ===
'false') {
8591 if ($result ===
null) {
8594 $result = ($result || $value);
8596 $result = ($result && $value);
8612function verifCond($strToEvaluate, $onlysimplestring =
'1')
8616 if (isset($strToEvaluate) && $strToEvaluate !==
'') {
8620 if ($rights !==
null) {
8625 $rep =
dol_eval($strToEvaluate, 1, 1, $onlysimplestring);
8629 $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));
8650function dol_eval($s, $returnvalue = 1, $hideerrors = 1, $onlysimplestring =
'1')
8652 if ($returnvalue != 1) {
8653 dol_syslog(
"Use of dol_eval with parameter returnvalue = 0 is now forbidden. Please fix this", LOG_ERR);
8656 global $dolibarr_main_use_dol_eval_new;
8657 if (!empty($dolibarr_main_use_dol_eval_new)) {
8678 $db, $langs, $user, $website, $websitepage,
8679 $action, $mainmenu, $leftmenu,
8691 defined(
'T_COALESCE_EQUAL') || define(
'T_COALESCE_EQUAL', PHP_INT_MAX);
8692 defined(
'T_FN') || define(
'T_FN', PHP_INT_MAX);
8695 defined(
'T_ATTRIBUTE') || define(
'T_ATTRIBUTE', PHP_INT_MAX);
8696 defined(
'T_MATCH') || define(
'T_MATCH', PHP_INT_MAX);
8697 defined(
'T_NAME_FULLY_QUALIFIED') || define(
'T_NAME_FULLY_QUALIFIED', PHP_INT_MAX);
8698 defined(
'T_NAME_QUALIFIED') || define(
'T_NAME_QUALIFIED', PHP_INT_MAX);
8699 defined(
'T_NAME_RELATIVE') || define(
'T_NAME_RELATIVE', PHP_INT_MAX);
8702 defined(
'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG') || define(
'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG', PHP_INT_MAX);
8703 defined(
'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG') || define(
'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG', PHP_INT_MAX);
8704 defined(
'T_ENUM') || define(
'T_ENUM', PHP_INT_MAX);
8705 defined(
'T_READONLY') || define(
'T_READONLY', PHP_INT_MAX);
8708 defined(
'T_PRIVATE_SET') || define(
'T_PRIVATE_SET', PHP_INT_MAX);
8709 defined(
'T_PROTECTED_SET') || define(
'T_PROTECTED_SET', PHP_INT_MAX);
8710 defined(
'T_PUBLIC_SET') || define(
'T_PUBLIC_SET', PHP_INT_MAX);
8712 $prohibited_token_ids = [
8719 'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG',
8720 'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG',
8770 'T_OPEN_TAG_WITH_ECHO',
8804 $prohibited_variables = [
8816 $forbiddenphpfunctions = array();
8817 $forbiddenphpmethods = array();
8820 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"override_function",
"session_id",
"session_create_id",
"session_regenerate_id"));
8821 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"get_defined_functions",
"get_defined_vars",
"get_defined_constants",
"get_declared_classes"));
8822 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"function"));
8824 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"GETPOST"));
8826 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"ob_start"));
8829 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"call_user_func",
"call_user_func_array"));
8830 $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"));
8831 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"usort",
"uasort",
"uksort"));
8832 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"preg_replace_callback",
"preg_replace_callback_array",
"header_register_callback"));
8833 $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"));
8834 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"spl_autoload_register",
"spl_autoload_unregister",
"iterator_apply",
"session_set_save_handler"));
8835 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"forward_static_call",
"forward_static_call_array",
"register_postsend_function"));
8836 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"readline_completion_function",
"readline_callback_handler_install"));
8839 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"exec",
"passthru",
"shell_exec",
"system",
"proc_open",
"popen"));
8840 $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"));
8841 $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", ));
8842 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"putenv",
"dl",
"apache_child_terminate",
"apache_setenv"));
8843 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_eval",
"dol_eval_new",
"dol_eval_standard",
"executeCLI",
"verifCond",
"dolEncrypt",
"dolDecrypt"));
8844 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"eval",
"create_function",
"assert",
"mb_ereg_replace"));
8847 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"require",
"include",
"require_once",
"include_once"));
8849 $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"));
8850 $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"));
8854 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"base64" .
"_" .
"decode",
"rawurl" .
"decode",
"url" .
"decode",
"str" .
"_rot13",
"hex" .
"2bin",
"printf",
"sprintf"));
8855 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_concat",
"dol_concatdesc"));
8858 $forbiddenphpmethods = array_merge($forbiddenphpmethods, array(
'invoke',
'invokeArgs'));
8860 $prohibited_functions = array_merge($forbiddenphpfunctions, $forbiddenphpmethods);
8862 $prohibited_token_arrangements = [
8867 ' T_CONSTANT_ENCAPSED_STRING ( ',
8871 $tokens = token_get_all(
"<?php return {$s};", TOKEN_PARSE);
8873 $tokens_arrangement =
' ';
8875 for ($i = 2,
$c = count($tokens) - 1; $i <
$c; ++$i) {
8876 if (is_array($tokens[$i])) {
8877 $token_id = $tokens[$i][0];
8878 $token_value = $tokens[$i][1];
8879 $token_name = token_name($tokens[$i][0]);
8881 $token_id = $tokens[$i];
8882 $token_value = $tokens[$i];
8883 $token_name = $tokens[$i];
8887 if (T_WHITESPACE === $token_id) {
8892 $tokens_arrangement .=
"{$token_name} ";
8896 T_VARIABLE === $token_id
8897 && in_array($token_value, $prohibited_variables,
true)
8899 return "Bad string syntax to evaluate. « {$token_value} » is prohibited in « {$s} »";
8904 T_STRING === $token_id
8905 && in_array($token_value, $prohibited_functions,
true)
8907 return "Bad string syntax to evaluate. « {$token_value} » is prohibited in « {$s} »";
8912 $maxi = count($prohibited_token_ids);
8913 for ($i = 0; $i < $maxi; ++$i) {
8914 if (
false !== strpos($tokens_arrangement,
" {$prohibited_token_ids[$i]} ")) {
8915 return "Bad string syntax to evaluate. « {$prohibited_token_ids[$i]} » is prohibited in « {$s} »";
8920 $maxi = count($prohibited_token_arrangements);
8921 for ($i = 0; $i < $maxi; ++$i) {
8922 if (
false !== strpos($tokens_arrangement, $prohibited_token_arrangements[$i])) {
8923 return "Bad string syntax to evaluate. « {$prohibited_token_arrangements[$i]} » is prohibited in « {$s} »";
8929 return @eval(
"return {$s};") ??
'';
8930 }
catch (Throwable $ex) {
8931 return "Bad string syntax to evaluate. Exception during evaluation: " . $s .
" - " . $ex->getMessage();
8955 global $db, $langs, $user, $website, $websitepage;
8956 global $action, $mainmenu, $leftmenu;
8958 global $objectoffield;
8966 $isObBufferActive =
false;
8967 if ($onlysimplestring ==
'0') {
8968 $onlysimplestring =
'1';
8970 if (!in_array($onlysimplestring, array(
'1',
'2'))) {
8971 return "Bad call of dol_eval. Parameter onlysimplestring must be '1' or '2'.";
8973 if (!is_scalar($s)) {
8974 return "Bad call of dol_eval. First parameter must be a string, found ".var_export($s,
true);
8978 global $dolibarr_main_restrict_eval_methods;
8981 if (!isset($dolibarr_main_restrict_eval_methods)) {
8982 $dolibarr_main_restrict_eval_methods =
'getDolGlobalString, getDolGlobalInt, getDolCurrency, getDolEntity, getDolDBType, fetchNoCompute, hasRight, isAdmin, isExternalUser, isModEnabled, isStringVarMatching, abs, min, max, round, dol_now, preg_match';
8985 $dolibarr_main_restrict_eval_methods_array = explode(
',', str_replace(
" ",
"", $dolibarr_main_restrict_eval_methods));
8993 $specialcharsallowed =
'^$_+-.*>&|=!?():"\',/@';
8994 if ($onlysimplestring ==
'2') {
8995 $specialcharsallowed .=
'<[]';
8997 global $dolibarr_main_allow_unsecured_special_chars_in_dol_eval;
8998 if (!empty($dolibarr_main_allow_unsecured_special_chars_in_dol_eval)) {
8999 $specialcharsallowed .= (string) $dolibarr_main_allow_unsecured_special_chars_in_dol_eval;
9001 if (preg_match(
'/[^a-z0-9\s' . preg_quote($specialcharsallowed,
'/') .
']/i', $s)) {
9002 return 'Bad string syntax to evaluate (found chars that are not chars for a simple one line clean eval string): ' . $s;
9014 if (strpos($s,
'/*') !==
false || strpos($s,
'//') !==
false) {
9015 return 'Bad string syntax to evaluate (The comment string /* and // are not allowed): ' . $s;
9019 $tmps = str_replace(
' ? ',
'__XXX__', $s);
9020 if (strpos($tmps,
'?') !==
false) {
9021 return 'Bad string syntax to evaluate (The char ? can be used only with a space before and after): ' . $s;
9025 if (preg_match(
'/<=?[^\s]/', $s)) {
9026 return 'Bad string syntax to evaluate (mode ' . $onlysimplestring .
', found a < or <= without space after): ' . $s;
9030 if (preg_match(
'/(include|include_once|require|require_once)/', $s)) {
9031 return 'Bad string syntax to evaluate (found not allowed key include|include_once|require|require_once): ' . $s;
9035 if (preg_match(
'/\$[\w]*\s*\(/', $s)) {
9036 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;
9039 if (empty($dolibarr_main_restrict_eval_methods)) {
9045 while ($scheck && $savescheck != $scheck) {
9046 $savescheck = $scheck;
9047 $scheck = preg_replace(
'/->[a-zA-Z0-9_]+\(/',
'->__METHOD__', $scheck);
9048 $scheck = preg_replace(
'/::[a-zA-Z0-9_]+\(/',
'->__METHOD__', $scheck);
9049 $scheck = preg_replace(
'/^\(+/',
'__PARENTHESIS__ ', $scheck);
9050 $scheck = preg_replace(
'/\&\&\s+\(/',
'__ANDPARENTHESIS__ ', $scheck);
9051 $scheck = preg_replace(
'/\|\|\s+\(/',
'__ORPARENTHESIS__ ', $scheck);
9052 $scheck = preg_replace(
'/^!?[a-zA-Z0-9_]+\(/',
'__FUNCTION__', $scheck);
9053 $scheck = preg_replace(
'/\s!?[a-zA-Z0-9_]+\(/',
'__FUNCTION__', $scheck);
9054 $scheck = preg_replace(
'/^!\(/',
'__NOTANDPARENTHESIS__', $scheck);
9055 $scheck = preg_replace(
'/\s!\(/',
' __NOTANDPARENTHESIS__', $scheck);
9056 $scheck = preg_replace(
'/(\^|\')\(/',
'__REGEXSTART__', $scheck);
9061 if (strpos($scheck,
'(') !==
false) {
9062 return 'Bad string syntax to evaluate (mode ' . $onlysimplestring .
', found call of a function or method without using the direct name of the function): ' . $s;
9066 if (strpos($s,
'`') !==
false) {
9067 return 'Bad string syntax to evaluate (backtick char is forbidden): ' . $s;
9072 if (preg_match(
'/[^0-9]+\.[^0-9]+/', $s)) {
9073 return 'Bad string syntax to evaluate (dot char is forbidden if not strictly between 2 numbers): ' . $s;
9081 while ($scheck && $savescheck != $scheck) {
9082 $savescheck = $scheck;
9083 $scheck = preg_replace(
'/\$conf->[a-z\_]+->enabled/',
'__VARCONFENABLED__', $scheck);
9084 $scheck = preg_replace(
'/\$user->id/',
'__VARUSERID__', $scheck);
9085 $scheck = preg_replace(
'/\$user->hasRight/',
'__VARUSERHASRIGHT__', $scheck);
9086 $scheck = preg_replace(
'/\$user->rights/',
'__VARUSERHASRIGHT__', $scheck);
9087 $scheck = preg_replace(
'/\$user->isAdmin/',
'__VARUSERHASRIGHT__', $scheck);
9088 $scheck = preg_replace(
'/\$user->admin/',
'__VARUSERISADMIN__', $scheck);
9089 $scheck = preg_replace(
'/\$user->isExternalUser/',
'__VARUSERSOCID__', $scheck);
9090 $scheck = preg_replace(
'/\$user->socid/',
'__VARUSERSOCID__', $scheck);
9091 $scheck = preg_replace(
'/\(\$db\)/',
'__VARDB__', $scheck);
9092 $scheck = preg_replace(
'/\$langs/',
'__VARLANGSTRANS__', $scheck);
9093 $scheck = preg_replace(
'/\$mysoc/',
'__VARMYSOC__', $scheck);
9094 $scheck = preg_replace(
'/\$action/',
'__VARACTION__', $scheck);
9095 $scheck = preg_replace(
'/\$mainmenu/',
'__VARMAINMENU__', $scheck);
9096 $scheck = preg_replace(
'/\$leftmenu/',
'__VARLEFTMENU__', $scheck);
9097 $scheck = preg_replace(
'/\$websitepage/',
'__VARWEBSITEPAGE__', $scheck);
9098 $scheck = preg_replace(
'/\$website/',
'__VARWEBSITE__', $scheck);
9099 $scheck = preg_replace(
'/\$objectoffield/',
'__VAROBJECTOFFIELD__', $scheck);
9100 $scheck = preg_replace(
'/\$object/',
'__VAROBJECT__', $scheck);
9101 $scheck = preg_replace(
'/\$var/',
'__VARVAR__', $scheck);
9104 $scheck = preg_replace(
'/\$soc->canvas/',
'__VARSOCCANVAS__', $scheck);
9105 $scheck = preg_replace(
'/\$obj->canvas/',
'__VAROBJCANVAS__', $scheck);
9108 if (strpos($scheck,
'$') !==
false) {
9109 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);
9110 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;
9115 $forbiddenphpstrings = array(
'_ENV',
'_SESSION',
'_COOKIE',
'_GET',
'_GLOBAL',
'_POST',
'_REQUEST',
'ReflectionFunction',
'SplFileObject',
'SplTempFileObject');
9117 if (empty($dolibarr_main_restrict_eval_methods)) {
9121 $forbiddenphpfunctions = array();
9122 $forbiddenphpmethods = array();
9124 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"override_function",
"session_id",
"session_create_id",
"session_regenerate_id"));
9125 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"get_defined_functions",
"get_defined_vars",
"get_defined_constants",
"get_declared_classes"));
9126 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"function"));
9128 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"GETPOST"));
9130 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"ob_start"));
9133 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"call_user_func",
"call_user_func_array"));
9134 $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"));
9135 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"usort",
"uasort",
"uksort"));
9136 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"preg_replace_callback",
"preg_replace_callback_array",
"header_register_callback"));
9137 $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"));
9138 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"spl_autoload_register",
"spl_autoload_unregister",
"iterator_apply",
"session_set_save_handler"));
9139 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"forward_static_call",
"forward_static_call_array",
"register_postsend_function"));
9140 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"readline_completion_function",
"readline_callback_handler_install"));
9143 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"exec",
"passthru",
"shell_exec",
"system",
"proc_open",
"popen"));
9144 $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"));
9145 $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", ));
9146 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"putenv",
"dl",
"apache_child_terminate",
"apache_setenv"));
9147 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_eval",
"dol_eval_new",
"dol_eval_standard",
"executeCLI",
"verifCond",
"dolEncrypt",
"dolDecrypt"));
9148 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"eval",
"create_function",
"assert",
"mb_ereg_replace"));
9151 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"require",
"include",
"require_once",
"include_once"));
9153 $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"));
9154 $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"));
9158 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"base64" .
"_" .
"decode",
"rawurl" .
"decode",
"url" .
"decode",
"str" .
"_rot13",
"hex" .
"2bin",
"printf",
"sprintf"));
9159 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_concat",
"dol_concatdesc"));
9168 $forbiddenphpmethods = array_merge($forbiddenphpmethods, array(
'invoke',
'invokeArgs'));
9176 $forbiddenphpregex =
'global\s*\$';
9177 $forbiddenphpregex .=
'|posix_[a-zA-Z0-9_]*|';
9178 $forbiddenphpregex .=
'\b(' . implode(
'|', $forbiddenphpfunctions) .
')\b';
9180 $forbiddenphpmethodsregex =
'->(' . implode(
'|', $forbiddenphpmethods) .
')';
9184 $oldstringtoclean = $s;
9185 $s = str_ireplace($forbiddenphpstrings,
'__forbiddenstring__', $s);
9186 $s = preg_replace(
'/' . $forbiddenphpregex .
'/i',
'__forbiddenstring__', $s);
9187 $s = preg_replace(
'/' . $forbiddenphpmethodsregex .
'/i',
'__forbiddenstring__', $s);
9189 }
while ($oldstringtoclean != $s);
9191 if (strpos($s,
'__forbiddenstring__') !==
false) {
9192 dol_syslog(
'Bad string syntax to evaluate: ' . $s, LOG_WARNING);
9193 return 'Bad string syntax to evaluate: ' . $s;
9197 if (!empty($dolibarr_main_restrict_eval_methods)) {
9200 $pattern =
'/([\s\w\'\]\"]+)\(/';
9203 preg_match_all($pattern, $s, $matches);
9205 if (count($matches)) {
9206 foreach ($matches[1] as $m) {
9212 if (!preg_match(
'/new ([A-Z][\w]+)/i', $m, $reg)) {
9213 if (!in_array($m, $dolibarr_main_restrict_eval_methods_array)) {
9214 if ($m !=
"'" && $m !=
'"') {
9215 dol_syslog(
'Bad string syntax to evaluate: ' . $s, LOG_WARNING);
9216 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;
9220 if (!class_exists($reg[1])) {
9221 dol_syslog(
'Bad string syntax to evaluate: Class "'.$reg[1].
'" does not exist. ' . $s, LOG_WARNING);
9222 return 'Bad string syntax to evaluate. Class "'.$reg[1].
'" does not exist. ' . $s;
9224 $parents = class_parents($reg[1]);
9225 if (!in_array(
'CommonObject', $parents)) {
9226 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);
9227 return 'Bad string syntax to evaluate. Class "'.$reg[1].
'" is not allowed because only classes extended CommonObject can be used in dynamic evaluation. ' . $s;
9233 $forbiddenphpregex =
'global\s*\$';
9234 $forbiddenphpregex .=
'|';
9235 $forbiddenphpregex .=
'}\s*\[';
9236 $forbiddenphpregex .=
'|';
9237 $forbiddenphpregex .=
'\)\s*\(';
9241 $oldstringtoclean = $s;
9242 $s = str_ireplace($forbiddenphpstrings,
'__forbiddenstring__', $s);
9243 $s = preg_replace(
'/' . $forbiddenphpregex .
'/i',
'__forbiddenstring__', $s);
9246 }
while ($oldstringtoclean != $s);
9248 if (strpos($s,
'__forbiddenstring__') !==
false) {
9249 dol_syslog(
'Bad string syntax to evaluate: ' . $s, LOG_WARNING);
9250 return 'Bad string syntax to evaluate: ' . $s;
9256 $isObBufferActive =
true;
9257 $tmps = $hideerrors ? @eval(
'return ' . $s .
';') : eval(
'return ' . $s .
';');
9258 $tmpo = ob_get_clean();
9259 $isObBufferActive =
false;
9261 print
'Bad string syntax to evaluate. Some data were output when it should not when evaluating: ' . $s;
9265 if ($isObBufferActive) {
9267 $tmpo = ob_get_clean();
9268 $isObBufferActive =
false;
9270 $error =
'dol_eval try/catch error for string: ' . $s .
' - Error: ';
9271 $error .= $e->getMessage();
9273 return 'Exception during evaluation: ' . $s;
9274 }
catch (Error $e) {
9275 if ($isObBufferActive) {
9277 $tmpo = ob_get_clean();
9278 $isObBufferActive =
false;
9280 $error =
'dol_eval try/catch error for string: ' . $s .
' - Error: ';
9281 $error .= $e->getMessage();
9283 return 'Exception during evaluation: ' . $s;
9296 return (trim($element) !=
'');
9311 if (empty($countrycode)) {
9315 if (strtoupper($countrycode) ==
'MQ') {
9318 if (strtoupper($countrycode) ==
'SE') {
9321 if (strtoupper($countrycode) ==
'CH') {
9322 if (
$mysoc->country_code ==
'FR') {
9325 if (
$mysoc->country_code ==
'DE') {
9328 if (
$mysoc->country_code ==
'IT') {
9510 $buildprimarykeytotest = strtolower($countrycode) .
'-' . strtoupper($countrycode);
9511 if (in_array($buildprimarykeytotest, $locales)) {
9512 return strtolower($countrycode) .
'_' . strtoupper($countrycode);
9515 if (function_exists(
'locale_get_primary_language') && function_exists(
'locale_get_region')) {
9516 foreach ($locales as $locale) {
9517 $locale_language = locale_get_primary_language($locale);
9518 $locale_region = locale_get_region($locale);
9519 if (strtoupper($countrycode) == $locale_region) {
9521 return strtolower($locale_language) .
'_' . strtoupper($locale_region);
9525 dol_syslog(
"Warning Extension php-intl is not available", LOG_WARNING);
9563 global $hookmanager, $db;
9565 if (isset(
$conf->modules_parts[
'tabs'][$type]) && is_array(
$conf->modules_parts[
'tabs'][$type])) {
9566 foreach (
$conf->modules_parts[
'tabs'][$type] as $value) {
9567 $values = explode(
':', $value);
9570 if ($mode ==
'add' && !preg_match(
'/^\-/', $values[1])) {
9571 if (count($values) !== 6) {
9572 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);
9579 if ($values[0] != $type) {
9587 $posstart = strpos($str,
'(');
9588 if ($posstart > 0) {
9589 $posend = strpos($str,
')');
9590 if ($posstart > 0) {
9591 $res1 = substr($str, $posstart + 1, $posend - $posstart - 1);
9592 if (is_numeric($res1)) {
9593 $postab = (int) $res1;
9594 $values[1] =
'+' . substr($str, $posend + 1);
9599 global $objectoffield;
9607 if ($filterorigmodule) {
9608 if (strpos($values[3],
'@')) {
9609 if ($filterorigmodule !=
'external') {
9613 if ($filterorigmodule !=
'core') {
9618 $langs->load($values[3]);
9621 if (preg_match(
'/SUBSTITUTION_([^_]+)/i', $values[2], $reg)) {
9623 $substitutionarray = array();
9628 $labeltemp = explode(
',', $values[2]);
9629 $label = $langs->trans($labeltemp[0]);
9631 if (!empty($labeltemp[1]) && is_object(
$object) && !empty(
$object->id)) {
9633 $classtoload = $labeltemp[1];
9634 if (class_exists($classtoload)) {
9635 $obj =
new $classtoload($db);
9636 $function = $labeltemp[3];
9637 if ($obj && $function && method_exists($obj, $function)) {
9639 $nbrec = $obj->$function(
$object->id, $obj);
9640 if (!empty($nbrec)) {
9641 $label .=
'<span class="badge marginleftonlyshort">' . $nbrec .
'</span>';
9647 $url = preg_replace(
'/__ID__/i', ((is_object(
$object) && !empty(
$object->id)) ?
$object->id :
''), $values[5]);
9648 $link = parse_url($url);
9650 if (isset($link[
'query'])) {
9651 parse_str($link[
'query'], $query);
9654 $newtab[1] = $label;
9655 $newtab[2] = str_replace(
'+',
'', $values[1]);
9659 $head = array_merge(array_slice($head, 0, $postab), array($newtab), array_slice($head, $postab));
9660 } elseif ($mode ==
'remove' && preg_match(
'/^\-/', $values[1])) {
9661 if ($values[0] != $type) {
9664 $tabname = str_replace(
'-',
'', $values[1]);
9665 foreach ($head as $key => $val) {
9666 $condition = (!empty($values[3]) ?
verifCond($values[3],
'2') : 1);
9668 if ($head[$key][2] == $tabname && $condition) {
9678 if (!empty($hookmanager)) {
9679 $parameters = array(
'object' =>
$object,
'mode' => $mode,
'head' => &$head,
'filterorigmodule' => $filterorigmodule,
'type' => $type);
9681 $reshook = $hookmanager->executeHooks(
'completeTabsHead', $parameters,
$object);
9683 $head = $hookmanager->resArray;
9685 $head = array_merge($head, $hookmanager->resArray);
9703 if (is_null($string)) {
9707 if (preg_match(
'/^\[.*\]$/sm', $delimiter) || preg_match(
'/^\(.*\)$/sm', $delimiter)) {
9709 $newdelimiter = $delimiter;
9713 $newdelimiter = preg_quote($delimiter,
'/');
9716 if ($a = preg_split(
'/' . $newdelimiter .
'/', $string)) {
9718 foreach ($a as $s) {
9720 if ($pos = strpos($s, $kv)) {
9721 $ka[trim(substr($s, 0, $pos))] = trim(substr($s, $pos + strlen($kv)));
9744 preg_match_all(
'/"([^"]*)"|\'([^\']*)\'|(\S+)/', $input, $matches);
9748 $result = array_map(
9755 static function ($a, $b,
$c) {
9771 return array_values(array_filter(
9779 static function ($val) {
9795 if (!function_exists(
'getmypid')) {
9796 return mt_rand(99900000, 99965535);
9824function natural_search($fields, $value, $mode = 0, $nofirstand = 0, $sqltoadd =
'')
9828 $value = trim($value);
9831 $value = preg_replace(
'/\*/',
'%', $value);
9834 $value = preg_replace(
'/([!<>=]+)\s+([0-9' . preg_quote($langs->trans(
"SeparatorDecimal"),
'/') .
'\-])/',
'\1\2', $value);
9837 $value = preg_replace(
'/\s*\|\s*/',
'|', $value);
9841 if ($mode != -3 && $mode != 3) {
9844 $crits = array($value);
9848 if (!is_array($fields)) {
9849 $fields = array($fields);
9852 foreach ($crits as $crit) {
9853 $crit = trim($crit);
9857 foreach ($fields as $field) {
9859 $tmpcrits = explode(
'|', $crit);
9861 foreach ($tmpcrits as $tmpcrit) {
9862 if ($tmpcrit !==
'0' && empty($tmpcrit)) {
9865 $tmpcrit = trim($tmpcrit);
9867 $newres .= (($i2 > 0 || $i3 > 0) ?
' OR ' :
'');
9870 $newcrit = preg_replace(
'/([!<>=]+)/',
'', $tmpcrit);
9873 preg_match(
'/([!<>=]+)/', $tmpcrit, $reg);
9874 if (!empty($reg[1])) {
9875 $operator = $reg[1];
9877 if ($newcrit !=
'') {
9879 if (is_numeric($numnewcrit)) {
9880 $newres .= $db->sanitize($field) .
' ' . $operator .
' ' . ((float) $numnewcrit);
9888 } elseif ($mode == 2 || $mode == -2) {
9889 $crit = preg_replace(
'/[^\-0-9,]/',
'', $crit);
9890 $newres .= ($i2 > 0 ?
' OR ' :
'') . $db->sanitize($field) .
" " . ($mode == -2 ?
'NOT ' :
'');
9891 $newres .= $crit ?
"IN (" . $db->sanitize($db->escape($crit)) .
")" :
"IN (0)";
9893 $newres .=
' OR ' . $db->sanitize($field) .
' IS NULL';
9896 } elseif ($mode == 3 || $mode == -3) {
9897 $tmparray = explode(
',', $crit);
9898 if (count($tmparray)) {
9900 $listofcodesnot =
'';
9901 foreach ($tmparray as $val) {
9904 if (preg_match(
'/^!/', $val)) {
9905 $listofcodesnot .= ($listofcodesnot ?
',' :
'');
9906 $listofcodesnot .=
"'" . $db->escape(preg_replace(
'/^!=?/',
'', $val)) .
"'";
9908 $listofcodes .= ($listofcodes ?
',' :
'');
9909 $listofcodes .=
"'" . $db->escape($val) .
"'";
9913 $newres .= ($i2 > 0 ?
' OR ' :
'');
9914 if ($listofcodes && $listofcodesnot) {
9918 $newres .= $db->sanitize($field) .
" " . ($mode == -3 ?
'NOT IN' :
'IN') .
" (" . $db->sanitize($listofcodes, 1, 0, 1) .
")";
9920 if ($listofcodes && $listofcodesnot) {
9923 if ($listofcodesnot) {
9924 $newres .= $db->sanitize($field) .
" " . ($mode == -3 ?
'IN ' :
'NOT IN') .
" (" . $db->sanitize($listofcodesnot, 1, 0, 1) .
")";
9926 if ($listofcodes && $listofcodesnot) {
9932 $newres .=
' OR ' . $db->sanitize($field) .
' IS NULL';
9934 } elseif ($mode == 4) {
9935 $tmparray = explode(
',', $crit);
9936 if (count($tmparray)) {
9938 foreach ($tmparray as $val) {
9941 $newres .= ($i2 > 0 ?
" OR (" :
"(") . $db->sanitize($field) .
" LIKE '" . $db->escape($val) .
",%'";
9942 $newres .=
' OR ' . $db->sanitize($field) .
" = '" . $db->escape($val) .
"'";
9943 $newres .=
' OR ' . $db->sanitize($field) .
" LIKE '%," . $db->escape($val) .
"'";
9944 $newres .=
' OR ' . $db->sanitize($field) .
" LIKE '%," . $db->escape($val) .
",%'";
9951 $tmpcrits = explode(
'|', $crit);
9953 foreach ($tmpcrits as $tmpcrit) {
9954 if ($tmpcrit !==
'0' && empty($tmpcrit)) {
9957 $tmpcrit = trim($tmpcrit);
9959 if ($tmpcrit ==
'^$' || strpos($crit,
'!') === 0) {
9960 $newres .= (($i2 > 0 || $i3 > 0) ?
' AND ' :
'');
9962 $newres .= (($i2 > 0 || $i3 > 0) ?
' OR ' :
'');
9966 $table = $label = $key =
null;
9968 if (strpos($field,
'ef.') === 0) {
9969 $extrafieldName = substr($field, 3);
9971 $extrafields->fetch_name_optionals_label(
'product');
9973 if (isset($extrafields->attributes[
'product'][
'type'][$extrafieldName]) && $extrafields->attributes[
'product'][
'type'][$extrafieldName] ===
'sellist') {
9975 $paramArray = $extrafields->attributes[
'product'][
'param'][$extrafieldName][
'options'] ?? [];
9976 $param = array_key_first($paramArray);
9977 list($table, $label, $key) = explode(
':', $param);
9981 if (preg_match(
'/\.(id|rowid)$/', $field)) {
9982 $newres .= $db->sanitize($field) .
" = " . (is_numeric($tmpcrit) ? ((float) $tmpcrit) :
'0');
9984 $tmpcrit2 = $tmpcrit;
9989 if ($isSellist && $key && $table && $label) {
9990 $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) .
"%')";
9992 if (preg_match(
'/^!/', $tmpcrit)) {
9993 $tmps .= $db->sanitize($field) .
" NOT LIKE ";
9994 $tmpcrit2 = preg_replace(
'/^!/',
'', $tmpcrit2);
9996 $tmps .= $db->sanitize($field) .
" LIKE ";
10000 if (preg_match(
'/^[\^\$]/', $tmpcrit)) {
10002 $tmpcrit2 = preg_replace(
'/^[\^\$]/',
'', $tmpcrit2);
10004 if (preg_match(
'/[\^\$]$/', $tmpcrit)) {
10006 $tmpcrit2 = preg_replace(
'/[\^\$]$/',
'', $tmpcrit2);
10009 if ($tmpcrit2 ==
'' || preg_match(
'/^!/', $tmpcrit)) {
10010 $tmps =
"(" . $tmps;
10013 $newres .= $tmpbefore;
10014 $newres .= $db->escape($tmpcrit2);
10015 $newres .= $tmpafter;
10017 if ($tmpcrit2 ==
'' || preg_match(
'/^!/', $tmpcrit)) {
10018 $newres .=
" OR " . $db->sanitize($field) .
" IS NULL)";
10031 $newres .= ($newres ?
'' :
' OR ').str_replace(
'__KEYTOSEARCH__', $db->escape($crit), $sqltoadd);
10035 $res = $res . ($res ?
' AND ' :
'') . ($i2 > 1 ?
'(' :
'') . $newres . ($i2 > 1 ?
')' :
'');
10039 $res = ($nofirstand ?
"" :
" AND ") .
"(" . $res .
")";
10055 $dirName = dirname($file);
10056 if ($dirName ==
'.') {
10060 if (!in_array($extName, array(
'',
'_small',
'_mini'))) {
10061 return 'Bad parameter extName';
10064 $fileName = preg_replace(
'/(\.gif|\.jpeg|\.jpg|\.png|\.bmp|\.webp|\.avif)$/i',
'', $file);
10065 $fileName = basename($fileName);
10067 if (empty($extImgTarget)) {
10068 $extImgTarget = (preg_match(
'/\.jpg$/i', $file) ?
'.jpg' :
'');
10070 if (empty($extImgTarget)) {
10071 $extImgTarget = (preg_match(
'/\.jpeg$/i', $file) ?
'.jpeg' :
'');
10073 if (empty($extImgTarget)) {
10074 $extImgTarget = (preg_match(
'/\.gif$/i', $file) ?
'.gif' :
'');
10076 if (empty($extImgTarget)) {
10077 $extImgTarget = (preg_match(
'/\.png$/i', $file) ?
'.png' :
'');
10079 if (empty($extImgTarget)) {
10080 $extImgTarget = (preg_match(
'/\.bmp$/i', $file) ?
'.bmp' :
'');
10082 if (empty($extImgTarget)) {
10083 $extImgTarget = (preg_match(
'/\.webp$/i', $file) ?
'.webp' :
'');
10085 if (empty($extImgTarget)) {
10086 $extImgTarget = (preg_match(
'/\.avif$/i', $file) ?
'.avif' :
'');
10089 if (!$extImgTarget) {
10095 $subdir =
'thumbs/';
10098 return ($dirName ? $dirName .
'/' :
'') . $subdir . $fileName . $extName . $extImgTarget;
10112 $arrayspecialines = array(1 =>
'Transport', 2 =>
'EcoTax', 3 =>
'Option');
10113 if ($idcode > 10) {
10114 return 'Module ID ' . $idcode;
10116 if (!empty($arrayspecialines[$idcode])) {
10117 return $langs->trans($arrayspecialines[$idcode]);
10133 if (preg_match(
'/\.noexe$/i', $file)) {
10138 $mime_preview = array(
'avif',
'bmp',
'jpeg',
'png',
'gif',
'tiff',
'pdf',
'plain',
'css',
'webp',
'webm',
'mp4');
10140 $mime_preview[] =
'svg+xml';
10143 $mime_preview[] =
'xml';
10148 $num_mime = array_search(
dol_mimetype($file,
'', 1), $mime_preview);
10149 if ($num_mime !==
false) {
10167function dol_mimetype($file, $default =
'application/octet-stream', $mode = 0)
10170 $imgmime =
'other.png';
10171 $famime =
'file-o';
10174 $tmpfile = preg_replace(
'/\.noexe$/',
'', $file);
10177 if (preg_match(
'/\.txt$/i', $tmpfile)) {
10178 $mime =
'text/plain';
10179 $imgmime =
'text.png';
10180 $famime =
'file-alt';
10181 } elseif (preg_match(
'/\.rtx$/i', $tmpfile)) {
10182 $mime =
'text/richtext';
10183 $imgmime =
'text.png';
10184 $famime =
'file-alt';
10185 } elseif (preg_match(
'/\.csv$/i', $tmpfile)) {
10186 $mime =
'text/csv';
10187 $imgmime =
'text.png';
10188 $famime =
'file-csv';
10189 } elseif (preg_match(
'/\.tsv$/i', $tmpfile)) {
10190 $mime =
'text/tab-separated-values';
10191 $imgmime =
'text.png';
10192 $famime =
'file-alt';
10193 } elseif (preg_match(
'/\.(cf|conf|log)$/i', $tmpfile)) {
10194 $mime =
'text/plain';
10195 $imgmime =
'text.png';
10196 $famime =
'file-alt';
10197 } elseif (preg_match(
'/\.ini$/i', $tmpfile)) {
10198 $mime =
'text/plain';
10199 $imgmime =
'text.png';
10201 $famime =
'file-alt';
10202 } elseif (preg_match(
'/\.md$/i', $tmpfile)) {
10203 $mime =
'text/plain';
10204 $imgmime =
'text.png';
10206 $famime =
'file-alt';
10207 } elseif (preg_match(
'/\.css$/i', $tmpfile)) {
10208 $mime =
'text/css';
10209 $imgmime =
'css.png';
10211 $famime =
'file-alt';
10212 } elseif (preg_match(
'/\.lang$/i', $tmpfile)) {
10213 $mime =
'text/plain';
10214 $imgmime =
'text.png';
10216 $famime =
'file-alt';
10217 } elseif (preg_match(
'/\.(crt|cer|key|pub)$/i', $tmpfile)) {
10218 $mime =
'text/plain';
10219 $imgmime =
'text.png';
10220 $famime =
'file-alt';
10221 } elseif (preg_match(
'/\.(html|htm|shtml)$/i', $tmpfile)) {
10222 $mime =
'text/html';
10223 $imgmime =
'html.png';
10225 $famime =
'file-alt';
10226 } elseif (preg_match(
'/\.(xml|xhtml)$/i', $tmpfile)) {
10227 $mime =
'text/xml';
10228 $imgmime =
'other.png';
10230 $famime =
'file-alt';
10231 } elseif (preg_match(
'/\.xaml$/i', $tmpfile)) {
10232 $mime =
'text/xml';
10233 $imgmime =
'other.png';
10235 $famime =
'file-alt';
10236 } elseif (preg_match(
'/\.bas$/i', $tmpfile)) {
10237 $mime =
'text/plain';
10238 $imgmime =
'text.png';
10240 $famime =
'file-code';
10241 } elseif (preg_match(
'/\.(c)$/i', $tmpfile)) {
10242 $mime =
'text/plain';
10243 $imgmime =
'text.png';
10245 $famime =
'file-code';
10246 } elseif (preg_match(
'/\.(cpp)$/i', $tmpfile)) {
10247 $mime =
'text/plain';
10248 $imgmime =
'text.png';
10250 $famime =
'file-code';
10251 } elseif (preg_match(
'/\.cs$/i', $tmpfile)) {
10252 $mime =
'text/plain';
10253 $imgmime =
'text.png';
10255 $famime =
'file-code';
10256 } elseif (preg_match(
'/\.(h)$/i', $tmpfile)) {
10257 $mime =
'text/plain';
10258 $imgmime =
'text.png';
10260 $famime =
'file-code';
10261 } elseif (preg_match(
'/\.(java|jsp)$/i', $tmpfile)) {
10262 $mime =
'text/plain';
10263 $imgmime =
'text.png';
10265 $famime =
'file-code';
10266 } elseif (preg_match(
'/\.php([0-9]{1})?$/i', $tmpfile)) {
10267 $mime =
'text/plain';
10268 $imgmime =
'php.png';
10270 $famime =
'file-code';
10271 } elseif (preg_match(
'/\.phtml$/i', $tmpfile)) {
10272 $mime =
'text/plain';
10273 $imgmime =
'php.png';
10275 $famime =
'file-code';
10276 } elseif (preg_match(
'/\.(pl|pm)$/i', $tmpfile)) {
10277 $mime =
'text/plain';
10278 $imgmime =
'pl.png';
10280 $famime =
'file-code';
10281 } elseif (preg_match(
'/\.sql$/i', $tmpfile)) {
10282 $mime =
'text/plain';
10283 $imgmime =
'text.png';
10285 $famime =
'file-code';
10286 } elseif (preg_match(
'/\.js$/i', $tmpfile)) {
10287 $mime =
'text/x-javascript';
10288 $imgmime =
'jscript.png';
10290 $famime =
'file-code';
10291 } elseif (preg_match(
'/\.odp$/i', $tmpfile)) {
10292 $mime =
'application/vnd.oasis.opendocument.presentation';
10293 $imgmime =
'ooffice.png';
10294 $famime =
'file-powerpoint';
10295 } elseif (preg_match(
'/\.ods$/i', $tmpfile)) {
10296 $mime =
'application/vnd.oasis.opendocument.spreadsheet';
10297 $imgmime =
'ooffice.png';
10298 $famime =
'file-excel';
10299 } elseif (preg_match(
'/\.odt$/i', $tmpfile)) {
10300 $mime =
'application/vnd.oasis.opendocument.text';
10301 $imgmime =
'ooffice.png';
10302 $famime =
'file-word';
10303 } elseif (preg_match(
'/\.mdb$/i', $tmpfile)) {
10304 $mime =
'application/msaccess';
10305 $imgmime =
'mdb.png';
10307 } elseif (preg_match(
'/\.doc[xm]?$/i', $tmpfile)) {
10308 $mime =
'application/msword';
10309 $imgmime =
'doc.png';
10310 $famime =
'file-word';
10311 } elseif (preg_match(
'/\.dot[xm]?$/i', $tmpfile)) {
10312 $mime =
'application/msword';
10313 $imgmime =
'doc.png';
10314 $famime =
'file-word';
10315 } elseif (preg_match(
'/\.xlt(x)?$/i', $tmpfile)) {
10316 $mime =
'application/vnd.ms-excel';
10317 $imgmime =
'xls.png';
10318 $famime =
'file-excel';
10319 } elseif (preg_match(
'/\.xla(m)?$/i', $tmpfile)) {
10320 $mime =
'application/vnd.ms-excel';
10321 $imgmime =
'xls.png';
10322 $famime =
'file-excel';
10323 } elseif (preg_match(
'/\.xls$/i', $tmpfile)) {
10324 $mime =
'application/vnd.ms-excel';
10325 $imgmime =
'xls.png';
10326 $famime =
'file-excel';
10327 } elseif (preg_match(
'/\.xls[bmx]$/i', $tmpfile)) {
10328 $mime =
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
10329 $imgmime =
'xls.png';
10330 $famime =
'file-excel';
10331 } elseif (preg_match(
'/\.pps[mx]?$/i', $tmpfile)) {
10332 $mime =
'application/vnd.ms-powerpoint';
10333 $imgmime =
'ppt.png';
10334 $famime =
'file-powerpoint';
10335 } elseif (preg_match(
'/\.ppt[mx]?$/i', $tmpfile)) {
10336 $mime =
'application/x-mspowerpoint';
10337 $imgmime =
'ppt.png';
10338 $famime =
'file-powerpoint';
10339 } elseif (preg_match(
'/\.pdf$/i', $tmpfile)) {
10340 $mime =
'application/pdf';
10341 $imgmime =
'pdf.png';
10342 $famime =
'file-pdf';
10343 } elseif (preg_match(
'/\.bat$/i', $tmpfile)) {
10344 $mime =
'text/x-bat';
10345 $imgmime =
'script.png';
10347 $famime =
'file-code';
10348 } elseif (preg_match(
'/\.sh$/i', $tmpfile)) {
10349 $mime =
'text/x-sh';
10350 $imgmime =
'script.png';
10352 $famime =
'file-code';
10353 } elseif (preg_match(
'/\.ksh$/i', $tmpfile)) {
10354 $mime =
'text/x-ksh';
10355 $imgmime =
'script.png';
10357 $famime =
'file-code';
10358 } elseif (preg_match(
'/\.bash$/i', $tmpfile)) {
10359 $mime =
'text/x-bash';
10360 $imgmime =
'script.png';
10362 $famime =
'file-code';
10363 } elseif (preg_match(
'/\.ico$/i', $tmpfile)) {
10364 $mime =
'image/x-icon';
10365 $imgmime =
'image.png';
10366 $famime =
'file-image';
10367 } elseif (preg_match(
'/\.(jpg|jpeg)$/i', $tmpfile)) {
10368 $mime =
'image/jpeg';
10369 $imgmime =
'image.png';
10370 $famime =
'file-image';
10371 } elseif (preg_match(
'/\.png$/i', $tmpfile)) {
10372 $mime =
'image/png';
10373 $imgmime =
'image.png';
10374 $famime =
'file-image';
10375 } elseif (preg_match(
'/\.gif$/i', $tmpfile)) {
10376 $mime =
'image/gif';
10377 $imgmime =
'image.png';
10378 $famime =
'file-image';
10379 } elseif (preg_match(
'/\.bmp$/i', $tmpfile)) {
10380 $mime =
'image/bmp';
10381 $imgmime =
'image.png';
10382 $famime =
'file-image';
10383 } elseif (preg_match(
'/\.(tif|tiff)$/i', $tmpfile)) {
10384 $mime =
'image/tiff';
10385 $imgmime =
'image.png';
10386 $famime =
'file-image';
10387 } elseif (preg_match(
'/\.svg$/i', $tmpfile)) {
10388 $mime =
'image/svg+xml';
10389 $imgmime =
'image.png';
10390 $famime =
'file-image';
10391 } elseif (preg_match(
'/\.webp$/i', $tmpfile)) {
10392 $mime =
'image/webp';
10393 $imgmime =
'image.png';
10394 $famime =
'file-image';
10395 } elseif (preg_match(
'/\.vcs$/i', $tmpfile)) {
10396 $mime =
'text/calendar';
10397 $imgmime =
'other.png';
10398 $famime =
'file-alt';
10399 } elseif (preg_match(
'/\.ics$/i', $tmpfile)) {
10400 $mime =
'text/calendar';
10401 $imgmime =
'other.png';
10402 $famime =
'file-alt';
10403 } elseif (preg_match(
'/\.torrent$/i', $tmpfile)) {
10404 $mime =
'application/x-bittorrent';
10405 $imgmime =
'other.png';
10406 $famime =
'file-o';
10407 } elseif (preg_match(
'/\.(mp3|ogg|au|wav|wma|mid)$/i', $tmpfile)) {
10409 $imgmime =
'audio.png';
10410 $famime =
'file-audio';
10411 } elseif (preg_match(
'/\.mp4$/i', $tmpfile)) {
10412 $mime =
'video/mp4';
10413 $imgmime =
'video.png';
10414 $famime =
'file-video';
10415 } elseif (preg_match(
'/\.ogv$/i', $tmpfile)) {
10416 $mime =
'video/ogg';
10417 $imgmime =
'video.png';
10418 $famime =
'file-video';
10419 } elseif (preg_match(
'/\.webm$/i', $tmpfile)) {
10420 $mime =
'video/webm';
10421 $imgmime =
'video.png';
10422 $famime =
'file-video';
10423 } elseif (preg_match(
'/\.avif$/i', $tmpfile)) {
10424 $mime =
'image/avif';
10425 $imgmime =
'image.png';
10426 $famime =
'file-image';
10427 } elseif (preg_match(
'/\.avi$/i', $tmpfile)) {
10428 $mime =
'video/x-msvideo';
10429 $imgmime =
'video.png';
10430 $famime =
'file-video';
10431 } elseif (preg_match(
'/\.divx$/i', $tmpfile)) {
10432 $mime =
'video/divx';
10433 $imgmime =
'video.png';
10434 $famime =
'file-video';
10435 } elseif (preg_match(
'/\.xvid$/i', $tmpfile)) {
10436 $mime =
'video/xvid';
10437 $imgmime =
'video.png';
10438 $famime =
'file-video';
10439 } elseif (preg_match(
'/\.(wmv|mpg|mpeg)$/i', $tmpfile)) {
10441 $imgmime =
'video.png';
10442 $famime =
'file-video';
10443 } elseif (preg_match(
'/\.(zip|rar|gz|tgz|xz|z|cab|bz2|7z|tar|lzh|zst)$/i', $tmpfile)) {
10446 $imgmime =
'archive.png';
10447 $famime =
'file-archive';
10448 } elseif (preg_match(
'/\.(exe|com)$/i', $tmpfile)) {
10449 $mime =
'application/octet-stream';
10450 $imgmime =
'other.png';
10451 $famime =
'file-o';
10452 } elseif (preg_match(
'/\.(dll|lib|o|so|a)$/i', $tmpfile)) {
10454 $imgmime =
'library.png';
10455 $famime =
'file-o';
10456 } elseif (preg_match(
'/\.err$/i', $tmpfile)) {
10458 $imgmime =
'error.png';
10459 $famime =
'file-alt';
10462 if ($famime ==
'file-o') {
10468 switch ((
int) $mode) {
10470 $tmp = explode(
'/', $mime);
10471 return (!empty($tmp[1]) ? $tmp[1] : $tmp[0]);
10497 $tablename = preg_replace(
'/^' . preg_quote(MAIN_DB_PREFIX,
'/') .
'/',
'', $tablename);
10499 $dictvalues = (isset(
$conf->cache[
'dictvalues_' . $tablename]) ?
$conf->cache[
'dictvalues_' . $tablename] :
null);
10501 if (is_null($dictvalues)) {
10502 $dictvalues = array();
10504 $sql =
"SELECT * FROM " . MAIN_DB_PREFIX . $tablename .
" WHERE 1 = 1";
10505 if ($checkentity) {
10506 $sql .=
' AND entity IN (0,' .
getEntity($tablename) .
')';
10509 $resql = $db->query($sql);
10511 while ($obj = $db->fetch_object($resql)) {
10512 $dictvalues[$obj->$rowidfield] = $obj;
10515 dol_print_error($db);
10518 $conf->cache[
'dictvalues_' . $tablename] = $dictvalues;
10521 if (!empty($dictvalues[
$id])) {
10523 $tmp = $dictvalues[
$id];
10524 return (property_exists($tmp, $field) ? $tmp->$field :
'');
10539 $stringcolor = str_replace(
'#',
'', $stringcolor);
10541 if (!empty($stringcolor)) {
10543 $tmp = explode(
',', $stringcolor);
10544 if (count($tmp) > 1) {
10549 $hexr = $stringcolor[0] . $stringcolor[1];
10550 $hexg = $stringcolor[2] . $stringcolor[3];
10551 $hexb = $stringcolor[4] . $stringcolor[5];
10552 $r = hexdec($hexr);
10553 $g = hexdec($hexg);
10554 $b = hexdec($hexb);
10556 $bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0;
10557 if ($bright > 0.6) {
10576 if (empty($menuentry[
'enabled'])) {
10579 if ($type_user && array_key_exists(
'module', $menuentry) && $menuentry[
'module']) {
10580 $tmploops = explode(
'|', $menuentry[
'module']);
10582 foreach ($tmploops as $tmploop) {
10583 if (in_array($tmploop, $listofmodulesforexternal)) {
10592 if (!$menuentry[
'perms'] && $type_user) {
10598 if (!$menuentry[
'perms']) {
10613 $result = (ceil($n) % $x === 0) ? ceil($n) : (round(($n + $x / 2) / $x) * $x);
10614 return (
int) $result;
10630 global
$conf, $db, $hookmanager;
10636 $classfile = $classname = $classpath = $subdir = $dir_output = $dir_temp = $parent_element =
'';
10640 $element = $elementType;
10641 $subelement = $elementType;
10642 $table_element = $elementType;
10645 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $elementType, $regs)) {
10646 $element = $subelement = $regs[1];
10647 $table_element = $regs[2].
'_'.$regs[1];
10648 $subdir =
'/'.$regs[1];
10650 } elseif (preg_match(
'/^([^_]+)_([^_]+)/i', $element, $regs)) {
10653 $module = $element = $regs[1];
10654 $table_element = $elementType;
10655 $subelement = $regs[2];
10659 if (substr($elementType, -3) ==
'det') {
10660 $module = preg_replace(
'/det$/',
'', $element);
10661 $subelement = preg_replace(
'/det$/',
'', $subelement);
10662 $classpath =
$module .
'/class';
10664 $classname = preg_replace(
'/det$/',
'Line', $element);
10665 if (in_array(
$module, array(
'expedition',
'propale',
'facture',
'contrat',
'fichinter',
'ficheinter',
'supplier_order',
'commandefournisseur'))) {
10666 $classname = preg_replace(
'/det$/',
'Ligne', $element);
10670 if ($elementType ==
"action" || $elementType ==
"actioncomm") {
10671 $classpath =
'comm/action/class';
10672 $subelement =
'Actioncomm';
10674 $table_element =
'actioncomm';
10675 } elseif ($elementType ==
'cronjob') {
10676 $classpath =
'cron/class';
10678 $table_element =
'cron';
10679 } elseif ($elementType ==
'adherent_type') {
10680 $classpath =
'adherents/class';
10681 $classfile =
'adherent_type';
10683 $subelement =
'adherent_type';
10684 $classname =
'AdherentType';
10685 $table_element =
'adherent_type';
10686 } elseif ($elementType ==
'bank_account' || $elementType ==
'bank' || $elementType ==
'banque') {
10688 $classpath =
'compta/bank/class';
10690 $classfile =
'account';
10691 $classname =
'Account';
10692 $element = $subelement =
'bank_account';
10693 $table_element =
'bank_account';
10694 } elseif ($elementType ==
'bank_line') {
10695 $classpath =
'compta/bank/class';
10697 $classfile =
'account';
10698 $classname =
'AccountLine';
10699 } elseif ($elementType ==
'remisecheque') {
10700 $classpath =
'compta/paiement/cheque/class';
10701 $classfile =
'remisecheque';
10702 $classname =
'RemiseCheque';
10704 $element =
'chequereceipt';
10705 $subelement =
'cheque';
10706 $table_element =
'bordereau_cheque';
10707 } elseif ($elementType ==
'category') {
10708 $classpath =
'categories/class';
10710 $subelement =
'categorie';
10711 $table_element =
'categorie';
10712 } elseif ($elementType ==
'contact') {
10713 $classpath =
'contact/class';
10714 $classfile =
'contact';
10716 $subelement =
'contact';
10717 $table_element =
'socpeople';
10718 $subdir =
'/contact';
10719 } elseif ($elementType ==
'inventory') {
10721 $classpath =
'product/inventory/class';
10722 } elseif ($elementType ==
'inventoryline') {
10724 $classpath =
'product/inventory/class';
10725 $table_element =
'inventorydet';
10726 $parent_element =
'inventory';
10727 } elseif ($elementType ==
'stock' || $elementType ==
'entrepot' || $elementType ==
'warehouse') {
10729 $classpath =
'product/stock/class';
10730 $classfile =
'entrepot';
10731 $classname =
'Entrepot';
10732 $table_element =
'entrepot';
10733 } elseif ($elementType ==
'project' || $elementType ==
'projet') {
10734 $classpath =
'projet/class';
10736 $table_element =
'projet';
10737 $classfile =
'project';
10738 $classname =
'Project';
10739 } elseif ($elementType ==
'project_task') {
10740 $classpath =
'projet/class';
10742 $subelement =
'task';
10743 $table_element =
'projet_task';
10744 } elseif ($elementType ==
'mo') {
10745 $classpath =
'mrp/class';
10749 $table_element =
'mrp_mo';
10750 } elseif ($elementType ==
'facture' || $elementType ==
'invoice') {
10751 $classpath =
'compta/facture/class';
10753 $subelement =
'facture';
10754 $table_element =
'facture';
10755 } elseif ($elementType ==
'facturedet') {
10756 $classpath =
'compta/facture/class';
10757 $classfile =
'facture';
10758 $classname =
'FactureLigne';
10760 $table_element =
'facturedet';
10761 $parent_element =
'facture';
10762 } elseif ($elementType ==
'facturerec' || $elementType ==
'facture_rec') {
10763 $classpath =
'compta/facture/class';
10764 $classfile =
'facture-rec';
10766 $classname =
'FactureRec';
10767 } elseif ($elementType ==
'commande' || $elementType ==
'order') {
10768 $classpath =
'commande/class';
10770 $subelement =
'commande';
10771 $table_element =
'commande';
10772 } elseif ($elementType ==
'commandedet') {
10773 $classpath =
'commande/class';
10774 $classfile =
'commande';
10775 $classname =
'OrderLine';
10777 $table_element =
'commandedet';
10778 $parent_element =
'commande';
10779 } elseif ($elementType ==
'propal') {
10780 $classpath =
'comm/propal/class';
10781 $table_element =
'propal';
10782 } elseif ($elementType ==
'propaldet') {
10783 $classpath =
'comm/propal/class';
10784 $classfile =
'propal';
10785 $subelement =
'propaleligne';
10787 $table_element =
'propaldet';
10788 $parent_element =
'propal';
10789 } elseif ($elementType ==
'shipping' || $elementType ==
'shipment') {
10790 $classpath =
'expedition/class';
10791 $classfile =
'expedition';
10792 $classname =
'Expedition';
10794 $table_element =
'expedition';
10795 } elseif ($elementType ==
'expeditiondet' || $elementType ==
'shippingdet') {
10796 $classpath =
'expedition/class';
10797 $classfile =
'expedition';
10798 $classname =
'ExpeditionLigne';
10800 $table_element =
'expeditiondet';
10801 $parent_element =
'expedition';
10802 } elseif ($elementType ==
'delivery_note') {
10803 $classpath =
'delivery/class';
10804 $subelement =
'delivery';
10806 } elseif ($elementType ==
'delivery') {
10807 $classpath =
'delivery/class';
10808 $subelement =
'delivery';
10810 } elseif ($elementType ==
'deliverydet') {
10812 } elseif ($elementType ==
'supplier_proposal') {
10813 $classpath =
'supplier_proposal/class';
10814 $module =
'supplier_proposal';
10815 $element =
'supplierproposal';
10816 $classfile =
'supplier_proposal';
10817 $subelement =
'supplierproposal';
10818 } elseif ($elementType ==
'supplier_proposaldet') {
10819 $classpath =
'supplier_proposal/class';
10820 $module =
'supplier_proposal';
10821 $classfile =
'supplier_proposal';
10822 $classname =
'SupplierProposalLine';
10823 $table_element =
'supplier_proposaldet';
10824 $parent_element =
'supplier_proposal';
10825 } elseif ($elementType ==
'contract') {
10826 $classpath =
'contrat/class';
10828 $subelement =
'contrat';
10829 $table_element =
'contract';
10830 } elseif ($elementType ==
'contratdet') {
10831 $classpath =
'contrat/class';
10833 $table_element =
'contratdet';
10834 $parent_element =
'contrat';
10835 } elseif ($elementType ==
'mailing') {
10836 $classpath =
'comm/mailing/class';
10838 $classfile =
'mailing';
10839 $classname =
'Mailing';
10841 } elseif ($elementType ==
'member' || $elementType ==
'adherent') {
10842 $classpath =
'adherents/class';
10844 $subelement =
'adherent';
10845 $table_element =
'adherent';
10846 } elseif ($elementType ==
'subscription') {
10847 $classpath =
'adherents/class';
10848 $classfile =
'subscription';
10850 $subelement =
'subscription';
10851 $classname =
'Subscription';
10852 $table_element =
'subscription';
10853 } elseif ($elementType ==
'usergroup') {
10854 $classpath =
'user/class';
10856 } elseif ($elementType ==
'mrp') {
10857 $classpath =
'mrp/class';
10862 $table_element =
'mrp_mo';
10863 } elseif ($elementType ==
'mrp_production') {
10864 $classpath =
'mrp/class';
10866 $classname =
'MoLine';
10869 $table_element =
'mrp_production';
10870 $parent_element =
'mo';
10871 } elseif ($elementType ==
'cabinetmed_cons') {
10872 $classpath =
'cabinetmed/class';
10874 $subelement =
'cabinetmedcons';
10875 $table_element =
'cabinetmedcons';
10876 } elseif ($elementType ==
'fichinter' || $elementType ==
'ficheinter') {
10877 $classpath =
'fichinter/class';
10879 $subelement =
'fichinter';
10880 $table_element =
'fichinter';
10881 } elseif ($elementType ==
'dolresource' || $elementType ==
'resource') {
10882 $classpath =
'resource/class';
10884 $subelement =
'dolresource';
10885 $table_element =
'resource';
10886 } elseif ($elementType ==
'opensurvey_sondage') {
10887 $classpath =
'opensurvey/class';
10889 $subelement =
'opensurveysondage';
10890 } elseif ($elementType ==
'order_supplier' || $elementType ==
'supplier_order' || $elementType ==
'commande_fournisseur' || $elementType ==
'commandefournisseur') {
10891 $classpath =
'fourn/class';
10893 $classfile =
'fournisseur.commande';
10894 $element =
'order_supplier';
10896 $classname =
'CommandeFournisseur';
10897 $table_element =
'commande_fournisseur';
10898 } elseif ($elementType ==
'commande_fournisseurdet') {
10899 $classpath =
'fourn/class';
10901 $classfile =
'fournisseur.commande';
10902 $element =
'commande_fournisseurdet';
10904 $classname =
'CommandeFournisseurLigne';
10905 $table_element =
'commande_fournisseurdet';
10906 $parent_element =
'commande_fournisseur';
10907 } elseif ($elementType ==
'invoice_supplier' || $elementType ==
'supplier_invoice' || $elementType ==
'facture_fourn') {
10908 $classpath =
'fourn/class';
10910 $classfile =
'fournisseur.facture';
10911 $element =
'invoice_supplier';
10913 $classname =
'FactureFournisseur';
10914 $table_element =
'facture_fourn';
10915 } elseif ($elementType ==
'invoice_supplier_rec' || $elementType ==
'supplier_invoice_rec' || $elementType ==
'facture_fourn_rec') {
10916 $classpath =
'fourn/class';
10918 $classfile =
'fournisseur.facture-rec';
10919 $element =
'invoice_supplier_rec';
10921 $classname =
'FactureFournisseurRec';
10922 $table_element =
'facture_fourn_rec';
10923 } elseif ($elementType ==
'facture_fourn_det') {
10924 $classpath =
'fourn/class';
10926 $classfile =
'fournisseur.facture';
10927 $element =
'facture_fourn_det';
10929 $classname =
'SupplierInvoiceLine';
10930 $table_element =
'facture_fourn_det';
10931 $parent_element =
'invoice_supplier';
10932 } elseif ($elementType ==
"service") {
10933 $classpath =
'product/class';
10935 $subelement =
'product';
10936 $table_element =
'product';
10937 } elseif ($elementType ==
'product_attribute') {
10939 $element =
'product_attribute';
10940 $subelement =
'product_attribute';
10941 $classpath =
'variants/class';
10942 $classfile =
'ProductAttribute';
10943 $classname =
'ProductAttribute';
10944 $table_element =
'product_attribute';
10945 } elseif ($elementType ==
'product_attribute_value') {
10947 $element =
'product_attribute_value';
10948 $subelement =
'product_attribute_value';
10949 $classpath =
'variants/class';
10950 $classfile =
'ProductAttributeValue';
10951 $classname =
'ProductAttributeValue';
10952 $table_element =
'product_attribute_value';
10953 $parent_element =
'product_attribute';
10954 } elseif ($elementType ==
'salary') {
10955 $classpath =
'salaries/class';
10957 } elseif ($elementType ==
'payment_salary') {
10958 $classpath =
'salaries/class';
10959 $classfile =
'paymentsalary';
10960 $classname =
'PaymentSalary';
10962 } elseif ($elementType ==
'payment') {
10963 $classpath =
'compta/paiement/class';
10964 $classfile =
'paiement';
10965 $classname =
'Paiement';
10967 $element =
'payment';
10968 $subelement =
'payment';
10969 $table_element =
'paiement';
10970 } elseif ($elementType ==
'payment_supplier') {
10971 $classpath =
'fourn/class';
10972 $classfile =
'paiementfourn';
10973 $classname =
'PaiementFourn';
10975 $element =
'payment_supplier';
10976 $subelement =
'payment_supplier';
10977 $table_element =
'paiementfourn';
10978 } elseif ($elementType ==
'payment_various') {
10979 $classpath =
'compta/bank/class';
10980 $classfile =
'paymentvarious';
10981 $classname =
'PaymentVarious';
10983 $element =
'payment_various';
10984 $subelement =
'payment_various';
10985 $table_element =
'payment_various';
10986 } elseif ($elementType ==
'stocktransfer') {
10987 $classpath =
'product/stock/stocktransfer/class';
10988 $classfile =
'stocktransfer';
10989 $classname =
'StockTransfer';
10991 $subelement =
'stocktransfer';
10992 $table_element =
'stocktransfer_stocktransfer';
10993 } elseif ($elementType ==
'job' || $elementType ==
'position' || $elementType ==
'skill' || $elementType ==
'evaluation') {
10994 $classpath =
'hrm/class';
10995 $classfile = $elementType;
10996 $classname = ucfirst($elementType);
10998 $subelement = $elementType;
10999 $table_element = ($elementType ==
'position' ?
'hrm_job_user' :
'hrm_'.$elementType);
11000 $subdir =
'/'.$elementType;
11001 } elseif ($elementType ==
'productlot') {
11003 $classpath =
'product/stock/class';
11004 $classfile =
'productlot';
11005 $classname =
'Productlot';
11006 $element =
'productlot';
11008 $table_element =
'product_lot';
11009 } elseif ($elementType ==
'societeaccount') {
11010 $classpath =
'societe/class';
11011 $classfile =
'societeaccount';
11012 $classname =
'SocieteAccount';
11014 } elseif ($elementType ==
'websitepage' || $elementType ==
'website_page') {
11015 $classpath =
'website/class';
11016 $classfile =
'websitepage';
11017 $classname =
'Websitepage';
11019 $subelement =
'websitepage';
11020 $table_element =
'website_page';
11021 } elseif ($elementType ==
'fiscalyear') {
11022 $classpath =
'core/class';
11024 $subelement =
'fiscalyear';
11025 } elseif ($elementType ==
'chargesociales') {
11026 $classpath =
'compta/sociales/class';
11028 $table_element =
'chargesociales';
11029 } elseif ($elementType ==
'tva') {
11030 $classpath =
'compta/tva/class';
11033 $table_element =
'tva';
11034 } elseif ($elementType ==
'emailsenderprofile') {
11036 $classpath =
'core/class';
11037 $classfile =
'emailsenderprofile';
11038 $classname =
'EmailSenderProfile';
11039 $table_element =
'c_email_senderprofile';
11041 } elseif ($elementType ==
'conferenceorboothattendee') {
11042 $classpath =
'eventorganization/class';
11043 $classfile =
'conferenceorboothattendee';
11044 $classname =
'ConferenceOrBoothAttendee';
11045 $module =
'eventorganization';
11046 } elseif ($elementType ==
'conferenceorbooth') {
11047 $classpath =
'eventorganization/class';
11048 $classfile =
'conferenceorbooth';
11049 $classname =
'ConferenceOrBooth';
11050 $module =
'eventorganization';
11051 $subdir =
'/conferenceorbooth';
11052 } elseif ($elementType ==
'ccountry') {
11054 $classpath =
'core/class';
11055 $classfile =
'ccountry';
11056 $classname =
'Ccountry';
11057 $table_element =
'c_country';
11059 } elseif ($elementType ==
'ecmfiles') {
11061 $classpath =
'ecm/class';
11062 $classfile =
'ecmfiles';
11063 $classname =
'Ecmfiles';
11064 $table_element =
'ecmfiles';
11066 } elseif ($elementType ==
'knowledgerecord' || $elementType ==
'knowledgemanagement') {
11067 $module =
'knowledgemanagement';
11068 $classpath =
'knowledgemanagement/class';
11069 $classfile =
'knowledgerecord';
11070 $classname =
'KnowledgeRecord';
11071 $table_element =
'knowledgemanagement_knowledgerecord';
11073 } elseif ($elementType ==
'customer') {
11075 $classpath =
'societe/class';
11076 $classfile =
'client';
11077 $classname =
'Client';
11078 $table_element =
'societe';
11080 } elseif ($elementType ==
'fournisseur' || $elementType ==
'supplier') {
11082 $classpath =
'fourn/class';
11083 $classfile =
'fournisseur';
11084 $classname =
'Fournisseur';
11085 $table_element =
'societe';
11087 } elseif ($elementType ==
'recruitmentcandidature') {
11089 $classfile =
'recruitmentcandidature';
11090 $classpath =
'recruitment/class';
11091 $classname =
'RecruitmentCandidature';
11092 $subelement =
'recruitmentcandidature';
11093 $subdir =
'/recruitmentcandidature';
11094 } elseif ($elementType ==
'recruitmentjobposition') {
11096 $classfile =
'recruitmentjobposition';
11097 $classpath =
'recruitment/class';
11098 $classname =
'RecruitmentJobPosition';
11099 $subelement =
'recruitmentjobposition';
11100 $subdir =
'/recruitmentjobposition';
11101 } elseif ($elementType ==
'recruitment') {
11106 $classfile =
'recruitmentjobposition';
11107 $classpath =
'recruitment/class';
11108 $classname =
'RecruitmentJobPosition';
11109 $element = $subelement =
'recruitmentjobposition';
11110 $table_element =
'recruitment_recruitmentjobposition';
11111 $subdir =
'/recruitmentjobposition';
11112 } elseif ($elementType ==
'product_attribute_combination') {
11114 $classpath =
'variants/class';
11115 $classfile =
'ProductCombination';
11116 $classname =
'ProductCombination';
11117 $element =
'productcombination';
11119 $table_element =
'product_attribute_combination';
11120 } elseif ($elementType ==
'product_attribute_combination2val') {
11122 $classpath =
'variants/class';
11123 $classfile =
'ProductCombination2ValuePair';
11124 $classname =
'ProductCombination2ValuePair';
11125 $element =
'productcombination2valuepair';
11127 $table_element =
'product_attribute_combination2val';
11128 } elseif ($elementType ==
'product_attribute_combination_price_level') {
11131 $classpath =
'variants/class';
11132 $classfile =
'ProductCombination';
11133 $classname =
'ProductCombinationLevel';
11134 $element =
'productcombinationlevel';
11136 $table_element =
'product_attribute_combination_price_level';
11140 if (empty($classfile)) {
11141 $classfile = strtolower($subelement);
11143 if (empty($classname)) {
11144 $classname = ucfirst($subelement);
11146 if (empty($classpath)) {
11147 $classpath =
$module .
'/class';
11154 if (!empty(
$conf->$module->multidir_output[
$conf->entity])) {
11155 $dir_output =
$conf->$module->multidir_output[
$conf->entity];
11156 } elseif (!empty(
$conf->$module->output[
$conf->entity])) {
11157 $dir_output =
$conf->$module->output[
$conf->entity];
11158 } elseif (!empty(
$conf->$module->dir_output)) {
11159 $dir_output =
$conf->$module->dir_output;
11161 if (!empty(
$conf->$module->multidir_temp[
$conf->entity])) {
11162 $dir_temp =
$conf->$module->multidir_temp[
$conf->entity];
11163 } elseif (!empty(
$conf->$module->temp[
$conf->entity])) {
11164 $dir_temp =
$conf->$module->temp[
$conf->entity];
11165 } elseif (!empty(
$conf->$module->dir_temp)) {
11166 $dir_temp =
$conf->$module->dir_temp;
11171 if ($element ==
'order_supplier' &&
isModEnabled(
'fournisseur')) {
11172 $dir_output =
$conf->fournisseur->commande->dir_output;
11173 $dir_temp =
$conf->fournisseur->commande->dir_temp;
11174 } elseif ($element ==
'invoice_supplier' &&
isModEnabled(
'fournisseur')) {
11175 $dir_output =
$conf->fournisseur->facture->dir_output;
11176 $dir_temp =
$conf->fournisseur->facture->dir_temp;
11177 } elseif ($elementType ==
'payment' &&
isModEnabled(
'invoice') && isset(
$conf->compta->payment)) {
11181 $dir_output =
$conf->compta->payment->dir_output;
11182 $dir_temp =
$conf->compta->payment->dir_temp;
11183 } elseif ($elementType ==
'payment_supplier' &&
isModEnabled(
'fournisseur') && isset(
$conf->fournisseur->payment)) {
11184 $dir_output =
$conf->fournisseur->payment->dir_output;
11185 $dir_temp =
$conf->fournisseur->payment->dir_temp;
11190 if (!empty($dir_output)) {
11191 $dir_output .= $subdir;
11193 if (!empty($dir_temp)) {
11195 $dir_temp .= $subdir;
11198 $elementProperties = array(
11200 'element' => $element,
11201 'table_element' => $table_element,
11202 'subelement' => $subelement,
11203 'classpath' => $classpath,
11204 'classfile' => $classfile,
11205 'classname' => $classname,
11206 'dir_output' => $dir_output,
11207 'dir_temp' => $dir_temp,
11208 'parent_element' => $parent_element,
11213 if (!is_object($hookmanager)) {
11214 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
11217 $hookmanager->initHooks(array(
'elementproperties'));
11221 $parameters = array(
11222 'elementType' => $elementType,
11223 'elementProperties' => $elementProperties
11226 $reshook = $hookmanager->executeHooks(
'getElementProperties', $parameters);
11229 $elementProperties = $hookmanager->resArray;
11230 } elseif (!empty($hookmanager->resArray) && is_array($hookmanager->resArray)) {
11231 $elementProperties = array_replace($elementProperties, $hookmanager->resArray);
11235 if (($key = array_search(
'elementproperties', $hookmanager->contextarray)) !==
false) {
11236 unset($hookmanager->contextarray[$key]);
11239 return $elementProperties;
11255function fetchObjectByElement($element_id, $element_type, $element_ref =
'', $useCache = 0, $maxCacheByType = 10)
11265 if ($element_prop[
'module'] ==
'product' || $element_prop[
'module'] ==
'service') {
11271 } elseif ($element_prop[
'module'] ==
'societeaccount') {
11274 $ismodenabled =
isModEnabled($element_prop[
'module']);
11280 if (is_array($element_prop) && (empty($element_prop[
'module']) || $ismodenabled)) {
11281 if ($useCache === 1 && $element_id > 0
11282 && !empty(
$conf->cache[
'fetchObjectByElement'][$element_type])
11283 && !empty(
$conf->cache[
'fetchObjectByElement'][$element_type][$element_id])
11284 && is_object(
$conf->cache[
'fetchObjectByElement'][$element_type][$element_id])
11286 return $conf->cache[
'fetchObjectByElement'][$element_type][$element_id];
11289 $includeresult =
dol_include_once(
'/' . $element_prop[
'classpath'] .
'/' . $element_prop[
'classfile'] .
'.class.php');
11290 if ($includeresult ===
false) {
11291 dol_syslog(
'fetchObjectByElement: class file /' . $element_prop[
'classpath'] .
'/' . $element_prop[
'classfile'] .
'.class.php not found for element ' . $element_type, LOG_WARNING);
11295 if (class_exists($element_prop[
'classname'])) {
11296 $className = $element_prop[
'classname'];
11300 $isinternalclass = (
new ReflectionClass($className))->isInternal();
11301 }
catch (ReflectionException $e) {
11302 $isinternalclass =
false;
11304 if ($isinternalclass) {
11305 dol_syslog(
'fetchObjectByElement: refuse to instantiate PHP internal class ' . $className .
' for element ' . $element_type, LOG_ERR);
11308 $objecttmp =
new $className($db);
11309 '@phan-var-force CommonObject $objecttmp';
11312 if ($element_id > 0 || !empty($element_ref)) {
11315 if (empty($element_id) && !empty($element_ref) && (in_array($objecttmp->element, array(
'evaluation',
'job',
'position',
'skill')))) {
11316 $element_id = $element_ref;
11320 $ret = $objecttmp->fetch($element_id, $element_ref);
11322 if (empty($objecttmp->module)) {
11323 $objecttmp->module = $element_prop[
'module'];
11326 if ($useCache > 0) {
11327 if (!isset(
$conf->cache[
'fetchObjectByElement'][$element_type])) {
11328 $conf->cache[
'fetchObjectByElement'][$element_type] = [];
11332 if (! empty(
$conf->cache[
'fetchObjectByElement'][$element_type]) && is_array(
$conf->cache[
'fetchObjectByElement'][$element_type]) && count(
$conf->cache[
'fetchObjectByElement'][$element_type]) >= $maxCacheByType) {
11333 array_shift(
$conf->cache[
'fetchObjectByElement'][$element_type]);
11336 $conf->cache[
'fetchObjectByElement'][$element_type][$element_id] = $objecttmp;
11345 dol_syslog($element_prop[
'classname'] .
" doesn't exists in /" . $element_prop[
'classpath'] .
"/" . $element_prop[
'classfile'] .
".class.php");
11360 $arrayofregexextension = array(
11387 return $arrayofregexextension;
11400 foreach ($arrayofregexextension as $fileextension) {
11401 if (preg_match(
'/\.' . preg_quote($fileextension,
'/') .
'$/i', $filename)) {
11418 return empty($_SESSION[
'newtoken']) ?
'' : $_SESSION[
'newtoken'];
11430 return isset($_SESSION[
'token']) ? $_SESSION[
'token'] :
'';
11442 if (empty(
$conf->cache[
'nonce'])) {
11443 include_once DOL_DOCUMENT_ROOT .
'/core/lib/security.lib.php';
11447 return $conf->cache[
'nonce'];
11461 if ($method == -1) {
11472 $level = ob_get_level();
11474 while (ob_get_level() > $level) {
11479 if ($method == 0) {
11480 readfile($fullpath_original_file_osencoded);
11481 } elseif ($method == 1) {
11483 $handle = fopen($fullpath_original_file_osencoded,
"rb");
11484 while (!feof($handle)) {
11485 print fread($handle, 8192);
11488 } elseif ($method == 2) {
11490 $handle1 = fopen($fullpath_original_file_osencoded,
"rb");
11491 $handle2 = fopen(
"php://output",
"wb");
11492 stream_copy_to_stream($handle1, $handle2);
11508 $result = json_decode($stringtodecode, $assoc);
11509 if ($result ===
null) {
11510 $result = unserialize($stringtodecode, [
'allowed_classes' =>
false]);
11538 if (is_null($filter) || !is_string($filter) || $filter ===
'') {
11541 if (!preg_match(
'/^\(.*\)$/', $filter)) {
11542 $filter =
'(' . $filter .
')';
11545 $regexstring =
'\(([a-zA-Z0-9_\.]+:[<>!=insotlke]+:[^\(\)]+)\)';
11546 $firstandlastparenthesis = 0;
11548 if (!
dolCheckFilters($filter, $errorstr, $firstandlastparenthesis)) {
11552 return 'Filter syntax error - ' . $errorstr;
11557 $t = preg_replace_callback(
'/' . $regexstring .
'/i',
'dolForgeDummyCriteriaCallback', $filter);
11558 $t = str_ireplace(array(
'and',
'or',
' '),
'', $t);
11561 if (preg_match(
'/[^\(\)]/', $t)) {
11562 $tmperrorstr =
'Bad syntax of the search string';
11563 $errorstr =
'Bad syntax of the search string: ' . $filter;
11567 dol_syslog(
"forgeSQLFromUniversalSearchCriteria Filter error - " . $errorstr, LOG_WARNING);
11568 return 'Filter error - ' . $tmperrorstr;
11572 global $globalforbiddenfields;
11573 $globalforbiddenfields = $forbiddenfields;
11575 $ret = ($noand ?
"" :
" AND ") . ($nopar ?
"" :
'(');
11576 $ret .= preg_replace_callback(
'/' . $regexstring .
'/i',
'dolForgeSQLCriteriaCallback', $filter);
11577 $ret .= ($nopar ?
"" :
')');
11579 if (is_object($db)) {
11580 $ret = str_replace(
'__NOW__',
"'" . $db->idate(
dol_now()) .
"'", $ret);
11582 if (is_object($user)) {
11583 $ret = str_replace(
'__USER_ID__', (
string) $user->id, $ret);
11598 $arrayofandtags = array();
11602 $parenthesislevel = 0;
11607 if ($parenthesislevel >= 1) {
11608 $sqlfilters = preg_replace(
'/^\(/',
'', preg_replace(
'/\)$/',
'', $sqlfilters));
11613 $countparenthesis = 0;
11614 while ($i < $nbofchars) {
11617 if ($char ==
'(') {
11618 $countparenthesis++;
11619 } elseif ($char ==
')') {
11620 $countparenthesis--;
11623 if ($countparenthesis == 0) {
11624 $char2 =
dol_substr($sqlfilters, $i + 1, 1);
11625 $char3 =
dol_substr($sqlfilters, $i + 2, 1);
11626 if ($char ==
'A' && $char2 ==
'N' && $char3 ==
'D') {
11629 if (!preg_match(
'/^\(.*\)$/', $s)) {
11630 $s =
'(' . $s .
')';
11632 $arrayofandtags[] = $s;
11645 if (!preg_match(
'/^\(.*\)$/', $s)) {
11646 $s =
'(' . $s .
')';
11648 $arrayofandtags[] = $s;
11651 return $arrayofandtags;
11663function dolCheckFilters($sqlfilters, &$error =
'', &$parenthesislevel = 0)
11667 $tmp = $sqlfilters;
11671 $parenthesislevel = 0;
11679 if ($char ==
'(') {
11680 if ($i == $parenthesislevel && $parenthesislevel == $counter) {
11682 $parenthesislevel++;
11685 } elseif ($char ==
')') {
11686 $nbcharremaining = ($nb - $i - 1);
11687 if ($nbcharremaining >= $counter) {
11688 $parenthesislevel = min($parenthesislevel, $counter - 1);
11690 if ($parenthesislevel > $counter && $nbcharremaining >= $counter) {
11691 $parenthesislevel = $counter;
11696 if ($counter < 0) {
11697 $error =
"Wrong balance of parenthesis in sqlfilters=" . $sqlfilters;
11698 $parenthesislevel = 0;
11706 if ($counter > 0) {
11707 $error =
"Wrong balance of parenthesis in sqlfilters=" . $sqlfilters;
11708 $parenthesislevel = 0;
11726 if (empty($matches[1])) {
11729 $tmp = explode(
':', $matches[1]);
11730 if (count($tmp) < 3) {
11749 global $globalforbiddenfields;
11752 if (empty($matches[1])) {
11755 $tmp = explode(
':', $matches[1], 3);
11756 if (count($tmp) < 3) {
11762 $newforbiddenfields = $globalforbiddenfields;
11763 if (!is_array($newforbiddenfields)) {
11764 $newforbiddenfields = array();
11767 $newforbiddenfields[] =
'pass';
11768 $newforbiddenfields[] =
'pass_crypted';
11769 $newforbiddenfields[] =
'api_key';
11771 $operand = preg_replace(
'/[^a-z0-9\._]/i',
'', trim($tmp[0]));
11774 if (!empty($newforbiddenfields)) {
11775 $operandwithoutprefix = preg_replace(
'/^[a-z0-9_]+\./i',
'', $operand);
11776 if (in_array(strtolower($operandwithoutprefix), $newforbiddenfields)) {
11781 $operator = strtoupper(preg_replace(
'/[^a-z<>!=]/i',
'', trim($tmp[1])));
11784 'NOTLIKE' =>
'NOT LIKE',
11785 'ISNOT' =>
'IS NOT',
11786 'NOTIN' =>
'NOT IN',
11790 if (array_key_exists($operator, $realOperator)) {
11791 $operator = $realOperator[$operator];
11794 $tmpescaped = $tmp[2];
11800 if ($operator ==
'IN' || $operator ==
'NOT IN') {
11801 global $dolibarr_allow_unsecured_select_in_extrafields_filter;
11804 $tmpescaped2 =
'(';
11806 $tmpelemarray = explode(
',', $tmpescaped);
11807 foreach ($tmpelemarray as $tmpkey => $tmpelem) {
11809 $tmpelem = trim($tmpelem);
11810 if (preg_match(
'/^\'(.*)\'$/', $tmpelem, $reg)) {
11811 $tmpelemarray[$tmpkey] =
"'".$db->escape($db->sanitize($reg[1], 2, 1, 1, 1)).
"'";
11812 } elseif (preg_match(
'/^[0-9]+$/', (
string) $tmpelem)) {
11813 $tmpelemarray[$tmpkey] = (int) $tmpelem;
11814 } elseif (is_numeric((
string) $tmpelem)) {
11815 $tmpelemarray[$tmpkey] = (float) $tmpelem;
11816 } elseif (!empty($dolibarr_allow_unsecured_select_in_extrafields_filter)) {
11817 $tmpelemarray[$tmpkey] = preg_replace(
'/[^a-z0-9_<>=!\s]/i',
'', $tmpelem);
11819 $tmpelemarray[$tmpkey] = preg_replace(
'/[^a-z0-9_]/i',
'', $tmpelem);
11822 $tmpescaped2 .= implode(
',', $tmpelemarray);
11823 $tmpescaped2 .=
')';
11825 $tmpescaped = $tmpescaped2;
11826 } elseif ($operator ==
'LIKE' || $operator ==
'NOT LIKE') {
11827 if (preg_match(
'/^\'([^\']*)\'$/', $tmpescaped, $regbis)) {
11828 $tmpescaped = $regbis[1];
11831 $tmpescaped =
"'" . $db->escape($tmpescaped) .
"'";
11832 } elseif (preg_match(
'/^\'(.*)\'$/', $tmpescaped, $regbis)) {
11835 $tmpescaped =
"'" . $db->escape($regbis[1]) .
"'";
11837 if (strtoupper($tmpescaped) ==
'NULL') {
11838 $tmpescaped =
'NULL';
11839 } elseif (preg_match(
'/^[0-9]+$/', (
string) $tmpescaped)) {
11840 $tmpescaped = (int) $tmpescaped;
11841 } elseif (is_numeric((
string) $tmpescaped)) {
11842 $tmpescaped = (float) $tmpescaped;
11844 $tmpescaped = preg_replace(
'/[^a-z0-9_]/i',
'', $tmpescaped);
11848 return '(' . $db->escape($operand) .
' ' . strtoupper($operator) .
' ' . $tmpescaped .
')';
11863 dol_syslog(
'getTimelineIcon::begin', LOG_DEBUG);
11866 $out =
'<!-- timeline icon -->' .
"\n";
11867 $iconClass =
'fa fa-comments';
11872 if ($histo[$key][
'percent'] == -1) {
11873 $colorClass =
'timeline-icon-not-applicble';
11874 $pictoTitle = $langs->trans(
'StatusNotApplicable');
11875 } elseif ($histo[$key][
'percent'] == 0) {
11876 $colorClass =
'timeline-icon-todo';
11877 $pictoTitle = $langs->trans(
'StatusActionToDo') .
' (0%)';
11878 } elseif ($histo[$key][
'percent'] > 0 && $histo[$key][
'percent'] < 100) {
11879 $colorClass =
'timeline-icon-in-progress';
11880 $pictoTitle = $langs->trans(
'StatusActionInProcess') .
' (' . $histo[$key][
'percent'] .
'%)';
11881 } elseif ($histo[$key][
'percent'] >= 100) {
11882 $colorClass =
'timeline-icon-done';
11883 $pictoTitle = $langs->trans(
'StatusActionDone') .
' (100%)';
11886 if ($actionstatic->code ==
'AC_TICKET_CREATE') {
11887 $iconClass =
'fa fa-ticket';
11888 } elseif ($actionstatic->code ==
'AC_TICKET_MODIFY') {
11889 $iconClass =
'fa fa-pencilxxx';
11890 } elseif (preg_match(
'/^TICKET_MSG/', $actionstatic->code)) {
11891 $iconClass =
'fa fa-comments';
11892 } elseif (preg_match(
'/^TICKET_MSG_PRIVATE/', $actionstatic->code)) {
11893 $iconClass =
'fa fa-mask';
11895 if ($actionstatic->type_picto) {
11896 $img_picto = img_picto(
'', $actionstatic->type_picto);
11898 if ($actionstatic->type_code ==
'AC_RDV') {
11899 $iconClass =
'fa fa-handshake';
11900 } elseif ($actionstatic->type_code ==
'AC_TEL') {
11901 $iconClass =
'fa fa-phone';
11902 } elseif ($actionstatic->type_code ==
'AC_FAX') {
11903 $iconClass =
'fa fa-fax';
11904 } elseif ($actionstatic->type_code ==
'AC_EMAIL') {
11905 $iconClass =
'fa fa-envelope';
11906 } elseif ($actionstatic->type_code ==
'AC_INT') {
11907 $iconClass =
'fa fa-shipping-fast';
11908 } elseif ($actionstatic->type_code ==
'AC_OTH_AUTO') {
11909 $iconClass =
'fa fa-robot';
11910 } elseif (!preg_match(
'/_AUTO/', $actionstatic->type_code)) {
11911 $iconClass =
'fa fa-robot';
11916 $out .=
'<i class="' . $iconClass .
' ' . $colorClass .
'" title="' . $pictoTitle .
'">' . $img_picto .
'</i>' .
"\n";
11930 $documents = array();
11932 $sql =
'SELECT ecm.rowid as id, ecm.src_object_type, ecm.src_object_id, ecm.filepath, ecm.filename, ecm.agenda_id';
11933 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'ecm_files ecm';
11934 $sql .=
" WHERE ecm.filepath = 'agenda/" . ((int)
$object->id) .
"'";
11936 $sql .=
' OR ecm.agenda_id = ' . (int)
$object->id;
11937 $sql .=
' ORDER BY ecm.position ASC';
11939 $resql = $db->query($sql);
11941 if ($db->num_rows($resql)) {
11942 while ($obj = $db->fetch_object($resql)) {
11943 $documents[$obj->id] = $obj;
11963function buildParamDate($prefix, $timestamp =
null, $hourTime =
'', $gm =
'auto')
11965 if ($timestamp ===
null) {
11966 $timestamp =
GETPOSTDATE($prefix, $hourTime, $gm);
11973 if ($hourTime ===
'getpost' || ($timestamp !==
null &&
dol_print_date($timestamp,
'%H:%M:%S') !==
'00:00:00')) {
11974 $TParam = array_merge($TParam, array(
11981 return '&' . http_build_query($TParam);
12002function recordNotFound($message =
'', $printheader = 1, $printfooter = 1, $showonlymessage = 0, $params =
null)
12004 global
$conf, $db, $langs, $hookmanager;
12007 if (!is_object($langs)) {
12008 include_once DOL_DOCUMENT_ROOT .
'/core/class/translate.class.php';
12010 $langs->setDefaultLang();
12013 $langs->load(
"errors");
12015 if ($printheader) {
12016 if (function_exists(
"llxHeader")) {
12018 } elseif (function_exists(
"llxHeaderVierge")) {
12023 print
'<div class="error">';
12024 if (empty($message)) {
12025 print $langs->trans(
"ErrorRecordNotFound");
12027 print $langs->trans($message);
12032 if (empty($showonlymessage)) {
12033 if (empty($hookmanager)) {
12034 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
12037 $hookmanager->initHooks(array(
'main'));
12040 $parameters = array(
'message' => $message,
'params' => $params);
12041 $reshook = $hookmanager->executeHooks(
'getErrorRecordNotFound', $parameters,
$object, $action);
12042 print $hookmanager->resPrint;
12045 if ($printfooter && function_exists(
"llxFooter")) {
12047 if (is_object($db)) {
12088 foreach ($array2 as $key => $value) {
12089 if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
12092 $merged[$key] = $value;
12107 if (!empty($obj->socid)) {
12108 return (
int) $obj->socid;
12109 } elseif (!empty($obj->soc_id)) {
12110 return (
int) $obj->soc_id;
12111 } elseif (!empty($obj->societe_id)) {
12112 return (
int) $obj->societe_id;
12125 if (!empty($_SESSION[
'dol_screenheight']) && $_SESSION[
'dol_screenheight'] < 700) {
12127 } elseif (!empty($_SESSION[
'dol_screenheight']) && $_SESSION[
'dol_screenheight'] < 950) {
12129 } elseif (!empty($_SESSION[
'dol_screenheight']) && $_SESSION[
'dol_screenheight'] > 1130) {
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
global $dolibarr_main_url_root
if(!defined( 'NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined( 'NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined( 'NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined( 'NOIPCHECK')) llxHeaderVierge($title, $head="", $disablejs=0, $disablehead=0, $arrayofjs=[], $arrayofcss=[], $ws='')
Header function.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
static getValidAddress($address, $format, $encode=0, $maxnumberofemail=0)
Return a formatted address string for SMTP protocol.
Class to manage GeoIP conversion Usage: $geoip=new GeoIP('country',$datfile); $geoip->getCountryCodeF...
Class to manage invoices.
Class to manage predefined suppliers products.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
isACompany()
Check if third party is a company (Business) or an end user (Consumer)
Class to manage translations.
Class to manage Dolibarr users.
if(! $sortfield) if(! $sortorder) $module
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
dol_get_prev_month($month, $year)
Return previous month.
dol_get_next_day($day, $month, $year)
Return next day.
getServerTimeZoneInt($refgmtdate='now')
Return server timezone int.
dol_get_prev_day($day, $month, $year)
Return previous day.
dol_get_next_month($month, $year)
Return next month.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_is_file($pathoffile)
Return if path is a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_is_dir($folder)
Test if filename is a directory.
$date_start
Variables from include:
isValidMailDomain($mail)
Return true if email has a domain name that can be resolved to MX type.
isValidVATID($company)
Check if VAT numero is valid (check done on syntax only, no database or remote access)
dol_html_entity_decode($a, $b, $c='UTF-8', $keepsomeentities=0)
Replace html_entity_decode functions to manage errors.
dol_now($mode='gmt')
Return date for now.
dolSort($arraytosort)
Sort an array using a user defined function.
verifCond($strToEvaluate, $onlysimplestring='1')
Verify if condition in string is ok or not.
getDolGlobalLoginBadCharUnauthorized()
Return the list of unauthorized characters in user logins.
recordNotFound($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Displays an error page when a record is not found.
getDolGlobalFloat($key, $default=0)
Return a Dolibarr global constant float value.
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formatted size.
isOnlyOneLocalTax($local)
Return true if LocalTax (1 or 2) is unique.
getExecutableContent()
Return array of extension for executable files of text files that can contains executable code.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
dol_print_email($email, $contactid=0, $socid=0, $addlink=0, $max=0, $showinvalid=2, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
get_default_localtax($thirdparty_seller, $thirdparty_buyer, $local, $idprod=0)
Function that return localtax of a product line (according to seller, buyer and product vat rate) If ...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
dolCheckFilters($sqlfilters, &$error='', &$parenthesislevel=0)
Return if a $sqlfilters parameter has a valid balance of parenthesis.
dol_getmypid()
Return getmypid() or random PID when function is disabled Some web hosts disable this php function fo...
getLanguageCodeFromCountryCode($countrycode)
Return default language from country code.
setEntity($currentobject)
Set entity id to use when to create an object.
dolForgeExplodeAnd($sqlfilters)
Explode an universal search string with AND parts.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
dolExplodeIntoArray($string, $delimiter=';', $kv='=')
Split a string with 2 keys into key array.
GETPOSTDATE($prefix, $hourTime='', $gm='auto', $saverestore='')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
dol_print_ip($ip, $mode=0, $showname=0)
Return an IP formatted to be shown on screen.
dol_ucfirst($string, $encoding="UTF-8")
Convert first character of the first word of a string to upper.
dol_print_phone($phone, $countrycode='', $contactid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
dol_strtolower($string, $encoding="UTF-8")
Convert a string to lower.
dol_htmlentitiesbr_decode($stringtodecode, $pagecodeto='UTF-8')
This function is called to decode a HTML string (it decodes entities and br tags)
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.
getDolUserInt($key, $default=0, $tmpuser=null)
Return Dolibarr user constant int value.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
getObjectSocId($obj)
Get the socid of an object, supporting legacy attribute names.
getListLimitFromScreenHeight()
Get the limit of list to show according to the screen height.
isASecretKey($keyname)
Return if string has a name dedicated to store a secret.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_string_onlythesehtmlattributes($stringtoclean, $allowed_attributes=null, $ishtml=null)
Clean a string from some undesirable HTML tags.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_eval_new($s)
Replace eval function to add more security.
getCallerInfoString()
Get caller info as a string that can be appended to a log message.
roundUpToNextMultiple($n, $x=5)
Round to next multiple.
dol_user_country()
Return country code for current user.
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.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getTaxesFromId($vatrate, $buyer=null, $seller=null, $firstparamisid=1)
Get tax (VAT) main information from Id.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
utf8_valid($str)
Check if a string is in UTF8.
getDolUserString($key, $default='', $tmpuser=null)
Return Dolibarr user constant string value.
getDolOptimizeSmallScreen()
Return if render must be optimized for small screen.
isValidMXRecord($domain)
Return if the domain name has a valid MX record.
GETPOSTISARRAY($paramname, $method=0)
Return true if the parameter $paramname is submit from a POST OR GET as an array.
jsonOrUnserialize($stringtodecode, $assoc=true)
Decode an encoded string.
dol_print_socialnetworks($value, $contactid, $socid, $type, $dictsocialnetworks=array())
Show social network link.
dolChmod($filepath, $newmask='')
Change mod of a file.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
get_localtax_by_third($local)
Get values of localtaxes (1 or 2) for company country for the common vat with the highest value.
dol_escape_php($stringtoescape, $stringforquotes=2)
Returns text escaped for inclusion into a php string, build with double quotes " or '.
dolSetCookie(string $cookiename, string $cookievalue, int $expire=-1)
Set a cookie.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getElementProperties($elementType)
Get an array with properties of an element.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
dol_get_object_properties($obj, $properties=[])
Get value of properties for an object - including magic properties when requested.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_strftime($fmt, $ts=false, $is_gmt=false)
Format a string.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_string_neverthesehtmltags($stringtoclean, $disallowed_tags=array('textarea'), $cleanalsosomestyles=0)
Clean a string from some undesirable HTML tags.
isValidPhone($phone)
Return true if phone number syntax is ok TODO Decide what to do with this.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.: VAT NPR in France)
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
getBrowserInfo($user_agent)
Return information about user browser.
dolGetFirstLetters($s, $nbofchar=1)
Return first letters of a strings.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
dol_clone_in_array($srcobject, $startlevel=0)
Create a clone of instance of object into a full array, using recursive call.
dol_strtoupper($string, $encoding="UTF-8")
Convert a string to upper.
getMultidirVersion($object, $module='', $forobject=0)
Return the full path of the directory where a module (or an object of a module) stores its versioned ...
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
dol_sanitizeUrl($stringtoclean, $type=1)
Clean a string to use it as an URL (into a href or src attribute, 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.
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().
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.
div refaddress div address
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
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...
realCharForNumericEntities($matches)
Return the real char for a numeric entities.