54if (!function_exists(
'utf8_encode')) {
62 function utf8_encode($elements)
64 return mb_convert_encoding($elements,
'UTF-8',
'ISO-8859-1');
68if (!function_exists(
'utf8_decode')) {
76 function utf8_decode($elements)
78 return mb_convert_encoding($elements,
'ISO-8859-1',
'UTF-8');
81if (!function_exists(
'str_starts_with')) {
90 function str_starts_with($haystack, $needle)
92 return (
string) $needle !==
'' && strncmp($haystack, $needle, strlen($needle)) === 0;
95if (!function_exists(
'str_ends_with')) {
104 function str_ends_with($haystack, $needle)
106 return $needle !==
'' && substr($haystack, -strlen($needle)) === (string) $needle;
109if (!function_exists(
'str_contains')) {
118 function str_contains($haystack, $needle)
120 return $needle !==
'' && mb_strpos($haystack, $needle) !==
false;
140 if (!is_object(
$object) && empty($module)) {
143 if (empty($module) && !empty(
$object->element)) {
148 if ($module ==
'fichinter') {
149 $module =
'ficheinter';
150 } elseif ($module ==
'invoice_supplier') {
151 $module =
'supplier_invoice';
152 } elseif ($module ==
'order_supplier') {
153 $module =
'supplier_order';
157 if ($mode ==
'output' || $mode ==
'outputrel' || $mode ==
'version') {
158 if (isset(
$conf->$module) && property_exists(
$conf->$module,
'multidir_output')) {
160 if ($mode !=
'outputrel') {
164 if (!isset(
$conf->$module->multidir_output[$entity])) {
165 return 'error-diroutput-not-defined-for-this-entity-and-object='.$module;
167 $s =
$conf->$module->multidir_output[$entity];
169 if ($forobject &&
$object->id > 0) {
173 } elseif (isset(
$conf->$module) && property_exists(
$conf->$module,
'dir_output')) {
175 if ($mode !=
'outputrel') {
176 $s =
$conf->$module->dir_output;
178 if ($forobject &&
$object->id > 0) {
183 return 'error-diroutput-not-defined-for-this-entity-and-object='.$module;
185 } elseif ($mode ==
'temp') {
186 if (isset(
$conf->$module) && property_exists(
$conf->$module,
'multidir_temp')) {
189 if (!isset(
$conf->$module->multidir_temp[$entity])) {
190 return 'error-dirtemp-not-defined-for-this-entity-and-object='.$module;
192 return $conf->$module->multidir_temp[$entity];
193 } elseif (isset(
$conf->$module) && property_exists(
$conf->$module,
'dir_temp')) {
194 return $conf->$module->dir_temp;
196 return 'error-dirtemp-not-defined-for-this-entity-and-object='.$module;
199 return 'error-bad-value-for-mode';
243 return (
string) (isset(
$conf->global->$key) ?
$conf->global->$key : $default);
258 return (
int) (isset(
$conf->global->$key) ?
$conf->global->$key : $default);
273 return (
float) (isset(
$conf->global->$key) ?
$conf->global->$key : $default);
287 return (
bool) (
$conf->global->$key ?? $default);
301 if (empty($tmpuser)) {
306 return (
string) (isset($tmpuser->conf->$key) ? $tmpuser->conf->$key : $default);
319 if (empty($tmpuser)) {
324 return (
int) (isset($tmpuser->conf->$key) ? $tmpuser->conf->$key : $default);
341 'adherent' =>
'member',
342 'member_type' =>
'adherent_type',
344 'contrat' =>
'contract',
345 'entrepot' =>
'stock',
346 'projet' =>
'project',
347 'categorie' =>
'category',
348 'commande' =>
'order',
349 'expedition' =>
'shipping',
350 'facture' =>
'invoice',
351 'fichinter' =>
'intervention',
352 'ficheinter' =>
'intervention',
353 'propale' =>
'propal',
354 'socpeople' =>
'contact',
355 'fournisseur' =>
'supplier',
357 'actioncomm' =>
'agenda',
358 'product_price' =>
'productprice',
359 'product_fournisseur_price' =>
'productsupplierprice',
369function isModEnabled($module)
379 $arrayconv[
'supplier_order'] =
'fournisseur';
380 $arrayconv[
'supplier_invoice'] =
'fournisseur';
385 if ($module ==
'delivery_note') {
389 $module =
'shipping';
393 $module_alt = $module;
394 if (!empty($arrayconv[$module])) {
395 $module_alt = $arrayconv[$module];
397 $module_bis = $module;
398 if (!empty($arrayconvbis[$module])) {
399 $module_bis = $arrayconvbis[$module];
402 return !empty(
$conf->modules[$module]) || !empty(
$conf->modules[$module_alt]) || !empty(
$conf->modules[$module_bis]);
421 $moduletomoduletouse = array(
422 'invoice' =>
'facture',
424 $moduleParmsMapping = array(
425 'product' =>
'produit',
428 if (!empty($moduletomoduletouse[$module])) {
429 $module = $moduletomoduletouse[$module];
432 $warningDelayPath = $parmlevel1;
433 if (!empty($moduleParmsMapping[$warningDelayPath])) {
434 $warningDelayPath = $moduleParmsMapping[$warningDelayPath];
438 if (!empty(
$conf->$module->$warningDelayPath->warning_delay)) {
439 if (!empty(
$conf->$module->$warningDelayPath->$parmlevel2->warning_delay)) {
440 return (
int)
$conf->$module->$warningDelayPath->$parmlevel2->warning_delay;
444 if (!empty(
$conf->$module->$warningDelayPath->warning_delay)) {
445 return (
int)
$conf->$module->$warningDelayPath->$parmlevel1->warning_delay;
460 if ($timestamp ===
'') {
461 dol_syslog(
'Using empty string for a timestamp is deprecated, prefer use of null when calling page '.$_SERVER[
"PHP_SELF"] .
getCallerInfoString(), LOG_NOTICE);
464 if (is_null($timestamp) || !is_numeric($timestamp)) {
484 require_once DOL_DOCUMENT_ROOT.
"/core/db/".$type.
'.class.php';
486 $class =
'DoliDB'.ucfirst($type);
487 $db =
new $class($type, $host, $user, $pass, $name, $port);
508function getEntity($element, $shared = 1, $currentobject =
null)
512 if (!is_object($hookmanager)) {
513 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
520 $element =
'project';
523 $element =
'contract';
525 case 'order_supplier':
526 $element =
'supplier_order';
528 case 'invoice_supplier':
529 $element =
'supplier_invoice';
533 if (is_object($mc)) {
534 $out = $mc->getEntity($element, $shared, $currentobject);
537 $addzero = array(
'user',
'usergroup',
'cronjob',
'c_email_templates',
'email_template',
'default_values',
'overwrite_trans');
539 $addzero[] =
'c_holiday_types';
541 if (in_array($element, $addzero)) {
544 $out .= ((int)
$conf->entity);
549 'element' => $element,
552 'currentobject' => $currentobject,
556 $reshook = $hookmanager->executeHooks(
'hookGetEntity', $parameters, $currentobject, $action);
558 if (is_numeric($reshook)) {
559 if ($reshook == 0 && !empty($hookmanager->resPrint)) {
560 $out .=
','.$hookmanager->resPrint;
561 } elseif ($reshook == 1) {
562 $out = $hookmanager->resPrint;
579 if (is_object($mc) && method_exists($mc,
'setEntity')) {
580 return $mc->setEntity($currentobject);
582 return ((is_object($currentobject) && $currentobject->id > 0 && $currentobject->entity > 0) ? $currentobject->entity :
$conf->entity);
594 return preg_match(
'/(_pass|password|_pw|_key|securekey|serverkey|secret\d?|p12key|exportkey|_PW_[a-z]+|token)$/i', $keyname);
606 for ($r =
""; $n >= 0; $n = intval($n / 26) - 1) {
607 $r = chr($n % 26 + 0x41) . $r;
631 include_once DOL_DOCUMENT_ROOT.
'/includes/mobiledetect/mobiledetectlib/Mobile_Detect.php';
638 $user_agent = substr($user_agent, 0, 512);
640 $detectmobile =
new Mobile_Detect(
null, $user_agent);
641 $tablet = $detectmobile->isTablet();
643 if ($detectmobile->isMobile()) {
647 if ($detectmobile->is(
'AndroidOS')) {
648 $os = $phone =
'android';
649 } elseif ($detectmobile->is(
'BlackBerryOS')) {
650 $os = $phone =
'blackberry';
651 } elseif ($detectmobile->is(
'iOS')) {
654 } elseif ($detectmobile->is(
'PalmOS')) {
655 $os = $phone =
'palm';
656 } elseif ($detectmobile->is(
'SymbianOS')) {
658 } elseif ($detectmobile->is(
'webOS')) {
660 } elseif ($detectmobile->is(
'MaemoOS')) {
662 } elseif ($detectmobile->is(
'WindowsMobileOS') || $detectmobile->is(
'WindowsPhoneOS')) {
668 if (preg_match(
'/linux/i', $user_agent)) {
670 } elseif (preg_match(
'/macintosh/i', $user_agent)) {
672 } elseif (preg_match(
'/windows/i', $user_agent)) {
678 if (preg_match(
'/firefox(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
680 $version = empty($reg[2]) ?
'' : $reg[2];
681 } elseif (preg_match(
'/edge(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
683 $version = empty($reg[2]) ?
'' : $reg[2];
684 } elseif (preg_match(
'/chrome(\/|\s)([\d\.]+)/i', $user_agent, $reg)) {
686 $version = empty($reg[2]) ?
'' : $reg[2];
687 } elseif (preg_match(
'/chrome/i', $user_agent, $reg)) {
690 } elseif (preg_match(
'/iceweasel/i', $user_agent)) {
692 } elseif (preg_match(
'/epiphany/i', $user_agent)) {
694 } elseif (preg_match(
'/safari(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
696 $version = empty($reg[2]) ?
'' : $reg[2];
697 } elseif (preg_match(
'/opera(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
700 $version = empty($reg[2]) ?
'' : $reg[2];
701 } elseif (preg_match(
'/(MSIE\s([0-9]+\.[0-9]))|.*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) {
703 $version = end($reg);
704 } elseif (preg_match(
'/(Windows NT\s([0-9]+\.[0-9])).*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) {
707 $version = end($reg);
708 } elseif (preg_match(
'/l[iy]n(x|ks)(\(|\/|\s)*([\d\.]+)/i', $user_agent, $reg)) {
710 $name =
'textbrowser';
711 $version = empty($reg[3]) ?
'' : $reg[3];
712 } elseif (preg_match(
'/w3m\/([\d\.]+)/i', $user_agent, $reg)) {
714 $name =
'textbrowser';
715 $version = empty($reg[1]) ?
'' : $reg[1];
727 'browsername' => $name,
728 'browserversion' => $version,
730 'browserua' => $user_agent,
745 $disconnectdone =
false;
747 if (is_object($db) && !empty($db->connected)) {
748 $depth = $db->transaction_opened;
749 $disconnectdone = $db->close();
751 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));
763function GETPOSTISSET($paramname)
767 $relativepathstring = $_SERVER[
"PHP_SELF"];
769 if (constant(
'DOL_URL_ROOT')) {
770 $relativepathstring = preg_replace(
'/^'.preg_quote(constant(
'DOL_URL_ROOT'),
'/').
'/',
'', $relativepathstring);
772 $relativepathstring = ltrim($relativepathstring,
'/');
773 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
779 if (!empty($_GET[
'restore_lastsearch_values'])) {
780 if (!empty($_SESSION[
'lastsearch_values_'.$relativepathstring])) {
781 $tmp = json_decode($_SESSION[
'lastsearch_values_'.$relativepathstring],
true);
782 if (is_array($tmp)) {
783 foreach ($tmp as $key => $val) {
784 if ($key == $paramname) {
792 if ($paramname ==
'contextpage' && !empty($_SESSION[
'lastsearch_contextpage_'.$relativepathstring])) {
794 } elseif ($paramname ==
'limit' && !empty($_SESSION[
'lastsearch_limit_'.$relativepathstring])) {
796 } elseif ($paramname ==
'page' && !empty($_SESSION[
'lastsearch_page_'.$relativepathstring])) {
798 } elseif ($paramname ==
'mode' && !empty($_SESSION[
'lastsearch_mode_'.$relativepathstring])) {
802 $isset = (isset($_POST[$paramname]) || isset($_GET[$paramname]));
819 if (empty($method)) {
820 $val = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] :
'');
821 } elseif ($method == 1) {
822 $val = isset($_GET[$paramname]) ? $_GET[$paramname] :
'';
823 } elseif ($method == 2) {
824 $val = isset($_POST[$paramname]) ? $_POST[$paramname] :
'';
825 } elseif ($method == 3) {
826 $val = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] :
'');
828 $val =
'BadFirstParameterForGETPOST';
831 return is_array($val);
864function GETPOST($paramname, $check =
'alphanohtml', $method = 0, $filter =
null, $options =
null, $noreplace = 0)
866 global $mysoc, $user,
$conf;
868 if (empty($paramname)) {
869 return 'BadFirstParameterForGETPOST';
872 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);
877 if (empty($method)) {
878 $out = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] :
'');
879 } elseif ($method == 1) {
880 $out = isset($_GET[$paramname]) ? $_GET[$paramname] :
'';
881 } elseif ($method == 2) {
882 $out = isset($_POST[$paramname]) ? $_POST[$paramname] :
'';
883 } elseif ($method == 3) {
884 $out = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] :
'');
886 return 'BadThirdParameterForGETPOST';
889 $relativepathstring =
'';
891 if (empty($method) || $method == 3 || $method == 4) {
892 $relativepathstring = (empty($_SERVER[
"PHP_SELF"]) ?
'' : $_SERVER[
"PHP_SELF"]);
894 if (constant(
'DOL_URL_ROOT')) {
895 $relativepathstring = preg_replace(
'/^'.preg_quote(constant(
'DOL_URL_ROOT'),
'/').
'/',
'', $relativepathstring);
897 $relativepathstring = ltrim($relativepathstring,
'/');
898 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
904 if (!empty($_GET[
'restore_lastsearch_values'])) {
905 if (!empty($_SESSION[
'lastsearch_values_'.$relativepathstring])) {
906 $tmp = json_decode($_SESSION[
'lastsearch_values_'.$relativepathstring],
true);
907 if (is_array($tmp)) {
908 foreach ($tmp as $key => $val) {
909 if ($key == $paramname) {
917 if ($paramname ==
'contextpage' && !empty($_SESSION[
'lastsearch_contextpage_'.$relativepathstring])) {
918 $out = $_SESSION[
'lastsearch_contextpage_'.$relativepathstring];
919 } elseif ($paramname ==
'limit' && !empty($_SESSION[
'lastsearch_limit_'.$relativepathstring])) {
920 $out = $_SESSION[
'lastsearch_limit_'.$relativepathstring];
921 } elseif ($paramname ==
'page' && !empty($_SESSION[
'lastsearch_page_'.$relativepathstring])) {
922 $out = $_SESSION[
'lastsearch_page_'.$relativepathstring];
923 } elseif ($paramname ==
'mode' && !empty($_SESSION[
'lastsearch_mode_'.$relativepathstring])) {
924 $out = $_SESSION[
'lastsearch_mode_'.$relativepathstring];
926 } elseif (!isset($_GET[
'sortfield'])) {
929 if (!empty($_GET[
'action']) && $_GET[
'action'] ==
'create' && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
932 '@phan-var-force CommonObject $object';
933 if (is_object(
$object) && isset(
$object->fields[$paramname][
'default'])) {
935 $out =
$object->fields[$paramname][
'default'];
939 if (!empty($_GET[
'action']) && (preg_match(
'/^create/', $_GET[
'action']) || preg_match(
'/^presend/', $_GET[
'action'])) && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
941 if (!empty($user->default_values)) {
942 if (isset($user->default_values[$relativepathstring][
'createform'])) {
943 foreach ($user->default_values[$relativepathstring][
'createform'] as $defkey => $defval) {
945 if ($defkey !=
'_noquery_') {
946 $tmpqueryarraytohave = explode(
'&', $defkey);
949 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
950 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
963 if (isset($user->default_values[$relativepathstring][
'createform'][$defkey][$paramname])) {
964 $out = $user->default_values[$relativepathstring][
'createform'][$defkey][$paramname];
971 } elseif (!empty($paramname) && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
973 if (!empty($user->default_values)) {
976 if ($paramname ==
'sortfield' || $paramname ==
'sortorder') {
978 if (isset($user->default_values[$relativepathstring][
'sortorder'])) {
980 foreach ($user->default_values[$relativepathstring][
'sortorder'] as $defkey => $defval) {
982 if ($defkey !=
'_noquery_') {
983 $tmpqueryarraytohave = explode(
'&', $defkey);
986 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
987 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
1000 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
1001 foreach ($user->default_values[$relativepathstring][
'sortorder'][$defkey] as $key => $val) {
1005 if ($paramname ==
'sortfield') {
1008 if ($paramname ==
'sortorder') {
1016 } elseif (isset($user->default_values[$relativepathstring][
'filters'])) {
1017 foreach ($user->default_values[$relativepathstring][
'filters'] as $defkey => $defval) {
1018 if (!empty($_GET[
'disabledefaultvalues'])) {
1022 if ($defkey !=
'_noquery_') {
1023 $tmpqueryarraytohave = explode(
'&', $defkey);
1026 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
1027 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
1039 if ($qualified && isset($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname])) {
1041 if (isset($_POST[
'search_all']) || isset($_GET[
'search_all'])) {
1044 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
1045 $out =
dol_string_nospecial($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname],
'', $forbidden_chars_to_replace);
1048 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
1049 $out =
dol_string_nospecial($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname],
'', $forbidden_chars_to_replace);
1064 '@phan-var-force string $paramname';
1065 if (!is_array($out) && empty($_POST[$paramname]) && empty($noreplace)) {
1067 $regreplace = array();
1071 while (preg_match(
'/__([A-Z0-9]+(?:_[A-Z0-9]+){0,3})__/i', $out, $reg) && ($loopnb < $maxloop)) {
1075 if ($reg[1] ==
'DAY') {
1077 $newout = $tmp[
'mday'];
1078 } elseif ($reg[1] ==
'MONTH') {
1080 $newout = $tmp[
'mon'];
1081 } elseif ($reg[1] ==
'YEAR') {
1083 $newout = $tmp[
'year'];
1084 } elseif ($reg[1] ==
'PREVIOUS_DAY') {
1087 $newout = $tmp2[
'day'];
1088 } elseif ($reg[1] ==
'PREVIOUS_MONTH') {
1091 $newout = $tmp2[
'month'];
1092 } elseif ($reg[1] ==
'PREVIOUS_YEAR') {
1094 $newout = ($tmp[
'year'] - 1);
1095 } elseif ($reg[1] ==
'NEXT_DAY') {
1098 $newout = $tmp2[
'day'];
1099 } elseif ($reg[1] ==
'NEXT_MONTH') {
1102 $newout = $tmp2[
'month'];
1103 } elseif ($reg[1] ==
'NEXT_YEAR') {
1105 $newout = ($tmp[
'year'] + 1);
1106 } elseif ($reg[1] ==
'MYCOMPANY_COUNTRY_ID' || $reg[1] ==
'MYCOUNTRY_ID' || $reg[1] ==
'MYCOUNTRYID') {
1107 $newout = $mysoc->country_id;
1108 } elseif ($reg[1] ==
'USER_ID' || $reg[1] ==
'USERID') {
1109 $newout = $user->id;
1110 } elseif ($reg[1] ==
'USER_SUPERVISOR_ID' || $reg[1] ==
'SUPERVISOR_ID' || $reg[1] ==
'SUPERVISORID') {
1111 $newout = $user->fk_user;
1112 } elseif ($reg[1] ==
'ENTITY_ID' || $reg[1] ==
'ENTITYID') {
1113 $newout =
$conf->entity;
1114 } elseif ($reg[1] ==
'ID') {
1117 $newout =
'REGREPLACE_'.$loopnb;
1118 $regreplace[$loopnb] = $reg[0];
1121 $out = preg_replace(
'/__'.preg_quote($reg[1],
'/').
'__/', $newout, $out);
1123 if (!empty($regreplace)) {
1124 foreach ($regreplace as $key => $value) {
1125 $out = preg_replace(
'/REGREPLACE_'.$key.
'/', $value, $out);
1131 if (preg_match(
'/^array/', $check)) {
1132 $tmpcheck =
'alphanohtml';
1135 } elseif (!is_array($out)) {
1136 $out = explode(
',', $out);
1138 $tmparray = explode(
':', $check);
1139 if (!empty($tmparray[1])) {
1140 $tmpcheck = $tmparray[1];
1143 foreach ($out as $outkey => $outval) {
1144 $out[$outkey] =
sanitizeVal($outval, $tmpcheck, $filter, $options);
1149 if (strpos($paramname,
'search_') === 0) {
1150 $out = preg_replace(
'/([<>])([-+]?\d)/',
'\1 \2', $out);
1154 $out =
sanitizeVal($out, $check, $filter, $options);
1161 if (preg_match(
'/^backto/i', $paramname)) {
1162 $out = str_replace(
'\\',
'/', $out);
1163 $out = str_replace(array(
':',
';',
'@',
"\t",
' '),
'', $out);
1165 $oldstringtoclean = $out;
1166 $out = str_ireplace(array(
'javascript',
'vbscript',
'&colon',
'&#'),
'', $out);
1167 $out = preg_replace(array(
'/^[^\?]*%/'),
'', $out);
1168 $out = preg_replace(array(
'/^[a-z]*\/\s*\/+/i'),
'', $out);
1169 }
while ($oldstringtoclean != $out);
1174 if (empty($method) || $method == 3 || $method == 4) {
1175 if (preg_match(
'/^search_/', $paramname) || in_array($paramname, array(
'sortorder',
'sortfield'))) {
1182 if ($out !=
'' && isset($user)) {
1183 $user->lastsearch_values_tmp[$relativepathstring][$paramname] = $out;
1188 if ($paramname ==
'hashp' && $out ==
'shared') {
1206 return (
int)
GETPOST($paramname,
'int', $method,
null,
null, 0);
1238function GETPOSTDATE($prefix, $hourTime =
'', $gm =
'auto', $saverestore =
'')
1241 if ($hourTime ===
'getpost' || $hourTime ===
'getpostend') {
1242 $hour = (GETPOSTISSET($prefix .
'hour') &&
GETPOSTINT($prefix .
'hour') >= 0) ?
GETPOSTINT($prefix .
'hour') : ($hourTime ===
'getpostend' ? 23 : 0);
1243 $minute = (GETPOSTISSET($prefix .
'min') &&
GETPOSTINT($prefix .
'min') >= 0) ?
GETPOSTINT($prefix .
'min') : ($hourTime ===
'getpostend' ? 59 : 0);
1244 $second = (GETPOSTISSET($prefix .
'sec') &&
GETPOSTINT($prefix .
'sec') >= 0) ?
GETPOSTINT($prefix .
'sec') : ($hourTime ===
'getpostend' ? 59 : 0);
1245 } elseif (preg_match(
'/^(\d\d):(\d\d):(\d\d)$/', $hourTime, $m)) {
1246 $hour = intval($m[1]);
1247 $minute = intval($m[2]);
1248 $second = intval($m[3]);
1249 } elseif ($hourTime ===
'end') {
1254 $hour = $minute = $second = 0;
1259 && !GETPOSTISSET($prefix .
'day')
1260 && !GETPOSTISSET($prefix .
'month')
1261 && !GETPOSTISSET($prefix .
'year')
1262 && isset($_SESSION[
'DOLDATE_' . $saverestore .
'_day'])
1263 && isset($_SESSION[
'DOLDATE_' . $saverestore .
'_month'])
1264 && isset($_SESSION[
'DOLDATE_' . $saverestore .
'_year'])
1266 $day = $_SESSION[
'DOLDATE_'.$saverestore.
'_day'];
1267 $month = $_SESSION[
'DOLDATE_'.$saverestore.
'_month'];
1268 $year = $_SESSION[
'DOLDATE_'.$saverestore.
'_year'];
1276 $hour = (int) min($hour, 23);
1277 $minute = (int) min($minute, 59);
1278 $second = (int) min($second, 59);
1281 $_SESSION[
'DOLDATE_'.$saverestore.
'_day'] = $day;
1282 $_SESSION[
'DOLDATE_'.$saverestore.
'_month'] = $month;
1283 $_SESSION[
'DOLDATE_'.$saverestore.
'_year'] = $year;
1287 return dol_mktime($hour, $minute, $second, $month, $day, $year, $gm);
1301function checkVal($out =
'', $check =
'alphanohtml', $filter =
null, $options =
null)
1303 return sanitizeVal($out, $check, $filter, $options);
1315function sanitizeVal($out =
'', $check =
'alphanohtml', $filter =
null, $options =
null)
1319 if ($out ===
null) {
1327 if (!is_numeric($out)) {
1332 if (is_array($out)) {
1333 $out = implode(
',', $out);
1335 if (preg_match(
'/[^0-9,-]+/i', $out)) {
1340 $out = filter_var($out, FILTER_SANITIZE_STRING);
1343 $out = filter_var($out, FILTER_SANITIZE_EMAIL);
1347 $out = preg_replace(
'/[^:\/\[\]a-z0-9@\$\'\*\~\.\-_,;\?\!=%&+#]+/i',
'', $out);
1351 if (!is_array($out)) {
1353 if (preg_match(
'/[^a-z]+/i', $out)) {
1359 if (!is_array($out)) {
1361 if (preg_match(
'/[^a-z0-9_\-\.]+/i', $out)) {
1367 if (!is_array($out)) {
1369 if (preg_match(
'/[^a-z0-9_\-\.@]+/i', $out)) {
1375 if (!is_array($out)) {
1377 if (preg_match(
'/[^a-z0-9_\-\.,]+/i', $out)) {
1384 if (!is_array($out)) {
1387 $oldstringtoclean = $out;
1391 $out = preg_replace(
'/\\\([0-9xu])/',
'/\1', $out);
1398 $out = str_ireplace(array(
'../',
'..\\',
'&',
'&',
'&',
'"',
'"',
'"',
'"',
'"',
'/',
'/',
'/',
'\',
'\',
'\'),
'', $out);
1399 }
while ($oldstringtoclean != $out);
1403 case 'alphawithlgt':
1404 if (!is_array($out)) {
1407 $oldstringtoclean = $out;
1411 $out = preg_replace(
'/\\\([0-9xu])/',
'/\1', $out);
1418 $out = str_ireplace(array(
'../',
'..\\',
'&',
'&',
'&',
'"',
'"',
'"',
'"',
'"',
'/',
'/',
'/',
'\',
'\',
'\'),
'', $out);
1419 }
while ($oldstringtoclean != $out);
1425 case 'restricthtmlnolink':
1426 case 'restricthtml':
1427 case 'restricthtmlallowclass':
1428 case 'restricthtmlallowiframe':
1429 case 'restricthtmlallowlinkscript':
1430 case 'restricthtmlallowunvalid':
1435 if (empty($filter)) {
1436 return 'BadParameterForGETPOST - Param 3 of sanitizeVal()';
1438 if (is_null($options)) {
1441 $out = filter_var($out, $filter, $options);
1445 dol_syslog(
"Error, you call sanitizeVal() with a bad value for the check type. Data will be sanitized with alphanohtml.", LOG_ERR);
1446 $out =
GETPOST($out,
'alphanohtml');
1461function dolSetCookie(
string $cookiename,
string $cookievalue,
int $expire = -1)
1463 global $dolibarr_main_force_https;
1465 if ($expire == -1) {
1466 $expire = (time() + (86400 * 354));
1469 if (PHP_VERSION_ID < 70300) {
1470 setcookie($cookiename, empty($cookievalue) ?
'' : $cookievalue, empty($cookievalue) ? 0 : $expire,
'/',
'', !(empty($dolibarr_main_force_https) &&
isHTTPS() === false), true);
1473 $cookieparams = array(
1474 'expires' => empty($cookievalue) ? 0 : $expire,
1477 'secure' => !(empty($dolibarr_main_force_https) &&
isHTTPS() === false),
1481 setcookie($cookiename, empty($cookievalue) ?
'' : $cookievalue, $cookieparams);
1483 if (empty($cookievalue)) {
1484 unset($_COOKIE[$cookiename]);
1488if (!function_exists(
'dol_getprefix')) {
1499 function dol_getprefix($mode =
'')
1502 if ($mode ==
'email') {
1508 } elseif (isset($_SERVER[
"SERVER_NAME"])) {
1509 return $_SERVER[
"SERVER_NAME"];
1514 if (!empty(
$conf->file->instance_unique_id)) {
1515 return sha1(
'dolibarr'.
$conf->file->instance_unique_id);
1519 return sha1(DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
1523 global $dolibarr_main_instance_unique_id, $dolibarr_main_cookie_cryptkey;
1524 $tmp_instance_unique_id = empty($dolibarr_main_instance_unique_id) ? (empty($dolibarr_main_cookie_cryptkey) ?
'' : $dolibarr_main_cookie_cryptkey) : $dolibarr_main_instance_unique_id;
1527 if (!empty($tmp_instance_unique_id)) {
1528 return sha1(
'dolibarr'.$tmp_instance_unique_id);
1532 if (isset($_SERVER[
"SERVER_NAME"]) && isset($_SERVER[
"DOCUMENT_ROOT"])) {
1533 return sha1($_SERVER[
"SERVER_NAME"].$_SERVER[
"DOCUMENT_ROOT"].DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
1535 return sha1(DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
1552 global
$conf, $langs, $user, $mysoc;
1556 if (!file_exists($fullpath)) {
1557 dol_syslog(
'functions::dol_include_once Tried to load unexisting file: '.$relpath, LOG_WARNING);
1560 if (!empty($classname) && !class_exists($classname)) {
1561 return include $fullpath;
1563 return include_once $fullpath;
1581function dol_buildpath($path, $type = 0, $returnemptyifnotfound = 0)
1585 $path = preg_replace(
'/^\//',
'', $path);
1588 $res = DOL_DOCUMENT_ROOT.
'/'.$path;
1589 if (is_array(
$conf->file->dol_document_root)) {
1590 foreach (
$conf->file->dol_document_root as $key => $dirroot) {
1591 if ($key ==
'main') {
1595 if (@file_exists($dirroot.
'/'.$path)) {
1596 $res = $dirroot.
'/'.$path;
1601 if ($returnemptyifnotfound) {
1603 if ($returnemptyifnotfound == 1 || !file_exists($res)) {
1615 $res = DOL_URL_ROOT.
'/'.$path;
1618 $res = DOL_MAIN_URL_ROOT.
'/'.$path;
1621 $res = DOL_URL_ROOT.
'/'.$path;
1624 foreach (
$conf->file->dol_document_root as $key => $dirroot) {
1625 if ($key ==
'main') {
1630 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim(
$conf->file->dol_main_url_root));
1631 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
1634 $res = (preg_match(
'/^http/i',
$conf->file->dol_url_root[$key]) ?
'' : $urlwithroot).
'/'.$path;
1639 preg_match(
'/^([^\?]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i', $path, $regs);
1640 if (!empty($regs[1])) {
1643 if (@file_exists($dirroot.
'/'.$regs[1])) {
1645 $res = (preg_match(
'/^http/i',
$conf->file->dol_url_root[$key]) ?
'' : DOL_URL_ROOT).
$conf->file->dol_url_root[$key].
'/'.$path;
1646 } elseif ($type == 2) {
1647 $res = (preg_match(
'/^http/i',
$conf->file->dol_url_root[$key]) ?
'' : DOL_MAIN_URL_ROOT).
$conf->file->dol_url_root[$key].
'/'.$path;
1648 } elseif ($type == 3) {
1652 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim(
$conf->file->dol_main_url_root));
1653 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
1656 $res = (preg_match(
'/^http/i',
$conf->file->dol_url_root[$key]) ?
'' : $urlwithroot).
$conf->file->dol_url_root[$key].
'/'.$path;
1680 if (empty($properties)) {
1681 return get_object_vars($obj);
1684 $existingProperties = [];
1685 $realProperties = get_object_vars($obj);
1688 foreach ($properties as $property) {
1689 if (array_key_exists($property, $realProperties)) {
1691 $existingProperties[$property] = $obj->{$property};
1692 } elseif (property_exists($obj, $property)) {
1694 $existingProperties[$property] = $obj->{$property};
1698 return $existingProperties;
1727 $myclone = unserialize(serialize(
$object));
1729 if (!empty($tmpsavdb)) {
1732 } elseif ($native == 2) {
1735 $tmparray = get_object_vars(
$object);
1737 if (is_array($tmparray)) {
1738 foreach ($tmparray as $propertykey => $propertyval) {
1739 if (is_scalar($propertyval) || is_array($propertyval)) {
1740 $myclone->$propertykey = $propertyval;
1760function dol_size($size, $type =
'')
1763 if (empty(
$conf->dol_optimize_smallscreen)) {
1766 if ($type ==
'width' && $size > 250) {
1792 $filesystem_forbidden_chars = array(
'<',
'>',
'/',
'\\',
'?',
'*',
'|',
'"',
':',
'°',
'$',
';',
'`');
1793 if ($includequotes) {
1794 $filesystem_forbidden_chars[] =
"'";
1797 $tmp = preg_replace(
'/\-\-+/',
'_', $tmp);
1798 $tmp = preg_replace(
'/\s+\-([^\s])/',
' _$1', $tmp);
1799 $tmp = preg_replace(
'/\s+\-$/',
'', $tmp);
1800 $tmp = str_replace(
'..',
'', $tmp);
1801 $tmp = preg_replace(
'/\s{2,}/',
' ', $tmp);
1823 $filesystem_forbidden_chars = array(
'<',
'>',
'?',
'*',
'|',
'"',
'°',
'$',
';',
'`');
1830 $tmp = preg_replace(
'/\-\-+/',
'_', $tmp);
1831 $tmp = preg_replace(
'/\s+\-([^\s])/',
' _$1', $tmp);
1832 $tmp = preg_replace(
'/\s+\-$/',
'', $tmp);
1833 $tmp = str_replace(
'..',
'', $tmp);
1834 $tmp = preg_replace(
'/\s{2,}/',
' ', $tmp);
1850 $stringtoclean = preg_replace(
'/[\x00-\x1F\x7F]/u',
'', $stringtoclean);
1852 $stringtoclean = preg_replace(
'/<!--[^>]*-->/',
'', $stringtoclean);
1854 $stringtoclean = str_replace(
'\\',
'/', $stringtoclean);
1858 $stringtoclean = str_replace(array(
':',
';',
'@'),
'', $stringtoclean);
1862 $oldstringtoclean = $stringtoclean;
1865 $stringtoclean = str_ireplace(array(
'javascript',
'vbscript',
'&colon',
'&#'),
'', $stringtoclean);
1866 }
while ($oldstringtoclean != $stringtoclean);
1870 $stringtoclean = preg_replace(array(
'/^[a-z]*\/\/+/i'),
'', $stringtoclean);
1873 return $stringtoclean;
1885 $oldstringtoclean = $stringtoclean;
1886 $stringtoclean = str_ireplace(array(
'"',
':',
'[',
']',
"\n",
"\r",
'\\',
'\/'),
'', $stringtoclean);
1887 }
while ($oldstringtoclean != $stringtoclean);
1889 return $stringtoclean;
1902 return preg_replace(
'/[^\w]+/',
'', $str);
1916 if (is_null($str)) {
1921 if (extension_loaded(
'intl') &&
getDolGlobalString(
'MAIN_UNACCENT_USE_TRANSLITERATOR')) {
1922 $transliterator = Transliterator::createFromRules(
':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: NFC;', Transliterator::FORWARD);
1923 return $transliterator->transliterate($str);
1926 $string = rawurlencode($str);
1927 $replacements = array(
1928 '%C3%80' =>
'A',
'%C3%81' =>
'A',
'%C3%82' =>
'A',
'%C3%83' =>
'A',
'%C3%84' =>
'A',
'%C3%85' =>
'A',
1930 '%C3%88' =>
'E',
'%C3%89' =>
'E',
'%C3%8A' =>
'E',
'%C3%8B' =>
'E',
1931 '%C3%8C' =>
'I',
'%C3%8D' =>
'I',
'%C3%8E' =>
'I',
'%C3%8F' =>
'I',
1933 '%C3%92' =>
'O',
'%C3%93' =>
'O',
'%C3%94' =>
'O',
'%C3%95' =>
'O',
'%C3%96' =>
'O',
'%C5%90' =>
'O',
1935 '%C3%99' =>
'U',
'%C3%9A' =>
'U',
'%C3%9B' =>
'U',
'%C3%9C' =>
'U',
'%C5%B0' =>
'U',
1936 '%C3%9D' =>
'Y',
'%C5%B8' =>
'y',
1937 '%C3%A0' =>
'a',
'%C3%A1' =>
'a',
'%C3%A2' =>
'a',
'%C3%A3' =>
'a',
'%C3%A4' =>
'a',
'%C3%A5' =>
'a',
1939 '%C3%A8' =>
'e',
'%C3%A9' =>
'e',
'%C3%AA' =>
'e',
'%C3%AB' =>
'e',
1940 '%C3%AC' =>
'i',
'%C3%AD' =>
'i',
'%C3%AE' =>
'i',
'%C3%AF' =>
'i',
1942 '%C3%B2' =>
'o',
'%C3%B3' =>
'o',
'%C3%B4' =>
'o',
'%C3%B5' =>
'o',
'%C3%B6' =>
'o',
'%C5%91' =>
'o',
1944 '%C3%B9' =>
'u',
'%C3%BA' =>
'u',
'%C3%BB' =>
'u',
'%C3%BC' =>
'u',
'%C5%B1' =>
'u',
1945 '%C3%BD' =>
'y',
'%C3%BF' =>
'y'
1947 $string = strtr($string, $replacements);
1948 return rawurldecode($string);
1953 "\xC0\xC1\xC2\xC3\xC4\xC5\xC7
1954 \xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1
1955 \xD2\xD3\xD4\xD5\xD8\xD9\xDA\xDB\xDD
1956 \xE0\xE1\xE2\xE3\xE4\xE5\xE7\xE8\xE9\xEA\xEB
1957 \xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF8
1958 \xF9\xFA\xFB\xFC\xFD\xFF",
1966 $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"));
1984function dol_string_nospecial($str, $newstr =
'_', $badcharstoreplace =
'', $badcharstoremove =
'', $keepspaces = 0)
1986 $forbidden_chars_to_replace = array(
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
",",
";",
"=",
'°',
'$',
';');
1987 if (empty($keepspaces)) {
1988 $forbidden_chars_to_replace[] =
" ";
1990 $forbidden_chars_to_remove = array();
1993 if (is_array($badcharstoreplace)) {
1994 $forbidden_chars_to_replace = $badcharstoreplace;
1996 if (is_array($badcharstoremove)) {
1997 $forbidden_chars_to_remove = $badcharstoremove;
2001 return str_replace($forbidden_chars_to_replace, $newstr, str_replace($forbidden_chars_to_remove,
"", $str));
2020 if ($removetabcrlf) {
2021 return preg_replace(
'/[\x00-\x1F\x7F]/u',
'', $str);
2023 return preg_replace(
'/[\x00-\x08\x11-\x12\x14-\x1F\x7F]/u',
'', $str);
2038 if (function_exists(
'iconv')) {
2039 $slug = iconv(
'UTF-8',
'ASCII//TRANSLIT//IGNORE', $slug);
2043 $slug = strtolower($slug);
2046 $slug = preg_replace(
'/[^a-z0-9]+/',
'-', $slug);
2049 $slug = trim($slug,
'-');
2062function dol_escape_js($stringtoescape, $mode = 0, $noescapebackslashn = 0)
2064 if (is_null($stringtoescape)) {
2069 $substitjs = array(
"'" =>
"\\'",
"\r" =>
'\\r');
2071 if (empty($noescapebackslashn)) {
2072 $substitjs[
"\n"] =
'\\n';
2073 $substitjs[
'\\'] =
'\\\\';
2076 $substitjs[
"'"] =
"\\'";
2077 $substitjs[
'"'] =
"\\'";
2078 } elseif ($mode == 1) {
2079 $substitjs[
"'"] =
"\\'";
2080 } elseif ($mode == 2) {
2081 $substitjs[
'"'] =
'\\"';
2082 } elseif ($mode == 3) {
2083 $substitjs[
"'"] =
"\\'";
2084 $substitjs[
'"'] =
"\\\"";
2086 return strtr((
string) $stringtoescape, $substitjs);
2100 return rawurlencode($stringtoescape);
2111 return str_replace(
'"',
'\"', $stringtoescape);
2123 if (is_null($stringtoescape)) {
2127 if ($stringforquotes == 2) {
2128 return str_replace(
'"',
"'", $stringtoescape);
2129 } elseif ($stringforquotes == 1) {
2135 $stringtoescape = str_replace(
'\\',
'', $stringtoescape);
2136 return str_replace(
"'",
"\'", str_replace(
'"',
"'", $stringtoescape));
2139 return 'Bad parameter for stringforquotes in dol_escape_php';
2150 return preg_replace(
'/[^a-z0-9_]/i',
'', $stringtoescape);
2161 return $stringtoescape;
2225 $allowedtags = array(
'br',
'b',
'font',
'hr',
'span');
2226 if (!empty($allowothertags) && is_array($allowothertags)) {
2227 $allowedtags = array_merge($allowedtags, $allowothertags);
2231 if ($escapeonlyhtmltags) {
2232 return dol_escape_htmltag(
dol_string_onlythesehtmltags($s, 1, 0, 0, 0, $allowedtags), 1, -1,
'', 1, 1);
2234 return dol_escape_htmltag(
dol_string_onlythesehtmltags(
dol_htmlentitiesbr($s), 1, 0, 0, 0, $allowedtags), 1, -1,
'', 0, 1);
2250 $escapeonlyhtmltags = 1;
2251 return dol_escape_htmltag(
dol_string_onlythesehtmltags($s, 1, 1, 1, 0, array()), 0, 0,
'', $escapeonlyhtmltags, 1);
2276 return htmlspecialchars($s, ENT_HTML5,
'UTF-8');
2296function dol_escape_htmltag($stringtoescape, $keepb = 0, $keepn = 0, $noescapetags =
'', $escapeonlyhtmltags = 0, $cleanalsojavascript = 0)
2298 if ($noescapetags ==
'common') {
2299 $noescapetags =
'html,body,a,b,em,hr,i,u,ul,ol,li,br,div,img,font,p,span,strong,table,tr,td,th,tbody,h1,h2,h3,h4,h5,h6,h7,h8,h9';
2301 $noescapetags .=
',header,footer,nav,section,menu,menuitem';
2303 if ($cleanalsojavascript) {
2308 if ($escapeonlyhtmltags) {
2309 $tmp = htmlspecialchars_decode((
string) $stringtoescape, ENT_COMPAT);
2316 $tmp = (string) $stringtoescape;
2319 $tmp = str_ireplace(
'<',
'__DONOTDECODELT', $tmp);
2320 $tmp = str_ireplace(
'>',
'__DONOTDECODEGT', $tmp);
2321 $tmp = str_ireplace(
'&',
'__DONOTDECODEAMP', $tmp);
2322 $tmp = str_ireplace(
'"',
'__DONOTDECODEQUOT', $tmp);
2323 $tmp = str_ireplace(
'&apos',
'__DONOTDECODEAPOS', $tmp);
2324 $tmp = str_ireplace(
''',
'__DONOTDECODE39', $tmp);
2326 $tmp = html_entity_decode((
string) $tmp, ENT_COMPAT,
'UTF-8');
2329 $tmp = str_ireplace(
'__DONOTDECODELT',
'<', $tmp);
2330 $tmp = str_ireplace(
'__DONOTDECODEGT',
'>', $tmp);
2331 $tmp = str_ireplace(
'__DONOTDECODEAMP',
'&', $tmp);
2332 $tmp = str_ireplace(
'__DONOTDECODEQUOT',
'"', $tmp);
2333 $tmp = str_ireplace(
'__DONOTDECODEAPOS',
'&apos', $tmp);
2334 $tmp = str_ireplace(
'__DONOTDECODE39',
''', $tmp);
2336 $tmp = str_ireplace(
''',
'__SIMPLEQUOTE__', $tmp);
2339 $tmp = strtr($tmp, array(
"<b>" =>
'',
'</b>' =>
'',
'<strong>' =>
'',
'</strong>' =>
''));
2342 $tmp = strtr($tmp, array(
"\r" =>
'\\r',
"\n" =>
'\\n'));
2343 } elseif ($keepn == -1) {
2344 $tmp = strtr($tmp, array(
"\r" =>
'',
"\n" =>
''));
2347 if ($escapeonlyhtmltags) {
2348 $tmp = htmlspecialchars($tmp, ENT_COMPAT,
'UTF-8');
2352 $tmparrayoftags = array();
2353 if ($noescapetags) {
2354 $tmparrayoftags = explode(
',', $noescapetags);
2357 if (count($tmparrayoftags)) {
2362 $tmp = str_ireplace(array(
'__DOUBLEQUOTE',
'__BEGINTAGTOREPLACE',
'__ENDTAGTOREPLACE',
'__BEGINENDTAGTOREPLACE'),
'', $tmp);
2364 foreach ($tmparrayoftags as $tagtoreplace) {
2366 $tmp = preg_replace(
'/<'.preg_quote($tagtoreplace,
'/').
'>/',
'__BEGINTAGTOREPLACE'.$tagtoreplace.
'__', $tmp);
2367 $tmp = str_ireplace(
'</'.$tagtoreplace.
'>',
'__ENDTAGTOREPLACE'.$tagtoreplace.
'__', $tmp);
2368 $tmp = preg_replace(
'/<'.preg_quote($tagtoreplace,
'/').
' \/>/',
'__BEGINENDTAGTOREPLACE'.$tagtoreplace.
'__', $tmp);
2374 if (preg_match(
'/<'.preg_quote($tagtoreplace,
'/').
'(\s+)([^>]+)>/', $tmp, $reg)) {
2376 $tmpattributes = str_ireplace(array(
'[',
']'),
'_', $reg[2]);
2377 $tmpattributes = str_ireplace(
'"',
'__DOUBLEQUOTE__', $tmpattributes);
2378 $tmpattributes = preg_replace(
'/[^a-z0-9_%,\/\?\;\s=&\.\-@:\.#\+]/i',
'', $tmpattributes);
2380 $tmp = str_replace(
'<'.$tagtoreplace.$reg[1].$reg[2].
'>',
'__BEGINTAGTOREPLACE'.$tagtoreplace.
'['.$tmpattributes.
']__', $tmp);
2383 $diff = strcmp($tmpold, $tmp);
2387 $tmp = str_ireplace(
'&',
'__ANDNOSEMICOLON__', $tmp);
2388 $tmp = str_ireplace(
'"',
'__DOUBLEQUOTENOSEMICOLON__', $tmp);
2389 $tmp = str_ireplace(
'<',
'__LESSTHAN__', $tmp);
2390 $tmp = str_ireplace(
'>',
'__GREATERTHAN__', $tmp);
2394 $result = htmlentities($tmp, ENT_COMPAT,
'UTF-8');
2398 if (count($tmparrayoftags)) {
2400 foreach ($tmparrayoftags as $tagtoreplace) {
2401 $result = str_ireplace(
'__BEGINTAGTOREPLACE'.$tagtoreplace.
'__',
'<'.$tagtoreplace.
'>', $result);
2402 $result = preg_replace(
'/__BEGINTAGTOREPLACE'.$tagtoreplace.
'\[([^\]]*)\]__/',
'<'.$tagtoreplace.
' \1>', $result);
2403 $result = str_ireplace(
'__ENDTAGTOREPLACE'.$tagtoreplace.
'__',
'</'.$tagtoreplace.
'>', $result);
2404 $result = str_ireplace(
'__BEGINENDTAGTOREPLACE'.$tagtoreplace.
'__',
'<'.$tagtoreplace.
' />', $result);
2405 $result = preg_replace(
'/__BEGINENDTAGTOREPLACE'.$tagtoreplace.
'\[([^\]]*)\]__/',
'<'.$tagtoreplace.
' \1 />', $result);
2408 $result = str_ireplace(
'__DOUBLEQUOTE__',
'"', $result);
2410 $result = str_ireplace(
'__ANDNOSEMICOLON__',
'&', $result);
2411 $result = str_ireplace(
'__DOUBLEQUOTENOSEMICOLON__',
'"', $result);
2412 $result = str_ireplace(
'__LESSTHAN__',
'<', $result);
2413 $result = str_ireplace(
'__GREATERTHAN__',
'>', $result);
2416 $result = str_ireplace(
'__SIMPLEQUOTE__',
''', $result);
2433 if (function_exists(
'mb_strtolower')) {
2434 return mb_strtolower($string, $encoding);
2436 return strtolower($string);
2450 if (function_exists(
'mb_strtoupper')) {
2451 return mb_strtoupper($string, $encoding);
2453 return strtoupper($string);
2467 if (function_exists(
'mb_substr')) {
2468 return mb_strtoupper(mb_substr($string, 0, 1, $encoding), $encoding).mb_substr($string, 1,
null, $encoding);
2470 return ucfirst($string);
2484 if (function_exists(
'mb_convert_case')) {
2485 return mb_convert_case($string, MB_CASE_TITLE, $encoding);
2487 return ucwords($string);
2499 $backtrace = debug_backtrace();
2501 if (count($backtrace) >= 1) {
2503 if (count($backtrace) == 1) {
2506 $trace = $backtrace[$pos];
2507 if (isset($trace[
'file'], $trace[
'line'])) {
2508 $msg =
" From {$trace['file']}:{$trace['line']}.";
2536function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename =
'', $restricttologhandler =
'', $logcontext =
null)
2538 global
$conf, $user, $debugbar;
2541 if (!isModEnabled(
'syslog')) {
2546 if (defined(
'USEEXTERNALSERVER') && !defined(
'USEDOLIBARRSERVER') && !defined(
'USEDOLIBARREDITOR')) {
2547 global $website, $websitekey;
2548 if (is_object($website) && !empty($website->ref)) {
2549 $suffixinfilename .=
'_website_'.$website->ref;
2550 } elseif (!empty($websitekey)) {
2551 $suffixinfilename .=
'_website_'.$websitekey;
2556 if (defined(
'USESUFFIXINLOG')) {
2557 $suffixinfilename .= constant(
'USESUFFIXINLOG');
2561 foreach (
$conf->loghandlers as $loghandlerinstance) {
2562 $loghandlerinstance->setIdent($ident);
2566 if (!empty($message)) {
2569 $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');
2571 if (!array_key_exists($level, $logLevels)) {
2572 dol_syslog(
'Error Bad Log Level '.$level, LOG_ERR);
2580 $message = preg_replace(
'/password=\'[^\']*\'/',
'password=\'hidden\'', $message);
2584 if ((!empty($_REQUEST[
'logtohtml']) &&
getDolGlobalString(
'MAIN_ENABLE_LOG_TO_HTML'))
2585 || (is_object($user) && $user->hasRight(
'debugbar',
'read') && is_object($debugbar))) {
2586 $ospid = sprintf(
"%7s",
dol_trunc((
string) getmypid(), 7,
'right',
'UTF-8', 1));
2587 $osuser =
" ".sprintf(
"%6s",
dol_trunc(function_exists(
'posix_getuid') ? posix_getuid() :
'', 6,
'right',
'UTF-8', 1));
2589 $conf->logbuffer[] =
dol_print_date(time(),
"%Y-%m-%d %H:%M:%S").
" ".sprintf(
"%-7s", $logLevels[$level]).
" ".$ospid.
" ".$osuser.
" ".$message;
2595 print
"\n\n<!-- Log start\n";
2597 print
"Log end -->\n";
2601 'message' => $message,
2602 'script' => (isset($_SERVER[
'PHP_SELF']) ? basename($_SERVER[
'PHP_SELF'],
'.php') :
''),
2604 'user' => ((is_object($user) && $user->id) ? $user->login :
''),
2606 'osuser' => function_exists(
'posix_getuid') ? (string) posix_getuid() :
'',
2607 'ospid' => (string) getmypid()
2612 if (!empty($remoteip)) {
2613 $data[
'ip'] = $remoteip;
2617 if (!empty($_SERVER[
'HTTP_X_FORWARDED_FOR'])) {
2618 $tmpips = explode(
',', $_SERVER[
'HTTP_X_FORWARDED_FOR']);
2622 foreach ($tmpips as $tmpip) {
2623 $tmpip = trim($tmpip);
2624 if (strtolower($tmpip) == strtolower($remoteip)) {
2627 if (empty($data[
'ip'])) {
2628 $data[
'ip'] = $tmpip;
2631 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',').$tmpip;
2634 if (!$foundremoteip) {
2636 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',').$remoteip;
2638 $data[
'ip'] .= (($j > 0) ?
']' :
'');
2639 } elseif (!empty($_SERVER[
'HTTP_CLIENT_IP'])) {
2640 $tmpips = explode(
',', $_SERVER[
'HTTP_CLIENT_IP']);
2644 foreach ($tmpips as $tmpip) {
2645 $tmpip = trim($tmpip);
2646 if (strtolower($tmpip) == strtolower($remoteip)) {
2649 if (empty($data[
'ip'])) {
2650 $data[
'ip'] = $tmpip;
2653 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',').$tmpip;
2656 if (!$foundremoteip) {
2658 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',').$remoteip;
2660 $data[
'ip'] .= (($j > 0) ?
']' :
'');
2662 } elseif (!empty($_SERVER[
'SERVER_ADDR'])) {
2664 $data[
'ip'] = (string) $_SERVER[
'SERVER_ADDR'];
2665 } elseif (!empty($_SERVER[
'COMPUTERNAME'])) {
2667 $data[
'ip'] = (string) $_SERVER[
'COMPUTERNAME'];
2669 $data[
'ip'] =
'???';
2672 if (!empty($_SERVER[
'USERNAME'])) {
2674 $data[
'osuser'] = (string) $_SERVER[
'USERNAME'];
2675 } elseif (!empty($_SERVER[
'LOGNAME'])) {
2677 $data[
'osuser'] = (string) $_SERVER[
'LOGNAME'];
2681 foreach (
$conf->loghandlers as $loghandlerinstance) {
2682 if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler) {
2685 $loghandlerinstance->export($data, $suffixinfilename);
2691 foreach (
$conf->loghandlers as $loghandlerinstance) {
2692 $loghandlerinstance->setIdent($ident);
2712 $form =
new Form($db);
2714 $templatenameforexport = $website->name_template;
2715 if (empty($templatenameforexport)) {
2716 $templatenameforexport =
'website_'.$website->ref;
2720 $out .=
'<input type="button" class="cursorpointer button bordertransp" id="open-dialog-' . $name .
'" value="'.dol_escape_htmltag($buttonstring).
'"/>';
2723 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">';
2724 $out .=
'jQuery(document).ready(function () {';
2725 $out .=
' jQuery("#open-dialog-' . $name .
'").click(function () {';
2726 $out .=
' var dialogHtml = \'';
2728 $dialogcontent =
' <div id="custom-dialog-' . $name .
'">';
2729 $dialogcontent .=
' <div style="margin-top: 20px;">';
2730 $dialogcontent .=
' <label for="export-site-' . $name .
'"><strong>'.$langs->trans(
"ExportSiteLabel").
'...</label><br>';
2731 $dialogcontent .=
' <button class="button smallpaddingimp" id="export-site-' . $name .
'">' .
dol_escape_htmltag($langs->trans(
"DownloadZip")) .
'</button>';
2732 $dialogcontent .=
' </div>';
2733 $dialogcontent .=
' <br>';
2734 $dialogcontent .=
' <div style="margin-top: 20px;">';
2735 $dialogcontent .=
' <strong>'.$langs->trans(
"ExportSiteGitLabel").
' '.$form->textwithpicto(
'', $langs->trans(
"SourceFiles"), 1,
'help',
'', 0, 3,
'').
'</strong><br>';
2736 $dialogcontent .=
' <form action="'.dol_escape_htmltag($overwriteGitUrl).
'" method="POST">';
2737 $dialogcontent .=
' <input type="hidden" name="action" value="overwritesite">';
2738 $dialogcontent .=
' <input type="hidden" name="token" value="'.newToken().
'">';
2739 $dialogcontent .=
' <input type="text" autofocus name="export_path" id="export-path-'.$name.
'" placeholder="'.$langs->trans(
'ExportPath').
'" style="width:400px " value="'.
dol_escape_htmltag($templatenameforexport).
'"/><br>';
2740 $dialogcontent .=
' <button type="submit" class="button smallpaddingimp" id="overwrite-git-' . $name .
'">' .
dol_escape_htmltag($langs->trans(
"ExportIntoGIT")) .
'</button>';
2741 $dialogcontent .=
' </form>';
2742 $dialogcontent .=
' </div>';
2743 $dialogcontent .=
' </div>';
2750 // Add the content of the dialog to the body of the page
2751 $out .= ' var $dialog = jQuery(
"#custom-dialog-' . $name . '");
';
2752 $out .= ' if ($dialog.length > 0) {
2755 jQuery(
"body").append(dialogHtml);
';
2757 // Configuration of popup
2758 $out .= ' jQuery(
"#custom-dialog-' . $name . '").dialog({
';
2759 $out .= ' autoOpen:
false,
';
2760 $out .= ' modal:
true,
';
2761 $out .= ' height: 290,
';
2762 $out .= ' width:
"40%",
';
2763 $out .= ' title:
"' . dol_escape_js($label) . '",
';
2766 // Simulate a click on the original "submit" input to export the site.
2767 $out .= ' jQuery(
"#export-site-' . $name . '").click(
function () {
';
2768 $out .= ' console.log(
"Clic on exportsite.");
';
2769 $out .= ' var target = jQuery(
"input[name=\'' . dol_escape_js($exportSiteName) . '\']");
';
2770 $out .= ' console.log(
"element founded:", target.length > 0);
';
2771 $out .= ' if (target.length > 0) { target.click(); }
';
2772 $out .= ' jQuery(
"#custom-dialog-' . $name . '").dialog(
"close");
';
2776 $out .= ' jQuery(
"#custom-dialog-' . $name . '").dialog(
"open");
';
2777 $out .= ' return false;
';
2780 $out .= '</script>
';
2802function dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled = '
', $morecss = 'classlink
button bordertransp
', $jsonopen = '', $jsonclose = '', $accesskey = '')
2806 if (strpos($url, '?
') > 0) {
2807 $url .= '&dol_hide_topmenu=1&dol_hide_leftmenu=1&dol_openinpopup=
'.urlencode($name);
2809 $url .= '?dol_hide_topmenu=1&dol_hide_leftmenu=1&dol_openinpopup=
'.urlencode($name);
2814 //print '<input
type=
"submit" class=
"button bordertransp"'.$disabled.' value=
"'.dol_escape_htmltag($langs->trans("MediaFiles
")).'" name=
"file_manager">
';
2815 $out .= '<!-- a link
for button to open url into a dialog popup -->
';
2816 $out .= '<a
'.($accesskey ? ' accesskey=
"'.$accesskey.'"' : '').' class=
"cursorpointer reposition button_'.$name.($morecss ? ' '.$morecss : '').'"'.$disabled.' title=
"'.dol_escape_htmltag($label).'"';
2817 if (empty($conf->use_javascript_ajax)) {
2818 $out .= ' href=
"'.DOL_URL_ROOT.$url.'" target=
"_blank"';
2819 } elseif ($jsonopen) {
2820 $out .= ' href=
"#" onclick=
"'.$jsonopen.'"';
2822 $out .= ' href=
"#"';
2824 $out .= '>
'.$buttonstring.'</a>
';
2826 if (!empty($conf->use_javascript_ajax)) {
2827 // Add code to open url using the popup.
2828 $out .= '<!-- code to open popup and variables to retrieve returned variables -->
';
2829 $out .= '<div
id=
"idfordialog'.$name.'" class=
"hidden">
'.(getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER
') < 2 ? 'div
for dialog
' : '').'</div>
';
2831 $out .= '<!-- Add js code to open dialog popup on dialog -->
';
2832 $out .= '<script nonce=
"'.getNonce().'" type=
"text/javascript">
2833 jQuery(document).ready(
function () {
2834 jQuery(
".button_'.$name.'").click(
function () {
2835 console.log(\
'Open popup with jQuery(...).dialog() on URL '.
dol_escape_js(DOL_URL_ROOT.$url).
'\');
2836 var $tmpdialog = $(\
'#idfordialog'.$name.
'\');
2837 $tmpdialog.html(\
'<iframe class="iframedialog" id="iframedialog'.$name.
'" style="border: 0px;" src="'.DOL_URL_ROOT.$url.
'" width="100%" height="98%"></iframe>\');
2841 height: (window.innerHeight - 150),
2844 open: function (event, ui) {
2845 console.log(
"open popup name='.$name.'");
2847 close:
function (event, ui) {
2848 console.log(
"Popup is closed, run jsonclose = '.$jsonclose.'");
2849 '.(empty($jsonclose) ? '' : $jsonclose.';
').'
2853 $tmpdialog.dialog(\
'open\');
2878function dol_fiche_head($links = array(), $active =
'0', $title =
'', $notab = 0, $picto =
'', $pictoisfullpath = 0, $morehtmlright =
'', $morecss =
'', $limittoshow = 0, $moretabssuffix =
'')
2880 print
dol_get_fiche_head($links, $active, $title, $notab, $picto, $pictoisfullpath, $morehtmlright, $morecss, $limittoshow, $moretabssuffix);
2900function dol_get_fiche_head($links = array(), $active =
'', $title =
'', $notab = 0, $picto =
'', $pictoisfullpath = 0, $morehtmlright =
'', $morecss =
'', $limittoshow = 0, $moretabssuffix =
'', $dragdropfile = 0, $morecssdiv =
'')
2902 global
$conf, $langs, $hookmanager;
2906 if (!empty(
$conf->dol_optimize_smallscreen)) {
2910 $out =
"\n".
'<!-- dol_fiche_head - dol_get_fiche_head -->';
2912 if ((!empty($title) && $showtitle) || $morehtmlright || !empty($links)) {
2913 $out .=
'<div class="tabs'.($picto ?
'' :
' nopaddingleft').
'" data-role="controlgroup" data-type="horizontal">'.
"\n";
2917 if ($morehtmlright) {
2918 $out .=
'<div class="inline-block floatright tabsElem">'.$morehtmlright.
'</div>';
2925 if (is_array($links) && !empty($links)) {
2926 $keys = array_keys($links);
2928 $maxkey = max($keys);
2934 if (empty($limittoshow)) {
2937 if (!empty(
$conf->dol_optimize_smallscreen)) {
2945 for ($i = 0; $i <= $maxkey; $i++) {
2946 if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2])) {
2948 if ($i >= $limittoshow) {
2954 for ($i = 0; $i <= $maxkey; $i++) {
2955 if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2])) {
2961 if ($i < $limittoshow || $isactive) {
2963 $out .=
'<div class="inline-block tabsElem'.($isactive ?
' tabsElemActive' :
'').((!$isactive &&
getDolGlobalString(
'MAIN_HIDE_INACTIVETAB_ON_PRINT')) ?
' hideonprint' :
'').
'"><!-- id tab = '.(empty($links[$i][2]) ?
'' :
dol_escape_htmltag($links[$i][2])).
' -->';
2965 if (isset($links[$i][2]) && $links[$i][2] ==
'image') {
2966 if (!empty($links[$i][0])) {
2967 $out .=
'<a class="tabimage'.($morecss ?
' '.$morecss :
'').
'" href="'.$links[$i][0].
'">'.$links[$i][1].
'</a>'.
"\n";
2969 $out .=
'<span class="tabspan">'.$links[$i][1].
'</span>'.
"\n";
2971 } elseif (!empty($links[$i][1])) {
2973 $out .=
'<div class="tab tab'.($isactive ?
'active' :
'unactive').
'" style="margin: 0 !important">';
2975 if (!empty($links[$i][0])) {
2976 $titletoshow = preg_replace(
'/<.*$/',
'', $links[$i][1]);
2977 $out .=
'<a'.(!empty($links[$i][2]) ?
' id="'.$links[$i][2].
'"' :
'').
' class="tab inline-block valignmiddle'.($morecss ?
' '.$morecss :
'').(!empty($links[$i][5]) ?
' '.$links[$i][5] :
'').
'" href="'.$links[$i][0].
'" title="'.
dol_escape_htmltag($titletoshow).
'">';
2980 if ($displaytab == 0 && $picto) {
2981 $out .=
img_picto($title, $picto,
'', $pictoisfullpath, 0, 0,
'',
'imgTabTitle paddingright marginrightonlyshort');
2984 $out .= $links[$i][1];
2985 if (!empty($links[$i][0])) {
2986 $out .=
'</a>'.
"\n";
2988 $out .= empty($links[$i][4]) ?
'' : $links[$i][4];
2997 $outmore .=
'<div class="popuptabset wordwrap">';
2999 $outmore_content =
'';
3001 if (isset($links[$i][2]) && $links[$i][2] ==
'image') {
3002 if (!empty($links[$i][0])) {
3003 $outmore_content .=
'<a class="tabimage'.($morecss ?
' '.$morecss :
'').
'" href="'.$links[$i][0].
'">'.$links[$i][1].
'</a>'.
"\n";
3005 $outmore_content .=
'<span class="tabspan">'.$links[$i][1].
'</span>'.
"\n";
3007 } elseif (!empty($links[$i][1])) {
3008 $outmore_content .=
'<a'.(!empty($links[$i][2]) ?
' id="'.$links[$i][2].
'"' :
'').
' class="wordwrap inline-block'.($morecss ?
' '.$morecss :
'').
'" href="'.$links[$i][0].
'">';
3009 $outmore_content .= preg_replace(
'/([a-z])\|([a-z])/i',
'\\1 | \\2', $links[$i][1]);
3010 $outmore_content .=
'</a>'.
"\n";
3012 if ($outmore_content !==
'') {
3013 $outmore .=
'<div class="popuptab wordwrap" style="display:inherit;">' . $outmore_content .
'</div>';
3019 $displaytab = $i + 1;
3022 $outmore .=
'</div>';
3026 $left = ($langs->trans(
"DIRECTION") ==
'rtl' ?
'right' :
'left');
3027 $right = ($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right');
3028 $widthofpopup = 240;
3030 $tabsname = $moretabssuffix;
3031 if (empty($tabsname)) {
3032 $tabsname = str_replace(
"@",
"", $picto);
3034 $out .=
'<div id="moretabs'.$tabsname.
'" class="inline-block tabsElem valignmiddle">';
3036 $out .=
'<div class="tab valignmiddle"><a href="#" class="tab moretab inline-block tabunactive valignmiddle"><span class="hideonsmartphone">'.$langs->trans(
"More").
'</span>... ('.$nbintab.
')</a></div>';
3038 $out .=
'<div id="moretabsList'.$tabsname.
'" style="width: '.$widthofpopup.
'px; position: absolute; '.$left.
': -999em; text-align: '.$left.
'; margin:0px; padding:2px; z-index:10;">';
3041 $out .=
'<div></div>';
3044 $out .=
'<script nonce="'.getNonce().
'">';
3045 $out .=
"$('#moretabs".$tabsname.
"').mouseenter( function() {
3046 var x = this.offsetLeft, y = this.offsetTop;
3047 console.log('mouseenter ".$left.
" x='+x+' y='+y+' window.innerWidth='+window.innerWidth);
3048 if ((window.innerWidth - x) < ".($widthofpopup + 10).
") {
3049 $('#moretabsList".$tabsname.
"').css('".$right.
"','8px');
3051 $('#moretabsList".$tabsname.
"').css('".$left.
"','auto');
3054 $out .=
"$('#moretabs".$tabsname.
"').mouseleave( function() { console.log('mouseleave ".$left.
"'); $('#moretabsList".$tabsname.
"').css('".$left.
"','-999em');});";
3055 $out .=
"</script>";
3058 if ((!empty($title) && $showtitle) || $morehtmlright || !empty($links)) {
3062 if (!$notab || $notab == -1 || $notab == -2 || $notab == -3 || $notab == -4) {
3063 $out .=
"\n".
'<div id="dragDropAreaTabBar" class="tabBar'.($notab == -1 ?
'' : ($notab == -2 ?
' tabBarNoTop' : ((($notab == -3 || $notab == -4) ?
' noborderbottom' :
'').($notab == -4 ?
'' :
' tabBarWithBottom'))));
3064 $out .= ($morecssdiv ?
' '.$morecssdiv :
'');
3067 if (!empty($dragdropfile)) {
3068 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
3071 $parameters = array(
'tabname' => $active,
'out' => $out);
3072 $reshook = $hookmanager->executeHooks(
'printTabsHead', $parameters);
3074 $out = $hookmanager->resPrint;
3100 if (!$notab || $notab == -1) {
3101 return "\n</div>\n";
3126function dol_banner_tab(
$object, $paramid, $morehtml =
'', $shownav = 1, $fieldid =
'rowid', $fieldref =
'ref', $morehtmlref =
'', $moreparam =
'', $nodbprefix = 0, $morehtmlleft =
'', $morehtmlstatus =
'', $onlybanner = 0, $morehtmlright =
'')
3128 global
$conf, $form, $user, $langs, $hookmanager, $action;
3132 $maxvisiblephotos = 1;
3136 $showbarcode = !isModEnabled(
'barcode') ? 0 : (empty(
$object->barcode) ? 0 : 1);
3137 if (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'barcode',
'lire_advance')) {
3140 $modulepart =
'unknown';
3142 if (in_array(
$object->element, [
'societe',
'contact',
'product',
'ticket',
'bom'])) {
3143 $modulepart =
$object->element;
3144 } elseif (
$object->element ==
'member') {
3145 $modulepart =
'memberphoto';
3146 } elseif (
$object->element ==
'user') {
3147 $modulepart =
'userphoto';
3150 if (class_exists(
"Imagick")) {
3151 if (
$object->element ==
'expensereport' ||
$object->element ==
'propal' ||
$object->element ==
'commande' ||
$object->element ==
'facture' ||
$object->element ==
'supplier_proposal') {
3152 $modulepart =
$object->element;
3153 } elseif (
$object->element ==
'fichinter' ||
$object->element ==
'intervention') {
3154 $modulepart =
'ficheinter';
3155 } elseif (
$object->element ==
'contrat' ||
$object->element ==
'contract') {
3156 $modulepart =
'contract';
3157 } elseif (
$object->element ==
'order_supplier') {
3158 $modulepart =
'supplier_order';
3159 } elseif (
$object->element ==
'invoice_supplier') {
3160 $modulepart =
'supplier_invoice';
3164 if (
$object->element ==
'product') {
3166 '@phan-var-force Product $object';
3168 $cssclass =
'photowithmargin photoref';
3169 $showimage =
$object->is_photo_available(
$conf->product->multidir_output[$entity]);
3171 if (
$conf->browser->layout ==
'phone') {
3172 $maxvisiblephotos = 1;
3175 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">'.$object->show_photos(
'product',
$conf->product->multidir_output[$entity], 1, $maxvisiblephotos, 0, 0, 0, 0, $width, 0,
'').
'</div>';
3179 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
3181 $nophoto =
'/public/theme/common/nophoto.png';
3182 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"><img class="photo'.$modulepart.($cssclass ?
' '.$cssclass :
'').
'" title="'.
dol_escape_htmltag($langs->trans(
"UploadAnImageToSeeAPhotoHere", $langs->transnoentitiesnoconv(
"Documents"))).
'" alt="No photo"'.($width ?
' style="width: '.$width.
'px"' :
'').
' src="'.DOL_URL_ROOT.$nophoto.
'"></div>';
3185 } elseif (
$object->element ==
'category') {
3187 '@phan-var-force Categorie $object';
3189 $cssclass =
'photowithmargin photoref';
3190 $showimage =
$object->isAnyPhotoAvailable(
$conf->categorie->multidir_output[$entity]);
3192 if (
$conf->browser->layout ==
'phone') {
3193 $maxvisiblephotos = 1;
3196 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">'.$object->show_photos(
'category',
$conf->categorie->multidir_output[$entity],
'small', $maxvisiblephotos, 0, 0, 0, 0, $width, 0,
'').
'</div>';
3200 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
3202 $nophoto =
'/public/theme/common/nophoto.png';
3203 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"><img class="photo'.$modulepart.($cssclass ?
' '.$cssclass :
'').
'" title="'.
dol_escape_htmltag($langs->trans(
"UploadAnImageToSeeAPhotoHere", $langs->transnoentitiesnoconv(
"Documents"))).
'" alt="No photo"'.($width ?
' style="width: '.$width.
'px"' :
'').
' src="'.DOL_URL_ROOT.$nophoto.
'"></div>';
3206 } elseif (
$object->element ==
'bom') {
3208 '@phan-var-force Bom $object';
3210 $cssclass =
'photowithmargin photoref';
3211 $showimage =
$object->is_photo_available(
$conf->bom->multidir_output[$entity]);
3213 if (
$conf->browser->layout ==
'phone') {
3214 $maxvisiblephotos = 1;
3217 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">'.$object->show_photos(
'bom',
$conf->bom->multidir_output[$entity],
'small', $maxvisiblephotos, 0, 0, 0, 0, $width, 0,
'').
'</div>';
3221 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
3223 $nophoto =
'/public/theme/common/nophoto.png';
3224 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"><img class="photo'.$modulepart.($cssclass ?
' '.$cssclass :
'').
'" title="'.
dol_escape_htmltag($langs->trans(
"UploadAnImageToSeeAPhotoHere", $langs->transnoentitiesnoconv(
"Documents"))).
'" alt="No photo"'.($width ?
' style="width: '.$width.
'px"' :
'').
' src="'.DOL_URL_ROOT.$nophoto.
'"></div>';
3227 } elseif (
$object->element ==
'ticket') {
3229 $cssclass =
'photoref';
3231 '@phan-var-force Ticket $object';
3232 $showimage =
$object->is_photo_available(
$conf->ticket->multidir_output[$entity].
'/'.
$object->ref);
3234 if (
$conf->browser->layout ==
'phone') {
3235 $maxvisiblephotos = 1;
3239 $showphoto =
$object->show_photos(
'ticket',
$conf->ticket->multidir_output[$entity],
'small', $maxvisiblephotos, 0, 0, 0, $width, 0);
3241 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">'.$showphoto.
'</div>';
3249 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
3251 $nophoto =
img_picto(
'No photo',
'object_ticket');
3252 $morehtmlleft .=
'<!-- No photo to show -->';
3253 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
3254 $morehtmlleft .= $nophoto;
3255 $morehtmlleft .=
'</div></div>';
3260 if ($modulepart !=
'unknown' || method_exists(
$object,
'getDataToShowPhoto')) {
3263 if (in_array($modulepart, array(
'propal',
'commande',
'facture',
'ficheinter',
'contract',
'supplier_order',
'supplier_proposal',
'supplier_invoice',
'expensereport')) && class_exists(
"Imagick")) {
3265 $dir_output = (empty(
$conf->$modulepart->multidir_output[$entity]) ?
$conf->$modulepart->dir_output :
$conf->$modulepart->multidir_output[$entity]).
"/";
3266 if (in_array($modulepart, array(
'invoice_supplier',
'supplier_invoice'))) {
3268 $subdir .= ((!empty($subdir) && !preg_match(
'/\/$/', $subdir)) ?
'/' :
'').$objectref;
3272 if (empty($subdir)) {
3273 $subdir =
'errorgettingsubdirofobject';
3276 $filepath = $dir_output.$subdir.
"/";
3278 $filepdf = $filepath.$objectref.
".pdf";
3279 $relativepath = $subdir.
'/'.$objectref.
'.pdf';
3282 $fileimage = $filepdf.
'_preview.png';
3283 $relativepathimage = $relativepath.
'_preview.png';
3285 $pdfexists = file_exists($filepdf);
3290 if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) {
3292 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
3301 if ($pdfexists && !$error) {
3302 $heightforphotref = 80;
3303 if (!empty(
$conf->dol_optimize_smallscreen)) {
3304 $heightforphotref = 60;
3307 if (file_exists($fileimage)) {
3308 $phototoshow =
'<div class="photoref">';
3309 $phototoshow .=
'<img height="'.$heightforphotref.
'" class="photo photowithborder" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart=apercu'.$modulepart.
'&file='.urlencode($relativepathimage).
'">';
3310 $phototoshow .=
'</div>';
3313 } elseif (!$phototoshow) {
3314 $phototoshow .= $form->showphoto($modulepart,
$object, 0, 0, 0,
'photowithmargin photoref',
'small', 1, 0);
3318 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">';
3319 $morehtmlleft .= $phototoshow;
3320 $morehtmlleft .=
'</div>';
3324 if (empty($phototoshow)) {
3325 if (
$object->element ==
'action') {
3327 $cssclass =
'photorefcenter';
3328 $nophoto =
img_picto(
'No photo',
'title_agenda');
3331 $cssclass =
'photorefcenter';
3333 $prefix =
'object_';
3337 if (strpos($picto,
'fontawesome_') !==
false) {
3340 $nophoto =
img_picto(
'No photo', $prefix.$picto);
3342 $morehtmlleft .=
'<!-- No photo to show -->';
3343 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
3344 $morehtmlleft .= $nophoto;
3345 $morehtmlleft .=
'</div></div>';
3352 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">'.$form->showbarcode(
$object, 100,
'photoref valignmiddle').
'</div>';
3355 if (
$object->element ==
'societe') {
3356 if (!empty(
$conf->use_javascript_ajax) && $user->hasRight(
'societe',
'creer') &&
getDolGlobalString(
'MAIN_DIRECT_STATUS_UPDATE')) {
3359 $morehtmlstatus .=
$object->getLibStatut(6);
3361 } elseif (
$object->element ==
'product') {
3363 if (!empty(
$conf->use_javascript_ajax) && $user->hasRight(
'produit',
'creer') &&
getDolGlobalString(
'MAIN_DIRECT_STATUS_UPDATE')) {
3364 $morehtmlstatus .=
ajax_object_onoff(
$object,
'status',
'tosell',
'ProductStatusOnSell',
'ProductStatusNotOnSell');
3366 $morehtmlstatus .=
'<span class="statusrefsell">'.$object->getLibStatut(6, 0).
'</span>';
3368 $morehtmlstatus .=
' ';
3370 if (!empty(
$conf->use_javascript_ajax) && $user->hasRight(
'produit',
'creer') &&
getDolGlobalString(
'MAIN_DIRECT_STATUS_UPDATE')) {
3371 $morehtmlstatus .=
ajax_object_onoff(
$object,
'status_buy',
'tobuy',
'ProductStatusOnBuy',
'ProductStatusNotOnBuy');
3373 $morehtmlstatus .=
'<span class="statusrefbuy">'.$object->getLibStatut(6, 1).
'</span>';
3375 } elseif (in_array(
$object->element, array(
'salary'))) {
3376 '@phan-var-force Salary $object';
3378 if (empty($tmptxt) || $tmptxt ==
$object->getLibStatut(3)) {
3381 $morehtmlstatus .= $tmptxt;
3382 } elseif (in_array(
$object->element, array(
'facture',
'invoice',
'invoice_supplier'))) {
3383 '@phan-var-force Facture|FactureFournisseur|CommonInvoice $object';
3384 $totalallpayments =
$object->getSommePaiement(0);
3385 $totalallpayments +=
$object->getSumCreditNotesUsed(0);
3386 $totalallpayments +=
$object->getSumDepositsUsed(0);
3387 $tmptxt =
$object->getLibStatut(6, $totalallpayments);
3388 if (empty($tmptxt) || $tmptxt ==
$object->getLibStatut(3)) {
3389 $tmptxt =
$object->getLibStatut(5, $totalallpayments);
3391 $morehtmlstatus .= $tmptxt;
3392 } elseif (in_array(
$object->element, array(
'chargesociales',
'loan',
'tva'))) {
3393 '@phan-var-force ChargeSociales|Loan|Tva $object';
3395 if (empty($tmptxt) || $tmptxt ==
$object->getLibStatut(3)) {
3398 $morehtmlstatus .= $tmptxt;
3399 } elseif (
$object->element ==
'contrat' ||
$object->element ==
'contract') {
3401 $morehtmlstatus .=
$object->getLibStatut(5);
3403 $morehtmlstatus .=
$object->getLibStatut(4);
3405 } elseif (
$object->element ==
'facturerec') {
3406 '@phan-var-force FactureRec $object';
3407 if (
$object->frequency == 0) {
3408 $morehtmlstatus .=
$object->getLibStatut(2);
3410 $morehtmlstatus .=
$object->getLibStatut(5);
3412 } elseif (
$object->element ==
'project_task') {
3413 $tmptxt =
$object->getLibStatut(4);
3414 $morehtmlstatus .= $tmptxt;
3415 } elseif (method_exists(
$object,
'getLibStatut')) {
3416 $tmptxt =
$object->getLibStatut(6);
3417 if (empty($tmptxt) || $tmptxt ==
$object->getLibStatut(3)) {
3418 $tmptxt =
$object->getLibStatut(5);
3420 $morehtmlstatus .= $tmptxt;
3424 if (isModEnabled(
'accounting') && in_array(
$object->element, array(
'bank',
'paiementcharge',
'facture',
'invoice',
'invoice_supplier',
'expensereport',
'payment_various'))) {
3426 if (method_exists(
$object,
'getVentilExportCompta')) {
3427 $accounted =
$object->getVentilExportCompta(1);
3428 $langs->load(
"accountancy");
3429 $morehtmlstatus .=
'</div><div class="statusref statusrefbis"><span class="opacitymedium">'.($accounted > 0 ?
'<a href="'.DOL_URL_ROOT.
'/accountancy/bookkeeping/list.php?search_mvt_num='.((int) $accounted).
'">'.$langs->trans(
"Accounted").
'</a>' : $langs->trans(
"NotYetAccounted")).
'</span>';
3434 if (!empty(
$object->name_alias)) {
3435 '@phan-var-force Societe $object';
3436 $morehtmlref .=
'<div class="refidno opacitymedium">'.dol_escape_htmltag(
$object->name_alias).
'</div>';
3440 if (in_array(
$object->element, array(
'product',
'bank_account',
'project_task'))) {
3442 $morehtmlref .=
'<div class="refidno opacitymedium">'.$object->label.
'</div>';
3446 if (method_exists(
$object,
'getBannerAddress') && !in_array(
$object->element, array(
'product',
'bookmark',
'ecm_directories',
'ecm_files'))) {
3449 $morehtmlref .=
'<div class="refidno refaddress">';
3450 $morehtmlref .= $moreaddress;
3451 $morehtmlref .=
'</div>';
3455 $morehtmlref .=
'<div style="clear: both;"></div>';
3456 $morehtmlref .=
'<div class="refidno opacitymedium">';
3457 $morehtmlref .= $langs->trans(
"TechnicalID").
': '.((int)
$object->id);
3458 $morehtmlref .=
'</div>';
3461 $parameters = array(
'morehtmlref' => &$morehtmlref,
'moreparam' => &$moreparam,
'morehtmlleft' => &$morehtmlleft,
'morehtmlstatus' => &$morehtmlstatus,
'morehtmlright' => &$morehtmlright);
3462 $reshook = $hookmanager->executeHooks(
'formDolBanner', $parameters,
$object, $action);
3465 } elseif (empty($reshook)) {
3466 $morehtmlref .= $hookmanager->resPrint;
3467 } elseif ($reshook > 0) {
3468 $morehtmlref = $hookmanager->resPrint;
3476 print
'<div class="'.($onlybanner ?
'arearefnobottom ' :
'arearef ').
'heightref valignmiddle centpercent">';
3477 print $form->showrefnav(
$object, $paramid, $morehtml, $shownav, $fieldid, $fieldref, $morehtmlref, $moreparam, $nodbprefix, $morehtmlleft, $morehtmlstatus, $morehtmlright);
3479 print
'<div class="underrefbanner clearboth"></div>';
3491function fieldLabel($langkey, $fieldkey, $fieldrequired = 0)
3495 if ($fieldrequired) {
3496 $ret .=
'<span class="fieldrequired">';
3498 $ret .=
'<label for="'.$fieldkey.
'">';
3499 $ret .= $langs->trans($langkey);
3501 if ($fieldrequired) {
3522 global $langs, $hookmanager;
3525 $countriesusingstate = array(
'AU',
'CA',
'US',
'IN',
'GB',
'ES',
'UK',
'TR',
'CN');
3530 $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)));
3533 if (isset(
$object->country_code) && in_array(
$object->country_code, array(
'AU',
'CA',
'US',
'CN')) ||
getDolGlobalString(
'MAIN_FORCE_STATE_INTO_ADDRESS')) {
3535 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3536 $ret .= (($ret && $town) ? $sep :
'').$town;
3539 $ret .= ($ret ? ($town ?
", " : $sep) :
'').
$object->state;
3542 $ret .= ($ret ? (($town ||
$object->state) ?
", " : $sep) :
'').
$object->zip;
3544 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'GB',
'UK'))) {
3546 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3547 $ret .= ($ret ? $sep :
'').$town;
3549 $ret .= ($ret ?
", " :
'').
$object->state;
3552 $ret .= ($ret ? $sep :
'').
$object->zip;
3554 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'ES',
'TR'))) {
3556 $ret .= ($ret ? $sep :
'').
$object->zip;
3557 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3558 $ret .= ($town ? ((
$object->zip ?
' ' :
'').$town) :
'');
3560 $ret .= $sep.$object->state;
3562 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'JP'))) {
3565 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3567 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'IT'))) {
3569 $ret .= ($ret ? $sep :
'').
$object->zip;
3570 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3571 $ret .= ($town ? ((
$object->zip ?
' ' :
'').$town) :
'');
3572 $ret .= (empty(
$object->state_code) ?
'' : (
' '.$object->state_code));
3575 $town = (($extralangcode && !empty(
$object->array_languages[
'address'][$extralangcode])) ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3576 $ret .= !empty(
$object->zip) ? (($ret ? $sep :
'').
$object->zip) :
'';
3577 $ret .= ($town ? ((
$object->zip ?
' ' : ($ret ? $sep :
'')).$town) :
'');
3578 if (!empty(
$object->state) && in_array(
$object->country_code, $countriesusingstate)) {
3579 $ret .= ($ret ?
", " :
'').
$object->state;
3583 if (!is_object($outputlangs)) {
3584 $outputlangs = $langs;
3587 $langs->load(
"dict");
3588 $ret .= (empty(
$object->country_code) ?
'' : ($ret ? $sep :
'').$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv(
"Country".$object->country_code)));
3591 $parameters = array(
'withcountry' => $withcountry,
'sep' => $sep,
'outputlangs' => $outputlangs,
'mode' => $mode,
'extralangcode' => $extralangcode);
3592 $reshook = $hookmanager->executeHooks(
'formatAddress', $parameters,
$object);
3596 $ret .= $hookmanager->resPrint;
3613function dol_strftime($fmt, $ts =
false, $is_gmt =
false)
3615 if ((abs($ts) <= 0x7FFFFFFF)) {
3618 return 'Error date outside supported range';
3643function dol_print_date($time, $format =
'', $tzoutput =
'auto', $outputlangs =
null, $encodetooutput =
false)
3645 global
$conf, $langs;
3652 if ($tzoutput ===
'auto') {
3653 $tzoutput = (empty(
$conf) ?
'tzserver' : (isset(
$conf->tzuserinputkey) ?
$conf->tzuserinputkey :
'tzserver'));
3658 $offsettz = $offsetdst = 0;
3661 if (is_string($tzoutput)) {
3662 if ($tzoutput ==
'tzserver') {
3664 $offsettzstring = @date_default_timezone_get();
3669 } elseif ($tzoutput ==
'tzuser' || $tzoutput ==
'tzuserrel') {
3671 $offsettzstring = (empty($_SESSION[
'dol_tz_string']) ?
'UTC' : $_SESSION[
'dol_tz_string']);
3673 if (class_exists(
'DateTimeZone')) {
3674 $user_date_tz =
new DateTimeZone($offsettzstring);
3675 $user_dt =
new DateTime();
3676 $user_dt->setTimezone($user_date_tz);
3677 $user_dt->setTimestamp($tzoutput ==
'tzuser' ?
dol_now() : (int) $time);
3678 $offsettz = $user_dt->getOffset();
3680 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
3681 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
3686 if (!is_object($outputlangs)) {
3687 $outputlangs = $langs;
3690 $format =
'daytextshort';
3695 $reduceformat = (!empty(
$conf->dol_optimize_smallscreen) && in_array($format, array(
'day',
'dayhour',
'dayhoursec'))) ? 1 : 0;
3696 $format = preg_replace(
'/inputnoreduce/',
'', $format);
3697 $formatwithoutreduce = preg_replace(
'/reduceformat/',
'', $format);
3698 if ($formatwithoutreduce != $format) {
3699 $format = $formatwithoutreduce;
3705 if ($format ==
'day') {
3706 $format = ($outputlangs->trans(
"FormatDateShort") !=
"FormatDateShort" ? $outputlangs->trans(
"FormatDateShort") :
$conf->format_date_short);
3707 } elseif ($format ==
'hour') {
3708 $format = ($outputlangs->trans(
"FormatHourShort") !=
"FormatHourShort" ? $outputlangs->trans(
"FormatHourShort") :
$conf->format_hour_short);
3709 } elseif ($format ==
'hourduration') {
3710 $format = ($outputlangs->trans(
"FormatHourShortDuration") !=
"FormatHourShortDuration" ? $outputlangs->trans(
"FormatHourShortDuration") :
$conf->format_hour_short_duration);
3711 } elseif ($format ==
'daytext') {
3712 $format = ($outputlangs->trans(
"FormatDateText") !=
"FormatDateText" ? $outputlangs->trans(
"FormatDateText") :
$conf->format_date_text);
3713 } elseif ($format ==
'daytextshort') {
3714 $format = ($outputlangs->trans(
"FormatDateTextShort") !=
"FormatDateTextShort" ? $outputlangs->trans(
"FormatDateTextShort") :
$conf->format_date_text_short);
3715 } elseif ($format ==
'dayhour') {
3716 $format = ($outputlangs->trans(
"FormatDateHourShort") !=
"FormatDateHourShort" ? $outputlangs->trans(
"FormatDateHourShort") :
$conf->format_date_hour_short);
3717 } elseif ($format ==
'dayhoursec') {
3718 $format = ($outputlangs->trans(
"FormatDateHourSecShort") !=
"FormatDateHourSecShort" ? $outputlangs->trans(
"FormatDateHourSecShort") :
$conf->format_date_hour_sec_short);
3719 } elseif ($format ==
'dayhourtext') {
3720 $format = ($outputlangs->trans(
"FormatDateHourText") !=
"FormatDateHourText" ? $outputlangs->trans(
"FormatDateHourText") :
$conf->format_date_hour_text);
3721 } elseif ($format ==
'dayhourtextshort') {
3722 $format = ($outputlangs->trans(
"FormatDateHourTextShort") !=
"FormatDateHourTextShort" ? $outputlangs->trans(
"FormatDateHourTextShort") :
$conf->format_date_hour_text_short);
3723 } elseif ($format ==
'dayhourlog') {
3725 $format =
'%Y%m%d%H%M%S';
3726 } elseif ($format ==
'dayhourlogsmall') {
3728 $format =
'%y%m%d%H%M';
3729 } elseif ($format ==
'dayhourldap') {
3730 $format =
'%Y%m%d%H%M%SZ';
3731 } elseif ($format ==
'dayhourxcard') {
3732 $format =
'%Y%m%dT%H%M%SZ';
3733 } elseif ($format ==
'dayxcard') {
3735 } elseif ($format ==
'dayrfc') {
3736 $format =
'%Y-%m-%d';
3737 } elseif ($format ==
'dayhourrfc') {
3738 $format =
'%Y-%m-%dT%H:%M:%SZ';
3739 } elseif ($format ==
'standard') {
3740 $format =
'%Y-%m-%d %H:%M:%S';
3743 if ($reduceformat) {
3744 $format = str_replace(
'%Y',
'%y', $format);
3745 $format = str_replace(
'yyyy',
'yy', $format);
3749 if (preg_match(
'/%b/i', $format)) {
3751 $format = str_replace(
'%b',
'__b__', $format);
3752 $format = str_replace(
'%B',
'__B__', $format);
3754 if (preg_match(
'/%a/i', $format)) {
3756 $format = str_replace(
'%a',
'__a__', $format);
3757 $format = str_replace(
'%A',
'__A__', $format);
3762 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)) {
3763 dol_print_error(
null,
"Functions.lib::dol_print_date function called with a bad value from page ".(empty($_SERVER[
"PHP_SELF"]) ?
'unknown' : $_SERVER[
"PHP_SELF"]));
3765 } elseif (preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', (
string) $time, $reg)) {
3767 dol_syslog(
"Functions.lib::dol_print_date function called with a bad value from page ".(empty($_SERVER[
"PHP_SELF"]) ?
'unknown' : $_SERVER[
"PHP_SELF"]), LOG_WARNING);
3770 $syear = (!empty($reg[1]) ? $reg[1] :
'');
3771 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
3772 $sday = (!empty($reg[3]) ? $reg[3] :
'');
3773 $shour = (!empty($reg[4]) ? $reg[4] :
'');
3774 $smin = (!empty($reg[5]) ? $reg[5] :
'');
3775 $ssec = (!empty($reg[6]) ? $reg[6] :
'');
3777 $time =
dol_mktime((
int) $shour, (
int) $smin, (
int) $ssec, (
int) $smonth, (
int) $sday, (
int) $syear,
true);
3780 $tzo =
new DateTimeZone(
'UTC');
3782 $tzo =
new DateTimeZone(date_default_timezone_get());
3784 $dtts =
new DateTime();
3785 $dtts->setTimestamp($time);
3786 $dtts->setTimezone($tzo);
3787 $newformat = str_replace(
3788 array(
'%Y',
'%y',
'%m',
'%d',
'%H',
'%I',
'%M',
'%S',
'%p',
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
3789 array(
'Y',
'y',
'm',
'd',
'H',
'h',
'i',
's',
'A',
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
3792 $ret = $dtts->format($newformat);
3794 array(
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
3795 array(
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
3800 if ($time < 100000000000) {
3801 $timetouse = $time + $offsettz + $offsetdst;
3804 $tzo =
new DateTimeZone(
'UTC');
3806 $tzo =
new DateTimeZone(date_default_timezone_get());
3808 $dtts =
new DateTime();
3809 $dtts->setTimestamp($timetouse);
3810 $dtts->setTimezone($tzo);
3811 $newformat = str_replace(
3812 array(
'%Y',
'%y',
'%m',
'%d',
'%H',
'%I',
'%M',
'%S',
'%p',
'%w',
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
3813 array(
'Y',
'y',
'm',
'd',
'H',
'h',
'i',
's',
'A',
'w',
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
3816 $ret = $dtts->format($newformat);
3818 array(
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
3819 array(
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
3824 $ret =
'Bad value '.$time.
' for date';
3828 if (preg_match(
'/__b__/i', $format)) {
3829 $timetouse = $time + $offsettz + $offsetdst;
3832 $tzo =
new DateTimeZone(
'UTC');
3834 $tzo =
new DateTimeZone(date_default_timezone_get());
3836 $dtts =
new DateTime();
3837 $dtts->setTimestamp($timetouse);
3838 $dtts->setTimezone($tzo);
3839 $month = (int) $dtts->format(
"m");
3840 $month = sprintf(
"%02d", $month);
3841 if ($encodetooutput) {
3842 $monthtext = $outputlangs->transnoentities(
'Month'.$month);
3843 $monthtextshort = $outputlangs->transnoentities(
'MonthShort'.$month);
3845 $monthtext = $outputlangs->transnoentitiesnoconv(
'Month'.$month);
3846 $monthtextshort = $outputlangs->transnoentitiesnoconv(
'MonthShort'.$month);
3849 $ret = str_replace(
'__b__', $monthtextshort, $ret);
3850 $ret = str_replace(
'__B__', $monthtext, $ret);
3854 if (preg_match(
'/__a__/i', $format)) {
3856 $timetouse = $time + $offsettz + $offsetdst;
3859 $tzo =
new DateTimeZone(
'UTC');
3861 $tzo =
new DateTimeZone(date_default_timezone_get());
3863 $dtts =
new DateTime();
3864 $dtts->setTimestamp($timetouse);
3865 $dtts->setTimezone($tzo);
3866 $w = $dtts->format(
"w");
3867 $dayweek = $outputlangs->transnoentitiesnoconv(
'Day'.$w);
3869 $ret = str_replace(
'__A__', $dayweek, $ret);
3870 $ret = str_replace(
'__a__',
dol_substr($dayweek, 0, 3), $ret);
3897function dol_getdate($timestamp, $fast =
false, $forcetimezone =
'')
3899 if ($timestamp ===
'') {
3903 $datetimeobj =
new DateTime();
3904 $datetimeobj->setTimestamp($timestamp);
3905 if ($forcetimezone) {
3906 $datetimeobj->setTimezone(
new DateTimeZone($forcetimezone ==
'gmt' ?
'UTC' : $forcetimezone));
3909 'year' => ((
int) date_format($datetimeobj,
'Y')),
3910 'mon' => ((
int) date_format($datetimeobj,
'm')),
3911 'mday' => ((
int) date_format($datetimeobj,
'd')),
3912 'wday' => ((
int) date_format($datetimeobj,
'w')),
3913 'yday' => ((
int) date_format($datetimeobj,
'z')),
3914 'hours' => ((
int) date_format($datetimeobj,
'H')),
3915 'minutes' => ((
int) date_format($datetimeobj,
'i')),
3916 'seconds' => ((
int) date_format($datetimeobj,
's')),
3944function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm =
'auto', $check = 1)
3949 if ($gm ===
'auto') {
3950 $gm = (empty(
$conf) ?
'tzserver' :
$conf->tzuserinputkey);
3955 if ($hour == -1 || empty($hour)) {
3958 if ($minute == -1 || empty($minute)) {
3961 if ($second == -1 || empty($second)) {
3967 if (!$month || !$day) {
3976 if ($hour < 0 || $hour > 24) {
3979 if ($minute < 0 || $minute > 60) {
3982 if ($second < 0 || $second > 60) {
3987 if (empty($gm) || ($gm ===
'server' || $gm ===
'tzserver')) {
3988 $default_timezone = @date_default_timezone_get();
3989 $localtz =
new DateTimeZone($default_timezone);
3990 } elseif ($gm ===
'user' || $gm ===
'tzuser' || $gm ===
'tzuserrel') {
3992 $default_timezone = (empty($_SESSION[
"dol_tz_string"]) ? @date_default_timezone_get() : $_SESSION[
"dol_tz_string"]);
3994 $localtz =
new DateTimeZone($default_timezone);
3996 dol_syslog(
"Warning dol_tz_string contains an invalid value ".json_encode($_SESSION[
"dol_tz_string"] ??
null), LOG_WARNING);
3997 $default_timezone = @date_default_timezone_get();
3999 } elseif (strrpos($gm,
"tz,") !==
false) {
4000 $timezone = str_replace(
"tz,",
"", $gm);
4002 $localtz =
new DateTimeZone($timezone);
4004 dol_syslog(
"Warning passed timezone contains an invalid value ".$timezone, LOG_WARNING);
4008 if (empty($localtz)) {
4009 $localtz =
new DateTimeZone(
'UTC');
4013 $dt =
new DateTime(
'now', $localtz);
4014 $dt->setDate((
int) $year, (
int) $month, (
int) $day);
4015 $dt->setTime((
int) $hour, (
int) $minute, (
int) $second);
4016 $date = $dt->getTimestamp();
4032function dol_now($mode =
'auto')
4036 if ($mode ===
'auto') {
4040 if ($mode ==
'gmt') {
4042 } elseif ($mode ==
'tzserver') {
4043 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
4045 $ret = (int) (
dol_now(
'gmt') + ($tzsecond * 3600));
4051 } elseif ($mode ==
'tzuser' || $mode ==
'tzuserrel') {
4054 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
4055 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
4056 $ret = (int) (
dol_now(
'gmt') + ($offsettz + $offsetdst));
4073 global
$conf, $langs;
4076 if (!empty(
$conf->dol_optimize_smallscreen)) {
4081 if (empty($shortvalue) || $size < ($level * 10)) {
4083 $textunitshort = $langs->trans(
"b");
4084 $textunitlong = $langs->trans(
"Bytes");
4086 $ret = round($size / $level, 0);
4087 $textunitshort = $langs->trans(
"Kb");
4088 $textunitlong = $langs->trans(
"KiloBytes");
4091 if (empty($shortunit)) {
4092 $ret .=
' '.$textunitlong;
4094 $ret .=
' '.$textunitshort;
4110function dol_print_url($url, $target =
'_blank', $max = 32, $withpicto = 0, $morecss =
'')
4118 $linkstart =
'<a href="';
4119 if (!preg_match(
'/^http/i', $url)) {
4120 $linkstart .=
'http://';
4125 $linkstart .=
' target="'.$target.
'"';
4127 $linkstart .=
' title="'.$langs->trans(
"URL").
': '.$url.
'"';
4131 if (!preg_match(
'/^http/i', $url)) {
4138 if ($morecss ==
'float') {
4139 return '<div class="nospan'.($morecss ?
' '.$morecss :
'').
'" style="margin-right: 10px">'.($withpicto ?
img_picto($langs->trans(
"Url"),
'globe',
'class="paddingrightonly"') :
'').$link.
'</div>';
4141 return $linkstart.
'<span class="nospan'.($morecss ?
' '.$morecss :
'').
'" style="margin-right: 10px">'.($withpicto ?
img_picto(
'',
'globe',
'class="paddingrightonly"') :
'').$link.
'</span>'.$linkend;
4158function dol_print_email($email, $cid = 0, $socid = 0, $addlink = 0, $max = 64, $showinvalid = 1, $withpicto = 0, $morecss =
'paddingrightonly')
4160 global $user, $langs, $hookmanager;
4171 if (empty($email)) {
4175 if ($addlink == 1) {
4176 $newemail =
'<a class="'.($morecss ? $morecss :
'').
'" style="text-overflow: ellipsis;" href="';
4177 if (!preg_match(
'/^mailto:/i', $email)) {
4178 $newemail .=
'mailto:';
4180 $newemail .= $email;
4181 $newemail .=
'" target="_blank">';
4183 $newemail .= ($withpicto ?
img_picto($langs->trans(
"EMail").
' : '.$email, (is_numeric($withpicto) ?
'email' : $withpicto),
'class="paddingrightonly"') :
'');
4188 $newemail .= $email;
4190 $newemail .=
'</a>';
4192 $langs->load(
"errors");
4193 $newemail .=
img_warning($langs->trans(
"ErrorBadEMail", $email),
'',
'paddingrightonly');
4196 if (($cid || $socid) && isModEnabled(
'agenda') && $user->hasRight(
"agenda",
"myactions",
"create")) {
4198 $linktoaddaction =
'';
4200 $linktoaddaction =
'<a href="'.DOL_URL_ROOT.
'/comm/action/card.php?action=create&backtopage=1&actioncode='.urlencode($type).
'&contactid='.((int) $cid).
'&socid='.((int) $socid).
'">'.
img_object($langs->trans(
"AddAction"),
"calendar").
'</a>';
4202 if ($linktoaddaction) {
4203 $newemail =
'<div>'.$newemail.
' '.$linktoaddaction.
'</div>';
4206 } elseif ($addlink ===
'thirdparty') {
4207 $tmpnewemail =
'<a class="'.($morecss ? $morecss :
'').
'" style="text-overflow: ellipsis;" href="'.DOL_URL_ROOT.
'/societe/card.php?socid='.$socid.
'&action=presend&mode=init#formmailbeforetitle">';
4208 $tmpnewemail .= ($withpicto ?
img_picto($langs->trans(
"EMail").
' : '.$email, (is_numeric($withpicto) ?
'email' : $withpicto),
'class="paddingrightonly"') :
'');
4209 if ($withpicto == 1) {
4210 $tmpnewemail .= $newemail;
4212 $tmpnewemail .=
'</a>';
4214 $newemail = $tmpnewemail;
4216 $newemail = ($withpicto ?
img_picto($langs->trans(
"EMail").
' : '.$email, (is_numeric($withpicto) ?
'email' : $withpicto),
'class="paddingrightonly"') :
'').$newemail;
4219 $langs->load(
"errors");
4220 $newemail .=
img_warning($langs->trans(
"ErrorBadEMail", $email));
4230 $parameters = array(
'cid' => $cid,
'socid' => $socid,
'addlink' => $addlink,
'picto' => $withpicto);
4232 $reshook = $hookmanager->executeHooks(
'printEmail', $parameters, $email);
4236 $rep .= $hookmanager->resPrint;
4251 $socialnetworks = array();
4253 require_once DOL_DOCUMENT_ROOT.
'/core/lib/memory.lib.php';
4254 $cachekey =
'socialnetworks_' .
$conf->entity;
4256 if (!is_null($dataretrieved)) {
4257 $socialnetworks = $dataretrieved;
4259 $sql =
"SELECT rowid, code, label, url, icon, active FROM ".MAIN_DB_PREFIX.
"c_socialnetworks";
4260 $sql .=
" WHERE entity=".$conf->entity;
4261 $resql = $db->query($sql);
4263 while ($obj = $db->fetch_object($resql)) {
4264 $socialnetworks[$obj->code] = array(
4265 'rowid' => $obj->rowid,
4266 'label' => $obj->label,
4268 'icon' => $obj->icon,
4269 'active' => $obj->active,
4275 return $socialnetworks;
4290 global $hookmanager, $langs, $user;
4294 if (empty($value)) {
4298 if (!empty($type)) {
4299 $htmllink =
'<div class="divsocialnetwork inline-block valignmiddle">';
4301 $htmllink .=
'<span class="fab pictofixedwidth ' . ($dictsocialnetworks[$type][
'icon'] ? $dictsocialnetworks[$type][
'icon'] :
'fa-link') .
'"></span>';
4302 if ($type ==
'skype') {
4304 $htmllink .=
' <a href="skype:';
4306 $htmllink .=
'?call" alt="' . $langs->trans(
"Call") .
' ' . $value .
'" title="' .
dol_escape_htmltag($langs->trans(
"Call") .
' ' . $value) .
'">';
4307 $htmllink .=
'<img src="' . DOL_URL_ROOT .
'/theme/common/skype_callbutton.png" border="0">';
4308 $htmllink .=
'</a><a href="skype:';
4310 $htmllink .=
'?chat" alt="' . $langs->trans(
"Chat") .
' ' . $value .
'" title="' .
dol_escape_htmltag($langs->trans(
"Chat") .
' ' . $value) .
'">';
4311 $htmllink .=
'<img class="paddingleft" src="' . DOL_URL_ROOT .
'/theme/common/skype_chatbutton.png" border="0">';
4312 $htmllink .=
'</a>';
4313 if (($contactid || $socid) && isModEnabled(
'agenda') && $user->hasRight(
'agenda',
'myactions',
'create')) {
4314 $addlink =
'AC_SKYPE';
4317 $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>';
4319 $htmllink .= ($link ?
' ' . $link :
'');
4322 if (!empty($dictsocialnetworks[$type][
'url'])) {
4323 $tmpvirginurl = preg_replace(
'/\/?{socialid}/',
'', $dictsocialnetworks[$type][
'url']);
4324 if ($tmpvirginurl) {
4325 $value = preg_replace(
'/^www\.' . preg_quote($tmpvirginurl,
'/') .
'\/?/',
'', $value);
4326 $value = preg_replace(
'/^' . preg_quote($tmpvirginurl,
'/') .
'\/?/',
'', $value);
4328 $tmpvirginurl3 = preg_replace(
'/^https:\/\//i',
'https://www.', $tmpvirginurl);
4329 if ($tmpvirginurl3) {
4330 $value = preg_replace(
'/^www\.' . preg_quote($tmpvirginurl3,
'/') .
'\/?/',
'', $value);
4331 $value = preg_replace(
'/^' . preg_quote($tmpvirginurl3,
'/') .
'\/?/',
'', $value);
4334 $tmpvirginurl2 = preg_replace(
'/^https?:\/\//i',
'', $tmpvirginurl);
4335 if ($tmpvirginurl2) {
4336 $value = preg_replace(
'/^www\.' . preg_quote($tmpvirginurl2,
'/') .
'\/?/',
'', $value);
4337 $value = preg_replace(
'/^' . preg_quote($tmpvirginurl2,
'/') .
'\/?/',
'', $value);
4340 if (preg_match(
'/^https?:\/\//i', $value)) {
4343 $link = str_replace(
'{socialid}', $value, $dictsocialnetworks[$type][
'url']);
4345 $valuetoshow = $value;
4346 $valuetoshow = preg_replace(
'/https:\/\/www\.(twitter|x|linkedin)\.com\/?/',
'', $valuetoshow);
4347 if (preg_match(
'/^https?:\/\//i', $link)) {
4356 $htmllink .=
'</div>';
4358 $langs->load(
"errors");
4359 $htmllink .=
img_warning($langs->trans(
"ErrorBadSocialNetworkValue", $value));
4363 $parameters = array(
4365 'cid' => $contactid,
4368 'dictsocialnetworks' => $dictsocialnetworks,
4371 $reshook = $hookmanager->executeHooks(
'printSocialNetworks', $parameters);
4375 $htmllink .= $hookmanager->resPrint;
4390function dol_print_profids($profID, $profIDtype, $countrycode =
'', $addcpButton = 1)
4394 if (empty($profID) || empty($profIDtype)) {
4397 if (empty($countrycode)) {
4398 $countrycode = $mysoc->country_code;
4400 $newProfID = $profID;
4401 $id = substr($profIDtype, -1);
4403 if (strtoupper($countrycode) ==
'FR') {
4409 $newProfID = substr($newProfID, 0, 3).
' '.substr($newProfID, 3, 3).
' '.substr($newProfID, 6, 3);
4413 $newProfID = substr($newProfID, 0, 3).
' '.substr($newProfID, 3, 3).
' '.substr($newProfID, 6, 3).
' '.substr($newProfID, 9, 5);
4417 $newProfID = substr($newProfID, 0, 2).
'.'.substr($newProfID, 2, 3);
4419 if ($profIDtype ===
'VAT' &&
dol_strlen($newProfID) == 13) {
4421 $newProfID = substr($newProfID, 0, 4).
' '.substr($newProfID, 4, 3).
' '.substr($newProfID, 7, 3).
' '.substr($newProfID, 10, 3);
4424 if (!empty($addcpButton)) {
4447function dol_print_phone($phone, $countrycode =
'', $cid = 0, $socid = 0, $addlink =
'', $separ =
" ", $withpicto =
'', $titlealt =
'', $adddivfloat = 0, $morecss =
'paddingright')
4449 global
$conf, $user, $langs, $mysoc, $hookmanager;
4452 $phone = is_null($phone) ?
'' : preg_replace(
"/[\s.-]/",
"", trim($phone));
4453 if (empty($phone)) {
4459 if (empty($countrycode) && is_object($mysoc)) {
4460 $countrycode = $mysoc->country_code;
4464 if (!empty(
$conf->dol_optimize_smallscreen) && $separ !=
'hidenum') {
4469 $newphonewa = $phone;
4470 if (strtoupper($countrycode) ==
"FR") {
4473 $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);
4475 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 2).$separ.substr($newphone, 5, 2);
4477 $newphone = substr($newphone, 0, 2).$separ.substr($newphone, 2, 3).$separ.substr($newphone, 5, 2).$separ.substr($newphone, 7, 2);
4479 $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);
4481 $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);
4483 $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);
4485 } elseif (strtoupper($countrycode) ==
"CA") {
4487 $newphone = ($separ !=
'' ?
'(' :
'').substr($newphone, 0, 3).($separ !=
'' ?
')' :
'').$separ.substr($newphone, 3, 3).($separ !=
'' ?
'-' :
'').substr($newphone, 6, 4);
4489 } elseif (strtoupper($countrycode) ==
"PT") {
4491 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
4493 } elseif (strtoupper($countrycode) ==
"SR") {
4495 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3);
4497 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 4);
4499 } elseif (strtoupper($countrycode) ==
"DE") {
4501 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 4).$separ.substr($newphone, 7, 4).$separ.substr($newphone, 11, 3);
4503 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 4).$separ.substr($newphone, 10, 3);
4505 } elseif (strtoupper($countrycode) ==
"ES") {
4507 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
4509 } elseif (strtoupper($countrycode) ==
"BF") {
4511 $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);
4513 } elseif (strtoupper($countrycode) ==
"RO") {
4515 $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);
4517 } elseif (strtoupper($countrycode) ==
"TR") {
4519 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 4);
4521 } elseif (strtoupper($countrycode) ==
"US") {
4523 $newphone = substr($newphone, 0, 2).$separ.substr($newphone, 2, 3).$separ.substr($newphone, 5, 3).$separ.substr($newphone, 8, 4);
4525 } elseif (strtoupper($countrycode) ==
"MX") {
4527 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 4).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 2);
4529 $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);
4531 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 4);
4533 } elseif (strtoupper($countrycode) ==
"ML") {
4535 $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);
4537 } elseif (strtoupper($countrycode) ==
"TH") {
4539 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 3);
4541 $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);
4543 } elseif (strtoupper($countrycode) ==
"MU") {
4546 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 2).$separ.substr($newphone, 9, 2);
4548 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 4).$separ.substr($newphone, 8, 2).$separ.substr($newphone, 10, 2);
4550 } elseif (strtoupper($countrycode) ==
"ZA") {
4552 $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);
4554 } elseif (strtoupper($countrycode) ==
"SY") {
4556 $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);
4558 $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);
4560 } elseif (strtoupper($countrycode) ==
"AE") {
4562 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 2);
4564 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
4566 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 4);
4568 } elseif (strtoupper($countrycode) ==
"DZ") {
4570 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
4572 } elseif (strtoupper($countrycode) ==
"BE") {
4574 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 3);
4576 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
4578 } elseif (strtoupper($countrycode) ==
"PF") {
4580 $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);
4582 } elseif (strtoupper($countrycode) ==
"CO") {
4584 $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);
4586 } elseif (strtoupper($countrycode) ==
"JO") {
4588 $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);
4590 } elseif (strtoupper($countrycode) ==
"JM") {
4592 $newphone = substr($newphone, 0, 5).$separ.substr($newphone, 5, 3).$separ.substr($newphone, 8, 4);
4594 } elseif (strtoupper($countrycode) ==
"MG") {
4596 $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);
4598 } elseif (strtoupper($countrycode) ==
"GB") {
4600 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 4).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
4602 } elseif (strtoupper($countrycode) ==
"CH") {
4604 $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);
4606 $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);
4608 } elseif (strtoupper($countrycode) ==
"TN") {
4610 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 2).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
4612 } elseif (strtoupper($countrycode) ==
"GF") {
4614 $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);
4616 } elseif (strtoupper($countrycode) ==
"GP") {
4618 $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);
4620 } elseif (strtoupper($countrycode) ==
"MQ") {
4622 $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);
4624 } elseif (strtoupper($countrycode) ==
"IT") {
4626 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
4628 $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);
4630 } elseif (strtoupper($countrycode) ==
"AU") {
4634 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 1).$separ.substr($newphone, 4, 4).$separ.substr($newphone, 8, 4);
4636 } elseif (strtoupper($countrycode) ==
"LU") {
4639 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 2).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 2);
4641 $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);
4643 $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);
4645 $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);
4647 } elseif (strtoupper($countrycode) ==
"PE") {
4650 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 4);
4652 $newphonewa =
'+51'.$newphone;
4653 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3);
4655 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 4);
4657 $newphonewa = $newphone;
4658 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
4660 } elseif (strtoupper($countrycode) ==
"IN") {
4662 if ($withpicto ==
'phone') {
4663 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 2).$separ.substr($newphone, 5, 4).$separ.substr($newphone, 9, 4);
4665 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 5).$separ.substr($newphone, 8, 5);
4670 $newphoneastart = $newphoneaend =
'';
4671 if (!empty($addlink)) {
4672 if ($addlink ==
'tel' ||
$conf->browser->layout ==
'phone' || (isModEnabled(
'clicktodial') &&
getDolGlobalString(
'CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS'))) {
4673 $newphoneastart =
'<a href="tel:'.urlencode($phone).
'">';
4674 $newphoneaend .=
'</a>';
4675 } elseif (isModEnabled(
'clicktodial') && $addlink ==
'AC_TEL') {
4676 if (empty($user->clicktodial_loaded)) {
4677 $user->fetch_clicktodial();
4681 $urlmask =
getDolGlobalString(
'CLICKTODIAL_URL',
'ErrorClickToDialModuleNotConfigured');
4682 if (!empty($user->clicktodial_url)) {
4683 $urlmask = $user->clicktodial_url;
4686 $clicktodial_poste = (!empty($user->clicktodial_poste) ? urlencode($user->clicktodial_poste) :
'');
4687 $clicktodial_login = (!empty($user->clicktodial_login) ? urlencode($user->clicktodial_login) :
'');
4688 $clicktodial_password = (!empty($user->clicktodial_password) ? urlencode($user->clicktodial_password) :
'');
4690 $url = sprintf($urlmask, urlencode($phone), $clicktodial_poste, $clicktodial_login, $clicktodial_password);
4692 $substitarray = array(
'__PHONEFROM__' => $clicktodial_poste,
4693 '__PHONETO__' => urlencode($phone),
4694 '__LOGIN__' => $clicktodial_login,
4695 '__PASS__' => $clicktodial_password);
4699 $newphoneastart =
'<a href="'.$url.
'" class="cssforclicktodial">';
4700 $newphoneaend =
'</a>';
4703 $newphoneastart =
'<a href="'.$url.
'"';
4705 $newphoneastart .=
' target="_blank" rel="noopener noreferrer"';
4707 $newphoneastart .=
'>';
4708 $newphoneaend .=
'</a>';
4713 if (isModEnabled(
'agenda') && $user->hasRight(
"agenda",
"myactions",
"create")) {
4715 $addlinktoagenda =
'';
4716 if ($addlink ==
'AC_FAX') {
4720 $addlinktoagenda =
'<a href="'.DOL_URL_ROOT.
'/comm/action/card.php?action=create&backtopage='. urlencode($_SERVER[
'REQUEST_URI']) .
'&actioncode='.$type.($cid ?
'&contactid='.$cid :
'').($socid ?
'&socid='.$socid :
'').
'">'.
img_object($langs->trans(
"AddAction"),
"calendar").
'</a>';
4722 if ($addlinktoagenda) {
4723 $newphone =
'<span>'.$newphone.
' '.$addlinktoagenda.
'</span>';
4728 if (
getDolGlobalString(
'CONTACT_PHONEMOBILE_SHOW_LINK_TO_WHATSAPP') && $withpicto ==
'mobile') {
4730 $newphone .=
' <a href="https://wa.me/'.$newphonewa.
'" target="_blank"';
4731 $newphone .=
'><span class="paddingright fab fa-whatsapp" style="color:#25D366;" title="WhatsApp"></span></a>';
4734 if (empty($titlealt)) {
4735 $titlealt = ($withpicto ==
'fax' ? $langs->trans(
"Fax") : $langs->trans(
"Phone"));
4740 $parameters = array(
'countrycode' => $countrycode,
'cid' => $cid,
'socid' => $socid,
'titlealt' => $titlealt,
'picto' => $withpicto);
4741 $reshook = $hookmanager->executeHooks(
'printPhone', $parameters, $phone);
4742 $rep .= $hookmanager->resPrint;
4744 if (empty($reshook)) {
4747 if ($withpicto ==
'fax') {
4748 $picto =
'phoning_fax';
4749 } elseif ($withpicto ==
'phone') {
4751 } elseif ($withpicto ==
'mobile') {
4752 $picto =
'phoning_mobile';
4757 if ($adddivfloat == 1) {
4758 $rep .=
'<div class="nospan float'.($morecss ?
' '.$morecss :
'').
'">';
4759 } elseif (empty($adddivfloat)) {
4760 $rep .=
'<span'.($morecss ?
' class="'.$morecss.
'"' :
'').
'>';
4763 $rep .= $newphoneastart;
4764 $rep .= ($withpicto ?
img_picto($titlealt,
'object_'.$picto.
'.png') :
'');
4765 if ($separ !=
'hidenum') {
4766 $rep .= ($withpicto ?
' ' :
'').$newphone;
4768 $rep .= $newphoneaend;
4770 if ($adddivfloat == 1) {
4772 } elseif (empty($adddivfloat)) {
4793 if (!isset(
$conf->cache[
'resolveips'])) {
4794 $conf->cache[
'resolveips'] = array();
4800 if (file_exists(DOL_DOCUMENT_ROOT.
'/theme/common/flags/'.$countrycode.
'.png')) {
4804 $ret .=
'('.$countrycode.
')';
4812 if (in_array($mode, [0, 2])) {
4815 if (!array_key_exists($ip,
$conf->cache[
'resolveips'])) {
4816 $domain = gethostbyaddr($ip);
4817 $conf->cache[
'resolveips'][$ip] = $domain;
4819 $domain =
$conf->cache[
'resolveips'][$ip];
4847 $ip = (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']);
4854 if (empty($_SERVER[
'HTTP_X_FORWARDED_FOR']) || preg_match(
'/[^0-9\.\:,\[\]\s]/', $_SERVER[
'HTTP_X_FORWARDED_FOR'])) {
4855 if (empty($_SERVER[
'HTTP_CLIENT_IP']) || preg_match(
'/[^0-9\.\:,\[\]\s]/', $_SERVER[
'HTTP_CLIENT_IP'])) {
4856 if (empty($_SERVER[
"HTTP_CF_CONNECTING_IP"])) {
4857 $ip = (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']);
4859 $ip = $_SERVER[
"HTTP_CF_CONNECTING_IP"];
4862 $ip = preg_replace(
'/,.*$/',
'', $_SERVER[
'HTTP_CLIENT_IP']);
4865 $ip = preg_replace(
'/,.*$/',
'', $_SERVER[
'HTTP_X_FORWARDED_FOR']);
4881 if (isset($_SERVER[
'HTTPS']) && $_SERVER[
'HTTPS'] ==
'on') {
4883 } elseif (!empty($_SERVER[
'HTTP_X_FORWARDED_PROTO']) && $_SERVER[
'HTTP_X_FORWARDED_PROTO'] ==
'https' || !empty($_SERVER[
'HTTP_X_FORWARDED_SSL']) && $_SERVER[
'HTTP_X_FORWARDED_SSL'] ==
'on') {
4899 if (isModEnabled(
'geoipmaxmind')) {
4905 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeoip.class.php';
4906 $geoip =
new DolGeoIP(
'country', $datafile);
4908 $countrycode = $geoip->getCountryCodeFromIP($ip);
4915 return $countrycode;
4927 global
$conf, $langs, $user;
4931 if (isModEnabled(
'geoipmaxmind')) {
4936 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeoip.class.php';
4937 $geoip =
new DolGeoIP(
'country', $datafile);
4938 $countrycode = $geoip->getCountryCodeFromIP($ip);
4939 $ret = $countrycode;
4958 global $hookmanager;
4964 $parameters = array(
'element' => $element,
'id' =>
$id);
4965 $reshook = $hookmanager->executeHooks(
'printAddress', $parameters, $address);
4966 $out .= $hookmanager->resPrint;
4968 if (empty($reshook)) {
4969 if (empty($charfornl)) {
4970 $out .= nl2br((
string) $address);
4972 $out .= preg_replace(
'/[\r\n]+/', $charfornl, (
string) $address);
4976 $showgmap = $showomap = 0;
4977 if (($element ==
'thirdparty' || $element ==
'societe') && isModEnabled(
'google') &&
getDolGlobalString(
'GOOGLE_ENABLE_GMAPS')) {
4980 if ($element ==
'contact' && isModEnabled(
'google') &&
getDolGlobalString(
'GOOGLE_ENABLE_GMAPS_CONTACTS')) {
4983 if ($element ==
'member' && isModEnabled(
'google') &&
getDolGlobalString(
'GOOGLE_ENABLE_GMAPS_MEMBERS')) {
4986 if ($element ==
'user' && isModEnabled(
'google') &&
getDolGlobalString(
'GOOGLE_ENABLE_GMAPS_USERS')) {
4989 if (($element ==
'thirdparty' || $element ==
'societe') && isModEnabled(
'openstreetmap') &&
getDolGlobalString(
'OPENSTREETMAP_ENABLE_MAPS')) {
4992 if ($element ==
'contact' && isModEnabled(
'openstreetmap') &&
getDolGlobalString(
'OPENSTREETMAP_ENABLE_MAPS_CONTACTS')) {
4995 if ($element ==
'member' && isModEnabled(
'openstreetmap') &&
getDolGlobalString(
'OPENSTREETMAP_ENABLE_MAPS_MEMBERS')) {
4998 if ($element ==
'user' && isModEnabled(
'openstreetmap') &&
getDolGlobalString(
'OPENSTREETMAP_ENABLE_MAPS_USERS')) {
5003 $out .=
' <a href="'.$url.
'" target="_gmaps"><img id="'.$htmlid.
'" class="valigntextbottom" src="'.DOL_URL_ROOT.
'/theme/common/gmap.png"></a>';
5006 $url =
dol_buildpath(
'/openstreetmap/maps.php?mode='.$element.
'&id='.
$id, 1);
5007 $out .=
' <a href="'.$url.
'" target="_gmaps"><img id="'.$htmlid.
'_openstreetmap" class="valigntextbottom" src="'.DOL_URL_ROOT.
'/theme/common/gmap.png"></a>';
5029function isValidEmail($address, $acceptsupervisorkey = 0, $acceptuserkey = 0)
5031 if ($acceptsupervisorkey && $address ==
'__SUPERVISOREMAIL__') {
5034 if ($acceptuserkey && $address ==
'__USER_EMAIL__') {
5037 if (filter_var($address, FILTER_VALIDATE_EMAIL)) {
5055 if (function_exists(
'idn_to_ascii') && function_exists(
'checkdnsrr')) {
5056 if (!checkdnsrr(idn_to_ascii($domain),
'MX')) {
5059 if (function_exists(
'getmxrr')) {
5062 getmxrr(idn_to_ascii($domain), $mxhosts, $weight);
5063 if (count($mxhosts) > 1) {
5066 if (count($mxhosts) == 1 && !in_array((
string) $mxhosts[0], array(
'',
'.'))) {
5103 $tmparray = explode(
' ', $s);
5104 foreach ($tmparray as $tmps) {
5119function dol_strlen($string, $stringencoding =
'UTF-8')
5121 if (is_null($string)) {
5125 if (function_exists(
'mb_strlen')) {
5126 return mb_strlen($string, $stringencoding);
5128 return strlen($string);
5142function dol_substr($string, $start, $length =
null, $stringencoding =
'', $trunconbytes = 0)
5146 if (empty($stringencoding)) {
5147 $stringencoding = (empty($langs) ?
'UTF-8' : $langs->charset_output);
5151 if (empty($trunconbytes)) {
5152 if (function_exists(
'mb_substr')) {
5153 $ret = mb_substr($string, $start, $length, $stringencoding);
5155 $ret = substr($string, $start, $length);
5158 if (function_exists(
'mb_strcut')) {
5159 $ret = mb_strcut($string, $start, $length, $stringencoding);
5161 $ret = substr($string, $start, $length);
5181function dol_trunc($string, $size = 40, $trunc =
'right', $stringencoding =
'UTF-8', $nodot = 0, $display = 0)
5189 if (empty($stringencoding)) {
5190 $stringencoding =
'UTF-8';
5193 if (!empty(
$conf->dol_optimize_smallscreen) &&
$conf->dol_optimize_smallscreen == 1 && $display == 1) {
5194 $size = round($size / 3);
5198 if ($trunc ==
'right') {
5200 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
5202 return dol_substr($newstring, 0, $size, $stringencoding).($nodot ?
'' :
'…');
5207 } elseif ($trunc ==
'middle') {
5209 if (
dol_strlen($newstring, $stringencoding) > 2 &&
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
5210 $size1 = (int) round($size / 2);
5211 $size2 = (int) round($size / 2);
5212 return dol_substr($newstring, 0, $size1, $stringencoding).
'…'.
dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size2, $size2, $stringencoding);
5216 } elseif ($trunc ==
'left') {
5218 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
5220 return '…'.dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size, $size, $stringencoding);
5224 } elseif ($trunc ==
'wrap') {
5226 if (
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
5232 return 'BadParam3CallingDolTrunc';
5246 $type2picto = array(
5247 'varchar' =>
'font',
5250 'int' =>
'sort-numeric-down',
5251 'double' =>
'sort-numeric-down',
5252 'price' =>
'currency',
5253 'pricecy' =>
'multicurrency',
5254 'password' =>
'key',
5255 'boolean' =>
'check-square',
5256 'date' =>
'calendar',
5257 'datetime' =>
'calendar',
5258 'duration' =>
'hourglass',
5264 'sellist' =>
'list',
5265 'stars' =>
'fontawesome_star_fas',
5266 'radio' =>
'check-circle',
5267 'checkbox' =>
'list',
5268 'chkbxlst' =>
'list',
5270 'icon' =>
"question",
5271 'point' =>
"country",
5272 'multipts' =>
'country',
5273 'linestrg' =>
"country",
5274 'polygon' =>
"country",
5275 'separate' =>
'minus'
5278 if (!empty($type2picto[$key])) {
5279 return img_picto(
'', $type2picto[$key],
'class="pictofixedwidth'.($morecss ?
' '.$morecss :
'').
'"');
5282 return img_picto(
'',
'generic',
'class="pictofixedwidth'.($morecss ?
' '.$morecss :
'').
'"');
5308function img_picto($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $srconly = 0, $notitle = 0, $alt =
'', $morecss =
'', $marginleftonlyshort = 2, $allowothertags = array())
5313 $url = DOL_URL_ROOT;
5314 $theme = isset(
$conf->theme) ?
$conf->theme :
null;
5315 $path =
'theme/'.$theme;
5316 if (empty($picto)) {
5321 if ($pictoisfullpath) {
5323 if (!preg_match(
'/(\.png|\.gif|\.svg)$/i', $picto)) {
5326 $fullpathpicto = $picto;
5328 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
5329 $morecss .= ($morecss ?
' ' :
'').$reg[1];
5330 $moreatt = str_replace(
'class="'.$reg[1].
'"',
'', $moreatt);
5335 $pictowithouttext = preg_replace(
'/(\.png|\.gif|\.svg)$/',
'', $picto);
5336 $pictowithouttext = str_replace(
'object_',
'', $pictowithouttext);
5337 $pictowithouttext = str_replace(
'_nocolor',
'', $pictowithouttext);
5340 $pictoconvertkey = array(
'facture' =>
'bill',
'shipping' =>
'shipment',
'fichinter' =>
'intervention',
'agenda' =>
'calendar',
'invoice_supplier' =>
'supplier_invoice',
'order_supplier' =>
'supplier_order');
5341 if (in_array($pictowithouttext, array_keys($pictoconvertkey))) {
5342 $pictowithouttext = $pictoconvertkey[$pictowithouttext];
5345 if (strpos($pictowithouttext,
'fontawesome_') === 0 || strpos($pictowithouttext,
'fa-') === 0) {
5347 $pictowithouttext = str_replace(
'fontawesome_',
'', $pictowithouttext);
5348 $pictowithouttext = str_replace(
'fa-',
'', $pictowithouttext);
5351 if ($pictowithouttext ==
'file-o') {
5352 $pictowithouttext =
'file';
5355 $pictowithouttextarray = explode(
'_', $pictowithouttext);
5356 $marginleftonlyshort = 0;
5358 if (!empty($pictowithouttextarray[1])) {
5360 $fakey =
'fa-'.$pictowithouttextarray[0];
5361 $faprefix = empty($pictowithouttextarray[1]) ?
'fas' : $pictowithouttextarray[1];
5362 $facolor = empty($pictowithouttextarray[2]) ?
'' : $pictowithouttextarray[2];
5363 $fasize = empty($pictowithouttextarray[3]) ?
'' : $pictowithouttextarray[3];
5365 $fakey =
'fa-'.$pictowithouttext;
5375 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
5376 $morecss .= ($morecss ?
' ' :
'').$reg[1];
5377 $moreatt = str_replace(
'class="'.$reg[1].
'"',
'', $moreatt);
5379 if (preg_match(
'/style="([^"]+)"/', $moreatt, $reg)) {
5380 $morestyle = $reg[1];
5381 $moreatt = str_replace(
'style="'.$reg[1].
'"',
'', $moreatt);
5383 $moreatt = trim($moreatt);
5385 $enabledisablehtml =
'<span class="'.$faprefix.
' '.$fakey.($marginleftonlyshort ? ($marginleftonlyshort == 1 ?
' marginleftonlyshort' :
' marginleftonly') :
'');
5386 $enabledisablehtml .= ($morecss ?
' '.$morecss :
'').
'" style="'.($fasize ? (
'font-size: '.$fasize.
';') :
'').($facolor ? (
' color: '.$facolor.
';') :
'').($morestyle ?
' '.$morestyle :
'').
'"'.(($notitle || empty($titlealt)) ?
'' :
' title="'.
dol_escape_htmltag($titlealt).
'"').($moreatt ?
' '.$moreatt :
'').
'>';
5387 $enabledisablehtml .=
'</span>';
5389 return $enabledisablehtml;
5393 $fakey = $pictowithouttext;
5397 if (in_array($pictowithouttext, array(
'card',
'bell',
'clock',
'establishment',
'file',
'file-o',
'generic',
'minus-square',
'object_generic',
'pdf',
'plus-square',
'timespent',
'note',
'off',
'on',
'object_bookmark',
'bookmark',
'vcard'))) {
5400 if (in_array($pictowithouttext, array(
'black-tie',
'discord',
'facebook',
'flickr',
'github',
'google',
'google-plus-g',
'instagram',
'linkedin',
'meetup',
'microsoft',
'pinterest',
'skype',
'slack',
'twitter',
'reddit',
'snapchat',
'stripe',
'stripe-s',
'tumblr',
'viadeo',
'whatsapp',
'youtube'))) {
5406 if ($pictowithouttext ==
'off') {
5407 $fakey =
'fa-square';
5409 } elseif ($pictowithouttext ==
'on') {
5410 $fakey =
'fa-check-square';
5412 } elseif ($pictowithouttext ==
'listlight') {
5413 $fakey =
'fa-download';
5414 $marginleftonlyshort = 1;
5415 } elseif ($pictowithouttext ==
'printer') {
5416 $fakey =
'fa-print';
5418 } elseif ($pictowithouttext ==
'note') {
5419 $fakey =
'fa-sticky-note';
5420 $marginleftonlyshort = 1;
5421 } elseif (in_array($pictowithouttext, array(
'1uparrow',
'1downarrow',
'1leftarrow',
'1rightarrow',
'1uparrow_selected',
'1downarrow_selected',
'1leftarrow_selected',
'1rightarrow_selected'))) {
5422 $convertarray = array(
'1uparrow' =>
'caret-up',
'1downarrow' =>
'caret-down',
'1leftarrow' =>
'caret-left',
'1rightarrow' =>
'caret-right',
'1uparrow_selected' =>
'caret-up',
'1downarrow_selected' =>
'caret-down',
'1leftarrow_selected' =>
'caret-left',
'1rightarrow_selected' =>
'caret-right');
5423 $fakey =
'fa-'.$convertarray[$pictowithouttext];
5424 if (preg_match(
'/selected/', $pictowithouttext)) {
5427 $marginleftonlyshort = 1;
5428 } elseif (!empty($arrayconvpictotofa[$pictowithouttext])) {
5429 $fakey =
'fa-'.$arrayconvpictotofa[$pictowithouttext];
5431 $fakey =
'fa-'.$pictowithouttext;
5434 if (in_array($pictowithouttext, array(
'dollyrevert',
'member',
'members',
'contract',
'group',
'resource',
'shipment',
'reception'))) {
5435 $morecss .=
' em092';
5437 if (in_array($pictowithouttext, array(
'conferenceorbooth',
'collab',
'eventorganization',
'holiday',
'info',
'info_black',
'project',
'workstation'))) {
5438 $morecss .=
' em088';
5440 if (in_array($pictowithouttext, array(
'asset',
'intervention',
'payment',
'loan',
'partnership',
'stock',
'technic'))) {
5441 $morecss .=
' em080';
5445 $arrayconvpictotomarginleftonly = array(
5446 'bank',
'check',
'delete',
'generic',
'grip',
'grip_title',
'jabber',
5447 'grip_title',
'grip',
'listlight',
'note',
'on',
'off',
'playdisabled',
'printer',
'resize',
'sign-out',
'stats',
'switch_on',
'switch_on_grey',
'switch_on_red',
'switch_off',
5448 'uparrow',
'1uparrow',
'1downarrow',
'1leftarrow',
'1rightarrow',
'1uparrow_selected',
'1downarrow_selected',
'1leftarrow_selected',
'1rightarrow_selected'
5450 if (!array_key_exists($pictowithouttext, $arrayconvpictotomarginleftonly)) {
5451 $marginleftonlyshort = 0;
5455 $arrayconvpictotomorcess = array(
5456 'action' =>
'infobox-action',
'account' =>
'infobox-bank_account',
'accounting_account' =>
'infobox-bank_account',
'accountline' =>
'infobox-bank_account',
'accountancy' =>
'infobox-bank_account',
'asset' =>
'infobox-bank_account',
5457 'bank_account' =>
'infobox-bank_account',
5458 'bill' =>
'infobox-commande',
'billa' =>
'infobox-commande',
'billr' =>
'infobox-commande',
'billd' =>
'infobox-commande',
5459 'bookcal' =>
'infobox-action',
5460 'margin' =>
'infobox-bank_account',
'conferenceorbooth' =>
'infobox-project',
5461 'cash-register' =>
'infobox-bank_account',
'contract' =>
'infobox-contrat',
'check' =>
'font-status4',
'collab' =>
'infobox-action',
'conversation' =>
'infobox-contrat',
5462 'donation' =>
'infobox-commande',
'dolly' =>
'infobox-commande',
'dollyrevert' =>
'flip infobox-order_supplier',
5463 'ecm' =>
'infobox-action',
'eventorganization' =>
'infobox-project',
5464 'hrm' =>
'infobox-adherent',
'group' =>
'infobox-adherent',
'intervention' =>
'infobox-contrat',
5465 'incoterm' =>
'infobox-supplier_proposal',
5466 'currency' =>
'infobox-bank_account',
'multicurrency' =>
'infobox-bank_account',
5467 'members' =>
'infobox-adherent',
'member' =>
'infobox-adherent',
'money-bill-alt' =>
'infobox-bank_account',
5468 'order' =>
'infobox-commande',
5469 'user' =>
'infobox-adherent',
'users' =>
'infobox-adherent',
5470 'error' =>
'pictoerror',
'warning' =>
'pictowarning',
'switch_on' =>
'font-status4',
'switch_on_warning' =>
'font-status4 warning',
'switch_on_red' =>
'font-status8',
5471 'holiday' =>
'infobox-holiday',
'info' =>
'opacityhigh',
'info_black' =>
'font-status1',
'invoice' =>
'infobox-commande',
5472 'knowledgemanagement' =>
'infobox-contrat rotate90',
'loan' =>
'infobox-bank_account',
5473 'payment' =>
'infobox-bank_account',
'payment_vat' =>
'infobox-bank_account',
'poll' =>
'infobox-adherent',
'pos' =>
'infobox-bank_account',
'project' =>
'infobox-project',
'projecttask' =>
'infobox-project',
5474 'propal' =>
'infobox-propal',
'proposal' =>
'infobox-propal',
'private' =>
'infobox-project',
5475 'reception' =>
'flip infobox-order_supplier',
'recruitmentjobposition' =>
'infobox-adherent',
'recruitmentcandidature' =>
'infobox-adherent',
5476 'resource' =>
'infobox-action',
5477 'salary' =>
'infobox-bank_account',
'shapes' =>
'infobox-adherent',
'shipment' =>
'infobox-commande',
'stripe' =>
'infobox-bank_account',
'supplier_invoice' =>
'infobox-order_supplier',
'supplier_invoicea' =>
'infobox-order_supplier',
'supplier_invoiced' =>
'infobox-order_supplier',
5478 'supplier' =>
'infobox-order_supplier',
'supplier_order' =>
'infobox-order_supplier',
'supplier_proposal' =>
'infobox-supplier_proposal',
5479 'ticket' =>
'infobox-contrat',
'title_accountancy' =>
'infobox-bank_account',
'title_hrm' =>
'infobox-holiday',
'expensereport' =>
'infobox-expensereport',
'trip' =>
'infobox-expensereport',
'title_agenda' =>
'infobox-action',
5480 'vat' =>
'infobox-bank_account',
5482 'list-alt' =>
'imgforviewmode',
'calendar' =>
'imgforviewmode',
'calendarweek' =>
'imgforviewmode',
'calendarmonth' =>
'imgforviewmode',
'calendarday' =>
'imgforviewmode',
'calendarperuser' =>
'imgforviewmode',
'calendarpertype' =>
'imgforviewmode'
5484 if (!empty($arrayconvpictotomorcess[$pictowithouttext]) && strpos($picto,
'_nocolor') ===
false) {
5485 $morecss .= ($morecss ?
' ' :
'').$arrayconvpictotomorcess[$pictowithouttext];
5489 $arrayconvpictotocolor = array(
5490 'address' =>
'#6c6aa8',
'building' =>
'#6c6aa8',
'bom' =>
'#a69944',
5491 'clone' =>
'#999',
'cog' =>
'#999',
'companies' =>
'#6c6aa8',
'company' =>
'#6c6aa8',
'contact' =>
'#6c6aa8',
'cron' =>
'#555',
5492 'dynamicprice' =>
'#a69944',
5493 'edit' =>
'#444',
'note' =>
'#999',
'error' =>
'',
'help' =>
'#bbb',
'listlight' =>
'#999',
'language' =>
'#555',
5495 'lock' =>
'#ddd',
'lot' =>
'#a69944',
5496 'map-marker-alt' =>
'#aaa',
'mrp' =>
'#a69944',
'product' =>
'#a69944',
'service' =>
'#a69944',
'inventory' =>
'#a69944',
'stock' =>
'#a69944',
'movement' =>
'#a69944',
5497 'other' =>
'#ddd',
'world' =>
'#986c6a',
5498 'partnership' =>
'#6c6aa8',
'playdisabled' =>
'#ccc',
'printer' =>
'#444',
'projectpub' =>
'#986c6a',
'resize' =>
'#444',
'rss' =>
'#cba',
5500 'search-plus' =>
'#808080',
'security' =>
'#999',
'square' =>
'#888',
'stop-circle' =>
'#888',
'stats' =>
'#444',
'switch_off' =>
'#999',
5501 'technic' =>
'#999',
'tick' =>
'#282',
'timespent' =>
'#555',
5502 'uncheck' =>
'#800',
'uparrow' =>
'#555',
'user-cog' =>
'#999',
'country' =>
'#aaa',
'globe-americas' =>
'#aaa',
'region' =>
'#aaa',
'state' =>
'#aaa',
5503 'website' =>
'#304',
'workstation' =>
'#a69944'
5505 if (isset($arrayconvpictotocolor[$pictowithouttext]) && strpos($picto,
'_nocolor') ===
false) {
5506 $facolor = $arrayconvpictotocolor[$pictowithouttext];
5513 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
5514 $morecss .= ($morecss ?
' ' :
'').$reg[1];
5515 $moreatt = str_replace(
'class="'.$reg[1].
'"',
'', $moreatt);
5517 if (preg_match(
'/style="([^"]+)"/', $moreatt, $reg)) {
5518 $morestyle = $reg[1];
5519 $moreatt = str_replace(
'style="'.$reg[1].
'"',
'', $moreatt);
5521 $moreatt = trim($moreatt);
5523 $enabledisablehtml =
'<span class="'.$fa.
' '.$fakey.($marginleftonlyshort ? ($marginleftonlyshort == 1 ?
' marginleftonlyshort' :
' marginleftonly') :
'');
5524 $enabledisablehtml .= ($morecss ?
' '.$morecss :
'').
'" style="'.($fasize ? (
'font-size: '.$fasize.
';') :
'').($facolor ? (
' color: '.$facolor.
';') :
'').($morestyle ?
' '.$morestyle :
'').
'"'.(($notitle || empty($titlealt)) ?
'' :
' title="'.
dol_escape_htmltag($titlealt).
'"').($moreatt ?
' '.$moreatt :
'').
'>';
5525 $enabledisablehtml .=
'</span>';
5527 return $enabledisablehtml;
5534 } elseif (!empty(
$conf->modules_parts[
'theme']) && array_key_exists($theme,
$conf->modules_parts[
'theme'])) {
5535 $path = $theme.
'/theme/'.$theme;
5540 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $picto, $regs)) {
5546 if (!preg_match(
'/(\.png|\.gif|\.svg)$/i', $picto)) {
5551 foreach (
$conf->file->dol_document_root as $type => $dirroot) {
5552 if ($type ==
'main') {
5556 if (file_exists($dirroot.
'/'.$path.
'/img/'.$picto)) {
5557 $url = DOL_URL_ROOT.$conf->file->dol_url_root[$type];
5563 $fullpathpicto = $url.
'/'.$path.
'/img/'.$picto;
5567 return $fullpathpicto;
5571 return '<img src="'.$fullpathpicto.
'"'.($notitle ?
'' :
' alt="'.dolPrintHTMLForAttribute($alt, 0, $allowothertags).
'"').(($notitle || empty($titlealt)) ?
'' :
' title="'.
dolPrintHTMLForAttribute($titlealt, 0, $allowothertags).
'"').($moreatt ?
' '.$moreatt.($morecss ?
' class="'.$morecss.
'"' :
'') :
' class="inline-block'.($morecss ?
' '.$morecss :
'').
'"').
'>';
5582 '1downarrow',
'1uparrow',
'1leftarrow',
'1rightarrow',
'1uparrow_selected',
'1downarrow_selected',
'1leftarrow_selected',
'1rightarrow_selected',
5583 'accountancy',
'accounting_account',
'account',
'accountline',
'action',
'add',
'address',
'ai',
'angle-double-down',
'angle-double-up',
'asset',
5584 'back',
'bank_account',
'barcode',
'bank',
'bell',
'bill',
'billa',
'billr',
'billd',
'birthday-cake',
'bom',
'bookcal',
'bookmark',
'briefcase-medical',
'bug',
'building',
5585 'card',
'calendarlist',
'calendar',
'calendarmonth',
'calendarweek',
'calendarday',
'calendarperuser',
'calendarpertype',
'hourglass',
5586 'cash-register',
'category',
'chart',
'check',
'clock',
'clone',
'close_title',
'code',
'cog',
'collab',
'company',
'contact',
'country',
'contract',
'conversation',
'cron',
'cross',
'cubes',
5587 'check-circle',
'check-square',
'circle',
'stop-circle',
'currency',
'multicurrency',
5588 'chevron-left',
'chevron-right',
'chevron-down',
'chevron-up',
5589 'chevron-double-left',
'chevron-double-right',
'chevron-double-down',
'chevron-double-top',
5590 'commercial',
'companies',
5591 'delete',
'dolly',
'dollyrevert',
'donation',
'download',
'dynamicprice',
5592 'edit',
'ellipsis-h',
'email',
'entity',
'envelope',
'eraser',
'establishment',
'expensereport',
'external-link-alt',
'external-link-square-alt',
'eye',
5593 'filter',
'file',
'file-o',
'file-code',
'file-export',
'file-import',
'file-upload',
'autofill',
'folder',
'folder-open',
'folder-plus',
'font',
5594 'generate',
'generic',
'globe',
'globe-americas',
'graph',
'grip',
'grip_title',
'group',
5595 'hands-helping',
'help',
'holiday',
5596 'id-card',
'images',
'incoterm',
'info',
'info_black',
'intervention',
'inventory',
'intracommreport',
'jobprofile',
5597 'key',
'knowledgemanagement',
5598 'label',
'language',
'layout',
'line',
'link',
'list',
'list-alt',
'listlight',
'loan',
'lock',
'lot',
'long-arrow-alt-right',
5599 'margin',
'map-marker-alt',
'member',
'meeting',
'minus',
'money-bill-alt',
'movement',
'mrp',
'note',
'next',
5600 'off',
'on',
'order',
5601 'paragraph',
'play',
'pdf',
'phone',
'phoning',
'phoning_mobile',
'phoning_fax',
'playdisabled',
'previous',
'poll',
'pos',
'printer',
'product',
'propal',
'proposal',
'puce',
5602 'resize',
'search',
'service',
'stats',
'stock',
5603 'security',
'setup',
'share-alt',
'sign-out',
'split',
'stripe',
'stripe-s',
'switch_off',
'switch_on',
'switch_on_grey',
'switch_on_warning',
'switch_on_red',
'tools',
'unlink',
'uparrow',
'user',
'user-tie',
'vcard',
'wrench',
5604 'discord',
'facebook',
'flickr',
'instagram',
'linkedin',
'github',
'google',
'jabber',
'meetup',
'microsoft',
'skype',
'slack',
'twitter',
'pinterest',
'reddit',
'snapchat',
'tumblr',
'youtube',
'viadeo',
'google-plus-g',
'whatsapp',
5605 'generic',
'home',
'hrm',
'members',
'products',
'invoicing',
5606 'partnership',
'payment',
'payment_vat',
'pencil-ruler',
'pictoconfirm',
'preview',
'project',
'projectpub',
'projecttask',
'question',
'refresh',
'region',
5607 'salary',
'shipment',
'state',
'supplier_invoice',
'supplier_invoicea',
'supplier_invoicer',
'supplier_invoiced',
5608 'technic',
'ticket',
5610 'recent',
'reception',
'recruitmentcandidature',
'recruitmentjobposition',
'replacement',
'resource',
'recurring',
'rss',
5611 'search-plus',
'shapes',
'skill',
'square',
'sort-numeric-down',
'status',
'stop-circle',
'store',
'supplier',
'supplier_proposal',
'supplier_order',
'supplier_invoice',
5612 'terminal',
'tick',
'timespent',
'title_setup',
'title_accountancy',
'title_bank',
'title_hrm',
'title_agenda',
'trip',
5613 'uncheck',
'undo',
'url',
'user-cog',
'user-injured',
'user-md',
'upload',
'vat',
'website',
'workstation',
'webhook',
'world',
'private',
5614 'conferenceorbooth',
'eventorganization',
5615 'stamp',
'signature',
5632 $arrayconvpictotofa = array(
5633 'account' =>
'university',
'accounting_account' =>
'clipboard-list',
'accountline' =>
'receipt',
'accountancy' =>
'search-dollar',
'action' =>
'calendar-alt',
'add' =>
'plus-circle',
'address' =>
'address-book',
'ai' =>
'magic',
5634 'asset' =>
'money-check-alt',
'autofill' =>
'fill',
5635 'back' =>
'arrow-left',
'bank_account' =>
'university',
5636 'bill' =>
'file-invoice-dollar',
'billa' =>
'file-excel',
'billr' =>
'file-invoice-dollar',
'billd' =>
'file-medical',
5637 'bookcal' =>
'calendar-check',
5638 'supplier_invoice' =>
'file-invoice-dollar',
'supplier_invoicea' =>
'file-excel',
'supplier_invoicer' =>
'file-invoice-dollar',
'supplier_invoiced' =>
'file-medical',
5640 'card' =>
'address-card',
'chart' =>
'chart-line',
'company' =>
'building',
'contact' =>
'address-book',
'contract' =>
'suitcase',
'collab' =>
'people-arrows',
'conversation' =>
'comments',
'country' =>
'globe-americas',
'cron' =>
'business-time',
'cross' =>
'times',
5641 'chevron-double-left' =>
'angle-double-left',
'chevron-double-right' =>
'angle-double-right',
'chevron-double-down' =>
'angle-double-down',
'chevron-double-top' =>
'angle-double-up',
5642 'donation' =>
'file-alt',
'dynamicprice' =>
'hand-holding-usd',
5643 'setup' =>
'cog',
'companies' =>
'building',
'products' =>
'cube',
'commercial' =>
'suitcase',
'invoicing' =>
'coins',
5644 'accounting' =>
'search-dollar',
'category' =>
'tag',
'dollyrevert' =>
'dolly',
5645 'file-o' =>
'file',
'generate' =>
'plus-square',
'hrm' =>
'user-tie',
'incoterm' =>
'truck-loading',
5646 'margin' =>
'calculator',
'members' =>
'user-friends',
'ticket' =>
'ticket-alt',
'globe' =>
'external-link-alt',
'lot' =>
'barcode',
5647 'email' =>
'at',
'establishment' =>
'building',
'edit' =>
'pencil-alt',
'entity' =>
'globe',
5648 'graph' =>
'chart-line',
'grip_title' =>
'arrows-alt',
'grip' =>
'arrows-alt',
'help' =>
'question-circle',
5649 'generic' =>
'file',
'holiday' =>
'umbrella-beach',
5650 'info' =>
'info-circle',
'info_black' =>
'info-circle',
'inventory' =>
'boxes',
'intracommreport' =>
'globe-europe',
'jobprofile' =>
'cogs',
5651 'knowledgemanagement' =>
'ticket-alt',
'label' =>
'layer-group',
'layout' =>
'columns',
'line' =>
'bars',
'loan' =>
'money-bill-alt',
5652 'member' =>
'user-alt',
'meeting' =>
'chalkboard-teacher',
'mrp' =>
'cubes',
'next' =>
'arrow-alt-circle-right',
5653 'trip' =>
'wallet',
'expensereport' =>
'wallet',
'group' =>
'users',
'movement' =>
'people-carry',
5654 'sign-out' =>
'sign-out-alt',
5655 'switch_off' =>
'toggle-off',
'switch_on' =>
'toggle-on',
'switch_on_grey' =>
'toggle-on',
'switch_on_warning' =>
'toggle-on',
'switch_on_red' =>
'toggle-on',
'check' =>
'check',
'bookmark' =>
'star',
5656 'bank' =>
'university',
'close_title' =>
'times',
'delete' =>
'trash',
'filter' =>
'filter',
5657 'list-alt' =>
'list-alt',
'calendarlist' =>
'bars',
'calendar' =>
'calendar-alt',
'calendarmonth' =>
'calendar-alt',
'calendarweek' =>
'calendar-week',
'calendarday' =>
'calendar-day',
'calendarperuser' =>
'table',
'calendarpertype' =>
'table',
5658 'intervention' =>
'ambulance',
'invoice' =>
'file-invoice-dollar',
'order' =>
'file-invoice',
5659 'error' =>
'exclamation-triangle',
'warning' =>
'exclamation-triangle',
5660 'other' =>
'square',
5661 'playdisabled' =>
'play',
'pdf' =>
'file-pdf',
'poll' =>
'check-double',
'pos' =>
'cash-register',
'preview' =>
'binoculars',
'project' =>
'project-diagram',
'projectpub' =>
'project-diagram',
'projecttask' =>
'tasks',
'propal' =>
'file-signature',
'proposal' =>
'file-signature',
5662 'partnership' =>
'handshake',
'payment' =>
'money-check-alt',
'payment_vat' =>
'money-check-alt',
'pictoconfirm' =>
'check-square',
'phoning' =>
'phone',
'phoning_mobile' =>
'mobile-alt',
'phoning_fax' =>
'fax',
'previous' =>
'arrow-alt-circle-left',
'printer' =>
'print',
'product' =>
'cube',
'puce' =>
'angle-right',
5663 'recent' =>
'check-square',
'reception' =>
'dolly',
'recruitmentjobposition' =>
'id-card-alt',
'recruitmentcandidature' =>
'id-badge',
5664 'resize' =>
'crop',
'supplier_order' =>
'dol-order_supplier',
'supplier_proposal' =>
'file-signature',
5665 'refresh' =>
'redo',
'region' =>
'map-marked',
'replacement' =>
'exchange-alt',
'resource' =>
'laptop-house',
'recurring' =>
'history',
5666 'service' =>
'concierge-bell',
5667 'skill' =>
'shapes',
'state' =>
'map-marked-alt',
'security' =>
'key',
'salary' =>
'wallet',
'shipment' =>
'dolly',
'stock' =>
'box-open',
'stats' =>
'chart-bar',
'split' =>
'code-branch',
5668 'status' =>
'stop-circle',
5669 'stripe' =>
'stripe-s',
'supplier' =>
'building',
5670 'technic' =>
'cogs',
'tick' =>
'check',
'timespent' =>
'clock',
'title_setup' =>
'tools',
'title_accountancy' =>
'money-check-alt',
'title_bank' =>
'university',
'title_hrm' =>
'umbrella-beach',
5671 'title_agenda' =>
'calendar-alt',
5672 'uncheck' =>
'times',
'uparrow' =>
'share',
'url' =>
'external-link-alt',
'vat' =>
'money-check-alt',
'vcard' =>
'arrow-alt-circle-down',
5673 'jabber' =>
'comment',
5674 'website' =>
'globe-americas',
'workstation' =>
'pallet',
'webhook' =>
'bullseye',
'world' =>
'globe',
'private' =>
'user-lock',
5675 'conferenceorbooth' =>
'chalkboard-teacher',
'eventorganization' =>
'project-diagram',
5676 'webportal' =>
'door-open'
5679 if (
$conf->currency ==
'EUR') {
5680 $arrayconvpictotofa[
'currency'] =
'euro-sign';
5681 $arrayconvpictotofa[
'multicurrency'] =
'dollar-sign';
5683 $arrayconvpictotofa[
'currency'] =
'dollar-sign';
5684 $arrayconvpictotofa[
'multicurrency'] =
'euro-sign';
5687 return $arrayconvpictotofa;
5705function img_object($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $srconly = 0, $notitle = 0, $allowothertags = array())
5707 if (strpos($picto,
'^') === 0) {
5708 return img_picto($titlealt, str_replace(
'^',
'', $picto), $moreatt, $pictoisfullpath, $srconly, $notitle,
'',
'', 2, $allowothertags);
5710 return img_picto($titlealt,
'object_'.$picto, $moreatt, $pictoisfullpath, $srconly, $notitle,
'',
'', 2, $allowothertags);
5725function img_weather($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $morecss =
'')
5729 if (is_numeric($picto)) {
5732 return '<i class="fa fa-weather-level'.$picto.
'"></i>';
5733 } elseif (!preg_match(
'/(\.png|\.gif)$/i', $picto)) {
5737 $path = DOL_URL_ROOT.
'/theme/'.
$conf->theme.
'/img/weather/'.$picto;
5739 return img_picto($titlealt, $path, $moreatt, 1, 0, 0,
'', $morecss);
5753function img_picto_common($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $notitle = 0)
5757 if (!preg_match(
'/(\.png|\.gif)$/i', $picto)) {
5761 if ($pictoisfullpath) {
5764 $path = DOL_URL_ROOT.
'/theme/common/'.$picto;
5767 $themepath = DOL_DOCUMENT_ROOT.
'/theme/'.
$conf->theme.
'/img/'.$picto;
5769 if (file_exists($themepath)) {
5775 return img_picto($titlealt, $path, $moreatt, 1, 0, $notitle);
5791function img_action($titlealt, $numaction, $picto =
'', $moreatt =
'')
5795 if (empty($titlealt) || $titlealt ==
'default') {
5796 if ($numaction ==
'-1' || $numaction ==
'ST_NO') {
5798 $titlealt = $langs->transnoentitiesnoconv(
'ChangeDoNotContact');
5799 } elseif ($numaction ==
'0' || $numaction ==
'ST_NEVER') {
5801 $titlealt = $langs->transnoentitiesnoconv(
'ChangeNeverContacted');
5802 } elseif ($numaction ==
'1' || $numaction ==
'ST_TODO') {
5804 $titlealt = $langs->transnoentitiesnoconv(
'ChangeToContact');
5805 } elseif ($numaction ==
'2' || $numaction ==
'ST_PEND') {
5807 $titlealt = $langs->transnoentitiesnoconv(
'ChangeContactInProcess');
5808 } elseif ($numaction ==
'3' || $numaction ==
'ST_DONE') {
5810 $titlealt = $langs->transnoentitiesnoconv(
'ChangeContactDone');
5812 $titlealt = $langs->transnoentitiesnoconv(
'ChangeStatus '.$numaction);
5816 if (!is_numeric($numaction)) {
5820 return img_picto($titlealt, (empty($picto) ?
'stcomm'.$numaction.
'.png' : $picto), $moreatt);
5830function img_pdf($titlealt =
'default', $size = 3)
5834 if ($titlealt ==
'default') {
5835 $titlealt = $langs->trans(
'Show');
5838 return img_picto($titlealt,
'pdf'.$size.
'.png');
5848function img_edit_add($titlealt =
'default', $other =
'')
5852 if ($titlealt ==
'default') {
5853 $titlealt = $langs->trans(
'Add');
5856 return img_picto($titlealt,
'edit_add.png', $other);
5869 if ($titlealt ==
'default') {
5870 $titlealt = $langs->trans(
'Remove');
5873 return img_picto($titlealt,
'edit_remove.png', $other);
5884function img_edit($titlealt =
'default', $float = 0, $other =
'')
5888 if ($titlealt ==
'default') {
5889 $titlealt = $langs->trans(
'Modify');
5892 return img_picto($titlealt,
'edit.png', ($float ?
'style="float: '.($langs->tab_translate[
"DIRECTION"] ==
'rtl' ?
'left' :
'right').
'"' :
"").($other ?
' '.$other :
''));
5903function img_view($titlealt =
'default', $float = 0, $other =
'class="valignmiddle"')
5907 if ($titlealt ==
'default') {
5908 $titlealt = $langs->trans(
'View');
5911 $moreatt = ($float ?
'style="float: right" ' :
'').$other;
5913 return img_picto($titlealt,
'eye', $moreatt);
5924function img_delete($titlealt =
'default', $other =
'class="pictodelete"', $morecss =
'')
5928 if ($titlealt ==
'default') {
5929 $titlealt = $langs->trans(
'Delete');
5932 return img_picto($titlealt,
'delete.png', $other, 0, 0, 0,
'', $morecss);
5942function img_printer($titlealt =
"default", $other =
'')
5945 if ($titlealt ==
"default") {
5946 $titlealt = $langs->trans(
"Print");
5948 return img_picto($titlealt,
'printer.png', $other);
5958function img_split($titlealt =
'default', $other =
'class="pictosplit"')
5962 if ($titlealt ==
'default') {
5963 $titlealt = $langs->trans(
'Split');
5966 return img_picto($titlealt,
'split.png', $other);
5976function img_help($usehelpcursor = 1, $usealttitle = 1)
5981 if (is_string($usealttitle)) {
5984 $usealttitle = $langs->trans(
'Info');
5988 return img_picto($usealttitle,
'info.png',
'style="vertical-align: middle;'.($usehelpcursor == 1 ?
' cursor: help' : ($usehelpcursor == 2 ?
' cursor: pointer' :
'')).
'"');
5997function img_info($titlealt =
'default')
6001 if ($titlealt ==
'default') {
6002 $titlealt = $langs->trans(
'Informations');
6005 return img_picto($titlealt,
'info.png',
'style="vertical-align: middle;"');
6016function img_warning($titlealt =
'default', $moreatt =
'', $morecss =
'pictowarning')
6020 if ($titlealt ==
'default') {
6021 $titlealt = $langs->trans(
'Warning');
6025 return img_picto($titlealt,
'warning.png',
'class="'.$morecss.
'"'.($moreatt ? ($moreatt ==
'1' ?
' style="float: right"' :
' '.$moreatt) :
''));
6034function img_error($titlealt =
'default')
6038 if ($titlealt ==
'default') {
6039 $titlealt = $langs->trans(
'Error');
6042 return img_picto($titlealt,
'error.png');
6052function img_next($titlealt =
'default', $moreatt =
'')
6056 if ($titlealt ==
'default') {
6057 $titlealt = $langs->trans(
'Next');
6061 return '<span class="fa fa-chevron-right paddingright paddingleft" title="'.dol_escape_htmltag($titlealt).
'"></span>';
6071function img_previous($titlealt =
'default', $moreatt =
'')
6075 if ($titlealt ==
'default') {
6076 $titlealt = $langs->trans(
'Previous');
6080 return '<span class="fa fa-chevron-left paddingright paddingleft" title="'.dol_escape_htmltag($titlealt).
'"></span>';
6091function img_down($titlealt =
'default', $selected = 0, $moreclass =
'')
6095 if ($titlealt ==
'default') {
6096 $titlealt = $langs->trans(
'Down');
6099 return img_picto($titlealt, ($selected ?
'1downarrow_selected.png' :
'1downarrow.png'),
'class="imgdown'.($moreclass ?
" ".$moreclass :
"").
'"');
6110function img_up($titlealt =
'default', $selected = 0, $moreclass =
'')
6114 if ($titlealt ==
'default') {
6115 $titlealt = $langs->trans(
'Up');
6118 return img_picto($titlealt, ($selected ?
'1uparrow_selected.png' :
'1uparrow.png'),
'class="imgup'.($moreclass ?
" ".$moreclass :
"").
'"');
6129function img_left($titlealt =
'default', $selected = 0, $moreatt =
'')
6133 if ($titlealt ==
'default') {
6134 $titlealt = $langs->trans(
'Left');
6137 return img_picto($titlealt, ($selected ?
'1leftarrow_selected.png' :
'1leftarrow.png'), $moreatt);
6148function img_right($titlealt =
'default', $selected = 0, $moreatt =
'')
6152 if ($titlealt ==
'default') {
6153 $titlealt = $langs->trans(
'Right');
6156 return img_picto($titlealt, ($selected ?
'1rightarrow_selected.png' :
'1rightarrow.png'), $moreatt);
6166function img_allow($allow, $titlealt =
'default')
6170 if ($titlealt ==
'default') {
6171 $titlealt = $langs->trans(
'Active');
6175 return img_picto($titlealt,
'tick.png');
6190 if (is_null($morecss)) {
6194 if ($brand ==
'visa' || $brand ==
'Visa') {
6196 } elseif ($brand ==
'mastercard' || $brand ==
'MasterCard') {
6197 $brand =
'cc-mastercard';
6198 } elseif ($brand ==
'amex' || $brand ==
'American Express') {
6200 } elseif ($brand ==
'discover' || $brand ==
'Discover') {
6201 $brand =
'cc-discover';
6202 } elseif ($brand ==
'jcb' || $brand ==
'JCB') {
6204 } elseif ($brand ==
'diners' || $brand ==
'Diners club') {
6205 $brand =
'cc-diners-club';
6206 } elseif (!in_array($brand, array(
'cc-visa',
'cc-mastercard',
'cc-amex',
'cc-discover',
'cc-jcb',
'cc-diners-club'))) {
6207 $brand =
'credit-card';
6210 return '<span class="fa fa-'.$brand.
' fa-fw'.($morecss ?
' '.$morecss :
'').
'"></span>';
6221function img_mime($file, $titlealt =
'', $morecss =
'')
6223 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
6229 if (empty($titlealt)) {
6230 $titlealt =
'Mime type: '.$mimetype;
6234 return '<i class="fa fa-'.$mimefa.
' '.(preg_match(
'/pictofixedwidth/', $morecss) ?
'' :
'paddingright ').($morecss ?
' '.$morecss :
'').
'"'.($titlealt ?
' title="'.
dolPrintHTMLForAttribute($titlealt).
'"' :
'').
'></i>';
6245function img_search($titlealt =
'default', $other =
'')
6249 if ($titlealt ==
'default') {
6250 $titlealt = $langs->trans(
'Search');
6253 $img =
img_picto($titlealt,
'search.png', $other, 0, 1);
6255 $input =
'<input type="image" class="liste_titre" name="button_search" src="'.$img.
'" ';
6256 $input .=
'value="'.dol_escape_htmltag($titlealt).
'" title="'.
dol_escape_htmltag($titlealt).
'" >';
6272 if ($titlealt ==
'default') {
6273 $titlealt = $langs->trans(
'Search');
6276 $img =
img_picto($titlealt,
'searchclear.png', $other, 0, 1);
6278 $input =
'<input type="image" class="liste_titre" name="button_removefilter" src="'.$img.
'" ';
6279 $input .=
'value="'.dol_escape_htmltag($titlealt).
'" title="'.
dol_escape_htmltag($titlealt).
'" >';
6296function info_admin($text, $infoonimgalt = 0, $nodiv = 0, $admin =
'1', $morecss =
'hideonsmartphone', $textfordropdown =
'', $picto =
'')
6298 global
$conf, $langs;
6300 if ($infoonimgalt) {
6301 $result =
img_picto($text,
'info',
'class="'.($morecss ?
' '.$morecss :
'').
'"');
6303 if (empty(
$conf->use_javascript_ajax)) {
6304 $textfordropdown =
'';
6307 $class = (empty($admin) ?
'undefined' : ($admin ==
'1' ?
'info' : $admin));
6308 $fa =
'info-circle';
6309 if ($picto ==
'warning') {
6310 $fa =
'exclamation-triangle';
6312 $result = ($nodiv ?
'' :
'<div class="wordbreak '.$class.($morecss ?
' '.$morecss :
'').($textfordropdown ?
' hidden' :
'').
'">').
'<span class="fa fa-'.$fa.
'" title="'.
dol_escape_htmltag($admin ? $langs->trans(
'InfoAdmin') : $langs->trans(
'Note')).
'"></span> ';
6314 $result .= ($nodiv ?
'' :
'</div>');
6316 if ($textfordropdown) {
6317 $tmpresult =
'<span class="'.$class.
'text opacitymedium cursorpointer">'.$langs->trans($textfordropdown).
' '.
img_picto($langs->trans($textfordropdown),
'1downarrow').
'</span>';
6318 $tmpresult .=
'<script nonce="'.getNonce().
'" type="text/javascript">
6319 jQuery(document).ready(function() {
6320 jQuery(".'.$class.
'text").click(function() {
6321 console.log("toggle text");
6322 jQuery(".'.$class.
'").toggle();
6327 $result = $tmpresult.$result;
6348 global
$conf, $langs, $user, $argv;
6349 global $dolibarr_main_prod;
6356 require_once DOL_DOCUMENT_ROOT.
'/core/class/translate.class.php';
6358 $langs->load(
"main");
6362 $langs->loadLangs(array(
'main',
'errors'));
6364 if ($_SERVER[
'DOCUMENT_ROOT']) {
6365 $out .= $langs->trans(
"DolibarrHasDetectedError").
".<br>\n";
6367 $out .=
"You use an experimental or develop level of features, so please do NOT report any bugs or vulnerability, except if problem is confirmed after moving option MAIN_FEATURES_LEVEL back to 0.<br>\n";
6369 $out .= $langs->trans(
"InformationToHelpDiagnose").
":<br>\n";
6371 $out .=
"<b>".$langs->trans(
"Date").
":</b> ".
dol_print_date(time(),
'dayhourlog').
"<br>\n";
6372 $out .=
"<b>".$langs->trans(
"Dolibarr").
":</b> ".DOL_VERSION.
" - https://www.dolibarr.org<br>\n";
6373 if (isset(
$conf->global->MAIN_FEATURES_LEVEL)) {
6374 $out .=
"<b>".$langs->trans(
"LevelOfFeature").
":</b> ".
getDolGlobalInt(
'MAIN_FEATURES_LEVEL').
"<br>\n";
6376 if ($user instanceof
User) {
6377 $out .=
"<b>".$langs->trans(
"Login").
":</b> ".$user->login.
"<br>\n";
6379 if (function_exists(
"phpversion")) {
6380 $out .=
"<b>".$langs->trans(
"PHP").
":</b> ".phpversion().
"<br>\n";
6382 $out .=
"<b>".$langs->trans(
"Server").
":</b> ".(isset($_SERVER[
"SERVER_SOFTWARE"]) ?
dol_htmlentities($_SERVER[
"SERVER_SOFTWARE"], ENT_COMPAT) :
'').
"<br>\n";
6383 if (function_exists(
"php_uname")) {
6384 $out .=
"<b>".$langs->trans(
"OS").
":</b> ".php_uname().
"<br>\n";
6386 $out .=
"<b>".$langs->trans(
"UserAgent").
":</b> ".(isset($_SERVER[
"HTTP_USER_AGENT"]) ?
dol_htmlentities($_SERVER[
"HTTP_USER_AGENT"], ENT_COMPAT) :
'').
"<br>\n";
6388 $out .=
"<b>" . $langs->trans(
"RequestedUrl") .
":</b> " . (isset($_SERVER[
"REQUEST_URI"]) ?
dol_htmlentities($_SERVER[
"REQUEST_URI"], ENT_COMPAT) :
'') .
"<br>\n";
6389 $out .=
"<b>" . $langs->trans(
"Referer") .
":</b> " . (isset($_SERVER[
"HTTP_REFERER"]) ?
dol_htmlentities($_SERVER[
"HTTP_REFERER"], ENT_COMPAT) :
'') .
"<br>\n";
6390 $out .=
"<b>" . $langs->trans(
"MenuManager") .
":</b> " . (isset(
$conf->standard_menu) ?
dol_htmlentities(
$conf->standard_menu, ENT_COMPAT) :
'') .
"<br>\n";
6392 $syslog .=
"url=" . (isset($_SERVER[
"REQUEST_URI"]) ?
dol_escape_htmltag($_SERVER[
"REQUEST_URI"]) :
'');
6393 $syslog .=
", query_string=" . (isset($_SERVER[
"QUERY_STRING"]) ?
dol_escape_htmltag($_SERVER[
"QUERY_STRING"]) :
'');
6395 $out .=
'> '.$langs->transnoentities(
"ErrorInternalErrorDetected").
":\n".$argv[0].
"\n";
6396 $syslog .=
"pid=".dol_getmypid();
6399 if (!empty(
$conf->modules)) {
6400 $out .=
"<b>".$langs->trans(
"Modules").
":</b> ".implode(
', ',
$conf->modules).
"<br>\n";
6403 if (is_object($db)) {
6404 if ($_SERVER[
'DOCUMENT_ROOT']) {
6405 $out .=
"<b>".$langs->trans(
"DatabaseTypeManager").
":</b> ".$db->type.
"<br>\n";
6406 $lastqueryerror = $db->lastqueryerror();
6408 $lastqueryerror =
"SQL error string is not a valid UTF8 string. We can't show it.";
6410 $out .=
"<b>".$langs->trans(
"RequestLastAccessInError").
":</b> ".($lastqueryerror ?
dol_escape_htmltag($lastqueryerror) : $langs->trans(
"ErrorNoRequestInError")).
"<br>\n";
6411 $out .=
"<b>".$langs->trans(
"ReturnCodeLastAccessInError").
":</b> ".($db->lasterrno() ?
dol_escape_htmltag($db->lasterrno()) : $langs->trans(
"ErrorNoRequestInError")).
"<br>\n";
6412 $out .=
"<b>".$langs->trans(
"InformationLastAccessInError").
":</b> ".($db->lasterror() ?
dol_escape_htmltag($db->lasterror()) : $langs->trans(
"ErrorNoRequestInError")).
"<br>\n";
6416 $out .=
'> '.$langs->transnoentities(
"DatabaseTypeManager").
":\n".$db->type.
"\n";
6417 $out .=
'> '.$langs->transnoentities(
"RequestLastAccessInError").
":\n".($db->lastqueryerror() ? $db->lastqueryerror() : $langs->transnoentities(
"ErrorNoRequestInError")).
"\n";
6418 $out .=
'> '.$langs->transnoentities(
"ReturnCodeLastAccessInError").
":\n".($db->lasterrno() ? $db->lasterrno() : $langs->transnoentities(
"ErrorNoRequestInError")).
"\n";
6419 $out .=
'> '.$langs->transnoentities(
"InformationLastAccessInError").
":\n".($db->lasterror() ? $db->lasterror() : $langs->transnoentities(
"ErrorNoRequestInError")).
"\n";
6421 $syslog .=
", sql=".$db->lastquery();
6422 $syslog .=
", db_error=".$db->lasterror();
6425 if ($error || $errors) {
6427 if (is_array($error) && is_array($errors)) {
6428 $errors = array_merge($error, $errors);
6429 } elseif (is_array($error)) {
6431 } elseif (is_array($errors) && !empty($error)) {
6432 $errors = array_merge(array($error), $errors);
6433 } elseif (!empty($error)) {
6434 $errors = array_merge(array($error), array($errors));
6437 $langs->load(
"errors");
6439 foreach ($errors as $msg) {
6443 if ($_SERVER[
'DOCUMENT_ROOT']) {
6446 $out .=
'> '.$langs->transnoentities(
"Message").
":\n".$msg.
"\n";
6448 $syslog .=
", msg=".$msg;
6451 if (empty($dolibarr_main_prod) && $_SERVER[
'DOCUMENT_ROOT'] && function_exists(
'xdebug_print_function_stack') && function_exists(
'xdebug_call_file')) {
6452 xdebug_print_function_stack();
6453 $out .=
'<b>XDebug information:</b>'.
"<br>\n";
6454 $out .=
'File: '.xdebug_call_file().
"<br>\n";
6455 $out .=
'Line: '.xdebug_call_line().
"<br>\n";
6456 $out .=
'Function: '.xdebug_call_function().
"<br>\n";
6461 if (!headers_sent()) {
6462 if (function_exists(
'top_httphead')) {
6466 http_response_code(202);
6469 if (empty($dolibarr_main_prod)) {
6472 if (empty($langs->defaultlang)) {
6473 $langs->setDefaultLang();
6475 $langs->loadLangs(array(
"main",
"errors"));
6477 print
'This website or feature is currently temporarily not available or failed after a technical error.<br><br>This may be due to a maintenance operation. Current status of operation ('.dol_print_date(
dol_now(),
'dayhourrfc').
') are on next line...<br><br>'.
"\n";
6478 print $langs->trans(
"DolibarrHasDetectedError").
'. ';
6479 print $langs->trans(
"YouCanSetOptionDolibarrMainProdToZero");
6480 if (!defined(
"MAIN_CORE_ERROR")) {
6481 define(
"MAIN_CORE_ERROR", 1);
6498function dol_print_error_email($prefixcode, $errormessage =
'', $errormessages = array(), $morecss =
'error', $email =
'')
6502 if (empty($email)) {
6506 $langs->load(
"errors");
6509 print
'<br><div class="center login_main_message"><div class="'.$morecss.
'">';
6510 print $langs->trans(
"ErrorContactEMail", $email, $prefixcode.
'-'.
dol_print_date($now,
'%Y%m%d%H%M%S'));
6511 if ($errormessage) {
6512 print
'<br><br>'.$errormessage;
6514 if (is_array($errormessages) && count($errormessages)) {
6515 foreach ($errormessages as $mesgtoshow) {
6516 print
'<br><br>'.$mesgtoshow;
6519 print
'</div></div>';
6538function print_liste_field_titre($name, $file =
"", $field =
"", $begin =
"", $param =
"", $moreattrib =
"", $sortfield =
"", $sortorder =
"", $prefix =
"", $tooltip =
"", $forcenowrapcolumntitle = 0)
6540 print
getTitleFieldOfList($name, 0, $file, $field, $begin, $param, $moreattrib, $sortfield, $sortorder, $prefix, 0, $tooltip, $forcenowrapcolumntitle);
6561function getTitleFieldOfList($name, $thead = 0, $file =
"", $field =
"", $begin =
"", $moreparam =
"", $moreattrib =
"", $sortfield =
"", $sortorder =
"", $prefix =
"", $disablesortlink = 0, $tooltip =
'', $forcenowrapcolumntitle = 0)
6563 global $langs, $form;
6566 if ($moreattrib ==
'class="right"') {
6567 $prefix .=
'right ';
6570 $sortorder = strtoupper((
string) $sortorder);
6579 $tmpsortfield = explode(
',', (
string) $sortfield);
6580 $sortfield1 = trim($tmpsortfield[0]);
6581 $tmpfield = explode(
',', $field);
6582 $field1 = trim($tmpfield[0]);
6584 if (!
getDolGlobalString(
'MAIN_DISABLE_WRAPPING_ON_COLUMN_TITLE') && empty($forcenowrapcolumntitle)) {
6585 $prefix =
'wrapcolumntitle '.$prefix;
6591 $liste_titre =
'liste_titre';
6592 if ($field1 && ($sortfield1 == $field1 || $sortfield1 == preg_replace(
"/^[^\.]+\./",
"", $field1))) {
6593 $liste_titre =
'liste_titre_sel';
6596 $tagstart =
'<'.$tag.
' class="'.$prefix.$liste_titre.
'" '.$moreattrib;
6601 if (empty($thead) && $field && empty($disablesortlink)) {
6602 $options = preg_replace(
'/sortfield=([a-zA-Z0-9,\s\.]+)/i',
'', (is_scalar($moreparam) ? $moreparam :
''));
6603 $options = preg_replace(
'/sortorder=([a-zA-Z0-9,\s\.]+)/i',
'', $options);
6604 $options = preg_replace(
'/&+/i',
'&', $options);
6605 if (!preg_match(
'/^&/', $options)) {
6606 $options =
'&'.$options;
6609 $sortordertouseinlink =
'';
6610 if ($field1 != $sortfield1) {
6611 if (preg_match(
'/^DESC/i', $sortorder)) {
6612 $sortordertouseinlink .= str_repeat(
'desc,', count(explode(
',', $field)));
6614 $sortordertouseinlink .= str_repeat(
'asc,', count(explode(
',', $field)));
6617 if (preg_match(
'/^ASC/i', $sortorder)) {
6618 $sortordertouseinlink .= str_repeat(
'desc,', count(explode(
',', $field)));
6620 $sortordertouseinlink .= str_repeat(
'asc,', count(explode(
',', $field)));
6623 $sortordertouseinlink = preg_replace(
'/,$/',
'', $sortordertouseinlink);
6624 $out .=
'<a class="reposition" href="'.$file.
'?sortfield='.urlencode($field).
'&sortorder='.urlencode($sortordertouseinlink).
'&begin='.urlencode($begin).$options.
'"';
6630 if (strpos($tooltip,
':') !==
false) {
6631 $tmptooltip = explode(
':', $tooltip);
6633 $tmptooltip = array($tooltip);
6635 $out .= $form->textwithpicto($langs->trans((
string) $name), $langs->trans($tmptooltip[0]), (empty($tmptooltip[2]) ?
'1' : $tmptooltip[2]),
'help',
'', 0, 3, (empty($tmptooltip[1]) ?
'' :
'extra_'.str_replace(
'.',
'_', $field).
'_'.$tmptooltip[1]));
6637 $out .= $langs->trans((
string) $name);
6640 if (empty($thead) && $field && empty($disablesortlink)) {
6644 if (empty($thead) && $field) {
6645 $options = preg_replace(
'/sortfield=([a-zA-Z0-9,\s\.]+)/i',
'', (is_scalar($moreparam) ? $moreparam :
''));
6646 $options = preg_replace(
'/sortorder=([a-zA-Z0-9,\s\.]+)/i',
'', $options);
6647 $options = preg_replace(
'/&+/i',
'&', $options);
6648 if (!preg_match(
'/^&/', $options)) {
6649 $options =
'&'.$options;
6652 if (!$sortorder || ($field1 != $sortfield1)) {
6655 if (preg_match(
'/^DESC/', $sortorder)) {
6656 $sortimg .=
'<span class="nowrap">'.img_up(
"Z-A", 0,
'paddingright').
'</span>';
6658 if (preg_match(
'/^ASC/', $sortorder)) {
6659 $sortimg .=
'<span class="nowrap">'.img_down(
"A-Z", 0,
'paddingright').
'</span>';
6664 $tagend =
'</'.$tag.
'>';
6666 $out = $tagstart.$sortimg.$out.$tagend;
6681 dol_syslog(__FUNCTION__.
" is deprecated", LOG_WARNING);
6683 print
'<div class="titre">'.$title.
'</div>';
6697function print_fiche_titre($title, $mesg =
'', $picto =
'generic', $pictoisfullpath = 0,
$id =
'')
6715function load_fiche_titre($title, $morehtmlright =
'', $picto =
'generic', $pictoisfullpath = 0,
$id =
'', $morecssontable =
'', $morehtmlcenter =
'')
6719 if ($picto ==
'setup') {
6724 $return .=
'<table '.($id ?
'id="'.$id.
'" ' :
'').
'class="centpercent notopnoleftnoright table-fiche-title'.($morecssontable ?
' '.$morecssontable :
'').
'">';
6725 $return .=
'<tr class="toptitle">';
6727 $return .=
'<td class="nobordernopadding widthpictotitle valignmiddle col-picto">'.img_picto(
'', $picto,
'class="valignmiddle widthpictotitle pictotitle"', $pictoisfullpath).
'</td>';
6729 $return .=
'<td class="nobordernopadding valignmiddle col-title">';
6730 $return .=
'<div class="titre inline-block">';
6731 $return .=
'<span class="inline-block valignmiddle">'.$title.
'</span>';
6732 $return .=
'</div>';
6735 $return .=
'<td class="nobordernopadding center valignmiddle col-center">'.$morehtmlcenter.
'</td>';
6738 $return .=
'<td class="nobordernopadding titre_right wordbreakimp right valignmiddle col-right">'.$morehtmlright.
'</td>';
6740 $return .=
'</tr></table>'.
"\n";
6768function print_barre_liste($title, $page, $file, $options =
'', $sortfield =
'', $sortorder =
'', $morehtmlcenter =
'', $num = -1, $totalnboflines =
'', $picto =
'generic', $pictoisfullpath = 0, $morehtmlright =
'', $morecss =
'', $limit = -1, $selectlimitsuffix = 0, $hidenavigation = 0, $pagenavastextinput = 0, $morehtmlrightbeforearrow =
'')
6770 global
$conf, $langs;
6773 $savtotalnboflines = $totalnboflines;
6774 if (is_numeric($totalnboflines)) {
6775 $totalnboflines = abs($totalnboflines);
6780 $tmparray = preg_split(
'/<br>/i', $title, 2);
6781 if (!empty($tmparray[1])) {
6782 $title = $tmparray[0];
6783 $subtitle = $tmparray[1];
6786 $page = (int) $page;
6788 if ($picto ==
'setup') {
6789 $picto =
'title_setup.png';
6791 if ((
$conf->browser->name ==
'ie') && $picto ==
'generic') {
6792 $picto =
'title.gif';
6795 $limit =
$conf->liste_limit;
6798 if ($savlimit != 0 && (($num > $limit) || ($num == -1) || ($limit == 0))) {
6806 print
"<!-- Begin print_barre_liste -->\n";
6807 print
'<table class="centpercent notopnoleftnoright table-fiche-title'.($morecss ?
' '.$morecss :
'').
'">';
6808 print
'<tr class="toptitle">';
6812 if ($picto && $title) {
6813 print
'<td class="nobordernopadding widthpictotitle valignmiddle col-picto">';
6814 print
img_picto(
'', $picto,
'class="valignmiddle pictotitle widthpictotitle"', $pictoisfullpath);
6818 print
'<td class="nobordernopadding valignmiddle col-title">';
6819 print
'<div class="titre inline-block">';
6820 print
'<span class="inline-block valignmiddle print-barre-liste">'.$title.
'</span>';
6821 if (!empty($title) && $savtotalnboflines >= 0 && (
string) $savtotalnboflines !=
'' && $totalnboflines > 0) {
6822 print
'<span class="opacitymedium colorblack marginleftonly totalnboflines valignmiddle" title="'.$langs->trans(
"NbRecordQualified").
'">('.$totalnboflines.
')</span>';
6825 if (!empty($subtitle)) {
6826 print
'<br><div class="subtitle inline-block hideonsmartphone">'.$subtitle.
'</div>';
6831 if ($morehtmlcenter && empty(
$conf->dol_optimize_smallscreen)) {
6832 print
'<td class="nobordernopadding center valignmiddle col-center">'.$morehtmlcenter.
'</td>';
6836 print
'<td class="nobordernopadding valignmiddle right col-right">';
6837 print
'<input type="hidden" name="pageplusoneold" value="'.((int) $page + 1).
'">';
6839 $options .=
"&sortfield=".urlencode($sortfield);
6842 $options .=
"&sortorder=".urlencode($sortorder);
6846 if ($savlimit != 0 && ($page > 0 || $num > $limit)) {
6847 if ($totalnboflines) {
6849 $maxnbofpage = (empty(
$conf->dol_optimize_smallscreen) ? 4 : 0);
6852 $nbpages = ceil($totalnboflines / $limit);
6856 $cpt = ($page - $maxnbofpage);
6862 if (empty($pagenavastextinput)) {
6863 $pagelist .=
'<li class="pagination"><a class="reposition" href="'.$file.
'?page=0'.$options.
'">1</a></li>';
6865 $pagelist .=
'<li class="pagination"><span class="inactive">...</span></li>';
6866 } elseif ($cpt == 2) {
6867 $pagelist .=
'<li class="pagination"><a class="reposition" href="'.$file.
'?page=1'.$options.
'">2</a></li>';
6873 if ($pagenavastextinput) {
6874 if ($cpt == $page) {
6875 $pagelist .=
'<li class="pagination pageplusone valignmiddle"><input type="text" class="'.($totalnboflines > 100 ?
'width40' :
'width25').
' center pageplusone heightofcombo" name="pageplusone" value="'.($page + 1).
'"></li>';
6879 if ($cpt == $page) {
6880 $pagelist .=
'<li class="pagination"><span class="active">'.($page + 1).
'</span></li>';
6882 $pagelist .=
'<li class="pagination"><a class="reposition" href="'.$file.
'?page='.$cpt.$options.
'">'.($cpt + 1).
'</a></li>';
6886 }
while ($cpt < $nbpages && $cpt <= ($page + $maxnbofpage));
6888 if (empty($pagenavastextinput)) {
6889 if ($cpt < $nbpages) {
6890 if ($cpt < $nbpages - 2) {
6891 $pagelist .=
'<li class="pagination"><span class="inactive">...</span></li>';
6892 } elseif ($cpt == $nbpages - 2) {
6893 $pagelist .=
'<li class="pagination"><a class="reposition" href="'.$file.
'?page='.($nbpages - 2).$options.
'">'.($nbpages - 1).
'</a></li>';
6895 $pagelist .=
'<li class="pagination"><a class="reposition" href="'.$file.
'?page='.($nbpages - 1).$options.
'">'.$nbpages.
'</a></li>';
6899 $pagelist .=
'<li class="pagination paginationlastpage"><a class="reposition" href="'.$file.
'?page='.($nbpages - 1).$options.
'">'.$nbpages.
'</a></li>';
6902 $pagelist .=
'<li class="pagination"><span class="active">'.($page + 1).
"</li>";
6906 if ($savlimit || $morehtmlright || $morehtmlrightbeforearrow) {
6907 print_fleche_navigation($page, $file, $options, $nextpage, $pagelist, $morehtmlright, $savlimit, $totalnboflines, $selectlimitsuffix, $morehtmlrightbeforearrow, $hidenavigation);
6911 if ($pagenavastextinput) {
6918 print
'</table>'.
"\n";
6921 if ($morehtmlcenter && !empty(
$conf->dol_optimize_smallscreen)) {
6922 print
'<div class="nobordernopadding marginbottomonly center valignmiddle col-center centpercent">'.$morehtmlcenter.
'</div>';
6925 print
"<!-- End title -->\n\n";
6944function print_fleche_navigation($page, $file, $options =
'', $nextpage = 0, $betweenarrows =
'', $afterarrows =
'', $limit = -1, $totalnboflines = 0, $selectlimitsuffix =
'', $beforearrows =
'', $hidenavigation = 0)
6946 global
$conf, $langs;
6948 print
'<div class="pagination"><ul>';
6949 if ($beforearrows) {
6950 print
'<li class="paginationbeforearrows">';
6951 print $beforearrows;
6955 if (empty($hidenavigation)) {
6956 if ((
int) $limit > 0 && (empty($selectlimitsuffix) || !is_numeric($selectlimitsuffix))) {
6957 $pagesizechoices =
'10:10,15:15,20:20,25:25,50:50,100:100,250:250,500:500,1000:1000';
6958 $pagesizechoices .=
',5000:5000';
6968 print
'<li class="pagination">';
6969 print
'<input onfocus="this.value=null;" onchange="this.blur();" class="flat selectlimit nopadding maxwidth75 right pageplusone" id="limit" name="limit" list="limitlist" title="'.dol_escape_htmltag($langs->trans(
"MaxNbOfRecordPerPage")).
'" value="'.$limit.
'">';
6970 print
'<datalist id="limitlist">';
6972 print
'<li class="paginationcombolimit valignmiddle">';
6973 print
'<select id="limit'.(is_numeric($selectlimitsuffix) ?
'' : $selectlimitsuffix).
'" name="limit" class="flat selectlimit nopadding maxwidth75 center'.(is_numeric($selectlimitsuffix) ?
'' :
' '.$selectlimitsuffix).
'" title="'.
dol_escape_htmltag($langs->trans(
"MaxNbOfRecordPerPage")).
'">';
6975 $tmpchoice = explode(
',', $pagesizechoices);
6976 $tmpkey = $limit.
':'.$limit;
6977 if (!in_array($tmpkey, $tmpchoice)) {
6978 $tmpchoice[$tmpkey] = $tmpkey;
6980 $tmpkey =
$conf->liste_limit.
':'.
$conf->liste_limit;
6981 if (!in_array($tmpkey, $tmpchoice)) {
6982 $tmpchoice[$tmpkey] = $tmpkey;
6984 asort($tmpchoice, SORT_NUMERIC);
6985 foreach ($tmpchoice as $val) {
6987 $tmp = explode(
':', $val);
6990 if ($key !=
'' && $val !=
'') {
6991 if ((
int) $key == (
int) $limit) {
6992 $selected =
' selected="selected"';
6994 print
'<option name="'.$key.
'"'.$selected.
'>'.
dol_escape_htmltag($val).
'</option>'.
"\n";
6998 print
'</datalist>';
7001 print
ajax_combobox(
"limit".(is_numeric($selectlimitsuffix) ?
'' : $selectlimitsuffix), array(), 0, 0,
'resolve',
'-1',
'limit');
7005 if (
$conf->use_javascript_ajax) {
7006 print
'<!-- JS CODE TO ENABLE select limit to launch submit of page -->
7008 jQuery(document).ready(function () {
7009 jQuery(".selectlimit").change(function() {
7010 console.log("We change limit so we submit the form");
7011 $(this).parents(\'form:first\').submit();
7020 print
'<li class="pagination paginationpage paginationpageleft"><a class="paginationprevious reposition" href="'.$file.
'?page='.($page - 1).$options.
'"><i class="fa fa-chevron-left" title="'.
dol_escape_htmltag($langs->trans(
"Previous")).
'"></i></a></li>';
7022 if ($betweenarrows) {
7023 print
'<!--<div class="betweenarrows nowraponall inline-block">-->';
7024 print $betweenarrows;
7025 print
'<!--</div>-->';
7027 if ($nextpage > 0) {
7028 print
'<li class="pagination paginationpage paginationpageright"><a class="paginationnext reposition" href="'.$file.
'?page='.($page + 1).$options.
'"><i class="fa fa-chevron-right" title="'.
dol_escape_htmltag($langs->trans(
"Next")).
'"></i></a></li>';
7031 print
'<li class="paginationafterarrows">';
7036 print
'</ul></div>'.
"\n";
7051function vatrate($rate, $addpercent =
false, $info_bits = 0, $usestarfornpr = 0, $html = 0)
7055 if (preg_match(
'/%/', $rate)) {
7056 $rate = str_replace(
'%',
'', $rate);
7060 if (preg_match(
'/\((.*)\)/', $rate, $reg)) {
7061 $morelabel =
' ('.$reg[1].
')';
7062 $rate = preg_replace(
'/\s*'.preg_quote($morelabel,
'/').
'/',
'', $rate);
7063 $morelabel =
' '.($html ?
'<span class="opacitymedium">' :
'').
'('.$reg[1].
')'.($html ?
'</span>' :
'');
7065 if (preg_match(
'/\*/', $rate)) {
7066 $rate = str_replace(
'*',
'', $rate);
7071 if (!preg_match(
'/\//', $rate)) {
7072 $ret =
price($rate, 0,
'', 0, 0).($addpercent ?
'%' :
'');
7075 $ret = $rate.($addpercent ?
'%' :
'');
7077 if (($info_bits & 1) && $usestarfornpr >= 0) {
7100function price($amount, $form = 0, $outlangs =
'', $trunc = 1, $rounding = -1, $forcerounding = -1, $currency_code =
'')
7102 global $langs,
$conf;
7105 if (empty($amount)) {
7108 $amount = (is_numeric($amount) ? $amount : 0);
7109 if ($rounding == -1) {
7112 $nbdecimal = $rounding;
7114 if ($outlangs ===
'none') {
7124 if (!($outlangs instanceof
Translate)) {
7128 if ($outlangs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
7129 $dec = $outlangs->transnoentitiesnoconv(
"SeparatorDecimal");
7131 if ($outlangs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
7132 $thousand = $outlangs->transnoentitiesnoconv(
"SeparatorThousand");
7134 if ($thousand ==
'None') {
7136 } elseif ($thousand ==
'Space') {
7143 $amount = str_replace(
',',
'.', $amount);
7145 $data = explode(
'.', $amount);
7146 $decpart = isset($data[1]) ? $data[1] :
'';
7147 $decpart = preg_replace(
'/0+$/i',
'', $decpart);
7157 $nbdecimalmaxshown = (int) str_replace(
'...',
'',
getDolGlobalString(
'MAIN_MAX_DECIMALS_SHOWN'));
7158 if ($trunc && $nbdecimal > $nbdecimalmaxshown) {
7159 $nbdecimal = $nbdecimalmaxshown;
7167 if ((
string) $forcerounding !=
'-1' && (string) $forcerounding !=
'') {
7168 if ($forcerounding ===
'MU') {
7170 } elseif ($forcerounding ===
'MT') {
7172 } elseif ($forcerounding >= 0) {
7173 $nbdecimal = (int) $forcerounding;
7178 $output = number_format((
float) $amount, $nbdecimal, $dec, $thousand);
7180 $cursymbolbefore = $cursymbolafter =
'';
7181 if ($currency_code && is_object($outlangs)) {
7182 if ($currency_code ==
'auto') {
7183 $currency_code =
$conf->currency;
7186 $listofcurrenciesbefore = array(
'AUD',
'CAD',
'CNY',
'COP',
'CLP',
'GBP',
'HKD',
'MXN',
'PEN',
'USD',
'CRC',
'ZAR');
7187 $listoflanguagesbefore = array(
'nl_NL');
7188 if (in_array($currency_code, $listofcurrenciesbefore) || in_array($outlangs->defaultlang, $listoflanguagesbefore)) {
7189 $cursymbolbefore .= $outlangs->getCurrencySymbol($currency_code);
7191 $tmpcur = $outlangs->getCurrencySymbol($currency_code);
7192 $cursymbolafter .= ($tmpcur == $currency_code ?
' '.$tmpcur : $tmpcur);
7195 $output = $cursymbolbefore.$output.$end.($cursymbolafter ?
' ' :
'').$cursymbolafter;
7197 $output = preg_replace(
'/\s/',
' ', $output);
7198 $output = preg_replace(
'/\'/',
''', $output);
7228function price2num($amount, $rounding =
'', $option = 0)
7230 global $langs,
$conf;
7233 if (is_null($amount)) {
7242 if (is_null($langs)) {
7246 if ($langs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
7247 $dec = $langs->transnoentitiesnoconv(
"SeparatorDecimal");
7249 if ($langs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
7250 $thousand = $langs->transnoentitiesnoconv(
"SeparatorThousand");
7253 if ($thousand ==
'None') {
7255 } elseif ($thousand ==
'Space') {
7263 if (!is_numeric($amount)) {
7264 $amount = preg_replace(
'/[a-zA-Z\/\\\*\(\)<>\_]/',
'', $amount);
7267 if ($option == 2 && $thousand ==
'.' && preg_match(
'/\.(\d\d\d)$/', (
string) $amount)) {
7268 $amount = str_replace($thousand,
'', $amount);
7274 if (is_numeric($amount)) {
7276 $temps = sprintf(
"%10.10F", $amount - intval($amount));
7277 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
7279 $amount = number_format($amount, $nbofdec, $dec, $thousand);
7285 if ($thousand !=
',' && $thousand !=
'.') {
7298 if (preg_match(
'/^(?<int>[^,]*,|[^.]*\.)(?<dec>[^.,]*)$/u', $amount, $matches)) {
7299 $intPart = $matches[
'int'];
7300 $decPart = $matches[
'dec'];
7303 $intPart = str_replace([
'.',
','],
'', $intPart);
7306 $amount = $intPart . $dec . $decPart;
7310 $amount = str_replace(
' ',
'', $amount);
7311 $amount = str_replace($thousand,
'', $amount);
7312 $amount = str_replace($dec,
'.', $amount);
7314 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
7320 $nbofdectoround =
'';
7321 if ($rounding ==
'MU') {
7323 } elseif ($rounding ==
'MT') {
7325 } elseif ($rounding ==
'MS') {
7326 $nbofdectoround = isset(
$conf->global->MAIN_MAX_DECIMALS_STOCK) ?
getDolGlobalInt(
'MAIN_MAX_DECIMALS_STOCK') : 5;
7327 } elseif ($rounding ==
'CU') {
7329 } elseif ($rounding ==
'CT') {
7331 } elseif (is_numeric($rounding)) {
7332 $nbofdectoround = (int) $rounding;
7337 $amount = round(is_string($amount) ? (
float) $amount : $amount, $nbofdectoround);
7339 return 'ErrorBadParameterProvidedToFunction';
7345 if (is_numeric($amount)) {
7347 $temps = sprintf(
"%10.10F", $amount - intval($amount));
7348 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
7350 $amount = number_format($amount, min($nbofdec, $nbofdectoround), $dec, $thousand);
7356 if ($thousand !=
',' && $thousand !=
'.') {
7357 $amount = str_replace(
',',
'.', $amount);
7360 $amount = str_replace(
' ',
'', $amount);
7361 $amount = str_replace($thousand,
'', $amount);
7362 $amount = str_replace($dec,
'.', $amount);
7364 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
7382function showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round = -1, $forceunitoutput =
'no', $use_short_label = 0)
7384 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
7386 if (($forceunitoutput ==
'no' && $dimension < 1 / 10000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == -6)) {
7387 $dimension *= 1000000;
7389 } elseif (($forceunitoutput ==
'no' && $dimension < 1 / 10 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == -3)) {
7392 } elseif (($forceunitoutput ==
'no' && $dimension > 100000000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == 6)) {
7393 $dimension /= 1000000;
7395 } elseif (($forceunitoutput ==
'no' && $dimension > 100000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == 3)) {
7412 $ret =
price($dimension, 0, $outputlangs, 0, 0, $round);
7414 $ret .=
' '.measuringUnitString(0, $type, $unit, $use_short_label, $outputlangs);
7432function get_localtax($vatrate, $local, $thirdparty_buyer =
null, $thirdparty_seller =
null, $vatnpr = 0)
7434 global $db,
$conf, $mysoc;
7436 if (empty($thirdparty_seller) || !is_object($thirdparty_seller)) {
7437 $thirdparty_seller = $mysoc;
7440 dol_syslog(
"get_localtax tva=".$vatrate.
" local=".$local.
" thirdparty_buyer id=".(is_object($thirdparty_buyer) ? $thirdparty_buyer->id :
'').
"/country_code=".(is_object($thirdparty_buyer) ? $thirdparty_buyer->country_code :
'').
" thirdparty_seller id=".$thirdparty_seller->id.
"/country_code=".$thirdparty_seller->country_code.
" thirdparty_seller localtax1_assuj=".$thirdparty_seller->localtax1_assuj.
" thirdparty_seller localtax2_assuj=".$thirdparty_seller->localtax2_assuj);
7442 $vatratecleaned = $vatrate;
7444 if (preg_match(
'/^(.*)\s*\((.*)\)$/', (
string) $vatrate, $reg)) {
7445 $vatratecleaned = trim($reg[1]);
7446 $vatratecode = $reg[2];
7455 if ($mysoc->country_code ==
'ES') {
7457 if (!$mysoc->localtax1_assuj || (
string) $vatratecleaned ==
"0") {
7460 if ($thirdparty_seller->id == $mysoc->id) {
7461 if (!$thirdparty_buyer->localtax1_assuj) {
7465 if (!$thirdparty_seller->localtax1_assuj) {
7473 if (!$mysoc->localtax2_assuj) {
7476 if ($thirdparty_seller->id == $mysoc->id) {
7477 if (!$thirdparty_buyer->localtax2_assuj) {
7481 if (!$thirdparty_seller->localtax2_assuj) {
7487 if ($local == 1 && !$thirdparty_seller->localtax1_assuj) {
7490 if ($local == 2 && !$thirdparty_seller->localtax2_assuj) {
7496 if (in_array($mysoc->country_code, array(
'ES'))) {
7497 $conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY = 1;
7503 if ($thirdparty_seller != $mysoc) {
7505 return $thirdparty_seller->localtax1_value;
7514 if ($thirdparty_seller != $mysoc) {
7517 return $thirdparty_seller->localtax2_value;
7520 if (in_array($mysoc->country_code, array(
'ES'))) {
7521 return $thirdparty_buyer->localtax2_value;
7530 $sql =
"SELECT t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
7531 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
7532 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($thirdparty_seller->country_code).
"'";
7533 $sql .=
" AND t.taux = ".((float) $vatratecleaned).
" AND t.active = 1";
7534 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
7535 if (!empty($vatratecode)) {
7536 $sql .=
" AND t.code ='".$db->escape($vatratecode).
"'";
7538 $sql .=
" AND t.recuperableonly = '".$db->escape((
string) $vatnpr).
"'";
7541 $resql = $db->query($sql);
7544 $obj = $db->fetch_object($resql);
7547 return $obj->localtax1;
7548 } elseif ($local == 2) {
7549 return $obj->localtax2;
7570 $valors = explode(
":", $tax);
7572 if (count($valors) > 1) {
7589 $sql =
" SELECT t.localtax".$local.
" as localtax";
7590 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t INNER JOIN ".MAIN_DB_PREFIX.
"c_country as c ON c.rowid = t.fk_pays";
7591 $sql .=
" WHERE c.code = '".$db->escape($mysoc->country_code).
"' AND t.active = 1 AND t.entity IN (".
getEntity(
'c_tva').
") AND t.taux = (";
7592 $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";
7593 $sql .=
" WHERE c.code = '".$db->escape($mysoc->country_code).
"' AND t.entity IN (".
getEntity(
'c_tva').
") AND tt.active = 1)";
7594 $sql .=
" AND t.localtax".$local.
"_type <> '0'";
7595 $sql .=
" ORDER BY t.rowid DESC";
7597 $resql = $db->query($sql);
7599 $obj = $db->fetch_object($resql);
7601 return $obj->localtax;
7622function getTaxesFromId($vatrate, $buyer =
null, $seller =
null, $firstparamisid = 1)
7626 dol_syslog(
"getTaxesFromId vat id or rate = ".$vatrate);
7629 $sql =
"SELECT t.rowid, t.code, t.taux as rate, t.recuperableonly as npr, t.accountancy_code_sell, t.accountancy_code_buy,";
7630 $sql .=
" t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type";
7631 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t";
7632 if ($firstparamisid) {
7633 $sql .=
" WHERE t.rowid = ".(int) $vatrate;
7635 $vatratecleaned = $vatrate;
7638 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
7639 $vatratecleaned = $reg[1];
7640 $vatratecode = $reg[2];
7643 $sql .=
", ".MAIN_DB_PREFIX.
"c_country as c";
7646 $sql .=
" WHERE t.fk_pays = c.rowid";
7648 $sql .=
" AND c.code = '".$db->escape($buyer->country_code).
"'";
7650 $sql .=
" AND c.code = '".$db->escape($seller->country_code).
"'";
7652 $sql .=
" AND t.taux = ".((float) $vatratecleaned).
" AND t.active = 1";
7653 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
7655 $sql .=
" AND t.code = '".$db->escape($vatratecode).
"'";
7659 $resql = $db->query($sql);
7661 $obj = $db->fetch_object($resql);
7664 'rowid' => $obj->rowid,
7665 'code' => $obj->code,
7666 'rate' => $obj->rate,
7667 'localtax1' => $obj->localtax1,
7668 'localtax1_type' => $obj->localtax1_type,
7669 'localtax2' => $obj->localtax2,
7670 'localtax2_type' => $obj->localtax2_type,
7672 'accountancy_code_sell' => $obj->accountancy_code_sell,
7673 'accountancy_code_buy' => $obj->accountancy_code_buy
7705 dol_syslog(
"getLocalTaxesFromRate vatrate=".$vatrate.
" local=".$local);
7708 $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";
7709 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t";
7710 if ($firstparamisid) {
7711 $sql .=
" WHERE t.rowid = ".(int) $vatrate;
7713 $vatratecleaned = $vatrate;
7716 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
7717 $vatratecleaned = $reg[1];
7718 $vatratecode = $reg[2];
7721 $sql .=
", ".MAIN_DB_PREFIX.
"c_country as c";
7722 if (!empty($mysoc) && $mysoc->country_code ==
'ES') {
7723 $countrycodetouse = ((empty($buyer) || empty($buyer->country_code)) ? $mysoc->country_code : $buyer->country_code);
7724 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($countrycodetouse).
"'";
7726 $countrycodetouse = ((empty($seller) || empty($seller->country_code)) ? $mysoc->country_code : $seller->country_code);
7727 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($countrycodetouse).
"'";
7729 $sql .=
" AND t.taux = ".((float) $vatratecleaned).
" AND t.active = 1";
7731 $sql .=
" AND t.code = '".$db->escape($vatratecode).
"'";
7735 $resql = $db->query($sql);
7737 $obj = $db->fetch_object($resql);
7740 $vateratestring = $obj->rate.($obj->code ?
' ('.$obj->code.
')' :
'');
7743 return array($obj->localtax1_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
7744 } elseif ($local == 2) {
7745 return array($obj->localtax2_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
7747 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);
7769 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
7777 $product->fetch($idprod);
7779 if (($mysoc->country_code == $thirdpartytouse->country_code)
7780 || (in_array($mysoc->country_code, array(
'FR',
'MC')) && in_array($thirdpartytouse->country_code, array(
'FR',
'MC')))
7781 || (in_array($mysoc->country_code, array(
'MQ',
'GP')) && in_array($thirdpartytouse->country_code, array(
'MQ',
'GP')))
7784 if ($idprodfournprice > 0) {
7785 $result = $product->get_buyprice($idprodfournprice, 0, 0,
'');
7787 $ret = $product->vatrate_supplier;
7788 if ($product->default_vat_code_supplier) {
7789 $ret .=
' ('.$product->default_vat_code_supplier.
')';
7795 $ret = $product->tva_tx;
7796 if ($product->default_vat_code) {
7797 $ret .=
' ('.$product->default_vat_code.
')';
7810 $sql =
"SELECT t.taux as vat_rate, t.code as default_vat_code";
7811 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
7812 $sql .=
" WHERE t.active = 1 AND t.fk_pays = c.rowid AND c.code = '".$db->escape($thirdpartytouse->country_code).
"'";
7813 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
7814 $sql .=
" ORDER BY t.use_default DESC, t.taux DESC, t.code ASC, t.recuperableonly ASC";
7815 $sql .= $db->plimit(1);
7817 $resql = $db->query($sql);
7819 $obj = $db->fetch_object($resql);
7821 $ret = $obj->vat_rate;
7822 if ($obj->default_vat_code) {
7823 $ret .=
' ('.$obj->default_vat_code.
')';
7847 dol_syslog(
"get_product_vat_for_country: ret=".$ret);
7864 if (!class_exists(
'Product')) {
7865 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
7874 $result = $product->fetch($idprod);
7876 if ($mysoc->country_code == $thirdpartytouse->country_code) {
7890 $sql =
"SELECT taux as vat_rate, localtax1, localtax2";
7891 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
7892 $sql .=
" WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code='".$db->escape($thirdpartytouse->country_code).
"'";
7893 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
7894 $sql .=
" ORDER BY t.taux DESC, t.recuperableonly ASC";
7895 $sql .= $db->plimit(1);
7897 $resql = $db->query($sql);
7899 $obj = $db->fetch_object($resql);
7902 $ret = $obj->localtax1;
7903 } elseif ($local == 2) {
7904 $ret = $obj->localtax2;
7912 dol_syslog(
"get_product_localtax_for_country: ret=".$ret);
7937 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
7940 $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;
7942 if (empty($thirdparty_seller->country_code)) {
7943 $thirdparty_seller->country_code = $mysoc->country_code;
7945 $seller_country_code = $thirdparty_seller->country_code;
7946 $seller_in_cee =
isInEEC($thirdparty_seller);
7948 if (empty($thirdparty_buyer->country_code)) {
7949 $thirdparty_buyer->country_code = $mysoc->country_code;
7951 $buyer_country_code = $thirdparty_buyer->country_code;
7952 $buyer_in_cee =
isInEEC($thirdparty_buyer);
7954 dol_syslog(
"get_default_tva: seller use vat=".$seller_use_vat.
", seller country=".$seller_country_code.
", seller in cee=".((
string) (
int) $seller_in_cee).
", 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).
", idprod=".$idprod.
", idprodfournprice=".$idprodfournprice.
", SERVICE_ARE_ECOMMERCE_200238EC=".
getDolGlobalString(
'SERVICE_ARE_ECOMMERCE_200238EC'));
7959 if ($seller_in_cee && $buyer_in_cee) {
7960 $isacompany = $thirdparty_buyer->isACompany();
7961 if ($isacompany &&
getDolGlobalString(
'MAIN_USE_VAT_COMPANIES_IN_EEC_WITH_INVALID_VAT_ID_ARE_INDIVIDUAL')) {
7962 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
7976 if (!$seller_use_vat) {
7982 if (!empty($thirdparty_buyer->state_id)) {
7983 $sql =
"SELECT d.rowid, t.taux as vat_default_rate, t.code as vat_default_code ";
7984 $sql .=
" FROM ".$db->prefix().
"c_tva as t";
7985 $sql .=
" INNER JOIN ".$db->prefix().
"c_departements as d ON t.fk_department_buyer = d.rowid";
7986 $sql .=
" WHERE d.rowid = ".((int) $thirdparty_buyer->state_id);
7987 $sql .=
" AND t.active > 0";
7988 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
7989 $sql .=
" ORDER BY t.use_default DESC, t.taux DESC, t.code ASC, t.recuperableonly ASC";
7991 $res = $db->query($sql);
7993 if ($db->num_rows($res)) {
7994 $obj = $db->fetch_object($res);
7995 return $obj->vat_default_rate.
' ('.$obj->vat_default_code.
')';
8002 if (($seller_country_code == $buyer_country_code)
8003 || (in_array($seller_country_code, array(
'FR',
'MC')) && in_array($buyer_country_code, array(
'FR',
'MC')))
8004 || (in_array($seller_country_code, array(
'MQ',
'GP')) && in_array($buyer_country_code, array(
'MQ',
'GP')))
8009 if ($seller_country_code ==
'IN' &&
getDolGlobalString(
'MAIN_SALETAX_AUTOSWITCH_I_CS_FOR_INDIA')) {
8013 if (preg_match(
'/C+S-(\d+)/', $tmpvat, $reg) && $thirdparty_seller->state_id != $thirdparty_buyer->state_id) {
8015 $tmpvat = str_replace(
"C+S",
"I", $tmpvat);
8016 } elseif (preg_match(
'/I-(\d+)/', $tmpvat, $reg) && $thirdparty_seller->state_id == $thirdparty_buyer->state_id) {
8018 $tmpvat = str_replace(
"I",
"C+S", $tmpvat);
8030 if (($seller_in_cee && $buyer_in_cee)) {
8031 $isacompany = $thirdparty_buyer->isACompany();
8032 if ($isacompany &&
getDolGlobalString(
'MAIN_USE_VAT_COMPANIES_IN_EEC_WITH_INVALID_VAT_ID_ARE_INDIVIDUAL')) {
8033 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
8050 if (
getDolGlobalString(
'MAIN_USE_VAT_OF_PRODUCT_FOR_INDIVIDUAL_CUSTOMER_OUT_OF_EEC') && empty($buyer_in_cee)) {
8051 $isacompany = $thirdparty_buyer->isACompany();
8079 if ($idprodfournprice > 0) {
8080 if (!class_exists(
'ProductFournisseur')) {
8081 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
8084 $prodprice->fetch_product_fournisseur_price($idprodfournprice);
8085 return $prodprice->fourn_tva_npr;
8086 } elseif ($idprod > 0) {
8087 if (!class_exists(
'Product')) {
8088 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
8091 $prod->fetch($idprod);
8092 return $prod->tva_npr;
8115 if (!is_object($thirdparty_seller)) {
8118 if (!is_object($thirdparty_buyer)) {
8122 if (empty($thirdparty_seller->country_code)) {
8123 $thirdparty_seller->country_code = $mysoc->country_code;
8125 $seller_country_code = $thirdparty_seller->country_code;
8128 if (empty($thirdparty_buyer->country_code)) {
8129 $thirdparty_buyer->country_code = $mysoc->country_code;
8131 $buyer_country_code = $thirdparty_buyer->country_code;
8135 if ($mysoc->country_code ==
'ES') {
8136 if (is_numeric($thirdparty_buyer->localtax1_assuj) && !$thirdparty_buyer->localtax1_assuj) {
8141 if (is_numeric($thirdparty_seller->localtax1_assuj) && !$thirdparty_seller->localtax1_assuj) {
8144 if (!is_numeric($thirdparty_seller->localtax1_assuj) && $thirdparty_seller->localtax1_assuj ==
'localtax1off') {
8148 } elseif ($local == 2) {
8150 if (is_numeric($thirdparty_seller->localtax2_assuj) && !$thirdparty_seller->localtax2_assuj) {
8153 if (!is_numeric($thirdparty_seller->localtax2_assuj) && $thirdparty_seller->localtax2_assuj ==
'localtax2off') {
8158 if ($seller_country_code == $buyer_country_code) {
8173function yn($yesno, $format = 1, $color = 0)
8177 $result =
'unknown';
8179 if ($yesno == 1 || (isset($yesno) && (strtolower($yesno) ==
'yes' || strtolower($yesno) ==
'true'))) {
8180 $result = $langs->trans(
'yes');
8181 if ($format == 1 || $format == 3) {
8182 $result = $langs->trans(
"Yes");
8185 $result =
'<input type="checkbox" value="1" checked disabled>';
8188 $result =
'<input type="checkbox" value="1" checked disabled> '.$result;
8190 if ($format == 4 || !is_numeric($format)) {
8191 $result =
img_picto(is_numeric($format) ?
'' : $format,
'check');
8195 } elseif ($yesno == 0 || strtolower($yesno) ==
'no' || strtolower($yesno) ==
'false') {
8196 $result = $langs->trans(
"no");
8197 if ($format == 1 || $format == 3) {
8198 $result = $langs->trans(
"No");
8201 $result =
'<input type="checkbox" value="0" disabled>';
8204 $result =
'<input type="checkbox" value="0" disabled> '.$result;
8206 if ($format == 4 || !is_numeric($format)) {
8207 $result =
img_picto(is_numeric($format) ?
'' : $format,
'uncheck');
8213 $classname =
'error';
8217 return '<span class="'.$classname.
'">'.$result.
'</span>';
8240function get_exdir($num, $level, $alpha, $withoutslash,
$object, $modulepart =
'')
8242 if (empty($modulepart) && is_object(
$object)) {
8243 if (!empty(
$object->module)) {
8244 $modulepart =
$object->module;
8245 } elseif (!empty(
$object->element)) {
8246 $modulepart =
$object->element;
8253 $arrayforoldpath = array(
'cheque' => 2,
'category' => 2,
'holiday' => 2,
'supplier_invoice' => 2,
'invoice_supplier' => 2,
'mailing' => 2,
'supplier_payment' => 2);
8255 $arrayforoldpath[
'product'] = 2;
8258 if (empty($level) && array_key_exists($modulepart, $arrayforoldpath)) {
8259 $level = $arrayforoldpath[$modulepart];
8261 if (!empty($level) && array_key_exists($modulepart, $arrayforoldpath)) {
8263 if (empty($num) && is_object(
$object)) {
8266 if (empty($alpha)) {
8267 $num = preg_replace(
'/([^0-9])/i',
'', $num);
8269 $num = preg_replace(
'/^.*\-/i',
'', $num);
8271 $num = substr(
"000".$num, -$level);
8273 $path = substr($num, 0, 1);
8276 $path = substr($num, 1, 1).
'/'.substr($num, 0, 1);
8279 $path = substr($num, 2, 1).
'/'.substr($num, 1, 1).
'/'.substr($num, 0, 1);
8285 if (in_array($modulepart, array(
'societe',
'thirdparty')) &&
$object instanceOf
Societe) {
8293 if (empty($withoutslash) && !empty($path)) {
8308function dol_mkdir($dir, $dataroot =
'', $newmask =
'')
8310 dol_syslog(
"functions.lib::dol_mkdir: dir=".$dir, LOG_INFO);
8315 if (@is_dir($dir_osencoded)) {
8323 if (!empty($dataroot)) {
8325 $dir = str_replace($dataroot.
'/',
'', $dir);
8326 $ccdir = $dataroot.
'/';
8329 $cdir = explode(
"/", $dir);
8330 $num = count($cdir);
8331 for ($i = 0; $i < $num; $i++) {
8333 $ccdir .=
'/'.$cdir[$i];
8335 $ccdir .= $cdir[$i];
8338 if (preg_match(
"/^.:$/", $ccdir, $regs)) {
8346 if (!@is_dir($ccdir_osencoded)) {
8347 dol_syslog(
"functions.lib::dol_mkdir: Directory '".$ccdir.
"' is not found (does not exists or is outside open_basedir PHP setting).", LOG_DEBUG);
8350 $dirmaskdec = octdec((
string) $newmask);
8351 if (empty($newmask)) {
8354 $dirmaskdec |= octdec(
'0111');
8355 if (!@mkdir($ccdir_osencoded, $dirmaskdec)) {
8357 dol_syslog(
"functions.lib::dol_mkdir: Fails to create directory '".$ccdir.
"' (no permission to write into parent or directory already exists).", LOG_WARNING);
8360 dol_syslog(
"functions.lib::dol_mkdir: Directory '".$ccdir.
"' created", LOG_DEBUG);
8369 return ($nberr ? -$nberr : $nbcreated);
8380function dolChmod($filepath, $newmask =
'')
8382 if (!empty($newmask)) {
8383 @chmod($filepath, octdec($newmask));
8397 return '<span class="fieldrequired">*</span>';
8417function dol_string_nohtmltag($stringtoclean, $removelinefeed = 1, $pagecodeto =
'UTF-8', $strip_tags = 0, $removedoublespaces = 1)
8419 if (is_null($stringtoclean)) {
8423 if ($removelinefeed == 2) {
8424 $stringtoclean = preg_replace(
'/<br[^>]*>(\n|\r)+/ims',
'<br>', $stringtoclean);
8426 $temp = preg_replace(
'/<br[^>]*>/i',
"\n", $stringtoclean);
8431 $temp = str_replace(
'< ',
'__ltspace__', $temp);
8432 $temp = str_replace(
'<:',
'__lttwopoints__', $temp);
8435 $temp = strip_tags($temp);
8438 $pattern =
"/<[^<>]+>/";
8445 $tempbis = str_replace(
'<>',
'', $temp);
8446 $tempbis = preg_replace($pattern,
'', $tempbis);
8448 }
while ($tempbis != $temp);
8453 $temp = preg_replace(
'/<+([a-z]+)/i',
'\1', $temp);
8459 if ($removelinefeed == 1) {
8460 $temp = str_replace(array(
"\r\n",
"\r",
"\n"),
" ", $temp);
8464 if ($removedoublespaces) {
8465 while (strpos($temp,
" ") !==
false) {
8466 $temp = str_replace(
" ",
" ", $temp);
8470 $temp = str_replace(
'__ltspace__',
'< ', $temp);
8471 $temp = str_replace(
'__lttwopoints__',
'<:', $temp);
8495function dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles = 1, $removeclassattribute = 1, $cleanalsojavascript = 0, $allowiframe = 0, $allowed_tags = array(), $allowlink = 0, $allowscript = 0, $allowstyle = 0, $allowphp = 0)
8497 if (empty($allowed_tags)) {
8498 $allowed_tags = array(
8499 "html",
"head",
"meta",
"body",
"article",
"a",
"abbr",
"b",
"blockquote",
"br",
"cite",
"div",
"dl",
"dd",
"dt",
"em",
"font",
"img",
"ins",
"hr",
"i",
"li",
8500 "ol",
"p",
"q",
"s",
"span",
"strike",
"strong",
"title",
"table",
"tr",
"th",
"td",
"u",
"ul",
"sup",
"sub",
"blockquote",
"pre",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
8501 "header",
"footer",
"nav",
"section",
"menu",
"menuitem"
8504 $allowed_tags[] =
"comment";
8506 if (!in_array(
'iframe', $allowed_tags)) {
8507 $allowed_tags[] =
"iframe";
8511 if (!in_array(
'link', $allowed_tags)) {
8512 $allowed_tags[] =
"link";
8516 if (!in_array(
'script', $allowed_tags)) {
8517 $allowed_tags[] =
"script";
8521 if (!in_array(
'style', $allowed_tags)) {
8522 $allowed_tags[] =
"style";
8526 $allowed_tags_string = implode(
"><", $allowed_tags);
8527 $allowed_tags_string =
'<'.$allowed_tags_string.
'>';
8529 $stringtoclean = str_replace(
'<!DOCTYPE html>',
'__!DOCTYPE_HTML__', $stringtoclean);
8534 $stringtoclean = preg_replace(
'/<!--([^>]*)-->/',
'<comment>\1</comment>', $stringtoclean);
8537 $allowed_tags[] =
"commentphp";
8538 $stringtoclean = preg_replace(
'/^<\?php([^"]+)\?>$/i',
'<commentphp>\1__</commentphp>', $stringtoclean);
8539 $stringtoclean = preg_replace(
'/"<\?php([^"]+)\?>"/i',
'"<commentphp>\1</commentphp>"', $stringtoclean);
8542 $stringtoclean = preg_replace(
'/:/i',
':', $stringtoclean);
8543 $stringtoclean = preg_replace(
'/:|�+58|:/i',
'', $stringtoclean);
8546 $temp = strip_tags($stringtoclean, $allowed_tags_string);
8548 if ($cleanalsosomestyles) {
8549 $temp = preg_replace(
'/position\s*:\s*(absolute|fixed)\s*!\s*important/i',
'', $temp);
8551 if ($removeclassattribute) {
8552 $temp = preg_replace(
'/(<[^>]+)\s+class=((["\']).*?\\3|\\w*)/i',
'\\1', $temp);
8557 if ($cleanalsojavascript) {
8558 $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);
8561 $temp = str_replace(
'__!DOCTYPE_HTML__',
'<!DOCTYPE html>', $temp);
8564 $temp = preg_replace(
'/<commentphp>(.*)<\/commentphp>/',
'<?php\1?>', $temp);
8567 $temp = preg_replace(
'/<comment>([^>]*)<\/comment>/',
'<!--\1-->', $temp);
8588 if (is_null($allowed_attributes)) {
8589 $allowed_attributes = array(
8590 "allow",
"allowfullscreen",
"alt",
"async",
"class",
"contenteditable",
"crossorigin",
"data-html",
"frameborder",
"height",
"href",
"id",
"name",
"property",
"rel",
"src",
"style",
"target",
"title",
"type",
"width",
8592 "header",
"footer",
"nav",
"section",
"menu",
"menuitem"
8596 if (!in_array(
"content", $allowed_attributes)) {
8597 $allowed_attributes[] =
"content";
8599 if (!in_array(
"http-equiv", $allowed_attributes)) {
8600 $allowed_attributes[] =
"http-equiv";
8603 if (class_exists(
'DOMDocument') && !empty($stringtoclean)) {
8605 $stringtoclean =
'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body>'.$stringtoclean.
'</body></html>';
8608 $dom =
new DOMDocument(
'',
'UTF-8');
8610 $savwarning = error_reporting();
8611 error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE);
8612 $dom->loadHTML($stringtoclean, LIBXML_ERR_NONE | LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD | LIBXML_NONET | LIBXML_NOWARNING | LIBXML_NOXMLDECL);
8613 error_reporting($savwarning);
8615 if ($dom instanceof DOMDocument) {
8616 for ($els = $dom->getElementsByTagname(
'*'), $i = $els->length - 1; $i >= 0; $i--) {
8617 $el = $els->item($i);
8618 if (!$el instanceof DOMElement) {
8621 $attrs = $el->attributes;
8622 for ($ii = $attrs->length - 1; $ii >= 0; $ii--) {
8624 if (!empty($attrs->item($ii)->name)) {
8625 if (! in_array($attrs->item($ii)->name, $allowed_attributes)) {
8627 $els->item($i)->removeAttribute($attrs->item($ii)->name);
8628 } elseif (in_array($attrs->item($ii)->name, array(
'style'))) {
8630 $valuetoclean = $attrs->item($ii)->value;
8632 if (isset($valuetoclean)) {
8634 $oldvaluetoclean = $valuetoclean;
8635 $valuetoclean = preg_replace(
'/\/\*.*\*\//m',
'', $valuetoclean);
8636 $valuetoclean = preg_replace(
'/position\s*:\s*[a-z]+/mi',
'', $valuetoclean);
8637 if ($els->item($i)->tagName ==
'a') {
8638 $valuetoclean = preg_replace(
'/display\s*:/mi',
'', $valuetoclean);
8639 $valuetoclean = preg_replace(
'/z-index\s*:/mi',
'', $valuetoclean);
8640 $valuetoclean = preg_replace(
'/\s+(top|left|right|bottom)\s*:/mi',
'', $valuetoclean);
8644 $valuetoclean = preg_replace(
'/(logout|passwordforgotten)\.php/mi',
'', $valuetoclean);
8645 $valuetoclean = preg_replace(
'/action=/mi',
'', $valuetoclean);
8646 }
while ($oldvaluetoclean != $valuetoclean);
8649 $attrs->item($ii)->value = $valuetoclean;
8656 $dom->encoding =
'UTF-8';
8658 $return = $dom->saveHTML();
8662 $return = preg_replace(
'/^'.preg_quote(
'<html><head><',
'/').
'[^<>]*'.preg_quote(
'></head><body>',
'/').
'/',
'', $return);
8663 $return = preg_replace(
'/'.preg_quote(
'</body></html>',
'/').
'$/',
'', trim($return));
8665 return trim($return);
8667 return $stringtoclean;
8684 $temp = $stringtoclean;
8685 foreach ($disallowed_tags as $tagtoremove) {
8686 $temp = preg_replace(
'/<\/?'.$tagtoremove.
'>/',
'', $temp);
8687 $temp = preg_replace(
'/<\/?'.$tagtoremove.
'\s+[^>]*>/',
'', $temp);
8690 if ($cleanalsosomestyles) {
8691 $temp = preg_replace(
'/position\s*:\s*(absolute|fixed)\s*!\s*important/',
'', $temp);
8709 if ($nboflines == 1) {
8711 $firstline = preg_replace(
'/<br[^>]*>.*$/s',
'', $text);
8712 $firstline = preg_replace(
'/<div[^>]*>.*$/s',
'', $firstline);
8715 $firstline = preg_replace(
'/[\n\r].*/',
'', $text);
8720 return $firstline.(isset($firstline) && isset($text) && (strlen($firstline) != strlen($text)) ?
'...' :
'');
8724 $text = preg_replace(
'/\n/',
'', $text);
8726 $repTable = array(
"\t" =>
" ",
"\n" =>
" ",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
8728 $repTable = array(
"\t" =>
" ",
"\n" =>
"<br>",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
8731 $text = strtr($text, $repTable);
8732 if ($charset ==
'UTF-8') {
8733 $pattern =
'/(<br[^>]*>)/Uu';
8736 $pattern =
'/(<br[^>]*>)/U';
8738 $a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
8743 $lastaddediscontent = 1;
8744 while ($countline < $nboflines && isset($a[$i])) {
8745 if (preg_match(
'/<br[^>]*>/', $a[$i])) {
8746 if (array_key_exists($i + 1, $a) && !empty($a[$i + 1])) {
8747 $firstline .= ($ishtml ?
"<br>\n" :
"\n");
8749 if (!$lastaddediscontent) {
8752 $lastaddediscontent = 0;
8755 $firstline .= $a[$i];
8756 $lastaddediscontent = 1;
8762 $adddots = (isset($a[$i]) && (!preg_match(
'/<br[^>]*>/', $a[$i]) || (array_key_exists($i + 1, $a) && !empty($a[$i + 1]))));
8764 $ret = $firstline.($adddots ?
'...' :
'');
8782function dol_nl2br($stringtoencode, $nl2brmode = 0, $forxml =
false)
8784 if (is_null($stringtoencode)) {
8789 return nl2br($stringtoencode, $forxml);
8791 $ret = preg_replace(
'/(\r\n|\r|\n)/i', ($forxml ?
'<br />' :
'<br>'), $stringtoencode);
8805function dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox = 0, $check =
'restricthtml')
8807 if (empty($nouseofiframesandbox) &&
getDolGlobalString(
'MAIN_SECURITY_USE_SANDBOX_FOR_HTMLWITHNOJS')) {
8812 return $stringtoencode;
8814 $out = $stringtoencode;
8818 $oldstringtoclean = $out;
8826 if (!empty($out) &&
getDolGlobalString(
'MAIN_RESTRICTHTML_ONLY_VALID_HTML') && $check !=
'restricthtmlallowunvalid') {
8828 libxml_use_internal_errors(
false);
8829 if (LIBXML_VERSION < 20900) {
8833 libxml_disable_entity_loader(
true);
8836 $dom =
new DOMDocument();
8844 $out =
'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body><div class="tricktoremove">'.$out.
'</div></body></html>';
8848 $out =
'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body><div class="tricktoremove">'.dol_nl2br($out).
'</div></body></html>';
8852 $dom->loadHTML($out, LIBXML_HTML_NODEFDTD | LIBXML_ERR_NONE | LIBXML_HTML_NOIMPLIED | LIBXML_NONET | LIBXML_NOWARNING | LIBXML_NOERROR | LIBXML_NOXMLDECL);
8854 $dom->encoding =
'UTF-8';
8856 $out = trim($dom->saveHTML());
8860 $out = preg_replace(
'/^'.preg_quote(
'<html><head><',
'/').
'[^<>]+'.preg_quote(
'></head><body><div class="tricktoremove">',
'/').
'/',
'', $out);
8861 $out = preg_replace(
'/'.preg_quote(
'</div></body></html>',
'/').
'$/',
'', trim($out));
8867 $out = str_replace(
'<br>',
'', $out);
8872 $out =
'InvalidHTMLStringCantBeCleaned '.$e->getMessage();
8879 if (!empty($out) &&
getDolGlobalString(
'MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY') && !in_array($check, array(
'restricthtmlallowunvalid',
'restricthtmlallowlinkscript')) && $outishtml) {
8885 if (extension_loaded(
'tidy') && class_exists(
"tidy")) {
8892 'quote-marks' =>
false,
8893 'doctype' =>
'strict',
8894 'show-body-only' =>
true,
8895 "indent-attributes" =>
false,
8896 "vertical-space" =>
false,
8899 'preserve-entities' =>
true
8909 $out = $tidy->repairString($out, $config,
'utf8');
8918 $out =
'InvalidHTMLStringCantBeCleaned '.$e->getMessage();
8923 $out = preg_replace(
'/[\x{200B}-\x{200D}\x{FEFF}]/u',
' ', $out);
8926 $out = preg_replace(
'/&(tab|newline);/i',
' ', $out);
8930 $out = preg_replace(
'/'/i',
''', $out);
8935 if (function_exists(
'realCharForNumericEntities')) {
8936 $out = preg_replace_callback(
8937 '/&#(x?[0-9][0-9a-f]+;?)/i',
8942 static function ($m) {
8950 $out = preg_replace(
'/&#x?[0-9]+/i',
'', $out);
8953 if ($check ==
'restricthtmlallowlinkscript') {
8955 } elseif ($check ==
'restricthtmlallowclass' || $check ==
'restricthtmlallowunvalid') {
8957 } elseif ($check ==
'restricthtmlallowiframe') {
8970 $out = preg_replace(
'/'/i',
"'", $out);
8974 $out = preg_replace(
'/on(mouse|drag|key|load|touch|pointer|select|transition)[a-z]*\s*=/i',
'', $out);
8975 $out = preg_replace(
'/on(abort|after|animation|auxclick|before|blur|cancel|canplay|canplaythrough|change|click|close|contextmenu|cuechange|copy|cut)[a-z]*\s*=/i',
'', $out);
8976 $out = preg_replace(
'/on(dblclick|drop|durationchange|emptied|end|ended|error|focus(in|out)?|formdata|gotpointercapture|hashchange|input|invalid)[a-z]*\s*=/i',
'', $out);
8977 $out = preg_replace(
'/on(lostpointercapture|offline|online|pagehide|pageshow)[a-z]*\s*=/i',
'', $out);
8978 $out = preg_replace(
'/on(paste|pause|play|playing|progress|ratechange|reset|resize|scroll|search|seeked|seeking|show|stalled|start|submit|suspend)[a-z]*\s*=/i',
'', $out);
8979 $out = preg_replace(
'/on(timeupdate|toggle|unload|volumechange|waiting|wheel)[a-z]*\s*=/i',
'', $out);
8981 $out = preg_replace(
'/on(repeat|begin|finish|beforeinput)[a-z]*\s*=/i',
'', $out);
8982 }
while ($oldstringtoclean != $out);
8989 $tmpout = preg_replace(
'/<img src="data:/mi',
'<__IMG_SRC_DATA__ src="data:', $out);
8990 preg_match_all(
'/(<img|url\(|<link)/i', $tmpout, $reg);
8991 $nblinks = count($reg[0]);
8992 if ($nblinks >
getDolGlobalInt(
"MAIN_SECURITY_MAX_IMG_IN_HTML_CONTENT", 1000)) {
8993 $out =
'ErrorTooManyLinksIntoHTMLString';
8996 if (
getDolGlobalInt(
'MAIN_DISALLOW_URL_INTO_DESCRIPTIONS') == 2 || $check ==
'restricthtmlnolink') {
8998 $out =
'ErrorHTMLLinksNotAllowed';
9000 } elseif (
getDolGlobalInt(
'MAIN_DISALLOW_URL_INTO_DESCRIPTIONS') == 1) {
9003 $pattern =
'/src=["\']?(http[^"\']+)|url\(["\']?(http[^\)]+)/';
9006 if (preg_match_all($pattern, $out, $matches)) {
9008 $urls = $matches[1];
9011 foreach ($urls as $url) {
9013 echo
"Found url = ".$url .
"\n";
9016 $out =
'ErrorHTMLExternalLinksNotAllowed';
9045function dol_htmlentitiesbr($stringtoencode, $nl2brmode = 0, $pagecodefrom =
'UTF-8', $removelasteolbr = 1)
9047 if (is_null($stringtoencode)) {
9051 $newstring = $stringtoencode;
9053 $newstring = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>/i',
'<br>', $newstring);
9054 if ($removelasteolbr) {
9055 $newstring = preg_replace(
'/<br>$/i',
'', $newstring);
9057 $newstring = preg_replace(
'/[\x{200B}-\x{200D}\x{FEFF}]/u',
' ', $newstring);
9058 $newstring = strtr($newstring, array(
'&' =>
'__PROTECTand__',
'<' =>
'__PROTECTlt__',
'>' =>
'__PROTECTgt__',
'"' =>
'__PROTECTdquot__'));
9060 $newstring = strtr($newstring, array(
'__PROTECTand__' =>
'&',
'__PROTECTlt__' =>
'<',
'__PROTECTgt__' =>
'>',
'__PROTECTdquot__' =>
'"'));
9062 if ($removelasteolbr) {
9063 $newstring = preg_replace(
'/(\r\n|\r|\n)$/i',
'', $newstring);
9082 $ret = preg_replace(
'/'.
"\r\n".
'<br(\s[\sa-zA-Z_="]*)?\/?>/i',
"<br>", $ret);
9083 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>'.
"\r\n".
'/i',
"\r\n", $ret);
9084 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>'.
"\n".
'/i',
"\n", $ret);
9085 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>/i',
"\n", $ret);
9097 $ret = preg_replace(
'/ $/i',
"", $stringtodecode);
9098 $ret = preg_replace(
'/(<br>|<br(\s[\sa-zA-Z_="]*)?\/?>|'.
"\n".
'|'.
"\r".
')+$/i',
"", $ret);
9114 if ($keepsomeentities) {
9115 $newstring = strtr($newstring, array(
'&' =>
'__andamp__',
'<' =>
'__andlt__',
'>' =>
'__andgt__',
'"' =>
'__dquot__'));
9117 $newstring = html_entity_decode((
string) $newstring, (
int) $b, (
string)
$c);
9118 if ($keepsomeentities) {
9119 $newstring = strtr($newstring, array(
'__andamp__' =>
'&',
'__andlt__' =>
'<',
'__andgt__' =>
'>',
'__dquot__' =>
'"'));
9135function dol_htmlentities($string, $flags = ENT_QUOTES | ENT_SUBSTITUTE, $encoding =
'UTF-8', $double_encode =
false)
9137 return htmlentities($string, $flags, $encoding, $double_encode);
9156 for ($scursor = 0; $scursor < $len; $scursor++) {
9157 $ordchar = ord($s[$scursor]);
9159 if ($ordchar < 32 && $ordchar != 13 && $ordchar != 10) {
9162 } elseif ($ordchar > 126 && $ordchar < 160) {
9166 $out .= $s[$scursor];
9188 $arraystring = explode(
"\n", $s);
9189 $nb = count($arraystring);
9206 $repTable = array(
"\t" =>
" ",
"\n" =>
"<br>",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
9208 $repTable = array(
"\t" =>
" ",
"\n" =>
" ",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
9211 $text = strtr($text, $repTable);
9212 if ($charset ==
'UTF-8') {
9213 $pattern =
'/(<br[^>]*>)/Uu';
9216 $pattern =
'/(<br[^>]*>)/U';
9218 $a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
9220 $nblines = (int) floor((count($a) + 1) / 2);
9223 foreach ($a as $line) {
9226 $line_dec = html_entity_decode($line);
9228 $line_dec = wordwrap($line_dec, $maxlinesize,
'\n',
true);
9229 $nblines += substr_count($line_dec,
'\n');
9249 if (is_null($msg)) {
9254 if (preg_match(
'/<(html|link|script)/i', $msg)) {
9256 } elseif (preg_match(
'/<body/i', $msg)) {
9258 } elseif (preg_match(
'/<\/textarea/i', $msg)) {
9260 } elseif (preg_match(
'/<(b|em|i|u)(\s+[^>]+)?>/i', $msg)) {
9262 } elseif (preg_match(
'/<br/i', $msg)) {
9268 $msg = preg_replace(
'/https?:\/\/[^"\'\s]+/i',
'', $msg);
9269 if (preg_match(
'/<(html|link|script|body)/i', $msg)) {
9271 } elseif (preg_match(
'/<\/textarea/i', $msg)) {
9273 } elseif (preg_match(
'/<(b|em|i|u)(\s+[^>]+)?>/i', $msg)) {
9275 } elseif (preg_match(
'/<(br|hr)\/>/i', $msg)) {
9277 } elseif (preg_match(
'/<(br|hr|div|font|li|p|span|strong|table)>/i', $msg)) {
9279 } elseif (preg_match(
'/<(br|hr|div|font|li|p|span|strong|table)\s+[^<>\/]*\/?>/i', $msg)) {
9281 } elseif (preg_match(
'/<img\s+[^<>]*src[^<>]*>/i', $msg)) {
9283 } elseif (preg_match(
'/<a\s+[^<>]*href[^<>]*>/i', $msg)) {
9285 } elseif (preg_match(
'/<h[0-9]>/i', $msg)) {
9287 } elseif (preg_match(
'/&[A-Z0-9]{1,6};/i', $msg)) {
9290 } elseif (preg_match(
'/&#[0-9]{2,3};/i', $msg)) {
9292 } elseif (preg_match(
'/&#x[a-f0-9][a-f0-9];/i', $msg)) {
9314function dol_concatdesc($text1, $text2, $forxml =
false, $invert =
false)
9316 if (!empty($invert)) {
9324 $ret .= (!empty($text1) && !empty($text2)) ? ((
dol_textishtml($text1) ||
dol_textishtml($text2)) ? ($forxml ?
"<br >\n" :
"<br>\n") :
"\n") :
"";
9344function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude =
null,
$object =
null, $include =
null)
9346 global $db,
$conf, $mysoc, $user, $extrafields;
9348 $substitutionarray = array();
9350 if ((empty($exclude) || !in_array(
'user', $exclude)) && (empty($include) || in_array(
'user', $include)) && $user instanceof
User) {
9354 $emailsendersignature = $user->signature;
9355 $usersignature = $user->signature;
9356 $substitutionarray = array_merge($substitutionarray, array(
9357 '__SENDEREMAIL_SIGNATURE__' => (
string) ((!
getDolGlobalString(
'MAIN_MAIL_DO_NOT_USE_SIGN')) ? ($onlykey == 2 ?
dol_trunc(
'SignatureFromTheSelectedSenderProfile', 30) : $emailsendersignature) :
''),
9361 if (is_object($user) && ($user instanceof
User)) {
9362 $substitutionarray = array_merge($substitutionarray, array(
9363 '__USER_ID__' => (
string) $user->id,
9364 '__USER_LOGIN__' => (
string) $user->login,
9365 '__USER_EMAIL__' => (
string) $user->email,
9366 '__USER_PHONE__' => (
string)
dol_print_phone($user->office_phone,
'', 0, 0,
'',
" ",
'',
'', -1),
9367 '__USER_PHONEPRO__' => (
string)
dol_print_phone($user->user_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
9368 '__USER_PHONEMOBILE__' => (
string)
dol_print_phone($user->personal_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
9369 '__USER_FAX__' => (
string) $user->office_fax,
9370 '__USER_LASTNAME__' => (
string) $user->lastname,
9371 '__USER_FIRSTNAME__' => (
string) $user->firstname,
9372 '__USER_FULLNAME__' => (
string) $user->getFullName($outputlangs),
9373 '__USER_SUPERVISOR_ID__' => (
string) ($user->fk_user ? $user->fk_user :
'0'),
9374 '__USER_JOB__' => (string) $user->job,
9376 '__USER_VCARD_URL__' => (string) $user->getOnlineVirtualCardUrl(
'',
'external')
9380 if ((empty($exclude) || !in_array(
'mycompany', $exclude)) && is_object($mysoc) && (empty($include) || in_array(
'mycompany', $include))) {
9381 $substitutionarray = array_merge($substitutionarray, array(
9382 '__MYCOMPANY_NAME__' => $mysoc->name,
9383 '__MYCOMPANY_EMAIL__' => $mysoc->email,
9384 '__MYCOMPANY_URL__' => $mysoc->url,
9385 '__MYCOMPANY_PHONE__' =>
dol_print_phone($mysoc->phone,
'', 0, 0,
'',
" ",
'',
'', -1),
9386 '__MYCOMPANY_PHONEMOBILE__' =>
dol_print_phone($mysoc->phone_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
9387 '__MYCOMPANY_FAX__' =>
dol_print_phone($mysoc->fax,
'', 0, 0,
'',
" ",
'',
'', -1),
9388 '__MYCOMPANY_PROFID1__' => $mysoc->idprof1,
9389 '__MYCOMPANY_PROFID2__' => $mysoc->idprof2,
9390 '__MYCOMPANY_PROFID3__' => $mysoc->idprof3,
9391 '__MYCOMPANY_PROFID4__' => $mysoc->idprof4,
9392 '__MYCOMPANY_PROFID5__' => $mysoc->idprof5,
9393 '__MYCOMPANY_PROFID6__' => $mysoc->idprof6,
9394 '__MYCOMPANY_PROFID7__' => $mysoc->idprof7,
9395 '__MYCOMPANY_PROFID8__' => $mysoc->idprof8,
9396 '__MYCOMPANY_PROFID9__' => $mysoc->idprof9,
9397 '__MYCOMPANY_PROFID10__' => $mysoc->idprof10,
9398 '__MYCOMPANY_CAPITAL__' => $mysoc->capital,
9399 '__MYCOMPANY_FULLADDRESS__' => (method_exists($mysoc,
'getFullAddress') ? $mysoc->getFullAddress(1,
', ') :
''),
9400 '__MYCOMPANY_ADDRESS__' => $mysoc->
address,
9401 '__MYCOMPANY_ZIP__' => $mysoc->zip,
9402 '__MYCOMPANY_TOWN__' => $mysoc->town,
9403 '__MYCOMPANY_STATE__' => $mysoc->state,
9404 '__MYCOMPANY_COUNTRY__' => $mysoc->country,
9405 '__MYCOMPANY_COUNTRY_ID__' => $mysoc->country_id,
9406 '__MYCOMPANY_COUNTRY_CODE__' => $mysoc->country_code,
9407 '__MYCOMPANY_CURRENCY_CODE__' =>
$conf->currency
9411 if (($onlykey || is_object(
$object)) && (empty($exclude) || !in_array(
'object', $exclude)) && (empty($include) || in_array(
'object', $include))) {
9413 $substitutionarray[
'__ID__'] =
'__ID__';
9414 $substitutionarray[
'__REF__'] =
'__REF__';
9415 $substitutionarray[
'__NEWREF__'] =
'__NEWREF__';
9416 $substitutionarray[
'__LABEL__'] =
'__LABEL__';
9417 $substitutionarray[
'__REF_CLIENT__'] =
'__REF_CLIENT__';
9418 $substitutionarray[
'__REF_SUPPLIER__'] =
'__REF_SUPPLIER__';
9419 $substitutionarray[
'__NOTE_PUBLIC__'] =
'__NOTE_PUBLIC__';
9420 $substitutionarray[
'__NOTE_PRIVATE__'] =
'__NOTE_PRIVATE__';
9421 $substitutionarray[
'__EXTRAFIELD_XXX__'] =
'__EXTRAFIELD_XXX__';
9423 if (isModEnabled(
"societe")) {
9424 $substitutionarray[
'__THIRDPARTY_ID__'] =
'__THIRDPARTY_ID__';
9425 $substitutionarray[
'__THIRDPARTY_NAME__'] =
'__THIRDPARTY_NAME__';
9426 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] =
'__THIRDPARTY_NAME_ALIAS__';
9427 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] =
'__THIRDPARTY_CODE_CLIENT__';
9428 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] =
'__THIRDPARTY_CODE_FOURNISSEUR__';
9429 $substitutionarray[
'__THIRDPARTY_EMAIL__'] =
'__THIRDPARTY_EMAIL__';
9431 $substitutionarray[
'__THIRDPARTY_URL__'] =
'__THIRDPARTY_URL__';
9433 $substitutionarray[
'__THIRDPARTY_PHONE__'] =
'__THIRDPARTY_PHONE__';
9434 $substitutionarray[
'__THIRDPARTY_FAX__'] =
'__THIRDPARTY_FAX__';
9435 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] =
'__THIRDPARTY_ADDRESS__';
9436 $substitutionarray[
'__THIRDPARTY_ZIP__'] =
'__THIRDPARTY_ZIP__';
9437 $substitutionarray[
'__THIRDPARTY_TOWN__'] =
'__THIRDPARTY_TOWN__';
9438 $substitutionarray[
'__THIRDPARTY_STATE__'] =
'__THIRDPARTY_STATE__';
9439 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] =
'__THIRDPARTY_IDPROF1__';
9440 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] =
'__THIRDPARTY_IDPROF2__';
9441 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] =
'__THIRDPARTY_IDPROF3__';
9442 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] =
'__THIRDPARTY_IDPROF4__';
9443 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] =
'__THIRDPARTY_IDPROF5__';
9444 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] =
'__THIRDPARTY_IDPROF6__';
9445 $substitutionarray[
'__THIRDPARTY_IDPROF7__'] =
'__THIRDPARTY_IDPROF7__';
9446 $substitutionarray[
'__THIRDPARTY_IDPROF8__'] =
'__THIRDPARTY_IDPROF8__';
9447 $substitutionarray[
'__THIRDPARTY_IDPROF9__'] =
'__THIRDPARTY_IDPROF9__';
9448 $substitutionarray[
'__THIRDPARTY_IDPROF10__'] =
'__THIRDPARTY_IDPROF10__';
9449 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] =
'__THIRDPARTY_TVAINTRA__';
9450 $substitutionarray[
'__THIRDPARTY_NOTE_PUBLIC__'] =
'__THIRDPARTY_NOTE_PUBLIC__';
9451 $substitutionarray[
'__THIRDPARTY_NOTE_PRIVATE__'] =
'__THIRDPARTY_NOTE_PRIVATE__';
9453 if (isModEnabled(
'member') && (!is_object(
$object) ||
$object->element ==
'adherent') && (empty($exclude) || !in_array(
'member', $exclude)) && (empty($include) || in_array(
'member', $include))) {
9454 $substitutionarray[
'__MEMBER_ID__'] =
'__MEMBER_ID__';
9455 $substitutionarray[
'__MEMBER_TITLE__'] =
'__MEMBER_TITLE__';
9456 $substitutionarray[
'__MEMBER_FIRSTNAME__'] =
'__MEMBER_FIRSTNAME__';
9457 $substitutionarray[
'__MEMBER_LASTNAME__'] =
'__MEMBER_LASTNAME__';
9458 $substitutionarray[
'__MEMBER_USER_LOGIN_INFORMATION__'] =
'Login and pass of the external user account';
9463 if (isModEnabled(
'ticket') && (!is_object(
$object) ||
$object->element ==
'ticket') && (empty($exclude) || !in_array(
'ticket', $exclude)) && (empty($include) || in_array(
'ticket', $include))) {
9464 $substitutionarray[
'__TICKET_TRACKID__'] =
'__TICKET_TRACKID__';
9465 $substitutionarray[
'__TICKET_SUBJECT__'] =
'__TICKET_SUBJECT__';
9466 $substitutionarray[
'__TICKET_TYPE__'] =
'__TICKET_TYPE__';
9467 $substitutionarray[
'__TICKET_SEVERITY__'] =
'__TICKET_SEVERITY__';
9468 $substitutionarray[
'__TICKET_CATEGORY__'] =
'__TICKET_CATEGORY__';
9469 $substitutionarray[
'__TICKET_ANALYTIC_CODE__'] =
'__TICKET_ANALYTIC_CODE__';
9470 $substitutionarray[
'__TICKET_MESSAGE__'] =
'__TICKET_MESSAGE__';
9471 $substitutionarray[
'__TICKET_PROGRESSION__'] =
'__TICKET_PROGRESSION__';
9472 $substitutionarray[
'__TICKET_USER_ASSIGN__'] =
'__TICKET_USER_ASSIGN__';
9475 if (isModEnabled(
'recruitment') && (!is_object(
$object) ||
$object->element ==
'recruitmentcandidature') && (empty($exclude) || !in_array(
'recruitment', $exclude)) && (empty($include) || in_array(
'recruitment', $include))) {
9476 $substitutionarray[
'__CANDIDATE_FULLNAME__'] =
'__CANDIDATE_FULLNAME__';
9477 $substitutionarray[
'__CANDIDATE_FIRSTNAME__'] =
'__CANDIDATE_FIRSTNAME__';
9478 $substitutionarray[
'__CANDIDATE_LASTNAME__'] =
'__CANDIDATE_LASTNAME__';
9480 if (isModEnabled(
'project') && (empty($exclude) || !in_array(
'project', $exclude)) && (empty($include) || in_array(
'project', $include))) {
9481 $substitutionarray[
'__PROJECT_ID__'] =
'__PROJECT_ID__';
9482 $substitutionarray[
'__PROJECT_REF__'] =
'__PROJECT_REF__';
9483 $substitutionarray[
'__PROJECT_NAME__'] =
'__PROJECT_NAME__';
9487 if (isModEnabled(
'contract') && (!is_object(
$object) ||
$object->element ==
'contract') && (empty($exclude) || !in_array(
'contract', $exclude)) && (empty($include) || in_array(
'contract', $include))) {
9488 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE__'] =
'Highest date planned for a service start';
9489 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATETIME__'] =
'Highest date and hour planned for service start';
9490 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE__'] =
'Lowest data for planned expiration of service';
9491 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATETIME__'] =
'Lowest date and hour for planned expiration of service';
9493 if (isModEnabled(
"propal") && (!is_object(
$object) ||
$object->element ==
'propal') && (empty($exclude) || !in_array(
'propal', $exclude)) && (empty($include) || in_array(
'propal', $include))) {
9494 $substitutionarray[
'__ONLINE_SIGN_URL__'] =
'ToOfferALinkForOnlineSignature';
9496 if (isModEnabled(
"intervention") && (!is_object(
$object) ||
$object->element ==
'fichinter') && (empty($exclude) || !in_array(
'intervention', $exclude)) && (empty($include) || in_array(
'intervention', $include))) {
9497 $substitutionarray[
'__ONLINE_SIGN_FICHINTER_URL__'] =
'ToOfferALinkForOnlineSignature';
9499 $substitutionarray[
'__ONLINE_PAYMENT_URL__'] =
'UrlToPayOnlineIfApplicable';
9500 $substitutionarray[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'TextAndUrlToPayOnlineIfApplicable';
9501 $substitutionarray[
'__SECUREKEYPAYMENT__'] =
'Security key (if key is not unique per record)';
9502 $substitutionarray[
'__SECUREKEYPAYMENT_MEMBER__'] =
'Security key for payment on a member subscription (one key per member)';
9503 $substitutionarray[
'__SECUREKEYPAYMENT_ORDER__'] =
'Security key for payment on an order';
9504 $substitutionarray[
'__SECUREKEYPAYMENT_INVOICE__'] =
'Security key for payment on an invoice';
9505 $substitutionarray[
'__SECUREKEYPAYMENT_CONTRACTLINE__'] =
'Security key for payment on a service of a contract';
9507 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
'Direct download url of a proposal';
9508 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
'Direct download url of an order';
9509 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
'Direct download url of an invoice';
9510 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
'Direct download url of a contract';
9511 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
'Direct download url of a supplier proposal';
9513 if (isModEnabled(
"shipping") && (!is_object(
$object) ||
$object->element ==
'shipping')) {
9514 $substitutionarray[
'__SHIPPINGTRACKNUM__'] =
'Shipping tracking number';
9515 $substitutionarray[
'__SHIPPINGTRACKNUMURL__'] =
'Shipping tracking url';
9516 $substitutionarray[
'__SHIPPINGMETHOD__'] =
'Shipping method';
9518 if (isModEnabled(
"reception") && (!is_object(
$object) ||
$object->element ==
'reception')) {
9519 $substitutionarray[
'__RECEPTIONTRACKNUM__'] =
'Shipping tracking number of shipment';
9520 $substitutionarray[
'__RECEPTIONTRACKNUMURL__'] =
'Shipping tracking url';
9523 '@phan-var-force Adherent|Delivery $object';
9525 $substitutionarray[
'__ID__'] =
$object->id;
9526 $substitutionarray[
'__REF__'] =
$object->ref;
9527 $substitutionarray[
'__NEWREF__'] =
$object->newref;
9529 $substitutionarray[
'__REF_CLIENT__'] = (isset(
$object->ref_client) ?
$object->ref_client : (isset(
$object->ref_customer) ?
$object->ref_customer :
null));
9530 $substitutionarray[
'__REF_SUPPLIER__'] = (isset(
$object->ref_supplier) ?
$object->ref_supplier :
null);
9531 $substitutionarray[
'__NOTE_PUBLIC__'] = (isset(
$object->note_public) ?
$object->note_public :
null);
9532 $substitutionarray[
'__NOTE_PRIVATE__'] = (isset(
$object->note_private) ?
$object->note_private :
null);
9534 $substitutionarray[
'__DATE_CREATION__'] = (isset(
$object->date_creation) ?
dol_print_date(
$object->date_creation,
'day',
false, $outputlangs) :
'');
9535 $substitutionarray[
'__DATE_MODIFICATION__'] = (isset(
$object->date_modification) ?
dol_print_date(
$object->date_modification,
'day',
false, $outputlangs) :
'');
9536 $substitutionarray[
'__DATE_VALIDATION__'] = (isset(
$object->date_validation) ?
dol_print_date(
$object->date_validation,
'day',
false, $outputlangs) :
'');
9539 $date_delivery =
null;
9540 if (property_exists(
$object,
'date_delivery')) {
9541 $date_delivery =
$object->date_delivery;
9542 } elseif (property_exists(
$object,
'delivery_date')) {
9543 $date_delivery =
$object->delivery_date;
9545 $substitutionarray[
'__DATE_DELIVERY__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
'day',
false, $outputlangs) :
'');
9546 $substitutionarray[
'__DATE_DELIVERY_DAY__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%d") :
'');
9547 $substitutionarray[
'__DATE_DELIVERY_DAY_TEXT__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%A") :
'');
9548 $substitutionarray[
'__DATE_DELIVERY_MON__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%m") :
'');
9549 $substitutionarray[
'__DATE_DELIVERY_MON_TEXT__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%b") :
'');
9550 $substitutionarray[
'__DATE_DELIVERY_YEAR__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%Y") :
'');
9551 $substitutionarray[
'__DATE_DELIVERY_HH__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%H") :
'');
9552 $substitutionarray[
'__DATE_DELIVERY_MM__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%M") :
'');
9553 $substitutionarray[
'__DATE_DELIVERY_SS__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%S") :
'');
9556 $substitutionarray[
'__REFCLIENT__'] = (isset(
$object->ref_client) ?
$object->ref_client : (isset(
$object->ref_customer) ?
$object->ref_customer :
null));
9557 $substitutionarray[
'__REFSUPPLIER__'] = (isset(
$object->ref_supplier) ?
$object->ref_supplier :
null);
9559 $substitutionarray[
'__SUPPLIER_ORDER_DATE_DELIVERY__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
'day',
false, $outputlangs) :
'');
9560 $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 :
'')) :
'');
9564 '@phan-var-force Adherent $object';
9568 $substitutionarray[
'__MEMBER_ID__'] = (isset(
$object->id) ?
$object->id :
'');
9569 if (method_exists(
$object,
'getCivilityLabel')) {
9570 $substitutionarray[
'__MEMBER_TITLE__'] =
$object->getCivilityLabel();
9572 $substitutionarray[
'__MEMBER_FIRSTNAME__'] = (isset(
$object->firstname) ?
$object->firstname :
'');
9573 $substitutionarray[
'__MEMBER_LASTNAME__'] = (isset(
$object->lastname) ?
$object->lastname :
'');
9574 $substitutionarray[
'__MEMBER_USER_LOGIN_INFORMATION__'] =
'';
9575 if (method_exists(
$object,
'getFullName')) {
9576 $substitutionarray[
'__MEMBER_FULLNAME__'] =
$object->getFullName($outputlangs);
9578 $substitutionarray[
'__MEMBER_COMPANY__'] = (isset(
$object->societe) ?
$object->societe :
'');
9579 $substitutionarray[
'__MEMBER_ADDRESS__'] = (isset(
$object->address) ?
$object->address :
'');
9580 $substitutionarray[
'__MEMBER_ZIP__'] = (isset(
$object->zip) ?
$object->zip :
'');
9581 $substitutionarray[
'__MEMBER_TOWN__'] = (isset(
$object->town) ?
$object->town :
'');
9582 $substitutionarray[
'__MEMBER_STATE__'] = (isset(
$object->state) ?
$object->state :
'');
9583 $substitutionarray[
'__MEMBER_COUNTRY__'] = (isset(
$object->country) ?
$object->country :
'');
9584 $substitutionarray[
'__MEMBER_EMAIL__'] = (isset(
$object->email) ?
$object->email :
'');
9585 $substitutionarray[
'__MEMBER_BIRTH__'] = (isset($birthday) ? $birthday :
'');
9586 $substitutionarray[
'__MEMBER_PHOTO__'] = (isset(
$object->photo) ?
$object->photo :
'');
9587 $substitutionarray[
'__MEMBER_LOGIN__'] = (isset(
$object->login) ?
$object->login :
'');
9588 $substitutionarray[
'__MEMBER_PASSWORD__'] = (isset(
$object->pass) ?
$object->pass :
'');
9592 $substitutionarray[
'__MEMBER_TYPE__'] = (isset(
$object->type) ?
$object->type :
'');
9593 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE__'] =
dol_print_date(
$object->first_subscription_date,
'day');
9595 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_RFC__'] =
dol_print_date(
$object->first_subscription_date,
'dayrfc');
9596 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_START__'] = (isset(
$object->first_subscription_date_start) ?
dol_print_date(
$object->first_subscription_date_start,
'day') :
'');
9597 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_START_RFC__'] = (isset(
$object->first_subscription_date_start) ?
dol_print_date(
$object->first_subscription_date_start,
'dayrfc') :
'');
9598 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_END__'] = (isset(
$object->first_subscription_date_end) ?
dol_print_date(
$object->first_subscription_date_end,
'day') :
'');
9599 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_END_RFC__'] = (isset(
$object->first_subscription_date_end) ?
dol_print_date(
$object->first_subscription_date_end,
'dayrfc') :
'');
9600 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE__'] =
dol_print_date(
$object->last_subscription_date,
'day');
9601 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_RFC__'] =
dol_print_date(
$object->last_subscription_date,
'dayrfc');
9602 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_START__'] =
dol_print_date(
$object->last_subscription_date_start,
'day');
9603 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_START_RFC__'] =
dol_print_date(
$object->last_subscription_date_start,
'dayrfc');
9604 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_END__'] =
dol_print_date(
$object->last_subscription_date_end,
'day');
9605 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_END_RFC__'] =
dol_print_date(
$object->last_subscription_date_end,
'dayrfc');
9610 '@phan-var-force Societe $object';
9611 $substitutionarray[
'__THIRDPARTY_ID__'] =
$object->id ??
'';
9612 $substitutionarray[
'__THIRDPARTY_NAME__'] =
$object->name ??
'';
9613 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] =
$object->name_alias ??
'';
9614 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] =
$object->code_client ??
'';
9615 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] =
$object->code_fournisseur ??
'';
9616 $substitutionarray[
'__THIRDPARTY_EMAIL__'] =
$object->email ??
'';
9617 $substitutionarray[
'__THIRDPARTY_EMAIL_URLENCODED__'] = urlencode(
$object->email ??
'');
9618 $substitutionarray[
'__THIRDPARTY_URL__'] =
$object->url ??
'';
9619 $substitutionarray[
'__THIRDPARTY_URL_URLENCODED__'] = urlencode(
$object->url ??
'');
9622 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] =
$object->address ??
'';
9623 $substitutionarray[
'__THIRDPARTY_ZIP__'] =
$object->zip ??
'';
9624 $substitutionarray[
'__THIRDPARTY_TOWN__'] =
$object->town ??
'';
9625 $substitutionarray[
'__THIRDPARTY_STATE__'] =
$object->state ??
'';
9626 $substitutionarray[
'__THIRDPARTY_COUNTRY_ID__'] = (
$object->country_id > 0 ?
$object->country_id :
'');
9627 $substitutionarray[
'__THIRDPARTY_COUNTRY_CODE__'] =
$object->country_code ??
'';
9628 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] =
$object->idprof1 ??
'';
9629 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] =
$object->idprof2 ??
'';
9630 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] =
$object->idprof3 ??
'';
9631 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] =
$object->idprof4 ??
'';
9632 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] =
$object->idprof5 ??
'';
9633 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] =
$object->idprof6 ??
'';
9634 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] =
$object->tva_intra ??
'';
9637 } elseif (is_object(
$object) && is_object(
$object->thirdparty)) {
9638 $substitutionarray[
'__THIRDPARTY_ID__'] =
$object->thirdparty->id ??
'';
9639 $substitutionarray[
'__THIRDPARTY_NAME__'] =
$object->thirdparty->name ??
'';
9640 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] =
$object->thirdparty->name_alias ??
'';
9641 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] =
$object->thirdparty->code_client ??
'';
9642 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] =
$object->thirdparty->code_fournisseur ??
'';
9643 $substitutionarray[
'__THIRDPARTY_EMAIL__'] =
$object->thirdparty->email ??
'';
9644 $substitutionarray[
'__THIRDPARTY_EMAIL_URLENCODED__'] = urlencode(
$object->thirdparty->email ??
'');
9647 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] =
$object->thirdparty->address ??
'';
9648 $substitutionarray[
'__THIRDPARTY_ZIP__'] =
$object->thirdparty->zip ??
'';
9649 $substitutionarray[
'__THIRDPARTY_TOWN__'] =
$object->thirdparty->town ??
'';
9650 $substitutionarray[
'__THIRDPARTY_STATE__'] =
$object->thirdparty->state ??
'';
9651 $substitutionarray[
'__THIRDPARTY_COUNTRY_ID__'] = (
$object->thirdparty->country_id > 0 ?
$object->thirdparty->country_id :
'');
9652 $substitutionarray[
'__THIRDPARTY_COUNTRY_CODE__'] =
$object->thirdparty->country_code ??
'';
9653 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] =
$object->thirdparty->idprof1 ??
'';
9654 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] =
$object->thirdparty->idprof2 ??
'';
9655 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] =
$object->thirdparty->idprof3 ??
'';
9656 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] =
$object->thirdparty->idprof4 ??
'';
9657 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] =
$object->thirdparty->idprof5 ??
'';
9658 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] =
$object->thirdparty->idprof6 ??
'';
9659 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] =
$object->thirdparty->tva_intra ??
'';
9664 if (is_object(
$object) &&
$object->element ==
'recruitmentcandidature') {
9665 '@phan-var-force RecruitmentCandidature $object';
9667 $substitutionarray[
'__CANDIDATE_FULLNAME__'] =
$object->getFullName($outputlangs);
9668 $substitutionarray[
'__CANDIDATE_FIRSTNAME__'] = isset(
$object->firstname) ?
$object->firstname :
'';
9669 $substitutionarray[
'__CANDIDATE_LASTNAME__'] = isset(
$object->lastname) ?
$object->lastname :
'';
9671 if (is_object(
$object) &&
$object->element ==
'conferenceorboothattendee') {
9672 '@phan-var-force ConferenceOrBoothAttendee $object';
9674 $substitutionarray[
'__ATTENDEE_FULLNAME__'] =
$object->getFullName($outputlangs);
9675 $substitutionarray[
'__ATTENDEE_FIRSTNAME__'] = isset(
$object->firstname) ?
$object->firstname :
'';
9676 $substitutionarray[
'__ATTENDEE_LASTNAME__'] = isset(
$object->lastname) ?
$object->lastname :
'';
9680 '@phan-var-force Project $object';
9682 $substitutionarray[
'__PROJECT_ID__'] =
$object->id;
9683 $substitutionarray[
'__PROJECT_REF__'] =
$object->ref;
9684 $substitutionarray[
'__PROJECT_NAME__'] =
$object->title;
9685 } elseif (is_object(
$object)) {
9687 if (!empty(
$object->project)) {
9689 } elseif (!empty(
$object->projet)) {
9692 if (!is_null($project) && is_object($project)) {
9693 $substitutionarray[
'__PROJECT_ID__'] = $project->id;
9694 $substitutionarray[
'__PROJECT_REF__'] = $project->ref;
9695 $substitutionarray[
'__PROJECT_NAME__'] = $project->title;
9700 $project_id =
$object->fk_project;
9701 } elseif (!empty(
$object->fk_projet) &&
$object->fk_projet > 0) {
9702 $project_id =
$object->fk_project;
9704 if ($project_id > 0) {
9706 $substitutionarray[
'__PROJECT_ID__@lazyload'] =
'/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id;
9707 $substitutionarray[
'__PROJECT_REF__@lazyload'] =
'/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id;
9708 $substitutionarray[
'__PROJECT_NAME__@lazyload'] =
'/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id;
9714 '@phan-var-force Facture $object';
9716 $substitutionarray[
'__INVOICE_SITUATION_NUMBER__'] = isset(
$object->situation_counter) ?
$object->situation_counter :
'';
9719 '@phan-var-force Expedition $object';
9721 $substitutionarray[
'__SHIPPINGTRACKNUM__'] =
$object->tracking_number;
9722 $substitutionarray[
'__SHIPPINGTRACKNUMURL__'] =
$object->tracking_url;
9723 $substitutionarray[
'__SHIPPINGMETHOD__'] =
$object->shipping_method;
9726 '@phan-var-force Reception $object';
9728 $substitutionarray[
'__RECEPTIONTRACKNUM__'] =
$object->tracking_number;
9729 $substitutionarray[
'__RECEPTIONTRACKNUMURL__'] =
$object->tracking_url;
9733 '@phan-var-force Contrat $object';
9735 $dateplannedstart =
'';
9736 $datenextexpiration =
'';
9737 foreach (
$object->lines as $line) {
9738 if ($line->date_start > $dateplannedstart) {
9739 $dateplannedstart = $line->date_start;
9741 if ($line->statut == 4 && $line->date_end && (!$datenextexpiration || $line->date_end < $datenextexpiration)) {
9742 $datenextexpiration = $line->date_end;
9745 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE__'] =
dol_print_date($dateplannedstart,
'day');
9746 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE_RFC__'] =
dol_print_date($dateplannedstart,
'dayrfc');
9747 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATETIME__'] =
dol_print_date($dateplannedstart,
'standard');
9749 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE__'] =
dol_print_date($datenextexpiration,
'day');
9750 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE_RFC__'] =
dol_print_date($datenextexpiration,
'dayrfc');
9751 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATETIME__'] =
dol_print_date($datenextexpiration,
'standard');
9755 '@phan-var-force Ticket $object';
9757 $substitutionarray[
'__TICKET_TRACKID__'] =
$object->track_id;
9758 $substitutionarray[
'__TICKET_SUBJECT__'] =
$object->subject;
9759 $substitutionarray[
'__TICKET_TYPE__'] =
$object->type_code;
9760 $substitutionarray[
'__TICKET_SEVERITY__'] =
$object->severity_code;
9761 $substitutionarray[
'__TICKET_CATEGORY__'] =
$object->category_code;
9762 $substitutionarray[
'__TICKET_ANALYTIC_CODE__'] =
$object->category_code;
9763 $substitutionarray[
'__TICKET_MESSAGE__'] =
$object->message;
9764 $substitutionarray[
'__TICKET_PROGRESSION__'] =
$object->progress;
9765 $userstat =
new User($db);
9766 if (
$object->fk_user_assign > 0) {
9767 $userstat->fetch(
$object->fk_user_assign);
9768 $substitutionarray[
'__TICKET_USER_ASSIGN__'] =
dolGetFirstLastname($userstat->firstname, $userstat->lastname);
9771 if (
$object->fk_user_create > 0) {
9772 $userstat->fetch(
$object->fk_user_create);
9773 $substitutionarray[
'__USER_CREATE__'] =
dolGetFirstLastname($userstat->firstname, $userstat->lastname);
9779 if (!is_object($extrafields)) {
9782 $extrafields->fetch_name_optionals_label(
$object->table_element,
true);
9784 if (
$object->fetch_optionals() > 0) {
9785 if (is_array($extrafields->attributes[
$object->table_element][
'label']) && count($extrafields->attributes[
$object->table_element][
'label']) > 0) {
9786 foreach ($extrafields->attributes[
$object->table_element][
'label'] as $key => $label) {
9787 if ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'date') {
9788 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'__'] =
dol_print_date(
$object->array_options[
'options_'.$key],
'day');
9789 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'_LOCALE__'] =
dol_print_date(
$object->array_options[
'options_'.$key],
'day',
'tzserver', $outputlangs);
9790 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'_RFC__'] =
dol_print_date(
$object->array_options[
'options_'.$key],
'dayrfc');
9791 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'datetime') {
9792 $datetime =
$object->array_options[
'options_'.$key];
9793 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhour') :
'');
9794 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'_LOCALE__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhour',
'tzserver', $outputlangs) :
'');
9795 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'_DAY_LOCALE__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'day',
'tzserver', $outputlangs) :
'');
9796 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'_RFC__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhourrfc') :
'');
9797 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'phone') {
9798 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'__'] =
dol_print_phone(
$object->array_options[
'options_'.$key]);
9799 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'price') {
9800 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'__'] =
$object->array_options[
'options_'.$key];
9801 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'_FORMATED__'] =
price(
$object->array_options[
'options_'.$key]);
9802 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'_FORMATTED__'] =
price(
$object->array_options[
'options_'.$key]);
9803 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] !=
'separator') {
9804 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'__'] = !empty(
$object->array_options[
'options_'.$key]) ?
$object->array_options[
'options_'.$key] :
'';
9812 if (empty($substitutionarray[
'__REF__'])) {
9816 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
9817 $outputlangs->loadLangs(array(
'paypal',
'other'));
9820 $typeforonlinepayment =
'free';
9822 $typeforonlinepayment =
'order';
9825 $typeforonlinepayment =
'invoice';
9828 $typeforonlinepayment =
'member';
9829 if (!empty(
$object->last_subscription_amount)) {
9830 $amounttouse =
$object->last_subscription_amount;
9834 $typeforonlinepayment =
'contract';
9837 $typeforonlinepayment =
'ficheinter';
9840 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $substitutionarray[
'__REF__'], $amounttouse);
9845 $substitutionarray[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = ($paymenturl ? str_replace(
'\n',
"\n", $outputlangs->trans(
"PredefinedMailContentLink", $paymenturl)) :
'');
9846 $substitutionarray[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
9850 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions_be.lib.php';
9855 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
$object->getLastMainDocLink(
$object->element);
9857 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
'';
9860 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
$object->getLastMainDocLink(
$object->element);
9862 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
'';
9865 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
$object->getLastMainDocLink(
$object->element);
9867 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
'';
9870 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
$object->getLastMainDocLink(
$object->element);
9872 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
'';
9875 $substitutionarray[
'__DIRECTDOWNLOAD_URL_FICHINTER__'] =
$object->getLastMainDocLink(
$object->element);
9877 $substitutionarray[
'__DIRECTDOWNLOAD_URL_FICHINTER__'] =
'';
9880 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
$object->getLastMainDocLink(
$object->element);
9882 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
'';
9886 '@phan-var-force Propal $object';
9888 $substitutionarray[
'__URL_PROPOSAL__'] = DOL_MAIN_URL_ROOT.
"/comm/propal/card.php?id=".
$object->id;
9889 require_once DOL_DOCUMENT_ROOT.
'/core/lib/signature.lib.php';
9890 $substitutionarray[
'__ONLINE_SIGN_URL__'] = getOnlineSignatureUrl(0,
'proposal',
$object->ref, 1,
$object);
9893 '@phan-var-force Commande $object';
9895 $substitutionarray[
'__URL_ORDER__'] = DOL_MAIN_URL_ROOT.
"/commande/card.php?id=".
$object->id;
9898 '@phan-var-force Facture $object';
9900 $substitutionarray[
'__URL_INVOICE__'] = DOL_MAIN_URL_ROOT.
"/compta/facture/card.php?id=".
$object->id;
9903 '@phan-var-force Contrat $object';
9905 $substitutionarray[
'__URL_CONTRACT__'] = DOL_MAIN_URL_ROOT.
"/contrat/card.php?id=".
$object->id;
9906 require_once DOL_DOCUMENT_ROOT.
'/core/lib/signature.lib.php';
9907 $substitutionarray[
'__ONLINE_SIGN_URL__'] = getOnlineSignatureUrl(0,
'contract',
$object->ref, 1,
$object);
9910 '@phan-var-force Fichinter $object';
9912 $substitutionarray[
'__URL_FICHINTER__'] = DOL_MAIN_URL_ROOT.
"/fichinter/card.php?id=".
$object->id;
9913 require_once DOL_DOCUMENT_ROOT.
'/core/lib/signature.lib.php';
9914 $substitutionarray[
'__ONLINE_SIGN_FICHINTER_URL__'] = getOnlineSignatureUrl(0,
'fichinter',
$object->ref, 1,
$object);
9916 if (is_object(
$object) &&
$object->element ==
'supplier_proposal') {
9917 '@phan-var-force SupplierProposal $object';
9919 $substitutionarray[
'__URL_SUPPLIER_PROPOSAL__'] = DOL_MAIN_URL_ROOT.
"/supplier_proposal/card.php?id=".
$object->id;
9921 if (is_object(
$object) &&
$object->element ==
'invoice_supplier') {
9922 '@phan-var-force FactureFournisseur $object';
9924 $substitutionarray[
'__URL_SUPPLIER_INVOICE__'] = DOL_MAIN_URL_ROOT.
"/fourn/facture/card.php?id=".
$object->id;
9927 '@phan-var-force Expedition $object';
9929 $substitutionarray[
'__URL_SHIPMENT__'] = DOL_MAIN_URL_ROOT.
"/expedition/card.php?id=".
$object->id;
9934 '@phan-var-force ActionComm $object';
9936 $substitutionarray[
'__EVENT_LABEL__'] =
$object->label;
9937 $substitutionarray[
'__EVENT_TYPE__'] = $outputlangs->trans(
"Action".
$object->type_code);
9939 $substitutionarray[
'__EVENT_TIME__'] =
dol_print_date(
$object->datep,
'hour',
'auto', $outputlangs);
9943 if ((empty($exclude) || !in_array(
'objectamount', $exclude)) && (empty($include) || in_array(
'objectamount', $include))) {
9944 '@phan-var-force Facture|FactureRec $object';
9946 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functionsnumtoword.lib.php';
9949 $substitutionarray[
'__DATE_DUE_YMD__'] = is_object(
$object) ? (isset(
$object->date_lim_reglement) ?
dol_print_date(
$object->date_lim_reglement,
'day',
false, $outputlangs) : null) :
'';
9951 $substitutionarray[
'__DATE_DUE_YMD_TEXT__'] = is_object(
$object) ? (isset(
$object->date_lim_reglement) ?
dol_print_date(
$object->date_lim_reglement,
'daytext',
false, $outputlangs) : null) :
'';
9953 $already_payed_all = 0;
9958 $substitutionarray[
'__AMOUNT_EXCL_TAX__'] = is_object(
$object) ?
$object->total_ht :
'';
9962 $substitutionarray[
'__AMOUNT__'] = is_object(
$object) ?
$object->total_ttc :
'';
9966 $substitutionarray[
'__AMOUNT_REMAIN__'] = is_object(
$object) ?
price2num(
$object->total_ttc - $already_payed_all,
'MT') :
'';
9968 $substitutionarray[
'__AMOUNT_VAT__'] = is_object(
$object) ? (isset(
$object->total_vat) ?
$object->total_vat :
$object->total_tva) :
'';
9972 if ($onlykey != 2 || $mysoc->useLocalTax(1)) {
9973 $substitutionarray[
'__AMOUNT_TAX2__'] = is_object(
$object) ?
$object->total_localtax1 :
'';
9975 if ($onlykey != 2 || $mysoc->useLocalTax(2)) {
9976 $substitutionarray[
'__AMOUNT_TAX3__'] = is_object(
$object) ?
$object->total_localtax2 :
'';
9980 $substitutionarray[
'__AMOUNT_EXCL_TAX_FORMATTED__'] = is_object(
$object) ? (
$object->total_ht ?
price(
$object->total_ht, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null) :
'';
9981 $substitutionarray[
'__AMOUNT_FORMATTED__'] = is_object(
$object) ? (
$object->total_ttc ?
price(
$object->total_ttc, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null) :
'';
9982 $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) :
'';
9983 $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)) :
'';
9984 if ($onlykey != 2 || $mysoc->useLocalTax(1)) {
9985 $substitutionarray[
'__AMOUNT_TAX2_FORMATTED__'] = is_object(
$object) ? (
$object->total_localtax1 ?
price(
$object->total_localtax1, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null) :
'';
9987 if ($onlykey != 2 || $mysoc->useLocalTax(2)) {
9988 $substitutionarray[
'__AMOUNT_TAX3_FORMATTED__'] = is_object(
$object) ? (
$object->total_localtax2 ?
price(
$object->total_localtax2, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null) :
'';
9991 if ($onlykey != 2) {
9992 $substitutionarray[
'__AMOUNT_EXCL_TAX_FORMATED__'] = $substitutionarray[
'__AMOUNT_EXCL_TAX_FORMATTED__'];
9993 $substitutionarray[
'__AMOUNT_FORMATED__'] = $substitutionarray[
'__AMOUNT_FORMATTED__'];
9994 $substitutionarray[
'__AMOUNT_REMAIN_FORMATED__'] = $substitutionarray[
'__AMOUNT_REMAIN_FORMATTED__'];
9995 $substitutionarray[
'__AMOUNT_VAT_FORMATED__'] = $substitutionarray[
'__AMOUNT_VAT_FORMATTED__'];
9996 if ($mysoc instanceof
Societe && $mysoc->useLocalTax(1)) {
9997 $substitutionarray[
'__AMOUNT_TAX2_FORMATED__'] = $substitutionarray[
'__AMOUNT_TAX2_FORMATTED__'];
9999 if ($mysoc instanceof
Societe && $mysoc->useLocalTax(2)) {
10000 $substitutionarray[
'__AMOUNT_TAX3_FORMATED__'] = $substitutionarray[
'__AMOUNT_TAX3_FORMATTED__'];
10004 $substitutionarray[
'__AMOUNT_MULTICURRENCY__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
$object->multicurrency_total_ttc :
'';
10005 $substitutionarray[
'__AMOUNT_MULTICURRENCY_TEXT__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
dol_convertToWord(
$object->multicurrency_total_ttc, $outputlangs,
'',
true) :
'';
10006 $substitutionarray[
'__AMOUNT_MULTICURRENCY_TEXTCURRENCY__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
dol_convertToWord(
$object->multicurrency_total_ttc, $outputlangs,
$object->multicurrency_code,
true) :
'';
10007 $substitutionarray[
'__MULTICURRENCY_CODE__'] = (is_object(
$object) && isset(
$object->multicurrency_code)) ?
$object->multicurrency_code :
'';
10011 if ($onlykey != 2) {
10012 $substitutionarray[
'__TOTAL_TTC__'] = is_object(
$object) ?
$object->total_ttc :
'';
10013 $substitutionarray[
'__TOTAL_HT__'] = is_object(
$object) ?
$object->total_ht :
'';
10014 $substitutionarray[
'__TOTAL_VAT__'] = is_object(
$object) ? (isset(
$object->total_vat) ?
$object->total_vat :
$object->total_tva) :
'';
10019 if ((empty($exclude) || !in_array(
'date', $exclude)) && (empty($include) || in_array(
'date', $include))) {
10020 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
10030 $daytext = $outputlangs->trans(
'Day'.$tmp[
'wday']);
10032 $substitutionarray = array_merge($substitutionarray, array(
10033 '__NOW_TMS__' => (
string) $now,
10034 '__NOW_TMS_YMD__' =>
dol_print_date($now,
'day',
'auto', $outputlangs),
10035 '__DAY__' => (
string) $tmp[
'mday'],
10036 '__DAY_TEXT__' => $daytext,
10037 '__DAY_TEXT_SHORT__' =>
dol_trunc($daytext, 3,
'right',
'UTF-8', 1),
10038 '__DAY_TEXT_MIN__' =>
dol_trunc($daytext, 1,
'right',
'UTF-8', 1),
10039 '__MONTH__' => (
string) $tmp[
'mon'],
10040 '__MONTH_TEXT__' => $outputlangs->trans(
'Month'.sprintf(
"%02d", $tmp[
'mon'])),
10041 '__MONTH_TEXT_SHORT__' => $outputlangs->trans(
'MonthShort'.sprintf(
"%02d", $tmp[
'mon'])),
10042 '__MONTH_TEXT_MIN__' => $outputlangs->trans(
'MonthVeryShort'.sprintf(
"%02d", $tmp[
'mon'])),
10043 '__YEAR__' => (
string) $tmp[
'year'],
10044 '__YEAR_PREVIOUS_MONTH__' => (
string) $tmp3[
'year'],
10045 '__YEAR_NEXT_MONTH__' => (
string) $tmp5[
'year'],
10046 '__PREVIOUS_DAY__' => (
string) $tmp2[
'day'],
10047 '__PREVIOUS_MONTH__' => (
string) $tmp3[
'month'],
10048 '__PREVIOUS_MONTH_TEXT__' => $outputlangs->trans(
'Month'.sprintf(
"%02d", $tmp3[
'month'])),
10049 '__PREVIOUS_MONTH_TEXT_SHORT__' => $outputlangs->trans(
'MonthShort'.sprintf(
"%02d", $tmp3[
'month'])),
10050 '__PREVIOUS_MONTH_TEXT_MIN__' => $outputlangs->trans(
'MonthVeryShort'.sprintf(
"%02d", $tmp3[
'month'])),
10051 '__PREVIOUS_YEAR__' => (
string) ($tmp[
'year'] - 1),
10052 '__NEXT_DAY__' => (
string) $tmp4[
'day'],
10053 '__NEXT_MONTH__' => (
string) $tmp5[
'month'],
10054 '__NEXT_MONTH_TEXT__' => $outputlangs->trans(
'Month'.sprintf(
"%02d", $tmp5[
'month'])),
10055 '__NEXT_MONTH_TEXT_SHORT__' => $outputlangs->trans(
'MonthShort'.sprintf(
"%02d", $tmp5[
'month'])),
10056 '__NEXT_MONTH_TEXT_MIN__' => $outputlangs->trans(
'MonthVeryShort'.sprintf(
"%02d", $tmp5[
'month'])),
10057 '__NEXT_YEAR__' => (
string) ($tmp[
'year'] + 1),
10061 if (isModEnabled(
'multicompany')) {
10062 $substitutionarray = array_merge($substitutionarray, array(
'__ENTITY_ID__' =>
$conf->entity));
10064 if ((empty($exclude) || !in_array(
'system', $exclude)) && (empty($include) || in_array(
'user', $include))) {
10065 $substitutionarray[
'__DOL_MAIN_URL_ROOT__'] = DOL_MAIN_URL_ROOT;
10066 $substitutionarray[
'__(AnyTranslationKey)__'] = $outputlangs->trans(
'TranslationOfKey');
10067 $substitutionarray[
'__(AnyTranslationKey|langfile)__'] = $outputlangs->trans(
'TranslationOfKey').
' (load also language file before)';
10068 $substitutionarray[
'__[AnyConstantKey]__'] = $outputlangs->trans(
'ValueOfConstantKey');
10073 return $substitutionarray;
10092function make_substitutions($text, $substitutionarray, $outputlangs =
null, $converttextinhtmlifnecessary = 0)
10094 global
$conf, $db, $langs;
10096 if (!is_array($substitutionarray)) {
10097 return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions';
10100 if (empty($outputlangs)) {
10101 $outputlangs = $langs;
10111 if (is_object($outputlangs)) {
10113 while (preg_match(
'/__\(([^\)]+)\)__/', $text, $reg)) {
10115 $tmp = explode(
'|', $reg[1]);
10116 if (!empty($tmp[1])) {
10117 $outputlangs->load($tmp[1]);
10120 $value = $outputlangs->transnoentitiesnoconv($reg[1]);
10122 if (empty($converttextinhtmlifnecessary)) {
10124 $text = preg_replace(
'/__\('.preg_quote($reg[1],
'/').
'\)__/', $msgishtml ?
dol_htmlentitiesbr($value) : $value, $text);
10126 if (! $msgishtml) {
10130 if ($valueishtml) {
10138 $text = preg_replace(
'/__\('.preg_quote($reg[1],
'/').
'\)__/', $value, $text);
10146 while (preg_match(
'/__\[([^\]]+)\]__/', $text, $reg)) {
10147 $keyfound = $reg[1];
10149 $value =
'*****forbidden*****';
10151 $value = empty(
$conf->global->$keyfound) ?
'' :
$conf->global->$keyfound;
10154 if (empty($converttextinhtmlifnecessary)) {
10156 $text = preg_replace(
'/__\['.preg_quote($keyfound,
'/').
'\]__/', $msgishtml ?
dol_htmlentitiesbr($value) : $value, $text);
10158 if (! $msgishtml) {
10161 if ($valueishtml) {
10169 $text = preg_replace(
'/__\['.preg_quote($keyfound,
'/').
'\]__/', $value, $text);
10174 foreach ($substitutionarray as $key => $value) {
10175 if (!isset($value)) {
10179 if (($key ==
'__USER_SIGNATURE__' || $key ==
'__SENDEREMAIL_SIGNATURE__') && (
getDolGlobalString(
'MAIN_MAIL_DO_NOT_USE_SIGN'))) {
10183 if (empty($converttextinhtmlifnecessary)) {
10184 $text = str_replace((
string) $key, (
string) $value, $text);
10186 if (! $msgishtml) {
10189 if ($valueishtml) {
10196 $text = str_replace((
string) $key, (
string) $value, $text);
10212 $memory_object_list = array();
10213 foreach ($substitutionarray as $key => $value) {
10214 $lazy_load_arr = array();
10215 if (preg_match(
'/(__[A-Z\_]+__)@lazyload$/', $key, $lazy_load_arr)) {
10216 if (isset($lazy_load_arr[1]) && !empty($lazy_load_arr[1])) {
10217 $key_to_substitute = $lazy_load_arr[1];
10218 if (preg_match(
'/' . preg_quote($key_to_substitute,
'/') .
'/', $text)) {
10219 $param_arr = explode(
':', (
string) $value);
10221 if (count($param_arr) == 4) {
10222 $path = $param_arr[0];
10223 $class = $param_arr[1];
10224 $method = $param_arr[2];
10225 $id = (int) $param_arr[3];
10228 if (!isset($memory_object_list[$class])) {
10230 require_once DOL_DOCUMENT_ROOT . $path;
10231 if (class_exists($class)) {
10232 $memory_object_list[$class] = array(
10240 if (isset($memory_object_list[$class]) && isset($memory_object_list[$class][
'list'])) {
10241 if (method_exists($class, $method)) {
10242 if (!isset($memory_object_list[$class][
'list'][
$id])) {
10243 $tmpobj =
new $class($db);
10245 $valuetouseforsubstitution = $tmpobj->$method(
$id, $key_to_substitute);
10246 $memory_object_list[$class][
'list'][
$id] = $tmpobj;
10249 $tmpobj = $memory_object_list[$class][
'list'][
$id];
10251 $valuetouseforsubstitution = $tmpobj->$method(
$id, $key_to_substitute,
true);
10254 $text = str_replace((
string) $key_to_substitute, (
string) $valuetouseforsubstitution, $text);
10280 global
$conf, $user;
10282 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
10287 $dirsubstitutions = array_merge(array(), (array)
$conf->modules_parts[
'substitutions']);
10289 foreach ($dirsubstitutions as $reldir) {
10297 $substitfiles =
dol_dir_list($dir,
'files', 0,
'functions_');
10298 foreach ($substitfiles as $substitfile) {
10300 if (preg_match(
'/functions_(.*)\.lib\.php/i', $substitfile[
'name'], $reg)) {
10303 dol_syslog(
"Library ".$substitfile[
'name'].
" found into ".$dir);
10305 require_once $dir.$substitfile[
'name'];
10307 $function_name = $module.
"_".$callfunc;
10308 if (function_exists($function_name)) {
10309 $function_name($substitutionarray, $outputlangs,
$object, $parameters);
10317 foreach ($substitutionarray as $key => $value) {
10318 $tags .=
'{'.$key.
'} => '.$value.
"\n";
10320 $substitutionarray = array_merge($substitutionarray, array(
'__ALL_TAGS__' => $tags));
10333function print_date_range($date_start, $date_end, $format =
'', $outputlangs =
null)
10335 print
get_date_range($date_start, $date_end, $format, $outputlangs);
10348function get_date_range($date_start, $date_end, $format =
'', $outputlangs =
null, $withparenthesis = 1)
10354 if (!is_object($outputlangs)) {
10355 $outputlangs = $langs;
10358 if ($date_start && $date_end) {
10359 $out .= ($withparenthesis ?
' (' :
'').$outputlangs->transnoentitiesnoconv(
'DateFromTo',
dol_print_date($date_start, $format,
false, $outputlangs),
dol_print_date($date_end, $format,
false, $outputlangs)).($withparenthesis ?
')' :
'');
10361 if ($date_start && !$date_end) {
10362 $out .= ($withparenthesis ?
' (' :
'').$outputlangs->transnoentitiesnoconv(
'DateFrom',
dol_print_date($date_start, $format,
false, $outputlangs)).($withparenthesis ?
')' :
'');
10364 if (!$date_start && $date_end) {
10365 $out .= ($withparenthesis ?
' (' :
'').$outputlangs->transnoentitiesnoconv(
'DateUntil',
dol_print_date($date_end, $format,
false, $outputlangs)).($withparenthesis ?
')' :
'');
10385 if ($nameorder < 0) {
10388 if ($nameorder == 1) {
10389 $ret .= $firstname;
10390 if ($firstname && $lastname) {
10394 } elseif ($nameorder == 2 || $nameorder == 3) {
10395 $ret .= $firstname;
10396 if (empty($ret) && $nameorder == 3) {
10401 if (empty($ret) && $nameorder == 5) {
10402 $ret .= $firstname;
10404 if ($nameorder == 0) {
10405 if ($firstname && $lastname) {
10408 $ret .= $firstname;
10427function setEventMessage($mesgs, $style =
'mesgs', $noduplicate = 0, $attop = 0)
10430 if (!is_array($mesgs)) {
10431 $mesgs = trim((
string) $mesgs);
10434 if (!empty($noduplicate) && isset($_SESSION[
'dol_events'][$style]) && in_array($mesgs, $_SESSION[
'dol_events'][$style])) {
10438 array_unshift($_SESSION[
'dol_events'][$style], $mesgs);
10440 $_SESSION[
'dol_events'][$style][] = $mesgs;
10445 foreach ($mesgs as $mesg) {
10446 $mesg = trim((
string) $mesg);
10448 if (!empty($noduplicate) && isset($_SESSION[
'dol_events'][$style]) && in_array($mesg, $_SESSION[
'dol_events'][$style])) {
10452 array_unshift($_SESSION[
'dol_events'][$style], $mesgs);
10454 $_SESSION[
'dol_events'][$style][] = $mesg;
10474function setEventMessages($mesg, $mesgs, $style =
'mesgs', $messagekey =
'', $noduplicate = 0, $attop = 0)
10476 if (empty($mesg) && empty($mesgs)) {
10484 if (empty($messagekey) || empty($_COOKIE[
"DOLUSER_HIDEMESSAGE".$messagekey])) {
10485 if (!in_array((
string) $style, array(
'mesgs',
'warnings',
'errors'))) {
10486 dol_print_error(
null,
'Bad parameter style='.$style.
' for setEventMessages');
10488 if (empty($mesgs)) {
10491 if (!empty($mesg) && !in_array($mesg, $mesgs)) {
10512 if (isset($_SESSION[
'dol_events'][
'mesgs'])) {
10513 if (empty($disabledoutputofmessages)) {
10516 unset($_SESSION[
'dol_events'][
'mesgs']);
10519 if (isset($_SESSION[
'dol_events'][
'errors'])) {
10520 if (empty($disabledoutputofmessages)) {
10523 unset($_SESSION[
'dol_events'][
'errors']);
10527 if (isset($_SESSION[
'dol_events'][
'warnings'])) {
10528 if (empty($disabledoutputofmessages)) {
10531 unset($_SESSION[
'dol_events'][
'warnings']);
10549function get_htmloutput_mesg($mesgstring =
'', $mesgarray = [], $style =
'ok', $keepembedded = 0)
10551 global
$conf, $langs;
10556 $divstart = $divend =
'';
10559 if ((empty(
$conf->use_javascript_ajax) ||
getDolGlobalString(
'MAIN_DISABLE_JQUERY_JNOTIFY') || defined(
'DISABLE_JQUERY_JNOTIFY') || $keepembedded) && !preg_match(
'/<div class=".*">/i', $out)) {
10560 $divstart =
'<div class="'.$style.
' clearboth">';
10561 $divend =
'</div>';
10564 if ((is_array($mesgarray) && count($mesgarray)) || $mesgstring) {
10565 $langs->load(
"errors");
10567 if (is_array($mesgarray) && count($mesgarray)) {
10568 foreach ($mesgarray as $message) {
10570 $out .= $langs->trans($message);
10571 if ($ret < count($mesgarray)) {
10578 $out .= $langs->trans($mesgstring);
10584 if (!empty(
$conf->use_javascript_ajax) && !
getDolGlobalString(
'MAIN_DISABLE_JQUERY_JNOTIFY') && !defined(
'DISABLE_JQUERY_JNOTIFY') && empty($keepembedded)) {
10585 $return =
'<script nonce="'.getNonce().
'">
10586 $(document).ready(function() {
10587 /* jnotify(message, preset of message type, keepmessage) */
10588 $.jnotify("'.
dol_escape_js($out).
'", "'.($style ==
"ok" ? 3000 : $style).
'", '.($style ==
"ok" ?
"false" :
"true").
',{ remove: function (){} } );
10628function dol_htmloutput_mesg($mesgstring =
'', $mesgarray = array(), $style =
'ok', $keepembedded = 0)
10630 if (empty($mesgstring) && (!is_array($mesgarray) || count($mesgarray) == 0)) {
10636 if (is_array($mesgarray)) {
10637 foreach ($mesgarray as $val) {
10638 if ($val && preg_match(
'/class="error"/i', $val)) {
10642 if ($val && preg_match(
'/class="warning"/i', $val)) {
10647 } elseif ($mesgstring && preg_match(
'/class="error"/i', $mesgstring)) {
10649 } elseif ($mesgstring && preg_match(
'/class="warning"/i', $mesgstring)) {
10652 if ($style ==
'error') {
10655 if ($style ==
'warning') {
10659 if ($iserror || $iswarning) {
10661 $mesgstring = preg_replace(
'/<\/div><div class="(error|warning)">/',
'<br>', $mesgstring);
10662 $mesgstring = preg_replace(
'/<div class="(error|warning)">/',
'', $mesgstring);
10663 $mesgstring = preg_replace(
'/<\/div>/',
'', $mesgstring);
10665 if (is_array($mesgarray)) {
10666 $newmesgarray = array();
10667 foreach ($mesgarray as $val) {
10668 if (is_string($val)) {
10669 $tmpmesgstring = preg_replace(
'/<\/div><div class="(error|warning)">/',
'<br>', $val);
10670 $tmpmesgstring = preg_replace(
'/<div class="(error|warning)">/',
'', $tmpmesgstring);
10671 $tmpmesgstring = preg_replace(
'/<\/div>/',
'', $tmpmesgstring);
10672 $newmesgarray[] = $tmpmesgstring;
10674 dol_syslog(
"Error call of dol_htmloutput_mesg with an array with a value that is not a string", LOG_WARNING);
10677 $mesgarray = $newmesgarray;
10679 print
get_htmloutput_mesg($mesgstring, $mesgarray, ($iserror ?
'error' :
'warning'), $keepembedded);
10721function dol_sort_array(&$array, $index, $order =
'asc', $natsort = 0, $case_sensitive = 0, $keepindex = 0)
10724 $order = strtolower($order);
10726 if (is_array($array)) {
10727 $sizearray = count($array);
10728 if ($sizearray > 0) {
10730 foreach (array_keys($array) as $key) {
10731 if (is_object($array[$key])) {
10732 $temp[$key] = empty($array[$key]->$index) ? 0 : $array[$key]->$index;
10735 $temp[$key] = empty($array[$key][$index]) ? 0 : $array[$key][$index];
10737 if ($natsort == -1) {
10738 $temp[$key] =
'___'.$temp[$key];
10742 if (empty($natsort) || $natsort == -1) {
10743 if ($order ==
'asc') {
10749 if ($case_sensitive) {
10752 natcasesort($temp);
10754 if ($order !=
'asc') {
10755 $temp = array_reverse($temp,
true);
10761 foreach (array_keys($temp) as $key) {
10762 (is_numeric($key) && empty($keepindex)) ? $sorted[] = $array[$key] : $sorted[$key] = $array[$key];
10781 $str = (string) $str;
10784 $strLength = strlen($str);
10785 for ($i = 0; $i < $strLength; $i++) {
10786 if (ord($str[$i]) < 0x80) {
10788 } elseif ((ord($str[$i]) & 0xE0) == 0xC0) {
10790 } elseif ((ord($str[$i]) & 0xF0) == 0xE0) {
10792 } elseif ((ord($str[$i]) & 0xF8) == 0xF0) {
10794 } elseif ((ord($str[$i]) & 0xFC) == 0xF8) {
10796 } elseif ((ord($str[$i]) & 0xFE) == 0xFC) {
10801 for ($j = 0; $j < $n; $j++) {
10802 if ((++$i == strlen($str)) || ((ord($str[$i]) & 0xC0) != 0x80)) {
10823 return preg_match(
'//u', $str) ? true :
false;
10835 if (function_exists(
'mb_check_encoding')) {
10837 if (!mb_check_encoding($str,
'ASCII')) {
10841 if (preg_match(
'/[^\x00-\x7f]/', $str)) {
10859 $tmp = ini_get(
"unicode.filesystem_encoding");
10860 if (empty($tmp) && !empty($_SERVER[
"WINDIR"])) {
10861 $tmp =
'iso-8859-1';
10870 if ($tmp ==
'iso-8859-1') {
10871 return mb_convert_encoding($str,
'ISO-8859-1',
'UTF-8');
10892function dol_getIdFromCode($db, $key, $tablename, $fieldkey =
'code', $fieldid =
'id', $entityfilter = 0, $filters =
'', $useCache =
true)
10902 if ($useCache && isset(
$conf->cache[
'codeid'][$tablename][$key][$fieldid])) {
10903 return $conf->cache[
'codeid'][$tablename][$key][$fieldid];
10906 dol_syslog(
'dol_getIdFromCode (value for field '.$fieldid.
' from key '.$key.
' not found into cache)', LOG_DEBUG);
10908 $sql =
"SELECT ".$fieldid.
" as valuetoget";
10909 $sql .=
" FROM ".MAIN_DB_PREFIX.$tablename;
10910 if ($fieldkey ==
'id' || $fieldkey ==
'rowid') {
10911 $sql .=
" WHERE ".$fieldkey.
" = ".((int) $key);
10913 $sql .=
" WHERE ".$fieldkey.
" = '".$db->escape($key).
"'";
10915 if (!empty($entityfilter)) {
10916 $sql .=
" AND entity IN (".getEntity($tablename).
")";
10922 $resql = $db->query($sql);
10924 $obj = $db->fetch_object($resql);
10927 $valuetoget = $obj->valuetoget;
10928 $conf->cache[
'codeid'][$tablename][$key][$fieldid] = $valuetoget;
10930 $conf->cache[
'codeid'][$tablename][$key][$fieldid] =
'';
10934 return $valuetoget;
10951 if ($matchrule == 1) {
10952 if ($var ==
'mainmenu') {
10954 return (preg_match(
'/^'.$regextext.
'/', $mainmenu));
10955 } elseif ($var ==
'leftmenu') {
10957 return (preg_match(
'/^'.$regextext.
'/', $leftmenu));
10959 return 'This variable is not accessible with dol_eval';
10962 return 'This value for matchrule is not implemented';
10976function verifCond($strToEvaluate, $onlysimplestring =
'1')
10980 if (isset($strToEvaluate) && $strToEvaluate !==
'') {
10983 $rep =
dol_eval($strToEvaluate, 1, 1, $onlysimplestring);
10984 $rights = (bool) $rep && (!is_string($rep) || strpos($rep,
'Bad string syntax to evaluate') ===
false);
11004function dol_eval($s, $returnvalue = 1, $hideerrors = 1, $onlysimplestring =
'1')
11006 if ($returnvalue != 1) {
11007 dol_syslog(
"Use of dol_eval with parameter returnvalue = 0 is now forbidden. Please fix this", LOG_ERR);
11030 $db, $langs, $user, $website, $websitepage,
11031 $action, $mainmenu, $leftmenu,
11040 defined(
'T_COALESCE_EQUAL') || define(
'T_COALESCE_EQUAL', PHP_INT_MAX);
11041 defined(
'T_FN') || define(
'T_FN', PHP_INT_MAX);
11044 defined(
'T_ATTRIBUTE') || define(
'T_ATTRIBUTE', PHP_INT_MAX);
11045 defined(
'T_MATCH') || define(
'T_MATCH', PHP_INT_MAX);
11046 defined(
'T_NAME_FULLY_QUALIFIED') || define(
'T_NAME_FULLY_QUALIFIED', PHP_INT_MAX);
11047 defined(
'T_NAME_QUALIFIED') || define(
'T_NAME_QUALIFIED', PHP_INT_MAX);
11048 defined(
'T_NAME_RELATIVE') || define(
'T_NAME_RELATIVE', PHP_INT_MAX);
11051 defined(
'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG') || define(
'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG', PHP_INT_MAX);
11052 defined(
'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG') || define(
'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG', PHP_INT_MAX);
11053 defined(
'T_ENUM') || define(
'T_ENUM', PHP_INT_MAX);
11054 defined(
'T_READONLY') || define(
'T_READONLY', PHP_INT_MAX);
11057 defined(
'T_PRIVATE_SET') || define(
'T_PRIVATE_SET', PHP_INT_MAX);
11058 defined(
'T_PROTECTED_SET') || define(
'T_PROTECTED_SET', PHP_INT_MAX);
11059 defined(
'T_PUBLIC_SET') || define(
'T_PUBLIC_SET', PHP_INT_MAX);
11061 $prohibited_token_ids = [
11067 'T_ABSTRACT',
'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG',
'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG',
'T_ATTRIBUTE',
11072 'T_CALLABLE',
'T_CATCH',
'T_CLASS',
'T_CLOSE_TAG',
'T_CONST',
11075 'T_DECLARE',
'T_DIR',
11078 'T_ECHO',
'T_ENDDECLARE',
'T_ENUM',
'T_EVAL',
'T_EXIT',
'T_EXTENDS',
11080 'T_FILE',
'T_FINAL',
'T_FINALLY',
'T_FN',
'T_FUNCTION',
'T_FUNC_C',
11081 'T_GLOBAL',
'T_GOTO',
11085 'T_IMPLEMENTS',
'T_INCLUDE',
'T_INCLUDE_ONCE',
'T_INSTEADOF',
'T_INTERFACE',
11095 'T_OPEN_TAG',
'T_OPEN_TAG_WITH_ECHO',
11097 'T_PRINT',
'T_PRIVATE',
'T_PROTECTED',
'T_PUBLIC',
11099 'T_READONLY',
'T_REQUIRE',
'T_REQUIRE_ONCE',
'T_RETURN',
11103 'T_THROW',
'T_TRAIT',
'T_TRAIT_C',
'T_TRY',
11104 'T_UNSET',
'T_UNSET_CAST',
'T_USE',
11117 $prohibited_variables = [
11118 '$_COOKIE',
'$_ENV',
'$_FILES',
'$GLOBALS',
'$_GET',
'$_POST',
'$_REQUEST',
'$_SERVER',
'$_SESSION',
11121 $prohibited_functions = [
11124 'override_function',
'session_id',
'session_create_id',
'session_regenerate_id',
11125 'call_user_func',
'call_user_func_array',
11126 'exec',
'passthru',
'shell_exec',
'system',
'proc_open',
'popen',
11127 'dol_eval',
'dol_eval_new',
'dol_eval_standard',
'dol_contctdesc',
'executeCLI',
'verifCond',
'GETPOST',
11128 'create_function',
'assert',
'mb_ereg_replace',
'mb_eregi_replace',
11129 'dol_compress_dir',
'dol_decode',
'dol_delete_file',
'dol_delete_dir',
'dol_delete_dir_recursive',
'dol_copy',
'archiveOrBackupFile',
11130 'fopen',
'file_put_contents',
'fputs',
'fputscsv',
'fwrite',
'fpassthru',
'mkdir',
'rmdir',
'symlink',
'touch',
'unlink',
'umask',
11131 'invoke',
'invokeArgs',
11132 'filter_input',
'filter_input_array',
'GETPOST',
11135 $prohibited_token_arrangements = [
11137 ' T_VARIABLE ( ',
' " ( ',
' \' ( ',
' T_CONSTANT_ENCAPSED_STRING ( ',
' ) ( ',
11140 $tokens = token_get_all(
"<?php return {$s};", TOKEN_PARSE);
11142 $tokens_arrangement =
' ';
11144 for ($i = 2,
$c = count($tokens) - 1; $i <
$c; ++$i) {
11145 if (is_array($tokens[$i])) {
11146 $token_id = $tokens[$i][0];
11147 $token_value = $tokens[$i][1];
11148 $token_name = token_name($tokens[$i][0]);
11150 $token_id = $tokens[$i];
11151 $token_value = $tokens[$i];
11152 $token_name = $tokens[$i];
11156 if (T_WHITESPACE === $token_id) {
11161 $tokens_arrangement .=
"{$token_name} ";
11164 if (T_VARIABLE === $token_id
11165 && in_array($token_value, $prohibited_variables,
true)
11167 return "« {$token_value} » is prohibited in « {$s} »";
11171 if (T_STRING === $token_id
11172 && in_array($token_value, $prohibited_functions,
true)
11174 return "« {$token_value} » is prohibited in « {$s} »";
11179 $maxi = count($prohibited_token_ids);
11180 for ($i = 0; $i < $maxi; ++$i) {
11181 if (
false !== strpos($tokens_arrangement,
" {$prohibited_token_ids[$i]} ")) {
11182 return "« {$prohibited_token_ids[$i]} » is prohibited in « {$s} »";
11187 $maxi = count($prohibited_token_arrangements);
11188 for ($i = 0; $i < $maxi; ++$i) {
11189 if (
false !== strpos($tokens_arrangement, $prohibited_token_arrangements[$i])) {
11190 return "« {$prohibited_token_arrangements[$i]} » is prohibited in « {$s} »";
11196 return @eval(
"return {$s};") ??
'';
11197 }
catch (Throwable $ex) {
11198 return "Exception during evaluation: ".$s.
" - ".$ex->getMessage();
11216function dol_eval_standard($s, $returnvalue = 1, $hideerrors = 1, $onlysimplestring =
'1')
11220 global $db, $langs, $user, $website, $websitepage;
11221 global $action, $mainmenu, $leftmenu;
11223 global $objectoffield;
11229 $isObBufferActive =
false;
11230 if (!in_array($onlysimplestring, array(
'0',
'1',
'2'))) {
11231 return "Bad call of dol_eval. Parameter onlysimplestring must be '0' (deprecated), '1' or '2'";
11233 if (!is_scalar($s)) {
11234 return "Bad call of dol_eval. First parameter must be a string, found ".var_export($s,
true);
11239 if ($onlysimplestring ==
'1' || $onlysimplestring ==
'2') {
11245 $specialcharsallowed =
'^$_+-.*>&|=!?():"\',/@';
11246 if ($onlysimplestring ==
'2') {
11247 $specialcharsallowed .=
'<[]';
11250 $specialcharsallowed .=
getDolGlobalString(
'MAIN_ALLOW_UNSECURED_SPECIAL_CHARS_IN_DOL_EVAL');
11252 if (preg_match(
'/[^a-z0-9\s'.preg_quote($specialcharsallowed,
'/').
']/i', $s)) {
11253 if ($returnvalue) {
11254 return 'Bad string syntax to evaluate (found chars that are not chars for a simple one line clean eval string): '.$s;
11256 dol_syslog(
'Bad string syntax to evaluate (found chars that are not chars for a simple one line clean eval string): '.$s, LOG_WARNING);
11262 $tmps = str_replace(
' ? ',
'__XXX__', $s);
11263 if (strpos($tmps,
'?') !==
false) {
11264 if ($returnvalue) {
11265 return 'Bad string syntax to evaluate (The char ? can be used only with a space before and after): '.$s;
11267 dol_syslog(
'Bad string syntax to evaluate (The char ? can be used only with a space before and after): '.$s, LOG_WARNING);
11273 if (preg_match(
'/<=?[^\s]/', $s)) {
11274 if ($returnvalue) {
11275 return 'Bad string syntax to evaluate (mode '.$onlysimplestring.
', found a < or <= without space before and after): '.$s;
11277 dol_syslog(
'Bad string syntax to evaluate (mode '.$onlysimplestring.
', found a < or <= without space before and after): '.$s, LOG_WARNING);
11283 if (preg_match(
'/\$[\w]*\s*\(/', $s)) {
11284 if ($returnvalue) {
11285 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;
11287 dol_syslog(
'Bad string syntax to evaluate (mode '.$onlysimplestring.
', found a call using "$abc(" or "$abc (" instead of using the direct name of the function): '.$s, LOG_WARNING);
11296 while ($scheck && $savescheck != $scheck) {
11297 $savescheck = $scheck;
11298 $scheck = preg_replace(
'/->[a-zA-Z0-9_]+\(/',
'->__METHOD__', $scheck);
11299 $scheck = preg_replace(
'/::[a-zA-Z0-9_]+\(/',
'->__METHOD__', $scheck);
11300 $scheck = preg_replace(
'/^\(+/',
'__PARENTHESIS__ ', $scheck);
11301 $scheck = preg_replace(
'/\&\&\s+\(/',
'__ANDPARENTHESIS__ ', $scheck);
11302 $scheck = preg_replace(
'/\|\|\s+\(/',
'__ORPARENTHESIS__ ', $scheck);
11303 $scheck = preg_replace(
'/^!?[a-zA-Z0-9_]+\(/',
'__FUNCTION__', $scheck);
11304 $scheck = preg_replace(
'/\s!?[a-zA-Z0-9_]+\(/',
'__FUNCTION__', $scheck);
11305 $scheck = preg_replace(
'/^!\(/',
'__NOTANDPARENTHESIS__', $scheck);
11306 $scheck = preg_replace(
'/\s!\(/',
' __NOTANDPARENTHESIS__', $scheck);
11307 $scheck = preg_replace(
'/(\^|\')\(/',
'__REGEXSTART__', $scheck);
11312 if (strpos($scheck,
'(') !==
false) {
11313 if ($returnvalue) {
11314 return 'Bad string syntax to evaluate (mode '.$onlysimplestring.
', found call of a function or method without using the direct name of the function): '.$s;
11316 dol_syslog(
'Bad string syntax to evaluate (mode '.$onlysimplestring.
', found call of a function or method without using the direct name of the function): '.$s, LOG_WARNING);
11325 if ($s ===
'Array') {
11326 if ($returnvalue) {
11327 return 'Bad string syntax to evaluate (value is Array): '.var_export($s,
true);
11329 dol_syslog(
'Bad string syntax to evaluate (value is Array): '.var_export($s,
true), LOG_WARNING);
11334 if (!
getDolGlobalString(
'MAIN_ALLOW_DOUBLE_COLON_IN_DOL_EVAL') && strpos($s,
'::') !==
false) {
11335 if ($returnvalue) {
11336 return 'Bad string syntax to evaluate (double : char is forbidden without setting MAIN_ALLOW_DOUBLE_COLON_IN_DOL_EVAL): '.$s;
11338 dol_syslog(
'Bad string syntax to evaluate (double : char is forbidden without setting MAIN_ALLOW_DOUBLE_COLON_IN_DOL_EVAL): '.$s, LOG_WARNING);
11343 if (strpos($s,
'`') !==
false) {
11344 if ($returnvalue) {
11345 return 'Bad string syntax to evaluate (backtick char is forbidden): '.$s;
11347 dol_syslog(
'Bad string syntax to evaluate (backtick char is forbidden): '.$s, LOG_WARNING);
11354 if (preg_match(
'/[^0-9]+\.[^0-9]+/', $s)) {
11355 if ($returnvalue) {
11356 return 'Bad string syntax to evaluate (dot char is forbidden): '.$s;
11358 dol_syslog(
'Bad string syntax to evaluate (dot char is forbidden): '.$s, LOG_WARNING);
11365 $forbiddenphpstrings = array(
'$$',
'$_',
'}[',
')(');
11366 $forbiddenphpstrings = array_merge($forbiddenphpstrings, array(
'_ENV',
'_SESSION',
'_COOKIE',
'_GET',
'_GLOBAL',
'_POST',
'_REQUEST',
'ReflectionFunction'));
11371 $forbiddenphpfunctions = array();
11372 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"override_function",
"session_id",
"session_create_id",
"session_regenerate_id"));
11373 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"get_defined_functions",
"get_defined_vars",
"get_defined_constants",
"get_declared_classes"));
11374 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"function",
"call_user_func",
"call_user_func_array"));
11376 $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"));
11377 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"usort",
"uasort",
"uksort",
"preg_replace_callback",
"preg_replace_callback_array",
"header_register_callback"));
11378 $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"));
11379 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"spl_autoload_register",
"spl_autoload_unregister",
"iterator_apply",
"session_set_save_handler"));
11380 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"forward_static_call",
"forward_static_call_array",
"register_postsend_function"));
11382 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"ob_start"));
11384 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"require",
"include",
"require_once",
"include_once"));
11385 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"exec",
"passthru",
"shell_exec",
"system",
"proc_open",
"popen"));
11386 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_eval",
"dol_eval_new",
"dol_eval_standard",
"dol_concatdesc",
"executeCLI",
"verifCond",
"GETPOST",
"dolEncrypt",
"dolDecrypt"));
11387 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"eval",
"create_function",
"assert",
"mb_ereg_replace"));
11388 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"readline_completion_function",
"readline_callback_handler_install"));
11389 $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"));
11390 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"chdir",
"dir",
"fopen",
"file",
"file_exists",
"file_get_contents",
"file_put_contents",
"fget",
"fgetc",
"fgetcsv",
"fputs",
"fputscsv",
"fpassthru",
"fscanf",
"fseek",
"fwrite",
"is_file",
"is_dir",
"is_link",
"mkdir",
"opendir",
"rmdir",
"scandir",
"symlink",
"touch",
"unlink",
"umask"));
11391 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"require",
"include"));
11394 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"base64".
"_".
"decode",
"rawurl".
"decode",
"url".
"decode",
"str".
"_rot13",
"hex".
"2bin"));
11395 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_concatdesc"));
11398 $forbiddenphpmethods = array(
'invoke',
'invokeArgs');
11400 $forbiddenphpregex =
'global\s*\$';
11401 $forbiddenphpregex .=
'|';
11402 $forbiddenphpregex .=
'\b('.implode(
'|', $forbiddenphpfunctions).
')\b';
11404 $forbiddenphpmethodsregex =
'->('.implode(
'|', $forbiddenphpmethods).
')';
11407 $oldstringtoclean = $s;
11408 $s = str_ireplace($forbiddenphpstrings,
'__forbiddenstring__', $s);
11409 $s = preg_replace(
'/'.$forbiddenphpregex.
'/i',
'__forbiddenstring__', $s);
11410 $s = preg_replace(
'/'.$forbiddenphpmethodsregex.
'/i',
'__forbiddenstring__', $s);
11412 }
while ($oldstringtoclean != $s);
11415 if (strpos($s,
'__forbiddenstring__') !==
false) {
11416 dol_syslog(
'Bad string syntax to evaluate: '.$s, LOG_WARNING);
11417 if ($returnvalue) {
11418 return 'Bad string syntax to evaluate: '.$s;
11420 dol_syslog(
'Bad string syntax to evaluate: '.$s);
11426 if ($returnvalue) {
11428 $isObBufferActive =
true;
11429 $tmps = $hideerrors ? @eval(
'return ' . $s .
';') : eval(
'return ' . $s .
';');
11430 $tmpo = ob_get_clean();
11431 $isObBufferActive =
false;
11433 print
'Bad string syntax to evaluate. Some data were output when it should not when evaluating: ' . $s;
11437 dol_syslog(
'Do not use anymore dol_eval with param returnvalue=0', LOG_WARNING);
11445 }
catch (Error $e) {
11446 if ($isObBufferActive) {
11448 $tmpo = ob_get_clean();
11449 $isObBufferActive =
false;
11451 $error =
'dol_eval try/catch error : ';
11452 $error .= $e->getMessage();
11454 if ($returnvalue) {
11455 return 'Exception during evaluation: '.$s;
11471 return (trim($element) !=
'');
11484 if (empty($codelang)) {
11488 if ($codelang ==
'auto') {
11489 return '<span class="fa fa-language"></span>';
11492 $langtocountryflag = array(
11494 'ca_ES' =>
'catalonia',
11498 'sw_SW' =>
'unknown',
11508 if (isset($langtocountryflag[$codelang])) {
11509 $flagImage = $langtocountryflag[$codelang];
11511 $tmparray = explode(
'_', $codelang);
11512 $flagImage = empty($tmparray[1]) ? $tmparray[0] : $tmparray[1];
11517 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
11518 $morecss = $reg[1];
11523 return '<span class="flag-sprite '.strtolower($flagImage).($morecss ?
' '.$morecss :
'').
'"'.($moreatt ?
' '.$moreatt :
'').(!$notitlealt ?
' title="'.$codelang.
'"' :
'').
'></span>';
11537 if (empty($countrycode)) {
11541 if (strtoupper($countrycode) ==
'MQ') {
11544 if (strtoupper($countrycode) ==
'SE') {
11547 if (strtoupper($countrycode) ==
'CH') {
11548 if ($mysoc->country_code ==
'FR') {
11551 if ($mysoc->country_code ==
'DE') {
11554 if ($mysoc->country_code ==
'IT') {
11736 $buildprimarykeytotest = strtolower($countrycode).
'-'.strtoupper($countrycode);
11737 if (in_array($buildprimarykeytotest, $locales)) {
11738 return strtolower($countrycode).
'_'.strtoupper($countrycode);
11741 if (function_exists(
'locale_get_primary_language') && function_exists(
'locale_get_region')) {
11742 foreach ($locales as $locale) {
11743 $locale_language = locale_get_primary_language($locale);
11744 $locale_region = locale_get_region($locale);
11745 if (strtoupper($countrycode) == $locale_region) {
11747 return strtolower($locale_language).
'_'.strtoupper($locale_region);
11751 dol_syslog(
"Warning Extension php-intl is not available", LOG_WARNING);
11789 global $hookmanager, $db;
11791 if (isset(
$conf->modules_parts[
'tabs'][$type]) && is_array(
$conf->modules_parts[
'tabs'][$type])) {
11792 foreach (
$conf->modules_parts[
'tabs'][$type] as $value) {
11793 $values = explode(
':', $value);
11796 if ($mode ==
'add' && !preg_match(
'/^\-/', $values[1])) {
11801 $posstart = strpos($str,
'(');
11802 if ($posstart > 0) {
11803 $posend = strpos($str,
')');
11804 if ($posstart > 0) {
11805 $res1 = substr($str, $posstart + 1, $posend - $posstart - 1);
11806 if (is_numeric($res1)) {
11807 $postab = (int) $res1;
11808 $values[1] =
'+' . substr($str, $posend + 1);
11812 if (count($values) == 6) {
11816 if ($values[0] != $type) {
11822 if ($filterorigmodule) {
11823 if (strpos($values[3],
'@')) {
11824 if ($filterorigmodule !=
'external') {
11828 if ($filterorigmodule !=
'core') {
11833 $langs->load($values[3]);
11835 if (preg_match(
'/SUBSTITUTION_([^_]+)/i', $values[2], $reg)) {
11837 $substitutionarray = array();
11842 $labeltemp = explode(
',', $values[2]);
11843 $label = $langs->trans($labeltemp[0]);
11845 if (!empty($labeltemp[1]) && is_object(
$object) && !empty(
$object->id)) {
11847 $classtoload = $labeltemp[1];
11848 if (class_exists($classtoload)) {
11849 $obj =
new $classtoload($db);
11850 $function = $labeltemp[3];
11851 if ($obj && $function && method_exists($obj, $function)) {
11853 $nbrec = $obj->$function(
$object->id, $obj);
11854 if (!empty($nbrec)) {
11855 $label .=
'<span class="badge marginleftonlyshort">'.$nbrec.
'</span>';
11863 $newtab[1] = $label;
11864 $newtab[2] = str_replace(
'+',
'', $values[1]);
11869 } elseif (count($values) == 5) {
11870 dol_syslog(
'Passing 5 values in tabs module_parts is deprecated. Please update to 6 with permissions.', LOG_WARNING);
11872 if ($values[0] != $type) {
11876 if ($filterorigmodule) {
11877 if (strpos($values[3],
'@')) {
11878 if ($filterorigmodule !=
'external') {
11882 if ($filterorigmodule !=
'core') {
11887 $langs->load($values[3]);
11889 if (preg_match(
'/SUBSTITUTION_([^_]+)/i', $values[2], $reg)) {
11890 $substitutionarray = array();
11894 $label = $langs->trans($values[2]);
11898 $newtab[1] = $label;
11899 $newtab[2] = str_replace(
'+',
'', $values[1]);
11903 $head = array_merge(array_slice($head, 0, $postab), array($newtab), array_slice($head, $postab));
11904 } elseif ($mode ==
'remove' && preg_match(
'/^\-/', $values[1])) {
11905 if ($values[0] != $type) {
11908 $tabname = str_replace(
'-',
'', $values[1]);
11909 foreach ($head as $key => $val) {
11910 $condition = (!empty($values[3]) ?
verifCond($values[3],
'2') : 1);
11912 if ($head[$key][2] == $tabname && $condition) {
11913 unset($head[$key]);
11922 if (!empty($hookmanager)) {
11923 $parameters = array(
'object' =>
$object,
'mode' => $mode,
'head' => &$head,
'filterorigmodule' => $filterorigmodule);
11925 $reshook = $hookmanager->executeHooks(
'completeTabsHead', $parameters,
$object);
11926 if ($reshook > 0) {
11927 $head = $hookmanager->resArray;
11929 $head = array_merge($head, $hookmanager->resArray);
11948 global
$conf, $hookmanager, $user, $langs;
11951 global $micro_start_time;
11953 if ($zone ==
'private') {
11954 print
"\n".
'<!-- Common footer for private page -->'.
"\n";
11956 print
"\n".
'<!-- Common footer for public page -->'.
"\n";
11960 print
"\n<!-- A div to store page_y POST parameter -->\n";
11961 print
'<div id="page_y" style="display: none;">'.(GETPOST(
'page_y') ?
GETPOST(
'page_y') :
'').
'</div>'.
"\n";
11963 $parameters = array();
11964 $reshook = $hookmanager->executeHooks(
'printCommonFooter', $parameters);
11965 if (empty($reshook)) {
11971 if (!empty(
$conf->use_javascript_ajax)) {
11972 print
"\n<!-- A script section to add menuhider handler on backoffice, manage focus and mandatory fields, tuning info, ... -->\n";
11973 print
'<script>'.
"\n";
11974 print
'jQuery(document).ready(function() {'.
"\n";
11976 if ($zone ==
'private' && empty(
$conf->dol_use_jmobile)) {
11978 print
'/* JS CODE TO ENABLE to manage handler to switch left menu page (menuhider) */'.
"\n";
11979 print
'jQuery("li.menuhider").click(function(event) {';
11980 print
' if (!$( "body" ).hasClass( "sidebar-collapse" )){ event.preventDefault(); }'.
"\n";
11981 print
' console.log("We click on .menuhider");'.
"\n";
11982 print
' $("body").toggleClass("sidebar-collapse")'.
"\n";
11987 if ($action ==
'create' || $action ==
'add' || $action ==
'edit' || (empty($action) && (preg_match(
'/new\.php/', $_SERVER[
"PHP_SELF"]))) || ((empty($action) || $action ==
'addline') && (preg_match(
'/card\.php/', $_SERVER[
"PHP_SELF"])))) {
11988 print
'/* JS CODE TO ENABLE to manage focus and mandatory form fields */'.
"\n";
11989 $relativepathstring = $_SERVER[
"PHP_SELF"];
11991 if (constant(
'DOL_URL_ROOT')) {
11992 $relativepathstring = preg_replace(
'/^'.preg_quote(constant(
'DOL_URL_ROOT'),
'/').
'/',
'', $relativepathstring);
11994 $relativepathstring = preg_replace(
'/^\//',
'', $relativepathstring);
11995 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
11998 if (!empty($user->default_values[$relativepathstring][
'focus'])) {
11999 foreach ($user->default_values[$relativepathstring][
'focus'] as $defkey => $defval) {
12001 if ($defkey !=
'_noquery_') {
12002 $tmpqueryarraytohave = explode(
'&', $defkey);
12004 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
12005 $tmpquerytohaveparam = explode(
'=', $tmpquerytohave);
12007 if (!GETPOSTISSET($tmpquerytohaveparam[0]) || ($tmpquerytohaveparam[1] !=
GETPOST($tmpquerytohaveparam[0]))) {
12011 if (!$foundintru) {
12020 print
'console.log("set the focus by executing jQuery(...).focus();")'.
"\n";
12021 foreach ($defval as $paramkey => $paramval) {
12023 print
'jQuery("input[name=\''.$paramkey.
'\']
").focus();'."\n
";
12024 print 'jQuery("textarea[
name=\
''.$paramkey.
'\']
").focus();'."\n
"; // TODO KO with ckeditor
12025 print 'jQuery("select[
name=\
''.$paramkey.
'\']
").focus();'."\n
"; // Not really useful, but we keep it in case of.
12030 if (!empty($user->default_values[$relativepathstring]['mandatory'])) {
12031 foreach ($user->default_values[$relativepathstring]['mandatory'] as $defkey => $defval) {
12033 if ($defkey != '_noquery_') {
12034 $tmpqueryarraytohave = explode('&', $defkey);
12036 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
12037 $tmpquerytohaveparam = explode('=', $tmpquerytohave);
12038 //print "console.log(
'".$tmpquerytohaveparam[0]." ".$tmpquerytohaveparam[1]." ".GETPOST($tmpquerytohaveparam[0])."');
";
12039 if (!GETPOSTISSET($tmpquerytohaveparam[0]) || ($tmpquerytohaveparam[1] != GETPOST($tmpquerytohaveparam[0]))) {
12043 if (!$foundintru) {
12046 //var_dump($defkey.'-'.$qualified);
12052 print 'console.log("set the js code to manage fields that are
set as mandatory
");'."\n
";
12054 foreach ($defval as $paramkey => $paramval) {
12055 // Solution 1: Add handler on submit to check if mandatory fields are empty
12056 print 'var form = $(\'[name="'.dol_escape_js($paramkey).'"]\').closest("form
");'."\n
";
12057 print "form.on(
'submit',
function(event) {
12058 var submitter = \$(
this).find(
':submit:focus').get(0);
12059 var buttonName = submitter ? \$(submitter).attr(
'name') :
'save';
12061 if (buttonName ==
'cancel') {
12062 console.log(
'We click on cancel button so we accept submit with no need to check mandatory fields');
12066 console.log(
'We did not click on cancel button but on something else, we check that field [name=".dol_escape_js($paramkey)."] is not empty');
12068 var tmpvalue = jQuery(
'[name=\"".dol_escape_js($paramkey)."\"]').val();
12069 let tmptypefield = jQuery(
'[name=\"".dol_escape_js($paramkey)."\"]').prop(
'nodeName').toLowerCase();
12071 if (tmptypefield ==
'textarea') {
12073 var tmpeditor = (typeof CKEDITOR !==
'undefined') ? CKEDITOR.instances[
'".dol_escape_js($paramkey)."'] : null;
12075 tmpvalue = tmpeditor.getData();
12076 console.log(
'For textarea tmpvalue is '+tmpvalue);
12080 let tmpvalueisempty =
false;
12081 if (tmpvalue ===
null || tmpvalue === undefined || tmpvalue ===
'' || tmpvalue === -1 || tmpvalue ===
'-1') {
12082 tmpvalueisempty =
true;
12084 if (tmpvalue ===
'0' && (tmptypefield ==
'select' || tmptypefield ==
'input')) {
12085 tmpvalueisempty =
true;
12087 if (tmpvalueisempty && buttonName !==
'cancel') {
12088 console.log(
'field has type '+tmptypefield+
' and is empty, we cancel the submit');
12089 event.preventDefault();
12090 event.stopPropagation();
12092 alert(
'".dol_escape_js($langs->transnoentitiesnoconv("ErrorFieldRequired", $paramkey).' (
'.$langs->transnoentitiesnoconv("CustomMandatoryFieldRule").')
')."');
12096 console.log(
'field has type '+tmptypefield+
' and is defined to '+tmpvalue);
12101 // Solution 2: Add property 'required' on input
12102 // so browser will check value and try to focus on it when submitting the form.
12103 //print 'setTimeout(function() {'; // If we want to wait that ckeditor beuatifier has finished its job.
12104 //print 'jQuery("input[
name=\
''.$paramkey.
'\']
").prop(\'required\',true);'."\n
";
12105 //print 'jQuery("textarea[
id=\
''.$paramkey.
'\']
").prop(\'required\',true);'."\n
";
12106 //print 'jQuery("select[
name=\
''.$paramkey.
'\']
").prop(\'required\',true);'."\n
";*/
12107 //print '// required on a select works only if key is "", so we add the required attributes but also we reset the key -1 or 0 to an empty string'."\n
";
12108 //print 'jQuery("select[
name=\
''.$paramkey.
'\'] option[value=\
'-1\']").prop(\'value\', \'\');'.
"\n";
12114 print
'jQuery(\':input[name="' .
dol_escape_js($paramkey) .
'"]\').closest("tr").find("td:first").addClass("fieldrequired");'.
"\n";
12118 print
'jQuery("input[name=\'cancel\']").click(function() {
12119 console.log("We click on cancel button so removed all required attribute");
12120 jQuery("input, textarea, select").each(function(){this.removeAttribute(\'required\');});
12130 if (!empty($_SERVER[
'MAIN_SHOW_TUNING_INFO']) ||
getDolGlobalString(
'MAIN_SHOW_TUNING_INFO')) {
12132 print
"/* JS CODE TO ENABLE to add memory info */\n";
12133 print
'window.console && console.log("';
12138 if (!empty($micro_start_time)) {
12139 $micro_end_time = microtime(
true);
12140 print
' - Build time: '.ceil(1000 * ($micro_end_time - $micro_start_time)).
' ms';
12143 if (function_exists(
"memory_get_usage")) {
12144 print
' - Mem: '.memory_get_usage();
12146 if (function_exists(
"memory_get_peak_usage")) {
12147 print
' - Real mem peak: '.memory_get_peak_usage(
true);
12149 if (function_exists(
"zend_loader_file_encoded")) {
12150 print
' - Zend encoded file: '.(zend_loader_file_encoded() ?
'yes' :
'no');
12155 print
"\n".
'</script>'.
"\n";
12161 foreach ($tmptagarray as $tmptag) {
12163 print
"<!-- JS CODE TO ENABLE for google analtics tag -->\n";
12165 <!-- Global site tag (gtag.js) - Google Analytics -->
12166 <script nonce="'.getNonce().
'" async src="https://www.googletagmanager.com/gtag/js?id='.trim($tmptag).
'"></script>
12168 window.dataLayer = window.dataLayer || [];
12169 function gtag(){dataLayer.push(arguments);}
12170 gtag(\'js\', new Date());
12172 gtag(\'config\', \''.trim($tmptag).
'\');
12179 // Add Xdebug coverage of code
12180 if (defined('XDEBUGCOVERAGE
')) {
12181 print_r(xdebug_get_code_coverage());
12184 // Add DebugBar data
12185 if ($user->hasRight('debugbar
', 'read
') && $debugbar instanceof DebugBar\DebugBar) {
12186 if (isset($debugbar['time
'])) {
12187 // @phan-suppress-next-line PhanPluginUnknownObjectMethodCall
12188 $debugbar['time
']->stopMeasure('pageaftermaster
');
12190 print '<!-- Output debugbar data -->
'."\n";
12191 $renderer = $debugbar->getJavascriptRenderer();
12192 print $renderer->render();
12193 } elseif (count($conf->logbuffer)) { // If there is some logs in buffer to show
12195 print "<!-- Start of log output\n";
12196 //print '<div
class=
"hidden">
'."\n";
12197 foreach ($conf->logbuffer as $logline) {
12198 print $logline."<br>\n";
12200 //print '</div>
'."\n";
12201 print "End of log output -->\n";
12215function dolExplodeIntoArray($string, $delimiter = ';
', $kv = '=
')
12217 if (is_null($string)) {
12221 if (preg_match('/^\[.*\]$/sm
', $delimiter) || preg_match('/^\(.*\)$/sm
', $delimiter)) {
12222 // This is a regex string
12223 $newdelimiter = $delimiter;
12225 // This is a simple string
12226 // @phan-suppress-next-line PhanPluginSuspiciousParamPositionInternal
12227 $newdelimiter = preg_quote($delimiter, '/
');
12230 if ($a = preg_split('/
'.$newdelimiter.'/
', $string)) {
12232 foreach ($a as $s) { // each part
12234 if ($pos = strpos($s, $kv)) { // key/value delimiter
12235 $ka[trim(substr($s, 0, $pos))] = trim(substr($s, $pos + strlen($kv)));
12236 } else { // key delimiter not found
12254function dolExplodeKeepIfQuotes($input)
12256 // Use regexp to capture words and section in quotes
12257 $matches = array();
12258 preg_match_all('/
"([^"]*)
"|\'([^\']*)\'|(\S+)/', $input, $matches);
12260 // Merge result and delete empty values
12262 $result = array_map(
12269 static function ($a, $b, $c) {
12285 return array_values(array_filter(
12293 static function ($val) {
12294 return $val !== '';
12306function dol_set_focus($selector)
12308 print "\n
".'<!-- Set focus onto a specific field -->'."\n
";
12309 print '<script nonce="'.getNonce().'">jQuery(document).ready(function() { console.log("Force focus by
dol_set_focus"); jQuery("'.dol_escape_js($selector).'").focus(); });</script>'."\n
";
12320function dol_getmypid()
12322 if (!function_exists('getmypid')) {
12323 return mt_rand(99900000, 99965535);
12325 return getmypid(); // May be a number on 64 bits (depending on OS)
12350function natural_search($fields, $value, $mode = 0, $nofirstand = 0)
12352 global $db, $langs;
12354 $value = trim($value);
12357 $value = preg_replace('/\*/', '%', $value); // Replace * with %
12360 $value = preg_replace('/([!<>=]+)\s+([0-9'.preg_quote($langs->trans("SeparatorDecimal
"), '/').'\-])/', '\1\2', $value); // Clean string '< 10' into '<10' so we can then explode on space to get all tests to do
12363 $value = preg_replace('/\s*\|\s*/', '|', $value);
12365 // Split criteria on ' ' but not if we are inside quotes.
12366 // For mode 3, the split is done later on the , only and not on the ' '.
12367 if ($mode != -3 && $mode != 3) {
12368 $crits = dolExplodeKeepIfQuotes($value);
12370 $crits = array($value);
12374 if (!is_array($fields)) {
12375 $fields = array($fields);
12377 $i1 = 0; // count the nb of "and
" criteria added (all fields / criteria)
12378 foreach ($crits as $crit) { // Loop on each AND criteria
12379 $crit = trim($crit);
12380 $i2 = 0; // count the nb of valid criteria added for this this first criteria
12383 foreach ($fields as $field) {
12385 $tmpcrits = explode('|', $crit);
12386 $i3 = 0; // count the nb of valid criteria added for this current field
12387 foreach ($tmpcrits as $tmpcrit) {
12388 if ($tmpcrit !== '0' && empty($tmpcrit)) {
12391 $tmpcrit = trim($tmpcrit);
12393 $newres .= (($i2 > 0 || $i3 > 0) ? ' OR ' : '');
12396 $newcrit = preg_replace('/([!<>=]+)/', '', $tmpcrit);
12399 preg_match('/([!<>=]+)/', $tmpcrit, $reg);
12400 if (!empty($reg[1])) {
12401 $operator = $reg[1];
12403 if ($newcrit != '') {
12404 $numnewcrit = price2num($newcrit);
12405 if (is_numeric($numnewcrit)) {
12406 $newres .= $db->sanitize($field).' '.$operator.' '.((float) $numnewcrit); // should be a numeric
12408 $newres .= '1 = 2'; // force false, we received a corrupted data
12410 $i3++; // a criteria was added to string
12413 $i2++; // a criteria for 1 more field was added to string
12414 } elseif ($mode == 2 || $mode == -2) {
12415 $crit = preg_replace('/[^\-0-9,]/', '', $crit); // ID are always integer
12416 $newres .= ($i2 > 0 ? ' OR ' : '').$db->sanitize($field)." ".($mode == -2 ? 'NOT ' : '');
12417 $newres .= $crit ? "IN (
".$db->sanitize($db->escape($crit)).")
" : "IN (0)
";
12419 $newres .= ' OR '.$db->sanitize($field).' IS NULL';
12421 $i2++; // a criteria for 1 more field was added to string
12422 } elseif ($mode == 3 || $mode == -3) {
12423 $tmparray = explode(',', $crit);
12424 if (count($tmparray)) {
12426 foreach ($tmparray as $val) {
12429 $listofcodes .= ($listofcodes ? ',' : '');
12430 $listofcodes .= "'".$db->escape($val)."'";
12433 $newres .= ($i2 > 0 ? ' OR ' : '').$db->sanitize($field)." ".($mode == -3 ? 'NOT ' : '')."IN (
".$db->sanitize($listofcodes, 1, 0, 1).")
";
12434 $i2++; // a criteria for 1 more field was added to string
12437 $newres .= ' OR '.$db->sanitize($field).' IS NULL';
12439 } elseif ($mode == 4) {
12440 $tmparray = explode(',', $crit);
12441 if (count($tmparray)) {
12443 foreach ($tmparray as $val) {
12446 $newres .= ($i2 > 0 ? " OR (
" : "(
").$db->sanitize($field)." LIKE
'".$db->escape($val).",%'";
12447 $newres .= ' OR '.$db->sanitize($field)." =
'".$db->escape($val)."'";
12448 $newres .= ' OR '.$db->sanitize($field)." LIKE
'%,".$db->escape($val)."'";
12449 $newres .= ' OR '.$db->sanitize($field)." LIKE
'%,".$db->escape($val).",%'";
12451 $i2++; // a criteria for 1 more field was added to string (we can add several criteria for the same field as it is a multiselect search criteria)
12455 } else { // $mode=0
12456 $tmpcrits = explode('|', $crit);
12457 $i3 = 0; // count the nb of valid criteria added for the current couple criteria/field
12458 foreach ($tmpcrits as $tmpcrit) { // loop on each OR criteria
12459 if ($tmpcrit !== '0' && empty($tmpcrit)) {
12462 $tmpcrit = trim($tmpcrit);
12464 if ($tmpcrit == '^$' || strpos($crit, '!') === 0) { // If we search empty, we must combined different OR fields with AND
12465 $newres .= (($i2 > 0 || $i3 > 0) ? ' AND ' : '');
12467 $newres .= (($i2 > 0 || $i3 > 0) ? ' OR ' : '');
12470 if (preg_match('/\.(id|rowid)$/', $field)) { // Special case for rowid that is sometimes a ref so used as a search field
12471 $newres .= $db->sanitize($field)." =
".(is_numeric($tmpcrit) ? ((float) $tmpcrit) : '0');
12473 $tmpcrit2 = $tmpcrit;
12478 if (preg_match('/^!/', $tmpcrit)) {
12479 $tmps .= $db->sanitize($field)." NOT LIKE
"; // ! as exclude character
12480 $tmpcrit2 = preg_replace('/^!/', '', $tmpcrit2);
12482 $tmps .= $db->sanitize($field)." LIKE
";
12486 if (preg_match('/^[\^\$]/
', $tmpcrit)) {
12488 $tmpcrit2 = preg_replace('/^[\^\$]/
', '', $tmpcrit2);
12490 if (preg_match('/[\^\$]$/
', $tmpcrit)) {
12492 $tmpcrit2 = preg_replace('/[\^\$]$/
', '', $tmpcrit2);
12495 if ($tmpcrit2 == '' || preg_match('/^!/
', $tmpcrit)) {
12499 $newres .= $tmpbefore;
12500 $newres .= $db->escape($tmpcrit2);
12501 $newres .= $tmpafter;
12503 if ($tmpcrit2 == '' || preg_match('/^!/', $tmpcrit)) {
12504 $newres .= " OR
".$field." IS NULL)
";
12511 $i2++; // a criteria for 1 more field was added to string
12515 $res = $res.($res ? ' AND ' : '').($i2 > 1 ? '(' : '').$newres.($i2 > 1 ? ')' : '');
12519 $res = ($nofirstand ? "" : " AND
")."(
".$res.")
";
12530function showDirectDownloadLink($object)
12535 $url = $object->getLastMainDocLink($object->element);
12537 $out .= img_picto($langs->trans("PublicDownloadLinkDesc
"), 'globe').' <span class="opacitymedium
">'.$langs->trans("DirectDownloadLink
").'</span><br>';
12539 $out .= '<div class="urllink
"><input type="text
" id="directdownloadlink
" class="quatrevingtpercent
" value="'.$url.'"></div>';
12540 $out .= ajax_autoselect("directdownloadlink
", '');
12542 $out .= '<div class="urllink
">'.$langs->trans("FileNotShared
").'</div>';
12556function getImageFileNameForSize($file, $extName, $extImgTarget = '')
12558 $dirName = dirname($file);
12559 if ($dirName == '.') {
12563 if (!in_array($extName, array('', '_small', '_mini'))) {
12564 return 'Bad parameter extName';
12567 $fileName = preg_replace('/(\.gif|\.jpeg|\.jpg|\.png|\.bmp|\.webp)$/i', '', $file); // We remove image extension, whatever is its case
12568 $fileName = basename($fileName);
12570 if (empty($extImgTarget)) {
12571 $extImgTarget = (preg_match('/\.jpg$/i', $file) ? '.jpg' : '');
12573 if (empty($extImgTarget)) {
12574 $extImgTarget = (preg_match('/\.jpeg$/i', $file) ? '.jpeg' : '');
12576 if (empty($extImgTarget)) {
12577 $extImgTarget = (preg_match('/\.gif$/i', $file) ? '.gif' : '');
12579 if (empty($extImgTarget)) {
12580 $extImgTarget = (preg_match('/\.png$/i', $file) ? '.png' : '');
12582 if (empty($extImgTarget)) {
12583 $extImgTarget = (preg_match('/\.bmp$/i', $file) ? '.bmp' : '');
12585 if (empty($extImgTarget)) {
12586 $extImgTarget = (preg_match('/\.webp$/i', $file) ? '.webp' : '');
12589 if (!$extImgTarget) {
12595 $subdir = 'thumbs/';
12598 return ($dirName ? $dirName.'/' : '').$subdir.$fileName.$extName.$extImgTarget; // New filename for thumb
12611function getAdvancedPreviewUrl($modulepart, $relativepath, $alldata = 0, $param = '')
12613 global $conf, $langs;
12615 if (empty($conf->use_javascript_ajax)) {
12619 $isAllowedForPreview = dolIsAllowedForPreview($relativepath);
12621 if ($alldata == 1) {
12622 if ($isAllowedForPreview) {
12623 return array('target' => '_blank', 'css' => 'documentpreview', 'url' => DOL_URL_ROOT.'/document.php?modulepart='.urlencode($modulepart).'&attachment=0&file='.urlencode($relativepath).($param ? '&'.$param : ''), 'mime' => dol_mimetype($relativepath));
12629 // old behavior, return a string
12630 if ($isAllowedForPreview) {
12631 $tmpurl = DOL_URL_ROOT.'/document.php?modulepart='.urlencode($modulepart).'&attachment=0&file='.urlencode($relativepath).($param ? '&'.$param : '');
12632 $title = $langs->transnoentities("Preview
");
12633 //$title = '%27-alert(document.domain)-%27'; // An example of js injection into a corrupted title string, that should be blocked by the dol_escape_uri().
12634 //$tmpurl = 'file='.urlencode("'-alert(document.domain)-'_small.jpg
"); // An example of tmpurl that should be blocked by the dol_escape_uri()
12636 // We need to do a dol_escape_uri() on the full string after the javascript: because such parts are the URI and when we click on such links, a RFC3986 decode is done,
12637 // by the browser, converting the %27 (like when having param file=abc%27def), or when having a corrupted title), into a ', BEFORE interpreting the content that can be a js code.
12638 // Using the dol_escape_uri guarantee that we encode for URI so decode retrieve original expected value.
12639 return 'javascript:'.dol_escape_uri('document_preview(\''.dol_escape_js($tmpurl).'\', \''.dol_escape_js(dol_mimetype($relativepath)).'\', \''.dol_escape_js($title).'\')');
12651function getLabelSpecialCode($idcode)
12655 $arrayspecialines = array(1 => 'Transport', 2 => 'EcoTax', 3 => 'Option');
12656 if ($idcode > 10) {
12657 return 'Module ID '.$idcode;
12659 if (!empty($arrayspecialines[$idcode])) {
12660 return $langs->trans($arrayspecialines[$idcode]);
12673function ajax_autoselect($htmlname, $addlink = '', $textonlink = 'Link')
12676 $out = '<script nonce="
'.getNonce().'">
12677 jQuery(document).ready(function () {
12678 jQuery("'.((strpos($htmlname, '.
') === 0 ? '' : '#
').$htmlname).'").click(function() { jQuery(this).select(); } );
12682 if ($textonlink === 'image') {
12683 $out .= ' <a href="'.$addlink.'" target="_blank
" rel="noopener noreferrer
">'.img_picto('', 'globe').'</a>';
12685 $out .= ' <a href="'.$addlink.'" target="_blank
" rel="noopener noreferrer
">'.$langs->trans("Link").'</a>';
12698function dolIsAllowedForPreview($file)
12700 // Check .noexe extension in filename
12701 if (preg_match('/\.noexe$/i', $file)) {
12705 // Check mime types
12706 $mime_preview = array('bmp', 'jpeg', 'png', 'gif', 'tiff', 'pdf', 'plain', 'css', 'webp');
12707 if (getDolGlobalString('MAIN_ALLOW_SVG_FILES_AS_IMAGES')) {
12708 $mime_preview[] = 'svg+xml';
12710 //$mime_preview[]='vnd.oasis.opendocument.presentation';
12711 //$mime_preview[]='archive';
12712 $num_mime = array_search(dol_mimetype($file, '', 1), $mime_preview);
12713 if ($num_mime !== false) {
12717 // By default, not allowed for preview
12731function dol_mimetype($file, $default = 'application/octet-stream', $mode = 0)
12734 $imgmime = 'other.png';
12735 $famime = 'file-o';
12738 $tmpfile = preg_replace('/\.noexe$/', '', $file);
12740 // Plain text files
12741 if (preg_match('/\.txt$/i', $tmpfile)) {
12742 $mime = 'text/plain';
12743 $imgmime = 'text.png';
12744 $famime = 'file-alt';
12745 } elseif (preg_match('/\.rtx$/i', $tmpfile)) {
12746 $mime = 'text/richtext';
12747 $imgmime = 'text.png';
12748 $famime = 'file-alt';
12749 } elseif (preg_match('/\.csv$/i', $tmpfile)) {
12750 $mime = 'text/csv';
12751 $imgmime = 'text.png';
12752 $famime = 'file-csv';
12753 } elseif (preg_match('/\.tsv$/i', $tmpfile)) {
12754 $mime = 'text/tab-separated-values';
12755 $imgmime = 'text.png';
12756 $famime = 'file-alt';
12757 } elseif (preg_match('/\.(cf|conf|log)$/i', $tmpfile)) {
12758 $mime = 'text/plain';
12759 $imgmime = 'text.png';
12760 $famime = 'file-alt';
12761 } elseif (preg_match('/\.ini$/i', $tmpfile)) {
12762 $mime = 'text/plain';
12763 $imgmime = 'text.png';
12765 $famime = 'file-alt';
12766 } elseif (preg_match('/\.md$/i', $tmpfile)) {
12767 $mime = 'text/plain';
12768 $imgmime = 'text.png';
12770 $famime = 'file-alt';
12771 } elseif (preg_match('/\.css$/i', $tmpfile)) {
12772 $mime = 'text/css';
12773 $imgmime = 'css.png';
12775 $famime = 'file-alt';
12776 } elseif (preg_match('/\.lang$/i', $tmpfile)) {
12777 $mime = 'text/plain';
12778 $imgmime = 'text.png';
12780 $famime = 'file-alt';
12781 } elseif (preg_match('/\.(crt|cer|key|pub)$/i', $tmpfile)) { // Certificate files
12782 $mime = 'text/plain';
12783 $imgmime = 'text.png';
12784 $famime = 'file-alt';
12785 } elseif (preg_match('/\.(html|htm|shtml)$/i', $tmpfile)) { // XML based (HTML/XML/XAML)
12786 $mime = 'text/html';
12787 $imgmime = 'html.png';
12789 $famime = 'file-alt';
12790 } elseif (preg_match('/\.(xml|xhtml)$/i', $tmpfile)) {
12791 $mime = 'text/xml';
12792 $imgmime = 'other.png';
12794 $famime = 'file-alt';
12795 } elseif (preg_match('/\.xaml$/i', $tmpfile)) {
12796 $mime = 'text/xml';
12797 $imgmime = 'other.png';
12799 $famime = 'file-alt';
12800 } elseif (preg_match('/\.bas$/i', $tmpfile)) { // Languages
12801 $mime = 'text/plain';
12802 $imgmime = 'text.png';
12804 $famime = 'file-code';
12805 } elseif (preg_match('/\.(c)$/i', $tmpfile)) {
12806 $mime = 'text/plain';
12807 $imgmime = 'text.png';
12809 $famime = 'file-code';
12810 } elseif (preg_match('/\.(cpp)$/i', $tmpfile)) {
12811 $mime = 'text/plain';
12812 $imgmime = 'text.png';
12814 $famime = 'file-code';
12815 } elseif (preg_match('/\.cs$/i', $tmpfile)) {
12816 $mime = 'text/plain';
12817 $imgmime = 'text.png';
12819 $famime = 'file-code';
12820 } elseif (preg_match('/\.(h)$/i', $tmpfile)) {
12821 $mime = 'text/plain';
12822 $imgmime = 'text.png';
12824 $famime = 'file-code';
12825 } elseif (preg_match('/\.(java|jsp)$/i', $tmpfile)) {
12826 $mime = 'text/plain';
12827 $imgmime = 'text.png';
12829 $famime = 'file-code';
12830 } elseif (preg_match('/\.php([0-9]{1})?$/i', $tmpfile)) {
12831 $mime = 'text/plain';
12832 $imgmime = 'php.png';
12834 $famime = 'file-code';
12835 } elseif (preg_match('/\.phtml$/i', $tmpfile)) {
12836 $mime = 'text/plain';
12837 $imgmime = 'php.png';
12839 $famime = 'file-code';
12840 } elseif (preg_match('/\.(pl|pm)$/i', $tmpfile)) {
12841 $mime = 'text/plain';
12842 $imgmime = 'pl.png';
12844 $famime = 'file-code';
12845 } elseif (preg_match('/\.sql$/i', $tmpfile)) {
12846 $mime = 'text/plain';
12847 $imgmime = 'text.png';
12849 $famime = 'file-code';
12850 } elseif (preg_match('/\.js$/i', $tmpfile)) {
12851 $mime = 'text/x-javascript';
12852 $imgmime = 'jscript.png';
12854 $famime = 'file-code';
12855 } elseif (preg_match('/\.odp$/i', $tmpfile)) { // Open office
12856 $mime = 'application/vnd.oasis.opendocument.presentation';
12857 $imgmime = 'ooffice.png';
12858 $famime = 'file-powerpoint';
12859 } elseif (preg_match('/\.ods$/i', $tmpfile)) {
12860 $mime = 'application/vnd.oasis.opendocument.spreadsheet';
12861 $imgmime = 'ooffice.png';
12862 $famime = 'file-excel';
12863 } elseif (preg_match('/\.odt$/i', $tmpfile)) {
12864 $mime = 'application/vnd.oasis.opendocument.text';
12865 $imgmime = 'ooffice.png';
12866 $famime = 'file-word';
12867 } elseif (preg_match('/\.mdb$/i', $tmpfile)) { // MS Office
12868 $mime = 'application/msaccess';
12869 $imgmime = 'mdb.png';
12871 } elseif (preg_match('/\.doc[xm]?$/i', $tmpfile)) {
12872 $mime = 'application/msword';
12873 $imgmime = 'doc.png';
12874 $famime = 'file-word';
12875 } elseif (preg_match('/\.dot[xm]?$/i', $tmpfile)) {
12876 $mime = 'application/msword';
12877 $imgmime = 'doc.png';
12878 $famime = 'file-word';
12879 } elseif (preg_match('/\.xlt(x)?$/i', $tmpfile)) {
12880 $mime = 'application/vnd.ms-excel';
12881 $imgmime = 'xls.png';
12882 $famime = 'file-excel';
12883 } elseif (preg_match('/\.xla(m)?$/i', $tmpfile)) {
12884 $mime = 'application/vnd.ms-excel';
12885 $imgmime = 'xls.png';
12886 $famime = 'file-excel';
12887 } elseif (preg_match('/\.xls$/i', $tmpfile)) {
12888 $mime = 'application/vnd.ms-excel';
12889 $imgmime = 'xls.png';
12890 $famime = 'file-excel';
12891 } elseif (preg_match('/\.xls[bmx]$/i', $tmpfile)) {
12892 $mime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
12893 $imgmime = 'xls.png';
12894 $famime = 'file-excel';
12895 } elseif (preg_match('/\.pps[mx]?$/i', $tmpfile)) {
12896 $mime = 'application/vnd.ms-powerpoint';
12897 $imgmime = 'ppt.png';
12898 $famime = 'file-powerpoint';
12899 } elseif (preg_match('/\.ppt[mx]?$/i', $tmpfile)) {
12900 $mime = 'application/x-mspowerpoint';
12901 $imgmime = 'ppt.png';
12902 $famime = 'file-powerpoint';
12903 } elseif (preg_match('/\.pdf$/i', $tmpfile)) { // Other
12904 $mime = 'application/pdf';
12905 $imgmime = 'pdf.png';
12906 $famime = 'file-pdf';
12907 } elseif (preg_match('/\.bat$/i', $tmpfile)) { // Scripts
12908 $mime = 'text/x-bat';
12909 $imgmime = 'script.png';
12911 $famime = 'file-code';
12912 } elseif (preg_match('/\.sh$/i', $tmpfile)) {
12913 $mime = 'text/x-sh';
12914 $imgmime = 'script.png';
12916 $famime = 'file-code';
12917 } elseif (preg_match('/\.ksh$/i', $tmpfile)) {
12918 $mime = 'text/x-ksh';
12919 $imgmime = 'script.png';
12921 $famime = 'file-code';
12922 } elseif (preg_match('/\.bash$/i', $tmpfile)) {
12923 $mime = 'text/x-bash';
12924 $imgmime = 'script.png';
12926 $famime = 'file-code';
12927 } elseif (preg_match('/\.ico$/i', $tmpfile)) { // Images
12928 $mime = 'image/x-icon';
12929 $imgmime = 'image.png';
12930 $famime = 'file-image';
12931 } elseif (preg_match('/\.(jpg|jpeg)$/i', $tmpfile)) {
12932 $mime = 'image/jpeg';
12933 $imgmime = 'image.png';
12934 $famime = 'file-image';
12935 } elseif (preg_match('/\.png$/i', $tmpfile)) {
12936 $mime = 'image/png';
12937 $imgmime = 'image.png';
12938 $famime = 'file-image';
12939 } elseif (preg_match('/\.gif$/i', $tmpfile)) {
12940 $mime = 'image/gif';
12941 $imgmime = 'image.png';
12942 $famime = 'file-image';
12943 } elseif (preg_match('/\.bmp$/i', $tmpfile)) {
12944 $mime = 'image/bmp';
12945 $imgmime = 'image.png';
12946 $famime = 'file-image';
12947 } elseif (preg_match('/\.(tif|tiff)$/i', $tmpfile)) {
12948 $mime = 'image/tiff';
12949 $imgmime = 'image.png';
12950 $famime = 'file-image';
12951 } elseif (preg_match('/\.svg$/i', $tmpfile)) {
12952 $mime = 'image/svg+xml';
12953 $imgmime = 'image.png';
12954 $famime = 'file-image';
12955 } elseif (preg_match('/\.webp$/i', $tmpfile)) {
12956 $mime = 'image/webp';
12957 $imgmime = 'image.png';
12958 $famime = 'file-image';
12959 } elseif (preg_match('/\.vcs$/i', $tmpfile)) { // Calendar
12960 $mime = 'text/calendar';
12961 $imgmime = 'other.png';
12962 $famime = 'file-alt';
12963 } elseif (preg_match('/\.ics$/i', $tmpfile)) {
12964 $mime = 'text/calendar';
12965 $imgmime = 'other.png';
12966 $famime = 'file-alt';
12967 } elseif (preg_match('/\.torrent$/i', $tmpfile)) { // Other
12968 $mime = 'application/x-bittorrent';
12969 $imgmime = 'other.png';
12970 $famime = 'file-o';
12971 } elseif (preg_match('/\.(mp3|ogg|au|wav|wma|mid)$/i', $tmpfile)) { // Audio
12973 $imgmime = 'audio.png';
12974 $famime = 'file-audio';
12975 } elseif (preg_match('/\.mp4$/i', $tmpfile)) { // Video
12976 $mime = 'video/mp4';
12977 $imgmime = 'video.png';
12978 $famime = 'file-video';
12979 } elseif (preg_match('/\.ogv$/i', $tmpfile)) {
12980 $mime = 'video/ogg';
12981 $imgmime = 'video.png';
12982 $famime = 'file-video';
12983 } elseif (preg_match('/\.webm$/i', $tmpfile)) {
12984 $mime = 'video/webm';
12985 $imgmime = 'video.png';
12986 $famime = 'file-video';
12987 } elseif (preg_match('/\.avi$/i', $tmpfile)) {
12988 $mime = 'video/x-msvideo';
12989 $imgmime = 'video.png';
12990 $famime = 'file-video';
12991 } elseif (preg_match('/\.divx$/i', $tmpfile)) {
12992 $mime = 'video/divx';
12993 $imgmime = 'video.png';
12994 $famime = 'file-video';
12995 } elseif (preg_match('/\.xvid$/i', $tmpfile)) {
12996 $mime = 'video/xvid';
12997 $imgmime = 'video.png';
12998 $famime = 'file-video';
12999 } elseif (preg_match('/\.(wmv|mpg|mpeg)$/i', $tmpfile)) {
13001 $imgmime = 'video.png';
13002 $famime = 'file-video';
13003 } elseif (preg_match('/\.(zip|rar|gz|tgz|xz|z|cab|bz2|7z|tar|lzh|zst)$/i', $tmpfile)) { // Archive
13004 // application/xxx where zzz is zip, ...
13006 $imgmime = 'archive.png';
13007 $famime = 'file-archive';
13008 } elseif (preg_match('/\.(exe|com)$/i', $tmpfile)) { // Exe
13009 $mime = 'application/octet-stream';
13010 $imgmime = 'other.png';
13011 $famime = 'file-o';
13012 } elseif (preg_match('/\.(dll|lib|o|so|a)$/i', $tmpfile)) { // Lib
13014 $imgmime = 'library.png';
13015 $famime = 'file-o';
13016 } elseif (preg_match('/\.err$/i', $tmpfile)) { // phpcs:ignore
13018 $imgmime = 'error.png';
13019 $famime = 'file-alt';
13022 if ($famime == 'file-o') {
13023 // file-o seems to not work in fontawesome 5
13027 // Return mimetype string
13028 switch ((int) $mode) {
13030 $tmp = explode('/', $mime);
13031 return (!empty($tmp[1]) ? $tmp[1] : $tmp[0]);
13053function getDictionaryValue($tablename, $field, $id, $checkentity = false, $rowidfield = 'rowid')
13057 $tablename = preg_replace('/^'.preg_quote(MAIN_DB_PREFIX, '/').'/', '', $tablename); // Clean name of table for backward compatibility.
13059 $dictvalues = (isset($conf->cache['dictvalues_'.$tablename]) ? $conf->cache['dictvalues_'.$tablename] : null);
13061 if (is_null($dictvalues)) {
13062 $dictvalues = array();
13064 $sql = "SELECT * FROM
".MAIN_DB_PREFIX.$tablename." WHERE 1 = 1
"; // Here select * is allowed as it is generic code and we don't have list of fields
13065 if ($checkentity) {
13066 $sql .= ' AND entity IN (0,'.getEntity($tablename).')';
13069 $resql = $db->query($sql);
13071 while ($obj = $db->fetch_object($resql)) {
13072 $dictvalues[$obj->$rowidfield] = $obj; // $obj is stdClass
13075 dol_print_error($db);
13078 $conf->cache['dictvalues_'.$tablename] = $dictvalues;
13081 if (!empty($dictvalues[$id])) {
13083 $tmp = $dictvalues[$id];
13084 return (property_exists($tmp, $field) ? $tmp->$field : '');
13097function colorIsLight($stringcolor)
13099 $stringcolor = str_replace('#', '', $stringcolor);
13101 if (!empty($stringcolor)) {
13103 $tmp = explode(',', $stringcolor);
13104 if (count($tmp) > 1) { // This is a comma RGB ('255','255','255')
13109 $hexr = $stringcolor[0].$stringcolor[1];
13110 $hexg = $stringcolor[2].$stringcolor[3];
13111 $hexb = $stringcolor[4].$stringcolor[5];
13112 $r = hexdec($hexr);
13113 $g = hexdec($hexg);
13114 $b = hexdec($hexb);
13116 $bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0; // HSL algorithm
13117 if ($bright > 0.6) {
13132function isVisibleToUserType($type_user, &$menuentry, &$listofmodulesforexternal)
13136 //print 'type_user='.$type_user.' module='.$menuentry['module'].' enabled='.$menuentry['enabled'].' perms='.$menuentry['perms'];
13137 //print 'ok='.in_array($menuentry['module'], $listofmodulesforexternal);
13138 if (empty($menuentry['enabled'])) {
13139 return 0; // Entry disabled by condition
13141 if ($type_user && array_key_exists('module', $menuentry) && $menuentry['module']) {
13142 $tmploops = explode('|', $menuentry['module']);
13144 foreach ($tmploops as $tmploop) {
13145 if (in_array($tmploop, $listofmodulesforexternal)) {
13151 return 0; // Entry is for menus all excluded to external users
13154 if (!$menuentry['perms'] && $type_user) {
13155 return 0; // No permissions and user is external
13157 if (!$menuentry['perms'] && getDolGlobalString('MAIN_MENU_HIDE_UNAUTHORIZED')) {
13158 return 0; // No permissions and option to hide when not allowed, even for internal user, is on
13160 if (!$menuentry['perms']) {
13161 return 2; // No permissions and user is external
13173function roundUpToNextMultiple($n, $x = 5)
13175 $result = (ceil($n) % $x === 0) ? ceil($n) : (round(($n + $x / 2) / $x) * $x);
13176 return (int) $result;
13190function dolGetBadge($label, $html = '', $type = 'primary', $mode = '', $url = '', $params = array())
13192 $csstouse = 'badge';
13193 $csstouse .= (!empty($mode) ? ' badge-'.$mode : '');
13194 $csstouse .= (!empty($type) ? ' badge-'.$type : '');
13195 $csstouse .= (empty($params['css']) ? '' : ' '.$params['css']);
13198 'class' => $csstouse
13201 if (empty($html)) {
13205 if (!empty($url)) {
13206 $attr['href'] = $url;
13209 if ($mode === 'dot') {
13210 $attr['class'] .= ' classfortooltip';
13211 $attr['title'] = $html;
13212 $attr['aria-label'] = $label;
13217 if (!empty($params['attr']) && is_array($params['attr'])) {
13218 foreach ($params['attr'] as $key => $value) {
13219 if ($key == 'class') {
13220 $attr['class'] .= ' '.$value;
13221 } elseif ($key == 'classOverride') {
13222 $attr['class'] = $value;
13224 $attr[$key] = $value;
13231 // escape all attribute
13232 $attr = array_map('dolPrintHTMLForAttribute', $attr);
13234 $TCompiledAttr = array();
13235 foreach ($attr as $key => $value) {
13236 $TCompiledAttr[] = $key.'="
'.$value.'"';
13239 $compiledAttributes = !empty($TCompiledAttr) ? implode(' ', $TCompiledAttr) : '';
13241 $tag = !empty($url) ? 'a' : 'span';
13243 return '<'.$tag.' '.$compiledAttributes.'>'.$html.'</'.$tag.'>';
13259function dolGetStatus($statusLabel = '', $statusLabelShort = '', $html = '', $statusType = 'status0', $displayMode = 0, $url = '', $params = array())
13264 $dolGetBadgeParams = array();
13266 if (!empty($params['badgeParams'])) {
13267 $dolGetBadgeParams = $params['badgeParams'];
13270 // TODO : add a hook
13271 if ($displayMode == 0) {
13272 $return = !empty($html) ? $html : (empty($conf->dol_optimize_smallscreen) ? $statusLabel : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort));
13273 } elseif ($displayMode == 1) {
13274 $return = !empty($html) ? $html : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort);
13275 } elseif (getDolGlobalString('MAIN_STATUS_USES_IMAGES')) {
13276 // Use status with images (for backward compatibility)
13278 $htmlLabel = (in_array($displayMode, array(1, 2, 5)) ? '<span class="hideonsmartphone
">' : '').(!empty($html) ? $html : $statusLabel).(in_array($displayMode, array(1, 2, 5)) ? '</span>' : '');
13279 $htmlLabelShort = (in_array($displayMode, array(1, 2, 5)) ? '<span class="hideonsmartphone
">' : '').(!empty($html) ? $html : (!empty($statusLabelShort) ? $statusLabelShort : $statusLabel)).(in_array($displayMode, array(1, 2, 5)) ? '</span>' : '');
13281 // For small screen, we always use the short label instead of long label.
13282 if (!empty($conf->dol_optimize_smallscreen)) {
13283 if ($displayMode == 0) {
13285 } elseif ($displayMode == 4) {
13287 } elseif ($displayMode == 6) {
13292 // For backward compatibility. Image's filename are still in French, so we use this array to convert
13293 $statusImg = array(
13294 'status0' => 'statut0',
13295 'status1' => 'statut1',
13296 'status2' => 'statut2',
13297 'status3' => 'statut3',
13298 'status4' => 'statut4',
13299 'status5' => 'statut5',
13300 'status6' => 'statut6',
13301 'status7' => 'statut7',
13302 'status8' => 'statut8',
13303 'status9' => 'statut9'
13306 if (!empty($statusImg[$statusType])) {
13307 $htmlImg = img_picto($statusLabel, $statusImg[$statusType]);
13309 $htmlImg = img_picto($statusLabel, $statusType);
13312 if ($displayMode === 2) {
13313 $return = $htmlImg.' '.$htmlLabelShort;
13314 } elseif ($displayMode === 3) {
13315 $return = $htmlImg;
13316 } elseif ($displayMode === 4) {
13317 $return = $htmlImg.' '.$htmlLabel;
13318 } elseif ($displayMode === 5) {
13319 $return = $htmlLabelShort.' '.$htmlImg;
13320 } else { // $displayMode >= 6
13321 $return = $htmlLabel.' '.$htmlImg;
13323 } elseif (!getDolGlobalString('MAIN_STATUS_USES_IMAGES') && !empty($displayMode)) {
13325 $statusLabelShort = (empty($statusLabelShort) ? $statusLabel : $statusLabelShort);
13327 $dolGetBadgeParams['attr']['class'] = 'badge-status';
13328 if (empty($dolGetBadgeParams['attr']['title'])) {
13329 $dolGetBadgeParams['attr']['title'] = empty($params['tooltip']) ? $statusLabel : ($params['tooltip'] != 'no' ? $params['tooltip'] : '');
13330 } else { // If a title was forced from $params['badgeParams']['attr']['title'], we set the class to get it as a tooltip.
13331 $dolGetBadgeParams['attr']['class'] .= ' classfortooltip';
13332 // And if we use tooltip, we can output title in HTML @phan-suppress-next-line PhanTypeInvalidDimOffset
13333 $dolGetBadgeParams['attr']['title'] = dol_htmlentitiesbr((string) $dolGetBadgeParams['attr']['title'], 1);
13336 if ($displayMode == 3) {
13337 $return = dolGetBadge((empty($conf->dol_optimize_smallscreen) ? $statusLabel : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort)), '', $statusType, 'dot', $url, $dolGetBadgeParams);
13338 } elseif ($displayMode === 5) {
13339 $return = dolGetBadge($statusLabelShort, $html, $statusType, '', $url, $dolGetBadgeParams);
13341 $return = dolGetBadge(((empty($conf->dol_optimize_smallscreen) && $displayMode != 2) ? $statusLabel : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort)), $html, $statusType, '', $url, $dolGetBadgeParams);
13384function dolGetButtonAction($label, $text = '', $actionType = 'default', $url = '', $id = '', $userRight = 1, $params = array())
13386 global $hookmanager, $action, $object, $langs;
13388 // If $url is an array, we must build a dropdown button or recursively iterate over each value
13389 if (is_array($url)) {
13390 // Loop on $url array to remove entries of disabled modules
13391 foreach ($url as $key => $subbutton) {
13392 if (isset($subbutton['enabled']) && empty($subbutton['enabled'])) {
13399 if (array_key_exists('areDropdownButtons', $params) && $params["areDropdownButtons
"] === false) { // @phan-suppress-current-line PhanTypeInvalidDimOffset
13400 foreach ($url as $button) {
13401 if (!empty($button['lang'])) {
13402 $langs->load($button['lang']);
13404 $label = $langs->trans($button['label']);
13405 $text = $button['text'] ?? '';
13406 $actionType = $button['actionType'] ?? '';
13407 $tmpUrl = DOL_URL_ROOT.$button['url'].(empty($params['backtopage']) ? '' : '&backtopage='.urlencode($params['backtopage']));
13408 $id = $button['id'] ?? '';
13409 $userRight = $button['perm'] ?? 1;
13410 $button['params'] = $button['params'] ?? []; // @phan-suppress-current-line PhanPluginDuplicateExpressionAssignmentOperation
13412 $out .= dolGetButtonAction($label, $text, $actionType, $tmpUrl, $id, $userRight, $button['params']);
13417 if (count($url) > 1) {
13418 $out .= '<div class="dropdown
inline-block dropdown-holder
">';
13419 $out .= '<a style="margin-right: auto;
" class="dropdown-toggle classfortooltip butAction
'.($userRight ? '' : 'Refused
').'" title="'.dol_escape_htmltag($label).'" data-toggle="dropdown
">'.($text ? $text : $label).'</a>';
13420 $out .= '<div class="dropdown-content
">';
13421 foreach ($url as $subbutton) {
13422 if (!empty($subbutton['lang'])) {
13423 $langs->load($subbutton['lang']);
13426 if (!empty($subbutton['urlraw'])) {
13427 $tmpurl = $subbutton['urlraw']; // Use raw url, no url completion, use only what developer send
13429 $tmpurl = !empty($subbutton['urlroot']) ? $subbutton['urlroot'] : $subbutton['url'];
13430 $tmpurl = dolCompletUrlForDropdownButton($tmpurl, $params, empty($subbutton['urlroot']));
13433 $subbuttonparam = array();
13434 if (!empty($subbutton['attr'])) {
13435 $subbuttonparam['attr'] = $subbutton['attr'];
13437 $subbuttonparam['isDropDown'] = (empty($params['isDropDown']) ? ($subbutton['isDropDown'] ?? false) : $params['isDropDown']);
13439 $out .= dolGetButtonAction('', $langs->trans($subbutton['label']), 'default', $tmpurl, $subbutton['id'] ?? '', $subbutton['perm'], $subbuttonparam);
13444 foreach ($url as $subbutton) { // Should loop on 1 record only
13445 if (!empty($subbutton['lang'])) {
13446 $langs->load($subbutton['lang']);
13449 if (!empty($subbutton['urlraw'])) {
13450 $tmpurl = $subbutton['urlraw']; // Use raw url, no url completion, use only what developer send
13452 $tmpurl = !empty($subbutton['urlroot']) ? $subbutton['urlroot'] : $subbutton['url'];
13453 $tmpurl = dolCompletUrlForDropdownButton($tmpurl, $params, empty($subbutton['urlroot']));
13456 $out .= dolGetButtonAction('', $langs->trans($subbutton['label']), 'default', $tmpurl, '', $subbutton['perm'], $params);
13463 // Here, $url is a simple link
13465 if (!empty($params['isDropdown']) || !empty($params['isDropDown'])) { // Use the dropdown-item style (not for action button)
13466 $class = "dropdown-item
";
13468 $class = 'butAction';
13469 if ($actionType == 'danger' || $actionType == 'delete') {
13470 $class = 'butActionDelete';
13471 if (!empty($url) && strpos($url, 'token=') === false) {
13472 $url .= '&token='.newToken();
13478 'href' => empty($url) ? '' : $url,
13482 if (empty($text)) {
13484 $attr['title'] = ''; // if html not set, leave label on title is redundant
13486 $attr['title'] = $label;
13487 $attr['aria-label'] = $label;
13490 if (empty($userRight) || $userRight < 0) {
13491 $attr['class'] = 'butActionRefused';
13492 $attr['href'] = '';
13493 $attr['title'] = (($label && $text && $label != $text) ? $label : '');
13494 $attr['title'] = ($attr['title'] ? $attr['title'] . (empty($userRight) ? '<br>' : '') : '').(empty($userRight) ? $langs->trans('NotEnoughPermissions') : '');
13502 if (!empty($params['attr']) && is_array($params['attr'])) {
13503 foreach ($params['attr'] as $key => $value) {
13504 if ($key == 'class') {
13505 $attr['class'] .= ' '.$value;
13506 } elseif ($key == 'classOverride') {
13507 $attr['class'] = $value;
13509 $attr[$key] = $value;
13514 // automatic add tooltip when title is detected
13515 if (!empty($attr['title']) && !empty($attr['class']) && strpos($attr['class'], 'classfortooltip') === false) {
13516 $attr['class'] .= ' classfortooltip';
13519 // Js Confirm button
13520 if ($userRight && !empty($params['confirm'])) {
13521 if (!is_array($params['confirm'])) {
13522 $params['confirm'] = array();
13525 if (empty($params['confirm']['url'])) {
13526 $params['confirm']['url'] = $url . (strpos($url, '?') > 0 ? '&' : '?') . 'confirm=yes';
13529 // for js disabled compatibility set $url as call to confirm action and $params['confirm']['url'] to confirmed action
13530 $attr['data-confirm-url'] = $params['confirm']['url'];
13531 $attr['data-confirm-title'] = !empty($params['confirm']['title']) ? $params['confirm']['title'] : $langs->trans('ConfirmBtnCommonTitle', $label);
13532 $attr['data-confirm-content'] = !empty($params['confirm']['content']) ? $params['confirm']['content'] : $langs->trans('ConfirmBtnCommonContent', $label);
13533 $attr['data-confirm-content'] = preg_replace("/\r|\n/
", "", $attr['data-confirm-content']);
13534 $attr['data-confirm-action-btn-label'] = !empty($params['confirm']['action-btn-label']) ? $params['confirm']['action-btn-label'] : $langs->trans('Confirm');
13535 $attr['data-confirm-cancel-btn-label'] = !empty($params['confirm']['cancel-btn-label']) ? $params['confirm']['cancel-btn-label'] : $langs->trans('CloseDialog');
13536 $attr['data-confirm-modal'] = !empty($params['confirm']['modal']) ? $params['confirm']['modal'] : true;
13538 $attr['class'] .= ' butActionConfirm';
13541 if (isset($attr['href']) && empty($attr['href'])) {
13542 unset($attr['href']);
13545 $TCompiledAttr = array();
13546 foreach ($attr as $key => $value) {
13547 if (!empty($params['use_unsecured_unescapedattr']) && is_array($params['use_unsecured_unescapedattr']) && in_array($key, $params['use_unsecured_unescapedattr'])) {
13549 $value = dol_htmlentities($value, ENT_QUOTES | ENT_SUBSTITUTE);
13550 } elseif ($key == 'href') {
13551 $value = dolPrintHTMLForAttributeUrl($value);
13553 $value = dolPrintHTMLForAttribute($value);
13556 $TCompiledAttr[] = $key.'="'.$value.'"'; // $value has been escaped by the dolPrintHTMLForAttribute... just before
13559 $compiledAttributes = empty($TCompiledAttr) ? '' : implode(' ', $TCompiledAttr);
13561 $tag = !empty($attr['href']) ? 'a' : 'span';
13564 $parameters = array(
13565 'TCompiledAttr' => $TCompiledAttr, // array
13566 'compiledAttributes' => $compiledAttributes, // string
13571 'actionType' => $actionType,
13574 'userRight' => $userRight,
13575 'params' => $params
13578 $reshook = $hookmanager->executeHooks('dolGetButtonAction', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
13579 if ($reshook < 0) {
13580 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
13583 if (empty($reshook)) {
13584 if (dol_textishtml($text)) { // If content already HTML encoded
13585 return '<' . $tag . ' ' . $compiledAttributes . '><span class="textbutton
">' . $text . '</span></' . $tag . '>';
13587 return '<' . $tag . ' ' . $compiledAttributes . '><span class="textbutton
">' . dol_escape_htmltag($text) . '</span></' . $tag . '>';
13590 return $hookmanager->resPrint;
13603function dolCompletUrlForDropdownButton(string $url, array $params, bool $addDolUrlRoot = true)
13609 $parsedUrl = parse_url($url);
13610 if ((isset($parsedUrl['scheme']) && in_array($parsedUrl['scheme'], ['javascript', 'mailto', 'tel'])) || strpos($url, '#') === 0) {
13614 if (!empty($parsedUrl['query'])) {
13615 // Use parse_str() function to parse the string passed via URL
13616 parse_str($parsedUrl['query'], $urlQuery);
13617 if (!isset($urlQuery['backtopage']) && isset($params['backtopage'])) {
13618 $url .= '&backtopage='.urlencode($params['backtopage']);
13622 if (!isset($parsedUrl['scheme']) && $addDolUrlRoot) {
13623 $url = DOL_URL_ROOT.$url;
13636function dolGetButtonTitleSeparator($moreClass = "
")
13638 return '<span class="button-title-separator
'.$moreClass.'" ></span>';
13647function getFieldErrorIcon($fieldValidationErrorMsg)
13650 if (!empty($fieldValidationErrorMsg)) {
13651 $out .= '<span class="field-error-icon classfortooltip
" title="'.dol_escape_htmltag($fieldValidationErrorMsg, 1).'" role="alert
" >'; // role alert is used for accessibility
13652 $out .= '<span class="fa fa-exclamation-circle
" aria-hidden="true" ></span>'; // For accessibility icon is separated and aria-hidden
13671function dolGetButtonTitle($label, $helpText = '', $iconClass = 'fa fa-file', $url = '', $id = '', $status = 1, $params = array())
13673 global $langs, $user;
13675 // Actually this conf is used in css too for external module compatibility and smooth transition to this function
13676 if (getDolGlobalString('MAIN_BUTTON_HIDE_UNAUTHORIZED') && (!$user->admin) && $status <= 0) {
13679 // Fix old picto fa-th-list to use fa-grid-vertical instead
13680 if ($iconClass == 'fa fa-th-list imgforviewmode') {
13681 $iconClass = ' fa fa-grip-horizontal imgforviewmode';
13684 $class = 'btnTitle';
13685 if (in_array($iconClass, array('fa fa-plus-circle', 'fa fa-plus-circle size15x', 'fa fa-comment-dots', 'fa fa-paper-plane'))) {
13686 $class .= ' btnTitlePlus';
13688 $useclassfortooltip = 1;
13690 if (!empty($params['morecss'])) {
13691 $class .= ' '.$params['morecss'];
13696 'href' => empty($url) ? '' : $url
13699 if (!empty($helpText)) {
13700 $attr['title'] = $helpText;
13701 } elseif ($label) { // empty($attr['title']) &&
13702 $attr['title'] = $label;
13703 $useclassfortooltip = 0;
13706 if ($status == 2) {
13707 $attr['class'] .= ' btnTitleSelected';
13708 } elseif ($status <= 0) {
13709 $attr['class'] .= ' refused';
13711 $attr['href'] = '';
13713 if ($status == -1) { // disable
13714 $attr['title'] = $langs->transnoentitiesnoconv("FeatureDisabled
");
13715 } elseif ($status == 0) { // Not enough permissions
13716 $attr['title'] = $langs->transnoentitiesnoconv("NotEnoughPermissions
");
13720 if (!empty($attr['title']) && $useclassfortooltip) {
13721 $attr['class'] .= ' classfortooltip';
13729 if (!empty($params['attr']) && is_array($params['attr'])) {
13730 foreach ($params['attr'] as $key => $value) {
13731 if ($key == 'class') {
13732 $attr['class'] .= ' '.$value;
13733 } elseif ($key == 'classOverride') {
13734 $attr['class'] = $value;
13736 $attr[$key] = $value;
13741 if (isset($attr['href']) && empty($attr['href'])) {
13742 unset($attr['href']);
13745 // TODO : add a hook
13747 // Generate attributes with escapement
13748 $TCompiledAttr = array();
13749 foreach ($attr as $key => $value) {
13750 $TCompiledAttr[] = $key.'="'.dol_escape_htmltag($value).'"'; // Do not use dolPrintHTMLForAttribute() here, we must accept "javascript:
string"
13753 $compiledAttributes = (empty($TCompiledAttr) ? '' : implode(' ', $TCompiledAttr));
13755 $tag = (empty($attr['href']) ? 'span' : 'a');
13757 $button = '<'.$tag.' '.$compiledAttributes.'>';
13758 $button .= '<span class="'.$iconClass.' valignmiddle btnTitle-icon
"></span>';
13759 if (!empty($params['forcenohideoftext'])) {
13760 $button .= '<span class="valignmiddle text-plus-circle btnTitle-label
'.(empty($params['forcenohideoftext
']) ? ' hideonsmartphone
' : '').'">'.$label.'</span>';
13762 $button .= '</'.$tag.'>';
13776function getElementProperties($elementType)
13778 global $conf, $db, $hookmanager;
13782 //$element_type='facture';
13784 $classfile = $classname = $classpath = $subdir = $dir_output = $dir_temp = $parent_element = '';
13786 // Parse element/subelement
13787 $module = $elementType;
13788 $element = $elementType;
13789 $subelement = $elementType;
13790 $table_element = $elementType;
13792 // If we ask a resource form external module (instead of default path)
13793 if (preg_match('/^([^@]+)@([^@]+)$/i', $elementType, $regs)) { // 'myobject@mymodule'
13794 $element = $subelement = $regs[1];
13795 $module = $regs[2];
13798 // If we ask a resource for a string with an element and a subelement
13799 // Example 'project_task'
13800 if (preg_match('/^([^_]+)_([^_]+)/i', $element, $regs)) { // 'myobject_mysubobject' with myobject=mymodule
13801 $module = $element = $regs[1];
13802 $subelement = $regs[2];
13805 // Object lines will use parent classpath and module ref
13806 if (substr($elementType, -3) == 'det') {
13807 $module = preg_replace('/det$/', '', $element);
13808 $subelement = preg_replace('/det$/', '', $subelement);
13809 $classpath = $module.'/class';
13810 $classfile = $module;
13811 $classname = preg_replace('/det$/', 'Line', $element);
13812 if (in_array($module, array('expedition', 'propale', 'facture', 'contrat', 'fichinter', 'commandefournisseur'))) {
13813 $classname = preg_replace('/det$/', 'Ligne', $element);
13816 // For compatibility and to work with non standard path
13817 if ($elementType == "action
" || $elementType == "actioncomm
") {
13818 $classpath = 'comm/action/class';
13819 $subelement = 'Actioncomm';
13820 $module = 'agenda';
13821 $table_element = 'actioncomm';
13822 } elseif ($elementType == 'cronjob') {
13823 $classpath = 'cron/class';
13825 $table_element = 'cron';
13826 } elseif ($elementType == 'adherent_type') {
13827 $classpath = 'adherents/class';
13828 $classfile = 'adherent_type';
13829 $module = 'adherent';
13830 $subelement = 'adherent_type';
13831 $classname = 'AdherentType';
13832 $table_element = 'adherent_type';
13833 } elseif ($elementType == 'bank_account') {
13834 $classpath = 'compta/bank/class';
13835 $module = 'bank'; // We need $conf->bank->dir_output and not $conf->banque->dir_output
13836 $classfile = 'account';
13837 $classname = 'Account';
13838 } elseif ($elementType == 'bank_line') {
13839 $classpath = 'compta/bank/class';
13840 $module = 'bank'; // We need $conf->bank->dir_output and not $conf->banque->dir_output
13841 $classfile = 'account';
13842 $classname = 'AccountLine';
13843 } elseif ($elementType == 'category') {
13844 $classpath = 'categories/class';
13845 $module = 'categorie';
13846 $subelement = 'categorie';
13847 $table_element = 'categorie';
13848 } elseif ($elementType == 'contact') {
13849 $classpath = 'contact/class';
13850 $classfile = 'contact';
13851 $module = 'societe';
13852 $subelement = 'contact';
13853 $table_element = 'socpeople';
13854 } elseif ($elementType == 'inventory') {
13855 $module = 'product';
13856 $classpath = 'product/inventory/class';
13857 } elseif ($elementType == 'inventoryline') {
13858 $module = 'product';
13859 $classpath = 'product/inventory/class';
13860 $table_element = 'inventorydet';
13861 $parent_element = 'inventory';
13862 } elseif ($elementType == 'stock' || $elementType == 'entrepot' || $elementType == 'warehouse') {
13864 $classpath = 'product/stock/class';
13865 $classfile = 'entrepot';
13866 $classname = 'Entrepot';
13867 $table_element = 'entrepot';
13868 } elseif ($elementType == 'project') {
13869 $classpath = 'projet/class';
13870 $module = 'projet';
13871 $table_element = 'projet';
13872 } elseif ($elementType == 'project_task') {
13873 $classpath = 'projet/class';
13874 $module = 'projet';
13875 $subelement = 'task';
13876 $table_element = 'projet_task';
13877 } elseif ($elementType == 'facture' || $elementType == 'invoice') {
13878 $classpath = 'compta/facture/class';
13879 $module = 'facture';
13880 $subelement = 'facture';
13881 $table_element = 'facture';
13882 } elseif ($elementType == 'facturedet') {
13883 $classpath = 'compta/facture/class';
13884 $classfile = 'facture';
13885 $classname = 'FactureLigne';
13886 $module = 'facture';
13887 $table_element = 'facturedet';
13888 $parent_element = 'facture';
13889 } elseif ($elementType == 'facturerec') {
13890 $classpath = 'compta/facture/class';
13891 $classfile = 'facture-rec';
13892 $module = 'facture';
13893 $classname = 'FactureRec';
13894 } elseif ($elementType == 'commande' || $elementType == 'order') {
13895 $classpath = 'commande/class';
13896 $module = 'commande';
13897 $subelement = 'commande';
13898 $table_element = 'commande';
13899 } elseif ($elementType == 'commandedet') {
13900 $classpath = 'commande/class';
13901 $classfile = 'commande';
13902 $classname = 'OrderLine';
13903 $module = 'commande';
13904 $table_element = 'commandedet';
13905 $parent_element = 'commande';
13906 } elseif ($elementType == 'propal') {
13907 $classpath = 'comm/propal/class';
13908 $table_element = 'propal';
13909 } elseif ($elementType == 'propaldet') {
13910 $classpath = 'comm/propal/class';
13911 $classfile = 'propal';
13912 $subelement = 'propaleligne';
13913 $module = 'propal';
13914 $table_element = 'propaldet';
13915 $parent_element = 'propal';
13916 } elseif ($elementType == 'shipping') {
13917 $classpath = 'expedition/class';
13918 $classfile = 'expedition';
13919 $classname = 'Expedition';
13920 $module = 'expedition';
13921 $table_element = 'expedition';
13922 } elseif ($elementType == 'expeditiondet' || $elementType == 'shippingdet') {
13923 $classpath = 'expedition/class';
13924 $classfile = 'expedition';
13925 $classname = 'ExpeditionLigne';
13926 $module = 'expedition';
13927 $table_element = 'expeditiondet';
13928 $parent_element = 'expedition';
13929 } elseif ($elementType == 'delivery_note') {
13930 $classpath = 'delivery/class';
13931 $subelement = 'delivery';
13932 $module = 'expedition';
13933 } elseif ($elementType == 'delivery') {
13934 $classpath = 'delivery/class';
13935 $subelement = 'delivery';
13936 $module = 'expedition';
13937 } elseif ($elementType == 'deliverydet') {
13939 } elseif ($elementType == 'supplier_proposal') {
13940 $classpath = 'supplier_proposal/class';
13941 $module = 'supplier_proposal';
13942 $element = 'supplierproposal';
13943 $classfile = 'supplier_proposal';
13944 $subelement = 'supplierproposal';
13945 } elseif ($elementType == 'supplier_proposaldet') {
13946 $classpath = 'supplier_proposal/class';
13947 $module = 'supplier_proposal';
13948 $classfile = 'supplier_proposal';
13949 $classname = 'SupplierProposalLine';
13950 $table_element = 'supplier_proposaldet';
13951 $parent_element = 'supplier_proposal';
13952 } elseif ($elementType == 'contract') {
13953 $classpath = 'contrat/class';
13954 $module = 'contrat';
13955 $subelement = 'contrat';
13956 $table_element = 'contract';
13957 } elseif ($elementType == 'contratdet') {
13958 $classpath = 'contrat/class';
13959 $module = 'contrat';
13960 $table_element = 'contratdet';
13961 $parent_element = 'contrat';
13962 } elseif ($elementType == 'mailing') {
13963 $classpath = 'comm/mailing/class';
13964 $module = 'mailing';
13965 $classfile = 'mailing';
13966 $classname = 'Mailing';
13968 } elseif ($elementType == 'member' || $elementType == 'adherent') {
13969 $classpath = 'adherents/class';
13970 $module = 'adherent';
13971 $subelement = 'adherent';
13972 $table_element = 'adherent';
13973 } elseif ($elementType == 'subscription') {
13974 $classpath = 'adherents/class';
13975 $classfile = 'subscription';
13976 $module = 'adherent';
13977 $subelement = 'subscription';
13978 $classname = 'Subscription';
13979 $table_element = 'subscription';
13980 } elseif ($elementType == 'usergroup') {
13981 $classpath = 'user/class';
13983 } elseif ($elementType == 'mo') {
13984 $classpath = 'mrp/class';
13989 $table_element = 'mrp_mo';
13990 } elseif ($elementType == 'mrp_production') {
13991 $classpath = 'mrp/class';
13993 $classname = 'MoLine';
13996 $table_element = 'mrp_production';
13997 $parent_element = 'mo';
13998 } elseif ($elementType == 'cabinetmed_cons') {
13999 $classpath = 'cabinetmed/class';
14000 $module = 'cabinetmed';
14001 $subelement = 'cabinetmedcons';
14002 $table_element = 'cabinetmedcons';
14003 } elseif ($elementType == 'fichinter') {
14004 $classpath = 'fichinter/class';
14005 $module = 'ficheinter';
14006 $subelement = 'fichinter';
14007 $table_element = 'fichinter';
14008 } elseif ($elementType == 'dolresource' || $elementType == 'resource') {
14009 $classpath = 'resource/class';
14010 $module = 'resource';
14011 $subelement = 'dolresource';
14012 $table_element = 'resource';
14013 } elseif ($elementType == 'opensurvey_sondage') {
14014 $classpath = 'opensurvey/class';
14015 $module = 'opensurvey';
14016 $subelement = 'opensurveysondage';
14017 } elseif ($elementType == 'order_supplier' || $elementType == 'supplier_order' ||$elementType == 'commande_fournisseur' || $elementType == 'commandefournisseur') {
14018 $classpath = 'fourn/class';
14019 $module = 'fournisseur';
14020 $classfile = 'fournisseur.commande';
14021 $element = 'order_supplier';
14023 $classname = 'CommandeFournisseur';
14024 $table_element = 'commande_fournisseur';
14025 } elseif ($elementType == 'commande_fournisseurdet') {
14026 $classpath = 'fourn/class';
14027 $module = 'fournisseur';
14028 $classfile = 'fournisseur.commande';
14029 $element = 'commande_fournisseurdet';
14031 $classname = 'CommandeFournisseurLigne';
14032 $table_element = 'commande_fournisseurdet';
14033 $parent_element = 'commande_fournisseur';
14034 } elseif ($elementType == 'invoice_supplier' || $elementType == 'supplier_invoice' || $elementType == 'facture_fourn') {
14035 $classpath = 'fourn/class';
14036 $module = 'fournisseur';
14037 $classfile = 'fournisseur.facture';
14038 $element = 'invoice_supplier';
14040 $classname = 'FactureFournisseur';
14041 $table_element = 'facture_fourn';
14042 } elseif ($elementType == 'facture_fourn_det') {
14043 $classpath = 'fourn/class';
14044 $module = 'fournisseur';
14045 $classfile = 'fournisseur.facture';
14046 $element = 'facture_fourn_det';
14048 $classname = 'SupplierInvoiceLine';
14049 $table_element = 'facture_fourn_det';
14050 $parent_element = 'invoice_supplier';
14051 } elseif ($elementType == "service
") {
14052 $classpath = 'product/class';
14053 $subelement = 'product';
14054 $table_element = 'product';
14055 } elseif ($elementType == 'salary') {
14056 $classpath = 'salaries/class';
14057 $module = 'salaries';
14058 } elseif ($elementType == 'payment_salary') {
14059 $classpath = 'salaries/class';
14060 $classfile = 'paymentsalary';
14061 $classname = 'PaymentSalary';
14062 $module = 'salaries';
14063 } elseif ($elementType == 'productlot') {
14064 $module = 'productbatch';
14065 $classpath = 'product/stock/class';
14066 $classfile = 'productlot';
14067 $classname = 'Productlot';
14068 $element = 'productlot';
14070 $table_element = 'product_lot';
14071 } elseif ($elementType == 'societeaccount') {
14072 $classpath = 'societe/class';
14073 $classfile = 'societeaccount';
14074 $classname = 'SocieteAccount';
14075 $module = 'societe';
14076 } elseif ($elementType == 'websitepage' || $elementType == 'website_page') {
14077 $classpath = 'website/class';
14078 $classfile = 'websitepage';
14079 $classname = 'Websitepage';
14080 $module = 'website';
14081 $subelement = 'websitepage';
14082 $table_element = 'website_page';
14083 } elseif ($elementType == 'fiscalyear') {
14084 $classpath = 'core/class';
14085 $module = 'accounting';
14086 $subelement = 'fiscalyear';
14087 } elseif ($elementType == 'chargesociales') {
14088 $classpath = 'compta/sociales/class';
14090 $table_element = 'chargesociales';
14091 } elseif ($elementType == 'tva') {
14092 $classpath = 'compta/tva/class';
14095 $table_element = 'tva';
14096 } elseif ($elementType == 'emailsenderprofile') {
14098 $classpath = 'core/class';
14099 $classfile = 'emailsenderprofile';
14100 $classname = 'EmailSenderProfile';
14101 $table_element = 'c_email_senderprofile';
14103 } elseif ($elementType == 'conferenceorboothattendee') {
14104 $classpath = 'eventorganization/class';
14105 $classfile = 'conferenceorboothattendee';
14106 $classname = 'ConferenceOrBoothAttendee';
14107 $module = 'eventorganization';
14108 } elseif ($elementType == 'conferenceorbooth') {
14109 $classpath = 'eventorganization/class';
14110 $classfile = 'conferenceorbooth';
14111 $classname = 'ConferenceOrBooth';
14112 $module = 'eventorganization';
14113 } elseif ($elementType == 'ccountry') {
14115 $classpath = 'core/class';
14116 $classfile = 'ccountry';
14117 $classname = 'Ccountry';
14118 $table_element = 'c_country';
14120 } elseif ($elementType == 'ecmfiles') {
14122 $classpath = 'ecm/class';
14123 $classfile = 'ecmfiles';
14124 $classname = 'Ecmfiles';
14125 $table_element = 'ecmfiles';
14127 } elseif ($elementType == 'knowledgerecord' || $elementType == 'knowledgemanagement') {
14128 $module = 'knowledgemanagement';
14129 $classpath = 'knowledgemanagement/class';
14130 $classfile = 'knowledgerecord';
14131 $classname = 'KnowledgeRecord';
14132 $table_element = 'knowledgemanagement_knowledgerecord';
14134 } elseif ($elementType == 'customer') {
14135 $module = 'societe';
14136 $classpath = 'societe/class';
14137 $classfile = 'client';
14138 $classname = 'Client';
14139 $table_element = 'societe';
14141 } elseif ($elementType == 'fournisseur' || $elementType == 'supplier') {
14142 $module = 'societe';
14143 $classpath = 'fourn/class';
14144 $classfile = 'fournisseur';
14145 $classname = 'Fournisseur';
14146 $table_element = 'societe';
14151 if (empty($classfile)) {
14152 $classfile = strtolower($subelement);
14154 if (empty($classname)) {
14155 $classname = ucfirst($subelement);
14157 if (empty($classpath)) {
14158 $classpath = $module.'/class';
14161 //print 'getElementProperties subdir='.$subdir;
14164 if ($module && isset($conf->$module)) { // The generic case
14165 if (!empty($conf->$module->multidir_output[$conf->entity])) {
14166 $dir_output = $conf->$module->multidir_output[$conf->entity];
14167 } elseif (!empty($conf->$module->output[$conf->entity])) {
14168 $dir_output = $conf->$module->output[$conf->entity];
14169 } elseif (!empty($conf->$module->dir_output)) {
14170 $dir_output = $conf->$module->dir_output;
14172 if (!empty($conf->$module->multidir_temp[$conf->entity])) {
14173 $dir_temp = $conf->$module->multidir_temp[$conf->entity];
14174 } elseif (!empty($conf->$module->temp[$conf->entity])) {
14175 $dir_temp = $conf->$module->temp[$conf->entity];
14176 } elseif (!empty($conf->$module->dir_temp)) {
14177 $dir_temp = $conf->$module->dir_temp;
14181 // Overwrite value for special cases
14182 if ($element == 'order_supplier' && isModEnabled('fournisseur')) {
14183 $dir_output = $conf->fournisseur->commande->dir_output;
14184 $dir_temp = $conf->fournisseur->commande->dir_temp;
14185 } elseif ($element == 'invoice_supplier' && isModEnabled('fournisseur')) {
14186 $dir_output = $conf->fournisseur->facture->dir_output;
14187 $dir_temp = $conf->fournisseur->facture->dir_temp;
14189 $dir_output .= $subdir;
14190 $dir_temp .= $subdir;
14192 $elementProperties = array(
14193 'module' => $module,
14194 'element' => $element,
14195 'table_element' => $table_element,
14196 'subelement' => $subelement,
14197 'classpath' => $classpath,
14198 'classfile' => $classfile,
14199 'classname' => $classname,
14200 'dir_output' => $dir_output,
14201 'dir_temp' => $dir_temp,
14202 'parent_element' => $parent_element,
14207 if (!is_object($hookmanager)) {
14208 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
14209 $hookmanager = new HookManager($db);
14211 $hookmanager->initHooks(array('elementproperties'));
14215 $parameters = array(
14216 'elementType' => $elementType,
14217 'elementProperties' => $elementProperties
14220 $reshook = $hookmanager->executeHooks('getElementProperties', $parameters);
14223 $elementProperties = $hookmanager->resArray;
14224 } elseif (!empty($hookmanager->resArray) && is_array($hookmanager->resArray)) { // resArray is always an array but for sécurity against misconfigured external modules
14225 $elementProperties = array_replace($elementProperties, $hookmanager->resArray);
14228 // context of elementproperties doesn't need to exist out of this function so delete it to avoid elementproperties context is equal to all
14229 if (($key = array_search('elementproperties', $hookmanager->contextarray)) !== false) {
14230 unset($hookmanager->contextarray[$key]);
14233 return $elementProperties;
14248function fetchObjectByElement($element_id, $element_type, $element_ref = '', $useCache = 0, $maxCacheByType = 10)
14254 $element_prop = getElementProperties($element_type);
14256 if ($element_prop['module'] == 'product' || $element_prop['module'] == 'service') {
14257 // For example, for an extrafield 'product' (shared for both product and service) that is a link to an object,
14258 // this is called with $element_type = 'product' when we need element properties of a service, we must return a product. If we create the
14259 // extrafield for a service, it is not supported and not found when editing the product/service card. So we must keep 'product' for extrafields
14260 // of service and we will return properties of a product.
14261 $ismodenabled = (isModEnabled('product') || isModEnabled('service'));
14262 } elseif ($element_prop['module'] == 'societeaccount') {
14263 $ismodenabled = isModEnabled('website') || isModEnabled('webportal');
14265 $ismodenabled = isModEnabled($element_prop['module']);
14267 //var_dump('element_type='.$element_type);
14268 //var_dump($element_prop);
14269 //var_dump($element_prop['module'].' '.$ismodenabled);
14270 if (is_array($element_prop) && (empty($element_prop['module']) || $ismodenabled)) {
14271 if ($useCache === 1 && $element_id > 0
14272 && !empty($conf->cache['fetchObjectByElement'][$element_type])
14273 && !empty($conf->cache['fetchObjectByElement'][$element_type][$element_id])
14274 && is_object($conf->cache['fetchObjectByElement'][$element_type][$element_id])
14276 return $conf->cache['fetchObjectByElement'][$element_type][$element_id];
14279 dol_include_once('/'.$element_prop['classpath'].'/'.$element_prop['classfile'].'.class.php');
14281 if (class_exists($element_prop['classname'])) {
14282 $className = $element_prop['classname'];
14283 $objecttmp = new $className($db);
14284 '@phan-var-force CommonObject $objecttmp';
14286 if ($element_id > 0 || !empty($element_ref)) {
14287 $ret = $objecttmp->fetch($element_id, $element_ref);
14289 if (empty($objecttmp->module)) {
14290 $objecttmp->module = $element_prop['module'];
14293 if ($useCache > 0) {
14294 if (!isset($conf->cache['fetchObjectByElement'][$element_type])) {
14295 $conf->cache['fetchObjectByElement'][$element_type] = [];
14298 // Manage cache limit
14299 if (! empty($conf->cache['fetchObjectByElement'][$element_type]) && is_array($conf->cache['fetchObjectByElement'][$element_type]) && count($conf->cache['fetchObjectByElement'][$element_type]) >= $maxCacheByType) {
14300 array_shift($conf->cache['fetchObjectByElement'][$element_type]);
14303 $conf->cache['fetchObjectByElement'][$element_type][$element_id] = $objecttmp;
14309 return $objecttmp; // returned an object without fetch
14312 dol_syslog($element_prop['classname'].' doesn\'t exists in /'.$element_prop['classpath'].'/'.$element_prop['classfile'].'.class.php');
14325function getExecutableContent()
14327 $arrayofregexextension = array(
14328 'htm', 'html', 'shtml', 'js', 'phar', 'php', 'php3', 'php4', 'php5', 'phtml', 'pht', 'pl', 'py', 'cgi', 'ksh', 'sh', 'shtml',
14329 'bash', 'bat', 'cmd', 'wpk', 'exe', 'dmg', 'appimage'
14332 return $arrayofregexextension;
14341function isAFileWithExecutableContent($filename)
14343 $arrayofregexextension = getExecutableContent();
14345 foreach ($arrayofregexextension as $fileextension) {
14346 if (preg_match('/\.'.preg_quote($fileextension, '/').'$/i', $filename)) {
14363 return empty($_SESSION['newtoken']) ? '' : $_SESSION['newtoken'];
14373function currentToken()
14375 return isset($_SESSION['token']) ? $_SESSION['token'] : '';
14387 if (empty($conf->cache['nonce'])) {
14388 $conf->cache['nonce'] = dolGetRandomBytes(8);
14391 return $conf->cache['nonce'];
14408function startSimpleTable($header, $link = "
", $arguments = "", $emptyColumns = 0, $number = -1, $pictofulllist = '')
14412 print '<div class="div-
table-responsive-no-min
">';
14413 print '<table class="noborder centpercent
">';
14414 print '<tr class="liste_titre
">';
14416 print ($emptyColumns < 1) ? '<th>' : '<th colspan="'.($emptyColumns + 1).'">';
14418 print '<span class="valignmiddle
">'.$langs->trans($header).'</span>';
14420 if (!empty($link)) {
14421 if (!empty($arguments)) {
14422 print '<a href="'.DOL_URL_ROOT.'/
'.$link.'?
'.$arguments.'">';
14424 print '<a href="'.DOL_URL_ROOT.'/
'.$link.'">';
14428 if ($number > -1) {
14429 print '<span class="badge marginleftonlyshort
">'.$number.'</span>';
14430 } elseif (!empty($link)) {
14431 print '<span class="badge marginleftonlyshort
">...</span>';
14434 if (!empty($link)) {
14440 if ($number < 0 && !empty($link)) {
14441 print '<th class="right
">';
14456function finishSimpleTable($addLineBreak = false)
14461 if ($addLineBreak) {
14477function addSummaryTableLine($tableColumnCount, $num, $nbofloop = 0, $total = 0, $noneWord = "None
", $extraRightColumn = false)
14482 print '<tr class="oddeven
">';
14483 print '<td colspan="'.$tableColumnCount.'"><span class="opacitymedium
">'.$langs->trans($noneWord).'</span></td>';
14488 if ($nbofloop === 0) {
14489 // don't show a summary line
14493 /* Case already handled above, commented to satisfy phpstan.
14495 $colspan = $tableColumnCount;
14498 if ($num > $nbofloop) {
14499 $colspan = $tableColumnCount;
14501 $colspan = $tableColumnCount - 1;
14504 if ($extraRightColumn) {
14508 print '<tr class="liste_total
">';
14510 if ($nbofloop > 0 && $num > $nbofloop) {
14511 print '<td colspan="'.$colspan.'" class="right
">'.$langs->trans("XMoreLines
", ($num - $nbofloop)).'</td>';
14513 print '<td colspan="'.$colspan.'" class="right
"> '.$langs->trans("Total
").'</td>';
14514 print '<td class="right centpercent
">'.price($total).'</td>';
14517 if ($extraRightColumn) {
14532function readfileLowMemory($fullpath_original_file_osencoded, $method = -1)
14534 if ($method == -1) {
14536 if (getDolGlobalString('MAIN_FORCE_READFILE_WITH_FREAD')) {
14539 if (getDolGlobalString('MAIN_FORCE_READFILE_WITH_STREAM_COPY')) {
14544 // Be sure we don't have output buffering enabled to have readfile working correctly
14545 while (ob_get_level()) {
14550 if ($method == 0) {
14551 readfile($fullpath_original_file_osencoded);
14552 } elseif ($method == 1) {
14554 $handle = fopen($fullpath_original_file_osencoded, "rb
");
14555 while (!feof($handle)) {
14556 print fread($handle, 8192);
14559 } elseif ($method == 2) {
14561 $handle1 = fopen($fullpath_original_file_osencoded, "rb
");
14562 $handle2 = fopen("php:
14563 stream_copy_to_stream($handle1, $handle2);
14584 $result =
'<span class="clipboardCP'.($showonlyonhover ?
' clipboardCPShowOnHover' :
'').
'">';
14585 if ($texttoshow ===
'none') {
14586 $result .=
'<'.$tag.
' class="clipboardCPValue hidewithsize">'.
dol_escape_htmltag($valuetocopy, 1, 1).
'</'.$tag.
'>';
14587 $result .=
'<span class="clipboardCPValueToPrint"></span>';
14588 } elseif ($texttoshow) {
14589 $result .=
'<'.$tag.
' class="clipboardCPValue hidewithsize">'.
dol_escape_htmltag($valuetocopy, 1, 1).
'</'.$tag.
'>';
14590 $result .=
'<span class="clipboardCPValueToPrint">'.dol_escape_htmltag($texttoshow, 1, 1).
'</span>';
14592 $result .=
'<'.$tag.
' class="clipboardCPValue">'.
dol_escape_htmltag($valuetocopy, 1, 1).
'</'.$tag.
'>';
14594 $result .=
'<span class="clipboardCPButton far fa-clipboard opacitymedium paddingleft pictomodule" title="'.dolPrintHTML($langs->trans(
"ClickToCopyToClipboard")).
'"></span>';
14595 $result .=
img_picto(
'',
'tick',
'class="clipboardCPTick hidden paddingleft pictomodule"');
14596 $result .=
'<span class="clipboardCPText"></span>';
14597 $result .=
'</span>';
14611 $result = json_decode($stringtodecode);
14612 if ($result ===
null) {
14613 $result = unserialize($stringtodecode);
14640 if (is_null($filter) || !is_string($filter) || $filter ===
'') {
14643 if (!preg_match(
'/^\(.*\)$/', $filter)) {
14644 $filter =
'(' . $filter .
')';
14647 $regexstring =
'\(([a-zA-Z0-9_\.]+:[<>!=insotlke]+:[^\(\)]+)\)';
14648 $firstandlastparenthesis = 0;
14650 if (!
dolCheckFilters($filter, $errorstr, $firstandlastparenthesis)) {
14654 return 'Filter syntax error - '.$errorstr;
14659 $t = preg_replace_callback(
'/'.$regexstring.
'/i',
'dolForgeDummyCriteriaCallback', $filter);
14660 $t = str_ireplace(array(
'and',
'or',
' '),
'', $t);
14663 if (preg_match(
'/[^\(\)]/', $t)) {
14664 $tmperrorstr =
'Bad syntax of the search string';
14665 $errorstr =
'Bad syntax of the search string: '.$filter;
14669 dol_syslog(
"forgeSQLFromUniversalSearchCriteria Filter error - ".$errorstr, LOG_WARNING);
14670 return 'Filter error - '.$tmperrorstr;
14674 $ret = ($noand ?
"" :
" AND ").($nopar ?
"" :
'(').preg_replace_callback(
'/'.$regexstring.
'/i',
'dolForgeSQLCriteriaCallback', $filter).($nopar ?
"" :
')');
14676 if (is_object($db)) {
14677 $ret = str_replace(
'__NOW__',
"'".$db->idate(
dol_now()).
"'", $ret);
14679 if (is_object($user)) {
14680 $ret = str_replace(
'__USER_ID__', (
string) $user->id, $ret);
14695 $arrayofandtags = array();
14699 $parenthesislevel = 0;
14704 if ($parenthesislevel >= 1) {
14705 $sqlfilters = preg_replace(
'/^\(/',
'', preg_replace(
'/\)$/',
'', $sqlfilters));
14710 $countparenthesis = 0;
14711 while ($i < $nbofchars) {
14714 if ($char ==
'(') {
14715 $countparenthesis++;
14716 } elseif ($char ==
')') {
14717 $countparenthesis--;
14720 if ($countparenthesis == 0) {
14721 $char2 =
dol_substr($sqlfilters, $i + 1, 1);
14722 $char3 =
dol_substr($sqlfilters, $i + 2, 1);
14723 if ($char ==
'A' && $char2 ==
'N' && $char3 ==
'D') {
14726 if (!preg_match(
'/^\(.*\)$/', $s)) {
14729 $arrayofandtags[] = $s;
14742 if (!preg_match(
'/^\(.*\)$/', $s)) {
14745 $arrayofandtags[] = $s;
14748 return $arrayofandtags;
14760function dolCheckFilters($sqlfilters, &$error =
'', &$parenthesislevel = 0)
14764 $tmp = $sqlfilters;
14768 $parenthesislevel = 0;
14776 if ($char ==
'(') {
14777 if ($i == $parenthesislevel && $parenthesislevel == $counter) {
14779 $parenthesislevel++;
14782 } elseif ($char ==
')') {
14783 $nbcharremaining = ($nb - $i - 1);
14784 if ($nbcharremaining >= $counter) {
14785 $parenthesislevel = min($parenthesislevel, $counter - 1);
14787 if ($parenthesislevel > $counter && $nbcharremaining >= $counter) {
14788 $parenthesislevel = $counter;
14793 if ($counter < 0) {
14794 $error =
"Wrong balance of parenthesis in sqlfilters=".$sqlfilters;
14795 $parenthesislevel = 0;
14803 if ($counter > 0) {
14804 $error =
"Wrong balance of parenthesis in sqlfilters=".$sqlfilters;
14805 $parenthesislevel = 0;
14823 if (empty($matches[1])) {
14826 $tmp = explode(
':', $matches[1]);
14827 if (count($tmp) < 3) {
14847 if (empty($matches[1])) {
14850 $tmp = explode(
':', $matches[1], 3);
14851 if (count($tmp) < 3) {
14855 $operand = preg_replace(
'/[^a-z0-9\._]/i',
'', trim($tmp[0]));
14857 $operator = strtoupper(preg_replace(
'/[^a-z<>!=]/i',
'', trim($tmp[1])));
14860 'NOTLIKE' =>
'NOT LIKE',
14861 'ISNOT' =>
'IS NOT',
14862 'NOTIN' =>
'NOT IN',
14866 if (array_key_exists($operator, $realOperator)) {
14867 $operator = $realOperator[$operator];
14870 $tmpescaped = $tmp[2];
14876 if ($operator ==
'IN' || $operator ==
'NOT IN') {
14878 $tmpescaped2 =
'(';
14880 $tmpelemarray = explode(
',', $tmpescaped);
14881 foreach ($tmpelemarray as $tmpkey => $tmpelem) {
14883 $tmpelem = trim($tmpelem);
14884 if (preg_match(
'/^\'(.*)\'$/', $tmpelem, $reg)) {
14885 $tmpelemarray[$tmpkey] =
"'".$db->escape($db->sanitize($reg[1], 2, 1, 1, 1)).
"'";
14886 } elseif (preg_match(
'/^[0-9]+$/', (
string) $tmpelem)) {
14887 $tmpelemarray[$tmpkey] = (int) $tmpelem;
14888 } elseif (is_numeric((
string) $tmpelem)) {
14889 $tmpelemarray[$tmpkey] = (float) $tmpelem;
14890 } elseif (!
getDolGlobalString(
"MAIN_DISALLOW_UNSECURED_SELECT_INTO_EXTRAFIELDS_FILTER")) {
14891 $tmpelemarray[$tmpkey] = preg_replace(
'/[^a-z0-9_<>=!\s]/i',
'', $tmpelem);
14893 $tmpelemarray[$tmpkey] = preg_replace(
'/[^a-z0-9_]/i',
'', $tmpelem);
14896 $tmpescaped2 .= implode(
',', $tmpelemarray);
14897 $tmpescaped2 .=
')';
14899 $tmpescaped = $tmpescaped2;
14900 } elseif ($operator ==
'LIKE' || $operator ==
'NOT LIKE') {
14901 if (preg_match(
'/^\'([^\']*)\'$/', $tmpescaped, $regbis)) {
14902 $tmpescaped = $regbis[1];
14905 $tmpescaped =
"'".$db->escape($tmpescaped).
"'";
14906 } elseif (preg_match(
'/^\'(.*)\'$/', $tmpescaped, $regbis)) {
14909 $tmpescaped =
"'".$db->escape($regbis[1]).
"'";
14911 if (strtoupper($tmpescaped) ==
'NULL') {
14912 $tmpescaped =
'NULL';
14913 } elseif (preg_match(
'/^[0-9]+$/', (
string) $tmpescaped)) {
14914 $tmpescaped = (int) $tmpescaped;
14915 } elseif (is_numeric((
string) $tmpescaped)) {
14916 $tmpescaped = (float) $tmpescaped;
14918 $tmpescaped = preg_replace(
'/[^a-z0-9_]/i',
'', $tmpescaped);
14922 return '('.$db->escape($operand).
' '.strtoupper($operator).
' '.$tmpescaped.
')';
14939 $out =
'<!-- timeline icon -->'.
"\n";
14940 $iconClass =
'fa fa-comments';
14945 if ($histo[$key][
'percent'] == -1) {
14946 $colorClass =
'timeline-icon-not-applicble';
14947 $pictoTitle = $langs->trans(
'StatusNotApplicable');
14948 } elseif ($histo[$key][
'percent'] == 0) {
14949 $colorClass =
'timeline-icon-todo';
14950 $pictoTitle = $langs->trans(
'StatusActionToDo').
' (0%)';
14951 } elseif ($histo[$key][
'percent'] > 0 && $histo[$key][
'percent'] < 100) {
14952 $colorClass =
'timeline-icon-in-progress';
14953 $pictoTitle = $langs->trans(
'StatusActionInProcess').
' ('.$histo[$key][
'percent'].
'%)';
14954 } elseif ($histo[$key][
'percent'] >= 100) {
14955 $colorClass =
'timeline-icon-done';
14956 $pictoTitle = $langs->trans(
'StatusActionDone').
' (100%)';
14959 if ($actionstatic->code ==
'AC_TICKET_CREATE') {
14960 $iconClass =
'fa fa-ticket';
14961 } elseif ($actionstatic->code ==
'AC_TICKET_MODIFY') {
14962 $iconClass =
'fa fa-pencilxxx';
14963 } elseif (preg_match(
'/^TICKET_MSG/', $actionstatic->code)) {
14964 $iconClass =
'fa fa-comments';
14965 } elseif (preg_match(
'/^TICKET_MSG_PRIVATE/', $actionstatic->code)) {
14966 $iconClass =
'fa fa-mask';
14968 if ($actionstatic->type_picto) {
14969 $img_picto =
img_picto(
'', $actionstatic->type_picto);
14971 if ($actionstatic->type_code ==
'AC_RDV') {
14972 $iconClass =
'fa fa-handshake';
14973 } elseif ($actionstatic->type_code ==
'AC_TEL') {
14974 $iconClass =
'fa fa-phone';
14975 } elseif ($actionstatic->type_code ==
'AC_FAX') {
14976 $iconClass =
'fa fa-fax';
14977 } elseif ($actionstatic->type_code ==
'AC_EMAIL') {
14978 $iconClass =
'fa fa-envelope';
14979 } elseif ($actionstatic->type_code ==
'AC_INT') {
14980 $iconClass =
'fa fa-shipping-fast';
14981 } elseif ($actionstatic->type_code ==
'AC_OTH_AUTO') {
14982 $iconClass =
'fa fa-robot';
14983 } elseif (!preg_match(
'/_AUTO/', $actionstatic->type_code)) {
14984 $iconClass =
'fa fa-robot';
14989 $out .=
'<i class="'.$iconClass.
' '.$colorClass.
'" title="'.$pictoTitle.
'">'.$img_picto.
'</i>'.
"\n";
15003 $documents = array();
15005 $sql =
'SELECT ecm.rowid as id, ecm.src_object_type, ecm.src_object_id, ecm.filepath, ecm.filename, ecm.agenda_id';
15006 $sql .=
' FROM '.MAIN_DB_PREFIX.
'ecm_files ecm';
15007 $sql .=
" WHERE ecm.filepath = 'agenda/".((int)
$object->id).
"'";
15009 $sql.=
' OR ecm.agenda_id = '.(int)
$object->id;
15010 $sql .=
' ORDER BY ecm.position ASC';
15012 $resql = $db->query($sql);
15014 if ($db->num_rows($resql)) {
15015 while ($obj = $db->fetch_object($resql)) {
15016 $documents[$obj->id] = $obj;
15042function show_actions_messaging(
$conf, $langs, $db, $filterobj, $objcon =
null, $noprint = 0, $actioncode =
'', $donetodo =
'done', $filters = array(), $sortfield =
'a.datep,a.id', $sortorder =
'DESC')
15044 global $user,
$conf;
15047 global $param, $massactionbutton;
15049 require_once DOL_DOCUMENT_ROOT .
'/comm/action/class/actioncomm.class.php';
15052 if (!is_object($filterobj) && !is_object($objcon)) {
15057 '@phan-var-force array<int,array{type:string,tododone:string,id:string,datestart:int|string,dateend:int|string,note:string,message:string,percent:string,userid:string,login:string,userfirstname:string,userlastname:string,userphoto:string,msg_from?:string,contact_id?:string,socpeopleassigned?:int[],lastname?:string,firstname?:string,fk_element?:int,elementtype?:string,acode:string,alabel?:string,libelle?:string,apicto?:string}> $histo';
15062 $sortfield_list = explode(
',', $sortfield);
15063 $sortfield_label_list = array(
'a.id' =>
'id',
'a.datep' =>
'dp',
'a.percent' =>
'percent');
15064 $sortfield_new_list = array();
15065 foreach ($sortfield_list as $sortfield_value) {
15066 $sortfield_new_list[] = $sortfield_label_list[trim($sortfield_value)];
15068 $sortfield_new = implode(
',', $sortfield_new_list);
15073 if (isModEnabled(
'agenda')) {
15075 if (is_object($objcon) && $objcon->id > 0) {
15076 $sql =
"SELECT DISTINCT a.id, a.label as label,";
15078 $sql =
"SELECT a.id, a.label as label,";
15080 $sql .=
" a.datep as dp,";
15081 $sql .=
" a.note as message,";
15082 $sql .=
" a.datep2 as dp2,";
15083 $sql .=
" a.percent as percent, 'action' as type,";
15084 $sql .=
" a.fk_element, a.elementtype,";
15085 $sql .=
" a.fk_contact,";
15086 $sql .=
" a.email_from as msg_from,";
15087 $sql .=
" c.code as acode, c.libelle as alabel, c.picto as apicto,";
15088 $sql .=
" u.rowid as user_id, u.login as user_login, u.photo as user_photo, u.firstname as user_firstname, u.lastname as user_lastname";
15089 if (is_object($filterobj) && get_class($filterobj) ==
'Societe') {
15090 $sql .=
", sp.lastname, sp.firstname";
15091 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Adherent') {
15092 $sql .=
", m.lastname, m.firstname";
15093 } elseif (is_object($filterobj) && in_array(get_class($filterobj), array(
'Commande',
'CommandeFournisseur',
'Product',
'Ticket',
'BOM',
'Contrat',
'Facture',
'FactureFournisseur'))) {
15096 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
15097 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on u.rowid = a.fk_user_action";
15098 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_actioncomm as c ON a.fk_action = c.id";
15100 $force_filter_contact = $filterobj instanceof
User;
15102 if (is_object($objcon) && $objcon->id > 0) {
15103 $force_filter_contact =
true;
15104 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"actioncomm_resources as r ON a.id = r.fk_actioncomm";
15105 $sql .=
" AND r.element_type = '".$db->escape($objcon->table_element).
"' AND r.fk_element = ".((int) $objcon->id);
15108 if ((is_object($filterobj) && get_class($filterobj) ==
'Societe') || (is_object($filterobj) && get_class($filterobj) ==
'Contact')) {
15109 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople as sp ON a.fk_contact = sp.rowid";
15110 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Dolresource') {
15111 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"element_resources as er";
15112 $sql .=
" ON er.resource_type = 'dolresource'";
15113 $sql .=
" AND er.element_id = a.id";
15114 $sql .=
" AND er.resource_id = ".((int) $filterobj->id);
15115 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Adherent') {
15116 $sql .=
", ".MAIN_DB_PREFIX.
"adherent as m";
15117 } elseif (is_object($filterobj) && get_class($filterobj) ==
'CommandeFournisseur') {
15118 $sql .=
", ".MAIN_DB_PREFIX.
"commande_fournisseur as o";
15119 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Product') {
15120 $sql .=
", ".MAIN_DB_PREFIX.
"product as o";
15121 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Ticket') {
15122 $sql .=
", ".MAIN_DB_PREFIX.
"ticket as o";
15123 } elseif (is_object($filterobj) && get_class($filterobj) ==
'BOM') {
15124 $sql .=
", ".MAIN_DB_PREFIX.
"bom_bom as o";
15125 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Contrat') {
15126 $sql .=
", ".MAIN_DB_PREFIX.
"contrat as o";
15127 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Facture') {
15128 $sql .=
", ".MAIN_DB_PREFIX.
"facture as o";
15129 } elseif (is_object($filterobj) && get_class($filterobj) ==
'FactureFournisseur') {
15130 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as o";
15133 $sql .=
" WHERE a.entity IN (".getEntity(
'agenda').
")";
15134 if (!$force_filter_contact) {
15135 if (is_object($filterobj) && in_array(get_class($filterobj), array(
'Societe',
'Client',
'Fournisseur')) && $filterobj->id) {
15136 $sql .=
" AND a.fk_soc = ".((int) $filterobj->id);
15137 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Project' && $filterobj->id) {
15138 $sql .=
" AND a.fk_project = ".((int) $filterobj->id);
15139 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Adherent') {
15140 $sql .=
" AND a.fk_element = m.rowid AND a.elementtype = 'member'";
15141 if ($filterobj->id) {
15142 $sql .=
" AND a.fk_element = ".((int) $filterobj->id);
15144 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Commande') {
15145 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'order'";
15146 if ($filterobj->id) {
15147 $sql .=
" AND a.fk_element = ".((int) $filterobj->id);
15149 } elseif (is_object($filterobj) && get_class($filterobj) ==
'CommandeFournisseur') {
15150 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'order_supplier'";
15151 if ($filterobj->id) {
15152 $sql .=
" AND a.fk_element = ".((int) $filterobj->id);
15154 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Product') {
15155 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'product'";
15156 if ($filterobj->id) {
15157 $sql .=
" AND a.fk_element = ".((int) $filterobj->id);
15159 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Ticket') {
15160 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'ticket'";
15161 if ($filterobj->id) {
15162 $sql .=
" AND a.fk_element = ".((int) $filterobj->id);
15164 } elseif (is_object($filterobj) && get_class($filterobj) ==
'BOM') {
15165 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'bom'";
15166 if ($filterobj->id) {
15167 $sql .=
" AND a.fk_element = ".((int) $filterobj->id);
15169 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Contrat') {
15170 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'contract'";
15171 if ($filterobj->id) {
15172 $sql .=
" AND a.fk_element = ".((int) $filterobj->id);
15174 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Contact' && $filterobj->id) {
15175 $sql .=
" AND a.fk_contact = sp.rowid";
15176 if ($filterobj->id) {
15177 $sql .=
" AND a.fk_contact = ".((int) $filterobj->id);
15179 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Facture') {
15180 $sql .=
" AND a.fk_element = o.rowid";
15181 if ($filterobj->id) {
15182 $sql .=
" AND a.fk_element = ".((int) $filterobj->id).
" AND a.elementtype = 'invoice'";
15184 } elseif (is_object($filterobj) && get_class($filterobj) ==
'FactureFournisseur') {
15185 $sql .=
" AND a.fk_element = o.rowid";
15186 if ($filterobj->id) {
15187 $sql .=
" AND a.fk_element = ".((int) $filterobj->id).
" AND a.elementtype = 'invoice_supplier'";
15191 $sql .=
" AND u.rowid = ". ((int) $filterobj->id);
15195 if (!empty($actioncode) && $actioncode !=
'-1') {
15197 if ($actioncode ==
'AC_NON_AUTO') {
15198 $sql .=
" AND c.type != 'systemauto'";
15199 } elseif ($actioncode ==
'AC_ALL_AUTO') {
15200 $sql .=
" AND c.type = 'systemauto'";
15202 if ($actioncode ==
'AC_OTH') {
15203 $sql .=
" AND c.type != 'systemauto'";
15204 } elseif ($actioncode ==
'AC_OTH_AUTO') {
15205 $sql .=
" AND c.type = 'systemauto'";
15209 if ($actioncode ==
'AC_NON_AUTO') {
15210 $sql .=
" AND c.type != 'systemauto'";
15211 } elseif ($actioncode ==
'AC_ALL_AUTO') {
15212 $sql .=
" AND c.type = 'systemauto'";
15214 $sql .=
" AND c.code = '".$db->escape($actioncode).
"'";
15218 if ($donetodo ==
'todo') {
15219 $sql .=
" AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now).
"'))";
15220 } elseif ($donetodo ==
'done') {
15221 $sql .=
" AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now).
"'))";
15223 if (is_array($filters) && $filters[
'search_agenda_label']) {
15224 $sql .=
natural_search(
'a.label', $filters[
'search_agenda_label']);
15229 if (isModEnabled(
'mailing') && !empty($objcon->email)
15230 && (empty($actioncode) || $actioncode ==
'AC_OTH_AUTO' || $actioncode ==
'AC_EMAILING')) {
15231 $langs->load(
"mails");
15233 $sql2 =
"SELECT m.rowid as id, m.titre as label, mc.date_envoi as dp, mc.date_envoi as dp2, '100' as percent, 'mailing' as type";
15234 $sql2 .=
", null as fk_element, '' as elementtype, null as contact_id";
15235 $sql2 .=
", 'AC_EMAILING' as acode, '' as alabel, '' as apicto";
15236 $sql2 .=
", u.rowid as user_id, u.login as user_login, u.photo as user_photo, u.firstname as user_firstname, u.lastname as user_lastname";
15237 if (is_object($filterobj) && get_class($filterobj) ==
'Societe') {
15238 $sql2 .=
", '' as lastname, '' as firstname";
15239 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Adherent') {
15240 $sql2 .=
", '' as lastname, '' as firstname";
15241 } elseif (is_object($filterobj) && get_class($filterobj) ==
'CommandeFournisseur') {
15242 $sql2 .=
", '' as ref";
15243 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Product') {
15244 $sql2 .=
", '' as ref";
15245 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Ticket') {
15246 $sql2 .=
", '' as ref";
15248 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"mailing as m, ".MAIN_DB_PREFIX.
"mailing_cibles as mc, ".MAIN_DB_PREFIX.
"user as u";
15249 $sql2 .=
" WHERE mc.email = '".$db->escape($objcon->email).
"'";
15250 $sql2 .=
" AND mc.statut = 1";
15251 $sql2 .=
" AND u.rowid = m.fk_user_valid";
15252 $sql2 .=
" AND mc.fk_mailing=m.rowid";
15255 if ($sql || $sql2) {
15256 if (!empty($sql) && !empty($sql2)) {
15257 $sql = $sql.
" UNION ".$sql2;
15258 } elseif (empty($sql) && !empty($sql2)) {
15267 $sql .= $db->order($sortfield_new, $sortorder);
15269 $sql .= $db->plimit($limit + 1, $offset);
15272 dol_syslog(
"function.lib::show_actions_messaging", LOG_DEBUG);
15273 $resql = $db->query($sql);
15276 $num = $db->num_rows($resql);
15278 $imaxinloop = ($limit ? min($num, $limit) : $num);
15279 while ($i < $imaxinloop) {
15280 $obj = $db->fetch_object($resql);
15282 if ($obj->type ==
'action') {
15284 $contactaction->id = $obj->id;
15285 $result = $contactaction->fetchResources();
15288 setEventMessage(
"actions.lib::show_actions_messaging Error fetch resource",
'errors');
15294 if (($obj->percent >= 0 and $obj->percent < 100) || ($obj->percent == -1 && $obj->dp > $now)) {
15295 $tododone =
'todo';
15298 $histo[$numaction] = array(
15299 'type' => $obj->type,
15300 'tododone' => $tododone,
15302 'datestart' => $db->jdate($obj->dp),
15303 'dateend' => $db->jdate($obj->dp2),
15304 'note' => $obj->label,
15306 'percent' => $obj->percent,
15308 'userid' => $obj->user_id,
15309 'login' => $obj->user_login,
15310 'userfirstname' => $obj->user_firstname,
15311 'userlastname' => $obj->user_lastname,
15312 'userphoto' => $obj->user_photo,
15313 'msg_from' => $obj->msg_from,
15315 'contact_id' => $obj->fk_contact,
15316 'socpeopleassigned' => $contactaction->socpeopleassigned,
15317 'lastname' => (empty($obj->lastname) ?
'' : $obj->lastname),
15318 'firstname' => (empty($obj->firstname) ?
'' : $obj->firstname),
15319 'fk_element' => $obj->fk_element,
15320 'elementtype' => $obj->elementtype,
15322 'acode' => $obj->acode,
15323 'alabel' => $obj->alabel,
15324 'libelle' => $obj->alabel,
15325 'apicto' => $obj->apicto
15328 $histo[$numaction] = array(
15329 'type' => $obj->type,
15330 'tododone' =>
'done',
15332 'datestart' => $db->jdate($obj->dp),
15333 'dateend' => $db->jdate($obj->dp2),
15334 'note' => $obj->label,
15336 'percent' => $obj->percent,
15337 'acode' => $obj->acode,
15339 'userid' => $obj->user_id,
15340 'login' => $obj->user_login,
15341 'userfirstname' => $obj->user_firstname,
15342 'userlastname' => $obj->user_lastname,
15343 'userphoto' => $obj->user_photo
15358 if (!isModEnabled(
'agenda')) {
15359 $langs->loadLangs(array(
"admin",
"errors"));
15360 $out =
info_admin($langs->trans(
"WarningModuleXDisabledSoYouMayMissEventHere", $langs->transnoentitiesnoconv(
"Module2400Name")), 0, 0,
'warning');
15363 if (isModEnabled(
'agenda') || (isModEnabled(
'mailing') && !empty($objcon->email))) {
15364 $delay_warning =
getDolGlobalInt(
'MAIN_DELAY_ACTIONS_TODO') * 24 * 60 * 60;
15366 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
15367 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
15368 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
15369 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
15374 $userstatic =
new User($db);
15375 $contactstatic =
new Contact($db);
15376 $userGetNomUrlCache = array();
15377 $contactGetNomUrlCache = array();
15379 $out .=
'<div class="filters-container" >';
15380 $out .=
'<form name="listactionsfilter" class="listactionsfilter" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
15381 $out .=
'<input type="hidden" name="token" value="'.newToken().
'">';
15383 if ($objcon && get_class($objcon) ==
'Contact' &&
15384 (is_null($filterobj) || get_class($filterobj) ==
'Societe')) {
15385 $out .=
'<input type="hidden" name="id" value="'.$objcon->id.
'" />';
15387 $out .=
'<input type="hidden" name="id" value="'.$filterobj->id.
'" />';
15389 if (($filterobj && get_class($filterobj) ==
'Societe')) {
15390 $out .=
'<input type="hidden" name="socid" value="'.$filterobj->id.
'" />';
15392 $out .=
'<input type="hidden" name="userid" value="'.$filterobj->id.
'" />';
15397 $out .=
'<div class="div-table-responsive-no-min">';
15398 $out .=
'<table class="noborder borderbottom centpercent">';
15400 $out .=
'<tr class="liste_titre">';
15404 $out .=
'<th class="liste_titre width50 middle">';
15405 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0,
'checkforselect', 1);
15406 $out .= $searchpicto;
15411 $out .=
getTitleFieldOfList(
'Date', 0, $_SERVER[
"PHP_SELF"],
'a.datep',
'', $param,
'', $sortfield, $sortorder,
'nowraponall nopaddingleftimp ').
"\n";
15413 $out .=
'<th class="liste_titre hideonsmartphone"><strong class="hideonsmartphone">'.$langs->trans(
"Search").
' : </strong></th>';
15415 $out .=
'<th class="liste_titre"></th>';
15418 $out .=
'<th class="liste_titre">';
15419 $out .=
'<span class="fas fa-square inline-block fawidth30 hideonsmartphone" style="color: #ddd;" title="'.$langs->trans(
"ActionType").
'"></span>';
15420 $out .= $formactions->select_type_actions($actioncode,
"actioncode",
'',
getDolGlobalString(
'AGENDA_USE_EVENT_TYPE') ? -1 : 1, 0, 0, 1,
'selecttype minwidth100', $langs->trans(
"Type"));
15423 $out .=
'<th class="liste_titre maxwidth100onsmartphone">';
15424 $out .=
'<input type="text" class="maxwidth100onsmartphone" name="search_agenda_label" value="'.$filters[
'search_agenda_label'].
'" placeholder="'.$langs->trans(
"Label").
'">';
15429 $out .=
'<th class="liste_titre width50 middle">';
15430 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0,
'checkforselect', 1);
15431 $out .= $searchpicto;
15437 $out .=
'</table>';
15444 $out .=
'<ul class="timeline">';
15448 if ($filterobj instanceof
Societe) {
15449 $tmp .=
'<a href="'.DOL_URL_ROOT.
'/comm/action/list.php?mode=show_list&socid='.$filterobj->id.
'&status=done">';
15451 if ($filterobj instanceof
User) {
15452 $tmp .=
'<a href="'.DOL_URL_ROOT.
'/comm/action/list.php?mode=show_list&socid='.$filterobj->id.
'&status=done">';
15454 $tmp .= ($donetodo !=
'done' ? $langs->trans(
"ActionsToDoShort") :
'');
15455 $tmp .= ($donetodo !=
'done' && $donetodo !=
'todo' ?
' / ' :
'');
15456 $tmp .= ($donetodo !=
'todo' ? $langs->trans(
"ActionsDoneShort") :
'');
15458 if ($filterobj instanceof
Societe) {
15461 if ($filterobj instanceof
User) {
15467 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/cactioncomm.class.php';
15469 $arraylist = $caction->liste_array(1,
'code',
'', (!
getDolGlobalString(
'AGENDA_USE_EVENT_TYPE') ? 1 : 0),
'', 1);
15471 $actualCycleDate =
false;
15474 foreach ($histo as $key => $value) {
15475 $actionstatic->fetch($histo[$key][
'id']);
15477 $actionstatic->type_picto = $histo[$key][
'apicto'];
15478 $actionstatic->type_code = $histo[$key][
'acode'];
15480 $labeltype = $actionstatic->type_code;
15481 if (!
getDolGlobalString(
'AGENDA_USE_EVENT_TYPE') && empty($arraylist[$labeltype])) {
15482 $labeltype =
'AC_OTH';
15484 if (!empty($actionstatic->code) && preg_match(
'/^TICKET_MSG/', $actionstatic->code)) {
15485 $labeltype = $langs->trans(
"Message");
15487 if (!empty($arraylist[$labeltype])) {
15488 $labeltype = $arraylist[$labeltype];
15490 if ($actionstatic->type_code ==
'AC_OTH_AUTO' && ($actionstatic->type_code != $actionstatic->code) && $labeltype && !empty($arraylist[$actionstatic->code])) {
15491 $labeltype .=
' - '.$arraylist[$actionstatic->code];
15495 $url = DOL_URL_ROOT.
'/comm/action/card.php?id='.$histo[$key][
'id'];
15497 $tmpa =
dol_getdate($histo[$key][
'datestart'],
false);
15499 if (isset($tmpa[
'year']) && isset($tmpa[
'yday']) && $actualCycleDate !== $tmpa[
'year'].
'-'.$tmpa[
'yday']) {
15500 $actualCycleDate = $tmpa[
'year'].
'-'.$tmpa[
'yday'];
15501 $out .=
'<!-- timeline time label -->';
15502 $out .=
'<li class="time-label">';
15503 $out .=
'<span class="timeline-badge-date">';
15504 $out .=
dol_print_date($histo[$key][
'datestart'],
'daytext',
'tzuserrel', $langs);
15507 $out .=
'<!-- /.timeline-label -->';
15511 $out .=
'<!-- timeline item -->'.
"\n";
15512 $out .=
'<li class="timeline-code-'.(!empty($actionstatic->code) ? strtolower($actionstatic->code) :
"none").
'">';
15515 $typeicon = $actionstatic->getTypePicto(
'pictofixedwidth timeline-icon-not-applicble', $labeltype);
15520 $out .=
'<div class="timeline-item">'.
"\n";
15522 $out .=
'<span class="time timeline-header-action2">';
15524 if (isset($histo[$key][
'type']) && $histo[$key][
'type'] ==
'mailing') {
15525 $out .=
'<a class="paddingleft paddingright timeline-btn2 editfielda" href="'.DOL_URL_ROOT.
'/comm/mailing/card.php?id='.$histo[$key][
'id'].
'">'.
img_object($langs->trans(
"ShowEMailing"),
"email").
' ';
15526 $out .= $histo[$key][
'id'];
15529 $out .= $actionstatic->getNomUrl(1, -1,
'valignmiddle').
' ';
15532 if ($user->hasRight(
'agenda',
'allactions',
'create') ||
15533 (($actionstatic->authorid == $user->id || $actionstatic->userownerid == $user->id) && $user->hasRight(
'agenda',
'myactions',
'create'))) {
15534 $out .=
'<a class="paddingleft paddingright timeline-btn2 editfielda" href="'.DOL_MAIN_URL_ROOT.
'/comm/action/card.php?action=edit&token='.
newToken().
'&id='.$actionstatic->id.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?'.$param).
'">';
15536 $out .=
img_picto($langs->trans(
"Modify"),
'edit',
'class="edita"');
15543 $out .=
'<span class="time"><i class="fa fa-clock-o valignmiddle"></i> <span class="valignmiddle">';
15544 $out .=
dol_print_date($histo[$key][
'datestart'],
'dayhour',
'tzuserrel');
15545 if ($histo[$key][
'dateend'] && $histo[$key][
'dateend'] != $histo[$key][
'datestart']) {
15546 $tmpa =
dol_getdate($histo[$key][
'datestart'],
true);
15547 $tmpb =
dol_getdate($histo[$key][
'dateend'],
true);
15548 if ($tmpa[
'mday'] == $tmpb[
'mday'] && $tmpa[
'mon'] == $tmpb[
'mon'] && $tmpa[
'year'] == $tmpb[
'year']) {
15549 $out .=
'-'.dol_print_date($histo[$key][
'dateend'],
'hour',
'tzuserrel');
15551 $out .=
'-'.dol_print_date($histo[$key][
'dateend'],
'dayhour',
'tzuserrel');
15555 if ($histo[$key][
'percent'] == 0 && $histo[$key][
'datestart'] && $histo[$key][
'datestart'] < ($now - $delay_warning)) {
15558 if ($histo[$key][
'percent'] == 0 && !$histo[$key][
'datestart'] && $histo[$key][
'dateend'] && $histo[$key][
'datestart'] < ($now - $delay_warning)) {
15561 if ($histo[$key][
'percent'] > 0 && $histo[$key][
'percent'] < 100 && $histo[$key][
'dateend'] && $histo[$key][
'dateend'] < ($now - $delay_warning)) {
15564 if ($histo[$key][
'percent'] > 0 && $histo[$key][
'percent'] < 100 && !$histo[$key][
'dateend'] && $histo[$key][
'datestart'] && $histo[$key][
'datestart'] < ($now - $delay_warning)) {
15570 $out .=
"</span></span>\n";
15572 $out .=
'<span class="time">';
15573 $out .= $actionstatic->getLibStatut(2);
15577 $out .=
'<h3 class="timeline-header">';
15580 $out .=
'<div class="messaging-author inline-block tdoverflowmax150 valignmiddle marginrightonly">';
15581 if ($histo[$key][
'userid'] > 0) {
15582 if (!isset($userGetNomUrlCache[$histo[$key][
'userid']])) {
15583 $userstatic->fetch($histo[$key][
'userid']);
15584 $userGetNomUrlCache[$histo[$key][
'userid']] = $userstatic->getNomUrl(-1,
'', 0, 0, 16, 0,
'firstelselast',
'');
15586 $out .= $userGetNomUrlCache[$histo[$key][
'userid']];
15587 } elseif (!empty($histo[$key][
'msg_from']) && $actionstatic->code ==
'TICKET_MSG') {
15588 if (!isset($contactGetNomUrlCache[$histo[$key][
'msg_from']])) {
15589 if ($contactstatic->fetch(0,
null,
'', $histo[$key][
'msg_from']) > 0) {
15590 $contactGetNomUrlCache[$histo[$key][
'msg_from']] = $contactstatic->getNomUrl(-1,
'', 16);
15592 $contactGetNomUrlCache[$histo[$key][
'msg_from']] = $histo[$key][
'msg_from'];
15595 $out .= $contactGetNomUrlCache[$histo[$key][
'msg_from']];
15600 $out .=
' <div class="messaging-title inline-block">';
15602 if (empty(
$conf->dol_optimize_smallscreen) && $actionstatic->type_code !=
'AC_OTH_AUTO') {
15603 $out .= $labeltype.
' - ';
15608 if (!empty($actionstatic->code) && preg_match(
'/^TICKET_MSG_PRIVATE/', $actionstatic->code)) {
15609 $out .= $langs->trans(
'TicketNewMessage').
' <em>('.$langs->trans(
'Private').
')</em>';
15610 } elseif (!empty($actionstatic->code) && preg_match(
'/^TICKET_MSG/', $actionstatic->code)) {
15611 $out .= $langs->trans(
'TicketNewMessage');
15612 } elseif (isset($histo[$key][
'type'])) {
15613 if ($histo[$key][
'type'] ==
'action') {
15614 $transcode = $langs->transnoentitiesnoconv(
"Action".$histo[$key][
'acode']);
15615 $libelle = ($transcode !=
"Action".$histo[$key][
'acode'] ? $transcode : $histo[$key][
'alabel']);
15616 $libelle = $histo[$key][
'note'];
15617 $actionstatic->id = $histo[$key][
'id'];
15618 if ($libelle != $labeltype) {
15621 } elseif ($histo[$key][
'type'] ==
'mailing') {
15622 $out .=
'<a href="'.DOL_URL_ROOT.
'/comm/mailing/card.php?id='.$histo[$key][
'id'].
'">'.
img_object($langs->trans(
"ShowEMailing"),
"email").
' ';
15623 $transcode = $langs->transnoentitiesnoconv(
"Action".$histo[$key][
'acode']);
15624 $libelle = ($transcode !=
"Action".$histo[$key][
'acode'] ? $transcode :
'Send mass mailing');
15627 $libelle .= $histo[$key][
'note'];
15631 $out = preg_replace(
'/ - $/',
'', $out);
15633 if (isset($histo[$key][
'elementtype']) && !empty($histo[$key][
'fk_element'])) {
15634 if (isset(
$conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']]) && isset(
$conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']][$histo[$key][
'fk_element']])) {
15635 $link =
$conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']][$histo[$key][
'fk_element']];
15637 if (!isset(
$conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']])) {
15638 $conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']] = array();
15640 $link =
dolGetElementUrl($histo[$key][
'fk_element'], $histo[$key][
'elementtype'], 1);
15641 $conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']][$histo[$key][
'fk_element']] = $link;
15644 $out .=
' - '.$link;
15653 if (!empty($histo[$key][
'message'] && $histo[$key][
'message'] != $libelle)
15654 && $actionstatic->code !=
'AC_TICKET_CREATE'
15655 && $actionstatic->code !=
'AC_TICKET_MODIFY'
15657 $out .=
'<div class="timeline-body wordbreak small">';
15658 $truncateLines =
getDolGlobalInt(
'MAIN_TRUNCATE_TIMELINE_MESSAGE', 3);
15660 if ($truncateLines > 0 && strlen($histo[$key][
'message']) > strlen($truncatedText)) {
15661 $out .=
'<div class="readmore-block --closed" >';
15662 $out .=
' <div class="readmore-block__excerpt">';
15664 $out .=
' <br><a class="read-more-link" data-read-more-action="open" href="'.DOL_MAIN_URL_ROOT.
'/comm/action/card.php?id='.$actionstatic->id.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?'.$param).
'" >'.$langs->trans(
"ReadMore").
' <span class="fa fa-chevron-right" aria-hidden="true"></span></a>';
15666 $out .=
' <div class="readmore-block__full-text" >';
15668 $out .=
' <a class="read-less-link" data-read-more-action="close" href="#" ><span class="fa fa-chevron-up" aria-hidden="true"></span> '.$langs->trans(
"ReadLess").
'</a>';
15682 if (isset($histo[$key][
'socpeopleassigned']) && is_array($histo[$key][
'socpeopleassigned']) && count($histo[$key][
'socpeopleassigned']) > 0) {
15684 foreach ($histo[$key][
'socpeopleassigned'] as $cid => $Tab) {
15685 if (empty(
$conf->cache[
'contact'][$cid])) {
15687 $contact->fetch($cid);
15688 $conf->cache[
'contact'][$cid] = $contact;
15690 $contact =
$conf->cache[
'contact'][$cid];
15694 $contactList .= !empty($contactList) ?
', ' :
'';
15695 $contactList .= $contact->getNomUrl(1);
15696 if (isset($histo[$key][
'acode']) && $histo[$key][
'acode'] ==
'AC_TEL') {
15697 if (!empty($contact->phone_pro)) {
15698 $contactList .=
'('.dol_print_phone($contact->phone_pro).
')';
15704 $footer .= $langs->trans(
'ActionOnContact').
' : '.$contactList;
15705 } elseif (empty($objcon->id) && isset($histo[$key][
'contact_id']) && $histo[$key][
'contact_id'] > 0) {
15706 if (empty(
$conf->cache[
'contact'][$histo[$key][
'contact_id']])) {
15708 $result = $contact->fetch($histo[$key][
'contact_id']);
15709 $conf->cache[
'contact'][$histo[$key][
'contact_id']] = $contact;
15711 $contact =
$conf->cache[
'contact'][$histo[$key][
'contact_id']];
15712 $result = ($contact instanceof
Contact) ? $contact->id : 0;
15716 $footer .= $contact->getNomUrl(1);
15717 if (isset($histo[$key][
'acode']) && $histo[$key][
'acode'] ==
'AC_TEL') {
15718 if (!empty($contact->phone_pro)) {
15719 $footer .=
'('.dol_print_phone($contact->phone_pro).
')';
15726 if (!empty($documents)) {
15727 $footer .=
'<div class="timeline-documents-container">';
15728 foreach ($documents as $doc) {
15729 $footer .=
'<span id="document_'.$doc->id.
'" class="timeline-documents" ';
15730 $footer .=
' data-id="'.$doc->id.
'" ';
15731 $footer .=
' data-path="'.$doc->filepath.
'"';
15732 $footer .=
' data-filename="'.dol_escape_htmltag($doc->filename).
'" ';
15735 $filePath = DOL_DATA_ROOT.
'/'.$doc->filepath.
'/'.$doc->filename;
15737 if (empty($doc->agenda_id)) {
15738 $dir_ref = $actionstatic->id;
15739 $modulepart =
'actions';
15741 $split_dir = explode(
'/', $doc->filepath);
15742 $modulepart = array_shift($split_dir);
15743 $dir_ref = implode(
'/', $split_dir);
15746 $file = $dir_ref.
'/'.$doc->filename;
15747 $thumb = $dir_ref.
'/thumbs/'.substr($doc->filename, 0, strrpos($doc->filename,
'.')).
'_mini'.substr($doc->filename, strrpos($doc->filename,
'.'));
15748 $doclink =
dol_buildpath(
'document.php', 1).
'?modulepart='.$modulepart.
'&attachment=0&file='.urlencode($file).
'&entity='.
$conf->entity;
15749 $viewlink =
dol_buildpath(
'viewimage.php', 1).
'?modulepart='.$modulepart.
'&file='.urlencode($thumb).
'&entity='.
$conf->entity;
15753 $mimeAttr =
' mime="'.$mime.
'" ';
15755 if (in_array($mime, array(
'image/png',
'image/jpeg',
'application/pdf'))) {
15756 $class .=
' documentpreview';
15759 $footer .=
'<a href="'.$doclink.
'" class="btn-link '.$class.
'" target="_blank" rel="noopener noreferrer" '.$mimeAttr.
' >';
15760 $footer .=
img_mime($filePath).
' '.$doc->filename;
15763 $footer .=
'</span>';
15765 $footer .=
'</div>';
15768 if (!empty($footer)) {
15769 $out .=
'<div class="timeline-footer">'.$footer.
'</div>';
15772 $out .=
'</div>'.
"\n";
15775 $out .=
'<!-- END timeline item -->';
15782 jQuery(document).ready(function () {
15783 $(document).on("click", "[data-read-more-action]", function(e){
15784 console.log("We click on data-read-more-action");
15785 let readMoreBloc = $(this).closest(".readmore-block");
15786 if(readMoreBloc.length > 0){
15787 e.preventDefault();
15788 if($(this).attr("data-read-more-action") == "close"){
15789 readMoreBloc.addClass("--closed").removeClass("--open");
15790 $("html, body").animate({
15791 scrollTop: readMoreBloc.offset().top - 200
15794 readMoreBloc.addClass("--open").removeClass("--closed");
15802 if (empty($histo)) {
15803 $out .=
'<span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span>';
15826function buildParamDate($prefix, $timestamp =
null, $hourTime =
'', $gm =
'auto')
15828 if ($timestamp ===
null) {
15829 $timestamp =
GETPOSTDATE($prefix, $hourTime, $gm);
15836 if ($hourTime ===
'getpost' || ($timestamp !==
null &&
dol_print_date($timestamp,
'%H:%M:%S') !==
'00:00:00')) {
15837 $TParam = array_merge($TParam, array(
15844 return '&' . http_build_query($TParam);
15865function recordNotFound($message =
'', $printheader = 1, $printfooter = 1, $showonlymessage = 0, $params =
null)
15867 global
$conf, $db, $langs, $hookmanager;
15870 if (!is_object($langs)) {
15871 include_once DOL_DOCUMENT_ROOT.
'/core/class/translate.class.php';
15873 $langs->setDefaultLang();
15876 $langs->load(
"errors");
15878 if ($printheader) {
15879 if (function_exists(
"llxHeader")) {
15881 } elseif (function_exists(
"llxHeaderVierge")) {
15886 print
'<div class="error">';
15887 if (empty($message)) {
15888 print $langs->trans(
"ErrorRecordNotFound");
15890 print $langs->trans($message);
15895 if (empty($showonlymessage)) {
15896 if (empty($hookmanager)) {
15897 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
15900 $hookmanager->initHooks(array(
'main'));
15903 $parameters = array(
'message' => $message,
'params' => $params);
15904 $reshook = $hookmanager->executeHooks(
'getErrorRecordNotFound', $parameters,
$object, $action);
15905 print $hookmanager->resPrint;
15908 if ($printfooter && function_exists(
"llxFooter")) {
15910 if (is_object($db)) {
$id
Support class for third parties, contacts, members, users or resources.
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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=[])
Header function.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
ajax_object_onoff($object, $code, $field, $text_on, $text_off, $input=array(), $morecss='', $htmlname='', $forcenojs=0, $moreparam='')
On/off button to change a property status of an object This uses the ajax service objectonoff....
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.
Class to manage agenda events (actions)
Class to manage different types of events.
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...)
Class to manage translations.
Class to manage Dolibarr users.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
dol_get_prev_month($month, $year)
Return previous month.
dol_get_next_day($day, $month, $year)
Return next day.
getServerTimeZoneInt($refgmtdate='now')
Return server timezone int.
dol_get_prev_day($day, $month, $year)
Return previous day.
dol_get_next_month($month, $year)
Return next month.
dol_convert_file($fileinput, $ext='png', $fileoutput='', $page='')
Convert an image file or a PDF into another image format.
dragAndDropFileUpload($htmlname)
Function to manage the drag and drop of a file.
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.
dolGetElementUrl($objectid, $objecttype, $withpicto=0, $option='')
Return link url to an object.
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_fiche_end($notab=0)
Show tab footer of a card.
verifCond($strToEvaluate, $onlysimplestring='1')
Verify if condition in string is ok or not.
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.
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...
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 ...
img_weather($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $morecss='')
Show weather picto.
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.
show_actions_messaging($conf, $langs, $db, $filterobj, $objcon=null, $noprint=0, $actioncode='', $donetodo='done', $filters=array(), $sortfield='a.datep, a.id', $sortorder='DESC')
Show html area with actions in messaging format.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
getLanguageCodeFromCountryCode($countrycode)
Return default language from country code.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
dol_ucfirst($string, $encoding="UTF-8")
Convert first character of the first word of a string to upper.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
img_right($titlealt='default', $selected=0, $moreatt='')
Show right arrow logo.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
dol_strtolower($string, $encoding="UTF-8")
Convert a string to lower.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
dol_htmlentitiesbr_decode($stringtodecode, $pagecodeto='UTF-8')
This function is called to decode a HTML string (it decodes entities and br tags)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_left($titlealt='default', $selected=0, $moreatt='')
Show left arrow logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dolPrintHTML($s, $allowiframe=0)
Return a string (that can be on several lines) ready to be output on a HTML page.
isASecretKey($keyname)
Return if string has a name dedicated to store a secret.
dolPrintHTMLForTextArea($s, $allowiframe=0)
Return a string ready to be output on input textarea.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
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.
get_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Get formatted error messages to output (Used to show messages on html output).
dol_user_country()
Return country code for current user.
dol_string_onlythesehtmlattributes($stringtoclean, $allowed_attributes=null)
Clean a string from some undesirable HTML tags.
getMultidirTemp($object, $module='', $forobject=0)
Return the full path of the directory where a module (or an object of a module) stores its temporary ...
isHTTPS()
Return if we are using a HTTPS connection Check HTTPS (no way to be modified by user but may be empty...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
img_action($titlealt, $numaction, $picto='', $moreatt='')
Show logo action.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_print_url($url, $target='_blank', $max=32, $withpicto=0, $morecss='')
Show Url link.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
printCommonFooter($zone='private')
Print common footer : conf->global->MAIN_HTML_FOOTER js for switch of menu hider js for conf->global-...
checkVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
img_down($titlealt='default', $selected=0, $moreclass='')
Show down arrow logo.
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.
dolPrintText($s)
Return a string label (possible on several lines and that should not contains any HTML) ready to be o...
utf8_valid($str)
Check if a string is in UTF8.
getPictoForType($key, $morecss='')
Return the picto for a data type.
getDolUserString($key, $default='', $tmpuser=null)
Return Dolibarr user constant string value.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
img_allow($allow, $titlealt='default')
Show tick logo if allowed.
isValidMXRecord($domain)
Return if the domain name has a valid MX record.
dolButtonToOpenExportDialog($name, $label, $buttonstring, $exportSiteName, $overwriteGitUrl, $website)
Create a dialog with two buttons for export and overwrite of a website.
GETPOSTISARRAY($paramname, $method=0)
Return true if the parameter $paramname is submit from a POST OR GET as an array.
dol_print_socialnetworks($value, $contactid, $socid, $type, $dictsocialnetworks=array())
Show social network link.
getImgPictoNameList()
Get all usage icon key usable for img_picto(..., key)
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tab header of a card.
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
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.
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.
ajax_autoselect($htmlname, $addlink='', $textonlink='Link')
Make content of an input box selected when we click into input field.
img_view($titlealt='default', $float=0, $other='class="valignmiddle"')
Show logo view card.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_get_object_properties($obj, $properties=[])
Get 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.
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag)
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
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.
dol_strftime($fmt, $ts=false, $is_gmt=false)
Format a string.
img_picto_common($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $notitle=0)
Show picto (generic function)
img_search($titlealt='default', $other='')
Show search logo.
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.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
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.
dolPrintHTMLForAttribute($s, $escapeonlyhtmltags=0, $allowothertags=array())
Return a string ready to be output into an HTML attribute (alt, title, data-html, ....
fieldLabel($langkey, $fieldkey, $fieldrequired=0)
Show a string with the label tag dedicated to the HTML edit field.
getBrowserInfo($user_agent)
Return information about user browser.
dolGetFirstLetters($s, $nbofchar=1)
Return first letters of a strings.
dol_eval_standard($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
dolPrintLabel($s, $escapeonlyhtmltags=0)
Return a string label (so on 1 line only and that should not contains any HTML) ready to be output on...
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 ...
dol_sanitizeUrl($stringtoclean, $type=1)
Clean a string to use it as an URL (into a href or src attribute)
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
img_printer($titlealt="default", $other='')
Show printer logo.
dol_htmloutput_events($disabledoutputofmessages=0)
Print formatted messages to output (Used to show messages on html output).
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
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...
getImgPictoConv($mode='fa')
Get array to convert the Dolibarr picto keys into font awesome keys.
print_date_range($date_start, $date_end, $format='', $outputlangs=null)
Format output for start and end date.
getArrayOfSocialNetworks()
Get array of social network dictionary.
num2Alpha($n)
Return a numeric value into an Excel like column number.
dol_size($size, $type='')
Optimize a size for some browsers (phone, smarphone...)
img_split($titlealt='default', $other='class="pictosplit"')
Show split logo.
img_pdf($titlealt='default', $size=3)
Show pdf logo.
dolGetCountryCodeFromIp($ip)
Return a country code from IP.
dol_textishtml($msg, $option=0)
Return if a text is a html content.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dolPrintPassword($s)
Return a string ready to be output on an HTML attribute (alt, title, ...)
dol_escape_all($stringtoescape)
Returns text escaped for all protocols (so only alpha chars and numbers)
GETPOSTFLOAT($paramname, $rounding='')
Return the value of a $_GET or $_POST supervariable, converted into float.
dolForgeSQLCriteriaCallback($matches)
Function to forge a SQL criteria from a USF (Universal Filter Syntax) string.
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')) 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.
dol_shutdown()
Function called at end of web php process.
dol_print_address($address, $htmlid, $element, $id, $noprint=0, $charfornl='')
Format address string.
dol_print_error_email($prefixcode, $errormessage='', $errormessages=array(), $morecss='error', $email='')
Show a public email and error code to contact if technical error.
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.
print_titre($title)
Show a title.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_string_nounprintableascii($str, $removetabcrlf=1)
Clean a string from all non printable ASCII chars (0x00-0x1F and 0x7F).
getDolGlobalBool($key, $default=false)
Return a Dolibarr global constant boolean value.
img_error($titlealt='default')
Show error logo.
getTimelineIcon($actionstatic, &$histo, $key)
Get timeline icon.
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formatted messages to output (Used to show messages on html output).
dol_clone($object, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
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,...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_next($titlealt='default', $moreatt='')
Show next logo.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
dol_string_is_good_iso($s, $clean=0)
Check if a string is a correct iso string If not, it will not be considered as HTML encoded even if i...
getNonce()
Return a random string to be used as a nonce value for js.
isStringVarMatching($var, $regextext, $matchrule=1)
Check if a variable with name $var startx with $text.
dolSlugify($stringtoslugify)
Returns text slugified (lowercase and no special char, separator is "-").
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).
get_htmloutput_mesg($mesgstring='', $mesgarray=[], $style='ok', $keepembedded=0)
Get formatted messages to output (Used to show messages on html output).
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...
get_product_localtax_for_country($idprod, $local, $thirdpartytouse)
Return localtax vat rate of a product in a particular country or default country vat if product is un...
print_fleche_navigation($page, $file, $options='', $nextpage=0, $betweenarrows='', $afterarrows='', $limit=-1, $totalnboflines=0, $selectlimitsuffix='', $beforearrows='', $hidenavigation=0)
Function to show navigation arrows into lists.
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.
jsonOrUnserialize($stringtodecode)
Decode an encode string.
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.
img_edit_add($titlealt='default', $other='')
Show logo +.
print_fiche_titre($title, $mesg='', $picto='generic', $pictoisfullpath=0, $id='')
Show a title with picto.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
get_product_vat_for_country($idprod, $thirdpartytouse, $idprodfournprice=0)
Return vat rate of a product in a particular country, or default country vat if product is unknown.
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.
img_credit_card($brand, $morecss=null)
Return image of a credit card according to its brand name.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
img_searchclear($titlealt='default', $other='')
Show search logo.
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.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
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...
img_up($titlealt='default', $selected=0, $moreclass='')
Show top arrow logo.
dol_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Print formatted error messages to output (Used to show messages on html output).
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
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_sanitizePathName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a path name.
dolPrintHTMLForAttributeUrl($s)
Return a string ready to be output on a href attribute (this one need a special because we need conte...
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)
img_edit_remove($titlealt='default', $other='')
Show logo -.
img_info($titlealt='default')
Show info logo.
getDoliDBInstance($type, $host, $user, $pass, $name, $port)
Return a DoliDB instance (database handler).
dol_sanitizeEmail($stringtoclean)
Clean a string to use it as an Email.
dol_nboflines_bis($text, $maxlinesize=0, $charset='UTF-8')
Return nb of lines of a formatted text with and (WARNING: string must not have mixed and br sep...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
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.
treeview li table
No Email.
ui state ui widget content ui state ui widget header ui state a ui button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
div refaddress div address
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
$conf db name
Only used if Module[ID]Name translation string is not found.
realCharForNumericEntities($matches)
Return the real char for a numeric entities.