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') {
192 $entity = (int) (empty(
$object->entity) ? $conf->entity :
$object->entity);
193 if (!isset($conf->$module->multidir_output[$entity])) {
194 return 'error-diroutput-not-defined-for-this-entity-and-object='.$module;
196 $s = $conf->$module->multidir_output[$entity] . $subdirectory;
198 if ($forobject &&
$object->id > 0) {
202 } elseif (isset($conf->$module) && property_exists($conf->$module,
'dir_output')) {
204 if ($mode !=
'outputrel') {
205 $s = $conf->$module->dir_output . $subdirectory;
207 if ($forobject &&
$object->id > 0) {
212 return 'error-diroutput-not-defined-for-this-entity-and-object='.$module;
214 } elseif ($mode ==
'temp') {
215 if (isset($conf->$module) && property_exists($conf->$module,
'multidir_temp')) {
217 $entity = (int) (empty(
$object->entity) ? $conf->entity :
$object->entity);
218 if (!isset($conf->$module->multidir_temp[$entity])) {
219 return 'error-dirtemp-not-defined-for-this-entity-and-object='.$module;
221 return $conf->$module->multidir_temp[$entity];
222 } elseif (isset($conf->$module) && property_exists($conf->$module,
'dir_temp')) {
223 return $conf->$module->dir_temp;
225 return 'error-dirtemp-not-defined-for-this-entity-and-object='.$module;
228 return 'error-bad-value-for-mode';
272 return (
string) (isset($conf->global->$key) ? $conf->global->$key : $default);
287 return (
int) (isset($conf->global->$key) ? $conf->global->$key : $default);
302 return (
float) (isset($conf->global->$key) ? $conf->global->$key : $default);
316 return (
bool) ($conf->global->$key ?? $default);
327 return (
string) $conf->currency;
338 return (
string) $conf->dol_optimize_smallscreen;
349 return (
int) $conf->entity;
360 return $conf->db->type;
371 return str_replace(
'_',
'', basename(dirname($s)).basename($s,
'.php'));
385 if (empty($tmpuser)) {
390 return (
string) (isset($tmpuser->conf->$key) ? $tmpuser->conf->$key : $default);
403 if (empty($tmpuser)) {
408 return (
int) (isset($tmpuser->conf->$key) ? $tmpuser->conf->$key : $default);
425 'adherent' =>
'member',
426 'member_type' =>
'adherent_type',
428 'contrat' =>
'contract',
429 'entrepot' =>
'stock',
430 'projet' =>
'project',
431 'categorie' =>
'category',
432 'commande' =>
'order',
433 'expedition' =>
'shipping',
434 'facture' =>
'invoice',
435 'fichinter' =>
'intervention',
436 'ficheinter' =>
'intervention',
437 'propale' =>
'propal',
438 'socpeople' =>
'contact',
439 'fournisseur' =>
'supplier',
441 'actioncomm' =>
'agenda',
442 'product_price' =>
'productprice',
443 'product_fournisseur_price' =>
'productsupplierprice',
463 $arrayconv[
'supplier_order'] =
'fournisseur';
464 $arrayconv[
'supplier_invoice'] =
'fournisseur';
467 $module_alt = $module;
468 if (!empty($arrayconv[$module])) {
469 $module_alt = $arrayconv[$module];
471 $module_bis = $module;
472 if (!empty($arrayconvbis[$module])) {
473 $module_bis = $arrayconvbis[$module];
476 return !empty($conf->modules[$module]) || !empty($conf->modules[$module_alt]) || !empty($conf->modules[$module_bis]);
494 $moduletomoduletouse = array(
495 'invoice' =>
'facture',
497 $moduleParmsMapping = array(
498 'product' =>
'produit',
501 if (!empty($moduletomoduletouse[$module])) {
502 $module = $moduletomoduletouse[$module];
505 $warningDelayPath = $parmlevel1;
506 if (!empty($moduleParmsMapping[$warningDelayPath])) {
507 $warningDelayPath = $moduleParmsMapping[$warningDelayPath];
511 if (!empty($conf->$module) && !empty($conf->$module->$warningDelayPath) && !empty($conf->$module->$warningDelayPath->$parmlevel2) && !empty($conf->$module->$warningDelayPath->$parmlevel2->warning_delay)) {
512 return (
int) $conf->$module->$warningDelayPath->$parmlevel2->warning_delay;
515 if (!empty($conf->$module) && !empty($conf->$module->$warningDelayPath) && !empty($conf->$module->$warningDelayPath->warning_delay)) {
516 return (
int) $conf->$module->$warningDelayPath->warning_delay;
531 if ($timestamp ===
'') {
532 dol_syslog(
'Using empty string for a timestamp is deprecated, prefer use of null when calling page ' . $_SERVER[
"PHP_SELF"] .
getCallerInfoString(), LOG_DEBUG);
535 if (is_null($timestamp) || !is_numeric($timestamp)) {
555 require_once DOL_DOCUMENT_ROOT .
"/core/db/" . $type .
'.class.php';
557 $class =
'DoliDB' . ucfirst($type);
558 $db =
new $class($type, $host, $user, $pass, $name, $port);
579function getEntity($element, $shared = 1, $currentobject =
null)
581 global $conf, $mc, $hookmanager,
$object, $action, $db;
583 if (!is_object($hookmanager)) {
584 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
591 $element =
'project';
594 $element =
'contract';
596 case 'order_supplier':
597 $element =
'supplier_order';
599 case 'invoice_supplier':
600 $element =
'supplier_invoice';
604 if (is_object($mc)) {
605 $out = $mc->getEntity($element, $shared, $currentobject);
608 $addzero = array(
'user',
'usergroup',
'cronjob',
'c_email_templates',
'email_template',
'default_values',
'overwrite_trans');
610 $addzero[] =
'c_holiday_types';
612 if (in_array($element, $addzero)) {
615 $out .= ((int) $conf->entity);
620 'element' => $element,
623 'currentobject' => $currentobject,
627 $reshook = $hookmanager->executeHooks(
'hookGetEntity', $parameters, $currentobject, $action);
629 if (is_numeric($reshook)) {
630 if ($reshook == 0 && !empty($hookmanager->resPrint)) {
631 $out .=
',' . $hookmanager->resPrint;
632 } elseif ($reshook == 1) {
633 $out = $hookmanager->resPrint;
650 if (is_object($mc) && method_exists($mc,
'setEntity')) {
651 return $mc->setEntity($currentobject);
653 return ((is_object($currentobject) && $currentobject->id > 0 && ((
int) $currentobject->entity) > 0) ? (
int) $currentobject->entity : $conf->entity);
665 return preg_match(
'/(_pass|password|_pw|_key|securekey|serverkey|secret\d?|p12key|exportkey|_PW_[a-z]+|token)$/i', $keyname);
678 for ($r =
""; $n >= 0; $n = intval($n / 26) - 1) {
679 $r = chr($n % 26 + 0x41) . $r;
703 include_once DOL_DOCUMENT_ROOT .
'/includes/mobiledetect/mobiledetectlib/Mobile_Detect.php';
710 $user_agent = substr($user_agent, 0, 512);
713 $detectmobile =
new Mobile_Detect(
null, $user_agent);
714 $tablet = $detectmobile->isTablet();
716 if ($detectmobile->isMobile()) {
720 if ($detectmobile->is(
'AndroidOS')) {
721 $os = $phone =
'android';
722 } elseif ($detectmobile->is(
'BlackBerryOS')) {
723 $os = $phone =
'blackberry';
724 } elseif ($detectmobile->is(
'iOS')) {
727 } elseif ($detectmobile->is(
'PalmOS')) {
728 $os = $phone =
'palm';
729 } elseif ($detectmobile->is(
'SymbianOS')) {
731 } elseif ($detectmobile->is(
'webOS')) {
733 } elseif ($detectmobile->is(
'MaemoOS')) {
735 } elseif ($detectmobile->is(
'WindowsMobileOS') || $detectmobile->is(
'WindowsPhoneOS')) {
741 if (preg_match(
'/linux/i', $user_agent)) {
743 } elseif (preg_match(
'/macintosh/i', $user_agent)) {
745 } elseif (preg_match(
'/windows/i', $user_agent)) {
751 if (preg_match(
'/firefox(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
753 $version = empty($reg[2]) ?
'' : $reg[2];
754 } elseif (preg_match(
'/edge(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
756 $version = empty($reg[2]) ?
'' : $reg[2];
757 } elseif (preg_match(
'/chrome(\/|\s)([\d\.]+)/i', $user_agent, $reg)) {
759 $version = empty($reg[2]) ?
'' : $reg[2];
760 } elseif (preg_match(
'/chrome/i', $user_agent, $reg)) {
763 } elseif (preg_match(
'/iceweasel/i', $user_agent)) {
765 } elseif (preg_match(
'/epiphany/i', $user_agent)) {
767 } elseif (preg_match(
'/safari(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
769 $version = empty($reg[2]) ?
'' : $reg[2];
770 } elseif (preg_match(
'/opera(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
773 $version = empty($reg[2]) ?
'' : $reg[2];
774 } elseif (preg_match(
'/(MSIE\s([0-9]+\.[0-9]))|.*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) {
776 $version = end($reg);
777 } elseif (preg_match(
'/(Windows NT\s([0-9]+\.[0-9])).*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) {
780 $version = end($reg);
781 } elseif (preg_match(
'/l[iy]n(x|ks)(\(|\/|\s)*([\d\.]+)/i', $user_agent, $reg)) {
783 $name =
'textbrowser';
784 $version = empty($reg[3]) ?
'' : $reg[3];
785 } elseif (preg_match(
'/w3m\/([\d\.]+)/i', $user_agent, $reg)) {
787 $name =
'textbrowser';
788 $version = empty($reg[1]) ?
'' : $reg[1];
800 'browsername' => $name,
801 'browserversion' => $version,
803 'browserua' => $user_agent,
818 $disconnectdone =
false;
820 if (is_object($db) && !empty($db->connected)) {
821 $depth = $db->transaction_opened;
822 $disconnectdone = $db->close();
824 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));
836function GETPOSTISSET($paramname)
840 $relativepathstring = $_SERVER[
"PHP_SELF"];
842 if (constant(
'DOL_URL_ROOT')) {
843 $relativepathstring = preg_replace(
'/^' . preg_quote(constant(
'DOL_URL_ROOT'),
'/') .
'/',
'', $relativepathstring);
845 $relativepathstring = ltrim($relativepathstring,
'/');
846 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
850 if (!empty($_GET[
'restore_lastsearch_values'])) {
851 if (!empty($_SESSION[
'lastsearch_values_' . $relativepathstring])) {
852 $tmp = json_decode($_SESSION[
'lastsearch_values_' . $relativepathstring],
true);
853 if (is_array($tmp)) {
854 foreach ($tmp as $key => $val) {
855 if ($key == $paramname) {
863 if ($paramname ==
'contextpage' && !empty($_SESSION[
'lastsearch_contextpage_' . $relativepathstring])) {
865 } elseif ($paramname ==
'limit' && !empty($_SESSION[
'lastsearch_limit_' . $relativepathstring])) {
867 } elseif ($paramname ==
'page' && !empty($_SESSION[
'lastsearch_page_' . $relativepathstring])) {
869 } elseif ($paramname ==
'mode' && !empty($_SESSION[
'lastsearch_mode_' . $relativepathstring])) {
873 $isset = (isset($_POST[$paramname]) || isset($_GET[$paramname]));
890 if (empty($method)) {
891 $val = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] :
'');
892 } elseif ($method == 1) {
893 $val = isset($_GET[$paramname]) ? $_GET[$paramname] :
'';
894 } elseif ($method == 2) {
895 $val = isset($_POST[$paramname]) ? $_POST[$paramname] :
'';
896 } elseif ($method == 3) {
897 $val = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] :
'');
899 $val =
'BadFirstParameterForGETPOST';
902 return is_array($val);
917 return (
int)
GETPOST($paramname,
'int', $method,
null,
null, 0);
933function GETPOSTFLOAT($paramname, $rounding =
'', $option = 2)
954function GETPOSTDATE($prefix, $hourTime =
'', $gm =
'auto', $saverestore =
'')
957 if ($hourTime ===
'getpost' || $hourTime ===
'getpostend') {
958 $hour = (GETPOSTISSET($prefix .
'hour') &&
GETPOSTINT($prefix .
'hour') >= 0) ?
GETPOSTINT($prefix .
'hour') : ($hourTime ===
'getpostend' ? 23 : 0);
959 $minute = (GETPOSTISSET($prefix .
'min') &&
GETPOSTINT($prefix .
'min') >= 0) ?
GETPOSTINT($prefix .
'min') : ($hourTime ===
'getpostend' ? 59 : 0);
960 $second = (GETPOSTISSET($prefix .
'sec') &&
GETPOSTINT($prefix .
'sec') >= 0) ?
GETPOSTINT($prefix .
'sec') : ($hourTime ===
'getpostend' ? 59 : 0);
961 } elseif (preg_match(
'/^(\d\d):(\d\d):(\d\d)$/', $hourTime, $m)) {
962 $hour = intval($m[1]);
963 $minute = intval($m[2]);
964 $second = intval($m[3]);
965 } elseif ($hourTime ===
'end') {
970 $hour = $minute = $second = 0;
975 && !GETPOSTISSET($prefix .
'day')
976 && !GETPOSTISSET($prefix .
'month')
977 && !GETPOSTISSET($prefix .
'year')
978 && isset($_SESSION[
'DOLDATE_' . $saverestore .
'_day'])
979 && isset($_SESSION[
'DOLDATE_' . $saverestore .
'_month'])
980 && isset($_SESSION[
'DOLDATE_' . $saverestore .
'_year'])
982 $day = $_SESSION[
'DOLDATE_' . $saverestore .
'_day'];
983 $month = $_SESSION[
'DOLDATE_' . $saverestore .
'_month'];
984 $year = $_SESSION[
'DOLDATE_' . $saverestore .
'_year'];
992 $hour = (int) min($hour, 23);
993 $minute = (int) min($minute, 59);
994 $second = (int) min($second, 59);
997 $_SESSION[
'DOLDATE_' . $saverestore .
'_day'] = $day;
998 $_SESSION[
'DOLDATE_' . $saverestore .
'_month'] = $month;
999 $_SESSION[
'DOLDATE_' . $saverestore .
'_year'] = $year;
1003 return dol_mktime($hour, $minute, $second, $month, $day, $year, $gm);
1046function GETPOST($paramname, $check =
'alphanohtml', $method = 0, $filter =
null, $options =
null, $noreplace = 0)
1048 global
$mysoc, $user, $conf;
1050 if (empty($paramname)) {
1051 return 'BadFirstParameterForGETPOST';
1053 if (empty($check)) {
1054 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);
1059 if (empty($method)) {
1060 $out = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] :
'');
1061 } elseif ($method == 1) {
1062 $out = isset($_GET[$paramname]) ? $_GET[$paramname] :
'';
1063 } elseif ($method == 2) {
1064 $out = isset($_POST[$paramname]) ? $_POST[$paramname] :
'';
1065 } elseif ($method == 3) {
1066 $out = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] :
'');
1068 return 'BadThirdParameterForGETPOST';
1071 $relativepathstring =
'';
1073 if (empty($method) || $method == 3 || $method == 4) {
1074 $relativepathstring = (empty($_SERVER[
"PHP_SELF"]) ?
'' : $_SERVER[
"PHP_SELF"]);
1076 if (constant(
'DOL_URL_ROOT')) {
1077 $relativepathstring = preg_replace(
'/^' . preg_quote(constant(
'DOL_URL_ROOT'),
'/') .
'/',
'', $relativepathstring);
1079 $relativepathstring = ltrim($relativepathstring,
'/');
1080 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
1084 if (!empty($_GET[
'restore_lastsearch_values'])) {
1085 if (!empty($_SESSION[
'lastsearch_values_' . $relativepathstring])) {
1086 $tmp = json_decode($_SESSION[
'lastsearch_values_' . $relativepathstring],
true);
1087 if (is_array($tmp)) {
1088 foreach ($tmp as $key => $val) {
1089 if ($key == $paramname) {
1097 if ($paramname ==
'contextpage' && !empty($_SESSION[
'lastsearch_contextpage_' . $relativepathstring])) {
1098 $out = $_SESSION[
'lastsearch_contextpage_' . $relativepathstring];
1099 } elseif ($paramname ==
'limit' && !empty($_SESSION[
'lastsearch_limit_' . $relativepathstring])) {
1100 $out = $_SESSION[
'lastsearch_limit_' . $relativepathstring];
1101 } elseif ($paramname ==
'page' && !empty($_SESSION[
'lastsearch_page_' . $relativepathstring])) {
1102 $out = $_SESSION[
'lastsearch_page_' . $relativepathstring];
1103 } elseif ($paramname ==
'mode' && !empty($_SESSION[
'lastsearch_mode_' . $relativepathstring])) {
1104 $out = $_SESSION[
'lastsearch_mode_' . $relativepathstring];
1106 } elseif (!isset($_GET[
'sortfield'])) {
1109 if (!empty($_GET[
'action']) && $_GET[
'action'] ==
'create' && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
1112 '@phan-var-force CommonObject $object';
1113 if (is_object(
$object) && isset(
$object->fields[$paramname][
'default'])) {
1115 $out =
$object->fields[$paramname][
'default'];
1119 if (!empty($_GET[
'action']) && (preg_match(
'/^create/', $_GET[
'action']) || preg_match(
'/^presend/', $_GET[
'action'])) && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
1121 if (!empty($user->default_values)) {
1122 if (isset($user->default_values[$relativepathstring][
'createform'])) {
1123 foreach ($user->default_values[$relativepathstring][
'createform'] as $defkey => $defval) {
1125 if ($defkey !=
'_noquery_') {
1126 $tmpqueryarraytohave = explode(
'&', $defkey);
1129 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
1130 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
1142 if (isset($user->default_values[$relativepathstring][
'createform'][$defkey][$paramname])) {
1143 $out = $user->default_values[$relativepathstring][
'createform'][$defkey][$paramname];
1150 } elseif (!empty($paramname) && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
1152 if (!empty($user->default_values)) {
1155 if ($paramname ==
'sortfield' || $paramname ==
'sortorder') {
1157 if (isset($user->default_values[$relativepathstring][
'sortorder'])) {
1159 foreach ($user->default_values[$relativepathstring][
'sortorder'] as $defkey => $defval) {
1161 if ($defkey !=
'_noquery_') {
1162 $tmpqueryarraytohave = explode(
'&', $defkey);
1165 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
1166 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
1178 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
1179 foreach ($user->default_values[$relativepathstring][
'sortorder'][$defkey] as $key => $val) {
1183 if ($paramname ==
'sortfield') {
1186 if ($paramname ==
'sortorder') {
1194 } elseif (isset($user->default_values[$relativepathstring][
'filters'])) {
1195 foreach ($user->default_values[$relativepathstring][
'filters'] as $defkey => $defval) {
1196 if (!empty($_GET[
'disabledefaultvalues'])) {
1200 if ($defkey !=
'_noquery_') {
1201 $tmpqueryarraytohave = explode(
'&', $defkey);
1204 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
1205 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
1216 if ($qualified && isset($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname])) {
1218 if (isset($_POST[
'search_all']) || isset($_GET[
'search_all'])) {
1221 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
1222 $out =
dol_string_nospecial($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname],
'', $forbidden_chars_to_replace);
1225 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
1226 $out =
dol_string_nospecial($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname],
'', $forbidden_chars_to_replace);
1241 '@phan-var-force string $paramname';
1242 if (!is_array($out) && empty($_POST[$paramname]) && empty($noreplace)) {
1244 $regreplace = array();
1248 while (preg_match(
'/__([A-Z0-9]+(?:_[A-Z0-9]+){0,3})__/i', $out, $reg) && ($loopnb < $maxloop)) {
1252 if ($reg[1] ==
'DAY') {
1254 $newout = $tmp[
'mday'];
1255 } elseif ($reg[1] ==
'MONTH') {
1257 $newout = $tmp[
'mon'];
1258 } elseif ($reg[1] ==
'YEAR') {
1260 $newout = $tmp[
'year'];
1261 } elseif ($reg[1] ==
'PREVIOUS_DAY') {
1264 $newout = $tmp2[
'day'];
1265 } elseif ($reg[1] ==
'PREVIOUS_MONTH') {
1268 $newout = $tmp2[
'month'];
1269 } elseif ($reg[1] ==
'PREVIOUS_YEAR') {
1271 $newout = ($tmp[
'year'] - 1);
1272 } elseif ($reg[1] ==
'NEXT_DAY') {
1275 $newout = $tmp2[
'day'];
1276 } elseif ($reg[1] ==
'NEXT_MONTH') {
1279 $newout = $tmp2[
'month'];
1280 } elseif ($reg[1] ==
'NEXT_YEAR') {
1282 $newout = ($tmp[
'year'] + 1);
1283 } elseif ($reg[1] ==
'MYCOMPANY_COUNTRY_ID' || $reg[1] ==
'MYCOUNTRY_ID' || $reg[1] ==
'MYCOUNTRYID') {
1284 $newout =
$mysoc->country_id;
1285 } elseif ($reg[1] ==
'USER_ID' || $reg[1] ==
'USERID') {
1286 $newout = $user->id;
1287 } elseif ($reg[1] ==
'USER_SUPERVISOR_ID' || $reg[1] ==
'SUPERVISOR_ID' || $reg[1] ==
'SUPERVISORID') {
1288 $newout = $user->fk_user;
1289 } elseif ($reg[1] ==
'ENTITY_ID' || $reg[1] ==
'ENTITYID') {
1290 $newout = $conf->entity;
1291 } elseif ($reg[1] ==
'ID') {
1294 $newout =
'REGREPLACE_' . $loopnb;
1295 $regreplace[$loopnb] = $reg[0];
1298 $out = preg_replace(
'/__' . preg_quote($reg[1],
'/') .
'__/', $newout, $out);
1300 if (!empty($regreplace)) {
1301 foreach ($regreplace as $key => $value) {
1302 $out = preg_replace(
'/REGREPLACE_' . $key .
'/', $value, $out);
1308 if (preg_match(
'/^array/', $check)) {
1309 $tmpcheck =
'alphanohtml';
1312 } elseif (!is_array($out)) {
1313 $out = explode(
',', $out);
1315 $tmparray = explode(
':', $check);
1316 if (!empty($tmparray[1])) {
1317 $tmpcheck = $tmparray[1];
1320 foreach ($out as $outkey => $outval) {
1321 $out[$outkey] =
sanitizeVal($outval, $tmpcheck, $filter, $options);
1326 if (strpos($paramname,
'search_') === 0) {
1327 $out = preg_replace(
'/([<>])([-+]?\d)/',
'\1 \2', $out);
1331 $out =
sanitizeVal($out, $check, $filter, $options);
1338 if (preg_match(
'/^backto/i', $paramname)) {
1339 $out = str_replace(
'\\',
'/', $out);
1340 $out = str_replace(array(
':',
';',
'@',
"\t",
' '),
'', $out);
1342 $oldstringtoclean = $out;
1343 $out = str_ireplace(array(
'javascript',
'vbscript',
'&colon',
'&#'),
'', $out);
1344 $out = preg_replace(array(
'/^[^\?]*%/'),
'', $out);
1345 $out = preg_replace(array(
'/^[a-z]*\/\s*\/+/i'),
'', $out);
1346 }
while ($oldstringtoclean != $out);
1351 if (empty($method) || $method == 3 || $method == 4) {
1352 if (preg_match(
'/^search_/', $paramname) || in_array($paramname, array(
'sortorder',
'sortfield'))) {
1359 if ($out !=
'' && isset($user)) {
1360 $user->lastsearch_values_tmp[$relativepathstring][$paramname] = $out;
1365 if ($paramname ==
'hashp' && $out ==
'shared') {
1381function sanitizeVal($out =
'', $check =
'alphanohtml', $filter =
null, $options =
null)
1385 if ($out ===
null) {
1393 if (!is_numeric($out)) {
1398 if (is_array($out)) {
1399 $out = implode(
',', $out);
1401 if (preg_match(
'/[^0-9,-]+/i', $out)) {
1406 dol_syslog(
"Use of parameter value 'san_alpha' in GETPOST is deprecated. Use 'alphanohtml', 'aZ09comma', ...", LOG_WARNING);
1407 $out = filter_var($out, FILTER_SANITIZE_STRING);
1410 $out = filter_var($out, FILTER_SANITIZE_EMAIL);
1414 $out = preg_replace(
'/[^:\/\[\]a-z0-9@\$\'\*\~\.\-_,;\?\!=%&+#]+/i',
'', $out);
1418 if (!is_array($out)) {
1420 if (preg_match(
'/[^a-z]+/i', $out)) {
1426 if (!is_array($out)) {
1428 if (preg_match(
'/[^a-z0-9_\-\.]+/i', $out)) {
1434 if (!is_array($out)) {
1436 if (preg_match(
'/[^a-z0-9_\-\.@]+/i', $out)) {
1442 if (!is_array($out)) {
1444 if (preg_match(
'/[^a-z0-9_\-\.,]+/i', $out)) {
1451 if (!is_array($out)) {
1454 $oldstringtoclean = $out;
1458 $out = preg_replace(
'/\\\([0-9xu])/',
'/\1', $out);
1465 $out = str_ireplace(array(
'../',
'..\\',
'&',
'&',
'&',
'"',
'"',
'"',
'"',
'"',
'/',
'/',
'/',
'\',
'\',
'\'),
'', $out);
1466 }
while ($oldstringtoclean != $out);
1470 case 'alphawithlgt':
1471 if (!is_array($out)) {
1474 $oldstringtoclean = $out;
1478 $out = preg_replace(
'/\\\([0-9xu])/',
'/\1', $out);
1485 $out = str_ireplace(array(
'../',
'..\\',
'&',
'&',
'&',
'"',
'"',
'"',
'"',
'"',
'/',
'/',
'/',
'\',
'\',
'\'),
'', $out);
1486 }
while ($oldstringtoclean != $out);
1492 case 'restricthtmlnolink':
1493 case 'restricthtml':
1494 case 'restricthtmlallowclass':
1495 case 'restricthtmlallowiframe':
1496 case 'restricthtmlallowlinkscript':
1497 case 'restricthtmlallowunvalid':
1502 if (empty($filter)) {
1503 return 'BadParameterForGETPOST - Param 3 of sanitizeVal()';
1505 if (is_null($options)) {
1508 $out = filter_var($out, $filter, $options);
1512 dol_syslog(
"Error, you call sanitizeVal() with a bad value for the check type. Data will be sanitized with alphanohtml.", LOG_ERR);
1513 $out =
GETPOST($out,
'alphanohtml');
1528function dolSetCookie(
string $cookiename,
string $cookievalue,
int $expire = -1)
1530 global $dolibarr_main_force_https;
1532 if ($expire == -1) {
1533 $expire = (time() + (86400 * 354));
1536 if (PHP_VERSION_ID < 70300) {
1537 setcookie($cookiename, empty($cookievalue) ?
'' : $cookievalue, empty($cookievalue) ? 0 : $expire,
'/',
'', !(empty($dolibarr_main_force_https) &&
isHTTPS() === false), true);
1540 $cookieparams = array(
1541 'expires' => empty($cookievalue) ? 0 : $expire,
1544 'secure' => !(empty($dolibarr_main_force_https) &&
isHTTPS() === false),
1548 setcookie($cookiename, empty($cookievalue) ?
'' : $cookievalue, $cookieparams);
1550 if (empty($cookievalue)) {
1551 unset($_COOKIE[$cookiename]);
1555if (!function_exists(
'dol_getprefix')) {
1566 function dol_getprefix($mode =
'')
1569 if ($mode ==
'email') {
1575 } elseif (isset($_SERVER[
"SERVER_NAME"])) {
1576 return $_SERVER[
"SERVER_NAME"];
1581 if (!empty($conf->file->instance_unique_id)) {
1582 return sha1(
'dolibarr' . $conf->file->instance_unique_id);
1586 return sha1(DOL_DOCUMENT_ROOT . DOL_URL_ROOT);
1590 global $dolibarr_main_instance_unique_id, $dolibarr_main_cookie_cryptkey;
1591 $tmp_instance_unique_id = empty($dolibarr_main_instance_unique_id) ? (empty($dolibarr_main_cookie_cryptkey) ?
'' : $dolibarr_main_cookie_cryptkey) : $dolibarr_main_instance_unique_id;
1594 if (!empty($tmp_instance_unique_id)) {
1595 return sha1(
'dolibarr' . $tmp_instance_unique_id);
1599 if (isset($_SERVER[
"SERVER_NAME"]) && isset($_SERVER[
"DOCUMENT_ROOT"])) {
1600 return sha1($_SERVER[
"SERVER_NAME"] . $_SERVER[
"DOCUMENT_ROOT"] . DOL_DOCUMENT_ROOT . DOL_URL_ROOT);
1602 return sha1(DOL_DOCUMENT_ROOT . DOL_URL_ROOT);
1619 global $conf, $langs, $user,
$mysoc;
1621 if (strpos($relpath,
'..') !==
false) {
1623 dol_syslog(
'functions::dol_include_once Tried to load a file with a path including a forbidden sequence ".." : ' . $relpath, LOG_WARNING);
1626 if (!preg_match(
'/\.php$/', $relpath)) {
1628 dol_syslog(
'functions::dol_include_once Tried to load a file that is not a PHP file : ' . $relpath, LOG_WARNING);
1634 if (!file_exists($fullpath)) {
1635 dol_syslog(
'functions::dol_include_once Tried to load unexisting file: ' . $relpath, LOG_WARNING);
1638 if (!empty($classname) && !class_exists($classname)) {
1639 return include $fullpath;
1641 return include_once $fullpath;
1659function dol_buildpath($path, $type = 0, $returnemptyifnotfound = 0)
1663 $path = preg_replace(
'/^\//',
'', $path);
1666 $res = DOL_DOCUMENT_ROOT .
'/' . $path;
1667 if (is_array($conf->file->dol_document_root)) {
1668 foreach ($conf->file->dol_document_root as $key => $dirroot) {
1669 if ($key ==
'main') {
1673 if (@file_exists($dirroot .
'/' . $path)) {
1674 if ($key !=
'main' && preg_match(
'/^core\//', $path)) {
1677 $res = $dirroot .
'/' . $path;
1682 if ($returnemptyifnotfound) {
1684 if ($returnemptyifnotfound == 1 || !file_exists($res)) {
1696 $res = DOL_URL_ROOT .
'/' . $path;
1699 $res = DOL_MAIN_URL_ROOT .
'/' . $path;
1702 $res = DOL_URL_ROOT .
'/' . $path;
1705 foreach ($conf->file->dol_document_root as $key => $dirroot) {
1706 if ($key ==
'main') {
1711 $urlwithouturlroot = preg_replace(
'/' . preg_quote(DOL_URL_ROOT,
'/') .
'$/i',
'', trim($conf->file->dol_main_url_root));
1712 $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT;
1715 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : $urlwithroot) .
'/' . $path;
1720 preg_match(
'/^([^\?]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i', $path, $regs);
1721 if (!empty($regs[1])) {
1724 if (@file_exists($dirroot .
'/' . $regs[1])) {
1726 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : DOL_URL_ROOT) . $conf->file->dol_url_root[$key] .
'/' . $path;
1727 } elseif ($type == 2) {
1728 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : DOL_MAIN_URL_ROOT) . $conf->file->dol_url_root[$key] .
'/' . $path;
1729 } elseif ($type == 3) {
1733 $urlwithouturlroot = preg_replace(
'/' . preg_quote(DOL_URL_ROOT,
'/') .
'$/i',
'', trim($conf->file->dol_main_url_root));
1734 $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT;
1737 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : $urlwithroot) . $conf->file->dol_url_root[$key] .
'/' . $path;
1756function dolBuildUrl($url, $params = [], $addtoken =
false)
1758 global $db, $hookmanager;
1760 if (!is_object($hookmanager)) {
1761 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
1764 if ((!isset($params[
'mainmenu']) || empty($params[
'mainmenu'])) && GETPOSTISSET(
'mainmenu')) {
1765 $params = array_merge($params, [
'mainmenu' => (
GETPOST(
'mainmenu',
'restricthtml'))]);
1767 if ((!isset($params[
'leftmenu'])) && GETPOSTISSET(
'leftmenu')) {
1768 $params = array_merge($params, [
'leftmenu' => (
GETPOST(
'leftmenu',
'restricthtml'))]);
1772 'params' => &$params,
1773 'addtoken' => &$addtoken,
1775 $hookmanager->executeHooks(
'buildurl', $parameters);
1777 $params = array_merge($params, [
'token' =>
newToken()]);
1781 $params = array_merge($params, [
'debug' =>
'debug']);
1784 $url .=
'?' . http_build_query($params);
1803 if (empty($properties)) {
1804 return get_object_vars($obj);
1807 $existingProperties = [];
1808 $realProperties = get_object_vars($obj);
1811 foreach ($properties as $property) {
1812 if (array_key_exists($property, $realProperties)) {
1814 $existingProperties[$property] = $obj->{$property};
1815 } elseif (property_exists($obj, $property)) {
1817 $existingProperties[$property] = $obj->{$property};
1821 return $existingProperties;
1840function dol_clone($srcobject, $native = 2)
1844 dol_syslog(
"Warning, call to dol_clone() with the deprecated parameter native=0, use 2 instead", LOG_WARNING);
1847 if (isset($srcobject->db) && isset($srcobject->db->db) && is_object($srcobject->db->db) && get_class($srcobject->db->db) ==
'PgSql\Connection') {
1848 $tmpsavdb = $srcobject->db;
1849 unset($srcobject->db);
1852 $myclone = unserialize(serialize($srcobject));
1854 if (!empty($tmpsavdb)) {
1855 $srcobject->db = $tmpsavdb;
1857 } elseif ($native == 2) {
1860 $tmparray = get_object_vars($srcobject);
1862 if (is_array($tmparray)) {
1863 foreach ($tmparray as $propertykey => $propertyval) {
1864 if (is_scalar($propertyval) || is_array($propertyval)) {
1865 $myclone->$propertykey = $propertyval;
1870 $myclone = clone $srcobject;
1887 if (is_object($srcobject)) {
1888 $srcobject = get_object_vars($srcobject);
1891 if (is_array($srcobject)) {
1893 foreach ($srcobject as $key => $value) {
1894 if (in_array($key, array(
'db',
'fields',
'error',
'errorhidden',
'errors',
'oldcopy',
'linkedObjects',
'linked_objects'))) {
1915function dol_size($size, $type =
'')
1918 if (empty($conf->dol_optimize_smallscreen)) {
1921 if ($type ==
'width' && $size > 250) {
1942function dol_sanitizeFileName($str, $newstr =
'_', $unaccent = 1, $includequotes = 0, $allowdash = 0)
1948 $filesystem_forbidden_chars = array(
'<',
'>',
'/',
'\\',
'?',
'*',
'|',
'"',
':',
'°',
'$',
';',
'`');
1949 if ($includequotes) {
1950 $filesystem_forbidden_chars[] =
"'";
1953 $tmp = preg_replace(
'/\-\-+/',
'_', $tmp);
1954 if (empty($allowdash)) {
1955 $tmp = preg_replace(
'/\s+\-([^\s])/',
' _$1', $tmp);
1956 $tmp = preg_replace(
'/\s+\-$/',
'', $tmp);
1958 $tmp = str_replace(
'..',
'', $tmp);
1959 $tmp = str_replace(
'~', $newstr, $tmp);
1960 $tmp = preg_replace(
'/\s{2,}/',
' ', $tmp);
1987 $filesystem_forbidden_chars = array(
'<',
'>',
'?',
'*',
'|',
'"',
'°',
'$',
';',
'`');
1994 $tmp = preg_replace(
'/\-\-+/', $newstr, $tmp);
1995 if (empty($allowdash)) {
1996 $tmp = preg_replace(
'/\s+\-([^\s])/',
' '.$newstr.
'$1', $tmp);
1997 $tmp = preg_replace(
'/\s+\-$/',
'', $tmp);
1999 $tmp = str_replace(
'..', $newstr, $tmp);
2000 $tmp = str_replace(
'~', $newstr, $tmp);
2001 $tmp = preg_replace(
'/\s{2,}/',
' ', $tmp);
2017 $stringtoclean = preg_replace(
'/[\x00-\x1F\x7F]/u',
'', $stringtoclean);
2019 $stringtoclean = preg_replace(
'/<!--[^>]*-->/',
'', $stringtoclean);
2021 $stringtoclean = str_replace(
'\\',
'/', $stringtoclean);
2025 $stringtoclean = str_replace(array(
':',
';',
'@'),
'', $stringtoclean);
2029 $oldstringtoclean = $stringtoclean;
2032 $stringtoclean = str_ireplace(array(
'javascript',
'vbscript',
'&colon',
'&#'),
'', $stringtoclean);
2033 }
while ($oldstringtoclean != $stringtoclean);
2037 $stringtoclean = preg_replace(array(
'/^[a-z]*\/\/+/i'),
'', $stringtoclean);
2040 return $stringtoclean;
2052 $oldstringtoclean = $stringtoclean;
2053 $stringtoclean = str_ireplace(array(
'"',
':',
'[',
']',
"\n",
"\r",
'\\',
'\/'),
'', $stringtoclean);
2054 }
while ($oldstringtoclean != $stringtoclean);
2056 return $stringtoclean;
2069 return preg_replace(
'/[^\w]+/',
'', $str);
2083 if (is_null($str)) {
2088 if (extension_loaded(
'intl') &&
getDolGlobalString(
'MAIN_UNACCENT_USE_TRANSLITERATOR')) {
2089 $transliterator = Transliterator::createFromRules(
':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: NFC;', Transliterator::FORWARD);
2090 return $transliterator->transliterate($str);
2093 $string = rawurlencode($str);
2094 $replacements = array(
2095 '%C3%80' =>
'A',
'%C3%81' =>
'A',
'%C3%82' =>
'A',
'%C3%83' =>
'A',
'%C3%84' =>
'A',
'%C3%85' =>
'A',
2097 '%C3%88' =>
'E',
'%C3%89' =>
'E',
'%C3%8A' =>
'E',
'%C3%8B' =>
'E',
2098 '%C3%8C' =>
'I',
'%C3%8D' =>
'I',
'%C3%8E' =>
'I',
'%C3%8F' =>
'I',
2100 '%C3%92' =>
'O',
'%C3%93' =>
'O',
'%C3%94' =>
'O',
'%C3%95' =>
'O',
'%C3%96' =>
'O',
'%C5%90' =>
'O',
2102 '%C3%99' =>
'U',
'%C3%9A' =>
'U',
'%C3%9B' =>
'U',
'%C3%9C' =>
'U',
'%C5%B0' =>
'U',
2103 '%C3%9D' =>
'Y',
'%C5%B8' =>
'y',
2104 '%C3%A0' =>
'a',
'%C3%A1' =>
'a',
'%C3%A2' =>
'a',
'%C3%A3' =>
'a',
'%C3%A4' =>
'a',
'%C3%A5' =>
'a',
2106 '%C3%A8' =>
'e',
'%C3%A9' =>
'e',
'%C3%AA' =>
'e',
'%C3%AB' =>
'e',
2107 '%C3%AC' =>
'i',
'%C3%AD' =>
'i',
'%C3%AE' =>
'i',
'%C3%AF' =>
'i',
2109 '%C3%B2' =>
'o',
'%C3%B3' =>
'o',
'%C3%B4' =>
'o',
'%C3%B5' =>
'o',
'%C3%B6' =>
'o',
'%C5%91' =>
'o',
2111 '%C3%B9' =>
'u',
'%C3%BA' =>
'u',
'%C3%BB' =>
'u',
'%C3%BC' =>
'u',
'%C5%B1' =>
'u',
2112 '%C3%BD' =>
'y',
'%C3%BF' =>
'y',
2133 $string = strtr($string, $replacements);
2134 return rawurldecode($string);
2139 "\xC0\xC1\xC2\xC3\xC4\xC5\xC7
2140 \xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1
2141 \xD2\xD3\xD4\xD5\xD8\xD9\xDA\xDB\xDD
2142 \xE0\xE1\xE2\xE3\xE4\xE5\xE7\xE8\xE9\xEA\xEB
2143 \xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF8
2144 \xF9\xFA\xFB\xFC\xFD\xFF",
2152 $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"));
2170function dol_string_nospecial($str, $newstr =
'_', $badcharstoreplace =
'', $badcharstoremove =
'', $keepspaces = 0)
2172 $forbidden_chars_to_replace = array(
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
",",
";",
"=",
'°',
'$',
';');
2173 if (empty($keepspaces)) {
2174 $forbidden_chars_to_replace[] =
" ";
2176 $forbidden_chars_to_remove = array();
2179 if (is_array($badcharstoreplace)) {
2180 $forbidden_chars_to_replace = $badcharstoreplace;
2182 if (is_array($badcharstoremove)) {
2183 $forbidden_chars_to_remove = $badcharstoremove;
2187 return str_replace($forbidden_chars_to_replace, $newstr, str_replace($forbidden_chars_to_remove,
"", $str));
2206 if ($removetabcrlf) {
2207 return preg_replace(
'/[\x00-\x1F\x7F]/u',
'', $str);
2209 return preg_replace(
'/[\x00-\x08\x11-\x12\x14-\x1F\x7F]/u',
'', $str);
2224 if (function_exists(
'iconv')) {
2225 $slug = iconv(
'UTF-8',
'ASCII//TRANSLIT//IGNORE', $slug);
2229 $slug = strtolower($slug);
2232 $slug = preg_replace(
'/[^a-z0-9]+/',
'-', $slug);
2235 $slug = trim($slug,
'-');
2248function dol_escape_js($stringtoescape, $mode = 0, $noescapebackslashn = 0)
2250 if (is_null($stringtoescape)) {
2255 $substitjs = array(
"'" =>
"\\'",
"\r" =>
'\\r');
2257 if (empty($noescapebackslashn)) {
2258 $substitjs[
"\n"] =
'\\n';
2259 $substitjs[
'\\'] =
'\\\\';
2262 $substitjs[
"'"] =
"\\'";
2263 $substitjs[
'"'] =
"\\'";
2264 } elseif ($mode == 1) {
2265 $substitjs[
"'"] =
"\\'";
2266 } elseif ($mode == 2) {
2267 $substitjs[
'"'] =
'\\"';
2268 } elseif ($mode == 3) {
2269 $substitjs[
"'"] =
"\\'";
2270 $substitjs[
'"'] =
"\\\"";
2272 return strtr((
string) $stringtoescape, $substitjs);
2286 return rawurlencode($stringtoescape);
2297 return str_replace(
'"',
'\"', $stringtoescape);
2309 if (is_null($stringtoescape)) {
2313 if ($stringforquotes == 2) {
2314 return str_replace(
'"',
"'", $stringtoescape);
2315 } elseif ($stringforquotes == 1) {
2321 $stringtoescape = str_replace(
'\\',
'', $stringtoescape);
2322 return str_replace(
"'",
"\'", str_replace(
'"',
"'", $stringtoescape));
2325 return 'Bad parameter for stringforquotes in dol_escape_php';
2336 return preg_replace(
'/[^a-z0-9_]/i',
'', $stringtoescape);
2347 return $stringtoescape;
2411 $allowedtags = array(
'br',
'b',
'font',
'hr',
'span');
2412 if (!empty($allowothertags) && is_array($allowothertags)) {
2413 $allowedtags = array_merge($allowedtags, $allowothertags);
2417 if ($escapeonlyhtmltags) {
2418 return dol_escape_htmltag(
dol_string_onlythesehtmltags($s, 1, 0, 0, 0, $allowedtags), 1, -1,
'', 1, 1);
2420 return dol_escape_htmltag(
dol_string_onlythesehtmltags(
dol_htmlentitiesbr($s), 1, 0, 0, 0, $allowedtags), 1, -1,
'', 0, 1);
2436 $escapeonlyhtmltags = 1;
2437 return dol_escape_htmltag(
dol_string_onlythesehtmltags($s, 1, 1, 1, 0, array()), 0, 0,
'', $escapeonlyhtmltags, 1);
2462 return htmlspecialchars($s, ENT_HTML5,
'UTF-8');
2482function dol_escape_htmltag($stringtoescape, $keepb = 0, $keepn = 0, $noescapetags =
'', $escapeonlyhtmltags = 0, $cleanalsojavascript = 0)
2484 if ($noescapetags ==
'common') {
2485 $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';
2487 $noescapetags .=
',header,footer,nav,section,menu,menuitem';
2489 if ($cleanalsojavascript) {
2494 if ($escapeonlyhtmltags) {
2495 $tmp = htmlspecialchars_decode((
string) $stringtoescape, ENT_COMPAT);
2502 $tmp = (string) $stringtoescape;
2505 $tmp = str_ireplace(
'<',
'__DONOTDECODELT', $tmp);
2506 $tmp = str_ireplace(
'>',
'__DONOTDECODEGT', $tmp);
2507 $tmp = str_ireplace(
'&',
'__DONOTDECODEAMP', $tmp);
2508 $tmp = str_ireplace(
'"',
'__DONOTDECODEQUOT', $tmp);
2509 $tmp = str_ireplace(
'&apos',
'__DONOTDECODEAPOS', $tmp);
2510 $tmp = str_ireplace(
''',
'__DONOTDECODE39', $tmp);
2512 $tmp = html_entity_decode((
string) $tmp, ENT_COMPAT,
'UTF-8');
2515 $tmp = str_ireplace(
'__DONOTDECODELT',
'<', $tmp);
2516 $tmp = str_ireplace(
'__DONOTDECODEGT',
'>', $tmp);
2517 $tmp = str_ireplace(
'__DONOTDECODEAMP',
'&', $tmp);
2518 $tmp = str_ireplace(
'__DONOTDECODEQUOT',
'"', $tmp);
2519 $tmp = str_ireplace(
'__DONOTDECODEAPOS',
'&apos', $tmp);
2520 $tmp = str_ireplace(
'__DONOTDECODE39',
''', $tmp);
2522 $tmp = str_ireplace(
''',
'__SIMPLEQUOTE__', $tmp);
2525 $tmp = strtr($tmp, array(
"<b>" =>
'',
'</b>' =>
'',
'<strong>' =>
'',
'</strong>' =>
''));
2528 $tmp = strtr($tmp, array(
"\r" =>
'\\r',
"\n" =>
'\\n'));
2529 } elseif ($keepn == -1) {
2530 $tmp = strtr($tmp, array(
"\r" =>
'',
"\n" =>
''));
2533 if ($escapeonlyhtmltags) {
2534 $tmp = htmlspecialchars($tmp, ENT_COMPAT,
'UTF-8');
2538 $tmparrayoftags = array();
2539 if ($noescapetags) {
2540 $tmparrayoftags = explode(
',', $noescapetags);
2543 if (count($tmparrayoftags)) {
2548 $tmp = str_ireplace(array(
'__DOUBLEQUOTE',
'__BEGINTAGTOREPLACE',
'__ENDTAGTOREPLACE',
'__BEGINENDTAGTOREPLACE'),
'', $tmp);
2550 foreach ($tmparrayoftags as $tagtoreplace) {
2552 $tmp = preg_replace(
'/<' . preg_quote($tagtoreplace,
'/') .
'>/',
'__BEGINTAGTOREPLACE' . $tagtoreplace .
'__', $tmp);
2553 $tmp = str_ireplace(
'</' . $tagtoreplace .
'>',
'__ENDTAGTOREPLACE' . $tagtoreplace .
'__', $tmp);
2554 $tmp = preg_replace(
'/<' . preg_quote($tagtoreplace,
'/') .
' \/>/',
'__BEGINENDTAGTOREPLACE' . $tagtoreplace .
'__', $tmp);
2560 if (preg_match(
'/<' . preg_quote($tagtoreplace,
'/') .
'(\s+)([^>]+)>/', $tmp, $reg)) {
2562 $tmpattributes = str_ireplace(array(
'[',
']'),
'_', $reg[2]);
2563 $tmpattributes = str_ireplace(
'"',
'__DOUBLEQUOTE__', $tmpattributes);
2564 $tmpattributes = preg_replace(
'/[^a-z0-9_%,\/\?\;\s=&\.\-@:\.#\+]/i',
'', $tmpattributes);
2566 $tmp = str_replace(
'<' . $tagtoreplace . $reg[1] . $reg[2] .
'>',
'__BEGINTAGTOREPLACE' . $tagtoreplace .
'[' . $tmpattributes .
']__', $tmp);
2569 $diff = strcmp($tmpold, $tmp);
2573 $tmp = str_ireplace(
'&',
'__ANDNOSEMICOLON__', $tmp);
2574 $tmp = str_ireplace(
'"',
'__DOUBLEQUOTENOSEMICOLON__', $tmp);
2575 $tmp = str_ireplace(
'<',
'__LESSTHAN__', $tmp);
2576 $tmp = str_ireplace(
'>',
'__GREATERTHAN__', $tmp);
2580 $result = htmlentities($tmp, ENT_COMPAT,
'UTF-8');
2584 if (count($tmparrayoftags)) {
2586 foreach ($tmparrayoftags as $tagtoreplace) {
2587 $result = str_ireplace(
'__BEGINTAGTOREPLACE' . $tagtoreplace .
'__',
'<' . $tagtoreplace .
'>', $result);
2588 $result = preg_replace(
'/__BEGINTAGTOREPLACE' . $tagtoreplace .
'\[([^\]]*)\]__/',
'<' . $tagtoreplace .
' \1>', $result);
2589 $result = str_ireplace(
'__ENDTAGTOREPLACE' . $tagtoreplace .
'__',
'</' . $tagtoreplace .
'>', $result);
2590 $result = str_ireplace(
'__BEGINENDTAGTOREPLACE' . $tagtoreplace .
'__',
'<' . $tagtoreplace .
' />', $result);
2591 $result = preg_replace(
'/__BEGINENDTAGTOREPLACE' . $tagtoreplace .
'\[([^\]]*)\]__/',
'<' . $tagtoreplace .
' \1 />', $result);
2594 $result = str_ireplace(
'__DOUBLEQUOTE__',
'"', $result);
2596 $result = str_ireplace(
'__ANDNOSEMICOLON__',
'&', $result);
2597 $result = str_ireplace(
'__DOUBLEQUOTENOSEMICOLON__',
'"', $result);
2598 $result = str_ireplace(
'__LESSTHAN__',
'<', $result);
2599 $result = str_ireplace(
'__GREATERTHAN__',
'>', $result);
2602 $result = str_ireplace(
'__SIMPLEQUOTE__',
''', $result);
2619 if (function_exists(
'mb_strtolower')) {
2620 return mb_strtolower($string, $encoding);
2622 return strtolower($string);
2636 if (function_exists(
'mb_strtoupper')) {
2637 return mb_strtoupper($string, $encoding);
2639 return strtoupper($string);
2653 if (function_exists(
'mb_substr')) {
2654 return mb_strtoupper(mb_substr($string, 0, 1, $encoding), $encoding) . mb_substr($string, 1,
null, $encoding);
2656 return ucfirst($string);
2670 if (function_exists(
'mb_convert_case')) {
2671 return mb_convert_case($string, MB_CASE_TITLE, $encoding);
2673 return ucwords($string);
2685 $backtrace = debug_backtrace();
2687 if (count($backtrace) >= 1) {
2689 if (count($backtrace) == 1) {
2692 $trace = $backtrace[$pos];
2693 if (isset($trace[
'file'], $trace[
'line'])) {
2694 $msg =
" From {$trace['file']}:{$trace['line']}.";
2722function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename =
'', $restricttologhandler =
'', $logcontext =
null)
2724 global $conf, $user, $debugbar;
2732 if (defined(
'USEEXTERNALSERVER') && !defined(
'USEDOLIBARRSERVER') && !defined(
'USEDOLIBARREDITOR')) {
2733 global $website, $websitekey;
2734 if (is_object($website) && !empty($website->ref)) {
2735 $suffixinfilename .=
'_website_' . $website->ref;
2736 } elseif (!empty($websitekey)) {
2737 $suffixinfilename .=
'_website_' . $websitekey;
2742 if (defined(
'USESUFFIXINLOG')) {
2743 $suffixinfilename .= constant(
'USESUFFIXINLOG');
2747 foreach ($conf->loghandlers as $loghandlerinstance) {
2748 $loghandlerinstance->setIdent($ident);
2752 if (!empty($message)) {
2755 $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');
2757 if (!array_key_exists($level, $logLevels)) {
2758 dol_syslog(
'Error Bad Log Level ' . $level, LOG_ERR);
2766 $message = preg_replace(
'/password=\'[^\']*\'/',
'password=\'hidden\'', $message);
2770 if ((!empty($_REQUEST[
'logtohtml']) &&
getDolGlobalString(
'MAIN_ENABLE_LOG_TO_HTML'))
2771 || (is_object($user) && $user->hasRight(
'debugbar',
'read') && is_object($debugbar))
2773 $ospid = sprintf(
"%7s",
dol_trunc((
string) getmypid(), 7,
'right',
'UTF-8', 1));
2774 $osuser =
" " . sprintf(
"%6s",
dol_trunc(function_exists(
'posix_getuid') ? posix_getuid() :
'', 6,
'right',
'UTF-8', 1));
2776 $conf->logbuffer[] =
dol_print_date(time(),
"%Y-%m-%d %H:%M:%S") .
" " . sprintf(
"%-7s", $logLevels[$level]) .
" " . $ospid .
" " . $osuser .
" " . $message;
2782 print
"\n\n<!-- Log start\n";
2784 print
"Log end -->\n";
2788 'message' => $message,
2789 'script' => (isset($_SERVER[
'PHP_SELF']) ? basename($_SERVER[
'PHP_SELF'],
'.php') :
''),
2791 'user' => ((is_object($user) && $user->id) ? $user->login :
''),
2793 'osuser' => function_exists(
'posix_getuid') ? (string) posix_getuid() :
'',
2794 'ospid' => (string) getmypid()
2799 if (!empty($remoteip)) {
2800 $data[
'ip'] = $remoteip;
2804 if (!empty($_SERVER[
'HTTP_X_FORWARDED_FOR'])) {
2805 $tmpips = explode(
',', $_SERVER[
'HTTP_X_FORWARDED_FOR']);
2809 foreach ($tmpips as $tmpip) {
2810 $tmpip = trim($tmpip);
2811 if (strtolower($tmpip) == strtolower($remoteip)) {
2814 if (empty($data[
'ip'])) {
2815 $data[
'ip'] = $tmpip;
2818 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $tmpip;
2821 if (!$foundremoteip) {
2823 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $remoteip;
2825 $data[
'ip'] .= (($j > 0) ?
']' :
'');
2826 } elseif (!empty($_SERVER[
'HTTP_CLIENT_IP'])) {
2827 $tmpips = explode(
',', $_SERVER[
'HTTP_CLIENT_IP']);
2831 foreach ($tmpips as $tmpip) {
2832 $tmpip = trim($tmpip);
2833 if (strtolower($tmpip) == strtolower($remoteip)) {
2836 if (empty($data[
'ip'])) {
2837 $data[
'ip'] = $tmpip;
2840 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $tmpip;
2843 if (!$foundremoteip) {
2845 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $remoteip;
2847 $data[
'ip'] .= (($j > 0) ?
']' :
'');
2849 } elseif (!empty($_SERVER[
'SERVER_ADDR'])) {
2851 $data[
'ip'] = (string) $_SERVER[
'SERVER_ADDR'];
2852 } elseif (!empty($_SERVER[
'COMPUTERNAME'])) {
2854 $data[
'ip'] = (string) $_SERVER[
'COMPUTERNAME'];
2856 $data[
'ip'] =
'???';
2859 if (!empty($_SERVER[
'USERNAME'])) {
2861 $data[
'osuser'] = (string) $_SERVER[
'USERNAME'];
2862 } elseif (!empty($_SERVER[
'LOGNAME'])) {
2864 $data[
'osuser'] = (string) $_SERVER[
'LOGNAME'];
2868 foreach ($conf->loghandlers as $loghandlerinstance) {
2869 if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler) {
2872 $loghandlerinstance->export($data, $suffixinfilename);
2878 foreach ($conf->loghandlers as $loghandlerinstance) {
2879 $loghandlerinstance->setIdent($ident);
2899 $form =
new Form($db);
2901 $templatenameforexport = $website->name_template;
2902 if (empty($templatenameforexport)) {
2903 $templatenameforexport =
'website_' . $website->ref;
2907 $out .=
'<input type="button" class="cursorpointer button bordertransp" id="open-dialog-' . $name .
'" value="' .
dol_escape_htmltag($buttonstring) .
'"/>';
2910 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">';
2911 $out .=
'jQuery(document).ready(function () {';
2912 $out .=
' jQuery("#open-dialog-' . $name .
'").click(function () {';
2913 $out .=
' var dialogHtml = \'';
2915 $dialogcontent =
' <div id="custom-dialog-' . $name .
'">';
2916 $dialogcontent .=
' <div style="margin-top: 20px;">';
2917 $dialogcontent .=
' <label for="export-site-' . $name .
'"><strong>' . $langs->trans(
"ExportSiteLabel") .
'...</label><br>';
2918 $dialogcontent .=
' <button class="button smallpaddingimp" id="export-site-' . $name .
'">' .
dol_escape_htmltag($langs->trans(
"DownloadZip")) .
'</button>';
2919 $dialogcontent .=
' </div>';
2920 $dialogcontent .=
' <br>';
2921 $dialogcontent .=
' <div style="margin-top: 20px;">';
2922 $dialogcontent .=
' <strong>' . $langs->trans(
"ExportSiteGitLabel") .
' ' . $form->textwithpicto(
'', $langs->trans(
"SourceFiles"), 1,
'help',
'', 0, 3,
'') .
'</strong><br>';
2923 $dialogcontent .=
' <form action="' .
dol_escape_htmltag($overwriteGitUrl) .
'" method="POST">';
2924 $dialogcontent .=
' <input type="hidden" name="action" value="overwritesite">';
2925 $dialogcontent .=
' <input type="hidden" name="token" value="' .
newToken() .
'">';
2926 $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>';
2927 $dialogcontent .=
' <button type="submit" class="button smallpaddingimp" id="overwrite-git-' . $name .
'">' .
dol_escape_htmltag($langs->trans(
"ExportIntoGIT")) .
'</button>';
2928 $dialogcontent .=
' </form>';
2929 $dialogcontent .=
' </div>';
2930 $dialogcontent .=
' </div>';
2937 // Add the content of the dialog to the body of the page
2938 $out .= ' var $dialog = jQuery(
"#custom-dialog-' . $name . '");
';
2939 $out .= ' if ($dialog.length > 0) {
2942 jQuery(
"body").append(dialogHtml);
';
2944 // Configuration of popup
2945 $out .= ' jQuery(
"#custom-dialog-' . $name . '").dialog({
';
2946 $out .= ' autoOpen:
false,
';
2947 $out .= ' modal:
true,
';
2948 $out .= ' height: 290,
';
2949 $out .= ' width:
"40%",
';
2950 $out .= ' title:
"' . dol_escape_js($label) . '",
';
2953 // Simulate a click on the original "submit" input to export the site.
2954 $out .= ' jQuery(
"#export-site-' . $name . '").click(
function () {
';
2955 $out .= ' console.log(
"Clic on exportsite.");
';
2956 $out .= ' var target = jQuery(
"input[name=\'' . dol_escape_js($exportSiteName) . '\']");
';
2957 $out .= ' console.log(
"element founded:", target.length > 0);
';
2958 $out .= ' if (target.length > 0) { target.click(); }
';
2959 $out .= ' jQuery(
"#custom-dialog-' . $name . '").dialog(
"close");
';
2963 $out .= ' jQuery(
"#custom-dialog-' . $name . '").dialog(
"open");
';
2964 $out .= ' return false;
';
2967 $out .= '</script>
';
2989function dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled = '
', $morecss = 'classlink
button bordertransp
', $jsonopen = '', $jsonclose = '', $accesskey = '')
2993 if (strpos($url, '?
') > 0) {
2994 $url .= '&dol_hide_topmenu=1&dol_hide_leftmenu=1&dol_openinpopup=
' . urlencode($name);
2996 $url .= '?dol_hide_topmenu=1&dol_hide_leftmenu=1&dol_openinpopup=
' . urlencode($name);
2999 if (preg_match('/^https/i
', $url)) {
3002 $urltoopen = DOL_URL_ROOT . $url;
3007 //print '<input
type=
"submit" class=
"button bordertransp"'.$disabled.' value=
"'.dol_escape_htmltag($langs->trans("MediaFiles
")).'" name=
"file_manager">
';
3008 $out .= '<!-- a link
for button to open url into a dialog popup -->
';
3009 $out .= '<a
' . ($accesskey ? ' accesskey=
"' . $accesskey . '"' : '') . ' class=
"cursorpointer reposition button_' . $name . ($morecss ? ' ' . $morecss : '') . '"' . $disabled . ' title=
"' . dol_escape_htmltag($label) . '"';
3010 if (empty($conf->use_javascript_ajax)) {
3011 $out .= ' href=
"' . $urltoopen . '" target=
"_blank"';
3012 } elseif ($jsonopen) {
3013 $out .= ' href=
"#" onclick=
"' . $jsonopen . '"';
3015 $out .= ' href=
"#"';
3017 $out .= '>
' . $buttonstring . '</a>
';
3019 if (!empty($conf->use_javascript_ajax)) {
3020 // Add code to open url using the popup.
3021 $out .= '<!-- code to open popup and variables to retrieve returned variables -->
';
3022 $out .= '<div
id=
"idfordialog' . $name . '" class=
"hidden">
' . (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER
') < 2 ? 'div
for dialog
' : '') . '</div>
';
3024 $out .= '<!-- Add js code to open dialog popup on dialog -->
';
3025 $out .= '<script nonce=
"' . getNonce() . '" type=
"text/javascript">
3026 jQuery(document).ready(
function () {
3027 jQuery(
".button_' . $name . '").click(
function () {
3028 console.log(\
'Open popup with jQuery(...).dialog() on URL ' .
dol_escape_js($urltoopen) .
'\');
3029 var $tmpdialog = $(\
'#idfordialog' . $name .
'\');
3030 $tmpdialog.html(\
'<iframe class="iframedialog" id="iframedialog' . $name .
'" style="border: 0px;" src="' . $urltoopen .
'" width="100%" height="98%"></iframe>\');
3034 height: (window.innerHeight - 150),
3037 open: function (event, ui) {
3038 console.log(
"open popup name=' . $name . '");
3040 close:
function (event, ui) {
3041 console.log(
"Popup is closed, run jsonclose = ' . $jsonclose . '");
3042 ' . (empty($jsonclose) ? '' : $jsonclose . ';
') . '
3046 $tmpdialog.dialog(\
'open\');
3071function dol_fiche_head($links = array(), $active =
'0', $title =
'', $notab = 0, $picto =
'', $pictoisfullpath = 0, $morehtmlright =
'', $morecss =
'', $limittoshow = 0, $moretabssuffix =
'')
3073 print
dol_get_fiche_head($links, $active, $title, $notab, $picto, $pictoisfullpath, $morehtmlright, $morecss, $limittoshow, $moretabssuffix);
3093function dol_get_fiche_head($links = array(), $active =
'', $title =
'', $notab = 0, $picto =
'', $pictoisfullpath = 0, $morehtmlright =
'', $morecss =
'', $limittoshow = 0, $moretabssuffix =
'', $dragdropfile = 0, $morecssdiv =
'')
3095 global $conf, $langs, $hookmanager;
3099 if (!empty($conf->dol_optimize_smallscreen)) {
3103 $out =
"\n" .
'<!-- dol_fiche_head - dol_get_fiche_head -->';
3105 if ((!empty($title) && $showtitle) || $morehtmlright || !empty($links)) {
3106 $out .=
'<div class="tabs' . ($picto ?
'' :
' nopaddingleft') .
'" data-role="controlgroup" data-type="horizontal">' .
"\n";
3110 if ($morehtmlright) {
3111 $out .=
'<div class="inline-block floatright tabsElem">' . $morehtmlright .
'</div>';
3118 if (is_array($links) && !empty($links)) {
3119 $keys = array_keys($links);
3121 $maxkey = max($keys);
3127 if (empty($limittoshow)) {
3130 if (!empty($conf->dol_optimize_smallscreen)) {
3138 for ($i = 0; $i <= $maxkey; $i++) {
3139 if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2])) {
3141 if ($i >= $limittoshow) {
3147 for ($i = 0; $i <= $maxkey; $i++) {
3148 if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2])) {
3154 if ($i < $limittoshow || $isactive) {
3156 $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])) .
' -->';
3158 if (isset($links[$i][2]) && $links[$i][2] ==
'image') {
3159 if (!empty($links[$i][0])) {
3160 $out .=
'<a class="tabimage' . ($morecss ?
' ' . $morecss :
'') .
'" href="' . $links[$i][0] .
'">' . $links[$i][1] .
'</a>' .
"\n";
3162 $out .=
'<span class="tabspan">' . $links[$i][1] .
'</span>' .
"\n";
3164 } elseif (!empty($links[$i][1])) {
3166 $out .=
'<div class="tab tab' . ($isactive ?
'active' :
'unactive') .
'" style="margin: 0 !important">';
3168 if (!empty($links[$i][0])) {
3169 $titletoshow = preg_replace(
'/<.*$/',
'', $links[$i][1]);
3170 $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) .
'">';
3173 if ($displaytab == 0 && $picto) {
3174 $out .=
img_picto($title, $picto,
'', $pictoisfullpath, 0, 0,
'',
'imgTabTitle paddingright marginrightonlyshort');
3177 $out .= $links[$i][1];
3178 if (!empty($links[$i][0])) {
3179 $out .=
'</a>' .
"\n";
3181 $out .= empty($links[$i][4]) ?
'' : $links[$i][4];
3190 $outmore .=
'<div class="popuptabset wordwrap">';
3192 $outmore_content =
'';
3194 if (isset($links[$i][2]) && $links[$i][2] ==
'image') {
3195 if (!empty($links[$i][0])) {
3196 $outmore_content .=
'<a class="tabimage' . ($morecss ?
' ' . $morecss :
'') .
'" href="' . $links[$i][0] .
'">' . $links[$i][1] .
'</a>' .
"\n";
3198 $outmore_content .=
'<span class="tabspan">' . $links[$i][1] .
'</span>' .
"\n";
3200 } elseif (!empty($links[$i][1])) {
3201 $outmore_content .=
'<a' . (!empty($links[$i][2]) ?
' id="' . $links[$i][2] .
'"' :
'') .
' class="wordwrap inline-block' . ($morecss ?
' ' . $morecss :
'') .
'" href="' . $links[$i][0] .
'">';
3202 $outmore_content .= preg_replace(
'/([a-z])\|([a-z])/i',
'\\1 | \\2', $links[$i][1]);
3203 $outmore_content .=
'</a>' .
"\n";
3205 if ($outmore_content !==
'') {
3206 $outmore .=
'<div class="popuptab wordwrap" style="display:inherit;">' . $outmore_content .
'</div>';
3212 $displaytab = $i + 1;
3215 $outmore .=
'</div>';
3219 $left = ($langs->trans(
"DIRECTION") ==
'rtl' ?
'right' :
'left');
3220 $right = ($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right');
3221 $widthofpopup = 240;
3223 $tabsname = $moretabssuffix;
3224 if (empty($tabsname)) {
3225 $tabsname = str_replace(
"@",
"", $picto);
3227 $out .=
'<div id="moretabs' . $tabsname .
'" class="inline-block tabsElem valignmiddle">';
3229 $out .=
'<div class="tab valignmiddle"><a href="#" class="tab moretab inline-block tabunactive valignmiddle"><span class="hideonsmartphone">' . $langs->trans(
"More") .
'</span>... (' . $nbintab .
')</a></div>';
3231 $out .=
'<div id="moretabsList' . $tabsname .
'" style="width: ' . $widthofpopup .
'px; position: absolute; ' . $left .
': -999em; text-align: ' . $left .
'; margin:0px; padding:2px; z-index:10;">';
3234 $out .=
'<div></div>';
3237 $out .=
'<script nonce="' .
getNonce() .
'">';
3238 $out .=
"$('#moretabs" . $tabsname .
"').mouseenter( function() {
3239 var x = this.offsetLeft, y = this.offsetTop;
3240 console.log('mouseenter " . $left .
" x='+x+' y='+y+' window.innerWidth='+window.innerWidth);
3241 if ((window.innerWidth - x) < " . ($widthofpopup + 10) .
") {
3242 $('#moretabsList" . $tabsname .
"').css('" . $right .
"','8px');
3244 $('#moretabsList" . $tabsname .
"').css('" . $left .
"','auto');
3247 $out .=
"$('#moretabs" . $tabsname .
"').mouseleave( function() { console.log('mouseleave " . $left .
"'); $('#moretabsList" . $tabsname .
"').css('" . $left .
"','-999em');});";
3248 $out .=
"</script>";
3251 if ((!empty($title) && $showtitle) || $morehtmlright || !empty($links)) {
3255 if (!$notab || $notab == -1 || $notab == -2 || $notab == -3 || $notab == -4) {
3256 $out .=
"\n" .
'<div id="dragDropAreaTabBar" class="tabBar' . ($notab == -1 ?
'' : ($notab == -2 ?
' tabBarNoTop' : ((($notab == -3 || $notab == -4) ?
' noborderbottom' :
'') . ($notab == -4 ?
'' :
' tabBarWithBottom'))));
3257 $out .= ($morecssdiv ?
' ' . $morecssdiv :
'');
3258 $out .=
'">' .
"\n";
3260 if (!empty($dragdropfile)) {
3261 include_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
3264 $parameters = array(
'tabname' => $active,
'out' => $out);
3265 $reshook = $hookmanager->executeHooks(
'printTabsHead', $parameters);
3267 $out = $hookmanager->resPrint;
3293 if (!$notab || $notab == -1) {
3294 return "\n</div>\n";
3319function dol_banner_tab(
$object, $paramid, $morehtml =
'', $shownav = 1, $fieldid =
'rowid', $fieldref =
'ref', $morehtmlref =
'', $moreparam =
'', $nodbprefix = 0, $morehtmlleft =
'', $morehtmlstatus =
'', $onlybanner = 0, $morehtmlright =
'')
3321 global $conf, $form, $user, $langs, $hookmanager, $action;
3325 $maxvisiblephotos = 1;
3327 $entity = (empty(
$object->entity) ? $conf->entity :
$object->entity);
3330 if (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'barcode',
'lire_advance')) {
3333 $modulepart =
'unknown';
3335 if (in_array(
$object->element, [
'societe',
'contact',
'product',
'ticket',
'bom'])) {
3336 $modulepart =
$object->element;
3337 } elseif (
$object->element ==
'member') {
3338 $modulepart =
'memberphoto';
3339 } elseif (
$object->element ==
'user') {
3340 $modulepart =
'userphoto';
3343 if (class_exists(
"Imagick")) {
3344 if (
$object->element ==
'expensereport' ||
$object->element ==
'propal' ||
$object->element ==
'commande' ||
$object->element ==
'facture' ||
$object->element ==
'supplier_proposal') {
3345 $modulepart =
$object->element;
3346 } elseif (
$object->element ==
'fichinter' ||
$object->element ==
'intervention') {
3347 $modulepart =
'ficheinter';
3348 } elseif (
$object->element ==
'contrat' ||
$object->element ==
'contract') {
3349 $modulepart =
'contract';
3350 } elseif (
$object->element ==
'order_supplier') {
3351 $modulepart =
'supplier_order';
3352 } elseif (
$object->element ==
'invoice_supplier') {
3353 $modulepart =
'supplier_invoice';
3357 if (
$object->element ==
'product') {
3359 '@phan-var-force Product $object';
3361 $cssclass =
'photowithmargin photoref';
3362 $showimage =
$object->is_photo_available($conf->product->multidir_output[$entity]);
3364 if ($conf->browser->layout ==
'phone') {
3365 $maxvisiblephotos = 1;
3368 $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>';
3372 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
3374 $nophoto =
'/public/theme/common/nophoto.png';
3375 $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>';
3378 } elseif (
$object->element ==
'category') {
3380 '@phan-var-force Categorie $object';
3382 $cssclass =
'photowithmargin photoref';
3383 $showimage =
$object->isAnyPhotoAvailable($conf->categorie->multidir_output[$entity]);
3385 if ($conf->browser->layout ==
'phone') {
3386 $maxvisiblephotos = 1;
3389 $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>';
3393 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
3395 $nophoto =
'/public/theme/common/nophoto.png';
3396 $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>';
3399 } elseif (
$object->element ==
'bom') {
3401 '@phan-var-force Bom $object';
3403 $cssclass =
'photowithmargin photoref';
3404 $showimage =
$object->is_photo_available($conf->bom->multidir_output[$entity]);
3406 if ($conf->browser->layout ==
'phone') {
3407 $maxvisiblephotos = 1;
3410 $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>';
3414 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
3416 $nophoto =
'/public/theme/common/nophoto.png';
3417 $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>';
3420 } elseif (
$object->element ==
'ticket') {
3422 $cssclass =
'photoref';
3424 '@phan-var-force Ticket $object';
3425 $showimage =
$object->is_photo_available($conf->ticket->multidir_output[$entity] .
'/' .
$object->ref);
3427 if ($conf->browser->layout ==
'phone') {
3428 $maxvisiblephotos = 1;
3432 $showphoto =
$object->show_photos(
'ticket', $conf->ticket->multidir_output[$entity],
'small', $maxvisiblephotos, 0, 0, 0, $width, 0);
3434 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">' . $showphoto .
'</div>';
3442 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
3444 $nophoto =
img_picto(
'No photo',
'object_ticket');
3445 $morehtmlleft .=
'<!-- No photo to show -->';
3446 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
3447 $morehtmlleft .= $nophoto;
3448 $morehtmlleft .=
'</div></div>';
3452 if ($modulepart !=
'unknown' || method_exists(
$object,
'getDataToShowPhoto')) {
3455 if (in_array($modulepart, array(
'propal',
'commande',
'facture',
'ficheinter',
'contract',
'supplier_order',
'supplier_proposal',
'supplier_invoice',
'expensereport')) && class_exists(
"Imagick")) {
3457 $dir_output = (empty($conf->$modulepart->multidir_output[$entity]) ? $conf->$modulepart->dir_output : $conf->$modulepart->multidir_output[$entity]) .
"/";
3458 if (in_array($modulepart, array(
'invoice_supplier',
'supplier_invoice'))) {
3460 $subdir .= ((!empty($subdir) && !preg_match(
'/\/$/', $subdir)) ?
'/' :
'') . $objectref;
3464 if (empty($subdir)) {
3465 $subdir =
'errorgettingsubdirofobject';
3468 $filepath = $dir_output . $subdir .
"/";
3470 $filepdf = $filepath . $objectref .
".pdf";
3471 $relativepath = $subdir .
'/' . $objectref .
'.pdf';
3474 $fileimage = $filepdf .
'_preview.png';
3475 $relativepathimage = $relativepath .
'_preview.png';
3477 $pdfexists = file_exists($filepdf);
3482 if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) {
3484 include_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
3493 if ($pdfexists && !$error) {
3494 $heightforphotref = 80;
3495 if (!empty($conf->dol_optimize_smallscreen)) {
3496 $heightforphotref = 60;
3499 if (file_exists($fileimage)) {
3500 $phototoshow =
'<div class="photoref">';
3501 $phototoshow .=
'<img height="' . $heightforphotref .
'" class="photo photowithborder" src="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=apercu' . $modulepart .
'&file=' . urlencode($relativepathimage) .
'">';
3502 $phototoshow .=
'</div>';
3505 } elseif (!$phototoshow) {
3506 $phototoshow .= $form->showphoto($modulepart,
$object, 0, 0, 0,
'photowithmargin photoref',
'small', 1, 0);
3510 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">';
3511 $morehtmlleft .= $phototoshow;
3512 $morehtmlleft .=
'</div>';
3516 if (empty($phototoshow)) {
3517 if (
$object->element ==
'action') {
3519 $cssclass =
'photorefcenter';
3520 $nophoto =
img_picto(
'No photo',
'title_agenda');
3523 $cssclass =
'photorefcenter';
3525 $prefix =
'object_';
3529 if (strpos($picto,
'fontawesome_') !==
false) {
3532 $nophoto =
img_picto(
'No photo', $prefix . $picto);
3534 $morehtmlleft .=
'<!-- No photo to show -->';
3535 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
3536 $morehtmlleft .= $nophoto;
3537 $morehtmlleft .=
'</div></div>';
3543 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">' . $form->showbarcode(
$object, 100,
'photoref valignmiddle') .
'</div>';
3546 if (
$object->element ==
'societe') {
3548 if (!empty($conf->use_javascript_ajax) && $user->hasRight(
'societe',
'creer') &&
getDolGlobalString(
'MAIN_DIRECT_STATUS_UPDATE')) {
3551 $morehtmlstatus .=
$object->getLibStatut(6);
3553 } elseif (
$object->element ==
'product') {
3556 if (!empty($conf->use_javascript_ajax) && $user->hasRight(
'produit',
'creer') &&
getDolGlobalString(
'MAIN_DIRECT_STATUS_UPDATE')) {
3557 $morehtmlstatus .=
ajax_object_onoff(
$object,
'status',
'status',
'ProductStatusOnSell',
'ProductStatusNotOnSell');
3559 $morehtmlstatus .=
'<span class="statusrefsell">' .
$object->getLibStatut(6, 0) .
'</span>';
3561 $morehtmlstatus .=
' ';
3563 if (!empty($conf->use_javascript_ajax) && $user->hasRight(
'produit',
'creer') &&
getDolGlobalString(
'MAIN_DIRECT_STATUS_UPDATE')) {
3564 $morehtmlstatus .=
ajax_object_onoff(
$object,
'status_buy',
'status_buy',
'ProductStatusOnBuy',
'ProductStatusNotOnBuy');
3566 $morehtmlstatus .=
'<span class="statusrefbuy">' .
$object->getLibStatut(6, 1) .
'</span>';
3568 } elseif (in_array(
$object->element, array(
'salary'))) {
3570 '@phan-var-force Salary $object';
3572 if (empty($tmptxt) || $tmptxt ==
$object->getLibStatut(3)) {
3575 $morehtmlstatus .= $tmptxt;
3576 } elseif (in_array(
$object->element, array(
'facture',
'invoice',
'invoice_supplier'))) {
3578 '@phan-var-force Facture|FactureFournisseur|CommonInvoice $object';
3579 if (!isset(
$object->alreadypaid)) {
3585 $tmptxt =
$object->getLibStatut(6, (
float)
$object->alreadypaid);
3586 if (empty($tmptxt) || $tmptxt ==
$object->getLibStatut(3)) {
3587 $tmptxt =
$object->getLibStatut(5, (
float)
$object->alreadypaid);
3589 $morehtmlstatus .= $tmptxt;
3590 } elseif (in_array(
$object->element, array(
'chargesociales',
'loan',
'tva'))) {
3592 '@phan-var-force ChargeSociales|Loan|Tva $object';
3594 if (empty($tmptxt) || $tmptxt ==
$object->getLibStatut(3)) {
3597 $morehtmlstatus .= $tmptxt;
3598 } elseif (
$object->element ==
'contrat' ||
$object->element ==
'contract') {
3601 $morehtmlstatus .=
$object->getLibStatut(5);
3603 $morehtmlstatus .=
$object->getLibStatut(4);
3605 } elseif (
$object->element ==
'facturerec') {
3607 '@phan-var-force FactureRec $object';
3608 if (
$object->frequency == 0) {
3609 $morehtmlstatus .=
$object->getLibStatut(2);
3611 $morehtmlstatus .=
$object->getLibStatut(5);
3613 } elseif (
$object->element ==
'project_task') {
3615 $tmptxt =
$object->getLibStatut(4);
3616 $morehtmlstatus .= $tmptxt;
3617 } elseif (method_exists(
$object,
'getLibStatut')) {
3618 $tmptxt =
$object->getLibStatut(6);
3619 if (empty($tmptxt) || $tmptxt ==
$object->getLibStatut(3)) {
3620 $tmptxt =
$object->getLibStatut(5);
3622 $morehtmlstatus .= $tmptxt;
3626 if (
isModEnabled(
'accounting') && in_array(
$object->element, array(
'bank',
'paiementcharge',
'facture',
'invoice',
'invoice_supplier',
'expensereport',
'payment_various'))) {
3628 if (method_exists(
$object,
'getVentilExportCompta')) {
3629 $accounted =
$object->getVentilExportCompta(1);
3630 $langs->load(
"accountancy");
3631 $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>';
3636 if (!empty(
$object->name_alias)) {
3638 '@phan-var-force Societe $object';
3643 if (in_array(
$object->element, array(
'product',
'bank_account',
'project_task'))) {
3646 $morehtmlref .=
'<div class="refidno banner-object-label">' .
$object->label .
'</div>';
3650 if (method_exists(
$object,
'getBannerAddress') && !in_array(
$object->element, array(
'product',
'bookmark',
'ecm_directories',
'ecm_files'))) {
3653 $morehtmlref .=
'<div class="refidno refaddress">';
3654 $morehtmlref .= $moreaddress;
3655 $morehtmlref .=
'</div>';
3659 $morehtmlref .=
'<div style="clear: both;"></div>';
3660 $morehtmlref .=
'<div class="refidno opacitymedium">';
3661 $morehtmlref .= $langs->trans(
"TechnicalID") .
': ' . ((int)
$object->id);
3662 $morehtmlref .=
'</div>';
3665 $parameters = array(
'morehtmlref' => &$morehtmlref,
'moreparam' => &$moreparam,
'morehtmlleft' => &$morehtmlleft,
'morehtmlstatus' => &$morehtmlstatus,
'morehtmlright' => &$morehtmlright);
3666 $reshook = $hookmanager->executeHooks(
'formDolBanner', $parameters,
$object, $action);
3669 } elseif (empty($reshook)) {
3670 $morehtmlref .= $hookmanager->resPrint;
3671 } elseif ($reshook > 0) {
3672 $morehtmlref = $hookmanager->resPrint;
3681 print
'<div class="' . ($onlybanner ?
'arearefnobottom ' :
'arearef ') .
'heightref valignmiddle centpercent object-banner-tab-container" data-module-part="'.
dolPrintHTMLForAttribute($modulepart).
'">';
3682 print $form->showrefnav(
$object, $paramid, $morehtml, $shownav, $fieldid, $fieldref, $morehtmlref, $moreparam, $nodbprefix, $morehtmlleft, $morehtmlstatus, $morehtmlright);
3684 print
'<div class="underrefbanner clearboth"></div>';
3696function fieldLabel($langkey, $fieldkey, $fieldrequired = 0)
3700 if ($fieldrequired) {
3701 $ret .=
'<span class="fieldrequired">';
3703 $ret .=
'<label for="' . $fieldkey .
'">';
3704 $ret .= $langs->trans($langkey);
3706 if ($fieldrequired) {
3727 global $langs, $hookmanager;
3730 $countriesusingstate = array(
'AU',
'CA',
'US',
'IN',
'GB',
'ES',
'UK',
'TR',
'CN');
3735 $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)));
3738 if (isset(
$object->country_code) && in_array(
$object->country_code, array(
'AU',
'CA',
'US',
'CN')) ||
getDolGlobalString(
'MAIN_FORCE_STATE_INTO_ADDRESS')) {
3740 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3741 $ret .= (($ret && $town) ? $sep :
'') . $town;
3744 $ret .= ($ret ? ($town ?
", " : $sep) :
'') .
$object->state;
3747 $ret .= ($ret ? (($town ||
$object->state) ?
", " : $sep) :
'') .
$object->zip;
3749 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'GB',
'UK'))) {
3751 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3752 $ret .= ($ret ? $sep :
'') . $town;
3754 $ret .= ($ret ?
", " :
'') .
$object->state;
3757 $ret .= ($ret ? $sep :
'') .
$object->zip;
3759 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'ES',
'TR'))) {
3761 $ret .= ($ret ? $sep :
'') .
$object->zip;
3762 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3763 $ret .= ($town ? ((
$object->zip ?
' ' :
'') . $town) :
'');
3765 $ret .= $sep .
$object->state;
3767 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'JP'))) {
3770 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3772 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'IT'))) {
3774 $ret .= ($ret ? $sep :
'') .
$object->zip;
3775 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3776 $ret .= ($town ? ((
$object->zip ?
' ' :
'') . $town) :
'');
3777 $ret .= (empty(
$object->state_code) ?
'' : (
' ' .
$object->state_code));
3780 $town = (($extralangcode && !empty(
$object->array_languages[
'address'][$extralangcode])) ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3781 $ret .= !empty(
$object->zip) ? (($ret ? $sep :
'') .
$object->zip) :
'';
3782 $ret .= ($town ? ((
$object->zip ?
' ' : ($ret ? $sep :
'')) . $town) :
'');
3783 if (!empty(
$object->state) && in_array(
$object->country_code, $countriesusingstate)) {
3784 $ret .= ($ret ?
", " :
'') .
$object->state;
3788 if (!is_object($outputlangs)) {
3789 $outputlangs = $langs;
3792 $langs->load(
"dict");
3793 $ret .= (empty(
$object->country_code) ?
'' : ($ret ? $sep :
'') . $outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv(
"Country" .
$object->country_code)));
3796 $parameters = array(
'withcountry' => $withcountry,
'sep' => $sep,
'outputlangs' => $outputlangs,
'mode' => $mode,
'extralangcode' => $extralangcode);
3797 $reshook = $hookmanager->executeHooks(
'formatAddress', $parameters,
$object);
3801 $ret .= $hookmanager->resPrint;
3818function dol_strftime($fmt, $ts =
false, $is_gmt =
false)
3820 if ((abs($ts) <= 0x7FFFFFFF)) {
3823 return 'Error date outside supported range';
3849function dol_print_date($time, $format =
'', $tzoutput =
'auto', $outputlangs =
null, $encodetooutput =
false, $decorate = 0)
3851 global $conf, $langs;
3858 if ($tzoutput ===
'auto') {
3859 $tzoutput = (empty($conf) ?
'tzserver' : (isset($conf->tzuserinputkey) ? $conf->tzuserinputkey :
'tzserver'));
3864 $offsettz = $offsetdst = 0;
3867 if (is_string($tzoutput)) {
3868 if ($tzoutput ==
'tzserver') {
3870 $offsettzstring = @date_default_timezone_get();
3875 } elseif ($tzoutput ==
'tzuser' || $tzoutput ==
'tzuserrel') {
3878 $offsettzstring = (empty($_SESSION[
'dol_tz_string']) ?
getDolGlobalString(
'MAIN_DOLIBARR_USER_TIMEZONE',
'UTC') : $_SESSION[
'dol_tz_string']);
3880 if (class_exists(
'DateTimeZone')) {
3882 $user_date_tz =
new DateTimeZone($offsettzstring);
3885 dol_syslog(
"DateInvalidTimeZoneException for timezone string '".$offsettzstring.
"'. Falling back to UTC.", LOG_ERR);
3886 $user_date_tz =
new DateTimeZone(
'UTC');
3888 $user_dt =
new DateTime();
3889 $user_dt->setTimezone($user_date_tz);
3890 $user_dt->setTimestamp($tzoutput ==
'tzuser' ?
dol_now() : (int) $time);
3891 $offsettz = $user_dt->getOffset();
3893 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
3894 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
3899 if (!is_object($outputlangs)) {
3900 $outputlangs = $langs;
3903 $format =
'daytextshort';
3908 $reduceformat = (!empty($conf->dol_optimize_smallscreen) && in_array($format, array(
'day',
'dayhour',
'dayhoursec'))) ? 1 : 0;
3909 $format = preg_replace(
'/inputnoreduce/',
'', $format);
3910 $formatwithoutreduce = preg_replace(
'/reduceformat/',
'', $format);
3911 if ($formatwithoutreduce != $format) {
3912 $format = $formatwithoutreduce;
3918 if ($format ==
'day') {
3919 $format = ($outputlangs->trans(
"FormatDateShort") !=
"FormatDateShort" ? $outputlangs->trans(
"FormatDateShort") : $conf->format_date_short);
3920 } elseif ($format ==
'hour') {
3921 $format = ($outputlangs->trans(
"FormatHourShort") !=
"FormatHourShort" ? $outputlangs->trans(
"FormatHourShort") : $conf->format_hour_short);
3922 } elseif ($format ==
'hourduration') {
3923 $format = ($outputlangs->trans(
"FormatHourShortDuration") !=
"FormatHourShortDuration" ? $outputlangs->trans(
"FormatHourShortDuration") : $conf->format_hour_short_duration);
3924 } elseif ($format ==
'daytext') {
3925 $format = ($outputlangs->trans(
"FormatDateText") !=
"FormatDateText" ? $outputlangs->trans(
"FormatDateText") : $conf->format_date_text);
3926 } elseif ($format ==
'daytextshort') {
3927 $format = ($outputlangs->trans(
"FormatDateTextShort") !=
"FormatDateTextShort" ? $outputlangs->trans(
"FormatDateTextShort") : $conf->format_date_text_short);
3928 } elseif ($format ==
'dayhour') {
3929 $format = ($outputlangs->trans(
"FormatDateHourShort") !=
"FormatDateHourShort" ? $outputlangs->trans(
"FormatDateHourShort") : $conf->format_date_hour_short);
3930 } elseif ($format ==
'dayhoursec') {
3931 $format = ($outputlangs->trans(
"FormatDateHourSecShort") !=
"FormatDateHourSecShort" ? $outputlangs->trans(
"FormatDateHourSecShort") : $conf->format_date_hour_sec_short);
3932 } elseif ($format ==
'dayhourtext') {
3933 $format = ($outputlangs->trans(
"FormatDateHourText") !=
"FormatDateHourText" ? $outputlangs->trans(
"FormatDateHourText") : $conf->format_date_hour_text);
3934 } elseif ($format ==
'dayhourtextshort') {
3935 $format = ($outputlangs->trans(
"FormatDateHourTextShort") !=
"FormatDateHourTextShort" ? $outputlangs->trans(
"FormatDateHourTextShort") : $conf->format_date_hour_text_short);
3936 } elseif ($format ==
'dayhourlog') {
3938 $format =
'%Y%m%d%H%M%S';
3939 } elseif ($format ==
'dayhourlogsmall') {
3941 $format =
'%y%m%d%H%M';
3942 } elseif ($format ==
'dayhourldap') {
3943 $format =
'%Y%m%d%H%M%SZ';
3944 } elseif ($format ==
'dayhourxcard') {
3945 $format =
'%Y%m%dT%H%M%SZ';
3946 } elseif ($format ==
'dayxcard') {
3948 } elseif ($format ==
'dayrfc') {
3949 $format =
'%Y-%m-%d';
3950 } elseif ($format ==
'dayhourrfc') {
3951 $format =
'%Y-%m-%dT%H:%M:%SZ';
3952 } elseif ($format ==
'standard') {
3953 $format =
'%Y-%m-%d %H:%M:%S';
3956 if ($reduceformat) {
3957 $format = str_replace(
'%Y',
'%y', $format);
3958 $format = str_replace(
'yyyy',
'yy', $format);
3962 if (preg_match(
'/%b/i', $format)) {
3964 $format = str_replace(
'%b',
'__b__', $format);
3965 $format = str_replace(
'%B',
'__B__', $format);
3967 if (preg_match(
'/%a/i', $format)) {
3969 $format = str_replace(
'%a',
'__a__', $format);
3970 $format = str_replace(
'%A',
'__A__', $format);
3975 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)) {
3978 } elseif (preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', (
string) $time, $reg)) {
3982 $syear = (!empty($reg[1]) ? $reg[1] :
'');
3983 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
3984 $sday = (!empty($reg[3]) ? $reg[3] :
'');
3985 $shour = (!empty($reg[4]) ? $reg[4] :
'');
3986 $smin = (!empty($reg[5]) ? $reg[5] :
'');
3987 $ssec = (!empty($reg[6]) ? $reg[6] :
'');
3989 $time =
dol_mktime((
int) $shour, (
int) $smin, (
int) $ssec, (
int) $smonth, (
int) $sday, (
int) $syear,
true);
3992 $tzo =
new DateTimeZone(
'UTC');
3994 $tzo =
new DateTimeZone(date_default_timezone_get());
3996 $dtts =
new DateTime();
3997 $dtts->setTimestamp($time);
3998 $dtts->setTimezone($tzo);
3999 $newformat = str_replace(
4000 array(
'%Y',
'%y',
'%m',
'%d',
'%H',
'%I',
'%M',
'%S',
'%p',
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
4001 array(
'Y',
'y',
'm',
'd',
'H',
'h',
'i',
's',
'A',
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
4004 $ret = $dtts->format($newformat);
4006 array(
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
4007 array(
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
4012 if ($time < 100000000000) {
4013 $dtts =
new DateTime();
4016 $timetouse = (int) $time + $offsettz + $offsetdst;
4018 $tzo =
new DateTimeZone(
'UTC');
4019 $dtts->setTimezone($tzo);
4020 $dtts->setTimestamp($timetouse);
4022 $timetouse = (int) $time + $offsettz + $offsetdst;
4024 $tzo =
new DateTimeZone(date_default_timezone_get());
4025 $dtts->setTimestamp($timetouse);
4026 $dtts->setTimezone($tzo);
4029 $newformat = str_replace(
4030 array(
'%Y',
'%y',
'%m',
'%d',
'%H',
'%I',
'%M',
'%S',
'%p',
'%w',
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
4031 array(
'Y',
'y',
'm',
'd',
'H',
'h',
'i',
's',
'A',
'w',
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
4035 $ret = $dtts->format($newformat);
4038 array(
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
4039 array(
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
4043 $ret =
'Bad value ' . $time .
' for date';
4047 if (preg_match(
'/__b__/i', $format)) {
4048 $timetouse = $time + $offsettz + $offsetdst;
4051 $tzo =
new DateTimeZone(
'UTC');
4053 $tzo =
new DateTimeZone(date_default_timezone_get());
4055 $dtts =
new DateTime();
4056 $dtts->setTimestamp($timetouse);
4057 $dtts->setTimezone($tzo);
4058 $month = (int) $dtts->format(
"m");
4059 $month = sprintf(
"%02d", $month);
4060 if ($encodetooutput) {
4061 $monthtext = $outputlangs->transnoentities(
'Month' . $month);
4062 $monthtextshort = $outputlangs->transnoentities(
'MonthShort' . $month);
4064 $monthtext = $outputlangs->transnoentitiesnoconv(
'Month' . $month);
4065 $monthtextshort = $outputlangs->transnoentitiesnoconv(
'MonthShort' . $month);
4068 $ret = str_replace(
'__b__', $monthtextshort, $ret);
4069 $ret = str_replace(
'__B__', $monthtext, $ret);
4073 if (preg_match(
'/__a__/i', $format)) {
4075 $timetouse = $time + $offsettz + $offsetdst;
4078 $tzo =
new DateTimeZone(
'UTC');
4080 $tzo =
new DateTimeZone(date_default_timezone_get());
4082 $dtts =
new DateTime();
4083 $dtts->setTimestamp($timetouse);
4084 $dtts->setTimezone($tzo);
4085 $w = $dtts->format(
"w");
4086 $dayweek = $outputlangs->transnoentitiesnoconv(
'Day' . $w);
4088 $ret = str_replace(
'__A__', $dayweek, $ret);
4089 $ret = str_replace(
'__a__',
dol_substr($dayweek, 0, 3), $ret);
4093 $ret = preg_replace(
'/(\d\d:\d\d [AP]M)$/',
'<span class="'.($decorate === 1 ?
'opacitymedium' : $decorate).
'">\1</span>', $ret);
4094 $ret = preg_replace(
'/(\d\d:\d\d)$/',
'<span class="'.($decorate === 1 ?
'opacitymedium' : $decorate).
'">\1</span>', $ret);
4121function dol_getdate($timestamp, $fast =
false, $forcetimezone =
'')
4123 if ($timestamp ===
'') {
4127 $datetimeobj =
new DateTime();
4128 $datetimeobj->setTimestamp($timestamp);
4129 if ($forcetimezone) {
4130 $datetimeobj->setTimezone(
new DateTimeZone($forcetimezone ==
'gmt' ?
'UTC' : $forcetimezone));
4133 'year' => ((
int) date_format($datetimeobj,
'Y')),
4134 'mon' => ((
int) date_format($datetimeobj,
'm')),
4135 'mday' => ((
int) date_format($datetimeobj,
'd')),
4136 'wday' => ((
int) date_format($datetimeobj,
'w')),
4137 'yday' => ((
int) date_format($datetimeobj,
'z')),
4138 'hours' => ((
int) date_format($datetimeobj,
'H')),
4139 'minutes' => ((
int) date_format($datetimeobj,
'i')),
4140 'seconds' => ((
int) date_format($datetimeobj,
's')),
4168function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm =
'auto', $check = 1)
4173 if ($gm ===
'auto') {
4174 $gm = (empty($conf) ?
'tzserver' : $conf->tzuserinputkey);
4179 if ($hour == -1 || empty($hour)) {
4182 if ($minute == -1 || empty($minute)) {
4185 if ($second == -1 || empty($second)) {
4191 if (!$month || !$day) {
4200 if ($hour < 0 || $hour > 24) {
4203 if ($minute < 0 || $minute > 60) {
4206 if ($second < 0 || $second > 60) {
4211 if (empty($gm) || ($gm ===
'server' || $gm ===
'tzserver')) {
4212 $default_timezone = @date_default_timezone_get();
4213 $localtz =
new DateTimeZone($default_timezone);
4214 } elseif ($gm ===
'user' || $gm ===
'tzuser' || $gm ===
'tzuserrel') {
4216 $default_timezone = (empty($_SESSION[
"dol_tz_string"]) ? @date_default_timezone_get() : $_SESSION[
"dol_tz_string"]);
4218 $localtz =
new DateTimeZone($default_timezone);
4220 dol_syslog(
"Warning dol_tz_string contains an invalid value " . json_encode($_SESSION[
"dol_tz_string"] ??
null), LOG_WARNING);
4221 $default_timezone = @date_default_timezone_get();
4223 } elseif (strrpos($gm,
"tz,") !==
false) {
4224 $timezone = str_replace(
"tz,",
"", $gm);
4226 $localtz =
new DateTimeZone($timezone);
4228 dol_syslog(
"Warning passed timezone contains an invalid value " . $timezone, LOG_WARNING);
4232 if (empty($localtz)) {
4233 $localtz =
new DateTimeZone(
'UTC');
4235 $dt =
new DateTime(
'now', $localtz);
4236 $dt->setDate((
int) $year, (
int) $month, (
int) $day);
4237 $dt->setTime((
int) $hour, (
int) $minute, (
int) $second);
4238 $date = $dt->getTimestamp();
4254function dol_now($mode =
'gmt')
4258 if ($mode ===
'auto') {
4262 if ($mode ==
'gmt') {
4264 } elseif ($mode ==
'tzserver') {
4265 require_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
4267 $ret = (int) (
dol_now(
'gmt') + ($tzsecond * 3600));
4272 } elseif ($mode ==
'tzuser' || $mode ==
'tzuserrel') {
4275 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
4276 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
4277 $ret = (int) (
dol_now(
'gmt') + ($offsettz + $offsetdst));
4294 global $conf, $langs;
4297 if (!empty($conf->dol_optimize_smallscreen)) {
4302 if (empty($shortvalue) || $size < ($level * 10)) {
4304 $textunitshort = $langs->trans(
"b");
4305 $textunitlong = $langs->trans(
"Bytes");
4307 $ret = round($size / $level, 0);
4308 $textunitshort = $langs->trans(
"Kb");
4309 $textunitlong = $langs->trans(
"KiloBytes");
4312 if (empty($shortunit)) {
4313 $ret .=
' ' . $textunitlong;
4315 $ret .=
' ' . $textunitshort;
4331function dol_print_url($url, $target =
'_blank', $max = 32, $withpicto = 0, $morecss =
'')
4339 $linkstart =
'<a href="';
4340 if (!preg_match(
'/^http/i', $url)) {
4341 $linkstart .=
'http://';
4346 $linkstart .=
' target="' . $target .
'"';
4348 $linkstart .=
' title="' . $langs->trans(
"URL") .
': ' . $url .
'"';
4352 if (!preg_match(
'/^http/i', $url)) {
4359 if ($morecss ==
'float') {
4360 return '<div class="nospan' . ($morecss ?
' ' . $morecss :
'') .
'" style="margin-right: 10px">' . ($withpicto ?
img_picto($langs->trans(
"Url"),
'globe',
'class="paddingrightonly"') :
'') . $link .
'</div>';
4362 return $linkstart .
'<span class="nospan' . ($morecss ?
' ' . $morecss :
'') .
'" style="margin-right: 10px">' . ($withpicto ?
img_picto(
'',
'globe',
'class="paddingrightonly"') :
'') . $link .
'</span>' . $linkend;
4379function dol_print_email($email, $contactid = 0, $socid = 0, $addlink = 0, $max = 0, $showinvalid = 2, $withpicto = 0, $morecss =
'paddingrightonly')
4381 global $user, $langs, $hookmanager;
4392 if (empty($email)) {
4396 if ($addlink == 1) {
4397 $newemail =
'<a class="' . ($morecss ? $morecss :
'') .
'" style="text-overflow: ellipsis;" href="';
4398 if (!preg_match(
'/^mailto:/i', $email)) {
4399 $newemail .=
'mailto:';
4401 $newemail .= $email;
4402 $newemail .=
'" target="_blank">';
4404 $newemail .= ($withpicto ?
img_picto($langs->trans(
"EMail") .
' : ' . $email, (is_numeric($withpicto) ?
'email' : $withpicto),
'class="paddingrightonly"') :
'');
4409 $newemail .= $email;
4411 $newemail .=
'</a>';
4414 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
4415 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
4418 $langs->load(
"errors");
4419 $newemail .=
img_warning($langs->transnoentitiesnoconv(
"ErrorBadEMail", $emailonly),
'',
'paddingrightonly');
4421 $langs->load(
"errors");
4422 $newemail .=
img_warning($langs->transnoentitiesnoconv(
"ErrorBadMXDomain", $emailonly),
'',
'paddingrightonly');
4426 if (($contactid || $socid) &&
isModEnabled(
'agenda') && $user->hasRight(
"agenda",
"myactions",
"create")) {
4428 $linktoaddaction =
'';
4430 $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>';
4432 if ($linktoaddaction) {
4433 $newemail =
'<div>' . $newemail .
' ' . $linktoaddaction .
'</div>';
4436 } elseif ($addlink ===
'thirdparty') {
4437 $tmpnewemail =
'<a class="' . ($morecss ? $morecss :
'') .
'" style="text-overflow: ellipsis;" href="' . DOL_URL_ROOT .
'/societe/card.php?socid=' . $socid .
'&action=presend&mode=init#formmailbeforetitle">';
4438 $tmpnewemail .= ($withpicto ?
img_picto($langs->trans(
"EMail") .
' : ' . $email, (is_numeric($withpicto) ?
'email' : $withpicto),
'class="paddingrightonly"') :
'');
4439 if ($withpicto == 1) {
4440 $tmpnewemail .= $newemail;
4442 $tmpnewemail .=
'</a>';
4444 $newemail = $tmpnewemail;
4446 $newemail = ($withpicto ?
img_picto($langs->trans(
"EMail") .
' : ' . $email, (is_numeric($withpicto) ?
'email' : $withpicto),
'class="paddingrightonly"') :
'') . $newemail;
4449 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
4450 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
4453 $langs->load(
"errors");
4454 $newemail .=
img_warning($langs->transnoentitiesnoconv(
"ErrorBadEMail", $email));
4456 $langs->load(
"errors");
4457 $newemail .=
img_warning($langs->transnoentitiesnoconv(
"ErrorBadMXDomain", $emailonly));
4468 $parameters = array(
'cid' => $contactid,
'socid' => $socid,
'addlink' => $addlink,
'picto' => $withpicto);
4470 $reshook = $hookmanager->executeHooks(
'printEmail', $parameters, $email);
4474 $rep .= $hookmanager->resPrint;
4489 $socialnetworks = array();
4491 require_once DOL_DOCUMENT_ROOT .
'/core/lib/memory.lib.php';
4495 if (!is_null($dataretrieved)) {
4496 $socialnetworks = $dataretrieved;
4498 $sql =
"SELECT rowid, code, label, url, icon, active FROM " . MAIN_DB_PREFIX .
"c_socialnetworks";
4499 $sql .=
" WHERE entity IN (" .
getEntity(
'c_socialnetworks').
")";
4501 $resql = $db->query($sql);
4503 while ($obj = $db->fetch_object($resql)) {
4504 $socialnetworks[$obj->code] = array(
4505 'rowid' => $obj->rowid,
4506 'label' => $obj->label,
4508 'icon' => $obj->icon,
4509 'active' => $obj->active,
4516 return (is_array($socialnetworks) ? $socialnetworks : array());
4531 global $hookmanager, $langs, $user;
4535 if (empty($value)) {
4539 if (!empty($type)) {
4540 $htmllink =
'<div class="divsocialnetwork inline-block valignmiddle">';
4542 $htmllink .=
'<span class="fab pictofixedwidth ' . ($dictsocialnetworks[$type][
'icon'] ? $dictsocialnetworks[$type][
'icon'] :
'fa-link') .
'"></span>';
4543 if ($type ==
'skype') {
4545 $htmllink .=
' <a href="skype:';
4547 $htmllink .=
'?call" alt="' . $langs->trans(
"Call") .
' ' . $value .
'" title="' .
dol_escape_htmltag($langs->trans(
"Call") .
' ' . $value) .
'">';
4548 $htmllink .=
'<img src="' . DOL_URL_ROOT .
'/theme/common/skype_callbutton.png" border="0">';
4549 $htmllink .=
'</a><a href="skype:';
4551 $htmllink .=
'?chat" alt="' . $langs->trans(
"Chat") .
' ' . $value .
'" title="' .
dol_escape_htmltag($langs->trans(
"Chat") .
' ' . $value) .
'">';
4552 $htmllink .=
'<img class="paddingleft" src="' . DOL_URL_ROOT .
'/theme/common/skype_chatbutton.png" border="0">';
4553 $htmllink .=
'</a>';
4554 if (($contactid || $socid) &&
isModEnabled(
'agenda') && $user->hasRight(
'agenda',
'myactions',
'create')) {
4555 $addlink =
'AC_SKYPE';
4558 $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>';
4560 $htmllink .= ($link ?
' ' . $link :
'');
4563 if (!empty($dictsocialnetworks[$type][
'url'])) {
4564 $tmpvirginurl = preg_replace(
'/\/?{socialid}/',
'', $dictsocialnetworks[$type][
'url']);
4565 if ($tmpvirginurl) {
4566 $value = preg_replace(
'/^www\.' . preg_quote($tmpvirginurl,
'/') .
'\/?/',
'', $value);
4567 $value = preg_replace(
'/^' . preg_quote($tmpvirginurl,
'/') .
'\/?/',
'', $value);
4569 $tmpvirginurl3 = preg_replace(
'/^https:\/\//i',
'https://www.', $tmpvirginurl);
4570 if ($tmpvirginurl3) {
4571 $value = preg_replace(
'/^www\.' . preg_quote($tmpvirginurl3,
'/') .
'\/?/',
'', $value);
4572 $value = preg_replace(
'/^' . preg_quote($tmpvirginurl3,
'/') .
'\/?/',
'', $value);
4575 $tmpvirginurl2 = preg_replace(
'/^https?:\/\//i',
'', $tmpvirginurl);
4576 if ($tmpvirginurl2) {
4577 $value = preg_replace(
'/^www\.' . preg_quote($tmpvirginurl2,
'/') .
'\/?/',
'', $value);
4578 $value = preg_replace(
'/^' . preg_quote($tmpvirginurl2,
'/') .
'\/?/',
'', $value);
4581 if (preg_match(
'/^https?:\/\//i', $value)) {
4584 $link = str_replace(
'{socialid}', $value, $dictsocialnetworks[$type][
'url']);
4586 $valuetoshow = $value;
4587 $valuetoshow = preg_replace(
'/https:\/\/www\.(twitter|x|linkedin)\.com\/?/',
'', $valuetoshow);
4588 if (preg_match(
'/^https?:\/\//i', $link)) {
4597 $htmllink .=
'</div>';
4599 $langs->load(
"errors");
4600 $htmllink .=
img_warning($langs->trans(
"ErrorBadSocialNetworkValue", $value));
4604 $parameters = array(
4606 'cid' => $contactid,
4609 'dictsocialnetworks' => $dictsocialnetworks,
4612 $reshook = $hookmanager->executeHooks(
'printSocialNetworks', $parameters);
4616 $htmllink .= $hookmanager->resPrint;
4631function dol_print_profids($profID, $profIDtype, $countrycode =
'', $addcpButton = 1)
4635 if (empty($profID) || empty($profIDtype)) {
4638 if (empty($countrycode)) {
4639 $countrycode =
$mysoc->country_code;
4641 $newProfID = $profID;
4642 $id = substr($profIDtype, -1);
4644 if (strtoupper($countrycode) ==
'FR') {
4650 $newProfID = substr($newProfID, 0, 3) .
' ' . substr($newProfID, 3, 3) .
' ' . substr($newProfID, 6, 3);
4654 $newProfID = substr($newProfID, 0, 3) .
' ' . substr($newProfID, 3, 3) .
' ' . substr($newProfID, 6, 3) .
' ' . substr($newProfID, 9, 5);
4658 $newProfID = substr($newProfID, 0, 2) .
'.' . substr($newProfID, 2, 3);
4660 if ($profIDtype ===
'VAT' &&
dol_strlen($newProfID) == 13) {
4662 $newProfID = substr($newProfID, 0, 4) .
' ' . substr($newProfID, 4, 3) .
' ' . substr($newProfID, 7, 3) .
' ' . substr($newProfID, 10, 3);
4665 if (!empty($addcpButton)) {
4688function dol_print_phone($phone, $countrycode =
'', $contactid = 0, $socid = 0, $addlink =
'', $separ =
" ", $withpicto =
'', $titlealt =
'', $adddivfloat = 0, $morecss =
'paddingright')
4690 global $conf, $user, $langs,
$mysoc, $hookmanager;
4693 $phone = is_null($phone) ?
'' : preg_replace(
"/[\s.-]/",
"", trim($phone));
4694 if (empty($phone)) {
4700 if (empty($countrycode) && is_object(
$mysoc)) {
4701 $countrycode =
$mysoc->country_code;
4705 if (!empty($conf->dol_optimize_smallscreen) && $separ !=
'hidenum') {
4710 $newphonewa = $phone;
4711 if (strtoupper($countrycode) ==
"FR") {
4714 $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);
4716 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 2) . $separ . substr($newphone, 5, 2);
4718 $newphone = substr($newphone, 0, 2) . $separ . substr($newphone, 2, 3) . $separ . substr($newphone, 5, 2) . $separ . substr($newphone, 7, 2);
4720 $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);
4722 $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);
4724 $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);
4726 } elseif (strtoupper($countrycode) ==
"CA") {
4728 $newphone = ($separ !=
'' ?
'(' :
'') . substr($newphone, 0, 3) . ($separ !=
'' ?
')' :
'') . $separ . substr($newphone, 3, 3) . ($separ !=
'' ?
'-' :
'') . substr($newphone, 6, 4);
4730 } elseif (strtoupper($countrycode) ==
"PT") {
4732 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
4734 } elseif (strtoupper($countrycode) ==
"SR") {
4736 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3);
4738 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 4);
4740 } elseif (strtoupper($countrycode) ==
"DE") {
4742 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4) . $separ . substr($newphone, 7, 4) . $separ . substr($newphone, 11, 3);
4744 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 4) . $separ . substr($newphone, 10, 3);
4746 } elseif (strtoupper($countrycode) ==
"ES") {
4748 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
4750 } elseif (strtoupper($countrycode) ==
"BF") {
4752 $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);
4754 } elseif (strtoupper($countrycode) ==
"RO") {
4756 $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);
4758 } elseif (strtoupper($countrycode) ==
"TR") {
4760 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 4);
4762 } elseif (strtoupper($countrycode) ==
"US") {
4764 $newphone = substr($newphone, 0, 2) . $separ . substr($newphone, 2, 3) . $separ . substr($newphone, 5, 3) . $separ . substr($newphone, 8, 4);
4766 } elseif (strtoupper($countrycode) ==
"MX") {
4768 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 2);
4770 $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);
4772 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 4);
4774 } elseif (strtoupper($countrycode) ==
"ML") {
4776 $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);
4778 } elseif (strtoupper($countrycode) ==
"TH") {
4780 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 3);
4782 $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);
4784 } elseif (strtoupper($countrycode) ==
"MU") {
4787 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 2) . $separ . substr($newphone, 9, 2);
4789 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 4) . $separ . substr($newphone, 8, 2) . $separ . substr($newphone, 10, 2);
4791 } elseif (strtoupper($countrycode) ==
"ZA") {
4793 $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);
4795 } elseif (strtoupper($countrycode) ==
"SY") {
4797 $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);
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, 3);
4801 } elseif (strtoupper($countrycode) ==
"AE") {
4803 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 2);
4805 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
4807 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 4);
4809 } elseif (strtoupper($countrycode) ==
"DZ") {
4811 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
4813 } elseif (strtoupper($countrycode) ==
"BE") {
4815 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 3);
4817 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
4819 } elseif (strtoupper($countrycode) ==
"PF") {
4821 $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);
4823 } elseif (strtoupper($countrycode) ==
"CO") {
4825 $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);
4827 } elseif (strtoupper($countrycode) ==
"JO") {
4829 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 1) . $separ . substr($newphone, 5, 3) . $separ . substr($newphone, 8, 2) . $separ . substr($newphone, 10, 2);
4831 } elseif (strtoupper($countrycode) ==
"JM") {
4833 $newphone = substr($newphone, 0, 5) . $separ . substr($newphone, 5, 3) . $separ . substr($newphone, 8, 4);
4835 } elseif (strtoupper($countrycode) ==
"MG") {
4837 $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);
4839 } elseif (strtoupper($countrycode) ==
"GB") {
4841 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
4843 } elseif (strtoupper($countrycode) ==
"CH") {
4845 $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);
4847 $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);
4849 } elseif (strtoupper($countrycode) ==
"TN") {
4851 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 2) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
4853 } elseif (strtoupper($countrycode) ==
"GF") {
4855 $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);
4857 } elseif (strtoupper($countrycode) ==
"GP") {
4859 $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);
4861 } elseif (strtoupper($countrycode) ==
"MQ") {
4863 $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);
4865 } elseif (strtoupper($countrycode) ==
"IT") {
4867 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
4869 $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);
4871 } elseif (strtoupper($countrycode) ==
"AU") {
4875 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 1) . $separ . substr($newphone, 4, 4) . $separ . substr($newphone, 8, 4);
4877 } elseif (strtoupper($countrycode) ==
"LU") {
4880 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 2) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 2);
4882 $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);
4884 $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);
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) ==
"PE") {
4891 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4);
4893 $newphonewa =
'+51' . $newphone;
4894 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3);
4896 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 4);
4898 $newphonewa = $newphone;
4899 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
4901 } elseif (strtoupper($countrycode) ==
"IN") {
4903 if ($withpicto ==
'phone') {
4904 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 2) . $separ . substr($newphone, 5, 4) . $separ . substr($newphone, 9, 4);
4906 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 5) . $separ . substr($newphone, 8, 5);
4911 $newphoneastart = $newphoneaend =
'';
4912 if (!empty($addlink)) {
4913 if ($addlink ==
'tel' || $conf->browser->layout ==
'phone' || (
isModEnabled(
'clicktodial') &&
getDolGlobalString(
'CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS'))) {
4914 $newphoneastart =
'<a href="tel:' . urlencode($phone) .
'">';
4915 $newphoneaend .=
'</a>';
4916 } elseif (
isModEnabled(
'clicktodial') && $addlink ==
'AC_TEL') {
4917 if (empty($user->clicktodial_loaded)) {
4918 $user->fetch_clicktodial();
4922 $urlmask =
getDolGlobalString(
'CLICKTODIAL_URL',
'ErrorClickToDialModuleNotConfigured');
4923 if (!empty($user->clicktodial_url)) {
4924 $urlmask = $user->clicktodial_url;
4927 $clicktodial_poste = (!empty($user->clicktodial_poste) ? urlencode($user->clicktodial_poste) :
'');
4928 $clicktodial_login = (!empty($user->clicktodial_login) ? urlencode($user->clicktodial_login) :
'');
4929 $clicktodial_password = (!empty($user->clicktodial_password) ? urlencode($user->clicktodial_password) :
'');
4931 $url = sprintf($urlmask, urlencode($phone), $clicktodial_poste, $clicktodial_login, $clicktodial_password);
4933 $substitarray = array(
4934 '__PHONEFROM__' => $clicktodial_poste,
4935 '__PHONETO__' => urlencode($phone),
4936 '__LOGIN__' => $clicktodial_login,
4937 '__PASS__' => $clicktodial_password
4942 $newphoneastart =
'<a href="' . $url .
'" class="cssforclicktodial">';
4943 $newphoneaend =
'</a>';
4946 $newphoneastart =
'<a href="' . $url .
'"';
4948 $newphoneastart .=
' target="_blank" rel="noopener noreferrer"';
4950 $newphoneastart .=
'>';
4951 $newphoneaend .=
'</a>';
4956 if (
isModEnabled(
'agenda') && $user->hasRight(
"agenda",
"myactions",
"create")) {
4958 $addlinktoagenda =
'';
4959 if ($addlink ==
'AC_FAX') {
4963 $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>';
4965 if ($addlinktoagenda) {
4966 $newphone =
'<span>' . $newphone .
' ' . $addlinktoagenda .
'</span>';
4971 if (
getDolGlobalString(
'CONTACT_PHONEMOBILE_SHOW_LINK_TO_WHATSAPP') && $withpicto ==
'mobile') {
4973 $newphone .=
' <a href="https://wa.me/' . $newphonewa .
'" target="_blank"';
4974 $newphone .=
'><span class="paddingright fab fa-whatsapp" style="color:#25D366;" title="WhatsApp"></span></a>';
4977 if (empty($titlealt)) {
4978 $titlealt = ($withpicto ==
'fax' ? $langs->trans(
"Fax") : $langs->trans(
"Phone"));
4983 $parameters = array(
'countrycode' => $countrycode,
'cid' => $contactid,
'socid' => $socid,
'titlealt' => $titlealt,
'picto' => $withpicto);
4984 $reshook = $hookmanager->executeHooks(
'printPhone', $parameters, $phone);
4985 $rep .= $hookmanager->resPrint;
4987 if (empty($reshook)) {
4990 if ($withpicto ==
'fax') {
4991 $picto =
'phoning_fax';
4992 } elseif ($withpicto ==
'phone') {
4994 } elseif ($withpicto ==
'mobile') {
4995 $picto =
'phoning_mobile';
5000 if ($adddivfloat == 1) {
5001 $rep .=
'<div class="nospan float' . ($morecss ?
' ' . $morecss :
'') .
'">';
5002 } elseif (empty($adddivfloat)) {
5003 $rep .=
'<span' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
'>';
5006 $rep .= $newphoneastart;
5007 $rep .= ($withpicto ?
img_picto($titlealt, $picto) :
'');
5008 if ($separ !=
'hidenum') {
5009 $rep .= ($withpicto ?
' ' :
'') . $newphone;
5011 $rep .= $newphoneaend;
5013 if ($adddivfloat == 1) {
5015 } elseif (empty($adddivfloat)) {
5036 if (!isset($conf->cache[
'resolveips'])) {
5037 $conf->cache[
'resolveips'] = array();
5043 if (file_exists(DOL_DOCUMENT_ROOT .
'/theme/common/flags/' . $countrycode .
'.png')) {
5046 $ret .=
'(' . $countrycode .
')';
5054 if (in_array($mode, [0, 2])) {
5057 if (!array_key_exists($ip, $conf->cache[
'resolveips'])) {
5058 $domain = gethostbyaddr($ip);
5059 $conf->cache[
'resolveips'][$ip] = $domain;
5061 $domain = $conf->cache[
'resolveips'][$ip];
5089 $ip = (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']);
5096 if (empty($_SERVER[
'HTTP_X_FORWARDED_FOR']) || preg_match(
'/[^0-9\.\:,\[\]\s]/', $_SERVER[
'HTTP_X_FORWARDED_FOR'])) {
5097 if (empty($_SERVER[
'HTTP_CLIENT_IP']) || preg_match(
'/[^0-9\.\:,\[\]\s]/', $_SERVER[
'HTTP_CLIENT_IP'])) {
5098 if (empty($_SERVER[
"HTTP_CF_CONNECTING_IP"])) {
5099 $ip = (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']);
5101 $ip = $_SERVER[
"HTTP_CF_CONNECTING_IP"];
5104 $ip = preg_replace(
'/,.*$/',
'', $_SERVER[
'HTTP_CLIENT_IP']);
5107 $ip = preg_replace(
'/,.*$/',
'', $_SERVER[
'HTTP_X_FORWARDED_FOR']);
5123 if (isset($_SERVER[
'HTTPS']) && $_SERVER[
'HTTPS'] ==
'on') {
5125 } 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') {
5146 $datafile = $diroffile .
'/' .
getDolGlobalString(
'GEOIPMAXMIND_COUNTRY_DATAFILE_EMBEDDED');
5152 include_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeoip.class.php';
5153 $geoip =
new DolGeoIP(
'country', $datafile);
5155 $countrycode = $geoip->getCountryCodeFromIP($ip);
5162 return $countrycode;
5174 global $conf, $langs, $user;
5183 include_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeoip.class.php';
5184 $geoip =
new DolGeoIP(
'country', $datafile);
5185 $countrycode = $geoip->getCountryCodeFromIP($ip);
5186 $ret = $countrycode;
5205 global $hookmanager;
5211 $parameters = array(
'element' => $element,
'id' =>
$id);
5212 $reshook = $hookmanager->executeHooks(
'printAddress', $parameters, $address);
5213 $out .= $hookmanager->resPrint;
5215 if (empty($reshook)) {
5216 if (empty($charfornl)) {
5217 $out .= nl2br((
string) $address);
5219 $out .= preg_replace(
'/[\r\n]+/', $charfornl, (
string) $address);
5223 $showgmap = $showomap = 0;
5249 $url =
dol_buildpath(
'/google/gmaps.php?mode=' . $element .
'&id=' .
$id, 1);
5250 $out .=
' <a href="' . $url .
'" target="_gmaps"><img id="' . $htmlid .
'" class="valigntextbottom" src="' . DOL_URL_ROOT .
'/theme/common/gmap.png"></a>';
5253 $url =
dol_buildpath(
'/openstreetmap/maps.php?mode=' . $element .
'&id=' .
$id, 1);
5254 $out .=
' <a href="' . $url .
'" target="_gmaps"><img id="' . $htmlid .
'_openstreetmap" class="valigntextbottom" src="' . DOL_URL_ROOT .
'/theme/common/gmap.png"></a>';
5276function isValidEmail($address, $acceptsupervisorkey = 0, $acceptuserkey = 0)
5278 if ($acceptsupervisorkey && $address ==
'__SUPERVISOREMAIL__') {
5281 if ($acceptuserkey && $address ==
'__USER_EMAIL__') {
5284 if (filter_var($address, FILTER_VALIDATE_EMAIL)) {
5302 if (function_exists(
'idn_to_ascii') && function_exists(
'checkdnsrr')) {
5303 if (!checkdnsrr(idn_to_ascii($domain),
'MX')) {
5306 if (function_exists(
'getmxrr')) {
5309 getmxrr(idn_to_ascii($domain), $mxhosts, $weight);
5310 if (count($mxhosts) > 1) {
5313 if (count($mxhosts) == 1 && !in_array((
string) $mxhosts[0], array(
'',
'.'))) {
5350 $tmparray = explode(
' ', $s);
5351 foreach ($tmparray as $tmps) {
5366function dol_strlen($string, $stringencoding =
'UTF-8')
5368 if (is_null($string)) {
5372 if (function_exists(
'mb_strlen')) {
5373 return mb_strlen($string, $stringencoding);
5375 return strlen($string);
5389function dol_substr($string, $start, $length =
null, $stringencoding =
'', $trunconbytes = 0)
5393 if (empty($stringencoding)) {
5394 $stringencoding = (empty($langs) ?
'UTF-8' : $langs->charset_output);
5398 if (empty($trunconbytes)) {
5399 if (function_exists(
'mb_substr')) {
5400 $ret = mb_substr($string, $start, $length, $stringencoding);
5402 $ret = substr($string, $start, $length);
5405 if (function_exists(
'mb_strcut')) {
5406 $ret = mb_strcut($string, $start, $length, $stringencoding);
5408 $ret = substr($string, $start, $length);
5428function dol_trunc($string, $size = 40, $trunc =
'right', $stringencoding =
'UTF-8', $nodot = 0, $display = 0)
5436 if (empty($stringencoding)) {
5437 $stringencoding =
'UTF-8';
5440 if (!empty($conf->dol_optimize_smallscreen) && $conf->dol_optimize_smallscreen == 1 && $display == 1) {
5441 $size = round($size / 3);
5445 if ($trunc ==
'right') {
5447 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
5449 return dol_substr($newstring, 0, $size, $stringencoding) . ($nodot ?
'' :
'…');
5454 } elseif ($trunc ==
'middle') {
5456 if (
dol_strlen($newstring, $stringencoding) > 2 &&
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
5457 $size1 = (int) round($size / 2);
5458 $size2 = (int) round($size / 2);
5459 return dol_substr($newstring, 0, $size1, $stringencoding) .
'…' .
dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size2, $size2, $stringencoding);
5463 } elseif ($trunc ==
'left') {
5465 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
5467 return '…' .
dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size, $size, $stringencoding);
5471 } elseif ($trunc ==
'wrap') {
5473 if (
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
5479 return 'BadParam3CallingDolTrunc';
5493 $type2picto = array(
5494 'varchar' =>
'font',
5497 'int' =>
'sort-numeric-down',
5498 'double' =>
'sort-numeric-down',
5499 'price' =>
'currency',
5500 'pricecy' =>
'multicurrency',
5501 'password' =>
'key',
5502 'boolean' =>
'check-square',
5503 'date' =>
'calendar',
5504 'datetime' =>
'calendar',
5505 'duration' =>
'hourglass',
5511 'sellist' =>
'list',
5512 'stars' =>
'fontawesome_star_fas',
5513 'radio' =>
'check-circle',
5514 'checkbox' =>
'list',
5515 'chkbxlst' =>
'list',
5517 'icon' =>
"question",
5518 'point' =>
"country",
5519 'multipts' =>
'country',
5520 'linestrg' =>
"country",
5521 'polygon' =>
"country",
5522 'separate' =>
'minus'
5525 if (!empty($type2picto[$key])) {
5526 return img_picto(
'', $type2picto[$key],
'class="pictofixedwidth' . ($morecss ?
' ' . $morecss :
'') .
'"');
5529 return img_picto(
'',
'generic',
'class="pictofixedwidth' . ($morecss ?
' ' . $morecss :
'') .
'"');
5556function img_picto($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $srconly = 0, $notitle = 0, $alt =
'', $morecss =
'', $marginleftonlyshort = 2, $allowothertags = array())
5561 $url = DOL_URL_ROOT;
5562 $theme = isset($conf->theme) ? $conf->theme :
null;
5563 $path =
'theme/' . $theme;
5564 if (empty($picto)) {
5569 $titlealt = str_replace(array(
'\n',
"\n"),
' - ', $titlealt);
5573 if ($pictoisfullpath) {
5575 if (!preg_match(
'/(\.png|\.gif|\.svg)$/i', $picto)) {
5578 $fullpathpicto = $picto;
5580 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
5581 $morecss .= ($morecss ?
' ' :
'') . $reg[1];
5582 $moreatt = str_replace(
'class="' . $reg[1] .
'"',
'', $moreatt);
5587 $pictowithouttext = preg_replace(
'/(\.png|\.gif|\.svg)$/',
'', $picto);
5588 $pictowithouttext = str_replace(
'object_',
'', $pictowithouttext);
5589 $pictowithouttext = str_replace(
'_nocolor',
'', $pictowithouttext);
5592 $pictoconvertkey = array(
5593 'facture' =>
'bill',
5594 'shipping' =>
'shipment',
5595 'fichinter' =>
'intervention',
5596 'agenda' =>
'calendar',
5597 'invoice_supplier' =>
'supplier_invoice',
5598 'order_supplier' =>
'supplier_order');
5599 if (in_array($pictowithouttext, array_keys($pictoconvertkey))) {
5600 $pictowithouttext = $pictoconvertkey[$pictowithouttext];
5603 if (strpos($pictowithouttext,
'fontawesome_') === 0 || strpos($pictowithouttext,
'fa-') === 0) {
5605 $pictowithouttext = str_replace(
'fontawesome_',
'', $pictowithouttext);
5606 $pictowithouttext = str_replace(
'fa-',
'', $pictowithouttext);
5609 if ($pictowithouttext ==
'file-o') {
5610 $pictowithouttext =
'file';
5613 $pictowithouttextarray = explode(
'_', $pictowithouttext);
5614 $marginleftonlyshort = 0;
5616 if (!empty($pictowithouttextarray[1])) {
5618 $fakey =
'fa-' . $pictowithouttextarray[0];
5619 $faprefix = empty($pictowithouttextarray[1]) ?
'fas' : $pictowithouttextarray[1];
5620 $facolor = empty($pictowithouttextarray[2]) ?
'' : $pictowithouttextarray[2];
5621 $fasize = empty($pictowithouttextarray[3]) ?
'' : $pictowithouttextarray[3];
5623 $fakey =
'fa-' . $pictowithouttext;
5633 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
5634 $morecss .= ($morecss ?
' ' :
'') . $reg[1];
5635 $moreatt = str_replace(
'class="' . $reg[1] .
'"',
'', $moreatt);
5637 if (preg_match(
'/style="([^"]+)"/', $moreatt, $reg)) {
5638 $morestyle = $reg[1];
5639 $moreatt = str_replace(
'style="' . $reg[1] .
'"',
'', $moreatt);
5641 $moreatt = trim($moreatt);
5643 $enabledisablehtml =
'<span class="' . $faprefix .
' ' . $fakey . ($marginleftonlyshort ? ($marginleftonlyshort == 1 ?
' marginleftonlyshort' :
' marginleftonly') :
'');
5644 $enabledisablehtml .= ($morecss ?
' ' . $morecss :
'') .
'" style="' . ($fasize ? (
'font-size: ' . $fasize .
';') :
'') . ($facolor ? (
' color: ' . $facolor .
';') :
'') . ($morestyle ?
' ' . $morestyle :
'') .
'"' . (($notitle || empty($titlealt)) ?
'' :
' title="' .
dol_escape_htmltag($titlealt) .
'"') . ($moreatt ?
' ' . $moreatt :
'') .
'>';
5645 $enabledisablehtml .=
'</span>';
5647 return $enabledisablehtml;
5650 if (empty($srconly) && !preg_match(
'/[\.\/@]/', $picto)) {
5651 $fakey = $pictowithouttext;
5655 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'))) {
5658 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'))) {
5664 if ($pictowithouttext ==
'off') {
5665 $fakey =
'fa-square';
5667 } elseif ($pictowithouttext ==
'on') {
5668 $fakey =
'fa-check-square';
5670 } elseif ($pictowithouttext ==
'listlight') {
5671 $fakey =
'fa-download';
5672 $marginleftonlyshort = 1;
5673 } elseif ($pictowithouttext ==
'printer') {
5674 $fakey =
'fa-print';
5676 } elseif ($pictowithouttext ==
'note') {
5677 $fakey =
'fa-sticky-note';
5678 $marginleftonlyshort = 1;
5679 } elseif (in_array($pictowithouttext, array(
'1uparrow',
'1downarrow',
'1leftarrow',
'1rightarrow',
'1uparrow_selected',
'1downarrow_selected',
'1leftarrow_selected',
'1rightarrow_selected'))) {
5680 $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');
5681 $fakey =
'fa-' . $convertarray[$pictowithouttext];
5682 if (preg_match(
'/selected/', $pictowithouttext)) {
5685 $marginleftonlyshort = 1;
5686 } elseif (!empty($arrayconvpictotofa[$pictowithouttext])) {
5687 $fakey =
'fa-' . $arrayconvpictotofa[$pictowithouttext];
5689 $fakey =
'fa-' . $pictowithouttext;
5692 if (in_array($pictowithouttext, array(
'dollyrevert',
'member',
'members',
'contract',
'group',
'resource',
'shipment',
'reception'))) {
5693 $morecss .=
' em092';
5695 if (in_array($pictowithouttext, array(
'conferenceorbooth',
'eventorganization',
'holiday',
'info',
'info_black',
'project',
'workstation'))) {
5696 $morecss .=
' em088';
5698 if (in_array($pictowithouttext, array(
'asset',
'intervention',
'payment',
'loan',
'partnership',
'stock',
'technic'))) {
5699 $morecss .=
' em080';
5703 $arrayconvpictotomarginleftonly = array(
5733 '1uparrow_selected',
5734 '1downarrow_selected',
5735 '1leftarrow_selected',
5736 '1rightarrow_selected'
5738 if (!array_key_exists($pictowithouttext, $arrayconvpictotomarginleftonly)) {
5739 $marginleftonlyshort = 0;
5743 $arrayconvpictotomorcess = array(
5744 'action' =>
'infobox-action',
5745 'account' =>
'infobox-bank_account',
5746 'accounting_account' =>
'infobox-bank_account',
5747 'accountline' =>
'infobox-bank_account',
5748 'accountancy' =>
'infobox-bank_account',
5749 'admin' =>
'opacitymedium',
5750 'asset' =>
'infobox-bank_account',
5751 'bank_account' =>
'infobox-bank_account',
5752 'bill' =>
'infobox-commande',
5753 'billa' =>
'infobox-commande',
5754 'billr' =>
'infobox-commande',
5755 'billd' =>
'infobox-commande',
5756 'bookcal' =>
'infobox-portal',
5757 'margin' =>
'infobox-bank_account',
5758 'conferenceorbooth' =>
'infobox-project',
5759 'cash-register' =>
'infobox-portal',
5760 'contract' =>
'infobox-contrat',
5761 'check' =>
'font-status4',
5762 'conversation' =>
'infobox-contrat',
5763 'donation' =>
'infobox-commande',
5764 'dolly' =>
'infobox-commande',
5765 'dollyrevert' =>
'flip infobox-order_supplier',
5766 'ecm' =>
'infobox-action',
5767 'eventorganization' =>
'infobox-project',
5768 'hrm' =>
'infobox-adherent',
5769 'group' =>
'infobox-adherent',
5770 'intervention' =>
'infobox-contrat',
5771 'incoterm' =>
'infobox-supplier_proposal',
5772 'intracommreport' =>
'infobox-bank_account',
5773 'currency' =>
'infobox-bank_account',
5774 'multicurrency' =>
'infobox-bank_account',
5775 'members' =>
'infobox-adherent',
5776 'member' =>
'infobox-adherent',
5777 'money-bill-alt' =>
'infobox-bank_account',
5778 'order' =>
'infobox-commande',
5779 'user' =>
'infobox-adherent',
5780 'users' =>
'infobox-adherent',
5781 'error' =>
'pictoerror',
5782 'warning' =>
'pictowarning',
5783 'switch_on' =>
'font-status4',
5784 'switch_on_warning' =>
'font-status4 warning',
5785 'switch_on_red' =>
'font-status8',
5786 'switch_off_warning' =>
'font-status4 warning',
5787 'switch_off_red' =>
'font-status8',
5788 'holiday' =>
'infobox-holiday',
5789 'info' =>
'opacityhigh',
5790 'info_black' =>
'purple',
5791 'invoice' =>
'infobox-commande',
5792 'knowledgemanagement' =>
'infobox-contrat rotate90',
5793 'loan' =>
'infobox-commande',
5794 'payment' =>
'infobox-bank_account',
5795 'payment_vat' =>
'infobox-bank_account',
5796 'poll' =>
'infobox-portal',
5797 'pos' =>
'infobox-bank_account',
5798 'project' =>
'infobox-project',
5799 'projecttask' =>
'infobox-project',
5800 'propal' =>
'infobox-propal',
5801 'proposal' =>
'infobox-propal',
5802 'private' =>
'infobox-project',
5803 'reception' =>
'flip infobox-order_supplier',
5804 'recruitmentjobposition' =>
'infobox-adherent',
5805 'recruitmentcandidature' =>
'infobox-adherent',
5806 'resource' =>
'infobox-action',
5807 'salary' =>
'infobox-commande',
5808 'shapes' =>
'infobox-adherent',
5809 'shipment' =>
'infobox-commande',
5810 'store' =>
'infobox-portal',
5811 'stripe' =>
'infobox-bank_account',
5812 'supplier_invoice' =>
'infobox-order_supplier',
5813 'supplier_invoicea' =>
'infobox-order_supplier',
5814 'supplier_invoiced' =>
'infobox-order_supplier',
5815 'supplier' =>
'infobox-order_supplier',
5816 'supplier_order' =>
'infobox-order_supplier',
5817 'supplier_proposal' =>
'infobox-supplier_proposal',
5818 'ticket' =>
'infobox-contrat',
5819 'title_accountancy' =>
'infobox-bank_account',
5820 'title_hrm' =>
'infobox-holiday',
5821 'expensereport' =>
'infobox-expensereport',
5822 'trip' =>
'infobox-expensereport',
5823 'title_agenda' =>
'infobox-action',
5824 'vat' =>
'infobox-bank_account',
5825 'webportal' =>
'infobox-portal',
5827 'list-alt' =>
'imgforviewmode',
5828 'calendar' =>
'imgforviewmode',
5829 'calendarweek' =>
'imgforviewmode',
5830 'calendarmonth' =>
'imgforviewmode',
5831 'calendarday' =>
'imgforviewmode',
5832 'calendarperuser' =>
'imgforviewmode',
5833 'calendarpertype' =>
'imgforviewmode'
5835 if (!empty($arrayconvpictotomorcess[$pictowithouttext]) && strpos($picto,
'_nocolor') ===
false) {
5836 $morecss .= ($morecss ?
' ' :
'') . $arrayconvpictotomorcess[$pictowithouttext];
5840 $arrayconvpictotocolor = array(
5841 'address' =>
'#6c6aa8',
5842 'building' =>
'#6c6aa8',
5846 'companies' =>
'#6c6aa8',
5847 'company' =>
'#6c6aa8',
5848 'contact' =>
'#6c6aa8',
5850 'dynamicprice' =>
'#a69944',
5855 'listlight' =>
'#999',
5856 'language' =>
'#555',
5860 'map-marker-alt' =>
'#aaa',
5862 'product' =>
'#a69944',
5863 'service' =>
'#a69944',
5864 'inventory' =>
'#a69944',
5865 'stock' =>
'#a69944',
5866 'movement' =>
'#a69944',
5868 'world' =>
'#986c6a',
5869 'partnership' =>
'#6c6aa8',
5870 'playdisabled' =>
'#ccc',
5871 'printer' =>
'#444',
5872 'projectpub' =>
'#986c6a',
5876 'search-plus' =>
'#808080',
5877 'security' =>
'#999',
5879 'stop-circle' =>
'#888',
5881 'superadmin' =>
'#600',
5882 'switch_off' =>
'#999',
5883 'technic' =>
'#999',
5885 'timespent' =>
'#555',
5886 'uncheck' =>
'#800',
5887 'uparrow' =>
'#555',
5888 'user-cog' =>
'#999',
5889 'country' =>
'#aaa',
5890 'globe-americas' =>
'#aaa',
5893 'website' =>
'#304',
5894 'workstation' =>
'#a69944'
5896 if (isset($arrayconvpictotocolor[$pictowithouttext]) && strpos($picto,
'_nocolor') ===
false) {
5897 $facolor = $arrayconvpictotocolor[$pictowithouttext];
5904 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
5905 $morecss .= ($morecss ?
' ' :
'') . $reg[1];
5906 $moreatt = str_replace(
'class="' . $reg[1] .
'"',
'', $moreatt);
5908 if (preg_match(
'/style="([^"]+)"/', $moreatt, $reg)) {
5909 $morestyle = $reg[1];
5910 $moreatt = str_replace(
'style="' . $reg[1] .
'"',
'', $moreatt);
5912 $moreatt = trim($moreatt);
5914 $enabledisablehtml =
'<span class="' . $fa .
' ' . $fakey . ($marginleftonlyshort ? ($marginleftonlyshort == 1 ?
' marginleftonlyshort' :
' marginleftonly') :
'');
5915 $enabledisablehtml .= ($morecss ?
' ' . $morecss :
'') .
'" style="' . ($fasize ? (
'font-size: ' . $fasize .
';') :
'') . ($facolor ? (
' color: ' . $facolor .
';') :
'') . ($morestyle ?
' ' . $morestyle :
'') .
'"' . (($notitle || empty($titlealt)) ?
'' :
' title="' .
dol_escape_htmltag($titlealt) .
'"') . ($moreatt ?
' ' . $moreatt :
'') .
'>';
5916 $enabledisablehtml .=
'</span>';
5918 return $enabledisablehtml;
5925 } elseif (!empty($conf->modules_parts[
'theme']) && array_key_exists($theme, $conf->modules_parts[
'theme'])) {
5926 $path = $theme .
'/theme/' . $theme;
5931 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $picto, $regs)) {
5937 if (!preg_match(
'/(\.png|\.gif|\.svg)$/i', $picto)) {
5942 foreach ($conf->file->dol_document_root as $type => $dirroot) {
5943 if ($type ==
'main') {
5947 if (file_exists($dirroot .
'/' . $path .
'/img/' . $picto) && !empty($conf->file->dol_url_root)) {
5948 $url = DOL_URL_ROOT . $conf->file->dol_url_root[$type];
5954 $fullpathpicto = $url .
'/' . $path .
'/img/' . $picto;
5958 return $fullpathpicto;
5962 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 :
'') .
'"') .
'>';
5976 if (empty($mode) || $mode ==
'fa') {
5978 $arrayconvpictotofa = array(
5979 'account' =>
'university',
5980 'accounting_account' =>
'clipboard-list',
5981 'accountline' =>
'receipt',
5982 'accountancy' =>
'search-dollar',
5983 'action' =>
'calendar-alt',
5984 'add' =>
'plus-circle',
5985 'address' =>
'address-book',
5988 'asset' =>
'money-check-alt',
5989 'autofill' =>
'fill',
5990 'back' =>
'arrow-left',
5991 'bank_account' =>
'university',
5992 'bill' =>
'file-invoice-dollar',
5993 'billa' =>
'file-excel',
5994 'billr' =>
'file-invoice-dollar',
5995 'billd' =>
'file-medical',
5996 'blockedlog' =>
'file-archive',
5997 'bookcal' =>
'calendar-check',
5998 'supplier_invoice' =>
'file-invoice-dollar',
5999 'supplier_invoicea' =>
'file-excel',
6000 'supplier_invoicer' =>
'file-invoice-dollar',
6001 'supplier_invoiced' =>
'file-medical',
6003 'card' =>
'address-card',
6004 'chart' =>
'chart-line',
6005 'company' =>
'building',
6006 'contact' =>
'address-book',
6007 'contract' =>
'suitcase',
6008 'collab' =>
'people-arrows',
6009 'conversation' =>
'comments',
6010 'country' =>
'globe-americas',
6011 'cron' =>
'business-time',
6013 'chevron-double-left' =>
'angle-double-left',
6014 'chevron-double-right' =>
'angle-double-right',
6015 'chevron-double-down' =>
'angle-double-down',
6016 'chevron-double-top' =>
'angle-double-up',
6017 'donation' =>
'gift',
6018 'dynamicprice' =>
'hand-holding-usd',
6020 'companies' =>
'building',
6021 'products' =>
'cube',
6022 'commercial' =>
'suitcase',
6023 'invoicing' =>
'coins',
6024 'accounting' =>
'search-dollar',
6025 'category' =>
'tag',
6026 'dollyrevert' =>
'dolly',
6028 'generate' =>
'plus-square',
6029 'hrm' =>
'user-tie',
6030 'incoterm' =>
'truck-loading',
6031 'margin' =>
'calculator',
6032 'members' =>
'user-friends',
6033 'ticket' =>
'ticket-alt',
6034 'globe' =>
'external-link-alt',
6037 'establishment' =>
'building',
6038 'edit' =>
'pencil-alt',
6039 'entity' =>
'globe',
6040 'graph' =>
'chart-line',
6041 'grip_title' =>
'arrows-alt',
6042 'grip' =>
'arrows-alt',
6043 'help' =>
'question-circle',
6044 'generic' =>
'file',
6045 'holiday' =>
'umbrella-beach',
6046 'info' =>
'info-circle',
6047 'info_black' =>
'info-circle',
6048 'inventory' =>
'boxes',
6049 'intracommreport' =>
'globe-europe',
6050 'jobprofile' =>
'cogs',
6051 'knowledgemanagement' =>
'ticket-alt',
6052 'label' =>
'layer-group',
6053 'layout' =>
'columns',
6055 'loan' =>
'money-bill-alt',
6056 'member' =>
'user-alt',
6057 'meeting' =>
'chalkboard-teacher',
6059 'next' =>
'arrow-alt-circle-right',
6061 'expensereport' =>
'wallet',
6063 'movement' =>
'people-carry',
6064 'sign-out' =>
'sign-out-alt',
6065 'superadmin' =>
'star',
6066 'switch_off' =>
'toggle-off',
6067 'switch_off_grey' =>
'toggle-off',
6068 'switch_off_warning' =>
'toggle-off',
6069 'switch_off_red' =>
'toggle-off',
6070 'switch_on' =>
'toggle-on',
6071 'switch_on_grey' =>
'toggle-on',
6072 'switch_on_warning' =>
'toggle-on',
6073 'switch_on_red' =>
'toggle-on',
6075 'bookmark' =>
'star',
6076 'bank' =>
'university',
6077 'close_title' =>
'times',
6078 'delete' =>
'trash',
6079 'filter' =>
'filter',
6080 'list-alt' =>
'list-alt',
6081 'calendarlist' =>
'bars',
6082 'calendar' =>
'calendar-alt',
6083 'calendarmonth' =>
'calendar-alt',
6084 'calendarweek' =>
'calendar-week',
6085 'calendarday' =>
'calendar-day',
6086 'calendarperuser' =>
'table',
6087 'calendarpertype' =>
'table',
6088 'intervention' =>
'ambulance',
6089 'invoice' =>
'file-invoice-dollar',
6090 'order' =>
'file-invoice',
6091 'error' =>
'exclamation-triangle',
6092 'warning' =>
'exclamation-triangle',
6093 'other' =>
'square',
6094 'playdisabled' =>
'play',
6095 'pdf' =>
'file-pdf',
6096 'poll' =>
'check-double',
6097 'pos' =>
'cash-register',
6098 'preview' =>
'binoculars',
6099 'project' =>
'project-diagram',
6100 'projectpub' =>
'project-diagram',
6101 'projecttask' =>
'tasks',
6102 'propal' =>
'file-signature',
6103 'proposal' =>
'file-signature',
6104 'partnership' =>
'handshake',
6105 'payment' =>
'money-check-alt',
6106 'payment_vat' =>
'money-check-alt',
6107 'pictoconfirm' =>
'check-square',
6108 'phoning' =>
'phone',
6109 'phoning_mobile' =>
'mobile-alt',
6110 'phoning_fax' =>
'fax',
6111 'previous' =>
'arrow-alt-circle-left',
6112 'printer' =>
'print',
6113 'product' =>
'cube',
6114 'puce' =>
'angle-right',
6115 'recent' =>
'check-square',
6116 'reception' =>
'dolly',
6117 'recruitmentjobposition' =>
'id-card-alt',
6118 'recruitmentcandidature' =>
'id-badge',
6120 'supplier_order' =>
'dol-order_supplier',
6121 'supplier_proposal' =>
'file-signature',
6122 'refresh' =>
'redo',
6123 'region' =>
'map-marked',
6124 'replacement' =>
'exchange-alt',
6125 'resource' =>
'laptop-house',
6126 'recurring' =>
'history',
6127 'service' =>
'concierge-bell',
6128 'skill' =>
'shapes',
6129 'state' =>
'map-marked-alt',
6130 'security' =>
'key',
6131 'salary' =>
'wallet',
6132 'shipment' =>
'dolly',
6133 'stock' =>
'box-open',
6134 'stats' =>
'chart-bar',
6135 'split' =>
'code-branch',
6136 'status' =>
'stop-circle',
6137 'stripe' =>
'stripe-s',
6138 'supplier' =>
'building',
6139 'technic' =>
'cogs',
6141 'timespent' =>
'clock',
6142 'title_setup' =>
'tools',
6143 'title_accountancy' =>
'money-check-alt',
6144 'title_bank' =>
'university',
6145 'title_hrm' =>
'umbrella-beach',
6146 'title_agenda' =>
'calendar-alt',
6147 'uncheck' =>
'times',
6148 'uparrow' =>
'share',
6149 'url' =>
'external-link-alt',
6150 'vat' =>
'money-check-alt',
6151 'vcard' =>
'arrow-alt-circle-down',
6152 'jabber' =>
'comment',
6153 'website' =>
'globe-americas',
6154 'workstation' =>
'pallet',
6155 'webhook' =>
'bullseye',
6157 'private' =>
'user-lock',
6158 'conferenceorbooth' =>
'chalkboard-teacher',
6159 'eventorganization' =>
'project-diagram',
6160 'webportal' =>
'door-open'
6163 if ($conf->currency ==
'EUR') {
6164 $arrayconvpictotofa[
'currency'] =
'euro-sign';
6165 $arrayconvpictotofa[
'multicurrency'] =
'dollar-sign';
6167 $arrayconvpictotofa[
'currency'] =
'dollar-sign';
6168 $arrayconvpictotofa[
'multicurrency'] =
'euro-sign';
6171 $arrayconvpictotofa = array();
6174 return $arrayconvpictotofa;
6192function img_object($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $srconly = 0, $notitle = 0, $allowothertags = array())
6194 if (strpos($picto,
'^') === 0) {
6195 return img_picto($titlealt, str_replace(
'^',
'', $picto), $moreatt, $pictoisfullpath, $srconly, $notitle,
'',
'', 2, $allowothertags);
6197 return img_picto($titlealt,
'object_' . $picto, $moreatt, $pictoisfullpath, $srconly, $notitle,
'',
'', 2, $allowothertags);
6212function img_weather($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $morecss =
'')
6216 if (is_numeric($picto)) {
6219 return '<i class="fa fa-weather-level' . $picto .
'"></i>';
6220 } elseif (!preg_match(
'/(\.png|\.gif)$/i', $picto)) {
6224 $path = DOL_URL_ROOT .
'/theme/' . $conf->theme .
'/img/weather/' . $picto;
6226 return img_picto($titlealt, $path, $moreatt, 1, 0, 0,
'', $morecss);
6240function img_picto_common($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $notitle = 0)
6244 if (!preg_match(
'/(\.png|\.gif)$/i', $picto)) {
6248 if ($pictoisfullpath) {
6251 $path = DOL_URL_ROOT .
'/theme/common/' . $picto;
6254 $themepath = DOL_DOCUMENT_ROOT .
'/theme/' . $conf->theme .
'/img/' . $picto;
6256 if (file_exists($themepath)) {
6262 return img_picto($titlealt, $path, $moreatt, 1, 0, $notitle);
6278function img_action($titlealt, $numaction, $picto =
'', $moreatt =
'')
6282 if (empty($titlealt) || $titlealt ==
'default') {
6283 if ($numaction ==
'-1' || $numaction ==
'ST_NO') {
6285 $titlealt = $langs->transnoentitiesnoconv(
'ChangeDoNotContact');
6286 } elseif ($numaction ==
'0' || $numaction ==
'ST_NEVER') {
6288 $titlealt = $langs->transnoentitiesnoconv(
'ChangeNeverContacted');
6289 } elseif ($numaction ==
'1' || $numaction ==
'ST_TODO') {
6291 $titlealt = $langs->transnoentitiesnoconv(
'ChangeToContact');
6292 } elseif ($numaction ==
'2' || $numaction ==
'ST_PEND') {
6294 $titlealt = $langs->transnoentitiesnoconv(
'ChangeContactInProcess');
6295 } elseif ($numaction ==
'3' || $numaction ==
'ST_DONE') {
6297 $titlealt = $langs->transnoentitiesnoconv(
'ChangeContactDone');
6299 $titlealt = $langs->transnoentitiesnoconv(
'ChangeStatus ' . $numaction);
6303 if (!is_numeric($numaction)) {
6307 return img_picto($titlealt, (empty($picto) ?
'stcomm' . $numaction .
'.png' : $picto), $moreatt);
6317function img_edit_add($titlealt =
'default', $other =
'')
6321 if ($titlealt ==
'default') {
6322 $titlealt = $langs->trans(
'Add');
6325 return img_picto($titlealt,
'edit_add.png', $other);
6338 if ($titlealt ==
'default') {
6339 $titlealt = $langs->trans(
'Remove');
6342 return img_picto($titlealt,
'edit_remove.png', $other);
6353function img_edit($titlealt =
'default', $float = 0, $other =
'')
6357 if ($titlealt ==
'default') {
6358 $titlealt = $langs->trans(
'Modify');
6361 return img_picto($titlealt,
'edit', ($float ?
'style="float: ' . ($langs->tab_translate[
"DIRECTION"] ==
'rtl' ?
'left' :
'right') .
'"' :
"") . ($other ?
' ' . $other :
''));
6372function img_view($titlealt =
'default', $float = 0, $other =
'class="valignmiddle"')
6376 if ($titlealt ==
'default') {
6377 $titlealt = $langs->trans(
'View');
6380 $moreatt = ($float ?
'style="float: right" ' :
'') . $other;
6382 return img_picto($titlealt,
'eye', $moreatt);
6393function img_delete($titlealt =
'default', $other =
'class="pictodelete"', $morecss =
'')
6397 if ($titlealt ==
'default') {
6398 $titlealt = $langs->trans(
'Delete');
6401 return img_picto($titlealt,
'delete', $other, 0, 0, 0,
'', $morecss);
6411function img_printer($titlealt =
"default", $other =
'')
6414 if ($titlealt ==
"default") {
6415 $titlealt = $langs->trans(
"Print");
6417 return img_picto($titlealt,
'printer', $other);
6427function img_split($titlealt =
'default', $other =
'class="pictosplit"')
6431 if ($titlealt ==
'default') {
6432 $titlealt = $langs->trans(
'Split');
6435 return img_picto($titlealt,
'split', $other);
6445function img_help($usehelpcursor = 1, $usealttitle = 1)
6450 if (is_string($usealttitle)) {
6453 $usealttitle = $langs->trans(
'Info');
6457 return img_picto($usealttitle,
'info',
'style="vertical-align: middle;' . ($usehelpcursor == 1 ?
' cursor: help' : ($usehelpcursor == 2 ?
' cursor: pointer' :
'')) .
'"');
6466function img_info($titlealt =
'default')
6470 if ($titlealt ==
'default') {
6471 $titlealt = $langs->trans(
'Informations');
6474 return img_picto($titlealt,
'info',
'style="vertical-align: middle;"');
6485function img_warning($titlealt =
'default', $moreatt =
'', $morecss =
'pictowarning')
6489 if ($titlealt ==
'default') {
6490 $titlealt = $langs->trans(
'Warning');
6494 return img_picto($titlealt,
'warning',
'class="' . $morecss .
'"' . ($moreatt ? ($moreatt ==
'1' ?
' style="float: right"' :
' ' . $moreatt) :
''));
6503function img_error($titlealt =
'default')
6507 if ($titlealt ==
'default') {
6508 $titlealt = $langs->trans(
'Error');
6521function img_next($titlealt =
'default', $moreatt =
'')
6525 if ($titlealt ==
'default') {
6526 $titlealt = $langs->trans(
'Next');
6530 return '<span class="fa fa-chevron-right paddingright paddingleft" title="' .
dol_escape_htmltag($titlealt) .
'"></span>';
6540function img_previous($titlealt =
'default', $moreatt =
'')
6544 if ($titlealt ==
'default') {
6545 $titlealt = $langs->trans(
'Previous');
6549 return '<span class="fa fa-chevron-left paddingright paddingleft" title="' .
dol_escape_htmltag($titlealt) .
'"></span>';
6560function img_down($titlealt =
'default', $selected = 0, $moreclass =
'')
6564 if ($titlealt ==
'default') {
6565 $titlealt = $langs->trans(
'Down');
6568 return img_picto($titlealt, ($selected ?
'1downarrow_selected' :
'1downarrow'),
'class="imgdown' . ($moreclass ?
" " . $moreclass :
"") .
'"');
6579function img_up($titlealt =
'default', $selected = 0, $moreclass =
'')
6583 if ($titlealt ==
'default') {
6584 $titlealt = $langs->trans(
'Up');
6587 return img_picto($titlealt, ($selected ?
'1uparrow_selected' :
'1uparrow'),
'class="imgup' . ($moreclass ?
" " . $moreclass :
"") .
'"');
6598function img_left($titlealt =
'default', $selected = 0, $moreatt =
'')
6602 if ($titlealt ==
'default') {
6603 $titlealt = $langs->trans(
'Left');
6606 return img_picto($titlealt, ($selected ?
'1leftarrow_selected' :
'1leftarrow'), $moreatt);
6617function img_right($titlealt =
'default', $selected = 0, $moreatt =
'')
6621 if ($titlealt ==
'default') {
6622 $titlealt = $langs->trans(
'Right');
6625 return img_picto($titlealt, ($selected ?
'1rightarrow_selected' :
'1rightarrow'), $moreatt);
6635function img_allow($allow, $titlealt =
'default')
6639 if ($titlealt ==
'default') {
6640 $titlealt = $langs->trans(
'Active');
6657function img_credit_card($brand, $morecss =
'fa-2x inline-block valignmiddle')
6659 if (is_null($morecss)) {
6663 if ($brand ==
'visa' || $brand ==
'Visa') {
6665 } elseif ($brand ==
'mastercard' || $brand ==
'MasterCard') {
6666 $brand =
'cc-mastercard';
6667 } elseif ($brand ==
'amex' || $brand ==
'American Express') {
6669 } elseif ($brand ==
'discover' || $brand ==
'Discover') {
6670 $brand =
'cc-discover';
6671 } elseif ($brand ==
'jcb' || $brand ==
'JCB') {
6673 } elseif ($brand ==
'diners' || $brand ==
'Diners club') {
6674 $brand =
'cc-diners-club';
6675 } elseif (!in_array($brand, array(
'cc-visa',
'cc-mastercard',
'cc-amex',
'cc-discover',
'cc-jcb',
'cc-diners-club'))) {
6676 $brand =
'credit-card';
6679 return '<span class="fa fa-' . $brand .
' fa-fw' . ($morecss ?
' ' . $morecss :
'') .
'"></span>';
6690function img_mime($file, $titlealt =
'', $morecss =
'')
6692 require_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
6698 if (empty($titlealt)) {
6699 $titlealt =
'Mime type: ' . $mimetype;
6703 return '<i class="fa fa-' . $mimefa .
' ' . (preg_match(
'/pictofixedwidth/', $morecss) ?
'' :
'paddingright ') . ($morecss ?
' ' . $morecss :
'') .
'"' . ($titlealt ?
' title="' .
dolPrintHTMLForAttribute($titlealt) .
'"' :
'') .
'></i>';
6714function img_search($titlealt =
'default', $other =
'')
6718 if ($titlealt ==
'default') {
6719 $titlealt = $langs->trans(
'Search');
6722 $img =
img_picto($titlealt,
'search', $other, 0, 1);
6724 $input =
'<input type="image" class="liste_titre" name="button_search" src="' . $img .
'" ';
6741 if ($titlealt ==
'default') {
6742 $titlealt = $langs->trans(
'Search');
6745 $img =
img_picto($titlealt,
'searchclear.png', $other, 0, 1);
6747 $input =
'<input type="image" class="liste_titre" name="button_removefilter" src="' . $img .
'" ';
6765function info_admin($text, $infoonimgalt = 0, $nodiv = 0, $admin =
'1', $morecss =
'hideonsmartphone', $textfordropdown =
'', $picto =
'')
6767 global $conf, $langs;
6769 if ($infoonimgalt) {
6770 $result =
img_picto($text,
'info',
'class="' . ($morecss ?
' ' . $morecss :
'') .
'"');
6772 if (empty($conf->use_javascript_ajax)) {
6773 $textfordropdown =
'';
6776 $class = (empty($admin) ?
'undefined' : ((string) $admin ==
'1' ?
'info' : $admin));
6777 $fa =
'info-circle';
6778 if ($picto ==
'warning') {
6779 $fa =
'exclamation-triangle';
6781 $result = ($nodiv ?
'' :
'<div class="wordbreak ' . $class . ($morecss ?
' ' . $morecss :
'') . ($textfordropdown ?
' hidden' :
'') .
'">');
6782 $result .=
img_picto((
string) $admin ? $langs->trans(
'InfoAdmin') : $langs->trans(
'Note'), $fa);
6785 $result .= ($nodiv ?
'' :
'</div>');
6787 if ($textfordropdown) {
6788 $tmpresult =
'<span class="' . $class .
'text opacitymedium cursorpointer">' . $langs->trans($textfordropdown) .
' ' .
img_picto($langs->trans($textfordropdown),
'1downarrow') .
'</span>';
6789 $tmpresult .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">
6790 jQuery(document).ready(function() {
6791 jQuery(".' . $class .
'text").click(function() {
6792 console.log("toggle text");
6793 jQuery(".' . $class .
'").toggle();
6798 $result = $tmpresult . $result;
6819 global $conf, $langs, $user, $argv;
6820 global $dolibarr_main_prod;
6827 require_once DOL_DOCUMENT_ROOT .
'/core/class/translate.class.php';
6829 $langs->load(
"main");
6833 $langs->loadLangs(array(
'main',
'errors'));
6835 if ($_SERVER[
'DOCUMENT_ROOT']) {
6836 $out .= $langs->trans(
"DolibarrHasDetectedError") .
".<br>\n";
6838 $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";
6840 $out .= $langs->trans(
"InformationToHelpDiagnose") .
":<br>\n";
6842 $out .=
"<b>" . $langs->trans(
"Date") .
":</b> " .
dol_print_date(time(),
'dayhourlog') .
"<br>\n";
6843 $out .=
"<b>" . $langs->trans(
"Dolibarr") .
":</b> " . DOL_VERSION .
" - https://www.dolibarr.org<br>\n";
6844 if (isset($conf->global->MAIN_FEATURES_LEVEL)) {
6845 $out .=
"<b>" . $langs->trans(
"LevelOfFeature") .
":</b> " .
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') .
"<br>\n";
6847 if ($user instanceof
User) {
6848 $out .=
"<b>" . $langs->trans(
"Login") .
":</b> " . $user->login .
"<br>\n";
6850 if (function_exists(
"phpversion")) {
6851 $out .=
"<b>" . $langs->trans(
"PHP") .
":</b> " . phpversion() .
"<br>\n";
6853 $out .=
"<b>" . $langs->trans(
"Server") .
":</b> " . (isset($_SERVER[
"SERVER_SOFTWARE"]) ?
dol_htmlentities($_SERVER[
"SERVER_SOFTWARE"], ENT_COMPAT) :
'') .
"<br>\n";
6854 if (function_exists(
"php_uname")) {
6855 $out .=
"<b>" . $langs->trans(
"OS") .
":</b> " . php_uname() .
"<br>\n";
6857 $out .=
"<b>" . $langs->trans(
"UserAgent") .
":</b> " . (isset($_SERVER[
"HTTP_USER_AGENT"]) ?
dol_htmlentities($_SERVER[
"HTTP_USER_AGENT"], ENT_COMPAT) :
'') .
"<br>\n";
6859 $out .=
"<b>" . $langs->trans(
"RequestedUrl") .
":</b> " . (isset($_SERVER[
"REQUEST_URI"]) ?
dol_htmlentities($_SERVER[
"REQUEST_URI"], ENT_COMPAT) :
'') .
"<br>\n";
6860 $out .=
"<b>" . $langs->trans(
"Referer") .
":</b> " . (isset($_SERVER[
"HTTP_REFERER"]) ?
dol_htmlentities($_SERVER[
"HTTP_REFERER"], ENT_COMPAT) :
'') .
"<br>\n";
6861 $out .=
"<b>" . $langs->trans(
"MenuManager") .
":</b> " . (isset($conf->standard_menu) ?
dol_htmlentities($conf->standard_menu, ENT_COMPAT) :
'') .
"<br>\n";
6863 $syslog .=
"url=" . (isset($_SERVER[
"REQUEST_URI"]) ?
dol_escape_htmltag($_SERVER[
"REQUEST_URI"]) :
'');
6864 $syslog .=
", query_string=" . (isset($_SERVER[
"QUERY_STRING"]) ?
dol_escape_htmltag($_SERVER[
"QUERY_STRING"]) :
'');
6866 $out .=
'> ' . $langs->transnoentities(
"ErrorInternalErrorDetected") .
":\n" . $argv[0] .
"\n";
6870 if (!empty($conf->modules)) {
6871 $out .=
"<b>" . $langs->trans(
"Modules") .
":</b> " . implode(
', ', $conf->modules) .
"<br>\n";
6874 if (is_object($db)) {
6875 if ($_SERVER[
'DOCUMENT_ROOT']) {
6876 $out .=
"<b>" . $langs->trans(
"DatabaseTypeManager") .
":</b> " . $db->type .
"<br>\n";
6877 $lastqueryerror = $db->lastqueryerror();
6879 $lastqueryerror =
"SQL error string is not a valid UTF8 string. We can't show it.";
6881 $out .=
"<b>" . $langs->trans(
"RequestLastAccessInError") .
":</b> " . ($lastqueryerror ?
dol_escape_htmltag($lastqueryerror) : $langs->trans(
"ErrorNoRequestInError")) .
"<br>\n";
6882 $out .=
"<b>" . $langs->trans(
"ReturnCodeLastAccessInError") .
":</b> " . ($db->lasterrno() ?
dol_escape_htmltag($db->lasterrno()) : $langs->trans(
"ErrorNoRequestInError")) .
"<br>\n";
6883 $out .=
"<b>" . $langs->trans(
"InformationLastAccessInError") .
":</b> " . ($db->lasterror() ?
dol_escape_htmltag($db->lasterror()) : $langs->trans(
"ErrorNoRequestInError")) .
"<br>\n";
6887 $out .=
'> ' . $langs->transnoentities(
"DatabaseTypeManager") .
":\n" . $db->type .
"\n";
6888 $out .=
'> ' . $langs->transnoentities(
"RequestLastAccessInError") .
":\n" . ($db->lastqueryerror() ? $db->lastqueryerror() : $langs->transnoentities(
"ErrorNoRequestInError")) .
"\n";
6889 $out .=
'> ' . $langs->transnoentities(
"ReturnCodeLastAccessInError") .
":\n" . ($db->lasterrno() ? $db->lasterrno() : $langs->transnoentities(
"ErrorNoRequestInError")) .
"\n";
6890 $out .=
'> ' . $langs->transnoentities(
"InformationLastAccessInError") .
":\n" . ($db->lasterror() ? $db->lasterror() : $langs->transnoentities(
"ErrorNoRequestInError")) .
"\n";
6892 $syslog .=
", sql=" . $db->lastquery();
6893 $syslog .=
", db_error=" . $db->lasterror();
6896 if ($error || $errors) {
6898 if (is_array($error) && is_array($errors)) {
6899 $errors = array_merge($error, $errors);
6900 } elseif (is_array($error)) {
6902 } elseif (is_array($errors) && !empty($error)) {
6903 $errors = array_merge(array($error), $errors);
6904 } elseif (!empty($error)) {
6905 $errors = array_merge(array($error), array($errors));
6908 $langs->load(
"errors");
6910 foreach ($errors as $msg) {
6914 if ($_SERVER[
'DOCUMENT_ROOT']) {
6915 $out .=
"<b>" . $langs->trans(
"Message") .
":</b> " .
dol_escape_htmltag($msg) .
"<br>\n";
6917 $out .=
'> ' . $langs->transnoentities(
"Message") .
":\n" . $msg .
"\n";
6919 $syslog .=
", msg=" . $msg;
6922 if (empty($dolibarr_main_prod) && $_SERVER[
'DOCUMENT_ROOT'] && function_exists(
'xdebug_print_function_stack') && function_exists(
'xdebug_call_file')) {
6923 xdebug_print_function_stack();
6924 $out .=
'<b>XDebug information:</b>' .
"<br>\n";
6925 $out .=
'File: ' . xdebug_call_file() .
"<br>\n";
6926 $out .=
'Line: ' . xdebug_call_line() .
"<br>\n";
6927 $out .=
'Function: ' . xdebug_call_function() .
"<br>\n";
6932 if (!headers_sent()) {
6933 if (function_exists(
'top_httphead')) {
6937 http_response_code(202);
6940 if (empty($dolibarr_main_prod)) {
6943 if (empty($langs->defaultlang)) {
6944 $langs->setDefaultLang();
6946 $langs->loadLangs(array(
"main",
"errors"));
6948 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";
6949 print $langs->trans(
"DolibarrHasDetectedError") .
'. ';
6950 print $langs->trans(
"YouCanSetOptionDolibarrMainProdToZero");
6951 if (!defined(
"MAIN_CORE_ERROR")) {
6952 define(
"MAIN_CORE_ERROR", 1);
6969function dol_print_error_email($prefixcode, $errormessage =
'', $errormessages = array(), $morecss =
'error', $email =
'')
6973 if (empty($email)) {
6977 $langs->load(
"errors");
6980 print
'<br><div class="center login_main_message"><div class="' . $morecss .
'">';
6981 print $langs->trans(
"ErrorContactEMail", $email, $prefixcode .
'-' .
dol_print_date($now,
'%Y%m%d%H%M%S'));
6982 if ($errormessage) {
6983 print
'<br><br>' . $errormessage;
6985 if (is_array($errormessages) && count($errormessages)) {
6986 foreach ($errormessages as $mesgtoshow) {
6987 print
'<br><br>' . $mesgtoshow;
6990 print
'</div></div>';
7009function print_liste_field_titre($name, $file =
"", $field =
"", $begin =
"", $param =
"", $moreattrib =
"", $sortfield =
"", $sortorder =
"", $prefix =
"", $tooltip =
"", $forcenowrapcolumntitle = 0)
7011 print
getTitleFieldOfList($name, 0, $file, $field, $begin, $param, $moreattrib, $sortfield, $sortorder, $prefix, 0, $tooltip, $forcenowrapcolumntitle);
7032function getTitleFieldOfList($name, $thead = 0, $file =
"", $field =
"", $begin =
"", $moreparam =
"", $moreattrib =
"", $sortfield =
"", $sortorder =
"", $prefix =
"", $disablesortlink = 0, $tooltip =
'', $forcenowrapcolumntitle = 0)
7034 global $langs, $form;
7037 if ($moreattrib ==
'class="right"') {
7038 $prefix .=
'right ';
7041 $tooltip = (string) $tooltip;
7043 $sortorder = strtoupper((
string) $sortorder);
7052 $tmpsortfield = explode(
',', (
string) $sortfield);
7053 $sortfield1 = trim($tmpsortfield[0]);
7054 $tmpfield = explode(
',', $field);
7055 $field1 = trim($tmpfield[0]);
7057 if (strpos((
string) $tooltip,
':') !==
false) {
7058 $tmptooltip = explode(
':', (
string) $tooltip);
7060 $tmptooltip = array($tooltip);
7063 $wrapcolumntitle = (empty($forcenowrapcolumntitle) || (!empty($tmptooltip[2]) && $tmptooltip[2] ==
'-1'));
7065 if (!
getDolGlobalString(
'MAIN_DISABLE_WRAPPING_ON_COLUMN_TITLE') && $wrapcolumntitle) {
7066 $prefix =
'wrapcolumntitle ' . $prefix;
7072 $liste_titre =
'liste_titre';
7073 if ($field1 && ($sortfield1 == $field1 || $sortfield1 == preg_replace(
"/^[^\.]+\./",
"", $field1))) {
7074 $liste_titre =
'liste_titre_sel';
7077 $tagstart =
'<' . $tag .
' class="' . $prefix . $liste_titre .
'" ' . $moreattrib;
7082 if (empty($thead) && $field && empty($disablesortlink)) {
7083 $options = preg_replace(
'/sortfield=([a-zA-Z0-9,\s\.]+)/i',
'', (is_scalar($moreparam) ? $moreparam :
''));
7084 $options = preg_replace(
'/sortorder=([a-zA-Z0-9,\s\.]+)/i',
'', $options);
7085 $options = preg_replace(
'/&+/i',
'&', $options);
7086 if (!preg_match(
'/^&/', $options)) {
7087 $options =
'&' . $options;
7090 $sortordertouseinlink =
'';
7091 if ($field1 != $sortfield1) {
7092 if (preg_match(
'/^DESC/i', $sortorder)) {
7093 $sortordertouseinlink .= str_repeat(
'desc,', count(explode(
',', $field)));
7095 $sortordertouseinlink .= str_repeat(
'asc,', count(explode(
',', $field)));
7098 if (preg_match(
'/^ASC/i', $sortorder)) {
7099 $sortordertouseinlink .= str_repeat(
'desc,', count(explode(
',', $field)));
7101 $sortordertouseinlink .= str_repeat(
'asc,', count(explode(
',', $field)));
7104 $sortordertouseinlink = preg_replace(
'/,$/',
'', $sortordertouseinlink);
7105 $out .=
'<a class="reposition" href="' .
dolBuildUrl($file, [
'sortfield' => $field,
'sortorder' => $sortordertouseinlink,
'begin' => $begin]) . $options .
'"';
7109 if ($tooltip && $tmptooltip[0]) {
7111 $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]));
7113 $out .= $langs->trans((
string) $name);
7116 if (empty($thead) && $field && empty($disablesortlink)) {
7120 if (empty($thead) && $field) {
7121 $options = preg_replace(
'/sortfield=([a-zA-Z0-9,\s\.]+)/i',
'', (is_scalar($moreparam) ? $moreparam :
''));
7122 $options = preg_replace(
'/sortorder=([a-zA-Z0-9,\s\.]+)/i',
'', $options);
7123 $options = preg_replace(
'/&+/i',
'&', $options);
7124 if (!preg_match(
'/^&/', $options)) {
7125 $options =
'&' . $options;
7128 if (!$sortorder || ($field1 != $sortfield1)) {
7131 if (preg_match(
'/^DESC/', $sortorder)) {
7132 $sortimg .=
'<span class="nowrap">' .
img_up(
"Z-A", 0,
'paddingright') .
'</span>';
7134 if (preg_match(
'/^ASC/', $sortorder)) {
7135 $sortimg .=
'<span class="nowrap">' .
img_down(
"A-Z", 0,
'paddingright') .
'</span>';
7140 $tagend =
'</' . $tag .
'>';
7142 $out = $tagstart . $sortimg . $out . $tagend;
7157 dol_syslog(__FUNCTION__ .
" is deprecated", LOG_WARNING);
7159 print
'<div class="titre">' . $title .
'</div>';
7173function print_fiche_titre($title, $mesg =
'', $picto =
'generic', $pictoisfullpath = 0,
$id =
'')
7192function load_fiche_titre($title, $morehtmlright =
'', $picto =
'generic', $pictoisfullpath = 0,
$id =
'', $morecssontable =
'', $morehtmlcenter =
'', $morecssonpicto =
'widthpictotitle')
7196 if ($picto ==
'setup') {
7201 $return .=
'<table ' . (
$id ?
'id="' .
$id .
'" ' :
'') .
'class="centpercent notopnoleftnoright table-fiche-title' . ($morecssontable ?
' ' . $morecssontable :
'') .
'">';
7202 $return .=
'<tr class="toptitle">';
7204 $return .=
'<td class="nobordernopadding widthpictotitle valignmiddle col-picto">' .
img_picto(
'', $picto,
'class="valignmiddle pictotitle'.($morecssonpicto ?
' '.$morecssonpicto :
'').
'"', $pictoisfullpath) .
'</td>';
7206 $return .=
'<td class="nobordernopadding valignmiddle col-title">';
7207 $return .=
'<div class="titre inline-block">';
7208 $return .=
'<span class="inline-block valignmiddle">' . $title .
'</span>';
7209 $return .=
'</div>';
7212 $return .=
'<td class="nobordernopadding center valignmiddle col-center">' . $morehtmlcenter .
'</td>';
7215 $return .=
'<td class="nobordernopadding titre_right wordbreakimp right valignmiddle col-right">' . $morehtmlright .
'</td>';
7217 $return .=
'</tr></table>' .
"\n";
7245function 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 =
'')
7247 global $conf, $langs;
7250 $savtotalnboflines = $totalnboflines;
7251 if (is_numeric($totalnboflines)) {
7252 $totalnboflines = abs($totalnboflines);
7257 $tmparray = preg_split(
'/<br>/i', $title, 2);
7258 if (!empty($tmparray[1])) {
7259 $title = $tmparray[0];
7260 $subtitle = $tmparray[1];
7263 $page = (int) $page;
7265 if ($picto ==
'setup') {
7266 $picto =
'title_setup';
7268 if (($conf->browser->name ==
'ie') && $picto ==
'generic') {
7269 $picto =
'title.gif';
7272 $limit = $conf->liste_limit;
7275 if ($savlimit != 0 && (($num > $limit) || ($num == -1) || ($limit == 0))) {
7283 print
"<!-- Begin print_barre_liste -->\n";
7284 print
'<table class="centpercent notopnoleftnoright table-fiche-title' . ($morecss ?
' ' . $morecss :
'') .
'">';
7285 print
'<tr class="toptitle">';
7289 if ($picto && $title) {
7290 print
'<td class="nobordernopadding widthpictotitle valignmiddle col-picto">';
7291 print
img_picto(
'', $picto,
'class="valignmiddle pictotitle widthpictotitle"', $pictoisfullpath);
7295 print
'<td class="nobordernopadding valignmiddle col-title">';
7296 print
'<div class="titre inline-block">';
7297 print
'<span class="inline-block valignmiddle print-barre-liste">' . $title .
'</span>';
7298 if (!empty($title) && $savtotalnboflines >= 0 && (
string) $savtotalnboflines !=
'' && $totalnboflines > 0) {
7299 print
'<span class="opacitymedium colorblack marginleftonly totalnboflines valignmiddle" title="' . $langs->trans(
"NbRecordQualified") .
'">(' . $totalnboflines .
')</span>';
7302 if (!empty($subtitle)) {
7303 print
'<br><div class="subtitle inline-block hideonsmartphone">' . $subtitle .
'</div>';
7308 if ($morehtmlcenter && empty($conf->dol_optimize_smallscreen)) {
7309 print
'<td class="nobordernopadding center valignmiddle col-center">' . $morehtmlcenter .
'</td>';
7313 print
'<td class="nobordernopadding valignmiddle right col-right">';
7314 print
'<input type="hidden" name="pageplusoneold" value="' . ((int) $page + 1) .
'">';
7316 parse_str($options, $query);
7318 $query += [
'sortfield' => $sortfield];
7321 $query += [
'sortorder' => $sortorder];
7324 $options =
'&' . http_build_query($query);
7326 $query = array_merge($query, [
'page' => $page]);
7330 if ($savlimit != 0 && ($page > 0 || $num > $limit)) {
7331 if ($totalnboflines) {
7333 $maxnbofpage = (empty($conf->dol_optimize_smallscreen) ? 4 : 0);
7336 $nbpages = ceil($totalnboflines / $limit);
7340 $cpt = ($page - $maxnbofpage);
7346 if (empty($pagenavastextinput)) {
7348 $pagelist .=
'<li class="pagination"><a class="reposition" href="' .
dolBuildUrl($file, $query) .
'">1</a></li>';
7350 $pagelist .=
'<li class="pagination"><span class="inactive">...</span></li>';
7351 } elseif ($cpt == 2) {
7353 $pagelist .=
'<li class="pagination"><a class="reposition" href="' .
dolBuildUrl($file, $query) .
'">2</a></li>';
7359 if ($pagenavastextinput) {
7360 if ($cpt == $page) {
7361 $pagelist .=
'<li class="pagination pageplusone valignmiddle"><input type="text" class="' . ($totalnboflines > 100 ?
'width40' :
'width25') .
' center pageplusone heightofcombo" name="pageplusone" value="' . ($page + 1) .
'"></li>';
7365 if ($cpt == $page) {
7366 $pagelist .=
'<li class="pagination"><span class="active">' . ($page + 1) .
'</span></li>';
7368 $query[
'page'] = $cpt;
7369 $pagelist .=
'<li class="pagination"><a class="reposition" href="' .
dolBuildUrl($file, $query) .
'">' . ($cpt + 1) .
'</a></li>';
7373 }
while ($cpt < $nbpages && $cpt <= ($page + $maxnbofpage));
7375 if (empty($pagenavastextinput)) {
7376 if ($cpt < $nbpages) {
7377 if ($cpt < $nbpages - 2) {
7378 $pagelist .=
'<li class="pagination"><span class="inactive">...</span></li>';
7379 } elseif ($cpt == $nbpages - 2) {
7380 $query[
'page'] = ($nbpages - 2);
7381 $pagelist .=
'<li class="pagination"><a class="reposition" href="' .
dolBuildUrl($file, $query) .
'">' . ($nbpages - 1) .
'</a></li>';
7383 $query[
'page'] = ($nbpages - 1);
7384 $pagelist .=
'<li class="pagination"><a class="reposition" href="' .
dolBuildUrl($file, $query) .
'">' . $nbpages .
'</a></li>';
7387 $query[
'page'] = ($nbpages - 1);
7388 $pagelist .=
'<li class="pagination paginationlastpage"><a class="reposition" href="' .
dolBuildUrl($file, $query) .
'">' . $nbpages .
'</a></li>';
7391 $pagelist .=
'<li class="pagination"><span class="active">' . ($page + 1) .
"</li>";
7395 if ($savlimit || $morehtmlright || $morehtmlrightbeforearrow) {
7396 print_fleche_navigation($page, $file, $options, $nextpage, $pagelist, $morehtmlright, $savlimit, $totalnboflines, $selectlimitsuffix, $morehtmlrightbeforearrow, $hidenavigation);
7400 if ($pagenavastextinput) {
7410 if ($morehtmlcenter && !empty($conf->dol_optimize_smallscreen)) {
7411 print
'<div class="nobordernopadding marginbottomonly center valignmiddle col-center centpercent">' . $morehtmlcenter .
'</div>';
7414 print
"<!-- End title -->\n\n";
7433function print_fleche_navigation($page, $file, $options =
'', $nextpage = 0, $betweenarrows =
'', $afterarrows =
'', $limit = -1, $totalnboflines = 0, $selectlimitsuffix =
'', $beforearrows =
'', $hidenavigation = 0)
7435 global $conf, $langs;
7437 print
'<div class="pagination"><ul>';
7438 if ($beforearrows) {
7439 print
'<li class="paginationbeforearrows">';
7440 print $beforearrows;
7444 if (empty($hidenavigation)) {
7445 if ((
int) $limit > 0 && (empty($selectlimitsuffix) || !is_numeric($selectlimitsuffix))) {
7446 $pagesizechoices =
'10:10,15:15,20:20,25:25,50:50,100:100,250:250,500:500,1000:1000';
7447 $pagesizechoices .=
',5000:5000';
7457 print
'<li class="pagination">';
7458 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 .
'">';
7459 print
'<datalist id="limitlist">';
7461 print
'<li class="paginationcombolimit valignmiddle">';
7462 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")) .
'">';
7464 $tmpchoice = explode(
',', $pagesizechoices);
7465 $tmpkey = $limit .
':' . $limit;
7466 if (!in_array($tmpkey, $tmpchoice)) {
7467 $tmpchoice[$tmpkey] = $tmpkey;
7469 $tmpkey = $conf->liste_limit .
':' . $conf->liste_limit;
7470 if (!in_array($tmpkey, $tmpchoice)) {
7471 $tmpchoice[$tmpkey] = $tmpkey;
7473 asort($tmpchoice, SORT_NUMERIC);
7474 foreach ($tmpchoice as $val) {
7476 $tmp = explode(
':', $val);
7479 if ($key !=
'' && $val !=
'') {
7480 if ((
int) $key == (
int) $limit) {
7481 $selected =
' selected="selected"';
7483 print
'<option name="' . $key .
'"' . $selected .
'>' .
dol_escape_htmltag($val) .
'</option>' .
"\n";
7487 print
'</datalist>';
7490 print
ajax_combobox(
"limit" . (is_numeric($selectlimitsuffix) ?
'' : $selectlimitsuffix), array(), 0, 0,
'resolve',
'-1',
'limit');
7494 if ($conf->use_javascript_ajax) {
7495 print
'<!-- JS CODE TO ENABLE select limit to launch submit of page -->
7497 jQuery(document).ready(function () {
7498 jQuery(".selectlimit").change(function() {
7499 console.log("We change limit so we submit the form");
7500 $(this).parents(\'form:first\').submit();
7509 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>';
7511 if ($betweenarrows) {
7512 print
'<!--<div class="betweenarrows nowraponall inline-block">-->';
7513 print $betweenarrows;
7514 print
'<!--</div>-->';
7516 if ($nextpage > 0) {
7517 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>';
7520 print
'<li class="paginationafterarrows">';
7525 print
'</ul></div>' .
"\n";
7540function vatrate($rate, $addpercent =
false, $info_bits = 0, $usestarfornpr = 0, $html = 0)
7544 if (preg_match(
'/%/', $rate)) {
7545 $rate = str_replace(
'%',
'', $rate);
7549 if (preg_match(
'/\((.*)\)/', $rate, $reg)) {
7550 $morelabel =
' (' . $reg[1] .
')';
7551 $rate = preg_replace(
'/\s*' . preg_quote($morelabel,
'/') .
'/',
'', $rate);
7552 $morelabel =
' ' . ($html ?
'<span class="opacitymedium">' :
'') .
'(' . $reg[1] .
')' . ($html ?
'</span>' :
'');
7554 if (preg_match(
'/\*/', $rate)) {
7555 $rate = str_replace(
'*',
'', $rate);
7560 if (!preg_match(
'/\//', $rate)) {
7561 $ret =
price($rate, 0,
'', 0, 0) . ($addpercent ?
'%' :
'');
7564 $ret = $rate . ($addpercent ?
'%' :
'');
7566 if (($info_bits & 1) && $usestarfornpr >= 0) {
7589function price($amount, $form = 0, $outlangs =
'', $trunc = 1, $rounding = -1, $forcerounding = -1, $currency_code =
'')
7591 global $langs, $conf;
7594 if (empty($amount)) {
7597 $amount = (is_numeric($amount) ? $amount : 0);
7598 if ($rounding == -1) {
7601 $nbdecimal = $rounding;
7603 if ($outlangs ===
'none') {
7613 if (!($outlangs instanceof
Translate)) {
7617 if ($outlangs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
7618 $dec = $outlangs->transnoentitiesnoconv(
"SeparatorDecimal");
7620 if ($outlangs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
7621 $thousand = $outlangs->transnoentitiesnoconv(
"SeparatorThousand");
7623 if ($thousand ==
'None') {
7625 } elseif ($thousand ==
'Space') {
7632 $amount = str_replace(
',',
'.', $amount);
7634 $data = explode(
'.', $amount);
7635 $decpart = isset($data[1]) ? $data[1] :
'';
7636 $decpart = preg_replace(
'/0+$/i',
'', $decpart);
7646 $nbdecimalmaxshown = (int) str_replace(
'...',
'',
getDolGlobalString(
'MAIN_MAX_DECIMALS_SHOWN'));
7647 if ($trunc && $nbdecimal > $nbdecimalmaxshown) {
7648 $nbdecimal = $nbdecimalmaxshown;
7656 if ((
string) $forcerounding !=
'-1' && (string) $forcerounding !=
'') {
7657 if ($forcerounding ===
'MU') {
7659 } elseif ($forcerounding ===
'MT') {
7661 } elseif ($forcerounding >= 0) {
7662 $nbdecimal = (int) $forcerounding;
7667 $output = number_format((
float) $amount, $nbdecimal, $dec, $thousand);
7669 $cursymbolbefore = $cursymbolafter =
'';
7670 if ($currency_code && is_object($outlangs)) {
7671 if ($currency_code ==
'auto') {
7672 $currency_code = $conf->currency;
7675 $listofcurrenciesbefore = array(
'AUD',
'CAD',
'CNY',
'COP',
'CLP',
'GBP',
'HKD',
'MXN',
'PEN',
'USD',
'CRC',
'ZAR');
7676 $listoflanguagesbefore = array(
'nl_NL');
7677 if (in_array($currency_code, $listofcurrenciesbefore) || in_array($outlangs->defaultlang, $listoflanguagesbefore)) {
7678 $cursymbolbefore .= $outlangs->getCurrencySymbol($currency_code);
7680 $tmpcur = $outlangs->getCurrencySymbol($currency_code);
7681 $cursymbolafter .= ($tmpcur == $currency_code ?
' ' . $tmpcur : $tmpcur);
7684 $output = $cursymbolbefore . $output . $end . ($cursymbolafter ?
' ' :
'') . $cursymbolafter;
7686 $output = preg_replace(
'/\s/',
' ', $output);
7687 $output = preg_replace(
'/\'/',
''', $output);
7718function price2num($amount, $rounding =
'', $option = 0)
7723 if (is_null($amount)) {
7732 if (is_null($langs)) {
7736 if ($langs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
7737 $dec = $langs->transnoentitiesnoconv(
"SeparatorDecimal");
7739 if ($langs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
7740 $thousand = $langs->transnoentitiesnoconv(
"SeparatorThousand");
7743 if ($thousand ==
'None') {
7745 } elseif ($thousand ==
'Space') {
7753 if (!is_numeric($amount)) {
7754 $amount = preg_replace(
'/[a-zA-Z\/\\\*\(\)<>\_]/',
'', $amount);
7757 if ($option == 2 && $thousand ==
'.' && preg_match(
'/\.(\d\d\d)$/', (
string) $amount)) {
7758 $amount = str_replace($thousand,
'', $amount);
7764 if (is_numeric($amount)) {
7766 $temps = sprintf(
"%10.10F", $amount - intval($amount));
7767 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
7769 $amount = number_format($amount, $nbofdec, $dec, $thousand);
7775 if ($thousand !=
',' && $thousand !=
'.') {
7788 if (preg_match(
'/^(?<int>[^,]*,|[^.]*\.)(?<dec>[^.,]*)$/u', $amount, $matches)) {
7789 $intPart = $matches[
'int'];
7790 $decPart = $matches[
'dec'];
7793 $intPart = str_replace([
'.',
','],
'', $intPart);
7796 $amount = $intPart . $dec . $decPart;
7800 $amount = str_replace(
' ',
'', $amount);
7801 $amount = str_replace($thousand,
'', $amount);
7802 $amount = str_replace($dec,
'.', $amount);
7804 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
7810 $nbofdectoround =
'';
7811 if ($rounding ==
'MU') {
7813 } elseif ($rounding ==
'MT') {
7815 } elseif ($rounding ==
'MS') {
7817 } elseif ($rounding ==
'CU') {
7819 } elseif ($rounding ==
'CT') {
7821 } elseif (is_numeric($rounding)) {
7822 $nbofdectoround = (int) $rounding;
7827 $amount = round(is_string($amount) ? (
float) $amount : $amount, $nbofdectoround);
7829 return 'ErrorBadParameterProvidedToFunction';
7835 if (is_numeric($amount)) {
7837 $temps = sprintf(
"%10.10F", $amount - intval($amount));
7838 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
7840 $amount = number_format($amount, min($nbofdec, $nbofdectoround), $dec, $thousand);
7846 if ($thousand !=
',' && $thousand !=
'.') {
7847 $amount = str_replace(
',',
'.', $amount);
7850 $amount = str_replace(
' ',
'', $amount);
7851 $amount = str_replace($thousand,
'', $amount);
7852 $amount = str_replace($dec,
'.', $amount);
7854 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
7872function showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round = -1, $forceunitoutput =
'no', $use_short_label = 0)
7874 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
7876 if (($forceunitoutput ==
'no' && $dimension < 1 / 10000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == -6)) {
7877 $dimension *= 1000000;
7879 } elseif (($forceunitoutput ==
'no' && $dimension < 1 / 10 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == -3)) {
7882 } elseif (($forceunitoutput ==
'no' && $dimension > 100000000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == 6)) {
7883 $dimension /= 1000000;
7885 } elseif (($forceunitoutput ==
'no' && $dimension > 100000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == 3)) {
7902 $ret =
price($dimension, 0, $outputlangs, 0, 0, $round);
7922function get_localtax($vatrate, $local, $thirdparty_buyer =
null, $thirdparty_seller =
null, $vatnpr = 0)
7924 global $db, $conf,
$mysoc;
7926 if (empty($thirdparty_seller) || !is_object($thirdparty_seller)) {
7927 $thirdparty_seller =
$mysoc;
7930 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);
7932 $vatratecleaned = $vatrate;
7934 if (preg_match(
'/^(.*)\s*\((.*)\)$/', (
string) $vatrate, $reg)) {
7935 $vatratecleaned = trim($reg[1]);
7936 $vatratecode = $reg[2];
7945 if (
$mysoc->country_code ==
'ES') {
7947 if (!
$mysoc->localtax1_assuj || (
string) $vatratecleaned ==
"0") {
7950 if ($thirdparty_seller->id ==
$mysoc->id) {
7951 if (!$thirdparty_buyer->localtax1_assuj) {
7955 if (!$thirdparty_seller->localtax1_assuj) {
7963 if (!
$mysoc->localtax2_assuj) {
7966 if ($thirdparty_seller->id ==
$mysoc->id) {
7967 if (!$thirdparty_buyer->localtax2_assuj) {
7971 if (!$thirdparty_seller->localtax2_assuj) {
7977 if ($local == 1 && !$thirdparty_seller->localtax1_assuj) {
7980 if ($local == 2 && !$thirdparty_seller->localtax2_assuj) {
7986 if (in_array(
$mysoc->country_code, array(
'ES'))) {
7987 $conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY = 1;
7993 if ($thirdparty_seller !=
$mysoc) {
7995 return $thirdparty_seller->localtax1_value;
8004 if ($thirdparty_seller !=
$mysoc) {
8007 return $thirdparty_seller->localtax2_value;
8010 if (in_array(
$mysoc->country_code, array(
'ES'))) {
8011 return $thirdparty_buyer->localtax2_value;
8020 $sql =
"SELECT t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
8021 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t, " . MAIN_DB_PREFIX .
"c_country as c";
8022 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '" . $db->escape($thirdparty_seller->country_code) .
"'";
8023 $sql .=
" AND t.taux = " . ((float) $vatratecleaned) .
" AND t.active = 1";
8024 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
8025 if (!empty($vatratecode)) {
8026 $sql .=
" AND t.code ='" . $db->escape($vatratecode) .
"'";
8028 $sql .=
" AND t.recuperableonly = '" . $db->escape((
string) $vatnpr) .
"'";
8031 $resql = $db->query($sql);
8034 $obj = $db->fetch_object($resql);
8037 return $obj->localtax1;
8038 } elseif ($local == 2) {
8039 return $obj->localtax2;
8060 $valors = explode(
":", $tax);
8062 if (count($valors) > 1) {
8079 $sql =
" SELECT t.localtax" . $local .
" as localtax";
8080 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t INNER JOIN " . MAIN_DB_PREFIX .
"c_country as c ON c.rowid = t.fk_pays";
8081 $sql .=
" WHERE c.code = '" . $db->escape(
$mysoc->country_code) .
"' AND t.active = 1 AND t.entity IN (" .
getEntity(
'c_tva') .
") AND t.taux = (";
8082 $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";
8083 $sql .=
" WHERE c.code = '" . $db->escape(
$mysoc->country_code) .
"' AND t.entity IN (" .
getEntity(
'c_tva') .
") AND tt.active = 1)";
8084 $sql .=
" AND t.localtax" . $local .
"_type <> '0'";
8085 $sql .=
" ORDER BY t.rowid DESC";
8087 $resql = $db->query($sql);
8089 $obj = $db->fetch_object($resql);
8091 return $obj->localtax;
8112function getTaxesFromId($vatrate, $buyer =
null, $seller =
null, $firstparamisid = 1)
8116 dol_syslog(
"getTaxesFromId vat id or rate = " . $vatrate);
8119 $sql =
"SELECT t.rowid, t.code, t.taux as rate, t.recuperableonly as npr, t.accountancy_code_sell, t.accountancy_code_buy,";
8120 $sql .=
" t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type";
8121 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t";
8122 if ($firstparamisid) {
8123 $sql .=
" WHERE t.rowid = " . (int) $vatrate;
8125 $vatratecleaned = $vatrate;
8128 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
8129 $vatratecleaned = $reg[1];
8130 $vatratecode = $reg[2];
8133 $sql .=
", " . MAIN_DB_PREFIX .
"c_country as c";
8136 $sql .=
" WHERE t.fk_pays = c.rowid";
8138 $sql .=
" AND c.code = '" . $db->escape($buyer->country_code) .
"'";
8140 $sql .=
" AND c.code = '" . $db->escape($seller->country_code) .
"'";
8142 $sql .=
" AND t.taux = " . ((float) $vatratecleaned) .
" AND t.active = 1";
8143 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
8145 $sql .=
" AND t.code = '" . $db->escape($vatratecode) .
"'";
8149 $resql = $db->query($sql);
8151 $obj = $db->fetch_object($resql);
8154 'rowid' => $obj->rowid,
8155 'code' => $obj->code,
8156 'rate' => $obj->rate,
8157 'localtax1' => $obj->localtax1,
8158 'localtax1_type' => $obj->localtax1_type,
8159 'localtax2' => $obj->localtax2,
8160 'localtax2_type' => $obj->localtax2_type,
8162 'accountancy_code_sell' => $obj->accountancy_code_sell,
8163 'accountancy_code_buy' => $obj->accountancy_code_buy
8195 dol_syslog(
"getLocalTaxesFromRate vatrate=" . $vatrate .
" local=" . $local);
8198 $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";
8199 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t";
8200 if ($firstparamisid) {
8201 $sql .=
" WHERE t.rowid = " . (int) $vatrate;
8203 $vatratecleaned = $vatrate;
8206 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
8207 $vatratecleaned = $reg[1];
8208 $vatratecode = $reg[2];
8211 $sql .=
", " . MAIN_DB_PREFIX .
"c_country as c";
8213 $countrycodetouse = ((empty($buyer) || empty($buyer->country_code)) ?
$mysoc->country_code : $buyer->country_code);
8214 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '" . $db->escape($countrycodetouse) .
"'";
8216 $countrycodetouse = ((empty($seller) || empty($seller->country_code)) ?
$mysoc->country_code : $seller->country_code);
8217 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '" . $db->escape($countrycodetouse) .
"'";
8219 $sql .=
" AND t.taux = " . ((float) $vatratecleaned) .
" AND t.active = 1";
8221 $sql .=
" AND t.code = '" . $db->escape($vatratecode) .
"'";
8225 $resql = $db->query($sql);
8227 $obj = $db->fetch_object($resql);
8230 $vateratestring = $obj->rate . ($obj->code ?
' (' . $obj->code .
')' :
'');
8233 return array($obj->localtax1_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
8234 } elseif ($local == 2) {
8235 return array($obj->localtax2_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
8237 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);
8259 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
8267 $product->fetch($idprod);
8269 if ((
$mysoc->country_code == $thirdpartytouseforcountry->country_code)
8270 || (in_array(
$mysoc->country_code, array(
'FR',
'MC')) && in_array($thirdpartytouseforcountry->country_code, array(
'FR',
'MC')))
8271 || (in_array(
$mysoc->country_code, array(
'MQ',
'GP')) && in_array($thirdpartytouseforcountry->country_code, array(
'MQ',
'GP')))
8274 if ($idprodfournprice > 0) {
8275 $result = $product->get_buyprice($idprodfournprice, 0, 0,
'');
8277 $ret = $product->vatrate_supplier;
8278 if ($product->default_vat_code_supplier) {
8279 $ret .=
' (' . $product->default_vat_code_supplier .
')';
8285 $ret = $product->tva_tx;
8286 if ($product->default_vat_code) {
8287 $ret .=
' (' . $product->default_vat_code .
')';
8300 $sql =
"SELECT t.taux as vat_rate, t.code as default_vat_code";
8301 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t, " . MAIN_DB_PREFIX .
"c_country as c";
8302 $sql .=
" WHERE t.active = 1 AND t.fk_pays = c.rowid AND c.code = '" . $db->escape($thirdpartytouseforcountry->country_code) .
"'";
8303 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
8304 $sql .=
" ORDER BY t.use_default DESC, t.taux DESC, t.code ASC, t.recuperableonly ASC";
8305 $sql .= $db->plimit(1);
8307 $resql = $db->query($sql);
8309 $obj = $db->fetch_object($resql);
8311 $ret = $obj->vat_rate;
8312 if ($obj->default_vat_code) {
8313 $ret .=
' (' . $obj->default_vat_code .
')';
8337 dol_syslog(
"get_product_vat_for_country: ret=" . $ret);
8355 if (!class_exists(
'Product')) {
8356 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
8365 $result = $product->fetch($idprod);
8367 if (
$mysoc->country_code == $thirdpartytouseforcountry->country_code) {
8381 $sql =
"SELECT taux as vat_rate, localtax1, localtax2";
8382 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t, " . MAIN_DB_PREFIX .
"c_country as c";
8383 $sql .=
" WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code='" . $db->escape($thirdpartytouseforcountry->country_code) .
"'";
8384 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
8385 $sql .=
" ORDER BY t.taux DESC, t.recuperableonly ASC";
8386 $sql .= $db->plimit(1);
8388 $resql = $db->query($sql);
8390 $obj = $db->fetch_object($resql);
8393 $ret = $obj->localtax1;
8394 } elseif ($local == 2) {
8395 $ret = $obj->localtax2;
8403 dol_syslog(
"get_product_localtax_for_country: ret=" . $ret);
8427 global
$mysoc, $db, $hookmanager;
8429 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
8432 $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;
8434 if (empty($thirdparty_seller->country_code)) {
8435 $thirdparty_seller->country_code =
$mysoc->country_code;
8437 $seller_country_code = $thirdparty_seller->country_code;
8438 $seller_in_cee =
isInEEC($thirdparty_seller);
8440 if (empty($thirdparty_buyer->country_code)) {
8441 $thirdparty_buyer->country_code =
$mysoc->country_code;
8443 $buyer_country_code = $thirdparty_buyer->country_code;
8444 $buyer_in_cee =
isInEEC($thirdparty_buyer);
8446 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'));
8454 if ($seller_in_cee && $buyer_in_cee) {
8455 $isacompany = $thirdparty_buyer->
isACompany();
8456 if ($isacompany && !
getDolGlobalString(
'MAIN_USE_VAT_ZERO_FOR_COMPANIES_IN_EEC_EVEN_IF_VAT_ID_UNKNOWN')) {
8457 require_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
8465 $vatrule =
'VATRULE 0';
8471 if (empty($vatrule) && !$seller_use_vat) {
8479 $vatrule =
'VATRULE 1';
8483 if (empty($vatrule) && !empty($thirdparty_buyer->state_id)) {
8484 $sql =
"SELECT d.rowid, t.taux as vat_default_rate, t.code as vat_default_code ";
8485 $sql .=
" FROM " . $db->prefix() .
"c_tva as t";
8486 $sql .=
" INNER JOIN " . $db->prefix() .
"c_departements as d ON t.fk_department_buyer = d.rowid";
8487 $sql .=
" WHERE d.rowid = " . ((int) $thirdparty_buyer->state_id);
8488 $sql .=
" AND t.active > 0";
8489 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
8490 $sql .=
" ORDER BY t.use_default DESC, t.taux DESC, t.code ASC, t.recuperableonly ASC";
8492 $res = $db->query($sql);
8494 if ($db->num_rows($res)) {
8495 $obj = $db->fetch_object($res);
8497 $vatvalue = $obj->vat_default_rate .
' (' . $obj->vat_default_code .
')';
8498 $vatrule =
'VATRULE 2';
8505 if (empty($vatrule) && (
8506 ($seller_country_code == $buyer_country_code)
8507 || (in_array($seller_country_code, array(
'FR',
'MC')) && in_array($buyer_country_code, array(
'FR',
'MC')))
8508 || (in_array($seller_country_code, array(
'MQ',
'GP')) && in_array($buyer_country_code, array(
'MQ',
'GP')))
8513 if ($seller_country_code ==
'IN' &&
getDolGlobalString(
'MAIN_SALETAX_AUTOSWITCH_I_CS_FOR_INDIA')) {
8517 if (preg_match(
'/C+S-(\d+)/', $tmpvat, $reg) && $thirdparty_seller->state_id != $thirdparty_buyer->state_id) {
8519 $tmpvat = str_replace(
"C+S",
"I", $tmpvat);
8520 } elseif (preg_match(
'/I-(\d+)/', $tmpvat, $reg) && $thirdparty_seller->state_id == $thirdparty_buyer->state_id) {
8522 $tmpvat = str_replace(
"I",
"C+S", $tmpvat);
8526 $vatvalue = $tmpvat;
8527 $vatrule =
'VATRULE 3b';
8535 if (empty($vatrule) && ($seller_in_cee && $buyer_in_cee)) {
8536 $isacompany = $thirdparty_buyer->
isACompany();
8537 if ($isacompany && !
getDolGlobalString(
'MAIN_USE_VAT_ZERO_FOR_COMPANIES_IN_EEC_EVEN_IF_VAT_ID_UNKNOWN')) {
8538 require_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
8547 $vatrule =
'VATRULE 5';
8554 $vatrule =
'VATRULE 6';
8560 if (empty($vatrule) &&
getDolGlobalString(
'MAIN_USE_VAT_OF_PRODUCT_FOR_INDIVIDUAL_CUSTOMER_OUT_OF_EEC') && empty($buyer_in_cee)) {
8561 $isacompany = $thirdparty_buyer->
isACompany();
8564 $vatrule =
'VATRULE extra';
8577 $parameters = array(
'vatvalue' => $vatvalue,
'vatrule' => $vatrule);
8581 $reshook = $hookmanager->executeHooks(
'get_default_tva', $parameters, $tmpobject, $tmpaction);
8582 if ($reshook > 0 && !empty($hookmanager->resArray[
'vatvalue'])) {
8583 $vatvalue = $hookmanager->resArray[
'vatvalue'];
8584 $vatrule = $hookmanager->resArray[
'vatrule'];
8605 if ($idprodfournprice > 0) {
8606 if (!class_exists(
'ProductFournisseur')) {
8607 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.product.class.php';
8610 $prodprice->fetch_product_fournisseur_price($idprodfournprice);
8611 return $prodprice->fourn_tva_npr;
8612 } elseif ($idprod > 0) {
8613 if (!class_exists(
'Product')) {
8614 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
8617 $prod->fetch($idprod);
8618 return $prod->tva_npr;
8641 if (!is_object($thirdparty_seller)) {
8644 if (!is_object($thirdparty_buyer)) {
8648 if (empty($thirdparty_seller->country_code)) {
8649 $thirdparty_seller->country_code =
$mysoc->country_code;
8651 $seller_country_code = $thirdparty_seller->country_code;
8654 if (empty($thirdparty_buyer->country_code)) {
8655 $thirdparty_buyer->country_code =
$mysoc->country_code;
8657 $buyer_country_code = $thirdparty_buyer->country_code;
8661 if (
$mysoc->country_code ==
'ES') {
8662 if (is_numeric($thirdparty_buyer->localtax1_assuj) && !$thirdparty_buyer->localtax1_assuj) {
8667 if (is_numeric($thirdparty_seller->localtax1_assuj) && !$thirdparty_seller->localtax1_assuj) {
8670 if (!is_numeric($thirdparty_seller->localtax1_assuj) && $thirdparty_seller->localtax1_assuj ==
'localtax1off') {
8674 } elseif ($local == 2) {
8676 if (is_numeric($thirdparty_seller->localtax2_assuj) && !$thirdparty_seller->localtax2_assuj) {
8679 if (!is_numeric($thirdparty_seller->localtax2_assuj) && $thirdparty_seller->localtax2_assuj ==
'localtax2off') {
8684 if ($seller_country_code == $buyer_country_code) {
8699function yn($yesno, $format = 1, $color = 0)
8703 $result =
'unknown';
8705 if ($yesno ===
true || (
int) $yesno == 1 || (isset($yesno) && (strtolower($yesno) ==
'yes' || strtolower($yesno) ==
'true'))) {
8706 $result = $langs->trans(
'yes');
8707 if ($format == 1 || $format == 3) {
8708 $result = $langs->trans(
"Yes");
8711 $result =
'<input type="checkbox" value="1" checked disabled>';
8714 $result =
'<input type="checkbox" value="1" checked disabled> ' . $result;
8716 if ($format == 4 || !is_numeric($format)) {
8717 $result =
img_picto(is_numeric($format) ?
'' : $format,
'check');
8722 $result = $langs->trans(
"no");
8723 if ($format == 1 || $format == 3) {
8724 $result = $langs->trans(
"No");
8727 $result =
'<input type="checkbox" value="0" disabled>';
8730 $result =
'<input type="checkbox" value="0" disabled> ' . $result;
8732 if ($format == 4 || !is_numeric($format)) {
8733 $result =
img_picto(is_numeric($format) ?
'' : $format,
'uncheck');
8739 $classname =
'error';
8743 return '<span class="' . $classname .
'">' . $result .
'</span>';
8766function get_exdir($num, $level, $alpha, $withoutslash,
$object, $modulepart =
'')
8768 if (empty($modulepart) && is_object(
$object)) {
8769 if (!empty(
$object->module)) {
8770 $modulepart =
$object->module;
8771 } elseif (!empty(
$object->element)) {
8772 $modulepart =
$object->element;
8779 $arrayforoldpath = array(
'cheque' => 2,
'category' => 2,
'supplier_invoice' => 2,
'invoice_supplier' => 2,
'mailing' => 2,
'supplier_payment' => 2);
8781 $arrayforoldpath[
'product'] = 2;
8784 if (empty($level) && array_key_exists($modulepart, $arrayforoldpath)) {
8785 $level = $arrayforoldpath[$modulepart];
8787 if (!empty($level) && array_key_exists($modulepart, $arrayforoldpath)) {
8789 if (empty($num) && is_object(
$object)) {
8792 if (empty($alpha)) {
8793 $num = preg_replace(
'/([^0-9])/i',
'', $num);
8795 $num = preg_replace(
'/^.*\-/i',
'', $num);
8797 $num = substr(
"000" . $num, -$level);
8799 $path = substr($num, 0, 1);
8802 $path = substr($num, 1, 1) .
'/' . substr($num, 0, 1);
8805 $path = substr($num, 2, 1) .
'/' . substr($num, 1, 1) .
'/' . substr($num, 0, 1);
8811 if (in_array($modulepart, array(
'societe',
'thirdparty')) &&
$object instanceof
Societe) {
8819 if (empty($withoutslash) && !empty($path)) {
8834function dol_mkdir($dir, $dataroot =
'', $newmask =
'')
8836 dol_syslog(
"functions.lib::dol_mkdir: dir=" . $dir, LOG_INFO);
8841 if (@is_dir($dir_osencoded)) {
8849 if (!empty($dataroot)) {
8851 $dir = str_replace($dataroot .
'/',
'', $dir);
8852 $ccdir = $dataroot .
'/';
8855 $cdir = explode(
"/", $dir);
8856 $num = count($cdir);
8857 for ($i = 0; $i < $num; $i++) {
8859 $ccdir .=
'/' . $cdir[$i];
8861 $ccdir .= $cdir[$i];
8864 if (preg_match(
"/^.:$/", $ccdir, $regs)) {
8872 if (!@is_dir($ccdir_osencoded)) {
8873 dol_syslog(
"functions.lib::dol_mkdir: Directory '" . $ccdir .
"' is not found (does not exists or is outside open_basedir PHP setting).", LOG_DEBUG);
8876 $dirmaskdec = octdec((
string) $newmask);
8877 if (empty($newmask)) {
8880 $dirmaskdec |= octdec(
'0111');
8881 if (!@mkdir($ccdir_osencoded, $dirmaskdec)) {
8883 dol_syslog(
"functions.lib::dol_mkdir: Fails to create directory '" . $ccdir .
"' (no permission to write into parent or directory already exists).", LOG_WARNING);
8886 dol_syslog(
"functions.lib::dol_mkdir: Directory '" . $ccdir .
"' created", LOG_DEBUG);
8895 return ($nberr ? -$nberr : $nbcreated);
8906function dolChmod($filepath, $newmask =
'')
8908 if (!empty($newmask)) {
8909 @chmod($filepath, octdec($newmask));
8923 return '<span class="fieldrequired">*</span>';
8943function dol_string_nohtmltag($stringtoclean, $removelinefeed = 1, $pagecodeto =
'UTF-8', $strip_tags = 0, $removedoublespaces = 1)
8945 if (is_null($stringtoclean)) {
8949 if ($removelinefeed == 2) {
8950 $stringtoclean = preg_replace(
'/<br[^>]*>(\n|\r)+/ims',
'<br>', $stringtoclean);
8952 $temp = preg_replace(
'/<br[^>]*>/i',
"\n", $stringtoclean);
8957 $temp = str_replace(
'< ',
'__ltspace__', $temp);
8958 $temp = str_replace(
'<:',
'__lttwopoints__', $temp);
8961 $temp = strip_tags($temp);
8964 $pattern =
"/<[^<>]+>/";
8971 $tempbis = str_replace(
'<>',
'', $temp);
8972 $tempbis = preg_replace($pattern,
'', $tempbis);
8974 }
while ($tempbis != $temp);
8979 $temp = preg_replace(
'/<+([a-z]+)/i',
'\1', $temp);
8985 if ($removelinefeed == 1) {
8986 $temp = str_replace(array(
"\r\n",
"\r",
"\n"),
" ", $temp);
8990 if ($removedoublespaces) {
8991 while (strpos($temp,
" ") !==
false) {
8992 $temp = str_replace(
" ",
" ", $temp);
8996 $temp = str_replace(
'__ltspace__',
'< ', $temp);
8997 $temp = str_replace(
'__lttwopoints__',
'<:', $temp);
9021function dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles = 1, $removeclassattribute = 1, $cleanalsojavascript = 0, $allowiframe = 0, $allowed_tags = array(), $allowlink = 0, $allowscript = 0, $allowstyle = 0, $allowphp = 0)
9023 if (empty($allowed_tags)) {
9024 $allowed_tags = array(
9081 $allowed_tags[] =
"comment";
9083 if (!in_array(
'iframe', $allowed_tags)) {
9084 $allowed_tags[] =
"iframe";
9088 if (!in_array(
'link', $allowed_tags)) {
9089 $allowed_tags[] =
"link";
9091 if (!in_array(
'meta', $allowed_tags)) {
9092 $allowed_tags[] =
"meta";
9096 if (!in_array(
'script', $allowed_tags)) {
9097 $allowed_tags[] =
"script";
9101 if (!in_array(
'style', $allowed_tags)) {
9102 $allowed_tags[] =
"style";
9106 $allowed_tags_string = implode(
"><", $allowed_tags);
9107 $allowed_tags_string =
'<' . $allowed_tags_string .
'>';
9109 $stringtoclean = str_replace(
'<!DOCTYPE html>',
'__!DOCTYPE_HTML__', $stringtoclean);
9114 $stringtoclean = preg_replace(
'/<!--([^>]*)-->/',
'<comment>\1</comment>', $stringtoclean);
9117 $allowed_tags[] =
"commentphp";
9118 $stringtoclean = preg_replace(
'/^<\?php([^"]+)\?>$/i',
'<commentphp>\1__</commentphp>', $stringtoclean);
9119 $stringtoclean = preg_replace(
'/"<\?php([^"]+)\?>"/i',
'"<commentphp>\1</commentphp>"', $stringtoclean);
9122 $stringtoclean = preg_replace(
'/:/i',
':', $stringtoclean);
9123 $stringtoclean = preg_replace(
'/:|�+58|:/i',
'', $stringtoclean);
9126 $temp = strip_tags($stringtoclean, $allowed_tags_string);
9128 if ($cleanalsosomestyles) {
9129 $temp = preg_replace(
'/position\s*:\s*(absolute|fixed)\s*!\s*important/i',
'', $temp);
9131 if ($removeclassattribute) {
9132 $temp = preg_replace(
'/(<[^>]+)\s+class=((["\']).*?\\3|\\w*)/i',
'\\1', $temp);
9137 if ($cleanalsojavascript) {
9138 $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);
9141 $temp = str_replace(
'__!DOCTYPE_HTML__',
'<!DOCTYPE html>', $temp);
9144 $temp = preg_replace(
'/<commentphp>(.*)<\/commentphp>/',
'<?php\1?>', $temp);
9147 $temp = preg_replace(
'/<comment>([^>]*)<\/comment>/',
'<!--\1-->', $temp);
9168 if (is_null($allowed_attributes)) {
9169 $allowed_attributes = array(
9203 if (!in_array(
"content", $allowed_attributes)) {
9204 $allowed_attributes[] =
"content";
9206 if (!in_array(
"http-equiv", $allowed_attributes)) {
9207 $allowed_attributes[] =
"http-equiv";
9210 if (class_exists(
'DOMDocument') && !empty($stringtoclean)) {
9212 $stringtoclean =
'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body>' . $stringtoclean .
'</body></html>';
9215 $dom =
new DOMDocument(
'',
'UTF-8');
9217 $savwarning = error_reporting();
9218 error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE);
9219 $dom->loadHTML($stringtoclean, LIBXML_ERR_NONE | LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD | LIBXML_NONET | LIBXML_NOWARNING | LIBXML_NOXMLDECL);
9220 error_reporting($savwarning);
9222 if ($dom instanceof DOMDocument) {
9223 for ($els = $dom->getElementsByTagname(
'*'), $i = $els->length - 1; $i >= 0; $i--) {
9224 $el = $els->item($i);
9225 if (!$el instanceof DOMElement) {
9228 $attrs = $el->attributes;
9229 for ($ii = $attrs->length - 1; $ii >= 0; $ii--) {
9231 if (!empty($attrs->item($ii)->name)) {
9232 if (! in_array($attrs->item($ii)->name, $allowed_attributes)) {
9234 $els->item($i)->removeAttribute($attrs->item($ii)->name);
9235 } elseif (in_array($attrs->item($ii)->name, array(
'style'))) {
9237 $valuetoclean = $attrs->item($ii)->value;
9239 if (isset($valuetoclean)) {
9241 $oldvaluetoclean = $valuetoclean;
9242 $valuetoclean = preg_replace(
'/\/\*.*\*\//m',
'', $valuetoclean);
9243 $valuetoclean = preg_replace(
'/position\s*:\s*[a-z]+/mi',
'', $valuetoclean);
9244 if ($els->item($i)->tagName ==
'a') {
9245 $valuetoclean = preg_replace(
'/display\s*:/mi',
'', $valuetoclean);
9246 $valuetoclean = preg_replace(
'/z-index\s*:/mi',
'', $valuetoclean);
9247 $valuetoclean = preg_replace(
'/\s+(top|left|right|bottom)\s*:/mi',
'', $valuetoclean);
9251 $valuetoclean = preg_replace(
'/(logout|passwordforgotten)\.php/mi',
'', $valuetoclean);
9252 $valuetoclean = preg_replace(
'/action=/mi',
'', $valuetoclean);
9253 }
while ($oldvaluetoclean != $valuetoclean);
9256 $attrs->item($ii)->value = $valuetoclean;
9263 $dom->encoding =
'UTF-8';
9265 $return = $dom->saveHTML();
9269 $return = preg_replace(
'/^' . preg_quote(
'<html><head><',
'/') .
'[^<>]*' . preg_quote(
'></head><body>',
'/') .
'/',
'', $return);
9270 $return = preg_replace(
'/' . preg_quote(
'</body></html>',
'/') .
'$/',
'', trim($return));
9272 return trim($return);
9274 return $stringtoclean;
9291 $temp = $stringtoclean;
9292 foreach ($disallowed_tags as $tagtoremove) {
9293 $temp = preg_replace(
'/<\/?' . $tagtoremove .
'>/',
'', $temp);
9294 $temp = preg_replace(
'/<\/?' . $tagtoremove .
'\s+[^>]*>/',
'', $temp);
9297 if ($cleanalsosomestyles) {
9298 $temp = preg_replace(
'/position\s*:\s*(absolute|fixed)\s*!\s*important/',
'', $temp);
9316 if (!is_string($text) || $text ===
'') {
9321 $selfclosing = array(
'br',
'hr',
'img',
'input',
'meta',
'link',
'source',
'col',
'area',
'base',
'embed',
'param',
'track',
'wbr');
9324 if (preg_match_all(
'/<\s*(\/?)([a-zA-Z][a-zA-Z0-9]*)[^>]*?(\/?)\s*>/', $text, $matches, PREG_SET_ORDER)) {
9325 foreach ($matches as $match) {
9326 $tag = strtolower($match[2]);
9327 if (in_array($tag, $selfclosing) || !empty($match[3])) {
9330 if (empty($match[1])) {
9334 $idx = array_search($tag, array_reverse($opened,
true),
true);
9335 if ($idx !==
false) {
9336 unset($opened[$idx]);
9342 foreach (array_reverse($opened) as $tag) {
9343 $text .=
'</'.$tag.
'>';
9360 if ($nboflines == 1) {
9362 $firstline = preg_replace(
'/<br[^>]*>.*$/s',
'', $text);
9363 $firstline = preg_replace(
'/<div[^>]*>.*$/s',
'', $firstline);
9366 $firstline = preg_replace(
'/[\n\r].*/',
'', $text);
9371 return $firstline . (isset($firstline) && isset($text) && (strlen($firstline) != strlen($text)) ?
'...' :
'');
9375 $text = preg_replace(
'/\n/',
'', $text);
9377 $repTable = array(
"\t" =>
" ",
"\n" =>
" ",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
9379 $repTable = array(
"\t" =>
" ",
"\n" =>
"<br>",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
9382 $text = strtr($text, $repTable);
9383 if ($charset ==
'UTF-8') {
9384 $pattern =
'/(<br[^>]*>)/Uu';
9387 $pattern =
'/(<br[^>]*>)/U';
9389 $a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
9394 $lastaddediscontent = 1;
9395 while ($countline < $nboflines && isset($a[$i])) {
9396 if (preg_match(
'/<br[^>]*>/', $a[$i])) {
9397 if (array_key_exists($i + 1, $a) && !empty($a[$i + 1])) {
9398 $firstline .= ($ishtml ?
"<br>\n" :
"\n");
9400 if (!$lastaddediscontent) {
9403 $lastaddediscontent = 0;
9406 $firstline .= $a[$i];
9407 $lastaddediscontent = 1;
9413 $adddots = (isset($a[$i]) && (!preg_match(
'/<br[^>]*>/', $a[$i]) || (array_key_exists($i + 1, $a) && !empty($a[$i + 1]))));
9415 $ret = $firstline . ($adddots ?
'...' :
'');
9433function dol_nl2br($stringtoencode, $nl2brmode = 0, $forxml =
false)
9435 if (is_null($stringtoencode)) {
9440 return nl2br($stringtoencode, $forxml);
9442 $ret = preg_replace(
'/(\r\n|\r|\n)/i', ($forxml ?
'<br />' :
'<br>'), $stringtoencode);
9456function dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox = 0, $check =
'restricthtml')
9458 if (empty($nouseofiframesandbox) &&
getDolGlobalString(
'MAIN_SECURITY_USE_SANDBOX_FOR_HTMLWITHNOJS')) {
9463 return $stringtoencode;
9465 $out = $stringtoencode;
9469 $oldstringtoclean = $out;
9477 if (!empty($out) &&
getDolGlobalString(
'MAIN_RESTRICTHTML_ONLY_VALID_HTML') && $check !=
'restricthtmlallowunvalid') {
9479 libxml_use_internal_errors(
false);
9480 if (LIBXML_VERSION < 20900) {
9484 libxml_disable_entity_loader(
true);
9487 $dom =
new DOMDocument();
9495 $out =
'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body><div class="tricktoremove">' . $out .
'</div></body></html>';
9499 $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>';
9505 $out = preg_replace_callback(
9506 '/__\[([0-9a-zA-Z_]+)\]__/',
9512 return '__BRACKETSTART' . $m[1] .
'BRACKETEND__';
9517 $dom->loadHTML($out, LIBXML_HTML_NODEFDTD | LIBXML_ERR_NONE | LIBXML_HTML_NOIMPLIED | LIBXML_NONET | LIBXML_NOWARNING | LIBXML_NOERROR | LIBXML_NOXMLDECL);
9519 $dom->encoding =
'UTF-8';
9521 $out = trim($dom->saveHTML());
9524 $out = preg_replace_callback(
9525 '/__BRACKETSTART([0-9a-zA-Z_]+)BRACKETEND__/',
9531 return '__[' . $m[1] .
']__';
9538 $out = preg_replace(
'/^' . preg_quote(
'<html><head><',
'/') .
'[^<>]+' . preg_quote(
'></head><body><div class="tricktoremove">',
'/') .
'/',
'', $out);
9539 $out = preg_replace(
'/' . preg_quote(
'</div></body></html>',
'/') .
'$/',
'', trim($out));
9544 $out = str_replace(
'<br>',
'', $out);
9549 $out =
'InvalidHTMLStringCantBeCleaned ' . $e->getMessage();
9556 if (!empty($out) &&
getDolGlobalString(
'MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY') && !in_array($check, array(
'restricthtmlallowunvalid',
'restricthtmlallowlinkscript')) && $outishtml) {
9562 if (extension_loaded(
'tidy') && class_exists(
"tidy")) {
9569 'quote-marks' =>
false,
9570 'doctype' =>
'strict',
9571 'show-body-only' =>
true,
9572 "indent-attributes" =>
false,
9573 "vertical-space" =>
false,
9576 'preserve-entities' =>
true
9586 $out = $tidy->repairString($out, $config,
'utf8');
9595 $out =
'InvalidHTMLStringCantBeCleaned ' . $e->getMessage();
9601 $out = preg_replace(
'/[\x{200B}-\x{200D}\x{FEFF}]/u',
' ', $out);
9604 $out = preg_replace(
'/&(tab|newline);/i',
' ', $out);
9608 $out = preg_replace(
'/'/i',
''', $out);
9613 if (function_exists(
'realCharForNumericEntities')) {
9614 $out = preg_replace_callback(
9615 '/&#(x?[0-9][0-9a-f]+;?)/i',
9620 static function ($m) {
9628 $out = preg_replace(
'/&#x?[0-9]+/i',
'', $out);
9631 if ($check ==
'restricthtmlallowlinkscript') {
9633 } elseif ($check ==
'restricthtmlallowclass' || $check ==
'restricthtmlallowunvalid') {
9635 } elseif ($check ==
'restricthtmlallowiframe') {
9648 $out = preg_replace(
'/'/i',
"'", $out);
9652 $out = preg_replace(
'/on(mouse|drag|key|load|touch|pointer|select|transition)[a-z]*\s*=/i',
'', $out);
9653 $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);
9654 $out = preg_replace(
'/on(dblclick|drop|durationchange|emptied|end|ended|error|focus(in|out)?|formdata|gotpointercapture|hashchange|input|invalid)[a-z]*\s*=/i',
'', $out);
9655 $out = preg_replace(
'/on(lostpointercapture|offline|online|pagehide|pageshow)[a-z]*\s*=/i',
'', $out);
9656 $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);
9657 $out = preg_replace(
'/on(timeupdate|toggle|unload|volumechange|waiting|wheel)[a-z]*\s*=/i',
'', $out);
9659 $out = preg_replace(
'/on(repeat|begin|finish|beforeinput)[a-z]*\s*=/i',
'', $out);
9660 }
while ($oldstringtoclean != $out);
9667 $tmpout = preg_replace(
'/<img src="data:/mi',
'<__IMG_SRC_DATA__ src="data:', $out);
9668 preg_match_all(
'/(<img|url\(|<link)/i', $tmpout, $reg);
9669 $nblinks = count($reg[0]);
9670 if ($nblinks >
getDolGlobalInt(
"MAIN_SECURITY_MAX_IMG_IN_HTML_CONTENT", 1000)) {
9671 $out =
'ErrorTooManyLinksIntoHTMLString';
9674 if (
getDolGlobalInt(
'MAIN_DISALLOW_URL_INTO_DESCRIPTIONS') == 2 || $check ==
'restricthtmlnolink') {
9676 $out =
'ErrorHTMLLinksNotAllowed';
9678 } elseif (
getDolGlobalInt(
'MAIN_DISALLOW_URL_INTO_DESCRIPTIONS') == 1) {
9683 $pattern =
'/src=["\']?(http[^"\']+)|url\(["\']?(http[^\)]+)/';
9688 if (preg_match_all($pattern, $out, $matches)) {
9691 foreach ($matches[1] as $tmpval) {
9692 if (!empty($tmpval)) {
9696 foreach ($matches[2] as $tmpval) {
9697 if (!empty($tmpval)) {
9705 foreach ($urls as $url) {
9707 $parsedurl = parse_url($url);
9708 if (!empty($parsedurl)) {
9717 if (empty($firstexturl)) {
9718 $firstexturl = $url;
9719 } elseif (empty($secondexturl)) {
9720 $secondexturl = $url;
9726 $out =
'ErrorHTMLExternalLinksNotAllowed (Example: '.$firstexturl.($secondexturl ?
' '.$secondexturl :
'').
')';
9755function dol_htmlentitiesbr($stringtoencode, $nl2brmode = 0, $pagecodefrom =
'UTF-8', $removelasteolbr = 1)
9757 if (is_null($stringtoencode)) {
9761 $newstring = $stringtoencode;
9763 $newstring = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>/i',
'<br>', $newstring);
9764 if ($removelasteolbr) {
9765 $newstring = preg_replace(
'/<br>$/i',
'', $newstring);
9767 $newstring = preg_replace(
'/[\x{200B}-\x{200D}\x{FEFF}]/u',
' ', $newstring);
9768 $newstring = strtr($newstring, array(
'&' =>
'__PROTECTand__',
'<' =>
'__PROTECTlt__',
'>' =>
'__PROTECTgt__',
'"' =>
'__PROTECTdquot__'));
9770 $newstring = strtr($newstring, array(
'__PROTECTand__' =>
'&',
'__PROTECTlt__' =>
'<',
'__PROTECTgt__' =>
'>',
'__PROTECTdquot__' =>
'"'));
9772 if ($removelasteolbr) {
9773 $newstring = preg_replace(
'/(\r\n|\r|\n)$/i',
'', $newstring);
9792 $ret = preg_replace(
'/' .
"\r\n" .
'<br(\s[\sa-zA-Z_="]*)?\/?>/i',
"<br>", $ret);
9793 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>' .
"\r\n" .
'/i',
"\r\n", $ret);
9794 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>' .
"\n" .
'/i',
"\n", $ret);
9795 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>/i',
"\n", $ret);
9807 $ret = preg_replace(
'/ $/i',
"", $stringtodecode);
9808 $ret = preg_replace(
'/(<br>|<br(\s[\sa-zA-Z_="]*)?\/?>|' .
"\n" .
'|' .
"\r" .
')+$/i',
"", $ret);
9824 if ($keepsomeentities) {
9825 $newstring = strtr($newstring, array(
'&' =>
'__andamp__',
'<' =>
'__andlt__',
'>' =>
'__andgt__',
'"' =>
'__dquot__'));
9827 $newstring = html_entity_decode((
string) $newstring, (
int) $b, (
string)
$c);
9828 if ($keepsomeentities) {
9829 $newstring = strtr($newstring, array(
'__andamp__' =>
'&',
'__andlt__' =>
'<',
'__andgt__' =>
'>',
'__dquot__' =>
'"'));
9845function dol_htmlentities($string, $flags = ENT_QUOTES | ENT_SUBSTITUTE, $encoding =
'UTF-8', $double_encode =
false)
9847 return htmlentities($string, $flags, $encoding, $double_encode);
9866 for ($scursor = 0; $scursor < $len; $scursor++) {
9867 $ordchar = ord($s[$scursor]);
9869 if ($ordchar < 32 && $ordchar != 13 && $ordchar != 10) {
9872 } elseif ($ordchar > 126 && $ordchar < 160) {
9876 $out .= $s[$scursor];
9898 $arraystring = explode(
"\n", $s);
9899 $nb = count($arraystring);
9916 $repTable = array(
"\t" =>
" ",
"\n" =>
"<br>",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
9918 $repTable = array(
"\t" =>
" ",
"\n" =>
" ",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
9921 $text = strtr($text, $repTable);
9922 if ($charset ==
'UTF-8') {
9923 $pattern =
'/(<br[^>]*>)/Uu';
9926 $pattern =
'/(<br[^>]*>)/U';
9928 $a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
9930 $nblines = (int) floor((count($a) + 1) / 2);
9933 foreach ($a as $line) {
9936 $line_dec = html_entity_decode($line);
9938 $line_dec = wordwrap($line_dec, $maxlinesize,
'\n',
true);
9939 $nblines += substr_count($line_dec,
'\n');
9959 if (is_null($msg)) {
9964 if (preg_match(
'/<(html|link|script)/i', $msg)) {
9966 } elseif (preg_match(
'/<body/i', $msg)) {
9968 } elseif (preg_match(
'/<\/textarea/i', $msg)) {
9970 } elseif (preg_match(
'/<(b|em|i|u)(\s+[^>]+)?>/i', $msg)) {
9972 } elseif (preg_match(
'/<br/i', $msg)) {
9978 $msg = preg_replace(
'/https?:\/\/[^"\'\s]+/i',
'', $msg);
9979 if (preg_match(
'/<(html|link|script|body)/i', $msg)) {
9981 } elseif (preg_match(
'/<\/textarea/i', $msg)) {
9983 } elseif (preg_match(
'/<(b|em|i|u)(\s+[^>]+)?>/i', $msg)) {
9985 } elseif (preg_match(
'/<(br|hr)\/>/i', $msg)) {
9987 } elseif (preg_match(
'/<(br|hr|div|font|li|p|span|strong|table)>/i', $msg)) {
9989 } elseif (preg_match(
'/<(br|hr|div|font|li|p|span|strong|table)\s+[^<>\/]*\/?>/i', $msg)) {
9991 } elseif (preg_match(
'/<img\s+[^<>]*src[^<>]*>/i', $msg)) {
9993 } elseif (preg_match(
'/<a\s+[^<>]*href[^<>]*>/i', $msg)) {
9995 } elseif (preg_match(
'/<h[0-9]>/i', $msg)) {
9997 } elseif (preg_match(
'/&[A-Z0-9]{1,6};/i', $msg)) {
10000 } elseif (preg_match(
'/&#[0-9]{2,3};/i', $msg)) {
10002 } elseif (preg_match(
'/&#x[a-f0-9][a-f0-9];/i', $msg)) {
10024function dol_concatdesc($text1, $text2, $forxml =
false, $invert =
false)
10026 if (!empty($invert)) {
10034 $ret .= (!empty($text1) && !empty($text2)) ? ((
dol_textishtml($text1) ||
dol_textishtml($text2)) ? ($forxml ?
"<br >\n" :
"<br>\n") :
"\n") :
"";
10049 return $text1.$text2;
10065function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude =
null,
$object =
null, $include =
null)
10067 global $db, $conf,
$mysoc, $user, $extrafields;
10069 $substitutionarray = array();
10071 if ((empty($exclude) || !in_array(
'user', $exclude)) && (empty($include) || in_array(
'user', $include)) && $user instanceof
User) {
10075 $emailsendersignature = $user->signature;
10076 $usersignature = $user->signature;
10077 $substitutionarray = array_merge($substitutionarray, array(
10078 '__SENDEREMAIL_SIGNATURE__' => (
string) ((!
getDolGlobalString(
'MAIN_MAIL_DO_NOT_USE_SIGN')) ? ($onlykey == 2 ?
dol_trunc(
'SignatureFromTheSelectedSenderProfile', 30) : $emailsendersignature) :
''),
10082 if (is_object($user) && ($user instanceof
User)) {
10083 $substitutionarray = array_merge($substitutionarray, array(
10084 '__USER_ID__' => (
string) $user->id,
10085 '__USER_LOGIN__' => (
string) $user->login,
10086 '__USER_EMAIL__' => (
string) $user->email,
10087 '__USER_PHONE__' => (
string)
dol_print_phone($user->office_phone,
'', 0, 0,
'',
" ",
'',
'', -1),
10088 '__USER_PHONEPRO__' => (
string)
dol_print_phone($user->user_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
10089 '__USER_PHONEMOBILE__' => (
string)
dol_print_phone($user->personal_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
10090 '__USER_FAX__' => (
string) $user->office_fax,
10091 '__USER_LASTNAME__' => (
string) $user->lastname,
10092 '__USER_FIRSTNAME__' => (
string) $user->firstname,
10093 '__USER_FULLNAME__' => (
string) $user->getFullName($outputlangs),
10094 '__USER_SUPERVISOR_ID__' => (
string) ($user->fk_user ? $user->fk_user :
'0'),
10095 '__USER_JOB__' => (string) $user->job,
10097 '__USER_VCARD_URL__' => (string) $user->getOnlineVirtualCardUrl(
'',
'external')
10101 if ((empty($exclude) || !in_array(
'mycompany', $exclude)) && is_object(
$mysoc) && (empty($include) || in_array(
'mycompany', $include))) {
10102 $substitutionarray = array_merge($substitutionarray, array(
10103 '__MYCOMPANY_NAME__' =>
$mysoc->name,
10104 '__MYCOMPANY_EMAIL__' =>
$mysoc->email,
10105 '__MYCOMPANY_URL__' =>
$mysoc->url,
10107 '__MYCOMPANY_PHONEMOBILE__' =>
dol_print_phone(
$mysoc->phone_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
10109 '__MYCOMPANY_PROFID1__' =>
$mysoc->idprof1,
10110 '__MYCOMPANY_PROFID2__' =>
$mysoc->idprof2,
10111 '__MYCOMPANY_PROFID3__' =>
$mysoc->idprof3,
10112 '__MYCOMPANY_PROFID4__' =>
$mysoc->idprof4,
10113 '__MYCOMPANY_PROFID5__' =>
$mysoc->idprof5,
10114 '__MYCOMPANY_PROFID6__' =>
$mysoc->idprof6,
10115 '__MYCOMPANY_PROFID7__' =>
$mysoc->idprof7,
10116 '__MYCOMPANY_PROFID8__' =>
$mysoc->idprof8,
10117 '__MYCOMPANY_PROFID9__' =>
$mysoc->idprof9,
10118 '__MYCOMPANY_PROFID10__' =>
$mysoc->idprof10,
10119 '__MYCOMPANY_CAPITAL__' =>
$mysoc->capital,
10120 '__MYCOMPANY_FULLADDRESS__' => (method_exists(
$mysoc,
'getFullAddress') ?
$mysoc->getFullAddress(1,
', ') :
''),
10122 '__MYCOMPANY_VATNUMBER__' =>
$mysoc->tva_intra,
10123 '__MYCOMPANY_ZIP__' =>
$mysoc->zip,
10124 '__MYCOMPANY_TOWN__' =>
$mysoc->town,
10125 '__MYCOMPANY_STATE__' =>
$mysoc->state,
10126 '__MYCOMPANY_COUNTRY__' =>
$mysoc->country,
10127 '__MYCOMPANY_COUNTRY_ID__' =>
$mysoc->country_id,
10128 '__MYCOMPANY_COUNTRY_CODE__' =>
$mysoc->country_code,
10129 '__MYCOMPANY_CURRENCY_CODE__' => $conf->currency
10133 if (($onlykey || is_object(
$object)) && (empty($exclude) || !in_array(
'object', $exclude)) && (empty($include) || in_array(
'object', $include))) {
10135 $substitutionarray[
'__ID__'] =
'__ID__';
10136 $substitutionarray[
'__REF__'] =
'__REF__';
10137 $substitutionarray[
'__NEWREF__'] =
'__NEWREF__';
10138 $substitutionarray[
'__LABEL__'] =
'__LABEL__';
10139 $substitutionarray[
'__REF_CLIENT__'] =
'__REF_CLIENT__';
10140 $substitutionarray[
'__REF_SUPPLIER__'] =
'__REF_SUPPLIER__';
10141 $substitutionarray[
'__NOTE_PUBLIC__'] =
'__NOTE_PUBLIC__';
10142 $substitutionarray[
'__NOTE_PRIVATE__'] =
'__NOTE_PRIVATE__';
10143 $substitutionarray[
'__EXTRAFIELD_XXX__'] =
'__EXTRAFIELD_XXX__';
10146 $substitutionarray[
'__THIRDPARTY_ID__'] =
'__THIRDPARTY_ID__';
10147 $substitutionarray[
'__THIRDPARTY_NAME__'] =
'__THIRDPARTY_NAME__';
10148 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] =
'__THIRDPARTY_NAME_ALIAS__';
10149 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] =
'__THIRDPARTY_CODE_CLIENT__';
10150 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] =
'__THIRDPARTY_CODE_FOURNISSEUR__';
10151 $substitutionarray[
'__THIRDPARTY_EMAIL__'] =
'__THIRDPARTY_EMAIL__';
10153 $substitutionarray[
'__THIRDPARTY_URL__'] =
'__THIRDPARTY_URL__';
10155 $substitutionarray[
'__THIRDPARTY_PHONE__'] =
'__THIRDPARTY_PHONE__';
10156 $substitutionarray[
'__THIRDPARTY_FAX__'] =
'__THIRDPARTY_FAX__';
10157 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] =
'__THIRDPARTY_ADDRESS__';
10158 $substitutionarray[
'__THIRDPARTY_ZIP__'] =
'__THIRDPARTY_ZIP__';
10159 $substitutionarray[
'__THIRDPARTY_TOWN__'] =
'__THIRDPARTY_TOWN__';
10160 $substitutionarray[
'__THIRDPARTY_STATE__'] =
'__THIRDPARTY_STATE__';
10161 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] =
'__THIRDPARTY_IDPROF1__';
10162 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] =
'__THIRDPARTY_IDPROF2__';
10163 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] =
'__THIRDPARTY_IDPROF3__';
10164 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] =
'__THIRDPARTY_IDPROF4__';
10165 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] =
'__THIRDPARTY_IDPROF5__';
10166 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] =
'__THIRDPARTY_IDPROF6__';
10167 $substitutionarray[
'__THIRDPARTY_IDPROF7__'] =
'__THIRDPARTY_IDPROF7__';
10168 $substitutionarray[
'__THIRDPARTY_IDPROF8__'] =
'__THIRDPARTY_IDPROF8__';
10169 $substitutionarray[
'__THIRDPARTY_IDPROF9__'] =
'__THIRDPARTY_IDPROF9__';
10170 $substitutionarray[
'__THIRDPARTY_IDPROF10__'] =
'__THIRDPARTY_IDPROF10__';
10171 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] =
'__THIRDPARTY_TVAINTRA__';
10172 $substitutionarray[
'__THIRDPARTY_NOTE_PUBLIC__'] =
'__THIRDPARTY_NOTE_PUBLIC__';
10173 $substitutionarray[
'__THIRDPARTY_NOTE_PRIVATE__'] =
'__THIRDPARTY_NOTE_PRIVATE__';
10175 if (
isModEnabled(
'member') && (!is_object(
$object) ||
$object->element ==
'adherent') && (empty($exclude) || !in_array(
'member', $exclude)) && (empty($include) || in_array(
'member', $include))) {
10176 $substitutionarray[
'__MEMBER_ID__'] =
'__MEMBER_ID__';
10177 $substitutionarray[
'__MEMBER_TITLE__'] =
'__MEMBER_TITLE__';
10178 $substitutionarray[
'__MEMBER_FIRSTNAME__'] =
'__MEMBER_FIRSTNAME__';
10179 $substitutionarray[
'__MEMBER_LASTNAME__'] =
'__MEMBER_LASTNAME__';
10180 $substitutionarray[
'__MEMBER_USER_LOGIN_INFORMATION__'] =
'Login and pass of the external user account';
10185 if (
isModEnabled(
'ticket') && (!is_object(
$object) ||
$object->element ==
'ticket') && (empty($exclude) || !in_array(
'ticket', $exclude)) && (empty($include) || in_array(
'ticket', $include))) {
10186 $substitutionarray[
'__TICKET_TRACKID__'] =
'__TICKET_TRACKID__';
10187 $substitutionarray[
'__TICKET_SUBJECT__'] =
'__TICKET_SUBJECT__';
10188 $substitutionarray[
'__TICKET_TYPE__'] =
'__TICKET_TYPE__';
10189 $substitutionarray[
'__TICKET_SEVERITY__'] =
'__TICKET_SEVERITY__';
10190 $substitutionarray[
'__TICKET_CATEGORY__'] =
'__TICKET_CATEGORY__';
10191 $substitutionarray[
'__TICKET_ANALYTIC_CODE__'] =
'__TICKET_ANALYTIC_CODE__';
10192 $substitutionarray[
'__TICKET_MESSAGE__'] =
'__TICKET_MESSAGE__';
10193 $substitutionarray[
'__TICKET_PROGRESSION__'] =
'__TICKET_PROGRESSION__';
10194 $substitutionarray[
'__TICKET_USER_ASSIGN__'] =
'__TICKET_USER_ASSIGN__';
10197 if (
isModEnabled(
'recruitment') && (!is_object(
$object) ||
$object->element ==
'recruitmentcandidature') && (empty($exclude) || !in_array(
'recruitment', $exclude)) && (empty($include) || in_array(
'recruitment', $include))) {
10198 $substitutionarray[
'__CANDIDATE_FULLNAME__'] =
'__CANDIDATE_FULLNAME__';
10199 $substitutionarray[
'__CANDIDATE_FIRSTNAME__'] =
'__CANDIDATE_FIRSTNAME__';
10200 $substitutionarray[
'__CANDIDATE_LASTNAME__'] =
'__CANDIDATE_LASTNAME__';
10202 if (
isModEnabled(
'project') && (empty($exclude) || !in_array(
'project', $exclude)) && (empty($include) || in_array(
'project', $include))) {
10203 $substitutionarray[
'__PROJECT_ID__'] =
'__PROJECT_ID__';
10204 $substitutionarray[
'__PROJECT_REF__'] =
'__PROJECT_REF__';
10205 $substitutionarray[
'__PROJECT_NAME__'] =
'__PROJECT_NAME__';
10209 if (
isModEnabled(
'contract') && (!is_object(
$object) ||
$object->element ==
'contract') && (empty($exclude) || !in_array(
'contract', $exclude)) && (empty($include) || in_array(
'contract', $include))) {
10210 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE__'] =
'Highest date planned for a service start';
10211 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATETIME__'] =
'Highest date and hour planned for service start';
10212 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE__'] =
'Lowest data for planned expiration of service';
10213 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATETIME__'] =
'Lowest date and hour for planned expiration of service';
10215 if (
isModEnabled(
"propal") && (!is_object(
$object) ||
$object->element ==
'propal') && (empty($exclude) || !in_array(
'propal', $exclude)) && (empty($include) || in_array(
'propal', $include))) {
10216 $substitutionarray[
'__ONLINE_SIGN_URL__'] =
'ToOfferALinkForOnlineSignature';
10218 if (
isModEnabled(
"intervention") && (!is_object(
$object) ||
$object->element ==
'fichinter') && (empty($exclude) || !in_array(
'intervention', $exclude)) && (empty($include) || in_array(
'intervention', $include))) {
10219 $substitutionarray[
'__ONLINE_SIGN_FICHINTER_URL__'] =
'ToOfferALinkForOnlineSignature';
10221 $substitutionarray[
'__ONLINE_PAYMENT_URL__'] =
'UrlToPayOnlineIfApplicable';
10222 $substitutionarray[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'TextAndUrlToPayOnlineIfApplicable';
10223 $substitutionarray[
'__SECUREKEYPAYMENT__'] =
'Security key (if key is not unique per record)';
10224 $substitutionarray[
'__SECUREKEYPAYMENT_MEMBER__'] =
'Security key for payment on a member subscription (one key per member)';
10225 $substitutionarray[
'__SECUREKEYPAYMENT_ORDER__'] =
'Security key for payment on an order';
10226 $substitutionarray[
'__SECUREKEYPAYMENT_INVOICE__'] =
'Security key for payment on an invoice';
10227 $substitutionarray[
'__SECUREKEYPAYMENT_CONTRACTLINE__'] =
'Security key for payment on a service of a contract';
10229 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
'Direct download url of a proposal';
10230 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
'Direct download url of an order';
10231 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
'Direct download url of an invoice';
10232 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
'Direct download url of a contract';
10233 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
'Direct download url of a supplier proposal';
10236 $substitutionarray[
'__SHIPPINGTRACKNUM__'] =
'Shipping tracking number';
10237 $substitutionarray[
'__SHIPPINGTRACKNUMURL__'] =
'Shipping tracking url';
10238 $substitutionarray[
'__SHIPPINGMETHOD__'] =
'Shipping method';
10241 $substitutionarray[
'__RECEPTIONTRACKNUM__'] =
'Shipping tracking number of shipment';
10242 $substitutionarray[
'__RECEPTIONTRACKNUMURL__'] =
'Shipping tracking url';
10245 '@phan-var-force Adherent|Delivery $object';
10247 $substitutionarray[
'__ID__'] =
$object->id;
10248 $substitutionarray[
'__REF__'] =
$object->ref;
10249 $substitutionarray[
'__NEWREF__'] =
$object->newref;
10251 $substitutionarray[
'__REF_CLIENT__'] = (isset(
$object->ref_client) ?
$object->ref_client : (isset(
$object->ref_customer) ?
$object->ref_customer :
null));
10252 $substitutionarray[
'__REF_SUPPLIER__'] = (isset(
$object->ref_supplier) ?
$object->ref_supplier :
null);
10253 $substitutionarray[
'__NOTE_PUBLIC__'] = (isset(
$object->note_public) ?
$object->note_public :
null);
10254 $substitutionarray[
'__NOTE_PRIVATE__'] = (isset(
$object->note_private) ?
$object->note_private :
null);
10256 $substitutionarray[
'__DATE_CREATION__'] = (isset(
$object->date_creation) ?
dol_print_date(
$object->date_creation,
'day',
false, $outputlangs) :
'');
10257 $substitutionarray[
'__DATE_MODIFICATION__'] = (isset(
$object->date_modification) ?
dol_print_date(
$object->date_modification,
'day',
false, $outputlangs) :
'');
10258 $substitutionarray[
'__DATE_VALIDATION__'] = (isset(
$object->date_validation) ?
dol_print_date(
$object->date_validation,
'day',
false, $outputlangs) :
'');
10261 $date_delivery =
null;
10262 if (property_exists(
$object,
'date_delivery')) {
10263 $date_delivery =
$object->date_delivery;
10264 } elseif (property_exists(
$object,
'delivery_date')) {
10265 $date_delivery =
$object->delivery_date;
10267 $substitutionarray[
'__DATE_DELIVERY__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
'day',
false, $outputlangs) :
'');
10268 $substitutionarray[
'__DATE_DELIVERY_DAY__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%d") :
'');
10269 $substitutionarray[
'__DATE_DELIVERY_DAY_TEXT__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%A") :
'');
10270 $substitutionarray[
'__DATE_DELIVERY_MON__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%m") :
'');
10271 $substitutionarray[
'__DATE_DELIVERY_MON_TEXT__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%b") :
'');
10272 $substitutionarray[
'__DATE_DELIVERY_YEAR__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%Y") :
'');
10273 $substitutionarray[
'__DATE_DELIVERY_HH__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%H") :
'');
10274 $substitutionarray[
'__DATE_DELIVERY_MM__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%M") :
'');
10275 $substitutionarray[
'__DATE_DELIVERY_SS__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%S") :
'');
10278 $substitutionarray[
'__REFCLIENT__'] = (isset(
$object->ref_client) ?
$object->ref_client : (isset(
$object->ref_customer) ?
$object->ref_customer :
null));
10279 $substitutionarray[
'__REFSUPPLIER__'] = (isset(
$object->ref_supplier) ?
$object->ref_supplier :
null);
10281 $substitutionarray[
'__SUPPLIER_ORDER_DATE_DELIVERY__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
'day',
false, $outputlangs) :
'');
10282 $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 :
'')) :
'');
10286 '@phan-var-force Adherent $object';
10290 $substitutionarray[
'__MEMBER_ID__'] = (isset(
$object->id) ?
$object->id :
'');
10291 if (method_exists(
$object,
'getCivilityLabel')) {
10292 $substitutionarray[
'__MEMBER_TITLE__'] =
$object->getCivilityLabel();
10294 $substitutionarray[
'__MEMBER_FIRSTNAME__'] = (isset(
$object->firstname) ?
$object->firstname :
'');
10295 $substitutionarray[
'__MEMBER_LASTNAME__'] = (isset(
$object->lastname) ?
$object->lastname :
'');
10296 $substitutionarray[
'__MEMBER_USER_LOGIN_INFORMATION__'] =
'';
10297 if (method_exists(
$object,
'getFullName')) {
10298 $substitutionarray[
'__MEMBER_FULLNAME__'] =
$object->getFullName($outputlangs);
10300 $substitutionarray[
'__MEMBER_COMPANY__'] = (isset(
$object->societe) ?
$object->societe :
'');
10301 $substitutionarray[
'__MEMBER_ADDRESS__'] = (isset(
$object->address) ?
$object->address :
'');
10302 $substitutionarray[
'__MEMBER_ZIP__'] = (isset(
$object->zip) ?
$object->zip :
'');
10303 $substitutionarray[
'__MEMBER_TOWN__'] = (isset(
$object->town) ?
$object->town :
'');
10304 $substitutionarray[
'__MEMBER_STATE__'] = (isset(
$object->state) ?
$object->state :
'');
10305 $substitutionarray[
'__MEMBER_COUNTRY__'] = (isset(
$object->country) ?
$object->country :
'');
10306 $substitutionarray[
'__MEMBER_EMAIL__'] = (isset(
$object->email) ?
$object->email :
'');
10307 $substitutionarray[
'__MEMBER_BIRTH__'] = (isset($birthday) ? $birthday :
'');
10308 $substitutionarray[
'__MEMBER_PHOTO__'] = (isset(
$object->photo) ?
$object->photo :
'');
10309 $substitutionarray[
'__MEMBER_LOGIN__'] = (isset(
$object->login) ?
$object->login :
'');
10310 $substitutionarray[
'__MEMBER_PASSWORD__'] = (isset(
$object->pass) ?
$object->pass :
'');
10314 $substitutionarray[
'__MEMBER_TYPE__'] = (isset(
$object->type) ?
$object->type :
'');
10315 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE__'] =
dol_print_date(
$object->first_subscription_date,
'day');
10317 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_RFC__'] =
dol_print_date(
$object->first_subscription_date,
'dayrfc');
10318 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_START__'] = (isset(
$object->first_subscription_date_start) ?
dol_print_date(
$object->first_subscription_date_start,
'day') :
'');
10319 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_START_RFC__'] = (isset(
$object->first_subscription_date_start) ?
dol_print_date(
$object->first_subscription_date_start,
'dayrfc') :
'');
10320 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_END__'] = (isset(
$object->first_subscription_date_end) ?
dol_print_date(
$object->first_subscription_date_end,
'day') :
'');
10321 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_END_RFC__'] = (isset(
$object->first_subscription_date_end) ?
dol_print_date(
$object->first_subscription_date_end,
'dayrfc') :
'');
10322 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE__'] =
dol_print_date(
$object->last_subscription_date,
'day');
10323 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_RFC__'] =
dol_print_date(
$object->last_subscription_date,
'dayrfc');
10324 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_START__'] =
dol_print_date(
$object->last_subscription_date_start,
'day');
10325 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_START_RFC__'] =
dol_print_date(
$object->last_subscription_date_start,
'dayrfc');
10326 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_END__'] =
dol_print_date(
$object->last_subscription_date_end,
'day');
10327 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_END_RFC__'] =
dol_print_date(
$object->last_subscription_date_end,
'dayrfc');
10332 '@phan-var-force Societe $object';
10333 $substitutionarray[
'__THIRDPARTY_ID__'] =
$object->id ??
'';
10334 $substitutionarray[
'__THIRDPARTY_NAME__'] =
$object->name ??
'';
10335 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] =
$object->name_alias ??
'';
10336 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] =
$object->code_client ??
'';
10337 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] =
$object->code_fournisseur ??
'';
10338 $substitutionarray[
'__THIRDPARTY_EMAIL__'] =
$object->email ??
'';
10339 $substitutionarray[
'__THIRDPARTY_EMAIL_URLENCODED__'] = urlencode(
$object->email ??
'');
10340 $substitutionarray[
'__THIRDPARTY_URL__'] =
$object->url ??
'';
10341 $substitutionarray[
'__THIRDPARTY_URL_URLENCODED__'] = urlencode(
$object->url ??
'');
10344 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] =
$object->address ??
'';
10345 $substitutionarray[
'__THIRDPARTY_ZIP__'] =
$object->zip ??
'';
10346 $substitutionarray[
'__THIRDPARTY_TOWN__'] =
$object->town ??
'';
10347 $substitutionarray[
'__THIRDPARTY_STATE__'] =
$object->state ??
'';
10348 $substitutionarray[
'__THIRDPARTY_COUNTRY_ID__'] = (
$object->country_id > 0 ?
$object->country_id :
'');
10349 $substitutionarray[
'__THIRDPARTY_COUNTRY_CODE__'] =
$object->country_code ??
'';
10350 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] =
$object->idprof1 ??
'';
10351 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] =
$object->idprof2 ??
'';
10352 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] =
$object->idprof3 ??
'';
10353 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] =
$object->idprof4 ??
'';
10354 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] =
$object->idprof5 ??
'';
10355 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] =
$object->idprof6 ??
'';
10356 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] =
$object->tva_intra ??
'';
10359 } elseif (is_object(
$object) && is_object(
$object->thirdparty)) {
10360 $substitutionarray[
'__THIRDPARTY_ID__'] =
$object->thirdparty->id ??
'';
10361 $substitutionarray[
'__THIRDPARTY_NAME__'] =
$object->thirdparty->name ??
'';
10362 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] =
$object->thirdparty->name_alias ??
'';
10363 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] =
$object->thirdparty->code_client ??
'';
10364 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] =
$object->thirdparty->code_fournisseur ??
'';
10365 $substitutionarray[
'__THIRDPARTY_EMAIL__'] =
$object->thirdparty->email ??
'';
10366 $substitutionarray[
'__THIRDPARTY_EMAIL_URLENCODED__'] = urlencode(
$object->thirdparty->email ??
'');
10369 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] =
$object->thirdparty->address ??
'';
10370 $substitutionarray[
'__THIRDPARTY_ZIP__'] =
$object->thirdparty->zip ??
'';
10371 $substitutionarray[
'__THIRDPARTY_TOWN__'] =
$object->thirdparty->town ??
'';
10372 $substitutionarray[
'__THIRDPARTY_STATE__'] =
$object->thirdparty->state ??
'';
10373 $substitutionarray[
'__THIRDPARTY_COUNTRY_ID__'] = (
$object->thirdparty->country_id > 0 ?
$object->thirdparty->country_id :
'');
10374 $substitutionarray[
'__THIRDPARTY_COUNTRY_CODE__'] =
$object->thirdparty->country_code ??
'';
10375 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] =
$object->thirdparty->idprof1 ??
'';
10376 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] =
$object->thirdparty->idprof2 ??
'';
10377 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] =
$object->thirdparty->idprof3 ??
'';
10378 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] =
$object->thirdparty->idprof4 ??
'';
10379 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] =
$object->thirdparty->idprof5 ??
'';
10380 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] =
$object->thirdparty->idprof6 ??
'';
10381 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] =
$object->thirdparty->tva_intra ??
'';
10386 if (is_object(
$object) &&
$object->element ==
'recruitmentcandidature') {
10387 '@phan-var-force RecruitmentCandidature $object';
10389 $substitutionarray[
'__CANDIDATE_FULLNAME__'] =
$object->getFullName($outputlangs);
10390 $substitutionarray[
'__CANDIDATE_FIRSTNAME__'] = isset(
$object->firstname) ?
$object->firstname :
'';
10391 $substitutionarray[
'__CANDIDATE_LASTNAME__'] = isset(
$object->lastname) ?
$object->lastname :
'';
10393 if (is_object(
$object) &&
$object->element ==
'conferenceorboothattendee') {
10394 '@phan-var-force ConferenceOrBoothAttendee $object';
10396 $substitutionarray[
'__ATTENDEE_FULLNAME__'] =
$object->getFullName($outputlangs);
10397 $substitutionarray[
'__ATTENDEE_FIRSTNAME__'] = isset(
$object->firstname) ?
$object->firstname :
'';
10398 $substitutionarray[
'__ATTENDEE_LASTNAME__'] = isset(
$object->lastname) ?
$object->lastname :
'';
10402 '@phan-var-force Project $object';
10404 $substitutionarray[
'__PROJECT_ID__'] =
$object->id;
10405 $substitutionarray[
'__PROJECT_REF__'] =
$object->ref;
10406 $substitutionarray[
'__PROJECT_NAME__'] =
$object->title;
10407 } elseif (is_object(
$object)) {
10409 if (!empty(
$object->project)) {
10412 if (!is_null($project) && is_object($project)) {
10413 $substitutionarray[
'__PROJECT_ID__'] = $project->id;
10414 $substitutionarray[
'__PROJECT_REF__'] = $project->ref;
10415 $substitutionarray[
'__PROJECT_NAME__'] = $project->title;
10420 $project_id =
$object->fk_project;
10421 } elseif (!empty(
$object->fk_projet) &&
$object->fk_projet > 0) {
10422 $project_id =
$object->fk_project;
10424 if ($project_id > 0) {
10426 $substitutionarray[
'__PROJECT_ID__@lazyload'] =
'/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id;
10427 $substitutionarray[
'__PROJECT_REF__@lazyload'] =
'/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id;
10428 $substitutionarray[
'__PROJECT_NAME__@lazyload'] =
'/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id;
10434 '@phan-var-force Facture $object';
10436 $substitutionarray[
'__INVOICE_SITUATION_NUMBER__'] = isset(
$object->situation_counter) ?
$object->situation_counter :
'';
10439 '@phan-var-force Expedition $object';
10441 $substitutionarray[
'__SHIPPINGTRACKNUM__'] =
$object->tracking_number;
10442 $substitutionarray[
'__SHIPPINGTRACKNUMURL__'] =
$object->tracking_url;
10443 $substitutionarray[
'__SHIPPINGMETHOD__'] =
$object->shipping_method;
10446 '@phan-var-force Reception $object';
10448 $substitutionarray[
'__RECEPTIONTRACKNUM__'] =
$object->tracking_number;
10449 $substitutionarray[
'__RECEPTIONTRACKNUMURL__'] =
$object->tracking_url;
10453 '@phan-var-force Contrat $object';
10455 $dateplannedstart =
'';
10456 $datenextexpiration =
'';
10457 foreach (
$object->lines as $line) {
10458 if ($line->date_start > $dateplannedstart) {
10459 $dateplannedstart = $line->date_start;
10461 if ($line->statut == 4 && $line->date_end && (!$datenextexpiration || $line->date_end < $datenextexpiration)) {
10462 $datenextexpiration = $line->date_end;
10465 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE__'] =
dol_print_date($dateplannedstart,
'day');
10466 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE_RFC__'] =
dol_print_date($dateplannedstart,
'dayrfc');
10467 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATETIME__'] =
dol_print_date($dateplannedstart,
'standard');
10469 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE__'] =
dol_print_date($datenextexpiration,
'day');
10470 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE_RFC__'] =
dol_print_date($datenextexpiration,
'dayrfc');
10471 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATETIME__'] =
dol_print_date($datenextexpiration,
'standard');
10475 '@phan-var-force Ticket $object';
10477 $substitutionarray[
'__TICKET_TRACKID__'] =
$object->track_id;
10478 $substitutionarray[
'__TICKET_SUBJECT__'] =
$object->subject;
10479 $substitutionarray[
'__TICKET_TYPE__'] =
$object->type_code;
10480 $substitutionarray[
'__TICKET_SEVERITY__'] =
$object->severity_code;
10481 $substitutionarray[
'__TICKET_CATEGORY__'] =
$object->category_code;
10482 $substitutionarray[
'__TICKET_ANALYTIC_CODE__'] =
$object->category_code;
10483 $substitutionarray[
'__TICKET_MESSAGE__'] =
$object->message;
10484 $substitutionarray[
'__TICKET_PROGRESSION__'] =
$object->progress;
10485 $userstat =
new User($db);
10486 if (
$object->fk_user_assign > 0) {
10487 $userstat->fetch(
$object->fk_user_assign);
10488 $substitutionarray[
'__TICKET_USER_ASSIGN__'] =
dolGetFirstLastname($userstat->firstname, $userstat->lastname);
10491 if (
$object->fk_user_create > 0) {
10492 $userstat->fetch(
$object->fk_user_create);
10493 $substitutionarray[
'__USER_CREATE__'] =
dolGetFirstLastname($userstat->firstname, $userstat->lastname);
10499 if (!is_object($extrafields)) {
10502 $extrafields->fetch_name_optionals_label(
$object->table_element,
true);
10504 if (
$object->fetch_optionals() > 0) {
10505 if (is_array($extrafields->attributes[
$object->table_element][
'label']) && count($extrafields->attributes[
$object->table_element][
'label']) > 0) {
10506 foreach ($extrafields->attributes[
$object->table_element][
'label'] as $key => $label) {
10507 if ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'date') {
10508 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] =
dol_print_date(
$object->array_options[
'options_' . $key],
'day');
10509 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_LOCALE__'] =
dol_print_date(
$object->array_options[
'options_' . $key],
'day',
'tzserver', $outputlangs);
10510 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_RFC__'] =
dol_print_date(
$object->array_options[
'options_' . $key],
'dayrfc');
10511 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'datetime') {
10512 $datetime =
$object->array_options[
'options_' . $key];
10513 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhour') :
'');
10514 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_LOCALE__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhour',
'tzserver', $outputlangs) :
'');
10515 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_DAY_LOCALE__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'day',
'tzserver', $outputlangs) :
'');
10516 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_RFC__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhourrfc') :
'');
10517 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'phone') {
10518 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] =
dol_print_phone(
$object->array_options[
'options_' . $key]);
10519 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'price') {
10520 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] =
$object->array_options[
'options_' . $key];
10521 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_FORMATED__'] =
price(
$object->array_options[
'options_' . $key]);
10522 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_FORMATTED__'] =
price(
$object->array_options[
'options_' . $key]);
10523 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] !=
'separator') {
10524 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] = !empty(
$object->array_options[
'options_' . $key]) ?
$object->array_options[
'options_' . $key] :
'';
10532 if (empty($substitutionarray[
'__REF__'])) {
10536 require_once DOL_DOCUMENT_ROOT .
'/core/lib/payments.lib.php';
10537 $outputlangs->loadLangs(array(
'paypal',
'other'));
10540 $typeforonlinepayment =
'free';
10542 $typeforonlinepayment =
'order';
10545 $typeforonlinepayment =
'invoice';
10548 $typeforonlinepayment =
'member';
10549 if (!empty(
$object->last_subscription_amount)) {
10550 $amounttouse =
$object->last_subscription_amount;
10554 $typeforonlinepayment =
'contract';
10557 $typeforonlinepayment =
'ficheinter';
10560 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $substitutionarray[
'__REF__'], (
float) $amounttouse);
10561 $paymenturl = $url;
10565 $substitutionarray[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = ($paymenturl ? str_replace(
'\n',
"\n", $outputlangs->trans(
"PredefinedMailContentLink", $paymenturl)) :
'');
10566 $substitutionarray[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
10570 include_once DOL_DOCUMENT_ROOT .
'/core/lib/functions_be.lib.php';
10575 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
$object->getLastMainDocLink(
$object->element);
10577 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
'';
10580 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
$object->getLastMainDocLink(
$object->element);
10582 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
'';
10585 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
$object->getLastMainDocLink(
$object->element);
10587 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
'';
10590 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
$object->getLastMainDocLink(
$object->element);
10592 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
'';
10595 $substitutionarray[
'__DIRECTDOWNLOAD_URL_FICHINTER__'] =
$object->getLastMainDocLink(
$object->element);
10597 $substitutionarray[
'__DIRECTDOWNLOAD_URL_FICHINTER__'] =
'';
10600 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
$object->getLastMainDocLink(
$object->element);
10602 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
'';
10606 '@phan-var-force Propal $object';
10608 $substitutionarray[
'__URL_PROPOSAL__'] = DOL_MAIN_URL_ROOT .
"/comm/propal/card.php?id=" .
$object->id;
10609 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
10610 $substitutionarray[
'__ONLINE_SIGN_URL__'] = getOnlineSignatureUrl(0,
'proposal',
$object->ref, 1,
$object);
10613 '@phan-var-force Commande $object';
10615 $substitutionarray[
'__URL_ORDER__'] = DOL_MAIN_URL_ROOT .
"/commande/card.php?id=" .
$object->id;
10618 '@phan-var-force Facture $object';
10620 $substitutionarray[
'__URL_INVOICE__'] = DOL_MAIN_URL_ROOT .
"/compta/facture/card.php?id=" .
$object->id;
10623 '@phan-var-force Contrat $object';
10625 $substitutionarray[
'__URL_CONTRACT__'] = DOL_MAIN_URL_ROOT .
"/contrat/card.php?id=" .
$object->id;
10626 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
10627 $substitutionarray[
'__ONLINE_SIGN_URL__'] = getOnlineSignatureUrl(0,
'contract',
$object->ref, 1,
$object);
10630 '@phan-var-force Fichinter $object';
10632 $substitutionarray[
'__URL_FICHINTER__'] = DOL_MAIN_URL_ROOT .
"/fichinter/card.php?id=" .
$object->id;
10633 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
10634 $substitutionarray[
'__ONLINE_SIGN_FICHINTER_URL__'] = getOnlineSignatureUrl(0,
'fichinter',
$object->ref, 1,
$object);
10636 if (is_object(
$object) &&
$object->element ==
'supplier_proposal') {
10637 '@phan-var-force SupplierProposal $object';
10639 $substitutionarray[
'__URL_SUPPLIER_PROPOSAL__'] = DOL_MAIN_URL_ROOT .
"/supplier_proposal/card.php?id=" .
$object->id;
10641 if (is_object(
$object) &&
$object->element ==
'invoice_supplier') {
10642 '@phan-var-force FactureFournisseur $object';
10644 $substitutionarray[
'__URL_SUPPLIER_INVOICE__'] = DOL_MAIN_URL_ROOT .
"/fourn/facture/card.php?id=" .
$object->id;
10646 if (is_object(
$object) &&
$object->element ==
'payment_supplier') {
10647 '@phan-var-force PaiementFourn $object';
10650 $liste_factures = [];
10653 $sql =
'SELECT f.ref,f.multicurrency_code as f_mccode, pf.*
10654 FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf
10655 JOIN '.MAIN_DB_PREFIX.
'facture_fourn as f ON pf.fk_facturefourn = f.rowid
10656 WHERE pf.fk_paiementfourn = '.((int)
$object->id);
10658 $resql = $db->query($sql);
10660 while ($objp = $db->fetch_object($resql)) {
10661 $liste_factures[] =
' - '.$outputlangs->trans(
'Invoice').
' '. $objp->ref.
' '.$outputlangs->trans(
'AmountPayed').
' '.
price($objp->multicurrency_amount, 0, $outputlangs, 0, -1, -1, $objp->multicurrency_code);
10664 $substitutionarray[
'__SUPPLIER_PAYMENT_INVOICES_LIST__'] = implode(
"\n", $liste_factures);
10666 $substitutionarray[
'__SUPPLIER_PAYMENT_INVOICES_TOTAL__'] =
price(
$object->multicurrency_amount, 0, $outputlangs, 0, -1, -1,
$object->multicurrency_code ?
$object->multicurrency_code : $conf->currency);
10669 '@phan-var-force Expedition $object';
10671 $substitutionarray[
'__URL_SHIPMENT__'] = DOL_MAIN_URL_ROOT .
"/expedition/card.php?id=" .
$object->id;
10676 '@phan-var-force ActionComm $object';
10678 $substitutionarray[
'__EVENT_LABEL__'] =
$object->label;
10679 $substitutionarray[
'__EVENT_DESCRIPTION__'] =
$object->note;
10680 $substitutionarray[
'__EVENT_TYPE__'] = $outputlangs->trans(
"Action" .
$object->type_code);
10681 $substitutionarray[
'__EVENT_DATE__'] =
dol_print_date(
$object->datep,
'day',
'auto', $outputlangs);
10682 $substitutionarray[
'__EVENT_TIME__'] =
dol_print_date(
$object->datep,
'hour',
'auto', $outputlangs);
10683 $substitutionarray[
'__EVENT_DATE_TZUSER__'] =
dol_print_date(
$object->datep,
'day',
'tzuserrel', $outputlangs);
10684 $substitutionarray[
'__EVENT_TIME_TZUSER__'] =
dol_print_date(
$object->datep,
'hour',
'tzuserrel', $outputlangs);
10689 if ((empty($exclude) || !in_array(
'objectamount', $exclude)) && (empty($include) || in_array(
'objectamount', $include))) {
10690 '@phan-var-force Facture|FactureRec $object';
10692 include_once DOL_DOCUMENT_ROOT .
'/core/lib/functionsnumtoword.lib.php';
10695 $substitutionarray[
'__DATE_DUE_YMD__'] = is_object(
$object) ? (isset(
$object->date_lim_reglement) ?
dol_print_date(
$object->date_lim_reglement,
'day',
false, $outputlangs) : null) :
'';
10697 $substitutionarray[
'__DATE_DUE_YMD_TEXT__'] = is_object(
$object) ? (isset(
$object->date_lim_reglement) ?
dol_print_date(
$object->date_lim_reglement,
'daytext',
false, $outputlangs) : null) :
'';
10699 $already_payed_all = 0;
10704 $substitutionarray[
'__AMOUNT_EXCL_TAX__'] = is_object(
$object) ?
$object->total_ht :
'';
10706 $substitutionarray[
'__AMOUNT_EXCL_TAX_TEXTCURRENCY__'] = is_object(
$object) ?
dol_convertToWord(
$object->total_ht, $outputlangs, $conf->currency,
true) :
'';
10708 $substitutionarray[
'__AMOUNT__'] = is_object(
$object) ?
$object->total_ttc :
'';
10710 $substitutionarray[
'__AMOUNT_TEXTCURRENCY__'] = is_object(
$object) ?
dol_convertToWord(
$object->total_ttc, $outputlangs, $conf->currency,
true) :
'';
10712 $substitutionarray[
'__AMOUNT_REMAIN__'] = is_object(
$object) ?
price2num(
$object->total_ttc - $already_payed_all,
'MT') :
'';
10714 $substitutionarray[
'__AMOUNT_VAT__'] = is_object(
$object) ? (isset(
$object->total_vat) ?
$object->total_vat :
$object->total_tva) :
'';
10718 $mysocuselocaltax1 =
false;
10719 $mysocuselocaltax2 =
false;
10721 $tmparray =
$mysoc->useLocalTax(-1);
10722 $mysocuselocaltax1 = $tmparray[1];
10723 $mysocuselocaltax2 = $tmparray[2];
10727 if ($onlykey != 2 || $mysocuselocaltax1) {
10728 $substitutionarray[
'__AMOUNT_TAX2__'] = is_object(
$object) ?
$object->total_localtax1 :
'';
10730 if ($onlykey != 2 || $mysocuselocaltax2) {
10731 $substitutionarray[
'__AMOUNT_TAX3__'] = is_object(
$object) ?
$object->total_localtax2 :
'';
10735 $substitutionarray[
'__AMOUNT_EXCL_TAX_FORMATTED__'] = is_object(
$object) ? (
$object->total_ht ?
price(
$object->total_ht, 0, $outputlangs, 0, -1, -1, $conf->currency) : null) :
'';
10736 $substitutionarray[
'__AMOUNT_FORMATTED__'] = is_object(
$object) ? (
$object->total_ttc ?
price(
$object->total_ttc, 0, $outputlangs, 0, -1, -1, $conf->currency) : null) :
'';
10737 $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) :
'';
10738 $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)) :
'';
10739 if ($onlykey != 2 || $mysocuselocaltax1) {
10740 $substitutionarray[
'__AMOUNT_TAX2_FORMATTED__'] = is_object(
$object) ? (
$object->total_localtax1 ?
price(
$object->total_localtax1, 0, $outputlangs, 0, -1, -1, $conf->currency) : null) :
'';
10742 if ($onlykey != 2 || $mysocuselocaltax2) {
10743 $substitutionarray[
'__AMOUNT_TAX3_FORMATTED__'] = is_object(
$object) ? (
$object->total_localtax2 ?
price(
$object->total_localtax2, 0, $outputlangs, 0, -1, -1, $conf->currency) : null) :
'';
10746 if ($onlykey != 2) {
10747 $substitutionarray[
'__AMOUNT_EXCL_TAX_FORMATED__'] = $substitutionarray[
'__AMOUNT_EXCL_TAX_FORMATTED__'];
10748 $substitutionarray[
'__AMOUNT_FORMATED__'] = $substitutionarray[
'__AMOUNT_FORMATTED__'];
10749 $substitutionarray[
'__AMOUNT_REMAIN_FORMATED__'] = $substitutionarray[
'__AMOUNT_REMAIN_FORMATTED__'];
10750 $substitutionarray[
'__AMOUNT_VAT_FORMATED__'] = $substitutionarray[
'__AMOUNT_VAT_FORMATTED__'];
10751 if ($mysocuselocaltax1) {
10752 $substitutionarray[
'__AMOUNT_TAX2_FORMATED__'] = $substitutionarray[
'__AMOUNT_TAX2_FORMATTED__'];
10754 if (
$mysoc->useLocalTax2) {
10755 $substitutionarray[
'__AMOUNT_TAX3_FORMATED__'] = $substitutionarray[
'__AMOUNT_TAX3_FORMATTED__'];
10759 $substitutionarray[
'__AMOUNT_MULTICURRENCY__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
$object->multicurrency_total_ttc :
'';
10760 $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) :
'';
10761 $substitutionarray[
'__AMOUNT_MULTICURRENCY_TEXT__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
dol_convertToWord(
$object->multicurrency_total_ttc, $outputlangs,
'',
true) :
'';
10762 $substitutionarray[
'__AMOUNT_MULTICURRENCY_TEXTCURRENCY__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
dol_convertToWord(
$object->multicurrency_total_ttc, $outputlangs,
$object->multicurrency_code,
true) :
'';
10763 $substitutionarray[
'__MULTICURRENCY_CODE__'] = (is_object(
$object) && isset(
$object->multicurrency_code)) ?
$object->multicurrency_code :
'';
10767 if ($onlykey != 2) {
10768 $substitutionarray[
'__TOTAL_TTC__'] = is_object(
$object) ?
$object->total_ttc :
'';
10769 $substitutionarray[
'__TOTAL_HT__'] = is_object(
$object) ?
$object->total_ht :
'';
10770 $substitutionarray[
'__TOTAL_VAT__'] = is_object(
$object) ? (isset(
$object->total_vat) ?
$object->total_vat :
$object->total_tva) :
'';
10775 if ((empty($exclude) || !in_array(
'date', $exclude)) && (empty($include) || in_array(
'date', $include))) {
10776 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
10786 $daytext = $outputlangs->trans(
'Day' . $tmp[
'wday']);
10788 $substitutionarray = array_merge($substitutionarray, array(
10789 '__NOW_TMS__' => (
string) $now,
10790 '__NOW_TMS_YMD__' =>
dol_print_date($now,
'day',
'auto', $outputlangs),
10791 '__DAY__' => (
string) $tmp[
'mday'],
10792 '__DAY_TEXT__' => $daytext,
10793 '__DAY_TEXT_SHORT__' =>
dol_trunc($daytext, 3,
'right',
'UTF-8', 1),
10794 '__DAY_TEXT_MIN__' =>
dol_trunc($daytext, 1,
'right',
'UTF-8', 1),
10795 '__MONTH__' => (
string) $tmp[
'mon'],
10796 '__MONTH_TEXT__' => $outputlangs->trans(
'Month' . sprintf(
"%02d", $tmp[
'mon'])),
10797 '__MONTH_TEXT_SHORT__' => $outputlangs->trans(
'MonthShort' . sprintf(
"%02d", $tmp[
'mon'])),
10798 '__MONTH_TEXT_MIN__' => $outputlangs->trans(
'MonthVeryShort' . sprintf(
"%02d", $tmp[
'mon'])),
10799 '__YEAR__' => (
string) $tmp[
'year'],
10800 '__YEAR_PREVIOUS_MONTH__' => (
string) $tmp3[
'year'],
10801 '__YEAR_NEXT_MONTH__' => (
string) $tmp5[
'year'],
10802 '__PREVIOUS_DAY__' => (
string) $tmp2[
'day'],
10803 '__PREVIOUS_MONTH__' => (
string) $tmp3[
'month'],
10804 '__PREVIOUS_MONTH_TEXT__' => $outputlangs->trans(
'Month' . sprintf(
"%02d", $tmp3[
'month'])),
10805 '__PREVIOUS_MONTH_TEXT_SHORT__' => $outputlangs->trans(
'MonthShort' . sprintf(
"%02d", $tmp3[
'month'])),
10806 '__PREVIOUS_MONTH_TEXT_MIN__' => $outputlangs->trans(
'MonthVeryShort' . sprintf(
"%02d", $tmp3[
'month'])),
10807 '__PREVIOUS_YEAR__' => (
string) ($tmp[
'year'] - 1),
10808 '__NEXT_DAY__' => (
string) $tmp4[
'day'],
10809 '__NEXT_MONTH__' => (
string) $tmp5[
'month'],
10810 '__NEXT_MONTH_TEXT__' => $outputlangs->trans(
'Month' . sprintf(
"%02d", $tmp5[
'month'])),
10811 '__NEXT_MONTH_TEXT_SHORT__' => $outputlangs->trans(
'MonthShort' . sprintf(
"%02d", $tmp5[
'month'])),
10812 '__NEXT_MONTH_TEXT_MIN__' => $outputlangs->trans(
'MonthVeryShort' . sprintf(
"%02d", $tmp5[
'month'])),
10813 '__NEXT_YEAR__' => (
string) ($tmp[
'year'] + 1),
10818 $substitutionarray = array_merge($substitutionarray, array(
'__ENTITY_ID__' => $conf->entity));
10820 if ((empty($exclude) || !in_array(
'system', $exclude)) && (empty($include) || in_array(
'user', $include))) {
10821 $substitutionarray[
'__DOL_MAIN_URL_ROOT__'] = DOL_MAIN_URL_ROOT;
10822 $substitutionarray[
'__(AnyTranslationKey)__'] = $outputlangs->trans(
'TranslationOfKey');
10823 $substitutionarray[
'__(AnyTranslationKey|langfile)__'] = $outputlangs->trans(
'TranslationOfKey') .
' (load also language file before)';
10824 $substitutionarray[
'__[AnyConstantKey]__'] = $outputlangs->trans(
'ValueOfConstantKey');
10829 return $substitutionarray;
10848function make_substitutions($text, $substitutionarray, $outputlangs =
null, $converttextinhtmlifnecessary = 0)
10850 global $db, $langs;
10852 if (!is_array($substitutionarray)) {
10853 return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions';
10856 if (empty($outputlangs)) {
10857 $outputlangs = $langs;
10867 if (is_object($outputlangs)) {
10869 while (preg_match(
'/__\(([^\)]+)\)__/', $text, $reg)) {
10871 $tmp = explode(
'|', $reg[1]);
10872 if (!empty($tmp[1])) {
10873 $outputlangs->load($tmp[1]);
10876 $value = $outputlangs->transnoentitiesnoconv($reg[1]);
10878 if (empty($converttextinhtmlifnecessary)) {
10880 $text = preg_replace(
'/__\(' . preg_quote($reg[1],
'/') .
'\)__/', $msgishtml ?
dol_htmlentitiesbr($value) : $value, $text);
10882 if (! $msgishtml) {
10886 if ($valueishtml) {
10894 $text = preg_replace(
'/__\(' . preg_quote($reg[1],
'/') .
'\)__/', $value, $text);
10902 while (preg_match(
'/__\[([^\]]+)\]__/', $text, $reg)) {
10903 $originalkeyfound = $reg[1];
10904 $keyfound = preg_replace(
'/\|urlencode$/',
'', $originalkeyfound);
10907 $value =
'*****forbidden*****';
10911 if (preg_match(
'/\|urlencode$/', $originalkeyfound)) {
10912 $value = urlencode($value);
10916 if (empty($converttextinhtmlifnecessary)) {
10918 $text = preg_replace(
'/__\[' . preg_quote($originalkeyfound,
'/') .
'\]__/', $msgishtml ?
dol_htmlentitiesbr($value) : $value, $text);
10920 if (! $msgishtml) {
10923 if ($valueishtml) {
10931 $text = preg_replace(
'/__\[' . preg_quote($originalkeyfound,
'/') .
'\]__/', $value, $text);
10936 foreach ($substitutionarray as $key => $value) {
10937 if (!isset($value)) {
10941 if (
getDolGlobalString(
'MAIN_MAIL_DO_NOT_USE_SIGN') && ($key ==
'__USER_SIGNATURE__' || $key ==
'__SENDEREMAIL_SIGNATURE__')) {
10945 if (empty($converttextinhtmlifnecessary)) {
10946 $text = str_replace((
string) $key, (
string) $value, $text);
10948 if (! $msgishtml) {
10951 if ($valueishtml) {
10958 $text = str_replace((
string) $key, (
string) $value, $text);
10974 $memory_object_list = array();
10975 foreach ($substitutionarray as $key => $value) {
10976 $lazy_load_arr = array();
10977 if (preg_match(
'/(__[A-Z\_]+__)@lazyload$/', $key, $lazy_load_arr)) {
10978 if (isset($lazy_load_arr[1]) && !empty($lazy_load_arr[1])) {
10979 $key_to_substitute = $lazy_load_arr[1];
10980 if (preg_match(
'/' . preg_quote($key_to_substitute,
'/') .
'/', $text)) {
10981 $param_arr = explode(
':', (
string) $value);
10983 if (count($param_arr) == 4) {
10984 $path = $param_arr[0];
10985 $class = $param_arr[1];
10986 $method = $param_arr[2];
10987 $id = (int) $param_arr[3];
10990 if (!isset($memory_object_list[$class])) {
10992 require_once DOL_DOCUMENT_ROOT . $path;
10993 if (class_exists($class)) {
10994 $memory_object_list[$class] = array(
11002 if (isset($memory_object_list[$class]) && isset($memory_object_list[$class][
'list'])) {
11003 if (method_exists($class, $method)) {
11004 if (!isset($memory_object_list[$class][
'list'][
$id])) {
11005 $tmpobj =
new $class($db);
11007 $valuetouseforsubstitution = $tmpobj->$method(
$id, $key_to_substitute);
11008 $memory_object_list[$class][
'list'][
$id] = $tmpobj;
11011 $tmpobj = $memory_object_list[$class][
'list'][
$id];
11013 $valuetouseforsubstitution = $tmpobj->$method(
$id, $key_to_substitute,
true);
11016 $text = str_replace((
string) $key_to_substitute, (
string) $valuetouseforsubstitution, $text);
11042 global $conf, $user;
11044 require_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
11049 $dirsubstitutions = array_merge(array(), (array) $conf->modules_parts[
'substitutions']);
11051 foreach ($dirsubstitutions as $reldir) {
11059 $substitfiles =
dol_dir_list($dir,
'files', 0,
'functions_');
11060 foreach ($substitfiles as $substitfile) {
11062 if (preg_match(
'/functions_(.*)\.lib\.php/i', $substitfile[
'name'], $reg)) {
11065 dol_syslog(
"Library " . $substitfile[
'name'] .
" found into " . $dir);
11067 require_once $dir . $substitfile[
'name'];
11069 $function_name = $module .
"_" . $callfunc;
11070 if (function_exists($function_name)) {
11071 $function_name($substitutionarray, $outputlangs,
$object, $parameters);
11079 foreach ($substitutionarray as $key => $value) {
11080 $tags .=
'{' . $key .
'} => ' . $value .
"\n";
11082 $substitutionarray = array_merge($substitutionarray, array(
'__ALL_TAGS__' => $tags));
11095function print_date_range($date_start, $date_end, $format =
'', $outputlangs =
null)
11097 print
get_date_range($date_start, $date_end, $format, $outputlangs);
11110function get_date_range($date_start, $date_end, $format =
'', $outputlangs =
null, $withparenthesis = 1)
11116 if (!is_object($outputlangs)) {
11117 $outputlangs = $langs;
11120 if ($date_start && $date_end) {
11121 $out .= ($withparenthesis ? ($withparenthesis == 1 ?
' ' :
'').
'(' :
'') . $outputlangs->transnoentitiesnoconv(
'DateFromTo',
dol_print_date($date_start, $format, false, $outputlangs),
dol_print_date($date_end, $format, false, $outputlangs)) . ($withparenthesis ?
')' :
'');
11123 if ($date_start && !$date_end) {
11124 $out .= ($withparenthesis ? ($withparenthesis == 1 ?
' ' :
'').
'(' :
'') . $outputlangs->transnoentitiesnoconv(
'DateFrom',
dol_print_date($date_start, $format, false, $outputlangs)) . ($withparenthesis ?
')' :
'');
11126 if (!$date_start && $date_end) {
11127 $out .= ($withparenthesis ? ($withparenthesis == 1 ?
' ' :
'').
'(' :
'') . $outputlangs->transnoentitiesnoconv(
'DateUntil',
dol_print_date($date_end, $format, false, $outputlangs)) . ($withparenthesis ?
')' :
'');
11145 if ($nameorder < 0) {
11148 if ($nameorder == 1) {
11149 $ret .= $firstname;
11150 if ($firstname && $lastname) {
11154 } elseif ($nameorder == 2 || $nameorder == 3) {
11155 $ret .= $firstname;
11156 if (empty($ret) && $nameorder == 3) {
11161 if (empty($ret) && $nameorder == 5) {
11162 $ret .= $firstname;
11164 if ($nameorder == 0) {
11165 if ($firstname && $lastname) {
11168 $ret .= $firstname;
11187function setEventMessage($mesgs, $style =
'mesgs', $noduplicate = 0, $attop = 0)
11190 if (!is_array($mesgs)) {
11191 $mesgs = trim((
string) $mesgs);
11194 if (!empty($noduplicate) && isset($_SESSION[
'dol_events'][$style]) && in_array($mesgs, $_SESSION[
'dol_events'][$style])) {
11198 array_unshift($_SESSION[
'dol_events'][$style], $mesgs);
11200 $_SESSION[
'dol_events'][$style][] = $mesgs;
11205 foreach ($mesgs as $mesg) {
11206 $mesg = trim((
string) $mesg);
11208 if (!empty($noduplicate) && isset($_SESSION[
'dol_events'][$style]) && in_array($mesg, $_SESSION[
'dol_events'][$style])) {
11212 array_unshift($_SESSION[
'dol_events'][$style], $mesgs);
11214 $_SESSION[
'dol_events'][$style][] = $mesg;
11234function setEventMessages($mesg, $mesgs, $style =
'mesgs', $messagekey =
'', $noduplicate = 0, $attop = 0)
11236 if (empty($mesg) && empty($mesgs)) {
11244 if (empty($messagekey) || empty($_COOKIE[
"DOLUSER_HIDEMESSAGE" . $messagekey])) {
11245 if (!in_array((
string) $style, array(
'mesgs',
'warnings',
'errors'))) {
11246 dol_print_error(
null,
'Bad parameter style=' . $style .
' for setEventMessages');
11248 if (empty($mesgs)) {
11251 if (!empty($mesg) && !in_array($mesg, $mesgs)) {
11272 if (isset($_SESSION[
'dol_events'][
'mesgs'])) {
11273 if (empty($disabledoutputofmessages)) {
11276 unset($_SESSION[
'dol_events'][
'mesgs']);
11279 if (isset($_SESSION[
'dol_events'][
'errors'])) {
11280 if (empty($disabledoutputofmessages)) {
11283 unset($_SESSION[
'dol_events'][
'errors']);
11287 if (isset($_SESSION[
'dol_events'][
'warnings'])) {
11288 if (empty($disabledoutputofmessages)) {
11291 unset($_SESSION[
'dol_events'][
'warnings']);
11309function get_htmloutput_mesg($mesgstring =
'', $mesgarray = [], $style =
'ok', $keepembedded = 0)
11311 global $conf, $langs;
11316 $divstart = $divend =
'';
11319 if ((empty($conf->use_javascript_ajax) ||
getDolGlobalString(
'MAIN_DISABLE_JQUERY_JNOTIFY') || defined(
'DISABLE_JQUERY_JNOTIFY') || $keepembedded) && !preg_match(
'/<div class=".*">/i', $out)) {
11320 $divstart =
'<div class="' . $style .
' clearboth">';
11321 $divend =
'</div>';
11324 if ((is_array($mesgarray) && count($mesgarray)) || $mesgstring) {
11325 $langs->load(
"errors");
11327 if (is_array($mesgarray) && count($mesgarray)) {
11328 foreach ($mesgarray as $message) {
11330 $out .= $langs->trans($message);
11331 if ($ret < count($mesgarray)) {
11338 $out .= $langs->trans($mesgstring);
11344 if (!empty($conf->use_javascript_ajax) && !
getDolGlobalString(
'MAIN_DISABLE_JQUERY_JNOTIFY') && !defined(
'DISABLE_JQUERY_JNOTIFY') && empty($keepembedded)) {
11345 $return =
'<script nonce="' .
getNonce() .
'">
11346 $(document).ready(function() {
11347 /* jnotify(message, preset of message type, keepmessage) */
11348 $.jnotify("' .
dol_escape_js($out) .
'", "' . ($style ==
"ok" ? 3000 : $style) .
'", ' . ($style ==
"ok" ?
"false" :
"true") .
',{ remove: function (){} } );
11388function dol_htmloutput_mesg($mesgstring =
'', $mesgarray = array(), $style =
'ok', $keepembedded = 0)
11390 if (empty($mesgstring) && (!is_array($mesgarray) || count($mesgarray) == 0)) {
11396 if (is_array($mesgarray)) {
11397 foreach ($mesgarray as $val) {
11398 if ($val && preg_match(
'/class="error"/i', $val)) {
11402 if ($val && preg_match(
'/class="warning"/i', $val)) {
11407 } elseif ($mesgstring && preg_match(
'/class="error"/i', $mesgstring)) {
11409 } elseif ($mesgstring && preg_match(
'/class="warning"/i', $mesgstring)) {
11412 if ($style ==
'error' || $style ==
'errors') {
11415 if ($style ==
'warning' || $style ==
'warnings') {
11419 if ($iserror || $iswarning) {
11421 $mesgstring = preg_replace(
'/<\/div><div class="(error|warning)">/',
'<br>', $mesgstring);
11422 $mesgstring = preg_replace(
'/<div class="(error|warning)">/',
'', $mesgstring);
11423 $mesgstring = preg_replace(
'/<\/div>/',
'', $mesgstring);
11425 if (is_array($mesgarray)) {
11426 $newmesgarray = array();
11427 foreach ($mesgarray as $val) {
11428 if (is_string($val)) {
11429 $tmpmesgstring = preg_replace(
'/<\/div><div class="(error|warning)">/',
'<br>', $val);
11430 $tmpmesgstring = preg_replace(
'/<div class="(error|warning)">/',
'', $tmpmesgstring);
11431 $tmpmesgstring = preg_replace(
'/<\/div>/',
'', $tmpmesgstring);
11432 $newmesgarray[] = $tmpmesgstring;
11434 dol_syslog(
"Error call of dol_htmloutput_mesg with an array with a value that is not a string", LOG_WARNING);
11437 $mesgarray = $newmesgarray;
11439 print
get_htmloutput_mesg($mesgstring, $mesgarray, ($iserror ?
'error' :
'warning'), $keepembedded);
11481function dol_sort_array(&$array, $index, $order =
'asc', $natsort = 0, $case_sensitive = 0, $keepindex = 0)
11484 $order = strtolower($order);
11486 if (is_array($array)) {
11487 $sizearray = count($array);
11488 if ($sizearray > 0) {
11491 foreach (array_keys($array) as $key) {
11492 $tmpmultikey = explode(
',', $index);
11493 $newindex = $tmpmultikey[0];
11494 if (is_object($array[$key])) {
11495 $temp[$key] = empty($array[$key]->$newindex) ? 0 : $array[$key]->$newindex;
11497 if (!empty($tmpmultikey[1])) {
11498 $newindex = $tmpmultikey[1];
11499 $temp[$key] .=
'__' . (empty($array[$key]->$newindex) ? 0 : $array[$key]->$newindex);
11503 $temp[$key] = empty($array[$key][$newindex]) ? 0 : $array[$key][$newindex];
11505 if (!empty($tmpmultikey[1])) {
11506 $newindex = $tmpmultikey[1];
11508 $temp[$key] .=
'__' . (empty($array[$key][$newindex]) ? 0 : $array[$key][$newindex]);
11511 if ($natsort == -1) {
11512 $temp[$key] =
'___' . $temp[$key];
11515 if (empty($natsort) || $natsort == -1) {
11516 if ($order ==
'asc') {
11522 if ($case_sensitive) {
11525 natcasesort($temp);
11527 if ($order !=
'asc') {
11528 $temp = array_reverse($temp,
true);
11534 foreach (array_keys($temp) as $key) {
11535 (is_numeric($key) && empty($keepindex)) ? $sorted[] = $array[$key] : $sorted[$key] = $array[$key];
11554 $str = (string) $str;
11557 $strLength = strlen($str);
11558 for ($i = 0; $i < $strLength; $i++) {
11559 if (ord($str[$i]) < 0x80) {
11561 } elseif ((ord($str[$i]) & 0xE0) == 0xC0) {
11563 } elseif ((ord($str[$i]) & 0xF0) == 0xE0) {
11565 } elseif ((ord($str[$i]) & 0xF8) == 0xF0) {
11567 } elseif ((ord($str[$i]) & 0xFC) == 0xF8) {
11569 } elseif ((ord($str[$i]) & 0xFE) == 0xFC) {
11574 for ($j = 0; $j < $n; $j++) {
11575 if ((++$i == strlen($str)) || ((ord($str[$i]) & 0xC0) != 0x80)) {
11596 return preg_match(
'//u', $str) ? true :
false;
11608 if (function_exists(
'mb_check_encoding')) {
11610 if (!mb_check_encoding($str,
'ASCII')) {
11614 if (preg_match(
'/[^\x00-\x7f]/', $str)) {
11632 $tmp = ini_get(
"unicode.filesystem_encoding");
11633 if (empty($tmp) && !empty($_SERVER[
"WINDIR"])) {
11634 $tmp =
'iso-8859-1';
11643 if ($tmp ==
'iso-8859-1') {
11644 return mb_convert_encoding($str,
'ISO-8859-1',
'UTF-8');
11665function dol_getIdFromCode($db, $key, $tablename, $fieldkey =
'code', $fieldid =
'id', $entityfilter = 0, $filters =
'', $useCache =
true)
11675 if ($useCache && isset($conf->cache[
'codeid'][$tablename][$key][$fieldid])) {
11676 return $conf->cache[
'codeid'][$tablename][$key][$fieldid];
11679 dol_syslog(
'dol_getIdFromCode (value for field ' . $fieldid .
' from key ' . $key .
' not found into cache)', LOG_DEBUG);
11681 $sql =
"SELECT " . $fieldid .
" as valuetoget";
11682 $sql .=
" FROM " . MAIN_DB_PREFIX . $tablename;
11683 if ($fieldkey ==
'id' || $fieldkey ==
'rowid') {
11684 $sql .=
" WHERE " . $fieldkey .
" = " . ((int) $key);
11686 $sql .=
" WHERE " . $fieldkey .
" = '" . $db->escape($key) .
"'";
11688 if (!empty($entityfilter)) {
11689 $sql .=
" AND entity IN (" .
getEntity($tablename) .
")";
11695 $resql = $db->query($sql);
11697 $obj = $db->fetch_object($resql);
11700 $valuetoget = $obj->valuetoget;
11701 $conf->cache[
'codeid'][$tablename][$key][$fieldid] = $valuetoget;
11703 $conf->cache[
'codeid'][$tablename][$key][$fieldid] =
'';
11707 return $valuetoget;
11727 $regextext = preg_replace(
'#^/\^?#',
'', (
string) $regextext);
11728 $regextext = preg_replace(
'#\$?/[imsxuADSUXJ]*$#',
'', $regextext);
11730 if ($matchrule == 1) {
11731 if ($var ==
'mainmenu') {
11733 return (preg_match(
'/^' . $regextext .
'/', $mainmenu));
11734 } elseif ($var ==
'leftmenu') {
11736 return (preg_match(
'/^' . $regextext .
'/', $leftmenu));
11738 return 'This variable is not accessible with dol_eval';
11741 return 'This value '.$matchrule.
' for param $matchrule is not yet implemented';
11755function verifCond($strToEvaluate, $onlysimplestring =
'1')
11759 if (isset($strToEvaluate) && $strToEvaluate !==
'') {
11762 $rep =
dol_eval($strToEvaluate, 1, 1, $onlysimplestring);
11764 $rights = (bool) $rep && (!is_string($rep) || strpos($rep,
'Bad string syntax to evaluate') ===
false);
11784function dol_eval($s, $returnvalue = 1, $hideerrors = 1, $onlysimplestring =
'1')
11786 if ($returnvalue != 1) {
11787 dol_syslog(
"Use of dol_eval with parameter returnvalue = 0 is now forbidden. Please fix this", LOG_ERR);
11810 $db, $langs, $user, $website, $websitepage,
11811 $action, $mainmenu, $leftmenu,
11820 defined(
'T_COALESCE_EQUAL') || define(
'T_COALESCE_EQUAL', PHP_INT_MAX);
11821 defined(
'T_FN') || define(
'T_FN', PHP_INT_MAX);
11824 defined(
'T_ATTRIBUTE') || define(
'T_ATTRIBUTE', PHP_INT_MAX);
11825 defined(
'T_MATCH') || define(
'T_MATCH', PHP_INT_MAX);
11826 defined(
'T_NAME_FULLY_QUALIFIED') || define(
'T_NAME_FULLY_QUALIFIED', PHP_INT_MAX);
11827 defined(
'T_NAME_QUALIFIED') || define(
'T_NAME_QUALIFIED', PHP_INT_MAX);
11828 defined(
'T_NAME_RELATIVE') || define(
'T_NAME_RELATIVE', PHP_INT_MAX);
11831 defined(
'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG') || define(
'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG', PHP_INT_MAX);
11832 defined(
'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG') || define(
'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG', PHP_INT_MAX);
11833 defined(
'T_ENUM') || define(
'T_ENUM', PHP_INT_MAX);
11834 defined(
'T_READONLY') || define(
'T_READONLY', PHP_INT_MAX);
11837 defined(
'T_PRIVATE_SET') || define(
'T_PRIVATE_SET', PHP_INT_MAX);
11838 defined(
'T_PROTECTED_SET') || define(
'T_PROTECTED_SET', PHP_INT_MAX);
11839 defined(
'T_PUBLIC_SET') || define(
'T_PUBLIC_SET', PHP_INT_MAX);
11841 $prohibited_token_ids = [
11848 'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG',
11849 'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG',
11899 'T_OPEN_TAG_WITH_ECHO',
11933 $prohibited_variables = [
11945 $prohibited_functions = [
11948 'override_function',
11950 'session_create_id',
11951 'session_regenerate_id',
11953 'call_user_func_array',
11962 'dol_eval_standard',
11970 'mb_eregi_replace',
11971 'dol_compress_dir',
11975 'dol_delete_dir_recursive',
11977 'archiveOrBackupFile',
11979 'file_put_contents',
11993 'filter_input_array',
11997 $prohibited_token_arrangements = [
12002 ' T_CONSTANT_ENCAPSED_STRING ( ',
12006 $tokens = token_get_all(
"<?php return {$s};", TOKEN_PARSE);
12008 $tokens_arrangement =
' ';
12010 for ($i = 2,
$c = count($tokens) - 1; $i <
$c; ++$i) {
12011 if (is_array($tokens[$i])) {
12012 $token_id = $tokens[$i][0];
12013 $token_value = $tokens[$i][1];
12014 $token_name = token_name($tokens[$i][0]);
12016 $token_id = $tokens[$i];
12017 $token_value = $tokens[$i];
12018 $token_name = $tokens[$i];
12022 if (T_WHITESPACE === $token_id) {
12027 $tokens_arrangement .=
"{$token_name} ";
12031 T_VARIABLE === $token_id
12032 && in_array($token_value, $prohibited_variables,
true)
12034 return "« {$token_value} » is prohibited in « {$s} »";
12039 T_STRING === $token_id
12040 && in_array($token_value, $prohibited_functions,
true)
12042 return "« {$token_value} » is prohibited in « {$s} »";
12047 $maxi = count($prohibited_token_ids);
12048 for ($i = 0; $i < $maxi; ++$i) {
12049 if (
false !== strpos($tokens_arrangement,
" {$prohibited_token_ids[$i]} ")) {
12050 return "« {$prohibited_token_ids[$i]} » is prohibited in « {$s} »";
12055 $maxi = count($prohibited_token_arrangements);
12056 for ($i = 0; $i < $maxi; ++$i) {
12057 if (
false !== strpos($tokens_arrangement, $prohibited_token_arrangements[$i])) {
12058 return "« {$prohibited_token_arrangements[$i]} » is prohibited in « {$s} »";
12064 return @eval(
"return {$s};") ??
'';
12065 }
catch (Throwable $ex) {
12066 return "Exception during evaluation: " . $s .
" - " . $ex->getMessage();
12089 global $db, $langs, $user, $website, $websitepage;
12090 global $action, $mainmenu, $leftmenu;
12092 global $objectoffield;
12100 $isObBufferActive =
false;
12101 if ($onlysimplestring ==
'0') {
12102 $onlysimplestring =
'1';
12104 if (!in_array($onlysimplestring, array(
'1',
'2'))) {
12105 return "Bad call of dol_eval. Parameter onlysimplestring must be '1' or '2'.";
12107 if (!is_scalar($s)) {
12108 return "Bad call of dol_eval. First parameter must be a string, found ".var_export($s,
true);
12112 global $dolibarr_main_restrict_eval_methods;
12115 if (!isset($dolibarr_main_restrict_eval_methods)) {
12116 $dolibarr_main_restrict_eval_methods =
'getDolGlobalString, getDolGlobalInt, getDolCurrency, getDolEntity, getDolDBType, fetchNoCompute, hasRight, isAdmin, isModEnabled, isStringVarMatching, abs, min, max, round, dol_now, preg_match';
12119 $dolibarr_main_restrict_eval_methods_array = explode(
',', str_replace(
" ",
"", $dolibarr_main_restrict_eval_methods));
12127 $specialcharsallowed =
'^$_+-.*>&|=!?():"\',/@';
12128 if ($onlysimplestring ==
'2') {
12129 $specialcharsallowed .=
'<[]';
12131 global $dolibarr_main_allow_unsecured_special_chars_in_dol_eval;
12132 if (!empty($dolibarr_main_allow_unsecured_special_chars_in_dol_eval)) {
12133 $specialcharsallowed .= (string) $dolibarr_main_allow_unsecured_special_chars_in_dol_eval;
12135 if (preg_match(
'/[^a-z0-9\s' . preg_quote($specialcharsallowed,
'/') .
']/i', $s)) {
12136 return 'Bad string syntax to evaluate (found chars that are not chars for a simple one line clean eval string): ' . $s;
12148 if (strpos($s,
'/*') !==
false || strpos($s,
'//') !==
false) {
12149 return 'Bad string syntax to evaluate (The comment string /* and // are not allowed): ' . $s;
12153 $tmps = str_replace(
' ? ',
'__XXX__', $s);
12154 if (strpos($tmps,
'?') !==
false) {
12155 return 'Bad string syntax to evaluate (The char ? can be used only with a space before and after): ' . $s;
12159 if (preg_match(
'/<=?[^\s]/', $s)) {
12160 return 'Bad string syntax to evaluate (mode ' . $onlysimplestring .
', found a < or <= without space after): ' . $s;
12164 if (preg_match(
'/\$[\w]*\s*\(/', $s)) {
12165 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;
12168 if (empty($dolibarr_main_restrict_eval_methods)) {
12174 while ($scheck && $savescheck != $scheck) {
12175 $savescheck = $scheck;
12176 $scheck = preg_replace(
'/->[a-zA-Z0-9_]+\(/',
'->__METHOD__', $scheck);
12177 $scheck = preg_replace(
'/::[a-zA-Z0-9_]+\(/',
'->__METHOD__', $scheck);
12178 $scheck = preg_replace(
'/^\(+/',
'__PARENTHESIS__ ', $scheck);
12179 $scheck = preg_replace(
'/\&\&\s+\(/',
'__ANDPARENTHESIS__ ', $scheck);
12180 $scheck = preg_replace(
'/\|\|\s+\(/',
'__ORPARENTHESIS__ ', $scheck);
12181 $scheck = preg_replace(
'/^!?[a-zA-Z0-9_]+\(/',
'__FUNCTION__', $scheck);
12182 $scheck = preg_replace(
'/\s!?[a-zA-Z0-9_]+\(/',
'__FUNCTION__', $scheck);
12183 $scheck = preg_replace(
'/^!\(/',
'__NOTANDPARENTHESIS__', $scheck);
12184 $scheck = preg_replace(
'/\s!\(/',
' __NOTANDPARENTHESIS__', $scheck);
12185 $scheck = preg_replace(
'/(\^|\')\(/',
'__REGEXSTART__', $scheck);
12190 if (strpos($scheck,
'(') !==
false) {
12191 return 'Bad string syntax to evaluate (mode ' . $onlysimplestring .
', found call of a function or method without using the direct name of the function): ' . $s;
12195 if (strpos($s,
'`') !==
false) {
12196 return 'Bad string syntax to evaluate (backtick char is forbidden): ' . $s;
12201 if (preg_match(
'/[^0-9]+\.[^0-9]+/', $s)) {
12202 return 'Bad string syntax to evaluate (dot char is forbidden if not strictly between 2 numbers): ' . $s;
12210 while ($scheck && $savescheck != $scheck) {
12211 $savescheck = $scheck;
12212 $scheck = preg_replace(
'/\$conf->[a-z\_]+->enabled/',
'__VARCONFENABLED__', $scheck);
12213 $scheck = preg_replace(
'/\$user->id/',
'__VARUSERID__', $scheck);
12214 $scheck = preg_replace(
'/\$user->hasRight/',
'__VARUSERHASRIGHT__', $scheck);
12215 $scheck = preg_replace(
'/\$user->rights/',
'__VARUSERHASRIGHT__', $scheck);
12216 $scheck = preg_replace(
'/\$user->admin/',
'__VARUSERISADMIN__', $scheck);
12217 $scheck = preg_replace(
'/\(\$db\)/',
'__VARDB__', $scheck);
12218 $scheck = preg_replace(
'/\$langs/',
'__VARLANGSTRANS__', $scheck);
12219 $scheck = preg_replace(
'/\$mysoc/',
'__VARMYSOC__', $scheck);
12220 $scheck = preg_replace(
'/\$action/',
'__VARACTION__', $scheck);
12221 $scheck = preg_replace(
'/\$mainmenu/',
'__VARMAINMENU__', $scheck);
12222 $scheck = preg_replace(
'/\$leftmenu/',
'__VARLEFTMENU__', $scheck);
12223 $scheck = preg_replace(
'/\$websitepage/',
'__VARWEBSITEPAGE__', $scheck);
12224 $scheck = preg_replace(
'/\$website/',
'__VARWEBSITE__', $scheck);
12225 $scheck = preg_replace(
'/\$objectoffield/',
'__VAROBJECTOFFIELD__', $scheck);
12226 $scheck = preg_replace(
'/\$object/',
'__VAROBJECT__', $scheck);
12227 $scheck = preg_replace(
'/\$var/',
'__VARVAR__', $scheck);
12230 $scheck = preg_replace(
'/\$soc->canvas/',
'__VARSOCCANVAS__', $scheck);
12231 $scheck = preg_replace(
'/\$obj->canvas/',
'__VAROBJCANVAS__', $scheck);
12234 if (strpos($scheck,
'$') !==
false) {
12235 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);
12236 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;
12241 $forbiddenphpstrings = array(
'_ENV',
'_SESSION',
'_COOKIE',
'_GET',
'_GLOBAL',
'_POST',
'_REQUEST',
'ReflectionFunction',
'SplFileObject',
'SplTempFileObject');
12243 if (empty($dolibarr_main_restrict_eval_methods)) {
12247 $forbiddenphpfunctions = array();
12248 $forbiddenphpmethods = array();
12250 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"override_function",
"session_id",
"session_create_id",
"session_regenerate_id"));
12251 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"get_defined_functions",
"get_defined_vars",
"get_defined_constants",
"get_declared_classes"));
12252 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"function",
"call_user_func",
"call_user_func_array"));
12254 $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"));
12255 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"usort",
"uasort",
"uksort",
"preg_replace_callback",
"preg_replace_callback_array",
"header_register_callback"));
12256 $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"));
12257 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"spl_autoload_register",
"spl_autoload_unregister",
"iterator_apply",
"session_set_save_handler"));
12258 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"forward_static_call",
"forward_static_call_array",
"register_postsend_function"));
12260 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"ob_start"));
12262 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"require",
"include",
"require_once",
"include_once"));
12263 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"exec",
"passthru",
"shell_exec",
"system",
"proc_open",
"popen"));
12264 $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"));
12265 $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", ));
12266 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"putenv",
"dl",
"apache_child_terminate",
"apache_setenv"));
12267 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"posix_kill",
"posix_setuid",
"posix_setgid"));
12268 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_eval",
"dol_eval_new",
"dol_eval_standard",
"executeCLI",
"verifCond",
"GETPOST",
"dolEncrypt",
"dolDecrypt"));
12269 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"eval",
"create_function",
"assert",
"mb_ereg_replace"));
12270 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"readline_completion_function",
"readline_callback_handler_install"));
12271 $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"));
12272 $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"));
12273 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"require",
"include"));
12276 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"base64" .
"_" .
"decode",
"rawurl" .
"decode",
"url" .
"decode",
"str" .
"_rot13",
"hex" .
"2bin",
"printf",
"sprintf"));
12277 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_concat",
"dol_concatdesc"));
12286 $forbiddenphpmethods = array_merge($forbiddenphpmethods, array(
'invoke',
'invokeArgs'));
12294 $forbiddenphpregex =
'global\s*\$';
12295 $forbiddenphpregex .=
'|';
12296 $forbiddenphpregex .=
'\b(' . implode(
'|', $forbiddenphpfunctions) .
')\b';
12298 $forbiddenphpmethodsregex =
'->(' . implode(
'|', $forbiddenphpmethods) .
')';
12302 $oldstringtoclean = $s;
12303 $s = str_ireplace($forbiddenphpstrings,
'__forbiddenstring__', $s);
12304 $s = preg_replace(
'/' . $forbiddenphpregex .
'/i',
'__forbiddenstring__', $s);
12305 $s = preg_replace(
'/' . $forbiddenphpmethodsregex .
'/i',
'__forbiddenstring__', $s);
12307 }
while ($oldstringtoclean != $s);
12309 if (strpos($s,
'__forbiddenstring__') !==
false) {
12310 dol_syslog(
'Bad string syntax to evaluate: ' . $s, LOG_WARNING);
12311 return 'Bad string syntax to evaluate: ' . $s;
12315 if (!empty($dolibarr_main_restrict_eval_methods)) {
12318 $pattern =
'/([\s\w\'\]\"]+)\(/';
12320 $matches = array();
12321 preg_match_all($pattern, $s, $matches);
12323 if (count($matches)) {
12324 foreach ($matches[1] as $m) {
12330 if (!preg_match(
'/new ([A-Z][\w]+)/i', $m, $reg)) {
12331 if (!in_array($m, $dolibarr_main_restrict_eval_methods_array)) {
12332 if ($m !=
"'" && $m !=
'"') {
12333 dol_syslog(
'Bad string syntax to evaluate: ' . $s, LOG_WARNING);
12334 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;
12338 if (!class_exists($reg[1])) {
12339 dol_syslog(
'Bad string syntax to evaluate: Class "'.$reg[1].
'" does not exist. ' . $s, LOG_WARNING);
12340 return 'Bad string syntax to evaluate. Class "'.$reg[1].
'" does not exist. ' . $s;
12342 $parents = class_parents($reg[1]);
12343 if (!in_array(
'CommonObject', $parents)) {
12344 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);
12345 return 'Bad string syntax to evaluate. Class "'.$reg[1].
'" is not allowed because only classes extended CommonObject can be used in dynamic evaluation. ' . $s;
12351 $forbiddenphpregex =
'global\s*\$';
12352 $forbiddenphpregex .=
'|';
12353 $forbiddenphpregex .=
'}\s*\[';
12354 $forbiddenphpregex .=
'|';
12355 $forbiddenphpregex .=
'\)\s*\(';
12359 $oldstringtoclean = $s;
12360 $s = str_ireplace($forbiddenphpstrings,
'__forbiddenstring__', $s);
12361 $s = preg_replace(
'/' . $forbiddenphpregex .
'/i',
'__forbiddenstring__', $s);
12364 }
while ($oldstringtoclean != $s);
12366 if (strpos($s,
'__forbiddenstring__') !==
false) {
12367 dol_syslog(
'Bad string syntax to evaluate: ' . $s, LOG_WARNING);
12368 return 'Bad string syntax to evaluate: ' . $s;
12374 $isObBufferActive =
true;
12375 $tmps = $hideerrors ? @eval(
'return ' . $s .
';') : eval(
'return ' . $s .
';');
12376 $tmpo = ob_get_clean();
12377 $isObBufferActive =
false;
12379 print
'Bad string syntax to evaluate. Some data were output when it should not when evaluating: ' . $s;
12382 }
catch (Error $e) {
12383 if ($isObBufferActive) {
12385 $tmpo = ob_get_clean();
12386 $isObBufferActive =
false;
12388 $error =
'dol_eval try/catch error : ';
12389 $error .= $e->getMessage();
12391 return 'Exception during evaluation: ' . $s;
12404 return (trim($element) !=
'');
12417 if (empty($codelang)) {
12421 if ($codelang ==
'auto') {
12422 return '<span class="fa fa-language"></span>';
12425 $langtocountryflag = array(
12427 'ca_ES' =>
'catalonia',
12431 'sw_SW' =>
'unknown',
12441 if (isset($langtocountryflag[$codelang])) {
12442 $flagImage = $langtocountryflag[$codelang];
12444 $tmparray = explode(
'_', $codelang);
12445 $flagImage = empty($tmparray[1]) ? $tmparray[0] : $tmparray[1];
12450 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
12451 $morecss = $reg[1];
12456 return '<span class="flag-sprite ' . strtolower($flagImage) . ($morecss ?
' ' . $morecss :
'') .
'"' . ($moreatt ?
' ' . $moreatt :
'') . (!$notitlealt ?
' title="' . $codelang .
'"' :
'') .
'></span>';
12470 if (empty($countrycode)) {
12474 if (strtoupper($countrycode) ==
'MQ') {
12477 if (strtoupper($countrycode) ==
'SE') {
12480 if (strtoupper($countrycode) ==
'CH') {
12481 if (
$mysoc->country_code ==
'FR') {
12484 if (
$mysoc->country_code ==
'DE') {
12487 if (
$mysoc->country_code ==
'IT') {
12669 $buildprimarykeytotest = strtolower($countrycode) .
'-' . strtoupper($countrycode);
12670 if (in_array($buildprimarykeytotest, $locales)) {
12671 return strtolower($countrycode) .
'_' . strtoupper($countrycode);
12674 if (function_exists(
'locale_get_primary_language') && function_exists(
'locale_get_region')) {
12675 foreach ($locales as $locale) {
12676 $locale_language = locale_get_primary_language($locale);
12677 $locale_region = locale_get_region($locale);
12678 if (strtoupper($countrycode) == $locale_region) {
12680 return strtolower($locale_language) .
'_' . strtoupper($locale_region);
12684 dol_syslog(
"Warning Extension php-intl is not available", LOG_WARNING);
12722 global $hookmanager, $db;
12724 if (isset($conf->modules_parts[
'tabs'][$type]) && is_array($conf->modules_parts[
'tabs'][$type])) {
12725 foreach ($conf->modules_parts[
'tabs'][$type] as $value) {
12726 $values = explode(
':', $value);
12729 if ($mode ==
'add' && !preg_match(
'/^\-/', $values[1])) {
12730 if (count($values) !== 6) {
12731 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);
12738 if ($values[0] != $type) {
12746 $posstart = strpos($str,
'(');
12747 if ($posstart > 0) {
12748 $posend = strpos($str,
')');
12749 if ($posstart > 0) {
12750 $res1 = substr($str, $posstart + 1, $posend - $posstart - 1);
12751 if (is_numeric($res1)) {
12752 $postab = (int) $res1;
12753 $values[1] =
'+' . substr($str, $posend + 1);
12758 global $objectoffield;
12766 if ($filterorigmodule) {
12767 if (strpos($values[3],
'@')) {
12768 if ($filterorigmodule !=
'external') {
12772 if ($filterorigmodule !=
'core') {
12777 $langs->load($values[3]);
12780 if (preg_match(
'/SUBSTITUTION_([^_]+)/i', $values[2], $reg)) {
12782 $substitutionarray = array();
12787 $labeltemp = explode(
',', $values[2]);
12788 $label = $langs->trans($labeltemp[0]);
12790 if (!empty($labeltemp[1]) && is_object(
$object) && !empty(
$object->id)) {
12792 $classtoload = $labeltemp[1];
12793 if (class_exists($classtoload)) {
12794 $obj =
new $classtoload($db);
12795 $function = $labeltemp[3];
12796 if ($obj && $function && method_exists($obj, $function)) {
12798 $nbrec = $obj->$function(
$object->id, $obj);
12799 if (!empty($nbrec)) {
12800 $label .=
'<span class="badge marginleftonlyshort">' . $nbrec .
'</span>';
12806 $url = preg_replace(
'/__ID__/i', ((is_object(
$object) && !empty(
$object->id)) ?
$object->id :
''), $values[5]);
12807 $link = parse_url($url);
12809 if (isset($link[
'query'])) {
12810 parse_str($link[
'query'], $query);
12813 $newtab[1] = $label;
12814 $newtab[2] = str_replace(
'+',
'', $values[1]);
12818 $head = array_merge(array_slice($head, 0, $postab), array($newtab), array_slice($head, $postab));
12819 } elseif ($mode ==
'remove' && preg_match(
'/^\-/', $values[1])) {
12820 if ($values[0] != $type) {
12823 $tabname = str_replace(
'-',
'', $values[1]);
12824 foreach ($head as $key => $val) {
12825 $condition = (!empty($values[3]) ?
verifCond($values[3],
'2') : 1);
12827 if ($head[$key][2] == $tabname && $condition) {
12828 unset($head[$key]);
12837 if (!empty($hookmanager)) {
12838 $parameters = array(
'object' =>
$object,
'mode' => $mode,
'head' => &$head,
'filterorigmodule' => $filterorigmodule);
12840 $reshook = $hookmanager->executeHooks(
'completeTabsHead', $parameters,
$object);
12841 if ($reshook > 0) {
12842 $head = $hookmanager->resArray;
12844 $head = array_merge($head, $hookmanager->resArray);
12863 global $conf, $hookmanager, $user, $langs;
12865 global $micro_start_time;
12867 if ($zone ==
'private') {
12868 print
"\n" .
'<!-- Common footer for private page -->' .
"\n";
12870 print
"\n" .
'<!-- Common footer for public page -->' .
"\n";
12874 print
"\n<!-- A div to store page_y POST parameter -->\n";
12875 print
'<div id="page_y" style="display: none;">' . (
GETPOST(
'page_y') ?
GETPOST(
'page_y') :
'') .
'</div>' .
"\n";
12877 $parameters = array(
'zone' => $zone);
12880 $reshook = $hookmanager->executeHooks(
'printCommonFooter', $parameters, $tmpobject, $action);
12881 if (empty($reshook)) {
12887 if (!empty($conf->use_javascript_ajax)) {
12888 print
"\n<!-- A script section to add menuhider handler on backoffice, manage focus and mandatory fields, tuning info, ... -->\n";
12889 print
'<script>' .
"\n";
12890 print
'jQuery(document).ready(function() {' .
"\n";
12892 if ($zone ==
'private' && empty($conf->dol_use_jmobile)) {
12894 print
'/* JS CODE TO ENABLE to manage handler to switch left menu page (menuhider) */' .
"\n";
12895 print
'jQuery("li.menuhider").click(function(event) {';
12896 print
' if (!$( "body" ).hasClass( "sidebar-collapse" )){ event.preventDefault(); }' .
"\n";
12897 print
' console.log("We click on .menuhider");' .
"\n";
12898 print
' $("body").toggleClass("sidebar-collapse")' .
"\n";
12899 print
'});' .
"\n";
12903 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"])))) {
12904 print
'/* JS CODE TO ENABLE to manage focus and mandatory form fields */' .
"\n";
12905 $relativepathstring = $_SERVER[
"PHP_SELF"];
12907 if (constant(
'DOL_URL_ROOT')) {
12908 $relativepathstring = preg_replace(
'/^' . preg_quote(constant(
'DOL_URL_ROOT'),
'/') .
'/',
'', $relativepathstring);
12910 $relativepathstring = preg_replace(
'/^\//',
'', $relativepathstring);
12911 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
12914 if (!empty($user->default_values[$relativepathstring][
'focus'])) {
12915 foreach ($user->default_values[$relativepathstring][
'focus'] as $defkey => $defval) {
12917 if ($defkey !=
'_noquery_') {
12918 $tmpqueryarraytohave = explode(
'&', $defkey);
12920 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
12921 $tmpquerytohaveparam = explode(
'=', $tmpquerytohave);
12923 if (!GETPOSTISSET($tmpquerytohaveparam[0]) || ($tmpquerytohaveparam[1] !=
GETPOST($tmpquerytohaveparam[0]))) {
12927 if (!$foundintru) {
12936 print
'console.log("set the focus by executing jQuery(...).focus();")' .
"\n";
12937 foreach ($defval as $paramkey => $paramval) {
12939 print
'jQuery("input[name=\'' . $paramkey .
'\']
").focus();' . "\n
";
12940 print 'jQuery("textarea[
name=\
'' . $paramkey .
'\']
").focus();' . "\n
"; // TODO KO with ckeditor
12941 print 'jQuery("select[
name=\
'' . $paramkey .
'\']
").focus();' . "\n
"; // Not really useful, but we keep it in case of.
12946 if (!empty($user->default_values[$relativepathstring]['mandatory'])) {
12947 foreach ($user->default_values[$relativepathstring]['mandatory'] as $defkey => $defval) {
12949 if ($defkey != '_noquery_') {
12950 $tmpqueryarraytohave = explode('&', $defkey);
12952 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
12953 $tmpquerytohaveparam = explode('=', $tmpquerytohave);
12954 //print "console.log(
'".$tmpquerytohaveparam[0]." ".$tmpquerytohaveparam[1]." ".GETPOST($tmpquerytohaveparam[0])."');
";
12955 if (!GETPOSTISSET($tmpquerytohaveparam[0]) || ($tmpquerytohaveparam[1] != GETPOST($tmpquerytohaveparam[0]))) {
12959 if (!$foundintru) {
12962 //var_dump($defkey.'-'.$qualified);
12968 print 'console.log("set the js code to manage fields that are
set as mandatory
");' . "\n
";
12970 foreach ($defval as $paramkey => $paramval) {
12971 // Solution 1: Add handler on submit to check if mandatory fields are empty
12972 print 'var form = $(\'[name="'.dol_escape_js($paramkey).'"]\').closest("form
");'."\n
";
12973 print "form.on(
'submit',
function(event) {
12974 var submitter = \$(
this).find(
':submit:focus').get(0);
12975 var buttonName = submitter ? \$(submitter).attr(
'name') :
'save';
12977 if (buttonName ==
'cancel') {
12978 console.log(
'We click on cancel button so we accept submit with no need to check mandatory fields');
12982 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');
12984 var tmpvalue = jQuery(
'[name=\"".dol_escape_js($paramkey)."\"]').val();
12985 let tmptypefield = jQuery(
'[name=\"".dol_escape_js($paramkey)."\"]').prop(
'nodeName').toLowerCase();
12987 if (tmptypefield ==
'textarea') {
12989 var tmpeditor = (typeof CKEDITOR !==
'undefined') ? CKEDITOR.instances[
'".dol_escape_js($paramkey)."'] : null;
12991 tmpvalue = tmpeditor.getData();
12992 console.log(
'For textarea tmpvalue is '+tmpvalue);
12996 let tmpvalueisempty =
false;
12997 if (tmpvalue ===
null || tmpvalue === undefined || tmpvalue ===
'' || tmpvalue === -1 || tmpvalue ===
'-1') {
12998 tmpvalueisempty =
true;
13000 if (tmpvalue ===
'0' && (tmptypefield ==
'select' || tmptypefield ==
'input')) {
13001 tmpvalueisempty =
true;
13003 if (tmpvalueisempty && buttonName !==
'cancel') {
13004 console.log(
'field has type '+tmptypefield+
' and is empty, we cancel the submit');
13005 event.preventDefault();
13006 event.stopPropagation();
13008 alert(
'".dol_escape_js($langs->transnoentitiesnoconv("ErrorFieldRequired", $paramkey).' (
'.$langs->transnoentitiesnoconv("CustomMandatoryFieldRule").')
')."');
13012 console.log(
'field has type '+tmptypefield+
' and is defined to '+tmpvalue);
13017 // Solution 2: Add property 'required' on input
13018 // so browser will check value and try to focus on it when submitting the form.
13019 //print 'setTimeout(function() {'; // If we want to wait that ckeditor beuatifier has finished its job.
13020 //print 'jQuery("input[
name=\
''.$paramkey.
'\']
").prop(\'required\',true);'."\n
";
13021 //print 'jQuery("textarea[
id=\
''.$paramkey.
'\']
").prop(\'required\',true);'."\n
";
13022 //print 'jQuery("select[
name=\
''.$paramkey.
'\']
").prop(\'required\',true);'."\n
";*/
13023 //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
";
13024 //print 'jQuery("select[
name=\
''.$paramkey.
'\'] option[value=\
'-1\']").prop(\'value\', \'\');'.
"\n";
13030 print
'jQuery(\':input[name="' .
dol_escape_js($paramkey) .
'"]\').closest("tr").find("td:first").addClass("fieldrequired");' .
"\n";
13034 print
'jQuery("input[name=\'cancel\']").click(function() {
13035 console.log("We click on cancel button so removed all required attribute");
13036 jQuery("input, textarea, select").each(function(){this.removeAttribute(\'required\');});
13043 print
'});' .
"\n";
13046 if (!empty($_SERVER[
'MAIN_SHOW_TUNING_INFO']) ||
getDolGlobalString(
'MAIN_SHOW_TUNING_INFO')) {
13048 print
"/* JS CODE TO ENABLE to add memory info */\n";
13049 print
'window.console && console.log("';
13054 if (!empty($micro_start_time)) {
13055 $micro_end_time = microtime(
true);
13056 print
' - Build time: ' . ceil(1000 * ($micro_end_time - $micro_start_time)) .
' ms';
13059 if (function_exists(
"memory_get_usage")) {
13060 print
' - Mem: ' . memory_get_usage();
13062 if (function_exists(
"memory_get_peak_usage")) {
13063 print
' - Real mem peak: ' . memory_get_peak_usage(
true);
13065 if (function_exists(
"zend_loader_file_encoded")) {
13066 print
' - Zend encoded file: ' . (zend_loader_file_encoded() ?
'yes' :
'no');
13068 print
'");' .
"\n";
13071 print
"\n" .
'</script>' .
"\n";
13077 foreach ($tmptagarray as $tmptag) {
13079 print
"<!-- JS CODE TO ENABLE for google analtics tag -->\n";
13081 <!-- Global site tag (gtag.js) - Google Analytics -->
13082 <script nonce="' .
getNonce() .
'" async src="https://www.googletagmanager.com/gtag/js?id=' . trim($tmptag) .
'"></script>
13084 window.dataLayer = window.dataLayer || [];
13085 function gtag(){dataLayer.push(arguments);}
13086 gtag(\'js\', new Date());
13088 gtag(\'config\', \'' . trim($tmptag) .
'\');
13095 // Add Xdebug coverage of code
13096 if (defined('XDEBUGCOVERAGE
')) {
13097 print_r(xdebug_get_code_coverage());
13100 // Output string from hooks
13101 if (!empty($hookmanager->resPrint)) {
13102 print $hookmanager->resPrint;
13105 // Add DebugBar data
13106 if ($user->hasRight('debugbar
', 'read
')) {
13108 if ($debugbar instanceof DebugBar\DebugBar) {
13109 if (isset($debugbar['time
'])) {
13110 // @phan-suppress-next-line PhanPluginUnknownObjectMethodCall
13111 $debugbar['time
']->stopMeasure('pageaftermaster
');
13113 print '<!-- Output debugbar data -->
' . "\n";
13114 $renderer = $debugbar->getJavascriptRenderer();
13115 print $renderer->render();
13117 } elseif (count($conf->logbuffer)) { // If there is some logs in buffer to show
13119 print "<!-- Start of log output\n";
13120 //print '<div
class=
"hidden">
'."\n";
13121 foreach ($conf->logbuffer as $logline) {
13122 print $logline . "<br>\n";
13124 //print '</div>
'."\n";
13125 print "End of log output -->\n";
13139function dolExplodeIntoArray($string, $delimiter = ';
', $kv = '=
')
13141 if (is_null($string)) {
13145 if (preg_match('/^\[.*\]$/sm
', $delimiter) || preg_match('/^\(.*\)$/sm
', $delimiter)) {
13146 // This is a regex string
13147 $newdelimiter = $delimiter;
13149 // This is a simple string
13150 // @phan-suppress-next-line PhanPluginSuspiciousParamPositionInternal
13151 $newdelimiter = preg_quote($delimiter, '/
');
13154 if ($a = preg_split('/
' . $newdelimiter . '/
', $string)) {
13156 foreach ($a as $s) { // each part
13158 if ($pos = strpos($s, $kv)) { // key/value delimiter
13159 $ka[trim(substr($s, 0, $pos))] = trim(substr($s, $pos + strlen($kv)));
13160 } else { // key delimiter not found
13178function dolExplodeKeepIfQuotes($input)
13180 // Use regexp to capture words and section in quotes
13181 $matches = array();
13182 preg_match_all('/
"([^"]*)
"|\'([^\']*)\'|(\S+)/', $input, $matches);
13184 // Merge result and delete empty values
13186 $result = array_map(
13193 static function ($a, $b, $c) {
13209 return array_values(array_filter(
13217 static function ($val) {
13218 return $val !== '';
13230function dol_set_focus($selector)
13232 print "\n
" . '<!-- Set focus onto a specific field -->' . "\n
";
13233 print '<script nonce="' . getNonce() . '">jQuery(document).ready(function() { console.log("Force focus by
dol_set_focus"); jQuery("' . dol_escape_js($selector) . '").focus(); });</script>' . "\n
";
13244function dol_getmypid()
13246 if (!function_exists('getmypid')) {
13247 return mt_rand(99900000, 99965535);
13249 return getmypid(); // May be a number on 64 bits (depending on OS)
13275function natural_search($fields, $value, $mode = 0, $nofirstand = 0, $sqltoadd = '')
13277 global $db, $langs;
13279 $value = trim($value);
13282 $value = preg_replace('/\*/', '%', $value); // Replace * with %
13285 $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
13288 $value = preg_replace('/\s*\|\s*/', '|', $value);
13290 // Split criteria on ' ' but not if we are inside quotes.
13291 // For mode 3, the split is done later on the , only and not on the ' '.
13292 if ($mode != -3 && $mode != 3) {
13293 $crits = dolExplodeKeepIfQuotes($value);
13295 $crits = array($value);
13299 if (!is_array($fields)) {
13300 $fields = array($fields);
13302 $i1 = 0; // count the nb of "and
" criteria added (all fields / criteria)
13303 foreach ($crits as $crit) { // Loop on each AND criteria
13304 $crit = trim($crit);
13305 $i2 = 0; // count the nb of valid criteria added for this this first criteria
13308 foreach ($fields as $field) {
13310 $tmpcrits = explode('|', $crit);
13311 $i3 = 0; // count the nb of valid criteria added for this current field
13312 foreach ($tmpcrits as $tmpcrit) {
13313 if ($tmpcrit !== '0' && empty($tmpcrit)) {
13316 $tmpcrit = trim($tmpcrit);
13318 $newres .= (($i2 > 0 || $i3 > 0) ? ' OR ' : '');
13321 $newcrit = preg_replace('/([!<>=]+)/', '', $tmpcrit);
13324 preg_match('/([!<>=]+)/', $tmpcrit, $reg);
13325 if (!empty($reg[1])) {
13326 $operator = $reg[1];
13328 if ($newcrit != '') {
13329 $numnewcrit = price2num($newcrit);
13330 if (is_numeric($numnewcrit)) {
13331 $newres .= $db->sanitize($field) . ' ' . $operator . ' ' . ((float) $numnewcrit); // should be a numeric
13333 $newres .= '1 = 2'; // force false, we received a corrupted data
13335 $i3++; // a criteria was added to string
13338 $i2++; // a criteria for 1 more field was added to string
13339 } elseif ($mode == 2 || $mode == -2) {
13340 $crit = preg_replace('/[^\-0-9,]/', '', $crit); // ID are always integer
13341 $newres .= ($i2 > 0 ? ' OR ' : '') . $db->sanitize($field) . " " . ($mode == -2 ? 'NOT ' : '');
13342 $newres .= $crit ? "IN (
" . $db->sanitize($db->escape($crit)) . ")
" : "IN (0)
";
13344 $newres .= ' OR ' . $db->sanitize($field) . ' IS NULL';
13346 $i2++; // a criteria for 1 more field was added to string
13347 } elseif ($mode == 3 || $mode == -3) {
13348 $tmparray = explode(',', $crit);
13349 if (count($tmparray)) {
13351 foreach ($tmparray as $val) {
13353 if ($val) { // TODO Test with if ($val !== '') {
13354 $listofcodes .= ($listofcodes ? ',' : '');
13355 $listofcodes .= "'" . $db->escape($val) . "'";
13358 $newres .= ($i2 > 0 ? ' OR ' : '') . $db->sanitize($field) . " " . ($mode == -3 ? 'NOT ' : '') . "IN (
" . $db->sanitize($listofcodes, 1, 0, 1) . ")
";
13359 $i2++; // a criteria for 1 more field was added to string
13362 $newres .= ' OR ' . $db->sanitize($field) . ' IS NULL';
13364 } elseif ($mode == 4) {
13365 $tmparray = explode(',', $crit);
13366 if (count($tmparray)) {
13368 foreach ($tmparray as $val) {
13371 $newres .= ($i2 > 0 ? " OR (
" : "(
") . $db->sanitize($field) . " LIKE
'" . $db->escape($val) . ",%'";
13372 $newres .= ' OR ' . $db->sanitize($field) . " =
'" . $db->escape($val) . "'";
13373 $newres .= ' OR ' . $db->sanitize($field) . " LIKE
'%," . $db->escape($val) . "'";
13374 $newres .= ' OR ' . $db->sanitize($field) . " LIKE
'%," . $db->escape($val) . ",%'";
13376 $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)
13380 } else { // $mode=0
13381 $tmpcrits = explode('|', $crit);
13382 $i3 = 0; // count the nb of valid criteria added for the current couple criteria/field
13383 foreach ($tmpcrits as $tmpcrit) { // loop on each OR criteria
13384 if ($tmpcrit !== '0' && empty($tmpcrit)) {
13387 $tmpcrit = trim($tmpcrit);
13389 if ($tmpcrit == '^$' || strpos($crit, '!') === 0) { // If we search empty, we must combined different OR fields with AND
13390 $newres .= (($i2 > 0 || $i3 > 0) ? ' AND ' : '');
13392 $newres .= (($i2 > 0 || $i3 > 0) ? ' OR ' : '');
13395 $isSellist = false;
13396 $table = $label = $key = null;
13398 if (strpos($field, 'ef.') === 0) {
13399 $extrafieldName = substr($field, 3);
13400 $extrafields = new ExtraFields($db);
13401 $extrafields->fetch_name_optionals_label('product');
13403 if (isset($extrafields->attributes['product']['type'][$extrafieldName]) && $extrafields->attributes['product']['type'][$extrafieldName] === 'sellist') {
13405 $paramArray = $extrafields->attributes['product']['param'][$extrafieldName]['options'] ?? [];
13406 $param = array_key_first($paramArray);
13407 list($table, $label, $key) = explode(':', $param);
13411 if (preg_match('/\.(id|rowid)$/', $field)) { // Special case for rowid that is sometimes a ref so used as a search field
13412 $newres .= $db->sanitize($field) . " =
" . (is_numeric($tmpcrit) ? ((float) $tmpcrit) : '0');
13414 $tmpcrit2 = $tmpcrit;
13420 $newres .= $field . " IN (SELECT t.
" . $db->sanitize($key) . " FROM
" . $db->prefix() . $db->sanitize($table) . " AS t WHERE t.
" . $db->sanitize($label) . " LIKE
'%" . $db->escape($tmpcrit2) . "%')
";
13422 if (preg_match('/^!/', $tmpcrit)) {
13423 $tmps .= $db->sanitize($field) . " NOT LIKE
"; // ! as exclude character
13424 $tmpcrit2 = preg_replace('/^!/', '', $tmpcrit2);
13426 $tmps .= $db->sanitize($field) . " LIKE
";
13430 if (preg_match('/^[\^\$]/
', $tmpcrit)) {
13432 $tmpcrit2 = preg_replace('/^[\^\$]/
', '', $tmpcrit2);
13434 if (preg_match('/[\^\$]$/
', $tmpcrit)) {
13436 $tmpcrit2 = preg_replace('/[\^\$]$/
', '', $tmpcrit2);
13439 if ($tmpcrit2 == '' || preg_match('/^!/
', $tmpcrit)) {
13440 $tmps = "(" . $tmps;
13443 $newres .= $tmpbefore;
13444 $newres .= $db->escape($tmpcrit2);
13445 $newres .= $tmpafter;
13447 if ($tmpcrit2 == '' || preg_match('/^!/', $tmpcrit)) {
13448 $newres .= " OR
" . $db->sanitize($field) . " IS NULL)
";
13456 $i2++; // a criteria for 1 more field was added to string
13461 $newres .= ($newres ? '' : ' OR ').str_replace('__KEYTOSEARCH__', $db->escape($crit), $sqltoadd);
13465 $res = $res . ($res ? ' AND ' : '') . ($i2 > 1 ? '(' : '') . $newres . ($i2 > 1 ? ')' : '');
13469 $res = ($nofirstand ? "" : " AND
") . "(
" . $res . ")
";
13480function showDirectDownloadLink($object)
13485 $url = $object->getLastMainDocLink($object->element);
13487 $out .= img_picto($langs->trans("PublicDownloadLinkDesc
"), 'globe') . ' <span class="opacitymedium
">' . $langs->trans("DirectDownloadLink
") . '</span><br>';
13489 $out .= '<div class="urllink
"><input type="text
" id="directdownloadlink
" class="quatrevingtpercent
" value="' . $url . '"></div>';
13490 $out .= ajax_autoselect("directdownloadlink
", '');
13492 $out .= '<div class="urllink
">' . $langs->trans("FileNotShared
") . '</div>';
13506function getImageFileNameForSize($file, $extName, $extImgTarget = '')
13508 $dirName = dirname($file);
13509 if ($dirName == '.') {
13513 if (!in_array($extName, array('', '_small', '_mini'))) {
13514 return 'Bad parameter extName';
13517 $fileName = preg_replace('/(\.gif|\.jpeg|\.jpg|\.png|\.bmp|\.webp)$/i', '', $file); // We remove image extension, whatever is its case
13518 $fileName = basename($fileName);
13520 if (empty($extImgTarget)) {
13521 $extImgTarget = (preg_match('/\.jpg$/i', $file) ? '.jpg' : '');
13523 if (empty($extImgTarget)) {
13524 $extImgTarget = (preg_match('/\.jpeg$/i', $file) ? '.jpeg' : '');
13526 if (empty($extImgTarget)) {
13527 $extImgTarget = (preg_match('/\.gif$/i', $file) ? '.gif' : '');
13529 if (empty($extImgTarget)) {
13530 $extImgTarget = (preg_match('/\.png$/i', $file) ? '.png' : '');
13532 if (empty($extImgTarget)) {
13533 $extImgTarget = (preg_match('/\.bmp$/i', $file) ? '.bmp' : '');
13535 if (empty($extImgTarget)) {
13536 $extImgTarget = (preg_match('/\.webp$/i', $file) ? '.webp' : '');
13539 if (!$extImgTarget) {
13545 $subdir = 'thumbs/';
13548 return ($dirName ? $dirName . '/' : '') . $subdir . $fileName . $extName . $extImgTarget; // New filename for thumb
13561function getAdvancedPreviewUrl($modulepart, $relativepath, $alldata = 0, $param = '')
13563 global $conf, $langs;
13565 if (empty($conf->use_javascript_ajax)) {
13569 $isAllowedForPreview = dolIsAllowedForPreview($relativepath);
13571 if ($alldata == 1) {
13572 if ($isAllowedForPreview) {
13573 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));
13579 // old behavior, return a string
13580 if ($isAllowedForPreview) {
13581 $tmpurl = DOL_URL_ROOT . '/document.php?modulepart=' . urlencode($modulepart) . '&attachment=0&file=' . urlencode($relativepath) . ($param ? '&' . $param : '');
13582 $title = $langs->transnoentities("Preview
");
13583 //$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().
13584 //$tmpurl = 'file='.urlencode("'-alert(document.domain)-'_small.jpg
"); // An example of tmpurl that should be blocked by the dol_escape_uri()
13586 // 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,
13587 // 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.
13588 // Using the dol_escape_uri guarantee that we encode for URI so decode retrieve original expected value.
13589 return 'javascript:' . dol_escape_uri('document_preview(\'' . dol_escape_js($tmpurl) . '\', \'' . dol_escape_js(dol_mimetype($relativepath)) . '\', \'' . dol_escape_js($title) . '\')');
13601function getLabelSpecialCode($idcode)
13605 $arrayspecialines = array(1 => 'Transport', 2 => 'EcoTax', 3 => 'Option');
13606 if ($idcode > 10) {
13607 return 'Module ID ' . $idcode;
13609 if (!empty($arrayspecialines[$idcode])) {
13610 return $langs->trans($arrayspecialines[$idcode]);
13623function ajax_autoselect($htmlname, $addlink = '', $textonlink = 'Link')
13626 $out = '<script nonce="
' . getNonce() . '">
13627 jQuery(document).ready(function () {
13628 jQuery("' . ((strpos($htmlname, '.
') === 0 ? '' : '#
') . $htmlname) . '").click(function() { jQuery(this).select(); } );
13632 if ($textonlink === 'image') {
13633 $out .= ' <a href="' . $addlink . '" target="_blank
" rel="noopener noreferrer
">' . img_picto('', 'globe') . '</a>';
13635 $out .= ' <a href="' . $addlink . '" target="_blank
" rel="noopener noreferrer
">' . $langs->trans("Link") . '</a>';
13648function dolIsAllowedForPreview($file)
13650 // Check .noexe extension in filename
13651 if (preg_match('/\.noexe$/i', $file)) {
13655 // Check mime types
13656 $mime_preview = array('bmp', 'jpeg', 'png', 'gif', 'tiff', 'pdf', 'plain', 'css', 'webp', 'webm', 'mp4');
13657 if (getDolGlobalString('MAIN_ALLOW_SVG_FILES_AS_IMAGES')) {
13658 $mime_preview[] = 'svg+xml';
13660 if (getDolGlobalString('MAIN_ALLOW_XML_FILES_AS_PREVIEW')) {
13661 $mime_preview[] = 'xml';
13664 //$mime_preview[]='vnd.oasis.opendocument.presentation';
13665 //$mime_preview[]='archive';
13666 $num_mime = array_search(dol_mimetype($file, '', 1), $mime_preview);
13667 if ($num_mime !== false) {
13671 // By default, not allowed for preview
13685function dol_mimetype($file, $default = 'application/octet-stream', $mode = 0)
13688 $imgmime = 'other.png';
13689 $famime = 'file-o';
13692 $tmpfile = preg_replace('/\.noexe$/', '', $file);
13694 // Plain text files
13695 if (preg_match('/\.txt$/i', $tmpfile)) {
13696 $mime = 'text/plain';
13697 $imgmime = 'text.png';
13698 $famime = 'file-alt';
13699 } elseif (preg_match('/\.rtx$/i', $tmpfile)) {
13700 $mime = 'text/richtext';
13701 $imgmime = 'text.png';
13702 $famime = 'file-alt';
13703 } elseif (preg_match('/\.csv$/i', $tmpfile)) {
13704 $mime = 'text/csv';
13705 $imgmime = 'text.png';
13706 $famime = 'file-csv';
13707 } elseif (preg_match('/\.tsv$/i', $tmpfile)) {
13708 $mime = 'text/tab-separated-values';
13709 $imgmime = 'text.png';
13710 $famime = 'file-alt';
13711 } elseif (preg_match('/\.(cf|conf|log)$/i', $tmpfile)) {
13712 $mime = 'text/plain';
13713 $imgmime = 'text.png';
13714 $famime = 'file-alt';
13715 } elseif (preg_match('/\.ini$/i', $tmpfile)) {
13716 $mime = 'text/plain';
13717 $imgmime = 'text.png';
13719 $famime = 'file-alt';
13720 } elseif (preg_match('/\.md$/i', $tmpfile)) {
13721 $mime = 'text/plain';
13722 $imgmime = 'text.png';
13724 $famime = 'file-alt';
13725 } elseif (preg_match('/\.css$/i', $tmpfile)) {
13726 $mime = 'text/css';
13727 $imgmime = 'css.png';
13729 $famime = 'file-alt';
13730 } elseif (preg_match('/\.lang$/i', $tmpfile)) {
13731 $mime = 'text/plain';
13732 $imgmime = 'text.png';
13734 $famime = 'file-alt';
13735 } elseif (preg_match('/\.(crt|cer|key|pub)$/i', $tmpfile)) { // Certificate files
13736 $mime = 'text/plain';
13737 $imgmime = 'text.png';
13738 $famime = 'file-alt';
13739 } elseif (preg_match('/\.(html|htm|shtml)$/i', $tmpfile)) { // XML based (HTML/XML/XAML)
13740 $mime = 'text/html';
13741 $imgmime = 'html.png';
13743 $famime = 'file-alt';
13744 } elseif (preg_match('/\.(xml|xhtml)$/i', $tmpfile)) {
13745 $mime = 'text/xml';
13746 $imgmime = 'other.png';
13748 $famime = 'file-alt';
13749 } elseif (preg_match('/\.xaml$/i', $tmpfile)) {
13750 $mime = 'text/xml';
13751 $imgmime = 'other.png';
13753 $famime = 'file-alt';
13754 } elseif (preg_match('/\.bas$/i', $tmpfile)) { // Languages
13755 $mime = 'text/plain';
13756 $imgmime = 'text.png';
13758 $famime = 'file-code';
13759 } elseif (preg_match('/\.(c)$/i', $tmpfile)) {
13760 $mime = 'text/plain';
13761 $imgmime = 'text.png';
13763 $famime = 'file-code';
13764 } elseif (preg_match('/\.(cpp)$/i', $tmpfile)) {
13765 $mime = 'text/plain';
13766 $imgmime = 'text.png';
13768 $famime = 'file-code';
13769 } elseif (preg_match('/\.cs$/i', $tmpfile)) {
13770 $mime = 'text/plain';
13771 $imgmime = 'text.png';
13773 $famime = 'file-code';
13774 } elseif (preg_match('/\.(h)$/i', $tmpfile)) {
13775 $mime = 'text/plain';
13776 $imgmime = 'text.png';
13778 $famime = 'file-code';
13779 } elseif (preg_match('/\.(java|jsp)$/i', $tmpfile)) {
13780 $mime = 'text/plain';
13781 $imgmime = 'text.png';
13783 $famime = 'file-code';
13784 } elseif (preg_match('/\.php([0-9]{1})?$/i', $tmpfile)) {
13785 $mime = 'text/plain';
13786 $imgmime = 'php.png';
13788 $famime = 'file-code';
13789 } elseif (preg_match('/\.phtml$/i', $tmpfile)) {
13790 $mime = 'text/plain';
13791 $imgmime = 'php.png';
13793 $famime = 'file-code';
13794 } elseif (preg_match('/\.(pl|pm)$/i', $tmpfile)) {
13795 $mime = 'text/plain';
13796 $imgmime = 'pl.png';
13798 $famime = 'file-code';
13799 } elseif (preg_match('/\.sql$/i', $tmpfile)) {
13800 $mime = 'text/plain';
13801 $imgmime = 'text.png';
13803 $famime = 'file-code';
13804 } elseif (preg_match('/\.js$/i', $tmpfile)) {
13805 $mime = 'text/x-javascript';
13806 $imgmime = 'jscript.png';
13808 $famime = 'file-code';
13809 } elseif (preg_match('/\.odp$/i', $tmpfile)) { // Open office
13810 $mime = 'application/vnd.oasis.opendocument.presentation';
13811 $imgmime = 'ooffice.png';
13812 $famime = 'file-powerpoint';
13813 } elseif (preg_match('/\.ods$/i', $tmpfile)) {
13814 $mime = 'application/vnd.oasis.opendocument.spreadsheet';
13815 $imgmime = 'ooffice.png';
13816 $famime = 'file-excel';
13817 } elseif (preg_match('/\.odt$/i', $tmpfile)) {
13818 $mime = 'application/vnd.oasis.opendocument.text';
13819 $imgmime = 'ooffice.png';
13820 $famime = 'file-word';
13821 } elseif (preg_match('/\.mdb$/i', $tmpfile)) { // MS Office
13822 $mime = 'application/msaccess';
13823 $imgmime = 'mdb.png';
13825 } elseif (preg_match('/\.doc[xm]?$/i', $tmpfile)) {
13826 $mime = 'application/msword';
13827 $imgmime = 'doc.png';
13828 $famime = 'file-word';
13829 } elseif (preg_match('/\.dot[xm]?$/i', $tmpfile)) {
13830 $mime = 'application/msword';
13831 $imgmime = 'doc.png';
13832 $famime = 'file-word';
13833 } elseif (preg_match('/\.xlt(x)?$/i', $tmpfile)) {
13834 $mime = 'application/vnd.ms-excel';
13835 $imgmime = 'xls.png';
13836 $famime = 'file-excel';
13837 } elseif (preg_match('/\.xla(m)?$/i', $tmpfile)) {
13838 $mime = 'application/vnd.ms-excel';
13839 $imgmime = 'xls.png';
13840 $famime = 'file-excel';
13841 } elseif (preg_match('/\.xls$/i', $tmpfile)) {
13842 $mime = 'application/vnd.ms-excel';
13843 $imgmime = 'xls.png';
13844 $famime = 'file-excel';
13845 } elseif (preg_match('/\.xls[bmx]$/i', $tmpfile)) {
13846 $mime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
13847 $imgmime = 'xls.png';
13848 $famime = 'file-excel';
13849 } elseif (preg_match('/\.pps[mx]?$/i', $tmpfile)) {
13850 $mime = 'application/vnd.ms-powerpoint';
13851 $imgmime = 'ppt.png';
13852 $famime = 'file-powerpoint';
13853 } elseif (preg_match('/\.ppt[mx]?$/i', $tmpfile)) {
13854 $mime = 'application/x-mspowerpoint';
13855 $imgmime = 'ppt.png';
13856 $famime = 'file-powerpoint';
13857 } elseif (preg_match('/\.pdf$/i', $tmpfile)) { // Other
13858 $mime = 'application/pdf';
13859 $imgmime = 'pdf.png';
13860 $famime = 'file-pdf';
13861 } elseif (preg_match('/\.bat$/i', $tmpfile)) { // Scripts
13862 $mime = 'text/x-bat';
13863 $imgmime = 'script.png';
13865 $famime = 'file-code';
13866 } elseif (preg_match('/\.sh$/i', $tmpfile)) {
13867 $mime = 'text/x-sh';
13868 $imgmime = 'script.png';
13870 $famime = 'file-code';
13871 } elseif (preg_match('/\.ksh$/i', $tmpfile)) {
13872 $mime = 'text/x-ksh';
13873 $imgmime = 'script.png';
13875 $famime = 'file-code';
13876 } elseif (preg_match('/\.bash$/i', $tmpfile)) {
13877 $mime = 'text/x-bash';
13878 $imgmime = 'script.png';
13880 $famime = 'file-code';
13881 } elseif (preg_match('/\.ico$/i', $tmpfile)) { // Images
13882 $mime = 'image/x-icon';
13883 $imgmime = 'image.png';
13884 $famime = 'file-image';
13885 } elseif (preg_match('/\.(jpg|jpeg)$/i', $tmpfile)) {
13886 $mime = 'image/jpeg';
13887 $imgmime = 'image.png';
13888 $famime = 'file-image';
13889 } elseif (preg_match('/\.png$/i', $tmpfile)) {
13890 $mime = 'image/png';
13891 $imgmime = 'image.png';
13892 $famime = 'file-image';
13893 } elseif (preg_match('/\.gif$/i', $tmpfile)) {
13894 $mime = 'image/gif';
13895 $imgmime = 'image.png';
13896 $famime = 'file-image';
13897 } elseif (preg_match('/\.bmp$/i', $tmpfile)) {
13898 $mime = 'image/bmp';
13899 $imgmime = 'image.png';
13900 $famime = 'file-image';
13901 } elseif (preg_match('/\.(tif|tiff)$/i', $tmpfile)) {
13902 $mime = 'image/tiff';
13903 $imgmime = 'image.png';
13904 $famime = 'file-image';
13905 } elseif (preg_match('/\.svg$/i', $tmpfile)) {
13906 $mime = 'image/svg+xml';
13907 $imgmime = 'image.png';
13908 $famime = 'file-image';
13909 } elseif (preg_match('/\.webp$/i', $tmpfile)) {
13910 $mime = 'image/webp';
13911 $imgmime = 'image.png';
13912 $famime = 'file-image';
13913 } elseif (preg_match('/\.vcs$/i', $tmpfile)) { // Calendar
13914 $mime = 'text/calendar';
13915 $imgmime = 'other.png';
13916 $famime = 'file-alt';
13917 } elseif (preg_match('/\.ics$/i', $tmpfile)) {
13918 $mime = 'text/calendar';
13919 $imgmime = 'other.png';
13920 $famime = 'file-alt';
13921 } elseif (preg_match('/\.torrent$/i', $tmpfile)) { // Other
13922 $mime = 'application/x-bittorrent';
13923 $imgmime = 'other.png';
13924 $famime = 'file-o';
13925 } elseif (preg_match('/\.(mp3|ogg|au|wav|wma|mid)$/i', $tmpfile)) { // Audio
13927 $imgmime = 'audio.png';
13928 $famime = 'file-audio';
13929 } elseif (preg_match('/\.mp4$/i', $tmpfile)) { // Video
13930 $mime = 'video/mp4';
13931 $imgmime = 'video.png';
13932 $famime = 'file-video';
13933 } elseif (preg_match('/\.ogv$/i', $tmpfile)) {
13934 $mime = 'video/ogg';
13935 $imgmime = 'video.png';
13936 $famime = 'file-video';
13937 } elseif (preg_match('/\.webm$/i', $tmpfile)) {
13938 $mime = 'video/webm';
13939 $imgmime = 'video.png';
13940 $famime = 'file-video';
13941 } elseif (preg_match('/\.avi$/i', $tmpfile)) {
13942 $mime = 'video/x-msvideo';
13943 $imgmime = 'video.png';
13944 $famime = 'file-video';
13945 } elseif (preg_match('/\.divx$/i', $tmpfile)) {
13946 $mime = 'video/divx';
13947 $imgmime = 'video.png';
13948 $famime = 'file-video';
13949 } elseif (preg_match('/\.xvid$/i', $tmpfile)) {
13950 $mime = 'video/xvid';
13951 $imgmime = 'video.png';
13952 $famime = 'file-video';
13953 } elseif (preg_match('/\.(wmv|mpg|mpeg)$/i', $tmpfile)) {
13955 $imgmime = 'video.png';
13956 $famime = 'file-video';
13957 } elseif (preg_match('/\.(zip|rar|gz|tgz|xz|z|cab|bz2|7z|tar|lzh|zst)$/i', $tmpfile)) { // Archive
13958 // application/xxx where zzz is zip, ...
13960 $imgmime = 'archive.png';
13961 $famime = 'file-archive';
13962 } elseif (preg_match('/\.(exe|com)$/i', $tmpfile)) { // Exe
13963 $mime = 'application/octet-stream';
13964 $imgmime = 'other.png';
13965 $famime = 'file-o';
13966 } elseif (preg_match('/\.(dll|lib|o|so|a)$/i', $tmpfile)) { // Lib
13968 $imgmime = 'library.png';
13969 $famime = 'file-o';
13970 } elseif (preg_match('/\.err$/i', $tmpfile)) { // phpcs:ignore
13972 $imgmime = 'error.png';
13973 $famime = 'file-alt';
13976 if ($famime == 'file-o') {
13977 // file-o seems to not work in fontawesome 5
13981 // Return mimetype string
13982 switch ((int) $mode) {
13984 $tmp = explode('/', $mime);
13985 return (!empty($tmp[1]) ? $tmp[1] : $tmp[0]);
14007function getDictionaryValue($tablename, $field, $id, $checkentity = false, $rowidfield = 'rowid')
14011 $tablename = preg_replace('/^' . preg_quote(MAIN_DB_PREFIX, '/') . '/', '', $tablename); // Clean name of table for backward compatibility.
14013 $dictvalues = (isset($conf->cache['dictvalues_' . $tablename]) ? $conf->cache['dictvalues_' . $tablename] : null);
14015 if (is_null($dictvalues)) {
14016 $dictvalues = array();
14018 $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
14019 if ($checkentity) {
14020 $sql .= ' AND entity IN (0,' . getEntity($tablename) . ')';
14023 $resql = $db->query($sql);
14025 while ($obj = $db->fetch_object($resql)) {
14026 $dictvalues[$obj->$rowidfield] = $obj; // $obj is stdClass
14029 dol_print_error($db);
14032 $conf->cache['dictvalues_' . $tablename] = $dictvalues;
14035 if (!empty($dictvalues[$id])) {
14037 $tmp = $dictvalues[$id];
14038 return (property_exists($tmp, $field) ? $tmp->$field : '');
14051function colorIsLight($stringcolor)
14053 $stringcolor = str_replace('#', '', $stringcolor);
14055 if (!empty($stringcolor)) {
14057 $tmp = explode(',', $stringcolor);
14058 if (count($tmp) > 1) { // This is a comma RGB ('255','255','255')
14063 $hexr = $stringcolor[0] . $stringcolor[1];
14064 $hexg = $stringcolor[2] . $stringcolor[3];
14065 $hexb = $stringcolor[4] . $stringcolor[5];
14066 $r = hexdec($hexr);
14067 $g = hexdec($hexg);
14068 $b = hexdec($hexb);
14070 $bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0; // HSL algorithm
14071 if ($bright > 0.6) {
14086function isVisibleToUserType($type_user, &$menuentry, &$listofmodulesforexternal)
14088 //print 'type_user='.$type_user.' module='.$menuentry['module'].' enabled='.$menuentry['enabled'].' perms='.$menuentry['perms'];
14089 //print 'ok='.in_array($menuentry['module'], $listofmodulesforexternal);
14090 if (empty($menuentry['enabled'])) {
14091 return 0; // Entry disabled by condition
14093 if ($type_user && array_key_exists('module', $menuentry) && $menuentry['module']) {
14094 $tmploops = explode('|', $menuentry['module']);
14096 foreach ($tmploops as $tmploop) {
14097 if (in_array($tmploop, $listofmodulesforexternal)) {
14103 return 0; // Entry is for menus all excluded to external users
14106 if (!$menuentry['perms'] && $type_user) {
14107 return 0; // No permissions and user is external
14109 if (!$menuentry['perms'] && getDolGlobalString('MAIN_MENU_HIDE_UNAUTHORIZED')) {
14110 return 0; // No permissions and option to hide when not allowed, even for internal user, is on
14112 if (!$menuentry['perms']) {
14113 return 2; // No permissions and user is external
14125function roundUpToNextMultiple($n, $x = 5)
14127 $result = (ceil($n) % $x === 0) ? ceil($n) : (round(($n + $x / 2) / $x) * $x);
14128 return (int) $result;
14142function dolGetBadge($label, $html = '', $type = 'primary', $mode = '', $url = '', $params = array())
14144 $csstouse = 'badge';
14145 $csstouse .= (!empty($mode) ? ' badge-' . $mode : '');
14146 $csstouse .= (!empty($type) ? ' badge-' . $type : '');
14147 $csstouse .= (empty($params['css']) ? '' : ' ' . $params['css']);
14150 'class' => $csstouse
14153 if (empty($html)) {
14157 if (!empty($url)) {
14158 $attr['href'] = $url;
14161 if ($mode === 'dot') {
14162 $attr['class'] .= ' classfortooltip';
14163 $attr['title'] = $html;
14164 $attr['aria-label'] = $label;
14169 if (!empty($params['attr']) && is_array($params['attr'])) {
14170 foreach ($params['attr'] as $key => $value) {
14171 if ($key == 'class') {
14172 $attr['class'] .= ' ' . $value;
14173 } elseif ($key == 'classOverride') {
14174 $attr['class'] = $value;
14176 $attr[$key] = $value;
14183 // escape all attribute
14184 $attr = array_map('dolPrintHTMLForAttribute', $attr);
14186 $TCompiledAttr = array();
14187 foreach ($attr as $key => $value) {
14188 $TCompiledAttr[] = $key . '="
' . $value . '"';
14191 $compiledAttributes = !empty($TCompiledAttr) ? implode(' ', $TCompiledAttr) : '';
14193 $tag = !empty($url) ? 'a' : 'span';
14195 return '<' . $tag . ' ' . $compiledAttributes . '>' . $html . '</' . $tag . '>';
14211function dolGetStatus($statusLabel = '', $statusLabelShort = '', $html = '', $statusType = 'status0', $displayMode = 0, $url = '', $params = array())
14216 $dolGetBadgeParams = array();
14218 if (!empty($params['badgeParams'])) {
14219 $dolGetBadgeParams = $params['badgeParams'];
14222 // TODO : add a hook
14223 if ($displayMode == 0) {
14224 $return = !empty($html) ? $html : (empty($conf->dol_optimize_smallscreen) ? $statusLabel : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort));
14225 } elseif ($displayMode == 1) {
14226 $return = !empty($html) ? $html : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort);
14227 } elseif (getDolGlobalString('MAIN_STATUS_USES_IMAGES')) {
14228 // Use status with images (for backward compatibility)
14230 $htmlLabel = (in_array($displayMode, array(1, 2, 5)) ? '<span class="hideonsmartphone
">' : '') . (!empty($html) ? $html : $statusLabel) . (in_array($displayMode, array(1, 2, 5)) ? '</span>' : '');
14231 $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>' : '');
14233 // For small screen, we always use the short label instead of long label.
14234 if (!empty($conf->dol_optimize_smallscreen)) {
14235 if ($displayMode == 0) {
14237 } elseif ($displayMode == 4) {
14239 } elseif ($displayMode == 6) {
14244 // For backward compatibility. Image's filename are still in French, so we use this array to convert
14245 $statusImg = array(
14246 'status0' => 'statut0',
14247 'status1' => 'statut1',
14248 'status2' => 'statut2',
14249 'status3' => 'statut3',
14250 'status4' => 'statut4',
14251 'status5' => 'statut5',
14252 'status6' => 'statut6',
14253 'status7' => 'statut7',
14254 'status8' => 'statut8',
14255 'status9' => 'statut9'
14258 if (!empty($statusImg[$statusType])) {
14259 $htmlImg = img_picto($statusLabel, $statusImg[$statusType]);
14261 $htmlImg = img_picto($statusLabel, $statusType);
14264 if ($displayMode === 2) {
14265 $return = $htmlImg . ' ' . $htmlLabelShort;
14266 } elseif ($displayMode === 3) {
14267 $return = $htmlImg;
14268 } elseif ($displayMode === 4) {
14269 $return = $htmlImg . ' ' . $htmlLabel;
14270 } elseif ($displayMode === 5) {
14271 $return = $htmlLabelShort . ' ' . $htmlImg;
14272 } else { // $displayMode >= 6
14273 $return = $htmlLabel . ' ' . $htmlImg;
14275 } elseif (!getDolGlobalString('MAIN_STATUS_USES_IMAGES') && !empty($displayMode)) {
14277 $statusLabelShort = (empty($statusLabelShort) ? $statusLabel : $statusLabelShort);
14279 $dolGetBadgeParams['attr']['class'] = 'badge-status';
14280 if (empty($dolGetBadgeParams['attr']['title'])) {
14281 $dolGetBadgeParams['attr']['title'] = empty($params['tooltip']) ? $statusLabel : ($params['tooltip'] != 'no' ? $params['tooltip'] : '');
14282 } else { // If a title was forced from $params['badgeParams']['attr']['title'], we set the class to get it as a tooltip.
14283 $dolGetBadgeParams['attr']['class'] .= ' classfortooltip';
14284 // And if we use tooltip, we can output title in HTML @phan-suppress-next-line PhanTypeInvalidDimOffset
14285 $dolGetBadgeParams['attr']['title'] = dol_htmlentitiesbr((string) $dolGetBadgeParams['attr']['title'], 1);
14288 if ($displayMode == 3) {
14289 $return = dolGetBadge((empty($conf->dol_optimize_smallscreen) ? $statusLabel : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort)), '', $statusType, 'dot', $url, $dolGetBadgeParams);
14290 } elseif ($displayMode === 5) {
14291 $return = dolGetBadge($statusLabelShort, $html, $statusType, '', $url, $dolGetBadgeParams);
14293 $return = dolGetBadge(((empty($conf->dol_optimize_smallscreen) && $displayMode != 2) ? $statusLabel : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort)), $html, $statusType, '', $url, $dolGetBadgeParams);
14336function dolGetButtonAction($label, $text = '', $actionType = 'default', $url = '', $id = '', $userRight = 1, $params = array())
14338 global $hookmanager, $action, $object, $langs;
14340 // If $url is an array, we must build a dropdown button or recursively iterate over each value
14341 if (is_array($url)) {
14342 // Loop on $url array to remove entries of disabled modules
14343 foreach ($url as $key => $subbutton) {
14344 if (isset($subbutton['enabled']) && empty($subbutton['enabled'])) {
14351 if (array_key_exists('areDropdownButtons', $params) && $params["areDropdownButtons
"] === false) { // @phan-suppress-current-line PhanTypeInvalidDimOffset
14352 foreach ($url as $button) {
14353 if (!empty($button['lang'])) {
14354 $langs->load($button['lang']);
14356 $label = $langs->trans($button['label']);
14357 $text = $button['text'] ?? '';
14358 $actionType = $button['actionType'] ?? '';
14359 $tmpUrl = DOL_URL_ROOT . $button['url'] . (empty($params['backtopage']) ? '' : '&backtopage=' . urlencode($params['backtopage']));
14360 $id = $button['id'] ?? '';
14361 $userRight = $button['perm'] ?? 1;
14362 $button['params'] = $button['params'] ?? []; // @phan-suppress-current-line PhanPluginDuplicateExpressionAssignmentOperation
14364 $out .= dolGetButtonAction($label, $text, $actionType, $tmpUrl, $id, $userRight, $button['params']);
14369 if (count($url) > 1) {
14370 $out .= '<div class="dropdown
inline-block dropdown-holder
">';
14371 $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>';
14372 $out .= '<div class="dropdown-content
">';
14373 foreach ($url as $subbutton) {
14374 if (!empty($subbutton['lang'])) {
14375 $langs->load($subbutton['lang']);
14378 if (!empty($subbutton['urlraw'])) {
14379 $tmpurl = $subbutton['urlraw']; // Use raw url, no url completion, use only what developer send
14381 $tmpurl = !empty($subbutton['urlroot']) ? $subbutton['urlroot'] : $subbutton['url'];
14382 $tmpurl = dolCompletUrlForDropdownButton($tmpurl, $params, empty($subbutton['urlroot']));
14385 $subbuttonparam = array();
14386 if (!empty($subbutton['attr'])) {
14387 $subbuttonparam['attr'] = $subbutton['attr'];
14389 $subbuttonparam['isDropDown'] = (empty($params['isDropDown']) ? ($subbutton['isDropDown'] ?? false) : $params['isDropDown']);
14391 $out .= dolGetButtonAction('', $langs->trans($subbutton['label']), 'default', $tmpurl, $subbutton['id'] ?? '', $subbutton['perm'], $subbuttonparam);
14396 foreach ($url as $subbutton) { // Should loop on 1 record only
14397 if (!empty($subbutton['lang'])) {
14398 $langs->load($subbutton['lang']);
14401 if (!empty($subbutton['urlraw'])) {
14402 $tmpurl = $subbutton['urlraw']; // Use raw url, no url completion, use only what developer send
14404 $tmpurl = !empty($subbutton['urlroot']) ? $subbutton['urlroot'] : $subbutton['url'];
14405 $tmpurl = dolCompletUrlForDropdownButton($tmpurl, $params, empty($subbutton['urlroot']));
14408 $label = $langs->trans($subbutton['label']);
14409 $text = $subbutton['text'] ?? '';
14410 if (empty($text)) {
14415 $out .= dolGetButtonAction($label, $text, 'default', $tmpurl, '', $subbutton['perm'], $params);
14422 // Here, $url is a simple link
14423 if (!empty($params['isDropdown']) || !empty($params['isDropDown'])) { // Use the dropdown-item style (not for action button)
14424 $class = "dropdown-item
";
14426 $class = 'butAction';
14427 if ($actionType == 'edit') {
14428 $class = 'butAction butActionEdit';
14429 } elseif ($actionType == 'email') {
14430 $class = 'butAction butActionEmail';
14431 } elseif ($actionType == 'clone') {
14432 $class = 'butAction butActionClone';
14433 } elseif ($actionType == 'danger' || $actionType == 'delete') {
14434 $class = 'butAction butActionDelete';
14435 if (!empty($url) && strpos($url, 'token=') === false) {
14436 $url .= '&token=' . newToken();
14442 'href' => empty($url) ? '' : $url,
14446 if (empty($text)) {
14448 $attr['title'] = ''; // if html not set, using label on title is redundant
14450 $attr['title'] = $label;
14451 $attr['aria-label'] = $label;
14454 if (empty($userRight) || $userRight < 0) {
14455 $attr['class'] = 'butActionRefused';
14456 $attr['href'] = '';
14457 $attr['title'] = (($label && $text && $label != $text) ? $label : '');
14458 $attr['title'] = ($attr['title'] ? $attr['title'] . (empty($userRight) ? '<br>' : '') : '');
14459 $attr['title'] .= ((empty($userRight) && empty($label)) ? $langs->trans('NotEnoughPermissions') : '');
14467 if (!empty($params['attr']) && is_array($params['attr'])) {
14468 foreach ($params['attr'] as $key => $value) {
14469 if ($key == 'class') {
14470 $attr['class'] .= ' ' . $value;
14471 } elseif ($key == 'classOverride') {
14472 $attr['class'] = $value;
14474 $attr[$key] = $value;
14479 // automatic add tooltip when title is detected
14480 if (!empty($attr['title']) && !empty($attr['class']) && strpos($attr['class'], 'classfortooltip') === false) {
14481 $attr['class'] .= ' classfortooltip';
14484 // Js Confirm button
14485 if ($userRight && !empty($params['confirm'])) {
14486 if (!is_array($params['confirm'])) {
14487 $params['confirm'] = array();
14490 if (empty($params['confirm']['url'])) {
14491 $params['confirm']['url'] = $url . (strpos($url, '?') > 0 ? '&' : '?') . 'confirm=yes';
14494 // for js disabled compatibility set $url as call to confirm action and $params['confirm']['url'] to confirmed action
14495 $attr['data-confirm-url'] = $params['confirm']['url'];
14496 $attr['data-confirm-title'] = !empty($params['confirm']['title']) ? $params['confirm']['title'] : $langs->trans('ConfirmBtnCommonTitle', $label);
14497 $attr['data-confirm-content'] = !empty($params['confirm']['content']) ? $params['confirm']['content'] : $langs->trans('ConfirmBtnCommonContent', $label);
14498 $attr['data-confirm-content'] = preg_replace("/\r|\n/
", "", $attr['data-confirm-content']);
14499 $attr['data-confirm-action-btn-label'] = !empty($params['confirm']['action-btn-label']) ? $params['confirm']['action-btn-label'] : $langs->trans('Confirm');
14500 $attr['data-confirm-cancel-btn-label'] = !empty($params['confirm']['cancel-btn-label']) ? $params['confirm']['cancel-btn-label'] : $langs->trans('CloseDialog');
14501 $attr['data-confirm-modal'] = !empty($params['confirm']['modal']) ? $params['confirm']['modal'] : true;
14503 $attr['class'] .= ' butActionConfirm';
14506 if (isset($attr['href']) && empty($attr['href'])) {
14507 unset($attr['href']);
14510 // TODO replace $TCompiledAttr generation by commonHtmlAttributeBuilder given below
14511 $TCompiledAttr = array();
14512 foreach ($attr as $key => $value) {
14513 if (!empty($params['use_unsecured_unescapedattr']) && is_array($params['use_unsecured_unescapedattr']) && in_array($key, $params['use_unsecured_unescapedattr'])) {
14515 $value = dol_htmlentities($value, ENT_QUOTES | ENT_SUBSTITUTE);
14516 } elseif (in_array($key, ['href', 'data-confirm-url'])) {
14517 $value = dolPrintHTMLForAttributeUrl($value);
14519 $value = dolPrintHTMLForAttribute($value);
14522 $TCompiledAttr[] = $key . '="' . $value . '"'; // $value has been escaped by the dolPrintHTMLForAttribute... just before
14524 // TODO replace $TCompiledAttr generation by uncomment line below and remove old code
14525 // $TCompiledAttr = commonHtmlAttributeBuilder($attr,$params['use_unsecured_unescapedattr'] ?? []);
14526 $compiledAttributes = empty($TCompiledAttr) ? '' : implode(' ', $TCompiledAttr);
14528 $tag = !empty($attr['href']) ? 'a' : 'span';
14530 $parameters = array(
14531 'TCompiledAttr' => $TCompiledAttr, // array
14532 'compiledAttributes' => $compiledAttributes, // string
14537 'actionType' => $actionType,
14540 'userRight' => $userRight,
14541 'params' => $params
14544 $reshook = $hookmanager->executeHooks('dolGetButtonAction', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
14545 if ($reshook < 0) {
14546 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
14549 if (empty($reshook)) {
14550 if (dol_textishtml($text)) { // If content already HTML encoded
14551 return '<' . $tag . ' ' . $compiledAttributes . '><span class="textbutton
">' . $text . '</span></' . $tag . '>';
14553 return '<' . $tag . ' ' . $compiledAttributes . '><span class="textbutton
">' . dol_escape_htmltag($text) . '</span></' . $tag . '>';
14556 return $hookmanager->resPrint;
14595function commonHtmlAttributeBuilder($attr, array $unescapedAttr = [])
14597 $TCompiledAttr = array();
14598 if (empty($attr)) {
14602 foreach ($attr as $key => $value) {
14603 // special boolean attributes case
14604 if (in_array($key, getListOfHtmlBooleanAttributes())) {
14606 $TCompiledAttr[$key] = $key;
14611 if (!empty($unescapedAttr) && in_array($key, $unescapedAttr)) {
14613 $value = dol_htmlentities((string) $value, ENT_QUOTES | ENT_SUBSTITUTE);
14614 } elseif ($key == 'href') {
14615 $value = dolPrintHTMLForAttributeUrl((string) $value);
14617 $value = dolPrintHTMLForAttribute((string) $value);
14620 $TCompiledAttr[$key] = $key . '="
' . $value . '"'; // $value has been escaped by the dolPrintHTMLForAttribute... just before
14623 return $TCompiledAttr;
14640function getListOfHtmlBooleanAttributes(): array
14689function dolCompletUrlForDropdownButton(string $url, array $params, bool $addDolUrlRoot = true)
14695 $parsedUrl = parse_url($url);
14696 if ((isset($parsedUrl['scheme']) && in_array($parsedUrl['scheme'], ['javascript', 'mailto', 'tel'])) || strpos($url, '#') === 0) {
14700 if (!empty($parsedUrl['query'])) {
14701 // Use parse_str() function to parse the string passed via URL
14702 parse_str($parsedUrl['query'], $urlQuery);
14703 if (!isset($urlQuery['backtopage']) && isset($params['backtopage'])) {
14704 $url .= '&backtopage=' . urlencode($params['backtopage']);
14708 if (!isset($parsedUrl['scheme']) && $addDolUrlRoot) {
14709 $url = DOL_URL_ROOT . $url;
14722function dolGetButtonTitleSeparator($moreClass = "
")
14724 return '<span class="button-title-separator
' . $moreClass . '" ></span>';
14733function getFieldErrorIcon($fieldValidationErrorMsg)
14736 if (!empty($fieldValidationErrorMsg)) {
14737 $out .= '<span class="field-error-icon classfortooltip
" title="' . dol_escape_htmltag($fieldValidationErrorMsg, 1) . '" role="alert
" >'; // role alert is used for accessibility
14738 $out .= '<span class="fa fa-exclamation-circle
" aria-hidden="true" ></span>'; // For accessibility icon is separated and aria-hidden
14757function dolGetButtonTitle($label, $helpText = '', $iconClass = 'fa fa-file', $url = '', $id = '', $status = 1, $params = array())
14759 global $langs, $user;
14761 // Actually this conf is used in css too for external module compatibility and smooth transition to this function
14762 if (getDolGlobalString('MAIN_BUTTON_HIDE_UNAUTHORIZED') && (!$user->admin) && $status <= 0) {
14765 // Fix old picto fa-th-list to use fa-grid-vertical instead
14766 if ($iconClass == 'fa fa-th-list imgforviewmode') {
14767 $iconClass = ' fa fa-grip-horizontal imgforviewmode';
14770 $class = 'btnTitle';
14771 if (in_array($iconClass, array('fa fa-plus-circle', 'fa fa-plus-circle size15x', 'fa fa-comment-dots', 'fa fa-paper-plane'))) {
14772 $class .= ' btnTitlePlus';
14774 $useclassfortooltip = 1;
14776 if (!empty($params['morecss'])) {
14777 $class .= ' ' . $params['morecss'];
14782 'href' => empty($url) ? '' : $url
14785 if (!empty($helpText)) {
14786 $attr['title'] = $helpText;
14787 } elseif ($label) { // empty($attr['title']) &&
14788 $attr['title'] = $label;
14789 $useclassfortooltip = 0;
14792 if ($status == 2) {
14793 $attr['class'] .= ' btnTitleSelected';
14794 } elseif ($status <= 0) {
14795 $attr['class'] .= ' refused';
14797 $attr['href'] = '';
14799 if ($status == -1) { // disable
14800 $attr['title'] = $langs->transnoentitiesnoconv("FeatureDisabled
");
14801 } elseif ($status == 0) { // Not enough permissions
14802 $attr['title'] = $langs->transnoentitiesnoconv("NotEnoughPermissions
");
14806 if (!empty($attr['title']) && $useclassfortooltip) {
14807 $attr['class'] .= ' classfortooltip';
14815 if (!empty($params['attr']) && is_array($params['attr'])) {
14816 foreach ($params['attr'] as $key => $value) {
14817 if ($key == 'class') {
14818 $attr['class'] .= ' ' . $value;
14819 } elseif ($key == 'classOverride') {
14820 $attr['class'] = $value;
14822 $attr[$key] = $value;
14827 if (isset($attr['href']) && empty($attr['href'])) {
14828 unset($attr['href']);
14831 // TODO : add a hook
14833 // Generate attributes with escapement
14834 $TCompiledAttr = array();
14835 foreach ($attr as $key => $value) {
14836 $TCompiledAttr[] = $key . '="' . dol_escape_htmltag($value) . '"'; // Do not use dolPrintHTMLForAttribute() here, we must accept "javascript:
string"
14839 $compiledAttributes = (empty($TCompiledAttr) ? '' : implode(' ', $TCompiledAttr));
14841 $tag = (empty($attr['href']) ? 'span' : 'a');
14843 $button = '<' . $tag . ' ' . $compiledAttributes . '>';
14844 $button .= '<span class="' . $iconClass . ' valignmiddle btnTitle-icon
"></span>';
14845 if (!empty($params['forcenohideoftext'])) {
14846 $button .= '<span class="valignmiddle text-plus-circle btnTitle-label
' . (empty($params['forcenohideoftext
']) ? ' hideonsmartphone
' : '') . '">' . $label . '</span>';
14848 $button .= '</' . $tag . '>';
14862function getElementProperties($elementType)
14864 global $conf, $db, $hookmanager;
14868 //$element_type='facture';
14870 $classfile = $classname = $classpath = $subdir = $dir_output = $dir_temp = $parent_element = '';
14872 // Parse element/subelement
14873 $module = $elementType;
14874 $element = $elementType;
14875 $subelement = $elementType;
14876 $table_element = $elementType;
14878 // If we ask a resource form external module (instead of default path)
14879 if (preg_match('/^([^@]+)@([^@]+)$/i', $elementType, $regs)) { // 'myobject@mymodule'
14880 $element = $subelement = $regs[1];
14881 $module = $regs[2];
14884 // If we ask a resource for a string with an element and a subelement
14885 // Example 'project_task'
14886 if (preg_match('/^([^_]+)_([^_]+)/i', $element, $regs)) { // 'myobject_mysubobject' with myobject=mymodule
14887 $module = $element = $regs[1];
14888 $subelement = $regs[2];
14891 // Object lines will use parent classpath and module ref
14892 if (substr($elementType, -3) == 'det') {
14893 $module = preg_replace('/det$/', '', $element);
14894 $subelement = preg_replace('/det$/', '', $subelement);
14895 $classpath = $module . '/class';
14896 $classfile = $module;
14897 $classname = preg_replace('/det$/', 'Line', $element);
14898 if (in_array($module, array('expedition', 'propale', 'facture', 'contrat', 'fichinter', 'supplier_order', 'commandefournisseur'))) {
14899 $classname = preg_replace('/det$/', 'Ligne', $element);
14902 // For compatibility and to work with non standard path
14903 if ($elementType == "action
" || $elementType == "actioncomm
") {
14904 $classpath = 'comm/action/class';
14905 $subelement = 'Actioncomm';
14906 $module = 'agenda';
14907 $table_element = 'actioncomm';
14908 } elseif ($elementType == 'cronjob') {
14909 $classpath = 'cron/class';
14911 $table_element = 'cron';
14912 } elseif ($elementType == 'adherent_type') {
14913 $classpath = 'adherents/class';
14914 $classfile = 'adherent_type';
14915 $module = 'adherent';
14916 $subelement = 'adherent_type';
14917 $classname = 'AdherentType';
14918 $table_element = 'adherent_type';
14919 } elseif ($elementType == 'bank_account') {
14920 $classpath = 'compta/bank/class';
14921 $module = 'bank'; // We need $conf->bank->dir_output and not $conf->banque->dir_output
14922 $classfile = 'account';
14923 $classname = 'Account';
14924 } elseif ($elementType == 'bank_line') {
14925 $classpath = 'compta/bank/class';
14926 $module = 'bank'; // We need $conf->bank->dir_output and not $conf->banque->dir_output
14927 $classfile = 'account';
14928 $classname = 'AccountLine';
14929 } elseif ($elementType == 'category') {
14930 $classpath = 'categories/class';
14931 $module = 'categorie';
14932 $subelement = 'categorie';
14933 $table_element = 'categorie';
14934 } elseif ($elementType == 'contact') {
14935 $classpath = 'contact/class';
14936 $classfile = 'contact';
14937 $module = 'societe';
14938 $subelement = 'contact';
14939 $table_element = 'socpeople';
14940 } elseif ($elementType == 'inventory') {
14941 $module = 'product';
14942 $classpath = 'product/inventory/class';
14943 } elseif ($elementType == 'inventoryline') {
14944 $module = 'product';
14945 $classpath = 'product/inventory/class';
14946 $table_element = 'inventorydet';
14947 $parent_element = 'inventory';
14948 } elseif ($elementType == 'stock' || $elementType == 'entrepot' || $elementType == 'warehouse') {
14950 $classpath = 'product/stock/class';
14951 $classfile = 'entrepot';
14952 $classname = 'Entrepot';
14953 $table_element = 'entrepot';
14954 } elseif ($elementType == 'project') {
14955 $classpath = 'projet/class';
14956 $module = 'projet';
14957 $table_element = 'projet';
14958 } elseif ($elementType == 'project_task') {
14959 $classpath = 'projet/class';
14960 $module = 'projet';
14961 $subelement = 'task';
14962 $table_element = 'projet_task';
14963 } elseif ($elementType == 'facture' || $elementType == 'invoice') {
14964 $classpath = 'compta/facture/class';
14965 $module = 'facture';
14966 $subelement = 'facture';
14967 $table_element = 'facture';
14968 } elseif ($elementType == 'facturedet') {
14969 $classpath = 'compta/facture/class';
14970 $classfile = 'facture';
14971 $classname = 'FactureLigne';
14972 $module = 'facture';
14973 $table_element = 'facturedet';
14974 $parent_element = 'facture';
14975 } elseif ($elementType == 'facturerec'|| $elementType == 'facture_rec') {
14976 $classpath = 'compta/facture/class';
14977 $classfile = 'facture-rec';
14978 $module = 'facture';
14979 $classname = 'FactureRec';
14980 } elseif ($elementType == 'commande' || $elementType == 'order') {
14981 $classpath = 'commande/class';
14982 $module = 'commande';
14983 $subelement = 'commande';
14984 $table_element = 'commande';
14985 } elseif ($elementType == 'commandedet') {
14986 $classpath = 'commande/class';
14987 $classfile = 'commande';
14988 $classname = 'OrderLine';
14989 $module = 'commande';
14990 $table_element = 'commandedet';
14991 $parent_element = 'commande';
14992 } elseif ($elementType == 'propal') {
14993 $classpath = 'comm/propal/class';
14994 $table_element = 'propal';
14995 } elseif ($elementType == 'propaldet') {
14996 $classpath = 'comm/propal/class';
14997 $classfile = 'propal';
14998 $subelement = 'propaleligne';
14999 $module = 'propal';
15000 $table_element = 'propaldet';
15001 $parent_element = 'propal';
15002 } elseif ($elementType == 'shipping') {
15003 $classpath = 'expedition/class';
15004 $classfile = 'expedition';
15005 $classname = 'Expedition';
15006 $module = 'expedition';
15007 $table_element = 'expedition';
15008 } elseif ($elementType == 'expeditiondet' || $elementType == 'shippingdet') {
15009 $classpath = 'expedition/class';
15010 $classfile = 'expedition';
15011 $classname = 'ExpeditionLigne';
15012 $module = 'expedition';
15013 $table_element = 'expeditiondet';
15014 $parent_element = 'expedition';
15015 } elseif ($elementType == 'delivery_note') {
15016 $classpath = 'delivery/class';
15017 $subelement = 'delivery';
15018 $module = 'expedition';
15019 } elseif ($elementType == 'delivery') {
15020 $classpath = 'delivery/class';
15021 $subelement = 'delivery';
15022 $module = 'expedition';
15023 } elseif ($elementType == 'deliverydet') {
15025 } elseif ($elementType == 'supplier_proposal') {
15026 $classpath = 'supplier_proposal/class';
15027 $module = 'supplier_proposal';
15028 $element = 'supplierproposal';
15029 $classfile = 'supplier_proposal';
15030 $subelement = 'supplierproposal';
15031 } elseif ($elementType == 'supplier_proposaldet') {
15032 $classpath = 'supplier_proposal/class';
15033 $module = 'supplier_proposal';
15034 $classfile = 'supplier_proposal';
15035 $classname = 'SupplierProposalLine';
15036 $table_element = 'supplier_proposaldet';
15037 $parent_element = 'supplier_proposal';
15038 } elseif ($elementType == 'contract') {
15039 $classpath = 'contrat/class';
15040 $module = 'contrat';
15041 $subelement = 'contrat';
15042 $table_element = 'contract';
15043 } elseif ($elementType == 'contratdet') {
15044 $classpath = 'contrat/class';
15045 $module = 'contrat';
15046 $table_element = 'contratdet';
15047 $parent_element = 'contrat';
15048 } elseif ($elementType == 'mailing') {
15049 $classpath = 'comm/mailing/class';
15050 $module = 'mailing';
15051 $classfile = 'mailing';
15052 $classname = 'Mailing';
15054 } elseif ($elementType == 'member' || $elementType == 'adherent') {
15055 $classpath = 'adherents/class';
15056 $module = 'adherent';
15057 $subelement = 'adherent';
15058 $table_element = 'adherent';
15059 } elseif ($elementType == 'subscription') {
15060 $classpath = 'adherents/class';
15061 $classfile = 'subscription';
15062 $module = 'adherent';
15063 $subelement = 'subscription';
15064 $classname = 'Subscription';
15065 $table_element = 'subscription';
15066 } elseif ($elementType == 'usergroup') {
15067 $classpath = 'user/class';
15069 } elseif ($elementType == 'mo' || $elementType == 'mrp') {
15070 $classpath = 'mrp/class';
15075 $table_element = 'mrp_mo';
15076 } elseif ($elementType == 'mrp_production') {
15077 $classpath = 'mrp/class';
15079 $classname = 'MoLine';
15082 $table_element = 'mrp_production';
15083 $parent_element = 'mo';
15084 } elseif ($elementType == 'cabinetmed_cons') {
15085 $classpath = 'cabinetmed/class';
15086 $module = 'cabinetmed';
15087 $subelement = 'cabinetmedcons';
15088 $table_element = 'cabinetmedcons';
15089 } elseif ($elementType == 'fichinter') {
15090 $classpath = 'fichinter/class';
15091 $module = 'ficheinter';
15092 $subelement = 'fichinter';
15093 $table_element = 'fichinter';
15094 } elseif ($elementType == 'dolresource' || $elementType == 'resource') {
15095 $classpath = 'resource/class';
15096 $module = 'resource';
15097 $subelement = 'dolresource';
15098 $table_element = 'resource';
15099 } elseif ($elementType == 'opensurvey_sondage') {
15100 $classpath = 'opensurvey/class';
15101 $module = 'opensurvey';
15102 $subelement = 'opensurveysondage';
15103 } elseif ($elementType == 'order_supplier' || $elementType == 'supplier_order' || $elementType == 'commande_fournisseur' || $elementType == 'commandefournisseur') {
15104 $classpath = 'fourn/class';
15105 $module = 'fournisseur';
15106 $classfile = 'fournisseur.commande';
15107 $element = 'order_supplier';
15109 $classname = 'CommandeFournisseur';
15110 $table_element = 'commande_fournisseur';
15111 } elseif ($elementType == 'commande_fournisseurdet') {
15112 $classpath = 'fourn/class';
15113 $module = 'fournisseur';
15114 $classfile = 'fournisseur.commande';
15115 $element = 'commande_fournisseurdet';
15117 $classname = 'CommandeFournisseurLigne';
15118 $table_element = 'commande_fournisseurdet';
15119 $parent_element = 'commande_fournisseur';
15120 } elseif ($elementType == 'invoice_supplier' || $elementType == 'supplier_invoice' || $elementType == 'facture_fourn') {
15121 $classpath = 'fourn/class';
15122 $module = 'fournisseur';
15123 $classfile = 'fournisseur.facture';
15124 $element = 'invoice_supplier';
15126 $classname = 'FactureFournisseur';
15127 $table_element = 'facture_fourn';
15128 } elseif ($elementType == 'facture_fourn_det') {
15129 $classpath = 'fourn/class';
15130 $module = 'fournisseur';
15131 $classfile = 'fournisseur.facture';
15132 $element = 'facture_fourn_det';
15134 $classname = 'SupplierInvoiceLine';
15135 $table_element = 'facture_fourn_det';
15136 $parent_element = 'invoice_supplier';
15137 } elseif ($elementType == "service
") {
15138 $classpath = 'product/class';
15139 $subelement = 'product';
15140 $table_element = 'product';
15141 } elseif ($elementType == 'product_attribute') {
15142 $module = 'variants';
15143 $element = 'product_attribute';
15144 $subelement = 'product_attribute';
15145 $classpath = 'variants/class';
15146 $classfile = 'ProductAttribute';
15147 $classname = 'ProductAttribute';
15148 $table_element = 'product_attribute';
15149 } elseif ($elementType == 'product_attribute_value') {
15150 $module = 'variants';
15151 $element = 'product_attribute_value';
15152 $subelement = 'product_attribute_value';
15153 $classpath = 'variants/class';
15154 $classfile = 'ProductAttributeValue';
15155 $classname = 'ProductAttributeValue';
15156 $table_element = 'product_attribute_value';
15157 $parent_element = 'product_attribute';
15158 } elseif ($elementType == 'salary') {
15159 $classpath = 'salaries/class';
15160 $module = 'salaries';
15161 } elseif ($elementType == 'payment_salary') {
15162 $classpath = 'salaries/class';
15163 $classfile = 'paymentsalary';
15164 $classname = 'PaymentSalary';
15165 $module = 'salaries';
15166 } elseif ($elementType == 'productlot') {
15167 $module = 'productbatch';
15168 $classpath = 'product/stock/class';
15169 $classfile = 'productlot';
15170 $classname = 'Productlot';
15171 $element = 'productlot';
15173 $table_element = 'product_lot';
15174 } elseif ($elementType == 'societeaccount') {
15175 $classpath = 'societe/class';
15176 $classfile = 'societeaccount';
15177 $classname = 'SocieteAccount';
15178 $module = 'societe';
15179 } elseif ($elementType == 'websitepage' || $elementType == 'website_page') {
15180 $classpath = 'website/class';
15181 $classfile = 'websitepage';
15182 $classname = 'Websitepage';
15183 $module = 'website';
15184 $subelement = 'websitepage';
15185 $table_element = 'website_page';
15186 } elseif ($elementType == 'fiscalyear') {
15187 $classpath = 'core/class';
15188 $module = 'accounting';
15189 $subelement = 'fiscalyear';
15190 } elseif ($elementType == 'chargesociales') {
15191 $classpath = 'compta/sociales/class';
15193 $table_element = 'chargesociales';
15194 } elseif ($elementType == 'tva') {
15195 $classpath = 'compta/tva/class';
15198 $table_element = 'tva';
15199 } elseif ($elementType == 'emailsenderprofile') {
15201 $classpath = 'core/class';
15202 $classfile = 'emailsenderprofile';
15203 $classname = 'EmailSenderProfile';
15204 $table_element = 'c_email_senderprofile';
15206 } elseif ($elementType == 'conferenceorboothattendee') {
15207 $classpath = 'eventorganization/class';
15208 $classfile = 'conferenceorboothattendee';
15209 $classname = 'ConferenceOrBoothAttendee';
15210 $module = 'eventorganization';
15211 } elseif ($elementType == 'conferenceorbooth') {
15212 $classpath = 'eventorganization/class';
15213 $classfile = 'conferenceorbooth';
15214 $classname = 'ConferenceOrBooth';
15215 $module = 'eventorganization';
15216 } elseif ($elementType == 'ccountry') {
15218 $classpath = 'core/class';
15219 $classfile = 'ccountry';
15220 $classname = 'Ccountry';
15221 $table_element = 'c_country';
15223 } elseif ($elementType == 'ecmfiles') {
15225 $classpath = 'ecm/class';
15226 $classfile = 'ecmfiles';
15227 $classname = 'Ecmfiles';
15228 $table_element = 'ecmfiles';
15230 } elseif ($elementType == 'knowledgerecord' || $elementType == 'knowledgemanagement') {
15231 $module = 'knowledgemanagement';
15232 $classpath = 'knowledgemanagement/class';
15233 $classfile = 'knowledgerecord';
15234 $classname = 'KnowledgeRecord';
15235 $table_element = 'knowledgemanagement_knowledgerecord';
15237 } elseif ($elementType == 'customer') {
15238 $module = 'societe';
15239 $classpath = 'societe/class';
15240 $classfile = 'client';
15241 $classname = 'Client';
15242 $table_element = 'societe';
15244 } elseif ($elementType == 'fournisseur' || $elementType == 'supplier') {
15245 $module = 'societe';
15246 $classpath = 'fourn/class';
15247 $classfile = 'fournisseur';
15248 $classname = 'Fournisseur';
15249 $table_element = 'societe';
15251 } elseif ($elementType == 'recruitmentcandidature') {
15252 $module = 'recruitment';
15253 $classfile = 'recruitmentcandidature';
15254 $classpath = 'recruitment/class';
15255 $classname = 'RecruitmentCandidature';
15256 $subelement = 'recruitmentcandidature';
15257 $subdir = '/recruitmentcandidature';
15258 } elseif ($elementType == 'recruitmentjobposition') {
15259 $module = 'recruitment';
15260 $classfile = 'recruitmentjobposition';
15261 $classpath = 'recruitment/class';
15262 $classname = 'RecruitmentJobPosition';
15263 $subelement = 'recruitmentjobposition';
15264 $subdir = '/recruitmentjobposition';
15268 if (empty($classfile)) {
15269 $classfile = strtolower($subelement);
15271 if (empty($classname)) {
15272 $classname = ucfirst($subelement);
15274 if (empty($classpath)) {
15275 $classpath = $module . '/class';
15278 //print 'getElementProperties subdir='.$subdir;
15281 if ($module && isset($conf->$module)) { // The generic case
15282 if (!empty($conf->$module->multidir_output[$conf->entity])) {
15283 $dir_output = $conf->$module->multidir_output[$conf->entity];
15284 } elseif (!empty($conf->$module->output[$conf->entity])) {
15285 $dir_output = $conf->$module->output[$conf->entity];
15286 } elseif (!empty($conf->$module->dir_output)) {
15287 $dir_output = $conf->$module->dir_output;
15289 if (!empty($conf->$module->multidir_temp[$conf->entity])) {
15290 $dir_temp = $conf->$module->multidir_temp[$conf->entity];
15291 } elseif (!empty($conf->$module->temp[$conf->entity])) {
15292 $dir_temp = $conf->$module->temp[$conf->entity];
15293 } elseif (!empty($conf->$module->dir_temp)) {
15294 $dir_temp = $conf->$module->dir_temp;
15298 // Overwrite value for special cases
15299 if ($element == 'order_supplier' && isModEnabled('fournisseur')) {
15300 $dir_output = $conf->fournisseur->commande->dir_output;
15301 $dir_temp = $conf->fournisseur->commande->dir_temp;
15302 } elseif ($element == 'invoice_supplier' && isModEnabled('fournisseur')) {
15303 $dir_output = $conf->fournisseur->facture->dir_output;
15304 $dir_temp = $conf->fournisseur->facture->dir_temp;
15306 $dir_output .= $subdir;
15307 $dir_temp .= $subdir;
15309 $elementProperties = array(
15310 'module' => $module,
15311 'element' => $element,
15312 'table_element' => $table_element,
15313 'subelement' => $subelement,
15314 'classpath' => $classpath,
15315 'classfile' => $classfile,
15316 'classname' => $classname,
15317 'dir_output' => $dir_output,
15318 'dir_temp' => $dir_temp,
15319 'parent_element' => $parent_element,
15324 if (!is_object($hookmanager)) {
15325 include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
15326 $hookmanager = new HookManager($db);
15328 $hookmanager->initHooks(array('elementproperties'));
15332 $parameters = array(
15333 'elementType' => $elementType,
15334 'elementProperties' => $elementProperties
15337 $reshook = $hookmanager->executeHooks('getElementProperties', $parameters);
15340 $elementProperties = $hookmanager->resArray;
15341 } elseif (!empty($hookmanager->resArray) && is_array($hookmanager->resArray)) { // resArray is always an array but for sécurity against misconfigured external modules
15342 $elementProperties = array_replace($elementProperties, $hookmanager->resArray);
15345 // context of elementproperties doesn't need to exist out of this function so delete it to avoid elementproperties context is equal to all
15346 if (($key = array_search('elementproperties', $hookmanager->contextarray)) !== false) {
15347 unset($hookmanager->contextarray[$key]);
15350 return $elementProperties;
15365function fetchObjectByElement($element_id, $element_type, $element_ref = '', $useCache = 0, $maxCacheByType = 10)
15371 $element_prop = getElementProperties($element_type);
15373 if ($element_prop['module'] == 'product' || $element_prop['module'] == 'service') {
15374 // For example, for an extrafield 'product' (shared for both product and service) that is a link to an object,
15375 // this is called with $element_type = 'product' when we need element properties of a service, we must return a product. If we create the
15376 // extrafield for a service, it is not supported and not found when editing the product/service card. So we must keep 'product' for extrafields
15377 // of service and we will return properties of a product.
15378 $ismodenabled = (isModEnabled('product') || isModEnabled('service'));
15379 } elseif ($element_prop['module'] == 'societeaccount') {
15380 $ismodenabled = isModEnabled('website') || isModEnabled('webportal');
15382 $ismodenabled = isModEnabled($element_prop['module']);
15384 //var_dump('element_type='.$element_type);
15385 //var_dump($element_prop);
15386 //var_dump($element_prop['module'].' '.$ismodenabled);
15387 if (is_array($element_prop) && (empty($element_prop['module']) || $ismodenabled)) {
15388 if ($useCache === 1 && $element_id > 0
15389 && !empty($conf->cache['fetchObjectByElement'][$element_type])
15390 && !empty($conf->cache['fetchObjectByElement'][$element_type][$element_id])
15391 && is_object($conf->cache['fetchObjectByElement'][$element_type][$element_id])
15393 return $conf->cache['fetchObjectByElement'][$element_type][$element_id];
15396 dol_include_once('/' . $element_prop['classpath'] . '/' . $element_prop['classfile'] . '.class.php');
15398 if (class_exists($element_prop['classname'])) {
15399 $className = $element_prop['classname'];
15400 $objecttmp = new $className($db);
15401 '@phan-var-force CommonObject $objecttmp';
15404 if ($element_id > 0 || !empty($element_ref)) {
15405 $ret = $objecttmp->fetch($element_id, $element_ref);
15407 if (empty($objecttmp->module)) {
15408 $objecttmp->module = $element_prop['module'];
15411 if ($useCache > 0) {
15412 if (!isset($conf->cache['fetchObjectByElement'][$element_type])) {
15413 $conf->cache['fetchObjectByElement'][$element_type] = [];
15416 // Manage cache limit
15417 if (! empty($conf->cache['fetchObjectByElement'][$element_type]) && is_array($conf->cache['fetchObjectByElement'][$element_type]) && count($conf->cache['fetchObjectByElement'][$element_type]) >= $maxCacheByType) {
15418 array_shift($conf->cache['fetchObjectByElement'][$element_type]);
15421 $conf->cache['fetchObjectByElement'][$element_type][$element_id] = $objecttmp;
15427 return $objecttmp; // returned an object without fetch
15430 dol_syslog($element_prop['classname'] . ' doesn\'t exists in /' . $element_prop['classpath'] . '/' . $element_prop['classfile'] . '.class.php');
15443function getExecutableContent()
15445 $arrayofregexextension = array(
15472 return $arrayofregexextension;
15481function isAFileWithExecutableContent($filename)
15483 $arrayofregexextension = getExecutableContent();
15485 foreach ($arrayofregexextension as $fileextension) {
15486 if (preg_match('/\.' . preg_quote($fileextension, '/') . '$/i', $filename)) {
15503 return empty($_SESSION['newtoken']) ? '' : $_SESSION['newtoken'];
15513function currentToken()
15515 return isset($_SESSION['token']) ? $_SESSION['token'] : '';
15527 if (empty($conf->cache['nonce'])) {
15528 include_once DOL_DOCUMENT_ROOT . '/core/lib/security.lib.php';
15529 $conf->cache['nonce'] = dolGetRandomBytes(8);
15532 return $conf->cache['nonce'];
15549function startSimpleTable($header, $link = "
", $arguments = "", $emptyColumns = 0, $number = -1, $pictofulllist = '')
15553 print '<div class="div-
table-responsive-no-min
">';
15554 print '<table class="noborder centpercent
">';
15555 print '<tr class="liste_titre
">';
15557 print ($emptyColumns < 1) ? '<th>' : '<th colspan="' . ($emptyColumns + 1) . '">';
15559 print '<span class="valignmiddle
">' . $langs->trans($header) . '</span>';
15561 if (!empty($link)) {
15562 if (!empty($arguments)) {
15563 print '<a href="' . DOL_URL_ROOT . '/
' . $link . '?
' . $arguments . '">';
15565 print '<a href="' . DOL_URL_ROOT . '/
' . $link . '">';
15569 if ($number > -1) {
15570 print '<span class="badge marginleftonlyshort
">' . $number . '</span>';
15571 } elseif (!empty($link)) {
15572 print '<span class="badge marginleftonlyshort
">...</span>';
15575 if (!empty($link)) {
15581 if ($number < 0 && !empty($link)) {
15582 print '<th class="right
">';
15597function finishSimpleTable($addLineBreak = false)
15602 if ($addLineBreak) {
15618function addSummaryTableLine($tableColumnCount, $num, $nbofloop = 0, $total = 0, $noneWord = "None
", $extraRightColumn = false)
15623 print '<tr class="oddeven
">';
15624 print '<td colspan="' . $tableColumnCount . '"><span class="opacitymedium
">' . $langs->trans($noneWord) . '</span></td>';
15629 if ($nbofloop === 0) {
15630 // don't show a summary line
15634 /* Case already handled above, commented to satisfy phpstan.
15636 $colspan = $tableColumnCount;
15639 if ($num > $nbofloop) {
15640 $colspan = $tableColumnCount;
15642 $colspan = $tableColumnCount - 1;
15645 if ($extraRightColumn) {
15649 print '<tr class="liste_total
">';
15651 if ($nbofloop > 0 && $num > $nbofloop) {
15652 print '<td colspan="' . $colspan . '" class="right
">' . $langs->trans("XMoreLines
", ($num - $nbofloop)) . '</td>';
15654 print '<td colspan="' . $colspan . '" class="right
"> ' . $langs->trans("Total
") . '</td>';
15655 print '<td class="right centpercent
">' . price($total) . '</td>';
15658 if ($extraRightColumn) {
15673function readfileLowMemory($fullpath_original_file_osencoded, $method = -1)
15675 if ($method == -1) {
15677 if (getDolGlobalString('MAIN_FORCE_READFILE_WITH_FREAD')) {
15680 if (getDolGlobalString('MAIN_FORCE_READFILE_WITH_STREAM_COPY')) {
15685 // Be sure we don't have output buffering enabled to have readfile working correctly
15686 while (ob_get_level()) {
15691 if ($method == 0) {
15692 readfile($fullpath_original_file_osencoded);
15693 } elseif ($method == 1) {
15695 $handle = fopen($fullpath_original_file_osencoded, "rb
");
15696 while (!feof($handle)) {
15697 print fread($handle, 8192);
15700 } elseif ($method == 2) {
15702 $handle1 = fopen($fullpath_original_file_osencoded, "rb
");
15703 $handle2 = fopen("php:
15704 stream_copy_to_stream($handle1, $handle2);
15725 $result =
'<span class="clipboardCP' . ($showonlyonhover ?
' clipboardCPShowOnHover valignmiddle' :
'') .
'">';
15726 if ($texttoshow ===
'none') {
15727 $result .=
'<' . $tag .
' class="clipboardCPValue hidewithsize">' .
dol_escape_htmltag($valuetocopy, 1, 1) .
'</' . $tag .
'>';
15728 $result .=
'<span class="clipboardCPValueToPrint"></span>';
15729 } elseif ($texttoshow) {
15730 $result .=
'<' . $tag .
' class="clipboardCPValue hidewithsize">' .
dol_escape_htmltag($valuetocopy, 1, 1) .
'</' . $tag .
'>';
15731 $result .=
'<span class="clipboardCPValueToPrint">' .
dol_escape_htmltag($texttoshow, 1, 1) .
'</span>';
15733 $result .=
'<' . $tag .
' class="clipboardCPValue">' .
dol_escape_htmltag($valuetocopy, 1, 1) .
'</' . $tag .
'>';
15735 $result .=
'<span class="clipboardCPButton far fa-clipboard opacitymedium paddingleft pictomodule" title="' .
dolPrintHTML($langs->trans(
"ClickToCopyToClipboard")) .
'"></span>';
15736 $result .=
img_picto(
'',
'tick',
'class="clipboardCPTick hidden paddingleft pictomodule"');
15737 $result .=
'<span class="clipboardCPText"></span>';
15738 $result .=
'</span>';
15753 $result = json_decode($stringtodecode, $assoc);
15754 if ($result ===
null) {
15755 $result = unserialize($stringtodecode, [
'allowed_classes' =>
false]);
15782 if (is_null($filter) || !is_string($filter) || $filter ===
'') {
15785 if (!preg_match(
'/^\(.*\)$/', $filter)) {
15786 $filter =
'(' . $filter .
')';
15789 $regexstring =
'\(([a-zA-Z0-9_\.]+:[<>!=insotlke]+:[^\(\)]+)\)';
15790 $firstandlastparenthesis = 0;
15792 if (!
dolCheckFilters($filter, $errorstr, $firstandlastparenthesis)) {
15796 return 'Filter syntax error - ' . $errorstr;
15801 $t = preg_replace_callback(
'/' . $regexstring .
'/i',
'dolForgeDummyCriteriaCallback', $filter);
15802 $t = str_ireplace(array(
'and',
'or',
' '),
'', $t);
15805 if (preg_match(
'/[^\(\)]/', $t)) {
15806 $tmperrorstr =
'Bad syntax of the search string';
15807 $errorstr =
'Bad syntax of the search string: ' . $filter;
15811 dol_syslog(
"forgeSQLFromUniversalSearchCriteria Filter error - " . $errorstr, LOG_WARNING);
15812 return 'Filter error - ' . $tmperrorstr;
15816 $ret = ($noand ?
"" :
" AND ") . ($nopar ?
"" :
'(') . preg_replace_callback(
'/' . $regexstring .
'/i',
'dolForgeSQLCriteriaCallback', $filter) . ($nopar ?
"" :
')');
15818 if (is_object($db)) {
15819 $ret = str_replace(
'__NOW__',
"'" . $db->idate(
dol_now()) .
"'", $ret);
15821 if (is_object($user)) {
15822 $ret = str_replace(
'__USER_ID__', (
string) $user->id, $ret);
15837 $arrayofandtags = array();
15841 $parenthesislevel = 0;
15846 if ($parenthesislevel >= 1) {
15847 $sqlfilters = preg_replace(
'/^\(/',
'', preg_replace(
'/\)$/',
'', $sqlfilters));
15852 $countparenthesis = 0;
15853 while ($i < $nbofchars) {
15856 if ($char ==
'(') {
15857 $countparenthesis++;
15858 } elseif ($char ==
')') {
15859 $countparenthesis--;
15862 if ($countparenthesis == 0) {
15863 $char2 =
dol_substr($sqlfilters, $i + 1, 1);
15864 $char3 =
dol_substr($sqlfilters, $i + 2, 1);
15865 if ($char ==
'A' && $char2 ==
'N' && $char3 ==
'D') {
15868 if (!preg_match(
'/^\(.*\)$/', $s)) {
15869 $s =
'(' . $s .
')';
15871 $arrayofandtags[] = $s;
15884 if (!preg_match(
'/^\(.*\)$/', $s)) {
15885 $s =
'(' . $s .
')';
15887 $arrayofandtags[] = $s;
15890 return $arrayofandtags;
15902function dolCheckFilters($sqlfilters, &$error =
'', &$parenthesislevel = 0)
15906 $tmp = $sqlfilters;
15910 $parenthesislevel = 0;
15918 if ($char ==
'(') {
15919 if ($i == $parenthesislevel && $parenthesislevel == $counter) {
15921 $parenthesislevel++;
15924 } elseif ($char ==
')') {
15925 $nbcharremaining = ($nb - $i - 1);
15926 if ($nbcharremaining >= $counter) {
15927 $parenthesislevel = min($parenthesislevel, $counter - 1);
15929 if ($parenthesislevel > $counter && $nbcharremaining >= $counter) {
15930 $parenthesislevel = $counter;
15935 if ($counter < 0) {
15936 $error =
"Wrong balance of parenthesis in sqlfilters=" . $sqlfilters;
15937 $parenthesislevel = 0;
15945 if ($counter > 0) {
15946 $error =
"Wrong balance of parenthesis in sqlfilters=" . $sqlfilters;
15947 $parenthesislevel = 0;
15965 if (empty($matches[1])) {
15968 $tmp = explode(
':', $matches[1]);
15969 if (count($tmp) < 3) {
15989 if (empty($matches[1])) {
15992 $tmp = explode(
':', $matches[1], 3);
15993 if (count($tmp) < 3) {
15997 $operand = preg_replace(
'/[^a-z0-9\._]/i',
'', trim($tmp[0]));
15999 $operator = strtoupper(preg_replace(
'/[^a-z<>!=]/i',
'', trim($tmp[1])));
16002 'NOTLIKE' =>
'NOT LIKE',
16003 'ISNOT' =>
'IS NOT',
16004 'NOTIN' =>
'NOT IN',
16008 if (array_key_exists($operator, $realOperator)) {
16009 $operator = $realOperator[$operator];
16012 $tmpescaped = $tmp[2];
16018 if ($operator ==
'IN' || $operator ==
'NOT IN') {
16020 $tmpescaped2 =
'(';
16022 $tmpelemarray = explode(
',', $tmpescaped);
16023 foreach ($tmpelemarray as $tmpkey => $tmpelem) {
16025 $tmpelem = trim($tmpelem);
16026 if (preg_match(
'/^\'(.*)\'$/', $tmpelem, $reg)) {
16027 $tmpelemarray[$tmpkey] =
"'" . $db->escape($db->sanitize($reg[1], 2, 1, 1, 1)) .
"'";
16028 $tmpelemarray[$tmpkey] =
"'".$db->escape($db->sanitize($reg[1], 2, 1, 1, 1)).
"'";
16029 } elseif (preg_match(
'/^[0-9]+$/', (
string) $tmpelem)) {
16030 $tmpelemarray[$tmpkey] = (int) $tmpelem;
16031 } elseif (is_numeric((
string) $tmpelem)) {
16032 $tmpelemarray[$tmpkey] = (float) $tmpelem;
16033 } elseif (!
getDolGlobalString(
"MAIN_DISALLOW_UNSECURED_SELECT_INTO_EXTRAFIELDS_FILTER")) {
16034 $tmpelemarray[$tmpkey] = preg_replace(
'/[^a-z0-9_<>=!\s]/i',
'', $tmpelem);
16036 $tmpelemarray[$tmpkey] = preg_replace(
'/[^a-z0-9_]/i',
'', $tmpelem);
16039 $tmpescaped2 .= implode(
',', $tmpelemarray);
16040 $tmpescaped2 .=
')';
16042 $tmpescaped = $tmpescaped2;
16043 } elseif ($operator ==
'LIKE' || $operator ==
'NOT LIKE') {
16044 if (preg_match(
'/^\'([^\']*)\'$/', $tmpescaped, $regbis)) {
16045 $tmpescaped = $regbis[1];
16048 $tmpescaped =
"'" . $db->escape($tmpescaped) .
"'";
16049 } elseif (preg_match(
'/^\'(.*)\'$/', $tmpescaped, $regbis)) {
16052 $tmpescaped =
"'" . $db->escape($regbis[1]) .
"'";
16054 if (strtoupper($tmpescaped) ==
'NULL') {
16055 $tmpescaped =
'NULL';
16056 } elseif (preg_match(
'/^[0-9]+$/', (
string) $tmpescaped)) {
16057 $tmpescaped = (int) $tmpescaped;
16058 } elseif (is_numeric((
string) $tmpescaped)) {
16059 $tmpescaped = (float) $tmpescaped;
16061 $tmpescaped = preg_replace(
'/[^a-z0-9_]/i',
'', $tmpescaped);
16065 return '(' . $db->escape($operand) .
' ' . strtoupper($operator) .
' ' . $tmpescaped .
')';
16082 $out =
'<!-- timeline icon -->' .
"\n";
16083 $iconClass =
'fa fa-comments';
16088 if ($histo[$key][
'percent'] == -1) {
16089 $colorClass =
'timeline-icon-not-applicble';
16090 $pictoTitle = $langs->trans(
'StatusNotApplicable');
16091 } elseif ($histo[$key][
'percent'] == 0) {
16092 $colorClass =
'timeline-icon-todo';
16093 $pictoTitle = $langs->trans(
'StatusActionToDo') .
' (0%)';
16094 } elseif ($histo[$key][
'percent'] > 0 && $histo[$key][
'percent'] < 100) {
16095 $colorClass =
'timeline-icon-in-progress';
16096 $pictoTitle = $langs->trans(
'StatusActionInProcess') .
' (' . $histo[$key][
'percent'] .
'%)';
16097 } elseif ($histo[$key][
'percent'] >= 100) {
16098 $colorClass =
'timeline-icon-done';
16099 $pictoTitle = $langs->trans(
'StatusActionDone') .
' (100%)';
16102 if ($actionstatic->code ==
'AC_TICKET_CREATE') {
16103 $iconClass =
'fa fa-ticket';
16104 } elseif ($actionstatic->code ==
'AC_TICKET_MODIFY') {
16105 $iconClass =
'fa fa-pencilxxx';
16106 } elseif (preg_match(
'/^TICKET_MSG/', $actionstatic->code)) {
16107 $iconClass =
'fa fa-comments';
16108 } elseif (preg_match(
'/^TICKET_MSG_PRIVATE/', $actionstatic->code)) {
16109 $iconClass =
'fa fa-mask';
16111 if ($actionstatic->type_picto) {
16112 $img_picto =
img_picto(
'', $actionstatic->type_picto);
16114 if ($actionstatic->type_code ==
'AC_RDV') {
16115 $iconClass =
'fa fa-handshake';
16116 } elseif ($actionstatic->type_code ==
'AC_TEL') {
16117 $iconClass =
'fa fa-phone';
16118 } elseif ($actionstatic->type_code ==
'AC_FAX') {
16119 $iconClass =
'fa fa-fax';
16120 } elseif ($actionstatic->type_code ==
'AC_EMAIL') {
16121 $iconClass =
'fa fa-envelope';
16122 } elseif ($actionstatic->type_code ==
'AC_INT') {
16123 $iconClass =
'fa fa-shipping-fast';
16124 } elseif ($actionstatic->type_code ==
'AC_OTH_AUTO') {
16125 $iconClass =
'fa fa-robot';
16126 } elseif (!preg_match(
'/_AUTO/', $actionstatic->type_code)) {
16127 $iconClass =
'fa fa-robot';
16132 $out .=
'<i class="' . $iconClass .
' ' . $colorClass .
'" title="' . $pictoTitle .
'">' . $img_picto .
'</i>' .
"\n";
16146 $documents = array();
16148 $sql =
'SELECT ecm.rowid as id, ecm.src_object_type, ecm.src_object_id, ecm.filepath, ecm.filename, ecm.agenda_id';
16149 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'ecm_files ecm';
16150 $sql .=
" WHERE ecm.filepath = 'agenda/" . ((int)
$object->id) .
"'";
16152 $sql .=
' OR ecm.agenda_id = ' . (int)
$object->id;
16153 $sql .=
' ORDER BY ecm.position ASC';
16155 $resql = $db->query($sql);
16157 if ($db->num_rows($resql)) {
16158 while ($obj = $db->fetch_object($resql)) {
16159 $documents[$obj->id] = $obj;
16185function show_actions_messaging($conf, $langs, $db, $filterobj, $objcon =
null, $noprint = 0, $actioncode =
'', $donetodo =
'done', $filters = array(), $sortfield =
'a.datep,a.id', $sortorder =
'DESC')
16187 global $user, $conf;
16190 global $param, $massactionbutton;
16192 require_once DOL_DOCUMENT_ROOT .
'/comm/action/class/actioncomm.class.php';
16195 if (!is_object($filterobj) && !is_object($objcon)) {
16200 '@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';
16205 $sortfield_list = explode(
',', $sortfield);
16206 $sortfield_label_list = array(
'a.id' =>
'id',
'a.datep' =>
'dp',
'a.percent' =>
'percent');
16207 $sortfield_new_list = array();
16208 foreach ($sortfield_list as $sortfield_value) {
16209 $sortfield_new_list[] = $sortfield_label_list[trim($sortfield_value)];
16211 $sortfield_new = implode(
',', $sortfield_new_list);
16218 if (is_object($objcon) && $objcon->id > 0) {
16219 $sql =
"SELECT DISTINCT a.id, a.label as label,";
16221 $sql =
"SELECT a.id, a.label as label,";
16223 $sql .=
" a.datep as dp,";
16224 $sql .=
" a.note as message,";
16225 $sql .=
" a.datep2 as dp2,";
16226 $sql .=
" a.percent as percent, 'action' as type,";
16227 $sql .=
" a.fk_element, a.elementtype,";
16228 $sql .=
" a.fk_contact,";
16229 $sql .=
" a.email_from as msg_from,";
16230 $sql .=
" c.code as acode, c.libelle as alabel, c.picto as apicto,";
16231 $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";
16232 if (is_object($filterobj) && get_class($filterobj) ==
'Societe') {
16233 $sql .=
", sp.lastname, sp.firstname";
16234 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Adherent') {
16235 $sql .=
", m.lastname, m.firstname";
16236 } elseif (is_object($filterobj) && in_array(get_class($filterobj), array(
'Commande',
'CommandeFournisseur',
'Product',
'Ticket',
'BOM',
'Contrat',
'Facture',
'FactureFournisseur',
'Propal',
'Expedition'))) {
16239 if (is_object($filterobj) && !empty($filterobj->table_element) && !empty($filterobj->element) && !empty($filterobj->id) && array_key_exists(
'ref', $filterobj->fields)) {
16243 $sql .=
" FROM " . MAIN_DB_PREFIX .
"actioncomm as a";
16244 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"user as u on u.rowid = a.fk_user_action";
16245 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"c_actioncomm as c ON a.fk_action = c.id";
16247 $force_filter_contact = $filterobj instanceof
User;
16249 if (is_object($objcon) && $objcon->id > 0) {
16250 $force_filter_contact =
true;
16251 $sql .=
" INNER JOIN " . MAIN_DB_PREFIX .
"actioncomm_resources as r ON a.id = r.fk_actioncomm";
16252 $sql .=
" AND r.element_type = '" . $db->escape($objcon->table_element) .
"' AND r.fk_element = " . ((int) $objcon->id);
16255 if ((is_object($filterobj) && get_class($filterobj) ==
'Societe') || (is_object($filterobj) && get_class($filterobj) ==
'Contact')) {
16256 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"socpeople as sp ON a.fk_contact = sp.rowid";
16257 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Dolresource') {
16258 $sql .=
" INNER JOIN " . MAIN_DB_PREFIX .
"element_resources as er";
16259 $sql .=
" ON er.resource_type = 'dolresource'";
16260 $sql .=
" AND er.element_id = a.id";
16261 $sql .=
" AND er.resource_id = " . ((int) $filterobj->id);
16262 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Adherent') {
16263 $sql .=
", " . MAIN_DB_PREFIX .
"adherent as m";
16264 } elseif (is_object($filterobj) && get_class($filterobj) ==
'CommandeFournisseur') {
16265 $sql .=
", " . MAIN_DB_PREFIX .
"commande_fournisseur as o";
16266 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Product') {
16267 $sql .=
", " . MAIN_DB_PREFIX .
"product as o";
16268 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Ticket') {
16269 $sql .=
", " . MAIN_DB_PREFIX .
"ticket as o";
16270 } elseif (is_object($filterobj) && get_class($filterobj) ==
'BOM') {
16271 $sql .=
", " . MAIN_DB_PREFIX .
"bom_bom as o";
16272 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Contrat') {
16273 $sql .=
", " . MAIN_DB_PREFIX .
"contrat as o";
16274 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Facture') {
16275 $sql .=
", " . MAIN_DB_PREFIX .
"facture as o";
16276 } elseif (is_object($filterobj) && get_class($filterobj) ==
'FactureFournisseur') {
16277 $sql .=
", " . MAIN_DB_PREFIX .
"facture_fourn as o";
16278 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Commande') {
16279 $sql .=
", " . MAIN_DB_PREFIX .
"commande as o";
16280 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Expedition') {
16281 $sql .=
", " . MAIN_DB_PREFIX .
"expedition as o";
16282 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Propal') {
16283 $sql .=
", " . MAIN_DB_PREFIX .
"propal as o";
16285 if (is_object($filterobj) && !empty($filterobj->table_element) && !empty($filterobj->element) && !empty($filterobj->id) && array_key_exists(
'ref', $filterobj->fields)) {
16286 $sql .=
", " . MAIN_DB_PREFIX . $filterobj->table_element .
" as o";
16289 $sql .=
" WHERE a.entity IN (" .
getEntity(
'agenda') .
")";
16290 if (!$force_filter_contact) {
16291 if (is_object($filterobj) && in_array(get_class($filterobj), array(
'Societe',
'Client',
'Fournisseur')) && $filterobj->id) {
16292 $sql .=
" AND a.fk_soc = " . ((int) $filterobj->id);
16293 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Project' && $filterobj->id) {
16294 $sql .=
" AND a.fk_project = o.rowid AND a.fk_project = " . ((int) $filterobj->id);
16295 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Adherent') {
16296 $sql .=
" AND a.fk_element = m.rowid AND a.elementtype = 'member'";
16297 if ($filterobj->id) {
16298 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16300 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Commande') {
16301 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'order'";
16302 if ($filterobj->id) {
16303 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16305 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Expedition') {
16306 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'shipping'";
16307 if ($filterobj->id) {
16308 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16310 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Propal') {
16311 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'propal'";
16312 if ($filterobj->id) {
16313 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16315 } elseif (is_object($filterobj) && get_class($filterobj) ==
'CommandeFournisseur') {
16316 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'order_supplier'";
16317 if ($filterobj->id) {
16318 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16320 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Product') {
16321 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'product'";
16322 if ($filterobj->id) {
16323 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16325 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Ticket') {
16326 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'ticket'";
16327 if ($filterobj->id) {
16328 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16330 } elseif (is_object($filterobj) && get_class($filterobj) ==
'BOM') {
16331 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'bom'";
16332 if ($filterobj->id) {
16333 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16335 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Contrat') {
16336 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'contract'";
16337 if ($filterobj->id) {
16338 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16340 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Contact' && $filterobj->id) {
16341 $sql .=
" AND a.fk_contact = sp.rowid";
16342 if ($filterobj->id) {
16343 $sql .=
" AND a.fk_contact = " . ((int) $filterobj->id);
16345 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Facture') {
16346 $sql .=
" AND a.fk_element = o.rowid";
16347 if ($filterobj->id) {
16348 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id) .
" AND a.elementtype = 'invoice'";
16350 } elseif (is_object($filterobj) && get_class($filterobj) ==
'FactureFournisseur') {
16351 $sql .=
" AND a.fk_element = o.rowid";
16352 if ($filterobj->id) {
16353 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id) .
" AND a.elementtype = 'invoice_supplier'";
16356 if (is_object($filterobj) && !empty($filterobj->element) && !empty($filterobj->id) && array_key_exists(
'ref', $filterobj->fields)) {
16357 $sql .=
" AND a.fk_element = o.rowid";
16358 $sql .=
" AND a.elementtype = '" . $db->escape($filterobj->element) .
"'";
16359 if ($filterobj->id) {
16360 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16365 $sql .=
" AND u.rowid = " . ((int) $filterobj->id);
16369 if (!empty($actioncode) && $actioncode !=
'-1') {
16371 if ($actioncode ==
'AC_NON_AUTO') {
16372 $sql .=
" AND c.type != 'systemauto'";
16373 } elseif ($actioncode ==
'AC_ALL_AUTO') {
16374 $sql .=
" AND c.type = 'systemauto'";
16376 if ($actioncode ==
'AC_OTH') {
16377 $sql .=
" AND c.type != 'systemauto'";
16378 } elseif ($actioncode ==
'AC_OTH_AUTO') {
16379 $sql .=
" AND c.type = 'systemauto'";
16383 if ($actioncode ==
'AC_NON_AUTO') {
16384 $sql .=
" AND c.type != 'systemauto'";
16385 } elseif ($actioncode ==
'AC_ALL_AUTO') {
16386 $sql .=
" AND c.type = 'systemauto'";
16388 $sql .=
" AND c.code = '" . $db->escape($actioncode) .
"'";
16392 if ($donetodo ==
'todo') {
16393 $sql .=
" AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '" . $db->idate($now) .
"'))";
16394 } elseif ($donetodo ==
'done') {
16395 $sql .=
" AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '" . $db->idate($now) .
"'))";
16397 if (is_array($filters) && $filters[
'search_agenda_label']) {
16398 $sql .=
natural_search(
'a.label', $filters[
'search_agenda_label']);
16405 && (empty($actioncode) || $actioncode ==
'AC_OTH_AUTO' || $actioncode ==
'AC_EMAILING')
16407 $langs->load(
"mails");
16409 $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";
16410 $sql2 .=
", null as fk_element, '' as elementtype, null as contact_id";
16411 $sql2 .=
", 'AC_EMAILING' as acode, '' as alabel, '' as apicto";
16412 $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";
16413 if (is_object($filterobj) && get_class($filterobj) ==
'Societe') {
16414 $sql2 .=
", '' as lastname, '' as firstname";
16415 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Adherent') {
16416 $sql2 .=
", '' as lastname, '' as firstname";
16417 } elseif (is_object($filterobj) && get_class($filterobj) ==
'CommandeFournisseur') {
16418 $sql2 .=
", '' as ref";
16419 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Product') {
16420 $sql2 .=
", '' as ref";
16421 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Ticket') {
16422 $sql2 .=
", '' as ref";
16424 $sql2 .=
" FROM " . MAIN_DB_PREFIX .
"mailing as m, " . MAIN_DB_PREFIX .
"mailing_cibles as mc, " . MAIN_DB_PREFIX .
"user as u";
16425 $sql2 .=
" WHERE mc.email = '" . $db->escape($objcon->email) .
"'";
16426 $sql2 .=
" AND mc.statut = 1";
16427 $sql2 .=
" AND u.rowid = m.fk_user_valid";
16428 $sql2 .=
" AND mc.fk_mailing=m.rowid";
16432 $MAXWITHOUTPAGINATION =
getDolGlobalInt(
'AGENDA_MAX_EVENTS_ON_PAGE_WITHOUT_PAGINATION', 100);
16434 if ($sql || $sql2) {
16435 if (!empty($sql) && !empty($sql2)) {
16436 $sql = $sql .
" UNION " . $sql2;
16437 } elseif (empty($sql) && !empty($sql2)) {
16443 $limit = $MAXWITHOUTPAGINATION;
16446 $sql .= $db->order($sortfield_new, $sortorder);
16448 $sql .= $db->plimit($limit + 1, $offset);
16451 dol_syslog(
"function.lib::show_actions_messaging", LOG_DEBUG);
16453 $resql = $db->query($sql);
16456 $num = $db->num_rows($resql);
16458 $imaxinloop = ($limit ? min($num, $limit) : $num);
16459 while ($i < $imaxinloop) {
16460 $obj = $db->fetch_object($resql);
16462 if ($obj->type ==
'action') {
16464 $contactaction->id = $obj->id;
16465 $result = $contactaction->fetchResources();
16468 setEventMessage(
"actions.lib::show_actions_messaging Error fetch resource",
'errors');
16474 if (($obj->percent >= 0 and $obj->percent < 100) || ($obj->percent == -1 && $obj->dp > $now)) {
16475 $tododone =
'todo';
16478 $histo[$numaction] = array(
16479 'type' => $obj->type,
16480 'tododone' => $tododone,
16482 'datestart' => $db->jdate($obj->dp),
16483 'dateend' => $db->jdate($obj->dp2),
16484 'note' => $obj->label,
16485 'message' => $obj->message,
16486 'percent' => $obj->percent,
16488 'userid' => $obj->user_id,
16489 'login' => $obj->user_login,
16490 'userfirstname' => $obj->user_firstname,
16491 'userlastname' => $obj->user_lastname,
16492 'userphoto' => $obj->user_photo,
16493 'msg_from' => $obj->msg_from,
16495 'contact_id' => $obj->fk_contact,
16496 'socpeopleassigned' => $contactaction->socpeopleassigned,
16497 'lastname' => (empty($obj->lastname) ?
'' : $obj->lastname),
16498 'firstname' => (empty($obj->firstname) ?
'' : $obj->firstname),
16499 'fk_element' => $obj->fk_element,
16500 'elementtype' => $obj->elementtype,
16502 'acode' => $obj->acode,
16503 'alabel' => $obj->alabel,
16504 'libelle' => $obj->alabel,
16505 'apicto' => $obj->apicto
16508 $histo[$numaction] = array(
16509 'type' => $obj->type,
16510 'tododone' =>
'done',
16512 'datestart' => $db->jdate($obj->dp),
16513 'dateend' => $db->jdate($obj->dp2),
16514 'note' => $obj->label,
16515 'message' => $obj->message,
16516 'percent' => $obj->percent,
16517 'acode' => $obj->acode,
16519 'userid' => $obj->user_id,
16520 'login' => $obj->user_login,
16521 'userfirstname' => $obj->user_firstname,
16522 'userlastname' => $obj->user_lastname,
16523 'userphoto' => $obj->user_photo
16539 $langs->loadLangs(array(
"admin",
"errors"));
16540 $out =
info_admin($langs->trans(
"WarningModuleXDisabledSoYouMayMissEventHere", $langs->transnoentitiesnoconv(
"Module2400Name")), 0, 0,
'warning');
16544 $delay_warning =
getDolGlobalInt(
'MAIN_DELAY_ACTIONS_TODO') * 24 * 60 * 60;
16546 require_once DOL_DOCUMENT_ROOT .
'/comm/action/class/actioncomm.class.php';
16547 include_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
16548 require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formactions.class.php';
16549 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
16554 $userstatic =
new User($db);
16555 $contactstatic =
new Contact($db);
16556 $userGetNomUrlCache = array();
16557 $contactGetNomUrlCache = array();
16559 $out .=
'<div class="filters-container" >';
16560 $out .=
'<form name="listactionsfilter" class="listactionsfilter" action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST">';
16561 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
16564 $objcon && get_class($objcon) ==
'Contact' &&
16565 (is_null($filterobj) || get_class($filterobj) ==
'Societe')
16567 $out .=
'<input type="hidden" name="id" value="' . $objcon->id .
'" />';
16569 $out .=
'<input type="hidden" name="id" value="' . $filterobj->id .
'" />';
16571 if (($filterobj && get_class($filterobj) ==
'Societe')) {
16572 $out .=
'<input type="hidden" name="socid" value="' . $filterobj->id .
'" />';
16574 $out .=
'<input type="hidden" name="userid" value="' . $filterobj->id .
'" />';
16579 $out .=
'<div class="div-table-responsive-no-min">';
16580 $out .=
'<table class="noborder borderbottom centpercent">';
16582 $out .=
'<tr class="liste_titre">';
16586 $out .=
'<th class="liste_titre width50 middle">';
16587 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0,
'checkforselect', 1);
16588 $out .= $searchpicto;
16593 $out .=
getTitleFieldOfList(
'Date', 0, $_SERVER[
"PHP_SELF"],
'a.datep',
'', $param,
'', $sortfield, $sortorder,
'nowraponall nopaddingleftimp ') .
"\n";
16595 $out .=
'<th class="liste_titre hideonsmartphone"><strong class="hideonsmartphone">' . $langs->trans(
"Search") .
' : </strong></th>';
16597 $out .=
'<th class="liste_titre"></th>';
16600 $out .=
'<th class="liste_titre">';
16601 $out .=
'<span class="fas fa-square inline-block fawidth30 hideonsmartphone" style="color: #ddd;" title="' . $langs->trans(
"ActionType") .
'"></span>';
16602 $out .= $formactions->select_type_actions($actioncode,
"actioncode",
'',
getDolGlobalString(
'AGENDA_USE_EVENT_TYPE') ? -1 : 1, 0, 0, 1,
'selecttype minwidth100', $langs->trans(
"Type"));
16605 $out .=
'<th class="liste_titre maxwidth100onsmartphone">';
16606 $out .=
'<input type="text" class="maxwidth100onsmartphone" name="search_agenda_label" value="' . $filters[
'search_agenda_label'] .
'" placeholder="' . $langs->trans(
"Label") .
'">';
16611 $out .=
'<th class="liste_titre width50 middle">';
16612 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0,
'checkforselect', 1);
16613 $out .= $searchpicto;
16619 $out .=
'</table>';
16626 $out .=
'<ul class="timeline">';
16630 if ($filterobj instanceof
Societe) {
16631 $tmp .=
'<a href="' . DOL_URL_ROOT .
'/comm/action/list.php?mode=show_list&socid=' . $filterobj->id .
'&status=done">';
16633 if ($filterobj instanceof
User) {
16634 $tmp .=
'<a href="' . DOL_URL_ROOT .
'/comm/action/list.php?mode=show_list&socid=' . $filterobj->id .
'&status=done">';
16636 $tmp .= ($donetodo !=
'done' ? $langs->trans(
"ActionsToDoShort") :
'');
16637 $tmp .= ($donetodo !=
'done' && $donetodo !=
'todo' ?
' / ' :
'');
16638 $tmp .= ($donetodo !=
'todo' ? $langs->trans(
"ActionsDoneShort") :
'');
16640 if ($filterobj instanceof
Societe) {
16643 if ($filterobj instanceof
User) {
16649 require_once DOL_DOCUMENT_ROOT .
'/comm/action/class/cactioncomm.class.php';
16651 $arraylist = $caction->liste_array(1,
'code',
'', (!
getDolGlobalString(
'AGENDA_USE_EVENT_TYPE') ? 1 : 0),
'', 1);
16653 $actualCycleDate =
false;
16656 foreach ($histo as $key => $value) {
16657 $actionstatic->fetch($histo[$key][
'id']);
16659 $actionstatic->type_picto = $histo[$key][
'apicto'];
16660 $actionstatic->type_code = $histo[$key][
'acode'];
16662 $labeltype = $actionstatic->type_code;
16663 if (!
getDolGlobalString(
'AGENDA_USE_EVENT_TYPE') && empty($arraylist[$labeltype])) {
16664 $labeltype =
'AC_OTH';
16666 if (!empty($actionstatic->code) && preg_match(
'/^TICKET_MSG/', $actionstatic->code)) {
16667 $labeltype = $langs->trans(
"Message");
16669 if (!empty($arraylist[$labeltype])) {
16670 $labeltype = $arraylist[$labeltype];
16672 if ($actionstatic->type_code ==
'AC_OTH_AUTO' && ($actionstatic->type_code != $actionstatic->code) && $labeltype && !empty($arraylist[$actionstatic->code])) {
16673 $labeltype .=
' - ' . $arraylist[$actionstatic->code];
16677 $url = DOL_URL_ROOT .
'/comm/action/card.php?id=' . $histo[$key][
'id'];
16679 $tmpa =
dol_getdate($histo[$key][
'datestart'],
false);
16681 if (isset($tmpa[
'year']) && isset($tmpa[
'yday']) && $actualCycleDate !== $tmpa[
'year'] .
'-' . $tmpa[
'yday']) {
16682 $actualCycleDate = $tmpa[
'year'] .
'-' . $tmpa[
'yday'];
16683 $out .=
'<!-- timeline time label -->';
16684 $out .=
'<li class="time-label">';
16685 $out .=
'<span class="timeline-badge-date">';
16686 $out .=
dol_print_date($histo[$key][
'datestart'],
'daytext',
'tzuserrel', $langs);
16689 $out .=
'<!-- /.timeline-label -->';
16693 $out .=
'<!-- timeline item -->' .
"\n";
16694 $out .=
'<li class="timeline-code-' . (!empty($actionstatic->code) ? strtolower($actionstatic->code) :
"none") .
'">';
16697 $typeicon = $actionstatic->getTypePicto(
'pictofixedwidth timeline-icon-not-applicble', $labeltype);
16702 $out .=
'<div class="timeline-item">' .
"\n";
16704 $out .=
'<span class="time timeline-header-action2">';
16706 if (isset($histo[$key][
'type']) && $histo[$key][
'type'] ==
'mailing') {
16707 $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") .
' ';
16708 $out .= $histo[$key][
'id'];
16711 $out .= $actionstatic->getNomUrl(1, -1,
'valignmiddle') .
' ';
16715 $user->hasRight(
'agenda',
'allactions',
'create') ||
16716 (($actionstatic->authorid == $user->id || $actionstatic->userownerid == $user->id) && $user->hasRight(
'agenda',
'myactions',
'create'))
16718 $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) .
'">';
16720 $out .=
img_picto($langs->trans(
"Modify"),
'edit',
'class="edita"');
16727 $out .=
'<span class="time"><i class="fa fa-clock valignmiddle"></i> ';
16728 $out .=
'<span class="valignmiddle marginrightonly">';
16729 $out .=
dol_print_date($histo[$key][
'datestart'],
'day',
'tzuserrel');
16732 $out .=
' '.dol_print_date($histo[$key][
'datestart'],
'hour',
'tzuserrel',
null,
false,
'opacitymedium');
16734 if ($histo[$key][
'dateend'] && $histo[$key][
'dateend'] != $histo[$key][
'datestart']) {
16735 $tmpa =
dol_getdate($histo[$key][
'datestart'],
true);
16736 $tmpb =
dol_getdate($histo[$key][
'dateend'],
true);
16737 if ($tmpa[
'mday'] == $tmpb[
'mday'] && $tmpa[
'mon'] == $tmpb[
'mon'] && $tmpa[
'year'] == $tmpb[
'year']) {
16738 $out .=
' - ' .
dol_print_date($histo[$key][
'dateend'],
'hour',
'tzuserrel',
null,
false, 1);
16740 $out .=
' - ' .
dol_print_date($histo[$key][
'dateend'],
'day',
'tzuserrel');
16742 $out .=
' '.dol_print_date($histo[$key][
'dateend'],
'hour',
'tzuserrel',
null,
false,
'opacitymedium');
16747 if ($histo[$key][
'percent'] == 0 && $histo[$key][
'datestart'] && $histo[$key][
'datestart'] < ($now - $delay_warning)) {
16750 if ($histo[$key][
'percent'] == 0 && !$histo[$key][
'datestart'] && $histo[$key][
'dateend'] && $histo[$key][
'datestart'] < ($now - $delay_warning)) {
16753 if ($histo[$key][
'percent'] > 0 && $histo[$key][
'percent'] < 100 && $histo[$key][
'dateend'] && $histo[$key][
'dateend'] < ($now - $delay_warning)) {
16756 if ($histo[$key][
'percent'] > 0 && $histo[$key][
'percent'] < 100 && !$histo[$key][
'dateend'] && $histo[$key][
'datestart'] && $histo[$key][
'datestart'] < ($now - $delay_warning)) {
16760 $out .=
img_warning($langs->trans(
"Late")) .
' ';
16762 $out .=
"</span></span>\n";
16764 $out .=
'<span class="time">';
16765 $out .= $actionstatic->getLibStatut(2);
16769 $out .=
'<h3 class="timeline-header">';
16772 $out .=
'<div class="messaging-author inline-block tdoverflowmax150 valignmiddle marginrightonly">';
16773 if ($histo[$key][
'userid'] > 0) {
16774 if (!isset($userGetNomUrlCache[$histo[$key][
'userid']])) {
16775 $userstatic->fetch($histo[$key][
'userid']);
16776 $userGetNomUrlCache[$histo[$key][
'userid']] = $userstatic->getNomUrl(-1,
'', 0, 0, 16, 0,
'firstelselast',
'');
16778 $out .= $userGetNomUrlCache[$histo[$key][
'userid']];
16779 } elseif (!empty($histo[$key][
'msg_from']) && $actionstatic->code ==
'TICKET_MSG') {
16780 if (!isset($contactGetNomUrlCache[$histo[$key][
'msg_from']])) {
16781 if ($contactstatic->fetch(0,
null,
'', $histo[$key][
'msg_from']) > 0) {
16782 $contactGetNomUrlCache[$histo[$key][
'msg_from']] = $contactstatic->getNomUrl(-1,
'', 16);
16784 $contactGetNomUrlCache[$histo[$key][
'msg_from']] = $histo[$key][
'msg_from'];
16787 $out .= $contactGetNomUrlCache[$histo[$key][
'msg_from']];
16789 $out .=
'<img class="photomemberphoto userphoto" alt="" src="/public/theme/common/user_anonymous.png">'.$langs->trans(
"Anonymous");
16794 $out .=
' <div class="messaging-title inline-block">';
16796 if (empty($conf->dol_optimize_smallscreen) && $actionstatic->type_code !=
'AC_OTH_AUTO') {
16797 $out .= $labeltype .
' - ';
16802 if (!empty($actionstatic->code) && preg_match(
'/^TICKET_MSG_PRIVATE/', $actionstatic->code)) {
16803 $out .= $langs->trans(
'TicketNewMessage').
' <em>('.$langs->trans(
'Private').
')</em>';
16804 } elseif (!empty($actionstatic->code) && preg_match(
'/^TICKET_MSG/', $actionstatic->code)) {
16805 $out .= $langs->trans(
'TicketNewMessage');
16806 } elseif (isset($histo[$key][
'type'])) {
16807 if ($histo[$key][
'type'] ==
'action') {
16808 $transcode = $langs->transnoentitiesnoconv(
"Action" . $histo[$key][
'acode']);
16809 $libelle = ($transcode !=
"Action" . $histo[$key][
'acode'] ? $transcode : $histo[$key][
'alabel']);
16810 $libelle = $histo[$key][
'note'];
16811 $actionstatic->id = $histo[$key][
'id'];
16812 if ($libelle != $labeltype) {
16815 } elseif ($histo[$key][
'type'] ==
'mailing') {
16816 $out .=
'<a href="' . DOL_URL_ROOT .
'/comm/mailing/card.php?id=' . $histo[$key][
'id'] .
'">' .
img_object($langs->trans(
"ShowEMailing"),
"email") .
' ';
16817 $transcode = $langs->transnoentitiesnoconv(
"Action" . $histo[$key][
'acode']);
16818 $libelle = ($transcode !=
"Action" . $histo[$key][
'acode'] ? $transcode :
'Send mass mailing');
16821 $libelle .= $histo[$key][
'note'];
16825 $out = preg_replace(
'/ - $/',
'', $out);
16827 if (isset($histo[$key][
'elementtype']) && !empty($histo[$key][
'fk_element'])) {
16828 if (isset($conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']]) && isset($conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']][$histo[$key][
'fk_element']])) {
16829 $link = $conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']][$histo[$key][
'fk_element']];
16831 if (!isset($conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']])) {
16832 $conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']] = array();
16834 $link =
dolGetElementUrl($histo[$key][
'fk_element'], $histo[$key][
'elementtype'], 1);
16835 $conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']][$histo[$key][
'fk_element']] = $link;
16838 $out .=
' - ' . $link;
16848 !empty($histo[$key][
'message'] && $histo[$key][
'message'] != $libelle)
16849 && $actionstatic->code !=
'AC_TICKET_CREATE'
16850 && $actionstatic->code !=
'AC_TICKET_MODIFY'
16852 $out .=
'<div class="timeline-body wordbreak small">';
16853 $truncateLines =
getDolGlobalInt(
'MAIN_TRUNCATE_TIMELINE_MESSAGE', 3);
16860 if ($truncateLines > 0 && strlen($newmess) > strlen($truncatedText)) {
16861 $out .=
'<div class="readmore-block --closed" >';
16862 $out .=
' <div class="readmore-block__excerpt">';
16864 $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>';
16866 $out .=
' <div class="readmore-block__full-text" >';
16868 $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>';
16882 if (isset($histo[$key][
'socpeopleassigned']) && is_array($histo[$key][
'socpeopleassigned']) && count($histo[$key][
'socpeopleassigned']) > 0) {
16884 foreach ($histo[$key][
'socpeopleassigned'] as $cid => $Tab) {
16885 if (empty($conf->cache[
'contact'][$cid])) {
16887 $contact->fetch($cid);
16888 $conf->cache[
'contact'][$cid] = $contact;
16890 $contact = $conf->cache[
'contact'][$cid];
16894 $contactList .= !empty($contactList) ?
', ' :
'';
16895 $contactList .= $contact->getNomUrl(1);
16896 if (isset($histo[$key][
'acode']) && $histo[$key][
'acode'] ==
'AC_TEL') {
16897 if (!empty($contact->phone_pro)) {
16904 $footer .= $langs->trans(
'ActionOnContact') .
' : ' . $contactList;
16905 } elseif (empty($objcon->id) && isset($histo[$key][
'contact_id']) && $histo[$key][
'contact_id'] > 0) {
16906 if (empty($conf->cache[
'contact'][$histo[$key][
'contact_id']])) {
16908 $result = $contact->fetch($histo[$key][
'contact_id']);
16909 $conf->cache[
'contact'][$histo[$key][
'contact_id']] = $contact;
16911 $contact = $conf->cache[
'contact'][$histo[$key][
'contact_id']];
16912 $result = ($contact instanceof
Contact) ? $contact->id : 0;
16916 $footer .= $contact->getNomUrl(1);
16917 if (isset($histo[$key][
'acode']) && $histo[$key][
'acode'] ==
'AC_TEL') {
16918 if (!empty($contact->phone_pro)) {
16926 if (!empty($documents)) {
16927 $footer .=
'<div class="timeline-documents-container">';
16928 foreach ($documents as $doc) {
16929 $footer .=
'<span id="document_' . $doc->id .
'" class="timeline-documents" ';
16930 $footer .=
' data-id="' . $doc->id .
'" ';
16931 $footer .=
' data-path="' . $doc->filepath .
'"';
16935 $filePath = DOL_DATA_ROOT .
'/' . $doc->filepath .
'/' . $doc->filename;
16937 if (empty($doc->agenda_id)) {
16938 $dir_ref = $actionstatic->id;
16939 $modulepart =
'actions';
16941 $split_dir = explode(
'/', $doc->filepath);
16942 $modulepart = array_shift($split_dir);
16943 $dir_ref = implode(
'/', $split_dir);
16946 $file = $dir_ref .
'/' . $doc->filename;
16947 $thumb = $dir_ref .
'/thumbs/' . substr($doc->filename, 0, strrpos($doc->filename,
'.')) .
'_mini' . substr($doc->filename, strrpos($doc->filename,
'.'));
16948 $doclink =
dol_buildpath(
'document.php', 1) .
'?modulepart=' . $modulepart .
'&attachment=0&file=' . urlencode($file) .
'&entity=' . $conf->entity;
16949 $viewlink =
dol_buildpath(
'viewimage.php', 1) .
'?modulepart=' . $modulepart .
'&file=' . urlencode($thumb) .
'&entity=' . $conf->entity;
16953 $mimeAttr =
' mime="' . $mime .
'" ';
16955 if (in_array($mime, array(
'image/png',
'image/jpeg',
'application/pdf'))) {
16956 $class .=
' documentpreview';
16959 $footer .=
'<a href="' . $doclink .
'" class="btn-link ' . $class .
'" target="_blank" rel="noopener noreferrer" ' . $mimeAttr .
' >';
16960 $footer .=
img_mime($filePath) .
' ' . $doc->filename;
16963 $footer .=
'</span>';
16965 $footer .=
'</div>';
16968 if (!empty($footer)) {
16969 $out .=
'<div class="timeline-footer">' . $footer .
'</div>';
16972 $out .=
'</div>' .
"\n";
16975 $out .=
'<!-- END timeline item -->';
16982 jQuery(document).ready(function () {
16983 $(document).on("click", "[data-read-more-action]", function(e){
16984 console.log("We click on data-read-more-action");
16985 let readMoreBloc = $(this).closest(".readmore-block");
16986 if(readMoreBloc.length > 0){
16987 e.preventDefault();
16988 if($(this).attr("data-read-more-action") == "close"){
16989 readMoreBloc.addClass("--closed").removeClass("--open");
16990 $("html, body").animate({
16991 scrollTop: readMoreBloc.offset().top - 200
16994 readMoreBloc.addClass("--open").removeClass("--closed");
17002 if (empty($histo)) {
17003 $out .=
'<span class="opacitymedium">' . $langs->trans(
"NoRecordFound") .
'</span>';
17006 if ($num > $MAXWITHOUTPAGINATION) {
17007 $langs->load(
"errors");
17009 $out .=
'<center><span class="opacitymedium">...' . $langs->trans(
"WarningTooManyDataPleaseUseMoreFilters", $MAXWITHOUTPAGINATION) .
'...</span></center>';
17032function buildParamDate($prefix, $timestamp =
null, $hourTime =
'', $gm =
'auto')
17034 if ($timestamp ===
null) {
17035 $timestamp =
GETPOSTDATE($prefix, $hourTime, $gm);
17042 if ($hourTime ===
'getpost' || ($timestamp !==
null &&
dol_print_date($timestamp,
'%H:%M:%S') !==
'00:00:00')) {
17043 $TParam = array_merge($TParam, array(
17050 return '&' . http_build_query($TParam);
17071function recordNotFound($message =
'', $printheader = 1, $printfooter = 1, $showonlymessage = 0, $params =
null)
17073 global $conf, $db, $langs, $hookmanager;
17076 if (!is_object($langs)) {
17077 include_once DOL_DOCUMENT_ROOT .
'/core/class/translate.class.php';
17079 $langs->setDefaultLang();
17082 $langs->load(
"errors");
17084 if ($printheader) {
17085 if (function_exists(
"llxHeader")) {
17087 } elseif (function_exists(
"llxHeaderVierge")) {
17092 print
'<div class="error">';
17093 if (empty($message)) {
17094 print $langs->trans(
"ErrorRecordNotFound");
17096 print $langs->trans($message);
17101 if (empty($showonlymessage)) {
17102 if (empty($hookmanager)) {
17103 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
17106 $hookmanager->initHooks(array(
'main'));
17109 $parameters = array(
'message' => $message,
'params' => $params);
17110 $reshook = $hookmanager->executeHooks(
'getErrorRecordNotFound', $parameters,
$object, $action);
17111 print $hookmanager->resPrint;
17114 if ($printfooter && function_exists(
"llxFooter")) {
17116 if (is_object($db)) {
17155 foreach ($array2 as $key => $value) {
17156 if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
17159 $merged[$key] = $value;
17174 if (!empty($obj->socid)) {
17175 return (
int) $obj->socid;
17176 } elseif (!empty($obj->soc_id)) {
17177 return (
int) $obj->soc_id;
17178 } elseif (!empty($obj->societe_id)) {
17179 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...
dol_print_email($email, $contactid=0, $socid=0, $addlink=0, $max=0, $showinvalid=2, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
get_default_localtax($thirdparty_seller, $thirdparty_buyer, $local, $idprod=0)
Function that return localtax of a product line (according to seller, buyer and product vat rate) If ...
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_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).
dolCloseUnclosedHtmlTags($text)
Close the HTML tags left open in a truncated HTML string.
get_product_localtax_for_country($idprod, $local, $thirdpartytouseforcountry)
Return localtax vat rate of a product in a particular country or default country vat if product is un...
getUserRemoteIP($trusted=0)
Return the real IP of remote user.
buildParamDate($prefix, $timestamp=null, $hourTime='', $gm='auto')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
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.