56if (!function_exists(
'utf8_encode')) {
64 function utf8_encode($elements)
66 return mb_convert_encoding($elements,
'UTF-8',
'ISO-8859-1');
70if (!function_exists(
'utf8_decode')) {
78 function utf8_decode($elements)
80 return mb_convert_encoding($elements,
'ISO-8859-1',
'UTF-8');
83if (!function_exists(
'str_starts_with')) {
92 function str_starts_with($haystack, $needle)
94 return (
string) $needle !==
'' && strncmp($haystack, $needle, strlen($needle)) === 0;
97if (!function_exists(
'str_ends_with')) {
106 function str_ends_with($haystack, $needle)
108 return $needle !==
'' && substr($haystack, -strlen($needle)) === (
string) $needle;
111if (!function_exists(
'str_contains')) {
120 function str_contains($haystack, $needle)
122 return $needle !==
'' && mb_strpos($haystack, $needle) !==
false;
137 return json_encode($data);
140 return var_export($data,
true);
160 if (!is_object(
$object) && empty($module)) {
163 if (empty($module) && !empty(
$object->element)) {
170 $module =
'ficheinter';
172 case 'invoice_supplier':
173 $module =
'supplier_invoice';
175 case 'order_supplier':
176 $module =
'supplier_order';
178 case 'recruitmentjobposition':
179 $module =
'recruitment';
180 $subdirectory =
'/recruitmentjobposition';
182 case 'recruitmentcandidature':
183 $module =
'recruitment';
184 $subdirectory =
'/recruitmentcandidature';
186 case 'knowledgerecord':
187 $module =
'knowledgemanagement';
188 $subdirectory =
'/knowledgerecord';
190 case 'commande_fournisseur':
191 $module =
'fournisseur';
192 $subdirectory =
'/commande';
195 $subdirectory =
'/sending';
214 if ($mode ==
'output' || $mode ==
'outputrel' || $mode ==
'version') {
215 if (isset(
$conf->$module) && property_exists(
$conf->$module,
'multidir_output')) {
217 if ($mode !=
'outputrel') {
220 if ($forobject &&
$object->id > 0) {
224 } elseif (isset(
$conf->$module) && property_exists(
$conf->$module,
'dir_output')) {
226 if ($mode !=
'outputrel') {
227 $s =
$conf->$module->dir_output . $subdirectory;
229 if ($forobject &&
$object->id > 0) {
234 return 'error-diroutput-not-defined-for-this-object=' . $module;
236 } elseif ($mode ==
'temp') {
237 if (isset(
$conf->$module) && property_exists(
$conf->$module,
'multidir_temp')) {
239 } elseif (isset(
$conf->$module) && property_exists(
$conf->$module,
'dir_temp')) {
240 return $conf->$module->dir_temp;
242 return 'error-dirtemp-not-defined-for-this-object=' . $module;
245 return 'error-bad-value-for-mode';
289 return (
string) (isset(
$conf->global->$key) ?
$conf->global->$key : $default);
299 global $dolibarr_login_badcharunauthorized;
301 if (isset($dolibarr_login_badcharunauthorized)) {
302 if ($dolibarr_login_badcharunauthorized ===
'MAIN_LOGIN_BADCHARUNAUTHORIZED') {
306 return (
string) $dolibarr_login_badcharunauthorized;
324 return (
int) (isset(
$conf->global->$key) ?
$conf->global->$key : $default);
339 return (
float) (isset(
$conf->global->$key) ?
$conf->global->$key : $default);
353 return (
bool) (
$conf->global->$key ?? $default);
364 return (
string)
$conf->currency;
375 return (
string)
$conf->dol_optimize_smallscreen;
386 return (
int)
$conf->entity;
397 return $conf->db->type;
408 return str_replace(
'_',
'', basename(dirname($s)).basename($s,
'.php'));
422 if (empty($tmpuser)) {
427 return (
string) (isset($tmpuser->conf->$key) ? $tmpuser->conf->$key : $default);
440 if (empty($tmpuser)) {
445 return (
int) (isset($tmpuser->conf->$key) ? $tmpuser->conf->$key : $default);
462 'adherent' =>
'member',
463 'member_type' =>
'adherent_type',
465 'contrat' =>
'contract',
466 'entrepot' =>
'stock',
467 'projet' =>
'project',
468 'categorie' =>
'category',
469 'commande' =>
'order',
470 'expedition' =>
'shipping',
471 'facture' =>
'invoice',
472 'fichinter' =>
'intervention',
473 'ficheinter' =>
'intervention',
474 'propale' =>
'propal',
475 'societe' =>
'thirdparty',
476 'socpeople' =>
'contact',
477 'fournisseur' =>
'supplier',
479 'actioncomm' =>
'agenda',
480 'product_price' =>
'productprice',
481 'product_fournisseur_price' =>
'productsupplierprice',
501 $arrayconv[
'supplier_order'] =
'fournisseur';
502 $arrayconv[
'supplier_invoice'] =
'fournisseur';
505 $module_alt = $module;
506 if (!empty($arrayconv[$module])) {
507 $module_alt = $arrayconv[$module];
509 $module_bis = $module;
510 if (!empty($arrayconvbis[$module])) {
511 $module_bis = $arrayconvbis[$module];
514 return !empty(
$conf->modules[$module]) || !empty(
$conf->modules[$module_alt]) || !empty(
$conf->modules[$module_bis]);
532 $moduletomoduletouse = array(
533 'invoice' =>
'facture',
535 $moduleParmsMapping = array(
536 'product' =>
'produit',
539 if (!empty($moduletomoduletouse[$module])) {
540 $module = $moduletomoduletouse[$module];
543 $warningDelayPath = $parmlevel1;
544 if (!empty($moduleParmsMapping[$warningDelayPath])) {
545 $warningDelayPath = $moduleParmsMapping[$warningDelayPath];
549 if (!empty(
$conf->$module) && !empty(
$conf->$module->$warningDelayPath) && !empty(
$conf->$module->$warningDelayPath->$parmlevel2) && !empty(
$conf->$module->$warningDelayPath->$parmlevel2->warning_delay)) {
550 return (
int)
$conf->$module->$warningDelayPath->$parmlevel2->warning_delay;
553 if (!empty(
$conf->$module) && !empty(
$conf->$module->$warningDelayPath) && !empty(
$conf->$module->$warningDelayPath->warning_delay)) {
554 return (
int)
$conf->$module->$warningDelayPath->warning_delay;
569 if ($timestamp ===
'') {
570 dol_syslog(
'Using empty string for a timestamp is deprecated, prefer use of null when calling page ' . $_SERVER[
"PHP_SELF"] .
getCallerInfoString(), LOG_NOTICE);
573 if (is_null($timestamp) || !is_numeric($timestamp)) {
593 require_once DOL_DOCUMENT_ROOT .
"/core/db/" . $type .
'.class.php';
595 $class =
'DoliDB' . ucfirst($type);
596 $db =
new $class($type, $host, $user, $pass, $name, $port);
617function getEntity($element, $shared = 1, $currentobject =
null)
621 if (!is_object($hookmanager)) {
622 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
629 $element =
'project';
632 $element =
'contract';
634 case 'order_supplier':
635 $element =
'supplier_order';
637 case 'invoice_supplier':
638 $element =
'supplier_invoice';
642 if (is_object($mc)) {
643 $out = $mc->getEntity($element, $shared, $currentobject);
646 $addzero = array(
'user',
'usergroup',
'cronjob',
'c_email_templates',
'email_template',
'default_values',
'overwrite_trans');
648 $addzero[] =
'c_holiday_types';
650 if (in_array($element, $addzero)) {
653 $out .= ((int)
$conf->entity);
658 'element' => $element,
661 'currentobject' => $currentobject,
665 $reshook = $hookmanager->executeHooks(
'hookGetEntity', $parameters, $currentobject, $action);
667 if (is_numeric($reshook)) {
668 if ($reshook == 0 && !empty($hookmanager->resPrint)) {
669 $out .=
',' . $hookmanager->resPrint;
670 } elseif ($reshook == 1) {
671 $out = $hookmanager->resPrint;
688 if (is_object($mc) && method_exists($mc,
'setEntity')) {
689 return $mc->setEntity($currentobject);
691 return ((is_object($currentobject) && $currentobject->id > 0 && ((
int) $currentobject->entity) > 0) ? (
int) $currentobject->entity :
$conf->entity);
703 return preg_match(
'/(_pass|password|_pw|_key|securekey|serverkey|secret\d?|p12key|exportkey|_PW_[a-z]+|token)$/i', $keyname);
716 for ($r =
""; $n >= 0; $n = intval($n / 26) - 1) {
717 $r = chr($n % 26 + 0x41) . $r;
741 include_once DOL_DOCUMENT_ROOT .
'/includes/mobiledetect/mobiledetectlib/Mobile_Detect.php';
748 $user_agent = substr($user_agent, 0, 512);
751 $detectmobile =
new Mobile_Detect(
null, $user_agent);
752 $tablet = $detectmobile->isTablet();
754 if ($detectmobile->isMobile()) {
758 if ($detectmobile->is(
'AndroidOS')) {
759 $os = $phone =
'android';
760 } elseif ($detectmobile->is(
'BlackBerryOS')) {
761 $os = $phone =
'blackberry';
762 } elseif ($detectmobile->is(
'iOS')) {
765 } elseif ($detectmobile->is(
'PalmOS')) {
766 $os = $phone =
'palm';
767 } elseif ($detectmobile->is(
'SymbianOS')) {
769 } elseif ($detectmobile->is(
'webOS')) {
771 } elseif ($detectmobile->is(
'MaemoOS')) {
773 } elseif ($detectmobile->is(
'WindowsMobileOS') || $detectmobile->is(
'WindowsPhoneOS')) {
779 if (preg_match(
'/linux/i', $user_agent)) {
781 } elseif (preg_match(
'/macintosh/i', $user_agent)) {
783 } elseif (preg_match(
'/windows/i', $user_agent)) {
789 if (preg_match(
'/firefox(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
791 $version = empty($reg[2]) ?
'' : $reg[2];
792 } elseif (preg_match(
'/edge(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
794 $version = empty($reg[2]) ?
'' : $reg[2];
795 } elseif (preg_match(
'/chrome(\/|\s)([\d\.]+)/i', $user_agent, $reg)) {
797 $version = empty($reg[2]) ?
'' : $reg[2];
798 } elseif (preg_match(
'/chrome/i', $user_agent, $reg)) {
801 } elseif (preg_match(
'/iceweasel/i', $user_agent)) {
803 } elseif (preg_match(
'/epiphany/i', $user_agent)) {
805 } elseif (preg_match(
'/safari(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
807 $version = empty($reg[2]) ?
'' : $reg[2];
808 } elseif (preg_match(
'/opera(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
811 $version = empty($reg[2]) ?
'' : $reg[2];
812 } elseif (preg_match(
'/(MSIE\s([0-9]+\.[0-9]))|.*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) {
814 $version = end($reg);
815 } elseif (preg_match(
'/(Windows NT\s([0-9]+\.[0-9])).*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) {
818 $version = end($reg);
819 } elseif (preg_match(
'/l[iy]n(x|ks)(\(|\/|\s)*([\d\.]+)/i', $user_agent, $reg)) {
821 $name =
'textbrowser';
822 $version = empty($reg[3]) ?
'' : $reg[3];
823 } elseif (preg_match(
'/w3m\/([\d\.]+)/i', $user_agent, $reg)) {
825 $name =
'textbrowser';
826 $version = empty($reg[1]) ?
'' : $reg[1];
838 'browsername' => $name,
839 'browserversion' => $version,
841 'browserua' => $user_agent,
856 $disconnectdone =
false;
858 if (is_object(
$db) && !empty(
$db->connected)) {
859 $depth =
$db->transaction_opened;
860 $disconnectdone =
$db->close();
862 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));
874function GETPOSTISSET($paramname)
878 $relativepathstring = $_SERVER[
"PHP_SELF"];
880 if (constant(
'DOL_URL_ROOT')) {
881 $relativepathstring = preg_replace(
'/^' . preg_quote(constant(
'DOL_URL_ROOT'),
'/') .
'/',
'', $relativepathstring);
883 $relativepathstring = ltrim($relativepathstring,
'/');
884 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
888 if (!empty($_GET[
'restore_lastsearch_values'])) {
889 if (!empty($_SESSION[
'lastsearch_values_' . $relativepathstring])) {
890 $tmp = json_decode($_SESSION[
'lastsearch_values_' . $relativepathstring],
true);
891 if (is_array($tmp)) {
892 foreach ($tmp as $key => $val) {
893 if ($key == $paramname) {
901 if ($paramname ==
'contextpage' && !empty($_SESSION[
'lastsearch_contextpage_' . $relativepathstring])) {
903 } elseif ($paramname ==
'limit' && !empty($_SESSION[
'lastsearch_limit_' . $relativepathstring])) {
905 } elseif ($paramname ==
'page' && !empty($_SESSION[
'lastsearch_page_' . $relativepathstring])) {
907 } elseif ($paramname ==
'mode' && !empty($_SESSION[
'lastsearch_mode_' . $relativepathstring])) {
911 $isset = (isset($_POST[$paramname]) || isset($_GET[$paramname]));
928 if (empty($method)) {
929 $val = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] :
'');
930 } elseif ($method == 1) {
931 $val = isset($_GET[$paramname]) ? $_GET[$paramname] :
'';
932 } elseif ($method == 2) {
933 $val = isset($_POST[$paramname]) ? $_POST[$paramname] :
'';
934 } elseif ($method == 3) {
935 $val = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] :
'');
937 $val =
'BadFirstParameterForGETPOST';
940 return is_array($val);
955 return (
int)
GETPOST($paramname,
'int', $method,
null,
null, 0);
971function GETPOSTFLOAT($paramname, $rounding =
'', $option = 2)
992function GETPOSTDATE($prefix, $hourTime =
'', $gm =
'auto', $saverestore =
'')
995 if ($hourTime ===
'getpost' || $hourTime ===
'getpostend') {
996 $hour = (GETPOSTISSET($prefix .
'hour') &&
GETPOSTINT($prefix .
'hour') >= 0) ?
GETPOSTINT($prefix .
'hour') : ($hourTime ===
'getpostend' ? 23 : 0);
997 $minute = (GETPOSTISSET($prefix .
'min') &&
GETPOSTINT($prefix .
'min') >= 0) ?
GETPOSTINT($prefix .
'min') : ($hourTime ===
'getpostend' ? 59 : 0);
998 $second = (GETPOSTISSET($prefix .
'sec') &&
GETPOSTINT($prefix .
'sec') >= 0) ?
GETPOSTINT($prefix .
'sec') : ($hourTime ===
'getpostend' ? 59 : 0);
999 } elseif (preg_match(
'/^(\d\d):(\d\d):(\d\d)$/', $hourTime, $m)) {
1000 $hour = intval($m[1]);
1001 $minute = intval($m[2]);
1002 $second = intval($m[3]);
1003 } elseif ($hourTime ===
'end') {
1008 $hour = $minute = $second = 0;
1013 && !GETPOSTISSET($prefix .
'day')
1014 && !GETPOSTISSET($prefix .
'month')
1015 && !GETPOSTISSET($prefix .
'year')
1016 && isset($_SESSION[
'DOLDATE_' . $saverestore .
'_day'])
1017 && isset($_SESSION[
'DOLDATE_' . $saverestore .
'_month'])
1018 && isset($_SESSION[
'DOLDATE_' . $saverestore .
'_year'])
1020 $day = $_SESSION[
'DOLDATE_' . $saverestore .
'_day'];
1021 $month = $_SESSION[
'DOLDATE_' . $saverestore .
'_month'];
1022 $year = $_SESSION[
'DOLDATE_' . $saverestore .
'_year'];
1030 $hour = (int) min($hour, 23);
1031 $minute = (int) min($minute, 59);
1032 $second = (int) min($second, 59);
1035 $_SESSION[
'DOLDATE_' . $saverestore .
'_day'] = $day;
1036 $_SESSION[
'DOLDATE_' . $saverestore .
'_month'] = $month;
1037 $_SESSION[
'DOLDATE_' . $saverestore .
'_year'] = $year;
1041 return dol_mktime($hour, $minute, $second, $month, $day, $year, $gm);
1084function GETPOST($paramname, $check =
'alphanohtml', $method = 0, $filter =
null, $options =
null, $noreplace = 0)
1088 if (empty($paramname)) {
1089 return 'BadFirstParameterForGETPOST';
1091 if (empty($check)) {
1092 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);
1096 if (in_array($paramname, array(
'sortfield',
'sortorder'))) {
1097 $check =
'aZ09comma';
1100 if (empty($method)) {
1101 $out = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] :
'');
1102 } elseif ($method == 1) {
1103 $out = isset($_GET[$paramname]) ? $_GET[$paramname] :
'';
1104 } elseif ($method == 2) {
1105 $out = isset($_POST[$paramname]) ? $_POST[$paramname] :
'';
1106 } elseif ($method == 3) {
1107 $out = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] :
'');
1109 return 'BadThirdParameterForGETPOST';
1112 $relativepathstring =
'';
1114 if (empty($method) || $method == 3 || $method == 4) {
1115 $relativepathstring = (empty($_SERVER[
"PHP_SELF"]) ?
'' : $_SERVER[
"PHP_SELF"]);
1117 if (constant(
'DOL_URL_ROOT')) {
1118 $relativepathstring = preg_replace(
'/^' . preg_quote(constant(
'DOL_URL_ROOT'),
'/') .
'/',
'', $relativepathstring);
1120 $relativepathstring = ltrim($relativepathstring,
'/');
1121 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
1125 if (!empty($_GET[
'restore_lastsearch_values'])) {
1126 if (!empty($_SESSION[
'lastsearch_values_' . $relativepathstring])) {
1127 $tmp = json_decode($_SESSION[
'lastsearch_values_' . $relativepathstring],
true);
1128 if (is_array($tmp)) {
1129 foreach ($tmp as $key => $val) {
1130 if ($key == $paramname) {
1138 if ($paramname ==
'contextpage' && !empty($_SESSION[
'lastsearch_contextpage_' . $relativepathstring])) {
1139 $out = $_SESSION[
'lastsearch_contextpage_' . $relativepathstring];
1140 } elseif ($paramname ==
'limit' && !empty($_SESSION[
'lastsearch_limit_' . $relativepathstring])) {
1141 $out = $_SESSION[
'lastsearch_limit_' . $relativepathstring];
1142 } elseif ($paramname ==
'page' && !empty($_SESSION[
'lastsearch_page_' . $relativepathstring])) {
1143 $out = $_SESSION[
'lastsearch_page_' . $relativepathstring];
1144 } elseif ($paramname ==
'mode' && !empty($_SESSION[
'lastsearch_mode_' . $relativepathstring])) {
1145 $out = $_SESSION[
'lastsearch_mode_' . $relativepathstring];
1147 } elseif (!isset($_GET[
'sortfield'])) {
1150 if (!empty($_GET[
'action']) && $_GET[
'action'] ==
'create' && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
1153 '@phan-var-force CommonObject $object';
1154 if (is_object(
$object) && isset(
$object->fields[$paramname][
'default'])) {
1156 $out =
$object->fields[$paramname][
'default'];
1160 if (!empty($_GET[
'action']) && (preg_match(
'/^create/', $_GET[
'action']) || preg_match(
'/^presend/', $_GET[
'action'])) && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
1162 if (!empty($user->default_values)) {
1163 if (isset($user->default_values[$relativepathstring][
'createform'])) {
1164 foreach ($user->default_values[$relativepathstring][
'createform'] as $defkey => $defval) {
1166 if ($defkey !=
'_noquery_') {
1167 $tmpqueryarraytohave = explode(
'&', $defkey);
1170 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
1171 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
1183 if (isset($user->default_values[$relativepathstring][
'createform'][$defkey][$paramname])) {
1184 $out = $user->default_values[$relativepathstring][
'createform'][$defkey][$paramname];
1191 } elseif (!empty($paramname) && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
1193 if (!empty($user->default_values)) {
1196 if ($paramname ==
'sortfield' || $paramname ==
'sortorder') {
1198 if (isset($user->default_values[$relativepathstring][
'sortorder'])) {
1200 foreach ($user->default_values[$relativepathstring][
'sortorder'] as $defkey => $defval) {
1202 if ($defkey !=
'_noquery_') {
1203 $tmpqueryarraytohave = explode(
'&', $defkey);
1206 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
1207 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
1219 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
1220 foreach ($user->default_values[$relativepathstring][
'sortorder'][$defkey] as $key => $val) {
1224 if ($paramname ==
'sortfield') {
1227 if ($paramname ==
'sortorder') {
1235 } elseif (isset($user->default_values[$relativepathstring][
'filters'])) {
1236 foreach ($user->default_values[$relativepathstring][
'filters'] as $defkey => $defval) {
1237 if (!empty($_GET[
'disabledefaultvalues'])) {
1241 if ($defkey !=
'_noquery_') {
1242 $tmpqueryarraytohave = explode(
'&', $defkey);
1245 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
1246 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
1257 if ($qualified && isset($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname])) {
1259 if (isset($_POST[
'search_all']) || isset($_GET[
'search_all'])) {
1262 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
1263 $out =
dol_string_nospecial($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname],
'', $forbidden_chars_to_replace);
1266 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
1267 $out =
dol_string_nospecial($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname],
'', $forbidden_chars_to_replace);
1282 '@phan-var-force string $paramname';
1283 if (!is_array($out) && empty($_POST[$paramname]) && empty($noreplace)) {
1284 if (preg_match(
'/__([A-Z0-9]+(?:_[A-Z0-9]+){0,3})__/i', $out)) {
1285 $substitutionarray = getCommonSubstitutionArray($langs, 0,
null, $user, array(
'mycompany',
'date',
'system',
'user'));
1293 if (preg_match(
'/^array/', $check)) {
1294 $tmpcheck =
'alphanohtml';
1295 if ($out ===
null || $out ===
'') {
1297 } elseif (!is_array($out)) {
1298 $out = explode(
',', $out);
1300 $tmparray = explode(
':', $check);
1301 if (!empty($tmparray[1])) {
1302 $tmpcheck = $tmparray[1];
1305 foreach ($out as $outkey => $outval) {
1306 $out[$outkey] =
sanitizeVal($outval, $tmpcheck, $filter, $options);
1311 if (strpos($paramname,
'search_') === 0) {
1312 $out = preg_replace(
'/([<>])([-+]?\d)/',
'\1 \2', $out);
1316 $out =
sanitizeVal($out, $check, $filter, $options);
1323 if (preg_match(
'/^backto/i', $paramname)) {
1324 $out = str_replace(
'\\',
'/', $out);
1325 $out = str_replace(array(
':',
';',
'@',
"\t",
' '),
'', $out);
1327 $oldstringtoclean = $out;
1328 $out = str_ireplace(array(
'javascript',
'vbscript',
'&colon',
'&#'),
'', $out);
1329 $out = preg_replace(array(
'/^[^\?]*%/'),
'', $out);
1330 $out = preg_replace(array(
'/^[a-z]*\/\s*\/+/i'),
'', $out);
1331 }
while ($oldstringtoclean != $out);
1336 if (empty($method) || $method == 3 || $method == 4) {
1337 if (preg_match(
'/^search_/', $paramname) || in_array($paramname, array(
'sortorder',
'sortfield'))) {
1344 if ($out !=
'' && isset($user)) {
1345 $user->lastsearch_values_tmp[$relativepathstring][$paramname] = $out;
1362function sanitizeVal($out =
'', $check =
'alphanohtml', $filter =
null, $options =
null)
1366 if ($out ===
null) {
1374 if (!is_numeric($out)) {
1379 if (is_array($out)) {
1380 $out = implode(
',', $out);
1382 if (preg_match(
'/[^0-9,-]+/i', $out)) {
1387 dol_syslog(
"Use of parameter value 'san_alpha' in GETPOST is deprecated. Use 'alphanohtml', 'aZ09comma', ...", LOG_WARNING);
1388 $out = filter_var($out, FILTER_SANITIZE_STRING);
1391 $out = filter_var($out, FILTER_SANITIZE_EMAIL);
1395 $out = preg_replace(
'/[^:\/\[\]a-z0-9@\$\'\*\~\.\-_,;\?\!=%&+#]+/i',
'', $out);
1399 if (!is_array($out)) {
1401 if (preg_match(
'/[^a-z]+/i', $out)) {
1407 if (!is_array($out)) {
1409 if (preg_match(
'/[^a-z0-9_\-\.]+/i', $out)) {
1415 if (!is_array($out)) {
1417 if (preg_match(
'/[^a-z0-9_\-\.@]+/i', $out)) {
1423 if (!is_array($out)) {
1425 if (preg_match(
'/[^a-z0-9_\-\.,]+/i', $out)) {
1432 if (!is_array($out)) {
1435 $oldstringtoclean = $out;
1439 $out = preg_replace(
'/\\\([0-9xu])/',
'/\1', $out);
1446 $out = str_ireplace(array(
'../',
'..\\',
'&',
'&',
'&',
'"',
'"',
'"',
'"',
'"',
'/',
'/',
'/',
'\',
'\',
'\'),
'', $out);
1447 }
while ($oldstringtoclean != $out);
1451 case 'alphawithlgt':
1452 if (!is_array($out)) {
1455 $oldstringtoclean = $out;
1459 $out = preg_replace(
'/\\\([0-9xu])/',
'/\1', $out);
1466 $out = str_ireplace(array(
'../',
'..\\',
'&',
'&',
'&',
'"',
'"',
'"',
'"',
'"',
'/',
'/',
'/',
'\',
'\',
'\'),
'', $out);
1467 }
while ($oldstringtoclean != $out);
1473 case 'restricthtmlnolink':
1474 case 'restricthtml':
1475 case 'restricthtmlallowclass':
1476 case 'restricthtmlallowiframe':
1477 case 'restricthtmlallowlinkscript':
1478 case 'restricthtmlallowunvalid':
1483 if (empty($filter)) {
1484 return 'BadParameterForGETPOST - Param 3 of sanitizeVal()';
1486 if (is_null($options)) {
1489 $out = filter_var($out, $filter, $options);
1493 dol_syslog(
"Error, you call sanitizeVal() with a bad value for the check type. Data will be sanitized with alphanohtml.", LOG_ERR);
1494 $out =
GETPOST($out,
'alphanohtml');
1509function dolSetCookie(
string $cookiename,
string $cookievalue,
int $expire = -1)
1511 include_once DOL_DOCUMENT_ROOT.
'/blockedlog/lib/securitycore.lib.php';
1513 global $dolibarr_main_force_https;
1515 if ($expire == -1) {
1516 $expire = (time() + (86400 * 354));
1519 if (PHP_VERSION_ID < 70300) {
1520 setcookie($cookiename, empty($cookievalue) ?
'' : $cookievalue, empty($cookievalue) ? 0 : $expire,
'/',
'', !(empty($dolibarr_main_force_https) &&
isHTTPS() === false), true);
1523 $cookieparams = array(
1524 'expires' => empty($cookievalue) ? 0 : $expire,
1527 'secure' => !(empty($dolibarr_main_force_https) &&
isHTTPS() === false),
1531 setcookie($cookiename, empty($cookievalue) ?
'' : $cookievalue, $cookieparams);
1533 if (empty($cookievalue)) {
1534 unset($_COOKIE[$cookiename]);
1538if (!function_exists(
'dol_getprefix')) {
1549 function dol_getprefix($mode =
'')
1552 if ($mode ==
'email') {
1558 } elseif (isset($_SERVER[
"SERVER_NAME"])) {
1559 return $_SERVER[
"SERVER_NAME"];
1564 if (!empty(
$conf->file->instance_unique_id)) {
1565 return sha1(
'dolibarr' .
$conf->file->instance_unique_id);
1569 return sha1(DOL_DOCUMENT_ROOT . DOL_URL_ROOT);
1573 global $dolibarr_main_instance_unique_id, $dolibarr_main_cookie_cryptkey;
1574 $tmp_instance_unique_id = empty($dolibarr_main_instance_unique_id) ? (empty($dolibarr_main_cookie_cryptkey) ?
'' : $dolibarr_main_cookie_cryptkey) : $dolibarr_main_instance_unique_id;
1577 if (!empty($tmp_instance_unique_id)) {
1578 return sha1(
'dolibarr' . $tmp_instance_unique_id);
1582 if (isset($_SERVER[
"SERVER_NAME"]) && isset($_SERVER[
"DOCUMENT_ROOT"])) {
1583 return sha1($_SERVER[
"SERVER_NAME"] . $_SERVER[
"DOCUMENT_ROOT"] . DOL_DOCUMENT_ROOT . DOL_URL_ROOT);
1585 return sha1(DOL_DOCUMENT_ROOT . DOL_URL_ROOT);
1604 if (strpos($relpath,
'..') !==
false) {
1606 dol_syslog(
'functions::dol_include_once Tried to load a file with a path including a forbidden sequence ".." : ' . $relpath, LOG_WARNING);
1609 if (!preg_match(
'/\.php$/', $relpath)) {
1611 dol_syslog(
'functions::dol_include_once Tried to load a file that is not a PHP file : ' . $relpath, LOG_WARNING);
1617 if (!file_exists($fullpath)) {
1618 dol_syslog(
'functions::dol_include_once Tried to load unexisting file: ' . $relpath, LOG_WARNING);
1621 if (!empty($classname) && !class_exists($classname)) {
1622 return include $fullpath;
1624 return include_once $fullpath;
1642function dol_buildpath($path, $type = 0, $returnemptyifnotfound = 0)
1646 $path = preg_replace(
'/^\//',
'', $path);
1649 $res = DOL_DOCUMENT_ROOT .
'/' . $path;
1650 if (is_array(
$conf->file->dol_document_root)) {
1651 foreach (
$conf->file->dol_document_root as $key => $dirroot) {
1652 if ($key ==
'main') {
1656 if (@file_exists($dirroot .
'/' . $path)) {
1657 if ($key !=
'main' && preg_match(
'/^core\//', $path)) {
1660 $res = $dirroot .
'/' . $path;
1665 if ($returnemptyifnotfound) {
1667 if ($returnemptyifnotfound == 1 || !file_exists($res)) {
1679 $res = DOL_URL_ROOT .
'/' . $path;
1682 $res = DOL_MAIN_URL_ROOT .
'/' . $path;
1685 $res = DOL_URL_ROOT .
'/' . $path;
1688 foreach (
$conf->file->dol_document_root as $key => $dirroot) {
1689 if ($key ==
'main') {
1694 $urlwithouturlroot = preg_replace(
'/' . preg_quote(DOL_URL_ROOT,
'/') .
'$/i',
'', trim(
$conf->file->dol_main_url_root));
1695 $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT;
1698 $res = (preg_match(
'/^http/i',
$conf->file->dol_url_root[$key]) ?
'' : $urlwithroot) .
'/' . $path;
1703 preg_match(
'/^([^\?]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i', $path, $regs);
1704 if (!empty($regs[1])) {
1707 if (@file_exists($dirroot .
'/' . $regs[1])) {
1709 $res = (preg_match(
'/^http/i',
$conf->file->dol_url_root[$key]) ?
'' : DOL_URL_ROOT) .
$conf->file->dol_url_root[$key] .
'/' . $path;
1710 } elseif ($type == 2) {
1711 $res = (preg_match(
'/^http/i',
$conf->file->dol_url_root[$key]) ?
'' : DOL_MAIN_URL_ROOT) .
$conf->file->dol_url_root[$key] .
'/' . $path;
1712 } elseif ($type == 3) {
1716 $urlwithouturlroot = preg_replace(
'/' . preg_quote(DOL_URL_ROOT,
'/') .
'$/i',
'', trim(
$conf->file->dol_main_url_root));
1717 $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT;
1720 $res = (preg_match(
'/^http/i',
$conf->file->dol_url_root[$key]) ?
'' : $urlwithroot) .
$conf->file->dol_url_root[$key] .
'/' . $path;
1740function dolBuildUrl($url, $params = [], $addtoken =
false, $anchor =
'')
1742 global
$db, $hookmanager;
1744 if (!is_object($hookmanager)) {
1745 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
1748 if ((!isset($params[
'mainmenu']) || empty($params[
'mainmenu'])) && GETPOSTISSET(
'mainmenu')) {
1749 $params = array_merge($params, [
'mainmenu' => (
GETPOST(
'mainmenu',
'restricthtml'))]);
1751 if ((!isset($params[
'leftmenu'])) && GETPOSTISSET(
'leftmenu')) {
1752 $params = array_merge($params, [
'leftmenu' => (
GETPOST(
'leftmenu',
'restricthtml'))]);
1756 'params' => &$params,
1757 'addtoken' => &$addtoken,
1759 $hookmanager->executeHooks(
'buildurl', $parameters);
1761 $params = array_merge($params, [
'token' => newToken()]);
1764 $url .=
'?' . http_build_query($params);
1767 $url .=
'#' . preg_replace(
'/[^a-z]/i',
'', $anchor);
1786 if (empty($properties)) {
1787 return get_object_vars($obj);
1790 $existingProperties = [];
1791 $realProperties = get_object_vars($obj);
1794 foreach ($properties as $property) {
1795 if (array_key_exists($property, $realProperties)) {
1797 $existingProperties[$property] = $obj->{$property};
1798 } elseif (property_exists($obj, $property)) {
1800 $existingProperties[$property] = $obj->{$property};
1804 return $existingProperties;
1825function dol_clone($srcobject, $native = 2)
1829 dol_syslog(
"Warning, call to dol_clone() with the deprecated parameter native=0, use 2 instead", LOG_WARNING);
1832 if (isset($srcobject->db) && isset($srcobject->db->db) && is_object($srcobject->db->db) && get_class($srcobject->db->db) ==
'PgSql\Connection') {
1833 $tmpsavdb = $srcobject->db;
1834 unset($srcobject->db);
1837 $myclone = unserialize(serialize($srcobject));
1839 if (!empty($tmpsavdb)) {
1840 $srcobject->db = $tmpsavdb;
1842 } elseif ($native == 2) {
1845 $tmparray = get_object_vars($srcobject);
1847 if (is_array($tmparray)) {
1848 foreach ($tmparray as $propertykey => $propertyval) {
1849 if (is_scalar($propertyval) || is_array($propertyval)) {
1850 $myclone->$propertykey = $propertyval;
1855 $myclone = clone $srcobject;
1872 if (is_object($srcobject)) {
1873 $srcobject = get_object_vars($srcobject);
1876 if (is_array($srcobject)) {
1878 foreach ($srcobject as $key => $value) {
1879 if (in_array($key, array(
'db',
'fields',
'error',
'errorhidden',
'errors',
'oldcopy',
'linkedObjects',
'linked_objects'))) {
1900function dol_size($size, $type =
'')
1903 if (empty(
$conf->dol_optimize_smallscreen)) {
1906 if ($type ==
'width' && $size > 250) {
1927function dol_sanitizeFileName($str, $newstr =
'_', $unaccent = 1, $includequotes = 0, $allowdash = 0)
1935 $filesystem_forbidden_chars = array(
'<',
'>',
'/',
'\\',
'?',
'*',
'|',
'"',
':',
'°',
'$',
';',
'`');
1936 if ($includequotes) {
1937 $filesystem_forbidden_chars[] =
"'";
1940 $tmp = preg_replace(
'/\-\-+/',
'_', $tmp);
1941 if (empty($allowdash)) {
1942 $tmp = preg_replace(
'/\s+\-([^\s])/',
' _$1', $tmp);
1943 $tmp = preg_replace(
'/\s+\-$/',
'', $tmp);
1945 $tmp = str_replace(
'..',
'', $tmp);
1946 $tmp = str_replace(
'~', $newstr, $tmp);
1947 $tmp = preg_replace(
'/\s{2,}/',
' ', $tmp);
1974 $filesystem_forbidden_chars = array(
'<',
'>',
'?',
'*',
'|',
'"',
'°',
'$',
';',
'`');
1981 $tmp = preg_replace(
'/\-\-+/', $newstr, $tmp);
1982 if (empty($allowdash)) {
1983 $tmp = preg_replace(
'/\s+\-([^\s])/',
' '.$newstr.
'$1', $tmp);
1984 $tmp = preg_replace(
'/\s+\-$/',
'', $tmp);
1986 $tmp = str_replace(
'..', $newstr, $tmp);
1987 $tmp = str_replace(
'~', $newstr, $tmp);
1988 $tmp = preg_replace(
'/\s{2,}/',
' ', $tmp);
2004 $stringtoclean = preg_replace(
'/[\x00-\x1F\x7F]/u',
'', $stringtoclean);
2006 $stringtoclean = preg_replace(
'/<!--[^>]*-->/',
'', $stringtoclean);
2008 $stringtoclean = str_replace(
'\\',
'/', $stringtoclean);
2012 $stringtoclean = str_replace(array(
':',
';',
'@'),
'', $stringtoclean);
2016 $oldstringtoclean = $stringtoclean;
2019 $stringtoclean = str_ireplace(array(
'javascript',
'vbscript',
'&colon',
'&#'),
'', $stringtoclean);
2020 }
while ($oldstringtoclean != $stringtoclean);
2024 $stringtoclean = preg_replace(array(
'/^[a-z]*\/\/+/i'),
'', $stringtoclean);
2027 return $stringtoclean;
2039 $oldstringtoclean = $stringtoclean;
2040 $stringtoclean = str_ireplace(array(
'"',
':',
'[',
']',
"\n",
"\r",
'\\',
'\/'),
'', $stringtoclean);
2041 }
while ($oldstringtoclean != $stringtoclean);
2043 return $stringtoclean;
2056 return preg_replace(
'/[^\w]+/',
'', $str);
2070 if (is_null($str)) {
2075 if (extension_loaded(
'intl') &&
getDolGlobalString(
'MAIN_UNACCENT_USE_TRANSLITERATOR')) {
2076 $transliterator = Transliterator::createFromRules(
':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: NFC;', Transliterator::FORWARD);
2077 return $transliterator->transliterate($str);
2080 $string = rawurlencode($str);
2081 $replacements = array(
2158 $string = strtr($string, $replacements);
2159 return rawurldecode($string);
2164 "\xC0\xC1\xC2\xC3\xC4\xC5\xC7
2165 \xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1
2166 \xD2\xD3\xD4\xD5\xD8\xD9\xDA\xDB\xDD
2167 \xE0\xE1\xE2\xE3\xE4\xE5\xE7\xE8\xE9\xEA\xEB
2168 \xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF8
2169 \xF9\xFA\xFB\xFC\xFD\xFF",
2177 $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"));
2195function dol_string_nospecial($str, $newstr =
'_', $badcharstoreplace =
'', $badcharstoremove =
'', $keepspaces = 0)
2197 $forbidden_chars_to_replace = array(
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
",",
";",
"=",
'°',
'$',
';');
2198 if (empty($keepspaces)) {
2199 $forbidden_chars_to_replace[] =
" ";
2201 $forbidden_chars_to_remove = array();
2204 if (is_array($badcharstoreplace)) {
2205 $forbidden_chars_to_replace = $badcharstoreplace;
2207 if (is_array($badcharstoremove)) {
2208 $forbidden_chars_to_remove = $badcharstoremove;
2212 return str_replace($forbidden_chars_to_replace, $newstr, str_replace($forbidden_chars_to_remove,
"", $str));
2231 if ($removetabcrlf) {
2232 return preg_replace(
'/[\x00-\x1F\x7F]/u',
'', $str);
2234 return preg_replace(
'/[\x00-\x08\x11-\x12\x14-\x1F\x7F]/u',
'', $str);
2249 if (function_exists(
'iconv')) {
2250 $slug = iconv(
'UTF-8',
'ASCII//TRANSLIT//IGNORE', $slug);
2254 $slug = strtolower($slug);
2257 $slug = preg_replace(
'/[^a-z0-9]+/',
'-', $slug);
2260 $slug = trim($slug,
'-');
2273function dol_escape_js($stringtoescape, $mode = 0, $noescapebackslashn = 0)
2275 if (is_null($stringtoescape)) {
2280 $substitjs = array(
"'" =>
"\\'",
"\r" =>
'\\r');
2282 if (empty($noescapebackslashn)) {
2283 $substitjs[
"\n"] =
'\\n';
2284 $substitjs[
'\\'] =
'\\\\';
2287 $substitjs[
"'"] =
"\\'";
2288 $substitjs[
'"'] =
"\\'";
2289 } elseif ($mode == 1) {
2290 $substitjs[
"'"] =
"\\'";
2291 } elseif ($mode == 2) {
2292 $substitjs[
'"'] =
'\\"';
2293 } elseif ($mode == 3) {
2294 $substitjs[
"'"] =
"\\'";
2295 $substitjs[
'"'] =
"\\\"";
2297 return strtr((
string) $stringtoescape, $substitjs);
2311 return rawurlencode($stringtoescape);
2322 return str_replace(
'"',
'\"', $stringtoescape);
2334 if (is_null($stringtoescape)) {
2338 if ($stringforquotes == 2) {
2339 return str_replace(
'"',
"'", $stringtoescape);
2340 } elseif ($stringforquotes == 1) {
2346 $stringtoescape = str_replace(
'\\',
'', $stringtoescape);
2347 return str_replace(
"'",
"\'", str_replace(
'"',
"'", $stringtoescape));
2350 return 'Bad parameter for stringforquotes in dol_escape_php';
2361 return preg_replace(
'/[^a-z0-9_]/i',
'', $stringtoescape);
2372 return $stringtoescape;
2413function dolPrintHTML($s, $allowiframe = 0, $moreallowedtags = array())
2422 $allowedtags =
'common';
2423 if (!empty($moreallowedtags)) {
2424 $allowedtags .=
','.implode(
',', $moreallowedtags);
2426 return dol_escape_htmltag(
dol_htmlwithnojs(
dol_string_onlythesehtmltags($stringWithEntitesForSpecialChar, 1, 1, 1, $allowiframe, $allowedtags)), 1, 1, $allowedtags, 0, 1);
2441 $allowedtags = array(
'br',
'b',
'font',
'hr',
'span');
2442 if (!empty($allowothertags) && is_array($allowothertags)) {
2443 $allowedtags = array_merge($allowedtags, $allowothertags);
2447 if ($escapeonlyhtmltags) {
2448 return dol_escape_htmltag(
dol_string_onlythesehtmltags($s, 1, 0, 0, 0, $allowedtags), 1, -1,
'', 1, 1);
2450 return dol_escape_htmltag(
dol_string_onlythesehtmltags(
dol_htmlentitiesbr($s), 1, 0, 0, 0, $allowedtags), 1, -1,
'', 0, 1);
2466 $escapeonlyhtmltags = 1;
2467 return dol_escape_htmltag(
dol_string_onlythesehtmltags($s, 1, 1, 1, 0, array()), 0, 0,
'', $escapeonlyhtmltags, 1);
2492 return htmlspecialchars($s, ENT_HTML5,
'UTF-8');
2512function dol_escape_htmltag($stringtoescape, $keepb = 0, $keepn = 0, $noescapetags =
'', $escapeonlyhtmltags = 0, $cleanalsojavascript = 0)
2515 if (preg_match(
'/^common([a-z,]*)/', $noescapetags, $reg)) {
2516 $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';
2518 $noescapetags .=
',header,footer,nav,section,menu,menuitem';
2519 if (!empty($reg[1])) {
2520 $noescapetags .= $reg[1];
2523 if ($cleanalsojavascript) {
2528 if ($escapeonlyhtmltags) {
2529 $tmp = htmlspecialchars_decode((
string) $stringtoescape, ENT_COMPAT);
2536 $tmp = (
string) $stringtoescape;
2539 $tmp = str_ireplace(
'<',
'__DONOTDECODELT', $tmp);
2540 $tmp = str_ireplace(
'>',
'__DONOTDECODEGT', $tmp);
2541 $tmp = str_ireplace(
'&',
'__DONOTDECODEAMP', $tmp);
2542 $tmp = str_ireplace(
'"',
'__DONOTDECODEQUOT', $tmp);
2543 $tmp = str_ireplace(
'&apos',
'__DONOTDECODEAPOS', $tmp);
2544 $tmp = str_ireplace(
''',
'__DONOTDECODE39', $tmp);
2546 $tmp = html_entity_decode((
string) $tmp, ENT_COMPAT,
'UTF-8');
2549 $tmp = str_ireplace(
'__DONOTDECODELT',
'<', $tmp);
2550 $tmp = str_ireplace(
'__DONOTDECODEGT',
'>', $tmp);
2551 $tmp = str_ireplace(
'__DONOTDECODEAMP',
'&', $tmp);
2552 $tmp = str_ireplace(
'__DONOTDECODEQUOT',
'"', $tmp);
2553 $tmp = str_ireplace(
'__DONOTDECODEAPOS',
'&apos', $tmp);
2554 $tmp = str_ireplace(
'__DONOTDECODE39',
''', $tmp);
2556 $tmp = str_ireplace(
''',
'__SIMPLEQUOTE__', $tmp);
2559 $tmp = strtr($tmp, array(
"<b>" =>
'',
'</b>' =>
'',
'<strong>' =>
'',
'</strong>' =>
''));
2562 $tmp = strtr($tmp, array(
"\r" =>
'\\r',
"\n" =>
'\\n'));
2563 } elseif ($keepn == -1) {
2564 $tmp = strtr($tmp, array(
"\r" =>
'',
"\n" =>
''));
2567 if ($escapeonlyhtmltags) {
2568 $tmp = htmlspecialchars($tmp, ENT_COMPAT,
'UTF-8');
2572 $tmparrayoftags = array();
2573 if ($noescapetags) {
2574 $tmparrayoftags = explode(
',', $noescapetags);
2577 if (count($tmparrayoftags)) {
2582 $tmp = str_ireplace(array(
'__DOUBLEQUOTE',
'__BEGINTAGTOREPLACE',
'__ENDTAGTOREPLACE',
'__BEGINENDTAGTOREPLACE'),
'', $tmp);
2584 foreach ($tmparrayoftags as $tagtoreplace) {
2586 $tmp = preg_replace(
'/<' . preg_quote($tagtoreplace,
'/') .
'>/',
'__BEGINTAGTOREPLACE' . $tagtoreplace .
'__', $tmp);
2587 $tmp = str_ireplace(
'</' . $tagtoreplace .
'>',
'__ENDTAGTOREPLACE' . $tagtoreplace .
'__', $tmp);
2588 $tmp = preg_replace(
'/<' . preg_quote($tagtoreplace,
'/') .
' \/>/',
'__BEGINENDTAGTOREPLACE' . $tagtoreplace .
'__', $tmp);
2594 if (preg_match(
'/<' . preg_quote($tagtoreplace,
'/') .
'(\s+)([^>]+)>/', $tmp, $reg)) {
2596 $tmpattributes = str_ireplace(array(
'[',
']'),
'_', $reg[2]);
2597 $tmpattributes = str_ireplace(
'"',
'__DOUBLEQUOTE__', $tmpattributes);
2598 $tmpattributes = preg_replace(
'/[^a-z0-9_%,\/\?\;\s=&\.\-@:\.#\+]/i',
'', $tmpattributes);
2600 $tmp = str_replace(
'<' . $tagtoreplace . $reg[1] . $reg[2] .
'>',
'__BEGINTAGTOREPLACE' . $tagtoreplace .
'[' . $tmpattributes .
']__', $tmp);
2603 $diff = strcmp($tmpold, $tmp);
2607 $tmp = str_ireplace(
'&',
'__ANDNOSEMICOLON__', $tmp);
2608 $tmp = str_ireplace(
'"',
'__DOUBLEQUOTENOSEMICOLON__', $tmp);
2609 $tmp = str_ireplace(
'<',
'__LESSTHAN__', $tmp);
2610 $tmp = str_ireplace(
'>',
'__GREATERTHAN__', $tmp);
2614 $result = htmlentities($tmp, ENT_COMPAT,
'UTF-8');
2618 if (count($tmparrayoftags)) {
2620 foreach ($tmparrayoftags as $tagtoreplace) {
2621 $result = str_ireplace(
'__BEGINTAGTOREPLACE' . $tagtoreplace .
'__',
'<' . $tagtoreplace .
'>', $result);
2622 $result = preg_replace(
'/__BEGINTAGTOREPLACE' . $tagtoreplace .
'\[([^\]]*)\]__/',
'<' . $tagtoreplace .
' \1>', $result);
2623 $result = str_ireplace(
'__ENDTAGTOREPLACE' . $tagtoreplace .
'__',
'</' . $tagtoreplace .
'>', $result);
2624 $result = str_ireplace(
'__BEGINENDTAGTOREPLACE' . $tagtoreplace .
'__',
'<' . $tagtoreplace .
' />', $result);
2625 $result = preg_replace(
'/__BEGINENDTAGTOREPLACE' . $tagtoreplace .
'\[([^\]]*)\]__/',
'<' . $tagtoreplace .
' \1 />', $result);
2628 $result = str_ireplace(
'__DOUBLEQUOTE__',
'"', $result);
2630 $result = str_ireplace(
'__ANDNOSEMICOLON__',
'&', $result);
2631 $result = str_ireplace(
'__DOUBLEQUOTENOSEMICOLON__',
'"', $result);
2632 $result = str_ireplace(
'__LESSTHAN__',
'<', $result);
2633 $result = str_ireplace(
'__GREATERTHAN__',
'>', $result);
2636 $result = str_ireplace(
'__SIMPLEQUOTE__',
''', $result);
2653 if (function_exists(
'mb_strtolower')) {
2654 return mb_strtolower($string, $encoding);
2656 return strtolower($string);
2670 if (function_exists(
'mb_strtoupper')) {
2671 return mb_strtoupper($string, $encoding);
2673 return strtoupper($string);
2687 if (function_exists(
'mb_substr')) {
2688 return mb_strtoupper(mb_substr($string, 0, 1, $encoding), $encoding) . mb_substr($string, 1,
null, $encoding);
2690 return ucfirst($string);
2704 if (function_exists(
'mb_convert_case')) {
2705 return mb_convert_case($string, MB_CASE_TITLE, $encoding);
2707 return ucwords($string);
2719 $backtrace = debug_backtrace();
2721 if (count($backtrace) >= 1) {
2723 if (count($backtrace) == 1) {
2726 $trace = $backtrace[$pos];
2727 if (isset($trace[
'file'], $trace[
'line'])) {
2728 $msg =
" From {$trace['file']}:{$trace['line']}.";
2756function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename =
'', $restricttologhandler =
'', $logcontext =
null)
2758 global
$conf, $user, $debugbar;
2766 if (defined(
'USEEXTERNALSERVER') && !defined(
'USEDOLIBARRSERVER') && !defined(
'USEDOLIBARREDITOR')) {
2767 global $website, $websitekey;
2768 if (is_object($website) && !empty($website->ref)) {
2769 $suffixinfilename .=
'_website_' . $website->ref;
2770 } elseif (!empty($websitekey)) {
2771 $suffixinfilename .=
'_website_' . $websitekey;
2776 if (defined(
'USESUFFIXINLOG')) {
2777 $suffixinfilename .= constant(
'USESUFFIXINLOG');
2781 foreach (
$conf->loghandlers as $loghandlerinstance) {
2782 $loghandlerinstance->setIdent($ident);
2786 if (!empty($message)) {
2789 $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');
2791 if (!array_key_exists($level, $logLevels)) {
2792 dol_syslog(
'Error Bad Log Level ' . $level, LOG_ERR);
2800 $message = preg_replace(
'/password=\'[^\']*\'/',
'password=\'hidden\'', $message);
2804 if ((!empty($_REQUEST[
'logtohtml']) &&
getDolGlobalString(
'MAIN_ENABLE_LOG_TO_HTML'))
2805 || (is_object($user) && $user->hasRight(
'debugbar',
'read') && is_object($debugbar))
2807 $ospid = sprintf(
"%7s",
dol_trunc((
string) getmypid(), 7,
'right',
'UTF-8', 1));
2808 $osuser =
" " . sprintf(
"%6s",
dol_trunc(function_exists(
'posix_getuid') ? posix_getuid() :
'', 6,
'right',
'UTF-8', 1));
2810 $conf->logbuffer[] =
dol_print_date(time(),
"%Y-%m-%d %H:%M:%S") .
" " . sprintf(
"%-7s", $logLevels[$level]) .
" " . $ospid .
" " . $osuser .
" " . $message;
2816 print
"\n\n<!-- Log start\n";
2818 print
"Log end -->\n";
2822 'message' => $message,
2823 'script' => (isset($_SERVER[
'PHP_SELF']) ? basename($_SERVER[
'PHP_SELF'],
'.php') :
''),
2825 'user' => ((is_object($user) && $user->id) ? $user->login :
''),
2827 'osuser' => function_exists(
'posix_getuid') ? (
string) posix_getuid() :
'',
2828 'ospid' => (
string) getmypid()
2833 if (!empty($remoteip)) {
2834 $data[
'ip'] = $remoteip;
2838 if (!empty($_SERVER[
'HTTP_X_FORWARDED_FOR'])) {
2839 $tmpips = explode(
',', $_SERVER[
'HTTP_X_FORWARDED_FOR']);
2843 foreach ($tmpips as $tmpip) {
2844 $tmpip = trim($tmpip);
2845 if (strtolower($tmpip) == strtolower($remoteip)) {
2848 if (empty($data[
'ip'])) {
2849 $data[
'ip'] = $tmpip;
2852 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $tmpip;
2855 if (!$foundremoteip) {
2857 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $remoteip;
2859 $data[
'ip'] .= (($j > 0) ?
']' :
'');
2860 } elseif (!empty($_SERVER[
'HTTP_CLIENT_IP'])) {
2861 $tmpips = explode(
',', $_SERVER[
'HTTP_CLIENT_IP']);
2865 foreach ($tmpips as $tmpip) {
2866 $tmpip = trim($tmpip);
2867 if (strtolower($tmpip) == strtolower($remoteip)) {
2870 if (empty($data[
'ip'])) {
2871 $data[
'ip'] = $tmpip;
2874 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $tmpip;
2877 if (!$foundremoteip) {
2879 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $remoteip;
2881 $data[
'ip'] .= (($j > 0) ?
']' :
'');
2883 } elseif (!empty($_SERVER[
'SERVER_ADDR'])) {
2885 $data[
'ip'] = (
string) $_SERVER[
'SERVER_ADDR'];
2886 } elseif (!empty($_SERVER[
'COMPUTERNAME'])) {
2888 $data[
'ip'] = (
string) $_SERVER[
'COMPUTERNAME'];
2890 $data[
'ip'] =
'???';
2893 if (!empty($_SERVER[
'USERNAME'])) {
2895 $data[
'osuser'] = (
string) $_SERVER[
'USERNAME'];
2896 } elseif (!empty($_SERVER[
'LOGNAME'])) {
2898 $data[
'osuser'] = (
string) $_SERVER[
'LOGNAME'];
2902 foreach (
$conf->loghandlers as $loghandlerinstance) {
2903 if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler) {
2906 $loghandlerinstance->export($data, $suffixinfilename);
2912 foreach (
$conf->loghandlers as $loghandlerinstance) {
2913 $loghandlerinstance->setIdent($ident);
2935 $templatenameforexport = $website->name_template;
2936 if (empty($templatenameforexport)) {
2937 $templatenameforexport =
'website_' . $website->ref;
2941 $out .=
'<input type="button" class="cursorpointer button bordertransp" id="open-dialog-' . $name .
'" value="' .
dol_escape_htmltag($buttonstring) .
'"/>';
2944 $out .=
'<script nonce="' . getNonce() .
'" type="text/javascript">';
2945 $out .=
'jQuery(document).ready(function () {';
2946 $out .=
' jQuery("#open-dialog-' . $name .
'").click(function () {';
2947 $out .=
' var dialogHtml = \'';
2949 $dialogcontent =
' <div id="custom-dialog-' . $name .
'">';
2950 $dialogcontent .=
' <div style="margin-top: 20px;">';
2951 $dialogcontent .=
' <label for="export-site-' . $name .
'"><strong>' . $langs->trans(
"ExportSiteLabel") .
'...</label><br>';
2952 $dialogcontent .=
' <button class="button smallpaddingimp" id="export-site-' . $name .
'">' .
dol_escape_htmltag($langs->trans(
"DownloadZip")) .
'</button>';
2953 $dialogcontent .=
' </div>';
2954 $dialogcontent .=
' <br>';
2955 $dialogcontent .=
' <div style="margin-top: 20px;">';
2956 $dialogcontent .=
' <strong>' . $langs->trans(
"ExportSiteGitLabel") .
' ' . $form->textwithpicto(
'', $langs->trans(
"SourceFiles"), 1,
'help',
'', 0, 3,
'') .
'</strong><br>';
2957 $dialogcontent .=
' <form action="' .
dol_escape_htmltag($overwriteGitUrl) .
'" method="POST">';
2958 $dialogcontent .=
' <input type="hidden" name="action" value="overwritesite">';
2959 $dialogcontent .=
' <input type="hidden" name="token" value="' . newToken() .
'">';
2960 $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>';
2961 $dialogcontent .=
' <button type="submit" class="button smallpaddingimp" id="overwrite-git-' . $name .
'">' .
dol_escape_htmltag($langs->trans(
"ExportIntoGIT")) .
'</button>';
2962 $dialogcontent .=
' </form>';
2963 $dialogcontent .=
' </div>';
2964 $dialogcontent .=
' </div>';
2971 // Add the content of the dialog to the body of the page
2972 $out .= ' var $dialog = jQuery(
"#custom-dialog-' . $name . '");
';
2973 $out .= ' if ($dialog.length > 0) {
2976 jQuery(
"body").append(dialogHtml);
';
2978 // Configuration of popup
2979 $out .= ' jQuery(
"#custom-dialog-' . $name . '").dialog({
';
2980 $out .= ' autoOpen:
false,
';
2981 $out .= ' modal:
true,
';
2982 $out .= ' height: 290,
';
2983 $out .= ' width:
"40%",
';
2984 $out .= ' title:
"' . dol_escape_js($label) . '",
';
2987 // Simulate a click on the original "submit" input to export the site.
2988 $out .= ' jQuery(
"#export-site-' . $name . '").click(
function () {
';
2989 $out .= ' console.log(
"Clic on exportsite.");
';
2990 $out .= ' var target = jQuery(
"input[name=\'' . dol_escape_js($exportSiteName) . '\']");
';
2991 $out .= ' console.log(
"element founded:", target.length > 0);
';
2992 $out .= ' if (target.length > 0) { target.click(); }
';
2993 $out .= ' jQuery(
"#custom-dialog-' . $name . '").dialog(
"close");
';
2997 $out .= ' jQuery(
"#custom-dialog-' . $name . '").dialog(
"open");
';
2998 $out .= ' return false;
';
3001 $out .= '</script>
';
3023function dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled = '
', $morecss = 'classlink
button bordertransp
', $jsonopen = '', $jsonclose = '', $accesskey = '')
3027 if (strpos($url, '?
') > 0) {
3028 $url .= '&dol_hide_topmenu=1&dol_hide_leftmenu=1&dol_openinpopup=
' . urlencode($name);
3030 $url .= '?dol_hide_topmenu=1&dol_hide_leftmenu=1&dol_openinpopup=
' . urlencode($name);
3033 if (preg_match('/^https/i
', $url)) {
3036 $urltoopen = DOL_URL_ROOT . $url;
3041 //print '<input
type=
"submit" class=
"button bordertransp"'.$disabled.' value=
"'.dol_escape_htmltag($langs->trans("MediaFiles
")).'" name=
"file_manager">
';
3042 $out .= '<!-- a link
for button to open url into a dialog popup -->
';
3043 $out .= '<a
' . ($accesskey ? ' accesskey=
"' . $accesskey . '"' : '') . ' class=
"cursorpointer reposition button_' . $name . ($morecss ? ' ' . $morecss : '') . '"' . $disabled . ' title=
"' . dol_escape_htmltag($label) . '"';
3044 if (empty($conf->use_javascript_ajax)) {
3045 $out .= ' href=
"' . $urltoopen . '" target=
"_blank"';
3046 } elseif ($jsonopen) {
3047 $out .= ' href=
"#" onclick=
"' . $jsonopen . '"';
3049 $out .= ' href=
"#"';
3051 $out .= '>
' . $buttonstring . '</a>
';
3053 if (!empty($conf->use_javascript_ajax)) {
3054 // Add code to open url using the popup.
3055 $out .= '<!-- code to open popup and variables to retrieve returned variables -->
';
3056 $out .= '<div
id=
"idfordialog' . $name . '" class=
"hidden">
' . (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER
') < 2 ? 'div
for dialog
' : '') . '</div>
';
3058 $out .= '<!-- Add js code to open dialog popup on dialog -->
';
3059 $out .= '<script nonce=
"' . getNonce() . '" type=
"text/javascript">
3060 jQuery(document).ready(
function () {
3061 jQuery(
".button_' . $name . '").click(
function () {
3062 console.log(\
'Open popup with jQuery(...).dialog() on URL ' .
dol_escape_js($urltoopen) .
'\');
3063 var $tmpdialog = $(\
'#idfordialog' . $name .
'\');
3064 $tmpdialog.html(\
'<iframe class="iframedialog" id="iframedialog' . $name .
'" style="border: 0px;" src="' . $urltoopen .
'" width="100%" height="98%"></iframe>\');
3068 height: (window.innerHeight - 150),
3071 open: function (event, ui) {
3072 console.log(
"open popup name=' . $name . '");
3074 close:
function (event, ui) {
3075 console.log(
"Popup is closed, run jsonclose = ' . $jsonclose . '");
3076 ' . (empty($jsonclose) ? '' : $jsonclose . ';
') . '
3080 $tmpdialog.dialog(\
'open\');
3105function dol_fiche_head($links = array(), $active =
'0', $title =
'', $notab = 0, $picto =
'', $pictoisfullpath = 0, $morehtmlright =
'', $morecss =
'', $limittoshow = 0, $moretabssuffix =
'')
3107 print
dol_get_fiche_head($links, $active, $title, $notab, $picto, $pictoisfullpath, $morehtmlright, $morecss, $limittoshow, $moretabssuffix);
3127function dol_get_fiche_head($links = array(), $active =
'', $title =
'', $notab = 0, $picto =
'', $pictoisfullpath = 0, $morehtmlright =
'', $morecss =
'', $limittoshow = 0, $moretabssuffix =
'', $dragdropfile = 0, $morecssdiv =
'')
3129 global
$conf, $langs, $hookmanager;
3133 if (!empty(
$conf->dol_optimize_smallscreen)) {
3137 $out =
"\n" .
'<!-- dol_fiche_head - dol_get_fiche_head -->';
3139 if ((!empty($title) && $showtitle) || $morehtmlright || !empty($links)) {
3140 $out .=
'<div class="tabs' . ($picto ?
'' :
' nopaddingleft') .
'" data-role="controlgroup" data-type="horizontal">' .
"\n";
3144 if ($morehtmlright) {
3145 $out .=
'<div class="inline-block floatright tabsElem">' . $morehtmlright .
'</div>';
3152 if (is_array($links) && !empty($links)) {
3153 $keys = array_keys($links);
3155 $maxkey = max($keys);
3161 if (empty($limittoshow)) {
3164 if (!empty(
$conf->dol_optimize_smallscreen)) {
3172 for ($i = 0; $i <= $maxkey; $i++) {
3173 if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2])) {
3175 if ($i >= $limittoshow) {
3181 for ($i = 0; $i <= $maxkey; $i++) {
3182 if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2])) {
3188 if ($i < $limittoshow || $isactive) {
3190 $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])) .
' -->';
3192 if (isset($links[$i][2]) && $links[$i][2] ==
'image') {
3193 if (!empty($links[$i][0])) {
3194 $out .=
'<a class="tabimage' . ($morecss ?
' ' . $morecss :
'') .
'" href="' . $links[$i][0] .
'">' . $links[$i][1] .
'</a>' .
"\n";
3196 $out .=
'<span class="tabspan">' . $links[$i][1] .
'</span>' .
"\n";
3198 } elseif (!empty($links[$i][1])) {
3200 $out .=
'<div class="tab tab' . ($isactive ?
'active' :
'unactive') .
'" style="margin: 0 !important">';
3202 if (!empty($links[$i][0])) {
3203 $titletoshow = preg_replace(
'/<.*$/',
'', $links[$i][1]);
3204 $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) .
'">';
3207 if ($displaytab == 0 && $picto) {
3208 $out .=
img_picto($title, $picto,
'', $pictoisfullpath, 0, 0,
'',
'imgTabTitle paddingright marginrightonlyshort');
3211 $out .= $links[$i][1];
3212 if (!empty($links[$i][0])) {
3213 $out .=
'</a>' .
"\n";
3215 $out .= empty($links[$i][4]) ?
'' : $links[$i][4];
3224 $outmore .=
'<div class="popuptabset wordwrap">';
3226 $outmore_content =
'';
3228 if (isset($links[$i][2]) && $links[$i][2] ==
'image') {
3229 if (!empty($links[$i][0])) {
3230 $outmore_content .=
'<a class="tabimage' . ($morecss ?
' ' . $morecss :
'') .
'" href="' . $links[$i][0] .
'">' . $links[$i][1] .
'</a>' .
"\n";
3232 $outmore_content .=
'<span class="tabspan">' . $links[$i][1] .
'</span>' .
"\n";
3234 } elseif (!empty($links[$i][1])) {
3235 $outmore_content .=
'<a' . (!empty($links[$i][2]) ?
' id="' . $links[$i][2] .
'"' :
'') .
' class="wordwrap inline-block' . ($morecss ?
' ' . $morecss :
'') .
'" href="' . $links[$i][0] .
'">';
3236 $outmore_content .= preg_replace(
'/([a-z])\|([a-z])/i',
'\\1 | \\2', $links[$i][1]);
3237 $outmore_content .=
'</a>' .
"\n";
3239 if ($outmore_content !==
'') {
3240 $outmore .=
'<div class="popuptab wordwrap" style="display:inherit;">' . $outmore_content .
'</div>';
3246 $displaytab = $i + 1;
3249 $outmore .=
'</div>';
3253 $left = ($langs->trans(
"DIRECTION") ==
'rtl' ?
'right' :
'left');
3254 $right = ($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right');
3255 $widthofpopup = 240;
3257 $tabsname = $moretabssuffix;
3258 if (empty($tabsname)) {
3259 $tabsname = str_replace(
"@",
"", $picto);
3261 $out .=
'<div id="moretabs' . $tabsname .
'" class="inline-block tabsElem valignmiddle">';
3263 $out .=
'<div class="tab valignmiddle"><a href="#" class="tab moretab inline-block tabunactive valignmiddle"><span class="fa fa-angle-down"></span> <span class="opacitymedium">+' . $nbintab .
'</span></a></div>';
3265 $out .=
'<div id="moretabsList' . $tabsname .
'" style="width: ' . $widthofpopup .
'px; position: absolute; ' . $left .
': -999em; text-align: ' . $left .
'; margin:0px; padding:2px; z-index:10;">';
3268 $out .=
'<div></div>';
3271 $out .=
'<script nonce="' . getNonce() .
'">';
3272 $out .=
"$('#moretabs" . $tabsname .
"').mouseenter( function() {
3273 var x = this.offsetLeft, y = this.offsetTop;
3274 console.log('mouseenter " . $left .
" x='+x+' y='+y+' window.innerWidth='+window.innerWidth);
3275 if ((window.innerWidth - x) < " . ($widthofpopup + 10) .
") {
3276 $('#moretabsList" . $tabsname .
"').css('" . $right .
"','8px');
3278 $('#moretabsList" . $tabsname .
"').css('" . $left .
"','auto');
3281 $out .=
"$('#moretabs" . $tabsname .
"').mouseleave( function() { console.log('mouseleave " . $left .
"'); $('#moretabsList" . $tabsname .
"').css('" . $left .
"','-999em');});";
3282 $out .=
"</script>";
3285 if ((!empty($title) && $showtitle) || $morehtmlright || !empty($links)) {
3289 if (!$notab || $notab == -1 || $notab == -2 || $notab == -3 || $notab == -4) {
3290 $out .=
"\n" .
'<div id="dragDropAreaTabBar" class="tabBar' . ($notab == -1 ?
'' : ($notab == -2 ?
' tabBarNoTop' : ((($notab == -3 || $notab == -4) ?
' noborderbottom' :
'') . ($notab == -4 ?
'' :
' tabBarWithBottom'))));
3291 $out .= ($morecssdiv ?
' ' . $morecssdiv :
'');
3292 $out .=
'">' .
"\n";
3294 if (!empty($dragdropfile)) {
3295 include_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
3298 $parameters = array(
'tabname' => $active,
'out' => $out);
3299 $reshook = $hookmanager->executeHooks(
'printTabsHead', $parameters);
3301 $out = $hookmanager->resPrint;
3327 if (!$notab || $notab == -1) {
3328 return "\n</div>\n";
3353function dol_banner_tab(
$object, $paramid, $morehtml =
'', $shownav = 1, $fieldid =
'rowid', $fieldref =
'ref', $morehtmlref =
'', $moreparam =
'', $nodbprefix = 0, $morehtmlleft =
'', $morehtmlstatus =
'', $onlybanner = 0, $morehtmlright =
'')
3355 global
$conf, $form, $user, $langs, $hookmanager, $action;
3359 $maxvisiblephotos = 1;
3364 if (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'barcode',
'lire_advance')) {
3367 $modulepart =
'unknown';
3369 if (in_array(
$object->element, [
'societe',
'contact',
'product',
'ticket',
'bom'])) {
3370 $modulepart =
$object->element;
3371 } elseif (
$object->element ==
'member') {
3372 $modulepart =
'memberphoto';
3373 } elseif (
$object->element ==
'user') {
3374 $modulepart =
'userphoto';
3377 if (class_exists(
"Imagick")) {
3378 if (
$object->element ==
'expensereport' ||
$object->element ==
'propal' ||
$object->element ==
'commande' ||
$object->element ==
'facture' ||
$object->element ==
'supplier_proposal') {
3379 $modulepart =
$object->element;
3380 } elseif (
$object->element ==
'fichinter' ||
$object->element ==
'intervention') {
3381 $modulepart =
'ficheinter';
3382 } elseif (
$object->element ==
'contrat' ||
$object->element ==
'contract') {
3383 $modulepart =
'contract';
3384 } elseif (
$object->element ==
'order_supplier') {
3385 $modulepart =
'supplier_order';
3386 } elseif (
$object->element ==
'invoice_supplier') {
3387 $modulepart =
'supplier_invoice';
3391 if (
$object->element ==
'product') {
3393 '@phan-var-force Product $object';
3395 $cssclass =
'photowithmargin photoref';
3396 $showimage =
$object->is_photo_available(
$conf->product->multidir_output[$entity]);
3398 if (
$conf->browser->layout ==
'phone') {
3399 $maxvisiblephotos = 1;
3401 $useLinkPathPhoto =
getDolGlobalInt(
'PRODUCT_USE_LINK_PATH_FOR_PHOTO');
3402 if ($showimage || $useLinkPathPhoto) {
3403 $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>';
3407 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
3409 $nophoto =
'/public/theme/common/nophoto.png';
3410 $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>';
3413 } elseif (
$object->element ==
'category') {
3415 '@phan-var-force Categorie $object';
3417 $cssclass =
'photowithmargin photoref';
3418 $showimage =
$object->isAnyPhotoAvailable(
$conf->categorie->multidir_output[$entity]);
3420 if (
$conf->browser->layout ==
'phone') {
3421 $maxvisiblephotos = 1;
3424 $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>';
3428 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
3430 $nophoto =
'/public/theme/common/nophoto.png';
3431 $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>';
3434 } elseif (
$object->element ==
'bom') {
3436 '@phan-var-force Bom $object';
3438 $cssclass =
'photowithmargin photoref';
3439 $showimage =
$object->is_photo_available(
$conf->bom->multidir_output[$entity]);
3441 if (
$conf->browser->layout ==
'phone') {
3442 $maxvisiblephotos = 1;
3445 $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>';
3449 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
3451 $nophoto =
'/public/theme/common/nophoto.png';
3452 $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>';
3455 } elseif (
$object->element ==
'ticket') {
3457 $cssclass =
'photoref';
3459 '@phan-var-force Ticket $object';
3460 $showimage =
$object->is_photo_available(
$conf->ticket->multidir_output[$entity] .
'/' .
$object->ref);
3462 if (
$conf->browser->layout ==
'phone') {
3463 $maxvisiblephotos = 1;
3467 $showphoto =
$object->show_photos(
'ticket',
$conf->ticket->multidir_output[$entity],
'small', $maxvisiblephotos, 0, 0, 0, $width, 0);
3469 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">' . $showphoto .
'</div>';
3477 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
3479 $nophoto =
img_picto(
'No photo',
'object_ticket');
3480 $morehtmlleft .=
'<!-- No photo to show -->';
3481 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
3482 $morehtmlleft .= $nophoto;
3483 $morehtmlleft .=
'</div></div>';
3487 if ($modulepart !=
'unknown' || method_exists(
$object,
'getDataToShowPhoto')) {
3490 if (in_array($modulepart, array(
'propal',
'commande',
'facture',
'ficheinter',
'contract',
'supplier_order',
'supplier_proposal',
'supplier_invoice',
'expensereport')) && class_exists(
"Imagick")) {
3492 $dir_output = (empty(
$conf->$modulepart->multidir_output[$entity]) ?
$conf->$modulepart->dir_output :
$conf->$modulepart->multidir_output[$entity]) .
"/";
3493 if (in_array($modulepart, array(
'invoice_supplier',
'supplier_invoice'))) {
3495 $subdir .= ((!empty($subdir) && !preg_match(
'/\/$/', $subdir)) ?
'/' :
'') . $objectref;
3499 if (empty($subdir)) {
3500 $subdir =
'errorgettingsubdirofobject';
3503 $filepath = $dir_output . $subdir .
"/";
3505 $filepdf = $filepath . $objectref .
".pdf";
3506 $relativepath = $subdir .
'/' . $objectref .
'.pdf';
3509 $fileimage = $filepdf .
'_preview.png';
3510 $relativepathimage = $relativepath .
'_preview.png';
3512 $pdfexists = file_exists($filepdf);
3517 if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) {
3519 include_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
3528 if ($pdfexists && !$error) {
3529 $heightforphotref = 80;
3530 if (!empty(
$conf->dol_optimize_smallscreen)) {
3531 $heightforphotref = 60;
3534 if (file_exists($fileimage)) {
3535 $phototoshow =
'<div class="photoref">';
3536 $phototoshow .=
'<img height="' . $heightforphotref .
'" class="photo photowithborder" src="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=apercu' . $modulepart .
'&file=' . urlencode($relativepathimage) .
'">';
3537 $phototoshow .=
'</div>';
3540 } elseif (!$phototoshow) {
3541 $phototoshow .= $form->showphoto($modulepart,
$object, 0, 0, 0,
'photowithmargin photoref',
'small', 1, 0);
3545 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">';
3546 $morehtmlleft .= $phototoshow;
3547 $morehtmlleft .=
'</div>';
3551 if (empty($phototoshow)) {
3552 if (
$object->element ==
'action') {
3554 $cssclass =
'photorefcenter';
3555 $nophoto =
img_picto(
'No photo',
'title_agenda');
3558 $cssclass =
'photorefcenter';
3560 $prefix =
'object_';
3564 if (strpos($picto,
'fontawesome_') !==
false) {
3567 $nophoto =
img_picto(
'No photo', $prefix . $picto);
3569 $morehtmlleft .=
'<!-- No photo to show -->';
3570 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
3571 $morehtmlleft .= $nophoto;
3572 $morehtmlleft .=
'</div></div>';
3577 $morehtmlref .=
'<div style="clear: both;"></div>';
3578 $morehtmlref .=
'<div class="smallimp refidno opacitymedium banner-object-technical-id">';
3579 $morehtmlref .= $langs->trans(
"TechnicalID") .
': ' . ((int)
$object->id);
3580 $morehtmlref .=
'</div>';
3586 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">' . $form->showbarcode(
$object, 100,
'photoref valignmiddle') .
'</div>';
3589 if (
$object->element ==
'societe') {
3591 if (!empty(
$conf->use_javascript_ajax) && $user->hasRight(
'societe',
'creer') &&
getDolGlobalString(
'MAIN_DIRECT_STATUS_UPDATE')) {
3594 $morehtmlstatus .=
$object->getLibStatut(6);
3596 } elseif (
$object->element ==
'product') {
3599 if (!empty(
$conf->use_javascript_ajax) && $user->hasRight(
'produit',
'creer') &&
getDolGlobalString(
'MAIN_DIRECT_STATUS_UPDATE')) {
3600 $morehtmlstatus .=
ajax_object_onoff(
$object,
'status',
'status',
'ProductStatusOnSell',
'ProductStatusNotOnSell');
3602 $morehtmlstatus .=
'<span class="statusrefsell">' .
$object->getLibStatut(6, 0) .
'</span>';
3604 $morehtmlstatus .=
' ';
3606 if (!empty(
$conf->use_javascript_ajax) && $user->hasRight(
'produit',
'creer') &&
getDolGlobalString(
'MAIN_DIRECT_STATUS_UPDATE')) {
3607 $morehtmlstatus .=
ajax_object_onoff(
$object,
'status_buy',
'status_buy',
'ProductStatusOnBuy',
'ProductStatusNotOnBuy');
3609 $morehtmlstatus .=
'<span class="statusrefbuy">' .
$object->getLibStatut(6, 1) .
'</span>';
3611 } elseif (in_array(
$object->element, array(
'salary'))) {
3613 '@phan-var-force Salary $object';
3615 if (empty($tmptxt) || $tmptxt ==
$object->getLibStatut(3)) {
3618 $morehtmlstatus .= $tmptxt;
3619 } elseif (in_array(
$object->element, array(
'facture',
'invoice',
'invoice_supplier'))) {
3621 '@phan-var-force Facture|FactureFournisseur|CommonInvoice $object';
3622 if (!isset(
$object->alreadypaid)) {
3628 $tmptxt =
$object->getLibStatut(6, (
float)
$object->alreadypaid);
3629 if (empty($tmptxt) || $tmptxt ==
$object->getLibStatut(3)) {
3630 $tmptxt =
$object->getLibStatut(5, (
float)
$object->alreadypaid);
3632 $morehtmlstatus .= $tmptxt;
3633 } elseif (in_array(
$object->element, array(
'chargesociales',
'loan',
'tva'))) {
3635 '@phan-var-force ChargeSociales|Loan|Tva $object';
3637 if (empty($tmptxt) || $tmptxt ==
$object->getLibStatut(3)) {
3640 $morehtmlstatus .= $tmptxt;
3641 } elseif (
$object->element ==
'contrat' ||
$object->element ==
'contract') {
3644 $morehtmlstatus .=
$object->getLibStatut(5);
3646 $morehtmlstatus .=
$object->getLibStatut(4);
3648 } elseif (
$object->element ==
'facturerec') {
3650 '@phan-var-force FactureRec $object';
3651 if (
$object->frequency == 0) {
3652 $morehtmlstatus .=
$object->getLibStatut(2);
3654 $morehtmlstatus .=
$object->getLibStatut(5);
3656 } elseif (
$object->element ==
'project_task') {
3658 $tmptxt =
$object->getLibStatut(4);
3659 $morehtmlstatus .= $tmptxt;
3660 } elseif (method_exists(
$object,
'getLibStatut')) {
3661 $tmptxt =
$object->getLibStatut(6);
3662 if (empty($tmptxt) || $tmptxt ==
$object->getLibStatut(3)) {
3663 $tmptxt =
$object->getLibStatut(5);
3665 $morehtmlstatus .= $tmptxt;
3669 if (
isModEnabled(
'accounting') && in_array(
$object->element, array(
'bank',
'paiementcharge',
'facture',
'invoice',
'invoice_supplier',
'expensereport',
'payment_various'))) {
3671 if (method_exists(
$object,
'getVentilExportCompta')) {
3672 $accounted =
$object->getVentilExportCompta(1);
3673 $langs->load(
"accountancy");
3674 $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>';
3679 if (!empty(
$object->name_alias)) {
3681 '@phan-var-force Societe $object';
3682 $morehtmlref .=
'<div class="refidno opacitymedium banner-object-name-alias">' .
dol_escape_htmltag(
$object->name_alias) .
'</div>';
3686 if (in_array(
$object->element, array(
'product',
'bank_account',
'project_task'))) {
3689 $morehtmlref .=
'<div class="refidno banner-object-label">' .
$object->label .
'</div>';
3693 if (method_exists(
$object,
'getBannerAddress') && !in_array(
$object->element, array(
'product',
'bookmark',
'ecm_directories',
'ecm_files'))) {
3696 $morehtmlref .=
'<div class="refidno refaddress">';
3697 $morehtmlref .= $moreaddress;
3698 $morehtmlref .=
'</div>';
3702 $parameters = array(
'morehtmlref' => &$morehtmlref,
'moreparam' => &$moreparam,
'morehtmlleft' => &$morehtmlleft,
'morehtmlstatus' => &$morehtmlstatus,
'morehtmlright' => &$morehtmlright);
3703 $reshook = $hookmanager->executeHooks(
'formDolBanner', $parameters,
$object, $action);
3706 } elseif (empty($reshook)) {
3707 $morehtmlref .= $hookmanager->resPrint;
3708 } elseif ($reshook > 0) {
3709 $morehtmlref = $hookmanager->resPrint;
3718 print
'<div class="' . ($onlybanner ?
'arearefnobottom ' :
'arearef ') .
'heightref valignmiddle centpercent object-banner-tab-container" data-module-part="'.
dolPrintHTMLForAttribute($modulepart).
'">';
3719 print $form->showrefnav(
$object, $paramid, $morehtml, $shownav, $fieldid, $fieldref, $morehtmlref, $moreparam, $nodbprefix, $morehtmlleft, $morehtmlstatus, $morehtmlright);
3721 print
'<div class="underrefbanner clearboth"></div>';
3733function fieldLabel($langkey, $fieldkey, $fieldrequired = 0)
3737 if ($fieldrequired) {
3738 $ret .=
'<span class="fieldrequired">';
3740 $ret .=
'<label for="' . $fieldkey .
'">';
3741 $ret .= $langs->trans($langkey);
3743 if ($fieldrequired) {
3764 global $langs, $hookmanager;
3767 $countriesusingstate = array(
'AU',
'CA',
'US',
'IN',
'GB',
'ES',
'UK',
'TR',
'CN');
3772 $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)));
3775 if (isset(
$object->country_code) && in_array(
$object->country_code, array(
'AU',
'CA',
'US',
'CN')) ||
getDolGlobalString(
'MAIN_FORCE_STATE_INTO_ADDRESS')) {
3777 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3778 $ret .= (($ret && $town) ? $sep :
'') . $town;
3781 $ret .= ($ret ? ($town ?
", " : $sep) :
'') .
$object->state;
3784 $ret .= ($ret ? (($town ||
$object->state) ?
", " : $sep) :
'') .
$object->zip;
3786 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'GB',
'UK'))) {
3788 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3789 $ret .= ($ret ? $sep :
'') . $town;
3791 $ret .= ($ret ?
", " :
'') .
$object->state;
3794 $ret .= ($ret ? $sep :
'') .
$object->zip;
3796 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'ES',
'TR'))) {
3798 $ret .= ($ret ? $sep :
'') .
$object->zip;
3799 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3800 $ret .= ($town ? ((
$object->zip ?
' ' :
'') . $town) :
'');
3802 $ret .= $sep .
$object->state;
3804 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'JP'))) {
3807 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3809 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'IT'))) {
3811 $ret .= ($ret ? $sep :
'') .
$object->zip;
3812 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3813 $ret .= ($town ? ((
$object->zip ?
' ' :
'') . $town) :
'');
3814 $ret .= (empty(
$object->state_code) ?
'' : (
' ' .
$object->state_code));
3817 $town = (($extralangcode && !empty(
$object->array_languages[
'address'][$extralangcode])) ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3818 $ret .= !empty(
$object->zip) ? (($ret ? $sep :
'') .
$object->zip) :
'';
3819 $ret .= ($town ? ((
$object->zip ?
' ' : ($ret ? $sep :
'')) . $town) :
'');
3820 if (!empty(
$object->state) && in_array(
$object->country_code, $countriesusingstate)) {
3821 $ret .= ($ret ?
", " :
'') .
$object->state;
3825 if (!is_object($outputlangs)) {
3826 $outputlangs = $langs;
3829 $langs->load(
"dict");
3830 $ret .= (empty(
$object->country_code) ?
'' : ($ret ? $sep :
'') . $outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv(
"Country" .
$object->country_code)));
3833 $parameters = array(
'withcountry' => $withcountry,
'sep' => $sep,
'outputlangs' => $outputlangs,
'mode' => $mode,
'extralangcode' => $extralangcode);
3834 $reshook = $hookmanager->executeHooks(
'formatAddress', $parameters,
$object);
3838 $ret .= $hookmanager->resPrint;
3855function dol_strftime($fmt, $ts =
false, $is_gmt =
false)
3857 if ((abs($ts) <= 0x7FFFFFFF)) {
3860 return 'Error date outside supported range';
3886function dol_print_date($time, $format =
'', $tzoutput =
'auto', $outputlangs =
null, $encodetooutput =
false, $decorate = 0)
3888 global
$conf, $langs;
3895 if ($tzoutput ===
'auto') {
3896 $tzoutput = (empty(
$conf) ?
'tzserver' : (isset(
$conf->tzuserinputkey) ?
$conf->tzuserinputkey :
'tzserver'));
3901 $offsettz = $offsetdst = 0;
3904 if (is_string($tzoutput)) {
3905 if ($tzoutput ==
'tzserver') {
3907 $offsettzstring = @date_default_timezone_get();
3912 } elseif ($tzoutput ==
'tzuser' || $tzoutput ==
'tzuserrel') {
3915 $offsettzstring = (empty($_SESSION[
'dol_tz_string']) ?
getDolGlobalString(
'MAIN_DOLIBARR_USER_TIMEZONE',
'UTC') : $_SESSION[
'dol_tz_string']);
3917 if (class_exists(
'DateTimeZone')) {
3919 $user_date_tz =
new DateTimeZone($offsettzstring);
3922 dol_syslog(
"DateInvalidTimeZoneException for timezone string '".$offsettzstring.
"'. Falling back to UTC.", LOG_ERR);
3923 $user_date_tz =
new DateTimeZone(
'UTC');
3925 $user_dt =
new DateTime();
3926 $user_dt->setTimezone($user_date_tz);
3927 $user_dt->setTimestamp($tzoutput ==
'tzuser' ?
dol_now() : (int) $time);
3928 $offsettz = $user_dt->getOffset();
3930 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
3931 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
3936 if (!is_object($outputlangs)) {
3937 $outputlangs = $langs;
3940 $format =
'daytextshort';
3945 $reduceformat = (!empty(
$conf->dol_optimize_smallscreen) && in_array($format, array(
'day',
'dayhour',
'dayhoursec'))) ? 1 : 0;
3946 $format = preg_replace(
'/inputnoreduce/',
'', $format);
3947 $formatwithoutreduce = preg_replace(
'/reduceformat/',
'', $format);
3948 if ($formatwithoutreduce != $format) {
3949 $format = $formatwithoutreduce;
3955 if ($format ==
'day') {
3956 $format = ($outputlangs->trans(
"FormatDateShort") !=
"FormatDateShort" ? $outputlangs->trans(
"FormatDateShort") :
$conf->format_date_short);
3957 } elseif ($format ==
'hour') {
3958 $format = ($outputlangs->trans(
"FormatHourShort") !=
"FormatHourShort" ? $outputlangs->trans(
"FormatHourShort") :
$conf->format_hour_short);
3959 } elseif ($format ==
'hoursec') {
3960 $s1 = $outputlangs->trans(
"FormatDateShort");
3961 $s2 = $outputlangs->trans(
"FormatDateHourSecShort");
3962 $s3 = trim(preg_replace(
'/'.preg_quote($s1,
'/').
'/',
'', $s2));
3965 } elseif ($format ==
'hourduration') {
3966 $format = ($outputlangs->trans(
"FormatHourShortDuration") !=
"FormatHourShortDuration" ? $outputlangs->trans(
"FormatHourShortDuration") :
$conf->format_hour_short_duration);
3967 } elseif ($format ==
'daytext') {
3968 $format = ($outputlangs->trans(
"FormatDateText") !=
"FormatDateText" ? $outputlangs->trans(
"FormatDateText") :
$conf->format_date_text);
3969 } elseif ($format ==
'daytextshort') {
3970 $format = ($outputlangs->trans(
"FormatDateTextShort") !=
"FormatDateTextShort" ? $outputlangs->trans(
"FormatDateTextShort") :
$conf->format_date_text_short);
3971 } elseif ($format ==
'dayhour') {
3972 $format = ($outputlangs->trans(
"FormatDateHourShort") !=
"FormatDateHourShort" ? $outputlangs->trans(
"FormatDateHourShort") :
$conf->format_date_hour_short);
3973 } elseif ($format ==
'dayhoursec') {
3974 $format = ($outputlangs->trans(
"FormatDateHourSecShort") !=
"FormatDateHourSecShort" ? $outputlangs->trans(
"FormatDateHourSecShort") :
$conf->format_date_hour_sec_short);
3975 } elseif ($format ==
'dayhourtext') {
3976 $format = ($outputlangs->trans(
"FormatDateHourText") !=
"FormatDateHourText" ? $outputlangs->trans(
"FormatDateHourText") :
$conf->format_date_hour_text);
3977 } elseif ($format ==
'dayhourtextshort') {
3978 $format = ($outputlangs->trans(
"FormatDateHourTextShort") !=
"FormatDateHourTextShort" ? $outputlangs->trans(
"FormatDateHourTextShort") :
$conf->format_date_hour_text_short);
3979 } elseif ($format ==
'dayhourlog') {
3981 $format =
'%Y%m%d%H%M%S';
3982 } elseif ($format ==
'dayhourlogsmall') {
3984 $format =
'%y%m%d%H%M';
3985 } elseif ($format ==
'dayhourldap') {
3986 $format =
'%Y%m%d%H%M%SZ';
3987 } elseif ($format ==
'dayhourxcard') {
3988 $format =
'%Y%m%dT%H%M%SZ';
3989 } elseif ($format ==
'dayxcard') {
3991 } elseif ($format ==
'dayrfc') {
3992 $format =
'%Y-%m-%d';
3993 } elseif ($format ==
'dayhourrfc') {
3994 $format =
'%Y-%m-%dT%H:%M:%SZ';
3995 } elseif ($format ==
'standard') {
3996 $format =
'%Y-%m-%d %H:%M:%S';
3999 if ($reduceformat) {
4000 $format = str_replace(
'%Y',
'%y', $format);
4001 $format = str_replace(
'yyyy',
'yy', $format);
4005 if (preg_match(
'/%b/i', $format)) {
4007 $format = str_replace(
'%b',
'__b__', $format);
4008 $format = str_replace(
'%B',
'__B__', $format);
4010 if (preg_match(
'/%a/i', $format)) {
4012 $format = str_replace(
'%a',
'__a__', $format);
4013 $format = str_replace(
'%A',
'__A__', $format);
4018 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)) {
4021 } elseif (preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', (
string) $time, $reg)) {
4025 $syear = (!empty($reg[1]) ? $reg[1] :
'');
4026 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
4027 $sday = (!empty($reg[3]) ? $reg[3] :
'');
4028 $shour = (!empty($reg[4]) ? $reg[4] :
'');
4029 $smin = (!empty($reg[5]) ? $reg[5] :
'');
4030 $ssec = (!empty($reg[6]) ? $reg[6] :
'');
4032 $time =
dol_mktime((
int) $shour, (
int) $smin, (
int) $ssec, (
int) $smonth, (
int) $sday, (
int) $syear,
true);
4035 $tzo =
new DateTimeZone(
'UTC');
4037 $tzo =
new DateTimeZone(date_default_timezone_get());
4039 $dtts =
new DateTime();
4040 $dtts->setTimestamp($time);
4041 $dtts->setTimezone($tzo);
4042 $newformat = str_replace(
4043 array(
'%Y',
'%y',
'%m',
'%d',
'%H',
'%I',
'%M',
'%S',
'%p',
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
4044 array(
'Y',
'y',
'm',
'd',
'H',
'h',
'i',
's',
'A',
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
4047 $ret = $dtts->format($newformat);
4049 array(
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
4050 array(
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
4055 if ($time < 100000000000) {
4056 $dtts =
new DateTime();
4059 $timetouse = (int) $time + $offsettz + $offsetdst;
4061 $tzo =
new DateTimeZone(
'UTC');
4062 $dtts->setTimezone($tzo);
4063 $dtts->setTimestamp($timetouse);
4065 $timetouse = (int) $time + $offsettz + $offsetdst;
4067 $tzo =
new DateTimeZone(date_default_timezone_get());
4068 $dtts->setTimestamp($timetouse);
4069 $dtts->setTimezone($tzo);
4072 $newformat = str_replace(
4073 array(
'%Y',
'%y',
'%m',
'%d',
'%H',
'%I',
'%M',
'%S',
'%p',
'%w',
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
4074 array(
'Y',
'y',
'm',
'd',
'H',
'h',
'i',
's',
'A',
'w',
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
4078 $ret = $dtts->format($newformat);
4081 array(
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
4082 array(
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
4086 $ret =
'Bad value ' . $time .
' for date';
4090 if (preg_match(
'/__b__/i', $format)) {
4091 $timetouse = $time + $offsettz + $offsetdst;
4094 $tzo =
new DateTimeZone(
'UTC');
4096 $tzo =
new DateTimeZone(date_default_timezone_get());
4098 $dtts =
new DateTime();
4099 $dtts->setTimestamp($timetouse);
4100 $dtts->setTimezone($tzo);
4101 $month = (int) $dtts->format(
"m");
4102 $month = sprintf(
"%02d", $month);
4103 if ($encodetooutput) {
4104 $monthtext = $outputlangs->transnoentities(
'Month' . $month);
4105 $monthtextshort = $outputlangs->transnoentities(
'MonthShort' . $month);
4107 $monthtext = $outputlangs->transnoentitiesnoconv(
'Month' . $month);
4108 $monthtextshort = $outputlangs->transnoentitiesnoconv(
'MonthShort' . $month);
4111 $ret = str_replace(
'__b__', $monthtextshort, $ret);
4112 $ret = str_replace(
'__B__', $monthtext, $ret);
4116 if (preg_match(
'/__a__/i', $format)) {
4118 $timetouse = $time + $offsettz + $offsetdst;
4121 $tzo =
new DateTimeZone(
'UTC');
4123 $tzo =
new DateTimeZone(date_default_timezone_get());
4125 $dtts =
new DateTime();
4126 $dtts->setTimestamp($timetouse);
4127 $dtts->setTimezone($tzo);
4128 $w = $dtts->format(
"w");
4129 $dayweek = $outputlangs->transnoentitiesnoconv(
'Day' . $w);
4131 $ret = str_replace(
'__A__', $dayweek, $ret);
4132 $ret = str_replace(
'__a__',
dol_substr($dayweek, 0, 3), $ret);
4136 $ret = preg_replace(
'/(\d\d:\d\d [AP]M)$/',
'<span class="'.($decorate === 1 ?
'opacitymedium' : $decorate).
'">\1</span>', $ret);
4137 $ret = preg_replace(
'/(\d\d:\d\d)$/',
'<span class="'.($decorate === 1 ?
'opacitymedium' : $decorate).
'">\1</span>', $ret);
4164function dol_getdate($timestamp, $fast =
false, $forcetimezone =
'')
4166 if ($timestamp ===
'') {
4170 $datetimeobj =
new DateTime();
4171 $datetimeobj->setTimestamp($timestamp);
4172 if ($forcetimezone) {
4173 $datetimeobj->setTimezone(
new DateTimeZone($forcetimezone ==
'gmt' ?
'UTC' : $forcetimezone));
4176 'year' => ((
int) date_format($datetimeobj,
'Y')),
4177 'mon' => ((
int) date_format($datetimeobj,
'm')),
4178 'mday' => ((
int) date_format($datetimeobj,
'd')),
4179 'wday' => ((
int) date_format($datetimeobj,
'w')),
4180 'yday' => ((
int) date_format($datetimeobj,
'z')),
4181 'hours' => ((
int) date_format($datetimeobj,
'H')),
4182 'minutes' => ((
int) date_format($datetimeobj,
'i')),
4183 'seconds' => ((
int) date_format($datetimeobj,
's')),
4211function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm =
'auto', $check = 1)
4216 if ($gm ===
'auto') {
4217 $gm = (empty(
$conf) ?
'tzserver' :
$conf->tzuserinputkey);
4222 if ($hour == -1 || empty($hour)) {
4225 if ($minute == -1 || empty($minute)) {
4228 if ($second == -1 || empty($second)) {
4234 if (!$month || !$day) {
4243 if ($hour < 0 || $hour > 24) {
4246 if ($minute < 0 || $minute > 60) {
4249 if ($second < 0 || $second > 60) {
4254 if (empty($gm) || ($gm ===
'server' || $gm ===
'tzserver')) {
4255 $default_timezone = @date_default_timezone_get();
4256 $localtz =
new DateTimeZone($default_timezone);
4257 } elseif ($gm ===
'user' || $gm ===
'tzuser' || $gm ===
'tzuserrel') {
4259 $default_timezone = (empty($_SESSION[
"dol_tz_string"]) ? @date_default_timezone_get() : $_SESSION[
"dol_tz_string"]);
4261 $localtz =
new DateTimeZone($default_timezone);
4263 dol_syslog(
"Warning dol_tz_string contains an invalid value " . json_encode($_SESSION[
"dol_tz_string"] ??
null), LOG_WARNING);
4264 $default_timezone = @date_default_timezone_get();
4266 } elseif (strrpos($gm,
"tz,") !==
false) {
4267 $timezone = (
string) str_replace(
"tz,",
"", $gm);
4269 $localtz =
new DateTimeZone($timezone);
4271 dol_syslog(
"Warning passed timezone contains an invalid value " . $timezone, LOG_WARNING);
4275 if (empty($localtz)) {
4276 $localtz =
new DateTimeZone(
'UTC');
4278 $dt =
new DateTime(
'now', $localtz);
4279 $dt->setDate((
int) $year, (
int) $month, (
int) $day);
4280 $dt->setTime((
int) $hour, (
int) $minute, (
int) $second);
4281 $date = $dt->getTimestamp();
4297function dol_now($mode =
'gmt')
4301 if ($mode ===
'auto') {
4305 if ($mode ==
'gmt') {
4307 } elseif ($mode ==
'tzserver') {
4308 require_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
4310 $ret = (int) (
dol_now(
'gmt') + ($tzsecond * 3600));
4315 } elseif ($mode ==
'tzuser' || $mode ==
'tzuserrel') {
4318 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
4319 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
4320 $ret = (int) (
dol_now(
'gmt') + ($offsettz + $offsetdst));
4337 global
$conf, $langs;
4340 if (!empty(
$conf->dol_optimize_smallscreen)) {
4345 if (empty($shortvalue) || $size < ($level * 10)) {
4347 $textunitshort = $langs->trans(
"b");
4348 $textunitlong = $langs->trans(
"Bytes");
4350 $ret = round($size / $level, 0);
4351 $textunitshort = $langs->trans(
"Kb");
4352 $textunitlong = $langs->trans(
"KiloBytes");
4355 if (empty($shortunit)) {
4356 $ret .=
' ' . $textunitlong;
4358 $ret .=
' ' . $textunitshort;
4374function dol_print_url($url, $target =
'_blank', $max = 32, $withpicto = 0, $morecss =
'')
4382 $linkstart =
'<a href="';
4383 if (!preg_match(
'/^http/i', $url)) {
4384 $linkstart .=
'http://';
4389 $linkstart .=
' target="' . $target .
'"';
4391 $linkstart .=
' title="' . $langs->trans(
"URL") .
': ' . $url .
'"';
4395 if (!preg_match(
'/^http/i', $url)) {
4402 if ($morecss ==
'float') {
4403 return '<div class="nospan' . ($morecss ?
' ' . $morecss :
'') .
'" style="margin-right: 10px">' . ($withpicto ?
img_picto($langs->trans(
"Url"),
'globe',
'class="paddingrightonly"') :
'') . $link .
'</div>';
4405 return $linkstart .
'<span class="nospan' . ($morecss ?
' ' . $morecss :
'') .
'" style="margin-right: 10px">' . ($withpicto ?
img_picto(
'',
'globe',
'class="paddingrightonly"') :
'') . $link .
'</span>' . $linkend;
4422function dol_print_email($email, $contactid = 0, $socid = 0, $addlink = 0, $max = 0, $showinvalid = 1, $withpicto = 0, $morecss =
'paddingrightonly')
4424 global $user, $langs, $hookmanager;
4435 if (empty($email)) {
4439 if ($addlink == 1) {
4440 $newemail =
'<a class="' . ($morecss ? $morecss :
'') .
'" style="text-overflow: ellipsis;" href="';
4441 if (!preg_match(
'/^mailto:/i', $email)) {
4442 $newemail .=
'mailto:';
4444 $newemail .= $email;
4445 $newemail .=
'" target="_blank">';
4447 $newemail .= ($withpicto ?
img_picto($langs->trans(
"EMail") .
' : ' . $email, (is_numeric($withpicto) ?
'email' : $withpicto),
'class="paddingrightonly"') :
'');
4452 $newemail .= $email;
4454 $newemail .=
'</a>';
4457 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
4458 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
4461 $langs->load(
"errors");
4462 $newemail .=
img_warning($langs->transnoentitiesnoconv(
"ErrorBadEMail", $emailonly),
'',
'paddingrightonly');
4464 $langs->load(
"errors");
4465 $newemail .=
img_warning($langs->transnoentitiesnoconv(
"ErrorBadMXDomain", $emailonly),
'',
'paddingrightonly');
4469 if (($contactid || $socid) &&
isModEnabled(
'agenda') && $user->hasRight(
"agenda",
"myactions",
"create")) {
4471 $linktoaddaction =
'';
4473 $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>';
4475 if ($linktoaddaction) {
4476 $newemail =
'<div>' . $newemail .
' ' . $linktoaddaction .
'</div>';
4479 } elseif ($addlink ===
'thirdparty') {
4480 $tmpnewemail =
'<a class="' . ($morecss ? $morecss :
'') .
'" style="text-overflow: ellipsis;" href="' . DOL_URL_ROOT .
'/societe/card.php?socid=' . $socid .
'&action=presend&mode=init#formmailbeforetitle">';
4481 $tmpnewemail .= ($withpicto ?
img_picto($langs->trans(
"EMail") .
' : ' . $email, (is_numeric($withpicto) ?
'email' : $withpicto),
'class="paddingrightonly"') :
'');
4482 if ($withpicto == 1) {
4483 $tmpnewemail .= $newemail;
4485 $tmpnewemail .=
'</a>';
4487 $newemail = $tmpnewemail;
4489 $newemail = ($withpicto ?
img_picto($langs->trans(
"EMail") .
' : ' . $email, (is_numeric($withpicto) ?
'email' : $withpicto),
'class="paddingrightonly"') :
'') . $newemail;
4492 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
4493 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
4496 $langs->load(
"errors");
4497 $newemail .=
img_warning($langs->transnoentitiesnoconv(
"ErrorBadEMail", $email));
4499 $langs->load(
"errors");
4500 $newemail .=
img_warning($langs->transnoentitiesnoconv(
"ErrorBadMXDomain", $emailonly));
4510 $rep .= showValueWithClipboardCPButton($newemail, 0,
'none');
4514 $parameters = array(
'cid' => $contactid,
'socid' => $socid,
'addlink' => $addlink,
'picto' => $withpicto);
4516 $reshook = $hookmanager->executeHooks(
'printEmail', $parameters, $email);
4520 $rep .= $hookmanager->resPrint;
4542function dolOutputDates($datep, $datef =
null, $fullday = 0, $addseconds = 0, $pictotoadd =
'', $tzoutput =
'tzuserrel', $reduceformat = 0)
4545 if (empty($datef)) {
4553 if ($tmpa[
'mday'] == $tmpb[
'mday'] && $tmpa[
'mon'] == $tmpb[
'mon'] && $tmpa[
'year'] == $tmpb[
'year']) {
4555 $s .=
'<div class="center inline-block">';
4556 if ($tmpa[
'hours'] != $tmpb[
'hours'] || $tmpa[
'minutes'] != $tmpb[
'minutes']) {
4558 $s .=
dol_print_date($datep,
'day'.($reduceformat ?
'reduceformat' :
''), $tzoutput);
4560 if (empty($fullday)) {
4561 $s .=
'<br><span class="small opacitymedium">';
4562 $s .=
dol_print_date($datep,
'hour'.($addseconds ?
'sec' :
'').
'reduceformat', $tzoutput);
4563 $s .=
'-'.dol_print_date($datef,
'hour'.($addseconds ?
'sec' :
'').
'reduceformat', $tzoutput);
4568 $s .=
dol_print_date($datep,
'day'.($reduceformat ?
'reduceformat' :
''),
'tzuserrel');
4570 if (empty($fullday)) {
4571 $s .=
'<br><span class="small opacitymedium">';
4572 $s .=
dol_print_date($datep,
'hour'.($addseconds ?
'sec' :
'').
'reduceformat', $tzoutput);
4579 $s .=
'<div class="center inline-block dateborderright">';
4580 $s .=
dol_print_date($datep,
'day'.($reduceformat ?
'reduceformat' :
''), $tzoutput);
4581 if (empty($fullday)) {
4582 $s .=
'<br><span class="small opacitymedium">';
4583 $s .=
dol_print_date($datep,
'hour'.($addseconds ?
'sec' :
'').
'reduceformat', $tzoutput);
4587 $s .=
'<div class="center inline-block dateborderleft">';
4588 $s .=
dol_print_date($datef,
'day'.($reduceformat ?
'reduceformat' :
''),
'tzuserrel');
4590 if (empty($fullday)) {
4591 $s .=
'<br><span class="small opacitymedium">';
4592 $s .=
dol_print_date($datef,
'hour'.($addseconds ?
'sec' :
'').
'reduceformat', $tzoutput);
4611 $socialnetworks = array();
4613 require_once DOL_DOCUMENT_ROOT .
'/core/lib/memory.lib.php';
4617 if (!is_null($dataretrieved)) {
4618 $socialnetworks = $dataretrieved;
4620 $sql =
"SELECT rowid, code, label, url, icon, active FROM " . MAIN_DB_PREFIX .
"c_socialnetworks";
4621 $sql .=
" WHERE entity IN (" .
getEntity(
'c_socialnetworks').
")";
4623 $resql =
$db->query($sql);
4625 while ($obj =
$db->fetch_object($resql)) {
4626 $socialnetworks[$obj->code] = array(
4627 'rowid' => $obj->rowid,
4628 'label' => $obj->label,
4630 'icon' => $obj->icon,
4631 'active' => $obj->active,
4638 return (is_array($socialnetworks) ? $socialnetworks : array());
4653 global $hookmanager, $langs, $user;
4657 if (empty($value)) {
4661 if (!empty($type)) {
4662 $htmllink =
'<div class="divsocialnetwork inline-block valignmiddle">';
4664 $htmllink .=
'<span class="fab pictofixedwidth ' . ($dictsocialnetworks[$type][
'icon'] ? $dictsocialnetworks[$type][
'icon'] :
'fa-link') .
'"></span>';
4665 if ($type ==
'skype') {
4667 $htmllink .=
' <a href="skype:';
4669 $htmllink .=
'?call" alt="' . $langs->trans(
"Call") .
' ' . $value .
'" title="' .
dol_escape_htmltag($langs->trans(
"Call") .
' ' . $value) .
'">';
4670 $htmllink .=
'<img src="' . DOL_URL_ROOT .
'/theme/common/skype_callbutton.png" border="0">';
4671 $htmllink .=
'</a><a href="skype:';
4673 $htmllink .=
'?chat" alt="' . $langs->trans(
"Chat") .
' ' . $value .
'" title="' .
dol_escape_htmltag($langs->trans(
"Chat") .
' ' . $value) .
'">';
4674 $htmllink .=
'<img class="paddingleft" src="' . DOL_URL_ROOT .
'/theme/common/skype_chatbutton.png" border="0">';
4675 $htmllink .=
'</a>';
4676 if (($contactid || $socid) &&
isModEnabled(
'agenda') && $user->hasRight(
'agenda',
'myactions',
'create')) {
4677 $addlink =
'AC_SKYPE';
4680 $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>';
4682 $htmllink .= ($link ?
' ' . $link :
'');
4685 if (!empty($dictsocialnetworks[$type][
'url'])) {
4686 $tmpvirginurl = preg_replace(
'/\/?{socialid}/',
'', $dictsocialnetworks[$type][
'url']);
4687 if ($tmpvirginurl) {
4688 $value = preg_replace(
'/^www\.' . preg_quote($tmpvirginurl,
'/') .
'\/?/',
'', $value);
4689 $value = preg_replace(
'/^' . preg_quote($tmpvirginurl,
'/') .
'\/?/',
'', $value);
4691 $tmpvirginurl3 = preg_replace(
'/^https:\/\//i',
'https://www.', $tmpvirginurl);
4692 if ($tmpvirginurl3) {
4693 $value = preg_replace(
'/^www\.' . preg_quote($tmpvirginurl3,
'/') .
'\/?/',
'', $value);
4694 $value = preg_replace(
'/^' . preg_quote($tmpvirginurl3,
'/') .
'\/?/',
'', $value);
4697 $tmpvirginurl2 = preg_replace(
'/^https?:\/\//i',
'', $tmpvirginurl);
4698 if ($tmpvirginurl2) {
4699 $value = preg_replace(
'/^www\.' . preg_quote($tmpvirginurl2,
'/') .
'\/?/',
'', $value);
4700 $value = preg_replace(
'/^' . preg_quote($tmpvirginurl2,
'/') .
'\/?/',
'', $value);
4703 if (preg_match(
'/^https?:\/\//i', $value)) {
4706 $link = str_replace(
'{socialid}', $value, $dictsocialnetworks[$type][
'url']);
4708 $valuetoshow = $value;
4709 $valuetoshow = preg_replace(
'/https:\/\/www\.(twitter|x|linkedin)\.com\/?/',
'', $valuetoshow);
4710 if (preg_match(
'/^https?:\/\//i', $link)) {
4719 $htmllink .=
'</div>';
4721 $langs->load(
"errors");
4722 $htmllink .=
img_warning($langs->trans(
"ErrorBadSocialNetworkValue", $value));
4726 $parameters = array(
4728 'cid' => $contactid,
4731 'dictsocialnetworks' => $dictsocialnetworks,
4734 $reshook = $hookmanager->executeHooks(
'printSocialNetworks', $parameters);
4738 $htmllink .= $hookmanager->resPrint;
4753function dol_print_profids($profID, $profIDtype, $countrycode =
'', $addcpButton = 1)
4757 if (empty($profID) || empty($profIDtype)) {
4760 if (empty($countrycode)) {
4761 $countrycode =
$mysoc->country_code;
4763 $newProfID = $profID;
4764 $id = substr($profIDtype, -1);
4766 if (strtoupper($countrycode) ==
'FR') {
4772 $newProfID = substr($newProfID, 0, 3) .
' ' . substr($newProfID, 3, 3) .
' ' . substr($newProfID, 6, 3);
4776 $newProfID = substr($newProfID, 0, 3) .
' ' . substr($newProfID, 3, 3) .
' ' . substr($newProfID, 6, 3) .
' ' . substr($newProfID, 9, 5);
4780 $newProfID = substr($newProfID, 0, 2) .
'.' . substr($newProfID, 2, 3);
4782 if ($profIDtype ===
'VAT' &&
dol_strlen($newProfID) == 13) {
4784 $newProfID = substr($newProfID, 0, 4) .
' ' . substr($newProfID, 4, 3) .
' ' . substr($newProfID, 7, 3) .
' ' . substr($newProfID, 10, 3);
4787 if (!empty($addcpButton)) {
4788 $ret = showValueWithClipboardCPButton(
dol_escape_htmltag($profID), ($addcpButton == 1 ? 1 : 0), $newProfID);
4810function dol_print_phone($phone, $countrycode =
'', $contactid = 0, $socid = 0, $addlink =
'', $separ =
" ", $withpicto =
'', $titlealt =
'', $adddivfloat = 0, $morecss =
'paddingright')
4812 global
$conf, $user, $langs,
$mysoc, $hookmanager;
4815 $phone = is_null($phone) ?
'' : preg_replace(
"/[\s.-]/",
"", trim($phone));
4816 if (empty($phone)) {
4822 if (empty($countrycode) && is_object(
$mysoc)) {
4823 $countrycode =
$mysoc->country_code;
4827 if (!empty(
$conf->dol_optimize_smallscreen) && $separ !=
'hidenum') {
4832 $newphonewa = $phone;
4833 if (strtoupper($countrycode) ==
"FR") {
4836 $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);
4838 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 2) . $separ . substr($newphone, 5, 2);
4840 $newphone = substr($newphone, 0, 2) . $separ . substr($newphone, 2, 3) . $separ . substr($newphone, 5, 2) . $separ . substr($newphone, 7, 2);
4842 $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);
4844 $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);
4846 $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);
4848 } elseif (strtoupper($countrycode) ==
"CA") {
4850 $newphone = ($separ !=
'' ?
'(' :
'') . substr($newphone, 0, 3) . ($separ !=
'' ?
')' :
'') . $separ . substr($newphone, 3, 3) . ($separ !=
'' ?
'-' :
'') . substr($newphone, 6, 4);
4852 } elseif (strtoupper($countrycode) ==
"PT") {
4854 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
4856 } elseif (strtoupper($countrycode) ==
"SR") {
4858 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3);
4860 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 4);
4862 } elseif (strtoupper($countrycode) ==
"DE") {
4864 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4) . $separ . substr($newphone, 7, 4) . $separ . substr($newphone, 11, 3);
4866 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 4) . $separ . substr($newphone, 10, 3);
4868 } elseif (strtoupper($countrycode) ==
"ES") {
4870 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
4872 } elseif (strtoupper($countrycode) ==
"BF") {
4874 $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);
4876 } elseif (strtoupper($countrycode) ==
"RO") {
4878 $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);
4880 } elseif (strtoupper($countrycode) ==
"TR") {
4882 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 4);
4884 } elseif (strtoupper($countrycode) ==
"US") {
4886 $newphone = substr($newphone, 0, 2) . $separ . substr($newphone, 2, 3) . $separ . substr($newphone, 5, 3) . $separ . substr($newphone, 8, 4);
4888 } elseif (strtoupper($countrycode) ==
"MX") {
4890 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 2);
4892 $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);
4894 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 4);
4896 } elseif (strtoupper($countrycode) ==
"ML") {
4898 $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);
4900 } elseif (strtoupper($countrycode) ==
"TH") {
4902 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 3);
4904 $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);
4906 } elseif (strtoupper($countrycode) ==
"MU") {
4909 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 2) . $separ . substr($newphone, 9, 2);
4911 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 4) . $separ . substr($newphone, 8, 2) . $separ . substr($newphone, 10, 2);
4913 } elseif (strtoupper($countrycode) ==
"ZA") {
4915 $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);
4917 } elseif (strtoupper($countrycode) ==
"SY") {
4919 $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);
4921 $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);
4923 } elseif (strtoupper($countrycode) ==
"AE") {
4925 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 2);
4927 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
4929 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 4);
4931 } elseif (strtoupper($countrycode) ==
"DZ") {
4933 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
4935 } elseif (strtoupper($countrycode) ==
"BE") {
4937 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 3);
4939 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
4941 } elseif (strtoupper($countrycode) ==
"PF") {
4943 $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);
4945 } elseif (strtoupper($countrycode) ==
"CO") {
4947 $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);
4949 } elseif (strtoupper($countrycode) ==
"JO") {
4951 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 1) . $separ . substr($newphone, 5, 3) . $separ . substr($newphone, 7, 2) . $separ . substr($newphone, 9, 2);
4953 } elseif (strtoupper($countrycode) ==
"JM") {
4955 $newphone = substr($newphone, 0, 5) . $separ . substr($newphone, 5, 3) . $separ . substr($newphone, 8, 4);
4957 } elseif (strtoupper($countrycode) ==
"MG") {
4959 $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);
4961 } elseif (strtoupper($countrycode) ==
"GB") {
4963 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
4965 } elseif (strtoupper($countrycode) ==
"CH") {
4967 $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);
4969 $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);
4971 } elseif (strtoupper($countrycode) ==
"TN") {
4973 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 2) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
4975 } elseif (strtoupper($countrycode) ==
"GF") {
4977 $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);
4979 } elseif (strtoupper($countrycode) ==
"GP") {
4981 $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);
4983 } elseif (strtoupper($countrycode) ==
"MQ") {
4985 $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);
4987 } elseif (strtoupper($countrycode) ==
"IT") {
4989 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
4991 $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);
4993 } elseif (strtoupper($countrycode) ==
"AU") {
4997 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 1) . $separ . substr($newphone, 4, 4) . $separ . substr($newphone, 8, 4);
4999 } elseif (strtoupper($countrycode) ==
"LU") {
5002 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 2) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 2);
5004 $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);
5006 $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);
5008 $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);
5010 } elseif (strtoupper($countrycode) ==
"PE") {
5013 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4);
5015 $newphonewa =
'+51' . $newphone;
5016 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 10, 3);
5018 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 8, 4);
5020 $newphonewa = $newphone;
5021 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 10, 3) . $separ . substr($newphone, 14, 3);
5023 } elseif (strtoupper($countrycode) ==
"IN") {
5025 if ($withpicto ==
'phone') {
5026 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 2) . $separ . substr($newphone, 5, 4) . $separ . substr($newphone, 9, 4);
5028 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 5) . $separ . substr($newphone, 8, 5);
5033 $newphoneastart = $newphoneaend =
'';
5034 if (!empty($addlink)) {
5036 $newphoneastart =
'<a href="tel:' . urlencode($phone) .
'">';
5037 $newphoneaend .=
'</a>';
5038 } elseif (
isModEnabled(
'clicktodial') && $addlink ==
'AC_TEL') {
5039 if (empty($user->clicktodial_loaded)) {
5040 $user->fetch_clicktodial();
5044 $urlmask =
getDolGlobalString(
'CLICKTODIAL_URL',
'ErrorClickToDialModuleNotConfigured');
5045 if (!empty($user->clicktodial_url)) {
5046 $urlmask = $user->clicktodial_url;
5049 $clicktodial_poste = (!empty($user->clicktodial_poste) ? urlencode($user->clicktodial_poste) :
'');
5050 $clicktodial_login = (!empty($user->clicktodial_login) ? urlencode($user->clicktodial_login) :
'');
5051 $clicktodial_password = (!empty($user->clicktodial_password) ? urlencode($user->clicktodial_password) :
'');
5053 $url = sprintf($urlmask, urlencode($phone), $clicktodial_poste, $clicktodial_login, $clicktodial_password);
5055 $substitarray = array(
5056 '__PHONEFROM__' => $clicktodial_poste,
5057 '__PHONETO__' => urlencode($phone),
5058 '__LOGIN__' => $clicktodial_login,
5059 '__PASS__' => $clicktodial_password
5064 $newphoneastart =
'<a href="' . $url .
'" class="cssforclicktodial">';
5065 $newphoneaend =
'</a>';
5068 $newphoneastart =
'<a href="' . $url .
'"';
5070 $newphoneastart .=
' target="_blank" rel="noopener noreferrer"';
5072 $newphoneastart .=
'>';
5073 $newphoneaend .=
'</a>';
5078 if (
isModEnabled(
'agenda') && $user->hasRight(
"agenda",
"myactions",
"create")) {
5080 $addlinktoagenda =
'';
5081 if ($addlink ==
'AC_FAX') {
5085 $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>';
5087 if ($addlinktoagenda) {
5088 $newphone =
'<span>' . $newphone .
' ' . $addlinktoagenda .
'</span>';
5093 if (
getDolGlobalString(
'CONTACT_PHONEMOBILE_SHOW_LINK_TO_WHATSAPP') && $withpicto ==
'mobile') {
5095 $newphone .=
' <a href="https://wa.me/' . $newphonewa .
'" target="_blank"';
5096 $newphone .=
'><span class="paddingright fab fa-whatsapp" style="color:#25D366;" title="WhatsApp"></span></a>';
5099 if (empty($titlealt)) {
5100 $titlealt = ($withpicto ==
'fax' ? $langs->trans(
"Fax") : $langs->trans(
"Phone"));
5105 $parameters = array(
'countrycode' => $countrycode,
'cid' => $contactid,
'socid' => $socid,
'titlealt' => $titlealt,
'picto' => $withpicto);
5106 $reshook = $hookmanager->executeHooks(
'printPhone', $parameters, $phone);
5107 $rep .= $hookmanager->resPrint;
5109 if (empty($reshook)) {
5112 if ($withpicto ==
'fax') {
5113 $picto =
'phoning_fax';
5114 } elseif ($withpicto ==
'phone') {
5116 } elseif ($withpicto ==
'mobile') {
5117 $picto =
'phoning_mobile';
5122 if ($adddivfloat == 1) {
5123 $rep .=
'<div class="nospan float' . ($morecss ?
' ' . $morecss :
'') .
'">';
5124 } elseif (empty($adddivfloat)) {
5125 $rep .=
'<span' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
'>';
5128 $rep .= $newphoneastart;
5129 $rep .= ($withpicto ?
img_picto($titlealt, $picto) :
'');
5130 if ($separ !=
'hidenum') {
5131 $rep .= ($withpicto ?
' ' :
'') . $newphone;
5133 $rep .= $newphoneaend;
5135 if ($adddivfloat == 1) {
5137 } elseif (empty($adddivfloat)) {
5158 if (!isset(
$conf->cache[
'resolveips'])) {
5159 $conf->cache[
'resolveips'] = array();
5165 if (file_exists(DOL_DOCUMENT_ROOT .
'/theme/common/flags/' . $countrycode .
'.png')) {
5168 $ret .=
'(' . $countrycode .
')';
5176 if (in_array($mode, [0, 2])) {
5179 if (!array_key_exists($ip,
$conf->cache[
'resolveips'])) {
5180 $domain = gethostbyaddr($ip);
5181 $conf->cache[
'resolveips'][$ip] = $domain;
5183 $domain =
$conf->cache[
'resolveips'][$ip];
5211 $ip = (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']);
5218 if (empty($_SERVER[
'HTTP_X_FORWARDED_FOR']) || preg_match(
'/[^0-9\.\:,\[\]\s]/', $_SERVER[
'HTTP_X_FORWARDED_FOR'])) {
5219 if (empty($_SERVER[
'HTTP_CLIENT_IP']) || preg_match(
'/[^0-9\.\:,\[\]\s]/', $_SERVER[
'HTTP_CLIENT_IP'])) {
5220 if (empty($_SERVER[
"HTTP_CF_CONNECTING_IP"])) {
5221 $ip = (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']);
5223 $ip = $_SERVER[
"HTTP_CF_CONNECTING_IP"];
5226 $ip = preg_replace(
'/,.*$/',
'', $_SERVER[
'HTTP_CLIENT_IP']);
5229 $ip = preg_replace(
'/,.*$/',
'', $_SERVER[
'HTTP_X_FORWARDED_FOR']);
5249 $datafile = $diroffile .
'/' .
getDolGlobalString(
'GEOIPMAXMIND_COUNTRY_DATAFILE_EMBEDDED');
5255 include_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeoip.class.php';
5256 $geoip =
new DolGeoIP(
'country', $datafile);
5258 $countrycode = $geoip->getCountryCodeFromIP($ip);
5265 return $countrycode;
5277 global
$conf, $langs, $user;
5286 include_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeoip.class.php';
5287 $geoip =
new DolGeoIP(
'country', $datafile);
5288 $countrycode = $geoip->getCountryCodeFromIP($ip);
5289 $ret = $countrycode;
5308 global $hookmanager;
5314 $parameters = array(
'element' => $element,
'id' =>
$id);
5315 $reshook = $hookmanager->executeHooks(
'printAddress', $parameters, $address);
5316 $out .= $hookmanager->resPrint;
5318 if (empty($reshook)) {
5319 if (empty($charfornl)) {
5320 $out .= nl2br((
string) $address);
5322 $out .= preg_replace(
'/[\r\n]+/', $charfornl, (
string) $address);
5326 $showgmap = $showomap = 0;
5352 $url =
dol_buildpath(
'/google/gmaps.php?mode=' . $element .
'&id=' .
$id, 1);
5353 $out .=
' <a href="' . $url .
'" target="_gmaps"><img id="' . $htmlid .
'" class="valigntextbottom" src="' . DOL_URL_ROOT .
'/theme/common/gmap.png"></a>';
5356 $url =
dol_buildpath(
'/openstreetmap/maps.php?mode=' . $element .
'&id=' .
$id, 1);
5357 $out .=
' <a href="' . $url .
'" target="_gmaps"><img id="' . $htmlid .
'_openstreetmap" class="valigntextbottom" src="' . DOL_URL_ROOT .
'/theme/common/gmap.png"></a>';
5379function isValidEmail($address, $acceptsupervisorkey = 0, $acceptuserkey = 0)
5381 if ($acceptsupervisorkey && $address ==
'__SUPERVISOREMAIL__') {
5384 if ($acceptuserkey && $address ==
'__USER_EMAIL__') {
5387 if (filter_var($address, FILTER_VALIDATE_EMAIL)) {
5405 if (function_exists(
'idn_to_ascii') && function_exists(
'checkdnsrr')) {
5406 if (!checkdnsrr(idn_to_ascii($domain),
'MX')) {
5409 if (function_exists(
'getmxrr')) {
5412 getmxrr(idn_to_ascii($domain), $mxhosts, $weight);
5413 if (count($mxhosts) > 1) {
5416 if (count($mxhosts) == 1 && !in_array((
string) $mxhosts[0], array(
'',
'.'))) {
5453 $tmparray = explode(
' ', $s);
5454 foreach ($tmparray as $tmps) {
5469function dol_strlen($string, $stringencoding =
'UTF-8')
5471 if (is_null($string)) {
5475 if (function_exists(
'mb_strlen')) {
5476 return mb_strlen($string, $stringencoding);
5478 return strlen($string);
5492function dol_substr($string, $start, $length =
null, $stringencoding =
'', $trunconbytes = 0)
5496 if (empty($stringencoding)) {
5497 $stringencoding = (empty($langs) ?
'UTF-8' : $langs->charset_output);
5501 if (empty($trunconbytes)) {
5502 if (function_exists(
'mb_substr')) {
5503 $ret = mb_substr($string, $start, $length, $stringencoding);
5505 $ret = substr($string, $start, $length);
5508 if (function_exists(
'mb_strcut')) {
5509 $ret = mb_strcut($string, $start, $length, $stringencoding);
5511 $ret = substr($string, $start, $length);
5531function dol_trunc($string, $size = 40, $trunc =
'right', $stringencoding =
'UTF-8', $nodot = 0, $display = 0)
5539 if (empty($stringencoding)) {
5540 $stringencoding =
'UTF-8';
5543 if (!empty(
$conf->dol_optimize_smallscreen) &&
$conf->dol_optimize_smallscreen == 1 && $display == 1) {
5544 $size = round($size / 3);
5548 if ($trunc ==
'right') {
5550 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
5552 return dol_substr($newstring, 0, $size, $stringencoding) . ($nodot ?
'' :
'…');
5557 } elseif ($trunc ==
'middle') {
5559 if (
dol_strlen($newstring, $stringencoding) > 2 &&
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
5560 $size1 = (int) round($size / 2);
5561 $size2 = (int) round($size / 2);
5562 return dol_substr($newstring, 0, $size1, $stringencoding) .
'…' .
dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size2, $size2, $stringencoding);
5566 } elseif ($trunc ==
'left') {
5568 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
5570 return '…' .
dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size, $size, $stringencoding);
5574 } elseif ($trunc ==
'wrap') {
5576 if (
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
5582 return 'BadParam3CallingDolTrunc';
5596 $type2picto = array(
5597 'varchar' =>
'font',
5600 'int' =>
'sort-numeric-down',
5601 'double' =>
'sort-numeric-down',
5602 'price' =>
'currency',
5603 'pricecy' =>
'multicurrency',
5604 'password' =>
'key',
5605 'boolean' =>
'check-square',
5606 'date' =>
'calendar',
5607 'datetime' =>
'calendar',
5608 'duration' =>
'hourglass',
5614 'sellist' =>
'list',
5615 'stars' =>
'fontawesome_star_fas',
5616 'radio' =>
'check-circle',
5617 'checkbox' =>
'list',
5618 'chkbxlst' =>
'list',
5620 'icon' =>
"question",
5621 'point' =>
"country",
5622 'multipts' =>
'country',
5623 'linestrg' =>
"country",
5624 'polygon' =>
"country",
5625 'separate' =>
'minus'
5628 if (!empty($type2picto[$key])) {
5629 return img_picto(
'', $type2picto[$key],
'class="pictofixedwidth' . ($morecss ?
' ' . $morecss :
'') .
'"');
5632 return img_picto(
'',
'generic',
'class="pictofixedwidth' . ($morecss ?
' ' . $morecss :
'') .
'"');
5659function img_picto($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $srconly = 0, $notitle = 0, $alt =
'', $morecss =
'', $marginleftonlyshort = 2, $allowothertags = array())
5664 $url = DOL_URL_ROOT;
5665 $theme = isset(
$conf->theme) ?
$conf->theme :
null;
5666 $path =
'theme/' . $theme;
5667 if (empty($picto)) {
5672 if ($pictoisfullpath) {
5674 if (!preg_match(
'/(\.png|\.gif|\.svg)$/i', $picto)) {
5677 $fullpathpicto = $picto;
5679 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
5680 $morecss .= ($morecss ?
' ' :
'') . $reg[1];
5681 $moreatt = str_replace(
'class="' . $reg[1] .
'"',
'', $moreatt);
5686 $pictowithouttext = preg_replace(
'/(\.png|\.gif|\.svg)$/',
'', $picto);
5687 $pictowithouttext = str_replace(
'object_',
'', $pictowithouttext);
5688 $pictowithouttext = str_replace(
'_nocolor',
'', $pictowithouttext);
5691 $pictoconvertkey = array(
5692 'facture' =>
'bill',
5693 'shipping' =>
'shipment',
5694 'fichinter' =>
'intervention',
5695 'agenda' =>
'calendar',
5696 'invoice_supplier' =>
'supplier_invoice',
5697 'order_supplier' =>
'supplier_order');
5698 if (in_array($pictowithouttext, array_keys($pictoconvertkey))) {
5699 $pictowithouttext = $pictoconvertkey[$pictowithouttext];
5702 if (strpos($pictowithouttext,
'fontawesome_') === 0 || strpos($pictowithouttext,
'fa-') === 0) {
5704 $pictowithouttext = str_replace(
'fontawesome_',
'', $pictowithouttext);
5705 $pictowithouttext = str_replace(
'fa-',
'', $pictowithouttext);
5708 if ($pictowithouttext ==
'file-o') {
5709 $pictowithouttext =
'file';
5712 $pictowithouttextarray = explode(
'_', $pictowithouttext);
5713 $marginleftonlyshort = 0;
5715 if (!empty($pictowithouttextarray[1])) {
5717 $fakey =
'fa-' . $pictowithouttextarray[0];
5718 $faprefix = empty($pictowithouttextarray[1]) ?
'fas' : $pictowithouttextarray[1];
5719 $facolor = empty($pictowithouttextarray[2]) ?
'' : $pictowithouttextarray[2];
5720 $fasize = empty($pictowithouttextarray[3]) ?
'' : $pictowithouttextarray[3];
5722 $fakey =
'fa-' . $pictowithouttext;
5732 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
5733 $morecss .= ($morecss ?
' ' :
'') . $reg[1];
5734 $moreatt = str_replace(
'class="' . $reg[1] .
'"',
'', $moreatt);
5736 if (preg_match(
'/style="([^"]+)"/', $moreatt, $reg)) {
5737 $morestyle = $reg[1];
5738 $moreatt = str_replace(
'style="' . $reg[1] .
'"',
'', $moreatt);
5740 $moreatt = trim($moreatt);
5742 $enabledisablehtml =
'<span class="' . $faprefix .
' ' . $fakey . ($marginleftonlyshort ? ($marginleftonlyshort == 1 ?
' marginleftonlyshort' :
' marginleftonly') :
'');
5743 $enabledisablehtml .= ($morecss ?
' ' . $morecss :
'') .
'" style="' . ($fasize ? (
'font-size: ' . $fasize .
';') :
'') . ($facolor ? (
' color: ' . $facolor .
';') :
'') . ($morestyle ?
' ' . $morestyle :
'') .
'"' . (($notitle || empty($titlealt)) ?
'' :
' title="' .
dol_escape_htmltag($titlealt) .
'"') . ($moreatt ?
' ' . $moreatt :
'') .
'>';
5744 $enabledisablehtml .=
'</span>';
5746 return $enabledisablehtml;
5749 if (empty($srconly) && !preg_match(
'/[\.\/@]/', $picto)) {
5750 $fakey = $pictowithouttext;
5754 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'))) {
5757 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'))) {
5763 if ($pictowithouttext ==
'off') {
5764 $fakey =
'fa-square';
5766 } elseif ($pictowithouttext ==
'on') {
5767 $fakey =
'fa-check-square';
5769 } elseif ($pictowithouttext ==
'listlight') {
5770 $fakey =
'fa-download';
5771 $marginleftonlyshort = 1;
5772 } elseif ($pictowithouttext ==
'printer') {
5773 $fakey =
'fa-print';
5775 } elseif ($pictowithouttext ==
'note') {
5776 $fakey =
'fa-sticky-note';
5777 $marginleftonlyshort = 1;
5778 } elseif (in_array($pictowithouttext, array(
'1uparrow',
'1downarrow',
'1leftarrow',
'1rightarrow',
'1uparrow_selected',
'1downarrow_selected',
'1leftarrow_selected',
'1rightarrow_selected'))) {
5779 $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');
5780 $fakey =
'fa-' . $convertarray[$pictowithouttext];
5781 if (preg_match(
'/selected/', $pictowithouttext)) {
5784 $marginleftonlyshort = 1;
5785 } elseif (!empty($arrayconvpictotofa[$pictowithouttext])) {
5786 $fakey =
'fa-' . $arrayconvpictotofa[$pictowithouttext];
5788 $fakey =
'fa-' . $pictowithouttext;
5791 if (in_array($pictowithouttext, array(
'dollyrevert',
'member',
'members',
'contract',
'group',
'resource',
'shipment',
'reception'))) {
5792 $morecss .=
' em092';
5794 if (in_array($pictowithouttext, array(
'conferenceorbooth',
'eventorganization',
'holiday',
'info',
'info_black',
'project',
'workstation'))) {
5795 $morecss .=
' em088';
5797 if (in_array($pictowithouttext, array(
'asset',
'intervention',
'payment',
'loan',
'partnership',
'stock',
'technic'))) {
5798 $morecss .=
' em080';
5802 $arrayconvpictotomarginleftonly = array(
5832 '1uparrow_selected',
5833 '1downarrow_selected',
5834 '1leftarrow_selected',
5835 '1rightarrow_selected'
5837 if (!array_key_exists($pictowithouttext, $arrayconvpictotomarginleftonly)) {
5838 $marginleftonlyshort = 0;
5842 $arrayconvpictotomorcess = array(
5843 'action' =>
'infobox-action',
5844 'account' =>
'infobox-bank_account',
5845 'accounting_account' =>
'infobox-bank_account',
5846 'accountline' =>
'infobox-bank_account',
5847 'accountancy' =>
'infobox-bank_account',
5848 'admin' =>
'opacitymedium',
5849 'asset' =>
'infobox-bank_account',
5850 'bank_account' =>
'infobox-bank_account',
5851 'bill' =>
'infobox-commande',
5852 'billa' =>
'infobox-commande',
5853 'billr' =>
'infobox-commande',
5854 'billd' =>
'infobox-commande',
5855 'bookcal' =>
'infobox-portal',
5856 'margin' =>
'infobox-bank_account',
5857 'conferenceorbooth' =>
'infobox-project',
5858 'cash-register' =>
'infobox-portal',
5859 'contract' =>
'infobox-contrat',
5860 'check' =>
'font-status4',
5861 'conversation' =>
'infobox-contrat',
5862 'donation' =>
'infobox-commande',
5863 'dolly' =>
'infobox-commande',
5864 'dollyrevert' =>
'flip infobox-order_supplier',
5865 'ecm' =>
'infobox-action',
5866 'eventorganization' =>
'infobox-project',
5867 'hrm' =>
'infobox-adherent',
5868 'group' =>
'infobox-adherent',
5869 'intervention' =>
'infobox-contrat',
5870 'incoterm' =>
'infobox-supplier_proposal',
5871 'intracommreport' =>
'infobox-bank_account',
5872 'currency' =>
'infobox-bank_account',
5873 'multicurrency' =>
'infobox-bank_account',
5874 'members' =>
'infobox-adherent',
5875 'member' =>
'infobox-adherent',
5876 'money-bill-alt' =>
'infobox-bank_account',
5877 'order' =>
'infobox-commande',
5878 'user' =>
'infobox-adherent',
5879 'users' =>
'infobox-adherent',
5880 'error' =>
'pictoerror',
5881 'warning' =>
'pictowarning',
5882 'switch_on' =>
'font-status4',
5883 'switch_on_warning' =>
'font-status4 warning',
5884 'switch_on_red' =>
'font-status8',
5885 'switch_off_warning' =>
'font-status4 warning',
5886 'switch_off_red' =>
'font-status8',
5887 'holiday' =>
'infobox-holiday',
5888 'info' =>
'opacityhigh',
5889 'info_black' =>
'purple',
5890 'invoice' =>
'infobox-commande',
5891 'knowledgemanagement' =>
'infobox-contrat rotate90',
5892 'loan' =>
'infobox-commande',
5893 'payment' =>
'infobox-bank_account',
5894 'payment_vat' =>
'infobox-bank_account',
5895 'poll' =>
'infobox-portal',
5896 'pos' =>
'infobox-bank_account',
5897 'project' =>
'infobox-project',
5898 'projecttask' =>
'infobox-project',
5899 'propal' =>
'infobox-propal',
5900 'proposal' =>
'infobox-propal',
5901 'private' =>
'infobox-project',
5902 'reception' =>
'flip infobox-order_supplier',
5903 'recruitmentjobposition' =>
'infobox-adherent',
5904 'recruitmentcandidature' =>
'infobox-adherent',
5905 'resource' =>
'infobox-action',
5906 'salary' =>
'infobox-commande',
5907 'shapes' =>
'infobox-adherent',
5908 'shipment' =>
'infobox-commande',
5909 'store' =>
'infobox-portal',
5910 'stripe' =>
'infobox-bank_account',
5911 'supplier_invoice' =>
'infobox-order_supplier',
5912 'supplier_invoicea' =>
'infobox-order_supplier',
5913 'supplier_invoiced' =>
'infobox-order_supplier',
5914 'supplier_invoicer' =>
'infobox-order_supplier',
5915 'supplier' =>
'infobox-order_supplier',
5916 'supplier_order' =>
'infobox-order_supplier',
5917 'supplier_proposal' =>
'infobox-supplier_proposal',
5918 'ticket' =>
'infobox-contrat',
5919 'title_accountancy' =>
'infobox-bank_account',
5920 'title_hrm' =>
'infobox-holiday',
5921 'expensereport' =>
'infobox-expensereport',
5922 'trip' =>
'infobox-expensereport',
5923 'title_agenda' =>
'infobox-action',
5924 'vat' =>
'infobox-bank_account',
5925 'webportal' =>
'infobox-portal',
5926 'website' =>
'infobox-portal',
5928 'list-alt' =>
'imgforviewmode',
5929 'calendar' =>
'imgforviewmode',
5930 'calendarweek' =>
'imgforviewmode',
5931 'calendarmonth' =>
'imgforviewmode',
5932 'calendarday' =>
'imgforviewmode',
5933 'calendarperuser' =>
'imgforviewmode',
5934 'calendarpertype' =>
'imgforviewmode'
5936 if (!empty($arrayconvpictotomorcess[$pictowithouttext]) && strpos($picto,
'_nocolor') ===
false) {
5937 $morecss .= ($morecss ?
' ' :
'') . $arrayconvpictotomorcess[$pictowithouttext];
5941 $arrayconvpictotocolor = array(
5942 'address' =>
'#6c6aa8',
5943 'building' =>
'#6c6aa8',
5947 'companies' =>
'#6c6aa8',
5948 'company' =>
'#6c6aa8',
5949 'contact' =>
'#6c6aa8',
5951 'dynamicprice' =>
'#a69944',
5956 'listlight' =>
'#999',
5957 'language' =>
'#555',
5961 'map-marker-alt' =>
'#aaa',
5963 'product' =>
'#a69944',
5964 'service' =>
'#a69944',
5965 'inventory' =>
'#a69944',
5966 'stock' =>
'#a69944',
5967 'movement' =>
'#a69944',
5969 'world' =>
'#986c6a',
5970 'partnership' =>
'#6c6aa8',
5971 'playdisabled' =>
'#ccc',
5972 'printer' =>
'#444',
5973 'projectpub' =>
'#986c6a',
5977 'search-plus' =>
'#808080',
5978 'security' =>
'#999',
5980 'stop-circle' =>
'#888',
5982 'superadmin' =>
'#600',
5983 'switch_off' =>
'#999',
5984 'technic' =>
'#999',
5986 'timespent' =>
'#555',
5987 'uncheck' =>
'#800',
5988 'uparrow' =>
'#555',
5989 'user-cog' =>
'#999',
5990 'country' =>
'#aaa',
5991 'globe-americas' =>
'#aaa',
5995 'workstation' =>
'#a69944'
5997 if (isset($arrayconvpictotocolor[$pictowithouttext]) && strpos($picto,
'_nocolor') ===
false) {
5998 $facolor = $arrayconvpictotocolor[$pictowithouttext];
6005 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
6006 $morecss .= ($morecss ?
' ' :
'') . $reg[1];
6007 $moreatt = str_replace(
'class="' . $reg[1] .
'"',
'', $moreatt);
6009 if (preg_match(
'/style="([^"]+)"/', $moreatt, $reg)) {
6010 $morestyle = $reg[1];
6011 $moreatt = str_replace(
'style="' . $reg[1] .
'"',
'', $moreatt);
6013 $moreatt = trim($moreatt);
6015 $enabledisablehtml =
'<span class="' . $fa .
' ' . $fakey . ($marginleftonlyshort ? ($marginleftonlyshort == 1 ?
' marginleftonlyshort' :
' marginleftonly') :
'');
6016 $enabledisablehtml .= ($morecss ?
' ' . $morecss :
'') .
'" style="' . ($fasize ? (
'font-size: ' . $fasize .
';') :
'') . ($facolor ? (
' color: ' . $facolor .
';') :
'') . ($morestyle ?
' ' . $morestyle :
'') .
'"' . (($notitle || empty($titlealt)) ?
'' :
' title="' .
dol_escape_htmltag($titlealt) .
'"') . ($moreatt ?
' ' . $moreatt :
'') .
'>';
6017 $enabledisablehtml .=
'</span>';
6019 return $enabledisablehtml;
6026 } elseif (!empty(
$conf->modules_parts[
'theme']) && array_key_exists($theme,
$conf->modules_parts[
'theme'])) {
6027 $path = $theme .
'/theme/' . $theme;
6032 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $picto, $regs)) {
6038 if (!preg_match(
'/(\.png|\.gif|\.svg)$/i', $picto)) {
6043 foreach (
$conf->file->dol_document_root as $type => $dirroot) {
6044 if ($type ==
'main') {
6048 if (file_exists($dirroot .
'/' . $path .
'/img/' . $picto) && !empty(
$conf->file->dol_url_root)) {
6049 $url = DOL_URL_ROOT .
$conf->file->dol_url_root[$type];
6055 $fullpathpicto = $url .
'/' . $path .
'/img/' . $picto;
6059 return $fullpathpicto;
6063 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 :
'') .
'"') .
'>';
6077 if (empty($mode) || $mode ==
'fa') {
6079 $arrayconvpictotofa = array(
6080 'account' =>
'university',
6081 'accounting_account' =>
'clipboard-list',
6082 'accountline' =>
'receipt',
6083 'accountancy' =>
'search-dollar',
6084 'action' =>
'calendar-alt',
6085 'add' =>
'plus-circle',
6086 'address' =>
'address-book',
6089 'asset' =>
'money-check-alt',
6090 'autofill' =>
'fill',
6091 'back' =>
'arrow-left',
6092 'bank_account' =>
'university',
6093 'bill' =>
'file-invoice-dollar',
6094 'billa' =>
'file-excel',
6095 'billr' =>
'file-invoice-dollar',
6096 'billd' =>
'file-medical',
6097 'blockedlog' =>
'file-archive',
6098 'bookcal' =>
'calendar-check',
6099 'supplier_invoice' =>
'file-invoice-dollar',
6100 'supplier_invoicea' =>
'file-excel',
6101 'supplier_invoicer' =>
'file-invoice-dollar',
6102 'supplier_invoiced' =>
'file-medical',
6104 'card' =>
'address-card',
6105 'chart' =>
'chart-line',
6106 'company' =>
'building',
6107 'contact' =>
'address-book',
6108 'contract' =>
'suitcase',
6109 'collab' =>
'people-arrows',
6110 'conversation' =>
'comments',
6111 'country' =>
'globe-americas',
6112 'cron' =>
'business-time',
6114 'chevron-double-left' =>
'angle-double-left',
6115 'chevron-double-right' =>
'angle-double-right',
6116 'chevron-double-down' =>
'angle-double-down',
6117 'chevron-double-top' =>
'angle-double-up',
6118 'donation' =>
'gift',
6119 'dynamicprice' =>
'hand-holding-usd',
6121 'companies' =>
'building',
6122 'products' =>
'cube',
6123 'commercial' =>
'suitcase',
6124 'invoicing' =>
'coins',
6125 'accounting' =>
'search-dollar',
6126 'category' =>
'tag',
6127 'dollyrevert' =>
'dolly',
6129 'generate' =>
'plus-square',
6130 'hrm' =>
'user-tie',
6131 'incoterm' =>
'truck-loading',
6132 'margin' =>
'calculator',
6133 'members' =>
'user-friends',
6134 'ticket' =>
'ticket-alt',
6135 'globe' =>
'external-link-alt',
6138 'establishment' =>
'building',
6139 'edit' =>
'pencil-alt',
6140 'entity' =>
'globe',
6141 'graph' =>
'chart-line',
6142 'grip_title' =>
'arrows-alt',
6143 'grip' =>
'arrows-alt',
6144 'help' =>
'question-circle',
6145 'generic' =>
'file',
6146 'holiday' =>
'umbrella-beach',
6147 'info' =>
'info-circle',
6148 'info_black' =>
'info-circle',
6149 'inventory' =>
'boxes',
6150 'intracommreport' =>
'globe-europe',
6151 'jobprofile' =>
'cogs',
6152 'knowledgemanagement' =>
'ticket-alt',
6153 'label' =>
'layer-group',
6154 'layout' =>
'columns',
6156 'loan' =>
'money-bill-alt',
6157 'member' =>
'user-alt',
6158 'meeting' =>
'chalkboard-teacher',
6160 'next' =>
'arrow-alt-circle-right',
6162 'expensereport' =>
'wallet',
6164 'movement' =>
'people-carry',
6165 'sign-out' =>
'sign-out-alt',
6166 'superadmin' =>
'star',
6167 'switch_off' =>
'toggle-off',
6168 'switch_off_grey' =>
'toggle-off',
6169 'switch_off_warning' =>
'toggle-off',
6170 'switch_off_red' =>
'toggle-off',
6171 'switch_on' =>
'toggle-on',
6172 'switch_on_grey' =>
'toggle-on',
6173 'switch_on_warning' =>
'toggle-on',
6174 'switch_on_red' =>
'toggle-on',
6176 'bookmark' =>
'star',
6177 'bank' =>
'university',
6178 'close_title' =>
'times',
6179 'delete' =>
'trash',
6180 'filter' =>
'filter',
6181 'list-alt' =>
'list-alt',
6182 'calendarlist' =>
'bars',
6183 'calendar' =>
'calendar-alt',
6184 'calendarmonth' =>
'calendar-alt',
6185 'calendarweek' =>
'calendar-week',
6186 'calendarday' =>
'calendar-day',
6187 'calendarperuser' =>
'table',
6188 'calendarpertype' =>
'table',
6189 'intervention' =>
'ambulance',
6190 'invoice' =>
'file-invoice-dollar',
6191 'order' =>
'file-invoice',
6192 'error' =>
'exclamation-triangle',
6193 'warning' =>
'exclamation-triangle',
6194 'other' =>
'square',
6195 'playdisabled' =>
'play',
6196 'pdf' =>
'file-pdf',
6197 'poll' =>
'check-double',
6198 'pos' =>
'cash-register',
6199 'preview' =>
'binoculars',
6200 'project' =>
'project-diagram',
6201 'projectpub' =>
'project-diagram',
6202 'projecttask' =>
'tasks',
6203 'propal' =>
'file-signature',
6204 'proposal' =>
'file-signature',
6205 'partnership' =>
'handshake',
6206 'payment' =>
'money-check-alt',
6207 'payment_vat' =>
'money-check-alt',
6208 'pictoconfirm' =>
'check-square',
6209 'phoning' =>
'phone',
6210 'phoning_mobile' =>
'mobile-alt',
6211 'phoning_fax' =>
'fax',
6212 'previous' =>
'arrow-alt-circle-left',
6213 'printer' =>
'print',
6214 'product' =>
'cube',
6215 'puce' =>
'angle-right',
6216 'recent' =>
'check-square',
6217 'reception' =>
'dolly',
6218 'recruitmentjobposition' =>
'id-card-alt',
6219 'recruitmentcandidature' =>
'id-badge',
6221 'supplier_order' =>
'dol-order_supplier',
6222 'supplier_proposal' =>
'file-signature',
6223 'refresh' =>
'redo',
6224 'region' =>
'map-marked',
6225 'replacement' =>
'exchange-alt',
6226 'resource' =>
'laptop-house',
6227 'recurring' =>
'history',
6228 'service' =>
'concierge-bell',
6229 'skill' =>
'shapes',
6230 'state' =>
'map-marked-alt',
6231 'security' =>
'key',
6232 'salary' =>
'wallet',
6233 'shipment' =>
'dolly',
6234 'stock' =>
'box-open',
6235 'stats' =>
'chart-bar',
6236 'split' =>
'code-branch',
6237 'status' =>
'stop-circle',
6238 'stripe' =>
'stripe-s',
6239 'supplier' =>
'building',
6240 'technic' =>
'cogs',
6242 'timespent' =>
'clock',
6243 'title_setup' =>
'tools',
6244 'title_accountancy' =>
'money-check-alt',
6245 'title_bank' =>
'university',
6246 'title_hrm' =>
'umbrella-beach',
6247 'title_agenda' =>
'calendar-alt',
6248 'uncheck' =>
'times',
6249 'uparrow' =>
'share',
6250 'url' =>
'external-link-alt',
6251 'vat' =>
'money-check-alt',
6252 'vcard' =>
'arrow-alt-circle-down',
6253 'jabber' =>
'comment',
6254 'website' =>
'globe-americas',
6255 'workstation' =>
'pallet',
6256 'webhook' =>
'bullseye',
6258 'private' =>
'user-lock',
6259 'conferenceorbooth' =>
'chalkboard-teacher',
6260 'eventorganization' =>
'project-diagram',
6261 'webportal' =>
'door-open'
6264 if (
$conf->currency ==
'EUR') {
6265 $arrayconvpictotofa[
'currency'] =
'euro-sign';
6266 $arrayconvpictotofa[
'multicurrency'] =
'dollar-sign';
6268 $arrayconvpictotofa[
'currency'] =
'dollar-sign';
6269 $arrayconvpictotofa[
'multicurrency'] =
'euro-sign';
6272 $arrayconvpictotofa = array();
6275 return $arrayconvpictotofa;
6293function img_object($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $srconly = 0, $notitle = 0, $allowothertags = array())
6295 if (strpos($picto,
'^') === 0) {
6296 return img_picto($titlealt, str_replace(
'^',
'', $picto), $moreatt, $pictoisfullpath, $srconly, $notitle,
'',
'', 2, $allowothertags);
6298 return img_picto($titlealt,
'object_' . $picto, $moreatt, $pictoisfullpath, $srconly, $notitle,
'',
'', 2, $allowothertags);
6313function img_weather($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $morecss =
'')
6317 if (is_numeric($picto)) {
6320 return '<i class="fa fa-weather-level' . $picto .
'"></i>';
6321 } elseif (!preg_match(
'/(\.png|\.gif)$/i', $picto)) {
6325 $path = DOL_URL_ROOT .
'/theme/' .
$conf->theme .
'/img/weather/' . $picto;
6327 return img_picto($titlealt, $path, $moreatt, 1, 0, 0,
'', $morecss);
6341function img_picto_common($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $notitle = 0)
6345 if (!preg_match(
'/(\.png|\.gif)$/i', $picto)) {
6349 if ($pictoisfullpath) {
6352 $path = DOL_URL_ROOT .
'/theme/common/' . $picto;
6355 $themepath = DOL_DOCUMENT_ROOT .
'/theme/' .
$conf->theme .
'/img/' . $picto;
6357 if (file_exists($themepath)) {
6363 return img_picto($titlealt, $path, $moreatt, 1, 0, $notitle);
6379function img_action($titlealt, $numaction, $picto =
'', $moreatt =
'')
6383 if (empty($titlealt) || $titlealt ==
'default') {
6384 if ($numaction ==
'-1' || $numaction ==
'ST_NO') {
6386 $titlealt = $langs->transnoentitiesnoconv(
'ChangeDoNotContact');
6387 } elseif ($numaction ==
'0' || $numaction ==
'ST_NEVER') {
6389 $titlealt = $langs->transnoentitiesnoconv(
'ChangeNeverContacted');
6390 } elseif ($numaction ==
'1' || $numaction ==
'ST_TODO') {
6392 $titlealt = $langs->transnoentitiesnoconv(
'ChangeToContact');
6393 } elseif ($numaction ==
'2' || $numaction ==
'ST_PEND') {
6395 $titlealt = $langs->transnoentitiesnoconv(
'ChangeContactInProcess');
6396 } elseif ($numaction ==
'3' || $numaction ==
'ST_DONE') {
6398 $titlealt = $langs->transnoentitiesnoconv(
'ChangeContactDone');
6400 $titlealt = $langs->transnoentitiesnoconv(
'ChangeStatus ' . $numaction);
6404 if (!is_numeric($numaction)) {
6408 return img_picto($titlealt, (empty($picto) ?
'stcomm' . $numaction .
'.png' : $picto), $moreatt);
6418function img_edit_add($titlealt =
'default', $other =
'')
6422 if ($titlealt ==
'default') {
6423 $titlealt = $langs->trans(
'Add');
6426 return img_picto($titlealt,
'edit_add.png', $other);
6439 if ($titlealt ==
'default') {
6440 $titlealt = $langs->trans(
'Remove');
6443 return img_picto($titlealt,
'edit_remove.png', $other);
6454function img_edit($titlealt =
'default', $float = 0, $other =
'')
6458 if ($titlealt ==
'default') {
6459 $titlealt = $langs->trans(
'Modify');
6462 return img_picto($titlealt,
'edit', ($float ?
'style="float: ' . ($langs->tab_translate[
"DIRECTION"] ==
'rtl' ?
'left' :
'right') .
'"' :
"") . ($other ?
' ' . $other :
''));
6473function img_view($titlealt =
'default', $float = 0, $other =
'class="valignmiddle"')
6477 if ($titlealt ==
'default') {
6478 $titlealt = $langs->trans(
'View');
6481 $moreatt = ($float ?
'style="float: right" ' :
'') . $other;
6483 return img_picto($titlealt,
'eye', $moreatt);
6494function img_delete($titlealt =
'default', $other =
'class="pictodelete"', $morecss =
'')
6498 if ($titlealt ==
'default') {
6499 $titlealt = $langs->trans(
'Delete');
6502 return img_picto($titlealt,
'delete', $other, 0, 0, 0,
'', $morecss);
6512function img_printer($titlealt =
"default", $other =
'')
6515 if ($titlealt ==
"default") {
6516 $titlealt = $langs->trans(
"Print");
6518 return img_picto($titlealt,
'printer', $other);
6528function img_split($titlealt =
'default', $other =
'class="pictosplit"')
6532 if ($titlealt ==
'default') {
6533 $titlealt = $langs->trans(
'Split');
6536 return img_picto($titlealt,
'split', $other);
6546function img_help($usehelpcursor = 1, $usealttitle = 1)
6551 if (is_string($usealttitle)) {
6554 $usealttitle = $langs->trans(
'Info');
6558 return img_picto($usealttitle,
'info',
'style="vertical-align: middle;' . ($usehelpcursor == 1 ?
' cursor: help' : ($usehelpcursor == 2 ?
' cursor: pointer' :
'')) .
'"');
6567function img_info($titlealt =
'default')
6571 if ($titlealt ==
'default') {
6572 $titlealt = $langs->trans(
'Informations');
6575 return img_picto($titlealt,
'info',
'style="vertical-align: middle;"');
6586function img_warning($titlealt =
'default', $moreatt =
'', $morecss =
'pictowarning')
6590 if ($titlealt ==
'default') {
6591 $titlealt = $langs->trans(
'Warning');
6595 return img_picto($titlealt,
'warning',
'class="' . $morecss .
'"' . ($moreatt ? ($moreatt ==
'1' ?
' style="float: right"' :
' ' . $moreatt) :
''));
6604function img_error($titlealt =
'default')
6608 if ($titlealt ==
'default') {
6609 $titlealt = $langs->trans(
'Error');
6622function img_next($titlealt =
'default', $moreatt =
'')
6626 if ($titlealt ==
'default') {
6627 $titlealt = $langs->trans(
'Next');
6631 return '<span class="fa fa-chevron-right paddingright paddingleft" title="' .
dol_escape_htmltag($titlealt) .
'"></span>';
6641function img_previous($titlealt =
'default', $moreatt =
'')
6645 if ($titlealt ==
'default') {
6646 $titlealt = $langs->trans(
'Previous');
6650 return '<span class="fa fa-chevron-left paddingright paddingleft" title="' .
dol_escape_htmltag($titlealt) .
'"></span>';
6661function img_down($titlealt =
'default', $selected = 0, $moreclass =
'')
6665 if ($titlealt ==
'default') {
6666 $titlealt = $langs->trans(
'Down');
6669 return img_picto($titlealt, ($selected ?
'1downarrow_selected' :
'1downarrow'),
'class="imgdown' . ($moreclass ?
" " . $moreclass :
"") .
'"');
6680function img_up($titlealt =
'default', $selected = 0, $moreclass =
'')
6684 if ($titlealt ==
'default') {
6685 $titlealt = $langs->trans(
'Up');
6688 return img_picto($titlealt, ($selected ?
'1uparrow_selected' :
'1uparrow'),
'class="imgup' . ($moreclass ?
" " . $moreclass :
"") .
'"');
6699function img_left($titlealt =
'default', $selected = 0, $moreatt =
'')
6703 if ($titlealt ==
'default') {
6704 $titlealt = $langs->trans(
'Left');
6707 return img_picto($titlealt, ($selected ?
'1leftarrow_selected' :
'1leftarrow'), $moreatt);
6718function img_right($titlealt =
'default', $selected = 0, $moreatt =
'')
6722 if ($titlealt ==
'default') {
6723 $titlealt = $langs->trans(
'Right');
6726 return img_picto($titlealt, ($selected ?
'1rightarrow_selected' :
'1rightarrow'), $moreatt);
6736function img_allow($allow, $titlealt =
'default')
6740 if ($titlealt ==
'default') {
6741 $titlealt = $langs->trans(
'Active');
6758function img_credit_card($brand, $morecss =
'fa-2x inline-block valignmiddle')
6760 if (is_null($morecss)) {
6764 if ($brand ==
'visa' || $brand ==
'Visa') {
6766 } elseif ($brand ==
'mastercard' || $brand ==
'MasterCard') {
6767 $brand =
'cc-mastercard';
6768 } elseif ($brand ==
'amex' || $brand ==
'American Express') {
6770 } elseif ($brand ==
'discover' || $brand ==
'Discover') {
6771 $brand =
'cc-discover';
6772 } elseif ($brand ==
'jcb' || $brand ==
'JCB') {
6774 } elseif ($brand ==
'diners' || $brand ==
'Diners club') {
6775 $brand =
'cc-diners-club';
6776 } elseif (!in_array($brand, array(
'cc-visa',
'cc-mastercard',
'cc-amex',
'cc-discover',
'cc-jcb',
'cc-diners-club'))) {
6777 $brand =
'credit-card';
6780 return '<span class="fa fa-' . $brand .
' fa-fw' . ($morecss ?
' ' . $morecss :
'') .
'"></span>';
6791function img_mime($file, $titlealt =
'', $morecss =
'')
6793 require_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
6795 $mimetype = dol_mimetype($file,
'', 1);
6797 $mimefa = dol_mimetype($file,
'', 4);
6799 if (empty($titlealt)) {
6800 $titlealt =
'Mime type: ' . $mimetype;
6804 return '<i class="fa fa-' . $mimefa .
' ' . (preg_match(
'/pictofixedwidth/', $morecss) ?
'' :
'paddingright ') . ($morecss ?
' ' . $morecss :
'') .
'"' . ($titlealt ?
' title="' .
dolPrintHTMLForAttribute($titlealt) .
'"' :
'') .
'></i>';
6815function img_search($titlealt =
'default', $other =
'')
6819 if ($titlealt ==
'default') {
6820 $titlealt = $langs->trans(
'Search');
6823 $img =
img_picto($titlealt,
'search', $other, 0, 1);
6825 $input =
'<input type="image" class="liste_titre" name="button_search" src="' . $img .
'" ';
6842 if ($titlealt ==
'default') {
6843 $titlealt = $langs->trans(
'Search');
6846 $img =
img_picto($titlealt,
'searchclear.png', $other, 0, 1);
6848 $input =
'<input type="image" class="liste_titre" name="button_removefilter" src="' . $img .
'" ';
6867function info_admin($text, $infoonimgalt = 0, $nodiv = 0, $admin =
'1', $morecss =
'hideonsmartphone', $textfordropdown =
'', $picto =
'', $textonpictotooltip =
'')
6869 global
$conf, $langs;
6871 if ($infoonimgalt) {
6872 $result =
img_picto($text,
'info',
'class="' . ($morecss ?
' ' . $morecss :
'') .
'"');
6874 if (empty(
$conf->use_javascript_ajax)) {
6875 $textfordropdown =
'';
6878 $class = (empty($admin) ?
'undefined' : ((
string) $admin ==
'1' ?
'info' : $admin));
6879 $fa =
'info-circle';
6880 if ($picto ==
'warning') {
6881 $fa =
'exclamation-triangle';
6883 $result = ($nodiv ?
'' :
'<div class="wordbreak ' . $class . ($morecss ?
' ' . $morecss :
'') . ($textfordropdown ?
' hidden' :
'') .
'">');
6884 $result .=
img_picto(((
string) $admin ? $langs->trans(
'InfoAdmin') : $langs->trans(
'Note')).($textonpictotooltip ?
' : '.$textonpictotooltip :
''), $fa);
6887 $result .= ($nodiv ?
'' :
'</div>');
6889 if ($textfordropdown) {
6890 $tmpresult =
'<span class="' . $class .
'text opacitymedium cursorpointer">' . $langs->trans($textfordropdown) .
' ' .
img_picto($langs->trans($textfordropdown),
'1downarrow') .
'</span>';
6891 $tmpresult .=
'<script nonce="' . getNonce() .
'" type="text/javascript">
6892 jQuery(document).ready(function() {
6893 jQuery(".' . $class .
'text").click(function() {
6894 console.log("toggle text");
6895 jQuery(".' . $class .
'").toggle();
6900 $result = $tmpresult . $result;
6921 global
$conf, $langs, $user, $argv;
6922 global $dolibarr_main_prod;
6929 require_once DOL_DOCUMENT_ROOT .
'/core/class/translate.class.php';
6931 $langs->load(
"main");
6935 $langs->loadLangs(array(
'main',
'errors'));
6937 if ($_SERVER[
'DOCUMENT_ROOT']) {
6938 $out .= $langs->trans(
"DolibarrHasDetectedError") .
".<br>\n";
6940 $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";
6942 $out .= $langs->trans(
"InformationToHelpDiagnose") .
":<br>\n";
6944 $out .=
"<b>" . $langs->trans(
"Date") .
":</b> " .
dol_print_date(time(),
'dayhourlog') .
"<br>\n";
6945 $out .=
"<b>" . $langs->trans(
"Dolibarr") .
":</b> " . DOL_VERSION .
" - https://www.dolibarr.org<br>\n";
6946 if (isset(
$conf->global->MAIN_FEATURES_LEVEL)) {
6947 $out .=
"<b>" . $langs->trans(
"LevelOfFeature") .
":</b> " .
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') .
"<br>\n";
6949 if ($user instanceof
User) {
6950 $out .=
"<b>" . $langs->trans(
"Login") .
":</b> " . $user->login .
"<br>\n";
6952 if (function_exists(
"phpversion")) {
6953 $out .=
"<b>" . $langs->trans(
"PHP") .
":</b> " . phpversion() .
"<br>\n";
6955 $out .=
"<b>" . $langs->trans(
"Server") .
":</b> " . (isset($_SERVER[
"SERVER_SOFTWARE"]) ?
dol_htmlentities($_SERVER[
"SERVER_SOFTWARE"], ENT_COMPAT) :
'') .
"<br>\n";
6956 if (function_exists(
"php_uname")) {
6957 $out .=
"<b>" . $langs->trans(
"OS") .
":</b> " . php_uname() .
"<br>\n";
6959 $out .=
"<b>" . $langs->trans(
"UserAgent") .
":</b> " . (isset($_SERVER[
"HTTP_USER_AGENT"]) ?
dol_htmlentities($_SERVER[
"HTTP_USER_AGENT"], ENT_COMPAT) :
'') .
"<br>\n";
6961 $out .=
"<b>" . $langs->trans(
"RequestedUrl") .
":</b> " . (isset($_SERVER[
"REQUEST_URI"]) ?
dol_htmlentities($_SERVER[
"REQUEST_URI"], ENT_COMPAT) :
'') .
"<br>\n";
6962 $out .=
"<b>" . $langs->trans(
"Referer") .
":</b> " . (isset($_SERVER[
"HTTP_REFERER"]) ?
dol_htmlentities($_SERVER[
"HTTP_REFERER"], ENT_COMPAT) :
'') .
"<br>\n";
6963 $out .=
"<b>" . $langs->trans(
"MenuManager") .
":</b> " . (isset(
$conf->standard_menu) ?
dol_htmlentities(
$conf->standard_menu, ENT_COMPAT) :
'') .
"<br>\n";
6965 $syslog .=
"url=" . (isset($_SERVER[
"REQUEST_URI"]) ?
dol_escape_htmltag($_SERVER[
"REQUEST_URI"]) :
'');
6966 $syslog .=
", query_string=" . (isset($_SERVER[
"QUERY_STRING"]) ?
dol_escape_htmltag($_SERVER[
"QUERY_STRING"]) :
'');
6968 $out .=
'> ' . $langs->transnoentities(
"ErrorInternalErrorDetected") .
":\n" . $argv[0] .
"\n";
6972 if (!empty(
$conf->modules)) {
6973 $out .=
"<b>" . $langs->trans(
"Modules") .
":</b> " . implode(
', ',
$conf->modules) .
"<br>\n";
6976 if (is_object(
$db)) {
6977 if ($_SERVER[
'DOCUMENT_ROOT']) {
6978 $out .=
"<b>" . $langs->trans(
"DatabaseTypeManager") .
":</b> " .
$db->type .
"<br>\n";
6979 $lastqueryerror =
$db->lastqueryerror();
6981 $lastqueryerror =
"SQL error string is not a valid UTF8 string. We can't show it.";
6983 $out .=
"<b>" . $langs->trans(
"RequestLastAccessInError") .
":</b> " . ($lastqueryerror ?
dol_escape_htmltag($lastqueryerror) : $langs->trans(
"ErrorNoRequestInError")) .
"<br>\n";
6984 $out .=
"<b>" . $langs->trans(
"ReturnCodeLastAccessInError") .
":</b> " . (
$db->lasterrno() ?
dol_escape_htmltag(
$db->lasterrno()) : $langs->trans(
"ErrorNoRequestInError")) .
"<br>\n";
6985 $out .=
"<b>" . $langs->trans(
"InformationLastAccessInError") .
":</b> " . (
$db->lasterror() ?
dol_escape_htmltag(
$db->lasterror()) : $langs->trans(
"ErrorNoRequestInError")) .
"<br>\n";
6989 $out .=
'> ' . $langs->transnoentities(
"DatabaseTypeManager") .
":\n" .
$db->type .
"\n";
6990 $out .=
'> ' . $langs->transnoentities(
"RequestLastAccessInError") .
":\n" . (
$db->lastqueryerror() ?
$db->lastqueryerror() : $langs->transnoentities(
"ErrorNoRequestInError")) .
"\n";
6991 $out .=
'> ' . $langs->transnoentities(
"ReturnCodeLastAccessInError") .
":\n" . (
$db->lasterrno() ?
$db->lasterrno() : $langs->transnoentities(
"ErrorNoRequestInError")) .
"\n";
6992 $out .=
'> ' . $langs->transnoentities(
"InformationLastAccessInError") .
":\n" . (
$db->lasterror() ?
$db->lasterror() : $langs->transnoentities(
"ErrorNoRequestInError")) .
"\n";
6994 $syslog .=
", sql=" .
$db->lastquery();
6995 $syslog .=
", db_error=" .
$db->lasterror();
6998 if ($error || $errors) {
7000 if (is_array($error) && is_array($errors)) {
7001 $errors = array_merge($error, $errors);
7002 } elseif (is_array($error)) {
7004 } elseif (is_array($errors) && !empty($error)) {
7005 $errors = array_merge(array($error), $errors);
7006 } elseif (!empty($error)) {
7007 $errors = array_merge(array($error), array($errors));
7010 $langs->load(
"errors");
7012 foreach ($errors as $msg) {
7016 if ($_SERVER[
'DOCUMENT_ROOT']) {
7017 $out .=
"<b>" . $langs->trans(
"Message") .
":</b> " .
dol_escape_htmltag($msg) .
"<br>\n";
7019 $out .=
'> ' . $langs->transnoentities(
"Message") .
":\n" . $msg .
"\n";
7021 $syslog .=
", msg=" . $msg;
7024 if (empty($dolibarr_main_prod) && $_SERVER[
'DOCUMENT_ROOT'] && function_exists(
'xdebug_print_function_stack') && function_exists(
'xdebug_call_file')) {
7025 xdebug_print_function_stack();
7026 $out .=
'<b>XDebug information:</b>' .
"<br>\n";
7027 $out .=
'File: ' . xdebug_call_file() .
"<br>\n";
7028 $out .=
'Line: ' . xdebug_call_line() .
"<br>\n";
7029 $out .=
'Function: ' . xdebug_call_function() .
"<br>\n";
7034 if (!headers_sent()) {
7035 if (function_exists(
'top_httphead')) {
7039 http_response_code(202);
7042 if (empty($dolibarr_main_prod)) {
7045 if (empty($langs->defaultlang)) {
7046 $langs->setDefaultLang();
7048 $langs->loadLangs(array(
"main",
"errors"));
7050 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";
7051 print $langs->trans(
"DolibarrHasDetectedError") .
'. ';
7052 print $langs->trans(
"YouCanSetOptionDolibarrMainProdToZero");
7053 if (!defined(
"MAIN_CORE_ERROR")) {
7054 define(
"MAIN_CORE_ERROR", 1);
7071function dol_print_error_email($prefixcode, $errormessage =
'', $errormessages = array(), $morecss =
'error', $email =
'')
7075 if (empty($email)) {
7079 $langs->load(
"errors");
7082 print
'<br><div class="center login_main_message"><div class="' . $morecss .
'">';
7083 print $langs->trans(
"ErrorContactEMail", $email, $prefixcode .
'-' .
dol_print_date($now,
'%Y%m%d%H%M%S'));
7084 if ($errormessage) {
7085 print
'<br><br>' . $errormessage;
7087 if (is_array($errormessages) && count($errormessages)) {
7088 foreach ($errormessages as $mesgtoshow) {
7089 print
'<br><br>' . $mesgtoshow;
7092 print
'</div></div>';
7111function print_liste_field_titre($name, $file =
"", $field =
"", $begin =
"", $param =
"", $moreattrib =
"", $sortfield =
"", $sortorder =
"", $prefix =
"", $tooltip =
"", $forcenowrapcolumntitle = 0)
7113 print
getTitleFieldOfList($name, 0, $file, $field, $begin, $param, $moreattrib, $sortfield, $sortorder, $prefix, 0, $tooltip, $forcenowrapcolumntitle);
7134function getTitleFieldOfList($name, $thead = 0, $file =
"", $field =
"", $begin =
"", $moreparam =
"", $moreattrib =
"", $sortfield =
"", $sortorder =
"", $prefix =
"", $disablesortlink = 0, $tooltip =
'', $forcenowrapcolumntitle = 0)
7136 global $langs, $form;
7139 if ($moreattrib ==
'class="right"') {
7140 $prefix .=
'right ';
7143 $tooltip = (
string) $tooltip;
7145 $sortorder = strtoupper((
string) $sortorder);
7154 $tmpsortfield = explode(
',', (
string) $sortfield);
7155 $sortfield1 = trim($tmpsortfield[0]);
7156 $tmpfield = explode(
',', $field);
7157 $field1 = trim($tmpfield[0]);
7159 if (strpos((
string) $tooltip,
':') !==
false) {
7160 $tmptooltip = explode(
':', (
string) $tooltip);
7162 $tmptooltip = array($tooltip);
7165 $wrapcolumntitle = (empty($forcenowrapcolumntitle) || (!empty($tmptooltip[2]) && $tmptooltip[2] ==
'-1'));
7167 if (!
getDolGlobalString(
'MAIN_DISABLE_WRAPPING_ON_COLUMN_TITLE') && $wrapcolumntitle) {
7168 $prefix =
'wrapcolumntitle ' . $prefix;
7174 $liste_titre =
'liste_titre';
7175 if ($field1 && ($sortfield1 == $field1 || $sortfield1 == preg_replace(
"/^[^\.]+\./",
"", $field1))) {
7176 $liste_titre =
'liste_titre_sel';
7179 $tagstart =
'<' . $tag .
' class="' . $prefix . $liste_titre .
'" ' . $moreattrib;
7184 if (empty($thead) && $field && empty($disablesortlink)) {
7185 $options = preg_replace(
'/sortfield=([a-zA-Z0-9,\s\.]+)/i',
'', (is_scalar($moreparam) ? $moreparam :
''));
7186 $options = preg_replace(
'/sortorder=([a-zA-Z0-9,\s\.]+)/i',
'', $options);
7187 $options = preg_replace(
'/&+/i',
'&', $options);
7188 if (!preg_match(
'/^&/', $options)) {
7189 $options =
'&' . $options;
7192 $sortordertouseinlink =
'';
7193 if ($field1 != $sortfield1) {
7194 if (preg_match(
'/^DESC/i', $sortorder)) {
7195 $sortordertouseinlink .= str_repeat(
'desc,', count(explode(
',', $field)));
7197 $sortordertouseinlink .= str_repeat(
'asc,', count(explode(
',', $field)));
7200 if (preg_match(
'/^ASC/i', $sortorder)) {
7201 $sortordertouseinlink .= str_repeat(
'desc,', count(explode(
',', $field)));
7203 $sortordertouseinlink .= str_repeat(
'asc,', count(explode(
',', $field)));
7206 $sortordertouseinlink = preg_replace(
'/,$/',
'', $sortordertouseinlink);
7207 $out .=
'<a class="reposition" href="' .
dolBuildUrl($file, [
'sortfield' => $field,
'sortorder' => $sortordertouseinlink,
'begin' => $begin]) . $options .
'"';
7211 if ($tooltip && $tmptooltip[0]) {
7213 $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]));
7215 $out .= $langs->trans((
string) $name);
7218 if (empty($thead) && $field && empty($disablesortlink)) {
7222 if (empty($thead) && $field) {
7223 $options = preg_replace(
'/sortfield=([a-zA-Z0-9,\s\.]+)/i',
'', (is_scalar($moreparam) ? $moreparam :
''));
7224 $options = preg_replace(
'/sortorder=([a-zA-Z0-9,\s\.]+)/i',
'', $options);
7225 $options = preg_replace(
'/&+/i',
'&', $options);
7226 if (!preg_match(
'/^&/', $options)) {
7227 $options =
'&' . $options;
7230 if (!$sortorder || ($field1 != $sortfield1)) {
7233 if (preg_match(
'/^DESC/', $sortorder)) {
7234 $sortimg .=
'<span class="nowrap">' .
img_up(
"Z-A", 0,
'paddingright') .
'</span>';
7236 if (preg_match(
'/^ASC/', $sortorder)) {
7237 $sortimg .=
'<span class="nowrap">' .
img_down(
"A-Z", 0,
'paddingright') .
'</span>';
7242 $tagend =
'</' . $tag .
'>';
7244 $out = $tagstart . $sortimg . $out . $tagend;
7259 dol_syslog(__FUNCTION__ .
" is deprecated", LOG_WARNING);
7261 print
'<div class="titre">' . $title .
'</div>';
7275function print_fiche_titre($title, $mesg =
'', $picto =
'generic', $pictoisfullpath = 0,
$id =
'')
7294function load_fiche_titre($title, $morehtmlright =
'', $picto =
'generic', $pictoisfullpath = 0,
$id =
'', $morecssontable =
'', $morehtmlcenter =
'', $morecssonpicto =
'widthpictotitle')
7298 if ($picto ==
'setup') {
7303 $return .=
'<table ' . (
$id ?
'id="' .
$id .
'" ' :
'') .
'class="centpercent notopnoleftnoright table-fiche-title' . ($morecssontable ?
' ' . $morecssontable :
'') .
'">';
7304 $return .=
'<tr class="toptitle">';
7306 $return .=
'<td class="nobordernopadding widthpictotitle valignmiddle col-picto">' .
img_picto(
'', $picto,
'class="valignmiddle pictotitle'.($morecssonpicto ?
' '.$morecssonpicto :
'').
'"', $pictoisfullpath) .
'</td>';
7308 $return .=
'<td class="nobordernopadding valignmiddle col-title">';
7309 $return .=
'<div class="titre inline-block">';
7310 $return .=
'<span class="inline-block valignmiddle print-barre-liste">' . $title .
'</span>';
7311 $return .=
'</div>';
7314 $return .=
'<td class="nobordernopadding center valignmiddle col-center">' . $morehtmlcenter .
'</td>';
7317 $return .=
'<td class="nobordernopadding titre_right wordbreakimp right valignmiddle col-right">' . $morehtmlright .
'</td>';
7319 $return .=
'</tr></table>' .
"\n";
7347function 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 =
'')
7349 global
$conf, $langs;
7352 $savtotalnboflines = $totalnboflines;
7353 if (is_numeric($totalnboflines)) {
7354 $totalnboflines = abs($totalnboflines);
7359 $tmparray = preg_split(
'/<br>/i', $title, 2);
7360 if (!empty($tmparray[1])) {
7361 $title = $tmparray[0];
7362 $subtitle = $tmparray[1];
7365 $page = (int) $page;
7367 if ($picto ==
'setup') {
7368 $picto =
'title_setup';
7370 if ((
$conf->browser->name ==
'ie') && $picto ==
'generic') {
7371 $picto =
'title.gif';
7374 $limit =
$conf->liste_limit;
7377 if ($savlimit != 0 && (($num > $limit) || ($num == -1) || ($limit == 0))) {
7385 print
"<!-- Begin print_barre_liste -->\n";
7386 print
'<table class="centpercent notopnoleftnoright table-fiche-title' . ($morecss ?
' ' . $morecss :
'') .
'">';
7387 print
'<tr class="toptitle">';
7391 if ($picto && $title) {
7392 print
'<td class="nobordernopadding widthpictotitle valignmiddle col-picto">';
7393 print
img_picto(
'', $picto,
'class="valignmiddle pictotitle widthpictotitle"', $pictoisfullpath);
7397 print
'<td class="nobordernopadding valignmiddle col-title">';
7398 print
'<div class="titre inline-block nowrap">';
7399 print
'<span class="inline-block valignmiddle print-barre-liste">' . $title .
'</span>';
7400 if (!empty($title) && $savtotalnboflines >= 0 && (
string) $savtotalnboflines !=
'') {
7401 if (is_numeric($totalnboflines) && (
int) $totalnboflines > 0) {
7402 print
'<span class="opacitymedium colorblack marginleftonly totalnboflines valignmiddle" title="' . $langs->trans(
"NbRecordQualified") .
'">(' . $totalnboflines .
')</span>';
7404 print
'<span class="opacitymedium colorblack marginleftonly totalnboflines valignmiddle">(' . $totalnboflines .
')</span>';
7408 if (!empty($subtitle)) {
7409 print
'<br><div class="subtitle inline-block hideonsmartphone">' . $subtitle .
'</div>';
7414 if ($morehtmlcenter && empty(
$conf->dol_optimize_smallscreen)) {
7415 print
'<td class="nobordernopadding center valignmiddle col-center">' . $morehtmlcenter .
'</td>';
7419 print
'<td class="nobordernopadding valignmiddle right col-right">';
7420 print
'<input type="hidden" name="pageplusoneold" value="' . ((int) $page + 1) .
'">';
7422 parse_str($options, $query);
7424 $query += [
'sortfield' => $sortfield];
7427 $query += [
'sortorder' => $sortorder];
7430 $options =
'&' . http_build_query($query);
7432 $query = array_merge($query, [
'page' => $page]);
7436 if ($savlimit != 0 && ($page > 0 || $num > $limit)) {
7437 if ($totalnboflines) {
7439 $maxnbofpage = (empty(
$conf->dol_optimize_smallscreen) ? 4 : 0);
7442 $nbpages = ceil($totalnboflines / $limit);
7446 $cpt = ($page - $maxnbofpage);
7452 if (empty($pagenavastextinput)) {
7454 $pagelist .=
'<li class="pagination"><a class="reposition" href="' .
dolBuildUrl($file, $query) .
'">1</a></li>';
7456 $pagelist .=
'<li class="pagination"><span class="inactive">...</span></li>';
7457 } elseif ($cpt == 2) {
7459 $pagelist .=
'<li class="pagination"><a class="reposition" href="' .
dolBuildUrl($file, $query) .
'">2</a></li>';
7465 if ($pagenavastextinput) {
7466 if ($cpt == $page) {
7467 $pagelist .=
'<li class="pagination pageplusone valignmiddle"><input type="text" class="' . ($totalnboflines > 100 ?
'width40' :
'width25') .
' center pageplusone heightofcombo" name="pageplusone" value="' . ($page + 1) .
'"></li>';
7471 if ($cpt == $page) {
7472 $pagelist .=
'<li class="pagination"><span class="active">' . ($page + 1) .
'</span></li>';
7474 $query[
'page'] = $cpt;
7475 $pagelist .=
'<li class="pagination"><a class="reposition" href="' .
dolBuildUrl($file, $query) .
'">' . ($cpt + 1) .
'</a></li>';
7479 }
while ($cpt < $nbpages && $cpt <= ($page + $maxnbofpage));
7481 if (empty($pagenavastextinput)) {
7482 if ($cpt < $nbpages) {
7483 if ($cpt < $nbpages - 2) {
7484 $pagelist .=
'<li class="pagination"><span class="inactive">...</span></li>';
7485 } elseif ($cpt == $nbpages - 2) {
7486 $query[
'page'] = ($nbpages - 2);
7487 $pagelist .=
'<li class="pagination"><a class="reposition" href="' .
dolBuildUrl($file, $query) .
'">' . ($nbpages - 1) .
'</a></li>';
7489 $query[
'page'] = ($nbpages - 1);
7490 $pagelist .=
'<li class="pagination"><a class="reposition" href="' .
dolBuildUrl($file, $query) .
'">' . $nbpages .
'</a></li>';
7493 $query[
'page'] = ($nbpages - 1);
7494 $pagelist .=
'<li class="pagination paginationlastpage"><a class="reposition" href="' .
dolBuildUrl($file, $query) .
'">' . $nbpages .
'</a></li>';
7497 $pagelist .=
'<li class="pagination"><span class="active">' . ($page + 1) .
"</li>";
7501 if ($savlimit || $morehtmlright || $morehtmlrightbeforearrow) {
7503 print_fleche_navigation($page, $file, $options, $nextpage, $pagelist, $morehtmlright, $savlimit, $totalnboflines, $selectlimitsuffix, $morehtmlrightbeforearrow, $hidenavigation);
7507 if ($pagenavastextinput) {
7508 print ajax_autoselect(
'.pageplusone');
7517 if ($morehtmlcenter && !empty(
$conf->dol_optimize_smallscreen)) {
7518 print
'<div class="nobordernopadding marginbottomonly center valignmiddle col-center centpercent">' . $morehtmlcenter .
'</div>';
7521 print
"<!-- End title -->\n\n";
7540function print_fleche_navigation($page, $file, $options =
'', $nextpage = 0, $betweenarrows =
'', $afterarrows =
'', $limit = -1, $totalnboflines = 0, $selectlimitsuffix =
'', $beforearrows =
'', $hidenavigation = 0)
7542 global
$conf, $langs;
7544 print
'<div class="pagination"><ul>';
7545 if ($beforearrows) {
7546 print
'<li class="paginationbeforearrows">';
7547 print $beforearrows;
7551 if (empty($hidenavigation)) {
7552 if ((
int) $limit > 0 && (empty($selectlimitsuffix) || !is_numeric($selectlimitsuffix))) {
7553 $pagesizechoices =
'10:10,15:15,20:20,25:25,50:50,100:100,250:250,500:500,1000:1000';
7554 $pagesizechoices .=
',5000:5000';
7564 print
'<li class="pagination">';
7565 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 .
'">';
7566 print
'<datalist id="limitlist">';
7568 print
'<li class="paginationcombolimit valignmiddle">';
7569 print
'<select id="limit' . (is_numeric($selectlimitsuffix) ?
'' : $selectlimitsuffix) .
'" name="'.(is_numeric($selectlimitsuffix) ?
'limit' : $selectlimitsuffix).
'" class="flat selectlimit nopadding maxwidth75 center' . (is_numeric($selectlimitsuffix) ?
'' :
' ' . $selectlimitsuffix) .
'" title="' .
dol_escape_htmltag($langs->trans(
"MaxNbOfRecordPerPage")) .
'">';
7571 $tmpchoice = explode(
',', $pagesizechoices);
7572 $tmpkey = $limit .
':' . $limit;
7573 if (!in_array($tmpkey, $tmpchoice)) {
7574 $tmpchoice[$tmpkey] = $tmpkey;
7576 $tmpkey =
$conf->liste_limit .
':' .
$conf->liste_limit;
7577 if (!in_array($tmpkey, $tmpchoice)) {
7578 $tmpchoice[$tmpkey] = $tmpkey;
7580 asort($tmpchoice, SORT_NUMERIC);
7581 foreach ($tmpchoice as $val) {
7583 $tmp = explode(
':', $val);
7586 if ($key !=
'' && $val !=
'') {
7587 if ((
int) $key == (
int) $limit) {
7588 $selected =
' selected="selected"';
7590 print
'<option name="' . $key .
'"' . $selected .
'>' .
dol_escape_htmltag($val) .
'</option>' .
"\n";
7594 print
'</datalist>';
7597 print
ajax_combobox(
"limit" . (is_numeric($selectlimitsuffix) ?
'' : $selectlimitsuffix), array(), 0, 0,
'resolve',
'-1',
'limit');
7601 if (
$conf->use_javascript_ajax) {
7602 print
'<!-- JS CODE TO ENABLE select limit to launch submit of page -->
7604 jQuery(document).ready(function () {
7605 jQuery(".selectlimit").change(function() {
7606 console.log("We change limit so we submit the form");
7607 $(this).parents(\'form:first\').submit();
7616 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>';
7618 if ($betweenarrows) {
7619 print
'<!--<div class="betweenarrows nowraponall inline-block">-->';
7620 print $betweenarrows;
7621 print
'<!--</div>-->';
7623 if ($nextpage > 0) {
7624 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>';
7627 print
'<li class="paginationafterarrows">';
7632 print
'</ul></div>' .
"\n";
7647function vatrate($rate, $addpercent =
false, $info_bits = 0, $usestarfornpr = 0, $html = 0)
7651 if (preg_match(
'/%/', $rate)) {
7652 $rate = str_replace(
'%',
'', $rate);
7656 if (preg_match(
'/\((.*)\)/', $rate, $reg)) {
7657 $morelabel =
' (' . $reg[1] .
')';
7658 $rate = preg_replace(
'/\s*' . preg_quote($morelabel,
'/') .
'/',
'', $rate);
7659 $morelabel =
' ' . ($html ?
'<span class="opacitymedium small">' :
'') .
'(' . $reg[1] .
')' . ($html ?
'</span>' :
'');
7661 if (preg_match(
'/\*/', $rate)) {
7662 $rate = str_replace(
'*',
'', $rate);
7667 if (!preg_match(
'/\//', $rate)) {
7668 $ret =
price($rate, 0,
'', 0, 0) . ($addpercent ?
'%' :
'');
7671 $ret = $rate . ($addpercent ?
'%' :
'');
7673 if (($info_bits & 1) && $usestarfornpr >= 0) {
7695function price($amount, $form = 0, $outlangs =
'', $trunc = 1, $rounding = -1, $forcerounding = -1, $currency_code =
'')
7697 global $langs,
$conf;
7700 if (empty($amount)) {
7703 $amount = (is_numeric($amount) ? $amount : 0);
7704 if ($rounding == -1) {
7707 $nbdecimal = $rounding;
7709 if ($outlangs ===
'none') {
7719 if (!($outlangs instanceof
Translate)) {
7723 if ($outlangs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
7724 $dec = $outlangs->transnoentitiesnoconv(
"SeparatorDecimal");
7726 if ($outlangs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
7727 $thousand = $outlangs->transnoentitiesnoconv(
"SeparatorThousand");
7729 if ($thousand ==
'None') {
7731 } elseif ($thousand ==
'Space') {
7738 $amount = str_replace(
',',
'.', $amount);
7740 $data = explode(
'.', $amount);
7741 $decpart = isset($data[1]) ? $data[1] :
'';
7742 $decpart = preg_replace(
'/0+$/i',
'', $decpart);
7752 $nbdecimalmaxshown = (int) str_replace(
'...',
'',
getDolGlobalString(
'MAIN_MAX_DECIMALS_SHOWN'));
7753 if ($trunc && $nbdecimal > $nbdecimalmaxshown) {
7754 $nbdecimal = $nbdecimalmaxshown;
7762 if ((
string) $forcerounding !=
'-1' && (
string) $forcerounding !=
'') {
7763 if ($forcerounding ===
'MU') {
7765 } elseif ($forcerounding ===
'MT') {
7767 } elseif ($forcerounding >= 0) {
7768 $nbdecimal = (int) $forcerounding;
7773 $output = number_format((
float) $amount, $nbdecimal, $dec, $thousand);
7775 $cursymbolbefore = $cursymbolafter =
'';
7776 if ($currency_code && is_object($outlangs)) {
7777 if ($currency_code ==
'auto') {
7778 $currency_code =
$conf->currency;
7781 $listofcurrenciesbefore = array(
'AUD',
'CAD',
'CNY',
'COP',
'CLP',
'GBP',
'HKD',
'MXN',
'PEN',
'USD',
'CRC',
'ZAR');
7782 $listoflanguagesbefore = array(
'nl_NL');
7783 if (in_array($currency_code, $listofcurrenciesbefore) || in_array($outlangs->defaultlang, $listoflanguagesbefore)) {
7784 $cursymbolbefore .= $outlangs->getCurrencySymbol($currency_code);
7786 $tmpcur = $outlangs->getCurrencySymbol($currency_code);
7787 $cursymbolafter .= ($tmpcur == $currency_code ?
' ' . $tmpcur : $tmpcur);
7791 $output = preg_replace(
'/\s/',
' ', $output);
7792 $output = $cursymbolbefore . $output . $end . ($cursymbolafter ?
' <span class="small">'.$cursymbolafter.
'</span>' :
'');
7793 $output = preg_replace(
'/\'/',
''', $output);
7795 $output = $cursymbolbefore . $output . $end . ($cursymbolafter ?
' '.$cursymbolafter :
'');
7826function price2num($amount, $rounding =
'', $option = 0)
7831 if (is_null($amount)) {
7840 if (is_null($langs)) {
7844 if ($langs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
7845 $dec = $langs->transnoentitiesnoconv(
"SeparatorDecimal");
7847 if ($langs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
7848 $thousand = $langs->transnoentitiesnoconv(
"SeparatorThousand");
7851 if ($thousand ==
'None') {
7853 } elseif ($thousand ==
'Space') {
7861 if (!is_numeric($amount)) {
7862 $amount = preg_replace(
'/[a-zA-Z\/\\\*\(\)<>\_]/',
'', $amount);
7865 if ($option == 2 && $thousand ==
'.' && preg_match(
'/\.(\d\d\d)$/', (
string) $amount)) {
7866 $amount = str_replace($thousand,
'', $amount);
7872 if (is_numeric($amount)) {
7874 $temps = sprintf(
"%10.10F", $amount - intval($amount));
7875 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
7877 $amount = number_format($amount, $nbofdec, $dec, $thousand);
7883 if ($thousand !=
',' && $thousand !=
'.') {
7896 if (preg_match(
'/^(?<int>[^,]*,|[^.]*\.)(?<dec>[^.,]*)$/u', $amount, $matches)) {
7897 $intPart = $matches[
'int'];
7898 $decPart = $matches[
'dec'];
7901 $intPart = str_replace([
'.',
','],
'', $intPart);
7904 $amount = $intPart . $dec . $decPart;
7908 $amount = str_replace(
' ',
'', $amount);
7909 $amount = str_replace($thousand,
'', $amount);
7910 $amount = str_replace($dec,
'.', $amount);
7912 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
7918 $nbofdectoround =
'';
7919 if ($rounding ==
'MU') {
7921 } elseif ($rounding ==
'MT') {
7923 } elseif ($rounding ==
'MS') {
7925 } elseif ($rounding ==
'CU') {
7927 } elseif ($rounding ==
'CT') {
7929 } elseif (is_numeric($rounding)) {
7930 $nbofdectoround = (int) $rounding;
7935 $amount = round(is_string($amount) ? (
float) $amount : $amount, $nbofdectoround);
7937 return 'ErrorBadParameterProvidedToFunction';
7943 if (is_numeric($amount)) {
7945 $temps = sprintf(
"%10.10F", $amount - intval($amount));
7946 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
7948 $amount = number_format($amount, min($nbofdec, $nbofdectoround), $dec, $thousand);
7954 if ($thousand !=
',' && $thousand !=
'.') {
7955 $amount = str_replace(
',',
'.', $amount);
7958 $amount = str_replace(
' ',
'', $amount);
7959 $amount = str_replace($thousand,
'', $amount);
7960 $amount = str_replace($dec,
'.', $amount);
7962 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
7980function showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round = -1, $forceunitoutput =
'no', $use_short_label = 0)
7982 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
7984 if (($forceunitoutput ==
'no' && $dimension < 1 / 10000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == -6)) {
7985 $dimension *= 1000000;
7987 } elseif (($forceunitoutput ==
'no' && $dimension < 1 / 10 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == -3)) {
7990 } elseif (($forceunitoutput ==
'no' && $dimension > 100000000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == 6)) {
7991 $dimension /= 1000000;
7993 } elseif (($forceunitoutput ==
'no' && $dimension > 100000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == 3)) {
8010 $ret =
price($dimension, 0, $outputlangs, 0, 0, $round);
8030function get_localtax($vatrate, $local, $thirdparty_buyer =
null, $thirdparty_seller =
null, $vatnpr = 0)
8034 if (empty($thirdparty_seller) || !is_object($thirdparty_seller)) {
8035 $thirdparty_seller =
$mysoc;
8038 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);
8040 $vatratecleaned = $vatrate;
8042 if (preg_match(
'/^(.*)\s*\((.*)\)$/', (
string) $vatrate, $reg)) {
8043 $vatratecleaned = trim($reg[1]);
8044 $vatratecode = $reg[2];
8053 if (
$mysoc->country_code ==
'ES') {
8055 if (!
$mysoc->localtax1_assuj || (
string) $vatratecleaned ==
"0") {
8058 if ($thirdparty_seller->id ==
$mysoc->id) {
8059 if (!$thirdparty_buyer->localtax1_assuj) {
8063 if (!$thirdparty_seller->localtax1_assuj) {
8071 if (!
$mysoc->localtax2_assuj) {
8074 if ($thirdparty_seller->id ==
$mysoc->id) {
8075 if (!$thirdparty_buyer->localtax2_assuj) {
8079 if (!$thirdparty_seller->localtax2_assuj) {
8085 if ($local == 1 && !$thirdparty_seller->localtax1_assuj) {
8088 if ($local == 2 && !$thirdparty_seller->localtax2_assuj) {
8094 if (in_array(
$mysoc->country_code, array(
'ES'))) {
8095 $conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY = 1;
8101 if ($thirdparty_seller !=
$mysoc) {
8103 return $thirdparty_seller->localtax1_value;
8112 if ($thirdparty_seller !=
$mysoc) {
8115 return $thirdparty_seller->localtax2_value;
8118 if (in_array(
$mysoc->country_code, array(
'ES'))) {
8119 return $thirdparty_buyer->localtax2_value;
8128 $sql =
"SELECT t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
8129 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t, " . MAIN_DB_PREFIX .
"c_country as c";
8130 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '" .
$db->escape($thirdparty_seller->country_code) .
"'";
8131 $sql .=
" AND t.taux = " . ((float) $vatratecleaned) .
" AND t.active = 1";
8132 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
8133 if (!empty($vatratecode)) {
8134 $sql .=
" AND t.code ='" .
$db->escape($vatratecode) .
"'";
8136 $sql .=
" AND t.recuperableonly = '" .
$db->escape((
string) $vatnpr) .
"'";
8139 $resql =
$db->query($sql);
8142 $obj =
$db->fetch_object($resql);
8145 return $obj->localtax1;
8146 } elseif ($local == 2) {
8147 return $obj->localtax2;
8168 $valors = explode(
":", $tax);
8170 if (count($valors) > 1) {
8187 $sql =
" SELECT t.localtax" . ((int) $local) .
" as localtax";
8188 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t INNER JOIN " . MAIN_DB_PREFIX .
"c_country as c ON c.rowid = t.fk_pays";
8189 $sql .=
" WHERE c.code = '" .
$db->escape(
$mysoc->country_code) .
"' AND t.active = 1 AND t.entity IN (" .
getEntity(
'c_tva') .
") AND t.taux = (";
8190 $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";
8191 $sql .=
" WHERE c.code = '" .
$db->escape(
$mysoc->country_code) .
"' AND t.entity IN (" .
getEntity(
'c_tva') .
") AND tt.active = 1)";
8192 $sql .=
" AND t.localtax" . ((int) $local) .
"_type <> '0'";
8193 $sql .=
" ORDER BY t.rowid DESC";
8195 $resql =
$db->query($sql);
8197 $obj =
$db->fetch_object($resql);
8199 return $obj->localtax;
8220function getTaxesFromId($vatrate, $buyer =
null, $seller =
null, $firstparamisid = 1)
8224 dol_syslog(
"getTaxesFromId vat id or rate = " . $vatrate);
8227 $sql =
"SELECT t.rowid, t.code, t.taux as rate, t.recuperableonly as npr, t.accountancy_code_sell, t.accountancy_code_buy,";
8228 $sql .=
" t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type";
8229 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t";
8230 if ($firstparamisid) {
8231 $sql .=
" WHERE t.rowid = " . (int) $vatrate;
8233 $vatratecleaned = $vatrate;
8236 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
8237 $vatratecleaned = $reg[1];
8238 $vatratecode = $reg[2];
8241 $sql .=
", " . MAIN_DB_PREFIX .
"c_country as c";
8244 $sql .=
" WHERE t.fk_pays = c.rowid";
8246 $sql .=
" AND c.code = '" .
$db->escape($buyer->country_code) .
"'";
8248 $sql .=
" AND c.code = '" .
$db->escape($seller->country_code) .
"'";
8250 $sql .=
" AND t.taux = " . ((float) $vatratecleaned) .
" AND t.active = 1";
8251 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
8253 $sql .=
" AND t.code = '" .
$db->escape($vatratecode) .
"'";
8257 $resql =
$db->query($sql);
8259 $obj =
$db->fetch_object($resql);
8262 'rowid' => $obj->rowid,
8263 'code' => $obj->code,
8264 'rate' => $obj->rate,
8265 'localtax1' => $obj->localtax1,
8266 'localtax1_type' => $obj->localtax1_type,
8267 'localtax2' => $obj->localtax2,
8268 'localtax2_type' => $obj->localtax2_type,
8270 'accountancy_code_sell' => $obj->accountancy_code_sell,
8271 'accountancy_code_buy' => $obj->accountancy_code_buy
8303 dol_syslog(
"getLocalTaxesFromRate vatrate=" . $vatrate .
" local=" . $local);
8306 $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";
8307 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t";
8308 if ($firstparamisid) {
8309 $sql .=
" WHERE t.rowid = " . (int) $vatrate;
8311 $vatratecleaned = $vatrate;
8314 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
8315 $vatratecleaned = $reg[1];
8316 $vatratecode = $reg[2];
8319 $sql .=
", " . MAIN_DB_PREFIX .
"c_country as c";
8321 $countrycodetouse = ((empty($buyer) || empty($buyer->country_code)) ?
$mysoc->country_code : $buyer->country_code);
8322 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '" .
$db->escape($countrycodetouse) .
"'";
8324 $countrycodetouse = ((empty($seller) || empty($seller->country_code)) ?
$mysoc->country_code : $seller->country_code);
8325 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '" .
$db->escape($countrycodetouse) .
"'";
8327 $sql .=
" AND t.taux = " . ((float) $vatratecleaned) .
" AND t.active = 1";
8329 $sql .=
" AND t.code = '" .
$db->escape($vatratecode) .
"'";
8333 $resql =
$db->query($sql);
8335 $obj =
$db->fetch_object($resql);
8338 $vateratestring = $obj->rate . ($obj->code ?
' (' . $obj->code .
')' :
'');
8341 return array($obj->localtax1_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
8342 } elseif ($local == 2) {
8343 return array($obj->localtax2_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
8345 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);
8367 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
8375 $product->fetch($idprod);
8377 if ((
$mysoc->country_code == $thirdpartytouseforcountry->country_code)
8378 || (in_array(
$mysoc->country_code, array(
'FR',
'MC')) && in_array($thirdpartytouseforcountry->country_code, array(
'FR',
'MC')))
8379 || (in_array(
$mysoc->country_code, array(
'MQ',
'GP')) && in_array($thirdpartytouseforcountry->country_code, array(
'MQ',
'GP')))
8382 if ($idprodfournprice > 0) {
8383 $result = $product->get_buyprice($idprodfournprice, 0, 0,
'');
8385 $ret = $product->vatrate_supplier;
8386 if ($product->default_vat_code_supplier) {
8387 $ret .=
' (' . $product->default_vat_code_supplier .
')';
8393 $ret = $product->tva_tx;
8394 if ($product->default_vat_code) {
8395 $ret .=
' (' . $product->default_vat_code .
')';
8408 $sql =
"SELECT t.taux as vat_rate, t.code as default_vat_code";
8409 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t, " . MAIN_DB_PREFIX .
"c_country as c";
8410 $sql .=
" WHERE t.active = 1 AND t.fk_pays = c.rowid AND c.code = '" .
$db->escape($thirdpartytouseforcountry->country_code) .
"'";
8411 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
8412 $sql .=
" ORDER BY t.use_default DESC, t.taux DESC, t.code ASC, t.recuperableonly ASC";
8413 $sql .=
$db->plimit(1);
8415 $resql =
$db->query($sql);
8417 $obj =
$db->fetch_object($resql);
8419 $ret = $obj->vat_rate;
8420 if ($obj->default_vat_code) {
8421 $ret .=
' (' . $obj->default_vat_code .
')';
8445 dol_syslog(
"get_product_vat_for_country: ret=" . $ret);
8463 if (!class_exists(
'Product')) {
8464 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
8473 $result = $product->fetch($idprod);
8475 if (
$mysoc->country_code == $thirdpartytouseforcountry->country_code) {
8489 $sql =
"SELECT taux as vat_rate, localtax1, localtax2";
8490 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t, " . MAIN_DB_PREFIX .
"c_country as c";
8491 $sql .=
" WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code='" .
$db->escape($thirdpartytouseforcountry->country_code) .
"'";
8492 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
8493 $sql .=
" ORDER BY t.taux DESC, t.recuperableonly ASC";
8494 $sql .=
$db->plimit(1);
8496 $resql =
$db->query($sql);
8498 $obj =
$db->fetch_object($resql);
8501 $ret = $obj->localtax1;
8502 } elseif ($local == 2) {
8503 $ret = $obj->localtax2;
8511 dol_syslog(
"get_product_localtax_for_country: ret=" . $ret);
8537 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
8540 $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;
8542 if (empty($thirdparty_seller->country_code)) {
8543 $thirdparty_seller->country_code =
$mysoc->country_code;
8545 $seller_country_code = $thirdparty_seller->country_code;
8546 $seller_in_cee =
isInEEC($thirdparty_seller);
8548 if (empty($thirdparty_buyer->country_code)) {
8549 $thirdparty_buyer->country_code =
$mysoc->country_code;
8551 $buyer_country_code = $thirdparty_buyer->country_code;
8552 $buyer_in_cee =
isInEEC($thirdparty_buyer);
8554 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'));
8562 if ($seller_in_cee && $buyer_in_cee) {
8563 $isacompany = $thirdparty_buyer->
isACompany();
8564 if ($isacompany && !
getDolGlobalString(
'MAIN_USE_VAT_ZERO_FOR_COMPANIES_IN_EEC_EVEN_IF_VAT_ID_UNKNOWN')) {
8565 require_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
8573 $vatrule =
'VATRULE 0';
8579 if (empty($vatrule) && !$seller_use_vat) {
8587 $vatrule =
'VATRULE 1';
8591 if (empty($vatrule) && !empty($thirdparty_buyer->state_id)) {
8592 $sql =
"SELECT d.rowid, t.taux as vat_default_rate, t.code as vat_default_code ";
8593 $sql .=
" FROM " .
$db->prefix() .
"c_tva as t";
8594 $sql .=
" INNER JOIN " .
$db->prefix() .
"c_departements as d ON t.fk_department_buyer = d.rowid";
8595 $sql .=
" WHERE d.rowid = " . ((int) $thirdparty_buyer->state_id);
8596 $sql .=
" ORDER BY t.use_default DESC, t.taux DESC, t.code ASC, t.recuperableonly ASC";
8598 $res =
$db->query($sql);
8600 if (
$db->num_rows($res)) {
8601 $obj =
$db->fetch_object($res);
8603 $vatvalue = $obj->vat_default_rate .
' (' . $obj->vat_default_code .
')';
8604 $vatrule =
'VATRULE 2';
8611 if (empty($vatrule) && (
8612 ($seller_country_code == $buyer_country_code)
8613 || (in_array($seller_country_code, array(
'FR',
'MC')) && in_array($buyer_country_code, array(
'FR',
'MC')))
8614 || (in_array($seller_country_code, array(
'MQ',
'GP')) && in_array($buyer_country_code, array(
'MQ',
'GP')))
8619 if ($seller_country_code ==
'IN' &&
getDolGlobalString(
'MAIN_SALETAX_AUTOSWITCH_I_CS_FOR_INDIA')) {
8623 if (preg_match(
'/C+S-(\d+)/', $tmpvat, $reg) && $thirdparty_seller->state_id != $thirdparty_buyer->state_id) {
8625 $tmpvat = str_replace(
"C+S",
"I", $tmpvat);
8626 } elseif (preg_match(
'/I-(\d+)/', $tmpvat, $reg) && $thirdparty_seller->state_id == $thirdparty_buyer->state_id) {
8628 $tmpvat = str_replace(
"I",
"C+S", $tmpvat);
8632 $vatvalue = $tmpvat;
8633 $vatrule =
'VATRULE 3b';
8641 if (empty($vatrule) && ($seller_in_cee && $buyer_in_cee)) {
8642 $isacompany = $thirdparty_buyer->
isACompany();
8643 if ($isacompany && !
getDolGlobalString(
'MAIN_USE_VAT_ZERO_FOR_COMPANIES_IN_EEC_EVEN_IF_VAT_ID_UNKNOWN')) {
8644 require_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
8653 $vatrule =
'VATRULE 5';
8660 $vatrule =
'VATRULE 6';
8666 if (empty($vatrule) &&
getDolGlobalString(
'MAIN_USE_VAT_OF_PRODUCT_FOR_INDIVIDUAL_CUSTOMER_OUT_OF_EEC') && empty($buyer_in_cee)) {
8667 $isacompany = $thirdparty_buyer->
isACompany();
8670 $vatrule =
'VATRULE extra';
8683 $parameters = array(
'vatvalue' => $vatvalue,
'vatrule' => $vatrule);
8687 $reshook = $hookmanager->executeHooks(
'get_default_tva', $parameters, $tmpobject, $tmpaction);
8688 if ($reshook > 0 && !empty($hookmanager->resArray[
'vatvalue'])) {
8689 $vatvalue = $hookmanager->resArray[
'vatvalue'];
8690 $vatrule = $hookmanager->resArray[
'vatrule'];
8711 if ($idprodfournprice > 0) {
8712 if (!class_exists(
'ProductFournisseur')) {
8713 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.product.class.php';
8716 $prodprice->fetch_product_fournisseur_price($idprodfournprice);
8717 return $prodprice->fourn_tva_npr;
8718 } elseif ($idprod > 0) {
8719 if (!class_exists(
'Product')) {
8720 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
8723 $prod->fetch($idprod);
8724 return $prod->tva_npr;
8747 if (!is_object($thirdparty_seller)) {
8750 if (!is_object($thirdparty_buyer)) {
8754 if (empty($thirdparty_seller->country_code)) {
8755 $thirdparty_seller->country_code =
$mysoc->country_code;
8757 $seller_country_code = $thirdparty_seller->country_code;
8760 if (empty($thirdparty_buyer->country_code)) {
8761 $thirdparty_buyer->country_code =
$mysoc->country_code;
8763 $buyer_country_code = $thirdparty_buyer->country_code;
8767 if (
$mysoc->country_code ==
'ES') {
8768 if (is_numeric($thirdparty_buyer->localtax1_assuj) && !$thirdparty_buyer->localtax1_assuj) {
8773 if (is_numeric($thirdparty_seller->localtax1_assuj) && !$thirdparty_seller->localtax1_assuj) {
8776 if (!is_numeric($thirdparty_seller->localtax1_assuj) && $thirdparty_seller->localtax1_assuj ==
'localtax1off') {
8780 } elseif ($local == 2) {
8782 if (is_numeric($thirdparty_seller->localtax2_assuj) && !$thirdparty_seller->localtax2_assuj) {
8785 if (!is_numeric($thirdparty_seller->localtax2_assuj) && $thirdparty_seller->localtax2_assuj ==
'localtax2off') {
8790 if ($seller_country_code == $buyer_country_code) {
8805function yn($yesno, $format = 1, $color = 0)
8809 $result =
'unknown';
8811 if ($yesno ===
true || (
int) $yesno == 1 || (isset($yesno) && (strtolower($yesno) ==
'yes' || strtolower($yesno) ==
'true'))) {
8812 $result = $langs->trans(
'yes');
8813 if ($format == 1 || $format == 3) {
8814 $result = $langs->trans(
"Yes");
8817 $result =
'<input type="checkbox" value="1" checked disabled>';
8820 $result =
'<input type="checkbox" value="1" checked disabled> ' . $result;
8822 if ($format == 4 || !is_numeric($format)) {
8823 $result =
img_picto(is_numeric($format) ?
'' : $format,
'check');
8828 $result = $langs->trans(
"no");
8829 if ($format == 1 || $format == 3) {
8830 $result = $langs->trans(
"No");
8833 $result =
'<input type="checkbox" value="0" disabled>';
8836 $result =
'<input type="checkbox" value="0" disabled> ' . $result;
8838 if ($format == 4 || !is_numeric($format)) {
8839 $result =
img_picto(is_numeric($format) ?
'' : $format,
'uncheck');
8845 $classname =
'error';
8849 return '<span class="' . $classname .
'">' . $result .
'</span>';
8872function get_exdir($num, $level, $alpha, $withoutslash,
$object, $modulepart =
'')
8874 if (empty($modulepart) && is_object(
$object)) {
8875 if (!empty(
$object->module)) {
8876 $modulepart =
$object->module;
8877 } elseif (!empty(
$object->element)) {
8878 $modulepart =
$object->element;
8885 $arrayforoldpath = array(
'cheque' => 2,
'category' => 2,
'supplier_invoice' => 2,
'invoice_supplier' => 2,
'mailing' => 2,
'supplier_payment' => 2);
8887 $arrayforoldpath[
'product'] = 2;
8890 if (empty($level) && array_key_exists($modulepart, $arrayforoldpath)) {
8891 $level = $arrayforoldpath[$modulepart];
8893 if (!empty($level) && array_key_exists($modulepart, $arrayforoldpath)) {
8895 if (empty($num) && is_object(
$object)) {
8898 if (empty($alpha)) {
8899 $num = preg_replace(
'/([^0-9])/i',
'', $num);
8901 $num = preg_replace(
'/^.*\-/i',
'', $num);
8903 $num = substr(
"000" . $num, -$level);
8905 $path = substr($num, 0, 1);
8908 $path = substr($num, 1, 1) .
'/' . substr($num, 0, 1);
8911 $path = substr($num, 2, 1) .
'/' . substr($num, 1, 1) .
'/' . substr($num, 0, 1);
8917 if (in_array($modulepart, array(
'societe',
'thirdparty')) &&
$object instanceof
Societe) {
8925 if (empty($withoutslash) && !empty($path)) {
8940function dol_mkdir($dir, $dataroot =
'', $newmask =
'')
8942 dol_syslog(
"functions.lib::dol_mkdir: dir=" . $dir, LOG_INFO);
8947 if (@is_dir($dir_osencoded)) {
8955 if (!empty($dataroot)) {
8957 $dir = str_replace($dataroot .
'/',
'', $dir);
8958 $ccdir = $dataroot .
'/';
8961 $cdir = explode(
"/", $dir);
8962 $num = count($cdir);
8963 for ($i = 0; $i < $num; $i++) {
8965 $ccdir .=
'/' . $cdir[$i];
8967 $ccdir .= $cdir[$i];
8970 if (preg_match(
"/^.:$/", $ccdir, $regs)) {
8978 if (!@is_dir($ccdir_osencoded)) {
8979 dol_syslog(
"functions.lib::dol_mkdir: Directory '" . $ccdir .
"' is not found (does not exists or is outside open_basedir PHP setting).", LOG_DEBUG);
8982 $dirmaskdec = octdec((
string) $newmask);
8983 if (empty($newmask)) {
8986 $dirmaskdec |= octdec(
'0111');
8987 if (!@mkdir($ccdir_osencoded, $dirmaskdec)) {
8989 dol_syslog(
"functions.lib::dol_mkdir: Fails to create directory '" . $ccdir .
"' (no permission to write into parent or directory already exists).", LOG_WARNING);
8992 dol_syslog(
"functions.lib::dol_mkdir: Directory '" . $ccdir .
"' created", LOG_DEBUG);
9001 return ($nberr ? -$nberr : $nbcreated);
9012function dolChmod($filepath, $newmask =
'')
9014 if (!empty($newmask)) {
9015 @chmod($filepath, octdec($newmask));
9029 return '<span class="fieldrequired">*</span>';
9049function dol_string_nohtmltag($stringtoclean, $removelinefeed = 1, $pagecodeto =
'UTF-8', $strip_tags = 0, $removedoublespaces = 1)
9051 if (is_null($stringtoclean)) {
9055 if ($removelinefeed == 2) {
9056 $stringtoclean = preg_replace(
'/<br[^>]*>(\n|\r)+/ims',
'<br>', $stringtoclean);
9058 $temp = preg_replace(
'/<br[^>]*>/i',
"\n", $stringtoclean);
9063 $temp = str_replace(
'< ',
'__ltspace__', $temp);
9064 $temp = str_replace(
'<:',
'__lttwopoints__', $temp);
9067 $temp = strip_tags($temp);
9070 $pattern =
"/<[^<>]+>/";
9077 $tempbis = str_replace(
'<>',
'', $temp);
9078 $tempbis = preg_replace($pattern,
'', $tempbis);
9080 }
while ($tempbis != $temp);
9085 $temp = preg_replace(
'/<+([a-z]+)/i',
'\1', $temp);
9091 if ($removelinefeed == 1) {
9092 $temp = str_replace(array(
"\r\n",
"\r",
"\n"),
" ", $temp);
9096 if ($removedoublespaces) {
9097 while (strpos($temp,
" ")) {
9098 $temp = str_replace(
" ",
" ", $temp);
9102 $temp = str_replace(
'__ltspace__',
'< ', $temp);
9103 $temp = str_replace(
'__lttwopoints__',
'<:', $temp);
9127function dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles = 1, $removeclassattribute = 1, $cleanalsojavascript = 0, $allowiframe = 0, $allowed_tags = array(), $allowlink = 0, $allowscript = 0, $allowstyle = 0, $allowphp = 0)
9129 $sav_allowed_tags = $allowed_tags;
9131 if (empty($allowed_tags) || (is_string($allowed_tags) && preg_match(
'/^common/', $allowed_tags))) {
9132 $allowed_tags = array(
9189 $allowed_tags[] =
"comment";
9191 if (!in_array(
'iframe', $allowed_tags)) {
9192 $allowed_tags[] =
"iframe";
9196 if (!in_array(
'link', $allowed_tags)) {
9197 $allowed_tags[] =
"link";
9199 if (!in_array(
'meta', $allowed_tags)) {
9200 $allowed_tags[] =
"meta";
9204 if (!in_array(
'script', $allowed_tags)) {
9205 $allowed_tags[] =
"script";
9209 if (!in_array(
'style', $allowed_tags)) {
9210 $allowed_tags[] =
"style";
9213 if (is_string($sav_allowed_tags)) {
9214 $tmptags = explode(
',', $sav_allowed_tags);
9215 foreach ($tmptags as $tag) {
9216 if ($tag !=
'common') {
9217 $allowed_tags[] = $tag;
9223 $allowed_tags_string = implode(
"><", $allowed_tags);
9224 $allowed_tags_string =
'<' . $allowed_tags_string .
'>';
9226 $stringtoclean = str_replace(
'<!DOCTYPE html>',
'__!DOCTYPE_HTML__', $stringtoclean);
9231 $stringtoclean = preg_replace(
'/<!--([^>]*)-->/',
'<comment>\1</comment>', $stringtoclean);
9234 $allowed_tags[] =
"commentphp";
9235 $stringtoclean = preg_replace(
'/^<\?php([^"]+)\?>$/i',
'<commentphp>\1__</commentphp>', $stringtoclean);
9236 $stringtoclean = preg_replace(
'/"<\?php([^"]+)\?>"/i',
'"<commentphp>\1</commentphp>"', $stringtoclean);
9239 $stringtoclean = preg_replace(
'/:/i',
':', $stringtoclean);
9240 $stringtoclean = preg_replace(
'/:|�+58|:/i',
'', $stringtoclean);
9243 $temp = strip_tags($stringtoclean, $allowed_tags_string);
9245 if ($cleanalsosomestyles) {
9247 $temp = preg_replace(
'/position\s*:\s*(absolute|fixed)/i',
'', $temp);
9248 $temp = preg_replace(
'/z-index\s*:/i',
'', $temp);
9250 if ($removeclassattribute) {
9251 $temp = preg_replace(
'/(<[^>]+)\s+class=((["\']).*?\\3|\\w*)/i',
'\\1', $temp);
9256 if ($cleanalsojavascript) {
9257 $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);
9260 $temp = str_replace(
'__!DOCTYPE_HTML__',
'<!DOCTYPE html>', $temp);
9263 $temp = preg_replace(
'/<commentphp>(.*)<\/commentphp>/',
'<?php\1?>', $temp);
9266 $temp = preg_replace(
'/<comment>([^>]*)<\/comment>/',
'<!--\1-->', $temp);
9287 if (is_null($allowed_attributes)) {
9288 $allowed_attributes = array(
9322 if (!in_array(
"content", $allowed_attributes)) {
9323 $allowed_attributes[] =
"content";
9325 if (!in_array(
"http-equiv", $allowed_attributes)) {
9326 $allowed_attributes[] =
"http-equiv";
9329 if (class_exists(
'DOMDocument') && !empty($stringtoclean)) {
9331 $stringtoclean =
'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body>' . $stringtoclean .
'</body></html>';
9334 $dom =
new DOMDocument(
'',
'UTF-8');
9336 $savwarning = error_reporting();
9337 error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE);
9338 $dom->loadHTML($stringtoclean, LIBXML_ERR_NONE | LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD | LIBXML_NONET | LIBXML_NOWARNING | LIBXML_NOXMLDECL);
9339 error_reporting($savwarning);
9341 if ($dom instanceof DOMDocument) {
9342 for ($els = $dom->getElementsByTagname(
'*'), $i = $els->length - 1; $i >= 0; $i--) {
9343 $el = $els->item($i);
9344 if (!$el instanceof DOMElement) {
9347 $attrs = $el->attributes;
9348 for ($ii = $attrs->length - 1; $ii >= 0; $ii--) {
9350 if (!empty($attrs->item($ii)->name)) {
9351 if (! in_array($attrs->item($ii)->name, $allowed_attributes)) {
9353 $els->item($i)->removeAttribute($attrs->item($ii)->name);
9354 } elseif (in_array($attrs->item($ii)->name, array(
'style'))) {
9356 $valuetoclean = $attrs->item($ii)->value;
9358 if (isset($valuetoclean)) {
9360 $oldvaluetoclean = $valuetoclean;
9361 $valuetoclean = preg_replace(
'/\/\*.*\*\//m',
'', $valuetoclean);
9362 $valuetoclean = preg_replace(
'/position\s*:\s*[a-z]+/mi',
'', $valuetoclean);
9363 if ($els->item($i)->tagName ==
'a') {
9364 $valuetoclean = preg_replace(
'/display\s*:/mi',
'', $valuetoclean);
9365 $valuetoclean = preg_replace(
'/z-index\s*:/mi',
'', $valuetoclean);
9366 $valuetoclean = preg_replace(
'/\s+(top|left|right|bottom)\s*:/mi',
'', $valuetoclean);
9370 $valuetoclean = preg_replace(
'/(logout|passwordforgotten)\.php/mi',
'', $valuetoclean);
9371 $valuetoclean = preg_replace(
'/action=/mi',
'', $valuetoclean);
9372 }
while ($oldvaluetoclean != $valuetoclean);
9375 $attrs->item($ii)->value = $valuetoclean;
9382 $dom->encoding =
'UTF-8';
9384 $return = $dom->saveHTML();
9388 $return = preg_replace(
'/^' . preg_quote(
'<html><head><',
'/') .
'[^<>]*' . preg_quote(
'></head><body>',
'/') .
'/',
'', $return);
9389 $return = preg_replace(
'/' . preg_quote(
'</body></html>',
'/') .
'$/',
'', trim($return));
9391 return trim($return);
9393 return $stringtoclean;
9410 $temp = $stringtoclean;
9411 foreach ($disallowed_tags as $tagtoremove) {
9412 $temp = preg_replace(
'/<\/?' . $tagtoremove .
'>/',
'', $temp);
9413 $temp = preg_replace(
'/<\/?' . $tagtoremove .
'\s+[^>]*>/',
'', $temp);
9416 if ($cleanalsosomestyles) {
9417 $temp = preg_replace(
'/position\s*:\s*(absolute|fixed)\s*!\s*important/',
'', $temp);
9435 if ($nboflines == 1) {
9437 $firstline = preg_replace(
'/<br[^>]*>.*$/s',
'', $text);
9438 $firstline = preg_replace(
'/<div[^>]*>.*$/s',
'', $firstline);
9441 $firstline = preg_replace(
'/[\n\r].*/',
'', $text);
9446 return $firstline . (isset($firstline) && isset($text) && (strlen($firstline) != strlen($text)) ?
'...' :
'');
9450 $text = preg_replace(
'/\n/',
'', $text);
9452 $repTable = array(
"\t" =>
" ",
"\n" =>
" ",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
9454 $repTable = array(
"\t" =>
" ",
"\n" =>
"<br>",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
9457 $text = strtr($text, $repTable);
9458 if ($charset ==
'UTF-8') {
9459 $pattern =
'/(<br[^>]*>)/Uu';
9462 $pattern =
'/(<br[^>]*>)/U';
9464 $a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
9469 $lastaddediscontent = 1;
9470 while ($countline < $nboflines && isset($a[$i])) {
9471 if (preg_match(
'/<br[^>]*>/', $a[$i])) {
9472 if (array_key_exists($i + 1, $a) && !empty($a[$i + 1])) {
9473 $firstline .= ($ishtml ?
"<br>\n" :
"\n");
9475 if (!$lastaddediscontent) {
9478 $lastaddediscontent = 0;
9481 $firstline .= $a[$i];
9482 $lastaddediscontent = 1;
9488 $adddots = (isset($a[$i]) && (!preg_match(
'/<br[^>]*>/', $a[$i]) || (array_key_exists($i + 1, $a) && !empty($a[$i + 1]))));
9490 $ret = $firstline . ($adddots ?
'...' :
'');
9508function dol_nl2br($stringtoencode, $nl2brmode = 0, $forxml =
false)
9510 if (is_null($stringtoencode)) {
9515 return nl2br($stringtoencode, $forxml);
9517 $ret = preg_replace(
'/(\r\n|\r|\n)/i', ($forxml ?
'<br />' :
'<br>'), $stringtoencode);
9531function dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox = 0, $check =
'restricthtml')
9533 if (empty($nouseofiframesandbox) &&
getDolGlobalString(
'MAIN_SECURITY_USE_SANDBOX_FOR_HTMLWITHNOJS')) {
9538 return $stringtoencode;
9540 $out = $stringtoencode;
9544 $oldstringtoclean = $out;
9552 if (!empty($out) &&
getDolGlobalInt(
'MAIN_RESTRICTHTML_ONLY_VALID_HTML') && $check !=
'restricthtmlallowunvalid') {
9554 libxml_use_internal_errors(
false);
9555 if (LIBXML_VERSION < 20900) {
9559 libxml_disable_entity_loader(
true);
9562 $dom =
new DOMDocument();
9570 $out =
'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body><div class="tricktoremove">' . $out .
'</div></body></html>';
9574 $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>';
9580 $out = preg_replace_callback(
9581 '/__\[([0-9a-zA-Z_]+)\]__/',
9587 return '__BRACKETSTART' . $m[1] .
'BRACKETEND__';
9592 $dom->loadHTML($out, LIBXML_HTML_NODEFDTD | LIBXML_ERR_NONE | LIBXML_HTML_NOIMPLIED | LIBXML_NONET | LIBXML_NOWARNING | LIBXML_NOERROR | LIBXML_NOXMLDECL);
9594 $dom->encoding =
'UTF-8';
9598 foreach ($dom->getElementsByTagName(
'*') as $el) {
9599 if (!$el instanceof DOMElement) {
9604 if ($el->hasAttribute(
'style')) {
9606 $style = $el->getAttribute(
'style');
9609 $style = preg_replace(
'/z-index\s*:/i',
'', $style);
9610 $style = preg_replace(
'/position\s*:/i',
'', $style);
9611 $style = preg_replace(
'/top\s*:/i',
'', $style);
9612 $style = preg_replace(
'/left\s*:/i',
'', $style);
9613 $style = preg_replace(
'/background\s*:/i',
'', $style);
9619 if (trim($style) ===
'') {
9621 $el->removeAttribute(
'style');
9624 $el->setAttribute(
'style', $style);
9630 $out = trim($dom->saveHTML());
9633 $out = preg_replace_callback(
9634 '/__BRACKETSTART([0-9a-zA-Z_]+)BRACKETEND__/',
9640 return '__[' . $m[1] .
']__';
9647 $out = preg_replace(
'/^' . preg_quote(
'<html><head><',
'/') .
'[^<>]+' . preg_quote(
'></head><body><div class="tricktoremove">',
'/') .
'/',
'', $out);
9648 $out = preg_replace(
'/' . preg_quote(
'</div></body></html>',
'/') .
'$/',
'', trim($out));
9653 $out = str_replace(
'<br>',
'', $out);
9658 $out =
'InvalidHTMLStringCantBeCleaned ' . $e->getMessage();
9665 if (!empty($out) &&
getDolGlobalInt(
'MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY') && !in_array($check, array(
'restricthtmlallowunvalid',
'restricthtmlallowlinkscript')) && $outishtml) {
9671 if (extension_loaded(
'tidy') && class_exists(
"tidy")) {
9678 'quote-marks' =>
false,
9679 'doctype' =>
'strict',
9680 'show-body-only' =>
true,
9681 "indent-attributes" =>
false,
9682 "vertical-space" =>
false,
9685 'preserve-entities' =>
true
9695 $out = $tidy->repairString($out, $config,
'utf8');
9704 $out =
'InvalidHTMLStringCantBeCleaned ' . $e->getMessage();
9710 $out = preg_replace(
'/[\x{200B}-\x{200D}\x{FEFF}]/u',
' ', $out);
9713 $out = preg_replace(
'/&(tab|newline);/i',
' ', $out);
9717 $out = preg_replace(
'/'/i',
''', $out);
9722 if (function_exists(
'realCharForNumericEntities')) {
9723 $out = preg_replace_callback(
9724 '/&#(x?[0-9][0-9a-f]+;?)/i',
9729 static function ($m) {
9737 $out = preg_replace(
'/&#x?[0-9]+/i',
'', $out);
9740 if ($check ==
'restricthtmlallowlinkscript') {
9742 } elseif ($check ==
'restricthtmlallowclass' || $check ==
'restricthtmlallowunvalid') {
9744 } elseif ($check ==
'restricthtmlallowiframe') {
9757 $out = preg_replace(
'/'/i',
"'", $out);
9761 $out = preg_replace(
'/on(mouse|drag|key|load|touch|pointer|select|transition)[a-z]*\s*=/i',
'', $out);
9762 $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);
9763 $out = preg_replace(
'/on(dblclick|drop|durationchange|emptied|end|ended|error|focus(in|out)?|formdata|gotpointercapture|hashchange|input|invalid)[a-z]*\s*=/i',
'', $out);
9764 $out = preg_replace(
'/on(lostpointercapture|offline|online|pagehide|pageshow)[a-z]*\s*=/i',
'', $out);
9765 $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);
9766 $out = preg_replace(
'/on(timeupdate|toggle|unload|volumechange|waiting|wheel)[a-z]*\s*=/i',
'', $out);
9768 $out = preg_replace(
'/on(repeat|begin|finish|beforeinput)[a-z]*\s*=/i',
'', $out);
9769 }
while ($oldstringtoclean != $out);
9776 $tmpout = preg_replace(
'/<img src="data:/mi',
'<__IMG_SRC_DATA__ src="data:', $out);
9777 preg_match_all(
'/(<img|url\(|<link)/i', $tmpout, $reg);
9778 $nblinks = count($reg[0]);
9779 if ($nblinks >
getDolGlobalInt(
"MAIN_SECURITY_MAX_IMG_IN_HTML_CONTENT", 1000)) {
9780 $out =
'ErrorTooManyLinksIntoHTMLString';
9783 if (
getDolGlobalInt(
'MAIN_DISALLOW_URL_INTO_DESCRIPTIONS') == 2 || $check ==
'restricthtmlnolink') {
9785 $out =
'ErrorHTMLLinksNotAllowed';
9787 } elseif (
getDolGlobalInt(
'MAIN_DISALLOW_URL_INTO_DESCRIPTIONS') == 1) {
9792 $pattern =
'/src=["\']?(http[^"\']+)|url\(["\']?(http[^\)]+)/';
9797 if (preg_match_all($pattern, $out, $matches)) {
9800 foreach ($matches[1] as $tmpval) {
9801 if (!empty($tmpval)) {
9805 foreach ($matches[2] as $tmpval) {
9806 if (!empty($tmpval)) {
9814 foreach ($urls as $url) {
9816 $parsedurl = parse_url($url);
9817 if (!empty($parsedurl)) {
9826 if (empty($firstexturl)) {
9827 $firstexturl = $url;
9828 } elseif (empty($secondexturl)) {
9829 $secondexturl = $url;
9835 $out =
'ErrorHTMLExternalLinksNotAllowed (Example: '.$firstexturl.($secondexturl ?
' '.$secondexturl :
'').
')';
9864function dol_htmlentitiesbr($stringtoencode, $nl2brmode = 0, $pagecodefrom =
'UTF-8', $removelasteolbr = 1)
9866 if (is_null($stringtoencode)) {
9870 $newstring = $stringtoencode;
9872 $newstring = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>/i',
'<br>', $newstring);
9873 if ($removelasteolbr) {
9874 $newstring = preg_replace(
'/<br>$/i',
'', $newstring);
9876 $newstring = preg_replace(
'/[\x{200B}-\x{200D}\x{FEFF}]/u',
' ', $newstring);
9877 $newstring = strtr($newstring, array(
'&' =>
'__PROTECTand__',
'<' =>
'__PROTECTlt__',
'>' =>
'__PROTECTgt__',
'"' =>
'__PROTECTdquot__'));
9879 $newstring = strtr($newstring, array(
'__PROTECTand__' =>
'&',
'__PROTECTlt__' =>
'<',
'__PROTECTgt__' =>
'>',
'__PROTECTdquot__' =>
'"'));
9881 if ($removelasteolbr) {
9882 $newstring = preg_replace(
'/(\r\n|\r|\n)$/i',
'', $newstring);
9901 $ret = preg_replace(
'/' .
"\r\n" .
'<br(\s[\sa-zA-Z_="]*)?\/?>/i',
"<br>", $ret);
9902 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>' .
"\r\n" .
'/i',
"\r\n", $ret);
9903 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>' .
"\n" .
'/i',
"\n", $ret);
9904 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>/i',
"\n", $ret);
9916 $ret = preg_replace(
'/ $/i',
"", $stringtodecode);
9917 $ret = preg_replace(
'/(<br>|<br(\s[\sa-zA-Z_="]*)?\/?>|' .
"\n" .
'|' .
"\r" .
')+$/i',
"", $ret);
9933 if ($keepsomeentities) {
9934 $newstring = strtr($newstring, array(
'&' =>
'__andamp__',
'<' =>
'__andlt__',
'>' =>
'__andgt__',
'"' =>
'__dquot__'));
9936 $newstring = html_entity_decode((
string) $newstring, (
int) $b, (
string)
$c);
9937 if ($keepsomeentities) {
9938 $newstring = strtr($newstring, array(
'__andamp__' =>
'&',
'__andlt__' =>
'<',
'__andgt__' =>
'>',
'__dquot__' =>
'"'));
9954function dol_htmlentities($string, $flags = ENT_QUOTES | ENT_SUBSTITUTE, $encoding =
'UTF-8', $double_encode =
false)
9956 return htmlentities($string, $flags, $encoding, $double_encode);
9975 for ($scursor = 0; $scursor < $len; $scursor++) {
9976 $ordchar = ord($s[$scursor]);
9978 if ($ordchar < 32 && $ordchar != 13 && $ordchar != 10) {
9981 } elseif ($ordchar > 126 && $ordchar < 160) {
9985 $out .= $s[$scursor];
10007 $arraystring = explode(
"\n", $s);
10008 $nb = count($arraystring);
10025 $repTable = array(
"\t" =>
" ",
"\n" =>
"<br>",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
10027 $repTable = array(
"\t" =>
" ",
"\n" =>
" ",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
10030 $text = strtr($text, $repTable);
10031 if ($charset ==
'UTF-8') {
10032 $pattern =
'/(<br[^>]*>)/Uu';
10035 $pattern =
'/(<br[^>]*>)/U';
10037 $a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
10039 $nblines = (int) floor((count($a) + 1) / 2);
10041 if ($maxlinesize) {
10042 foreach ($a as $line) {
10045 $line_dec = html_entity_decode($line);
10047 $line_dec = wordwrap($line_dec, $maxlinesize,
'\n',
true);
10048 $nblines += substr_count($line_dec,
'\n');
10068 if (is_null($msg)) {
10072 if ($option == 1) {
10073 if (preg_match(
'/<(html|link|script)/i', $msg)) {
10075 } elseif (preg_match(
'/<body/i', $msg)) {
10077 } elseif (preg_match(
'/<\/textarea/i', $msg)) {
10079 } elseif (preg_match(
'/<(b|em|i|u)(\s+[^>]+)?>/i', $msg)) {
10081 } elseif (preg_match(
'/<br/i', $msg)) {
10087 $msg = preg_replace(
'/https?:\/\/[^"\'\s]+/i',
'', $msg);
10088 if (preg_match(
'/<(html|link|script|body)/i', $msg)) {
10090 } elseif (preg_match(
'/<\/textarea/i', $msg)) {
10092 } elseif (preg_match(
'/<(b|em|i|u)(\s+[^>]+)?>/i', $msg)) {
10094 } elseif (preg_match(
'/<(br|hr)\/>/i', $msg)) {
10096 } elseif (preg_match(
'/<(br|hr|div|font|li|p|span|strong|table)>/i', $msg)) {
10098 } elseif (preg_match(
'/<(br|hr|div|font|li|p|span|strong|table)\s+[^<>\/]*\/?>/i', $msg)) {
10100 } elseif (preg_match(
'/<img\s+[^<>]*src[^<>]*>/i', $msg)) {
10102 } elseif (preg_match(
'/<a\s+[^<>]*href[^<>]*>/i', $msg)) {
10104 } elseif (preg_match(
'/<h[0-9]>/i', $msg)) {
10106 } elseif (preg_match(
'/&[A-Z0-9]{1,6};/i', $msg)) {
10109 } elseif (preg_match(
'/&#[0-9]{2,3};/i', $msg)) {
10111 } elseif (preg_match(
'/&#x[a-f0-9][a-f0-9];/i', $msg)) {
10133function dol_concatdesc($text1, $text2, $forxml =
false, $invert =
false)
10135 if (!empty($invert)) {
10143 $ret .= (!empty($text1) && !empty($text2)) ? ((
dol_textishtml($text1) ||
dol_textishtml($text2)) ? ($forxml ?
"<br >\n" :
"<br>\n") :
"\n") :
"";
10158 return $text1.$text2;
10170 if (!is_string($callback)) {
10171 throw new InvalidArgumentException(
"Les callbacks sont désactivés.");
10174 $allowed_callbacks = [
'strtolower',
'strtoupper',
'intval'];
10175 if (!in_array($callback, $allowed_callbacks,
true)) {
10176 throw new InvalidArgumentException(
"Callback function not allowed.");
10178 return array_map($callback, $array);
10195function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude =
null,
$object =
null, $include =
null)
10199 $substitutionarray = array();
10201 if ((empty($exclude) || !in_array(
'user', $exclude)) && (empty($include) || in_array(
'user', $include)) && $user instanceof
User) {
10205 $emailsendersignature = $user->signature;
10206 $usersignature = $user->signature;
10207 $substitutionarray = array_merge($substitutionarray, array(
10208 '__SENDEREMAIL_SIGNATURE__' => (
string) ((!
getDolGlobalString(
'MAIN_MAIL_DO_NOT_USE_SIGN')) ? ($onlykey == 2 ?
dol_trunc(
'SignatureFromTheSelectedSenderProfile', 30) : $emailsendersignature) :
''),
10212 if (is_object($user) && ($user instanceof
User)) {
10213 $substitutionarray = array_merge($substitutionarray, array(
10214 '__USER_ID__' => (
string) $user->id,
10215 '__USER_LOGIN__' => (
string) $user->login,
10216 '__USER_EMAIL__' => (
string) $user->email,
10217 '__USER_PHONE__' => (
string)
dol_print_phone($user->office_phone,
'', 0, 0,
'',
" ",
'',
'', -1),
10218 '__USER_PHONEPRO__' => (
string)
dol_print_phone($user->user_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
10219 '__USER_PHONEMOBILE__' => (
string)
dol_print_phone($user->personal_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
10220 '__USER_FAX__' => (
string) $user->office_fax,
10221 '__USER_LASTNAME__' => (
string) $user->lastname,
10222 '__USER_FIRSTNAME__' => (
string) $user->firstname,
10223 '__USER_FULLNAME__' => (
string) $user->getFullName($outputlangs),
10224 '__USER_SUPERVISOR_ID__' => (
string) ($user->fk_user ? $user->fk_user :
'0'),
10225 '__USER_JOB__' => (
string) $user->job,
10227 '__USER_VCARD_URL__' => (
string) $user->getOnlineVirtualCardUrl(
'',
'external')
10231 if ((empty($exclude) || !in_array(
'mycompany', $exclude)) && is_object(
$mysoc) && (empty($include) || in_array(
'mycompany', $include))) {
10232 $substitutionarray = array_merge($substitutionarray, array(
10233 '__MYCOMPANY_NAME__' =>
$mysoc->name,
10234 '__MYCOMPANY_EMAIL__' =>
$mysoc->email,
10235 '__MYCOMPANY_URL__' =>
$mysoc->url,
10237 '__MYCOMPANY_PHONEMOBILE__' =>
dol_print_phone((
string)
$mysoc->phone_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
10239 '__MYCOMPANY_PROFID1__' =>
$mysoc->idprof1,
10240 '__MYCOMPANY_PROFID2__' =>
$mysoc->idprof2,
10241 '__MYCOMPANY_PROFID3__' =>
$mysoc->idprof3,
10242 '__MYCOMPANY_PROFID4__' =>
$mysoc->idprof4,
10243 '__MYCOMPANY_PROFID5__' =>
$mysoc->idprof5,
10244 '__MYCOMPANY_PROFID6__' =>
$mysoc->idprof6,
10245 '__MYCOMPANY_PROFID7__' =>
$mysoc->idprof7,
10246 '__MYCOMPANY_PROFID8__' =>
$mysoc->idprof8,
10247 '__MYCOMPANY_PROFID9__' =>
$mysoc->idprof9,
10248 '__MYCOMPANY_PROFID10__' =>
$mysoc->idprof10,
10249 '__MYCOMPANY_CAPITAL__' =>
$mysoc->capital,
10250 '__MYCOMPANY_FULLADDRESS__' => (method_exists(
$mysoc,
'getFullAddress') ?
$mysoc->getFullAddress(1,
', ') :
''),
10252 '__MYCOMPANY_VATNUMBER__' =>
$mysoc->tva_intra,
10253 '__MYCOMPANY_ZIP__' =>
$mysoc->zip,
10254 '__MYCOMPANY_TOWN__' =>
$mysoc->town,
10255 '__MYCOMPANY_STATE__' =>
$mysoc->state,
10256 '__MYCOMPANY_COUNTRY__' =>
$mysoc->country,
10257 '__MYCOMPANY_COUNTRY_ID__' =>
$mysoc->country_id,
10258 '__MYCOMPANY_COUNTRY_CODE__' =>
$mysoc->country_code,
10259 '__MYCOMPANY_CURRENCY_CODE__' =>
$conf->currency
10263 if (($onlykey || is_object(
$object)) && (empty($exclude) || !in_array(
'object', $exclude)) && (empty($include) || in_array(
'object', $include))) {
10265 $substitutionarray[
'__ID__'] =
'__ID__';
10266 $substitutionarray[
'__REF__'] =
'__REF__';
10267 $substitutionarray[
'__NEWREF__'] =
'__NEWREF__';
10268 $substitutionarray[
'__LABEL__'] =
'__LABEL__';
10269 $substitutionarray[
'__REF_CLIENT__'] =
'__REF_CLIENT__';
10270 $substitutionarray[
'__REF_SUPPLIER__'] =
'__REF_SUPPLIER__';
10271 $substitutionarray[
'__NOTE_PUBLIC__'] =
'__NOTE_PUBLIC__';
10272 $substitutionarray[
'__NOTE_PRIVATE__'] =
'__NOTE_PRIVATE__';
10273 $substitutionarray[
'__EXTRAFIELD_XXX__'] =
'__EXTRAFIELD_XXX__';
10276 $substitutionarray[
'__THIRDPARTY_ID__'] =
'__THIRDPARTY_ID__';
10277 $substitutionarray[
'__THIRDPARTY_NAME__'] =
'__THIRDPARTY_NAME__';
10278 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] =
'__THIRDPARTY_NAME_ALIAS__';
10279 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] =
'__THIRDPARTY_CODE_CLIENT__';
10280 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] =
'__THIRDPARTY_CODE_FOURNISSEUR__';
10281 $substitutionarray[
'__THIRDPARTY_EMAIL__'] =
'__THIRDPARTY_EMAIL__';
10283 $substitutionarray[
'__THIRDPARTY_URL__'] =
'__THIRDPARTY_URL__';
10285 $substitutionarray[
'__THIRDPARTY_PHONE__'] =
'__THIRDPARTY_PHONE__';
10286 $substitutionarray[
'__THIRDPARTY_FAX__'] =
'__THIRDPARTY_FAX__';
10287 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] =
'__THIRDPARTY_ADDRESS__';
10288 $substitutionarray[
'__THIRDPARTY_ZIP__'] =
'__THIRDPARTY_ZIP__';
10289 $substitutionarray[
'__THIRDPARTY_TOWN__'] =
'__THIRDPARTY_TOWN__';
10290 $substitutionarray[
'__THIRDPARTY_STATE__'] =
'__THIRDPARTY_STATE__';
10291 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] =
'__THIRDPARTY_IDPROF1__';
10292 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] =
'__THIRDPARTY_IDPROF2__';
10293 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] =
'__THIRDPARTY_IDPROF3__';
10294 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] =
'__THIRDPARTY_IDPROF4__';
10295 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] =
'__THIRDPARTY_IDPROF5__';
10296 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] =
'__THIRDPARTY_IDPROF6__';
10297 $substitutionarray[
'__THIRDPARTY_IDPROF7__'] =
'__THIRDPARTY_IDPROF7__';
10298 $substitutionarray[
'__THIRDPARTY_IDPROF8__'] =
'__THIRDPARTY_IDPROF8__';
10299 $substitutionarray[
'__THIRDPARTY_IDPROF9__'] =
'__THIRDPARTY_IDPROF9__';
10300 $substitutionarray[
'__THIRDPARTY_IDPROF10__'] =
'__THIRDPARTY_IDPROF10__';
10301 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] =
'__THIRDPARTY_TVAINTRA__';
10302 $substitutionarray[
'__THIRDPARTY_NOTE_PUBLIC__'] =
'__THIRDPARTY_NOTE_PUBLIC__';
10303 $substitutionarray[
'__THIRDPARTY_NOTE_PRIVATE__'] =
'__THIRDPARTY_NOTE_PRIVATE__';
10305 if (
isModEnabled(
'member') && (!is_object(
$object) ||
$object->element ==
'adherent') && (empty($exclude) || !in_array(
'member', $exclude)) && (empty($include) || in_array(
'member', $include))) {
10306 $substitutionarray[
'__MEMBER_ID__'] =
'__MEMBER_ID__';
10307 $substitutionarray[
'__MEMBER_TITLE__'] =
'__MEMBER_TITLE__';
10308 $substitutionarray[
'__MEMBER_FIRSTNAME__'] =
'__MEMBER_FIRSTNAME__';
10309 $substitutionarray[
'__MEMBER_LASTNAME__'] =
'__MEMBER_LASTNAME__';
10310 $substitutionarray[
'__MEMBER_USER_LOGIN_INFORMATION__'] =
'Login and pass of the external user account';
10315 if (
isModEnabled(
'ticket') && (!is_object(
$object) ||
$object->element ==
'ticket') && (empty($exclude) || !in_array(
'ticket', $exclude)) && (empty($include) || in_array(
'ticket', $include))) {
10316 $substitutionarray[
'__TICKET_TRACKID__'] =
'__TICKET_TRACKID__';
10317 $substitutionarray[
'__TICKET_SUBJECT__'] =
'__TICKET_SUBJECT__';
10318 $substitutionarray[
'__TICKET_TYPE__'] =
'__TICKET_TYPE__';
10319 $substitutionarray[
'__TICKET_SEVERITY__'] =
'__TICKET_SEVERITY__';
10320 $substitutionarray[
'__TICKET_CATEGORY__'] =
'__TICKET_CATEGORY__';
10321 $substitutionarray[
'__TICKET_ANALYTIC_CODE__'] =
'__TICKET_ANALYTIC_CODE__';
10322 $substitutionarray[
'__TICKET_MESSAGE__'] =
'__TICKET_MESSAGE__';
10323 $substitutionarray[
'__TICKET_PROGRESSION__'] =
'__TICKET_PROGRESSION__';
10324 $substitutionarray[
'__TICKET_USER_ASSIGN__'] =
'__TICKET_USER_ASSIGN__';
10326 if (
isModEnabled(
'recruitment') && (!is_object(
$object) ||
$object->element ==
'recruitmentcandidature') && (empty($exclude) || !in_array(
'recruitment', $exclude)) && (empty($include) || in_array(
'recruitment', $include))) {
10327 $substitutionarray[
'__CANDIDATE_FULLNAME__'] =
'__CANDIDATE_FULLNAME__';
10328 $substitutionarray[
'__CANDIDATE_FIRSTNAME__'] =
'__CANDIDATE_FIRSTNAME__';
10329 $substitutionarray[
'__CANDIDATE_LASTNAME__'] =
'__CANDIDATE_LASTNAME__';
10331 if (
isModEnabled(
'holiday') && (!is_object(
$object) ||
$object->element ==
'holiday') && (empty($exclude) || !in_array(
'holiday', $exclude)) && (empty($include) || in_array(
'holiday', $include))) {
10332 $substitutionarray[
'__HOLIDAY_ARRAY_PER_EMPLOYEE_FOR_PERIOD__'] =
'__HOLIDAY_ARRAY_PER_EMPLOYEE_FOR_PERIOD__';
10334 if (
isModEnabled(
'project') && (empty($exclude) || !in_array(
'project', $exclude)) && (empty($include) || in_array(
'project', $include))) {
10335 $substitutionarray[
'__PROJECT_ID__'] =
'__PROJECT_ID__';
10336 $substitutionarray[
'__PROJECT_REF__'] =
'__PROJECT_REF__';
10337 $substitutionarray[
'__PROJECT_NAME__'] =
'__PROJECT_NAME__';
10341 if (
isModEnabled(
'contract') && (!is_object(
$object) ||
$object->element ==
'contract') && (empty($exclude) || !in_array(
'contract', $exclude)) && (empty($include) || in_array(
'contract', $include))) {
10342 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE__'] =
'Highest date planned for a service start';
10343 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATETIME__'] =
'Highest date and hour planned for service start';
10344 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE__'] =
'Lowest data for planned expiration of service';
10345 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATETIME__'] =
'Lowest date and hour for planned expiration of service';
10347 if (
isModEnabled(
"propal") && (!is_object(
$object) ||
$object->element ==
'propal') && (empty($exclude) || !in_array(
'propal', $exclude)) && (empty($include) || in_array(
'propal', $include))) {
10348 $substitutionarray[
'__ONLINE_SIGN_URL__'] =
'ToOfferALinkForOnlineSignature';
10350 if (
isModEnabled(
"intervention") && (!is_object(
$object) ||
$object->element ==
'fichinter') && (empty($exclude) || !in_array(
'intervention', $exclude)) && (empty($include) || in_array(
'intervention', $include))) {
10351 $substitutionarray[
'__ONLINE_SIGN_FICHINTER_URL__'] =
'ToOfferALinkForOnlineSignature';
10353 $substitutionarray[
'__ONLINE_PAYMENT_URL__'] =
'UrlToPayOnlineIfApplicable';
10354 $substitutionarray[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'TextAndUrlToPayOnlineIfApplicable';
10355 $substitutionarray[
'__SECUREKEYPAYMENT__'] =
'Security key (if key is not unique per record)';
10356 $substitutionarray[
'__SECUREKEYPAYMENT_MEMBER__'] =
'Security key for payment on a member subscription (one key per member)';
10357 $substitutionarray[
'__SECUREKEYPAYMENT_ORDER__'] =
'Security key for payment on an order';
10358 $substitutionarray[
'__SECUREKEYPAYMENT_INVOICE__'] =
'Security key for payment on an invoice';
10359 $substitutionarray[
'__SECUREKEYPAYMENT_CONTRACTLINE__'] =
'Security key for payment on a service of a contract';
10361 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
'Direct download url of a proposal';
10362 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
'Direct download url of an order';
10363 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
'Direct download url of an invoice';
10364 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
'Direct download url of a contract';
10365 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
'Direct download url of a supplier proposal';
10366 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_ORDER__'] =
'Direct download url of a supplier order';
10367 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_INVOICE__'] =
'Direct download url of a supplier invoice';
10370 $substitutionarray[
'__SHIPPINGTRACKNUM__'] =
'Shipping tracking number';
10371 $substitutionarray[
'__SHIPPINGTRACKNUMURL__'] =
'Shipping tracking url';
10372 $substitutionarray[
'__SHIPPINGMETHOD__'] =
'Shipping method';
10375 $substitutionarray[
'__RECEPTIONTRACKNUM__'] =
'Shipping tracking number of shipment';
10376 $substitutionarray[
'__RECEPTIONTRACKNUMURL__'] =
'Shipping tracking url';
10379 '@phan-var-force Adherent|Delivery $object';
10381 $substitutionarray[
'__ID__'] =
$object->id;
10382 $substitutionarray[
'__REF__'] =
$object->ref;
10383 $substitutionarray[
'__NEWREF__'] =
$object->newref;
10385 $substitutionarray[
'__REF_CLIENT__'] = (isset(
$object->ref_client) ?
$object->ref_client : (isset(
$object->ref_customer) ?
$object->ref_customer :
null));
10386 $substitutionarray[
'__REF_SUPPLIER__'] = (isset(
$object->ref_supplier) ?
$object->ref_supplier :
null);
10387 $substitutionarray[
'__NOTE_PUBLIC__'] = (isset(
$object->note_public) ?
$object->note_public :
null);
10388 $substitutionarray[
'__NOTE_PRIVATE__'] = (isset(
$object->note_private) ?
$object->note_private :
null);
10390 $substitutionarray[
'__DATE_CREATION__'] = (isset(
$object->date_creation) ?
dol_print_date(
$object->date_creation,
'day',
false, $outputlangs) :
'');
10391 $substitutionarray[
'__DATE_MODIFICATION__'] = (isset(
$object->date_modification) ?
dol_print_date(
$object->date_modification,
'day',
false, $outputlangs) :
'');
10392 $substitutionarray[
'__DATE_VALIDATION__'] = (isset(
$object->date_validation) ?
dol_print_date(
$object->date_validation,
'day',
false, $outputlangs) :
'');
10395 $date_delivery =
null;
10396 if (property_exists(
$object,
'date_delivery')) {
10397 $date_delivery =
$object->date_delivery;
10398 } elseif (property_exists(
$object,
'delivery_date')) {
10399 $date_delivery =
$object->delivery_date;
10401 $substitutionarray[
'__DATE_DELIVERY__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
'day',
false, $outputlangs) :
'');
10402 $substitutionarray[
'__DATE_DELIVERY_DAY__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%d") :
'');
10403 $substitutionarray[
'__DATE_DELIVERY_DAY_TEXT__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%A") :
'');
10404 $substitutionarray[
'__DATE_DELIVERY_MON__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%m") :
'');
10405 $substitutionarray[
'__DATE_DELIVERY_MON_TEXT__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%b") :
'');
10406 $substitutionarray[
'__DATE_DELIVERY_YEAR__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%Y") :
'');
10407 $substitutionarray[
'__DATE_DELIVERY_HH__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%H") :
'');
10408 $substitutionarray[
'__DATE_DELIVERY_MM__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%M") :
'');
10409 $substitutionarray[
'__DATE_DELIVERY_SS__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%S") :
'');
10412 $substitutionarray[
'__REFCLIENT__'] = (isset(
$object->ref_client) ?
$object->ref_client : (isset(
$object->ref_customer) ?
$object->ref_customer :
null));
10413 $substitutionarray[
'__REFSUPPLIER__'] = (isset(
$object->ref_supplier) ?
$object->ref_supplier :
null);
10415 $substitutionarray[
'__SUPPLIER_ORDER_DATE_DELIVERY__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
'day',
false, $outputlangs) :
'');
10416 $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 :
'')) :
'');
10420 '@phan-var-force Adherent $object';
10424 $substitutionarray[
'__MEMBER_ID__'] = (isset(
$object->id) ?
$object->id :
'');
10425 if (method_exists(
$object,
'getCivilityLabel')) {
10426 $substitutionarray[
'__MEMBER_TITLE__'] =
$object->getCivilityLabel();
10428 $substitutionarray[
'__MEMBER_FIRSTNAME__'] = (isset(
$object->firstname) ?
$object->firstname :
'');
10429 $substitutionarray[
'__MEMBER_LASTNAME__'] = (isset(
$object->lastname) ?
$object->lastname :
'');
10430 $substitutionarray[
'__MEMBER_USER_LOGIN_INFORMATION__'] =
'';
10431 if (method_exists(
$object,
'getFullName')) {
10432 $substitutionarray[
'__MEMBER_FULLNAME__'] =
$object->getFullName($outputlangs);
10434 $substitutionarray[
'__MEMBER_COMPANY__'] = (isset(
$object->societe) ?
$object->societe :
'');
10435 $substitutionarray[
'__MEMBER_ADDRESS__'] = (isset(
$object->address) ?
$object->address :
'');
10436 $substitutionarray[
'__MEMBER_ZIP__'] = (isset(
$object->zip) ?
$object->zip :
'');
10437 $substitutionarray[
'__MEMBER_TOWN__'] = (isset(
$object->town) ?
$object->town :
'');
10438 $substitutionarray[
'__MEMBER_STATE__'] = (isset(
$object->state) ?
$object->state :
'');
10439 $substitutionarray[
'__MEMBER_COUNTRY__'] = (isset(
$object->country) ?
$object->country :
'');
10440 $substitutionarray[
'__MEMBER_EMAIL__'] = (isset(
$object->email) ?
$object->email :
'');
10441 $substitutionarray[
'__MEMBER_BIRTH__'] = (isset($birthday) ? $birthday :
'');
10442 $substitutionarray[
'__MEMBER_PHOTO__'] = (isset(
$object->photo) ?
$object->photo :
'');
10443 $substitutionarray[
'__MEMBER_LOGIN__'] = (isset(
$object->login) ?
$object->login :
'');
10444 $substitutionarray[
'__MEMBER_PASSWORD__'] = (isset(
$object->pass) ?
$object->pass :
'');
10448 $substitutionarray[
'__MEMBER_TYPE__'] = (isset(
$object->type) ?
$object->type :
'');
10449 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE__'] =
dol_print_date(
$object->first_subscription_date,
'day');
10451 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_RFC__'] =
dol_print_date(
$object->first_subscription_date,
'dayrfc');
10452 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_START__'] = (isset(
$object->first_subscription_date_start) ?
dol_print_date(
$object->first_subscription_date_start,
'day') :
'');
10453 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_START_RFC__'] = (isset(
$object->first_subscription_date_start) ?
dol_print_date(
$object->first_subscription_date_start,
'dayrfc') :
'');
10454 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_END__'] = (isset(
$object->first_subscription_date_end) ?
dol_print_date(
$object->first_subscription_date_end,
'day') :
'');
10455 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_END_RFC__'] = (isset(
$object->first_subscription_date_end) ?
dol_print_date(
$object->first_subscription_date_end,
'dayrfc') :
'');
10456 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE__'] =
dol_print_date(
$object->last_subscription_date,
'day');
10457 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_RFC__'] =
dol_print_date(
$object->last_subscription_date,
'dayrfc');
10458 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_START__'] =
dol_print_date(
$object->last_subscription_date_start,
'day');
10459 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_START_RFC__'] =
dol_print_date(
$object->last_subscription_date_start,
'dayrfc');
10460 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_END__'] =
dol_print_date(
$object->last_subscription_date_end,
'day');
10461 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_END_RFC__'] =
dol_print_date(
$object->last_subscription_date_end,
'dayrfc');
10466 '@phan-var-force Societe $object';
10467 $substitutionarray[
'__THIRDPARTY_ID__'] =
$object->id ??
'';
10468 $substitutionarray[
'__THIRDPARTY_NAME__'] =
$object->name ??
'';
10469 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] =
$object->name_alias ??
'';
10470 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] =
$object->code_client ??
'';
10471 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] =
$object->code_fournisseur ??
'';
10472 $substitutionarray[
'__THIRDPARTY_EMAIL__'] =
$object->email ??
'';
10473 $substitutionarray[
'__THIRDPARTY_EMAIL_URLENCODED__'] = urlencode(
$object->email ??
'');
10474 $substitutionarray[
'__THIRDPARTY_URL__'] =
$object->url ??
'';
10475 $substitutionarray[
'__THIRDPARTY_URL_URLENCODED__'] = urlencode(
$object->url ??
'');
10478 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] =
$object->address ??
'';
10479 $substitutionarray[
'__THIRDPARTY_ZIP__'] =
$object->zip ??
'';
10480 $substitutionarray[
'__THIRDPARTY_TOWN__'] =
$object->town ??
'';
10481 $substitutionarray[
'__THIRDPARTY_STATE__'] =
$object->state ??
'';
10482 $substitutionarray[
'__THIRDPARTY_COUNTRY_ID__'] = (
$object->country_id > 0 ?:
'');
10483 $substitutionarray[
'__THIRDPARTY_COUNTRY_CODE__'] =
$object->country_code ??
'';
10484 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] =
$object->idprof1 ??
'';
10485 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] =
$object->idprof2 ??
'';
10486 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] =
$object->idprof3 ??
'';
10487 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] =
$object->idprof4 ??
'';
10488 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] =
$object->idprof5 ??
'';
10489 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] =
$object->idprof6 ??
'';
10490 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] =
$object->tva_intra ??
'';
10493 } elseif (is_object(
$object) && is_object(
$object->thirdparty)) {
10494 $substitutionarray[
'__THIRDPARTY_ID__'] =
$object->thirdparty->id ??
'';
10495 $substitutionarray[
'__THIRDPARTY_NAME__'] =
$object->thirdparty->name ??
'';
10496 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] =
$object->thirdparty->name_alias ??
'';
10497 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] =
$object->thirdparty->code_client ??
'';
10498 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] =
$object->thirdparty->code_fournisseur ??
'';
10499 $substitutionarray[
'__THIRDPARTY_EMAIL__'] =
$object->thirdparty->email ??
'';
10500 $substitutionarray[
'__THIRDPARTY_EMAIL_URLENCODED__'] = urlencode(
$object->thirdparty->email ??
'');
10503 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] =
$object->thirdparty->address ??
'';
10504 $substitutionarray[
'__THIRDPARTY_ZIP__'] =
$object->thirdparty->zip ??
'';
10505 $substitutionarray[
'__THIRDPARTY_TOWN__'] =
$object->thirdparty->town ??
'';
10506 $substitutionarray[
'__THIRDPARTY_STATE__'] =
$object->thirdparty->state ??
'';
10507 $substitutionarray[
'__THIRDPARTY_COUNTRY_ID__'] = (
$object->thirdparty->country_id > 0 ?:
'');
10508 $substitutionarray[
'__THIRDPARTY_COUNTRY_CODE__'] =
$object->thirdparty->country_code ??
'';
10509 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] =
$object->thirdparty->idprof1 ??
'';
10510 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] =
$object->thirdparty->idprof2 ??
'';
10511 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] =
$object->thirdparty->idprof3 ??
'';
10512 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] =
$object->thirdparty->idprof4 ??
'';
10513 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] =
$object->thirdparty->idprof5 ??
'';
10514 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] =
$object->thirdparty->idprof6 ??
'';
10515 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] =
$object->thirdparty->tva_intra ??
'';
10520 if (is_object(
$object) &&
$object->element ==
'recruitmentcandidature') {
10521 '@phan-var-force RecruitmentCandidature $object';
10523 $substitutionarray[
'__CANDIDATE_FULLNAME__'] =
$object->getFullName($outputlangs);
10524 $substitutionarray[
'__CANDIDATE_FIRSTNAME__'] = isset(
$object->firstname) ?
$object->firstname :
'';
10525 $substitutionarray[
'__CANDIDATE_LASTNAME__'] = isset(
$object->lastname) ?
$object->lastname :
'';
10527 if (is_object(
$object) &&
$object->element ==
'conferenceorboothattendee') {
10528 '@phan-var-force ConferenceOrBoothAttendee $object';
10530 $substitutionarray[
'__ATTENDEE_FULLNAME__'] =
$object->getFullName($outputlangs);
10531 $substitutionarray[
'__ATTENDEE_FIRSTNAME__'] = isset(
$object->firstname) ?
$object->firstname :
'';
10532 $substitutionarray[
'__ATTENDEE_LASTNAME__'] = isset(
$object->lastname) ?
$object->lastname :
'';
10536 '@phan-var-force Project $object';
10538 $substitutionarray[
'__PROJECT_ID__'] =
$object->id;
10539 $substitutionarray[
'__PROJECT_REF__'] =
$object->ref;
10540 $substitutionarray[
'__PROJECT_NAME__'] =
$object->title;
10541 } elseif (is_object(
$object)) {
10543 if (!empty(
$object->project)) {
10546 if (!is_null($project) && is_object($project)) {
10547 $substitutionarray[
'__PROJECT_ID__'] = $project->id;
10548 $substitutionarray[
'__PROJECT_REF__'] = $project->ref;
10549 $substitutionarray[
'__PROJECT_NAME__'] = $project->title;
10554 $project_id =
$object->fk_project;
10555 } elseif (!empty(
$object->fk_projet) &&
$object->fk_projet > 0) {
10556 $project_id =
$object->fk_project;
10558 if ($project_id > 0) {
10560 $substitutionarray[
'__PROJECT_ID__@lazyload'] =
'/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id;
10561 $substitutionarray[
'__PROJECT_REF__@lazyload'] =
'/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id;
10562 $substitutionarray[
'__PROJECT_NAME__@lazyload'] =
'/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id;
10568 '@phan-var-force Facture $object';
10570 $substitutionarray[
'__INVOICE_SITUATION_NUMBER__'] = isset(
$object->situation_counter) ?
$object->situation_counter :
'';
10573 '@phan-var-force Expedition $object';
10575 $substitutionarray[
'__SHIPPINGTRACKNUM__'] =
$object->tracking_number;
10576 $substitutionarray[
'__SHIPPINGTRACKNUMURL__'] =
$object->tracking_url;
10577 $substitutionarray[
'__SHIPPINGMETHOD__'] =
$object->shipping_method;
10580 '@phan-var-force Reception $object';
10582 $substitutionarray[
'__RECEPTIONTRACKNUM__'] =
$object->tracking_number;
10583 $substitutionarray[
'__RECEPTIONTRACKNUMURL__'] =
$object->tracking_url;
10587 '@phan-var-force Contrat $object';
10589 $dateplannedstart =
'';
10590 $datenextexpiration =
'';
10591 foreach (
$object->lines as $line) {
10592 if ($line->date_start > $dateplannedstart) {
10593 $dateplannedstart = $line->date_start;
10595 if ($line->statut == 4 && $line->date_end && (!$datenextexpiration || $line->date_end < $datenextexpiration)) {
10596 $datenextexpiration = $line->date_end;
10599 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE__'] =
dol_print_date($dateplannedstart,
'day');
10600 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE_RFC__'] =
dol_print_date($dateplannedstart,
'dayrfc');
10601 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATETIME__'] =
dol_print_date($dateplannedstart,
'standard');
10603 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE__'] =
dol_print_date($datenextexpiration,
'day');
10604 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE_RFC__'] =
dol_print_date($datenextexpiration,
'dayrfc');
10605 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATETIME__'] =
dol_print_date($datenextexpiration,
'standard');
10609 '@phan-var-force Ticket $object';
10611 $substitutionarray[
'__TICKET_TRACKID__'] =
$object->track_id;
10612 $substitutionarray[
'__TICKET_SUBJECT__'] =
$object->subject;
10613 $substitutionarray[
'__TICKET_TYPE__'] =
$object->type_code;
10614 $substitutionarray[
'__TICKET_SEVERITY__'] =
$object->severity_code;
10615 $substitutionarray[
'__TICKET_CATEGORY__'] =
$object->category_code;
10616 $substitutionarray[
'__TICKET_ANALYTIC_CODE__'] =
$object->category_code;
10617 $substitutionarray[
'__TICKET_MESSAGE__'] =
$object->message;
10618 $substitutionarray[
'__TICKET_PROGRESSION__'] =
$object->progress;
10620 if (
$object->fk_user_assign > 0) {
10621 $userstat->fetch(
$object->fk_user_assign);
10622 $substitutionarray[
'__TICKET_USER_ASSIGN__'] =
dolGetFirstLastname($userstat->firstname, $userstat->lastname);
10625 if (
$object->fk_user_create > 0) {
10626 $userstat->fetch(
$object->fk_user_create);
10627 $substitutionarray[
'__USER_CREATE__'] =
dolGetFirstLastname($userstat->firstname, $userstat->lastname);
10633 if (!is_object($extrafields)) {
10636 $extrafields->fetch_name_optionals_label(
$object->table_element,
true);
10638 if (
$object->fetch_optionals() > 0) {
10639 if (is_array($extrafields->attributes[
$object->table_element][
'label']) && count($extrafields->attributes[
$object->table_element][
'label']) > 0) {
10640 foreach ($extrafields->attributes[
$object->table_element][
'label'] as $key => $label) {
10641 if ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'date') {
10642 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] =
dol_print_date(
$object->array_options[
'options_' . $key],
'day');
10643 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_LOCALE__'] =
dol_print_date(
$object->array_options[
'options_' . $key],
'day',
'tzserver', $outputlangs);
10644 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_RFC__'] =
dol_print_date(
$object->array_options[
'options_' . $key],
'dayrfc');
10645 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'datetime') {
10646 $datetime =
$object->array_options[
'options_' . $key];
10647 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhour') :
'');
10648 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_LOCALE__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhour',
'tzserver', $outputlangs) :
'');
10649 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_DAY_LOCALE__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'day',
'tzserver', $outputlangs) :
'');
10650 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_RFC__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhourrfc') :
'');
10651 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'phone') {
10652 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] =
dol_print_phone(
$object->array_options[
'options_' . $key]);
10653 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'price') {
10654 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] =
$object->array_options[
'options_' . $key];
10655 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_FORMATED__'] =
price(
$object->array_options[
'options_' . $key]);
10656 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_FORMATTED__'] =
price(
$object->array_options[
'options_' . $key]);
10657 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'select') {
10658 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] = !empty(
$object->array_options[
'options_' . $key]) ?
$object->array_options[
'options_' . $key] :
'';
10659 $val = $extrafields->attributes[
$object->table_element][
'param'][$key][
'options'][
$object->array_options[
'options_'.$key]] ??
$object->array_options[
'options_'.$key];
10660 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'_LABEL__'] = $val;
10661 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] !=
'separator') {
10662 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] = !empty(
$object->array_options[
'options_' . $key]) ?
$object->array_options[
'options_' . $key] :
'';
10670 if (empty($substitutionarray[
'__REF__'])) {
10674 require_once DOL_DOCUMENT_ROOT .
'/core/lib/payments.lib.php';
10675 $outputlangs->loadLangs(array(
'paypal',
'other'));
10678 $typeforonlinepayment =
'free';
10680 $typeforonlinepayment =
'order';
10683 $typeforonlinepayment =
'invoice';
10686 $typeforonlinepayment =
'member';
10687 if (!empty(
$object->last_subscription_amount)) {
10688 $amounttouse =
$object->last_subscription_amount;
10692 $typeforonlinepayment =
'contract';
10695 $typeforonlinepayment =
'ficheinter';
10698 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $substitutionarray[
'__REF__'], (
float) $amounttouse);
10699 $paymenturl = $url;
10703 $substitutionarray[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = ($paymenturl ? str_replace(
'\n',
"\n", $outputlangs->trans(
"PredefinedMailContentLink", $paymenturl)) :
'');
10704 $substitutionarray[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
10708 include_once DOL_DOCUMENT_ROOT .
'/core/lib/functions_be.lib.php';
10713 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
$object->getLastMainDocLink(
$object->element);
10715 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
'';
10718 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
$object->getLastMainDocLink(
$object->element);
10720 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
'';
10723 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
$object->getLastMainDocLink(
$object->element);
10725 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
'';
10728 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
$object->getLastMainDocLink(
$object->element);
10730 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
'';
10733 $substitutionarray[
'__DIRECTDOWNLOAD_URL_FICHINTER__'] =
$object->getLastMainDocLink(
$object->element);
10735 $substitutionarray[
'__DIRECTDOWNLOAD_URL_FICHINTER__'] =
'';
10738 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
$object->getLastMainDocLink(
$object->element);
10740 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
'';
10743 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_ORDER__'] =
$object->getLastMainDocLink(
$object->element);
10745 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_ORDER__'] =
'';
10748 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_INVOICE__'] =
$object->getLastMainDocLink(
$object->element);
10750 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_INVOICE__'] =
'';
10754 '@phan-var-force Propal $object';
10756 $substitutionarray[
'__URL_PROPOSAL__'] = DOL_MAIN_URL_ROOT .
"/comm/propal/card.php?id=" .
$object->id;
10757 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
10758 $substitutionarray[
'__ONLINE_SIGN_URL__'] = getOnlineSignatureUrl(0,
'proposal', (
string)
$object->ref, 1,
$object);
10761 '@phan-var-force Commande $object';
10763 $substitutionarray[
'__URL_ORDER__'] = DOL_MAIN_URL_ROOT .
"/commande/card.php?id=" .
$object->id;
10766 '@phan-var-force Facture $object';
10768 $substitutionarray[
'__URL_INVOICE__'] = DOL_MAIN_URL_ROOT .
"/compta/facture/card.php?id=" .
$object->id;
10771 '@phan-var-force Contrat $object';
10773 $substitutionarray[
'__URL_CONTRACT__'] = DOL_MAIN_URL_ROOT .
"/contrat/card.php?id=" .
$object->id;
10774 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
10775 $substitutionarray[
'__ONLINE_SIGN_URL__'] = getOnlineSignatureUrl(0,
'contract', (
string)
$object->ref, 1,
$object);
10778 '@phan-var-force Fichinter $object';
10780 $substitutionarray[
'__URL_FICHINTER__'] = DOL_MAIN_URL_ROOT .
"/fichinter/card.php?id=" .
$object->id;
10781 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
10782 $substitutionarray[
'__ONLINE_SIGN_FICHINTER_URL__'] = getOnlineSignatureUrl(0,
'fichinter', (
string)
$object->ref, 1,
$object);
10784 if (is_object(
$object) &&
$object->element ==
'supplier_proposal') {
10785 '@phan-var-force SupplierProposal $object';
10787 $substitutionarray[
'__URL_SUPPLIER_PROPOSAL__'] = DOL_MAIN_URL_ROOT .
"/supplier_proposal/card.php?id=" .
$object->id;
10789 if (is_object(
$object) &&
$object->element ==
'invoice_supplier') {
10790 '@phan-var-force FactureFournisseur $object';
10792 $substitutionarray[
'__URL_SUPPLIER_INVOICE__'] = DOL_MAIN_URL_ROOT .
"/fourn/facture/card.php?id=" .
$object->id;
10794 if (is_object(
$object) &&
$object->element ==
'payment_supplier') {
10795 '@phan-var-force PaiementFourn $object';
10798 $liste_factures = [];
10802 $sql =
'SELECT f.ref,f.multicurrency_code as f_mccode, pf.*
10803 FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf
10804 JOIN '.MAIN_DB_PREFIX.
'facture_fourn as f ON pf.fk_facturefourn = f.rowid
10805 WHERE pf.fk_paiementfourn = '.((int)
$object->id);
10807 $resql =
$db->query($sql);
10809 while ($objp =
$db->fetch_object($resql)) {
10810 $liste_factures[] =
' - '.$outputlangs->trans(
'Invoice').
' '. $objp->ref.
' '.$outputlangs->trans(
'AmountPayed').
' '.
price($objp->multicurrency_amount, 0, $outputlangs, 0, -1, -1, $objp->multicurrency_code);
10813 $substitutionarray[
'__SUPPLIER_PAYMENT_INVOICES_LIST__'] = implode(
"\n", $liste_factures);
10815 $substitutionarray[
'__SUPPLIER_PAYMENT_INVOICES_TOTAL__'] =
price(
$object->multicurrency_amount, 0, $outputlangs, 0, -1, -1,
$object->multicurrency_code ?
$object->multicurrency_code :
$conf->currency);
10818 '@phan-var-force Expedition $object';
10820 $substitutionarray[
'__URL_SHIPMENT__'] = DOL_MAIN_URL_ROOT .
"/expedition/card.php?id=" .
$object->id;
10822 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
10823 $substitutionarray[
'__ONLINE_SIGN_URL__'] = getOnlineSignatureUrl(0,
'expedition',
$object->ref, 1,
$object);
10829 '@phan-var-force ActionComm $object';
10831 $substitutionarray[
'__EVENT_LABEL__'] =
$object->label;
10832 $substitutionarray[
'__EVENT_DESCRIPTION__'] =
$object->note;
10833 $substitutionarray[
'__EVENT_TYPE__'] = $outputlangs->trans(
"Action" .
$object->type_code);
10834 $substitutionarray[
'__EVENT_DATE__'] =
dol_print_date(
$object->datep,
'day',
'auto', $outputlangs);
10835 $substitutionarray[
'__EVENT_TIME__'] =
dol_print_date(
$object->datep,
'hour',
'auto', $outputlangs);
10836 $substitutionarray[
'__EVENT_DATE_TZUSER__'] =
dol_print_date(
$object->datep,
'day',
'tzuserrel', $outputlangs);
10837 $substitutionarray[
'__EVENT_TIME_TZUSER__'] =
dol_print_date(
$object->datep,
'hour',
'tzuserrel', $outputlangs);
10842 if ((empty($exclude) || !in_array(
'objectamount', $exclude)) && (empty($include) || in_array(
'objectamount', $include))) {
10843 '@phan-var-force Facture|FactureRec $object';
10845 include_once DOL_DOCUMENT_ROOT .
'/core/lib/functionsnumtoword.lib.php';
10848 $substitutionarray[
'__DATE_DUE_YMD__'] = is_object(
$object) ? (isset(
$object->date_lim_reglement) ?
dol_print_date(
$object->date_lim_reglement,
'day',
false, $outputlangs) : null) :
'';
10850 $substitutionarray[
'__DATE_DUE_YMD_TEXT__'] = is_object(
$object) ? (isset(
$object->date_lim_reglement) ?
dol_print_date(
$object->date_lim_reglement,
'daytext',
false, $outputlangs) : null) :
'';
10852 $already_payed_all = 0;
10858 $substitutionarray[
'__AMOUNT_EXCL_TAX__'] = is_object(
$object) ?
$object->total_ht :
'';
10862 $substitutionarray[
'__AMOUNT__'] = is_object(
$object) ?
$object->total_ttc :
'';
10866 $substitutionarray[
'__DEPOSIT_PERCENT__'] = is_object(
$object) ?
$object->deposit_percent :
'';
10869 $substitutionarray[
'__AMOUNT_REMAIN__'] = is_object(
$object) ?
price2num(
$object->total_ttc - $already_payed_all,
'MT') :
'';
10871 $substitutionarray[
'__AMOUNT_VAT__'] = is_object(
$object) ? (isset(
$object->total_vat) ?
$object->total_vat :
$object->total_tva) :
'';
10875 $mysocuselocaltax1 =
false;
10876 $mysocuselocaltax2 =
false;
10878 $tmparray =
$mysoc->useLocalTax(-1);
10879 $mysocuselocaltax1 = $tmparray[1];
10880 $mysocuselocaltax2 = $tmparray[2];
10884 if ($onlykey != 2 || $mysocuselocaltax1) {
10885 $substitutionarray[
'__AMOUNT_TAX2__'] = is_object(
$object) ?
$object->total_localtax1 :
'';
10887 if ($onlykey != 2 || $mysocuselocaltax2) {
10888 $substitutionarray[
'__AMOUNT_TAX3__'] = is_object(
$object) ?
$object->total_localtax2 :
'';
10892 $substitutionarray[
'__AMOUNT_EXCL_TAX_FORMATTED__'] = is_object(
$object) ? (
$object->total_ht ?
price(
$object->total_ht, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null) :
'';
10893 $substitutionarray[
'__AMOUNT_FORMATTED__'] = is_object(
$object) ? (
$object->total_ttc ?
price(
$object->total_ttc, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null) :
'';
10894 $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) :
'';
10895 $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)) :
'';
10896 if ($onlykey != 2 || $mysocuselocaltax1) {
10897 $substitutionarray[
'__AMOUNT_TAX2_FORMATTED__'] = is_object(
$object) ? (
$object->total_localtax1 ?
price(
$object->total_localtax1, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null) :
'';
10899 if ($onlykey != 2 || $mysocuselocaltax2) {
10900 $substitutionarray[
'__AMOUNT_TAX3_FORMATTED__'] = is_object(
$object) ? (
$object->total_localtax2 ?
price(
$object->total_localtax2, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null) :
'';
10903 if ($onlykey != 2) {
10904 $substitutionarray[
'__AMOUNT_EXCL_TAX_FORMATED__'] = $substitutionarray[
'__AMOUNT_EXCL_TAX_FORMATTED__'];
10905 $substitutionarray[
'__AMOUNT_FORMATED__'] = $substitutionarray[
'__AMOUNT_FORMATTED__'];
10906 $substitutionarray[
'__AMOUNT_REMAIN_FORMATED__'] = $substitutionarray[
'__AMOUNT_REMAIN_FORMATTED__'];
10907 $substitutionarray[
'__AMOUNT_VAT_FORMATED__'] = $substitutionarray[
'__AMOUNT_VAT_FORMATTED__'];
10908 if ($mysocuselocaltax1) {
10909 $substitutionarray[
'__AMOUNT_TAX2_FORMATED__'] = $substitutionarray[
'__AMOUNT_TAX2_FORMATTED__'];
10911 if (
$mysoc->useLocalTax2) {
10912 $substitutionarray[
'__AMOUNT_TAX3_FORMATED__'] = $substitutionarray[
'__AMOUNT_TAX3_FORMATTED__'];
10916 $substitutionarray[
'__AMOUNT_MULTICURRENCY__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
$object->multicurrency_total_ttc :
'';
10917 $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) :
'';
10918 $substitutionarray[
'__AMOUNT_MULTICURRENCY_TEXT__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
dol_convertToWord(
$object->multicurrency_total_ttc, $outputlangs,
'',
true) :
'';
10919 $substitutionarray[
'__AMOUNT_MULTICURRENCY_TEXTCURRENCY__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
dol_convertToWord(
$object->multicurrency_total_ttc, $outputlangs,
$object->multicurrency_code,
true) :
'';
10920 $substitutionarray[
'__MULTICURRENCY_CODE__'] = (is_object(
$object) && isset(
$object->multicurrency_code)) ?
$object->multicurrency_code :
'';
10924 if ($onlykey != 2) {
10925 $substitutionarray[
'__TOTAL_TTC__'] = is_object(
$object) ?
$object->total_ttc :
'';
10926 $substitutionarray[
'__TOTAL_HT__'] = is_object(
$object) ?
$object->total_ht :
'';
10927 $substitutionarray[
'__TOTAL_VAT__'] = is_object(
$object) ? (isset(
$object->total_vat) ?
$object->total_vat :
$object->total_tva) :
'';
10932 if ((empty($exclude) || !in_array(
'date', $exclude)) && (empty($include) || in_array(
'date', $include))) {
10933 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
10943 $daytext = $outputlangs->trans(
'Day' . $tmp[
'wday']);
10945 $substitutionarray = array_merge($substitutionarray, array(
10946 '__NOW_TMS__' => (
string) $now,
10947 '__NOW_TMS_YMD__' =>
dol_print_date($now,
'day',
'auto', $outputlangs),
10948 '__DAY__' => (
string) $tmp[
'mday'],
10949 '__DAY_TEXT__' => $daytext,
10950 '__DAY_TEXT_SHORT__' =>
dol_trunc($daytext, 3,
'right',
'UTF-8', 1),
10951 '__DAY_TEXT_MIN__' =>
dol_trunc($daytext, 1,
'right',
'UTF-8', 1),
10952 '__MONTH__' => (
string) $tmp[
'mon'],
10953 '__MONTH_TEXT__' => $outputlangs->transnoentitiesnoconv(
'Month' . sprintf(
"%02d", $tmp[
'mon'])),
10954 '__MONTH_TEXT_SHORT__' => $outputlangs->transnoentitiesnoconv(
'MonthShort' . sprintf(
"%02d", $tmp[
'mon'])),
10955 '__MONTH_TEXT_MIN__' => $outputlangs->transnoentitiesnoconv(
'MonthVeryShort' . sprintf(
"%02d", $tmp[
'mon'])),
10956 '__YEAR__' => (
string) $tmp[
'year'],
10957 '__YEAR_PREVIOUS_MONTH__' => (
string) $tmp3[
'year'],
10958 '__YEAR_NEXT_MONTH__' => (
string) $tmp5[
'year'],
10959 '__PREVIOUS_DAY__' => (
string) $tmp2[
'day'],
10960 '__PREVIOUS_MONTH__' => (
string) $tmp3[
'month'],
10961 '__PREVIOUS_MONTH_TEXT__' => $outputlangs->transnoentitiesnoconv(
'Month' . sprintf(
"%02d", $tmp3[
'month'])),
10962 '__PREVIOUS_MONTH_TEXT_SHORT__' => $outputlangs->transnoentitiesnoconv(
'MonthShort' . sprintf(
"%02d", $tmp3[
'month'])),
10963 '__PREVIOUS_MONTH_TEXT_MIN__' => $outputlangs->transnoentitiesnoconv(
'MonthVeryShort' . sprintf(
"%02d", $tmp3[
'month'])),
10964 '__PREVIOUS_YEAR__' => (
string) ($tmp[
'year'] - 1),
10965 '__NEXT_DAY__' => (
string) $tmp4[
'day'],
10966 '__NEXT_MONTH__' => (
string) $tmp5[
'month'],
10967 '__NEXT_MONTH_TEXT__' => $outputlangs->transnoentitiesnoconv(
'Month' . sprintf(
"%02d", $tmp5[
'month'])),
10968 '__NEXT_MONTH_TEXT_SHORT__' => $outputlangs->transnoentitiesnoconv(
'MonthShort' . sprintf(
"%02d", $tmp5[
'month'])),
10969 '__NEXT_MONTH_TEXT_MIN__' => $outputlangs->transnoentitiesnoconv(
'MonthVeryShort' . sprintf(
"%02d", $tmp5[
'month'])),
10970 '__NEXT_YEAR__' => (
string) ($tmp[
'year'] + 1),
10975 $substitutionarray = array_merge($substitutionarray, array(
'__ENTITY_ID__' =>
$conf->entity));
10977 if ((empty($exclude) || !in_array(
'system', $exclude)) && (empty($include) || in_array(
'user', $include))) {
10978 $substitutionarray[
'__DOL_MAIN_URL_ROOT__'] = DOL_MAIN_URL_ROOT;
10979 $substitutionarray[
'__(AnyTranslationKey)__'] = $outputlangs->transnoentitiesnoconv(
'TranslationOfKey');
10980 $substitutionarray[
'__(AnyTranslationKey|langfile)__'] = $outputlangs->transnoentitiesnoconv(
'TranslationOfKey') .
' (load also language file before)';
10981 $substitutionarray[
'__[AnyConstantKey]__'] = $outputlangs->transnoentitiesnoconv(
'ValueOfConstantKey');
10986 return $substitutionarray;
11005function make_substitutions($text, $substitutionarray, $outputlangs =
null, $converttextinhtmlifnecessary = 0)
11007 global
$db, $langs;
11009 if (!is_array($substitutionarray)) {
11010 return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions';
11013 if (empty($outputlangs)) {
11014 $outputlangs = $langs;
11024 if (is_object($outputlangs)) {
11026 while (preg_match(
'/__\(([^\)]+)\)__/', $text, $reg)) {
11028 $tmp = explode(
'|', $reg[1]);
11029 if (!empty($tmp[1])) {
11030 $outputlangs->load($tmp[1]);
11033 $value = $outputlangs->transnoentitiesnoconv($reg[1]);
11035 if (empty($converttextinhtmlifnecessary)) {
11037 $text = preg_replace(
'/__\(' . preg_quote($reg[1],
'/') .
'\)__/', $msgishtml ?
dol_htmlentitiesbr($value) : $value, $text);
11039 if (! $msgishtml) {
11043 if ($valueishtml) {
11051 $text = preg_replace(
'/__\(' . preg_quote($reg[1],
'/') .
'\)__/', $value, $text);
11059 while (preg_match(
'/__\[([^\]]+)\]__/', $text, $reg)) {
11060 $originalkeyfound = $reg[1];
11061 $keyfound = preg_replace(
'/\|urlencode$/',
'', $originalkeyfound);
11064 $value =
'*****forbidden*****';
11068 if (preg_match(
'/\|urlencode$/', $originalkeyfound)) {
11069 $value = urlencode($value);
11073 if (empty($converttextinhtmlifnecessary)) {
11075 $text = preg_replace(
'/__\[' . preg_quote($originalkeyfound,
'/') .
'\]__/', $msgishtml ?
dol_htmlentitiesbr($value) : $value, $text);
11077 if (! $msgishtml) {
11080 if ($valueishtml) {
11088 $text = preg_replace(
'/__\[' . preg_quote($originalkeyfound,
'/') .
'\]__/', $value, $text);
11093 foreach ($substitutionarray as $key => $value) {
11094 if (!isset($value)) {
11098 if (
getDolGlobalString(
'MAIN_MAIL_DO_NOT_USE_SIGN') && ($key ==
'__USER_SIGNATURE__' || $key ==
'__SENDEREMAIL_SIGNATURE__')) {
11102 if (empty($converttextinhtmlifnecessary)) {
11103 $text = str_replace((
string) $key, (
string) $value, $text);
11105 if (! $msgishtml) {
11108 if ($valueishtml) {
11115 $text = str_replace((
string) $key, (
string) $value, $text);
11130 $memory_object_list = array();
11131 foreach ($substitutionarray as $key => $value) {
11132 $lazy_load_arr = array();
11133 if (preg_match(
'/(__[A-Z\_]+__)@lazyload$/', $key, $lazy_load_arr)) {
11134 if (isset($lazy_load_arr[1]) && !empty($lazy_load_arr[1])) {
11135 $key_to_substitute = $lazy_load_arr[1];
11136 if (preg_match(
'/' . preg_quote($key_to_substitute,
'/') .
'/', $text)) {
11137 $param_arr = explode(
':', (
string) $value);
11139 if (count($param_arr) >= 4) {
11140 $path = $param_arr[0];
11141 $class = $param_arr[1];
11142 $method = $param_arr[2];
11143 $id = (int) $param_arr[3];
11144 $keyinarrayresult = empty($param_arr[4]) ?
'' : $param_arr[4];
11147 if (!isset($memory_object_list[$class])) {
11149 require_once DOL_DOCUMENT_ROOT . $path;
11150 if (class_exists($class)) {
11151 $memory_object_list[$class] = array(
11159 if (isset($memory_object_list[$class]) && isset($memory_object_list[$class][
'list'])) {
11160 if (method_exists($class, $method)) {
11161 if (!isset($memory_object_list[$class][
'list'][
$id])) {
11162 $tmpobj =
new $class(
$db);
11164 $tmpvaluetouseforsubstitution = $tmpobj->$method(
$id, $key_to_substitute);
11165 $memory_object_list[$class][
'list'][
$id] = $tmpobj;
11168 $tmpobj = $memory_object_list[$class][
'list'][
$id];
11170 $tmpvaluetouseforsubstitution = $tmpobj->$method(
$id, $key_to_substitute,
true);
11173 if ($keyinarrayresult) {
11174 $valuetouseforsubstitution = (
string) $tmpvaluetouseforsubstitution[$keyinarrayresult];
11176 $valuetouseforsubstitution = (
string) $tmpvaluetouseforsubstitution;
11178 $text = str_replace((
string) $key_to_substitute, $valuetouseforsubstitution, $text);
11204 global
$conf, $user;
11206 require_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
11211 $dirsubstitutions = array_merge(array(), (array)
$conf->modules_parts[
'substitutions']);
11213 foreach ($dirsubstitutions as $reldir) {
11221 $substitfiles =
dol_dir_list($dir,
'files', 0,
'functions_');
11222 foreach ($substitfiles as $substitfile) {
11224 if (preg_match(
'/functions_(.*)\.lib\.php/i', $substitfile[
'name'], $reg)) {
11227 dol_syslog(
"Library " . $substitfile[
'name'] .
" found into " . $dir);
11229 require_once $dir . $substitfile[
'name'];
11231 $function_name = $module .
"_" . $callfunc;
11232 if (function_exists($function_name)) {
11233 $function_name($substitutionarray, $outputlangs,
$object, $parameters);
11241 foreach ($substitutionarray as $key => $value) {
11242 $tags .=
'{' . $key .
'} => ' . $value .
"\n";
11244 $substitutionarray = array_merge($substitutionarray, array(
'__ALL_TAGS__' => $tags));
11278 if (!is_object($outputlangs)) {
11279 $outputlangs = $langs;
11283 $out .= ($withparenthesis ? ($withparenthesis == 1 ?
' ' :
'').
'(' :
'') . $outputlangs->transnoentitiesnoconv(
'DateFromTo',
dol_print_date(
$date_start, $format, false, $outputlangs),
dol_print_date($date_end, $format, false, $outputlangs)) . ($withparenthesis ?
')' :
'');
11286 $out .= ($withparenthesis ? ($withparenthesis == 1 ?
' ' :
'').
'(' :
'') . $outputlangs->transnoentitiesnoconv(
'DateFrom',
dol_print_date(
$date_start, $format, false, $outputlangs)) . ($withparenthesis ?
')' :
'');
11289 $out .= ($withparenthesis ? ($withparenthesis == 1 ?
' ' :
'').
'(' :
'') . $outputlangs->transnoentitiesnoconv(
'DateUntil',
dol_print_date($date_end, $format, false, $outputlangs)) . ($withparenthesis ?
')' :
'');
11307 if ($nameorder < 0) {
11310 if ($nameorder == 1) {
11311 $ret .= $firstname;
11312 if ($firstname && $lastname) {
11316 } elseif ($nameorder == 2 || $nameorder == 3) {
11317 $ret .= $firstname;
11318 if (empty($ret) && $nameorder == 3) {
11323 if (empty($ret) && $nameorder == 5) {
11324 $ret .= $firstname;
11326 if ($nameorder == 0) {
11327 if ($firstname && $lastname) {
11330 $ret .= $firstname;
11349function setEventMessage($mesgs, $style =
'mesgs', $noduplicate = 0, $attop = 0)
11352 if (!is_array($mesgs)) {
11353 $mesgs = trim((
string) $mesgs);
11356 if (!empty($noduplicate) && isset($_SESSION[
'dol_events'][$style]) && in_array($mesgs, $_SESSION[
'dol_events'][$style])) {
11360 array_unshift($_SESSION[
'dol_events'][$style], $mesgs);
11362 $_SESSION[
'dol_events'][$style][] = $mesgs;
11367 foreach ($mesgs as $mesg) {
11368 $mesg = trim((
string) $mesg);
11370 if (!empty($noduplicate) && isset($_SESSION[
'dol_events'][$style]) && in_array($mesg, $_SESSION[
'dol_events'][$style])) {
11374 array_unshift($_SESSION[
'dol_events'][$style], $mesgs);
11376 $_SESSION[
'dol_events'][$style][] = $mesg;
11396function setEventMessages($mesg, $mesgs, $style =
'mesgs', $messagekey =
'', $noduplicate = 0, $attop = 0)
11398 if (empty($mesg) && empty($mesgs)) {
11406 if (empty($messagekey) || empty($_COOKIE[
"DOLUSER_HIDEMESSAGE" . $messagekey])) {
11407 if (!in_array((
string) $style, array(
'mesgs',
'warnings',
'errors'))) {
11408 dol_print_error(
null,
'Bad parameter style=' . $style .
' for setEventMessages');
11410 if (empty($mesgs)) {
11413 if (!empty($mesg) && !in_array($mesg, $mesgs)) {
11434 if (isset($_SESSION[
'dol_events'][
'mesgs'])) {
11435 if (empty($disabledoutputofmessages)) {
11438 unset($_SESSION[
'dol_events'][
'mesgs']);
11441 if (isset($_SESSION[
'dol_events'][
'errors'])) {
11442 if (empty($disabledoutputofmessages)) {
11445 unset($_SESSION[
'dol_events'][
'errors']);
11449 if (isset($_SESSION[
'dol_events'][
'warnings'])) {
11450 if (empty($disabledoutputofmessages)) {
11453 unset($_SESSION[
'dol_events'][
'warnings']);
11471function get_htmloutput_mesg($mesgstring =
'', $mesgarray = [], $style =
'ok', $keepembedded = 0)
11473 global
$conf, $langs;
11478 $divstart = $divend =
'';
11481 if ((empty(
$conf->use_javascript_ajax) ||
getDolGlobalString(
'MAIN_DISABLE_JQUERY_JNOTIFY') || $keepembedded) && !preg_match(
'/<div class=".*">/i', $out)) {
11482 $divstart =
'<div class="' . $style .
' clearboth">';
11483 $divend =
'</div>';
11486 if ((is_array($mesgarray) && count($mesgarray)) || $mesgstring) {
11487 $langs->load(
"errors");
11489 if (is_array($mesgarray) && count($mesgarray)) {
11490 foreach ($mesgarray as $message) {
11492 $out .= $langs->trans($message);
11493 if ($ret < count($mesgarray)) {
11500 $out .= $langs->trans($mesgstring);
11506 if (!empty(
$conf->use_javascript_ajax) && !
getDolGlobalString(
'MAIN_DISABLE_JQUERY_JNOTIFY') && empty($keepembedded)) {
11507 $return =
'<script nonce="' . getNonce() .
'">
11508 $(document).ready(function() {
11509 /* jnotify(message, preset of message type, keepmessage) */
11510 $.jnotify("' .
dol_escape_js($out) .
'", "' . ($style ==
"ok" ? 3000 : $style) .
'", ' . ($style ==
"ok" ?
"false" :
"true") .
',{ remove: function (){} } );
11550function dol_htmloutput_mesg($mesgstring =
'', $mesgarray = array(), $style =
'ok', $keepembedded = 0)
11552 if (empty($mesgstring) && (!is_array($mesgarray) || count($mesgarray) == 0)) {
11558 if (is_array($mesgarray)) {
11559 foreach ($mesgarray as $val) {
11560 if ($val && preg_match(
'/class="error"/i', $val)) {
11564 if ($val && preg_match(
'/class="warning"/i', $val)) {
11569 } elseif ($mesgstring && preg_match(
'/class="error"/i', $mesgstring)) {
11571 } elseif ($mesgstring && preg_match(
'/class="warning"/i', $mesgstring)) {
11574 if ($style ==
'error' || $style ==
'errors') {
11577 if ($style ==
'warning' || $style ==
'warnings') {
11581 if ($iserror || $iswarning) {
11583 $mesgstring = preg_replace(
'/<\/div><div class="(error|warning)">/',
'<br>', $mesgstring);
11584 $mesgstring = preg_replace(
'/<div class="(error|warning)">/',
'', $mesgstring);
11585 $mesgstring = preg_replace(
'/<\/div>/',
'', $mesgstring);
11587 if (is_array($mesgarray)) {
11588 $newmesgarray = array();
11589 foreach ($mesgarray as $val) {
11590 if (is_string($val)) {
11591 $tmpmesgstring = preg_replace(
'/<\/div><div class="(error|warning)">/',
'<br>', $val);
11592 $tmpmesgstring = preg_replace(
'/<div class="(error|warning)">/',
'', $tmpmesgstring);
11593 $tmpmesgstring = preg_replace(
'/<\/div>/',
'', $tmpmesgstring);
11594 $newmesgarray[] = $tmpmesgstring;
11596 dol_syslog(
"Error call of dol_htmloutput_mesg with an array with a value that is not a string", LOG_WARNING);
11599 $mesgarray = $newmesgarray;
11601 print
get_htmloutput_mesg($mesgstring, $mesgarray, ($iserror ?
'error' :
'warning'), $keepembedded);
11644function dol_sort_array(&$array, $index, $order =
'asc', $natsort = 0, $case_sensitive = 0, $keepindex = 0)
11647 $order = strtolower($order);
11649 if (is_array($array)) {
11650 $sizearray = count($array);
11651 if ($sizearray > 0) {
11654 foreach (array_keys($array) as $key) {
11655 $tmpmultikey = explode(
',', $index);
11656 $newindex = $tmpmultikey[0];
11657 if (is_object($array[$key])) {
11658 $temp[$key] = empty($array[$key]->$newindex) ? 0 : $array[$key]->$newindex;
11660 if (!empty($tmpmultikey[1])) {
11661 $newindex = $tmpmultikey[1];
11662 $temp[$key] .=
'__' . (empty($array[$key]->$newindex) ? 0 : $array[$key]->$newindex);
11666 $temp[$key] = empty($array[$key][$newindex]) ? 0 : $array[$key][$newindex];
11668 if (!empty($tmpmultikey[1])) {
11669 $newindex = $tmpmultikey[1];
11671 $temp[$key] .=
'__' . (empty($array[$key][$newindex]) ? 0 : $array[$key][$newindex]);
11674 if ($natsort == -1) {
11675 $temp[$key] =
'___' . $temp[$key];
11678 if (empty($natsort) || $natsort == -1) {
11679 if ($order ==
'asc') {
11685 if ($case_sensitive) {
11688 natcasesort($temp);
11690 if ($order !=
'asc') {
11691 $temp = array_reverse($temp,
true);
11697 foreach (array_keys($temp) as $key) {
11698 (is_numeric($key) && empty($keepindex)) ? $sorted[] = $array[$key] : $sorted[$key] = $array[$key];
11720 $strLength = strlen($str);
11721 for ($i = 0; $i < $strLength; $i++) {
11722 if (ord($str[$i]) < 0x80) {
11724 } elseif ((ord($str[$i]) & 0xE0) == 0xC0) {
11726 } elseif ((ord($str[$i]) & 0xF0) == 0xE0) {
11728 } elseif ((ord($str[$i]) & 0xF8) == 0xF0) {
11730 } elseif ((ord($str[$i]) & 0xFC) == 0xF8) {
11732 } elseif ((ord($str[$i]) & 0xFE) == 0xFC) {
11737 for ($j = 0; $j < $n; $j++) {
11738 if ((++$i == strlen($str)) || ((ord($str[$i]) & 0xC0) != 0x80)) {
11759 return preg_match(
'//u', $str) ? true :
false;
11771 if (function_exists(
'mb_check_encoding')) {
11773 if (!mb_check_encoding($str,
'ASCII')) {
11777 if (preg_match(
'/[^\x00-\x7f]/', $str)) {
11795 $tmp = ini_get(
"unicode.filesystem_encoding");
11796 if (empty($tmp) && !empty($_SERVER[
"WINDIR"])) {
11797 $tmp =
'iso-8859-1';
11806 if ($tmp ==
'iso-8859-1') {
11807 return mb_convert_encoding($str,
'ISO-8859-1',
'UTF-8');
11828function dol_getIdFromCode(
$db, $key, $tablename, $fieldkey =
'code', $fieldid =
'id', $entityfilter = 0, $filters =
'', $useCache =
true)
11838 if ($useCache && isset(
$conf->cache[
'codeid'][$tablename][$key][$fieldid])) {
11839 return $conf->cache[
'codeid'][$tablename][$key][$fieldid];
11842 dol_syslog(
'dol_getIdFromCode (value for field ' . $fieldid .
' from key ' . $key .
' not found into cache)', LOG_DEBUG);
11844 $sql =
"SELECT " .
$db->sanitize($fieldid) .
" as valuetoget";
11845 $sql .=
" FROM " . MAIN_DB_PREFIX .
$db->sanitize($tablename);
11846 if ($fieldkey ==
'id' || $fieldkey ==
'rowid') {
11847 $sql .=
" WHERE " .
$db->sanitize($fieldkey) .
" = " . ((int) $key);
11849 $sql .=
" WHERE " .
$db->sanitize($fieldkey) .
" = '" .
$db->escape($key) .
"'";
11851 if (!empty($entityfilter)) {
11852 $sql .=
" AND entity IN (" .
getEntity($tablename) .
")";
11858 $resql =
$db->query($sql);
11860 $obj =
$db->fetch_object($resql);
11863 $valuetoget = $obj->valuetoget;
11864 $conf->cache[
'codeid'][$tablename][$key][$fieldid] = $valuetoget;
11866 $conf->cache[
'codeid'][$tablename][$key][$fieldid] =
'';
11870 return $valuetoget;
11890 $regextext = preg_replace(
'#^/\^?#',
'', (
string) $regextext);
11891 $regextext = preg_replace(
'#\$?/[imsxuADSUXJ]*$#',
'', $regextext);
11893 if ($matchrule == 1) {
11894 if ($var ==
'mainmenu') {
11896 return (preg_match(
'/^' . $regextext .
'/', $mainmenu));
11897 } elseif ($var ==
'leftmenu') {
11899 return (preg_match(
'/^' . $regextext .
'/', $leftmenu));
11901 return 'This variable is not accessible with dol_eval';
11904 return 'This value '.$matchrule.
' for param $matchrule is not yet implemented';
11918function verifCond($strToEvaluate, $onlysimplestring =
'1')
11922 if (isset($strToEvaluate) && $strToEvaluate !==
'') {
11925 $rep =
dol_eval($strToEvaluate, 1, 1, $onlysimplestring);
11929 $rights = (bool) $rep && (!is_string($rep) || strpos($rep,
'Bad call of') ===
false || strpos($rep,
'Bad string syntax to evaluate') ===
false);
11949function dol_eval($s, $returnvalue = 1, $hideerrors = 1, $onlysimplestring =
'1')
11951 if ($returnvalue != 1) {
11952 dol_syslog(
"Use of dol_eval with parameter returnvalue = 0 is now forbidden. Please fix this", LOG_ERR);
11976 $db, $langs, $user, $website, $websitepage,
11977 $action, $mainmenu, $leftmenu,
11989 defined(
'T_COALESCE_EQUAL') || define(
'T_COALESCE_EQUAL', PHP_INT_MAX);
11990 defined(
'T_FN') || define(
'T_FN', PHP_INT_MAX);
11993 defined(
'T_ATTRIBUTE') || define(
'T_ATTRIBUTE', PHP_INT_MAX);
11994 defined(
'T_MATCH') || define(
'T_MATCH', PHP_INT_MAX);
11995 defined(
'T_NAME_FULLY_QUALIFIED') || define(
'T_NAME_FULLY_QUALIFIED', PHP_INT_MAX);
11996 defined(
'T_NAME_QUALIFIED') || define(
'T_NAME_QUALIFIED', PHP_INT_MAX);
11997 defined(
'T_NAME_RELATIVE') || define(
'T_NAME_RELATIVE', PHP_INT_MAX);
12000 defined(
'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG') || define(
'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG', PHP_INT_MAX);
12001 defined(
'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG') || define(
'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG', PHP_INT_MAX);
12002 defined(
'T_ENUM') || define(
'T_ENUM', PHP_INT_MAX);
12003 defined(
'T_READONLY') || define(
'T_READONLY', PHP_INT_MAX);
12006 defined(
'T_PRIVATE_SET') || define(
'T_PRIVATE_SET', PHP_INT_MAX);
12007 defined(
'T_PROTECTED_SET') || define(
'T_PROTECTED_SET', PHP_INT_MAX);
12008 defined(
'T_PUBLIC_SET') || define(
'T_PUBLIC_SET', PHP_INT_MAX);
12010 $prohibited_token_ids = [
12017 'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG',
12018 'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG',
12068 'T_OPEN_TAG_WITH_ECHO',
12102 $prohibited_variables = [
12114 $prohibited_functions = [
12117 'override_function',
12119 'session_create_id',
12120 'session_regenerate_id',
12122 'call_user_func_array',
12131 'dol_eval_standard',
12139 'mb_eregi_replace',
12140 'dol_compress_dir',
12144 'dol_delete_dir_recursive',
12146 'archiveOrBackupFile',
12148 'file_put_contents',
12162 'filter_input_array',
12166 $prohibited_token_arrangements = [
12171 ' T_CONSTANT_ENCAPSED_STRING ( ',
12175 $tokens = token_get_all(
"<?php return {$s};", TOKEN_PARSE);
12177 $tokens_arrangement =
' ';
12179 for ($i = 2,
$c = count($tokens) - 1; $i <
$c; ++$i) {
12180 if (is_array($tokens[$i])) {
12181 $token_id = $tokens[$i][0];
12182 $token_value = $tokens[$i][1];
12183 $token_name = token_name($tokens[$i][0]);
12185 $token_id = $tokens[$i];
12186 $token_value = $tokens[$i];
12187 $token_name = $tokens[$i];
12191 if (T_WHITESPACE === $token_id) {
12196 $tokens_arrangement .=
"{$token_name} ";
12200 T_VARIABLE === $token_id
12201 && in_array($token_value, $prohibited_variables,
true)
12203 return "« {$token_value} » is prohibited in « {$s} »";
12208 T_STRING === $token_id
12209 && in_array($token_value, $prohibited_functions,
true)
12211 return "« {$token_value} » is prohibited in « {$s} »";
12216 $maxi = count($prohibited_token_ids);
12217 for ($i = 0; $i < $maxi; ++$i) {
12218 if (
false !== strpos($tokens_arrangement,
" {$prohibited_token_ids[$i]} ")) {
12219 return "« {$prohibited_token_ids[$i]} » is prohibited in « {$s} »";
12224 $maxi = count($prohibited_token_arrangements);
12225 for ($i = 0; $i < $maxi; ++$i) {
12226 if (
false !== strpos($tokens_arrangement, $prohibited_token_arrangements[$i])) {
12227 return "« {$prohibited_token_arrangements[$i]} » is prohibited in « {$s} »";
12233 return @eval(
"return {$s};") ??
'';
12234 }
catch (Throwable $ex) {
12235 return "Exception during evaluation: " . $s .
" - " . $ex->getMessage();
12259 global
$db, $langs, $user, $website, $websitepage;
12260 global $action, $mainmenu, $leftmenu;
12262 global $objectoffield;
12270 $isObBufferActive =
false;
12271 if ($onlysimplestring ==
'0') {
12272 $onlysimplestring =
'1';
12274 if (!in_array($onlysimplestring, array(
'1',
'2'))) {
12275 return "Bad call of dol_eval. Parameter onlysimplestring must be '1' or '2'.";
12277 if (!is_scalar($s)) {
12278 return "Bad call of dol_eval. First parameter must be a string, found ".var_export($s,
true);
12282 global $dolibarr_main_restrict_eval_methods;
12285 if (!isset($dolibarr_main_restrict_eval_methods)) {
12286 $dolibarr_main_restrict_eval_methods =
'getDolGlobalString, getDolGlobalInt, getDolCurrency, getDolEntity, getDolDBType, fetchNoCompute, hasRight, isAdmin, isExternalUser, isModEnabled, isStringVarMatching, abs, min, max, round, dol_now, preg_match';
12289 $dolibarr_main_restrict_eval_methods_array = explode(
',', str_replace(
" ",
"", $dolibarr_main_restrict_eval_methods));
12297 $specialcharsallowed =
'^$_+-.*>&|=!?():"\',/@';
12298 if ($onlysimplestring ==
'2') {
12299 $specialcharsallowed .=
'<[]';
12301 global $dolibarr_main_allow_unsecured_special_chars_in_dol_eval;
12302 if (!empty($dolibarr_main_allow_unsecured_special_chars_in_dol_eval)) {
12303 $specialcharsallowed .= (
string) $dolibarr_main_allow_unsecured_special_chars_in_dol_eval;
12305 if (preg_match(
'/[^a-z0-9\s' . preg_quote($specialcharsallowed,
'/') .
']/i', $s)) {
12306 return 'Bad string syntax to evaluate (found chars that are not chars for a simple one line clean eval string): ' . $s;
12318 if (strpos($s,
'/*') !==
false || strpos($s,
'//') !==
false) {
12319 return 'Bad string syntax to evaluate (The comment string /* and // are not allowed): ' . $s;
12323 $tmps = str_replace(
' ? ',
'__XXX__', $s);
12324 if (strpos($tmps,
'?') !==
false) {
12325 return 'Bad string syntax to evaluate (The char ? can be used only with a space before and after): ' . $s;
12329 if (preg_match(
'/<=?[^\s]/', $s)) {
12330 return 'Bad string syntax to evaluate (mode ' . $onlysimplestring .
', found a < or <= without space after): ' . $s;
12334 if (preg_match(
'/\$[\w]*\s*\(/', $s)) {
12335 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;
12338 if (empty($dolibarr_main_restrict_eval_methods)) {
12344 while ($scheck && $savescheck != $scheck) {
12345 $savescheck = $scheck;
12346 $scheck = preg_replace(
'/->[a-zA-Z0-9_]+\(/',
'->__METHOD__', $scheck);
12347 $scheck = preg_replace(
'/::[a-zA-Z0-9_]+\(/',
'->__METHOD__', $scheck);
12348 $scheck = preg_replace(
'/^\(+/',
'__PARENTHESIS__ ', $scheck);
12349 $scheck = preg_replace(
'/\&\&\s+\(/',
'__ANDPARENTHESIS__ ', $scheck);
12350 $scheck = preg_replace(
'/\|\|\s+\(/',
'__ORPARENTHESIS__ ', $scheck);
12351 $scheck = preg_replace(
'/^!?[a-zA-Z0-9_]+\(/',
'__FUNCTION__', $scheck);
12352 $scheck = preg_replace(
'/\s!?[a-zA-Z0-9_]+\(/',
'__FUNCTION__', $scheck);
12353 $scheck = preg_replace(
'/^!\(/',
'__NOTANDPARENTHESIS__', $scheck);
12354 $scheck = preg_replace(
'/\s!\(/',
' __NOTANDPARENTHESIS__', $scheck);
12355 $scheck = preg_replace(
'/(\^|\')\(/',
'__REGEXSTART__', $scheck);
12360 if (strpos($scheck,
'(') !==
false) {
12361 return 'Bad string syntax to evaluate (mode ' . $onlysimplestring .
', found call of a function or method without using the direct name of the function): ' . $s;
12365 if (strpos($s,
'`') !==
false) {
12366 return 'Bad string syntax to evaluate (backtick char is forbidden): ' . $s;
12371 if (preg_match(
'/[^0-9]+\.[^0-9]+/', $s)) {
12372 return 'Bad string syntax to evaluate (dot char is forbidden if not strictly between 2 numbers): ' . $s;
12380 while ($scheck && $savescheck != $scheck) {
12381 $savescheck = $scheck;
12382 $scheck = preg_replace(
'/\$conf->[a-z\_]+->enabled/',
'__VARCONFENABLED__', $scheck);
12383 $scheck = preg_replace(
'/\$user->id/',
'__VARUSERID__', $scheck);
12384 $scheck = preg_replace(
'/\$user->hasRight/',
'__VARUSERHASRIGHT__', $scheck);
12385 $scheck = preg_replace(
'/\$user->rights/',
'__VARUSERHASRIGHT__', $scheck);
12386 $scheck = preg_replace(
'/\$user->isAdmin/',
'__VARUSERHASRIGHT__', $scheck);
12387 $scheck = preg_replace(
'/\$user->admin/',
'__VARUSERISADMIN__', $scheck);
12388 $scheck = preg_replace(
'/\$user->isExternalUser/',
'__VARUSERSOCID__', $scheck);
12389 $scheck = preg_replace(
'/\$user->socid/',
'__VARUSERSOCID__', $scheck);
12390 $scheck = preg_replace(
'/\(\$db\)/',
'__VARDB__', $scheck);
12391 $scheck = preg_replace(
'/\$langs/',
'__VARLANGSTRANS__', $scheck);
12392 $scheck = preg_replace(
'/\$mysoc/',
'__VARMYSOC__', $scheck);
12393 $scheck = preg_replace(
'/\$action/',
'__VARACTION__', $scheck);
12394 $scheck = preg_replace(
'/\$mainmenu/',
'__VARMAINMENU__', $scheck);
12395 $scheck = preg_replace(
'/\$leftmenu/',
'__VARLEFTMENU__', $scheck);
12396 $scheck = preg_replace(
'/\$websitepage/',
'__VARWEBSITEPAGE__', $scheck);
12397 $scheck = preg_replace(
'/\$website/',
'__VARWEBSITE__', $scheck);
12398 $scheck = preg_replace(
'/\$objectoffield/',
'__VAROBJECTOFFIELD__', $scheck);
12399 $scheck = preg_replace(
'/\$object/',
'__VAROBJECT__', $scheck);
12400 $scheck = preg_replace(
'/\$var/',
'__VARVAR__', $scheck);
12403 $scheck = preg_replace(
'/\$soc->canvas/',
'__VARSOCCANVAS__', $scheck);
12404 $scheck = preg_replace(
'/\$obj->canvas/',
'__VAROBJCANVAS__', $scheck);
12407 if (strpos($scheck,
'$') !==
false) {
12408 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);
12409 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;
12414 $forbiddenphpstrings = array(
'_ENV',
'_SESSION',
'_COOKIE',
'_GET',
'_GLOBAL',
'_POST',
'_REQUEST',
'ReflectionFunction',
'SplFileObject',
'SplTempFileObject');
12416 if (empty($dolibarr_main_restrict_eval_methods)) {
12420 $forbiddenphpfunctions = array();
12421 $forbiddenphpmethods = array();
12423 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"override_function",
"session_id",
"session_create_id",
"session_regenerate_id"));
12424 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"get_defined_functions",
"get_defined_vars",
"get_defined_constants",
"get_declared_classes"));
12425 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"function",
"call_user_func",
"call_user_func_array"));
12427 $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"));
12428 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"usort",
"uasort",
"uksort",
"preg_replace_callback",
"preg_replace_callback_array",
"header_register_callback"));
12429 $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"));
12430 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"spl_autoload_register",
"spl_autoload_unregister",
"iterator_apply",
"session_set_save_handler"));
12431 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"forward_static_call",
"forward_static_call_array",
"register_postsend_function"));
12433 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"ob_start"));
12435 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"require",
"include",
"require_once",
"include_once"));
12436 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"exec",
"passthru",
"shell_exec",
"system",
"proc_open",
"popen"));
12437 $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"));
12438 $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", ));
12439 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"putenv",
"dl",
"apache_child_terminate",
"apache_setenv"));
12440 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"posix_kill",
"posix_setuid",
"posix_setgid"));
12441 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_eval",
"dol_eval_new",
"dol_eval_standard",
"executeCLI",
"verifCond",
"GETPOST",
"dolEncrypt",
"dolDecrypt"));
12442 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"eval",
"create_function",
"assert",
"mb_ereg_replace"));
12443 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"readline_completion_function",
"readline_callback_handler_install"));
12444 $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"));
12445 $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"));
12446 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"require",
"include"));
12449 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"base64" .
"_" .
"decode",
"rawurl" .
"decode",
"url" .
"decode",
"str" .
"_rot13",
"hex" .
"2bin",
"printf",
"sprintf"));
12450 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_concat",
"dol_concatdesc"));
12459 $forbiddenphpmethods = array_merge($forbiddenphpmethods, array(
'invoke',
'invokeArgs'));
12467 $forbiddenphpregex =
'global\s*\$';
12468 $forbiddenphpregex .=
'|';
12469 $forbiddenphpregex .=
'\b(' . implode(
'|', $forbiddenphpfunctions) .
')\b';
12471 $forbiddenphpmethodsregex =
'->(' . implode(
'|', $forbiddenphpmethods) .
')';
12475 $oldstringtoclean = $s;
12476 $s = str_ireplace($forbiddenphpstrings,
'__forbiddenstring__', $s);
12477 $s = preg_replace(
'/' . $forbiddenphpregex .
'/i',
'__forbiddenstring__', $s);
12478 $s = preg_replace(
'/' . $forbiddenphpmethodsregex .
'/i',
'__forbiddenstring__', $s);
12480 }
while ($oldstringtoclean != $s);
12482 if (strpos($s,
'__forbiddenstring__') !==
false) {
12483 dol_syslog(
'Bad string syntax to evaluate: ' . $s, LOG_WARNING);
12484 return 'Bad string syntax to evaluate: ' . $s;
12488 if (!empty($dolibarr_main_restrict_eval_methods)) {
12491 $pattern =
'/([\s\w\'\]\"]+)\(/';
12493 $matches = array();
12494 preg_match_all($pattern, $s, $matches);
12496 if (count($matches)) {
12497 foreach ($matches[1] as $m) {
12503 if (!preg_match(
'/new ([A-Z][\w]+)/i', $m, $reg)) {
12504 if (!in_array($m, $dolibarr_main_restrict_eval_methods_array)) {
12505 if ($m !=
"'" && $m !=
'"') {
12506 dol_syslog(
'Bad string syntax to evaluate: ' . $s, LOG_WARNING);
12507 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;
12511 if (!class_exists($reg[1])) {
12512 dol_syslog(
'Bad string syntax to evaluate: Class "'.$reg[1].
'" does not exist. ' . $s, LOG_WARNING);
12513 return 'Bad string syntax to evaluate. Class "'.$reg[1].
'" does not exist. ' . $s;
12515 $parents = class_parents($reg[1]);
12516 if (!in_array(
'CommonObject', $parents)) {
12517 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);
12518 return 'Bad string syntax to evaluate. Class "'.$reg[1].
'" is not allowed because only classes extended CommonObject can be used in dynamic evaluation. ' . $s;
12524 $forbiddenphpregex =
'global\s*\$';
12525 $forbiddenphpregex .=
'|';
12526 $forbiddenphpregex .=
'}\s*\[';
12527 $forbiddenphpregex .=
'|';
12528 $forbiddenphpregex .=
'\)\s*\(';
12532 $oldstringtoclean = $s;
12533 $s = str_ireplace($forbiddenphpstrings,
'__forbiddenstring__', $s);
12534 $s = preg_replace(
'/' . $forbiddenphpregex .
'/i',
'__forbiddenstring__', $s);
12537 }
while ($oldstringtoclean != $s);
12539 if (strpos($s,
'__forbiddenstring__') !==
false) {
12540 dol_syslog(
'Bad string syntax to evaluate: ' . $s, LOG_WARNING);
12541 return 'Bad string syntax to evaluate: ' . $s;
12547 $isObBufferActive =
true;
12548 $tmps = $hideerrors ? @eval(
'return ' . $s .
';') : eval(
'return ' . $s .
';');
12549 $tmpo = ob_get_clean();
12550 $isObBufferActive =
false;
12552 print
'Bad string syntax to evaluate. Some data were output when it should not when evaluating: ' . $s;
12556 if ($isObBufferActive) {
12558 $tmpo = ob_get_clean();
12559 $isObBufferActive =
false;
12561 $error =
'dol_eval try/catch error for string: ' . $s .
' - Error: ';
12562 $error .= $e->getMessage();
12564 return 'Exception during evaluation: ' . $s;
12565 }
catch (Error $e) {
12566 if ($isObBufferActive) {
12568 $tmpo = ob_get_clean();
12569 $isObBufferActive =
false;
12571 $error =
'dol_eval try/catch error for string: ' . $s .
' - Error: ';
12572 $error .= $e->getMessage();
12574 return 'Exception during evaluation: ' . $s;
12587 return (trim($element) !=
'');
12600 if (empty($codelang)) {
12604 if ($codelang ==
'auto') {
12605 return '<span class="fa fa-language"></span>';
12608 $langtocountryflag = array(
12610 'ca_ES' =>
'catalonia',
12614 'sw_SW' =>
'unknown',
12624 if (isset($langtocountryflag[$codelang])) {
12625 $flagImage = $langtocountryflag[$codelang];
12627 $tmparray = explode(
'_', $codelang);
12628 $flagImage = empty($tmparray[1]) ? $tmparray[0] : $tmparray[1];
12633 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
12634 $morecss = $reg[1];
12639 return '<span class="flag-sprite ' . strtolower($flagImage) . ($morecss ?
' ' . $morecss :
'') .
'"' . ($moreatt ?
' ' . $moreatt :
'') . (!$notitlealt ?
' title="' . $codelang .
'"' :
'') .
'></span>';
12653 if (empty($countrycode)) {
12657 if (strtoupper($countrycode) ==
'MQ') {
12660 if (strtoupper($countrycode) ==
'SE') {
12663 if (strtoupper($countrycode) ==
'CH') {
12664 if (
$mysoc->country_code ==
'FR') {
12667 if (
$mysoc->country_code ==
'DE') {
12670 if (
$mysoc->country_code ==
'IT') {
12852 $buildprimarykeytotest = strtolower($countrycode) .
'-' . strtoupper($countrycode);
12853 if (in_array($buildprimarykeytotest, $locales)) {
12854 return strtolower($countrycode) .
'_' . strtoupper($countrycode);
12857 if (function_exists(
'locale_get_primary_language') && function_exists(
'locale_get_region')) {
12858 foreach ($locales as $locale) {
12859 $locale_language = locale_get_primary_language($locale);
12860 $locale_region = locale_get_region($locale);
12861 if (strtoupper($countrycode) == $locale_region) {
12863 return strtolower($locale_language) .
'_' . strtoupper($locale_region);
12867 dol_syslog(
"Warning Extension php-intl is not available", LOG_WARNING);
12905 global $hookmanager,
$db;
12907 if (isset(
$conf->modules_parts[
'tabs'][$type]) && is_array(
$conf->modules_parts[
'tabs'][$type])) {
12908 foreach (
$conf->modules_parts[
'tabs'][$type] as $value) {
12909 $values = explode(
':', $value);
12912 if ($mode ==
'add' && !preg_match(
'/^\-/', $values[1])) {
12913 if (count($values) !== 6) {
12914 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);
12921 if ($values[0] != $type) {
12929 $posstart = strpos($str,
'(');
12930 if ($posstart > 0) {
12931 $posend = strpos($str,
')');
12932 if ($posstart > 0) {
12933 $res1 = substr($str, $posstart + 1, $posend - $posstart - 1);
12934 if (is_numeric($res1)) {
12935 $postab = (int) $res1;
12936 $values[1] =
'+' . substr($str, $posend + 1);
12941 global $objectoffield;
12949 if ($filterorigmodule) {
12950 if (strpos($values[3],
'@')) {
12951 if ($filterorigmodule !=
'external') {
12955 if ($filterorigmodule !=
'core') {
12960 $langs->load($values[3]);
12963 if (preg_match(
'/SUBSTITUTION_([^_]+)/i', $values[2], $reg)) {
12965 $substitutionarray = array();
12970 $labeltemp = explode(
',', $values[2]);
12971 $label = $langs->trans($labeltemp[0]);
12973 if (!empty($labeltemp[1]) && is_object(
$object) && !empty(
$object->id)) {
12975 $classtoload = $labeltemp[1];
12976 if (class_exists($classtoload)) {
12977 $obj =
new $classtoload(
$db);
12978 $function = $labeltemp[3];
12979 if ($obj && $function && method_exists($obj, $function)) {
12981 $nbrec = $obj->$function(
$object->id, $obj);
12982 if (!empty($nbrec)) {
12983 $label .=
'<span class="badge marginleftonlyshort">' . $nbrec .
'</span>';
12989 $url = preg_replace(
'/__ID__/i', ((is_object(
$object) && !empty(
$object->id)) ?
$object->id :
''), $values[5]);
12990 $link = parse_url($url);
12992 if (isset($link[
'query'])) {
12993 parse_str($link[
'query'], $query);
12996 $newtab[1] = $label;
12997 $newtab[2] = str_replace(
'+',
'', $values[1]);
13001 $head = array_merge(array_slice($head, 0, $postab), array($newtab), array_slice($head, $postab));
13002 } elseif ($mode ==
'remove' && preg_match(
'/^\-/', $values[1])) {
13003 if ($values[0] != $type) {
13006 $tabname = str_replace(
'-',
'', $values[1]);
13007 foreach ($head as $key => $val) {
13008 $condition = (!empty($values[3]) ?
verifCond($values[3],
'2') : 1);
13010 if ($head[$key][2] == $tabname && $condition) {
13011 unset($head[$key]);
13020 if (!empty($hookmanager)) {
13021 $parameters = array(
'object' =>
$object,
'mode' => $mode,
'head' => &$head,
'filterorigmodule' => $filterorigmodule,
'type' => $type);
13023 $reshook = $hookmanager->executeHooks(
'completeTabsHead', $parameters,
$object);
13024 if ($reshook > 0) {
13025 $head = $hookmanager->resArray;
13027 $head = array_merge($head, $hookmanager->resArray);
13046 global
$conf, $hookmanager, $user, $langs;
13048 global $micro_start_time;
13050 if ($zone ==
'private') {
13051 print
"\n" .
'<!-- Common footer for private page -->' .
"\n";
13053 print
"\n" .
'<!-- Common footer for public page -->' .
"\n";
13057 print
"\n<!-- A div to store page_y POST parameter -->\n";
13058 print
'<div id="page_y" style="display: none;">' . (
GETPOST(
'page_y') ?
GETPOST(
'page_y') :
'') .
'</div>' .
"\n";
13060 $parameters = array(
'zone' => $zone);
13063 $reshook = $hookmanager->executeHooks(
'printCommonFooter', $parameters, $tmpobject, $action);
13064 if (empty($reshook)) {
13070 if (!empty(
$conf->use_javascript_ajax)) {
13071 print
"\n<!-- A script section to add menuhider handler on backoffice, manage focus and mandatory fields, tuning info, ... -->\n";
13072 print
'<script>' .
"\n";
13073 print
'jQuery(document).ready(function() {' .
"\n";
13075 if ($zone ==
'private' && empty(
$conf->dol_use_jmobile)) {
13077 print
'/* JS CODE TO ENABLE to manage handler to switch left menu page (menuhider) */' .
"\n";
13078 print
'jQuery("li.menuhider").click(function(event) {';
13079 print
' if (!$( "body" ).hasClass( "sidebar-collapse" )){ event.preventDefault(); }' .
"\n";
13080 print
' console.log("We click on .menuhider");' .
"\n";
13081 print
' $("body").toggleClass("sidebar-collapse")' .
"\n";
13082 print
'});' .
"\n";
13086 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"])))) {
13087 print
'/* JS CODE TO ENABLE to manage focus and mandatory form fields */' .
"\n";
13088 $relativepathstring = $_SERVER[
"PHP_SELF"];
13090 if (constant(
'DOL_URL_ROOT')) {
13091 $relativepathstring = preg_replace(
'/^' . preg_quote(constant(
'DOL_URL_ROOT'),
'/') .
'/',
'', $relativepathstring);
13093 $relativepathstring = preg_replace(
'/^\//',
'', $relativepathstring);
13094 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
13097 if (!empty($user->default_values[$relativepathstring][
'focus'])) {
13098 foreach ($user->default_values[$relativepathstring][
'focus'] as $defkey => $defval) {
13100 if ($defkey !=
'_noquery_') {
13101 $tmpqueryarraytohave = explode(
'&', $defkey);
13103 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
13104 $tmpquerytohaveparam = explode(
'=', $tmpquerytohave);
13106 if (!GETPOSTISSET($tmpquerytohaveparam[0]) || ($tmpquerytohaveparam[1] !=
GETPOST($tmpquerytohaveparam[0]))) {
13110 if (!$foundintru) {
13119 print
'console.log("set the focus by executing jQuery(...).focus();")' .
"\n";
13120 foreach ($defval as $paramkey => $paramval) {
13122 print
'jQuery("input[name=\'' . $paramkey .
'\']
").focus();' . "\n
";
13123 print 'jQuery("textarea[
name=\
'' . $paramkey .
'\']
").focus();' . "\n
"; // TODO KO with ckeditor
13124 print 'jQuery("select[
name=\
'' . $paramkey .
'\']
").focus();' . "\n
"; // Not really useful, but we keep it in case of.
13129 if (!empty($user->default_values[$relativepathstring]['mandatory'])) {
13130 foreach ($user->default_values[$relativepathstring]['mandatory'] as $defkey => $defval) {
13132 if ($defkey != '_noquery_') {
13133 $tmpqueryarraytohave = explode('&', $defkey);
13135 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
13136 $tmpquerytohaveparam = explode('=', $tmpquerytohave);
13137 //print "console.log(
'".$tmpquerytohaveparam[0]." ".$tmpquerytohaveparam[1]." ".GETPOST($tmpquerytohaveparam[0])."');
";
13138 if (!GETPOSTISSET($tmpquerytohaveparam[0]) || ($tmpquerytohaveparam[1] != GETPOST($tmpquerytohaveparam[0]))) {
13142 if (!$foundintru) {
13145 //var_dump($defkey.'-'.$qualified);
13151 print 'console.log("set the js code to manage fields that are
set as mandatory
");' . "\n
";
13153 foreach ($defval as $paramkey => $paramval) {
13154 // Solution 1: Add handler on submit to check if mandatory fields are empty
13155 print 'var form = $(\'[name="'.dol_escape_js($paramkey).'"]\').closest("form
");'."\n
";
13156 print "form.on(
'submit',
function(event) {
13157 var submitter = \$(
this).find(
':submit:focus').get(0);
13158 var buttonName = submitter ? \$(submitter).attr(
'name') :
'save';
13160 if (buttonName ==
'cancel') {
13161 console.log(
'We click on cancel button so we accept submit with no need to check mandatory fields');
13165 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');
13167 var tmpvalue = jQuery(
'[name=\"".dol_escape_js($paramkey)."\"]').val();
13168 let tmptypefield = jQuery(
'[name=\"".dol_escape_js($paramkey)."\"]').prop(
'nodeName').toLowerCase();
13170 if (tmptypefield ==
'textarea') {
13172 var tmpeditor = CKEDITOR.instances[
'" . dol_escape_js($paramkey) . "'];
13174 tmpvalue = tmpeditor.getData();
13175 console.log(
'For textarea tmpvalue is '+tmpvalue);
13179 let tmpvalueisempty =
false;
13180 if (tmpvalue ===
null || tmpvalue === undefined || tmpvalue ===
'' || tmpvalue === -1) {
13181 tmpvalueisempty =
true;
13183 if (tmpvalue ===
'0' && (tmptypefield ==
'select' || tmptypefield ==
'input')) {
13184 tmpvalueisempty =
true;
13186 if (tmpvalueisempty && buttonName !==
'cancel') {
13187 console.log(
'field has type '+tmptypefield+
' and is empty, we cancel the submit');
13188 event.preventDefault();
13189 event.stopPropagation();
13191 alert(
'".dol_escape_js($langs->transnoentitiesnoconv("ErrorFieldRequired", $paramkey).' (
'.$langs->transnoentitiesnoconv("CustomMandatoryFieldRule").')
')."');
13195 console.log(
'field has type '+tmptypefield+
' and is defined to '+tmpvalue);
13200 // Solution 2: Add property 'required' on input
13201 // so browser will check value and try to focus on it when submitting the form.
13202 //print 'setTimeout(function() {'; // If we want to wait that ckeditor beuatifier has finished its job.
13203 //print 'jQuery("input[
name=\
''.$paramkey.
'\']
").prop(\'required\',true);'."\n
";
13204 //print 'jQuery("textarea[
id=\
''.$paramkey.
'\']
").prop(\'required\',true);'."\n
";
13205 //print 'jQuery("select[
name=\
''.$paramkey.
'\']
").prop(\'required\',true);'."\n
";*/
13206 //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
";
13207 //print 'jQuery("select[
name=\
''.$paramkey.
'\'] option[value=\
'-1\']").prop(\'value\', \'\');'.
"\n";
13213 print
'jQuery(\':input[name="' .
dol_escape_js($paramkey) .
'"]\').closest("tr").find("td:first").addClass("fieldrequired");' .
"\n";
13217 print
'jQuery("input[name=\'cancel\']").click(function() {
13218 console.log("We click on cancel button so removed all required attribute");
13219 jQuery("input, textarea, select").each(function(){this.removeAttribute(\'required\');});
13226 print
'});' .
"\n";
13229 if (!empty($_SERVER[
'MAIN_SHOW_TUNING_INFO']) ||
getDolGlobalString(
'MAIN_SHOW_TUNING_INFO')) {
13231 print
"/* JS CODE TO ENABLE to add memory info */\n";
13232 print
'window.console && console.log("';
13237 if (!empty($micro_start_time)) {
13238 $micro_end_time = microtime(
true);
13239 print
' - Build time: ' . ceil(1000 * ($micro_end_time - $micro_start_time)) .
' ms';
13242 if (function_exists(
"memory_get_usage")) {
13243 print
' - Mem: ' . memory_get_usage();
13245 if (function_exists(
"memory_get_peak_usage")) {
13246 print
' - Real mem peak: ' . memory_get_peak_usage(
true);
13248 if (function_exists(
"zend_loader_file_encoded")) {
13249 print
' - Zend encoded file: ' . (zend_loader_file_encoded() ?
'yes' :
'no');
13251 print
'");' .
"\n";
13254 print
"\n" .
'</script>' .
"\n";
13260 foreach ($tmptagarray as $tmptag) {
13262 print
"<!-- JS CODE TO ENABLE for google analtics tag -->\n";
13264 <!-- Global site tag (gtag.js) - Google Analytics -->
13265 <script nonce="' . getNonce() .
'" async src="https://www.googletagmanager.com/gtag/js?id=' . trim($tmptag) .
'"></script>
13267 window.dataLayer = window.dataLayer || [];
13268 function gtag(){dataLayer.push(arguments);}
13269 gtag(\'js\', new Date());
13271 gtag(\'config\', \'' . trim($tmptag) .
'\');
13278 // Add Xdebug coverage of code
13279 if (defined('XDEBUGCOVERAGE
')) {
13280 print_r(xdebug_get_code_coverage());
13283 // Output string from hooks
13284 if (!empty($hookmanager->resPrint)) {
13285 print $hookmanager->resPrint;
13288 // Add DebugBar data
13289 if ($user->hasRight('debugbar
', 'read
')) {
13291 if ($debugbar instanceof DebugBar\DebugBar) {
13292 if (isset($debugbar['time
'])) {
13293 // @phan-suppress-next-line PhanPluginUnknownObjectMethodCall
13294 $debugbar['time
']->stopMeasure('pageaftermaster
');
13296 print '<!-- Output debugbar data -->
' . "\n";
13297 $renderer = $debugbar->getJavascriptRenderer();
13298 print $renderer->render();
13300 } elseif (count($conf->logbuffer)) { // If there is some logs in buffer to show
13302 print "<!-- Start of log output\n";
13303 //print '<div
class=
"hidden">
'."\n";
13304 foreach ($conf->logbuffer as $logline) {
13305 print $logline . "<br>\n";
13307 //print '</div>
'."\n";
13308 print "End of log output -->\n";
13322function dolExplodeIntoArray($string, $delimiter = ';
', $kv = '=
')
13324 if (is_null($string)) {
13328 if (preg_match('/^\[.*\]$/sm
', $delimiter) || preg_match('/^\(.*\)$/sm
', $delimiter)) {
13329 // This is a regex string
13330 $newdelimiter = $delimiter;
13332 // This is a simple string
13333 // @phan-suppress-next-line PhanPluginSuspiciousParamPositionInternal
13334 $newdelimiter = preg_quote($delimiter, '/
');
13337 if ($a = preg_split('/
' . $newdelimiter . '/
', $string)) {
13339 foreach ($a as $s) { // each part
13341 if ($pos = strpos($s, $kv)) { // key/value delimiter
13342 $ka[trim(substr($s, 0, $pos))] = trim(substr($s, $pos + strlen($kv)));
13343 } else { // key delimiter not found
13361function dolExplodeKeepIfQuotes($input)
13363 // Use regexp to capture words and section in quotes
13364 $matches = array();
13365 preg_match_all('/
"([^"]*)
"|\'([^\']*)\'|(\S+)/', $input, $matches);
13367 // Merge result and delete empty values
13369 $result = array_map(
13376 static function ($a, $b, $c) {
13392 return array_values(array_filter(
13400 static function ($val) {
13401 return $val !== '';
13413function dol_set_focus($selector)
13415 print "\n
" . '<!-- Set focus onto a specific field -->' . "\n
";
13416 print '<script nonce="' . getNonce() . '">jQuery(document).ready(function() { console.log("Force focus by
dol_set_focus"); jQuery("' . dol_escape_js($selector) . '").focus(); });</script>' . "\n
";
13427function dol_getmypid()
13429 if (!function_exists('getmypid')) {
13430 return mt_rand(99900000, 99965535);
13432 return getmypid(); // May be a number on 64 bits (depending on OS)
13458function natural_search($fields, $value, $mode = 0, $nofirstand = 0, $sqltoadd = '')
13460 global $db, $langs;
13462 $value = trim($value);
13465 $value = preg_replace('/\*/', '%', $value); // Replace * with %
13468 $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
13471 $value = preg_replace('/\s*\|\s*/', '|', $value);
13473 // Split criteria on ' ' but not if we are inside quotes.
13474 // For mode 3, the split is done later on the , only and not on the ' '.
13475 if ($mode != -3 && $mode != 3) {
13476 $crits = dolExplodeKeepIfQuotes($value);
13478 $crits = array($value);
13482 if (!is_array($fields)) {
13483 $fields = array($fields);
13485 $i1 = 0; // count the nb of "and
" criteria added (all fields / criteria)
13486 foreach ($crits as $crit) { // Loop on each AND criteria
13487 $crit = trim($crit);
13488 $i2 = 0; // count the nb of valid criteria added for this this first criteria
13491 foreach ($fields as $field) {
13493 $tmpcrits = explode('|', $crit);
13494 $i3 = 0; // count the nb of valid criteria added for this current field
13495 foreach ($tmpcrits as $tmpcrit) {
13496 if ($tmpcrit !== '0' && empty($tmpcrit)) {
13499 $tmpcrit = trim($tmpcrit);
13501 $newres .= (($i2 > 0 || $i3 > 0) ? ' OR ' : '');
13504 $newcrit = preg_replace('/([!<>=]+)/', '', $tmpcrit);
13507 preg_match('/([!<>=]+)/', $tmpcrit, $reg);
13508 if (!empty($reg[1])) {
13509 $operator = $reg[1];
13511 if ($newcrit != '') {
13512 $numnewcrit = price2num($newcrit);
13513 if (is_numeric($numnewcrit)) {
13514 $newres .= $db->sanitize($field) . ' ' . $operator . ' ' . ((float) $numnewcrit); // should be a numeric
13516 $newres .= '1 = 2'; // force false, we received a corrupted data
13518 $i3++; // a criteria was added to string
13521 $i2++; // a criteria for 1 more field was added to string
13522 } elseif ($mode == 2 || $mode == -2) {
13523 $crit = preg_replace('/[^\-0-9,]/', '', $crit); // ID are always integer
13524 $newres .= ($i2 > 0 ? ' OR ' : '') . $db->sanitize($field) . " " . ($mode == -2 ? 'NOT ' : '');
13525 $newres .= $crit ? "IN (
" . $db->sanitize($db->escape($crit)) . ")
" : "IN (0)
";
13527 $newres .= ' OR ' . $db->sanitize($field) . ' IS NULL';
13529 $i2++; // a criteria for 1 more field was added to string
13530 } elseif ($mode == 3 || $mode == -3) {
13531 $tmparray = explode(',', $crit);
13532 if (count($tmparray)) {
13534 $listofcodesnot = '';
13535 foreach ($tmparray as $val) {
13538 if (preg_match('/^!/', $val)) {
13539 $listofcodesnot .= ($listofcodesnot ? ',' : '');
13540 $listofcodesnot .= "'" . $db->escape(preg_replace('/^!=?/
', '', $val)) . "'";
13542 $listofcodes .= ($listofcodes ? ',' : '');
13543 $listofcodes .= "'" . $db->escape($val) . "'";
13547 $newres .= ($i2 > 0 ? ' OR ' : '');
13548 if ($listofcodes && $listofcodesnot) {
13551 if ($listofcodes) {
13552 $newres .= $db->sanitize($field) . " " . ($mode == -3 ? 'NOT IN' : 'IN') . " (
" . $db->sanitize($listofcodes, 1, 0, 1) . ")
";
13554 if ($listofcodes && $listofcodesnot) {
13555 $newres .= ' AND ';
13557 if ($listofcodesnot) {
13558 $newres .= $db->sanitize($field) . " " . ($mode == -3 ? 'IN ' : 'NOT IN') . " (
" . $db->sanitize($listofcodesnot, 1, 0, 1) . ")
";
13560 if ($listofcodes && $listofcodesnot) {
13563 $i2++; // a criteria for 1 more field was added to string
13566 $newres .= ' OR ' . $db->sanitize($field) . ' IS NULL';
13568 } elseif ($mode == 4) {
13569 $tmparray = explode(',', $crit);
13570 if (count($tmparray)) {
13572 foreach ($tmparray as $val) {
13575 $newres .= ($i2 > 0 ? " OR (
" : "(
") . $db->sanitize($field) . " LIKE
'" . $db->escape($val) . ",%'";
13576 $newres .= ' OR ' . $db->sanitize($field) . " =
'" . $db->escape($val) . "'";
13577 $newres .= ' OR ' . $db->sanitize($field) . " LIKE
'%," . $db->escape($val) . "'";
13578 $newres .= ' OR ' . $db->sanitize($field) . " LIKE
'%," . $db->escape($val) . ",%'";
13580 $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)
13584 } else { // $mode=0
13585 $tmpcrits = explode('|', $crit);
13586 $i3 = 0; // count the nb of valid criteria added for the current couple criteria/field
13587 foreach ($tmpcrits as $tmpcrit) { // loop on each OR criteria
13588 if ($tmpcrit !== '0' && empty($tmpcrit)) {
13591 $tmpcrit = trim($tmpcrit);
13593 if ($tmpcrit == '^$' || strpos($crit, '!') === 0) { // If we search empty, we must combined different OR fields with AND
13594 $newres .= (($i2 > 0 || $i3 > 0) ? ' AND ' : '');
13596 $newres .= (($i2 > 0 || $i3 > 0) ? ' OR ' : '');
13599 $isSellist = false;
13600 $table = $label = $key = null;
13602 if (strpos($field, 'ef.') === 0) {
13603 $extrafieldName = substr($field, 3);
13604 $extrafields = new ExtraFields($db);
13605 $extrafields->fetch_name_optionals_label('product');
13607 if (isset($extrafields->attributes['product']['type'][$extrafieldName]) && $extrafields->attributes['product']['type'][$extrafieldName] === 'sellist') {
13609 $paramArray = $extrafields->attributes['product']['param'][$extrafieldName]['options'] ?? [];
13610 $param = array_key_first($paramArray);
13611 list($table, $label, $key) = explode(':', $param);
13615 if (preg_match('/\.(id|rowid)$/', $field)) { // Special case for rowid that is sometimes a ref so used as a search field
13616 $newres .= $db->sanitize($field) . " =
" . (is_numeric($tmpcrit) ? ((float) $tmpcrit) : '0');
13618 $tmpcrit2 = $tmpcrit;
13624 $newres .= $field . " IN (SELECT t.
" . $key . " FROM
" . $db->prefix() . $table . " AS t WHERE t.
" . $label . " LIKE
'%" . $db->escape($tmpcrit2) . "%')
";
13626 if (preg_match('/^!/', $tmpcrit)) {
13627 $tmps .= $db->sanitize($field) . " NOT LIKE
"; // ! as exclude character
13628 $tmpcrit2 = preg_replace('/^!/', '', $tmpcrit2);
13630 $tmps .= $db->sanitize($field) . " LIKE
";
13634 if (preg_match('/^[\^\$]/
', $tmpcrit)) {
13636 $tmpcrit2 = preg_replace('/^[\^\$]/
', '', $tmpcrit2);
13638 if (preg_match('/[\^\$]$/
', $tmpcrit)) {
13640 $tmpcrit2 = preg_replace('/[\^\$]$/
', '', $tmpcrit2);
13643 if ($tmpcrit2 == '' || preg_match('/^!/
', $tmpcrit)) {
13644 $tmps = "(" . $tmps;
13647 $newres .= $tmpbefore;
13648 $newres .= $db->escape($tmpcrit2);
13649 $newres .= $tmpafter;
13651 if ($tmpcrit2 == '' || preg_match('/^!/', $tmpcrit)) {
13652 $newres .= " OR
" . $field . " IS NULL)
";
13660 $i2++; // a criteria for 1 more field was added to string
13665 $newres .= ($newres ? '' : ' OR ').str_replace('__KEYTOSEARCH__', $crit, $sqltoadd);
13669 $res = $res . ($res ? ' AND ' : '') . ($i2 > 1 ? '(' : '') . $newres . ($i2 > 1 ? ')' : '');
13673 $res = ($nofirstand ? "" : " AND
") . "(
" . $res . ")
";
13685function showSimpleOrderTable($outputlangs, $object)
13690 $discountIsAvailable = false;
13691 $orderPositionHasNoPrice = false;
13693 if(!property_exists($object->lines[0], "remise_percent
") ||
13694 !property_exists($object->lines[0], "fk_unit
") ||
13695 !property_exists($object->lines[0], "multicurrency_total_ttc
") ||
13696 !property_exists($object->lines[0], "description") ||
13697 !property_exists($object->lines[0], "qty
")) {
13701 foreach($object->lines as $order_position) {
13703 if(!property_exists($order_position, "price")){
13704 $orderPositionHasNoPrice = true;
13708 if(!empty($order_position->remise_percent)){
13709 $discountIsAvailable = true;
13714 if($orderPositionHasNoPrice){
13718 $discountHeader = $discountIsAvailable ? `<th style="width:120px
">{$outputlangs->trans("Discount
")}</th>` : "";
13720 $table = '<table border="0
" cellpadding="1
" cellspacing="1
">';
13722 $table .= <<<TABLEHEADER
13725 <th style="width:50px; text-align:left
">#</th>
13726 <th style="text-align:left
">{$outputlangs->trans("Description
")}</th>
13727 <th style="width:120px; text-align:right;
">{$outputlangs->trans("Price
")}</th>
13728 <th style="width:100px; text-align:right;
">{$outputlangs->trans("Quantity
")}</th>
13729 <th style="width:120px; text-align:right;
">{$outputlangs->trans("Unit
")}</th>
13731 <th style="width:120px; text-align:right;
">{$outputlangs->trans("Sum
")}</th>
13737 foreach($object->lines as $index => $order_position) {
13739 $position = $index + 1;
13740 $price = price($order_position->price, 0, $outputlangs, 0, -1, -1, $conf->currency);
13741 $unit = measuringUnitString($order_position->fk_unit,'','',1);
13742 $total = price($order_position->multicurrency_total_ttc, 0, $outputlangs, 0, -1, -1, $conf->currency);
13743 $discount = $discountIsAvailable ? `<td style="text-align:center
">{$order_position->remise_percent}%</td>` : "";
13746 $table .= <<<ORDERPOSITION
13749 <td>$order_position->description</td>
13750 <td style="text-align:right
">$price</td>
13751 <td style="text-align:right
">$order_position->qty</td>
13752 <td style="text-align:right
">$unit</td>
13754 <td style="text-align:right
">$total</td>
13760 $table .= '</tbody></table>';
13770function showDirectDownloadLink($object)
13775 $url = $object->getLastMainDocLink($object->element);
13777 $out .= img_picto($langs->trans("PublicDownloadLinkDesc
"), 'globe') . ' <span class="opacitymedium
">' . $langs->trans("DirectDownloadLink
") . '</span><br>';
13779 $out .= '<div class="urllink
"><input type="text
" id="directdownloadlink
" class="quatrevingtpercent
" value="' . $url . '"></div>';
13780 $out .= ajax_autoselect("directdownloadlink
", '');
13782 $out .= '<div class="urllink
">' . $langs->trans("FileNotShared
") . '</div>';
13796function getImageFileNameForSize($file, $extName, $extImgTarget = '')
13798 $dirName = dirname($file);
13799 if ($dirName == '.') {
13803 if (!in_array($extName, array('', '_small', '_mini'))) {
13804 return 'Bad parameter extName';
13807 $fileName = preg_replace('/(\.gif|\.jpeg|\.jpg|\.png|\.bmp|\.webp|\.avif)$/i', '', $file); // We remove image extension, whatever is its case
13808 $fileName = basename($fileName);
13810 if (empty($extImgTarget)) {
13811 $extImgTarget = (preg_match('/\.jpg$/i', $file) ? '.jpg' : '');
13813 if (empty($extImgTarget)) {
13814 $extImgTarget = (preg_match('/\.jpeg$/i', $file) ? '.jpeg' : '');
13816 if (empty($extImgTarget)) {
13817 $extImgTarget = (preg_match('/\.gif$/i', $file) ? '.gif' : '');
13819 if (empty($extImgTarget)) {
13820 $extImgTarget = (preg_match('/\.png$/i', $file) ? '.png' : '');
13822 if (empty($extImgTarget)) {
13823 $extImgTarget = (preg_match('/\.bmp$/i', $file) ? '.bmp' : '');
13825 if (empty($extImgTarget)) {
13826 $extImgTarget = (preg_match('/\.webp$/i', $file) ? '.webp' : '');
13828 if (empty($extImgTarget)) {
13829 $extImgTarget = (preg_match('/\.avif$/i', $file) ? '.avif' : '');
13832 if (!$extImgTarget) {
13838 $subdir = 'thumbs/';
13841 return ($dirName ? $dirName . '/' : '') . $subdir . $fileName . $extName . $extImgTarget; // New filename for thumb
13854function getAdvancedPreviewUrl($modulepart, $relativepath, $alldata = 0, $param = '')
13856 global $conf, $langs;
13858 if (empty($conf->use_javascript_ajax)) {
13862 $isAllowedForPreview = dolIsAllowedForPreview($relativepath);
13864 if ($alldata == 1) {
13865 if ($isAllowedForPreview) {
13866 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));
13872 // old behavior, return a string
13873 if ($isAllowedForPreview) {
13874 $tmpurl = DOL_URL_ROOT . '/document.php?modulepart=' . urlencode($modulepart) . '&attachment=0&file=' . urlencode($relativepath) . ($param ? '&' . $param : '');
13875 $title = $langs->transnoentities("Preview
");
13876 //$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().
13877 //$tmpurl = 'file='.urlencode("'-alert(document.domain)-'_small.jpg
"); // An example of tmpurl that should be blocked by the dol_escape_uri()
13879 // 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,
13880 // 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.
13881 // Using the dol_escape_uri guarantee that we encode for URI so decode retrieve original expected value.
13882 return 'javascript:' . dol_escape_uri('document_preview(\'' . dol_escape_js($tmpurl) . '\', \'' . dol_escape_js(dol_mimetype($relativepath)) . '\', \'' . dol_escape_js($title) . '\')');
13894function getLabelSpecialCode($idcode)
13898 $arrayspecialines = array(1 => 'Transport', 2 => 'EcoTax', 3 => 'Option');
13899 if ($idcode > 10) {
13900 return 'Module ID ' . $idcode;
13902 if (!empty($arrayspecialines[$idcode])) {
13903 return $langs->trans($arrayspecialines[$idcode]);
13917function ajax_autoselect($htmlname, $addlink = '', $textonlink = 'Link')
13920 $out = '<script nonce="
' . getNonce() . '">
13921 jQuery(document).ready(function () {
13922 jQuery("' . ((strpos($htmlname, '.
') === 0 ? '' : '#
') . $htmlname) . '").click(function() { jQuery(this).select(); } );
13926 if ($textonlink === 'image') {
13927 $out .= ' <a href="' . $addlink . '" target="_blank
" rel="noopener noreferrer
">' . img_picto('', 'globe') . '</a>';
13929 $out .= ' <a href="' . $addlink . '" target="_blank
" rel="noopener noreferrer
">' . $langs->trans("Link") . '</a>';
13942function dolIsAllowedForPreview($file)
13944 // Check .noexe extension in filename
13945 if (preg_match('/\.noexe$/i', $file)) {
13949 // Check mime types
13950 $mime_preview = array('avif', 'bmp', 'jpeg', 'png', 'gif', 'tiff', 'pdf', 'plain', 'css', 'webp', 'webm', 'mp4');
13951 if (getDolGlobalString('MAIN_ALLOW_SVG_FILES_AS_IMAGES')) {
13952 $mime_preview[] = 'svg+xml';
13954 //$mime_preview[]='vnd.oasis.opendocument.presentation';
13955 //$mime_preview[]='archive';
13956 $num_mime = array_search(dol_mimetype($file, '', 1), $mime_preview);
13957 if ($num_mime !== false) {
13961 // By default, not allowed for preview
13975function dol_mimetype($file, $default = 'application/octet-stream', $mode = 0)
13978 $imgmime = 'other.png';
13979 $famime = 'file-o';
13982 $tmpfile = preg_replace('/\.noexe$/', '', $file);
13984 // Plain text files
13985 if (preg_match('/\.txt$/i', $tmpfile)) {
13986 $mime = 'text/plain';
13987 $imgmime = 'text.png';
13988 $famime = 'file-alt';
13989 } elseif (preg_match('/\.rtx$/i', $tmpfile)) {
13990 $mime = 'text/richtext';
13991 $imgmime = 'text.png';
13992 $famime = 'file-alt';
13993 } elseif (preg_match('/\.csv$/i', $tmpfile)) {
13994 $mime = 'text/csv';
13995 $imgmime = 'text.png';
13996 $famime = 'file-csv';
13997 } elseif (preg_match('/\.tsv$/i', $tmpfile)) {
13998 $mime = 'text/tab-separated-values';
13999 $imgmime = 'text.png';
14000 $famime = 'file-alt';
14001 } elseif (preg_match('/\.(cf|conf|log)$/i', $tmpfile)) {
14002 $mime = 'text/plain';
14003 $imgmime = 'text.png';
14004 $famime = 'file-alt';
14005 } elseif (preg_match('/\.ini$/i', $tmpfile)) {
14006 $mime = 'text/plain';
14007 $imgmime = 'text.png';
14009 $famime = 'file-alt';
14010 } elseif (preg_match('/\.md$/i', $tmpfile)) {
14011 $mime = 'text/plain';
14012 $imgmime = 'text.png';
14014 $famime = 'file-alt';
14015 } elseif (preg_match('/\.css$/i', $tmpfile)) {
14016 $mime = 'text/css';
14017 $imgmime = 'css.png';
14019 $famime = 'file-alt';
14020 } elseif (preg_match('/\.lang$/i', $tmpfile)) {
14021 $mime = 'text/plain';
14022 $imgmime = 'text.png';
14024 $famime = 'file-alt';
14025 } elseif (preg_match('/\.(crt|cer|key|pub)$/i', $tmpfile)) { // Certificate files
14026 $mime = 'text/plain';
14027 $imgmime = 'text.png';
14028 $famime = 'file-alt';
14029 } elseif (preg_match('/\.(html|htm|shtml)$/i', $tmpfile)) { // XML based (HTML/XML/XAML)
14030 $mime = 'text/html';
14031 $imgmime = 'html.png';
14033 $famime = 'file-alt';
14034 } elseif (preg_match('/\.(xml|xhtml)$/i', $tmpfile)) {
14035 $mime = 'text/xml';
14036 $imgmime = 'other.png';
14038 $famime = 'file-alt';
14039 } elseif (preg_match('/\.xaml$/i', $tmpfile)) {
14040 $mime = 'text/xml';
14041 $imgmime = 'other.png';
14043 $famime = 'file-alt';
14044 } elseif (preg_match('/\.bas$/i', $tmpfile)) { // Languages
14045 $mime = 'text/plain';
14046 $imgmime = 'text.png';
14048 $famime = 'file-code';
14049 } elseif (preg_match('/\.(c)$/i', $tmpfile)) {
14050 $mime = 'text/plain';
14051 $imgmime = 'text.png';
14053 $famime = 'file-code';
14054 } elseif (preg_match('/\.(cpp)$/i', $tmpfile)) {
14055 $mime = 'text/plain';
14056 $imgmime = 'text.png';
14058 $famime = 'file-code';
14059 } elseif (preg_match('/\.cs$/i', $tmpfile)) {
14060 $mime = 'text/plain';
14061 $imgmime = 'text.png';
14063 $famime = 'file-code';
14064 } elseif (preg_match('/\.(h)$/i', $tmpfile)) {
14065 $mime = 'text/plain';
14066 $imgmime = 'text.png';
14068 $famime = 'file-code';
14069 } elseif (preg_match('/\.(java|jsp)$/i', $tmpfile)) {
14070 $mime = 'text/plain';
14071 $imgmime = 'text.png';
14073 $famime = 'file-code';
14074 } elseif (preg_match('/\.php([0-9]{1})?$/i', $tmpfile)) {
14075 $mime = 'text/plain';
14076 $imgmime = 'php.png';
14078 $famime = 'file-code';
14079 } elseif (preg_match('/\.phtml$/i', $tmpfile)) {
14080 $mime = 'text/plain';
14081 $imgmime = 'php.png';
14083 $famime = 'file-code';
14084 } elseif (preg_match('/\.(pl|pm)$/i', $tmpfile)) {
14085 $mime = 'text/plain';
14086 $imgmime = 'pl.png';
14088 $famime = 'file-code';
14089 } elseif (preg_match('/\.sql$/i', $tmpfile)) {
14090 $mime = 'text/plain';
14091 $imgmime = 'text.png';
14093 $famime = 'file-code';
14094 } elseif (preg_match('/\.js$/i', $tmpfile)) {
14095 $mime = 'text/x-javascript';
14096 $imgmime = 'jscript.png';
14098 $famime = 'file-code';
14099 } elseif (preg_match('/\.odp$/i', $tmpfile)) { // Open office
14100 $mime = 'application/vnd.oasis.opendocument.presentation';
14101 $imgmime = 'ooffice.png';
14102 $famime = 'file-powerpoint';
14103 } elseif (preg_match('/\.ods$/i', $tmpfile)) {
14104 $mime = 'application/vnd.oasis.opendocument.spreadsheet';
14105 $imgmime = 'ooffice.png';
14106 $famime = 'file-excel';
14107 } elseif (preg_match('/\.odt$/i', $tmpfile)) {
14108 $mime = 'application/vnd.oasis.opendocument.text';
14109 $imgmime = 'ooffice.png';
14110 $famime = 'file-word';
14111 } elseif (preg_match('/\.mdb$/i', $tmpfile)) { // MS Office
14112 $mime = 'application/msaccess';
14113 $imgmime = 'mdb.png';
14115 } elseif (preg_match('/\.doc[xm]?$/i', $tmpfile)) {
14116 $mime = 'application/msword';
14117 $imgmime = 'doc.png';
14118 $famime = 'file-word';
14119 } elseif (preg_match('/\.dot[xm]?$/i', $tmpfile)) {
14120 $mime = 'application/msword';
14121 $imgmime = 'doc.png';
14122 $famime = 'file-word';
14123 } elseif (preg_match('/\.xlt(x)?$/i', $tmpfile)) {
14124 $mime = 'application/vnd.ms-excel';
14125 $imgmime = 'xls.png';
14126 $famime = 'file-excel';
14127 } elseif (preg_match('/\.xla(m)?$/i', $tmpfile)) {
14128 $mime = 'application/vnd.ms-excel';
14129 $imgmime = 'xls.png';
14130 $famime = 'file-excel';
14131 } elseif (preg_match('/\.xls$/i', $tmpfile)) {
14132 $mime = 'application/vnd.ms-excel';
14133 $imgmime = 'xls.png';
14134 $famime = 'file-excel';
14135 } elseif (preg_match('/\.xls[bmx]$/i', $tmpfile)) {
14136 $mime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
14137 $imgmime = 'xls.png';
14138 $famime = 'file-excel';
14139 } elseif (preg_match('/\.pps[mx]?$/i', $tmpfile)) {
14140 $mime = 'application/vnd.ms-powerpoint';
14141 $imgmime = 'ppt.png';
14142 $famime = 'file-powerpoint';
14143 } elseif (preg_match('/\.ppt[mx]?$/i', $tmpfile)) {
14144 $mime = 'application/x-mspowerpoint';
14145 $imgmime = 'ppt.png';
14146 $famime = 'file-powerpoint';
14147 } elseif (preg_match('/\.pdf$/i', $tmpfile)) { // Other
14148 $mime = 'application/pdf';
14149 $imgmime = 'pdf.png';
14150 $famime = 'file-pdf';
14151 } elseif (preg_match('/\.bat$/i', $tmpfile)) { // Scripts
14152 $mime = 'text/x-bat';
14153 $imgmime = 'script.png';
14155 $famime = 'file-code';
14156 } elseif (preg_match('/\.sh$/i', $tmpfile)) {
14157 $mime = 'text/x-sh';
14158 $imgmime = 'script.png';
14160 $famime = 'file-code';
14161 } elseif (preg_match('/\.ksh$/i', $tmpfile)) {
14162 $mime = 'text/x-ksh';
14163 $imgmime = 'script.png';
14165 $famime = 'file-code';
14166 } elseif (preg_match('/\.bash$/i', $tmpfile)) {
14167 $mime = 'text/x-bash';
14168 $imgmime = 'script.png';
14170 $famime = 'file-code';
14171 } elseif (preg_match('/\.ico$/i', $tmpfile)) { // Images
14172 $mime = 'image/x-icon';
14173 $imgmime = 'image.png';
14174 $famime = 'file-image';
14175 } elseif (preg_match('/\.(jpg|jpeg)$/i', $tmpfile)) {
14176 $mime = 'image/jpeg';
14177 $imgmime = 'image.png';
14178 $famime = 'file-image';
14179 } elseif (preg_match('/\.png$/i', $tmpfile)) {
14180 $mime = 'image/png';
14181 $imgmime = 'image.png';
14182 $famime = 'file-image';
14183 } elseif (preg_match('/\.gif$/i', $tmpfile)) {
14184 $mime = 'image/gif';
14185 $imgmime = 'image.png';
14186 $famime = 'file-image';
14187 } elseif (preg_match('/\.bmp$/i', $tmpfile)) {
14188 $mime = 'image/bmp';
14189 $imgmime = 'image.png';
14190 $famime = 'file-image';
14191 } elseif (preg_match('/\.(tif|tiff)$/i', $tmpfile)) {
14192 $mime = 'image/tiff';
14193 $imgmime = 'image.png';
14194 $famime = 'file-image';
14195 } elseif (preg_match('/\.svg$/i', $tmpfile)) {
14196 $mime = 'image/svg+xml';
14197 $imgmime = 'image.png';
14198 $famime = 'file-image';
14199 } elseif (preg_match('/\.webp$/i', $tmpfile)) {
14200 $mime = 'image/webp';
14201 $imgmime = 'image.png';
14202 $famime = 'file-image';
14203 } elseif (preg_match('/\.vcs$/i', $tmpfile)) { // Calendar
14204 $mime = 'text/calendar';
14205 $imgmime = 'other.png';
14206 $famime = 'file-alt';
14207 } elseif (preg_match('/\.ics$/i', $tmpfile)) {
14208 $mime = 'text/calendar';
14209 $imgmime = 'other.png';
14210 $famime = 'file-alt';
14211 } elseif (preg_match('/\.torrent$/i', $tmpfile)) { // Other
14212 $mime = 'application/x-bittorrent';
14213 $imgmime = 'other.png';
14214 $famime = 'file-o';
14215 } elseif (preg_match('/\.(mp3|ogg|au|wav|wma|mid)$/i', $tmpfile)) { // Audio
14217 $imgmime = 'audio.png';
14218 $famime = 'file-audio';
14219 } elseif (preg_match('/\.mp4$/i', $tmpfile)) { // Video
14220 $mime = 'video/mp4';
14221 $imgmime = 'video.png';
14222 $famime = 'file-video';
14223 } elseif (preg_match('/\.ogv$/i', $tmpfile)) {
14224 $mime = 'video/ogg';
14225 $imgmime = 'video.png';
14226 $famime = 'file-video';
14227 } elseif (preg_match('/\.webm$/i', $tmpfile)) {
14228 $mime = 'video/webm';
14229 $imgmime = 'video.png';
14230 $famime = 'file-video';
14231 } elseif (preg_match('/\.avif$/i', $tmpfile)) {
14232 $mime = 'image/avif';
14233 $imgmime = 'image.png';
14234 $famime = 'file-image';
14235 } elseif (preg_match('/\.avi$/i', $tmpfile)) {
14236 $mime = 'video/x-msvideo';
14237 $imgmime = 'video.png';
14238 $famime = 'file-video';
14239 } elseif (preg_match('/\.divx$/i', $tmpfile)) {
14240 $mime = 'video/divx';
14241 $imgmime = 'video.png';
14242 $famime = 'file-video';
14243 } elseif (preg_match('/\.xvid$/i', $tmpfile)) {
14244 $mime = 'video/xvid';
14245 $imgmime = 'video.png';
14246 $famime = 'file-video';
14247 } elseif (preg_match('/\.(wmv|mpg|mpeg)$/i', $tmpfile)) {
14249 $imgmime = 'video.png';
14250 $famime = 'file-video';
14251 } elseif (preg_match('/\.(zip|rar|gz|tgz|xz|z|cab|bz2|7z|tar|lzh|zst)$/i', $tmpfile)) { // Archive
14252 // application/xxx where zzz is zip, ...
14254 $imgmime = 'archive.png';
14255 $famime = 'file-archive';
14256 } elseif (preg_match('/\.(exe|com)$/i', $tmpfile)) { // Exe
14257 $mime = 'application/octet-stream';
14258 $imgmime = 'other.png';
14259 $famime = 'file-o';
14260 } elseif (preg_match('/\.(dll|lib|o|so|a)$/i', $tmpfile)) { // Lib
14262 $imgmime = 'library.png';
14263 $famime = 'file-o';
14264 } elseif (preg_match('/\.err$/i', $tmpfile)) { // phpcs:ignore
14266 $imgmime = 'error.png';
14267 $famime = 'file-alt';
14270 if ($famime == 'file-o') {
14271 // file-o seems to not work in fontawesome 5
14275 // Return mimetype string
14276 switch ((int) $mode) {
14278 $tmp = explode('/', $mime);
14279 return (!empty($tmp[1]) ? $tmp[1] : $tmp[0]);
14301function getDictionaryValue($tablename, $field, $id, $checkentity = false, $rowidfield = 'rowid')
14305 $tablename = preg_replace('/^' . preg_quote(MAIN_DB_PREFIX, '/') . '/', '', $tablename); // Clean name of table for backward compatibility.
14307 $dictvalues = (isset($conf->cache['dictvalues_' . $tablename]) ? $conf->cache['dictvalues_' . $tablename] : null);
14309 if (is_null($dictvalues)) {
14310 $dictvalues = array();
14312 $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
14313 if ($checkentity) {
14314 $sql .= ' AND entity IN (0,' . getEntity($tablename) . ')';
14317 $resql = $db->query($sql);
14319 while ($obj = $db->fetch_object($resql)) {
14320 $dictvalues[$obj->$rowidfield] = $obj; // $obj is stdClass
14323 dol_print_error($db);
14326 $conf->cache['dictvalues_' . $tablename] = $dictvalues;
14329 if (!empty($dictvalues[$id])) {
14331 $tmp = $dictvalues[$id];
14332 return (property_exists($tmp, $field) ? $tmp->$field : '');
14345function colorIsLight($stringcolor)
14347 $stringcolor = str_replace('#', '', $stringcolor);
14349 if (!empty($stringcolor)) {
14351 $tmp = explode(',', $stringcolor);
14352 if (count($tmp) > 1) { // This is a comma RGB ('255','255','255')
14357 $hexr = $stringcolor[0] . $stringcolor[1];
14358 $hexg = $stringcolor[2] . $stringcolor[3];
14359 $hexb = $stringcolor[4] . $stringcolor[5];
14360 $r = hexdec($hexr);
14361 $g = hexdec($hexg);
14362 $b = hexdec($hexb);
14364 $bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0; // HSL algorithm
14365 if ($bright > 0.6) {
14380function isVisibleToUserType($type_user, &$menuentry, &$listofmodulesforexternal)
14382 //print 'type_user='.$type_user.' module='.$menuentry['module'].' enabled='.$menuentry['enabled'].' perms='.$menuentry['perms'];
14383 //print 'ok='.in_array($menuentry['module'], $listofmodulesforexternal);
14384 if (empty($menuentry['enabled'])) {
14385 return 0; // Entry disabled by condition
14387 if ($type_user && array_key_exists('module', $menuentry) && $menuentry['module']) {
14388 $tmploops = explode('|', $menuentry['module']);
14390 foreach ($tmploops as $tmploop) {
14391 if (in_array($tmploop, $listofmodulesforexternal)) {
14397 return 0; // Entry is for menus all excluded to external users
14400 if (!$menuentry['perms'] && $type_user) {
14401 return 0; // No permissions and user is external
14403 if (!$menuentry['perms'] && getDolGlobalString('MAIN_MENU_HIDE_UNAUTHORIZED')) {
14404 return 0; // No permissions and option to hide when not allowed, even for internal user, is on
14406 if (!$menuentry['perms']) {
14407 return 2; // No permissions and user is external
14419function roundUpToNextMultiple($n, $x = 5)
14421 $result = (ceil($n) % $x === 0) ? ceil($n) : (round(($n + $x / 2) / $x) * $x);
14422 return (int) $result;
14436function dolGetBadge($label, $html = '', $type = 'primary', $mode = '', $url = '', $params = array())
14438 $csstouse = 'badge';
14439 $csstouse .= (!empty($mode) ? ' badge-' . $mode : '');
14440 $csstouse .= (!empty($type) ? ' badge-' . $type : '');
14441 $csstouse .= (empty($params['css']) ? '' : ' ' . $params['css']);
14444 'class' => $csstouse
14447 if (empty($html)) {
14451 if (!empty($url)) {
14452 $attr['href'] = $url;
14455 if ($mode === 'dot') {
14456 $attr['class'] .= ' classfortooltip';
14457 $attr['title'] = $html;
14458 $attr['aria-label'] = $label;
14463 if (!empty($params['attr']) && is_array($params['attr'])) {
14464 foreach ($params['attr'] as $key => $value) {
14465 if ($key == 'class') {
14466 $attr['class'] .= ' ' . $value;
14467 } elseif ($key == 'classOverride') {
14468 $attr['class'] = $value;
14470 $attr[$key] = $value;
14477 // escape all attribute
14478 $attr = array_map('dolPrintHTMLForAttribute', $attr);
14480 $TCompiledAttr = array();
14481 foreach ($attr as $key => $value) {
14482 $TCompiledAttr[] = $key . '="
' . $value . '"';
14485 $compiledAttributes = !empty($TCompiledAttr) ? implode(' ', $TCompiledAttr) : '';
14487 $tag = !empty($url) ? 'a' : 'span';
14489 return '<' . $tag . ' ' . $compiledAttributes . '>' . $html . '</' . $tag . '>';
14505function dolGetStatus($statusLabel = '', $statusLabelShort = '', $html = '', $statusType = 'status0', $displayMode = 0, $url = '', $params = array())
14510 $dolGetBadgeParams = array();
14512 if (!empty($params['badgeParams'])) {
14513 $dolGetBadgeParams = $params['badgeParams'];
14516 // TODO : add a hook
14517 if ($displayMode == 0) {
14518 $return = !empty($html) ? $html : (empty($conf->dol_optimize_smallscreen) ? $statusLabel : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort));
14519 } elseif ($displayMode == 1) {
14520 $return = !empty($html) ? $html : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort);
14521 } elseif (getDolGlobalString('MAIN_STATUS_USES_IMAGES')) {
14522 // Use status with images (for backward compatibility)
14524 $htmlLabel = (in_array($displayMode, array(1, 2, 5)) ? '<span class="hideonsmartphone
">' : '') . (!empty($html) ? $html : $statusLabel) . (in_array($displayMode, array(1, 2, 5)) ? '</span>' : '');
14525 $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>' : '');
14527 // For small screen, we always use the short label instead of long label.
14528 if (!empty($conf->dol_optimize_smallscreen)) {
14529 if ($displayMode == 0) {
14531 } elseif ($displayMode == 4) {
14533 } elseif ($displayMode == 6) {
14538 // For backward compatibility. Image's filename are still in French, so we use this array to convert
14539 $statusImg = array(
14540 'status0' => 'statut0',
14541 'status1' => 'statut1',
14542 'status2' => 'statut2',
14543 'status3' => 'statut3',
14544 'status4' => 'statut4',
14545 'status5' => 'statut5',
14546 'status6' => 'statut6',
14547 'status7' => 'statut7',
14548 'status8' => 'statut8',
14549 'status9' => 'statut9'
14552 if (!empty($statusImg[$statusType])) {
14553 $htmlImg = img_picto($statusLabel, $statusImg[$statusType]);
14555 $htmlImg = img_picto($statusLabel, $statusType);
14558 if ($displayMode === 2) {
14559 $return = $htmlImg . ' ' . $htmlLabelShort;
14560 } elseif ($displayMode === 3) {
14561 $return = $htmlImg;
14562 } elseif ($displayMode === 4) {
14563 $return = $htmlImg . ' ' . $htmlLabel;
14564 } elseif ($displayMode === 5) {
14565 $return = $htmlLabelShort . ' ' . $htmlImg;
14566 } else { // $displayMode >= 6
14567 $return = $htmlLabel . ' ' . $htmlImg;
14569 } elseif (!getDolGlobalString('MAIN_STATUS_USES_IMAGES') && !empty($displayMode)) {
14571 $statusLabelShort = (empty($statusLabelShort) ? $statusLabel : $statusLabelShort);
14573 $dolGetBadgeParams['attr']['class'] = 'badge-status';
14574 if (empty($dolGetBadgeParams['attr']['title'])) {
14575 $dolGetBadgeParams['attr']['title'] = empty($params['tooltip']) ? $statusLabel : ($params['tooltip'] != 'no' ? $params['tooltip'] : '');
14576 } else { // If a title was forced from $params['badgeParams']['attr']['title'], we set the class to get it as a tooltip.
14577 $dolGetBadgeParams['attr']['class'] .= ' classfortooltip';
14578 // And if we use tooltip, we can output title in HTML @phan-suppress-next-line PhanTypeInvalidDimOffset
14579 $dolGetBadgeParams['attr']['title'] = dol_htmlentitiesbr((string) $dolGetBadgeParams['attr']['title'], 1);
14582 if ($displayMode == 3) {
14583 $return = dolGetBadge((empty($conf->dol_optimize_smallscreen) ? $statusLabel : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort)), '', $statusType, 'dot', $url, $dolGetBadgeParams);
14584 } elseif ($displayMode === 5) {
14585 $return = dolGetBadge($statusLabelShort, $html, $statusType, '', $url, $dolGetBadgeParams);
14587 $return = dolGetBadge(((empty($conf->dol_optimize_smallscreen) && $displayMode != 2) ? $statusLabel : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort)), $html, $statusType, '', $url, $dolGetBadgeParams);
14630function dolGetButtonAction($label, $text = '', $actionType = 'default', $url = '', $id = '', $userRight = 1, $params = array())
14632 global $hookmanager, $action, $object, $langs;
14634 // If $url is an array, we must build a dropdown button or recursively iterate over each value
14635 if (is_array($url)) {
14636 // Loop on $url array to remove entries of disabled modules
14637 foreach ($url as $key => $subbutton) {
14638 if (isset($subbutton['enabled']) && empty($subbutton['enabled'])) {
14645 if (array_key_exists('areDropdownButtons', $params) && $params["areDropdownButtons
"] === false) { // @phan-suppress-current-line PhanTypeInvalidDimOffset
14646 foreach ($url as $button) {
14647 if (!empty($button['lang'])) {
14648 $langs->load($button['lang']);
14650 $label = $langs->trans($button['label']);
14651 $text = $button['text'] ?? '';
14652 $actionType = $button['actionType'] ?? '';
14653 $tmpUrl = DOL_URL_ROOT . $button['url'] . (empty($params['backtopage']) ? '' : '&backtopage=' . urlencode($params['backtopage']));
14654 $id = $button['id'] ?? '';
14655 $userRight = $button['perm'] ?? 1;
14656 $button['params'] = $button['params'] ?? []; // @phan-suppress-current-line PhanPluginDuplicateExpressionAssignmentOperation
14658 $out .= dolGetButtonAction($label, $text, $actionType, $tmpUrl, $id, $userRight, $button['params']);
14663 if (count($url) > 1) {
14664 $out .= '<div class="dropdown
inline-block dropdown-holder
">';
14665 $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>';
14666 $out .= '<div class="dropdown-content
">';
14667 foreach ($url as $subbutton) {
14668 if (!empty($subbutton['lang'])) {
14669 $langs->load($subbutton['lang']);
14672 if (!empty($subbutton['urlraw'])) {
14673 $tmpurl = $subbutton['urlraw']; // Use raw url, no url completion, use only what developer send
14675 $tmpurl = !empty($subbutton['urlroot']) ? $subbutton['urlroot'] : $subbutton['url'];
14676 $tmpurl = dolCompletUrlForDropdownButton($tmpurl, $params, empty($subbutton['urlroot']));
14679 $subbuttonparam = array();
14680 if (!empty($subbutton['attr'])) {
14681 $subbuttonparam['attr'] = $subbutton['attr'];
14683 $subbuttonparam['isDropDown'] = (empty($params['isDropDown']) ? ($subbutton['isDropDown'] ?? false) : $params['isDropDown']);
14685 $out .= dolGetButtonAction('', $langs->trans($subbutton['label']), 'default', $tmpurl, $subbutton['id'] ?? '', $subbutton['perm'], $subbuttonparam);
14690 foreach ($url as $subbutton) { // Should loop on 1 record only
14691 if (!empty($subbutton['lang'])) {
14692 $langs->load($subbutton['lang']);
14695 if (!empty($subbutton['urlraw'])) {
14696 $tmpurl = $subbutton['urlraw']; // Use raw url, no url completion, use only what developer send
14698 $tmpurl = !empty($subbutton['urlroot']) ? $subbutton['urlroot'] : $subbutton['url'];
14699 $tmpurl = dolCompletUrlForDropdownButton($tmpurl, $params, empty($subbutton['urlroot']));
14702 $label = $langs->trans($subbutton['label']);
14703 $text = $subbutton['text'] ?? '';
14704 if (empty($text)) {
14709 $out .= dolGetButtonAction($label, $text, 'default', $tmpurl, '', $subbutton['perm'], $params);
14716 // Here, $url is a simple link
14717 if (!empty($params['isDropdown']) || !empty($params['isDropDown'])) { // Use the dropdown-item style (not for action button)
14718 $class = "dropdown-item
";
14720 $class = 'butAction';
14721 if ($actionType == 'edit') {
14722 $class = 'butAction butActionEdit';
14723 } elseif ($actionType == 'email') {
14724 $class = 'butAction butActionEmail';
14725 } elseif ($actionType == 'clone') {
14726 $class = 'butAction butActionClone';
14727 } elseif ($actionType == 'cancel') {
14728 $class = 'butAction butActionDelete';
14729 } elseif ($actionType == 'danger' || $actionType == 'delete') {
14730 $class = 'butAction butActionDelete';
14731 if (!empty($url) && strpos($url, 'token=') === false) {
14732 $url .= '&token=' . newToken();
14738 'href' => empty($url) ? '' : $url,
14742 if (empty($text)) {
14744 $attr['title'] = ''; // if html not set, using label on title is redundant
14746 $attr['title'] = $label;
14747 $attr['aria-label'] = $label;
14750 if (empty($userRight) || $userRight < 0) {
14751 $attr['class'] = 'butActionRefused';
14752 $attr['href'] = '';
14753 $attr['title'] = (($label && $text && $label != $text) ? $label : '');
14754 $attr['title'] = ($attr['title'] ? $attr['title'] . (empty($userRight) ? '<br>' : '') : '');
14755 $attr['title'] .= ((empty($userRight) && empty($label)) ? $langs->trans('NotEnoughPermissions') : '');
14763 if (!empty($params['attr']) && is_array($params['attr'])) {
14764 foreach ($params['attr'] as $key => $value) {
14765 if ($key == 'class') {
14766 $attr['class'] .= ' ' . $value;
14767 } elseif ($key == 'classOverride') {
14768 $attr['class'] = $value;
14770 $attr[$key] = $value;
14775 // automatic add tooltip when title is detected
14776 if (!empty($attr['title']) && !empty($attr['class']) && strpos($attr['class'], 'classfortooltip') === false) {
14777 $attr['class'] .= ' classfortooltip';
14780 // Js Confirm button
14781 if ($userRight && !empty($params['confirm'])) {
14782 if (!is_array($params['confirm'])) {
14783 $params['confirm'] = array();
14786 if (empty($params['confirm']['url'])) {
14787 $params['confirm']['url'] = $url . (strpos($url, '?') > 0 ? '&' : '?') . 'confirm=yes';
14790 // for js disabled compatibility set $url as call to confirm action and $params['confirm']['url'] to confirmed action
14791 $attr['data-confirm-url'] = $params['confirm']['url'];
14792 $attr['data-confirm-title'] = !empty($params['confirm']['title']) ? $params['confirm']['title'] : $langs->trans('ConfirmBtnCommonTitle', $label);
14793 $attr['data-confirm-content'] = !empty($params['confirm']['content']) ? $params['confirm']['content'] : $langs->trans('ConfirmBtnCommonContent', $label);
14794 $attr['data-confirm-content'] = preg_replace("/\r|\n/
", "", $attr['data-confirm-content']);
14795 $attr['data-confirm-action-btn-label'] = !empty($params['confirm']['action-btn-label']) ? $params['confirm']['action-btn-label'] : $langs->trans('Confirm');
14796 $attr['data-confirm-cancel-btn-label'] = !empty($params['confirm']['cancel-btn-label']) ? $params['confirm']['cancel-btn-label'] : $langs->trans('CloseDialog');
14797 $attr['data-confirm-modal'] = !empty($params['confirm']['modal']) ? $params['confirm']['modal'] : true;
14799 $attr['class'] .= ' butActionConfirm';
14802 if (isset($attr['href']) && empty($attr['href'])) {
14803 unset($attr['href']);
14806 // TODO replace $TCompiledAttr generation by commonHtmlAttributeBuilder given below
14807 $TCompiledAttr = array();
14808 foreach ($attr as $key => $value) {
14809 if (!empty($params['use_unsecured_unescapedattr']) && is_array($params['use_unsecured_unescapedattr']) && in_array($key, $params['use_unsecured_unescapedattr'])) {
14811 $value = dol_htmlentities($value, ENT_QUOTES | ENT_SUBSTITUTE);
14812 } elseif ($key == 'href') {
14813 $value = dolPrintHTMLForAttributeUrl($value);
14815 $value = dolPrintHTMLForAttribute($value);
14818 $TCompiledAttr[] = $key . '="' . $value . '"'; // $value has been escaped by the dolPrintHTMLForAttribute... just before
14820 // TODO replace $TCompiledAttr generation by uncomment line below and remove old code
14821 // $TCompiledAttr = commonHtmlAttributeBuilder($attr,$params['use_unsecured_unescapedattr'] ?? []);
14822 $compiledAttributes = empty($TCompiledAttr) ? '' : implode(' ', $TCompiledAttr);
14824 $tag = !empty($attr['href']) ? 'a' : 'span';
14826 $parameters = array(
14827 'TCompiledAttr' => $TCompiledAttr, // array
14828 'compiledAttributes' => $compiledAttributes, // string
14833 'actionType' => $actionType,
14836 'userRight' => $userRight,
14837 'params' => $params
14840 $reshook = $hookmanager->executeHooks('dolGetButtonAction', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
14841 if ($reshook < 0) {
14842 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
14845 if (empty($reshook)) {
14846 if (dol_textishtml($text)) { // If content already HTML encoded
14847 return '<' . $tag . ' ' . $compiledAttributes . '><span class="textbutton
">' . $text . '</span></' . $tag . '>';
14849 return '<' . $tag . ' ' . $compiledAttributes . '><span class="textbutton
">' . dol_escape_htmltag($text) . '</span></' . $tag . '>';
14852 return $hookmanager->resPrint;
14891function commonHtmlAttributeBuilder($attr, array $unescapedAttr = [])
14893 $TCompiledAttr = array();
14894 if (empty($attr)) {
14898 foreach ($attr as $key => $value) {
14899 // special boolean attributes case
14900 if (in_array($key, getListOfHtmlBooleanAttributes())) {
14902 $TCompiledAttr[$key] = $key;
14907 if (!empty($unescapedAttr) && in_array($key, $unescapedAttr)) {
14909 $value = dol_htmlentities((string) $value, ENT_QUOTES | ENT_SUBSTITUTE);
14910 } elseif ($key == 'href') {
14911 $value = dolPrintHTMLForAttributeUrl((string) $value);
14913 $value = dolPrintHTMLForAttribute((string) $value);
14916 $TCompiledAttr[$key] = $key . '="
' . $value . '"'; // $value has been escaped by the dolPrintHTMLForAttribute... just before
14919 return $TCompiledAttr;
14936function getListOfHtmlBooleanAttributes(): array
14985function dolCompletUrlForDropdownButton(string $url, array $params, bool $addDolUrlRoot = true)
14991 $parsedUrl = parse_url($url);
14992 if ((isset($parsedUrl['scheme']) && in_array($parsedUrl['scheme'], ['javascript', 'mailto', 'tel'])) || strpos($url, '#') === 0) {
14996 if (!empty($parsedUrl['query'])) {
14997 // Use parse_str() function to parse the string passed via URL
14998 parse_str($parsedUrl['query'], $urlQuery);
14999 if (!isset($urlQuery['backtopage']) && isset($params['backtopage'])) {
15000 $url .= '&backtopage=' . urlencode($params['backtopage']);
15004 if (!isset($parsedUrl['scheme']) && $addDolUrlRoot) {
15005 $url = DOL_URL_ROOT . $url;
15018function dolGetButtonTitleSeparator($moreClass = "
")
15020 return '<span class="button-title-separator
' . $moreClass . '" ></span>';
15029function getFieldErrorIcon($fieldValidationErrorMsg)
15032 if (!empty($fieldValidationErrorMsg)) {
15033 $out .= '<span class="field-error-icon classfortooltip
" title="' . dol_escape_htmltag($fieldValidationErrorMsg, 1) . '" role="alert
" >'; // role alert is used for accessibility
15034 $out .= '<span class="fa fa-exclamation-circle
" aria-hidden="true" ></span>'; // For accessibility icon is separated and aria-hidden
15053function dolGetButtonTitle($label, $helpText = '', $iconClass = 'fa fa-file', $url = '', $id = '', $status = 1, $params = array())
15055 global $langs, $user;
15057 // Actually this conf is used in css too for external module compatibility and smooth transition to this function
15058 if (getDolGlobalString('MAIN_BUTTON_HIDE_UNAUTHORIZED') && (!$user->admin) && $status <= 0) {
15061 // Fix old picto fa-th-list to use fa-grid-vertical instead
15062 if ($iconClass == 'fa fa-th-list imgforviewmode') {
15063 $iconClass = ' fa fa-grip-horizontal imgforviewmode';
15066 $class = 'btnTitle';
15067 if (in_array($iconClass, array('fa fa-plus-circle', 'fa fa-plus-circle size15x', 'fa fa-comment-dots', 'fa fa-paper-plane'))) {
15068 $class .= ' btnTitlePlus';
15070 $useclassfortooltip = 1;
15072 if (!empty($params['morecss'])) {
15073 $class .= ' ' . $params['morecss'];
15078 'href' => empty($url) ? '' : $url
15081 if (!empty($helpText)) {
15082 $attr['title'] = $helpText;
15083 } elseif ($label) { // empty($attr['title']) &&
15084 $attr['title'] = $label;
15085 $useclassfortooltip = 0;
15088 if ($status == 2) {
15089 $attr['class'] .= ' btnTitleSelected';
15090 } elseif ($status <= 0) {
15091 $attr['class'] .= ' refused';
15093 $attr['href'] = '';
15095 if ($status == -1) { // disable
15096 $attr['title'] = $langs->transnoentitiesnoconv("FeatureDisabled
");
15097 } elseif ($status == 0) { // Not enough permissions
15098 $attr['title'] = $langs->transnoentitiesnoconv("NotEnoughPermissions
");
15102 if (!empty($attr['title']) && $useclassfortooltip) {
15103 $attr['class'] .= ' classfortooltip';
15111 if (!empty($params['attr']) && is_array($params['attr'])) {
15112 foreach ($params['attr'] as $key => $value) {
15113 if ($key == 'class') {
15114 $attr['class'] .= ' ' . $value;
15115 } elseif ($key == 'classOverride') {
15116 $attr['class'] = $value;
15118 $attr[$key] = $value;
15123 if (isset($attr['href']) && empty($attr['href'])) {
15124 unset($attr['href']);
15127 // TODO : add a hook
15129 // Generate attributes with escapement
15130 $TCompiledAttr = array();
15131 foreach ($attr as $key => $value) {
15132 $TCompiledAttr[] = $key . '="' . dol_escape_htmltag($value) . '"'; // Do not use dolPrintHTMLForAttribute() here, we must accept "javascript:
string"
15135 $compiledAttributes = (empty($TCompiledAttr) ? '' : implode(' ', $TCompiledAttr));
15137 $tag = (empty($attr['href']) ? 'span' : 'a');
15139 $button = '<' . $tag . ' ' . $compiledAttributes . '>';
15140 $button .= '<span class="' . $iconClass . ' valignmiddle btnTitle-icon
"></span>';
15141 if (!empty($params['forcenohideoftext'])) {
15142 $button .= '<span class="valignmiddle text-plus-circle btnTitle-label
' . (empty($params['forcenohideoftext
']) ? ' hideonsmartphone
' : '') . '">' . $label . '</span>';
15144 $button .= '</' . $tag . '>';
15158function getElementProperties($elementType)
15160 global $conf, $db, $hookmanager;
15164 //$element_type='facture';
15166 $classfile = $classname = $classpath = $subdir = $dir_output = $dir_temp = $parent_element = '';
15168 // Parse element/subelement
15169 $module = $elementType;
15170 $element = $elementType;
15171 $subelement = $elementType;
15172 $table_element = $elementType;
15174 // If we ask a resource form external module (instead of default path)
15175 if (preg_match('/^([^@]+)@([^@]+)$/i', $elementType, $regs)) { // 'myobject@mymodule'
15176 $element = $subelement = $regs[1];
15177 $module = $regs[2];
15180 // If we ask a resource for a string with an element and a subelement
15181 // Example 'project_task'
15182 if (preg_match('/^([^_]+)_([^_]+)/i', $element, $regs)) { // 'myobject_mysubobject' with myobject=mymodule
15183 $module = $element = $regs[1];
15184 $subelement = $regs[2];
15187 // Object lines will use parent classpath and module ref
15188 if (substr($elementType, -3) == 'det') {
15189 $module = preg_replace('/det$/', '', $element);
15190 $subelement = preg_replace('/det$/', '', $subelement);
15191 $classpath = $module . '/class';
15192 $classfile = $module;
15193 $classname = preg_replace('/det$/', 'Line', $element);
15194 if (in_array($module, array('expedition', 'propale', 'facture', 'contrat', 'fichinter', 'supplier_order', 'commandefournisseur'))) {
15195 $classname = preg_replace('/det$/', 'Ligne', $element);
15198 // For compatibility and to work with non standard path
15199 if ($elementType == "action
" || $elementType == "actioncomm
") {
15200 $classpath = 'comm/action/class';
15201 $subelement = 'Actioncomm';
15202 $module = 'agenda';
15203 $table_element = 'actioncomm';
15204 } elseif ($elementType == 'cronjob') {
15205 $classpath = 'cron/class';
15207 $table_element = 'cron';
15208 } elseif ($elementType == 'adherent_type') {
15209 $classpath = 'adherents/class';
15210 $classfile = 'adherent_type';
15211 $module = 'adherent';
15212 $subelement = 'adherent_type';
15213 $classname = 'AdherentType';
15214 $table_element = 'adherent_type';
15215 } elseif ($elementType == 'bank_account') {
15216 $classpath = 'compta/bank/class';
15217 $module = 'bank'; // We need $conf->bank->dir_output and not $conf->banque->dir_output
15218 $classfile = 'account';
15219 $classname = 'Account';
15220 } elseif ($elementType == 'bank_line') {
15221 $classpath = 'compta/bank/class';
15222 $module = 'bank'; // We need $conf->bank->dir_output and not $conf->banque->dir_output
15223 $classfile = 'account';
15224 $classname = 'AccountLine';
15225 } elseif ($elementType == 'category') {
15226 $classpath = 'categories/class';
15227 $module = 'categorie';
15228 $subelement = 'categorie';
15229 $table_element = 'categorie';
15230 } elseif ($elementType == 'contact') {
15231 $classpath = 'contact/class';
15232 $classfile = 'contact';
15233 $module = 'societe';
15234 $subelement = 'contact';
15235 $table_element = 'socpeople';
15236 } elseif ($elementType == 'inventory') {
15237 $module = 'product';
15238 $classpath = 'product/inventory/class';
15239 } elseif ($elementType == 'inventoryline') {
15240 $module = 'product';
15241 $classpath = 'product/inventory/class';
15242 $table_element = 'inventorydet';
15243 $parent_element = 'inventory';
15244 } elseif ($elementType == 'stock' || $elementType == 'entrepot' || $elementType == 'warehouse') {
15246 $classpath = 'product/stock/class';
15247 $classfile = 'entrepot';
15248 $classname = 'Entrepot';
15249 $table_element = 'entrepot';
15250 } elseif ($elementType == 'project') {
15251 $classpath = 'projet/class';
15252 $module = 'projet';
15253 $table_element = 'projet';
15254 } elseif ($elementType == 'project_task') {
15255 $classpath = 'projet/class';
15256 $module = 'projet';
15257 $subelement = 'task';
15258 $table_element = 'projet_task';
15259 } elseif ($elementType == 'mo') {
15260 $classpath = 'mrp/class';
15264 $table_element = 'mrp_mo';
15265 } elseif ($elementType == 'facture' || $elementType == 'invoice') {
15266 $classpath = 'compta/facture/class';
15267 $module = 'facture';
15268 $subelement = 'facture';
15269 $table_element = 'facture';
15270 } elseif ($elementType == 'facturedet') {
15271 $classpath = 'compta/facture/class';
15272 $classfile = 'facture';
15273 $classname = 'FactureLigne';
15274 $module = 'facture';
15275 $table_element = 'facturedet';
15276 $parent_element = 'facture';
15277 } elseif ($elementType == 'facturerec' || $elementType == 'facture_rec') {
15278 $classpath = 'compta/facture/class';
15279 $classfile = 'facture-rec';
15280 $module = 'facture';
15281 $classname = 'FactureRec';
15282 } elseif ($elementType == 'commande' || $elementType == 'order') {
15283 $classpath = 'commande/class';
15284 $module = 'commande';
15285 $subelement = 'commande';
15286 $table_element = 'commande';
15287 } elseif ($elementType == 'commandedet') {
15288 $classpath = 'commande/class';
15289 $classfile = 'commande';
15290 $classname = 'OrderLine';
15291 $module = 'commande';
15292 $table_element = 'commandedet';
15293 $parent_element = 'commande';
15294 } elseif ($elementType == 'propal') {
15295 $classpath = 'comm/propal/class';
15296 $table_element = 'propal';
15297 } elseif ($elementType == 'propaldet') {
15298 $classpath = 'comm/propal/class';
15299 $classfile = 'propal';
15300 $subelement = 'propaleligne';
15301 $module = 'propal';
15302 $table_element = 'propaldet';
15303 $parent_element = 'propal';
15304 } elseif ($elementType == 'shipping') {
15305 $classpath = 'expedition/class';
15306 $classfile = 'expedition';
15307 $classname = 'Expedition';
15308 $module = 'expedition';
15309 $table_element = 'expedition';
15310 } elseif ($elementType == 'expeditiondet' || $elementType == 'shippingdet') {
15311 $classpath = 'expedition/class';
15312 $classfile = 'expedition';
15313 $classname = 'ExpeditionLigne';
15314 $module = 'expedition';
15315 $table_element = 'expeditiondet';
15316 $parent_element = 'expedition';
15317 } elseif ($elementType == 'delivery_note') {
15318 $classpath = 'delivery/class';
15319 $subelement = 'delivery';
15320 $module = 'expedition';
15321 } elseif ($elementType == 'delivery') {
15322 $classpath = 'delivery/class';
15323 $subelement = 'delivery';
15324 $module = 'expedition';
15325 } elseif ($elementType == 'deliverydet') {
15327 } elseif ($elementType == 'supplier_proposal') {
15328 $classpath = 'supplier_proposal/class';
15329 $module = 'supplier_proposal';
15330 $element = 'supplierproposal';
15331 $classfile = 'supplier_proposal';
15332 $subelement = 'supplierproposal';
15333 } elseif ($elementType == 'supplier_proposaldet') {
15334 $classpath = 'supplier_proposal/class';
15335 $module = 'supplier_proposal';
15336 $classfile = 'supplier_proposal';
15337 $classname = 'SupplierProposalLine';
15338 $table_element = 'supplier_proposaldet';
15339 $parent_element = 'supplier_proposal';
15340 } elseif ($elementType == 'contract') {
15341 $classpath = 'contrat/class';
15342 $module = 'contrat';
15343 $subelement = 'contrat';
15344 $table_element = 'contract';
15345 } elseif ($elementType == 'contratdet') {
15346 $classpath = 'contrat/class';
15347 $module = 'contrat';
15348 $table_element = 'contratdet';
15349 $parent_element = 'contrat';
15350 } elseif ($elementType == 'mailing') {
15351 $classpath = 'comm/mailing/class';
15352 $module = 'mailing';
15353 $classfile = 'mailing';
15354 $classname = 'Mailing';
15356 } elseif ($elementType == 'member' || $elementType == 'adherent') {
15357 $classpath = 'adherents/class';
15358 $module = 'adherent';
15359 $subelement = 'adherent';
15360 $table_element = 'adherent';
15361 } elseif ($elementType == 'subscription') {
15362 $classpath = 'adherents/class';
15363 $classfile = 'subscription';
15364 $module = 'adherent';
15365 $subelement = 'subscription';
15366 $classname = 'Subscription';
15367 $table_element = 'subscription';
15368 } elseif ($elementType == 'usergroup') {
15369 $classpath = 'user/class';
15371 } elseif ($elementType == 'mo' || $elementType == 'mrp') {
15372 $classpath = 'mrp/class';
15377 $table_element = 'mrp_mo';
15378 } elseif ($elementType == 'mrp_production') {
15379 $classpath = 'mrp/class';
15381 $classname = 'MoLine';
15384 $table_element = 'mrp_production';
15385 $parent_element = 'mo';
15386 } elseif ($elementType == 'cabinetmed_cons') {
15387 $classpath = 'cabinetmed/class';
15388 $module = 'cabinetmed';
15389 $subelement = 'cabinetmedcons';
15390 $table_element = 'cabinetmedcons';
15391 } elseif ($elementType == 'fichinter') {
15392 $classpath = 'fichinter/class';
15393 $module = 'ficheinter';
15394 $subelement = 'fichinter';
15395 $table_element = 'fichinter';
15396 } elseif ($elementType == 'dolresource' || $elementType == 'resource') {
15397 $classpath = 'resource/class';
15398 $module = 'resource';
15399 $subelement = 'dolresource';
15400 $table_element = 'resource';
15401 } elseif ($elementType == 'opensurvey_sondage') {
15402 $classpath = 'opensurvey/class';
15403 $module = 'opensurvey';
15404 $subelement = 'opensurveysondage';
15405 } elseif ($elementType == 'order_supplier' || $elementType == 'supplier_order' || $elementType == 'commande_fournisseur' || $elementType == 'commandefournisseur') {
15406 $classpath = 'fourn/class';
15407 $module = 'fournisseur';
15408 $classfile = 'fournisseur.commande';
15409 $element = 'order_supplier';
15411 $classname = 'CommandeFournisseur';
15412 $table_element = 'commande_fournisseur';
15413 } elseif ($elementType == 'commande_fournisseurdet') {
15414 $classpath = 'fourn/class';
15415 $module = 'fournisseur';
15416 $classfile = 'fournisseur.commande';
15417 $element = 'commande_fournisseurdet';
15419 $classname = 'CommandeFournisseurLigne';
15420 $table_element = 'commande_fournisseurdet';
15421 $parent_element = 'commande_fournisseur';
15422 } elseif ($elementType == 'invoice_supplier' || $elementType == 'supplier_invoice' || $elementType == 'facture_fourn') {
15423 $classpath = 'fourn/class';
15424 $module = 'fournisseur';
15425 $classfile = 'fournisseur.facture';
15426 $element = 'invoice_supplier';
15428 $classname = 'FactureFournisseur';
15429 $table_element = 'facture_fourn';
15430 } elseif ($elementType == 'facture_fourn_det') {
15431 $classpath = 'fourn/class';
15432 $module = 'fournisseur';
15433 $classfile = 'fournisseur.facture';
15434 $element = 'facture_fourn_det';
15436 $classname = 'SupplierInvoiceLine';
15437 $table_element = 'facture_fourn_det';
15438 $parent_element = 'invoice_supplier';
15439 } elseif ($elementType == "service
") {
15440 $classpath = 'product/class';
15441 $subelement = 'product';
15442 $table_element = 'product';
15443 } elseif ($elementType == 'salary') {
15444 $classpath = 'salaries/class';
15445 $module = 'salaries';
15446 } elseif ($elementType == 'payment_salary') {
15447 $classpath = 'salaries/class';
15448 $classfile = 'paymentsalary';
15449 $classname = 'PaymentSalary';
15450 $module = 'salaries';
15451 } elseif ($elementType == 'productlot') {
15452 $module = 'productbatch';
15453 $classpath = 'product/stock/class';
15454 $classfile = 'productlot';
15455 $classname = 'Productlot';
15456 $element = 'productlot';
15458 $table_element = 'product_lot';
15459 } elseif ($elementType == 'societeaccount') {
15460 $classpath = 'societe/class';
15461 $classfile = 'societeaccount';
15462 $classname = 'SocieteAccount';
15463 $module = 'societe';
15464 } elseif ($elementType == 'websitepage' || $elementType == 'website_page') {
15465 $classpath = 'website/class';
15466 $classfile = 'websitepage';
15467 $classname = 'Websitepage';
15468 $module = 'website';
15469 $subelement = 'websitepage';
15470 $table_element = 'website_page';
15471 } elseif ($elementType == 'fiscalyear') {
15472 $classpath = 'core/class';
15473 $module = 'accounting';
15474 $subelement = 'fiscalyear';
15475 } elseif ($elementType == 'chargesociales') {
15476 $classpath = 'compta/sociales/class';
15478 $table_element = 'chargesociales';
15479 } elseif ($elementType == 'tva') {
15480 $classpath = 'compta/tva/class';
15483 $table_element = 'tva';
15484 } elseif ($elementType == 'emailsenderprofile') {
15486 $classpath = 'core/class';
15487 $classfile = 'emailsenderprofile';
15488 $classname = 'EmailSenderProfile';
15489 $table_element = 'c_email_senderprofile';
15491 } elseif ($elementType == 'conferenceorboothattendee') {
15492 $classpath = 'eventorganization/class';
15493 $classfile = 'conferenceorboothattendee';
15494 $classname = 'ConferenceOrBoothAttendee';
15495 $module = 'eventorganization';
15496 } elseif ($elementType == 'conferenceorbooth') {
15497 $classpath = 'eventorganization/class';
15498 $classfile = 'conferenceorbooth';
15499 $classname = 'ConferenceOrBooth';
15500 $module = 'eventorganization';
15501 } elseif ($elementType == 'ccountry') {
15503 $classpath = 'core/class';
15504 $classfile = 'ccountry';
15505 $classname = 'Ccountry';
15506 $table_element = 'c_country';
15508 } elseif ($elementType == 'ecmfiles') {
15510 $classpath = 'ecm/class';
15511 $classfile = 'ecmfiles';
15512 $classname = 'Ecmfiles';
15513 $table_element = 'ecmfiles';
15515 } elseif ($elementType == 'knowledgerecord' || $elementType == 'knowledgemanagement') {
15516 $module = 'knowledgemanagement';
15517 $classpath = 'knowledgemanagement/class';
15518 $classfile = 'knowledgerecord';
15519 $classname = 'KnowledgeRecord';
15520 $table_element = 'knowledgemanagement_knowledgerecord';
15522 } elseif ($elementType == 'customer') {
15523 $module = 'societe';
15524 $classpath = 'societe/class';
15525 $classfile = 'client';
15526 $classname = 'Client';
15527 $table_element = 'societe';
15529 } elseif ($elementType == 'fournisseur' || $elementType == 'supplier') {
15530 $module = 'societe';
15531 $classpath = 'fourn/class';
15532 $classfile = 'fournisseur';
15533 $classname = 'Fournisseur';
15534 $table_element = 'societe';
15536 } elseif ($elementType == 'recruitmentcandidature') {
15537 $module = 'recruitment';
15538 $classfile = 'recruitmentcandidature';
15539 $classpath = 'recruitment/class';
15540 $classname = 'RecruitmentCandidature';
15541 $subelement = 'recruitmentcandidature';
15542 $subdir = '/recruitmentcandidature';
15543 } elseif ($elementType == 'recruitmentjobposition') {
15544 $module = 'recruitment';
15545 $classfile = 'recruitmentjobposition';
15546 $classpath = 'recruitment/class';
15547 $classname = 'RecruitmentJobPosition';
15548 $subelement = 'recruitmentjobposition';
15549 $subdir = '/recruitmentjobposition';
15553 if (empty($classfile)) {
15554 $classfile = strtolower($subelement);
15556 if (empty($classname)) {
15557 $classname = ucfirst($subelement);
15559 if (empty($classpath)) {
15560 $classpath = $module . '/class';
15563 //print 'getElementProperties subdir='.$subdir;
15566 if ($module && isset($conf->$module)) { // The generic case
15567 if (!empty($conf->$module->multidir_output[$conf->entity])) {
15568 $dir_output = $conf->$module->multidir_output[$conf->entity];
15569 } elseif (!empty($conf->$module->output[$conf->entity])) {
15570 $dir_output = $conf->$module->output[$conf->entity];
15571 } elseif (!empty($conf->$module->dir_output)) {
15572 $dir_output = $conf->$module->dir_output;
15574 if (!empty($conf->$module->multidir_temp[$conf->entity])) {
15575 $dir_temp = $conf->$module->multidir_temp[$conf->entity];
15576 } elseif (!empty($conf->$module->temp[$conf->entity])) {
15577 $dir_temp = $conf->$module->temp[$conf->entity];
15578 } elseif (!empty($conf->$module->dir_temp)) {
15579 $dir_temp = $conf->$module->dir_temp;
15583 // Overwrite value for special cases
15584 if ($element == 'order_supplier' && isModEnabled('fournisseur')) {
15585 $dir_output = $conf->fournisseur->commande->dir_output;
15586 $dir_temp = $conf->fournisseur->commande->dir_temp;
15587 } elseif ($element == 'invoice_supplier' && isModEnabled('fournisseur')) {
15588 $dir_output = $conf->fournisseur->facture->dir_output;
15589 $dir_temp = $conf->fournisseur->facture->dir_temp;
15591 $dir_output .= $subdir;
15592 $dir_temp .= $subdir;
15594 $elementProperties = array(
15595 'module' => $module,
15596 'element' => $element,
15597 'table_element' => $table_element,
15598 'subelement' => $subelement,
15599 'classpath' => $classpath,
15600 'classfile' => $classfile,
15601 'classname' => $classname,
15602 'dir_output' => $dir_output,
15603 'dir_temp' => $dir_temp,
15604 'parent_element' => $parent_element,
15609 if (!is_object($hookmanager)) {
15610 include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
15611 $hookmanager = new HookManager($db);
15613 $hookmanager->initHooks(array('elementproperties'));
15617 $parameters = array(
15618 'elementType' => $elementType,
15619 'elementProperties' => $elementProperties
15622 $reshook = $hookmanager->executeHooks('getElementProperties', $parameters);
15625 $elementProperties = $hookmanager->resArray;
15626 } elseif (!empty($hookmanager->resArray) && is_array($hookmanager->resArray)) { // resArray is always an array but for sécurity against misconfigured external modules
15627 $elementProperties = array_replace($elementProperties, $hookmanager->resArray);
15630 // context of elementproperties doesn't need to exist out of this function so delete it to avoid elementproperties context is equal to all
15631 if (($key = array_search('elementproperties', $hookmanager->contextarray)) !== false) {
15632 unset($hookmanager->contextarray[$key]);
15635 return $elementProperties;
15650function fetchObjectByElement($element_id, $element_type, $element_ref = '', $useCache = 0, $maxCacheByType = 10)
15656 $element_prop = getElementProperties($element_type);
15658 if ($element_prop['module'] == 'product' || $element_prop['module'] == 'service') {
15659 // For example, for an extrafield 'product' (shared for both product and service) that is a link to an object,
15660 // this is called with $element_type = 'product' when we need element properties of a service, we must return a product. If we create the
15661 // extrafield for a service, it is not supported and not found when editing the product/service card. So we must keep 'product' for extrafields
15662 // of service and we will return properties of a product.
15663 $ismodenabled = (isModEnabled('product') || isModEnabled('service'));
15664 } elseif ($element_prop['module'] == 'societeaccount') {
15665 $ismodenabled = isModEnabled('website') || isModEnabled('webportal');
15667 $ismodenabled = isModEnabled($element_prop['module']);
15669 //var_dump('element_type='.$element_type);
15670 //var_dump($element_prop);
15671 //var_dump($element_prop['module'].' '.$ismodenabled);
15672 if (is_array($element_prop) && (empty($element_prop['module']) || $ismodenabled)) {
15673 if ($useCache === 1 && $element_id > 0
15674 && !empty($conf->cache['fetchObjectByElement'][$element_type])
15675 && !empty($conf->cache['fetchObjectByElement'][$element_type][$element_id])
15676 && is_object($conf->cache['fetchObjectByElement'][$element_type][$element_id])
15678 return $conf->cache['fetchObjectByElement'][$element_type][$element_id];
15681 dol_include_once('/' . $element_prop['classpath'] . '/' . $element_prop['classfile'] . '.class.php');
15683 if (class_exists($element_prop['classname'])) {
15684 $className = $element_prop['classname'];
15685 $objecttmp = new $className($db);
15686 '@phan-var-force CommonObject $objecttmp';
15689 if ($element_id > 0 || !empty($element_ref)) {
15690 $ret = $objecttmp->fetch($element_id, $element_ref);
15692 if (empty($objecttmp->module)) {
15693 $objecttmp->module = $element_prop['module'];
15696 if ($useCache > 0) {
15697 if (!isset($conf->cache['fetchObjectByElement'][$element_type])) {
15698 $conf->cache['fetchObjectByElement'][$element_type] = [];
15701 // Manage cache limit
15702 if (! empty($conf->cache['fetchObjectByElement'][$element_type]) && is_array($conf->cache['fetchObjectByElement'][$element_type]) && count($conf->cache['fetchObjectByElement'][$element_type]) >= $maxCacheByType) {
15703 array_shift($conf->cache['fetchObjectByElement'][$element_type]);
15706 $conf->cache['fetchObjectByElement'][$element_type][$element_id] = $objecttmp;
15712 return $objecttmp; // returned an object without fetch
15715 dol_syslog($element_prop['classname'] . ' doesn\'t exists in /' . $element_prop['classpath'] . '/' . $element_prop['classfile'] . '.class.php');
15728function getExecutableContent()
15730 $arrayofregexextension = array(
15757 return $arrayofregexextension;
15766function isAFileWithExecutableContent($filename)
15768 $arrayofregexextension = getExecutableContent();
15770 foreach ($arrayofregexextension as $fileextension) {
15771 if (preg_match('/\.' . preg_quote($fileextension, '/') . '$/i', $filename)) {
15788 return empty($_SESSION['newtoken']) ? '' : $_SESSION['newtoken'];
15798function currentToken()
15800 return isset($_SESSION['token']) ? $_SESSION['token'] : '';
15812 if (empty($conf->cache['nonce'])) {
15813 include_once DOL_DOCUMENT_ROOT . '/core/lib/security.lib.php';
15814 $conf->cache['nonce'] = dolGetRandomBytes(8);
15817 return $conf->cache['nonce'];
15834function startSimpleTable($header, $link = "
", $arguments = "", $emptyColumns = 0, $number = -1, $pictofulllist = '')
15838 print '<div class="div-
table-responsive-no-min
">';
15839 print '<table class="noborder centpercent
">';
15840 print '<tr class="liste_titre
">';
15842 print ($emptyColumns < 1) ? '<th>' : '<th colspan="' . ($emptyColumns + 1) . '">';
15844 print '<span class="valignmiddle
">' . $langs->trans($header) . '</span>';
15846 if (!empty($link)) {
15847 if (!empty($arguments)) {
15848 print '<a href="' . DOL_URL_ROOT . '/
' . $link . '?
' . $arguments . '">';
15850 print '<a href="' . DOL_URL_ROOT . '/
' . $link . '">';
15854 if ($number > -1) {
15855 print '<span class="badge marginleftonlyshort
">' . $number . '</span>';
15856 } elseif (!empty($link)) {
15857 print '<span class="badge marginleftonlyshort
">...</span>';
15860 if (!empty($link)) {
15866 if ($number < 0 && !empty($link)) {
15867 print '<th class="right
">';
15882function finishSimpleTable($addLineBreak = false)
15887 if ($addLineBreak) {
15903function addSummaryTableLine($tableColumnCount, $num, $nbofloop = 0, $total = 0, $noneWord = "None
", $extraRightColumn = false)
15908 print '<tr class="oddeven
">';
15909 print '<td colspan="' . $tableColumnCount . '"><span class="opacitymedium
">' . $langs->trans($noneWord) . '</span></td>';
15914 if ($nbofloop === 0) {
15915 // don't show a summary line
15919 /* Case already handled above, commented to satisfy phpstan.
15921 $colspan = $tableColumnCount;
15924 if ($num > $nbofloop) {
15925 $colspan = $tableColumnCount;
15927 $colspan = $tableColumnCount - 1;
15930 if ($extraRightColumn) {
15934 print '<tr class="liste_total
">';
15936 if ($nbofloop > 0 && $num > $nbofloop) {
15937 print '<td colspan="' . $colspan . '" class="right
">' . $langs->trans("XMoreLines
", ($num - $nbofloop)) . '</td>';
15939 print '<td colspan="' . $colspan . '" class="right
"> ' . $langs->trans("Total
") . '</td>';
15940 print '<td class="right centpercent
">' . price($total) . '</td>';
15943 if ($extraRightColumn) {
15958function readfileLowMemory($fullpath_original_file_osencoded, $method = -1)
15960 if ($method == -1) {
15962 if (getDolGlobalString('MAIN_FORCE_READFILE_WITH_FREAD')) {
15965 if (getDolGlobalString('MAIN_FORCE_READFILE_WITH_STREAM_COPY')) {
15970 // Be sure we don't have output buffering enabled to have readfile working correctly
15971 $level = ob_get_level();
15973 while (ob_get_level() > $level) {
15978 if ($method == 0) {
15979 readfile($fullpath_original_file_osencoded);
15980 } elseif ($method == 1) {
15982 $handle = fopen($fullpath_original_file_osencoded, "rb
");
15983 while (!feof($handle)) {
15984 print fread($handle, 8192);
15987 } elseif ($method == 2) {
15989 $handle1 = fopen($fullpath_original_file_osencoded, "rb
");
15990 $handle2 = fopen("php:
15991 stream_copy_to_stream($handle1, $handle2);
16006function showValueWithClipboardCPButton($valuetocopy, $showonlyonhover = 1, $texttoshow =
'')
16012 $result =
'<span class="clipboardCP' . ($showonlyonhover ?
' clipboardCPShowOnHover valignmiddle' :
'') .
'">';
16013 if ($texttoshow ===
'none') {
16014 $result .=
'<' . $tag .
' class="clipboardCPValue hidewithsize">' .
dol_escape_htmltag($valuetocopy, 1, 1) .
'</' . $tag .
'>';
16015 $result .=
'<span class="clipboardCPValueToPrint"></span>';
16016 } elseif ($texttoshow) {
16017 $result .=
'<' . $tag .
' class="clipboardCPValue hidewithsize">' .
dol_escape_htmltag($valuetocopy, 1, 1) .
'</' . $tag .
'>';
16018 $result .=
'<span class="clipboardCPValueToPrint">' .
dol_escape_htmltag($texttoshow, 1, 1) .
'</span>';
16020 $result .=
'<' . $tag .
' class="clipboardCPValue">' .
dol_escape_htmltag($valuetocopy, 1, 1) .
'</' . $tag .
'>';
16022 $result .=
'<span class="clipboardCPButton far fa-clipboard opacitymedium paddingleft pictomodule" title="' .
dolPrintHTML($langs->trans(
"ClickToCopyToClipboard")) .
'"></span>';
16023 $result .=
img_picto(
'',
'tick',
'class="clipboardCPTick hidden paddingleft pictomodule"');
16024 $result .=
'<span class="clipboardCPText"></span>';
16025 $result .=
'</span>';
16038function jsonOrUnserialize($stringtodecode, $assoc =
true)
16040 $result = json_decode($stringtodecode, $assoc);
16041 if ($result ===
null) {
16042 $result = unserialize($stringtodecode, [
'allowed_classes' =>
false]);
16065function forgeSQLFromUniversalSearchCriteria($filter, &$errorstr =
'', $noand = 0, $nopar = 0, $noerror = 0)
16069 if (is_null($filter) || !is_string($filter) || $filter ===
'') {
16072 if (!preg_match(
'/^\(.*\)$/', $filter)) {
16073 $filter =
'(' . $filter .
')';
16076 $regexstring =
'\(([a-zA-Z0-9_\.]+:[<>!=insotlke]+:[^\(\)]+)\)';
16077 $firstandlastparenthesis = 0;
16079 if (!dolCheckFilters($filter, $errorstr, $firstandlastparenthesis)) {
16083 return 'Filter syntax error - ' . $errorstr;
16088 $t = preg_replace_callback(
'/' . $regexstring .
'/i',
'dolForgeDummyCriteriaCallback', $filter);
16089 $t = str_ireplace(array(
'and',
'or',
' '),
'', $t);
16092 if (preg_match(
'/[^\(\)]/', $t)) {
16093 $tmperrorstr =
'Bad syntax of the search string';
16094 $errorstr =
'Bad syntax of the search string: ' . $filter;
16098 dol_syslog(
"forgeSQLFromUniversalSearchCriteria Filter error - " . $errorstr, LOG_WARNING);
16099 return 'Filter error - ' . $tmperrorstr;
16103 $ret = ($noand ?
"" :
" AND ") . ($nopar ?
"" :
'(') . preg_replace_callback(
'/' . $regexstring .
'/i',
'dolForgeSQLCriteriaCallback', $filter) . ($nopar ?
"" :
')');
16105 if (is_object(
$db)) {
16106 $ret = str_replace(
'__NOW__',
"'" .
$db->idate(
dol_now()) .
"'", $ret);
16108 if (is_object($user)) {
16109 $ret = str_replace(
'__USER_ID__', (
string) $user->id, $ret);
16122function dolForgeExplodeAnd($sqlfilters)
16124 $arrayofandtags = array();
16128 $parenthesislevel = 0;
16129 $result = dolCheckFilters($sqlfilters, $error, $parenthesislevel);
16133 if ($parenthesislevel >= 1) {
16134 $sqlfilters = preg_replace(
'/^\(/',
'', preg_replace(
'/\)$/',
'', $sqlfilters));
16139 $countparenthesis = 0;
16140 while ($i < $nbofchars) {
16143 if ($char ==
'(') {
16144 $countparenthesis++;
16145 } elseif ($char ==
')') {
16146 $countparenthesis--;
16149 if ($countparenthesis == 0) {
16150 $char2 =
dol_substr($sqlfilters, $i + 1, 1);
16151 $char3 =
dol_substr($sqlfilters, $i + 2, 1);
16152 if ($char ==
'A' && $char2 ==
'N' && $char3 ==
'D') {
16155 if (!preg_match(
'/^\(.*\)$/', $s)) {
16156 $s =
'(' . $s .
')';
16158 $arrayofandtags[] = $s;
16171 if (!preg_match(
'/^\(.*\)$/', $s)) {
16172 $s =
'(' . $s .
')';
16174 $arrayofandtags[] = $s;
16177 return $arrayofandtags;
16189function dolCheckFilters($sqlfilters, &$error =
'', &$parenthesislevel = 0)
16193 $tmp = $sqlfilters;
16197 $parenthesislevel = 0;
16205 if ($char ==
'(') {
16206 if ($i == $parenthesislevel && $parenthesislevel == $counter) {
16208 $parenthesislevel++;
16211 } elseif ($char ==
')') {
16212 $nbcharremaining = ($nb - $i - 1);
16213 if ($nbcharremaining >= $counter) {
16214 $parenthesislevel = min($parenthesislevel, $counter - 1);
16216 if ($parenthesislevel > $counter && $nbcharremaining >= $counter) {
16217 $parenthesislevel = $counter;
16222 if ($counter < 0) {
16223 $error =
"Wrong balance of parenthesis in sqlfilters=" . $sqlfilters;
16224 $parenthesislevel = 0;
16232 if ($counter > 0) {
16233 $error =
"Wrong balance of parenthesis in sqlfilters=" . $sqlfilters;
16234 $parenthesislevel = 0;
16249function dolForgeDummyCriteriaCallback($matches)
16252 if (empty($matches[1])) {
16255 $tmp = explode(
':', $matches[1]);
16256 if (count($tmp) < 3) {
16272function dolForgeSQLCriteriaCallback($matches)
16277 if (empty($matches[1])) {
16280 $tmp = explode(
':', $matches[1], 3);
16281 if (count($tmp) < 3) {
16285 $operand = preg_replace(
'/[^a-z0-9\._]/i',
'', trim($tmp[0]));
16287 $operator = strtoupper(preg_replace(
'/[^a-z<>!=]/i',
'', trim($tmp[1])));
16290 'NOTLIKE' =>
'NOT LIKE',
16291 'ISNOT' =>
'IS NOT',
16292 'NOTIN' =>
'NOT IN',
16296 if (array_key_exists($operator, $realOperator)) {
16297 $operator = $realOperator[$operator];
16300 $tmpescaped = $tmp[2];
16306 if ($operator ==
'IN' || $operator ==
'NOT IN') {
16307 global $dolibarr_allow_unsecured_select_in_extrafields_filter;
16310 $tmpescaped2 =
'(';
16312 $tmpelemarray = explode(
',', $tmpescaped);
16313 foreach ($tmpelemarray as $tmpkey => $tmpelem) {
16315 $tmpelem = trim($tmpelem);
16316 if (preg_match(
'/^\'(.*)\'$/', $tmpelem, $reg)) {
16317 $tmpelemarray[$tmpkey] =
"'" .
$db->escape(
$db->sanitize($reg[1], 2, 1, 1, 1)) .
"'";
16318 } elseif (ctype_digit((
string) $tmpelem)) {
16319 $tmpelemarray[$tmpkey] = (int) $tmpelem;
16320 } elseif (is_numeric((
string) $tmpelem)) {
16321 $tmpelemarray[$tmpkey] = (float) $tmpelem;
16322 } elseif (!empty($dolibarr_allow_unsecured_select_in_extrafields_filter)) {
16323 $tmpelemarray[$tmpkey] = preg_replace(
'/[^a-z0-9_<>=!\s]/i',
'', $tmpelem);
16325 $tmpelemarray[$tmpkey] = preg_replace(
'/[^a-z0-9_]/i',
'', $tmpelem);
16328 $tmpescaped2 .= implode(
',', $tmpelemarray);
16329 $tmpescaped2 .=
')';
16331 $tmpescaped = $tmpescaped2;
16332 } elseif ($operator ==
'LIKE' || $operator ==
'NOT LIKE') {
16333 if (preg_match(
'/^\'([^\']*)\'$/', $tmpescaped, $regbis)) {
16334 $tmpescaped = $regbis[1];
16337 $tmpescaped =
"'" .
$db->escape($tmpescaped) .
"'";
16338 } elseif (preg_match(
'/^\'(.*)\'$/', $tmpescaped, $regbis)) {
16341 $tmpescaped =
"'" .
$db->escape($regbis[1]) .
"'";
16343 if (strtoupper($tmpescaped) ==
'NULL') {
16344 $tmpescaped =
'NULL';
16345 } elseif (ctype_digit((
string) $tmpescaped)) {
16346 $tmpescaped = (int) $tmpescaped;
16347 } elseif (is_numeric((
string) $tmpescaped)) {
16348 $tmpescaped = (float) $tmpescaped;
16350 $tmpescaped = preg_replace(
'/[^a-z0-9_]/i',
'', $tmpescaped);
16354 return '(' .
$db->escape($operand) .
' ' . strtoupper($operator) .
' ' . $tmpescaped .
')';
16367function getTimelineIcon($actionstatic, &$histo, $key)
16369 dol_syslog(
'getTimelineIcon::begin', LOG_DEBUG);
16372 $out =
'<!-- timeline icon -->' .
"\n";
16373 $iconClass =
'fa fa-comments';
16378 if ($histo[$key][
'percent'] == -1) {
16379 $colorClass =
'timeline-icon-not-applicble';
16380 $pictoTitle = $langs->trans(
'StatusNotApplicable');
16381 } elseif ($histo[$key][
'percent'] == 0) {
16382 $colorClass =
'timeline-icon-todo';
16383 $pictoTitle = $langs->trans(
'StatusActionToDo') .
' (0%)';
16384 } elseif ($histo[$key][
'percent'] > 0 && $histo[$key][
'percent'] < 100) {
16385 $colorClass =
'timeline-icon-in-progress';
16386 $pictoTitle = $langs->trans(
'StatusActionInProcess') .
' (' . $histo[$key][
'percent'] .
'%)';
16387 } elseif ($histo[$key][
'percent'] >= 100) {
16388 $colorClass =
'timeline-icon-done';
16389 $pictoTitle = $langs->trans(
'StatusActionDone') .
' (100%)';
16392 if ($actionstatic->code ==
'AC_TICKET_CREATE') {
16393 $iconClass =
'fa fa-ticket';
16394 } elseif ($actionstatic->code ==
'AC_TICKET_MODIFY') {
16395 $iconClass =
'fa fa-pencilxxx';
16396 } elseif (preg_match(
'/^TICKET_MSG/', $actionstatic->code)) {
16397 $iconClass =
'fa fa-comments';
16398 } elseif (preg_match(
'/^TICKET_MSG_PRIVATE/', $actionstatic->code)) {
16399 $iconClass =
'fa fa-mask';
16401 if ($actionstatic->type_picto) {
16402 $img_picto =
img_picto(
'', $actionstatic->type_picto);
16404 if ($actionstatic->type_code ==
'AC_RDV') {
16405 $iconClass =
'fa fa-handshake';
16406 } elseif ($actionstatic->type_code ==
'AC_TEL') {
16407 $iconClass =
'fa fa-phone';
16408 } elseif ($actionstatic->type_code ==
'AC_FAX') {
16409 $iconClass =
'fa fa-fax';
16410 } elseif ($actionstatic->type_code ==
'AC_EMAIL') {
16411 $iconClass =
'fa fa-envelope';
16412 } elseif ($actionstatic->type_code ==
'AC_INT') {
16413 $iconClass =
'fa fa-shipping-fast';
16414 } elseif ($actionstatic->type_code ==
'AC_OTH_AUTO') {
16415 $iconClass =
'fa fa-robot';
16416 } elseif (!preg_match(
'/_AUTO/', $actionstatic->type_code)) {
16417 $iconClass =
'fa fa-robot';
16422 $out .=
'<i class="' . $iconClass .
' ' . $colorClass .
'" title="' . $pictoTitle .
'">' . $img_picto .
'</i>' .
"\n";
16432function getActionCommEcmList(
$object)
16436 $documents = array();
16438 $sql =
'SELECT ecm.rowid as id, ecm.src_object_type, ecm.src_object_id, ecm.filepath, ecm.filename, ecm.agenda_id';
16439 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'ecm_files ecm';
16440 $sql .=
" WHERE ecm.filepath = 'agenda/" . ((int)
$object->id) .
"'";
16442 $sql .=
' OR ecm.agenda_id = ' . (int)
$object->id;
16443 $sql .=
' ORDER BY ecm.position ASC';
16445 $resql =
$db->query($sql);
16447 if (
$db->num_rows($resql)) {
16448 while ($obj =
$db->fetch_object($resql)) {
16449 $documents[$obj->id] = $obj;
16475function show_actions_messaging(
$conf, $langs,
$db, $filterobj, $objcon =
null, $noprint = 0, $actioncode =
'', $donetodo =
'done', $filters = array(), $sortfield =
'a.datep,a.id', $sortorder =
'DESC')
16477 dol_syslog(
'show_actions_messaging::begin', LOG_DEBUG);
16478 global $user,
$conf;
16481 global $param, $massactionbutton;
16483 require_once DOL_DOCUMENT_ROOT .
'/comm/action/class/actioncomm.class.php';
16486 if (!is_object($filterobj) && !is_object($objcon)) {
16491 '@phan-var-force array<int,array{type:string,tododone:string,id:string,datestart:int|string,dateend:int|string,fulldayevent:int,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';
16496 $sortfield_list = explode(
',', $sortfield);
16497 $sortfield_label_list = array(
'a.id' =>
'id',
'a.datep' =>
'dp',
'a.percent' =>
'percent');
16498 $sortfield_new_list = array();
16499 foreach ($sortfield_list as $sortfield_value) {
16500 $sortfield_new_list[] = $sortfield_label_list[trim($sortfield_value)];
16502 $sortfield_new = implode(
',', $sortfield_new_list);
16509 if (is_object($objcon) && $objcon->id > 0) {
16510 $sql =
"SELECT DISTINCT a.id, a.label as label,";
16512 $sql =
"SELECT a.id, a.label as label,";
16514 $sql .=
" a.datep as dp,";
16515 $sql .=
" a.note as message,";
16516 $sql .=
" a.datep2 as dp2,";
16517 $sql .=
" a.percent as percent, 'action' as type,";
16518 $sql .=
" a.fk_element, a.elementtype,";
16519 $sql .=
" a.fk_contact, a.fulldayevent,";
16520 $sql .=
" a.email_from as msg_from,";
16521 $sql .=
" c.code as acode, c.libelle as alabel, c.picto as apicto,";
16522 $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";
16523 if (is_object($filterobj) && get_class($filterobj) ==
'Societe') {
16524 $sql .=
", sp.lastname, sp.firstname";
16525 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Adherent') {
16526 $sql .=
", m.lastname, m.firstname";
16527 } elseif (is_object($filterobj) && in_array(get_class($filterobj), array(
'Commande',
'CommandeFournisseur',
'Product',
'Ticket',
'BOM',
'Contrat',
'Facture',
'FactureFournisseur',
'Propal',
'Expedition'))) {
16530 if (is_object($filterobj) && !empty($filterobj->table_element) && !empty($filterobj->element) && !empty($filterobj->id) && array_key_exists(
'ref', $filterobj->fields)) {
16534 $sql .=
" FROM " . MAIN_DB_PREFIX .
"actioncomm as a";
16535 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"user as u on u.rowid = a.fk_user_action";
16536 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"c_actioncomm as c ON a.fk_action = c.id";
16538 $force_filter_contact = $filterobj instanceof
User;
16540 if (is_object($objcon) && $objcon->id > 0) {
16541 $force_filter_contact =
true;
16542 $sql .=
" INNER JOIN " . MAIN_DB_PREFIX .
"actioncomm_resources as r ON a.id = r.fk_actioncomm";
16543 $sql .=
" AND r.element_type = '" .
$db->escape($objcon->table_element) .
"' AND r.fk_element = " . ((int) $objcon->id);
16546 if ((is_object($filterobj) && get_class($filterobj) ==
'Societe') || (is_object($filterobj) && get_class($filterobj) ==
'Contact')) {
16547 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"socpeople as sp ON a.fk_contact = sp.rowid";
16548 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Dolresource') {
16549 $sql .=
" INNER JOIN " . MAIN_DB_PREFIX .
"element_resources as er";
16550 $sql .=
" ON er.resource_type = 'dolresource'";
16551 $sql .=
" AND er.element_id = a.id";
16552 $sql .=
" AND er.resource_id = " . ((int) $filterobj->id);
16553 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Adherent') {
16554 $sql .=
", " . MAIN_DB_PREFIX .
"adherent as m";
16555 } elseif (is_object($filterobj) && get_class($filterobj) ==
'CommandeFournisseur') {
16556 $sql .=
", " . MAIN_DB_PREFIX .
"commande_fournisseur as o";
16557 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Product') {
16558 $sql .=
", " . MAIN_DB_PREFIX .
"product as o";
16559 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Ticket') {
16560 $sql .=
", " . MAIN_DB_PREFIX .
"ticket as o";
16561 } elseif (is_object($filterobj) && get_class($filterobj) ==
'BOM') {
16562 $sql .=
", " . MAIN_DB_PREFIX .
"bom_bom as o";
16563 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Contrat') {
16564 $sql .=
", " . MAIN_DB_PREFIX .
"contrat as o";
16565 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Facture') {
16566 $sql .=
", " . MAIN_DB_PREFIX .
"facture as o";
16567 } elseif (is_object($filterobj) && get_class($filterobj) ==
'FactureFournisseur') {
16568 $sql .=
", " . MAIN_DB_PREFIX .
"facture_fourn as o";
16569 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Commande') {
16570 $sql .=
", " . MAIN_DB_PREFIX .
"commande as o";
16571 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Expedition') {
16572 $sql .=
", " . MAIN_DB_PREFIX .
"expedition as o";
16573 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Propal') {
16574 $sql .=
", " . MAIN_DB_PREFIX .
"propal as o";
16576 if (is_object($filterobj) && !empty($filterobj->table_element) && !empty($filterobj->element) && !empty($filterobj->id) && array_key_exists(
'ref', $filterobj->fields)) {
16577 $sql .=
", " . MAIN_DB_PREFIX . $filterobj->table_element .
" as o";
16580 $sql .=
" WHERE a.entity IN (" .
getEntity(
'agenda') .
")";
16581 if (!$force_filter_contact) {
16582 if (is_object($filterobj) && in_array(get_class($filterobj), array(
'Societe',
'Client',
'Fournisseur')) && $filterobj->id) {
16583 $sql .=
" AND a.fk_soc = " . ((int) $filterobj->id);
16584 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Project' && $filterobj->id) {
16585 $sql .=
" AND a.fk_project = o.rowid AND a.fk_project = " . ((int) $filterobj->id);
16586 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Adherent') {
16587 $sql .=
" AND a.fk_element = m.rowid AND a.elementtype = 'member'";
16588 if ($filterobj->id) {
16589 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16591 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Commande') {
16592 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'order'";
16593 if ($filterobj->id) {
16594 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16596 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Expedition') {
16597 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'shipping'";
16598 if ($filterobj->id) {
16599 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16601 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Propal') {
16602 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'propal'";
16603 if ($filterobj->id) {
16604 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16606 } elseif (is_object($filterobj) && get_class($filterobj) ==
'CommandeFournisseur') {
16607 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'order_supplier'";
16608 if ($filterobj->id) {
16609 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16611 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Product') {
16612 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'product'";
16613 if ($filterobj->id) {
16614 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16616 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Ticket') {
16617 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'ticket'";
16618 if ($filterobj->id) {
16619 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16621 } elseif (is_object($filterobj) && get_class($filterobj) ==
'BOM') {
16622 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'bom'";
16623 if ($filterobj->id) {
16624 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16626 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Contrat') {
16627 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'contract'";
16628 if ($filterobj->id) {
16629 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16631 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Contact' && $filterobj->id) {
16632 $sql .=
" AND a.fk_contact = sp.rowid";
16633 if ($filterobj->id) {
16634 $sql .=
" AND a.fk_contact = " . ((int) $filterobj->id);
16636 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Facture') {
16637 $sql .=
" AND a.fk_element = o.rowid";
16638 if ($filterobj->id) {
16639 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id) .
" AND a.elementtype = 'invoice'";
16641 } elseif (is_object($filterobj) && get_class($filterobj) ==
'FactureFournisseur') {
16642 $sql .=
" AND a.fk_element = o.rowid";
16643 if ($filterobj->id) {
16644 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id) .
" AND a.elementtype = 'invoice_supplier'";
16647 if (is_object($filterobj) && !empty($filterobj->element) && !empty($filterobj->id) && array_key_exists(
'ref', $filterobj->fields)) {
16648 $sql .=
" AND a.fk_element = o.rowid";
16649 $sql .=
" AND a.elementtype = '" .
$db->escape($filterobj->element) .
"'";
16650 if ($filterobj->id) {
16651 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16656 $sql .=
" AND u.rowid = " . ((int) $filterobj->id);
16660 if (!empty($actioncode) && $actioncode !=
'-1') {
16662 if ($actioncode ==
'AC_NON_AUTO') {
16663 $sql .=
" AND c.type != 'systemauto'";
16664 } elseif ($actioncode ==
'AC_ALL_AUTO') {
16665 $sql .=
" AND c.type = 'systemauto'";
16667 if ($actioncode ==
'AC_OTH') {
16668 $sql .=
" AND c.type != 'systemauto'";
16669 } elseif ($actioncode ==
'AC_OTH_AUTO') {
16670 $sql .=
" AND c.type = 'systemauto'";
16674 if ($actioncode ==
'AC_NON_AUTO') {
16675 $sql .=
" AND c.type != 'systemauto'";
16676 } elseif ($actioncode ==
'AC_ALL_AUTO') {
16677 $sql .=
" AND c.type = 'systemauto'";
16679 $sql .=
" AND c.code = '" .
$db->escape($actioncode) .
"'";
16683 if ($donetodo ==
'todo') {
16684 $sql .=
" AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '" .
$db->idate($now) .
"'))";
16685 } elseif ($donetodo ==
'done') {
16686 $sql .=
" AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '" .
$db->idate($now) .
"'))";
16688 if (is_array($filters) && $filters[
'search_agenda_label']) {
16689 $sql .=
natural_search(
'a.label', $filters[
'search_agenda_label']);
16696 && (empty($actioncode) || $actioncode ==
'AC_OTH_AUTO' || $actioncode ==
'AC_EMAILING')
16698 $langs->load(
"mails");
16700 $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";
16701 $sql2 .=
", null as fk_element, '' as elementtype, null as contact_id";
16702 $sql2 .=
", 'AC_EMAILING' as acode, '' as alabel, '' as apicto";
16703 $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";
16704 if (is_object($filterobj) && get_class($filterobj) ==
'Societe') {
16705 $sql2 .=
", '' as lastname, '' as firstname";
16706 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Adherent') {
16707 $sql2 .=
", '' as lastname, '' as firstname";
16708 } elseif (is_object($filterobj) && get_class($filterobj) ==
'CommandeFournisseur') {
16709 $sql2 .=
", '' as ref";
16710 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Product') {
16711 $sql2 .=
", '' as ref";
16712 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Ticket') {
16713 $sql2 .=
", '' as ref";
16715 $sql2 .=
" FROM " . MAIN_DB_PREFIX .
"mailing as m, " . MAIN_DB_PREFIX .
"mailing_cibles as mc, " . MAIN_DB_PREFIX .
"user as u";
16716 $sql2 .=
" WHERE mc.email = '" .
$db->escape($objcon->email) .
"'";
16717 $sql2 .=
" AND mc.statut = 1";
16718 $sql2 .=
" AND u.rowid = m.fk_user_valid";
16719 $sql2 .=
" AND mc.fk_mailing=m.rowid";
16723 $MAXWITHOUTPAGINATION =
getDolGlobalInt(
'AGENDA_MAX_EVENTS_ON_PAGE_WITHOUT_PAGINATION', 100);
16725 if ($sql || $sql2) {
16726 if (!empty($sql) && !empty($sql2)) {
16727 $sql = $sql .
" UNION " . $sql2;
16728 } elseif (empty($sql) && !empty($sql2)) {
16734 $limit = $MAXWITHOUTPAGINATION;
16737 $sql .=
$db->order($sortfield_new, $sortorder);
16739 $sql .=
$db->plimit($limit + 1, $offset);
16742 dol_syslog(
"function.lib::show_actions_messaging", LOG_DEBUG);
16744 $resql =
$db->query($sql);
16747 $num =
$db->num_rows($resql);
16749 $imaxinloop = ($limit ? min($num, $limit) : $num);
16750 while ($i < $imaxinloop) {
16751 $obj =
$db->fetch_object($resql);
16753 if ($obj->type ==
'action') {
16755 $contactaction->id = $obj->id;
16756 $result = $contactaction->fetchResources();
16759 setEventMessage(
"actions.lib::show_actions_messaging Error fetch resource",
'errors');
16765 if (($obj->percent >= 0 and $obj->percent < 100) || ($obj->percent == -1 && $obj->dp > $now)) {
16766 $tododone =
'todo';
16769 $histo[$numaction] = array(
16770 'type' => $obj->type,
16771 'tododone' => $tododone,
16773 'datestart' =>
$db->jdate($obj->dp),
16774 'dateend' =>
$db->jdate($obj->dp2),
16775 'fulldayevent' => (
int) $obj->fulldayevent,
16776 'note' => $obj->label,
16777 'message' => $obj->message,
16778 'percent' => $obj->percent,
16780 'userid' => $obj->user_id,
16781 'login' => $obj->user_login,
16782 'userfirstname' => $obj->user_firstname,
16783 'userlastname' => $obj->user_lastname,
16784 'userphoto' => $obj->user_photo,
16785 'msg_from' => $obj->msg_from,
16787 'contact_id' => $obj->fk_contact,
16788 'socpeopleassigned' => $contactaction->socpeopleassigned,
16789 'lastname' => (empty($obj->lastname) ?
'' : $obj->lastname),
16790 'firstname' => (empty($obj->firstname) ?
'' : $obj->firstname),
16791 'fk_element' => $obj->fk_element,
16792 'elementtype' => $obj->elementtype,
16794 'acode' => $obj->acode,
16795 'alabel' => $obj->alabel,
16796 'libelle' => $obj->alabel,
16797 'apicto' => $obj->apicto
16800 $histo[$numaction] = array(
16801 'type' => $obj->type,
16802 'tododone' =>
'done',
16804 'datestart' =>
$db->jdate($obj->dp),
16805 'dateend' =>
$db->jdate($obj->dp2),
16806 'fulldayevent' => (
int) $obj->fulldayevent,
16807 'note' => $obj->label,
16808 'message' => $obj->message,
16809 'percent' => $obj->percent,
16810 'acode' => $obj->acode,
16812 'userid' => $obj->user_id,
16813 'login' => $obj->user_login,
16814 'userfirstname' => $obj->user_firstname,
16815 'userlastname' => $obj->user_lastname,
16816 'userphoto' => $obj->user_photo
16832 $langs->loadLangs(array(
"admin",
"errors"));
16833 $out =
info_admin($langs->trans(
"WarningModuleXDisabledSoYouMayMissEventHere", $langs->transnoentitiesnoconv(
"Module2400Name")), 0, 0,
'warning');
16837 $delay_warning =
getDolGlobalInt(
'MAIN_DELAY_ACTIONS_TODO') * 24 * 60 * 60;
16839 require_once DOL_DOCUMENT_ROOT .
'/comm/action/class/actioncomm.class.php';
16840 include_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
16841 require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formactions.class.php';
16842 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
16849 $userGetNomUrlCache = array();
16850 $contactGetNomUrlCache = array();
16852 $out .=
'<div class="filters-container" >';
16853 $out .=
'<form name="listactionsfilter" class="listactionsfilter" action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST">';
16854 $out .=
'<input type="hidden" name="token" value="' . newToken() .
'">';
16857 $objcon && get_class($objcon) ==
'Contact' &&
16858 (is_null($filterobj) || get_class($filterobj) ==
'Societe')
16860 $out .=
'<input type="hidden" name="id" value="' . $objcon->id .
'" />';
16862 $out .=
'<input type="hidden" name="id" value="' . $filterobj->id .
'" />';
16864 if (($filterobj && get_class($filterobj) ==
'Societe')) {
16865 $out .=
'<input type="hidden" name="socid" value="' . $filterobj->id .
'" />';
16867 $out .=
'<input type="hidden" name="userid" value="' . $filterobj->id .
'" />';
16872 $out .=
'<div class="div-table-responsive-no-min">';
16873 $out .=
'<table class="noborder borderbottom centpercent">';
16875 $out .=
'<tr class="liste_titre">';
16878 if (
$conf->main_checkbox_left_column) {
16879 $out .=
'<th class="liste_titre width50 middle">';
16880 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0,
'checkforselect', 1);
16881 $out .= $searchpicto;
16886 $out .=
getTitleFieldOfList(
'Date', 0, $_SERVER[
"PHP_SELF"],
'a.datep',
'', $param,
'', $sortfield, $sortorder,
'nowraponall nopaddingleftimp ') .
"\n";
16888 $out .=
'<th class="liste_titre hideonsmartphone"><strong class="hideonsmartphone">' . $langs->trans(
"Search") .
' : </strong></th>';
16890 $out .=
'<th class="liste_titre"></th>';
16893 $out .=
'<th class="liste_titre">';
16894 $out .=
'<span class="fas fa-square inline-block fawidth30 hideonsmartphone" style="color: #ddd;" title="' . $langs->trans(
"ActionType") .
'"></span>';
16895 $out .= $formactions->select_type_actions($actioncode,
"actioncode",
'',
getDolGlobalString(
'AGENDA_USE_EVENT_TYPE') ? -1 : 1, 0, 0, 1,
'selecttype minwidth100', $langs->trans(
"Type"));
16898 $out .=
'<th class="liste_titre maxwidth100onsmartphone">';
16899 $out .=
'<input type="text" class="maxwidth100onsmartphone" name="search_agenda_label" value="' . $filters[
'search_agenda_label'] .
'" placeholder="' . $langs->trans(
"Label") .
'">';
16903 if (!
$conf->main_checkbox_left_column) {
16904 $out .=
'<th class="liste_titre width50 middle">';
16905 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0,
'checkforselect', 1);
16906 $out .= $searchpicto;
16912 $out .=
'</table>';
16919 $out .=
'<ul class="timeline">';
16923 if ($filterobj instanceof
Societe) {
16924 $tmp .=
'<a href="' . DOL_URL_ROOT .
'/comm/action/list.php?mode=show_list&socid=' . $filterobj->id .
'&status=done">';
16926 if ($filterobj instanceof
User) {
16927 $tmp .=
'<a href="' . DOL_URL_ROOT .
'/comm/action/list.php?mode=show_list&socid=' . $filterobj->id .
'&status=done">';
16929 $tmp .= ($donetodo !=
'done' ? $langs->trans(
"ActionsToDoShort") :
'');
16930 $tmp .= ($donetodo !=
'done' && $donetodo !=
'todo' ?
' / ' :
'');
16931 $tmp .= ($donetodo !=
'todo' ? $langs->trans(
"ActionsDoneShort") :
'');
16933 if ($filterobj instanceof
Societe) {
16936 if ($filterobj instanceof
User) {
16942 require_once DOL_DOCUMENT_ROOT .
'/comm/action/class/cactioncomm.class.php';
16944 $arraylist = $caction->liste_array(1,
'code',
'', (!
getDolGlobalString(
'AGENDA_USE_EVENT_TYPE') ? 1 : 0),
'', 1);
16946 $actualCycleDate =
false;
16949 foreach ($histo as $key => $value) {
16950 $actionstatic->fetch($histo[$key][
'id']);
16952 $actionstatic->type_picto = $histo[$key][
'apicto'];
16953 $actionstatic->type_code = $histo[$key][
'acode'];
16955 $labeltype = $actionstatic->type_code;
16956 if (!
getDolGlobalString(
'AGENDA_USE_EVENT_TYPE') && empty($arraylist[$labeltype])) {
16957 $labeltype =
'AC_OTH';
16959 if (!empty($actionstatic->code) && preg_match(
'/^TICKET_MSG/', $actionstatic->code)) {
16960 $labeltype = $langs->trans(
"Message");
16962 if (!empty($arraylist[$labeltype])) {
16963 $labeltype = $arraylist[$labeltype];
16965 if ($actionstatic->type_code ==
'AC_OTH_AUTO' && ($actionstatic->type_code != $actionstatic->code) && $labeltype && !empty($arraylist[$actionstatic->code])) {
16966 $labeltype .=
' - ' . $arraylist[$actionstatic->code];
16970 $url = DOL_URL_ROOT .
'/comm/action/card.php?id=' . $histo[$key][
'id'];
16972 $tmpa =
dol_getdate($histo[$key][
'datestart'],
false);
16974 if (isset($tmpa[
'year']) && isset($tmpa[
'yday']) && $actualCycleDate !== $tmpa[
'year'] .
'-' . $tmpa[
'yday']) {
16975 $actualCycleDate = $tmpa[
'year'] .
'-' . $tmpa[
'yday'];
16976 $out .=
'<!-- timeline time label -->';
16977 $out .=
'<li class="time-label">';
16978 $out .=
'<span class="timeline-badge-date">';
16979 $out .=
dol_print_date($histo[$key][
'datestart'],
'daytext',
'tzuserrel', $langs);
16982 $out .=
'<!-- /.timeline-label -->';
16986 $out .=
'<!-- timeline item -->' .
"\n";
16987 $out .=
'<li class="timeline-code-' . (!empty($actionstatic->code) ? strtolower($actionstatic->code) :
"none") .
'">';
16990 $typeicon = $actionstatic->getTypePicto(
'pictofixedwidth timeline-icon-not-applicble', $labeltype);
16995 $out .=
'<div class="timeline-item">' .
"\n";
16997 $out .=
'<span class="time timeline-header-action2">';
16999 if (isset($histo[$key][
'type']) && $histo[$key][
'type'] ==
'mailing') {
17000 $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") .
' ';
17001 $out .= $histo[$key][
'id'];
17004 $out .= $actionstatic->getNomUrl(1, -1,
'valignmiddle') .
' ';
17008 $user->hasRight(
'agenda',
'allactions',
'create') ||
17009 (($actionstatic->authorid == $user->id || $actionstatic->userownerid == $user->id) && $user->hasRight(
'agenda',
'myactions',
'create'))
17011 $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) .
'">';
17013 $out .=
img_picto($langs->trans(
"Modify"),
'edit',
'class="edita"');
17020 $out .=
'<span class="time"><i class="fa fa-clock valignmiddle"></i> ';
17021 $out .=
'<span class="valignmiddle marginrightonly">';
17022 $out .=
dol_print_date($histo[$key][
'datestart'],
'day',
'tzuserrel');
17025 $out .=
' '.dol_print_date($histo[$key][
'datestart'],
'hour',
'tzuserrel',
null,
false,
'opacitymedium');
17027 if ($histo[$key][
'dateend'] && $histo[$key][
'dateend'] != $histo[$key][
'datestart']) {
17028 $tmpa =
dol_getdate($histo[$key][
'datestart'],
true);
17029 $tmpb =
dol_getdate($histo[$key][
'dateend'],
true);
17030 if ($tmpa[
'mday'] == $tmpb[
'mday'] && $tmpa[
'mon'] == $tmpb[
'mon'] && $tmpa[
'year'] == $tmpb[
'year']) {
17031 $out .=
' - ' .
dol_print_date($histo[$key][
'dateend'],
'hour',
'tzuserrel',
null,
false, 1);
17033 $out .=
' - ' .
dol_print_date($histo[$key][
'dateend'],
'day',
'tzuserrel');
17035 $out .=
' '.dol_print_date($histo[$key][
'dateend'],
'hour',
'tzuserrel',
null,
false,
'opacitymedium');
17040 if ($histo[$key][
'percent'] == 0 && $histo[$key][
'datestart'] && $histo[$key][
'datestart'] < ($now - $delay_warning)) {
17043 if ($histo[$key][
'percent'] == 0 && !$histo[$key][
'datestart'] && $histo[$key][
'dateend'] && $histo[$key][
'datestart'] < ($now - $delay_warning)) {
17046 if ($histo[$key][
'percent'] > 0 && $histo[$key][
'percent'] < 100 && $histo[$key][
'dateend'] && $histo[$key][
'dateend'] < ($now - $delay_warning)) {
17049 if ($histo[$key][
'percent'] > 0 && $histo[$key][
'percent'] < 100 && !$histo[$key][
'dateend'] && $histo[$key][
'datestart'] && $histo[$key][
'datestart'] < ($now - $delay_warning)) {
17053 $out .=
img_warning($langs->trans(
"Late")) .
' ';
17055 $out .=
"</span></span>\n";
17057 $out .=
'<span class="time">';
17058 $out .= $actionstatic->getLibStatut(2);
17062 $out .=
'<h3 class="timeline-header">';
17065 $out .=
'<div class="messaging-author inline-block tdoverflowmax150 valignmiddle marginrightonly">';
17066 if ($histo[$key][
'userid'] > 0) {
17067 if (!isset($userGetNomUrlCache[$histo[$key][
'userid']])) {
17068 $userstatic->fetch($histo[$key][
'userid']);
17069 $userGetNomUrlCache[$histo[$key][
'userid']] = $userstatic->getNomUrl(-1,
'', 0, 0, 16, 0,
'firstelselast',
'');
17071 $out .= $userGetNomUrlCache[$histo[$key][
'userid']];
17072 } elseif (!empty($histo[$key][
'msg_from']) && $actionstatic->code ==
'TICKET_MSG') {
17073 if (!isset($contactGetNomUrlCache[$histo[$key][
'msg_from']])) {
17074 if ($contactstatic->fetch(0,
null,
'', $histo[$key][
'msg_from']) > 0) {
17075 $contactGetNomUrlCache[$histo[$key][
'msg_from']] = $contactstatic->getNomUrl(-1,
'', 16);
17077 $contactGetNomUrlCache[$histo[$key][
'msg_from']] = $histo[$key][
'msg_from'];
17080 $out .= $contactGetNomUrlCache[$histo[$key][
'msg_from']];
17082 $out .=
'<img class="photomemberphoto userphoto" alt="" src="/public/theme/common/user_anonymous.png">'.$langs->trans(
"Anonymous");
17087 $out .=
' <div class="messaging-title inline-block">';
17089 if (empty(
$conf->dol_optimize_smallscreen) && $actionstatic->type_code !=
'AC_OTH_AUTO') {
17090 $out .= $labeltype .
' - ';
17095 if (!empty($actionstatic->code) && preg_match(
'/^TICKET_MSG_PRIVATE/', $actionstatic->code)) {
17096 $out .= $langs->trans(
'TicketNewMessage').
' - <em>'.
img_picto($langs->trans(
'Private'),
'lock',
'class="valignmiddle"').
' '.$langs->trans(
'Private').
'</em>';
17097 $summary = preg_replace(
'/\[[^\]]*\]\s*/',
'', $actionstatic->label);
17099 $out .=
' - '.dolPrintHTML($summary);
17101 } elseif (!empty($actionstatic->code) && preg_match(
'/^TICKET_MSG/', $actionstatic->code)) {
17102 $out .= $langs->trans(
'TicketNewMessage');
17103 } elseif (isset($histo[$key][
'type'])) {
17104 if ($histo[$key][
'type'] ==
'action') {
17105 $transcode = $langs->transnoentitiesnoconv(
"Action" . $histo[$key][
'acode']);
17106 $libelle = ($transcode !=
"Action" . $histo[$key][
'acode'] ? $transcode : $histo[$key][
'alabel']);
17107 $libelle = $histo[$key][
'note'];
17108 $actionstatic->id = $histo[$key][
'id'];
17109 if ($libelle != $labeltype) {
17112 } elseif ($histo[$key][
'type'] ==
'mailing') {
17113 $out .=
'<a href="' . DOL_URL_ROOT .
'/comm/mailing/card.php?id=' . $histo[$key][
'id'] .
'">' .
img_object($langs->trans(
"ShowEMailing"),
"email") .
' ';
17114 $transcode = $langs->transnoentitiesnoconv(
"Action" . $histo[$key][
'acode']);
17115 $libelle = ($transcode !=
"Action" . $histo[$key][
'acode'] ? $transcode :
'Send mass mailing');
17118 $libelle .= $histo[$key][
'note'];
17122 $out = preg_replace(
'/ - $/',
'', $out);
17124 if (isset($histo[$key][
'elementtype']) && !empty($histo[$key][
'fk_element'])) {
17125 if (isset(
$conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']]) && isset(
$conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']][$histo[$key][
'fk_element']])) {
17126 $link =
$conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']][$histo[$key][
'fk_element']];
17128 if (!isset(
$conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']])) {
17129 $conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']] = array();
17131 $link =
dolGetElementUrl($histo[$key][
'fk_element'], $histo[$key][
'elementtype'], 1);
17132 $conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']][$histo[$key][
'fk_element']] = $link;
17137 if (is_object($filterobj) && get_class($filterobj) ==
'Ticket') {
17138 if ($histo[$key][
'elementtype'] ==
'ticket') {
17143 if ($link && $showlink) {
17144 $out .=
' - ' . $link;
17153 if ($actionstatic->code ==
'AC_TICKET_CREATE') {
17154 $newmess = $filterobj->message;
17156 $newmess = $histo[$key][
'message'];
17159 !empty($newmess && $newmess != $libelle)
17160 && $actionstatic->code !=
'AC_TICKET_MODIFY'
17162 $out .=
'<div class="timeline-body wordbreak small">';
17163 $truncateLines =
getDolGlobalInt(
'MAIN_TRUNCATE_TIMELINE_MESSAGE', 3);
17165 if ($truncateLines > 0 && strlen($newmess) > strlen($truncatedText)) {
17166 $out .=
'<div class="readmore-block --closed" >';
17167 $out .=
' <div class="readmore-block__excerpt">';
17168 $out .=
dolPrintHTML($truncatedText, 0, array(
'pre',
'code'));
17169 $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>';
17171 $out .=
' <div class="readmore-block__full-text" >';
17173 $out .=
dolPrintHTML($newmess, 0, array(
'pre',
'code'));
17175 $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>';
17179 $out .=
dolPrintHTML($newmess, 0, array(
'pre',
'code'));
17188 if (isset($histo[$key][
'socpeopleassigned']) && is_array($histo[$key][
'socpeopleassigned']) && count($histo[$key][
'socpeopleassigned']) > 0) {
17190 foreach ($histo[$key][
'socpeopleassigned'] as $cid => $Tab) {
17191 if (empty(
$conf->cache[
'contact'][$cid])) {
17193 $contact->fetch($cid);
17194 $conf->cache[
'contact'][$cid] = $contact;
17196 $contact =
$conf->cache[
'contact'][$cid];
17200 $contactList .= !empty($contactList) ?
', ' :
'';
17201 $contactList .= $contact->getNomUrl(1);
17202 if (isset($histo[$key][
'acode']) && $histo[$key][
'acode'] ==
'AC_TEL') {
17203 if (!empty($contact->phone_pro)) {
17210 $footer .= $langs->trans(
'ActionOnContact') .
' : ' . $contactList;
17211 } elseif (empty($objcon->id) && isset($histo[$key][
'contact_id']) && $histo[$key][
'contact_id'] > 0) {
17212 if (empty(
$conf->cache[
'contact'][$histo[$key][
'contact_id']])) {
17214 $result = $contact->fetch($histo[$key][
'contact_id']);
17215 $conf->cache[
'contact'][$histo[$key][
'contact_id']] = $contact;
17217 $contact =
$conf->cache[
'contact'][$histo[$key][
'contact_id']];
17218 $result = ($contact instanceof
Contact) ? $contact->id : 0;
17222 $footer .= $contact->getNomUrl(1);
17223 if (isset($histo[$key][
'acode']) && $histo[$key][
'acode'] ==
'AC_TEL') {
17224 if (!empty($contact->phone_pro)) {
17231 $documents = getActionCommEcmList($actionstatic);
17232 if (!empty($documents)) {
17233 $footer .=
'<div class="timeline-documents-container">';
17234 foreach ($documents as $doc) {
17235 $footer .=
'<span id="document_' . $doc->id .
'" class="timeline-documents" ';
17236 $footer .=
' data-id="' . $doc->id .
'" ';
17237 $footer .=
' data-path="' . $doc->filepath .
'"';
17241 $filePath = DOL_DATA_ROOT .
'/' . $doc->filepath .
'/' . $doc->filename;
17242 $mime = dol_mimetype($filePath);
17243 if (empty($doc->agenda_id)) {
17244 $dir_ref = $actionstatic->id;
17245 $modulepart =
'actions';
17247 $split_dir = explode(
'/', $doc->filepath);
17248 $modulepart = array_shift($split_dir);
17249 $dir_ref = implode(
'/', $split_dir);
17252 $file = $dir_ref .
'/' . $doc->filename;
17253 $thumb = $dir_ref .
'/thumbs/' . substr($doc->filename, 0, strrpos($doc->filename,
'.')) .
'_mini' . substr($doc->filename, strrpos($doc->filename,
'.'));
17254 $doclink =
dol_buildpath(
'document.php', 1) .
'?modulepart=' . $modulepart .
'&attachment=0&file=' . urlencode($file) .
'&entity=' .
$conf->entity;
17255 $viewlink =
dol_buildpath(
'viewimage.php', 1) .
'?modulepart=' . $modulepart .
'&file=' . urlencode($thumb) .
'&entity=' .
$conf->entity;
17259 $mimeAttr =
' mime="' . $mime .
'" ';
17261 if (in_array($mime, array(
'image/png',
'image/jpeg',
'application/pdf'))) {
17262 $class .=
' documentpreview';
17265 $footer .=
'<a href="' . $doclink .
'" class="btn-link ' . $class .
'" target="_blank" rel="noopener noreferrer" ' . $mimeAttr .
' >';
17266 $footer .=
img_mime($filePath) .
' ' . $doc->filename;
17269 $footer .=
'</span>';
17271 $footer .=
'</div>';
17274 if (!empty($footer)) {
17275 $out .=
'<div class="timeline-footer">' . $footer .
'</div>';
17278 $out .=
'</div>' .
"\n";
17281 $out .=
'<!-- END timeline item -->';
17288 jQuery(document).ready(function () {
17289 $(document).on("click", "[data-read-more-action]", function(e){
17290 console.log("We click on data-read-more-action");
17291 let readMoreBloc = $(this).closest(".readmore-block");
17292 if(readMoreBloc.length > 0){
17293 e.preventDefault();
17294 if($(this).attr("data-read-more-action") == "close"){
17295 readMoreBloc.addClass("--closed").removeClass("--open");
17296 $("html, body").animate({
17297 scrollTop: readMoreBloc.offset().top - 200
17300 readMoreBloc.addClass("--open").removeClass("--closed");
17308 if (empty($histo)) {
17309 $out .=
'<span class="opacitymedium">' . $langs->trans(
"NoRecordFound") .
'</span>';
17312 if ($num > $MAXWITHOUTPAGINATION) {
17313 $langs->load(
"errors");
17314 $out .=
'<center><span class="opacitymedium">...' . $langs->trans(
"WarningTooManyDataPleaseUseMoreFilters", $MAXWITHOUTPAGINATION) .
'...</span></center>';
17337function buildParamDate($prefix, $timestamp =
null, $hourTime =
'', $gm =
'auto')
17339 if ($timestamp ===
null) {
17340 $timestamp =
GETPOSTDATE($prefix, $hourTime, $gm);
17347 if ($hourTime ===
'getpost' || ($timestamp !==
null &&
dol_print_date($timestamp,
'%H:%M:%S') !==
'00:00:00')) {
17348 $TParam = array_merge($TParam, array(
17355 return '&' . http_build_query($TParam);
17376function recordNotFound($message =
'', $printheader = 1, $printfooter = 1, $showonlymessage = 0, $params =
null)
17378 global
$conf,
$db, $langs, $hookmanager;
17381 if (!is_object($langs)) {
17382 include_once DOL_DOCUMENT_ROOT .
'/core/class/translate.class.php';
17384 $langs->setDefaultLang();
17387 $langs->load(
"errors");
17389 if ($printheader) {
17390 if (function_exists(
"llxHeader")) {
17392 } elseif (function_exists(
"llxHeaderVierge")) {
17397 print
'<div class="error">';
17398 if (empty($message)) {
17399 print $langs->trans(
"ErrorRecordNotFound");
17401 print $langs->trans($message);
17406 if (empty($showonlymessage)) {
17407 if (empty($hookmanager)) {
17408 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
17411 $hookmanager->initHooks(array(
'main'));
17414 $parameters = array(
'message' => $message,
'params' => $params);
17415 $reshook = $hookmanager->executeHooks(
'getErrorRecordNotFound', $parameters,
$object, $action);
17416 print $hookmanager->resPrint;
17419 if ($printfooter && function_exists(
"llxFooter")) {
17421 if (is_object(
$db)) {
17456function array_merge_recursive_distinct(array $array1, array $array2): array
17460 foreach ($array2 as $key => $value) {
17461 if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
17462 $merged[$key] = array_merge_recursive_distinct($merged[$key], $value);
17464 $merged[$key] = $value;
17477function getObjectSocId($obj)
17479 if (!empty($obj->socid)) {
17480 return (
int) $obj->socid;
17481 } elseif (!empty($obj->soc_id)) {
17482 return (
int) $obj->soc_id;
17483 } elseif (!empty($obj->societe_id)) {
17484 return (
int) $obj->societe_id;
17494function getListLimitFromScreenHeight()
17497 if (!empty($_SESSION[
'dol_screenheight']) && $_SESSION[
'dol_screenheight'] < 700) {
17499 } elseif (!empty($_SESSION[
'dol_screenheight']) && $_SESSION[
'dol_screenheight'] < 950) {
17501 } elseif (!empty($_SESSION[
'dol_screenheight']) && $_SESSION[
'dol_screenheight'] > 1130) {
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
global $dolibarr_main_url_root
if(!defined( 'NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined( 'NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined( 'NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined( 'NOIPCHECK')) llxHeaderVierge($title, $head="", $disablejs=0, $disablehead=0, $arrayofjs=[], $arrayofcss=[], $ws='')
Header function.
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.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_convert_file($fileinput, $ext='png', $fileoutput='', $page='')
Convert a PDF file 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.
$date_start
Variables from include:
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.
getDolGlobalLoginBadCharUnauthorized()
Return the list of unauthorized characters in user logins.
getDolGlobalFloat($key, $default=0)
Return a Dolibarr global constant float value.
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formatted size.
isOnlyOneLocalTax($local)
Return true if LocalTax (1 or 2) is unique.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
get_default_localtax($thirdparty_seller, $thirdparty_buyer, $local, $idprod=0)
Function that return localtax of a product line (according to seller, buyer and product vat rate) If ...
img_weather($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $morecss='')
Show weather picto.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
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.
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.
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.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='')
Show information in HTML for admin users or standard users.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dolPrintHTML($s, $allowiframe=0, $moreallowedtags=array())
Return a string (that can be on several lines) ready to be output on a HTML page.
dolGetFirstLineOfText($text, $nboflines=1, $charset='UTF-8')
Return first line of text.
dol_format_address($object, $withcountry=0, $sep="\n", $outputlangs=null, $mode=0, $extralangcode='')
Return a formatted address (part address/zip/town/state) according to country rules.
getDolUserInt($key, $default=0, $tmpuser=null)
Return Dolibarr user constant int value.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
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.
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 ...
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dolOutputDates($datep, $datef=null, $fullday=0, $addseconds=0, $pictotoadd='', $tzoutput='tzuserrel', $reduceformat=0)
Print decorated date-hour.
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.
img_allow($allow, $titlealt='default')
Show tick logo if allowed.
isValidMXRecord($domain)
Return if the domain name has a valid MX record.
dolButtonToOpenExportDialog($name, $label, $buttonstring, $exportSiteName, $overwriteGitUrl, $website)
Create a dialog with two buttons for export and overwrite of a website.
GETPOSTISARRAY($paramname, $method=0)
Return true if the parameter $paramname is submit from a POST OR GET as an array.
dol_print_socialnetworks($value, $contactid, $socid, $type, $dictsocialnetworks=array())
Show social network link.
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.
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)
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.
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
dol_strftime($fmt, $ts=false, $is_gmt=false)
Format a string.
img_picto_common($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $notitle=0)
Show picto (generic function)
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
img_search($titlealt='default', $other='')
Show search logo.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_string_neverthesehtmltags($stringtoclean, $disallowed_tags=array('textarea'), $cleanalsosomestyles=0)
Clean a string from some undesirable HTML tags.
isValidPhone($phone)
Return true if phone number syntax is ok TODO Decide what to do with this.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.: VAT NPR in France)
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
dolPrintHTMLForAttribute($s, $escapeonlyhtmltags=0, $allowothertags=array())
Return a string ready to be output into an HTML attribute (alt, title, data-html, ....
fieldLabel($langkey, $fieldkey, $fieldrequired=0)
Show a string with the label tag dedicated to the HTML edit field.
getBrowserInfo($user_agent)
Return information about user browser.
dolGetFirstLetters($s, $nbofchar=1)
Return first letters of a strings.
dolPrintLabel($s, $escapeonlyhtmltags=0)
Return a string label (so on 1 line only and that should not contains any HTML) ready to be output on...
dol_clone_in_array($srcobject, $startlevel=0)
Create a clone of instance of object into a full array, using recursive call.
dol_print_email($email, $contactid=0, $socid=0, $addlink=0, $max=0, $showinvalid=1, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
dol_strtoupper($string, $encoding="UTF-8")
Convert a string to upper.
getMultidirVersion($object, $module='', $forobject=0)
Return the full path of the directory where a module (or an object of a module) stores its versioned ...
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
dol_sanitizeUrl($stringtoclean, $type=1)
Clean a string to use it as an URL (into a href or src attribute)
showSimpleOrderTable($outputlangs, $object)
Returns simple order table template as string.
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.
safeArrayMap($callback, array $array)
Add a function to replace array_map with allowed callback.
num2Alpha($n)
Return a numeric value into an Excel like column number.
dol_size($size, $type='')
Optimize a size for some browsers (phone, smarphone...)
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)
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.
if(!function_exists( 'utf8_encode')) if(!function_exists('utf8_decode')) if(!function_exists( 'str_starts_with')) if(!function_exists('str_ends_with')) if(!function_exists( 'str_contains')) formatLogObject($data)
Return a string serialized to be output on log with dol_syslog() An option allow to output log in one...
getDolDBType()
Return the current entity.
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.
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formatted messages to output (Used to show messages on html output).
get_product_localtax_for_country($idprod, $local, $thirdpartytouseforcountry)
Return localtax vat rate of a product in a particular country or default country vat if product is un...
getUserRemoteIP($trusted=0)
Return the real IP of remote user.
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...
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.
dol_ucwords($string, $encoding="UTF-8")
Convert first character of all the words of a string to upper.
img_edit_add($titlealt='default', $other='')
Show logo "+".
print_fiche_titre($title, $mesg='', $picto='generic', $pictoisfullpath=0, $id='')
Show a title with picto.
dol_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.
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
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
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.
isHTTPS()
Return if we are using a HTTPS connection Check HTTPS (no way to be modified by user but may be empty...
realCharForNumericEntities($matches)
Return the real char for a numeric entities.