55if (!function_exists(
'utf8_encode')) {
63 function utf8_encode($elements)
65 return mb_convert_encoding($elements,
'UTF-8',
'ISO-8859-1');
69if (!function_exists(
'utf8_decode')) {
77 function utf8_decode($elements)
79 return mb_convert_encoding($elements,
'ISO-8859-1',
'UTF-8');
82if (!function_exists(
'str_starts_with')) {
91 function str_starts_with($haystack, $needle)
93 return (
string) $needle !==
'' && strncmp($haystack, $needle, strlen($needle)) === 0;
96if (!function_exists(
'str_ends_with')) {
105 function str_ends_with($haystack, $needle)
107 return $needle !==
'' && substr($haystack, -strlen($needle)) === (string) $needle;
110if (!function_exists(
'str_contains')) {
119 function str_contains($haystack, $needle)
121 return $needle !==
'' && mb_strpos($haystack, $needle) !==
false;
142 if (!is_object(
$object) && empty($module)) {
145 if (empty($module) && !empty(
$object->element)) {
152 $module =
'ficheinter';
154 case 'invoice_supplier':
155 $module =
'supplier_invoice';
157 case 'order_supplier':
158 $module =
'supplier_order';
160 case 'recruitmentjobposition':
161 $module =
'recruitment';
162 $subdirectory =
'/recruitmentjobposition';
164 case 'recruitmentcandidature':
165 $module =
'recruitment';
166 $subdirectory =
'/recruitmentcandidature';
168 case 'knowledgerecord':
169 $module =
'knowledgemanagement';
170 $subdirectory =
'/knowledgerecord';
186 if ($mode ==
'output' || $mode ==
'outputrel' || $mode ==
'version') {
187 if (isset($conf->$module) && property_exists($conf->$module,
'multidir_output')) {
189 if ($mode !=
'outputrel') {
190 $s = $conf->$module->multidir_output[(empty(
$object->entity) ? $conf->entity :
$object->entity)] . $subdirectory;
192 if ($forobject &&
$object->id > 0) {
196 } elseif (isset($conf->$module) && property_exists($conf->$module,
'dir_output')) {
198 if ($mode !=
'outputrel') {
199 $s = $conf->$module->dir_output . $subdirectory;
201 if ($forobject &&
$object->id > 0) {
206 return 'error-diroutput-not-defined-for-this-object=' . $module;
208 } elseif ($mode ==
'temp') {
209 if (isset($conf->$module) && property_exists($conf->$module,
'multidir_temp')) {
210 return $conf->$module->multidir_temp[(empty(
$object->entity) ? $conf->entity :
$object->entity)];
211 } elseif (isset($conf->$module) && property_exists($conf->$module,
'dir_temp')) {
212 return $conf->$module->dir_temp;
214 return 'error-dirtemp-not-defined-for-this-object=' . $module;
217 return 'error-bad-value-for-mode';
261 return (
string) (isset($conf->global->$key) ? $conf->global->$key : $default);
276 return (
int) (isset($conf->global->$key) ? $conf->global->$key : $default);
291 return (
float) (isset($conf->global->$key) ? $conf->global->$key : $default);
305 return (
bool) ($conf->global->$key ?? $default);
316 return (
string) $conf->currency;
327 return (
string) $conf->dol_optimize_smallscreen;
338 return (
int) $conf->entity;
349 return $conf->db->type;
360 return str_replace(
'_',
'', basename(dirname($s)).basename($s,
'.php'));
374 if (empty($tmpuser)) {
379 return (
string) (isset($tmpuser->conf->$key) ? $tmpuser->conf->$key : $default);
392 if (empty($tmpuser)) {
397 return (
int) (isset($tmpuser->conf->$key) ? $tmpuser->conf->$key : $default);
414 'adherent' =>
'member',
415 'member_type' =>
'adherent_type',
417 'contrat' =>
'contract',
418 'entrepot' =>
'stock',
419 'projet' =>
'project',
420 'categorie' =>
'category',
421 'commande' =>
'order',
422 'expedition' =>
'shipping',
423 'facture' =>
'invoice',
424 'fichinter' =>
'intervention',
425 'ficheinter' =>
'intervention',
426 'propale' =>
'propal',
427 'socpeople' =>
'contact',
428 'fournisseur' =>
'supplier',
430 'actioncomm' =>
'agenda',
431 'product_price' =>
'productprice',
432 'product_fournisseur_price' =>
'productsupplierprice',
452 $arrayconv[
'supplier_order'] =
'fournisseur';
453 $arrayconv[
'supplier_invoice'] =
'fournisseur';
456 $module_alt = $module;
457 if (!empty($arrayconv[$module])) {
458 $module_alt = $arrayconv[$module];
460 $module_bis = $module;
461 if (!empty($arrayconvbis[$module])) {
462 $module_bis = $arrayconvbis[$module];
465 return !empty($conf->modules[$module]) || !empty($conf->modules[$module_alt]) || !empty($conf->modules[$module_bis]);
483 $moduletomoduletouse = array(
484 'invoice' =>
'facture',
486 $moduleParmsMapping = array(
487 'product' =>
'produit',
490 if (!empty($moduletomoduletouse[$module])) {
491 $module = $moduletomoduletouse[$module];
494 $warningDelayPath = $parmlevel1;
495 if (!empty($moduleParmsMapping[$warningDelayPath])) {
496 $warningDelayPath = $moduleParmsMapping[$warningDelayPath];
500 if (!empty($conf->$module) && !empty($conf->$module->$warningDelayPath) && !empty($conf->$module->$warningDelayPath->$parmlevel2) && !empty($conf->$module->$warningDelayPath->$parmlevel2->warning_delay)) {
501 return (
int) $conf->$module->$warningDelayPath->$parmlevel2->warning_delay;
504 if (!empty($conf->$module) && !empty($conf->$module->$warningDelayPath) && !empty($conf->$module->$warningDelayPath->warning_delay)) {
505 return (
int) $conf->$module->$warningDelayPath->warning_delay;
520 if ($timestamp ===
'') {
521 dol_syslog(
'Using empty string for a timestamp is deprecated, prefer use of null when calling page ' . $_SERVER[
"PHP_SELF"] .
getCallerInfoString(), LOG_NOTICE);
524 if (is_null($timestamp) || !is_numeric($timestamp)) {
544 require_once DOL_DOCUMENT_ROOT .
"/core/db/" . $type .
'.class.php';
546 $class =
'DoliDB' . ucfirst($type);
547 $db =
new $class($type, $host, $user, $pass, $name, $port);
568function getEntity($element, $shared = 1, $currentobject =
null)
570 global $conf, $mc, $hookmanager,
$object, $action, $db;
572 if (!is_object($hookmanager)) {
573 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
580 $element =
'project';
583 $element =
'contract';
585 case 'order_supplier':
586 $element =
'supplier_order';
588 case 'invoice_supplier':
589 $element =
'supplier_invoice';
593 if (is_object($mc)) {
594 $out = $mc->getEntity($element, $shared, $currentobject);
597 $addzero = array(
'user',
'usergroup',
'cronjob',
'c_email_templates',
'email_template',
'default_values',
'overwrite_trans');
599 $addzero[] =
'c_holiday_types';
601 if (in_array($element, $addzero)) {
604 $out .= ((int) $conf->entity);
609 'element' => $element,
612 'currentobject' => $currentobject,
616 $reshook = $hookmanager->executeHooks(
'hookGetEntity', $parameters, $currentobject, $action);
618 if (is_numeric($reshook)) {
619 if ($reshook == 0 && !empty($hookmanager->resPrint)) {
620 $out .=
',' . $hookmanager->resPrint;
621 } elseif ($reshook == 1) {
622 $out = $hookmanager->resPrint;
639 if (is_object($mc) && method_exists($mc,
'setEntity')) {
640 return $mc->setEntity($currentobject);
642 return ((is_object($currentobject) && $currentobject->id > 0 && ((
int) $currentobject->entity) > 0) ? (
int) $currentobject->entity : $conf->entity);
654 return preg_match(
'/(_pass|password|_pw|_key|securekey|serverkey|secret\d?|p12key|exportkey|_PW_[a-z]+|token)$/i', $keyname);
667 for ($r =
""; $n >= 0; $n = intval($n / 26) - 1) {
668 $r = chr($n % 26 + 0x41) . $r;
692 include_once DOL_DOCUMENT_ROOT .
'/includes/mobiledetect/mobiledetectlib/Mobile_Detect.php';
699 $user_agent = substr($user_agent, 0, 512);
702 $detectmobile =
new Mobile_Detect(
null, $user_agent);
703 $tablet = $detectmobile->isTablet();
705 if ($detectmobile->isMobile()) {
709 if ($detectmobile->is(
'AndroidOS')) {
710 $os = $phone =
'android';
711 } elseif ($detectmobile->is(
'BlackBerryOS')) {
712 $os = $phone =
'blackberry';
713 } elseif ($detectmobile->is(
'iOS')) {
716 } elseif ($detectmobile->is(
'PalmOS')) {
717 $os = $phone =
'palm';
718 } elseif ($detectmobile->is(
'SymbianOS')) {
720 } elseif ($detectmobile->is(
'webOS')) {
722 } elseif ($detectmobile->is(
'MaemoOS')) {
724 } elseif ($detectmobile->is(
'WindowsMobileOS') || $detectmobile->is(
'WindowsPhoneOS')) {
730 if (preg_match(
'/linux/i', $user_agent)) {
732 } elseif (preg_match(
'/macintosh/i', $user_agent)) {
734 } elseif (preg_match(
'/windows/i', $user_agent)) {
740 if (preg_match(
'/firefox(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
742 $version = empty($reg[2]) ?
'' : $reg[2];
743 } elseif (preg_match(
'/edge(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
745 $version = empty($reg[2]) ?
'' : $reg[2];
746 } elseif (preg_match(
'/chrome(\/|\s)([\d\.]+)/i', $user_agent, $reg)) {
748 $version = empty($reg[2]) ?
'' : $reg[2];
749 } elseif (preg_match(
'/chrome/i', $user_agent, $reg)) {
752 } elseif (preg_match(
'/iceweasel/i', $user_agent)) {
754 } elseif (preg_match(
'/epiphany/i', $user_agent)) {
756 } elseif (preg_match(
'/safari(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
758 $version = empty($reg[2]) ?
'' : $reg[2];
759 } elseif (preg_match(
'/opera(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
762 $version = empty($reg[2]) ?
'' : $reg[2];
763 } elseif (preg_match(
'/(MSIE\s([0-9]+\.[0-9]))|.*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) {
765 $version = end($reg);
766 } elseif (preg_match(
'/(Windows NT\s([0-9]+\.[0-9])).*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) {
769 $version = end($reg);
770 } elseif (preg_match(
'/l[iy]n(x|ks)(\(|\/|\s)*([\d\.]+)/i', $user_agent, $reg)) {
772 $name =
'textbrowser';
773 $version = empty($reg[3]) ?
'' : $reg[3];
774 } elseif (preg_match(
'/w3m\/([\d\.]+)/i', $user_agent, $reg)) {
776 $name =
'textbrowser';
777 $version = empty($reg[1]) ?
'' : $reg[1];
789 'browsername' => $name,
790 'browserversion' => $version,
792 'browserua' => $user_agent,
807 $disconnectdone =
false;
809 if (is_object($db) && !empty($db->connected)) {
810 $depth = $db->transaction_opened;
811 $disconnectdone = $db->close();
813 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));
825function GETPOSTISSET($paramname)
829 $relativepathstring = $_SERVER[
"PHP_SELF"];
831 if (constant(
'DOL_URL_ROOT')) {
832 $relativepathstring = preg_replace(
'/^' . preg_quote(constant(
'DOL_URL_ROOT'),
'/') .
'/',
'', $relativepathstring);
834 $relativepathstring = ltrim($relativepathstring,
'/');
835 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
839 if (!empty($_GET[
'restore_lastsearch_values'])) {
840 if (!empty($_SESSION[
'lastsearch_values_' . $relativepathstring])) {
841 $tmp = json_decode($_SESSION[
'lastsearch_values_' . $relativepathstring],
true);
842 if (is_array($tmp)) {
843 foreach ($tmp as $key => $val) {
844 if ($key == $paramname) {
852 if ($paramname ==
'contextpage' && !empty($_SESSION[
'lastsearch_contextpage_' . $relativepathstring])) {
854 } elseif ($paramname ==
'limit' && !empty($_SESSION[
'lastsearch_limit_' . $relativepathstring])) {
856 } elseif ($paramname ==
'page' && !empty($_SESSION[
'lastsearch_page_' . $relativepathstring])) {
858 } elseif ($paramname ==
'mode' && !empty($_SESSION[
'lastsearch_mode_' . $relativepathstring])) {
862 $isset = (isset($_POST[$paramname]) || isset($_GET[$paramname]));
879 if (empty($method)) {
880 $val = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] :
'');
881 } elseif ($method == 1) {
882 $val = isset($_GET[$paramname]) ? $_GET[$paramname] :
'';
883 } elseif ($method == 2) {
884 $val = isset($_POST[$paramname]) ? $_POST[$paramname] :
'';
885 } elseif ($method == 3) {
886 $val = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] :
'');
888 $val =
'BadFirstParameterForGETPOST';
891 return is_array($val);
906 return (
int)
GETPOST($paramname,
'int', $method,
null,
null, 0);
922function GETPOSTFLOAT($paramname, $rounding =
'', $option = 2)
943function GETPOSTDATE($prefix, $hourTime =
'', $gm =
'auto', $saverestore =
'')
946 if ($hourTime ===
'getpost' || $hourTime ===
'getpostend') {
947 $hour = (GETPOSTISSET($prefix .
'hour') &&
GETPOSTINT($prefix .
'hour') >= 0) ?
GETPOSTINT($prefix .
'hour') : ($hourTime ===
'getpostend' ? 23 : 0);
948 $minute = (GETPOSTISSET($prefix .
'min') &&
GETPOSTINT($prefix .
'min') >= 0) ?
GETPOSTINT($prefix .
'min') : ($hourTime ===
'getpostend' ? 59 : 0);
949 $second = (GETPOSTISSET($prefix .
'sec') &&
GETPOSTINT($prefix .
'sec') >= 0) ?
GETPOSTINT($prefix .
'sec') : ($hourTime ===
'getpostend' ? 59 : 0);
950 } elseif (preg_match(
'/^(\d\d):(\d\d):(\d\d)$/', $hourTime, $m)) {
951 $hour = intval($m[1]);
952 $minute = intval($m[2]);
953 $second = intval($m[3]);
954 } elseif ($hourTime ===
'end') {
959 $hour = $minute = $second = 0;
964 && !GETPOSTISSET($prefix .
'day')
965 && !GETPOSTISSET($prefix .
'month')
966 && !GETPOSTISSET($prefix .
'year')
967 && isset($_SESSION[
'DOLDATE_' . $saverestore .
'_day'])
968 && isset($_SESSION[
'DOLDATE_' . $saverestore .
'_month'])
969 && isset($_SESSION[
'DOLDATE_' . $saverestore .
'_year'])
971 $day = $_SESSION[
'DOLDATE_' . $saverestore .
'_day'];
972 $month = $_SESSION[
'DOLDATE_' . $saverestore .
'_month'];
973 $year = $_SESSION[
'DOLDATE_' . $saverestore .
'_year'];
981 $hour = (int) min($hour, 23);
982 $minute = (int) min($minute, 59);
983 $second = (int) min($second, 59);
986 $_SESSION[
'DOLDATE_' . $saverestore .
'_day'] = $day;
987 $_SESSION[
'DOLDATE_' . $saverestore .
'_month'] = $month;
988 $_SESSION[
'DOLDATE_' . $saverestore .
'_year'] = $year;
992 return dol_mktime($hour, $minute, $second, $month, $day, $year, $gm);
1035function GETPOST($paramname, $check =
'alphanohtml', $method = 0, $filter =
null, $options =
null, $noreplace = 0)
1037 global
$mysoc, $user, $conf;
1039 if (empty($paramname)) {
1040 return 'BadFirstParameterForGETPOST';
1042 if (empty($check)) {
1043 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);
1048 if (empty($method)) {
1049 $out = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] :
'');
1050 } elseif ($method == 1) {
1051 $out = isset($_GET[$paramname]) ? $_GET[$paramname] :
'';
1052 } elseif ($method == 2) {
1053 $out = isset($_POST[$paramname]) ? $_POST[$paramname] :
'';
1054 } elseif ($method == 3) {
1055 $out = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] :
'');
1057 return 'BadThirdParameterForGETPOST';
1060 $relativepathstring =
'';
1062 if (empty($method) || $method == 3 || $method == 4) {
1063 $relativepathstring = (empty($_SERVER[
"PHP_SELF"]) ?
'' : $_SERVER[
"PHP_SELF"]);
1065 if (constant(
'DOL_URL_ROOT')) {
1066 $relativepathstring = preg_replace(
'/^' . preg_quote(constant(
'DOL_URL_ROOT'),
'/') .
'/',
'', $relativepathstring);
1068 $relativepathstring = ltrim($relativepathstring,
'/');
1069 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
1073 if (!empty($_GET[
'restore_lastsearch_values'])) {
1074 if (!empty($_SESSION[
'lastsearch_values_' . $relativepathstring])) {
1075 $tmp = json_decode($_SESSION[
'lastsearch_values_' . $relativepathstring],
true);
1076 if (is_array($tmp)) {
1077 foreach ($tmp as $key => $val) {
1078 if ($key == $paramname) {
1086 if ($paramname ==
'contextpage' && !empty($_SESSION[
'lastsearch_contextpage_' . $relativepathstring])) {
1087 $out = $_SESSION[
'lastsearch_contextpage_' . $relativepathstring];
1088 } elseif ($paramname ==
'limit' && !empty($_SESSION[
'lastsearch_limit_' . $relativepathstring])) {
1089 $out = $_SESSION[
'lastsearch_limit_' . $relativepathstring];
1090 } elseif ($paramname ==
'page' && !empty($_SESSION[
'lastsearch_page_' . $relativepathstring])) {
1091 $out = $_SESSION[
'lastsearch_page_' . $relativepathstring];
1092 } elseif ($paramname ==
'mode' && !empty($_SESSION[
'lastsearch_mode_' . $relativepathstring])) {
1093 $out = $_SESSION[
'lastsearch_mode_' . $relativepathstring];
1095 } elseif (!isset($_GET[
'sortfield'])) {
1098 if (!empty($_GET[
'action']) && $_GET[
'action'] ==
'create' && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
1101 '@phan-var-force CommonObject $object';
1102 if (is_object(
$object) && isset(
$object->fields[$paramname][
'default'])) {
1104 $out =
$object->fields[$paramname][
'default'];
1108 if (!empty($_GET[
'action']) && (preg_match(
'/^create/', $_GET[
'action']) || preg_match(
'/^presend/', $_GET[
'action'])) && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
1110 if (!empty($user->default_values)) {
1111 if (isset($user->default_values[$relativepathstring][
'createform'])) {
1112 foreach ($user->default_values[$relativepathstring][
'createform'] as $defkey => $defval) {
1114 if ($defkey !=
'_noquery_') {
1115 $tmpqueryarraytohave = explode(
'&', $defkey);
1118 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
1119 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
1131 if (isset($user->default_values[$relativepathstring][
'createform'][$defkey][$paramname])) {
1132 $out = $user->default_values[$relativepathstring][
'createform'][$defkey][$paramname];
1139 } elseif (!empty($paramname) && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
1141 if (!empty($user->default_values)) {
1144 if ($paramname ==
'sortfield' || $paramname ==
'sortorder') {
1146 if (isset($user->default_values[$relativepathstring][
'sortorder'])) {
1148 foreach ($user->default_values[$relativepathstring][
'sortorder'] as $defkey => $defval) {
1150 if ($defkey !=
'_noquery_') {
1151 $tmpqueryarraytohave = explode(
'&', $defkey);
1154 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
1155 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
1167 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
1168 foreach ($user->default_values[$relativepathstring][
'sortorder'][$defkey] as $key => $val) {
1172 if ($paramname ==
'sortfield') {
1175 if ($paramname ==
'sortorder') {
1183 } elseif (isset($user->default_values[$relativepathstring][
'filters'])) {
1184 foreach ($user->default_values[$relativepathstring][
'filters'] as $defkey => $defval) {
1185 if (!empty($_GET[
'disabledefaultvalues'])) {
1189 if ($defkey !=
'_noquery_') {
1190 $tmpqueryarraytohave = explode(
'&', $defkey);
1193 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
1194 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
1205 if ($qualified && isset($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname])) {
1207 if (isset($_POST[
'search_all']) || isset($_GET[
'search_all'])) {
1210 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
1211 $out =
dol_string_nospecial($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname],
'', $forbidden_chars_to_replace);
1214 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
1215 $out =
dol_string_nospecial($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname],
'', $forbidden_chars_to_replace);
1230 '@phan-var-force string $paramname';
1231 if (!is_array($out) && empty($_POST[$paramname]) && empty($noreplace)) {
1233 $regreplace = array();
1237 while (preg_match(
'/__([A-Z0-9]+(?:_[A-Z0-9]+){0,3})__/i', $out, $reg) && ($loopnb < $maxloop)) {
1241 if ($reg[1] ==
'DAY') {
1243 $newout = $tmp[
'mday'];
1244 } elseif ($reg[1] ==
'MONTH') {
1246 $newout = $tmp[
'mon'];
1247 } elseif ($reg[1] ==
'YEAR') {
1249 $newout = $tmp[
'year'];
1250 } elseif ($reg[1] ==
'PREVIOUS_DAY') {
1253 $newout = $tmp2[
'day'];
1254 } elseif ($reg[1] ==
'PREVIOUS_MONTH') {
1257 $newout = $tmp2[
'month'];
1258 } elseif ($reg[1] ==
'PREVIOUS_YEAR') {
1260 $newout = ($tmp[
'year'] - 1);
1261 } elseif ($reg[1] ==
'NEXT_DAY') {
1264 $newout = $tmp2[
'day'];
1265 } elseif ($reg[1] ==
'NEXT_MONTH') {
1268 $newout = $tmp2[
'month'];
1269 } elseif ($reg[1] ==
'NEXT_YEAR') {
1271 $newout = ($tmp[
'year'] + 1);
1272 } elseif ($reg[1] ==
'MYCOMPANY_COUNTRY_ID' || $reg[1] ==
'MYCOUNTRY_ID' || $reg[1] ==
'MYCOUNTRYID') {
1273 $newout =
$mysoc->country_id;
1274 } elseif ($reg[1] ==
'USER_ID' || $reg[1] ==
'USERID') {
1275 $newout = $user->id;
1276 } elseif ($reg[1] ==
'USER_SUPERVISOR_ID' || $reg[1] ==
'SUPERVISOR_ID' || $reg[1] ==
'SUPERVISORID') {
1277 $newout = $user->fk_user;
1278 } elseif ($reg[1] ==
'ENTITY_ID' || $reg[1] ==
'ENTITYID') {
1279 $newout = $conf->entity;
1280 } elseif ($reg[1] ==
'ID') {
1283 $newout =
'REGREPLACE_' . $loopnb;
1284 $regreplace[$loopnb] = $reg[0];
1287 $out = preg_replace(
'/__' . preg_quote($reg[1],
'/') .
'__/', $newout, $out);
1289 if (!empty($regreplace)) {
1290 foreach ($regreplace as $key => $value) {
1291 $out = preg_replace(
'/REGREPLACE_' . $key .
'/', $value, $out);
1297 if (preg_match(
'/^array/', $check)) {
1298 $tmpcheck =
'alphanohtml';
1301 } elseif (!is_array($out)) {
1302 $out = explode(
',', $out);
1304 $tmparray = explode(
':', $check);
1305 if (!empty($tmparray[1])) {
1306 $tmpcheck = $tmparray[1];
1309 foreach ($out as $outkey => $outval) {
1310 $out[$outkey] =
sanitizeVal($outval, $tmpcheck, $filter, $options);
1315 if (strpos($paramname,
'search_') === 0) {
1316 $out = preg_replace(
'/([<>])([-+]?\d)/',
'\1 \2', $out);
1320 $out =
sanitizeVal($out, $check, $filter, $options);
1327 if (preg_match(
'/^backto/i', $paramname)) {
1328 $out = str_replace(
'\\',
'/', $out);
1329 $out = str_replace(array(
':',
';',
'@',
"\t",
' '),
'', $out);
1331 $oldstringtoclean = $out;
1332 $out = str_ireplace(array(
'javascript',
'vbscript',
'&colon',
'&#'),
'', $out);
1333 $out = preg_replace(array(
'/^[^\?]*%/'),
'', $out);
1334 $out = preg_replace(array(
'/^[a-z]*\/\s*\/+/i'),
'', $out);
1335 }
while ($oldstringtoclean != $out);
1340 if (empty($method) || $method == 3 || $method == 4) {
1341 if (preg_match(
'/^search_/', $paramname) || in_array($paramname, array(
'sortorder',
'sortfield'))) {
1348 if ($out !=
'' && isset($user)) {
1349 $user->lastsearch_values_tmp[$relativepathstring][$paramname] = $out;
1366function sanitizeVal($out =
'', $check =
'alphanohtml', $filter =
null, $options =
null)
1370 if ($out ===
null) {
1378 if (!is_numeric($out)) {
1383 if (is_array($out)) {
1384 $out = implode(
',', $out);
1386 if (preg_match(
'/[^0-9,-]+/i', $out)) {
1391 dol_syslog(
"Use of parameter value 'san_alpha' in GETPOST is deprecated. Use 'alphanohtml', 'aZ09comma', ...", LOG_WARNING);
1392 $out = filter_var($out, FILTER_SANITIZE_STRING);
1395 $out = filter_var($out, FILTER_SANITIZE_EMAIL);
1399 $out = preg_replace(
'/[^:\/\[\]a-z0-9@\$\'\*\~\.\-_,;\?\!=%&+#]+/i',
'', $out);
1403 if (!is_array($out)) {
1405 if (preg_match(
'/[^a-z]+/i', $out)) {
1411 if (!is_array($out)) {
1413 if (preg_match(
'/[^a-z0-9_\-\.]+/i', $out)) {
1419 if (!is_array($out)) {
1421 if (preg_match(
'/[^a-z0-9_\-\.@]+/i', $out)) {
1427 if (!is_array($out)) {
1429 if (preg_match(
'/[^a-z0-9_\-\.,]+/i', $out)) {
1436 if (!is_array($out)) {
1439 $oldstringtoclean = $out;
1443 $out = preg_replace(
'/\\\([0-9xu])/',
'/\1', $out);
1450 $out = str_ireplace(array(
'../',
'..\\',
'&',
'&',
'&',
'"',
'"',
'"',
'"',
'"',
'/',
'/',
'/',
'\',
'\',
'\'),
'', $out);
1451 }
while ($oldstringtoclean != $out);
1455 case 'alphawithlgt':
1456 if (!is_array($out)) {
1459 $oldstringtoclean = $out;
1463 $out = preg_replace(
'/\\\([0-9xu])/',
'/\1', $out);
1470 $out = str_ireplace(array(
'../',
'..\\',
'&',
'&',
'&',
'"',
'"',
'"',
'"',
'"',
'/',
'/',
'/',
'\',
'\',
'\'),
'', $out);
1471 }
while ($oldstringtoclean != $out);
1477 case 'restricthtmlnolink':
1478 case 'restricthtml':
1479 case 'restricthtmlallowclass':
1480 case 'restricthtmlallowiframe':
1481 case 'restricthtmlallowlinkscript':
1482 case 'restricthtmlallowunvalid':
1487 if (empty($filter)) {
1488 return 'BadParameterForGETPOST - Param 3 of sanitizeVal()';
1490 if (is_null($options)) {
1493 $out = filter_var($out, $filter, $options);
1497 dol_syslog(
"Error, you call sanitizeVal() with a bad value for the check type. Data will be sanitized with alphanohtml.", LOG_ERR);
1498 $out =
GETPOST($out,
'alphanohtml');
1513function dolSetCookie(
string $cookiename,
string $cookievalue,
int $expire = -1)
1515 global $dolibarr_main_force_https;
1517 if ($expire == -1) {
1518 $expire = (time() + (86400 * 354));
1521 if (PHP_VERSION_ID < 70300) {
1522 setcookie($cookiename, empty($cookievalue) ?
'' : $cookievalue, empty($cookievalue) ? 0 : $expire,
'/',
'', !(empty($dolibarr_main_force_https) &&
isHTTPS() === false), true);
1525 $cookieparams = array(
1526 'expires' => empty($cookievalue) ? 0 : $expire,
1529 'secure' => !(empty($dolibarr_main_force_https) &&
isHTTPS() === false),
1533 setcookie($cookiename, empty($cookievalue) ?
'' : $cookievalue, $cookieparams);
1535 if (empty($cookievalue)) {
1536 unset($_COOKIE[$cookiename]);
1540if (!function_exists(
'dol_getprefix')) {
1551 function dol_getprefix($mode =
'')
1554 if ($mode ==
'email') {
1560 } elseif (isset($_SERVER[
"SERVER_NAME"])) {
1561 return $_SERVER[
"SERVER_NAME"];
1566 if (!empty($conf->file->instance_unique_id)) {
1567 return sha1(
'dolibarr' . $conf->file->instance_unique_id);
1571 return sha1(DOL_DOCUMENT_ROOT . DOL_URL_ROOT);
1575 global $dolibarr_main_instance_unique_id, $dolibarr_main_cookie_cryptkey;
1576 $tmp_instance_unique_id = empty($dolibarr_main_instance_unique_id) ? (empty($dolibarr_main_cookie_cryptkey) ?
'' : $dolibarr_main_cookie_cryptkey) : $dolibarr_main_instance_unique_id;
1579 if (!empty($tmp_instance_unique_id)) {
1580 return sha1(
'dolibarr' . $tmp_instance_unique_id);
1584 if (isset($_SERVER[
"SERVER_NAME"]) && isset($_SERVER[
"DOCUMENT_ROOT"])) {
1585 return sha1($_SERVER[
"SERVER_NAME"] . $_SERVER[
"DOCUMENT_ROOT"] . DOL_DOCUMENT_ROOT . DOL_URL_ROOT);
1587 return sha1(DOL_DOCUMENT_ROOT . DOL_URL_ROOT);
1604 global $conf, $langs, $user,
$mysoc;
1606 if (strpos($relpath,
'..') !==
false) {
1608 dol_syslog(
'functions::dol_include_once Tried to load a file with a path including a forbidden sequence ".." : ' . $relpath, LOG_WARNING);
1611 if (!preg_match(
'/\.php$/', $relpath)) {
1613 dol_syslog(
'functions::dol_include_once Tried to load a file that is not a PHP file : ' . $relpath, LOG_WARNING);
1619 if (!file_exists($fullpath)) {
1620 dol_syslog(
'functions::dol_include_once Tried to load unexisting file: ' . $relpath, LOG_WARNING);
1623 if (!empty($classname) && !class_exists($classname)) {
1624 return include $fullpath;
1626 return include_once $fullpath;
1644function dol_buildpath($path, $type = 0, $returnemptyifnotfound = 0)
1648 $path = preg_replace(
'/^\//',
'', $path);
1651 $res = DOL_DOCUMENT_ROOT .
'/' . $path;
1652 if (is_array($conf->file->dol_document_root)) {
1653 foreach ($conf->file->dol_document_root as $key => $dirroot) {
1654 if ($key ==
'main') {
1658 if (@file_exists($dirroot .
'/' . $path)) {
1659 if ($key !=
'main' && preg_match(
'/^core\//', $path)) {
1662 $res = $dirroot .
'/' . $path;
1667 if ($returnemptyifnotfound) {
1669 if ($returnemptyifnotfound == 1 || !file_exists($res)) {
1681 $res = DOL_URL_ROOT .
'/' . $path;
1684 $res = DOL_MAIN_URL_ROOT .
'/' . $path;
1687 $res = DOL_URL_ROOT .
'/' . $path;
1690 foreach ($conf->file->dol_document_root as $key => $dirroot) {
1691 if ($key ==
'main') {
1696 $urlwithouturlroot = preg_replace(
'/' . preg_quote(DOL_URL_ROOT,
'/') .
'$/i',
'', trim($conf->file->dol_main_url_root));
1697 $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT;
1700 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : $urlwithroot) .
'/' . $path;
1705 preg_match(
'/^([^\?]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i', $path, $regs);
1706 if (!empty($regs[1])) {
1709 if (@file_exists($dirroot .
'/' . $regs[1])) {
1711 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : DOL_URL_ROOT) . $conf->file->dol_url_root[$key] .
'/' . $path;
1712 } elseif ($type == 2) {
1713 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : DOL_MAIN_URL_ROOT) . $conf->file->dol_url_root[$key] .
'/' . $path;
1714 } elseif ($type == 3) {
1718 $urlwithouturlroot = preg_replace(
'/' . preg_quote(DOL_URL_ROOT,
'/') .
'$/i',
'', trim($conf->file->dol_main_url_root));
1719 $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT;
1722 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : $urlwithroot) . $conf->file->dol_url_root[$key] .
'/' . $path;
1741function dolBuildUrl($url, $params = [], $addtoken =
false)
1743 global $db, $hookmanager;
1745 if (!is_object($hookmanager)) {
1746 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
1749 if ((!isset($params[
'mainmenu']) || empty($params[
'mainmenu'])) && GETPOSTISSET(
'mainmenu')) {
1750 $params = array_merge($params, [
'mainmenu' => (
GETPOST(
'mainmenu',
'restricthtml'))]);
1752 if ((!isset($params[
'leftmenu'])) && GETPOSTISSET(
'leftmenu')) {
1753 $params = array_merge($params, [
'leftmenu' => (
GETPOST(
'leftmenu',
'restricthtml'))]);
1757 'params' => &$params,
1758 'addtoken' => &$addtoken,
1760 $hookmanager->executeHooks(
'buildurl', $parameters);
1762 $params = array_merge($params, [
'token' =>
newToken()]);
1766 $params = array_merge($params, [
'debug' =>
'debug']);
1769 $url .=
'?' . http_build_query($params);
1788 if (empty($properties)) {
1789 return get_object_vars($obj);
1792 $existingProperties = [];
1793 $realProperties = get_object_vars($obj);
1796 foreach ($properties as $property) {
1797 if (array_key_exists($property, $realProperties)) {
1799 $existingProperties[$property] = $obj->{$property};
1800 } elseif (property_exists($obj, $property)) {
1802 $existingProperties[$property] = $obj->{$property};
1806 return $existingProperties;
1825function dol_clone($srcobject, $native = 2)
1829 dol_syslog(
"Warning, call to dol_clone() with the deprecated parameter native=0, use 2 instead", LOG_WARNING);
1832 if (isset($srcobject->db) && isset($srcobject->db->db) && is_object($srcobject->db->db) && get_class($srcobject->db->db) ==
'PgSql\Connection') {
1833 $tmpsavdb = $srcobject->db;
1834 unset($srcobject->db);
1837 $myclone = unserialize(serialize($srcobject));
1839 if (!empty($tmpsavdb)) {
1840 $srcobject->db = $tmpsavdb;
1842 } elseif ($native == 2) {
1845 $tmparray = get_object_vars($srcobject);
1847 if (is_array($tmparray)) {
1848 foreach ($tmparray as $propertykey => $propertyval) {
1849 if (is_scalar($propertyval) || is_array($propertyval)) {
1850 $myclone->$propertykey = $propertyval;
1855 $myclone = clone $srcobject;
1872 if (is_object($srcobject)) {
1873 $srcobject = get_object_vars($srcobject);
1876 if (is_array($srcobject)) {
1878 foreach ($srcobject as $key => $value) {
1879 if (in_array($key, array(
'db',
'fields',
'error',
'errorhidden',
'errors',
'oldcopy',
'linkedObjects',
'linked_objects'))) {
1900function dol_size($size, $type =
'')
1903 if (empty($conf->dol_optimize_smallscreen)) {
1906 if ($type ==
'width' && $size > 250) {
1927function dol_sanitizeFileName($str, $newstr =
'_', $unaccent = 1, $includequotes = 0, $allowdash = 0)
1933 $filesystem_forbidden_chars = array(
'<',
'>',
'/',
'\\',
'?',
'*',
'|',
'"',
':',
'°',
'$',
';',
'`');
1934 if ($includequotes) {
1935 $filesystem_forbidden_chars[] =
"'";
1938 $tmp = preg_replace(
'/\-\-+/',
'_', $tmp);
1939 if (empty($allowdash)) {
1940 $tmp = preg_replace(
'/\s+\-([^\s])/',
' _$1', $tmp);
1941 $tmp = preg_replace(
'/\s+\-$/',
'', $tmp);
1943 $tmp = str_replace(
'..',
'', $tmp);
1944 $tmp = str_replace(
'~', $newstr, $tmp);
1945 $tmp = preg_replace(
'/\s{2,}/',
' ', $tmp);
1972 $filesystem_forbidden_chars = array(
'<',
'>',
'?',
'*',
'|',
'"',
'°',
'$',
';',
'`');
1979 $tmp = preg_replace(
'/\-\-+/', $newstr, $tmp);
1980 if (empty($allowdash)) {
1981 $tmp = preg_replace(
'/\s+\-([^\s])/',
' '.$newstr.
'$1', $tmp);
1982 $tmp = preg_replace(
'/\s+\-$/',
'', $tmp);
1984 $tmp = str_replace(
'..', $newstr, $tmp);
1985 $tmp = str_replace(
'~', $newstr, $tmp);
1986 $tmp = preg_replace(
'/\s{2,}/',
' ', $tmp);
2002 $stringtoclean = preg_replace(
'/[\x00-\x1F\x7F]/u',
'', $stringtoclean);
2004 $stringtoclean = preg_replace(
'/<!--[^>]*-->/',
'', $stringtoclean);
2006 $stringtoclean = str_replace(
'\\',
'/', $stringtoclean);
2010 $stringtoclean = str_replace(array(
':',
';',
'@'),
'', $stringtoclean);
2014 $oldstringtoclean = $stringtoclean;
2017 $stringtoclean = str_ireplace(array(
'javascript',
'vbscript',
'&colon',
'&#'),
'', $stringtoclean);
2018 }
while ($oldstringtoclean != $stringtoclean);
2022 $stringtoclean = preg_replace(array(
'/^[a-z]*\/\/+/i'),
'', $stringtoclean);
2025 return $stringtoclean;
2037 $oldstringtoclean = $stringtoclean;
2038 $stringtoclean = str_ireplace(array(
'"',
':',
'[',
']',
"\n",
"\r",
'\\',
'\/'),
'', $stringtoclean);
2039 }
while ($oldstringtoclean != $stringtoclean);
2041 return $stringtoclean;
2054 return preg_replace(
'/[^\w]+/',
'', $str);
2068 if (is_null($str)) {
2073 if (extension_loaded(
'intl') &&
getDolGlobalString(
'MAIN_UNACCENT_USE_TRANSLITERATOR')) {
2074 $transliterator = Transliterator::createFromRules(
':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: NFC;', Transliterator::FORWARD);
2075 return $transliterator->transliterate($str);
2078 $string = rawurlencode($str);
2079 $replacements = array(
2156 $string = strtr($string, $replacements);
2157 return rawurldecode($string);
2162 "\xC0\xC1\xC2\xC3\xC4\xC5\xC7
2163 \xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1
2164 \xD2\xD3\xD4\xD5\xD8\xD9\xDA\xDB\xDD
2165 \xE0\xE1\xE2\xE3\xE4\xE5\xE7\xE8\xE9\xEA\xEB
2166 \xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF8
2167 \xF9\xFA\xFB\xFC\xFD\xFF",
2175 $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"));
2193function dol_string_nospecial($str, $newstr =
'_', $badcharstoreplace =
'', $badcharstoremove =
'', $keepspaces = 0)
2195 $forbidden_chars_to_replace = array(
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
",",
";",
"=",
'°',
'$',
';');
2196 if (empty($keepspaces)) {
2197 $forbidden_chars_to_replace[] =
" ";
2199 $forbidden_chars_to_remove = array();
2202 if (is_array($badcharstoreplace)) {
2203 $forbidden_chars_to_replace = $badcharstoreplace;
2205 if (is_array($badcharstoremove)) {
2206 $forbidden_chars_to_remove = $badcharstoremove;
2210 return str_replace($forbidden_chars_to_replace, $newstr, str_replace($forbidden_chars_to_remove,
"", $str));
2229 if ($removetabcrlf) {
2230 return preg_replace(
'/[\x00-\x1F\x7F]/u',
'', $str);
2232 return preg_replace(
'/[\x00-\x08\x11-\x12\x14-\x1F\x7F]/u',
'', $str);
2247 if (function_exists(
'iconv')) {
2248 $slug = iconv(
'UTF-8',
'ASCII//TRANSLIT//IGNORE', $slug);
2252 $slug = strtolower($slug);
2255 $slug = preg_replace(
'/[^a-z0-9]+/',
'-', $slug);
2258 $slug = trim($slug,
'-');
2271function dol_escape_js($stringtoescape, $mode = 0, $noescapebackslashn = 0)
2273 if (is_null($stringtoescape)) {
2278 $substitjs = array(
"'" =>
"\\'",
"\r" =>
'\\r');
2280 if (empty($noescapebackslashn)) {
2281 $substitjs[
"\n"] =
'\\n';
2282 $substitjs[
'\\'] =
'\\\\';
2285 $substitjs[
"'"] =
"\\'";
2286 $substitjs[
'"'] =
"\\'";
2287 } elseif ($mode == 1) {
2288 $substitjs[
"'"] =
"\\'";
2289 } elseif ($mode == 2) {
2290 $substitjs[
'"'] =
'\\"';
2291 } elseif ($mode == 3) {
2292 $substitjs[
"'"] =
"\\'";
2293 $substitjs[
'"'] =
"\\\"";
2295 return strtr((
string) $stringtoescape, $substitjs);
2309 return rawurlencode($stringtoescape);
2320 return str_replace(
'"',
'\"', $stringtoescape);
2332 if (is_null($stringtoescape)) {
2336 if ($stringforquotes == 2) {
2337 return str_replace(
'"',
"'", $stringtoescape);
2338 } elseif ($stringforquotes == 1) {
2344 $stringtoescape = str_replace(
'\\',
'', $stringtoescape);
2345 return str_replace(
"'",
"\'", str_replace(
'"',
"'", $stringtoescape));
2348 return 'Bad parameter for stringforquotes in dol_escape_php';
2359 return preg_replace(
'/[^a-z0-9_]/i',
'', $stringtoescape);
2370 return $stringtoescape;
2434 $allowedtags = array(
'br',
'b',
'font',
'hr',
'span');
2435 if (!empty($allowothertags) && is_array($allowothertags)) {
2436 $allowedtags = array_merge($allowedtags, $allowothertags);
2440 if ($escapeonlyhtmltags) {
2441 return dol_escape_htmltag(
dol_string_onlythesehtmltags($s, 1, 0, 0, 0, $allowedtags), 1, -1,
'', 1, 1);
2443 return dol_escape_htmltag(
dol_string_onlythesehtmltags(
dol_htmlentitiesbr($s), 1, 0, 0, 0, $allowedtags), 1, -1,
'', 0, 1);
2459 $escapeonlyhtmltags = 1;
2460 return dol_escape_htmltag(
dol_string_onlythesehtmltags($s, 1, 1, 1, 0, array()), 0, 0,
'', $escapeonlyhtmltags, 1);
2485 return htmlspecialchars($s, ENT_HTML5,
'UTF-8');
2505function dol_escape_htmltag($stringtoescape, $keepb = 0, $keepn = 0, $noescapetags =
'', $escapeonlyhtmltags = 0, $cleanalsojavascript = 0)
2507 if ($noescapetags ==
'common') {
2508 $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';
2510 $noescapetags .=
',header,footer,nav,section,menu,menuitem';
2512 if ($cleanalsojavascript) {
2517 if ($escapeonlyhtmltags) {
2518 $tmp = htmlspecialchars_decode((
string) $stringtoescape, ENT_COMPAT);
2525 $tmp = (string) $stringtoescape;
2528 $tmp = str_ireplace(
'<',
'__DONOTDECODELT', $tmp);
2529 $tmp = str_ireplace(
'>',
'__DONOTDECODEGT', $tmp);
2530 $tmp = str_ireplace(
'&',
'__DONOTDECODEAMP', $tmp);
2531 $tmp = str_ireplace(
'"',
'__DONOTDECODEQUOT', $tmp);
2532 $tmp = str_ireplace(
'&apos',
'__DONOTDECODEAPOS', $tmp);
2533 $tmp = str_ireplace(
''',
'__DONOTDECODE39', $tmp);
2535 $tmp = html_entity_decode((
string) $tmp, ENT_COMPAT,
'UTF-8');
2538 $tmp = str_ireplace(
'__DONOTDECODELT',
'<', $tmp);
2539 $tmp = str_ireplace(
'__DONOTDECODEGT',
'>', $tmp);
2540 $tmp = str_ireplace(
'__DONOTDECODEAMP',
'&', $tmp);
2541 $tmp = str_ireplace(
'__DONOTDECODEQUOT',
'"', $tmp);
2542 $tmp = str_ireplace(
'__DONOTDECODEAPOS',
'&apos', $tmp);
2543 $tmp = str_ireplace(
'__DONOTDECODE39',
''', $tmp);
2545 $tmp = str_ireplace(
''',
'__SIMPLEQUOTE__', $tmp);
2548 $tmp = strtr($tmp, array(
"<b>" =>
'',
'</b>' =>
'',
'<strong>' =>
'',
'</strong>' =>
''));
2551 $tmp = strtr($tmp, array(
"\r" =>
'\\r',
"\n" =>
'\\n'));
2552 } elseif ($keepn == -1) {
2553 $tmp = strtr($tmp, array(
"\r" =>
'',
"\n" =>
''));
2556 if ($escapeonlyhtmltags) {
2557 $tmp = htmlspecialchars($tmp, ENT_COMPAT,
'UTF-8');
2561 $tmparrayoftags = array();
2562 if ($noescapetags) {
2563 $tmparrayoftags = explode(
',', $noescapetags);
2566 if (count($tmparrayoftags)) {
2571 $tmp = str_ireplace(array(
'__DOUBLEQUOTE',
'__BEGINTAGTOREPLACE',
'__ENDTAGTOREPLACE',
'__BEGINENDTAGTOREPLACE'),
'', $tmp);
2573 foreach ($tmparrayoftags as $tagtoreplace) {
2575 $tmp = preg_replace(
'/<' . preg_quote($tagtoreplace,
'/') .
'>/',
'__BEGINTAGTOREPLACE' . $tagtoreplace .
'__', $tmp);
2576 $tmp = str_ireplace(
'</' . $tagtoreplace .
'>',
'__ENDTAGTOREPLACE' . $tagtoreplace .
'__', $tmp);
2577 $tmp = preg_replace(
'/<' . preg_quote($tagtoreplace,
'/') .
' \/>/',
'__BEGINENDTAGTOREPLACE' . $tagtoreplace .
'__', $tmp);
2583 if (preg_match(
'/<' . preg_quote($tagtoreplace,
'/') .
'(\s+)([^>]+)>/', $tmp, $reg)) {
2585 $tmpattributes = str_ireplace(array(
'[',
']'),
'_', $reg[2]);
2586 $tmpattributes = str_ireplace(
'"',
'__DOUBLEQUOTE__', $tmpattributes);
2587 $tmpattributes = preg_replace(
'/[^a-z0-9_%,\/\?\;\s=&\.\-@:\.#\+]/i',
'', $tmpattributes);
2589 $tmp = str_replace(
'<' . $tagtoreplace . $reg[1] . $reg[2] .
'>',
'__BEGINTAGTOREPLACE' . $tagtoreplace .
'[' . $tmpattributes .
']__', $tmp);
2592 $diff = strcmp($tmpold, $tmp);
2596 $tmp = str_ireplace(
'&',
'__ANDNOSEMICOLON__', $tmp);
2597 $tmp = str_ireplace(
'"',
'__DOUBLEQUOTENOSEMICOLON__', $tmp);
2598 $tmp = str_ireplace(
'<',
'__LESSTHAN__', $tmp);
2599 $tmp = str_ireplace(
'>',
'__GREATERTHAN__', $tmp);
2603 $result = htmlentities($tmp, ENT_COMPAT,
'UTF-8');
2607 if (count($tmparrayoftags)) {
2609 foreach ($tmparrayoftags as $tagtoreplace) {
2610 $result = str_ireplace(
'__BEGINTAGTOREPLACE' . $tagtoreplace .
'__',
'<' . $tagtoreplace .
'>', $result);
2611 $result = preg_replace(
'/__BEGINTAGTOREPLACE' . $tagtoreplace .
'\[([^\]]*)\]__/',
'<' . $tagtoreplace .
' \1>', $result);
2612 $result = str_ireplace(
'__ENDTAGTOREPLACE' . $tagtoreplace .
'__',
'</' . $tagtoreplace .
'>', $result);
2613 $result = str_ireplace(
'__BEGINENDTAGTOREPLACE' . $tagtoreplace .
'__',
'<' . $tagtoreplace .
' />', $result);
2614 $result = preg_replace(
'/__BEGINENDTAGTOREPLACE' . $tagtoreplace .
'\[([^\]]*)\]__/',
'<' . $tagtoreplace .
' \1 />', $result);
2617 $result = str_ireplace(
'__DOUBLEQUOTE__',
'"', $result);
2619 $result = str_ireplace(
'__ANDNOSEMICOLON__',
'&', $result);
2620 $result = str_ireplace(
'__DOUBLEQUOTENOSEMICOLON__',
'"', $result);
2621 $result = str_ireplace(
'__LESSTHAN__',
'<', $result);
2622 $result = str_ireplace(
'__GREATERTHAN__',
'>', $result);
2625 $result = str_ireplace(
'__SIMPLEQUOTE__',
''', $result);
2642 if (function_exists(
'mb_strtolower')) {
2643 return mb_strtolower($string, $encoding);
2645 return strtolower($string);
2659 if (function_exists(
'mb_strtoupper')) {
2660 return mb_strtoupper($string, $encoding);
2662 return strtoupper($string);
2676 if (function_exists(
'mb_substr')) {
2677 return mb_strtoupper(mb_substr($string, 0, 1, $encoding), $encoding) . mb_substr($string, 1,
null, $encoding);
2679 return ucfirst($string);
2693 if (function_exists(
'mb_convert_case')) {
2694 return mb_convert_case($string, MB_CASE_TITLE, $encoding);
2696 return ucwords($string);
2708 $backtrace = debug_backtrace();
2710 if (count($backtrace) >= 1) {
2712 if (count($backtrace) == 1) {
2715 $trace = $backtrace[$pos];
2716 if (isset($trace[
'file'], $trace[
'line'])) {
2717 $msg =
" From {$trace['file']}:{$trace['line']}.";
2745function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename =
'', $restricttologhandler =
'', $logcontext =
null)
2747 global $conf, $user, $debugbar;
2755 if (defined(
'USEEXTERNALSERVER') && !defined(
'USEDOLIBARRSERVER') && !defined(
'USEDOLIBARREDITOR')) {
2756 global $website, $websitekey;
2757 if (is_object($website) && !empty($website->ref)) {
2758 $suffixinfilename .=
'_website_' . $website->ref;
2759 } elseif (!empty($websitekey)) {
2760 $suffixinfilename .=
'_website_' . $websitekey;
2765 if (defined(
'USESUFFIXINLOG')) {
2766 $suffixinfilename .= constant(
'USESUFFIXINLOG');
2770 foreach ($conf->loghandlers as $loghandlerinstance) {
2771 $loghandlerinstance->setIdent($ident);
2775 if (!empty($message)) {
2778 $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');
2780 if (!array_key_exists($level, $logLevels)) {
2781 dol_syslog(
'Error Bad Log Level ' . $level, LOG_ERR);
2789 $message = preg_replace(
'/password=\'[^\']*\'/',
'password=\'hidden\'', $message);
2793 if ((!empty($_REQUEST[
'logtohtml']) &&
getDolGlobalString(
'MAIN_ENABLE_LOG_TO_HTML'))
2794 || (is_object($user) && $user->hasRight(
'debugbar',
'read') && is_object($debugbar))
2796 $ospid = sprintf(
"%7s",
dol_trunc((
string) getmypid(), 7,
'right',
'UTF-8', 1));
2797 $osuser =
" " . sprintf(
"%6s",
dol_trunc(function_exists(
'posix_getuid') ? posix_getuid() :
'', 6,
'right',
'UTF-8', 1));
2799 $conf->logbuffer[] =
dol_print_date(time(),
"%Y-%m-%d %H:%M:%S") .
" " . sprintf(
"%-7s", $logLevels[$level]) .
" " . $ospid .
" " . $osuser .
" " . $message;
2805 print
"\n\n<!-- Log start\n";
2807 print
"Log end -->\n";
2811 'message' => $message,
2812 'script' => (isset($_SERVER[
'PHP_SELF']) ? basename($_SERVER[
'PHP_SELF'],
'.php') :
''),
2814 'user' => ((is_object($user) && $user->id) ? $user->login :
''),
2816 'osuser' => function_exists(
'posix_getuid') ? (string) posix_getuid() :
'',
2817 'ospid' => (string) getmypid()
2822 if (!empty($remoteip)) {
2823 $data[
'ip'] = $remoteip;
2827 if (!empty($_SERVER[
'HTTP_X_FORWARDED_FOR'])) {
2828 $tmpips = explode(
',', $_SERVER[
'HTTP_X_FORWARDED_FOR']);
2832 foreach ($tmpips as $tmpip) {
2833 $tmpip = trim($tmpip);
2834 if (strtolower($tmpip) == strtolower($remoteip)) {
2837 if (empty($data[
'ip'])) {
2838 $data[
'ip'] = $tmpip;
2841 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $tmpip;
2844 if (!$foundremoteip) {
2846 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $remoteip;
2848 $data[
'ip'] .= (($j > 0) ?
']' :
'');
2849 } elseif (!empty($_SERVER[
'HTTP_CLIENT_IP'])) {
2850 $tmpips = explode(
',', $_SERVER[
'HTTP_CLIENT_IP']);
2854 foreach ($tmpips as $tmpip) {
2855 $tmpip = trim($tmpip);
2856 if (strtolower($tmpip) == strtolower($remoteip)) {
2859 if (empty($data[
'ip'])) {
2860 $data[
'ip'] = $tmpip;
2863 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $tmpip;
2866 if (!$foundremoteip) {
2868 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $remoteip;
2870 $data[
'ip'] .= (($j > 0) ?
']' :
'');
2872 } elseif (!empty($_SERVER[
'SERVER_ADDR'])) {
2874 $data[
'ip'] = (string) $_SERVER[
'SERVER_ADDR'];
2875 } elseif (!empty($_SERVER[
'COMPUTERNAME'])) {
2877 $data[
'ip'] = (string) $_SERVER[
'COMPUTERNAME'];
2879 $data[
'ip'] =
'???';
2882 if (!empty($_SERVER[
'USERNAME'])) {
2884 $data[
'osuser'] = (string) $_SERVER[
'USERNAME'];
2885 } elseif (!empty($_SERVER[
'LOGNAME'])) {
2887 $data[
'osuser'] = (string) $_SERVER[
'LOGNAME'];
2891 foreach ($conf->loghandlers as $loghandlerinstance) {
2892 if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler) {
2895 $loghandlerinstance->export($data, $suffixinfilename);
2901 foreach ($conf->loghandlers as $loghandlerinstance) {
2902 $loghandlerinstance->setIdent($ident);
2922 $form =
new Form($db);
2924 $templatenameforexport = $website->name_template;
2925 if (empty($templatenameforexport)) {
2926 $templatenameforexport =
'website_' . $website->ref;
2930 $out .=
'<input type="button" class="cursorpointer button bordertransp" id="open-dialog-' . $name .
'" value="' .
dol_escape_htmltag($buttonstring) .
'"/>';
2933 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">';
2934 $out .=
'jQuery(document).ready(function () {';
2935 $out .=
' jQuery("#open-dialog-' . $name .
'").click(function () {';
2936 $out .=
' var dialogHtml = \'';
2938 $dialogcontent =
' <div id="custom-dialog-' . $name .
'">';
2939 $dialogcontent .=
' <div style="margin-top: 20px;">';
2940 $dialogcontent .=
' <label for="export-site-' . $name .
'"><strong>' . $langs->trans(
"ExportSiteLabel") .
'...</label><br>';
2941 $dialogcontent .=
' <button class="button smallpaddingimp" id="export-site-' . $name .
'">' .
dol_escape_htmltag($langs->trans(
"DownloadZip")) .
'</button>';
2942 $dialogcontent .=
' </div>';
2943 $dialogcontent .=
' <br>';
2944 $dialogcontent .=
' <div style="margin-top: 20px;">';
2945 $dialogcontent .=
' <strong>' . $langs->trans(
"ExportSiteGitLabel") .
' ' . $form->textwithpicto(
'', $langs->trans(
"SourceFiles"), 1,
'help',
'', 0, 3,
'') .
'</strong><br>';
2946 $dialogcontent .=
' <form action="' .
dol_escape_htmltag($overwriteGitUrl) .
'" method="POST">';
2947 $dialogcontent .=
' <input type="hidden" name="action" value="overwritesite">';
2948 $dialogcontent .=
' <input type="hidden" name="token" value="' .
newToken() .
'">';
2949 $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>';
2950 $dialogcontent .=
' <button type="submit" class="button smallpaddingimp" id="overwrite-git-' . $name .
'">' .
dol_escape_htmltag($langs->trans(
"ExportIntoGIT")) .
'</button>';
2951 $dialogcontent .=
' </form>';
2952 $dialogcontent .=
' </div>';
2953 $dialogcontent .=
' </div>';
2960 // Add the content of the dialog to the body of the page
2961 $out .= ' var $dialog = jQuery(
"#custom-dialog-' . $name . '");
';
2962 $out .= ' if ($dialog.length > 0) {
2965 jQuery(
"body").append(dialogHtml);
';
2967 // Configuration of popup
2968 $out .= ' jQuery(
"#custom-dialog-' . $name . '").dialog({
';
2969 $out .= ' autoOpen:
false,
';
2970 $out .= ' modal:
true,
';
2971 $out .= ' height: 290,
';
2972 $out .= ' width:
"40%",
';
2973 $out .= ' title:
"' . dol_escape_js($label) . '",
';
2976 // Simulate a click on the original "submit" input to export the site.
2977 $out .= ' jQuery(
"#export-site-' . $name . '").click(
function () {
';
2978 $out .= ' console.log(
"Clic on exportsite.");
';
2979 $out .= ' var target = jQuery(
"input[name=\'' . dol_escape_js($exportSiteName) . '\']");
';
2980 $out .= ' console.log(
"element founded:", target.length > 0);
';
2981 $out .= ' if (target.length > 0) { target.click(); }
';
2982 $out .= ' jQuery(
"#custom-dialog-' . $name . '").dialog(
"close");
';
2986 $out .= ' jQuery(
"#custom-dialog-' . $name . '").dialog(
"open");
';
2987 $out .= ' return false;
';
2990 $out .= '</script>
';
3012function dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled = '
', $morecss = 'classlink
button bordertransp
', $jsonopen = '', $jsonclose = '', $accesskey = '')
3016 if (strpos($url, '?
') > 0) {
3017 $url .= '&dol_hide_topmenu=1&dol_hide_leftmenu=1&dol_openinpopup=
' . urlencode($name);
3019 $url .= '?dol_hide_topmenu=1&dol_hide_leftmenu=1&dol_openinpopup=
' . urlencode($name);
3022 if (preg_match('/^https/i
', $url)) {
3025 $urltoopen = DOL_URL_ROOT . $url;
3030 //print '<input
type=
"submit" class=
"button bordertransp"'.$disabled.' value=
"'.dol_escape_htmltag($langs->trans("MediaFiles
")).'" name=
"file_manager">
';
3031 $out .= '<!-- a link
for button to open url into a dialog popup -->
';
3032 $out .= '<a
' . ($accesskey ? ' accesskey=
"' . $accesskey . '"' : '') . ' class=
"cursorpointer reposition button_' . $name . ($morecss ? ' ' . $morecss : '') . '"' . $disabled . ' title=
"' . dol_escape_htmltag($label) . '"';
3033 if (empty($conf->use_javascript_ajax)) {
3034 $out .= ' href=
"' . $urltoopen . '" target=
"_blank"';
3035 } elseif ($jsonopen) {
3036 $out .= ' href=
"#" onclick=
"' . $jsonopen . '"';
3038 $out .= ' href=
"#"';
3040 $out .= '>
' . $buttonstring . '</a>
';
3042 if (!empty($conf->use_javascript_ajax)) {
3043 // Add code to open url using the popup.
3044 $out .= '<!-- code to open popup and variables to retrieve returned variables -->
';
3045 $out .= '<div
id=
"idfordialog' . $name . '" class=
"hidden">
' . (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER
') < 2 ? 'div
for dialog
' : '') . '</div>
';
3047 $out .= '<!-- Add js code to open dialog popup on dialog -->
';
3048 $out .= '<script nonce=
"' . getNonce() . '" type=
"text/javascript">
3049 jQuery(document).ready(
function () {
3050 jQuery(
".button_' . $name . '").click(
function () {
3051 console.log(\
'Open popup with jQuery(...).dialog() on URL ' .
dol_escape_js($urltoopen) .
'\');
3052 var $tmpdialog = $(\
'#idfordialog' . $name .
'\');
3053 $tmpdialog.html(\
'<iframe class="iframedialog" id="iframedialog' . $name .
'" style="border: 0px;" src="' . $urltoopen .
'" width="100%" height="98%"></iframe>\');
3057 height: (window.innerHeight - 150),
3060 open: function (event, ui) {
3061 console.log(
"open popup name=' . $name . '");
3063 close:
function (event, ui) {
3064 console.log(
"Popup is closed, run jsonclose = ' . $jsonclose . '");
3065 ' . (empty($jsonclose) ? '' : $jsonclose . ';
') . '
3069 $tmpdialog.dialog(\
'open\');
3094function dol_fiche_head($links = array(), $active =
'0', $title =
'', $notab = 0, $picto =
'', $pictoisfullpath = 0, $morehtmlright =
'', $morecss =
'', $limittoshow = 0, $moretabssuffix =
'')
3096 print
dol_get_fiche_head($links, $active, $title, $notab, $picto, $pictoisfullpath, $morehtmlright, $morecss, $limittoshow, $moretabssuffix);
3116function dol_get_fiche_head($links = array(), $active =
'', $title =
'', $notab = 0, $picto =
'', $pictoisfullpath = 0, $morehtmlright =
'', $morecss =
'', $limittoshow = 0, $moretabssuffix =
'', $dragdropfile = 0, $morecssdiv =
'')
3118 global $conf, $langs, $hookmanager;
3122 if (!empty($conf->dol_optimize_smallscreen)) {
3126 $out =
"\n" .
'<!-- dol_fiche_head - dol_get_fiche_head -->';
3128 if ((!empty($title) && $showtitle) || $morehtmlright || !empty($links)) {
3129 $out .=
'<div class="tabs' . ($picto ?
'' :
' nopaddingleft') .
'" data-role="controlgroup" data-type="horizontal">' .
"\n";
3133 if ($morehtmlright) {
3134 $out .=
'<div class="inline-block floatright tabsElem">' . $morehtmlright .
'</div>';
3141 if (is_array($links) && !empty($links)) {
3142 $keys = array_keys($links);
3144 $maxkey = max($keys);
3150 if (empty($limittoshow)) {
3153 if (!empty($conf->dol_optimize_smallscreen)) {
3161 for ($i = 0; $i <= $maxkey; $i++) {
3162 if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2])) {
3164 if ($i >= $limittoshow) {
3170 for ($i = 0; $i <= $maxkey; $i++) {
3171 if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2])) {
3177 if ($i < $limittoshow || $isactive) {
3179 $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])) .
' -->';
3181 if (isset($links[$i][2]) && $links[$i][2] ==
'image') {
3182 if (!empty($links[$i][0])) {
3183 $out .=
'<a class="tabimage' . ($morecss ?
' ' . $morecss :
'') .
'" href="' . $links[$i][0] .
'">' . $links[$i][1] .
'</a>' .
"\n";
3185 $out .=
'<span class="tabspan">' . $links[$i][1] .
'</span>' .
"\n";
3187 } elseif (!empty($links[$i][1])) {
3189 $out .=
'<div class="tab tab' . ($isactive ?
'active' :
'unactive') .
'" style="margin: 0 !important">';
3191 if (!empty($links[$i][0])) {
3192 $titletoshow = preg_replace(
'/<.*$/',
'', $links[$i][1]);
3193 $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) .
'">';
3196 if ($displaytab == 0 && $picto) {
3197 $out .=
img_picto($title, $picto,
'', $pictoisfullpath, 0, 0,
'',
'imgTabTitle paddingright marginrightonlyshort');
3200 $out .= $links[$i][1];
3201 if (!empty($links[$i][0])) {
3202 $out .=
'</a>' .
"\n";
3204 $out .= empty($links[$i][4]) ?
'' : $links[$i][4];
3213 $outmore .=
'<div class="popuptabset wordwrap">';
3215 $outmore_content =
'';
3217 if (isset($links[$i][2]) && $links[$i][2] ==
'image') {
3218 if (!empty($links[$i][0])) {
3219 $outmore_content .=
'<a class="tabimage' . ($morecss ?
' ' . $morecss :
'') .
'" href="' . $links[$i][0] .
'">' . $links[$i][1] .
'</a>' .
"\n";
3221 $outmore_content .=
'<span class="tabspan">' . $links[$i][1] .
'</span>' .
"\n";
3223 } elseif (!empty($links[$i][1])) {
3224 $outmore_content .=
'<a' . (!empty($links[$i][2]) ?
' id="' . $links[$i][2] .
'"' :
'') .
' class="wordwrap inline-block' . ($morecss ?
' ' . $morecss :
'') .
'" href="' . $links[$i][0] .
'">';
3225 $outmore_content .= preg_replace(
'/([a-z])\|([a-z])/i',
'\\1 | \\2', $links[$i][1]);
3226 $outmore_content .=
'</a>' .
"\n";
3228 if ($outmore_content !==
'') {
3229 $outmore .=
'<div class="popuptab wordwrap" style="display:inherit;">' . $outmore_content .
'</div>';
3235 $displaytab = $i + 1;
3238 $outmore .=
'</div>';
3242 $left = ($langs->trans(
"DIRECTION") ==
'rtl' ?
'right' :
'left');
3243 $right = ($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right');
3244 $widthofpopup = 240;
3246 $tabsname = $moretabssuffix;
3247 if (empty($tabsname)) {
3248 $tabsname = str_replace(
"@",
"", $picto);
3250 $out .=
'<div id="moretabs' . $tabsname .
'" class="inline-block tabsElem valignmiddle">';
3252 $out .=
'<div class="tab valignmiddle"><a href="#" class="tab moretab inline-block tabunactive valignmiddle"><span class="hideonsmartphone">' . $langs->trans(
"More") .
'</span>... (' . $nbintab .
')</a></div>';
3254 $out .=
'<div id="moretabsList' . $tabsname .
'" style="width: ' . $widthofpopup .
'px; position: absolute; ' . $left .
': -999em; text-align: ' . $left .
'; margin:0px; padding:2px; z-index:10;">';
3257 $out .=
'<div></div>';
3260 $out .=
'<script nonce="' .
getNonce() .
'">';
3261 $out .=
"$('#moretabs" . $tabsname .
"').mouseenter( function() {
3262 var x = this.offsetLeft, y = this.offsetTop;
3263 console.log('mouseenter " . $left .
" x='+x+' y='+y+' window.innerWidth='+window.innerWidth);
3264 if ((window.innerWidth - x) < " . ($widthofpopup + 10) .
") {
3265 $('#moretabsList" . $tabsname .
"').css('" . $right .
"','8px');
3267 $('#moretabsList" . $tabsname .
"').css('" . $left .
"','auto');
3270 $out .=
"$('#moretabs" . $tabsname .
"').mouseleave( function() { console.log('mouseleave " . $left .
"'); $('#moretabsList" . $tabsname .
"').css('" . $left .
"','-999em');});";
3271 $out .=
"</script>";
3274 if ((!empty($title) && $showtitle) || $morehtmlright || !empty($links)) {
3278 if (!$notab || $notab == -1 || $notab == -2 || $notab == -3 || $notab == -4) {
3279 $out .=
"\n" .
'<div id="dragDropAreaTabBar" class="tabBar' . ($notab == -1 ?
'' : ($notab == -2 ?
' tabBarNoTop' : ((($notab == -3 || $notab == -4) ?
' noborderbottom' :
'') . ($notab == -4 ?
'' :
' tabBarWithBottom'))));
3280 $out .= ($morecssdiv ?
' ' . $morecssdiv :
'');
3281 $out .=
'">' .
"\n";
3283 if (!empty($dragdropfile)) {
3284 include_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
3287 $parameters = array(
'tabname' => $active,
'out' => $out);
3288 $reshook = $hookmanager->executeHooks(
'printTabsHead', $parameters);
3290 $out = $hookmanager->resPrint;
3316 if (!$notab || $notab == -1) {
3317 return "\n</div>\n";
3342function dol_banner_tab(
$object, $paramid, $morehtml =
'', $shownav = 1, $fieldid =
'rowid', $fieldref =
'ref', $morehtmlref =
'', $moreparam =
'', $nodbprefix = 0, $morehtmlleft =
'', $morehtmlstatus =
'', $onlybanner = 0, $morehtmlright =
'')
3344 global $conf, $form, $user, $langs, $hookmanager, $action;
3348 $maxvisiblephotos = 1;
3350 $entity = (empty(
$object->entity) ? $conf->entity :
$object->entity);
3353 if (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'barcode',
'lire_advance')) {
3356 $modulepart =
'unknown';
3358 if (in_array(
$object->element, [
'societe',
'contact',
'product',
'ticket',
'bom'])) {
3359 $modulepart =
$object->element;
3360 } elseif (
$object->element ==
'member') {
3361 $modulepart =
'memberphoto';
3362 } elseif (
$object->element ==
'user') {
3363 $modulepart =
'userphoto';
3366 if (class_exists(
"Imagick")) {
3367 if (
$object->element ==
'expensereport' ||
$object->element ==
'propal' ||
$object->element ==
'commande' ||
$object->element ==
'facture' ||
$object->element ==
'supplier_proposal') {
3368 $modulepart =
$object->element;
3369 } elseif (
$object->element ==
'fichinter' ||
$object->element ==
'intervention') {
3370 $modulepart =
'ficheinter';
3371 } elseif (
$object->element ==
'contrat' ||
$object->element ==
'contract') {
3372 $modulepart =
'contract';
3373 } elseif (
$object->element ==
'order_supplier') {
3374 $modulepart =
'supplier_order';
3375 } elseif (
$object->element ==
'invoice_supplier') {
3376 $modulepart =
'supplier_invoice';
3380 if (
$object->element ==
'product') {
3382 '@phan-var-force Product $object';
3384 $cssclass =
'photowithmargin photoref';
3385 $showimage =
$object->is_photo_available($conf->product->multidir_output[$entity]);
3387 if ($conf->browser->layout ==
'phone') {
3388 $maxvisiblephotos = 1;
3391 $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>';
3395 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
3397 $nophoto =
'/public/theme/common/nophoto.png';
3398 $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>';
3401 } elseif (
$object->element ==
'category') {
3403 '@phan-var-force Categorie $object';
3405 $cssclass =
'photowithmargin photoref';
3406 $showimage =
$object->isAnyPhotoAvailable($conf->categorie->multidir_output[$entity]);
3408 if ($conf->browser->layout ==
'phone') {
3409 $maxvisiblephotos = 1;
3412 $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>';
3416 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
3418 $nophoto =
'/public/theme/common/nophoto.png';
3419 $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>';
3422 } elseif (
$object->element ==
'bom') {
3424 '@phan-var-force Bom $object';
3426 $cssclass =
'photowithmargin photoref';
3427 $showimage =
$object->is_photo_available($conf->bom->multidir_output[$entity]);
3429 if ($conf->browser->layout ==
'phone') {
3430 $maxvisiblephotos = 1;
3433 $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>';
3437 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
3439 $nophoto =
'/public/theme/common/nophoto.png';
3440 $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>';
3443 } elseif (
$object->element ==
'ticket') {
3445 $cssclass =
'photoref';
3447 '@phan-var-force Ticket $object';
3448 $showimage =
$object->is_photo_available($conf->ticket->multidir_output[$entity] .
'/' .
$object->ref);
3450 if ($conf->browser->layout ==
'phone') {
3451 $maxvisiblephotos = 1;
3455 $showphoto =
$object->show_photos(
'ticket', $conf->ticket->multidir_output[$entity],
'small', $maxvisiblephotos, 0, 0, 0, $width, 0);
3457 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">' . $showphoto .
'</div>';
3465 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
3467 $nophoto =
img_picto(
'No photo',
'object_ticket');
3468 $morehtmlleft .=
'<!-- No photo to show -->';
3469 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
3470 $morehtmlleft .= $nophoto;
3471 $morehtmlleft .=
'</div></div>';
3475 if ($modulepart !=
'unknown' || method_exists(
$object,
'getDataToShowPhoto')) {
3478 if (in_array($modulepart, array(
'propal',
'commande',
'facture',
'ficheinter',
'contract',
'supplier_order',
'supplier_proposal',
'supplier_invoice',
'expensereport')) && class_exists(
"Imagick")) {
3480 $dir_output = (empty($conf->$modulepart->multidir_output[$entity]) ? $conf->$modulepart->dir_output : $conf->$modulepart->multidir_output[$entity]) .
"/";
3481 if (in_array($modulepart, array(
'invoice_supplier',
'supplier_invoice'))) {
3483 $subdir .= ((!empty($subdir) && !preg_match(
'/\/$/', $subdir)) ?
'/' :
'') . $objectref;
3487 if (empty($subdir)) {
3488 $subdir =
'errorgettingsubdirofobject';
3491 $filepath = $dir_output . $subdir .
"/";
3493 $filepdf = $filepath . $objectref .
".pdf";
3494 $relativepath = $subdir .
'/' . $objectref .
'.pdf';
3497 $fileimage = $filepdf .
'_preview.png';
3498 $relativepathimage = $relativepath .
'_preview.png';
3500 $pdfexists = file_exists($filepdf);
3505 if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) {
3507 include_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
3516 if ($pdfexists && !$error) {
3517 $heightforphotref = 80;
3518 if (!empty($conf->dol_optimize_smallscreen)) {
3519 $heightforphotref = 60;
3522 if (file_exists($fileimage)) {
3523 $phototoshow =
'<div class="photoref">';
3524 $phototoshow .=
'<img height="' . $heightforphotref .
'" class="photo photowithborder" src="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=apercu' . $modulepart .
'&file=' . urlencode($relativepathimage) .
'">';
3525 $phototoshow .=
'</div>';
3528 } elseif (!$phototoshow) {
3529 $phototoshow .= $form->showphoto($modulepart,
$object, 0, 0, 0,
'photowithmargin photoref',
'small', 1, 0);
3533 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">';
3534 $morehtmlleft .= $phototoshow;
3535 $morehtmlleft .=
'</div>';
3539 if (empty($phototoshow)) {
3540 if (
$object->element ==
'action') {
3542 $cssclass =
'photorefcenter';
3543 $nophoto =
img_picto(
'No photo',
'title_agenda');
3546 $cssclass =
'photorefcenter';
3548 $prefix =
'object_';
3552 if (strpos($picto,
'fontawesome_') !==
false) {
3555 $nophoto =
img_picto(
'No photo', $prefix . $picto);
3557 $morehtmlleft .=
'<!-- No photo to show -->';
3558 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
3559 $morehtmlleft .= $nophoto;
3560 $morehtmlleft .=
'</div></div>';
3566 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">' . $form->showbarcode(
$object, 100,
'photoref valignmiddle') .
'</div>';
3569 if (
$object->element ==
'societe') {
3571 if (!empty($conf->use_javascript_ajax) && $user->hasRight(
'societe',
'creer') &&
getDolGlobalString(
'MAIN_DIRECT_STATUS_UPDATE')) {
3574 $morehtmlstatus .=
$object->getLibStatut(6);
3576 } elseif (
$object->element ==
'product') {
3579 if (!empty($conf->use_javascript_ajax) && $user->hasRight(
'produit',
'creer') &&
getDolGlobalString(
'MAIN_DIRECT_STATUS_UPDATE')) {
3580 $morehtmlstatus .=
ajax_object_onoff(
$object,
'status',
'status',
'ProductStatusOnSell',
'ProductStatusNotOnSell');
3582 $morehtmlstatus .=
'<span class="statusrefsell">' .
$object->getLibStatut(6, 0) .
'</span>';
3584 $morehtmlstatus .=
' ';
3586 if (!empty($conf->use_javascript_ajax) && $user->hasRight(
'produit',
'creer') &&
getDolGlobalString(
'MAIN_DIRECT_STATUS_UPDATE')) {
3587 $morehtmlstatus .=
ajax_object_onoff(
$object,
'status_buy',
'status_buy',
'ProductStatusOnBuy',
'ProductStatusNotOnBuy');
3589 $morehtmlstatus .=
'<span class="statusrefbuy">' .
$object->getLibStatut(6, 1) .
'</span>';
3591 } elseif (in_array(
$object->element, array(
'salary'))) {
3593 '@phan-var-force Salary $object';
3595 if (empty($tmptxt) || $tmptxt ==
$object->getLibStatut(3)) {
3598 $morehtmlstatus .= $tmptxt;
3599 } elseif (in_array(
$object->element, array(
'facture',
'invoice',
'invoice_supplier'))) {
3601 '@phan-var-force Facture|FactureFournisseur|CommonInvoice $object';
3602 if (!isset(
$object->alreadypaid)) {
3608 $tmptxt =
$object->getLibStatut(6, (
float)
$object->alreadypaid);
3609 if (empty($tmptxt) || $tmptxt ==
$object->getLibStatut(3)) {
3610 $tmptxt =
$object->getLibStatut(5, (
float)
$object->alreadypaid);
3612 $morehtmlstatus .= $tmptxt;
3613 } elseif (in_array(
$object->element, array(
'chargesociales',
'loan',
'tva'))) {
3615 '@phan-var-force ChargeSociales|Loan|Tva $object';
3617 if (empty($tmptxt) || $tmptxt ==
$object->getLibStatut(3)) {
3620 $morehtmlstatus .= $tmptxt;
3621 } elseif (
$object->element ==
'contrat' ||
$object->element ==
'contract') {
3624 $morehtmlstatus .=
$object->getLibStatut(5);
3626 $morehtmlstatus .=
$object->getLibStatut(4);
3628 } elseif (
$object->element ==
'facturerec') {
3630 '@phan-var-force FactureRec $object';
3631 if (
$object->frequency == 0) {
3632 $morehtmlstatus .=
$object->getLibStatut(2);
3634 $morehtmlstatus .=
$object->getLibStatut(5);
3636 } elseif (
$object->element ==
'project_task') {
3638 $tmptxt =
$object->getLibStatut(4);
3639 $morehtmlstatus .= $tmptxt;
3640 } elseif (method_exists(
$object,
'getLibStatut')) {
3641 $tmptxt =
$object->getLibStatut(6);
3642 if (empty($tmptxt) || $tmptxt ==
$object->getLibStatut(3)) {
3643 $tmptxt =
$object->getLibStatut(5);
3645 $morehtmlstatus .= $tmptxt;
3649 if (
isModEnabled(
'accounting') && in_array(
$object->element, array(
'bank',
'paiementcharge',
'facture',
'invoice',
'invoice_supplier',
'expensereport',
'payment_various'))) {
3651 if (method_exists(
$object,
'getVentilExportCompta')) {
3652 $accounted =
$object->getVentilExportCompta(1);
3653 $langs->load(
"accountancy");
3654 $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>';
3659 if (!empty(
$object->name_alias)) {
3661 '@phan-var-force Societe $object';
3666 if (in_array(
$object->element, array(
'product',
'bank_account',
'project_task'))) {
3669 $morehtmlref .=
'<div class="refidno banner-object-label">' .
$object->label .
'</div>';
3673 if (method_exists(
$object,
'getBannerAddress') && !in_array(
$object->element, array(
'product',
'bookmark',
'ecm_directories',
'ecm_files'))) {
3676 $morehtmlref .=
'<div class="refidno refaddress">';
3677 $morehtmlref .= $moreaddress;
3678 $morehtmlref .=
'</div>';
3682 $morehtmlref .=
'<div style="clear: both;"></div>';
3683 $morehtmlref .=
'<div class="refidno opacitymedium">';
3684 $morehtmlref .= $langs->trans(
"TechnicalID") .
': ' . ((int)
$object->id);
3685 $morehtmlref .=
'</div>';
3688 $parameters = array(
'morehtmlref' => &$morehtmlref,
'moreparam' => &$moreparam,
'morehtmlleft' => &$morehtmlleft,
'morehtmlstatus' => &$morehtmlstatus,
'morehtmlright' => &$morehtmlright);
3689 $reshook = $hookmanager->executeHooks(
'formDolBanner', $parameters,
$object, $action);
3692 } elseif (empty($reshook)) {
3693 $morehtmlref .= $hookmanager->resPrint;
3694 } elseif ($reshook > 0) {
3695 $morehtmlref = $hookmanager->resPrint;
3704 print
'<div class="' . ($onlybanner ?
'arearefnobottom ' :
'arearef ') .
'heightref valignmiddle centpercent object-banner-tab-container" data-module-part="'.
dolPrintHTMLForAttribute($modulepart).
'">';
3705 print $form->showrefnav(
$object, $paramid, $morehtml, $shownav, $fieldid, $fieldref, $morehtmlref, $moreparam, $nodbprefix, $morehtmlleft, $morehtmlstatus, $morehtmlright);
3707 print
'<div class="underrefbanner clearboth"></div>';
3719function fieldLabel($langkey, $fieldkey, $fieldrequired = 0)
3723 if ($fieldrequired) {
3724 $ret .=
'<span class="fieldrequired">';
3726 $ret .=
'<label for="' . $fieldkey .
'">';
3727 $ret .= $langs->trans($langkey);
3729 if ($fieldrequired) {
3750 global $langs, $hookmanager;
3753 $countriesusingstate = array(
'AU',
'CA',
'US',
'IN',
'GB',
'ES',
'UK',
'TR',
'CN');
3758 $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)));
3761 if (isset(
$object->country_code) && in_array(
$object->country_code, array(
'AU',
'CA',
'US',
'CN')) ||
getDolGlobalString(
'MAIN_FORCE_STATE_INTO_ADDRESS')) {
3763 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3764 $ret .= (($ret && $town) ? $sep :
'') . $town;
3767 $ret .= ($ret ? ($town ?
", " : $sep) :
'') .
$object->state;
3770 $ret .= ($ret ? (($town ||
$object->state) ?
", " : $sep) :
'') .
$object->zip;
3772 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'GB',
'UK'))) {
3774 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3775 $ret .= ($ret ? $sep :
'') . $town;
3777 $ret .= ($ret ?
", " :
'') .
$object->state;
3780 $ret .= ($ret ? $sep :
'') .
$object->zip;
3782 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'ES',
'TR'))) {
3784 $ret .= ($ret ? $sep :
'') .
$object->zip;
3785 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3786 $ret .= ($town ? ((
$object->zip ?
' ' :
'') . $town) :
'');
3788 $ret .= $sep .
$object->state;
3790 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'JP'))) {
3793 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3795 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'IT'))) {
3797 $ret .= ($ret ? $sep :
'') .
$object->zip;
3798 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3799 $ret .= ($town ? ((
$object->zip ?
' ' :
'') . $town) :
'');
3800 $ret .= (empty(
$object->state_code) ?
'' : (
' ' .
$object->state_code));
3803 $town = (($extralangcode && !empty(
$object->array_languages[
'address'][$extralangcode])) ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3804 $ret .= !empty(
$object->zip) ? (($ret ? $sep :
'') .
$object->zip) :
'';
3805 $ret .= ($town ? ((
$object->zip ?
' ' : ($ret ? $sep :
'')) . $town) :
'');
3806 if (!empty(
$object->state) && in_array(
$object->country_code, $countriesusingstate)) {
3807 $ret .= ($ret ?
", " :
'') .
$object->state;
3811 if (!is_object($outputlangs)) {
3812 $outputlangs = $langs;
3815 $langs->load(
"dict");
3816 $ret .= (empty(
$object->country_code) ?
'' : ($ret ? $sep :
'') . $outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv(
"Country" .
$object->country_code)));
3819 $parameters = array(
'withcountry' => $withcountry,
'sep' => $sep,
'outputlangs' => $outputlangs,
'mode' => $mode,
'extralangcode' => $extralangcode);
3820 $reshook = $hookmanager->executeHooks(
'formatAddress', $parameters,
$object);
3824 $ret .= $hookmanager->resPrint;
3841function dol_strftime($fmt, $ts =
false, $is_gmt =
false)
3843 if ((abs($ts) <= 0x7FFFFFFF)) {
3846 return 'Error date outside supported range';
3872function dol_print_date($time, $format =
'', $tzoutput =
'auto', $outputlangs =
null, $encodetooutput =
false, $decorate = 0)
3874 global $conf, $langs;
3881 if ($tzoutput ===
'auto') {
3882 $tzoutput = (empty($conf) ?
'tzserver' : (isset($conf->tzuserinputkey) ? $conf->tzuserinputkey :
'tzserver'));
3887 $offsettz = $offsetdst = 0;
3890 if (is_string($tzoutput)) {
3891 if ($tzoutput ==
'tzserver') {
3893 $offsettzstring = @date_default_timezone_get();
3898 } elseif ($tzoutput ==
'tzuser' || $tzoutput ==
'tzuserrel') {
3901 $offsettzstring = (empty($_SESSION[
'dol_tz_string']) ?
getDolGlobalString(
'MAIN_DOLIBARR_USER_TIMEZONE',
'UTC') : $_SESSION[
'dol_tz_string']);
3903 if (class_exists(
'DateTimeZone')) {
3905 $user_date_tz =
new DateTimeZone($offsettzstring);
3908 dol_syslog(
"DateInvalidTimeZoneException for timezone string '".$offsettzstring.
"'. Falling back to UTC.", LOG_ERR);
3909 $user_date_tz =
new DateTimeZone(
'UTC');
3911 $user_dt =
new DateTime();
3912 $user_dt->setTimezone($user_date_tz);
3913 $user_dt->setTimestamp($tzoutput ==
'tzuser' ?
dol_now() : (int) $time);
3914 $offsettz = $user_dt->getOffset();
3916 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
3917 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
3922 if (!is_object($outputlangs)) {
3923 $outputlangs = $langs;
3926 $format =
'daytextshort';
3931 $reduceformat = (!empty($conf->dol_optimize_smallscreen) && in_array($format, array(
'day',
'dayhour',
'dayhoursec'))) ? 1 : 0;
3932 $format = preg_replace(
'/inputnoreduce/',
'', $format);
3933 $formatwithoutreduce = preg_replace(
'/reduceformat/',
'', $format);
3934 if ($formatwithoutreduce != $format) {
3935 $format = $formatwithoutreduce;
3941 if ($format ==
'day') {
3942 $format = ($outputlangs->trans(
"FormatDateShort") !=
"FormatDateShort" ? $outputlangs->trans(
"FormatDateShort") : $conf->format_date_short);
3943 } elseif ($format ==
'hour') {
3944 $format = ($outputlangs->trans(
"FormatHourShort") !=
"FormatHourShort" ? $outputlangs->trans(
"FormatHourShort") : $conf->format_hour_short);
3945 } elseif ($format ==
'hourduration') {
3946 $format = ($outputlangs->trans(
"FormatHourShortDuration") !=
"FormatHourShortDuration" ? $outputlangs->trans(
"FormatHourShortDuration") : $conf->format_hour_short_duration);
3947 } elseif ($format ==
'daytext') {
3948 $format = ($outputlangs->trans(
"FormatDateText") !=
"FormatDateText" ? $outputlangs->trans(
"FormatDateText") : $conf->format_date_text);
3949 } elseif ($format ==
'daytextshort') {
3950 $format = ($outputlangs->trans(
"FormatDateTextShort") !=
"FormatDateTextShort" ? $outputlangs->trans(
"FormatDateTextShort") : $conf->format_date_text_short);
3951 } elseif ($format ==
'dayhour') {
3952 $format = ($outputlangs->trans(
"FormatDateHourShort") !=
"FormatDateHourShort" ? $outputlangs->trans(
"FormatDateHourShort") : $conf->format_date_hour_short);
3953 } elseif ($format ==
'dayhoursec') {
3954 $format = ($outputlangs->trans(
"FormatDateHourSecShort") !=
"FormatDateHourSecShort" ? $outputlangs->trans(
"FormatDateHourSecShort") : $conf->format_date_hour_sec_short);
3955 } elseif ($format ==
'dayhourtext') {
3956 $format = ($outputlangs->trans(
"FormatDateHourText") !=
"FormatDateHourText" ? $outputlangs->trans(
"FormatDateHourText") : $conf->format_date_hour_text);
3957 } elseif ($format ==
'dayhourtextshort') {
3958 $format = ($outputlangs->trans(
"FormatDateHourTextShort") !=
"FormatDateHourTextShort" ? $outputlangs->trans(
"FormatDateHourTextShort") : $conf->format_date_hour_text_short);
3959 } elseif ($format ==
'dayhourlog') {
3961 $format =
'%Y%m%d%H%M%S';
3962 } elseif ($format ==
'dayhourlogsmall') {
3964 $format =
'%y%m%d%H%M';
3965 } elseif ($format ==
'dayhourldap') {
3966 $format =
'%Y%m%d%H%M%SZ';
3967 } elseif ($format ==
'dayhourxcard') {
3968 $format =
'%Y%m%dT%H%M%SZ';
3969 } elseif ($format ==
'dayxcard') {
3971 } elseif ($format ==
'dayrfc') {
3972 $format =
'%Y-%m-%d';
3973 } elseif ($format ==
'dayhourrfc') {
3974 $format =
'%Y-%m-%dT%H:%M:%SZ';
3975 } elseif ($format ==
'standard') {
3976 $format =
'%Y-%m-%d %H:%M:%S';
3979 if ($reduceformat) {
3980 $format = str_replace(
'%Y',
'%y', $format);
3981 $format = str_replace(
'yyyy',
'yy', $format);
3985 if (preg_match(
'/%b/i', $format)) {
3987 $format = str_replace(
'%b',
'__b__', $format);
3988 $format = str_replace(
'%B',
'__B__', $format);
3990 if (preg_match(
'/%a/i', $format)) {
3992 $format = str_replace(
'%a',
'__a__', $format);
3993 $format = str_replace(
'%A',
'__A__', $format);
3998 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)) {
4001 } elseif (preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', (
string) $time, $reg)) {
4005 $syear = (!empty($reg[1]) ? $reg[1] :
'');
4006 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
4007 $sday = (!empty($reg[3]) ? $reg[3] :
'');
4008 $shour = (!empty($reg[4]) ? $reg[4] :
'');
4009 $smin = (!empty($reg[5]) ? $reg[5] :
'');
4010 $ssec = (!empty($reg[6]) ? $reg[6] :
'');
4012 $time =
dol_mktime((
int) $shour, (
int) $smin, (
int) $ssec, (
int) $smonth, (
int) $sday, (
int) $syear,
true);
4015 $tzo =
new DateTimeZone(
'UTC');
4017 $tzo =
new DateTimeZone(date_default_timezone_get());
4019 $dtts =
new DateTime();
4020 $dtts->setTimestamp($time);
4021 $dtts->setTimezone($tzo);
4022 $newformat = str_replace(
4023 array(
'%Y',
'%y',
'%m',
'%d',
'%H',
'%I',
'%M',
'%S',
'%p',
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
4024 array(
'Y',
'y',
'm',
'd',
'H',
'h',
'i',
's',
'A',
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
4027 $ret = $dtts->format($newformat);
4029 array(
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
4030 array(
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
4035 if ($time < 100000000000) {
4036 $dtts =
new DateTime();
4039 $timetouse = (int) $time + $offsettz + $offsetdst;
4041 $tzo =
new DateTimeZone(
'UTC');
4042 $dtts->setTimezone($tzo);
4043 $dtts->setTimestamp($timetouse);
4045 $timetouse = (int) $time + $offsettz + $offsetdst;
4047 $tzo =
new DateTimeZone(date_default_timezone_get());
4048 $dtts->setTimestamp($timetouse);
4049 $dtts->setTimezone($tzo);
4052 $newformat = str_replace(
4053 array(
'%Y',
'%y',
'%m',
'%d',
'%H',
'%I',
'%M',
'%S',
'%p',
'%w',
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
4054 array(
'Y',
'y',
'm',
'd',
'H',
'h',
'i',
's',
'A',
'w',
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
4058 $ret = $dtts->format($newformat);
4061 array(
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
4062 array(
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
4066 $ret =
'Bad value ' . $time .
' for date';
4070 if (preg_match(
'/__b__/i', $format)) {
4071 $timetouse = $time + $offsettz + $offsetdst;
4074 $tzo =
new DateTimeZone(
'UTC');
4076 $tzo =
new DateTimeZone(date_default_timezone_get());
4078 $dtts =
new DateTime();
4079 $dtts->setTimestamp($timetouse);
4080 $dtts->setTimezone($tzo);
4081 $month = (int) $dtts->format(
"m");
4082 $month = sprintf(
"%02d", $month);
4083 if ($encodetooutput) {
4084 $monthtext = $outputlangs->transnoentities(
'Month' . $month);
4085 $monthtextshort = $outputlangs->transnoentities(
'MonthShort' . $month);
4087 $monthtext = $outputlangs->transnoentitiesnoconv(
'Month' . $month);
4088 $monthtextshort = $outputlangs->transnoentitiesnoconv(
'MonthShort' . $month);
4091 $ret = str_replace(
'__b__', $monthtextshort, $ret);
4092 $ret = str_replace(
'__B__', $monthtext, $ret);
4096 if (preg_match(
'/__a__/i', $format)) {
4098 $timetouse = $time + $offsettz + $offsetdst;
4101 $tzo =
new DateTimeZone(
'UTC');
4103 $tzo =
new DateTimeZone(date_default_timezone_get());
4105 $dtts =
new DateTime();
4106 $dtts->setTimestamp($timetouse);
4107 $dtts->setTimezone($tzo);
4108 $w = $dtts->format(
"w");
4109 $dayweek = $outputlangs->transnoentitiesnoconv(
'Day' . $w);
4111 $ret = str_replace(
'__A__', $dayweek, $ret);
4112 $ret = str_replace(
'__a__',
dol_substr($dayweek, 0, 3), $ret);
4116 $ret = preg_replace(
'/(\d\d:\d\d [AP]M)$/',
'<span class="'.($decorate === 1 ?
'opacitymedium' : $decorate).
'">\1</span>', $ret);
4117 $ret = preg_replace(
'/(\d\d:\d\d)$/',
'<span class="'.($decorate === 1 ?
'opacitymedium' : $decorate).
'">\1</span>', $ret);
4144function dol_getdate($timestamp, $fast =
false, $forcetimezone =
'')
4146 if ($timestamp ===
'') {
4150 $datetimeobj =
new DateTime();
4151 $datetimeobj->setTimestamp($timestamp);
4152 if ($forcetimezone) {
4153 $datetimeobj->setTimezone(
new DateTimeZone($forcetimezone ==
'gmt' ?
'UTC' : $forcetimezone));
4156 'year' => ((
int) date_format($datetimeobj,
'Y')),
4157 'mon' => ((
int) date_format($datetimeobj,
'm')),
4158 'mday' => ((
int) date_format($datetimeobj,
'd')),
4159 'wday' => ((
int) date_format($datetimeobj,
'w')),
4160 'yday' => ((
int) date_format($datetimeobj,
'z')),
4161 'hours' => ((
int) date_format($datetimeobj,
'H')),
4162 'minutes' => ((
int) date_format($datetimeobj,
'i')),
4163 'seconds' => ((
int) date_format($datetimeobj,
's')),
4191function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm =
'auto', $check = 1)
4196 if ($gm ===
'auto') {
4197 $gm = (empty($conf) ?
'tzserver' : $conf->tzuserinputkey);
4202 if ($hour == -1 || empty($hour)) {
4205 if ($minute == -1 || empty($minute)) {
4208 if ($second == -1 || empty($second)) {
4214 if (!$month || !$day) {
4223 if ($hour < 0 || $hour > 24) {
4226 if ($minute < 0 || $minute > 60) {
4229 if ($second < 0 || $second > 60) {
4234 if (empty($gm) || ($gm ===
'server' || $gm ===
'tzserver')) {
4235 $default_timezone = @date_default_timezone_get();
4236 $localtz =
new DateTimeZone($default_timezone);
4237 } elseif ($gm ===
'user' || $gm ===
'tzuser' || $gm ===
'tzuserrel') {
4239 $default_timezone = (empty($_SESSION[
"dol_tz_string"]) ? @date_default_timezone_get() : $_SESSION[
"dol_tz_string"]);
4241 $localtz =
new DateTimeZone($default_timezone);
4243 dol_syslog(
"Warning dol_tz_string contains an invalid value " . json_encode($_SESSION[
"dol_tz_string"] ??
null), LOG_WARNING);
4244 $default_timezone = @date_default_timezone_get();
4246 } elseif (strrpos($gm,
"tz,") !==
false) {
4247 $timezone = str_replace(
"tz,",
"", $gm);
4249 $localtz =
new DateTimeZone($timezone);
4251 dol_syslog(
"Warning passed timezone contains an invalid value " . $timezone, LOG_WARNING);
4255 if (empty($localtz)) {
4256 $localtz =
new DateTimeZone(
'UTC');
4258 $dt =
new DateTime(
'now', $localtz);
4259 $dt->setDate((
int) $year, (
int) $month, (
int) $day);
4260 $dt->setTime((
int) $hour, (
int) $minute, (
int) $second);
4261 $date = $dt->getTimestamp();
4277function dol_now($mode =
'gmt')
4281 if ($mode ===
'auto') {
4285 if ($mode ==
'gmt') {
4287 } elseif ($mode ==
'tzserver') {
4288 require_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
4290 $ret = (int) (
dol_now(
'gmt') + ($tzsecond * 3600));
4295 } elseif ($mode ==
'tzuser' || $mode ==
'tzuserrel') {
4298 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
4299 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
4300 $ret = (int) (
dol_now(
'gmt') + ($offsettz + $offsetdst));
4317 global $conf, $langs;
4320 if (!empty($conf->dol_optimize_smallscreen)) {
4325 if (empty($shortvalue) || $size < ($level * 10)) {
4327 $textunitshort = $langs->trans(
"b");
4328 $textunitlong = $langs->trans(
"Bytes");
4330 $ret = round($size / $level, 0);
4331 $textunitshort = $langs->trans(
"Kb");
4332 $textunitlong = $langs->trans(
"KiloBytes");
4335 if (empty($shortunit)) {
4336 $ret .=
' ' . $textunitlong;
4338 $ret .=
' ' . $textunitshort;
4354function dol_print_url($url, $target =
'_blank', $max = 32, $withpicto = 0, $morecss =
'')
4362 $linkstart =
'<a href="';
4363 if (!preg_match(
'/^http/i', $url)) {
4364 $linkstart .=
'http://';
4369 $linkstart .=
' target="' . $target .
'"';
4371 $linkstart .=
' title="' . $langs->trans(
"URL") .
': ' . $url .
'"';
4375 if (!preg_match(
'/^http/i', $url)) {
4382 if ($morecss ==
'float') {
4383 return '<div class="nospan' . ($morecss ?
' ' . $morecss :
'') .
'" style="margin-right: 10px">' . ($withpicto ?
img_picto($langs->trans(
"Url"),
'globe',
'class="paddingrightonly"') :
'') . $link .
'</div>';
4385 return $linkstart .
'<span class="nospan' . ($morecss ?
' ' . $morecss :
'') .
'" style="margin-right: 10px">' . ($withpicto ?
img_picto(
'',
'globe',
'class="paddingrightonly"') :
'') . $link .
'</span>' . $linkend;
4402function dol_print_email($email, $contactid = 0, $socid = 0, $addlink = 0, $max = 0, $showinvalid = 1, $withpicto = 0, $morecss =
'paddingrightonly')
4404 global $user, $langs, $hookmanager;
4415 if (empty($email)) {
4419 if ($addlink == 1) {
4420 $newemail =
'<a class="' . ($morecss ? $morecss :
'') .
'" style="text-overflow: ellipsis;" href="';
4421 if (!preg_match(
'/^mailto:/i', $email)) {
4422 $newemail .=
'mailto:';
4424 $newemail .= $email;
4425 $newemail .=
'" target="_blank">';
4427 $newemail .= ($withpicto ?
img_picto($langs->trans(
"EMail") .
' : ' . $email, (is_numeric($withpicto) ?
'email' : $withpicto),
'class="paddingrightonly"') :
'');
4432 $newemail .= $email;
4434 $newemail .=
'</a>';
4437 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
4438 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
4441 $langs->load(
"errors");
4442 $newemail .=
img_warning($langs->transnoentitiesnoconv(
"ErrorBadEMail", $emailonly),
'',
'paddingrightonly');
4444 $langs->load(
"errors");
4445 $newemail .=
img_warning($langs->transnoentitiesnoconv(
"ErrorBadMXDomain", $emailonly),
'',
'paddingrightonly');
4449 if (($contactid || $socid) &&
isModEnabled(
'agenda') && $user->hasRight(
"agenda",
"myactions",
"create")) {
4451 $linktoaddaction =
'';
4453 $linktoaddaction =
'<a href="' . DOL_URL_ROOT .
'/comm/action/card.php?action=create&backtopage=1&actioncode=' . urlencode($type) .
'&contactid=' . ((int) $contactid) .
'&socid=' . ((int) $socid) .
'">' .
img_object($langs->trans(
"AddAction"),
"calendar") .
'</a>';
4455 if ($linktoaddaction) {
4456 $newemail =
'<div>' . $newemail .
' ' . $linktoaddaction .
'</div>';
4459 } elseif ($addlink ===
'thirdparty') {
4460 $tmpnewemail =
'<a class="' . ($morecss ? $morecss :
'') .
'" style="text-overflow: ellipsis;" href="' . DOL_URL_ROOT .
'/societe/card.php?socid=' . $socid .
'&action=presend&mode=init#formmailbeforetitle">';
4461 $tmpnewemail .= ($withpicto ?
img_picto($langs->trans(
"EMail") .
' : ' . $email, (is_numeric($withpicto) ?
'email' : $withpicto),
'class="paddingrightonly"') :
'');
4462 if ($withpicto == 1) {
4463 $tmpnewemail .= $newemail;
4465 $tmpnewemail .=
'</a>';
4467 $newemail = $tmpnewemail;
4469 $newemail = ($withpicto ?
img_picto($langs->trans(
"EMail") .
' : ' . $email, (is_numeric($withpicto) ?
'email' : $withpicto),
'class="paddingrightonly"') :
'') . $newemail;
4472 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
4473 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
4476 $langs->load(
"errors");
4477 $newemail .=
img_warning($langs->transnoentitiesnoconv(
"ErrorBadEMail", $email));
4479 $langs->load(
"errors");
4480 $newemail .=
img_warning($langs->transnoentitiesnoconv(
"ErrorBadMXDomain", $emailonly));
4491 $parameters = array(
'cid' => $contactid,
'socid' => $socid,
'addlink' => $addlink,
'picto' => $withpicto);
4493 $reshook = $hookmanager->executeHooks(
'printEmail', $parameters, $email);
4497 $rep .= $hookmanager->resPrint;
4512 $socialnetworks = array();
4514 require_once DOL_DOCUMENT_ROOT .
'/core/lib/memory.lib.php';
4518 if (!is_null($dataretrieved)) {
4519 $socialnetworks = $dataretrieved;
4521 $sql =
"SELECT rowid, code, label, url, icon, active FROM " . MAIN_DB_PREFIX .
"c_socialnetworks";
4522 $sql .=
" WHERE entity IN (" .
getEntity(
'c_socialnetworks').
")";
4524 $resql = $db->query($sql);
4526 while ($obj = $db->fetch_object($resql)) {
4527 $socialnetworks[$obj->code] = array(
4528 'rowid' => $obj->rowid,
4529 'label' => $obj->label,
4531 'icon' => $obj->icon,
4532 'active' => $obj->active,
4539 return (is_array($socialnetworks) ? $socialnetworks : array());
4554 global $hookmanager, $langs, $user;
4558 if (empty($value)) {
4562 if (!empty($type)) {
4563 $htmllink =
'<div class="divsocialnetwork inline-block valignmiddle">';
4565 $htmllink .=
'<span class="fab pictofixedwidth ' . ($dictsocialnetworks[$type][
'icon'] ? $dictsocialnetworks[$type][
'icon'] :
'fa-link') .
'"></span>';
4566 if ($type ==
'skype') {
4568 $htmllink .=
' <a href="skype:';
4570 $htmllink .=
'?call" alt="' . $langs->trans(
"Call") .
' ' . $value .
'" title="' .
dol_escape_htmltag($langs->trans(
"Call") .
' ' . $value) .
'">';
4571 $htmllink .=
'<img src="' . DOL_URL_ROOT .
'/theme/common/skype_callbutton.png" border="0">';
4572 $htmllink .=
'</a><a href="skype:';
4574 $htmllink .=
'?chat" alt="' . $langs->trans(
"Chat") .
' ' . $value .
'" title="' .
dol_escape_htmltag($langs->trans(
"Chat") .
' ' . $value) .
'">';
4575 $htmllink .=
'<img class="paddingleft" src="' . DOL_URL_ROOT .
'/theme/common/skype_chatbutton.png" border="0">';
4576 $htmllink .=
'</a>';
4577 if (($contactid || $socid) &&
isModEnabled(
'agenda') && $user->hasRight(
'agenda',
'myactions',
'create')) {
4578 $addlink =
'AC_SKYPE';
4581 $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>';
4583 $htmllink .= ($link ?
' ' . $link :
'');
4586 if (!empty($dictsocialnetworks[$type][
'url'])) {
4587 $tmpvirginurl = preg_replace(
'/\/?{socialid}/',
'', $dictsocialnetworks[$type][
'url']);
4588 if ($tmpvirginurl) {
4589 $value = preg_replace(
'/^www\.' . preg_quote($tmpvirginurl,
'/') .
'\/?/',
'', $value);
4590 $value = preg_replace(
'/^' . preg_quote($tmpvirginurl,
'/') .
'\/?/',
'', $value);
4592 $tmpvirginurl3 = preg_replace(
'/^https:\/\//i',
'https://www.', $tmpvirginurl);
4593 if ($tmpvirginurl3) {
4594 $value = preg_replace(
'/^www\.' . preg_quote($tmpvirginurl3,
'/') .
'\/?/',
'', $value);
4595 $value = preg_replace(
'/^' . preg_quote($tmpvirginurl3,
'/') .
'\/?/',
'', $value);
4598 $tmpvirginurl2 = preg_replace(
'/^https?:\/\//i',
'', $tmpvirginurl);
4599 if ($tmpvirginurl2) {
4600 $value = preg_replace(
'/^www\.' . preg_quote($tmpvirginurl2,
'/') .
'\/?/',
'', $value);
4601 $value = preg_replace(
'/^' . preg_quote($tmpvirginurl2,
'/') .
'\/?/',
'', $value);
4604 if (preg_match(
'/^https?:\/\//i', $value)) {
4607 $link = str_replace(
'{socialid}', $value, $dictsocialnetworks[$type][
'url']);
4609 $valuetoshow = $value;
4610 $valuetoshow = preg_replace(
'/https:\/\/www\.(twitter|x|linkedin)\.com\/?/',
'', $valuetoshow);
4611 if (preg_match(
'/^https?:\/\//i', $link)) {
4620 $htmllink .=
'</div>';
4622 $langs->load(
"errors");
4623 $htmllink .=
img_warning($langs->trans(
"ErrorBadSocialNetworkValue", $value));
4627 $parameters = array(
4629 'cid' => $contactid,
4632 'dictsocialnetworks' => $dictsocialnetworks,
4635 $reshook = $hookmanager->executeHooks(
'printSocialNetworks', $parameters);
4639 $htmllink .= $hookmanager->resPrint;
4654function dol_print_profids($profID, $profIDtype, $countrycode =
'', $addcpButton = 1)
4658 if (empty($profID) || empty($profIDtype)) {
4661 if (empty($countrycode)) {
4662 $countrycode =
$mysoc->country_code;
4664 $newProfID = $profID;
4665 $id = substr($profIDtype, -1);
4667 if (strtoupper($countrycode) ==
'FR') {
4673 $newProfID = substr($newProfID, 0, 3) .
' ' . substr($newProfID, 3, 3) .
' ' . substr($newProfID, 6, 3);
4677 $newProfID = substr($newProfID, 0, 3) .
' ' . substr($newProfID, 3, 3) .
' ' . substr($newProfID, 6, 3) .
' ' . substr($newProfID, 9, 5);
4681 $newProfID = substr($newProfID, 0, 2) .
'.' . substr($newProfID, 2, 3);
4683 if ($profIDtype ===
'VAT' &&
dol_strlen($newProfID) == 13) {
4685 $newProfID = substr($newProfID, 0, 4) .
' ' . substr($newProfID, 4, 3) .
' ' . substr($newProfID, 7, 3) .
' ' . substr($newProfID, 10, 3);
4688 if (!empty($addcpButton)) {
4711function dol_print_phone($phone, $countrycode =
'', $contactid = 0, $socid = 0, $addlink =
'', $separ =
" ", $withpicto =
'', $titlealt =
'', $adddivfloat = 0, $morecss =
'paddingright')
4713 global $conf, $user, $langs,
$mysoc, $hookmanager;
4716 $phone = is_null($phone) ?
'' : preg_replace(
"/[\s.-]/",
"", trim($phone));
4717 if (empty($phone)) {
4723 if (empty($countrycode) && is_object(
$mysoc)) {
4724 $countrycode =
$mysoc->country_code;
4728 if (!empty($conf->dol_optimize_smallscreen) && $separ !=
'hidenum') {
4733 $newphonewa = $phone;
4734 if (strtoupper($countrycode) ==
"FR") {
4737 $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);
4739 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 2) . $separ . substr($newphone, 5, 2);
4741 $newphone = substr($newphone, 0, 2) . $separ . substr($newphone, 2, 3) . $separ . substr($newphone, 5, 2) . $separ . substr($newphone, 7, 2);
4743 $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);
4745 $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);
4747 $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);
4749 } elseif (strtoupper($countrycode) ==
"CA") {
4751 $newphone = ($separ !=
'' ?
'(' :
'') . substr($newphone, 0, 3) . ($separ !=
'' ?
')' :
'') . $separ . substr($newphone, 3, 3) . ($separ !=
'' ?
'-' :
'') . substr($newphone, 6, 4);
4753 } elseif (strtoupper($countrycode) ==
"PT") {
4755 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
4757 } elseif (strtoupper($countrycode) ==
"SR") {
4759 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3);
4761 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 4);
4763 } elseif (strtoupper($countrycode) ==
"DE") {
4765 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4) . $separ . substr($newphone, 7, 4) . $separ . substr($newphone, 11, 3);
4767 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 4) . $separ . substr($newphone, 10, 3);
4769 } elseif (strtoupper($countrycode) ==
"ES") {
4771 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
4773 } elseif (strtoupper($countrycode) ==
"BF") {
4775 $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);
4777 } elseif (strtoupper($countrycode) ==
"RO") {
4779 $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);
4781 } elseif (strtoupper($countrycode) ==
"TR") {
4783 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 4);
4785 } elseif (strtoupper($countrycode) ==
"US") {
4787 $newphone = substr($newphone, 0, 2) . $separ . substr($newphone, 2, 3) . $separ . substr($newphone, 5, 3) . $separ . substr($newphone, 8, 4);
4789 } elseif (strtoupper($countrycode) ==
"MX") {
4791 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 2);
4793 $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);
4795 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 4);
4797 } elseif (strtoupper($countrycode) ==
"ML") {
4799 $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);
4801 } elseif (strtoupper($countrycode) ==
"TH") {
4803 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 3);
4805 $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);
4807 } elseif (strtoupper($countrycode) ==
"MU") {
4810 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 2) . $separ . substr($newphone, 9, 2);
4812 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 4) . $separ . substr($newphone, 8, 2) . $separ . substr($newphone, 10, 2);
4814 } elseif (strtoupper($countrycode) ==
"ZA") {
4816 $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);
4818 } elseif (strtoupper($countrycode) ==
"SY") {
4820 $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);
4822 $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);
4824 } elseif (strtoupper($countrycode) ==
"AE") {
4826 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 2);
4828 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
4830 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 4);
4832 } elseif (strtoupper($countrycode) ==
"DZ") {
4834 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
4836 } elseif (strtoupper($countrycode) ==
"BE") {
4838 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 3);
4840 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
4842 } elseif (strtoupper($countrycode) ==
"PF") {
4844 $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);
4846 } elseif (strtoupper($countrycode) ==
"CO") {
4848 $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);
4850 } elseif (strtoupper($countrycode) ==
"JO") {
4852 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 1) . $separ . substr($newphone, 5, 3) . $separ . substr($newphone, 7, 2) . $separ . substr($newphone, 9, 2);
4854 } elseif (strtoupper($countrycode) ==
"JM") {
4856 $newphone = substr($newphone, 0, 5) . $separ . substr($newphone, 5, 3) . $separ . substr($newphone, 8, 4);
4858 } elseif (strtoupper($countrycode) ==
"MG") {
4860 $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);
4862 } elseif (strtoupper($countrycode) ==
"GB") {
4864 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
4866 } elseif (strtoupper($countrycode) ==
"CH") {
4868 $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);
4870 $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);
4872 } elseif (strtoupper($countrycode) ==
"TN") {
4874 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 2) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
4876 } elseif (strtoupper($countrycode) ==
"GF") {
4878 $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);
4880 } elseif (strtoupper($countrycode) ==
"GP") {
4882 $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);
4884 } elseif (strtoupper($countrycode) ==
"MQ") {
4886 $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);
4888 } elseif (strtoupper($countrycode) ==
"IT") {
4890 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
4892 $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);
4894 } elseif (strtoupper($countrycode) ==
"AU") {
4898 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 1) . $separ . substr($newphone, 4, 4) . $separ . substr($newphone, 8, 4);
4900 } elseif (strtoupper($countrycode) ==
"LU") {
4903 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 2) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 2);
4905 $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);
4907 $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);
4909 $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);
4911 } elseif (strtoupper($countrycode) ==
"PE") {
4914 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4);
4916 $newphonewa =
'+51' . $newphone;
4917 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 10, 3);
4919 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 8, 4);
4921 $newphonewa = $newphone;
4922 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 10, 3) . $separ . substr($newphone, 14, 3);
4924 } elseif (strtoupper($countrycode) ==
"IN") {
4926 if ($withpicto ==
'phone') {
4927 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 2) . $separ . substr($newphone, 5, 4) . $separ . substr($newphone, 9, 4);
4929 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 5) . $separ . substr($newphone, 8, 5);
4934 $newphoneastart = $newphoneaend =
'';
4935 if (!empty($addlink)) {
4936 if ($addlink ==
'tel' || $conf->browser->layout ==
'phone' || (
isModEnabled(
'clicktodial') &&
getDolGlobalString(
'CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS'))) {
4937 $newphoneastart =
'<a href="tel:' . urlencode($phone) .
'">';
4938 $newphoneaend .=
'</a>';
4939 } elseif (
isModEnabled(
'clicktodial') && $addlink ==
'AC_TEL') {
4940 if (empty($user->clicktodial_loaded)) {
4941 $user->fetch_clicktodial();
4945 $urlmask =
getDolGlobalString(
'CLICKTODIAL_URL',
'ErrorClickToDialModuleNotConfigured');
4946 if (!empty($user->clicktodial_url)) {
4947 $urlmask = $user->clicktodial_url;
4950 $clicktodial_poste = (!empty($user->clicktodial_poste) ? urlencode($user->clicktodial_poste) :
'');
4951 $clicktodial_login = (!empty($user->clicktodial_login) ? urlencode($user->clicktodial_login) :
'');
4952 $clicktodial_password = (!empty($user->clicktodial_password) ? urlencode($user->clicktodial_password) :
'');
4954 $url = sprintf($urlmask, urlencode($phone), $clicktodial_poste, $clicktodial_login, $clicktodial_password);
4956 $substitarray = array(
4957 '__PHONEFROM__' => $clicktodial_poste,
4958 '__PHONETO__' => urlencode($phone),
4959 '__LOGIN__' => $clicktodial_login,
4960 '__PASS__' => $clicktodial_password
4965 $newphoneastart =
'<a href="' . $url .
'" class="cssforclicktodial">';
4966 $newphoneaend =
'</a>';
4969 $newphoneastart =
'<a href="' . $url .
'"';
4971 $newphoneastart .=
' target="_blank" rel="noopener noreferrer"';
4973 $newphoneastart .=
'>';
4974 $newphoneaend .=
'</a>';
4979 if (
isModEnabled(
'agenda') && $user->hasRight(
"agenda",
"myactions",
"create")) {
4981 $addlinktoagenda =
'';
4982 if ($addlink ==
'AC_FAX') {
4986 $addlinktoagenda =
'<a href="' . DOL_URL_ROOT .
'/comm/action/card.php?action=create&backtopage=' . urlencode($_SERVER[
'REQUEST_URI']) .
'&actioncode=' . $type . ($contactid ?
'&contactid=' . $contactid :
'') . ($socid ?
'&socid=' . $socid :
'') .
'">' .
img_object($langs->trans(
"AddAction"),
"calendar") .
'</a>';
4988 if ($addlinktoagenda) {
4989 $newphone =
'<span>' . $newphone .
' ' . $addlinktoagenda .
'</span>';
4994 if (
getDolGlobalString(
'CONTACT_PHONEMOBILE_SHOW_LINK_TO_WHATSAPP') && $withpicto ==
'mobile') {
4996 $newphone .=
' <a href="https://wa.me/' . $newphonewa .
'" target="_blank"';
4997 $newphone .=
'><span class="paddingright fab fa-whatsapp" style="color:#25D366;" title="WhatsApp"></span></a>';
5000 if (empty($titlealt)) {
5001 $titlealt = ($withpicto ==
'fax' ? $langs->trans(
"Fax") : $langs->trans(
"Phone"));
5006 $parameters = array(
'countrycode' => $countrycode,
'cid' => $contactid,
'socid' => $socid,
'titlealt' => $titlealt,
'picto' => $withpicto);
5007 $reshook = $hookmanager->executeHooks(
'printPhone', $parameters, $phone);
5008 $rep .= $hookmanager->resPrint;
5010 if (empty($reshook)) {
5013 if ($withpicto ==
'fax') {
5014 $picto =
'phoning_fax';
5015 } elseif ($withpicto ==
'phone') {
5017 } elseif ($withpicto ==
'mobile') {
5018 $picto =
'phoning_mobile';
5023 if ($adddivfloat == 1) {
5024 $rep .=
'<div class="nospan float' . ($morecss ?
' ' . $morecss :
'') .
'">';
5025 } elseif (empty($adddivfloat)) {
5026 $rep .=
'<span' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
'>';
5029 $rep .= $newphoneastart;
5030 $rep .= ($withpicto ?
img_picto($titlealt, $picto) :
'');
5031 if ($separ !=
'hidenum') {
5032 $rep .= ($withpicto ?
' ' :
'') . $newphone;
5034 $rep .= $newphoneaend;
5036 if ($adddivfloat == 1) {
5038 } elseif (empty($adddivfloat)) {
5059 if (!isset($conf->cache[
'resolveips'])) {
5060 $conf->cache[
'resolveips'] = array();
5066 if (file_exists(DOL_DOCUMENT_ROOT .
'/theme/common/flags/' . $countrycode .
'.png')) {
5069 $ret .=
'(' . $countrycode .
')';
5077 if (in_array($mode, [0, 2])) {
5080 if (!array_key_exists($ip, $conf->cache[
'resolveips'])) {
5081 $domain = gethostbyaddr($ip);
5082 $conf->cache[
'resolveips'][$ip] = $domain;
5084 $domain = $conf->cache[
'resolveips'][$ip];
5112 $ip = (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']);
5119 if (empty($_SERVER[
'HTTP_X_FORWARDED_FOR']) || preg_match(
'/[^0-9\.\:,\[\]\s]/', $_SERVER[
'HTTP_X_FORWARDED_FOR'])) {
5120 if (empty($_SERVER[
'HTTP_CLIENT_IP']) || preg_match(
'/[^0-9\.\:,\[\]\s]/', $_SERVER[
'HTTP_CLIENT_IP'])) {
5121 if (empty($_SERVER[
"HTTP_CF_CONNECTING_IP"])) {
5122 $ip = (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']);
5124 $ip = $_SERVER[
"HTTP_CF_CONNECTING_IP"];
5127 $ip = preg_replace(
'/,.*$/',
'', $_SERVER[
'HTTP_CLIENT_IP']);
5130 $ip = preg_replace(
'/,.*$/',
'', $_SERVER[
'HTTP_X_FORWARDED_FOR']);
5146 if (isset($_SERVER[
'HTTPS']) && $_SERVER[
'HTTPS'] ==
'on') {
5148 } 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') {
5169 $datafile = $diroffile .
'/' .
getDolGlobalString(
'GEOIPMAXMIND_COUNTRY_DATAFILE_EMBEDDED');
5175 include_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeoip.class.php';
5176 $geoip =
new DolGeoIP(
'country', $datafile);
5178 $countrycode = $geoip->getCountryCodeFromIP($ip);
5185 return $countrycode;
5197 global $conf, $langs, $user;
5206 include_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeoip.class.php';
5207 $geoip =
new DolGeoIP(
'country', $datafile);
5208 $countrycode = $geoip->getCountryCodeFromIP($ip);
5209 $ret = $countrycode;
5228 global $hookmanager;
5234 $parameters = array(
'element' => $element,
'id' =>
$id);
5235 $reshook = $hookmanager->executeHooks(
'printAddress', $parameters, $address);
5236 $out .= $hookmanager->resPrint;
5238 if (empty($reshook)) {
5239 if (empty($charfornl)) {
5240 $out .= nl2br((
string) $address);
5242 $out .= preg_replace(
'/[\r\n]+/', $charfornl, (
string) $address);
5246 $showgmap = $showomap = 0;
5272 $url =
dol_buildpath(
'/google/gmaps.php?mode=' . $element .
'&id=' .
$id, 1);
5273 $out .=
' <a href="' . $url .
'" target="_gmaps"><img id="' . $htmlid .
'" class="valigntextbottom" src="' . DOL_URL_ROOT .
'/theme/common/gmap.png"></a>';
5276 $url =
dol_buildpath(
'/openstreetmap/maps.php?mode=' . $element .
'&id=' .
$id, 1);
5277 $out .=
' <a href="' . $url .
'" target="_gmaps"><img id="' . $htmlid .
'_openstreetmap" class="valigntextbottom" src="' . DOL_URL_ROOT .
'/theme/common/gmap.png"></a>';
5299function isValidEmail($address, $acceptsupervisorkey = 0, $acceptuserkey = 0)
5301 if ($acceptsupervisorkey && $address ==
'__SUPERVISOREMAIL__') {
5304 if ($acceptuserkey && $address ==
'__USER_EMAIL__') {
5307 if (filter_var($address, FILTER_VALIDATE_EMAIL)) {
5325 if (function_exists(
'idn_to_ascii') && function_exists(
'checkdnsrr')) {
5326 if (!checkdnsrr(idn_to_ascii($domain),
'MX')) {
5329 if (function_exists(
'getmxrr')) {
5332 getmxrr(idn_to_ascii($domain), $mxhosts, $weight);
5333 if (count($mxhosts) > 1) {
5336 if (count($mxhosts) == 1 && !in_array((
string) $mxhosts[0], array(
'',
'.'))) {
5373 $tmparray = explode(
' ', $s);
5374 foreach ($tmparray as $tmps) {
5389function dol_strlen($string, $stringencoding =
'UTF-8')
5391 if (is_null($string)) {
5395 if (function_exists(
'mb_strlen')) {
5396 return mb_strlen($string, $stringencoding);
5398 return strlen($string);
5412function dol_substr($string, $start, $length =
null, $stringencoding =
'', $trunconbytes = 0)
5416 if (empty($stringencoding)) {
5417 $stringencoding = (empty($langs) ?
'UTF-8' : $langs->charset_output);
5421 if (empty($trunconbytes)) {
5422 if (function_exists(
'mb_substr')) {
5423 $ret = mb_substr($string, $start, $length, $stringencoding);
5425 $ret = substr($string, $start, $length);
5428 if (function_exists(
'mb_strcut')) {
5429 $ret = mb_strcut($string, $start, $length, $stringencoding);
5431 $ret = substr($string, $start, $length);
5451function dol_trunc($string, $size = 40, $trunc =
'right', $stringencoding =
'UTF-8', $nodot = 0, $display = 0)
5459 if (empty($stringencoding)) {
5460 $stringencoding =
'UTF-8';
5463 if (!empty($conf->dol_optimize_smallscreen) && $conf->dol_optimize_smallscreen == 1 && $display == 1) {
5464 $size = round($size / 3);
5468 if ($trunc ==
'right') {
5470 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
5472 return dol_substr($newstring, 0, $size, $stringencoding) . ($nodot ?
'' :
'…');
5477 } elseif ($trunc ==
'middle') {
5479 if (
dol_strlen($newstring, $stringencoding) > 2 &&
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
5480 $size1 = (int) round($size / 2);
5481 $size2 = (int) round($size / 2);
5482 return dol_substr($newstring, 0, $size1, $stringencoding) .
'…' .
dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size2, $size2, $stringencoding);
5486 } elseif ($trunc ==
'left') {
5488 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
5490 return '…' .
dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size, $size, $stringencoding);
5494 } elseif ($trunc ==
'wrap') {
5496 if (
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
5502 return 'BadParam3CallingDolTrunc';
5516 $type2picto = array(
5517 'varchar' =>
'font',
5520 'int' =>
'sort-numeric-down',
5521 'double' =>
'sort-numeric-down',
5522 'price' =>
'currency',
5523 'pricecy' =>
'multicurrency',
5524 'password' =>
'key',
5525 'boolean' =>
'check-square',
5526 'date' =>
'calendar',
5527 'datetime' =>
'calendar',
5528 'duration' =>
'hourglass',
5534 'sellist' =>
'list',
5535 'stars' =>
'fontawesome_star_fas',
5536 'radio' =>
'check-circle',
5537 'checkbox' =>
'list',
5538 'chkbxlst' =>
'list',
5540 'icon' =>
"question",
5541 'point' =>
"country",
5542 'multipts' =>
'country',
5543 'linestrg' =>
"country",
5544 'polygon' =>
"country",
5545 'separate' =>
'minus'
5548 if (!empty($type2picto[$key])) {
5549 return img_picto(
'', $type2picto[$key],
'class="pictofixedwidth' . ($morecss ?
' ' . $morecss :
'') .
'"');
5552 return img_picto(
'',
'generic',
'class="pictofixedwidth' . ($morecss ?
' ' . $morecss :
'') .
'"');
5579function img_picto($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $srconly = 0, $notitle = 0, $alt =
'', $morecss =
'', $marginleftonlyshort = 2, $allowothertags = array())
5584 $url = DOL_URL_ROOT;
5585 $theme = isset($conf->theme) ? $conf->theme :
null;
5586 $path =
'theme/' . $theme;
5587 if (empty($picto)) {
5592 if ($pictoisfullpath) {
5594 if (!preg_match(
'/(\.png|\.gif|\.svg)$/i', $picto)) {
5597 $fullpathpicto = $picto;
5599 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
5600 $morecss .= ($morecss ?
' ' :
'') . $reg[1];
5601 $moreatt = str_replace(
'class="' . $reg[1] .
'"',
'', $moreatt);
5606 $pictowithouttext = preg_replace(
'/(\.png|\.gif|\.svg)$/',
'', $picto);
5607 $pictowithouttext = str_replace(
'object_',
'', $pictowithouttext);
5608 $pictowithouttext = str_replace(
'_nocolor',
'', $pictowithouttext);
5611 $pictoconvertkey = array(
5612 'facture' =>
'bill',
5613 'shipping' =>
'shipment',
5614 'fichinter' =>
'intervention',
5615 'agenda' =>
'calendar',
5616 'invoice_supplier' =>
'supplier_invoice',
5617 'order_supplier' =>
'supplier_order');
5618 if (in_array($pictowithouttext, array_keys($pictoconvertkey))) {
5619 $pictowithouttext = $pictoconvertkey[$pictowithouttext];
5622 if (strpos($pictowithouttext,
'fontawesome_') === 0 || strpos($pictowithouttext,
'fa-') === 0) {
5624 $pictowithouttext = str_replace(
'fontawesome_',
'', $pictowithouttext);
5625 $pictowithouttext = str_replace(
'fa-',
'', $pictowithouttext);
5628 if ($pictowithouttext ==
'file-o') {
5629 $pictowithouttext =
'file';
5632 $pictowithouttextarray = explode(
'_', $pictowithouttext);
5633 $marginleftonlyshort = 0;
5635 if (!empty($pictowithouttextarray[1])) {
5637 $fakey =
'fa-' . $pictowithouttextarray[0];
5638 $faprefix = empty($pictowithouttextarray[1]) ?
'fas' : $pictowithouttextarray[1];
5639 $facolor = empty($pictowithouttextarray[2]) ?
'' : $pictowithouttextarray[2];
5640 $fasize = empty($pictowithouttextarray[3]) ?
'' : $pictowithouttextarray[3];
5642 $fakey =
'fa-' . $pictowithouttext;
5652 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
5653 $morecss .= ($morecss ?
' ' :
'') . $reg[1];
5654 $moreatt = str_replace(
'class="' . $reg[1] .
'"',
'', $moreatt);
5656 if (preg_match(
'/style="([^"]+)"/', $moreatt, $reg)) {
5657 $morestyle = $reg[1];
5658 $moreatt = str_replace(
'style="' . $reg[1] .
'"',
'', $moreatt);
5660 $moreatt = trim($moreatt);
5662 $enabledisablehtml =
'<span class="' . $faprefix .
' ' . $fakey . ($marginleftonlyshort ? ($marginleftonlyshort == 1 ?
' marginleftonlyshort' :
' marginleftonly') :
'');
5663 $enabledisablehtml .= ($morecss ?
' ' . $morecss :
'') .
'" style="' . ($fasize ? (
'font-size: ' . $fasize .
';') :
'') . ($facolor ? (
' color: ' . $facolor .
';') :
'') . ($morestyle ?
' ' . $morestyle :
'') .
'"' . (($notitle || empty($titlealt)) ?
'' :
' title="' .
dol_escape_htmltag($titlealt) .
'"') . ($moreatt ?
' ' . $moreatt :
'') .
'>';
5664 $enabledisablehtml .=
'</span>';
5666 return $enabledisablehtml;
5669 if (empty($srconly) && !preg_match(
'/[\.\/@]/', $picto)) {
5670 $fakey = $pictowithouttext;
5674 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'))) {
5677 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'))) {
5683 if ($pictowithouttext ==
'off') {
5684 $fakey =
'fa-square';
5686 } elseif ($pictowithouttext ==
'on') {
5687 $fakey =
'fa-check-square';
5689 } elseif ($pictowithouttext ==
'listlight') {
5690 $fakey =
'fa-download';
5691 $marginleftonlyshort = 1;
5692 } elseif ($pictowithouttext ==
'printer') {
5693 $fakey =
'fa-print';
5695 } elseif ($pictowithouttext ==
'note') {
5696 $fakey =
'fa-sticky-note';
5697 $marginleftonlyshort = 1;
5698 } elseif (in_array($pictowithouttext, array(
'1uparrow',
'1downarrow',
'1leftarrow',
'1rightarrow',
'1uparrow_selected',
'1downarrow_selected',
'1leftarrow_selected',
'1rightarrow_selected'))) {
5699 $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');
5700 $fakey =
'fa-' . $convertarray[$pictowithouttext];
5701 if (preg_match(
'/selected/', $pictowithouttext)) {
5704 $marginleftonlyshort = 1;
5705 } elseif (!empty($arrayconvpictotofa[$pictowithouttext])) {
5706 $fakey =
'fa-' . $arrayconvpictotofa[$pictowithouttext];
5708 $fakey =
'fa-' . $pictowithouttext;
5711 if (in_array($pictowithouttext, array(
'dollyrevert',
'member',
'members',
'contract',
'group',
'resource',
'shipment',
'reception'))) {
5712 $morecss .=
' em092';
5714 if (in_array($pictowithouttext, array(
'conferenceorbooth',
'eventorganization',
'holiday',
'info',
'info_black',
'project',
'workstation'))) {
5715 $morecss .=
' em088';
5717 if (in_array($pictowithouttext, array(
'asset',
'intervention',
'payment',
'loan',
'partnership',
'stock',
'technic'))) {
5718 $morecss .=
' em080';
5722 $arrayconvpictotomarginleftonly = array(
5752 '1uparrow_selected',
5753 '1downarrow_selected',
5754 '1leftarrow_selected',
5755 '1rightarrow_selected'
5757 if (!array_key_exists($pictowithouttext, $arrayconvpictotomarginleftonly)) {
5758 $marginleftonlyshort = 0;
5762 $arrayconvpictotomorcess = array(
5763 'action' =>
'infobox-action',
5764 'account' =>
'infobox-bank_account',
5765 'accounting_account' =>
'infobox-bank_account',
5766 'accountline' =>
'infobox-bank_account',
5767 'accountancy' =>
'infobox-bank_account',
5768 'admin' =>
'opacitymedium',
5769 'asset' =>
'infobox-bank_account',
5770 'bank_account' =>
'infobox-bank_account',
5771 'bill' =>
'infobox-commande',
5772 'billa' =>
'infobox-commande',
5773 'billr' =>
'infobox-commande',
5774 'billd' =>
'infobox-commande',
5775 'bookcal' =>
'infobox-portal',
5776 'margin' =>
'infobox-bank_account',
5777 'conferenceorbooth' =>
'infobox-project',
5778 'cash-register' =>
'infobox-portal',
5779 'contract' =>
'infobox-contrat',
5780 'check' =>
'font-status4',
5781 'conversation' =>
'infobox-contrat',
5782 'donation' =>
'infobox-commande',
5783 'dolly' =>
'infobox-commande',
5784 'dollyrevert' =>
'flip infobox-order_supplier',
5785 'ecm' =>
'infobox-action',
5786 'eventorganization' =>
'infobox-project',
5787 'hrm' =>
'infobox-adherent',
5788 'group' =>
'infobox-adherent',
5789 'intervention' =>
'infobox-contrat',
5790 'incoterm' =>
'infobox-supplier_proposal',
5791 'intracommreport' =>
'infobox-bank_account',
5792 'currency' =>
'infobox-bank_account',
5793 'multicurrency' =>
'infobox-bank_account',
5794 'members' =>
'infobox-adherent',
5795 'member' =>
'infobox-adherent',
5796 'money-bill-alt' =>
'infobox-bank_account',
5797 'order' =>
'infobox-commande',
5798 'user' =>
'infobox-adherent',
5799 'users' =>
'infobox-adherent',
5800 'error' =>
'pictoerror',
5801 'warning' =>
'pictowarning',
5802 'switch_on' =>
'font-status4',
5803 'switch_on_warning' =>
'font-status4 warning',
5804 'switch_on_red' =>
'font-status8',
5805 'switch_off_warning' =>
'font-status4 warning',
5806 'switch_off_red' =>
'font-status8',
5807 'holiday' =>
'infobox-holiday',
5808 'info' =>
'opacityhigh',
5809 'info_black' =>
'purple',
5810 'invoice' =>
'infobox-commande',
5811 'knowledgemanagement' =>
'infobox-contrat rotate90',
5812 'loan' =>
'infobox-commande',
5813 'payment' =>
'infobox-bank_account',
5814 'payment_vat' =>
'infobox-bank_account',
5815 'poll' =>
'infobox-portal',
5816 'pos' =>
'infobox-bank_account',
5817 'project' =>
'infobox-project',
5818 'projecttask' =>
'infobox-project',
5819 'propal' =>
'infobox-propal',
5820 'proposal' =>
'infobox-propal',
5821 'private' =>
'infobox-project',
5822 'reception' =>
'flip infobox-order_supplier',
5823 'recruitmentjobposition' =>
'infobox-adherent',
5824 'recruitmentcandidature' =>
'infobox-adherent',
5825 'resource' =>
'infobox-action',
5826 'salary' =>
'infobox-commande',
5827 'shapes' =>
'infobox-adherent',
5828 'shipment' =>
'infobox-commande',
5829 'store' =>
'infobox-portal',
5830 'stripe' =>
'infobox-bank_account',
5831 'supplier_invoice' =>
'infobox-order_supplier',
5832 'supplier_invoicea' =>
'infobox-order_supplier',
5833 'supplier_invoiced' =>
'infobox-order_supplier',
5834 'supplier' =>
'infobox-order_supplier',
5835 'supplier_order' =>
'infobox-order_supplier',
5836 'supplier_proposal' =>
'infobox-supplier_proposal',
5837 'ticket' =>
'infobox-contrat',
5838 'title_accountancy' =>
'infobox-bank_account',
5839 'title_hrm' =>
'infobox-holiday',
5840 'expensereport' =>
'infobox-expensereport',
5841 'trip' =>
'infobox-expensereport',
5842 'title_agenda' =>
'infobox-action',
5843 'vat' =>
'infobox-bank_account',
5844 'webportal' =>
'infobox-portal',
5846 'list-alt' =>
'imgforviewmode',
5847 'calendar' =>
'imgforviewmode',
5848 'calendarweek' =>
'imgforviewmode',
5849 'calendarmonth' =>
'imgforviewmode',
5850 'calendarday' =>
'imgforviewmode',
5851 'calendarperuser' =>
'imgforviewmode',
5852 'calendarpertype' =>
'imgforviewmode'
5854 if (!empty($arrayconvpictotomorcess[$pictowithouttext]) && strpos($picto,
'_nocolor') ===
false) {
5855 $morecss .= ($morecss ?
' ' :
'') . $arrayconvpictotomorcess[$pictowithouttext];
5859 $arrayconvpictotocolor = array(
5860 'address' =>
'#6c6aa8',
5861 'building' =>
'#6c6aa8',
5865 'companies' =>
'#6c6aa8',
5866 'company' =>
'#6c6aa8',
5867 'contact' =>
'#6c6aa8',
5869 'dynamicprice' =>
'#a69944',
5874 'listlight' =>
'#999',
5875 'language' =>
'#555',
5879 'map-marker-alt' =>
'#aaa',
5881 'product' =>
'#a69944',
5882 'service' =>
'#a69944',
5883 'inventory' =>
'#a69944',
5884 'stock' =>
'#a69944',
5885 'movement' =>
'#a69944',
5887 'world' =>
'#986c6a',
5888 'partnership' =>
'#6c6aa8',
5889 'playdisabled' =>
'#ccc',
5890 'printer' =>
'#444',
5891 'projectpub' =>
'#986c6a',
5895 'search-plus' =>
'#808080',
5896 'security' =>
'#999',
5898 'stop-circle' =>
'#888',
5900 'superadmin' =>
'#600',
5901 'switch_off' =>
'#999',
5902 'technic' =>
'#999',
5904 'timespent' =>
'#555',
5905 'uncheck' =>
'#800',
5906 'uparrow' =>
'#555',
5907 'user-cog' =>
'#999',
5908 'country' =>
'#aaa',
5909 'globe-americas' =>
'#aaa',
5912 'website' =>
'#304',
5913 'workstation' =>
'#a69944'
5915 if (isset($arrayconvpictotocolor[$pictowithouttext]) && strpos($picto,
'_nocolor') ===
false) {
5916 $facolor = $arrayconvpictotocolor[$pictowithouttext];
5923 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
5924 $morecss .= ($morecss ?
' ' :
'') . $reg[1];
5925 $moreatt = str_replace(
'class="' . $reg[1] .
'"',
'', $moreatt);
5927 if (preg_match(
'/style="([^"]+)"/', $moreatt, $reg)) {
5928 $morestyle = $reg[1];
5929 $moreatt = str_replace(
'style="' . $reg[1] .
'"',
'', $moreatt);
5931 $moreatt = trim($moreatt);
5933 $enabledisablehtml =
'<span class="' . $fa .
' ' . $fakey . ($marginleftonlyshort ? ($marginleftonlyshort == 1 ?
' marginleftonlyshort' :
' marginleftonly') :
'');
5934 $enabledisablehtml .= ($morecss ?
' ' . $morecss :
'') .
'" style="' . ($fasize ? (
'font-size: ' . $fasize .
';') :
'') . ($facolor ? (
' color: ' . $facolor .
';') :
'') . ($morestyle ?
' ' . $morestyle :
'') .
'"' . (($notitle || empty($titlealt)) ?
'' :
' title="' .
dol_escape_htmltag($titlealt) .
'"') . ($moreatt ?
' ' . $moreatt :
'') .
'>';
5935 $enabledisablehtml .=
'</span>';
5937 return $enabledisablehtml;
5944 } elseif (!empty($conf->modules_parts[
'theme']) && array_key_exists($theme, $conf->modules_parts[
'theme'])) {
5945 $path = $theme .
'/theme/' . $theme;
5950 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $picto, $regs)) {
5956 if (!preg_match(
'/(\.png|\.gif|\.svg)$/i', $picto)) {
5961 foreach ($conf->file->dol_document_root as $type => $dirroot) {
5962 if ($type ==
'main') {
5966 if (file_exists($dirroot .
'/' . $path .
'/img/' . $picto) && !empty($conf->file->dol_url_root)) {
5967 $url = DOL_URL_ROOT . $conf->file->dol_url_root[$type];
5973 $fullpathpicto = $url .
'/' . $path .
'/img/' . $picto;
5977 return $fullpathpicto;
5981 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 :
'') .
'"') .
'>';
5995 if (empty($mode) || $mode ==
'fa') {
5997 $arrayconvpictotofa = array(
5998 'account' =>
'university',
5999 'accounting_account' =>
'clipboard-list',
6000 'accountline' =>
'receipt',
6001 'accountancy' =>
'search-dollar',
6002 'action' =>
'calendar-alt',
6003 'add' =>
'plus-circle',
6004 'address' =>
'address-book',
6007 'asset' =>
'money-check-alt',
6008 'autofill' =>
'fill',
6009 'back' =>
'arrow-left',
6010 'bank_account' =>
'university',
6011 'bill' =>
'file-invoice-dollar',
6012 'billa' =>
'file-excel',
6013 'billr' =>
'file-invoice-dollar',
6014 'billd' =>
'file-medical',
6015 'blockedlog' =>
'file-archive',
6016 'bookcal' =>
'calendar-check',
6017 'supplier_invoice' =>
'file-invoice-dollar',
6018 'supplier_invoicea' =>
'file-excel',
6019 'supplier_invoicer' =>
'file-invoice-dollar',
6020 'supplier_invoiced' =>
'file-medical',
6022 'card' =>
'address-card',
6023 'chart' =>
'chart-line',
6024 'company' =>
'building',
6025 'contact' =>
'address-book',
6026 'contract' =>
'suitcase',
6027 'collab' =>
'people-arrows',
6028 'conversation' =>
'comments',
6029 'country' =>
'globe-americas',
6030 'cron' =>
'business-time',
6032 'chevron-double-left' =>
'angle-double-left',
6033 'chevron-double-right' =>
'angle-double-right',
6034 'chevron-double-down' =>
'angle-double-down',
6035 'chevron-double-top' =>
'angle-double-up',
6036 'donation' =>
'gift',
6037 'dynamicprice' =>
'hand-holding-usd',
6039 'companies' =>
'building',
6040 'products' =>
'cube',
6041 'commercial' =>
'suitcase',
6042 'invoicing' =>
'coins',
6043 'accounting' =>
'search-dollar',
6044 'category' =>
'tag',
6045 'dollyrevert' =>
'dolly',
6047 'generate' =>
'plus-square',
6048 'hrm' =>
'user-tie',
6049 'incoterm' =>
'truck-loading',
6050 'margin' =>
'calculator',
6051 'members' =>
'user-friends',
6052 'ticket' =>
'ticket-alt',
6053 'globe' =>
'external-link-alt',
6056 'establishment' =>
'building',
6057 'edit' =>
'pencil-alt',
6058 'entity' =>
'globe',
6059 'graph' =>
'chart-line',
6060 'grip_title' =>
'arrows-alt',
6061 'grip' =>
'arrows-alt',
6062 'help' =>
'question-circle',
6063 'generic' =>
'file',
6064 'holiday' =>
'umbrella-beach',
6065 'info' =>
'info-circle',
6066 'info_black' =>
'info-circle',
6067 'inventory' =>
'boxes',
6068 'intracommreport' =>
'globe-europe',
6069 'jobprofile' =>
'cogs',
6070 'knowledgemanagement' =>
'ticket-alt',
6071 'label' =>
'layer-group',
6072 'layout' =>
'columns',
6074 'loan' =>
'money-bill-alt',
6075 'member' =>
'user-alt',
6076 'meeting' =>
'chalkboard-teacher',
6078 'next' =>
'arrow-alt-circle-right',
6080 'expensereport' =>
'wallet',
6082 'movement' =>
'people-carry',
6083 'sign-out' =>
'sign-out-alt',
6084 'superadmin' =>
'star',
6085 'switch_off' =>
'toggle-off',
6086 'switch_off_grey' =>
'toggle-off',
6087 'switch_off_warning' =>
'toggle-off',
6088 'switch_off_red' =>
'toggle-off',
6089 'switch_on' =>
'toggle-on',
6090 'switch_on_grey' =>
'toggle-on',
6091 'switch_on_warning' =>
'toggle-on',
6092 'switch_on_red' =>
'toggle-on',
6094 'bookmark' =>
'star',
6095 'bank' =>
'university',
6096 'close_title' =>
'times',
6097 'delete' =>
'trash',
6098 'filter' =>
'filter',
6099 'list-alt' =>
'list-alt',
6100 'calendarlist' =>
'bars',
6101 'calendar' =>
'calendar-alt',
6102 'calendarmonth' =>
'calendar-alt',
6103 'calendarweek' =>
'calendar-week',
6104 'calendarday' =>
'calendar-day',
6105 'calendarperuser' =>
'table',
6106 'calendarpertype' =>
'table',
6107 'intervention' =>
'ambulance',
6108 'invoice' =>
'file-invoice-dollar',
6109 'order' =>
'file-invoice',
6110 'error' =>
'exclamation-triangle',
6111 'warning' =>
'exclamation-triangle',
6112 'other' =>
'square',
6113 'playdisabled' =>
'play',
6114 'pdf' =>
'file-pdf',
6115 'poll' =>
'check-double',
6116 'pos' =>
'cash-register',
6117 'preview' =>
'binoculars',
6118 'project' =>
'project-diagram',
6119 'projectpub' =>
'project-diagram',
6120 'projecttask' =>
'tasks',
6121 'propal' =>
'file-signature',
6122 'proposal' =>
'file-signature',
6123 'partnership' =>
'handshake',
6124 'payment' =>
'money-check-alt',
6125 'payment_vat' =>
'money-check-alt',
6126 'pictoconfirm' =>
'check-square',
6127 'phoning' =>
'phone',
6128 'phoning_mobile' =>
'mobile-alt',
6129 'phoning_fax' =>
'fax',
6130 'previous' =>
'arrow-alt-circle-left',
6131 'printer' =>
'print',
6132 'product' =>
'cube',
6133 'puce' =>
'angle-right',
6134 'recent' =>
'check-square',
6135 'reception' =>
'dolly',
6136 'recruitmentjobposition' =>
'id-card-alt',
6137 'recruitmentcandidature' =>
'id-badge',
6139 'supplier_order' =>
'dol-order_supplier',
6140 'supplier_proposal' =>
'file-signature',
6141 'refresh' =>
'redo',
6142 'region' =>
'map-marked',
6143 'replacement' =>
'exchange-alt',
6144 'resource' =>
'laptop-house',
6145 'recurring' =>
'history',
6146 'service' =>
'concierge-bell',
6147 'skill' =>
'shapes',
6148 'state' =>
'map-marked-alt',
6149 'security' =>
'key',
6150 'salary' =>
'wallet',
6151 'shipment' =>
'dolly',
6152 'stock' =>
'box-open',
6153 'stats' =>
'chart-bar',
6154 'split' =>
'code-branch',
6155 'status' =>
'stop-circle',
6156 'stripe' =>
'stripe-s',
6157 'supplier' =>
'building',
6158 'technic' =>
'cogs',
6160 'timespent' =>
'clock',
6161 'title_setup' =>
'tools',
6162 'title_accountancy' =>
'money-check-alt',
6163 'title_bank' =>
'university',
6164 'title_hrm' =>
'umbrella-beach',
6165 'title_agenda' =>
'calendar-alt',
6166 'uncheck' =>
'times',
6167 'uparrow' =>
'share',
6168 'url' =>
'external-link-alt',
6169 'vat' =>
'money-check-alt',
6170 'vcard' =>
'arrow-alt-circle-down',
6171 'jabber' =>
'comment',
6172 'website' =>
'globe-americas',
6173 'workstation' =>
'pallet',
6174 'webhook' =>
'bullseye',
6176 'private' =>
'user-lock',
6177 'conferenceorbooth' =>
'chalkboard-teacher',
6178 'eventorganization' =>
'project-diagram',
6179 'webportal' =>
'door-open'
6182 if ($conf->currency ==
'EUR') {
6183 $arrayconvpictotofa[
'currency'] =
'euro-sign';
6184 $arrayconvpictotofa[
'multicurrency'] =
'dollar-sign';
6186 $arrayconvpictotofa[
'currency'] =
'dollar-sign';
6187 $arrayconvpictotofa[
'multicurrency'] =
'euro-sign';
6190 $arrayconvpictotofa = array();
6193 return $arrayconvpictotofa;
6211function img_object($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $srconly = 0, $notitle = 0, $allowothertags = array())
6213 if (strpos($picto,
'^') === 0) {
6214 return img_picto($titlealt, str_replace(
'^',
'', $picto), $moreatt, $pictoisfullpath, $srconly, $notitle,
'',
'', 2, $allowothertags);
6216 return img_picto($titlealt,
'object_' . $picto, $moreatt, $pictoisfullpath, $srconly, $notitle,
'',
'', 2, $allowothertags);
6231function img_weather($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $morecss =
'')
6235 if (is_numeric($picto)) {
6238 return '<i class="fa fa-weather-level' . $picto .
'"></i>';
6239 } elseif (!preg_match(
'/(\.png|\.gif)$/i', $picto)) {
6243 $path = DOL_URL_ROOT .
'/theme/' . $conf->theme .
'/img/weather/' . $picto;
6245 return img_picto($titlealt, $path, $moreatt, 1, 0, 0,
'', $morecss);
6259function img_picto_common($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $notitle = 0)
6263 if (!preg_match(
'/(\.png|\.gif)$/i', $picto)) {
6267 if ($pictoisfullpath) {
6270 $path = DOL_URL_ROOT .
'/theme/common/' . $picto;
6273 $themepath = DOL_DOCUMENT_ROOT .
'/theme/' . $conf->theme .
'/img/' . $picto;
6275 if (file_exists($themepath)) {
6281 return img_picto($titlealt, $path, $moreatt, 1, 0, $notitle);
6297function img_action($titlealt, $numaction, $picto =
'', $moreatt =
'')
6301 if (empty($titlealt) || $titlealt ==
'default') {
6302 if ($numaction ==
'-1' || $numaction ==
'ST_NO') {
6304 $titlealt = $langs->transnoentitiesnoconv(
'ChangeDoNotContact');
6305 } elseif ($numaction ==
'0' || $numaction ==
'ST_NEVER') {
6307 $titlealt = $langs->transnoentitiesnoconv(
'ChangeNeverContacted');
6308 } elseif ($numaction ==
'1' || $numaction ==
'ST_TODO') {
6310 $titlealt = $langs->transnoentitiesnoconv(
'ChangeToContact');
6311 } elseif ($numaction ==
'2' || $numaction ==
'ST_PEND') {
6313 $titlealt = $langs->transnoentitiesnoconv(
'ChangeContactInProcess');
6314 } elseif ($numaction ==
'3' || $numaction ==
'ST_DONE') {
6316 $titlealt = $langs->transnoentitiesnoconv(
'ChangeContactDone');
6318 $titlealt = $langs->transnoentitiesnoconv(
'ChangeStatus ' . $numaction);
6322 if (!is_numeric($numaction)) {
6326 return img_picto($titlealt, (empty($picto) ?
'stcomm' . $numaction .
'.png' : $picto), $moreatt);
6336function img_edit_add($titlealt =
'default', $other =
'')
6340 if ($titlealt ==
'default') {
6341 $titlealt = $langs->trans(
'Add');
6344 return img_picto($titlealt,
'edit_add.png', $other);
6357 if ($titlealt ==
'default') {
6358 $titlealt = $langs->trans(
'Remove');
6361 return img_picto($titlealt,
'edit_remove.png', $other);
6372function img_edit($titlealt =
'default', $float = 0, $other =
'')
6376 if ($titlealt ==
'default') {
6377 $titlealt = $langs->trans(
'Modify');
6380 return img_picto($titlealt,
'edit', ($float ?
'style="float: ' . ($langs->tab_translate[
"DIRECTION"] ==
'rtl' ?
'left' :
'right') .
'"' :
"") . ($other ?
' ' . $other :
''));
6391function img_view($titlealt =
'default', $float = 0, $other =
'class="valignmiddle"')
6395 if ($titlealt ==
'default') {
6396 $titlealt = $langs->trans(
'View');
6399 $moreatt = ($float ?
'style="float: right" ' :
'') . $other;
6401 return img_picto($titlealt,
'eye', $moreatt);
6412function img_delete($titlealt =
'default', $other =
'class="pictodelete"', $morecss =
'')
6416 if ($titlealt ==
'default') {
6417 $titlealt = $langs->trans(
'Delete');
6420 return img_picto($titlealt,
'delete', $other, 0, 0, 0,
'', $morecss);
6430function img_printer($titlealt =
"default", $other =
'')
6433 if ($titlealt ==
"default") {
6434 $titlealt = $langs->trans(
"Print");
6436 return img_picto($titlealt,
'printer', $other);
6446function img_split($titlealt =
'default', $other =
'class="pictosplit"')
6450 if ($titlealt ==
'default') {
6451 $titlealt = $langs->trans(
'Split');
6454 return img_picto($titlealt,
'split', $other);
6464function img_help($usehelpcursor = 1, $usealttitle = 1)
6469 if (is_string($usealttitle)) {
6472 $usealttitle = $langs->trans(
'Info');
6476 return img_picto($usealttitle,
'info',
'style="vertical-align: middle;' . ($usehelpcursor == 1 ?
' cursor: help' : ($usehelpcursor == 2 ?
' cursor: pointer' :
'')) .
'"');
6485function img_info($titlealt =
'default')
6489 if ($titlealt ==
'default') {
6490 $titlealt = $langs->trans(
'Informations');
6493 return img_picto($titlealt,
'info',
'style="vertical-align: middle;"');
6504function img_warning($titlealt =
'default', $moreatt =
'', $morecss =
'pictowarning')
6508 if ($titlealt ==
'default') {
6509 $titlealt = $langs->trans(
'Warning');
6513 return img_picto($titlealt,
'warning',
'class="' . $morecss .
'"' . ($moreatt ? ($moreatt ==
'1' ?
' style="float: right"' :
' ' . $moreatt) :
''));
6522function img_error($titlealt =
'default')
6526 if ($titlealt ==
'default') {
6527 $titlealt = $langs->trans(
'Error');
6540function img_next($titlealt =
'default', $moreatt =
'')
6544 if ($titlealt ==
'default') {
6545 $titlealt = $langs->trans(
'Next');
6549 return '<span class="fa fa-chevron-right paddingright paddingleft" title="' .
dol_escape_htmltag($titlealt) .
'"></span>';
6559function img_previous($titlealt =
'default', $moreatt =
'')
6563 if ($titlealt ==
'default') {
6564 $titlealt = $langs->trans(
'Previous');
6568 return '<span class="fa fa-chevron-left paddingright paddingleft" title="' .
dol_escape_htmltag($titlealt) .
'"></span>';
6579function img_down($titlealt =
'default', $selected = 0, $moreclass =
'')
6583 if ($titlealt ==
'default') {
6584 $titlealt = $langs->trans(
'Down');
6587 return img_picto($titlealt, ($selected ?
'1downarrow_selected' :
'1downarrow'),
'class="imgdown' . ($moreclass ?
" " . $moreclass :
"") .
'"');
6598function img_up($titlealt =
'default', $selected = 0, $moreclass =
'')
6602 if ($titlealt ==
'default') {
6603 $titlealt = $langs->trans(
'Up');
6606 return img_picto($titlealt, ($selected ?
'1uparrow_selected' :
'1uparrow'),
'class="imgup' . ($moreclass ?
" " . $moreclass :
"") .
'"');
6617function img_left($titlealt =
'default', $selected = 0, $moreatt =
'')
6621 if ($titlealt ==
'default') {
6622 $titlealt = $langs->trans(
'Left');
6625 return img_picto($titlealt, ($selected ?
'1leftarrow_selected' :
'1leftarrow'), $moreatt);
6636function img_right($titlealt =
'default', $selected = 0, $moreatt =
'')
6640 if ($titlealt ==
'default') {
6641 $titlealt = $langs->trans(
'Right');
6644 return img_picto($titlealt, ($selected ?
'1rightarrow_selected' :
'1rightarrow'), $moreatt);
6654function img_allow($allow, $titlealt =
'default')
6658 if ($titlealt ==
'default') {
6659 $titlealt = $langs->trans(
'Active');
6676function img_credit_card($brand, $morecss =
'fa-2x inline-block valignmiddle')
6678 if (is_null($morecss)) {
6682 if ($brand ==
'visa' || $brand ==
'Visa') {
6684 } elseif ($brand ==
'mastercard' || $brand ==
'MasterCard') {
6685 $brand =
'cc-mastercard';
6686 } elseif ($brand ==
'amex' || $brand ==
'American Express') {
6688 } elseif ($brand ==
'discover' || $brand ==
'Discover') {
6689 $brand =
'cc-discover';
6690 } elseif ($brand ==
'jcb' || $brand ==
'JCB') {
6692 } elseif ($brand ==
'diners' || $brand ==
'Diners club') {
6693 $brand =
'cc-diners-club';
6694 } elseif (!in_array($brand, array(
'cc-visa',
'cc-mastercard',
'cc-amex',
'cc-discover',
'cc-jcb',
'cc-diners-club'))) {
6695 $brand =
'credit-card';
6698 return '<span class="fa fa-' . $brand .
' fa-fw' . ($morecss ?
' ' . $morecss :
'') .
'"></span>';
6709function img_mime($file, $titlealt =
'', $morecss =
'')
6711 require_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
6717 if (empty($titlealt)) {
6718 $titlealt =
'Mime type: ' . $mimetype;
6722 return '<i class="fa fa-' . $mimefa .
' ' . (preg_match(
'/pictofixedwidth/', $morecss) ?
'' :
'paddingright ') . ($morecss ?
' ' . $morecss :
'') .
'"' . ($titlealt ?
' title="' .
dolPrintHTMLForAttribute($titlealt) .
'"' :
'') .
'></i>';
6733function img_search($titlealt =
'default', $other =
'')
6737 if ($titlealt ==
'default') {
6738 $titlealt = $langs->trans(
'Search');
6741 $img =
img_picto($titlealt,
'search', $other, 0, 1);
6743 $input =
'<input type="image" class="liste_titre" name="button_search" src="' . $img .
'" ';
6760 if ($titlealt ==
'default') {
6761 $titlealt = $langs->trans(
'Search');
6764 $img =
img_picto($titlealt,
'searchclear.png', $other, 0, 1);
6766 $input =
'<input type="image" class="liste_titre" name="button_removefilter" src="' . $img .
'" ';
6784function info_admin($text, $infoonimgalt = 0, $nodiv = 0, $admin =
'1', $morecss =
'hideonsmartphone', $textfordropdown =
'', $picto =
'')
6786 global $conf, $langs;
6788 if ($infoonimgalt) {
6789 $result =
img_picto($text,
'info',
'class="' . ($morecss ?
' ' . $morecss :
'') .
'"');
6791 if (empty($conf->use_javascript_ajax)) {
6792 $textfordropdown =
'';
6795 $class = (empty($admin) ?
'undefined' : ((string) $admin ==
'1' ?
'info' : $admin));
6796 $fa =
'info-circle';
6797 if ($picto ==
'warning') {
6798 $fa =
'exclamation-triangle';
6800 $result = ($nodiv ?
'' :
'<div class="wordbreak ' . $class . ($morecss ?
' ' . $morecss :
'') . ($textfordropdown ?
' hidden' :
'') .
'">');
6801 $result .=
img_picto((
string) $admin ? $langs->trans(
'InfoAdmin') : $langs->trans(
'Note'), $fa);
6804 $result .= ($nodiv ?
'' :
'</div>');
6806 if ($textfordropdown) {
6807 $tmpresult =
'<span class="' . $class .
'text opacitymedium cursorpointer">' . $langs->trans($textfordropdown) .
' ' .
img_picto($langs->trans($textfordropdown),
'1downarrow') .
'</span>';
6808 $tmpresult .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">
6809 jQuery(document).ready(function() {
6810 jQuery(".' . $class .
'text").click(function() {
6811 console.log("toggle text");
6812 jQuery(".' . $class .
'").toggle();
6817 $result = $tmpresult . $result;
6838 global $conf, $langs, $user, $argv;
6839 global $dolibarr_main_prod;
6846 require_once DOL_DOCUMENT_ROOT .
'/core/class/translate.class.php';
6848 $langs->load(
"main");
6852 $langs->loadLangs(array(
'main',
'errors'));
6854 if ($_SERVER[
'DOCUMENT_ROOT']) {
6855 $out .= $langs->trans(
"DolibarrHasDetectedError") .
".<br>\n";
6857 $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";
6859 $out .= $langs->trans(
"InformationToHelpDiagnose") .
":<br>\n";
6861 $out .=
"<b>" . $langs->trans(
"Date") .
":</b> " .
dol_print_date(time(),
'dayhourlog') .
"<br>\n";
6862 $out .=
"<b>" . $langs->trans(
"Dolibarr") .
":</b> " . DOL_VERSION .
" - https://www.dolibarr.org<br>\n";
6863 if (isset($conf->global->MAIN_FEATURES_LEVEL)) {
6864 $out .=
"<b>" . $langs->trans(
"LevelOfFeature") .
":</b> " .
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') .
"<br>\n";
6866 if ($user instanceof
User) {
6867 $out .=
"<b>" . $langs->trans(
"Login") .
":</b> " . $user->login .
"<br>\n";
6869 if (function_exists(
"phpversion")) {
6870 $out .=
"<b>" . $langs->trans(
"PHP") .
":</b> " . phpversion() .
"<br>\n";
6872 $out .=
"<b>" . $langs->trans(
"Server") .
":</b> " . (isset($_SERVER[
"SERVER_SOFTWARE"]) ?
dol_htmlentities($_SERVER[
"SERVER_SOFTWARE"], ENT_COMPAT) :
'') .
"<br>\n";
6873 if (function_exists(
"php_uname")) {
6874 $out .=
"<b>" . $langs->trans(
"OS") .
":</b> " . php_uname() .
"<br>\n";
6876 $out .=
"<b>" . $langs->trans(
"UserAgent") .
":</b> " . (isset($_SERVER[
"HTTP_USER_AGENT"]) ?
dol_htmlentities($_SERVER[
"HTTP_USER_AGENT"], ENT_COMPAT) :
'') .
"<br>\n";
6878 $out .=
"<b>" . $langs->trans(
"RequestedUrl") .
":</b> " . (isset($_SERVER[
"REQUEST_URI"]) ?
dol_htmlentities($_SERVER[
"REQUEST_URI"], ENT_COMPAT) :
'') .
"<br>\n";
6879 $out .=
"<b>" . $langs->trans(
"Referer") .
":</b> " . (isset($_SERVER[
"HTTP_REFERER"]) ?
dol_htmlentities($_SERVER[
"HTTP_REFERER"], ENT_COMPAT) :
'') .
"<br>\n";
6880 $out .=
"<b>" . $langs->trans(
"MenuManager") .
":</b> " . (isset($conf->standard_menu) ?
dol_htmlentities($conf->standard_menu, ENT_COMPAT) :
'') .
"<br>\n";
6882 $syslog .=
"url=" . (isset($_SERVER[
"REQUEST_URI"]) ?
dol_escape_htmltag($_SERVER[
"REQUEST_URI"]) :
'');
6883 $syslog .=
", query_string=" . (isset($_SERVER[
"QUERY_STRING"]) ?
dol_escape_htmltag($_SERVER[
"QUERY_STRING"]) :
'');
6885 $out .=
'> ' . $langs->transnoentities(
"ErrorInternalErrorDetected") .
":\n" . $argv[0] .
"\n";
6889 if (!empty($conf->modules)) {
6890 $out .=
"<b>" . $langs->trans(
"Modules") .
":</b> " . implode(
', ', $conf->modules) .
"<br>\n";
6893 if (is_object($db)) {
6894 if ($_SERVER[
'DOCUMENT_ROOT']) {
6895 $out .=
"<b>" . $langs->trans(
"DatabaseTypeManager") .
":</b> " . $db->type .
"<br>\n";
6896 $lastqueryerror = $db->lastqueryerror();
6898 $lastqueryerror =
"SQL error string is not a valid UTF8 string. We can't show it.";
6900 $out .=
"<b>" . $langs->trans(
"RequestLastAccessInError") .
":</b> " . ($lastqueryerror ?
dol_escape_htmltag($lastqueryerror) : $langs->trans(
"ErrorNoRequestInError")) .
"<br>\n";
6901 $out .=
"<b>" . $langs->trans(
"ReturnCodeLastAccessInError") .
":</b> " . ($db->lasterrno() ?
dol_escape_htmltag($db->lasterrno()) : $langs->trans(
"ErrorNoRequestInError")) .
"<br>\n";
6902 $out .=
"<b>" . $langs->trans(
"InformationLastAccessInError") .
":</b> " . ($db->lasterror() ?
dol_escape_htmltag($db->lasterror()) : $langs->trans(
"ErrorNoRequestInError")) .
"<br>\n";
6906 $out .=
'> ' . $langs->transnoentities(
"DatabaseTypeManager") .
":\n" . $db->type .
"\n";
6907 $out .=
'> ' . $langs->transnoentities(
"RequestLastAccessInError") .
":\n" . ($db->lastqueryerror() ? $db->lastqueryerror() : $langs->transnoentities(
"ErrorNoRequestInError")) .
"\n";
6908 $out .=
'> ' . $langs->transnoentities(
"ReturnCodeLastAccessInError") .
":\n" . ($db->lasterrno() ? $db->lasterrno() : $langs->transnoentities(
"ErrorNoRequestInError")) .
"\n";
6909 $out .=
'> ' . $langs->transnoentities(
"InformationLastAccessInError") .
":\n" . ($db->lasterror() ? $db->lasterror() : $langs->transnoentities(
"ErrorNoRequestInError")) .
"\n";
6911 $syslog .=
", sql=" . $db->lastquery();
6912 $syslog .=
", db_error=" . $db->lasterror();
6915 if ($error || $errors) {
6917 if (is_array($error) && is_array($errors)) {
6918 $errors = array_merge($error, $errors);
6919 } elseif (is_array($error)) {
6921 } elseif (is_array($errors) && !empty($error)) {
6922 $errors = array_merge(array($error), $errors);
6923 } elseif (!empty($error)) {
6924 $errors = array_merge(array($error), array($errors));
6927 $langs->load(
"errors");
6929 foreach ($errors as $msg) {
6933 if ($_SERVER[
'DOCUMENT_ROOT']) {
6934 $out .=
"<b>" . $langs->trans(
"Message") .
":</b> " .
dol_escape_htmltag($msg) .
"<br>\n";
6936 $out .=
'> ' . $langs->transnoentities(
"Message") .
":\n" . $msg .
"\n";
6938 $syslog .=
", msg=" . $msg;
6941 if (empty($dolibarr_main_prod) && $_SERVER[
'DOCUMENT_ROOT'] && function_exists(
'xdebug_print_function_stack') && function_exists(
'xdebug_call_file')) {
6942 xdebug_print_function_stack();
6943 $out .=
'<b>XDebug information:</b>' .
"<br>\n";
6944 $out .=
'File: ' . xdebug_call_file() .
"<br>\n";
6945 $out .=
'Line: ' . xdebug_call_line() .
"<br>\n";
6946 $out .=
'Function: ' . xdebug_call_function() .
"<br>\n";
6951 if (!headers_sent()) {
6952 if (function_exists(
'top_httphead')) {
6956 http_response_code(202);
6959 if (empty($dolibarr_main_prod)) {
6962 if (empty($langs->defaultlang)) {
6963 $langs->setDefaultLang();
6965 $langs->loadLangs(array(
"main",
"errors"));
6967 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";
6968 print $langs->trans(
"DolibarrHasDetectedError") .
'. ';
6969 print $langs->trans(
"YouCanSetOptionDolibarrMainProdToZero");
6970 if (!defined(
"MAIN_CORE_ERROR")) {
6971 define(
"MAIN_CORE_ERROR", 1);
6988function dol_print_error_email($prefixcode, $errormessage =
'', $errormessages = array(), $morecss =
'error', $email =
'')
6992 if (empty($email)) {
6996 $langs->load(
"errors");
6999 print
'<br><div class="center login_main_message"><div class="' . $morecss .
'">';
7000 print $langs->trans(
"ErrorContactEMail", $email, $prefixcode .
'-' .
dol_print_date($now,
'%Y%m%d%H%M%S'));
7001 if ($errormessage) {
7002 print
'<br><br>' . $errormessage;
7004 if (is_array($errormessages) && count($errormessages)) {
7005 foreach ($errormessages as $mesgtoshow) {
7006 print
'<br><br>' . $mesgtoshow;
7009 print
'</div></div>';
7028function print_liste_field_titre($name, $file =
"", $field =
"", $begin =
"", $param =
"", $moreattrib =
"", $sortfield =
"", $sortorder =
"", $prefix =
"", $tooltip =
"", $forcenowrapcolumntitle = 0)
7030 print
getTitleFieldOfList($name, 0, $file, $field, $begin, $param, $moreattrib, $sortfield, $sortorder, $prefix, 0, $tooltip, $forcenowrapcolumntitle);
7051function getTitleFieldOfList($name, $thead = 0, $file =
"", $field =
"", $begin =
"", $moreparam =
"", $moreattrib =
"", $sortfield =
"", $sortorder =
"", $prefix =
"", $disablesortlink = 0, $tooltip =
'', $forcenowrapcolumntitle = 0)
7053 global $langs, $form;
7056 if ($moreattrib ==
'class="right"') {
7057 $prefix .=
'right ';
7060 $tooltip = (string) $tooltip;
7062 $sortorder = strtoupper((
string) $sortorder);
7071 $tmpsortfield = explode(
',', (
string) $sortfield);
7072 $sortfield1 = trim($tmpsortfield[0]);
7073 $tmpfield = explode(
',', $field);
7074 $field1 = trim($tmpfield[0]);
7076 if (strpos((
string) $tooltip,
':') !==
false) {
7077 $tmptooltip = explode(
':', (
string) $tooltip);
7079 $tmptooltip = array($tooltip);
7082 $wrapcolumntitle = (empty($forcenowrapcolumntitle) || (!empty($tmptooltip[2]) && $tmptooltip[2] ==
'-1'));
7084 if (!
getDolGlobalString(
'MAIN_DISABLE_WRAPPING_ON_COLUMN_TITLE') && $wrapcolumntitle) {
7085 $prefix =
'wrapcolumntitle ' . $prefix;
7091 $liste_titre =
'liste_titre';
7092 if ($field1 && ($sortfield1 == $field1 || $sortfield1 == preg_replace(
"/^[^\.]+\./",
"", $field1))) {
7093 $liste_titre =
'liste_titre_sel';
7096 $tagstart =
'<' . $tag .
' class="' . $prefix . $liste_titre .
'" ' . $moreattrib;
7101 if (empty($thead) && $field && empty($disablesortlink)) {
7102 $options = preg_replace(
'/sortfield=([a-zA-Z0-9,\s\.]+)/i',
'', (is_scalar($moreparam) ? $moreparam :
''));
7103 $options = preg_replace(
'/sortorder=([a-zA-Z0-9,\s\.]+)/i',
'', $options);
7104 $options = preg_replace(
'/&+/i',
'&', $options);
7105 if (!preg_match(
'/^&/', $options)) {
7106 $options =
'&' . $options;
7109 $sortordertouseinlink =
'';
7110 if ($field1 != $sortfield1) {
7111 if (preg_match(
'/^DESC/i', $sortorder)) {
7112 $sortordertouseinlink .= str_repeat(
'desc,', count(explode(
',', $field)));
7114 $sortordertouseinlink .= str_repeat(
'asc,', count(explode(
',', $field)));
7117 if (preg_match(
'/^ASC/i', $sortorder)) {
7118 $sortordertouseinlink .= str_repeat(
'desc,', count(explode(
',', $field)));
7120 $sortordertouseinlink .= str_repeat(
'asc,', count(explode(
',', $field)));
7123 $sortordertouseinlink = preg_replace(
'/,$/',
'', $sortordertouseinlink);
7124 $out .=
'<a class="reposition" href="' .
dolBuildUrl($file, [
'sortfield' => $field,
'sortorder' => $sortordertouseinlink,
'begin' => $begin]) . $options .
'"';
7128 if ($tooltip && $tmptooltip[0]) {
7130 $out .= $form->textwithpicto($langs->trans((
string) $name), $langs->trans((
string) $tmptooltip[0]), (empty($tmptooltip[2]) ?
'1' : $tmptooltip[2]),
'help', ((!empty($tmptooltip[2]) && $tmptooltip[2] ==
'-1') ?
'paddingrightonly' :
''), 0, 3, (empty($tmptooltip[1]) ?
'' :
'extra_' . str_replace(
'.',
'_', $field) .
'_' . $tmptooltip[1]));
7132 $out .= $langs->trans((
string) $name);
7135 if (empty($thead) && $field && empty($disablesortlink)) {
7139 if (empty($thead) && $field) {
7140 $options = preg_replace(
'/sortfield=([a-zA-Z0-9,\s\.]+)/i',
'', (is_scalar($moreparam) ? $moreparam :
''));
7141 $options = preg_replace(
'/sortorder=([a-zA-Z0-9,\s\.]+)/i',
'', $options);
7142 $options = preg_replace(
'/&+/i',
'&', $options);
7143 if (!preg_match(
'/^&/', $options)) {
7144 $options =
'&' . $options;
7147 if (!$sortorder || ($field1 != $sortfield1)) {
7150 if (preg_match(
'/^DESC/', $sortorder)) {
7151 $sortimg .=
'<span class="nowrap">' .
img_up(
"Z-A", 0,
'paddingright') .
'</span>';
7153 if (preg_match(
'/^ASC/', $sortorder)) {
7154 $sortimg .=
'<span class="nowrap">' .
img_down(
"A-Z", 0,
'paddingright') .
'</span>';
7159 $tagend =
'</' . $tag .
'>';
7161 $out = $tagstart . $sortimg . $out . $tagend;
7176 dol_syslog(__FUNCTION__ .
" is deprecated", LOG_WARNING);
7178 print
'<div class="titre">' . $title .
'</div>';
7192function print_fiche_titre($title, $mesg =
'', $picto =
'generic', $pictoisfullpath = 0,
$id =
'')
7211function load_fiche_titre($title, $morehtmlright =
'', $picto =
'generic', $pictoisfullpath = 0,
$id =
'', $morecssontable =
'', $morehtmlcenter =
'', $morecssonpicto =
'widthpictotitle')
7215 if ($picto ==
'setup') {
7220 $return .=
'<table ' . (
$id ?
'id="' .
$id .
'" ' :
'') .
'class="centpercent notopnoleftnoright table-fiche-title' . ($morecssontable ?
' ' . $morecssontable :
'') .
'">';
7221 $return .=
'<tr class="toptitle">';
7223 $return .=
'<td class="nobordernopadding widthpictotitle valignmiddle col-picto">' .
img_picto(
'', $picto,
'class="valignmiddle pictotitle'.($morecssonpicto ?
' '.$morecssonpicto :
'').
'"', $pictoisfullpath) .
'</td>';
7225 $return .=
'<td class="nobordernopadding valignmiddle col-title">';
7226 $return .=
'<div class="titre inline-block">';
7227 $return .=
'<span class="inline-block valignmiddle">' . $title .
'</span>';
7228 $return .=
'</div>';
7231 $return .=
'<td class="nobordernopadding center valignmiddle col-center">' . $morehtmlcenter .
'</td>';
7234 $return .=
'<td class="nobordernopadding titre_right wordbreakimp right valignmiddle col-right">' . $morehtmlright .
'</td>';
7236 $return .=
'</tr></table>' .
"\n";
7264function 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 =
'')
7266 global $conf, $langs;
7269 $savtotalnboflines = $totalnboflines;
7270 if (is_numeric($totalnboflines)) {
7271 $totalnboflines = abs($totalnboflines);
7276 $tmparray = preg_split(
'/<br>/i', $title, 2);
7277 if (!empty($tmparray[1])) {
7278 $title = $tmparray[0];
7279 $subtitle = $tmparray[1];
7282 $page = (int) $page;
7284 if ($picto ==
'setup') {
7285 $picto =
'title_setup';
7287 if (($conf->browser->name ==
'ie') && $picto ==
'generic') {
7288 $picto =
'title.gif';
7291 $limit = $conf->liste_limit;
7294 if ($savlimit != 0 && (($num > $limit) || ($num == -1) || ($limit == 0))) {
7302 print
"<!-- Begin print_barre_liste -->\n";
7303 print
'<table class="centpercent notopnoleftnoright table-fiche-title' . ($morecss ?
' ' . $morecss :
'') .
'">';
7304 print
'<tr class="toptitle">';
7308 if ($picto && $title) {
7309 print
'<td class="nobordernopadding widthpictotitle valignmiddle col-picto">';
7310 print
img_picto(
'', $picto,
'class="valignmiddle pictotitle widthpictotitle"', $pictoisfullpath);
7314 print
'<td class="nobordernopadding valignmiddle col-title">';
7315 print
'<div class="titre inline-block">';
7316 print
'<span class="inline-block valignmiddle print-barre-liste">' . $title .
'</span>';
7317 if (!empty($title) && $savtotalnboflines >= 0 && (
string) $savtotalnboflines !=
'' && $totalnboflines > 0) {
7318 print
'<span class="opacitymedium colorblack marginleftonly totalnboflines valignmiddle" title="' . $langs->trans(
"NbRecordQualified") .
'">(' . $totalnboflines .
')</span>';
7321 if (!empty($subtitle)) {
7322 print
'<br><div class="subtitle inline-block hideonsmartphone">' . $subtitle .
'</div>';
7327 if ($morehtmlcenter && empty($conf->dol_optimize_smallscreen)) {
7328 print
'<td class="nobordernopadding center valignmiddle col-center">' . $morehtmlcenter .
'</td>';
7332 print
'<td class="nobordernopadding valignmiddle right col-right">';
7333 print
'<input type="hidden" name="pageplusoneold" value="' . ((int) $page + 1) .
'">';
7335 parse_str($options, $query);
7337 $query += [
'sortfield' => $sortfield];
7340 $query += [
'sortorder' => $sortorder];
7343 $options =
'&' . http_build_query($query);
7345 $query = array_merge($query, [
'page' => $page]);
7349 if ($savlimit != 0 && ($page > 0 || $num > $limit)) {
7350 if ($totalnboflines) {
7352 $maxnbofpage = (empty($conf->dol_optimize_smallscreen) ? 4 : 0);
7355 $nbpages = ceil($totalnboflines / $limit);
7359 $cpt = ($page - $maxnbofpage);
7365 if (empty($pagenavastextinput)) {
7367 $pagelist .=
'<li class="pagination"><a class="reposition" href="' .
dolBuildUrl($file, $query) .
'">1</a></li>';
7369 $pagelist .=
'<li class="pagination"><span class="inactive">...</span></li>';
7370 } elseif ($cpt == 2) {
7372 $pagelist .=
'<li class="pagination"><a class="reposition" href="' .
dolBuildUrl($file, $query) .
'">2</a></li>';
7378 if ($pagenavastextinput) {
7379 if ($cpt == $page) {
7380 $pagelist .=
'<li class="pagination pageplusone valignmiddle"><input type="text" class="' . ($totalnboflines > 100 ?
'width40' :
'width25') .
' center pageplusone heightofcombo" name="pageplusone" value="' . ($page + 1) .
'"></li>';
7384 if ($cpt == $page) {
7385 $pagelist .=
'<li class="pagination"><span class="active">' . ($page + 1) .
'</span></li>';
7387 $query[
'page'] = $cpt;
7388 $pagelist .=
'<li class="pagination"><a class="reposition" href="' .
dolBuildUrl($file, $query) .
'">' . ($cpt + 1) .
'</a></li>';
7392 }
while ($cpt < $nbpages && $cpt <= ($page + $maxnbofpage));
7394 if (empty($pagenavastextinput)) {
7395 if ($cpt < $nbpages) {
7396 if ($cpt < $nbpages - 2) {
7397 $pagelist .=
'<li class="pagination"><span class="inactive">...</span></li>';
7398 } elseif ($cpt == $nbpages - 2) {
7399 $query[
'page'] = ($nbpages - 2);
7400 $pagelist .=
'<li class="pagination"><a class="reposition" href="' .
dolBuildUrl($file, $query) .
'">' . ($nbpages - 1) .
'</a></li>';
7402 $query[
'page'] = ($nbpages - 1);
7403 $pagelist .=
'<li class="pagination"><a class="reposition" href="' .
dolBuildUrl($file, $query) .
'">' . $nbpages .
'</a></li>';
7406 $query[
'page'] = ($nbpages - 1);
7407 $pagelist .=
'<li class="pagination paginationlastpage"><a class="reposition" href="' .
dolBuildUrl($file, $query) .
'">' . $nbpages .
'</a></li>';
7410 $pagelist .=
'<li class="pagination"><span class="active">' . ($page + 1) .
"</li>";
7414 if ($savlimit || $morehtmlright || $morehtmlrightbeforearrow) {
7415 print_fleche_navigation($page, $file, $options, $nextpage, $pagelist, $morehtmlright, $savlimit, $totalnboflines, $selectlimitsuffix, $morehtmlrightbeforearrow, $hidenavigation);
7419 if ($pagenavastextinput) {
7429 if ($morehtmlcenter && !empty($conf->dol_optimize_smallscreen)) {
7430 print
'<div class="nobordernopadding marginbottomonly center valignmiddle col-center centpercent">' . $morehtmlcenter .
'</div>';
7433 print
"<!-- End title -->\n\n";
7452function print_fleche_navigation($page, $file, $options =
'', $nextpage = 0, $betweenarrows =
'', $afterarrows =
'', $limit = -1, $totalnboflines = 0, $selectlimitsuffix =
'', $beforearrows =
'', $hidenavigation = 0)
7454 global $conf, $langs;
7456 print
'<div class="pagination"><ul>';
7457 if ($beforearrows) {
7458 print
'<li class="paginationbeforearrows">';
7459 print $beforearrows;
7463 if (empty($hidenavigation)) {
7464 if ((
int) $limit > 0 && (empty($selectlimitsuffix) || !is_numeric($selectlimitsuffix))) {
7465 $pagesizechoices =
'10:10,15:15,20:20,25:25,50:50,100:100,250:250,500:500,1000:1000';
7466 $pagesizechoices .=
',5000:5000';
7476 print
'<li class="pagination">';
7477 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 .
'">';
7478 print
'<datalist id="limitlist">';
7480 print
'<li class="paginationcombolimit valignmiddle">';
7481 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")) .
'">';
7483 $tmpchoice = explode(
',', $pagesizechoices);
7484 $tmpkey = $limit .
':' . $limit;
7485 if (!in_array($tmpkey, $tmpchoice)) {
7486 $tmpchoice[$tmpkey] = $tmpkey;
7488 $tmpkey = $conf->liste_limit .
':' . $conf->liste_limit;
7489 if (!in_array($tmpkey, $tmpchoice)) {
7490 $tmpchoice[$tmpkey] = $tmpkey;
7492 asort($tmpchoice, SORT_NUMERIC);
7493 foreach ($tmpchoice as $val) {
7495 $tmp = explode(
':', $val);
7498 if ($key !=
'' && $val !=
'') {
7499 if ((
int) $key == (
int) $limit) {
7500 $selected =
' selected="selected"';
7502 print
'<option name="' . $key .
'"' . $selected .
'>' .
dol_escape_htmltag($val) .
'</option>' .
"\n";
7506 print
'</datalist>';
7509 print
ajax_combobox(
"limit" . (is_numeric($selectlimitsuffix) ?
'' : $selectlimitsuffix), array(), 0, 0,
'resolve',
'-1',
'limit');
7513 if ($conf->use_javascript_ajax) {
7514 print
'<!-- JS CODE TO ENABLE select limit to launch submit of page -->
7516 jQuery(document).ready(function () {
7517 jQuery(".selectlimit").change(function() {
7518 console.log("We change limit so we submit the form");
7519 $(this).parents(\'form:first\').submit();
7528 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>';
7530 if ($betweenarrows) {
7531 print
'<!--<div class="betweenarrows nowraponall inline-block">-->';
7532 print $betweenarrows;
7533 print
'<!--</div>-->';
7535 if ($nextpage > 0) {
7536 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>';
7539 print
'<li class="paginationafterarrows">';
7544 print
'</ul></div>' .
"\n";
7559function vatrate($rate, $addpercent =
false, $info_bits = 0, $usestarfornpr = 0, $html = 0)
7563 if (preg_match(
'/%/', $rate)) {
7564 $rate = str_replace(
'%',
'', $rate);
7568 if (preg_match(
'/\((.*)\)/', $rate, $reg)) {
7569 $morelabel =
' (' . $reg[1] .
')';
7570 $rate = preg_replace(
'/\s*' . preg_quote($morelabel,
'/') .
'/',
'', $rate);
7571 $morelabel =
' ' . ($html ?
'<span class="opacitymedium">' :
'') .
'(' . $reg[1] .
')' . ($html ?
'</span>' :
'');
7573 if (preg_match(
'/\*/', $rate)) {
7574 $rate = str_replace(
'*',
'', $rate);
7579 if (!preg_match(
'/\//', $rate)) {
7580 $ret =
price($rate, 0,
'', 0, 0) . ($addpercent ?
'%' :
'');
7583 $ret = $rate . ($addpercent ?
'%' :
'');
7585 if (($info_bits & 1) && $usestarfornpr >= 0) {
7608function price($amount, $form = 0, $outlangs =
'', $trunc = 1, $rounding = -1, $forcerounding = -1, $currency_code =
'')
7610 global $langs, $conf;
7613 if (empty($amount)) {
7616 $amount = (is_numeric($amount) ? $amount : 0);
7617 if ($rounding == -1) {
7620 $nbdecimal = $rounding;
7622 if ($outlangs ===
'none') {
7632 if (!($outlangs instanceof
Translate)) {
7636 if ($outlangs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
7637 $dec = $outlangs->transnoentitiesnoconv(
"SeparatorDecimal");
7639 if ($outlangs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
7640 $thousand = $outlangs->transnoentitiesnoconv(
"SeparatorThousand");
7642 if ($thousand ==
'None') {
7644 } elseif ($thousand ==
'Space') {
7651 $amount = str_replace(
',',
'.', $amount);
7653 $data = explode(
'.', $amount);
7654 $decpart = isset($data[1]) ? $data[1] :
'';
7655 $decpart = preg_replace(
'/0+$/i',
'', $decpart);
7665 $nbdecimalmaxshown = (int) str_replace(
'...',
'',
getDolGlobalString(
'MAIN_MAX_DECIMALS_SHOWN'));
7666 if ($trunc && $nbdecimal > $nbdecimalmaxshown) {
7667 $nbdecimal = $nbdecimalmaxshown;
7675 if ((
string) $forcerounding !=
'-1' && (string) $forcerounding !=
'') {
7676 if ($forcerounding ===
'MU') {
7678 } elseif ($forcerounding ===
'MT') {
7680 } elseif ($forcerounding >= 0) {
7681 $nbdecimal = (int) $forcerounding;
7686 $output = number_format((
float) $amount, $nbdecimal, $dec, $thousand);
7688 $cursymbolbefore = $cursymbolafter =
'';
7689 if ($currency_code && is_object($outlangs)) {
7690 if ($currency_code ==
'auto') {
7691 $currency_code = $conf->currency;
7694 $listofcurrenciesbefore = array(
'AUD',
'CAD',
'CNY',
'COP',
'CLP',
'GBP',
'HKD',
'MXN',
'PEN',
'USD',
'CRC',
'ZAR');
7695 $listoflanguagesbefore = array(
'nl_NL');
7696 if (in_array($currency_code, $listofcurrenciesbefore) || in_array($outlangs->defaultlang, $listoflanguagesbefore)) {
7697 $cursymbolbefore .= $outlangs->getCurrencySymbol($currency_code);
7699 $tmpcur = $outlangs->getCurrencySymbol($currency_code);
7700 $cursymbolafter .= ($tmpcur == $currency_code ?
' ' . $tmpcur : $tmpcur);
7703 $output = $cursymbolbefore . $output . $end . ($cursymbolafter ?
' ' :
'') . $cursymbolafter;
7705 $output = preg_replace(
'/\s/',
' ', $output);
7706 $output = preg_replace(
'/\'/',
''', $output);
7737function price2num($amount, $rounding =
'', $option = 0)
7742 if (is_null($amount)) {
7751 if (is_null($langs)) {
7755 if ($langs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
7756 $dec = $langs->transnoentitiesnoconv(
"SeparatorDecimal");
7758 if ($langs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
7759 $thousand = $langs->transnoentitiesnoconv(
"SeparatorThousand");
7762 if ($thousand ==
'None') {
7764 } elseif ($thousand ==
'Space') {
7772 if (!is_numeric($amount)) {
7773 $amount = preg_replace(
'/[a-zA-Z\/\\\*\(\)<>\_]/',
'', $amount);
7776 if ($option == 2 && $thousand ==
'.' && preg_match(
'/\.(\d\d\d)$/', (
string) $amount)) {
7777 $amount = str_replace($thousand,
'', $amount);
7783 if (is_numeric($amount)) {
7785 $temps = sprintf(
"%10.10F", $amount - intval($amount));
7786 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
7788 $amount = number_format($amount, $nbofdec, $dec, $thousand);
7794 if ($thousand !=
',' && $thousand !=
'.') {
7807 if (preg_match(
'/^(?<int>[^,]*,|[^.]*\.)(?<dec>[^.,]*)$/u', $amount, $matches)) {
7808 $intPart = $matches[
'int'];
7809 $decPart = $matches[
'dec'];
7812 $intPart = str_replace([
'.',
','],
'', $intPart);
7815 $amount = $intPart . $dec . $decPart;
7819 $amount = str_replace(
' ',
'', $amount);
7820 $amount = str_replace($thousand,
'', $amount);
7821 $amount = str_replace($dec,
'.', $amount);
7823 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
7829 $nbofdectoround =
'';
7830 if ($rounding ==
'MU') {
7832 } elseif ($rounding ==
'MT') {
7834 } elseif ($rounding ==
'MS') {
7836 } elseif ($rounding ==
'CU') {
7838 } elseif ($rounding ==
'CT') {
7840 } elseif (is_numeric($rounding)) {
7841 $nbofdectoround = (int) $rounding;
7846 $amount = round(is_string($amount) ? (
float) $amount : $amount, $nbofdectoround);
7848 return 'ErrorBadParameterProvidedToFunction';
7854 if (is_numeric($amount)) {
7856 $temps = sprintf(
"%10.10F", $amount - intval($amount));
7857 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
7859 $amount = number_format($amount, min($nbofdec, $nbofdectoround), $dec, $thousand);
7865 if ($thousand !=
',' && $thousand !=
'.') {
7866 $amount = str_replace(
',',
'.', $amount);
7869 $amount = str_replace(
' ',
'', $amount);
7870 $amount = str_replace($thousand,
'', $amount);
7871 $amount = str_replace($dec,
'.', $amount);
7873 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
7891function showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round = -1, $forceunitoutput =
'no', $use_short_label = 0)
7893 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
7895 if (($forceunitoutput ==
'no' && $dimension < 1 / 10000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == -6)) {
7896 $dimension *= 1000000;
7898 } elseif (($forceunitoutput ==
'no' && $dimension < 1 / 10 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == -3)) {
7901 } elseif (($forceunitoutput ==
'no' && $dimension > 100000000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == 6)) {
7902 $dimension /= 1000000;
7904 } elseif (($forceunitoutput ==
'no' && $dimension > 100000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == 3)) {
7921 $ret =
price($dimension, 0, $outputlangs, 0, 0, $round);
7941function get_localtax($vatrate, $local, $thirdparty_buyer =
null, $thirdparty_seller =
null, $vatnpr = 0)
7943 global $db, $conf,
$mysoc;
7945 if (empty($thirdparty_seller) || !is_object($thirdparty_seller)) {
7946 $thirdparty_seller =
$mysoc;
7949 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);
7951 $vatratecleaned = $vatrate;
7953 if (preg_match(
'/^(.*)\s*\((.*)\)$/', (
string) $vatrate, $reg)) {
7954 $vatratecleaned = trim($reg[1]);
7955 $vatratecode = $reg[2];
7964 if (
$mysoc->country_code ==
'ES') {
7966 if (!
$mysoc->localtax1_assuj || (
string) $vatratecleaned ==
"0") {
7969 if ($thirdparty_seller->id ==
$mysoc->id) {
7970 if (!$thirdparty_buyer->localtax1_assuj) {
7974 if (!$thirdparty_seller->localtax1_assuj) {
7982 if (!
$mysoc->localtax2_assuj) {
7985 if ($thirdparty_seller->id ==
$mysoc->id) {
7986 if (!$thirdparty_buyer->localtax2_assuj) {
7990 if (!$thirdparty_seller->localtax2_assuj) {
7996 if ($local == 1 && !$thirdparty_seller->localtax1_assuj) {
7999 if ($local == 2 && !$thirdparty_seller->localtax2_assuj) {
8005 if (in_array(
$mysoc->country_code, array(
'ES'))) {
8006 $conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY = 1;
8012 if ($thirdparty_seller !=
$mysoc) {
8014 return $thirdparty_seller->localtax1_value;
8023 if ($thirdparty_seller !=
$mysoc) {
8026 return $thirdparty_seller->localtax2_value;
8029 if (in_array(
$mysoc->country_code, array(
'ES'))) {
8030 return $thirdparty_buyer->localtax2_value;
8039 $sql =
"SELECT t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
8040 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t, " . MAIN_DB_PREFIX .
"c_country as c";
8041 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '" . $db->escape($thirdparty_seller->country_code) .
"'";
8042 $sql .=
" AND t.taux = " . ((float) $vatratecleaned) .
" AND t.active = 1";
8043 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
8044 if (!empty($vatratecode)) {
8045 $sql .=
" AND t.code ='" . $db->escape($vatratecode) .
"'";
8047 $sql .=
" AND t.recuperableonly = '" . $db->escape((
string) $vatnpr) .
"'";
8050 $resql = $db->query($sql);
8053 $obj = $db->fetch_object($resql);
8056 return $obj->localtax1;
8057 } elseif ($local == 2) {
8058 return $obj->localtax2;
8079 $valors = explode(
":", $tax);
8081 if (count($valors) > 1) {
8098 $sql =
" SELECT t.localtax" . $local .
" as localtax";
8099 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t INNER JOIN " . MAIN_DB_PREFIX .
"c_country as c ON c.rowid = t.fk_pays";
8100 $sql .=
" WHERE c.code = '" . $db->escape(
$mysoc->country_code) .
"' AND t.active = 1 AND t.entity IN (" .
getEntity(
'c_tva') .
") AND t.taux = (";
8101 $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";
8102 $sql .=
" WHERE c.code = '" . $db->escape(
$mysoc->country_code) .
"' AND t.entity IN (" .
getEntity(
'c_tva') .
") AND tt.active = 1)";
8103 $sql .=
" AND t.localtax" . $local .
"_type <> '0'";
8104 $sql .=
" ORDER BY t.rowid DESC";
8106 $resql = $db->query($sql);
8108 $obj = $db->fetch_object($resql);
8110 return $obj->localtax;
8131function getTaxesFromId($vatrate, $buyer =
null, $seller =
null, $firstparamisid = 1)
8135 dol_syslog(
"getTaxesFromId vat id or rate = " . $vatrate);
8138 $sql =
"SELECT t.rowid, t.code, t.taux as rate, t.recuperableonly as npr, t.accountancy_code_sell, t.accountancy_code_buy,";
8139 $sql .=
" t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type";
8140 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t";
8141 if ($firstparamisid) {
8142 $sql .=
" WHERE t.rowid = " . (int) $vatrate;
8144 $vatratecleaned = $vatrate;
8147 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
8148 $vatratecleaned = $reg[1];
8149 $vatratecode = $reg[2];
8152 $sql .=
", " . MAIN_DB_PREFIX .
"c_country as c";
8155 $sql .=
" WHERE t.fk_pays = c.rowid";
8157 $sql .=
" AND c.code = '" . $db->escape($buyer->country_code) .
"'";
8159 $sql .=
" AND c.code = '" . $db->escape($seller->country_code) .
"'";
8161 $sql .=
" AND t.taux = " . ((float) $vatratecleaned) .
" AND t.active = 1";
8162 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
8164 $sql .=
" AND t.code = '" . $db->escape($vatratecode) .
"'";
8168 $resql = $db->query($sql);
8170 $obj = $db->fetch_object($resql);
8173 'rowid' => $obj->rowid,
8174 'code' => $obj->code,
8175 'rate' => $obj->rate,
8176 'localtax1' => $obj->localtax1,
8177 'localtax1_type' => $obj->localtax1_type,
8178 'localtax2' => $obj->localtax2,
8179 'localtax2_type' => $obj->localtax2_type,
8181 'accountancy_code_sell' => $obj->accountancy_code_sell,
8182 'accountancy_code_buy' => $obj->accountancy_code_buy
8214 dol_syslog(
"getLocalTaxesFromRate vatrate=" . $vatrate .
" local=" . $local);
8217 $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";
8218 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t";
8219 if ($firstparamisid) {
8220 $sql .=
" WHERE t.rowid = " . (int) $vatrate;
8222 $vatratecleaned = $vatrate;
8225 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
8226 $vatratecleaned = $reg[1];
8227 $vatratecode = $reg[2];
8230 $sql .=
", " . MAIN_DB_PREFIX .
"c_country as c";
8232 $countrycodetouse = ((empty($buyer) || empty($buyer->country_code)) ?
$mysoc->country_code : $buyer->country_code);
8233 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '" . $db->escape($countrycodetouse) .
"'";
8235 $countrycodetouse = ((empty($seller) || empty($seller->country_code)) ?
$mysoc->country_code : $seller->country_code);
8236 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '" . $db->escape($countrycodetouse) .
"'";
8238 $sql .=
" AND t.taux = " . ((float) $vatratecleaned) .
" AND t.active = 1";
8240 $sql .=
" AND t.code = '" . $db->escape($vatratecode) .
"'";
8244 $resql = $db->query($sql);
8246 $obj = $db->fetch_object($resql);
8249 $vateratestring = $obj->rate . ($obj->code ?
' (' . $obj->code .
')' :
'');
8252 return array($obj->localtax1_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
8253 } elseif ($local == 2) {
8254 return array($obj->localtax2_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
8256 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);
8278 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
8286 $product->fetch($idprod);
8288 if ((
$mysoc->country_code == $thirdpartytouseforcountry->country_code)
8289 || (in_array(
$mysoc->country_code, array(
'FR',
'MC')) && in_array($thirdpartytouseforcountry->country_code, array(
'FR',
'MC')))
8290 || (in_array(
$mysoc->country_code, array(
'MQ',
'GP')) && in_array($thirdpartytouseforcountry->country_code, array(
'MQ',
'GP')))
8293 if ($idprodfournprice > 0) {
8294 $result = $product->get_buyprice($idprodfournprice, 0, 0,
'');
8296 $ret = $product->vatrate_supplier;
8297 if ($product->default_vat_code_supplier) {
8298 $ret .=
' (' . $product->default_vat_code_supplier .
')';
8304 $ret = $product->tva_tx;
8305 if ($product->default_vat_code) {
8306 $ret .=
' (' . $product->default_vat_code .
')';
8319 $sql =
"SELECT t.taux as vat_rate, t.code as default_vat_code";
8320 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t, " . MAIN_DB_PREFIX .
"c_country as c";
8321 $sql .=
" WHERE t.active = 1 AND t.fk_pays = c.rowid AND c.code = '" . $db->escape($thirdpartytouseforcountry->country_code) .
"'";
8322 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
8323 $sql .=
" ORDER BY t.use_default DESC, t.taux DESC, t.code ASC, t.recuperableonly ASC";
8324 $sql .= $db->plimit(1);
8326 $resql = $db->query($sql);
8328 $obj = $db->fetch_object($resql);
8330 $ret = $obj->vat_rate;
8331 if ($obj->default_vat_code) {
8332 $ret .=
' (' . $obj->default_vat_code .
')';
8356 dol_syslog(
"get_product_vat_for_country: ret=" . $ret);
8374 if (!class_exists(
'Product')) {
8375 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
8384 $result = $product->fetch($idprod);
8386 if (
$mysoc->country_code == $thirdpartytouseforcountry->country_code) {
8400 $sql =
"SELECT taux as vat_rate, localtax1, localtax2";
8401 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t, " . MAIN_DB_PREFIX .
"c_country as c";
8402 $sql .=
" WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code='" . $db->escape($thirdpartytouseforcountry->country_code) .
"'";
8403 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
8404 $sql .=
" ORDER BY t.taux DESC, t.recuperableonly ASC";
8405 $sql .= $db->plimit(1);
8407 $resql = $db->query($sql);
8409 $obj = $db->fetch_object($resql);
8412 $ret = $obj->localtax1;
8413 } elseif ($local == 2) {
8414 $ret = $obj->localtax2;
8422 dol_syslog(
"get_product_localtax_for_country: ret=" . $ret);
8446 global
$mysoc, $db, $hookmanager;
8448 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
8451 $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;
8453 if (empty($thirdparty_seller->country_code)) {
8454 $thirdparty_seller->country_code =
$mysoc->country_code;
8456 $seller_country_code = $thirdparty_seller->country_code;
8457 $seller_in_cee =
isInEEC($thirdparty_seller);
8459 if (empty($thirdparty_buyer->country_code)) {
8460 $thirdparty_buyer->country_code =
$mysoc->country_code;
8462 $buyer_country_code = $thirdparty_buyer->country_code;
8463 $buyer_in_cee =
isInEEC($thirdparty_buyer);
8465 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'));
8473 if ($seller_in_cee && $buyer_in_cee) {
8474 $isacompany = $thirdparty_buyer->
isACompany();
8475 if ($isacompany && !
getDolGlobalString(
'MAIN_USE_VAT_ZERO_FOR_COMPANIES_IN_EEC_EVEN_IF_VAT_ID_UNKNOWN')) {
8476 require_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
8484 $vatrule =
'VATRULE 0';
8490 if (empty($vatrule) && !$seller_use_vat) {
8498 $vatrule =
'VATRULE 1';
8502 if (empty($vatrule) && !empty($thirdparty_buyer->state_id)) {
8503 $sql =
"SELECT d.rowid, t.taux as vat_default_rate, t.code as vat_default_code ";
8504 $sql .=
" FROM " . $db->prefix() .
"c_tva as t";
8505 $sql .=
" INNER JOIN " . $db->prefix() .
"c_departements as d ON t.fk_department_buyer = d.rowid";
8506 $sql .=
" WHERE d.rowid = " . ((int) $thirdparty_buyer->state_id);
8507 $sql .=
" ORDER BY t.use_default DESC, t.taux DESC, t.code ASC, t.recuperableonly ASC";
8509 $res = $db->query($sql);
8511 if ($db->num_rows($res)) {
8512 $obj = $db->fetch_object($res);
8514 $vatvalue = $obj->vat_default_rate .
' (' . $obj->vat_default_code .
')';
8515 $vatrule =
'VATRULE 2';
8522 if (empty($vatrule) && (
8523 ($seller_country_code == $buyer_country_code)
8524 || (in_array($seller_country_code, array(
'FR',
'MC')) && in_array($buyer_country_code, array(
'FR',
'MC')))
8525 || (in_array($seller_country_code, array(
'MQ',
'GP')) && in_array($buyer_country_code, array(
'MQ',
'GP')))
8530 if ($seller_country_code ==
'IN' &&
getDolGlobalString(
'MAIN_SALETAX_AUTOSWITCH_I_CS_FOR_INDIA')) {
8534 if (preg_match(
'/C+S-(\d+)/', $tmpvat, $reg) && $thirdparty_seller->state_id != $thirdparty_buyer->state_id) {
8536 $tmpvat = str_replace(
"C+S",
"I", $tmpvat);
8537 } elseif (preg_match(
'/I-(\d+)/', $tmpvat, $reg) && $thirdparty_seller->state_id == $thirdparty_buyer->state_id) {
8539 $tmpvat = str_replace(
"I",
"C+S", $tmpvat);
8543 $vatvalue = $tmpvat;
8544 $vatrule =
'VATRULE 3b';
8552 if (empty($vatrule) && ($seller_in_cee && $buyer_in_cee)) {
8553 $isacompany = $thirdparty_buyer->
isACompany();
8554 if ($isacompany && !
getDolGlobalString(
'MAIN_USE_VAT_ZERO_FOR_COMPANIES_IN_EEC_EVEN_IF_VAT_ID_UNKNOWN')) {
8555 require_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
8564 $vatrule =
'VATRULE 5';
8571 $vatrule =
'VATRULE 6';
8577 if (empty($vatrule) &&
getDolGlobalString(
'MAIN_USE_VAT_OF_PRODUCT_FOR_INDIVIDUAL_CUSTOMER_OUT_OF_EEC') && empty($buyer_in_cee)) {
8578 $isacompany = $thirdparty_buyer->
isACompany();
8581 $vatrule =
'VATRULE extra';
8594 $parameters = array(
'vatvalue' => $vatvalue,
'vatrule' => $vatrule);
8598 $reshook = $hookmanager->executeHooks(
'get_default_tva', $parameters, $tmpobject, $tmpaction);
8599 if ($reshook > 0 && !empty($hookmanager->resArray[
'vatvalue'])) {
8600 $vatvalue = $hookmanager->resArray[
'vatvalue'];
8601 $vatrule = $hookmanager->resArray[
'vatrule'];
8622 if ($idprodfournprice > 0) {
8623 if (!class_exists(
'ProductFournisseur')) {
8624 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.product.class.php';
8627 $prodprice->fetch_product_fournisseur_price($idprodfournprice);
8628 return $prodprice->fourn_tva_npr;
8629 } elseif ($idprod > 0) {
8630 if (!class_exists(
'Product')) {
8631 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
8634 $prod->fetch($idprod);
8635 return $prod->tva_npr;
8658 if (!is_object($thirdparty_seller)) {
8661 if (!is_object($thirdparty_buyer)) {
8665 if (empty($thirdparty_seller->country_code)) {
8666 $thirdparty_seller->country_code =
$mysoc->country_code;
8668 $seller_country_code = $thirdparty_seller->country_code;
8671 if (empty($thirdparty_buyer->country_code)) {
8672 $thirdparty_buyer->country_code =
$mysoc->country_code;
8674 $buyer_country_code = $thirdparty_buyer->country_code;
8678 if (
$mysoc->country_code ==
'ES') {
8679 if (is_numeric($thirdparty_buyer->localtax1_assuj) && !$thirdparty_buyer->localtax1_assuj) {
8684 if (is_numeric($thirdparty_seller->localtax1_assuj) && !$thirdparty_seller->localtax1_assuj) {
8687 if (!is_numeric($thirdparty_seller->localtax1_assuj) && $thirdparty_seller->localtax1_assuj ==
'localtax1off') {
8691 } elseif ($local == 2) {
8693 if (is_numeric($thirdparty_seller->localtax2_assuj) && !$thirdparty_seller->localtax2_assuj) {
8696 if (!is_numeric($thirdparty_seller->localtax2_assuj) && $thirdparty_seller->localtax2_assuj ==
'localtax2off') {
8701 if ($seller_country_code == $buyer_country_code) {
8716function yn($yesno, $format = 1, $color = 0)
8720 $result =
'unknown';
8722 if ($yesno ===
true || (
int) $yesno == 1 || (isset($yesno) && (strtolower($yesno) ==
'yes' || strtolower($yesno) ==
'true'))) {
8723 $result = $langs->trans(
'yes');
8724 if ($format == 1 || $format == 3) {
8725 $result = $langs->trans(
"Yes");
8728 $result =
'<input type="checkbox" value="1" checked disabled>';
8731 $result =
'<input type="checkbox" value="1" checked disabled> ' . $result;
8733 if ($format == 4 || !is_numeric($format)) {
8734 $result =
img_picto(is_numeric($format) ?
'' : $format,
'check');
8739 $result = $langs->trans(
"no");
8740 if ($format == 1 || $format == 3) {
8741 $result = $langs->trans(
"No");
8744 $result =
'<input type="checkbox" value="0" disabled>';
8747 $result =
'<input type="checkbox" value="0" disabled> ' . $result;
8749 if ($format == 4 || !is_numeric($format)) {
8750 $result =
img_picto(is_numeric($format) ?
'' : $format,
'uncheck');
8756 $classname =
'error';
8760 return '<span class="' . $classname .
'">' . $result .
'</span>';
8783function get_exdir($num, $level, $alpha, $withoutslash,
$object, $modulepart =
'')
8785 if (empty($modulepart) && is_object(
$object)) {
8786 if (!empty(
$object->module)) {
8787 $modulepart =
$object->module;
8788 } elseif (!empty(
$object->element)) {
8789 $modulepart =
$object->element;
8796 $arrayforoldpath = array(
'cheque' => 2,
'category' => 2,
'supplier_invoice' => 2,
'invoice_supplier' => 2,
'mailing' => 2,
'supplier_payment' => 2);
8798 $arrayforoldpath[
'product'] = 2;
8801 if (empty($level) && array_key_exists($modulepart, $arrayforoldpath)) {
8802 $level = $arrayforoldpath[$modulepart];
8804 if (!empty($level) && array_key_exists($modulepart, $arrayforoldpath)) {
8806 if (empty($num) && is_object(
$object)) {
8809 if (empty($alpha)) {
8810 $num = preg_replace(
'/([^0-9])/i',
'', $num);
8812 $num = preg_replace(
'/^.*\-/i',
'', $num);
8814 $num = substr(
"000" . $num, -$level);
8816 $path = substr($num, 0, 1);
8819 $path = substr($num, 1, 1) .
'/' . substr($num, 0, 1);
8822 $path = substr($num, 2, 1) .
'/' . substr($num, 1, 1) .
'/' . substr($num, 0, 1);
8828 if (in_array($modulepart, array(
'societe',
'thirdparty')) &&
$object instanceof
Societe) {
8836 if (empty($withoutslash) && !empty($path)) {
8851function dol_mkdir($dir, $dataroot =
'', $newmask =
'')
8853 dol_syslog(
"functions.lib::dol_mkdir: dir=" . $dir, LOG_INFO);
8858 if (@is_dir($dir_osencoded)) {
8866 if (!empty($dataroot)) {
8868 $dir = str_replace($dataroot .
'/',
'', $dir);
8869 $ccdir = $dataroot .
'/';
8872 $cdir = explode(
"/", $dir);
8873 $num = count($cdir);
8874 for ($i = 0; $i < $num; $i++) {
8876 $ccdir .=
'/' . $cdir[$i];
8878 $ccdir .= $cdir[$i];
8881 if (preg_match(
"/^.:$/", $ccdir, $regs)) {
8889 if (!@is_dir($ccdir_osencoded)) {
8890 dol_syslog(
"functions.lib::dol_mkdir: Directory '" . $ccdir .
"' is not found (does not exists or is outside open_basedir PHP setting).", LOG_DEBUG);
8893 $dirmaskdec = octdec((
string) $newmask);
8894 if (empty($newmask)) {
8897 $dirmaskdec |= octdec(
'0111');
8898 if (!@mkdir($ccdir_osencoded, $dirmaskdec)) {
8900 dol_syslog(
"functions.lib::dol_mkdir: Fails to create directory '" . $ccdir .
"' (no permission to write into parent or directory already exists).", LOG_WARNING);
8903 dol_syslog(
"functions.lib::dol_mkdir: Directory '" . $ccdir .
"' created", LOG_DEBUG);
8912 return ($nberr ? -$nberr : $nbcreated);
8923function dolChmod($filepath, $newmask =
'')
8925 if (!empty($newmask)) {
8926 @chmod($filepath, octdec($newmask));
8940 return '<span class="fieldrequired">*</span>';
8960function dol_string_nohtmltag($stringtoclean, $removelinefeed = 1, $pagecodeto =
'UTF-8', $strip_tags = 0, $removedoublespaces = 1)
8962 if (is_null($stringtoclean)) {
8966 if ($removelinefeed == 2) {
8967 $stringtoclean = preg_replace(
'/<br[^>]*>(\n|\r)+/ims',
'<br>', $stringtoclean);
8969 $temp = preg_replace(
'/<br[^>]*>/i',
"\n", $stringtoclean);
8974 $temp = str_replace(
'< ',
'__ltspace__', $temp);
8975 $temp = str_replace(
'<:',
'__lttwopoints__', $temp);
8978 $temp = strip_tags($temp);
8981 $pattern =
"/<[^<>]+>/";
8988 $tempbis = str_replace(
'<>',
'', $temp);
8989 $tempbis = preg_replace($pattern,
'', $tempbis);
8991 }
while ($tempbis != $temp);
8996 $temp = preg_replace(
'/<+([a-z]+)/i',
'\1', $temp);
9002 if ($removelinefeed == 1) {
9003 $temp = str_replace(array(
"\r\n",
"\r",
"\n"),
" ", $temp);
9007 if ($removedoublespaces) {
9008 while (strpos($temp,
" ")) {
9009 $temp = str_replace(
" ",
" ", $temp);
9013 $temp = str_replace(
'__ltspace__',
'< ', $temp);
9014 $temp = str_replace(
'__lttwopoints__',
'<:', $temp);
9038function dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles = 1, $removeclassattribute = 1, $cleanalsojavascript = 0, $allowiframe = 0, $allowed_tags = array(), $allowlink = 0, $allowscript = 0, $allowstyle = 0, $allowphp = 0)
9040 if (empty($allowed_tags)) {
9041 $allowed_tags = array(
9098 $allowed_tags[] =
"comment";
9100 if (!in_array(
'iframe', $allowed_tags)) {
9101 $allowed_tags[] =
"iframe";
9105 if (!in_array(
'link', $allowed_tags)) {
9106 $allowed_tags[] =
"link";
9108 if (!in_array(
'meta', $allowed_tags)) {
9109 $allowed_tags[] =
"meta";
9113 if (!in_array(
'script', $allowed_tags)) {
9114 $allowed_tags[] =
"script";
9118 if (!in_array(
'style', $allowed_tags)) {
9119 $allowed_tags[] =
"style";
9123 $allowed_tags_string = implode(
"><", $allowed_tags);
9124 $allowed_tags_string =
'<' . $allowed_tags_string .
'>';
9126 $stringtoclean = str_replace(
'<!DOCTYPE html>',
'__!DOCTYPE_HTML__', $stringtoclean);
9131 $stringtoclean = preg_replace(
'/<!--([^>]*)-->/',
'<comment>\1</comment>', $stringtoclean);
9134 $allowed_tags[] =
"commentphp";
9135 $stringtoclean = preg_replace(
'/^<\?php([^"]+)\?>$/i',
'<commentphp>\1__</commentphp>', $stringtoclean);
9136 $stringtoclean = preg_replace(
'/"<\?php([^"]+)\?>"/i',
'"<commentphp>\1</commentphp>"', $stringtoclean);
9139 $stringtoclean = preg_replace(
'/:/i',
':', $stringtoclean);
9140 $stringtoclean = preg_replace(
'/:|�+58|:/i',
'', $stringtoclean);
9143 $temp = strip_tags($stringtoclean, $allowed_tags_string);
9145 if ($cleanalsosomestyles) {
9146 $temp = preg_replace(
'/position\s*:\s*(absolute|fixed)\s*!\s*important/i',
'', $temp);
9148 if ($removeclassattribute) {
9149 $temp = preg_replace(
'/(<[^>]+)\s+class=((["\']).*?\\3|\\w*)/i',
'\\1', $temp);
9154 if ($cleanalsojavascript) {
9155 $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);
9158 $temp = str_replace(
'__!DOCTYPE_HTML__',
'<!DOCTYPE html>', $temp);
9161 $temp = preg_replace(
'/<commentphp>(.*)<\/commentphp>/',
'<?php\1?>', $temp);
9164 $temp = preg_replace(
'/<comment>([^>]*)<\/comment>/',
'<!--\1-->', $temp);
9185 if (is_null($allowed_attributes)) {
9186 $allowed_attributes = array(
9220 if (!in_array(
"content", $allowed_attributes)) {
9221 $allowed_attributes[] =
"content";
9223 if (!in_array(
"http-equiv", $allowed_attributes)) {
9224 $allowed_attributes[] =
"http-equiv";
9227 if (class_exists(
'DOMDocument') && !empty($stringtoclean)) {
9229 $stringtoclean =
'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body>' . $stringtoclean .
'</body></html>';
9232 $dom =
new DOMDocument(
'',
'UTF-8');
9234 $savwarning = error_reporting();
9235 error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE);
9236 $dom->loadHTML($stringtoclean, LIBXML_ERR_NONE | LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD | LIBXML_NONET | LIBXML_NOWARNING | LIBXML_NOXMLDECL);
9237 error_reporting($savwarning);
9239 if ($dom instanceof DOMDocument) {
9240 for ($els = $dom->getElementsByTagname(
'*'), $i = $els->length - 1; $i >= 0; $i--) {
9241 $el = $els->item($i);
9242 if (!$el instanceof DOMElement) {
9245 $attrs = $el->attributes;
9246 for ($ii = $attrs->length - 1; $ii >= 0; $ii--) {
9248 if (!empty($attrs->item($ii)->name)) {
9249 if (! in_array($attrs->item($ii)->name, $allowed_attributes)) {
9251 $els->item($i)->removeAttribute($attrs->item($ii)->name);
9252 } elseif (in_array($attrs->item($ii)->name, array(
'style'))) {
9254 $valuetoclean = $attrs->item($ii)->value;
9256 if (isset($valuetoclean)) {
9258 $oldvaluetoclean = $valuetoclean;
9259 $valuetoclean = preg_replace(
'/\/\*.*\*\//m',
'', $valuetoclean);
9260 $valuetoclean = preg_replace(
'/position\s*:\s*[a-z]+/mi',
'', $valuetoclean);
9261 if ($els->item($i)->tagName ==
'a') {
9262 $valuetoclean = preg_replace(
'/display\s*:/mi',
'', $valuetoclean);
9263 $valuetoclean = preg_replace(
'/z-index\s*:/mi',
'', $valuetoclean);
9264 $valuetoclean = preg_replace(
'/\s+(top|left|right|bottom)\s*:/mi',
'', $valuetoclean);
9268 $valuetoclean = preg_replace(
'/(logout|passwordforgotten)\.php/mi',
'', $valuetoclean);
9269 $valuetoclean = preg_replace(
'/action=/mi',
'', $valuetoclean);
9270 }
while ($oldvaluetoclean != $valuetoclean);
9273 $attrs->item($ii)->value = $valuetoclean;
9280 $dom->encoding =
'UTF-8';
9282 $return = $dom->saveHTML();
9286 $return = preg_replace(
'/^' . preg_quote(
'<html><head><',
'/') .
'[^<>]*' . preg_quote(
'></head><body>',
'/') .
'/',
'', $return);
9287 $return = preg_replace(
'/' . preg_quote(
'</body></html>',
'/') .
'$/',
'', trim($return));
9289 return trim($return);
9291 return $stringtoclean;
9308 $temp = $stringtoclean;
9309 foreach ($disallowed_tags as $tagtoremove) {
9310 $temp = preg_replace(
'/<\/?' . $tagtoremove .
'>/',
'', $temp);
9311 $temp = preg_replace(
'/<\/?' . $tagtoremove .
'\s+[^>]*>/',
'', $temp);
9314 if ($cleanalsosomestyles) {
9315 $temp = preg_replace(
'/position\s*:\s*(absolute|fixed)\s*!\s*important/',
'', $temp);
9333 if ($nboflines == 1) {
9335 $firstline = preg_replace(
'/<br[^>]*>.*$/s',
'', $text);
9336 $firstline = preg_replace(
'/<div[^>]*>.*$/s',
'', $firstline);
9339 $firstline = preg_replace(
'/[\n\r].*/',
'', $text);
9344 return $firstline . (isset($firstline) && isset($text) && (strlen($firstline) != strlen($text)) ?
'...' :
'');
9348 $text = preg_replace(
'/\n/',
'', $text);
9350 $repTable = array(
"\t" =>
" ",
"\n" =>
" ",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
9352 $repTable = array(
"\t" =>
" ",
"\n" =>
"<br>",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
9355 $text = strtr($text, $repTable);
9356 if ($charset ==
'UTF-8') {
9357 $pattern =
'/(<br[^>]*>)/Uu';
9360 $pattern =
'/(<br[^>]*>)/U';
9362 $a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
9367 $lastaddediscontent = 1;
9368 while ($countline < $nboflines && isset($a[$i])) {
9369 if (preg_match(
'/<br[^>]*>/', $a[$i])) {
9370 if (array_key_exists($i + 1, $a) && !empty($a[$i + 1])) {
9371 $firstline .= ($ishtml ?
"<br>\n" :
"\n");
9373 if (!$lastaddediscontent) {
9376 $lastaddediscontent = 0;
9379 $firstline .= $a[$i];
9380 $lastaddediscontent = 1;
9386 $adddots = (isset($a[$i]) && (!preg_match(
'/<br[^>]*>/', $a[$i]) || (array_key_exists($i + 1, $a) && !empty($a[$i + 1]))));
9388 $ret = $firstline . ($adddots ?
'...' :
'');
9406function dol_nl2br($stringtoencode, $nl2brmode = 0, $forxml =
false)
9408 if (is_null($stringtoencode)) {
9413 return nl2br($stringtoencode, $forxml);
9415 $ret = preg_replace(
'/(\r\n|\r|\n)/i', ($forxml ?
'<br />' :
'<br>'), $stringtoencode);
9429function dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox = 0, $check =
'restricthtml')
9431 if (empty($nouseofiframesandbox) &&
getDolGlobalString(
'MAIN_SECURITY_USE_SANDBOX_FOR_HTMLWITHNOJS')) {
9436 return $stringtoencode;
9438 $out = $stringtoencode;
9442 $oldstringtoclean = $out;
9450 if (!empty($out) &&
getDolGlobalString(
'MAIN_RESTRICTHTML_ONLY_VALID_HTML') && $check !=
'restricthtmlallowunvalid') {
9452 libxml_use_internal_errors(
false);
9453 if (LIBXML_VERSION < 20900) {
9457 libxml_disable_entity_loader(
true);
9460 $dom =
new DOMDocument();
9468 $out =
'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body><div class="tricktoremove">' . $out .
'</div></body></html>';
9472 $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>';
9478 $out = preg_replace_callback(
9479 '/__\[([0-9a-zA-Z_]+)\]__/',
9485 return '__BRACKETSTART' . $m[1] .
'BRACKETEND__';
9490 $dom->loadHTML($out, LIBXML_HTML_NODEFDTD | LIBXML_ERR_NONE | LIBXML_HTML_NOIMPLIED | LIBXML_NONET | LIBXML_NOWARNING | LIBXML_NOERROR | LIBXML_NOXMLDECL);
9492 $dom->encoding =
'UTF-8';
9494 $out = trim($dom->saveHTML());
9497 $out = preg_replace_callback(
9498 '/__BRACKETSTART([0-9a-zA-Z_]+)BRACKETEND__/',
9504 return '__[' . $m[1] .
']__';
9511 $out = preg_replace(
'/^' . preg_quote(
'<html><head><',
'/') .
'[^<>]+' . preg_quote(
'></head><body><div class="tricktoremove">',
'/') .
'/',
'', $out);
9512 $out = preg_replace(
'/' . preg_quote(
'</div></body></html>',
'/') .
'$/',
'', trim($out));
9517 $out = str_replace(
'<br>',
'', $out);
9522 $out =
'InvalidHTMLStringCantBeCleaned ' . $e->getMessage();
9529 if (!empty($out) &&
getDolGlobalString(
'MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY') && !in_array($check, array(
'restricthtmlallowunvalid',
'restricthtmlallowlinkscript')) && $outishtml) {
9535 if (extension_loaded(
'tidy') && class_exists(
"tidy")) {
9542 'quote-marks' =>
false,
9543 'doctype' =>
'strict',
9544 'show-body-only' =>
true,
9545 "indent-attributes" =>
false,
9546 "vertical-space" =>
false,
9549 'preserve-entities' =>
true
9559 $out = $tidy->repairString($out, $config,
'utf8');
9568 $out =
'InvalidHTMLStringCantBeCleaned ' . $e->getMessage();
9574 $out = preg_replace(
'/[\x{200B}-\x{200D}\x{FEFF}]/u',
' ', $out);
9577 $out = preg_replace(
'/&(tab|newline);/i',
' ', $out);
9581 $out = preg_replace(
'/'/i',
''', $out);
9586 if (function_exists(
'realCharForNumericEntities')) {
9587 $out = preg_replace_callback(
9588 '/&#(x?[0-9][0-9a-f]+;?)/i',
9593 static function ($m) {
9601 $out = preg_replace(
'/&#x?[0-9]+/i',
'', $out);
9604 if ($check ==
'restricthtmlallowlinkscript') {
9606 } elseif ($check ==
'restricthtmlallowclass' || $check ==
'restricthtmlallowunvalid') {
9608 } elseif ($check ==
'restricthtmlallowiframe') {
9621 $out = preg_replace(
'/'/i',
"'", $out);
9625 $out = preg_replace(
'/on(mouse|drag|key|load|touch|pointer|select|transition)[a-z]*\s*=/i',
'', $out);
9626 $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);
9627 $out = preg_replace(
'/on(dblclick|drop|durationchange|emptied|end|ended|error|focus(in|out)?|formdata|gotpointercapture|hashchange|input|invalid)[a-z]*\s*=/i',
'', $out);
9628 $out = preg_replace(
'/on(lostpointercapture|offline|online|pagehide|pageshow)[a-z]*\s*=/i',
'', $out);
9629 $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);
9630 $out = preg_replace(
'/on(timeupdate|toggle|unload|volumechange|waiting|wheel)[a-z]*\s*=/i',
'', $out);
9632 $out = preg_replace(
'/on(repeat|begin|finish|beforeinput)[a-z]*\s*=/i',
'', $out);
9633 }
while ($oldstringtoclean != $out);
9640 $tmpout = preg_replace(
'/<img src="data:/mi',
'<__IMG_SRC_DATA__ src="data:', $out);
9641 preg_match_all(
'/(<img|url\(|<link)/i', $tmpout, $reg);
9642 $nblinks = count($reg[0]);
9643 if ($nblinks >
getDolGlobalInt(
"MAIN_SECURITY_MAX_IMG_IN_HTML_CONTENT", 1000)) {
9644 $out =
'ErrorTooManyLinksIntoHTMLString';
9647 if (
getDolGlobalInt(
'MAIN_DISALLOW_URL_INTO_DESCRIPTIONS') == 2 || $check ==
'restricthtmlnolink') {
9649 $out =
'ErrorHTMLLinksNotAllowed';
9651 } elseif (
getDolGlobalInt(
'MAIN_DISALLOW_URL_INTO_DESCRIPTIONS') == 1) {
9656 $pattern =
'/src=["\']?(http[^"\']+)|url\(["\']?(http[^\)]+)/';
9661 if (preg_match_all($pattern, $out, $matches)) {
9664 foreach ($matches[1] as $tmpval) {
9665 if (!empty($tmpval)) {
9669 foreach ($matches[2] as $tmpval) {
9670 if (!empty($tmpval)) {
9678 foreach ($urls as $url) {
9680 $parsedurl = parse_url($url);
9681 if (!empty($parsedurl)) {
9690 if (empty($firstexturl)) {
9691 $firstexturl = $url;
9692 } elseif (empty($secondexturl)) {
9693 $secondexturl = $url;
9699 $out =
'ErrorHTMLExternalLinksNotAllowed (Example: '.$firstexturl.($secondexturl ?
' '.$secondexturl :
'').
')';
9728function dol_htmlentitiesbr($stringtoencode, $nl2brmode = 0, $pagecodefrom =
'UTF-8', $removelasteolbr = 1)
9730 if (is_null($stringtoencode)) {
9734 $newstring = $stringtoencode;
9736 $newstring = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>/i',
'<br>', $newstring);
9737 if ($removelasteolbr) {
9738 $newstring = preg_replace(
'/<br>$/i',
'', $newstring);
9740 $newstring = preg_replace(
'/[\x{200B}-\x{200D}\x{FEFF}]/u',
' ', $newstring);
9741 $newstring = strtr($newstring, array(
'&' =>
'__PROTECTand__',
'<' =>
'__PROTECTlt__',
'>' =>
'__PROTECTgt__',
'"' =>
'__PROTECTdquot__'));
9743 $newstring = strtr($newstring, array(
'__PROTECTand__' =>
'&',
'__PROTECTlt__' =>
'<',
'__PROTECTgt__' =>
'>',
'__PROTECTdquot__' =>
'"'));
9745 if ($removelasteolbr) {
9746 $newstring = preg_replace(
'/(\r\n|\r|\n)$/i',
'', $newstring);
9765 $ret = preg_replace(
'/' .
"\r\n" .
'<br(\s[\sa-zA-Z_="]*)?\/?>/i',
"<br>", $ret);
9766 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>' .
"\r\n" .
'/i',
"\r\n", $ret);
9767 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>' .
"\n" .
'/i',
"\n", $ret);
9768 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>/i',
"\n", $ret);
9780 $ret = preg_replace(
'/ $/i',
"", $stringtodecode);
9781 $ret = preg_replace(
'/(<br>|<br(\s[\sa-zA-Z_="]*)?\/?>|' .
"\n" .
'|' .
"\r" .
')+$/i',
"", $ret);
9797 if ($keepsomeentities) {
9798 $newstring = strtr($newstring, array(
'&' =>
'__andamp__',
'<' =>
'__andlt__',
'>' =>
'__andgt__',
'"' =>
'__dquot__'));
9800 $newstring = html_entity_decode((
string) $newstring, (
int) $b, (
string)
$c);
9801 if ($keepsomeentities) {
9802 $newstring = strtr($newstring, array(
'__andamp__' =>
'&',
'__andlt__' =>
'<',
'__andgt__' =>
'>',
'__dquot__' =>
'"'));
9818function dol_htmlentities($string, $flags = ENT_QUOTES | ENT_SUBSTITUTE, $encoding =
'UTF-8', $double_encode =
false)
9820 return htmlentities($string, $flags, $encoding, $double_encode);
9839 for ($scursor = 0; $scursor < $len; $scursor++) {
9840 $ordchar = ord($s[$scursor]);
9842 if ($ordchar < 32 && $ordchar != 13 && $ordchar != 10) {
9845 } elseif ($ordchar > 126 && $ordchar < 160) {
9849 $out .= $s[$scursor];
9871 $arraystring = explode(
"\n", $s);
9872 $nb = count($arraystring);
9889 $repTable = array(
"\t" =>
" ",
"\n" =>
"<br>",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
9891 $repTable = array(
"\t" =>
" ",
"\n" =>
" ",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
9894 $text = strtr($text, $repTable);
9895 if ($charset ==
'UTF-8') {
9896 $pattern =
'/(<br[^>]*>)/Uu';
9899 $pattern =
'/(<br[^>]*>)/U';
9901 $a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
9903 $nblines = (int) floor((count($a) + 1) / 2);
9906 foreach ($a as $line) {
9909 $line_dec = html_entity_decode($line);
9911 $line_dec = wordwrap($line_dec, $maxlinesize,
'\n',
true);
9912 $nblines += substr_count($line_dec,
'\n');
9932 if (is_null($msg)) {
9937 if (preg_match(
'/<(html|link|script)/i', $msg)) {
9939 } elseif (preg_match(
'/<body/i', $msg)) {
9941 } elseif (preg_match(
'/<\/textarea/i', $msg)) {
9943 } elseif (preg_match(
'/<(b|em|i|u)(\s+[^>]+)?>/i', $msg)) {
9945 } elseif (preg_match(
'/<br/i', $msg)) {
9951 $msg = preg_replace(
'/https?:\/\/[^"\'\s]+/i',
'', $msg);
9952 if (preg_match(
'/<(html|link|script|body)/i', $msg)) {
9954 } elseif (preg_match(
'/<\/textarea/i', $msg)) {
9956 } elseif (preg_match(
'/<(b|em|i|u)(\s+[^>]+)?>/i', $msg)) {
9958 } elseif (preg_match(
'/<(br|hr)\/>/i', $msg)) {
9960 } elseif (preg_match(
'/<(br|hr|div|font|li|p|span|strong|table)>/i', $msg)) {
9962 } elseif (preg_match(
'/<(br|hr|div|font|li|p|span|strong|table)\s+[^<>\/]*\/?>/i', $msg)) {
9964 } elseif (preg_match(
'/<img\s+[^<>]*src[^<>]*>/i', $msg)) {
9966 } elseif (preg_match(
'/<a\s+[^<>]*href[^<>]*>/i', $msg)) {
9968 } elseif (preg_match(
'/<h[0-9]>/i', $msg)) {
9970 } elseif (preg_match(
'/&[A-Z0-9]{1,6};/i', $msg)) {
9973 } elseif (preg_match(
'/&#[0-9]{2,3};/i', $msg)) {
9975 } elseif (preg_match(
'/&#x[a-f0-9][a-f0-9];/i', $msg)) {
9997function dol_concatdesc($text1, $text2, $forxml =
false, $invert =
false)
9999 if (!empty($invert)) {
10007 $ret .= (!empty($text1) && !empty($text2)) ? ((
dol_textishtml($text1) ||
dol_textishtml($text2)) ? ($forxml ?
"<br >\n" :
"<br>\n") :
"\n") :
"";
10022 return $text1.$text2;
10038function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude =
null,
$object =
null, $include =
null)
10040 global $db, $conf,
$mysoc, $user, $extrafields;
10042 $substitutionarray = array();
10044 if ((empty($exclude) || !in_array(
'user', $exclude)) && (empty($include) || in_array(
'user', $include)) && $user instanceof
User) {
10048 $emailsendersignature = $user->signature;
10049 $usersignature = $user->signature;
10050 $substitutionarray = array_merge($substitutionarray, array(
10051 '__SENDEREMAIL_SIGNATURE__' => (
string) ((!
getDolGlobalString(
'MAIN_MAIL_DO_NOT_USE_SIGN')) ? ($onlykey == 2 ?
dol_trunc(
'SignatureFromTheSelectedSenderProfile', 30) : $emailsendersignature) :
''),
10055 if (is_object($user) && ($user instanceof
User)) {
10056 $substitutionarray = array_merge($substitutionarray, array(
10057 '__USER_ID__' => (
string) $user->id,
10058 '__USER_LOGIN__' => (
string) $user->login,
10059 '__USER_EMAIL__' => (
string) $user->email,
10060 '__USER_PHONE__' => (
string)
dol_print_phone($user->office_phone,
'', 0, 0,
'',
" ",
'',
'', -1),
10061 '__USER_PHONEPRO__' => (
string)
dol_print_phone($user->user_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
10062 '__USER_PHONEMOBILE__' => (
string)
dol_print_phone($user->personal_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
10063 '__USER_FAX__' => (
string) $user->office_fax,
10064 '__USER_LASTNAME__' => (
string) $user->lastname,
10065 '__USER_FIRSTNAME__' => (
string) $user->firstname,
10066 '__USER_FULLNAME__' => (
string) $user->getFullName($outputlangs),
10067 '__USER_SUPERVISOR_ID__' => (
string) ($user->fk_user ? $user->fk_user :
'0'),
10068 '__USER_JOB__' => (string) $user->job,
10070 '__USER_VCARD_URL__' => (string) $user->getOnlineVirtualCardUrl(
'',
'external')
10074 if ((empty($exclude) || !in_array(
'mycompany', $exclude)) && is_object(
$mysoc) && (empty($include) || in_array(
'mycompany', $include))) {
10075 $substitutionarray = array_merge($substitutionarray, array(
10076 '__MYCOMPANY_NAME__' =>
$mysoc->name,
10077 '__MYCOMPANY_EMAIL__' =>
$mysoc->email,
10078 '__MYCOMPANY_URL__' =>
$mysoc->url,
10080 '__MYCOMPANY_PHONEMOBILE__' =>
dol_print_phone(
$mysoc->phone_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
10082 '__MYCOMPANY_PROFID1__' =>
$mysoc->idprof1,
10083 '__MYCOMPANY_PROFID2__' =>
$mysoc->idprof2,
10084 '__MYCOMPANY_PROFID3__' =>
$mysoc->idprof3,
10085 '__MYCOMPANY_PROFID4__' =>
$mysoc->idprof4,
10086 '__MYCOMPANY_PROFID5__' =>
$mysoc->idprof5,
10087 '__MYCOMPANY_PROFID6__' =>
$mysoc->idprof6,
10088 '__MYCOMPANY_PROFID7__' =>
$mysoc->idprof7,
10089 '__MYCOMPANY_PROFID8__' =>
$mysoc->idprof8,
10090 '__MYCOMPANY_PROFID9__' =>
$mysoc->idprof9,
10091 '__MYCOMPANY_PROFID10__' =>
$mysoc->idprof10,
10092 '__MYCOMPANY_CAPITAL__' =>
$mysoc->capital,
10093 '__MYCOMPANY_FULLADDRESS__' => (method_exists(
$mysoc,
'getFullAddress') ?
$mysoc->getFullAddress(1,
', ') :
''),
10095 '__MYCOMPANY_VATNUMBER__' =>
$mysoc->tva_intra,
10096 '__MYCOMPANY_ZIP__' =>
$mysoc->zip,
10097 '__MYCOMPANY_TOWN__' =>
$mysoc->town,
10098 '__MYCOMPANY_STATE__' =>
$mysoc->state,
10099 '__MYCOMPANY_COUNTRY__' =>
$mysoc->country,
10100 '__MYCOMPANY_COUNTRY_ID__' =>
$mysoc->country_id,
10101 '__MYCOMPANY_COUNTRY_CODE__' =>
$mysoc->country_code,
10102 '__MYCOMPANY_CURRENCY_CODE__' => $conf->currency
10106 if (($onlykey || is_object(
$object)) && (empty($exclude) || !in_array(
'object', $exclude)) && (empty($include) || in_array(
'object', $include))) {
10108 $substitutionarray[
'__ID__'] =
'__ID__';
10109 $substitutionarray[
'__REF__'] =
'__REF__';
10110 $substitutionarray[
'__NEWREF__'] =
'__NEWREF__';
10111 $substitutionarray[
'__LABEL__'] =
'__LABEL__';
10112 $substitutionarray[
'__REF_CLIENT__'] =
'__REF_CLIENT__';
10113 $substitutionarray[
'__REF_SUPPLIER__'] =
'__REF_SUPPLIER__';
10114 $substitutionarray[
'__NOTE_PUBLIC__'] =
'__NOTE_PUBLIC__';
10115 $substitutionarray[
'__NOTE_PRIVATE__'] =
'__NOTE_PRIVATE__';
10116 $substitutionarray[
'__EXTRAFIELD_XXX__'] =
'__EXTRAFIELD_XXX__';
10119 $substitutionarray[
'__THIRDPARTY_ID__'] =
'__THIRDPARTY_ID__';
10120 $substitutionarray[
'__THIRDPARTY_NAME__'] =
'__THIRDPARTY_NAME__';
10121 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] =
'__THIRDPARTY_NAME_ALIAS__';
10122 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] =
'__THIRDPARTY_CODE_CLIENT__';
10123 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] =
'__THIRDPARTY_CODE_FOURNISSEUR__';
10124 $substitutionarray[
'__THIRDPARTY_EMAIL__'] =
'__THIRDPARTY_EMAIL__';
10126 $substitutionarray[
'__THIRDPARTY_URL__'] =
'__THIRDPARTY_URL__';
10128 $substitutionarray[
'__THIRDPARTY_PHONE__'] =
'__THIRDPARTY_PHONE__';
10129 $substitutionarray[
'__THIRDPARTY_FAX__'] =
'__THIRDPARTY_FAX__';
10130 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] =
'__THIRDPARTY_ADDRESS__';
10131 $substitutionarray[
'__THIRDPARTY_ZIP__'] =
'__THIRDPARTY_ZIP__';
10132 $substitutionarray[
'__THIRDPARTY_TOWN__'] =
'__THIRDPARTY_TOWN__';
10133 $substitutionarray[
'__THIRDPARTY_STATE__'] =
'__THIRDPARTY_STATE__';
10134 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] =
'__THIRDPARTY_IDPROF1__';
10135 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] =
'__THIRDPARTY_IDPROF2__';
10136 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] =
'__THIRDPARTY_IDPROF3__';
10137 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] =
'__THIRDPARTY_IDPROF4__';
10138 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] =
'__THIRDPARTY_IDPROF5__';
10139 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] =
'__THIRDPARTY_IDPROF6__';
10140 $substitutionarray[
'__THIRDPARTY_IDPROF7__'] =
'__THIRDPARTY_IDPROF7__';
10141 $substitutionarray[
'__THIRDPARTY_IDPROF8__'] =
'__THIRDPARTY_IDPROF8__';
10142 $substitutionarray[
'__THIRDPARTY_IDPROF9__'] =
'__THIRDPARTY_IDPROF9__';
10143 $substitutionarray[
'__THIRDPARTY_IDPROF10__'] =
'__THIRDPARTY_IDPROF10__';
10144 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] =
'__THIRDPARTY_TVAINTRA__';
10145 $substitutionarray[
'__THIRDPARTY_NOTE_PUBLIC__'] =
'__THIRDPARTY_NOTE_PUBLIC__';
10146 $substitutionarray[
'__THIRDPARTY_NOTE_PRIVATE__'] =
'__THIRDPARTY_NOTE_PRIVATE__';
10148 if (
isModEnabled(
'member') && (!is_object(
$object) ||
$object->element ==
'adherent') && (empty($exclude) || !in_array(
'member', $exclude)) && (empty($include) || in_array(
'member', $include))) {
10149 $substitutionarray[
'__MEMBER_ID__'] =
'__MEMBER_ID__';
10150 $substitutionarray[
'__MEMBER_TITLE__'] =
'__MEMBER_TITLE__';
10151 $substitutionarray[
'__MEMBER_FIRSTNAME__'] =
'__MEMBER_FIRSTNAME__';
10152 $substitutionarray[
'__MEMBER_LASTNAME__'] =
'__MEMBER_LASTNAME__';
10153 $substitutionarray[
'__MEMBER_USER_LOGIN_INFORMATION__'] =
'Login and pass of the external user account';
10158 if (
isModEnabled(
'ticket') && (!is_object(
$object) ||
$object->element ==
'ticket') && (empty($exclude) || !in_array(
'ticket', $exclude)) && (empty($include) || in_array(
'ticket', $include))) {
10159 $substitutionarray[
'__TICKET_TRACKID__'] =
'__TICKET_TRACKID__';
10160 $substitutionarray[
'__TICKET_SUBJECT__'] =
'__TICKET_SUBJECT__';
10161 $substitutionarray[
'__TICKET_TYPE__'] =
'__TICKET_TYPE__';
10162 $substitutionarray[
'__TICKET_SEVERITY__'] =
'__TICKET_SEVERITY__';
10163 $substitutionarray[
'__TICKET_CATEGORY__'] =
'__TICKET_CATEGORY__';
10164 $substitutionarray[
'__TICKET_ANALYTIC_CODE__'] =
'__TICKET_ANALYTIC_CODE__';
10165 $substitutionarray[
'__TICKET_MESSAGE__'] =
'__TICKET_MESSAGE__';
10166 $substitutionarray[
'__TICKET_PROGRESSION__'] =
'__TICKET_PROGRESSION__';
10167 $substitutionarray[
'__TICKET_USER_ASSIGN__'] =
'__TICKET_USER_ASSIGN__';
10170 if (
isModEnabled(
'recruitment') && (!is_object(
$object) ||
$object->element ==
'recruitmentcandidature') && (empty($exclude) || !in_array(
'recruitment', $exclude)) && (empty($include) || in_array(
'recruitment', $include))) {
10171 $substitutionarray[
'__CANDIDATE_FULLNAME__'] =
'__CANDIDATE_FULLNAME__';
10172 $substitutionarray[
'__CANDIDATE_FIRSTNAME__'] =
'__CANDIDATE_FIRSTNAME__';
10173 $substitutionarray[
'__CANDIDATE_LASTNAME__'] =
'__CANDIDATE_LASTNAME__';
10175 if (
isModEnabled(
'project') && (empty($exclude) || !in_array(
'project', $exclude)) && (empty($include) || in_array(
'project', $include))) {
10176 $substitutionarray[
'__PROJECT_ID__'] =
'__PROJECT_ID__';
10177 $substitutionarray[
'__PROJECT_REF__'] =
'__PROJECT_REF__';
10178 $substitutionarray[
'__PROJECT_NAME__'] =
'__PROJECT_NAME__';
10182 if (
isModEnabled(
'contract') && (!is_object(
$object) ||
$object->element ==
'contract') && (empty($exclude) || !in_array(
'contract', $exclude)) && (empty($include) || in_array(
'contract', $include))) {
10183 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE__'] =
'Highest date planned for a service start';
10184 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATETIME__'] =
'Highest date and hour planned for service start';
10185 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE__'] =
'Lowest data for planned expiration of service';
10186 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATETIME__'] =
'Lowest date and hour for planned expiration of service';
10188 if (
isModEnabled(
"propal") && (!is_object(
$object) ||
$object->element ==
'propal') && (empty($exclude) || !in_array(
'propal', $exclude)) && (empty($include) || in_array(
'propal', $include))) {
10189 $substitutionarray[
'__ONLINE_SIGN_URL__'] =
'ToOfferALinkForOnlineSignature';
10191 if (
isModEnabled(
"intervention") && (!is_object(
$object) ||
$object->element ==
'fichinter') && (empty($exclude) || !in_array(
'intervention', $exclude)) && (empty($include) || in_array(
'intervention', $include))) {
10192 $substitutionarray[
'__ONLINE_SIGN_FICHINTER_URL__'] =
'ToOfferALinkForOnlineSignature';
10194 $substitutionarray[
'__ONLINE_PAYMENT_URL__'] =
'UrlToPayOnlineIfApplicable';
10195 $substitutionarray[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'TextAndUrlToPayOnlineIfApplicable';
10196 $substitutionarray[
'__SECUREKEYPAYMENT__'] =
'Security key (if key is not unique per record)';
10197 $substitutionarray[
'__SECUREKEYPAYMENT_MEMBER__'] =
'Security key for payment on a member subscription (one key per member)';
10198 $substitutionarray[
'__SECUREKEYPAYMENT_ORDER__'] =
'Security key for payment on an order';
10199 $substitutionarray[
'__SECUREKEYPAYMENT_INVOICE__'] =
'Security key for payment on an invoice';
10200 $substitutionarray[
'__SECUREKEYPAYMENT_CONTRACTLINE__'] =
'Security key for payment on a service of a contract';
10202 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
'Direct download url of a proposal';
10203 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
'Direct download url of an order';
10204 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
'Direct download url of an invoice';
10205 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
'Direct download url of a contract';
10206 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
'Direct download url of a supplier proposal';
10209 $substitutionarray[
'__SHIPPINGTRACKNUM__'] =
'Shipping tracking number';
10210 $substitutionarray[
'__SHIPPINGTRACKNUMURL__'] =
'Shipping tracking url';
10211 $substitutionarray[
'__SHIPPINGMETHOD__'] =
'Shipping method';
10214 $substitutionarray[
'__RECEPTIONTRACKNUM__'] =
'Shipping tracking number of shipment';
10215 $substitutionarray[
'__RECEPTIONTRACKNUMURL__'] =
'Shipping tracking url';
10218 '@phan-var-force Adherent|Delivery $object';
10220 $substitutionarray[
'__ID__'] =
$object->id;
10221 $substitutionarray[
'__REF__'] =
$object->ref;
10222 $substitutionarray[
'__NEWREF__'] =
$object->newref;
10224 $substitutionarray[
'__REF_CLIENT__'] = (isset(
$object->ref_client) ?
$object->ref_client : (isset(
$object->ref_customer) ?
$object->ref_customer :
null));
10225 $substitutionarray[
'__REF_SUPPLIER__'] = (isset(
$object->ref_supplier) ?
$object->ref_supplier :
null);
10226 $substitutionarray[
'__NOTE_PUBLIC__'] = (isset(
$object->note_public) ?
$object->note_public :
null);
10227 $substitutionarray[
'__NOTE_PRIVATE__'] = (isset(
$object->note_private) ?
$object->note_private :
null);
10229 $substitutionarray[
'__DATE_CREATION__'] = (isset(
$object->date_creation) ?
dol_print_date(
$object->date_creation,
'day',
false, $outputlangs) :
'');
10230 $substitutionarray[
'__DATE_MODIFICATION__'] = (isset(
$object->date_modification) ?
dol_print_date(
$object->date_modification,
'day',
false, $outputlangs) :
'');
10231 $substitutionarray[
'__DATE_VALIDATION__'] = (isset(
$object->date_validation) ?
dol_print_date(
$object->date_validation,
'day',
false, $outputlangs) :
'');
10234 $date_delivery =
null;
10235 if (property_exists(
$object,
'date_delivery')) {
10236 $date_delivery =
$object->date_delivery;
10237 } elseif (property_exists(
$object,
'delivery_date')) {
10238 $date_delivery =
$object->delivery_date;
10240 $substitutionarray[
'__DATE_DELIVERY__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
'day',
false, $outputlangs) :
'');
10241 $substitutionarray[
'__DATE_DELIVERY_DAY__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%d") :
'');
10242 $substitutionarray[
'__DATE_DELIVERY_DAY_TEXT__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%A") :
'');
10243 $substitutionarray[
'__DATE_DELIVERY_MON__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%m") :
'');
10244 $substitutionarray[
'__DATE_DELIVERY_MON_TEXT__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%b") :
'');
10245 $substitutionarray[
'__DATE_DELIVERY_YEAR__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%Y") :
'');
10246 $substitutionarray[
'__DATE_DELIVERY_HH__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%H") :
'');
10247 $substitutionarray[
'__DATE_DELIVERY_MM__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%M") :
'');
10248 $substitutionarray[
'__DATE_DELIVERY_SS__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%S") :
'');
10251 $substitutionarray[
'__REFCLIENT__'] = (isset(
$object->ref_client) ?
$object->ref_client : (isset(
$object->ref_customer) ?
$object->ref_customer :
null));
10252 $substitutionarray[
'__REFSUPPLIER__'] = (isset(
$object->ref_supplier) ?
$object->ref_supplier :
null);
10254 $substitutionarray[
'__SUPPLIER_ORDER_DATE_DELIVERY__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
'day',
false, $outputlangs) :
'');
10255 $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 :
'')) :
'');
10259 '@phan-var-force Adherent $object';
10263 $substitutionarray[
'__MEMBER_ID__'] = (isset(
$object->id) ?
$object->id :
'');
10264 if (method_exists(
$object,
'getCivilityLabel')) {
10265 $substitutionarray[
'__MEMBER_TITLE__'] =
$object->getCivilityLabel();
10267 $substitutionarray[
'__MEMBER_FIRSTNAME__'] = (isset(
$object->firstname) ?
$object->firstname :
'');
10268 $substitutionarray[
'__MEMBER_LASTNAME__'] = (isset(
$object->lastname) ?
$object->lastname :
'');
10269 $substitutionarray[
'__MEMBER_USER_LOGIN_INFORMATION__'] =
'';
10270 if (method_exists(
$object,
'getFullName')) {
10271 $substitutionarray[
'__MEMBER_FULLNAME__'] =
$object->getFullName($outputlangs);
10273 $substitutionarray[
'__MEMBER_COMPANY__'] = (isset(
$object->societe) ?
$object->societe :
'');
10274 $substitutionarray[
'__MEMBER_ADDRESS__'] = (isset(
$object->address) ?
$object->address :
'');
10275 $substitutionarray[
'__MEMBER_ZIP__'] = (isset(
$object->zip) ?
$object->zip :
'');
10276 $substitutionarray[
'__MEMBER_TOWN__'] = (isset(
$object->town) ?
$object->town :
'');
10277 $substitutionarray[
'__MEMBER_STATE__'] = (isset(
$object->state) ?
$object->state :
'');
10278 $substitutionarray[
'__MEMBER_COUNTRY__'] = (isset(
$object->country) ?
$object->country :
'');
10279 $substitutionarray[
'__MEMBER_EMAIL__'] = (isset(
$object->email) ?
$object->email :
'');
10280 $substitutionarray[
'__MEMBER_BIRTH__'] = (isset($birthday) ? $birthday :
'');
10281 $substitutionarray[
'__MEMBER_PHOTO__'] = (isset(
$object->photo) ?
$object->photo :
'');
10282 $substitutionarray[
'__MEMBER_LOGIN__'] = (isset(
$object->login) ?
$object->login :
'');
10283 $substitutionarray[
'__MEMBER_PASSWORD__'] = (isset(
$object->pass) ?
$object->pass :
'');
10287 $substitutionarray[
'__MEMBER_TYPE__'] = (isset(
$object->type) ?
$object->type :
'');
10288 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE__'] =
dol_print_date(
$object->first_subscription_date,
'day');
10290 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_RFC__'] =
dol_print_date(
$object->first_subscription_date,
'dayrfc');
10291 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_START__'] = (isset(
$object->first_subscription_date_start) ?
dol_print_date(
$object->first_subscription_date_start,
'day') :
'');
10292 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_START_RFC__'] = (isset(
$object->first_subscription_date_start) ?
dol_print_date(
$object->first_subscription_date_start,
'dayrfc') :
'');
10293 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_END__'] = (isset(
$object->first_subscription_date_end) ?
dol_print_date(
$object->first_subscription_date_end,
'day') :
'');
10294 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_END_RFC__'] = (isset(
$object->first_subscription_date_end) ?
dol_print_date(
$object->first_subscription_date_end,
'dayrfc') :
'');
10295 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE__'] =
dol_print_date(
$object->last_subscription_date,
'day');
10296 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_RFC__'] =
dol_print_date(
$object->last_subscription_date,
'dayrfc');
10297 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_START__'] =
dol_print_date(
$object->last_subscription_date_start,
'day');
10298 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_START_RFC__'] =
dol_print_date(
$object->last_subscription_date_start,
'dayrfc');
10299 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_END__'] =
dol_print_date(
$object->last_subscription_date_end,
'day');
10300 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_END_RFC__'] =
dol_print_date(
$object->last_subscription_date_end,
'dayrfc');
10305 '@phan-var-force Societe $object';
10306 $substitutionarray[
'__THIRDPARTY_ID__'] =
$object->id ??
'';
10307 $substitutionarray[
'__THIRDPARTY_NAME__'] =
$object->name ??
'';
10308 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] =
$object->name_alias ??
'';
10309 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] =
$object->code_client ??
'';
10310 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] =
$object->code_fournisseur ??
'';
10311 $substitutionarray[
'__THIRDPARTY_EMAIL__'] =
$object->email ??
'';
10312 $substitutionarray[
'__THIRDPARTY_EMAIL_URLENCODED__'] = urlencode(
$object->email ??
'');
10313 $substitutionarray[
'__THIRDPARTY_URL__'] =
$object->url ??
'';
10314 $substitutionarray[
'__THIRDPARTY_URL_URLENCODED__'] = urlencode(
$object->url ??
'');
10317 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] =
$object->address ??
'';
10318 $substitutionarray[
'__THIRDPARTY_ZIP__'] =
$object->zip ??
'';
10319 $substitutionarray[
'__THIRDPARTY_TOWN__'] =
$object->town ??
'';
10320 $substitutionarray[
'__THIRDPARTY_STATE__'] =
$object->state ??
'';
10321 $substitutionarray[
'__THIRDPARTY_COUNTRY_ID__'] = (
$object->country_id > 0 ?:
'');
10322 $substitutionarray[
'__THIRDPARTY_COUNTRY_CODE__'] =
$object->country_code ??
'';
10323 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] =
$object->idprof1 ??
'';
10324 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] =
$object->idprof2 ??
'';
10325 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] =
$object->idprof3 ??
'';
10326 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] =
$object->idprof4 ??
'';
10327 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] =
$object->idprof5 ??
'';
10328 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] =
$object->idprof6 ??
'';
10329 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] =
$object->tva_intra ??
'';
10332 } elseif (is_object(
$object) && is_object(
$object->thirdparty)) {
10333 $substitutionarray[
'__THIRDPARTY_ID__'] =
$object->thirdparty->id ??
'';
10334 $substitutionarray[
'__THIRDPARTY_NAME__'] =
$object->thirdparty->name ??
'';
10335 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] =
$object->thirdparty->name_alias ??
'';
10336 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] =
$object->thirdparty->code_client ??
'';
10337 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] =
$object->thirdparty->code_fournisseur ??
'';
10338 $substitutionarray[
'__THIRDPARTY_EMAIL__'] =
$object->thirdparty->email ??
'';
10339 $substitutionarray[
'__THIRDPARTY_EMAIL_URLENCODED__'] = urlencode(
$object->thirdparty->email ??
'');
10342 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] =
$object->thirdparty->address ??
'';
10343 $substitutionarray[
'__THIRDPARTY_ZIP__'] =
$object->thirdparty->zip ??
'';
10344 $substitutionarray[
'__THIRDPARTY_TOWN__'] =
$object->thirdparty->town ??
'';
10345 $substitutionarray[
'__THIRDPARTY_STATE__'] =
$object->thirdparty->state ??
'';
10346 $substitutionarray[
'__THIRDPARTY_COUNTRY_ID__'] = (
$object->thirdparty->country_id > 0 ?:
'');
10347 $substitutionarray[
'__THIRDPARTY_COUNTRY_CODE__'] =
$object->thirdparty->country_code ??
'';
10348 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] =
$object->thirdparty->idprof1 ??
'';
10349 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] =
$object->thirdparty->idprof2 ??
'';
10350 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] =
$object->thirdparty->idprof3 ??
'';
10351 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] =
$object->thirdparty->idprof4 ??
'';
10352 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] =
$object->thirdparty->idprof5 ??
'';
10353 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] =
$object->thirdparty->idprof6 ??
'';
10354 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] =
$object->thirdparty->tva_intra ??
'';
10359 if (is_object(
$object) &&
$object->element ==
'recruitmentcandidature') {
10360 '@phan-var-force RecruitmentCandidature $object';
10362 $substitutionarray[
'__CANDIDATE_FULLNAME__'] =
$object->getFullName($outputlangs);
10363 $substitutionarray[
'__CANDIDATE_FIRSTNAME__'] = isset(
$object->firstname) ?
$object->firstname :
'';
10364 $substitutionarray[
'__CANDIDATE_LASTNAME__'] = isset(
$object->lastname) ?
$object->lastname :
'';
10366 if (is_object(
$object) &&
$object->element ==
'conferenceorboothattendee') {
10367 '@phan-var-force ConferenceOrBoothAttendee $object';
10369 $substitutionarray[
'__ATTENDEE_FULLNAME__'] =
$object->getFullName($outputlangs);
10370 $substitutionarray[
'__ATTENDEE_FIRSTNAME__'] = isset(
$object->firstname) ?
$object->firstname :
'';
10371 $substitutionarray[
'__ATTENDEE_LASTNAME__'] = isset(
$object->lastname) ?
$object->lastname :
'';
10375 '@phan-var-force Project $object';
10377 $substitutionarray[
'__PROJECT_ID__'] =
$object->id;
10378 $substitutionarray[
'__PROJECT_REF__'] =
$object->ref;
10379 $substitutionarray[
'__PROJECT_NAME__'] =
$object->title;
10380 } elseif (is_object(
$object)) {
10382 if (!empty(
$object->project)) {
10385 if (!is_null($project) && is_object($project)) {
10386 $substitutionarray[
'__PROJECT_ID__'] = $project->id;
10387 $substitutionarray[
'__PROJECT_REF__'] = $project->ref;
10388 $substitutionarray[
'__PROJECT_NAME__'] = $project->title;
10393 $project_id =
$object->fk_project;
10394 } elseif (!empty(
$object->fk_projet) &&
$object->fk_projet > 0) {
10395 $project_id =
$object->fk_project;
10397 if ($project_id > 0) {
10399 $substitutionarray[
'__PROJECT_ID__@lazyload'] =
'/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id;
10400 $substitutionarray[
'__PROJECT_REF__@lazyload'] =
'/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id;
10401 $substitutionarray[
'__PROJECT_NAME__@lazyload'] =
'/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id;
10407 '@phan-var-force Facture $object';
10409 $substitutionarray[
'__INVOICE_SITUATION_NUMBER__'] = isset(
$object->situation_counter) ?
$object->situation_counter :
'';
10412 '@phan-var-force Expedition $object';
10414 $substitutionarray[
'__SHIPPINGTRACKNUM__'] =
$object->tracking_number;
10415 $substitutionarray[
'__SHIPPINGTRACKNUMURL__'] =
$object->tracking_url;
10416 $substitutionarray[
'__SHIPPINGMETHOD__'] =
$object->shipping_method;
10419 '@phan-var-force Reception $object';
10421 $substitutionarray[
'__RECEPTIONTRACKNUM__'] =
$object->tracking_number;
10422 $substitutionarray[
'__RECEPTIONTRACKNUMURL__'] =
$object->tracking_url;
10426 '@phan-var-force Contrat $object';
10428 $dateplannedstart =
'';
10429 $datenextexpiration =
'';
10430 foreach (
$object->lines as $line) {
10431 if ($line->date_start > $dateplannedstart) {
10432 $dateplannedstart = $line->date_start;
10434 if ($line->statut == 4 && $line->date_end && (!$datenextexpiration || $line->date_end < $datenextexpiration)) {
10435 $datenextexpiration = $line->date_end;
10438 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE__'] =
dol_print_date($dateplannedstart,
'day');
10439 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE_RFC__'] =
dol_print_date($dateplannedstart,
'dayrfc');
10440 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATETIME__'] =
dol_print_date($dateplannedstart,
'standard');
10442 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE__'] =
dol_print_date($datenextexpiration,
'day');
10443 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE_RFC__'] =
dol_print_date($datenextexpiration,
'dayrfc');
10444 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATETIME__'] =
dol_print_date($datenextexpiration,
'standard');
10448 '@phan-var-force Ticket $object';
10450 $substitutionarray[
'__TICKET_TRACKID__'] =
$object->track_id;
10451 $substitutionarray[
'__TICKET_SUBJECT__'] =
$object->subject;
10452 $substitutionarray[
'__TICKET_TYPE__'] =
$object->type_code;
10453 $substitutionarray[
'__TICKET_SEVERITY__'] =
$object->severity_code;
10454 $substitutionarray[
'__TICKET_CATEGORY__'] =
$object->category_code;
10455 $substitutionarray[
'__TICKET_ANALYTIC_CODE__'] =
$object->category_code;
10456 $substitutionarray[
'__TICKET_MESSAGE__'] =
$object->message;
10457 $substitutionarray[
'__TICKET_PROGRESSION__'] =
$object->progress;
10458 $userstat =
new User($db);
10459 if (
$object->fk_user_assign > 0) {
10460 $userstat->fetch(
$object->fk_user_assign);
10461 $substitutionarray[
'__TICKET_USER_ASSIGN__'] =
dolGetFirstLastname($userstat->firstname, $userstat->lastname);
10464 if (
$object->fk_user_create > 0) {
10465 $userstat->fetch(
$object->fk_user_create);
10466 $substitutionarray[
'__USER_CREATE__'] =
dolGetFirstLastname($userstat->firstname, $userstat->lastname);
10472 if (!is_object($extrafields)) {
10475 $extrafields->fetch_name_optionals_label(
$object->table_element,
true);
10477 if (
$object->fetch_optionals() > 0) {
10478 if (is_array($extrafields->attributes[
$object->table_element][
'label']) && count($extrafields->attributes[
$object->table_element][
'label']) > 0) {
10479 foreach ($extrafields->attributes[
$object->table_element][
'label'] as $key => $label) {
10480 if ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'date') {
10481 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] =
dol_print_date(
$object->array_options[
'options_' . $key],
'day');
10482 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_LOCALE__'] =
dol_print_date(
$object->array_options[
'options_' . $key],
'day',
'tzserver', $outputlangs);
10483 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_RFC__'] =
dol_print_date(
$object->array_options[
'options_' . $key],
'dayrfc');
10484 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'datetime') {
10485 $datetime =
$object->array_options[
'options_' . $key];
10486 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhour') :
'');
10487 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_LOCALE__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhour',
'tzserver', $outputlangs) :
'');
10488 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_DAY_LOCALE__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'day',
'tzserver', $outputlangs) :
'');
10489 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_RFC__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhourrfc') :
'');
10490 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'phone') {
10491 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] =
dol_print_phone(
$object->array_options[
'options_' . $key]);
10492 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'price') {
10493 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] =
$object->array_options[
'options_' . $key];
10494 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_FORMATED__'] =
price(
$object->array_options[
'options_' . $key]);
10495 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_FORMATTED__'] =
price(
$object->array_options[
'options_' . $key]);
10496 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] !=
'separator') {
10497 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] = !empty(
$object->array_options[
'options_' . $key]) ?
$object->array_options[
'options_' . $key] :
'';
10505 if (empty($substitutionarray[
'__REF__'])) {
10509 require_once DOL_DOCUMENT_ROOT .
'/core/lib/payments.lib.php';
10510 $outputlangs->loadLangs(array(
'paypal',
'other'));
10513 $typeforonlinepayment =
'free';
10515 $typeforonlinepayment =
'order';
10518 $typeforonlinepayment =
'invoice';
10521 $typeforonlinepayment =
'member';
10522 if (!empty(
$object->last_subscription_amount)) {
10523 $amounttouse =
$object->last_subscription_amount;
10527 $typeforonlinepayment =
'contract';
10530 $typeforonlinepayment =
'ficheinter';
10533 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $substitutionarray[
'__REF__'], (
float) $amounttouse);
10534 $paymenturl = $url;
10538 $substitutionarray[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = ($paymenturl ? str_replace(
'\n',
"\n", $outputlangs->trans(
"PredefinedMailContentLink", $paymenturl)) :
'');
10539 $substitutionarray[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
10543 include_once DOL_DOCUMENT_ROOT .
'/core/lib/functions_be.lib.php';
10548 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
$object->getLastMainDocLink(
$object->element);
10550 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
'';
10553 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
$object->getLastMainDocLink(
$object->element);
10555 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
'';
10558 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
$object->getLastMainDocLink(
$object->element);
10560 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
'';
10563 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
$object->getLastMainDocLink(
$object->element);
10565 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
'';
10568 $substitutionarray[
'__DIRECTDOWNLOAD_URL_FICHINTER__'] =
$object->getLastMainDocLink(
$object->element);
10570 $substitutionarray[
'__DIRECTDOWNLOAD_URL_FICHINTER__'] =
'';
10573 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
$object->getLastMainDocLink(
$object->element);
10575 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
'';
10579 '@phan-var-force Propal $object';
10581 $substitutionarray[
'__URL_PROPOSAL__'] = DOL_MAIN_URL_ROOT .
"/comm/propal/card.php?id=" .
$object->id;
10582 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
10583 $substitutionarray[
'__ONLINE_SIGN_URL__'] = getOnlineSignatureUrl(0,
'proposal',
$object->ref, 1,
$object);
10586 '@phan-var-force Commande $object';
10588 $substitutionarray[
'__URL_ORDER__'] = DOL_MAIN_URL_ROOT .
"/commande/card.php?id=" .
$object->id;
10591 '@phan-var-force Facture $object';
10593 $substitutionarray[
'__URL_INVOICE__'] = DOL_MAIN_URL_ROOT .
"/compta/facture/card.php?id=" .
$object->id;
10596 '@phan-var-force Contrat $object';
10598 $substitutionarray[
'__URL_CONTRACT__'] = DOL_MAIN_URL_ROOT .
"/contrat/card.php?id=" .
$object->id;
10599 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
10600 $substitutionarray[
'__ONLINE_SIGN_URL__'] = getOnlineSignatureUrl(0,
'contract',
$object->ref, 1,
$object);
10603 '@phan-var-force Fichinter $object';
10605 $substitutionarray[
'__URL_FICHINTER__'] = DOL_MAIN_URL_ROOT .
"/fichinter/card.php?id=" .
$object->id;
10606 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
10607 $substitutionarray[
'__ONLINE_SIGN_FICHINTER_URL__'] = getOnlineSignatureUrl(0,
'fichinter',
$object->ref, 1,
$object);
10609 if (is_object(
$object) &&
$object->element ==
'supplier_proposal') {
10610 '@phan-var-force SupplierProposal $object';
10612 $substitutionarray[
'__URL_SUPPLIER_PROPOSAL__'] = DOL_MAIN_URL_ROOT .
"/supplier_proposal/card.php?id=" .
$object->id;
10614 if (is_object(
$object) &&
$object->element ==
'invoice_supplier') {
10615 '@phan-var-force FactureFournisseur $object';
10617 $substitutionarray[
'__URL_SUPPLIER_INVOICE__'] = DOL_MAIN_URL_ROOT .
"/fourn/facture/card.php?id=" .
$object->id;
10619 if (is_object(
$object) &&
$object->element ==
'payment_supplier') {
10620 '@phan-var-force PaiementFourn $object';
10623 $liste_factures = [];
10626 $sql =
'SELECT f.ref,f.multicurrency_code as f_mccode, pf.*
10627 FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf
10628 JOIN '.MAIN_DB_PREFIX.
'facture_fourn as f ON pf.fk_facturefourn = f.rowid
10629 WHERE pf.fk_paiementfourn = '.((int)
$object->id);
10631 $resql = $db->query($sql);
10633 while ($objp = $db->fetch_object($resql)) {
10634 $liste_factures[] =
' - '.$outputlangs->trans(
'Invoice').
' '. $objp->ref.
' '.$outputlangs->trans(
'AmountPayed').
' '.
price($objp->multicurrency_amount, 0, $outputlangs, 0, -1, -1, $objp->multicurrency_code);
10637 $substitutionarray[
'__SUPPLIER_PAYMENT_INVOICES_LIST__'] = implode(
"\n", $liste_factures);
10639 $substitutionarray[
'__SUPPLIER_PAYMENT_INVOICES_TOTAL__'] =
price(
$object->multicurrency_amount, 0, $outputlangs, 0, -1, -1,
$object->multicurrency_code ?
$object->multicurrency_code : $conf->currency);
10642 '@phan-var-force Expedition $object';
10644 $substitutionarray[
'__URL_SHIPMENT__'] = DOL_MAIN_URL_ROOT .
"/expedition/card.php?id=" .
$object->id;
10649 '@phan-var-force ActionComm $object';
10651 $substitutionarray[
'__EVENT_LABEL__'] =
$object->label;
10652 $substitutionarray[
'__EVENT_DESCRIPTION__'] =
$object->note;
10653 $substitutionarray[
'__EVENT_TYPE__'] = $outputlangs->trans(
"Action" .
$object->type_code);
10654 $substitutionarray[
'__EVENT_DATE__'] =
dol_print_date(
$object->datep,
'day',
'auto', $outputlangs);
10655 $substitutionarray[
'__EVENT_TIME__'] =
dol_print_date(
$object->datep,
'hour',
'auto', $outputlangs);
10656 $substitutionarray[
'__EVENT_DATE_TZUSER__'] =
dol_print_date(
$object->datep,
'day',
'tzuserrel', $outputlangs);
10657 $substitutionarray[
'__EVENT_TIME_TZUSER__'] =
dol_print_date(
$object->datep,
'hour',
'tzuserrel', $outputlangs);
10662 if ((empty($exclude) || !in_array(
'objectamount', $exclude)) && (empty($include) || in_array(
'objectamount', $include))) {
10663 '@phan-var-force Facture|FactureRec $object';
10665 include_once DOL_DOCUMENT_ROOT .
'/core/lib/functionsnumtoword.lib.php';
10668 $substitutionarray[
'__DATE_DUE_YMD__'] = is_object(
$object) ? (isset(
$object->date_lim_reglement) ?
dol_print_date(
$object->date_lim_reglement,
'day',
false, $outputlangs) : null) :
'';
10670 $substitutionarray[
'__DATE_DUE_YMD_TEXT__'] = is_object(
$object) ? (isset(
$object->date_lim_reglement) ?
dol_print_date(
$object->date_lim_reglement,
'daytext',
false, $outputlangs) : null) :
'';
10672 $already_payed_all = 0;
10677 $substitutionarray[
'__AMOUNT_EXCL_TAX__'] = is_object(
$object) ?
$object->total_ht :
'';
10679 $substitutionarray[
'__AMOUNT_EXCL_TAX_TEXTCURRENCY__'] = is_object(
$object) ?
dol_convertToWord(
$object->total_ht, $outputlangs, $conf->currency,
true) :
'';
10681 $substitutionarray[
'__AMOUNT__'] = is_object(
$object) ?
$object->total_ttc :
'';
10683 $substitutionarray[
'__AMOUNT_TEXTCURRENCY__'] = is_object(
$object) ?
dol_convertToWord(
$object->total_ttc, $outputlangs, $conf->currency,
true) :
'';
10685 $substitutionarray[
'__AMOUNT_REMAIN__'] = is_object(
$object) ?
price2num(
$object->total_ttc - $already_payed_all,
'MT') :
'';
10687 $substitutionarray[
'__AMOUNT_VAT__'] = is_object(
$object) ? (isset(
$object->total_vat) ?
$object->total_vat :
$object->total_tva) :
'';
10691 $mysocuselocaltax1 =
false;
10692 $mysocuselocaltax2 =
false;
10694 $tmparray =
$mysoc->useLocalTax(-1);
10695 $mysocuselocaltax1 = $tmparray[1];
10696 $mysocuselocaltax2 = $tmparray[2];
10700 if ($onlykey != 2 || $mysocuselocaltax1) {
10701 $substitutionarray[
'__AMOUNT_TAX2__'] = is_object(
$object) ?
$object->total_localtax1 :
'';
10703 if ($onlykey != 2 || $mysocuselocaltax2) {
10704 $substitutionarray[
'__AMOUNT_TAX3__'] = is_object(
$object) ?
$object->total_localtax2 :
'';
10708 $substitutionarray[
'__AMOUNT_EXCL_TAX_FORMATTED__'] = is_object(
$object) ? (
$object->total_ht ?
price(
$object->total_ht, 0, $outputlangs, 0, -1, -1, $conf->currency) : null) :
'';
10709 $substitutionarray[
'__AMOUNT_FORMATTED__'] = is_object(
$object) ? (
$object->total_ttc ?
price(
$object->total_ttc, 0, $outputlangs, 0, -1, -1, $conf->currency) : null) :
'';
10710 $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) :
'';
10711 $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)) :
'';
10712 if ($onlykey != 2 || $mysocuselocaltax1) {
10713 $substitutionarray[
'__AMOUNT_TAX2_FORMATTED__'] = is_object(
$object) ? (
$object->total_localtax1 ?
price(
$object->total_localtax1, 0, $outputlangs, 0, -1, -1, $conf->currency) : null) :
'';
10715 if ($onlykey != 2 || $mysocuselocaltax2) {
10716 $substitutionarray[
'__AMOUNT_TAX3_FORMATTED__'] = is_object(
$object) ? (
$object->total_localtax2 ?
price(
$object->total_localtax2, 0, $outputlangs, 0, -1, -1, $conf->currency) : null) :
'';
10719 if ($onlykey != 2) {
10720 $substitutionarray[
'__AMOUNT_EXCL_TAX_FORMATED__'] = $substitutionarray[
'__AMOUNT_EXCL_TAX_FORMATTED__'];
10721 $substitutionarray[
'__AMOUNT_FORMATED__'] = $substitutionarray[
'__AMOUNT_FORMATTED__'];
10722 $substitutionarray[
'__AMOUNT_REMAIN_FORMATED__'] = $substitutionarray[
'__AMOUNT_REMAIN_FORMATTED__'];
10723 $substitutionarray[
'__AMOUNT_VAT_FORMATED__'] = $substitutionarray[
'__AMOUNT_VAT_FORMATTED__'];
10724 if ($mysocuselocaltax1) {
10725 $substitutionarray[
'__AMOUNT_TAX2_FORMATED__'] = $substitutionarray[
'__AMOUNT_TAX2_FORMATTED__'];
10727 if (
$mysoc->useLocalTax2) {
10728 $substitutionarray[
'__AMOUNT_TAX3_FORMATED__'] = $substitutionarray[
'__AMOUNT_TAX3_FORMATTED__'];
10732 $substitutionarray[
'__AMOUNT_MULTICURRENCY__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
$object->multicurrency_total_ttc :
'';
10733 $substitutionarray[
'__AMOUNT_MULTICURRENCY_FORMATED__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
price(
$object->multicurrency_total_ttc, 0, $outputlangs, 0, -1, -1,
$object->multicurrency_code) :
'';
10734 $substitutionarray[
'__AMOUNT_MULTICURRENCY_TEXT__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
dol_convertToWord(
$object->multicurrency_total_ttc, $outputlangs,
'',
true) :
'';
10735 $substitutionarray[
'__AMOUNT_MULTICURRENCY_TEXTCURRENCY__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
dol_convertToWord(
$object->multicurrency_total_ttc, $outputlangs,
$object->multicurrency_code,
true) :
'';
10736 $substitutionarray[
'__MULTICURRENCY_CODE__'] = (is_object(
$object) && isset(
$object->multicurrency_code)) ?
$object->multicurrency_code :
'';
10740 if ($onlykey != 2) {
10741 $substitutionarray[
'__TOTAL_TTC__'] = is_object(
$object) ?
$object->total_ttc :
'';
10742 $substitutionarray[
'__TOTAL_HT__'] = is_object(
$object) ?
$object->total_ht :
'';
10743 $substitutionarray[
'__TOTAL_VAT__'] = is_object(
$object) ? (isset(
$object->total_vat) ?
$object->total_vat :
$object->total_tva) :
'';
10748 if ((empty($exclude) || !in_array(
'date', $exclude)) && (empty($include) || in_array(
'date', $include))) {
10749 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
10759 $daytext = $outputlangs->trans(
'Day' . $tmp[
'wday']);
10761 $substitutionarray = array_merge($substitutionarray, array(
10762 '__NOW_TMS__' => (
string) $now,
10763 '__NOW_TMS_YMD__' =>
dol_print_date($now,
'day',
'auto', $outputlangs),
10764 '__DAY__' => (
string) $tmp[
'mday'],
10765 '__DAY_TEXT__' => $daytext,
10766 '__DAY_TEXT_SHORT__' =>
dol_trunc($daytext, 3,
'right',
'UTF-8', 1),
10767 '__DAY_TEXT_MIN__' =>
dol_trunc($daytext, 1,
'right',
'UTF-8', 1),
10768 '__MONTH__' => (
string) $tmp[
'mon'],
10769 '__MONTH_TEXT__' => $outputlangs->trans(
'Month' . sprintf(
"%02d", $tmp[
'mon'])),
10770 '__MONTH_TEXT_SHORT__' => $outputlangs->trans(
'MonthShort' . sprintf(
"%02d", $tmp[
'mon'])),
10771 '__MONTH_TEXT_MIN__' => $outputlangs->trans(
'MonthVeryShort' . sprintf(
"%02d", $tmp[
'mon'])),
10772 '__YEAR__' => (
string) $tmp[
'year'],
10773 '__YEAR_PREVIOUS_MONTH__' => (
string) $tmp3[
'year'],
10774 '__YEAR_NEXT_MONTH__' => (
string) $tmp5[
'year'],
10775 '__PREVIOUS_DAY__' => (
string) $tmp2[
'day'],
10776 '__PREVIOUS_MONTH__' => (
string) $tmp3[
'month'],
10777 '__PREVIOUS_MONTH_TEXT__' => $outputlangs->trans(
'Month' . sprintf(
"%02d", $tmp3[
'month'])),
10778 '__PREVIOUS_MONTH_TEXT_SHORT__' => $outputlangs->trans(
'MonthShort' . sprintf(
"%02d", $tmp3[
'month'])),
10779 '__PREVIOUS_MONTH_TEXT_MIN__' => $outputlangs->trans(
'MonthVeryShort' . sprintf(
"%02d", $tmp3[
'month'])),
10780 '__PREVIOUS_YEAR__' => (
string) ($tmp[
'year'] - 1),
10781 '__NEXT_DAY__' => (
string) $tmp4[
'day'],
10782 '__NEXT_MONTH__' => (
string) $tmp5[
'month'],
10783 '__NEXT_MONTH_TEXT__' => $outputlangs->trans(
'Month' . sprintf(
"%02d", $tmp5[
'month'])),
10784 '__NEXT_MONTH_TEXT_SHORT__' => $outputlangs->trans(
'MonthShort' . sprintf(
"%02d", $tmp5[
'month'])),
10785 '__NEXT_MONTH_TEXT_MIN__' => $outputlangs->trans(
'MonthVeryShort' . sprintf(
"%02d", $tmp5[
'month'])),
10786 '__NEXT_YEAR__' => (
string) ($tmp[
'year'] + 1),
10791 $substitutionarray = array_merge($substitutionarray, array(
'__ENTITY_ID__' => $conf->entity));
10793 if ((empty($exclude) || !in_array(
'system', $exclude)) && (empty($include) || in_array(
'user', $include))) {
10794 $substitutionarray[
'__DOL_MAIN_URL_ROOT__'] = DOL_MAIN_URL_ROOT;
10795 $substitutionarray[
'__(AnyTranslationKey)__'] = $outputlangs->trans(
'TranslationOfKey');
10796 $substitutionarray[
'__(AnyTranslationKey|langfile)__'] = $outputlangs->trans(
'TranslationOfKey') .
' (load also language file before)';
10797 $substitutionarray[
'__[AnyConstantKey]__'] = $outputlangs->trans(
'ValueOfConstantKey');
10802 return $substitutionarray;
10821function make_substitutions($text, $substitutionarray, $outputlangs =
null, $converttextinhtmlifnecessary = 0)
10823 global $db, $langs;
10825 if (!is_array($substitutionarray)) {
10826 return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions';
10829 if (empty($outputlangs)) {
10830 $outputlangs = $langs;
10840 if (is_object($outputlangs)) {
10842 while (preg_match(
'/__\(([^\)]+)\)__/', $text, $reg)) {
10844 $tmp = explode(
'|', $reg[1]);
10845 if (!empty($tmp[1])) {
10846 $outputlangs->load($tmp[1]);
10849 $value = $outputlangs->transnoentitiesnoconv($reg[1]);
10851 if (empty($converttextinhtmlifnecessary)) {
10853 $text = preg_replace(
'/__\(' . preg_quote($reg[1],
'/') .
'\)__/', $msgishtml ?
dol_htmlentitiesbr($value) : $value, $text);
10855 if (! $msgishtml) {
10859 if ($valueishtml) {
10867 $text = preg_replace(
'/__\(' . preg_quote($reg[1],
'/') .
'\)__/', $value, $text);
10875 while (preg_match(
'/__\[([^\]]+)\]__/', $text, $reg)) {
10876 $originalkeyfound = $reg[1];
10877 $keyfound = preg_replace(
'/\|urlencode$/',
'', $originalkeyfound);
10880 $value =
'*****forbidden*****';
10884 if (preg_match(
'/\|urlencode$/', $originalkeyfound)) {
10885 $value = urlencode($value);
10889 if (empty($converttextinhtmlifnecessary)) {
10891 $text = preg_replace(
'/__\[' . preg_quote($originalkeyfound,
'/') .
'\]__/', $msgishtml ?
dol_htmlentitiesbr($value) : $value, $text);
10893 if (! $msgishtml) {
10896 if ($valueishtml) {
10904 $text = preg_replace(
'/__\[' . preg_quote($originalkeyfound,
'/') .
'\]__/', $value, $text);
10909 foreach ($substitutionarray as $key => $value) {
10910 if (!isset($value)) {
10914 if (
getDolGlobalString(
'MAIN_MAIL_DO_NOT_USE_SIGN') && ($key ==
'__USER_SIGNATURE__' || $key ==
'__SENDEREMAIL_SIGNATURE__')) {
10918 if (empty($converttextinhtmlifnecessary)) {
10919 $text = str_replace((
string) $key, (
string) $value, $text);
10921 if (! $msgishtml) {
10924 if ($valueishtml) {
10931 $text = str_replace((
string) $key, (
string) $value, $text);
10947 $memory_object_list = array();
10948 foreach ($substitutionarray as $key => $value) {
10949 $lazy_load_arr = array();
10950 if (preg_match(
'/(__[A-Z\_]+__)@lazyload$/', $key, $lazy_load_arr)) {
10951 if (isset($lazy_load_arr[1]) && !empty($lazy_load_arr[1])) {
10952 $key_to_substitute = $lazy_load_arr[1];
10953 if (preg_match(
'/' . preg_quote($key_to_substitute,
'/') .
'/', $text)) {
10954 $param_arr = explode(
':', (
string) $value);
10956 if (count($param_arr) == 4) {
10957 $path = $param_arr[0];
10958 $class = $param_arr[1];
10959 $method = $param_arr[2];
10960 $id = (int) $param_arr[3];
10963 if (!isset($memory_object_list[$class])) {
10965 require_once DOL_DOCUMENT_ROOT . $path;
10966 if (class_exists($class)) {
10967 $memory_object_list[$class] = array(
10975 if (isset($memory_object_list[$class]) && isset($memory_object_list[$class][
'list'])) {
10976 if (method_exists($class, $method)) {
10977 if (!isset($memory_object_list[$class][
'list'][
$id])) {
10978 $tmpobj =
new $class($db);
10980 $valuetouseforsubstitution = $tmpobj->$method(
$id, $key_to_substitute);
10981 $memory_object_list[$class][
'list'][
$id] = $tmpobj;
10984 $tmpobj = $memory_object_list[$class][
'list'][
$id];
10986 $valuetouseforsubstitution = $tmpobj->$method(
$id, $key_to_substitute,
true);
10989 $text = str_replace((
string) $key_to_substitute, (
string) $valuetouseforsubstitution, $text);
11015 global $conf, $user;
11017 require_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
11022 $dirsubstitutions = array_merge(array(), (array) $conf->modules_parts[
'substitutions']);
11024 foreach ($dirsubstitutions as $reldir) {
11032 $substitfiles =
dol_dir_list($dir,
'files', 0,
'functions_');
11033 foreach ($substitfiles as $substitfile) {
11035 if (preg_match(
'/functions_(.*)\.lib\.php/i', $substitfile[
'name'], $reg)) {
11038 dol_syslog(
"Library " . $substitfile[
'name'] .
" found into " . $dir);
11040 require_once $dir . $substitfile[
'name'];
11042 $function_name = $module .
"_" . $callfunc;
11043 if (function_exists($function_name)) {
11044 $function_name($substitutionarray, $outputlangs,
$object, $parameters);
11052 foreach ($substitutionarray as $key => $value) {
11053 $tags .=
'{' . $key .
'} => ' . $value .
"\n";
11055 $substitutionarray = array_merge($substitutionarray, array(
'__ALL_TAGS__' => $tags));
11068function print_date_range($date_start, $date_end, $format =
'', $outputlangs =
null)
11070 print
get_date_range($date_start, $date_end, $format, $outputlangs);
11083function get_date_range($date_start, $date_end, $format =
'', $outputlangs =
null, $withparenthesis = 1)
11089 if (!is_object($outputlangs)) {
11090 $outputlangs = $langs;
11093 if ($date_start && $date_end) {
11094 $out .= ($withparenthesis ? ($withparenthesis == 1 ?
' ' :
'').
'(' :
'') . $outputlangs->transnoentitiesnoconv(
'DateFromTo',
dol_print_date($date_start, $format, false, $outputlangs),
dol_print_date($date_end, $format, false, $outputlangs)) . ($withparenthesis ?
')' :
'');
11096 if ($date_start && !$date_end) {
11097 $out .= ($withparenthesis ? ($withparenthesis == 1 ?
' ' :
'').
'(' :
'') . $outputlangs->transnoentitiesnoconv(
'DateFrom',
dol_print_date($date_start, $format, false, $outputlangs)) . ($withparenthesis ?
')' :
'');
11099 if (!$date_start && $date_end) {
11100 $out .= ($withparenthesis ? ($withparenthesis == 1 ?
' ' :
'').
'(' :
'') . $outputlangs->transnoentitiesnoconv(
'DateUntil',
dol_print_date($date_end, $format, false, $outputlangs)) . ($withparenthesis ?
')' :
'');
11118 if ($nameorder < 0) {
11121 if ($nameorder == 1) {
11122 $ret .= $firstname;
11123 if ($firstname && $lastname) {
11127 } elseif ($nameorder == 2 || $nameorder == 3) {
11128 $ret .= $firstname;
11129 if (empty($ret) && $nameorder == 3) {
11134 if (empty($ret) && $nameorder == 5) {
11135 $ret .= $firstname;
11137 if ($nameorder == 0) {
11138 if ($firstname && $lastname) {
11141 $ret .= $firstname;
11160function setEventMessage($mesgs, $style =
'mesgs', $noduplicate = 0, $attop = 0)
11163 if (!is_array($mesgs)) {
11164 $mesgs = trim((
string) $mesgs);
11167 if (!empty($noduplicate) && isset($_SESSION[
'dol_events'][$style]) && in_array($mesgs, $_SESSION[
'dol_events'][$style])) {
11171 array_unshift($_SESSION[
'dol_events'][$style], $mesgs);
11173 $_SESSION[
'dol_events'][$style][] = $mesgs;
11178 foreach ($mesgs as $mesg) {
11179 $mesg = trim((
string) $mesg);
11181 if (!empty($noduplicate) && isset($_SESSION[
'dol_events'][$style]) && in_array($mesg, $_SESSION[
'dol_events'][$style])) {
11185 array_unshift($_SESSION[
'dol_events'][$style], $mesgs);
11187 $_SESSION[
'dol_events'][$style][] = $mesg;
11207function setEventMessages($mesg, $mesgs, $style =
'mesgs', $messagekey =
'', $noduplicate = 0, $attop = 0)
11209 if (empty($mesg) && empty($mesgs)) {
11217 if (empty($messagekey) || empty($_COOKIE[
"DOLUSER_HIDEMESSAGE" . $messagekey])) {
11218 if (!in_array((
string) $style, array(
'mesgs',
'warnings',
'errors'))) {
11219 dol_print_error(
null,
'Bad parameter style=' . $style .
' for setEventMessages');
11221 if (empty($mesgs)) {
11224 if (!empty($mesg) && !in_array($mesg, $mesgs)) {
11245 if (isset($_SESSION[
'dol_events'][
'mesgs'])) {
11246 if (empty($disabledoutputofmessages)) {
11249 unset($_SESSION[
'dol_events'][
'mesgs']);
11252 if (isset($_SESSION[
'dol_events'][
'errors'])) {
11253 if (empty($disabledoutputofmessages)) {
11256 unset($_SESSION[
'dol_events'][
'errors']);
11260 if (isset($_SESSION[
'dol_events'][
'warnings'])) {
11261 if (empty($disabledoutputofmessages)) {
11264 unset($_SESSION[
'dol_events'][
'warnings']);
11282function get_htmloutput_mesg($mesgstring =
'', $mesgarray = [], $style =
'ok', $keepembedded = 0)
11284 global $conf, $langs;
11289 $divstart = $divend =
'';
11292 if ((empty($conf->use_javascript_ajax) ||
getDolGlobalString(
'MAIN_DISABLE_JQUERY_JNOTIFY') || $keepembedded) && !preg_match(
'/<div class=".*">/i', $out)) {
11293 $divstart =
'<div class="' . $style .
' clearboth">';
11294 $divend =
'</div>';
11297 if ((is_array($mesgarray) && count($mesgarray)) || $mesgstring) {
11298 $langs->load(
"errors");
11300 if (is_array($mesgarray) && count($mesgarray)) {
11301 foreach ($mesgarray as $message) {
11303 $out .= $langs->trans($message);
11304 if ($ret < count($mesgarray)) {
11311 $out .= $langs->trans($mesgstring);
11317 if (!empty($conf->use_javascript_ajax) && !
getDolGlobalString(
'MAIN_DISABLE_JQUERY_JNOTIFY') && empty($keepembedded)) {
11318 $return =
'<script nonce="' .
getNonce() .
'">
11319 $(document).ready(function() {
11320 /* jnotify(message, preset of message type, keepmessage) */
11321 $.jnotify("' .
dol_escape_js($out) .
'", "' . ($style ==
"ok" ? 3000 : $style) .
'", ' . ($style ==
"ok" ?
"false" :
"true") .
',{ remove: function (){} } );
11361function dol_htmloutput_mesg($mesgstring =
'', $mesgarray = array(), $style =
'ok', $keepembedded = 0)
11363 if (empty($mesgstring) && (!is_array($mesgarray) || count($mesgarray) == 0)) {
11369 if (is_array($mesgarray)) {
11370 foreach ($mesgarray as $val) {
11371 if ($val && preg_match(
'/class="error"/i', $val)) {
11375 if ($val && preg_match(
'/class="warning"/i', $val)) {
11380 } elseif ($mesgstring && preg_match(
'/class="error"/i', $mesgstring)) {
11382 } elseif ($mesgstring && preg_match(
'/class="warning"/i', $mesgstring)) {
11385 if ($style ==
'error' || $style ==
'errors') {
11388 if ($style ==
'warning' || $style ==
'warnings') {
11392 if ($iserror || $iswarning) {
11394 $mesgstring = preg_replace(
'/<\/div><div class="(error|warning)">/',
'<br>', $mesgstring);
11395 $mesgstring = preg_replace(
'/<div class="(error|warning)">/',
'', $mesgstring);
11396 $mesgstring = preg_replace(
'/<\/div>/',
'', $mesgstring);
11398 if (is_array($mesgarray)) {
11399 $newmesgarray = array();
11400 foreach ($mesgarray as $val) {
11401 if (is_string($val)) {
11402 $tmpmesgstring = preg_replace(
'/<\/div><div class="(error|warning)">/',
'<br>', $val);
11403 $tmpmesgstring = preg_replace(
'/<div class="(error|warning)">/',
'', $tmpmesgstring);
11404 $tmpmesgstring = preg_replace(
'/<\/div>/',
'', $tmpmesgstring);
11405 $newmesgarray[] = $tmpmesgstring;
11407 dol_syslog(
"Error call of dol_htmloutput_mesg with an array with a value that is not a string", LOG_WARNING);
11410 $mesgarray = $newmesgarray;
11412 print
get_htmloutput_mesg($mesgstring, $mesgarray, ($iserror ?
'error' :
'warning'), $keepembedded);
11454function dol_sort_array(&$array, $index, $order =
'asc', $natsort = 0, $case_sensitive = 0, $keepindex = 0)
11457 $order = strtolower($order);
11459 if (is_array($array)) {
11460 $sizearray = count($array);
11461 if ($sizearray > 0) {
11464 foreach (array_keys($array) as $key) {
11465 $tmpmultikey = explode(
',', $index);
11466 $newindex = $tmpmultikey[0];
11467 if (is_object($array[$key])) {
11468 $temp[$key] = empty($array[$key]->$newindex) ? 0 : $array[$key]->$newindex;
11470 if (!empty($tmpmultikey[1])) {
11471 $newindex = $tmpmultikey[1];
11472 $temp[$key] .=
'__' . (empty($array[$key]->$newindex) ? 0 : $array[$key]->$newindex);
11476 $temp[$key] = empty($array[$key][$newindex]) ? 0 : $array[$key][$newindex];
11478 if (!empty($tmpmultikey[1])) {
11479 $newindex = $tmpmultikey[1];
11481 $temp[$key] .=
'__' . (empty($array[$key][$newindex]) ? 0 : $array[$key][$newindex]);
11484 if ($natsort == -1) {
11485 $temp[$key] =
'___' . $temp[$key];
11488 if (empty($natsort) || $natsort == -1) {
11489 if ($order ==
'asc') {
11495 if ($case_sensitive) {
11498 natcasesort($temp);
11500 if ($order !=
'asc') {
11501 $temp = array_reverse($temp,
true);
11507 foreach (array_keys($temp) as $key) {
11508 (is_numeric($key) && empty($keepindex)) ? $sorted[] = $array[$key] : $sorted[$key] = $array[$key];
11527 $str = (string) $str;
11530 $strLength = strlen($str);
11531 for ($i = 0; $i < $strLength; $i++) {
11532 if (ord($str[$i]) < 0x80) {
11534 } elseif ((ord($str[$i]) & 0xE0) == 0xC0) {
11536 } elseif ((ord($str[$i]) & 0xF0) == 0xE0) {
11538 } elseif ((ord($str[$i]) & 0xF8) == 0xF0) {
11540 } elseif ((ord($str[$i]) & 0xFC) == 0xF8) {
11542 } elseif ((ord($str[$i]) & 0xFE) == 0xFC) {
11547 for ($j = 0; $j < $n; $j++) {
11548 if ((++$i == strlen($str)) || ((ord($str[$i]) & 0xC0) != 0x80)) {
11569 return preg_match(
'//u', $str) ? true :
false;
11581 if (function_exists(
'mb_check_encoding')) {
11583 if (!mb_check_encoding($str,
'ASCII')) {
11587 if (preg_match(
'/[^\x00-\x7f]/', $str)) {
11605 $tmp = ini_get(
"unicode.filesystem_encoding");
11606 if (empty($tmp) && !empty($_SERVER[
"WINDIR"])) {
11607 $tmp =
'iso-8859-1';
11616 if ($tmp ==
'iso-8859-1') {
11617 return mb_convert_encoding($str,
'ISO-8859-1',
'UTF-8');
11638function dol_getIdFromCode($db, $key, $tablename, $fieldkey =
'code', $fieldid =
'id', $entityfilter = 0, $filters =
'', $useCache =
true)
11648 if ($useCache && isset($conf->cache[
'codeid'][$tablename][$key][$fieldid])) {
11649 return $conf->cache[
'codeid'][$tablename][$key][$fieldid];
11652 dol_syslog(
'dol_getIdFromCode (value for field ' . $fieldid .
' from key ' . $key .
' not found into cache)', LOG_DEBUG);
11654 $sql =
"SELECT " . $fieldid .
" as valuetoget";
11655 $sql .=
" FROM " . MAIN_DB_PREFIX . $tablename;
11656 if ($fieldkey ==
'id' || $fieldkey ==
'rowid') {
11657 $sql .=
" WHERE " . $fieldkey .
" = " . ((int) $key);
11659 $sql .=
" WHERE " . $fieldkey .
" = '" . $db->escape($key) .
"'";
11661 if (!empty($entityfilter)) {
11662 $sql .=
" AND entity IN (" .
getEntity($tablename) .
")";
11668 $resql = $db->query($sql);
11670 $obj = $db->fetch_object($resql);
11673 $valuetoget = $obj->valuetoget;
11674 $conf->cache[
'codeid'][$tablename][$key][$fieldid] = $valuetoget;
11676 $conf->cache[
'codeid'][$tablename][$key][$fieldid] =
'';
11680 return $valuetoget;
11700 $regextext = preg_replace(
'#^/\^?#',
'', (
string) $regextext);
11701 $regextext = preg_replace(
'#\$?/[imsxuADSUXJ]*$#',
'', $regextext);
11703 if ($matchrule == 1) {
11704 if ($var ==
'mainmenu') {
11706 return (preg_match(
'/^' . $regextext .
'/', $mainmenu));
11707 } elseif ($var ==
'leftmenu') {
11709 return (preg_match(
'/^' . $regextext .
'/', $leftmenu));
11711 return 'This variable is not accessible with dol_eval';
11714 return 'This value '.$matchrule.
' for param $matchrule is not yet implemented';
11728function verifCond($strToEvaluate, $onlysimplestring =
'1')
11732 if (isset($strToEvaluate) && $strToEvaluate !==
'') {
11735 $rep =
dol_eval($strToEvaluate, 1, 1, $onlysimplestring);
11737 $rights = (bool) $rep && (!is_string($rep) || strpos($rep,
'Bad string syntax to evaluate') ===
false);
11757function dol_eval($s, $returnvalue = 1, $hideerrors = 1, $onlysimplestring =
'1')
11759 if ($returnvalue != 1) {
11760 dol_syslog(
"Use of dol_eval with parameter returnvalue = 0 is now forbidden. Please fix this", LOG_ERR);
11783 $db, $langs, $user, $website, $websitepage,
11784 $action, $mainmenu, $leftmenu,
11793 defined(
'T_COALESCE_EQUAL') || define(
'T_COALESCE_EQUAL', PHP_INT_MAX);
11794 defined(
'T_FN') || define(
'T_FN', PHP_INT_MAX);
11797 defined(
'T_ATTRIBUTE') || define(
'T_ATTRIBUTE', PHP_INT_MAX);
11798 defined(
'T_MATCH') || define(
'T_MATCH', PHP_INT_MAX);
11799 defined(
'T_NAME_FULLY_QUALIFIED') || define(
'T_NAME_FULLY_QUALIFIED', PHP_INT_MAX);
11800 defined(
'T_NAME_QUALIFIED') || define(
'T_NAME_QUALIFIED', PHP_INT_MAX);
11801 defined(
'T_NAME_RELATIVE') || define(
'T_NAME_RELATIVE', PHP_INT_MAX);
11804 defined(
'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG') || define(
'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG', PHP_INT_MAX);
11805 defined(
'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG') || define(
'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG', PHP_INT_MAX);
11806 defined(
'T_ENUM') || define(
'T_ENUM', PHP_INT_MAX);
11807 defined(
'T_READONLY') || define(
'T_READONLY', PHP_INT_MAX);
11810 defined(
'T_PRIVATE_SET') || define(
'T_PRIVATE_SET', PHP_INT_MAX);
11811 defined(
'T_PROTECTED_SET') || define(
'T_PROTECTED_SET', PHP_INT_MAX);
11812 defined(
'T_PUBLIC_SET') || define(
'T_PUBLIC_SET', PHP_INT_MAX);
11814 $prohibited_token_ids = [
11821 'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG',
11822 'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG',
11872 'T_OPEN_TAG_WITH_ECHO',
11906 $prohibited_variables = [
11918 $prohibited_functions = [
11921 'override_function',
11923 'session_create_id',
11924 'session_regenerate_id',
11926 'call_user_func_array',
11935 'dol_eval_standard',
11943 'mb_eregi_replace',
11944 'dol_compress_dir',
11948 'dol_delete_dir_recursive',
11950 'archiveOrBackupFile',
11952 'file_put_contents',
11966 'filter_input_array',
11970 $prohibited_token_arrangements = [
11975 ' T_CONSTANT_ENCAPSED_STRING ( ',
11979 $tokens = token_get_all(
"<?php return {$s};", TOKEN_PARSE);
11981 $tokens_arrangement =
' ';
11983 for ($i = 2,
$c = count($tokens) - 1; $i <
$c; ++$i) {
11984 if (is_array($tokens[$i])) {
11985 $token_id = $tokens[$i][0];
11986 $token_value = $tokens[$i][1];
11987 $token_name = token_name($tokens[$i][0]);
11989 $token_id = $tokens[$i];
11990 $token_value = $tokens[$i];
11991 $token_name = $tokens[$i];
11995 if (T_WHITESPACE === $token_id) {
12000 $tokens_arrangement .=
"{$token_name} ";
12004 T_VARIABLE === $token_id
12005 && in_array($token_value, $prohibited_variables,
true)
12007 return "« {$token_value} » is prohibited in « {$s} »";
12012 T_STRING === $token_id
12013 && in_array($token_value, $prohibited_functions,
true)
12015 return "« {$token_value} » is prohibited in « {$s} »";
12020 $maxi = count($prohibited_token_ids);
12021 for ($i = 0; $i < $maxi; ++$i) {
12022 if (
false !== strpos($tokens_arrangement,
" {$prohibited_token_ids[$i]} ")) {
12023 return "« {$prohibited_token_ids[$i]} » is prohibited in « {$s} »";
12028 $maxi = count($prohibited_token_arrangements);
12029 for ($i = 0; $i < $maxi; ++$i) {
12030 if (
false !== strpos($tokens_arrangement, $prohibited_token_arrangements[$i])) {
12031 return "« {$prohibited_token_arrangements[$i]} » is prohibited in « {$s} »";
12037 return @eval(
"return {$s};") ??
'';
12038 }
catch (Throwable $ex) {
12039 return "Exception during evaluation: " . $s .
" - " . $ex->getMessage();
12062 global $db, $langs, $user, $website, $websitepage;
12063 global $action, $mainmenu, $leftmenu;
12065 global $objectoffield;
12073 $isObBufferActive =
false;
12074 if ($onlysimplestring ==
'0') {
12075 $onlysimplestring =
'1';
12077 if (!in_array($onlysimplestring, array(
'1',
'2'))) {
12078 return "Bad call of dol_eval. Parameter onlysimplestring must be '1' or '2'.";
12080 if (!is_scalar($s)) {
12081 return "Bad call of dol_eval. First parameter must be a string, found ".var_export($s,
true);
12085 global $dolibarr_main_restrict_eval_methods;
12088 if (!isset($dolibarr_main_restrict_eval_methods)) {
12089 $dolibarr_main_restrict_eval_methods =
'getDolGlobalString, getDolGlobalInt, getDolCurrency, getDolEntity, getDolDBType, fetchNoCompute, hasRight, isAdmin, isModEnabled, isStringVarMatching, abs, min, max, round, dol_now, preg_match';
12092 $dolibarr_main_restrict_eval_methods_array = explode(
',', str_replace(
" ",
"", $dolibarr_main_restrict_eval_methods));
12100 $specialcharsallowed =
'^$_+-.*>&|=!?():"\',/@';
12101 if ($onlysimplestring ==
'2') {
12102 $specialcharsallowed .=
'<[]';
12104 global $dolibarr_main_allow_unsecured_special_chars_in_dol_eval;
12105 if (!empty($dolibarr_main_allow_unsecured_special_chars_in_dol_eval)) {
12106 $specialcharsallowed .= (string) $dolibarr_main_allow_unsecured_special_chars_in_dol_eval;
12108 if (preg_match(
'/[^a-z0-9\s' . preg_quote($specialcharsallowed,
'/') .
']/i', $s)) {
12109 return 'Bad string syntax to evaluate (found chars that are not chars for a simple one line clean eval string): ' . $s;
12121 if (strpos($s,
'/*') !==
false || strpos($s,
'//') !==
false) {
12122 return 'Bad string syntax to evaluate (The comment string /* and // are not allowed): ' . $s;
12126 $tmps = str_replace(
' ? ',
'__XXX__', $s);
12127 if (strpos($tmps,
'?') !==
false) {
12128 return 'Bad string syntax to evaluate (The char ? can be used only with a space before and after): ' . $s;
12132 if (preg_match(
'/<=?[^\s]/', $s)) {
12133 return 'Bad string syntax to evaluate (mode ' . $onlysimplestring .
', found a < or <= without space after): ' . $s;
12137 if (preg_match(
'/\$[\w]*\s*\(/', $s)) {
12138 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;
12141 if (empty($dolibarr_main_restrict_eval_methods)) {
12147 while ($scheck && $savescheck != $scheck) {
12148 $savescheck = $scheck;
12149 $scheck = preg_replace(
'/->[a-zA-Z0-9_]+\(/',
'->__METHOD__', $scheck);
12150 $scheck = preg_replace(
'/::[a-zA-Z0-9_]+\(/',
'->__METHOD__', $scheck);
12151 $scheck = preg_replace(
'/^\(+/',
'__PARENTHESIS__ ', $scheck);
12152 $scheck = preg_replace(
'/\&\&\s+\(/',
'__ANDPARENTHESIS__ ', $scheck);
12153 $scheck = preg_replace(
'/\|\|\s+\(/',
'__ORPARENTHESIS__ ', $scheck);
12154 $scheck = preg_replace(
'/^!?[a-zA-Z0-9_]+\(/',
'__FUNCTION__', $scheck);
12155 $scheck = preg_replace(
'/\s!?[a-zA-Z0-9_]+\(/',
'__FUNCTION__', $scheck);
12156 $scheck = preg_replace(
'/^!\(/',
'__NOTANDPARENTHESIS__', $scheck);
12157 $scheck = preg_replace(
'/\s!\(/',
' __NOTANDPARENTHESIS__', $scheck);
12158 $scheck = preg_replace(
'/(\^|\')\(/',
'__REGEXSTART__', $scheck);
12163 if (strpos($scheck,
'(') !==
false) {
12164 return 'Bad string syntax to evaluate (mode ' . $onlysimplestring .
', found call of a function or method without using the direct name of the function): ' . $s;
12168 if (strpos($s,
'`') !==
false) {
12169 return 'Bad string syntax to evaluate (backtick char is forbidden): ' . $s;
12174 if (preg_match(
'/[^0-9]+\.[^0-9]+/', $s)) {
12175 return 'Bad string syntax to evaluate (dot char is forbidden if not strictly between 2 numbers): ' . $s;
12183 while ($scheck && $savescheck != $scheck) {
12184 $savescheck = $scheck;
12185 $scheck = preg_replace(
'/\$conf->[a-z\_]+->enabled/',
'__VARCONFENABLED__', $scheck);
12186 $scheck = preg_replace(
'/\$user->id/',
'__VARUSERID__', $scheck);
12187 $scheck = preg_replace(
'/\$user->hasRight/',
'__VARUSERHASRIGHT__', $scheck);
12188 $scheck = preg_replace(
'/\$user->rights/',
'__VARUSERHASRIGHT__', $scheck);
12189 $scheck = preg_replace(
'/\$user->admin/',
'__VARUSERISADMIN__', $scheck);
12190 $scheck = preg_replace(
'/\(\$db\)/',
'__VARDB__', $scheck);
12191 $scheck = preg_replace(
'/\$langs/',
'__VARLANGSTRANS__', $scheck);
12192 $scheck = preg_replace(
'/\$mysoc/',
'__VARMYSOC__', $scheck);
12193 $scheck = preg_replace(
'/\$action/',
'__VARACTION__', $scheck);
12194 $scheck = preg_replace(
'/\$mainmenu/',
'__VARMAINMENU__', $scheck);
12195 $scheck = preg_replace(
'/\$leftmenu/',
'__VARLEFTMENU__', $scheck);
12196 $scheck = preg_replace(
'/\$websitepage/',
'__VARWEBSITEPAGE__', $scheck);
12197 $scheck = preg_replace(
'/\$website/',
'__VARWEBSITE__', $scheck);
12198 $scheck = preg_replace(
'/\$objectoffield/',
'__VAROBJECTOFFIELD__', $scheck);
12199 $scheck = preg_replace(
'/\$object/',
'__VAROBJECT__', $scheck);
12200 $scheck = preg_replace(
'/\$var/',
'__VARVAR__', $scheck);
12203 $scheck = preg_replace(
'/\$soc->canvas/',
'__VARSOCCANVAS__', $scheck);
12204 $scheck = preg_replace(
'/\$obj->canvas/',
'__VAROBJCANVAS__', $scheck);
12207 if (strpos($scheck,
'$') !==
false) {
12208 dol_syslog(
'Bad string syntax to evaluate (found use of $ not matching pattern: $user->hasRight, ($db), $langs, $mysoc, $action, $mainmenu, $leftmenu, $website, $websitepage, $objectoffield or $var123): ' . $s, LOG_WARNING);
12209 return 'Bad string syntax to evaluate (found use of $ not matching pattern: $user->hasRight, ($db), $langs, $mysoc, $action, $mainmenu, $leftmenu, $website, $websitepage, $objectoffield or $var123): ' . $s;
12214 $forbiddenphpstrings = array(
'_ENV',
'_SESSION',
'_COOKIE',
'_GET',
'_GLOBAL',
'_POST',
'_REQUEST',
'ReflectionFunction',
'SplFileObject',
'SplTempFileObject');
12216 if (empty($dolibarr_main_restrict_eval_methods)) {
12220 $forbiddenphpfunctions = array();
12221 $forbiddenphpmethods = array();
12223 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"override_function",
"session_id",
"session_create_id",
"session_regenerate_id"));
12224 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"get_defined_functions",
"get_defined_vars",
"get_defined_constants",
"get_declared_classes"));
12225 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"function",
"call_user_func",
"call_user_func_array"));
12227 $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"));
12228 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"usort",
"uasort",
"uksort",
"preg_replace_callback",
"preg_replace_callback_array",
"header_register_callback"));
12229 $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"));
12230 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"spl_autoload_register",
"spl_autoload_unregister",
"iterator_apply",
"session_set_save_handler"));
12231 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"forward_static_call",
"forward_static_call_array",
"register_postsend_function"));
12233 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"ob_start"));
12235 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"require",
"include",
"require_once",
"include_once"));
12236 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"exec",
"passthru",
"shell_exec",
"system",
"proc_open",
"popen"));
12237 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"pcntl_alarm",
"pcntl_exec",
"pcntl_fork",
"pcntl_waitpid",
"pcntl_wait",
"pcntl_wifexited",
"pcntl_wifstopped",
"pcntl_wifsignaled",
"pcntl_wifcontinued",
"pcntl_wexitstatus",
"pcntl_wtermsig",
"pcntl_wstopsig",
"pcntl_signal"));
12238 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"pcntl_signal_get_handler",
"pcntl_signal_dispatch",
"pcntl_get_last_error",
"pcntl_strerror",
"pcntl_sigprocmask",
"pcntl_sigwaitinfo",
"pcntl_sigtimedwait",
"pcntl_getpriority",
"pcntl_async_signals",
"pcntl_unshare", ));
12239 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"putenv",
"dl",
"apache_child_terminate",
"apache_setenv"));
12240 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"posix_kill",
"posix_setuid",
"posix_setgid"));
12241 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_eval",
"dol_eval_new",
"dol_eval_standard",
"executeCLI",
"verifCond",
"GETPOST",
"dolEncrypt",
"dolDecrypt"));
12242 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"eval",
"create_function",
"assert",
"mb_ereg_replace"));
12243 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"readline_completion_function",
"readline_callback_handler_install"));
12244 $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"));
12245 $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"));
12246 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"require",
"include"));
12249 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"base64" .
"_" .
"decode",
"rawurl" .
"decode",
"url" .
"decode",
"str" .
"_rot13",
"hex" .
"2bin",
"printf",
"sprintf"));
12250 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_concat",
"dol_concatdesc"));
12259 $forbiddenphpmethods = array_merge($forbiddenphpmethods, array(
'invoke',
'invokeArgs'));
12267 $forbiddenphpregex =
'global\s*\$';
12268 $forbiddenphpregex .=
'|';
12269 $forbiddenphpregex .=
'\b(' . implode(
'|', $forbiddenphpfunctions) .
')\b';
12271 $forbiddenphpmethodsregex =
'->(' . implode(
'|', $forbiddenphpmethods) .
')';
12275 $oldstringtoclean = $s;
12276 $s = str_ireplace($forbiddenphpstrings,
'__forbiddenstring__', $s);
12277 $s = preg_replace(
'/' . $forbiddenphpregex .
'/i',
'__forbiddenstring__', $s);
12278 $s = preg_replace(
'/' . $forbiddenphpmethodsregex .
'/i',
'__forbiddenstring__', $s);
12280 }
while ($oldstringtoclean != $s);
12282 if (strpos($s,
'__forbiddenstring__') !==
false) {
12283 dol_syslog(
'Bad string syntax to evaluate: ' . $s, LOG_WARNING);
12284 return 'Bad string syntax to evaluate: ' . $s;
12288 if (!empty($dolibarr_main_restrict_eval_methods)) {
12291 $pattern =
'/([\s\w\'\]\"]+)\(/';
12293 $matches = array();
12294 preg_match_all($pattern, $s, $matches);
12296 if (count($matches)) {
12297 foreach ($matches[1] as $m) {
12303 if (!preg_match(
'/new ([A-Z][\w]+)/i', $m, $reg)) {
12304 if (!in_array($m, $dolibarr_main_restrict_eval_methods_array)) {
12305 if ($m !=
"'" && $m !=
'"') {
12306 dol_syslog(
'Bad string syntax to evaluate: ' . $s, LOG_WARNING);
12307 return 'Bad string syntax to evaluate. A function or method "'.$m.
'" was called and is not into the parameter $dolibarr_main_restrict_eval_methods of white-listed functions and methods: ' . $s;
12311 if (!class_exists($reg[1])) {
12312 dol_syslog(
'Bad string syntax to evaluate: Class "'.$reg[1].
'" does not exist. ' . $s, LOG_WARNING);
12313 return 'Bad string syntax to evaluate. Class "'.$reg[1].
'" does not exist. ' . $s;
12315 $parents = class_parents($reg[1]);
12316 if (!in_array(
'CommonObject', $parents)) {
12317 dol_syslog(
'Bad string syntax to evaluate: Class "'.$reg[1].
'" is not allowed because only classes extended CommonObject can be used in dynamic evaluation. ' . $s, LOG_WARNING);
12318 return 'Bad string syntax to evaluate. Class "'.$reg[1].
'" is not allowed because only classes extended CommonObject can be used in dynamic evaluation. ' . $s;
12324 $forbiddenphpregex =
'global\s*\$';
12325 $forbiddenphpregex .=
'|';
12326 $forbiddenphpregex .=
'}\s*\[';
12327 $forbiddenphpregex .=
'|';
12328 $forbiddenphpregex .=
'\)\s*\(';
12332 $oldstringtoclean = $s;
12333 $s = str_ireplace($forbiddenphpstrings,
'__forbiddenstring__', $s);
12334 $s = preg_replace(
'/' . $forbiddenphpregex .
'/i',
'__forbiddenstring__', $s);
12337 }
while ($oldstringtoclean != $s);
12339 if (strpos($s,
'__forbiddenstring__') !==
false) {
12340 dol_syslog(
'Bad string syntax to evaluate: ' . $s, LOG_WARNING);
12341 return 'Bad string syntax to evaluate: ' . $s;
12347 $isObBufferActive =
true;
12348 $tmps = $hideerrors ? @eval(
'return ' . $s .
';') : eval(
'return ' . $s .
';');
12349 $tmpo = ob_get_clean();
12350 $isObBufferActive =
false;
12352 print
'Bad string syntax to evaluate. Some data were output when it should not when evaluating: ' . $s;
12355 }
catch (Error $e) {
12356 if ($isObBufferActive) {
12358 $tmpo = ob_get_clean();
12359 $isObBufferActive =
false;
12361 $error =
'dol_eval try/catch error : ';
12362 $error .= $e->getMessage();
12364 return 'Exception during evaluation: ' . $s;
12377 return (trim($element) !=
'');
12390 if (empty($codelang)) {
12394 if ($codelang ==
'auto') {
12395 return '<span class="fa fa-language"></span>';
12398 $langtocountryflag = array(
12400 'ca_ES' =>
'catalonia',
12404 'sw_SW' =>
'unknown',
12414 if (isset($langtocountryflag[$codelang])) {
12415 $flagImage = $langtocountryflag[$codelang];
12417 $tmparray = explode(
'_', $codelang);
12418 $flagImage = empty($tmparray[1]) ? $tmparray[0] : $tmparray[1];
12423 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
12424 $morecss = $reg[1];
12429 return '<span class="flag-sprite ' . strtolower($flagImage) . ($morecss ?
' ' . $morecss :
'') .
'"' . ($moreatt ?
' ' . $moreatt :
'') . (!$notitlealt ?
' title="' . $codelang .
'"' :
'') .
'></span>';
12443 if (empty($countrycode)) {
12447 if (strtoupper($countrycode) ==
'MQ') {
12450 if (strtoupper($countrycode) ==
'SE') {
12453 if (strtoupper($countrycode) ==
'CH') {
12454 if (
$mysoc->country_code ==
'FR') {
12457 if (
$mysoc->country_code ==
'DE') {
12460 if (
$mysoc->country_code ==
'IT') {
12642 $buildprimarykeytotest = strtolower($countrycode) .
'-' . strtoupper($countrycode);
12643 if (in_array($buildprimarykeytotest, $locales)) {
12644 return strtolower($countrycode) .
'_' . strtoupper($countrycode);
12647 if (function_exists(
'locale_get_primary_language') && function_exists(
'locale_get_region')) {
12648 foreach ($locales as $locale) {
12649 $locale_language = locale_get_primary_language($locale);
12650 $locale_region = locale_get_region($locale);
12651 if (strtoupper($countrycode) == $locale_region) {
12653 return strtolower($locale_language) .
'_' . strtoupper($locale_region);
12657 dol_syslog(
"Warning Extension php-intl is not available", LOG_WARNING);
12695 global $hookmanager, $db;
12697 if (isset($conf->modules_parts[
'tabs'][$type]) && is_array($conf->modules_parts[
'tabs'][$type])) {
12698 foreach ($conf->modules_parts[
'tabs'][$type] as $value) {
12699 $values = explode(
':', $value);
12702 if ($mode ==
'add' && !preg_match(
'/^\-/', $values[1])) {
12703 if (count($values) !== 6) {
12704 dol_syslog(
'The module_parts["tabs"] entries must be composed of 6 values separated by ":", but got "' . $value .
'". Please check your module descriptor classes.', LOG_ERR);
12711 if ($values[0] != $type) {
12719 $posstart = strpos($str,
'(');
12720 if ($posstart > 0) {
12721 $posend = strpos($str,
')');
12722 if ($posstart > 0) {
12723 $res1 = substr($str, $posstart + 1, $posend - $posstart - 1);
12724 if (is_numeric($res1)) {
12725 $postab = (int) $res1;
12726 $values[1] =
'+' . substr($str, $posend + 1);
12731 global $objectoffield;
12739 if ($filterorigmodule) {
12740 if (strpos($values[3],
'@')) {
12741 if ($filterorigmodule !=
'external') {
12745 if ($filterorigmodule !=
'core') {
12750 $langs->load($values[3]);
12753 if (preg_match(
'/SUBSTITUTION_([^_]+)/i', $values[2], $reg)) {
12755 $substitutionarray = array();
12760 $labeltemp = explode(
',', $values[2]);
12761 $label = $langs->trans($labeltemp[0]);
12763 if (!empty($labeltemp[1]) && is_object(
$object) && !empty(
$object->id)) {
12765 $classtoload = $labeltemp[1];
12766 if (class_exists($classtoload)) {
12767 $obj =
new $classtoload($db);
12768 $function = $labeltemp[3];
12769 if ($obj && $function && method_exists($obj, $function)) {
12771 $nbrec = $obj->$function(
$object->id, $obj);
12772 if (!empty($nbrec)) {
12773 $label .=
'<span class="badge marginleftonlyshort">' . $nbrec .
'</span>';
12779 $url = preg_replace(
'/__ID__/i', ((is_object(
$object) && !empty(
$object->id)) ?
$object->id :
''), $values[5]);
12780 $link = parse_url($url);
12782 if (isset($link[
'query'])) {
12783 parse_str($link[
'query'], $query);
12786 $newtab[1] = $label;
12787 $newtab[2] = str_replace(
'+',
'', $values[1]);
12791 $head = array_merge(array_slice($head, 0, $postab), array($newtab), array_slice($head, $postab));
12792 } elseif ($mode ==
'remove' && preg_match(
'/^\-/', $values[1])) {
12793 if ($values[0] != $type) {
12796 $tabname = str_replace(
'-',
'', $values[1]);
12797 foreach ($head as $key => $val) {
12798 $condition = (!empty($values[3]) ?
verifCond($values[3],
'2') : 1);
12800 if ($head[$key][2] == $tabname && $condition) {
12801 unset($head[$key]);
12810 if (!empty($hookmanager)) {
12811 $parameters = array(
'object' =>
$object,
'mode' => $mode,
'head' => &$head,
'filterorigmodule' => $filterorigmodule);
12813 $reshook = $hookmanager->executeHooks(
'completeTabsHead', $parameters,
$object);
12814 if ($reshook > 0) {
12815 $head = $hookmanager->resArray;
12817 $head = array_merge($head, $hookmanager->resArray);
12836 global $conf, $hookmanager, $user, $langs;
12838 global $micro_start_time;
12840 if ($zone ==
'private') {
12841 print
"\n" .
'<!-- Common footer for private page -->' .
"\n";
12843 print
"\n" .
'<!-- Common footer for public page -->' .
"\n";
12847 print
"\n<!-- A div to store page_y POST parameter -->\n";
12848 print
'<div id="page_y" style="display: none;">' . (
GETPOST(
'page_y') ?
GETPOST(
'page_y') :
'') .
'</div>' .
"\n";
12850 $parameters = array(
'zone' => $zone);
12853 $reshook = $hookmanager->executeHooks(
'printCommonFooter', $parameters, $tmpobject, $action);
12854 if (empty($reshook)) {
12860 if (!empty($conf->use_javascript_ajax)) {
12861 print
"\n<!-- A script section to add menuhider handler on backoffice, manage focus and mandatory fields, tuning info, ... -->\n";
12862 print
'<script>' .
"\n";
12863 print
'jQuery(document).ready(function() {' .
"\n";
12865 if ($zone ==
'private' && empty($conf->dol_use_jmobile)) {
12867 print
'/* JS CODE TO ENABLE to manage handler to switch left menu page (menuhider) */' .
"\n";
12868 print
'jQuery("li.menuhider").click(function(event) {';
12869 print
' if (!$( "body" ).hasClass( "sidebar-collapse" )){ event.preventDefault(); }' .
"\n";
12870 print
' console.log("We click on .menuhider");' .
"\n";
12871 print
' $("body").toggleClass("sidebar-collapse")' .
"\n";
12872 print
'});' .
"\n";
12876 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"])))) {
12877 print
'/* JS CODE TO ENABLE to manage focus and mandatory form fields */' .
"\n";
12878 $relativepathstring = $_SERVER[
"PHP_SELF"];
12880 if (constant(
'DOL_URL_ROOT')) {
12881 $relativepathstring = preg_replace(
'/^' . preg_quote(constant(
'DOL_URL_ROOT'),
'/') .
'/',
'', $relativepathstring);
12883 $relativepathstring = preg_replace(
'/^\//',
'', $relativepathstring);
12884 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
12887 if (!empty($user->default_values[$relativepathstring][
'focus'])) {
12888 foreach ($user->default_values[$relativepathstring][
'focus'] as $defkey => $defval) {
12890 if ($defkey !=
'_noquery_') {
12891 $tmpqueryarraytohave = explode(
'&', $defkey);
12893 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
12894 $tmpquerytohaveparam = explode(
'=', $tmpquerytohave);
12896 if (!GETPOSTISSET($tmpquerytohaveparam[0]) || ($tmpquerytohaveparam[1] !=
GETPOST($tmpquerytohaveparam[0]))) {
12900 if (!$foundintru) {
12909 print
'console.log("set the focus by executing jQuery(...).focus();")' .
"\n";
12910 foreach ($defval as $paramkey => $paramval) {
12912 print
'jQuery("input[name=\'' . $paramkey .
'\']
").focus();' . "\n
";
12913 print 'jQuery("textarea[
name=\
'' . $paramkey .
'\']
").focus();' . "\n
"; // TODO KO with ckeditor
12914 print 'jQuery("select[
name=\
'' . $paramkey .
'\']
").focus();' . "\n
"; // Not really useful, but we keep it in case of.
12919 if (!empty($user->default_values[$relativepathstring]['mandatory'])) {
12920 foreach ($user->default_values[$relativepathstring]['mandatory'] as $defkey => $defval) {
12922 if ($defkey != '_noquery_') {
12923 $tmpqueryarraytohave = explode('&', $defkey);
12925 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
12926 $tmpquerytohaveparam = explode('=', $tmpquerytohave);
12927 //print "console.log(
'".$tmpquerytohaveparam[0]." ".$tmpquerytohaveparam[1]." ".GETPOST($tmpquerytohaveparam[0])."');
";
12928 if (!GETPOSTISSET($tmpquerytohaveparam[0]) || ($tmpquerytohaveparam[1] != GETPOST($tmpquerytohaveparam[0]))) {
12932 if (!$foundintru) {
12935 //var_dump($defkey.'-'.$qualified);
12941 print 'console.log("set the js code to manage fields that are
set as mandatory
");' . "\n
";
12943 foreach ($defval as $paramkey => $paramval) {
12944 // Solution 1: Add handler on submit to check if mandatory fields are empty
12945 print 'var form = $(\'[name="'.dol_escape_js($paramkey).'"]\').closest("form
");'."\n
";
12946 print "form.on(
'submit',
function(event) {
12947 var submitter = \$(
this).find(
':submit:focus').get(0);
12948 var buttonName = submitter ? \$(submitter).attr(
'name') :
'save';
12950 if (buttonName ==
'cancel') {
12951 console.log(
'We click on cancel button so we accept submit with no need to check mandatory fields');
12955 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');
12957 var tmpvalue = jQuery(
'[name=\"".dol_escape_js($paramkey)."\"]').val();
12958 let tmptypefield = jQuery(
'[name=\"".dol_escape_js($paramkey)."\"]').prop(
'nodeName').toLowerCase();
12960 if (tmptypefield ==
'textarea') {
12962 var tmpeditor = CKEDITOR.instances[
'" . dol_escape_js($paramkey) . "'];
12964 tmpvalue = tmpeditor.getData();
12965 console.log(
'For textarea tmpvalue is '+tmpvalue);
12969 let tmpvalueisempty =
false;
12970 if (tmpvalue ===
null || tmpvalue === undefined || tmpvalue ===
'' || tmpvalue === -1) {
12971 tmpvalueisempty =
true;
12973 if (tmpvalue ===
'0' && (tmptypefield ==
'select' || tmptypefield ==
'input')) {
12974 tmpvalueisempty =
true;
12976 if (tmpvalueisempty && buttonName !==
'cancel') {
12977 console.log(
'field has type '+tmptypefield+
' and is empty, we cancel the submit');
12978 event.preventDefault();
12979 event.stopPropagation();
12981 alert(
'".dol_escape_js($langs->transnoentitiesnoconv("ErrorFieldRequired", $paramkey).' (
'.$langs->transnoentitiesnoconv("CustomMandatoryFieldRule").')
')."');
12985 console.log(
'field has type '+tmptypefield+
' and is defined to '+tmpvalue);
12990 // Solution 2: Add property 'required' on input
12991 // so browser will check value and try to focus on it when submitting the form.
12992 //print 'setTimeout(function() {'; // If we want to wait that ckeditor beuatifier has finished its job.
12993 //print 'jQuery("input[
name=\
''.$paramkey.
'\']
").prop(\'required\',true);'."\n
";
12994 //print 'jQuery("textarea[
id=\
''.$paramkey.
'\']
").prop(\'required\',true);'."\n
";
12995 //print 'jQuery("select[
name=\
''.$paramkey.
'\']
").prop(\'required\',true);'."\n
";*/
12996 //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
";
12997 //print 'jQuery("select[
name=\
''.$paramkey.
'\'] option[value=\
'-1\']").prop(\'value\', \'\');'.
"\n";
13003 print
'jQuery(\':input[name="' .
dol_escape_js($paramkey) .
'"]\').closest("tr").find("td:first").addClass("fieldrequired");' .
"\n";
13007 print
'jQuery("input[name=\'cancel\']").click(function() {
13008 console.log("We click on cancel button so removed all required attribute");
13009 jQuery("input, textarea, select").each(function(){this.removeAttribute(\'required\');});
13016 print
'});' .
"\n";
13019 if (!empty($_SERVER[
'MAIN_SHOW_TUNING_INFO']) ||
getDolGlobalString(
'MAIN_SHOW_TUNING_INFO')) {
13021 print
"/* JS CODE TO ENABLE to add memory info */\n";
13022 print
'window.console && console.log("';
13027 if (!empty($micro_start_time)) {
13028 $micro_end_time = microtime(
true);
13029 print
' - Build time: ' . ceil(1000 * ($micro_end_time - $micro_start_time)) .
' ms';
13032 if (function_exists(
"memory_get_usage")) {
13033 print
' - Mem: ' . memory_get_usage();
13035 if (function_exists(
"memory_get_peak_usage")) {
13036 print
' - Real mem peak: ' . memory_get_peak_usage(
true);
13038 if (function_exists(
"zend_loader_file_encoded")) {
13039 print
' - Zend encoded file: ' . (zend_loader_file_encoded() ?
'yes' :
'no');
13041 print
'");' .
"\n";
13044 print
"\n" .
'</script>' .
"\n";
13050 foreach ($tmptagarray as $tmptag) {
13052 print
"<!-- JS CODE TO ENABLE for google analtics tag -->\n";
13054 <!-- Global site tag (gtag.js) - Google Analytics -->
13055 <script nonce="' .
getNonce() .
'" async src="https://www.googletagmanager.com/gtag/js?id=' . trim($tmptag) .
'"></script>
13057 window.dataLayer = window.dataLayer || [];
13058 function gtag(){dataLayer.push(arguments);}
13059 gtag(\'js\', new Date());
13061 gtag(\'config\', \'' . trim($tmptag) .
'\');
13068 // Add Xdebug coverage of code
13069 if (defined('XDEBUGCOVERAGE
')) {
13070 print_r(xdebug_get_code_coverage());
13073 // Output string from hooks
13074 if (!empty($hookmanager->resPrint)) {
13075 print $hookmanager->resPrint;
13078 // Add DebugBar data
13079 if ($user->hasRight('debugbar
', 'read
')) {
13081 if ($debugbar instanceof DebugBar\DebugBar) {
13082 if (isset($debugbar['time
'])) {
13083 // @phan-suppress-next-line PhanPluginUnknownObjectMethodCall
13084 $debugbar['time
']->stopMeasure('pageaftermaster
');
13086 print '<!-- Output debugbar data -->
' . "\n";
13087 $renderer = $debugbar->getJavascriptRenderer();
13088 print $renderer->render();
13090 } elseif (count($conf->logbuffer)) { // If there is some logs in buffer to show
13092 print "<!-- Start of log output\n";
13093 //print '<div
class=
"hidden">
'."\n";
13094 foreach ($conf->logbuffer as $logline) {
13095 print $logline . "<br>\n";
13097 //print '</div>
'."\n";
13098 print "End of log output -->\n";
13112function dolExplodeIntoArray($string, $delimiter = ';
', $kv = '=
')
13114 if (is_null($string)) {
13118 if (preg_match('/^\[.*\]$/sm
', $delimiter) || preg_match('/^\(.*\)$/sm
', $delimiter)) {
13119 // This is a regex string
13120 $newdelimiter = $delimiter;
13122 // This is a simple string
13123 // @phan-suppress-next-line PhanPluginSuspiciousParamPositionInternal
13124 $newdelimiter = preg_quote($delimiter, '/
');
13127 if ($a = preg_split('/
' . $newdelimiter . '/
', $string)) {
13129 foreach ($a as $s) { // each part
13131 if ($pos = strpos($s, $kv)) { // key/value delimiter
13132 $ka[trim(substr($s, 0, $pos))] = trim(substr($s, $pos + strlen($kv)));
13133 } else { // key delimiter not found
13151function dolExplodeKeepIfQuotes($input)
13153 // Use regexp to capture words and section in quotes
13154 $matches = array();
13155 preg_match_all('/
"([^"]*)
"|\'([^\']*)\'|(\S+)/', $input, $matches);
13157 // Merge result and delete empty values
13159 $result = array_map(
13166 static function ($a, $b, $c) {
13182 return array_values(array_filter(
13190 static function ($val) {
13191 return $val !== '';
13203function dol_set_focus($selector)
13205 print "\n
" . '<!-- Set focus onto a specific field -->' . "\n
";
13206 print '<script nonce="' . getNonce() . '">jQuery(document).ready(function() { console.log("Force focus by
dol_set_focus"); jQuery("' . dol_escape_js($selector) . '").focus(); });</script>' . "\n
";
13217function dol_getmypid()
13219 if (!function_exists('getmypid')) {
13220 return mt_rand(99900000, 99965535);
13222 return getmypid(); // May be a number on 64 bits (depending on OS)
13248function natural_search($fields, $value, $mode = 0, $nofirstand = 0, $sqltoadd = '')
13250 global $db, $langs;
13252 $value = trim($value);
13255 $value = preg_replace('/\*/', '%', $value); // Replace * with %
13258 $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
13261 $value = preg_replace('/\s*\|\s*/', '|', $value);
13263 // Split criteria on ' ' but not if we are inside quotes.
13264 // For mode 3, the split is done later on the , only and not on the ' '.
13265 if ($mode != -3 && $mode != 3) {
13266 $crits = dolExplodeKeepIfQuotes($value);
13268 $crits = array($value);
13272 if (!is_array($fields)) {
13273 $fields = array($fields);
13275 $i1 = 0; // count the nb of "and
" criteria added (all fields / criteria)
13276 foreach ($crits as $crit) { // Loop on each AND criteria
13277 $crit = trim($crit);
13278 $i2 = 0; // count the nb of valid criteria added for this this first criteria
13281 foreach ($fields as $field) {
13283 $tmpcrits = explode('|', $crit);
13284 $i3 = 0; // count the nb of valid criteria added for this current field
13285 foreach ($tmpcrits as $tmpcrit) {
13286 if ($tmpcrit !== '0' && empty($tmpcrit)) {
13289 $tmpcrit = trim($tmpcrit);
13291 $newres .= (($i2 > 0 || $i3 > 0) ? ' OR ' : '');
13294 $newcrit = preg_replace('/([!<>=]+)/', '', $tmpcrit);
13297 preg_match('/([!<>=]+)/', $tmpcrit, $reg);
13298 if (!empty($reg[1])) {
13299 $operator = $reg[1];
13301 if ($newcrit != '') {
13302 $numnewcrit = price2num($newcrit);
13303 if (is_numeric($numnewcrit)) {
13304 $newres .= $db->sanitize($field) . ' ' . $operator . ' ' . ((float) $numnewcrit); // should be a numeric
13306 $newres .= '1 = 2'; // force false, we received a corrupted data
13308 $i3++; // a criteria was added to string
13311 $i2++; // a criteria for 1 more field was added to string
13312 } elseif ($mode == 2 || $mode == -2) {
13313 $crit = preg_replace('/[^\-0-9,]/', '', $crit); // ID are always integer
13314 $newres .= ($i2 > 0 ? ' OR ' : '') . $db->sanitize($field) . " " . ($mode == -2 ? 'NOT ' : '');
13315 $newres .= $crit ? "IN (
" . $db->sanitize($db->escape($crit)) . ")
" : "IN (0)
";
13317 $newres .= ' OR ' . $db->sanitize($field) . ' IS NULL';
13319 $i2++; // a criteria for 1 more field was added to string
13320 } elseif ($mode == 3 || $mode == -3) {
13321 $tmparray = explode(',', $crit);
13322 if (count($tmparray)) {
13324 foreach ($tmparray as $val) {
13326 if ($val) { // TODO Test with if ($val !== '') {
13327 $listofcodes .= ($listofcodes ? ',' : '');
13328 $listofcodes .= "'" . $db->escape($val) . "'";
13331 $newres .= ($i2 > 0 ? ' OR ' : '') . $db->sanitize($field) . " " . ($mode == -3 ? 'NOT ' : '') . "IN (
" . $db->sanitize($listofcodes, 1, 0, 1) . ")
";
13332 $i2++; // a criteria for 1 more field was added to string
13335 $newres .= ' OR ' . $db->sanitize($field) . ' IS NULL';
13337 } elseif ($mode == 4) {
13338 $tmparray = explode(',', $crit);
13339 if (count($tmparray)) {
13341 foreach ($tmparray as $val) {
13344 $newres .= ($i2 > 0 ? " OR (
" : "(
") . $db->sanitize($field) . " LIKE
'" . $db->escape($val) . ",%'";
13345 $newres .= ' OR ' . $db->sanitize($field) . " =
'" . $db->escape($val) . "'";
13346 $newres .= ' OR ' . $db->sanitize($field) . " LIKE
'%," . $db->escape($val) . "'";
13347 $newres .= ' OR ' . $db->sanitize($field) . " LIKE
'%," . $db->escape($val) . ",%'";
13349 $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)
13353 } else { // $mode=0
13354 $tmpcrits = explode('|', $crit);
13355 $i3 = 0; // count the nb of valid criteria added for the current couple criteria/field
13356 foreach ($tmpcrits as $tmpcrit) { // loop on each OR criteria
13357 if ($tmpcrit !== '0' && empty($tmpcrit)) {
13360 $tmpcrit = trim($tmpcrit);
13362 if ($tmpcrit == '^$' || strpos($crit, '!') === 0) { // If we search empty, we must combined different OR fields with AND
13363 $newres .= (($i2 > 0 || $i3 > 0) ? ' AND ' : '');
13365 $newres .= (($i2 > 0 || $i3 > 0) ? ' OR ' : '');
13368 $isSellist = false;
13369 $table = $label = $key = null;
13371 if (strpos($field, 'ef.') === 0) {
13372 $extrafieldName = substr($field, 3);
13373 $extrafields = new ExtraFields($db);
13374 $extrafields->fetch_name_optionals_label('product');
13376 if (isset($extrafields->attributes['product']['type'][$extrafieldName]) && $extrafields->attributes['product']['type'][$extrafieldName] === 'sellist') {
13378 $paramArray = $extrafields->attributes['product']['param'][$extrafieldName]['options'] ?? [];
13379 $param = array_key_first($paramArray);
13380 list($table, $label, $key) = explode(':', $param);
13384 if (preg_match('/\.(id|rowid)$/', $field)) { // Special case for rowid that is sometimes a ref so used as a search field
13385 $newres .= $db->sanitize($field) . " =
" . (is_numeric($tmpcrit) ? ((float) $tmpcrit) : '0');
13387 $tmpcrit2 = $tmpcrit;
13393 $newres .= $field . " IN (SELECT t.
" . $key . " FROM
" . $db->prefix() . $table . " AS t WHERE t.
" . $label . " LIKE
'%" . $db->escape($tmpcrit2) . "%')
";
13395 if (preg_match('/^!/', $tmpcrit)) {
13396 $tmps .= $db->sanitize($field) . " NOT LIKE
"; // ! as exclude character
13397 $tmpcrit2 = preg_replace('/^!/', '', $tmpcrit2);
13399 $tmps .= $db->sanitize($field) . " LIKE
";
13403 if (preg_match('/^[\^\$]/
', $tmpcrit)) {
13405 $tmpcrit2 = preg_replace('/^[\^\$]/
', '', $tmpcrit2);
13407 if (preg_match('/[\^\$]$/
', $tmpcrit)) {
13409 $tmpcrit2 = preg_replace('/[\^\$]$/
', '', $tmpcrit2);
13412 if ($tmpcrit2 == '' || preg_match('/^!/
', $tmpcrit)) {
13413 $tmps = "(" . $tmps;
13416 $newres .= $tmpbefore;
13417 $newres .= $db->escape($tmpcrit2);
13418 $newres .= $tmpafter;
13420 if ($tmpcrit2 == '' || preg_match('/^!/', $tmpcrit)) {
13421 $newres .= " OR
" . $field . " IS NULL)
";
13429 $i2++; // a criteria for 1 more field was added to string
13434 $newres .= ($newres ? '' : ' OR ').str_replace('__KEYTOSEARCH__', $crit, $sqltoadd);
13438 $res = $res . ($res ? ' AND ' : '') . ($i2 > 1 ? '(' : '') . $newres . ($i2 > 1 ? ')' : '');
13442 $res = ($nofirstand ? "" : " AND
") . "(
" . $res . ")
";
13453function showDirectDownloadLink($object)
13458 $url = $object->getLastMainDocLink($object->element);
13460 $out .= img_picto($langs->trans("PublicDownloadLinkDesc
"), 'globe') . ' <span class="opacitymedium
">' . $langs->trans("DirectDownloadLink
") . '</span><br>';
13462 $out .= '<div class="urllink
"><input type="text
" id="directdownloadlink
" class="quatrevingtpercent
" value="' . $url . '"></div>';
13463 $out .= ajax_autoselect("directdownloadlink
", '');
13465 $out .= '<div class="urllink
">' . $langs->trans("FileNotShared
") . '</div>';
13479function getImageFileNameForSize($file, $extName, $extImgTarget = '')
13481 $dirName = dirname($file);
13482 if ($dirName == '.') {
13486 if (!in_array($extName, array('', '_small', '_mini'))) {
13487 return 'Bad parameter extName';
13490 $fileName = preg_replace('/(\.gif|\.jpeg|\.jpg|\.png|\.bmp|\.webp)$/i', '', $file); // We remove image extension, whatever is its case
13491 $fileName = basename($fileName);
13493 if (empty($extImgTarget)) {
13494 $extImgTarget = (preg_match('/\.jpg$/i', $file) ? '.jpg' : '');
13496 if (empty($extImgTarget)) {
13497 $extImgTarget = (preg_match('/\.jpeg$/i', $file) ? '.jpeg' : '');
13499 if (empty($extImgTarget)) {
13500 $extImgTarget = (preg_match('/\.gif$/i', $file) ? '.gif' : '');
13502 if (empty($extImgTarget)) {
13503 $extImgTarget = (preg_match('/\.png$/i', $file) ? '.png' : '');
13505 if (empty($extImgTarget)) {
13506 $extImgTarget = (preg_match('/\.bmp$/i', $file) ? '.bmp' : '');
13508 if (empty($extImgTarget)) {
13509 $extImgTarget = (preg_match('/\.webp$/i', $file) ? '.webp' : '');
13512 if (!$extImgTarget) {
13518 $subdir = 'thumbs/';
13521 return ($dirName ? $dirName . '/' : '') . $subdir . $fileName . $extName . $extImgTarget; // New filename for thumb
13534function getAdvancedPreviewUrl($modulepart, $relativepath, $alldata = 0, $param = '')
13536 global $conf, $langs;
13538 if (empty($conf->use_javascript_ajax)) {
13542 $isAllowedForPreview = dolIsAllowedForPreview($relativepath);
13544 if ($alldata == 1) {
13545 if ($isAllowedForPreview) {
13546 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));
13552 // old behavior, return a string
13553 if ($isAllowedForPreview) {
13554 $tmpurl = DOL_URL_ROOT . '/document.php?modulepart=' . urlencode($modulepart) . '&attachment=0&file=' . urlencode($relativepath) . ($param ? '&' . $param : '');
13555 $title = $langs->transnoentities("Preview
");
13556 //$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().
13557 //$tmpurl = 'file='.urlencode("'-alert(document.domain)-'_small.jpg
"); // An example of tmpurl that should be blocked by the dol_escape_uri()
13559 // 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,
13560 // 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.
13561 // Using the dol_escape_uri guarantee that we encode for URI so decode retrieve original expected value.
13562 return 'javascript:' . dol_escape_uri('document_preview(\'' . dol_escape_js($tmpurl) . '\', \'' . dol_escape_js(dol_mimetype($relativepath)) . '\', \'' . dol_escape_js($title) . '\')');
13574function getLabelSpecialCode($idcode)
13578 $arrayspecialines = array(1 => 'Transport', 2 => 'EcoTax', 3 => 'Option');
13579 if ($idcode > 10) {
13580 return 'Module ID ' . $idcode;
13582 if (!empty($arrayspecialines[$idcode])) {
13583 return $langs->trans($arrayspecialines[$idcode]);
13596function ajax_autoselect($htmlname, $addlink = '', $textonlink = 'Link')
13599 $out = '<script nonce="
' . getNonce() . '">
13600 jQuery(document).ready(function () {
13601 jQuery("' . ((strpos($htmlname, '.
') === 0 ? '' : '#
') . $htmlname) . '").click(function() { jQuery(this).select(); } );
13605 if ($textonlink === 'image') {
13606 $out .= ' <a href="' . $addlink . '" target="_blank
" rel="noopener noreferrer
">' . img_picto('', 'globe') . '</a>';
13608 $out .= ' <a href="' . $addlink . '" target="_blank
" rel="noopener noreferrer
">' . $langs->trans("Link") . '</a>';
13621function dolIsAllowedForPreview($file)
13623 // Check .noexe extension in filename
13624 if (preg_match('/\.noexe$/i', $file)) {
13628 // Check mime types
13629 $mime_preview = array('bmp', 'jpeg', 'png', 'gif', 'tiff', 'pdf', 'plain', 'css', 'webp', 'webm', 'mp4');
13630 if (getDolGlobalString('MAIN_ALLOW_SVG_FILES_AS_IMAGES')) {
13631 $mime_preview[] = 'svg+xml';
13633 //$mime_preview[]='vnd.oasis.opendocument.presentation';
13634 //$mime_preview[]='archive';
13635 $num_mime = array_search(dol_mimetype($file, '', 1), $mime_preview);
13636 if ($num_mime !== false) {
13640 // By default, not allowed for preview
13654function dol_mimetype($file, $default = 'application/octet-stream', $mode = 0)
13657 $imgmime = 'other.png';
13658 $famime = 'file-o';
13661 $tmpfile = preg_replace('/\.noexe$/', '', $file);
13663 // Plain text files
13664 if (preg_match('/\.txt$/i', $tmpfile)) {
13665 $mime = 'text/plain';
13666 $imgmime = 'text.png';
13667 $famime = 'file-alt';
13668 } elseif (preg_match('/\.rtx$/i', $tmpfile)) {
13669 $mime = 'text/richtext';
13670 $imgmime = 'text.png';
13671 $famime = 'file-alt';
13672 } elseif (preg_match('/\.csv$/i', $tmpfile)) {
13673 $mime = 'text/csv';
13674 $imgmime = 'text.png';
13675 $famime = 'file-csv';
13676 } elseif (preg_match('/\.tsv$/i', $tmpfile)) {
13677 $mime = 'text/tab-separated-values';
13678 $imgmime = 'text.png';
13679 $famime = 'file-alt';
13680 } elseif (preg_match('/\.(cf|conf|log)$/i', $tmpfile)) {
13681 $mime = 'text/plain';
13682 $imgmime = 'text.png';
13683 $famime = 'file-alt';
13684 } elseif (preg_match('/\.ini$/i', $tmpfile)) {
13685 $mime = 'text/plain';
13686 $imgmime = 'text.png';
13688 $famime = 'file-alt';
13689 } elseif (preg_match('/\.md$/i', $tmpfile)) {
13690 $mime = 'text/plain';
13691 $imgmime = 'text.png';
13693 $famime = 'file-alt';
13694 } elseif (preg_match('/\.css$/i', $tmpfile)) {
13695 $mime = 'text/css';
13696 $imgmime = 'css.png';
13698 $famime = 'file-alt';
13699 } elseif (preg_match('/\.lang$/i', $tmpfile)) {
13700 $mime = 'text/plain';
13701 $imgmime = 'text.png';
13703 $famime = 'file-alt';
13704 } elseif (preg_match('/\.(crt|cer|key|pub)$/i', $tmpfile)) { // Certificate files
13705 $mime = 'text/plain';
13706 $imgmime = 'text.png';
13707 $famime = 'file-alt';
13708 } elseif (preg_match('/\.(html|htm|shtml)$/i', $tmpfile)) { // XML based (HTML/XML/XAML)
13709 $mime = 'text/html';
13710 $imgmime = 'html.png';
13712 $famime = 'file-alt';
13713 } elseif (preg_match('/\.(xml|xhtml)$/i', $tmpfile)) {
13714 $mime = 'text/xml';
13715 $imgmime = 'other.png';
13717 $famime = 'file-alt';
13718 } elseif (preg_match('/\.xaml$/i', $tmpfile)) {
13719 $mime = 'text/xml';
13720 $imgmime = 'other.png';
13722 $famime = 'file-alt';
13723 } elseif (preg_match('/\.bas$/i', $tmpfile)) { // Languages
13724 $mime = 'text/plain';
13725 $imgmime = 'text.png';
13727 $famime = 'file-code';
13728 } elseif (preg_match('/\.(c)$/i', $tmpfile)) {
13729 $mime = 'text/plain';
13730 $imgmime = 'text.png';
13732 $famime = 'file-code';
13733 } elseif (preg_match('/\.(cpp)$/i', $tmpfile)) {
13734 $mime = 'text/plain';
13735 $imgmime = 'text.png';
13737 $famime = 'file-code';
13738 } elseif (preg_match('/\.cs$/i', $tmpfile)) {
13739 $mime = 'text/plain';
13740 $imgmime = 'text.png';
13742 $famime = 'file-code';
13743 } elseif (preg_match('/\.(h)$/i', $tmpfile)) {
13744 $mime = 'text/plain';
13745 $imgmime = 'text.png';
13747 $famime = 'file-code';
13748 } elseif (preg_match('/\.(java|jsp)$/i', $tmpfile)) {
13749 $mime = 'text/plain';
13750 $imgmime = 'text.png';
13752 $famime = 'file-code';
13753 } elseif (preg_match('/\.php([0-9]{1})?$/i', $tmpfile)) {
13754 $mime = 'text/plain';
13755 $imgmime = 'php.png';
13757 $famime = 'file-code';
13758 } elseif (preg_match('/\.phtml$/i', $tmpfile)) {
13759 $mime = 'text/plain';
13760 $imgmime = 'php.png';
13762 $famime = 'file-code';
13763 } elseif (preg_match('/\.(pl|pm)$/i', $tmpfile)) {
13764 $mime = 'text/plain';
13765 $imgmime = 'pl.png';
13767 $famime = 'file-code';
13768 } elseif (preg_match('/\.sql$/i', $tmpfile)) {
13769 $mime = 'text/plain';
13770 $imgmime = 'text.png';
13772 $famime = 'file-code';
13773 } elseif (preg_match('/\.js$/i', $tmpfile)) {
13774 $mime = 'text/x-javascript';
13775 $imgmime = 'jscript.png';
13777 $famime = 'file-code';
13778 } elseif (preg_match('/\.odp$/i', $tmpfile)) { // Open office
13779 $mime = 'application/vnd.oasis.opendocument.presentation';
13780 $imgmime = 'ooffice.png';
13781 $famime = 'file-powerpoint';
13782 } elseif (preg_match('/\.ods$/i', $tmpfile)) {
13783 $mime = 'application/vnd.oasis.opendocument.spreadsheet';
13784 $imgmime = 'ooffice.png';
13785 $famime = 'file-excel';
13786 } elseif (preg_match('/\.odt$/i', $tmpfile)) {
13787 $mime = 'application/vnd.oasis.opendocument.text';
13788 $imgmime = 'ooffice.png';
13789 $famime = 'file-word';
13790 } elseif (preg_match('/\.mdb$/i', $tmpfile)) { // MS Office
13791 $mime = 'application/msaccess';
13792 $imgmime = 'mdb.png';
13794 } elseif (preg_match('/\.doc[xm]?$/i', $tmpfile)) {
13795 $mime = 'application/msword';
13796 $imgmime = 'doc.png';
13797 $famime = 'file-word';
13798 } elseif (preg_match('/\.dot[xm]?$/i', $tmpfile)) {
13799 $mime = 'application/msword';
13800 $imgmime = 'doc.png';
13801 $famime = 'file-word';
13802 } elseif (preg_match('/\.xlt(x)?$/i', $tmpfile)) {
13803 $mime = 'application/vnd.ms-excel';
13804 $imgmime = 'xls.png';
13805 $famime = 'file-excel';
13806 } elseif (preg_match('/\.xla(m)?$/i', $tmpfile)) {
13807 $mime = 'application/vnd.ms-excel';
13808 $imgmime = 'xls.png';
13809 $famime = 'file-excel';
13810 } elseif (preg_match('/\.xls$/i', $tmpfile)) {
13811 $mime = 'application/vnd.ms-excel';
13812 $imgmime = 'xls.png';
13813 $famime = 'file-excel';
13814 } elseif (preg_match('/\.xls[bmx]$/i', $tmpfile)) {
13815 $mime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
13816 $imgmime = 'xls.png';
13817 $famime = 'file-excel';
13818 } elseif (preg_match('/\.pps[mx]?$/i', $tmpfile)) {
13819 $mime = 'application/vnd.ms-powerpoint';
13820 $imgmime = 'ppt.png';
13821 $famime = 'file-powerpoint';
13822 } elseif (preg_match('/\.ppt[mx]?$/i', $tmpfile)) {
13823 $mime = 'application/x-mspowerpoint';
13824 $imgmime = 'ppt.png';
13825 $famime = 'file-powerpoint';
13826 } elseif (preg_match('/\.pdf$/i', $tmpfile)) { // Other
13827 $mime = 'application/pdf';
13828 $imgmime = 'pdf.png';
13829 $famime = 'file-pdf';
13830 } elseif (preg_match('/\.bat$/i', $tmpfile)) { // Scripts
13831 $mime = 'text/x-bat';
13832 $imgmime = 'script.png';
13834 $famime = 'file-code';
13835 } elseif (preg_match('/\.sh$/i', $tmpfile)) {
13836 $mime = 'text/x-sh';
13837 $imgmime = 'script.png';
13839 $famime = 'file-code';
13840 } elseif (preg_match('/\.ksh$/i', $tmpfile)) {
13841 $mime = 'text/x-ksh';
13842 $imgmime = 'script.png';
13844 $famime = 'file-code';
13845 } elseif (preg_match('/\.bash$/i', $tmpfile)) {
13846 $mime = 'text/x-bash';
13847 $imgmime = 'script.png';
13849 $famime = 'file-code';
13850 } elseif (preg_match('/\.ico$/i', $tmpfile)) { // Images
13851 $mime = 'image/x-icon';
13852 $imgmime = 'image.png';
13853 $famime = 'file-image';
13854 } elseif (preg_match('/\.(jpg|jpeg)$/i', $tmpfile)) {
13855 $mime = 'image/jpeg';
13856 $imgmime = 'image.png';
13857 $famime = 'file-image';
13858 } elseif (preg_match('/\.png$/i', $tmpfile)) {
13859 $mime = 'image/png';
13860 $imgmime = 'image.png';
13861 $famime = 'file-image';
13862 } elseif (preg_match('/\.gif$/i', $tmpfile)) {
13863 $mime = 'image/gif';
13864 $imgmime = 'image.png';
13865 $famime = 'file-image';
13866 } elseif (preg_match('/\.bmp$/i', $tmpfile)) {
13867 $mime = 'image/bmp';
13868 $imgmime = 'image.png';
13869 $famime = 'file-image';
13870 } elseif (preg_match('/\.(tif|tiff)$/i', $tmpfile)) {
13871 $mime = 'image/tiff';
13872 $imgmime = 'image.png';
13873 $famime = 'file-image';
13874 } elseif (preg_match('/\.svg$/i', $tmpfile)) {
13875 $mime = 'image/svg+xml';
13876 $imgmime = 'image.png';
13877 $famime = 'file-image';
13878 } elseif (preg_match('/\.webp$/i', $tmpfile)) {
13879 $mime = 'image/webp';
13880 $imgmime = 'image.png';
13881 $famime = 'file-image';
13882 } elseif (preg_match('/\.vcs$/i', $tmpfile)) { // Calendar
13883 $mime = 'text/calendar';
13884 $imgmime = 'other.png';
13885 $famime = 'file-alt';
13886 } elseif (preg_match('/\.ics$/i', $tmpfile)) {
13887 $mime = 'text/calendar';
13888 $imgmime = 'other.png';
13889 $famime = 'file-alt';
13890 } elseif (preg_match('/\.torrent$/i', $tmpfile)) { // Other
13891 $mime = 'application/x-bittorrent';
13892 $imgmime = 'other.png';
13893 $famime = 'file-o';
13894 } elseif (preg_match('/\.(mp3|ogg|au|wav|wma|mid)$/i', $tmpfile)) { // Audio
13896 $imgmime = 'audio.png';
13897 $famime = 'file-audio';
13898 } elseif (preg_match('/\.mp4$/i', $tmpfile)) { // Video
13899 $mime = 'video/mp4';
13900 $imgmime = 'video.png';
13901 $famime = 'file-video';
13902 } elseif (preg_match('/\.ogv$/i', $tmpfile)) {
13903 $mime = 'video/ogg';
13904 $imgmime = 'video.png';
13905 $famime = 'file-video';
13906 } elseif (preg_match('/\.webm$/i', $tmpfile)) {
13907 $mime = 'video/webm';
13908 $imgmime = 'video.png';
13909 $famime = 'file-video';
13910 } elseif (preg_match('/\.avi$/i', $tmpfile)) {
13911 $mime = 'video/x-msvideo';
13912 $imgmime = 'video.png';
13913 $famime = 'file-video';
13914 } elseif (preg_match('/\.divx$/i', $tmpfile)) {
13915 $mime = 'video/divx';
13916 $imgmime = 'video.png';
13917 $famime = 'file-video';
13918 } elseif (preg_match('/\.xvid$/i', $tmpfile)) {
13919 $mime = 'video/xvid';
13920 $imgmime = 'video.png';
13921 $famime = 'file-video';
13922 } elseif (preg_match('/\.(wmv|mpg|mpeg)$/i', $tmpfile)) {
13924 $imgmime = 'video.png';
13925 $famime = 'file-video';
13926 } elseif (preg_match('/\.(zip|rar|gz|tgz|xz|z|cab|bz2|7z|tar|lzh|zst)$/i', $tmpfile)) { // Archive
13927 // application/xxx where zzz is zip, ...
13929 $imgmime = 'archive.png';
13930 $famime = 'file-archive';
13931 } elseif (preg_match('/\.(exe|com)$/i', $tmpfile)) { // Exe
13932 $mime = 'application/octet-stream';
13933 $imgmime = 'other.png';
13934 $famime = 'file-o';
13935 } elseif (preg_match('/\.(dll|lib|o|so|a)$/i', $tmpfile)) { // Lib
13937 $imgmime = 'library.png';
13938 $famime = 'file-o';
13939 } elseif (preg_match('/\.err$/i', $tmpfile)) { // phpcs:ignore
13941 $imgmime = 'error.png';
13942 $famime = 'file-alt';
13945 if ($famime == 'file-o') {
13946 // file-o seems to not work in fontawesome 5
13950 // Return mimetype string
13951 switch ((int) $mode) {
13953 $tmp = explode('/', $mime);
13954 return (!empty($tmp[1]) ? $tmp[1] : $tmp[0]);
13976function getDictionaryValue($tablename, $field, $id, $checkentity = false, $rowidfield = 'rowid')
13980 $tablename = preg_replace('/^' . preg_quote(MAIN_DB_PREFIX, '/') . '/', '', $tablename); // Clean name of table for backward compatibility.
13982 $dictvalues = (isset($conf->cache['dictvalues_' . $tablename]) ? $conf->cache['dictvalues_' . $tablename] : null);
13984 if (is_null($dictvalues)) {
13985 $dictvalues = array();
13987 $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
13988 if ($checkentity) {
13989 $sql .= ' AND entity IN (0,' . getEntity($tablename) . ')';
13992 $resql = $db->query($sql);
13994 while ($obj = $db->fetch_object($resql)) {
13995 $dictvalues[$obj->$rowidfield] = $obj; // $obj is stdClass
13998 dol_print_error($db);
14001 $conf->cache['dictvalues_' . $tablename] = $dictvalues;
14004 if (!empty($dictvalues[$id])) {
14006 $tmp = $dictvalues[$id];
14007 return (property_exists($tmp, $field) ? $tmp->$field : '');
14020function colorIsLight($stringcolor)
14022 $stringcolor = str_replace('#', '', $stringcolor);
14024 if (!empty($stringcolor)) {
14026 $tmp = explode(',', $stringcolor);
14027 if (count($tmp) > 1) { // This is a comma RGB ('255','255','255')
14032 $hexr = $stringcolor[0] . $stringcolor[1];
14033 $hexg = $stringcolor[2] . $stringcolor[3];
14034 $hexb = $stringcolor[4] . $stringcolor[5];
14035 $r = hexdec($hexr);
14036 $g = hexdec($hexg);
14037 $b = hexdec($hexb);
14039 $bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0; // HSL algorithm
14040 if ($bright > 0.6) {
14055function isVisibleToUserType($type_user, &$menuentry, &$listofmodulesforexternal)
14057 //print 'type_user='.$type_user.' module='.$menuentry['module'].' enabled='.$menuentry['enabled'].' perms='.$menuentry['perms'];
14058 //print 'ok='.in_array($menuentry['module'], $listofmodulesforexternal);
14059 if (empty($menuentry['enabled'])) {
14060 return 0; // Entry disabled by condition
14062 if ($type_user && array_key_exists('module', $menuentry) && $menuentry['module']) {
14063 $tmploops = explode('|', $menuentry['module']);
14065 foreach ($tmploops as $tmploop) {
14066 if (in_array($tmploop, $listofmodulesforexternal)) {
14072 return 0; // Entry is for menus all excluded to external users
14075 if (!$menuentry['perms'] && $type_user) {
14076 return 0; // No permissions and user is external
14078 if (!$menuentry['perms'] && getDolGlobalString('MAIN_MENU_HIDE_UNAUTHORIZED')) {
14079 return 0; // No permissions and option to hide when not allowed, even for internal user, is on
14081 if (!$menuentry['perms']) {
14082 return 2; // No permissions and user is external
14094function roundUpToNextMultiple($n, $x = 5)
14096 $result = (ceil($n) % $x === 0) ? ceil($n) : (round(($n + $x / 2) / $x) * $x);
14097 return (int) $result;
14111function dolGetBadge($label, $html = '', $type = 'primary', $mode = '', $url = '', $params = array())
14113 $csstouse = 'badge';
14114 $csstouse .= (!empty($mode) ? ' badge-' . $mode : '');
14115 $csstouse .= (!empty($type) ? ' badge-' . $type : '');
14116 $csstouse .= (empty($params['css']) ? '' : ' ' . $params['css']);
14119 'class' => $csstouse
14122 if (empty($html)) {
14126 if (!empty($url)) {
14127 $attr['href'] = $url;
14130 if ($mode === 'dot') {
14131 $attr['class'] .= ' classfortooltip';
14132 $attr['title'] = $html;
14133 $attr['aria-label'] = $label;
14138 if (!empty($params['attr']) && is_array($params['attr'])) {
14139 foreach ($params['attr'] as $key => $value) {
14140 if ($key == 'class') {
14141 $attr['class'] .= ' ' . $value;
14142 } elseif ($key == 'classOverride') {
14143 $attr['class'] = $value;
14145 $attr[$key] = $value;
14152 // escape all attribute
14153 $attr = array_map('dolPrintHTMLForAttribute', $attr);
14155 $TCompiledAttr = array();
14156 foreach ($attr as $key => $value) {
14157 $TCompiledAttr[] = $key . '="
' . $value . '"';
14160 $compiledAttributes = !empty($TCompiledAttr) ? implode(' ', $TCompiledAttr) : '';
14162 $tag = !empty($url) ? 'a' : 'span';
14164 return '<' . $tag . ' ' . $compiledAttributes . '>' . $html . '</' . $tag . '>';
14180function dolGetStatus($statusLabel = '', $statusLabelShort = '', $html = '', $statusType = 'status0', $displayMode = 0, $url = '', $params = array())
14185 $dolGetBadgeParams = array();
14187 if (!empty($params['badgeParams'])) {
14188 $dolGetBadgeParams = $params['badgeParams'];
14191 // TODO : add a hook
14192 if ($displayMode == 0) {
14193 $return = !empty($html) ? $html : (empty($conf->dol_optimize_smallscreen) ? $statusLabel : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort));
14194 } elseif ($displayMode == 1) {
14195 $return = !empty($html) ? $html : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort);
14196 } elseif (getDolGlobalString('MAIN_STATUS_USES_IMAGES')) {
14197 // Use status with images (for backward compatibility)
14199 $htmlLabel = (in_array($displayMode, array(1, 2, 5)) ? '<span class="hideonsmartphone
">' : '') . (!empty($html) ? $html : $statusLabel) . (in_array($displayMode, array(1, 2, 5)) ? '</span>' : '');
14200 $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>' : '');
14202 // For small screen, we always use the short label instead of long label.
14203 if (!empty($conf->dol_optimize_smallscreen)) {
14204 if ($displayMode == 0) {
14206 } elseif ($displayMode == 4) {
14208 } elseif ($displayMode == 6) {
14213 // For backward compatibility. Image's filename are still in French, so we use this array to convert
14214 $statusImg = array(
14215 'status0' => 'statut0',
14216 'status1' => 'statut1',
14217 'status2' => 'statut2',
14218 'status3' => 'statut3',
14219 'status4' => 'statut4',
14220 'status5' => 'statut5',
14221 'status6' => 'statut6',
14222 'status7' => 'statut7',
14223 'status8' => 'statut8',
14224 'status9' => 'statut9'
14227 if (!empty($statusImg[$statusType])) {
14228 $htmlImg = img_picto($statusLabel, $statusImg[$statusType]);
14230 $htmlImg = img_picto($statusLabel, $statusType);
14233 if ($displayMode === 2) {
14234 $return = $htmlImg . ' ' . $htmlLabelShort;
14235 } elseif ($displayMode === 3) {
14236 $return = $htmlImg;
14237 } elseif ($displayMode === 4) {
14238 $return = $htmlImg . ' ' . $htmlLabel;
14239 } elseif ($displayMode === 5) {
14240 $return = $htmlLabelShort . ' ' . $htmlImg;
14241 } else { // $displayMode >= 6
14242 $return = $htmlLabel . ' ' . $htmlImg;
14244 } elseif (!getDolGlobalString('MAIN_STATUS_USES_IMAGES') && !empty($displayMode)) {
14246 $statusLabelShort = (empty($statusLabelShort) ? $statusLabel : $statusLabelShort);
14248 $dolGetBadgeParams['attr']['class'] = 'badge-status';
14249 if (empty($dolGetBadgeParams['attr']['title'])) {
14250 $dolGetBadgeParams['attr']['title'] = empty($params['tooltip']) ? $statusLabel : ($params['tooltip'] != 'no' ? $params['tooltip'] : '');
14251 } else { // If a title was forced from $params['badgeParams']['attr']['title'], we set the class to get it as a tooltip.
14252 $dolGetBadgeParams['attr']['class'] .= ' classfortooltip';
14253 // And if we use tooltip, we can output title in HTML @phan-suppress-next-line PhanTypeInvalidDimOffset
14254 $dolGetBadgeParams['attr']['title'] = dol_htmlentitiesbr((string) $dolGetBadgeParams['attr']['title'], 1);
14257 if ($displayMode == 3) {
14258 $return = dolGetBadge((empty($conf->dol_optimize_smallscreen) ? $statusLabel : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort)), '', $statusType, 'dot', $url, $dolGetBadgeParams);
14259 } elseif ($displayMode === 5) {
14260 $return = dolGetBadge($statusLabelShort, $html, $statusType, '', $url, $dolGetBadgeParams);
14262 $return = dolGetBadge(((empty($conf->dol_optimize_smallscreen) && $displayMode != 2) ? $statusLabel : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort)), $html, $statusType, '', $url, $dolGetBadgeParams);
14305function dolGetButtonAction($label, $text = '', $actionType = 'default', $url = '', $id = '', $userRight = 1, $params = array())
14307 global $hookmanager, $action, $object, $langs;
14309 // If $url is an array, we must build a dropdown button or recursively iterate over each value
14310 if (is_array($url)) {
14311 // Loop on $url array to remove entries of disabled modules
14312 foreach ($url as $key => $subbutton) {
14313 if (isset($subbutton['enabled']) && empty($subbutton['enabled'])) {
14320 if (array_key_exists('areDropdownButtons', $params) && $params["areDropdownButtons
"] === false) { // @phan-suppress-current-line PhanTypeInvalidDimOffset
14321 foreach ($url as $button) {
14322 if (!empty($button['lang'])) {
14323 $langs->load($button['lang']);
14325 $label = $langs->trans($button['label']);
14326 $text = $button['text'] ?? '';
14327 $actionType = $button['actionType'] ?? '';
14328 $tmpUrl = DOL_URL_ROOT . $button['url'] . (empty($params['backtopage']) ? '' : '&backtopage=' . urlencode($params['backtopage']));
14329 $id = $button['id'] ?? '';
14330 $userRight = $button['perm'] ?? 1;
14331 $button['params'] = $button['params'] ?? []; // @phan-suppress-current-line PhanPluginDuplicateExpressionAssignmentOperation
14333 $out .= dolGetButtonAction($label, $text, $actionType, $tmpUrl, $id, $userRight, $button['params']);
14338 if (count($url) > 1) {
14339 $out .= '<div class="dropdown
inline-block dropdown-holder
">';
14340 $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>';
14341 $out .= '<div class="dropdown-content
">';
14342 foreach ($url as $subbutton) {
14343 if (!empty($subbutton['lang'])) {
14344 $langs->load($subbutton['lang']);
14347 if (!empty($subbutton['urlraw'])) {
14348 $tmpurl = $subbutton['urlraw']; // Use raw url, no url completion, use only what developer send
14350 $tmpurl = !empty($subbutton['urlroot']) ? $subbutton['urlroot'] : $subbutton['url'];
14351 $tmpurl = dolCompletUrlForDropdownButton($tmpurl, $params, empty($subbutton['urlroot']));
14354 $subbuttonparam = array();
14355 if (!empty($subbutton['attr'])) {
14356 $subbuttonparam['attr'] = $subbutton['attr'];
14358 $subbuttonparam['isDropDown'] = (empty($params['isDropDown']) ? ($subbutton['isDropDown'] ?? false) : $params['isDropDown']);
14360 $out .= dolGetButtonAction('', $langs->trans($subbutton['label']), 'default', $tmpurl, $subbutton['id'] ?? '', $subbutton['perm'], $subbuttonparam);
14365 foreach ($url as $subbutton) { // Should loop on 1 record only
14366 if (!empty($subbutton['lang'])) {
14367 $langs->load($subbutton['lang']);
14370 if (!empty($subbutton['urlraw'])) {
14371 $tmpurl = $subbutton['urlraw']; // Use raw url, no url completion, use only what developer send
14373 $tmpurl = !empty($subbutton['urlroot']) ? $subbutton['urlroot'] : $subbutton['url'];
14374 $tmpurl = dolCompletUrlForDropdownButton($tmpurl, $params, empty($subbutton['urlroot']));
14377 $label = $langs->trans($subbutton['label']);
14378 $text = $subbutton['text'] ?? '';
14379 if (empty($text)) {
14384 $out .= dolGetButtonAction($label, $text, 'default', $tmpurl, '', $subbutton['perm'], $params);
14391 // Here, $url is a simple link
14392 if (!empty($params['isDropdown']) || !empty($params['isDropDown'])) { // Use the dropdown-item style (not for action button)
14393 $class = "dropdown-item
";
14395 $class = 'butAction';
14396 if ($actionType == 'edit') {
14397 $class = 'butAction butActionEdit';
14398 } elseif ($actionType == 'email') {
14399 $class = 'butAction butActionEmail';
14400 } elseif ($actionType == 'clone') {
14401 $class = 'butAction butActionClone';
14402 } elseif ($actionType == 'danger' || $actionType == 'delete') {
14403 $class = 'butAction butActionDelete';
14404 if (!empty($url) && strpos($url, 'token=') === false) {
14405 $url .= '&token=' . newToken();
14411 'href' => empty($url) ? '' : $url,
14415 if (empty($text)) {
14417 $attr['title'] = ''; // if html not set, using label on title is redundant
14419 $attr['title'] = $label;
14420 $attr['aria-label'] = $label;
14423 if (empty($userRight) || $userRight < 0) {
14424 $attr['class'] = 'butActionRefused';
14425 $attr['href'] = '';
14426 $attr['title'] = (($label && $text && $label != $text) ? $label : '');
14427 $attr['title'] = ($attr['title'] ? $attr['title'] . (empty($userRight) ? '<br>' : '') : '');
14428 $attr['title'] .= ((empty($userRight) && empty($label)) ? $langs->trans('NotEnoughPermissions') : '');
14436 if (!empty($params['attr']) && is_array($params['attr'])) {
14437 foreach ($params['attr'] as $key => $value) {
14438 if ($key == 'class') {
14439 $attr['class'] .= ' ' . $value;
14440 } elseif ($key == 'classOverride') {
14441 $attr['class'] = $value;
14443 $attr[$key] = $value;
14448 // automatic add tooltip when title is detected
14449 if (!empty($attr['title']) && !empty($attr['class']) && strpos($attr['class'], 'classfortooltip') === false) {
14450 $attr['class'] .= ' classfortooltip';
14453 // Js Confirm button
14454 if ($userRight && !empty($params['confirm'])) {
14455 if (!is_array($params['confirm'])) {
14456 $params['confirm'] = array();
14459 if (empty($params['confirm']['url'])) {
14460 $params['confirm']['url'] = $url . (strpos($url, '?') > 0 ? '&' : '?') . 'confirm=yes';
14463 // for js disabled compatibility set $url as call to confirm action and $params['confirm']['url'] to confirmed action
14464 $attr['data-confirm-url'] = $params['confirm']['url'];
14465 $attr['data-confirm-title'] = !empty($params['confirm']['title']) ? $params['confirm']['title'] : $langs->trans('ConfirmBtnCommonTitle', $label);
14466 $attr['data-confirm-content'] = !empty($params['confirm']['content']) ? $params['confirm']['content'] : $langs->trans('ConfirmBtnCommonContent', $label);
14467 $attr['data-confirm-content'] = preg_replace("/\r|\n/
", "", $attr['data-confirm-content']);
14468 $attr['data-confirm-action-btn-label'] = !empty($params['confirm']['action-btn-label']) ? $params['confirm']['action-btn-label'] : $langs->trans('Confirm');
14469 $attr['data-confirm-cancel-btn-label'] = !empty($params['confirm']['cancel-btn-label']) ? $params['confirm']['cancel-btn-label'] : $langs->trans('CloseDialog');
14470 $attr['data-confirm-modal'] = !empty($params['confirm']['modal']) ? $params['confirm']['modal'] : true;
14472 $attr['class'] .= ' butActionConfirm';
14475 if (isset($attr['href']) && empty($attr['href'])) {
14476 unset($attr['href']);
14479 // TODO replace $TCompiledAttr generation by commonHtmlAttributeBuilder given below
14480 $TCompiledAttr = array();
14481 foreach ($attr as $key => $value) {
14482 if (!empty($params['use_unsecured_unescapedattr']) && is_array($params['use_unsecured_unescapedattr']) && in_array($key, $params['use_unsecured_unescapedattr'])) {
14484 $value = dol_htmlentities($value, ENT_QUOTES | ENT_SUBSTITUTE);
14485 } elseif ($key == 'href') {
14486 $value = dolPrintHTMLForAttributeUrl($value);
14488 $value = dolPrintHTMLForAttribute($value);
14491 $TCompiledAttr[] = $key . '="' . $value . '"'; // $value has been escaped by the dolPrintHTMLForAttribute... just before
14493 // TODO replace $TCompiledAttr generation by uncomment line below and remove old code
14494 // $TCompiledAttr = commonHtmlAttributeBuilder($attr,$params['use_unsecured_unescapedattr'] ?? []);
14495 $compiledAttributes = empty($TCompiledAttr) ? '' : implode(' ', $TCompiledAttr);
14497 $tag = !empty($attr['href']) ? 'a' : 'span';
14499 $parameters = array(
14500 'TCompiledAttr' => $TCompiledAttr, // array
14501 'compiledAttributes' => $compiledAttributes, // string
14506 'actionType' => $actionType,
14509 'userRight' => $userRight,
14510 'params' => $params
14513 $reshook = $hookmanager->executeHooks('dolGetButtonAction', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
14514 if ($reshook < 0) {
14515 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
14518 if (empty($reshook)) {
14519 if (dol_textishtml($text)) { // If content already HTML encoded
14520 return '<' . $tag . ' ' . $compiledAttributes . '><span class="textbutton
">' . $text . '</span></' . $tag . '>';
14522 return '<' . $tag . ' ' . $compiledAttributes . '><span class="textbutton
">' . dol_escape_htmltag($text) . '</span></' . $tag . '>';
14525 return $hookmanager->resPrint;
14564function commonHtmlAttributeBuilder($attr, array $unescapedAttr = [])
14566 $TCompiledAttr = array();
14567 if (empty($attr)) {
14571 foreach ($attr as $key => $value) {
14572 // special boolean attributes case
14573 if (in_array($key, getListOfHtmlBooleanAttributes())) {
14575 $TCompiledAttr[$key] = $key;
14580 if (!empty($unescapedAttr) && in_array($key, $unescapedAttr)) {
14582 $value = dol_htmlentities((string) $value, ENT_QUOTES | ENT_SUBSTITUTE);
14583 } elseif ($key == 'href') {
14584 $value = dolPrintHTMLForAttributeUrl((string) $value);
14586 $value = dolPrintHTMLForAttribute((string) $value);
14589 $TCompiledAttr[$key] = $key . '="
' . $value . '"'; // $value has been escaped by the dolPrintHTMLForAttribute... just before
14592 return $TCompiledAttr;
14609function getListOfHtmlBooleanAttributes(): array
14658function dolCompletUrlForDropdownButton(string $url, array $params, bool $addDolUrlRoot = true)
14664 $parsedUrl = parse_url($url);
14665 if ((isset($parsedUrl['scheme']) && in_array($parsedUrl['scheme'], ['javascript', 'mailto', 'tel'])) || strpos($url, '#') === 0) {
14669 if (!empty($parsedUrl['query'])) {
14670 // Use parse_str() function to parse the string passed via URL
14671 parse_str($parsedUrl['query'], $urlQuery);
14672 if (!isset($urlQuery['backtopage']) && isset($params['backtopage'])) {
14673 $url .= '&backtopage=' . urlencode($params['backtopage']);
14677 if (!isset($parsedUrl['scheme']) && $addDolUrlRoot) {
14678 $url = DOL_URL_ROOT . $url;
14691function dolGetButtonTitleSeparator($moreClass = "
")
14693 return '<span class="button-title-separator
' . $moreClass . '" ></span>';
14702function getFieldErrorIcon($fieldValidationErrorMsg)
14705 if (!empty($fieldValidationErrorMsg)) {
14706 $out .= '<span class="field-error-icon classfortooltip
" title="' . dol_escape_htmltag($fieldValidationErrorMsg, 1) . '" role="alert
" >'; // role alert is used for accessibility
14707 $out .= '<span class="fa fa-exclamation-circle
" aria-hidden="true" ></span>'; // For accessibility icon is separated and aria-hidden
14726function dolGetButtonTitle($label, $helpText = '', $iconClass = 'fa fa-file', $url = '', $id = '', $status = 1, $params = array())
14728 global $langs, $user;
14730 // Actually this conf is used in css too for external module compatibility and smooth transition to this function
14731 if (getDolGlobalString('MAIN_BUTTON_HIDE_UNAUTHORIZED') && (!$user->admin) && $status <= 0) {
14734 // Fix old picto fa-th-list to use fa-grid-vertical instead
14735 if ($iconClass == 'fa fa-th-list imgforviewmode') {
14736 $iconClass = ' fa fa-grip-horizontal imgforviewmode';
14739 $class = 'btnTitle';
14740 if (in_array($iconClass, array('fa fa-plus-circle', 'fa fa-plus-circle size15x', 'fa fa-comment-dots', 'fa fa-paper-plane'))) {
14741 $class .= ' btnTitlePlus';
14743 $useclassfortooltip = 1;
14745 if (!empty($params['morecss'])) {
14746 $class .= ' ' . $params['morecss'];
14751 'href' => empty($url) ? '' : $url
14754 if (!empty($helpText)) {
14755 $attr['title'] = $helpText;
14756 } elseif ($label) { // empty($attr['title']) &&
14757 $attr['title'] = $label;
14758 $useclassfortooltip = 0;
14761 if ($status == 2) {
14762 $attr['class'] .= ' btnTitleSelected';
14763 } elseif ($status <= 0) {
14764 $attr['class'] .= ' refused';
14766 $attr['href'] = '';
14768 if ($status == -1) { // disable
14769 $attr['title'] = $langs->transnoentitiesnoconv("FeatureDisabled
");
14770 } elseif ($status == 0) { // Not enough permissions
14771 $attr['title'] = $langs->transnoentitiesnoconv("NotEnoughPermissions
");
14775 if (!empty($attr['title']) && $useclassfortooltip) {
14776 $attr['class'] .= ' classfortooltip';
14784 if (!empty($params['attr']) && is_array($params['attr'])) {
14785 foreach ($params['attr'] as $key => $value) {
14786 if ($key == 'class') {
14787 $attr['class'] .= ' ' . $value;
14788 } elseif ($key == 'classOverride') {
14789 $attr['class'] = $value;
14791 $attr[$key] = $value;
14796 if (isset($attr['href']) && empty($attr['href'])) {
14797 unset($attr['href']);
14800 // TODO : add a hook
14802 // Generate attributes with escapement
14803 $TCompiledAttr = array();
14804 foreach ($attr as $key => $value) {
14805 $TCompiledAttr[] = $key . '="' . dol_escape_htmltag($value) . '"'; // Do not use dolPrintHTMLForAttribute() here, we must accept "javascript:
string"
14808 $compiledAttributes = (empty($TCompiledAttr) ? '' : implode(' ', $TCompiledAttr));
14810 $tag = (empty($attr['href']) ? 'span' : 'a');
14812 $button = '<' . $tag . ' ' . $compiledAttributes . '>';
14813 $button .= '<span class="' . $iconClass . ' valignmiddle btnTitle-icon
"></span>';
14814 if (!empty($params['forcenohideoftext'])) {
14815 $button .= '<span class="valignmiddle text-plus-circle btnTitle-label
' . (empty($params['forcenohideoftext
']) ? ' hideonsmartphone
' : '') . '">' . $label . '</span>';
14817 $button .= '</' . $tag . '>';
14831function getElementProperties($elementType)
14833 global $conf, $db, $hookmanager;
14837 //$element_type='facture';
14839 $classfile = $classname = $classpath = $subdir = $dir_output = $dir_temp = $parent_element = '';
14841 // Parse element/subelement
14842 $module = $elementType;
14843 $element = $elementType;
14844 $subelement = $elementType;
14845 $table_element = $elementType;
14847 // If we ask a resource form external module (instead of default path)
14848 if (preg_match('/^([^@]+)@([^@]+)$/i', $elementType, $regs)) { // 'myobject@mymodule'
14849 $element = $subelement = $regs[1];
14850 $module = $regs[2];
14853 // If we ask a resource for a string with an element and a subelement
14854 // Example 'project_task'
14855 if (preg_match('/^([^_]+)_([^_]+)/i', $element, $regs)) { // 'myobject_mysubobject' with myobject=mymodule
14856 $module = $element = $regs[1];
14857 $subelement = $regs[2];
14860 // Object lines will use parent classpath and module ref
14861 if (substr($elementType, -3) == 'det') {
14862 $module = preg_replace('/det$/', '', $element);
14863 $subelement = preg_replace('/det$/', '', $subelement);
14864 $classpath = $module . '/class';
14865 $classfile = $module;
14866 $classname = preg_replace('/det$/', 'Line', $element);
14867 if (in_array($module, array('expedition', 'propale', 'facture', 'contrat', 'fichinter', 'supplier_order', 'commandefournisseur'))) {
14868 $classname = preg_replace('/det$/', 'Ligne', $element);
14871 // For compatibility and to work with non standard path
14872 if ($elementType == "action
" || $elementType == "actioncomm
") {
14873 $classpath = 'comm/action/class';
14874 $subelement = 'Actioncomm';
14875 $module = 'agenda';
14876 $table_element = 'actioncomm';
14877 } elseif ($elementType == 'cronjob') {
14878 $classpath = 'cron/class';
14880 $table_element = 'cron';
14881 } elseif ($elementType == 'adherent_type') {
14882 $classpath = 'adherents/class';
14883 $classfile = 'adherent_type';
14884 $module = 'adherent';
14885 $subelement = 'adherent_type';
14886 $classname = 'AdherentType';
14887 $table_element = 'adherent_type';
14888 } elseif ($elementType == 'bank_account') {
14889 $classpath = 'compta/bank/class';
14890 $module = 'bank'; // We need $conf->bank->dir_output and not $conf->banque->dir_output
14891 $classfile = 'account';
14892 $classname = 'Account';
14893 } elseif ($elementType == 'bank_line') {
14894 $classpath = 'compta/bank/class';
14895 $module = 'bank'; // We need $conf->bank->dir_output and not $conf->banque->dir_output
14896 $classfile = 'account';
14897 $classname = 'AccountLine';
14898 } elseif ($elementType == 'category') {
14899 $classpath = 'categories/class';
14900 $module = 'categorie';
14901 $subelement = 'categorie';
14902 $table_element = 'categorie';
14903 } elseif ($elementType == 'contact') {
14904 $classpath = 'contact/class';
14905 $classfile = 'contact';
14906 $module = 'societe';
14907 $subelement = 'contact';
14908 $table_element = 'socpeople';
14909 } elseif ($elementType == 'inventory') {
14910 $module = 'product';
14911 $classpath = 'product/inventory/class';
14912 } elseif ($elementType == 'inventoryline') {
14913 $module = 'product';
14914 $classpath = 'product/inventory/class';
14915 $table_element = 'inventorydet';
14916 $parent_element = 'inventory';
14917 } elseif ($elementType == 'stock' || $elementType == 'entrepot' || $elementType == 'warehouse') {
14919 $classpath = 'product/stock/class';
14920 $classfile = 'entrepot';
14921 $classname = 'Entrepot';
14922 $table_element = 'entrepot';
14923 } elseif ($elementType == 'project') {
14924 $classpath = 'projet/class';
14925 $module = 'projet';
14926 $table_element = 'projet';
14927 } elseif ($elementType == 'project_task') {
14928 $classpath = 'projet/class';
14929 $module = 'projet';
14930 $subelement = 'task';
14931 $table_element = 'projet_task';
14932 } elseif ($elementType == 'facture' || $elementType == 'invoice') {
14933 $classpath = 'compta/facture/class';
14934 $module = 'facture';
14935 $subelement = 'facture';
14936 $table_element = 'facture';
14937 } elseif ($elementType == 'facturedet') {
14938 $classpath = 'compta/facture/class';
14939 $classfile = 'facture';
14940 $classname = 'FactureLigne';
14941 $module = 'facture';
14942 $table_element = 'facturedet';
14943 $parent_element = 'facture';
14944 } elseif ($elementType == 'facturerec'|| $elementType == 'facture_rec') {
14945 $classpath = 'compta/facture/class';
14946 $classfile = 'facture-rec';
14947 $module = 'facture';
14948 $classname = 'FactureRec';
14949 } elseif ($elementType == 'commande' || $elementType == 'order') {
14950 $classpath = 'commande/class';
14951 $module = 'commande';
14952 $subelement = 'commande';
14953 $table_element = 'commande';
14954 } elseif ($elementType == 'commandedet') {
14955 $classpath = 'commande/class';
14956 $classfile = 'commande';
14957 $classname = 'OrderLine';
14958 $module = 'commande';
14959 $table_element = 'commandedet';
14960 $parent_element = 'commande';
14961 } elseif ($elementType == 'propal') {
14962 $classpath = 'comm/propal/class';
14963 $table_element = 'propal';
14964 } elseif ($elementType == 'propaldet') {
14965 $classpath = 'comm/propal/class';
14966 $classfile = 'propal';
14967 $subelement = 'propaleligne';
14968 $module = 'propal';
14969 $table_element = 'propaldet';
14970 $parent_element = 'propal';
14971 } elseif ($elementType == 'shipping') {
14972 $classpath = 'expedition/class';
14973 $classfile = 'expedition';
14974 $classname = 'Expedition';
14975 $module = 'expedition';
14976 $table_element = 'expedition';
14977 } elseif ($elementType == 'expeditiondet' || $elementType == 'shippingdet') {
14978 $classpath = 'expedition/class';
14979 $classfile = 'expedition';
14980 $classname = 'ExpeditionLigne';
14981 $module = 'expedition';
14982 $table_element = 'expeditiondet';
14983 $parent_element = 'expedition';
14984 } elseif ($elementType == 'delivery_note') {
14985 $classpath = 'delivery/class';
14986 $subelement = 'delivery';
14987 $module = 'expedition';
14988 } elseif ($elementType == 'delivery') {
14989 $classpath = 'delivery/class';
14990 $subelement = 'delivery';
14991 $module = 'expedition';
14992 } elseif ($elementType == 'deliverydet') {
14994 } elseif ($elementType == 'supplier_proposal') {
14995 $classpath = 'supplier_proposal/class';
14996 $module = 'supplier_proposal';
14997 $element = 'supplierproposal';
14998 $classfile = 'supplier_proposal';
14999 $subelement = 'supplierproposal';
15000 } elseif ($elementType == 'supplier_proposaldet') {
15001 $classpath = 'supplier_proposal/class';
15002 $module = 'supplier_proposal';
15003 $classfile = 'supplier_proposal';
15004 $classname = 'SupplierProposalLine';
15005 $table_element = 'supplier_proposaldet';
15006 $parent_element = 'supplier_proposal';
15007 } elseif ($elementType == 'contract') {
15008 $classpath = 'contrat/class';
15009 $module = 'contrat';
15010 $subelement = 'contrat';
15011 $table_element = 'contract';
15012 } elseif ($elementType == 'contratdet') {
15013 $classpath = 'contrat/class';
15014 $module = 'contrat';
15015 $table_element = 'contratdet';
15016 $parent_element = 'contrat';
15017 } elseif ($elementType == 'mailing') {
15018 $classpath = 'comm/mailing/class';
15019 $module = 'mailing';
15020 $classfile = 'mailing';
15021 $classname = 'Mailing';
15023 } elseif ($elementType == 'member' || $elementType == 'adherent') {
15024 $classpath = 'adherents/class';
15025 $module = 'adherent';
15026 $subelement = 'adherent';
15027 $table_element = 'adherent';
15028 } elseif ($elementType == 'subscription') {
15029 $classpath = 'adherents/class';
15030 $classfile = 'subscription';
15031 $module = 'adherent';
15032 $subelement = 'subscription';
15033 $classname = 'Subscription';
15034 $table_element = 'subscription';
15035 } elseif ($elementType == 'usergroup') {
15036 $classpath = 'user/class';
15038 } elseif ($elementType == 'mo' || $elementType == 'mrp') {
15039 $classpath = 'mrp/class';
15044 $table_element = 'mrp_mo';
15045 } elseif ($elementType == 'mrp_production') {
15046 $classpath = 'mrp/class';
15048 $classname = 'MoLine';
15051 $table_element = 'mrp_production';
15052 $parent_element = 'mo';
15053 } elseif ($elementType == 'cabinetmed_cons') {
15054 $classpath = 'cabinetmed/class';
15055 $module = 'cabinetmed';
15056 $subelement = 'cabinetmedcons';
15057 $table_element = 'cabinetmedcons';
15058 } elseif ($elementType == 'fichinter') {
15059 $classpath = 'fichinter/class';
15060 $module = 'ficheinter';
15061 $subelement = 'fichinter';
15062 $table_element = 'fichinter';
15063 } elseif ($elementType == 'dolresource' || $elementType == 'resource') {
15064 $classpath = 'resource/class';
15065 $module = 'resource';
15066 $subelement = 'dolresource';
15067 $table_element = 'resource';
15068 } elseif ($elementType == 'opensurvey_sondage') {
15069 $classpath = 'opensurvey/class';
15070 $module = 'opensurvey';
15071 $subelement = 'opensurveysondage';
15072 } elseif ($elementType == 'order_supplier' || $elementType == 'supplier_order' || $elementType == 'commande_fournisseur' || $elementType == 'commandefournisseur') {
15073 $classpath = 'fourn/class';
15074 $module = 'fournisseur';
15075 $classfile = 'fournisseur.commande';
15076 $element = 'order_supplier';
15078 $classname = 'CommandeFournisseur';
15079 $table_element = 'commande_fournisseur';
15080 } elseif ($elementType == 'commande_fournisseurdet') {
15081 $classpath = 'fourn/class';
15082 $module = 'fournisseur';
15083 $classfile = 'fournisseur.commande';
15084 $element = 'commande_fournisseurdet';
15086 $classname = 'CommandeFournisseurLigne';
15087 $table_element = 'commande_fournisseurdet';
15088 $parent_element = 'commande_fournisseur';
15089 } elseif ($elementType == 'invoice_supplier' || $elementType == 'supplier_invoice' || $elementType == 'facture_fourn') {
15090 $classpath = 'fourn/class';
15091 $module = 'fournisseur';
15092 $classfile = 'fournisseur.facture';
15093 $element = 'invoice_supplier';
15095 $classname = 'FactureFournisseur';
15096 $table_element = 'facture_fourn';
15097 } elseif ($elementType == 'facture_fourn_det') {
15098 $classpath = 'fourn/class';
15099 $module = 'fournisseur';
15100 $classfile = 'fournisseur.facture';
15101 $element = 'facture_fourn_det';
15103 $classname = 'SupplierInvoiceLine';
15104 $table_element = 'facture_fourn_det';
15105 $parent_element = 'invoice_supplier';
15106 } elseif ($elementType == "service
") {
15107 $classpath = 'product/class';
15108 $subelement = 'product';
15109 $table_element = 'product';
15110 } elseif ($elementType == 'salary') {
15111 $classpath = 'salaries/class';
15112 $module = 'salaries';
15113 } elseif ($elementType == 'payment_salary') {
15114 $classpath = 'salaries/class';
15115 $classfile = 'paymentsalary';
15116 $classname = 'PaymentSalary';
15117 $module = 'salaries';
15118 } elseif ($elementType == 'productlot') {
15119 $module = 'productbatch';
15120 $classpath = 'product/stock/class';
15121 $classfile = 'productlot';
15122 $classname = 'Productlot';
15123 $element = 'productlot';
15125 $table_element = 'product_lot';
15126 } elseif ($elementType == 'societeaccount') {
15127 $classpath = 'societe/class';
15128 $classfile = 'societeaccount';
15129 $classname = 'SocieteAccount';
15130 $module = 'societe';
15131 } elseif ($elementType == 'websitepage' || $elementType == 'website_page') {
15132 $classpath = 'website/class';
15133 $classfile = 'websitepage';
15134 $classname = 'Websitepage';
15135 $module = 'website';
15136 $subelement = 'websitepage';
15137 $table_element = 'website_page';
15138 } elseif ($elementType == 'fiscalyear') {
15139 $classpath = 'core/class';
15140 $module = 'accounting';
15141 $subelement = 'fiscalyear';
15142 } elseif ($elementType == 'chargesociales') {
15143 $classpath = 'compta/sociales/class';
15145 $table_element = 'chargesociales';
15146 } elseif ($elementType == 'tva') {
15147 $classpath = 'compta/tva/class';
15150 $table_element = 'tva';
15151 } elseif ($elementType == 'emailsenderprofile') {
15153 $classpath = 'core/class';
15154 $classfile = 'emailsenderprofile';
15155 $classname = 'EmailSenderProfile';
15156 $table_element = 'c_email_senderprofile';
15158 } elseif ($elementType == 'conferenceorboothattendee') {
15159 $classpath = 'eventorganization/class';
15160 $classfile = 'conferenceorboothattendee';
15161 $classname = 'ConferenceOrBoothAttendee';
15162 $module = 'eventorganization';
15163 } elseif ($elementType == 'conferenceorbooth') {
15164 $classpath = 'eventorganization/class';
15165 $classfile = 'conferenceorbooth';
15166 $classname = 'ConferenceOrBooth';
15167 $module = 'eventorganization';
15168 } elseif ($elementType == 'ccountry') {
15170 $classpath = 'core/class';
15171 $classfile = 'ccountry';
15172 $classname = 'Ccountry';
15173 $table_element = 'c_country';
15175 } elseif ($elementType == 'ecmfiles') {
15177 $classpath = 'ecm/class';
15178 $classfile = 'ecmfiles';
15179 $classname = 'Ecmfiles';
15180 $table_element = 'ecmfiles';
15182 } elseif ($elementType == 'knowledgerecord' || $elementType == 'knowledgemanagement') {
15183 $module = 'knowledgemanagement';
15184 $classpath = 'knowledgemanagement/class';
15185 $classfile = 'knowledgerecord';
15186 $classname = 'KnowledgeRecord';
15187 $table_element = 'knowledgemanagement_knowledgerecord';
15189 } elseif ($elementType == 'customer') {
15190 $module = 'societe';
15191 $classpath = 'societe/class';
15192 $classfile = 'client';
15193 $classname = 'Client';
15194 $table_element = 'societe';
15196 } elseif ($elementType == 'fournisseur' || $elementType == 'supplier') {
15197 $module = 'societe';
15198 $classpath = 'fourn/class';
15199 $classfile = 'fournisseur';
15200 $classname = 'Fournisseur';
15201 $table_element = 'societe';
15203 } elseif ($elementType == 'recruitmentcandidature') {
15204 $module = 'recruitment';
15205 $classfile = 'recruitmentcandidature';
15206 $classpath = 'recruitment/class';
15207 $classname = 'RecruitmentCandidature';
15208 $subelement = 'recruitmentcandidature';
15209 $subdir = '/recruitmentcandidature';
15210 } elseif ($elementType == 'recruitmentjobposition') {
15211 $module = 'recruitment';
15212 $classfile = 'recruitmentjobposition';
15213 $classpath = 'recruitment/class';
15214 $classname = 'RecruitmentJobPosition';
15215 $subelement = 'recruitmentjobposition';
15216 $subdir = '/recruitmentjobposition';
15220 if (empty($classfile)) {
15221 $classfile = strtolower($subelement);
15223 if (empty($classname)) {
15224 $classname = ucfirst($subelement);
15226 if (empty($classpath)) {
15227 $classpath = $module . '/class';
15230 //print 'getElementProperties subdir='.$subdir;
15233 if ($module && isset($conf->$module)) { // The generic case
15234 if (!empty($conf->$module->multidir_output[$conf->entity])) {
15235 $dir_output = $conf->$module->multidir_output[$conf->entity];
15236 } elseif (!empty($conf->$module->output[$conf->entity])) {
15237 $dir_output = $conf->$module->output[$conf->entity];
15238 } elseif (!empty($conf->$module->dir_output)) {
15239 $dir_output = $conf->$module->dir_output;
15241 if (!empty($conf->$module->multidir_temp[$conf->entity])) {
15242 $dir_temp = $conf->$module->multidir_temp[$conf->entity];
15243 } elseif (!empty($conf->$module->temp[$conf->entity])) {
15244 $dir_temp = $conf->$module->temp[$conf->entity];
15245 } elseif (!empty($conf->$module->dir_temp)) {
15246 $dir_temp = $conf->$module->dir_temp;
15250 // Overwrite value for special cases
15251 if ($element == 'order_supplier' && isModEnabled('fournisseur')) {
15252 $dir_output = $conf->fournisseur->commande->dir_output;
15253 $dir_temp = $conf->fournisseur->commande->dir_temp;
15254 } elseif ($element == 'invoice_supplier' && isModEnabled('fournisseur')) {
15255 $dir_output = $conf->fournisseur->facture->dir_output;
15256 $dir_temp = $conf->fournisseur->facture->dir_temp;
15258 $dir_output .= $subdir;
15259 $dir_temp .= $subdir;
15261 $elementProperties = array(
15262 'module' => $module,
15263 'element' => $element,
15264 'table_element' => $table_element,
15265 'subelement' => $subelement,
15266 'classpath' => $classpath,
15267 'classfile' => $classfile,
15268 'classname' => $classname,
15269 'dir_output' => $dir_output,
15270 'dir_temp' => $dir_temp,
15271 'parent_element' => $parent_element,
15276 if (!is_object($hookmanager)) {
15277 include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
15278 $hookmanager = new HookManager($db);
15280 $hookmanager->initHooks(array('elementproperties'));
15284 $parameters = array(
15285 'elementType' => $elementType,
15286 'elementProperties' => $elementProperties
15289 $reshook = $hookmanager->executeHooks('getElementProperties', $parameters);
15292 $elementProperties = $hookmanager->resArray;
15293 } elseif (!empty($hookmanager->resArray) && is_array($hookmanager->resArray)) { // resArray is always an array but for sécurity against misconfigured external modules
15294 $elementProperties = array_replace($elementProperties, $hookmanager->resArray);
15297 // context of elementproperties doesn't need to exist out of this function so delete it to avoid elementproperties context is equal to all
15298 if (($key = array_search('elementproperties', $hookmanager->contextarray)) !== false) {
15299 unset($hookmanager->contextarray[$key]);
15302 return $elementProperties;
15317function fetchObjectByElement($element_id, $element_type, $element_ref = '', $useCache = 0, $maxCacheByType = 10)
15323 $element_prop = getElementProperties($element_type);
15325 if ($element_prop['module'] == 'product' || $element_prop['module'] == 'service') {
15326 // For example, for an extrafield 'product' (shared for both product and service) that is a link to an object,
15327 // this is called with $element_type = 'product' when we need element properties of a service, we must return a product. If we create the
15328 // extrafield for a service, it is not supported and not found when editing the product/service card. So we must keep 'product' for extrafields
15329 // of service and we will return properties of a product.
15330 $ismodenabled = (isModEnabled('product') || isModEnabled('service'));
15331 } elseif ($element_prop['module'] == 'societeaccount') {
15332 $ismodenabled = isModEnabled('website') || isModEnabled('webportal');
15334 $ismodenabled = isModEnabled($element_prop['module']);
15336 //var_dump('element_type='.$element_type);
15337 //var_dump($element_prop);
15338 //var_dump($element_prop['module'].' '.$ismodenabled);
15339 if (is_array($element_prop) && (empty($element_prop['module']) || $ismodenabled)) {
15340 if ($useCache === 1 && $element_id > 0
15341 && !empty($conf->cache['fetchObjectByElement'][$element_type])
15342 && !empty($conf->cache['fetchObjectByElement'][$element_type][$element_id])
15343 && is_object($conf->cache['fetchObjectByElement'][$element_type][$element_id])
15345 return $conf->cache['fetchObjectByElement'][$element_type][$element_id];
15348 dol_include_once('/' . $element_prop['classpath'] . '/' . $element_prop['classfile'] . '.class.php');
15350 if (class_exists($element_prop['classname'])) {
15351 $className = $element_prop['classname'];
15352 $objecttmp = new $className($db);
15353 '@phan-var-force CommonObject $objecttmp';
15356 if ($element_id > 0 || !empty($element_ref)) {
15357 $ret = $objecttmp->fetch($element_id, $element_ref);
15359 if (empty($objecttmp->module)) {
15360 $objecttmp->module = $element_prop['module'];
15363 if ($useCache > 0) {
15364 if (!isset($conf->cache['fetchObjectByElement'][$element_type])) {
15365 $conf->cache['fetchObjectByElement'][$element_type] = [];
15368 // Manage cache limit
15369 if (! empty($conf->cache['fetchObjectByElement'][$element_type]) && is_array($conf->cache['fetchObjectByElement'][$element_type]) && count($conf->cache['fetchObjectByElement'][$element_type]) >= $maxCacheByType) {
15370 array_shift($conf->cache['fetchObjectByElement'][$element_type]);
15373 $conf->cache['fetchObjectByElement'][$element_type][$element_id] = $objecttmp;
15379 return $objecttmp; // returned an object without fetch
15382 dol_syslog($element_prop['classname'] . ' doesn\'t exists in /' . $element_prop['classpath'] . '/' . $element_prop['classfile'] . '.class.php');
15395function getExecutableContent()
15397 $arrayofregexextension = array(
15424 return $arrayofregexextension;
15433function isAFileWithExecutableContent($filename)
15435 $arrayofregexextension = getExecutableContent();
15437 foreach ($arrayofregexextension as $fileextension) {
15438 if (preg_match('/\.' . preg_quote($fileextension, '/') . '$/i', $filename)) {
15455 return empty($_SESSION['newtoken']) ? '' : $_SESSION['newtoken'];
15465function currentToken()
15467 return isset($_SESSION['token']) ? $_SESSION['token'] : '';
15479 if (empty($conf->cache['nonce'])) {
15480 include_once DOL_DOCUMENT_ROOT . '/core/lib/security.lib.php';
15481 $conf->cache['nonce'] = dolGetRandomBytes(8);
15484 return $conf->cache['nonce'];
15501function startSimpleTable($header, $link = "
", $arguments = "", $emptyColumns = 0, $number = -1, $pictofulllist = '')
15505 print '<div class="div-
table-responsive-no-min
">';
15506 print '<table class="noborder centpercent
">';
15507 print '<tr class="liste_titre
">';
15509 print ($emptyColumns < 1) ? '<th>' : '<th colspan="' . ($emptyColumns + 1) . '">';
15511 print '<span class="valignmiddle
">' . $langs->trans($header) . '</span>';
15513 if (!empty($link)) {
15514 if (!empty($arguments)) {
15515 print '<a href="' . DOL_URL_ROOT . '/
' . $link . '?
' . $arguments . '">';
15517 print '<a href="' . DOL_URL_ROOT . '/
' . $link . '">';
15521 if ($number > -1) {
15522 print '<span class="badge marginleftonlyshort
">' . $number . '</span>';
15523 } elseif (!empty($link)) {
15524 print '<span class="badge marginleftonlyshort
">...</span>';
15527 if (!empty($link)) {
15533 if ($number < 0 && !empty($link)) {
15534 print '<th class="right
">';
15549function finishSimpleTable($addLineBreak = false)
15554 if ($addLineBreak) {
15570function addSummaryTableLine($tableColumnCount, $num, $nbofloop = 0, $total = 0, $noneWord = "None
", $extraRightColumn = false)
15575 print '<tr class="oddeven
">';
15576 print '<td colspan="' . $tableColumnCount . '"><span class="opacitymedium
">' . $langs->trans($noneWord) . '</span></td>';
15581 if ($nbofloop === 0) {
15582 // don't show a summary line
15586 /* Case already handled above, commented to satisfy phpstan.
15588 $colspan = $tableColumnCount;
15591 if ($num > $nbofloop) {
15592 $colspan = $tableColumnCount;
15594 $colspan = $tableColumnCount - 1;
15597 if ($extraRightColumn) {
15601 print '<tr class="liste_total
">';
15603 if ($nbofloop > 0 && $num > $nbofloop) {
15604 print '<td colspan="' . $colspan . '" class="right
">' . $langs->trans("XMoreLines
", ($num - $nbofloop)) . '</td>';
15606 print '<td colspan="' . $colspan . '" class="right
"> ' . $langs->trans("Total
") . '</td>';
15607 print '<td class="right centpercent
">' . price($total) . '</td>';
15610 if ($extraRightColumn) {
15625function readfileLowMemory($fullpath_original_file_osencoded, $method = -1)
15627 if ($method == -1) {
15629 if (getDolGlobalString('MAIN_FORCE_READFILE_WITH_FREAD')) {
15632 if (getDolGlobalString('MAIN_FORCE_READFILE_WITH_STREAM_COPY')) {
15637 // Be sure we don't have output buffering enabled to have readfile working correctly
15638 while (ob_get_level()) {
15643 if ($method == 0) {
15644 readfile($fullpath_original_file_osencoded);
15645 } elseif ($method == 1) {
15647 $handle = fopen($fullpath_original_file_osencoded, "rb
");
15648 while (!feof($handle)) {
15649 print fread($handle, 8192);
15652 } elseif ($method == 2) {
15654 $handle1 = fopen($fullpath_original_file_osencoded, "rb
");
15655 $handle2 = fopen("php:
15656 stream_copy_to_stream($handle1, $handle2);
15677 $result =
'<span class="clipboardCP' . ($showonlyonhover ?
' clipboardCPShowOnHover valignmiddle' :
'') .
'">';
15678 if ($texttoshow ===
'none') {
15679 $result .=
'<' . $tag .
' class="clipboardCPValue hidewithsize">' .
dol_escape_htmltag($valuetocopy, 1, 1) .
'</' . $tag .
'>';
15680 $result .=
'<span class="clipboardCPValueToPrint"></span>';
15681 } elseif ($texttoshow) {
15682 $result .=
'<' . $tag .
' class="clipboardCPValue hidewithsize">' .
dol_escape_htmltag($valuetocopy, 1, 1) .
'</' . $tag .
'>';
15683 $result .=
'<span class="clipboardCPValueToPrint">' .
dol_escape_htmltag($texttoshow, 1, 1) .
'</span>';
15685 $result .=
'<' . $tag .
' class="clipboardCPValue">' .
dol_escape_htmltag($valuetocopy, 1, 1) .
'</' . $tag .
'>';
15687 $result .=
'<span class="clipboardCPButton far fa-clipboard opacitymedium paddingleft pictomodule" title="' .
dolPrintHTML($langs->trans(
"ClickToCopyToClipboard")) .
'"></span>';
15688 $result .=
img_picto(
'',
'tick',
'class="clipboardCPTick hidden paddingleft pictomodule"');
15689 $result .=
'<span class="clipboardCPText"></span>';
15690 $result .=
'</span>';
15705 $result = json_decode($stringtodecode, $assoc);
15706 if ($result ===
null) {
15707 $result = unserialize($stringtodecode);
15734 if (is_null($filter) || !is_string($filter) || $filter ===
'') {
15737 if (!preg_match(
'/^\(.*\)$/', $filter)) {
15738 $filter =
'(' . $filter .
')';
15741 $regexstring =
'\(([a-zA-Z0-9_\.]+:[<>!=insotlke]+:[^\(\)]+)\)';
15742 $firstandlastparenthesis = 0;
15744 if (!
dolCheckFilters($filter, $errorstr, $firstandlastparenthesis)) {
15748 return 'Filter syntax error - ' . $errorstr;
15753 $t = preg_replace_callback(
'/' . $regexstring .
'/i',
'dolForgeDummyCriteriaCallback', $filter);
15754 $t = str_ireplace(array(
'and',
'or',
' '),
'', $t);
15757 if (preg_match(
'/[^\(\)]/', $t)) {
15758 $tmperrorstr =
'Bad syntax of the search string';
15759 $errorstr =
'Bad syntax of the search string: ' . $filter;
15763 dol_syslog(
"forgeSQLFromUniversalSearchCriteria Filter error - " . $errorstr, LOG_WARNING);
15764 return 'Filter error - ' . $tmperrorstr;
15768 $ret = ($noand ?
"" :
" AND ") . ($nopar ?
"" :
'(') . preg_replace_callback(
'/' . $regexstring .
'/i',
'dolForgeSQLCriteriaCallback', $filter) . ($nopar ?
"" :
')');
15770 if (is_object($db)) {
15771 $ret = str_replace(
'__NOW__',
"'" . $db->idate(
dol_now()) .
"'", $ret);
15773 if (is_object($user)) {
15774 $ret = str_replace(
'__USER_ID__', (
string) $user->id, $ret);
15789 $arrayofandtags = array();
15793 $parenthesislevel = 0;
15798 if ($parenthesislevel >= 1) {
15799 $sqlfilters = preg_replace(
'/^\(/',
'', preg_replace(
'/\)$/',
'', $sqlfilters));
15804 $countparenthesis = 0;
15805 while ($i < $nbofchars) {
15808 if ($char ==
'(') {
15809 $countparenthesis++;
15810 } elseif ($char ==
')') {
15811 $countparenthesis--;
15814 if ($countparenthesis == 0) {
15815 $char2 =
dol_substr($sqlfilters, $i + 1, 1);
15816 $char3 =
dol_substr($sqlfilters, $i + 2, 1);
15817 if ($char ==
'A' && $char2 ==
'N' && $char3 ==
'D') {
15820 if (!preg_match(
'/^\(.*\)$/', $s)) {
15821 $s =
'(' . $s .
')';
15823 $arrayofandtags[] = $s;
15836 if (!preg_match(
'/^\(.*\)$/', $s)) {
15837 $s =
'(' . $s .
')';
15839 $arrayofandtags[] = $s;
15842 return $arrayofandtags;
15854function dolCheckFilters($sqlfilters, &$error =
'', &$parenthesislevel = 0)
15858 $tmp = $sqlfilters;
15862 $parenthesislevel = 0;
15870 if ($char ==
'(') {
15871 if ($i == $parenthesislevel && $parenthesislevel == $counter) {
15873 $parenthesislevel++;
15876 } elseif ($char ==
')') {
15877 $nbcharremaining = ($nb - $i - 1);
15878 if ($nbcharremaining >= $counter) {
15879 $parenthesislevel = min($parenthesislevel, $counter - 1);
15881 if ($parenthesislevel > $counter && $nbcharremaining >= $counter) {
15882 $parenthesislevel = $counter;
15887 if ($counter < 0) {
15888 $error =
"Wrong balance of parenthesis in sqlfilters=" . $sqlfilters;
15889 $parenthesislevel = 0;
15897 if ($counter > 0) {
15898 $error =
"Wrong balance of parenthesis in sqlfilters=" . $sqlfilters;
15899 $parenthesislevel = 0;
15917 if (empty($matches[1])) {
15920 $tmp = explode(
':', $matches[1]);
15921 if (count($tmp) < 3) {
15941 if (empty($matches[1])) {
15944 $tmp = explode(
':', $matches[1], 3);
15945 if (count($tmp) < 3) {
15949 $operand = preg_replace(
'/[^a-z0-9\._]/i',
'', trim($tmp[0]));
15951 $operator = strtoupper(preg_replace(
'/[^a-z<>!=]/i',
'', trim($tmp[1])));
15954 'NOTLIKE' =>
'NOT LIKE',
15955 'ISNOT' =>
'IS NOT',
15956 'NOTIN' =>
'NOT IN',
15960 if (array_key_exists($operator, $realOperator)) {
15961 $operator = $realOperator[$operator];
15964 $tmpescaped = $tmp[2];
15970 if ($operator ==
'IN' || $operator ==
'NOT IN') {
15972 $tmpescaped2 =
'(';
15974 $tmpelemarray = explode(
',', $tmpescaped);
15975 foreach ($tmpelemarray as $tmpkey => $tmpelem) {
15977 $tmpelem = trim($tmpelem);
15978 if (preg_match(
'/^\'(.*)\'$/', $tmpelem, $reg)) {
15979 $tmpelemarray[$tmpkey] =
"'" . $db->escape($db->sanitize($reg[1], 2, 1, 1, 1)) .
"'";
15980 } elseif (ctype_digit((
string) $tmpelem)) {
15981 $tmpelemarray[$tmpkey] = (int) $tmpelem;
15982 } elseif (is_numeric((
string) $tmpelem)) {
15983 $tmpelemarray[$tmpkey] = (float) $tmpelem;
15984 } elseif (!
getDolGlobalString(
"MAIN_DISALLOW_UNSECURED_SELECT_INTO_EXTRAFIELDS_FILTER")) {
15985 $tmpelemarray[$tmpkey] = preg_replace(
'/[^a-z0-9_<>=!\s]/i',
'', $tmpelem);
15987 $tmpelemarray[$tmpkey] = preg_replace(
'/[^a-z0-9_]/i',
'', $tmpelem);
15990 $tmpescaped2 .= implode(
',', $tmpelemarray);
15991 $tmpescaped2 .=
')';
15993 $tmpescaped = $tmpescaped2;
15994 } elseif ($operator ==
'LIKE' || $operator ==
'NOT LIKE') {
15995 if (preg_match(
'/^\'([^\']*)\'$/', $tmpescaped, $regbis)) {
15996 $tmpescaped = $regbis[1];
15999 $tmpescaped =
"'" . $db->escape($tmpescaped) .
"'";
16000 } elseif (preg_match(
'/^\'(.*)\'$/', $tmpescaped, $regbis)) {
16003 $tmpescaped =
"'" . $db->escape($regbis[1]) .
"'";
16005 if (strtoupper($tmpescaped) ==
'NULL') {
16006 $tmpescaped =
'NULL';
16007 } elseif (ctype_digit((
string) $tmpescaped)) {
16008 $tmpescaped = (int) $tmpescaped;
16009 } elseif (is_numeric((
string) $tmpescaped)) {
16010 $tmpescaped = (float) $tmpescaped;
16012 $tmpescaped = preg_replace(
'/[^a-z0-9_]/i',
'', $tmpescaped);
16016 return '(' . $db->escape($operand) .
' ' . strtoupper($operator) .
' ' . $tmpescaped .
')';
16033 $out =
'<!-- timeline icon -->' .
"\n";
16034 $iconClass =
'fa fa-comments';
16039 if ($histo[$key][
'percent'] == -1) {
16040 $colorClass =
'timeline-icon-not-applicble';
16041 $pictoTitle = $langs->trans(
'StatusNotApplicable');
16042 } elseif ($histo[$key][
'percent'] == 0) {
16043 $colorClass =
'timeline-icon-todo';
16044 $pictoTitle = $langs->trans(
'StatusActionToDo') .
' (0%)';
16045 } elseif ($histo[$key][
'percent'] > 0 && $histo[$key][
'percent'] < 100) {
16046 $colorClass =
'timeline-icon-in-progress';
16047 $pictoTitle = $langs->trans(
'StatusActionInProcess') .
' (' . $histo[$key][
'percent'] .
'%)';
16048 } elseif ($histo[$key][
'percent'] >= 100) {
16049 $colorClass =
'timeline-icon-done';
16050 $pictoTitle = $langs->trans(
'StatusActionDone') .
' (100%)';
16053 if ($actionstatic->code ==
'AC_TICKET_CREATE') {
16054 $iconClass =
'fa fa-ticket';
16055 } elseif ($actionstatic->code ==
'AC_TICKET_MODIFY') {
16056 $iconClass =
'fa fa-pencilxxx';
16057 } elseif (preg_match(
'/^TICKET_MSG/', $actionstatic->code)) {
16058 $iconClass =
'fa fa-comments';
16059 } elseif (preg_match(
'/^TICKET_MSG_PRIVATE/', $actionstatic->code)) {
16060 $iconClass =
'fa fa-mask';
16062 if ($actionstatic->type_picto) {
16063 $img_picto =
img_picto(
'', $actionstatic->type_picto);
16065 if ($actionstatic->type_code ==
'AC_RDV') {
16066 $iconClass =
'fa fa-handshake';
16067 } elseif ($actionstatic->type_code ==
'AC_TEL') {
16068 $iconClass =
'fa fa-phone';
16069 } elseif ($actionstatic->type_code ==
'AC_FAX') {
16070 $iconClass =
'fa fa-fax';
16071 } elseif ($actionstatic->type_code ==
'AC_EMAIL') {
16072 $iconClass =
'fa fa-envelope';
16073 } elseif ($actionstatic->type_code ==
'AC_INT') {
16074 $iconClass =
'fa fa-shipping-fast';
16075 } elseif ($actionstatic->type_code ==
'AC_OTH_AUTO') {
16076 $iconClass =
'fa fa-robot';
16077 } elseif (!preg_match(
'/_AUTO/', $actionstatic->type_code)) {
16078 $iconClass =
'fa fa-robot';
16083 $out .=
'<i class="' . $iconClass .
' ' . $colorClass .
'" title="' . $pictoTitle .
'">' . $img_picto .
'</i>' .
"\n";
16097 $documents = array();
16099 $sql =
'SELECT ecm.rowid as id, ecm.src_object_type, ecm.src_object_id, ecm.filepath, ecm.filename, ecm.agenda_id';
16100 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'ecm_files ecm';
16101 $sql .=
" WHERE ecm.filepath = 'agenda/" . ((int)
$object->id) .
"'";
16103 $sql .=
' OR ecm.agenda_id = ' . (int)
$object->id;
16104 $sql .=
' ORDER BY ecm.position ASC';
16106 $resql = $db->query($sql);
16108 if ($db->num_rows($resql)) {
16109 while ($obj = $db->fetch_object($resql)) {
16110 $documents[$obj->id] = $obj;
16136function show_actions_messaging($conf, $langs, $db, $filterobj, $objcon =
null, $noprint = 0, $actioncode =
'', $donetodo =
'done', $filters = array(), $sortfield =
'a.datep,a.id', $sortorder =
'DESC')
16138 global $user, $conf;
16141 global $param, $massactionbutton;
16143 require_once DOL_DOCUMENT_ROOT .
'/comm/action/class/actioncomm.class.php';
16146 if (!is_object($filterobj) && !is_object($objcon)) {
16151 '@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';
16156 $sortfield_list = explode(
',', $sortfield);
16157 $sortfield_label_list = array(
'a.id' =>
'id',
'a.datep' =>
'dp',
'a.percent' =>
'percent');
16158 $sortfield_new_list = array();
16159 foreach ($sortfield_list as $sortfield_value) {
16160 $sortfield_new_list[] = $sortfield_label_list[trim($sortfield_value)];
16162 $sortfield_new = implode(
',', $sortfield_new_list);
16169 if (is_object($objcon) && $objcon->id > 0) {
16170 $sql =
"SELECT DISTINCT a.id, a.label as label,";
16172 $sql =
"SELECT a.id, a.label as label,";
16174 $sql .=
" a.datep as dp,";
16175 $sql .=
" a.note as message,";
16176 $sql .=
" a.datep2 as dp2,";
16177 $sql .=
" a.percent as percent, 'action' as type,";
16178 $sql .=
" a.fk_element, a.elementtype,";
16179 $sql .=
" a.fk_contact,";
16180 $sql .=
" a.email_from as msg_from,";
16181 $sql .=
" c.code as acode, c.libelle as alabel, c.picto as apicto,";
16182 $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";
16183 if (is_object($filterobj) && get_class($filterobj) ==
'Societe') {
16184 $sql .=
", sp.lastname, sp.firstname";
16185 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Adherent') {
16186 $sql .=
", m.lastname, m.firstname";
16187 } elseif (is_object($filterobj) && in_array(get_class($filterobj), array(
'Commande',
'CommandeFournisseur',
'Product',
'Ticket',
'BOM',
'Contrat',
'Facture',
'FactureFournisseur',
'Propal',
'Expedition'))) {
16190 if (is_object($filterobj) && !empty($filterobj->table_element) && !empty($filterobj->element) && !empty($filterobj->id) && array_key_exists(
'ref', $filterobj->fields)) {
16194 $sql .=
" FROM " . MAIN_DB_PREFIX .
"actioncomm as a";
16195 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"user as u on u.rowid = a.fk_user_action";
16196 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"c_actioncomm as c ON a.fk_action = c.id";
16198 $force_filter_contact = $filterobj instanceof
User;
16200 if (is_object($objcon) && $objcon->id > 0) {
16201 $force_filter_contact =
true;
16202 $sql .=
" INNER JOIN " . MAIN_DB_PREFIX .
"actioncomm_resources as r ON a.id = r.fk_actioncomm";
16203 $sql .=
" AND r.element_type = '" . $db->escape($objcon->table_element) .
"' AND r.fk_element = " . ((int) $objcon->id);
16206 if ((is_object($filterobj) && get_class($filterobj) ==
'Societe') || (is_object($filterobj) && get_class($filterobj) ==
'Contact')) {
16207 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"socpeople as sp ON a.fk_contact = sp.rowid";
16208 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Dolresource') {
16209 $sql .=
" INNER JOIN " . MAIN_DB_PREFIX .
"element_resources as er";
16210 $sql .=
" ON er.resource_type = 'dolresource'";
16211 $sql .=
" AND er.element_id = a.id";
16212 $sql .=
" AND er.resource_id = " . ((int) $filterobj->id);
16213 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Adherent') {
16214 $sql .=
", " . MAIN_DB_PREFIX .
"adherent as m";
16215 } elseif (is_object($filterobj) && get_class($filterobj) ==
'CommandeFournisseur') {
16216 $sql .=
", " . MAIN_DB_PREFIX .
"commande_fournisseur as o";
16217 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Product') {
16218 $sql .=
", " . MAIN_DB_PREFIX .
"product as o";
16219 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Ticket') {
16220 $sql .=
", " . MAIN_DB_PREFIX .
"ticket as o";
16221 } elseif (is_object($filterobj) && get_class($filterobj) ==
'BOM') {
16222 $sql .=
", " . MAIN_DB_PREFIX .
"bom_bom as o";
16223 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Contrat') {
16224 $sql .=
", " . MAIN_DB_PREFIX .
"contrat as o";
16225 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Facture') {
16226 $sql .=
", " . MAIN_DB_PREFIX .
"facture as o";
16227 } elseif (is_object($filterobj) && get_class($filterobj) ==
'FactureFournisseur') {
16228 $sql .=
", " . MAIN_DB_PREFIX .
"facture_fourn as o";
16229 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Commande') {
16230 $sql .=
", " . MAIN_DB_PREFIX .
"commande as o";
16231 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Expedition') {
16232 $sql .=
", " . MAIN_DB_PREFIX .
"expedition as o";
16233 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Propal') {
16234 $sql .=
", " . MAIN_DB_PREFIX .
"propal as o";
16236 if (is_object($filterobj) && !empty($filterobj->table_element) && !empty($filterobj->element) && !empty($filterobj->id) && array_key_exists(
'ref', $filterobj->fields)) {
16237 $sql .=
", " . MAIN_DB_PREFIX . $filterobj->table_element .
" as o";
16240 $sql .=
" WHERE a.entity IN (" .
getEntity(
'agenda') .
")";
16241 if (!$force_filter_contact) {
16242 if (is_object($filterobj) && in_array(get_class($filterobj), array(
'Societe',
'Client',
'Fournisseur')) && $filterobj->id) {
16243 $sql .=
" AND a.fk_soc = " . ((int) $filterobj->id);
16244 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Project' && $filterobj->id) {
16245 $sql .=
" AND a.fk_project = o.rowid AND a.fk_project = " . ((int) $filterobj->id);
16246 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Adherent') {
16247 $sql .=
" AND a.fk_element = m.rowid AND a.elementtype = 'member'";
16248 if ($filterobj->id) {
16249 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16251 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Commande') {
16252 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'order'";
16253 if ($filterobj->id) {
16254 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16256 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Expedition') {
16257 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'shipping'";
16258 if ($filterobj->id) {
16259 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16261 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Propal') {
16262 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'propal'";
16263 if ($filterobj->id) {
16264 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16266 } elseif (is_object($filterobj) && get_class($filterobj) ==
'CommandeFournisseur') {
16267 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'order_supplier'";
16268 if ($filterobj->id) {
16269 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16271 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Product') {
16272 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'product'";
16273 if ($filterobj->id) {
16274 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16276 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Ticket') {
16277 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'ticket'";
16278 if ($filterobj->id) {
16279 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16281 } elseif (is_object($filterobj) && get_class($filterobj) ==
'BOM') {
16282 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'bom'";
16283 if ($filterobj->id) {
16284 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16286 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Contrat') {
16287 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'contract'";
16288 if ($filterobj->id) {
16289 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16291 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Contact' && $filterobj->id) {
16292 $sql .=
" AND a.fk_contact = sp.rowid";
16293 if ($filterobj->id) {
16294 $sql .=
" AND a.fk_contact = " . ((int) $filterobj->id);
16296 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Facture') {
16297 $sql .=
" AND a.fk_element = o.rowid";
16298 if ($filterobj->id) {
16299 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id) .
" AND a.elementtype = 'invoice'";
16301 } elseif (is_object($filterobj) && get_class($filterobj) ==
'FactureFournisseur') {
16302 $sql .=
" AND a.fk_element = o.rowid";
16303 if ($filterobj->id) {
16304 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id) .
" AND a.elementtype = 'invoice_supplier'";
16307 if (is_object($filterobj) && !empty($filterobj->element) && !empty($filterobj->id) && array_key_exists(
'ref', $filterobj->fields)) {
16308 $sql .=
" AND a.fk_element = o.rowid";
16309 $sql .=
" AND a.elementtype = '" . $db->escape($filterobj->element) .
"'";
16310 if ($filterobj->id) {
16311 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16316 $sql .=
" AND u.rowid = " . ((int) $filterobj->id);
16320 if (!empty($actioncode) && $actioncode !=
'-1') {
16322 if ($actioncode ==
'AC_NON_AUTO') {
16323 $sql .=
" AND c.type != 'systemauto'";
16324 } elseif ($actioncode ==
'AC_ALL_AUTO') {
16325 $sql .=
" AND c.type = 'systemauto'";
16327 if ($actioncode ==
'AC_OTH') {
16328 $sql .=
" AND c.type != 'systemauto'";
16329 } elseif ($actioncode ==
'AC_OTH_AUTO') {
16330 $sql .=
" AND c.type = 'systemauto'";
16334 if ($actioncode ==
'AC_NON_AUTO') {
16335 $sql .=
" AND c.type != 'systemauto'";
16336 } elseif ($actioncode ==
'AC_ALL_AUTO') {
16337 $sql .=
" AND c.type = 'systemauto'";
16339 $sql .=
" AND c.code = '" . $db->escape($actioncode) .
"'";
16343 if ($donetodo ==
'todo') {
16344 $sql .=
" AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '" . $db->idate($now) .
"'))";
16345 } elseif ($donetodo ==
'done') {
16346 $sql .=
" AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '" . $db->idate($now) .
"'))";
16348 if (is_array($filters) && $filters[
'search_agenda_label']) {
16349 $sql .=
natural_search(
'a.label', $filters[
'search_agenda_label']);
16356 && (empty($actioncode) || $actioncode ==
'AC_OTH_AUTO' || $actioncode ==
'AC_EMAILING')
16358 $langs->load(
"mails");
16360 $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";
16361 $sql2 .=
", null as fk_element, '' as elementtype, null as contact_id";
16362 $sql2 .=
", 'AC_EMAILING' as acode, '' as alabel, '' as apicto";
16363 $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";
16364 if (is_object($filterobj) && get_class($filterobj) ==
'Societe') {
16365 $sql2 .=
", '' as lastname, '' as firstname";
16366 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Adherent') {
16367 $sql2 .=
", '' as lastname, '' as firstname";
16368 } elseif (is_object($filterobj) && get_class($filterobj) ==
'CommandeFournisseur') {
16369 $sql2 .=
", '' as ref";
16370 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Product') {
16371 $sql2 .=
", '' as ref";
16372 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Ticket') {
16373 $sql2 .=
", '' as ref";
16375 $sql2 .=
" FROM " . MAIN_DB_PREFIX .
"mailing as m, " . MAIN_DB_PREFIX .
"mailing_cibles as mc, " . MAIN_DB_PREFIX .
"user as u";
16376 $sql2 .=
" WHERE mc.email = '" . $db->escape($objcon->email) .
"'";
16377 $sql2 .=
" AND mc.statut = 1";
16378 $sql2 .=
" AND u.rowid = m.fk_user_valid";
16379 $sql2 .=
" AND mc.fk_mailing=m.rowid";
16383 $MAXWITHOUTPAGINATION =
getDolGlobalInt(
'AGENDA_MAX_EVENTS_ON_PAGE_WITHOUT_PAGINATION', 100);
16385 if ($sql || $sql2) {
16386 if (!empty($sql) && !empty($sql2)) {
16387 $sql = $sql .
" UNION " . $sql2;
16388 } elseif (empty($sql) && !empty($sql2)) {
16394 $limit = $MAXWITHOUTPAGINATION;
16397 $sql .= $db->order($sortfield_new, $sortorder);
16399 $sql .= $db->plimit($limit + 1, $offset);
16402 dol_syslog(
"function.lib::show_actions_messaging", LOG_DEBUG);
16404 $resql = $db->query($sql);
16407 $num = $db->num_rows($resql);
16409 $imaxinloop = ($limit ? min($num, $limit) : $num);
16410 while ($i < $imaxinloop) {
16411 $obj = $db->fetch_object($resql);
16413 if ($obj->type ==
'action') {
16415 $contactaction->id = $obj->id;
16416 $result = $contactaction->fetchResources();
16419 setEventMessage(
"actions.lib::show_actions_messaging Error fetch resource",
'errors');
16425 if (($obj->percent >= 0 and $obj->percent < 100) || ($obj->percent == -1 && $obj->dp > $now)) {
16426 $tododone =
'todo';
16429 $histo[$numaction] = array(
16430 'type' => $obj->type,
16431 'tododone' => $tododone,
16433 'datestart' => $db->jdate($obj->dp),
16434 'dateend' => $db->jdate($obj->dp2),
16435 'note' => $obj->label,
16436 'message' => $obj->message,
16437 'percent' => $obj->percent,
16439 'userid' => $obj->user_id,
16440 'login' => $obj->user_login,
16441 'userfirstname' => $obj->user_firstname,
16442 'userlastname' => $obj->user_lastname,
16443 'userphoto' => $obj->user_photo,
16444 'msg_from' => $obj->msg_from,
16446 'contact_id' => $obj->fk_contact,
16447 'socpeopleassigned' => $contactaction->socpeopleassigned,
16448 'lastname' => (empty($obj->lastname) ?
'' : $obj->lastname),
16449 'firstname' => (empty($obj->firstname) ?
'' : $obj->firstname),
16450 'fk_element' => $obj->fk_element,
16451 'elementtype' => $obj->elementtype,
16453 'acode' => $obj->acode,
16454 'alabel' => $obj->alabel,
16455 'libelle' => $obj->alabel,
16456 'apicto' => $obj->apicto
16459 $histo[$numaction] = array(
16460 'type' => $obj->type,
16461 'tododone' =>
'done',
16463 'datestart' => $db->jdate($obj->dp),
16464 'dateend' => $db->jdate($obj->dp2),
16465 'note' => $obj->label,
16466 'message' => $obj->message,
16467 'percent' => $obj->percent,
16468 'acode' => $obj->acode,
16470 'userid' => $obj->user_id,
16471 'login' => $obj->user_login,
16472 'userfirstname' => $obj->user_firstname,
16473 'userlastname' => $obj->user_lastname,
16474 'userphoto' => $obj->user_photo
16490 $langs->loadLangs(array(
"admin",
"errors"));
16491 $out =
info_admin($langs->trans(
"WarningModuleXDisabledSoYouMayMissEventHere", $langs->transnoentitiesnoconv(
"Module2400Name")), 0, 0,
'warning');
16495 $delay_warning =
getDolGlobalInt(
'MAIN_DELAY_ACTIONS_TODO') * 24 * 60 * 60;
16497 require_once DOL_DOCUMENT_ROOT .
'/comm/action/class/actioncomm.class.php';
16498 include_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
16499 require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formactions.class.php';
16500 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
16505 $userstatic =
new User($db);
16506 $contactstatic =
new Contact($db);
16507 $userGetNomUrlCache = array();
16508 $contactGetNomUrlCache = array();
16510 $out .=
'<div class="filters-container" >';
16511 $out .=
'<form name="listactionsfilter" class="listactionsfilter" action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST">';
16512 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
16515 $objcon && get_class($objcon) ==
'Contact' &&
16516 (is_null($filterobj) || get_class($filterobj) ==
'Societe')
16518 $out .=
'<input type="hidden" name="id" value="' . $objcon->id .
'" />';
16520 $out .=
'<input type="hidden" name="id" value="' . $filterobj->id .
'" />';
16522 if (($filterobj && get_class($filterobj) ==
'Societe')) {
16523 $out .=
'<input type="hidden" name="socid" value="' . $filterobj->id .
'" />';
16525 $out .=
'<input type="hidden" name="userid" value="' . $filterobj->id .
'" />';
16530 $out .=
'<div class="div-table-responsive-no-min">';
16531 $out .=
'<table class="noborder borderbottom centpercent">';
16533 $out .=
'<tr class="liste_titre">';
16537 $out .=
'<th class="liste_titre width50 middle">';
16538 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0,
'checkforselect', 1);
16539 $out .= $searchpicto;
16544 $out .=
getTitleFieldOfList(
'Date', 0, $_SERVER[
"PHP_SELF"],
'a.datep',
'', $param,
'', $sortfield, $sortorder,
'nowraponall nopaddingleftimp ') .
"\n";
16546 $out .=
'<th class="liste_titre hideonsmartphone"><strong class="hideonsmartphone">' . $langs->trans(
"Search") .
' : </strong></th>';
16548 $out .=
'<th class="liste_titre"></th>';
16551 $out .=
'<th class="liste_titre">';
16552 $out .=
'<span class="fas fa-square inline-block fawidth30 hideonsmartphone" style="color: #ddd;" title="' . $langs->trans(
"ActionType") .
'"></span>';
16553 $out .= $formactions->select_type_actions($actioncode,
"actioncode",
'',
getDolGlobalString(
'AGENDA_USE_EVENT_TYPE') ? -1 : 1, 0, 0, 1,
'selecttype minwidth100', $langs->trans(
"Type"));
16556 $out .=
'<th class="liste_titre maxwidth100onsmartphone">';
16557 $out .=
'<input type="text" class="maxwidth100onsmartphone" name="search_agenda_label" value="' . $filters[
'search_agenda_label'] .
'" placeholder="' . $langs->trans(
"Label") .
'">';
16562 $out .=
'<th class="liste_titre width50 middle">';
16563 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0,
'checkforselect', 1);
16564 $out .= $searchpicto;
16570 $out .=
'</table>';
16577 $out .=
'<ul class="timeline">';
16581 if ($filterobj instanceof
Societe) {
16582 $tmp .=
'<a href="' . DOL_URL_ROOT .
'/comm/action/list.php?mode=show_list&socid=' . $filterobj->id .
'&status=done">';
16584 if ($filterobj instanceof
User) {
16585 $tmp .=
'<a href="' . DOL_URL_ROOT .
'/comm/action/list.php?mode=show_list&socid=' . $filterobj->id .
'&status=done">';
16587 $tmp .= ($donetodo !=
'done' ? $langs->trans(
"ActionsToDoShort") :
'');
16588 $tmp .= ($donetodo !=
'done' && $donetodo !=
'todo' ?
' / ' :
'');
16589 $tmp .= ($donetodo !=
'todo' ? $langs->trans(
"ActionsDoneShort") :
'');
16591 if ($filterobj instanceof
Societe) {
16594 if ($filterobj instanceof
User) {
16600 require_once DOL_DOCUMENT_ROOT .
'/comm/action/class/cactioncomm.class.php';
16602 $arraylist = $caction->liste_array(1,
'code',
'', (!
getDolGlobalString(
'AGENDA_USE_EVENT_TYPE') ? 1 : 0),
'', 1);
16604 $actualCycleDate =
false;
16607 foreach ($histo as $key => $value) {
16608 $actionstatic->fetch($histo[$key][
'id']);
16610 $actionstatic->type_picto = $histo[$key][
'apicto'];
16611 $actionstatic->type_code = $histo[$key][
'acode'];
16613 $labeltype = $actionstatic->type_code;
16614 if (!
getDolGlobalString(
'AGENDA_USE_EVENT_TYPE') && empty($arraylist[$labeltype])) {
16615 $labeltype =
'AC_OTH';
16617 if (!empty($actionstatic->code) && preg_match(
'/^TICKET_MSG/', $actionstatic->code)) {
16618 $labeltype = $langs->trans(
"Message");
16620 if (!empty($arraylist[$labeltype])) {
16621 $labeltype = $arraylist[$labeltype];
16623 if ($actionstatic->type_code ==
'AC_OTH_AUTO' && ($actionstatic->type_code != $actionstatic->code) && $labeltype && !empty($arraylist[$actionstatic->code])) {
16624 $labeltype .=
' - ' . $arraylist[$actionstatic->code];
16628 $url = DOL_URL_ROOT .
'/comm/action/card.php?id=' . $histo[$key][
'id'];
16630 $tmpa =
dol_getdate($histo[$key][
'datestart'],
false);
16632 if (isset($tmpa[
'year']) && isset($tmpa[
'yday']) && $actualCycleDate !== $tmpa[
'year'] .
'-' . $tmpa[
'yday']) {
16633 $actualCycleDate = $tmpa[
'year'] .
'-' . $tmpa[
'yday'];
16634 $out .=
'<!-- timeline time label -->';
16635 $out .=
'<li class="time-label">';
16636 $out .=
'<span class="timeline-badge-date">';
16637 $out .=
dol_print_date($histo[$key][
'datestart'],
'daytext',
'tzuserrel', $langs);
16640 $out .=
'<!-- /.timeline-label -->';
16644 $out .=
'<!-- timeline item -->' .
"\n";
16645 $out .=
'<li class="timeline-code-' . (!empty($actionstatic->code) ? strtolower($actionstatic->code) :
"none") .
'">';
16648 $typeicon = $actionstatic->getTypePicto(
'pictofixedwidth timeline-icon-not-applicble', $labeltype);
16653 $out .=
'<div class="timeline-item">' .
"\n";
16655 $out .=
'<span class="time timeline-header-action2">';
16657 if (isset($histo[$key][
'type']) && $histo[$key][
'type'] ==
'mailing') {
16658 $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") .
' ';
16659 $out .= $histo[$key][
'id'];
16662 $out .= $actionstatic->getNomUrl(1, -1,
'valignmiddle') .
' ';
16666 $user->hasRight(
'agenda',
'allactions',
'create') ||
16667 (($actionstatic->authorid == $user->id || $actionstatic->userownerid == $user->id) && $user->hasRight(
'agenda',
'myactions',
'create'))
16669 $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) .
'">';
16671 $out .=
img_picto($langs->trans(
"Modify"),
'edit',
'class="edita"');
16678 $out .=
'<span class="time"><i class="fa fa-clock valignmiddle"></i> ';
16679 $out .=
'<span class="valignmiddle marginrightonly">';
16680 $out .=
dol_print_date($histo[$key][
'datestart'],
'day',
'tzuserrel');
16683 $out .=
' '.dol_print_date($histo[$key][
'datestart'],
'hour',
'tzuserrel',
null,
false,
'opacitymedium');
16685 if ($histo[$key][
'dateend'] && $histo[$key][
'dateend'] != $histo[$key][
'datestart']) {
16686 $tmpa =
dol_getdate($histo[$key][
'datestart'],
true);
16687 $tmpb =
dol_getdate($histo[$key][
'dateend'],
true);
16688 if ($tmpa[
'mday'] == $tmpb[
'mday'] && $tmpa[
'mon'] == $tmpb[
'mon'] && $tmpa[
'year'] == $tmpb[
'year']) {
16689 $out .=
' - ' .
dol_print_date($histo[$key][
'dateend'],
'hour',
'tzuserrel',
null,
false, 1);
16691 $out .=
' - ' .
dol_print_date($histo[$key][
'dateend'],
'day',
'tzuserrel');
16693 $out .=
' '.dol_print_date($histo[$key][
'dateend'],
'hour',
'tzuserrel',
null,
false,
'opacitymedium');
16698 if ($histo[$key][
'percent'] == 0 && $histo[$key][
'datestart'] && $histo[$key][
'datestart'] < ($now - $delay_warning)) {
16701 if ($histo[$key][
'percent'] == 0 && !$histo[$key][
'datestart'] && $histo[$key][
'dateend'] && $histo[$key][
'datestart'] < ($now - $delay_warning)) {
16704 if ($histo[$key][
'percent'] > 0 && $histo[$key][
'percent'] < 100 && $histo[$key][
'dateend'] && $histo[$key][
'dateend'] < ($now - $delay_warning)) {
16707 if ($histo[$key][
'percent'] > 0 && $histo[$key][
'percent'] < 100 && !$histo[$key][
'dateend'] && $histo[$key][
'datestart'] && $histo[$key][
'datestart'] < ($now - $delay_warning)) {
16711 $out .=
img_warning($langs->trans(
"Late")) .
' ';
16713 $out .=
"</span></span>\n";
16715 $out .=
'<span class="time">';
16716 $out .= $actionstatic->getLibStatut(2);
16720 $out .=
'<h3 class="timeline-header">';
16723 $out .=
'<div class="messaging-author inline-block tdoverflowmax150 valignmiddle marginrightonly">';
16724 if ($histo[$key][
'userid'] > 0) {
16725 if (!isset($userGetNomUrlCache[$histo[$key][
'userid']])) {
16726 $userstatic->fetch($histo[$key][
'userid']);
16727 $userGetNomUrlCache[$histo[$key][
'userid']] = $userstatic->getNomUrl(-1,
'', 0, 0, 16, 0,
'firstelselast',
'');
16729 $out .= $userGetNomUrlCache[$histo[$key][
'userid']];
16730 } elseif (!empty($histo[$key][
'msg_from']) && $actionstatic->code ==
'TICKET_MSG') {
16731 if (!isset($contactGetNomUrlCache[$histo[$key][
'msg_from']])) {
16732 if ($contactstatic->fetch(0,
null,
'', $histo[$key][
'msg_from']) > 0) {
16733 $contactGetNomUrlCache[$histo[$key][
'msg_from']] = $contactstatic->getNomUrl(-1,
'', 16);
16735 $contactGetNomUrlCache[$histo[$key][
'msg_from']] = $histo[$key][
'msg_from'];
16738 $out .= $contactGetNomUrlCache[$histo[$key][
'msg_from']];
16740 $out .=
'<img class="photomemberphoto userphoto" alt="" src="/public/theme/common/user_anonymous.png">'.$langs->trans(
"Anonymous");
16745 $out .=
' <div class="messaging-title inline-block">';
16747 if (empty($conf->dol_optimize_smallscreen) && $actionstatic->type_code !=
'AC_OTH_AUTO') {
16748 $out .= $labeltype .
' - ';
16753 if (!empty($actionstatic->code) && preg_match(
'/^TICKET_MSG_PRIVATE/', $actionstatic->code)) {
16754 $out .= $langs->trans(
'TicketNewMessage').
' <em>('.$langs->trans(
'Private').
')</em>';
16755 } elseif (!empty($actionstatic->code) && preg_match(
'/^TICKET_MSG/', $actionstatic->code)) {
16756 $out .= $langs->trans(
'TicketNewMessage');
16757 } elseif (isset($histo[$key][
'type'])) {
16758 if ($histo[$key][
'type'] ==
'action') {
16759 $transcode = $langs->transnoentitiesnoconv(
"Action" . $histo[$key][
'acode']);
16760 $libelle = ($transcode !=
"Action" . $histo[$key][
'acode'] ? $transcode : $histo[$key][
'alabel']);
16761 $libelle = $histo[$key][
'note'];
16762 $actionstatic->id = $histo[$key][
'id'];
16763 if ($libelle != $labeltype) {
16766 } elseif ($histo[$key][
'type'] ==
'mailing') {
16767 $out .=
'<a href="' . DOL_URL_ROOT .
'/comm/mailing/card.php?id=' . $histo[$key][
'id'] .
'">' .
img_object($langs->trans(
"ShowEMailing"),
"email") .
' ';
16768 $transcode = $langs->transnoentitiesnoconv(
"Action" . $histo[$key][
'acode']);
16769 $libelle = ($transcode !=
"Action" . $histo[$key][
'acode'] ? $transcode :
'Send mass mailing');
16772 $libelle .= $histo[$key][
'note'];
16776 $out = preg_replace(
'/ - $/',
'', $out);
16778 if (isset($histo[$key][
'elementtype']) && !empty($histo[$key][
'fk_element'])) {
16779 if (isset($conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']]) && isset($conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']][$histo[$key][
'fk_element']])) {
16780 $link = $conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']][$histo[$key][
'fk_element']];
16782 if (!isset($conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']])) {
16783 $conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']] = array();
16785 $link =
dolGetElementUrl($histo[$key][
'fk_element'], $histo[$key][
'elementtype'], 1);
16786 $conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']][$histo[$key][
'fk_element']] = $link;
16789 $out .=
' - ' . $link;
16799 !empty($histo[$key][
'message'] && $histo[$key][
'message'] != $libelle)
16800 && $actionstatic->code !=
'AC_TICKET_CREATE'
16801 && $actionstatic->code !=
'AC_TICKET_MODIFY'
16803 $out .=
'<div class="timeline-body wordbreak small">';
16804 $truncateLines =
getDolGlobalInt(
'MAIN_TRUNCATE_TIMELINE_MESSAGE', 3);
16807 if ($truncateLines > 0 && strlen($newmess) > strlen($truncatedText)) {
16808 $out .=
'<div class="readmore-block --closed" >';
16809 $out .=
' <div class="readmore-block__excerpt">';
16811 $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>';
16813 $out .=
' <div class="readmore-block__full-text" >';
16815 $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>';
16829 if (isset($histo[$key][
'socpeopleassigned']) && is_array($histo[$key][
'socpeopleassigned']) && count($histo[$key][
'socpeopleassigned']) > 0) {
16831 foreach ($histo[$key][
'socpeopleassigned'] as $cid => $Tab) {
16832 if (empty($conf->cache[
'contact'][$cid])) {
16834 $contact->fetch($cid);
16835 $conf->cache[
'contact'][$cid] = $contact;
16837 $contact = $conf->cache[
'contact'][$cid];
16841 $contactList .= !empty($contactList) ?
', ' :
'';
16842 $contactList .= $contact->getNomUrl(1);
16843 if (isset($histo[$key][
'acode']) && $histo[$key][
'acode'] ==
'AC_TEL') {
16844 if (!empty($contact->phone_pro)) {
16851 $footer .= $langs->trans(
'ActionOnContact') .
' : ' . $contactList;
16852 } elseif (empty($objcon->id) && isset($histo[$key][
'contact_id']) && $histo[$key][
'contact_id'] > 0) {
16853 if (empty($conf->cache[
'contact'][$histo[$key][
'contact_id']])) {
16855 $result = $contact->fetch($histo[$key][
'contact_id']);
16856 $conf->cache[
'contact'][$histo[$key][
'contact_id']] = $contact;
16858 $contact = $conf->cache[
'contact'][$histo[$key][
'contact_id']];
16859 $result = ($contact instanceof
Contact) ? $contact->id : 0;
16863 $footer .= $contact->getNomUrl(1);
16864 if (isset($histo[$key][
'acode']) && $histo[$key][
'acode'] ==
'AC_TEL') {
16865 if (!empty($contact->phone_pro)) {
16873 if (!empty($documents)) {
16874 $footer .=
'<div class="timeline-documents-container">';
16875 foreach ($documents as $doc) {
16876 $footer .=
'<span id="document_' . $doc->id .
'" class="timeline-documents" ';
16877 $footer .=
' data-id="' . $doc->id .
'" ';
16878 $footer .=
' data-path="' . $doc->filepath .
'"';
16882 $filePath = DOL_DATA_ROOT .
'/' . $doc->filepath .
'/' . $doc->filename;
16884 if (empty($doc->agenda_id)) {
16885 $dir_ref = $actionstatic->id;
16886 $modulepart =
'actions';
16888 $split_dir = explode(
'/', $doc->filepath);
16889 $modulepart = array_shift($split_dir);
16890 $dir_ref = implode(
'/', $split_dir);
16893 $file = $dir_ref .
'/' . $doc->filename;
16894 $thumb = $dir_ref .
'/thumbs/' . substr($doc->filename, 0, strrpos($doc->filename,
'.')) .
'_mini' . substr($doc->filename, strrpos($doc->filename,
'.'));
16895 $doclink =
dol_buildpath(
'document.php', 1) .
'?modulepart=' . $modulepart .
'&attachment=0&file=' . urlencode($file) .
'&entity=' . $conf->entity;
16896 $viewlink =
dol_buildpath(
'viewimage.php', 1) .
'?modulepart=' . $modulepart .
'&file=' . urlencode($thumb) .
'&entity=' . $conf->entity;
16900 $mimeAttr =
' mime="' . $mime .
'" ';
16902 if (in_array($mime, array(
'image/png',
'image/jpeg',
'application/pdf'))) {
16903 $class .=
' documentpreview';
16906 $footer .=
'<a href="' . $doclink .
'" class="btn-link ' . $class .
'" target="_blank" rel="noopener noreferrer" ' . $mimeAttr .
' >';
16907 $footer .=
img_mime($filePath) .
' ' . $doc->filename;
16910 $footer .=
'</span>';
16912 $footer .=
'</div>';
16915 if (!empty($footer)) {
16916 $out .=
'<div class="timeline-footer">' . $footer .
'</div>';
16919 $out .=
'</div>' .
"\n";
16922 $out .=
'<!-- END timeline item -->';
16929 jQuery(document).ready(function () {
16930 $(document).on("click", "[data-read-more-action]", function(e){
16931 console.log("We click on data-read-more-action");
16932 let readMoreBloc = $(this).closest(".readmore-block");
16933 if(readMoreBloc.length > 0){
16934 e.preventDefault();
16935 if($(this).attr("data-read-more-action") == "close"){
16936 readMoreBloc.addClass("--closed").removeClass("--open");
16937 $("html, body").animate({
16938 scrollTop: readMoreBloc.offset().top - 200
16941 readMoreBloc.addClass("--open").removeClass("--closed");
16949 if (empty($histo)) {
16950 $out .=
'<span class="opacitymedium">' . $langs->trans(
"NoRecordFound") .
'</span>';
16953 if ($num > $MAXWITHOUTPAGINATION) {
16954 $langs->load(
"errors");
16956 $out .=
'<center><span class="opacitymedium">...' . $langs->trans(
"WarningTooManyDataPleaseUseMoreFilters", $MAXWITHOUTPAGINATION) .
'...</span></center>';
16979function buildParamDate($prefix, $timestamp =
null, $hourTime =
'', $gm =
'auto')
16981 if ($timestamp ===
null) {
16982 $timestamp =
GETPOSTDATE($prefix, $hourTime, $gm);
16989 if ($hourTime ===
'getpost' || ($timestamp !==
null &&
dol_print_date($timestamp,
'%H:%M:%S') !==
'00:00:00')) {
16990 $TParam = array_merge($TParam, array(
16997 return '&' . http_build_query($TParam);
17018function recordNotFound($message =
'', $printheader = 1, $printfooter = 1, $showonlymessage = 0, $params =
null)
17020 global $conf, $db, $langs, $hookmanager;
17023 if (!is_object($langs)) {
17024 include_once DOL_DOCUMENT_ROOT .
'/core/class/translate.class.php';
17026 $langs->setDefaultLang();
17029 $langs->load(
"errors");
17031 if ($printheader) {
17032 if (function_exists(
"llxHeader")) {
17034 } elseif (function_exists(
"llxHeaderVierge")) {
17039 print
'<div class="error">';
17040 if (empty($message)) {
17041 print $langs->trans(
"ErrorRecordNotFound");
17043 print $langs->trans($message);
17048 if (empty($showonlymessage)) {
17049 if (empty($hookmanager)) {
17050 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
17053 $hookmanager->initHooks(array(
'main'));
17056 $parameters = array(
'message' => $message,
'params' => $params);
17057 $reshook = $hookmanager->executeHooks(
'getErrorRecordNotFound', $parameters,
$object, $action);
17058 print $hookmanager->resPrint;
17061 if ($printfooter && function_exists(
"llxFooter")) {
17063 if (is_object($db)) {
17102 foreach ($array2 as $key => $value) {
17103 if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
17106 $merged[$key] = $value;
17121 if (!empty($obj->socid)) {
17122 return (
int) $obj->socid;
17123 } elseif (!empty($obj->soc_id)) {
17124 return (
int) $obj->soc_id;
17125 } elseif (!empty($obj->societe_id)) {
17126 return (
int) $obj->societe_id;
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
global $dolibarr_main_url_root
if(!defined( 'NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined( 'NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined( 'NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined( 'NOIPCHECK')) llxHeaderVierge($title, $head="", $disablejs=0, $disablehead=0, $arrayofjs=[], $arrayofcss=[])
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='', $readonly=0)
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.
static getValidAddress($address, $format, $encode=0, $maxnumberofemail=0)
Return a formatted address string for SMTP protocol.
Class to manage GeoIP conversion Usage: $geoip=new GeoIP('country',$datfile); $geoip->getCountryCodeF...
Class to manage invoices.
Class to manage predefined suppliers products.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
isACompany()
Check if third party is a company (Business) or an end user (Consumer)
Class to manage translations.
Class to manage Dolibarr users.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
dol_get_prev_month($month, $year)
Return previous month.
dol_get_next_day($day, $month, $year)
Return next day.
getServerTimeZoneInt($refgmtdate='now')
Return server timezone int.
dol_get_prev_day($day, $month, $year)
Return previous day.
dol_get_next_month($month, $year)
Return next month.
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.
isValidMailDomain($mail)
Return true if email has a domain name that can be resolved to MX type.
isValidVATID($company)
Check if VAT numero is valid (check done on syntax only, no database or remote access)
dol_html_entity_decode($a, $b, $c='UTF-8', $keepsomeentities=0)
Replace html_entity_decode functions to manage errors.
dol_now($mode='gmt')
Return date for now.
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.
dol_getmypid()
Return getmypid() or random PID when function is disabled Some web hosts disable this php function fo...
getLanguageCodeFromCountryCode($countrycode)
Return default language from country code.
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.
img_credit_card($brand, $morecss='fa-2x inline-block valignmiddle')
Return image of a credit card according to its brand name.
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.
dol_print_phone($phone, $countrycode='', $contactid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
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.
dolBuildUrl($url, $params=[], $addtoken=false)
Return path of url.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
getObjectSocId($obj)
Get the socid of an object, supporting legacy attribute names.
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.
getDolEntity()
Return the current entity.
picto_required()
Return picto saying a field is required.
isDolTms($timestamp)
isDolTms check if a timestamp is valid.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
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.
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-...
dol_sanitizePathName($str, $newstr='_', $unaccent=0, $allowdash=0)
Clean a string to use it as a path name.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
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.
getDolOptimizeSmallScreen()
Return if render must be optimized for small screen.
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.
jsonOrUnserialize($stringtodecode, $assoc=true)
Decode an encoded string.
dol_print_socialnetworks($value, $contactid, $socid, $type, $dictsocialnetworks=array())
Show social network link.
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tab header of a card.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
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_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)
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
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.
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_clone_in_array($srcobject, $startlevel=0)
Create a clone of instance of object into a full array, using recursive call.
dol_print_email($email, $contactid=0, $socid=0, $addlink=0, $max=0, $showinvalid=1, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
dol_strtoupper($string, $encoding="UTF-8")
Convert a string to upper.
getMultidirVersion($object, $module='', $forobject=0)
Return the full path of the directory where a module (or an object of a module) stores its versioned ...
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
dol_sanitizeUrl($stringtoclean, $type=1)
Clean a string to use it as an URL (into a href or src attribute)
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.
getDolDefaultContextPage($s)
Return the default context page string.
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.
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)
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.
getDolDBType()
Return the current entity.
print_titre($title)
Show a title.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_string_nounprintableascii($str, $removetabcrlf=1)
Clean a string from all non printable ASCII chars (0x00-0x1F and 0x7F).
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalBool($key, $default=false)
Return a Dolibarr global constant boolean value.
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).
get_product_localtax_for_country($idprod, $local, $thirdpartytouseforcountry)
Return localtax vat rate of a product in a particular country or default country vat if product is un...
getUserRemoteIP($trusted=0)
Return the real IP of remote user.
buildParamDate($prefix, $timestamp=null, $hourTime='', $gm='auto')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
dol_string_is_good_iso($s, $clean=0)
Check if a string is a correct iso string If not, it will not be considered as HTML encoded even if i...
getNonce()
Return a random string to be used as a nonce value for js.
isStringVarMatching($var, $regextext, $matchrule=1)
Check if a variable with name $var start with $regextext.
dolSlugify($stringtoslugify)
Returns text slugified (lowercase and no special char, separator is "-").
dol_concat($text1, $text2)
Concat 2 strings.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
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...
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.
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.
dolForgeDummyCriteriaCallback($matches)
Function to forge a SQL criteria from a Dolibarr filter syntax string.
dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0, $allowed_tags=array(), $allowlink=0, $allowscript=0, $allowstyle=0, $allowphp=0)
Clean a string to keep only desirable HTML tags.
dol_escape_json($stringtoescape)
Returns text escaped for inclusion into javascript code.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.
dol_validElement($element)
Return if var element is ok.
dol_sanitizeKeyCode($str)
Clean a string to use it as a key or code.
isModEnabled($module)
Is Dolibarr module enabled.
array_merge_recursive_distinct(array $array1, array $array2)
Recursively merges two arrays while preserving keys and replacing existing values.
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 rate, when selling a product with vat $vatrate,...
dol_eval_standard($s, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
get_product_vat_for_country($idprod, $thirdpartytouseforcountry, $idprodfournprice=0)
Return vat rate of a product in a particular country, or default country vat if product is unknown.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
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.
multi select button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
treeview li table
No Email.
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.
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.
measuringUnitString($unitid, $measuring_style='', $unitscale=null, $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
$conf db name
Only used if Module[ID]Name translation string is not found.
realCharForNumericEntities($matches)
Return the real char for a numeric entities.